@gemologic/sheen 0.2.1 → 0.3.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 +25 -5
- package/dist/index.js +86 -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/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.js +1 -2
- 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.js +2 -4
- 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.js +57 -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.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/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 +25 -5
- package/src/navigation.ts +2 -1
- 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/Collapsible.tsx +1 -1
- package/src/primitives/Combobox.tsx +2 -1
- package/src/primitives/CommandPalette.tsx +2 -2
- 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 +2 -1
- 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/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/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 +261 -0
- package/src/styles/navigation.css +137 -0
- package/src/styles/overlays.css +104 -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
|
@@ -0,0 +1,406 @@
|
|
|
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, 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 interface BoardColumn<Card extends SortableItem = SortableItem> {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
/** Column title, used by the default header and in announcements. */
|
|
15
|
+
readonly label: string;
|
|
16
|
+
readonly cards: readonly Card[];
|
|
17
|
+
/** A disabled column neither accepts cards nor lets its cards or itself be picked up. */
|
|
18
|
+
readonly disabled?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface BoardMove {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly fromColumn: string;
|
|
24
|
+
readonly fromIndex: number;
|
|
25
|
+
readonly toColumn: string;
|
|
26
|
+
/** Final index in `toColumn`, measured after the card leaves its original position. */
|
|
27
|
+
readonly index: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type BoardCardOf<Column extends BoardColumn> = Column["cards"][number];
|
|
31
|
+
|
|
32
|
+
export type BoardProps<Column extends BoardColumn> = Omit<JSX.HTMLAttributes<HTMLDivElement>, "children" | "ref" | "onDrop"> & {
|
|
33
|
+
ref?: HTMLDivElement | ((element: HTMLDivElement) => void);
|
|
34
|
+
/** Owner-ordered columns. Column and card ids are stable and unique across the board. */
|
|
35
|
+
columns: readonly Column[];
|
|
36
|
+
children: (card: Accessor<BoardCardOf<Column>>, column: Accessor<Column>) => JSX.Element;
|
|
37
|
+
/** Replaces the default title and count inside each column header. The reorder handle stays Sheen-owned. */
|
|
38
|
+
columnHeader?: (column: Accessor<Column>, count: Accessor<number>) => JSX.Element;
|
|
39
|
+
/** Proposes a card move. The board is controlled: nothing moves until the owner passes updated columns back. */
|
|
40
|
+
onMove: (move: BoardMove) => void;
|
|
41
|
+
/** Enables column reordering through each header's handle. */
|
|
42
|
+
onColumnReorder?: (reorder: SortableReorder) => void;
|
|
43
|
+
/** Accessible name for the board. */
|
|
44
|
+
label: string;
|
|
45
|
+
/** Render a grip button on each card that owns pointer and keyboard dragging. Without it the whole card drags and takes focus. */
|
|
46
|
+
handle?: boolean;
|
|
47
|
+
disabled?: boolean;
|
|
48
|
+
messages?: Partial<SortableMessages>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
interface Position { readonly column: string; readonly index: number }
|
|
52
|
+
type Lift =
|
|
53
|
+
| { readonly kind: "card"; readonly id: string; readonly origin: Position; readonly target: Position }
|
|
54
|
+
| { readonly kind: "column"; readonly id: string; readonly origin: number; readonly target: number };
|
|
55
|
+
type Indicator =
|
|
56
|
+
| { readonly kind: "card"; readonly id: string; readonly edge: SortableEdge }
|
|
57
|
+
| { readonly kind: "append"; readonly id: string }
|
|
58
|
+
| { readonly kind: "column"; readonly id: string; readonly edge: SortableEdge };
|
|
59
|
+
|
|
60
|
+
function sameIndicator(first: Indicator | undefined, second: Indicator | undefined): boolean {
|
|
61
|
+
if (!first || !second) return first === second;
|
|
62
|
+
return first.kind === second.kind && first.id === second.id && (first.kind === "append" || second.kind === "append" || first.edge === second.edge);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** A controlled Kanban board: cards move within and between columns, and columns optionally reorder. */
|
|
66
|
+
export function Board<Column extends BoardColumn>(props: BoardProps<Column>): JSX.Element {
|
|
67
|
+
const theme = useTheme();
|
|
68
|
+
const formatter = useNumberFormatter();
|
|
69
|
+
const generatedId = createUniqueId();
|
|
70
|
+
const instance = Symbol("Board");
|
|
71
|
+
const [local, others] = splitProps(props, ["ref", "class", "columns", "children", "columnHeader", "onMove", "onColumnReorder", "label", "handle", "disabled", "messages", "aria-describedby"]);
|
|
72
|
+
const messages = createMemo(() => resolveSortableMessages(theme.messages(), local.messages));
|
|
73
|
+
const columnIndex = createMemo(() => {
|
|
74
|
+
validateIds(local.columns.map(column => column.id), "Board columns");
|
|
75
|
+
validateIds(local.columns.flatMap(column => column.cards.map(card => card.id)), "Board cards");
|
|
76
|
+
return new Map(local.columns.map(column => [column.id, column]));
|
|
77
|
+
});
|
|
78
|
+
const cardIndex = createMemo(() => {
|
|
79
|
+
const map = new Map<string, { readonly card: BoardCardOf<Column>; readonly column: string }>();
|
|
80
|
+
for (const column of local.columns) for (const card of column.cards) map.set(card.id, { card, column: column.id });
|
|
81
|
+
return map;
|
|
82
|
+
});
|
|
83
|
+
const ownedColumns = createMemo(() => [...columnIndex().keys()]);
|
|
84
|
+
const ownedCards = (column: string) => columnIndex().get(column)?.cards.map(card => card.id) ?? [];
|
|
85
|
+
const [lift, setLift] = createSignal<Lift>();
|
|
86
|
+
const [indicator, setIndicator] = createSignal<Indicator>();
|
|
87
|
+
const [dragging, setDragging] = createSignal<string>();
|
|
88
|
+
const [announcement, setAnnouncement] = createSignal("");
|
|
89
|
+
// A refresh that removes the lifted card, its target column, or the lifted column ends the lift.
|
|
90
|
+
const activeLift = createMemo(() => {
|
|
91
|
+
const current = lift();
|
|
92
|
+
if (!current) return undefined;
|
|
93
|
+
if (current.kind === "column") return columnIndex().has(current.id) ? current : undefined;
|
|
94
|
+
return cardIndex().has(current.id) && columnIndex().has(current.target.column) ? current : undefined;
|
|
95
|
+
});
|
|
96
|
+
const columnIds = createMemo(() => {
|
|
97
|
+
const current = activeLift();
|
|
98
|
+
return current?.kind === "column" ? moveId(ownedColumns(), current.id, current.target) : ownedColumns();
|
|
99
|
+
});
|
|
100
|
+
const cardIds = (column: string): string[] => {
|
|
101
|
+
const current = activeLift();
|
|
102
|
+
const owned = ownedCards(column);
|
|
103
|
+
if (current?.kind !== "card") return owned;
|
|
104
|
+
const without = owned.filter(id => id !== current.id);
|
|
105
|
+
if (current.target.column !== column) return without;
|
|
106
|
+
without.splice(Math.min(without.length, current.target.index), 0, current.id);
|
|
107
|
+
return without;
|
|
108
|
+
};
|
|
109
|
+
const instructionsId = `${generatedId}-instructions`;
|
|
110
|
+
let root: HTMLDivElement | undefined;
|
|
111
|
+
let scroller: HTMLDivElement | undefined;
|
|
112
|
+
let relocating = false;
|
|
113
|
+
let disposed = false;
|
|
114
|
+
onCleanup(() => { disposed = true; });
|
|
115
|
+
|
|
116
|
+
const columnDisabled = (column: string) => Boolean(local.disabled || columnIndex().get(column)?.disabled);
|
|
117
|
+
const cardDisabled = (id: string) => {
|
|
118
|
+
const entry = cardIndex().get(id);
|
|
119
|
+
return !entry || columnDisabled(entry.column) || Boolean(entry.card.disabled);
|
|
120
|
+
};
|
|
121
|
+
const columnLabel = (column: string) => columnIndex().get(column)?.label ?? column;
|
|
122
|
+
const accepts = (source: DragData) => source.boardInstance === instance;
|
|
123
|
+
const find = (selector: string, attribute: string, id: string) => [...root?.querySelectorAll<HTMLElement>(selector) ?? []].find(element => element.getAttribute(attribute) === id);
|
|
124
|
+
const keyboardTarget = (kind: Lift["kind"], id: string): HTMLElement | undefined => {
|
|
125
|
+
if (kind === "column") return find(".sheen-board-column", "data-column-id", id)?.querySelector<HTMLElement>(".sheen-board-column-handle") ?? undefined;
|
|
126
|
+
const card = find(".sheen-board-card", "data-card-id", id);
|
|
127
|
+
return local.handle ? card?.querySelector<HTMLElement>(".sheen-board-card-handle") ?? undefined : card;
|
|
128
|
+
};
|
|
129
|
+
const say = (text: string) => {
|
|
130
|
+
setAnnouncement("");
|
|
131
|
+
queueMicrotask(() => { if (!disposed) setAnnouncement(text); });
|
|
132
|
+
};
|
|
133
|
+
const count = (value: number) => formatter().format(value);
|
|
134
|
+
const announceCard = (template: string, id: string, position: Position) => say(formatMessage(template, {
|
|
135
|
+
label: cardIndex().get(id)?.card.label ?? id, column: columnLabel(position.column),
|
|
136
|
+
position: count(position.index + 1), count: count(ownedCards(position.column).filter(card => card !== id).length + 1),
|
|
137
|
+
}));
|
|
138
|
+
const announceColumn = (template: string, id: string, position: number) => say(formatMessage(template, {
|
|
139
|
+
label: columnLabel(id), position: count(position + 1), count: count(ownedColumns().length),
|
|
140
|
+
}));
|
|
141
|
+
const relocate = (kind: Lift["kind"], id: string, update: () => void) => {
|
|
142
|
+
relocating = true;
|
|
143
|
+
try { update(); }
|
|
144
|
+
finally {
|
|
145
|
+
const target = keyboardTarget(kind, id);
|
|
146
|
+
if (target && target.ownerDocument.activeElement !== target) target.focus();
|
|
147
|
+
relocating = false;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const cardPosition = (id: string): Position | undefined => {
|
|
151
|
+
const entry = cardIndex().get(id);
|
|
152
|
+
return entry ? { column: entry.column, index: ownedCards(entry.column).indexOf(id) } : undefined;
|
|
153
|
+
};
|
|
154
|
+
const proposeCard = (id: string, target: Position) => {
|
|
155
|
+
const origin = cardPosition(id);
|
|
156
|
+
if (!origin || (origin.column === target.column && origin.index === target.index)) return;
|
|
157
|
+
local.onMove({ id, fromColumn: origin.column, fromIndex: origin.index, toColumn: target.column, index: target.index });
|
|
158
|
+
};
|
|
159
|
+
const proposeColumn = (id: string, fromIndex: number, toIndex: number) => {
|
|
160
|
+
if (!local.onColumnReorder || fromIndex === toIndex || fromIndex < 0) return;
|
|
161
|
+
local.onColumnReorder({ id, fromIndex, toIndex, ids: moveId(ownedColumns(), id, toIndex) });
|
|
162
|
+
};
|
|
163
|
+
const cancel = () => {
|
|
164
|
+
const current = activeLift();
|
|
165
|
+
setLift(undefined);
|
|
166
|
+
if (current?.kind === "card") announceCard(messages().boardCancelled, current.id, current.origin);
|
|
167
|
+
else if (current) announceColumn(messages().sortableCancelled, current.id, current.origin);
|
|
168
|
+
};
|
|
169
|
+
const neighbourColumn = (from: string, delta: -1 | 1): string | undefined => {
|
|
170
|
+
const order = columnIds();
|
|
171
|
+
for (let position = order.indexOf(from) + delta; position >= 0 && position < order.length; position += delta) {
|
|
172
|
+
const candidate = order[position];
|
|
173
|
+
if (candidate !== undefined && !columnDisabled(candidate)) return candidate;
|
|
174
|
+
}
|
|
175
|
+
return undefined;
|
|
176
|
+
};
|
|
177
|
+
const moveCard = (current: Extract<Lift, { kind: "card" }>, intent: NonNullable<ReturnType<typeof keyIntent>>): Position | undefined => {
|
|
178
|
+
const room = (column: string) => ownedCards(column).filter(id => id !== current.id).length;
|
|
179
|
+
const { column, index } = current.target;
|
|
180
|
+
if (intent.kind === "edge") return { column, index: intent.to === "start" ? 0 : room(column) };
|
|
181
|
+
if (intent.kind !== "step") return undefined;
|
|
182
|
+
if (intent.axis === "vertical") return { column, index: Math.max(0, Math.min(room(column), index + intent.delta)) };
|
|
183
|
+
const next = neighbourColumn(column, intent.delta);
|
|
184
|
+
return next ? { column: next, index: Math.min(index, room(next)) } : undefined;
|
|
185
|
+
};
|
|
186
|
+
const onKeyDown = (kind: Lift["kind"], id: string, event: KeyboardEvent, element: HTMLElement) => {
|
|
187
|
+
if (event.target !== element || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
188
|
+
const intent = keyIntent(event.key, isRtl(element));
|
|
189
|
+
const current = activeLift();
|
|
190
|
+
if (!intent) return;
|
|
191
|
+
if (!current) {
|
|
192
|
+
if (intent.kind !== "toggle") return;
|
|
193
|
+
if (kind === "card") {
|
|
194
|
+
const origin = cardPosition(id);
|
|
195
|
+
if (!origin || cardDisabled(id)) return;
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
setLift({ kind, id, origin, target: origin });
|
|
198
|
+
announceCard(messages().boardLifted, id, origin);
|
|
199
|
+
} else {
|
|
200
|
+
if (columnDisabled(id)) return;
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
const origin = ownedColumns().indexOf(id);
|
|
203
|
+
setLift({ kind, id, origin, target: origin });
|
|
204
|
+
announceColumn(messages().sortableLifted, id, origin);
|
|
205
|
+
}
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (current.id !== id || current.kind !== kind) return;
|
|
209
|
+
event.preventDefault();
|
|
210
|
+
if (intent.kind === "cancel") { relocate(kind, id, cancel); return; }
|
|
211
|
+
if (current.kind === "card") {
|
|
212
|
+
if (intent.kind === "toggle") {
|
|
213
|
+
relocate(kind, id, () => batch(() => { proposeCard(id, current.target); setLift(undefined); }));
|
|
214
|
+
announceCard(messages().boardDropped, id, current.target);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const target = moveCard(current, intent);
|
|
218
|
+
if (!target || (target.column === current.target.column && target.index === current.target.index)) return;
|
|
219
|
+
relocate(kind, id, () => setLift({ ...current, target }));
|
|
220
|
+
announceCard(messages().boardMoved, id, target);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (intent.kind === "toggle") {
|
|
224
|
+
relocate(kind, id, () => batch(() => { proposeColumn(id, current.origin, current.target); setLift(undefined); }));
|
|
225
|
+
announceColumn(messages().sortableDropped, id, current.target);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (intent.kind === "step" && intent.axis !== "horizontal") return;
|
|
229
|
+
const last = ownedColumns().length - 1;
|
|
230
|
+
const target = intent.kind === "edge" ? (intent.to === "start" ? 0 : last) : Math.max(0, Math.min(last, current.target + intent.delta));
|
|
231
|
+
if (target === current.target) return;
|
|
232
|
+
relocate(kind, id, () => setLift({ ...current, target }));
|
|
233
|
+
announceColumn(messages().sortableMoved, id, target);
|
|
234
|
+
};
|
|
235
|
+
const onFocusOut = (id: string, event: FocusEvent, element: HTMLElement) => {
|
|
236
|
+
if (relocating || activeLift()?.id !== id) return;
|
|
237
|
+
if (event.relatedTarget instanceof Node && element.contains(event.relatedTarget)) return;
|
|
238
|
+
cancel();
|
|
239
|
+
};
|
|
240
|
+
const resolveCardDrop = (cardId: string, target: DragData): { readonly position: Position; readonly indicator: Indicator } | undefined => {
|
|
241
|
+
const column = stringField(target, "columnId");
|
|
242
|
+
if (!column) return undefined;
|
|
243
|
+
const others = ownedCards(column).filter(id => id !== cardId);
|
|
244
|
+
if (target.kind === "column") return { position: { column, index: others.length }, indicator: { kind: "append", id: column } };
|
|
245
|
+
const over = stringField(target, "cardId");
|
|
246
|
+
const edge = edgeField(target);
|
|
247
|
+
if (!over || !edge || over === cardId) return undefined;
|
|
248
|
+
const index = others.indexOf(over) + (edge === "after" ? 1 : 0);
|
|
249
|
+
return { position: { column, index }, indicator: { kind: "card", id: over, edge } };
|
|
250
|
+
};
|
|
251
|
+
const resolveColumnDrop = (columnId: string, target: DragData) => {
|
|
252
|
+
const over = stringField(target, "columnId");
|
|
253
|
+
const edge = edgeField(target);
|
|
254
|
+
if (target.kind !== "column" || !over || !edge) return undefined;
|
|
255
|
+
const from = ownedColumns().indexOf(columnId);
|
|
256
|
+
const to = dropIndex(from, ownedColumns().indexOf(over), edge);
|
|
257
|
+
return to === from ? undefined : { from, to, indicator: { kind: "column", id: over, edge } satisfies Indicator };
|
|
258
|
+
};
|
|
259
|
+
const isNoop = (cardId: string, position: Position) => {
|
|
260
|
+
const origin = cardPosition(cardId);
|
|
261
|
+
return origin?.column === position.column && origin.index === position.index;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
onMount(() => {
|
|
265
|
+
if (!scroller) return;
|
|
266
|
+
const columns = scroller;
|
|
267
|
+
onCleanup(bindMonitor({
|
|
268
|
+
accepts,
|
|
269
|
+
scrollers: () => scrollContainers(columns, ...columns.querySelectorAll<HTMLElement>(".sheen-board-cards")),
|
|
270
|
+
onDrag: (source, target) => {
|
|
271
|
+
const sourceId = stringField(source, "sourceId");
|
|
272
|
+
let next: Indicator | undefined;
|
|
273
|
+
if (sourceId && target && source.kind === "card") {
|
|
274
|
+
const drop = resolveCardDrop(sourceId, target);
|
|
275
|
+
next = drop && !isNoop(sourceId, drop.position) ? drop.indicator : undefined;
|
|
276
|
+
} else if (sourceId && target && source.kind === "column") next = resolveColumnDrop(sourceId, target)?.indicator;
|
|
277
|
+
if (!sameIndicator(indicator(), next)) setIndicator(next);
|
|
278
|
+
},
|
|
279
|
+
onDrop: (source, target) => {
|
|
280
|
+
setIndicator(undefined);
|
|
281
|
+
const sourceId = stringField(source, "sourceId");
|
|
282
|
+
if (!sourceId || !target) return;
|
|
283
|
+
if (source.kind === "card") {
|
|
284
|
+
const drop = resolveCardDrop(sourceId, target);
|
|
285
|
+
if (!drop || isNoop(sourceId, drop.position)) return;
|
|
286
|
+
proposeCard(sourceId, drop.position);
|
|
287
|
+
announceCard(messages().boardDropped, sourceId, drop.position);
|
|
288
|
+
} else if (source.kind === "column") {
|
|
289
|
+
const drop = resolveColumnDrop(sourceId, target);
|
|
290
|
+
if (!drop) return;
|
|
291
|
+
proposeColumn(sourceId, drop.from, drop.to);
|
|
292
|
+
announceColumn(messages().sortableDropped, sourceId, drop.to);
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
}));
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
return <div {...others} ref={element => { root = element; if (typeof local.ref === "function") local.ref(element); }} class={cn("sheen-board", local.class)}
|
|
299
|
+
role="group" aria-label={local.label} aria-describedby={[instructionsId, local["aria-describedby"]].filter(Boolean).join(" ")}
|
|
300
|
+
data-disabled={local.disabled ? "" : undefined} data-active={activeLift() || dragging() ? "" : undefined}>
|
|
301
|
+
<div ref={scroller} class="sheen-board-columns">
|
|
302
|
+
<For each={columnIds()}>{columnId => {
|
|
303
|
+
const initial = columnIndex().get(columnId);
|
|
304
|
+
if (!initial) throw new Error(`Board: missing column ${JSON.stringify(columnId)}`);
|
|
305
|
+
let lastColumn = initial;
|
|
306
|
+
const column = () => { const value = columnIndex().get(columnId); if (value) lastColumn = value; return lastColumn; };
|
|
307
|
+
const cards = createMemo(() => cardIds(columnId), undefined, { equals: (first, second) => first.length === second.length && first.every((id, position) => id === second[position]) });
|
|
308
|
+
const total = () => cards().length;
|
|
309
|
+
const headerId = createUniqueId();
|
|
310
|
+
const disabled = () => columnDisabled(columnId);
|
|
311
|
+
const lifted = () => activeLift()?.kind === "column" && activeLift()?.id === columnId;
|
|
312
|
+
const columnIndicator = () => { const value = indicator(); return value && value.kind !== "card" && value.id === columnId ? value : undefined; };
|
|
313
|
+
let section: HTMLDivElement | undefined;
|
|
314
|
+
let columnHandle: HTMLButtonElement | undefined;
|
|
315
|
+
createEffect(() => {
|
|
316
|
+
if (!section) return;
|
|
317
|
+
const target = section;
|
|
318
|
+
const reorderable = Boolean(local.onColumnReorder);
|
|
319
|
+
const release = [bindDropTarget({
|
|
320
|
+
element: target,
|
|
321
|
+
accepts: source => accepts(source) && !disabled() && (source.kind === "card" || reorderable),
|
|
322
|
+
data: input => ({ kind: "column", columnId, edge: closestEdge(target, input, "horizontal") }),
|
|
323
|
+
})];
|
|
324
|
+
if (reorderable && columnHandle) release.push(bindDraggable({
|
|
325
|
+
element: target, handle: columnHandle, canDrag: () => !disabled() && !activeLift(),
|
|
326
|
+
data: () => ({ boardInstance: instance, kind: "column", sourceId: columnId }),
|
|
327
|
+
onStart: () => setDragging(columnId), onEnd: () => setDragging(undefined),
|
|
328
|
+
}));
|
|
329
|
+
onCleanup(() => { for (const cleanup of release) cleanup(); });
|
|
330
|
+
});
|
|
331
|
+
return <div ref={section} class="sheen-board-column" role="group" aria-labelledby={headerId} data-column-id={columnId}
|
|
332
|
+
data-disabled={disabled() ? "" : undefined} data-lifted={lifted() ? "" : undefined} data-dragging={dragging() === columnId ? "" : undefined}
|
|
333
|
+
data-drop-target={columnIndicator()?.kind === "append" ? "" : undefined}
|
|
334
|
+
data-drop-edge={(() => { const value = columnIndicator(); return value?.kind === "column" ? value.edge : undefined; })()}>
|
|
335
|
+
<div class="sheen-board-column-header">
|
|
336
|
+
<Show when={local.onColumnReorder}>
|
|
337
|
+
<button ref={columnHandle} type="button" class="sheen-sortable-handle sheen-board-column-handle" aria-label={formatMessage(messages().boardColumnHandle, { label: column().label })}
|
|
338
|
+
aria-describedby={instructionsId} aria-pressed={lifted() ? "true" : "false"} disabled={disabled()}
|
|
339
|
+
onKeyDown={event => onKeyDown("column", columnId, event, event.currentTarget)} onFocusOut={event => onFocusOut(columnId, event, event.currentTarget)}>
|
|
340
|
+
<Glyph class="sheen-sortable-grip" name="grip" />
|
|
341
|
+
</button>
|
|
342
|
+
</Show>
|
|
343
|
+
<div id={headerId} class="sheen-board-column-heading">
|
|
344
|
+
<Show when={local.columnHeader} fallback={<>
|
|
345
|
+
<span class="sheen-board-column-title">{column().label}</span>
|
|
346
|
+
<span class="sheen-board-column-count" aria-label={formatMessage(messages().boardCardCount, { count: count(total()) })}>{count(total())}</span>
|
|
347
|
+
</>}>{render => render()(column, total)}</Show>
|
|
348
|
+
</div>
|
|
349
|
+
</div>
|
|
350
|
+
<ul class="sheen-board-cards" role="list" aria-labelledby={headerId}>
|
|
351
|
+
<For each={cards()}>{cardId => <BoardCardNode cardId={cardId} column={column} />}</For>
|
|
352
|
+
</ul>
|
|
353
|
+
<Show when={total() === 0}><p class="sheen-board-empty">{messages().boardEmptyColumn}</p></Show>
|
|
354
|
+
</div>;
|
|
355
|
+
}}</For>
|
|
356
|
+
</div>
|
|
357
|
+
<span id={instructionsId} class="sheen-sortable-hidden">{messages().boardInstructions}</span>
|
|
358
|
+
<span class="sheen-sortable-hidden" role="status" aria-live="assertive" aria-atomic="true">{announcement()}</span>
|
|
359
|
+
</div>;
|
|
360
|
+
|
|
361
|
+
function BoardCardNode(card: { readonly cardId: string; readonly column: Accessor<Column> }): JSX.Element {
|
|
362
|
+
const id = card.cardId;
|
|
363
|
+
const initial = cardIndex().get(id);
|
|
364
|
+
if (!initial) throw new Error(`Board: missing card ${JSON.stringify(id)}`);
|
|
365
|
+
let last: BoardCardOf<Column> = initial.card;
|
|
366
|
+
const value = (): BoardCardOf<Column> => { const entry = cardIndex().get(id); if (entry) last = entry.card; return last; };
|
|
367
|
+
const disabled = () => cardDisabled(id);
|
|
368
|
+
const lifted = () => activeLift()?.kind === "card" && activeLift()?.id === id;
|
|
369
|
+
const ownKeys = () => !local.handle;
|
|
370
|
+
const cardIndicator = () => { const current = indicator(); return current?.kind === "card" && current.id === id ? current.edge : undefined; };
|
|
371
|
+
let element: HTMLLIElement | undefined;
|
|
372
|
+
let handle: HTMLButtonElement | undefined;
|
|
373
|
+
createEffect(() => {
|
|
374
|
+
if (!element) return;
|
|
375
|
+
const target = element;
|
|
376
|
+
const dragHandle = local.handle ? handle : undefined;
|
|
377
|
+
const release = [
|
|
378
|
+
bindDraggable({
|
|
379
|
+
element: target, handle: dragHandle, canDrag: () => !disabled() && !activeLift(),
|
|
380
|
+
data: () => ({ boardInstance: instance, kind: "card", sourceId: id }),
|
|
381
|
+
onStart: () => setDragging(id), onEnd: () => setDragging(undefined),
|
|
382
|
+
}),
|
|
383
|
+
bindDropTarget({
|
|
384
|
+
element: target,
|
|
385
|
+
accepts: source => accepts(source) && source.kind === "card" && !columnDisabled(card.column().id),
|
|
386
|
+
data: input => ({ kind: "card", cardId: id, columnId: card.column().id, edge: closestEdge(target, input, "vertical") }),
|
|
387
|
+
}),
|
|
388
|
+
];
|
|
389
|
+
onCleanup(() => { for (const cleanup of release) cleanup(); });
|
|
390
|
+
});
|
|
391
|
+
return <li ref={element} class="sheen-board-card" data-card-id={id}
|
|
392
|
+
data-disabled={disabled() ? "" : undefined} data-lifted={lifted() ? "" : undefined} data-dragging={dragging() === id ? "" : undefined} data-drop-edge={cardIndicator()}
|
|
393
|
+
tabindex={ownKeys() && !disabled() ? 0 : undefined} aria-describedby={ownKeys() ? instructionsId : undefined} aria-disabled={ownKeys() && disabled() ? "true" : undefined}
|
|
394
|
+
onKeyDown={event => { if (ownKeys()) onKeyDown("card", id, event, event.currentTarget); }}
|
|
395
|
+
onFocusOut={event => { if (ownKeys()) onFocusOut(id, event, event.currentTarget); }}>
|
|
396
|
+
<Show when={local.handle}>
|
|
397
|
+
<button ref={handle} type="button" class="sheen-sortable-handle sheen-board-card-handle" aria-label={formatMessage(messages().boardCardHandle, { label: value().label })}
|
|
398
|
+
aria-describedby={instructionsId} aria-pressed={lifted() ? "true" : "false"} disabled={disabled()}
|
|
399
|
+
onKeyDown={event => onKeyDown("card", id, event, event.currentTarget)} onFocusOut={event => onFocusOut(id, event, event.currentTarget)}>
|
|
400
|
+
<Glyph class="sheen-sortable-grip" name="grip" />
|
|
401
|
+
</button>
|
|
402
|
+
</Show>
|
|
403
|
+
<div class="sheen-board-card-content">{local.children(value, card.column)}</div>
|
|
404
|
+
</li>;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
@@ -15,13 +15,24 @@ export interface ButtonProps extends JSX.ButtonHTMLAttributes<HTMLButtonElement>
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function Button(props: ButtonProps): JSX.Element {
|
|
18
|
-
const [local, others] = splitProps(props, ["class", "variant", "tone", "size", "loading", "disabled", "shortcut", "ref", "children"]);
|
|
18
|
+
const [local, others] = splitProps(props, ["class", "variant", "tone", "size", "loading", "disabled", "shortcut", "ref", "onClick", "children"]);
|
|
19
19
|
let element: HTMLButtonElement | undefined;
|
|
20
20
|
const binding = useShortcutAction(() => local.shortcut, () => {
|
|
21
21
|
if (!local.disabled && !local.loading) element?.click();
|
|
22
22
|
});
|
|
23
|
-
|
|
23
|
+
// Loading keeps the native button enabled so focus survives the pending work; activation is suppressed here instead.
|
|
24
|
+
const click: JSX.EventHandler<HTMLButtonElement, MouseEvent> = event => {
|
|
25
|
+
if (local.loading) {
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
event.stopPropagation();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const handler = local.onClick;
|
|
31
|
+
if (typeof handler === "function") handler(event);
|
|
32
|
+
else if (handler) handler[0](handler[1], event);
|
|
33
|
+
};
|
|
34
|
+
return <button {...others} onClick={click} ref={node => { element = node; if (typeof local.ref === "function") local.ref(node); }} type={others.type ?? "button"}
|
|
24
35
|
class={cn(buttonVariants({ variant: local.variant, tone: local.tone, size: local.size }), local.class)}
|
|
25
|
-
data-variant={local.variant ?? "
|
|
26
|
-
data-sheen-shortcut={binding()?.displayKeys} disabled={local.disabled
|
|
36
|
+
data-variant={local.variant ?? "outline"} data-tone={local.tone ?? "neutral"} data-size={local.size ?? "md"}
|
|
37
|
+
data-sheen-shortcut={binding()?.displayKeys} disabled={local.disabled} aria-disabled={local.loading && !local.disabled ? "true" : others["aria-disabled"]} aria-busy={local.loading || undefined}>{local.children}</button>;
|
|
27
38
|
}
|
|
@@ -33,7 +33,7 @@ export function Collapsible(props: CollapsibleProps): JSX.Element {
|
|
|
33
33
|
};
|
|
34
34
|
createEffect(() => { if (!open()) restoreFocus(); });
|
|
35
35
|
return <Primitive.Root {...others} id={id()} class={cn("sheen-collapsible", local.class)} open={open()} onOpenChange={change} disabled={local.disabled ?? false}>
|
|
36
|
-
<Primitive.Trigger as={Button} ref={trigger} id={`${id()}-trigger`} aria-controls={`${id()}-content`} class="sheen-collapsible-trigger">
|
|
36
|
+
<Primitive.Trigger as={Button} variant="ghost" ref={trigger} id={`${id()}-trigger`} aria-controls={`${id()}-content`} class="sheen-collapsible-trigger">
|
|
37
37
|
<span class="sheen-collapsible-indicator" aria-hidden="true" />{local.label}
|
|
38
38
|
</Primitive.Trigger>
|
|
39
39
|
<div ref={content} id={`${id()}-content`} class="sheen-collapsible-content" data-open={open()} aria-hidden={!open() || undefined} inert={!open()}>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as Primitive from "#sheen-kobalte/combobox";
|
|
2
|
+
import { Glyph } from "./Glyph.tsx";
|
|
2
3
|
import { For, Show, createEffect, createMemo, createSignal, createUniqueId, onCleanup, onMount, splitProps } from "solid-js";
|
|
3
4
|
import type { Accessor, JSX } from "solid-js";
|
|
4
5
|
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
@@ -143,7 +144,7 @@ function OptionItem(props: Primitive.ComboboxRootItemComponentProps<ComboboxOpti
|
|
|
143
144
|
}}>
|
|
144
145
|
<Primitive.ItemLabel>{props.item.rawValue.label}</Primitive.ItemLabel>
|
|
145
146
|
<Show when={props.item.rawValue.description}>{description => <Primitive.ItemDescription class="sheen-select-option-description">{description()}</Primitive.ItemDescription>}</Show>
|
|
146
|
-
<Primitive.ItemIndicator class="sheen-select-indicator" aria-hidden="true"
|
|
147
|
+
<Primitive.ItemIndicator class="sheen-select-indicator" aria-hidden="true"><Glyph name="check" /></Primitive.ItemIndicator>
|
|
147
148
|
</Primitive.Item>;
|
|
148
149
|
}
|
|
149
150
|
|
|
@@ -161,12 +161,12 @@ export function CommandPalette(props: CommandPaletteProps): JSX.Element {
|
|
|
161
161
|
onCleanup(() => controller.abort());
|
|
162
162
|
});
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
// The palette's own open shortcut is not a command inside the palette.
|
|
165
|
+
const registeredCommands = createMemo<readonly CommandPaletteCommand[]>(() => shortcuts.bindings().filter(binding => !binding.shadowed && !(binding.keys === "mod+k" && binding.label === theme.messages().openCommandPalette)).map(binding => Object.freeze({
|
|
165
166
|
id: `shortcut:${binding.id}`,
|
|
166
167
|
label: binding.label,
|
|
167
168
|
group: binding.group,
|
|
168
169
|
keywords: [binding.keys, binding.displayKeys, binding.scope],
|
|
169
|
-
disabled: binding.keys === "mod+k" && binding.label === theme.messages().openCommandPalette,
|
|
170
170
|
run: () => { shortcuts.run(binding.id); },
|
|
171
171
|
})));
|
|
172
172
|
const commands = createMemo(() => {
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { For, Show, createMemo, createSignal, onCleanup, onMount, splitProps } from "solid-js";
|
|
2
|
+
import type { Accessor, JSX } from "solid-js";
|
|
3
|
+
import { Button } from "./Button.tsx";
|
|
4
|
+
import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
5
|
+
import { cn } from "../utils/cn.ts";
|
|
6
|
+
|
|
7
|
+
export interface ConversationItem {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type ConversationProps<Item extends ConversationItem> = Omit<JSX.HTMLAttributes<HTMLDivElement>, "children" | "ref" | "role"> & {
|
|
12
|
+
ref?: HTMLDivElement | ((element: HTMLDivElement) => void);
|
|
13
|
+
items: readonly Item[];
|
|
14
|
+
children: (item: Accessor<Item>) => JSX.Element;
|
|
15
|
+
label?: string;
|
|
16
|
+
stickToBottom?: boolean;
|
|
17
|
+
jumpLabel?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Distance from the end, in CSS pixels, still treated as "at the bottom" so subpixel layout cannot unstick the thread.
|
|
21
|
+
const bottomTolerance = 4;
|
|
22
|
+
// Later members of one appended batch share the last stagger step instead of delaying indefinitely.
|
|
23
|
+
const maximumStagger = 6;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A scrolling message log keyed by stable item IDs. Existing message nodes survive appends and content updates.
|
|
27
|
+
* While the reader is at the end, growth keeps the newest content in view; scrolling away stops that until they return.
|
|
28
|
+
*/
|
|
29
|
+
export function Conversation<Item extends ConversationItem>(props: ConversationProps<Item>): JSX.Element {
|
|
30
|
+
const theme = useTheme();
|
|
31
|
+
const [local, others] = splitProps(props, ["ref", "items", "children", "label", "stickToBottom", "jumpLabel", "class"]);
|
|
32
|
+
const index = createMemo(() => {
|
|
33
|
+
const map = new Map<string, Item>();
|
|
34
|
+
for (const item of local.items) {
|
|
35
|
+
if (!item.id) throw new Error("Conversation: item ids must be nonempty");
|
|
36
|
+
if (map.has(item.id)) throw new Error(`Conversation: duplicate item id "${item.id}"`);
|
|
37
|
+
map.set(item.id, item);
|
|
38
|
+
}
|
|
39
|
+
return map;
|
|
40
|
+
});
|
|
41
|
+
const ids = createMemo(() => [...index().keys()]);
|
|
42
|
+
const [stuck, setStuck] = createSignal(true);
|
|
43
|
+
const sticky = () => local.stickToBottom !== false;
|
|
44
|
+
let scroller: HTMLDivElement | undefined;
|
|
45
|
+
let content: HTMLDivElement | undefined;
|
|
46
|
+
let mounted = false;
|
|
47
|
+
let batch = 0;
|
|
48
|
+
let batchReset = false;
|
|
49
|
+
let lastTop = 0;
|
|
50
|
+
const atBottom = (element: HTMLDivElement) => element.scrollHeight - element.scrollTop - element.clientHeight <= bottomTolerance;
|
|
51
|
+
const scrollToEnd = () => {
|
|
52
|
+
if (!scroller) return;
|
|
53
|
+
scroller.scrollTop = scroller.scrollHeight;
|
|
54
|
+
lastTop = scroller.scrollTop;
|
|
55
|
+
};
|
|
56
|
+
// Growth between a programmatic scroll and its event must not read as the reader leaving the end, so only upward movement unsticks.
|
|
57
|
+
const onScroll = (element: HTMLDivElement) => {
|
|
58
|
+
const top = element.scrollTop;
|
|
59
|
+
if (top < lastTop - bottomTolerance) setStuck(false);
|
|
60
|
+
else if (atBottom(element)) setStuck(true);
|
|
61
|
+
lastTop = top;
|
|
62
|
+
};
|
|
63
|
+
onMount(() => {
|
|
64
|
+
mounted = true;
|
|
65
|
+
if (!scroller || !content) return;
|
|
66
|
+
const element = scroller;
|
|
67
|
+
if (sticky()) scrollToEnd();
|
|
68
|
+
setStuck(atBottom(element));
|
|
69
|
+
lastTop = element.scrollTop;
|
|
70
|
+
// Content growth (appends, streaming text, late images) emits no scroll event; follow it only while stuck.
|
|
71
|
+
const observer = new ResizeObserver(() => {
|
|
72
|
+
if (sticky() && stuck()) scrollToEnd();
|
|
73
|
+
else { lastTop = element.scrollTop; setStuck(atBottom(element)); }
|
|
74
|
+
});
|
|
75
|
+
observer.observe(content);
|
|
76
|
+
observer.observe(element);
|
|
77
|
+
onCleanup(() => observer.disconnect());
|
|
78
|
+
});
|
|
79
|
+
const entering = () => {
|
|
80
|
+
if (!mounted) return undefined;
|
|
81
|
+
if (!batchReset) {
|
|
82
|
+
batchReset = true;
|
|
83
|
+
queueMicrotask(() => { batch = 0; batchReset = false; });
|
|
84
|
+
}
|
|
85
|
+
return Math.min(batch++, maximumStagger);
|
|
86
|
+
};
|
|
87
|
+
return <div {...others} ref={element => { if (typeof local.ref === "function") local.ref(element); }} class={cn("sheen-conversation", local.class)} data-stuck={stuck() || undefined}>
|
|
88
|
+
<div ref={scroller} class="sheen-conversation-scroller" role="log" aria-label={local.label ?? theme.messages().conversation} tabindex="0"
|
|
89
|
+
onScroll={event => onScroll(event.currentTarget)} onWheel={event => { const element = event.currentTarget; if (event.deltaY < 0 && element.scrollTop > 0) setStuck(false); }}>
|
|
90
|
+
<div ref={content} class="sheen-conversation-content">
|
|
91
|
+
<For each={ids()}>{id => {
|
|
92
|
+
const stagger = entering();
|
|
93
|
+
const [animating, setAnimating] = createSignal(stagger !== undefined);
|
|
94
|
+
return <Show when={index().get(id)}>{item =>
|
|
95
|
+
<div class="sheen-conversation-item" data-id={id} data-entering={animating() || undefined}
|
|
96
|
+
style={stagger === undefined ? undefined : { "--sheen-conversation-stagger": String(stagger) }}
|
|
97
|
+
onAnimationEnd={event => { if (event.target === event.currentTarget) setAnimating(false); }}>{local.children(item)}</div>
|
|
98
|
+
}</Show>;
|
|
99
|
+
}}</For>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
<Show when={sticky() && !stuck()}>
|
|
103
|
+
<Button class="sheen-conversation-jump" variant="outline" size="sm" onClick={() => { scrollToEnd(); setStuck(true); scroller?.focus({ preventScroll: true }); }}>
|
|
104
|
+
{local.jumpLabel ?? theme.messages().jumpToLatest}
|
|
105
|
+
</Button>
|
|
106
|
+
</Show>
|
|
107
|
+
</div>;
|
|
108
|
+
}
|
|
@@ -5,6 +5,7 @@ import { useTheme } from "../theme/ThemeProvider.tsx";
|
|
|
5
5
|
import { Button } from "./Button.tsx";
|
|
6
6
|
import { buttonVariants } from "./button-variants.ts";
|
|
7
7
|
import { cn } from "../utils/cn.ts";
|
|
8
|
+
import { Glyph } from "./Glyph.tsx";
|
|
8
9
|
import { useModalShortcutScope } from "./ShortcutProvider.tsx";
|
|
9
10
|
|
|
10
11
|
export interface DialogProps extends ParentProps {
|
|
@@ -39,6 +40,8 @@ export function ModalFrame(props: DialogProps & { alert?: boolean }): JSX.Elemen
|
|
|
39
40
|
useModalShortcutScope(() => props.shortcutScope ?? `dialog:${id}`, open);
|
|
40
41
|
let content: HTMLDivElement | undefined;
|
|
41
42
|
let closeButton: HTMLButtonElement | undefined;
|
|
43
|
+
/** Alerts and custom close labels keep a labelled footer action; other dialogs close from a corner icon placed last in tab order. */
|
|
44
|
+
const textClose = (): boolean => Boolean(props.alert) || props.closeLabel !== undefined;
|
|
42
45
|
createEffect(() => {
|
|
43
46
|
if (open()) onCleanup(theme.layers.register(id));
|
|
44
47
|
});
|
|
@@ -70,9 +73,10 @@ export function ModalFrame(props: DialogProps & { alert?: boolean }): JSX.Elemen
|
|
|
70
73
|
</div>
|
|
71
74
|
<div class="sheen-dialog-body">{props.children}</div>
|
|
72
75
|
<div class="sheen-dialog-footer">
|
|
73
|
-
<KobalteDialog.CloseButton as={Button} ref={element => { closeButton = element; }} disabled={!dismissible()} aria-label={props.closeLabel ?? theme.messages().close}>{props.closeLabel ?? theme.messages().close}</KobalteDialog.CloseButton>
|
|
76
|
+
<Show when={textClose()}><KobalteDialog.CloseButton as={Button} variant="ghost" ref={element => { closeButton = element; }} disabled={!dismissible()} aria-label={props.closeLabel ?? theme.messages().close}>{props.closeLabel ?? theme.messages().close}</KobalteDialog.CloseButton></Show>
|
|
74
77
|
{props.footer}
|
|
75
78
|
</div>
|
|
79
|
+
<Show when={!textClose()}><KobalteDialog.CloseButton as={Button} variant="ghost" class="sheen-dialog-close" size="sm" ref={element => { closeButton = element; }} disabled={!dismissible()} aria-label={theme.messages().close}><Glyph name="close" /></KobalteDialog.CloseButton></Show>
|
|
76
80
|
</KobalteDialog.Content>
|
|
77
81
|
</KobalteDialog.Portal>}</Show>
|
|
78
82
|
</KobalteDialog.Root>;
|