@sincpro/web-framework 3.22.0 → 4.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.
- package/README.md +114 -112
- package/dist/core/cache.d.ts +20 -23
- package/dist/core/cache.js +37 -52
- package/dist/core/changes.d.ts +10 -18
- package/dist/core/changes.js +11 -30
- package/dist/core/command.d.ts +25 -11
- package/dist/core/command.js +9 -12
- package/dist/core/edit.d.ts +16 -2
- package/dist/core/edit.js +13 -2
- package/dist/core/groups.d.ts +3 -2
- package/dist/core/groups.js +4 -3
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +2 -2
- package/dist/core/list.d.ts +17 -11
- package/dist/core/list.js +17 -11
- package/dist/core/names.d.ts +8 -6
- package/dist/core/names.js +14 -18
- package/dist/core/server.d.ts +9 -7
- package/dist/core/server.js +17 -21
- package/dist/core/trail.d.ts +6 -3
- package/dist/core/trail.js +2 -2
- package/dist/react/context.d.ts +13 -6
- package/dist/react/context.js +11 -9
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/useBatchCommand.d.ts +5 -5
- package/dist/react/useBatchCommand.js +10 -12
- package/dist/react/useCommand.d.ts +11 -15
- package/dist/react/useCommand.js +15 -13
- package/dist/react/useCount.d.ts +2 -2
- package/dist/react/useCounts.js +10 -9
- package/dist/react/useGroups.d.ts +1 -1
- package/dist/react/useGroups.js +22 -13
- package/dist/react/useHistory.js +7 -7
- package/dist/react/useListing.d.ts +14 -7
- package/dist/react/useListing.js +33 -9
- package/dist/react/useLookup.js +5 -7
- package/dist/react/useNameOf.d.ts +2 -2
- package/dist/react/useNameOf.js +4 -13
- package/dist/react/usePivot.d.ts +1 -1
- package/dist/react/usePivot.js +13 -7
- package/dist/react/useRecord.js +37 -55
- package/dist/react/useRecordLifecycle.js +8 -9
- package/dist/react/useServiceReading.js +6 -18
- package/dist/react/useUpload.js +9 -2
- package/dist/react/useWrites.d.ts +13 -12
- package/dist/react/useWrites.js +17 -16
- package/dist/web/board/Dashboard.d.ts +2 -2
- package/dist/web/list/EntityList.d.ts +2 -2
- package/dist/web/list/entityList/choosing.d.ts +3 -3
- package/dist/web/list/entityList/faces.d.ts +6 -6
- package/dist/web/list/entityList/grouping.d.ts +3 -3
- package/dist/web/list/entityList/opening.d.ts +4 -4
- package/dist/web/list/entityList/opening.js +2 -1
- package/dist/web/list/entityList/paging.d.ts +3 -3
- package/dist/web/list/entityList/props.d.ts +4 -4
- package/dist/web/list/entityList/rowActions.d.ts +4 -4
- package/dist/web/list/entityList/rowActions.js +1 -1
- package/dist/web/list/export.d.ts +2 -2
- package/dist/web/list/export.js +7 -8
- package/dist/web/list/presentation.d.ts +3 -3
- package/dist/web/list/records.d.ts +13 -10
- package/dist/web/list/records.js +23 -44
- package/dist/web/list/reorder.d.ts +1 -1
- package/dist/web/list/reorder.js +8 -6
- package/dist/web/list/rowCommands.d.ts +10 -9
- package/dist/web/list/rowCommands.js +14 -15
- package/dist/web/list/useEntityList.d.ts +4 -4
- package/dist/web/record/CommandButton.d.ts +8 -8
- package/dist/web/record/EntityTags.js +4 -4
- package/dist/web/record/RelatedList.js +2 -2
- package/dist/web/record/lines.js +4 -4
- package/dist/web/record/richText.js +1 -1
- package/dist/web/workspace/SincproApp.d.ts +8 -6
- package/dist/web/workspace/SincproApp.js +17 -19
- package/dist/web/workspace/composer.d.ts +14 -9
- package/dist/web/workspace/composer.js +29 -8
- package/dist/web/workspace/record.js +2 -2
- package/package.json +3 -3
|
@@ -14,7 +14,7 @@ import { useMemo } from "react";
|
|
|
14
14
|
* whole order, never grouped or while choosing.
|
|
15
15
|
*/
|
|
16
16
|
export function useListRowActions({ listing, idOf, commands, rowActions: asked, grouped, choosing, }) {
|
|
17
|
-
const restoring = listing.definition?.trash === true && listing.entity.restore !== undefined;
|
|
17
|
+
const restoring = listing.definition?.trash === true && listing.entity.operations.restore !== undefined;
|
|
18
18
|
const offered = useMemo(() => restoring
|
|
19
19
|
? [
|
|
20
20
|
...commands,
|
|
@@ -3,8 +3,8 @@ import type { Listing } from "../../react/useListing.js";
|
|
|
3
3
|
import { type DockAction } from "@sincpro/web-ui";
|
|
4
4
|
/**
|
|
5
5
|
* «Exportar»: the list's records — its question on screen, filter and order, every page — as a
|
|
6
|
-
* spreadsheet (`core/export`), saved by the browser. Offered when the entity
|
|
7
|
-
* (
|
|
6
|
+
* spreadsheet (`core/export`), saved by the browser. Offered when the entity has an `export`
|
|
7
|
+
* operation (its contract publishes one); `null` otherwise.
|
|
8
8
|
*
|
|
9
9
|
* Context: the server writes the export (JSON Lines, read as it streams: no page of the list is
|
|
10
10
|
* fetched to build it, so a million rows is the server's work, not the page's), and this writes
|
package/dist/web/list/export.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { downloadRoute, exportRoute } from "@sincpro/client-framework";
|
|
3
2
|
import { nameOf } from "@sincpro/criteria";
|
|
4
3
|
import { frameworkCopy } from "../../core/copy.js";
|
|
5
4
|
import { csvOf, exportColumnsOf } from "../../core/export.js";
|
|
@@ -9,20 +8,19 @@ import { useToastIfAny } from "@sincpro/web-ui";
|
|
|
9
8
|
import { Download } from "lucide-react";
|
|
10
9
|
/**
|
|
11
10
|
* «Exportar»: the list's records — its question on screen, filter and order, every page — as a
|
|
12
|
-
* spreadsheet (`core/export`), saved by the browser. Offered when the entity
|
|
13
|
-
* (
|
|
11
|
+
* spreadsheet (`core/export`), saved by the browser. Offered when the entity has an `export`
|
|
12
|
+
* operation (its contract publishes one); `null` otherwise.
|
|
14
13
|
*
|
|
15
14
|
* Context: the server writes the export (JSON Lines, read as it streams: no page of the list is
|
|
16
15
|
* fetched to build it, so a million rows is the server's work, not the page's), and this writes
|
|
17
16
|
* what a person opens: the model's words as headers, the region's separator and decimal.
|
|
18
17
|
*/
|
|
19
18
|
export function useListExport(listing, enabled) {
|
|
20
|
-
const {
|
|
19
|
+
const { operations, locale } = useFramework();
|
|
21
20
|
const toast = useToastIfAny();
|
|
22
|
-
const
|
|
23
|
-
if (!enabled ||
|
|
21
|
+
const exporting = listing.entity.operations.export;
|
|
22
|
+
if (!enabled || exporting === undefined)
|
|
24
23
|
return null;
|
|
25
|
-
const path = entity.export;
|
|
26
24
|
return {
|
|
27
25
|
id: "export",
|
|
28
26
|
label: frameworkCopy().list.export,
|
|
@@ -31,7 +29,8 @@ export function useListExport(listing, enabled) {
|
|
|
31
29
|
onSelect: () => {
|
|
32
30
|
// The question on screen without its page: every record it keeps, in its order.
|
|
33
31
|
const { pagination: _page, ...asked } = listing.question;
|
|
34
|
-
void
|
|
32
|
+
void operations
|
|
33
|
+
.call(exporting, { ...listing.input, criteria: asked, format: "jsonl" })
|
|
35
34
|
.then((download) => download.blob())
|
|
36
35
|
.then((blob) => blob.text())
|
|
37
36
|
.then((text) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Entity, type EntityOperations } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
3
|
import { type ListDefinition } from "../../core/list.js";
|
|
4
4
|
import type { DockMoment, PickerItem, RecordCard, RowOf, Tone } from "@sincpro/web-ui";
|
|
@@ -106,11 +106,11 @@ export type PartOf<V> = unknown extends V ? AnyRecord : NonNullable<V> extends {
|
|
|
106
106
|
export type PartLooks<T> = {
|
|
107
107
|
readonly [K in keyof T & string as [PartOf<T[K]>] extends [never] ? never : K]?: PartLook<PartOf<T[K]>>;
|
|
108
108
|
};
|
|
109
|
-
export type Presented<T extends AnyRecord,
|
|
109
|
+
export type Presented<T extends AnyRecord, O extends EntityOperations = EntityOperations> = Entity<T, O> & {
|
|
110
110
|
readonly presentation: Presentation<T>;
|
|
111
111
|
};
|
|
112
112
|
/** The entity with how its records look: pass it wherever an entity goes. */
|
|
113
|
-
export declare function presented<T extends AnyRecord,
|
|
113
|
+
export declare function presented<T extends AnyRecord, O extends EntityOperations = EntityOperations>(entity: Entity<T, O>, presentation: Presentation<T>): Presented<T, O>;
|
|
114
114
|
/** The presentation an entity — or the entity of a named list — was declared with; none is `{}`. */
|
|
115
115
|
export declare function presentationOf<T extends AnyRecord>(source: Entity<T> | ListDefinition<T>): Presentation<T>;
|
|
116
116
|
/** How the parts an entity's records hold under `name` look; `{}` when it declares nothing. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type Entity, type MetaStore, type
|
|
1
|
+
import { type Entity, type MetaStore, type OperationTransport, type Selection } from "@sincpro/client-framework";
|
|
2
2
|
import { type AnyRecord, type Expression, type Meta } from "@sincpro/criteria";
|
|
3
|
-
import type
|
|
3
|
+
import { type NameBook } from "../../core/names.js";
|
|
4
4
|
import type { BrowseRecords, LoadModel, SearchRecords, ToastSpec } from "@sincpro/web-ui";
|
|
5
5
|
import { type ReactNode } from "react";
|
|
6
6
|
/** A record as a person picks it by name: its key, its name, and what tells it apart. */
|
|
@@ -15,7 +15,7 @@ export type Choice = {
|
|
|
15
15
|
* template and a short page), each record whole, read as its name and, beside it, what tells it
|
|
16
16
|
* apart — the entity's `option` look, else its summary's description or type. Never its key.
|
|
17
17
|
*
|
|
18
|
-
* await findChoices(
|
|
18
|
+
* await findChoices(operations, clientes, clienteMeta, "andres", "es")
|
|
19
19
|
* -> [{ id: "C-7", name: "Andrés Pérez", detail: "NIT 4455667" }, …]
|
|
20
20
|
*
|
|
21
21
|
* Context: `matching` asks for references (identity and display), and the `option` look and the
|
|
@@ -23,11 +23,14 @@ export type Choice = {
|
|
|
23
23
|
* backend (#48). The question keeps `matching`'s template and its page, and brings each record
|
|
24
24
|
* whole. ⌘K and the search bar's records (web-ui 2.7) read a record the same way, here.
|
|
25
25
|
*/
|
|
26
|
-
export declare function findChoices<T extends AnyRecord>(
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
export declare function findChoices<T extends AnyRecord>(operations: OperationTransport, entity: Entity<T>, meta: Meta, text: string, locale: string | undefined, options?: {
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
input?: Readonly<Record<string, unknown>>;
|
|
29
|
+
}): Promise<Choice[]>;
|
|
30
|
+
/** What the searches of records ask of the framework: the screens' operations, its definitions,
|
|
31
|
+
* its names and its entities — `useFramework()`'s. */
|
|
29
32
|
export type FrameworkReads = {
|
|
30
|
-
|
|
33
|
+
operations: OperationTransport;
|
|
31
34
|
metas: MetaStore;
|
|
32
35
|
names: NameBook;
|
|
33
36
|
entities: readonly Entity[];
|
|
@@ -41,10 +44,10 @@ export type FrameworkReads = {
|
|
|
41
44
|
* application did not declare finds nothing — the bar still offers the relation's text.
|
|
42
45
|
* 2. Keys instead of a text (a filter read back from a link): their names, through the book every
|
|
43
46
|
* cell asks (`NameBook`: one request per entity, kept) — a key without one reads as itself.
|
|
44
|
-
* 3. Else the entity's literal search (`findChoices`), its definition
|
|
47
|
+
* 3. Else the entity's literal search (`findChoices`), by its definition (the contract's, `metas`).
|
|
45
48
|
*/
|
|
46
49
|
export declare function recordsSearch(framework: FrameworkReads, locale: string | undefined): SearchRecords;
|
|
47
|
-
/** `recordsSearch` over the framework's context: the screens'
|
|
50
|
+
/** `recordsSearch` over the framework's context: the screens' operations, its definitions and
|
|
48
51
|
* its names, in the provider's language. */
|
|
49
52
|
export declare function useSearchRecords(): SearchRecords;
|
|
50
53
|
/**
|
|
@@ -56,7 +59,7 @@ export declare function useSearchRecords(): SearchRecords;
|
|
|
56
59
|
*
|
|
57
60
|
* 1. From the root's definition, each name of the path is a relation of the model before it.
|
|
58
61
|
* 2. Its model is the relation's own definition, when the server published it inside; else its
|
|
59
|
-
* entity's (`entityFor` by the aggregate it names),
|
|
62
|
+
* entity's (`entityFor` by the aggregate it names), as the screens know it (`metas`).
|
|
60
63
|
* Final: that definition as web-ui reads a model (`modelOf`); a path that leads nowhere — a name
|
|
61
64
|
* the model lacks, a relation to an entity the application did not declare — is refused.
|
|
62
65
|
*/
|
package/dist/web/list/records.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { keysOf,
|
|
3
|
+
import { keysOf, readPage, SelectionTooLarge, } from "@sincpro/client-framework";
|
|
4
4
|
import { matching } from "@sincpro/criteria";
|
|
5
5
|
import { frameworkCopy } from "../../core/copy.js";
|
|
6
6
|
import { explain } from "../../core/explain.js";
|
|
7
7
|
import { lookupOf } from "../../core/lookup.js";
|
|
8
|
+
import { searchedAlone } from "../../core/names.js";
|
|
8
9
|
import { entityFor } from "../../core/relation.js";
|
|
9
10
|
import { summaryOf } from "../../core/summary.js";
|
|
10
11
|
import { useFramework } from "../../react/context.js";
|
|
@@ -18,7 +19,7 @@ import { createContext, useContext, useMemo } from "react";
|
|
|
18
19
|
* template and a short page), each record whole, read as its name and, beside it, what tells it
|
|
19
20
|
* apart — the entity's `option` look, else its summary's description or type. Never its key.
|
|
20
21
|
*
|
|
21
|
-
* await findChoices(
|
|
22
|
+
* await findChoices(operations, clientes, clienteMeta, "andres", "es")
|
|
22
23
|
* -> [{ id: "C-7", name: "Andrés Pérez", detail: "NIT 4455667" }, …]
|
|
23
24
|
*
|
|
24
25
|
* Context: `matching` asks for references (identity and display), and the `option` look and the
|
|
@@ -26,9 +27,9 @@ import { createContext, useContext, useMemo } from "react";
|
|
|
26
27
|
* backend (#48). The question keeps `matching`'s template and its page, and brings each record
|
|
27
28
|
* whole. ⌘K and the search bar's records (web-ui 2.7) read a record the same way, here.
|
|
28
29
|
*/
|
|
29
|
-
export async function findChoices(
|
|
30
|
+
export async function findChoices(operations, entity, meta, text, locale, options = {}) {
|
|
30
31
|
const { specification: _reference, ...question } = matching(meta, text);
|
|
31
|
-
const page = await
|
|
32
|
+
const page = await readPage(operations, entity, question, { ...options, meta });
|
|
32
33
|
const look = presentationOf(entity).option;
|
|
33
34
|
return lookupOf(meta, page.rows, entity.summary).map((one) => {
|
|
34
35
|
const own = look === undefined || one.record === undefined ? {} : look(one.record);
|
|
@@ -46,30 +47,6 @@ export async function findChoices(transport, entity, meta, route, text, locale,
|
|
|
46
47
|
};
|
|
47
48
|
});
|
|
48
49
|
}
|
|
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
50
|
/**
|
|
74
51
|
* web-ui's `searchRecords` (2.7) answered by the framework: the records of a relation the search
|
|
75
52
|
* bar unfolds and the criteria builder picks — «andres» → the customers that match —, each
|
|
@@ -79,7 +56,7 @@ async function metaOf(framework, entity, signal) {
|
|
|
79
56
|
* application did not declare finds nothing — the bar still offers the relation's text.
|
|
80
57
|
* 2. Keys instead of a text (a filter read back from a link): their names, through the book every
|
|
81
58
|
* 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
|
|
59
|
+
* 3. Else the entity's literal search (`findChoices`), by its definition (the contract's, `metas`).
|
|
83
60
|
*/
|
|
84
61
|
export function recordsSearch(framework, locale) {
|
|
85
62
|
return async ({ relation, text, keys, signal }) => {
|
|
@@ -91,11 +68,14 @@ export function recordsSearch(framework, locale) {
|
|
|
91
68
|
id: key,
|
|
92
69
|
name: (await framework.names.nameOf(entity, String(key))) ?? String(key),
|
|
93
70
|
})));
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
71
|
+
if (!searchedAlone(entity))
|
|
72
|
+
return [];
|
|
73
|
+
const meta = framework.metas.get(entity.key);
|
|
74
|
+
if (meta === undefined)
|
|
97
75
|
return [];
|
|
98
|
-
const choices = await findChoices(framework.
|
|
76
|
+
const choices = await findChoices(framework.operations, entity, meta, text, locale, {
|
|
77
|
+
signal,
|
|
78
|
+
});
|
|
99
79
|
return choices.map((one) => ({
|
|
100
80
|
id: one.id,
|
|
101
81
|
name: one.name,
|
|
@@ -103,11 +83,11 @@ export function recordsSearch(framework, locale) {
|
|
|
103
83
|
}));
|
|
104
84
|
};
|
|
105
85
|
}
|
|
106
|
-
/** `recordsSearch` over the framework's context: the screens'
|
|
86
|
+
/** `recordsSearch` over the framework's context: the screens' operations, its definitions and
|
|
107
87
|
* its names, in the provider's language. */
|
|
108
88
|
export function useSearchRecords() {
|
|
109
|
-
const {
|
|
110
|
-
return useMemo(() => recordsSearch({
|
|
89
|
+
const { operations, metas, names, entities, locale } = useFramework();
|
|
90
|
+
return useMemo(() => recordsSearch({ operations, metas, names, entities }, locale), [operations, metas, names, entities, locale]);
|
|
111
91
|
}
|
|
112
92
|
/**
|
|
113
93
|
* web-ui's `loadModel` (2.8) answered by the framework: the model at the end of a path of
|
|
@@ -118,7 +98,7 @@ export function useSearchRecords() {
|
|
|
118
98
|
*
|
|
119
99
|
* 1. From the root's definition, each name of the path is a relation of the model before it.
|
|
120
100
|
* 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),
|
|
101
|
+
* entity's (`entityFor` by the aggregate it names), as the screens know it (`metas`).
|
|
122
102
|
* Final: that definition as web-ui reads a model (`modelOf`); a path that leads nowhere — a name
|
|
123
103
|
* the model lacks, a relation to an entity the application did not declare — is refused.
|
|
124
104
|
*/
|
|
@@ -132,7 +112,7 @@ export function modelLoader(framework, root, locale) {
|
|
|
132
112
|
const entity = typeof field.relation === "string"
|
|
133
113
|
? entityFor(framework.entities, field.relation, framework.metas.get)
|
|
134
114
|
: undefined;
|
|
135
|
-
return entity === undefined ? undefined :
|
|
115
|
+
return entity === undefined ? undefined : framework.metas.get(entity.key);
|
|
136
116
|
};
|
|
137
117
|
return async (path) => {
|
|
138
118
|
let meta = root;
|
|
@@ -147,10 +127,10 @@ export function modelLoader(framework, root, locale) {
|
|
|
147
127
|
}
|
|
148
128
|
/** `modelLoader` over the framework's context, from a list's definition (none yet: none). */
|
|
149
129
|
export function useLoadModel(root) {
|
|
150
|
-
const {
|
|
130
|
+
const { operations, metas, names, entities, locale } = useFramework();
|
|
151
131
|
return useMemo(() => root == null
|
|
152
132
|
? undefined
|
|
153
|
-
: modelLoader({
|
|
133
|
+
: modelLoader({ operations, metas, names, entities }, root, locale), [root, operations, metas, names, entities, locale]);
|
|
154
134
|
}
|
|
155
135
|
/**
|
|
156
136
|
* web-ui's `browseRecords` (2.8) answered by the framework: «Buscar más…» under the records of a
|
|
@@ -182,11 +162,10 @@ export function recordsBrowser(framework, open, names, refused) {
|
|
|
182
162
|
keys,
|
|
183
163
|
signal: new AbortController().signal,
|
|
184
164
|
}).then(browse.choose, refused);
|
|
185
|
-
|
|
186
|
-
if (browse.many && open.chooseMany !== undefined && route !== undefined)
|
|
165
|
+
if (browse.many && open.chooseMany !== undefined && searchedAlone(entity))
|
|
187
166
|
open.chooseMany(entity, (selection) => void keysOf(selection, {
|
|
188
|
-
transport: framework.
|
|
189
|
-
|
|
167
|
+
transport: framework.operations,
|
|
168
|
+
entity,
|
|
190
169
|
identity,
|
|
191
170
|
limit: BATCH_LIMIT,
|
|
192
171
|
}).then(answer, refused), browse.text, scope);
|
|
@@ -4,7 +4,7 @@ import type { Listing } from "../../react/useListing.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* A listing's rows put in their order by hand: when they may be dragged (`reorderingOf`), the
|
|
6
6
|
* rows as the screen shows them while a move travels, and the move itself — one `Edit` of the
|
|
7
|
-
* record moved through its entity's
|
|
7
|
+
* record moved through its entity's `edit` operation, or one per row when its group is respaced.
|
|
8
8
|
*
|
|
9
9
|
* const reorder = useReorder(listing, idOf);
|
|
10
10
|
* <List.Table onReorder={reorder.move} /> // absent: no grip
|
package/dist/web/list/reorder.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { targeted } from "@sincpro/client-framework";
|
|
3
|
+
import { withTargetsOf } from "../../core/edit.js";
|
|
3
4
|
import { movesFor, placed, reorderingOf, } from "../../core/reorder.js";
|
|
4
5
|
import { useFramework } from "../../react/context.js";
|
|
5
6
|
import { useEffect, useMemo, useState } from "react";
|
|
6
7
|
export function useReorder(listing, keyOf,
|
|
7
8
|
/** `false` while the screen does not allow it (grouped, choosing). */
|
|
8
9
|
allowed = true) {
|
|
9
|
-
const {
|
|
10
|
+
const { operations } = useFramework();
|
|
10
11
|
const { entity, meta, order, rows: read } = listing;
|
|
11
|
-
const
|
|
12
|
-
const reordering = useMemo(() => (allowed &&
|
|
12
|
+
const editing = entity.operations.edit;
|
|
13
|
+
const reordering = useMemo(() => (allowed && editing !== undefined ? reorderingOf(meta, order) : undefined), [allowed, editing, meta, order]);
|
|
13
14
|
const [shown, setShown] = useState(null);
|
|
14
15
|
const [error, setError] = useState(null);
|
|
15
16
|
const [elsewhere, setElsewhere] = useState(false);
|
|
16
17
|
// A new reading is what is stored: it replaces the order a move showed ahead of it.
|
|
17
18
|
useEffect(() => setShown(null), [read]);
|
|
18
19
|
const rows = shown ?? read;
|
|
19
|
-
const move = reordering === undefined ||
|
|
20
|
+
const move = reordering === undefined || editing === undefined
|
|
20
21
|
? undefined
|
|
21
22
|
: (id, before) => {
|
|
22
23
|
const moves = movesFor(rows, keyOf, reordering, id, before);
|
|
@@ -33,7 +34,7 @@ allowed = true) {
|
|
|
33
34
|
try {
|
|
34
35
|
for (const one of moves) {
|
|
35
36
|
const row = rows.find((candidate) => keyOf(candidate) === one.id) ?? {};
|
|
36
|
-
|
|
37
|
+
const edit = targeted(entity, editing, one.id, {
|
|
37
38
|
id: one.id,
|
|
38
39
|
values: { [reordering.handle]: one.value },
|
|
39
40
|
changed: [reordering.handle],
|
|
@@ -43,6 +44,7 @@ allowed = true) {
|
|
|
43
44
|
: {}),
|
|
44
45
|
action: "save",
|
|
45
46
|
});
|
|
47
|
+
await operations.call(editing, withTargetsOf(editing, row, edit));
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
catch (failure) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type EntityOperations } from "@sincpro/client-framework";
|
|
2
2
|
import { type AnyRecord, type Expression } from "@sincpro/criteria";
|
|
3
|
+
import type { BodyOf, CommandName } from "../../core/command.js";
|
|
3
4
|
import type { Listing } from "../../react/useListing.js";
|
|
4
5
|
import type { RowAction } from "@sincpro/web-ui";
|
|
5
6
|
import type { LucideIcon } from "lucide-react";
|
|
@@ -22,8 +23,8 @@ import type { LucideIcon } from "lucide-react";
|
|
|
22
23
|
* ]);
|
|
23
24
|
* <EntityList listing={listing} rowActions={commands.rowActions} />
|
|
24
25
|
*/
|
|
25
|
-
export type RowCommand<T,
|
|
26
|
-
[N in
|
|
26
|
+
export type RowCommand<T, O extends EntityOperations = EntityOperations> = {
|
|
27
|
+
[N in CommandName<O>]: {
|
|
27
28
|
/** A Command the entity declares (`entity({ commands })`); a typed entity, only its own. */
|
|
28
29
|
command: N;
|
|
29
30
|
label: string;
|
|
@@ -31,12 +32,12 @@ export type RowCommand<T, C extends CommandBodies = CommandBodies> = {
|
|
|
31
32
|
tone?: RowAction["tone"];
|
|
32
33
|
/** Offered only on rows that hold it — a hint, not protection: the server decides. */
|
|
33
34
|
when?: Expression<T>;
|
|
34
|
-
/** What the Command is sent with — checked against
|
|
35
|
-
*
|
|
36
|
-
body?: (row: T) =>
|
|
35
|
+
/** What the Command is sent with — checked against its operation's input. Without it, an
|
|
36
|
+
* empty body: the row's key goes where the operation names it. */
|
|
37
|
+
body?: (row: T) => BodyOf<O, N>;
|
|
37
38
|
};
|
|
38
|
-
}[
|
|
39
|
-
/** The row action of the trash (`trashOf`): the entity's `restore
|
|
39
|
+
}[CommandName<O>];
|
|
40
|
+
/** The row action of the trash (`trashOf`): the entity's `restore`, run from the row. */
|
|
40
41
|
export declare const RESTORE = "restore";
|
|
41
42
|
export type RowCommands<T> = {
|
|
42
43
|
rowActions: (row: T) => readonly RowAction[];
|
|
@@ -44,4 +45,4 @@ export type RowCommands<T> = {
|
|
|
44
45
|
error: unknown;
|
|
45
46
|
dismiss: () => void;
|
|
46
47
|
};
|
|
47
|
-
export declare function useRowCommands<T extends AnyRecord,
|
|
48
|
+
export declare function useRowCommands<T extends AnyRecord, O extends EntityOperations = EntityOperations>(listing: Listing<T, O>, commands: readonly RowCommand<T, O>[]): RowCommands<T>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { retryKeys, targeted } from "@sincpro/client-framework";
|
|
3
3
|
import { matches } from "@sincpro/criteria";
|
|
4
|
+
import { withTargetsOf } from "../../core/edit.js";
|
|
4
5
|
import { useFramework } from "../../react/context.js";
|
|
5
6
|
import { useCallback, useState } from "react";
|
|
6
|
-
/** The row action of the trash (`trashOf`): the entity's `restore
|
|
7
|
+
/** The row action of the trash (`trashOf`): the entity's `restore`, run from the row. */
|
|
7
8
|
export const RESTORE = "restore";
|
|
8
9
|
export function useRowCommands(listing, commands) {
|
|
9
|
-
const {
|
|
10
|
+
const { operations } = useFramework();
|
|
10
11
|
const [running, setRunning] = useState(new Set());
|
|
11
12
|
const [error, setError] = useState(null);
|
|
12
13
|
// One key per row and Command, kept while it goes unanswered: retrying is the same gesture.
|
|
@@ -14,25 +15,23 @@ export function useRowCommands(listing, commands) {
|
|
|
14
15
|
const { entity, meta } = listing;
|
|
15
16
|
const key = meta?.get_id || meta?.identity || "id";
|
|
16
17
|
const run = useCallback(async (one, row) => {
|
|
17
|
-
// «Restore» on a row of the trash runs the entity's own `restore`
|
|
18
|
-
//
|
|
19
|
-
const
|
|
20
|
-
(one.command === RESTORE ? entity.restore : undefined);
|
|
21
|
-
if (
|
|
18
|
+
// «Restore» on a row of the trash runs the entity's own `restore` (`trashOf`), unless the
|
|
19
|
+
// entity declares a Command of that name.
|
|
20
|
+
const operation = entity.operations.commands?.[one.command] ??
|
|
21
|
+
(one.command === RESTORE ? entity.operations.restore : undefined);
|
|
22
|
+
if (operation === undefined)
|
|
22
23
|
throw new Error(`${entity.key} declares no command "${one.command}"`);
|
|
23
24
|
const id = String(row[key]);
|
|
24
25
|
const gesture = `${one.command}\u0000${id}`;
|
|
25
26
|
const retry = keys.get(gesture) ?? retryKeys();
|
|
26
27
|
keys.set(gesture, retry);
|
|
27
|
-
//
|
|
28
|
-
|
|
28
|
+
// The row's id where the operation names its record; what else it names (`tenant_id`)
|
|
29
|
+
// is the row's, unless the body says it.
|
|
30
|
+
const body = withTargetsOf(operation, row, targeted(entity, operation, id, one.body?.(row) ?? {}));
|
|
29
31
|
setRunning((now) => new Set(now).add(gesture));
|
|
30
32
|
setError(null);
|
|
31
33
|
try {
|
|
32
|
-
|
|
33
|
-
await transport.send(route.method, pathFor(route, id, { ...row, ...body }), body, undefined, {
|
|
34
|
-
idempotencyKey: retry.keyFor(body),
|
|
35
|
-
});
|
|
34
|
+
await operations.call(operation, body, { idempotencyKey: retry.keyFor(body) });
|
|
36
35
|
retry.settle(null);
|
|
37
36
|
listing.reload();
|
|
38
37
|
}
|
|
@@ -47,7 +46,7 @@ export function useRowCommands(listing, commands) {
|
|
|
47
46
|
return next;
|
|
48
47
|
});
|
|
49
48
|
}
|
|
50
|
-
}, [
|
|
49
|
+
}, [operations, entity, key, keys, listing]);
|
|
51
50
|
const rowActions = (row) => commands
|
|
52
51
|
.filter((one) => meta === null || one.when === undefined || matches(row, one.when, meta))
|
|
53
52
|
.map((one) => ({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type EntityOperations } from "@sincpro/client-framework";
|
|
2
2
|
import { type AnyRecord } from "@sincpro/criteria";
|
|
3
3
|
import { type EntityListProps } from "./entityList/props.js";
|
|
4
4
|
export type { EntityEmpty, EntityFace, EntityListProps, NamedFilter, View, } from "./entityList/props.js";
|
|
@@ -21,10 +21,10 @@ export type { EntityEmpty, EntityFace, EntityListProps, NamedFilter, View, } fro
|
|
|
21
21
|
* What the screen asks wins over the named list's (`defineList`), which wins over the entity's
|
|
22
22
|
* own look (`presented`), which wins over the model.
|
|
23
23
|
*/
|
|
24
|
-
export declare function useEntityList<T extends AnyRecord,
|
|
24
|
+
export declare function useEntityList<T extends AnyRecord, O extends EntityOperations = EntityOperations>({ listing, api, columns: askedColumns, cells, yesNo, views: askedViews, title, description, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot, empty, search, recent: askedRecent, sums, filters, facets, groupable, selectable, selection: held, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, O>,
|
|
25
25
|
/** The faces the screen's tree writes, when it writes one (`EntityList.Table`…). */
|
|
26
26
|
writtenViews?: readonly string[]): {
|
|
27
|
-
listing: import("../../index.js").Listing<T,
|
|
27
|
+
listing: import("../../index.js").Listing<T, O>;
|
|
28
28
|
meta: import("@sincpro/criteria").Meta | null;
|
|
29
29
|
locale: string | undefined;
|
|
30
30
|
embedded: boolean;
|
|
@@ -180,4 +180,4 @@ writtenViews?: readonly string[]): {
|
|
|
180
180
|
};
|
|
181
181
|
};
|
|
182
182
|
/** What a list's root and its parts read. */
|
|
183
|
-
export type EntityListState<T extends AnyRecord = AnyRecord> = ReturnType<typeof useEntityList<T,
|
|
183
|
+
export type EntityListState<T extends AnyRecord = AnyRecord> = ReturnType<typeof useEntityList<T, EntityOperations>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Entity, type EntityOperations } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
|
-
import {
|
|
3
|
+
import type { BodyOf, CommandAnswer, CommandName } from "../../core/command.js";
|
|
4
4
|
import { type ActionDialog } from "./ActionButton.js";
|
|
5
5
|
import { type AskField } from "./ask.js";
|
|
6
6
|
import { type ActionLook, type DockedAction } from "./dock.js";
|
|
@@ -17,13 +17,13 @@ import { type ActionLook, type DockedAction } from "./dock.js";
|
|
|
17
17
|
* beside `body`.
|
|
18
18
|
*/
|
|
19
19
|
/** What a Command's button and dock action are given. */
|
|
20
|
-
export type CommandActionProps<T extends AnyRecord, R,
|
|
21
|
-
entity: Entity<T,
|
|
20
|
+
export type CommandActionProps<T extends AnyRecord, R, O extends EntityOperations, N extends CommandName<O>> = {
|
|
21
|
+
entity: Entity<T, O>;
|
|
22
22
|
/** One the entity declares; a typed entity takes only its own names. */
|
|
23
23
|
command: N;
|
|
24
24
|
id?: string;
|
|
25
25
|
/** What it is sent with — checked against a typed entity's `C[command]`. */
|
|
26
|
-
body?:
|
|
26
|
+
body?: BodyOf<O, N>;
|
|
27
27
|
label: string;
|
|
28
28
|
/** Asks the server what it would do before doing it. */
|
|
29
29
|
destructive?: boolean;
|
|
@@ -35,9 +35,9 @@ export type CommandActionProps<T extends AnyRecord, R, C extends CommandBodies,
|
|
|
35
35
|
record?: AnyRecord;
|
|
36
36
|
/** What its window says — its title (the label without «…» by default), a sentence under it. */
|
|
37
37
|
dialog?: ActionDialog;
|
|
38
|
-
onDone?: (answer:
|
|
38
|
+
onDone?: (answer: CommandAnswer<R, O, N>) => void;
|
|
39
39
|
};
|
|
40
|
-
export declare function CommandButton<T extends AnyRecord, R = unknown,
|
|
40
|
+
export declare function CommandButton<T extends AnyRecord, R = unknown, O extends EntityOperations = EntityOperations, N extends CommandName<O> = CommandName<O>>({ role, ...props }: CommandActionProps<T, R, O, N> & {
|
|
41
41
|
role?: "primary" | "secondary" | "ghost";
|
|
42
42
|
}): import("react").JSX.Element;
|
|
43
43
|
/**
|
|
@@ -52,7 +52,7 @@ export declare function CommandButton<T extends AnyRecord, R = unknown, C extend
|
|
|
52
52
|
* <Record.Dock actions={[confirmar.action, anular.action]} />
|
|
53
53
|
* {anular.dialog}
|
|
54
54
|
*/
|
|
55
|
-
export declare function useCommandAction<T extends AnyRecord, R = unknown,
|
|
55
|
+
export declare function useCommandAction<T extends AnyRecord, R = unknown, O extends EntityOperations = EntityOperations, N extends CommandName<O> = CommandName<O>>({ icon, primary, danger, tucked, shortcut, hint, actionId, ...props }: CommandActionProps<T, R, O, N> & Omit<ActionLook, "id"> & {
|
|
56
56
|
/** The dock's id for it — the record's is `id`. Defaults to the label. */
|
|
57
57
|
actionId?: string;
|
|
58
58
|
}): DockedAction;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { keysOf
|
|
3
|
+
import { keysOf } from "@sincpro/client-framework";
|
|
4
4
|
import { isList } from "../../core/list.js";
|
|
5
5
|
import { useFramework } from "../../react/context.js";
|
|
6
6
|
import { BATCH_LIMIT } from "../../react/useBatchCommand.js";
|
|
@@ -33,7 +33,7 @@ import { useRef } from "react";
|
|
|
33
33
|
* <EntityTags entity={people} value={followers} onChange={setFollowers} />
|
|
34
34
|
*/
|
|
35
35
|
export function EntityTags({ entity, value, onChange, criteria, onOpen, openTarget, onBrowseAll, placeholder, disabled, "aria-label": ariaLabel, }) {
|
|
36
|
-
const { metas,
|
|
36
|
+
const { metas, operations } = useFramework();
|
|
37
37
|
const opening = useRecordOpening();
|
|
38
38
|
const toast = useToastIfAny();
|
|
39
39
|
const base = isList(entity) ? entity.entity : entity;
|
|
@@ -54,8 +54,8 @@ export function EntityTags({ entity, value, onChange, criteria, onOpen, openTarg
|
|
|
54
54
|
const addChosen = (selection) => {
|
|
55
55
|
const meta = metas.get(base.key);
|
|
56
56
|
keysOf(selection, {
|
|
57
|
-
transport,
|
|
58
|
-
|
|
57
|
+
transport: operations,
|
|
58
|
+
entity: base,
|
|
59
59
|
identity: meta?.get_id || meta?.identity || "id",
|
|
60
60
|
limit: BATCH_LIMIT,
|
|
61
61
|
}).then(add, (failure) => toast?.show(refusalNotice(failure)));
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import {} from "@sincpro/client-framework";
|
|
4
4
|
import { frameworkCopy } from "../../core/copy.js";
|
|
5
|
-
import { fieldStateOf } from "../../core/edit.js";
|
|
5
|
+
import { canCreate, fieldStateOf } from "../../core/edit.js";
|
|
6
6
|
import { defaultFields, STAMPS } from "../../core/present.js";
|
|
7
7
|
import { backReference, isKeyValue } from "../../core/relation.js";
|
|
8
8
|
import { useRelated } from "../../react/useRelated.js";
|
|
@@ -65,7 +65,7 @@ export function RelatedList({ record, name, entity, pageSize, ...list }) {
|
|
|
65
65
|
// The value the rows point back with.
|
|
66
66
|
const here = pointing?.value;
|
|
67
67
|
const adding = create === undefined ||
|
|
68
|
-
entity.
|
|
68
|
+
!canCreate(entity, listing.meta) ||
|
|
69
69
|
!back ||
|
|
70
70
|
record.isNew ||
|
|
71
71
|
!isKeyValue(here) ||
|
package/dist/web/record/lines.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { keysOf
|
|
3
|
+
import { keysOf } from "@sincpro/client-framework";
|
|
4
4
|
import { choicesOf } from "@sincpro/criteria";
|
|
5
5
|
import { frameworkCopy } from "../../core/copy.js";
|
|
6
6
|
import { adviceAt, defaultsOf, errorAt, linePlacesOf, pathOf, } from "../../core/edit.js";
|
|
@@ -122,7 +122,7 @@ function LineValue({ definition, field, line, set, label, invalid, locale, inCel
|
|
|
122
122
|
*/
|
|
123
123
|
export function RecordLinesEditor({ record, name, lines, look = {}, }) {
|
|
124
124
|
const { meta, locale, edit } = record;
|
|
125
|
-
const { entities, metas,
|
|
125
|
+
const { entities, metas, operations } = useFramework();
|
|
126
126
|
const opening = useRecordOpening();
|
|
127
127
|
const toast = useToastIfAny();
|
|
128
128
|
const definition = meta?.fields[name]?.definition ?? null;
|
|
@@ -177,8 +177,8 @@ export function RecordLinesEditor({ record, name, lines, look = {}, }) {
|
|
|
177
177
|
: () => chooseMany(manyEntity, (selection) => {
|
|
178
178
|
const meta = metas.get(manyEntity.key);
|
|
179
179
|
keysOf(selection, {
|
|
180
|
-
transport,
|
|
181
|
-
|
|
180
|
+
transport: operations,
|
|
181
|
+
entity: manyEntity,
|
|
182
182
|
identity: meta?.get_id || meta?.identity || "id",
|
|
183
183
|
limit: BATCH_LIMIT,
|
|
184
184
|
}).then((keys) => write((all) => [
|
|
@@ -24,7 +24,7 @@ export function RichTextControl({ control }) {
|
|
|
24
24
|
const { richText, uploads, transport } = useFramework();
|
|
25
25
|
const { about } = control;
|
|
26
26
|
const html = typeof control.value === "string" ? control.value : "";
|
|
27
|
-
const images = useMemo(() => uploads === undefined || about === undefined
|
|
27
|
+
const images = useMemo(() => uploads === undefined || transport === undefined || about === undefined
|
|
28
28
|
? undefined
|
|
29
29
|
: {
|
|
30
30
|
upload: async (file) => {
|