@sincpro/web-framework 3.6.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.
- package/README.md +3 -0
- package/dist/core/crumbs.d.ts +4 -0
- package/dist/core/crumbs.js +24 -0
- package/dist/web/index.d.ts +5 -3
- package/dist/web/index.js +5 -3
- package/dist/web/list/EntityList.d.ts +23 -6
- package/dist/web/list/EntityList.js +89 -21
- package/dist/web/list/columns.d.ts +4 -1
- package/dist/web/list/columns.js +14 -6
- package/dist/web/list/dock.d.ts +19 -0
- package/dist/web/list/dock.js +20 -0
- package/dist/web/list/groups.d.ts +7 -1
- package/dist/web/list/groups.js +25 -5
- package/dist/web/record/ActionButton.d.ts +25 -0
- package/dist/web/record/ActionButton.js +39 -18
- package/dist/web/record/CommandButton.d.ts +22 -2
- package/dist/web/record/CommandButton.js +43 -17
- package/dist/web/record/RecordLifecycle.d.ts +28 -7
- package/dist/web/record/RecordLifecycle.js +63 -10
- package/dist/web/record/ServiceButton.d.ts +20 -2
- package/dist/web/record/ServiceButton.js +35 -27
- package/dist/web/record/dock.d.ts +31 -0
- package/dist/web/record/dock.js +14 -0
- package/dist/web/record/record.d.ts +14 -3
- package/dist/web/record/record.js +39 -6
- package/dist/web/workspace/record.d.ts +8 -3
- package/dist/web/workspace/record.js +20 -16
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -501,6 +501,9 @@ hook and draw your own, or go straight to the loose piece.
|
|
|
501
501
|
| Act on it (with a dry run) | `ServiceButton` (a use case), `CommandButton`, row commands | `useService`, `useCommand` | `transport.send` |
|
|
502
502
|
| What is chosen in a list | `EntityList selectable selection` | `useSelection` | `Selection`, `chosen`, `allMatching` (client-framework) |
|
|
503
503
|
| Act on each chosen one | `BatchProgress`, `selectionActions={(chosen) => …}` | `useBatchCommand` | `runBatch`, `keysOf` (client-framework), `sendRoute` |
|
|
504
|
+
| A list's actions, by the style | `EntityList actions`, `selectionActions` (`DockAction`s) | — | web-ui's `List.Dock`, `ViewStyleProvider` |
|
|
505
|
+
| A record's actions, by the style | `EntityRecord actions`, web-ui's `Record.Dock` | `useRecordLifecycleActions` | `DockedAction`, `ActionLook` |
|
|
506
|
+
| A use case or a Command, there | `ServiceButton`, `CommandButton` (as buttons) | `useServiceAction`/`useCommandAction` | — |
|
|
504
507
|
| Delete it | `EntityRecord` (`RecordLifecycle`) | `useRecordLifecycle` | `entity.delete`, `useRouteCommand` |
|
|
505
508
|
| Its trash | `EntityRecord` (`RecordLifecycle`), `listView(trashOf(entity))` | `useRecordLifecycle` | `entity.archive`, `entity.restore`, `trashOf` |
|
|
506
509
|
| Read again when it was written | every reading of this package, by itself | `useWrites` | `processChanges` (client-framework) |
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A crumb says only what is its OWN.
|
|
3
|
+
*
|
|
4
|
+
* Context: a view names itself whole so its tab stands alone in the workspace — «Pagos · María
|
|
5
|
+
* Fernanda Apaza Quispe» —, and the trail takes that name: `Pagos › María Fernanda Apaza Quispe ›
|
|
6
|
+
* Pagos · María Fernanda Apaza Quispe`. The crumb before already says whose; the last one wrapped
|
|
7
|
+
* onto a second line to say it again. Under its parent, a crumb drops the parent's name and the
|
|
8
|
+
* joint that held it («·», «:», «—», «de», «of»…) — «Pagos» —, and is left whole when the parent's
|
|
9
|
+
* name is not in it or is all of it.
|
|
10
|
+
*/
|
|
11
|
+
const JOINT = /^(?:[\s·:—–|/-]|de\b|del\b|of\b|for\b|para\b)+|(?:[\s·:—–|/-]|\bde|\bdel|\bof|\bfor|\bpara)+$/giu;
|
|
12
|
+
export function ownLabel(label, parent) {
|
|
13
|
+
const before = parent?.trim();
|
|
14
|
+
if (before === undefined || before === "" || !label.includes(before))
|
|
15
|
+
return label;
|
|
16
|
+
const own = label.replace(before, "").replace(JOINT, "").trim();
|
|
17
|
+
return own === "" ? label : own;
|
|
18
|
+
}
|
|
19
|
+
export function ownCrumbs(crumbs) {
|
|
20
|
+
return crumbs.map((crumb, at) => {
|
|
21
|
+
const own = ownLabel(crumb.label, crumbs[at - 1]?.label);
|
|
22
|
+
return own === crumb.label ? crumb : { ...crumb, label: own };
|
|
23
|
+
});
|
|
24
|
+
}
|
package/dist/web/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { BatchProgress } from "./list/BatchProgress.js";
|
|
5
5
|
export { aggregateOf, type ColumnOptions, columnsOf, } from "./list/columns.js";
|
|
6
|
+
export { actionsOf, type ScreenActions } from "./list/dock.js";
|
|
6
7
|
export { type EntityFace, EntityList, type EntityListProps, type View, } from "./list/EntityList.js";
|
|
7
8
|
export { EntitySearchBar } from "./list/EntitySearchBar.js";
|
|
8
9
|
export { groupableOf, pilesOf } from "./list/groups.js";
|
|
@@ -14,17 +15,18 @@ export { type RowCommand, type RowCommands, useRowCommands, } from "./list/rowCo
|
|
|
14
15
|
export { facetsOf, modelOf } from "./list/search.js";
|
|
15
16
|
export { type ActionDialog, type Asked, } from "./record/ActionButton.js";
|
|
16
17
|
export { type AskedField, type AskField, type AskForm, askFormOf, } from "./record/ask.js";
|
|
17
|
-
export { CommandButton } from "./record/CommandButton.js";
|
|
18
|
+
export { type CommandActionProps, CommandButton, useCommandAction, } from "./record/CommandButton.js";
|
|
18
19
|
export { RelationPicker } from "./record/control.js";
|
|
20
|
+
export { type ActionLook, type DockedAction } from "./record/dock.js";
|
|
19
21
|
export { dirtyOf, type FieldControl, RecordField, } from "./record/edit.js";
|
|
20
22
|
export { EntityPicker } from "./record/EntityPicker.js";
|
|
21
23
|
export { EntityTags } from "./record/EntityTags.js";
|
|
22
24
|
export { type LineColumn, type LineControl, type LinesLook, RecordLinesEditor, } from "./record/lines.js";
|
|
23
25
|
export { type RecordOpening, RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
|
|
24
26
|
export { countOf, factsOf, RecordLines, usePartLook, } from "./record/record.js";
|
|
25
|
-
export { RecordLifecycle } from "./record/RecordLifecycle.js";
|
|
27
|
+
export { type LifecycleDone, RecordLifecycle, useRecordLifecycleActions, } from "./record/RecordLifecycle.js";
|
|
26
28
|
export { RelatedList } from "./record/RelatedList.js";
|
|
27
|
-
export { ServiceButton } from "./record/ServiceButton.js";
|
|
29
|
+
export { type ServiceActionProps, ServiceButton, useServiceAction, } from "./record/ServiceButton.js";
|
|
28
30
|
export { cardOf, relationOf } from "./record/summary.js";
|
|
29
31
|
export { Refused } from "./Refused.js";
|
|
30
32
|
export { entityView, type EntityViewOptions, listView, type ListViewOptions, } from "./workspace/composer.js";
|
package/dist/web/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { BatchProgress } from "./list/BatchProgress.js";
|
|
5
5
|
export { aggregateOf, columnsOf, } from "./list/columns.js";
|
|
6
|
+
export { actionsOf } from "./list/dock.js";
|
|
6
7
|
export { EntityList, } from "./list/EntityList.js";
|
|
7
8
|
export { EntitySearchBar } from "./list/EntitySearchBar.js";
|
|
8
9
|
export { groupableOf, pilesOf } from "./list/groups.js";
|
|
@@ -14,17 +15,18 @@ export { useRowCommands, } from "./list/rowCommands.js";
|
|
|
14
15
|
export { facetsOf, modelOf } from "./list/search.js";
|
|
15
16
|
export {} from "./record/ActionButton.js";
|
|
16
17
|
export { askFormOf, } from "./record/ask.js";
|
|
17
|
-
export { CommandButton } from "./record/CommandButton.js";
|
|
18
|
+
export { CommandButton, useCommandAction, } from "./record/CommandButton.js";
|
|
18
19
|
export { RelationPicker } from "./record/control.js";
|
|
20
|
+
export {} from "./record/dock.js";
|
|
19
21
|
export { dirtyOf, RecordField, } from "./record/edit.js";
|
|
20
22
|
export { EntityPicker } from "./record/EntityPicker.js";
|
|
21
23
|
export { EntityTags } from "./record/EntityTags.js";
|
|
22
24
|
export { RecordLinesEditor, } from "./record/lines.js";
|
|
23
25
|
export { RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
|
|
24
26
|
export { countOf, factsOf, RecordLines, usePartLook, } from "./record/record.js";
|
|
25
|
-
export { RecordLifecycle } from "./record/RecordLifecycle.js";
|
|
27
|
+
export { RecordLifecycle, useRecordLifecycleActions, } from "./record/RecordLifecycle.js";
|
|
26
28
|
export { RelatedList } from "./record/RelatedList.js";
|
|
27
|
-
export { ServiceButton } from "./record/ServiceButton.js";
|
|
29
|
+
export { ServiceButton, useServiceAction, } from "./record/ServiceButton.js";
|
|
28
30
|
export { cardOf, relationOf } from "./record/summary.js";
|
|
29
31
|
export { Refused } from "./Refused.js";
|
|
30
32
|
export { entityView, listView, } from "./workspace/composer.js";
|
|
@@ -4,8 +4,9 @@ import { type WorkspaceApi } from "@sincpro/web-composer";
|
|
|
4
4
|
import { type GroupLevel, type NamedFilter } from "../../core/list.js";
|
|
5
5
|
import type { Listing } from "../../react/useListing.js";
|
|
6
6
|
import { type ListSelection } from "../../react/useSelection.js";
|
|
7
|
+
import { type ScreenActions } from "./dock.js";
|
|
7
8
|
import { type RowCommand } from "./rowCommands.js";
|
|
8
|
-
import { type ListCrumb, type ListPresentProps, type ListSet, type OpenTarget, type RowAction } from "@sincpro/web-ui";
|
|
9
|
+
import { type ListCrumb, type ListPresentProps, type ListSet, type OpenTarget, type RowAction, type YesNoColumn } from "@sincpro/web-ui";
|
|
9
10
|
import { type ReactNode } from "react";
|
|
10
11
|
/**
|
|
11
12
|
* A whole collection from a `Listing`: the bar, the search, the set in the views it offers,
|
|
@@ -42,6 +43,14 @@ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = Comma
|
|
|
42
43
|
columns?: readonly string[];
|
|
43
44
|
/** The cells that are not plain text: a link, a tag. Memoise it: compared by identity. */
|
|
44
45
|
cells?: Readonly<Partial<Record<string, (row: T) => ReactNode>>>;
|
|
46
|
+
/**
|
|
47
|
+
* How a yes/no column reads, by field — web-ui's `yesNo`: `check` (the default: ✓ and
|
|
48
|
+
* nothing), `icon` (a green ✓ and a quiet ✕), `word` — or a `checkbox` / `switch` that
|
|
49
|
+
* changes it from the list with `onToggle` (an update, a Command). Memoise it.
|
|
50
|
+
*
|
|
51
|
+
* yesNo={{ published: { look: "switch", onToggle: (course, on) => publish.run(course.id, on) } }}
|
|
52
|
+
*/
|
|
53
|
+
yesNo?: Readonly<Partial<Record<string, YesNoColumn<T>>>>;
|
|
45
54
|
/**
|
|
46
55
|
* The ways to look at the set, the first one shown: `table` (columns), `rows` (a name and
|
|
47
56
|
* its facts, what a narrow panel wants), `board` (cards) and `sheet` (a spreadsheet, every
|
|
@@ -65,7 +74,13 @@ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = Comma
|
|
|
65
74
|
title?: string;
|
|
66
75
|
description?: string;
|
|
67
76
|
crumbs?: readonly ListCrumb[];
|
|
68
|
-
|
|
77
|
+
/**
|
|
78
|
+
* What the list starts — «Importar», «Exportar ▸» —, beside «Nuevo». As data (`DockAction`s)
|
|
79
|
+
* the application's view style draws them with «Nuevo»: the bar's buttons in `traditional`,
|
|
80
|
+
* one pill floating at the bottom in `modern` (web-ui's `ViewStyleProvider`). A node drawn
|
|
81
|
+
* by hand stays in the bar.
|
|
82
|
+
*/
|
|
83
|
+
actions?: ScreenActions;
|
|
69
84
|
onOpen?: (row: T) => void;
|
|
70
85
|
onPeek?: (row: T) => void;
|
|
71
86
|
/**
|
|
@@ -105,9 +120,11 @@ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = Comma
|
|
|
105
120
|
/** The selection, held by the screen (`useSelection(listing)`): read and set from outside the
|
|
106
121
|
* list. Without it the list holds its own. */
|
|
107
122
|
selection?: ListSelection<T>;
|
|
108
|
-
/** What to do with what is chosen,
|
|
109
|
-
*
|
|
110
|
-
|
|
123
|
+
/** What to do with what is chosen, while something is — handed the selection to act on it
|
|
124
|
+
* (`useBatchCommand`). As data, the view style draws it: in the bar in place of the search
|
|
125
|
+
* in `traditional`, a pill floating at the bottom in `modern` («3 elegidas ✕ · Confirmar»).
|
|
126
|
+
* Giving it makes the rows choosable: `selectable` is not needed with it. */
|
|
127
|
+
selectionActions?: ScreenActions | ((selection: ListSelection<T>) => ScreenActions);
|
|
111
128
|
/** The list is a FIELD of a record — its lines, its members — and not a screen. */
|
|
112
129
|
embedded?: boolean;
|
|
113
130
|
/**
|
|
@@ -141,4 +158,4 @@ export type EntityFace<T> = {
|
|
|
141
158
|
render: (set: ListSet<T>) => ReactNode;
|
|
142
159
|
};
|
|
143
160
|
export type View = "table" | "rows" | "board" | "sheet" | "pivot";
|
|
144
|
-
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, facets: askedFacets, groupable: askedGroupable, selectable, selection: held, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;
|
|
161
|
+
export declare function EntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, yesNo, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, facets: askedFacets, groupable: askedGroupable, selectable, selection: held, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx,
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } 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
5
|
import { RecordLink, useCrumbs, usePhone } from "@sincpro/web-composer";
|
|
6
6
|
import { frameworkCopy } from "../../core/copy.js";
|
|
7
|
+
import { ownCrumbs } from "../../core/crumbs.js";
|
|
7
8
|
import { explain } from "../../core/explain.js";
|
|
8
9
|
import { choosesMany, } from "../../core/list.js";
|
|
9
10
|
import { textOf, viewOf } from "../../core/present.js";
|
|
@@ -13,6 +14,7 @@ import { useGroups } from "../../react/useGroups.js";
|
|
|
13
14
|
import { usePivot } from "../../react/usePivot.js";
|
|
14
15
|
import { useSelection } from "../../react/useSelection.js";
|
|
15
16
|
import { columnsOf } from "./columns.js";
|
|
17
|
+
import { actionsOf } from "./dock.js";
|
|
16
18
|
import { EntitySearchBar } from "./EntitySearchBar.js";
|
|
17
19
|
import { pilesOf } from "./groups.js";
|
|
18
20
|
import { OpenInMenu, openOptions, targetsFor } from "./openIn.js";
|
|
@@ -20,7 +22,7 @@ import { pivotOf } from "./pivot.js";
|
|
|
20
22
|
import { over, presentationOf } from "./presentation.js";
|
|
21
23
|
import { RESTORE, useRowCommands, } from "./rowCommands.js";
|
|
22
24
|
import { Button, Callout, List, Pagination, pathKey, RecordCard, SearchField, Tag, } from "@sincpro/web-ui";
|
|
23
|
-
import { RotateCcw } from "lucide-react";
|
|
25
|
+
import { Plus, RotateCcw } from "lucide-react";
|
|
24
26
|
import { useEffect, useId, useMemo, useRef, useState } from "react";
|
|
25
27
|
/** What `useCrumbs` reads when the list is not in a workspace: no trail, and nothing to follow. */
|
|
26
28
|
const NO_TRAIL = [];
|
|
@@ -35,7 +37,7 @@ const TRAILS = 50;
|
|
|
35
37
|
const NO_COMMANDS = [];
|
|
36
38
|
/** What a list offers when nobody said: every face that needs no configuration. */
|
|
37
39
|
const EVERY_VIEW = ["table", "rows", "board", "sheet"];
|
|
38
|
-
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, facets: askedFacets, groupable: askedGroupable, selectable = false, selection: held, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
|
|
40
|
+
export function EntityList({ listing, api, columns: askedColumns, cells, yesNo, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search = "bar", sums, filters: askedFilters, facets: askedFacets, groupable: askedGroupable, selectable = false, selection: held, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
|
|
39
41
|
// A named list (`defineList`) brings its own columns, filters, faces and words; what the
|
|
40
42
|
// screen passes wins.
|
|
41
43
|
const definition = listing.definition;
|
|
@@ -74,7 +76,9 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
74
76
|
const choosingMany = choosing && choosesMany(api?.choosing?.question);
|
|
75
77
|
const own = useSelection(listing);
|
|
76
78
|
const chosen = held ?? own;
|
|
77
|
-
|
|
79
|
+
// Actions for the chosen rows make the rows choosable: given without `selectable` they were
|
|
80
|
+
// silently never shown — no ticks, nothing to act on.
|
|
81
|
+
const ticking = selectable || choosingMany || selectionActions !== undefined;
|
|
78
82
|
// The record opened from a row knows the page it came from: «3 / 64» and its neighbours.
|
|
79
83
|
const { trails, dateStyle } = useFramework();
|
|
80
84
|
const trailKey = `trail:${useId()}`;
|
|
@@ -134,9 +138,30 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
134
138
|
listing.entity.create !== undefined
|
|
135
139
|
? () => api.open(listing.entity.newRef())
|
|
136
140
|
: undefined;
|
|
141
|
+
// What the list starts, as data: «Nuevo» — the primary — and the screen's, drawn by the view
|
|
142
|
+
// style (`List.Dock`). Actions drawn by hand stay in the bar, with «Nuevo» beside them.
|
|
143
|
+
const started = actionsOf(actions);
|
|
144
|
+
const startDock = started.drawn !== null
|
|
145
|
+
? []
|
|
146
|
+
: [
|
|
147
|
+
...(creating === undefined
|
|
148
|
+
? []
|
|
149
|
+
: [
|
|
150
|
+
{
|
|
151
|
+
id: "create",
|
|
152
|
+
label: frameworkCopy().record.create,
|
|
153
|
+
icon: Plus,
|
|
154
|
+
primary: true,
|
|
155
|
+
onSelect: creating,
|
|
156
|
+
},
|
|
157
|
+
]),
|
|
158
|
+
...started.dock,
|
|
159
|
+
];
|
|
137
160
|
// A press opens the page — the composer's one predictable gesture. Every other place the
|
|
138
|
-
// record may open is
|
|
139
|
-
// (`onPeek` with `rowClick="open"`: the press stays «open»)
|
|
161
|
+
// record may open is among the row's ways in, web-ui's (`openTargets` + `onOpenIn`, web-ui
|
|
162
|
+
// 2.10): 👁 for a look (`onPeek` with `rowClick="open"`: the press stays «open»), and «Abrir
|
|
163
|
+
// en…» with the rest — in ONE place at the row's end, a pill in the modern style. Drawn beside
|
|
164
|
+
// the name as well, a row offered three unaligned sets. A chooser only chooses.
|
|
140
165
|
const openingIn = onOpenIn ??
|
|
141
166
|
(api === undefined
|
|
142
167
|
? undefined
|
|
@@ -149,30 +174,34 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
149
174
|
(targets.includes("peek") && openingIn !== undefined
|
|
150
175
|
? (row) => openingIn(row, "peek")
|
|
151
176
|
: undefined);
|
|
152
|
-
// The cells are memoised (below)
|
|
153
|
-
// `onOpenIn` is always the current one without redrawing
|
|
177
|
+
// The cells are memoised (below) and web-ui holds the row ways: both reach the opener through
|
|
178
|
+
// a ref, so a screen's inline `onOpenIn` is always the current one without redrawing.
|
|
154
179
|
const openingNow = useRef(openingIn);
|
|
155
180
|
openingNow.current = openingIn;
|
|
181
|
+
// The rows face (not the table) takes «Abrir en…» as its row's actions.
|
|
156
182
|
const openInOf = (row) => elsewhere.length === 0 || openingIn === undefined ? null : (_jsx(OpenInMenu, { targets: elsewhere, name: idOf(row), onOpen: (to) => openingNow.current?.(row, to) }));
|
|
157
|
-
// The column that names a row carries its link
|
|
158
|
-
//
|
|
183
|
+
// The column that names a row carries its link: the identity, or — in a list that does not
|
|
184
|
+
// show it (a relation inside a record) — the record's name, else the first. The link is only
|
|
185
|
+
// the name (`compact`): the places it opens in are the row's ways.
|
|
159
186
|
const named = columns === undefined || columns.includes(identity)
|
|
160
187
|
? identity
|
|
161
188
|
: meta?.display && columns.includes(meta.display)
|
|
162
189
|
? meta.display
|
|
163
190
|
: (columns[0] ?? identity);
|
|
164
191
|
const rowName = (row) => named === identity ? idOf(row) : (textOf(meta, named, row[named], locale) ?? idOf(row));
|
|
165
|
-
const linked = choosing || cells?.[named] !== undefined ||
|
|
192
|
+
const linked = choosing || cells?.[named] !== undefined || api === undefined
|
|
166
193
|
? cells
|
|
167
194
|
: {
|
|
168
195
|
...cells,
|
|
169
|
-
[named]: (row) => (
|
|
196
|
+
[named]: (row) => (_jsx(RecordLink, { api: api, resource: refOf(row), compact: true, children: rowName(row) })),
|
|
170
197
|
};
|
|
171
198
|
// `useCrumbs`, not `api.crumbs()`: the crumb must follow a name given later (`setTitle`).
|
|
172
199
|
// Without a workspace it reads a trail that never changes — a hook cannot be skipped.
|
|
173
200
|
const following = useCrumbs(api ?? NO_WORKSPACE);
|
|
174
201
|
usePhone(api ?? NO_WORKSPACE); // where a row opens follows the mode (`targetsFor`)
|
|
175
|
-
|
|
202
|
+
// The workspace's crumbs say each view's whole name (its tab's); in the trail a crumb says only
|
|
203
|
+
// what is its own — «Pagos», not «Pagos · María Fernanda» under «María Fernanda».
|
|
204
|
+
const trail = crumbs ?? (embedded || api === undefined ? undefined : ownCrumbs(following));
|
|
176
205
|
// The workspace hears what is chosen: the keys, or — «all that match» — the ones on screen.
|
|
177
206
|
const published = (chosen.selection.by === "keys"
|
|
178
207
|
? chosen.selection.keys
|
|
@@ -186,7 +215,21 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
186
215
|
}, [api, ticking, published, listing.entity]);
|
|
187
216
|
// «Elegir los 187 que coinciden» only past the page, and only with the server's exact count.
|
|
188
217
|
const total = listing.count?.exact === true ? listing.count.value : null;
|
|
189
|
-
|
|
218
|
+
// What is done to the chosen rows: answering whoever asked for several, else the screen's.
|
|
219
|
+
const onChosen = choosingMany
|
|
220
|
+
? [
|
|
221
|
+
{
|
|
222
|
+
id: "add-chosen",
|
|
223
|
+
label: frameworkCopy().picker.addChosen(chosen.size),
|
|
224
|
+
primary: true,
|
|
225
|
+
onSelect: () => api?.answer(chosen.selection),
|
|
226
|
+
},
|
|
227
|
+
]
|
|
228
|
+
: typeof selectionActions === "function"
|
|
229
|
+
? selectionActions(chosen)
|
|
230
|
+
: selectionActions;
|
|
231
|
+
// As data they go to the dock, where the view style draws them; by hand, in the bar.
|
|
232
|
+
const forChosen = actionsOf(onChosen);
|
|
190
233
|
const selection = ticking
|
|
191
234
|
? {
|
|
192
235
|
has: chosen.isChosen,
|
|
@@ -196,7 +239,7 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
196
239
|
...(total !== null && total > listing.rows.length
|
|
197
240
|
? { matching: { total, onSelect: chosen.chooseAllMatching } }
|
|
198
241
|
: {}),
|
|
199
|
-
...(
|
|
242
|
+
...(forChosen.drawn === null ? {} : { actions: forChosen.drawn }),
|
|
200
243
|
}
|
|
201
244
|
: undefined;
|
|
202
245
|
// Rebuilt only when what it reads changes: a new set of columns on every render redraws
|
|
@@ -207,9 +250,20 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
207
250
|
locale,
|
|
208
251
|
...(linked ? { cells: linked } : {}),
|
|
209
252
|
...(look.tones === undefined ? {} : { tones: look.tones }),
|
|
253
|
+
...(yesNo === undefined ? {} : { yesNo }),
|
|
210
254
|
}),
|
|
211
255
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
212
|
-
[
|
|
256
|
+
[
|
|
257
|
+
meta,
|
|
258
|
+
locale,
|
|
259
|
+
names,
|
|
260
|
+
cells,
|
|
261
|
+
yesNo,
|
|
262
|
+
api,
|
|
263
|
+
elsewhere.join(),
|
|
264
|
+
openingIn === undefined,
|
|
265
|
+
dateStyle,
|
|
266
|
+
]);
|
|
213
267
|
// A state the application gave colours to is the row's tag — and not again among its facts.
|
|
214
268
|
const stateField = summaryFieldsOf(meta, {}, listing.entity.summary).state;
|
|
215
269
|
const stateTones = stateField === undefined ? undefined : look.tones?.[stateField];
|
|
@@ -299,7 +353,15 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
299
353
|
// each says what its next «more» brings (1.5).
|
|
300
354
|
const groups = useGroups(listing, sums === undefined ? {} : { sums: sums || [] });
|
|
301
355
|
const grouped = groups.levels.length > 0;
|
|
302
|
-
|
|
356
|
+
// A table and a sheet say a group's sums under their columns (web-ui 2.9): beside the group's
|
|
357
|
+
// name, only what no column shown adds up.
|
|
358
|
+
const columnar = present === "table" || present === "sheet";
|
|
359
|
+
const underColumns = new Set(columnar
|
|
360
|
+
? shown.flatMap((column) => column.aggregate === undefined || column.defaultHidden || column.field === undefined
|
|
361
|
+
? []
|
|
362
|
+
: [column.field])
|
|
363
|
+
: []);
|
|
364
|
+
const { piles, bucketAt } = pilesOf(groups.buckets, groups.levels, meta, locale, groups.rowsOf, groups.brings, underColumns);
|
|
303
365
|
const [opened, setOpened] = useState(() => new Set());
|
|
304
366
|
useEffect(() => setOpened(new Set()), [groups.buckets]);
|
|
305
367
|
const collapsed = [...bucketAt.keys()].filter((key) => !opened.has(key));
|
|
@@ -375,8 +437,9 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
375
437
|
: copy.groups(groups.buckets.length, records) }))) : fits ? null : listing.paging === "pages" ? (page.from === 0 ? null : (_jsx(Pagination, { from: page.from, to: page.to, total: count?.value ?? page.to, ...(page.hasPrev ? { onPrev: listing.prev } : {}), ...(page.hasNext ? { onNext: listing.next } : {}) }))) : (_jsxs(_Fragment, { children: [count === null ? null : (_jsx("span", { className: "text-meta text-muted", children: copy.shown(listing.rows.length, count.value, count.exact) })), listing.capped ? (_jsx("span", { className: "text-meta text-muted", children: copy.capped(listing.rows.length) })) : listing.hasMore ? (_jsx(Button, { size: "sm", role: "secondary", disabled: listing.status === "loadingMore", onClick: listing.more, children: listing.status === "loadingMore" ? copy.loading : copy.loadMore })) : null] }));
|
|
376
438
|
const pageTotals = totalled && partial && present === "table";
|
|
377
439
|
// Written only when it says something: web-ui draws an embedded list's bar for any slot
|
|
378
|
-
// written, an empty one too.
|
|
379
|
-
|
|
440
|
+
// written, an empty one too. Its parts side by side and apart: the slot does not space them,
|
|
441
|
+
// and «Totales de esta página» read glued to «1–50 / 112».
|
|
442
|
+
const paging = !pageTotals && dropped.length === 0 && through === null ? null : (_jsxs("span", { className: "flex items-center gap-3", children: [pageTotals ? _jsx("span", { className: "text-meta text-muted", children: copy.pageTotals }) : null, dropped.length === 0 ? null : (_jsx(Tag, { tone: "warn", title: copy.dropped(dropped), children: copy.dropped(dropped) })), through] }));
|
|
380
443
|
return (_jsxs(List, { items: listing.rows, keyOf: idOf, embedded: embedded, present: present, onPresentChange: setPresent, ...grouping,
|
|
381
444
|
// The whole order, as web-ui 1.7 shows and sets it: ⇧-click on a header adds a field,
|
|
382
445
|
// the sort menu reorders them — the same list the criteria builder writes.
|
|
@@ -397,12 +460,17 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
|
|
|
397
460
|
}, filtered: listing.selection !== undefined || listing.text !== "", empty: {
|
|
398
461
|
sentence: empty ?? copy.empty,
|
|
399
462
|
whenFiltered: { sentence: copy.emptyFiltered },
|
|
400
|
-
}, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }),
|
|
463
|
+
}, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }), ...(elsewhere.length === 0 || openingIn === undefined
|
|
464
|
+
? {}
|
|
465
|
+
: {
|
|
466
|
+
openTargets: elsewhere,
|
|
467
|
+
onOpenIn: (row, to) => openingNow.current?.(row, to),
|
|
468
|
+
}), 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 }), ...(facets === undefined ? {} : { facets }), ...(asked === "" ? {} : { seed: asked }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
|
|
401
469
|
setDraft(next);
|
|
402
470
|
// Emptied (or cleared with ×): the whole set again, at once.
|
|
403
471
|
if (next === "" && listing.text !== "")
|
|
404
472
|
listing.search("", { now: true });
|
|
405
|
-
}, onSubmit: (text) => listing.search(text, { now: true }), placeholder: copy.search, "aria-label": copy.search }) })) : null,
|
|
473
|
+
}, onSubmit: (text) => listing.search(text, { now: true }), placeholder: copy.search, "aria-label": copy.search }) })) : null, started.drawn === null ? null : (_jsxs(List.Actions, { children: [started.drawn, creating === undefined ? null : (_jsx(Button, { role: "primary", size: "sm", onClick: creating, children: frameworkCopy().record.create }))] })), startDock.length === 0 && forChosen.dock.length === 0 ? null : (_jsx(List.Dock, { ...(startDock.length === 0 ? {} : { actions: startDock }), ...(forChosen.dock.length === 0 ? {} : { selection: forChosen.dock }) })), paging === null ? null : _jsx(List.Pagination, { children: paging })] }), views.includes("table") ? (_jsx(List.Table, { columns: shown, ...(totalled ? { totals: true } : {}), ...(rowActions === undefined ? {} : { rowActions }) })) : null, _jsx(List.Rows, { row: rowOf }), views.includes("sheet") ? (_jsx(List.Sheet, { columns: sheetColumns, cell: (row, column) => {
|
|
406
474
|
const value = row[column.id];
|
|
407
475
|
return value === null || value === undefined
|
|
408
476
|
? null
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AnyRecord, Meta } from "@sincpro/criteria";
|
|
2
2
|
import type { ChoiceTones } from "./presentation.js";
|
|
3
|
-
import { type Aggregate, type DataColumn } from "@sincpro/web-ui";
|
|
3
|
+
import { type Aggregate, type DataColumn, type YesNoColumn } from "@sincpro/web-ui";
|
|
4
4
|
import type { ReactNode } from "react";
|
|
5
5
|
export type ColumnOptions<T> = {
|
|
6
6
|
locale?: string | undefined;
|
|
@@ -8,6 +8,9 @@ export type ColumnOptions<T> = {
|
|
|
8
8
|
cells?: Readonly<Partial<Record<string, (row: T) => ReactNode>>>;
|
|
9
9
|
/** The colour of each value of a choice (`presented(entity, { tones })`). */
|
|
10
10
|
tones?: ChoiceTones<T> | undefined;
|
|
11
|
+
/** How a yes/no column reads — web-ui's `yesNo`: `check` (the default here: ✓ and nothing),
|
|
12
|
+
* `icon`, `word` — or, with `onToggle`, a `checkbox` / `switch` that writes it from the list. */
|
|
13
|
+
yesNo?: Readonly<Partial<Record<string, YesNoColumn<T>>>> | undefined;
|
|
11
14
|
};
|
|
12
15
|
/** How the model adds a field up at a list's foot, as web-ui's `aggregate`. */
|
|
13
16
|
export declare function aggregateOf(meta: Meta | null | undefined, name: string): Aggregate | undefined;
|
package/dist/web/list/columns.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { frameworkCopy } from "../../core/copy.js";
|
|
4
3
|
import { totalOf } from "../../core/measure.js";
|
|
5
4
|
import { BOOKKEEPING, defaultFields, fieldMetaOf, sortKeyOf, textOf, valueAt, viewOf, } from "../../core/present.js";
|
|
6
5
|
import { relationFieldOf } from "../../core/relation.js";
|
|
7
6
|
import { useEntityFor } from "../../react/context.js";
|
|
8
7
|
import { useNameOf } from "../../react/useNameOf.js";
|
|
9
8
|
import { Tag } from "@sincpro/web-ui";
|
|
10
|
-
import { Check } from "lucide-react";
|
|
11
9
|
/**
|
|
12
10
|
* The columns of a table, from the model: name the fields, the rest follows.
|
|
13
11
|
*
|
|
@@ -58,6 +56,7 @@ function columnOf(meta, name, options, hidden) {
|
|
|
58
56
|
const whole = view.name === meta?.identity || view.numeric || money || DATES.has(view.type);
|
|
59
57
|
const tones = options.tones?.[name];
|
|
60
58
|
const choice = (field?.choices?.length ?? 0) > 0;
|
|
59
|
+
const boolean = view.type === "boolean";
|
|
61
60
|
const aggregate = aggregateOf(meta, name);
|
|
62
61
|
// The column IS a key of another record: `customer_id` beside its relation, or a key alone.
|
|
63
62
|
const relation = relationFieldOf(meta, name);
|
|
@@ -87,14 +86,23 @@ function columnOf(meta, name, options, hidden) {
|
|
|
87
86
|
const word = text(row);
|
|
88
87
|
return word === "" ? null : (_jsx(Tag, { tone: tones?.[String(raw(row))] ?? "neutral", children: word }));
|
|
89
88
|
}
|
|
90
|
-
:
|
|
91
|
-
? //
|
|
92
|
-
|
|
89
|
+
: boolean
|
|
90
|
+
? // Drawn by web-ui from the value (`yesNo`, below): no cell of its own.
|
|
91
|
+
undefined
|
|
93
92
|
: whole
|
|
94
93
|
? (row) => _jsx("span", { className: "whitespace-nowrap", children: text(row) })
|
|
95
94
|
: text),
|
|
96
|
-
text
|
|
95
|
+
// A yes/no reads by its look (web-ui's `YesNo`): with a `text` of its own the table would
|
|
96
|
+
// draw the words instead.
|
|
97
|
+
...(boolean ? {} : { text }),
|
|
97
98
|
numeric: view.numeric || money,
|
|
99
|
+
...(boolean
|
|
100
|
+
? {
|
|
101
|
+
// A yes is a check and a no is nothing by default: a column of «sí/no» is noise to
|
|
102
|
+
// scan. Every look still says «sí» / «no» to a screen reader.
|
|
103
|
+
yesNo: { look: "check", ...options.yesNo?.[name] },
|
|
104
|
+
}
|
|
105
|
+
: {}),
|
|
98
106
|
sortable: view.sortable,
|
|
99
107
|
...(view.name === meta?.identity ? { mono: true } : {}),
|
|
100
108
|
...(hidden ? { optional: true, defaultHidden: true } : {}),
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DockAction } from "@sincpro/web-ui";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* A screen's actions: as DATA — web-ui's `DockAction`s, which the application's view style
|
|
5
|
+
* draws (the bar's buttons in `traditional`, one pill floating at the bottom in `modern`) — or
|
|
6
|
+
* drawn by hand, a node that stays where it is put.
|
|
7
|
+
*
|
|
8
|
+
* actions={[{ id: "import", label: "Importar", icon: Upload, onSelect: importar }]}
|
|
9
|
+
* actions={<ImportarColegiados />} // its own dialog: drawn by hand, in the bar
|
|
10
|
+
*/
|
|
11
|
+
export type ScreenActions = readonly DockAction[] | ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* The actions split by who draws them: `dock`, the ones given as data, for the view style;
|
|
14
|
+
* `drawn`, a node drawn by hand, to put where it goes — `null` when there is none.
|
|
15
|
+
*/
|
|
16
|
+
export declare function actionsOf(actions: ScreenActions): {
|
|
17
|
+
dock: readonly DockAction[];
|
|
18
|
+
drawn: ReactNode;
|
|
19
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isValidElement } from "react";
|
|
2
|
+
/** One action as data: an object with its id and its words, not an element. */
|
|
3
|
+
function isDockAction(one) {
|
|
4
|
+
return (typeof one === "object" &&
|
|
5
|
+
one !== null &&
|
|
6
|
+
!isValidElement(one) &&
|
|
7
|
+
"id" in one &&
|
|
8
|
+
"label" in one);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The actions split by who draws them: `dock`, the ones given as data, for the view style;
|
|
12
|
+
* `drawn`, a node drawn by hand, to put where it goes — `null` when there is none.
|
|
13
|
+
*/
|
|
14
|
+
export function actionsOf(actions) {
|
|
15
|
+
if (actions === undefined || actions === null || actions === false)
|
|
16
|
+
return { dock: [], drawn: null };
|
|
17
|
+
if (Array.isArray(actions) && actions.every(isDockAction))
|
|
18
|
+
return { dock: actions, drawn: null };
|
|
19
|
+
return { dock: [], drawn: actions };
|
|
20
|
+
}
|
|
@@ -17,10 +17,16 @@ export declare function groupableOf(meta: Meta | null, locale?: string, only?: r
|
|
|
17
17
|
/**
|
|
18
18
|
* The server's groups as piles, with the words a person reads, and each pile's group so that
|
|
19
19
|
* opening one reads its rows. Rows sit only on the deepest level, once read.
|
|
20
|
+
*
|
|
21
|
+
* What the server summed for a group is its `totals` — web-ui (2.9) says each figure under its
|
|
22
|
+
* column in a grouped table and a sheet, as Odoo's grouped list — and, in words beside the
|
|
23
|
+
* group's name (`detail`), what no column on screen says: a board's card has no columns.
|
|
20
24
|
*/
|
|
21
25
|
export declare function pilesOf<T extends AnyRecord>(buckets: readonly Bucket<T>[], levels: readonly GroupLevel[], meta: Meta | null, locale: string | undefined, rowsOf: (bucket: Bucket<T>) => readonly T[] | undefined,
|
|
22
26
|
/** What a group's next «more» brings (`Pile.more`); omitted, web-ui says nothing about it. */
|
|
23
|
-
brings?: (bucket: Bucket<T>) => number | false | undefined
|
|
27
|
+
brings?: (bucket: Bucket<T>) => number | false | undefined,
|
|
28
|
+
/** The figures a column on screen already says under itself: not said again in words. */
|
|
29
|
+
underColumns?: ReadonlySet<string>): {
|
|
24
30
|
piles: Pile<T>[];
|
|
25
31
|
bucketAt: ReadonlyMap<string, Bucket<T>>;
|
|
26
32
|
deepest: number;
|
package/dist/web/list/groups.js
CHANGED
|
@@ -42,13 +42,24 @@ export function groupableOf(meta, locale, only) {
|
|
|
42
42
|
...(field.type === "date" || field.type === "datetime" ? { grains: DATE_GRAINS } : {}),
|
|
43
43
|
}));
|
|
44
44
|
}
|
|
45
|
+
/** A summed figure as a number — the wire may carry an exact decimal as text («1204.50»). */
|
|
46
|
+
function figureOf(value) {
|
|
47
|
+
const figure = typeof value === "number" ? value : typeof value === "string" ? Number(value) : NaN;
|
|
48
|
+
return value === "" || !Number.isFinite(figure) ? undefined : figure;
|
|
49
|
+
}
|
|
45
50
|
/**
|
|
46
51
|
* The server's groups as piles, with the words a person reads, and each pile's group so that
|
|
47
52
|
* opening one reads its rows. Rows sit only on the deepest level, once read.
|
|
53
|
+
*
|
|
54
|
+
* What the server summed for a group is its `totals` — web-ui (2.9) says each figure under its
|
|
55
|
+
* column in a grouped table and a sheet, as Odoo's grouped list — and, in words beside the
|
|
56
|
+
* group's name (`detail`), what no column on screen says: a board's card has no columns.
|
|
48
57
|
*/
|
|
49
58
|
export function pilesOf(buckets, levels, meta, locale, rowsOf,
|
|
50
59
|
/** What a group's next «more» brings (`Pile.more`); omitted, web-ui says nothing about it. */
|
|
51
|
-
brings
|
|
60
|
+
brings,
|
|
61
|
+
/** The figures a column on screen already says under itself: not said again in words. */
|
|
62
|
+
underColumns = new Set()) {
|
|
52
63
|
const bucketAt = new Map();
|
|
53
64
|
const none = frameworkCopy().list.noValue;
|
|
54
65
|
const labelFor = (bucket, depth, key) => {
|
|
@@ -63,9 +74,18 @@ brings) {
|
|
|
63
74
|
}
|
|
64
75
|
return textOf(meta, bucket.field, bucket.value, locale) || key;
|
|
65
76
|
};
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
77
|
+
const summed = (bucket) => {
|
|
78
|
+
const measures = Object.entries(bucket.measures ?? {});
|
|
79
|
+
const totals = Object.fromEntries(measures.flatMap(([field, value]) => {
|
|
80
|
+
const figure = figureOf(value);
|
|
81
|
+
return figure === undefined ? [] : [[field, figure]];
|
|
82
|
+
}));
|
|
83
|
+
const inWords = measures.filter(([field]) => !underColumns.has(field));
|
|
84
|
+
const detail = detailOf(meta, Object.fromEntries(inWords), locale);
|
|
85
|
+
return {
|
|
86
|
+
...(Object.keys(totals).length === 0 ? {} : { totals }),
|
|
87
|
+
...(detail === undefined ? {} : { detail }),
|
|
88
|
+
};
|
|
69
89
|
};
|
|
70
90
|
const more = (bucket, deepest) => {
|
|
71
91
|
const next = deepest ? brings?.(bucket) : undefined;
|
|
@@ -83,7 +103,7 @@ brings) {
|
|
|
83
103
|
key,
|
|
84
104
|
label: labelFor(bucket, depth, key),
|
|
85
105
|
count: bucket.count,
|
|
86
|
-
...
|
|
106
|
+
...summed(bucket),
|
|
87
107
|
items: below.length === 0 ? [...(rowsOf(bucket) ?? [])] : [],
|
|
88
108
|
piles: walk(below, path, depth + 1),
|
|
89
109
|
...more(bucket, below.length === 0),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Rehearsal } from "../../react/useCommand.js";
|
|
2
2
|
import type { AskForm } from "./ask.js";
|
|
3
|
+
import { type ReactNode } from "react";
|
|
3
4
|
/** What a person filled in before the action runs, by field name. */
|
|
4
5
|
export type Asked = Readonly<Record<string, unknown>>;
|
|
5
6
|
/** What an action's window says, when the screen says it its way. */
|
|
@@ -54,3 +55,27 @@ export declare function ActionButton<R>({ action, label, role, disabled, ask: fo
|
|
|
54
55
|
dialog?: ActionDialog;
|
|
55
56
|
onDone?: (answer: R) => void;
|
|
56
57
|
}): import("react").JSX.Element;
|
|
58
|
+
/** An action's gesture, for whatever starts it — a button, a dock's action, a shortcut. */
|
|
59
|
+
export type ActionGesture = {
|
|
60
|
+
/** Starts it: opens what it asks, asks first what it would do (it destroys), or runs. */
|
|
61
|
+
start: () => void;
|
|
62
|
+
/** It runs: not offered again until it ends. */
|
|
63
|
+
busy: boolean;
|
|
64
|
+
/** Its window — what it asks, what it would do, a refusal —; `null` while closed. Put it
|
|
65
|
+
* anywhere on the screen: it opens over everything. */
|
|
66
|
+
dialog: ReactNode;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* `ActionButton`'s gesture without the button: started by anything, its window put where the
|
|
70
|
+
* screen puts it.
|
|
71
|
+
*
|
|
72
|
+
* Context: web-ui's dock (`Record.Dock`, the modern style's floating pill) takes actions as
|
|
73
|
+
* data — a label and an `onSelect` —, not buttons. The gesture is the same: `start` is the
|
|
74
|
+
* button's click, and `dialog` the window it opened.
|
|
75
|
+
*/
|
|
76
|
+
export declare function useActionGesture<R>(action: ButtonAction<R>, { label, ask: form, dialog, onDone, }: {
|
|
77
|
+
label: string;
|
|
78
|
+
ask?: AskForm;
|
|
79
|
+
dialog?: ActionDialog;
|
|
80
|
+
onDone?: (answer: R) => void;
|
|
81
|
+
}): ActionGesture;
|