@jsudc/react 0.4.0 → 0.5.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 +589 -11
- package/dist/actions/RowActionsMenu.d.ts +45 -0
- package/dist/actions/RowActionsMenu.js +161 -0
- package/dist/actions/RowActionsMenu.js.map +1 -0
- package/dist/actions/bulk.d.ts +81 -0
- package/dist/actions/bulk.js +54 -0
- package/dist/actions/bulk.js.map +1 -0
- package/dist/actions/row.d.ts +50 -0
- package/dist/actions/row.js +34 -0
- package/dist/actions/row.js.map +1 -0
- package/dist/actions/useRowActionRunner.d.ts +26 -0
- package/dist/actions/useRowActionRunner.js +198 -0
- package/dist/actions/useRowActionRunner.js.map +1 -0
- package/dist/calendar/CalendarRenderer.js +4 -3
- package/dist/calendar/CalendarRenderer.js.map +1 -1
- package/dist/cards/CardRenderer.d.ts +6 -0
- package/dist/cards/CardRenderer.js +42 -7
- package/dist/cards/CardRenderer.js.map +1 -1
- package/dist/chart/ChartRenderer.js +6 -4
- package/dist/chart/ChartRenderer.js.map +1 -1
- package/dist/chart/ChartWindowControl.js +1 -1
- package/dist/data-view/BulkBar.d.ts +36 -0
- package/dist/data-view/BulkBar.js +239 -0
- package/dist/data-view/BulkBar.js.map +1 -0
- package/dist/data-view/FilePreview.js +1 -1
- package/dist/data-view/FilterBuilder.js +1 -1
- package/dist/data-view/FilterChips.js +1 -1
- package/dist/data-view/LiveIndicator.d.ts +10 -0
- package/dist/data-view/LiveIndicator.js +33 -0
- package/dist/data-view/LiveIndicator.js.map +1 -0
- package/dist/data-view/UdcDataView.d.ts +28 -1
- package/dist/data-view/UdcDataView.js +69 -8
- package/dist/data-view/UdcDataView.js.map +1 -1
- package/dist/headless.d.ts +6 -0
- package/dist/headless.js +9 -2
- package/dist/i18n/translations.js +128 -0
- package/dist/i18n/translations.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +13 -4
- package/dist/kanban/KanbanCard.js +1 -1
- package/dist/kanban/KanbanRenderer.js +5 -4
- package/dist/kanban/KanbanRenderer.js.map +1 -1
- package/dist/lookup/batch.js +1 -1
- package/dist/lookup/options.js +4 -1
- package/dist/lookup/options.js.map +1 -1
- package/dist/lookup/useUdcLookup.js +9 -3
- package/dist/lookup/useUdcLookup.js.map +1 -1
- package/dist/map/MapRenderer.js +3 -2
- package/dist/map/MapRenderer.js.map +1 -1
- package/dist/renderers/types.d.ts +32 -1
- package/dist/renderers/types.js.map +1 -1
- package/dist/rows/useRowActivation.d.ts +17 -0
- package/dist/rows/useRowActivation.js +37 -5
- package/dist/rows/useRowActivation.js.map +1 -1
- package/dist/rows/useRowSelection.d.ts +92 -0
- package/dist/rows/useRowSelection.js +156 -0
- package/dist/rows/useRowSelection.js.map +1 -0
- package/dist/schema-editor/DeleteFieldDialog.js +1 -1
- package/dist/schema-editor/FieldFormDialog.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.scoped.css +1 -1
- package/dist/table/CellEditor.js +1 -1
- package/dist/table/SelectCheckbox.d.ts +15 -0
- package/dist/table/SelectCheckbox.js +37 -0
- package/dist/table/SelectCheckbox.js.map +1 -0
- package/dist/table/TableRenderer.d.ts +13 -0
- package/dist/table/TableRenderer.js +281 -123
- package/dist/table/TableRenderer.js.map +1 -1
- package/dist/table/cells.js +1 -1
- package/dist/table/index.d.ts +1 -0
- package/dist/table/states.js +1 -1
- package/dist/table/useRowWindow.d.ts +82 -0
- package/dist/table/useRowWindow.js +182 -0
- package/dist/table/useRowWindow.js.map +1 -0
- package/dist/table.js.map +1 -1
- package/dist/tree/TreeRenderer.d.ts +2 -0
- package/dist/tree/TreeRenderer.js +15 -9
- package/dist/tree/TreeRenderer.js.map +1 -1
- package/dist/udc/changeFeed.d.ts +94 -0
- package/dist/udc/changeFeed.js +250 -0
- package/dist/udc/changeFeed.js.map +1 -0
- package/dist/udc/changes.d.ts +34 -0
- package/dist/udc/changes.js +79 -0
- package/dist/udc/changes.js.map +1 -0
- package/dist/udc/client.js +5 -2
- package/dist/udc/client.js.map +1 -1
- package/dist/udc/hooks.d.ts +93 -20
- package/dist/udc/hooks.js +113 -10
- package/dist/udc/hooks.js.map +1 -1
- package/dist/udc/keys.d.ts +2 -0
- package/dist/udc/keys.js.map +1 -1
- package/dist/udc/listCache.d.ts +11 -0
- package/dist/udc/listCache.js +38 -0
- package/dist/udc/listCache.js.map +1 -0
- package/dist/udc/provider.d.ts +17 -2
- package/dist/udc/provider.js +18 -2
- package/dist/udc/provider.js.map +1 -1
- package/dist/udc/unauthenticated.d.ts +4 -0
- package/dist/udc/unauthenticated.js +17 -0
- package/dist/udc/unauthenticated.js.map +1 -0
- package/dist/ui-kit/types.d.ts +14 -0
- package/package.json +3 -3
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Row } from "@jsudc/core";
|
|
2
|
+
/**
|
|
3
|
+
* What is selected. `ids`: exactly these rows. `matching`: every row the
|
|
4
|
+
* list's filter matches, loaded or not, except `except`. `anchor` is the row a
|
|
5
|
+
* shift-range starts from (the last one toggled), `null` for none.
|
|
6
|
+
*/
|
|
7
|
+
export type RowSelectionState = {
|
|
8
|
+
mode: "ids";
|
|
9
|
+
ids: ReadonlySet<string>;
|
|
10
|
+
anchor: string | null;
|
|
11
|
+
} | {
|
|
12
|
+
mode: "matching";
|
|
13
|
+
except: ReadonlySet<string>;
|
|
14
|
+
anchor: string | null;
|
|
15
|
+
};
|
|
16
|
+
/** Nothing selected. */
|
|
17
|
+
export declare const EMPTY_SELECTION: RowSelectionState;
|
|
18
|
+
/** Is the row `id` selected? */
|
|
19
|
+
export declare function selectionHas(s: RowSelectionState, id: string): boolean;
|
|
20
|
+
/** Nothing selected: no id in id mode (matching mode always counts as something). */
|
|
21
|
+
export declare function selectionIsEmpty(s: RowSelectionState): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* How many rows are selected: the ids in id mode; in matching mode `total`
|
|
24
|
+
* minus the exceptions, or `null` when the list has no total (a source with
|
|
25
|
+
* `capabilities.total_count: false`).
|
|
26
|
+
*/
|
|
27
|
+
export declare function selectionCount(s: RowSelectionState, total: number | null): number | null;
|
|
28
|
+
/** Flip one row; it becomes the anchor of the next range. */
|
|
29
|
+
export declare function toggleSelection(s: RowSelectionState, id: string): RowSelectionState;
|
|
30
|
+
/**
|
|
31
|
+
* Shift-click on `id`: every row from the anchor to `id`, in the order of
|
|
32
|
+
* `rows` (the rows as loaded), takes the state the anchor has. Without an
|
|
33
|
+
* anchor among `rows` it is a plain toggle. The anchor stays where it was, so
|
|
34
|
+
* a second shift-click re-ranges from the same row.
|
|
35
|
+
*/
|
|
36
|
+
export declare function selectRange(s: RowSelectionState, rows: readonly Row[], id: string): RowSelectionState;
|
|
37
|
+
/** Every loaded row selected (`on`) or none of them. */
|
|
38
|
+
export declare function setPageSelection(s: RowSelectionState, rows: readonly Row[], on: boolean): RowSelectionState;
|
|
39
|
+
/** Every row that matches the list's filter, loaded or not. */
|
|
40
|
+
export declare function selectAllMatching(): RowSelectionState;
|
|
41
|
+
/** How much of the loaded rows is selected: `none`, `some` or `all` (no rows: `none`). */
|
|
42
|
+
export declare function pageSelectionState(s: RowSelectionState, rows: readonly Row[]): "none" | "some" | "all";
|
|
43
|
+
/**
|
|
44
|
+
* The live selection of one list: its state, what follows from it, and the
|
|
45
|
+
* operations. What `RendererProps.selection` carries.
|
|
46
|
+
*/
|
|
47
|
+
export interface RowSelection {
|
|
48
|
+
/** `ids`: the rows in `ids`. `matching`: every row of the filter except `exceptIds`. */
|
|
49
|
+
mode: "ids" | "matching";
|
|
50
|
+
/** The selected ids (id mode; empty in matching mode). */
|
|
51
|
+
ids: readonly string[];
|
|
52
|
+
/** The ids taken out of an "all that match" selection (matching mode; empty in id mode). */
|
|
53
|
+
exceptIds: readonly string[];
|
|
54
|
+
/** How many rows are selected; `null` in matching mode when the list has no total. */
|
|
55
|
+
count: number | null;
|
|
56
|
+
/** Nothing is selected. */
|
|
57
|
+
isEmpty: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* The selected rows the list has loaded, in id mode also those loaded
|
|
60
|
+
* earlier and no longer in the list (kept from when they were selected).
|
|
61
|
+
*/
|
|
62
|
+
rows: readonly Row[];
|
|
63
|
+
/** How much of the loaded rows is selected, for a header checkbox. */
|
|
64
|
+
pageState: "none" | "some" | "all";
|
|
65
|
+
isSelected: (id: string) => boolean;
|
|
66
|
+
/** Flip one row; with `range` (shift-click) select from the last toggled row to this one. */
|
|
67
|
+
toggle: (id: string, opts?: {
|
|
68
|
+
range?: boolean;
|
|
69
|
+
}) => void;
|
|
70
|
+
/** Select (`true`) or clear (`false`) every loaded row. */
|
|
71
|
+
setPage: (on: boolean) => void;
|
|
72
|
+
/** Select every row that matches the filter, loaded or not. */
|
|
73
|
+
selectAllMatching: () => void;
|
|
74
|
+
/** Keep exactly these ids selected (id mode). */
|
|
75
|
+
setIds: (ids: readonly string[]) => void;
|
|
76
|
+
/** Select nothing. */
|
|
77
|
+
clear: () => void;
|
|
78
|
+
}
|
|
79
|
+
export interface UseRowSelectionOptions {
|
|
80
|
+
/** The loaded rows, in the order they are drawn: what a range and "the page" cover. */
|
|
81
|
+
rows: readonly Row[];
|
|
82
|
+
/** The list's total; `null` when the source does not count. */
|
|
83
|
+
total: number | null;
|
|
84
|
+
/**
|
|
85
|
+
* Changes when the selection no longer applies: the collection or the
|
|
86
|
+
* filter (search, chips, the filter tree, the host's filter). A sort, a
|
|
87
|
+
* refetch or another page loading keep the key, and the selection.
|
|
88
|
+
*/
|
|
89
|
+
resetKey: string;
|
|
90
|
+
}
|
|
91
|
+
/** One list's selection, cleared whenever `resetKey` changes. */
|
|
92
|
+
export declare function useRowSelection({ rows, total, resetKey }: UseRowSelectionOptions): RowSelection;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { useCallback, useMemo, useRef, useState } from "react";
|
|
2
|
+
// src/rows/useRowSelection.ts
|
|
3
|
+
/** Nothing selected. */
|
|
4
|
+
var EMPTY_SELECTION = Object.freeze({
|
|
5
|
+
mode: "ids",
|
|
6
|
+
ids: /* @__PURE__ */ new Set(),
|
|
7
|
+
anchor: null
|
|
8
|
+
});
|
|
9
|
+
var idOf = (r) => r.__meta.id;
|
|
10
|
+
/** Is the row `id` selected? */
|
|
11
|
+
function selectionHas(s, id) {
|
|
12
|
+
return s.mode === "ids" ? s.ids.has(id) : !s.except.has(id);
|
|
13
|
+
}
|
|
14
|
+
/** Nothing selected: no id in id mode (matching mode always counts as something). */
|
|
15
|
+
function selectionIsEmpty(s) {
|
|
16
|
+
return s.mode === "ids" && s.ids.size === 0;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* How many rows are selected: the ids in id mode; in matching mode `total`
|
|
20
|
+
* minus the exceptions, or `null` when the list has no total (a source with
|
|
21
|
+
* `capabilities.total_count: false`).
|
|
22
|
+
*/
|
|
23
|
+
function selectionCount(s, total) {
|
|
24
|
+
if (s.mode === "ids") return s.ids.size;
|
|
25
|
+
return total === null ? null : Math.max(0, total - s.except.size);
|
|
26
|
+
}
|
|
27
|
+
/** Set (`on`) or unset each of `ids`, keeping the mode. */
|
|
28
|
+
function setMany(s, ids, on, anchor) {
|
|
29
|
+
if (s.mode === "ids") {
|
|
30
|
+
const next = new Set(s.ids);
|
|
31
|
+
for (const id of ids) on ? next.add(id) : next.delete(id);
|
|
32
|
+
return {
|
|
33
|
+
mode: "ids",
|
|
34
|
+
ids: next,
|
|
35
|
+
anchor
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const except = new Set(s.except);
|
|
39
|
+
for (const id of ids) on ? except.delete(id) : except.add(id);
|
|
40
|
+
return {
|
|
41
|
+
mode: "matching",
|
|
42
|
+
except,
|
|
43
|
+
anchor
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Flip one row; it becomes the anchor of the next range. */
|
|
47
|
+
function toggleSelection(s, id) {
|
|
48
|
+
return setMany(s, [id], !selectionHas(s, id), id);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Shift-click on `id`: every row from the anchor to `id`, in the order of
|
|
52
|
+
* `rows` (the rows as loaded), takes the state the anchor has. Without an
|
|
53
|
+
* anchor among `rows` it is a plain toggle. The anchor stays where it was, so
|
|
54
|
+
* a second shift-click re-ranges from the same row.
|
|
55
|
+
*/
|
|
56
|
+
function selectRange(s, rows, id) {
|
|
57
|
+
const from = s.anchor === null ? -1 : rows.findIndex((r) => idOf(r) === s.anchor);
|
|
58
|
+
const to = rows.findIndex((r) => idOf(r) === id);
|
|
59
|
+
if (from < 0 || to < 0) return toggleSelection(s, id);
|
|
60
|
+
const [lo, hi] = from <= to ? [from, to] : [to, from];
|
|
61
|
+
return setMany(s, rows.slice(lo, hi + 1).map(idOf), selectionHas(s, s.anchor), s.anchor);
|
|
62
|
+
}
|
|
63
|
+
/** Every loaded row selected (`on`) or none of them. */
|
|
64
|
+
function setPageSelection(s, rows, on) {
|
|
65
|
+
return setMany(s, rows.map(idOf), on, s.anchor);
|
|
66
|
+
}
|
|
67
|
+
/** Every row that matches the list's filter, loaded or not. */
|
|
68
|
+
function selectAllMatching() {
|
|
69
|
+
return {
|
|
70
|
+
mode: "matching",
|
|
71
|
+
except: /* @__PURE__ */ new Set(),
|
|
72
|
+
anchor: null
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** How much of the loaded rows is selected: `none`, `some` or `all` (no rows: `none`). */
|
|
76
|
+
function pageSelectionState(s, rows) {
|
|
77
|
+
let on = 0;
|
|
78
|
+
for (const r of rows) if (selectionHas(s, idOf(r))) on++;
|
|
79
|
+
if (on === 0) return "none";
|
|
80
|
+
return on === rows.length ? "all" : "some";
|
|
81
|
+
}
|
|
82
|
+
/** One list's selection, cleared whenever `resetKey` changes. */
|
|
83
|
+
function useRowSelection({ rows, total, resetKey }) {
|
|
84
|
+
const [held, setHeld] = useState({
|
|
85
|
+
key: resetKey,
|
|
86
|
+
state: EMPTY_SELECTION
|
|
87
|
+
});
|
|
88
|
+
const state = held.key === resetKey ? held.state : EMPTY_SELECTION;
|
|
89
|
+
const latest = useRef({
|
|
90
|
+
rows,
|
|
91
|
+
resetKey
|
|
92
|
+
});
|
|
93
|
+
latest.current = {
|
|
94
|
+
rows,
|
|
95
|
+
resetKey
|
|
96
|
+
};
|
|
97
|
+
const known = useRef(/* @__PURE__ */ new Map());
|
|
98
|
+
for (const r of rows) if (known.current.has(idOf(r))) known.current.set(idOf(r), r);
|
|
99
|
+
const update = useCallback((f) => {
|
|
100
|
+
const { rows: now, resetKey: key } = latest.current;
|
|
101
|
+
setHeld((h) => ({
|
|
102
|
+
key,
|
|
103
|
+
state: f(h.key === key ? h.state : EMPTY_SELECTION, now)
|
|
104
|
+
}));
|
|
105
|
+
}, []);
|
|
106
|
+
const toggle = useCallback((id, opts) => update((s, now) => opts?.range ? selectRange(s, now, id) : toggleSelection(s, id)), [update]);
|
|
107
|
+
const setPage = useCallback((on) => update((s, now) => setPageSelection(s, now, on)), [update]);
|
|
108
|
+
const selectAll = useCallback(() => update(() => selectAllMatching()), [update]);
|
|
109
|
+
const setIds = useCallback((ids) => update(() => ({
|
|
110
|
+
mode: "ids",
|
|
111
|
+
ids: new Set(ids),
|
|
112
|
+
anchor: null
|
|
113
|
+
})), [update]);
|
|
114
|
+
const clear = useCallback(() => update(() => EMPTY_SELECTION), [update]);
|
|
115
|
+
return useMemo(() => {
|
|
116
|
+
const byId = new Map(rows.map((r) => [idOf(r), r]));
|
|
117
|
+
let selectedRows;
|
|
118
|
+
if (state.mode === "ids") {
|
|
119
|
+
selectedRows = [];
|
|
120
|
+
for (const id of state.ids) {
|
|
121
|
+
const r = byId.get(id) ?? known.current.get(id);
|
|
122
|
+
if (r) selectedRows.push(r);
|
|
123
|
+
}
|
|
124
|
+
} else selectedRows = rows.filter((r) => !state.except.has(idOf(r)));
|
|
125
|
+
const keep = /* @__PURE__ */ new Map();
|
|
126
|
+
for (const r of selectedRows) keep.set(idOf(r), r);
|
|
127
|
+
known.current = keep;
|
|
128
|
+
return {
|
|
129
|
+
mode: state.mode,
|
|
130
|
+
ids: state.mode === "ids" ? [...state.ids] : [],
|
|
131
|
+
exceptIds: state.mode === "matching" ? [...state.except] : [],
|
|
132
|
+
count: selectionCount(state, total),
|
|
133
|
+
isEmpty: selectionIsEmpty(state),
|
|
134
|
+
rows: selectedRows,
|
|
135
|
+
pageState: pageSelectionState(state, rows),
|
|
136
|
+
isSelected: (id) => selectionHas(state, id),
|
|
137
|
+
toggle,
|
|
138
|
+
setPage,
|
|
139
|
+
selectAllMatching: selectAll,
|
|
140
|
+
setIds,
|
|
141
|
+
clear
|
|
142
|
+
};
|
|
143
|
+
}, [
|
|
144
|
+
state,
|
|
145
|
+
rows,
|
|
146
|
+
total,
|
|
147
|
+
toggle,
|
|
148
|
+
setPage,
|
|
149
|
+
selectAll,
|
|
150
|
+
setIds,
|
|
151
|
+
clear
|
|
152
|
+
]);
|
|
153
|
+
}
|
|
154
|
+
export { EMPTY_SELECTION, pageSelectionState, selectAllMatching, selectRange, selectionCount, selectionHas, selectionIsEmpty, setPageSelection, toggleSelection, useRowSelection };
|
|
155
|
+
|
|
156
|
+
//# sourceMappingURL=useRowSelection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRowSelection.js","names":[],"sources":["../../src/rows/useRowSelection.ts"],"sourcesContent":["// Row selection over a list (0.5.0): a set of ids, or \"every row that matches this filter,\n// except these ids\". The model is plain data with pure operations (so a virtualised list,\n// which draws only some rows, ranges over the rows as loaded, not over the DOM), and\n// `useRowSelection` keeps one for a list, clearing it when the list's key (collection and\n// filter) changes. The data view uses it; a host renderer gets the same from\n// `@jsudc/react/headless` through `RendererProps.selection`. No JSX.\nimport type { Row } from \"@jsudc/core\";\nimport { useCallback, useMemo, useRef, useState } from \"react\";\n\n/**\n * What is selected. `ids`: exactly these rows. `matching`: every row the\n * list's filter matches, loaded or not, except `except`. `anchor` is the row a\n * shift-range starts from (the last one toggled), `null` for none.\n */\nexport type RowSelectionState =\n | { mode: \"ids\"; ids: ReadonlySet<string>; anchor: string | null }\n | { mode: \"matching\"; except: ReadonlySet<string>; anchor: string | null };\n\n/** Nothing selected. */\nexport const EMPTY_SELECTION: RowSelectionState = Object.freeze({\n mode: \"ids\",\n ids: new Set<string>(),\n anchor: null,\n}) as RowSelectionState;\n\nconst idOf = (r: Row) => r.__meta.id;\n\n/** Is the row `id` selected? */\nexport function selectionHas(s: RowSelectionState, id: string): boolean {\n return s.mode === \"ids\" ? s.ids.has(id) : !s.except.has(id);\n}\n\n/** Nothing selected: no id in id mode (matching mode always counts as something). */\nexport function selectionIsEmpty(s: RowSelectionState): boolean {\n return s.mode === \"ids\" && s.ids.size === 0;\n}\n\n/**\n * How many rows are selected: the ids in id mode; in matching mode `total`\n * minus the exceptions, or `null` when the list has no total (a source with\n * `capabilities.total_count: false`).\n */\nexport function selectionCount(s: RowSelectionState, total: number | null): number | null {\n if (s.mode === \"ids\") return s.ids.size;\n return total === null ? null : Math.max(0, total - s.except.size);\n}\n\n/** Set (`on`) or unset each of `ids`, keeping the mode. */\nfunction setMany(\n s: RowSelectionState,\n ids: readonly string[],\n on: boolean,\n anchor: string | null,\n): RowSelectionState {\n if (s.mode === \"ids\") {\n const next = new Set(s.ids);\n for (const id of ids) on ? next.add(id) : next.delete(id);\n return { mode: \"ids\", ids: next, anchor };\n }\n const except = new Set(s.except);\n for (const id of ids) on ? except.delete(id) : except.add(id);\n return { mode: \"matching\", except, anchor };\n}\n\n/** Flip one row; it becomes the anchor of the next range. */\nexport function toggleSelection(s: RowSelectionState, id: string): RowSelectionState {\n return setMany(s, [id], !selectionHas(s, id), id);\n}\n\n/**\n * Shift-click on `id`: every row from the anchor to `id`, in the order of\n * `rows` (the rows as loaded), takes the state the anchor has. Without an\n * anchor among `rows` it is a plain toggle. The anchor stays where it was, so\n * a second shift-click re-ranges from the same row.\n */\nexport function selectRange(\n s: RowSelectionState,\n rows: readonly Row[],\n id: string,\n): RowSelectionState {\n const from = s.anchor === null ? -1 : rows.findIndex((r) => idOf(r) === s.anchor);\n const to = rows.findIndex((r) => idOf(r) === id);\n if (from < 0 || to < 0) return toggleSelection(s, id);\n const [lo, hi] = from <= to ? [from, to] : [to, from];\n const ids = rows.slice(lo, hi + 1).map(idOf);\n return setMany(s, ids, selectionHas(s, s.anchor as string), s.anchor);\n}\n\n/** Every loaded row selected (`on`) or none of them. */\nexport function setPageSelection(\n s: RowSelectionState,\n rows: readonly Row[],\n on: boolean,\n): RowSelectionState {\n return setMany(s, rows.map(idOf), on, s.anchor);\n}\n\n/** Every row that matches the list's filter, loaded or not. */\nexport function selectAllMatching(): RowSelectionState {\n return { mode: \"matching\", except: new Set(), anchor: null };\n}\n\n/** How much of the loaded rows is selected: `none`, `some` or `all` (no rows: `none`). */\nexport function pageSelectionState(\n s: RowSelectionState,\n rows: readonly Row[],\n): \"none\" | \"some\" | \"all\" {\n let on = 0;\n for (const r of rows) if (selectionHas(s, idOf(r))) on++;\n if (on === 0) return \"none\";\n return on === rows.length ? \"all\" : \"some\";\n}\n\n/**\n * The live selection of one list: its state, what follows from it, and the\n * operations. What `RendererProps.selection` carries.\n */\nexport interface RowSelection {\n /** `ids`: the rows in `ids`. `matching`: every row of the filter except `exceptIds`. */\n mode: \"ids\" | \"matching\";\n /** The selected ids (id mode; empty in matching mode). */\n ids: readonly string[];\n /** The ids taken out of an \"all that match\" selection (matching mode; empty in id mode). */\n exceptIds: readonly string[];\n /** How many rows are selected; `null` in matching mode when the list has no total. */\n count: number | null;\n /** Nothing is selected. */\n isEmpty: boolean;\n /**\n * The selected rows the list has loaded, in id mode also those loaded\n * earlier and no longer in the list (kept from when they were selected).\n */\n rows: readonly Row[];\n /** How much of the loaded rows is selected, for a header checkbox. */\n pageState: \"none\" | \"some\" | \"all\";\n isSelected: (id: string) => boolean;\n /** Flip one row; with `range` (shift-click) select from the last toggled row to this one. */\n toggle: (id: string, opts?: { range?: boolean }) => void;\n /** Select (`true`) or clear (`false`) every loaded row. */\n setPage: (on: boolean) => void;\n /** Select every row that matches the filter, loaded or not. */\n selectAllMatching: () => void;\n /** Keep exactly these ids selected (id mode). */\n setIds: (ids: readonly string[]) => void;\n /** Select nothing. */\n clear: () => void;\n}\n\nexport interface UseRowSelectionOptions {\n /** The loaded rows, in the order they are drawn: what a range and \"the page\" cover. */\n rows: readonly Row[];\n /** The list's total; `null` when the source does not count. */\n total: number | null;\n /**\n * Changes when the selection no longer applies: the collection or the\n * filter (search, chips, the filter tree, the host's filter). A sort, a\n * refetch or another page loading keep the key, and the selection.\n */\n resetKey: string;\n}\n\n/** One list's selection, cleared whenever `resetKey` changes. */\nexport function useRowSelection({ rows, total, resetKey }: UseRowSelectionOptions): RowSelection {\n const [held, setHeld] = useState<{ key: string; state: RowSelectionState }>({\n key: resetKey,\n state: EMPTY_SELECTION,\n });\n // A new key reads as empty at once (no effect, no frame with a stale selection).\n const state = held.key === resetKey ? held.state : EMPTY_SELECTION;\n const latest = useRef({ rows, resetKey });\n latest.current = { rows, resetKey };\n // Rows selected while loaded, so `rows` still names them after a refetch drops them.\n const known = useRef(new Map<string, Row>());\n for (const r of rows) if (known.current.has(idOf(r))) known.current.set(idOf(r), r);\n\n const update = useCallback(\n (f: (s: RowSelectionState, rows: readonly Row[]) => RowSelectionState) => {\n const { rows: now, resetKey: key } = latest.current;\n setHeld((h) => ({ key, state: f(h.key === key ? h.state : EMPTY_SELECTION, now) }));\n },\n [],\n );\n\n const toggle = useCallback(\n (id: string, opts?: { range?: boolean }) =>\n update((s, now) => (opts?.range ? selectRange(s, now, id) : toggleSelection(s, id))),\n [update],\n );\n const setPage = useCallback(\n (on: boolean) => update((s, now) => setPageSelection(s, now, on)),\n [update],\n );\n const selectAll = useCallback(() => update(() => selectAllMatching()), [update]);\n const setIds = useCallback(\n (ids: readonly string[]) => update(() => ({ mode: \"ids\", ids: new Set(ids), anchor: null })),\n [update],\n );\n const clear = useCallback(() => update(() => EMPTY_SELECTION), [update]);\n\n return useMemo(() => {\n const byId = new Map(rows.map((r) => [idOf(r), r] as const));\n let selectedRows: Row[];\n if (state.mode === \"ids\") {\n selectedRows = [];\n for (const id of state.ids) {\n const r = byId.get(id) ?? known.current.get(id);\n if (r) selectedRows.push(r);\n }\n } else {\n selectedRows = rows.filter((r) => !state.except.has(idOf(r)));\n }\n // Remember what is selected now; forget what is not.\n const keep = new Map<string, Row>();\n for (const r of selectedRows) keep.set(idOf(r), r);\n known.current = keep;\n return {\n mode: state.mode,\n ids: state.mode === \"ids\" ? [...state.ids] : [],\n exceptIds: state.mode === \"matching\" ? [...state.except] : [],\n count: selectionCount(state, total),\n isEmpty: selectionIsEmpty(state),\n rows: selectedRows,\n pageState: pageSelectionState(state, rows),\n isSelected: (id: string) => selectionHas(state, id),\n toggle,\n setPage,\n selectAllMatching: selectAll,\n setIds,\n clear,\n };\n }, [state, rows, total, toggle, setPage, selectAll, setIds, clear]);\n}\n"],"mappings":";;;AAmBA,IAAa,kBAAqC,OAAO,OAAO;CAC9D,MAAM;CACN,qBAAK,IAAI,IAAY;CACrB,QAAQ;AACV,CAAC;AAED,IAAM,QAAQ,MAAW,EAAE,OAAO;;AAGlC,SAAgB,aAAa,GAAsB,IAAqB;CACtE,OAAO,EAAE,SAAS,QAAQ,EAAE,IAAI,IAAI,EAAE,IAAI,CAAC,EAAE,OAAO,IAAI,EAAE;AAC5D;;AAGA,SAAgB,iBAAiB,GAA+B;CAC9D,OAAO,EAAE,SAAS,SAAS,EAAE,IAAI,SAAS;AAC5C;;;;;;AAOA,SAAgB,eAAe,GAAsB,OAAqC;CACxF,IAAI,EAAE,SAAS,OAAO,OAAO,EAAE,IAAI;CACnC,OAAO,UAAU,OAAO,OAAO,KAAK,IAAI,GAAG,QAAQ,EAAE,OAAO,IAAI;AAClE;;AAGA,SAAS,QACP,GACA,KACA,IACA,QACmB;CACnB,IAAI,EAAE,SAAS,OAAO;EACpB,MAAM,OAAO,IAAI,IAAI,EAAE,GAAG;EAC1B,KAAK,MAAM,MAAM,KAAK,KAAK,KAAK,IAAI,EA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AAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAU,CAAC;EAC3D,IAAI;EACJ,IAAI,MAAM,SAAS,OAAO;GACxB,eAAe,CAAC;GAChB,KAAK,MAAM,MAAM,MAAM,KAAK;IAC1B,MAAM,IAAI,KAAK,IAAI,EAAE,KAAK,MAAM,QAAQ,IAAI,EAAE;IAC9C,IAAI,GAAG,aAAa,KAAK,CAAC;GAC5B;EACF,OACE,eAAe,KAAK,QAAQ,MAAM,CAAC,MAAM,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC;EAG9D,MAAM,uBAAO,IAAI,IAAiB;EAClC,KAAK,MAAM,KAAK,cAAc,KAAK,IAAI,KAAK,CAAC,GAAG,CAAC;EACjD,MAAM,UAAU;EAChB,OAAO;GACL,MAAM,MAAM;GACZ,KAAK,MAAM,SAAS,QAAQ,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC;GAC9C,WAAW,MAAM,SAAS,aAAa,CAAC,GAAG,MAAM,MAAM,IAAI,CAAC;GAC5D,OAAO,eAAe,OAAO,KAAK;GAClC,SAAS,iBAAiB,KAAK;GAC/B,MAAM;GACN,WAAW,mBAAmB,OAAO,IAAI;GACzC,aAAa,OAAe,aAAa,OAAO,EAAE;GAClD;GACA;GACA,mBAAmB;GACnB;GACA;EACF;CACF,GAAG;EAAC;EAAO;EAAM;EAAO;EAAQ;EAAS;EAAW;EAAQ;CAAK,CAAC;AACpE"}
|
|
@@ -1,9 +1,9 @@
|
|
|
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 { isUdcError } from "@jsudc/core";
|
|
4
5
|
import { useState } from "react";
|
|
5
6
|
import { AlertTriangle, Trash2 } from "lucide-react";
|
|
6
|
-
import { isUdcError } from "@jsudc/core";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
// src/schema-editor/DeleteFieldDialog.tsx
|
|
9
9
|
/** Confirms a soft delete: the column goes, the data stays. */
|
|
@@ -4,9 +4,9 @@ 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 { isUdcError } from "@jsudc/core";
|
|
7
8
|
import { useId, useState } from "react";
|
|
8
9
|
import { AlertTriangle, Lock } from "lucide-react";
|
|
9
|
-
import { isUdcError } from "@jsudc/core";
|
|
10
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
// src/schema-editor/FieldFormDialog.tsx
|
|
12
12
|
/**
|