@sincpro/web-framework 3.5.0 → 3.7.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 (63) hide show
  1. package/README.md +5 -0
  2. package/dist/core/command.d.ts +16 -0
  3. package/dist/core/command.js +17 -0
  4. package/dist/core/copy.d.ts +16 -0
  5. package/dist/core/copy.js +26 -0
  6. package/dist/core/crumbs.d.ts +4 -0
  7. package/dist/core/crumbs.js +24 -0
  8. package/dist/core/history.d.ts +16 -4
  9. package/dist/core/history.js +20 -17
  10. package/dist/core/index.d.ts +4 -3
  11. package/dist/core/index.js +3 -2
  12. package/dist/core/list.d.ts +12 -0
  13. package/dist/core/list.js +14 -0
  14. package/dist/core/present.d.ts +12 -0
  15. package/dist/core/present.js +39 -0
  16. package/dist/react/index.d.ts +2 -0
  17. package/dist/react/index.js +2 -0
  18. package/dist/react/useBatchCommand.d.ts +50 -0
  19. package/dist/react/useBatchCommand.js +124 -0
  20. package/dist/react/useCommand.js +3 -4
  21. package/dist/react/useSelection.d.ts +37 -0
  22. package/dist/react/useSelection.js +40 -0
  23. package/dist/web/index.d.ts +7 -3
  24. package/dist/web/index.js +7 -3
  25. package/dist/web/list/BatchProgress.d.ts +16 -0
  26. package/dist/web/list/BatchProgress.js +40 -0
  27. package/dist/web/list/EntityList.d.ts +31 -8
  28. package/dist/web/list/EntityList.js +122 -39
  29. package/dist/web/list/EntitySearchBar.d.ts +9 -0
  30. package/dist/web/list/EntitySearchBar.js +15 -5
  31. package/dist/web/list/columns.d.ts +4 -1
  32. package/dist/web/list/columns.js +14 -6
  33. package/dist/web/list/dock.d.ts +19 -0
  34. package/dist/web/list/dock.js +20 -0
  35. package/dist/web/list/groups.d.ts +7 -1
  36. package/dist/web/list/groups.js +25 -5
  37. package/dist/web/list/pivot.d.ts +5 -1
  38. package/dist/web/list/pivot.js +28 -11
  39. package/dist/web/list/records.d.ts +100 -0
  40. package/dist/web/list/records.js +219 -0
  41. package/dist/web/list/search.d.ts +0 -17
  42. package/dist/web/list/search.js +33 -5
  43. package/dist/web/record/ActionButton.d.ts +25 -0
  44. package/dist/web/record/ActionButton.js +39 -18
  45. package/dist/web/record/CommandButton.d.ts +22 -2
  46. package/dist/web/record/CommandButton.js +43 -17
  47. package/dist/web/record/EntityTags.d.ts +5 -2
  48. package/dist/web/record/EntityTags.js +34 -12
  49. package/dist/web/record/RecordLifecycle.d.ts +28 -7
  50. package/dist/web/record/RecordLifecycle.js +63 -10
  51. package/dist/web/record/ServiceButton.d.ts +20 -2
  52. package/dist/web/record/ServiceButton.js +35 -27
  53. package/dist/web/record/dock.d.ts +31 -0
  54. package/dist/web/record/dock.js +14 -0
  55. package/dist/web/record/opening.d.ts +6 -2
  56. package/dist/web/record/record.d.ts +14 -3
  57. package/dist/web/record/record.js +39 -6
  58. package/dist/web/workspace/SincproApp.js +13 -2
  59. package/dist/web/workspace/composer.d.ts +1 -1
  60. package/dist/web/workspace/composer.js +23 -25
  61. package/dist/web/workspace/record.d.ts +8 -3
  62. package/dist/web/workspace/record.js +20 -16
  63. package/package.json +9 -9
@@ -3,6 +3,7 @@ import type { AnyRecord } from "@sincpro/criteria";
3
3
  import { type AnswerOf } from "../../react/useCommand.js";
4
4
  import { type ActionDialog } from "./ActionButton.js";
5
5
  import { type AskField } from "./ask.js";
6
+ import { type ActionLook, type DockedAction } from "./dock.js";
6
7
  /**
7
8
  * An entity's Command as a button: sent as it is, over the screens' transport.
8
9
  *
@@ -15,7 +16,8 @@ import { type AskField } from "./ask.js";
15
16
  * record's fields of the same name, filled from `record`, and what is filled goes in the body
16
17
  * beside `body`.
17
18
  */
18
- export declare function CommandButton<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>({ entity, command, id, body, label, destructive, role, disabled, ask, record, dialog, onDone, }: {
19
+ /** What a Command's button and dock action are given. */
20
+ export type CommandActionProps<T extends AnyRecord, R, C extends CommandBodies, N extends keyof C & string, A extends CommandAnswers> = {
19
21
  entity: Entity<T, C, A>;
20
22
  /** One the entity declares; a typed entity takes only its own names. */
21
23
  command: N;
@@ -25,7 +27,6 @@ export declare function CommandButton<T extends AnyRecord, R = unknown, C extend
25
27
  label: string;
26
28
  /** Asks the server what it would do before doing it. */
27
29
  destructive?: boolean;
28
- role?: "primary" | "secondary" | "ghost";
29
30
  /** Not offered right now — «Mover» with no other tenant chosen. The server still decides. */
30
31
  disabled?: boolean;
31
32
  /** The fields it asks for before it runs, sent in its body: `["areas"]`. */
@@ -35,4 +36,23 @@ export declare function CommandButton<T extends AnyRecord, R = unknown, C extend
35
36
  /** What its window says — its title (the label without «…» by default), a sentence under it. */
36
37
  dialog?: ActionDialog;
37
38
  onDone?: (answer: AnswerOf<R, A, N>) => void;
39
+ };
40
+ export declare function CommandButton<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>({ role, ...props }: CommandActionProps<T, R, C, N, A> & {
41
+ role?: "primary" | "secondary" | "ghost";
38
42
  }): import("react").JSX.Element;
43
+ /**
44
+ * An entity's Command as an action of a dock — what `CommandButton` is as a button, for web-ui's
45
+ * `Record.Dock`: the view style draws it, and its window is put on the screen by whoever uses
46
+ * it. One that destroys (`destructive`: asked first what it would do) is drawn as such — apart,
47
+ * in red — unless `danger` says otherwise.
48
+ *
49
+ * const anular = useCommandAction({
50
+ * entity: invoices, command: "cancel", id: invoice.id, label: "Anular", destructive: true,
51
+ * });
52
+ * <Record.Dock actions={[confirmar.action, anular.action]} />
53
+ * {anular.dialog}
54
+ */
55
+ export declare function useCommandAction<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>({ icon, primary, danger, tucked, shortcut, hint, actionId, ...props }: CommandActionProps<T, R, C, N, A> & Omit<ActionLook, "id"> & {
56
+ /** The dock's id for it — the record's is `id`. Defaults to the label. */
57
+ actionId?: string;
58
+ }): DockedAction;
@@ -4,21 +4,46 @@ import {} from "@sincpro/client-framework";
4
4
  import { entityFor } from "../../core/relation.js";
5
5
  import { useFramework } from "../../react/context.js";
6
6
  import { useCommand } from "../../react/useCommand.js";
7
- import { ActionButton, } from "./ActionButton.js";
8
- import { askFormOf } from "./ask.js";
7
+ import { ActionButton, useActionGesture, } from "./ActionButton.js";
8
+ import { askFormOf, } from "./ask.js";
9
+ import { dockedOf, } from "./dock.js";
10
+ export function CommandButton({ role = "secondary", ...props }) {
11
+ const { action, form } = useCommandBehind(props);
12
+ return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), ...(props.dialog === undefined ? {} : { dialog: props.dialog }), action: action, label: props.label, role: role, disabled: props.disabled ?? false, ...(props.onDone === undefined ? {} : { onDone: props.onDone }) }));
13
+ }
9
14
  /**
10
- * An entity's Command as a button: sent as it is, over the screens' transport.
11
- *
12
- * Context: the gesture is `ActionButton`'s — run on the click, or (`destructive`) ask the
13
- * server's dry run first and show what it would do; a refusal where it happened. An action that is
14
- * one of the application's own use cases — logic of its own, composed, traced as
15
- * `<context>/<Service>` — is a `ServiceButton`.
15
+ * An entity's Command as an action of a dock — what `CommandButton` is as a button, for web-ui's
16
+ * `Record.Dock`: the view style draws it, and its window is put on the screen by whoever uses
17
+ * it. One that destroys (`destructive`: asked first what it would do) is drawn as such — apart,
18
+ * in red — unless `danger` says otherwise.
16
19
  *
17
- * One that needs input names the fields it asks for (`ask`): a dialog draws them as the
18
- * record's fields of the same name, filled from `record`, and what is filled goes in the body
19
- * beside `body`.
20
+ * const anular = useCommandAction({
21
+ * entity: invoices, command: "cancel", id: invoice.id, label: "Anular", destructive: true,
22
+ * });
23
+ * <Record.Dock actions={[confirmar.action, anular.action]} />
24
+ * {anular.dialog}
20
25
  */
21
- export function CommandButton({ entity, command, id, body, label, destructive = false, role = "secondary", disabled = false, ask, record, dialog, onDone, }) {
26
+ export function useCommandAction({ icon, primary, danger, tucked, shortcut, hint, actionId, ...props }) {
27
+ const { action, form } = useCommandBehind(props);
28
+ const gesture = useActionGesture(action, {
29
+ label: props.label,
30
+ ...(form === undefined ? {} : { ask: form }),
31
+ ...(props.dialog === undefined ? {} : { dialog: props.dialog }),
32
+ ...(props.onDone === undefined ? {} : { onDone: props.onDone }),
33
+ });
34
+ const look = {
35
+ icon,
36
+ primary,
37
+ danger: danger ?? props.destructive,
38
+ tucked,
39
+ shortcut,
40
+ hint,
41
+ id: actionId,
42
+ };
43
+ return dockedOf(gesture, props.label, look, props.disabled);
44
+ }
45
+ /** What runs behind a Command's button or dock action: sending it, its dry run, what it asks. */
46
+ function useCommandBehind({ entity, command, id, body, destructive = false, ask, record, }) {
22
47
  const sending = useCommand(entity, command);
23
48
  const { metas, entities, locale } = useFramework();
24
49
  const form = ask === undefined
@@ -30,14 +55,15 @@ export function CommandButton({ entity, command, id, body, label, destructive =
30
55
  entityFor: (target) => entityFor(entities, target, metas.get),
31
56
  });
32
57
  const bodyWith = (asked) => (asked === undefined ? body : { ...body, ...asked });
33
- return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), ...(dialog === undefined ? {} : { dialog }), action: {
58
+ return {
59
+ action: {
34
60
  run: (asked) => sending.run(id, bodyWith(asked)),
35
- ...(destructive
36
- ? { rehearse: (asked) => sending.rehearse(id, bodyWith(asked)) }
37
- : {}),
61
+ ...(destructive ? { rehearse: (asked) => sending.rehearse(id, bodyWith(asked)) } : {}),
38
62
  busy: sending.busy,
39
63
  error: sending.error,
40
64
  rehearsal: sending.rehearsal,
41
65
  reset: sending.reset,
42
- }, label: label, role: role, disabled: disabled, ...(onDone === undefined ? {} : { onDone }) }));
66
+ },
67
+ form,
68
+ };
43
69
  }
@@ -15,8 +15,11 @@ import { type OpenTarget } from "@sincpro/web-ui";
15
15
  *
16
16
  * Inside a workspace, opening a chip and «Buscar más…» are the workspace's (`RecordOpening`),
17
17
  * as for a many2one: a chip opens where the workspace puts it, and «Buscar más…» is the
18
- * entity's list opened to choose, offering neither what `criteria` leaves out nor the chips
19
- * already on — the record answered there is added. `onOpen` / `onBrowseAll` replace either.
18
+ * entity's list opened to choose SEVERAL (`chooseMany`), offering neither what `criteria` leaves
19
+ * out nor the chips already on — what was ticked there, or every record it matches («Elegir los
20
+ * 37 que coinciden»), is added, at most `BATCH_LIMIT` at once (past it nothing is added and a
21
+ * notice says why). A workspace that cannot choose several adds the one answered (`choose`).
22
+ * `onOpen` / `onBrowseAll` replace either.
20
23
  * Without a workspace a chip is a value.
21
24
  *
22
25
  * <EntityTags entity={people} value={followers} onChange={setFollowers} />
@@ -1,12 +1,14 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import {} from "@sincpro/client-framework";
3
+ import { keysOf, listRoute } from "@sincpro/client-framework";
4
4
  import { isList } from "../../core/list.js";
5
5
  import { useFramework } from "../../react/context.js";
6
+ import { BATCH_LIMIT } from "../../react/useBatchCommand.js";
6
7
  import { excluding, useLookup } from "../../react/useLookup.js";
7
8
  import { presentationOf } from "../list/presentation.js";
9
+ import { refusalNotice } from "../list/records.js";
8
10
  import { chooserScopeOf, useRecordOpening } from "./opening.js";
9
- import { TagsField } from "@sincpro/web-ui";
11
+ import { TagsField, useToastIfAny } from "@sincpro/web-ui";
10
12
  import { useRef } from "react";
11
13
  /**
12
14
  * A many2many: put SEVERAL records of an entity on this one — the followers of an invoice,
@@ -21,15 +23,19 @@ import { useRef } from "react";
21
23
  *
22
24
  * Inside a workspace, opening a chip and «Buscar más…» are the workspace's (`RecordOpening`),
23
25
  * as for a many2one: a chip opens where the workspace puts it, and «Buscar más…» is the
24
- * entity's list opened to choose, offering neither what `criteria` leaves out nor the chips
25
- * already on — the record answered there is added. `onOpen` / `onBrowseAll` replace either.
26
+ * entity's list opened to choose SEVERAL (`chooseMany`), offering neither what `criteria` leaves
27
+ * out nor the chips already on — what was ticked there, or every record it matches («Elegir los
28
+ * 37 que coinciden»), is added, at most `BATCH_LIMIT` at once (past it nothing is added and a
29
+ * notice says why). A workspace that cannot choose several adds the one answered (`choose`).
30
+ * `onOpen` / `onBrowseAll` replace either.
26
31
  * Without a workspace a chip is a value.
27
32
  *
28
33
  * <EntityTags entity={people} value={followers} onChange={setFollowers} />
29
34
  */
30
35
  export function EntityTags({ entity, value, onChange, criteria, onOpen, openTarget, onBrowseAll, placeholder, disabled, "aria-label": ariaLabel, }) {
31
- const { metas } = useFramework();
36
+ const { metas, transport } = useFramework();
32
37
  const opening = useRecordOpening();
38
+ const toast = useToastIfAny();
33
39
  const base = isList(entity) ? entity.entity : entity;
34
40
  // «Buscar más…» answers after the chooser closes: it adds to the chips on screen THEN.
35
41
  const now = useRef(value);
@@ -38,14 +44,30 @@ export function EntityTags({ entity, value, onChange, criteria, onOpen, openTarg
38
44
  (opening === null
39
45
  ? undefined
40
46
  : (id, to) => opening.open(base.ref(id), to));
41
- const choose = opening?.choose;
47
+ /** Added after the chips on screen THEN, each once, in the order they came. */
48
+ const add = (keys) => {
49
+ const fresh = keys.filter((key) => !now.current.includes(key));
50
+ if (fresh.length > 0)
51
+ onChange([...now.current, ...fresh]);
52
+ };
53
+ /** The keys of what a chooser of several answered — in hand, or read once with a ceiling. */
54
+ const addChosen = (selection) => {
55
+ const meta = metas.get(base.key);
56
+ keysOf(selection, {
57
+ transport,
58
+ route: listRoute(base.list),
59
+ identity: meta?.get_id || meta?.identity || "id",
60
+ limit: BATCH_LIMIT,
61
+ }).then(add, (failure) => toast?.show(refusalNotice(failure)));
62
+ };
63
+ const scope = () => chooserScopeOf(entity, excluding(criteria, value, metas.get(base.key)));
64
+ const { choose, chooseMany } = opening ?? {};
42
65
  const browseAll = onBrowseAll ??
43
- (choose === undefined
44
- ? undefined
45
- : (query) => choose(base, (id) => {
46
- if (!now.current.includes(id))
47
- onChange([...now.current, id]);
48
- }, query, chooserScopeOf(entity, excluding(criteria, value, metas.get(base.key)))));
66
+ (chooseMany !== undefined
67
+ ? (query) => chooseMany(base, addChosen, query, scope())
68
+ : choose === undefined
69
+ ? undefined
70
+ : (query) => choose(base, (id) => add([id]), query, scope()));
49
71
  const lookup = useLookup(entity, {
50
72
  ...(criteria === undefined ? {} : { criteria }),
51
73
  values: value,
@@ -1,5 +1,9 @@
1
1
  import type { AnyRecord } from "@sincpro/criteria";
2
2
  import type { RecordReading } from "../../react/useRecord.js";
3
+ import { type DockAction } from "@sincpro/web-ui";
4
+ import type { ReactNode } from "react";
5
+ /** What the record's lifecycle did: after `delete` and `archive` it is out of every reading. */
6
+ export type LifecycleDone = "delete" | "archive" | "restore";
3
7
  /**
4
8
  * The record's own lifecycle as buttons — «Mover a la papelera» / «Restaurar» and «Eliminar»,
5
9
  * each when its entity declares sincpro_framework's `Archive`, `Restore`, `Delete` — a deletion
@@ -11,13 +15,30 @@ import type { RecordReading } from "../../react/useRecord.js";
11
15
  * <RecordLifecycle record={member} onDone={() => api.close()} />
12
16
  * </Record.Actions>
13
17
  *
14
- * Context: `EntityRecord` draws it; a screen of its own draws it the same, or drops to
15
- * `useRecordLifecycle` and draws its own. What happens after is the screen's (`onDone`): in a
16
- * workspace the surface closes — the record is gone —, and every list that showed it reads
17
- * again by itself (the write is announced).
18
+ * Context: `EntityRecord` draws it; a screen of its own draws it the same, or takes them as a
19
+ * dock's actions (`useRecordLifecycleActions`), or drops to `useRecordLifecycle` and draws its
20
+ * own. What happens after is the screen's (`onDone`): in a workspace the surface closes — the
21
+ * record is gone —, and every list that showed it reads again by itself (the write is announced).
18
22
  */
19
23
  export declare function RecordLifecycle<T extends AnyRecord>({ record, onDone, }: {
20
24
  record: RecordReading<T>;
21
- /** Done: which action — after `delete` and `archive` the record is out of every reading. */
22
- onDone?: (action: "delete" | "archive" | "restore") => void;
23
- }): import("react").JSX.Element | null;
25
+ onDone?: (done: LifecycleDone) => void;
26
+ }): import("react").JSX.Element;
27
+ /** The lifecycle's actions as the rail's buttons — beside actions a screen drew by hand. */
28
+ export declare function LifecycleButtons({ actions }: {
29
+ actions: readonly DockAction[];
30
+ }): import("react").JSX.Element;
31
+ /**
32
+ * The record's own lifecycle as actions of a dock (web-ui's `Record.Dock`) — what
33
+ * `RecordLifecycle` draws as buttons: the view style draws them (the rail's buttons, or the
34
+ * modern style's floating pill, «Eliminar» apart and in red), and their window — what a deletion
35
+ * would do, a refusal — is put on the screen by whoever uses them.
36
+ *
37
+ * const lifecycle = useRecordLifecycleActions(member, () => api.close());
38
+ * <Record.Dock actions={[...own, ...lifecycle.actions]} />
39
+ * {lifecycle.dialog}
40
+ */
41
+ export declare function useRecordLifecycleActions<T extends AnyRecord>(record: RecordReading<T>, onDone?: (done: LifecycleDone) => void): {
42
+ actions: readonly DockAction[];
43
+ dialog: ReactNode;
44
+ };
@@ -1,8 +1,19 @@
1
1
  "use client";
2
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { frameworkCopy } from "../../core/copy.js";
4
4
  import { useRecordLifecycle } from "../../react/useRecordLifecycle.js";
5
- import { ActionButton } from "./ActionButton.js";
5
+ import { useActionGesture, } from "./ActionButton.js";
6
+ import { dockedOf } from "./dock.js";
7
+ import { Button } from "@sincpro/web-ui";
8
+ import { Archive, RotateCcw, Trash2 } from "lucide-react";
9
+ /** In place of an action the entity does not declare: never offered, never started. */
10
+ const NOT_DECLARED = {
11
+ run: async () => undefined,
12
+ busy: false,
13
+ error: null,
14
+ rehearsal: null,
15
+ reset: () => { },
16
+ };
6
17
  /**
7
18
  * The record's own lifecycle as buttons — «Mover a la papelera» / «Restaurar» and «Eliminar»,
8
19
  * each when its entity declares sincpro_framework's `Archive`, `Restore`, `Delete` — a deletion
@@ -14,16 +25,58 @@ import { ActionButton } from "./ActionButton.js";
14
25
  * <RecordLifecycle record={member} onDone={() => api.close()} />
15
26
  * </Record.Actions>
16
27
  *
17
- * Context: `EntityRecord` draws it; a screen of its own draws it the same, or drops to
18
- * `useRecordLifecycle` and draws its own. What happens after is the screen's (`onDone`): in a
19
- * workspace the surface closes — the record is gone —, and every list that showed it reads
20
- * again by itself (the write is announced).
28
+ * Context: `EntityRecord` draws it; a screen of its own draws it the same, or takes them as a
29
+ * dock's actions (`useRecordLifecycleActions`), or drops to `useRecordLifecycle` and draws its
30
+ * own. What happens after is the screen's (`onDone`): in a workspace the surface closes — the
31
+ * record is gone —, and every list that showed it reads again by itself (the write is announced).
21
32
  */
22
33
  export function RecordLifecycle({ record, onDone, }) {
34
+ const lifecycle = useRecordLifecycleActions(record, onDone);
35
+ return (_jsxs(_Fragment, { children: [_jsx(LifecycleButtons, { actions: lifecycle.actions }), lifecycle.dialog] }));
36
+ }
37
+ /** The lifecycle's actions as the rail's buttons — beside actions a screen drew by hand. */
38
+ export function LifecycleButtons({ actions }) {
39
+ return (_jsx(_Fragment, { children: actions.map((one) => (_jsx(Button, { size: "sm", role: "secondary", disabled: one.disabled ?? false, onClick: () => one.onSelect?.(), children: one.label }, one.id))) }));
40
+ }
41
+ /**
42
+ * The record's own lifecycle as actions of a dock (web-ui's `Record.Dock`) — what
43
+ * `RecordLifecycle` draws as buttons: the view style draws them (the rail's buttons, or the
44
+ * modern style's floating pill, «Eliminar» apart and in red), and their window — what a deletion
45
+ * would do, a refusal — is put on the screen by whoever uses them.
46
+ *
47
+ * const lifecycle = useRecordLifecycleActions(member, () => api.close());
48
+ * <Record.Dock actions={[...own, ...lifecycle.actions]} />
49
+ * {lifecycle.dialog}
50
+ */
51
+ export function useRecordLifecycleActions(record, onDone) {
23
52
  const lifecycle = useRecordLifecycle(record);
24
53
  const copy = frameworkCopy().record;
25
- const shown = ["archive", "restore", "delete"].filter((one) => lifecycle[one] !== undefined);
26
- if (shown.length === 0)
27
- return null;
28
- return (_jsx(_Fragment, { children: shown.map((one) => (_jsx(ActionButton, { action: lifecycle[one], label: copy[one], onDone: () => onDone?.(one) }, one))) }));
54
+ // Always the three, in this order: a hook is not skipped. One not declared is not offered.
55
+ const archive = useActionGesture(lifecycle.archive ?? NOT_DECLARED, {
56
+ label: copy.archive,
57
+ onDone: () => onDone?.("archive"),
58
+ });
59
+ const restore = useActionGesture(lifecycle.restore ?? NOT_DECLARED, {
60
+ label: copy.restore,
61
+ onDone: () => onDone?.("restore"),
62
+ });
63
+ const remove = useActionGesture(lifecycle.delete ?? NOT_DECLARED, {
64
+ label: copy.delete,
65
+ onDone: () => onDone?.("delete"),
66
+ });
67
+ const offered = [
68
+ lifecycle.archive === undefined
69
+ ? null
70
+ : dockedOf(archive, copy.archive, { id: "archive", icon: Archive }),
71
+ lifecycle.restore === undefined
72
+ ? null
73
+ : dockedOf(restore, copy.restore, { id: "restore", icon: RotateCcw }),
74
+ lifecycle.delete === undefined
75
+ ? null
76
+ : dockedOf(remove, copy.delete, { id: "delete", icon: Trash2, danger: true }),
77
+ ].filter((one) => one !== null);
78
+ return {
79
+ actions: offered.map((one) => one.action),
80
+ dialog: offered.map((one) => one.dialog),
81
+ };
29
82
  }
@@ -3,6 +3,7 @@ import type { AnyRecord } from "@sincpro/criteria";
3
3
  import type { Rehearsal } from "../../react/useCommand.js";
4
4
  import { type ActionDialog, type Asked } from "./ActionButton.js";
5
5
  import { type AskField } from "./ask.js";
6
+ import { type ActionLook, type DockedAction } from "./dock.js";
6
7
  /**
7
8
  * One of the application's use cases as a button — its Feature or ApplicationService, run on its
8
9
  * bounded context.
@@ -28,13 +29,13 @@ import { type AskField } from "./ask.js";
28
29
  * <ServiceButton label="Delegar áreas" entity={cuentas} record={cuenta} ask={["areas"]}
29
30
  * run={(asked) => cuentaBoundedContext.execute(new CommandDelegarAreas(cuenta.id, asked.areas))} />
30
31
  */
31
- export declare function ServiceButton<R>({ label, run, rehearse, role, disabled, ask, entity, record, dialog, onDone, }: {
32
+ /** What a use case's button and dock action are given. */
33
+ export type ServiceActionProps<R> = {
32
34
  label: string;
33
35
  /** The use case, executed on its bounded context — with what was asked, when it asks. */
34
36
  run: (asked: Asked) => Promise<R>;
35
37
  /** The same use case run dry — what it would do, nothing touched —, asked before `run`. */
36
38
  rehearse?: (asked: Asked) => Promise<Rehearsal>;
37
- role?: "primary" | "secondary" | "ghost";
38
39
  /** Not offered right now. The use case still decides. */
39
40
  disabled?: boolean;
40
41
  /** The fields it asks for before it runs: `["areas"]`. */
@@ -46,4 +47,21 @@ export declare function ServiceButton<R>({ label, run, rehearse, role, disabled,
46
47
  /** What its window says — its title (the label without «…» by default), a sentence under it. */
47
48
  dialog?: ActionDialog;
48
49
  onDone?: (answer: R) => void;
50
+ };
51
+ export declare function ServiceButton<R>({ role, ...props }: ServiceActionProps<R> & {
52
+ role?: "primary" | "secondary" | "ghost";
49
53
  }): import("react").JSX.Element;
54
+ /**
55
+ * One of the application's use cases as an action of a dock — what `ServiceButton` is as a
56
+ * button, for web-ui's `Record.Dock`: the view style draws it (a rail's button, or the modern
57
+ * style's floating pill), and its window — what it asks, what it would do, a refusal — is put
58
+ * on the screen by whoever uses it.
59
+ *
60
+ * const aprobar = useServiceAction({
61
+ * label: "Aprobar", icon: Check, primary: true,
62
+ * run: () => pagosBoundedContext.execute(new CommandAprobarPago(pago.id)),
63
+ * });
64
+ * <Record.Dock actions={[aprobar.action]} />
65
+ * {aprobar.dialog}
66
+ */
67
+ export declare function useServiceAction<R>({ icon, primary, danger, tucked, shortcut, hint, id, ...props }: ServiceActionProps<R> & ActionLook): DockedAction;
@@ -3,38 +3,43 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { entityFor } from "../../core/relation.js";
4
4
  import { useFrameworkIfAny } from "../../react/context.js";
5
5
  import { useService } from "../../react/useService.js";
6
- import { ActionButton, } from "./ActionButton.js";
7
- import { askFormOf } from "./ask.js";
6
+ import { ActionButton, useActionGesture, } from "./ActionButton.js";
7
+ import { askFormOf, } from "./ask.js";
8
+ import { dockedOf, } from "./dock.js";
8
9
  /** What the button runs when there is no dry run: nothing. */
9
10
  const NO_REHEARSAL = async (_asked) => undefined;
10
11
  /** What a use case that asks nothing receives. */
11
12
  const NOTHING_ASKED = {};
13
+ export function ServiceButton({ role = "secondary", ...props }) {
14
+ const { action, form } = useServiceBehind(props);
15
+ return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), ...(props.dialog === undefined ? {} : { dialog: props.dialog }), action: action, label: props.label, role: role, disabled: props.disabled ?? false, ...(props.onDone === undefined ? {} : { onDone: props.onDone }) }));
16
+ }
12
17
  /**
13
- * One of the application's use cases as a button — its Feature or ApplicationService, run on its
14
- * bounded context.
15
- *
16
- * <ServiceButton
17
- * label="Cancelar"
18
- * run={() => projectBoundedContext.execute(new CommandCancelIssue(issue.id))}
19
- * rehearse={() => projectBoundedContext.execute(new CommandCancelIssue(issue.id, true))}
20
- * />
21
- *
22
- * Context: an action of an application is a use case — its logic, its composition, its span
23
- * `<context>/<Service>`, its request carrying the run's trace to the server —, never a request a
24
- * screen sends; what the screen adds is the state of running it (`useService`). The gesture is
25
- * `CommandButton`'s, drawn once by `ActionButton`: run on the click, off while it runs, a refusal
26
- * where it happened; and an action that destroys asks first (`rehearse`, the use case run dry)
27
- * and shows what it would do. What it changed, every screen hears by itself: the use case's
28
- * client announces its write (`processChanges`), so `onDone` is for what only this screen does
29
- * next — a toast, closing a window —, never to read again.
18
+ * One of the application's use cases as an action of a dock — what `ServiceButton` is as a
19
+ * button, for web-ui's `Record.Dock`: the view style draws it (a rail's button, or the modern
20
+ * style's floating pill), and its window — what it asks, what it would do, a refusal — is put
21
+ * on the screen by whoever uses it.
30
22
  *
31
- * A use case that needs input names the fields it asks for (`ask`), read as `entity`'s fields of
32
- * the same name and filled from `record`; `run` and `rehearse` receive what was filled.
33
- *
34
- * <ServiceButton label="Delegar áreas" entity={cuentas} record={cuenta} ask={["areas"]}
35
- * run={(asked) => cuentaBoundedContext.execute(new CommandDelegarAreas(cuenta.id, asked.areas))} />
23
+ * const aprobar = useServiceAction({
24
+ * label: "Aprobar", icon: Check, primary: true,
25
+ * run: () => pagosBoundedContext.execute(new CommandAprobarPago(pago.id)),
26
+ * });
27
+ * <Record.Dock actions={[aprobar.action]} />
28
+ * {aprobar.dialog}
36
29
  */
37
- export function ServiceButton({ label, run, rehearse, role = "secondary", disabled = false, ask, entity, record, dialog, onDone, }) {
30
+ export function useServiceAction({ icon, primary, danger, tucked, shortcut, hint, id, ...props }) {
31
+ const { action, form } = useServiceBehind(props);
32
+ const gesture = useActionGesture(action, {
33
+ label: props.label,
34
+ ...(form === undefined ? {} : { ask: form }),
35
+ ...(props.dialog === undefined ? {} : { dialog: props.dialog }),
36
+ ...(props.onDone === undefined ? {} : { onDone: props.onDone }),
37
+ });
38
+ const look = { icon, primary, danger, tucked, shortcut, hint, id };
39
+ return dockedOf(gesture, props.label, look, props.disabled);
40
+ }
41
+ /** What runs behind a use case's button or dock action: the run, its dry run, what it asks. */
42
+ function useServiceBehind({ run, rehearse, ask, entity, record }) {
38
43
  const running = useService((asked) => run(asked ?? NOTHING_ASKED));
39
44
  const rehearsing = useService((asked) => (rehearse ?? NO_REHEARSAL)(asked ?? NOTHING_ASKED));
40
45
  // Outside a provider it still runs: the asked fields are then drawn by what `ask` says.
@@ -51,7 +56,8 @@ export function ServiceButton({ label, run, rehearse, role = "secondary", disabl
51
56
  entityFor: (target) => entityFor(framework.entities, target, framework.metas.get),
52
57
  }),
53
58
  });
54
- return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), ...(dialog === undefined ? {} : { dialog }), action: {
59
+ return {
60
+ action: {
55
61
  run: running.run,
56
62
  ...(rehearse === undefined ? {} : { rehearse: rehearsing.run }),
57
63
  busy: running.busy || rehearsing.busy,
@@ -61,5 +67,7 @@ export function ServiceButton({ label, run, rehearse, role = "secondary", disabl
61
67
  running.reset();
62
68
  rehearsing.reset();
63
69
  },
64
- }, label: label, role: role, disabled: disabled, ...(onDone === undefined ? {} : { onDone }) }));
70
+ },
71
+ form,
72
+ };
65
73
  }
@@ -0,0 +1,31 @@
1
+ import type { ActionGesture } from "./ActionButton.js";
2
+ import type { DockAction } from "@sincpro/web-ui";
3
+ import type { ReactNode } from "react";
4
+ /**
5
+ * An action for a dock — web-ui's `Record.Dock` and `List.Dock`, which the application's view
6
+ * style draws: the rail's buttons in `traditional`, one pill floating at the bottom in `modern`
7
+ * — and the window its gesture opens (what it asks, what it would do, a refusal).
8
+ *
9
+ * const aprobar = useServiceAction({ label: "Aprobar", primary: true, run: aprobarPago });
10
+ * <Record.Rail>
11
+ * <Record.Dock actions={[aprobar.action]} />
12
+ * </Record.Rail>
13
+ * {aprobar.dialog}
14
+ */
15
+ export type DockedAction = {
16
+ action: DockAction;
17
+ /** Put it anywhere on the screen — it opens over everything —; `null` while closed. */
18
+ dialog: ReactNode;
19
+ };
20
+ /** How an action is drawn in a dock — everything but its words and what it does. Its `id`
21
+ * defaults to its label. */
22
+ export type ActionLook = Pick<DockAction, "icon" | "primary" | "danger" | "tucked" | "shortcut" | "hint"> & {
23
+ id?: string;
24
+ };
25
+ /** A look as a hook receives it: a field the screen left out is `undefined`. */
26
+ type LookGiven = {
27
+ [K in keyof ActionLook]?: ActionLook[K] | undefined;
28
+ };
29
+ /** The dock's action started by a gesture: off while it runs. */
30
+ export declare function dockedOf(gesture: ActionGesture, label: string, look: LookGiven, disabled?: boolean): DockedAction;
31
+ export {};
@@ -0,0 +1,14 @@
1
+ /** The dock's action started by a gesture: off while it runs. */
2
+ export function dockedOf(gesture, label, look, disabled = false) {
3
+ const { id, ...drawn } = Object.fromEntries(Object.entries(look).filter(([, value]) => value !== undefined));
4
+ return {
5
+ action: {
6
+ ...drawn,
7
+ id: id ?? label,
8
+ label,
9
+ disabled: disabled || gesture.busy,
10
+ onSelect: gesture.start,
11
+ },
12
+ dialog: gesture.dialog,
13
+ };
14
+ }
@@ -1,6 +1,7 @@
1
- import { type Entity, type ResourceRef } from "@sincpro/client-framework";
1
+ import { type Entity, type ResourceRef, type Selection } from "@sincpro/client-framework";
2
2
  import { type AnyRecord, type Criteria, type Expression } from "@sincpro/criteria";
3
3
  import { type ListDefinition } from "../../core/list.js";
4
+ import type { Chooser } from "../list/records.js";
4
5
  import type { OpenTarget } from "@sincpro/web-ui";
5
6
  import { type ReactNode } from "react";
6
7
  /**
@@ -29,7 +30,10 @@ export type RecordOpening = {
29
30
  /** «Buscar más…»: the entity's own list opened to choose (in composer, a modal that answers),
30
31
  * on what was typed, offering only what `scope` lets the picker choose (`chooserScopeOf`).
31
32
  * Without it the picker brings its own chooser. */
32
- choose?: (entity: Entity, answer: (id: string) => void, query: string, scope?: Expression) => void;
33
+ choose?: Chooser<string>;
34
+ /** «Buscar más…» for several — a many2many: the same list opened to choose MANY, answering a
35
+ * `Selection` (what was ticked, or every record it matches). Without it, `choose` adds one. */
36
+ chooseMany?: Chooser<Selection>;
33
37
  /** «Agregar» on a one2many: the form of a new record of `entity`, starting with `values`
34
38
  * (the key that points back here), opened where it answers; `created` once it exists.
35
39
  * Without it a record's one2many only reads. */
@@ -1,8 +1,8 @@
1
1
  import type { Entity } from "@sincpro/client-framework";
2
2
  import { type AnyRecord, type Meta } from "@sincpro/criteria";
3
3
  import { type ChoiceTones, type PartLook } from "../list/presentation.js";
4
- import { type RowAction, type SheetField } from "@sincpro/web-ui";
5
- import type { ReactNode } from "react";
4
+ import { type DockAction, type RowAction, type SheetField } from "@sincpro/web-ui";
5
+ import { type ReactNode } from "react";
6
6
  export declare function factsOf<T extends AnyRecord>(record: T, meta: Meta | null | undefined, names: readonly string[], options?: {
7
7
  locale?: string | undefined;
8
8
  cells?: Readonly<Partial<Record<string, (record: T) => ReactNode>>>;
@@ -40,8 +40,16 @@ export declare function usePartLook<T extends AnyRecord>(meta: Meta | null | und
40
40
  * <RecordLines record={project} meta={meta} name="shares"
41
41
  * rowActions={(share) => [{ id: "unshare", label: "Quitar", icon: X, tone: "danger",
42
42
  * onSelect: () => unshare.run(project.id, { tenant_id: share.tenant_id }) }]} />
43
+ *
44
+ * `selectionActions` acts on SEVERAL: the parts get ticks, and what is done to the chosen ones
45
+ * is web-ui's dock — in the collection's line in the traditional style, floating in the modern
46
+ * one, where it takes the record's place while parts are chosen. It is handed the chosen parts
47
+ * and a way to clear the choice once done.
48
+ *
49
+ * selectionActions={(chosen, clear) => [{ id: "unshare", label: `Quitar ${chosen.length}`,
50
+ * icon: X, onSelect: () => { void unshareAll(chosen); clear(); } }]}
43
51
  */
44
- export declare function RecordLines<T extends AnyRecord>({ record, meta, name, entity, columns, cells, tones, locale, onOpen, rowActions, }: {
52
+ export declare function RecordLines<T extends AnyRecord>({ record, meta, name, entity, columns, cells, tones, locale, onOpen, rowActions, selectionActions, }: {
45
53
  record: AnyRecord;
46
54
  meta: Meta | null | undefined;
47
55
  name: string;
@@ -56,4 +64,7 @@ export declare function RecordLines<T extends AnyRecord>({ record, meta, name, e
56
64
  onOpen?: (row: T) => void;
57
65
  /** What a row's part can be acted on with — a Command of the record. */
58
66
  rowActions?: (row: T) => readonly RowAction[];
67
+ /** What is done to several parts at once; giving it makes the parts choosable. Handed the
68
+ * chosen parts, and `clear` to drop the choice once done. */
69
+ selectionActions?: (chosen: readonly T[], clear: () => void) => readonly DockAction[];
59
70
  }): import("react").JSX.Element;