@sincpro/web-framework 3.18.0 → 3.20.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 +83 -54
- package/dist/core/copy.d.ts +14 -0
- package/dist/core/copy.js +57 -2
- package/dist/core/edit.d.ts +13 -0
- package/dist/core/edit.js +14 -0
- package/dist/core/explain.d.ts +4 -0
- package/dist/core/explain.js +4 -0
- package/dist/core/export.d.ts +29 -0
- package/dist/core/export.js +47 -0
- package/dist/core/groups.d.ts +3 -1
- package/dist/core/groups.js +7 -0
- package/dist/core/index.d.ts +4 -3
- package/dist/core/index.js +4 -3
- package/dist/core/lines.d.ts +10 -0
- package/dist/core/lines.js +24 -0
- package/dist/core/list.d.ts +12 -0
- package/dist/react/context.d.ts +44 -1
- package/dist/react/context.js +50 -1
- package/dist/react/index.d.ts +4 -2
- package/dist/react/index.js +4 -2
- package/dist/react/useCounts.d.ts +23 -0
- package/dist/react/useCounts.js +43 -0
- package/dist/react/useGroups.js +38 -5
- package/dist/react/useNameOf.d.ts +13 -0
- package/dist/react/useNameOf.js +32 -0
- package/dist/react/usePeopleOf.d.ts +14 -0
- package/dist/react/usePeopleOf.js +35 -0
- package/dist/react/useRecord.js +2 -2
- package/dist/react/useServiceReading.d.ts +8 -0
- package/dist/react/useServiceReading.js +12 -2
- package/dist/web/index.d.ts +4 -2
- package/dist/web/index.js +4 -2
- package/dist/web/list/EntityList.d.ts +36 -177
- package/dist/web/list/EntityList.js +175 -536
- package/dist/web/list/entityList/choosing.d.ts +50 -0
- package/dist/web/list/entityList/choosing.js +77 -0
- package/dist/web/list/entityList/faces.d.ts +53 -0
- package/dist/web/list/entityList/faces.js +155 -0
- package/dist/web/list/entityList/grouping.d.ts +50 -0
- package/dist/web/list/entityList/grouping.js +97 -0
- package/dist/web/list/entityList/opening.d.ts +68 -0
- package/dist/web/list/entityList/opening.js +149 -0
- package/dist/web/list/entityList/paging.d.ts +30 -0
- package/dist/web/list/entityList/paging.js +39 -0
- package/dist/web/list/entityList/props.d.ts +174 -0
- package/dist/web/list/entityList/props.js +16 -0
- package/dist/web/list/entityList/rowActions.d.ts +31 -0
- package/dist/web/list/entityList/rowActions.js +40 -0
- package/dist/web/list/export.d.ts +13 -0
- package/dist/web/list/export.js +61 -0
- package/dist/web/list/groups.d.ts +16 -0
- package/dist/web/list/groups.js +39 -0
- package/dist/web/list/useEntityList.d.ts +183 -0
- package/dist/web/list/useEntityList.js +225 -0
- package/dist/web/parts.d.ts +42 -0
- package/dist/web/parts.js +88 -0
- package/dist/web/record/lines.d.ts +3 -0
- package/dist/web/record/lines.js +75 -9
- package/dist/web/workspace/RecordScreen.d.ts +206 -0
- package/dist/web/workspace/RecordScreen.js +251 -0
- package/dist/web/workspace/SincproApp.d.ts +14 -2
- package/dist/web/workspace/SincproApp.js +27 -9
- package/dist/web/workspace/composer.js +1 -1
- package/dist/web/workspace/record.d.ts +21 -27
- package/dist/web/workspace/record.js +29 -77
- package/dist/web/workspace/workspace.d.ts +2 -0
- package/dist/web/workspace/workspace.js +1 -1
- package/package.json +7 -7
package/dist/core/lines.js
CHANGED
|
@@ -113,6 +113,30 @@ export function writtenInCell(definition, field, declared) {
|
|
|
113
113
|
return !relation.many && declared(relation.target);
|
|
114
114
|
return CELL_TYPES.has(definition.fields[field]?.type ?? "");
|
|
115
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* The many2one «Add several…» fills — one new line per record chosen —: the one the screen names
|
|
118
|
+
* (`asked`), else the line's ONLY to-one relation a person writes whose entity the application
|
|
119
|
+
* declared (a product). `false` from the screen, or none or several to choose from: none — two
|
|
120
|
+
* candidates are a question only the screen can answer.
|
|
121
|
+
*
|
|
122
|
+
* addManyOf(lineMeta, declared) // "product_code"
|
|
123
|
+
* addManyOf(lineMeta, declared, "warehouse_id") // the screen's
|
|
124
|
+
*/
|
|
125
|
+
export function addManyOf(definition, declared, asked) {
|
|
126
|
+
if (definition === null || asked === false)
|
|
127
|
+
return undefined;
|
|
128
|
+
const candidates = lineFields(definition).filter((field) => {
|
|
129
|
+
const relation = relationFieldOf(definition, field);
|
|
130
|
+
return (relation !== undefined &&
|
|
131
|
+
!relation.many &&
|
|
132
|
+
relation.key === field &&
|
|
133
|
+
definition.fields[field]?.readonly !== true &&
|
|
134
|
+
declared(relation.target));
|
|
135
|
+
});
|
|
136
|
+
if (asked !== undefined)
|
|
137
|
+
return candidates.includes(asked) ? asked : undefined;
|
|
138
|
+
return candidates.length === 1 ? candidates[0] : undefined;
|
|
139
|
+
}
|
|
116
140
|
/**
|
|
117
141
|
* How «Agregar una línea» adds: in the table when every column a person may write fits a cell
|
|
118
142
|
* and nothing required is left out of the columns; in the dialog otherwise — a row that cannot
|
package/dist/core/list.d.ts
CHANGED
|
@@ -59,6 +59,18 @@ export type ListDefinition<T extends AnyRecord = AnyRecord> = {
|
|
|
59
59
|
views?: readonly ("table" | "rows" | "board" | "tiles" | "sheet" | "pivot")[];
|
|
60
60
|
/** Grouped from the start — the server counts the groups. */
|
|
61
61
|
groupBy?: readonly GroupLevel[];
|
|
62
|
+
/**
|
|
63
|
+
* How many groups of `groupBy`'s first level start open — each reading ONE page of what it
|
|
64
|
+
* holds, so the ceiling stays. Without it every group starts closed: right for a million rows,
|
|
65
|
+
* wrong for a directory of six bodies.
|
|
66
|
+
*/
|
|
67
|
+
open?: number;
|
|
68
|
+
/**
|
|
69
|
+
* The order the groups come in (criteria's `grouping.order`): by a level's field, by a figure
|
|
70
|
+
* the list adds up, or by `count`. A sort that names none of them for a level is left out of
|
|
71
|
+
* that level's question — the server would refuse it. Without it, by the group's value.
|
|
72
|
+
*/
|
|
73
|
+
groupOrder?: readonly Sort<T>[];
|
|
62
74
|
/** The fields «Group by» offers, in this order — among those the model lets split the set. */
|
|
63
75
|
groupable?: readonly string[];
|
|
64
76
|
/** The entity's trash (`trashOf`): each row offers «Restore» when the entity declares it. */
|
package/dist/react/context.d.ts
CHANGED
|
@@ -58,8 +58,12 @@ type FrameworkContextValue = {
|
|
|
58
58
|
richText: RichTextSettings;
|
|
59
59
|
/** Where a file a person gives goes — the application's (`FrameworkProvider uploads`). */
|
|
60
60
|
uploads: Uploads | undefined;
|
|
61
|
+
/** Who is who — the application's (`FrameworkProvider people`). */
|
|
62
|
+
people: People | undefined;
|
|
61
63
|
};
|
|
62
|
-
|
|
64
|
+
/** Who is who: usernames → the names a person reads, for every username asked at once. */
|
|
65
|
+
export type People = (who: readonly string[]) => Promise<Readonly<Record<string, string>>>;
|
|
66
|
+
export declare function FrameworkProvider({ transport, locale, metas: seed, entities, timeZone, dateStyle, currency, region, events, richText, uploads, people, changes, children, }: {
|
|
63
67
|
transport: Transport;
|
|
64
68
|
/** The language labels and values are read in (`"es"`); the model's `default` without it. */
|
|
65
69
|
locale?: string;
|
|
@@ -95,6 +99,13 @@ export declare function FrameworkProvider({ transport, locale, metas: seed, enti
|
|
|
95
99
|
* rich text takes no pictures.
|
|
96
100
|
*/
|
|
97
101
|
uploads?: Uploads;
|
|
102
|
+
/**
|
|
103
|
+
* Who is who: the names of the people a record's history and authorship name by username
|
|
104
|
+
* («jperez» → «Juana Pérez»). The application's use case answers them — the accounts are its
|
|
105
|
+
* bounded context's —, asked once for every username a screen shows. Without it, the
|
|
106
|
+
* usernames are shown.
|
|
107
|
+
*/
|
|
108
|
+
people?: People;
|
|
98
109
|
/** Where writes are announced — the process's (`processChanges`) unless a test gives another. */
|
|
99
110
|
changes?: ChangeFeed;
|
|
100
111
|
children: ReactNode;
|
|
@@ -105,4 +116,36 @@ export declare function useFramework(): FrameworkContextValue;
|
|
|
105
116
|
export declare function useFrameworkIfAny(): FrameworkContextValue | null;
|
|
106
117
|
/** The declared entity a relation points at (`"Cliente"`), or `undefined`. */
|
|
107
118
|
export declare function useEntityFor(target: string | undefined): Entity | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* The models one part of the application brings — a face, a lazily loaded bounded context —:
|
|
121
|
+
* their entities, their definitions and their facts, added to the provider's for the screens
|
|
122
|
+
* under it.
|
|
123
|
+
*
|
|
124
|
+
* <FrameworkProvider transport={transport}> ← the public site: none
|
|
125
|
+
* <ModelDefinitions metas={metasOf(billing)} events={eventMetasOf(billing)}>
|
|
126
|
+
* <Backoffice /> ← loads them with its code
|
|
127
|
+
* </ModelDefinitions>
|
|
128
|
+
* </FrameworkProvider>
|
|
129
|
+
*
|
|
130
|
+
* Context: the definitions were the provider's only, so an application that serves a public site
|
|
131
|
+
* and a backoffice from one provider shipped every model to every page (quipu: 1.1 MB on its home
|
|
132
|
+
* page, read by nobody there). Brought here, they travel with the code that needs them.
|
|
133
|
+
*
|
|
134
|
+
* `metas` go into the process's one store — what the provider learned from the server is never
|
|
135
|
+
* replaced by a snapshot written at build time —, so once a face brought them every screen knows
|
|
136
|
+
* them, as if the server had sent them. `entities` (what a relation is resolved to) and `events`
|
|
137
|
+
* (the facts of a history) are added over the provider's for the screens under this one only.
|
|
138
|
+
*/
|
|
139
|
+
export declare function ModelDefinitions({ entities, metas, events, people, children, }: {
|
|
140
|
+
/** Its entities: a relation of one of its models is drawn with them. */
|
|
141
|
+
entities?: readonly Entity[] | undefined;
|
|
142
|
+
/** Each entity's model by its key (`metasOf(contract)`): drawn with no request for it. */
|
|
143
|
+
metas?: Readonly<Record<string, Meta>> | undefined;
|
|
144
|
+
/** Each domain event's definition by its name (`eventMetasOf(contract)`). */
|
|
145
|
+
events?: Readonly<Record<string, Meta>> | undefined;
|
|
146
|
+
/** Who is who on this face's screens (`FrameworkProvider people`), when the face names its
|
|
147
|
+
* people and the provider around it does not. */
|
|
148
|
+
people?: People | undefined;
|
|
149
|
+
children?: ReactNode;
|
|
150
|
+
}): import("react").JSX.Element;
|
|
108
151
|
export {};
|
package/dist/react/context.js
CHANGED
|
@@ -7,7 +7,7 @@ import { entityFor } from "../core/relation.js";
|
|
|
7
7
|
import { useContextValues } from "./useContextValues.js";
|
|
8
8
|
import { createContext, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
9
9
|
const FrameworkContext = createContext(null);
|
|
10
|
-
export function FrameworkProvider({ transport, locale, metas: seed, entities = NO_ENTITIES, timeZone, dateStyle = "numeric", currency, region, events = NO_EVENTS, richText = NO_RICH_TEXT, uploads, changes = processChanges, children, }) {
|
|
10
|
+
export function FrameworkProvider({ transport, locale, metas: seed, entities = NO_ENTITIES, timeZone, dateStyle = "numeric", currency, region, events = NO_EVENTS, richText = NO_RICH_TEXT, uploads, people, changes = processChanges, children, }) {
|
|
11
11
|
// Installed before the children draw, and again when it changes (another company): the
|
|
12
12
|
// formatters read it, so it cannot wait for an effect.
|
|
13
13
|
const zoned = useRef(null);
|
|
@@ -72,6 +72,7 @@ export function FrameworkProvider({ transport, locale, metas: seed, entities = N
|
|
|
72
72
|
events,
|
|
73
73
|
richText,
|
|
74
74
|
uploads,
|
|
75
|
+
people,
|
|
75
76
|
}), [
|
|
76
77
|
screens,
|
|
77
78
|
locale,
|
|
@@ -86,6 +87,7 @@ export function FrameworkProvider({ transport, locale, metas: seed, entities = N
|
|
|
86
87
|
events,
|
|
87
88
|
richText,
|
|
88
89
|
uploads,
|
|
90
|
+
people,
|
|
89
91
|
]);
|
|
90
92
|
return _jsx(FrameworkContext.Provider, { value: value, children: children });
|
|
91
93
|
}
|
|
@@ -108,3 +110,50 @@ export function useEntityFor(target) {
|
|
|
108
110
|
const { entities, metas } = useFramework();
|
|
109
111
|
return target === undefined ? undefined : entityFor(entities, target, metas.get);
|
|
110
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* The models one part of the application brings — a face, a lazily loaded bounded context —:
|
|
115
|
+
* their entities, their definitions and their facts, added to the provider's for the screens
|
|
116
|
+
* under it.
|
|
117
|
+
*
|
|
118
|
+
* <FrameworkProvider transport={transport}> ← the public site: none
|
|
119
|
+
* <ModelDefinitions metas={metasOf(billing)} events={eventMetasOf(billing)}>
|
|
120
|
+
* <Backoffice /> ← loads them with its code
|
|
121
|
+
* </ModelDefinitions>
|
|
122
|
+
* </FrameworkProvider>
|
|
123
|
+
*
|
|
124
|
+
* Context: the definitions were the provider's only, so an application that serves a public site
|
|
125
|
+
* and a backoffice from one provider shipped every model to every page (quipu: 1.1 MB on its home
|
|
126
|
+
* page, read by nobody there). Brought here, they travel with the code that needs them.
|
|
127
|
+
*
|
|
128
|
+
* `metas` go into the process's one store — what the provider learned from the server is never
|
|
129
|
+
* replaced by a snapshot written at build time —, so once a face brought them every screen knows
|
|
130
|
+
* them, as if the server had sent them. `entities` (what a relation is resolved to) and `events`
|
|
131
|
+
* (the facts of a history) are added over the provider's for the screens under this one only.
|
|
132
|
+
*/
|
|
133
|
+
export function ModelDefinitions({ entities, metas, events, people, children, }) {
|
|
134
|
+
const above = useFramework();
|
|
135
|
+
// Added while rendering, before the screens under it render: they read the store as they draw.
|
|
136
|
+
const brought = useRef(undefined);
|
|
137
|
+
if (metas !== undefined && brought.current !== metas) {
|
|
138
|
+
for (const [key, meta] of Object.entries(metas))
|
|
139
|
+
if (above.metas.get(key) === undefined)
|
|
140
|
+
above.metas.set(key, meta);
|
|
141
|
+
brought.current = metas;
|
|
142
|
+
}
|
|
143
|
+
const value = useMemo(() => entities === undefined && events === undefined && people === undefined
|
|
144
|
+
? above
|
|
145
|
+
: {
|
|
146
|
+
...above,
|
|
147
|
+
...(entities === undefined
|
|
148
|
+
? {}
|
|
149
|
+
: {
|
|
150
|
+
entities: [
|
|
151
|
+
...above.entities,
|
|
152
|
+
...entities.filter((one) => !above.entities.includes(one)),
|
|
153
|
+
],
|
|
154
|
+
}),
|
|
155
|
+
...(events === undefined ? {} : { events: { ...above.events, ...events } }),
|
|
156
|
+
...(people === undefined ? {} : { people }),
|
|
157
|
+
}, [above, entities, events, people]);
|
|
158
|
+
return _jsx(FrameworkContext.Provider, { value: value, children: children });
|
|
159
|
+
}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -3,17 +3,19 @@
|
|
|
3
3
|
* DOM, no design system — so a screen can drop `EntityList` and still keep it. `make doctor`
|
|
4
4
|
* keeps it that way.
|
|
5
5
|
*/
|
|
6
|
-
export { FrameworkProvider, useEntityFor, useFramework, } from "./context.js";
|
|
6
|
+
export { FrameworkProvider, ModelDefinitions, type People, useEntityFor, useFramework, } from "./context.js";
|
|
7
7
|
export { type ListScope, ListScopeProvider, useListScope, } from "./scope.js";
|
|
8
8
|
export { BATCH_LIMIT, type BatchCommandState, useBatchCommand, } from "./useBatchCommand.js";
|
|
9
9
|
export { type AnswerOf, type CommandState, type Rehearsal, useCommand, useRouteCommand, } from "./useCommand.js";
|
|
10
10
|
export { useContextValues } from "./useContextValues.js";
|
|
11
11
|
export { useCount } from "./useCount.js";
|
|
12
|
+
export { type CountAsked, useCounts } from "./useCounts.js";
|
|
12
13
|
export { type Groups, useGroups } from "./useGroups.js";
|
|
13
14
|
export { useHistory } from "./useHistory.js";
|
|
14
15
|
export { type Listing, type ListingOptions, type Paging, useListing, } from "./useListing.js";
|
|
15
16
|
export { excluding, type Lookup, useLookup } from "./useLookup.js";
|
|
16
|
-
export { useNameOf } from "./useNameOf.js";
|
|
17
|
+
export { useNameOf, useNamesOf } from "./useNameOf.js";
|
|
18
|
+
export { usePeopleOf } from "./usePeopleOf.js";
|
|
17
19
|
export { type PivotAxes, type PivotReading, usePivot, } from "./usePivot.js";
|
|
18
20
|
export { type Editing, type RecordReading, type RecordState, useRecord, } from "./useRecord.js";
|
|
19
21
|
export { type LifecycleAction, type RecordLifecycleActions, useRecordLifecycle, } from "./useRecordLifecycle.js";
|
package/dist/react/index.js
CHANGED
|
@@ -3,17 +3,19 @@
|
|
|
3
3
|
* DOM, no design system — so a screen can drop `EntityList` and still keep it. `make doctor`
|
|
4
4
|
* keeps it that way.
|
|
5
5
|
*/
|
|
6
|
-
export { FrameworkProvider, useEntityFor, useFramework, } from "./context.js";
|
|
6
|
+
export { FrameworkProvider, ModelDefinitions, useEntityFor, useFramework, } from "./context.js";
|
|
7
7
|
export { ListScopeProvider, useListScope, } from "./scope.js";
|
|
8
8
|
export { BATCH_LIMIT, useBatchCommand, } from "./useBatchCommand.js";
|
|
9
9
|
export { useCommand, useRouteCommand, } from "./useCommand.js";
|
|
10
10
|
export { useContextValues } from "./useContextValues.js";
|
|
11
11
|
export { useCount } from "./useCount.js";
|
|
12
|
+
export { useCounts } from "./useCounts.js";
|
|
12
13
|
export { useGroups } from "./useGroups.js";
|
|
13
14
|
export { useHistory } from "./useHistory.js";
|
|
14
15
|
export { useListing, } from "./useListing.js";
|
|
15
16
|
export { excluding, useLookup } from "./useLookup.js";
|
|
16
|
-
export { useNameOf } from "./useNameOf.js";
|
|
17
|
+
export { useNameOf, useNamesOf } from "./useNameOf.js";
|
|
18
|
+
export { usePeopleOf } from "./usePeopleOf.js";
|
|
17
19
|
export { usePivot, } from "./usePivot.js";
|
|
18
20
|
export { useRecord, } from "./useRecord.js";
|
|
19
21
|
export { useRecordLifecycle, } from "./useRecordLifecycle.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Entity } from "@sincpro/client-framework";
|
|
2
|
+
import type { Expression } from "@sincpro/criteria";
|
|
3
|
+
/** One question to count: the records of `entity` that `where` keeps. */
|
|
4
|
+
export type CountAsked = {
|
|
5
|
+
entity: Entity;
|
|
6
|
+
where: Expression;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* How many records each question keeps, asked together — a record's smart buttons («Sus pagos 4»,
|
|
10
|
+
* «Cuotas pendientes 2»), as many as the record has. `null` while it is asked, or when the server
|
|
11
|
+
* did not answer one.
|
|
12
|
+
*
|
|
13
|
+
* const [pagos, cuotas] = useCounts([
|
|
14
|
+
* { entity: pagos, where: { field: "colegiado_id", operator: "=", value: id } },
|
|
15
|
+
* { entity: cuotas, where: pendientesDe(id) },
|
|
16
|
+
* ]);
|
|
17
|
+
*
|
|
18
|
+
* Context: `useCount` is a listing of one, so a screen counted one question per hook — and a
|
|
19
|
+
* record's links, whose number and questions depend on the record, ended as hooks an application
|
|
20
|
+
* passed as data (`useEnlaces`). The questions here are data, read again when they or the
|
|
21
|
+
* process's context change.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useCounts(asked: readonly CountAsked[]): readonly (number | null)[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { listRoute } from "@sincpro/client-framework";
|
|
3
|
+
import { useFramework } from "./context.js";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
/**
|
|
6
|
+
* How many records each question keeps, asked together — a record's smart buttons («Sus pagos 4»,
|
|
7
|
+
* «Cuotas pendientes 2»), as many as the record has. `null` while it is asked, or when the server
|
|
8
|
+
* did not answer one.
|
|
9
|
+
*
|
|
10
|
+
* const [pagos, cuotas] = useCounts([
|
|
11
|
+
* { entity: pagos, where: { field: "colegiado_id", operator: "=", value: id } },
|
|
12
|
+
* { entity: cuotas, where: pendientesDe(id) },
|
|
13
|
+
* ]);
|
|
14
|
+
*
|
|
15
|
+
* Context: `useCount` is a listing of one, so a screen counted one question per hook — and a
|
|
16
|
+
* record's links, whose number and questions depend on the record, ended as hooks an application
|
|
17
|
+
* passed as data (`useEnlaces`). The questions here are data, read again when they or the
|
|
18
|
+
* process's context change.
|
|
19
|
+
*/
|
|
20
|
+
export function useCounts(asked) {
|
|
21
|
+
const { transport, context } = useFramework();
|
|
22
|
+
// The questions by their content: a new array of the same questions asks nothing again.
|
|
23
|
+
const key = JSON.stringify(asked.map((one) => [listRoute(one.entity.list), one.where]));
|
|
24
|
+
const [counted, setCounted] = useState();
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const questions = JSON.parse(key);
|
|
27
|
+
if (questions.length === 0)
|
|
28
|
+
return;
|
|
29
|
+
let current = true;
|
|
30
|
+
void Promise.all(questions.map(([route, where]) => transport
|
|
31
|
+
.list(route, {
|
|
32
|
+
selection: where,
|
|
33
|
+
count: "exact",
|
|
34
|
+
pagination: { limit: 1 },
|
|
35
|
+
})
|
|
36
|
+
.then((page) => page.count?.value ?? null, () => null))).then((values) => {
|
|
37
|
+
if (current)
|
|
38
|
+
setCounted({ key, values });
|
|
39
|
+
});
|
|
40
|
+
return () => void (current = false);
|
|
41
|
+
}, [transport, key, context]);
|
|
42
|
+
return counted?.key === key ? counted.values : asked.map(() => null);
|
|
43
|
+
}
|
package/dist/react/useGroups.js
CHANGED
|
@@ -4,7 +4,7 @@ import { areGroups, groupKeyOf, isGroupedAnswer, levelQuestion, nextGroups, NotG
|
|
|
4
4
|
import { measuresOf, sumsOf } from "../core/measure.js";
|
|
5
5
|
import { useFramework } from "./context.js";
|
|
6
6
|
import { useWrites } from "./useWrites.js";
|
|
7
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
7
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
8
8
|
const IDLE = {
|
|
9
9
|
status: "idle",
|
|
10
10
|
buckets: [],
|
|
@@ -29,6 +29,9 @@ export function useGroups(listing, options = {}) {
|
|
|
29
29
|
const [below, setBelow] = useState(new Map());
|
|
30
30
|
const [rows, setRows] = useState(new Map());
|
|
31
31
|
const [opened, setOpened] = useState(new Set());
|
|
32
|
+
// The order of the groups and how many start open are the named list's (`defineList`).
|
|
33
|
+
const groupOrder = listing.definition?.groupOrder;
|
|
34
|
+
const ordered = useMemo(() => (groupOrder === undefined ? {} : { order: groupOrder }), [groupOrder]);
|
|
32
35
|
const pageSize = options.pageSize ?? 50;
|
|
33
36
|
const groupPageSize = options.groupPageSize ?? 80;
|
|
34
37
|
const maxRows = options.maxRows ?? 500;
|
|
@@ -158,7 +161,7 @@ export function useGroups(listing, options = {}) {
|
|
|
158
161
|
const limit = mode === "again" ? Math.max(groupPageSize, had?.buckets.length ?? 0) : groupPageSize;
|
|
159
162
|
const offset = mode === "more" ? (had?.buckets.length ?? 0) : 0;
|
|
160
163
|
const measures = measuresNow();
|
|
161
|
-
const criteria = levelQuestion(bucket.criteria, level, { limit, offset }, measures === undefined ? {} : { measures });
|
|
164
|
+
const criteria = levelQuestion(bucket.criteria, level, { limit, offset }, { ...ordered, ...(measures === undefined ? {} : { measures }) });
|
|
162
165
|
setBelow((map) => new Map(map).set(key, {
|
|
163
166
|
...(had ?? { path, buckets: [], count: null }),
|
|
164
167
|
reading: true,
|
|
@@ -199,7 +202,7 @@ export function useGroups(listing, options = {}) {
|
|
|
199
202
|
error,
|
|
200
203
|
}));
|
|
201
204
|
});
|
|
202
|
-
}, [transport, route, groupPageSize]);
|
|
205
|
+
}, [transport, route, groupPageSize, ordered]);
|
|
203
206
|
arrived.current = (buckets, above) => {
|
|
204
207
|
const deepest = above.length === now.current.levels.length - 1;
|
|
205
208
|
const closed = [];
|
|
@@ -218,6 +221,35 @@ export function useGroups(listing, options = {}) {
|
|
|
218
221
|
setBelow((map) => closed.reduce((kept, path) => without(kept, path), map));
|
|
219
222
|
setRows((map) => closed.reduce((kept, path) => without(kept, path), map));
|
|
220
223
|
};
|
|
224
|
+
/**
|
|
225
|
+
* The named list's grouping opens its first `open` groups once — the first time it arrives.
|
|
226
|
+
* After that what is open is the person's: a search keeps it, and closing one stays closed.
|
|
227
|
+
*/
|
|
228
|
+
const startedOpen = useRef(null);
|
|
229
|
+
const startOpen = (buckets) => {
|
|
230
|
+
const definition = listing.definition;
|
|
231
|
+
const count = definition?.open ?? 0;
|
|
232
|
+
const asked = JSON.stringify(now.current.levels);
|
|
233
|
+
if (count <= 0 || startedOpen.current === asked)
|
|
234
|
+
return;
|
|
235
|
+
if (asked !== JSON.stringify(definition?.groupBy ?? []))
|
|
236
|
+
return;
|
|
237
|
+
startedOpen.current = asked;
|
|
238
|
+
const deepest = now.current.levels.length === 1;
|
|
239
|
+
const first = buckets.slice(0, count);
|
|
240
|
+
setOpened((was) => {
|
|
241
|
+
const next = new Set(was);
|
|
242
|
+
for (const bucket of first)
|
|
243
|
+
next.add(keyOf(pathOf(bucket)));
|
|
244
|
+
return next;
|
|
245
|
+
});
|
|
246
|
+
for (const bucket of first) {
|
|
247
|
+
if (deepest)
|
|
248
|
+
readRows(bucket, pathOf(bucket), "first");
|
|
249
|
+
else
|
|
250
|
+
readLevel(bucket, pathOf(bucket), "first");
|
|
251
|
+
}
|
|
252
|
+
};
|
|
221
253
|
// Another split starts closed; the same split under another question keeps what is open.
|
|
222
254
|
const split = JSON.stringify(levels);
|
|
223
255
|
const shownSplit = useRef(split);
|
|
@@ -248,7 +280,7 @@ export function useGroups(listing, options = {}) {
|
|
|
248
280
|
// As many groups as were on screen: a search does not undo the person's «more groups».
|
|
249
281
|
const shown = fresh ? 0 : now.current.root.buckets.length;
|
|
250
282
|
const measures = measuresNow();
|
|
251
|
-
const criteria = levelQuestion(JSON.parse(question), first, { limit: Math.max(groupPageSize, shown) }, { counted: true, ...(measures === undefined ? {} : { measures }) });
|
|
283
|
+
const criteria = levelQuestion(JSON.parse(question), first, { limit: Math.max(groupPageSize, shown) }, { ...ordered, counted: true, ...(measures === undefined ? {} : { measures }) });
|
|
252
284
|
transport.list(route, criteria, aborter.signal).then((page) => {
|
|
253
285
|
if (generation.current.id !== id)
|
|
254
286
|
return;
|
|
@@ -267,6 +299,7 @@ export function useGroups(listing, options = {}) {
|
|
|
267
299
|
records: page.count?.value ?? null,
|
|
268
300
|
});
|
|
269
301
|
arrived.current(buckets, []);
|
|
302
|
+
startOpen(buckets);
|
|
270
303
|
}, (error) => {
|
|
271
304
|
if (generation.current.id === id)
|
|
272
305
|
setRoot({ ...IDLE, status: "failed", error });
|
|
@@ -286,7 +319,7 @@ export function useGroups(listing, options = {}) {
|
|
|
286
319
|
inFlight.current.add(tag);
|
|
287
320
|
const { id, signal } = generation.current;
|
|
288
321
|
const measures = measuresNow();
|
|
289
|
-
const criteria = levelQuestion(JSON.parse(question), first, { limit: groupPageSize, offset: root.buckets.length }, measures === undefined ? {} : { measures });
|
|
322
|
+
const criteria = levelQuestion(JSON.parse(question), first, { limit: groupPageSize, offset: root.buckets.length }, { ...ordered, ...(measures === undefined ? {} : { measures }) });
|
|
290
323
|
setRoot((was) => ({ ...was, status: "loading" }));
|
|
291
324
|
transport.list(route, criteria, signal).then((page) => {
|
|
292
325
|
inFlight.current.delete(tag);
|
|
@@ -12,3 +12,16 @@ import { type Entity } from "@sincpro/client-framework";
|
|
|
12
12
|
* const name = useNameOf(tenants, record.tenant_id) ?? record.tenant_id;
|
|
13
13
|
*/
|
|
14
14
|
export declare function useNameOf(entity: Entity | undefined, id: string): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* The names of several records by key, each of the aggregate it names (`target`) — a grouping's
|
|
17
|
+
* heads, where the number of keys is the page's. Asked through the same book as `useNameOf`: one
|
|
18
|
+
* request per entity for the keys of the moment, a name already known shared. A key of an
|
|
19
|
+
* aggregate the application declared no entity for stays unnamed.
|
|
20
|
+
*
|
|
21
|
+
* const nameOf = useNamesOf([{ target: "directorio.Organo", id: "CONSEJO_TECNICO" }]);
|
|
22
|
+
* nameOf("directorio.Organo", "CONSEJO_TECNICO") // "Consejo Técnico", once it answers
|
|
23
|
+
*/
|
|
24
|
+
export declare function useNamesOf(asked: readonly {
|
|
25
|
+
target: string;
|
|
26
|
+
id: string;
|
|
27
|
+
}[]): (target: string, id: string) => string | undefined;
|
package/dist/react/useNameOf.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { listRoute } from "@sincpro/client-framework";
|
|
3
|
+
import { entityFor } from "../core/relation.js";
|
|
3
4
|
import { useFramework } from "./context.js";
|
|
4
5
|
import { useWrites } from "./useWrites.js";
|
|
5
6
|
import { useEffect, useState } from "react";
|
|
@@ -32,6 +33,37 @@ export function useNameOf(entity, id) {
|
|
|
32
33
|
}, [names, entity, id, context, writes]);
|
|
33
34
|
return named?.id === id ? named.name : undefined;
|
|
34
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* The names of several records by key, each of the aggregate it names (`target`) — a grouping's
|
|
38
|
+
* heads, where the number of keys is the page's. Asked through the same book as `useNameOf`: one
|
|
39
|
+
* request per entity for the keys of the moment, a name already known shared. A key of an
|
|
40
|
+
* aggregate the application declared no entity for stays unnamed.
|
|
41
|
+
*
|
|
42
|
+
* const nameOf = useNamesOf([{ target: "directorio.Organo", id: "CONSEJO_TECNICO" }]);
|
|
43
|
+
* nameOf("directorio.Organo", "CONSEJO_TECNICO") // "Consejo Técnico", once it answers
|
|
44
|
+
*/
|
|
45
|
+
export function useNamesOf(asked) {
|
|
46
|
+
const { names, context, entities, metas } = useFramework();
|
|
47
|
+
const [named, setNamed] = useState(new Map());
|
|
48
|
+
// The keys by their content: a new array of the same keys asks nothing again.
|
|
49
|
+
const question = JSON.stringify(asked.map(({ target, id }) => [target, id]));
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
let current = true;
|
|
52
|
+
for (const [target, id] of JSON.parse(question)) {
|
|
53
|
+
const entity = entityFor(entities, target, metas.get);
|
|
54
|
+
if (entity === undefined || id === "")
|
|
55
|
+
continue;
|
|
56
|
+
void names.nameOf(entity, id).then((name) => {
|
|
57
|
+
if (current && name !== undefined)
|
|
58
|
+
setNamed((was) => new Map(was).set(nameKey(target, id), name));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return () => void (current = false);
|
|
62
|
+
// `context` asks again: another company names its records its own way.
|
|
63
|
+
}, [names, question, context, entities, metas]);
|
|
64
|
+
return (target, id) => named.get(nameKey(target, id));
|
|
65
|
+
}
|
|
66
|
+
const nameKey = (target, id) => `${target}\u0000${id}`;
|
|
35
67
|
/** Where `entity` is listed — or nothing to follow when it is listed only under a record. */
|
|
36
68
|
function routeOf(entity) {
|
|
37
69
|
try {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The name of each person among `who`, by the application's port (`FrameworkProvider people`):
|
|
3
|
+
* every username asked at once, and asked again only when the set changes. A username nobody
|
|
4
|
+
* names — or every one, without the port — reads as itself.
|
|
5
|
+
*
|
|
6
|
+
* const nameOf = usePeopleOf(history.map((one) => one.by));
|
|
7
|
+
* nameOf("jperez") // "Juana Pérez", once the port answers
|
|
8
|
+
*
|
|
9
|
+
* Context: a record's history and authorship say who by username — the fact's `actor` —, and an
|
|
10
|
+
* application showed «jperez» or wrote its own hook to rename them on every screen (quipu's
|
|
11
|
+
* `usePorNombre`). Who is who is the application's to answer (its accounts are a bounded context
|
|
12
|
+
* of their own); asking it, once per screen, is the framework's.
|
|
13
|
+
*/
|
|
14
|
+
export declare function usePeopleOf(who: readonly (string | null | undefined)[]): (who: string) => string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useFramework } from "./context.js";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* The name of each person among `who`, by the application's port (`FrameworkProvider people`):
|
|
6
|
+
* every username asked at once, and asked again only when the set changes. A username nobody
|
|
7
|
+
* names — or every one, without the port — reads as itself.
|
|
8
|
+
*
|
|
9
|
+
* const nameOf = usePeopleOf(history.map((one) => one.by));
|
|
10
|
+
* nameOf("jperez") // "Juana Pérez", once the port answers
|
|
11
|
+
*
|
|
12
|
+
* Context: a record's history and authorship say who by username — the fact's `actor` —, and an
|
|
13
|
+
* application showed «jperez» or wrote its own hook to rename them on every screen (quipu's
|
|
14
|
+
* `usePorNombre`). Who is who is the application's to answer (its accounts are a bounded context
|
|
15
|
+
* of their own); asking it, once per screen, is the framework's.
|
|
16
|
+
*/
|
|
17
|
+
export function usePeopleOf(who) {
|
|
18
|
+
const { people, context } = useFramework();
|
|
19
|
+
const [named, setNamed] = useState({});
|
|
20
|
+
// The set as its content: a new array of the same people asks nothing again.
|
|
21
|
+
const asked = [...new Set(who.filter((one) => !!one))].sort().join("\n");
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (people === undefined || asked === "")
|
|
24
|
+
return;
|
|
25
|
+
let current = true;
|
|
26
|
+
void people(asked.split("\n")).then((names) => {
|
|
27
|
+
if (current)
|
|
28
|
+
setNamed(names);
|
|
29
|
+
},
|
|
30
|
+
// Unnamed is no error: the username stays.
|
|
31
|
+
() => undefined);
|
|
32
|
+
return () => void (current = false);
|
|
33
|
+
}, [people, asked, context]);
|
|
34
|
+
return (one) => named[one] ?? one;
|
|
35
|
+
}
|
package/dist/react/useRecord.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { newEntityId, pathFor, retryKeys, startingValuesOf, TransportError, WITH_PARAM, } from "@sincpro/client-framework";
|
|
3
|
-
import { changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, } from "../core/edit.js";
|
|
3
|
+
import { canCreate, changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, } from "../core/edit.js";
|
|
4
4
|
import { linesAnswered } from "../core/lines.js";
|
|
5
5
|
import { useFramework } from "./context.js";
|
|
6
6
|
import { useWrites } from "./useWrites.js";
|
|
@@ -200,7 +200,7 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
200
200
|
// neither — every field of it is read only, whatever the model's hints say: an input nothing
|
|
201
201
|
// can save is an invitation that lies.
|
|
202
202
|
const writable = isNew
|
|
203
|
-
?
|
|
203
|
+
? canCreate(entity, state.meta)
|
|
204
204
|
: (entity.edit ?? entity.save) !== undefined;
|
|
205
205
|
/** The record's key for a write: its own, or the one minted for it while it is new. */
|
|
206
206
|
const keyNow = () => {
|
|
@@ -35,9 +35,17 @@ type UseCase<A extends unknown[], R> = (...args: A) => R | Promise<R>;
|
|
|
35
35
|
* arguments, a followed write or `reload()` read as always.
|
|
36
36
|
*
|
|
37
37
|
* const portada = useServiceReading(sitio.portada, [], { initial: loaderData.portada });
|
|
38
|
+
*
|
|
39
|
+
* `enabled: false` is a reading that cannot ask yet — nobody signed in, a key still unknown: it
|
|
40
|
+
* stays `loading` and asks nothing, and reads as soon as it is enabled. Never answer a pending
|
|
41
|
+
* promise from the use case to hold it back: the reading would wait on a question nobody asked.
|
|
42
|
+
*
|
|
43
|
+
* const perfil = useServiceReading(cuentas.perfil, [usuario], { enabled: usuario !== "" });
|
|
38
44
|
*/
|
|
39
45
|
export declare function useServiceReading<A extends unknown[], R>(useCase: UseCase<A, R>, args: A, options?: {
|
|
40
46
|
follows?: readonly Entity[];
|
|
41
47
|
initial?: Awaited<R>;
|
|
48
|
+
/** `false`: nothing to ask yet — it stays `loading` and asks nothing. `true` by default. */
|
|
49
|
+
enabled?: boolean;
|
|
42
50
|
}): ServiceReading<Awaited<R>>;
|
|
43
51
|
export {};
|
|
@@ -37,6 +37,12 @@ function routeOf(entity) {
|
|
|
37
37
|
* arguments, a followed write or `reload()` read as always.
|
|
38
38
|
*
|
|
39
39
|
* const portada = useServiceReading(sitio.portada, [], { initial: loaderData.portada });
|
|
40
|
+
*
|
|
41
|
+
* `enabled: false` is a reading that cannot ask yet — nobody signed in, a key still unknown: it
|
|
42
|
+
* stays `loading` and asks nothing, and reads as soon as it is enabled. Never answer a pending
|
|
43
|
+
* promise from the use case to hold it back: the reading would wait on a question nobody asked.
|
|
44
|
+
*
|
|
45
|
+
* const perfil = useServiceReading(cuentas.perfil, [usuario], { enabled: usuario !== "" });
|
|
40
46
|
*/
|
|
41
47
|
export function useServiceReading(useCase, args, options = {}) {
|
|
42
48
|
const { context, changes, entities } = useFramework();
|
|
@@ -49,6 +55,7 @@ export function useServiceReading(useCase, args, options = {}) {
|
|
|
49
55
|
// Born answered: the first read on mount is the one the server already made.
|
|
50
56
|
const seeded = useRef(options.initial !== undefined);
|
|
51
57
|
const [again, setAgain] = useState(0);
|
|
58
|
+
const enabled = options.enabled ?? true;
|
|
52
59
|
// A write anyone sends — a save, another use case, a panel beside — to what it follows.
|
|
53
60
|
const followed = (options.follows ?? [])
|
|
54
61
|
.map(routeOf)
|
|
@@ -64,6 +71,8 @@ export function useServiceReading(useCase, args, options = {}) {
|
|
|
64
71
|
});
|
|
65
72
|
}, [changes, entities, followed]);
|
|
66
73
|
useEffect(() => {
|
|
74
|
+
if (!enabled)
|
|
75
|
+
return;
|
|
67
76
|
if (seeded.current) {
|
|
68
77
|
seeded.current = false;
|
|
69
78
|
return;
|
|
@@ -81,8 +90,9 @@ export function useServiceReading(useCase, args, options = {}) {
|
|
|
81
90
|
setAnswered({ key, status: "failed", answer: undefined, error });
|
|
82
91
|
});
|
|
83
92
|
return () => void (current = false);
|
|
84
|
-
// `context` and `again` read again: another company, a followed write, a `reload()
|
|
85
|
-
|
|
93
|
+
// `context` and `again` read again: another company, a followed write, a `reload()`; and
|
|
94
|
+
// being enabled reads what had to wait.
|
|
95
|
+
}, [key, context, again, enabled]);
|
|
86
96
|
const reload = useCallback(() => setAgain((n) => n + 1), []);
|
|
87
97
|
if (answered === null || answered.key !== key)
|
|
88
98
|
return { status: "loading", answer: undefined, error: null, reload };
|
package/dist/web/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { attachmentOf } from "./files.js";
|
|
|
5
5
|
export { BatchProgress } from "./list/BatchProgress.js";
|
|
6
6
|
export { aggregateOf, type ColumnOptions, columnsOf, } from "./list/columns.js";
|
|
7
7
|
export { actionsOf, type ScreenActions } from "./list/dock.js";
|
|
8
|
-
export { type EntityEmpty, type EntityFace, EntityList, type EntityListProps, type View, } from "./list/EntityList.js";
|
|
8
|
+
export { type EntityEmpty, type EntityFace, EntityList, type EntityListProps, useScreenListing, type View, } from "./list/EntityList.js";
|
|
9
9
|
export { EntitySearchBar } from "./list/EntitySearchBar.js";
|
|
10
10
|
export { groupableOf, pilesOf } from "./list/groups.js";
|
|
11
11
|
export { OpenInMenu } from "./list/openIn.js";
|
|
@@ -15,6 +15,7 @@ export { type Choice, type Chooser, findChoices, type FrameworkReads, modelLoade
|
|
|
15
15
|
export { type Reorder, useReorder } from "./list/reorder.js";
|
|
16
16
|
export { type RowCommand, type RowCommands, useRowCommands, } from "./list/rowCommands.js";
|
|
17
17
|
export { facetsOf, modelOf } from "./list/search.js";
|
|
18
|
+
export { type EntityListState, useEntityList, } from "./list/useEntityList.js";
|
|
18
19
|
export { type ActionDialog, type Asked, } from "./record/ActionButton.js";
|
|
19
20
|
export { type AskedField, type AskField, type AskForm, askFormOf, unansweredOf, } from "./record/ask.js";
|
|
20
21
|
export { ChoiceTag, type ChoiceTagLook, choiceTagOf, } from "./record/choice.js";
|
|
@@ -38,7 +39,8 @@ export { Refused } from "./Refused.js";
|
|
|
38
39
|
export { RouteError, type RouteErrorProps } from "./RouteError.js";
|
|
39
40
|
export { entityView, type EntityViewOptions, listView, type ListViewOptions, } from "./workspace/composer.js";
|
|
40
41
|
export { openIn, openOptions, RECORD_SIZE, RelatedRecord, targetsFor, } from "./workspace/open.js";
|
|
41
|
-
export {
|
|
42
|
+
export { type RecordTag, type Stamp, useRecordScreen, } from "./workspace/record.js";
|
|
43
|
+
export { EntityRecord, type FieldDrawn, type ReadyRecord, RecordScreen, type RecordScreenProps, type RelatedLink, useScreenColumns, useScreenRecord, } from "./workspace/RecordScreen.js";
|
|
42
44
|
export { SincproApp } from "./workspace/SincproApp.js";
|
|
43
45
|
export { webUiSkin } from "./workspace/skin.js";
|
|
44
46
|
export { chooserIn, useFollowed, useRecordInWorkspace, } from "./workspace/workspace.js";
|