@sincpro/web-ui 2.8.0 → 2.10.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 +152 -3
- package/dist/components/activity/Activity.js +3 -2
- package/dist/components/board/Board.d.ts +2 -1
- package/dist/components/board/Board.js +17 -1
- package/dist/components/form/Form.js +12 -3
- package/dist/components/form/FormIndex.d.ts +5 -1
- package/dist/components/form/FormIndex.js +71 -23
- package/dist/components/form/Sheet.js +22 -4
- package/dist/components/listing/ListingBar.d.ts +25 -1
- package/dist/components/listing/ListingBar.js +43 -14
- package/dist/components/listing/Pagination.d.ts +4 -1
- package/dist/components/listing/Pagination.js +19 -6
- package/dist/components/listing/modelCells.js +1 -9
- package/dist/components/record/ActionDock.d.ts +58 -0
- package/dist/components/record/ActionDock.js +69 -0
- package/dist/components/record/Breadcrumb.d.ts +3 -1
- package/dist/components/record/Breadcrumb.js +13 -5
- package/dist/components/record/DirtyActions.js +11 -1
- package/dist/components/record/Pager.d.ts +12 -10
- package/dist/components/record/Pager.js +39 -6
- package/dist/components/record/RecordHeader.d.ts +13 -1
- package/dist/components/record/RecordHeader.js +70 -25
- package/dist/components/record/SmartButtons.js +2 -2
- package/dist/components/record/StatusBar.d.ts +68 -1
- package/dist/components/record/StatusBar.js +218 -48
- package/dist/components/record/dock.d.ts +56 -0
- package/dist/components/record/dock.js +58 -0
- package/dist/components/record/index.d.ts +3 -1
- package/dist/components/record/index.js +5 -1
- package/dist/foundations/copy.d.ts +9 -0
- package/dist/foundations/copy.es.js +10 -1
- package/dist/foundations/copy.js +5 -0
- package/dist/foundations/form.d.ts +10 -1
- package/dist/foundations/grouping.d.ts +9 -0
- package/dist/foundations/index.d.ts +3 -1
- package/dist/foundations/index.js +8 -2
- package/dist/foundations/keys.d.ts +34 -0
- package/dist/foundations/keys.js +99 -0
- package/dist/foundations/shortcut.d.ts +17 -1
- package/dist/foundations/shortcut.js +57 -1
- package/dist/foundations/viewStyle.d.ts +8 -0
- package/dist/foundations/viewStyle.js +12 -0
- package/dist/primitives/choice/Switch.d.ts +4 -1
- package/dist/primitives/choice/Switch.js +2 -2
- package/dist/primitives/menu/Menu.d.ts +3 -0
- package/dist/primitives/menu/Menu.js +7 -1
- package/dist/primitives/table/DataTable.d.ts +29 -0
- package/dist/primitives/table/DataTable.js +84 -13
- package/dist/primitives/table/EditableTable.js +7 -2
- package/dist/primitives/table/RowActions.d.ts +5 -0
- package/dist/primitives/table/RowActions.js +27 -3
- package/dist/primitives/table/SheetTable.d.ts +3 -0
- package/dist/primitives/table/SheetTable.js +15 -2
- package/dist/primitives/table/index.d.ts +1 -1
- package/dist/primitives/value/Value.d.ts +5 -1
- package/dist/primitives/value/Value.js +9 -3
- package/dist/primitives/value/YesNo.d.ts +22 -0
- package/dist/primitives/value/YesNo.js +16 -0
- package/dist/primitives/value/index.d.ts +1 -0
- package/dist/primitives/value/index.js +1 -0
- package/dist/tokens.css +35 -2
- package/dist/views/list/List.d.ts +7 -2
- package/dist/views/list/List.js +12 -4
- package/dist/views/list/ListView.d.ts +1 -1
- package/dist/views/list/ListView.js +112 -17
- package/dist/views/list/derive.d.ts +1 -1
- package/dist/views/list/derive.js +45 -9
- package/dist/views/list/presentations.d.ts +2 -2
- package/dist/views/list/presentations.js +35 -3
- package/dist/views/list/types.d.ts +43 -0
- package/dist/views/list/useReachBottom.d.ts +15 -0
- package/dist/views/list/useReachBottom.js +55 -0
- package/dist/views/record/Record.d.ts +16 -2
- package/dist/views/record/Record.js +30 -7
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { MenuGroup, MenuOption } from "../../primitives/menu/Menu.js";
|
|
2
|
+
import type { LucideIcon } from "lucide-react";
|
|
3
|
+
/** One action of a dock. */
|
|
4
|
+
export interface DockAction {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
icon?: LucideIcon;
|
|
8
|
+
/** THE action the screen exists for: gold, always seen. One per dock — a second one is
|
|
9
|
+
* read as a secondary. */
|
|
10
|
+
primary?: boolean;
|
|
11
|
+
/** It destroys or undoes: drawn last in «Más», apart, never beside the primary. */
|
|
12
|
+
danger?: boolean;
|
|
13
|
+
/** In «Más» even with room: what is rarely done. */
|
|
14
|
+
tucked?: boolean;
|
|
15
|
+
onSelect?: () => void;
|
|
16
|
+
/** Sub-actions: «Imprimir ▸ Factura · Remito». Seen, the action is a menu button; in
|
|
17
|
+
* «Más», a submenu. Its own `onSelect` is not run — a row that opens does not also do. */
|
|
18
|
+
items?: readonly DockAction[];
|
|
19
|
+
/** The keys that run it, as people read them — «Ctrl+P». A hint in the menu. */
|
|
20
|
+
shortcut?: string;
|
|
21
|
+
/** The line under it, in the menu. */
|
|
22
|
+
hint?: string;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface DockPlan {
|
|
26
|
+
primary: DockAction | undefined;
|
|
27
|
+
/** The secondary actions seen, in order. */
|
|
28
|
+
shown: DockAction[];
|
|
29
|
+
/** «Más»: the rest, and the destructive ones apart. */
|
|
30
|
+
more: DockAction[];
|
|
31
|
+
danger: DockAction[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* What a dock shows for these actions, with room for `visible` secondary ones.
|
|
35
|
+
*
|
|
36
|
+
* in [Registrar pago*, Enviar, Imprimir▸, Duplicar, Anular!], visible 2
|
|
37
|
+
* out shown [Enviar, Imprimir] more [Duplicar] danger [Anular] primary Registrar pago
|
|
38
|
+
*/
|
|
39
|
+
export declare function dockPlan(actions: readonly DockAction[], visible?: number): DockPlan;
|
|
40
|
+
/** How a combination is drawn — the platform's way («⌥D», «Alt+D»); as written without one. */
|
|
41
|
+
export type KeysLabel = (keys: string) => string;
|
|
42
|
+
/** An action as a menu row — its sub-actions as a submenu, its shortcut drawn for this
|
|
43
|
+
* keyboard. */
|
|
44
|
+
export declare function dockOption(action: DockAction, label?: KeysLabel): MenuOption;
|
|
45
|
+
/** «Más» as menu groups: the rest, then the destructive ones apart. */
|
|
46
|
+
export declare function moreGroups(plan: DockPlan, label?: KeysLabel): MenuGroup[];
|
|
47
|
+
/**
|
|
48
|
+
* The combinations a dock answers: every action with a `shortcut` — sub-actions and what waits
|
|
49
|
+
* in «Más» included, a shortcut is how one reaches what is not in sight. None while there are
|
|
50
|
+
* changes: the actions are not there, and Save answers Mod+S itself (`DirtyActions`).
|
|
51
|
+
*/
|
|
52
|
+
export declare function dockShortcuts(actions: readonly DockAction[], dirty?: boolean): {
|
|
53
|
+
keys: string;
|
|
54
|
+
run: () => void;
|
|
55
|
+
enabled: boolean;
|
|
56
|
+
}[];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a dock shows for these actions, with room for `visible` secondary ones.
|
|
3
|
+
*
|
|
4
|
+
* in [Registrar pago*, Enviar, Imprimir▸, Duplicar, Anular!], visible 2
|
|
5
|
+
* out shown [Enviar, Imprimir] more [Duplicar] danger [Anular] primary Registrar pago
|
|
6
|
+
*/
|
|
7
|
+
export function dockPlan(actions, visible = 2) {
|
|
8
|
+
const primary = actions.find((one) => one.primary === true);
|
|
9
|
+
const rest = actions.filter((one) => one !== primary);
|
|
10
|
+
const danger = rest.filter((one) => one.danger === true);
|
|
11
|
+
const candidates = rest.filter((one) => one.danger !== true && one.tucked !== true);
|
|
12
|
+
const shown = candidates.slice(0, Math.max(0, visible));
|
|
13
|
+
const more = rest.filter((one) => one.danger !== true && !shown.includes(one));
|
|
14
|
+
/* One action alone in «Más» is drawn instead of the menu — unless it was tucked on purpose
|
|
15
|
+
or something destructive shares the menu with it. */
|
|
16
|
+
if (more.length === 1 && danger.length === 0 && more[0].tucked !== true) {
|
|
17
|
+
return { primary, shown: [...shown, more[0]], more: [], danger };
|
|
18
|
+
}
|
|
19
|
+
return { primary, shown, more, danger };
|
|
20
|
+
}
|
|
21
|
+
/** An action as a menu row — its sub-actions as a submenu, its shortcut drawn for this
|
|
22
|
+
* keyboard. */
|
|
23
|
+
export function dockOption(action, label = (keys) => keys) {
|
|
24
|
+
return {
|
|
25
|
+
id: action.id,
|
|
26
|
+
label: action.label,
|
|
27
|
+
...(action.icon === undefined ? {} : { icon: action.icon }),
|
|
28
|
+
...(action.hint === undefined ? {} : { hint: action.hint }),
|
|
29
|
+
...(action.shortcut === undefined ? {} : { shortcut: label(action.shortcut) }),
|
|
30
|
+
...(action.disabled === undefined ? {} : { disabled: action.disabled }),
|
|
31
|
+
...(action.danger === true ? { danger: true } : {}),
|
|
32
|
+
...(action.onSelect === undefined ? {} : { onSelect: action.onSelect }),
|
|
33
|
+
...(action.items === undefined
|
|
34
|
+
? {}
|
|
35
|
+
: { items: action.items.map((one) => dockOption(one, label)) }),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** «Más» as menu groups: the rest, then the destructive ones apart. */
|
|
39
|
+
export function moreGroups(plan, label) {
|
|
40
|
+
const option = (one) => dockOption(one, label);
|
|
41
|
+
return [
|
|
42
|
+
...(plan.more.length === 0 ? [] : [{ options: plan.more.map(option) }]),
|
|
43
|
+
...(plan.danger.length === 0 ? [] : [{ options: plan.danger.map(option) }]),
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The combinations a dock answers: every action with a `shortcut` — sub-actions and what waits
|
|
48
|
+
* in «Más» included, a shortcut is how one reaches what is not in sight. None while there are
|
|
49
|
+
* changes: the actions are not there, and Save answers Mod+S itself (`DirtyActions`).
|
|
50
|
+
*/
|
|
51
|
+
export function dockShortcuts(actions, dirty = false) {
|
|
52
|
+
if (dirty)
|
|
53
|
+
return [];
|
|
54
|
+
const all = (list) => list.flatMap((one) => [one, ...(one.items === undefined ? [] : all(one.items))]);
|
|
55
|
+
return all(actions).flatMap((one) => one.shortcut === undefined || one.onSelect === undefined
|
|
56
|
+
? []
|
|
57
|
+
: [{ keys: one.shortcut, run: one.onSelect, enabled: one.disabled !== true }]);
|
|
58
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
export { ActionDock, type ActionDockProps, type DockLook, type DockPlacement, type RecordDockPlacement, type RecordDockProps, } from "./ActionDock.js";
|
|
1
2
|
export { Breadcrumb, type Crumb } from "./Breadcrumb.js";
|
|
2
3
|
export { DirtyActions, type DirtyState, } from "./DirtyActions.js";
|
|
4
|
+
export { type DockAction, dockOption, type DockPlan, dockPlan, moreGroups, } from "./dock.js";
|
|
3
5
|
export { Pager } from "./Pager.js";
|
|
4
6
|
export { RecordAudit, type RecordStamp } from "./RecordAudit.js";
|
|
5
7
|
export { RecordRibbon } from "./RecordRibbon.js";
|
|
6
8
|
export { RecordSkeleton } from "./RecordSkeleton.js";
|
|
7
9
|
export { SmartButton, SmartButtons } from "./SmartButtons.js";
|
|
8
|
-
export { type Stage, StatusBar } from "./StatusBar.js";
|
|
10
|
+
export { type Stage, type StageState, StatusBar, type StatusDisplay, type StatusLook, } from "./StatusBar.js";
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/* RECORD PARTS — the header, status bar, pager and skeleton of one record. The `Record` view
|
|
2
2
|
composes them. */
|
|
3
|
+
/* The actions FLOATING, as data: what is seen and what waits in «Más» is
|
|
4
|
+
decided by `dockPlan`. */
|
|
5
|
+
export { ActionDock, } from "./ActionDock.js";
|
|
3
6
|
export { Breadcrumb } from "./Breadcrumb.js";
|
|
4
7
|
export { DirtyActions, } from "./DirtyActions.js";
|
|
8
|
+
export { dockOption, dockPlan, moreGroups, } from "./dock.js";
|
|
5
9
|
export { Pager } from "./Pager.js";
|
|
6
10
|
export { RecordAudit } from "./RecordAudit.js";
|
|
7
11
|
export { RecordRibbon } from "./RecordRibbon.js";
|
|
8
12
|
export { RecordSkeleton } from "./RecordSkeleton.js";
|
|
9
13
|
export { SmartButton, SmartButtons } from "./SmartButtons.js";
|
|
10
|
-
export { StatusBar } from "./StatusBar.js";
|
|
14
|
+
export { StatusBar, } from "./StatusBar.js";
|
|
@@ -62,6 +62,13 @@ export type UiCopy = {
|
|
|
62
62
|
prev: string;
|
|
63
63
|
next: string;
|
|
64
64
|
};
|
|
65
|
+
/** The floating action dock (`ActionDock`). */
|
|
66
|
+
dock: {
|
|
67
|
+
/** The toolbar's name, when the screen does not give one. */
|
|
68
|
+
label: string;
|
|
69
|
+
/** «Más»: the actions that did not fit. */
|
|
70
|
+
more: string;
|
|
71
|
+
};
|
|
65
72
|
record: {
|
|
66
73
|
prev: string;
|
|
67
74
|
next: string;
|
|
@@ -621,6 +628,8 @@ export type UiCopy = {
|
|
|
621
628
|
/** The header of the first column, which is read aloud and not
|
|
622
629
|
* drawn: without it, a screen reader announces a column with no name. */
|
|
623
630
|
concept: string;
|
|
631
|
+
/** The line that closes a report built from the piles: what all of them add up to. */
|
|
632
|
+
total: string;
|
|
624
633
|
};
|
|
625
634
|
/**
|
|
626
635
|
* THE BUILDER of criteria: the words of its sections and its controls.
|
|
@@ -65,6 +65,10 @@ export const SPANISH_COPY = {
|
|
|
65
65
|
prev: "Página anterior",
|
|
66
66
|
next: "Página siguiente",
|
|
67
67
|
},
|
|
68
|
+
dock: {
|
|
69
|
+
label: "Acciones",
|
|
70
|
+
more: "Más acciones",
|
|
71
|
+
},
|
|
68
72
|
record: {
|
|
69
73
|
prev: "Anterior",
|
|
70
74
|
next: "Siguiente",
|
|
@@ -410,7 +414,12 @@ export const SPANISH_COPY = {
|
|
|
410
414
|
finish: "Terminar",
|
|
411
415
|
working: "Procesando…",
|
|
412
416
|
},
|
|
413
|
-
report: {
|
|
417
|
+
report: {
|
|
418
|
+
open: "Abrir {name}",
|
|
419
|
+
close: "Cerrar {name}",
|
|
420
|
+
concept: "Concepto",
|
|
421
|
+
total: "Total",
|
|
422
|
+
},
|
|
414
423
|
builder: {
|
|
415
424
|
filter: "Filtro",
|
|
416
425
|
order: "Orden",
|
package/dist/foundations/copy.js
CHANGED
|
@@ -41,6 +41,10 @@ export const ENGLISH_COPY = {
|
|
|
41
41
|
prev: "Previous page",
|
|
42
42
|
next: "Next page",
|
|
43
43
|
},
|
|
44
|
+
dock: {
|
|
45
|
+
label: "Actions",
|
|
46
|
+
more: "More actions",
|
|
47
|
+
},
|
|
44
48
|
record: {
|
|
45
49
|
prev: "Previous record",
|
|
46
50
|
next: "Next record",
|
|
@@ -400,6 +404,7 @@ export const ENGLISH_COPY = {
|
|
|
400
404
|
open: "Open {name}",
|
|
401
405
|
close: "Close {name}",
|
|
402
406
|
concept: "Item",
|
|
407
|
+
total: "Total",
|
|
403
408
|
},
|
|
404
409
|
builder: {
|
|
405
410
|
filter: "Filter",
|
|
@@ -79,7 +79,16 @@ export declare function FormModeProvider({ value, children, }: {
|
|
|
79
79
|
/** The mode of this field. The prop beats the context — a computed field stays
|
|
80
80
|
* in read mode inside a form that is being edited. */
|
|
81
81
|
export declare function useFormMode(explicit?: FormMode): FormMode;
|
|
82
|
-
|
|
82
|
+
/**
|
|
83
|
+
* dense the ERP's sheet: one white paper, groups side by side, a notebook of tabs.
|
|
84
|
+
* settings a back office's form: each section a card of rows that explain themselves —
|
|
85
|
+
* the label, its help under it, the control beside —, an index at the left.
|
|
86
|
+
* sections the DENSE sheet in the settings' shape: each group and each notebook page a
|
|
87
|
+
* card, on the ground, with the index at the left — and inside, the dense grid
|
|
88
|
+
* (label | value, two or three columns). A long record found by its index
|
|
89
|
+
* instead of hidden behind tabs, without losing a line of density.
|
|
90
|
+
*/
|
|
91
|
+
export type FormStyle = "dense" | "settings" | "sections";
|
|
83
92
|
export declare function FormStyleProvider({ value, children, }: {
|
|
84
93
|
value: FormStyle;
|
|
85
94
|
children: ReactNode;
|
|
@@ -99,6 +99,15 @@ export type Pile<T> = {
|
|
|
99
99
|
/** What the pile ADDS UP TO, already written — «Total Bs 1.204.933» — summed by whoever
|
|
100
100
|
* keeps the data over EVERY row in it, like the count. Drawn in the pile's header. */
|
|
101
101
|
detail?: string;
|
|
102
|
+
/**
|
|
103
|
+
* What each COLUMN adds up to over every row in the pile, by column id (or the column's
|
|
104
|
+
* `field`) — what the server's grouped read summed: `{ amount_total: 1204933.5 }`. Drawn in
|
|
105
|
+
* the pile's row, UNDER its column, written like the column's footer.
|
|
106
|
+
*
|
|
107
|
+
* Absent, a table sums the rows the pile holds — only when it holds all of them: the sum of
|
|
108
|
+
* one page of a pile of thousands looks like its total and is not.
|
|
109
|
+
*/
|
|
110
|
+
totals?: Readonly<Record<string, number>>;
|
|
102
111
|
/** The rows, at the DEEPEST level. Empty in the ones above: a pile that
|
|
103
112
|
* has piles inside has no rows of its own. */
|
|
104
113
|
items: readonly T[];
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { type CopyCatalog, type CopyOverride, createCopy, mergeCopyOver, } from "./catalog.js";
|
|
2
2
|
export { currentCopy, currentCopyLocale, ENGLISH_COPY, fillCopy, installCopy, mergeCopy, type UiCopy, type UiCopyOverride, UiCopyProvider, useUiCopy, } from "./copy.js";
|
|
3
3
|
export { byDensity, type Density, DensityProvider, useDensity, } from "./density.js";
|
|
4
|
+
export { useViewStyle, type ViewStyle, ViewStyleProvider, } from "./viewStyle.js";
|
|
4
5
|
export { controlName, FieldBoundary, type FieldIds, type FormMode, FormModeProvider, type FormStyle, FormStyleProvider, useFieldIds, useFormMode, useFormStyle, } from "./form.js";
|
|
5
|
-
export { type
|
|
6
|
+
export { type KeyPress, type Keys, keysAria, keysLabel, matchesKeys, needsModifier, type ParsedKeys, parseKeys, } from "./keys.js";
|
|
7
|
+
export { type KeyboardPlatform, type ModShortcut, modShortcut, type Shortcut, useKeyboardPlatform, useKeysHint, useShortcuts, } from "./shortcut.js";
|
|
6
8
|
export { bySurface, SurfaceProvider, useSurface } from "./surface.js";
|
|
7
9
|
export { applyTheme, isTheme, type ResolvedTheme, resolveTheme, type Theme, THEME_ATTRIBUTE, ThemeProvider, type ThemeProviderProps, THEMES, useTheme, } from "./theme.js";
|
|
8
10
|
export type { OpenTarget, Size, Surface, Tone } from "./types.js";
|
|
@@ -3,11 +3,17 @@
|
|
|
3
3
|
export { createCopy, mergeCopyOver, } from "./catalog.js";
|
|
4
4
|
export { currentCopy, currentCopyLocale, ENGLISH_COPY, fillCopy, installCopy, mergeCopy, UiCopyProvider, useUiCopy, } from "./copy.js";
|
|
5
5
|
export { byDensity, DensityProvider, useDensity, } from "./density.js";
|
|
6
|
+
/* How a whole application draws its views — `traditional` or `modern` (the direction): the
|
|
7
|
+
record's rail and the actions of a record and of a list. Set once, like the density. */
|
|
8
|
+
export { useViewStyle, ViewStyleProvider, } from "./viewStyle.js";
|
|
6
9
|
/* A CONTROL'S CONTRACT — the ids its `Field` gives it and whether it is viewed or written. The
|
|
7
10
|
package's controls and the application's speak it alike. */
|
|
8
11
|
export { controlName, FieldBoundary, FormModeProvider, FormStyleProvider, useFieldIds, useFormMode, useFormStyle, } from "./form.js";
|
|
9
|
-
/* A SHORTCUT, drawn the way the person's keyboard says it
|
|
10
|
-
|
|
12
|
+
/* A SHORTCUT, drawn the way the person's keyboard says it («⌘K» on a Mac, «Ctrl K» elsewhere),
|
|
13
|
+
and BOUND: `useShortcuts` runs it while the piece that declares it is on screen — the last
|
|
14
|
+
mounted wins. A combination is written once («Alt+D», «Mod+S») and read by `foundations/keys`. */
|
|
15
|
+
export { keysAria, keysLabel, matchesKeys, needsModifier, parseKeys, } from "./keys.js";
|
|
16
|
+
export { modShortcut, useKeyboardPlatform, useKeysHint, useShortcuts, } from "./shortcut.js";
|
|
11
17
|
/* THE THEME — light, dark or the operating system's. The palettes live in `tokens.css`; this
|
|
12
18
|
only writes `data-theme`. */
|
|
13
19
|
export { bySurface, SurfaceProvider, useSurface } from "./surface.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** The keyboard the page is used with — what a combination is drawn and matched for. */
|
|
2
|
+
export type KeyboardPlatform = "apple" | "other";
|
|
3
|
+
/** A combination as written: «Alt+D», «Mod+S», «Alt+Shift+P», «Escape». */
|
|
4
|
+
export type Keys = string;
|
|
5
|
+
export interface ParsedKeys {
|
|
6
|
+
alt: boolean;
|
|
7
|
+
shift: boolean;
|
|
8
|
+
ctrl: boolean;
|
|
9
|
+
meta: boolean;
|
|
10
|
+
/** The platform's command key: ⌘ on a Mac, Ctrl elsewhere. */
|
|
11
|
+
mod: boolean;
|
|
12
|
+
/** The key itself, as written: «D», «S», «ArrowLeft», «Escape». */
|
|
13
|
+
key: string;
|
|
14
|
+
}
|
|
15
|
+
/** What a keydown carries that a combination is compared to. */
|
|
16
|
+
export interface KeyPress {
|
|
17
|
+
key: string;
|
|
18
|
+
code: string;
|
|
19
|
+
altKey: boolean;
|
|
20
|
+
shiftKey: boolean;
|
|
21
|
+
ctrlKey: boolean;
|
|
22
|
+
metaKey: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare function parseKeys(keys: Keys): ParsedKeys;
|
|
25
|
+
/** Whether the press IS the combination — every modifier exactly, the key by its place when it
|
|
26
|
+
* is a letter or a digit (layouts and Alt change what it types, not where it is). */
|
|
27
|
+
export declare function matchesKeys(press: KeyPress, keys: Keys, platform: KeyboardPlatform): boolean;
|
|
28
|
+
/** Whether the combination needs a modifier — then it works while a field is being typed in;
|
|
29
|
+
* a bare key does not, or typing «d» would duplicate the record. */
|
|
30
|
+
export declare function needsModifier(keys: Keys): boolean;
|
|
31
|
+
/** How the combination is drawn on this keyboard: «⌥D» on a Mac, «Alt+D» elsewhere. */
|
|
32
|
+
export declare function keysLabel(keys: Keys, platform: KeyboardPlatform | null): string;
|
|
33
|
+
/** What `aria-keyshortcuts` says on this keyboard: «Alt+D», «Meta+S». */
|
|
34
|
+
export declare function keysAria(keys: Keys, platform: KeyboardPlatform | null): string;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/* ==================================================================== *
|
|
2
|
+
* A KEY COMBINATION — written once, pressed on any keyboard, read the way that keyboard says it.
|
|
3
|
+
*
|
|
4
|
+
* Context: an ERP is worked from the keyboard — next record, duplicate, save — and a shortcut
|
|
5
|
+
* written as a hint in a menu that nothing binds is a promise the screen does not keep. The
|
|
6
|
+
* combination is written ONE way and this module reads it three:
|
|
7
|
+
*
|
|
8
|
+
* "Alt+D" what is written: modifiers, then the key, joined with «+»
|
|
9
|
+
* matchesKeys whether a keydown IS it — by the key's PLACE for a letter or a digit
|
|
10
|
+
* (`KeyD`), so Alt+D on a Mac, where it types «∂», still matches
|
|
11
|
+
* keysLabel how it is drawn: «⌥D» on a Mac, «Alt+D» elsewhere
|
|
12
|
+
* keysAria what `aria-keyshortcuts` says: «Alt+D»
|
|
13
|
+
*
|
|
14
|
+
* `Mod` is the platform's command key — ⌘ on a Mac, Ctrl elsewhere —: «Mod+S» saves on both.
|
|
15
|
+
* Pure: what is bound and when lives in `useShortcuts`.
|
|
16
|
+
* ==================================================================== */
|
|
17
|
+
export function parseKeys(keys) {
|
|
18
|
+
const parts = keys.split("+").map((one) => one.trim());
|
|
19
|
+
const key = parts.pop() ?? "";
|
|
20
|
+
const has = (name) => parts.some((one) => one.toLowerCase() === name);
|
|
21
|
+
return {
|
|
22
|
+
alt: has("alt") || has("option"),
|
|
23
|
+
shift: has("shift"),
|
|
24
|
+
ctrl: has("ctrl") || has("control"),
|
|
25
|
+
meta: has("meta") || has("cmd"),
|
|
26
|
+
mod: has("mod"),
|
|
27
|
+
key,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Whether the press IS the combination — every modifier exactly, the key by its place when it
|
|
31
|
+
* is a letter or a digit (layouts and Alt change what it types, not where it is). */
|
|
32
|
+
export function matchesKeys(press, keys, platform) {
|
|
33
|
+
const want = parseKeys(keys);
|
|
34
|
+
const ctrl = want.ctrl || (want.mod && platform === "other");
|
|
35
|
+
const meta = want.meta || (want.mod && platform === "apple");
|
|
36
|
+
if (press.altKey !== want.alt ||
|
|
37
|
+
press.shiftKey !== want.shift ||
|
|
38
|
+
press.ctrlKey !== ctrl ||
|
|
39
|
+
press.metaKey !== meta)
|
|
40
|
+
return false;
|
|
41
|
+
if (/^[a-z]$/i.test(want.key))
|
|
42
|
+
return press.code === `Key${want.key.toUpperCase()}`;
|
|
43
|
+
if (/^\d$/.test(want.key))
|
|
44
|
+
return press.code === `Digit${want.key}`;
|
|
45
|
+
return press.key.toLowerCase() === want.key.toLowerCase();
|
|
46
|
+
}
|
|
47
|
+
/** Whether the combination needs a modifier — then it works while a field is being typed in;
|
|
48
|
+
* a bare key does not, or typing «d» would duplicate the record. */
|
|
49
|
+
export function needsModifier(keys) {
|
|
50
|
+
const want = parseKeys(keys);
|
|
51
|
+
return want.alt || want.ctrl || want.meta || want.mod;
|
|
52
|
+
}
|
|
53
|
+
const APPLE = {
|
|
54
|
+
alt: "⌥",
|
|
55
|
+
shift: "⇧",
|
|
56
|
+
ctrl: "⌃",
|
|
57
|
+
meta: "⌘",
|
|
58
|
+
mod: "⌘",
|
|
59
|
+
};
|
|
60
|
+
const OTHER = {
|
|
61
|
+
alt: "Alt",
|
|
62
|
+
shift: "Shift",
|
|
63
|
+
ctrl: "Ctrl",
|
|
64
|
+
meta: "Meta",
|
|
65
|
+
mod: "Ctrl",
|
|
66
|
+
};
|
|
67
|
+
const KEY_WORDS = {
|
|
68
|
+
ArrowLeft: "←",
|
|
69
|
+
ArrowRight: "→",
|
|
70
|
+
ArrowUp: "↑",
|
|
71
|
+
ArrowDown: "↓",
|
|
72
|
+
Escape: "Esc",
|
|
73
|
+
Enter: "↵",
|
|
74
|
+
};
|
|
75
|
+
/** How the combination is drawn on this keyboard: «⌥D» on a Mac, «Alt+D» elsewhere. */
|
|
76
|
+
export function keysLabel(keys, platform) {
|
|
77
|
+
if (platform === null)
|
|
78
|
+
return keys;
|
|
79
|
+
const want = parseKeys(keys);
|
|
80
|
+
const key = KEY_WORDS[want.key] ?? want.key.toUpperCase();
|
|
81
|
+
const names = platform === "apple" ? APPLE : OTHER;
|
|
82
|
+
const mods = ["mod", "ctrl", "alt", "shift", "meta"]
|
|
83
|
+
.filter((one) => want[one] && !(one === "meta" && want.mod))
|
|
84
|
+
.map((one) => names[one]);
|
|
85
|
+
return platform === "apple" ? [...mods, key].join("") : [...mods, key].join("+");
|
|
86
|
+
}
|
|
87
|
+
/** What `aria-keyshortcuts` says on this keyboard: «Alt+D», «Meta+S». */
|
|
88
|
+
export function keysAria(keys, platform) {
|
|
89
|
+
const want = parseKeys(keys);
|
|
90
|
+
const mod = platform === "apple" ? "Meta" : "Control";
|
|
91
|
+
return [
|
|
92
|
+
...(want.mod ? [mod] : []),
|
|
93
|
+
...(want.ctrl ? ["Control"] : []),
|
|
94
|
+
...(want.meta && !want.mod ? ["Meta"] : []),
|
|
95
|
+
...(want.alt ? ["Alt"] : []),
|
|
96
|
+
...(want.shift ? ["Shift"] : []),
|
|
97
|
+
want.key.length === 1 ? want.key.toUpperCase() : want.key,
|
|
98
|
+
].join("+");
|
|
99
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type KeyboardPlatform, type Keys } from "./keys.js";
|
|
1
2
|
/**
|
|
2
3
|
* Context: a shortcut is drawn the way the person's keyboard says it — «⌘K» on a Mac, «Ctrl K»
|
|
3
4
|
* everywhere else. A «Ctrl K» on a Mac is a shortcut that does not work, and people stop
|
|
@@ -5,7 +6,7 @@
|
|
|
5
6
|
* it is `null`, and the shortcut appears right after instead of being drawn wrong and
|
|
6
7
|
* corrected in front of the person.
|
|
7
8
|
*/
|
|
8
|
-
export type KeyboardPlatform
|
|
9
|
+
export type { KeyboardPlatform };
|
|
9
10
|
/** The keyboard the page is being used with; `null` on the server and while hydrating. */
|
|
10
11
|
export declare function useKeyboardPlatform(): KeyboardPlatform | null;
|
|
11
12
|
export type ModShortcut = {
|
|
@@ -16,3 +17,18 @@ export type ModShortcut = {
|
|
|
16
17
|
};
|
|
17
18
|
/** The platform's command key with `key`: ⌘ on a Mac, Ctrl elsewhere. */
|
|
18
19
|
export declare function modShortcut(key: string, platform: KeyboardPlatform): ModShortcut;
|
|
20
|
+
export interface Shortcut {
|
|
21
|
+
/** «Alt+D», «Mod+S», «Alt+P»: see `foundations/keys`. */
|
|
22
|
+
keys: Keys;
|
|
23
|
+
run: () => void;
|
|
24
|
+
/** Off for now — an action disabled, a pager at its end. */
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** Binds these combinations while the calling piece is mounted — the last mounted wins. */
|
|
28
|
+
export declare function useShortcuts(shortcuts: readonly Shortcut[]): void;
|
|
29
|
+
/** How a combination is drawn and announced on this keyboard: the label for a tooltip or a
|
|
30
|
+
* menu, `aria-keyshortcuts` for the control. `undefined` until the platform is known. */
|
|
31
|
+
export declare function useKeysHint(keys: Keys | undefined): {
|
|
32
|
+
label: string;
|
|
33
|
+
aria: string;
|
|
34
|
+
} | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { keysAria, keysLabel, matchesKeys, needsModifier, } from "./keys.js";
|
|
3
|
+
import { useEffect, useRef, useSyncExternalStore } from "react";
|
|
3
4
|
function readPlatform() {
|
|
4
5
|
const nav = navigator;
|
|
5
6
|
/* `userAgentData` where there is one (Chromium); `platform` is deprecated but it is the
|
|
@@ -18,3 +19,58 @@ export function modShortcut(key, platform) {
|
|
|
18
19
|
? { label: `⌘${key}`, aria: `Meta+${key}` }
|
|
19
20
|
: { label: `Ctrl ${key}`, aria: `Control+${key}` };
|
|
20
21
|
}
|
|
22
|
+
const stack = [];
|
|
23
|
+
function editable(target) {
|
|
24
|
+
if (!(target instanceof HTMLElement))
|
|
25
|
+
return false;
|
|
26
|
+
return (target.isContentEditable ||
|
|
27
|
+
target.tagName === "INPUT" ||
|
|
28
|
+
target.tagName === "TEXTAREA" ||
|
|
29
|
+
target.tagName === "SELECT");
|
|
30
|
+
}
|
|
31
|
+
function onKeyDown(event) {
|
|
32
|
+
if (event.defaultPrevented || event.isComposing)
|
|
33
|
+
return;
|
|
34
|
+
const platform = readPlatform();
|
|
35
|
+
for (let at = stack.length - 1; at >= 0; at--) {
|
|
36
|
+
for (const one of stack[at].current) {
|
|
37
|
+
if (one.enabled === false || !matchesKeys(event, one.keys, platform))
|
|
38
|
+
continue;
|
|
39
|
+
if (!needsModifier(one.keys) && editable(event.target))
|
|
40
|
+
continue;
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
one.run();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Binds these combinations while the calling piece is mounted — the last mounted wins. */
|
|
48
|
+
export function useShortcuts(shortcuts) {
|
|
49
|
+
const latest = useRef(shortcuts);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
latest.current = shortcuts;
|
|
52
|
+
});
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const entry = latest;
|
|
55
|
+
stack.push(entry);
|
|
56
|
+
if (stack.length === 1)
|
|
57
|
+
window.addEventListener("keydown", onKeyDown);
|
|
58
|
+
return () => {
|
|
59
|
+
const at = stack.indexOf(entry);
|
|
60
|
+
if (at >= 0)
|
|
61
|
+
stack.splice(at, 1);
|
|
62
|
+
if (stack.length === 0)
|
|
63
|
+
window.removeEventListener("keydown", onKeyDown);
|
|
64
|
+
};
|
|
65
|
+
}, []);
|
|
66
|
+
}
|
|
67
|
+
/** How a combination is drawn and announced on this keyboard: the label for a tooltip or a
|
|
68
|
+
* menu, `aria-keyshortcuts` for the control. `undefined` until the platform is known. */
|
|
69
|
+
export function useKeysHint(keys) {
|
|
70
|
+
const platform = useKeyboardPlatform();
|
|
71
|
+
/* On the server the keyboard is unknown: no hint rather than a wrong one (Ctrl on a Mac). It
|
|
72
|
+
appears after hydration, as the search entry's does. */
|
|
73
|
+
return keys === undefined || platform === null
|
|
74
|
+
? undefined
|
|
75
|
+
: { label: keysLabel(keys, platform), aria: keysAria(keys, platform) };
|
|
76
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type ViewStyle = "traditional" | "modern";
|
|
3
|
+
export declare function ViewStyleProvider({ value, children, }: {
|
|
4
|
+
value: ViewStyle;
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
/** The style in force: the record's own, else the provider's. */
|
|
8
|
+
export declare function useViewStyle(own?: ViewStyle): ViewStyle;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext } from "react";
|
|
4
|
+
const Ctx = createContext("traditional");
|
|
5
|
+
export function ViewStyleProvider({ value, children, }) {
|
|
6
|
+
return _jsx(Ctx.Provider, { value: value, children: children });
|
|
7
|
+
}
|
|
8
|
+
/** The style in force: the record's own, else the provider's. */
|
|
9
|
+
export function useViewStyle(own) {
|
|
10
|
+
const inherited = useContext(Ctx);
|
|
11
|
+
return own ?? inherited;
|
|
12
|
+
}
|
|
@@ -10,5 +10,8 @@ export type SwitchProps = {
|
|
|
10
10
|
describedBy?: string;
|
|
11
11
|
/** Forces the mode. By default it inherits the form's: in read mode it draws the answer. */
|
|
12
12
|
mode?: FormMode;
|
|
13
|
+
/** Its name when there is no `Field` and no sentence beside it — a switch in a table cell,
|
|
14
|
+
* named by its column. */
|
|
15
|
+
label?: string;
|
|
13
16
|
};
|
|
14
|
-
export declare function Switch({ checked, onChange, children, disabled, id: ownId, describedBy: ownDescribedBy, mode, }: SwitchProps): import("react").JSX.Element;
|
|
17
|
+
export declare function Switch({ checked, onChange, children, disabled, id: ownId, describedBy: ownDescribedBy, mode, label, }: SwitchProps): import("react").JSX.Element;
|
|
@@ -43,7 +43,7 @@ const thumb = tv({
|
|
|
43
43
|
},
|
|
44
44
|
},
|
|
45
45
|
});
|
|
46
|
-
export function Switch({ checked, onChange, children, disabled = false, id: ownId, describedBy: ownDescribedBy, mode, }) {
|
|
46
|
+
export function Switch({ checked, onChange, children, disabled = false, id: ownId, describedBy: ownDescribedBy, mode, label, }) {
|
|
47
47
|
const { id, labelledBy, describedBy } = useFieldIds({
|
|
48
48
|
id: ownId,
|
|
49
49
|
describedBy: ownDescribedBy,
|
|
@@ -58,7 +58,7 @@ export function Switch({ checked, onChange, children, disabled = false, id: ownI
|
|
|
58
58
|
if (useFormMode(mode) === "read") {
|
|
59
59
|
return (_jsxs("span", { className: "flex min-h-(--size-control-md) items-center gap-1.5 text-meta text-ink", children: [checked ? (_jsx(Check, { "aria-hidden": true, className: "size-(--size-icon-sm) text-good", strokeWidth: 2.5 })) : (_jsx(Minus, { "aria-hidden": true, className: "size-(--size-icon-sm) text-muted", strokeWidth: 2.5 })), children] }));
|
|
60
60
|
}
|
|
61
|
-
return (_jsx(AriaSwitch, { id: id, "aria-labelledby": named, "aria-describedby": describedBy, isSelected: checked, onChange: (next) => onChange?.(next), isDisabled: disabled,
|
|
61
|
+
return (_jsx(AriaSwitch, { id: id, "aria-labelledby": named, ...(named === undefined && label !== undefined ? { "aria-label": label } : {}), "aria-describedby": describedBy, isSelected: checked, onChange: (next) => onChange?.(next), isDisabled: disabled,
|
|
62
62
|
/* The height of a control, so a switch alone in a field lines up with a text input in
|
|
63
63
|
the next column. */
|
|
64
64
|
className: "group inline-flex min-h-(--size-control-md) min-w-0 cursor-pointer items-center gap-2.5 text-meta text-ink disabled:cursor-not-allowed disabled:opacity-45", children: (state) => (_jsxs(_Fragment, { children: [_jsx("span", { className: track(state), children: _jsx("span", { className: thumb(state) }) }), children === undefined ? null : (_jsx("span", { id: textId, className: "min-w-0", children: children }))] })) }));
|
|
@@ -34,6 +34,9 @@ export interface MenuOption {
|
|
|
34
34
|
* exist until it is opened. In an ERP the frequent verbs have a shortcut, and the menu
|
|
35
35
|
* is where people learn it. */
|
|
36
36
|
shortcut?: string;
|
|
37
|
+
/** It destroys or undoes — «Anular», «Eliminar»: the label and its icon in the danger tone,
|
|
38
|
+
* so it is read before it is pressed. Put such options in a group of their own, last. */
|
|
39
|
+
danger?: boolean;
|
|
37
40
|
/** The option opens a SUBMENU with these options instead of running. Its own `onSelect`
|
|
38
41
|
* and `checked` are ignored — a row that opens something does not also do something.
|
|
39
42
|
* Children may carry `items` too, but a third level is usually a dialog in disguise. */
|
|
@@ -135,7 +135,13 @@ export function MenuList({ label, groups, onAction, closeOnSelect, emptyText, wi
|
|
|
135
135
|
const Icon = o.icon;
|
|
136
136
|
const opens = o.items !== undefined;
|
|
137
137
|
const checked = !opens && o.checked === true;
|
|
138
|
-
return (_jsxs(MenuItem, { id: o.id, textValue: o.hint === undefined ? o.label : `${o.label} ${o.hint}`, isDisabled: o.disabled, "data-ui": "menu.item", className: `flex w-full cursor-default rounded-ui-option ${hasHints ? "items-start py-1.5" : "items-center py-1"} gap-2 ${nested ? "pr-2 pl-(--spacing-indent)" : "px-2"} text-left outline-0 transition-colors duration-(--duration-instant)
|
|
138
|
+
return (_jsxs(MenuItem, { id: o.id, textValue: o.hint === undefined ? o.label : `${o.label} ${o.hint}`, isDisabled: o.disabled, "data-ui": "menu.item", className: `flex w-full cursor-default rounded-ui-option ${hasHints ? "items-start py-1.5" : "items-center py-1"} gap-2 ${nested ? "pr-2 pl-(--spacing-indent)" : "px-2"} text-left outline-0 transition-colors duration-(--duration-instant) ${o.danger === true
|
|
139
|
+
? "data-focused:bg-danger/10"
|
|
140
|
+
: "data-focused:bg-ui-option-active data-open:bg-ui-option-active"} disabled:opacity-45`, children: [hasMarks ? (_jsx("span", { className: `${hasHints ? "mt-0.5" : ""} flex size-(--size-icon-sm) shrink-0 items-center justify-center`, children: checked ? (_jsx(Check, { className: "size-(--size-icon-sm) text-primary", strokeWidth: 2.5, "aria-hidden": true })) : Icon !== undefined ? (_jsx(Icon, { className: `size-(--size-icon-sm) ${o.danger === true ? "text-danger" : "text-muted"}`, strokeWidth: 2, "aria-hidden": true })) : null })) : null, _jsxs("span", { className: "min-w-0 flex-1", children: [_jsxs("span", { className: "flex items-center gap-1.5", children: [_jsx("span", { className: `truncate text-meta ${o.danger === true
|
|
141
|
+
? "text-danger"
|
|
142
|
+
: checked
|
|
143
|
+
? "font-medium text-ink"
|
|
144
|
+
: "text-ink"}`, children: o.label }), o.badge === undefined ? null : typeof o.badge === "number" ? (_jsx("span", { className: "ml-auto flex shrink-0", children: _jsx(Count, { value: o.badge }) })) : typeof o.badge === "string" ? (_jsx("span", { className: "inline-flex shrink-0 items-center rounded-pill border border-warn/30 bg-warn/10 px-2 py-0.5 text-micro text-warn", children: o.badge })) : (_jsx("span", { className: "ml-auto shrink-0", children: o.badge }))] }), o.hint === undefined ? null : (_jsx("span", { className: "mt-0.5 block truncate text-micro text-muted", children: o.hint }))] }), o.shortcut === undefined ? null : (_jsx(Keyboard, { className: "shrink-0 self-center pl-3 font-mono text-micro text-muted", children: o.shortcut })), opens ? (_jsx(ChevronRight, { className: "size-(--size-icon-sm) shrink-0 self-center text-muted", strokeWidth: 2, "aria-hidden": true })) : null] }, o.id));
|
|
139
145
|
};
|
|
140
146
|
return (_jsx(AriaMenu, { "data-ui": "menu", "aria-label": label, shouldCloseOnSelect: closeOnSelect, onAction: act, renderEmptyState: () => (_jsx("p", { className: "px-3 py-3 text-meta text-muted italic", children: emptyText })), className: `max-h-[inherit] overflow-y-auto p-1 outline-0 ${layout === "columns" ? "flex flex-col sm:flex-row sm:items-stretch" : ""}`, children: groups.map((g, gi) => {
|
|
141
147
|
const key = sectionKey(g, gi);
|