@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
package/dist/react/useRecord.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { newEntityId,
|
|
3
|
-
import { canCreate, changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, } from "../core/edit.js";
|
|
2
|
+
import { newEntityId, readRecord, retryKeys, startingValuesOf, TransportError, WITH_PARAM, } from "@sincpro/client-framework";
|
|
3
|
+
import { canCreate, changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, withTargetsOf, } from "../core/edit.js";
|
|
4
4
|
import { linesAnswered } from "../core/lines.js";
|
|
5
|
+
import { knownModelOf } from "../core/models.js";
|
|
5
6
|
import { useFramework } from "./context.js";
|
|
6
7
|
import { useWrites } from "./useWrites.js";
|
|
7
8
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
8
9
|
/** How long typing has to pause before the server is asked what the record becomes. */
|
|
9
10
|
const PREVIEW_PAUSE = 300;
|
|
10
11
|
export function useRecord(entity, opened, options = {}) {
|
|
11
|
-
const {
|
|
12
|
+
const { operations, locale, metas, context } = useFramework();
|
|
12
13
|
const given = typeof opened === "string" ? opened : (opened.id ?? "");
|
|
13
14
|
// As written in the reference: a text compares by value, so a new render with the same
|
|
14
15
|
// reference is not a new start.
|
|
@@ -28,7 +29,7 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
28
29
|
const startedFrom = (read) => {
|
|
29
30
|
if (read.meta)
|
|
30
31
|
metas.set(entity.key, read.meta);
|
|
31
|
-
const meta = read.meta ?? metas
|
|
32
|
+
const meta = read.meta ?? knownModelOf(metas, entity) ?? null;
|
|
32
33
|
const starting = start === undefined ? {} : startingValuesOf({ params: { [WITH_PARAM]: start } });
|
|
33
34
|
return {
|
|
34
35
|
status: "ready",
|
|
@@ -58,7 +59,7 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
58
59
|
// their order): on mount it is not asked again — nor in React's second mount of the same
|
|
59
60
|
// question (StrictMode). Any other question (a `reload()`, another id, another transport)
|
|
60
61
|
// reads as always.
|
|
61
|
-
const answered = useRef(served === undefined ? null : [
|
|
62
|
+
const answered = useRef(served === undefined ? null : [operations, metas, entity, given, given === "", start, 0]);
|
|
62
63
|
// A server that answers the record FROM the draft (sincpro_framework) sends no values apart:
|
|
63
64
|
// the record is the draft. One that sends them apart, they are what was typed.
|
|
64
65
|
const [typed, setTyped] = useState(() => served?.draft?.values ?? {});
|
|
@@ -95,7 +96,7 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
95
96
|
};
|
|
96
97
|
useEffect(() => {
|
|
97
98
|
// The server's question (`initial`) is answered already: nothing to read.
|
|
98
|
-
const asked = [
|
|
99
|
+
const asked = [operations, metas, entity, id, isNew, start, round];
|
|
99
100
|
const before = answered.current;
|
|
100
101
|
if (before !== null && asked.every((one, at) => Object.is(one, before[at])))
|
|
101
102
|
return;
|
|
@@ -108,14 +109,8 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
108
109
|
if (!again)
|
|
109
110
|
setState((now) => ({ status: "loading", record: null, meta: now.meta, error: null }));
|
|
110
111
|
if (isNew) {
|
|
111
|
-
// Nothing to read but the model:
|
|
112
|
-
|
|
113
|
-
const asked = known
|
|
114
|
-
? Promise.resolve(known)
|
|
115
|
-
: transport
|
|
116
|
-
.list(entity.list, { pagination: { limit: 1 } }, aborter.signal)
|
|
117
|
-
.then((page) => page.meta);
|
|
118
|
-
asked.then((meta) => {
|
|
112
|
+
// Nothing to read but the model: the contract's, or a face's (`ModelDefinitions`).
|
|
113
|
+
Promise.resolve(knownModelOf(metas, entity) ?? null).then((meta) => {
|
|
119
114
|
if (meta)
|
|
120
115
|
metas.set(entity.key, meta);
|
|
121
116
|
if (aborter.signal.aborted)
|
|
@@ -138,7 +133,10 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
138
133
|
});
|
|
139
134
|
return () => aborter.abort();
|
|
140
135
|
}
|
|
141
|
-
|
|
136
|
+
readRecord(operations, entity, id, {
|
|
137
|
+
signal: aborter.signal,
|
|
138
|
+
meta: knownModelOf(metas, entity) ?? null,
|
|
139
|
+
}).then((answer) => {
|
|
142
140
|
if (answer.meta)
|
|
143
141
|
metas.set(entity.key, answer.meta);
|
|
144
142
|
if (aborter.signal.aborted)
|
|
@@ -153,7 +151,7 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
153
151
|
setState({
|
|
154
152
|
status: "ready",
|
|
155
153
|
record: answer.record,
|
|
156
|
-
meta: answer.meta ?? metas
|
|
154
|
+
meta: answer.meta ?? knownModelOf(metas, entity) ?? null,
|
|
157
155
|
error: null,
|
|
158
156
|
});
|
|
159
157
|
}, (error) => {
|
|
@@ -164,9 +162,9 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
164
162
|
});
|
|
165
163
|
return () => aborter.abort();
|
|
166
164
|
// `forget` only resets this hook's own state; listing it would reload the record on every
|
|
167
|
-
// render. What reloads it is the
|
|
165
|
+
// render. What reloads it is the operations, the entity, the id or an explicit `reload()`.
|
|
168
166
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
169
|
-
}, [
|
|
167
|
+
}, [operations, metas, entity, id, isNew, start, round]);
|
|
170
168
|
useEffect(() => {
|
|
171
169
|
mounted.current = true;
|
|
172
170
|
return () => {
|
|
@@ -179,7 +177,7 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
179
177
|
// panel beside —: a record with nothing typed reads again; one being edited keeps what was
|
|
180
178
|
// typed — losing it is never the framework's decision, and its save still meets the version
|
|
181
179
|
// it read (a 409 when someone saved). Its own save reads it again by itself.
|
|
182
|
-
const writes = useWrites(isNew ? undefined : entity
|
|
180
|
+
const writes = useWrites(isNew ? undefined : entity);
|
|
183
181
|
const askedFor = useRef({ context, writes });
|
|
184
182
|
useEffect(() => {
|
|
185
183
|
if (askedFor.current.context === context && askedFor.current.writes === writes)
|
|
@@ -194,16 +192,15 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
194
192
|
const version = record["version"];
|
|
195
193
|
// sincpro_framework's `Edit` names a record by `id`; a model keyed by another field (an
|
|
196
194
|
// invoice's number, the server's to give) is still created through `create`.
|
|
195
|
+
const editing = entity.operations.edit;
|
|
197
196
|
const byEdit = isNew &&
|
|
198
|
-
|
|
197
|
+
editing !== undefined &&
|
|
199
198
|
(state.meta?.get_id || state.meta?.identity || "id") === "id";
|
|
200
199
|
// Whether anything can store this record: a new one by `create` (or `Edit` under a minted
|
|
201
|
-
// key), a stored one by `edit
|
|
200
|
+
// key), a stored one by `edit`. A payment or an order that only Commands move has
|
|
202
201
|
// neither — every field of it is read only, whatever the model's hints say: an input nothing
|
|
203
202
|
// can save is an invitation that lies.
|
|
204
|
-
const writable = isNew
|
|
205
|
-
? canCreate(entity, state.meta)
|
|
206
|
-
: (entity.edit ?? entity.save) !== undefined;
|
|
203
|
+
const writable = isNew ? canCreate(entity, state.meta) : editing !== undefined;
|
|
207
204
|
/** The record's key for a write: its own, or the one minted for it while it is new. */
|
|
208
205
|
const keyNow = () => {
|
|
209
206
|
if (!byEdit)
|
|
@@ -213,7 +210,7 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
213
210
|
return minted.current.key;
|
|
214
211
|
};
|
|
215
212
|
const ask = (next, name) => {
|
|
216
|
-
const preview = entity.preview;
|
|
213
|
+
const preview = entity.operations.preview;
|
|
217
214
|
const field = name.split(".")[0] ?? name;
|
|
218
215
|
// What the server wrote down is computed here, as it would: a change whose every reach has
|
|
219
216
|
// a formula needs the server only for a rule that judges it.
|
|
@@ -230,23 +227,16 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
230
227
|
return;
|
|
231
228
|
cancelPreview();
|
|
232
229
|
pause.current = setTimeout(() => {
|
|
233
|
-
//
|
|
234
|
-
// a preview not
|
|
235
|
-
let path;
|
|
236
|
-
try {
|
|
237
|
-
path = pathFor(preview, isNew ? undefined : id, { ...record, ...next });
|
|
238
|
-
}
|
|
239
|
-
catch {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
230
|
+
// What it names besides the edit (`tenant_id`) is a field of the record on screen; a
|
|
231
|
+
// preview the server cannot answer is a preview not shown — never an error out of a timer.
|
|
242
232
|
const aborter = new AbortController();
|
|
243
233
|
asking.current = aborter;
|
|
244
|
-
|
|
245
|
-
.
|
|
234
|
+
operations
|
|
235
|
+
.call(preview, withTargetsOf(preview, { ...record, ...next }, {
|
|
246
236
|
id: isNew ? null : id,
|
|
247
237
|
values: isNew ? { ...record, ...next } : changesOf(record, next),
|
|
248
238
|
changed: [name],
|
|
249
|
-
}, aborter.signal)
|
|
239
|
+
}), { signal: aborter.signal })
|
|
250
240
|
.then((answer) => {
|
|
251
241
|
if (aborter.signal.aborted || !mounted.current)
|
|
252
242
|
return;
|
|
@@ -335,23 +325,19 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
335
325
|
save: async () => {
|
|
336
326
|
if (isNew && !byEdit)
|
|
337
327
|
return create();
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
throw new Error(`${entity.key} declares no save route`);
|
|
328
|
+
if (editing === undefined)
|
|
329
|
+
throw new Error(`${entity.key} has no edit`);
|
|
341
330
|
cancelPreview();
|
|
342
331
|
setSaving(true);
|
|
343
332
|
setFailure(null);
|
|
344
|
-
const key = keyNow();
|
|
345
333
|
try {
|
|
346
|
-
await
|
|
347
|
-
? { ...changed, ...(version === undefined ? {} : { version }) }
|
|
348
|
-
: editOf("save"));
|
|
334
|
+
await operations.call(editing, withTargetsOf(editing, values, editOf("save")));
|
|
349
335
|
setDraft(null);
|
|
350
336
|
// Stored under the key it was born with: the hook becomes that record and reads it.
|
|
351
337
|
if (isNew) {
|
|
352
338
|
if (mounted.current) {
|
|
353
339
|
forget();
|
|
354
|
-
setBorn({ from: given, id:
|
|
340
|
+
setBorn({ from: given, id: keyNow() });
|
|
355
341
|
}
|
|
356
342
|
}
|
|
357
343
|
else
|
|
@@ -373,25 +359,22 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
373
359
|
discard: () => {
|
|
374
360
|
forget();
|
|
375
361
|
// The draft lives on the server: discarding only here would bring it back on the next read.
|
|
376
|
-
|
|
377
|
-
if (route === undefined || draft === null)
|
|
362
|
+
if (editing === undefined || draft === null)
|
|
378
363
|
return;
|
|
379
364
|
setDraft(null);
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
.then(() => transport.send(route.method, pathFor(route, keyNow(), values), editOf("discard")))
|
|
365
|
+
operations
|
|
366
|
+
.call(editing, withTargetsOf(editing, values, editOf("discard")))
|
|
383
367
|
.then(() => mounted.current && reload())
|
|
384
368
|
.catch((error) => mounted.current && refused(error));
|
|
385
369
|
},
|
|
386
370
|
created,
|
|
387
371
|
// A draft is kept against a record: a stored one, or a new one born by `Edit` under its key.
|
|
388
|
-
...(
|
|
372
|
+
...(editing === undefined || (isNew && !byEdit)
|
|
389
373
|
? {}
|
|
390
374
|
: {
|
|
391
375
|
keep: async () => {
|
|
392
|
-
const route = (entity.edit ?? entity.draft);
|
|
393
376
|
try {
|
|
394
|
-
const kept = await
|
|
377
|
+
const kept = await operations.call(editing, withTargetsOf(editing, values, editOf("save_draft")));
|
|
395
378
|
const now = kept.draft;
|
|
396
379
|
if (now)
|
|
397
380
|
setDraft({
|
|
@@ -409,9 +392,9 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
409
392
|
}),
|
|
410
393
|
};
|
|
411
394
|
async function create() {
|
|
412
|
-
const
|
|
413
|
-
if (
|
|
414
|
-
throw new Error(`${entity.key}
|
|
395
|
+
const creator = entity.operations.commands?.create;
|
|
396
|
+
if (creator === undefined)
|
|
397
|
+
throw new Error(`${entity.key} has no create`);
|
|
415
398
|
cancelPreview();
|
|
416
399
|
setSaving(true);
|
|
417
400
|
setFailure(null);
|
|
@@ -419,7 +402,7 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
419
402
|
const body = creationOf(state.meta, values);
|
|
420
403
|
const idempotencyKey = creating.current.keyFor(body);
|
|
421
404
|
try {
|
|
422
|
-
const answer = await
|
|
405
|
+
const answer = await operations.call(creator, body, { idempotencyKey });
|
|
423
406
|
creating.current.settle(null);
|
|
424
407
|
if (!mounted.current)
|
|
425
408
|
return true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { useOperationCommand, } from "./useCommand.js";
|
|
3
3
|
/**
|
|
4
4
|
* The record's own lifecycle, as actions of ONE stored record: what its entity declares of
|
|
5
5
|
* sincpro_framework's `Delete` (`entity.delete`) and its trash (`entity.archive`,
|
|
@@ -21,9 +21,10 @@ import { useRouteCommand, } from "./useCommand.js";
|
|
|
21
21
|
*/
|
|
22
22
|
export function useRecordLifecycle(record) {
|
|
23
23
|
const { entity } = record;
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
24
|
+
const { delete: remove, archive, restore } = entity.operations;
|
|
25
|
+
const deletion = useOperationCommand(entity, remove);
|
|
26
|
+
const archival = useOperationCommand(entity, archive);
|
|
27
|
+
const restoral = useOperationCommand(entity, restore);
|
|
27
28
|
const stored = !record.isNew && record.status === "ready";
|
|
28
29
|
if (!stored)
|
|
29
30
|
return {};
|
|
@@ -40,10 +41,8 @@ export function useRecordLifecycle(record) {
|
|
|
40
41
|
reset: command.reset,
|
|
41
42
|
});
|
|
42
43
|
return {
|
|
43
|
-
...(
|
|
44
|
-
...(
|
|
45
|
-
...(
|
|
46
|
-
? {}
|
|
47
|
-
: { restore: action(restoral, false) }),
|
|
44
|
+
...(remove === undefined ? {} : { delete: action(deletion, true) }),
|
|
45
|
+
...(archive === undefined || archived ? {} : { archive: action(archival, false) }),
|
|
46
|
+
...(restore === undefined || !archived ? {} : { restore: action(restoral, false) }),
|
|
48
47
|
};
|
|
49
48
|
}
|
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import {} from "@sincpro/client-framework";
|
|
3
3
|
import { touches } from "../core/changes.js";
|
|
4
4
|
import { useFramework } from "./context.js";
|
|
5
5
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
6
|
-
/** Where `entity` is listed — or nothing to follow when it is listed only under a record. */
|
|
7
|
-
function routeOf(entity) {
|
|
8
|
-
try {
|
|
9
|
-
return listRoute(entity.list);
|
|
10
|
-
}
|
|
11
|
-
catch {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
6
|
/**
|
|
16
7
|
* A use case that READS, run by the screen that shows it: on mount, again whenever its
|
|
17
8
|
* arguments change, when the process's context changes (another company), and when a write
|
|
@@ -45,7 +36,7 @@ function routeOf(entity) {
|
|
|
45
36
|
* const perfil = useServiceReading(cuentas.perfil, [usuario], { enabled: usuario !== "" });
|
|
46
37
|
*/
|
|
47
38
|
export function useServiceReading(useCase, args, options = {}) {
|
|
48
|
-
const { context, changes
|
|
39
|
+
const { context, changes } = useFramework();
|
|
49
40
|
const key = JSON.stringify(args);
|
|
50
41
|
const latest = useRef({ useCase, args });
|
|
51
42
|
latest.current = { useCase, args };
|
|
@@ -57,19 +48,16 @@ export function useServiceReading(useCase, args, options = {}) {
|
|
|
57
48
|
const [again, setAgain] = useState(0);
|
|
58
49
|
const enabled = options.enabled ?? true;
|
|
59
50
|
// A write anyone sends — a save, another use case, a panel beside — to what it follows.
|
|
60
|
-
const followed = (options.follows ?? [])
|
|
61
|
-
.map(routeOf)
|
|
62
|
-
.filter((route) => route !== undefined)
|
|
63
|
-
.join("\n");
|
|
51
|
+
const followed = (options.follows ?? []).map((one) => one.model).join("\n");
|
|
64
52
|
useEffect(() => {
|
|
65
53
|
if (followed === "")
|
|
66
54
|
return;
|
|
67
|
-
const
|
|
55
|
+
const models = followed.split("\n");
|
|
68
56
|
return changes.follow((change) => {
|
|
69
|
-
if (
|
|
57
|
+
if (models.some((model) => touches(change, { model })))
|
|
70
58
|
setAgain((n) => n + 1);
|
|
71
59
|
});
|
|
72
|
-
}, [changes,
|
|
60
|
+
}, [changes, followed]);
|
|
73
61
|
useEffect(() => {
|
|
74
62
|
if (!enabled)
|
|
75
63
|
return;
|
package/dist/react/useSummary.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {} from "@sincpro/client-framework";
|
|
3
|
+
import { knownModelOf } from "../core/models.js";
|
|
3
4
|
import { summaryOf } from "../core/summary.js";
|
|
4
5
|
import { useFramework } from "./context.js";
|
|
5
6
|
import { useCallback } from "react";
|
|
@@ -16,7 +17,7 @@ import { useCallback } from "react";
|
|
|
16
17
|
*/
|
|
17
18
|
export function useSummaryOf(entity) {
|
|
18
19
|
const { metas, locale } = useFramework();
|
|
19
|
-
return useCallback((record, meta) => summaryOf(meta ?? metas
|
|
20
|
+
return useCallback((record, meta) => summaryOf(meta ?? knownModelOf(metas, entity) ?? null, record, {
|
|
20
21
|
fields: entity.summary,
|
|
21
22
|
...(locale === undefined ? {} : { locale }),
|
|
22
23
|
}), [metas, entity, locale]);
|
package/dist/react/useUpload.js
CHANGED
|
@@ -27,7 +27,8 @@ export function useUpload(about, own) {
|
|
|
27
27
|
useEffect(() => () => running.current?.abort(), []);
|
|
28
28
|
const send = useCallback(async (file) => {
|
|
29
29
|
const { about: target, uploads: where, transport: wire } = now.current;
|
|
30
|
-
|
|
30
|
+
// Where the bytes go is REST's transport: without it, nothing is sent.
|
|
31
|
+
if (where === undefined || wire === undefined)
|
|
31
32
|
return undefined;
|
|
32
33
|
running.current?.abort();
|
|
33
34
|
const control = new AbortController();
|
|
@@ -65,5 +66,11 @@ export function useUpload(about, own) {
|
|
|
65
66
|
}, []);
|
|
66
67
|
const cancel = useCallback(() => running.current?.abort(), []);
|
|
67
68
|
const retry = useCallback(() => (last.current === null ? Promise.resolve(undefined) : send(last.current)), [send]);
|
|
68
|
-
return {
|
|
69
|
+
return {
|
|
70
|
+
available: uploads !== undefined && transport !== undefined,
|
|
71
|
+
...state,
|
|
72
|
+
send,
|
|
73
|
+
cancel,
|
|
74
|
+
retry,
|
|
75
|
+
};
|
|
69
76
|
}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import type { Entity } from "@sincpro/client-framework";
|
|
1
2
|
/**
|
|
2
|
-
* How many times
|
|
3
|
-
*
|
|
3
|
+
* How many times `entity` was written since this screen started reading it — a dependency that
|
|
4
|
+
* makes a reading read again.
|
|
4
5
|
*
|
|
5
|
-
* const writes = useWrites(
|
|
6
|
-
* useEffect(() => { …
|
|
6
|
+
* const writes = useWrites(entity);
|
|
7
|
+
* useEffect(() => { … readPage(operations, entity, …) … }, [operations, entity, writes]);
|
|
7
8
|
*
|
|
8
9
|
* Context: a screen must show what is true now, whoever wrote it — its own save, a use case run
|
|
9
|
-
* from a button, a panel beside it. Every write
|
|
10
|
-
* on the process's change feed (`processChanges`, @sincpro/client-framework); this
|
|
11
|
-
* counts the ones that
|
|
12
|
-
* history
|
|
13
|
-
* framework's own readings do (`useListing`, `useRecord`, `useHistory`, `useGroups`,
|
|
14
|
-
* `useNameOf`), and so may a screen's own. It reads again on the next render, when
|
|
15
|
-
* it — following the same feed — has already forgotten the old answer.
|
|
10
|
+
* from a button, a panel beside it. Every write an operation adapter of the framework sends is
|
|
11
|
+
* announced on the process's change feed (`processChanges`, @sincpro/client-framework); this
|
|
12
|
+
* follows it and counts the ones that name the entity (`touches`) — its lists, its records and
|
|
13
|
+
* their history alike. A reading adds the count to what it reads by, as it adds the company it
|
|
14
|
+
* reads in: the framework's own readings do (`useListing`, `useRecord`, `useHistory`, `useGroups`,
|
|
15
|
+
* `usePivot`, `useNameOf`), and so may a screen's own. It reads again on the next render, when
|
|
16
|
+
* the cache under it — following the same feed — has already forgotten the old answer.
|
|
16
17
|
*
|
|
17
18
|
* `undefined`: nothing is read yet, and nothing is counted.
|
|
18
19
|
*/
|
|
19
|
-
export declare function useWrites(
|
|
20
|
+
export declare function useWrites(entity: Pick<Entity, "model"> | undefined): number;
|
package/dist/react/useWrites.js
CHANGED
|
@@ -3,33 +3,34 @@ import { touches } from "../core/changes.js";
|
|
|
3
3
|
import { useFramework } from "./context.js";
|
|
4
4
|
import { useEffect, useState } from "react";
|
|
5
5
|
/**
|
|
6
|
-
* How many times
|
|
7
|
-
*
|
|
6
|
+
* How many times `entity` was written since this screen started reading it — a dependency that
|
|
7
|
+
* makes a reading read again.
|
|
8
8
|
*
|
|
9
|
-
* const writes = useWrites(
|
|
10
|
-
* useEffect(() => { …
|
|
9
|
+
* const writes = useWrites(entity);
|
|
10
|
+
* useEffect(() => { … readPage(operations, entity, …) … }, [operations, entity, writes]);
|
|
11
11
|
*
|
|
12
12
|
* Context: a screen must show what is true now, whoever wrote it — its own save, a use case run
|
|
13
|
-
* from a button, a panel beside it. Every write
|
|
14
|
-
* on the process's change feed (`processChanges`, @sincpro/client-framework); this
|
|
15
|
-
* counts the ones that
|
|
16
|
-
* history
|
|
17
|
-
* framework's own readings do (`useListing`, `useRecord`, `useHistory`, `useGroups`,
|
|
18
|
-
* `useNameOf`), and so may a screen's own. It reads again on the next render, when
|
|
19
|
-
* it — following the same feed — has already forgotten the old answer.
|
|
13
|
+
* from a button, a panel beside it. Every write an operation adapter of the framework sends is
|
|
14
|
+
* announced on the process's change feed (`processChanges`, @sincpro/client-framework); this
|
|
15
|
+
* follows it and counts the ones that name the entity (`touches`) — its lists, its records and
|
|
16
|
+
* their history alike. A reading adds the count to what it reads by, as it adds the company it
|
|
17
|
+
* reads in: the framework's own readings do (`useListing`, `useRecord`, `useHistory`, `useGroups`,
|
|
18
|
+
* `usePivot`, `useNameOf`), and so may a screen's own. It reads again on the next render, when
|
|
19
|
+
* the cache under it — following the same feed — has already forgotten the old answer.
|
|
20
20
|
*
|
|
21
21
|
* `undefined`: nothing is read yet, and nothing is counted.
|
|
22
22
|
*/
|
|
23
|
-
export function useWrites(
|
|
24
|
-
const { changes
|
|
23
|
+
export function useWrites(entity) {
|
|
24
|
+
const { changes } = useFramework();
|
|
25
25
|
const [writes, setWrites] = useState(0);
|
|
26
|
+
const model = entity?.model;
|
|
26
27
|
useEffect(() => {
|
|
27
|
-
if (
|
|
28
|
+
if (model === undefined)
|
|
28
29
|
return;
|
|
29
30
|
return changes.follow((change) => {
|
|
30
|
-
if (touches(change,
|
|
31
|
+
if (touches(change, { model }))
|
|
31
32
|
setWrites((count) => count + 1);
|
|
32
33
|
});
|
|
33
|
-
}, [changes,
|
|
34
|
+
}, [changes, model]);
|
|
34
35
|
return writes;
|
|
35
36
|
}
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* `useBoardPeriod`, `boardStateOf`) for a tile of the application's own — a table, a list, a
|
|
24
24
|
* map — inside the same board; and web-ui's `Board` below them, for a board with no period.
|
|
25
25
|
*/
|
|
26
|
-
import type {
|
|
26
|
+
import type { Entity, EntityOperations } from "@sincpro/client-framework";
|
|
27
27
|
import { type AnyRecord, type Criteria, type Expression, type Period } from "@sincpro/criteria";
|
|
28
28
|
import type { GroupLevel } from "../../core/list.js";
|
|
29
29
|
import { type Listing } from "../../react/useListing.js";
|
|
@@ -53,7 +53,7 @@ export type BoardReadingOptions<T> = {
|
|
|
53
53
|
* A listing of `entity` as a board tile reads it: one row a page (the count and the question are
|
|
54
54
|
* what a tile wants), cut by the board's period over `over`.
|
|
55
55
|
*/
|
|
56
|
-
export declare function useBoardListing<T extends AnyRecord,
|
|
56
|
+
export declare function useBoardListing<T extends AnyRecord, O extends EntityOperations = EntityOperations>(entity: Entity<T, O>, { over, criteria }?: BoardReadingOptions<T>): Listing<T, O>;
|
|
57
57
|
/**
|
|
58
58
|
* web-ui's state of a tile from a reading: reading while it asks, the refusal in the server's
|
|
59
59
|
* words when it failed — with «Reintentar» when there is a way to ask again.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Entity, 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 EntityListProps, type EntityListState } from "./useEntityList.js";
|
|
@@ -15,7 +15,7 @@ export type { EntityEmpty, EntityFace, EntityListProps, NamedFilter, View, } fro
|
|
|
15
15
|
* }
|
|
16
16
|
*/
|
|
17
17
|
export declare function useScreenListing<T extends AnyRecord>(_entity?: Entity<T>): Listing<T>;
|
|
18
|
-
declare function EntityListRoot<T extends AnyRecord,
|
|
18
|
+
declare function EntityListRoot<T extends AnyRecord, O extends EntityOperations = EntityOperations>(props: EntityListProps<T, O> & {
|
|
19
19
|
/** The list's tree. Without it, the default: the bar, the faces of `views`, the notices. */
|
|
20
20
|
children?: ReactNode;
|
|
21
21
|
}): import("react").JSX.Element;
|
|
@@ -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 { Listing } from "../../../react/useListing.js";
|
|
@@ -23,8 +23,8 @@ export declare function purposeOf(api: WorkspaceApi | undefined): {
|
|
|
23
23
|
* without knowing this list. Its actions — answering whoever asked for several, else the
|
|
24
24
|
* screen's — go to the dock as data, or into the bar when drawn by hand.
|
|
25
25
|
*/
|
|
26
|
-
export declare function useListChoosing<T extends AnyRecord,
|
|
27
|
-
listing: Listing<T,
|
|
26
|
+
export declare function useListChoosing<T extends AnyRecord, O extends EntityOperations>({ listing, api, idOf, held, selectable, selectionActions, choosingMany, }: {
|
|
27
|
+
listing: Listing<T, O>;
|
|
28
28
|
api: WorkspaceApi | undefined;
|
|
29
29
|
idOf: (row: T) => string;
|
|
30
30
|
held: ListSelection<T> | undefined;
|
|
@@ -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 ResourceRef, type WorkspaceApi } from "@sincpro/web-composer";
|
|
4
4
|
import type { Listing } from "../../../react/useListing.js";
|
|
@@ -14,13 +14,13 @@ import { type ReactNode } from "react";
|
|
|
14
14
|
* same columns — never a second list of fields. The pivot asks the server only while it is the
|
|
15
15
|
* face on screen.
|
|
16
16
|
*/
|
|
17
|
-
export declare function useListFaces<T extends AnyRecord,
|
|
18
|
-
listing: Listing<T,
|
|
17
|
+
export declare function useListFaces<T extends AnyRecord, O extends EntityOperations>({ listing, api, idOf, columns, cells, yesNo, choosing, refOf, elsewhere, opens, openInOf, present, views, pivot: pivotAsked, }: {
|
|
18
|
+
listing: Listing<T, O>;
|
|
19
19
|
api: WorkspaceApi | undefined;
|
|
20
20
|
idOf: (row: T) => string;
|
|
21
21
|
columns: readonly string[] | undefined;
|
|
22
|
-
cells: EntityListProps<T,
|
|
23
|
-
yesNo: EntityListProps<T,
|
|
22
|
+
cells: EntityListProps<T, O>["cells"];
|
|
23
|
+
yesNo: EntityListProps<T, O>["yesNo"];
|
|
24
24
|
choosing: boolean;
|
|
25
25
|
refOf: (row: T) => ResourceRef;
|
|
26
26
|
elsewhere: readonly string[];
|
|
@@ -28,7 +28,7 @@ export declare function useListFaces<T extends AnyRecord, C extends CommandBodie
|
|
|
28
28
|
openInOf: (row: T) => ReactNode;
|
|
29
29
|
present: string;
|
|
30
30
|
views: readonly string[];
|
|
31
|
-
pivot: EntityListProps<T,
|
|
31
|
+
pivot: EntityListProps<T, O>["pivot"];
|
|
32
32
|
}): {
|
|
33
33
|
columns: import("@sincpro/web-ui").DataColumn<T>[];
|
|
34
34
|
sheetColumns: {
|
|
@@ -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 DataColumn, type Pile } from "@sincpro/web-ui";
|
|
@@ -13,8 +13,8 @@ import { type DataColumn, type Pile } from "@sincpro/web-ui";
|
|
|
13
13
|
* than it counts offers the next page of them. A table and a sheet say a group's sums under their
|
|
14
14
|
* columns: beside the group's name, only what no column shown adds up.
|
|
15
15
|
*/
|
|
16
|
-
export declare function useListGrouping<T extends AnyRecord,
|
|
17
|
-
listing: Listing<T,
|
|
16
|
+
export declare function useListGrouping<T extends AnyRecord, O extends EntityOperations>({ listing, sums, columns, present, }: {
|
|
17
|
+
listing: Listing<T, O>;
|
|
18
18
|
sums: readonly string[] | false | undefined;
|
|
19
19
|
columns: readonly DataColumn<T>[];
|
|
20
20
|
present: string;
|
|
@@ -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 { Listing } from "../../../react/useListing.js";
|
|
@@ -13,7 +13,7 @@ import type { DockAction, OpenTarget } from "@sincpro/web-ui";
|
|
|
13
13
|
* the record it opened replaced it and still walks on it — so the oldest go past a ceiling
|
|
14
14
|
* instead: one per list ever shown, fifty at most.
|
|
15
15
|
*/
|
|
16
|
-
export declare function useListTrail<T extends AnyRecord,
|
|
16
|
+
export declare function useListTrail<T extends AnyRecord, O extends EntityOperations>(listing: Listing<T, O>, api: WorkspaceApi | undefined, identity: string, idOf: (row: T) => string): string;
|
|
17
17
|
/**
|
|
18
18
|
* What a row does, and where its record may open.
|
|
19
19
|
*
|
|
@@ -22,8 +22,8 @@ export declare function useListTrail<T extends AnyRecord, C extends CommandBodie
|
|
|
22
22
|
* among the row's ways in, web-ui's (`openTargets` + `onOpenIn`): 👁 for a look, and «Abrir en…»
|
|
23
23
|
* with the rest, in ONE place at the row's end. A chooser only chooses.
|
|
24
24
|
*/
|
|
25
|
-
export declare function useListOpening<T extends AnyRecord,
|
|
26
|
-
listing: Listing<T,
|
|
25
|
+
export declare function useListOpening<T extends AnyRecord, O extends EntityOperations>({ listing, api, idOf, chosen, choosing, choosingMany, embedded, create, actions, onOpen, onPeek, openTargets, onOpenIn, }: {
|
|
26
|
+
listing: Listing<T, O>;
|
|
27
27
|
api: WorkspaceApi | undefined;
|
|
28
28
|
idOf: (row: T) => string;
|
|
29
29
|
chosen: ListSelection<T>;
|
|
@@ -28,7 +28,8 @@ export function useListTrail(listing, api, identity, idOf) {
|
|
|
28
28
|
return;
|
|
29
29
|
const pages = listing.paging === "pages";
|
|
30
30
|
trails.set(trailKey, {
|
|
31
|
-
|
|
31
|
+
entity: listing.entity,
|
|
32
|
+
input: listing.input,
|
|
32
33
|
question: listing.question,
|
|
33
34
|
key: identity,
|
|
34
35
|
ids: listing.rows.map(idOf),
|
|
@@ -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 { Groups } from "../../../react/useGroups.js";
|
|
4
4
|
import type { Listing } from "../../../react/useListing.js";
|
|
@@ -16,8 +16,8 @@ import type { ReactNode } from "react";
|
|
|
16
16
|
* this page's; inside a record or a panel a page's sum reads as THE total, so an embedded list
|
|
17
17
|
* adds up only when every row is in hand.
|
|
18
18
|
*/
|
|
19
|
-
export declare function useListPaging<T extends AnyRecord,
|
|
20
|
-
listing: Listing<T,
|
|
19
|
+
export declare function useListPaging<T extends AnyRecord, O extends EntityOperations>({ listing, groups, grouped, records, columns, embedded, present, }: {
|
|
20
|
+
listing: Listing<T, O>;
|
|
21
21
|
groups: Groups<T>;
|
|
22
22
|
grouped: boolean;
|
|
23
23
|
records: number;
|