@sincpro/web-framework 3.17.0 → 3.19.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 +76 -54
- package/dist/core/copy.d.ts +2 -0
- package/dist/core/copy.js +6 -2
- package/dist/core/explain.d.ts +4 -0
- package/dist/core/explain.js +4 -0
- package/dist/core/groups.d.ts +3 -1
- package/dist/core/groups.js +10 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/lines.d.ts +10 -0
- package/dist/core/lines.js +24 -0
- package/dist/core/list.d.ts +12 -0
- package/dist/react/context.d.ts +29 -0
- package/dist/react/context.js +46 -0
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +2 -2
- package/dist/react/useGroups.d.ts +6 -0
- package/dist/react/useGroups.js +84 -11
- package/dist/react/useNameOf.d.ts +13 -0
- package/dist/react/useNameOf.js +32 -0
- package/dist/react/useServiceReading.d.ts +8 -0
- package/dist/react/useServiceReading.js +12 -2
- package/dist/web/index.d.ts +4 -2
- package/dist/web/index.js +4 -2
- package/dist/web/list/EntityList.d.ts +36 -177
- package/dist/web/list/EntityList.js +175 -529
- package/dist/web/list/entityList/choosing.d.ts +50 -0
- package/dist/web/list/entityList/choosing.js +77 -0
- package/dist/web/list/entityList/faces.d.ts +53 -0
- package/dist/web/list/entityList/faces.js +155 -0
- package/dist/web/list/entityList/grouping.d.ts +50 -0
- package/dist/web/list/entityList/grouping.js +97 -0
- package/dist/web/list/entityList/opening.d.ts +68 -0
- package/dist/web/list/entityList/opening.js +144 -0
- package/dist/web/list/entityList/paging.d.ts +30 -0
- package/dist/web/list/entityList/paging.js +39 -0
- package/dist/web/list/entityList/props.d.ts +173 -0
- package/dist/web/list/entityList/props.js +16 -0
- package/dist/web/list/entityList/rowActions.d.ts +31 -0
- package/dist/web/list/entityList/rowActions.js +40 -0
- package/dist/web/list/groups.d.ts +17 -1
- package/dist/web/list/groups.js +43 -0
- package/dist/web/list/useEntityList.d.ts +183 -0
- package/dist/web/list/useEntityList.js +225 -0
- package/dist/web/parts.d.ts +42 -0
- package/dist/web/parts.js +88 -0
- package/dist/web/record/lines.d.ts +3 -0
- package/dist/web/record/lines.js +75 -9
- package/dist/web/workspace/RecordScreen.d.ts +156 -0
- package/dist/web/workspace/RecordScreen.js +197 -0
- package/dist/web/workspace/SincproApp.d.ts +3 -1
- package/dist/web/workspace/SincproApp.js +22 -4
- package/dist/web/workspace/composer.js +1 -1
- package/dist/web/workspace/record.d.ts +4 -22
- package/dist/web/workspace/record.js +5 -70
- package/package.json +3 -3
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { type CommandBodies } from "@sincpro/client-framework";
|
|
2
|
+
import { type AnyRecord } from "@sincpro/criteria";
|
|
3
|
+
import { type EntityListProps } from "./entityList/props.js";
|
|
4
|
+
export type { EntityEmpty, EntityFace, EntityListProps, NamedFilter, View, } from "./entityList/props.js";
|
|
5
|
+
/**
|
|
6
|
+
* Everything an `EntityList` knows before it draws, as web-ui's PROPS for each region — the
|
|
7
|
+
* regions are drawn by its parts (`EntityList.tsx`).
|
|
8
|
+
*
|
|
9
|
+
* Context: this was the first 600 lines of `EntityList`, every concern mixed with its tree. It is
|
|
10
|
+
* now the composition of one hook per concern, each in `entityList/` and each readable alone:
|
|
11
|
+
*
|
|
12
|
+
* | Concern | Hook |
|
|
13
|
+
* | ----------------------------------------------------- | ------------------- |
|
|
14
|
+
* | why it is open, what is chosen and what is done to it | `useListChoosing` |
|
|
15
|
+
* | what a row does, where its record opens, «Nuevo» | `useListOpening` |
|
|
16
|
+
* | the columns, the sheet, a row's facts, cards, pivot | `useListFaces` |
|
|
17
|
+
* | the groups the server counts, what failed | `useListGrouping` |
|
|
18
|
+
* | the way through the set, the totals at the foot | `useListPaging` |
|
|
19
|
+
* | a row's Commands, the trash, reordering by hand | `useListRowActions` |
|
|
20
|
+
*
|
|
21
|
+
* What the screen asks wins over the named list's (`defineList`), which wins over the entity's
|
|
22
|
+
* own look (`presented`), which wins over the model.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useEntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, yesNo, views: askedViews, title, description, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot, empty, search, recent: askedRecent, sums, filters, facets, groupable, selectable, selection: held, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>,
|
|
25
|
+
/** The faces the screen's tree writes, when it writes one (`EntityList.Table`…). */
|
|
26
|
+
writtenViews?: readonly string[]): {
|
|
27
|
+
listing: import("../../index.js").Listing<T, C>;
|
|
28
|
+
meta: import("@sincpro/criteria").Meta | null;
|
|
29
|
+
locale: string | undefined;
|
|
30
|
+
embedded: boolean;
|
|
31
|
+
views: readonly string[];
|
|
32
|
+
present: string;
|
|
33
|
+
/** web-ui `List`'s own props: the set, its state, its order, its groups, what a row does. */
|
|
34
|
+
root: {
|
|
35
|
+
openTargets?: ("peek" | "modal" | "side" | "window")[] | undefined;
|
|
36
|
+
onOpenIn?: ((row: T, to: import("@sincpro/web-ui").OpenTarget) => void | undefined) | undefined;
|
|
37
|
+
onPeek?: ((row: T) => void) | undefined;
|
|
38
|
+
rowClick?: "open" | undefined;
|
|
39
|
+
onOpen?: ((row: T) => void) | undefined;
|
|
40
|
+
selection?: {
|
|
41
|
+
actions?: string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | import("react").ReactPortal | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | undefined;
|
|
42
|
+
matching?: {
|
|
43
|
+
total: number;
|
|
44
|
+
onSelect: () => void;
|
|
45
|
+
} | undefined;
|
|
46
|
+
has: (key: string) => boolean;
|
|
47
|
+
toggle: (key: string) => void;
|
|
48
|
+
count: number;
|
|
49
|
+
clear: () => void;
|
|
50
|
+
} | undefined;
|
|
51
|
+
onSortChange: (next: readonly {
|
|
52
|
+
key: string;
|
|
53
|
+
direction: "asc" | "desc";
|
|
54
|
+
}[]) => void;
|
|
55
|
+
state: {
|
|
56
|
+
loading: boolean;
|
|
57
|
+
refreshing: boolean;
|
|
58
|
+
error: string | null;
|
|
59
|
+
};
|
|
60
|
+
filtered: boolean;
|
|
61
|
+
empty: import("@sincpro/web-ui").ListEmpty;
|
|
62
|
+
sortable?: {
|
|
63
|
+
field: string;
|
|
64
|
+
label: string;
|
|
65
|
+
}[] | undefined;
|
|
66
|
+
sort: {
|
|
67
|
+
key: string;
|
|
68
|
+
direction: "desc" | "asc";
|
|
69
|
+
}[];
|
|
70
|
+
group: {
|
|
71
|
+
onMorePiles: (parent: import("@sincpro/web-ui").Pile<T> | null) => void;
|
|
72
|
+
morePiles?: number | false | undefined;
|
|
73
|
+
pilesCount?: number | undefined;
|
|
74
|
+
levels: readonly import("../../index.js").GroupLevel[];
|
|
75
|
+
of: (row: T, level: {
|
|
76
|
+
field: string;
|
|
77
|
+
}) => string;
|
|
78
|
+
piles: import("@sincpro/web-ui").Pile<T>[];
|
|
79
|
+
collapsed: string[];
|
|
80
|
+
onToggle: (key: string) => void;
|
|
81
|
+
onMore: (pile: import("@sincpro/web-ui").Pile<T>) => void;
|
|
82
|
+
onPage: (pile: import("@sincpro/web-ui").Pile<T>, step: 1 | -1) => void;
|
|
83
|
+
};
|
|
84
|
+
items: readonly T[];
|
|
85
|
+
keyOf: (row: T) => string;
|
|
86
|
+
embedded: boolean;
|
|
87
|
+
present: string;
|
|
88
|
+
onPresentChange: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
89
|
+
} | {
|
|
90
|
+
openTargets?: ("peek" | "modal" | "side" | "window")[] | undefined;
|
|
91
|
+
onOpenIn?: ((row: T, to: import("@sincpro/web-ui").OpenTarget) => void | undefined) | undefined;
|
|
92
|
+
onPeek?: ((row: T) => void) | undefined;
|
|
93
|
+
rowClick?: "open" | undefined;
|
|
94
|
+
onOpen?: ((row: T) => void) | undefined;
|
|
95
|
+
selection?: {
|
|
96
|
+
actions?: string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | import("react").ReactPortal | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | undefined;
|
|
97
|
+
matching?: {
|
|
98
|
+
total: number;
|
|
99
|
+
onSelect: () => void;
|
|
100
|
+
} | undefined;
|
|
101
|
+
has: (key: string) => boolean;
|
|
102
|
+
toggle: (key: string) => void;
|
|
103
|
+
count: number;
|
|
104
|
+
clear: () => void;
|
|
105
|
+
} | undefined;
|
|
106
|
+
onSortChange: (next: readonly {
|
|
107
|
+
key: string;
|
|
108
|
+
direction: "asc" | "desc";
|
|
109
|
+
}[]) => void;
|
|
110
|
+
state: {
|
|
111
|
+
loading: boolean;
|
|
112
|
+
refreshing: boolean;
|
|
113
|
+
error: string | null;
|
|
114
|
+
};
|
|
115
|
+
filtered: boolean;
|
|
116
|
+
empty: import("@sincpro/web-ui").ListEmpty;
|
|
117
|
+
sortable?: {
|
|
118
|
+
field: string;
|
|
119
|
+
label: string;
|
|
120
|
+
}[] | undefined;
|
|
121
|
+
sort: {
|
|
122
|
+
key: string;
|
|
123
|
+
direction: "desc" | "asc";
|
|
124
|
+
}[];
|
|
125
|
+
group?: undefined;
|
|
126
|
+
items: readonly T[];
|
|
127
|
+
keyOf: (row: T) => string;
|
|
128
|
+
embedded: boolean;
|
|
129
|
+
present: string;
|
|
130
|
+
onPresentChange: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
131
|
+
};
|
|
132
|
+
/** The bar's pieces. */
|
|
133
|
+
bar: {
|
|
134
|
+
trail: readonly import("@sincpro/web-ui").ListCrumb[] | undefined;
|
|
135
|
+
title: string;
|
|
136
|
+
description: string | undefined;
|
|
137
|
+
search: false | "bar" | "box";
|
|
138
|
+
filters: readonly import("./entityList/props.js").NamedFilter<T>[];
|
|
139
|
+
groups: import("../../index.js").Groups<T>;
|
|
140
|
+
groupable: readonly string[] | undefined;
|
|
141
|
+
facets: readonly string[] | undefined;
|
|
142
|
+
asked: string;
|
|
143
|
+
recent: string | undefined;
|
|
144
|
+
draft: string;
|
|
145
|
+
setDraft: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
146
|
+
drawn: import("react").ReactNode;
|
|
147
|
+
creating: (() => void) | undefined;
|
|
148
|
+
startDock: readonly import("@sincpro/web-ui").DockAction[];
|
|
149
|
+
chosenDock: readonly import("@sincpro/web-ui").DockAction[];
|
|
150
|
+
paging: import("react").ReactNode;
|
|
151
|
+
};
|
|
152
|
+
/** The faces' pieces: the same set read as a table, rows, a sheet, a pivot, cards, tiles. */
|
|
153
|
+
face: {
|
|
154
|
+
columns: import("@sincpro/web-ui").DataColumn<T>[];
|
|
155
|
+
totalled: boolean;
|
|
156
|
+
rowActions: ((row: T) => import("@sincpro/web-ui").RowAction[]) | undefined;
|
|
157
|
+
reorder: ((id: string, before: string | null) => void) | undefined;
|
|
158
|
+
rowOf: (row: T) => import("@sincpro/web-ui").RowOf;
|
|
159
|
+
sheetColumns: {
|
|
160
|
+
look?: "tag" | undefined;
|
|
161
|
+
numeric?: boolean | undefined;
|
|
162
|
+
id: string;
|
|
163
|
+
header: string;
|
|
164
|
+
}[];
|
|
165
|
+
tones: Readonly<Partial<Record<string | (keyof T & string), Readonly<Record<string, import("@sincpro/web-ui").Tone>>>>> | undefined;
|
|
166
|
+
folded: import("@sincpro/web-ui").Pivot | null;
|
|
167
|
+
cardOfRow: ((row: T, ways: import("@sincpro/web-ui").CardWays) => import("react").JSX.Element) | undefined;
|
|
168
|
+
tileOfRow: ((row: T, ways: import("@sincpro/web-ui").CardWays) => import("react").JSX.Element) | undefined;
|
|
169
|
+
faces: readonly import("./entityList/props.js").EntityFace<T>[];
|
|
170
|
+
};
|
|
171
|
+
/** What happened to a gesture on the list: rows moved elsewhere, a command refused. */
|
|
172
|
+
notices: {
|
|
173
|
+
movedElsewhere: boolean;
|
|
174
|
+
dismissMoved: () => void;
|
|
175
|
+
refused: {
|
|
176
|
+
heading: string;
|
|
177
|
+
sentence: string;
|
|
178
|
+
retryable: boolean;
|
|
179
|
+
} | null;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
/** What a list's root and its parts read. */
|
|
183
|
+
export type EntityListState<T extends AnyRecord = AnyRecord> = ReturnType<typeof useEntityList<T, CommandBodies>>;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { QUERY_PARAM } from "@sincpro/client-framework";
|
|
3
|
+
import { nameOf } from "@sincpro/criteria";
|
|
4
|
+
import { useCrumbs, usePhone } from "@sincpro/web-composer";
|
|
5
|
+
import { frameworkCopy } from "../../core/copy.js";
|
|
6
|
+
import { ownCrumbs } from "../../core/crumbs.js";
|
|
7
|
+
import { purposeOf, useListChoosing, } from "./entityList/choosing.js";
|
|
8
|
+
import { useListFaces } from "./entityList/faces.js";
|
|
9
|
+
import { useListGrouping } from "./entityList/grouping.js";
|
|
10
|
+
import { useListOpening } from "./entityList/opening.js";
|
|
11
|
+
import { useListPaging } from "./entityList/paging.js";
|
|
12
|
+
import { emptyOf, EVERY_VIEW, NO_COMMANDS, } from "./entityList/props.js";
|
|
13
|
+
import { useListRowActions } from "./entityList/rowActions.js";
|
|
14
|
+
import { presentationOf } from "./presentation.js";
|
|
15
|
+
import { useEffect, useState } from "react";
|
|
16
|
+
/** What `useCrumbs` reads when the list is not in a workspace: no trail, and nothing to follow. */
|
|
17
|
+
const NO_TRAIL = [];
|
|
18
|
+
const NO_WORKSPACE = {
|
|
19
|
+
crumbs: () => NO_TRAIL,
|
|
20
|
+
context: { subscribe: () => () => undefined },
|
|
21
|
+
layout: { phone: () => false, subscribe: () => () => undefined },
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Everything an `EntityList` knows before it draws, as web-ui's PROPS for each region — the
|
|
25
|
+
* regions are drawn by its parts (`EntityList.tsx`).
|
|
26
|
+
*
|
|
27
|
+
* Context: this was the first 600 lines of `EntityList`, every concern mixed with its tree. It is
|
|
28
|
+
* now the composition of one hook per concern, each in `entityList/` and each readable alone:
|
|
29
|
+
*
|
|
30
|
+
* | Concern | Hook |
|
|
31
|
+
* | ----------------------------------------------------- | ------------------- |
|
|
32
|
+
* | why it is open, what is chosen and what is done to it | `useListChoosing` |
|
|
33
|
+
* | what a row does, where its record opens, «Nuevo» | `useListOpening` |
|
|
34
|
+
* | the columns, the sheet, a row's facts, cards, pivot | `useListFaces` |
|
|
35
|
+
* | the groups the server counts, what failed | `useListGrouping` |
|
|
36
|
+
* | the way through the set, the totals at the foot | `useListPaging` |
|
|
37
|
+
* | a row's Commands, the trash, reordering by hand | `useListRowActions` |
|
|
38
|
+
*
|
|
39
|
+
* What the screen asks wins over the named list's (`defineList`), which wins over the entity's
|
|
40
|
+
* own look (`presented`), which wins over the model.
|
|
41
|
+
*/
|
|
42
|
+
export function useEntityList({ listing, api, columns: askedColumns, cells, yesNo, views: askedViews, title, description, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot, empty, search = "bar", recent: askedRecent = false, sums, filters, facets, groupable, selectable = false, selection: held, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, },
|
|
43
|
+
/** The faces the screen's tree writes, when it writes one (`EntityList.Table`…). */
|
|
44
|
+
writtenViews) {
|
|
45
|
+
// 1. What the screen asked, over the named list's and the entity's.
|
|
46
|
+
const definition = listing.definition;
|
|
47
|
+
const columns = askedColumns ?? definition?.columns ?? presentationOf(listing.entity).columns;
|
|
48
|
+
const views = askedViews ??
|
|
49
|
+
writtenViews ??
|
|
50
|
+
definition?.views ??
|
|
51
|
+
(embedded ? ["table"] : pivot === undefined ? EVERY_VIEW : [...EVERY_VIEW, "pivot"]);
|
|
52
|
+
const recent = askedRecent === false
|
|
53
|
+
? undefined
|
|
54
|
+
: askedRecent === true
|
|
55
|
+
? (definition?.key ?? listing.entity.kind)
|
|
56
|
+
: askedRecent;
|
|
57
|
+
const { meta, locale } = listing;
|
|
58
|
+
const identity = meta?.identity ?? "id";
|
|
59
|
+
const idOf = (row) => String(row[identity]);
|
|
60
|
+
const [present, setPresent] = useState(views[0] ?? "table");
|
|
61
|
+
// 2. The box search: opened to choose on what was typed in a picker (`chooserRef(query)`), it
|
|
62
|
+
// starts searched; then its text is a draft until Enter — typing asks the server nothing.
|
|
63
|
+
const asked = api?.self.params?.[QUERY_PARAM] ?? "";
|
|
64
|
+
const [draft, setDraft] = useState(asked === "" ? listing.text : asked);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (asked !== "" && search === "box")
|
|
67
|
+
listing.search(asked, { now: true });
|
|
68
|
+
// Once, as it opens: what the person types next is theirs.
|
|
69
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
70
|
+
}, []);
|
|
71
|
+
// 3. Why it is open, and what is chosen.
|
|
72
|
+
const { choosing, choosingMany } = purposeOf(api);
|
|
73
|
+
const chosen = useListChoosing({
|
|
74
|
+
listing,
|
|
75
|
+
api,
|
|
76
|
+
idOf,
|
|
77
|
+
held,
|
|
78
|
+
selectable,
|
|
79
|
+
selectionActions,
|
|
80
|
+
choosingMany,
|
|
81
|
+
});
|
|
82
|
+
// 4. What a row does and where its record opens.
|
|
83
|
+
const opening = useListOpening({
|
|
84
|
+
listing,
|
|
85
|
+
api,
|
|
86
|
+
idOf,
|
|
87
|
+
chosen: chosen.chosen,
|
|
88
|
+
choosing,
|
|
89
|
+
choosingMany,
|
|
90
|
+
embedded,
|
|
91
|
+
create,
|
|
92
|
+
actions,
|
|
93
|
+
onOpen,
|
|
94
|
+
onPeek,
|
|
95
|
+
openTargets,
|
|
96
|
+
onOpenIn,
|
|
97
|
+
});
|
|
98
|
+
// `useCrumbs`, not `api.crumbs()`: the crumb must follow a name given later (`setTitle`).
|
|
99
|
+
// Without a workspace it reads a trail that never changes — a hook cannot be skipped.
|
|
100
|
+
const following = useCrumbs(api ?? NO_WORKSPACE);
|
|
101
|
+
usePhone(api ?? NO_WORKSPACE); // where a row opens follows the mode (`targetsFor`)
|
|
102
|
+
// The workspace's crumbs say each view's whole name; in the trail a crumb says only what is
|
|
103
|
+
// its own — «Pagos», not «Pagos · María Fernanda» under «María Fernanda».
|
|
104
|
+
const trail = crumbs ?? (embedded || api === undefined ? undefined : ownCrumbs(following));
|
|
105
|
+
// 5. The set read several ways, grouped, and walked through.
|
|
106
|
+
const face = useListFaces({
|
|
107
|
+
listing,
|
|
108
|
+
api,
|
|
109
|
+
idOf,
|
|
110
|
+
columns,
|
|
111
|
+
cells,
|
|
112
|
+
yesNo,
|
|
113
|
+
choosing,
|
|
114
|
+
refOf: opening.refOf,
|
|
115
|
+
elsewhere: opening.elsewhere,
|
|
116
|
+
opens: opening.opens,
|
|
117
|
+
openInOf: opening.openInOf,
|
|
118
|
+
present,
|
|
119
|
+
views,
|
|
120
|
+
pivot,
|
|
121
|
+
});
|
|
122
|
+
const grouping = useListGrouping({ listing, sums, columns: face.columns, present });
|
|
123
|
+
const { totalled, paging } = useListPaging({
|
|
124
|
+
listing,
|
|
125
|
+
groups: grouping.groups,
|
|
126
|
+
grouped: grouping.grouped,
|
|
127
|
+
records: grouping.records,
|
|
128
|
+
columns: face.columns,
|
|
129
|
+
embedded,
|
|
130
|
+
present,
|
|
131
|
+
});
|
|
132
|
+
// 6. What can be done to a row.
|
|
133
|
+
const rows = useListRowActions({
|
|
134
|
+
listing,
|
|
135
|
+
idOf,
|
|
136
|
+
commands,
|
|
137
|
+
rowActions: askedRowActions,
|
|
138
|
+
grouped: grouping.grouped,
|
|
139
|
+
choosing,
|
|
140
|
+
});
|
|
141
|
+
const { groups, grouped, failure } = grouping;
|
|
142
|
+
return {
|
|
143
|
+
listing,
|
|
144
|
+
meta,
|
|
145
|
+
locale,
|
|
146
|
+
embedded,
|
|
147
|
+
views,
|
|
148
|
+
present,
|
|
149
|
+
/** web-ui `List`'s own props: the set, its state, its order, its groups, what a row does. */
|
|
150
|
+
root: {
|
|
151
|
+
items: rows.reorder.rows,
|
|
152
|
+
keyOf: idOf,
|
|
153
|
+
embedded,
|
|
154
|
+
present,
|
|
155
|
+
onPresentChange: setPresent,
|
|
156
|
+
...grouping.grouping,
|
|
157
|
+
// The whole order, as web-ui shows and sets it: ⇧-click on a header adds a field, the sort
|
|
158
|
+
// menu reorders them — the same list the criteria builder writes. While the rows can be
|
|
159
|
+
// dragged the order shown IS their position: no column sort.
|
|
160
|
+
sort: rows.reorder.move === undefined ? face.sortStates : [],
|
|
161
|
+
// The faces with no headers sort too, on the server. Not inside a record or a panel: a
|
|
162
|
+
// handful of rows has no «Ordenar» to offer, and the table's headers still sort.
|
|
163
|
+
...(embedded ? {} : { sortable: face.sortable }),
|
|
164
|
+
onSortChange: (next) => listing.orderBy(next.map((one) => ({ field: one.key, descending: one.direction === "desc" }))),
|
|
165
|
+
state: {
|
|
166
|
+
// Only the FIRST reading shows the skeleton. Refining keeps the rows on screen until the
|
|
167
|
+
// server answers — a row that vanished under the pointer lost a click — and `refreshing`
|
|
168
|
+
// draws a quiet bar over them: asking, not gone.
|
|
169
|
+
loading: grouped
|
|
170
|
+
? groups.status === "loading" && groups.buckets.length === 0
|
|
171
|
+
: listing.status === "loading" && listing.rows.length === 0,
|
|
172
|
+
refreshing: grouped
|
|
173
|
+
? groups.status === "loading" && groups.buckets.length > 0
|
|
174
|
+
: listing.status === "loading" && listing.rows.length > 0,
|
|
175
|
+
error: failure === null
|
|
176
|
+
? null
|
|
177
|
+
: [failure.heading, failure.sentence].filter(Boolean).join(". "),
|
|
178
|
+
},
|
|
179
|
+
filtered: listing.selection !== undefined || listing.text !== "",
|
|
180
|
+
empty: emptyOf(empty, frameworkCopy().list),
|
|
181
|
+
...(chosen.selection === undefined ? {} : { selection: chosen.selection }),
|
|
182
|
+
...opening.ways,
|
|
183
|
+
},
|
|
184
|
+
/** The bar's pieces. */
|
|
185
|
+
bar: {
|
|
186
|
+
trail,
|
|
187
|
+
title: title ?? definition?.title ?? nameOf(meta, locale),
|
|
188
|
+
description: description ?? definition?.description,
|
|
189
|
+
search,
|
|
190
|
+
filters: filters ?? definition?.filters ?? [],
|
|
191
|
+
groups,
|
|
192
|
+
groupable: groupable ?? definition?.groupable,
|
|
193
|
+
facets: facets ?? definition?.facets,
|
|
194
|
+
asked,
|
|
195
|
+
recent,
|
|
196
|
+
draft,
|
|
197
|
+
setDraft,
|
|
198
|
+
drawn: opening.started.drawn,
|
|
199
|
+
creating: opening.started.creating,
|
|
200
|
+
startDock: opening.started.dock,
|
|
201
|
+
chosenDock: chosen.dock,
|
|
202
|
+
paging,
|
|
203
|
+
},
|
|
204
|
+
/** The faces' pieces: the same set read as a table, rows, a sheet, a pivot, cards, tiles. */
|
|
205
|
+
face: {
|
|
206
|
+
columns: face.columns,
|
|
207
|
+
totalled,
|
|
208
|
+
rowActions: rows.rowActions,
|
|
209
|
+
reorder: rows.reorder.move,
|
|
210
|
+
rowOf: face.rowOf,
|
|
211
|
+
sheetColumns: face.sheetColumns,
|
|
212
|
+
tones: face.tones,
|
|
213
|
+
folded: face.folded,
|
|
214
|
+
cardOfRow: face.cardOfRow,
|
|
215
|
+
tileOfRow: face.tileOfRow,
|
|
216
|
+
faces: faces ?? [],
|
|
217
|
+
},
|
|
218
|
+
/** What happened to a gesture on the list: rows moved elsewhere, a command refused. */
|
|
219
|
+
notices: {
|
|
220
|
+
movedElsewhere: rows.reorder.elsewhere,
|
|
221
|
+
dismissMoved: rows.reorder.dismiss,
|
|
222
|
+
refused: rows.refused,
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* The parts of a screen piece: how `RecordScreen.*` and `EntityList.*` reach web-ui's slots.
|
|
4
|
+
*
|
|
5
|
+
* Context: web-ui's archetypes (`Record`, `List`) read their slots as DATA, by a mark on the
|
|
6
|
+
* element (`__slot`), and a slot wrapped in a component of ours is never found. So a part that
|
|
7
|
+
* becomes a slot draws nothing itself: it is a mark with a `resolve` function, and the root of
|
|
8
|
+
* the piece replaces it by web-ui's slot — filled from the root's state — before handing the tree
|
|
9
|
+
* to web-ui. Everything that is not a part passes as it was written: web-ui's own slots, and the
|
|
10
|
+
* application's components, which draw themselves and read the root by its hook.
|
|
11
|
+
*
|
|
12
|
+
* const Pager = part<NoProps, ListState>("EntityList.Pager", (_props, state) =>
|
|
13
|
+
* state.paging === null ? null : <List.Pagination>{state.paging}</List.Pagination>);
|
|
14
|
+
*
|
|
15
|
+
* <List …>{resolveParts(children, state)}</List>
|
|
16
|
+
*/
|
|
17
|
+
declare const RESOLVE: unique symbol;
|
|
18
|
+
/** A part that takes nothing: what it draws is its root's. */
|
|
19
|
+
export type NoProps = {
|
|
20
|
+
children?: never;
|
|
21
|
+
};
|
|
22
|
+
/** A part of a screen piece, resolved by its root against the root's state `S`. Drawn by React
|
|
23
|
+
* itself — never resolved — it throws. */
|
|
24
|
+
export type Part<P, S> = ((props: P) => null) & {
|
|
25
|
+
[RESOLVE]: (props: P, state: S) => ReactNode;
|
|
26
|
+
/** What kind of part it is, when the root must know before resolving (a list's faces). */
|
|
27
|
+
kind?: string;
|
|
28
|
+
displayName: string;
|
|
29
|
+
};
|
|
30
|
+
/** Marks a part: `name` is how it reads in React's tools, `resolve` what it becomes. */
|
|
31
|
+
export declare function part<P, S>(name: string, resolve: (props: P, state: S) => ReactNode, kind?: string): Part<P, S>;
|
|
32
|
+
/** The kinds of the parts written at the top of a tree, fragments opened, in order. */
|
|
33
|
+
export declare function kindsIn(children: ReactNode): string[];
|
|
34
|
+
/**
|
|
35
|
+
* The tree as web-ui reads it: each part replaced by what it resolves to, and the children of
|
|
36
|
+
* any web-ui slot that carries a tree (`Record.Paper`, `List.Bar`) resolved in turn. Fragments
|
|
37
|
+
* are opened, so two parts under one condition are still found.
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveParts<S>(children: ReactNode, state: S): ReactNode[];
|
|
40
|
+
/** What a resolved tree really holds: nothing that draws nothing. */
|
|
41
|
+
export declare function written(nodes: readonly ReactNode[]): ReactNode[];
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Children, cloneElement, Fragment, isValidElement, } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* The parts of a screen piece: how `RecordScreen.*` and `EntityList.*` reach web-ui's slots.
|
|
4
|
+
*
|
|
5
|
+
* Context: web-ui's archetypes (`Record`, `List`) read their slots as DATA, by a mark on the
|
|
6
|
+
* element (`__slot`), and a slot wrapped in a component of ours is never found. So a part that
|
|
7
|
+
* becomes a slot draws nothing itself: it is a mark with a `resolve` function, and the root of
|
|
8
|
+
* the piece replaces it by web-ui's slot — filled from the root's state — before handing the tree
|
|
9
|
+
* to web-ui. Everything that is not a part passes as it was written: web-ui's own slots, and the
|
|
10
|
+
* application's components, which draw themselves and read the root by its hook.
|
|
11
|
+
*
|
|
12
|
+
* const Pager = part<NoProps, ListState>("EntityList.Pager", (_props, state) =>
|
|
13
|
+
* state.paging === null ? null : <List.Pagination>{state.paging}</List.Pagination>);
|
|
14
|
+
*
|
|
15
|
+
* <List …>{resolveParts(children, state)}</List>
|
|
16
|
+
*/
|
|
17
|
+
const RESOLVE = Symbol("part");
|
|
18
|
+
/** Marks a part: `name` is how it reads in React's tools, `resolve` what it becomes. */
|
|
19
|
+
export function part(name, resolve, kind) {
|
|
20
|
+
// Drawn by React means no root resolved it: written outside its root, or inside a component
|
|
21
|
+
// of the application's that hides it from the root. web-ui would never find it either, so it
|
|
22
|
+
// says so — an anchor that does not exist is an error, never a silent gap (MANIFESTO).
|
|
23
|
+
const marked = (() => {
|
|
24
|
+
throw new Error(`${name} is drawn by its root: write it inside one — directly, or inside one of its parts.`);
|
|
25
|
+
});
|
|
26
|
+
marked[RESOLVE] = resolve;
|
|
27
|
+
marked.displayName = name;
|
|
28
|
+
if (kind !== undefined)
|
|
29
|
+
marked.kind = kind;
|
|
30
|
+
return marked;
|
|
31
|
+
}
|
|
32
|
+
function partOf(node) {
|
|
33
|
+
const type = node.type;
|
|
34
|
+
return typeof type === "string" || type[RESOLVE] === undefined
|
|
35
|
+
? undefined
|
|
36
|
+
: type;
|
|
37
|
+
}
|
|
38
|
+
/** The kinds of the parts written at the top of a tree, fragments opened, in order. */
|
|
39
|
+
export function kindsIn(children) {
|
|
40
|
+
const kinds = [];
|
|
41
|
+
Children.toArray(children).forEach((child) => {
|
|
42
|
+
if (!isValidElement(child))
|
|
43
|
+
return;
|
|
44
|
+
if (child.type === Fragment) {
|
|
45
|
+
kinds.push(...kindsIn(child.props.children));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const kind = partOf(child)?.kind;
|
|
49
|
+
if (kind !== undefined)
|
|
50
|
+
kinds.push(kind);
|
|
51
|
+
});
|
|
52
|
+
return kinds;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The tree as web-ui reads it: each part replaced by what it resolves to, and the children of
|
|
56
|
+
* any web-ui slot that carries a tree (`Record.Paper`, `List.Bar`) resolved in turn. Fragments
|
|
57
|
+
* are opened, so two parts under one condition are still found.
|
|
58
|
+
*/
|
|
59
|
+
export function resolveParts(children, state) {
|
|
60
|
+
const out = [];
|
|
61
|
+
Children.toArray(children).forEach((child) => {
|
|
62
|
+
if (!isValidElement(child)) {
|
|
63
|
+
out.push(child);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (child.type === Fragment) {
|
|
67
|
+
out.push(...resolveParts(child.props.children, state));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const found = partOf(child);
|
|
71
|
+
if (found !== undefined) {
|
|
72
|
+
// The written key goes in front: two parts of the same kind stay apart.
|
|
73
|
+
out.push(...Children.toArray(found[RESOLVE](child.props, state)).map((one) => isValidElement(one) ? cloneElement(one, { key: `${child.key}${one.key}` }) : one));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const slotted = child.type.__slot !== undefined;
|
|
77
|
+
const inner = child.props.children;
|
|
78
|
+
// A slot whose child is a render function (`List.Present`) has no tree to resolve.
|
|
79
|
+
out.push(slotted && inner !== undefined && typeof inner !== "function"
|
|
80
|
+
? cloneElement(child, undefined, ...resolveParts(inner, state))
|
|
81
|
+
: child);
|
|
82
|
+
});
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
/** What a resolved tree really holds: nothing that draws nothing. */
|
|
86
|
+
export function written(nodes) {
|
|
87
|
+
return nodes.filter((node) => node !== null && node !== undefined && node !== false);
|
|
88
|
+
}
|
|
@@ -47,6 +47,9 @@ export type LinesLook = {
|
|
|
47
47
|
controls?: Readonly<Partial<Record<string, (control: LineControl) => ReactNode>>>;
|
|
48
48
|
/** Columns that are not fields, after the fields. */
|
|
49
49
|
extra?: readonly LineColumn[];
|
|
50
|
+
/** The many2one «Agregar varios…» fills, one new line per record chosen. Without it, the
|
|
51
|
+
* line's only to-one relation a person writes (`addManyOf`); `false`: not offered. */
|
|
52
|
+
addMany?: string | false;
|
|
50
53
|
/** The whole line's dialog, the screen's way. */
|
|
51
54
|
editor?: (draft: AnyRecord, set: (next: AnyRecord) => void, state: LineEditorState) => ReactNode;
|
|
52
55
|
};
|