@jsudc/react 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +556 -19
- package/dist/calendar/CalendarRenderer.js +1 -1
- package/dist/calendar/EventDetail.js +1 -1
- package/dist/calendar.js +1 -1
- package/dist/cards/CardRenderer.d.ts +2 -1
- package/dist/cards/CardRenderer.js +143 -109
- package/dist/cards/CardRenderer.js.map +1 -1
- package/dist/cells/registry.d.ts +60 -0
- package/dist/cells/registry.js +47 -0
- package/dist/cells/registry.js.map +1 -0
- package/dist/chart/ChartWindowControl.js +1 -1
- package/dist/components/ui/checkbox.js +1 -1
- package/dist/components/ui/dialog.js +4 -3
- package/dist/components/ui/dialog.js.map +1 -1
- package/dist/components/ui/dropdown-menu.js +2 -1
- package/dist/components/ui/dropdown-menu.js.map +1 -1
- package/dist/components/ui/popover.js +2 -1
- package/dist/components/ui/popover.js.map +1 -1
- package/dist/components/ui/select.js +2 -1
- package/dist/components/ui/select.js.map +1 -1
- package/dist/components/ui/toast.js +3 -2
- package/dist/components/ui/toast.js.map +1 -1
- package/dist/components/ui/tooltip.js +2 -1
- package/dist/components/ui/tooltip.js.map +1 -1
- package/dist/data-view/FilterBuilder.js +1 -1
- package/dist/data-view/FilterChips.js +1 -1
- package/dist/data-view/Freshness.js +1 -1
- package/dist/data-view/SearchBox.js +1 -1
- package/dist/data-view/UdcDataView.d.ts +83 -1
- package/dist/data-view/UdcDataView.js +171 -85
- package/dist/data-view/UdcDataView.js.map +1 -1
- package/dist/data-view/useDataViewState.d.ts +8 -0
- package/dist/data-view/useDataViewState.js +2 -1
- package/dist/data-view/useDataViewState.js.map +1 -1
- package/dist/headless.d.ts +3 -0
- package/dist/headless.js +4 -1
- package/dist/i18n/translations.js +8 -0
- package/dist/i18n/translations.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.js +7 -3
- package/dist/kanban/KanbanColumn.js +1 -1
- package/dist/kanban/KanbanRenderer.js +1 -1
- package/dist/lib/scope.d.ts +8 -0
- package/dist/lib/scope.js +12 -0
- package/dist/lib/scope.js.map +1 -0
- package/dist/lookup/LookupCombobox.js +1 -1
- package/dist/map/MapRenderer.js +1 -1
- package/dist/renderers/types.d.ts +12 -0
- package/dist/renderers/types.js.map +1 -1
- package/dist/rows/useRowActivation.d.ts +74 -0
- package/dist/rows/useRowActivation.js +225 -0
- package/dist/rows/useRowActivation.js.map +1 -0
- package/dist/schema-editor/DeleteFieldDialog.js +1 -1
- package/dist/schema-editor/FieldFormDialog.js +1 -1
- package/dist/schema-editor/TagInput.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.scoped.css +2 -0
- package/dist/table/CellEditor.js +1 -0
- package/dist/table/CellEditor.js.map +1 -1
- package/dist/table/TableRenderer.d.ts +2 -1
- package/dist/table/TableRenderer.js +41 -8
- package/dist/table/TableRenderer.js.map +1 -1
- package/dist/table/cells.d.ts +13 -2
- package/dist/table/cells.js +14 -1
- package/dist/table/cells.js.map +1 -1
- package/dist/table/states.d.ts +6 -0
- package/dist/table/states.js +14 -1
- package/dist/table/states.js.map +1 -1
- package/dist/tree/TreeNode.js +1 -1
- package/dist/tree/TreeRenderer.js +1 -1
- package/dist/udc/client.d.ts +15 -1
- package/dist/udc/client.js +31 -10
- package/dist/udc/client.js.map +1 -1
- package/dist/udc/hooks.d.ts +8 -3
- package/dist/udc/provider.d.ts +5 -2
- package/dist/udc/provider.js +6 -1
- package/dist/udc/provider.js.map +1 -1
- package/dist/ui-kit/ui.d.ts +1 -0
- package/dist/ui.js +2 -1
- package/dist/url-state/adapters.d.ts +23 -0
- package/dist/url-state/adapters.js +57 -0
- package/dist/url-state/adapters.js.map +1 -0
- package/dist/url-state/index.d.ts +1 -0
- package/package.json +6 -4
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
// src/rows/useRowActivation.ts
|
|
3
|
+
/** Is activation on: any of the three props passed? */
|
|
4
|
+
function rowActivationEnabled(p) {
|
|
5
|
+
return p.onRowActivate !== void 0 || p.activeRowId !== void 0 || p.onActiveRowChange !== void 0;
|
|
6
|
+
}
|
|
7
|
+
/** Elements whose keys belong to them: an input, a cell editor, a menu, a dialog, a list box. */
|
|
8
|
+
var OWNS_KEYS = "input,textarea,select,[contenteditable=\"\"],[contenteditable=\"true\"],[role=\"menu\"],[role=\"menubar\"],[role=\"dialog\"],[role=\"alertdialog\"],[role=\"listbox\"],[role=\"combobox\"],[role=\"textbox\"],[data-cell-editor]";
|
|
9
|
+
/** Where a click is the control's, not the row's. */
|
|
10
|
+
var OWNS_CLICK = `a,button,label,${OWNS_KEYS}`;
|
|
11
|
+
function closestOf(target, selector) {
|
|
12
|
+
const el = target;
|
|
13
|
+
return el && typeof el.closest === "function" ? el.closest(selector) : null;
|
|
14
|
+
}
|
|
15
|
+
/** Is `target` inside `container` (a key or click from a portal bubbles through React too)? */
|
|
16
|
+
function within(container, target) {
|
|
17
|
+
const node = target;
|
|
18
|
+
return !!node && typeof node.nodeType === "number" && container.contains(node);
|
|
19
|
+
}
|
|
20
|
+
/** Does a key pressed on `target` belong to it rather than to the list? */
|
|
21
|
+
function ownsKeys(target) {
|
|
22
|
+
if (target?.isContentEditable === true) return true;
|
|
23
|
+
return closestOf(target, OWNS_KEYS) !== null;
|
|
24
|
+
}
|
|
25
|
+
var idOf = (r) => r.__meta.id;
|
|
26
|
+
/**
|
|
27
|
+
* The active row of a list and the keys that move it. Spread `rowProps(row)`
|
|
28
|
+
* on each row's element, call `handleClick` from its `onClick`, and give the
|
|
29
|
+
* list `role="grid"` (rows `role="row"`) while `enabled`.
|
|
30
|
+
*/
|
|
31
|
+
function useRowActivation(options) {
|
|
32
|
+
const { rows, activeRowId: controlledId, onRowActivate, onActiveRowChange } = options;
|
|
33
|
+
const enabled = options.enabled ?? rowActivationEnabled(options);
|
|
34
|
+
const controlled = controlledId !== void 0;
|
|
35
|
+
const [ownId, setOwnId] = useState(null);
|
|
36
|
+
const [focusId, setFocusId] = useState(null);
|
|
37
|
+
const rawId = controlled ? controlledId : ownId;
|
|
38
|
+
const has = (id) => id !== null && rows.some((r) => idOf(r) === id);
|
|
39
|
+
const activeRowId = enabled && has(rawId) ? rawId : null;
|
|
40
|
+
const tabStopId = !enabled ? null : activeRowId ?? (has(focusId) ? focusId : null) ?? (rows[0] ? idOf(rows[0]) : null);
|
|
41
|
+
const latest = useRef({
|
|
42
|
+
rows,
|
|
43
|
+
activeRowId,
|
|
44
|
+
onRowActivate,
|
|
45
|
+
onActiveRowChange,
|
|
46
|
+
controlled
|
|
47
|
+
});
|
|
48
|
+
latest.current = {
|
|
49
|
+
rows,
|
|
50
|
+
activeRowId,
|
|
51
|
+
onRowActivate,
|
|
52
|
+
onActiveRowChange,
|
|
53
|
+
controlled
|
|
54
|
+
};
|
|
55
|
+
const paging = useRef(options);
|
|
56
|
+
paging.current = options;
|
|
57
|
+
const elements = useRef(/* @__PURE__ */ new Map());
|
|
58
|
+
const refs = useRef(/* @__PURE__ */ new Map());
|
|
59
|
+
const refFor = (id) => {
|
|
60
|
+
let cb = refs.current.get(id);
|
|
61
|
+
if (!cb) {
|
|
62
|
+
cb = (el) => {
|
|
63
|
+
if (el) elements.current.set(id, el);
|
|
64
|
+
else elements.current.delete(id);
|
|
65
|
+
};
|
|
66
|
+
refs.current.set(id, cb);
|
|
67
|
+
}
|
|
68
|
+
return cb;
|
|
69
|
+
};
|
|
70
|
+
/** The row id that had focus while the list had it; kept across a refetch that unmounts rows. */
|
|
71
|
+
const focusedRef = useRef(null);
|
|
72
|
+
/** Infinite mode: the last row when ArrowDown asked for the next page; moves past it on arrival. */
|
|
73
|
+
const pendingRef = useRef(null);
|
|
74
|
+
const focusRow = useCallback((id) => {
|
|
75
|
+
const el = elements.current.get(id);
|
|
76
|
+
if (!el) return;
|
|
77
|
+
el.focus({ preventScroll: true });
|
|
78
|
+
if (typeof el.scrollIntoView === "function") el.scrollIntoView({ block: "nearest" });
|
|
79
|
+
}, []);
|
|
80
|
+
const changeActive = useCallback((row) => {
|
|
81
|
+
const now = latest.current;
|
|
82
|
+
if (now.activeRowId === idOf(row)) return;
|
|
83
|
+
if (!now.controlled) setOwnId(idOf(row));
|
|
84
|
+
now.onActiveRowChange?.(row);
|
|
85
|
+
}, []);
|
|
86
|
+
const go = useCallback((row) => {
|
|
87
|
+
setFocusId(idOf(row));
|
|
88
|
+
focusedRef.current = idOf(row);
|
|
89
|
+
changeActive(row);
|
|
90
|
+
focusRow(idOf(row));
|
|
91
|
+
}, [changeActive, focusRow]);
|
|
92
|
+
const activate = useCallback((row) => {
|
|
93
|
+
changeActive(row);
|
|
94
|
+
latest.current.onRowActivate?.(row);
|
|
95
|
+
}, [changeActive]);
|
|
96
|
+
const step = useCallback((from, to) => {
|
|
97
|
+
const list = latest.current.rows;
|
|
98
|
+
if (list.length === 0) return;
|
|
99
|
+
if (to === "first") return go(list[0]);
|
|
100
|
+
const last = list.length - 1;
|
|
101
|
+
if (to === "last") return go(list[last]);
|
|
102
|
+
const i = from === null ? -1 : list.findIndex((r) => idOf(r) === from);
|
|
103
|
+
if (i < 0) return go(list[0]);
|
|
104
|
+
const next = to === "next" ? i + 1 : i - 1;
|
|
105
|
+
if (next < 0) return;
|
|
106
|
+
if (next > last) {
|
|
107
|
+
const { hasNextPage, isFetchingNextPage, fetchNextPage } = paging.current;
|
|
108
|
+
if (hasNextPage && fetchNextPage) {
|
|
109
|
+
pendingRef.current = idOf(list[last]);
|
|
110
|
+
if (!isFetchingNextPage) fetchNextPage();
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
go(list[next]);
|
|
115
|
+
}, [go]);
|
|
116
|
+
const move = useCallback((to) => {
|
|
117
|
+
const now = latest.current;
|
|
118
|
+
step(now.activeRowId ?? focusedRef.current, to);
|
|
119
|
+
}, [step]);
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
const pending = pendingRef.current;
|
|
122
|
+
if (!enabled || pending === null) return;
|
|
123
|
+
const i = rows.findIndex((r) => idOf(r) === pending);
|
|
124
|
+
const next = i >= 0 ? rows[i + 1] : void 0;
|
|
125
|
+
if (next) {
|
|
126
|
+
pendingRef.current = null;
|
|
127
|
+
go(next);
|
|
128
|
+
} else if (i < 0 || !options.isFetchingNextPage && !options.hasNextPage) pendingRef.current = null;
|
|
129
|
+
}, [
|
|
130
|
+
enabled,
|
|
131
|
+
rows,
|
|
132
|
+
go,
|
|
133
|
+
options.isFetchingNextPage,
|
|
134
|
+
options.hasNextPage
|
|
135
|
+
]);
|
|
136
|
+
useLayoutEffect(() => {
|
|
137
|
+
const id = focusedRef.current;
|
|
138
|
+
if (!enabled || id === null) return;
|
|
139
|
+
const el = elements.current.get(id);
|
|
140
|
+
if (!el) return;
|
|
141
|
+
const active = typeof document === "undefined" ? null : document.activeElement;
|
|
142
|
+
if (active === el) return;
|
|
143
|
+
if (active === null || active === document.body) el.focus({ preventScroll: true });
|
|
144
|
+
}, [enabled, rows]);
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (activeRowId === null) return;
|
|
147
|
+
const el = elements.current.get(activeRowId);
|
|
148
|
+
if (el && typeof el.scrollIntoView === "function") el.scrollIntoView({ block: "nearest" });
|
|
149
|
+
}, [activeRowId]);
|
|
150
|
+
const onKeyDown = (e, row) => {
|
|
151
|
+
if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;
|
|
152
|
+
if (!within(e.currentTarget, e.target)) return;
|
|
153
|
+
if (ownsKeys(e.target)) return;
|
|
154
|
+
const id = idOf(row);
|
|
155
|
+
switch (e.key) {
|
|
156
|
+
case "ArrowDown":
|
|
157
|
+
case "j":
|
|
158
|
+
step(id, "next");
|
|
159
|
+
break;
|
|
160
|
+
case "ArrowUp":
|
|
161
|
+
case "k":
|
|
162
|
+
step(id, "previous");
|
|
163
|
+
break;
|
|
164
|
+
case "Home":
|
|
165
|
+
step(id, "first");
|
|
166
|
+
break;
|
|
167
|
+
case "End":
|
|
168
|
+
step(id, "last");
|
|
169
|
+
break;
|
|
170
|
+
case "Enter":
|
|
171
|
+
if (closestOf(e.target, "a,button") !== null && e.target !== e.currentTarget) return;
|
|
172
|
+
activate(row);
|
|
173
|
+
break;
|
|
174
|
+
default: return;
|
|
175
|
+
}
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
};
|
|
178
|
+
const handleClick = (e, row) => {
|
|
179
|
+
if (!enabled || e.defaultPrevented) return false;
|
|
180
|
+
if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return false;
|
|
181
|
+
if (!within(e.currentTarget, e.target)) return false;
|
|
182
|
+
if (closestOf(e.target, OWNS_CLICK)) return false;
|
|
183
|
+
const id = idOf(row);
|
|
184
|
+
setFocusId(id);
|
|
185
|
+
const focusable = closestOf(e.target, "[tabindex]");
|
|
186
|
+
if (!focusable || focusable === e.currentTarget) {
|
|
187
|
+
focusedRef.current = id;
|
|
188
|
+
elements.current.get(id)?.focus({ preventScroll: true });
|
|
189
|
+
}
|
|
190
|
+
activate(row);
|
|
191
|
+
return true;
|
|
192
|
+
};
|
|
193
|
+
const rowProps = (row) => {
|
|
194
|
+
if (!enabled) return {};
|
|
195
|
+
const id = idOf(row);
|
|
196
|
+
return {
|
|
197
|
+
ref: refFor(id),
|
|
198
|
+
tabIndex: id === tabStopId ? 0 : -1,
|
|
199
|
+
"aria-selected": id === activeRowId,
|
|
200
|
+
"data-active": id === activeRowId ? "true" : void 0,
|
|
201
|
+
onKeyDown: (e) => onKeyDown(e, row),
|
|
202
|
+
onFocus: (e) => {
|
|
203
|
+
if (e.target !== e.currentTarget) return;
|
|
204
|
+
focusedRef.current = id;
|
|
205
|
+
setFocusId(id);
|
|
206
|
+
},
|
|
207
|
+
onBlur: (e) => {
|
|
208
|
+
const list = e.currentTarget.parentElement;
|
|
209
|
+
if (!list || !within(list, e.relatedTarget)) focusedRef.current = null;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
return {
|
|
214
|
+
enabled,
|
|
215
|
+
activeRowId,
|
|
216
|
+
tabStopId,
|
|
217
|
+
rowProps,
|
|
218
|
+
handleClick,
|
|
219
|
+
activate,
|
|
220
|
+
move
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
export { ownsKeys, rowActivationEnabled, useRowActivation };
|
|
224
|
+
|
|
225
|
+
//# sourceMappingURL=useRowActivation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRowActivation.js","names":[],"sources":["../../src/rows/useRowActivation.ts"],"sourcesContent":["// Row activation and keyboard movement over a list of rows: the active row, a roving tab\n// stop, ArrowUp / ArrowDown / j / k / Home / End / Enter, and a click that activates. The\n// table and the cards use it; a host renderer gets the same behaviour from\n// `@jsudc/react/headless`. No JSX.\nimport type { Row } from \"@jsudc/core\";\nimport {\n type FocusEvent,\n type KeyboardEvent,\n type MouseEvent,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\n\n/**\n * The activation props of `UdcDataView` and of `RendererProps`. All optional;\n * with none of them a list behaves as before 0.4.0 (no tab stop on the rows,\n * no keys, no active row).\n */\nexport interface RowActivationProps {\n /** A row was activated: Enter on it, or a plain click (no modifier, the main button). */\n onRowActivate?: ((row: Row) => void) | undefined;\n /**\n * The row drawn as active (`aria-selected=\"true\"`, `data-active`, the\n * `--selected` background). Passed: controlled, the host moves it in\n * `onActiveRowChange`; `null` is \"none\". Left out: the list keeps it itself.\n */\n activeRowId?: string | null | undefined;\n /**\n * The active row changed by the user: moved by the keys (without Enter) or a\n * click on another row (before `onRowActivate`). Preview on move here.\n */\n onActiveRowChange?: ((row: Row | null) => void) | undefined;\n}\n\n/** Is activation on: any of the three props passed? */\nexport function rowActivationEnabled(p: RowActivationProps): boolean {\n return (\n p.onRowActivate !== undefined ||\n p.activeRowId !== undefined ||\n p.onActiveRowChange !== undefined\n );\n}\n\nexport interface UseRowActivationOptions extends RowActivationProps {\n /** The loaded rows, in the order they are drawn. */\n rows: readonly Row[];\n /** Infinite mode: moving past the last loaded row asks for the next page. */\n hasNextPage?: boolean | undefined;\n isFetchingNextPage?: boolean | undefined;\n fetchNextPage?: (() => unknown) | undefined;\n /** Override the default, `rowActivationEnabled(options)`. */\n enabled?: boolean | undefined;\n}\n\n/** What to spread on the element of one row (a `<tr>`, a card, an `<li>`). */\nexport interface RowActivationRowProps {\n ref: (el: HTMLElement | null) => void;\n /** One tab stop for the list: the active row, else the last focused one, else the first. */\n tabIndex: 0 | -1;\n \"aria-selected\": boolean;\n /** `\"true\"` on the active row: a stable hook for CSS (`.udc-row[data-active]`). */\n \"data-active\": \"true\" | undefined;\n onKeyDown: (e: KeyboardEvent<HTMLElement>) => void;\n onFocus: (e: FocusEvent<HTMLElement>) => void;\n onBlur: (e: FocusEvent<HTMLElement>) => void;\n}\n\nexport interface RowActivation {\n /** Off: `rowProps` is `{}` and the handlers do nothing. */\n enabled: boolean;\n /** The active row's id when it is among `rows`, else `null`. */\n activeRowId: string | null;\n /** The row holding the list's tab stop. */\n tabStopId: string | null;\n /** The props of one row's element (`{}` when off). */\n rowProps: (row: Row) => RowActivationRowProps | Record<string, never>;\n /**\n * A click on the row: a plain click activates it (and focuses it, unless the\n * click went to a focusable cell). A modified or non-main-button click, or one\n * on a link, button, input or menu, is left alone. `true` when it activated.\n */\n handleClick: (e: MouseEvent<HTMLElement>, row: Row) => boolean;\n /** Activate `row` as Enter does: make it active, then `onRowActivate`. */\n activate: (row: Row) => void;\n /** Move the active row, as the keys do, and focus it. */\n move: (to: \"next\" | \"previous\" | \"first\" | \"last\") => void;\n}\n\n/** Elements whose keys belong to them: an input, a cell editor, a menu, a dialog, a list box. */\nconst OWNS_KEYS =\n 'input,textarea,select,[contenteditable=\"\"],[contenteditable=\"true\"],[role=\"menu\"],[role=\"menubar\"],[role=\"dialog\"],[role=\"alertdialog\"],[role=\"listbox\"],[role=\"combobox\"],[role=\"textbox\"],[data-cell-editor]';\n/** Where a click is the control's, not the row's. */\nconst OWNS_CLICK = `a,button,label,${OWNS_KEYS}`;\n\n// Duck-typed, so an element of another realm (an iframe) counts too.\nfunction closestOf(target: EventTarget | null, selector: string): Element | null {\n const el = target as Element | null;\n return el && typeof el.closest === \"function\" ? el.closest(selector) : null;\n}\n\n/** Is `target` inside `container` (a key or click from a portal bubbles through React too)? */\nfunction within(container: HTMLElement, target: EventTarget | null): boolean {\n const node = target as Node | null;\n return !!node && typeof node.nodeType === \"number\" && container.contains(node);\n}\n\n/** Does a key pressed on `target` belong to it rather than to the list? */\nexport function ownsKeys(target: EventTarget | null): boolean {\n if ((target as HTMLElement | null)?.isContentEditable === true) return true;\n return closestOf(target, OWNS_KEYS) !== null;\n}\n\nconst idOf = (r: Row) => r.__meta.id;\n\n/**\n * The active row of a list and the keys that move it. Spread `rowProps(row)`\n * on each row's element, call `handleClick` from its `onClick`, and give the\n * list `role=\"grid\"` (rows `role=\"row\"`) while `enabled`.\n */\nexport function useRowActivation(options: UseRowActivationOptions): RowActivation {\n const { rows, activeRowId: controlledId, onRowActivate, onActiveRowChange } = options;\n const enabled = options.enabled ?? rowActivationEnabled(options);\n const controlled = controlledId !== undefined;\n const [ownId, setOwnId] = useState<string | null>(null);\n const [focusId, setFocusId] = useState<string | null>(null);\n const rawId = controlled ? controlledId : ownId;\n const has = (id: string | null): id is string => id !== null && rows.some((r) => idOf(r) === id);\n const activeRowId = enabled && has(rawId) ? rawId : null;\n const tabStopId = !enabled\n ? null\n : (activeRowId ?? (has(focusId) ? focusId : null) ?? (rows[0] ? idOf(rows[0]) : null));\n\n // The latest values, for handlers that outlive a render.\n const latest = useRef({ rows, activeRowId, onRowActivate, onActiveRowChange, controlled });\n latest.current = { rows, activeRowId, onRowActivate, onActiveRowChange, controlled };\n const paging = useRef(options);\n paging.current = options;\n\n // One stable ref callback per row id, so React does not detach and reattach each render.\n const elements = useRef(new Map<string, HTMLElement>());\n const refs = useRef(new Map<string, (el: HTMLElement | null) => void>());\n const refFor = (id: string) => {\n let cb = refs.current.get(id);\n if (!cb) {\n cb = (el) => {\n if (el) elements.current.set(id, el);\n else elements.current.delete(id);\n };\n refs.current.set(id, cb);\n }\n return cb;\n };\n\n /** The row id that had focus while the list had it; kept across a refetch that unmounts rows. */\n const focusedRef = useRef<string | null>(null);\n /** Infinite mode: the last row when ArrowDown asked for the next page; moves past it on arrival. */\n const pendingRef = useRef<string | null>(null);\n\n const focusRow = useCallback((id: string) => {\n const el = elements.current.get(id);\n if (!el) return;\n el.focus({ preventScroll: true });\n if (typeof el.scrollIntoView === \"function\") el.scrollIntoView({ block: \"nearest\" });\n }, []);\n\n const changeActive = useCallback((row: Row) => {\n const now = latest.current;\n if (now.activeRowId === idOf(row)) return;\n if (!now.controlled) setOwnId(idOf(row));\n now.onActiveRowChange?.(row);\n }, []);\n\n const go = useCallback(\n (row: Row) => {\n setFocusId(idOf(row));\n focusedRef.current = idOf(row);\n changeActive(row);\n focusRow(idOf(row));\n },\n [changeActive, focusRow],\n );\n\n const activate = useCallback(\n (row: Row) => {\n changeActive(row);\n latest.current.onRowActivate?.(row);\n },\n [changeActive],\n );\n\n const step = useCallback(\n (from: string | null, to: \"next\" | \"previous\" | \"first\" | \"last\") => {\n const list = latest.current.rows;\n if (list.length === 0) return;\n if (to === \"first\") return go(list[0] as Row);\n const last = list.length - 1;\n if (to === \"last\") return go(list[last] as Row);\n const i = from === null ? -1 : list.findIndex((r) => idOf(r) === from);\n if (i < 0) return go(list[0] as Row);\n const next = to === \"next\" ? i + 1 : i - 1;\n if (next < 0) return;\n if (next > last) {\n const { hasNextPage, isFetchingNextPage, fetchNextPage } = paging.current;\n if (hasNextPage && fetchNextPage) {\n pendingRef.current = idOf(list[last] as Row);\n if (!isFetchingNextPage) fetchNextPage();\n }\n return;\n }\n go(list[next] as Row);\n },\n [go],\n );\n\n const move = useCallback(\n (to: \"next\" | \"previous\" | \"first\" | \"last\") => {\n const now = latest.current;\n step(now.activeRowId ?? focusedRef.current, to);\n },\n [step],\n );\n\n // A page arrived after ArrowDown on the last row: continue onto its first row.\n useEffect(() => {\n const pending = pendingRef.current;\n if (!enabled || pending === null) return;\n const i = rows.findIndex((r) => idOf(r) === pending);\n const next = i >= 0 ? rows[i + 1] : undefined;\n if (next) {\n pendingRef.current = null;\n go(next);\n } else if (i < 0 || (!options.isFetchingNextPage && !options.hasNextPage)) {\n pendingRef.current = null;\n }\n }, [enabled, rows, go, options.isFetchingNextPage, options.hasNextPage]);\n\n // Rows unmounted under the focus (a refetch drawing skeletons, a sort): give it back by id.\n // biome-ignore lint/correctness/useExhaustiveDependencies: `rows` is the trigger, not an input\n useLayoutEffect(() => {\n const id = focusedRef.current;\n if (!enabled || id === null) return;\n const el = elements.current.get(id);\n if (!el) return;\n const active = typeof document === \"undefined\" ? null : document.activeElement;\n if (active === el) return;\n if (active === null || active === document.body) el.focus({ preventScroll: true });\n }, [enabled, rows]);\n\n // The active row set from outside (the host opened a message) is scrolled into view.\n useEffect(() => {\n if (activeRowId === null) return;\n const el = elements.current.get(activeRowId);\n if (el && typeof el.scrollIntoView === \"function\") el.scrollIntoView({ block: \"nearest\" });\n }, [activeRowId]);\n\n const onKeyDown = (e: KeyboardEvent<HTMLElement>, row: Row) => {\n if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;\n // A key from a portalled menu or dialog bubbles through React to here: not the list's.\n if (!within(e.currentTarget, e.target)) return;\n if (ownsKeys(e.target)) return;\n const id = idOf(row);\n switch (e.key) {\n case \"ArrowDown\":\n case \"j\":\n step(id, \"next\");\n break;\n case \"ArrowUp\":\n case \"k\":\n step(id, \"previous\");\n break;\n case \"Home\":\n step(id, \"first\");\n break;\n case \"End\":\n step(id, \"last\");\n break;\n case \"Enter\":\n // Enter on a link or a button in the row is that control's.\n if (closestOf(e.target, \"a,button\") !== null && e.target !== e.currentTarget) return;\n activate(row);\n break;\n default:\n return;\n }\n e.preventDefault();\n };\n\n const handleClick = (e: MouseEvent<HTMLElement>, row: Row): boolean => {\n if (!enabled || e.defaultPrevented) return false;\n if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return false;\n if (!within(e.currentTarget, e.target)) return false;\n if (closestOf(e.target, OWNS_CLICK)) return false;\n const id = idOf(row);\n setFocusId(id);\n // A click in a focusable cell (an editable one) keeps the focus there.\n const focusable = closestOf(e.target, \"[tabindex]\");\n if (!focusable || focusable === e.currentTarget) {\n focusedRef.current = id;\n elements.current.get(id)?.focus({ preventScroll: true });\n }\n activate(row);\n return true;\n };\n\n const rowProps = (row: Row): RowActivationRowProps | Record<string, never> => {\n if (!enabled) return {};\n const id = idOf(row);\n return {\n ref: refFor(id),\n tabIndex: id === tabStopId ? 0 : -1,\n \"aria-selected\": id === activeRowId,\n \"data-active\": id === activeRowId ? \"true\" : undefined,\n onKeyDown: (e) => onKeyDown(e, row),\n onFocus: (e) => {\n if (e.target !== e.currentTarget) return;\n focusedRef.current = id;\n setFocusId(id);\n },\n onBlur: (e) => {\n // Focus left the list (not to another row or a cell of it): forget it.\n const list = e.currentTarget.parentElement;\n if (!list || !within(list, e.relatedTarget)) focusedRef.current = null;\n },\n };\n };\n\n return { enabled, activeRowId, tabStopId, rowProps, handleClick, activate, move };\n}\n"],"mappings":";;;AAsCA,SAAgB,qBAAqB,GAAgC;CACnE,OACE,EAAE,kBAAkB,KAAA,KACpB,EAAE,gBAAgB,KAAA,KAClB,EAAE,sBAAsB,KAAA;AAE5B;;AAgDA,IAAM,YACJ;;AAEF,IAAM,aAAa,kBAAkB;AAGrC,SAAS,UAAU,QAA4B,UAAkC;CAC/E,MAAM,KAAK;CACX,OAAO,MAAM,OAAO,GAAG,YAAY,aAAa,GAAG,QAAQ,QAAQ,IAAI;AACzE;;AAGA,SAAS,OAAO,WAAwB,QAAqC;CAC3E,MAAM,OAAO;CACb,OAAO,CAAC,CAAC,QAAQ,OAAO,KAAK,aAAa,YAAY,UAAU,SAAS,IAAI;AAC/E;;A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L,KAAK,OAAO,EAAE;GACd,UAAU,OAAO,YAAY,IAAI;GACjC,iBAAiB,OAAO;GACxB,eAAe,OAAO,cAAc,SAAS,KAAA;GAC7C,YAAY,MAAM,UAAU,GAAG,GAAG;GAClC,UAAU,MAAM;IACd,IAAI,EAAE,WAAW,EAAE,eAAe;IAClC,WAAW,UAAU;IACrB,WAAW,EAAE;GACf;GACA,SAAS,MAAM;IAEb,MAAM,OAAO,EAAE,cAAc;IAC7B,IAAI,CAAC,QAAQ,CAAC,OAAO,MAAM,EAAE,aAAa,GAAG,WAAW,UAAU;GACpE;EACF;CACF;CAEA,OAAO;EAAE;EAAS;EAAa;EAAW;EAAU;EAAa;EAAU;CAAK;AAClF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useI18n } from "../i18n/i18n.js";
|
|
2
2
|
import { useUdcSchema } from "../udc/hooks.js";
|
|
3
3
|
import { useUiKit } from "../ui-kit/context.js";
|
|
4
|
-
import { AlertTriangle, Trash2 } from "lucide-react";
|
|
5
4
|
import { useState } from "react";
|
|
5
|
+
import { AlertTriangle, Trash2 } from "lucide-react";
|
|
6
6
|
import { isUdcError } from "@jsudc/core";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
// src/schema-editor/DeleteFieldDialog.tsx
|
|
@@ -4,8 +4,8 @@ import { useUdcSchema } from "../udc/hooks.js";
|
|
|
4
4
|
import { useUiKit } from "../ui-kit/context.js";
|
|
5
5
|
import { FORM_TYPES, draftFromDef, draftToFieldDef, emptyDraft, nameProblem, suggestName, typeControls, validateDraft } from "./fieldForm.js";
|
|
6
6
|
import { TagInput } from "./TagInput.js";
|
|
7
|
-
import { AlertTriangle, Lock } from "lucide-react";
|
|
8
7
|
import { useId, useState } from "react";
|
|
8
|
+
import { AlertTriangle, Lock } from "lucide-react";
|
|
9
9
|
import { isUdcError } from "@jsudc/core";
|
|
10
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
// src/schema-editor/FieldFormDialog.tsx
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cn } from "../lib/utils.js";
|
|
2
|
-
import { X } from "lucide-react";
|
|
3
2
|
import { useState } from "react";
|
|
3
|
+
import { X } from "lucide-react";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
// src/schema-editor/TagInput.tsx
|
|
6
6
|
/** A list of short strings: Enter or comma adds the typed one, Backspace on empty drops the last. */
|