pivotkit-react 0.3.0 → 0.4.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +121 -1
  2. package/README.md +1 -1
  3. package/dist/chunks/{chunk-32Z33U6S.js → chunk-6MDAL3IO.js} +28 -3
  4. package/dist/chunks/{chunk-APB4NW4O.js → chunk-LEN5RPBM.js} +3 -6
  5. package/dist/chunks/{chunk-7CC4JHDY.js → chunk-WB4GKWFQ.js} +1 -4
  6. package/dist/chunks/chunk-XN55BQ4M.js +618 -0
  7. package/dist/chunks/{chunk-IOPAM4JD.js → chunk-YITKWZ4L.js} +48 -492
  8. package/dist/chunks/chunk-ZYEYZSYL.js +187 -0
  9. package/dist/import-ui.js +769 -0
  10. package/dist/import-worker.js +20 -0
  11. package/dist/index.js +599 -175
  12. package/dist/labels.js +14 -10
  13. package/dist/menu-texts-de.js +1 -1
  14. package/dist/menus.js +132 -68
  15. package/dist/styles.css +116 -8
  16. package/package.json +3 -2
  17. package/types/data-history.d.ts +85 -0
  18. package/types/data-keep.d.ts +51 -0
  19. package/types/data-menu.d.ts +11 -0
  20. package/types/dom.d.ts +40 -7
  21. package/types/field-info.d.ts +32 -0
  22. package/types/import-host.d.ts +53 -0
  23. package/types/import-labels.d.ts +360 -0
  24. package/types/import-module.d.ts +2 -0
  25. package/types/import-run.d.ts +73 -0
  26. package/types/import-source.d.ts +32 -0
  27. package/types/import-steps.d.ts +121 -0
  28. package/types/import-ui.d.ts +108 -0
  29. package/types/import-worker.d.ts +1 -0
  30. package/types/index.d.ts +56 -4
  31. package/types/labels.d.ts +26 -2
  32. package/types/lazy-import.d.ts +4 -0
  33. package/types/lazy-menus.d.ts +2 -2
  34. package/types/levels.d.ts +3 -2
  35. package/types/menu-labels.d.ts +0 -3
  36. package/types/menu-topics.d.ts +2 -4
  37. package/types/menus.d.ts +1 -0
  38. package/types/overflow.d.ts +29 -17
  39. package/types/popover.d.ts +47 -5
  40. package/types/section.d.ts +2 -2
  41. package/types/toasts.d.ts +1 -1
  42. package/types/toolbar-panels.d.ts +6 -5
  43. package/types/unused-keep.d.ts +20 -0
  44. package/types/unused.d.ts +1 -0
  45. package/types/use-view-history.d.ts +12 -4
  46. package/types/virtual.d.ts +15 -0
@@ -0,0 +1,618 @@
1
+ // src/dom.js
2
+ import { createContext, useContext, useEffect, useId, useRef } from "react";
3
+ var FormNameContext = createContext("pk");
4
+ function useFormName() {
5
+ const prefix = useContext(FormNameContext);
6
+ return `${prefix}-${useId().replace(/[^A-Za-z0-9_-]/g, "")}`;
7
+ }
8
+ var FOCUSABLE = "button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], [tabindex]:not([tabindex='-1'])";
9
+ function rootOf(node) {
10
+ const root = node && typeof node.getRootNode === "function" ? node.getRootNode() : null;
11
+ if (root && (root.nodeType === 9 || root.nodeType === 11)) {
12
+ return (
13
+ /** @type {Document | ShadowRoot} */
14
+ root
15
+ );
16
+ }
17
+ return typeof document !== "undefined" ? document : null;
18
+ }
19
+ function activeIn(node) {
20
+ return rootOf(node)?.activeElement ?? null;
21
+ }
22
+ function eventWithin(event, elements) {
23
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [];
24
+ return elements.some((el) => el && (path.includes(el) || event.target instanceof Node && el.contains(event.target)));
25
+ }
26
+ function tabStops(container) {
27
+ const all = (
28
+ /** @type {HTMLElement[]} */
29
+ [...container.querySelectorAll(FOCUSABLE)].filter(
30
+ (el) => el.tabIndex >= 0 && !el.closest("[inert]") && el.getClientRects().length > 0 && el.ownerDocument.defaultView?.getComputedStyle(el).visibility !== "hidden"
31
+ )
32
+ );
33
+ const radio = (el) => el instanceof HTMLInputElement && el.type === "radio" && el.name !== "";
34
+ return all.filter((el) => {
35
+ if (!radio(el)) {
36
+ return true;
37
+ }
38
+ const group = all.filter((o) => radio(o) && /** @type {HTMLInputElement} */
39
+ o.name === /** @type {HTMLInputElement} */
40
+ el.name);
41
+ const checked = group.find((o) => (
42
+ /** @type {HTMLInputElement} */
43
+ o.checked
44
+ ));
45
+ return el === (checked ?? group[0]);
46
+ });
47
+ }
48
+ function stopAfter(el) {
49
+ const root = rootOf(el);
50
+ const scope = root && root.nodeType === 9 ? (
51
+ /** @type {Document} */
52
+ root.body
53
+ ) : root;
54
+ if (!scope) {
55
+ return null;
56
+ }
57
+ const stops = tabStops(
58
+ /** @type {Element | ShadowRoot} */
59
+ scope
60
+ ).filter((s) => !s.closest(".pk-popover"));
61
+ const at = stops.indexOf(el);
62
+ return at === -1 ? null : stops[at + 1] ?? null;
63
+ }
64
+ function tabWithin(event, container) {
65
+ const active = activeIn(container);
66
+ if (event.key !== "Tab" || event.defaultPrevented || !container || !active || !container.contains(active)) {
67
+ return null;
68
+ }
69
+ const stops = tabStops(container);
70
+ const at = stops.indexOf(
71
+ /** @type {HTMLElement} */
72
+ active
73
+ );
74
+ const next = at === -1 ? event.shiftKey ? stops.length - 1 : 0 : at + (event.shiftKey ? -1 : 1);
75
+ if (next < 0 || next >= stops.length) {
76
+ return "out";
77
+ }
78
+ event.preventDefault();
79
+ stops[next].focus();
80
+ return "moved";
81
+ }
82
+ function trapTab(event, container) {
83
+ if (event.key !== "Tab" || event.defaultPrevented || !container) {
84
+ return;
85
+ }
86
+ event.preventDefault();
87
+ const stops = tabStops(container);
88
+ if (stops.length === 0) {
89
+ return;
90
+ }
91
+ const at = stops.indexOf(
92
+ /** @type {HTMLElement} */
93
+ activeIn(container)
94
+ );
95
+ const step = event.shiftKey ? -1 : 1;
96
+ const next = at === -1 ? event.shiftKey ? stops.length - 1 : 0 : (at + step + stops.length) % stops.length;
97
+ stops[next].focus();
98
+ }
99
+ var layers = [];
100
+ function useEscapeLayer(open, onClose) {
101
+ const close = useRef(onClose);
102
+ useEffect(() => {
103
+ close.current = onClose;
104
+ });
105
+ useEffect(() => {
106
+ if (!open || typeof document === "undefined") {
107
+ return void 0;
108
+ }
109
+ const token = {};
110
+ layers.push(token);
111
+ const onKey = (e) => {
112
+ if (e.key === "Escape" && layers[layers.length - 1] === token && !e.defaultPrevented) {
113
+ e.preventDefault();
114
+ close.current();
115
+ }
116
+ };
117
+ document.addEventListener("keydown", onKey);
118
+ return () => {
119
+ document.removeEventListener("keydown", onKey);
120
+ layers.splice(layers.indexOf(token), 1);
121
+ };
122
+ }, [open]);
123
+ }
124
+ function useModal(ref, open, onClose, opener) {
125
+ useEscapeLayer(open, onClose);
126
+ useEffect(() => {
127
+ const el = ref.current;
128
+ if (!open || !el) {
129
+ return void 0;
130
+ }
131
+ const was = activeIn(el);
132
+ const plain = !was || was === el.ownerDocument.body || was.classList.contains("pk-root");
133
+ const back = plain && opener ? el.closest(".pk-root")?.querySelector(opener) ?? was : was;
134
+ const t = requestAnimationFrame(() => {
135
+ const now = activeIn(el);
136
+ if (now && now !== el && el.contains(now)) {
137
+ return;
138
+ }
139
+ const first = (
140
+ /** @type {HTMLElement | null} */
141
+ el.querySelector("[data-autofocus]") ?? tabStops(el)[0] ?? el
142
+ );
143
+ first.focus({ preventScroll: true });
144
+ });
145
+ return () => {
146
+ cancelAnimationFrame(t);
147
+ const target = (
148
+ /** @type {HTMLElement | null} */
149
+ back
150
+ );
151
+ const now = activeIn(el);
152
+ if (target && target.isConnected && (!now || el.contains(now) || now === el.ownerDocument.body)) {
153
+ target.focus({ preventScroll: true });
154
+ }
155
+ };
156
+ }, [ref, open, opener]);
157
+ return { onKeyDown: (e) => trapTab(e, ref.current) };
158
+ }
159
+
160
+ // src/icons.jsx
161
+ import React from "react";
162
+ var PATHS = {
163
+ grip: "M9 6h.01M9 12h.01M9 18h.01M15 6h.01M15 12h.01M15 18h.01",
164
+ text: "M4 18 8.5 6h1L14 18M5.6 14h6.8M17 11.5c.6-.7 1.4-1 2.3-1 1.5 0 2.2.9 2.2 2.3V18m0-3.4c-.8-.4-1.6-.5-2.5-.5-1.4 0-2.3.7-2.3 1.9 0 1.1.8 1.8 2 1.8 1.2 0 2.1-.6 2.8-1.6",
165
+ number: "M9 4 7 20M17 4l-2 16M4 9h16M3 15h16",
166
+ date: "M7 3v3M17 3v3M4 8h16M5 5h14a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1ZM8 12h2M14 12h2M8 16h2M14 16h2",
167
+ boolean: "M8 7h8a5 5 0 0 1 0 10H8A5 5 0 0 1 8 7ZM16 14a2 2 0 1 0 0-4 2 2 0 0 0 0 4Z",
168
+ search: "M11 18a7 7 0 1 0 0-14 7 7 0 0 0 0 14ZM20 20l-4-4",
169
+ x: "M6 6l12 12M18 6 6 18",
170
+ chevronDown: "m6 9 6 6 6-6",
171
+ chevronRight: "m9 6 6 6-6 6",
172
+ arrowUp: "M12 19V5M6 11l6-6 6 6",
173
+ arrowDown: "M12 5v14M6 13l6 6 6-6",
174
+ undo: "M9 14 4 9l5-5M4 9h10.5a5.5 5.5 0 0 1 0 11H11",
175
+ redo: "m15 14 5-5-5-5M20 9H9.5a5.5 5.5 0 0 0 0 11H13",
176
+ reset: "M3 12a9 9 0 1 0 3-6.7L3 8M3 3v5h5",
177
+ table: "M4 5h16v14H4zM4 10h16M4 15h16M10 5v14",
178
+ chart: "M4 20h16M7 16v-5M12 16V6M17 16v-8",
179
+ stacked: "M4 20h16M7 16v-3M7 13v-3M12 16v-4M12 12V6M17 16v-2M17 14V9",
180
+ horizontal: "M4 4v16M8 7h7M8 12h11M8 17h5",
181
+ line: "M4 18 9 12l4 3 7-9M4 20h16",
182
+ area: "M4 18 9 11l4 3 7-8v14H4Z",
183
+ pie: "M12 3a9 9 0 1 0 9 9h-9Z M15 3.5A9 9 0 0 1 20.5 9H15Z",
184
+ donut: "M12 3a9 9 0 1 0 9 9h-4a5 5 0 1 1-5-5Z M14.5 3.4A9 9 0 0 1 20.6 9.5h-4.1a5 5 0 0 0-2-2Z",
185
+ heatmap: "M4 4h7v7H4zM13 4h7v7h-7zM4 13h7v7H4zM13 13h7v7h-7z",
186
+ download: "M12 4v11M7 10l5 5 5-5M5 20h14",
187
+ bookmark: "M7 4h10a1 1 0 0 1 1 1v15l-6-4-6 4V5a1 1 0 0 1 1-1Z",
188
+ sliders: "M4 7h10M18 7h2M4 17h4M12 17h8M16 5v4M10 15v4",
189
+ filter: "M4 5h16l-6 7.5V19l-4-2v-4.5Z",
190
+ more: "M12 6h.01M12 12h.01M12 18h.01",
191
+ plus: "M12 5v14M5 12h14",
192
+ check: "m5 12 5 5 9-10",
193
+ sortAsc: "M7 4v16M3 8l4-4 4 4M14 6h7M14 12h5M14 18h3",
194
+ sortDesc: "M7 4v16M3 16l4 4 4-4M14 6h3M14 12h5M14 18h7",
195
+ panel: "M4 5h16v14H4zM9 5v14",
196
+ layout: "M4 5h7v6H4zM13 5h7v6h-7zM4 13h7v6H4zM13 13h7v6h-7z",
197
+ trash: "M5 7h14M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3",
198
+ save: "M5 4h11l3 3v13H5zM8 4v5h7V4M8 20v-6h8v6",
199
+ sparkle: "M12 4l1.8 4.6L18 10l-4.2 1.4L12 16l-1.8-4.6L6 10l4.2-1.4Z",
200
+ rows: "M4 6h16M4 12h16M4 18h16",
201
+ cols: "M6 4v16M12 4v16M18 4v16",
202
+ sigma: "M18 5H6l6 7-6 7h12",
203
+ info: "M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18ZM12 11v5M12 8h.01",
204
+ warn: "M12 4 2.8 20h18.4ZM12 10v4.5M12 17.5h.01",
205
+ image: "M4 5h16v14H4zM4 16l5-5 4 4 3-3 4 4M15 9h.01",
206
+ file: "M6 3h8l4 4v14H6zM14 3v4h4",
207
+ newFile: "M6 3h8l4 4v14H6zM14 3v4h4M12 11v6M9 14h6",
208
+ swap: "M7 4 3 8l4 4M3 8h14M17 20l4-4-4-4M21 16H7",
209
+ top: "M4 20v-6h5v6M9 20V8h6v12M15 20v-9h5v9M3 20h18",
210
+ link: "M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1",
211
+ copy: "M8 8h11v12H8zM5 16V4h11",
212
+ upload: "M12 16V5M7 10l5-5 5 5M5 20h14",
213
+ drag: "M12 3v18M3 12h18M12 3l-3 3M12 3l3 3M12 21l-3-3M12 21l3-3M3 12l3-3M3 12l3 3M21 12l-3-3M21 12l-3 3",
214
+ enlarge: "M14 4h6v6M10 20H4v-6M20 4l-7 7M4 20l7-7",
215
+ fullScreen: "M3 8V3h5M21 8V3h-5M3 16v5h5M21 16v5h-5"
216
+ };
217
+ function Icon({ name, size = 16, className }) {
218
+ return /* @__PURE__ */ React.createElement("svg", { className: className ? `pk-icon ${className}` : "pk-icon", width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false" }, /* @__PURE__ */ React.createElement("path", { d: PATHS[name] ?? PATHS.info }));
219
+ }
220
+ var TYPE_ICON = { string: "text", number: "number", date: "date", boolean: "boolean", null: "text" };
221
+ var ZONE_ICON = { rows: "rows", cols: "cols", values: "sigma", filters: "filter" };
222
+
223
+ // src/iso.js
224
+ import { useEffect as useEffect2, useLayoutEffect } from "react";
225
+ var useIsoLayoutEffect = typeof window !== "undefined" && typeof document !== "undefined" ? useLayoutEffect : useEffect2;
226
+
227
+ // src/popover.jsx
228
+ import React2, { createContext as createContext2, useCallback, useContext as useContext2, useEffect as useEffect3, useId as useId2, useRef as useRef2, useState } from "react";
229
+ import { createPortal } from "react-dom";
230
+
231
+ // src/place.js
232
+ var MARGIN = 8;
233
+ var GAP = 6;
234
+ function viewportOf(doc) {
235
+ const root = doc.documentElement;
236
+ const win = doc.defaultView;
237
+ return { width: root?.clientWidth || win?.innerWidth || 0, height: root?.clientHeight || win?.innerHeight || 0 };
238
+ }
239
+ function placePopover(anchor, size, viewport, align = "start", { fill = false } = {}) {
240
+ const below = viewport.height - anchor.bottom - GAP - MARGIN;
241
+ const above = anchor.top - GAP - MARGIN;
242
+ const wanted = align === "end" ? anchor.right - size.width : anchor.left;
243
+ const left = Math.max(MARGIN, Math.min(wanted, viewport.width - size.width - MARGIN));
244
+ const most = Math.max(0, viewport.height - 2 * MARGIN);
245
+ if (fill && size.height > below && size.height > above) {
246
+ const height2 = Math.min(size.height, most);
247
+ const side2 = below >= above ? "below" : "above";
248
+ const near = side2 === "below" ? anchor.bottom + GAP : anchor.top - GAP - height2;
249
+ return { top: Math.max(MARGIN, Math.min(near, viewport.height - MARGIN - height2)), left, maxHeight: most, side: side2 };
250
+ }
251
+ const side = size.height <= below || below >= above ? "below" : "above";
252
+ const room = side === "below" ? below : above;
253
+ const height = Math.min(size.height, room);
254
+ const top = side === "below" ? anchor.bottom + GAP : anchor.top - GAP - height;
255
+ return { top: Math.max(MARGIN, top), left, maxHeight: Math.max(120, room), side };
256
+ }
257
+ var KEEP_ROOM = 240;
258
+ function keepPlace(last, next, anchor, size, viewport) {
259
+ if (!last || last.anchorTop !== anchor.top || last.side === next.side) {
260
+ return next;
261
+ }
262
+ const room = last.side === "below" ? viewport.height - anchor.bottom - GAP - MARGIN : anchor.top - GAP - MARGIN;
263
+ if (room < Math.min(size.height, KEEP_ROOM)) {
264
+ return next;
265
+ }
266
+ const height = Math.min(size.height, room);
267
+ const top = last.side === "below" ? anchor.bottom + GAP : anchor.top - GAP - height;
268
+ return { ...next, top: Math.max(MARGIN, top), maxHeight: room, side: last.side };
269
+ }
270
+ function fromOrigin(place, origin) {
271
+ return { ...place, top: place.top - origin.top, left: place.left - origin.left };
272
+ }
273
+
274
+ // src/popover.jsx
275
+ var LayerContext = createContext2({ layer: (
276
+ /** @type {HTMLElement | null} */
277
+ null
278
+ ), size: "wide" });
279
+ var OPTION = "[data-pk-option]:not([disabled])";
280
+ var hasTopLayer = () => typeof HTMLElement === "function" && typeof HTMLElement.prototype.showPopover === "function";
281
+ function useTopLayer(open, refs, key, layer) {
282
+ useIsoLayoutEffect(() => {
283
+ if (!open || !hasTopLayer()) {
284
+ return void 0;
285
+ }
286
+ const shown = (
287
+ /** @type {HTMLElement[]} */
288
+ refs.map((r) => r.current).filter((el) => el && el.isConnected && el.hasAttribute("popover"))
289
+ );
290
+ for (const el of shown) {
291
+ try {
292
+ el.showPopover();
293
+ } catch {
294
+ }
295
+ }
296
+ return () => {
297
+ for (const el of shown) {
298
+ try {
299
+ el.hidePopover();
300
+ } catch {
301
+ }
302
+ }
303
+ };
304
+ }, [open, key, layer]);
305
+ }
306
+ function wheelScrollsInside(path, popover, dx, dy) {
307
+ for (const node of path) {
308
+ if (!(node instanceof Element)) {
309
+ continue;
310
+ }
311
+ const style = node.ownerDocument.defaultView?.getComputedStyle(node);
312
+ const scrolls = (overflow) => overflow === "auto" || overflow === "scroll";
313
+ if (style && scrolls(style.overflowY) && (dy < 0 && node.scrollTop > 0 || dy > 0 && node.scrollTop + node.clientHeight < node.scrollHeight - 1)) {
314
+ return true;
315
+ }
316
+ if (style && scrolls(style.overflowX) && (dx < 0 && node.scrollLeft > 0 || dx > 0 && node.scrollLeft + node.clientWidth < node.scrollWidth - 1)) {
317
+ return true;
318
+ }
319
+ if (node === popover) {
320
+ return false;
321
+ }
322
+ }
323
+ return false;
324
+ }
325
+ function Popover({ open, anchor, onClose, label, role = "dialog", align = "start", className, id, passive = false, fill = false, onPointerEnter, onPointerLeave, children }) {
326
+ const { layer, size } = useContext2(LayerContext);
327
+ const ref = useRef2(
328
+ /** @type {HTMLDivElement | null} */
329
+ null
330
+ );
331
+ const ownId = useId2();
332
+ const elId = id ?? ownId;
333
+ const parentId = anchor.current?.closest?.(".pk-popover")?.id;
334
+ const within = (n) => n === ref.current || n.getAttribute("data-pk-parent") === elId;
335
+ const [pos, setPos] = useState(
336
+ /** @type {null | { top: number, left: number, maxHeight: number, side: string }} */
337
+ null
338
+ );
339
+ const sheet = size === "narrow" && !passive;
340
+ const scrim = useRef2(
341
+ /** @type {HTMLDivElement | null} */
342
+ null
343
+ );
344
+ const [top] = useState(() => !passive && hasTopLayer());
345
+ const inTopLayer = (
346
+ /** @type {any} */
347
+ top ? { popover: "manual" } : {}
348
+ );
349
+ useTopLayer(open, [scrim, ref], sheet, layer);
350
+ useIsoLayoutEffect(() => {
351
+ if (!open) {
352
+ setPos(null);
353
+ return void 0;
354
+ }
355
+ let last = null;
356
+ const place = () => {
357
+ const el2 = ref.current;
358
+ const a = anchor.current;
359
+ if (!el2 || !a || sheet) {
360
+ return;
361
+ }
362
+ const r = a.getBoundingClientRect();
363
+ const size2 = { width: el2.offsetWidth, height: el2.scrollHeight };
364
+ const viewport = viewportOf(el2.ownerDocument);
365
+ const place2 = keepPlace(last, placePopover(r, size2, viewport, align, { fill }), r, size2, viewport);
366
+ last = { top: place2.top, side: place2.side, anchorTop: r.top };
367
+ const probe = el2.hasAttribute("popover") ? null : layer?.querySelector(".pk-origin");
368
+ setPos(probe ? fromOrigin(place2, probe.getBoundingClientRect()) : place2);
369
+ };
370
+ place();
371
+ const el = ref.current;
372
+ const ro = typeof ResizeObserver === "function" && el ? new ResizeObserver(place) : null;
373
+ if (ro && el) {
374
+ ro.observe(el);
375
+ }
376
+ window.addEventListener("resize", place);
377
+ window.addEventListener("scroll", place, true);
378
+ return () => {
379
+ ro?.disconnect();
380
+ window.removeEventListener("resize", place);
381
+ window.removeEventListener("scroll", place, true);
382
+ };
383
+ }, [open, anchor, align, sheet, layer, fill]);
384
+ useEscapeLayer(open, onClose);
385
+ const closeRef = useRef2(onClose);
386
+ useEffect3(() => {
387
+ closeRef.current = onClose;
388
+ });
389
+ useEffect3(() => {
390
+ if (!open || passive) {
391
+ return void 0;
392
+ }
393
+ const el = ref.current;
394
+ const shown = (o) => o.getClientRects().length > 0;
395
+ const first = el?.querySelector("[data-autofocus]") ?? [...el?.querySelectorAll(OPTION) ?? []].find(shown) ?? [...el?.querySelectorAll(FOCUSABLE) ?? []].find((o) => shown(o) && !o.classList.contains("pk-info")) ?? (el?.querySelector("[data-pk-option]") ? el : null);
396
+ const t = requestAnimationFrame(() => (
397
+ /** @type {HTMLElement | null} */
398
+ first?.focus({ preventScroll: true })
399
+ ));
400
+ const onDown = (e) => {
401
+ if (!eventWithin(e, [el, anchor.current]) && !e.composedPath().some((n) => n instanceof Element && n !== el && n.getAttribute("data-pk-parent") === elId)) {
402
+ closeRef.current();
403
+ }
404
+ };
405
+ const doc = el?.ownerDocument ?? document;
406
+ doc.addEventListener("pointerdown", onDown, true);
407
+ const onWheel = (e) => {
408
+ if (el && !e.ctrlKey && !wheelScrollsInside(e.composedPath(), el, e.deltaX, e.deltaY)) {
409
+ e.preventDefault();
410
+ }
411
+ };
412
+ el?.addEventListener("wheel", onWheel, { passive: false });
413
+ const button = anchor.current;
414
+ return () => {
415
+ cancelAnimationFrame(t);
416
+ doc.removeEventListener("pointerdown", onDown, true);
417
+ el?.removeEventListener("wheel", onWheel);
418
+ const now = activeIn(button);
419
+ if (button && button.isConnected && (!now || now === doc.body || el?.contains(now) || !now.isConnected)) {
420
+ button.focus({ preventScroll: true });
421
+ }
422
+ };
423
+ }, [open, anchor, passive, elId]);
424
+ if (!open || !layer) {
425
+ return null;
426
+ }
427
+ const onKeyDown = (e) => {
428
+ if (role === "menu" && e.key === "Tab") {
429
+ e.preventDefault();
430
+ onClose();
431
+ return;
432
+ }
433
+ if (sheet) {
434
+ trapTab(e, ref.current);
435
+ } else if (tabWithin(e, ref.current) === "out") {
436
+ e.preventDefault();
437
+ onClose();
438
+ return;
439
+ }
440
+ if (role === "menu" && e.key.length === 1 && e.key !== " " && !e.altKey && !e.ctrlKey && !e.metaKey) {
441
+ const options = (
442
+ /** @type {HTMLElement[]} */
443
+ [...ref.current?.querySelectorAll(OPTION) ?? []].filter((o) => o.getClientRects().length > 0)
444
+ );
445
+ const at = options.indexOf(
446
+ /** @type {HTMLElement} */
447
+ activeIn(ref.current)
448
+ );
449
+ const texts = options.map((o) => (o.querySelector(".pk-option-text")?.firstChild?.textContent ?? "").trim().toLowerCase());
450
+ const want = e.key.toLowerCase();
451
+ for (let i = 1; i <= options.length; i++) {
452
+ const k = (Math.max(0, at) + i) % options.length;
453
+ if (texts[k].startsWith(want)) {
454
+ e.preventDefault();
455
+ options[k].focus();
456
+ break;
457
+ }
458
+ }
459
+ return;
460
+ }
461
+ if (e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === "Home" || e.key === "End") {
462
+ const options = (
463
+ /** @type {HTMLElement[]} */
464
+ [...ref.current?.querySelectorAll(OPTION) ?? []].filter((o) => o.getClientRects().length > 0)
465
+ );
466
+ if (options.length === 0 || e.target instanceof HTMLInputElement && e.target.type !== "checkbox") {
467
+ return;
468
+ }
469
+ e.preventDefault();
470
+ const at = options.indexOf(
471
+ /** @type {HTMLElement} */
472
+ activeIn(ref.current)
473
+ );
474
+ const next = e.key === "Home" ? 0 : e.key === "End" ? options.length - 1 : (at + (e.key === "ArrowDown" ? 1 : -1) + options.length) % options.length;
475
+ options[next].focus();
476
+ }
477
+ };
478
+ const onBlur = (e) => {
479
+ const to = (
480
+ /** @type {Node | null} */
481
+ e.relatedTarget
482
+ );
483
+ if (to && !ref.current?.contains(to) && !anchor.current?.contains(to) && !(to instanceof Element && [...to.ownerDocument.querySelectorAll(".pk-popover")].some((p) => p.contains(to) && within(p)))) {
484
+ onClose();
485
+ }
486
+ };
487
+ const style = sheet ? void 0 : pos ? { top: pos.top, left: pos.left, maxHeight: pos.maxHeight } : { top: 0, left: 0, visibility: (
488
+ /** @type {const} */
489
+ "hidden"
490
+ ) };
491
+ return createPortal(
492
+ /* @__PURE__ */ React2.createElement(React2.Fragment, null, sheet ? /* @__PURE__ */ React2.createElement("div", { ref: scrim, className: "pk-scrim", ...inTopLayer, onClick: onClose, "aria-hidden": "true" }) : null, /* @__PURE__ */ React2.createElement(
493
+ "div",
494
+ {
495
+ ref,
496
+ ...inTopLayer,
497
+ id: elId,
498
+ "data-pk-parent": parentId,
499
+ role,
500
+ "aria-label": passive ? void 0 : label,
501
+ "aria-modal": sheet && role === "dialog" ? true : void 0,
502
+ className: `pk-popover${sheet ? " pk-sheet" : ""}${pos?.side === "above" ? " pk-above" : ""}${className ? ` ${className}` : ""}`,
503
+ style,
504
+ onKeyDown,
505
+ onBlur: sheet || passive ? void 0 : onBlur,
506
+ onPointerEnter,
507
+ onPointerLeave,
508
+ tabIndex: passive ? void 0 : -1
509
+ },
510
+ children
511
+ )),
512
+ layer
513
+ );
514
+ }
515
+ function MenuButton({ label, icon, text, showText = true, className, role = "menu", align, popoverClass, disabled, title, children, testId, buttonRef, name, tabIndex, slot, fill, mark, arrowOpens = false, off }) {
516
+ const [open, setOpen] = useState(false);
517
+ const offId = useId2();
518
+ if (off && open) {
519
+ setOpen(false);
520
+ }
521
+ const own = useRef2(
522
+ /** @type {HTMLButtonElement | null} */
523
+ null
524
+ );
525
+ const ref = buttonRef ?? own;
526
+ const id = useId2();
527
+ const close = useCallback(() => setOpen(false), []);
528
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
529
+ "button",
530
+ {
531
+ ref,
532
+ type: "button",
533
+ "aria-haspopup": role === "menu" ? "menu" : "dialog",
534
+ "aria-expanded": open,
535
+ "aria-controls": open ? id : void 0,
536
+ "aria-label": name ?? (showText && text ? void 0 : label),
537
+ "aria-disabled": off ? true : void 0,
538
+ "aria-describedby": off ? offId : void 0,
539
+ title: off ?? title ?? (showText && text ? void 0 : label),
540
+ className: `${className ?? "pk-btn"}${off ? " pk-off" : ""}`,
541
+ disabled,
542
+ tabIndex,
543
+ "data-pk-slot": slot,
544
+ "data-testid": testId,
545
+ onClick: () => off ? void 0 : setOpen((o) => !o),
546
+ onKeyDown: arrowOpens ? (e) => {
547
+ if (e.key === "ArrowDown" && !open && !off) {
548
+ e.preventDefault();
549
+ setOpen(true);
550
+ }
551
+ } : void 0
552
+ },
553
+ icon ? /* @__PURE__ */ React2.createElement(Icon, { name: (
554
+ /** @type {any} */
555
+ icon
556
+ ) }) : null,
557
+ showText && text ? /* @__PURE__ */ React2.createElement("span", { className: "pk-btn-text" }, text) : null,
558
+ mark,
559
+ showText && text ? /* @__PURE__ */ React2.createElement(Icon, { name: "chevronDown", size: 14, className: "pk-caret" }) : null,
560
+ off ? /* @__PURE__ */ React2.createElement("span", { id: offId, hidden: true }, off) : null
561
+ ), /* @__PURE__ */ React2.createElement(Popover, { open, anchor: ref, onClose: close, label, role, align, className: popoverClass, id, fill }, children(close)));
562
+ }
563
+ function Group({ title, label, menu = false, head, after, children, testId, titleTestId }) {
564
+ const titleId = useId2();
565
+ const top = title ? /* @__PURE__ */ React2.createElement("div", { className: "pk-section-head" }, /* @__PURE__ */ React2.createElement("div", { className: "pk-section-title", id: titleId, role: menu ? "presentation" : void 0, "data-testid": titleTestId }, title), head) : null;
566
+ const name = title ? { "aria-labelledby": titleId } : { "aria-label": label };
567
+ if (menu) {
568
+ return /* @__PURE__ */ React2.createElement("div", { className: "pk-section", role: "none" }, top, /* @__PURE__ */ React2.createElement("div", { role: title || label ? "group" : "none", ...title || label ? name : {}, "data-testid": testId }, children), after);
569
+ }
570
+ return /* @__PURE__ */ React2.createElement("div", { className: "pk-section", role: "group", ...name, "data-testid": testId }, top, children, after);
571
+ }
572
+ function Option({ onSelect, icon, checked, checkbox = false, children, hint, reason, inMenu = false, disabled, danger, tone, testId, current }) {
573
+ const second = disabled && reason ? reason : hint;
574
+ const role = inMenu ? checked === void 0 ? "menuitem" : checkbox ? "menuitemcheckbox" : "menuitemradio" : void 0;
575
+ const off = inMenu && disabled;
576
+ return /* @__PURE__ */ React2.createElement(
577
+ "button",
578
+ {
579
+ type: "button",
580
+ role,
581
+ "aria-checked": inMenu && checked !== void 0 ? checked : void 0,
582
+ "aria-pressed": !inMenu && checked !== void 0 ? checked : void 0,
583
+ "aria-current": current ? "true" : void 0,
584
+ "aria-disabled": off || void 0,
585
+ className: `pk-option${checked ? " pk-checked" : ""}${danger ? " pk-danger" : ""}${tone === "accent" ? " pk-accent" : ""}${off ? " pk-disabled" : ""}`,
586
+ "data-pk-option": "",
587
+ "data-testid": testId,
588
+ disabled: off ? void 0 : disabled,
589
+ onClick: off ? void 0 : onSelect
590
+ },
591
+ /* @__PURE__ */ React2.createElement("span", { className: "pk-option-icon" }, checked || current ? /* @__PURE__ */ React2.createElement(Icon, { name: "check" }) : icon ? /* @__PURE__ */ React2.createElement(Icon, { name: (
592
+ /** @type {any} */
593
+ icon
594
+ ) }) : null),
595
+ /* @__PURE__ */ React2.createElement("span", { className: "pk-option-text" }, children, second ? /* @__PURE__ */ React2.createElement("span", { className: "pk-option-hint" }, second) : null)
596
+ );
597
+ }
598
+
599
+ export {
600
+ FormNameContext,
601
+ useFormName,
602
+ rootOf,
603
+ activeIn,
604
+ tabStops,
605
+ stopAfter,
606
+ useModal,
607
+ Icon,
608
+ TYPE_ICON,
609
+ ZONE_ICON,
610
+ useIsoLayoutEffect,
611
+ LayerContext,
612
+ hasTopLayer,
613
+ useTopLayer,
614
+ Popover,
615
+ MenuButton,
616
+ Group,
617
+ Option
618
+ };