@sincpro/web-framework 0.4.0 → 0.4.2
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 +42 -44
- package/dist/core/cache.d.ts +10 -2
- package/dist/core/cache.js +31 -9
- package/dist/core/copy.d.ts +4 -0
- package/dist/core/copy.js +4 -0
- package/dist/core/edit.d.ts +5 -0
- package/dist/core/edit.js +6 -2
- package/dist/core/entity.d.ts +39 -5
- package/dist/core/entity.js +57 -4
- package/dist/core/history.js +5 -1
- package/dist/core/ids.d.ts +17 -0
- package/dist/core/ids.js +52 -0
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.js +2 -1
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/react/scope.d.ts +23 -0
- package/dist/react/scope.js +12 -0
- package/dist/react/useCommand.js +1 -1
- package/dist/react/useListing.d.ts +1 -1
- package/dist/react/useListing.js +11 -11
- package/dist/react/useLookup.d.ts +10 -1
- package/dist/react/useLookup.js +29 -3
- package/dist/react/useRecord.d.ts +13 -2
- package/dist/react/useRecord.js +73 -22
- package/dist/web/list/rowCommands.js +2 -1
- package/dist/web/record/CommandButton.d.ts +3 -1
- package/dist/web/record/CommandButton.js +2 -2
- package/dist/web/record/EntityPicker.d.ts +28 -9
- package/dist/web/record/EntityPicker.js +54 -18
- package/dist/web/record/EntityTags.d.ts +5 -3
- package/dist/web/record/EntityTags.js +29 -6
- package/dist/web/record/control.d.ts +4 -4
- package/dist/web/record/control.js +7 -17
- package/dist/web/record/lines.js +12 -2
- package/dist/web/record/opening.d.ts +17 -3
- package/dist/web/record/opening.js +12 -0
- package/dist/web/workspace/SincproApp.d.ts +15 -4
- package/dist/web/workspace/SincproApp.js +18 -7
- package/dist/web/workspace/composer.d.ts +20 -1
- package/dist/web/workspace/composer.js +28 -10
- package/dist/web/workspace/record.js +12 -2
- package/dist/web/workspace/workspace.d.ts +6 -2
- package/dist/web/workspace/workspace.js +6 -2
- package/package.json +3 -3
|
@@ -13,9 +13,11 @@ import { type OpenTarget } from "@sincpro/web-ui";
|
|
|
13
13
|
* once by their keys. A person or a company (`entity(…, { summary: { person: true } })`) is
|
|
14
14
|
* chosen by their face.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Inside a workspace, opening a chip and «Buscar más…» are the workspace's (`RecordOpening`),
|
|
17
|
+
* as for a many2one: a chip opens where the workspace puts it, and «Buscar más…» is the
|
|
18
|
+
* entity's list opened to choose, offering neither what `criteria` leaves out nor the chips
|
|
19
|
+
* already on — the record answered there is added. `onOpen` / `onBrowseAll` replace either.
|
|
20
|
+
* Without a workspace a chip is a value.
|
|
19
21
|
*
|
|
20
22
|
* <EntityTags entity={people} value={followers} onChange={setFollowers} />
|
|
21
23
|
*/
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { isList } from "../../core/list.js";
|
|
4
|
-
import {
|
|
4
|
+
import { useFramework } from "../../react/context.js";
|
|
5
|
+
import { excluding, useLookup } from "../../react/useLookup.js";
|
|
5
6
|
import { presentationOf } from "../list/presentation.js";
|
|
7
|
+
import { chooserScopeOf, useRecordOpening } from "./opening.js";
|
|
6
8
|
import { TagsField } from "@sincpro/web-ui";
|
|
9
|
+
import { useRef } from "react";
|
|
7
10
|
/**
|
|
8
11
|
* A many2many: put SEVERAL records of an entity on this one — the followers of an invoice,
|
|
9
12
|
* the products of a promotion — as web-ui's `TagsField` chips, fed by `useLookup`.
|
|
@@ -15,18 +18,38 @@ import { TagsField } from "@sincpro/web-ui";
|
|
|
15
18
|
* once by their keys. A person or a company (`entity(…, { summary: { person: true } })`) is
|
|
16
19
|
* chosen by their face.
|
|
17
20
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
+
* Inside a workspace, opening a chip and «Buscar más…» are the workspace's (`RecordOpening`),
|
|
22
|
+
* as for a many2one: a chip opens where the workspace puts it, and «Buscar más…» is the
|
|
23
|
+
* entity's list opened to choose, offering neither what `criteria` leaves out nor the chips
|
|
24
|
+
* already on — the record answered there is added. `onOpen` / `onBrowseAll` replace either.
|
|
25
|
+
* Without a workspace a chip is a value.
|
|
21
26
|
*
|
|
22
27
|
* <EntityTags entity={people} value={followers} onChange={setFollowers} />
|
|
23
28
|
*/
|
|
24
29
|
export function EntityTags({ entity, value, onChange, criteria, onOpen, openTarget, onBrowseAll, placeholder, disabled, "aria-label": ariaLabel, }) {
|
|
30
|
+
const { metas } = useFramework();
|
|
31
|
+
const opening = useRecordOpening();
|
|
32
|
+
const base = isList(entity) ? entity.entity : entity;
|
|
33
|
+
// «Buscar más…» answers after the chooser closes: it adds to the chips on screen THEN.
|
|
34
|
+
const now = useRef(value);
|
|
35
|
+
now.current = value;
|
|
36
|
+
const opens = onOpen ??
|
|
37
|
+
(opening === null
|
|
38
|
+
? undefined
|
|
39
|
+
: (id, to) => opening.open(base.ref(id), to));
|
|
40
|
+
const choose = opening?.choose;
|
|
41
|
+
const browseAll = onBrowseAll ??
|
|
42
|
+
(choose === undefined
|
|
43
|
+
? undefined
|
|
44
|
+
: (query) => choose(base, (id) => {
|
|
45
|
+
if (!now.current.includes(id))
|
|
46
|
+
onChange([...now.current, id]);
|
|
47
|
+
}, query, chooserScopeOf(entity, excluding(criteria, value, metas.get(base.key)))));
|
|
25
48
|
const lookup = useLookup(entity, {
|
|
26
49
|
...(criteria === undefined ? {} : { criteria }),
|
|
27
50
|
values: value,
|
|
28
51
|
});
|
|
29
|
-
const person =
|
|
52
|
+
const person = base.summary.person === true;
|
|
30
53
|
const look = presentationOf(entity).option;
|
|
31
54
|
// A chip says a name and shows a face; the list under it also the datum that tells two apart
|
|
32
55
|
// (web-ui 1.5 `TagOption.meta`, never on the chip). Of the entity's look of a choice, those
|
|
@@ -48,5 +71,5 @@ export function EntityTags({ entity, value, onChange, criteria, onOpen, openTarg
|
|
|
48
71
|
...lookup.options.map(asTag),
|
|
49
72
|
...lookup.chosenAll.filter((one) => !offered.has(one.id)).map(asTag),
|
|
50
73
|
];
|
|
51
|
-
return (_jsx(TagsField, { value: value, onChange: onChange, options: options, ...(lookup.searchable ? { onSearch: lookup.search } : {}), ...(
|
|
74
|
+
return (_jsx(TagsField, { value: value, onChange: onChange, options: options, ...(lookup.searchable ? { onSearch: lookup.search } : {}), ...(opens === undefined ? {} : { onOpen: opens }), ...(openTarget === undefined ? {} : { openTarget }), ...(browseAll === undefined ? {} : { onBrowseAll: browseAll }), ...(placeholder === undefined ? {} : { placeholder }), ...(disabled === undefined ? {} : { disabled }), ...(ariaLabel === undefined ? {} : { "aria-label": ariaLabel }) }));
|
|
52
75
|
}
|
|
@@ -27,10 +27,10 @@ export declare function controlFor(control: FieldControl, type: string, exact: b
|
|
|
27
27
|
* A many2one's control: the picker of the entity it points at — the server's literal search,
|
|
28
28
|
* the first ten, «Buscar más…» — opening the chosen one where the view says.
|
|
29
29
|
*
|
|
30
|
-
* Context: shared by a record's field and a line.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
30
|
+
* Context: shared by a record's field and a line. Where it opens is `EntityPicker`'s — the
|
|
31
|
+
* workspace's when there is one. Inside a line the lines editor gives an opening without the
|
|
32
|
+
* workspace's chooser (`RecordLinesEditor`), so «Buscar más…» is the picker's own there;
|
|
33
|
+
* `ownChooser` asks for it anywhere else.
|
|
34
34
|
*/
|
|
35
35
|
export declare function RelationPicker({ target, value, onChange, label, ownChooser, standalone, }: {
|
|
36
36
|
target: Entity;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { instantOf, timeZoneNow, wallTimeOf } from "../../core/zone.js";
|
|
4
4
|
import { EntityPicker } from "./EntityPicker.js";
|
|
5
|
-
import { useRecordOpening } from "./opening.js";
|
|
6
5
|
import { Checkbox, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextInput, } from "@sincpro/web-ui";
|
|
7
6
|
/**
|
|
8
7
|
* The control a field's TYPE asks for — a choice, a number, a date, a date and time, a yes/no, a
|
|
@@ -44,24 +43,15 @@ export function controlFor(control, type, exact, choices) {
|
|
|
44
43
|
* A many2one's control: the picker of the entity it points at — the server's literal search,
|
|
45
44
|
* the first ten, «Buscar más…» — opening the chosen one where the view says.
|
|
46
45
|
*
|
|
47
|
-
* Context: shared by a record's field and a line.
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
46
|
+
* Context: shared by a record's field and a line. Where it opens is `EntityPicker`'s — the
|
|
47
|
+
* workspace's when there is one. Inside a line the lines editor gives an opening without the
|
|
48
|
+
* workspace's chooser (`RecordLinesEditor`), so «Buscar más…» is the picker's own there;
|
|
49
|
+
* `ownChooser` asks for it anywhere else.
|
|
51
50
|
*/
|
|
52
51
|
export function RelationPicker({ target, value, onChange, label, ownChooser = false, standalone = false, }) {
|
|
53
|
-
|
|
52
|
+
// Opening the chosen record and «Buscar más…» are the workspace's when there is one: the
|
|
53
|
+
// picker reads it (`RecordOpening`); a line keeps its own chooser.
|
|
54
54
|
return (_jsx(EntityPicker, { entity: target, value: value, onChange: onChange,
|
|
55
55
|
// «Buscar más…» is an option of the picker already: no second button beside it.
|
|
56
|
-
browse: false, ...(standalone ? { "aria-label": label } : {})
|
|
57
|
-
? {}
|
|
58
|
-
: {
|
|
59
|
-
onOpen: (chosen, to) => opening.open(target.ref(chosen), to),
|
|
60
|
-
openTargets: opening.targets,
|
|
61
|
-
...(ownChooser || opening.choose === undefined
|
|
62
|
-
? {}
|
|
63
|
-
: {
|
|
64
|
-
onBrowseAll: (query) => opening.choose?.(target, (id) => onChange(id), query),
|
|
65
|
-
}),
|
|
66
|
-
}) }));
|
|
56
|
+
browse: false, ownChooser: ownChooser, ...(standalone ? { "aria-label": label } : {}) }));
|
|
67
57
|
}
|
package/dist/web/record/lines.js
CHANGED
|
@@ -7,6 +7,7 @@ import { textOf, viewOf } from "../../core/present.js";
|
|
|
7
7
|
import { entityFor, relationFieldOf, } from "../../core/relation.js";
|
|
8
8
|
import { useEntityFor, useFramework } from "../../react/context.js";
|
|
9
9
|
import { controlFor, RelationPicker, } from "./control.js";
|
|
10
|
+
import { RecordOpeningProvider, useRecordOpening, } from "./opening.js";
|
|
10
11
|
import { Field, LineItems, ReadValue, } from "@sincpro/web-ui";
|
|
11
12
|
import { useRef } from "react";
|
|
12
13
|
/** How a field of a line reads: a many2one's key by the name of what it points at. */
|
|
@@ -41,7 +42,7 @@ function LineValue({ definition, field, line, set, label, invalid, locale, inCel
|
|
|
41
42
|
});
|
|
42
43
|
if (relation !== undefined && !relation.many && target !== undefined) {
|
|
43
44
|
const key = line[relation.key];
|
|
44
|
-
return (_jsx(RelationPicker, { target: target, value: key === null || key === undefined ? "" : String(key), label: label,
|
|
45
|
+
return (_jsx(RelationPicker, { target: target, value: key === null || key === undefined ? "" : String(key), label: label, standalone: inCell, onChange: (id, chosen) => write({ [relation.key]: id, [relation.relation]: chosen ?? null }) }));
|
|
45
46
|
}
|
|
46
47
|
return controlFor({
|
|
47
48
|
value: line[field],
|
|
@@ -83,6 +84,7 @@ function LineValue({ definition, field, line, set, label, invalid, locale, inCel
|
|
|
83
84
|
export function RecordLinesEditor({ record, name, lines, look = {}, }) {
|
|
84
85
|
const { meta, locale, edit } = record;
|
|
85
86
|
const { entities, metas } = useFramework();
|
|
87
|
+
const opening = useRecordOpening();
|
|
86
88
|
const definition = meta?.fields[name]?.definition ?? null;
|
|
87
89
|
const identity = definition?.identity || "id";
|
|
88
90
|
const fields = lineFields(definition);
|
|
@@ -146,7 +148,7 @@ export function RecordLinesEditor({ record, name, lines, look = {}, }) {
|
|
|
146
148
|
...(one.numeric === undefined ? {} : { numeric: one.numeric }),
|
|
147
149
|
})),
|
|
148
150
|
];
|
|
149
|
-
|
|
151
|
+
const table = (_jsx(LineItems, { lines: lines, columns: columns, getLineId: keyOf, mode: writing ? "edit" : "read", adding: adding, onChange: (key, next) => write((all) => all.map((one) => (keyOf(one) === key ? sameLine(one, next) : one))), newLine: () => blankLine(defaultsOf(definition), identity), onAdd: (line) => write((all) => [...all, line]), onRemove: (key) => write((all) => all.filter((one) => keyOf(one) !== key)), onRestore: (line, index) => write((all) => [...all.slice(0, index), line, ...all.slice(index)]), onReorder: (key, before) => write((all) => moved(all, identity, key, before)),
|
|
150
152
|
// A cell says its own (web-ui 1.6 `cellState`): the line model's hints refined by the
|
|
151
153
|
// server's `items[i]`, the error pointing at it (under its value) and its warning.
|
|
152
154
|
cellState: (line, column) => {
|
|
@@ -187,4 +189,12 @@ export function RecordLinesEditor({ record, name, lines, look = {}, }) {
|
|
|
187
189
|
return (_jsx(Field, { label: view.label, required: state.required && !state.readonly, ...(error === undefined ? {} : { error }), children: state.readonly ? (_jsx(ReadValue, { value: textIn(definition, field, relations.get(field), draft, locale) || "—" })) : (_jsx(LineValue, { definition: definition, field: field, line: draft, set: set, label: view.label, invalid: error !== undefined, locale: locale, inCell: false, own: controls[field] })) }, field));
|
|
188
190
|
}) }));
|
|
189
191
|
} }));
|
|
192
|
+
// Inside a line «Buscar más…» is the picker's own chooser, never the workspace's — the
|
|
193
|
+
// screen's own controls included: the workspace opens it outside the line, a row commits when
|
|
194
|
+
// the focus leaves it, and the answer would land on a line no longer being written (over the
|
|
195
|
+
// line's dialog, a modal over a modal). Opening a chosen record is still the workspace's.
|
|
196
|
+
if (opening === null || opening.choose === undefined)
|
|
197
|
+
return table;
|
|
198
|
+
const { choose: _, ...inLine } = opening;
|
|
199
|
+
return _jsx(RecordOpeningProvider, { value: inLine, children: table });
|
|
190
200
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AnyRecord, type Criteria, type Expression } from "@sincpro/criteria";
|
|
2
2
|
import type { Entity, EntityRef } from "../../core/entity.js";
|
|
3
|
+
import { type ListDefinition } from "../../core/list.js";
|
|
3
4
|
import type { OpenTarget } from "@sincpro/web-ui";
|
|
4
5
|
import { type ReactNode } from "react";
|
|
5
6
|
/**
|
|
@@ -11,6 +12,12 @@ import { type ReactNode } from "react";
|
|
|
11
12
|
* does not decide: the view that holds it says how to open (`entityView` fills it with the
|
|
12
13
|
* composer's `openIn` and the places allowed from where the view is), and a field asks. Without
|
|
13
14
|
* it a related record is a value, not a door.
|
|
15
|
+
*
|
|
16
|
+
* Every picker of an entity reads it by itself — `RecordField`, and an `EntityPicker` or
|
|
17
|
+
* `EntityTags` a screen writes by hand — so inside a workspace a record and a chooser always
|
|
18
|
+
* open in the workspace; what a screen passes (`onOpen`, `onBrowseAll`) still wins. Where the
|
|
19
|
+
* workspace's chooser must not be used — a line being written, whose answer would land on a line
|
|
20
|
+
* that already committed — the holder gives an opening without `choose`.
|
|
14
21
|
*/
|
|
15
22
|
export type RecordOpening = {
|
|
16
23
|
open: (ref: EntityRef, to: OpenTarget) => void;
|
|
@@ -20,8 +27,9 @@ export type RecordOpening = {
|
|
|
20
27
|
* (a table of seven columns in 760 px breaks every number and date into three lines). */
|
|
21
28
|
narrow?: boolean;
|
|
22
29
|
/** «Buscar más…»: the entity's own list opened to choose (in composer, a modal that answers),
|
|
23
|
-
* on what was typed
|
|
24
|
-
|
|
30
|
+
* on what was typed, offering only what `scope` lets the picker choose (`chooserScopeOf`).
|
|
31
|
+
* Without it the picker brings its own chooser. */
|
|
32
|
+
choose?: (entity: Entity, answer: (id: string) => void, query: string, scope?: Expression) => void;
|
|
25
33
|
/** «Agregar» on a one2many: the form of a new record of `entity`, starting with `values`
|
|
26
34
|
* (the key that points back here), opened where it answers; `created` once it exists.
|
|
27
35
|
* Without it a record's one2many only reads. */
|
|
@@ -32,3 +40,9 @@ export declare function RecordOpeningProvider({ value, children, }: {
|
|
|
32
40
|
children: ReactNode;
|
|
33
41
|
}): import("react").JSX.Element;
|
|
34
42
|
export declare function useRecordOpening(): RecordOpening | null;
|
|
43
|
+
/**
|
|
44
|
+
* What a picker's chooser may offer: its named list's scope and its own cut (criteria, the keys
|
|
45
|
+
* it excludes) as ONE expression — what `chooserRef(query, scope)` carries to the workspace,
|
|
46
|
+
* whose list knows nothing of the picker that opened it.
|
|
47
|
+
*/
|
|
48
|
+
export declare function chooserScopeOf<T extends AnyRecord>(entity: Entity<T> | ListDefinition<T>, cut: Criteria<T> | undefined): Expression | undefined;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { merge } from "@sincpro/criteria";
|
|
4
|
+
import { isList, scopeOf } from "../../core/list.js";
|
|
3
5
|
import { createContext, useContext } from "react";
|
|
4
6
|
const Opening = createContext(null);
|
|
5
7
|
export function RecordOpeningProvider({ value, children, }) {
|
|
@@ -8,3 +10,13 @@ export function RecordOpeningProvider({ value, children, }) {
|
|
|
8
10
|
export function useRecordOpening() {
|
|
9
11
|
return useContext(Opening);
|
|
10
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* What a picker's chooser may offer: its named list's scope and its own cut (criteria, the keys
|
|
15
|
+
* it excludes) as ONE expression — what `chooserRef(query, scope)` carries to the workspace,
|
|
16
|
+
* whose list knows nothing of the picker that opened it.
|
|
17
|
+
*/
|
|
18
|
+
export function chooserScopeOf(entity, cut) {
|
|
19
|
+
const named = isList(entity) ? scopeOf(entity) : undefined;
|
|
20
|
+
const all = named === undefined ? cut : cut === undefined ? named : merge(named, cut);
|
|
21
|
+
return all?.where;
|
|
22
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Meta } from "@sincpro/criteria";
|
|
2
|
-
import { type ComposerSkin, type ResourceRef, type ViewSpec } from "@sincpro/web-composer";
|
|
2
|
+
import { type ComposerSkin, type ResourceRef, type ViewSpec, type WorkspaceStore } from "@sincpro/web-composer";
|
|
3
3
|
import { type CacheOptions } from "../../core/cache.js";
|
|
4
4
|
import type { Entity } from "../../core/entity.js";
|
|
5
5
|
import type { Transport } from "../../core/transport.js";
|
|
@@ -12,10 +12,15 @@ import { type ReactNode } from "react";
|
|
|
12
12
|
* Context: forge's `main.tsx` + `console.tsx` installed three copy tables, a toast provider, a
|
|
13
13
|
* context of its own and a composer by hand. This is that, once. It is a convenience, not the
|
|
14
14
|
* only door: everything it mounts is exported, and an app with its own shell mounts them itself.
|
|
15
|
-
* What it does NOT own: the session (the app builds the transport with its headers) and the
|
|
16
|
-
* application bar
|
|
15
|
+
* What it does NOT own: the session (the app builds the transport with its headers) and what the
|
|
16
|
+
* application bar says. The bar is the app's (`bar`), drawn above the workspace inside every
|
|
17
|
+
* provider; a menu in it opens views through the workspace the app holds (`workspace`, from
|
|
18
|
+
* composer's `useWorkspace()`) — a workspace owned in here could not be reached from outside.
|
|
19
|
+
*
|
|
20
|
+
* const workspace = useWorkspace();
|
|
21
|
+
* <SincproApp workspace={workspace} bar={<Menu onOpen={(ref) => workspace.push(ref)} />} … />
|
|
17
22
|
*/
|
|
18
|
-
export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, }: {
|
|
23
|
+
export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, workspace: given, bar, }: {
|
|
19
24
|
transport: Transport;
|
|
20
25
|
/** The entities as composer views — `entityView(…)` — and any other view of the app. */
|
|
21
26
|
views: readonly ViewSpec[];
|
|
@@ -40,4 +45,10 @@ export declare function SincproApp({ transport, views, start, language, metas, e
|
|
|
40
45
|
/** Where the business is (`"America/La_Paz"`): every date and time on its wall clock.
|
|
41
46
|
* Without it, the browser's. */
|
|
42
47
|
timeZone?: string;
|
|
48
|
+
/** The workspace, when the app needs to reach it (a menu of its bar): composer's
|
|
49
|
+
* `useWorkspace()`. Without it, the app keeps one of its own. */
|
|
50
|
+
workspace?: WorkspaceStore;
|
|
51
|
+
/** The application's bar, above the workspace and inside the providers: its menus may read
|
|
52
|
+
* the framework (`useFramework`) and open views through `workspace`. */
|
|
53
|
+
bar?: ReactNode;
|
|
43
54
|
}): import("react").JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Composer, installComposerCopy, SPANISH_COMPOSER_COPY, useWorkspace, } from "@sincpro/web-composer";
|
|
4
4
|
import { createRegistry } from "@sincpro/web-composer/domain";
|
|
5
5
|
import { cachedTransport } from "../../core/cache.js";
|
|
@@ -16,10 +16,15 @@ import { useEffect, useMemo, useState } from "react";
|
|
|
16
16
|
* Context: forge's `main.tsx` + `console.tsx` installed three copy tables, a toast provider, a
|
|
17
17
|
* context of its own and a composer by hand. This is that, once. It is a convenience, not the
|
|
18
18
|
* only door: everything it mounts is exported, and an app with its own shell mounts them itself.
|
|
19
|
-
* What it does NOT own: the session (the app builds the transport with its headers) and the
|
|
20
|
-
* application bar
|
|
19
|
+
* What it does NOT own: the session (the app builds the transport with its headers) and what the
|
|
20
|
+
* application bar says. The bar is the app's (`bar`), drawn above the workspace inside every
|
|
21
|
+
* provider; a menu in it opens views through the workspace the app holds (`workspace`, from
|
|
22
|
+
* composer's `useWorkspace()`) — a workspace owned in here could not be reached from outside.
|
|
23
|
+
*
|
|
24
|
+
* const workspace = useWorkspace();
|
|
25
|
+
* <SincproApp workspace={workspace} bar={<Menu onOpen={(ref) => workspace.push(ref)} />} … />
|
|
21
26
|
*/
|
|
22
|
-
export function SincproApp({ transport, views, start, language = "es", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, }) {
|
|
27
|
+
export function SincproApp({ transport, views, start, language = "es", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, workspace: given, bar, }) {
|
|
23
28
|
// Installed once, before anything draws: the three tables are module state of their packages.
|
|
24
29
|
useState(() => {
|
|
25
30
|
if (language === "es") {
|
|
@@ -29,11 +34,17 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
|
|
|
29
34
|
}
|
|
30
35
|
return null;
|
|
31
36
|
});
|
|
32
|
-
const cached = useMemo(() =>
|
|
37
|
+
const cached = useMemo(() => cache === false
|
|
38
|
+
? transport
|
|
39
|
+
: cachedTransport(transport, {
|
|
40
|
+
...(entities === undefined ? {} : { entities }),
|
|
41
|
+
...cache,
|
|
42
|
+
}),
|
|
33
43
|
// The options are read once: a cache that changes shape mid-session forgets everything.
|
|
34
44
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
45
|
[transport]);
|
|
36
|
-
const
|
|
46
|
+
const own = useWorkspace();
|
|
47
|
+
const workspace = given ?? own;
|
|
37
48
|
const registry = useMemo(() => createRegistry(views), [views]);
|
|
38
49
|
useEffect(() => {
|
|
39
50
|
if (start !== undefined)
|
|
@@ -41,5 +52,5 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
|
|
|
41
52
|
// The first screen only: a re-render must not push it again.
|
|
42
53
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
43
54
|
}, [workspace]);
|
|
44
|
-
return (_jsx(FrameworkProvider, { transport: cached, locale: language, ...(metas === undefined ? {} : { metas }), ...(entities === undefined ? {} : { entities }), ...(timeZone === undefined ? {} : { timeZone }), children: _jsx(ToastProvider, { children:
|
|
55
|
+
return (_jsx(FrameworkProvider, { transport: cached, locale: language, ...(metas === undefined ? {} : { metas }), ...(entities === undefined ? {} : { entities }), ...(timeZone === undefined ? {} : { timeZone }), children: _jsx(ToastProvider, { children: _jsxs("div", { className: "flex h-dvh min-h-0 flex-col bg-ground", children: [bar, _jsx("div", { className: "flex min-h-0 flex-1 flex-col", children: _jsx(Composer, { workspace: workspace, registry: registry, skin: skin, ...(empty === undefined ? {} : { empty }) }) })] }) }) }));
|
|
45
56
|
}
|
|
@@ -21,7 +21,16 @@ import { type ComponentType } from "react";
|
|
|
21
21
|
*
|
|
22
22
|
* ⌘K asks the server with `matching` — 8 records, identity and display — the same question a
|
|
23
23
|
* many2one asks. The model definition is asked for once, on the first search, unless `meta`
|
|
24
|
-
* is handed over.
|
|
24
|
+
* is handed over. A list whose route answers a SCOPE by its params (forge's `/projects`
|
|
25
|
+
* without `tenant_id` is the projects with NO tenant) is searched in the one ⌘K should see:
|
|
26
|
+
* `search: { params }`.
|
|
27
|
+
*
|
|
28
|
+
* The screens can come in a chunk of their own (`load`): the composer asks for a view's
|
|
29
|
+
* component when it first opens, so the application's bundle does not carry every screen of
|
|
30
|
+
* every entity — `entityView` keeps that, where handing it the components had lost it.
|
|
31
|
+
*
|
|
32
|
+
* entityView(invoices, { transport, name: "Facturas",
|
|
33
|
+
* load: () => import("./invoice_views").then((m) => ({ list: m.Invoices, record: m.Invoice })) })
|
|
25
34
|
*/
|
|
26
35
|
export type EntityViewOptions = {
|
|
27
36
|
transport: Transport;
|
|
@@ -37,6 +46,16 @@ export type EntityViewOptions = {
|
|
|
37
46
|
/** Known before any search: no request asks for it. */
|
|
38
47
|
meta?: Meta;
|
|
39
48
|
actions?: ViewSpec["actions"];
|
|
49
|
+
/** ⌘K's question: the list route's params that say which records it searches. */
|
|
50
|
+
search?: {
|
|
51
|
+
params?: Readonly<Record<string, string>>;
|
|
52
|
+
};
|
|
53
|
+
/** The screens, loaded when the view first opens — a dynamic `import()`. What it does not
|
|
54
|
+
* bring is `list` / `record`, or the defaults. */
|
|
55
|
+
load?: () => Promise<{
|
|
56
|
+
list?: ComponentType<ViewProps>;
|
|
57
|
+
record?: ComponentType<ViewProps>;
|
|
58
|
+
}>;
|
|
40
59
|
};
|
|
41
60
|
export declare function entityView<T extends AnyRecord>(entity: Entity<T>, options: EntityViewOptions): ViewSpec;
|
|
42
61
|
/**
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { matching } from "@sincpro/criteria";
|
|
4
|
-
import { NEW_PARAM } from "../../core/entity.js";
|
|
4
|
+
import { listRoute, NEW_PARAM, scopeOfRef, } from "../../core/entity.js";
|
|
5
5
|
import { lookupOf } from "../../core/lookup.js";
|
|
6
|
+
import { ListScopeProvider } from "../../react/scope.js";
|
|
6
7
|
import { useListing } from "../../react/useListing.js";
|
|
7
8
|
import { EntityList } from "../list/EntityList.js";
|
|
8
9
|
import { presentationOf } from "../list/presentation.js";
|
|
@@ -26,7 +27,7 @@ function InWorkspace({ api, children }) {
|
|
|
26
27
|
open: (ref, to) => openIn(api, ref, to),
|
|
27
28
|
targets,
|
|
28
29
|
narrow: api.surface !== "page",
|
|
29
|
-
choose: (entity, answer, query) => api.pick(entity.chooserRef(query), (ref) => ref.id === undefined || answer(ref.id), answering),
|
|
30
|
+
choose: (entity, answer, query, scope) => api.pick(entity.chooserRef(query, scope), (ref) => ref.id === undefined || answer(ref.id), answering),
|
|
30
31
|
create: (entity, values, created) => api.pick(entity.newRef(values), () => created(), answering),
|
|
31
32
|
};
|
|
32
33
|
}, [api, targets]);
|
|
@@ -45,13 +46,24 @@ function recordOf(entity) {
|
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
48
|
export function entityView(entity, options) {
|
|
48
|
-
const List = options.list ?? listOf(entity);
|
|
49
|
-
const One = options.record ?? recordOf(entity);
|
|
50
49
|
let meta = options.meta ?? null;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
const route = listRoute(entity.list, options.search?.params);
|
|
51
|
+
async function screens() {
|
|
52
|
+
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);
|
|
55
|
+
return function EntityView(props) {
|
|
56
|
+
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: its cut travels in
|
|
58
|
+
// the reference, and the list — the application's own too — reads under it.
|
|
59
|
+
const cut = record ? undefined : scopeOfRef(props.resource);
|
|
60
|
+
const list = cut === undefined ? (_jsx(List, { ...props })) : (_jsx(ListScopeProvider, { value: { key: entity.key, where: cut }, children: _jsx(List, { ...props }) }));
|
|
61
|
+
return _jsx(InWorkspace, { api: props.api, children: record ? _jsx(One, { ...props }) : list });
|
|
62
|
+
};
|
|
54
63
|
}
|
|
64
|
+
// Built once: a second open of the view must be the same component, or it would remount. A
|
|
65
|
+
// chunk that failed to arrive is asked again next time.
|
|
66
|
+
let view = null;
|
|
55
67
|
return {
|
|
56
68
|
domain: entity.domain,
|
|
57
69
|
kind: entity.kind,
|
|
@@ -63,10 +75,10 @@ export function entityView(entity, options) {
|
|
|
63
75
|
if (query.trim() === "")
|
|
64
76
|
return [];
|
|
65
77
|
if (meta === null)
|
|
66
|
-
meta = (await options.transport.list(
|
|
78
|
+
meta = (await options.transport.list(route, { pagination: { limit: 1 } })).meta;
|
|
67
79
|
if (meta?.search == null)
|
|
68
80
|
return [];
|
|
69
|
-
const page = await options.transport.list(
|
|
81
|
+
const page = await options.transport.list(route, {
|
|
70
82
|
...matching(meta, query),
|
|
71
83
|
meta: false,
|
|
72
84
|
});
|
|
@@ -82,7 +94,13 @@ export function entityView(entity, options) {
|
|
|
82
94
|
};
|
|
83
95
|
});
|
|
84
96
|
},
|
|
85
|
-
load:
|
|
97
|
+
load: () => {
|
|
98
|
+
view ??= screens().catch((failure) => {
|
|
99
|
+
view = null;
|
|
100
|
+
throw failure;
|
|
101
|
+
});
|
|
102
|
+
return view;
|
|
103
|
+
},
|
|
86
104
|
};
|
|
87
105
|
}
|
|
88
106
|
export function listView(list, options = {}) {
|
|
@@ -68,12 +68,22 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, })
|
|
|
68
68
|
const dirty = dirtyOf(reading);
|
|
69
69
|
const created = summary?.created;
|
|
70
70
|
const updated = summary?.updated;
|
|
71
|
-
|
|
71
|
+
// Who, only when the record says it (web-ui 1.9: an author is optional, the line then says
|
|
72
|
+
// only when). The moment goes as the framework writes every fact of the record.
|
|
73
|
+
const stamp = (one) => one?.at == null ? undefined : { at: one.at, ...(one.by == null ? {} : { by: one.by }) };
|
|
72
74
|
const createdStamp = stamp(created);
|
|
73
75
|
const updatedStamp = stamp(updated);
|
|
74
76
|
// Moving away with something typed would lose it: «save / discard» comes first.
|
|
75
77
|
const place = trail === undefined || reading.isNew || edit.dirty ? null : placeOf(trail, reading.id);
|
|
76
|
-
return (_jsxs(Record
|
|
78
|
+
return (_jsxs(Record
|
|
79
|
+
// Where it is mounted decides the paper, not what the rail carries: crumbs, pager and
|
|
80
|
+
// actions come and go while it is on screen (loading, a draft), and the paper flipping
|
|
81
|
+
// with them remounted the form under the field being typed in. A modal is already a card.
|
|
82
|
+
, {
|
|
83
|
+
// Where it is mounted decides the paper, not what the rail carries: crumbs, pager and
|
|
84
|
+
// actions come and go while it is on screen (loading, a draft), and the paper flipping
|
|
85
|
+
// with them remounted the form under the field being typed in. A modal is already a card.
|
|
86
|
+
placement: api.surface === "modal" ? "card" : "page", identity: {
|
|
77
87
|
title: summary?.name ?? copy.creating(nameOf(meta, locale) || ""),
|
|
78
88
|
...(summary?.type == null ? {} : { subtitle: summary.type }),
|
|
79
89
|
...(summary?.state == null ? {} : { tag: { label: summary.state } }),
|
|
@@ -22,8 +22,12 @@ import type { RecordReading } from "../../react/useRecord.js";
|
|
|
22
22
|
*/
|
|
23
23
|
export declare function useRecordInWorkspace<T extends AnyRecord>(api: WorkspaceApi, record: RecordReading<T>): void;
|
|
24
24
|
/**
|
|
25
|
-
* «Browse everything»
|
|
26
|
-
*
|
|
25
|
+
* «Browse everything» as the composer's chooser: the entity's own list opens in a window and
|
|
26
|
+
* the row clicked there answers the field.
|
|
27
|
+
*
|
|
28
|
+
* Context: an `EntityPicker` inside an `entityView` already does this by itself (its
|
|
29
|
+
* `RecordOpening`), carrying its cut. This is for a screen that wires a chooser by hand — a
|
|
30
|
+
* button of its own, another `pick` option — and it carries no cut.
|
|
27
31
|
*
|
|
28
32
|
* <EntityPicker entity={customers} onChange={set} onBrowseAll={chooserIn(api, customers, set)} />
|
|
29
33
|
*/
|
|
@@ -53,8 +53,12 @@ function newTitle(meta, locale) {
|
|
|
53
53
|
return frameworkCopy().record.creating(nameOf(meta, locale) || "");
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
|
-
* «Browse everything»
|
|
57
|
-
*
|
|
56
|
+
* «Browse everything» as the composer's chooser: the entity's own list opens in a window and
|
|
57
|
+
* the row clicked there answers the field.
|
|
58
|
+
*
|
|
59
|
+
* Context: an `EntityPicker` inside an `entityView` already does this by itself (its
|
|
60
|
+
* `RecordOpening`), carrying its cut. This is for a screen that wires a chooser by hand — a
|
|
61
|
+
* button of its own, another `pick` option — and it carries no cut.
|
|
58
62
|
*
|
|
59
63
|
* <EntityPicker entity={customers} onChange={set} onBrowseAll={chooserIn(api, customers, set)} />
|
|
60
64
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
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",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@sincpro/criteria": "^0.3.1",
|
|
27
27
|
"@sincpro/criteria-react": "^0.3.1",
|
|
28
28
|
"@sincpro/web-composer": "^1.5.0",
|
|
29
|
-
"@sincpro/web-ui": "^1.
|
|
29
|
+
"@sincpro/web-ui": "^1.9.0",
|
|
30
30
|
"react": ">=19",
|
|
31
31
|
"react-dom": ">=19"
|
|
32
32
|
},
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@sincpro/criteria": "^0.3.1",
|
|
36
36
|
"@sincpro/criteria-react": "^0.3.1",
|
|
37
37
|
"@sincpro/web-composer": "^1.5.0",
|
|
38
|
-
"@sincpro/web-ui": "^1.
|
|
38
|
+
"@sincpro/web-ui": "^1.9.0",
|
|
39
39
|
"@storybook/addon-a11y": "10.6.5",
|
|
40
40
|
"@storybook/addon-docs": "10.6.5",
|
|
41
41
|
"@storybook/addon-mcp": "10.6.5",
|