@sincpro/web-framework 0.2.0 → 0.4.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 +56 -19
- package/dist/core/copy.d.ts +2 -0
- package/dist/core/copy.js +2 -0
- package/dist/core/edit.d.ts +35 -3
- package/dist/core/edit.js +49 -5
- package/dist/core/entity.d.ts +14 -2
- package/dist/core/entity.js +33 -1
- package/dist/core/index.d.ts +4 -2
- package/dist/core/index.js +4 -2
- package/dist/core/lines.d.ts +52 -0
- package/dist/core/lines.js +120 -0
- package/dist/core/list.d.ts +1 -1
- package/dist/core/lookup.d.ts +2 -0
- package/dist/core/lookup.js +3 -1
- package/dist/core/present.js +7 -2
- package/dist/core/rest.d.ts +5 -9
- package/dist/core/rest.js +14 -6
- package/dist/core/transport.d.ts +9 -1
- package/dist/core/zone.d.ts +27 -0
- package/dist/core/zone.js +75 -0
- package/dist/react/context.d.ts +13 -1
- package/dist/react/context.js +10 -2
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +1 -0
- package/dist/react/useGroups.d.ts +13 -1
- package/dist/react/useGroups.js +48 -7
- package/dist/react/useListing.d.ts +8 -4
- package/dist/react/useListing.js +11 -5
- package/dist/react/usePivot.d.ts +33 -0
- package/dist/react/usePivot.js +59 -0
- package/dist/react/useRecord.d.ts +13 -9
- package/dist/react/useRecord.js +55 -13
- package/dist/web/index.d.ts +7 -1
- package/dist/web/index.js +7 -1
- package/dist/web/list/EntityList.d.ts +46 -7
- package/dist/web/list/EntityList.js +132 -21
- package/dist/web/list/EntitySearchBar.js +19 -1
- package/dist/web/list/columns.d.ts +0 -13
- package/dist/web/list/columns.js +20 -1
- package/dist/web/list/groups.d.ts +3 -1
- package/dist/web/list/groups.js +8 -1
- package/dist/web/list/openIn.d.ts +41 -0
- package/dist/web/list/openIn.js +55 -0
- package/dist/web/list/pivot.d.ts +23 -0
- package/dist/web/list/pivot.js +64 -0
- package/dist/web/list/presentation.d.ts +51 -0
- package/dist/web/list/presentation.js +20 -0
- package/dist/web/record/EntityPicker.d.ts +3 -1
- package/dist/web/record/EntityPicker.js +15 -5
- package/dist/web/record/EntityTags.js +16 -5
- package/dist/web/record/RelatedList.d.ts +6 -0
- package/dist/web/record/RelatedList.js +26 -2
- package/dist/web/record/control.d.ts +43 -0
- package/dist/web/record/control.js +67 -0
- package/dist/web/record/edit.d.ts +16 -8
- package/dist/web/record/edit.js +57 -49
- package/dist/web/record/lines.d.ts +84 -0
- package/dist/web/record/lines.js +190 -0
- package/dist/web/record/opening.d.ts +8 -0
- package/dist/web/record/summary.js +14 -6
- package/dist/web/workspace/SincproApp.d.ts +4 -1
- package/dist/web/workspace/SincproApp.js +2 -2
- package/dist/web/workspace/composer.d.ts +2 -1
- package/dist/web/workspace/composer.js +27 -16
- package/dist/web/workspace/open.d.ts +2 -14
- package/dist/web/workspace/open.js +2 -13
- package/dist/web/workspace/record.js +6 -3
- package/dist/web/workspace/workspace.d.ts +4 -2
- package/dist/web/workspace/workspace.js +10 -4
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -278,6 +278,21 @@ function InvoiceView({ api, resource }: ViewProps) {
|
|
|
278
278
|
}
|
|
279
279
|
```
|
|
280
280
|
|
|
281
|
+
How a record of an entity LOOKS — as a choice, a row, a card — is said once, around the entity,
|
|
282
|
+
and every place that draws one uses it (`EntityPicker`, `EntityTags`, ⌘K, `EntityList`'s rows and
|
|
283
|
+
board). Each size answers web-ui's props for it, over the default; give only what changes:
|
|
284
|
+
|
|
285
|
+
```tsx
|
|
286
|
+
export const customers = presented(
|
|
287
|
+
entity<Customer>("sales:customer", { list: "/customers" }),
|
|
288
|
+
{
|
|
289
|
+
option: (c) => ({ meta: `NIT ${c.tax_id}`, aside: <Balance value={c.balance} /> }),
|
|
290
|
+
row: (c) => (c.blocked ? { tags: <Tag tone="bad">Blocked</Tag> } : {}),
|
|
291
|
+
card: (c) => ({ subtitle: c.city }),
|
|
292
|
+
},
|
|
293
|
+
);
|
|
294
|
+
```
|
|
295
|
+
|
|
281
296
|
Any record, at any size, from its summary:
|
|
282
297
|
|
|
283
298
|
```tsx
|
|
@@ -310,25 +325,30 @@ const tickets = defineMeta({
|
|
|
310
325
|
Each answers one question, and each comes in the three levels — use the component, drop to the
|
|
311
326
|
hook and draw your own, or go straight to the loose piece.
|
|
312
327
|
|
|
313
|
-
| Question | Declarative
|
|
314
|
-
| -------------------------------- |
|
|
315
|
-
| Where is the data? | `entity()`
|
|
316
|
-
| What is each field? | `Meta` from the server, or `defineMeta`
|
|
317
|
-
| What is a record, at any size? | `cardOf`, `relationOf`
|
|
318
|
-
|
|
|
319
|
-
|
|
|
320
|
-
| A
|
|
321
|
-
|
|
|
322
|
-
|
|
|
323
|
-
|
|
|
324
|
-
|
|
|
325
|
-
|
|
|
326
|
-
|
|
|
327
|
-
|
|
|
328
|
-
|
|
|
329
|
-
|
|
|
330
|
-
|
|
|
331
|
-
|
|
|
328
|
+
| Question | Declarative | Hook | Loose piece |
|
|
329
|
+
| -------------------------------- | ------------------------------------------------------- | ------------------------------------- | ------------------------------------ |
|
|
330
|
+
| Where is the data? | `entity()` | — | `restTransport`, `memoryTransport` |
|
|
331
|
+
| What is each field? | `Meta` from the server, or `defineMeta` | — | `textOf`, `viewOf`, `metaFromSchema` |
|
|
332
|
+
| What is a record, at any size? | `cardOf`, `relationOf` | `useSummaryOf` | `summaryOf` |
|
|
333
|
+
| How does a record look? | `presented(entity, { option, row, card })` | — | `presentationOf` |
|
|
334
|
+
| N records: search, filter, page | `EntityList`, `EntitySearchBar` | `useListing`, `useGroups` | `transport.list(route, criteria)` |
|
|
335
|
+
| A named slice (to collect, …) | `defineList` + `listView` | `useListing(list)` | `scopeOf` |
|
|
336
|
+
| A record's whole screen | `EntityRecord`, `entityView` without `record` | — | `formOf` |
|
|
337
|
+
| Previous / next from a record | `EntityRecord` (from a list) | — | `placeOf`, `stepIn` (`Trail`) |
|
|
338
|
+
| How much each group adds up | `EntityList sums` | `useGroups` (`sums`) | `sumsOf`, `detailOf` |
|
|
339
|
+
| One record: read, edit, save | `RecordField`, `factsOf`, `RecordLines` | `useRecord` | `transport.one`, `transport.send` |
|
|
340
|
+
| Its lines: add, edit, remove | `RecordField name="lines"` (`LineItems`) | `useRecord` (`edit.cell`, `errorAt`) | `lineKey`, `editableLines`, `pathOf` |
|
|
341
|
+
| Its relations, inside it | `RelatedList` | `useRelated` | `relatedOf` |
|
|
342
|
+
| Choose one (literal search) | `EntityPicker`, `chooserIn` | `useLookup` | `lookupOf` + criteria's `matching` |
|
|
343
|
+
| Choose several (many2many) | `EntityTags` | `useLookup` (`values`) | `lookupOf` |
|
|
344
|
+
| A relation, from the model alone | `RecordField name="customer_id"` | `useEntityFor` | `relationFieldOf`, `entityFor` |
|
|
345
|
+
| Open it where it belongs | `RelatedRecord`, `entityView`, `EntityList openTargets` | — | `openIn`, `targetsFor`, `OpenInMenu` |
|
|
346
|
+
| Look at the set several ways | `EntityList views` (table, rows, board, sheet) | — | web-ui's `List.*` |
|
|
347
|
+
| Cross it by two fields | `EntityList pivot` | `usePivot` | `pivotOf` |
|
|
348
|
+
| Order by several fields | the bar's criteria builder | `listing.orderBy([...])` | criteria's `order` |
|
|
349
|
+
| Act on it (with a dry run) | `CommandButton`, `commands` on rows | `useCommand` | `transport.send` |
|
|
350
|
+
| What happened to it | `Record.Activity` fed by `useHistory` | `useHistory` | `historyOf` |
|
|
351
|
+
| The application context | `SincproApp` | `useRecordInWorkspace`, `useFollowed` | `FrameworkProvider`, `webUiSkin` |
|
|
332
352
|
|
|
333
353
|
The rules behind them, in short:
|
|
334
354
|
|
|
@@ -341,6 +361,23 @@ The rules behind them, in short:
|
|
|
341
361
|
- **Every word on screen** is the model's (`labelOf`, `choiceLabelOf`) or the framework's copy
|
|
342
362
|
table (`frameworkCopy()`), never a string in a component.
|
|
343
363
|
|
|
364
|
+
### Where state lives
|
|
365
|
+
|
|
366
|
+
There is no store of ours to learn: each kind of state already has its owner.
|
|
367
|
+
|
|
368
|
+
| State | Lives in | Read with |
|
|
369
|
+
| -------------------------------------------- | -------------------------------------------------- | ---------------------------------- |
|
|
370
|
+
| Who answers, language, known models | `FrameworkProvider` (this package) | the hooks, through context |
|
|
371
|
+
| What the backend sees on every request | the transport's `headers` (e.g. `sincpro-context`) | the backend's `use_context()` |
|
|
372
|
+
| What an opening carries (company, a default) | composer: the reference's `params` | `api.self.params`, `api.setParams` |
|
|
373
|
+
| The record a modal covers | composer: `api.over` | `api.over` |
|
|
374
|
+
| What a chooser was asked | composer: `pick(…, { question })` | `api.choosing` |
|
|
375
|
+
| What the user is on, what is selected | composer: `api.context` | `useWorkspaceContext(api)` |
|
|
376
|
+
| A screen's list, record, groups | the hooks | `useListing`, `useRecord`, … |
|
|
377
|
+
|
|
378
|
+
Not yet: a new record does not take the `params` it was opened with as its initial values
|
|
379
|
+
(`ROADMAP.md`, «Estado y contexto»).
|
|
380
|
+
|
|
344
381
|
### Inside
|
|
345
382
|
|
|
346
383
|
Three folders, one direction — `make doctor` keeps the arrows:
|
package/dist/core/copy.d.ts
CHANGED
|
@@ -53,6 +53,8 @@ export type FrameworkCopy = {
|
|
|
53
53
|
creating: (name: string) => string;
|
|
54
54
|
/** The list's button that opens the form of a new record. */
|
|
55
55
|
create: string;
|
|
56
|
+
/** A record's one2many: the button that opens the form of a new related record. */
|
|
57
|
+
add: string;
|
|
56
58
|
};
|
|
57
59
|
picker: {
|
|
58
60
|
/** The button beside a many2one that opens the chooser over the whole set. */
|
package/dist/core/copy.js
CHANGED
|
@@ -29,6 +29,7 @@ export const ENGLISH_FRAMEWORK_COPY = {
|
|
|
29
29
|
partial: (shown, total) => `Showing ${shown} of ${total}.`,
|
|
30
30
|
creating: (name) => (name ? `${name} · new` : "New"),
|
|
31
31
|
create: "New",
|
|
32
|
+
add: "Add",
|
|
32
33
|
},
|
|
33
34
|
picker: {
|
|
34
35
|
browse: "Search all",
|
|
@@ -96,6 +97,7 @@ export const SPANISH_FRAMEWORK_COPY = {
|
|
|
96
97
|
partial: (shown, total) => `Se muestran ${shown} de ${total}.`,
|
|
97
98
|
creating: (name) => (name ? `${name} · nuevo` : "Nuevo"),
|
|
98
99
|
create: "Nuevo",
|
|
100
|
+
add: "Agregar",
|
|
99
101
|
},
|
|
100
102
|
picker: {
|
|
101
103
|
browse: "Buscar en todos",
|
package/dist/core/edit.d.ts
CHANGED
|
@@ -16,15 +16,47 @@ export type FieldState = {
|
|
|
16
16
|
required: boolean;
|
|
17
17
|
visible: boolean;
|
|
18
18
|
};
|
|
19
|
-
/**
|
|
20
|
-
|
|
19
|
+
/**
|
|
20
|
+
* What a server preview said about a field. A list of records — an invoice's lines — carries
|
|
21
|
+
* each one's own in `items`, in the order the form sent them (sincpro_framework's
|
|
22
|
+
* `FieldState.items`).
|
|
23
|
+
*/
|
|
24
|
+
export type ServerFieldState = Partial<FieldState> & {
|
|
25
|
+
items?: readonly Readonly<Record<string, ServerFieldState>>[];
|
|
26
|
+
};
|
|
27
|
+
export type FieldStates = Readonly<Record<string, ServerFieldState>>;
|
|
28
|
+
/** What the server's preview warned about, pointing where it belongs (`path`: the field, or a
|
|
29
|
+
* line's cell — `["lines", 1, "price"]`). It refuses nothing. sincpro_framework's warning. */
|
|
30
|
+
export type Advice = {
|
|
31
|
+
message: string;
|
|
32
|
+
field?: string | null;
|
|
33
|
+
path?: readonly (string | number)[];
|
|
34
|
+
};
|
|
21
35
|
export declare function fieldStateOf(meta: Meta | null | undefined, name: string, values: AnyRecord, fromServer?: FieldStates): FieldState;
|
|
36
|
+
/** Each line's states of a list of records, as the server said them — by position. */
|
|
37
|
+
export declare function lineStatesOf(fromServer: FieldStates | undefined, name: string): readonly FieldStates[];
|
|
22
38
|
/** The fields whose value differs from the record's — what a save or a draft sends. */
|
|
23
39
|
export declare function changesOf(record: AnyRecord, values: AnyRecord): AnyRecord;
|
|
24
40
|
/** What is missing before it can be saved: a required, visible, editable field left empty. */
|
|
25
41
|
export declare function missingOf(meta: Meta | null | undefined, values: AnyRecord, fromServer?: FieldStates): string[];
|
|
26
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Where the server's word points inside the record, as one key: `"discount"`, `"lines/1/qty"`.
|
|
44
|
+
* A JSON pointer (RFC 6901), bare (`/discount`) or as a fragment (`#/values/lines/1/qty`) — the
|
|
45
|
+
* command's `values/` envelope dropped, `~1`/`~0` read back — or a path (`["lines", 1, "qty"]`).
|
|
46
|
+
* Errors and warnings are read with the same rule, so both land on the same cell.
|
|
47
|
+
*/
|
|
48
|
+
export declare function pathOf(at: string | readonly (string | number)[]): string;
|
|
49
|
+
/**
|
|
50
|
+
* The server's word on what did not validate, by where it points (`pathOf`): a field's own
|
|
51
|
+
* error under its name, a line's cell's under its whole path (`lines/1/qty`). The first word for
|
|
52
|
+
* a place wins. `errorAt` reads a field's, its lines' included.
|
|
53
|
+
*/
|
|
27
54
|
export declare function errorsByField(errors: readonly FieldError[] | undefined): Record<string, string>;
|
|
55
|
+
/** The error at `at` or under it (`lines` finds `lines/1/qty`): what marks a field invalid. */
|
|
56
|
+
export declare function errorAt(errors: Readonly<Record<string, string>>, at: string): string | undefined;
|
|
57
|
+
/** The warnings at `at` or under it — a line's (`lines/1`) finds its cells'. One with no path
|
|
58
|
+
* is placed by its field. */
|
|
59
|
+
export declare function adviceAt(advice: readonly Advice[], at: string): Advice[];
|
|
28
60
|
/**
|
|
29
61
|
* A record that does not exist yet: the defaults the model publishes for each field
|
|
30
62
|
* (`FieldMeta.default`, sincpro_framework's `defaults_of`), and nothing else.
|
package/dist/core/edit.js
CHANGED
|
@@ -15,7 +15,13 @@ export function fieldStateOf(meta, name, values, fromServer) {
|
|
|
15
15
|
? true
|
|
16
16
|
: holds(values, field.visible_when, meta),
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
// `items` is the lines' own word, read with `lineStatesOf` — never a state of the field.
|
|
19
|
+
const { items: _lines, ...server } = fromServer?.[name] ?? {};
|
|
20
|
+
return { ...own, ...server };
|
|
21
|
+
}
|
|
22
|
+
/** Each line's states of a list of records, as the server said them — by position. */
|
|
23
|
+
export function lineStatesOf(fromServer, name) {
|
|
24
|
+
return fromServer?.[name]?.items ?? [];
|
|
19
25
|
}
|
|
20
26
|
/** The fields whose value differs from the record's — what a save or a draft sends. */
|
|
21
27
|
export function changesOf(record, values) {
|
|
@@ -39,16 +45,54 @@ export function missingOf(meta, values, fromServer) {
|
|
|
39
45
|
return state.required && state.visible && !state.readonly && empty;
|
|
40
46
|
});
|
|
41
47
|
}
|
|
42
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Where the server's word points inside the record, as one key: `"discount"`, `"lines/1/qty"`.
|
|
50
|
+
* A JSON pointer (RFC 6901), bare (`/discount`) or as a fragment (`#/values/lines/1/qty`) — the
|
|
51
|
+
* command's `values/` envelope dropped, `~1`/`~0` read back — or a path (`["lines", 1, "qty"]`).
|
|
52
|
+
* Errors and warnings are read with the same rule, so both land on the same cell.
|
|
53
|
+
*/
|
|
54
|
+
export function pathOf(at) {
|
|
55
|
+
if (typeof at !== "string")
|
|
56
|
+
return at.map(String).join("/");
|
|
57
|
+
const segments = at
|
|
58
|
+
.replace(/^#/, "")
|
|
59
|
+
.replace(/^\//, "")
|
|
60
|
+
.split("/")
|
|
61
|
+
.map((one) => one.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
62
|
+
if (segments[0] === "values" && segments.length > 1)
|
|
63
|
+
segments.shift();
|
|
64
|
+
return segments.join("/");
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The server's word on what did not validate, by where it points (`pathOf`): a field's own
|
|
68
|
+
* error under its name, a line's cell's under its whole path (`lines/1/qty`). The first word for
|
|
69
|
+
* a place wins. `errorAt` reads a field's, its lines' included.
|
|
70
|
+
*/
|
|
43
71
|
export function errorsByField(errors) {
|
|
44
72
|
const found = {};
|
|
45
73
|
for (const error of errors ?? []) {
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
found[
|
|
74
|
+
const at = pathOf(error.pointer);
|
|
75
|
+
if (at !== "" && found[at] === undefined)
|
|
76
|
+
found[at] = error.detail;
|
|
49
77
|
}
|
|
50
78
|
return found;
|
|
51
79
|
}
|
|
80
|
+
/** The error at `at` or under it (`lines` finds `lines/1/qty`): what marks a field invalid. */
|
|
81
|
+
export function errorAt(errors, at) {
|
|
82
|
+
const own = errors[at];
|
|
83
|
+
if (own !== undefined)
|
|
84
|
+
return own;
|
|
85
|
+
const under = Object.keys(errors).find((key) => key.startsWith(`${at}/`));
|
|
86
|
+
return under === undefined ? undefined : errors[under];
|
|
87
|
+
}
|
|
88
|
+
/** The warnings at `at` or under it — a line's (`lines/1`) finds its cells'. One with no path
|
|
89
|
+
* is placed by its field. */
|
|
90
|
+
export function adviceAt(advice, at) {
|
|
91
|
+
return advice.filter((one) => {
|
|
92
|
+
const key = one.path !== undefined && one.path.length > 0 ? pathOf(one.path) : (one.field ?? "");
|
|
93
|
+
return key === at || key.startsWith(`${at}/`);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
52
96
|
/**
|
|
53
97
|
* A record that does not exist yet: the defaults the model publishes for each field
|
|
54
98
|
* (`FieldMeta.default`, sincpro_framework's `defaults_of`), and nothing else.
|
package/dist/core/entity.d.ts
CHANGED
|
@@ -29,8 +29,10 @@ export type Entity<T extends AnyRecord = AnyRecord> = {
|
|
|
29
29
|
/** Where the workspace finds it: the list without an id, one record with it — the shape of a
|
|
30
30
|
* composer `ResourceRef`, built here so no screen writes `{ domain, kind, id }` by hand. */
|
|
31
31
|
ref: (id?: string) => EntityRef;
|
|
32
|
-
/** A record that does not exist yet — the form that creates one. Its view is the record's.
|
|
33
|
-
|
|
32
|
+
/** A record that does not exist yet — the form that creates one. Its view is the record's.
|
|
33
|
+
* With `values`, the form starts with them over the model's defaults: an invoice created
|
|
34
|
+
* from its customer starts with that customer (`startingValuesOf`). */
|
|
35
|
+
newRef: (values?: AnyRecord) => EntityRef;
|
|
34
36
|
/** Its list opened to CHOOSE one: a row answers whoever asked (composer's `api.pick`). With
|
|
35
37
|
* `query`, the list opens on that literal search — what was typed in the picker. */
|
|
36
38
|
chooserRef: (query?: string) => EntityRef;
|
|
@@ -80,6 +82,16 @@ export declare const PICK_PARAM = "pick";
|
|
|
80
82
|
export declare const QUERY_PARAM = "q";
|
|
81
83
|
/** The list a record was opened from (its `Trail`): «3 / 64» and the arrows to its neighbours. */
|
|
82
84
|
export declare const TRAIL_PARAM = "from";
|
|
85
|
+
/** What a new record starts with, as JSON: one param keeps each value's type (a number stays
|
|
86
|
+
* a number), where a param per field would turn all of them into text. */
|
|
87
|
+
export declare const WITH_PARAM = "with";
|
|
88
|
+
/**
|
|
89
|
+
* What a new record's reference says it starts with (`newRef(values)`), or nothing.
|
|
90
|
+
*
|
|
91
|
+
* Context: a reference survives a reload and a link, so its params can be anything a person
|
|
92
|
+
* typed in the address bar — a value that is not a JSON object is not a start, never an error.
|
|
93
|
+
*/
|
|
94
|
+
export declare function startingValuesOf(ref: Pick<EntityRef, "params">): AnyRecord;
|
|
83
95
|
/** A write: its method and its path, `{id}` where the record's key goes. */
|
|
84
96
|
export type WriteRoute = {
|
|
85
97
|
method: Method;
|
package/dist/core/entity.js
CHANGED
|
@@ -9,6 +9,29 @@ export const PICK_PARAM = "pick";
|
|
|
9
9
|
export const QUERY_PARAM = "q";
|
|
10
10
|
/** The list a record was opened from (its `Trail`): «3 / 64» and the arrows to its neighbours. */
|
|
11
11
|
export const TRAIL_PARAM = "from";
|
|
12
|
+
/** What a new record starts with, as JSON: one param keeps each value's type (a number stays
|
|
13
|
+
* a number), where a param per field would turn all of them into text. */
|
|
14
|
+
export const WITH_PARAM = "with";
|
|
15
|
+
/**
|
|
16
|
+
* What a new record's reference says it starts with (`newRef(values)`), or nothing.
|
|
17
|
+
*
|
|
18
|
+
* Context: a reference survives a reload and a link, so its params can be anything a person
|
|
19
|
+
* typed in the address bar — a value that is not a JSON object is not a start, never an error.
|
|
20
|
+
*/
|
|
21
|
+
export function startingValuesOf(ref) {
|
|
22
|
+
const written = ref.params?.[WITH_PARAM];
|
|
23
|
+
if (written === undefined)
|
|
24
|
+
return {};
|
|
25
|
+
try {
|
|
26
|
+
const read = JSON.parse(written);
|
|
27
|
+
return read !== null && typeof read === "object" && !Array.isArray(read)
|
|
28
|
+
? read
|
|
29
|
+
: {};
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
12
35
|
const METHODS = new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
13
36
|
/** `"POST /invoices/{id}/confirm"` → its method and path. A write without a method is a bug. */
|
|
14
37
|
export function writeRoute(text) {
|
|
@@ -32,7 +55,16 @@ export function entity(key, routes) {
|
|
|
32
55
|
domain,
|
|
33
56
|
kind,
|
|
34
57
|
ref: (id) => ({ domain, kind, ...(id === undefined || id === "" ? {} : { id }) }),
|
|
35
|
-
newRef: () => ({
|
|
58
|
+
newRef: (values) => ({
|
|
59
|
+
domain,
|
|
60
|
+
kind,
|
|
61
|
+
params: {
|
|
62
|
+
[NEW_PARAM]: "1",
|
|
63
|
+
...(values === undefined || Object.keys(values).length === 0
|
|
64
|
+
? {}
|
|
65
|
+
: { [WITH_PARAM]: JSON.stringify(values) }),
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
36
68
|
chooserRef: (query) => ({
|
|
37
69
|
domain,
|
|
38
70
|
kind,
|
package/dist/core/index.d.ts
CHANGED
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { type CachedTransport, cachedTransport, type CacheOptions, } from "./cache.js";
|
|
7
7
|
export { ENGLISH_FRAMEWORK_COPY, type FrameworkCopy, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "./copy.js";
|
|
8
|
-
export { changesOf, creationOf, defaultsOf, errorsByField, type FieldState, fieldStateOf, type FieldStates, missingOf, } from "./edit.js";
|
|
9
|
-
export { type Entity, entity, type EntityRef, type EntityRoutes, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, TRAIL_PARAM, type WriteRoute, writeRoute, } from "./entity.js";
|
|
8
|
+
export { type Advice, adviceAt, changesOf, creationOf, defaultsOf, errorAt, errorsByField, type FieldState, fieldStateOf, type FieldStates, lineStatesOf, missingOf, pathOf, type ServerFieldState, } from "./edit.js";
|
|
9
|
+
export { type Entity, entity, type EntityRef, type EntityRoutes, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, startingValuesOf, TRAIL_PARAM, WITH_PARAM, type WriteRoute, writeRoute, } from "./entity.js";
|
|
10
10
|
export { type FormLayout, formOf } from "./form.js";
|
|
11
11
|
export { type HistoryEntry, historyOf } from "./history.js";
|
|
12
|
+
export { addingOf, type AddingRule, blankLine, type Declared, editableLines, type LineAdding, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
|
|
12
13
|
export { defineList, type GroupLevel, isList, type ListDefinition, type ListSpec, type NamedFilter, scopeOf, } from "./list.js";
|
|
13
14
|
export { lookupOf, type LookupOption } from "./lookup.js";
|
|
14
15
|
export { detailOf, measuresOf, sumsOf } from "./measure.js";
|
|
@@ -24,3 +25,4 @@ export { completeMeta, type JsonSchema, metaFromSchema, type SchemaComponents, }
|
|
|
24
25
|
export { type RecordSummary, type SummaryFields, summaryFieldsOf, summaryOf, type SummaryPart, } from "./summary.js";
|
|
25
26
|
export { placeOf, stepIn, type Trail } from "./trail.js";
|
|
26
27
|
export { type Draft, explain, type Method, type One, type SendOptions, type Transport, TransportError, } from "./transport.js";
|
|
28
|
+
export { installTimeZone, instantOf, timeZoneNow, wallTimeOf, } from "./zone.js";
|
package/dist/core/index.js
CHANGED
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { cachedTransport, } from "./cache.js";
|
|
7
7
|
export { ENGLISH_FRAMEWORK_COPY, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "./copy.js";
|
|
8
|
-
export { changesOf, creationOf, defaultsOf, errorsByField, fieldStateOf, missingOf, } from "./edit.js";
|
|
9
|
-
export { entity, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, TRAIL_PARAM, writeRoute, } from "./entity.js";
|
|
8
|
+
export { adviceAt, changesOf, creationOf, defaultsOf, errorAt, errorsByField, fieldStateOf, lineStatesOf, missingOf, pathOf, } from "./edit.js";
|
|
9
|
+
export { entity, NEW_PARAM, pathFor, PICK_PARAM, QUERY_PARAM, startingValuesOf, TRAIL_PARAM, WITH_PARAM, writeRoute, } from "./entity.js";
|
|
10
10
|
export { formOf } from "./form.js";
|
|
11
11
|
export { historyOf } from "./history.js";
|
|
12
|
+
export { addingOf, blankLine, editableLines, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
|
|
12
13
|
export { defineList, isList, scopeOf, } from "./list.js";
|
|
13
14
|
export { lookupOf } from "./lookup.js";
|
|
14
15
|
export { detailOf, measuresOf, sumsOf } from "./measure.js";
|
|
@@ -24,3 +25,4 @@ export { completeMeta, metaFromSchema, } from "./schema.js";
|
|
|
24
25
|
export { summaryFieldsOf, summaryOf, } from "./summary.js";
|
|
25
26
|
export { placeOf, stepIn } from "./trail.js";
|
|
26
27
|
export { explain, TransportError, } from "./transport.js";
|
|
28
|
+
export { installTimeZone, instantOf, timeZoneNow, wallTimeOf, } from "./zone.js";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { AnyRecord, Meta } from "@sincpro/criteria";
|
|
2
|
+
/** The key a line is drawn and found by: its identity, or a local one while it has none. */
|
|
3
|
+
export declare function lineKey(line: AnyRecord, identity: string): string;
|
|
4
|
+
/** `next` is `line` edited: it keeps the line's local key. */
|
|
5
|
+
export declare function sameLine<T extends AnyRecord>(line: AnyRecord, next: T): T;
|
|
6
|
+
/** What the server answered about the list it was sent, each line keeping its key by position. */
|
|
7
|
+
export declare function linesAnswered(sent: readonly AnyRecord[], answered: readonly AnyRecord[]): AnyRecord[];
|
|
8
|
+
/**
|
|
9
|
+
* The lines a form can edit, or `null` when it holds only part of them: a list written back
|
|
10
|
+
* whole from one page would delete every line the page did not bring.
|
|
11
|
+
*/
|
|
12
|
+
export declare function editableLines(value: unknown): AnyRecord[] | null;
|
|
13
|
+
/** A blank line: the line model's defaults, never its identity — the server mints that. */
|
|
14
|
+
export declare function blankLine(defaults: AnyRecord, identity: string): AnyRecord;
|
|
15
|
+
/** The list with the line `key` moved before `before` (`null`: to the end). */
|
|
16
|
+
export declare function moved<T extends AnyRecord>(lines: readonly T[], identity: string, key: string, before: string | null): T[];
|
|
17
|
+
/** Where «Agregar una línea» writes the new line: a row of the table, or the line's dialog. */
|
|
18
|
+
export type LineAdding = "inline" | "editor";
|
|
19
|
+
/** Whether an aggregate of the application answers for `target` («Producto»). */
|
|
20
|
+
export type Declared = (target: string) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The fields a line is drawn and written by: its scalars, as a form's — never its identity
|
|
23
|
+
* (the server mints it) nor the bookkeeping. A many2one is its key (`product_code`), which the
|
|
24
|
+
* screen names by its relation (`product`).
|
|
25
|
+
*/
|
|
26
|
+
export declare function lineFields(definition: Meta | null): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Whether a field of a line can be written inside its cell.
|
|
29
|
+
*
|
|
30
|
+
* Context: a cell holds a control as wide as its column. A many2one is a picker only when the
|
|
31
|
+
* application declared the entity it points at — otherwise its key is an id nobody types.
|
|
32
|
+
* An embedded value or anything the table has no control for needs the dialog's room.
|
|
33
|
+
*/
|
|
34
|
+
export declare function writtenInCell(definition: Meta, field: string, declared: Declared): boolean;
|
|
35
|
+
/** What decides where a line is written, besides its model. */
|
|
36
|
+
export type AddingRule = {
|
|
37
|
+
/** Whether the application declared the entity a relation points at. */
|
|
38
|
+
declared: Declared;
|
|
39
|
+
/** The screen's choice: «editor» always holds, «inline» only where it works. */
|
|
40
|
+
asked?: LineAdding;
|
|
41
|
+
/** The fields drawn as columns, when the screen chose them. Without it, every line field. */
|
|
42
|
+
shown?: readonly string[];
|
|
43
|
+
/** The fields the screen writes with a control of its own: they fit a cell whatever their
|
|
44
|
+
* type — the screen said how. */
|
|
45
|
+
own?: ReadonlySet<string>;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* How «Agregar una línea» adds: in the table when every column a person may write fits a cell
|
|
49
|
+
* and nothing required is left out of the columns; in the dialog otherwise — a row that cannot
|
|
50
|
+
* be finished where it was opened is a trap.
|
|
51
|
+
*/
|
|
52
|
+
export declare function addingOf(definition: Meta | null, rule: AddingRule): LineAdding;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { BOOKKEEPING, defaultFields } from "./present.js";
|
|
2
|
+
import { relatedOf } from "./related.js";
|
|
3
|
+
import { relationFieldOf } from "./relation.js";
|
|
4
|
+
/**
|
|
5
|
+
* The lines of an aggregate as a form edits them: the whole list, in order.
|
|
6
|
+
*
|
|
7
|
+
* Context: sincpro_framework writes the lines of an aggregate in the same command as the
|
|
8
|
+
* aggregate — the list as the form holds it, whole and in order, with the version it was read
|
|
9
|
+
* at (without it, a whole list would delete a line someone else added). A line that came from
|
|
10
|
+
* the server carries its id; a new one goes WITHOUT one — the server refuses an id it does not
|
|
11
|
+
* know and mints its own. So a new line's key on screen is kept APART from the line (a weak map
|
|
12
|
+
* on the line object), carried to each edited copy, and matched by POSITION to what the server
|
|
13
|
+
* answers about the list it was sent. Adding, removing, undoing and reordering are the screen's:
|
|
14
|
+
* nothing about them travels but the resulting list — no per-line commands on the wire.
|
|
15
|
+
*/
|
|
16
|
+
const keys = new WeakMap();
|
|
17
|
+
let minted = 0;
|
|
18
|
+
/** The key a line is drawn and found by: its identity, or a local one while it has none. */
|
|
19
|
+
export function lineKey(line, identity) {
|
|
20
|
+
const own = line[identity];
|
|
21
|
+
if (own !== undefined && own !== null && own !== "")
|
|
22
|
+
return String(own);
|
|
23
|
+
let key = keys.get(line);
|
|
24
|
+
if (key === undefined) {
|
|
25
|
+
key = `new-${++minted}`;
|
|
26
|
+
keys.set(line, key);
|
|
27
|
+
}
|
|
28
|
+
return key;
|
|
29
|
+
}
|
|
30
|
+
/** `next` is `line` edited: it keeps the line's local key. */
|
|
31
|
+
export function sameLine(line, next) {
|
|
32
|
+
const key = keys.get(line);
|
|
33
|
+
if (key !== undefined && !keys.has(next))
|
|
34
|
+
keys.set(next, key);
|
|
35
|
+
return next;
|
|
36
|
+
}
|
|
37
|
+
/** What the server answered about the list it was sent, each line keeping its key by position. */
|
|
38
|
+
export function linesAnswered(sent, answered) {
|
|
39
|
+
return answered.map((line, i) => (sent[i] === undefined ? line : sameLine(sent[i], line)));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The lines a form can edit, or `null` when it holds only part of them: a list written back
|
|
43
|
+
* whole from one page would delete every line the page did not bring.
|
|
44
|
+
*/
|
|
45
|
+
export function editableLines(value) {
|
|
46
|
+
if (Array.isArray(value))
|
|
47
|
+
return value;
|
|
48
|
+
const related = relatedOf(value);
|
|
49
|
+
return related.partial ? null : [...related.items];
|
|
50
|
+
}
|
|
51
|
+
/** A blank line: the line model's defaults, never its identity — the server mints that. */
|
|
52
|
+
export function blankLine(defaults, identity) {
|
|
53
|
+
const { [identity]: _id, ...rest } = defaults;
|
|
54
|
+
return { ...rest };
|
|
55
|
+
}
|
|
56
|
+
/** The list with the line `key` moved before `before` (`null`: to the end). */
|
|
57
|
+
export function moved(lines, identity, key, before) {
|
|
58
|
+
const line = lines.find((one) => lineKey(one, identity) === key);
|
|
59
|
+
if (line === undefined)
|
|
60
|
+
return [...lines];
|
|
61
|
+
const rest = lines.filter((one) => one !== line);
|
|
62
|
+
const at = before === null
|
|
63
|
+
? rest.length
|
|
64
|
+
: rest.findIndex((one) => lineKey(one, identity) === before);
|
|
65
|
+
return [
|
|
66
|
+
...rest.slice(0, at < 0 ? rest.length : at),
|
|
67
|
+
line,
|
|
68
|
+
...rest.slice(at < 0 ? rest.length : at),
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
/** The value types a cell has a control for: each one fits the width of a column. */
|
|
72
|
+
const CELL_TYPES = new Set([
|
|
73
|
+
"text",
|
|
74
|
+
"integer",
|
|
75
|
+
"number",
|
|
76
|
+
"date",
|
|
77
|
+
"datetime",
|
|
78
|
+
"boolean",
|
|
79
|
+
"text[]",
|
|
80
|
+
]);
|
|
81
|
+
/**
|
|
82
|
+
* The fields a line is drawn and written by: its scalars, as a form's — never its identity
|
|
83
|
+
* (the server mints it) nor the bookkeeping. A many2one is its key (`product_code`), which the
|
|
84
|
+
* screen names by its relation (`product`).
|
|
85
|
+
*/
|
|
86
|
+
export function lineFields(definition) {
|
|
87
|
+
if (definition === null)
|
|
88
|
+
return [];
|
|
89
|
+
return defaultFields(definition).filter((field) => field !== definition.identity && !BOOKKEEPING.has(field));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Whether a field of a line can be written inside its cell.
|
|
93
|
+
*
|
|
94
|
+
* Context: a cell holds a control as wide as its column. A many2one is a picker only when the
|
|
95
|
+
* application declared the entity it points at — otherwise its key is an id nobody types.
|
|
96
|
+
* An embedded value or anything the table has no control for needs the dialog's room.
|
|
97
|
+
*/
|
|
98
|
+
export function writtenInCell(definition, field, declared) {
|
|
99
|
+
const relation = relationFieldOf(definition, field);
|
|
100
|
+
if (relation !== undefined)
|
|
101
|
+
return !relation.many && declared(relation.target);
|
|
102
|
+
return CELL_TYPES.has(definition.fields[field]?.type ?? "");
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* How «Agregar una línea» adds: in the table when every column a person may write fits a cell
|
|
106
|
+
* and nothing required is left out of the columns; in the dialog otherwise — a row that cannot
|
|
107
|
+
* be finished where it was opened is a trap.
|
|
108
|
+
*/
|
|
109
|
+
export function addingOf(definition, rule) {
|
|
110
|
+
if (rule.asked === "editor" || definition === null)
|
|
111
|
+
return "editor";
|
|
112
|
+
const fields = lineFields(definition);
|
|
113
|
+
const shown = new Set(rule.shown ?? fields);
|
|
114
|
+
const writable = (field) => definition.fields[field]?.readonly !== true;
|
|
115
|
+
const fits = (field) => rule.own?.has(field) === true || writtenInCell(definition, field, rule.declared);
|
|
116
|
+
const ok = fields
|
|
117
|
+
.filter(writable)
|
|
118
|
+
.every((field) => shown.has(field) ? fits(field) : definition.fields[field]?.required !== true);
|
|
119
|
+
return ok ? "inline" : "editor";
|
|
120
|
+
}
|
package/dist/core/list.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export type ListDefinition<T extends AnyRecord = AnyRecord> = {
|
|
|
41
41
|
/** The cuts it offers by name in the search bar. */
|
|
42
42
|
filters?: readonly NamedFilter<T>[];
|
|
43
43
|
/** The faces it offers, the first one shown. */
|
|
44
|
-
views?: readonly ("table" | "rows" | "board")[];
|
|
44
|
+
views?: readonly ("table" | "rows" | "board" | "sheet" | "pivot")[];
|
|
45
45
|
/** Grouped from the start — the server counts the groups. */
|
|
46
46
|
groupBy?: readonly GroupLevel[];
|
|
47
47
|
};
|
package/dist/core/lookup.d.ts
CHANGED
|
@@ -15,5 +15,7 @@ export type LookupOption = {
|
|
|
15
15
|
label: string;
|
|
16
16
|
detail?: string;
|
|
17
17
|
image?: string;
|
|
18
|
+
/** The row it was read from: what an entity's own presentation draws the choice with. */
|
|
19
|
+
record?: AnyRecord;
|
|
18
20
|
};
|
|
19
21
|
export declare function lookupOf(meta: Meta | null | undefined, rows: readonly AnyRecord[], summary?: SummaryFields): LookupOption[];
|
package/dist/core/lookup.js
CHANGED
|
@@ -9,6 +9,8 @@ export function lookupOf(meta, rows, summary = {}) {
|
|
|
9
9
|
const imageField = summaryFieldsOf(meta, row, summary).image;
|
|
10
10
|
const picture = imageField === undefined ? undefined : row[imageField];
|
|
11
11
|
const image = typeof picture === "string" && picture !== "" ? { image: picture } : {};
|
|
12
|
-
return label === id
|
|
12
|
+
return label === id
|
|
13
|
+
? { id, label, ...image, record: row }
|
|
14
|
+
: { id, label, detail: id, ...image, record: row };
|
|
13
15
|
});
|
|
14
16
|
}
|
package/dist/core/present.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { choiceLabelOf, labelOf, } from "@sincpro/criteria";
|
|
2
2
|
import { frameworkCopy } from "./copy.js";
|
|
3
3
|
import { relatedOf } from "./related.js";
|
|
4
|
+
import { timeZoneNow } from "./zone.js";
|
|
4
5
|
/** Present when a field is named that the model does not declare: drawn plain, never thrown. */
|
|
5
6
|
const UNKNOWN = {
|
|
6
7
|
type: "unknown",
|
|
@@ -63,10 +64,14 @@ function decimals(text) {
|
|
|
63
64
|
*/
|
|
64
65
|
const formatters = new Map();
|
|
65
66
|
function dateFormat(locale, withTime) {
|
|
66
|
-
|
|
67
|
+
// An instant reads on the wall clock of the installed zone; a calendar day has no zone.
|
|
68
|
+
const zone = withTime ? timeZoneNow() : "";
|
|
69
|
+
const key = `d|${locale ?? ""}|${withTime}|${zone}`;
|
|
67
70
|
let format = formatters.get(key);
|
|
68
71
|
if (format === undefined) {
|
|
69
|
-
format = new Intl.DateTimeFormat(locale, withTime
|
|
72
|
+
format = new Intl.DateTimeFormat(locale, withTime
|
|
73
|
+
? { dateStyle: "medium", timeStyle: "short", timeZone: zone }
|
|
74
|
+
: { dateStyle: "medium" });
|
|
70
75
|
formatters.set(key, format);
|
|
71
76
|
}
|
|
72
77
|
return format;
|
package/dist/core/rest.d.ts
CHANGED
|
@@ -3,15 +3,11 @@ import { type Transport } from "./transport.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* The REST wire of sincpro_framework (`FastApiGateway`).
|
|
5
5
|
*
|
|
6
|
-
* Context:
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* - it sends `pack()` (base64url), and the REST entrypoint reads the parameter as plain JSON
|
|
12
|
-
* and refuses anything else («criteria is not JSON») — here it travels as JSON.
|
|
13
|
-
*
|
|
14
|
-
* Once criteria fixes both, this keeps only what it adds: `one()`.
|
|
6
|
+
* Context: a list is criteria's `restSource` (0.3.1 sends the criteria as plain JSON and joins
|
|
7
|
+
* a route that carries its own query, `/projects?tenant_id=acme` — the two things forge's
|
|
8
|
+
* console found wrong in 0.3.0, fixed there). What this adds is what criteria does not know:
|
|
9
|
+
* one record (`one()`), a write (`send()`, with its `Idempotency-Key`), and its refusals as a
|
|
10
|
+
* `TransportError`, the one error every screen explains.
|
|
15
11
|
*
|
|
16
12
|
* const transport = restTransport({
|
|
17
13
|
* base: "/v1",
|