@gemologic/sheen 0.1.0-rc.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/LICENSE +19 -0
- package/README.md +32 -0
- package/dist/core.d.ts +52 -0
- package/dist/core.js +29 -0
- package/dist/formisch.d.ts +5 -0
- package/dist/formisch.js +22 -0
- package/dist/forms.d.ts +34 -0
- package/dist/forms.js +18 -0
- package/dist/index.d.ts +144 -0
- package/dist/index.js +75 -0
- package/dist/layout/Layout.d.ts +28 -0
- package/dist/layout/Layout.js +121 -0
- package/dist/metadata.d.ts +46 -0
- package/dist/metadata.js +47 -0
- package/dist/navigation.d.ts +30 -0
- package/dist/navigation.js +16 -0
- package/dist/overlays.d.ts +28 -0
- package/dist/overlays.js +15 -0
- package/dist/primitives/Accordion.d.ts +16 -0
- package/dist/primitives/Accordion.js +223 -0
- package/dist/primitives/ActivityTimeline.d.ts +20 -0
- package/dist/primitives/ActivityTimeline.js +104 -0
- package/dist/primitives/AlertDialog.d.ts +7 -0
- package/dist/primitives/AlertDialog.js +8 -0
- package/dist/primitives/Avatar.d.ts +22 -0
- package/dist/primitives/Avatar.js +115 -0
- package/dist/primitives/Breadcrumb.d.ts +11 -0
- package/dist/primitives/Breadcrumb.js +66 -0
- package/dist/primitives/Button.d.ts +11 -0
- package/dist/primitives/Button.js +59 -0
- package/dist/primitives/ButtonGroup.d.ts +7 -0
- package/dist/primitives/ButtonGroup.js +33 -0
- package/dist/primitives/Checkbox.d.ts +22 -0
- package/dist/primitives/Checkbox.js +93 -0
- package/dist/primitives/CheckboxGroup.d.ts +18 -0
- package/dist/primitives/CheckboxGroup.js +122 -0
- package/dist/primitives/Collapsible.d.ts +9 -0
- package/dist/primitives/Collapsible.js +72 -0
- package/dist/primitives/Combobox.d.ts +41 -0
- package/dist/primitives/Combobox.js +684 -0
- package/dist/primitives/CommandPalette.d.ts +42 -0
- package/dist/primitives/CommandPalette.js +319 -0
- package/dist/primitives/ConfirmDialog.d.ts +11 -0
- package/dist/primitives/ConfirmDialog.js +42 -0
- package/dist/primitives/ContextMenu.d.ts +16 -0
- package/dist/primitives/ContextMenu.js +132 -0
- package/dist/primitives/DescriptionList.d.ts +11 -0
- package/dist/primitives/DescriptionList.js +44 -0
- package/dist/primitives/Dialog.d.ts +21 -0
- package/dist/primitives/Dialog.js +141 -0
- package/dist/primitives/Drawer.d.ts +9 -0
- package/dist/primitives/Drawer.js +21 -0
- package/dist/primitives/DropdownMenu.d.ts +59 -0
- package/dist/primitives/DropdownMenu.js +441 -0
- package/dist/primitives/EditableTextField.d.ts +11 -0
- package/dist/primitives/EditableTextField.js +126 -0
- package/dist/primitives/EmptyState.d.ts +7 -0
- package/dist/primitives/EmptyState.js +45 -0
- package/dist/primitives/Field.d.ts +18 -0
- package/dist/primitives/Field.js +72 -0
- package/dist/primitives/FileDropzone.d.ts +40 -0
- package/dist/primitives/FileDropzone.js +261 -0
- package/dist/primitives/IconButton.d.ts +8 -0
- package/dist/primitives/IconButton.js +34 -0
- package/dist/primitives/Input.d.ts +7 -0
- package/dist/primitives/Input.js +55 -0
- package/dist/primitives/InputGroup.d.ts +7 -0
- package/dist/primitives/InputGroup.js +73 -0
- package/dist/primitives/Link.d.ts +7 -0
- package/dist/primitives/Link.js +35 -0
- package/dist/primitives/LinkTooltip.d.ts +11 -0
- package/dist/primitives/LinkTooltip.js +88 -0
- package/dist/primitives/NavList.d.ts +17 -0
- package/dist/primitives/NavList.js +143 -0
- package/dist/primitives/Notice.d.ts +8 -0
- package/dist/primitives/Notice.js +64 -0
- package/dist/primitives/NumberField.d.ts +22 -0
- package/dist/primitives/NumberField.js +177 -0
- package/dist/primitives/Pagination.d.ts +12 -0
- package/dist/primitives/Pagination.js +127 -0
- package/dist/primitives/Popover.d.ts +12 -0
- package/dist/primitives/Popover.js +103 -0
- package/dist/primitives/Progress.d.ts +17 -0
- package/dist/primitives/Progress.js +98 -0
- package/dist/primitives/RadioGroup.d.ts +19 -0
- package/dist/primitives/RadioGroup.js +173 -0
- package/dist/primitives/Resizable.d.ts +36 -0
- package/dist/primitives/Resizable.js +196 -0
- package/dist/primitives/ScrollArea.d.ts +6 -0
- package/dist/primitives/ScrollArea.js +178 -0
- package/dist/primitives/SearchInput.d.ts +12 -0
- package/dist/primitives/SearchInput.js +89 -0
- package/dist/primitives/SegmentedControl.d.ts +25 -0
- package/dist/primitives/SegmentedControl.js +188 -0
- package/dist/primitives/Select.d.ts +24 -0
- package/dist/primitives/Select.js +320 -0
- package/dist/primitives/Separator.d.ts +6 -0
- package/dist/primitives/Separator.js +31 -0
- package/dist/primitives/ShortcutPending.d.ts +6 -0
- package/dist/primitives/ShortcutPending.js +40 -0
- package/dist/primitives/ShortcutProvider.d.ts +32 -0
- package/dist/primitives/ShortcutProvider.js +172 -0
- package/dist/primitives/ShortcutScope.d.ts +6 -0
- package/dist/primitives/ShortcutScope.js +29 -0
- package/dist/primitives/ShortcutSheet.d.ts +5 -0
- package/dist/primitives/ShortcutSheet.js +87 -0
- package/dist/primitives/Skeleton.d.ts +5 -0
- package/dist/primitives/Skeleton.js +23 -0
- package/dist/primitives/Slider.d.ts +35 -0
- package/dist/primitives/Slider.js +210 -0
- package/dist/primitives/Spinner.d.ts +7 -0
- package/dist/primitives/Spinner.js +44 -0
- package/dist/primitives/Status.d.ts +15 -0
- package/dist/primitives/Status.js +78 -0
- package/dist/primitives/Stepper.d.ts +32 -0
- package/dist/primitives/Stepper.js +147 -0
- package/dist/primitives/Surface.d.ts +11 -0
- package/dist/primitives/Surface.js +58 -0
- package/dist/primitives/Switch.d.ts +4 -0
- package/dist/primitives/Switch.js +7 -0
- package/dist/primitives/Table.d.ts +23 -0
- package/dist/primitives/Table.js +101 -0
- package/dist/primitives/Tabs.d.ts +17 -0
- package/dist/primitives/Tabs.js +157 -0
- package/dist/primitives/TagInput.d.ts +33 -0
- package/dist/primitives/TagInput.js +288 -0
- package/dist/primitives/Textarea.d.ts +8 -0
- package/dist/primitives/Textarea.js +106 -0
- package/dist/primitives/Toast.d.ts +10 -0
- package/dist/primitives/Toast.js +78 -0
- package/dist/primitives/Toaster.d.ts +9 -0
- package/dist/primitives/Toaster.js +183 -0
- package/dist/primitives/Tooltip.d.ts +13 -0
- package/dist/primitives/Tooltip.js +84 -0
- package/dist/primitives/Tree.d.ts +23 -0
- package/dist/primitives/Tree.js +275 -0
- package/dist/primitives/Typography.d.ts +16 -0
- package/dist/primitives/Typography.js +82 -0
- package/dist/primitives/boolean-input-state.d.ts +14 -0
- package/dist/primitives/boolean-input-state.js +39 -0
- package/dist/primitives/button-variants.d.ts +9 -0
- package/dist/primitives/button-variants.js +7 -0
- package/dist/primitives/choice-options.d.ts +7 -0
- package/dist/primitives/choice-options.js +35 -0
- package/dist/primitives/create-confirm.d.ts +15 -0
- package/dist/primitives/create-confirm.js +49 -0
- package/dist/primitives/create-toaster.d.ts +51 -0
- package/dist/primitives/create-toaster.js +87 -0
- package/dist/primitives/link-focus.d.ts +2 -0
- package/dist/primitives/link-focus.js +38 -0
- package/dist/primitives/menu-focus.d.ts +3 -0
- package/dist/primitives/menu-focus.js +32 -0
- package/dist/primitives/tooltip-layer.d.ts +14 -0
- package/dist/primitives/tooltip-layer.js +84 -0
- package/dist/theme/ThemeProvider.d.ts +59 -0
- package/dist/theme/ThemeProvider.js +239 -0
- package/dist/theme/intl.d.ts +6 -0
- package/dist/theme/intl.js +13 -0
- package/dist/theme/keyboard-script.d.ts +2 -0
- package/dist/theme/keyboard-script.js +6 -0
- package/dist/theme/layers.d.ts +7 -0
- package/dist/theme/layers.js +23 -0
- package/dist/theme/messages.d.ts +235 -0
- package/dist/theme/messages.js +115 -0
- package/dist/theme/script.d.ts +9 -0
- package/dist/theme/script.js +49 -0
- package/dist/theme/state.d.ts +27 -0
- package/dist/theme/state.js +55 -0
- package/dist/utils/browser-status.d.ts +5 -0
- package/dist/utils/browser-status.js +22 -0
- package/dist/utils/cn.d.ts +3 -0
- package/dist/utils/cn.js +7 -0
- package/dist/utils/optimistic.d.ts +6 -0
- package/dist/utils/optimistic.js +16 -0
- package/dist/utils/polymorphic.d.ts +1 -0
- package/dist/utils/shortcut-platform.d.ts +2 -0
- package/dist/utils/shortcut-platform.js +10 -0
- package/dist/utils/shortcut-registry.d.ts +61 -0
- package/dist/utils/shortcut-registry.js +186 -0
- package/package.json +100 -0
- package/src/core.ts +55 -0
- package/src/formisch.ts +28 -0
- package/src/forms.ts +34 -0
- package/src/index.ts +144 -0
- package/src/layout/Layout.tsx +43 -0
- package/src/metadata.d.ts +46 -0
- package/src/metadata.ts +66 -0
- package/src/navigation.ts +30 -0
- package/src/overlays.ts +28 -0
- package/src/primitives/Accordion.tsx +145 -0
- package/src/primitives/ActivityTimeline.tsx +72 -0
- package/src/primitives/AlertDialog.tsx +8 -0
- package/src/primitives/Avatar.tsx +85 -0
- package/src/primitives/Breadcrumb.tsx +41 -0
- package/src/primitives/Button.tsx +27 -0
- package/src/primitives/ButtonGroup.tsx +18 -0
- package/src/primitives/Checkbox.tsx +51 -0
- package/src/primitives/CheckboxGroup.tsx +73 -0
- package/src/primitives/Collapsible.tsx +43 -0
- package/src/primitives/Combobox.tsx +402 -0
- package/src/primitives/CommandPalette.tsx +234 -0
- package/src/primitives/ConfirmDialog.tsx +25 -0
- package/src/primitives/ContextMenu.tsx +100 -0
- package/src/primitives/DescriptionList.tsx +26 -0
- package/src/primitives/Dialog.tsx +81 -0
- package/src/primitives/Drawer.tsx +26 -0
- package/src/primitives/DropdownMenu.tsx +221 -0
- package/src/primitives/EditableTextField.tsx +91 -0
- package/src/primitives/EmptyState.tsx +21 -0
- package/src/primitives/Field.tsx +38 -0
- package/src/primitives/FileDropzone.tsx +189 -0
- package/src/primitives/IconButton.tsx +22 -0
- package/src/primitives/Input.tsx +17 -0
- package/src/primitives/InputGroup.tsx +23 -0
- package/src/primitives/Link.tsx +19 -0
- package/src/primitives/LinkTooltip.tsx +31 -0
- package/src/primitives/NavList.tsx +58 -0
- package/src/primitives/Notice.tsx +25 -0
- package/src/primitives/NumberField.tsx +168 -0
- package/src/primitives/Pagination.tsx +64 -0
- package/src/primitives/Popover.tsx +44 -0
- package/src/primitives/Progress.tsx +62 -0
- package/src/primitives/RadioGroup.tsx +104 -0
- package/src/primitives/Resizable.tsx +170 -0
- package/src/primitives/ScrollArea.tsx +115 -0
- package/src/primitives/SearchInput.tsx +98 -0
- package/src/primitives/SegmentedControl.tsx +140 -0
- package/src/primitives/Select.tsx +171 -0
- package/src/primitives/Separator.tsx +13 -0
- package/src/primitives/ShortcutPending.tsx +21 -0
- package/src/primitives/ShortcutProvider.tsx +179 -0
- package/src/primitives/ShortcutScope.tsx +17 -0
- package/src/primitives/ShortcutSheet.tsx +35 -0
- package/src/primitives/Skeleton.tsx +12 -0
- package/src/primitives/Slider.tsx +153 -0
- package/src/primitives/Spinner.tsx +19 -0
- package/src/primitives/Status.tsx +33 -0
- package/src/primitives/Stepper.tsx +106 -0
- package/src/primitives/Surface.tsx +21 -0
- package/src/primitives/Switch.tsx +9 -0
- package/src/primitives/Table.tsx +57 -0
- package/src/primitives/Tabs.tsx +96 -0
- package/src/primitives/TagInput.tsx +282 -0
- package/src/primitives/Textarea.tsx +77 -0
- package/src/primitives/Toast.tsx +36 -0
- package/src/primitives/Toaster.tsx +175 -0
- package/src/primitives/Tooltip.tsx +41 -0
- package/src/primitives/Tree.tsx +256 -0
- package/src/primitives/Typography.tsx +39 -0
- package/src/primitives/boolean-input-state.ts +65 -0
- package/src/primitives/button-variants.ts +20 -0
- package/src/primitives/choice-options.ts +39 -0
- package/src/primitives/create-confirm.tsx +56 -0
- package/src/primitives/create-toaster.ts +128 -0
- package/src/primitives/link-focus.ts +38 -0
- package/src/primitives/menu-focus.ts +43 -0
- package/src/primitives/tooltip-layer.tsx +53 -0
- package/src/styles.css +655 -0
- package/src/theme/ThemeProvider.tsx +215 -0
- package/src/theme/intl.ts +14 -0
- package/src/theme/keyboard-script.ts +4 -0
- package/src/theme/layers.ts +16 -0
- package/src/theme/messages.ts +157 -0
- package/src/theme/script.ts +70 -0
- package/src/theme/state.ts +48 -0
- package/src/utils/browser-status.ts +36 -0
- package/src/utils/cn.ts +5 -0
- package/src/utils/optimistic.ts +22 -0
- package/src/utils/polymorphic.ts +1 -0
- package/src/utils/shortcut-platform.ts +4 -0
- package/src/utils/shortcut-registry.ts +216 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createEffect, createMemo, createSignal, onCleanup, onMount } from "solid-js";
|
|
2
|
+
|
|
3
|
+
interface BooleanInputOptions {
|
|
4
|
+
checked?: boolean;
|
|
5
|
+
defaultChecked?: boolean;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
readOnly?: boolean;
|
|
8
|
+
indeterminate?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Shared ownership for native boolean inputs, including pre-hydration edits and reset. */
|
|
12
|
+
export function createBooleanInputState(options: BooleanInputOptions, onChange: (next: boolean) => void) {
|
|
13
|
+
const initialChecked = options.defaultChecked ?? false;
|
|
14
|
+
const [draft, setDraft] = createSignal(initialChecked);
|
|
15
|
+
const controlled = createMemo(() => options.checked);
|
|
16
|
+
const checked = () => controlled() ?? draft();
|
|
17
|
+
const [mounted, setMounted] = createSignal(false);
|
|
18
|
+
let input: HTMLInputElement | undefined;
|
|
19
|
+
const change = (next: boolean) => {
|
|
20
|
+
if (next === checked()) return;
|
|
21
|
+
if (controlled() === undefined) setDraft(next);
|
|
22
|
+
onChange(next);
|
|
23
|
+
};
|
|
24
|
+
onMount(() => {
|
|
25
|
+
const element = input;
|
|
26
|
+
const view = element?.ownerDocument.defaultView;
|
|
27
|
+
if (!element || !view) return;
|
|
28
|
+
// Reconcile an input already toggled before hydration with its visual/app state.
|
|
29
|
+
if (!options.disabled && !options.readOnly) change(element.checked);
|
|
30
|
+
element.checked = checked();
|
|
31
|
+
element.indeterminate = options.indeterminate ?? false;
|
|
32
|
+
setMounted(true);
|
|
33
|
+
const pending = new Set<number>();
|
|
34
|
+
const reset = (event: Event) => {
|
|
35
|
+
if (event.target !== element.form) return;
|
|
36
|
+
const task = view.setTimeout(() => {
|
|
37
|
+
pending.delete(task);
|
|
38
|
+
if (event.defaultPrevented) return;
|
|
39
|
+
if (controlled() === undefined) change(initialChecked);
|
|
40
|
+
element.checked = checked();
|
|
41
|
+
element.indeterminate = options.indeterminate ?? false;
|
|
42
|
+
}, 0);
|
|
43
|
+
pending.add(task);
|
|
44
|
+
};
|
|
45
|
+
element.ownerDocument.addEventListener("reset", reset, true);
|
|
46
|
+
onCleanup(() => {
|
|
47
|
+
element.ownerDocument.removeEventListener("reset", reset, true);
|
|
48
|
+
for (const task of pending) view.clearTimeout(task);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
createEffect(() => {
|
|
52
|
+
if (!mounted() || !input) return;
|
|
53
|
+
input.checked = checked();
|
|
54
|
+
input.indeterminate = options.indeterminate ?? false;
|
|
55
|
+
});
|
|
56
|
+
const requestChange = (element: HTMLInputElement) => {
|
|
57
|
+
if (options.disabled || options.readOnly) {
|
|
58
|
+
element.checked = checked();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
change(element.checked);
|
|
62
|
+
element.checked = checked();
|
|
63
|
+
};
|
|
64
|
+
return { checked, requestChange, setInput: (element: HTMLInputElement) => { input = element; } };
|
|
65
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ClassValue } from "clsx";
|
|
2
|
+
import { cn } from "../utils/cn.ts";
|
|
3
|
+
|
|
4
|
+
/** Class-only composition for native controls; behavior belongs to the component. */
|
|
5
|
+
export interface ButtonVariantProps {
|
|
6
|
+
readonly variant?: "solid" | "soft" | "outline" | "ghost" | "link" | undefined;
|
|
7
|
+
readonly tone?: "neutral" | "accent" | "danger" | "success" | undefined;
|
|
8
|
+
readonly size?: "xs" | "sm" | "md" | "lg" | undefined;
|
|
9
|
+
readonly class?: ClassValue | undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function buttonVariants(options: ButtonVariantProps = {}): string {
|
|
13
|
+
return cn(
|
|
14
|
+
"sheen-button",
|
|
15
|
+
`sheen-button-${options.variant ?? "ghost"}`,
|
|
16
|
+
`sheen-button-${options.tone ?? "neutral"}`,
|
|
17
|
+
`sheen-button-${options.size ?? "md"}`,
|
|
18
|
+
options.class,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createMemo, onCleanup } from "solid-js";
|
|
2
|
+
import type { Accessor } from "solid-js";
|
|
3
|
+
|
|
4
|
+
export function createChoiceOptions<Option extends { readonly value: string }>(source: Accessor<readonly Option[]>, root: Accessor<HTMLElement | undefined>, component: string) {
|
|
5
|
+
let disposed = false;
|
|
6
|
+
onCleanup(() => { disposed = true; });
|
|
7
|
+
const byValue = createMemo(() => {
|
|
8
|
+
const options = new Map<string, Option>();
|
|
9
|
+
for (const option of source()) {
|
|
10
|
+
if (options.has(option.value)) throw new Error(`${component}: duplicate option value ${JSON.stringify(option.value)}`);
|
|
11
|
+
options.set(option.value, option);
|
|
12
|
+
}
|
|
13
|
+
return options;
|
|
14
|
+
});
|
|
15
|
+
let previousKeys: string[] = [];
|
|
16
|
+
const keys = createMemo(() => {
|
|
17
|
+
const next = [...byValue().keys()];
|
|
18
|
+
const element = root();
|
|
19
|
+
const focused = element?.querySelector<HTMLInputElement>("input:focus");
|
|
20
|
+
if (element && focused) {
|
|
21
|
+
const previousIndex = previousKeys.indexOf(focused.value);
|
|
22
|
+
// Moving retained DOM may blur it. Never override a deliberate external focus move.
|
|
23
|
+
element.ownerDocument.defaultView?.queueMicrotask(() => {
|
|
24
|
+
if (disposed || !element.isConnected) return;
|
|
25
|
+
const active = element.ownerDocument.activeElement;
|
|
26
|
+
if (active !== element.ownerDocument.body && active !== focused) return;
|
|
27
|
+
const inputs = [...element.querySelectorAll<HTMLInputElement>("input[type=checkbox], input[type=radio]")];
|
|
28
|
+
const eligible = (input: HTMLInputElement) => !input.matches(":disabled");
|
|
29
|
+
const retained = inputs.find(input => input.value === focused.value && eligible(input));
|
|
30
|
+
const index = Math.max(0, previousIndex);
|
|
31
|
+
const nearest = inputs.slice(index).find(eligible) ?? inputs.slice(0, index).reverse().find(eligible);
|
|
32
|
+
(retained ?? nearest ?? element).focus({ preventScroll: true });
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
previousKeys = next;
|
|
36
|
+
return next;
|
|
37
|
+
});
|
|
38
|
+
return { byValue, keys };
|
|
39
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Show, createSignal, getOwner, onCleanup } from "solid-js";
|
|
2
|
+
import type { Accessor, JSX } from "solid-js";
|
|
3
|
+
import { ConfirmDialog } from "./ConfirmDialog.tsx";
|
|
4
|
+
|
|
5
|
+
export interface ConfirmOptions {
|
|
6
|
+
readonly title: string;
|
|
7
|
+
readonly description: string;
|
|
8
|
+
readonly confirmLabel?: string;
|
|
9
|
+
readonly cancelLabel?: string;
|
|
10
|
+
readonly tone?: "accent" | "danger";
|
|
11
|
+
readonly signal?: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
interface Request {
|
|
14
|
+
readonly options: ConfirmOptions;
|
|
15
|
+
readonly opener: HTMLElement | undefined;
|
|
16
|
+
readonly open: Accessor<boolean>;
|
|
17
|
+
readonly settle: (result: boolean) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface ConfirmController {
|
|
20
|
+
readonly confirm: (options: ConfirmOptions) => Promise<boolean>;
|
|
21
|
+
readonly Dialog: () => JSX.Element;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Create inside a Solid owner and mount Dialog once within that owner's theme scope. */
|
|
25
|
+
export function createConfirm(): ConfirmController {
|
|
26
|
+
if (!getOwner()) throw new Error("createConfirm requires a Solid owner");
|
|
27
|
+
let disposed = false;
|
|
28
|
+
const [request, setRequest] = createSignal<Request>();
|
|
29
|
+
onCleanup(() => { disposed = true; request()?.settle(false); });
|
|
30
|
+
function confirm(options: ConfirmOptions): Promise<boolean> {
|
|
31
|
+
if (disposed || options.signal?.aborted) return Promise.resolve(false);
|
|
32
|
+
if (request()?.open()) return Promise.reject(new Error("createConfirm already has an unanswered request"));
|
|
33
|
+
const snapshot = { ...options };
|
|
34
|
+
const active = typeof document === "undefined" ? undefined : document.activeElement;
|
|
35
|
+
const opener = typeof HTMLElement !== "undefined" && active instanceof HTMLElement ? active : undefined;
|
|
36
|
+
return new Promise(resolve => {
|
|
37
|
+
const [open, setOpen] = createSignal(true);
|
|
38
|
+
let settled = false;
|
|
39
|
+
const abort = () => settle(false);
|
|
40
|
+
const settle = (result: boolean) => {
|
|
41
|
+
if (settled) return;
|
|
42
|
+
settled = true;
|
|
43
|
+
snapshot.signal?.removeEventListener("abort", abort);
|
|
44
|
+
setOpen(false);
|
|
45
|
+
resolve(result);
|
|
46
|
+
};
|
|
47
|
+
snapshot.signal?.addEventListener("abort", abort, { once: true });
|
|
48
|
+
setRequest({ options: snapshot, opener, open, settle });
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function Dialog(): JSX.Element {
|
|
52
|
+
return <Show when={request()} keyed>{current => <ConfirmDialog {...current.options} open={current.open()}
|
|
53
|
+
returnFocus={() => current.opener} onConfirm={() => current.settle(true)} onCancel={() => current.settle(false)} />}</Show>;
|
|
54
|
+
}
|
|
55
|
+
return { confirm, Dialog };
|
|
56
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { createSignal, getOwner, onCleanup } from "solid-js";
|
|
2
|
+
import type { Accessor } from "solid-js";
|
|
3
|
+
|
|
4
|
+
/** An ephemeral handle belonging to the controller that created it. */
|
|
5
|
+
export type ToastId = symbol;
|
|
6
|
+
/** Internal presenter lease, intentionally absent from the package root exports. */
|
|
7
|
+
export const toasterPresenter = Symbol("sheen toaster presenter");
|
|
8
|
+
export interface ToastAction {
|
|
9
|
+
readonly label: string;
|
|
10
|
+
readonly run: () => void | Promise<void>;
|
|
11
|
+
/** Safe, app-localized text. Raw rejection values are never display copy. */
|
|
12
|
+
readonly errorMessage: string;
|
|
13
|
+
readonly retryLabel?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ToastOptions {
|
|
16
|
+
readonly title: string;
|
|
17
|
+
readonly description?: string;
|
|
18
|
+
readonly tone?: "neutral" | "success" | "warning" | "danger";
|
|
19
|
+
readonly priority?: "polite" | "assertive";
|
|
20
|
+
/** Visible lifetime in milliseconds; null means persistent. */
|
|
21
|
+
readonly duration?: number | null;
|
|
22
|
+
readonly action?: ToastAction;
|
|
23
|
+
}
|
|
24
|
+
export interface ToastNotification {
|
|
25
|
+
readonly id: ToastId;
|
|
26
|
+
readonly options: Readonly<ToastOptions & {
|
|
27
|
+
tone: NonNullable<ToastOptions["tone"]>;
|
|
28
|
+
priority: NonNullable<ToastOptions["priority"]>;
|
|
29
|
+
duration: number | null;
|
|
30
|
+
}>;
|
|
31
|
+
readonly state: "idle" | "pending" | "failed";
|
|
32
|
+
readonly error?: unknown;
|
|
33
|
+
}
|
|
34
|
+
export type ToastActionResult = { readonly status: "succeeded" } | { readonly status: "failed"; readonly error: unknown } | { readonly status: "ignored" };
|
|
35
|
+
export interface ToastController {
|
|
36
|
+
readonly [toasterPresenter]: () => () => void;
|
|
37
|
+
readonly notifications: Accessor<readonly ToastNotification[]>;
|
|
38
|
+
readonly show: (options: ToastOptions) => ToastId;
|
|
39
|
+
/** Replace the whole message and invalidate any previous action completion. */
|
|
40
|
+
readonly update: (id: ToastId, options: ToastOptions) => boolean;
|
|
41
|
+
readonly dismiss: (id: ToastId) => boolean;
|
|
42
|
+
readonly clear: () => void;
|
|
43
|
+
readonly runAction: (id: ToastId) => Promise<ToastActionResult>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function snapshot(options: ToastOptions): ToastNotification["options"] {
|
|
47
|
+
if (!options.title.trim()) throw new Error("Toast: title must be nonempty");
|
|
48
|
+
if (options.action && (!options.action.label.trim() || !options.action.errorMessage.trim())) {
|
|
49
|
+
throw new Error("Toast: action label and error message must be nonempty");
|
|
50
|
+
}
|
|
51
|
+
if (options.action?.retryLabel !== undefined && !options.action.retryLabel.trim()) throw new Error("Toast: retry label must be nonempty");
|
|
52
|
+
const tone = options.tone ?? "neutral";
|
|
53
|
+
const duration = options.duration === undefined ? (options.action || tone === "danger" || tone === "warning" ? null : 5000) : options.duration;
|
|
54
|
+
if (duration !== null && (!Number.isFinite(duration) || duration <= 0 || duration > 2_147_483_647)) {
|
|
55
|
+
throw new Error("Toast: duration must be null or a positive finite browser timer duration");
|
|
56
|
+
}
|
|
57
|
+
const result = { ...options, tone, priority: options.priority ?? "polite", duration };
|
|
58
|
+
return Object.freeze(options.action ? { ...result, action: Object.freeze({ ...options.action }) } : result);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Owner-local notification state. No global queue, DOM, timer, or transport is created. */
|
|
62
|
+
export function createToaster(): ToastController {
|
|
63
|
+
if (!getOwner()) throw new Error("createToaster requires a Solid owner");
|
|
64
|
+
const [notifications, setNotifications] = createSignal<readonly ToastNotification[]>(Object.freeze([]));
|
|
65
|
+
const executions = new Map<ToastId, symbol>();
|
|
66
|
+
let disposed = false;
|
|
67
|
+
let claimed = false;
|
|
68
|
+
const find = (id: ToastId) => notifications().find(notification => notification.id === id);
|
|
69
|
+
const replace = (notification: ToastNotification) => {
|
|
70
|
+
setNotifications(current => Object.freeze(current.map(item => item.id === notification.id ? Object.freeze(notification) : item)));
|
|
71
|
+
};
|
|
72
|
+
const clear = () => { executions.clear(); setNotifications(Object.freeze([])); };
|
|
73
|
+
const dismiss = (id: ToastId): boolean => {
|
|
74
|
+
if (!find(id)) return false;
|
|
75
|
+
executions.delete(id);
|
|
76
|
+
setNotifications(current => Object.freeze(current.filter(notification => notification.id !== id)));
|
|
77
|
+
return true;
|
|
78
|
+
};
|
|
79
|
+
onCleanup(() => { disposed = true; clear(); });
|
|
80
|
+
|
|
81
|
+
async function runAction(id: ToastId): Promise<ToastActionResult> {
|
|
82
|
+
const notification = find(id);
|
|
83
|
+
const action = notification?.options.action;
|
|
84
|
+
if (disposed || !notification || !action || notification.state === "pending") return { status: "ignored" };
|
|
85
|
+
const execution = Symbol("toast action");
|
|
86
|
+
executions.set(id, execution);
|
|
87
|
+
replace({ id, options: notification.options, state: "pending" });
|
|
88
|
+
try {
|
|
89
|
+
await action.run();
|
|
90
|
+
if (disposed || executions.get(id) !== execution) return { status: "ignored" };
|
|
91
|
+
dismiss(id);
|
|
92
|
+
return { status: "succeeded" };
|
|
93
|
+
} catch (error) {
|
|
94
|
+
if (disposed || executions.get(id) !== execution) return { status: "ignored" };
|
|
95
|
+
executions.delete(id);
|
|
96
|
+
replace({ id, options: notification.options, state: "failed", error });
|
|
97
|
+
return { status: "failed", error };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return Object.freeze({
|
|
102
|
+
[toasterPresenter](): () => void {
|
|
103
|
+
if (disposed) throw new Error("Cannot mount a disposed toast controller");
|
|
104
|
+
if (claimed) throw new Error("A toast controller can have only one Toaster presenter");
|
|
105
|
+
claimed = true;
|
|
106
|
+
return () => { claimed = false; };
|
|
107
|
+
},
|
|
108
|
+
notifications,
|
|
109
|
+
show(options: ToastOptions): ToastId {
|
|
110
|
+
if (disposed) throw new Error("Cannot show a toast after its owner is disposed");
|
|
111
|
+
const resolved = snapshot(options);
|
|
112
|
+
const id = Symbol("sheen toast");
|
|
113
|
+
const notification: ToastNotification = Object.freeze({ id, options: resolved, state: "idle" });
|
|
114
|
+
setNotifications(current => Object.freeze([...current, notification]));
|
|
115
|
+
return id;
|
|
116
|
+
},
|
|
117
|
+
update(id: ToastId, options: ToastOptions): boolean {
|
|
118
|
+
if (disposed || !find(id)) return false;
|
|
119
|
+
const resolved = snapshot(options);
|
|
120
|
+
executions.delete(id);
|
|
121
|
+
replace({ id, options: resolved, state: "idle" });
|
|
122
|
+
return true;
|
|
123
|
+
},
|
|
124
|
+
dismiss,
|
|
125
|
+
clear,
|
|
126
|
+
runAction,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { onCleanup, onMount } from "solid-js";
|
|
2
|
+
import type { Accessor } from "solid-js";
|
|
3
|
+
|
|
4
|
+
export function createLinkFocusRecovery(root: Accessor<HTMLElement | undefined>): void {
|
|
5
|
+
onMount(() => {
|
|
6
|
+
const element = root();
|
|
7
|
+
if (!element) return;
|
|
8
|
+
const links = () => [...element.querySelectorAll<HTMLAnchorElement>("a[href]")].filter(link => link.closest("nav") === element);
|
|
9
|
+
let previous = links();
|
|
10
|
+
let focused: HTMLAnchorElement | undefined;
|
|
11
|
+
const recordFocus = () => {
|
|
12
|
+
const active = element.ownerDocument.activeElement;
|
|
13
|
+
focused = active instanceof HTMLAnchorElement && active.closest("nav") === element ? active : undefined;
|
|
14
|
+
};
|
|
15
|
+
recordFocus();
|
|
16
|
+
element.ownerDocument.addEventListener("focusin", recordFocus);
|
|
17
|
+
const observer = new MutationObserver(() => {
|
|
18
|
+
const next = links();
|
|
19
|
+
const active = element.ownerDocument.activeElement;
|
|
20
|
+
if (element.isConnected && focused && active === element.ownerDocument.body) {
|
|
21
|
+
const eligible = (link: HTMLAnchorElement) => link.isConnected && link.hasAttribute("href") && !link.closest("[inert], [hidden]") && link.getClientRects().length > 0;
|
|
22
|
+
const retained = next.includes(focused) && eligible(focused) ? focused : undefined;
|
|
23
|
+
const previousIndex = previous.indexOf(focused);
|
|
24
|
+
if (previousIndex >= 0) {
|
|
25
|
+
const index = Math.min(previousIndex, next.length);
|
|
26
|
+
const nearest = next.slice(index).find(eligible) ?? next.slice(0, index).reverse().find(eligible);
|
|
27
|
+
(retained ?? nearest ?? element).focus({ preventScroll: true });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
previous = next;
|
|
31
|
+
});
|
|
32
|
+
observer.observe(element, { childList: true, subtree: true, attributes: true, attributeFilter: ["href", "hidden", "inert"] });
|
|
33
|
+
onCleanup(() => {
|
|
34
|
+
observer.disconnect();
|
|
35
|
+
element.ownerDocument.removeEventListener("focusin", recordFocus);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createEffect, onCleanup } from "solid-js";
|
|
2
|
+
import type { Accessor } from "solid-js";
|
|
3
|
+
|
|
4
|
+
/** Restore only focus lost by mutations within this menu, never another layer's focus. */
|
|
5
|
+
export function createMenuFocusRecovery(root: Accessor<HTMLElement | undefined>, open: Accessor<boolean>): void {
|
|
6
|
+
createEffect(() => {
|
|
7
|
+
const element = root();
|
|
8
|
+
if (!element || !open()) return;
|
|
9
|
+
const document = element.ownerDocument;
|
|
10
|
+
const items = () => Array.from(element.querySelectorAll<HTMLElement>('[role="menuitem"], [role="menuitemcheckbox"], [role="menuitemradio"]'))
|
|
11
|
+
.filter(item => item.closest('[role="menu"]') === element && item.getAttribute("aria-disabled") !== "true" && !item.closest("[inert]"));
|
|
12
|
+
let focused: HTMLElement | undefined;
|
|
13
|
+
let order: HTMLElement[] = [];
|
|
14
|
+
const track = () => {
|
|
15
|
+
const active = document.activeElement;
|
|
16
|
+
const entries = items();
|
|
17
|
+
if (active instanceof HTMLElement && entries.includes(active)) { focused = active; order = entries; }
|
|
18
|
+
else if (!(active === element && focused && (!focused.isConnected || focused.getAttribute("aria-disabled") === "true"))) focused = undefined;
|
|
19
|
+
};
|
|
20
|
+
const outsidePointer = (event: PointerEvent) => { if (event.target instanceof Node && !element.contains(event.target)) focused = undefined; };
|
|
21
|
+
document.addEventListener("focusin", track);
|
|
22
|
+
document.addEventListener("pointerdown", outsidePointer, true);
|
|
23
|
+
track();
|
|
24
|
+
const observer = new MutationObserver(() => {
|
|
25
|
+
if (!open() || !element.isConnected || !focused) return;
|
|
26
|
+
const active = document.activeElement;
|
|
27
|
+
if (active !== focused && active !== element && active !== document.body) return;
|
|
28
|
+
const entries = items();
|
|
29
|
+
const previous = focused;
|
|
30
|
+
const index = order.indexOf(previous);
|
|
31
|
+
const next = entries.includes(previous) ? previous :
|
|
32
|
+
[...order.slice(index + 1), ...order.slice(0, Math.max(0, index)).reverse()].find(item => entries.includes(item)) ?? entries[0];
|
|
33
|
+
(next ?? element).focus({ preventScroll: true });
|
|
34
|
+
order = entries;
|
|
35
|
+
});
|
|
36
|
+
observer.observe(element, { childList: true, subtree: true, attributes: true, attributeFilter: ["aria-disabled", "disabled"] });
|
|
37
|
+
onCleanup(() => {
|
|
38
|
+
observer.disconnect();
|
|
39
|
+
document.removeEventListener("focusin", track);
|
|
40
|
+
document.removeEventListener("pointerdown", outsidePointer, true);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as Primitive from "@kobalte/core/tooltip";
|
|
2
|
+
import { Show, createEffect, createMemo, createSignal, createUniqueId, onCleanup, onMount } from "solid-js";
|
|
3
|
+
import type { Accessor } from "solid-js";
|
|
4
|
+
import { Kbd } from "./Typography.tsx";
|
|
5
|
+
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
6
|
+
|
|
7
|
+
export function createTooltipLayer(trigger: Accessor<HTMLElement | undefined>, disabled: Accessor<boolean>) {
|
|
8
|
+
const theme = useTheme();
|
|
9
|
+
const id = createUniqueId();
|
|
10
|
+
const [open, setOpen] = createSignal(false);
|
|
11
|
+
let dismissedWhileEngaged = false;
|
|
12
|
+
createEffect(() => { if (open()) onCleanup(theme.layers.register(id)); });
|
|
13
|
+
createEffect(() => {
|
|
14
|
+
if (disabled()) setOpen(false);
|
|
15
|
+
else { const element = trigger(); if (element && element.ownerDocument.activeElement === element) setOpen(true); }
|
|
16
|
+
});
|
|
17
|
+
const layer = createMemo<number>(previous => open() ? theme.layers.zIndex(id) : previous ?? 100);
|
|
18
|
+
onMount(() => {
|
|
19
|
+
const element = trigger();
|
|
20
|
+
if (!element) return;
|
|
21
|
+
const releaseDismissal = () => { dismissedWhileEngaged = false; };
|
|
22
|
+
element.addEventListener("blur", releaseDismissal);
|
|
23
|
+
element.addEventListener("pointerleave", releaseDismissal);
|
|
24
|
+
onCleanup(() => {
|
|
25
|
+
element.removeEventListener("blur", releaseDismissal);
|
|
26
|
+
element.removeEventListener("pointerleave", releaseDismissal);
|
|
27
|
+
});
|
|
28
|
+
if (!disabled() && (element.ownerDocument.activeElement === element || element.matches(":hover"))) setOpen(true);
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
theme,
|
|
32
|
+
id,
|
|
33
|
+
open,
|
|
34
|
+
layer,
|
|
35
|
+
change: (next: boolean) => setOpen(next && !disabled() && !dismissedWhileEngaged),
|
|
36
|
+
dismiss: () => {
|
|
37
|
+
dismissedWhileEngaged = true;
|
|
38
|
+
setOpen(false);
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function TooltipLayer(props: { state: ReturnType<typeof createTooltipLayer>; content: string; shortcut?: Accessor<string | undefined> | undefined }) {
|
|
44
|
+
return <Show when={props.state.theme.portal()}>{target => <Primitive.Portal mount={target()}>
|
|
45
|
+
<Primitive.Content id={`${props.state.id}-content`} data-kb-top-layer="true" class="sheen-tooltip" aria-hidden={!props.state.open() || undefined} style={{ "z-index": props.state.layer() }}
|
|
46
|
+
onEscapeKeyDown={event => {
|
|
47
|
+
if (!props.state.theme.layers.isTop(props.state.id)) event.preventDefault();
|
|
48
|
+
else props.state.dismiss();
|
|
49
|
+
}}>
|
|
50
|
+
<span>{props.content}</span><Show when={props.shortcut?.()}>{shortcut => <Kbd>{shortcut()}</Kbd>}</Show>
|
|
51
|
+
</Primitive.Content>
|
|
52
|
+
</Primitive.Portal>}</Show>;
|
|
53
|
+
}
|