@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,55 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useLayoutEffect, useState } from "react";
|
|
3
|
+
/** The nearest ancestor that scrolls vertically; `null` when it is the window. */
|
|
4
|
+
function scrollerOf(el) {
|
|
5
|
+
for (let at = el.parentElement; at !== null; at = at.parentElement) {
|
|
6
|
+
const y = getComputedStyle(at).overflowY;
|
|
7
|
+
if (y === "auto" || y === "scroll")
|
|
8
|
+
return at;
|
|
9
|
+
}
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* How tall a list must be to reach the bottom of what scrolls it — so its floating pill sits at
|
|
14
|
+
* the bottom of the SCREEN, not right under the last row.
|
|
15
|
+
*
|
|
16
|
+
* Context: the pill is sticky to the bottom of the list (`mt-auto`), which is the bottom of the
|
|
17
|
+
* screen only while the list is taller than the screen. A list of six courses ended a third of the
|
|
18
|
+
* way down and its pill floated there, under the sixth row: its place moved with how many rows
|
|
19
|
+
* there were. With this as its `min-height` the list reaches the bottom of its scroll box (the
|
|
20
|
+
* window, or the view's own box), and the pill has ONE place.
|
|
21
|
+
*
|
|
22
|
+
* Measured once and on resize — never on scroll: where the list starts within what scrolls does
|
|
23
|
+
* not change while scrolling. Nothing is measured on the server; the pill settles after hydration.
|
|
24
|
+
*/
|
|
25
|
+
export function useReachBottom(frame, on) {
|
|
26
|
+
const [min, setMin] = useState();
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
const el = frame.current;
|
|
29
|
+
if (!on || el === null) {
|
|
30
|
+
setMin(undefined);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const scroller = scrollerOf(el);
|
|
34
|
+
const measure = () => {
|
|
35
|
+
const viewTop = scroller === null ? 0 : scroller.getBoundingClientRect().top;
|
|
36
|
+
const viewHeight = scroller === null ? window.innerHeight : scroller.clientHeight;
|
|
37
|
+
const scrolled = scroller === null ? window.scrollY : scroller.scrollTop;
|
|
38
|
+
const padded = scroller === null
|
|
39
|
+
? 0
|
|
40
|
+
: Number.parseFloat(getComputedStyle(scroller).paddingBottom) || 0;
|
|
41
|
+
const top = el.getBoundingClientRect().top - viewTop + scrolled;
|
|
42
|
+
const rest = Math.floor(viewHeight - top - padded);
|
|
43
|
+
setMin(rest > 0 ? rest : undefined);
|
|
44
|
+
};
|
|
45
|
+
measure();
|
|
46
|
+
const watch = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(measure);
|
|
47
|
+
watch?.observe(scroller ?? document.documentElement);
|
|
48
|
+
window.addEventListener("resize", measure);
|
|
49
|
+
return () => {
|
|
50
|
+
watch?.disconnect();
|
|
51
|
+
window.removeEventListener("resize", measure);
|
|
52
|
+
};
|
|
53
|
+
}, [frame, on]);
|
|
54
|
+
return min;
|
|
55
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { type ActivityProps } from "../../components/activity/Activity.js";
|
|
2
2
|
import { type SheetField, type SheetLayout } from "../../components/form/Sheet.js";
|
|
3
|
+
import type { RecordDockProps } from "../../components/record/ActionDock.js";
|
|
3
4
|
import type { Crumb } from "../../components/record/Breadcrumb.js";
|
|
4
5
|
import type { DirtyState } from "../../components/record/DirtyActions.js";
|
|
5
6
|
import { type RecordStamp } from "../../components/record/RecordAudit.js";
|
|
6
7
|
import { type RecordNoticeSpec } from "../../components/record/RecordNotices.js";
|
|
7
8
|
import { RecordSkeleton } from "../../components/record/RecordSkeleton.js";
|
|
8
|
-
import { type Stage } from "../../components/record/StatusBar.js";
|
|
9
|
+
import { type Stage, type StatusLook } from "../../components/record/StatusBar.js";
|
|
9
10
|
import type { Surface, Tone } from "../../foundations/types.js";
|
|
11
|
+
import { type ViewStyle } from "../../foundations/viewStyle.js";
|
|
10
12
|
import { type TabNotice } from "../../primitives/tabs/Tabs.js";
|
|
11
13
|
import type { LucideIcon } from "lucide-react";
|
|
12
14
|
import { type ReactNode } from "react";
|
|
@@ -43,6 +45,11 @@ export type RecordPager = {
|
|
|
43
45
|
total: number;
|
|
44
46
|
onPrev?: () => void;
|
|
45
47
|
onNext?: () => void;
|
|
48
|
+
/** The combinations that move — Alt+P and Alt+N by default, `false` for none. */
|
|
49
|
+
keys?: {
|
|
50
|
+
prev: string;
|
|
51
|
+
next: string;
|
|
52
|
+
} | false;
|
|
46
53
|
};
|
|
47
54
|
export type { SheetField };
|
|
48
55
|
/** A notice of the record: the props of `Record.Notice` (a `Callout` without its × label,
|
|
@@ -71,6 +78,9 @@ type StatusProps = {
|
|
|
71
78
|
failed?: boolean;
|
|
72
79
|
/** The stages can be chosen: pressing one moves the record there (a CRM's pipeline). */
|
|
73
80
|
onSelect?: (id: string) => void;
|
|
81
|
+
/** Which widget draws it (`StatusLook`). Absent: `segmented` in the modern style, `track`
|
|
82
|
+
* (Odoo's) in the traditional one. */
|
|
83
|
+
look?: StatusLook;
|
|
74
84
|
/** The status escape hatch, for whatever is neither of the two. */
|
|
75
85
|
children?: ReactNode;
|
|
76
86
|
};
|
|
@@ -145,9 +155,12 @@ export type RecordProps = {
|
|
|
145
155
|
* whole tree under the paper the moment one of them appears or goes away.
|
|
146
156
|
*/
|
|
147
157
|
placement?: "page" | "card";
|
|
158
|
+
/** How this record is drawn — `traditional` or `modern`. Absent, the
|
|
159
|
+
* `ViewStyleProvider`'s: an application chooses once. */
|
|
160
|
+
look?: ViewStyle;
|
|
148
161
|
children?: ReactNode;
|
|
149
162
|
};
|
|
150
|
-
export declare function Record({ identity, error, dirty, placement, children }: RecordProps): import("react").JSX.Element;
|
|
163
|
+
export declare function Record({ identity, error, dirty, placement, look: ownLook, children, }: RecordProps): import("react").JSX.Element;
|
|
151
164
|
export declare namespace Record {
|
|
152
165
|
var Skeleton: typeof RecordSkeleton;
|
|
153
166
|
var Rail: ((props: RailProps) => ReactNode) & import("../../foundations/slots.js").Slotted<"rail">;
|
|
@@ -155,6 +168,7 @@ export declare namespace Record {
|
|
|
155
168
|
var Pager: ((props: RecordPager) => ReactNode) & import("../../foundations/slots.js").Slotted<"pager">;
|
|
156
169
|
var Smart: ((props: SmartProps) => ReactNode) & import("../../foundations/slots.js").Slotted<"smart">;
|
|
157
170
|
var Actions: ((props: ActionsProps) => ReactNode) & import("../../foundations/slots.js").Slotted<"actions">;
|
|
171
|
+
var Dock: ((props: RecordDockProps) => ReactNode) & import("../../foundations/slots.js").Slotted<"dock">;
|
|
158
172
|
var Status: ((props: StatusProps) => ReactNode) & import("../../foundations/slots.js").Slotted<"status">;
|
|
159
173
|
var Paper: ((props: PaperProps) => ReactNode) & import("../../foundations/slots.js").Slotted<"paper">;
|
|
160
174
|
var Activity: ((props: RecordActivityProps) => ReactNode) & import("../../foundations/slots.js").Slotted<"activity">;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { Activity } from "../../components/activity/Activity.js";
|
|
4
|
+
import { FormSection } from "../../components/form/Form.js";
|
|
4
5
|
import { Sheet, } from "../../components/form/Sheet.js";
|
|
5
6
|
import { Pager as PagerControl } from "../../components/record/Pager.js";
|
|
6
7
|
import { RecordAudit } from "../../components/record/RecordAudit.js";
|
|
@@ -9,10 +10,12 @@ import { RecordBlocking, RecordNoticeIndicator, splitNotices, } from "../../comp
|
|
|
9
10
|
import { RecordRibbon } from "../../components/record/RecordRibbon.js";
|
|
10
11
|
import { RecordSkeleton } from "../../components/record/RecordSkeleton.js";
|
|
11
12
|
import { SmartButton, SmartButtons } from "../../components/record/SmartButtons.js";
|
|
12
|
-
import { StatusBar } from "../../components/record/StatusBar.js";
|
|
13
|
+
import { StatusBar, } from "../../components/record/StatusBar.js";
|
|
13
14
|
import { useUiCopy } from "../../foundations/copy.js";
|
|
14
15
|
import { byDensity, useDensity } from "../../foundations/density.js";
|
|
16
|
+
import { useFormStyle } from "../../foundations/form.js";
|
|
15
17
|
import { flatten, pick as pickSlot, pickAll, propsOf, slot, slotOf, } from "../../foundations/slots.js";
|
|
18
|
+
import { useViewStyle } from "../../foundations/viewStyle.js";
|
|
16
19
|
import { createNoteRegistry, NoteRegistryContext, } from "../../primitives/field/note.js";
|
|
17
20
|
import { Tabs, TabsPanel, TabsScope, } from "../../primitives/tabs/Tabs.js";
|
|
18
21
|
import { useEffect, useId, useState, useSyncExternalStore } from "react";
|
|
@@ -32,6 +35,7 @@ const Smart = slot("smart", (_props) => null);
|
|
|
32
35
|
* where the thumb is — and with `dirty`, Save and Discard take that bar instead. The
|
|
33
36
|
* rest stay here. Nothing to declare: see THE THUMB BAR in `RecordHeader`. */
|
|
34
37
|
const Actions = slot("actions", (_props) => null);
|
|
38
|
+
const Dock = slot("dock", (_props) => null);
|
|
35
39
|
/** The status, as DATA and not as a node: the bar lives in the rail and
|
|
36
40
|
* whoever passed it already built had to remember the rail's surface. Forgetting it
|
|
37
41
|
* painted the canvas palette on top of the chrome, and it happened. */
|
|
@@ -72,8 +76,10 @@ const Page = slot("page", (_props) => null);
|
|
|
72
76
|
function NotebookScope({ tabs, children }) {
|
|
73
77
|
return tabs ? _jsx(TabsScope, { children: children }) : children;
|
|
74
78
|
}
|
|
75
|
-
export function Record({ identity, error = null, dirty, placement, children }) {
|
|
79
|
+
export function Record({ identity, error = null, dirty, placement, look: ownLook, children, }) {
|
|
80
|
+
const look = useViewStyle(ownLook);
|
|
76
81
|
const d = useDensity();
|
|
82
|
+
const formStyle = useFormStyle();
|
|
77
83
|
const copy = useUiCopy();
|
|
78
84
|
const top = flatten(children);
|
|
79
85
|
const railNode = pick(top, "rail");
|
|
@@ -87,6 +93,7 @@ export function Record({ identity, error = null, dirty, placement, children }) {
|
|
|
87
93
|
const pager = propsOf(pick(rail, "pager"));
|
|
88
94
|
const smart = propsOf(pick(rail, "smart"))?.links;
|
|
89
95
|
const actions = propsOf(pick(rail, "actions"))?.children;
|
|
96
|
+
const dock = propsOf(pick(rail, "dock"));
|
|
90
97
|
const status = propsOf(pick(rail, "status"));
|
|
91
98
|
/* The status's two questions, with the surface already resolved: «¿dónde
|
|
92
99
|
está?» and «¿qué pasó para llegar acá?». */
|
|
@@ -104,7 +111,11 @@ export function Record({ identity, error = null, dirty, placement, children }) {
|
|
|
104
111
|
/* Stacked in one block: above where it is, below what happened to get there.
|
|
105
112
|
Side by side they competed for width with the buttons and both ended up
|
|
106
113
|
truncated; one under the other, each has its whole line. */
|
|
107
|
-
_jsxs("div", { className: "flex min-w-0 flex-col items-end gap-1.5", children: [status.stages === undefined ? null : (_jsx(StatusBar, { stages: status.stages, current: status.current ?? status.stages[0]?.id ?? "", failed: status.failed ?? false, surface: surface, ...(status.
|
|
114
|
+
_jsxs("div", { className: "flex min-w-0 flex-col items-end gap-1.5", children: [status.stages === undefined ? null : (_jsx(StatusBar, { stages: status.stages, current: status.current ?? status.stages[0]?.id ?? "", failed: status.failed ?? false, surface: surface, ...(status.look !== undefined
|
|
115
|
+
? { look: status.look }
|
|
116
|
+
: look === "modern"
|
|
117
|
+
? { look: "segmented" }
|
|
118
|
+
: {}), ...(status.onSelect === undefined ? {} : { onSelect: status.onSelect }) })), status.children] }));
|
|
108
119
|
const paper = propsOf(paperNode);
|
|
109
120
|
const inPaper = [...flatten(paper?.children), ...loose];
|
|
110
121
|
const fields = propsOf(pick(inPaper, "facts"))?.fields;
|
|
@@ -143,7 +154,16 @@ export function Record({ identity, error = null, dirty, placement, children }) {
|
|
|
143
154
|
}, [reveal, alertsId]);
|
|
144
155
|
const notebook = propsOf(pick(inPaper, "pages"));
|
|
145
156
|
const pages = flatten(notebook?.children).filter((node) => slotOf(node) === "page");
|
|
146
|
-
|
|
157
|
+
/* «sections» (`FormStyleProvider`): the notebook's pages are not tabs but CARDS, one under
|
|
158
|
+
the other, found by the index — the long record read top to bottom, nothing hidden
|
|
159
|
+
behind a tab. */
|
|
160
|
+
const sectioned = formStyle === "sections";
|
|
161
|
+
const pageCards = sectioned
|
|
162
|
+
? pages
|
|
163
|
+
.map((node) => propsOf(node))
|
|
164
|
+
.filter((page) => page !== undefined)
|
|
165
|
+
: [];
|
|
166
|
+
const tabs = (sectioned ? [] : pages)
|
|
147
167
|
.map((node) => propsOf(node))
|
|
148
168
|
.filter((page) => page !== undefined)
|
|
149
169
|
.map(({ id, label, icon, count, notice }) => ({
|
|
@@ -181,8 +201,10 @@ export function Record({ identity, error = null, dirty, placement, children }) {
|
|
|
181
201
|
}), ...(paper?.width === undefined ? {} : { width: paper.width }), ...(dirty === undefined ? {} : { dirty }), ...(crumbs === undefined ? {} : { crumbs }), ...(pager === undefined
|
|
182
202
|
? {}
|
|
183
203
|
: {
|
|
184
|
-
pager: (_jsx(PagerControl, { index: pager.index, total: pager.total, surface: surface, ...(pager.onPrev === undefined ? {} : { onPrev: pager.onPrev }), ...(pager.onNext === undefined ? {} : { onNext: pager.onNext }) })
|
|
185
|
-
|
|
204
|
+
pager: (_jsx(PagerControl, { index: pager.index, total: pager.total, surface: surface, ...(pager.onPrev === undefined ? {} : { onPrev: pager.onPrev }), ...(pager.onNext === undefined ? {} : { onNext: pager.onNext }), ...(pager.keys === undefined ? {} : { keys: pager.keys }),
|
|
205
|
+
/* The modern style's position stands out: a translucent pill. */
|
|
206
|
+
look: look === "modern" ? "pill" : "plain" })),
|
|
207
|
+
}), ...(actions === undefined ? {} : { actions }), ...(dock === undefined ? {} : { dock }), look: look, ...(statusBlock === undefined ? {} : { status: statusBlock }), ...(identity.icon === undefined ? {} : { icon: identity.icon }), title: identity.title, ...(identity.subtitle === undefined ? {} : { subtitle: identity.subtitle }), ...(identity.figure === undefined ? {} : { figure: identity.figure }), ...(identity.tag === undefined ? {} : { tag: identity.tag }), ...(smart === undefined || smart.length === 0
|
|
186
208
|
? {}
|
|
187
209
|
: {
|
|
188
210
|
smart: (_jsx(SmartButtons, { children: smart.map((s) => (_jsx(SmartButton, { icon: s.icon, ...(s.count === undefined ? {} : { count: s.count }), label: s.label, layout: onTheRail && d === "comfortable" ? "inline" : "stacked", ...(s.onClick === undefined ? {} : { onClick: s.onClick }) }, s.label))) })),
|
|
@@ -215,7 +237,7 @@ export function Record({ identity, error = null, dirty, placement, children }) {
|
|
|
215
237
|
? {
|
|
216
238
|
head: (_jsxs(_Fragment, { children: [above, globalSheet && aspectsNode !== undefined ? (_jsx("div", { className: `border-b border-line-strong ${byDensity(d, "-mx-4 px-4", "")}`, children: aspectsNode })) : null] })),
|
|
217
239
|
}
|
|
218
|
-
: {}), children: [tabs.length === 0 ? (pageBody) : (_jsx(TabsPanel, { id: current, className: `flex min-w-0 flex-col ${byDensity(d, "gap-(--spacing-block)", "gap-2.5")}`, children: pageBody })), below] }) }), audit === undefined ? null : _jsx(RecordAudit, { ...audit })] }) }) }) }) }));
|
|
240
|
+
: {}), children: [sectioned ? (pageCards.map((page) => (_jsx(FormSection, { title: page.label, children: page.children }, page.id)))) : tabs.length === 0 ? (pageBody) : (_jsx(TabsPanel, { id: current, className: `flex min-w-0 flex-col ${byDensity(d, "gap-(--spacing-block)", "gap-2.5")}`, children: pageBody })), below] }) }), audit === undefined ? null : _jsx(RecordAudit, { ...audit })] }) }) }) }) }));
|
|
219
241
|
}
|
|
220
242
|
Record.Skeleton = RecordSkeleton;
|
|
221
243
|
Record.Rail = Rail;
|
|
@@ -223,6 +245,7 @@ Record.Crumbs = Crumbs;
|
|
|
223
245
|
Record.Pager = PagerSlot;
|
|
224
246
|
Record.Smart = Smart;
|
|
225
247
|
Record.Actions = Actions;
|
|
248
|
+
Record.Dock = Dock;
|
|
226
249
|
Record.Status = Status;
|
|
227
250
|
Record.Paper = Paper;
|
|
228
251
|
Record.Activity = ActivitySlot;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-ui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"description": "An enterprise web design system for business software — ERPs, back offices, management tools — in React and Tailwind: tokens, primitives, components and the two views every management screen is made of.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|