@sincpro/web-framework 3.4.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.
- package/README.md +2 -0
- package/dist/core/command.d.ts +16 -0
- package/dist/core/command.js +17 -0
- package/dist/core/copy.d.ts +16 -0
- package/dist/core/copy.js +26 -0
- package/dist/core/history.d.ts +16 -4
- package/dist/core/history.js +20 -17
- package/dist/core/index.d.ts +4 -3
- package/dist/core/index.js +3 -2
- package/dist/core/list.d.ts +51 -2
- package/dist/core/list.js +58 -1
- package/dist/core/present.d.ts +12 -0
- package/dist/core/present.js +39 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +2 -0
- package/dist/react/useBatchCommand.d.ts +50 -0
- package/dist/react/useBatchCommand.js +124 -0
- package/dist/react/useCommand.js +3 -4
- package/dist/react/useListing.d.ts +7 -1
- package/dist/react/useListing.js +9 -21
- package/dist/react/useSelection.d.ts +37 -0
- package/dist/react/useSelection.js +40 -0
- package/dist/react/useServiceReading.d.ts +8 -0
- package/dist/react/useServiceReading.js +16 -1
- package/dist/web/index.d.ts +2 -0
- package/dist/web/index.js +2 -0
- package/dist/web/list/BatchProgress.d.ts +16 -0
- package/dist/web/list/BatchProgress.js +40 -0
- package/dist/web/list/EntityList.d.ts +12 -6
- package/dist/web/list/EntityList.js +37 -22
- package/dist/web/list/EntitySearchBar.d.ts +9 -0
- package/dist/web/list/EntitySearchBar.js +15 -5
- package/dist/web/list/pivot.d.ts +5 -1
- package/dist/web/list/pivot.js +28 -11
- package/dist/web/list/records.d.ts +100 -0
- package/dist/web/list/records.js +219 -0
- package/dist/web/list/search.d.ts +0 -17
- package/dist/web/list/search.js +33 -5
- package/dist/web/record/EntityTags.d.ts +5 -2
- package/dist/web/record/EntityTags.js +34 -12
- package/dist/web/record/opening.d.ts +6 -2
- package/dist/web/workspace/SincproApp.js +13 -2
- package/dist/web/workspace/composer.d.ts +1 -1
- package/dist/web/workspace/composer.js +23 -25
- package/dist/web/workspace/record.d.ts +1 -1
- package/package.json +9 -9
|
@@ -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
|
|
25
|
-
* already on —
|
|
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
|
-
|
|
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
|
-
(
|
|
44
|
-
?
|
|
45
|
-
:
|
|
46
|
-
|
|
47
|
-
|
|
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?:
|
|
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
|
|
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 {
|
|
4
|
+
import { nameOf } from "@sincpro/criteria";
|
|
5
5
|
import { usePhone, } from "@sincpro/web-composer";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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) => {
|
|
@@ -50,7 +50,7 @@ export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>,
|
|
|
50
50
|
record: {
|
|
51
51
|
error?: string | undefined;
|
|
52
52
|
dirty?: import("@sincpro/web-ui").DirtyState | undefined;
|
|
53
|
-
placement: "
|
|
53
|
+
placement: "page" | "card";
|
|
54
54
|
identity: {
|
|
55
55
|
tag?: {
|
|
56
56
|
tone?: import("@sincpro/web-ui").Tone | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "3.
|
|
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.
|
|
44
|
-
"@sincpro/criteria": "^2.
|
|
45
|
-
"@sincpro/criteria-react": "^2.
|
|
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.
|
|
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.
|
|
76
|
-
"@sincpro/criteria": "^2.
|
|
77
|
-
"@sincpro/criteria-react": "^2.
|
|
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.
|
|
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",
|