@sincpro/web-framework 2.5.0 → 3.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.
Files changed (57) hide show
  1. package/README.md +33 -28
  2. package/dist/core/copy.d.ts +8 -0
  3. package/dist/core/copy.js +8 -0
  4. package/dist/core/edit.d.ts +19 -0
  5. package/dist/core/edit.js +46 -0
  6. package/dist/core/history.d.ts +7 -0
  7. package/dist/core/history.js +5 -0
  8. package/dist/core/index.d.ts +3 -3
  9. package/dist/core/index.js +3 -3
  10. package/dist/core/list.d.ts +20 -2
  11. package/dist/core/list.js +24 -0
  12. package/dist/core/present.d.ts +22 -0
  13. package/dist/core/present.js +51 -19
  14. package/dist/react/index.d.ts +5 -1
  15. package/dist/react/index.js +5 -1
  16. package/dist/react/useCommand.d.ts +7 -1
  17. package/dist/react/useCommand.js +12 -2
  18. package/dist/react/useCount.d.ts +18 -0
  19. package/dist/react/useCount.js +23 -0
  20. package/dist/react/useRecord.d.ts +6 -6
  21. package/dist/react/useRecord.js +10 -7
  22. package/dist/react/useRecordLifecycle.d.ts +43 -0
  23. package/dist/react/useRecordLifecycle.js +49 -0
  24. package/dist/react/useService.d.ts +5 -1
  25. package/dist/react/useServiceReading.d.ts +35 -0
  26. package/dist/react/useServiceReading.js +75 -0
  27. package/dist/react/useTextOf.d.ts +16 -0
  28. package/dist/react/useTextOf.js +21 -0
  29. package/dist/web/index.d.ts +1 -0
  30. package/dist/web/index.js +1 -0
  31. package/dist/web/list/EntityList.d.ts +4 -1
  32. package/dist/web/list/EntityList.js +23 -6
  33. package/dist/web/list/EntitySearchBar.d.ts +4 -1
  34. package/dist/web/list/EntitySearchBar.js +2 -2
  35. package/dist/web/list/groups.d.ts +13 -3
  36. package/dist/web/list/groups.js +21 -8
  37. package/dist/web/list/openIn.d.ts +4 -2
  38. package/dist/web/list/openIn.js +9 -2
  39. package/dist/web/list/rowCommands.d.ts +2 -0
  40. package/dist/web/list/rowCommands.js +6 -1
  41. package/dist/web/record/RecordLifecycle.d.ts +23 -0
  42. package/dist/web/record/RecordLifecycle.js +29 -0
  43. package/dist/web/record/control.d.ts +9 -3
  44. package/dist/web/record/control.js +13 -4
  45. package/dist/web/record/edit.js +1 -1
  46. package/dist/web/record/lines.js +1 -1
  47. package/dist/web/record/opening.d.ts +2 -2
  48. package/dist/web/record/record.js +36 -3
  49. package/dist/web/workspace/composer.d.ts +5 -1
  50. package/dist/web/workspace/composer.js +30 -12
  51. package/dist/web/workspace/open.d.ts +1 -1
  52. package/dist/web/workspace/open.js +7 -1
  53. package/dist/web/workspace/record.d.ts +6 -2
  54. package/dist/web/workspace/record.js +16 -7
  55. package/dist/web/workspace/workspace.d.ts +7 -1
  56. package/dist/web/workspace/workspace.js +13 -4
  57. package/package.json +6 -6
@@ -0,0 +1,18 @@
1
+ import type { CommandBodies, Entity } from "@sincpro/client-framework";
2
+ import type { AnyRecord, Count, Criteria } from "@sincpro/criteria";
3
+ import type { ListDefinition } from "../core/list.js";
4
+ /**
5
+ * How many records of an entity a criteria holds, counted by the SERVER: «this member's
6
+ * payments (2)», the number of a smart button. `null` until it answers — and while it fails —,
7
+ * which web-ui's `SmartButton` reads as «—», never as 0.
8
+ *
9
+ * const pagos = useCount(payments, { selection: { field: "member_id", value: member.id } });
10
+ * <SmartButton icon={Wallet} label="Pagos" count={pagos?.value} onClick={…} />
11
+ *
12
+ * Context: an application counted «this member's payments» with a hook of its own over a list
13
+ * reference it built by hand. It is a listing of one row: the count is the one the server sends
14
+ * with every page (a floor, `exact: false`, when it stopped counting at its cap), and it follows
15
+ * the context and every write to the entity as any list does — a payment saved in a modal moves
16
+ * the number behind it. Never a page fetched to be counted here.
17
+ */
18
+ export declare function useCount<T extends AnyRecord, C extends CommandBodies = CommandBodies>(given: Entity<T, C> | ListDefinition<T>, criteria?: Criteria<T>): Count | null;
@@ -0,0 +1,23 @@
1
+ "use client";
2
+ import { useListing } from "./useListing.js";
3
+ /**
4
+ * How many records of an entity a criteria holds, counted by the SERVER: «this member's
5
+ * payments (2)», the number of a smart button. `null` until it answers — and while it fails —,
6
+ * which web-ui's `SmartButton` reads as «—», never as 0.
7
+ *
8
+ * const pagos = useCount(payments, { selection: { field: "member_id", value: member.id } });
9
+ * <SmartButton icon={Wallet} label="Pagos" count={pagos?.value} onClick={…} />
10
+ *
11
+ * Context: an application counted «this member's payments» with a hook of its own over a list
12
+ * reference it built by hand. It is a listing of one row: the count is the one the server sends
13
+ * with every page (a floor, `exact: false`, when it stopped counting at its cap), and it follows
14
+ * the context and every write to the entity as any list does — a payment saved in a modal moves
15
+ * the number behind it. Never a page fetched to be counted here.
16
+ */
17
+ export function useCount(given, criteria) {
18
+ const listing = useListing(given, {
19
+ pageSize: 1,
20
+ ...(criteria === undefined ? {} : { criteria }),
21
+ });
22
+ return listing.status === "failed" ? null : listing.count;
23
+ }
@@ -1,4 +1,4 @@
1
- import { type Draft, type Entity, type EntityRef } from "@sincpro/client-framework";
1
+ import { type Draft, type Entity, type ResourceRef } from "@sincpro/client-framework";
2
2
  import type { AnyRecord, Meta } from "@sincpro/criteria";
3
3
  import { type Advice, type FieldState } from "../core/edit.js";
4
4
  /**
@@ -18,10 +18,10 @@ import { type Advice, type FieldState } from "../core/edit.js";
18
18
  * - **drafts** — an edit kept between requests (sincpro_framework's `Drafts`) comes back with
19
19
  * the record and is shown as restored; `keep()` stores the current one.
20
20
  * - **`Edit`** — an entity that declares `edit` speaks sincpro_framework's `Edit` on it for all
21
- * three: `keep()` is `save_draft`, `save()` is `save` — the record whole, the fields changed,
22
- * the draft version read and the stored version it started from — and `discard()` is
23
- * `discard`, which drops the draft on the server too. Without it, a save sends the changed
24
- * fields and the version to `save`.
21
+ * three: `keep()` is `save_draft`, `save()` is `save` — the fields changed, without what the
22
+ * framework writes (`editedOf`), the draft version read and the stored version it started
23
+ * from — and `discard()` is `discard`, which drops the draft on the server too. Without it,
24
+ * a save sends the changed fields and the version to `save`.
25
25
  * - **creating** — with no id it is a record that does not exist yet: it starts from the
26
26
  * defaults the model publishes, previews like any other, and `save()` sends it to the
27
27
  * entity's `create` route with an `Idempotency-Key` (a retry never creates two). When the
@@ -101,4 +101,4 @@ export type RecordReading<T> = RecordState<T> & {
101
101
  reload: () => void;
102
102
  edit: Editing;
103
103
  };
104
- export declare function useRecord<T extends AnyRecord>(entity: Entity<T>, opened: string | EntityRef): RecordReading<T>;
104
+ export declare function useRecord<T extends AnyRecord>(entity: Entity<T>, opened: string | ResourceRef): RecordReading<T>;
@@ -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, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, } from "../core/edit.js";
3
+ import { 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";
@@ -232,14 +232,17 @@ export function useRecord(entity, opened) {
232
232
  else
233
233
  setFailure(error);
234
234
  };
235
- // sincpro_framework's `Edit`: the record as the form holds it, whole; the fields changed; the
236
- // draft version read (`0`: none) — another tab that kept first wins —, and the stored version
237
- // the edit started from. Without an `action` it is the server's default, `save_draft`.
235
+ // sincpro_framework's `Edit`: what the form writes; the fields changed; the draft version read
236
+ // (`0`: none) — another tab that kept first wins —, and the stored version the edit started
237
+ // from. Without an `action` it is the server's default, `save_draft`.
238
238
  const editOf = (action) => ({
239
239
  id: keyNow(),
240
- // A new record carries what a person may write — never a field the framework writes (its
241
- // id, its stamps), which `Edit` refuses.
242
- values: isNew ? creationOf(state.meta, values) : values,
240
+ // Never a field the framework writes (its id, its stamps, a line's version), which `Edit`
241
+ // refuses: a new record carries what a person may write, a stored one what changed — the
242
+ // server puts it over what it stored and the caller's draft.
243
+ values: isNew
244
+ ? creationOf(state.meta, values)
245
+ : editedOf(state.meta, values, Object.keys(changed)),
243
246
  changed: Object.keys(changed),
244
247
  version: draft?.version ?? 0,
245
248
  ...(typeof version === "number" ? { origin_version: version } : {}),
@@ -0,0 +1,43 @@
1
+ import type { AnyRecord } from "@sincpro/criteria";
2
+ import { type Rehearsal } from "./useCommand.js";
3
+ import type { RecordReading } from "./useRecord.js";
4
+ /** An action on the record itself — what `RecordLifecycle` draws with `ActionButton`'s gesture:
5
+ * one that destroys can `rehearse` first; one that can be undone runs on the click. It answers
6
+ * `null` when done, `undefined` when refused. */
7
+ export type LifecycleAction = {
8
+ run: () => Promise<null | undefined>;
9
+ rehearse?: () => Promise<Rehearsal | undefined>;
10
+ busy: boolean;
11
+ error: unknown;
12
+ rehearsal: Rehearsal | null;
13
+ reset: () => void;
14
+ };
15
+ /** What the record's entity lets be done to the record itself, each only when declared. */
16
+ export type RecordLifecycleActions = {
17
+ /** sincpro_framework's `Delete`: gone, its fact kept in the history. Rehearsed first. */
18
+ delete?: LifecycleAction;
19
+ /** `Archive`: into the trash — out of every reading, nothing lost. On a record not archived. */
20
+ archive?: LifecycleAction;
21
+ /** `Restore`: out of the trash. On an archived record (`archived_at` set). */
22
+ restore?: LifecycleAction;
23
+ };
24
+ /**
25
+ * The record's own lifecycle, as actions of ONE stored record: what its entity declares of
26
+ * sincpro_framework's `Delete` (`entity.delete`) and its trash (`entity.archive`,
27
+ * `entity.restore`, client-framework 2.0) — `archive` on a record outside the trash, `restore` on
28
+ * one in it (`archived_at` set).
29
+ *
30
+ * const lifecycle = useRecordLifecycle(member);
31
+ * lifecycle.delete?.rehearse() // «Se eliminará Ana Pérez»: nothing touched
32
+ * lifecycle.delete?.run() // null: gone
33
+ *
34
+ * Context: an application wrote a Command and a Feature per aggregate to delete one, and a
35
+ * confirm of its own. The backend publishes the generic `Delete` (3.37): a `DryRunnable` whose
36
+ * dry run answers what would go, refused when the record moved past the version read
37
+ * (`origin_version`), answering nothing. So each action sends the version this screen read and
38
+ * a deletion rehearses with the same body: the confirmation is the server's word on THIS version.
39
+ * Putting a record in the trash, or taking it out, can be undone: it runs on the click. A new
40
+ * record, or one not read yet, has none. Over REST a `DELETE`'s fields travel in its query string
41
+ * (client-framework 1.12): sent in a body, a dry run would run the real delete.
42
+ */
43
+ export declare function useRecordLifecycle<T extends AnyRecord>(record: RecordReading<T>): RecordLifecycleActions;
@@ -0,0 +1,49 @@
1
+ "use client";
2
+ import { useRouteCommand, } from "./useCommand.js";
3
+ /**
4
+ * The record's own lifecycle, as actions of ONE stored record: what its entity declares of
5
+ * sincpro_framework's `Delete` (`entity.delete`) and its trash (`entity.archive`,
6
+ * `entity.restore`, client-framework 2.0) — `archive` on a record outside the trash, `restore` on
7
+ * one in it (`archived_at` set).
8
+ *
9
+ * const lifecycle = useRecordLifecycle(member);
10
+ * lifecycle.delete?.rehearse() // «Se eliminará Ana Pérez»: nothing touched
11
+ * lifecycle.delete?.run() // null: gone
12
+ *
13
+ * Context: an application wrote a Command and a Feature per aggregate to delete one, and a
14
+ * confirm of its own. The backend publishes the generic `Delete` (3.37): a `DryRunnable` whose
15
+ * dry run answers what would go, refused when the record moved past the version read
16
+ * (`origin_version`), answering nothing. So each action sends the version this screen read and
17
+ * a deletion rehearses with the same body: the confirmation is the server's word on THIS version.
18
+ * Putting a record in the trash, or taking it out, can be undone: it runs on the click. A new
19
+ * record, or one not read yet, has none. Over REST a `DELETE`'s fields travel in its query string
20
+ * (client-framework 1.12): sent in a body, a dry run would run the real delete.
21
+ */
22
+ export function useRecordLifecycle(record) {
23
+ const { entity } = record;
24
+ const deletion = useRouteCommand(entity.delete, entity.key);
25
+ const archival = useRouteCommand(entity.archive, entity.key);
26
+ const restoral = useRouteCommand(entity.restore, entity.key);
27
+ const stored = !record.isNew && record.status === "ready";
28
+ if (!stored)
29
+ return {};
30
+ const held = record.record;
31
+ const version = held["version"];
32
+ const checked = typeof version === "number" ? { origin_version: version } : {};
33
+ const archived = held["archived_at"] !== null && held["archived_at"] !== undefined;
34
+ const action = (command, rehearsed) => ({
35
+ run: () => command.run(record.id, checked),
36
+ ...(rehearsed ? { rehearse: () => command.rehearse(record.id, checked) } : {}),
37
+ busy: command.busy,
38
+ error: command.error,
39
+ rehearsal: command.rehearsal,
40
+ reset: command.reset,
41
+ });
42
+ return {
43
+ ...(entity.delete === undefined ? {} : { delete: action(deletion, true) }),
44
+ ...(entity.archive === undefined || archived ? {} : { archive: action(archival, false) }),
45
+ ...(entity.restore === undefined || !archived
46
+ ? {}
47
+ : { restore: action(restoral, false) }),
48
+ };
49
+ }
@@ -2,7 +2,11 @@
2
2
  * What a screen keeps of running one of the application's use cases.
3
3
  *
4
4
  * `run` answers what the use case answered, or `undefined` when it failed — the failure is in
5
- * `error`, for the screen to say (`explain`, `Refused`); it never throws at the screen.
5
+ * `error`, for the screen to say (`explain`, `Refused`); it never throws at the screen. So a use
6
+ * case that answers nothing answers `null`, never `undefined`: a `DELETE` the server answers
7
+ * with 204 resolves `null` through the transport, and a Feature hands that on instead of typing
8
+ * itself `void` — or «done» and «failed» look the same to the screen
9
+ * (Sincpro-SRL/sincpro_client_framework#51).
6
10
  */
7
11
  export type ServiceState<A extends unknown[], R> = {
8
12
  run: (...args: A) => Promise<R | undefined>;
@@ -0,0 +1,35 @@
1
+ import { type Entity } from "@sincpro/client-framework";
2
+ /** What a screen shows of a use case that reads: the answer to the arguments it asks with NOW. */
3
+ export type ServiceReading<R> = {
4
+ /** `loading` until the answer to these arguments arrives — never another's answer. */
5
+ status: "loading" | "ready" | "failed";
6
+ answer: R | undefined;
7
+ error: unknown;
8
+ /** Read again with the same arguments; the answer stays on screen until the new one. */
9
+ reload: () => void;
10
+ };
11
+ /** A use case as a screen reads with it: a method of a service, read from its bounded context. */
12
+ type UseCase<A extends unknown[], R> = (...args: A) => R | Promise<R>;
13
+ /**
14
+ * A use case that READS, run by the screen that shows it: on mount, again whenever its
15
+ * arguments change, when the process's context changes (another company), and when a write
16
+ * touches an entity it follows.
17
+ *
18
+ * const balance = useServiceReading(members.Accounts.balance, [{ member_id }], {
19
+ * follows: [payments],
20
+ * });
21
+ * balance.status === "ready" ? <Stat value={text.money(balance.answer)} /> : <Skeleton />
22
+ *
23
+ * Context: `useService` is an ACTION's — it runs when a person presses, never on mount — and a
24
+ * screen that read with it re-ran it by hand when a route param changed: easy to miss, and the
25
+ * screen kept showing the answer of the tab it left. Here a reading is keyed by its arguments
26
+ * (as JSON): the answer of other arguments is never shown — another member starts as `loading`,
27
+ * as `useRecord` does for another id — while reading the same ones again keeps the answer on
28
+ * screen until the new one lands. The last question wins: an answer to arguments no longer on
29
+ * screen is dropped. The use case is the latest the screen gave (a bounded context answers a new
30
+ * function per `scoped(…)`); its trace and report are the service's, never this hook's.
31
+ */
32
+ export declare function useServiceReading<A extends unknown[], R>(useCase: UseCase<A, R>, args: A, options?: {
33
+ follows?: readonly Entity[];
34
+ }): ServiceReading<Awaited<R>>;
35
+ export {};
@@ -0,0 +1,75 @@
1
+ "use client";
2
+ import { listRoute } from "@sincpro/client-framework";
3
+ import { touches } from "../core/changes.js";
4
+ import { useFramework } from "./context.js";
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
+ /**
16
+ * A use case that READS, run by the screen that shows it: on mount, again whenever its
17
+ * arguments change, when the process's context changes (another company), and when a write
18
+ * touches an entity it follows.
19
+ *
20
+ * const balance = useServiceReading(members.Accounts.balance, [{ member_id }], {
21
+ * follows: [payments],
22
+ * });
23
+ * balance.status === "ready" ? <Stat value={text.money(balance.answer)} /> : <Skeleton />
24
+ *
25
+ * Context: `useService` is an ACTION's — it runs when a person presses, never on mount — and a
26
+ * screen that read with it re-ran it by hand when a route param changed: easy to miss, and the
27
+ * screen kept showing the answer of the tab it left. Here a reading is keyed by its arguments
28
+ * (as JSON): the answer of other arguments is never shown — another member starts as `loading`,
29
+ * as `useRecord` does for another id — while reading the same ones again keeps the answer on
30
+ * screen until the new one lands. The last question wins: an answer to arguments no longer on
31
+ * screen is dropped. The use case is the latest the screen gave (a bounded context answers a new
32
+ * function per `scoped(…)`); its trace and report are the service's, never this hook's.
33
+ */
34
+ export function useServiceReading(useCase, args, options = {}) {
35
+ const { context, changes, entities } = useFramework();
36
+ const key = JSON.stringify(args);
37
+ const latest = useRef({ useCase, args });
38
+ latest.current = { useCase, args };
39
+ const [answered, setAnswered] = useState(null);
40
+ const [again, setAgain] = useState(0);
41
+ // A write anyone sends — a save, another use case, a panel beside — to what it follows.
42
+ const followed = (options.follows ?? [])
43
+ .map(routeOf)
44
+ .filter((route) => route !== undefined)
45
+ .join("\n");
46
+ useEffect(() => {
47
+ if (followed === "")
48
+ return;
49
+ const routes = followed.split("\n");
50
+ return changes.follow((change) => {
51
+ if (routes.some((route) => touches(change, route, entities)))
52
+ setAgain((n) => n + 1);
53
+ });
54
+ }, [changes, entities, followed]);
55
+ useEffect(() => {
56
+ let current = true;
57
+ const { useCase: read, args: now } = latest.current;
58
+ // Through the promise: a use case that throws before it answers is a failure like any other.
59
+ Promise.resolve()
60
+ .then(() => read(...now))
61
+ .then((answer) => {
62
+ if (current)
63
+ setAnswered({ key, status: "ready", answer: answer, error: null });
64
+ }, (error) => {
65
+ if (current)
66
+ setAnswered({ key, status: "failed", answer: undefined, error });
67
+ });
68
+ return () => void (current = false);
69
+ // `context` and `again` read again: another company, a followed write, a `reload()`.
70
+ }, [key, context, again]);
71
+ const reload = useCallback(() => setAgain((n) => n + 1), []);
72
+ if (answered === null || answered.key !== key)
73
+ return { status: "loading", answer: undefined, error: null, reload };
74
+ return { status: answered.status, answer: answered.answer, error: answered.error, reload };
75
+ }
@@ -0,0 +1,16 @@
1
+ /** What a value a screen holds reads as — each `null` when there is nothing to read. */
2
+ export type ValueTexts = {
3
+ number: (value: unknown) => string | null;
4
+ day: (value: unknown) => string | null;
5
+ instant: (value: unknown) => string | null;
6
+ money: (value: unknown) => string | null;
7
+ };
8
+ /**
9
+ * The texts of `numberTextOf`, `dayTextOf`, `instantTextOf` and `moneyTextOf`, in the
10
+ * provider's locale and on the zone it installed — for what a screen of its own holds outside a
11
+ * model: a total it added up, a balance a use case answered.
12
+ *
13
+ * const text = useTextOf();
14
+ * <Stat label="Saldo" value={text.money(balance) ?? "—"} />
15
+ */
16
+ export declare function useTextOf(): ValueTexts;
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ import { dayTextOf, instantTextOf, moneyTextOf, numberTextOf, } from "../core/present.js";
3
+ import { useFramework } from "./context.js";
4
+ import { useMemo } from "react";
5
+ /**
6
+ * The texts of `numberTextOf`, `dayTextOf`, `instantTextOf` and `moneyTextOf`, in the
7
+ * provider's locale and on the zone it installed — for what a screen of its own holds outside a
8
+ * model: a total it added up, a balance a use case answered.
9
+ *
10
+ * const text = useTextOf();
11
+ * <Stat label="Saldo" value={text.money(balance) ?? "—"} />
12
+ */
13
+ export function useTextOf() {
14
+ const { locale } = useFramework();
15
+ return useMemo(() => ({
16
+ number: (value) => numberTextOf(value, locale),
17
+ day: (value) => dayTextOf(value, locale),
18
+ instant: (value) => instantTextOf(value, locale),
19
+ money: (value) => moneyTextOf(value, locale),
20
+ }), [locale]);
21
+ }
@@ -18,6 +18,7 @@ export { EntityTags } from "./record/EntityTags.js";
18
18
  export { type LineColumn, type LineControl, type LinesLook, RecordLinesEditor, } from "./record/lines.js";
19
19
  export { type RecordOpening, RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
20
20
  export { countOf, factsOf, RecordLines } from "./record/record.js";
21
+ export { RecordLifecycle } from "./record/RecordLifecycle.js";
21
22
  export { RelatedList } from "./record/RelatedList.js";
22
23
  export { ServiceButton } from "./record/ServiceButton.js";
23
24
  export { cardOf, relationOf } from "./record/summary.js";
package/dist/web/index.js CHANGED
@@ -18,6 +18,7 @@ export { EntityTags } from "./record/EntityTags.js";
18
18
  export { RecordLinesEditor, } from "./record/lines.js";
19
19
  export { RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
20
20
  export { countOf, factsOf, RecordLines } from "./record/record.js";
21
+ export { RecordLifecycle } from "./record/RecordLifecycle.js";
21
22
  export { RelatedList } from "./record/RelatedList.js";
22
23
  export { ServiceButton } from "./record/ServiceButton.js";
23
24
  export { cardOf, relationOf } from "./record/summary.js";
@@ -89,6 +89,9 @@ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = Comma
89
89
  sums?: readonly string[] | false;
90
90
  /** The cuts this list offers by name: «sólo pagadas», «vencidas». */
91
91
  filters?: readonly NamedFilter<T>[];
92
+ /** The fields «Group by» offers, in this order — among those the model lets split the set.
93
+ * Without it, the list definition's, else every one the model does. */
94
+ groupable?: readonly string[];
92
95
  /**
93
96
  * Rows can be ticked. With `api`, what is ticked is PUBLISHED to the workspace
94
97
  * (`api.select`): a panel beside it follows the selection without knowing this list.
@@ -129,4 +132,4 @@ export type EntityFace<T> = {
129
132
  render: (set: ListSet<T>) => ReactNode;
130
133
  };
131
134
  export type View = "table" | "rows" | "board" | "sheet" | "pivot";
132
- export declare function EntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, selectable, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;
135
+ export declare function EntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, groupable: askedGroupable, selectable, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;
@@ -2,7 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { PICK_PARAM, QUERY_PARAM, TRAIL_PARAM, } from "@sincpro/client-framework";
4
4
  import { nameOf } from "@sincpro/criteria";
5
- import { RecordLink, useCrumbs } from "@sincpro/web-composer";
5
+ import { RecordLink, useCrumbs, usePhone } from "@sincpro/web-composer";
6
6
  import { frameworkCopy } from "../../core/copy.js";
7
7
  import { explain } from "../../core/explain.js";
8
8
  import { textOf, viewOf } from "../../core/present.js";
@@ -15,14 +15,16 @@ import { pilesOf } from "./groups.js";
15
15
  import { OpenInMenu, openOptions, targetsFor } from "./openIn.js";
16
16
  import { pivotOf } from "./pivot.js";
17
17
  import { over, presentationOf } from "./presentation.js";
18
- import { useRowCommands } from "./rowCommands.js";
18
+ import { RESTORE, useRowCommands, } from "./rowCommands.js";
19
19
  import { Button, Callout, List, Pagination, pathKey, RecordCard, SearchField, Tag, } from "@sincpro/web-ui";
20
+ import { RotateCcw } from "lucide-react";
20
21
  import { useEffect, useId, useMemo, useRef, useState } from "react";
21
22
  /** What `useCrumbs` reads when the list is not in a workspace: no trail, and nothing to follow. */
22
23
  const NO_TRAIL = [];
23
24
  const NO_WORKSPACE = {
24
25
  crumbs: () => NO_TRAIL,
25
26
  context: { subscribe: () => () => undefined },
27
+ layout: { phone: () => false, subscribe: () => () => undefined },
26
28
  };
27
29
  /** How many lists' trails are kept: the records opened from the last fifty lists page on. */
28
30
  const TRAILS = 50;
@@ -30,7 +32,7 @@ const TRAILS = 50;
30
32
  const NO_COMMANDS = [];
31
33
  /** What a list offers when nobody said: every face that needs no configuration. */
32
34
  const EVERY_VIEW = ["table", "rows", "board", "sheet"];
33
- export function EntityList({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search = "bar", sums, filters: askedFilters, selectable = false, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
35
+ export function EntityList({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search = "bar", sums, filters: askedFilters, groupable: askedGroupable, selectable = false, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
34
36
  // A named list (`defineList`) brings its own columns, filters, faces and words; what the
35
37
  // screen passes wins.
36
38
  const definition = listing.definition;
@@ -39,6 +41,7 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
39
41
  definition?.views ??
40
42
  (embedded ? ["table"] : pivotAsked === undefined ? EVERY_VIEW : [...EVERY_VIEW, "pivot"]);
41
43
  const filters = askedFilters ?? definition?.filters ?? [];
44
+ const groupable = askedGroupable ?? definition?.groupable;
42
45
  const title = askedTitle ?? definition?.title;
43
46
  const description = askedDescription ?? definition?.description;
44
47
  const copy = frameworkCopy().list;
@@ -148,6 +151,7 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
148
151
  // `useCrumbs`, not `api.crumbs()`: the crumb must follow a name given later (`setTitle`).
149
152
  // Without a workspace it reads a trail that never changes — a hook cannot be skipped.
150
153
  const following = useCrumbs(api ?? NO_WORKSPACE);
154
+ usePhone(api ?? NO_WORKSPACE); // where a row opens follows the mode (`targetsFor`)
151
155
  const trail = crumbs ?? (embedded || api === undefined ? undefined : following);
152
156
  const [ticked, setTicked] = useState(() => new Set());
153
157
  const tick = (next) => {
@@ -287,8 +291,21 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
287
291
  : {};
288
292
  const records = groups.buckets.reduce((sum, bucket) => sum + bucket.count, 0);
289
293
  // A row's actions: the entity's Commands, then whatever else the screen offers.
290
- const rowCommands = useRowCommands(listing, commands);
291
- const rowActions = commands.length === 0 && askedRowActions === undefined
294
+ // The trash (`trashOf`): each row is brought back from where it is, with the entity's own
295
+ // `restore` — it can be undone, so it runs on the click; the list reads again after.
296
+ const restoring = listing.definition?.trash === true && listing.entity.restore !== undefined;
297
+ const offered = useMemo(() => restoring
298
+ ? [
299
+ ...commands,
300
+ {
301
+ command: RESTORE,
302
+ label: frameworkCopy().record.restore,
303
+ icon: RotateCcw,
304
+ },
305
+ ]
306
+ : commands, [restoring, commands]);
307
+ const rowCommands = useRowCommands(listing, offered);
308
+ const rowActions = offered.length === 0 && askedRowActions === undefined
292
309
  ? undefined
293
310
  : (row) => [...rowCommands.rowActions(row), ...(askedRowActions?.(row) ?? [])];
294
311
  const refused = rowCommands.error === null ? null : explain(rowCommands.error);
@@ -315,7 +332,7 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
315
332
  }, filtered: listing.selection !== undefined || listing.text !== "", empty: {
316
333
  sentence: empty ?? copy.empty,
317
334
  whenFiltered: { sentence: copy.emptyFiltered },
318
- }, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }), children: [_jsxs(List.Bar, { children: [trail === undefined || trail.length === 0 ? null : _jsx(List.Crumbs, { crumbs: trail }), embedded ? null : (_jsx(List.Identity, { title: title ?? nameOf(meta, locale), ...(description === undefined ? {} : { description }) })), search === "bar" ? (_jsx(List.Search, { children: _jsx(EntitySearchBar, { listing: listing, filters: filters, groups: groups, ...(asked === "" ? {} : { seed: asked }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
335
+ }, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }), children: [_jsxs(List.Bar, { children: [trail === undefined || trail.length === 0 ? null : _jsx(List.Crumbs, { crumbs: trail }), embedded ? null : (_jsx(List.Identity, { title: title ?? nameOf(meta, locale), ...(description === undefined ? {} : { description }) })), search === "bar" ? (_jsx(List.Search, { children: _jsx(EntitySearchBar, { listing: listing, filters: filters, groups: groups, ...(groupable === undefined ? {} : { groupable }), ...(asked === "" ? {} : { seed: asked }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
319
336
  setDraft(next);
320
337
  // Emptied (or cleared with ×): the whole set again, at once.
321
338
  if (next === "" && listing.text !== "")
@@ -23,12 +23,15 @@ import type { Listing } from "../../react/useListing.js";
23
23
  * <List.Search><EntitySearchBar listing={listing} filters={…} /></List.Search>
24
24
  */
25
25
  export type { NamedFilter };
26
- export declare function EntitySearchBar<T extends AnyRecord>({ listing, filters, groups, seed, }: {
26
+ export declare function EntitySearchBar<T extends AnyRecord>({ listing, filters, groups, groupable: only, seed, }: {
27
27
  listing: Listing<T>;
28
28
  /** The cuts this set offers by name: «sólo pagadas», «vencidas». */
29
29
  filters?: readonly NamedFilter<T>[];
30
30
  /** The grouping of the same set (`useGroups(listing)`): offers «Group by». */
31
31
  groups?: Groups<T>;
32
+ /** The fields «Group by» offers, in this order — among those the model lets split the set.
33
+ * Without it, every one it does. */
34
+ groupable?: readonly string[];
32
35
  /** A text to start on, put as the literal search chip — what was typed in a picker whose
33
36
  * «Buscar más…» opened this list. */
34
37
  seed?: string;
@@ -8,14 +8,14 @@ import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, Grou
8
8
  import { useEffect, useMemo, useRef, useState } from "react";
9
9
  /** No grouping: one constant, so the control is not handed a new array on every render. */
10
10
  const NO_LEVELS = [];
11
- export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
11
+ export function EntitySearchBar({ listing, filters = [], groups, groupable: only, seed, }) {
12
12
  const copy = frameworkCopy().list;
13
13
  const { meta, locale } = listing;
14
14
  const [put, setPut] = useState([]);
15
15
  const [building, setBuilding] = useState(false);
16
16
  const model = useMemo(() => (meta ? modelOf(meta, locale) : undefined), [meta, locale]);
17
17
  const facets = useMemo(() => (meta ? facetsOf(meta, locale) : []), [meta, locale]);
18
- const groupable = useMemo(() => groupableOf(meta, locale), [meta, locale]);
18
+ const groupable = useMemo(() => groupableOf(meta, locale, only), [meta, locale, only]);
19
19
  const ui = useUiCopy();
20
20
  const seeded = useRef(false);
21
21
  useEffect(() => {
@@ -1,9 +1,19 @@
1
1
  import { type AnyRecord, type Bucket, type Meta } from "@sincpro/criteria";
2
2
  import type { GroupLevel } from "../../react/useGroups.js";
3
3
  import { type GroupableField, type Pile } from "@sincpro/web-ui";
4
- /** The fields the model says may split a set (`groupable`), in its words. The identity splits
5
- * into groups of one, and the version means nothing to a person: neither is offered. */
6
- export declare function groupableOf(meta: Meta | null, locale?: string): GroupableField[];
4
+ /**
5
+ * The fields the model says may split a set (`groupable`), in its words. The identity splits
6
+ * into groups of one, and the version means nothing to a person: neither is offered. With
7
+ * `only`, the screen's own choice among them, in its order — a name the model does not let
8
+ * split the set is still not offered.
9
+ *
10
+ * Context: sincpro_framework marks a field groupable by its TYPE, so a context's log offered
11
+ * «group by» `correlation_id` and `causation_id`. Which of them mean something to a person is
12
+ * the model's to say (ROADMAP); until it does, and wherever a screen knows better, the screen
13
+ * names them (`EntityList groupable`, `defineList({ groupable })`). Never a list of technical
14
+ * names kept here.
15
+ */
16
+ export declare function groupableOf(meta: Meta | null, locale?: string, only?: readonly string[]): GroupableField[];
7
17
  /**
8
18
  * The server's groups as piles, with the words a person reads, and each pile's group so that
9
19
  * opening one reads its rows. Rows sit only on the deepest level, once read.
@@ -13,16 +13,29 @@ import { dateLabel, pathKey, } from "@sincpro/web-ui";
13
13
  */
14
14
  /** The cuts a date offers, coarse to fine — web-ui orders the levels by them. */
15
15
  const DATE_GRAINS = ["year", "quarter", "month", "week", "day"];
16
- /** The fields the model says may split a set (`groupable`), in its words. The identity splits
17
- * into groups of one, and the version means nothing to a person: neither is offered. */
18
- export function groupableOf(meta, locale) {
16
+ /**
17
+ * The fields the model says may split a set (`groupable`), in its words. The identity splits
18
+ * into groups of one, and the version means nothing to a person: neither is offered. With
19
+ * `only`, the screen's own choice among them, in its order — a name the model does not let
20
+ * split the set is still not offered.
21
+ *
22
+ * Context: sincpro_framework marks a field groupable by its TYPE, so a context's log offered
23
+ * «group by» `correlation_id` and `causation_id`. Which of them mean something to a person is
24
+ * the model's to say (ROADMAP); until it does, and wherever a screen knows better, the screen
25
+ * names them (`EntityList groupable`, `defineList({ groupable })`). Never a list of technical
26
+ * names kept here.
27
+ */
28
+ export function groupableOf(meta, locale, only) {
19
29
  if (meta === null)
20
30
  return [];
21
- return Object.entries(meta.fields)
22
- .filter(([name, field]) => field.groupable === true &&
23
- field.kind === "scalar" &&
24
- name !== meta.identity &&
25
- name !== "version")
31
+ const names = only ?? Object.keys(meta.fields);
32
+ return names
33
+ .map((name) => [name, meta.fields[name]])
34
+ .filter((entry) => entry[1] !== undefined &&
35
+ entry[1].groupable === true &&
36
+ entry[1].kind === "scalar" &&
37
+ entry[0] !== meta.identity &&
38
+ entry[0] !== "version")
26
39
  .map(([name, field]) => ({
27
40
  field: name,
28
41
  label: labelOf(meta, name, locale),
@@ -12,7 +12,9 @@ import { type OpenTarget } from "@sincpro/web-ui";
12
12
  *
13
13
  * The places allowed depend on where the list is: from inside a modal, no modal (a second one
14
14
  * would replace the first and lose what was typed in it) — composer says where a view is
15
- * (`api.over`).
15
+ * (`api.over`). On a phone a side panel and a window both open as the page (composer 1.7,
16
+ * `api.layout`), so neither is offered: three entries that do the same are a lie. A screen that
17
+ * draws the menu follows the mode (`usePhone(api)`) so it redraws when it changes.
16
18
  */
17
19
  /** A record's form fits; a short task (register a payment) passes its own size. */
18
20
  export declare const RECORD_SIZE: {
@@ -20,7 +22,7 @@ export declare const RECORD_SIZE: {
20
22
  readonly h: 560;
21
23
  };
22
24
  /** Where a record may open from this view, the default first. */
23
- export declare function targetsFor(api: Pick<WorkspaceApi, "over">): readonly OpenTarget[];
25
+ export declare function targetsFor(api: Pick<WorkspaceApi, "over"> & Partial<Pick<WorkspaceApi, "layout">>): readonly OpenTarget[];
24
26
  /** web-ui's target as composer's options. Destinations share their names, so only the size is
25
27
  * added — to the two that have one. */
26
28
  export declare function openOptions(to: OpenTarget, size?: {