@sincpro/web-framework 3.22.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -112
- package/dist/core/cache.d.ts +20 -23
- package/dist/core/cache.js +37 -52
- package/dist/core/changes.d.ts +10 -18
- package/dist/core/changes.js +11 -30
- package/dist/core/command.d.ts +25 -11
- package/dist/core/command.js +9 -12
- package/dist/core/edit.d.ts +16 -2
- package/dist/core/edit.js +13 -2
- package/dist/core/groups.d.ts +3 -2
- package/dist/core/groups.js +4 -3
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +2 -2
- package/dist/core/list.d.ts +17 -11
- package/dist/core/list.js +17 -11
- package/dist/core/names.d.ts +8 -6
- package/dist/core/names.js +14 -18
- package/dist/core/server.d.ts +9 -7
- package/dist/core/server.js +17 -21
- package/dist/core/trail.d.ts +6 -3
- package/dist/core/trail.js +2 -2
- package/dist/react/context.d.ts +13 -6
- package/dist/react/context.js +11 -9
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/useBatchCommand.d.ts +5 -5
- package/dist/react/useBatchCommand.js +10 -12
- package/dist/react/useCommand.d.ts +11 -15
- package/dist/react/useCommand.js +15 -13
- package/dist/react/useCount.d.ts +2 -2
- package/dist/react/useCounts.js +10 -9
- package/dist/react/useGroups.d.ts +1 -1
- package/dist/react/useGroups.js +22 -13
- package/dist/react/useHistory.js +7 -7
- package/dist/react/useListing.d.ts +14 -7
- package/dist/react/useListing.js +33 -9
- package/dist/react/useLookup.js +5 -7
- package/dist/react/useNameOf.d.ts +2 -2
- package/dist/react/useNameOf.js +4 -13
- package/dist/react/usePivot.d.ts +1 -1
- package/dist/react/usePivot.js +13 -7
- package/dist/react/useRecord.js +37 -55
- package/dist/react/useRecordLifecycle.js +8 -9
- package/dist/react/useServiceReading.js +6 -18
- package/dist/react/useUpload.js +9 -2
- package/dist/react/useWrites.d.ts +13 -12
- package/dist/react/useWrites.js +17 -16
- package/dist/web/board/Dashboard.d.ts +2 -2
- package/dist/web/list/EntityList.d.ts +2 -2
- package/dist/web/list/entityList/choosing.d.ts +3 -3
- package/dist/web/list/entityList/faces.d.ts +6 -6
- package/dist/web/list/entityList/grouping.d.ts +3 -3
- package/dist/web/list/entityList/opening.d.ts +4 -4
- package/dist/web/list/entityList/opening.js +2 -1
- package/dist/web/list/entityList/paging.d.ts +3 -3
- package/dist/web/list/entityList/props.d.ts +4 -4
- package/dist/web/list/entityList/rowActions.d.ts +4 -4
- package/dist/web/list/entityList/rowActions.js +1 -1
- package/dist/web/list/export.d.ts +2 -2
- package/dist/web/list/export.js +7 -8
- package/dist/web/list/presentation.d.ts +3 -3
- package/dist/web/list/records.d.ts +13 -10
- package/dist/web/list/records.js +23 -44
- package/dist/web/list/reorder.d.ts +1 -1
- package/dist/web/list/reorder.js +8 -6
- package/dist/web/list/rowCommands.d.ts +10 -9
- package/dist/web/list/rowCommands.js +14 -15
- package/dist/web/list/useEntityList.d.ts +4 -4
- package/dist/web/record/CommandButton.d.ts +8 -8
- package/dist/web/record/EntityTags.js +4 -4
- package/dist/web/record/RelatedList.js +2 -2
- package/dist/web/record/lines.js +4 -4
- package/dist/web/record/richText.js +1 -1
- package/dist/web/workspace/SincproApp.d.ts +8 -6
- package/dist/web/workspace/SincproApp.js +17 -19
- package/dist/web/workspace/composer.d.ts +14 -9
- package/dist/web/workspace/composer.js +29 -8
- package/dist/web/workspace/record.js +2 -2
- package/package.json +3 -3
package/dist/react/useRecord.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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
5
|
import { useFramework } from "./context.js";
|
|
6
6
|
import { useWrites } from "./useWrites.js";
|
|
@@ -8,7 +8,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
|
8
8
|
/** How long typing has to pause before the server is asked what the record becomes. */
|
|
9
9
|
const PREVIEW_PAUSE = 300;
|
|
10
10
|
export function useRecord(entity, opened, options = {}) {
|
|
11
|
-
const {
|
|
11
|
+
const { operations, locale, metas, context } = useFramework();
|
|
12
12
|
const given = typeof opened === "string" ? opened : (opened.id ?? "");
|
|
13
13
|
// As written in the reference: a text compares by value, so a new render with the same
|
|
14
14
|
// reference is not a new start.
|
|
@@ -58,7 +58,7 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
58
58
|
// their order): on mount it is not asked again — nor in React's second mount of the same
|
|
59
59
|
// question (StrictMode). Any other question (a `reload()`, another id, another transport)
|
|
60
60
|
// reads as always.
|
|
61
|
-
const answered = useRef(served === undefined ? null : [
|
|
61
|
+
const answered = useRef(served === undefined ? null : [operations, metas, entity, given, given === "", start, 0]);
|
|
62
62
|
// A server that answers the record FROM the draft (sincpro_framework) sends no values apart:
|
|
63
63
|
// the record is the draft. One that sends them apart, they are what was typed.
|
|
64
64
|
const [typed, setTyped] = useState(() => served?.draft?.values ?? {});
|
|
@@ -95,7 +95,7 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
95
95
|
};
|
|
96
96
|
useEffect(() => {
|
|
97
97
|
// The server's question (`initial`) is answered already: nothing to read.
|
|
98
|
-
const asked = [
|
|
98
|
+
const asked = [operations, metas, entity, id, isNew, start, round];
|
|
99
99
|
const before = answered.current;
|
|
100
100
|
if (before !== null && asked.every((one, at) => Object.is(one, before[at])))
|
|
101
101
|
return;
|
|
@@ -108,14 +108,8 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
108
108
|
if (!again)
|
|
109
109
|
setState((now) => ({ status: "loading", record: null, meta: now.meta, error: null }));
|
|
110
110
|
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) => {
|
|
111
|
+
// Nothing to read but the model: the contract's, or a face's (`ModelDefinitions`).
|
|
112
|
+
Promise.resolve(metas.get(entity.key) ?? null).then((meta) => {
|
|
119
113
|
if (meta)
|
|
120
114
|
metas.set(entity.key, meta);
|
|
121
115
|
if (aborter.signal.aborted)
|
|
@@ -138,7 +132,10 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
138
132
|
});
|
|
139
133
|
return () => aborter.abort();
|
|
140
134
|
}
|
|
141
|
-
|
|
135
|
+
readRecord(operations, entity, id, {
|
|
136
|
+
signal: aborter.signal,
|
|
137
|
+
meta: metas.get(entity.key) ?? null,
|
|
138
|
+
}).then((answer) => {
|
|
142
139
|
if (answer.meta)
|
|
143
140
|
metas.set(entity.key, answer.meta);
|
|
144
141
|
if (aborter.signal.aborted)
|
|
@@ -164,9 +161,9 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
164
161
|
});
|
|
165
162
|
return () => aborter.abort();
|
|
166
163
|
// `forget` only resets this hook's own state; listing it would reload the record on every
|
|
167
|
-
// render. What reloads it is the
|
|
164
|
+
// render. What reloads it is the operations, the entity, the id or an explicit `reload()`.
|
|
168
165
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
169
|
-
}, [
|
|
166
|
+
}, [operations, metas, entity, id, isNew, start, round]);
|
|
170
167
|
useEffect(() => {
|
|
171
168
|
mounted.current = true;
|
|
172
169
|
return () => {
|
|
@@ -179,7 +176,7 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
179
176
|
// panel beside —: a record with nothing typed reads again; one being edited keeps what was
|
|
180
177
|
// typed — losing it is never the framework's decision, and its save still meets the version
|
|
181
178
|
// it read (a 409 when someone saved). Its own save reads it again by itself.
|
|
182
|
-
const writes = useWrites(isNew ? undefined : entity
|
|
179
|
+
const writes = useWrites(isNew ? undefined : entity);
|
|
183
180
|
const askedFor = useRef({ context, writes });
|
|
184
181
|
useEffect(() => {
|
|
185
182
|
if (askedFor.current.context === context && askedFor.current.writes === writes)
|
|
@@ -194,16 +191,15 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
194
191
|
const version = record["version"];
|
|
195
192
|
// sincpro_framework's `Edit` names a record by `id`; a model keyed by another field (an
|
|
196
193
|
// invoice's number, the server's to give) is still created through `create`.
|
|
194
|
+
const editing = entity.operations.edit;
|
|
197
195
|
const byEdit = isNew &&
|
|
198
|
-
|
|
196
|
+
editing !== undefined &&
|
|
199
197
|
(state.meta?.get_id || state.meta?.identity || "id") === "id";
|
|
200
198
|
// Whether anything can store this record: a new one by `create` (or `Edit` under a minted
|
|
201
|
-
// key), a stored one by `edit
|
|
199
|
+
// key), a stored one by `edit`. A payment or an order that only Commands move has
|
|
202
200
|
// neither — every field of it is read only, whatever the model's hints say: an input nothing
|
|
203
201
|
// can save is an invitation that lies.
|
|
204
|
-
const writable = isNew
|
|
205
|
-
? canCreate(entity, state.meta)
|
|
206
|
-
: (entity.edit ?? entity.save) !== undefined;
|
|
202
|
+
const writable = isNew ? canCreate(entity, state.meta) : editing !== undefined;
|
|
207
203
|
/** The record's key for a write: its own, or the one minted for it while it is new. */
|
|
208
204
|
const keyNow = () => {
|
|
209
205
|
if (!byEdit)
|
|
@@ -213,7 +209,7 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
213
209
|
return minted.current.key;
|
|
214
210
|
};
|
|
215
211
|
const ask = (next, name) => {
|
|
216
|
-
const preview = entity.preview;
|
|
212
|
+
const preview = entity.operations.preview;
|
|
217
213
|
const field = name.split(".")[0] ?? name;
|
|
218
214
|
// What the server wrote down is computed here, as it would: a change whose every reach has
|
|
219
215
|
// a formula needs the server only for a rule that judges it.
|
|
@@ -230,23 +226,16 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
230
226
|
return;
|
|
231
227
|
cancelPreview();
|
|
232
228
|
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
|
-
}
|
|
229
|
+
// What it names besides the edit (`tenant_id`) is a field of the record on screen; a
|
|
230
|
+
// preview the server cannot answer is a preview not shown — never an error out of a timer.
|
|
242
231
|
const aborter = new AbortController();
|
|
243
232
|
asking.current = aborter;
|
|
244
|
-
|
|
245
|
-
.
|
|
233
|
+
operations
|
|
234
|
+
.call(preview, withTargetsOf(preview, { ...record, ...next }, {
|
|
246
235
|
id: isNew ? null : id,
|
|
247
236
|
values: isNew ? { ...record, ...next } : changesOf(record, next),
|
|
248
237
|
changed: [name],
|
|
249
|
-
}, aborter.signal)
|
|
238
|
+
}), { signal: aborter.signal })
|
|
250
239
|
.then((answer) => {
|
|
251
240
|
if (aborter.signal.aborted || !mounted.current)
|
|
252
241
|
return;
|
|
@@ -335,23 +324,19 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
335
324
|
save: async () => {
|
|
336
325
|
if (isNew && !byEdit)
|
|
337
326
|
return create();
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
throw new Error(`${entity.key} declares no save route`);
|
|
327
|
+
if (editing === undefined)
|
|
328
|
+
throw new Error(`${entity.key} has no edit`);
|
|
341
329
|
cancelPreview();
|
|
342
330
|
setSaving(true);
|
|
343
331
|
setFailure(null);
|
|
344
|
-
const key = keyNow();
|
|
345
332
|
try {
|
|
346
|
-
await
|
|
347
|
-
? { ...changed, ...(version === undefined ? {} : { version }) }
|
|
348
|
-
: editOf("save"));
|
|
333
|
+
await operations.call(editing, withTargetsOf(editing, values, editOf("save")));
|
|
349
334
|
setDraft(null);
|
|
350
335
|
// Stored under the key it was born with: the hook becomes that record and reads it.
|
|
351
336
|
if (isNew) {
|
|
352
337
|
if (mounted.current) {
|
|
353
338
|
forget();
|
|
354
|
-
setBorn({ from: given, id:
|
|
339
|
+
setBorn({ from: given, id: keyNow() });
|
|
355
340
|
}
|
|
356
341
|
}
|
|
357
342
|
else
|
|
@@ -373,25 +358,22 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
373
358
|
discard: () => {
|
|
374
359
|
forget();
|
|
375
360
|
// The draft lives on the server: discarding only here would bring it back on the next read.
|
|
376
|
-
|
|
377
|
-
if (route === undefined || draft === null)
|
|
361
|
+
if (editing === undefined || draft === null)
|
|
378
362
|
return;
|
|
379
363
|
setDraft(null);
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
.then(() => transport.send(route.method, pathFor(route, keyNow(), values), editOf("discard")))
|
|
364
|
+
operations
|
|
365
|
+
.call(editing, withTargetsOf(editing, values, editOf("discard")))
|
|
383
366
|
.then(() => mounted.current && reload())
|
|
384
367
|
.catch((error) => mounted.current && refused(error));
|
|
385
368
|
},
|
|
386
369
|
created,
|
|
387
370
|
// A draft is kept against a record: a stored one, or a new one born by `Edit` under its key.
|
|
388
|
-
...(
|
|
371
|
+
...(editing === undefined || (isNew && !byEdit)
|
|
389
372
|
? {}
|
|
390
373
|
: {
|
|
391
374
|
keep: async () => {
|
|
392
|
-
const route = (entity.edit ?? entity.draft);
|
|
393
375
|
try {
|
|
394
|
-
const kept = await
|
|
376
|
+
const kept = await operations.call(editing, withTargetsOf(editing, values, editOf("save_draft")));
|
|
395
377
|
const now = kept.draft;
|
|
396
378
|
if (now)
|
|
397
379
|
setDraft({
|
|
@@ -409,9 +391,9 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
409
391
|
}),
|
|
410
392
|
};
|
|
411
393
|
async function create() {
|
|
412
|
-
const
|
|
413
|
-
if (
|
|
414
|
-
throw new Error(`${entity.key}
|
|
394
|
+
const creator = entity.operations.commands?.create;
|
|
395
|
+
if (creator === undefined)
|
|
396
|
+
throw new Error(`${entity.key} has no create`);
|
|
415
397
|
cancelPreview();
|
|
416
398
|
setSaving(true);
|
|
417
399
|
setFailure(null);
|
|
@@ -419,7 +401,7 @@ export function useRecord(entity, opened, options = {}) {
|
|
|
419
401
|
const body = creationOf(state.meta, values);
|
|
420
402
|
const idempotencyKey = creating.current.keyFor(body);
|
|
421
403
|
try {
|
|
422
|
-
const answer = await
|
|
404
|
+
const answer = await operations.call(creator, body, { idempotencyKey });
|
|
423
405
|
creating.current.settle(null);
|
|
424
406
|
if (!mounted.current)
|
|
425
407
|
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/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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EntityOperations } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
3
|
import type { WorkspaceApi } from "@sincpro/web-composer";
|
|
4
4
|
import type { GroupLevel, NamedFilter } from "../../../core/list.js";
|
|
@@ -13,8 +13,8 @@ export type { NamedFilter };
|
|
|
13
13
|
* What a screen says to an `EntityList`: values, never regions — a region is a part
|
|
14
14
|
* (`EntityList.Bar`, `EntityList.Table`…).
|
|
15
15
|
*/
|
|
16
|
-
export type EntityListProps<T extends AnyRecord,
|
|
17
|
-
listing: Listing<T,
|
|
16
|
+
export type EntityListProps<T extends AnyRecord, O extends EntityOperations = EntityOperations> = {
|
|
17
|
+
listing: Listing<T, O>;
|
|
18
18
|
/**
|
|
19
19
|
* The workspace this list is a view of. With it, a row opens its record as a page, the
|
|
20
20
|
* identity column is the composer's `RecordLink` (peek, side panel, window on hover) and the
|
|
@@ -135,7 +135,7 @@ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = Comma
|
|
|
135
135
|
* The entity's Commands offered on each row («Confirmar»), sent with their idempotency key;
|
|
136
136
|
* the list is read again when one is done (`useRowCommands`).
|
|
137
137
|
*/
|
|
138
|
-
commands?: readonly RowCommand<T,
|
|
138
|
+
commands?: readonly RowCommand<T, O>[];
|
|
139
139
|
/** Any other action of a row — or the commands built by hand with `useRowCommands`. */
|
|
140
140
|
rowActions?: (row: T) => readonly RowAction[];
|
|
141
141
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EntityOperations } from "@sincpro/client-framework";
|
|
2
2
|
import type { AnyRecord } from "@sincpro/criteria";
|
|
3
3
|
import type { Listing } from "../../../react/useListing.js";
|
|
4
4
|
import { type RowCommand } from "../rowCommands.js";
|
|
@@ -11,10 +11,10 @@ import type { RowAction } from "@sincpro/web-ui";
|
|
|
11
11
|
* undone, so it runs on the click, and the list reads again after. Rows are reordered only on the
|
|
12
12
|
* whole order, never grouped or while choosing.
|
|
13
13
|
*/
|
|
14
|
-
export declare function useListRowActions<T extends AnyRecord,
|
|
15
|
-
listing: Listing<T,
|
|
14
|
+
export declare function useListRowActions<T extends AnyRecord, O extends EntityOperations>({ listing, idOf, commands, rowActions: asked, grouped, choosing, }: {
|
|
15
|
+
listing: Listing<T, O>;
|
|
16
16
|
idOf: (row: T) => string;
|
|
17
|
-
commands: readonly RowCommand<T,
|
|
17
|
+
commands: readonly RowCommand<T, O>[];
|
|
18
18
|
rowActions: ((row: T) => readonly RowAction[]) | undefined;
|
|
19
19
|
grouped: boolean;
|
|
20
20
|
choosing: boolean;
|