@sincpro/web-framework 0.4.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +48 -44
  2. package/dist/core/discovery.d.ts +47 -0
  3. package/dist/core/discovery.js +68 -0
  4. package/dist/core/edit.d.ts +35 -6
  5. package/dist/core/edit.js +57 -4
  6. package/dist/core/entity.d.ts +18 -3
  7. package/dist/core/entity.js +27 -1
  8. package/dist/core/ids.d.ts +17 -0
  9. package/dist/core/ids.js +52 -0
  10. package/dist/core/index.d.ts +3 -2
  11. package/dist/core/index.js +3 -2
  12. package/dist/core/meta.d.ts +7 -0
  13. package/dist/core/meta.js +1 -1
  14. package/dist/core/metas.d.ts +4 -5
  15. package/dist/core/rest.d.ts +8 -0
  16. package/dist/core/rest.js +62 -3
  17. package/dist/core/schema.d.ts +5 -12
  18. package/dist/core/trail.js +1 -4
  19. package/dist/react/index.d.ts +1 -0
  20. package/dist/react/index.js +1 -0
  21. package/dist/react/scope.d.ts +23 -0
  22. package/dist/react/scope.js +12 -0
  23. package/dist/react/useGroups.js +1 -2
  24. package/dist/react/useHistory.js +1 -1
  25. package/dist/react/useListing.js +14 -9
  26. package/dist/react/useLookup.js +2 -3
  27. package/dist/react/usePivot.js +0 -1
  28. package/dist/react/useRecord.d.ts +9 -2
  29. package/dist/react/useRecord.js +53 -12
  30. package/dist/react/useRelated.js +2 -2
  31. package/dist/web/list/EntitySearchBar.js +2 -2
  32. package/dist/web/list/search.js +1 -1
  33. package/dist/web/record/EntityPicker.d.ts +14 -7
  34. package/dist/web/record/EntityPicker.js +21 -6
  35. package/dist/web/record/EntityTags.d.ts +5 -3
  36. package/dist/web/record/EntityTags.js +29 -6
  37. package/dist/web/record/control.d.ts +4 -4
  38. package/dist/web/record/control.js +7 -17
  39. package/dist/web/record/lines.js +28 -11
  40. package/dist/web/record/opening.d.ts +17 -3
  41. package/dist/web/record/opening.js +12 -0
  42. package/dist/web/workspace/composer.js +9 -7
  43. package/dist/web/workspace/workspace.d.ts +6 -2
  44. package/dist/web/workspace/workspace.js +6 -2
  45. package/package.json +7 -7
@@ -8,6 +8,7 @@ import { useListing } from "../../react/useListing.js";
8
8
  import { excluding, useLookup } from "../../react/useLookup.js";
9
9
  import { EntityList } from "../list/EntityList.js";
10
10
  import { over, presentationOf } from "../list/presentation.js";
11
+ import { chooserScopeOf, useRecordOpening } from "./opening.js";
11
12
  import { Dialog, IconButton, Picker } from "@sincpro/web-ui";
12
13
  import { TextSearch } from "lucide-react";
13
14
  import { useState } from "react";
@@ -23,9 +24,13 @@ import { useState } from "react";
23
24
  * searched, ordered and paged by the server, where clicking a row answers the field. An entity
24
25
  * without a search template is filtered where it is.
25
26
  *
26
- * Inside a workspace, «open» and the chooser can be the composer's instead (`api.open`,
27
- * `api.pick`): pass `onOpen` / `onBrowseAll` and they replace the defaults — `chooserIn(api,
28
- * entity, onChange)` is that `onBrowseAll`.
27
+ * Inside a workspace, «open» and the chooser ARE the workspace's (`RecordOpening`, which
28
+ * `entityView` gives every view): the chosen record opens where the workspace puts it, and
29
+ * «Buscar más…» is the entity's own list opened to choose — carrying the picker's cut, so it
30
+ * offers only what the picker would. A picker written by hand used to open web-ui's `Dialog`
31
+ * there unless the screen remembered to pass `onBrowseAll`. The built-in chooser is for a
32
+ * picker outside any workspace, or where the workspace's must not be used (`ownChooser`).
33
+ * `onOpen` / `onBrowseAll` still replace either.
29
34
  *
30
35
  * `criteria` narrows what may be chosen — the contacts of the chosen customer — in the picker
31
36
  * and in its chooser alike; the server applies it, and a new one starts the choices over. A
@@ -47,9 +52,10 @@ import { useState } from "react";
47
52
  * <EntityPicker entity={activeCustomers} columns={["name", "tax_id", "city"]} … />
48
53
  * <EntityPicker entity={tenants} none="Sin tenant" exclude={sharedWith} … />
49
54
  */
50
- export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onBrowseAll, criteria, columns, browse = true, none, exclude, placeholder, disabled, "aria-label": ariaLabel, }) {
55
+ export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onBrowseAll, ownChooser = false, criteria, columns, browse = true, none, exclude, placeholder, disabled, "aria-label": ariaLabel, }) {
51
56
  const base = isList(entity) ? entity.entity : entity;
52
57
  const { metas } = useFramework();
58
+ const opening = useRecordOpening();
53
59
  const lookup = useLookup(entity, {
54
60
  ...(criteria === undefined ? {} : { criteria }),
55
61
  ...(value === undefined ? {} : { value }),
@@ -63,7 +69,16 @@ export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onB
63
69
  : [{ id: "", name: none === true ? frameworkCopy().picker.none : none }];
64
70
  const look = presentationOf(entity).option;
65
71
  const [choosing, setChoosing] = useState(false);
66
- const browseAll = onBrowseAll ?? (() => setChoosing(true));
72
+ const opens = onOpen ??
73
+ (opening === null
74
+ ? undefined
75
+ : (id, to) => opening.open(base.ref(id), to));
76
+ const targets = openTargets ?? opening?.targets;
77
+ const choose = ownChooser ? undefined : opening?.choose;
78
+ const browseAll = onBrowseAll ??
79
+ (choose === undefined
80
+ ? () => setChoosing(true)
81
+ : (query) => choose(base, (id) => onChange(id), query, chooserScopeOf(entity, scope)));
67
82
  const picker = (_jsx(Picker, { items: [
68
83
  ...nothing,
69
84
  ...lookup.options.map((one) => over({
@@ -85,7 +100,7 @@ export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onB
85
100
  : look(lookup.chosen.record).name) ?? lookup.chosen.label,
86
101
  }), onChange: (id) => onChange(id, lookup.options.find((one) => one.id === id)?.record), ...(lookup.searchable ? { onSearch: lookup.search } : {}),
87
102
  // «Loading» only before there is anything: refining keeps the ten on screen.
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 }) }));
103
+ loading: lookup.loading && lookup.options.length === 0, ...(opens === undefined || value === "" ? {} : { onOpen: opens }), ...(targets === undefined ? {} : { openTargets: targets }), onBrowseAll: browseAll, ...(placeholder === undefined ? {} : { placeholder }), ...(disabled === undefined ? {} : { disabled }), ...(ariaLabel === undefined ? {} : { "aria-label": ariaLabel }) }));
89
104
  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) => {
90
105
  onChange(id, row);
91
106
  setChoosing(false);
@@ -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
- * Opening a chip is the composer's (`onOpen` — a preview by default: a chip is a glance at one
17
- * of many), and «Buscar más…» is the list that adds (`onBrowseAll`, `api.pick` with the list in
18
- * its choosing mode). Without a workspace a chip is a value.
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 { useLookup } from "../../react/useLookup.js";
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
- * Opening a chip is the composer's (`onOpen` — a preview by default: a chip is a glance at one
19
- * of many), and «Buscar más…» is the list that adds (`onBrowseAll`, `api.pick` with the list in
20
- * its choosing mode). Without a workspace a chip is a value.
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 = (isList(entity) ? entity.entity : entity).summary.person === true;
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 } : {}), ...(onOpen === undefined ? {} : { onOpen }), ...(openTarget === undefined ? {} : { openTarget }), ...(onBrowseAll === undefined ? {} : { onBrowseAll }), ...(placeholder === undefined ? {} : { placeholder }), ...(disabled === undefined ? {} : { disabled }), ...(ariaLabel === undefined ? {} : { "aria-label": ariaLabel }) }));
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. Inside a line (`ownChooser`: its row or its
31
- * dialog) «Buscar más…» is the picker's own chooser, never the workspace's: the workspace opens
32
- * it outside the line — a row commits when the focus leaves it, and the answer would land on a
33
- * line no longer being written; over the line's dialog it would be a modal over a modal.
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. Inside a line (`ownChooser`: its row or its
48
- * dialog) «Buscar más…» is the picker's own chooser, never the workspace's: the workspace opens
49
- * it outside the line — a row commits when the focus leaves it, and the answer would land on a
50
- * line no longer being written; over the line's dialog it would be a modal over a modal.
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
- const opening = useRecordOpening();
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 } : {}), ...(opening === null
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
  }
@@ -1,12 +1,13 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { choicesOf } from "@sincpro/criteria";
4
- import { adviceAt, defaultsOf, errorAt, pathOf } from "../../core/edit.js";
4
+ import { adviceAt, defaultsOf, errorAt, linePlacesOf, pathOf, } from "../../core/edit.js";
5
5
  import { addingOf, blankLine, lineFields, lineKey, moved, sameLine, writtenInCell, } from "../../core/lines.js";
6
6
  import { textOf, viewOf } from "../../core/present.js";
7
7
  import { entityFor, relationFieldOf, } from "../../core/relation.js";
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, ownChooser: true, standalone: inCell, onChange: (id, chosen) => write({ [relation.key]: id, [relation.relation]: chosen ?? null }) }));
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,34 +148,41 @@ export function RecordLinesEditor({ record, name, lines, look = {}, }) {
146
148
  ...(one.numeric === undefined ? {} : { numeric: one.numeric }),
147
149
  })),
148
150
  ];
149
- return (_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)),
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) => {
153
155
  const index = indexOf(line);
154
- const at = `${name}/${index}/${column}`;
156
+ const places = linePlacesOf(name, line, index, identity).map((one) => `${one}/${column}`);
155
157
  const state = edit.cell(name, index, column);
156
- const error = errorAt(edit.errors, at);
157
- const warned = adviceAt(edit.advice, at)[0];
158
+ const error = places
159
+ .map((at) => errorAt(edit.errors, at))
160
+ .find((one) => one !== undefined);
161
+ const warned = places.flatMap((at) => adviceAt(edit.advice, at))[0];
158
162
  return {
159
163
  readonly: state.readonly,
160
164
  required: state.required,
161
165
  hidden: !state.visible,
162
166
  ...(error === undefined ? {} : { error }),
163
- ...(warned === undefined ? {} : { flag: { tone: "warn", label: warned.message } }),
167
+ ...(warned === undefined
168
+ ? {}
169
+ : { flag: { tone: warned.blocks_save ? "bad" : "warn", label: warned.message } }),
164
170
  };
165
171
  },
166
172
  // The line's own flag: what points at the line and at no cell drawn — the line as a
167
173
  // whole, or a field it has no column for (an id the server does not know).
168
174
  flag: (line) => {
169
- const at = `${name}/${indexOf(line)}`;
170
- const onLine = (key) => key === at ||
171
- (key.startsWith(`${at}/`) && !drawn.has(key.slice(at.length + 1).split("/")[0]));
175
+ const places = linePlacesOf(name, line, indexOf(line), identity);
176
+ const onLine = (key) => places.some((at) => key === at ||
177
+ (key.startsWith(`${at}/`) &&
178
+ !drawn.has(key.slice(at.length + 1).split("/")[0])));
172
179
  const error = Object.entries(edit.errors).find(([key]) => onLine(key))?.[1];
173
180
  if (error !== undefined)
174
181
  return { tone: "bad", label: error };
175
182
  const warned = edit.advice.find((one) => onLine(pathOf(one.path ?? [one.field ?? ""])));
176
- return warned === undefined ? null : { tone: "warn", label: warned.message };
183
+ return warned === undefined
184
+ ? null
185
+ : { tone: warned.blocks_save ? "bad" : "warn", label: warned.message };
177
186
  }, editor: (draft, set, state) => {
178
187
  if (look.editor !== undefined)
179
188
  return look.editor(draft, set, state);
@@ -187,4 +196,12 @@ export function RecordLinesEditor({ record, name, lines, look = {}, }) {
187
196
  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
197
  }) }));
189
198
  } }));
199
+ // Inside a line «Buscar más…» is the picker's own chooser, never the workspace's — the
200
+ // screen's own controls included: the workspace opens it outside the line, a row commits when
201
+ // the focus leaves it, and the answer would land on a line no longer being written (over the
202
+ // line's dialog, a modal over a modal). Opening a chosen record is still the workspace's.
203
+ if (opening === null || opening.choose === undefined)
204
+ return table;
205
+ const { choose: _, ...inLine } = opening;
206
+ return _jsx(RecordOpeningProvider, { value: inLine, children: table });
190
207
  }
@@ -1,5 +1,6 @@
1
- import type { AnyRecord } from "@sincpro/criteria";
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. Without it the picker brings its own chooser. */
24
- choose?: (entity: Entity, answer: (id: string) => void, query: string) => void;
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?.selection;
22
+ }
@@ -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 { listRoute, 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]);
@@ -53,7 +54,11 @@ export function entityView(entity, options) {
53
54
  const One = loaded.record ?? options.record ?? recordOf(entity);
54
55
  return function EntityView(props) {
55
56
  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
+ // 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 });
57
62
  };
58
63
  }
59
64
  // Built once: a second open of the view must be the same component, or it would remount. A
@@ -73,10 +78,7 @@ export function entityView(entity, options) {
73
78
  meta = (await options.transport.list(route, { pagination: { limit: 1 } })).meta;
74
79
  if (meta?.search == null)
75
80
  return [];
76
- const page = await options.transport.list(route, {
77
- ...matching(meta, query),
78
- meta: false,
79
- });
81
+ const page = await options.transport.list(route, matching(meta, query));
80
82
  // ⌘K writes text: of the entity's look of a choice, its name and its meta.
81
83
  const look = presentationOf(entity).option;
82
84
  return lookupOf(meta, page.rows, entity.summary).map((one) => {
@@ -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» of an `EntityPicker` as the composer's chooser: the entity's own list
26
- * opens in a window and the row clicked there answers the field.
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» of an `EntityPicker` as the composer's chooser: the entity's own list
57
- * opens in a window and the row clicked there answers the field.
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.1",
3
+ "version": "1.0.0",
4
4
  "description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,19 +23,19 @@
23
23
  "printWidth": 94
24
24
  },
25
25
  "peerDependencies": {
26
- "@sincpro/criteria": "^0.3.1",
27
- "@sincpro/criteria-react": "^0.3.1",
26
+ "@sincpro/criteria": "^1.0.0",
27
+ "@sincpro/criteria-react": "^1.0.0",
28
28
  "@sincpro/web-composer": "^1.5.0",
29
- "@sincpro/web-ui": "^1.9.0",
29
+ "@sincpro/web-ui": "^1.11.1",
30
30
  "react": ">=19",
31
31
  "react-dom": ">=19"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@eslint/js": "^10.0.1",
35
- "@sincpro/criteria": "^0.3.1",
36
- "@sincpro/criteria-react": "^0.3.1",
35
+ "@sincpro/criteria": "^1.0.0",
36
+ "@sincpro/criteria-react": "^1.0.0",
37
37
  "@sincpro/web-composer": "^1.5.0",
38
- "@sincpro/web-ui": "^1.9.0",
38
+ "@sincpro/web-ui": "^1.11.1",
39
39
  "@storybook/addon-a11y": "10.6.5",
40
40
  "@storybook/addon-docs": "10.6.5",
41
41
  "@storybook/addon-mcp": "10.6.5",