@torpor/ui 1.3.6 → 1.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.
Files changed (128) hide show
  1. package/dist/Accordion/AccordionItem.torp +1 -1
  2. package/dist/Alert/Alert.torp +41 -0
  3. package/dist/Alert/index.d.ts +37 -0
  4. package/dist/Alert/index.js +1 -0
  5. package/dist/Charts/ChartScatter.torp +167 -0
  6. package/dist/Charts/ScatterChart.torp +49 -178
  7. package/dist/Charts/index.d.ts +38 -78
  8. package/dist/Charts/index.js +2 -4
  9. package/dist/ColorPicker/ColorPalette.torp +107 -29
  10. package/dist/ColorPicker/ColorPicker.torp +121 -10
  11. package/dist/ColorPicker/ColorPickerAlpha.torp +58 -0
  12. package/dist/ColorPicker/ColorPickerArea.torp +175 -0
  13. package/dist/ColorPicker/ColorPickerEyedropper.torp +77 -0
  14. package/dist/ColorPicker/ColorPickerHue.torp +59 -0
  15. package/dist/ColorPicker/ColorPickerInput.torp +7 -18
  16. package/dist/ColorPicker/ColorPickerTypes.ts +11 -1
  17. package/dist/ColorPicker/index.d.ts +139 -14
  18. package/dist/ColorPicker/index.js +5 -1
  19. package/dist/ComboBox/ComboBox.torp +40 -5
  20. package/dist/ComboBox/index.d.ts +5 -2
  21. package/dist/ComboBox/index.js +1 -2
  22. package/dist/Contextual/Contextual.torp +25 -77
  23. package/dist/Contextual/ContextualContent.torp +10 -51
  24. package/dist/Contextual/ContextualHover.torp +13 -85
  25. package/dist/Contextual/ContextualTrigger.torp +9 -16
  26. package/dist/Contextual/ContextualTypes.ts +6 -12
  27. package/dist/Contextual/index.d.ts +10 -13
  28. package/dist/DataGrid/DataGrid.torp +2 -2
  29. package/dist/DataGrid/index.d.ts +1 -1
  30. package/dist/DatePicker/DatePicker.torp +6 -4
  31. package/dist/DateRangePicker/DateRangePicker.torp +14 -13
  32. package/dist/DateTimePicker/DateTimePicker.torp +264 -0
  33. package/dist/DateTimePicker/index.d.ts +46 -0
  34. package/dist/DateTimePicker/index.js +1 -0
  35. package/dist/Dialog/Dialog.torp +0 -1
  36. package/dist/Dialog/index.d.ts +0 -1
  37. package/dist/Drawer/Drawer.torp +5 -23
  38. package/dist/Drawer/DrawerContent.torp +1 -0
  39. package/dist/Drawer/DrawerOverlay.torp +9 -16
  40. package/dist/Drawer/DrawerTrigger.torp +9 -24
  41. package/dist/Drawer/DrawerTypes.ts +3 -1
  42. package/dist/Form/CheckBox.torp +10 -18
  43. package/dist/Form/File.torp +10 -18
  44. package/dist/Form/FileDrop.torp +16 -22
  45. package/dist/Form/Input.torp +14 -20
  46. package/dist/Form/Radio.torp +71 -0
  47. package/dist/Form/RadioGroup.torp +221 -0
  48. package/dist/Form/RadioGroupTypes.ts +40 -0
  49. package/dist/Form/Select.torp +10 -18
  50. package/dist/Form/{Toggle.torp → Switch.torp} +17 -21
  51. package/dist/Form/TextArea.torp +10 -18
  52. package/dist/Form/ToggleButton.torp +94 -0
  53. package/dist/Form/ToggleGroup.torp +150 -0
  54. package/dist/Form/ToggleGroupTypes.ts +23 -0
  55. package/dist/Form/index.d.ts +173 -15
  56. package/dist/Form/index.js +6 -2
  57. package/dist/ListBox/ListBox.torp +27 -5
  58. package/dist/ListBox/ListBoxItem.torp +1 -1
  59. package/dist/ListBox/index.d.ts +6 -2
  60. package/dist/MaskedInput/MaskedInput.torp +1 -1
  61. package/dist/Menu/MenuPopoutTrigger.torp +1 -1
  62. package/dist/MenuBar/MenuBar.torp +5 -3
  63. package/dist/MenuBar/MenuBarItemTrigger.torp +2 -2
  64. package/dist/Meter/Meter.torp +126 -0
  65. package/dist/Meter/MeterIndicator.torp +41 -0
  66. package/dist/Meter/MeterTypes.ts +8 -0
  67. package/dist/Meter/index.d.ts +79 -0
  68. package/dist/Meter/index.js +3 -0
  69. package/dist/Modal/Modal.torp +4 -22
  70. package/dist/Modal/ModalOverlay.torp +9 -16
  71. package/dist/NavMenu/NavMenu.torp +5 -3
  72. package/dist/NumberInput/NumberInput.torp +1 -1
  73. package/dist/PinInput/PinInput.torp +220 -0
  74. package/dist/PinInput/index.d.ts +48 -0
  75. package/dist/PinInput/index.js +1 -0
  76. package/dist/Popover/Popover.torp +18 -24
  77. package/dist/Popover/PopoverContent.torp +8 -0
  78. package/dist/Popover/PopoverHover.torp +30 -3
  79. package/dist/Popover/PopoverTypes.ts +2 -0
  80. package/dist/Popover/index.d.ts +8 -1
  81. package/dist/Rating/Rating.torp +1 -1
  82. package/dist/SegmentedControl/SegmentedControl.torp +3 -3
  83. package/dist/SegmentedControl/SegmentedItem.torp +1 -1
  84. package/dist/SelectBox/SelectBox.torp +40 -5
  85. package/dist/SelectBox/index.d.ts +5 -2
  86. package/dist/SelectBox/index.js +1 -2
  87. package/dist/Slider/Slider.torp +1 -1
  88. package/dist/SortableList/SortableList.torp +132 -0
  89. package/dist/SortableList/SortableListItem.torp +117 -0
  90. package/dist/SortableList/SortableListTypes.ts +16 -0
  91. package/dist/SortableList/index.d.ts +81 -0
  92. package/dist/SortableList/index.js +3 -0
  93. package/dist/TabGroup/TabContent.torp +1 -1
  94. package/dist/TabGroup/TabGroup.torp +2 -2
  95. package/dist/TabGroup/TabHeader.torp +1 -1
  96. package/dist/TagInput/TagInput.torp +1 -1
  97. package/dist/TimePicker/TimePicker.torp +1 -1
  98. package/dist/ToolBar/ToolBar.torp +8 -4
  99. package/dist/ToolBar/ToolBarPopoutTrigger.torp +1 -1
  100. package/dist/Tooltip/Tooltip.torp +104 -0
  101. package/dist/Tooltip/TooltipContent.torp +81 -0
  102. package/dist/Tooltip/TooltipTrigger.torp +79 -0
  103. package/dist/Tooltip/TooltipTypes.ts +28 -0
  104. package/dist/Tooltip/index.d.ts +104 -0
  105. package/dist/Tooltip/index.js +4 -0
  106. package/dist/Tree/Tree.torp +1 -1
  107. package/dist/Tree/TreeItem.torp +1 -1
  108. package/dist/VirtualList/VirtualList.torp +149 -0
  109. package/dist/VirtualList/index.d.ts +46 -0
  110. package/dist/VirtualList/index.js +1 -0
  111. package/dist/dnd/index.d.ts +2 -0
  112. package/dist/dnd/index.js +212 -0
  113. package/dist/dnd/index.js.map +1 -0
  114. package/dist/loader/index.d.ts +2 -0
  115. package/dist/{loader-CBGbVpkN.js → loader/index.js} +2 -2
  116. package/dist/loader/index.js.map +1 -0
  117. package/dist/utils/PopoutClickTrigger.torp +1 -0
  118. package/dist/utils/PopoutOverlay.torp +39 -0
  119. package/dist/utils/PopoutTypes.ts +4 -0
  120. package/dist/utils/SubmenuPopoutTrigger.torp +5 -5
  121. package/dist/utils/colorUtils.ts +260 -75
  122. package/dist/utils/formField.ts +4 -3
  123. package/dist/utils/handlePopoutButton.ts +43 -0
  124. package/package.json +41 -5
  125. package/dist/Charts/GridLines.torp +0 -65
  126. package/dist/Charts/XAxis.torp +0 -69
  127. package/dist/Charts/YAxis.torp +0 -49
  128. package/dist/loader-CBGbVpkN.js.map +0 -1
@@ -0,0 +1,149 @@
1
+ import type { ClassValue, StyleValue } from "@torpor/view";
2
+
3
+ interface VirtualListProps {
4
+ /** An ID for the root element */
5
+ id?: string;
6
+ /** Classes for the root element */
7
+ class?: ClassValue;
8
+ /** Styles for the root element */
9
+ style?: StyleValue;
10
+ /** The items to render */
11
+ items: any[];
12
+ /** The fixed height of each item, in pixels */
13
+ itemHeight: number;
14
+ /** The height of the scroll viewport, in pixels; defaults to the element's height */
15
+ height?: number;
16
+ /** Extra items to render above and below the viewport (default 3) */
17
+ overscan?: number;
18
+ /** An accessible name for the list */
19
+ ariaLabel?: string;
20
+ }
21
+
22
+ /**
23
+ * A list that renders only the items in and around its scroll viewport, for
24
+ * large collections with fixed-height rows.
25
+ *
26
+ * The slot is rendered once per visible item, with the item and its index
27
+ * passed back as `$slot.item` and `$slot.index`:
28
+ *
29
+ * ```
30
+ * <VirtualList items={$state.rows} itemHeight={32} height={400} ariaLabel="Log">
31
+ * <div>{$slot.item.label}</div>
32
+ * </VirtualList>
33
+ * ```
34
+ *
35
+ * DataGrid has its own virtualization; use this for simpler lists.
36
+ */
37
+ export default function VirtualList($props: VirtualListProps | undefined) {
38
+ let root: HTMLElement | undefined;
39
+ let observer: ResizeObserver | undefined;
40
+
41
+ function getOverscan(): number {
42
+ return Math.max(0, $props?.overscan ?? 3);
43
+ }
44
+
45
+ function getItemHeight(): number {
46
+ return Math.max(1, $props?.itemHeight ?? 1);
47
+ }
48
+
49
+ let $state = $watch({
50
+ scrollTop: 0,
51
+ viewport: $props?.height ?? 0,
52
+ get start(): number {
53
+ return $cache(() => {
54
+ return Math.max(0, Math.floor($state.scrollTop / getItemHeight()) - getOverscan());
55
+ });
56
+ },
57
+ get end(): number {
58
+ return $cache(() => {
59
+ const items = $props?.items ?? [];
60
+ // Before the viewport has been measured, render a small window
61
+ // so the list still has content on the server and before mount
62
+ const viewport = $state.viewport || getItemHeight() * 10;
63
+ const count = Math.ceil(viewport / getItemHeight()) + getOverscan() * 2;
64
+ return Math.min(items.length, $state.start + count);
65
+ });
66
+ },
67
+ get visible(): { item: any; index: number }[] {
68
+ return $cache(() => {
69
+ const items = $props?.items ?? [];
70
+ const visible: { item: any; index: number }[] = [];
71
+ for (let i = $state.start; i < $state.end; i++) {
72
+ visible.push({ item: items[i], index: i });
73
+ }
74
+ return visible;
75
+ });
76
+ },
77
+ });
78
+
79
+ // A height prop takes precedence over the measured height; otherwise
80
+ // watch the element so CSS-driven sizes work
81
+ $run(() => {
82
+ const height = $props?.height;
83
+ if (height !== undefined) {
84
+ $state.viewport = height;
85
+ }
86
+ });
87
+
88
+ function measure() {
89
+ if ($props?.height === undefined && root) {
90
+ $state.viewport = root.clientHeight;
91
+ }
92
+ }
93
+
94
+ function handleScroll(e: Event) {
95
+ $state.scrollTop = (e.currentTarget as HTMLElement).scrollTop;
96
+ }
97
+
98
+ function attach(el: HTMLElement) {
99
+ root = el;
100
+ measure();
101
+ if ($props?.height === undefined && typeof ResizeObserver !== "undefined") {
102
+ observer = new ResizeObserver(measure);
103
+ observer.observe(el);
104
+ }
105
+ return () => {
106
+ observer?.disconnect();
107
+ observer = undefined;
108
+ if (root === el) root = undefined;
109
+ };
110
+ }
111
+
112
+ @render {
113
+ <div
114
+ {$props?.id}
115
+ class={["torp-virtual-list", $props?.class]}
116
+ style={[$props?.style, $props?.height !== undefined ? `height:${$props.height}px` : undefined]}
117
+ role="list"
118
+ aria-label={$props?.ariaLabel}
119
+ onscroll={handleScroll}
120
+ onmount={attach}
121
+ >
122
+ <div
123
+ class="torp-virtual-list-spacer"
124
+ style={`height:${($props?.items?.length ?? 0) * getItemHeight()}px`}
125
+ >
126
+ @for (let entry of $state.visible) {
127
+ @key = entry.index
128
+ <div
129
+ class="torp-virtual-list-item"
130
+ role="listitem"
131
+ data-index={entry.index}
132
+ style={`position:absolute;top:${entry.index * getItemHeight()}px;height:${getItemHeight()}px;left:0;right:0`}
133
+ >
134
+ <slot item={entry.item} index={entry.index} />
135
+ </div>
136
+ }
137
+ </div>
138
+ </div>
139
+ }
140
+
141
+ @style {
142
+ .torp-virtual-list {
143
+ overflow: auto;
144
+ }
145
+ .torp-virtual-list-spacer {
146
+ position: relative;
147
+ }
148
+ }
149
+ }
@@ -0,0 +1,46 @@
1
+ import { type SlotRender } from "@torpor/view";
2
+
3
+
4
+ interface VirtualListProps {
5
+ /** An ID for the root element */
6
+ id?: string;
7
+ /** Classes for the root element */
8
+ class?: ClassValue;
9
+ /** Styles for the root element */
10
+ style?: StyleValue;
11
+ /** The items to render */
12
+ items: any[];
13
+ /** The fixed height of each item, in pixels */
14
+ itemHeight: number;
15
+ /** The height of the scroll viewport, in pixels; defaults to the element's height */
16
+ height?: number;
17
+ /** Extra items to render above and below the viewport (default 3) */
18
+ overscan?: number;
19
+ /** An accessible name for the list */
20
+ ariaLabel?: string;
21
+ }
22
+
23
+ /**
24
+ * A list that renders only the items in and around its scroll viewport, for
25
+ * large collections with fixed-height rows.
26
+ *
27
+ * The slot is rendered once per visible item, with the item and its index
28
+ * passed back as `$slot.item` and `$slot.index`:
29
+ *
30
+ * ```
31
+ * <VirtualList items={$state.rows} itemHeight={32} height={400} ariaLabel="Log">
32
+ * <div>{$slot.item.label}</div>
33
+ * </VirtualList>
34
+ * ```
35
+ *
36
+ * DataGrid has its own virtualization; use this for simpler lists.
37
+ */
38
+ declare function VirtualList(
39
+ $parent: ParentNode,
40
+ $anchor: Node | null,
41
+ $props: VirtualListProps | undefined,
42
+ $context?: Record<PropertyKey, any>,
43
+ $slots?: Record<string, SlotRender>,
44
+ ): void;
45
+
46
+ export { VirtualList };
@@ -0,0 +1 @@
1
+ export { default as VirtualList } from "./VirtualList.torp";
@@ -0,0 +1,2 @@
1
+ import { type SlotRender } from "@torpor/view";
2
+ export { };
@@ -0,0 +1,212 @@
1
+ import { $watch } from "@torpor/view";
2
+ //#region src/utils/dragState.ts
3
+ const dragState = $watch({ current: void 0 });
4
+ let nextId = 0;
5
+ /** Starts tracking a drag and returns its id */
6
+ function beginDrag(kind, data) {
7
+ const info = {
8
+ id: String(nextId++),
9
+ kind,
10
+ data
11
+ };
12
+ dragState.current = info;
13
+ return info;
14
+ }
15
+ /** Clears the tracked drag */
16
+ function endDrag() {
17
+ dragState.current = void 0;
18
+ }
19
+ const TYPE_PREFIX = "application/x-torpor-drag/";
20
+ /** Encodes a drag id into a dataTransfer-compatible mime type */
21
+ function encodeDragType(id) {
22
+ return TYPE_PREFIX + id;
23
+ }
24
+ /**
25
+ * Writes the drag's id into the event's dataTransfer. No-op when the event
26
+ * carries no transfer (some synthetic tests construct bare events).
27
+ */
28
+ function writeDragType(e, id) {
29
+ e.dataTransfer?.setData(encodeDragType(id), id);
30
+ }
31
+ /**
32
+ * Resolves which drag an incoming event refers to. Prefers the id encoded
33
+ * in the dataTransfer (verified against the live drag); falls back to the
34
+ * tracked drag itself for dragover events, whose transfers are locked.
35
+ */
36
+ function resolveDrag(e) {
37
+ const current = dragState.current;
38
+ if (!current) return void 0;
39
+ try {
40
+ const types = e.dataTransfer?.types ?? [];
41
+ for (let type of types) if (type.startsWith(TYPE_PREFIX)) return type === encodeDragType(current.id) ? current : void 0;
42
+ } catch {}
43
+ return current;
44
+ }
45
+ //#endregion
46
+ //#region src/mount/draggable.ts
47
+ /**
48
+ * Makes an element draggable via the native HTML5 drag & drop API.
49
+ *
50
+ * ```
51
+ * <li onmount={(el) => draggable(el, { kind: "list-item", data: item })}>
52
+ * ```
53
+ *
54
+ * Pairs with dropTarget, which receives `{ kind, data }` for accepted
55
+ * drops. The tracked drag is always cleaned up on dragend, so handlers
56
+ * don't leak between drags.
57
+ */
58
+ function draggable(node, options) {
59
+ let started = false;
60
+ function handleStart(e) {
61
+ if (options.onstart?.(e) === false) {
62
+ e.preventDefault();
63
+ return;
64
+ }
65
+ writeDragType(e, beginDrag(options.kind ?? "", options.data).id);
66
+ if (e.dataTransfer) e.dataTransfer.effectAllowed = "move";
67
+ started = true;
68
+ }
69
+ function handleEnd(e) {
70
+ if (started) {
71
+ started = false;
72
+ endDrag();
73
+ options.onend?.(e);
74
+ }
75
+ }
76
+ node.addEventListener("dragstart", handleStart);
77
+ node.addEventListener("dragend", handleEnd);
78
+ return () => {
79
+ node.removeEventListener("dragstart", handleStart);
80
+ node.removeEventListener("dragend", handleEnd);
81
+ if (started) {
82
+ started = false;
83
+ endDrag();
84
+ }
85
+ };
86
+ }
87
+ //#endregion
88
+ //#region src/mount/dropTarget.ts
89
+ /**
90
+ * Turns an element into a drop target for native HTML5 drags.
91
+ *
92
+ * ```
93
+ * <div
94
+ * class="panel"
95
+ * onmount={(el) =>
96
+ * dropTarget(el, {
97
+ * accepts: (info) => info.kind === "list-item",
98
+ * dragClass: "dropping",
99
+ * ondrop: (info) => addItem(info.data),
100
+ * })
101
+ * }
102
+ * />
103
+ * ```
104
+ *
105
+ * Handles the tedious parts of the platform API -- preventing the browser's
106
+ * default navigation, resolving the tracked drag, effect negotiation --
107
+ * so components only express what they accept and what happens on drop.
108
+ */
109
+ function dropTarget(node, options) {
110
+ let hoverClassApplied = false;
111
+ function accepts(info) {
112
+ return !!info && (!options.accepts || options.accepts(info));
113
+ }
114
+ function applyHover() {
115
+ if (!hoverClassApplied && options.dragClass) {
116
+ hoverClassApplied = true;
117
+ node.classList.add(options.dragClass);
118
+ }
119
+ }
120
+ function removeHover() {
121
+ if (hoverClassApplied) {
122
+ hoverClassApplied = false;
123
+ node.classList.remove(options.dragClass);
124
+ }
125
+ }
126
+ function handleOver(e) {
127
+ const info = resolveDrag(e);
128
+ if (!accepts(info)) return;
129
+ e.preventDefault();
130
+ if (e.dataTransfer) e.dataTransfer.dropEffect = options.effect ?? "move";
131
+ applyHover();
132
+ options.onover?.(info, e);
133
+ }
134
+ function handleEnter(e) {
135
+ const info = resolveDrag(e);
136
+ if (!accepts(info)) return;
137
+ applyHover();
138
+ options.onenter?.(info, e);
139
+ }
140
+ function handleLeave(e) {
141
+ const related = e.relatedTarget;
142
+ if (related && node.contains(related)) return;
143
+ removeHover();
144
+ options.onleave?.();
145
+ }
146
+ function handleDrop(e) {
147
+ e.preventDefault();
148
+ removeHover();
149
+ const info = resolveDrag(e);
150
+ if (!accepts(info)) return;
151
+ options.ondrop?.(info, e);
152
+ }
153
+ node.addEventListener("dragover", handleOver);
154
+ node.addEventListener("dragenter", handleEnter);
155
+ node.addEventListener("dragleave", handleLeave);
156
+ node.addEventListener("drop", handleDrop);
157
+ return () => {
158
+ removeHover();
159
+ node.removeEventListener("dragover", handleOver);
160
+ node.removeEventListener("dragenter", handleEnter);
161
+ node.removeEventListener("dragleave", handleLeave);
162
+ node.removeEventListener("drop", handleDrop);
163
+ };
164
+ }
165
+ //#endregion
166
+ //#region src/utils/reorderList.ts
167
+ /**
168
+ * Pure helpers for reorderable collections, used by list and tree drag &
169
+ * drop. Geometry-free on purpose: components measure their own slots with
170
+ * slotIndex and combine the result with these.
171
+ */
172
+ /** Moves an item to a final index; out-of-range targets are clamped */
173
+ function moveItem(items, from, to) {
174
+ const next = items.slice();
175
+ if (from < 0 || from >= next.length) return next;
176
+ const clamped = Math.min(next.length - 1, Math.max(0, to));
177
+ const [item] = next.splice(from, 1);
178
+ next.splice(clamped, 0, item);
179
+ return next;
180
+ }
181
+ /**
182
+ * Moves an item to sit at the slot `insertAt` occupied *before* the move --
183
+ * i.e. `insertAt` indexes into the original order, which is what pointer
184
+ * math produces (dropped before item N). Handles the index shift caused by
185
+ * removing the dragged element.
186
+ */
187
+ function moveToSlot(items, from, insertAt) {
188
+ let to = insertAt;
189
+ if (from < insertAt) to = insertAt - 1;
190
+ return moveItem(items, from, to);
191
+ }
192
+ /**
193
+ * Finds which slot a pointer sits in along an axis: the index of the first
194
+ * element whose midpoint the point has passed (or elements.length when past
195
+ * all of them). `elements` must already be in display order.
196
+ *
197
+ * ```
198
+ * const insert = slotIndex([...list.children], "y", e.clientY);
199
+ * list.set(items => moveToSlot(items, dragFrom, insert));
200
+ * ```
201
+ */
202
+ function slotIndex(elements, axis, point) {
203
+ for (let i = 0; i < elements.length; i++) {
204
+ const rect = elements[i].getBoundingClientRect();
205
+ if (point < (axis === "x" ? rect.left + rect.width / 2 : rect.top + rect.height / 2)) return i;
206
+ }
207
+ return elements.length;
208
+ }
209
+ //#endregion
210
+ export { beginDrag, dragState, draggable, dropTarget, encodeDragType, endDrag, moveItem, moveToSlot, resolveDrag, slotIndex, writeDragType };
211
+
212
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/utils/dragState.ts","../../src/mount/draggable.ts","../../src/mount/dropTarget.ts","../../src/utils/reorderList.ts"],"sourcesContent":["import { $watch } from \"@torpor/view\";\n\n/**\n * Shared state for HTML5 drag & drop. A source element starts a drag with\n * `beginDrag`; drop targets consult `dragState.current` during dragover and\n * drop. Because the dataTransfer API restricts what can be read outside\n * drop, the store is the reliable channel -- the dataTransfer only carries\n * the drag's id, which doubles as an integrity check and makes drags\n * interoperable across windows when the type is allowed through.\n *\n * Drags don't nest, so a single module-level state is enough.\n */\n\nexport interface DragInfo {\n\t/** Generated identifier for this drag, mirrored into the dataTransfer */\n\tid: string;\n\t/** High-level kind (\"list-item\", \"tree-item\", \"file\"...), for filtering */\n\tkind: string;\n\t/** Arbitrary payload attached by the drag source */\n\tdata: any;\n}\n\nexport interface DragState {\n\t/** The active drag, if any */\n\tcurrent: DragInfo | undefined;\n}\n\nexport const dragState: DragState = $watch({\n\tcurrent: undefined as DragInfo | undefined,\n});\n\nlet nextId = 0;\n\n/** Starts tracking a drag and returns its id */\nexport function beginDrag(kind: string, data: any): DragInfo {\n\tconst info: DragInfo = {\n\t\tid: String(nextId++),\n\t\tkind,\n\t\tdata,\n\t};\n\tdragState.current = info;\n\treturn info;\n}\n\n/** Clears the tracked drag */\nexport function endDrag(): void {\n\tdragState.current = undefined;\n}\n\nconst TYPE_PREFIX = \"application/x-torpor-drag/\";\n\n/** Encodes a drag id into a dataTransfer-compatible mime type */\nexport function encodeDragType(id: string): string {\n\treturn TYPE_PREFIX + id;\n}\n\n/**\n * Writes the drag's id into the event's dataTransfer. No-op when the event\n * carries no transfer (some synthetic tests construct bare events).\n */\nexport function writeDragType(e: DragEvent, id: string): void {\n\te.dataTransfer?.setData(encodeDragType(id), id);\n}\n\n/**\n * Resolves which drag an incoming event refers to. Prefers the id encoded\n * in the dataTransfer (verified against the live drag); falls back to the\n * tracked drag itself for dragover events, whose transfers are locked.\n */\nexport function resolveDrag(e: DragEvent): DragInfo | undefined {\n\tconst current = dragState.current;\n\tif (!current) return undefined;\n\n\ttry {\n\t\tconst types: readonly string[] = e.dataTransfer?.types ?? [];\n\t\tfor (let type of types) {\n\t\t\tif (type.startsWith(TYPE_PREFIX)) {\n\t\t\t\treturn type === encodeDragType(current.id) ? current : undefined;\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// Reading types can throw for foreign-origin drags; treat those as\n\t\t// unmatched and fall back to the tracked drag below\n\t}\n\treturn current;\n}\n","import { beginDrag, endDrag, writeDragType } from \"../utils/dragState\";\n\ninterface DraggableOptions {\n\t/** High-level kind for drop targets to filter on */\n\tkind?: string;\n\t/** Payload handed to the drop target that receives this drag */\n\tdata?: any;\n\t/**\n\t * Called when a drag starts; returning false cancels the drag entirely\n\t * (useful for drags-in-progress controls, readonly flags etc)\n\t */\n\tonstart?: (e: DragEvent) => boolean | void;\n\t/** Called when the drag finishes, whether it was dropped or cancelled */\n\tonend?: (e: DragEvent) => void;\n}\n\n/**\n * Makes an element draggable via the native HTML5 drag & drop API.\n *\n * ```\n * <li onmount={(el) => draggable(el, { kind: \"list-item\", data: item })}>\n * ```\n *\n * Pairs with dropTarget, which receives `{ kind, data }` for accepted\n * drops. The tracked drag is always cleaned up on dragend, so handlers\n * don't leak between drags.\n */\nexport default function draggable(node: HTMLElement, options: DraggableOptions): () => void {\n\tlet started = false;\n\n\tfunction handleStart(e: DragEvent) {\n\t\tif (options.onstart?.(e) === false) {\n\t\t\te.preventDefault();\n\t\t\treturn;\n\t\t}\n\t\tconst info = beginDrag(options.kind ?? \"\", options.data);\n\t\twriteDragType(e, info.id);\n\t\tif (e.dataTransfer) {\n\t\t\te.dataTransfer.effectAllowed = \"move\";\n\t\t}\n\t\tstarted = true;\n\t}\n\n\tfunction handleEnd(e: DragEvent) {\n\t\tif (started) {\n\t\t\tstarted = false;\n\t\t\tendDrag();\n\t\t\toptions.onend?.(e);\n\t\t}\n\t}\n\n\tnode.addEventListener(\"dragstart\", handleStart);\n\tnode.addEventListener(\"dragend\", handleEnd);\n\n\treturn () => {\n\t\tnode.removeEventListener(\"dragstart\", handleStart);\n\t\tnode.removeEventListener(\"dragend\", handleEnd);\n\t\tif (started) {\n\t\t\tstarted = false;\n\t\t\tendDrag();\n\t\t}\n\t};\n}\n","import { type DragInfo, resolveDrag } from \"../utils/dragState\";\n\ninterface DropTargetOptions {\n\t/** Filters incoming drags; only accepted kinds receive over/drop calls */\n\taccepts?: (info: DragInfo) => boolean;\n\t/** The cursor effect shown while hovering (default \"move\") */\n\teffect?: \"move\" | \"copy\" | \"link\";\n\t/** Called continuously while an accepted drag hovers the target */\n\tonover?: (info: DragInfo, e: DragEvent) => void;\n\t/** Called once when hovering starts */\n\tonenter?: (info: DragInfo, e: DragEvent) => void;\n\t/** Called once when hovering ends */\n\tonleave?: () => void;\n\t/** Called when an accepted drag is dropped; returning false rejects it */\n\tondrop?: (info: DragInfo, e: DragEvent) => boolean | void;\n\t/** Class applied while an accepted drag hovers the target */\n\tdragClass?: string;\n}\n\n/**\n * Turns an element into a drop target for native HTML5 drags.\n *\n * ```\n * <div\n * \tclass=\"panel\"\n * \tonmount={(el) =>\n * \t\tdropTarget(el, {\n * \t\t\taccepts: (info) => info.kind === \"list-item\",\n * \t\t\tdragClass: \"dropping\",\n * \t\t\tondrop: (info) => addItem(info.data),\n * \t\t})\n * \t}\n * />\n * ```\n *\n * Handles the tedious parts of the platform API -- preventing the browser's\n * default navigation, resolving the tracked drag, effect negotiation --\n * so components only express what they accept and what happens on drop.\n */\nexport default function dropTarget(node: HTMLElement, options: DropTargetOptions): () => void {\n\tlet hoverClassApplied = false;\n\n\tfunction accepts(info: DragInfo | undefined): info is DragInfo {\n\t\treturn !!info && (!options.accepts || options.accepts(info));\n\t}\n\n\tfunction applyHover() {\n\t\tif (!hoverClassApplied && options.dragClass) {\n\t\t\thoverClassApplied = true;\n\t\t\tnode.classList.add(options.dragClass);\n\t\t}\n\t}\n\n\tfunction removeHover() {\n\t\tif (hoverClassApplied) {\n\t\t\thoverClassApplied = false;\n\t\t\tnode.classList.remove(options.dragClass!);\n\t\t}\n\t}\n\n\tfunction handleOver(e: DragEvent) {\n\t\tconst info = resolveDrag(e);\n\t\tif (!accepts(info)) return;\n\n\t\te.preventDefault();\n\t\tif (e.dataTransfer) {\n\t\t\te.dataTransfer.dropEffect = options.effect ?? \"move\";\n\t\t}\n\t\tapplyHover();\n\t\toptions.onover?.(info!, e);\n\t}\n\n\tfunction handleEnter(e: DragEvent) {\n\t\tconst info = resolveDrag(e);\n\t\tif (!accepts(info)) return;\n\t\tapplyHover();\n\t\toptions.onenter?.(info!, e);\n\t}\n\n\tfunction handleLeave(e: DragEvent) {\n\t\tconst related = e.relatedTarget as Node | null;\n\t\tif (related && node.contains(related)) return;\n\t\tremoveHover();\n\t\toptions.onleave?.();\n\t}\n\n\tfunction handleDrop(e: DragEvent) {\n\t\te.preventDefault();\n\t\tremoveHover();\n\n\t\tconst info = resolveDrag(e);\n\t\tif (!accepts(info)) return;\n\t\toptions.ondrop?.(info!, e);\n\t}\n\n\tnode.addEventListener(\"dragover\", handleOver);\n\tnode.addEventListener(\"dragenter\", handleEnter);\n\tnode.addEventListener(\"dragleave\", handleLeave);\n\tnode.addEventListener(\"drop\", handleDrop);\n\n\treturn () => {\n\t\tremoveHover();\n\t\tnode.removeEventListener(\"dragover\", handleOver);\n\t\tnode.removeEventListener(\"dragenter\", handleEnter);\n\t\tnode.removeEventListener(\"dragleave\", handleLeave);\n\t\tnode.removeEventListener(\"drop\", handleDrop);\n\t};\n}\n","/**\n * Pure helpers for reorderable collections, used by list and tree drag &\n * drop. Geometry-free on purpose: components measure their own slots with\n * slotIndex and combine the result with these.\n */\n\n/** Moves an item to a final index; out-of-range targets are clamped */\nexport function moveItem<T>(items: T[], from: number, to: number): T[] {\n\tconst next = items.slice();\n\tif (from < 0 || from >= next.length) return next;\n\tconst clamped = Math.min(next.length - 1, Math.max(0, to));\n\tconst [item] = next.splice(from, 1);\n\tnext.splice(clamped, 0, item);\n\treturn next;\n}\n\n/**\n * Moves an item to sit at the slot `insertAt` occupied *before* the move --\n * i.e. `insertAt` indexes into the original order, which is what pointer\n * math produces (dropped before item N). Handles the index shift caused by\n * removing the dragged element.\n */\nexport function moveToSlot<T>(items: T[], from: number, insertAt: number): T[] {\n\tlet to = insertAt;\n\tif (from < insertAt) {\n\t\tto = insertAt - 1;\n\t}\n\treturn moveItem(items, from, to);\n}\n\n/**\n * Finds which slot a pointer sits in along an axis: the index of the first\n * element whose midpoint the point has passed (or elements.length when past\n * all of them). `elements` must already be in display order.\n *\n * ```\n * const insert = slotIndex([...list.children], \"y\", e.clientY);\n * list.set(items => moveToSlot(items, dragFrom, insert));\n * ```\n */\nexport function slotIndex(\n\telements: { getBoundingClientRect(): DOMRect }[],\n\taxis: \"x\" | \"y\",\n\tpoint: number,\n): number {\n\tfor (let i = 0; i < elements.length; i++) {\n\t\tconst rect = elements[i].getBoundingClientRect();\n\t\tconst mid = axis === \"x\" ? rect.left + rect.width / 2 : rect.top + rect.height / 2;\n\t\tif (point < mid) return i;\n\t}\n\treturn elements.length;\n}\n"],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ import { type SlotRender } from "@torpor/view";
2
+ export { };
@@ -46,6 +46,6 @@ function createItemLoader(options) {
46
46
  });
47
47
  }
48
48
  //#endregion
49
- export { normalizeLoadResult as n, createItemLoader as t };
49
+ export { createItemLoader, normalizeLoadResult };
50
50
 
51
- //# sourceMappingURL=loader-CBGbVpkN.js.map
51
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/utils/loader.ts"],"sourcesContent":["import { $async, $watch } from \"@torpor/view\";\n\n/**\n * Shared contract for loading data from the network, used by components that\n * can take either static data or a loader function (DataGrid now, ComboBox\n * auto-complete and others later).\n *\n * A loader receives a request object describing what to fetch -- paging,\n * search text and sorting are standard; components extend it with their own\n * fields -- plus an AbortSignal so stale requests can be cancelled.\n */\n\n/** The base shape of a load request. Components extend this with their own fields. */\nexport interface LoadRequest {\n\t/** 1-based page number to load */\n\tpage?: number;\n\t/** Number of items per page */\n\tpageSize?: number;\n\t/** Search or filter text entered by the user */\n\tsearchText?: string;\n\t/** The field to sort by */\n\tsortBy?: string;\n\t/** The direction to sort in */\n\tsortDirection?: \"asc\" | \"desc\";\n}\n\n/**\n * The result of a load: the items for the current request, and optionally\n * the total count (needed for paged components to show a pager).\n */\nexport interface LoadResult<T = any> {\n\titems: T[];\n\t/** The total number of items across all pages, if known */\n\ttotal?: number;\n}\n\n/**\n * Reads data for a request. May return a promise or a plain result, and may\n * return just an array of items when no total is available.\n */\nexport type Loader<T = any, TRequest extends LoadRequest = LoadRequest> = (\n\trequest: TRequest,\n\tsignal?: AbortSignal,\n) => Promise<LoadResult<T> | T[]> | LoadResult<T> | T[];\n\n/** Wraps a bare array in a LoadResult so consumers always get the same shape */\nexport function normalizeLoadResult<T>(result: LoadResult<T> | T[]): LoadResult<T> {\n\treturn Array.isArray(result) ? { items: result } : result;\n}\n\nexport interface ItemLoaderOptions<T = any, TRequest extends LoadRequest = LoadRequest> {\n\t/** The loader function to fetch items */\n\tload: Loader<T, TRequest>;\n\t/**\n\t * Builds the request for the current fetch. Called inside the async\n\t * getter, so reads of reactive state here re-fetch when they change.\n\t */\n\tgetRequest: () => TRequest;\n\t/** Called after each successful load with the normalized result */\n\tonload?: (result: LoadResult<T>) => void;\n}\n\n/** Reactive loading state returned by createItemLoader */\nexport interface ItemLoaderState<T = any> {\n\t/** The full result of the current load; suspends while a fetch is pending */\n\treadonly result: LoadResult<T> | undefined;\n\t/** The loaded items; suspends while a fetch is pending */\n\treadonly items: T[];\n}\n\n/**\n * Shared loading state for components that read items from a network loader\n * (DataGrid, ComboBox auto-complete etc). Read the returned state's `items`\n * or `result` inside an `@await` boundary: while a fetch is pending the read\n * suspends, and when dependencies read inside `getRequest` change the fetch\n * re-runs.\n *\n * For lazy loading (fetch only once some condition is met), gate the whole\n * rendering of the region that reads this loader behind that condition\n * (`@if`), so the `@await` boundary -- and with it the first fetch --\n * comes into existence when the condition flips.\n *\n * ```\n * let $load = createItemLoader({\n * \tload: $props.load,\n * \tgetRequest: () => ({ searchText: $state.searchText }),\n * });\n * @await { ...$load.items... } with { <span>Loading…</span> }\n * ```\n */\nexport function createItemLoader<T = any, TRequest extends LoadRequest = LoadRequest>(\n\toptions: ItemLoaderOptions<T, TRequest>,\n): ItemLoaderState<T> {\n\t// The in-flight fetch's controller: a re-run (search text changed, item\n\t// expanded) aborts it, so loaders that take the signal can cancel the\n\t// wire request. The $async generation guard discards stale results\n\t// application-side either way.\n\tlet abort: AbortController | null = null;\n\n\treturn $watch({\n\t\tget result(): LoadResult<T> | undefined {\n\t\t\treturn $async(() => {\n\t\t\t\tabort?.abort();\n\t\t\t\tconst controller = new AbortController();\n\t\t\t\tabort = controller;\n\t\t\t\tconst promise = Promise.resolve(options.load(options.getRequest(), controller.signal))\n\t\t\t\t\t.then(normalizeLoadResult)\n\t\t\t\t\t.catch((error) => {\n\t\t\t\t\t\t// Our own abort is not an error — the superseding fetch\n\t\t\t\t\t\t// owns the UI, so this one never settles instead of\n\t\t\t\t\t\t// rejecting into the await boundary\n\t\t\t\t\t\tif (controller.signal.aborted) {\n\t\t\t\t\t\t\treturn new Promise<LoadResult<T>>(() => {});\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t});\n\t\t\t\t// Report successful loads to the consumer; failures surface\n\t\t\t\t// through the component's error boundary, not this chain\n\t\t\t\tpromise.then(\n\t\t\t\t\t(r) => options.onload?.(r),\n\t\t\t\t\t() => {},\n\t\t\t\t);\n\t\t\t\treturn promise as Promise<LoadResult<T>>;\n\t\t\t});\n\t\t},\n\t\tget items(): T[] {\n\t\t\treturn this.result?.items ?? [];\n\t\t},\n\t});\n}\n"],"mappings":";;;AA8CA,SAAgB,oBAAuB,QAA4C;CAClF,OAAO,MAAM,QAAQ,MAAM,IAAI,EAAE,OAAO,OAAO,IAAI;AACpD;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,iBACf,SACqB;CAKrB,IAAI,QAAgC;CAEpC,OAAO,OAAO;EACb,IAAI,SAAoC;GACvC,OAAO,aAAa;IACnB,OAAO,MAAM;IACb,MAAM,aAAa,IAAI,gBAAgB;IACvC,QAAQ;IACR,MAAM,UAAU,QAAQ,QAAQ,QAAQ,KAAK,QAAQ,WAAW,GAAG,WAAW,MAAM,CAAC,CAAC,CACpF,KAAK,mBAAmB,CAAC,CACzB,OAAO,UAAU;KAIjB,IAAI,WAAW,OAAO,SACrB,OAAO,IAAI,cAA6B,CAAC,CAAC;KAE3C,MAAM;IACP,CAAC;IAGF,QAAQ,MACN,MAAM,QAAQ,SAAS,CAAC,SACnB,CAAC,CACR;IACA,OAAO;GACR,CAAC;EACF;EACA,IAAI,QAAa;GAChB,OAAO,KAAK,QAAQ,SAAS,CAAC;EAC/B;CACD,CAAC;AACF"}
@@ -64,6 +64,7 @@ export default function PopoutClickTrigger($props?: PopoutClickTriggerProps) {
64
64
 
65
65
  function handleMount(el: HTMLElement) {
66
66
  context.anchorElement = el;
67
+ context.focusTrigger = () => el.focus();
67
68
  }
68
69
 
69
70
  @render {
@@ -0,0 +1,39 @@
1
+ import type { ClassValue, StyleValue } from "@torpor/view";
2
+ import { disableScroll } from "../mount/disableScroll";
3
+ import type { PopoutContext } from "./PopoutTypes";
4
+
5
+ interface PopoutOverlayProps {
6
+ /** An ID for the root element */
7
+ id?: string;
8
+ /** Classes for the root element */
9
+ class?: ClassValue;
10
+ /** Styles for the root element */
11
+ style?: StyleValue;
12
+ /** The containing popout's context (the family-specific one) */
13
+ context: PopoutContext;
14
+ }
15
+
16
+ /**
17
+ * The shared background overlay behind modal popouts. Adding an overlay
18
+ * automatically sets the component's `modal` value to true.
19
+ */
20
+ export default function PopoutOverlay($props: PopoutOverlayProps | undefined) {
21
+ const $state = $props!.context.state;
22
+
23
+ // Any popup with an overlay is modal
24
+ $state.modal = true;
25
+
26
+ @render {
27
+ @if ($state.visible) {
28
+ <div
29
+ {$props?.id}
30
+ class={$props?.class}
31
+ {$props?.style}
32
+ tabindex="-1"
33
+ onmount={(_el) => disableScroll()}
34
+ >
35
+ <slot />
36
+ </div>
37
+ }
38
+ }
39
+ }
@@ -30,6 +30,8 @@ export interface PopoutContext extends FocusApi {
30
30
  state: PopoutState;
31
31
  //modal: boolean;
32
32
  anchorElement?: HTMLElement;
33
+ /** Focuses the trigger, used when a popout hides */
34
+ focusTrigger?: () => void;
33
35
 
34
36
  /**
35
37
  * Called from menu content when an arrow key should move to an adjacent item
@@ -55,6 +57,8 @@ export interface PopoutState {
55
57
  contentRole?: string;
56
58
  /** Whether the popout is modal (e.g. it has an overlay) */
57
59
  modal?: boolean;
60
+ /** The selected value, for input popouts such as SelectBox and ComboBox */
61
+ value?: any;
58
62
  /** The ID of the active descendant element, for aria-activedescendant */
59
63
  activeDescendant?: string;
60
64
  }
@@ -27,7 +27,7 @@ interface SubmenuPopoutTriggerProps {
27
27
  /** The containing group's registration function */
28
28
  registerItem: (item: SubmenuItemState) => { index: number };
29
29
  /** Called with the registration index, for wrappers that need it elsewhere */
30
- onRegister?: (index: number) => void;
30
+ onregister?: (index: number) => void;
31
31
  /** The containing group's key handler, called for keys other than openKey */
32
32
  handleItemKey: (e: KeyboardEvent) => void;
33
33
  /** The containing group's focus handler */
@@ -41,7 +41,7 @@ interface SubmenuPopoutTriggerProps {
41
41
  * Called with the registration index when the trigger is activated by
42
42
  * clicking or with openKey, before the popout is shown
43
43
  */
44
- onActivate?: (index: number) => void;
44
+ onactivate?: (index: number) => void;
45
45
  /** Replaces the default toggle behaviour when the trigger is clicked */
46
46
  onclick?: () => void;
47
47
  }
@@ -78,7 +78,7 @@ export default function SubmenuPopoutTrigger($props: SubmenuPopoutTriggerProps |
78
78
  // Register this item with the containing group and store the index
79
79
  const item: SubmenuItemState = { setFocused, setVisible, disabled: $props?.disabled };
80
80
  const { index } = $props!.registerItem(item);
81
- $props?.onRegister?.(index);
81
+ $props?.onregister?.(index);
82
82
 
83
83
  function setFocused() {
84
84
  button.focus();
@@ -91,7 +91,7 @@ export default function SubmenuPopoutTrigger($props: SubmenuPopoutTriggerProps |
91
91
  }
92
92
 
93
93
  function activate() {
94
- $props?.onActivate?.(index);
94
+ $props?.onactivate?.(index);
95
95
  }
96
96
 
97
97
  function handleClick() {
@@ -117,7 +117,7 @@ export default function SubmenuPopoutTrigger($props: SubmenuPopoutTriggerProps |
117
117
  const hoverDelay = $props?.hoverDelay ?? 500;
118
118
  const hoverOpen = createHoverOpen(
119
119
  () => setVisible(true),
120
- () => $props?.disabled ?? false,
120
+ () => $props?.disabled === true,
121
121
  hoverDelay,
122
122
  );
123
123