@sincpro/web-ui 2.3.0 → 2.5.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 +71 -6
- package/dist/components/activity/Activity.d.ts +20 -1
- package/dist/components/activity/Activity.js +44 -7
- package/dist/components/activity/index.d.ts +1 -1
- package/dist/components/board/Board.d.ts +74 -2
- package/dist/components/board/Board.js +65 -2
- package/dist/components/board/index.d.ts +1 -1
- package/dist/components/board/index.js +1 -1
- package/dist/components/canvas/canvas.css +6 -1
- package/dist/components/form/Form.js +11 -0
- package/dist/components/form/FormIndex.d.ts +11 -0
- package/dist/components/form/FormIndex.js +96 -0
- package/dist/components/form/Sheet.js +5 -0
- package/dist/components/guide/Guide.d.ts +33 -0
- package/dist/components/guide/Guide.js +288 -0
- package/dist/components/guide/GuideSpot.d.ts +14 -0
- package/dist/components/guide/GuideSpot.js +13 -0
- package/dist/components/guide/index.d.ts +4 -0
- package/dist/components/guide/index.js +6 -0
- package/dist/components/guide/place.d.ts +44 -0
- package/dist/components/guide/place.js +69 -0
- package/dist/components/guide/target.d.ts +41 -0
- package/dist/components/guide/target.js +55 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/listing/ChartExplorer.js +10 -5
- package/dist/components/listing/Listing.js +7 -5
- package/dist/components/listing/Row.js +8 -7
- package/dist/components/navigation/NavigationTree.js +1 -1
- package/dist/components/record/DirtyActions.d.ts +19 -8
- package/dist/components/record/DirtyActions.js +89 -13
- package/dist/components/record/RecordHeader.js +17 -11
- package/dist/components/record/ThumbBar.js +2 -1
- package/dist/components/shell/SearchEntry.d.ts +29 -0
- package/dist/components/shell/SearchEntry.js +34 -0
- package/dist/components/shell/Sidebar.d.ts +5 -1
- package/dist/components/shell/Sidebar.js +4 -3
- package/dist/components/shell/TopBar.d.ts +5 -1
- package/dist/components/shell/TopBar.js +3 -2
- package/dist/components/shell/index.d.ts +1 -0
- package/dist/components/shell/index.js +3 -0
- package/dist/foundations/calendar.d.ts +12 -0
- package/dist/foundations/calendar.js +50 -0
- package/dist/foundations/chart.d.ts +10 -1
- package/dist/foundations/chart.js +17 -1
- package/dist/foundations/copy.d.ts +39 -2
- package/dist/foundations/copy.es.js +19 -0
- package/dist/foundations/copy.js +19 -0
- package/dist/foundations/form.d.ts +6 -0
- package/dist/foundations/form.js +7 -0
- package/dist/foundations/index.d.ts +3 -2
- package/dist/foundations/index.js +4 -2
- package/dist/foundations/pivot.d.ts +6 -0
- package/dist/foundations/pivot.js +1 -0
- package/dist/foundations/shortcut.d.ts +18 -0
- package/dist/foundations/shortcut.js +20 -0
- package/dist/primitives/chart/BarList.d.ts +30 -0
- package/dist/primitives/chart/BarList.js +27 -0
- package/dist/primitives/chart/Chart.d.ts +13 -0
- package/dist/primitives/chart/Chart.js +71 -19
- package/dist/primitives/chart/Sparkline.d.ts +30 -0
- package/dist/primitives/chart/Sparkline.js +53 -0
- package/dist/primitives/chart/index.d.ts +2 -0
- package/dist/primitives/chart/index.js +2 -0
- package/dist/primitives/field/Field.d.ts +6 -2
- package/dist/primitives/field/Field.js +35 -6
- package/dist/primitives/value/Metric.d.ts +12 -1
- package/dist/primitives/value/Metric.js +9 -4
- package/dist/tokens.css +92 -22
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { FormIndex, FormIndexScope } from "./FormIndex.js";
|
|
3
4
|
import { byDensity, useDensity } from "../../foundations/density.js";
|
|
5
|
+
import { useFormStyle } from "../../foundations/form.js";
|
|
4
6
|
import { FieldLayoutProvider, } from "../../primitives/field/layout.js";
|
|
5
7
|
import { NoteCard, NoteFlag } from "../../primitives/field/note.js";
|
|
6
8
|
import { Hint } from "../../primitives/hint/Hint.js";
|
|
@@ -46,10 +48,13 @@ function Facts({ fields, columns, layout, }) {
|
|
|
46
48
|
}
|
|
47
49
|
export function Sheet({ fields, columns = 2, layout = "stacked", head, children, }) {
|
|
48
50
|
const d = useDensity();
|
|
51
|
+
const settings = useFormStyle() === "settings";
|
|
49
52
|
const facts = fields !== undefined && fields.length > 0;
|
|
50
53
|
if (!facts && head === undefined && children === undefined)
|
|
51
54
|
return null;
|
|
52
55
|
const top = facts || head !== undefined ? (_jsxs("div", { className: `flex min-w-0 flex-col ${byDensity(d, "gap-4", "gap-3")}`, children: [facts ? _jsx(Facts, { fields: fields, columns: columns, layout: layout }) : null, head] })) : null;
|
|
56
|
+
if (settings)
|
|
57
|
+
return (_jsx(FieldLayoutProvider, { value: layout, children: _jsx(FormIndexScope, { children: _jsx("div", { className: "@container/form min-w-0", children: _jsxs("div", { className: "flex min-w-0 gap-6", children: [_jsx(FormIndex, {}), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-4", children: [top, children] })] }) }) }) }));
|
|
53
58
|
return (_jsx(FieldLayoutProvider, { value: layout, children: _jsxs("div", { className: `flex min-w-0 flex-col ${byDensity(d, "gap-(--spacing-block)", "gap-2.5")}`, children: [top, children] }) }));
|
|
54
59
|
}
|
|
55
60
|
/** A row of columns on the paper. The paper is the sheet; a group is not a
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type GuideSide } from "./place.js";
|
|
2
|
+
import { type GuideTarget } from "./target.js";
|
|
3
|
+
import { type ReactNode } from "react";
|
|
4
|
+
export type GuideStep = {
|
|
5
|
+
id: string;
|
|
6
|
+
/** What it points at. Without it the card is centred: a welcome, a goodbye. */
|
|
7
|
+
target?: GuideTarget;
|
|
8
|
+
title: string;
|
|
9
|
+
/** What it explains: text, a list, an image, a button that tries the thing. */
|
|
10
|
+
body: ReactNode;
|
|
11
|
+
/** The side of the target the card prefers; it flips when there is no room. `bottom` by
|
|
12
|
+
* default. */
|
|
13
|
+
placement?: GuideSide;
|
|
14
|
+
/** Runs before the step looks for its target: navigate, open a tab, expand a section. The
|
|
15
|
+
* tour waits for it, then for the target to appear. */
|
|
16
|
+
before?: () => void | Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
/** `finish`: the last step's button. `skip`: «Saltar el recorrido». `dismiss`: Escape. */
|
|
19
|
+
export type GuideCloseReason = "finish" | "skip" | "dismiss";
|
|
20
|
+
export type GuideProps = {
|
|
21
|
+
steps: readonly GuideStep[];
|
|
22
|
+
open: boolean;
|
|
23
|
+
/** The tour wants to close; the application sets `open` to false — and remembers, if it
|
|
24
|
+
* wants to, that this person has seen it. */
|
|
25
|
+
onClose: (reason: GuideCloseReason, index: number) => void;
|
|
26
|
+
/** A step is on screen: to save how far someone got, to measure. */
|
|
27
|
+
onStepChange?: (index: number, step: GuideStep) => void;
|
|
28
|
+
/** Where it starts each time it opens — to resume a tour left halfway. */
|
|
29
|
+
startAt?: number;
|
|
30
|
+
/** The tour's name, for a screen reader: «Recorrido del portal». */
|
|
31
|
+
label?: string;
|
|
32
|
+
};
|
|
33
|
+
export declare function Guide({ steps, open, onClose, onStepChange, startAt, label, }: GuideProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { placeCard, } from "./place.js";
|
|
4
|
+
import { boxOf, findTarget, scrollable, } from "./target.js";
|
|
5
|
+
import { useSidebarDrawer } from "../shell/sidebarDrawer.js";
|
|
6
|
+
import { fillCopy, useUiCopy } from "../../foundations/copy.js";
|
|
7
|
+
import { SurfaceProvider } from "../../foundations/surface.js";
|
|
8
|
+
import { Button } from "../../primitives/button/Button.js";
|
|
9
|
+
import { useEffect, useId, useRef, useState, } from "react";
|
|
10
|
+
import { Dialog, Modal, ModalOverlay } from "react-aria-components";
|
|
11
|
+
/** How long a step waits for its target to appear before it is skipped: a list that loads,
|
|
12
|
+
* a screen the step's `before()` navigated to. Long enough for those, short enough that a
|
|
13
|
+
* stop that is not there is not a wait. */
|
|
14
|
+
const WAIT_FOR_TARGET = 1500;
|
|
15
|
+
const SPOT_PADDING = 0.375; // rem — the cut-out's air around the target (`p-1.5`)
|
|
16
|
+
const CARD_GAP = 0.75; // rem — between the cut-out and the card
|
|
17
|
+
const WINDOW_MARGIN = 1; // rem — the card never comes closer to the window's edge
|
|
18
|
+
const nextFrame = () => new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
19
|
+
const prefersLessMotion = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
20
|
+
/** Scrolled into view only when it is not already whole in it: a tour that scrolls a page
|
|
21
|
+
* that was fine moves the very thing it is about to explain. */
|
|
22
|
+
function bringIntoView(element) {
|
|
23
|
+
const box = boxOf(element);
|
|
24
|
+
const whole = box !== null &&
|
|
25
|
+
box.top >= 0 &&
|
|
26
|
+
box.left >= 0 &&
|
|
27
|
+
box.top + box.height <= window.innerHeight &&
|
|
28
|
+
box.left + box.width <= window.innerWidth;
|
|
29
|
+
if (whole)
|
|
30
|
+
return;
|
|
31
|
+
scrollable(element).scrollIntoView({
|
|
32
|
+
block: "center",
|
|
33
|
+
inline: "nearest",
|
|
34
|
+
behavior: prefersLessMotion() ? "auto" : "smooth",
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
38
|
+
const rounded = (box) => box === null
|
|
39
|
+
? null
|
|
40
|
+
: {
|
|
41
|
+
top: Math.round(box.top),
|
|
42
|
+
left: Math.round(box.left),
|
|
43
|
+
width: Math.round(box.width),
|
|
44
|
+
height: Math.round(box.height),
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The target's box, the card's size and the window's, measured every frame while the tour is
|
|
48
|
+
* open — and set only when they change.
|
|
49
|
+
*
|
|
50
|
+
* Context: the things a target does while a tour points at it have no single event: a page
|
|
51
|
+
* scrolled into place, a drawer sliding in (a transform), a font loading, a list re-rendering
|
|
52
|
+
* the node. One `getBoundingClientRect` per frame follows all of them, and costs nothing next
|
|
53
|
+
* to a frame. A node React replaced is found again by the same target.
|
|
54
|
+
*/
|
|
55
|
+
function useLayout(active, element, target, card) {
|
|
56
|
+
const [layout, setLayout] = useState({
|
|
57
|
+
target: null,
|
|
58
|
+
card: null,
|
|
59
|
+
view: { width: 0, height: 0 },
|
|
60
|
+
});
|
|
61
|
+
/* Read, not depended on: steps written inline give a new `target` object every render, and
|
|
62
|
+
restarting the loop on each would measure for ever. */
|
|
63
|
+
const latestTarget = useRef(target);
|
|
64
|
+
latestTarget.current = target;
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!active)
|
|
67
|
+
return;
|
|
68
|
+
let current = element;
|
|
69
|
+
let frame = 0;
|
|
70
|
+
const tick = () => {
|
|
71
|
+
const target = latestTarget.current;
|
|
72
|
+
if (current !== null && !current.isConnected && target !== undefined) {
|
|
73
|
+
current = findTarget(target).shown;
|
|
74
|
+
}
|
|
75
|
+
const node = card.current;
|
|
76
|
+
const next = {
|
|
77
|
+
target: current === null ? null : rounded(boxOf(current)),
|
|
78
|
+
card: node === null ? null : { width: node.offsetWidth, height: node.offsetHeight },
|
|
79
|
+
view: { width: window.innerWidth, height: window.innerHeight },
|
|
80
|
+
};
|
|
81
|
+
setLayout((previous) => (same(previous, next) ? previous : next));
|
|
82
|
+
frame = requestAnimationFrame(tick);
|
|
83
|
+
};
|
|
84
|
+
tick();
|
|
85
|
+
return () => cancelAnimationFrame(frame);
|
|
86
|
+
}, [active, element, card]);
|
|
87
|
+
return layout;
|
|
88
|
+
}
|
|
89
|
+
export function Guide({ steps, open, onClose, onStepChange, startAt = 0, label, }) {
|
|
90
|
+
const copy = useUiCopy();
|
|
91
|
+
const drawer = useSidebarDrawer();
|
|
92
|
+
const titleId = useId();
|
|
93
|
+
const bodyId = useId();
|
|
94
|
+
const card = useRef(null);
|
|
95
|
+
const [request, setRequest] = useState(null);
|
|
96
|
+
const [shown, setShown] = useState(null);
|
|
97
|
+
/* Bumped when the tour opens the drawer: the tour's own overlay mounts again ABOVE it, or
|
|
98
|
+
the drawer — the newest modal — would make the card inert. */
|
|
99
|
+
const [layer, setLayer] = useState(0);
|
|
100
|
+
/* The latest props, read by the async step without restarting it: an application that
|
|
101
|
+
writes its `steps` inline gives a new array every render. */
|
|
102
|
+
const latest = useRef({ steps, onClose, onStepChange, drawer });
|
|
103
|
+
latest.current = { steps, onClose, onStepChange, drawer };
|
|
104
|
+
const openedDrawer = useRef(false);
|
|
105
|
+
const returnTo = useRef(null);
|
|
106
|
+
/* Open: from `startAt`, remembering where the focus was. Closed: the drawer the tour opened
|
|
107
|
+
closes, and the focus goes back — a tour that went through the drawer remounted its
|
|
108
|
+
overlay, and the overlay's own memory of «where the focus was» went with it. */
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
if (!open)
|
|
111
|
+
return;
|
|
112
|
+
returnTo.current =
|
|
113
|
+
document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
114
|
+
const first = Math.min(Math.max(startAt, 0), Math.max(latest.current.steps.length - 1, 0));
|
|
115
|
+
setRequest({ index: first, dir: 1 });
|
|
116
|
+
return () => {
|
|
117
|
+
setRequest(null);
|
|
118
|
+
setShown(null);
|
|
119
|
+
if (openedDrawer.current)
|
|
120
|
+
latest.current.drawer?.close();
|
|
121
|
+
openedDrawer.current = false;
|
|
122
|
+
const back = returnTo.current;
|
|
123
|
+
requestAnimationFrame(() => {
|
|
124
|
+
const lost = document.activeElement === null || document.activeElement === document.body;
|
|
125
|
+
if (lost && back?.isConnected === true)
|
|
126
|
+
back.focus();
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
}, [open, startAt]);
|
|
130
|
+
const close = (reason) => latest.current.onClose(reason, shown?.index ?? request?.index ?? 0);
|
|
131
|
+
/* One step: run its `before`, wait for its target, open or close the drawer for it, bring
|
|
132
|
+
it into view — and only then show it, so the card never names one thing while the veil
|
|
133
|
+
cuts out another. */
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (!open || request === null)
|
|
136
|
+
return;
|
|
137
|
+
let cancelled = false;
|
|
138
|
+
const { steps: all } = latest.current;
|
|
139
|
+
const step = all[request.index];
|
|
140
|
+
if (step === undefined)
|
|
141
|
+
return;
|
|
142
|
+
const drawerElement = () => {
|
|
143
|
+
const id = latest.current.drawer?.id;
|
|
144
|
+
return id === undefined ? null : document.getElementById(id);
|
|
145
|
+
};
|
|
146
|
+
const seek = async (target) => {
|
|
147
|
+
const started = performance.now();
|
|
148
|
+
let openedHere = false;
|
|
149
|
+
while (!cancelled) {
|
|
150
|
+
const { shown: found, hidden } = findTarget(target);
|
|
151
|
+
const sheet = latest.current.drawer;
|
|
152
|
+
if (found !== null) {
|
|
153
|
+
const inDrawer = drawerElement()?.contains(found) === true;
|
|
154
|
+
if (!inDrawer && openedDrawer.current && sheet?.isOpen === true) {
|
|
155
|
+
sheet.close();
|
|
156
|
+
openedDrawer.current = false;
|
|
157
|
+
}
|
|
158
|
+
if (openedHere)
|
|
159
|
+
setLayer((n) => n + 1);
|
|
160
|
+
return found;
|
|
161
|
+
}
|
|
162
|
+
const inSidebar = hidden?.closest('[data-ui="frame.sidebar"]') != null;
|
|
163
|
+
if (inSidebar && sheet !== null && !sheet.isOpen && !openedHere) {
|
|
164
|
+
sheet.open();
|
|
165
|
+
openedDrawer.current = true;
|
|
166
|
+
openedHere = true;
|
|
167
|
+
}
|
|
168
|
+
if (performance.now() - started > WAIT_FOR_TARGET)
|
|
169
|
+
return null;
|
|
170
|
+
await nextFrame();
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
};
|
|
174
|
+
/* The step's target is not there: on to the next one in the direction of travel. Past
|
|
175
|
+
the last, the tour is done; before the first, nothing earlier is on screen, so it
|
|
176
|
+
stays where the person is. */
|
|
177
|
+
const skip = () => {
|
|
178
|
+
const next = request.index + request.dir;
|
|
179
|
+
if (next >= 0 && next < all.length) {
|
|
180
|
+
setRequest({ index: next, dir: request.dir });
|
|
181
|
+
}
|
|
182
|
+
else if (request.dir === 1) {
|
|
183
|
+
latest.current.onClose("finish", request.index);
|
|
184
|
+
}
|
|
185
|
+
else if (shown !== null) {
|
|
186
|
+
setRequest({ index: shown.index, dir: 1 });
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
void (async () => {
|
|
190
|
+
try {
|
|
191
|
+
await step.before?.();
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
if (!cancelled)
|
|
195
|
+
skip();
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (cancelled)
|
|
199
|
+
return;
|
|
200
|
+
const element = step.target === undefined ? null : await seek(step.target);
|
|
201
|
+
if (cancelled)
|
|
202
|
+
return;
|
|
203
|
+
if (step.target !== undefined && element === null) {
|
|
204
|
+
skip();
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (element !== null)
|
|
208
|
+
bringIntoView(element);
|
|
209
|
+
setShown({ index: request.index, element });
|
|
210
|
+
latest.current.onStepChange?.(request.index, step);
|
|
211
|
+
})();
|
|
212
|
+
return () => {
|
|
213
|
+
cancelled = true;
|
|
214
|
+
};
|
|
215
|
+
// `shown` is read for a skip backwards only; the step must not restart when it lands.
|
|
216
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
217
|
+
}, [open, request]);
|
|
218
|
+
/* The focus on the button that walks the tour, on every step: Enter, Enter, Enter. */
|
|
219
|
+
useEffect(() => {
|
|
220
|
+
if (shown === null)
|
|
221
|
+
return;
|
|
222
|
+
const frame = requestAnimationFrame(() => card.current?.querySelector('[data-emphasis="primary"]')?.focus());
|
|
223
|
+
return () => cancelAnimationFrame(frame);
|
|
224
|
+
}, [shown, layer]);
|
|
225
|
+
const step = shown === null ? undefined : steps[shown.index];
|
|
226
|
+
const layout = useLayout(open && shown !== null, shown?.element ?? null, step?.target, card);
|
|
227
|
+
if (!open || shown === null || step === undefined)
|
|
228
|
+
return null;
|
|
229
|
+
const index = shown.index;
|
|
230
|
+
const first = index === 0;
|
|
231
|
+
const last = index === steps.length - 1;
|
|
232
|
+
const go = (dir) => setRequest({ index: index + dir, dir });
|
|
233
|
+
const progress = fillCopy(copy.guide.progress, {
|
|
234
|
+
current: String(index + 1),
|
|
235
|
+
total: String(steps.length),
|
|
236
|
+
});
|
|
237
|
+
const rem = parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
|
|
238
|
+
const pad = SPOT_PADDING * rem;
|
|
239
|
+
const spot = layout.target === null
|
|
240
|
+
? null
|
|
241
|
+
: {
|
|
242
|
+
top: layout.target.top - pad,
|
|
243
|
+
left: layout.target.left - pad,
|
|
244
|
+
width: layout.target.width + 2 * pad,
|
|
245
|
+
height: layout.target.height + 2 * pad,
|
|
246
|
+
};
|
|
247
|
+
const place = layout.card === null
|
|
248
|
+
? null
|
|
249
|
+
: placeCard({
|
|
250
|
+
target: spot,
|
|
251
|
+
card: layout.card,
|
|
252
|
+
view: layout.view,
|
|
253
|
+
prefer: step.placement ?? "bottom",
|
|
254
|
+
gap: CARD_GAP * rem,
|
|
255
|
+
margin: WINDOW_MARGIN * rem,
|
|
256
|
+
});
|
|
257
|
+
const onKeyDown = (event) => {
|
|
258
|
+
if (event.target instanceof HTMLInputElement ||
|
|
259
|
+
event.target instanceof HTMLTextAreaElement)
|
|
260
|
+
return;
|
|
261
|
+
const rtl = getComputedStyle(event.currentTarget).direction === "rtl";
|
|
262
|
+
const forward = rtl ? "ArrowLeft" : "ArrowRight";
|
|
263
|
+
const backward = rtl ? "ArrowRight" : "ArrowLeft";
|
|
264
|
+
if (event.key === forward) {
|
|
265
|
+
event.preventDefault();
|
|
266
|
+
if (last)
|
|
267
|
+
close("finish");
|
|
268
|
+
else
|
|
269
|
+
go(1);
|
|
270
|
+
}
|
|
271
|
+
else if (event.key === backward && !first) {
|
|
272
|
+
event.preventDefault();
|
|
273
|
+
go(-1);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
return (_jsxs(ModalOverlay, { isOpen: true, isDismissable: false, onOpenChange: (next) => {
|
|
277
|
+
if (!next)
|
|
278
|
+
close("dismiss");
|
|
279
|
+
}, className: "fixed inset-0 z-60 print:hidden", "data-ui": "guide", children: [spot === null ? (_jsx("div", { "aria-hidden": true, "data-ui": "guide.veil", className: "absolute inset-0 bg-ui-guide-scrim" })) : (
|
|
280
|
+
/* The veil IS the cut-out's shadow: one box around the target throws a spread as
|
|
281
|
+
wide as the window, so the hole is exact, rounded, and glides from one target to
|
|
282
|
+
the next. */
|
|
283
|
+
_jsx("div", { "aria-hidden": true, "data-ui": "guide.spot", className: "pointer-events-none fixed rounded-box text-ui-guide-scrim shadow-guide-veil outline-2 outline-surface transition-[top,left,width,height] duration-(--duration-panel) ease-(--ease-out)", style: spot })), _jsx(Modal, { className: "fixed w-(--container-guide) outline-0 transition-[top,left] duration-(--duration-panel) ease-(--ease-out)", style: place === null
|
|
284
|
+
? { top: 0, left: 0, visibility: "hidden" }
|
|
285
|
+
: { top: place.top, left: place.left }, children: _jsx(Dialog, { ref: (node) => {
|
|
286
|
+
card.current = node;
|
|
287
|
+
}, "aria-label": label ?? copy.guide.label, "aria-describedby": `${titleId} ${bodyId}`, "data-ui": "guide.card", "data-side": place?.side, className: "rounded-ui-guide border border-line-strong bg-ui-guide p-4 text-ink shadow-window outline-0", children: _jsx(SurfaceProvider, { value: "canvas", children: _jsxs("div", { role: "presentation", onKeyDown: onKeyDown, className: "flex flex-col gap-2", children: [_jsx("p", { "data-ui": "guide.progress", className: "text-micro tabular-nums text-muted", children: progress }), _jsx("h2", { id: titleId, "data-ui": "guide.title", className: "text-lead font-semibold", children: step.title }), _jsx("div", { id: bodyId, "data-ui": "guide.body", className: "text-meta", children: step.body }), _jsxs("div", { "data-ui": "guide.actions", className: "flex items-center gap-2 pt-2", children: [last ? null : (_jsx(Button, { role: "ghost", size: "sm", onClick: () => close("skip"), children: copy.guide.skip })), _jsxs("span", { className: "ms-auto flex items-center gap-2", children: [first ? null : (_jsx(Button, { size: "sm", onClick: () => go(-1), children: copy.guide.back })), _jsx(Button, { role: "primary", size: "sm", onClick: () => (last ? close("finish") : go(1)), children: last ? copy.guide.finish : copy.guide.next })] })] }), _jsx("p", { className: "sr-only", "aria-live": "polite", children: fillCopy(copy.guide.step, { progress, title: step.title }) })] }) }) }) })] }, layer));
|
|
288
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Marks anything as a stop of a tour — `{ spot: "cifras" }` — without changing its layout.
|
|
4
|
+
*
|
|
5
|
+
* Context: a tour has to point at things the application composes — a row of `Metrics`, a
|
|
6
|
+
* `Block`, a group of buttons — and none of them should grow a prop for it. This is a wrapper
|
|
7
|
+
* with no box of its own (`display: contents`): inside a flex row or a grid its children stay
|
|
8
|
+
* exactly where they were, and the tour measures the union of their boxes. An element of the
|
|
9
|
+
* application's own can carry `data-guide` directly; this is for what it does not write.
|
|
10
|
+
*/
|
|
11
|
+
export declare function GuideSpot({ id, children }: {
|
|
12
|
+
id: string;
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Marks anything as a stop of a tour — `{ spot: "cifras" }` — without changing its layout.
|
|
4
|
+
*
|
|
5
|
+
* Context: a tour has to point at things the application composes — a row of `Metrics`, a
|
|
6
|
+
* `Block`, a group of buttons — and none of them should grow a prop for it. This is a wrapper
|
|
7
|
+
* with no box of its own (`display: contents`): inside a flex row or a grid its children stay
|
|
8
|
+
* exactly where they were, and the tour measures the union of their boxes. An element of the
|
|
9
|
+
* application's own can carry `data-guide` directly; this is for what it does not write.
|
|
10
|
+
*/
|
|
11
|
+
export function GuideSpot({ id, children }) {
|
|
12
|
+
return (_jsx("span", { "data-guide": id, className: "contents", children: children }));
|
|
13
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { Guide, type GuideCloseReason, type GuideProps, type GuideStep, } from "./Guide.js";
|
|
2
|
+
export { GuideSpot } from "./GuideSpot.js";
|
|
3
|
+
export { type Box as GuideBox, type CardPlacement as GuideCardPlacement, type GuideSide, type Size as GuideSize, placeCard, } from "./place.js";
|
|
4
|
+
export { boxOf, findTarget, type Found as GuideMatch, type GuideTarget, selectorOf, } from "./target.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/* A GUIDED TOUR — the screen explains what each thing is, where it is. */
|
|
2
|
+
export { Guide, } from "./Guide.js";
|
|
3
|
+
export { GuideSpot } from "./GuideSpot.js";
|
|
4
|
+
/* The rules underneath, for an application that draws a tour of its own. */
|
|
5
|
+
export { placeCard, } from "./place.js";
|
|
6
|
+
export { boxOf, findTarget, selectorOf, } from "./target.js";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a tour's card goes, beside what it points at.
|
|
3
|
+
*
|
|
4
|
+
* Context: pure on purpose. The tour measures — the target's box, the card's size, the
|
|
5
|
+
* window — and this decides, so the one part of a tour that is easy to get subtly wrong (a
|
|
6
|
+
* card under the fold, a card covering what it explains, a card off the left edge on a
|
|
7
|
+
* phone) is held by tests that need no browser.
|
|
8
|
+
*
|
|
9
|
+
* 1. No target: the card is centred — a welcome, a goodbye.
|
|
10
|
+
* 2. The preferred side, then its opposite, then the other two: the first one where the
|
|
11
|
+
* whole card fits between the target and the window's margin wins.
|
|
12
|
+
* 3. Along that side the card is centred on the target, and clamped inside the margins:
|
|
13
|
+
* a target at the window's edge keeps its card in view.
|
|
14
|
+
* Final: no side fits (the target is most of the window — a whole list): the card goes to
|
|
15
|
+
* the bottom of the window, over the target, where it covers the least of its top.
|
|
16
|
+
*/
|
|
17
|
+
export type GuideSide = "top" | "bottom" | "left" | "right";
|
|
18
|
+
export type Box = {
|
|
19
|
+
top: number;
|
|
20
|
+
left: number;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
};
|
|
24
|
+
export type Size = {
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
};
|
|
28
|
+
export type CardPlacement = {
|
|
29
|
+
top: number;
|
|
30
|
+
left: number;
|
|
31
|
+
/** Which side of the target it ended on; `center` without a target, `over` when no side had
|
|
32
|
+
* room. */
|
|
33
|
+
side: GuideSide | "center" | "over";
|
|
34
|
+
};
|
|
35
|
+
export declare function placeCard({ target, card, view, prefer, gap, margin, }: {
|
|
36
|
+
target: Box | null;
|
|
37
|
+
card: Size;
|
|
38
|
+
view: Size;
|
|
39
|
+
prefer?: GuideSide;
|
|
40
|
+
/** Between the target and the card. */
|
|
41
|
+
gap: number;
|
|
42
|
+
/** The card never comes closer than this to the window's edge. */
|
|
43
|
+
margin: number;
|
|
44
|
+
}): CardPlacement;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a tour's card goes, beside what it points at.
|
|
3
|
+
*
|
|
4
|
+
* Context: pure on purpose. The tour measures — the target's box, the card's size, the
|
|
5
|
+
* window — and this decides, so the one part of a tour that is easy to get subtly wrong (a
|
|
6
|
+
* card under the fold, a card covering what it explains, a card off the left edge on a
|
|
7
|
+
* phone) is held by tests that need no browser.
|
|
8
|
+
*
|
|
9
|
+
* 1. No target: the card is centred — a welcome, a goodbye.
|
|
10
|
+
* 2. The preferred side, then its opposite, then the other two: the first one where the
|
|
11
|
+
* whole card fits between the target and the window's margin wins.
|
|
12
|
+
* 3. Along that side the card is centred on the target, and clamped inside the margins:
|
|
13
|
+
* a target at the window's edge keeps its card in view.
|
|
14
|
+
* Final: no side fits (the target is most of the window — a whole list): the card goes to
|
|
15
|
+
* the bottom of the window, over the target, where it covers the least of its top.
|
|
16
|
+
*/
|
|
17
|
+
const ORDER = {
|
|
18
|
+
bottom: ["bottom", "top", "right", "left"],
|
|
19
|
+
top: ["top", "bottom", "right", "left"],
|
|
20
|
+
right: ["right", "left", "bottom", "top"],
|
|
21
|
+
left: ["left", "right", "bottom", "top"],
|
|
22
|
+
};
|
|
23
|
+
/** Between `min` and `max`; when the card is wider than the room, its start edge wins — the
|
|
24
|
+
* title is what must stay readable. */
|
|
25
|
+
function clamp(value, min, max) {
|
|
26
|
+
return Math.max(min, Math.min(value, max));
|
|
27
|
+
}
|
|
28
|
+
function fits(side, target, card, view, gap, margin) {
|
|
29
|
+
switch (side) {
|
|
30
|
+
case "bottom":
|
|
31
|
+
return target.top + target.height + gap + card.height <= view.height - margin;
|
|
32
|
+
case "top":
|
|
33
|
+
return target.top - gap - card.height >= margin;
|
|
34
|
+
case "right":
|
|
35
|
+
return target.left + target.width + gap + card.width <= view.width - margin;
|
|
36
|
+
case "left":
|
|
37
|
+
return target.left - gap - card.width >= margin;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function placeCard({ target, card, view, prefer = "bottom", gap, margin, }) {
|
|
41
|
+
const across = (value) => clamp(value, margin, view.width - margin - card.width);
|
|
42
|
+
const down = (value) => clamp(value, margin, view.height - margin - card.height);
|
|
43
|
+
if (target === null) {
|
|
44
|
+
return {
|
|
45
|
+
top: down((view.height - card.height) / 2),
|
|
46
|
+
left: across((view.width - card.width) / 2),
|
|
47
|
+
side: "center",
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const middleX = target.left + target.width / 2 - card.width / 2;
|
|
51
|
+
const middleY = target.top + target.height / 2 - card.height / 2;
|
|
52
|
+
const side = ORDER[prefer].find((one) => fits(one, target, card, view, gap, margin));
|
|
53
|
+
switch (side) {
|
|
54
|
+
case "bottom":
|
|
55
|
+
return { top: target.top + target.height + gap, left: across(middleX), side };
|
|
56
|
+
case "top":
|
|
57
|
+
return { top: target.top - gap - card.height, left: across(middleX), side };
|
|
58
|
+
case "right":
|
|
59
|
+
return { top: down(middleY), left: target.left + target.width + gap, side };
|
|
60
|
+
case "left":
|
|
61
|
+
return { top: down(middleY), left: target.left - gap - card.width, side };
|
|
62
|
+
case undefined:
|
|
63
|
+
return {
|
|
64
|
+
top: down(view.height - margin - card.height),
|
|
65
|
+
left: across(middleX),
|
|
66
|
+
side: "over",
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Box } from "./place.js";
|
|
2
|
+
/**
|
|
3
|
+
* What a step of a tour points at.
|
|
4
|
+
*
|
|
5
|
+
* Context: the anchors are the ones the system already keeps stable, so no component needs a
|
|
6
|
+
* prop to be pointed at:
|
|
7
|
+
*
|
|
8
|
+
* - `{ part }` — a web-ui part (`data-ui`, listed in the README and guarded by a test):
|
|
9
|
+
* `{ part: "sidebar.search" }`. With `key`, one item of a collection:
|
|
10
|
+
* `{ part: "navigation.item", key: "socios.cuotas" }`.
|
|
11
|
+
* - `{ spot }` — anything the application marked: `<GuideSpot id="cifras">` or its own
|
|
12
|
+
* element with `data-guide="cifras"`.
|
|
13
|
+
* - `{ selector }` — any CSS selector, for what has no name yet.
|
|
14
|
+
* - a function — a ref, or whatever the application computes at that moment.
|
|
15
|
+
*/
|
|
16
|
+
export type GuideTarget = {
|
|
17
|
+
part: string;
|
|
18
|
+
key?: string;
|
|
19
|
+
} | {
|
|
20
|
+
spot: string;
|
|
21
|
+
} | {
|
|
22
|
+
selector: string;
|
|
23
|
+
} | (() => Element | null | undefined);
|
|
24
|
+
/** The CSS selector a target names; `null` for a function. */
|
|
25
|
+
export declare function selectorOf(target: Exclude<GuideTarget, () => unknown>): string;
|
|
26
|
+
export declare function selectorOf(target: GuideTarget): string | null;
|
|
27
|
+
/** The element's box on screen, `null` when it has none — hidden, or not laid out. A
|
|
28
|
+
* `GuideSpot` measures as the union of what it wraps. */
|
|
29
|
+
export declare function boxOf(element: Element): Box | null;
|
|
30
|
+
export type Found = {
|
|
31
|
+
/** The first match that is on screen. */
|
|
32
|
+
shown: Element | null;
|
|
33
|
+
/** A match that exists but is not on screen — the sidebar beside the view, on a phone. */
|
|
34
|
+
hidden: Element | null;
|
|
35
|
+
};
|
|
36
|
+
/** Of every match, the one on screen wins: the same sidebar is laid out twice on a phone —
|
|
37
|
+
* hidden beside the view, and shown in the drawer. */
|
|
38
|
+
export declare function findTarget(target: GuideTarget, root?: ParentNode): Found;
|
|
39
|
+
/** What to scroll so the target is in view: a `GuideSpot` has no box to scroll to, its first
|
|
40
|
+
* child does. */
|
|
41
|
+
export declare function scrollable(element: Element): Element;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/* A quoted attribute value: only `"` and `\` need escaping there — and unlike `CSS.escape`
|
|
3
|
+
this also runs where there is no DOM (a test, a server). */
|
|
4
|
+
const quoted = (value) => `"${value.replace(/["\\]/g, "\\$&")}"`;
|
|
5
|
+
export function selectorOf(target) {
|
|
6
|
+
if (typeof target === "function")
|
|
7
|
+
return null;
|
|
8
|
+
if ("part" in target) {
|
|
9
|
+
const part = `[data-ui=${quoted(target.part)}]`;
|
|
10
|
+
return target.key === undefined ? part : `${part}[data-key=${quoted(target.key)}]`;
|
|
11
|
+
}
|
|
12
|
+
if ("spot" in target)
|
|
13
|
+
return `[data-guide=${quoted(target.spot)}]`;
|
|
14
|
+
return target.selector;
|
|
15
|
+
}
|
|
16
|
+
/** `display: contents` has no box of its own (a `GuideSpot`): its box is its children's. */
|
|
17
|
+
function wraps(element) {
|
|
18
|
+
return getComputedStyle(element).display === "contents";
|
|
19
|
+
}
|
|
20
|
+
/** The element's box on screen, `null` when it has none — hidden, or not laid out. A
|
|
21
|
+
* `GuideSpot` measures as the union of what it wraps. */
|
|
22
|
+
export function boxOf(element) {
|
|
23
|
+
if (wraps(element)) {
|
|
24
|
+
const boxes = [...element.children].map(boxOf).filter((box) => box !== null);
|
|
25
|
+
if (boxes.length === 0)
|
|
26
|
+
return null;
|
|
27
|
+
const top = Math.min(...boxes.map((b) => b.top));
|
|
28
|
+
const left = Math.min(...boxes.map((b) => b.left));
|
|
29
|
+
const bottom = Math.max(...boxes.map((b) => b.top + b.height));
|
|
30
|
+
const right = Math.max(...boxes.map((b) => b.left + b.width));
|
|
31
|
+
return { top, left, width: right - left, height: bottom - top };
|
|
32
|
+
}
|
|
33
|
+
if (!element.checkVisibility({ visibilityProperty: true }))
|
|
34
|
+
return null;
|
|
35
|
+
const rect = element.getBoundingClientRect();
|
|
36
|
+
if (rect.width === 0 && rect.height === 0)
|
|
37
|
+
return null;
|
|
38
|
+
return { top: rect.top, left: rect.left, width: rect.width, height: rect.height };
|
|
39
|
+
}
|
|
40
|
+
/** Of every match, the one on screen wins: the same sidebar is laid out twice on a phone —
|
|
41
|
+
* hidden beside the view, and shown in the drawer. */
|
|
42
|
+
export function findTarget(target, root = document) {
|
|
43
|
+
const matches = typeof target === "function"
|
|
44
|
+
? [target()].filter((one) => one !== null && one !== undefined)
|
|
45
|
+
: [...root.querySelectorAll(selectorOf(target))];
|
|
46
|
+
return {
|
|
47
|
+
shown: matches.find((one) => boxOf(one) !== null) ?? null,
|
|
48
|
+
hidden: matches.find((one) => boxOf(one) === null) ?? null,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** What to scroll so the target is in view: a `GuideSpot` has no box to scroll to, its first
|
|
52
|
+
* child does. */
|
|
53
|
+
export function scrollable(element) {
|
|
54
|
+
return wraps(element) ? (element.firstElementChild ?? element) : element;
|
|
55
|
+
}
|
|
@@ -9,6 +9,7 @@ export * from "./flow/index.js";
|
|
|
9
9
|
export * from "./form/index.js";
|
|
10
10
|
export * from "./frame/index.js";
|
|
11
11
|
export * from "./gantt/index.js";
|
|
12
|
+
export * from "./guide/index.js";
|
|
12
13
|
export * from "./lines/index.js";
|
|
13
14
|
export * from "./listing/index.js";
|
|
14
15
|
export * from "./navigation/index.js";
|
package/dist/components/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./flow/index.js";
|
|
|
10
10
|
export * from "./form/index.js";
|
|
11
11
|
export * from "./frame/index.js";
|
|
12
12
|
export * from "./gantt/index.js";
|
|
13
|
+
export * from "./guide/index.js";
|
|
13
14
|
export * from "./lines/index.js";
|
|
14
15
|
export * from "./listing/index.js";
|
|
15
16
|
export * from "./navigation/index.js";
|