@gemologic/sheen 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/ai.d.ts +8 -0
- package/dist/ai.js +5 -0
- package/dist/core.d.ts +11 -4
- package/dist/core.js +32 -28
- package/dist/formisch.js +1 -2
- package/dist/forms.d.ts +2 -0
- package/dist/forms.js +16 -15
- package/dist/index.d.ts +27 -5
- package/dist/index.js +87 -76
- package/dist/layout/Layout.js +1 -2
- package/dist/metadata.js +1 -2
- package/dist/navigation.d.ts +2 -1
- package/dist/navigation.js +16 -16
- package/dist/overlays.d.ts +2 -0
- package/dist/overlays.js +9 -8
- package/dist/primitives/Accordion.js +9 -9
- package/dist/primitives/ActivityTimeline.js +57 -49
- package/dist/primitives/AlertDialog.js +1 -2
- package/dist/primitives/Avatar.js +16 -17
- package/dist/primitives/Board.d.ts +39 -0
- package/dist/primitives/Board.js +471 -0
- package/dist/primitives/Breadcrumb.js +1 -2
- package/dist/primitives/Button.js +38 -27
- package/dist/primitives/ButtonGroup.js +1 -2
- package/dist/primitives/Checkbox.d.ts +16 -2
- package/dist/primitives/Checkbox.js +46 -36
- package/dist/primitives/CheckboxGroup.js +11 -12
- package/dist/primitives/Collapsible.js +6 -6
- package/dist/primitives/Combobox.js +203 -201
- package/dist/primitives/CommandPalette.d.ts +4 -0
- package/dist/primitives/CommandPalette.js +138 -116
- package/dist/primitives/ConfirmDialog.js +5 -6
- package/dist/primitives/ContextMenu.js +7 -8
- package/dist/primitives/Conversation.d.ts +17 -0
- package/dist/primitives/Conversation.js +107 -0
- package/dist/primitives/DescriptionList.js +1 -2
- package/dist/primitives/Dialog.js +101 -68
- package/dist/primitives/Drawer.js +12 -13
- package/dist/primitives/DropdownMenu.js +163 -157
- package/dist/primitives/EditableTextField.js +3 -8
- package/dist/primitives/EmptyState.js +1 -2
- package/dist/primitives/Field.js +1 -2
- package/dist/primitives/FileDropzone.js +19 -18
- package/dist/primitives/Form.d.ts +23 -0
- package/dist/primitives/Form.js +76 -0
- package/dist/primitives/Glyph.d.ts +40 -0
- package/dist/primitives/Glyph.js +65 -0
- package/dist/primitives/IconButton.js +5 -6
- package/dist/primitives/Input.js +1 -2
- package/dist/primitives/InputGroup.js +8 -9
- package/dist/primitives/Link.d.ts +9 -1
- package/dist/primitives/Link.js +23 -17
- package/dist/primitives/LinkTooltip.js +6 -7
- package/dist/primitives/List.d.ts +34 -0
- package/dist/primitives/List.js +135 -0
- package/dist/primitives/Message.d.ts +13 -0
- package/dist/primitives/Message.js +75 -0
- package/dist/primitives/NavList.js +15 -16
- package/dist/primitives/Notice.d.ts +15 -1
- package/dist/primitives/Notice.js +91 -43
- package/dist/primitives/NumberField.js +81 -81
- package/dist/primitives/NumberText.d.ts +4 -0
- package/dist/primitives/NumberText.js +50 -25
- package/dist/primitives/Pagination.js +81 -60
- package/dist/primitives/Popover.d.ts +1 -0
- package/dist/primitives/Popover.js +65 -57
- package/dist/primitives/Progress.js +1 -2
- package/dist/primitives/PromptInput.d.ts +23 -0
- package/dist/primitives/PromptInput.js +135 -0
- package/dist/primitives/RadioGroup.js +12 -17
- package/dist/primitives/Resizable.js +1 -2
- package/dist/primitives/ScrollArea.js +1 -2
- package/dist/primitives/SearchInput.js +45 -38
- package/dist/primitives/SegmentedControl.d.ts +2 -0
- package/dist/primitives/SegmentedControl.js +92 -78
- package/dist/primitives/Select.js +105 -100
- package/dist/primitives/Separator.js +1 -2
- package/dist/primitives/ShortcutPending.js +11 -12
- package/dist/primitives/ShortcutProvider.d.ts +5 -0
- package/dist/primitives/ShortcutProvider.js +71 -65
- package/dist/primitives/ShortcutScope.js +8 -9
- package/dist/primitives/ShortcutSheet.js +30 -24
- package/dist/primitives/Skeleton.js +1 -2
- package/dist/primitives/Slider.js +1 -2
- package/dist/primitives/SortableList.d.ts +19 -0
- package/dist/primitives/SortableList.js +235 -0
- package/dist/primitives/Spinner.js +1 -2
- package/dist/primitives/Status.js +14 -14
- package/dist/primitives/Stepper.js +54 -52
- package/dist/primitives/StreamingText.d.ts +12 -0
- package/dist/primitives/StreamingText.js +42 -0
- package/dist/primitives/Surface.js +1 -2
- package/dist/primitives/Switch.d.ts +2 -2
- package/dist/primitives/Switch.js +1 -2
- package/dist/primitives/Table.js +1 -2
- package/dist/primitives/Tabs.js +20 -17
- package/dist/primitives/TagInput.js +6 -9
- package/dist/primitives/Textarea.js +37 -63
- package/dist/primitives/Toast.js +42 -41
- package/dist/primitives/Toaster.js +27 -28
- package/dist/primitives/Tooltip.js +32 -32
- package/dist/primitives/TooltipTrigger.d.ts +18 -0
- package/dist/primitives/TooltipTrigger.js +76 -0
- package/dist/primitives/Tree.js +1 -2
- package/dist/primitives/Typography.d.ts +6 -2
- package/dist/primitives/Typography.js +20 -12
- package/dist/primitives/boolean-input-state.js +3 -8
- package/dist/primitives/button-variants.js +2 -3
- package/dist/primitives/choice-options.js +1 -2
- package/dist/primitives/create-confirm.js +1 -2
- package/dist/primitives/create-toaster.js +1 -2
- package/dist/primitives/link-focus.js +1 -2
- package/dist/primitives/menu-focus.js +1 -2
- package/dist/primitives/sortable-core.d.ts +70 -0
- package/dist/primitives/sortable-core.js +109 -0
- package/dist/primitives/sortable-drag.d.ts +29 -0
- package/dist/primitives/sortable-drag.js +50 -0
- package/dist/primitives/tooltip-layer.js +26 -27
- package/dist/sortable.d.ts +6 -0
- package/dist/sortable.js +4 -0
- package/dist/theme/ThemeProvider.d.ts +6 -1
- package/dist/theme/ThemeProvider.js +65 -58
- package/dist/theme/intl.js +1 -2
- package/dist/theme/keyboard-script.js +1 -2
- package/dist/theme/layers.js +1 -2
- package/dist/theme/messages.d.ts +26 -0
- package/dist/theme/messages.js +9 -2
- package/dist/theme/number-format-cache.js +1 -2
- package/dist/theme/script.d.ts +1 -0
- package/dist/theme/script.js +3 -3
- package/dist/theme/state.d.ts +4 -4
- package/dist/theme/state.js +12 -13
- package/dist/utils/auto-resize.d.ts +6 -0
- package/dist/utils/auto-resize.js +31 -0
- package/dist/utils/browser-status.js +1 -2
- package/dist/utils/change-motion.d.ts +8 -0
- package/dist/utils/change-motion.js +19 -0
- package/dist/utils/cn.js +1 -2
- package/dist/utils/media-query.d.ts +10 -0
- package/dist/utils/media-query.js +16 -0
- package/dist/utils/optimistic.js +1 -2
- package/dist/utils/shortcut-platform.js +1 -2
- package/dist/utils/shortcut-registry.d.ts +5 -0
- package/dist/utils/shortcut-registry.js +61 -51
- package/dist/vite.js +3 -4
- package/package.json +23 -5
- package/src/ai.ts +8 -0
- package/src/core.ts +11 -4
- package/src/forms.ts +2 -0
- package/src/index.ts +27 -5
- package/src/navigation.ts +2 -1
- package/src/overlays.ts +2 -0
- package/src/primitives/Accordion.tsx +1 -1
- package/src/primitives/ActivityTimeline.tsx +12 -7
- package/src/primitives/Board.tsx +406 -0
- package/src/primitives/Button.tsx +15 -4
- package/src/primitives/Checkbox.tsx +14 -7
- package/src/primitives/Collapsible.tsx +1 -1
- package/src/primitives/Combobox.tsx +2 -1
- package/src/primitives/CommandPalette.tsx +13 -4
- package/src/primitives/Conversation.tsx +108 -0
- package/src/primitives/Dialog.tsx +5 -1
- package/src/primitives/DropdownMenu.tsx +12 -6
- package/src/primitives/FileDropzone.tsx +2 -2
- package/src/primitives/Form.tsx +58 -0
- package/src/primitives/Glyph.tsx +55 -0
- package/src/primitives/Link.tsx +15 -6
- package/src/primitives/List.tsx +68 -0
- package/src/primitives/Message.tsx +40 -0
- package/src/primitives/Notice.tsx +45 -12
- package/src/primitives/NumberField.tsx +3 -2
- package/src/primitives/NumberText.tsx +31 -4
- package/src/primitives/Pagination.tsx +6 -5
- package/src/primitives/Popover.tsx +7 -5
- package/src/primitives/PromptInput.tsx +116 -0
- package/src/primitives/SearchInput.tsx +4 -3
- package/src/primitives/SegmentedControl.tsx +29 -4
- package/src/primitives/Select.tsx +3 -2
- package/src/primitives/ShortcutProvider.tsx +14 -1
- package/src/primitives/ShortcutSheet.tsx +1 -1
- package/src/primitives/SortableList.tsx +208 -0
- package/src/primitives/Status.tsx +1 -1
- package/src/primitives/Stepper.tsx +7 -7
- package/src/primitives/StreamingText.tsx +32 -0
- package/src/primitives/Switch.tsx +2 -2
- package/src/primitives/Tabs.tsx +2 -1
- package/src/primitives/TagInput.tsx +1 -1
- package/src/primitives/Textarea.tsx +3 -47
- package/src/primitives/Toast.tsx +2 -1
- package/src/primitives/Tooltip.tsx +4 -2
- package/src/primitives/TooltipTrigger.tsx +60 -0
- package/src/primitives/Typography.tsx +11 -2
- package/src/primitives/button-variants.ts +1 -1
- package/src/primitives/sortable-core.ts +139 -0
- package/src/primitives/sortable-drag.ts +75 -0
- package/src/sortable.ts +6 -0
- package/src/styles/ai.css +57 -0
- package/src/styles/core.css +321 -0
- package/src/styles/forms.css +263 -0
- package/src/styles/navigation.css +137 -0
- package/src/styles/overlays.css +107 -0
- package/src/styles/sortable.css +87 -0
- package/src/styles.css +5 -658
- package/src/theme/ThemeProvider.tsx +20 -8
- package/src/theme/messages.ts +20 -1
- package/src/theme/script.ts +2 -2
- package/src/theme/state.ts +5 -5
- package/src/utils/auto-resize.ts +58 -0
- package/src/utils/change-motion.ts +28 -0
- package/src/utils/media-query.ts +26 -0
- package/src/utils/shortcut-registry.ts +19 -2
- package/src/vite.ts +3 -3
- package/vendor/integrity.json +13 -13
- package/vendor/kobalte-core/chunk/3D6FM2PJ.js +7 -1
- package/vendor/kobalte-core/chunk/G3KI2B4X.js +2 -1
- package/vendor/kobalte-core/chunk/KEL2LLJM.jsx +2 -1
- package/vendor/kobalte-core/chunk/RFN6X5VH.jsx +7 -1
- package/vendor/origins.json +4 -4
- package/vendor/solid-web/dev.cjs +21 -17
- package/vendor/solid-web/dev.js +21 -17
- package/vendor/solid-web/server.cjs +1 -1
- package/vendor/solid-web/server.js +1 -1
- package/vendor/solid-web/web.cjs +21 -17
- package/vendor/solid-web/web.js +21 -17
|
@@ -4,6 +4,7 @@ import { Button } from "./Button.tsx";
|
|
|
4
4
|
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
5
5
|
import { useNumberFormatter } from "../theme/intl.ts";
|
|
6
6
|
import { cn } from "../utils/cn.ts";
|
|
7
|
+
import { Glyph } from "./Glyph.tsx";
|
|
7
8
|
|
|
8
9
|
export interface PaginationProps extends Omit<JSX.HTMLAttributes<HTMLElement>, "children" | "onChange"> {
|
|
9
10
|
pageIndex: number;
|
|
@@ -54,11 +55,11 @@ export function Pagination(props: PaginationProps): JSX.Element {
|
|
|
54
55
|
.replaceAll("{page}", format().format(state().count ? state().index + 1 : 0))
|
|
55
56
|
.replaceAll("{pages}", format().format(state().count));
|
|
56
57
|
return <nav {...others} ref={element => { root = element; if (typeof local.ref === "function") local.ref(element); }} class={cn("sheen-pagination", local.class)} aria-label={local.label ?? theme.messages().pagination} aria-busy={local.pending || undefined} aria-disabled={local.disabled || undefined} data-pending={local.pending ? "" : undefined}>
|
|
57
|
-
<Button aria-disabled={unavailable(0) || undefined} onClick={() => request(0)}
|
|
58
|
-
<Button aria-disabled={unavailable(state().index - 1) || undefined} onClick={() => request(state().index - 1)}
|
|
59
|
-
<For each={pages()}>{index => <Button aria-label={pageLabel(index)} aria-current={index === state().index ? "page" : undefined} aria-disabled={unavailable(index) || undefined} onClick={() => request(index)}>{format().format(index + 1)}</Button>}</For>
|
|
60
|
-
<Button aria-disabled={unavailable(state().index + 1) || undefined} onClick={() => request(state().index + 1)}
|
|
61
|
-
<Button aria-disabled={unavailable(state().count - 1) || undefined} onClick={() => request(state().count - 1)}
|
|
58
|
+
<Button variant="ghost" class="sheen-pagination-step" aria-label={theme.messages().firstPage} aria-disabled={unavailable(0) || undefined} onClick={() => request(0)}><Glyph name="chevrons-left" /></Button>
|
|
59
|
+
<Button variant="ghost" class="sheen-pagination-step" aria-label={theme.messages().previousPage} aria-disabled={unavailable(state().index - 1) || undefined} onClick={() => request(state().index - 1)}><Glyph name="chevron-left" /></Button>
|
|
60
|
+
<For each={pages()}>{index => <Button variant="ghost" aria-label={pageLabel(index)} aria-current={index === state().index ? "page" : undefined} aria-disabled={unavailable(index) || undefined} onClick={() => request(index)}>{format().format(index + 1)}</Button>}</For>
|
|
61
|
+
<Button variant="ghost" class="sheen-pagination-step" aria-label={theme.messages().nextPage} aria-disabled={unavailable(state().index + 1) || undefined} onClick={() => request(state().index + 1)}><Glyph name="chevron-right" /></Button>
|
|
62
|
+
<Button variant="ghost" class="sheen-pagination-step" aria-label={theme.messages().lastPage} aria-disabled={unavailable(state().count - 1) || undefined} onClick={() => request(state().count - 1)}><Glyph name="chevrons-right" /></Button>
|
|
62
63
|
<output aria-live="polite" aria-atomic="true">{summary()}</output>
|
|
63
64
|
</nav>;
|
|
64
65
|
}
|
|
@@ -4,6 +4,7 @@ import type { JSX, ParentProps } from "solid-js";
|
|
|
4
4
|
import { Button } from "./Button.tsx";
|
|
5
5
|
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
6
6
|
import { cn } from "../utils/cn.ts";
|
|
7
|
+
import { Glyph } from "./Glyph.tsx";
|
|
7
8
|
|
|
8
9
|
export interface PopoverProps extends ParentProps {
|
|
9
10
|
trigger: JSX.Element;
|
|
@@ -12,13 +13,14 @@ export interface PopoverProps extends ParentProps {
|
|
|
12
13
|
open?: boolean;
|
|
13
14
|
defaultOpen?: boolean;
|
|
14
15
|
onOpenChange?: (open: boolean) => void;
|
|
16
|
+
disabled?: boolean;
|
|
15
17
|
placement?: "top" | "top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "left" | "right";
|
|
16
18
|
class?: string;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
function PopoverTrigger(props: ParentProps): JSX.Element {
|
|
21
|
+
function PopoverTrigger(props: ParentProps<{ disabled: boolean }>): JSX.Element {
|
|
20
22
|
const context = Primitive.usePopoverContext();
|
|
21
|
-
return <Button ref={context.setTriggerRef} variant="outline" data-sheen-popover-trigger=""
|
|
23
|
+
return <Button ref={context.setTriggerRef} variant="outline" data-sheen-popover-trigger="" disabled={props.disabled}
|
|
22
24
|
aria-haspopup="dialog" aria-expanded={context.isOpen()} aria-controls={context.isOpen() ? context.contentId() : undefined}
|
|
23
25
|
onPointerDown={event => { if (event.pointerType === "mouse") event.preventDefault(); }}
|
|
24
26
|
onClick={() => context.toggle()} {...context.dataset()}>{props.children}</Button>;
|
|
@@ -30,14 +32,14 @@ export function Popover(props: PopoverProps): JSX.Element {
|
|
|
30
32
|
const [draft, setDraft] = createSignal(props.defaultOpen ?? false);
|
|
31
33
|
const open = () => props.open === undefined ? draft() : props.open;
|
|
32
34
|
const change = (next: boolean) => {
|
|
33
|
-
if (next === open()) return;
|
|
35
|
+
if (next === open() || (next && props.disabled)) return;
|
|
34
36
|
if (props.open === undefined) setDraft(next);
|
|
35
37
|
props.onOpenChange?.(next);
|
|
36
38
|
};
|
|
37
39
|
createEffect(() => { if (open()) onCleanup(theme.layers.register(id)); });
|
|
38
40
|
const layer = createMemo<number>(previous => open() ? theme.layers.zIndex(id) : previous ?? 100);
|
|
39
41
|
return <Primitive.Root open={open()} onOpenChange={change} placement={props.placement ?? "bottom"} gutter={6}>
|
|
40
|
-
<PopoverTrigger>{props.trigger}</PopoverTrigger>
|
|
42
|
+
<PopoverTrigger disabled={props.disabled ?? false}>{props.trigger}</PopoverTrigger>
|
|
41
43
|
<Show when={theme.portal()}>{target => <Primitive.Portal mount={target()}>
|
|
42
44
|
<Primitive.Content data-kb-top-layer="true" class={cn("sheen-popover", props.class)} aria-hidden={!open() || undefined} inert={!open()} style={{ "z-index": layer() }}
|
|
43
45
|
onEscapeKeyDown={event => { if (!theme.layers.isTop(id)) event.preventDefault(); }}>
|
|
@@ -45,7 +47,7 @@ export function Popover(props: PopoverProps): JSX.Element {
|
|
|
45
47
|
<Show when={props.description}><Primitive.Description>{props.description}</Primitive.Description></Show>
|
|
46
48
|
</div>
|
|
47
49
|
<div class="sheen-dialog-body">{props.children}</div>
|
|
48
|
-
<
|
|
50
|
+
<Primitive.CloseButton as={Button} variant="ghost" class="sheen-dialog-close" size="sm" aria-label={theme.messages().close}><Glyph name="close" /></Primitive.CloseButton>
|
|
49
51
|
</Primitive.Content>
|
|
50
52
|
</Primitive.Portal>}</Show>
|
|
51
53
|
</Primitive.Root>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Show, children, createEffect, createMemo, createSignal, onMount, splitProps } from "solid-js";
|
|
2
|
+
import type { JSX } from "solid-js";
|
|
3
|
+
import { isServer } from "solid-js/web";
|
|
4
|
+
import { Button } from "./Button.tsx";
|
|
5
|
+
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
6
|
+
import { cn } from "../utils/cn.ts";
|
|
7
|
+
import { createAutoResize } from "../utils/auto-resize.ts";
|
|
8
|
+
|
|
9
|
+
export type PromptInputStatus = "idle" | "streaming";
|
|
10
|
+
|
|
11
|
+
export interface PromptInputProps extends Omit<JSX.FormHTMLAttributes<HTMLFormElement>, "onSubmit" | "children" | "name" | "ref"> {
|
|
12
|
+
ref?: HTMLFormElement | ((element: HTMLFormElement) => void);
|
|
13
|
+
value?: string;
|
|
14
|
+
defaultValue?: string;
|
|
15
|
+
onValueChange?: (value: string) => void;
|
|
16
|
+
onSubmit: (value: string) => void;
|
|
17
|
+
onStop?: () => void;
|
|
18
|
+
status?: PromptInputStatus;
|
|
19
|
+
label?: string;
|
|
20
|
+
placeholder?: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
maxRows?: number;
|
|
24
|
+
leading?: JSX.Element;
|
|
25
|
+
trailing?: JSX.Element;
|
|
26
|
+
submitLabel?: string;
|
|
27
|
+
stopLabel?: string;
|
|
28
|
+
textareaRef?: (element: HTMLTextAreaElement) => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A chat composer: an auto-growing textarea whose single action sends the draft or stops the streaming response. */
|
|
32
|
+
export function PromptInput(props: PromptInputProps): JSX.Element {
|
|
33
|
+
const theme = useTheme();
|
|
34
|
+
const [local, others] = splitProps(props, ["ref", "value", "defaultValue", "onValueChange", "onSubmit", "onStop", "status", "label", "placeholder", "name", "disabled", "maxRows", "leading", "trailing", "submitLabel", "stopLabel", "textareaRef", "class"]);
|
|
35
|
+
const leading = children(() => local.leading);
|
|
36
|
+
const trailing = children(() => local.trailing);
|
|
37
|
+
const [draft, setDraft] = createSignal(local.defaultValue ?? "");
|
|
38
|
+
const value = () => local.value ?? draft();
|
|
39
|
+
const [composing, setComposing] = createSignal(false);
|
|
40
|
+
const streaming = () => local.status === "streaming";
|
|
41
|
+
const maxRows = createMemo(() => {
|
|
42
|
+
const rows = local.maxRows ?? 8;
|
|
43
|
+
if (!Number.isSafeInteger(rows) || rows < 1) throw new Error("PromptInput: maxRows must be a positive integer");
|
|
44
|
+
return rows;
|
|
45
|
+
});
|
|
46
|
+
let textarea: HTMLTextAreaElement | undefined;
|
|
47
|
+
const schedule = createAutoResize(() => textarea, () => true);
|
|
48
|
+
createEffect(() => { void value(); void maxRows(); void theme.state(); schedule(); });
|
|
49
|
+
const update = (next: string) => {
|
|
50
|
+
if (local.value === undefined) setDraft(next);
|
|
51
|
+
local.onValueChange?.(next);
|
|
52
|
+
};
|
|
53
|
+
// A controlled owner may reject a proposal; restore its value unless an IME draft is still open.
|
|
54
|
+
const reconcile = () => {
|
|
55
|
+
if (textarea && !composing() && textarea.value !== value()) textarea.value = value();
|
|
56
|
+
};
|
|
57
|
+
const canSubmit = () => !local.disabled && !streaming() && !composing() && value().trim().length > 0;
|
|
58
|
+
const canStop = () => !local.disabled && streaming() && local.onStop !== undefined;
|
|
59
|
+
const submit = () => {
|
|
60
|
+
if (!canSubmit()) return;
|
|
61
|
+
const submitted = value();
|
|
62
|
+
if (local.value === undefined) setDraft("");
|
|
63
|
+
local.onSubmit(submitted);
|
|
64
|
+
reconcile();
|
|
65
|
+
};
|
|
66
|
+
onMount(() => {
|
|
67
|
+
// Adopt text typed before hydration attached the input handler.
|
|
68
|
+
if (textarea && textarea.value !== value()) {
|
|
69
|
+
update(textarea.value);
|
|
70
|
+
reconcile();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
const onKeyDown: JSX.EventHandler<HTMLTextAreaElement, KeyboardEvent> = event => {
|
|
74
|
+
if (event.key !== "Enter" || event.shiftKey) return;
|
|
75
|
+
// Enter that confirms an IME candidate belongs to the composition. Safari reports it after compositionend with keyCode 229.
|
|
76
|
+
if (event.isComposing || event.keyCode === 229 || composing()) return;
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
submit();
|
|
79
|
+
};
|
|
80
|
+
const onAction: JSX.EventHandler<HTMLButtonElement, MouseEvent> = event => {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
if (streaming()) {
|
|
83
|
+
if (canStop()) local.onStop?.();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
submit();
|
|
87
|
+
};
|
|
88
|
+
const actionLabel = () => streaming() ? local.stopLabel ?? theme.messages().stopResponse : local.submitLabel ?? theme.messages().sendMessage;
|
|
89
|
+
// HTML parsing removes one leading newline from textarea text content.
|
|
90
|
+
const serverText = () => `\n${value()}`;
|
|
91
|
+
return <form {...others} ref={element => { if (typeof local.ref === "function") local.ref(element); }} class={cn("sheen-prompt-input", local.class)}
|
|
92
|
+
data-status={streaming() ? "streaming" : "idle"} data-disabled={local.disabled || undefined}
|
|
93
|
+
onSubmit={event => { event.preventDefault(); submit(); }}>
|
|
94
|
+
<textarea class="sheen-prompt-input-textarea" rows={1} name={local.name} placeholder={local.placeholder} disabled={local.disabled}
|
|
95
|
+
aria-label={local.label ?? theme.messages().promptInput} value={isServer ? undefined : value()}
|
|
96
|
+
style={{ "--sheen-prompt-input-max-rows": String(maxRows()) }}
|
|
97
|
+
ref={element => { textarea = element; local.textareaRef?.(element); }}
|
|
98
|
+
onInput={event => { update(event.currentTarget.value); reconcile(); schedule(); }}
|
|
99
|
+
onCompositionStart={() => setComposing(true)}
|
|
100
|
+
onCompositionEnd={() => { setComposing(false); reconcile(); }}
|
|
101
|
+
onKeyDown={onKeyDown}>{isServer ? serverText() : undefined}</textarea>
|
|
102
|
+
<div class="sheen-prompt-input-toolbar">
|
|
103
|
+
<Show when={leading.toArray().length > 0}><div class="sheen-prompt-input-leading">{leading()}</div></Show>
|
|
104
|
+
<div class="sheen-prompt-input-trailing">
|
|
105
|
+
{trailing()}
|
|
106
|
+
<Button class="sheen-prompt-input-action" type={streaming() ? "button" : "submit"} variant="solid" tone={streaming() ? "neutral" : "accent"} size="sm"
|
|
107
|
+
disabled={local.disabled} aria-disabled={!local.disabled && !(streaming() ? canStop() : canSubmit()) ? "true" : undefined}
|
|
108
|
+
aria-label={actionLabel()} data-action={streaming() ? "stop" : "send"} onClick={onAction}>
|
|
109
|
+
<svg class="sheen-prompt-input-glyph" viewBox="0 0 16 16" aria-hidden="true" fill="currentColor">
|
|
110
|
+
<Show when={streaming()} fallback={<path d="M8 2.5 13 7.5l-1.06 1.06-3.19-3.19V13.5h-1.5V5.37L4.06 8.56 3 7.5z" />}><rect x="4" y="4" width="8" height="8" rx="1.5" /></Show>
|
|
111
|
+
</svg>
|
|
112
|
+
</Button>
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
</form>;
|
|
116
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createSignal, onCleanup, onMount, splitProps } from "solid-js";
|
|
2
|
+
import { Glyph } from "./Glyph.tsx";
|
|
2
3
|
import type { JSX } from "solid-js";
|
|
3
4
|
import { Button } from "./Button.tsx";
|
|
4
5
|
import { InputGroup } from "./InputGroup.tsx";
|
|
@@ -87,12 +88,12 @@ export function SearchInput(props: SearchInputProps): JSX.Element {
|
|
|
87
88
|
input = element;
|
|
88
89
|
if (typeof local.ref === "function") local.ref(element);
|
|
89
90
|
}} endContent={<>
|
|
90
|
-
<Button class="sheen-search-input-clear" type="button" disabled={others.disabled || others.readOnly || others.readonly || composition() !== undefined || !value()} onClick={() => {
|
|
91
|
+
<Button variant="ghost" class="sheen-search-input-clear" type="button" disabled={others.disabled || others.readOnly || others.readonly || composition() !== undefined || !value()} onClick={() => {
|
|
91
92
|
if (others.disabled || others.readOnly || others.readonly || composition() !== undefined || !value()) return;
|
|
92
93
|
update("");
|
|
93
94
|
if (input && input.value !== value()) input.value = value();
|
|
94
95
|
input?.focus();
|
|
95
|
-
}}>{local.clearLabel ?? theme.messages().clearSearch}</Button>
|
|
96
|
-
<
|
|
96
|
+
}}><Glyph name="close" /><span class="sheen-sr-only">{local.clearLabel ?? theme.messages().clearSearch}</span></Button>
|
|
97
|
+
<Glyph class="sheen-search-input-indicator" name="search" />
|
|
97
98
|
</>} />;
|
|
98
99
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { For, Show, createMemo, createSignal, createUniqueId, onCleanup, onMount, splitProps, untrack } from "solid-js";
|
|
1
|
+
import { For, Show, createEffect, createMemo, createSignal, createUniqueId, onCleanup, onMount, splitProps, untrack } from "solid-js";
|
|
2
2
|
import type { JSX } from "solid-js";
|
|
3
3
|
import { cn } from "../utils/cn.ts";
|
|
4
4
|
import { createChoiceOptions } from "./choice-options.ts";
|
|
@@ -25,12 +25,14 @@ export interface SegmentedControlProps extends Omit<JSX.FieldsetHTMLAttributes<H
|
|
|
25
25
|
orientation?: "horizontal" | "vertical";
|
|
26
26
|
size?: "sm" | "md";
|
|
27
27
|
overflowBehavior?: "scroll" | "wrap";
|
|
28
|
+
/** Stretch segments to share the container width equally, for short exclusive choices such as Buy/Sell. */
|
|
29
|
+
fullWidth?: boolean;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
/** A compact, native-radio single-selection control with roving focus. */
|
|
31
33
|
export function SegmentedControl(props: SegmentedControlProps): JSX.Element {
|
|
32
34
|
const generatedId = createUniqueId();
|
|
33
|
-
const [local, others] = splitProps(props, ["id", "ref", "class", "name", "label", "options", "value", "defaultValue", "onValueChange", "description", "error", "disabled", "readOnly", "required", "orientation", "size", "overflowBehavior", "form", "aria-label", "aria-labelledby", "aria-describedby"]);
|
|
35
|
+
const [local, others] = splitProps(props, ["id", "ref", "class", "name", "label", "options", "value", "defaultValue", "onValueChange", "description", "error", "disabled", "readOnly", "required", "orientation", "size", "overflowBehavior", "fullWidth", "form", "aria-label", "aria-labelledby", "aria-describedby"]);
|
|
34
36
|
const initialValue = local.defaultValue ?? null;
|
|
35
37
|
const [uncontrolled, setUncontrolled] = createSignal<string | null>(initialValue);
|
|
36
38
|
const value = () => local.value === undefined ? uncontrolled() : local.value;
|
|
@@ -107,9 +109,32 @@ export function SegmentedControl(props: SegmentedControlProps): JSX.Element {
|
|
|
107
109
|
pending.add(task);
|
|
108
110
|
};
|
|
109
111
|
element.ownerDocument.addEventListener("reset", reset, true);
|
|
112
|
+
const track = element.querySelector<HTMLElement>(".sheen-segmented-options");
|
|
113
|
+
const indicator = track?.querySelector<HTMLElement>(".sheen-segmented-indicator");
|
|
114
|
+
let frame = 0;
|
|
115
|
+
// The indicator follows the checked label; the static checked fill stays in server markup until the first placement.
|
|
116
|
+
const place = (): void => {
|
|
117
|
+
if (!track || !indicator) return;
|
|
118
|
+
const label = track.querySelector<HTMLElement>(".sheen-segmented-input:checked + .sheen-segmented-item-label");
|
|
119
|
+
indicator.hidden = !label;
|
|
120
|
+
if (!label) return;
|
|
121
|
+
// Each item is positioned, so the label's offsets are item-relative; add the item's offset within the track.
|
|
122
|
+
const item = label.parentElement;
|
|
123
|
+
const x = label.offsetLeft + (item?.offsetLeft ?? 0);
|
|
124
|
+
const y = label.offsetTop + (item?.offsetTop ?? 0);
|
|
125
|
+
indicator.style.translate = `${x}px ${y}px`;
|
|
126
|
+
indicator.style.inlineSize = `${label.offsetWidth}px`;
|
|
127
|
+
indicator.style.blockSize = `${label.offsetHeight}px`;
|
|
128
|
+
if (track.dataset.indicatorReady === undefined) frame = view.requestAnimationFrame(() => { track.dataset.indicatorReady = ""; });
|
|
129
|
+
};
|
|
130
|
+
createEffect(() => { value(); place(); });
|
|
131
|
+
const observer = new view.ResizeObserver(place);
|
|
132
|
+
if (track) observer.observe(track);
|
|
110
133
|
onCleanup(() => {
|
|
111
134
|
element.ownerDocument.removeEventListener("reset", reset, true);
|
|
112
135
|
for (const task of pending) view.clearTimeout(task);
|
|
136
|
+
observer.disconnect();
|
|
137
|
+
view.cancelAnimationFrame(frame);
|
|
113
138
|
});
|
|
114
139
|
});
|
|
115
140
|
const describedBy = () => [local.description ? `${generatedId}-description` : "", local.error ? `${generatedId}-error` : "", local["aria-describedby"]].filter(Boolean).join(" ") || undefined;
|
|
@@ -118,10 +143,10 @@ export function SegmentedControl(props: SegmentedControlProps): JSX.Element {
|
|
|
118
143
|
class={cn("sheen-segmented-control", local.class)} aria-labelledby={local["aria-labelledby"] ?? `${generatedId}-label`} aria-describedby={describedBy()}
|
|
119
144
|
aria-invalid={local.error ? "true" : undefined} aria-readonly={local.readOnly || undefined} aria-orientation={local.orientation ?? "horizontal"}
|
|
120
145
|
data-invalid={local.error ? "" : undefined} data-readonly={local.readOnly || undefined} data-size={local.size ?? "sm"}
|
|
121
|
-
data-overflow={local.overflowBehavior ?? "scroll"} disabled={local.disabled ?? false}>
|
|
146
|
+
data-overflow={local.overflowBehavior ?? "scroll"} data-full-width={local.fullWidth || undefined} disabled={local.disabled ?? false}>
|
|
122
147
|
<legend id={`${generatedId}-label`} class="sheen-segmented-label">{local.label}<Show when={local.required}><span aria-hidden="true"> *</span></Show></legend>
|
|
123
148
|
<Show when={local.description}><p id={`${generatedId}-description`} class="sheen-segmented-description">{local.description}</p></Show>
|
|
124
|
-
<div class="sheen-segmented-options"><For each={keys()}>{key => {
|
|
149
|
+
<div class="sheen-segmented-options"><span class="sheen-segmented-indicator" aria-hidden="true" hidden /><For each={keys()}>{key => {
|
|
125
150
|
const initialOption = untrack(() => byValue().get(key));
|
|
126
151
|
if (!initialOption) throw new Error("SegmentedControl: missing option during creation");
|
|
127
152
|
const option = () => byValue().get(key) ?? initialOption;
|
|
@@ -3,6 +3,7 @@ import { For, Show, createEffect, createMemo, createSignal, createUniqueId, onCl
|
|
|
3
3
|
import type { JSX } from "solid-js";
|
|
4
4
|
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
5
5
|
import { cn } from "../utils/cn.ts";
|
|
6
|
+
import { Glyph } from "./Glyph.tsx";
|
|
6
7
|
import { useShortcutKeyboardOwner } from "./ShortcutProvider.tsx";
|
|
7
8
|
|
|
8
9
|
export interface SelectOption {
|
|
@@ -130,7 +131,7 @@ export function Select(props: SelectProps): JSX.Element {
|
|
|
130
131
|
<Primitive.Trigger as={TriggerButton} data-sheen-select-trigger="" id={`${id}-trigger`} ref={setTrigger} form={local.form} class="sheen-input sheen-select-trigger"
|
|
131
132
|
onClick={event => { if (!local.disabled && (!event.currentTarget.dataset.pointerType || event.detail === 0)) setOpen(current => !current); }}>
|
|
132
133
|
<span id={`${id}-value`} data-placeholder={!selected() || undefined}>{selected()?.label ?? local.placeholder ?? theme.messages().selectOption}</span>
|
|
133
|
-
<
|
|
134
|
+
<Glyph name="chevron-down" class="sheen-select-chevron" />
|
|
134
135
|
</Primitive.Trigger>
|
|
135
136
|
<select id={`${id}-native`} ref={native} class="sheen-select-native" aria-hidden="true" tabIndex={-1} name={local.name} form={local.form}
|
|
136
137
|
required={local.required} disabled={local.disabled} aria-label={local.label}
|
|
@@ -160,7 +161,7 @@ export function Select(props: SelectProps): JSX.Element {
|
|
|
160
161
|
return <Primitive.Item item={collection().getItem(key) ?? initialItem} class="sheen-select-option">
|
|
161
162
|
<Primitive.ItemLabel>{options().get(key)?.label}</Primitive.ItemLabel>
|
|
162
163
|
<Show when={options().get(key)?.description}>{description => <Primitive.ItemDescription class="sheen-select-option-description">{description()}</Primitive.ItemDescription>}</Show>
|
|
163
|
-
<Primitive.ItemIndicator class="sheen-select-indicator" aria-hidden="true"
|
|
164
|
+
<Primitive.ItemIndicator class="sheen-select-indicator" aria-hidden="true"><Glyph name="check" /></Primitive.ItemIndicator>
|
|
164
165
|
</Primitive.Item>;
|
|
165
166
|
}}</For>}
|
|
166
167
|
</Primitive.Listbox>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext, createEffect, createMemo, createSignal, getOwner, onCleanup, onMount, useContext } from "solid-js";
|
|
2
2
|
import type { Accessor, JSX } from "solid-js";
|
|
3
|
-
import { createShortcutRegistry } from "../utils/shortcut-registry.ts";
|
|
3
|
+
import { createShortcutRegistry, formatShortcut } from "../utils/shortcut-registry.ts";
|
|
4
4
|
import { resolveShortcutPlatform } from "../utils/shortcut-platform.ts";
|
|
5
5
|
import type { PendingShortcut, ShortcutAction, ShortcutBinding, ShortcutDefinition } from "../utils/shortcut-registry.ts";
|
|
6
6
|
|
|
@@ -97,6 +97,19 @@ export function ShortcutProvider(props: ShortcutProviderProps): JSX.Element {
|
|
|
97
97
|
return <ShortcutContext.Provider value={{ registry, pending, bindings, characterShortcuts, acquireModal, acquireFocusScope, acquireKeyboardOwner }}>{props.children}</ShortcutContext.Provider>;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Platform display text for a shortcut definition (`mod+k` → `Ctrl+K`, or `⌘+K` on Apple platforms).
|
|
102
|
+
* Server markup and the first client frame use the non-Apple form; the platform resolves after mount.
|
|
103
|
+
*/
|
|
104
|
+
export function useShortcutLabel(keys: Accessor<string | undefined>): Accessor<string | undefined> {
|
|
105
|
+
const [platform, setPlatform] = createSignal<"mac" | "other">("other");
|
|
106
|
+
onMount(() => setPlatform(resolveShortcutPlatform(navigator.platform)));
|
|
107
|
+
return () => {
|
|
108
|
+
const value = keys();
|
|
109
|
+
return value === undefined ? undefined : formatShortcut(value, platform());
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
100
113
|
/** Register in the nearest provider and release the binding with its Solid owner. */
|
|
101
114
|
export function useShortcut(definition: ShortcutDefinition): void {
|
|
102
115
|
const context = useContext(ShortcutContext);
|
|
@@ -22,7 +22,7 @@ export function ShortcutSheet(props: ShortcutSheetProps): JSX.Element {
|
|
|
22
22
|
<Heading level={3}>{group}</Heading>
|
|
23
23
|
<dl class="sheen-shortcut-bindings">
|
|
24
24
|
<For each={bindings().filter(binding => binding.group === group).map(binding => binding.id)}>{id => <Show when={records().get(id)}>{binding => <div>
|
|
25
|
-
<dt><Text>{binding().label}</Text><Text tone="muted">{binding().scope}</Text></dt>
|
|
25
|
+
<dt><Text>{binding().label}</Text><Show when={binding().scope !== "global"}><Text tone="muted">{binding().scope}</Text></Show></dt>
|
|
26
26
|
<dd><Kbd>{binding().displayKeys}</Kbd>
|
|
27
27
|
<Show when={binding().shadowed}><Text tone="muted">{theme.messages().shortcutShadowed}</Text></Show>
|
|
28
28
|
<Show when={binding().characterOnly && !characters()}><Text tone="muted">{theme.messages().shortcutDisabled}</Text></Show>
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { For, Show, batch, createEffect, createMemo, createSignal, createUniqueId, onCleanup, onMount, splitProps } from "solid-js";
|
|
2
|
+
import type { Accessor, JSX } from "solid-js";
|
|
3
|
+
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
4
|
+
import { useNumberFormatter } from "../theme/intl.ts";
|
|
5
|
+
import { cn } from "../utils/cn.ts";
|
|
6
|
+
import { closestEdge, dropIndex, edgeField, formatMessage, isRtl, keyIntent, moveId, resolveSortableMessages, scrollContainers, stringField, validateIds } from "./sortable-core.ts";
|
|
7
|
+
import type { SortableEdge, SortableItem, SortableMessages, SortableOrientation, SortableReorder } from "./sortable-core.ts";
|
|
8
|
+
import { bindDraggable, bindDropTarget, bindMonitor } from "./sortable-drag.ts";
|
|
9
|
+
import type { DragData } from "./sortable-drag.ts";
|
|
10
|
+
import { Glyph } from "./Glyph.tsx";
|
|
11
|
+
|
|
12
|
+
export type SortableListProps<Item extends SortableItem> = Omit<JSX.HTMLAttributes<HTMLDivElement>, "children" | "ref" | "onDrop"> & {
|
|
13
|
+
ref?: HTMLDivElement | ((element: HTMLDivElement) => void);
|
|
14
|
+
/** Owner-ordered items with stable, unique ids. Item nodes are keyed by id and survive refreshes and reorders. */
|
|
15
|
+
items: readonly Item[];
|
|
16
|
+
children: (item: Accessor<Item>, index: Accessor<number>) => JSX.Element;
|
|
17
|
+
/** Proposes a new order. The list is controlled: nothing moves until the owner passes reordered items back. */
|
|
18
|
+
onReorder: (reorder: SortableReorder) => void;
|
|
19
|
+
/** Accessible name for the list. */
|
|
20
|
+
label: string;
|
|
21
|
+
orientation?: SortableOrientation;
|
|
22
|
+
/** Render a grip button that owns pointer and keyboard dragging. Without it the whole item drags and takes focus. */
|
|
23
|
+
handle?: boolean;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
messages?: Partial<SortableMessages>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
interface Lift { readonly id: string; readonly origin: number; readonly target: number }
|
|
29
|
+
interface DropIndicator { readonly id: string; readonly edge: SortableEdge }
|
|
30
|
+
|
|
31
|
+
function sameIndicator(first: DropIndicator | undefined, second: DropIndicator | undefined): boolean {
|
|
32
|
+
return first?.id === second?.id && first?.edge === second?.edge;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A controlled reorderable list with pointer dragging, auto-scroll, and an announced keyboard model. */
|
|
36
|
+
export function SortableList<Item extends SortableItem>(props: SortableListProps<Item>): JSX.Element {
|
|
37
|
+
const theme = useTheme();
|
|
38
|
+
const formatter = useNumberFormatter();
|
|
39
|
+
const generatedId = createUniqueId();
|
|
40
|
+
const instance = Symbol("SortableList");
|
|
41
|
+
const [local, others] = splitProps(props, ["ref", "class", "items", "children", "onReorder", "label", "orientation", "handle", "disabled", "messages", "aria-describedby"]);
|
|
42
|
+
const messages = createMemo(() => resolveSortableMessages(theme.messages(), local.messages));
|
|
43
|
+
const index = createMemo(() => {
|
|
44
|
+
validateIds(local.items.map(item => item.id), "SortableList");
|
|
45
|
+
return new Map(local.items.map(item => [item.id, item]));
|
|
46
|
+
});
|
|
47
|
+
const owned = createMemo(() => [...index().keys()]);
|
|
48
|
+
const [lift, setLift] = createSignal<Lift>();
|
|
49
|
+
const [indicator, setIndicator] = createSignal<DropIndicator>();
|
|
50
|
+
const [dragging, setDragging] = createSignal<string>();
|
|
51
|
+
const [announcement, setAnnouncement] = createSignal("");
|
|
52
|
+
// A refresh that removes the lifted item ends the lift; the remaining order is the owner's.
|
|
53
|
+
const activeLift = createMemo(() => {
|
|
54
|
+
const current = lift();
|
|
55
|
+
return current && index().has(current.id) ? current : undefined;
|
|
56
|
+
});
|
|
57
|
+
const ids = createMemo(() => {
|
|
58
|
+
const current = activeLift();
|
|
59
|
+
return current ? moveId(owned(), current.id, current.target) : owned();
|
|
60
|
+
});
|
|
61
|
+
const orientation = () => local.orientation ?? "vertical";
|
|
62
|
+
const instructionsId = `${generatedId}-instructions`;
|
|
63
|
+
let root: HTMLDivElement | undefined;
|
|
64
|
+
let relocating = false;
|
|
65
|
+
let disposed = false;
|
|
66
|
+
onCleanup(() => { disposed = true; });
|
|
67
|
+
|
|
68
|
+
const itemDisabled = (id: string) => Boolean(local.disabled || index().get(id)?.disabled);
|
|
69
|
+
const accepts = (source: DragData) => source.sortableInstance === instance;
|
|
70
|
+
const keyboardTarget = (id: string): HTMLElement | undefined => {
|
|
71
|
+
const item = [...root?.querySelectorAll<HTMLElement>(".sheen-sortable-item") ?? []].find(element => element.dataset.sortableId === id);
|
|
72
|
+
return local.handle ? item?.querySelector<HTMLElement>(".sheen-sortable-handle") ?? undefined : item;
|
|
73
|
+
};
|
|
74
|
+
const announce = (template: string, id: string, position: number) => {
|
|
75
|
+
const values = { label: index().get(id)?.label ?? id, position: formatter().format(position + 1), count: formatter().format(ids().length) };
|
|
76
|
+
setAnnouncement("");
|
|
77
|
+
queueMicrotask(() => { if (!disposed) setAnnouncement(formatMessage(template, values)); });
|
|
78
|
+
};
|
|
79
|
+
// Reordering moves the focused node in the DOM, which blurs it; restore focus without treating that blur as leaving.
|
|
80
|
+
const relocate = (id: string, update: () => void) => {
|
|
81
|
+
relocating = true;
|
|
82
|
+
try { update(); }
|
|
83
|
+
finally {
|
|
84
|
+
const target = keyboardTarget(id);
|
|
85
|
+
if (target && target.ownerDocument.activeElement !== target) target.focus();
|
|
86
|
+
relocating = false;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const propose = (id: string, fromIndex: number, toIndex: number) => {
|
|
90
|
+
if (fromIndex === toIndex || fromIndex < 0) return;
|
|
91
|
+
local.onReorder({ id, fromIndex, toIndex, ids: moveId(owned(), id, toIndex) });
|
|
92
|
+
};
|
|
93
|
+
const cancel = () => {
|
|
94
|
+
const current = activeLift();
|
|
95
|
+
setLift(undefined);
|
|
96
|
+
if (current) announce(messages().sortableCancelled, current.id, current.origin);
|
|
97
|
+
};
|
|
98
|
+
const onKeyDown = (id: string, event: KeyboardEvent, element: HTMLElement) => {
|
|
99
|
+
if (event.target !== element || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
100
|
+
const intent = keyIntent(event.key, isRtl(element));
|
|
101
|
+
const current = activeLift();
|
|
102
|
+
if (!intent) return;
|
|
103
|
+
if (!current) {
|
|
104
|
+
if (intent.kind !== "toggle" || itemDisabled(id)) return;
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
const origin = owned().indexOf(id);
|
|
107
|
+
setLift({ id, origin, target: origin });
|
|
108
|
+
announce(messages().sortableLifted, id, origin);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (current.id !== id) return;
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
if (intent.kind === "toggle") {
|
|
114
|
+
relocate(id, () => batch(() => { propose(id, current.origin, current.target); setLift(undefined); }));
|
|
115
|
+
announce(messages().sortableDropped, id, current.target);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (intent.kind === "cancel") { relocate(id, cancel); return; }
|
|
119
|
+
if (intent.kind === "step" && intent.axis !== orientation()) return;
|
|
120
|
+
const last = ids().length - 1;
|
|
121
|
+
const target = intent.kind === "edge" ? (intent.to === "start" ? 0 : last) : Math.max(0, Math.min(last, current.target + intent.delta));
|
|
122
|
+
if (target === current.target) return;
|
|
123
|
+
relocate(id, () => setLift({ ...current, target }));
|
|
124
|
+
announce(messages().sortableMoved, id, target);
|
|
125
|
+
};
|
|
126
|
+
const onFocusOut = (id: string, event: FocusEvent, element: HTMLElement) => {
|
|
127
|
+
if (relocating || activeLift()?.id !== id) return;
|
|
128
|
+
if (event.relatedTarget instanceof Node && element.contains(event.relatedTarget)) return;
|
|
129
|
+
cancel();
|
|
130
|
+
};
|
|
131
|
+
const resolveDrop = (source: DragData, target: DragData | undefined) => {
|
|
132
|
+
const sourceId = stringField(source, "sortableId");
|
|
133
|
+
const targetId = target ? stringField(target, "sortableId") : undefined;
|
|
134
|
+
const edge = target ? edgeField(target) : undefined;
|
|
135
|
+
if (!sourceId || !targetId || !edge) return undefined;
|
|
136
|
+
const from = ids().indexOf(sourceId);
|
|
137
|
+
return { sourceId, targetId, edge, from, to: dropIndex(from, ids().indexOf(targetId), edge) };
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
onMount(() => {
|
|
141
|
+
if (!root) return;
|
|
142
|
+
const element = root;
|
|
143
|
+
onCleanup(bindMonitor({
|
|
144
|
+
accepts,
|
|
145
|
+
scrollers: () => scrollContainers(element),
|
|
146
|
+
onDrag: (source, target) => {
|
|
147
|
+
const drop = resolveDrop(source, target);
|
|
148
|
+
const next = drop && drop.to !== drop.from ? { id: drop.targetId, edge: drop.edge } : undefined;
|
|
149
|
+
if (!sameIndicator(indicator(), next)) setIndicator(next);
|
|
150
|
+
},
|
|
151
|
+
onDrop: (source, target) => {
|
|
152
|
+
setIndicator(undefined);
|
|
153
|
+
const drop = resolveDrop(source, target);
|
|
154
|
+
if (!drop || drop.to === drop.from) return;
|
|
155
|
+
propose(drop.sourceId, drop.from, drop.to);
|
|
156
|
+
announce(messages().sortableDropped, drop.sourceId, drop.to);
|
|
157
|
+
},
|
|
158
|
+
}));
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
return <div {...others} ref={element => { root = element; if (typeof local.ref === "function") local.ref(element); }} class={cn("sheen-sortable", local.class)}
|
|
162
|
+
data-orientation={orientation()} data-disabled={local.disabled ? "" : undefined} data-active={activeLift() || dragging() ? "" : undefined}>
|
|
163
|
+
<ul class="sheen-sortable-list" role="list" aria-label={local.label} aria-describedby={[instructionsId, local["aria-describedby"]].filter(Boolean).join(" ")}>
|
|
164
|
+
<For each={ids()}>{(id, position) => {
|
|
165
|
+
const initial = index().get(id);
|
|
166
|
+
if (!initial) throw new Error(`SortableList: missing item ${JSON.stringify(id)}`);
|
|
167
|
+
let last = initial;
|
|
168
|
+
const item = () => { const value = index().get(id); if (value) last = value; return last; };
|
|
169
|
+
const disabled = () => itemDisabled(id);
|
|
170
|
+
const lifted = () => activeLift()?.id === id;
|
|
171
|
+
const ownKeys = () => !local.handle;
|
|
172
|
+
let element: HTMLLIElement | undefined;
|
|
173
|
+
let handle: HTMLButtonElement | undefined;
|
|
174
|
+
createEffect(() => {
|
|
175
|
+
if (!element) return;
|
|
176
|
+
const target = element;
|
|
177
|
+
const dragHandle = local.handle ? handle : undefined;
|
|
178
|
+
const release = [
|
|
179
|
+
bindDraggable({
|
|
180
|
+
element: target, handle: dragHandle, canDrag: () => !disabled() && !activeLift(),
|
|
181
|
+
data: () => ({ sortableInstance: instance, sortableId: id }),
|
|
182
|
+
onStart: () => setDragging(id), onEnd: () => setDragging(undefined),
|
|
183
|
+
}),
|
|
184
|
+
bindDropTarget({ element: target, accepts, data: input => ({ sortableId: id, edge: closestEdge(target, input, orientation()) }) }),
|
|
185
|
+
];
|
|
186
|
+
onCleanup(() => { for (const cleanup of release) cleanup(); });
|
|
187
|
+
});
|
|
188
|
+
return <li ref={element} class="sheen-sortable-item" data-sortable-id={id}
|
|
189
|
+
data-disabled={disabled() ? "" : undefined} data-lifted={lifted() ? "" : undefined} data-dragging={dragging() === id ? "" : undefined}
|
|
190
|
+
data-drop-edge={indicator()?.id === id ? indicator()?.edge : undefined}
|
|
191
|
+
tabindex={ownKeys() && !disabled() ? 0 : undefined} aria-describedby={ownKeys() ? instructionsId : undefined} aria-disabled={ownKeys() && disabled() ? "true" : undefined}
|
|
192
|
+
onKeyDown={event => { if (ownKeys()) onKeyDown(id, event, event.currentTarget); }}
|
|
193
|
+
onFocusOut={event => { if (ownKeys()) onFocusOut(id, event, event.currentTarget); }}>
|
|
194
|
+
<Show when={local.handle}>
|
|
195
|
+
<button ref={handle} type="button" class="sheen-sortable-handle" aria-label={formatMessage(messages().sortableHandle, { label: item().label })} aria-describedby={instructionsId}
|
|
196
|
+
aria-pressed={lifted() ? "true" : "false"} disabled={disabled()}
|
|
197
|
+
onKeyDown={event => onKeyDown(id, event, event.currentTarget)} onFocusOut={event => onFocusOut(id, event, event.currentTarget)}>
|
|
198
|
+
<Glyph class="sheen-sortable-grip" name="grip" />
|
|
199
|
+
</button>
|
|
200
|
+
</Show>
|
|
201
|
+
<div class="sheen-sortable-content">{local.children(item, position)}</div>
|
|
202
|
+
</li>;
|
|
203
|
+
}}</For>
|
|
204
|
+
</ul>
|
|
205
|
+
<span id={instructionsId} class="sheen-sortable-hidden">{messages().sortableInstructions}</span>
|
|
206
|
+
<span class="sheen-sortable-hidden" role="status" aria-live="assertive" aria-atomic="true">{announcement()}</span>
|
|
207
|
+
</div>;
|
|
208
|
+
}
|
|
@@ -27,7 +27,7 @@ export function Tag(props: TagProps): JSX.Element {
|
|
|
27
27
|
return <Badge {...others} class={cn("sheen-tag", local.class)} data-disabled={local.disabled || undefined}>
|
|
28
28
|
<span>{local.children ?? local.label}</span>
|
|
29
29
|
<Show when={local.onRemove}>
|
|
30
|
-
<Button class="sheen-tag-remove" size="xs" disabled={local.disabled} aria-label={local.removeLabel ?? `${theme.messages().remove} ${local.label}`} onClick={() => local.onRemove?.()}>{theme.messages().remove}</Button>
|
|
30
|
+
<Button variant="ghost" class="sheen-tag-remove" size="xs" disabled={local.disabled} aria-label={local.removeLabel ?? `${theme.messages().remove} ${local.label}`} onClick={() => local.onRemove?.()}>{theme.messages().remove}</Button>
|
|
31
31
|
</Show>
|
|
32
32
|
</Badge>;
|
|
33
33
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { For, Show, createMemo, splitProps } from "solid-js";
|
|
2
|
+
import { Glyph } from "./Glyph.tsx";
|
|
2
3
|
import type { Accessor, JSX } from "solid-js";
|
|
3
4
|
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
4
5
|
import { cn } from "../utils/cn.ts";
|
|
@@ -53,8 +54,8 @@ function StepLabel(props: { readonly step: Accessor<StepperStep> }): JSX.Element
|
|
|
53
54
|
if (step.kind === "action" && !step.disabled) step.onSelect();
|
|
54
55
|
};
|
|
55
56
|
return <Show when={props.step().kind === "link"} fallback={<Show when={props.step().kind === "action"} fallback={<strong>{props.step().label}</strong>}>
|
|
56
|
-
<Button variant="
|
|
57
|
-
</Show>}><Link href={href()}>{props.step().label}</Link></Show>;
|
|
57
|
+
<Button variant="ghost" class="sheen-stepper-action" disabled={actionDisabled()} onClick={select}>{props.step().label}</Button>
|
|
58
|
+
</Show>}><Link variant="quiet" href={href()}>{props.step().label}</Link></Show>;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/** A semantic workflow progress list with native link and action variants. */
|
|
@@ -83,15 +84,14 @@ export function Stepper(props: StepperProps): JSX.Element {
|
|
|
83
84
|
if (state === "error") return theme.messages().workflowError;
|
|
84
85
|
return theme.messages().workflowUpcoming;
|
|
85
86
|
};
|
|
86
|
-
const marker = (state: WorkflowState, index: number):
|
|
87
|
-
if (state === "completed") return "
|
|
88
|
-
if (state === "
|
|
89
|
-
if (state === "error") return "!";
|
|
87
|
+
const marker = (state: WorkflowState, index: number): JSX.Element => {
|
|
88
|
+
if (state === "completed") return <Glyph name="check" />;
|
|
89
|
+
if (state === "error") return <Glyph name="alert" />;
|
|
90
90
|
return String(index + 1);
|
|
91
91
|
};
|
|
92
92
|
return <nav {...others} ref={element => { if (typeof local.ref === "function") local.ref(element); }} class={cn("sheen-stepper", local.class)} aria-label={local["aria-label"] ?? local.label}
|
|
93
93
|
aria-busy={local.refreshing || undefined} data-orientation={local.orientation ?? "horizontal"} data-density={local.density ?? "default"} data-refreshing={local.refreshing || undefined}>
|
|
94
|
-
<progress class="sheen-stepper-progress" max={Math.max(1, ids().length)} value={completed()} aria-label={theme.messages().stepperProgress.replaceAll("{label}", local.label)} />
|
|
94
|
+
<progress class="sheen-stepper-progress sheen-sr-only" max={Math.max(1, ids().length)} value={completed()} aria-label={theme.messages().stepperProgress.replaceAll("{label}", local.label)} />
|
|
95
95
|
<ol class="sheen-stepper-list"><For each={ids()}>{(id, index) => {
|
|
96
96
|
const step = () => byId().get(id);
|
|
97
97
|
return <Show when={step()}>{current => <li class="sheen-stepper-step" data-step-id={id} data-state={current().state} aria-current={current().state === "current" ? "step" : undefined}>
|