@sincpro/web-framework 0.3.0 → 0.4.1

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.
Files changed (40) hide show
  1. package/dist/core/cache.d.ts +10 -2
  2. package/dist/core/cache.js +31 -9
  3. package/dist/core/copy.d.ts +4 -0
  4. package/dist/core/copy.js +4 -0
  5. package/dist/core/edit.d.ts +5 -0
  6. package/dist/core/edit.js +6 -2
  7. package/dist/core/entity.d.ts +21 -2
  8. package/dist/core/entity.js +30 -3
  9. package/dist/core/history.js +5 -1
  10. package/dist/core/index.d.ts +2 -1
  11. package/dist/core/index.js +2 -1
  12. package/dist/core/lines.d.ts +1 -2
  13. package/dist/core/lines.js +2 -2
  14. package/dist/core/present.js +7 -2
  15. package/dist/core/zone.d.ts +27 -0
  16. package/dist/core/zone.js +75 -0
  17. package/dist/react/context.d.ts +5 -1
  18. package/dist/react/context.js +10 -2
  19. package/dist/react/index.d.ts +1 -1
  20. package/dist/react/index.js +1 -1
  21. package/dist/react/useCommand.js +1 -1
  22. package/dist/react/useListing.d.ts +1 -1
  23. package/dist/react/useListing.js +2 -7
  24. package/dist/react/useLookup.d.ts +10 -1
  25. package/dist/react/useLookup.js +29 -3
  26. package/dist/react/useRecord.d.ts +7 -2
  27. package/dist/react/useRecord.js +42 -20
  28. package/dist/web/list/rowCommands.js +2 -1
  29. package/dist/web/record/CommandButton.d.ts +3 -1
  30. package/dist/web/record/CommandButton.js +2 -2
  31. package/dist/web/record/EntityPicker.d.ts +15 -3
  32. package/dist/web/record/EntityPicker.js +35 -14
  33. package/dist/web/record/control.d.ts +2 -1
  34. package/dist/web/record/control.js +9 -2
  35. package/dist/web/workspace/SincproApp.d.ts +18 -4
  36. package/dist/web/workspace/SincproApp.js +18 -7
  37. package/dist/web/workspace/composer.d.ts +20 -1
  38. package/dist/web/workspace/composer.js +22 -9
  39. package/dist/web/workspace/record.js +12 -2
  40. package/package.json +3 -3
@@ -1,4 +1,5 @@
1
1
  "use client";
2
+ import { merge } from "@sincpro/criteria";
2
3
  import { isList } from "../core/list.js";
3
4
  import { lookupOf } from "../core/lookup.js";
4
5
  import { useFramework } from "./context.js";
@@ -6,17 +7,42 @@ import { useListing } from "./useListing.js";
6
7
  import { useEffect, useRef, useState } from "react";
7
8
  /** Ten: what a dropdown shows without scrolling, and what Odoo's many2one asks for. */
8
9
  const FIRST = 10;
10
+ /** What may be chosen: the screen's own cut, without the keys it excludes. */
11
+ export function excluding(criteria, exclude, meta) {
12
+ if (exclude === undefined || exclude.length === 0 || meta == null)
13
+ return criteria;
14
+ const out = {
15
+ where: {
16
+ field: meta.get_id || meta.identity || "id",
17
+ operator: "not in",
18
+ value: [...exclude],
19
+ },
20
+ };
21
+ return criteria === undefined ? out : merge(criteria, out);
22
+ }
9
23
  export function useLookup(
10
24
  /** The entity, or a named list of it: «active customers» chooses only those. */
11
25
  entity, options = {}) {
12
- const { transport } = useFramework();
26
+ const { transport, metas } = useFramework();
27
+ const base = isList(entity) ? entity.entity : entity;
28
+ // The key field to exclude by comes with the definition: known already, or with the first
29
+ // answer — then this renders again and the reading starts over without the excluded.
30
+ const [definition, setDefinition] = useState(() => ({
31
+ key: base.key,
32
+ meta: metas.get(base.key),
33
+ }));
34
+ const keyed = definition.key === base.key ? definition.meta : metas.get(base.key);
35
+ const scope = excluding(options.criteria, options.exclude, keyed);
13
36
  // «More», not pages: a choice list grows downwards, and its ceiling keeps it light.
14
37
  const listing = useListing(entity, {
15
38
  paging: "more",
16
39
  pageSize: options.pageSize ?? FIRST,
17
- ...(options.criteria === undefined ? {} : { criteria: options.criteria }),
40
+ ...(scope === undefined ? {} : { criteria: scope }),
18
41
  });
19
- const base = isList(entity) ? entity.entity : entity;
42
+ useEffect(() => {
43
+ if (keyed === undefined && listing.meta !== null)
44
+ setDefinition({ key: base.key, meta: listing.meta });
45
+ }, [keyed, listing.meta, base.key]);
20
46
  const choices = lookupOf(listing.meta, listing.rows, base.summary);
21
47
  // Every choice seen is remembered: the chosen are named even after the page moved on.
22
48
  const seen = useRef(new Map());
@@ -18,6 +18,11 @@ import { type Draft } from "../core/transport.js";
18
18
  * in between, the server answers 409 and the screen says so instead of overwriting.
19
19
  * - **drafts** — an edit kept between requests (sincpro_framework's `Drafts`) comes back with
20
20
  * the record and is shown as restored; `keep()` stores the current one.
21
+ * - **`Edit`** — an entity that declares `edit` speaks sincpro_framework's `Edit` on it for all
22
+ * three: `keep()` is `save_draft`, `save()` is `save` — the record whole, the fields changed,
23
+ * the draft version read and the stored version it started from — and `discard()` is
24
+ * `discard`, which drops the draft on the server too. Without it, a save sends the changed
25
+ * fields and the version to `save`.
21
26
  * - **creating** — with no id it is a record that does not exist yet: it starts from the
22
27
  * defaults the model publishes, previews like any other, and `save()` sends it to the
23
28
  * entity's `create` route with an `Idempotency-Key` (a retry never creates two). When the
@@ -74,8 +79,8 @@ export type Editing = {
74
79
  draft: Draft | null;
75
80
  save: () => Promise<boolean>;
76
81
  discard: () => void;
77
- /** Store the current edit as a draft — only when the entity declares where, and the record
78
- * exists: a draft is kept against a record. */
82
+ /** Store the current edit as a draft — only when the entity declares where (`draft` or
83
+ * `edit`), and the record exists: a draft is kept against a record. */
79
84
  keep?: () => Promise<void>;
80
85
  /** What the last create answered, when it did not say the new record's identity. */
81
86
  created: unknown;
@@ -145,10 +145,19 @@ export function useRecord(entity, opened) {
145
145
  return;
146
146
  cancelPreview();
147
147
  pause.current = setTimeout(() => {
148
+ // A key of the route (`{tenant_id}`) is a field of the record on screen. One it lacks is
149
+ // a preview not asked — never an error thrown out of a timer.
150
+ let path;
151
+ try {
152
+ path = pathFor(preview, isNew ? undefined : id, { ...record, ...next });
153
+ }
154
+ catch {
155
+ return;
156
+ }
148
157
  const aborter = new AbortController();
149
158
  asking.current = aborter;
150
159
  transport
151
- .send(preview.method, pathFor(preview, isNew ? undefined : id), {
160
+ .send(preview.method, path, {
152
161
  id: isNew ? null : id,
153
162
  values: isNew ? { ...record, ...next } : changesOf(record, next),
154
163
  changed: [name],
@@ -181,6 +190,17 @@ export function useRecord(entity, opened) {
181
190
  else
182
191
  setFailure(error);
183
192
  };
193
+ // sincpro_framework's `Edit`: the record as the form holds it, whole; the fields changed; the
194
+ // draft version read (`0`: none) — another tab that kept first wins —, and the stored version
195
+ // the edit started from. Without an `action` it is the server's default, `save_draft`.
196
+ const editOf = (action) => ({
197
+ id,
198
+ values,
199
+ changed: Object.keys(changed),
200
+ version: draft?.version ?? 0,
201
+ ...(typeof version === "number" ? { origin_version: version } : {}),
202
+ ...(action === undefined ? {} : { action }),
203
+ });
184
204
  const edit = {
185
205
  values,
186
206
  changed,
@@ -209,17 +229,16 @@ export function useRecord(entity, opened) {
209
229
  save: async () => {
210
230
  if (isNew)
211
231
  return create();
212
- const route = entity.save;
232
+ const route = entity.edit ?? entity.save;
213
233
  if (route === undefined)
214
234
  throw new Error(`${entity.key} declares no save route`);
215
235
  cancelPreview();
216
236
  setSaving(true);
217
237
  setFailure(null);
218
238
  try {
219
- await transport.send(route.method, pathFor(route, id), {
220
- ...changed,
221
- ...(version === undefined ? {} : { version }),
222
- });
239
+ await transport.send(route.method, pathFor(route, id, values), entity.edit === undefined
240
+ ? { ...changed, ...(version === undefined ? {} : { version }) }
241
+ : editOf("save"));
223
242
  setDraft(null);
224
243
  reload();
225
244
  return true;
@@ -236,24 +255,27 @@ export function useRecord(entity, opened) {
236
255
  setSaving(false);
237
256
  }
238
257
  },
239
- discard: forget,
258
+ discard: () => {
259
+ forget();
260
+ // The draft lives on the server: discarding only here would bring it back on the next read.
261
+ const route = entity.edit;
262
+ if (route === undefined || isNew || draft === null)
263
+ return;
264
+ setDraft(null);
265
+ // Through the promise: a route key the record lacks is refused like any failure.
266
+ Promise.resolve()
267
+ .then(() => transport.send(route.method, pathFor(route, id, values), editOf("discard")))
268
+ .then(() => mounted.current && reload())
269
+ .catch((error) => mounted.current && refused(error));
270
+ },
240
271
  created,
241
- ...(entity.draft === undefined || isNew
272
+ ...((entity.edit ?? entity.draft) === undefined || isNew
242
273
  ? {}
243
274
  : {
244
275
  keep: async () => {
245
- const route = entity.draft;
246
- // sincpro_framework's `Edit`: the record as the form holds it, whole; the fields
247
- // changed; the draft version read (`0`: none) — another tab that kept first wins —,
248
- // and the stored version the edit started from.
276
+ const route = (entity.edit ?? entity.draft);
249
277
  try {
250
- const kept = await transport.send(route.method, pathFor(route, id), {
251
- id,
252
- values,
253
- changed: Object.keys(changed),
254
- version: draft?.version ?? 0,
255
- ...(typeof version === "number" ? { origin_version: version } : {}),
256
- });
278
+ const kept = await transport.send(route.method, pathFor(route, id, values), entity.edit === undefined ? editOf() : editOf("save_draft"));
257
279
  const now = kept.draft;
258
280
  if (now)
259
281
  setDraft({
@@ -281,7 +303,7 @@ export function useRecord(entity, opened) {
281
303
  const body = creationOf(state.meta, values);
282
304
  const idempotencyKey = creating.current.keyFor(body);
283
305
  try {
284
- const answer = await transport.send(route.method, pathFor(route), body, undefined, { idempotencyKey });
306
+ const answer = await transport.send(route.method, pathFor(route, undefined, body), body, undefined, { idempotencyKey });
285
307
  creating.current.settle(null);
286
308
  if (!mounted.current)
287
309
  return true;
@@ -24,7 +24,8 @@ export function useRowCommands(listing, commands) {
24
24
  setRunning((now) => new Set(now).add(gesture));
25
25
  setError(null);
26
26
  try {
27
- await transport.send(route.method, pathFor(route, id), body, undefined, {
27
+ // A key of the route beyond `{id}` (`{tenant_id}`) is the row's, unless the body says it.
28
+ await transport.send(route.method, pathFor(route, id, { ...row, ...body }), body, undefined, {
28
29
  idempotencyKey: retry.keyFor(body),
29
30
  });
30
31
  retry.settle(null);
@@ -9,7 +9,7 @@ import type { Entity } from "../../core/entity.js";
9
9
  * shows THAT in the window: the confirmation is the consequence, in the server's words, not a
10
10
  * question. A refusal is shown where it happened, with what to do.
11
11
  */
12
- export declare function CommandButton<T extends AnyRecord, R = unknown>({ entity, command, id, body, label, destructive, role, onDone, }: {
12
+ export declare function CommandButton<T extends AnyRecord, R = unknown>({ entity, command, id, body, label, destructive, role, disabled, onDone, }: {
13
13
  entity: Entity<T>;
14
14
  command: string;
15
15
  id?: string;
@@ -18,5 +18,7 @@ export declare function CommandButton<T extends AnyRecord, R = unknown>({ entity
18
18
  /** Asks the server what it would do before doing it. */
19
19
  destructive?: boolean;
20
20
  role?: "primary" | "secondary" | "ghost";
21
+ /** Not offered right now — «Mover» with no other tenant chosen. The server still decides. */
22
+ disabled?: boolean;
21
23
  onDone?: (answer: R) => void;
22
24
  }): import("react").JSX.Element;
@@ -14,7 +14,7 @@ import { useState } from "react";
14
14
  * shows THAT in the window: the confirmation is the consequence, in the server's words, not a
15
15
  * question. A refusal is shown where it happened, with what to do.
16
16
  */
17
- export function CommandButton({ entity, command, id, body, label, destructive = false, role = "secondary", onDone, }) {
17
+ export function CommandButton({ entity, command, id, body, label, destructive = false, role = "secondary", disabled = false, onDone, }) {
18
18
  const copy = frameworkCopy().command;
19
19
  const action = useCommand(entity, command);
20
20
  const [open, setOpen] = useState(false);
@@ -36,5 +36,5 @@ export function CommandButton({ entity, command, id, body, label, destructive =
36
36
  setOpen(false);
37
37
  action.reset();
38
38
  };
39
- return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: destructive ? "secondary" : role, disabled: action.busy, onClick: () => void (destructive ? ask() : run()), children: label }), open ? (_jsx(Dialog, { open: true, title: label, onClose: close, footer: destructive && action.error === null ? (_jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { size: "sm", role: "secondary", onClick: close, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy || action.rehearsal === null, onClick: () => void run(), children: copy.confirm })] })) : undefined, children: action.error !== null ? (_jsx(Refused, { error: action.error })) : action.rehearsal === null ? (_jsx("p", { className: "text-meta text-muted", children: copy.rehearsing })) : (_jsx("p", { className: "text-ink", children: action.rehearsal.text })) })) : null] }));
39
+ return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: destructive ? "secondary" : role, disabled: disabled || action.busy, onClick: () => void (destructive ? ask() : run()), children: label }), open ? (_jsx(Dialog, { open: true, title: label, onClose: close, footer: destructive && action.error === null ? (_jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { size: "sm", role: "secondary", onClick: close, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy || action.rehearsal === null, onClick: () => void run(), children: copy.confirm })] })) : undefined, children: action.error !== null ? (_jsx(Refused, { error: action.error })) : action.rehearsal === null ? (_jsx("p", { className: "text-meta text-muted", children: copy.rehearsing })) : (_jsx("p", { className: "text-ink", children: action.rehearsal.text })) })) : null] }));
40
40
  }
@@ -28,10 +28,17 @@ import { type OpenTarget } from "@sincpro/web-ui";
28
28
  * way to the server's literal search. The chooser is a table — the columns the list declares,
29
29
  * or `columns` — searched by the entity's literal search on the server.
30
30
  *
31
+ * A field that may stay empty offers that as a choice (`none`): «Ninguno», or the screen's own
32
+ * word («Sin tenant»), answered as `""`. web-ui's `Picker` has no way to clear a choice, so it
33
+ * is the first option, while nothing is typed. `exclude` leaves keys out of the choices — the
34
+ * tenants a project is already shared with —, in the picker and its chooser, and the SERVER
35
+ * leaves them out (`useLookup exclude`).
36
+ *
31
37
  * <EntityPicker entity={customers} value={id} onChange={set} />
32
38
  * <EntityPicker entity={activeCustomers} columns={["name", "tax_id", "city"]} … />
39
+ * <EntityPicker entity={tenants} none="Sin tenant" exclude={sharedWith} … />
33
40
  */
34
- export declare function EntityPicker<T extends AnyRecord>({ entity, value, onChange, onOpen, openTargets, onBrowseAll, criteria, columns, browse, placeholder, disabled, "aria-label": ariaLabel, }: {
41
+ export declare function EntityPicker<T extends AnyRecord>({ entity, value, onChange, onOpen, openTargets, onBrowseAll, criteria, columns, browse, none, exclude, placeholder, disabled, "aria-label": ariaLabel, }: {
35
42
  /** What is chosen from: an entity, or a named list of it (its cut, columns and title). */
36
43
  entity: Entity<T> | ListDefinition<T>;
37
44
  /** The chooser's columns. Without it, the named list's, or every scalar field. */
@@ -40,9 +47,14 @@ export declare function EntityPicker<T extends AnyRecord>({ entity, value, onCha
40
47
  browse?: boolean;
41
48
  /** Which records may be chosen at all: applied by the server under what is typed. */
42
49
  criteria?: Criteria<T>;
50
+ /** The field may stay empty: a first choice that answers `""` — `true` says «Ninguno», a
51
+ * text is the screen's own word for it. */
52
+ none?: boolean | string;
53
+ /** Keys never offered — those already chosen elsewhere. Left out by the server. */
54
+ exclude?: readonly string[];
43
55
  value?: string;
44
- /** The key chosen, and its record when the choice brought it — what a line keeps beside the
45
- * key so its cell names the choice without asking again. */
56
+ /** The key chosen (`""` for `none`), and its record when the choice brought it — what a line
57
+ * keeps beside the key so its cell names the choice without asking again. */
46
58
  onChange: (id: string, chosen?: T) => void;
47
59
  /** Open the chosen record where the person asked — in composer,
48
60
  * `(id, to) => openIn(api, entity.ref(id), to)`. */
@@ -3,8 +3,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
3
3
  import { nameOf } from "@sincpro/criteria";
4
4
  import { frameworkCopy } from "../../core/copy.js";
5
5
  import { isList } from "../../core/list.js";
6
+ import { useFramework } from "../../react/context.js";
6
7
  import { useListing } from "../../react/useListing.js";
7
- import { useLookup } from "../../react/useLookup.js";
8
+ import { excluding, useLookup } from "../../react/useLookup.js";
8
9
  import { EntityList } from "../list/EntityList.js";
9
10
  import { over, presentationOf } from "../list/presentation.js";
10
11
  import { Dialog, IconButton, Picker } from "@sincpro/web-ui";
@@ -36,27 +37,47 @@ import { useState } from "react";
36
37
  * way to the server's literal search. The chooser is a table — the columns the list declares,
37
38
  * or `columns` — searched by the entity's literal search on the server.
38
39
  *
40
+ * A field that may stay empty offers that as a choice (`none`): «Ninguno», or the screen's own
41
+ * word («Sin tenant»), answered as `""`. web-ui's `Picker` has no way to clear a choice, so it
42
+ * is the first option, while nothing is typed. `exclude` leaves keys out of the choices — the
43
+ * tenants a project is already shared with —, in the picker and its chooser, and the SERVER
44
+ * leaves them out (`useLookup exclude`).
45
+ *
39
46
  * <EntityPicker entity={customers} value={id} onChange={set} />
40
47
  * <EntityPicker entity={activeCustomers} columns={["name", "tax_id", "city"]} … />
48
+ * <EntityPicker entity={tenants} none="Sin tenant" exclude={sharedWith} … />
41
49
  */
42
- export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onBrowseAll, criteria, columns, browse = true, placeholder, disabled, "aria-label": ariaLabel, }) {
50
+ export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onBrowseAll, criteria, columns, browse = true, none, exclude, placeholder, disabled, "aria-label": ariaLabel, }) {
51
+ const base = isList(entity) ? entity.entity : entity;
52
+ const { metas } = useFramework();
43
53
  const lookup = useLookup(entity, {
44
54
  ...(criteria === undefined ? {} : { criteria }),
45
55
  ...(value === undefined ? {} : { value }),
56
+ ...(exclude === undefined ? {} : { exclude }),
46
57
  });
47
- const person = (isList(entity) ? entity.entity : entity).summary.person === true;
58
+ // The chooser opens after the picker read the definition: it excludes from its first page.
59
+ const scope = excluding(criteria, exclude, metas.get(base.key));
60
+ const person = base.summary.person === true;
61
+ const nothing = none === undefined || none === false || lookup.text !== ""
62
+ ? []
63
+ : [{ id: "", name: none === true ? frameworkCopy().picker.none : none }];
48
64
  const look = presentationOf(entity).option;
49
65
  const [choosing, setChoosing] = useState(false);
50
66
  const browseAll = onBrowseAll ?? (() => setChoosing(true));
51
- const picker = (_jsx(Picker, { items: lookup.options.map((one) => over({
52
- id: one.id,
53
- name: one.label,
54
- ...(one.detail === undefined ? {} : { meta: one.detail, haystack: one.detail }),
55
- // A person or a company is chosen by their face: the photo, or their initials.
56
- ...(person ? { avatar: one.image ?? true } : {}),
57
- },
58
- // The entity's own look of a choice, over the default (`presented`).
59
- look === undefined || one.record === undefined ? undefined : look(one.record))), ...(value === undefined ? {} : { value }), ...(lookup.chosen === undefined
67
+ const picker = (_jsx(Picker, { items: [
68
+ ...nothing,
69
+ ...lookup.options.map((one) => over({
70
+ id: one.id,
71
+ name: one.label,
72
+ ...(one.detail === undefined ? {} : { meta: one.detail, haystack: one.detail }),
73
+ // A person or a company is chosen by their face: the photo, or their initials.
74
+ ...(person ? { avatar: one.image ?? true } : {}),
75
+ },
76
+ // The entity's own look of a choice, over the default (`presented`).
77
+ look === undefined || one.record === undefined
78
+ ? undefined
79
+ : look(one.record))),
80
+ ], ...(value === undefined ? {} : { value }), ...(lookup.chosen === undefined
60
81
  ? {}
61
82
  : {
62
83
  valueLabel: (lookup.chosen.record === undefined || look === undefined
@@ -64,8 +85,8 @@ export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onB
64
85
  : look(lookup.chosen.record).name) ?? lookup.chosen.label,
65
86
  }), onChange: (id) => onChange(id, lookup.options.find((one) => one.id === id)?.record), ...(lookup.searchable ? { onSearch: lookup.search } : {}),
66
87
  // «Loading» only before there is anything: refining keeps the ten on screen.
67
- loading: lookup.loading && lookup.options.length === 0, ...(onOpen === undefined ? {} : { onOpen }), ...(openTargets === undefined ? {} : { openTargets }), onBrowseAll: browseAll, ...(placeholder === undefined ? {} : { placeholder }), ...(disabled === undefined ? {} : { disabled }), ...(ariaLabel === undefined ? {} : { "aria-label": ariaLabel }) }));
68
- return (_jsxs(_Fragment, { children: [browse ? (_jsxs("span", { className: "flex min-w-0 items-start gap-1", children: [_jsx("span", { className: "min-w-0 flex-1", children: picker }), _jsx(IconButton, { icon: TextSearch, label: frameworkCopy().picker.browse, onClick: () => browseAll(lookup.text), ...(disabled === undefined ? {} : { disabled }) })] })) : (picker), choosing ? (_jsx(Chooser, { entity: entity, ...(columns === undefined ? {} : { columns }), ...(criteria === undefined ? {} : { criteria }), onChoose: (id, row) => {
88
+ loading: lookup.loading && lookup.options.length === 0, ...(onOpen === undefined || value === "" ? {} : { onOpen }), ...(openTargets === undefined ? {} : { openTargets }), onBrowseAll: browseAll, ...(placeholder === undefined ? {} : { placeholder }), ...(disabled === undefined ? {} : { disabled }), ...(ariaLabel === undefined ? {} : { "aria-label": ariaLabel }) }));
89
+ return (_jsxs(_Fragment, { children: [browse ? (_jsxs("span", { className: "flex min-w-0 items-start gap-1", children: [_jsx("span", { className: "min-w-0 flex-1", children: picker }), _jsx(IconButton, { icon: TextSearch, label: frameworkCopy().picker.browse, onClick: () => browseAll(lookup.text), ...(disabled === undefined ? {} : { disabled }) })] })) : (picker), choosing ? (_jsx(Chooser, { entity: entity, ...(columns === undefined ? {} : { columns }), ...(scope === undefined ? {} : { criteria: scope }), onChoose: (id, row) => {
69
90
  onChange(id, row);
70
91
  setChoosing(false);
71
92
  }, onClose: () => setChoosing(false) })) : null] }));
@@ -13,7 +13,8 @@ export type FieldControl = {
13
13
  standalone?: boolean;
14
14
  };
15
15
  /**
16
- * The control a field's TYPE asks for — a choice, a number, a date, a yes/no, a list of words,
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,
17
18
  * a text.
18
19
  * Shared by a record's field (`RecordField`) and a line's cell and dialog (`RecordLinesEditor`):
19
20
  * one rule for what a value is edited with.
@@ -1,10 +1,12 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { instantOf, timeZoneNow, wallTimeOf } from "../../core/zone.js";
3
4
  import { EntityPicker } from "./EntityPicker.js";
4
5
  import { useRecordOpening } from "./opening.js";
5
- import { Checkbox, DatePicker, NumberInput, Select, TagsField, TextInput, } from "@sincpro/web-ui";
6
+ import { Checkbox, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextInput, } from "@sincpro/web-ui";
6
7
  /**
7
- * The control a field's TYPE asks for — a choice, a number, a date, a yes/no, a list of words,
8
+ * The control a field's TYPE asks for — a choice, a number, a date, a date and time, a yes/no, a
9
+ * list of words,
8
10
  * a text.
9
11
  * Shared by a record's field (`RecordField`) and a line's cell and dialog (`RecordLinesEditor`):
10
12
  * one rule for what a value is edited with.
@@ -22,6 +24,11 @@ export function controlFor(control, type, exact, choices) {
22
24
  return (_jsx(NumberInput, { value: value === null || value === undefined || value === "" ? "" : Number(value),
23
25
  // A decimal travels as text so no digit is lost; the server reads it that way back.
24
26
  onChange: (next) => set(next === "" ? null : exact ? String(next) : next), ...named }));
27
+ case "datetime": {
28
+ // An instant from the server, typed on the wall clock of the installed zone.
29
+ const zone = timeZoneNow();
30
+ return (_jsx(DateTimePicker, { value: typeof value === "string" && value !== "" ? wallTimeOf(value, zone) : null, onChange: (wall) => set(wall === null ? null : instantOf(wall, zone)), ...named }));
31
+ }
25
32
  case "date":
26
33
  return (_jsx(DatePicker, { value: typeof value === "string" && value !== "" ? value : null, onChange: set, ...named }));
27
34
  case "text[]": {
@@ -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 (the app draws its own, around this or beside it).
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, }: {
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[];
@@ -37,4 +42,13 @@ export declare function SincproApp({ transport, views, start, language, metas, e
37
42
  * `false` asks the server every time.
38
43
  */
39
44
  cache?: CacheOptions | false;
45
+ /** Where the business is (`"America/La_Paz"`): every date and time on its wall clock.
46
+ * Without it, the browser's. */
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;
40
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 (the app draws its own, around this or beside it).
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 = {}, }) {
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(() => (cache === false ? transport : cachedTransport(transport, cache)),
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 workspace = useWorkspace();
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 }), children: _jsx(ToastProvider, { children: _jsx("div", { className: "flex h-dvh min-h-0 flex-col bg-ground", children: _jsx(Composer, { workspace: workspace, registry: registry, skin: skin, ...(empty === undefined ? {} : { empty }) }) }) }) }));
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,7 +1,7 @@
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 } from "../../core/entity.js";
5
5
  import { lookupOf } from "../../core/lookup.js";
6
6
  import { useListing } from "../../react/useListing.js";
7
7
  import { EntityList } from "../list/EntityList.js";
@@ -45,13 +45,20 @@ function recordOf(entity) {
45
45
  };
46
46
  }
47
47
  export function entityView(entity, options) {
48
- const List = options.list ?? listOf(entity);
49
- const One = options.record ?? recordOf(entity);
50
48
  let meta = options.meta ?? null;
51
- function EntityView(props) {
52
- const record = props.resource.id !== undefined || props.resource.params?.[NEW_PARAM] !== undefined;
53
- return (_jsx(InWorkspace, { api: props.api, children: record ? _jsx(One, { ...props }) : _jsx(List, { ...props }) }));
49
+ const route = listRoute(entity.list, options.search?.params);
50
+ async function screens() {
51
+ const loaded = options.load === undefined ? {} : await options.load();
52
+ const List = loaded.list ?? options.list ?? listOf(entity);
53
+ const One = loaded.record ?? options.record ?? recordOf(entity);
54
+ return function EntityView(props) {
55
+ const record = props.resource.id !== undefined || props.resource.params?.[NEW_PARAM] !== undefined;
56
+ return (_jsx(InWorkspace, { api: props.api, children: record ? _jsx(One, { ...props }) : _jsx(List, { ...props }) }));
57
+ };
54
58
  }
59
+ // Built once: a second open of the view must be the same component, or it would remount. A
60
+ // chunk that failed to arrive is asked again next time.
61
+ let view = null;
55
62
  return {
56
63
  domain: entity.domain,
57
64
  kind: entity.kind,
@@ -63,10 +70,10 @@ export function entityView(entity, options) {
63
70
  if (query.trim() === "")
64
71
  return [];
65
72
  if (meta === null)
66
- meta = (await options.transport.list(entity.list, { pagination: { limit: 1 } })).meta;
73
+ meta = (await options.transport.list(route, { pagination: { limit: 1 } })).meta;
67
74
  if (meta?.search == null)
68
75
  return [];
69
- const page = await options.transport.list(entity.list, {
76
+ const page = await options.transport.list(route, {
70
77
  ...matching(meta, query),
71
78
  meta: false,
72
79
  });
@@ -82,7 +89,13 @@ export function entityView(entity, options) {
82
89
  };
83
90
  });
84
91
  },
85
- load: async () => EntityView,
92
+ load: () => {
93
+ view ??= screens().catch((failure) => {
94
+ view = null;
95
+ throw failure;
96
+ });
97
+ return view;
98
+ },
86
99
  };
87
100
  }
88
101
  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
- const stamp = (one) => one?.at == null ? undefined : { at: one.at, by: one.by ?? "—" };
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, { identity: {
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 } }),