@sincpro/web-framework 3.4.0 → 3.5.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/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/list.d.ts +39 -2
- package/dist/core/list.js +44 -1
- package/dist/react/useListing.d.ts +7 -1
- package/dist/react/useListing.js +9 -21
- package/dist/react/useServiceReading.d.ts +8 -0
- package/dist/react/useServiceReading.js +16 -1
- package/dist/web/workspace/record.d.ts +1 -1
- package/package.json +5 -5
package/dist/core/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export { type FormLayout, formOf } from "./form.js";
|
|
|
15
15
|
export { areGroups, NotGrouped } from "./groups.js";
|
|
16
16
|
export { FACT_TONES, type FactTone, type HistoryEntry, historyOf, toneOfFact, } from "./history.js";
|
|
17
17
|
export { addingOf, type AddingRule, blankLine, type Declared, editableLines, isReference, type LineAdding, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
|
|
18
|
-
export { defineList, type GroupLevel, isList, type ListDefinition, type ListSpec, type NamedFilter, scopeOf, trashOf, } from "./list.js";
|
|
18
|
+
export { defineList, type GroupLevel, isList, type ListDefinition, listingAsk, type ListingQuestion, type ListSpec, type NamedFilter, readListing, scopeOf, trashOf, } from "./list.js";
|
|
19
19
|
export { lookupOf, type LookupOption } from "./lookup.js";
|
|
20
20
|
export { detailOf, measuresOf, sumsOf, type Total, totalOf, } from "./measure.js";
|
|
21
21
|
export { BOOKKEEPING, currencyNow, type DateStyle, dateStyleNow, dayTextOf, defaultFields, fieldAt, fieldMetaOf, type FieldView, installCurrency, installDateStyle, instantTextOf, moneyTextOf, numberTextOf, sortKeyOf, STAMPS, textOf, valueAt, viewOf, } from "./present.js";
|
package/dist/core/index.js
CHANGED
|
@@ -15,7 +15,7 @@ export { formOf } from "./form.js";
|
|
|
15
15
|
export { areGroups, NotGrouped } from "./groups.js";
|
|
16
16
|
export { FACT_TONES, historyOf, toneOfFact, } from "./history.js";
|
|
17
17
|
export { addingOf, blankLine, editableLines, isReference, lineFields, lineKey, linesAnswered, moved, sameLine, writtenInCell, } from "./lines.js";
|
|
18
|
-
export { defineList, isList, scopeOf, trashOf, } from "./list.js";
|
|
18
|
+
export { defineList, isList, listingAsk, readListing, scopeOf, trashOf, } from "./list.js";
|
|
19
19
|
export { lookupOf } from "./lookup.js";
|
|
20
20
|
export { detailOf, measuresOf, sumsOf, totalOf, } from "./measure.js";
|
|
21
21
|
export { BOOKKEEPING, currencyNow, dateStyleNow, dayTextOf, defaultFields, fieldAt, fieldMetaOf, installCurrency, installDateStyle, instantTextOf, moneyTextOf, numberTextOf, sortKeyOf, STAMPS, textOf, valueAt, viewOf, } from "./present.js";
|
package/dist/core/list.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type Entity, type ResourceRef } from "@sincpro/client-framework";
|
|
2
|
-
import type
|
|
1
|
+
import { type Entity, type ResourceRef, type Transport } from "@sincpro/client-framework";
|
|
2
|
+
import { type AnyRecord, type Criteria, type Expression, type Grain, type Page, type Sort } from "@sincpro/criteria";
|
|
3
3
|
/**
|
|
4
4
|
* A named way of looking at an entity: «Por cobrar», «Borradores», «Mis tickets».
|
|
5
5
|
*
|
|
@@ -70,6 +70,43 @@ export declare function defineList<T extends AnyRecord>(entity: Entity<T>, spec:
|
|
|
70
70
|
export declare function isList<T extends AnyRecord>(given: Entity<T> | ListDefinition<T>): given is ListDefinition<T>;
|
|
71
71
|
/** The criteria a definition always asks: its scope, in its order. */
|
|
72
72
|
export declare function scopeOf<T extends AnyRecord>(list: ListDefinition<T>): Criteria<T>;
|
|
73
|
+
/** What a listing's first page depends on, besides the entity or the named list. */
|
|
74
|
+
export type ListingQuestion<T> = {
|
|
75
|
+
/** The route's own parameters: `{ tenant_id: "acme" }` → `/projects?tenant_id=acme`. */
|
|
76
|
+
params?: Readonly<Record<string, string>>;
|
|
77
|
+
/** What the listing always asks — a scope. Search, filter and order AND it. */
|
|
78
|
+
criteria?: Criteria<T>;
|
|
79
|
+
/** Rows per page. 50 by default; the server's own default too. */
|
|
80
|
+
pageSize?: number;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* The route and the criteria of a listing's first page: the named list's scope, a screen's cut
|
|
84
|
+
* and the caller's criteria ANDed, the page size set.
|
|
85
|
+
*
|
|
86
|
+
* listingAsk(porCobrar, { pageSize: 25 })
|
|
87
|
+
* → { route: "/facturas", criteria: { selection: state = posted, pagination: { limit: 25 } } }
|
|
88
|
+
*
|
|
89
|
+
* Context: `useListing` asks it on mount and `readListing` asks it on a server, so a page read
|
|
90
|
+
* there is the very page the screen would have asked for, and hydrating it reads nothing twice.
|
|
91
|
+
*/
|
|
92
|
+
export declare function listingAsk<T extends AnyRecord>(given: Entity<T> | ListDefinition<T>, own?: ListingQuestion<T>, cut?: Expression<T>): {
|
|
93
|
+
route: string;
|
|
94
|
+
criteria: Criteria<T>;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* A listing's first page, read outside React — on the server that renders the screen, in a
|
|
98
|
+
* route's loader —, through the same transport the `FrameworkProvider` is given. Handed to
|
|
99
|
+
* `useListing(list, { ...own, page })`, the screen starts from it and asks nothing on mount.
|
|
100
|
+
*
|
|
101
|
+
* // the loader, on the server
|
|
102
|
+
* const page = await readListing(transport, misPagos, { criteria: delColegiado });
|
|
103
|
+
* // the screen, rendered there and hydrated in the browser
|
|
104
|
+
* const listing = useListing(misPagos, { criteria: delColegiado, page });
|
|
105
|
+
*
|
|
106
|
+
* A chooser's cut (`ListScopeProvider`) lives in the screen and is not read here: a listing
|
|
107
|
+
* under one is asked with it by the screen, as a SPA does.
|
|
108
|
+
*/
|
|
109
|
+
export declare function readListing<T extends AnyRecord>(transport: Transport, given: Entity<T> | ListDefinition<T>, own?: ListingQuestion<T>, signal?: AbortSignal): Promise<Page<T>>;
|
|
73
110
|
/**
|
|
74
111
|
* An entity's trash, as a named list: its archived records (sincpro_framework's `Archive`,
|
|
75
112
|
* `ArchivableMixin`), each row offering «Restore» when the entity declares `restore`.
|
package/dist/core/list.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {} from "@sincpro/client-framework";
|
|
1
|
+
import { listRoute, screensTransport, } from "@sincpro/client-framework";
|
|
2
|
+
import { merge, } from "@sincpro/criteria";
|
|
2
3
|
import { frameworkCopy } from "./copy.js";
|
|
3
4
|
export function defineList(entity, spec) {
|
|
4
5
|
if (!/^[a-z0-9][a-z0-9-]*$/.test(spec.id))
|
|
@@ -22,6 +23,48 @@ export function scopeOf(list) {
|
|
|
22
23
|
...(list.order === undefined ? {} : { order: [list.order] }),
|
|
23
24
|
};
|
|
24
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* The route and the criteria of a listing's first page: the named list's scope, a screen's cut
|
|
28
|
+
* and the caller's criteria ANDed, the page size set.
|
|
29
|
+
*
|
|
30
|
+
* listingAsk(porCobrar, { pageSize: 25 })
|
|
31
|
+
* → { route: "/facturas", criteria: { selection: state = posted, pagination: { limit: 25 } } }
|
|
32
|
+
*
|
|
33
|
+
* Context: `useListing` asks it on mount and `readListing` asks it on a server, so a page read
|
|
34
|
+
* there is the very page the screen would have asked for, and hydrating it reads nothing twice.
|
|
35
|
+
*/
|
|
36
|
+
export function listingAsk(given, own = {}, cut) {
|
|
37
|
+
const definition = isList(given) ? given : undefined;
|
|
38
|
+
const entity = definition?.entity ?? given;
|
|
39
|
+
const parts = [
|
|
40
|
+
...(definition === undefined ? [] : [scopeOf(definition)]),
|
|
41
|
+
...(cut === undefined ? [] : [{ selection: cut }]),
|
|
42
|
+
...(own.criteria === undefined ? [] : [own.criteria]),
|
|
43
|
+
];
|
|
44
|
+
const asked = parts.length === 0 ? undefined : parts.reduce((all, one) => merge(all, one));
|
|
45
|
+
const size = own.pageSize ?? asked?.pagination?.limit ?? 50;
|
|
46
|
+
return {
|
|
47
|
+
route: listRoute(entity.list, own.params),
|
|
48
|
+
criteria: { ...asked, pagination: { ...asked?.pagination, limit: size } },
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A listing's first page, read outside React — on the server that renders the screen, in a
|
|
53
|
+
* route's loader —, through the same transport the `FrameworkProvider` is given. Handed to
|
|
54
|
+
* `useListing(list, { ...own, page })`, the screen starts from it and asks nothing on mount.
|
|
55
|
+
*
|
|
56
|
+
* // the loader, on the server
|
|
57
|
+
* const page = await readListing(transport, misPagos, { criteria: delColegiado });
|
|
58
|
+
* // the screen, rendered there and hydrated in the browser
|
|
59
|
+
* const listing = useListing(misPagos, { criteria: delColegiado, page });
|
|
60
|
+
*
|
|
61
|
+
* A chooser's cut (`ListScopeProvider`) lives in the screen and is not read here: a listing
|
|
62
|
+
* under one is asked with it by the screen, as a SPA does.
|
|
63
|
+
*/
|
|
64
|
+
export function readListing(transport, given, own = {}, signal) {
|
|
65
|
+
const { route, criteria } = listingAsk(given, own);
|
|
66
|
+
return screensTransport(transport).list(route, criteria, signal);
|
|
67
|
+
}
|
|
25
68
|
/**
|
|
26
69
|
* An entity's trash, as a named list: its archived records (sincpro_framework's `Archive`,
|
|
27
70
|
* `ArchivableMixin`), each row offering «Restore» when the entity declares `restore`.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type CommandBodies, type Entity } from "@sincpro/client-framework";
|
|
2
|
-
import { type AnyRecord, type Count, type Criteria, type Dropped, type Expression, type Meta, type ReadingStatus, type Sort } from "@sincpro/criteria";
|
|
2
|
+
import { type AnyRecord, type Count, type Criteria, type Dropped, type Expression, type Meta, type Page, type ReadingStatus, type Sort } from "@sincpro/criteria";
|
|
3
3
|
import { type ListDefinition } from "../core/list.js";
|
|
4
4
|
/**
|
|
5
5
|
* N records of an entity, live: what a list draws and the gestures that drive it.
|
|
@@ -94,5 +94,11 @@ export type ListingOptions<T> = {
|
|
|
94
94
|
pageSize?: number;
|
|
95
95
|
/** `more` mode: the most rows ever on screen. 500 by default. */
|
|
96
96
|
maxRows?: number;
|
|
97
|
+
/**
|
|
98
|
+
* The first page already read — on the server, by `readListing` with this same list and
|
|
99
|
+
* these same options. The listing starts `ready` with it, renders its rows there, and in the
|
|
100
|
+
* browser keeps it instead of asking again. Without it, the listing reads on mount (a SPA).
|
|
101
|
+
*/
|
|
102
|
+
page?: Page<T>;
|
|
97
103
|
};
|
|
98
104
|
export declare function useListing<T extends AnyRecord, C extends CommandBodies = CommandBodies>(given: Entity<T, C> | ListDefinition<T>, own?: ListingOptions<T>): Listing<T, C>;
|
package/dist/react/useListing.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import {} from "@sincpro/client-framework";
|
|
3
3
|
import { merge, resource, resumingFrom, searchOver, } from "@sincpro/criteria";
|
|
4
4
|
import { useReading } from "@sincpro/criteria-react";
|
|
5
|
-
import { isList,
|
|
5
|
+
import { isList, listingAsk } from "../core/list.js";
|
|
6
6
|
import { useFramework } from "./context.js";
|
|
7
7
|
import { useListScope } from "./scope.js";
|
|
8
8
|
import { useWrites } from "./useWrites.js";
|
|
@@ -17,30 +17,18 @@ export function useListing(given, own = {}) {
|
|
|
17
17
|
const entity = (definition?.entity ?? given);
|
|
18
18
|
// The screen's cut for this entity (a chooser's, `ListScopeProvider`) ANDs like a scope.
|
|
19
19
|
const cut = useListScope(entity.key);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
];
|
|
24
|
-
const options = scopes.length === 0
|
|
25
|
-
? own
|
|
26
|
-
: {
|
|
27
|
-
...own,
|
|
28
|
-
criteria: [...scopes, ...(own.criteria === undefined ? [] : [own.criteria])].reduce((all, one) => merge(all, one)),
|
|
29
|
-
};
|
|
30
|
-
const route = listRoute(entity.list, options.params);
|
|
20
|
+
// The first page's question — the list's scope, the cut, the caller's criteria, the page
|
|
21
|
+
// size —: the same `readListing` asks on a server, so a page read there is this one.
|
|
22
|
+
const { route, criteria: asked } = listingAsk(given, own, cut);
|
|
31
23
|
const source = useMemo(() => resource((criteria, signal) => transport.list(route, criteria, signal)), [transport, route]);
|
|
32
24
|
// A definition already known draws the columns before the first page arrives; the one the
|
|
33
25
|
// transport reads from the discovery document comes with it.
|
|
34
26
|
const [preloaded] = useState(() => metas.get(entity.key));
|
|
35
|
-
const paging =
|
|
36
|
-
const size =
|
|
37
|
-
const maxRows =
|
|
38
|
-
const asked = {
|
|
39
|
-
...options.criteria,
|
|
40
|
-
pagination: { ...options.criteria?.pagination, limit: size },
|
|
41
|
-
};
|
|
27
|
+
const paging = own.paging ?? "pages";
|
|
28
|
+
const size = asked.pagination?.limit ?? 50;
|
|
29
|
+
const maxRows = own.maxRows ?? 500;
|
|
42
30
|
const base = asked;
|
|
43
|
-
const reading = useReading(source, base);
|
|
31
|
+
const reading = useReading(source, base, own.page === undefined ? {} : { page: own.page });
|
|
44
32
|
// `pages` mode: the cursor that opens each page walked so far — page 0 opens with none.
|
|
45
33
|
const [cursors, setCursors] = useState([null]);
|
|
46
34
|
// The definition is kept across refinements: a refine in flight must not blank the columns.
|
|
@@ -28,8 +28,16 @@ type UseCase<A extends unknown[], R> = (...args: A) => R | Promise<R>;
|
|
|
28
28
|
* screen until the new one lands. The last question wins: an answer to arguments no longer on
|
|
29
29
|
* screen is dropped. The use case is the latest the screen gave (a bounded context answers a new
|
|
30
30
|
* function per `scoped(…)`); its trace and report are the service's, never this hook's.
|
|
31
|
+
*
|
|
32
|
+
* `initial` is the answer to these same arguments already read — on the server that renders the
|
|
33
|
+
* screen, in a route's loader, by calling the same use case. The reading starts `ready` with it,
|
|
34
|
+
* renders it there, and in the browser keeps it on mount instead of reading again; a change of
|
|
35
|
+
* arguments, a followed write or `reload()` read as always.
|
|
36
|
+
*
|
|
37
|
+
* const portada = useServiceReading(sitio.portada, [], { initial: loaderData.portada });
|
|
31
38
|
*/
|
|
32
39
|
export declare function useServiceReading<A extends unknown[], R>(useCase: UseCase<A, R>, args: A, options?: {
|
|
33
40
|
follows?: readonly Entity[];
|
|
41
|
+
initial?: Awaited<R>;
|
|
34
42
|
}): ServiceReading<Awaited<R>>;
|
|
35
43
|
export {};
|
|
@@ -30,13 +30,24 @@ function routeOf(entity) {
|
|
|
30
30
|
* screen until the new one lands. The last question wins: an answer to arguments no longer on
|
|
31
31
|
* screen is dropped. The use case is the latest the screen gave (a bounded context answers a new
|
|
32
32
|
* function per `scoped(…)`); its trace and report are the service's, never this hook's.
|
|
33
|
+
*
|
|
34
|
+
* `initial` is the answer to these same arguments already read — on the server that renders the
|
|
35
|
+
* screen, in a route's loader, by calling the same use case. The reading starts `ready` with it,
|
|
36
|
+
* renders it there, and in the browser keeps it on mount instead of reading again; a change of
|
|
37
|
+
* arguments, a followed write or `reload()` read as always.
|
|
38
|
+
*
|
|
39
|
+
* const portada = useServiceReading(sitio.portada, [], { initial: loaderData.portada });
|
|
33
40
|
*/
|
|
34
41
|
export function useServiceReading(useCase, args, options = {}) {
|
|
35
42
|
const { context, changes, entities } = useFramework();
|
|
36
43
|
const key = JSON.stringify(args);
|
|
37
44
|
const latest = useRef({ useCase, args });
|
|
38
45
|
latest.current = { useCase, args };
|
|
39
|
-
const [answered, setAnswered] = useState(
|
|
46
|
+
const [answered, setAnswered] = useState(() => options.initial === undefined
|
|
47
|
+
? null
|
|
48
|
+
: { key, status: "ready", answer: options.initial, error: null });
|
|
49
|
+
// Born answered: the first read on mount is the one the server already made.
|
|
50
|
+
const seeded = useRef(options.initial !== undefined);
|
|
40
51
|
const [again, setAgain] = useState(0);
|
|
41
52
|
// A write anyone sends — a save, another use case, a panel beside — to what it follows.
|
|
42
53
|
const followed = (options.follows ?? [])
|
|
@@ -53,6 +64,10 @@ export function useServiceReading(useCase, args, options = {}) {
|
|
|
53
64
|
});
|
|
54
65
|
}, [changes, entities, followed]);
|
|
55
66
|
useEffect(() => {
|
|
67
|
+
if (seeded.current) {
|
|
68
|
+
seeded.current = false;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
56
71
|
let current = true;
|
|
57
72
|
const { useCase: read, args: now } = latest.current;
|
|
58
73
|
// Through the promise: a use case that throws before it answers is a failure like any other.
|
|
@@ -50,7 +50,7 @@ export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>,
|
|
|
50
50
|
record: {
|
|
51
51
|
error?: string | undefined;
|
|
52
52
|
dirty?: import("@sincpro/web-ui").DirtyState | undefined;
|
|
53
|
-
placement: "
|
|
53
|
+
placement: "page" | "card";
|
|
54
54
|
identity: {
|
|
55
55
|
tag?: {
|
|
56
56
|
tone?: import("@sincpro/web-ui").Tone | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.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",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"@opentelemetry/sdk-trace": "^3.1.0",
|
|
42
42
|
"@sentry/browser": "^11.11.0",
|
|
43
43
|
"@sincpro/client-framework": "^2.2.0",
|
|
44
|
-
"@sincpro/criteria": "^2.
|
|
45
|
-
"@sincpro/criteria-react": "^2.
|
|
44
|
+
"@sincpro/criteria": "^2.3.0",
|
|
45
|
+
"@sincpro/criteria-react": "^2.3.0",
|
|
46
46
|
"@sincpro/web-composer": "^1.7.0",
|
|
47
47
|
"@sincpro/web-ui": "^2.5.0",
|
|
48
48
|
"react": ">=19",
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
"@opentelemetry/sdk-trace": "3.1.0",
|
|
74
74
|
"@sentry/browser": "11.11.0",
|
|
75
75
|
"@sincpro/client-framework": "^2.2.0",
|
|
76
|
-
"@sincpro/criteria": "^2.
|
|
77
|
-
"@sincpro/criteria-react": "^2.
|
|
76
|
+
"@sincpro/criteria": "^2.3.0",
|
|
77
|
+
"@sincpro/criteria-react": "^2.3.0",
|
|
78
78
|
"@sincpro/web-composer": "^1.8.0",
|
|
79
79
|
"@sincpro/web-ui": "^2.5.0",
|
|
80
80
|
"@storybook/addon-a11y": "10.6.5",
|