@jsudc/react 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +555 -2
- package/dist/all.d.ts +9 -0
- package/dist/all.js +14 -0
- package/dist/all.js.map +1 -0
- package/dist/calendar/CalendarRenderer.d.ts +9 -0
- package/dist/calendar/CalendarRenderer.js +314 -0
- package/dist/calendar/CalendarRenderer.js.map +1 -0
- package/dist/calendar/EventBlock.d.ts +16 -0
- package/dist/calendar/EventBlock.js +57 -0
- package/dist/calendar/EventBlock.js.map +1 -0
- package/dist/calendar/EventDetail.d.ts +20 -0
- package/dist/calendar/EventDetail.js +186 -0
- package/dist/calendar/EventDetail.js.map +1 -0
- package/dist/calendar/MonthGrid.d.ts +19 -0
- package/dist/calendar/MonthGrid.js +121 -0
- package/dist/calendar/MonthGrid.js.map +1 -0
- package/dist/calendar/TimeGrid.d.ts +24 -0
- package/dist/calendar/TimeGrid.js +331 -0
- package/dist/calendar/TimeGrid.js.map +1 -0
- package/dist/calendar/index.d.ts +4 -0
- package/dist/calendar/model.d.ts +97 -0
- package/dist/calendar/model.js +279 -0
- package/dist/calendar/model.js.map +1 -0
- package/dist/calendar/useCalendarUrl.d.ts +13 -0
- package/dist/calendar/useCalendarUrl.js +35 -0
- package/dist/calendar/useCalendarUrl.js.map +1 -0
- package/dist/calendar.d.ts +1 -0
- package/dist/calendar.js +22 -0
- package/dist/calendar.js.map +1 -0
- package/dist/cards/CardRenderer.d.ts +24 -0
- package/dist/cards/CardRenderer.js +277 -0
- package/dist/cards/CardRenderer.js.map +1 -0
- package/dist/cards/cardModel.d.ts +48 -0
- package/dist/cards/cardModel.js +86 -0
- package/dist/cards/cardModel.js.map +1 -0
- package/dist/cards/index.d.ts +4 -0
- package/dist/cards.d.ts +1 -0
- package/dist/cards.js +15 -0
- package/dist/cards.js.map +1 -0
- package/dist/chart/ChartRenderer.d.ts +16 -0
- package/dist/chart/ChartRenderer.js +531 -0
- package/dist/chart/ChartRenderer.js.map +1 -0
- package/dist/chart/ChartWindowControl.d.ts +13 -0
- package/dist/chart/ChartWindowControl.js +103 -0
- package/dist/chart/ChartWindowControl.js.map +1 -0
- package/dist/chart/index.d.ts +7 -0
- package/dist/chart/model.d.ts +45 -0
- package/dist/chart/model.js +184 -0
- package/dist/chart/model.js.map +1 -0
- package/dist/chart/useChartWindow.d.ts +18 -0
- package/dist/chart/useChartWindow.js +70 -0
- package/dist/chart/useChartWindow.js.map +1 -0
- package/dist/chart/window.d.ts +50 -0
- package/dist/chart/window.js +133 -0
- package/dist/chart/window.js.map +1 -0
- package/dist/chart.d.ts +1 -0
- package/dist/chart.js +18 -0
- package/dist/chart.js.map +1 -0
- package/dist/components/ui/button.d.ts +21 -0
- package/dist/components/ui/button.js +30 -0
- package/dist/components/ui/button.js.map +1 -0
- package/dist/components/ui/checkbox.d.ts +2 -0
- package/dist/components/ui/checkbox.js +23 -0
- package/dist/components/ui/checkbox.js.map +1 -0
- package/dist/components/ui/dialog.d.ts +14 -0
- package/dist/components/ui/dialog.js +52 -0
- package/dist/components/ui/dialog.js.map +1 -0
- package/dist/components/ui/dropdown-menu.d.ts +12 -0
- package/dist/components/ui/dropdown-menu.js +35 -0
- package/dist/components/ui/dropdown-menu.js.map +1 -0
- package/dist/components/ui/input.d.ts +4 -0
- package/dist/components/ui/input.js +24 -0
- package/dist/components/ui/input.js.map +1 -0
- package/dist/components/ui/misc.d.ts +6 -0
- package/dist/components/ui/misc.js +24 -0
- package/dist/components/ui/misc.js.map +1 -0
- package/dist/components/ui/popover.d.ts +6 -0
- package/dist/components/ui/popover.js +21 -0
- package/dist/components/ui/popover.js.map +1 -0
- package/dist/components/ui/segmented.d.ts +11 -0
- package/dist/components/ui/segmented.js +35 -0
- package/dist/components/ui/segmented.js.map +1 -0
- package/dist/components/ui/select.d.ts +12 -0
- package/dist/components/ui/select.js +39 -0
- package/dist/components/ui/select.js.map +1 -0
- package/dist/components/ui/toast.d.ts +10 -0
- package/dist/components/ui/toast.js +72 -0
- package/dist/components/ui/toast.js.map +1 -0
- package/dist/components/ui/tooltip.d.ts +9 -0
- package/dist/components/ui/tooltip.js +19 -0
- package/dist/components/ui/tooltip.js.map +1 -0
- package/dist/data-view/DocTab.d.ts +8 -0
- package/dist/data-view/DocTab.js +26 -0
- package/dist/data-view/DocTab.js.map +1 -0
- package/dist/data-view/FilePreview.d.ts +10 -0
- package/dist/data-view/FilePreview.js +71 -0
- package/dist/data-view/FilePreview.js.map +1 -0
- package/dist/data-view/FilterBuilder.d.ts +26 -0
- package/dist/data-view/FilterBuilder.js +349 -0
- package/dist/data-view/FilterBuilder.js.map +1 -0
- package/dist/data-view/FilterChips.d.ts +12 -0
- package/dist/data-view/FilterChips.js +296 -0
- package/dist/data-view/FilterChips.js.map +1 -0
- package/dist/data-view/FolderBar.d.ts +5 -0
- package/dist/data-view/FolderBar.js +46 -0
- package/dist/data-view/FolderBar.js.map +1 -0
- package/dist/data-view/FolderEntry.d.ts +13 -0
- package/dist/data-view/FolderEntry.js +37 -0
- package/dist/data-view/FolderEntry.js.map +1 -0
- package/dist/data-view/Freshness.d.ts +18 -0
- package/dist/data-view/Freshness.js +87 -0
- package/dist/data-view/Freshness.js.map +1 -0
- package/dist/data-view/SearchBox.d.ts +7 -0
- package/dist/data-view/SearchBox.js +65 -0
- package/dist/data-view/SearchBox.js.map +1 -0
- package/dist/data-view/SourceTab.d.ts +9 -0
- package/dist/data-view/SourceTab.js +104 -0
- package/dist/data-view/SourceTab.js.map +1 -0
- package/dist/data-view/UdcDataView.d.ts +12 -0
- package/dist/data-view/UdcDataView.js +365 -0
- package/dist/data-view/UdcDataView.js.map +1 -0
- package/dist/data-view/compose.d.ts +24 -0
- package/dist/data-view/compose.js +86 -0
- package/dist/data-view/compose.js.map +1 -0
- package/dist/data-view/folder.d.ts +13 -0
- package/dist/data-view/folder.js +52 -0
- package/dist/data-view/folder.js.map +1 -0
- package/dist/data-view/liveView.d.ts +20 -0
- package/dist/data-view/liveView.js +67 -0
- package/dist/data-view/liveView.js.map +1 -0
- package/dist/data-view/urlState.d.ts +44 -0
- package/dist/data-view/urlState.js +139 -0
- package/dist/data-view/urlState.js.map +1 -0
- package/dist/data-view/useDataViewState.d.ts +39 -0
- package/dist/data-view/useDataViewState.js +79 -0
- package/dist/data-view/useDataViewState.js.map +1 -0
- package/dist/headless.d.ts +31 -0
- package/dist/headless.js +31 -0
- package/dist/i18n/i18n.d.ts +71 -0
- package/dist/i18n/i18n.js +151 -0
- package/dist/i18n/i18n.js.map +1 -0
- package/dist/i18n/translations.d.ts +16 -0
- package/dist/i18n/translations.js +967 -0
- package/dist/i18n/translations.js.map +1 -0
- package/dist/icons/lucide.generated.d.ts +2 -0
- package/dist/icons/lucide.generated.js +32 -0
- package/dist/icons/lucide.generated.js.map +1 -0
- package/dist/icons/resolve.d.ts +9 -0
- package/dist/icons/resolve.js +25 -0
- package/dist/icons/resolve.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +23 -0
- package/dist/kanban/CardDetailDialog.d.ts +17 -0
- package/dist/kanban/CardDetailDialog.js +53 -0
- package/dist/kanban/CardDetailDialog.js.map +1 -0
- package/dist/kanban/KanbanBoardSwitcher.d.ts +6 -0
- package/dist/kanban/KanbanBoardSwitcher.js +27 -0
- package/dist/kanban/KanbanBoardSwitcher.js.map +1 -0
- package/dist/kanban/KanbanCard.d.ts +21 -0
- package/dist/kanban/KanbanCard.js +189 -0
- package/dist/kanban/KanbanCard.js.map +1 -0
- package/dist/kanban/KanbanColumn.d.ts +30 -0
- package/dist/kanban/KanbanColumn.js +228 -0
- package/dist/kanban/KanbanColumn.js.map +1 -0
- package/dist/kanban/KanbanRenderer.d.ts +3 -0
- package/dist/kanban/KanbanRenderer.js +472 -0
- package/dist/kanban/KanbanRenderer.js.map +1 -0
- package/dist/kanban/index.d.ts +5 -0
- package/dist/kanban/model.d.ts +89 -0
- package/dist/kanban/model.js +159 -0
- package/dist/kanban/model.js.map +1 -0
- package/dist/kanban/persist.d.ts +27 -0
- package/dist/kanban/persist.js +54 -0
- package/dist/kanban/persist.js.map +1 -0
- package/dist/kanban/useKanbanBoard.d.ts +21 -0
- package/dist/kanban/useKanbanBoard.js +47 -0
- package/dist/kanban/useKanbanBoard.js.map +1 -0
- package/dist/kanban.d.ts +1 -0
- package/dist/kanban.js +17 -0
- package/dist/kanban.js.map +1 -0
- package/dist/lib/storage.d.ts +7 -0
- package/dist/lib/storage.js +24 -0
- package/dist/lib/storage.js.map +1 -0
- package/dist/lib/theme.d.ts +11 -0
- package/dist/lib/theme.js +43 -0
- package/dist/lib/theme.js.map +1 -0
- package/dist/lib/utils.d.ts +4 -0
- package/dist/lib/utils.js +12 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/map/MapRenderer.d.ts +13 -0
- package/dist/map/MapRenderer.js +405 -0
- package/dist/map/MapRenderer.js.map +1 -0
- package/dist/map/index.d.ts +4 -0
- package/dist/map/model.d.ts +68 -0
- package/dist/map/model.js +143 -0
- package/dist/map/model.js.map +1 -0
- package/dist/map.d.ts +1 -0
- package/dist/map.js +15 -0
- package/dist/map.js.map +1 -0
- package/dist/react-router/UdcReactRouterUrlState.d.ts +10 -0
- package/dist/react-router/UdcReactRouterUrlState.js +35 -0
- package/dist/react-router/UdcReactRouterUrlState.js.map +1 -0
- package/dist/react-router/index.d.ts +1 -0
- package/dist/react-router.d.ts +1 -0
- package/dist/react-router.js +1 -0
- package/dist/renderers/AllRowsStatus.d.ts +8 -0
- package/dist/renderers/AllRowsStatus.js +34 -0
- package/dist/renderers/AllRowsStatus.js.map +1 -0
- package/dist/renderers/context.d.ts +11 -0
- package/dist/renderers/context.js +15 -0
- package/dist/renderers/context.js.map +1 -0
- package/dist/renderers/registry.d.ts +25 -0
- package/dist/renderers/registry.js +40 -0
- package/dist/renderers/registry.js.map +1 -0
- package/dist/renderers/types.d.ts +90 -0
- package/dist/renderers/types.js +8 -0
- package/dist/renderers/types.js.map +1 -0
- package/dist/schema-editor/ColumnHeaderMenu.d.ts +11 -0
- package/dist/schema-editor/ColumnHeaderMenu.js +75 -0
- package/dist/schema-editor/ColumnHeaderMenu.js.map +1 -0
- package/dist/schema-editor/DeleteFieldDialog.d.ts +8 -0
- package/dist/schema-editor/DeleteFieldDialog.js +79 -0
- package/dist/schema-editor/DeleteFieldDialog.js.map +1 -0
- package/dist/schema-editor/FieldFormDialog.d.ts +22 -0
- package/dist/schema-editor/FieldFormDialog.js +312 -0
- package/dist/schema-editor/FieldFormDialog.js.map +1 -0
- package/dist/schema-editor/TagInput.d.ts +9 -0
- package/dist/schema-editor/TagInput.js +46 -0
- package/dist/schema-editor/TagInput.js.map +1 -0
- package/dist/schema-editor/fieldForm.d.ts +52 -0
- package/dist/schema-editor/fieldForm.js +132 -0
- package/dist/schema-editor/fieldForm.js.map +1 -0
- package/dist/schema-editor/index.d.ts +6 -0
- package/dist/schema-editor/useSchemaEditor.d.ts +15 -0
- package/dist/schema-editor/useSchemaEditor.js +87 -0
- package/dist/schema-editor/useSchemaEditor.js.map +1 -0
- package/dist/schema-editor.d.ts +1 -0
- package/dist/schema-editor.js +7 -0
- package/dist/styles.css +2 -0
- package/dist/table/CellEditor.d.ts +31 -0
- package/dist/table/CellEditor.js +145 -0
- package/dist/table/CellEditor.js.map +1 -0
- package/dist/table/Pager.d.ts +8 -0
- package/dist/table/Pager.js +90 -0
- package/dist/table/Pager.js.map +1 -0
- package/dist/table/TableRenderer.d.ts +27 -0
- package/dist/table/TableRenderer.js +458 -0
- package/dist/table/TableRenderer.js.map +1 -0
- package/dist/table/cells.d.ts +16 -0
- package/dist/table/cells.js +106 -0
- package/dist/table/cells.js.map +1 -0
- package/dist/table/format.d.ts +24 -0
- package/dist/table/format.js +117 -0
- package/dist/table/format.js.map +1 -0
- package/dist/table/index.d.ts +6 -0
- package/dist/table/sparkline.d.ts +31 -0
- package/dist/table/sparkline.js +105 -0
- package/dist/table/sparkline.js.map +1 -0
- package/dist/table/states.d.ts +17 -0
- package/dist/table/states.js +86 -0
- package/dist/table/states.js.map +1 -0
- package/dist/table/style.d.ts +15 -0
- package/dist/table/style.js +53 -0
- package/dist/table/style.js.map +1 -0
- package/dist/table/transforms.d.ts +17 -0
- package/dist/table/transforms.js +95 -0
- package/dist/table/transforms.js.map +1 -0
- package/dist/table/useInfiniteSentinel.d.ts +8 -0
- package/dist/table/useInfiniteSentinel.js +34 -0
- package/dist/table/useInfiniteSentinel.js.map +1 -0
- package/dist/table.d.ts +1 -0
- package/dist/table.js +18 -0
- package/dist/table.js.map +1 -0
- package/dist/time/timezone.d.ts +27 -0
- package/dist/time/timezone.js +65 -0
- package/dist/time/timezone.js.map +1 -0
- package/dist/time/zoned.d.ts +65 -0
- package/dist/time/zoned.js +208 -0
- package/dist/time/zoned.js.map +1 -0
- package/dist/tokens.css +457 -0
- package/dist/tree/TreeNode.d.ts +9 -0
- package/dist/tree/TreeNode.js +292 -0
- package/dist/tree/TreeNode.js.map +1 -0
- package/dist/tree/TreeRenderer.d.ts +54 -0
- package/dist/tree/TreeRenderer.js +446 -0
- package/dist/tree/TreeRenderer.js.map +1 -0
- package/dist/tree/expand.d.ts +31 -0
- package/dist/tree/expand.js +80 -0
- package/dist/tree/expand.js.map +1 -0
- package/dist/tree/index.d.ts +4 -0
- package/dist/tree/model.d.ts +108 -0
- package/dist/tree/model.js +294 -0
- package/dist/tree/model.js.map +1 -0
- package/dist/tree.d.ts +1 -0
- package/dist/tree.js +15 -0
- package/dist/tree.js.map +1 -0
- package/dist/udc/client.d.ts +11 -0
- package/dist/udc/client.js +30 -0
- package/dist/udc/client.js.map +1 -0
- package/dist/udc/hooks.d.ts +644 -0
- package/dist/udc/hooks.js +353 -0
- package/dist/udc/hooks.js.map +1 -0
- package/dist/udc/keys.d.ts +19 -0
- package/dist/udc/keys.js +30 -0
- package/dist/udc/keys.js.map +1 -0
- package/dist/udc/provider.d.ts +19 -0
- package/dist/udc/provider.js +29 -0
- package/dist/udc/provider.js.map +1 -0
- package/dist/ui-kit/context.d.ts +11 -0
- package/dist/ui-kit/context.js +19 -0
- package/dist/ui-kit/context.js.map +1 -0
- package/dist/ui-kit/default.d.ts +3 -0
- package/dist/ui-kit/default.js +45 -0
- package/dist/ui-kit/default.js.map +1 -0
- package/dist/ui-kit/index.d.ts +2 -0
- package/dist/ui-kit/types.d.ts +227 -0
- package/dist/ui-kit/ui.d.ts +12 -0
- package/dist/ui.d.ts +1 -0
- package/dist/ui.js +13 -0
- package/dist/url-state/UrlState.d.ts +20 -0
- package/dist/url-state/UrlState.js +27 -0
- package/dist/url-state/UrlState.js.map +1 -0
- package/dist/url-state/adapter.d.ts +24 -0
- package/dist/url-state/adapter.js +33 -0
- package/dist/url-state/adapter.js.map +1 -0
- package/dist/url-state/index.d.ts +2 -0
- package/package.json +185 -4
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { type Condition, type FilterNode, type ListRequest, type ParentLookup, type Row, type SchemaDoc, type TreeOptions, type TreeReparentRequest } from "@jsudc/core";
|
|
2
|
+
export declare const idOf: (r: Row) => string;
|
|
3
|
+
export declare function parentOf(row: Row, opts: Pick<TreeOptions, "parent_field">): string | null;
|
|
4
|
+
export declare function numberOf(row: Row | undefined, field: string | undefined): number | null;
|
|
5
|
+
/** Siblings in `sibling_sort` order (missing values last either way, as the server), ties by id. */
|
|
6
|
+
export declare function sortSiblings(rows: readonly Row[], sort: TreeOptions["sibling_sort"]): Row[];
|
|
7
|
+
export interface BuiltTree {
|
|
8
|
+
roots: Row[];
|
|
9
|
+
/** Parent id → its children, sorted. */
|
|
10
|
+
children: ReadonlyMap<string, Row[]>;
|
|
11
|
+
byId: ReadonlyMap<string, Row>;
|
|
12
|
+
/** Rows drawn as roots because their parent is not among the rows (a filter left it out). */
|
|
13
|
+
orphans: ReadonlySet<string>;
|
|
14
|
+
/** Depth in the drawn tree (an orphan is at 0). */
|
|
15
|
+
depth: ReadonlyMap<string, number>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The tree of a flat list: a row whose parent is in the list sits under it;
|
|
19
|
+
* every other row is a root — an orphan when it does have a parent, so a
|
|
20
|
+
* chip that filters parents out still shows their children. A row caught
|
|
21
|
+
* in a parent cycle is drawn as a root too, never lost.
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildTree(rows: readonly Row[], opts: Pick<TreeOptions, "parent_field" | "sibling_sort">): BuiltTree;
|
|
24
|
+
/** Child → parent of every row, for `isCycle`. */
|
|
25
|
+
export declare function parentLookup(rows: Iterable<Row>, opts: Pick<TreeOptions, "parent_field">): ParentLookup;
|
|
26
|
+
/** Start / end indices of every case-insensitive occurrence of `term`, taken literally. */
|
|
27
|
+
export declare function findMatchRanges(text: string, term: string): [number, number][];
|
|
28
|
+
/** `text` split into plain and matching parts, in order, each with its start offset. */
|
|
29
|
+
export declare function highlightParts(text: string, term: string): {
|
|
30
|
+
text: string;
|
|
31
|
+
match: boolean;
|
|
32
|
+
at: number;
|
|
33
|
+
}[];
|
|
34
|
+
/**
|
|
35
|
+
* `highlight_and_expand`: the rows any search field of which contains the
|
|
36
|
+
* term (as the server's `contains` would), and every ancestor of one — the
|
|
37
|
+
* nodes to open so each match is on screen.
|
|
38
|
+
*/
|
|
39
|
+
export declare function searchExpansion(tree: BuiltTree, term: string, fields: readonly string[], opts: Pick<TreeOptions, "parent_field">): {
|
|
40
|
+
matches: Set<string>;
|
|
41
|
+
open: Set<string>;
|
|
42
|
+
};
|
|
43
|
+
/** The `<SECTION>_<TERM>` split of an i18n label, on the first underscore; `null` when it has none. */
|
|
44
|
+
export declare function i18nKey(value: string): [string, string] | null;
|
|
45
|
+
export declare function rootCondition(opts: TreeOptions): Condition;
|
|
46
|
+
/**
|
|
47
|
+
* The roots of a lazy tree: `root_filter` and the data view's filter. With
|
|
48
|
+
* a filter on, every matching row is listed instead (the ones under a
|
|
49
|
+
* matching parent are dropped by the renderer and show when it opens).
|
|
50
|
+
*/
|
|
51
|
+
export declare function lazyRootsQuery(opts: TreeOptions, filter: FilterNode | undefined): Pick<ListRequest, "filter" | "sort"> & {
|
|
52
|
+
limit: number;
|
|
53
|
+
};
|
|
54
|
+
/** One level of a lazy tree: the children of `parentId` that pass the data view's filter. */
|
|
55
|
+
export declare function lazyChildrenQuery(opts: TreeOptions, parentId: string, filter: FilterNode | undefined): Pick<ListRequest, "filter" | "sort"> & {
|
|
56
|
+
limit: number;
|
|
57
|
+
};
|
|
58
|
+
/** The siblings under `parent` (or the roots), by order: what a drop's order is computed from. */
|
|
59
|
+
export declare function siblingsQuery(opts: TreeOptions, parent: string | null): Pick<ListRequest, "filter" | "sort"> & {
|
|
60
|
+
limit: number;
|
|
61
|
+
};
|
|
62
|
+
/** Onto a node (it becomes the last child) or into the gap above a node (same parent). */
|
|
63
|
+
export type DropTarget = {
|
|
64
|
+
kind: "into";
|
|
65
|
+
id: string;
|
|
66
|
+
} | {
|
|
67
|
+
kind: "before";
|
|
68
|
+
id: string;
|
|
69
|
+
};
|
|
70
|
+
export declare function dropId(t: DropTarget): string;
|
|
71
|
+
export declare function parseDropId(id: string): DropTarget | null;
|
|
72
|
+
/** The parent a drop on `target` gives the moved node; `undefined` when the target is not loaded. */
|
|
73
|
+
export declare function dropParent(target: DropTarget, rowsById: ReadonlyMap<string, Row>, opts: Pick<TreeOptions, "parent_field">): string | null | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Whether `dragId` may land on `target`: never into itself or its subtree
|
|
76
|
+
* (`isCycle`, over the target parent's `ancestor_ids` when the tree has
|
|
77
|
+
* them, else the loaded rows' parent links), never above itself.
|
|
78
|
+
*/
|
|
79
|
+
export declare function canDrop(dragId: string, target: DropTarget, rowsById: ReadonlyMap<string, Row>, opts: Pick<TreeOptions, "parent_field" | "ancestor_ids_field">): boolean;
|
|
80
|
+
export interface DropPlan {
|
|
81
|
+
id: string;
|
|
82
|
+
parent: string | null;
|
|
83
|
+
order: number;
|
|
84
|
+
/** No integer left between the neighbours: renumber the siblings and plan again. */
|
|
85
|
+
collision: boolean;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The order of a drop, from the new parent's children by order (the moved
|
|
89
|
+
* node left out): last child for `into`, between the target and the one
|
|
90
|
+
* above it for `before`.
|
|
91
|
+
*/
|
|
92
|
+
export declare function planDrop(dragId: string, target: DropTarget, parent: string | null, siblings: readonly {
|
|
93
|
+
id: string;
|
|
94
|
+
order: number | null;
|
|
95
|
+
}[]): DropPlan;
|
|
96
|
+
/** The `tree.reparent` call of a plan; the structure fields come from `tree_options`. */
|
|
97
|
+
export declare function reparentRequest(collection: string, opts: TreeOptions, plan: DropPlan, version: number | undefined): TreeReparentRequest;
|
|
98
|
+
export declare const REPLY_AUTHOR: {
|
|
99
|
+
readonly name: "You";
|
|
100
|
+
readonly initials: "YO";
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* A reply under `parent`: the text in `label_field`, the next sparse order
|
|
104
|
+
* after the last sibling, depth one below, "You" as author when the schema
|
|
105
|
+
* has one, and now in every datetime field the siblings sort by (so the
|
|
106
|
+
* reply reads last, as a new comment should).
|
|
107
|
+
*/
|
|
108
|
+
export declare function replyRow(opts: TreeOptions, schema: Pick<SchemaDoc, "fields">, parent: Row, siblings: readonly Row[], text: string, now: Date): Record<string, unknown>;
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { ORDER_GAP, detectCollision, isCycle, orderBetween, treeReparentFields } from "@jsudc/core";
|
|
2
|
+
// src/tree/model.ts
|
|
3
|
+
var idOf = (r) => r.__meta.id;
|
|
4
|
+
function parentOf(row, opts) {
|
|
5
|
+
const v = row[opts.parent_field];
|
|
6
|
+
return typeof v === "string" && v !== "" ? v : null;
|
|
7
|
+
}
|
|
8
|
+
function numberOf(row, field) {
|
|
9
|
+
if (!row || !field) return null;
|
|
10
|
+
const v = row[field];
|
|
11
|
+
const n = typeof v === "number" ? v : typeof v === "string" && v !== "" ? Number(v) : NaN;
|
|
12
|
+
return Number.isFinite(n) ? n : null;
|
|
13
|
+
}
|
|
14
|
+
var missing = (v) => v === null || v === void 0 || v === "";
|
|
15
|
+
function compare(a, b) {
|
|
16
|
+
if (typeof a === "number" && typeof b === "number") return a - b;
|
|
17
|
+
return String(a).localeCompare(String(b));
|
|
18
|
+
}
|
|
19
|
+
/** Siblings in `sibling_sort` order (missing values last either way, as the server), ties by id. */
|
|
20
|
+
function sortSiblings(rows, sort) {
|
|
21
|
+
return [...rows].sort((x, y) => {
|
|
22
|
+
for (const { field, dir } of sort) {
|
|
23
|
+
const [a, b] = [x[field], y[field]];
|
|
24
|
+
if (missing(a) || missing(b)) {
|
|
25
|
+
if (missing(a) && missing(b)) continue;
|
|
26
|
+
return missing(a) ? 1 : -1;
|
|
27
|
+
}
|
|
28
|
+
const c = compare(a, b);
|
|
29
|
+
if (c !== 0) return dir === "desc" ? -c : c;
|
|
30
|
+
}
|
|
31
|
+
return idOf(x) < idOf(y) ? -1 : idOf(x) > idOf(y) ? 1 : 0;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The tree of a flat list: a row whose parent is in the list sits under it;
|
|
36
|
+
* every other row is a root — an orphan when it does have a parent, so a
|
|
37
|
+
* chip that filters parents out still shows their children. A row caught
|
|
38
|
+
* in a parent cycle is drawn as a root too, never lost.
|
|
39
|
+
*/
|
|
40
|
+
function buildTree(rows, opts) {
|
|
41
|
+
const byId = new Map(rows.map((r) => [idOf(r), r]));
|
|
42
|
+
const kids = /* @__PURE__ */ new Map();
|
|
43
|
+
const roots = [];
|
|
44
|
+
const orphans = /* @__PURE__ */ new Set();
|
|
45
|
+
for (const row of rows) {
|
|
46
|
+
const p = parentOf(row, opts);
|
|
47
|
+
if (p !== null && byId.has(p) && p !== idOf(row)) kids.set(p, [...kids.get(p) ?? [], row]);
|
|
48
|
+
else {
|
|
49
|
+
roots.push(row);
|
|
50
|
+
if (p !== null) orphans.add(idOf(row));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const depth = /* @__PURE__ */ new Map();
|
|
54
|
+
const visit = (row, d) => {
|
|
55
|
+
depth.set(idOf(row), d);
|
|
56
|
+
for (const c of kids.get(idOf(row)) ?? []) if (!depth.has(idOf(c))) visit(c, d + 1);
|
|
57
|
+
};
|
|
58
|
+
for (const r of roots) visit(r, 0);
|
|
59
|
+
for (const row of rows) {
|
|
60
|
+
if (depth.has(idOf(row))) continue;
|
|
61
|
+
roots.push(row);
|
|
62
|
+
orphans.add(idOf(row));
|
|
63
|
+
visit(row, 0);
|
|
64
|
+
}
|
|
65
|
+
const children = new Map([...kids].map(([p, list]) => [p, sortSiblings(list, opts.sibling_sort)]));
|
|
66
|
+
return {
|
|
67
|
+
roots: sortSiblings(roots, opts.sibling_sort),
|
|
68
|
+
children,
|
|
69
|
+
byId,
|
|
70
|
+
orphans,
|
|
71
|
+
depth
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Child → parent of every row, for `isCycle`. */
|
|
75
|
+
function parentLookup(rows, opts) {
|
|
76
|
+
const map = /* @__PURE__ */ new Map();
|
|
77
|
+
for (const r of rows) map.set(idOf(r), parentOf(r, opts));
|
|
78
|
+
return map;
|
|
79
|
+
}
|
|
80
|
+
/** Start / end indices of every case-insensitive occurrence of `term`, taken literally. */
|
|
81
|
+
function findMatchRanges(text, term) {
|
|
82
|
+
const needle = term.trim().toLowerCase();
|
|
83
|
+
if (!needle) return [];
|
|
84
|
+
const hay = text.toLowerCase();
|
|
85
|
+
const ranges = [];
|
|
86
|
+
for (let i = hay.indexOf(needle); i !== -1; i = hay.indexOf(needle, i + needle.length)) ranges.push([i, i + needle.length]);
|
|
87
|
+
return ranges;
|
|
88
|
+
}
|
|
89
|
+
/** `text` split into plain and matching parts, in order, each with its start offset. */
|
|
90
|
+
function highlightParts(text, term) {
|
|
91
|
+
const parts = [];
|
|
92
|
+
let at = 0;
|
|
93
|
+
for (const [from, to] of findMatchRanges(text, term)) {
|
|
94
|
+
if (from > at) parts.push({
|
|
95
|
+
text: text.slice(at, from),
|
|
96
|
+
match: false,
|
|
97
|
+
at
|
|
98
|
+
});
|
|
99
|
+
parts.push({
|
|
100
|
+
text: text.slice(from, to),
|
|
101
|
+
match: true,
|
|
102
|
+
at: from
|
|
103
|
+
});
|
|
104
|
+
at = to;
|
|
105
|
+
}
|
|
106
|
+
if (at < text.length || parts.length === 0) parts.push({
|
|
107
|
+
text: text.slice(at),
|
|
108
|
+
match: false,
|
|
109
|
+
at
|
|
110
|
+
});
|
|
111
|
+
return parts;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* `highlight_and_expand`: the rows any search field of which contains the
|
|
115
|
+
* term (as the server's `contains` would), and every ancestor of one — the
|
|
116
|
+
* nodes to open so each match is on screen.
|
|
117
|
+
*/
|
|
118
|
+
function searchExpansion(tree, term, fields, opts) {
|
|
119
|
+
const matches = /* @__PURE__ */ new Set();
|
|
120
|
+
const open = /* @__PURE__ */ new Set();
|
|
121
|
+
const needle = term.trim().toLowerCase();
|
|
122
|
+
if (!needle) return {
|
|
123
|
+
matches,
|
|
124
|
+
open
|
|
125
|
+
};
|
|
126
|
+
for (const row of tree.byId.values()) {
|
|
127
|
+
if (!fields.some((f) => String(row[f] ?? "").toLowerCase().includes(needle))) continue;
|
|
128
|
+
matches.add(idOf(row));
|
|
129
|
+
let p = tree.orphans.has(idOf(row)) ? null : parentOf(row, opts);
|
|
130
|
+
while (p !== null && !open.has(p) && tree.byId.has(p)) {
|
|
131
|
+
open.add(p);
|
|
132
|
+
const up = tree.byId.get(p);
|
|
133
|
+
p = tree.orphans.has(p) ? null : parentOf(up, opts);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
matches,
|
|
138
|
+
open
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/** The `<SECTION>_<TERM>` split of an i18n label, on the first underscore; `null` when it has none. */
|
|
142
|
+
function i18nKey(value) {
|
|
143
|
+
const i = value.indexOf("_");
|
|
144
|
+
return i > 0 && i < value.length - 1 ? [value.slice(0, i), value.slice(i + 1)] : null;
|
|
145
|
+
}
|
|
146
|
+
var and = (parts) => {
|
|
147
|
+
const list = parts.filter((p) => p !== void 0);
|
|
148
|
+
return list.length === 0 ? void 0 : list.length === 1 ? list[0] : { and: list };
|
|
149
|
+
};
|
|
150
|
+
function rootCondition(opts) {
|
|
151
|
+
const { field, op, value } = opts.root_filter;
|
|
152
|
+
return op === "is_null" ? {
|
|
153
|
+
field,
|
|
154
|
+
op
|
|
155
|
+
} : {
|
|
156
|
+
field,
|
|
157
|
+
op,
|
|
158
|
+
value
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The roots of a lazy tree: `root_filter` and the data view's filter. With
|
|
163
|
+
* a filter on, every matching row is listed instead (the ones under a
|
|
164
|
+
* matching parent are dropped by the renderer and show when it opens).
|
|
165
|
+
*/
|
|
166
|
+
function lazyRootsQuery(opts, filter) {
|
|
167
|
+
return {
|
|
168
|
+
filter: filter === void 0 ? rootCondition(opts) : filter,
|
|
169
|
+
sort: opts.sibling_sort,
|
|
170
|
+
limit: opts.lazy_page_size
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/** One level of a lazy tree: the children of `parentId` that pass the data view's filter. */
|
|
174
|
+
function lazyChildrenQuery(opts, parentId, filter) {
|
|
175
|
+
return {
|
|
176
|
+
filter: and([{
|
|
177
|
+
field: opts.parent_field,
|
|
178
|
+
op: "eq",
|
|
179
|
+
value: parentId
|
|
180
|
+
}, filter]),
|
|
181
|
+
sort: opts.sibling_sort,
|
|
182
|
+
limit: opts.lazy_page_size
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/** The siblings under `parent` (or the roots), by order: what a drop's order is computed from. */
|
|
186
|
+
function siblingsQuery(opts, parent) {
|
|
187
|
+
return {
|
|
188
|
+
filter: parent === null ? {
|
|
189
|
+
field: opts.parent_field,
|
|
190
|
+
op: "is_null"
|
|
191
|
+
} : {
|
|
192
|
+
field: opts.parent_field,
|
|
193
|
+
op: "eq",
|
|
194
|
+
value: parent
|
|
195
|
+
},
|
|
196
|
+
sort: [{ field: opts.order_field }],
|
|
197
|
+
limit: opts.lazy_page_size
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function dropId(t) {
|
|
201
|
+
return `${t.kind}:${t.id}`;
|
|
202
|
+
}
|
|
203
|
+
function parseDropId(id) {
|
|
204
|
+
const m = /^(into|before):(.+)$/.exec(id);
|
|
205
|
+
return m ? {
|
|
206
|
+
kind: m[1],
|
|
207
|
+
id: m[2]
|
|
208
|
+
} : null;
|
|
209
|
+
}
|
|
210
|
+
/** The parent a drop on `target` gives the moved node; `undefined` when the target is not loaded. */
|
|
211
|
+
function dropParent(target, rowsById, opts) {
|
|
212
|
+
if (target.kind === "into") return target.id;
|
|
213
|
+
const row = rowsById.get(target.id);
|
|
214
|
+
return row ? parentOf(row, opts) : void 0;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Whether `dragId` may land on `target`: never into itself or its subtree
|
|
218
|
+
* (`isCycle`, over the target parent's `ancestor_ids` when the tree has
|
|
219
|
+
* them, else the loaded rows' parent links), never above itself.
|
|
220
|
+
*/
|
|
221
|
+
function canDrop(dragId, target, rowsById, opts) {
|
|
222
|
+
if (target.kind === "before" && target.id === dragId) return false;
|
|
223
|
+
const parent = dropParent(target, rowsById, opts);
|
|
224
|
+
if (parent === void 0) return false;
|
|
225
|
+
const stored = parent === null ? [] : rowsById.get(parent)?.[opts.ancestor_ids_field ?? ""];
|
|
226
|
+
const ancestry = Array.isArray(stored) ? stored : parentLookup(rowsById.values(), opts);
|
|
227
|
+
return !isCycle(dragId, parent, ancestry) && !isCycle(dragId, parent, parentLookup(rowsById.values(), opts));
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* The order of a drop, from the new parent's children by order (the moved
|
|
231
|
+
* node left out): last child for `into`, between the target and the one
|
|
232
|
+
* above it for `before`.
|
|
233
|
+
*/
|
|
234
|
+
function planDrop(dragId, target, parent, siblings) {
|
|
235
|
+
const orders = siblings.filter((s) => s.id !== dragId).map((s, i) => ({
|
|
236
|
+
id: s.id,
|
|
237
|
+
order: s.order ?? (i + 1) * ORDER_GAP
|
|
238
|
+
}));
|
|
239
|
+
let prev = orders.at(-1)?.order ?? null;
|
|
240
|
+
let next = null;
|
|
241
|
+
if (target.kind === "before") {
|
|
242
|
+
const i = orders.findIndex((s) => s.id === target.id);
|
|
243
|
+
if (i !== -1) {
|
|
244
|
+
prev = orders[i - 1]?.order ?? null;
|
|
245
|
+
next = orders[i]?.order ?? null;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
id: dragId,
|
|
250
|
+
parent,
|
|
251
|
+
order: orderBetween(prev, next),
|
|
252
|
+
collision: detectCollision(prev, next)
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
/** The `tree.reparent` call of a plan; the structure fields come from `tree_options`. */
|
|
256
|
+
function reparentRequest(collection, opts, plan, version) {
|
|
257
|
+
return {
|
|
258
|
+
collection,
|
|
259
|
+
id: plan.id,
|
|
260
|
+
parent: plan.parent,
|
|
261
|
+
order: plan.order,
|
|
262
|
+
...version === void 0 ? {} : { expected_version: version },
|
|
263
|
+
fields: treeReparentFields(opts)
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
var REPLY_AUTHOR = {
|
|
267
|
+
name: "You",
|
|
268
|
+
initials: "YO"
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* A reply under `parent`: the text in `label_field`, the next sparse order
|
|
272
|
+
* after the last sibling, depth one below, "You" as author when the schema
|
|
273
|
+
* has one, and now in every datetime field the siblings sort by (so the
|
|
274
|
+
* reply reads last, as a new comment should).
|
|
275
|
+
*/
|
|
276
|
+
function replyRow(opts, schema, parent, siblings, text, now) {
|
|
277
|
+
const live = (f) => f && schema.fields[f]?.deleted !== true ? f : void 0;
|
|
278
|
+
const orders = siblings.map((s) => numberOf(s, opts.order_field)).filter((n) => n !== null);
|
|
279
|
+
const row = {
|
|
280
|
+
[opts.parent_field]: idOf(parent),
|
|
281
|
+
[opts.label_field]: text,
|
|
282
|
+
[opts.order_field]: (orders.length ? Math.max(...orders) : 0) + ORDER_GAP
|
|
283
|
+
};
|
|
284
|
+
const depthField = live(opts.depth_field);
|
|
285
|
+
if (depthField) row[depthField] = (numberOf(parent, depthField) ?? 0) + 1;
|
|
286
|
+
const avatar = live(opts.avatar_field);
|
|
287
|
+
if (avatar) row[avatar] = REPLY_AUTHOR.initials;
|
|
288
|
+
if (schema.fields.author?.type === "string") row.author = REPLY_AUTHOR.name;
|
|
289
|
+
for (const { field } of opts.sibling_sort) if (schema.fields[field]?.type === "datetime") row[field] = now.toISOString();
|
|
290
|
+
return row;
|
|
291
|
+
}
|
|
292
|
+
export { REPLY_AUTHOR, buildTree, canDrop, dropId, dropParent, findMatchRanges, highlightParts, i18nKey, idOf, lazyChildrenQuery, lazyRootsQuery, numberOf, parentLookup, parentOf, parseDropId, planDrop, reparentRequest, replyRow, rootCondition, searchExpansion, siblingsQuery, sortSiblings };
|
|
293
|
+
|
|
294
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../src/tree/model.ts"],"sourcesContent":["import {\n type Condition,\n detectCollision,\n type FilterNode,\n isCycle,\n type ListRequest,\n ORDER_GAP,\n orderBetween,\n type ParentLookup,\n type Row,\n type SchemaDoc,\n type TreeOptions,\n type TreeReparentRequest,\n treeReparentFields,\n} from \"@jsudc/core\";\n\n/*\n * The tree's pure parts: building a tree from flat rows, sibling order,\n * search highlight and expansion, drop targets and the payloads it writes.\n * The renderer only wires these to queries and the DOM.\n */\n\nexport const idOf = (r: Row) => r.__meta.id;\n\nexport function parentOf(row: Row, opts: Pick<TreeOptions, \"parent_field\">): string | null {\n const v = row[opts.parent_field];\n return typeof v === \"string\" && v !== \"\" ? v : null;\n}\n\nexport function numberOf(row: Row | undefined, field: string | undefined): number | null {\n if (!row || !field) return null;\n const v = row[field];\n const n = typeof v === \"number\" ? v : typeof v === \"string\" && v !== \"\" ? Number(v) : Number.NaN;\n return Number.isFinite(n) ? n : null;\n}\n\nconst missing = (v: unknown) => v === null || v === undefined || v === \"\";\n\nfunction compare(a: unknown, b: unknown): number {\n if (typeof a === \"number\" && typeof b === \"number\") return a - b;\n return String(a).localeCompare(String(b));\n}\n\n/** Siblings in `sibling_sort` order (missing values last either way, as the server), ties by id. */\nexport function sortSiblings(rows: readonly Row[], sort: TreeOptions[\"sibling_sort\"]): Row[] {\n return [...rows].sort((x, y) => {\n for (const { field, dir } of sort) {\n const [a, b] = [x[field], y[field]];\n if (missing(a) || missing(b)) {\n if (missing(a) && missing(b)) continue;\n return missing(a) ? 1 : -1;\n }\n const c = compare(a, b);\n if (c !== 0) return dir === \"desc\" ? -c : c;\n }\n return idOf(x) < idOf(y) ? -1 : idOf(x) > idOf(y) ? 1 : 0;\n });\n}\n\nexport interface BuiltTree {\n roots: Row[];\n /** Parent id → its children, sorted. */\n children: ReadonlyMap<string, Row[]>;\n byId: ReadonlyMap<string, Row>;\n /** Rows drawn as roots because their parent is not among the rows (a filter left it out). */\n orphans: ReadonlySet<string>;\n /** Depth in the drawn tree (an orphan is at 0). */\n depth: ReadonlyMap<string, number>;\n}\n\n/**\n * The tree of a flat list: a row whose parent is in the list sits under it;\n * every other row is a root — an orphan when it does have a parent, so a\n * chip that filters parents out still shows their children. A row caught\n * in a parent cycle is drawn as a root too, never lost.\n */\nexport function buildTree(\n rows: readonly Row[],\n opts: Pick<TreeOptions, \"parent_field\" | \"sibling_sort\">,\n): BuiltTree {\n const byId = new Map(rows.map((r) => [idOf(r), r]));\n const kids = new Map<string, Row[]>();\n const roots: Row[] = [];\n const orphans = new Set<string>();\n for (const row of rows) {\n const p = parentOf(row, opts);\n if (p !== null && byId.has(p) && p !== idOf(row)) {\n kids.set(p, [...(kids.get(p) ?? []), row]);\n } else {\n roots.push(row);\n if (p !== null) orphans.add(idOf(row));\n }\n }\n const depth = new Map<string, number>();\n const visit = (row: Row, d: number) => {\n depth.set(idOf(row), d);\n for (const c of kids.get(idOf(row)) ?? []) if (!depth.has(idOf(c))) visit(c, d + 1);\n };\n for (const r of roots) visit(r, 0);\n // Rows only reachable through a cycle: break it at one of them.\n for (const row of rows) {\n if (depth.has(idOf(row))) continue;\n roots.push(row);\n orphans.add(idOf(row));\n visit(row, 0);\n }\n const children = new Map(\n [...kids].map(([p, list]) => [p, sortSiblings(list, opts.sibling_sort)] as const),\n );\n return { roots: sortSiblings(roots, opts.sibling_sort), children, byId, orphans, depth };\n}\n\n/** Child → parent of every row, for `isCycle`. */\nexport function parentLookup(rows: Iterable<Row>, opts: Pick<TreeOptions, \"parent_field\">) {\n const map = new Map<string, string | null>();\n for (const r of rows) map.set(idOf(r), parentOf(r, opts));\n return map as ParentLookup;\n}\n\n// search ------------------------------------------------------------------------\n\n/** Start / end indices of every case-insensitive occurrence of `term`, taken literally. */\nexport function findMatchRanges(text: string, term: string): [number, number][] {\n const needle = term.trim().toLowerCase();\n if (!needle) return [];\n const hay = text.toLowerCase();\n const ranges: [number, number][] = [];\n for (let i = hay.indexOf(needle); i !== -1; i = hay.indexOf(needle, i + needle.length)) {\n ranges.push([i, i + needle.length]);\n }\n return ranges;\n}\n\n/** `text` split into plain and matching parts, in order, each with its start offset. */\nexport function highlightParts(\n text: string,\n term: string,\n): { text: string; match: boolean; at: number }[] {\n const parts: { text: string; match: boolean; at: number }[] = [];\n let at = 0;\n for (const [from, to] of findMatchRanges(text, term)) {\n if (from > at) parts.push({ text: text.slice(at, from), match: false, at });\n parts.push({ text: text.slice(from, to), match: true, at: from });\n at = to;\n }\n if (at < text.length || parts.length === 0) {\n parts.push({ text: text.slice(at), match: false, at });\n }\n return parts;\n}\n\n/**\n * `highlight_and_expand`: the rows any search field of which contains the\n * term (as the server's `contains` would), and every ancestor of one — the\n * nodes to open so each match is on screen.\n */\nexport function searchExpansion(\n tree: BuiltTree,\n term: string,\n fields: readonly string[],\n opts: Pick<TreeOptions, \"parent_field\">,\n): { matches: Set<string>; open: Set<string> } {\n const matches = new Set<string>();\n const open = new Set<string>();\n const needle = term.trim().toLowerCase();\n if (!needle) return { matches, open };\n for (const row of tree.byId.values()) {\n if (\n !fields.some((f) =>\n String(row[f] ?? \"\")\n .toLowerCase()\n .includes(needle),\n )\n )\n continue;\n matches.add(idOf(row));\n let p = tree.orphans.has(idOf(row)) ? null : parentOf(row, opts);\n while (p !== null && !open.has(p) && tree.byId.has(p)) {\n open.add(p);\n const up = tree.byId.get(p) as Row;\n p = tree.orphans.has(p) ? null : parentOf(up, opts);\n }\n }\n return { matches, open };\n}\n\n// labels ------------------------------------------------------------------------\n\n/** The `<SECTION>_<TERM>` split of an i18n label, on the first underscore; `null` when it has none. */\nexport function i18nKey(value: string): [string, string] | null {\n const i = value.indexOf(\"_\");\n return i > 0 && i < value.length - 1 ? [value.slice(0, i), value.slice(i + 1)] : null;\n}\n\n// lazy queries --------------------------------------------------------------------\n\nconst and = (parts: (FilterNode | undefined)[]): FilterNode | undefined => {\n const list = parts.filter((p): p is FilterNode => p !== undefined);\n return list.length === 0 ? undefined : list.length === 1 ? list[0] : { and: list };\n};\n\nexport function rootCondition(opts: TreeOptions): Condition {\n const { field, op, value } = opts.root_filter;\n return op === \"is_null\" ? { field, op } : { field, op, value };\n}\n\n/**\n * The roots of a lazy tree: `root_filter` and the data view's filter. With\n * a filter on, every matching row is listed instead (the ones under a\n * matching parent are dropped by the renderer and show when it opens).\n */\nexport function lazyRootsQuery(\n opts: TreeOptions,\n filter: FilterNode | undefined,\n): Pick<ListRequest, \"filter\" | \"sort\"> & { limit: number } {\n const f = filter === undefined ? rootCondition(opts) : filter;\n return { filter: f, sort: opts.sibling_sort, limit: opts.lazy_page_size };\n}\n\n/** One level of a lazy tree: the children of `parentId` that pass the data view's filter. */\nexport function lazyChildrenQuery(\n opts: TreeOptions,\n parentId: string,\n filter: FilterNode | undefined,\n): Pick<ListRequest, \"filter\" | \"sort\"> & { limit: number } {\n const own: Condition = { field: opts.parent_field, op: \"eq\", value: parentId };\n return {\n filter: and([own, filter]) as FilterNode,\n sort: opts.sibling_sort,\n limit: opts.lazy_page_size,\n };\n}\n\n/** The siblings under `parent` (or the roots), by order: what a drop's order is computed from. */\nexport function siblingsQuery(\n opts: TreeOptions,\n parent: string | null,\n): Pick<ListRequest, \"filter\" | \"sort\"> & { limit: number } {\n const filter: Condition =\n parent === null\n ? { field: opts.parent_field, op: \"is_null\" }\n : { field: opts.parent_field, op: \"eq\", value: parent };\n return { filter, sort: [{ field: opts.order_field }], limit: opts.lazy_page_size };\n}\n\n// drops -----------------------------------------------------------------------------\n\n/** Onto a node (it becomes the last child) or into the gap above a node (same parent). */\nexport type DropTarget = { kind: \"into\"; id: string } | { kind: \"before\"; id: string };\n\nexport function dropId(t: DropTarget): string {\n return `${t.kind}:${t.id}`;\n}\n\nexport function parseDropId(id: string): DropTarget | null {\n const m = /^(into|before):(.+)$/.exec(id);\n return m ? { kind: m[1] as DropTarget[\"kind\"], id: m[2] as string } : null;\n}\n\n/** The parent a drop on `target` gives the moved node; `undefined` when the target is not loaded. */\nexport function dropParent(\n target: DropTarget,\n rowsById: ReadonlyMap<string, Row>,\n opts: Pick<TreeOptions, \"parent_field\">,\n): string | null | undefined {\n if (target.kind === \"into\") return target.id;\n const row = rowsById.get(target.id);\n return row ? parentOf(row, opts) : undefined;\n}\n\n/**\n * Whether `dragId` may land on `target`: never into itself or its subtree\n * (`isCycle`, over the target parent's `ancestor_ids` when the tree has\n * them, else the loaded rows' parent links), never above itself.\n */\nexport function canDrop(\n dragId: string,\n target: DropTarget,\n rowsById: ReadonlyMap<string, Row>,\n opts: Pick<TreeOptions, \"parent_field\" | \"ancestor_ids_field\">,\n): boolean {\n if (target.kind === \"before\" && target.id === dragId) return false;\n const parent = dropParent(target, rowsById, opts);\n if (parent === undefined) return false;\n const stored = parent === null ? [] : rowsById.get(parent)?.[opts.ancestor_ids_field ?? \"\"];\n const ancestry = Array.isArray(stored)\n ? (stored as string[])\n : parentLookup(rowsById.values(), opts);\n // Stored ancestors may be stale for rows moved in this session: the loaded links must agree too.\n return (\n !isCycle(dragId, parent, ancestry) &&\n !isCycle(dragId, parent, parentLookup(rowsById.values(), opts))\n );\n}\n\nexport interface DropPlan {\n id: string;\n parent: string | null;\n order: number;\n /** No integer left between the neighbours: renumber the siblings and plan again. */\n collision: boolean;\n}\n\n/**\n * The order of a drop, from the new parent's children by order (the moved\n * node left out): last child for `into`, between the target and the one\n * above it for `before`.\n */\nexport function planDrop(\n dragId: string,\n target: DropTarget,\n parent: string | null,\n siblings: readonly { id: string; order: number | null }[],\n): DropPlan {\n const orders = siblings\n .filter((s) => s.id !== dragId)\n .map((s, i) => ({ id: s.id, order: s.order ?? (i + 1) * ORDER_GAP }));\n let prev: number | null = orders.at(-1)?.order ?? null;\n let next: number | null = null;\n if (target.kind === \"before\") {\n const i = orders.findIndex((s) => s.id === target.id);\n if (i !== -1) {\n prev = orders[i - 1]?.order ?? null;\n next = orders[i]?.order ?? null;\n }\n }\n return {\n id: dragId,\n parent,\n order: orderBetween(prev, next),\n collision: detectCollision(prev, next),\n };\n}\n\n/** The `tree.reparent` call of a plan; the structure fields come from `tree_options`. */\nexport function reparentRequest(\n collection: string,\n opts: TreeOptions,\n plan: DropPlan,\n version: number | undefined,\n): TreeReparentRequest {\n return {\n collection,\n id: plan.id,\n parent: plan.parent,\n order: plan.order,\n ...(version === undefined ? {} : { expected_version: version }),\n fields: treeReparentFields(opts),\n };\n}\n\n// reply -------------------------------------------------------------------------------\n\nexport const REPLY_AUTHOR = { name: \"You\", initials: \"YO\" } as const;\n\n/**\n * A reply under `parent`: the text in `label_field`, the next sparse order\n * after the last sibling, depth one below, \"You\" as author when the schema\n * has one, and now in every datetime field the siblings sort by (so the\n * reply reads last, as a new comment should).\n */\nexport function replyRow(\n opts: TreeOptions,\n schema: Pick<SchemaDoc, \"fields\">,\n parent: Row,\n siblings: readonly Row[],\n text: string,\n now: Date,\n): Record<string, unknown> {\n const live = (f: string | undefined) => (f && schema.fields[f]?.deleted !== true ? f : undefined);\n const orders = siblings\n .map((s) => numberOf(s, opts.order_field))\n .filter((n): n is number => n !== null);\n const row: Record<string, unknown> = {\n [opts.parent_field]: idOf(parent),\n [opts.label_field]: text,\n [opts.order_field]: (orders.length ? Math.max(...orders) : 0) + ORDER_GAP,\n };\n const depthField = live(opts.depth_field);\n if (depthField) row[depthField] = (numberOf(parent, depthField) ?? 0) + 1;\n const avatar = live(opts.avatar_field);\n if (avatar) row[avatar] = REPLY_AUTHOR.initials;\n if (schema.fields.author?.type === \"string\") row.author = REPLY_AUTHOR.name;\n for (const { field } of opts.sibling_sort) {\n if (schema.fields[field]?.type === \"datetime\") row[field] = now.toISOString();\n }\n return row;\n}\n"],"mappings":";;AAsBA,IAAa,QAAQ,MAAW,EAAE,OAAO;AAEzC,SAAgB,SAAS,KAAU,MAAwD;CACzF,MAAM,IAAI,IAAI,KAAK;CACnB,OAAO,OAAO,MAAM,YAAY,MAAM,KAAK,IAAI;AACjD;AAEA,SAAgB,SAAS,KAAsB,OAA0C;CACvF,IAAI,CAAC,OAAO,CAAC,OAAO,OAAO;CAC3B,MAAM,IAAI,IAAI;CACd,MAAM,IAAI,OAAO,MAAM,WAAW,IAAI,OAAO,MAAM,YAAY,MAAM,KAAK,OAAO,CAAC,IAAI;CACtF,OAAO,OAAO,SAAS,CAAC,IAAI,IAAI;AAClC;AAEA,IAAM,WAAW,MAAe,MAAM,QAAQ,MAAM,KAAA,KAAa,MAAM;AAEvE,SAAS,QAAQ,GAAY,GAAoB;CAC/C,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU,OAAO,IAAI;CAC/D,OAAO,OAAO,CAAC,CAAC,CAAC,cAAc,OAAO,CAAC,CAAC;AAC1C;;AAGA,SAAgB,aAAa,MAAsB,MAA0C;CAC3F,OAAO,CAAC,GAAG,IAAI,CAAC,CAA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B,QAAQ;EAC7D,QAAQ,mBAAmB,IAAI;CACjC;AACF;AAIA,IAAa,eAAe;CAAE,MAAM;CAAO,UAAU;AAAK;;;;;;;AAQ1D,SAAgB,SACd,MACA,QACA,QACA,UACA,MACA,KACyB;CACzB,MAAM,QAAQ,MAA2B,KAAK,OAAO,OAAO,EAAE,EAAE,YAAY,OAAO,IAAI,KAAA;CACvF,MAAM,SAAS,SACZ,KAAK,MAAM,SAAS,GAAG,KAAK,WAAW,CAAC,CAAC,CACzC,QAAQ,MAAmB,MAAM,IAAI;CACxC,MAAM,MAA+B;GAClC,KAAK,eAAe,KAAK,MAAM;GAC/B,KAAK,cAAc;GACnB,KAAK,eAAe,OAAO,SAAS,KAAK,IAAI,GAAG,MAAM,IAAI,KAAK;CAClE;CACA,MAAM,aAAa,KAAK,KAAK,WAAW;CACxC,IAAI,YAAY,IAAI,eAAe,SAAS,QAAQ,UAAU,KAAK,KAAK;CACxE,MAAM,SAAS,KAAK,KAAK,YAAY;CACrC,IAAI,QAAQ,IAAI,UAAU,aAAa;CACvC,IAAI,OAAO,OAAO,QAAQ,SAAS,UAAU,IAAI,SAAS,aAAa;CACvE,KAAK,MAAM,EAAE,WAAW,KAAK,cAC3B,IAAI,OAAO,OAAO,MAAM,EAAE,SAAS,YAAY,IAAI,SAAS,IAAI,YAAY;CAE9E,OAAO;AACT"}
|
package/dist/tree.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./tree/index.js";
|
package/dist/tree.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TreeRenderer } from "./tree/TreeRenderer.js";
|
|
2
|
+
import { ListTree } from "lucide-react";
|
|
3
|
+
// src/tree/index.ts
|
|
4
|
+
/** `createRendererRegistry(treeRenderer, …)`: the `tree` tab. */
|
|
5
|
+
var treeRenderer = {
|
|
6
|
+
name: "tree",
|
|
7
|
+
component: TreeRenderer,
|
|
8
|
+
icon: ListTree,
|
|
9
|
+
labelKey: "TAB_TREE",
|
|
10
|
+
paging: false,
|
|
11
|
+
editMode: false
|
|
12
|
+
};
|
|
13
|
+
export { TreeRenderer, treeRenderer };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=tree.js.map
|
package/dist/tree.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.js","names":[],"sources":["../src/tree/index.ts"],"sourcesContent":["// @jsudc/react/tree: the tree renderer. Needs the `@dnd-kit/core` peer (drag to reparent).\nimport { ListTree } from \"lucide-react\";\nimport type { RendererDefinition } from \"../renderers/types.js\";\nimport { TreeRenderer } from \"./TreeRenderer.js\";\n\nexport { TreeRenderer } from \"./TreeRenderer.js\";\n\n/** `createRendererRegistry(treeRenderer, …)`: the `tree` tab. */\nexport const treeRenderer: RendererDefinition = {\n name: \"tree\",\n component: TreeRenderer,\n icon: ListTree,\n labelKey: \"TAB_TREE\",\n paging: false,\n editMode: false,\n};\n"],"mappings":";;;;AAQA,IAAa,eAAmC;CAC9C,MAAM;CACN,WAAW;CACX,MAAM;CACN,UAAU;CACV,QAAQ;CACR,UAAU;AACZ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { UdcClient } from "@jsudc/core/client";
|
|
2
|
+
import { QueryClient } from "@tanstack/react-query";
|
|
3
|
+
/** The client every hook talks to; `UdcProvider` sets it. */
|
|
4
|
+
export declare const UdcClientContext: import("react").Context<UdcClient | null>;
|
|
5
|
+
export declare function useUdcClient(): UdcClient;
|
|
6
|
+
/**
|
|
7
|
+
* A protocol error is the server's answer, not a hiccup: asking again gives
|
|
8
|
+
* the same answer. Only transport failures are retried, twice.
|
|
9
|
+
*/
|
|
10
|
+
export declare function shouldRetry(failureCount: number, error: unknown): boolean;
|
|
11
|
+
export declare function createUdcQueryClient(): QueryClient;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
import { isUdcError } from "@jsudc/core";
|
|
3
|
+
import { QueryClient } from "@tanstack/react-query";
|
|
4
|
+
// src/udc/client.ts
|
|
5
|
+
/** The client every hook talks to; `UdcProvider` sets it. */
|
|
6
|
+
var UdcClientContext = createContext(null);
|
|
7
|
+
function useUdcClient() {
|
|
8
|
+
const client = useContext(UdcClientContext);
|
|
9
|
+
if (!client) throw new Error("useUdcClient needs a <UdcProvider client={...}> above it");
|
|
10
|
+
return client;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A protocol error is the server's answer, not a hiccup: asking again gives
|
|
14
|
+
* the same answer. Only transport failures are retried, twice.
|
|
15
|
+
*/
|
|
16
|
+
function shouldRetry(failureCount, error) {
|
|
17
|
+
return !isUdcError(error) && failureCount < 2;
|
|
18
|
+
}
|
|
19
|
+
function createUdcQueryClient() {
|
|
20
|
+
return new QueryClient({ defaultOptions: {
|
|
21
|
+
queries: {
|
|
22
|
+
retry: shouldRetry,
|
|
23
|
+
refetchOnWindowFocus: false
|
|
24
|
+
},
|
|
25
|
+
mutations: { retry: false }
|
|
26
|
+
} });
|
|
27
|
+
}
|
|
28
|
+
export { UdcClientContext, createUdcQueryClient, shouldRetry, useUdcClient };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../../src/udc/client.ts"],"sourcesContent":["import { isUdcError } from \"@jsudc/core\";\nimport type { UdcClient } from \"@jsudc/core/client\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { createContext, useContext } from \"react\";\n\n/** The client every hook talks to; `UdcProvider` sets it. */\nexport const UdcClientContext = createContext<UdcClient | null>(null);\n\nexport function useUdcClient(): UdcClient {\n const client = useContext(UdcClientContext);\n if (!client) throw new Error(\"useUdcClient needs a <UdcProvider client={...}> above it\");\n return client;\n}\n\n/**\n * A protocol error is the server's answer, not a hiccup: asking again gives\n * the same answer. Only transport failures are retried, twice.\n */\nexport function shouldRetry(failureCount: number, error: unknown): boolean {\n return !isUdcError(error) && failureCount < 2;\n}\n\nexport function createUdcQueryClient(): QueryClient {\n return new QueryClient({\n defaultOptions: {\n queries: { retry: shouldRetry, refetchOnWindowFocus: false },\n mutations: { retry: false },\n },\n });\n}\n"],"mappings":";;;;;AAMA,IAAa,mBAAmB,cAAgC,IAAI;AAEpE,SAAgB,eAA0B;CACxC,MAAM,SAAS,WAAW,gBAAgB;CAC1C,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,0DAA0D;CACvF,OAAO;AACT;;;;;AAMA,SAAgB,YAAY,cAAsB,OAAyB;CACzE,OAAO,CAAC,WAAW,KAAK,KAAK,eAAe;AAC9C;AAEA,SAAgB,uBAAoC;CAClD,OAAO,IAAI,YAAY,EACrB,gBAAgB;EACd,SAAS;GAAE,OAAO;GAAa,sBAAsB;EAAM;EAC3D,WAAW,EAAE,OAAO,MAAM;CAC5B,EACF,CAAC;AACH"}
|