@sincpro/web-framework 0.4.2 → 1.1.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 +82 -41
- package/dist/codegen/cli.d.ts +2 -0
- package/dist/codegen/cli.js +82 -0
- package/dist/codegen/client.d.ts +14 -0
- package/dist/codegen/client.js +178 -0
- package/dist/codegen/domain.d.ts +14 -0
- package/dist/codegen/domain.js +195 -0
- package/dist/codegen/entities.d.ts +14 -0
- package/dist/codegen/entities.js +158 -0
- package/dist/codegen/index.d.ts +11 -0
- package/dist/codegen/index.js +9 -0
- package/dist/codegen/metamodel.d.ts +89 -0
- package/dist/codegen/metamodel.js +1 -0
- package/dist/codegen/names.d.ts +40 -0
- package/dist/codegen/names.js +114 -0
- package/dist/codegen/rest.d.ts +31 -0
- package/dist/codegen/rest.js +27 -0
- package/dist/core/cache.js +7 -0
- package/dist/core/contract.d.ts +34 -0
- package/dist/core/contract.js +41 -0
- package/dist/core/discovery.d.ts +47 -0
- package/dist/core/discovery.js +68 -0
- package/dist/core/edit.d.ts +35 -6
- package/dist/core/edit.js +57 -4
- package/dist/core/entity.d.ts +77 -9
- package/dist/core/entity.js +51 -6
- package/dist/core/index.d.ts +5 -4
- package/dist/core/index.js +5 -4
- package/dist/core/memory.d.ts +3 -0
- package/dist/core/memory.js +9 -0
- package/dist/core/meta.d.ts +7 -0
- package/dist/core/meta.js +1 -1
- package/dist/core/metas.d.ts +4 -5
- package/dist/core/relation.d.ts +11 -1
- package/dist/core/relation.js +30 -2
- package/dist/core/rest.d.ts +23 -0
- package/dist/core/rest.js +78 -3
- package/dist/core/schema.d.ts +5 -12
- package/dist/core/trail.js +1 -4
- package/dist/core/transport.d.ts +11 -0
- package/dist/core/transport.js +9 -0
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +1 -0
- package/dist/react/useCommand.d.ts +15 -5
- package/dist/react/useCommand.js +7 -4
- package/dist/react/useGroups.js +1 -2
- package/dist/react/useHistory.js +1 -1
- package/dist/react/useListing.d.ts +5 -4
- package/dist/react/useListing.js +9 -8
- package/dist/react/useLookup.js +2 -3
- package/dist/react/useNameOf.d.ts +13 -0
- package/dist/react/useNameOf.js +44 -0
- package/dist/react/usePivot.js +0 -1
- package/dist/react/useRecord.d.ts +2 -1
- package/dist/react/useRecord.js +15 -3
- package/dist/react/useRelated.js +2 -2
- package/dist/web/list/EntityList.d.ts +5 -4
- package/dist/web/list/EntityList.js +1 -1
- package/dist/web/list/EntitySearchBar.js +2 -2
- package/dist/web/list/presentation.d.ts +3 -3
- package/dist/web/list/presentation.js +1 -0
- package/dist/web/list/rowCommands.d.ts +16 -12
- package/dist/web/list/rowCommands.js +3 -2
- package/dist/web/list/search.js +1 -1
- package/dist/web/record/CommandButton.d.ts +9 -6
- package/dist/web/record/edit.js +19 -7
- package/dist/web/record/lines.js +23 -10
- package/dist/web/record/opening.js +1 -1
- package/dist/web/workspace/composer.js +1 -4
- package/package.json +18 -7
package/dist/react/useLookup.js
CHANGED
|
@@ -12,7 +12,7 @@ export function excluding(criteria, exclude, meta) {
|
|
|
12
12
|
if (exclude === undefined || exclude.length === 0 || meta == null)
|
|
13
13
|
return criteria;
|
|
14
14
|
const out = {
|
|
15
|
-
|
|
15
|
+
selection: {
|
|
16
16
|
field: meta.get_id || meta.identity || "id",
|
|
17
17
|
operator: "not in",
|
|
18
18
|
value: [...exclude],
|
|
@@ -64,11 +64,10 @@ entity, options = {}) {
|
|
|
64
64
|
const aborter = new AbortController();
|
|
65
65
|
transport
|
|
66
66
|
.list(route, {
|
|
67
|
-
|
|
67
|
+
selection: keys.length === 1
|
|
68
68
|
? { field: key, operator: "=", value: keys[0] ?? "" }
|
|
69
69
|
: { field: key, operator: "in", value: keys },
|
|
70
70
|
pagination: { limit: keys.length },
|
|
71
|
-
meta: false,
|
|
72
71
|
}, aborter.signal)
|
|
73
72
|
.then((page) => {
|
|
74
73
|
for (const one of lookupOf(meta, page.rows, base.summary))
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Entity } from "../core/entity.js";
|
|
2
|
+
/**
|
|
3
|
+
* The name of one record of an entity, by its key — what a field shows when it holds only the
|
|
4
|
+
* key (`EntityID[Tenant]`) and not the record it points at.
|
|
5
|
+
*
|
|
6
|
+
* Context: asked ONCE by key, the way `useLookup` names a chosen record it never saw: a page
|
|
7
|
+
* narrowed to that key, one row, read with the definition the application knows. Unnamed is no
|
|
8
|
+
* error — the field shows the key — and an entity listed under another record
|
|
9
|
+
* (`/tenants/{tenant_id}/members`) has no list to ask by key, so it stays unnamed.
|
|
10
|
+
*
|
|
11
|
+
* const name = useNameOf(tenants, record.tenant_id) ?? record.tenant_id;
|
|
12
|
+
*/
|
|
13
|
+
export declare function useNameOf(entity: Entity | undefined, id: string): string | undefined;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { listRoute } from "../core/entity.js";
|
|
3
|
+
import { lookupOf } from "../core/lookup.js";
|
|
4
|
+
import { useFramework } from "./context.js";
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
/**
|
|
7
|
+
* The name of one record of an entity, by its key — what a field shows when it holds only the
|
|
8
|
+
* key (`EntityID[Tenant]`) and not the record it points at.
|
|
9
|
+
*
|
|
10
|
+
* Context: asked ONCE by key, the way `useLookup` names a chosen record it never saw: a page
|
|
11
|
+
* narrowed to that key, one row, read with the definition the application knows. Unnamed is no
|
|
12
|
+
* error — the field shows the key — and an entity listed under another record
|
|
13
|
+
* (`/tenants/{tenant_id}/members`) has no list to ask by key, so it stays unnamed.
|
|
14
|
+
*
|
|
15
|
+
* const name = useNameOf(tenants, record.tenant_id) ?? record.tenant_id;
|
|
16
|
+
*/
|
|
17
|
+
export function useNameOf(entity, id) {
|
|
18
|
+
const { transport, metas } = useFramework();
|
|
19
|
+
const [named, setNamed] = useState(undefined);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (entity === undefined || id === "")
|
|
22
|
+
return;
|
|
23
|
+
let route;
|
|
24
|
+
try {
|
|
25
|
+
route = listRoute(entity.list);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const known = metas.get(entity.key);
|
|
31
|
+
const key = known?.get_id || known?.identity || "id";
|
|
32
|
+
const aborter = new AbortController();
|
|
33
|
+
transport
|
|
34
|
+
.list(route, { selection: { field: key, operator: "=", value: id }, pagination: { limit: 1 } }, aborter.signal)
|
|
35
|
+
.then((page) => {
|
|
36
|
+
const [one] = lookupOf(page.meta ?? known ?? null, page.rows, entity.summary);
|
|
37
|
+
if (one !== undefined)
|
|
38
|
+
setNamed({ id, name: one.label });
|
|
39
|
+
})
|
|
40
|
+
.catch(() => undefined);
|
|
41
|
+
return () => aborter.abort();
|
|
42
|
+
}, [transport, metas, entity, id]);
|
|
43
|
+
return named?.id === id ? named.name : undefined;
|
|
44
|
+
}
|
package/dist/react/usePivot.js
CHANGED
|
@@ -30,7 +30,6 @@ export function usePivot(listing, axes) {
|
|
|
30
30
|
const [rows, columns] = JSON.parse(shape);
|
|
31
31
|
const grouped = (levels) => ({
|
|
32
32
|
...JSON.parse(question),
|
|
33
|
-
meta: false,
|
|
34
33
|
grouping: {
|
|
35
34
|
group_by: levels.map((level) => ({ ...level })),
|
|
36
35
|
...(sums === "" ? {} : { measures: measuresOf(sums.split(",")) }),
|
|
@@ -65,7 +65,8 @@ export type Editing = {
|
|
|
65
65
|
set: (name: string, value: unknown) => void;
|
|
66
66
|
state: (name: string) => FieldState;
|
|
67
67
|
/** A cell of a list of records — line `index` of `name`, its `field`: the line model's hints
|
|
68
|
-
* over that line, refined by what the server's preview said of it (`items
|
|
68
|
+
* over that line, refined by what the server's preview said of it (`items`, by the line's
|
|
69
|
+
* identity, by its position when it has none). */
|
|
69
70
|
cell: (name: string, index: number, field: string) => FieldState;
|
|
70
71
|
/** The server's word on what did not validate, by where it points (`pathOf`): `discount`,
|
|
71
72
|
* `lines/1/qty`. Read a field's — its lines' included — with `errorAt`. */
|
package/dist/react/useRecord.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { changesOf, creationOf, defaultsOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, } from "../core/edit.js";
|
|
2
|
+
import { changesOf, computedLocally, creationOf, defaultsOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, } from "../core/edit.js";
|
|
3
3
|
import { pathFor, startingValuesOf, WITH_PARAM, } from "../core/entity.js";
|
|
4
4
|
import { newEntityId } from "../core/ids.js";
|
|
5
5
|
import { linesAnswered } from "../core/lines.js";
|
|
@@ -158,7 +158,19 @@ export function useRecord(entity, opened) {
|
|
|
158
158
|
};
|
|
159
159
|
const ask = (next, name) => {
|
|
160
160
|
const preview = entity.preview;
|
|
161
|
-
|
|
161
|
+
const field = name.split(".")[0] ?? name;
|
|
162
|
+
// What the server wrote down is computed here, as it would: a change whose every reach has
|
|
163
|
+
// a formula needs the server only for a rule that judges it.
|
|
164
|
+
const local = Array.isArray(next[field])
|
|
165
|
+
? undefined
|
|
166
|
+
: computedLocally(state.meta, { ...record, ...next }, field);
|
|
167
|
+
if (local !== undefined)
|
|
168
|
+
setComputed((now) => ({ ...now, ...local }));
|
|
169
|
+
const judged = (state.meta?.fields[field]?.judged_by?.length ?? 0) > 0;
|
|
170
|
+
// A change that reaches nothing — no computation, no rule — has nothing to ask the server.
|
|
171
|
+
if (preview === undefined || !needsPreview(state.meta, field))
|
|
172
|
+
return;
|
|
173
|
+
if (local !== undefined && !judged)
|
|
162
174
|
return;
|
|
163
175
|
cancelPreview();
|
|
164
176
|
pause.current = setTimeout(() => {
|
|
@@ -233,7 +245,7 @@ export function useRecord(entity, opened) {
|
|
|
233
245
|
cell: (name, index, field) => {
|
|
234
246
|
const line = (Array.isArray(values[name]) ? values[name] : [])[index];
|
|
235
247
|
const definition = state.meta?.fields[name]?.definition;
|
|
236
|
-
return fieldStateOf(definition, field, line ?? {}, lineStatesOf(fromServer, name
|
|
248
|
+
return fieldStateOf(definition, field, line ?? {}, lineStatesOf(fromServer, name, line, index, definition?.identity || "id"));
|
|
237
249
|
},
|
|
238
250
|
errors: failure instanceof TransportError ? errorsByField(failure.problem?.errors) : {},
|
|
239
251
|
advice,
|
package/dist/react/useRelated.js
CHANGED
|
@@ -21,9 +21,9 @@ export function useRelated(record, name, related, options = {}) {
|
|
|
21
21
|
const value = record.record === null ? null : record.record[own];
|
|
22
22
|
const scope = {
|
|
23
23
|
...options.criteria,
|
|
24
|
-
|
|
24
|
+
selection: {
|
|
25
25
|
all: [
|
|
26
|
-
...(options.criteria?.
|
|
26
|
+
...(options.criteria?.selection ? [options.criteria.selection] : []),
|
|
27
27
|
{ field: key, operator: "=", value: value },
|
|
28
28
|
],
|
|
29
29
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type AnyRecord } from "@sincpro/criteria";
|
|
2
2
|
import { type WorkspaceApi } from "@sincpro/web-composer";
|
|
3
|
+
import { type CommandBodies } from "../../core/entity.js";
|
|
3
4
|
import type { GroupLevel, NamedFilter } from "../../core/list.js";
|
|
4
5
|
import type { Listing } from "../../react/useListing.js";
|
|
5
6
|
import { type RowCommand } from "./rowCommands.js";
|
|
@@ -28,8 +29,8 @@ import { type ReactNode } from "react";
|
|
|
28
29
|
* screen passes `onOpen`.
|
|
29
30
|
*/
|
|
30
31
|
export type { NamedFilter };
|
|
31
|
-
export type EntityListProps<T extends AnyRecord> = {
|
|
32
|
-
listing: Listing<T>;
|
|
32
|
+
export type EntityListProps<T extends AnyRecord, C extends CommandBodies = CommandBodies> = {
|
|
33
|
+
listing: Listing<T, C>;
|
|
33
34
|
/**
|
|
34
35
|
* The workspace this list is a view of. With it, a row opens its record as a page, the
|
|
35
36
|
* identity column is the composer's `RecordLink` (peek, side panel, window on hover) and the
|
|
@@ -107,7 +108,7 @@ export type EntityListProps<T extends AnyRecord> = {
|
|
|
107
108
|
* The entity's Commands offered on each row («Confirmar»), sent with their idempotency key;
|
|
108
109
|
* the list is read again when one is done (`useRowCommands`).
|
|
109
110
|
*/
|
|
110
|
-
commands?: readonly RowCommand<T>[];
|
|
111
|
+
commands?: readonly RowCommand<T, C>[];
|
|
111
112
|
/** Any other action of a row — or the commands built by hand with `useRowCommands`. */
|
|
112
113
|
rowActions?: (row: T) => readonly RowAction[];
|
|
113
114
|
/**
|
|
@@ -128,4 +129,4 @@ export type EntityFace<T> = {
|
|
|
128
129
|
render: (set: ListSet<T>) => ReactNode;
|
|
129
130
|
};
|
|
130
131
|
export type View = "table" | "rows" | "board" | "sheet" | "pivot";
|
|
131
|
-
export declare function EntityList<T extends AnyRecord>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, selectable, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T>): import("react").JSX.Element;
|
|
132
|
+
export declare function EntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, selectable, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
import { nameOf } from "@sincpro/criteria";
|
|
4
4
|
import { RecordLink, useCrumbs } from "@sincpro/web-composer";
|
|
5
5
|
import { frameworkCopy } from "../../core/copy.js";
|
|
6
|
-
import { PICK_PARAM, QUERY_PARAM, TRAIL_PARAM } from "../../core/entity.js";
|
|
6
|
+
import { PICK_PARAM, QUERY_PARAM, TRAIL_PARAM, } from "../../core/entity.js";
|
|
7
7
|
import { textOf, viewOf } from "../../core/present.js";
|
|
8
8
|
import { explain } from "../../core/transport.js";
|
|
9
9
|
import { useFramework } from "../../react/context.js";
|
|
@@ -22,7 +22,7 @@ export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
|
|
|
22
22
|
if (seeded.current || seed === undefined || seed === "" || meta?.search == null)
|
|
23
23
|
return;
|
|
24
24
|
seeded.current = true;
|
|
25
|
-
const where = matching(meta, seed).
|
|
25
|
+
const where = matching(meta, seed).selection;
|
|
26
26
|
if (where === undefined)
|
|
27
27
|
return;
|
|
28
28
|
const chip = filterCriteria(where, fillCopy(ui.search.literalChip, { text: seed }));
|
|
@@ -63,7 +63,7 @@ export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
|
|
|
63
63
|
: { grouping: _jsx(GroupingLevels, { fields: groupable, control: control }) }), onOpenBuilder: () => setBuilding(true), ...(meta?.search == null
|
|
64
64
|
? {}
|
|
65
65
|
: {
|
|
66
|
-
literal: (text) => matching(meta, text).
|
|
66
|
+
literal: (text) => matching(meta, text).selection ?? null,
|
|
67
67
|
}) }), building ? (_jsx(Dialog, { open: true, width: "lg", title: copy.builder, onClose: () => setBuilding(false), children: _jsx(CriteriaBuilder, { model: model, ...(whereOf(put) === undefined && listing.order.length === 0
|
|
68
68
|
? {}
|
|
69
69
|
: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
2
|
-
import type { Entity } from "../../core/entity.js";
|
|
2
|
+
import type { CommandAnswers, CommandBodies, Entity } from "../../core/entity.js";
|
|
3
3
|
import { type ListDefinition } from "../../core/list.js";
|
|
4
4
|
import type { PickerItem, RecordCard, RowOf } from "@sincpro/web-ui";
|
|
5
5
|
import type { ComponentProps } from "react";
|
|
@@ -40,11 +40,11 @@ export type Presentation<T> = {
|
|
|
40
40
|
row?: (record: T) => RowLook;
|
|
41
41
|
card?: (record: T) => CardLook;
|
|
42
42
|
};
|
|
43
|
-
export type Presented<T extends AnyRecord> = Entity<T> & {
|
|
43
|
+
export type Presented<T extends AnyRecord, C extends CommandBodies = CommandBodies, A extends CommandAnswers = CommandAnswers> = Entity<T, C, A> & {
|
|
44
44
|
readonly presentation: Presentation<T>;
|
|
45
45
|
};
|
|
46
46
|
/** The entity with how its records look: pass it wherever an entity goes. */
|
|
47
|
-
export declare function presented<T extends AnyRecord>(entity: Entity<T>, presentation: Presentation<T>): Presented<T>;
|
|
47
|
+
export declare function presented<T extends AnyRecord, C extends CommandBodies = CommandBodies, A extends CommandAnswers = CommandAnswers>(entity: Entity<T, C, A>, presentation: Presentation<T>): Presented<T, C, A>;
|
|
48
48
|
/** The presentation an entity — or the entity of a named list — was declared with; none is `{}`. */
|
|
49
49
|
export declare function presentationOf<T extends AnyRecord>(source: Entity<T> | ListDefinition<T>): Presentation<T>;
|
|
50
50
|
/** `look` over `base`, leaving out what `look` sets to `undefined`: «no tags» is not a hole. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isList } from "../../core/list.js";
|
|
2
2
|
/** The entity with how its records look: pass it wherever an entity goes. */
|
|
3
3
|
export function presented(entity, presentation) {
|
|
4
|
+
// Its typed Commands and answers go with it: a generated entity, presented, is still checked.
|
|
4
5
|
return { ...entity, presentation };
|
|
5
6
|
}
|
|
6
7
|
/** The presentation an entity — or the entity of a named list — was declared with; none is `{}`. */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type AnyRecord, type Expression } from "@sincpro/criteria";
|
|
2
|
+
import { type CommandBodies } from "../../core/entity.js";
|
|
2
3
|
import type { Listing } from "../../react/useListing.js";
|
|
3
4
|
import type { RowAction } from "@sincpro/web-ui";
|
|
4
5
|
import type { LucideIcon } from "lucide-react";
|
|
@@ -21,21 +22,24 @@ import type { LucideIcon } from "lucide-react";
|
|
|
21
22
|
* ]);
|
|
22
23
|
* <EntityList listing={listing} rowActions={commands.rowActions} />
|
|
23
24
|
*/
|
|
24
|
-
export type RowCommand<T> = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
export type RowCommand<T, C extends CommandBodies = CommandBodies> = {
|
|
26
|
+
[N in keyof C & string]: {
|
|
27
|
+
/** A Command the entity declares (`entity({ commands })`); a typed entity, only its own. */
|
|
28
|
+
command: N;
|
|
29
|
+
label: string;
|
|
30
|
+
icon: LucideIcon;
|
|
31
|
+
tone?: RowAction["tone"];
|
|
32
|
+
/** Offered only on rows that hold it — a hint, not protection: the server decides. */
|
|
33
|
+
when?: Expression<T>;
|
|
34
|
+
/** What the Command is sent with — checked against a typed entity's `C[command]`. Without
|
|
35
|
+
* it, an empty body: the route (or the Command's `target`) names the row. */
|
|
36
|
+
body?: (row: T) => C[N];
|
|
37
|
+
};
|
|
38
|
+
}[keyof C & string];
|
|
35
39
|
export type RowCommands<T> = {
|
|
36
40
|
rowActions: (row: T) => readonly RowAction[];
|
|
37
41
|
/** The last refusal, until `dismiss`. */
|
|
38
42
|
error: unknown;
|
|
39
43
|
dismiss: () => void;
|
|
40
44
|
};
|
|
41
|
-
export declare function useRowCommands<T extends AnyRecord>(listing: Listing<T>, commands: readonly RowCommand<T>[]): RowCommands<T>;
|
|
45
|
+
export declare function useRowCommands<T extends AnyRecord, C extends CommandBodies = CommandBodies>(listing: Listing<T, C>, commands: readonly RowCommand<T, C>[]): RowCommands<T>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { matches } from "@sincpro/criteria";
|
|
3
|
-
import { pathFor } from "../../core/entity.js";
|
|
3
|
+
import { bodyFor, pathFor } from "../../core/entity.js";
|
|
4
4
|
import { retryKeys } from "../../core/retry.js";
|
|
5
5
|
import { useFramework } from "../../react/context.js";
|
|
6
6
|
import { useCallback, useState } from "react";
|
|
@@ -20,7 +20,8 @@ export function useRowCommands(listing, commands) {
|
|
|
20
20
|
const gesture = `${one.command}\u0000${id}`;
|
|
21
21
|
const retry = keys.get(gesture) ?? retryKeys();
|
|
22
22
|
keys.set(gesture, retry);
|
|
23
|
-
|
|
23
|
+
// A Command whose body names its record (`target`) gets the row's id there.
|
|
24
|
+
const body = bodyFor(route, id, one.body?.(row) ?? {});
|
|
24
25
|
setRunning((now) => new Set(now).add(gesture));
|
|
25
26
|
setError(null);
|
|
26
27
|
try {
|
package/dist/web/list/search.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
2
|
-
import type { Entity } from "../../core/entity.js";
|
|
2
|
+
import type { CommandAnswers, CommandBodies, Entity } from "../../core/entity.js";
|
|
3
|
+
import { type AnswerOf } from "../../react/useCommand.js";
|
|
3
4
|
/**
|
|
4
5
|
* An entity's Command as a button.
|
|
5
6
|
*
|
|
@@ -9,16 +10,18 @@ import type { Entity } from "../../core/entity.js";
|
|
|
9
10
|
* shows THAT in the window: the confirmation is the consequence, in the server's words, not a
|
|
10
11
|
* question. A refusal is shown where it happened, with what to do.
|
|
11
12
|
*/
|
|
12
|
-
export declare function CommandButton<T extends AnyRecord, R = unknown>({ entity, command, id, body, label, destructive, role, disabled, onDone, }: {
|
|
13
|
-
entity: Entity<T>;
|
|
14
|
-
|
|
13
|
+
export declare function CommandButton<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>({ entity, command, id, body, label, destructive, role, disabled, onDone, }: {
|
|
14
|
+
entity: Entity<T, C, A>;
|
|
15
|
+
/** One the entity declares; a typed entity takes only its own names. */
|
|
16
|
+
command: N;
|
|
15
17
|
id?: string;
|
|
16
|
-
|
|
18
|
+
/** What it is sent with — checked against a typed entity's `C[command]`. */
|
|
19
|
+
body?: C[N];
|
|
17
20
|
label: string;
|
|
18
21
|
/** Asks the server what it would do before doing it. */
|
|
19
22
|
destructive?: boolean;
|
|
20
23
|
role?: "primary" | "secondary" | "ghost";
|
|
21
24
|
/** Not offered right now — «Mover» with no other tenant chosen. The server still decides. */
|
|
22
25
|
disabled?: boolean;
|
|
23
|
-
onDone?: (answer: R) => void;
|
|
26
|
+
onDone?: (answer: AnswerOf<R, A, N>) => void;
|
|
24
27
|
}): import("react").JSX.Element;
|
package/dist/web/record/edit.js
CHANGED
|
@@ -7,12 +7,19 @@ import { editableLines } from "../../core/lines.js";
|
|
|
7
7
|
import { textOf, viewOf } from "../../core/present.js";
|
|
8
8
|
import { relationFieldOf } from "../../core/relation.js";
|
|
9
9
|
import { useEntityFor, useFramework } from "../../react/context.js";
|
|
10
|
+
import { useNameOf } from "../../react/useNameOf.js";
|
|
10
11
|
import { controlFor, RelationPicker, } from "./control.js";
|
|
11
12
|
import { RecordLinesEditor } from "./lines.js";
|
|
12
13
|
import { useRecordOpening } from "./opening.js";
|
|
13
14
|
import { RecordLines } from "./record.js";
|
|
14
15
|
import { RelatedList } from "./RelatedList.js";
|
|
15
16
|
import { Checkbox, Field, FormSection, ReadValue, RelationValue, } from "@sincpro/web-ui";
|
|
17
|
+
/** A key alone, read: the name of the record it points at, asked once by key — the key until
|
|
18
|
+
* then, and when nothing answers. */
|
|
19
|
+
function KeyValue({ target, id, ...rest }) {
|
|
20
|
+
const name = useNameOf(target, id);
|
|
21
|
+
return _jsx(RelationValue, { name: name ?? id, ...rest });
|
|
22
|
+
}
|
|
16
23
|
/**
|
|
17
24
|
* One field of a record being edited, from the model: its word, whether it is required or
|
|
18
25
|
* read-only now (the hints, evaluated over what is on screen), the server's error for it, and a
|
|
@@ -99,13 +106,18 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
|
|
|
99
106
|
return null;
|
|
100
107
|
const key = edit.values[relation.key];
|
|
101
108
|
const id = key === null || key === undefined ? "" : String(key);
|
|
102
|
-
if (state.readonly)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
if (state.readonly) {
|
|
110
|
+
const opens = opening === null || id === ""
|
|
111
|
+
? {}
|
|
112
|
+
: {
|
|
113
|
+
onOpenIn: (to) => opening.open(target.ref(id), to),
|
|
114
|
+
openTargets: opening.targets,
|
|
115
|
+
};
|
|
116
|
+
// A relation held beside its key names itself; a key alone (`EntityID`) asks its name.
|
|
117
|
+
if (!relation.held)
|
|
118
|
+
return _jsx(KeyValue, { target: target, id: id, ...opens });
|
|
119
|
+
return (_jsx(RelationValue, { name: textOf(meta, relation.relation, edit.values[relation.relation], locale) ?? id, ...opens }));
|
|
120
|
+
}
|
|
109
121
|
return (_jsx(RelationPicker, { target: target, value: id, onChange: (next) => edit.set(relation.key, next), label: view.label }));
|
|
110
122
|
}
|
|
111
123
|
if (view.type === "boolean" && as === undefined)
|
package/dist/web/record/lines.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { choicesOf } from "@sincpro/criteria";
|
|
4
|
-
import { adviceAt, defaultsOf, errorAt, pathOf } from "../../core/edit.js";
|
|
4
|
+
import { adviceAt, defaultsOf, errorAt, linePlacesOf, pathOf, } from "../../core/edit.js";
|
|
5
5
|
import { addingOf, blankLine, lineFields, lineKey, moved, sameLine, writtenInCell, } from "../../core/lines.js";
|
|
6
6
|
import { textOf, viewOf } from "../../core/present.js";
|
|
7
7
|
import { entityFor, relationFieldOf, } from "../../core/relation.js";
|
|
@@ -42,7 +42,13 @@ function LineValue({ definition, field, line, set, label, invalid, locale, inCel
|
|
|
42
42
|
});
|
|
43
43
|
if (relation !== undefined && !relation.many && target !== undefined) {
|
|
44
44
|
const key = line[relation.key];
|
|
45
|
-
return (_jsx(RelationPicker, { target: target, value: key === null || key === undefined ? "" : String(key), label: label, standalone: inCell, onChange: (id, chosen) =>
|
|
45
|
+
return (_jsx(RelationPicker, { target: target, value: key === null || key === undefined ? "" : String(key), label: label, standalone: inCell, onChange: (id, chosen) =>
|
|
46
|
+
// A relation held beside its key keeps the chosen record, so the cell names it at
|
|
47
|
+
// once; a key alone (`EntityID`) is only its key — writing the record there too
|
|
48
|
+
// would put the record IN the key.
|
|
49
|
+
write(relation.held
|
|
50
|
+
? { [relation.key]: id, [relation.relation]: chosen ?? null }
|
|
51
|
+
: { [relation.key]: id }) }));
|
|
46
52
|
}
|
|
47
53
|
return controlFor({
|
|
48
54
|
value: line[field],
|
|
@@ -153,29 +159,36 @@ export function RecordLinesEditor({ record, name, lines, look = {}, }) {
|
|
|
153
159
|
// server's `items[i]`, the error pointing at it (under its value) and its warning.
|
|
154
160
|
cellState: (line, column) => {
|
|
155
161
|
const index = indexOf(line);
|
|
156
|
-
const
|
|
162
|
+
const places = linePlacesOf(name, line, index, identity).map((one) => `${one}/${column}`);
|
|
157
163
|
const state = edit.cell(name, index, column);
|
|
158
|
-
const error =
|
|
159
|
-
|
|
164
|
+
const error = places
|
|
165
|
+
.map((at) => errorAt(edit.errors, at))
|
|
166
|
+
.find((one) => one !== undefined);
|
|
167
|
+
const warned = places.flatMap((at) => adviceAt(edit.advice, at))[0];
|
|
160
168
|
return {
|
|
161
169
|
readonly: state.readonly,
|
|
162
170
|
required: state.required,
|
|
163
171
|
hidden: !state.visible,
|
|
164
172
|
...(error === undefined ? {} : { error }),
|
|
165
|
-
...(warned === undefined
|
|
173
|
+
...(warned === undefined
|
|
174
|
+
? {}
|
|
175
|
+
: { flag: { tone: warned.blocks_save ? "bad" : "warn", label: warned.message } }),
|
|
166
176
|
};
|
|
167
177
|
},
|
|
168
178
|
// The line's own flag: what points at the line and at no cell drawn — the line as a
|
|
169
179
|
// whole, or a field it has no column for (an id the server does not know).
|
|
170
180
|
flag: (line) => {
|
|
171
|
-
const
|
|
172
|
-
const onLine = (key) => key === at ||
|
|
173
|
-
(key.startsWith(`${at}/`) &&
|
|
181
|
+
const places = linePlacesOf(name, line, indexOf(line), identity);
|
|
182
|
+
const onLine = (key) => places.some((at) => key === at ||
|
|
183
|
+
(key.startsWith(`${at}/`) &&
|
|
184
|
+
!drawn.has(key.slice(at.length + 1).split("/")[0])));
|
|
174
185
|
const error = Object.entries(edit.errors).find(([key]) => onLine(key))?.[1];
|
|
175
186
|
if (error !== undefined)
|
|
176
187
|
return { tone: "bad", label: error };
|
|
177
188
|
const warned = edit.advice.find((one) => onLine(pathOf(one.path ?? [one.field ?? ""])));
|
|
178
|
-
return warned === undefined
|
|
189
|
+
return warned === undefined
|
|
190
|
+
? null
|
|
191
|
+
: { tone: warned.blocks_save ? "bad" : "warn", label: warned.message };
|
|
179
192
|
}, editor: (draft, set, state) => {
|
|
180
193
|
if (look.editor !== undefined)
|
|
181
194
|
return look.editor(draft, set, state);
|
|
@@ -18,5 +18,5 @@ export function useRecordOpening() {
|
|
|
18
18
|
export function chooserScopeOf(entity, cut) {
|
|
19
19
|
const named = isList(entity) ? scopeOf(entity) : undefined;
|
|
20
20
|
const all = named === undefined ? cut : cut === undefined ? named : merge(named, cut);
|
|
21
|
-
return all?.
|
|
21
|
+
return all?.selection;
|
|
22
22
|
}
|
|
@@ -78,10 +78,7 @@ export function entityView(entity, options) {
|
|
|
78
78
|
meta = (await options.transport.list(route, { pagination: { limit: 1 } })).meta;
|
|
79
79
|
if (meta?.search == null)
|
|
80
80
|
return [];
|
|
81
|
-
const page = await options.transport.list(route,
|
|
82
|
-
...matching(meta, query),
|
|
83
|
-
meta: false,
|
|
84
|
-
});
|
|
81
|
+
const page = await options.transport.list(route, matching(meta, query));
|
|
85
82
|
// ⌘K writes text: of the entity's look of a choice, its name and its meta.
|
|
86
83
|
const look = presentationOf(entity).option;
|
|
87
84
|
return lookupOf(meta, page.rows, entity.summary).map((one) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -9,8 +9,19 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./core": {
|
|
14
|
+
"types": "./dist/core/index.d.ts",
|
|
15
|
+
"default": "./dist/core/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./codegen": {
|
|
18
|
+
"types": "./dist/codegen/index.d.ts",
|
|
19
|
+
"default": "./dist/codegen/index.js"
|
|
12
20
|
}
|
|
13
21
|
},
|
|
22
|
+
"bin": {
|
|
23
|
+
"sincpro-web": "./dist/codegen/cli.js"
|
|
24
|
+
},
|
|
14
25
|
"publishConfig": {
|
|
15
26
|
"access": "public"
|
|
16
27
|
},
|
|
@@ -23,19 +34,19 @@
|
|
|
23
34
|
"printWidth": 94
|
|
24
35
|
},
|
|
25
36
|
"peerDependencies": {
|
|
26
|
-
"@sincpro/criteria": "^
|
|
27
|
-
"@sincpro/criteria-react": "^
|
|
37
|
+
"@sincpro/criteria": "^1.1.0",
|
|
38
|
+
"@sincpro/criteria-react": "^1.1.0",
|
|
28
39
|
"@sincpro/web-composer": "^1.5.0",
|
|
29
|
-
"@sincpro/web-ui": "^1.
|
|
40
|
+
"@sincpro/web-ui": "^1.11.1",
|
|
30
41
|
"react": ">=19",
|
|
31
42
|
"react-dom": ">=19"
|
|
32
43
|
},
|
|
33
44
|
"devDependencies": {
|
|
34
45
|
"@eslint/js": "^10.0.1",
|
|
35
|
-
"@sincpro/criteria": "^
|
|
36
|
-
"@sincpro/criteria-react": "^
|
|
46
|
+
"@sincpro/criteria": "^1.1.0",
|
|
47
|
+
"@sincpro/criteria-react": "^1.1.0",
|
|
37
48
|
"@sincpro/web-composer": "^1.5.0",
|
|
38
|
-
"@sincpro/web-ui": "^1.
|
|
49
|
+
"@sincpro/web-ui": "^1.11.1",
|
|
39
50
|
"@storybook/addon-a11y": "10.6.5",
|
|
40
51
|
"@storybook/addon-docs": "10.6.5",
|
|
41
52
|
"@storybook/addon-mcp": "10.6.5",
|