Merge commit 'a1474e9316bfd91b791bb40f13259754cdfea161' into glitch-soc/merge-upstream
This commit is contained in:
commit
2bb0d6d360
13 files changed
+432
-21
No files matched your search
@@ -24,6 +24,7 @@ export interface ApiImageAttachmentJSON extends BaseApiMediaAttachmentJSON {
|
||||
meta: {
|
||||
original: ApiImageAttachmentMetaJSON;
|
||||
small: ApiImageAttachmentMetaJSON;
|
||||
focus?: ApiFocusAttachmentMetaJSON;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -42,10 +43,7 @@ export interface ApiVideoAttachmentJSON extends BaseApiMediaAttachmentJSON {
|
||||
colors: ApiColorsAttachmentMetaJSON;
|
||||
original: ApiVideoAttachmentMetaJSON;
|
||||
small: ApiImageAttachmentMetaJSON;
|
||||
focus: {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
focus?: ApiFocusAttachmentMetaJSON;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -54,6 +52,7 @@ export interface ApiGifvAttachmentJSON extends BaseApiMediaAttachmentJSON {
|
||||
meta: {
|
||||
original: ApiVideoAttachmentMetaJSON;
|
||||
small: ApiImageAttachmentMetaJSON;
|
||||
focus?: ApiFocusAttachmentMetaJSON;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -89,3 +88,8 @@ export interface ApiColorsAttachmentMetaJSON {
|
||||
foreground: string;
|
||||
accent: string;
|
||||
}
|
||||
|
||||
export interface ApiFocusAttachmentMetaJSON {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
@@ -23,12 +23,12 @@ export const textAtCursorMatchesToken = (
|
||||
word = word.trim();
|
||||
|
||||
if (word.length < 3 || (word[0] && !searchTokens.includes(word[0]))) {
|
||||
return [null, null];
|
||||
return [null, null] as const;
|
||||
}
|
||||
|
||||
if (word.length > 0) {
|
||||
return [left + 1, word];
|
||||
return [left + 1, word] as const;
|
||||
} else {
|
||||
return [null, null];
|
||||
return [null, null] as const;
|
||||
}
|
||||
};
|
||||
@@ -153,7 +153,7 @@ const AutosuggestTextarea = forwardRef(({
|
||||
}
|
||||
}, [lang]);
|
||||
|
||||
const renderSuggestion = (suggestion, i) => {
|
||||
const renderSuggestion = useCallback((suggestion, i) => {
|
||||
let inner, key;
|
||||
|
||||
if (suggestion.type === 'emoji') {
|
||||
@@ -172,7 +172,7 @@ const AutosuggestTextarea = forwardRef(({
|
||||
{inner}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
}, [selectedSuggestion, handleSuggestionClick]);
|
||||
|
||||
const handleRef = useCallback((element) => {
|
||||
textareaRef.current = element;
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
@use '@/styles/mastodon/mixins';
|
||||
|
||||
.menu {
|
||||
@include mixins.elevation-1;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: var(--space-2xs) 0;
|
||||
border-radius: var(--radius-md);
|
||||
background: var(--color-bg-primary);
|
||||
overflow: hidden;
|
||||
|
||||
&[data-elevation='2'] {
|
||||
@include mixins.elevation-2;
|
||||
}
|
||||
|
||||
> hr {
|
||||
height: 1px;
|
||||
background-color: var(--color-border-primary);
|
||||
margin: var(--space-2xs) var(--space-sm);
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
.menuItem {
|
||||
@include mixins.type-body-compact;
|
||||
|
||||
--cursor: pointer;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-xs);
|
||||
padding: var(--space-xs) var(--space-sm);
|
||||
cursor: var(--cursor);
|
||||
transition:
|
||||
background 200ms,
|
||||
color 200ms;
|
||||
|
||||
label {
|
||||
cursor: inherit;
|
||||
font-weight: inherit;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: color-mix(
|
||||
in srgb,
|
||||
var(--color-bg-primary) 90%,
|
||||
var(--color-bg-inverted)
|
||||
);
|
||||
}
|
||||
|
||||
&:active,
|
||||
.menuItemActive {
|
||||
background-color: var(--color-bg-inverted);
|
||||
color: var(--color-text-inverted);
|
||||
}
|
||||
|
||||
&:has(:disabled) {
|
||||
--cursor: not-allowed;
|
||||
|
||||
background-color: var(--color-bg-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.menuItemButton {
|
||||
appearance: none;
|
||||
background: none;
|
||||
border: none;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.menu > hr {
|
||||
height: 1px;
|
||||
background-color: var(--color-border-primary);
|
||||
margin: var(--space-2xs) var(--space-sm);
|
||||
border: none;
|
||||
width: calc(100% - (2 * var(--space-sm)));
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
import {
|
||||
MoonIcon,
|
||||
NumberCircleOneIcon,
|
||||
NumberCircleTwoIcon,
|
||||
SunIcon,
|
||||
} from '@phosphor-icons/react';
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import { action } from 'storybook/actions';
|
||||
|
||||
import { useToggle } from '@/mastodon/hooks/useToggle';
|
||||
|
||||
import { Button } from '../button/redesign';
|
||||
import { ToggleField } from '../form_fields/redesign';
|
||||
import { Icon } from '../icon';
|
||||
|
||||
import type { DropdownProps } from './redesign';
|
||||
import {
|
||||
Dropdown,
|
||||
DropdownItem,
|
||||
DropdownItemButton,
|
||||
DropdownPopover,
|
||||
} from './redesign';
|
||||
|
||||
const meta = {
|
||||
title: 'Redesign/Dropdown',
|
||||
args: {
|
||||
elevation: 1,
|
||||
},
|
||||
argTypes: {
|
||||
elevation: {
|
||||
control: 'inline-radio',
|
||||
options: [1, 2],
|
||||
},
|
||||
},
|
||||
} satisfies Meta<Omit<DropdownProps<'div'>, 'children'>>;
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof meta>;
|
||||
|
||||
const handleMenuItemClick = action('menu item click');
|
||||
|
||||
export const Simple: Story = {
|
||||
render(args) {
|
||||
return (
|
||||
<Dropdown {...args}>
|
||||
<DropdownItemButton
|
||||
icon={NumberCircleOneIcon}
|
||||
onClick={handleMenuItemClick}
|
||||
>
|
||||
First item
|
||||
</DropdownItemButton>
|
||||
<DropdownItemButton
|
||||
icon={NumberCircleTwoIcon}
|
||||
onClick={handleMenuItemClick}
|
||||
>
|
||||
Second item
|
||||
</DropdownItemButton>
|
||||
</Dropdown>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export const Popover: Story = {
|
||||
render(args) {
|
||||
const [ref, setRef] = useState<HTMLButtonElement | null>(null);
|
||||
const [open, { onToggle, onFalse }] = useToggle();
|
||||
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||||
<Button ref={setRef} onClick={onToggle}>
|
||||
Click to show dropdown
|
||||
</Button>
|
||||
|
||||
<DropdownPopover
|
||||
reference={ref}
|
||||
isOpen={open}
|
||||
onClose={onFalse}
|
||||
{...args}
|
||||
>
|
||||
<DropdownItemButton
|
||||
icon={NumberCircleOneIcon}
|
||||
onClick={handleMenuItemClick}
|
||||
>
|
||||
First item
|
||||
</DropdownItemButton>
|
||||
<DropdownItemButton
|
||||
icon={NumberCircleTwoIcon}
|
||||
onClick={handleMenuItemClick}
|
||||
>
|
||||
Second item
|
||||
</DropdownItemButton>
|
||||
</DropdownPopover>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export const Controls: Story = {
|
||||
render(args) {
|
||||
const [sun, { onToggle }] = useToggle();
|
||||
return (
|
||||
<Dropdown {...args}>
|
||||
<DropdownItemButton onClick={handleMenuItemClick}>
|
||||
First item
|
||||
</DropdownItemButton>
|
||||
|
||||
<hr />
|
||||
|
||||
<DropdownItem>
|
||||
{sun ? (
|
||||
<Icon id='sun' icon={SunIcon} />
|
||||
) : (
|
||||
<Icon id='moon' icon={MoonIcon} />
|
||||
)}
|
||||
<ToggleField label='Daytime toggle' size='sm' onChange={onToggle} />
|
||||
</DropdownItem>
|
||||
</Dropdown>
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,133 @@
|
||||
import type React from 'react';
|
||||
|
||||
import classNames from 'classnames';
|
||||
|
||||
import type { Merge } from 'type-fest';
|
||||
|
||||
import { Icon } from '../icon';
|
||||
import type { IconProp } from '../icon';
|
||||
import type { PopoverProps } from '../popover';
|
||||
import { Popover } from '../popover';
|
||||
|
||||
import classes from './redesign.module.scss';
|
||||
|
||||
export const menuItemClass = classes.menuItem;
|
||||
|
||||
export type DropdownProps<As extends React.ElementType> = Merge<
|
||||
{
|
||||
as?: As;
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
elevation?: 1 | 2;
|
||||
maxWidth?: number | string;
|
||||
style?: React.CSSProperties;
|
||||
},
|
||||
React.ComponentProps<As>
|
||||
>;
|
||||
|
||||
export const DropdownPopover = <As extends React.ElementType>({
|
||||
isOpen,
|
||||
onClose,
|
||||
reference,
|
||||
popoverElement,
|
||||
container,
|
||||
placement,
|
||||
offset = 4,
|
||||
flip,
|
||||
strategy,
|
||||
matchReferenceWidth,
|
||||
closeOnClickOutside,
|
||||
children,
|
||||
...props
|
||||
}: DropdownProps<As> & Omit<PopoverProps, 'children'>) => {
|
||||
const popoverProps = {
|
||||
isOpen,
|
||||
onClose,
|
||||
reference,
|
||||
popoverElement,
|
||||
container,
|
||||
placement,
|
||||
offset,
|
||||
flip,
|
||||
strategy,
|
||||
matchReferenceWidth,
|
||||
closeOnClickOutside,
|
||||
};
|
||||
return (
|
||||
<Popover {...popoverProps}>
|
||||
{({ props: popoverChildProps }) => (
|
||||
<Dropdown {...props} {...popoverChildProps}>
|
||||
{children}
|
||||
</Dropdown>
|
||||
)}
|
||||
</Popover>
|
||||
);
|
||||
};
|
||||
|
||||
export const Dropdown = <As extends React.ElementType>({
|
||||
as: asComp,
|
||||
children,
|
||||
className,
|
||||
elevation = 1,
|
||||
maxWidth,
|
||||
style,
|
||||
...props
|
||||
}: DropdownProps<As>) => {
|
||||
const Component = asComp ?? 'div';
|
||||
return (
|
||||
<Component
|
||||
{...props}
|
||||
className={classNames(className, classes.menu)}
|
||||
data-elevation={elevation}
|
||||
style={{
|
||||
maxWidth: typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth,
|
||||
...style,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Component>
|
||||
);
|
||||
};
|
||||
|
||||
type DropdownItemProps<As extends React.ElementType> = Merge<
|
||||
{ as?: As; children?: React.ReactNode; className?: string; active?: boolean },
|
||||
React.ComponentPropsWithoutRef<As>
|
||||
>;
|
||||
|
||||
export const DropdownItem = <As extends React.ElementType>({
|
||||
active,
|
||||
as: AsComp,
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}: DropdownItemProps<As>) => {
|
||||
const Component = AsComp ?? 'div';
|
||||
return (
|
||||
<Component
|
||||
{...props}
|
||||
className={classNames(
|
||||
className,
|
||||
classes.menuItem,
|
||||
active && classes.menuItemActive,
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</Component>
|
||||
);
|
||||
};
|
||||
|
||||
export const DropdownItemButton: React.FC<
|
||||
{ icon?: IconProp } & React.ComponentProps<'button'>
|
||||
> = ({ icon, children, className, ...props }) => {
|
||||
return (
|
||||
<DropdownItem
|
||||
type='button'
|
||||
{...props}
|
||||
as='button'
|
||||
className={classNames(className, classes.menuItemButton)}
|
||||
>
|
||||
{icon && <Icon id='menu' icon={icon} />}
|
||||
{children}
|
||||
</DropdownItem>
|
||||
);
|
||||
};
|
||||
@@ -95,13 +95,18 @@ export interface PopoverProps {
|
||||
* enable it to be sized and positioned. The `ref` prop
|
||||
* is not passed when the `popoverElement` prop is provided.
|
||||
*/
|
||||
props: Record<string, unknown> & {
|
||||
ref?: React.RefCallback<HTMLElement>;
|
||||
style: React.CSSProperties;
|
||||
};
|
||||
props: PopoverChildProps;
|
||||
}) => React.ReactNode;
|
||||
}
|
||||
|
||||
export interface PopoverChildProps {
|
||||
ref?: React.RefCallback<HTMLElement>;
|
||||
style: React.CSSProperties;
|
||||
'data-popover-placement': Placement;
|
||||
'data-popover-reference-hidden'?: boolean;
|
||||
'data-popover-escaped'?: boolean;
|
||||
}
|
||||
|
||||
export const Popover: React.FC<PopoverProps> = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
|
||||
@@ -56,13 +56,15 @@ const getFrequentlyUsedLanguages = createSelector(
|
||||
|
||||
const isTextLongEnoughForGuess = (text: string) => text.length > 20;
|
||||
|
||||
const LanguageDropdownMenu: React.FC<{
|
||||
const emptyArray: Language[] = [];
|
||||
|
||||
export const LanguageDropdownMenu: React.FC<{
|
||||
value: string;
|
||||
guess?: string;
|
||||
guess: string;
|
||||
onClose: () => void;
|
||||
onChange: (arg0: string) => void;
|
||||
}> = ({ value, guess, onClose, onChange }) => {
|
||||
const languages = preloadedLanguages as Language[];
|
||||
const languages = preloadedLanguages ?? emptyArray;
|
||||
const intl = useIntl();
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
const nodeRef = useRef<HTMLDivElement>(null);
|
||||
@@ -317,7 +319,7 @@ export const LanguageDropdown: React.FC = () => {
|
||||
const text = useAppSelector((state) => state.compose.get('text') as string);
|
||||
|
||||
const current =
|
||||
(preloadedLanguages as Language[]).find((lang) => lang[0] === value) ?? [];
|
||||
(preloadedLanguages ?? []).find((lang) => lang[0] === value) ?? [];
|
||||
|
||||
const handleMouseDown = useCallback(() => {
|
||||
if (!open && document.activeElement instanceof HTMLElement) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||
|
||||
import { STORE_HYDRATE } from '../actions/store';
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
accept_content_types: [],
|
||||
accept_content_types: ImmutableList(),
|
||||
});
|
||||
|
||||
export default function meta(state = initialState, action) {
|
||||
|
||||
@@ -30,7 +30,7 @@ export const selectPlainStatus = createAppSelector(
|
||||
export const selectAccountStatus = createAppSelector(
|
||||
[
|
||||
selectPlainStatus,
|
||||
(state, statusId: string) => {
|
||||
(state, statusId?: string | null) => {
|
||||
const accountId = state.statuses.getIn([statusId, 'account']);
|
||||
if (typeof accountId !== 'string') {
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user