@sincpro/web-framework 2.5.0 → 3.0.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 +33 -28
- package/dist/core/copy.d.ts +8 -0
- package/dist/core/copy.js +8 -0
- package/dist/core/edit.d.ts +19 -0
- package/dist/core/edit.js +46 -0
- package/dist/core/history.d.ts +7 -0
- package/dist/core/history.js +5 -0
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +3 -3
- package/dist/core/list.d.ts +20 -2
- package/dist/core/list.js +24 -0
- package/dist/core/present.d.ts +22 -0
- package/dist/core/present.js +51 -19
- package/dist/react/index.d.ts +5 -1
- package/dist/react/index.js +5 -1
- package/dist/react/useCommand.d.ts +7 -1
- package/dist/react/useCommand.js +12 -2
- package/dist/react/useCount.d.ts +18 -0
- package/dist/react/useCount.js +23 -0
- package/dist/react/useRecord.d.ts +6 -6
- package/dist/react/useRecord.js +10 -7
- package/dist/react/useRecordLifecycle.d.ts +43 -0
- package/dist/react/useRecordLifecycle.js +49 -0
- package/dist/react/useService.d.ts +5 -1
- package/dist/react/useServiceReading.d.ts +35 -0
- package/dist/react/useServiceReading.js +75 -0
- package/dist/react/useTextOf.d.ts +16 -0
- package/dist/react/useTextOf.js +21 -0
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +1 -0
- package/dist/web/list/EntityList.d.ts +4 -1
- package/dist/web/list/EntityList.js +23 -6
- package/dist/web/list/EntitySearchBar.d.ts +4 -1
- package/dist/web/list/EntitySearchBar.js +2 -2
- package/dist/web/list/groups.d.ts +13 -3
- package/dist/web/list/groups.js +21 -8
- package/dist/web/list/openIn.d.ts +4 -2
- package/dist/web/list/openIn.js +9 -2
- package/dist/web/list/rowCommands.d.ts +2 -0
- package/dist/web/list/rowCommands.js +6 -1
- package/dist/web/record/RecordLifecycle.d.ts +23 -0
- package/dist/web/record/RecordLifecycle.js +29 -0
- package/dist/web/record/control.d.ts +9 -3
- package/dist/web/record/control.js +13 -4
- package/dist/web/record/edit.js +1 -1
- package/dist/web/record/lines.js +1 -1
- package/dist/web/record/opening.d.ts +2 -2
- package/dist/web/record/record.js +36 -3
- package/dist/web/workspace/composer.d.ts +5 -1
- package/dist/web/workspace/composer.js +30 -12
- package/dist/web/workspace/open.d.ts +1 -1
- package/dist/web/workspace/open.js +7 -1
- package/dist/web/workspace/record.d.ts +6 -2
- package/dist/web/workspace/record.js +16 -7
- package/dist/web/workspace/workspace.d.ts +7 -1
- package/dist/web/workspace/workspace.js +13 -4
- package/package.json +6 -6
package/dist/web/list/openIn.js
CHANGED
|
@@ -14,15 +14,22 @@ import { AppWindow, Eye, FileText, PanelRight, SquareArrowOutUpRight, SquareStac
|
|
|
14
14
|
*
|
|
15
15
|
* The places allowed depend on where the list is: from inside a modal, no modal (a second one
|
|
16
16
|
* would replace the first and lose what was typed in it) — composer says where a view is
|
|
17
|
-
* (`api.over`).
|
|
17
|
+
* (`api.over`). On a phone a side panel and a window both open as the page (composer 1.7,
|
|
18
|
+
* `api.layout`), so neither is offered: three entries that do the same are a lie. A screen that
|
|
19
|
+
* draws the menu follows the mode (`usePhone(api)`) so it redraws when it changes.
|
|
18
20
|
*/
|
|
19
21
|
/** A record's form fits; a short task (register a payment) passes its own size. */
|
|
20
22
|
export const RECORD_SIZE = { w: 760, h: 560 };
|
|
21
23
|
const EVERYWHERE = ["modal", "peek", "side", "page", "window"];
|
|
22
24
|
const FROM_A_MODAL = ["side", "peek", "page", "window"];
|
|
25
|
+
const ON_A_PHONE = ["modal", "peek", "page"];
|
|
26
|
+
const ON_A_PHONE_FROM_A_MODAL = ["peek", "page"];
|
|
23
27
|
/** Where a record may open from this view, the default first. */
|
|
24
28
|
export function targetsFor(api) {
|
|
25
|
-
|
|
29
|
+
const phone = api.layout?.phone() === true;
|
|
30
|
+
if (api.over === null)
|
|
31
|
+
return phone ? ON_A_PHONE : EVERYWHERE;
|
|
32
|
+
return phone ? ON_A_PHONE_FROM_A_MODAL : FROM_A_MODAL;
|
|
26
33
|
}
|
|
27
34
|
/** web-ui's target as composer's options. Destinations share their names, so only the size is
|
|
28
35
|
* added — to the two that have one. */
|
|
@@ -36,6 +36,8 @@ export type RowCommand<T, C extends CommandBodies = CommandBodies> = {
|
|
|
36
36
|
body?: (row: T) => C[N];
|
|
37
37
|
};
|
|
38
38
|
}[keyof C & string];
|
|
39
|
+
/** The row action of the trash (`trashOf`): the entity's `restore` route, run from the row. */
|
|
40
|
+
export declare const RESTORE = "restore";
|
|
39
41
|
export type RowCommands<T> = {
|
|
40
42
|
rowActions: (row: T) => readonly RowAction[];
|
|
41
43
|
/** The last refusal, until `dismiss`. */
|
|
@@ -3,6 +3,8 @@ import { bodyFor, pathFor, retryKeys } from "@sincpro/client-framework";
|
|
|
3
3
|
import { matches } from "@sincpro/criteria";
|
|
4
4
|
import { useFramework } from "../../react/context.js";
|
|
5
5
|
import { useCallback, useState } from "react";
|
|
6
|
+
/** The row action of the trash (`trashOf`): the entity's `restore` route, run from the row. */
|
|
7
|
+
export const RESTORE = "restore";
|
|
6
8
|
export function useRowCommands(listing, commands) {
|
|
7
9
|
const { transport } = useFramework();
|
|
8
10
|
const [running, setRunning] = useState(new Set());
|
|
@@ -12,7 +14,10 @@ export function useRowCommands(listing, commands) {
|
|
|
12
14
|
const { entity, meta } = listing;
|
|
13
15
|
const key = meta?.get_id || meta?.identity || "id";
|
|
14
16
|
const run = useCallback(async (one, row) => {
|
|
15
|
-
|
|
17
|
+
// «Restore» on a row of the trash runs the entity's own `restore` route (`trashOf`), unless
|
|
18
|
+
// the entity declares a Command of that name.
|
|
19
|
+
const route = entity.commands[one.command] ??
|
|
20
|
+
(one.command === RESTORE ? entity.restore : undefined);
|
|
16
21
|
if (route === undefined)
|
|
17
22
|
throw new Error(`${entity.key} declares no command "${one.command}"`);
|
|
18
23
|
const id = String(row[key]);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AnyRecord } from "@sincpro/criteria";
|
|
2
|
+
import type { RecordReading } from "../../react/useRecord.js";
|
|
3
|
+
/**
|
|
4
|
+
* The record's own lifecycle as buttons — «Mover a la papelera» / «Restaurar» and «Eliminar»,
|
|
5
|
+
* each when its entity declares sincpro_framework's `Archive`, `Restore`, `Delete` — a deletion
|
|
6
|
+
* asking the server first what it would do (its dry run) and doing it on «Hacerlo», the trash's
|
|
7
|
+
* two on the click (they can be undone). Nothing when the entity declares none, or the record is
|
|
8
|
+
* new.
|
|
9
|
+
*
|
|
10
|
+
* <Record.Actions>
|
|
11
|
+
* <RecordLifecycle record={member} onDone={() => api.close()} />
|
|
12
|
+
* </Record.Actions>
|
|
13
|
+
*
|
|
14
|
+
* Context: `EntityRecord` draws it; a screen of its own draws it the same, or drops to
|
|
15
|
+
* `useRecordLifecycle` and draws its own. What happens after is the screen's (`onDone`): in a
|
|
16
|
+
* workspace the surface closes — the record is gone —, and every list that showed it reads
|
|
17
|
+
* again by itself (the write is announced).
|
|
18
|
+
*/
|
|
19
|
+
export declare function RecordLifecycle<T extends AnyRecord>({ record, onDone, }: {
|
|
20
|
+
record: RecordReading<T>;
|
|
21
|
+
/** Done: which action — after `delete` and `archive` the record is out of every reading. */
|
|
22
|
+
onDone?: (action: "delete" | "archive" | "restore") => void;
|
|
23
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { frameworkCopy } from "../../core/copy.js";
|
|
4
|
+
import { useRecordLifecycle } from "../../react/useRecordLifecycle.js";
|
|
5
|
+
import { ActionButton } from "./ActionButton.js";
|
|
6
|
+
/**
|
|
7
|
+
* The record's own lifecycle as buttons — «Mover a la papelera» / «Restaurar» and «Eliminar»,
|
|
8
|
+
* each when its entity declares sincpro_framework's `Archive`, `Restore`, `Delete` — a deletion
|
|
9
|
+
* asking the server first what it would do (its dry run) and doing it on «Hacerlo», the trash's
|
|
10
|
+
* two on the click (they can be undone). Nothing when the entity declares none, or the record is
|
|
11
|
+
* new.
|
|
12
|
+
*
|
|
13
|
+
* <Record.Actions>
|
|
14
|
+
* <RecordLifecycle record={member} onDone={() => api.close()} />
|
|
15
|
+
* </Record.Actions>
|
|
16
|
+
*
|
|
17
|
+
* Context: `EntityRecord` draws it; a screen of its own draws it the same, or drops to
|
|
18
|
+
* `useRecordLifecycle` and draws its own. What happens after is the screen's (`onDone`): in a
|
|
19
|
+
* workspace the surface closes — the record is gone —, and every list that showed it reads
|
|
20
|
+
* again by itself (the write is announced).
|
|
21
|
+
*/
|
|
22
|
+
export function RecordLifecycle({ record, onDone, }) {
|
|
23
|
+
const lifecycle = useRecordLifecycle(record);
|
|
24
|
+
const copy = frameworkCopy().record;
|
|
25
|
+
const shown = ["archive", "restore", "delete"].filter((one) => lifecycle[one] !== undefined);
|
|
26
|
+
if (shown.length === 0)
|
|
27
|
+
return null;
|
|
28
|
+
return (_jsx(_Fragment, { children: shown.map((one) => (_jsx(ActionButton, { action: lifecycle[one], label: copy[one], onDone: () => onDone?.(one) }, one))) }));
|
|
29
|
+
}
|
|
@@ -14,15 +14,21 @@ export type FieldControl = {
|
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* The control a field's TYPE asks for — a choice, a number, a date, a date and time, a yes/no, a
|
|
17
|
-
* list of words,
|
|
18
|
-
*
|
|
17
|
+
* list of words, a text — or the one its `widget` names when the model names one of the
|
|
18
|
+
* framework's own: `textarea`, several lines of prose.
|
|
19
19
|
* Shared by a record's field (`RecordField`) and a line's cell and dialog (`RecordLinesEditor`):
|
|
20
20
|
* one rule for what a value is edited with.
|
|
21
|
+
*
|
|
22
|
+
* Context: sincpro_framework publishes each field's widget — its type's, or the one
|
|
23
|
+
* `presentation(widgets=…)` names — and a screen that ignored it drew a one-line input for a
|
|
24
|
+
* note, so every application passed `as` for each long text. Only the framework's own names are
|
|
25
|
+
* read here: a name an application registers is drawn with `as`, never looked up in a registry
|
|
26
|
+
* of strings.
|
|
21
27
|
*/
|
|
22
28
|
export declare function controlFor(control: FieldControl, type: string, exact: boolean, choices: {
|
|
23
29
|
value: unknown;
|
|
24
30
|
label: string;
|
|
25
|
-
}[]): ReactNode;
|
|
31
|
+
}[], widget?: string): ReactNode;
|
|
26
32
|
/**
|
|
27
33
|
* A many2one's control: the picker of the entity it points at — the server's literal search,
|
|
28
34
|
* the first ten, «Buscar más…» — opening the chosen one where the view says.
|
|
@@ -2,15 +2,21 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { dayOf, instantOf, timeZoneNow, wallTimeOf, } from "@sincpro/client-framework";
|
|
4
4
|
import { EntityPicker } from "./EntityPicker.js";
|
|
5
|
-
import { Checkbox, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextInput, } from "@sincpro/web-ui";
|
|
5
|
+
import { Checkbox, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextArea, TextInput, } from "@sincpro/web-ui";
|
|
6
6
|
/**
|
|
7
7
|
* The control a field's TYPE asks for — a choice, a number, a date, a date and time, a yes/no, a
|
|
8
|
-
* list of words,
|
|
9
|
-
*
|
|
8
|
+
* list of words, a text — or the one its `widget` names when the model names one of the
|
|
9
|
+
* framework's own: `textarea`, several lines of prose.
|
|
10
10
|
* Shared by a record's field (`RecordField`) and a line's cell and dialog (`RecordLinesEditor`):
|
|
11
11
|
* one rule for what a value is edited with.
|
|
12
|
+
*
|
|
13
|
+
* Context: sincpro_framework publishes each field's widget — its type's, or the one
|
|
14
|
+
* `presentation(widgets=…)` names — and a screen that ignored it drew a one-line input for a
|
|
15
|
+
* note, so every application passed `as` for each long text. Only the framework's own names are
|
|
16
|
+
* read here: a name an application registers is drawn with `as`, never looked up in a registry
|
|
17
|
+
* of strings.
|
|
12
18
|
*/
|
|
13
|
-
export function controlFor(control, type, exact, choices) {
|
|
19
|
+
export function controlFor(control, type, exact, choices, widget) {
|
|
14
20
|
const { value, set } = control;
|
|
15
21
|
const named = control.standalone === true ? { "aria-label": control.label } : {};
|
|
16
22
|
if (choices.length > 0)
|
|
@@ -39,6 +45,9 @@ export function controlFor(control, type, exact, choices) {
|
|
|
39
45
|
return (_jsx(TagsField, { value: words, options: words.map((word) => ({ value: word, label: word })), onChange: set, onCreate: (word) => word, ...named }));
|
|
40
46
|
}
|
|
41
47
|
default:
|
|
48
|
+
// Not in a cell: a row of a table is one line high, and the dialog has the room.
|
|
49
|
+
if (widget === "textarea" && control.standalone !== true)
|
|
50
|
+
return (_jsx(TextArea, { value: value === null || value === undefined ? "" : String(value), onChange: set }));
|
|
42
51
|
return (_jsx(TextInput, { value: value === null || value === undefined ? "" : String(value), onChange: set, ...named }));
|
|
43
52
|
}
|
|
44
53
|
}
|
package/dist/web/record/edit.js
CHANGED
|
@@ -143,7 +143,7 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
|
|
|
143
143
|
}
|
|
144
144
|
if (view.type === "boolean" && as === undefined)
|
|
145
145
|
return (_jsx(Checkbox, { checked: value === true, onChange: control.set, label: view.label, disabled: state.readonly }));
|
|
146
|
-
return (_jsx(Field, { label: view.label, required: state.required && !state.readonly, ...(view.help === undefined ? {} : { hint: view.help }), ...(error === undefined ? {} : { error }), children: as !== undefined ? (as(control)) : relation !== undefined && !relation.many && target !== undefined ? (manyToOne()) : state.readonly ? (_jsx(ReadValue, { value: textOf(meta, name, value, locale) ?? "—" })) : (controlFor(control, view.type, field?.exact === true, choicesOf(meta, name, locale))) }));
|
|
146
|
+
return (_jsx(Field, { label: view.label, required: state.required && !state.readonly, ...(view.help === undefined ? {} : { hint: view.help }), ...(error === undefined ? {} : { error }), children: as !== undefined ? (as(control)) : relation !== undefined && !relation.many && target !== undefined ? (manyToOne()) : state.readonly ? (_jsx(ReadValue, { value: textOf(meta, name, value, locale) ?? "—" })) : (controlFor(control, view.type, field?.exact === true, choicesOf(meta, name, locale), field?.widget)) }));
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
149
149
|
* The record's «save / discard», for `<Record dirty={…}>`: present only while something changed,
|
package/dist/web/record/lines.js
CHANGED
|
@@ -64,7 +64,7 @@ function LineValue({ definition, field, line, set, label, invalid, locale, inCel
|
|
|
64
64
|
invalid,
|
|
65
65
|
label,
|
|
66
66
|
standalone: inCell,
|
|
67
|
-
}, viewOf(definition, field, locale).type, definition?.fields[field]?.exact === true, choicesOf(definition, field, locale));
|
|
67
|
+
}, viewOf(definition, field, locale).type, definition?.fields[field]?.exact === true, choicesOf(definition, field, locale), definition?.fields[field]?.widget);
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* The lines of an aggregate, edited inside its record: web-ui's `LineItems` over the record's
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Entity, type
|
|
1
|
+
import { type Entity, type ResourceRef } from "@sincpro/client-framework";
|
|
2
2
|
import { type AnyRecord, type Criteria, type Expression } from "@sincpro/criteria";
|
|
3
3
|
import { type ListDefinition } from "../../core/list.js";
|
|
4
4
|
import type { OpenTarget } from "@sincpro/web-ui";
|
|
@@ -20,7 +20,7 @@ import { type ReactNode } from "react";
|
|
|
20
20
|
* that already committed — the holder gives an opening without `choose`.
|
|
21
21
|
*/
|
|
22
22
|
export type RecordOpening = {
|
|
23
|
-
open: (ref:
|
|
23
|
+
open: (ref: ResourceRef, to: OpenTarget) => void;
|
|
24
24
|
/** Where it may open from here, the default first. */
|
|
25
25
|
targets: readonly OpenTarget[];
|
|
26
26
|
/** The form is not on a page — a panel, a peek, a modal: a list inside it starts as rows
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { describeRows } from "@sincpro/criteria";
|
|
4
4
|
import { frameworkCopy } from "../../core/copy.js";
|
|
5
5
|
import { textOf, viewOf } from "../../core/present.js";
|
|
6
6
|
import { relatedOf } from "../../core/related.js";
|
|
7
|
+
import { relationFieldOf } from "../../core/relation.js";
|
|
8
|
+
import { useEntityFor } from "../../react/context.js";
|
|
9
|
+
import { useNameOf } from "../../react/useNameOf.js";
|
|
7
10
|
import { columnsOf } from "../list/columns.js";
|
|
8
|
-
import {
|
|
11
|
+
import { useRecordOpening } from "./opening.js";
|
|
12
|
+
import { List, RelationValue, } from "@sincpro/web-ui";
|
|
9
13
|
/**
|
|
10
14
|
* The parts of ONE record, from the model.
|
|
11
15
|
*
|
|
@@ -28,14 +32,43 @@ export function factsOf(record, meta, names, options = {}) {
|
|
|
28
32
|
return names.map((name) => {
|
|
29
33
|
const view = viewOf(meta, name, options.locale);
|
|
30
34
|
const own = options.cells?.[name];
|
|
35
|
+
const relation = relationFieldOf(meta, name);
|
|
31
36
|
return {
|
|
32
37
|
label: view.label,
|
|
33
|
-
value: own ? own(record) : (textOf(meta, name, record[name], options.locale) ?? EMPTY),
|
|
38
|
+
value: own ? (own(record)) : relation !== undefined && !relation.many ? (_jsx(RelationFact, { record: record, meta: meta, name: name, relation: relation, locale: options.locale })) : ((textOf(meta, name, record[name], options.locale) ?? EMPTY)),
|
|
34
39
|
...(view.help === undefined ? {} : { hint: view.help }),
|
|
35
40
|
...(name === meta?.identity ? { mono: true } : {}),
|
|
36
41
|
};
|
|
37
42
|
});
|
|
38
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* A many2one read as a fact: the name of the record it points at, as a link that opens it where
|
|
46
|
+
* the view says (`RecordOpening`: the workspace's places, «Abrir en…») — when the application
|
|
47
|
+
* declared its entity. A key alone (`EntityID[Tenant]`) is named by key (`useNameOf`). Of an
|
|
48
|
+
* entity nobody declared, it is the text it always was.
|
|
49
|
+
*
|
|
50
|
+
* Context: a fact a person read as «Globex Bolivia» led nowhere, so an application wrote its own
|
|
51
|
+
* link for «this payment's member», or misused a smart button for it. A component inside the
|
|
52
|
+
* fact's VALUE is fine: what web-ui finds by type are the slots, never their content.
|
|
53
|
+
*/
|
|
54
|
+
function RelationFact({ record, meta, name, relation, locale, }) {
|
|
55
|
+
const target = useEntityFor(relation.target);
|
|
56
|
+
const opening = useRecordOpening();
|
|
57
|
+
const raw = record[relation.key];
|
|
58
|
+
const key = raw === null || raw === undefined ? "" : String(raw);
|
|
59
|
+
const asked = useNameOf(relation.held ? undefined : target, key);
|
|
60
|
+
if (target === undefined || key === "")
|
|
61
|
+
return _jsx(_Fragment, { children: textOf(meta, name, record[name], locale) ?? EMPTY });
|
|
62
|
+
const held = relation.held
|
|
63
|
+
? textOf(meta, relation.relation, record[relation.relation], locale)
|
|
64
|
+
: null;
|
|
65
|
+
return (_jsx(RelationValue, { name: held ?? asked ?? key, ...(opening === null
|
|
66
|
+
? {}
|
|
67
|
+
: {
|
|
68
|
+
onOpenIn: (to) => opening.open(target.ref(key), to),
|
|
69
|
+
openTargets: opening.targets,
|
|
70
|
+
}) }));
|
|
71
|
+
}
|
|
39
72
|
/** How many records a relation of this record holds — the TOTAL, not the page it brought. */
|
|
40
73
|
export function countOf(record, name) {
|
|
41
74
|
return relatedOf(record[name]).count.value;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Entity, type Transport } from "@sincpro/client-framework";
|
|
2
2
|
import { type AnyRecord, type Meta } from "@sincpro/criteria";
|
|
3
|
-
import type
|
|
3
|
+
import { type ViewProps, type ViewSpec } from "@sincpro/web-composer";
|
|
4
4
|
import type { ListDefinition } from "../../core/list.js";
|
|
5
5
|
import { type ComponentType } from "react";
|
|
6
6
|
/**
|
|
@@ -44,6 +44,10 @@ export type EntityViewOptions = {
|
|
|
44
44
|
goto?: boolean;
|
|
45
45
|
/** Known before any search: no request asks for it. */
|
|
46
46
|
meta?: Meta;
|
|
47
|
+
/** A record's name, the screen's way — for a model with no display field (a singleton reads
|
|
48
|
+
* as its key). Used by the default record; a record of its own passes it to
|
|
49
|
+
* `useRecordInWorkspace` / `useRecordScreen`. */
|
|
50
|
+
title?: (record: AnyRecord) => string | null;
|
|
47
51
|
actions?: ViewSpec["actions"];
|
|
48
52
|
/** ⌘K's question: the list route's params that say which records it searches. */
|
|
49
53
|
search?: {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { listRoute, NEW_PARAM, scopeOfRef, } from "@sincpro/client-framework";
|
|
3
|
+
import { isEntityId, listRoute, NEW_PARAM, scopeNameOf, scopeOfRef, } from "@sincpro/client-framework";
|
|
4
4
|
import { matching } from "@sincpro/criteria";
|
|
5
|
+
import { usePhone, } from "@sincpro/web-composer";
|
|
5
6
|
import { lookupOf } from "../../core/lookup.js";
|
|
6
7
|
import { ListScopeProvider } from "../../react/scope.js";
|
|
7
8
|
import { useListing } from "../../react/useListing.js";
|
|
@@ -17,6 +18,7 @@ import { useMemo } from "react";
|
|
|
17
18
|
* a one2many's «Agregar» as the new record's form that answers once it exists.
|
|
18
19
|
*/
|
|
19
20
|
function InWorkspace({ api, children }) {
|
|
21
|
+
usePhone(api); // the places follow the mode: on a phone, no side panel and no window
|
|
20
22
|
const targets = targetsFor(api);
|
|
21
23
|
const opening = useMemo(() => {
|
|
22
24
|
// Never a modal over a modal: from inside one, what answers docks beside it.
|
|
@@ -33,29 +35,45 @@ function InWorkspace({ api, children }) {
|
|
|
33
35
|
}, [api, targets]);
|
|
34
36
|
return _jsx(RecordOpeningProvider, { value: opening, children: children });
|
|
35
37
|
}
|
|
36
|
-
/** The entity's list when the application writes none
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
/** The entity's list when the application writes none: opened under a named cut, it says
|
|
39
|
+
* whose it is («Facturas · Globex Bolivia»). */
|
|
40
|
+
function listOf(entity, name) {
|
|
41
|
+
return function DefaultList({ api, resource }) {
|
|
42
|
+
const of = scopeNameOf(resource);
|
|
43
|
+
return (_jsx(EntityList, { listing: useListing(entity), api: api, ...(of === undefined ? {} : { title: `${name} · ${of}` }) }));
|
|
40
44
|
};
|
|
41
45
|
}
|
|
42
46
|
/** The entity's record when the application writes none. */
|
|
43
|
-
function recordOf(entity) {
|
|
47
|
+
function recordOf(entity, title) {
|
|
44
48
|
return function DefaultRecord(props) {
|
|
45
|
-
return _jsx(EntityRecord, { ...props, entity: entity });
|
|
49
|
+
return (_jsx(EntityRecord, { ...props, entity: entity, ...(title === undefined ? {} : { title }) }));
|
|
46
50
|
};
|
|
47
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* What a reference reads as before its view names it — a crumb whose view is not mounted, a
|
|
54
|
+
* record still loading: the list is the view's name (with its cut's, `entity.listRef`); a record
|
|
55
|
+
* its key when the key is something a person reads (`F-2026-0004`), the view's name when it is
|
|
56
|
+
* a machine's (a UUID v7, `isEntityId`).
|
|
57
|
+
*/
|
|
58
|
+
function titleOf(ref, name) {
|
|
59
|
+
if (ref.id === undefined) {
|
|
60
|
+
const of = scopeNameOf(ref);
|
|
61
|
+
return of === undefined ? name : `${name} · ${of}`;
|
|
62
|
+
}
|
|
63
|
+
return isEntityId(ref.id) ? name : ref.id;
|
|
64
|
+
}
|
|
48
65
|
export function entityView(entity, options) {
|
|
49
66
|
let meta = options.meta ?? null;
|
|
50
67
|
const route = listRoute(entity.list, options.search?.params);
|
|
51
68
|
async function screens() {
|
|
52
69
|
const loaded = options.load === undefined ? {} : await options.load();
|
|
53
|
-
const List = loaded.list ?? options.list ?? listOf(entity);
|
|
54
|
-
const One = loaded.record ?? options.record ?? recordOf(entity);
|
|
70
|
+
const List = loaded.list ?? options.list ?? listOf(entity, options.name);
|
|
71
|
+
const One = loaded.record ?? options.record ?? recordOf(entity, options.title);
|
|
55
72
|
return function EntityView(props) {
|
|
56
73
|
const record = props.resource.id !== undefined || props.resource.params?.[NEW_PARAM] !== undefined;
|
|
57
|
-
// A chooser opened by a picker offers only what the picker may choose
|
|
58
|
-
//
|
|
74
|
+
// A chooser opened by a picker offers only what the picker may choose, and a list opened
|
|
75
|
+
// under a cut (`entity.listRef`) shows only what it cuts: the cut travels in the reference, and
|
|
76
|
+
// the list — the application's own too — reads under it.
|
|
59
77
|
const cut = record ? undefined : scopeOfRef(props.resource);
|
|
60
78
|
const list = cut === undefined ? (_jsx(List, { ...props })) : (_jsx(ListScopeProvider, { value: { key: entity.key, selection: cut }, children: _jsx(List, { ...props }) }));
|
|
61
79
|
return _jsx(InWorkspace, { api: props.api, children: record ? _jsx(One, { ...props }) : list });
|
|
@@ -67,7 +85,7 @@ export function entityView(entity, options) {
|
|
|
67
85
|
return {
|
|
68
86
|
domain: entity.domain,
|
|
69
87
|
kind: entity.kind,
|
|
70
|
-
title: (ref) => ref
|
|
88
|
+
title: (ref) => titleOf(ref, options.name),
|
|
71
89
|
goto: options.goto ?? true,
|
|
72
90
|
...(options.icon === undefined ? {} : { icon: options.icon }),
|
|
73
91
|
...(options.actions === undefined ? {} : { actions: options.actions }),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Entity } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord, Meta } from "@sincpro/criteria";
|
|
3
|
-
import type
|
|
3
|
+
import { type ResourceRef, type WorkspaceApi } from "@sincpro/web-composer";
|
|
4
4
|
import { type OpenTarget } from "@sincpro/web-ui";
|
|
5
5
|
import type { ReactNode } from "react";
|
|
6
6
|
/**
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import {} from "@sincpro/client-framework";
|
|
4
|
+
import { usePhone } from "@sincpro/web-composer";
|
|
5
|
+
import { useNameOf } from "../../react/useNameOf.js";
|
|
4
6
|
import { useSummaryOf } from "../../react/useSummary.js";
|
|
5
7
|
import { openOptions, targetsFor } from "../list/openIn.js";
|
|
6
8
|
import { relationOf } from "../record/summary.js";
|
|
@@ -44,9 +46,13 @@ export function openIn(api, ref, to, size) {
|
|
|
44
46
|
*/
|
|
45
47
|
export function RelatedRecord({ api, entity, value, meta, editor, }) {
|
|
46
48
|
const summarize = useSummaryOf(entity);
|
|
49
|
+
usePhone(api); // «Abrir en…» follows the mode: on a phone, no side panel and no window
|
|
50
|
+
// A key alone (`payment_id`, an `EntityID`) is read by its name, asked once by key — the key
|
|
51
|
+
// until it answers, and when nothing does. It used to stay the key: «P-0192…» for a payment.
|
|
52
|
+
const named = useNameOf(entity, typeof value === "string" ? value : "");
|
|
47
53
|
const extra = editor === undefined ? {} : { editor };
|
|
48
54
|
if (value === null || value === undefined || value === "")
|
|
49
55
|
return _jsx(RelationValue, { name: null, ...extra });
|
|
50
56
|
const summary = summarize(typeof value === "string" ? { id: value } : value, meta);
|
|
51
|
-
return (_jsx(RelationValue, { ...relationOf(summary), onOpenIn: (to) => openIn(api, entity.ref(summary.id), to), openTargets: targetsFor(api), ...extra }));
|
|
57
|
+
return (_jsx(RelationValue, { ...relationOf(named === undefined ? summary : { ...summary, name: named }), onOpenIn: (to) => openIn(api, entity.ref(summary.id), to), openTargets: targetsFor(api), ...extra }));
|
|
52
58
|
}
|
|
@@ -35,7 +35,9 @@ export type Stamp = {
|
|
|
35
35
|
* `Record.Rail`), and a region wrapped in one of ours is not found. Before it, forge's console
|
|
36
36
|
* carried these 150 lines itself (`shared/record_screen.tsx`).
|
|
37
37
|
*/
|
|
38
|
-
export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>, { api, resource }: Pick<ViewProps, "api" | "resource"
|
|
38
|
+
export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>, { api, resource }: Pick<ViewProps, "api" | "resource">, options?: {
|
|
39
|
+
title?: ((record: T) => string | null) | undefined;
|
|
40
|
+
}): {
|
|
39
41
|
reading: RecordReading<T>;
|
|
40
42
|
crumbs: readonly import("@sincpro/web-composer").Crumb[];
|
|
41
43
|
history: import("../../index.js").HistoryEntry[] | undefined;
|
|
@@ -66,8 +68,10 @@ export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>,
|
|
|
66
68
|
created?: Stamp | undefined;
|
|
67
69
|
} | undefined;
|
|
68
70
|
};
|
|
69
|
-
export declare function EntityRecord<T extends AnyRecord>({ api, resource, entity, fields, pages, actions, }: ViewProps & {
|
|
71
|
+
export declare function EntityRecord<T extends AnyRecord>({ api, resource, entity, fields, pages, actions, title, }: ViewProps & {
|
|
70
72
|
entity: Entity<T>;
|
|
73
|
+
/** Its name, the screen's way — for a record whose model has no display field. */
|
|
74
|
+
title?: (record: T) => string | null;
|
|
71
75
|
/** The fields, in this order. Without it, the model's (`formOf`). */
|
|
72
76
|
fields?: readonly string[];
|
|
73
77
|
/** The one2many shown as pages, in this order. Without it, every one the model has. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { TRAIL_PARAM } from "@sincpro/client-framework";
|
|
4
4
|
import { labelOf, nameOf } from "@sincpro/criteria";
|
|
5
5
|
import { useCrumbs } from "@sincpro/web-composer";
|
|
@@ -12,6 +12,7 @@ import { useHistory } from "../../react/useHistory.js";
|
|
|
12
12
|
import { useRecord } from "../../react/useRecord.js";
|
|
13
13
|
import { useSummaryOf } from "../../react/useSummary.js";
|
|
14
14
|
import { dirtyOf, RecordField } from "../record/edit.js";
|
|
15
|
+
import { RecordLifecycle } from "../record/RecordLifecycle.js";
|
|
15
16
|
import { Refused } from "../Refused.js";
|
|
16
17
|
import { useRecordInWorkspace } from "./workspace.js";
|
|
17
18
|
import { Button, Callout, FormSection, Record, Skeleton } from "@sincpro/web-ui";
|
|
@@ -64,10 +65,10 @@ function refusalOf(failure) {
|
|
|
64
65
|
* `Record.Rail`), and a region wrapped in one of ours is not found. Before it, forge's console
|
|
65
66
|
* carried these 150 lines itself (`shared/record_screen.tsx`).
|
|
66
67
|
*/
|
|
67
|
-
export function useRecordScreen(entity, { api, resource }) {
|
|
68
|
+
export function useRecordScreen(entity, { api, resource }, options = {}) {
|
|
68
69
|
const reading = useRecord(entity, resource);
|
|
69
70
|
const crumbs = useCrumbs(api);
|
|
70
|
-
useRecordInWorkspace(api, reading);
|
|
71
|
+
useRecordInWorkspace(api, reading, options);
|
|
71
72
|
const history = useHistory(entity, reading.isNew ? "" : reading.id, [reading.record]);
|
|
72
73
|
const summarize = useSummaryOf(entity);
|
|
73
74
|
const copy = frameworkCopy().record;
|
|
@@ -112,7 +113,8 @@ export function useRecordScreen(entity, { api, resource }) {
|
|
|
112
113
|
placement: api.surface === "modal" ? "card" : "page",
|
|
113
114
|
identity: {
|
|
114
115
|
// A new record is «creating»; an existing one has no name until it is read.
|
|
115
|
-
title:
|
|
116
|
+
title: (ready && !reading.isNew ? options.title?.(reading.record) : null) ??
|
|
117
|
+
summary?.name ??
|
|
116
118
|
(reading.isNew ? copy.creating(nameOf(reading.meta, reading.locale) || "") : ""),
|
|
117
119
|
...(summary?.type == null ? {} : { subtitle: summary.type }),
|
|
118
120
|
...(summary?.state == null ? {} : { tag: { label: summary.state } }),
|
|
@@ -134,8 +136,8 @@ export function useRecordScreen(entity, { api, resource }) {
|
|
|
134
136
|
},
|
|
135
137
|
};
|
|
136
138
|
}
|
|
137
|
-
export function EntityRecord({ api, resource, entity, fields, pages, actions, }) {
|
|
138
|
-
const screen = useRecordScreen(entity, { api, resource });
|
|
139
|
+
export function EntityRecord({ api, resource, entity, fields, pages, actions, title, }) {
|
|
140
|
+
const screen = useRecordScreen(entity, { api, resource }, { title });
|
|
139
141
|
const { reading, crumbs, history, pager } = screen;
|
|
140
142
|
const [page, setPage] = useState(undefined);
|
|
141
143
|
const copy = frameworkCopy().record;
|
|
@@ -146,7 +148,14 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, })
|
|
|
146
148
|
const { meta, locale, edit } = reading;
|
|
147
149
|
const layout = formOf(meta, entity.summary);
|
|
148
150
|
const shown = fields ?? layout.fields;
|
|
149
|
-
|
|
151
|
+
// The record's own lifecycle (its `Delete`, its trash) beside the screen's commands; once it is
|
|
152
|
+
// out of every reading the surface closes — every list that showed it reads again by itself.
|
|
153
|
+
const lifecycle = reading.isNew ||
|
|
154
|
+
(entity.delete === undefined &&
|
|
155
|
+
entity.archive === undefined &&
|
|
156
|
+
entity.restore === undefined) ? null : (_jsx(RecordLifecycle, { record: reading, onDone: (done) => (done === "restore" ? reading.reload() : api.close()) }));
|
|
157
|
+
const own = actions?.(reading) ?? null;
|
|
158
|
+
const ownActions = own === null && lifecycle === null ? null : (_jsxs(_Fragment, { children: [own, lifecycle] }));
|
|
150
159
|
const tabs = pages ?? layout.pages;
|
|
151
160
|
return (_jsxs(Record, { ...screen.record, children: [crumbs.length === 0 && pager === undefined && ownActions === null ? null : (_jsxs(Record.Rail, { children: [crumbs.length === 0 ? null : _jsx(Record.Crumbs, { crumbs: crumbs }), pager === undefined ? null : _jsx(Record.Pager, { ...pager }), ownActions === null ? null : _jsx(Record.Actions, { children: ownActions })] })), _jsxs(Record.Paper, { layout: "horizontal", children: [edit.conflict || edit.restored ? (_jsxs("div", { className: "flex flex-col gap-3", children: [edit.conflict ? (_jsx(Callout, { tone: "warn", title: copy.conflict, children: _jsx(Button, { size: "sm", role: "secondary", onClick: reading.reload, children: copy.reload }) })) : null, edit.restored ? (_jsx(Callout, { tone: "info", title: copy.restored, children: null })) : null] })) : null, _jsx(FormSection, { columns: api.surface === "page" || api.surface === "modal" ? 2 : 1, children: shown.map((name) => (_jsx(RecordField, { record: reading, name: name }, name))) }), edit.advice
|
|
152
161
|
.filter((one) => (one.path?.length ?? 0) <= 1)
|
|
@@ -17,10 +17,16 @@ import type { RecordReading } from "../../react/useRecord.js";
|
|
|
17
17
|
* to ANSWER (`api.pick(entity.newRef(…))` — «Agregar» on a record's one2many), it answers the
|
|
18
18
|
* record it became instead, and the surface closes: whoever asked reads it again.
|
|
19
19
|
*
|
|
20
|
+
* Its name is the model's display field — or the screen's word for it (`title`), for a record
|
|
21
|
+
* whose model has none: a singleton («the institution's texts») would read as its key.
|
|
22
|
+
*
|
|
20
23
|
* const invoice = useRecord(invoices, resource);
|
|
21
24
|
* useRecordInWorkspace(api, invoice);
|
|
25
|
+
* useRecordInWorkspace(api, texts, { title: () => "Textos de la institución" });
|
|
22
26
|
*/
|
|
23
|
-
export declare function useRecordInWorkspace<T extends AnyRecord>(api: WorkspaceApi, record: RecordReading<T
|
|
27
|
+
export declare function useRecordInWorkspace<T extends AnyRecord>(api: WorkspaceApi, record: RecordReading<T>, options?: {
|
|
28
|
+
title?: ((record: T) => string | null) | undefined;
|
|
29
|
+
}): void;
|
|
24
30
|
/**
|
|
25
31
|
* «Browse everything» as the composer's chooser: the entity's own list opens in a window and
|
|
26
32
|
* the row clicked there answers the field.
|
|
@@ -20,16 +20,25 @@ import { useEffect } from "react";
|
|
|
20
20
|
* to ANSWER (`api.pick(entity.newRef(…))` — «Agregar» on a record's one2many), it answers the
|
|
21
21
|
* record it became instead, and the surface closes: whoever asked reads it again.
|
|
22
22
|
*
|
|
23
|
+
* Its name is the model's display field — or the screen's word for it (`title`), for a record
|
|
24
|
+
* whose model has none: a singleton («the institution's texts») would read as its key.
|
|
25
|
+
*
|
|
23
26
|
* const invoice = useRecord(invoices, resource);
|
|
24
27
|
* useRecordInWorkspace(api, invoice);
|
|
28
|
+
* useRecordInWorkspace(api, texts, { title: () => "Textos de la institución" });
|
|
25
29
|
*/
|
|
26
|
-
export function useRecordInWorkspace(api, record) {
|
|
30
|
+
export function useRecordInWorkspace(api, record, options = {}) {
|
|
27
31
|
const display = record.meta?.display || record.meta?.identity || "";
|
|
32
|
+
const named = record.status === "ready" && options.title !== undefined
|
|
33
|
+
? options.title(record.record)
|
|
34
|
+
: null;
|
|
28
35
|
const title = record.isNew
|
|
29
36
|
? newTitle(record.meta, record.locale)
|
|
30
|
-
:
|
|
31
|
-
?
|
|
32
|
-
:
|
|
37
|
+
: named !== null
|
|
38
|
+
? named
|
|
39
|
+
: record.status === "ready" && display !== ""
|
|
40
|
+
? textOf(record.meta, display, record.record[display], record.locale)
|
|
41
|
+
: null;
|
|
33
42
|
const dirty = record.edit.dirty;
|
|
34
43
|
const opened = api.self.id ?? "";
|
|
35
44
|
const { entity, id } = record;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.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",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"@opentelemetry/resources": "^3.1.0",
|
|
41
41
|
"@opentelemetry/sdk-trace": "^3.1.0",
|
|
42
42
|
"@sentry/browser": "^11.11.0",
|
|
43
|
-
"@sincpro/client-framework": "^
|
|
43
|
+
"@sincpro/client-framework": "^2.0.0",
|
|
44
44
|
"@sincpro/criteria": "^2.1.0",
|
|
45
45
|
"@sincpro/criteria-react": "^2.1.0",
|
|
46
|
-
"@sincpro/web-composer": "^1.
|
|
46
|
+
"@sincpro/web-composer": "^1.7.0",
|
|
47
47
|
"@sincpro/web-ui": "^2.1.0",
|
|
48
48
|
"react": ">=19",
|
|
49
49
|
"react-dom": ">=19"
|
|
@@ -72,11 +72,11 @@
|
|
|
72
72
|
"@opentelemetry/resources": "3.1.0",
|
|
73
73
|
"@opentelemetry/sdk-trace": "3.1.0",
|
|
74
74
|
"@sentry/browser": "11.11.0",
|
|
75
|
-
"@sincpro/client-framework": "^
|
|
75
|
+
"@sincpro/client-framework": "^2.0.0",
|
|
76
76
|
"@sincpro/criteria": "^2.1.0",
|
|
77
77
|
"@sincpro/criteria-react": "^2.1.0",
|
|
78
|
-
"@sincpro/web-composer": "^1.
|
|
79
|
-
"@sincpro/web-ui": "^2.
|
|
78
|
+
"@sincpro/web-composer": "^1.7.0",
|
|
79
|
+
"@sincpro/web-ui": "^2.2.0",
|
|
80
80
|
"@storybook/addon-a11y": "10.6.5",
|
|
81
81
|
"@storybook/addon-docs": "10.6.5",
|
|
82
82
|
"@storybook/addon-mcp": "10.6.5",
|