@sincpro/web-framework 3.5.0 → 3.6.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 (41) hide show
  1. package/README.md +2 -0
  2. package/dist/core/command.d.ts +16 -0
  3. package/dist/core/command.js +17 -0
  4. package/dist/core/copy.d.ts +16 -0
  5. package/dist/core/copy.js +26 -0
  6. package/dist/core/history.d.ts +16 -4
  7. package/dist/core/history.js +20 -17
  8. package/dist/core/index.d.ts +4 -3
  9. package/dist/core/index.js +3 -2
  10. package/dist/core/list.d.ts +12 -0
  11. package/dist/core/list.js +14 -0
  12. package/dist/core/present.d.ts +12 -0
  13. package/dist/core/present.js +39 -0
  14. package/dist/react/index.d.ts +2 -0
  15. package/dist/react/index.js +2 -0
  16. package/dist/react/useBatchCommand.d.ts +50 -0
  17. package/dist/react/useBatchCommand.js +124 -0
  18. package/dist/react/useCommand.js +3 -4
  19. package/dist/react/useSelection.d.ts +37 -0
  20. package/dist/react/useSelection.js +40 -0
  21. package/dist/web/index.d.ts +2 -0
  22. package/dist/web/index.js +2 -0
  23. package/dist/web/list/BatchProgress.d.ts +16 -0
  24. package/dist/web/list/BatchProgress.js +40 -0
  25. package/dist/web/list/EntityList.d.ts +12 -6
  26. package/dist/web/list/EntityList.js +37 -22
  27. package/dist/web/list/EntitySearchBar.d.ts +9 -0
  28. package/dist/web/list/EntitySearchBar.js +15 -5
  29. package/dist/web/list/pivot.d.ts +5 -1
  30. package/dist/web/list/pivot.js +28 -11
  31. package/dist/web/list/records.d.ts +100 -0
  32. package/dist/web/list/records.js +219 -0
  33. package/dist/web/list/search.d.ts +0 -17
  34. package/dist/web/list/search.js +33 -5
  35. package/dist/web/record/EntityTags.d.ts +5 -2
  36. package/dist/web/record/EntityTags.js +34 -12
  37. package/dist/web/record/opening.d.ts +6 -2
  38. package/dist/web/workspace/SincproApp.js +13 -2
  39. package/dist/web/workspace/composer.d.ts +1 -1
  40. package/dist/web/workspace/composer.js +23 -25
  41. package/package.json +9 -9
@@ -0,0 +1,219 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { keysOf, listRoute, SelectionTooLarge, } from "@sincpro/client-framework";
4
+ import { matching } from "@sincpro/criteria";
5
+ import { frameworkCopy } from "../../core/copy.js";
6
+ import { explain } from "../../core/explain.js";
7
+ import { lookupOf } from "../../core/lookup.js";
8
+ import { entityFor } from "../../core/relation.js";
9
+ import { summaryOf } from "../../core/summary.js";
10
+ import { useFramework } from "../../react/context.js";
11
+ import { BATCH_LIMIT } from "../../react/useBatchCommand.js";
12
+ import { presentationOf } from "./presentation.js";
13
+ import { modelOf } from "./search.js";
14
+ import { createContext, useContext, useMemo } from "react";
15
+ /**
16
+ * The records of an entity that match a typed text, as a person picks them by name — a ⌘K hit,
17
+ * a relation's record in the search bar: the entity's LITERAL search (`matching`: its search
18
+ * template and a short page), each record whole, read as its name and, beside it, what tells it
19
+ * apart — the entity's `option` look, else its summary's description or type. Never its key.
20
+ *
21
+ * await findChoices(transport, clientes, clienteMeta, "/clientes", "andres", "es")
22
+ * -> [{ id: "C-7", name: "Andrés Pérez", detail: "NIT 4455667" }, …]
23
+ *
24
+ * Context: `matching` asks for references (identity and display), and the `option` look and the
25
+ * summary read fields a reference does not carry: ⌘K's detail was always empty against the real
26
+ * backend (#48). The question keeps `matching`'s template and its page, and brings each record
27
+ * whole. ⌘K and the search bar's records (web-ui 2.7) read a record the same way, here.
28
+ */
29
+ export async function findChoices(transport, entity, meta, route, text, locale, signal) {
30
+ const { specification: _reference, ...question } = matching(meta, text);
31
+ const page = await transport.list(route, question, signal);
32
+ const look = presentationOf(entity).option;
33
+ return lookupOf(meta, page.rows, entity.summary).map((one) => {
34
+ const own = look === undefined || one.record === undefined ? {} : look(one.record);
35
+ const summary = one.record === undefined
36
+ ? undefined
37
+ : summaryOf(meta, one.record, {
38
+ fields: entity.summary ?? {},
39
+ ...(locale === undefined ? {} : { locale }),
40
+ });
41
+ const detail = own.meta ?? summary?.description ?? summary?.type ?? undefined;
42
+ return {
43
+ id: one.id,
44
+ name: own.name ?? one.label,
45
+ ...(detail === undefined ? {} : { detail }),
46
+ };
47
+ });
48
+ }
49
+ /** Where an entity is listed, or `undefined` when only under another record (`/{id}/lines`). */
50
+ function routeOf(entity) {
51
+ try {
52
+ return listRoute(entity.list);
53
+ }
54
+ catch {
55
+ return undefined;
56
+ }
57
+ }
58
+ /** An entity's definition: known, or read once (one row) and kept for every place after. */
59
+ async function metaOf(framework, entity, signal) {
60
+ const known = framework.metas.get(entity.key);
61
+ if (known !== undefined)
62
+ return known;
63
+ const route = routeOf(entity);
64
+ if (route === undefined)
65
+ return undefined;
66
+ const read = (await framework.transport.list(route, { pagination: { limit: 1 } }, signal))
67
+ .meta;
68
+ if (read == null)
69
+ return undefined;
70
+ framework.metas.set(entity.key, read);
71
+ return read;
72
+ }
73
+ /**
74
+ * web-ui's `searchRecords` (2.7) answered by the framework: the records of a relation the search
75
+ * bar unfolds and the criteria builder picks — «andres» → the customers that match —, each
76
+ * chosen by its key and read by its name.
77
+ *
78
+ * 1. The relation names an aggregate: its entity among the application's (`entityFor`); one the
79
+ * application did not declare finds nothing — the bar still offers the relation's text.
80
+ * 2. Keys instead of a text (a filter read back from a link): their names, through the book every
81
+ * cell asks (`NameBook`: one request per entity, kept) — a key without one reads as itself.
82
+ * 3. Else the entity's literal search (`findChoices`), its definition known or read once.
83
+ */
84
+ export function recordsSearch(framework, locale) {
85
+ return async ({ relation, text, keys, signal }) => {
86
+ const entity = entityFor(framework.entities, relation, framework.metas.get);
87
+ if (entity === undefined)
88
+ return [];
89
+ if (keys !== undefined)
90
+ return Promise.all(keys.map(async (key) => ({
91
+ id: key,
92
+ name: (await framework.names.nameOf(entity, String(key))) ?? String(key),
93
+ })));
94
+ const route = routeOf(entity);
95
+ const meta = await metaOf(framework, entity, signal);
96
+ if (route === undefined || meta === undefined)
97
+ return [];
98
+ const choices = await findChoices(framework.transport, entity, meta, route, text, locale, signal);
99
+ return choices.map((one) => ({
100
+ id: one.id,
101
+ name: one.name,
102
+ ...(one.detail === undefined ? {} : { meta: one.detail }),
103
+ }));
104
+ };
105
+ }
106
+ /** `recordsSearch` over the framework's context: the screens' transport, its definitions and
107
+ * its names, in the provider's language. */
108
+ export function useSearchRecords() {
109
+ const { transport, metas, names, entities, locale } = useFramework();
110
+ return useMemo(() => recordsSearch({ transport, metas, names, entities }, locale), [transport, metas, names, entities, locale]);
111
+ }
112
+ /**
113
+ * web-ui's `loadModel` (2.8) answered by the framework: the model at the end of a path of
114
+ * relations — «Cliente › País» —, what the criteria builder walks to offer a related record's
115
+ * fields and the records themselves.
116
+ *
117
+ * await modelLoader(framework, facturaMeta, "es")(["customer"]) -> the customers' model
118
+ *
119
+ * 1. From the root's definition, each name of the path is a relation of the model before it.
120
+ * 2. Its model is the relation's own definition, when the server published it inside; else its
121
+ * entity's (`entityFor` by the aggregate it names), known or read once.
122
+ * Final: that definition as web-ui reads a model (`modelOf`); a path that leads nowhere — a name
123
+ * the model lacks, a relation to an entity the application did not declare — is refused.
124
+ */
125
+ export function modelLoader(framework, root, locale) {
126
+ const next = async (meta, name) => {
127
+ const field = meta.fields[name];
128
+ if (field === undefined)
129
+ return undefined;
130
+ if (field.definition)
131
+ return field.definition;
132
+ const entity = typeof field.relation === "string"
133
+ ? entityFor(framework.entities, field.relation, framework.metas.get)
134
+ : undefined;
135
+ return entity === undefined ? undefined : metaOf(framework, entity);
136
+ };
137
+ return async (path) => {
138
+ let meta = root;
139
+ for (const name of path) {
140
+ const found = await next(meta, name);
141
+ if (found === undefined)
142
+ throw new Error(`no model at ${path.join(" › ")}`);
143
+ meta = found;
144
+ }
145
+ return modelOf(meta, locale);
146
+ };
147
+ }
148
+ /** `modelLoader` over the framework's context, from a list's definition (none yet: none). */
149
+ export function useLoadModel(root) {
150
+ const { transport, metas, names, entities, locale } = useFramework();
151
+ return useMemo(() => root == null
152
+ ? undefined
153
+ : modelLoader({ transport, metas, names, entities }, root, locale), [root, transport, metas, names, entities, locale]);
154
+ }
155
+ /**
156
+ * web-ui's `browseRecords` (2.8) answered by the framework: «Buscar más…» under the records of a
157
+ * relation opens its entity's list to choose — several when the place takes several, one
158
+ * otherwise —, on what was typed and without what is already chosen; the keys chosen are answered
159
+ * named.
160
+ *
161
+ * 1. The relation's entity (`entityFor`); one the application did not declare is not browsed.
162
+ * 2. What is chosen is left out of the chooser (`not in` its keys), as a picker's chooser does.
163
+ * 3. Several: the chooser answers a `Selection`, read as keys with a ceiling (`keysOf`,
164
+ * `BATCH_LIMIT`) — past it nothing is chosen and `refused` says why. One: its key.
165
+ * Final: the keys, named through `names` (the `NameBook`), handed to web-ui (`choose`).
166
+ */
167
+ export function recordsBrowser(framework, open, names, refused) {
168
+ return (browse) => {
169
+ const entity = entityFor(framework.entities, browse.relation, framework.metas.get);
170
+ if (entity === undefined)
171
+ return;
172
+ const meta = framework.metas.get(entity.key);
173
+ const identity = meta?.get_id || meta?.identity || "id";
174
+ const chosen = browse.chosen.map((one) => String(one.id));
175
+ const scope = chosen.length === 0
176
+ ? undefined
177
+ : { field: identity, operator: "not in", value: chosen };
178
+ const answer = (keys) => names({
179
+ relation: browse.relation,
180
+ path: browse.path,
181
+ text: "",
182
+ keys,
183
+ signal: new AbortController().signal,
184
+ }).then(browse.choose, refused);
185
+ const route = routeOf(entity);
186
+ if (browse.many && open.chooseMany !== undefined && route !== undefined)
187
+ open.chooseMany(entity, (selection) => void keysOf(selection, {
188
+ transport: framework.transport,
189
+ route,
190
+ identity,
191
+ limit: BATCH_LIMIT,
192
+ }).then(answer, refused), browse.text, scope);
193
+ else
194
+ open.choose?.(entity, (id) => void answer([id]), browse.text, scope);
195
+ };
196
+ }
197
+ /**
198
+ * What a person is told when choosing records failed — too many chosen to take at once
199
+ * (`SelectionTooLarge`), in the framework's words; anything else, as the server explained it —,
200
+ * as a web-ui toast.
201
+ */
202
+ export function refusalNotice(failure) {
203
+ if (failure instanceof SelectionTooLarge)
204
+ return {
205
+ tone: "warn",
206
+ message: frameworkCopy().batch.tooMany(failure.size, failure.limit),
207
+ };
208
+ const { heading, sentence } = explain(failure);
209
+ return { tone: "bad", message: heading, detail: sentence };
210
+ }
211
+ const Browser = createContext(null);
212
+ /** «Buscar más…» for every search bar below — what a workspace view gives its screens. */
213
+ export function RecordsBrowserProvider({ value, children, }) {
214
+ return _jsx(Browser.Provider, { value: value, children: children });
215
+ }
216
+ /** The view's «Buscar más…», or `null` outside a workspace. */
217
+ export function useRecordsBrowser() {
218
+ return useContext(Browser);
219
+ }
@@ -1,22 +1,5 @@
1
1
  import { type Meta } from "@sincpro/criteria";
2
2
  import type { ModelDefinition, SearchFacet } from "@sincpro/web-ui";
3
- /**
4
- * The model, as web-ui's search bar and criteria builder read it.
5
- *
6
- * Context: web-ui keeps its OWN vocabulary of a model (`ModelDefinition`), written before the
7
- * framework settled its wire, and the two drifted: `identifiedBy` against `identified_by`, one
8
- * `translations` object against a `label` on each field. web-ui is right to own it — it is a
9
- * design system and must not depend on one backend — so the translation lives here, the one
10
- * place that knows both.
11
- *
12
- * Known gap: web-ui's field has `choices` but no word for each choice, so the bar offers an
13
- * enum's raw values («paid») where a cell says «Pagada». Fixing it is web-ui's.
14
- *
15
- * `texts` keeps only those plain text fields: web-ui's bar offers a typed word in EVERY text
16
- * field of the model it is handed (its `facets` are read only without one), so the bar is handed
17
- * the model with the text fields a person types into (`facetsOf`) — and the criteria builder the
18
- * whole one.
19
- */
20
3
  export declare function modelOf(meta: Meta, locale?: string, texts?: readonly string[]): ModelDefinition;
21
4
  /**
22
5
  * Where a typed text can be looked for: the fields the screen names (`defineList facets`), else
@@ -1,4 +1,4 @@
1
- import { labelOf } from "@sincpro/criteria";
1
+ import { choiceLabelOf, isRelational, labelOf } from "@sincpro/criteria";
2
2
  /**
3
3
  * The model, as web-ui's search bar and criteria builder read it.
4
4
  *
@@ -8,19 +8,33 @@ import { labelOf } from "@sincpro/criteria";
8
8
  * design system and must not depend on one backend — so the translation lives here, the one
9
9
  * place that knows both.
10
10
  *
11
- * Known gap: web-ui's field has `choices` but no word for each choice, so the bar offers an
12
- * enum's raw values («paid») where a cell says «Pagada». Fixing it is web-ui's.
11
+ * An enum carries the word of each value (`translations.choices`, web-ui 2.7): the bar offers
12
+ * «Estado: Pagada» for «pagada» typed and sends `paid` — before, it offered the raw value where
13
+ * a cell said «Pagada». A to-many relation carries the key of the records on the other side
14
+ * (`relationKey`, from the related definition): what the bar's records are compared by through
15
+ * it once chosen.
13
16
  *
14
17
  * `texts` keeps only those plain text fields: web-ui's bar offers a typed word in EVERY text
15
18
  * field of the model it is handed (its `facets` are read only without one), so the bar is handed
16
19
  * the model with the text fields a person types into (`facetsOf`) — and the criteria builder the
17
20
  * whole one.
18
21
  */
22
+ /** The comparisons of a text a person types: never asked of a key. */
23
+ const TYPED_TEXT = new Set(["like", "starts with"]);
19
24
  export function modelOf(meta, locale, texts) {
25
+ // The column a to-one relation is identified by — sincpro_framework's `identified_by`, its
26
+ // foreign key — stays: web-ui compares a chosen record by it and never offers it on its own.
27
+ // It holds a KEY, so it is handed without the comparisons of a text a person types («like»,
28
+ // «starts with»): with them web-ui read it as a column that names the record, and «globex» on
29
+ // «Cliente» became «customer_id contains globex» instead of unfolding the customers.
30
+ const identifying = new Set(Object.values(meta.fields)
31
+ .filter((field) => isRelational(field) && field.many !== true)
32
+ .map((field) => field.identified_by)
33
+ .filter((name) => typeof name === "string" && name !== ""));
20
34
  const kept = (name) => {
21
35
  const field = meta.fields[name];
22
36
  const text = field?.type === "text" && !field.choices?.length;
23
- return texts === undefined || !text || texts.includes(name);
37
+ return texts === undefined || !text || texts.includes(name) || identifying.has(name);
24
38
  };
25
39
  const names = Object.keys(meta.fields).filter(kept);
26
40
  return {
@@ -34,7 +48,9 @@ export function modelOf(meta, locale, texts) {
34
48
  type: field.type,
35
49
  nullable: field.nullable,
36
50
  sortable: field.sortable,
37
- ops: field.ops,
51
+ ops: identifying.has(name)
52
+ ? field.ops.filter((op) => !TYPED_TEXT.has(op))
53
+ : field.ops,
38
54
  kind: field.kind,
39
55
  ...(field.many === undefined ? {} : { many: field.many }),
40
56
  ...(field.relation === undefined ? {} : { relation: field.relation }),
@@ -42,6 +58,9 @@ export function modelOf(meta, locale, texts) {
42
58
  ? {}
43
59
  : { identifiedBy: field.identified_by }),
44
60
  ...(field.choices && field.choices.length > 0 ? { choices: field.choices } : {}),
61
+ ...(field.many === true && field.definition
62
+ ? { relationKey: field.definition.get_id || field.definition.identity }
63
+ : {}),
45
64
  },
46
65
  ])),
47
66
  translations: {
@@ -49,6 +68,15 @@ export function modelOf(meta, locale, texts) {
49
68
  default: meta.name?.[locale ?? ""] ?? meta.name?.["default"] ?? meta.aggregate,
50
69
  },
51
70
  labels: Object.fromEntries(names.map((name) => [name, { default: labelOf(meta, name, locale) }])),
71
+ choices: Object.fromEntries(names
72
+ .filter((name) => (meta.fields[name]?.choices?.length ?? 0) > 0)
73
+ .map((name) => [
74
+ name,
75
+ Object.fromEntries((meta.fields[name]?.choices ?? []).map((value) => [
76
+ String(value),
77
+ { default: choiceLabelOf(meta, name, value, locale) },
78
+ ])),
79
+ ])),
52
80
  },
53
81
  };
54
82
  }
@@ -15,8 +15,11 @@ import { type OpenTarget } from "@sincpro/web-ui";
15
15
  *
16
16
  * Inside a workspace, opening a chip and «Buscar más…» are the workspace's (`RecordOpening`),
17
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.
18
+ * entity's list opened to choose SEVERAL (`chooseMany`), offering neither what `criteria` leaves
19
+ * out nor the chips already on — what was ticked there, or every record it matches («Elegir los
20
+ * 37 que coinciden»), is added, at most `BATCH_LIMIT` at once (past it nothing is added and a
21
+ * notice says why). A workspace that cannot choose several adds the one answered (`choose`).
22
+ * `onOpen` / `onBrowseAll` replace either.
20
23
  * Without a workspace a chip is a value.
21
24
  *
22
25
  * <EntityTags entity={people} value={followers} onChange={setFollowers} />
@@ -1,12 +1,14 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import {} from "@sincpro/client-framework";
3
+ import { keysOf, listRoute } from "@sincpro/client-framework";
4
4
  import { isList } from "../../core/list.js";
5
5
  import { useFramework } from "../../react/context.js";
6
+ import { BATCH_LIMIT } from "../../react/useBatchCommand.js";
6
7
  import { excluding, useLookup } from "../../react/useLookup.js";
7
8
  import { presentationOf } from "../list/presentation.js";
9
+ import { refusalNotice } from "../list/records.js";
8
10
  import { chooserScopeOf, useRecordOpening } from "./opening.js";
9
- import { TagsField } from "@sincpro/web-ui";
11
+ import { TagsField, useToastIfAny } from "@sincpro/web-ui";
10
12
  import { useRef } from "react";
11
13
  /**
12
14
  * A many2many: put SEVERAL records of an entity on this one — the followers of an invoice,
@@ -21,15 +23,19 @@ import { useRef } from "react";
21
23
  *
22
24
  * Inside a workspace, opening a chip and «Buscar más…» are the workspace's (`RecordOpening`),
23
25
  * as for a many2one: a chip opens where the workspace puts it, and «Buscar más…» is the
24
- * entity's list opened to choose, offering neither what `criteria` leaves out nor the chips
25
- * already on — the record answered there is added. `onOpen` / `onBrowseAll` replace either.
26
+ * entity's list opened to choose SEVERAL (`chooseMany`), offering neither what `criteria` leaves
27
+ * out nor the chips already on — what was ticked there, or every record it matches («Elegir los
28
+ * 37 que coinciden»), is added, at most `BATCH_LIMIT` at once (past it nothing is added and a
29
+ * notice says why). A workspace that cannot choose several adds the one answered (`choose`).
30
+ * `onOpen` / `onBrowseAll` replace either.
26
31
  * Without a workspace a chip is a value.
27
32
  *
28
33
  * <EntityTags entity={people} value={followers} onChange={setFollowers} />
29
34
  */
30
35
  export function EntityTags({ entity, value, onChange, criteria, onOpen, openTarget, onBrowseAll, placeholder, disabled, "aria-label": ariaLabel, }) {
31
- const { metas } = useFramework();
36
+ const { metas, transport } = useFramework();
32
37
  const opening = useRecordOpening();
38
+ const toast = useToastIfAny();
33
39
  const base = isList(entity) ? entity.entity : entity;
34
40
  // «Buscar más…» answers after the chooser closes: it adds to the chips on screen THEN.
35
41
  const now = useRef(value);
@@ -38,14 +44,30 @@ export function EntityTags({ entity, value, onChange, criteria, onOpen, openTarg
38
44
  (opening === null
39
45
  ? undefined
40
46
  : (id, to) => opening.open(base.ref(id), to));
41
- const choose = opening?.choose;
47
+ /** Added after the chips on screen THEN, each once, in the order they came. */
48
+ const add = (keys) => {
49
+ const fresh = keys.filter((key) => !now.current.includes(key));
50
+ if (fresh.length > 0)
51
+ onChange([...now.current, ...fresh]);
52
+ };
53
+ /** The keys of what a chooser of several answered — in hand, or read once with a ceiling. */
54
+ const addChosen = (selection) => {
55
+ const meta = metas.get(base.key);
56
+ keysOf(selection, {
57
+ transport,
58
+ route: listRoute(base.list),
59
+ identity: meta?.get_id || meta?.identity || "id",
60
+ limit: BATCH_LIMIT,
61
+ }).then(add, (failure) => toast?.show(refusalNotice(failure)));
62
+ };
63
+ const scope = () => chooserScopeOf(entity, excluding(criteria, value, metas.get(base.key)));
64
+ const { choose, chooseMany } = opening ?? {};
42
65
  const browseAll = onBrowseAll ??
43
- (choose === undefined
44
- ? undefined
45
- : (query) => choose(base, (id) => {
46
- if (!now.current.includes(id))
47
- onChange([...now.current, id]);
48
- }, query, chooserScopeOf(entity, excluding(criteria, value, metas.get(base.key)))));
66
+ (chooseMany !== undefined
67
+ ? (query) => chooseMany(base, addChosen, query, scope())
68
+ : choose === undefined
69
+ ? undefined
70
+ : (query) => choose(base, (id) => add([id]), query, scope()));
49
71
  const lookup = useLookup(entity, {
50
72
  ...(criteria === undefined ? {} : { criteria }),
51
73
  values: value,
@@ -1,6 +1,7 @@
1
- import { type Entity, type ResourceRef } from "@sincpro/client-framework";
1
+ import { type Entity, type ResourceRef, type Selection } from "@sincpro/client-framework";
2
2
  import { type AnyRecord, type Criteria, type Expression } from "@sincpro/criteria";
3
3
  import { type ListDefinition } from "../../core/list.js";
4
+ import type { Chooser } from "../list/records.js";
4
5
  import type { OpenTarget } from "@sincpro/web-ui";
5
6
  import { type ReactNode } from "react";
6
7
  /**
@@ -29,7 +30,10 @@ export type RecordOpening = {
29
30
  /** «Buscar más…»: the entity's own list opened to choose (in composer, a modal that answers),
30
31
  * on what was typed, offering only what `scope` lets the picker choose (`chooserScopeOf`).
31
32
  * Without it the picker brings its own chooser. */
32
- choose?: (entity: Entity, answer: (id: string) => void, query: string, scope?: Expression) => void;
33
+ choose?: Chooser<string>;
34
+ /** «Buscar más…» for several — a many2many: the same list opened to choose MANY, answering a
35
+ * `Selection` (what was ticked, or every record it matches). Without it, `choose` adds one. */
36
+ chooseMany?: Chooser<Selection>;
33
37
  /** «Agregar» on a one2many: the form of a new record of `entity`, starting with `values`
34
38
  * (the key that points back here), opened where it answers; `created` once it exists.
35
39
  * Without it a record's one2many only reads. */
@@ -6,8 +6,9 @@ import { createRegistry, formatRef, PHONE_WIDTH } from "@sincpro/web-composer/do
6
6
  import { cachedTransport, } from "../../core/cache.js";
7
7
  import { installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "../../core/copy.js";
8
8
  import { FrameworkProvider } from "../../react/context.js";
9
+ import { useSearchRecords } from "../list/records.js";
9
10
  import { webUiSkin } from "./skin.js";
10
- import { installCopy, SPANISH_COPY, ToastProvider } from "@sincpro/web-ui";
11
+ import { installCopy, SearchProvider, SPANISH_COPY, ToastProvider, useSearchSettings, } from "@sincpro/web-ui";
11
12
  import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
12
13
  /**
13
14
  * The application context in one place: who answers (the transport), in which language, which
@@ -38,6 +39,16 @@ function onPhone(changed) {
38
39
  const isPhone = () => typeof window !== "undefined" && window.matchMedia !== undefined
39
40
  ? window.matchMedia(PHONE).matches
40
41
  : false;
42
+ /**
43
+ * The framework's search of a relation's records for every web-ui bar and builder below — a
44
+ * screen's own `SearchBar` included —, unless the application put its own around the app.
45
+ * Inside the `FrameworkProvider`: it searches through the screens' transport.
46
+ */
47
+ function FrameworkSearch({ children }) {
48
+ const framework = useSearchRecords();
49
+ const outer = useSearchSettings();
50
+ return (_jsx(SearchProvider, { searchRecords: outer.searchRecords ?? framework, children: children }));
51
+ }
41
52
  /** A view that broke while drawing, told to the process's error reporter: `view <ref>`. */
42
53
  const reportViewError = (error, { resource }) => reportError(error, `view ${formatRef(resource)}`);
43
54
  export function SincproApp({ transport, views, start, language = "es", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, dateStyle, currency, events, workspace: given, bar, onViewError = reportViewError, changes = processChanges, }) {
@@ -85,5 +96,5 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
85
96
  // The first screen only: a re-render must not push it again.
86
97
  // eslint-disable-next-line react-hooks/exhaustive-deps
87
98
  }, [workspace]);
88
- return (_jsx(FrameworkProvider, { transport: cached, locale: language, changes: changes, ...(metas === undefined ? {} : { metas }), ...(entities === undefined ? {} : { entities }), ...(timeZone === undefined ? {} : { timeZone }), dateStyle: dateStyle ?? (phone ? "literal" : "numeric"), ...(currency === undefined ? {} : { currency }), ...(events === undefined ? {} : { events }), 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, onViewError: onViewError, ...(empty === undefined ? {} : { empty }) }) })] }) }) }));
99
+ return (_jsx(FrameworkProvider, { transport: cached, locale: language, changes: changes, ...(metas === undefined ? {} : { metas }), ...(entities === undefined ? {} : { entities }), ...(timeZone === undefined ? {} : { timeZone }), dateStyle: dateStyle ?? (phone ? "literal" : "numeric"), ...(currency === undefined ? {} : { currency }), ...(events === undefined ? {} : { events }), children: _jsx(FrameworkSearch, { 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, onViewError: onViewError, ...(empty === undefined ? {} : { empty }) }) })] }) }) }) }));
89
100
  }
@@ -1,7 +1,7 @@
1
1
  import { type Entity, type Transport } from "@sincpro/client-framework";
2
2
  import { type AnyRecord, type Meta } from "@sincpro/criteria";
3
3
  import { type ViewProps, type ViewSpec } from "@sincpro/web-composer";
4
- import type { ListDefinition } from "../../core/list.js";
4
+ import { type ListDefinition } from "../../core/list.js";
5
5
  import { type ComponentType } from "react";
6
6
  /**
7
7
  * An entity as the composer's view: one `ViewSpec` for its list (a reference without an id)
@@ -1,17 +1,18 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { isEntityId, listRoute, NEW_PARAM, processContext, scopeNameOf, scopeOfRef, } from "@sincpro/client-framework";
4
- import { matching, nameOf } from "@sincpro/criteria";
4
+ import { nameOf } from "@sincpro/criteria";
5
5
  import { usePhone, } from "@sincpro/web-composer";
6
- import { lookupOf } from "../../core/lookup.js";
7
- import { summaryOf } from "../../core/summary.js";
6
+ import { CHOOSE_MANY } from "../../core/list.js";
7
+ import { useFramework } from "../../react/context.js";
8
8
  import { ListScopeProvider } from "../../react/scope.js";
9
9
  import { useListing } from "../../react/useListing.js";
10
10
  import { EntityList } from "../list/EntityList.js";
11
- import { presentationOf } from "../list/presentation.js";
11
+ import { findChoices, recordsBrowser, RecordsBrowserProvider, refusalNotice, useSearchRecords, } from "../list/records.js";
12
12
  import { RecordOpeningProvider, } from "../record/opening.js";
13
13
  import { openIn, RECORD_SIZE, targetsFor } from "./open.js";
14
14
  import { EntityRecord } from "./record.js";
15
+ import { useToastIfAny } from "@sincpro/web-ui";
15
16
  import { useMemo } from "react";
16
17
  /**
17
18
  * The fields of a view open their records in the workspace: a modal over this surface by
@@ -31,10 +32,19 @@ function InWorkspace({ api, children }) {
31
32
  targets,
32
33
  narrow: api.surface !== "page",
33
34
  choose: (entity, answer, query, scope) => api.pick(entity.chooserRef(query, scope), (ref) => ref.id === undefined || answer(ref.id), answering),
35
+ chooseMany: (entity, answer, query, scope) => api.pick(entity.chooserRef(query, scope), answer, {
36
+ ...answering,
37
+ question: CHOOSE_MANY,
38
+ }),
34
39
  create: (entity, values, created) => api.pick(entity.newRef(values), () => created(), answering),
35
40
  };
36
41
  }, [api, targets]);
37
- return _jsx(RecordOpeningProvider, { value: opening, children: children });
42
+ // «Buscar más…» in the view's search bars: the same choosers, named by the framework's book.
43
+ const { transport, metas, names, entities } = useFramework();
44
+ const named = useSearchRecords();
45
+ const toast = useToastIfAny();
46
+ const browser = useMemo(() => recordsBrowser({ transport, metas, names, entities }, opening, named, (failure) => toast?.show(refusalNotice(failure))), [transport, metas, names, entities, opening, named, toast]);
47
+ return (_jsx(RecordOpeningProvider, { value: opening, children: _jsx(RecordsBrowserProvider, { value: browser, children: children }) }));
38
48
  }
39
49
  /** The entity's list when the application writes none: opened under a named cut, it says
40
50
  * whose it is («Facturas · Globex Bolivia»). */
@@ -108,26 +118,14 @@ export function entityView(entity, options) {
108
118
  meta = (await options.transport.list(route, { pagination: { limit: 1 } })).meta;
109
119
  if (meta?.search == null)
110
120
  return [];
111
- const page = await options.transport.list(route, matching(meta, query));
112
- const known = meta;
113
- const locale = localeNow();
114
- // ⌘K writes text: of the entity's look of a choice, its name and its meta.
115
- const look = presentationOf(entity).option;
116
- return lookupOf(known, page.rows, entity.summary).map((one) => {
117
- const own = look === undefined || one.record === undefined ? {} : look(one.record);
118
- const summary = one.record === undefined
119
- ? undefined
120
- : summaryOf(known, one.record, {
121
- fields: entity.summary ?? {},
122
- ...(locale === undefined ? {} : { locale }),
123
- });
124
- const detail = own.meta ?? summary?.description ?? summary?.type ?? undefined;
125
- return {
126
- ref: entity.ref(one.id),
127
- label: own.name ?? one.label,
128
- ...(detail === undefined ? {} : { detail }),
129
- };
130
- });
121
+ // A hit reads as a choice anywhere a record is picked by name: its name and what tells it
122
+ // apart, never its key (`findChoices`).
123
+ const choices = await findChoices(options.transport, entity, meta, route, query, localeNow());
124
+ return choices.map((one) => ({
125
+ ref: entity.ref(one.id),
126
+ label: one.name,
127
+ ...(one.detail === undefined ? {} : { detail: one.detail }),
128
+ }));
131
129
  },
132
130
  load: () => {
133
131
  view ??= screens().catch((failure) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-framework",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -40,11 +40,11 @@
40
40
  "@opentelemetry/resources": "^3.1.0",
41
41
  "@opentelemetry/sdk-trace": "^3.1.0",
42
42
  "@sentry/browser": "^11.11.0",
43
- "@sincpro/client-framework": "^2.2.0",
44
- "@sincpro/criteria": "^2.3.0",
45
- "@sincpro/criteria-react": "^2.3.0",
43
+ "@sincpro/client-framework": "^2.3.0",
44
+ "@sincpro/criteria": "^2.4.0",
45
+ "@sincpro/criteria-react": "^2.4.0",
46
46
  "@sincpro/web-composer": "^1.7.0",
47
- "@sincpro/web-ui": "^2.5.0",
47
+ "@sincpro/web-ui": "^2.8.0",
48
48
  "react": ">=19",
49
49
  "react-dom": ">=19"
50
50
  },
@@ -72,11 +72,11 @@
72
72
  "@opentelemetry/resources": "3.1.0",
73
73
  "@opentelemetry/sdk-trace": "3.1.0",
74
74
  "@sentry/browser": "11.11.0",
75
- "@sincpro/client-framework": "^2.2.0",
76
- "@sincpro/criteria": "^2.3.0",
77
- "@sincpro/criteria-react": "^2.3.0",
75
+ "@sincpro/client-framework": "^2.3.0",
76
+ "@sincpro/criteria": "^2.4.0",
77
+ "@sincpro/criteria-react": "^2.4.0",
78
78
  "@sincpro/web-composer": "^1.8.0",
79
- "@sincpro/web-ui": "^2.5.0",
79
+ "@sincpro/web-ui": "^2.8.0",
80
80
  "@storybook/addon-a11y": "10.6.5",
81
81
  "@storybook/addon-docs": "10.6.5",
82
82
  "@storybook/addon-mcp": "10.6.5",