@sincpro/web-framework 3.22.0 → 4.1.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 +3 -2
- package/dist/core/index.js +3 -2
- package/dist/core/list.d.ts +17 -11
- package/dist/core/list.js +17 -11
- package/dist/core/models.d.ts +16 -0
- package/dist/core/models.js +18 -0
- package/dist/core/names.d.ts +8 -6
- package/dist/core/names.js +16 -19
- 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 +22 -10
- 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 +12 -13
- 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 +9 -8
- package/dist/react/useListing.d.ts +14 -7
- package/dist/react/useListing.js +35 -10
- package/dist/react/useLookup.js +8 -9
- 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 +40 -57
- package/dist/react/useRecordLifecycle.js +8 -9
- package/dist/react/useServiceReading.js +6 -18
- package/dist/react/useSummary.js +2 -1
- 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 +25 -45
- 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/CommandButton.js +2 -1
- package/dist/web/record/EntityPicker.js +2 -1
- package/dist/web/record/EntityTags.js +7 -6
- package/dist/web/record/RelatedList.js +2 -2
- package/dist/web/record/ServiceButton.js +6 -1
- package/dist/web/record/choice.js +2 -1
- package/dist/web/record/edit.js +2 -1
- package/dist/web/record/lines.js +6 -5
- 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 +31 -8
- package/dist/web/workspace/record.js +2 -2
- package/package.json +3 -3
|
@@ -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 { WorkspaceApi } from "@sincpro/web-composer";
|
|
4
4
|
import type { GroupLevel, NamedFilter } from "../../../core/list.js";
|
|
@@ -13,8 +13,8 @@ export type { NamedFilter };
|
|
|
13
13
|
* What a screen says to an `EntityList`: values, never regions — a region is a part
|
|
14
14
|
* (`EntityList.Bar`, `EntityList.Table`…).
|
|
15
15
|
*/
|
|
16
|
-
export type EntityListProps<T extends AnyRecord,
|
|
17
|
-
listing: Listing<T,
|
|
16
|
+
export type EntityListProps<T extends AnyRecord, O extends EntityOperations = EntityOperations> = {
|
|
17
|
+
listing: Listing<T, O>;
|
|
18
18
|
/**
|
|
19
19
|
* The workspace this list is a view of. With it, a row opens its record as a page, the
|
|
20
20
|
* identity column is the composer's `RecordLink` (peek, side panel, window on hover) and the
|
|
@@ -135,7 +135,7 @@ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = Comma
|
|
|
135
135
|
* The entity's Commands offered on each row («Confirmar»), sent with their idempotency key;
|
|
136
136
|
* the list is read again when one is done (`useRowCommands`).
|
|
137
137
|
*/
|
|
138
|
-
commands?: readonly RowCommand<T,
|
|
138
|
+
commands?: readonly RowCommand<T, O>[];
|
|
139
139
|
/** Any other action of a row — or the commands built by hand with `useRowCommands`. */
|
|
140
140
|
rowActions?: (row: T) => readonly RowAction[];
|
|
141
141
|
/**
|
|
@@ -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 { Listing } from "../../../react/useListing.js";
|
|
4
4
|
import { type RowCommand } from "../rowCommands.js";
|
|
@@ -11,10 +11,10 @@ import type { RowAction } from "@sincpro/web-ui";
|
|
|
11
11
|
* undone, so it runs on the click, and the list reads again after. Rows are reordered only on the
|
|
12
12
|
* whole order, never grouped or while choosing.
|
|
13
13
|
*/
|
|
14
|
-
export declare function useListRowActions<T extends AnyRecord,
|
|
15
|
-
listing: Listing<T,
|
|
14
|
+
export declare function useListRowActions<T extends AnyRecord, O extends EntityOperations>({ listing, idOf, commands, rowActions: asked, grouped, choosing, }: {
|
|
15
|
+
listing: Listing<T, O>;
|
|
16
16
|
idOf: (row: T) => string;
|
|
17
|
-
commands: readonly RowCommand<T,
|
|
17
|
+
commands: readonly RowCommand<T, O>[];
|
|
18
18
|
rowActions: ((row: T) => readonly RowAction[]) | undefined;
|
|
19
19
|
grouped: boolean;
|
|
20
20
|
choosing: boolean;
|
|
@@ -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,12 @@
|
|
|
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 { knownModelOf } from "../../core/models.js";
|
|
9
|
+
import { searchedAlone } from "../../core/names.js";
|
|
8
10
|
import { entityFor } from "../../core/relation.js";
|
|
9
11
|
import { summaryOf } from "../../core/summary.js";
|
|
10
12
|
import { useFramework } from "../../react/context.js";
|
|
@@ -18,7 +20,7 @@ import { createContext, useContext, useMemo } from "react";
|
|
|
18
20
|
* template and a short page), each record whole, read as its name and, beside it, what tells it
|
|
19
21
|
* apart — the entity's `option` look, else its summary's description or type. Never its key.
|
|
20
22
|
*
|
|
21
|
-
* await findChoices(
|
|
23
|
+
* await findChoices(operations, clientes, clienteMeta, "andres", "es")
|
|
22
24
|
* -> [{ id: "C-7", name: "Andrés Pérez", detail: "NIT 4455667" }, …]
|
|
23
25
|
*
|
|
24
26
|
* Context: `matching` asks for references (identity and display), and the `option` look and the
|
|
@@ -26,9 +28,9 @@ import { createContext, useContext, useMemo } from "react";
|
|
|
26
28
|
* backend (#48). The question keeps `matching`'s template and its page, and brings each record
|
|
27
29
|
* whole. ⌘K and the search bar's records (web-ui 2.7) read a record the same way, here.
|
|
28
30
|
*/
|
|
29
|
-
export async function findChoices(
|
|
31
|
+
export async function findChoices(operations, entity, meta, text, locale, options = {}) {
|
|
30
32
|
const { specification: _reference, ...question } = matching(meta, text);
|
|
31
|
-
const page = await
|
|
33
|
+
const page = await readPage(operations, entity, question, { ...options, meta });
|
|
32
34
|
const look = presentationOf(entity).option;
|
|
33
35
|
return lookupOf(meta, page.rows, entity.summary).map((one) => {
|
|
34
36
|
const own = look === undefined || one.record === undefined ? {} : look(one.record);
|
|
@@ -46,30 +48,6 @@ export async function findChoices(transport, entity, meta, route, text, locale,
|
|
|
46
48
|
};
|
|
47
49
|
});
|
|
48
50
|
}
|
|
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
51
|
/**
|
|
74
52
|
* web-ui's `searchRecords` (2.7) answered by the framework: the records of a relation the search
|
|
75
53
|
* bar unfolds and the criteria builder picks — «andres» → the customers that match —, each
|
|
@@ -79,7 +57,7 @@ async function metaOf(framework, entity, signal) {
|
|
|
79
57
|
* application did not declare finds nothing — the bar still offers the relation's text.
|
|
80
58
|
* 2. Keys instead of a text (a filter read back from a link): their names, through the book every
|
|
81
59
|
* 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
|
|
60
|
+
* 3. Else the entity's literal search (`findChoices`), by its definition (the contract's, `metas`).
|
|
83
61
|
*/
|
|
84
62
|
export function recordsSearch(framework, locale) {
|
|
85
63
|
return async ({ relation, text, keys, signal }) => {
|
|
@@ -91,11 +69,14 @@ export function recordsSearch(framework, locale) {
|
|
|
91
69
|
id: key,
|
|
92
70
|
name: (await framework.names.nameOf(entity, String(key))) ?? String(key),
|
|
93
71
|
})));
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
72
|
+
if (!searchedAlone(entity))
|
|
73
|
+
return [];
|
|
74
|
+
const meta = knownModelOf(framework.metas, entity);
|
|
75
|
+
if (meta === undefined)
|
|
97
76
|
return [];
|
|
98
|
-
const choices = await findChoices(framework.
|
|
77
|
+
const choices = await findChoices(framework.operations, entity, meta, text, locale, {
|
|
78
|
+
signal,
|
|
79
|
+
});
|
|
99
80
|
return choices.map((one) => ({
|
|
100
81
|
id: one.id,
|
|
101
82
|
name: one.name,
|
|
@@ -103,11 +84,11 @@ export function recordsSearch(framework, locale) {
|
|
|
103
84
|
}));
|
|
104
85
|
};
|
|
105
86
|
}
|
|
106
|
-
/** `recordsSearch` over the framework's context: the screens'
|
|
87
|
+
/** `recordsSearch` over the framework's context: the screens' operations, its definitions and
|
|
107
88
|
* its names, in the provider's language. */
|
|
108
89
|
export function useSearchRecords() {
|
|
109
|
-
const {
|
|
110
|
-
return useMemo(() => recordsSearch({
|
|
90
|
+
const { operations, metas, names, entities, locale } = useFramework();
|
|
91
|
+
return useMemo(() => recordsSearch({ operations, metas, names, entities }, locale), [operations, metas, names, entities, locale]);
|
|
111
92
|
}
|
|
112
93
|
/**
|
|
113
94
|
* web-ui's `loadModel` (2.8) answered by the framework: the model at the end of a path of
|
|
@@ -118,7 +99,7 @@ export function useSearchRecords() {
|
|
|
118
99
|
*
|
|
119
100
|
* 1. From the root's definition, each name of the path is a relation of the model before it.
|
|
120
101
|
* 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),
|
|
102
|
+
* entity's (`entityFor` by the aggregate it names), as the screens know it (`metas`).
|
|
122
103
|
* Final: that definition as web-ui reads a model (`modelOf`); a path that leads nowhere — a name
|
|
123
104
|
* the model lacks, a relation to an entity the application did not declare — is refused.
|
|
124
105
|
*/
|
|
@@ -132,7 +113,7 @@ export function modelLoader(framework, root, locale) {
|
|
|
132
113
|
const entity = typeof field.relation === "string"
|
|
133
114
|
? entityFor(framework.entities, field.relation, framework.metas.get)
|
|
134
115
|
: undefined;
|
|
135
|
-
return entity === undefined ? undefined :
|
|
116
|
+
return entity === undefined ? undefined : knownModelOf(framework.metas, entity);
|
|
136
117
|
};
|
|
137
118
|
return async (path) => {
|
|
138
119
|
let meta = root;
|
|
@@ -147,10 +128,10 @@ export function modelLoader(framework, root, locale) {
|
|
|
147
128
|
}
|
|
148
129
|
/** `modelLoader` over the framework's context, from a list's definition (none yet: none). */
|
|
149
130
|
export function useLoadModel(root) {
|
|
150
|
-
const {
|
|
131
|
+
const { operations, metas, names, entities, locale } = useFramework();
|
|
151
132
|
return useMemo(() => root == null
|
|
152
133
|
? undefined
|
|
153
|
-
: modelLoader({
|
|
134
|
+
: modelLoader({ operations, metas, names, entities }, root, locale), [root, operations, metas, names, entities, locale]);
|
|
154
135
|
}
|
|
155
136
|
/**
|
|
156
137
|
* web-ui's `browseRecords` (2.8) answered by the framework: «Buscar más…» under the records of a
|
|
@@ -169,7 +150,7 @@ export function recordsBrowser(framework, open, names, refused) {
|
|
|
169
150
|
const entity = entityFor(framework.entities, browse.relation, framework.metas.get);
|
|
170
151
|
if (entity === undefined)
|
|
171
152
|
return;
|
|
172
|
-
const meta = framework.metas
|
|
153
|
+
const meta = knownModelOf(framework.metas, entity);
|
|
173
154
|
const identity = meta?.get_id || meta?.identity || "id";
|
|
174
155
|
const chosen = browse.chosen.map((one) => String(one.id));
|
|
175
156
|
const scope = chosen.length === 0
|
|
@@ -182,11 +163,10 @@ export function recordsBrowser(framework, open, names, refused) {
|
|
|
182
163
|
keys,
|
|
183
164
|
signal: new AbortController().signal,
|
|
184
165
|
}).then(browse.choose, refused);
|
|
185
|
-
|
|
186
|
-
if (browse.many && open.chooseMany !== undefined && route !== undefined)
|
|
166
|
+
if (browse.many && open.chooseMany !== undefined && searchedAlone(entity))
|
|
187
167
|
open.chooseMany(entity, (selection) => void keysOf(selection, {
|
|
188
|
-
transport: framework.
|
|
189
|
-
|
|
168
|
+
transport: framework.operations,
|
|
169
|
+
entity,
|
|
190
170
|
identity,
|
|
191
171
|
limit: BATCH_LIMIT,
|
|
192
172
|
}).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,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import {} from "@sincpro/client-framework";
|
|
4
|
+
import { knownModelOf } from "../../core/models.js";
|
|
4
5
|
import { entityFor } from "../../core/relation.js";
|
|
5
6
|
import { useFramework } from "../../react/context.js";
|
|
6
7
|
import { useCommand } from "../../react/useCommand.js";
|
|
@@ -49,7 +50,7 @@ function useCommandBehind({ entity, command, id, body, destructive = false, ask,
|
|
|
49
50
|
const form = ask === undefined
|
|
50
51
|
? undefined
|
|
51
52
|
: askFormOf(ask, {
|
|
52
|
-
meta: metas
|
|
53
|
+
meta: knownModelOf(metas, entity),
|
|
53
54
|
locale,
|
|
54
55
|
record,
|
|
55
56
|
entityFor: (target) => entityFor(entities, target, metas.get),
|
|
@@ -4,6 +4,7 @@ import {} from "@sincpro/client-framework";
|
|
|
4
4
|
import { nameOf } from "@sincpro/criteria";
|
|
5
5
|
import { frameworkCopy } from "../../core/copy.js";
|
|
6
6
|
import { isList } from "../../core/list.js";
|
|
7
|
+
import { knownModelOf } from "../../core/models.js";
|
|
7
8
|
import { useFramework } from "../../react/context.js";
|
|
8
9
|
import { useListing } from "../../react/useListing.js";
|
|
9
10
|
import { excluding, useLookup } from "../../react/useLookup.js";
|
|
@@ -63,7 +64,7 @@ export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onB
|
|
|
63
64
|
...(exclude === undefined ? {} : { exclude }),
|
|
64
65
|
});
|
|
65
66
|
// The chooser opens after the picker read the definition: it excludes from its first page.
|
|
66
|
-
const scope = excluding(criteria, exclude, metas
|
|
67
|
+
const scope = excluding(criteria, exclude, knownModelOf(metas, base));
|
|
67
68
|
const person = base.summary.person === true;
|
|
68
69
|
const nothing = none === undefined || none === false || lookup.text !== ""
|
|
69
70
|
? []
|