@polyxd/react 0.1.1 → 0.2.1
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/dist/components/action-bar.d.ts +16 -0
- package/dist/components/action-bar.js +96 -0
- package/dist/components/action-bar.js.map +1 -0
- package/dist/components/chart.js +133 -2
- package/dist/components/chart.js.map +1 -1
- package/dist/components/content.d.ts +16 -0
- package/dist/components/content.js +540 -19
- package/dist/components/content.js.map +1 -1
- package/dist/components/flow.d.ts +0 -4
- package/dist/components/flow.js +124 -6
- package/dist/components/flow.js.map +1 -1
- package/dist/components/index.js +7 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/inputs.d.ts +8 -0
- package/dist/components/inputs.js +334 -11
- package/dist/components/inputs.js.map +1 -1
- package/dist/components/marks.d.ts +40 -0
- package/dist/components/marks.js +221 -0
- package/dist/components/marks.js.map +1 -0
- package/dist/components/navigation.d.ts +2 -1
- package/dist/components/navigation.js +48 -12
- package/dist/components/navigation.js.map +1 -1
- package/dist/components/overlays.d.ts +18 -0
- package/dist/components/overlays.js +128 -0
- package/dist/components/overlays.js.map +1 -0
- package/dist/components/pickers.d.ts +10 -0
- package/dist/components/pickers.js +402 -0
- package/dist/components/pickers.js.map +1 -0
- package/dist/components/table.d.ts +5 -0
- package/dist/components/table.js +19 -10
- package/dist/components/table.js.map +1 -1
- package/dist/components/tree.d.ts +11 -0
- package/dist/components/tree.js +268 -0
- package/dist/components/tree.js.map +1 -0
- package/dist/context.d.ts +2 -0
- package/dist/context.js.map +1 -1
- package/dist/format.d.ts +3 -1
- package/dist/format.js +19 -0
- package/dist/format.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/skeleton.d.ts +16 -0
- package/dist/skeleton.js +30 -0
- package/dist/skeleton.js.map +1 -0
- package/dist/surface.js +4 -3
- package/dist/surface.js.map +1 -1
- package/package.json +2 -2
- package/src/styles.css +2226 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.js","sourceRoot":"","sources":["../../src/components/navigation.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAa,MAAM,eAAgB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAgB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAc,CAAC;AAEpC,kEAAkE;AAClE,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB
|
|
1
|
+
{"version":3,"file":"navigation.js","sourceRoot":"","sources":["../../src/components/navigation.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAa,MAAM,eAAgB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAgB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAc,CAAC;AAEpC,kEAAkE;AAClE,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,IAAI,EAAkB;IACjD,MAAM,CAAC,GAAG,WAAW,EAAE,CAAC;IACxB,MAAM,CAAC,GAAG,UAAU,EAAE,CAAC;IACvB,MAAM,GAAG,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IACzC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxC,MAAM,CAAC,O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ChC,KAAC,MAAM,CAAC,OAAO,IAAC,SAAS,EAAC,aAAa,GAAG,EAC1C,MAAC,MAAM,CAAC,OAAO,IAAC,SAAS,EAAC,gBAAgB,sBAAmB,SAAS,aACpE,eAAK,SAAS,EAAC,kBAAkB,aAC/B,KAAC,MAAM,CAAC,KAAK,IAAC,SAAS,EAAC,iBAAiB,YAAE,KAAK,GAAgB,EAChE,KAAC,MAAM,CAAC,KAAK,IAAC,SAAS,EAAC,iBAAiB,gBAAY,OAAO,YAC1D,KAAC,IAAI,IAAC,IAAI,EAAC,OAAO,GAAG,GACR,IACX,EACL,IAAI,IACU,IACH,IACJ,CACf,CAAC,CAAC,CAAC,CACF,IAAI,CACL,GACG,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Node } from "../context.tsx";
|
|
2
|
+
/**
|
|
3
|
+
* Secondary actions behind one control. The children are Actions; each becomes a menu item that
|
|
4
|
+
* dispatches that Action. A danger-toned Action goes last, after a divider. `context` also renders
|
|
5
|
+
* an overflow control, since right-click and long-press are not discoverable.
|
|
6
|
+
*/
|
|
7
|
+
export declare function ActionMenu({ node }: {
|
|
8
|
+
node: Node;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
/**
|
|
11
|
+
* Content over the current view. `open` may be bound to host data (the renderer writes false on
|
|
12
|
+
* dismiss); absent, the panel is open until dismissed. Dismissal also dispatches ui.dismiss, like
|
|
13
|
+
* Confirm. dialog, drawer and sheet are modal (Radix Dialog); popover is a non-modal Radix Popover
|
|
14
|
+
* anchored where the Panel sits in the tree.
|
|
15
|
+
*/
|
|
16
|
+
export declare function Panel({ node }: {
|
|
17
|
+
node: Node;
|
|
18
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createElement, useContext, useId, useRef, useState } from "react";
|
|
3
|
+
import { ContextMenu, Dialog, DropdownMenu, Popover } from "radix-ui";
|
|
4
|
+
import { HeadingContext, useBindings, useSurface } from "../context.js";
|
|
5
|
+
import { Render, useA11y } from "../surface.js";
|
|
6
|
+
import { Children } from "./structure.js";
|
|
7
|
+
import { Icon } from "./avatar.js";
|
|
8
|
+
/** Whether a Dynamic* value is a binding (rather than a literal). */
|
|
9
|
+
const isBinding = (v) => typeof v === "object" && v !== null && typeof v.path === "string";
|
|
10
|
+
/** A downward chevron: the one glyph the icon set lacks. */
|
|
11
|
+
function Chevron() {
|
|
12
|
+
return (_jsx("svg", { className: "pxd-action-menu-chevron", width: 16, height: 16, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m6 9 6 6 6-6" }) }));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Secondary actions behind one control. The children are Actions; each becomes a menu item that
|
|
16
|
+
* dispatches that Action. A danger-toned Action goes last, after a divider. `context` also renders
|
|
17
|
+
* an overflow control, since right-click and long-press are not discoverable.
|
|
18
|
+
*/
|
|
19
|
+
export function ActionMenu({ node }) {
|
|
20
|
+
const b = useBindings();
|
|
21
|
+
const s = useSurface();
|
|
22
|
+
const a11y = useA11y(node);
|
|
23
|
+
const kind = node.kind ?? "overflow";
|
|
24
|
+
const label = b.text(node.label);
|
|
25
|
+
// accessibility.label, when the author set one, wins over the control's own label.
|
|
26
|
+
const name = a11y["aria-label"] ?? label;
|
|
27
|
+
const actions = (node.children ?? [])
|
|
28
|
+
.map((id) => s.byId.get(id))
|
|
29
|
+
.filter((c) => Boolean(c) && (c.visible === undefined || b.value(c.visible) !== false));
|
|
30
|
+
const usual = actions.filter((a) => a.tone !== "danger");
|
|
31
|
+
const danger = actions.filter((a) => a.tone === "danger");
|
|
32
|
+
const items = (M) => {
|
|
33
|
+
const item = (a) => (_jsx(M.Item, { className: `pxd-menu-item${a.tone === "danger" ? " pxd-menu-item-danger" : ""}`, disabled: a.disabled !== undefined ? Boolean(b.value(a.disabled)) : undefined, onSelect: () => s.dispatch(a.action, b.scope, a.id), "data-pxd-id": a.id, "data-pxd-component": a.component, children: b.text(a.label) }, a.id));
|
|
34
|
+
return (_jsxs(_Fragment, { children: [usual.map(item), danger.length > 0 && usual.length > 0 && _jsx(M.Separator, { className: "pxd-menu-separator" }), danger.map(item)] }));
|
|
35
|
+
};
|
|
36
|
+
const overflowTrigger = (_jsx(DropdownMenu.Trigger, { className: "pxd-icon-button pxd-action-menu-trigger pxd-action-menu-overflow", ...a11y, "aria-label": name, children: _jsx(Icon, { name: "dots", size: 18 }) }));
|
|
37
|
+
const menu = (_jsx(DropdownMenu.Portal, { container: s.portal, children: _jsx(DropdownMenu.Content, { className: "pxd-menu pxd-action-menu", align: "end", sideOffset: 4, children: items(DropdownMenu) }) }));
|
|
38
|
+
if (kind === "dropdown")
|
|
39
|
+
return (_jsxs(DropdownMenu.Root, { children: [_jsxs(DropdownMenu.Trigger, { className: "pxd-button pxd-button-secondary pxd-action-menu-trigger pxd-action-menu-dropdown", ...a11y, "aria-label": a11y["aria-label"], children: [label, _jsx(Chevron, {})] }), menu] }));
|
|
40
|
+
if (kind === "split") {
|
|
41
|
+
// The menu part takes the primary's emphasis so the two read as one control.
|
|
42
|
+
const primary = node.primary ? s.byId.get(node.primary) : undefined;
|
|
43
|
+
const emphasis = primary?.emphasis ?? "secondary";
|
|
44
|
+
return (_jsxs(DropdownMenu.Root, { children: [_jsxs("div", { className: "pxd-split", role: "group", ...a11y, "aria-label": name, children: [node.primary && _jsx(Render, { id: node.primary }), _jsx(DropdownMenu.Trigger, { className: `pxd-button pxd-button-${emphasis} pxd-action-menu-trigger pxd-split-menu`, "aria-label": `${label}: more options`, children: _jsx(Chevron, {}) })] }), menu] }));
|
|
45
|
+
}
|
|
46
|
+
if (kind === "context")
|
|
47
|
+
return (_jsxs(ContextMenu.Root, { children: [_jsx(ContextMenu.Trigger, { asChild: true, children: _jsx("span", { className: "pxd-context-target", children: _jsxs(DropdownMenu.Root, { children: [overflowTrigger, menu] }) }) }), _jsx(ContextMenu.Portal, { container: s.portal, children: _jsx(ContextMenu.Content, { className: "pxd-menu pxd-action-menu", "aria-label": name, children: items(ContextMenu) }) })] }));
|
|
48
|
+
return (_jsxs(DropdownMenu.Root, { children: [overflowTrigger, menu] }));
|
|
49
|
+
}
|
|
50
|
+
/** Drag a bottom sheet down to dismiss it. Handlers go on the header; the transform on the sheet. */
|
|
51
|
+
function useDragDown(enabled, sheet, onDismiss) {
|
|
52
|
+
const start = useRef(null);
|
|
53
|
+
const reset = () => {
|
|
54
|
+
start.current = null;
|
|
55
|
+
if (sheet.current) {
|
|
56
|
+
sheet.current.style.transform = "";
|
|
57
|
+
sheet.current.style.transition = "";
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
if (!enabled)
|
|
61
|
+
return {};
|
|
62
|
+
return {
|
|
63
|
+
onPointerDown: (e) => {
|
|
64
|
+
if (e.pointerType === "mouse" && e.button !== 0)
|
|
65
|
+
return;
|
|
66
|
+
start.current = e.clientY;
|
|
67
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
68
|
+
},
|
|
69
|
+
onPointerMove: (e) => {
|
|
70
|
+
if (start.current === null || !sheet.current)
|
|
71
|
+
return;
|
|
72
|
+
const dy = Math.max(0, e.clientY - start.current);
|
|
73
|
+
sheet.current.style.transition = "none";
|
|
74
|
+
sheet.current.style.transform = `translateY(${dy}px)`;
|
|
75
|
+
},
|
|
76
|
+
onPointerUp: (e) => {
|
|
77
|
+
if (start.current === null)
|
|
78
|
+
return;
|
|
79
|
+
const dy = e.clientY - start.current;
|
|
80
|
+
reset();
|
|
81
|
+
if (dy > 80)
|
|
82
|
+
onDismiss();
|
|
83
|
+
},
|
|
84
|
+
onPointerCancel: reset,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Content over the current view. `open` may be bound to host data (the renderer writes false on
|
|
89
|
+
* dismiss); absent, the panel is open until dismissed. Dismissal also dispatches ui.dismiss, like
|
|
90
|
+
* Confirm. dialog, drawer and sheet are modal (Radix Dialog); popover is a non-modal Radix Popover
|
|
91
|
+
* anchored where the Panel sits in the tree.
|
|
92
|
+
*/
|
|
93
|
+
export function Panel({ node }) {
|
|
94
|
+
const b = useBindings();
|
|
95
|
+
const s = useSurface();
|
|
96
|
+
const a11y = useA11y(node);
|
|
97
|
+
const level = Math.min(useContext(HeadingContext), 6);
|
|
98
|
+
const titleId = useId();
|
|
99
|
+
const sheetRef = useRef(null);
|
|
100
|
+
const kind = node.kind ?? "dialog";
|
|
101
|
+
const size = node.size ?? "default";
|
|
102
|
+
const dismissible = node.dismissible !== false;
|
|
103
|
+
const bound = isBinding(node.open);
|
|
104
|
+
const [local, setLocal] = useState(true);
|
|
105
|
+
const open = bound ? Boolean(b.value(node.open)) : local && node.open !== false;
|
|
106
|
+
const close = () => {
|
|
107
|
+
if (bound)
|
|
108
|
+
b.write(node.open, false);
|
|
109
|
+
else
|
|
110
|
+
setLocal(false);
|
|
111
|
+
s.dispatch({ event: { name: "ui.dismiss" } }, b.scope, node.id);
|
|
112
|
+
};
|
|
113
|
+
const onOpenChange = (o) => {
|
|
114
|
+
if (!o)
|
|
115
|
+
close();
|
|
116
|
+
};
|
|
117
|
+
// A panel that must be completed ignores Escape and the backdrop.
|
|
118
|
+
const guard = dismissible ? {} : { onEscapeKeyDown: (e) => e.preventDefault(), onInteractOutside: (e) => e.preventDefault() };
|
|
119
|
+
const drag = useDragDown(kind === "sheet" && dismissible, sheetRef, close);
|
|
120
|
+
const title = b.text(node.title);
|
|
121
|
+
const className = `pxd-panel pxd-panel-${kind} pxd-panel-size-${size}`;
|
|
122
|
+
const body = (_jsx(HeadingContext.Provider, { value: level + 1, children: _jsx("div", { className: "pxd-panel-body pxd-stack", children: _jsx(Children, { ids: node.children }) }) }));
|
|
123
|
+
const footer = node.actions && (_jsx("div", { className: "pxd-panel-footer", children: _jsx(Render, { id: node.actions }) }));
|
|
124
|
+
if (kind === "popover")
|
|
125
|
+
return (_jsxs(Popover.Root, { open: open, onOpenChange: onOpenChange, children: [_jsx(Popover.Anchor, { className: "pxd-panel-anchor" }), _jsx(Popover.Portal, { container: s.portal, children: _jsxs(Popover.Content, { className: className, "aria-labelledby": titleId, sideOffset: 8, collisionPadding: 8, ...guard, ...a11y, children: [_jsxs("div", { className: "pxd-panel-header", children: [createElement(`h${level}`, { id: titleId, className: "pxd-panel-title" }, title), dismissible && (_jsx(Popover.Close, { className: "pxd-icon-button pxd-panel-close", "aria-label": "Close", children: _jsx(Icon, { name: "close" }) }))] }), body, footer, _jsx(Popover.Arrow, { className: "pxd-panel-arrow", width: 16, height: 8 })] }) })] }));
|
|
126
|
+
return (_jsx(Dialog.Root, { open: open, onOpenChange: onOpenChange, children: _jsxs(Dialog.Portal, { container: s.portal, children: [_jsx(Dialog.Overlay, { className: "pxd-overlay pxd-panel-backdrop" }), _jsxs(Dialog.Content, { ref: sheetRef, className: className, "aria-describedby": undefined, ...guard, ...a11y, children: [_jsxs("div", { className: "pxd-panel-header", ...drag, children: [kind === "sheet" && _jsx("span", { className: "pxd-panel-grip", "aria-hidden": "true" }), _jsx(Dialog.Title, { asChild: true, children: createElement(`h${level}`, { className: "pxd-panel-title" }, title) }), dismissible && (_jsx(Dialog.Close, { className: "pxd-icon-button pxd-panel-close", "aria-label": "Close", children: _jsx(Icon, { name: "close" }) }))] }), body, footer] })] }) }));
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=overlays.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlays.js","sourceRoot":"","sources":["../../src/components/overlays.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAA8D,MAAM,OAAO,CAAC;AACvI,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,OA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AC,IAAI,EAAC,OAAO,GAAG,GACR,CAChB,IACG,EACL,IAAI,EACJ,MAAM,IACQ,IACH,GACJ,CACf,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Node } from "../context.tsx";
|
|
2
|
+
export declare function FileInput({ node }: {
|
|
3
|
+
node: Node;
|
|
4
|
+
}): import("react").JSX.Element;
|
|
5
|
+
export declare function ColorInput({ node }: {
|
|
6
|
+
node: Node;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
8
|
+
export declare function CodeInput({ node }: {
|
|
9
|
+
node: Node;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useRef, useState } from "react";
|
|
3
|
+
import { RadioGroup } from "radix-ui";
|
|
4
|
+
import { useBindings, useSurface } from "../context.js";
|
|
5
|
+
import { absolute } from "../data.js";
|
|
6
|
+
import { useA11y } from "../surface.js";
|
|
7
|
+
import { optionsOf } from "./inputs.js";
|
|
8
|
+
import { Icon } from "./avatar.js";
|
|
9
|
+
/*
|
|
10
|
+
* Pickers: files, colours and one-time codes. Each follows the input conventions in inputs.tsx:
|
|
11
|
+
* a `pxd-field` with a `pxd-field-label`, optional `pxd-field-help`, the required mark, and the
|
|
12
|
+
* value written back through the node's binding.
|
|
13
|
+
*/
|
|
14
|
+
/** Same as inputs.tsx's mark: for the eye only, the control carries `required` for the reader. */
|
|
15
|
+
const RequiredMark = () => (_jsx("span", { className: "pxd-required", "aria-hidden": "true", children: "*" }));
|
|
16
|
+
/** Dispatch `node.action` with `next` applied wherever its context binds to `node.value` (as Toggle does). */
|
|
17
|
+
function dispatchWith(s, b, node, next) {
|
|
18
|
+
const ptr = b.pointer(node.value);
|
|
19
|
+
const context = Object.fromEntries(Object.entries(node.action.event.context ?? {}).map(([k, v]) => [k, v && typeof v === "object" && "path" in v && absolute(v.path, b.scope) === ptr ? next : b.value(v)]));
|
|
20
|
+
s.dispatch({ event: { name: node.action.event.name, context } }, { pointer: "" }, node.id);
|
|
21
|
+
}
|
|
22
|
+
const describedBy = (...ids) => ids.filter(Boolean).join(" ") || undefined;
|
|
23
|
+
const UNITS = ["byte", "kilobyte", "megabyte", "gigabyte"];
|
|
24
|
+
function formatBytes(n, locale) {
|
|
25
|
+
let i = 0;
|
|
26
|
+
let v = n;
|
|
27
|
+
while (v >= 1024 && i < UNITS.length - 1) {
|
|
28
|
+
v /= 1024;
|
|
29
|
+
i++;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
return new Intl.NumberFormat(locale, { style: "unit", unit: UNITS[i], unitDisplay: "short", maximumFractionDigits: v < 10 ? 1 : 0 }).format(v);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return `${Math.round(v * 10) / 10} ${["B", "KB", "MB", "GB"][i]}`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** '.pdf' → 'PDF', 'image/*' → 'images', 'application/zip' → 'ZIP'. */
|
|
39
|
+
function describeType(a) {
|
|
40
|
+
const t = a.trim().toLowerCase();
|
|
41
|
+
if (t.startsWith("."))
|
|
42
|
+
return t.slice(1).toUpperCase();
|
|
43
|
+
const wild = { "image/*": "images", "video/*": "videos", "audio/*": "audio", "text/*": "text files" };
|
|
44
|
+
if (wild[t])
|
|
45
|
+
return wild[t];
|
|
46
|
+
if (t === "application/pdf")
|
|
47
|
+
return "PDF";
|
|
48
|
+
const sub = t.split("/")[1];
|
|
49
|
+
return sub ? sub.replace(/^(x-|vnd\.)/, "").toUpperCase() : a;
|
|
50
|
+
}
|
|
51
|
+
function listText(items) {
|
|
52
|
+
if (items.length <= 1)
|
|
53
|
+
return items.join("");
|
|
54
|
+
return `${items.slice(0, -1).join(", ")} or ${items[items.length - 1]}`;
|
|
55
|
+
}
|
|
56
|
+
function matchesAccept(file, accept) {
|
|
57
|
+
if (accept.length === 0)
|
|
58
|
+
return true;
|
|
59
|
+
const name = file.name.toLowerCase();
|
|
60
|
+
const type = file.type.toLowerCase();
|
|
61
|
+
return accept.some((a) => {
|
|
62
|
+
const t = a.trim().toLowerCase();
|
|
63
|
+
if (t.startsWith("."))
|
|
64
|
+
return name.endsWith(t);
|
|
65
|
+
if (t.endsWith("/*"))
|
|
66
|
+
return type.startsWith(t.slice(0, -1));
|
|
67
|
+
return type === t;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const revoke = (f) => {
|
|
71
|
+
if (typeof f.ref === "string" && f.ref.startsWith("blob:"))
|
|
72
|
+
URL.revokeObjectURL(f.ref);
|
|
73
|
+
};
|
|
74
|
+
export function FileInput({ node }) {
|
|
75
|
+
const b = useBindings();
|
|
76
|
+
const s = useSurface();
|
|
77
|
+
const id = useId();
|
|
78
|
+
const helpId = useId();
|
|
79
|
+
const errorId = useId();
|
|
80
|
+
const [error, setError] = useState(null);
|
|
81
|
+
const [dragging, setDragging] = useState(false);
|
|
82
|
+
const raw = b.value(node.value);
|
|
83
|
+
const files = Array.isArray(raw) ? raw : [];
|
|
84
|
+
const accept = Array.isArray(node.accept) ? node.accept : [];
|
|
85
|
+
const maxSize = node.maxSize;
|
|
86
|
+
const multiple = Boolean(node.multiple);
|
|
87
|
+
const label = b.text(node.label);
|
|
88
|
+
// The limits are always said before choosing, after whatever the host says about what to attach.
|
|
89
|
+
const acceptText = accept.length ? listText(accept.map(describeType)) : "";
|
|
90
|
+
const limits = [acceptText && `Accepts ${acceptText}.`, maxSize && `Up to ${formatBytes(maxSize, s.locale)}${multiple ? " each" : ""}.`].filter(Boolean).join(" ");
|
|
91
|
+
const help = [node.help !== undefined ? b.text(node.help) : "", limits].filter(Boolean).join(" ") || undefined;
|
|
92
|
+
const add = (list) => {
|
|
93
|
+
if (!list)
|
|
94
|
+
return;
|
|
95
|
+
const chosen = Array.from(list);
|
|
96
|
+
const accepted = [];
|
|
97
|
+
const refused = [];
|
|
98
|
+
for (const f of multiple ? chosen : chosen.slice(0, 1)) {
|
|
99
|
+
if (maxSize && f.size > maxSize)
|
|
100
|
+
refused.push(`${f.name} is ${formatBytes(f.size, s.locale)}; the limit is ${formatBytes(maxSize, s.locale)}.`);
|
|
101
|
+
else if (!matchesAccept(f, accept))
|
|
102
|
+
refused.push(`${f.name} isn't an accepted type${acceptText ? ` (${acceptText})` : ""}.`);
|
|
103
|
+
else
|
|
104
|
+
accepted.push({ name: f.name, size: f.size, type: f.type, ref: URL.createObjectURL(f) });
|
|
105
|
+
}
|
|
106
|
+
setError(refused.length ? refused.join(" ") : null);
|
|
107
|
+
if (accepted.length === 0)
|
|
108
|
+
return;
|
|
109
|
+
if (multiple) {
|
|
110
|
+
// The same file chosen twice is one file.
|
|
111
|
+
const fresh = accepted.filter((a) => !files.some((f) => f.name === a.name && f.size === a.size));
|
|
112
|
+
accepted.filter((a) => !fresh.includes(a)).forEach(revoke);
|
|
113
|
+
if (fresh.length)
|
|
114
|
+
b.write(node.value, [...files, ...fresh]);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
files.forEach(revoke);
|
|
118
|
+
b.write(node.value, accepted);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const remove = (i) => {
|
|
122
|
+
revoke(files[i]);
|
|
123
|
+
b.write(node.value, files.filter((_, j) => j !== i));
|
|
124
|
+
setError(null);
|
|
125
|
+
};
|
|
126
|
+
const onDrop = (e) => {
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
setDragging(false);
|
|
129
|
+
add(e.dataTransfer.files);
|
|
130
|
+
};
|
|
131
|
+
const onDragOver = (e) => {
|
|
132
|
+
e.preventDefault();
|
|
133
|
+
if (!dragging)
|
|
134
|
+
setDragging(true);
|
|
135
|
+
};
|
|
136
|
+
const onDragLeave = (e) => {
|
|
137
|
+
// Leaving a child still counts as inside the zone.
|
|
138
|
+
if (!e.currentTarget.contains(e.relatedTarget))
|
|
139
|
+
setDragging(false);
|
|
140
|
+
};
|
|
141
|
+
return (_jsxs("div", { className: "pxd-field pxd-file", children: [_jsxs("label", { className: "pxd-field-label", htmlFor: id, children: [label, node.required && _jsx(RequiredMark, {})] }), help && (_jsx("p", { className: "pxd-field-help", id: helpId, children: help })), _jsxs("div", { className: "pxd-dropzone", "data-dragging": dragging || undefined, onDrop: onDrop, onDragOver: onDragOver, onDragLeave: onDragLeave, children: [_jsx("input", { id: id, className: "pxd-dropzone-input", type: "file", accept: accept.length ? accept.join(",") : undefined, multiple: multiple, required: node.required && files.length === 0, "aria-describedby": describedBy(help && helpId, error && errorId), "aria-invalid": error ? true : undefined, onChange: (e) => {
|
|
142
|
+
add(e.target.files);
|
|
143
|
+
e.target.value = "";
|
|
144
|
+
}, ...useA11y(node) }), _jsx("span", { className: "pxd-dropzone-icon", "aria-hidden": "true", children: _jsx(Icon, { name: "file", size: 24 }) }), _jsxs("span", { className: "pxd-dropzone-text", children: [_jsx("span", { className: "pxd-dropzone-action", children: multiple ? "Choose files" : "Choose a file" }), _jsx("span", { className: "pxd-dropzone-hint", children: multiple ? "or drop them here" : "or drop it here" })] })] }), error && (_jsx("p", { className: "pxd-field-error", id: errorId, role: "alert", children: error })), files.length > 0 && (_jsx("ul", { className: "pxd-file-list", children: files.map((f, i) => (_jsxs("li", { className: "pxd-file-item", children: [_jsx("span", { className: "pxd-file-icon", "aria-hidden": "true", children: _jsx(Icon, { name: "file", size: 18 }) }), _jsxs("span", { className: "pxd-file-text", children: [_jsx("span", { className: "pxd-file-name", children: f.name }), _jsx("span", { className: "pxd-file-size", children: formatBytes(f.size, s.locale) }), typeof f.progress === "number" && f.progress < 1 && _jsx("progress", { className: "pxd-file-progress", value: f.progress, max: 1, "aria-label": `Uploading ${f.name}` })] }), _jsx("button", { type: "button", className: "pxd-file-remove", "aria-label": `Remove ${f.name}`, onClick: () => remove(i), children: _jsx(Icon, { name: "close", size: 18 }) })] }, `${f.name}-${f.size}-${i}`))) }))] }));
|
|
145
|
+
}
|
|
146
|
+
const clamp = (n, lo, hi) => Math.min(hi, Math.max(lo, n));
|
|
147
|
+
const hex2 = (n) => clamp(Math.round(n), 0, 255).toString(16).padStart(2, "0");
|
|
148
|
+
const parseAlpha = (t) => (t === undefined ? 1 : clamp(t.endsWith("%") ? parseFloat(t) / 100 : parseFloat(t), 0, 1));
|
|
149
|
+
const channel = (t) => (t.endsWith("%") ? (parseFloat(t) / 100) * 255 : parseFloat(t));
|
|
150
|
+
function hslToRgb(h, s, l) {
|
|
151
|
+
const hh = (((h % 360) + 360) % 360) / 360;
|
|
152
|
+
if (s === 0)
|
|
153
|
+
return [l * 255, l * 255, l * 255];
|
|
154
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
155
|
+
const p = 2 * l - q;
|
|
156
|
+
const f = (t) => {
|
|
157
|
+
if (t < 0)
|
|
158
|
+
t += 1;
|
|
159
|
+
if (t > 1)
|
|
160
|
+
t -= 1;
|
|
161
|
+
if (t < 1 / 6)
|
|
162
|
+
return p + (q - p) * 6 * t;
|
|
163
|
+
if (t < 1 / 2)
|
|
164
|
+
return q;
|
|
165
|
+
if (t < 2 / 3)
|
|
166
|
+
return p + (q - p) * (2 / 3 - t) * 6;
|
|
167
|
+
return p;
|
|
168
|
+
};
|
|
169
|
+
return [f(hh + 1 / 3) * 255, f(hh) * 255, f(hh - 1 / 3) * 255];
|
|
170
|
+
}
|
|
171
|
+
function rgbToHsl(r, g, b) {
|
|
172
|
+
const rr = r / 255;
|
|
173
|
+
const gg = g / 255;
|
|
174
|
+
const bb = b / 255;
|
|
175
|
+
const max = Math.max(rr, gg, bb);
|
|
176
|
+
const min = Math.min(rr, gg, bb);
|
|
177
|
+
const l = (max + min) / 2;
|
|
178
|
+
if (max === min)
|
|
179
|
+
return [0, 0, l];
|
|
180
|
+
const d = max - min;
|
|
181
|
+
const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
182
|
+
let h = max === rr ? (gg - bb) / d + (gg < bb ? 6 : 0) : max === gg ? (bb - rr) / d + 2 : (rr - gg) / d + 4;
|
|
183
|
+
h /= 6;
|
|
184
|
+
return [h * 360, s, l];
|
|
185
|
+
}
|
|
186
|
+
/** Parse CSS hex, rgb()/rgba() and hsl()/hsla() text; null when it isn't a colour yet. */
|
|
187
|
+
function parseColor(text) {
|
|
188
|
+
if (typeof text !== "string")
|
|
189
|
+
return null;
|
|
190
|
+
const t = text.trim();
|
|
191
|
+
const hex = /^#([0-9a-f]{3,8})$/i.exec(t);
|
|
192
|
+
if (hex) {
|
|
193
|
+
const h = hex[1];
|
|
194
|
+
if (h.length === 3 || h.length === 4) {
|
|
195
|
+
const [r, g, b, a] = h.split("").map((c) => parseInt(c + c, 16));
|
|
196
|
+
return { r, g, b, a: h.length === 4 ? a / 255 : 1 };
|
|
197
|
+
}
|
|
198
|
+
if (h.length === 6 || h.length === 8) {
|
|
199
|
+
const at = (i) => parseInt(h.slice(i, i + 2), 16);
|
|
200
|
+
return { r: at(0), g: at(2), b: at(4), a: h.length === 8 ? at(6) / 255 : 1 };
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
const fn = /^(rgba?|hsla?)\(\s*([^)]+?)\s*\)$/i.exec(t);
|
|
205
|
+
if (!fn)
|
|
206
|
+
return null;
|
|
207
|
+
const parts = fn[2].split(/\s*[,/]\s*|\s+/).filter(Boolean);
|
|
208
|
+
if (parts.length < 3 || parts.length > 4)
|
|
209
|
+
return null;
|
|
210
|
+
const a = parseAlpha(parts[3]);
|
|
211
|
+
if (Number.isNaN(a))
|
|
212
|
+
return null;
|
|
213
|
+
if (fn[1].toLowerCase().startsWith("rgb")) {
|
|
214
|
+
const [r, g, b] = parts.slice(0, 3).map(channel);
|
|
215
|
+
if ([r, g, b].some(Number.isNaN))
|
|
216
|
+
return null;
|
|
217
|
+
return { r: clamp(r, 0, 255), g: clamp(g, 0, 255), b: clamp(b, 0, 255), a };
|
|
218
|
+
}
|
|
219
|
+
const h = parseFloat(parts[0]);
|
|
220
|
+
const sat = parseFloat(parts[1]) / 100;
|
|
221
|
+
const light = parseFloat(parts[2]) / 100;
|
|
222
|
+
if ([h, sat, light].some(Number.isNaN))
|
|
223
|
+
return null;
|
|
224
|
+
const [r, g, b] = hslToRgb(h, clamp(sat, 0, 1), clamp(light, 0, 1));
|
|
225
|
+
return { r, g, b, a };
|
|
226
|
+
}
|
|
227
|
+
/** Write a colour as CSS text in the requested format; alpha appears only when allowed and below 1. */
|
|
228
|
+
function formatColor(c, format, alpha) {
|
|
229
|
+
const a = alpha ? Math.round(c.a * 100) / 100 : 1;
|
|
230
|
+
const r = Math.round(c.r);
|
|
231
|
+
const g = Math.round(c.g);
|
|
232
|
+
const b = Math.round(c.b);
|
|
233
|
+
if (format === "rgb")
|
|
234
|
+
return a < 1 ? `rgba(${r}, ${g}, ${b}, ${a})` : `rgb(${r}, ${g}, ${b})`;
|
|
235
|
+
if (format === "hsl") {
|
|
236
|
+
const [h, s, l] = rgbToHsl(r, g, b);
|
|
237
|
+
const hh = Math.round(h);
|
|
238
|
+
const ss = Math.round(s * 100);
|
|
239
|
+
const ll = Math.round(l * 100);
|
|
240
|
+
return a < 1 ? `hsla(${hh}, ${ss}%, ${ll}%, ${a})` : `hsl(${hh}, ${ss}%, ${ll}%)`;
|
|
241
|
+
}
|
|
242
|
+
return `#${hex2(r)}${hex2(g)}${hex2(b)}${a < 1 ? hex2(a * 255) : ""}`;
|
|
243
|
+
}
|
|
244
|
+
const toHex6 = (c) => (c ? `#${hex2(c.r)}${hex2(c.g)}${hex2(c.b)}` : "#000000");
|
|
245
|
+
const OTHER = "__other";
|
|
246
|
+
export function ColorInput({ node }) {
|
|
247
|
+
const b = useBindings();
|
|
248
|
+
const s = useSurface();
|
|
249
|
+
const labelId = useId();
|
|
250
|
+
const helpId = useId();
|
|
251
|
+
const pickerId = useId();
|
|
252
|
+
const textId = useId();
|
|
253
|
+
const alphaId = useId();
|
|
254
|
+
const format = node.format ?? "hex";
|
|
255
|
+
const alpha = Boolean(node.alpha);
|
|
256
|
+
const label = b.text(node.label);
|
|
257
|
+
const help = node.help !== undefined ? b.text(node.help) : undefined;
|
|
258
|
+
const stored = b.value(node.value);
|
|
259
|
+
const storedText = stored === null || stored === undefined ? "" : String(stored);
|
|
260
|
+
const parsed = parseColor(storedText);
|
|
261
|
+
const [draft, setDraft] = useState(null);
|
|
262
|
+
const [otherChosen, setOtherChosen] = useState(false);
|
|
263
|
+
const a11y = useA11y(node);
|
|
264
|
+
const swatches = node.swatches ? optionsOf({ ...node, options: node.swatches }, s.data, b.scope, b.text) : [];
|
|
265
|
+
const hasSwatches = swatches.length > 0;
|
|
266
|
+
const write = (c) => b.write(node.value, formatColor(c, format, alpha));
|
|
267
|
+
const onText = (text) => {
|
|
268
|
+
setDraft(text);
|
|
269
|
+
const c = parseColor(text);
|
|
270
|
+
if (c)
|
|
271
|
+
write(c);
|
|
272
|
+
};
|
|
273
|
+
// Which swatch holds the current value (by colour, not by text: '#FFF' is 'rgb(255, 255, 255)').
|
|
274
|
+
const same = (a, c) => Boolean(a && c && Math.round(a.r) === Math.round(c.r) && Math.round(a.g) === Math.round(c.g) && Math.round(a.b) === Math.round(c.b) && (!alpha || Math.abs(a.a - c.a) < 0.005));
|
|
275
|
+
const matchIdx = swatches.findIndex((o) => (parsed ? same(parseColor(o.value), parsed) : String(o.value) === storedText && storedText !== ""));
|
|
276
|
+
const current = otherChosen ? OTHER : matchIdx >= 0 ? String(matchIdx) : storedText ? OTHER : "";
|
|
277
|
+
const showPicker = !hasSwatches || current === OTHER;
|
|
278
|
+
const picker = (_jsxs("div", { className: "pxd-color-picker", children: [_jsx("input", { id: pickerId, className: "pxd-color-native", type: "color", value: toHex6(parsed), "aria-label": `${label}: pick`, "aria-describedby": describedBy(help && helpId), onChange: (e) => {
|
|
279
|
+
const c = parseColor(e.target.value);
|
|
280
|
+
if (c) {
|
|
281
|
+
setDraft(null);
|
|
282
|
+
write({ ...c, a: parsed?.a ?? 1 });
|
|
283
|
+
}
|
|
284
|
+
} }), _jsx("input", { id: textId, className: "pxd-input pxd-input-mono pxd-color-text", type: "text", inputMode: "text", autoComplete: "off", spellCheck: false, placeholder: format === "hex" ? "#000000" : format === "rgb" ? "rgb(0, 0, 0)" : "hsl(0, 0%, 0%)", value: draft ?? storedText, "aria-label": `${label}: value`, "aria-describedby": describedBy(help && helpId), "aria-invalid": draft !== null && draft !== "" && !parseColor(draft) ? true : undefined, required: !hasSwatches && node.required, onChange: (e) => onText(e.target.value), onBlur: () => setDraft(null) }), alpha && (_jsxs("label", { className: "pxd-color-alpha", htmlFor: alphaId, children: [_jsx("span", { className: "pxd-color-alpha-label", children: "Opacity" }), _jsx("input", { id: alphaId, type: "range", min: 0, max: 100, step: 1, value: Math.round((parsed?.a ?? 1) * 100), disabled: !parsed, "aria-valuetext": `${Math.round((parsed?.a ?? 1) * 100)}%`, onChange: (e) => {
|
|
285
|
+
if (parsed) {
|
|
286
|
+
setDraft(null);
|
|
287
|
+
write({ ...parsed, a: Number(e.target.value) / 100 });
|
|
288
|
+
}
|
|
289
|
+
} }), _jsxs("output", { className: "pxd-color-alpha-value", htmlFor: alphaId, "aria-hidden": "true", children: [Math.round((parsed?.a ?? 1) * 100), "%"] })] }))] }));
|
|
290
|
+
if (!hasSwatches) {
|
|
291
|
+
return (_jsxs("div", { className: "pxd-field pxd-color", role: "group", "aria-labelledby": labelId, "aria-describedby": describedBy(help && helpId), ...a11y, children: [_jsxs("div", { className: "pxd-field-label", id: labelId, children: [label, node.required && _jsx(RequiredMark, {})] }), help && (_jsx("p", { className: "pxd-field-help", id: helpId, children: help })), picker] }));
|
|
292
|
+
}
|
|
293
|
+
return (_jsxs("div", { className: "pxd-field pxd-color", ...a11y, children: [_jsxs("div", { className: "pxd-field-label", id: labelId, children: [label, node.required && _jsx(RequiredMark, {})] }), help && (_jsx("p", { className: "pxd-field-help", id: helpId, children: help })), _jsxs(RadioGroup.Root, { className: "pxd-swatches", "aria-labelledby": labelId, "aria-describedby": describedBy(help && helpId), "aria-required": node.required || undefined, value: current, orientation: "horizontal", onValueChange: (k) => {
|
|
294
|
+
if (k === OTHER)
|
|
295
|
+
return setOtherChosen(true);
|
|
296
|
+
setOtherChosen(false);
|
|
297
|
+
setDraft(null);
|
|
298
|
+
const o = swatches[Number(k)];
|
|
299
|
+
const c = parseColor(o.value);
|
|
300
|
+
b.write(node.value, c ? formatColor(c, format, alpha) : o.value);
|
|
301
|
+
}, children: [swatches.map((o, i) => (_jsxs(RadioGroup.Item, { value: String(i), className: "pxd-swatch", title: o.label, children: [_jsx("span", { className: "pxd-swatch-color", style: { background: String(o.value) }, "aria-hidden": "true" }), _jsx("span", { className: "pxd-swatch-name", children: o.label })] }, String(i)))), _jsxs(RadioGroup.Item, { value: OTHER, className: "pxd-swatch pxd-swatch-other", title: "Other", children: [_jsx("span", { className: "pxd-swatch-color", style: current === OTHER && parsed ? { background: storedText } : undefined, "aria-hidden": "true" }), _jsx("span", { className: "pxd-swatch-name", children: "Other" })] })] }), showPicker && picker] }));
|
|
302
|
+
}
|
|
303
|
+
/* ------------------------------------------------------------------------------------------ */
|
|
304
|
+
/* CodeInput */
|
|
305
|
+
/* ------------------------------------------------------------------------------------------ */
|
|
306
|
+
const fromString = (text, n) => Array.from({ length: n }, (_, i) => text[i] ?? "");
|
|
307
|
+
export function CodeInput({ node }) {
|
|
308
|
+
const b = useBindings();
|
|
309
|
+
const s = useSurface();
|
|
310
|
+
const labelId = useId();
|
|
311
|
+
const helpId = useId();
|
|
312
|
+
const n = clamp(Number(node.length) || 6, 4, 12);
|
|
313
|
+
const numeric = (node.kind ?? "numeric") === "numeric";
|
|
314
|
+
const required = node.required ?? true;
|
|
315
|
+
const label = b.text(node.label);
|
|
316
|
+
const help = node.help !== undefined ? b.text(node.help) : undefined;
|
|
317
|
+
const raw = b.value(node.value);
|
|
318
|
+
const stored = raw === null || raw === undefined ? "" : String(raw);
|
|
319
|
+
const [chars, setChars] = useState(() => fromString(stored, n));
|
|
320
|
+
const [seen, setSeen] = useState(stored);
|
|
321
|
+
// The host may reset or fill the code (e.g. after a failed attempt); follow it.
|
|
322
|
+
if (stored !== seen) {
|
|
323
|
+
setSeen(stored);
|
|
324
|
+
if (stored !== chars.join(""))
|
|
325
|
+
setChars(fromString(stored, n));
|
|
326
|
+
}
|
|
327
|
+
const [fired, setFired] = useState(null);
|
|
328
|
+
const boxes = useRef([]);
|
|
329
|
+
const a11y = useA11y(node);
|
|
330
|
+
const clean = (t) => t.replace(numeric ? /[^0-9]/g : /[^0-9a-zA-Z]/g, "");
|
|
331
|
+
const focusAt = (i) => boxes.current[clamp(i, 0, n - 1)]?.focus();
|
|
332
|
+
const commit = (next) => {
|
|
333
|
+
setChars(next);
|
|
334
|
+
const code = next.join("");
|
|
335
|
+
setSeen(code);
|
|
336
|
+
b.write(node.value, code);
|
|
337
|
+
if (node.action && next.every(Boolean) && code !== fired) {
|
|
338
|
+
// Every box is in: run the action once for this code, so no button is needed.
|
|
339
|
+
setFired(code);
|
|
340
|
+
dispatchWith(s, b, node, code);
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
/** Put `text` into the boxes from `from` onwards, then move to the box after the last one filled. */
|
|
344
|
+
const fill = (from, text) => {
|
|
345
|
+
const t = clean(text);
|
|
346
|
+
if (!t)
|
|
347
|
+
return;
|
|
348
|
+
const next = [...chars];
|
|
349
|
+
let i = from;
|
|
350
|
+
for (const ch of t) {
|
|
351
|
+
if (i >= n)
|
|
352
|
+
break;
|
|
353
|
+
next[i++] = ch;
|
|
354
|
+
}
|
|
355
|
+
commit(next);
|
|
356
|
+
focusAt(i);
|
|
357
|
+
};
|
|
358
|
+
const onChange = (i, e) => {
|
|
359
|
+
const prev = chars[i];
|
|
360
|
+
let t = e.target.value;
|
|
361
|
+
// The box's own character may survive a keystroke that didn't replace it; the new text is what remains.
|
|
362
|
+
if (prev && t.length > 1)
|
|
363
|
+
t = t.startsWith(prev) ? t.slice(prev.length) : t.endsWith(prev) ? t.slice(0, -prev.length) : t;
|
|
364
|
+
if (t === "") {
|
|
365
|
+
const next = [...chars];
|
|
366
|
+
next[i] = "";
|
|
367
|
+
return commit(next);
|
|
368
|
+
}
|
|
369
|
+
fill(clean(t).length >= n ? 0 : i, t);
|
|
370
|
+
};
|
|
371
|
+
const onKeyDown = (i, e) => {
|
|
372
|
+
if (e.key === "Backspace" && !chars[i] && i > 0) {
|
|
373
|
+
e.preventDefault();
|
|
374
|
+
const next = [...chars];
|
|
375
|
+
next[i - 1] = "";
|
|
376
|
+
commit(next);
|
|
377
|
+
focusAt(i - 1);
|
|
378
|
+
}
|
|
379
|
+
else if (e.key === "ArrowLeft") {
|
|
380
|
+
e.preventDefault();
|
|
381
|
+
focusAt(i - 1);
|
|
382
|
+
}
|
|
383
|
+
else if (e.key === "ArrowRight") {
|
|
384
|
+
e.preventDefault();
|
|
385
|
+
focusAt(i + 1);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
const onPaste = (i, e) => {
|
|
389
|
+
e.preventDefault();
|
|
390
|
+
const t = e.clipboardData.getData("text");
|
|
391
|
+
fill(clean(t).length >= n ? 0 : i, t);
|
|
392
|
+
};
|
|
393
|
+
// Past six characters the boxes are grouped in threes or fours by a wider gap.
|
|
394
|
+
const groupSize = n > 6 ? (n % 4 === 0 ? 4 : 3) : n;
|
|
395
|
+
const groups = [];
|
|
396
|
+
for (let i = 0; i < n; i += groupSize)
|
|
397
|
+
groups.push(Array.from({ length: Math.min(groupSize, n - i) }, (_, j) => i + j));
|
|
398
|
+
return (_jsxs("div", { className: "pxd-field pxd-code", role: "group", "aria-labelledby": labelId, "aria-describedby": describedBy(help && helpId), ...a11y, children: [_jsxs("div", { className: "pxd-field-label", id: labelId, children: [label, required && _jsx(RequiredMark, {})] }), help && (_jsx("p", { className: "pxd-field-help", id: helpId, children: help })), _jsx("div", { className: "pxd-code-boxes", children: groups.map((group, g) => (_jsx("div", { className: "pxd-code-group", children: group.map((i) => (_jsx("input", { ref: (el) => {
|
|
399
|
+
boxes.current[i] = el;
|
|
400
|
+
}, className: "pxd-code-box", type: "text", inputMode: numeric ? "numeric" : "text", pattern: numeric ? "[0-9]*" : "[0-9A-Za-z]*", autoComplete: i === 0 ? "one-time-code" : "off", autoCapitalize: numeric ? undefined : "characters", spellCheck: false, "aria-label": `Digit ${i + 1} of ${n}`, value: chars[i], "data-filled": chars[i] ? "" : undefined, required: required, onFocus: (e) => e.target.select(), onChange: (e) => onChange(i, e), onKeyDown: (e) => onKeyDown(i, e), onPaste: (e) => onPaste(i, e) }, i))) }, g))) })] }));
|
|
401
|
+
}
|
|
402
|
+
//# sourceMappingURL=pickers.js.map
|