@sincpro/web-framework 3.1.0 → 3.3.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/dist/core/copy.d.ts +2 -0
- package/dist/core/copy.js +2 -0
- package/dist/core/list.d.ts +3 -0
- package/dist/react/context.d.ts +3 -0
- package/dist/react/context.js +5 -0
- package/dist/web/index.d.ts +4 -2
- package/dist/web/index.js +4 -2
- package/dist/web/list/EntityList.d.ts +4 -1
- package/dist/web/list/EntityList.js +21 -12
- package/dist/web/list/EntitySearchBar.d.ts +6 -2
- package/dist/web/list/EntitySearchBar.js +11 -3
- package/dist/web/list/columns.js +29 -2
- package/dist/web/list/presentation.d.ts +30 -0
- package/dist/web/list/presentation.js +24 -0
- package/dist/web/list/search.d.ts +14 -5
- package/dist/web/list/search.js +29 -14
- package/dist/web/record/ActionButton.d.ts +26 -4
- package/dist/web/record/ActionButton.js +62 -3
- package/dist/web/record/CommandButton.d.ts +13 -1
- package/dist/web/record/CommandButton.js +24 -5
- package/dist/web/record/ServiceButton.d.ts +22 -4
- package/dist/web/record/ServiceButton.js +31 -6
- package/dist/web/record/ask.d.ts +72 -0
- package/dist/web/record/ask.js +63 -0
- package/dist/web/record/control.d.ts +2 -2
- package/dist/web/record/control.js +7 -3
- package/dist/web/record/edit.d.ts +1 -1
- package/dist/web/record/edit.js +11 -3
- package/dist/web/record/lines.d.ts +4 -0
- package/dist/web/record/lines.js +18 -3
- package/dist/web/record/record.d.ts +25 -1
- package/dist/web/record/record.js +38 -4
- package/dist/web/workspace/composer.d.ts +7 -2
- package/dist/web/workspace/composer.js +24 -4
- package/dist/web/workspace/record.d.ts +1 -1
- package/package.json +3 -3
|
@@ -4,10 +4,11 @@ import { describeRows } from "@sincpro/criteria";
|
|
|
4
4
|
import { frameworkCopy } from "../../core/copy.js";
|
|
5
5
|
import { textOf, valueAt, viewOf } from "../../core/present.js";
|
|
6
6
|
import { relatedOf } from "../../core/related.js";
|
|
7
|
-
import { relationFieldOf } from "../../core/relation.js";
|
|
8
|
-
import { useEntityFor } from "../../react/context.js";
|
|
7
|
+
import { entityFor, relationFieldOf, } from "../../core/relation.js";
|
|
8
|
+
import { useEntityFor, useFrameworkIfAny } from "../../react/context.js";
|
|
9
9
|
import { useNameOf } from "../../react/useNameOf.js";
|
|
10
10
|
import { columnsOf } from "../list/columns.js";
|
|
11
|
+
import { partLookOf, presentationOf, tonesOver, } from "../list/presentation.js";
|
|
11
12
|
import { useRecordOpening } from "./opening.js";
|
|
12
13
|
import { List, RelationValue, } from "@sincpro/web-ui";
|
|
13
14
|
/**
|
|
@@ -76,6 +77,30 @@ function RelationFact({ record, meta, name, relation, locale, }) {
|
|
|
76
77
|
export function countOf(record, name) {
|
|
77
78
|
return relatedOf(record[name]).count.value;
|
|
78
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* How the rows of `name` look, layer over layer: the related entity's own presentation (when the
|
|
82
|
+
* relation points at a declared one), the parts the record's entity declared
|
|
83
|
+
* (`presented(issues, { parts: { runs: … } })`), and what the screen passes — each over the one
|
|
84
|
+
* before, so a screen changes one colour and keeps the rest.
|
|
85
|
+
*
|
|
86
|
+
* The record's entity is the one given, or the provider's entity of the model's aggregate.
|
|
87
|
+
*/
|
|
88
|
+
export function usePartLook(meta, name, own) {
|
|
89
|
+
const framework = useFrameworkIfAny();
|
|
90
|
+
const find = (target) => target === undefined || framework === null
|
|
91
|
+
? undefined
|
|
92
|
+
: entityFor(framework.entities, target, framework.metas.get);
|
|
93
|
+
const declared = partLookOf(own.entity ?? find(meta?.aggregate), name);
|
|
94
|
+
const relation = relationFieldOf(meta, name);
|
|
95
|
+
const related = relation?.many === true ? find(relation.target) : undefined;
|
|
96
|
+
const itself = related === undefined ? {} : presentationOf(related);
|
|
97
|
+
const columns = own.columns ?? declared.columns ?? itself.columns;
|
|
98
|
+
const tones = tonesOver(itself.tones, declared.tones, own.tones);
|
|
99
|
+
return {
|
|
100
|
+
...(columns === undefined ? {} : { columns: columns }),
|
|
101
|
+
...(tones === undefined ? {} : { tones }),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
79
104
|
/**
|
|
80
105
|
* A one2many / many2many of the record, as an embedded list.
|
|
81
106
|
*
|
|
@@ -83,6 +108,10 @@ export function countOf(record, name) {
|
|
|
83
108
|
* read off the rows otherwise. When the record brought only one page of them, it says so —
|
|
84
109
|
* «se muestran 50 de 1000» — instead of drawing 50 as if they were all.
|
|
85
110
|
*
|
|
111
|
+
* A choice of a row — a run's state, a member's role — is a tag in the colour declared ONCE
|
|
112
|
+
* with the record's entity (`presented(issues, { parts: { runs: { tones } } })`); `tones` here
|
|
113
|
+
* changes it for this screen, value by value.
|
|
114
|
+
*
|
|
86
115
|
* `rowActions` acts on a part from its row — a group's member, a project's share — with a
|
|
87
116
|
* Command of the record (`useCommand(projects, "unshareProject")`): the parts have no route of
|
|
88
117
|
* their own, so what removes one is the record's, and the screen names it.
|
|
@@ -91,10 +120,15 @@ export function countOf(record, name) {
|
|
|
91
120
|
* rowActions={(share) => [{ id: "unshare", label: "Quitar", icon: X, tone: "danger",
|
|
92
121
|
* onSelect: () => unshare.run(project.id, { tenant_id: share.tenant_id }) }]} />
|
|
93
122
|
*/
|
|
94
|
-
export function RecordLines({ record, meta, name, columns, cells, locale, onOpen, rowActions, }) {
|
|
123
|
+
export function RecordLines({ record, meta, name, entity, columns, cells, tones, locale, onOpen, rowActions, }) {
|
|
124
|
+
const look = usePartLook(meta, name, { entity, columns, tones });
|
|
95
125
|
const related = relatedOf(record[name]);
|
|
96
126
|
const definition = meta?.fields[name]?.definition ?? describeRows(related.items);
|
|
97
127
|
const identity = definition.identity || "id";
|
|
98
128
|
const copy = frameworkCopy();
|
|
99
|
-
return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(List, { embedded: true, items: related.items, keyOf: (row) => String(row[identity]), present: "table", empty: { sentence: copy.list.empty }, ...(onOpen === undefined ? {} : { onOpen }), children: _jsx(List.Table, { columns: columnsOf(definition, columns, {
|
|
129
|
+
return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(List, { embedded: true, items: related.items, keyOf: (row) => String(row[identity]), present: "table", empty: { sentence: copy.list.empty }, ...(onOpen === undefined ? {} : { onOpen }), children: _jsx(List.Table, { columns: columnsOf(definition, look.columns, {
|
|
130
|
+
locale,
|
|
131
|
+
...(cells ? { cells } : {}),
|
|
132
|
+
...(look.tones === undefined ? {} : { tones: look.tones }),
|
|
133
|
+
}), ...(rowActions === undefined ? {} : { rowActions }) }) }), related.partial ? (_jsx("p", { className: "text-meta text-muted", children: copy.record.partial(related.items.length, related.count.value, related.count.exact) })) : null] }));
|
|
100
134
|
}
|
|
@@ -18,8 +18,10 @@ import { type ComponentType } from "react";
|
|
|
18
18
|
* (`entity.newRef(values)`), which `useRecord(entity, resource)` fills with the model's defaults
|
|
19
19
|
* and what the reference carries.
|
|
20
20
|
*
|
|
21
|
-
* ⌘K asks the server with `matching` — 8 records
|
|
22
|
-
*
|
|
21
|
+
* ⌘K asks the server with `matching` — 8 records — the same question a many2one asks. Each hit
|
|
22
|
+
* says what it is (`noun`, composer's) and, beside it, what tells it apart: the entity's own
|
|
23
|
+
* `option` look, else its summary's description or type — never its key, which tells a person
|
|
24
|
+
* nothing a UUID long («María Fernanda Apaza Quispe 01a1ebd4…»). The model definition is asked for once, on the first search, unless `meta`
|
|
23
25
|
* is handed over. A list whose route answers a SCOPE by its params (forge's `/projects`
|
|
24
26
|
* without `tenant_id` is the projects with NO tenant) is searched in the one ⌘K should see:
|
|
25
27
|
* `search: { params }`.
|
|
@@ -35,6 +37,9 @@ export type EntityViewOptions = {
|
|
|
35
37
|
transport: Transport;
|
|
36
38
|
/** How it reads in the palette, a panel's frame and the breadcrumb. */
|
|
37
39
|
name: string;
|
|
40
|
+
/** What ONE of its records is called — «Colegiado» —, beside each record ⌘K finds, so two
|
|
41
|
+
* «María» of different kinds say which is which. Without it, the model's own name. */
|
|
42
|
+
noun?: string;
|
|
38
43
|
/** Its list. Without it, `EntityList` over the entity: search bar, pages, «Nuevo». */
|
|
39
44
|
list?: ComponentType<ViewProps>;
|
|
40
45
|
/** Its record. Without it, `EntityRecord`: the form the model describes. */
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { isEntityId, listRoute, NEW_PARAM, scopeNameOf, scopeOfRef, } from "@sincpro/client-framework";
|
|
4
|
-
import { matching } from "@sincpro/criteria";
|
|
3
|
+
import { isEntityId, listRoute, NEW_PARAM, processContext, scopeNameOf, scopeOfRef, } from "@sincpro/client-framework";
|
|
4
|
+
import { matching, nameOf } from "@sincpro/criteria";
|
|
5
5
|
import { usePhone, } from "@sincpro/web-composer";
|
|
6
6
|
import { lookupOf } from "../../core/lookup.js";
|
|
7
|
+
import { summaryOf } from "../../core/summary.js";
|
|
7
8
|
import { ListScopeProvider } from "../../react/scope.js";
|
|
8
9
|
import { useListing } from "../../react/useListing.js";
|
|
9
10
|
import { EntityList } from "../list/EntityList.js";
|
|
@@ -49,6 +50,11 @@ function recordOf(entity, title) {
|
|
|
49
50
|
return (_jsx(EntityRecord, { ...props, entity: entity, ...(title === undefined ? {} : { title }) }));
|
|
50
51
|
};
|
|
51
52
|
}
|
|
53
|
+
/** The language the screens speak now — the provider puts it in the process's context. */
|
|
54
|
+
function localeNow() {
|
|
55
|
+
const lang = processContext.get("lang");
|
|
56
|
+
return typeof lang === "string" && lang !== "" ? lang : undefined;
|
|
57
|
+
}
|
|
52
58
|
/**
|
|
53
59
|
* What a reference reads as before its view names it — a crumb whose view is not mounted, a
|
|
54
60
|
* record still loading: the list is the view's name (with its cut's, `entity.listRef`); a record
|
|
@@ -85,6 +91,12 @@ export function entityView(entity, options) {
|
|
|
85
91
|
return {
|
|
86
92
|
domain: entity.domain,
|
|
87
93
|
kind: entity.kind,
|
|
94
|
+
// Read when ⌘K draws a hit, so the model's own name is there once a search brought it.
|
|
95
|
+
get noun() {
|
|
96
|
+
if (options.noun !== undefined)
|
|
97
|
+
return options.noun;
|
|
98
|
+
return meta?.name === undefined ? undefined : nameOf(meta, localeNow());
|
|
99
|
+
},
|
|
88
100
|
title: (ref) => titleOf(ref, options.name),
|
|
89
101
|
goto: options.goto ?? true,
|
|
90
102
|
...(options.icon === undefined ? {} : { icon: options.icon }),
|
|
@@ -97,11 +109,19 @@ export function entityView(entity, options) {
|
|
|
97
109
|
if (meta?.search == null)
|
|
98
110
|
return [];
|
|
99
111
|
const page = await options.transport.list(route, matching(meta, query));
|
|
112
|
+
const known = meta;
|
|
113
|
+
const locale = localeNow();
|
|
100
114
|
// ⌘K writes text: of the entity's look of a choice, its name and its meta.
|
|
101
115
|
const look = presentationOf(entity).option;
|
|
102
|
-
return lookupOf(
|
|
116
|
+
return lookupOf(known, page.rows, entity.summary).map((one) => {
|
|
103
117
|
const own = look === undefined || one.record === undefined ? {} : look(one.record);
|
|
104
|
-
const
|
|
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;
|
|
105
125
|
return {
|
|
106
126
|
ref: entity.ref(one.id),
|
|
107
127
|
label: own.name ?? one.label,
|
|
@@ -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: "card" | "page";
|
|
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.3.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",
|
|
@@ -75,8 +75,8 @@
|
|
|
75
75
|
"@sincpro/client-framework": "^2.2.0",
|
|
76
76
|
"@sincpro/criteria": "^2.2.2",
|
|
77
77
|
"@sincpro/criteria-react": "^2.1.0",
|
|
78
|
-
"@sincpro/web-composer": "^1.
|
|
79
|
-
"@sincpro/web-ui": "^2.
|
|
78
|
+
"@sincpro/web-composer": "^1.8.0",
|
|
79
|
+
"@sincpro/web-ui": "^2.4.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",
|