PluginProbe
Gutenberg / 23.1.0
Gutenberg v23.1.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / scripts / media-utils / index.js

index.js in Gutenberg 23.1.0, at build/scripts/media-utils/index.js

19,651 lines 694.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2 var wp;
3 (wp ||= {}).mediaUtils = (() => {
4 var __create = Object.create;
5 var __defProp = Object.defineProperty;
6 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7 var __getOwnPropNames = Object.getOwnPropertyNames;
8 var __getProtoOf = Object.getPrototypeOf;
9 var __hasOwnProp = Object.prototype.hasOwnProperty;
10 var __commonJS = (cb, mod) => function __require() {
11 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12 };
13 var __export = (target, all) => {
14 for (var name in all)
15 __defProp(target, name, { get: all[name], enumerable: true });
16 };
17 var __copyProps = (to, from, except, desc) => {
18 if (from && typeof from === "object" || typeof from === "function") {
19 for (let key of __getOwnPropNames(from))
20 if (!__hasOwnProp.call(to, key) && key !== except)
21 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22 }
23 return to;
24 };
25 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26 // If the importer is in node compatibility mode or this is not an ESM
27 // file that has been converted to a CommonJS file using a Babel-
28 // compatible transform (i.e. "__esModule" has not been set), then set
29 // "default" to the CommonJS "module.exports" for node compatibility.
30 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31 mod
32 ));
33 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
35 // package-external:@wordpress/element
36 var require_element = __commonJS({
37 "package-external:@wordpress/element"(exports, module) {
38 module.exports = window.wp.element;
39 }
40 });
41
42 // package-external:@wordpress/i18n
43 var require_i18n = __commonJS({
44 "package-external:@wordpress/i18n"(exports, module) {
45 module.exports = window.wp.i18n;
46 }
47 });
48
49 // package-external:@wordpress/blob
50 var require_blob = __commonJS({
51 "package-external:@wordpress/blob"(exports, module) {
52 module.exports = window.wp.blob;
53 }
54 });
55
56 // package-external:@wordpress/api-fetch
57 var require_api_fetch = __commonJS({
58 "package-external:@wordpress/api-fetch"(exports, module) {
59 module.exports = window.wp.apiFetch;
60 }
61 });
62
63 // package-external:@wordpress/core-data
64 var require_core_data = __commonJS({
65 "package-external:@wordpress/core-data"(exports, module) {
66 module.exports = window.wp.coreData;
67 }
68 });
69
70 // package-external:@wordpress/data
71 var require_data = __commonJS({
72 "package-external:@wordpress/data"(exports, module) {
73 module.exports = window.wp.data;
74 }
75 });
76
77 // package-external:@wordpress/components
78 var require_components = __commonJS({
79 "package-external:@wordpress/components"(exports, module) {
80 module.exports = window.wp.components;
81 }
82 });
83
84 // package-external:@wordpress/primitives
85 var require_primitives = __commonJS({
86 "package-external:@wordpress/primitives"(exports, module) {
87 module.exports = window.wp.primitives;
88 }
89 });
90
91 // vendor-external:react/jsx-runtime
92 var require_jsx_runtime = __commonJS({
93 "vendor-external:react/jsx-runtime"(exports, module) {
94 module.exports = window.ReactJSXRuntime;
95 }
96 });
97
98 // package-external:@wordpress/compose
99 var require_compose = __commonJS({
100 "package-external:@wordpress/compose"(exports, module) {
101 module.exports = window.wp.compose;
102 }
103 });
104
105 // vendor-external:react
106 var require_react = __commonJS({
107 "vendor-external:react"(exports, module) {
108 module.exports = window.React;
109 }
110 });
111
112 // vendor-external:react-dom
113 var require_react_dom = __commonJS({
114 "vendor-external:react-dom"(exports, module) {
115 module.exports = window.ReactDOM;
116 }
117 });
118
119 // node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js
120 var require_use_sync_external_store_shim_development = __commonJS({
121 "node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js"(exports) {
122 "use strict";
123 (function() {
124 function is(x2, y2) {
125 return x2 === y2 && (0 !== x2 || 1 / x2 === 1 / y2) || x2 !== x2 && y2 !== y2;
126 }
127 function useSyncExternalStore$2(subscribe2, getSnapshot) {
128 didWarnOld18Alpha || void 0 === React8.startTransition || (didWarnOld18Alpha = true, console.error(
129 "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
130 ));
131 var value = getSnapshot();
132 if (!didWarnUncachedGetSnapshot) {
133 var cachedValue = getSnapshot();
134 objectIs(value, cachedValue) || (console.error(
135 "The result of getSnapshot should be cached to avoid an infinite loop"
136 ), didWarnUncachedGetSnapshot = true);
137 }
138 cachedValue = useState31({
139 inst: { value, getSnapshot }
140 });
141 var inst = cachedValue[0].inst, forceUpdate = cachedValue[1];
142 useLayoutEffect4(
143 function() {
144 inst.value = value;
145 inst.getSnapshot = getSnapshot;
146 checkIfSnapshotChanged(inst) && forceUpdate({ inst });
147 },
148 [subscribe2, value, getSnapshot]
149 );
150 useEffect25(
151 function() {
152 checkIfSnapshotChanged(inst) && forceUpdate({ inst });
153 return subscribe2(function() {
154 checkIfSnapshotChanged(inst) && forceUpdate({ inst });
155 });
156 },
157 [subscribe2]
158 );
159 useDebugValue(value);
160 return value;
161 }
162 function checkIfSnapshotChanged(inst) {
163 var latestGetSnapshot = inst.getSnapshot;
164 inst = inst.value;
165 try {
166 var nextValue = latestGetSnapshot();
167 return !objectIs(inst, nextValue);
168 } catch (error) {
169 return true;
170 }
171 }
172 function useSyncExternalStore$1(subscribe2, getSnapshot) {
173 return getSnapshot();
174 }
175 "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
176 var React8 = require_react(), objectIs = "function" === typeof Object.is ? Object.is : is, useState31 = React8.useState, useEffect25 = React8.useEffect, useLayoutEffect4 = React8.useLayoutEffect, useDebugValue = React8.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
177 exports.useSyncExternalStore = void 0 !== React8.useSyncExternalStore ? React8.useSyncExternalStore : shim;
178 "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
179 })();
180 }
181 });
182
183 // node_modules/use-sync-external-store/shim/index.js
184 var require_shim = __commonJS({
185 "node_modules/use-sync-external-store/shim/index.js"(exports, module) {
186 "use strict";
187 if (false) {
188 module.exports = null;
189 } else {
190 module.exports = require_use_sync_external_store_shim_development();
191 }
192 }
193 });
194
195 // package-external:@wordpress/private-apis
196 var require_private_apis = __commonJS({
197 "package-external:@wordpress/private-apis"(exports, module) {
198 module.exports = window.wp.privateApis;
199 }
200 });
201
202 // package-external:@wordpress/keycodes
203 var require_keycodes = __commonJS({
204 "package-external:@wordpress/keycodes"(exports, module) {
205 module.exports = window.wp.keycodes;
206 }
207 });
208
209 // node_modules/remove-accents/index.js
210 var require_remove_accents = __commonJS({
211 "node_modules/remove-accents/index.js"(exports, module) {
212 var characterMap = {
213 "\xC0": "A",
214 "\xC1": "A",
215 "\xC2": "A",
216 "\xC3": "A",
217 "\xC4": "A",
218 "\xC5": "A",
219 "\u1EA4": "A",
220 "\u1EAE": "A",
221 "\u1EB2": "A",
222 "\u1EB4": "A",
223 "\u1EB6": "A",
224 "\xC6": "AE",
225 "\u1EA6": "A",
226 "\u1EB0": "A",
227 "\u0202": "A",
228 "\u1EA2": "A",
229 "\u1EA0": "A",
230 "\u1EA8": "A",
231 "\u1EAA": "A",
232 "\u1EAC": "A",
233 "\xC7": "C",
234 "\u1E08": "C",
235 "\xC8": "E",
236 "\xC9": "E",
237 "\xCA": "E",
238 "\xCB": "E",
239 "\u1EBE": "E",
240 "\u1E16": "E",
241 "\u1EC0": "E",
242 "\u1E14": "E",
243 "\u1E1C": "E",
244 "\u0206": "E",
245 "\u1EBA": "E",
246 "\u1EBC": "E",
247 "\u1EB8": "E",
248 "\u1EC2": "E",
249 "\u1EC4": "E",
250 "\u1EC6": "E",
251 "\xCC": "I",
252 "\xCD": "I",
253 "\xCE": "I",
254 "\xCF": "I",
255 "\u1E2E": "I",
256 "\u020A": "I",
257 "\u1EC8": "I",
258 "\u1ECA": "I",
259 "\xD0": "D",
260 "\xD1": "N",
261 "\xD2": "O",
262 "\xD3": "O",
263 "\xD4": "O",
264 "\xD5": "O",
265 "\xD6": "O",
266 "\xD8": "O",
267 "\u1ED0": "O",
268 "\u1E4C": "O",
269 "\u1E52": "O",
270 "\u020E": "O",
271 "\u1ECE": "O",
272 "\u1ECC": "O",
273 "\u1ED4": "O",
274 "\u1ED6": "O",
275 "\u1ED8": "O",
276 "\u1EDC": "O",
277 "\u1EDE": "O",
278 "\u1EE0": "O",
279 "\u1EDA": "O",
280 "\u1EE2": "O",
281 "\xD9": "U",
282 "\xDA": "U",
283 "\xDB": "U",
284 "\xDC": "U",
285 "\u1EE6": "U",
286 "\u1EE4": "U",
287 "\u1EEC": "U",
288 "\u1EEE": "U",
289 "\u1EF0": "U",
290 "\xDD": "Y",
291 "\xE0": "a",
292 "\xE1": "a",
293 "\xE2": "a",
294 "\xE3": "a",
295 "\xE4": "a",
296 "\xE5": "a",
297 "\u1EA5": "a",
298 "\u1EAF": "a",
299 "\u1EB3": "a",
300 "\u1EB5": "a",
301 "\u1EB7": "a",
302 "\xE6": "ae",
303 "\u1EA7": "a",
304 "\u1EB1": "a",
305 "\u0203": "a",
306 "\u1EA3": "a",
307 "\u1EA1": "a",
308 "\u1EA9": "a",
309 "\u1EAB": "a",
310 "\u1EAD": "a",
311 "\xE7": "c",
312 "\u1E09": "c",
313 "\xE8": "e",
314 "\xE9": "e",
315 "\xEA": "e",
316 "\xEB": "e",
317 "\u1EBF": "e",
318 "\u1E17": "e",
319 "\u1EC1": "e",
320 "\u1E15": "e",
321 "\u1E1D": "e",
322 "\u0207": "e",
323 "\u1EBB": "e",
324 "\u1EBD": "e",
325 "\u1EB9": "e",
326 "\u1EC3": "e",
327 "\u1EC5": "e",
328 "\u1EC7": "e",
329 "\xEC": "i",
330 "\xED": "i",
331 "\xEE": "i",
332 "\xEF": "i",
333 "\u1E2F": "i",
334 "\u020B": "i",
335 "\u1EC9": "i",
336 "\u1ECB": "i",
337 "\xF0": "d",
338 "\xF1": "n",
339 "\xF2": "o",
340 "\xF3": "o",
341 "\xF4": "o",
342 "\xF5": "o",
343 "\xF6": "o",
344 "\xF8": "o",
345 "\u1ED1": "o",
346 "\u1E4D": "o",
347 "\u1E53": "o",
348 "\u020F": "o",
349 "\u1ECF": "o",
350 "\u1ECD": "o",
351 "\u1ED5": "o",
352 "\u1ED7": "o",
353 "\u1ED9": "o",
354 "\u1EDD": "o",
355 "\u1EDF": "o",
356 "\u1EE1": "o",
357 "\u1EDB": "o",
358 "\u1EE3": "o",
359 "\xF9": "u",
360 "\xFA": "u",
361 "\xFB": "u",
362 "\xFC": "u",
363 "\u1EE7": "u",
364 "\u1EE5": "u",
365 "\u1EED": "u",
366 "\u1EEF": "u",
367 "\u1EF1": "u",
368 "\xFD": "y",
369 "\xFF": "y",
370 "\u0100": "A",
371 "\u0101": "a",
372 "\u0102": "A",
373 "\u0103": "a",
374 "\u0104": "A",
375 "\u0105": "a",
376 "\u0106": "C",
377 "\u0107": "c",
378 "\u0108": "C",
379 "\u0109": "c",
380 "\u010A": "C",
381 "\u010B": "c",
382 "\u010C": "C",
383 "\u010D": "c",
384 "C\u0306": "C",
385 "c\u0306": "c",
386 "\u010E": "D",
387 "\u010F": "d",
388 "\u0110": "D",
389 "\u0111": "d",
390 "\u0112": "E",
391 "\u0113": "e",
392 "\u0114": "E",
393 "\u0115": "e",
394 "\u0116": "E",
395 "\u0117": "e",
396 "\u0118": "E",
397 "\u0119": "e",
398 "\u011A": "E",
399 "\u011B": "e",
400 "\u011C": "G",
401 "\u01F4": "G",
402 "\u011D": "g",
403 "\u01F5": "g",
404 "\u011E": "G",
405 "\u011F": "g",
406 "\u0120": "G",
407 "\u0121": "g",
408 "\u0122": "G",
409 "\u0123": "g",
410 "\u0124": "H",
411 "\u0125": "h",
412 "\u0126": "H",
413 "\u0127": "h",
414 "\u1E2A": "H",
415 "\u1E2B": "h",
416 "\u0128": "I",
417 "\u0129": "i",
418 "\u012A": "I",
419 "\u012B": "i",
420 "\u012C": "I",
421 "\u012D": "i",
422 "\u012E": "I",
423 "\u012F": "i",
424 "\u0130": "I",
425 "\u0131": "i",
426 "\u0132": "IJ",
427 "\u0133": "ij",
428 "\u0134": "J",
429 "\u0135": "j",
430 "\u0136": "K",
431 "\u0137": "k",
432 "\u1E30": "K",
433 "\u1E31": "k",
434 "K\u0306": "K",
435 "k\u0306": "k",
436 "\u0139": "L",
437 "\u013A": "l",
438 "\u013B": "L",
439 "\u013C": "l",
440 "\u013D": "L",
441 "\u013E": "l",
442 "\u013F": "L",
443 "\u0140": "l",
444 "\u0141": "l",
445 "\u0142": "l",
446 "\u1E3E": "M",
447 "\u1E3F": "m",
448 "M\u0306": "M",
449 "m\u0306": "m",
450 "\u0143": "N",
451 "\u0144": "n",
452 "\u0145": "N",
453 "\u0146": "n",
454 "\u0147": "N",
455 "\u0148": "n",
456 "\u0149": "n",
457 "N\u0306": "N",
458 "n\u0306": "n",
459 "\u014C": "O",
460 "\u014D": "o",
461 "\u014E": "O",
462 "\u014F": "o",
463 "\u0150": "O",
464 "\u0151": "o",
465 "\u0152": "OE",
466 "\u0153": "oe",
467 "P\u0306": "P",
468 "p\u0306": "p",
469 "\u0154": "R",
470 "\u0155": "r",
471 "\u0156": "R",
472 "\u0157": "r",
473 "\u0158": "R",
474 "\u0159": "r",
475 "R\u0306": "R",
476 "r\u0306": "r",
477 "\u0212": "R",
478 "\u0213": "r",
479 "\u015A": "S",
480 "\u015B": "s",
481 "\u015C": "S",
482 "\u015D": "s",
483 "\u015E": "S",
484 "\u0218": "S",
485 "\u0219": "s",
486 "\u015F": "s",
487 "\u0160": "S",
488 "\u0161": "s",
489 "\u0162": "T",
490 "\u0163": "t",
491 "\u021B": "t",
492 "\u021A": "T",
493 "\u0164": "T",
494 "\u0165": "t",
495 "\u0166": "T",
496 "\u0167": "t",
497 "T\u0306": "T",
498 "t\u0306": "t",
499 "\u0168": "U",
500 "\u0169": "u",
501 "\u016A": "U",
502 "\u016B": "u",
503 "\u016C": "U",
504 "\u016D": "u",
505 "\u016E": "U",
506 "\u016F": "u",
507 "\u0170": "U",
508 "\u0171": "u",
509 "\u0172": "U",
510 "\u0173": "u",
511 "\u0216": "U",
512 "\u0217": "u",
513 "V\u0306": "V",
514 "v\u0306": "v",
515 "\u0174": "W",
516 "\u0175": "w",
517 "\u1E82": "W",
518 "\u1E83": "w",
519 "X\u0306": "X",
520 "x\u0306": "x",
521 "\u0176": "Y",
522 "\u0177": "y",
523 "\u0178": "Y",
524 "Y\u0306": "Y",
525 "y\u0306": "y",
526 "\u0179": "Z",
527 "\u017A": "z",
528 "\u017B": "Z",
529 "\u017C": "z",
530 "\u017D": "Z",
531 "\u017E": "z",
532 "\u017F": "s",
533 "\u0192": "f",
534 "\u01A0": "O",
535 "\u01A1": "o",
536 "\u01AF": "U",
537 "\u01B0": "u",
538 "\u01CD": "A",
539 "\u01CE": "a",
540 "\u01CF": "I",
541 "\u01D0": "i",
542 "\u01D1": "O",
543 "\u01D2": "o",
544 "\u01D3": "U",
545 "\u01D4": "u",
546 "\u01D5": "U",
547 "\u01D6": "u",
548 "\u01D7": "U",
549 "\u01D8": "u",
550 "\u01D9": "U",
551 "\u01DA": "u",
552 "\u01DB": "U",
553 "\u01DC": "u",
554 "\u1EE8": "U",
555 "\u1EE9": "u",
556 "\u1E78": "U",
557 "\u1E79": "u",
558 "\u01FA": "A",
559 "\u01FB": "a",
560 "\u01FC": "AE",
561 "\u01FD": "ae",
562 "\u01FE": "O",
563 "\u01FF": "o",
564 "\xDE": "TH",
565 "\xFE": "th",
566 "\u1E54": "P",
567 "\u1E55": "p",
568 "\u1E64": "S",
569 "\u1E65": "s",
570 "X\u0301": "X",
571 "x\u0301": "x",
572 "\u0403": "\u0413",
573 "\u0453": "\u0433",
574 "\u040C": "\u041A",
575 "\u045C": "\u043A",
576 "A\u030B": "A",
577 "a\u030B": "a",
578 "E\u030B": "E",
579 "e\u030B": "e",
580 "I\u030B": "I",
581 "i\u030B": "i",
582 "\u01F8": "N",
583 "\u01F9": "n",
584 "\u1ED2": "O",
585 "\u1ED3": "o",
586 "\u1E50": "O",
587 "\u1E51": "o",
588 "\u1EEA": "U",
589 "\u1EEB": "u",
590 "\u1E80": "W",
591 "\u1E81": "w",
592 "\u1EF2": "Y",
593 "\u1EF3": "y",
594 "\u0200": "A",
595 "\u0201": "a",
596 "\u0204": "E",
597 "\u0205": "e",
598 "\u0208": "I",
599 "\u0209": "i",
600 "\u020C": "O",
601 "\u020D": "o",
602 "\u0210": "R",
603 "\u0211": "r",
604 "\u0214": "U",
605 "\u0215": "u",
606 "B\u030C": "B",
607 "b\u030C": "b",
608 "\u010C\u0323": "C",
609 "\u010D\u0323": "c",
610 "\xCA\u030C": "E",
611 "\xEA\u030C": "e",
612 "F\u030C": "F",
613 "f\u030C": "f",
614 "\u01E6": "G",
615 "\u01E7": "g",
616 "\u021E": "H",
617 "\u021F": "h",
618 "J\u030C": "J",
619 "\u01F0": "j",
620 "\u01E8": "K",
621 "\u01E9": "k",
622 "M\u030C": "M",
623 "m\u030C": "m",
624 "P\u030C": "P",
625 "p\u030C": "p",
626 "Q\u030C": "Q",
627 "q\u030C": "q",
628 "\u0158\u0329": "R",
629 "\u0159\u0329": "r",
630 "\u1E66": "S",
631 "\u1E67": "s",
632 "V\u030C": "V",
633 "v\u030C": "v",
634 "W\u030C": "W",
635 "w\u030C": "w",
636 "X\u030C": "X",
637 "x\u030C": "x",
638 "Y\u030C": "Y",
639 "y\u030C": "y",
640 "A\u0327": "A",
641 "a\u0327": "a",
642 "B\u0327": "B",
643 "b\u0327": "b",
644 "\u1E10": "D",
645 "\u1E11": "d",
646 "\u0228": "E",
647 "\u0229": "e",
648 "\u0190\u0327": "E",
649 "\u025B\u0327": "e",
650 "\u1E28": "H",
651 "\u1E29": "h",
652 "I\u0327": "I",
653 "i\u0327": "i",
654 "\u0197\u0327": "I",
655 "\u0268\u0327": "i",
656 "M\u0327": "M",
657 "m\u0327": "m",
658 "O\u0327": "O",
659 "o\u0327": "o",
660 "Q\u0327": "Q",
661 "q\u0327": "q",
662 "U\u0327": "U",
663 "u\u0327": "u",
664 "X\u0327": "X",
665 "x\u0327": "x",
666 "Z\u0327": "Z",
667 "z\u0327": "z",
668 "\u0439": "\u0438",
669 "\u0419": "\u0418",
670 "\u0451": "\u0435",
671 "\u0401": "\u0415"
672 };
673 var chars = Object.keys(characterMap).join("|");
674 var allAccents = new RegExp(chars, "g");
675 var firstAccent = new RegExp(chars, "");
676 function matcher(match2) {
677 return characterMap[match2];
678 }
679 var removeAccents2 = function(string) {
680 return string.replace(allAccents, matcher);
681 };
682 var hasAccents = function(string) {
683 return !!string.match(firstAccent);
684 };
685 module.exports = removeAccents2;
686 module.exports.has = hasAccents;
687 module.exports.remove = removeAccents2;
688 }
689 });
690
691 // node_modules/fast-deep-equal/es6/index.js
692 var require_es6 = __commonJS({
693 "node_modules/fast-deep-equal/es6/index.js"(exports, module) {
694 "use strict";
695 module.exports = function equal(a2, b2) {
696 if (a2 === b2) return true;
697 if (a2 && b2 && typeof a2 == "object" && typeof b2 == "object") {
698 if (a2.constructor !== b2.constructor) return false;
699 var length, i2, keys;
700 if (Array.isArray(a2)) {
701 length = a2.length;
702 if (length != b2.length) return false;
703 for (i2 = length; i2-- !== 0; )
704 if (!equal(a2[i2], b2[i2])) return false;
705 return true;
706 }
707 if (a2 instanceof Map && b2 instanceof Map) {
708 if (a2.size !== b2.size) return false;
709 for (i2 of a2.entries())
710 if (!b2.has(i2[0])) return false;
711 for (i2 of a2.entries())
712 if (!equal(i2[1], b2.get(i2[0]))) return false;
713 return true;
714 }
715 if (a2 instanceof Set && b2 instanceof Set) {
716 if (a2.size !== b2.size) return false;
717 for (i2 of a2.entries())
718 if (!b2.has(i2[0])) return false;
719 return true;
720 }
721 if (ArrayBuffer.isView(a2) && ArrayBuffer.isView(b2)) {
722 length = a2.length;
723 if (length != b2.length) return false;
724 for (i2 = length; i2-- !== 0; )
725 if (a2[i2] !== b2[i2]) return false;
726 return true;
727 }
728 if (a2.constructor === RegExp) return a2.source === b2.source && a2.flags === b2.flags;
729 if (a2.valueOf !== Object.prototype.valueOf) return a2.valueOf() === b2.valueOf();
730 if (a2.toString !== Object.prototype.toString) return a2.toString() === b2.toString();
731 keys = Object.keys(a2);
732 length = keys.length;
733 if (length !== Object.keys(b2).length) return false;
734 for (i2 = length; i2-- !== 0; )
735 if (!Object.prototype.hasOwnProperty.call(b2, keys[i2])) return false;
736 for (i2 = length; i2-- !== 0; ) {
737 var key = keys[i2];
738 if (!equal(a2[key], b2[key])) return false;
739 }
740 return true;
741 }
742 return a2 !== a2 && b2 !== b2;
743 };
744 }
745 });
746
747 // package-external:@wordpress/date
748 var require_date = __commonJS({
749 "package-external:@wordpress/date"(exports, module) {
750 module.exports = window.wp.date;
751 }
752 });
753
754 // package-external:@wordpress/warning
755 var require_warning = __commonJS({
756 "package-external:@wordpress/warning"(exports, module) {
757 module.exports = window.wp.warning;
758 }
759 });
760
761 // package-external:@wordpress/preferences
762 var require_preferences = __commonJS({
763 "package-external:@wordpress/preferences"(exports, module) {
764 module.exports = window.wp.preferences;
765 }
766 });
767
768 // package-external:@wordpress/url
769 var require_url = __commonJS({
770 "package-external:@wordpress/url"(exports, module) {
771 module.exports = window.wp.url;
772 }
773 });
774
775 // package-external:@wordpress/notices
776 var require_notices = __commonJS({
777 "package-external:@wordpress/notices"(exports, module) {
778 module.exports = window.wp.notices;
779 }
780 });
781
782 // packages/media-utils/build-module/index.mjs
783 var index_exports = {};
784 __export(index_exports, {
785 MediaUpload: () => media_upload_default,
786 privateApis: () => privateApis12,
787 transformAttachment: () => transformAttachment,
788 uploadMedia: () => uploadMedia,
789 validateFileSize: () => validateFileSize,
790 validateMimeType: () => validateMimeType,
791 validateMimeTypeForUser: () => validateMimeTypeForUser
792 });
793
794 // packages/media-utils/build-module/components/media-upload/index.mjs
795 var import_element = __toESM(require_element(), 1);
796 var import_i18n = __toESM(require_i18n(), 1);
797 var DEFAULT_EMPTY_GALLERY = [];
798 var getFeaturedImageMediaFrame = () => {
799 const { wp } = window;
800 return wp.media.view.MediaFrame.Select.extend({
801 /**
802 * Enables the Set Featured Image Button.
803 *
804 * @param {Object} toolbar toolbar for featured image state
805 * @return {void}
806 */
807 featuredImageToolbar(toolbar) {
808 this.createSelectToolbar(toolbar, {
809 text: wp.media.view.l10n.setFeaturedImage,
810 state: this.options.state
811 });
812 },
813 /**
814 * Handle the edit state requirements of selected media item.
815 *
816 * @return {void}
817 */
818 editState() {
819 const selection = this.state("featured-image").get("selection");
820 const view = new wp.media.view.EditImage({
821 model: selection.single(),
822 controller: this
823 }).render();
824 this.content.set(view);
825 view.loadEditor();
826 },
827 /**
828 * Create the default states.
829 *
830 * @return {void}
831 */
832 createStates: function createStates() {
833 this.on(
834 "toolbar:create:featured-image",
835 this.featuredImageToolbar,
836 this
837 );
838 this.on("content:render:edit-image", this.editState, this);
839 this.states.add([
840 new wp.media.controller.FeaturedImage(),
841 new wp.media.controller.EditImage({
842 model: this.options.editImage
843 })
844 ]);
845 }
846 });
847 };
848 var getSingleMediaFrame = () => {
849 const { wp } = window;
850 return wp.media.view.MediaFrame.Select.extend({
851 /**
852 * Create the default states on the frame.
853 */
854 createStates() {
855 const options = this.options;
856 if (this.options.states) {
857 return;
858 }
859 this.states.add([
860 // Main states.
861 new wp.media.controller.Library({
862 library: wp.media.query(options.library),
863 multiple: options.multiple,
864 title: options.title,
865 priority: 20,
866 filterable: "uploaded"
867 // Allow filtering by uploaded images.
868 }),
869 new wp.media.controller.EditImage({
870 model: options.editImage
871 })
872 ]);
873 }
874 });
875 };
876 var getGalleryDetailsMediaFrame = () => {
877 const { wp } = window;
878 return wp.media.view.MediaFrame.Post.extend({
879 /**
880 * Set up gallery toolbar.
881 *
882 * @return {void}
883 */
884 galleryToolbar() {
885 const editing = this.state().get("editing");
886 this.toolbar.set(
887 new wp.media.view.Toolbar({
888 controller: this,
889 items: {
890 insert: {
891 style: "primary",
892 text: editing ? wp.media.view.l10n.updateGallery : wp.media.view.l10n.insertGallery,
893 priority: 80,
894 requires: { library: true },
895 /**
896 * @fires wp.media.controller.State#update
897 */
898 click() {
899 const controller = this.controller, state = controller.state();
900 controller.close();
901 state.trigger(
902 "update",
903 state.get("library")
904 );
905 controller.setState(controller.options.state);
906 controller.reset();
907 }
908 }
909 }
910 })
911 );
912 },
913 /**
914 * Handle the edit state requirements of selected media item.
915 *
916 * @return {void}
917 */
918 editState() {
919 const selection = this.state("gallery").get("selection");
920 const view = new wp.media.view.EditImage({
921 model: selection.single(),
922 controller: this
923 }).render();
924 this.content.set(view);
925 view.loadEditor();
926 },
927 /**
928 * Create the default states.
929 *
930 * @return {void}
931 */
932 createStates: function createStates() {
933 this.on("toolbar:create:main-gallery", this.galleryToolbar, this);
934 this.on("content:render:edit-image", this.editState, this);
935 this.states.add([
936 new wp.media.controller.Library({
937 id: "gallery",
938 title: wp.media.view.l10n.createGalleryTitle,
939 priority: 40,
940 toolbar: "main-gallery",
941 filterable: "uploaded",
942 multiple: "add",
943 editable: false,
944 library: wp.media.query({
945 type: "image",
946 ...this.options.library
947 })
948 }),
949 new wp.media.controller.EditImage({
950 model: this.options.editImage
951 }),
952 new wp.media.controller.GalleryEdit({
953 library: this.options.selection,
954 editing: this.options.editing,
955 menu: "gallery",
956 displaySettings: false,
957 multiple: true
958 }),
959 new wp.media.controller.GalleryAdd()
960 ]);
961 }
962 });
963 };
964 var slimImageObject = (img) => {
965 const attrSet = [
966 "sizes",
967 "mime",
968 "type",
969 "subtype",
970 "id",
971 "url",
972 "alt",
973 "link",
974 "caption"
975 ];
976 return attrSet.reduce((result, key) => {
977 if (img?.hasOwnProperty(key)) {
978 result[key] = img[key];
979 }
980 return result;
981 }, {});
982 };
983 var getAttachmentsCollection = (ids) => {
984 const { wp } = window;
985 return wp.media.query({
986 order: "ASC",
987 orderby: "post__in",
988 post__in: ids,
989 posts_per_page: -1,
990 query: true,
991 type: "image"
992 });
993 };
994 var MediaUpload = class extends import_element.Component {
995 constructor() {
996 super(...arguments);
997 this.openModal = this.openModal.bind(this);
998 this.onOpen = this.onOpen.bind(this);
999 this.onSelect = this.onSelect.bind(this);
1000 this.onUpdate = this.onUpdate.bind(this);
1001 this.onClose = this.onClose.bind(this);
1002 }
1003 initializeListeners() {
1004 this.frame.on("select", this.onSelect);
1005 this.frame.on("update", this.onUpdate);
1006 this.frame.on("open", this.onOpen);
1007 this.frame.on("close", this.onClose);
1008 }
1009 /**
1010 * Sets the Gallery frame and initializes listeners.
1011 *
1012 * @return {void}
1013 */
1014 buildAndSetGalleryFrame() {
1015 const {
1016 addToGallery = false,
1017 allowedTypes,
1018 multiple = false,
1019 value = DEFAULT_EMPTY_GALLERY
1020 } = this.props;
1021 if (value === this.lastGalleryValue) {
1022 return;
1023 }
1024 const { wp } = window;
1025 this.lastGalleryValue = value;
1026 if (this.frame) {
1027 this.frame.remove();
1028 }
1029 let currentState;
1030 if (addToGallery) {
1031 currentState = "gallery-library";
1032 } else {
1033 currentState = value && value.length ? "gallery-edit" : "gallery";
1034 }
1035 if (!this.GalleryDetailsMediaFrame) {
1036 this.GalleryDetailsMediaFrame = getGalleryDetailsMediaFrame();
1037 }
1038 const attachments = getAttachmentsCollection(value);
1039 const selection = new wp.media.model.Selection(attachments.models, {
1040 props: attachments.props.toJSON(),
1041 multiple
1042 });
1043 this.frame = new this.GalleryDetailsMediaFrame({
1044 mimeType: allowedTypes,
1045 state: currentState,
1046 multiple,
1047 selection,
1048 editing: !!value?.length
1049 });
1050 wp.media.frame = this.frame;
1051 this.initializeListeners();
1052 }
1053 /**
1054 * Initializes the Media Library requirements for the featured image flow.
1055 *
1056 * @return {void}
1057 */
1058 buildAndSetFeatureImageFrame() {
1059 const { wp } = window;
1060 const { value: featuredImageId, multiple, allowedTypes } = this.props;
1061 const featuredImageFrame = getFeaturedImageMediaFrame();
1062 const attachments = getAttachmentsCollection(featuredImageId);
1063 const selection = new wp.media.model.Selection(attachments.models, {
1064 props: attachments.props.toJSON()
1065 });
1066 this.frame = new featuredImageFrame({
1067 mimeType: allowedTypes,
1068 state: "featured-image",
1069 multiple,
1070 selection,
1071 editing: featuredImageId
1072 });
1073 wp.media.frame = this.frame;
1074 wp.media.view.settings.post = {
1075 ...wp.media.view.settings.post,
1076 featuredImageId: featuredImageId || -1
1077 };
1078 }
1079 /**
1080 * Initializes the Media Library requirements for the single image flow.
1081 *
1082 * @return {void}
1083 */
1084 buildAndSetSingleMediaFrame() {
1085 const { wp } = window;
1086 const {
1087 allowedTypes,
1088 multiple = false,
1089 title = (0, import_i18n.__)("Select or Upload Media"),
1090 value
1091 } = this.props;
1092 const frameConfig = {
1093 title,
1094 multiple
1095 };
1096 if (!!allowedTypes) {
1097 frameConfig.library = { type: allowedTypes };
1098 }
1099 if (this.frame) {
1100 this.frame.remove();
1101 }
1102 const singleImageFrame = getSingleMediaFrame();
1103 const attachments = getAttachmentsCollection(value);
1104 const selection = new wp.media.model.Selection(attachments.models, {
1105 props: attachments.props.toJSON()
1106 });
1107 this.frame = new singleImageFrame({
1108 mimeType: allowedTypes,
1109 multiple,
1110 selection,
1111 ...frameConfig
1112 });
1113 wp.media.frame = this.frame;
1114 }
1115 componentWillUnmount() {
1116 this.frame?.remove();
1117 }
1118 onUpdate(selections) {
1119 const { onSelect, multiple = false } = this.props;
1120 const state = this.frame.state();
1121 const selectedImages = selections || state.get("selection");
1122 if (!selectedImages || !selectedImages.models.length) {
1123 return;
1124 }
1125 if (multiple) {
1126 onSelect(
1127 selectedImages.models.map(
1128 (model) => slimImageObject(model.toJSON())
1129 )
1130 );
1131 } else {
1132 onSelect(slimImageObject(selectedImages.models[0].toJSON()));
1133 }
1134 }
1135 onSelect() {
1136 const { onSelect, multiple = false } = this.props;
1137 const attachment = this.frame.state().get("selection").toJSON();
1138 onSelect(multiple ? attachment : attachment[0]);
1139 }
1140 onOpen() {
1141 const { wp } = window;
1142 const { value } = this.props;
1143 this.updateCollection();
1144 if (this.props.mode) {
1145 this.frame.content.mode(this.props.mode);
1146 }
1147 const hasMedia = Array.isArray(value) ? !!value?.length : !!value;
1148 if (!hasMedia) {
1149 return;
1150 }
1151 const isGallery = this.props.gallery;
1152 const selection = this.frame.state().get("selection");
1153 const valueArray = Array.isArray(value) ? value : [value];
1154 if (!isGallery) {
1155 valueArray.forEach((id) => {
1156 selection.add(wp.media.attachment(id));
1157 });
1158 }
1159 const attachments = getAttachmentsCollection(valueArray);
1160 attachments.more().done(function() {
1161 if (isGallery && attachments?.models?.length) {
1162 selection.add(attachments.models);
1163 }
1164 });
1165 }
1166 onClose() {
1167 const { onClose } = this.props;
1168 if (onClose) {
1169 onClose();
1170 }
1171 this.frame.detach();
1172 }
1173 updateCollection() {
1174 const frameContent = this.frame.content.get();
1175 if (frameContent && frameContent.collection) {
1176 const collection = frameContent.collection;
1177 collection.toArray().forEach((model) => model.trigger("destroy", model));
1178 collection.mirroring._hasMore = true;
1179 collection.more();
1180 }
1181 }
1182 openModal() {
1183 const {
1184 gallery = false,
1185 unstableFeaturedImageFlow = false,
1186 modalClass
1187 } = this.props;
1188 if (gallery) {
1189 this.buildAndSetGalleryFrame();
1190 } else {
1191 this.buildAndSetSingleMediaFrame();
1192 }
1193 if (modalClass) {
1194 this.frame.$el.addClass(modalClass);
1195 }
1196 if (unstableFeaturedImageFlow) {
1197 this.buildAndSetFeatureImageFrame();
1198 }
1199 this.initializeListeners();
1200 this.frame.open();
1201 }
1202 render() {
1203 return this.props.render({ open: this.openModal });
1204 }
1205 };
1206 var media_upload_default = MediaUpload;
1207
1208 // packages/media-utils/build-module/utils/upload-media.mjs
1209 var import_i18n5 = __toESM(require_i18n(), 1);
1210 var import_blob = __toESM(require_blob(), 1);
1211
1212 // packages/media-utils/build-module/utils/upload-to-server.mjs
1213 var import_api_fetch = __toESM(require_api_fetch(), 1);
1214
1215 // packages/media-utils/build-module/utils/flatten-form-data.mjs
1216 function isPlainObject(data) {
1217 return data !== null && typeof data === "object" && Object.getPrototypeOf(data) === Object.prototype;
1218 }
1219 function flattenFormData(formData, key, data) {
1220 if (isPlainObject(data)) {
1221 for (const [name, value] of Object.entries(data)) {
1222 flattenFormData(formData, `${key}[${name}]`, value);
1223 }
1224 } else if (data !== void 0) {
1225 formData.append(key, String(data));
1226 }
1227 }
1228
1229 // packages/media-utils/build-module/utils/transform-attachment.mjs
1230 function transformAttachment(attachment) {
1231 const { alt_text, source_url, ...savedMediaProps } = attachment;
1232 return {
1233 ...savedMediaProps,
1234 alt: attachment.alt_text,
1235 caption: attachment.caption?.raw ?? "",
1236 title: attachment.title.raw,
1237 url: attachment.source_url,
1238 poster: attachment._embedded?.["wp:featuredmedia"]?.[0]?.source_url || void 0
1239 };
1240 }
1241
1242 // packages/media-utils/build-module/utils/upload-to-server.mjs
1243 async function uploadToServer(file, additionalData = {}, signal) {
1244 const data = new FormData();
1245 data.append("file", file, file.name || file.type.replace("/", "."));
1246 for (const [key, value] of Object.entries(additionalData)) {
1247 flattenFormData(
1248 data,
1249 key,
1250 value
1251 );
1252 }
1253 return transformAttachment(
1254 await (0, import_api_fetch.default)({
1255 // This allows the video block to directly get a video's poster image.
1256 path: "/wp/v2/media?_embed=wp:featuredmedia",
1257 body: data,
1258 method: "POST",
1259 signal
1260 })
1261 );
1262 }
1263
1264 // packages/media-utils/build-module/utils/validate-mime-type.mjs
1265 var import_i18n2 = __toESM(require_i18n(), 1);
1266
1267 // packages/media-utils/build-module/utils/upload-error.mjs
1268 var UploadError = class extends Error {
1269 code;
1270 file;
1271 constructor({ code, message: message2, file, cause }) {
1272 super(message2, { cause });
1273 Object.setPrototypeOf(this, new.target.prototype);
1274 this.code = code;
1275 this.file = file;
1276 }
1277 };
1278
1279 // packages/media-utils/build-module/utils/validate-mime-type.mjs
1280 function validateMimeType(file, allowedTypes) {
1281 if (!allowedTypes || allowedTypes.includes("*")) {
1282 return;
1283 }
1284 const isAllowedType = allowedTypes.some((allowedType) => {
1285 if (allowedType.includes("/")) {
1286 return allowedType === file.type;
1287 }
1288 return file.type.startsWith(`${allowedType}/`);
1289 });
1290 if (file.type && !isAllowedType) {
1291 throw new UploadError({
1292 code: "MIME_TYPE_NOT_SUPPORTED",
1293 message: (0, import_i18n2.sprintf)(
1294 // translators: %s: file name.
1295 (0, import_i18n2.__)("%s: Sorry, this file type is not supported here."),
1296 file.name
1297 ),
1298 file
1299 });
1300 }
1301 }
1302
1303 // packages/media-utils/build-module/utils/validate-mime-type-for-user.mjs
1304 var import_i18n3 = __toESM(require_i18n(), 1);
1305
1306 // packages/media-utils/build-module/utils/get-mime-types-array.mjs
1307 function getMimeTypesArray(wpMimeTypesObject) {
1308 if (!wpMimeTypesObject) {
1309 return null;
1310 }
1311 return Object.entries(wpMimeTypesObject).flatMap(
1312 ([extensionsString, mime]) => {
1313 const [type] = mime.split("/");
1314 const extensions = extensionsString.split("|");
1315 return [
1316 mime,
1317 ...extensions.map(
1318 (extension) => `${type}/${extension}`
1319 )
1320 ];
1321 }
1322 );
1323 }
1324
1325 // packages/media-utils/build-module/utils/validate-mime-type-for-user.mjs
1326 function validateMimeTypeForUser(file, wpAllowedMimeTypes) {
1327 const allowedMimeTypesForUser = getMimeTypesArray(wpAllowedMimeTypes);
1328 if (!allowedMimeTypesForUser) {
1329 return;
1330 }
1331 const isAllowedMimeTypeForUser = allowedMimeTypesForUser.includes(
1332 file.type
1333 );
1334 if (file.type && !isAllowedMimeTypeForUser) {
1335 throw new UploadError({
1336 code: "MIME_TYPE_NOT_ALLOWED_FOR_USER",
1337 message: (0, import_i18n3.sprintf)(
1338 // translators: %s: file name.
1339 (0, import_i18n3.__)(
1340 "%s: Sorry, you are not allowed to upload this file type."
1341 ),
1342 file.name
1343 ),
1344 file
1345 });
1346 }
1347 }
1348
1349 // packages/media-utils/build-module/utils/validate-file-size.mjs
1350 var import_i18n4 = __toESM(require_i18n(), 1);
1351 function validateFileSize(file, maxUploadFileSize) {
1352 if (file.size <= 0) {
1353 throw new UploadError({
1354 code: "EMPTY_FILE",
1355 message: (0, import_i18n4.sprintf)(
1356 // translators: %s: file name.
1357 (0, import_i18n4.__)("%s: This file is empty."),
1358 file.name
1359 ),
1360 file
1361 });
1362 }
1363 if (maxUploadFileSize && file.size > maxUploadFileSize) {
1364 throw new UploadError({
1365 code: "SIZE_ABOVE_LIMIT",
1366 message: (0, import_i18n4.sprintf)(
1367 // translators: %s: file name.
1368 (0, import_i18n4.__)(
1369 "%s: This file exceeds the maximum upload size for this site."
1370 ),
1371 file.name
1372 ),
1373 file
1374 });
1375 }
1376 }
1377
1378 // packages/media-utils/build-module/utils/upload-media.mjs
1379 function uploadMedia({
1380 wpAllowedMimeTypes,
1381 allowedTypes,
1382 additionalData = {},
1383 filesList,
1384 maxUploadFileSize,
1385 onError,
1386 onFileChange,
1387 signal,
1388 multiple = true
1389 }) {
1390 if (!multiple && filesList.length > 1) {
1391 onError?.(new Error((0, import_i18n5.__)("Only one file can be used here.")));
1392 return;
1393 }
1394 const validFiles = [];
1395 const filesSet = [];
1396 const setAndUpdateFiles = (index, value) => {
1397 if (!window.__clientSideMediaProcessing) {
1398 if (filesSet[index]?.url) {
1399 (0, import_blob.revokeBlobURL)(filesSet[index].url);
1400 }
1401 }
1402 filesSet[index] = value;
1403 onFileChange?.(
1404 filesSet.filter((attachment) => attachment !== null)
1405 );
1406 };
1407 for (const mediaFile of filesList) {
1408 try {
1409 validateMimeTypeForUser(mediaFile, wpAllowedMimeTypes);
1410 } catch (error) {
1411 onError?.(error);
1412 continue;
1413 }
1414 try {
1415 validateMimeType(mediaFile, allowedTypes);
1416 } catch (error) {
1417 onError?.(error);
1418 continue;
1419 }
1420 try {
1421 validateFileSize(mediaFile, maxUploadFileSize);
1422 } catch (error) {
1423 onError?.(error);
1424 continue;
1425 }
1426 validFiles.push(mediaFile);
1427 if (!window.__clientSideMediaProcessing) {
1428 filesSet.push({ url: (0, import_blob.createBlobURL)(mediaFile) });
1429 onFileChange?.(filesSet);
1430 }
1431 }
1432 validFiles.map(async (file, index) => {
1433 try {
1434 const attachment = await uploadToServer(
1435 file,
1436 additionalData,
1437 signal
1438 );
1439 setAndUpdateFiles(index, attachment);
1440 } catch (error) {
1441 setAndUpdateFiles(index, null);
1442 let message2;
1443 if (typeof error === "object" && error !== null && "message" in error) {
1444 message2 = typeof error.message === "string" ? error.message : String(error.message);
1445 } else {
1446 message2 = (0, import_i18n5.sprintf)(
1447 // translators: %s: file name
1448 (0, import_i18n5.__)("Error while uploading file %s to the media library."),
1449 file.name
1450 );
1451 }
1452 onError?.(
1453 new UploadError({
1454 code: "GENERAL",
1455 message: message2,
1456 file,
1457 cause: error instanceof Error ? error : void 0
1458 })
1459 );
1460 }
1461 });
1462 }
1463
1464 // packages/media-utils/build-module/utils/sideload-media.mjs
1465 var import_i18n6 = __toESM(require_i18n(), 1);
1466
1467 // packages/media-utils/build-module/utils/sideload-to-server.mjs
1468 var import_api_fetch2 = __toESM(require_api_fetch(), 1);
1469 async function sideloadToServer(file, attachmentId, additionalData = {}, signal) {
1470 const data = new FormData();
1471 data.append("file", file, file.name || file.type.replace("/", "."));
1472 for (const [key, value] of Object.entries(additionalData)) {
1473 flattenFormData(
1474 data,
1475 key,
1476 value
1477 );
1478 }
1479 return (0, import_api_fetch2.default)({
1480 path: `/wp/v2/media/${attachmentId}/sideload`,
1481 body: data,
1482 method: "POST",
1483 signal
1484 });
1485 }
1486
1487 // packages/media-utils/build-module/utils/sideload-media.mjs
1488 var noop = () => {
1489 };
1490 async function sideloadMedia({
1491 file,
1492 attachmentId,
1493 additionalData = {},
1494 signal,
1495 onSuccess,
1496 onError = noop
1497 }) {
1498 try {
1499 const subSizeData = await sideloadToServer(
1500 file,
1501 attachmentId,
1502 additionalData,
1503 signal
1504 );
1505 onSuccess?.(subSizeData);
1506 } catch (error) {
1507 let message2;
1508 if (error instanceof Error) {
1509 message2 = error.message;
1510 } else {
1511 message2 = (0, import_i18n6.sprintf)(
1512 // translators: %s: file name
1513 (0, import_i18n6.__)("Error while sideloading file %s to the server."),
1514 file.name
1515 );
1516 }
1517 onError(
1518 new UploadError({
1519 code: "GENERAL",
1520 message: message2,
1521 file,
1522 cause: error instanceof Error ? error : void 0
1523 })
1524 );
1525 }
1526 }
1527
1528 // node_modules/clsx/dist/clsx.mjs
1529 function r(e2) {
1530 var t2, f2, n2 = "";
1531 if ("string" == typeof e2 || "number" == typeof e2) n2 += e2;
1532 else if ("object" == typeof e2) if (Array.isArray(e2)) {
1533 var o2 = e2.length;
1534 for (t2 = 0; t2 < o2; t2++) e2[t2] && (f2 = r(e2[t2])) && (n2 && (n2 += " "), n2 += f2);
1535 } else for (f2 in e2) e2[f2] && (n2 && (n2 += " "), n2 += f2);
1536 return n2;
1537 }
1538 function clsx() {
1539 for (var e2, t2, f2 = 0, n2 = "", o2 = arguments.length; f2 < o2; f2++) (e2 = arguments[f2]) && (t2 = r(e2)) && (n2 && (n2 += " "), n2 += t2);
1540 return n2;
1541 }
1542 var clsx_default = clsx;
1543
1544 // packages/media-utils/build-module/components/media-upload-modal/index.mjs
1545 var import_element68 = __toESM(require_element(), 1);
1546 var import_i18n66 = __toESM(require_i18n(), 1);
1547 var import_core_data6 = __toESM(require_core_data(), 1);
1548 var import_data13 = __toESM(require_data(), 1);
1549 var import_components53 = __toESM(require_components(), 1);
1550
1551 // packages/icons/build-module/library/arrow-down.mjs
1552 var import_primitives = __toESM(require_primitives(), 1);
1553 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
1554 var arrow_down_default = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.Path, { d: "m16.5 13.5-3.7 3.7V4h-1.5v13.2l-3.8-3.7-1 1 5.5 5.6 5.5-5.6z" }) });
1555
1556 // packages/icons/build-module/library/arrow-left.mjs
1557 var import_primitives2 = __toESM(require_primitives(), 1);
1558 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
1559 var arrow_left_default = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.Path, { d: "M20 11.2H6.8l3.7-3.7-1-1L3.9 12l5.6 5.5 1-1-3.7-3.7H20z" }) });
1560
1561 // packages/icons/build-module/library/arrow-right.mjs
1562 var import_primitives3 = __toESM(require_primitives(), 1);
1563 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
1564 var arrow_right_default = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.Path, { d: "m14.5 6.5-1 1 3.7 3.7H4v1.6h13.2l-3.7 3.7 1 1 5.6-5.5z" }) });
1565
1566 // packages/icons/build-module/library/arrow-up.mjs
1567 var import_primitives4 = __toESM(require_primitives(), 1);
1568 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
1569 var arrow_up_default = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.Path, { d: "M12 3.9 6.5 9.5l1 1 3.8-3.7V20h1.5V6.8l3.7 3.7 1-1z" }) });
1570
1571 // packages/icons/build-module/library/audio.mjs
1572 var import_primitives5 = __toESM(require_primitives(), 1);
1573 var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
1574 var audio_default = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.Path, { d: "M17.7 4.3c-1.2 0-2.8 0-3.8 1-.6.6-.9 1.5-.9 2.6V14c-.6-.6-1.5-1-2.5-1C8.6 13 7 14.6 7 16.5S8.6 20 10.5 20c1.5 0 2.8-1 3.3-2.3.5-.8.7-1.8.7-2.5V7.9c0-.7.2-1.2.5-1.6.6-.6 1.8-.6 2.8-.6h.3V4.3h-.4z" }) });
1575
1576 // packages/icons/build-module/library/block-table.mjs
1577 var import_primitives6 = __toESM(require_primitives(), 1);
1578 var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
1579 var block_table_default = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives6.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives6.Path, { d: "M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM5 4.5h14c.3 0 .5.2.5.5v3.5h-15V5c0-.3.2-.5.5-.5zm8 5.5h6.5v3.5H13V10zm-1.5 3.5h-7V10h7v3.5zm-7 5.5v-4h7v4.5H5c-.3 0-.5-.2-.5-.5zm14.5.5h-6V15h6.5v4c0 .3-.2.5-.5.5z" }) });
1580
1581 // packages/icons/build-module/library/category.mjs
1582 var import_primitives7 = __toESM(require_primitives(), 1);
1583 var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
1584 var category_default = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives7.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives7.Path, { fillRule: "evenodd", clipRule: "evenodd", d: "M6 5.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5H6a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM4 6a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2H6a2 2 0 01-2-2V6zm11-.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5h-3a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM13 6a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2h-3a2 2 0 01-2-2V6zm5 8.5h-3a.5.5 0 00-.5.5v3a.5.5 0 00.5.5h3a.5.5 0 00.5-.5v-3a.5.5 0 00-.5-.5zM15 13a2 2 0 00-2 2v3a2 2 0 002 2h3a2 2 0 002-2v-3a2 2 0 00-2-2h-3zm-9 1.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5H6a.5.5 0 01-.5-.5v-3a.5.5 0 01.5-.5zM4 15a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2H6a2 2 0 01-2-2v-3z" }) });
1585
1586 // packages/icons/build-module/library/check.mjs
1587 var import_primitives8 = __toESM(require_primitives(), 1);
1588 var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
1589 var check_default = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_primitives8.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_primitives8.Path, { d: "M16.5 7.5 10 13.9l-2.5-2.4-1 1 3.5 3.6 7.5-7.6z" }) });
1590
1591 // packages/icons/build-module/library/chevron-down.mjs
1592 var import_primitives9 = __toESM(require_primitives(), 1);
1593 var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
1594 var chevron_down_default = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_primitives9.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_primitives9.Path, { d: "M17.5 11.6L12 16l-5.5-4.4.9-1.2L12 14l4.5-3.6 1 1.2z" }) });
1595
1596 // packages/icons/build-module/library/close-small.mjs
1597 var import_primitives10 = __toESM(require_primitives(), 1);
1598 var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1);
1599 var close_small_default = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_primitives10.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_primitives10.Path, { d: "M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z" }) });
1600
1601 // packages/icons/build-module/library/cog.mjs
1602 var import_primitives11 = __toESM(require_primitives(), 1);
1603 var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1);
1604 var cog_default = /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_primitives11.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_primitives11.Path, { fillRule: "evenodd", clipRule: "evenodd", d: "M10.289 4.836A1 1 0 0111.275 4h1.306a1 1 0 01.987.836l.244 1.466c.787.26 1.503.679 2.108 1.218l1.393-.522a1 1 0 011.216.437l.653 1.13a1 1 0 01-.23 1.273l-1.148.944a6.025 6.025 0 010 2.435l1.149.946a1 1 0 01.23 1.272l-.653 1.13a1 1 0 01-1.216.437l-1.394-.522c-.605.54-1.32.958-2.108 1.218l-.244 1.466a1 1 0 01-.987.836h-1.306a1 1 0 01-.986-.836l-.244-1.466a5.995 5.995 0 01-2.108-1.218l-1.394.522a1 1 0 01-1.217-.436l-.653-1.131a1 1 0 01.23-1.272l1.149-.946a6.026 6.026 0 010-2.435l-1.148-.944a1 1 0 01-.23-1.272l.653-1.131a1 1 0 011.217-.437l1.393.522a5.994 5.994 0 012.108-1.218l.244-1.466zM14.929 12a3 3 0 11-6 0 3 3 0 016 0z" }) });
1605
1606 // packages/icons/build-module/library/comment-author-avatar.mjs
1607 var import_primitives12 = __toESM(require_primitives(), 1);
1608 var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1);
1609 var comment_author_avatar_default = /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_primitives12.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_primitives12.Path, { fillRule: "evenodd", clipRule: "evenodd", d: "M7.25 16.437a6.5 6.5 0 1 1 9.5 0V16A2.75 2.75 0 0 0 14 13.25h-4A2.75 2.75 0 0 0 7.25 16v.437Zm1.5 1.193a6.47 6.47 0 0 0 3.25.87 6.47 6.47 0 0 0 3.25-.87V16c0-.69-.56-1.25-1.25-1.25h-4c-.69 0-1.25.56-1.25 1.25v1.63ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Zm10-2a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z" }) });
1610
1611 // packages/icons/build-module/library/envelope.mjs
1612 var import_primitives13 = __toESM(require_primitives(), 1);
1613 var import_jsx_runtime13 = __toESM(require_jsx_runtime(), 1);
1614 var envelope_default = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_primitives13.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_primitives13.Path, { fillRule: "evenodd", clipRule: "evenodd", d: "M3 7c0-1.1.9-2 2-2h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Zm2-.5h14c.3 0 .5.2.5.5v1L12 13.5 4.5 7.9V7c0-.3.2-.5.5-.5Zm-.5 3.3V17c0 .3.2.5.5.5h14c.3 0 .5-.2.5-.5V9.8L12 15.4 4.5 9.8Z" }) });
1615
1616 // packages/icons/build-module/library/error.mjs
1617 var import_primitives14 = __toESM(require_primitives(), 1);
1618 var import_jsx_runtime14 = __toESM(require_jsx_runtime(), 1);
1619 var error_default = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_primitives14.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_primitives14.Path, { fillRule: "evenodd", clipRule: "evenodd", d: "M12.218 5.377a.25.25 0 0 0-.436 0l-7.29 12.96a.25.25 0 0 0 .218.373h14.58a.25.25 0 0 0 .218-.372l-7.29-12.96Zm-1.743-.735c.669-1.19 2.381-1.19 3.05 0l7.29 12.96a1.75 1.75 0 0 1-1.525 2.608H4.71a1.75 1.75 0 0 1-1.525-2.608l7.29-12.96ZM12.75 17.46h-1.5v-1.5h1.5v1.5Zm-1.5-3h1.5v-5h-1.5v5Z" }) });
1620
1621 // packages/icons/build-module/library/file.mjs
1622 var import_primitives15 = __toESM(require_primitives(), 1);
1623 var import_jsx_runtime15 = __toESM(require_jsx_runtime(), 1);
1624 var file_default = /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_primitives15.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_primitives15.Path, { fillRule: "evenodd", clipRule: "evenodd", d: "M12.848 8a1 1 0 0 1-.914-.594l-.723-1.63a.5.5 0 0 0-.447-.276H5a.5.5 0 0 0-.5.5v11.5a.5.5 0 0 0 .5.5h14a.5.5 0 0 0 .5-.5v-9A.5.5 0 0 0 19 8h-6.152Zm.612-1.5a.5.5 0 0 1-.462-.31l-.445-1.084A2 2 0 0 0 10.763 4H5a2 2 0 0 0-2 2v11.5a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-9a2 2 0 0 0-2-2h-5.54Z" }) });
1625
1626 // packages/icons/build-module/library/format-list-bullets-rtl.mjs
1627 var import_primitives16 = __toESM(require_primitives(), 1);
1628 var import_jsx_runtime16 = __toESM(require_jsx_runtime(), 1);
1629 var format_list_bullets_rtl_default = /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_primitives16.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_primitives16.Path, { d: "M4 8.8h8.9V7.2H4v1.6zm0 7h8.9v-1.5H4v1.5zM18 13c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0-3c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2z" }) });
1630
1631 // packages/icons/build-module/library/format-list-bullets.mjs
1632 var import_primitives17 = __toESM(require_primitives(), 1);
1633 var import_jsx_runtime17 = __toESM(require_jsx_runtime(), 1);
1634 var format_list_bullets_default = /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_primitives17.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_primitives17.Path, { d: "M11.1 15.8H20v-1.5h-8.9v1.5zm0-8.6v1.5H20V7.2h-8.9zM6 13c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0-7c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z" }) });
1635
1636 // packages/icons/build-module/library/funnel.mjs
1637 var import_primitives18 = __toESM(require_primitives(), 1);
1638 var import_jsx_runtime18 = __toESM(require_jsx_runtime(), 1);
1639 var funnel_default = /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_primitives18.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_primitives18.Path, { d: "M10 17.5H14V16H10V17.5ZM6 6V7.5H18V6H6ZM8 12.5H16V11H8V12.5Z" }) });
1640
1641 // packages/icons/build-module/library/image.mjs
1642 var import_primitives19 = __toESM(require_primitives(), 1);
1643 var import_jsx_runtime19 = __toESM(require_jsx_runtime(), 1);
1644 var image_default = /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_primitives19.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_primitives19.Path, { d: "M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM5 4.5h14c.3 0 .5.2.5.5v8.4l-3-2.9c-.3-.3-.8-.3-1 0L11.9 14 9 12c-.3-.2-.6-.2-.8 0l-3.6 2.6V5c-.1-.3.1-.5.4-.5zm14 15H5c-.3 0-.5-.2-.5-.5v-2.4l4.1-3 3 1.9c.3.2.7.2.9-.1L16 12l3.5 3.4V19c0 .3-.2.5-.5.5z" }) });
1645
1646 // packages/icons/build-module/library/link.mjs
1647 var import_primitives20 = __toESM(require_primitives(), 1);
1648 var import_jsx_runtime20 = __toESM(require_jsx_runtime(), 1);
1649 var link_default = /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_primitives20.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_primitives20.Path, { d: "M10 17.389H8.444A5.194 5.194 0 1 1 8.444 7H10v1.5H8.444a3.694 3.694 0 0 0 0 7.389H10v1.5ZM14 7h1.556a5.194 5.194 0 0 1 0 10.39H14v-1.5h1.556a3.694 3.694 0 0 0 0-7.39H14V7Zm-4.5 6h5v-1.5h-5V13Z" }) });
1650
1651 // packages/icons/build-module/library/mobile.mjs
1652 var import_primitives21 = __toESM(require_primitives(), 1);
1653 var import_jsx_runtime21 = __toESM(require_jsx_runtime(), 1);
1654 var mobile_default = /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_primitives21.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_primitives21.Path, { d: "M15 4H9c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h6c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm.5 14c0 .3-.2.5-.5.5H9c-.3 0-.5-.2-.5-.5V6c0-.3.2-.5.5-.5h6c.3 0 .5.2.5.5v12zm-4.5-.5h2V16h-2v1.5z" }) });
1655
1656 // packages/icons/build-module/library/more-vertical.mjs
1657 var import_primitives22 = __toESM(require_primitives(), 1);
1658 var import_jsx_runtime22 = __toESM(require_jsx_runtime(), 1);
1659 var more_vertical_default = /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_primitives22.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_primitives22.Path, { d: "M13 19h-2v-2h2v2zm0-6h-2v-2h2v2zm0-6h-2V5h2v2z" }) });
1660
1661 // packages/icons/build-module/library/next.mjs
1662 var import_primitives23 = __toESM(require_primitives(), 1);
1663 var import_jsx_runtime23 = __toESM(require_jsx_runtime(), 1);
1664 var next_default = /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_primitives23.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_primitives23.Path, { d: "M6.6 6L5.4 7l4.5 5-4.5 5 1.1 1 5.5-6-5.4-6zm6 0l-1.1 1 4.5 5-4.5 5 1.1 1 5.5-6-5.5-6z" }) });
1665
1666 // packages/icons/build-module/library/previous.mjs
1667 var import_primitives24 = __toESM(require_primitives(), 1);
1668 var import_jsx_runtime24 = __toESM(require_jsx_runtime(), 1);
1669 var previous_default = /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_primitives24.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_primitives24.Path, { d: "M11.6 7l-1.1-1L5 12l5.5 6 1.1-1L7 12l4.6-5zm6 0l-1.1-1-5.5 6 5.5 6 1.1-1-4.6-5 4.6-5z" }) });
1670
1671 // packages/icons/build-module/library/scheduled.mjs
1672 var import_primitives25 = __toESM(require_primitives(), 1);
1673 var import_jsx_runtime25 = __toESM(require_jsx_runtime(), 1);
1674 var scheduled_default = /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_primitives25.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_primitives25.Path, { fillRule: "evenodd", clipRule: "evenodd", d: "M12 18.5a6.5 6.5 0 1 1 0-13 6.5 6.5 0 0 1 0 13ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Zm9 1V8h-1.5v3.5h-2V13H13Z" }) });
1675
1676 // packages/icons/build-module/library/search.mjs
1677 var import_primitives26 = __toESM(require_primitives(), 1);
1678 var import_jsx_runtime26 = __toESM(require_jsx_runtime(), 1);
1679 var search_default = /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_primitives26.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_primitives26.Path, { d: "M13 5c-3.3 0-6 2.7-6 6 0 1.4.5 2.7 1.3 3.7l-3.8 3.8 1.1 1.1 3.8-3.8c1 .8 2.3 1.3 3.7 1.3 3.3 0 6-2.7 6-6S16.3 5 13 5zm0 10.5c-2.5 0-4.5-2-4.5-4.5s2-4.5 4.5-4.5 4.5 2 4.5 4.5-2 4.5-4.5 4.5z" }) });
1680
1681 // packages/icons/build-module/library/seen.mjs
1682 var import_primitives27 = __toESM(require_primitives(), 1);
1683 var import_jsx_runtime27 = __toESM(require_jsx_runtime(), 1);
1684 var seen_default = /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(import_primitives27.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(import_primitives27.Path, { d: "M3.99961 13C4.67043 13.3354 4.6703 13.3357 4.67017 13.3359L4.67298 13.3305C4.67621 13.3242 4.68184 13.3135 4.68988 13.2985C4.70595 13.2686 4.7316 13.2218 4.76695 13.1608C4.8377 13.0385 4.94692 12.8592 5.09541 12.6419C5.39312 12.2062 5.84436 11.624 6.45435 11.0431C7.67308 9.88241 9.49719 8.75 11.9996 8.75C14.502 8.75 16.3261 9.88241 17.5449 11.0431C18.1549 11.624 18.6061 12.2062 18.9038 12.6419C19.0523 12.8592 19.1615 13.0385 19.2323 13.1608C19.2676 13.2218 19.2933 13.2686 19.3093 13.2985C19.3174 13.3135 19.323 13.3242 19.3262 13.3305L19.3291 13.3359C19.3289 13.3357 19.3288 13.3354 19.9996 13C20.6704 12.6646 20.6703 12.6643 20.6701 12.664L20.6697 12.6632L20.6688 12.6614L20.6662 12.6563L20.6583 12.6408C20.6517 12.6282 20.6427 12.6108 20.631 12.5892C20.6078 12.5459 20.5744 12.4852 20.5306 12.4096C20.4432 12.2584 20.3141 12.0471 20.1423 11.7956C19.7994 11.2938 19.2819 10.626 18.5794 9.9569C17.1731 8.61759 14.9972 7.25 11.9996 7.25C9.00203 7.25 6.82614 8.61759 5.41987 9.9569C4.71736 10.626 4.19984 11.2938 3.85694 11.7956C3.68511 12.0471 3.55605 12.2584 3.4686 12.4096C3.42484 12.4852 3.39142 12.5459 3.36818 12.5892C3.35656 12.6108 3.34748 12.6282 3.34092 12.6408L3.33297 12.6563L3.33041 12.6614L3.32948 12.6632L3.32911 12.664C3.32894 12.6643 3.32879 12.6646 3.99961 13ZM11.9996 16C13.9326 16 15.4996 14.433 15.4996 12.5C15.4996 10.567 13.9326 9 11.9996 9C10.0666 9 8.49961 10.567 8.49961 12.5C8.49961 14.433 10.0666 16 11.9996 16Z" }) });
1685
1686 // packages/icons/build-module/library/unseen.mjs
1687 var import_primitives28 = __toESM(require_primitives(), 1);
1688 var import_jsx_runtime28 = __toESM(require_jsx_runtime(), 1);
1689 var unseen_default = /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_primitives28.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_primitives28.Path, { d: "M20.7 12.7s0-.1-.1-.2c0-.2-.2-.4-.4-.6-.3-.5-.9-1.2-1.6-1.8-.7-.6-1.5-1.3-2.6-1.8l-.6 1.4c.9.4 1.6 1 2.1 1.5.6.6 1.1 1.2 1.4 1.6.1.2.3.4.3.5v.1l.7-.3.7-.3Zm-5.2-9.3-1.8 4c-.5-.1-1.1-.2-1.7-.2-3 0-5.2 1.4-6.6 2.7-.7.7-1.2 1.3-1.6 1.8-.2.3-.3.5-.4.6 0 0 0 .1-.1.2s0 0 .7.3l.7.3V13c0-.1.2-.3.3-.5.3-.4.7-1 1.4-1.6 1.2-1.2 3-2.3 5.5-2.3H13v.3c-.4 0-.8-.1-1.1-.1-1.9 0-3.5 1.6-3.5 3.5s.6 2.3 1.6 2.9l-2 4.4.9.4 7.6-16.2-.9-.4Zm-3 12.6c1.7-.2 3-1.7 3-3.5s-.2-1.4-.6-1.9L12.4 16Z" }) });
1690
1691 // packages/icons/build-module/library/upload.mjs
1692 var import_primitives29 = __toESM(require_primitives(), 1);
1693 var import_jsx_runtime29 = __toESM(require_jsx_runtime(), 1);
1694 var upload_default = /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_primitives29.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_primitives29.Path, { d: "M18.5 15v3.5H13V6.7l4.5 4.1 1-1.1-6.2-5.8-5.8 5.8 1 1.1 4-4v11.7h-6V15H4v5h16v-5z" }) });
1695
1696 // packages/icons/build-module/library/video.mjs
1697 var import_primitives30 = __toESM(require_primitives(), 1);
1698 var import_jsx_runtime30 = __toESM(require_jsx_runtime(), 1);
1699 var video_default = /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_primitives30.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_primitives30.Path, { d: "M18.7 3H5.3C4 3 3 4 3 5.3v13.4C3 20 4 21 5.3 21h13.4c1.3 0 2.3-1 2.3-2.3V5.3C21 4 20 3 18.7 3zm.8 15.7c0 .4-.4.8-.8.8H5.3c-.4 0-.8-.4-.8-.8V5.3c0-.4.4-.8.8-.8h13.4c.4 0 .8.4.8.8v13.4zM10 15l5-3-5-3v6z" }) });
1700
1701 // node_modules/@base-ui/utils/esm/useRefWithInit.js
1702 var React = __toESM(require_react(), 1);
1703 var UNINITIALIZED = {};
1704 function useRefWithInit(init2, initArg) {
1705 const ref = React.useRef(UNINITIALIZED);
1706 if (ref.current === UNINITIALIZED) {
1707 ref.current = init2(initArg);
1708 }
1709 return ref;
1710 }
1711
1712 // node_modules/@base-ui/utils/esm/warn.js
1713 var set;
1714 if (true) {
1715 set = /* @__PURE__ */ new Set();
1716 }
1717 function warn(...messages) {
1718 if (true) {
1719 const messageKey = messages.join(" ");
1720 if (!set.has(messageKey)) {
1721 set.add(messageKey);
1722 console.warn(`Base UI: ${messageKey}`);
1723 }
1724 }
1725 }
1726
1727 // node_modules/@base-ui/react/esm/internals/useRenderElement.js
1728 var React4 = __toESM(require_react(), 1);
1729
1730 // node_modules/@base-ui/utils/esm/useMergedRefs.js
1731 function useMergedRefs(a2, b2, c2, d2) {
1732 const forkRef = useRefWithInit(createForkRef).current;
1733 if (didChange(forkRef, a2, b2, c2, d2)) {
1734 update(forkRef, [a2, b2, c2, d2]);
1735 }
1736 return forkRef.callback;
1737 }
1738 function useMergedRefsN(refs) {
1739 const forkRef = useRefWithInit(createForkRef).current;
1740 if (didChangeN(forkRef, refs)) {
1741 update(forkRef, refs);
1742 }
1743 return forkRef.callback;
1744 }
1745 function createForkRef() {
1746 return {
1747 callback: null,
1748 cleanup: null,
1749 refs: []
1750 };
1751 }
1752 function didChange(forkRef, a2, b2, c2, d2) {
1753 return forkRef.refs[0] !== a2 || forkRef.refs[1] !== b2 || forkRef.refs[2] !== c2 || forkRef.refs[3] !== d2;
1754 }
1755 function didChangeN(forkRef, newRefs) {
1756 return forkRef.refs.length !== newRefs.length || forkRef.refs.some((ref, index) => ref !== newRefs[index]);
1757 }
1758 function update(forkRef, refs) {
1759 forkRef.refs = refs;
1760 if (refs.every((ref) => ref == null)) {
1761 forkRef.callback = null;
1762 return;
1763 }
1764 forkRef.callback = (instance) => {
1765 if (forkRef.cleanup) {
1766 forkRef.cleanup();
1767 forkRef.cleanup = null;
1768 }
1769 if (instance != null) {
1770 const cleanupCallbacks = Array(refs.length).fill(null);
1771 for (let i2 = 0; i2 < refs.length; i2 += 1) {
1772 const ref = refs[i2];
1773 if (ref == null) {
1774 continue;
1775 }
1776 switch (typeof ref) {
1777 case "function": {
1778 const refCleanup = ref(instance);
1779 if (typeof refCleanup === "function") {
1780 cleanupCallbacks[i2] = refCleanup;
1781 }
1782 break;
1783 }
1784 case "object": {
1785 ref.current = instance;
1786 break;
1787 }
1788 default:
1789 }
1790 }
1791 forkRef.cleanup = () => {
1792 for (let i2 = 0; i2 < refs.length; i2 += 1) {
1793 const ref = refs[i2];
1794 if (ref == null) {
1795 continue;
1796 }
1797 switch (typeof ref) {
1798 case "function": {
1799 const cleanupCallback = cleanupCallbacks[i2];
1800 if (typeof cleanupCallback === "function") {
1801 cleanupCallback();
1802 } else {
1803 ref(null);
1804 }
1805 break;
1806 }
1807 case "object": {
1808 ref.current = null;
1809 break;
1810 }
1811 default:
1812 }
1813 }
1814 };
1815 }
1816 };
1817 }
1818
1819 // node_modules/@base-ui/utils/esm/getReactElementRef.js
1820 var React3 = __toESM(require_react(), 1);
1821
1822 // node_modules/@base-ui/utils/esm/reactVersion.js
1823 var React2 = __toESM(require_react(), 1);
1824 var majorVersion = parseInt(React2.version, 10);
1825 function isReactVersionAtLeast(reactVersionToCheck) {
1826 return majorVersion >= reactVersionToCheck;
1827 }
1828
1829 // node_modules/@base-ui/utils/esm/getReactElementRef.js
1830 function getReactElementRef(element) {
1831 if (!/* @__PURE__ */ React3.isValidElement(element)) {
1832 return null;
1833 }
1834 const reactElement = element;
1835 const propsWithRef = reactElement.props;
1836 return (isReactVersionAtLeast(19) ? propsWithRef?.ref : reactElement.ref) ?? null;
1837 }
1838
1839 // node_modules/@base-ui/utils/esm/mergeObjects.js
1840 function mergeObjects(a2, b2) {
1841 if (a2 && !b2) {
1842 return a2;
1843 }
1844 if (!a2 && b2) {
1845 return b2;
1846 }
1847 if (a2 || b2) {
1848 return {
1849 ...a2,
1850 ...b2
1851 };
1852 }
1853 return void 0;
1854 }
1855
1856 // node_modules/@base-ui/utils/esm/empty.js
1857 var EMPTY_ARRAY = Object.freeze([]);
1858 var EMPTY_OBJECT = Object.freeze({});
1859
1860 // node_modules/@base-ui/react/esm/internals/getStateAttributesProps.js
1861 function getStateAttributesProps(state, customMapping) {
1862 const props = {};
1863 for (const key in state) {
1864 const value = state[key];
1865 if (customMapping?.hasOwnProperty(key)) {
1866 const customProps = customMapping[key](value);
1867 if (customProps != null) {
1868 Object.assign(props, customProps);
1869 }
1870 continue;
1871 }
1872 if (value === true) {
1873 props[`data-${key.toLowerCase()}`] = "";
1874 } else if (value) {
1875 props[`data-${key.toLowerCase()}`] = value.toString();
1876 }
1877 }
1878 return props;
1879 }
1880
1881 // node_modules/@base-ui/react/esm/utils/resolveClassName.js
1882 function resolveClassName(className, state) {
1883 return typeof className === "function" ? className(state) : className;
1884 }
1885
1886 // node_modules/@base-ui/react/esm/utils/resolveStyle.js
1887 function resolveStyle(style, state) {
1888 return typeof style === "function" ? style(state) : style;
1889 }
1890
1891 // node_modules/@base-ui/react/esm/merge-props/mergeProps.js
1892 var EMPTY_PROPS = {};
1893 function mergeProps(a2, b2, c2, d2, e2) {
1894 if (!c2 && !d2 && !e2 && !a2) {
1895 return createInitialMergedProps(b2);
1896 }
1897 let merged = createInitialMergedProps(a2);
1898 if (b2) {
1899 merged = mergeInto(merged, b2);
1900 }
1901 if (c2) {
1902 merged = mergeInto(merged, c2);
1903 }
1904 if (d2) {
1905 merged = mergeInto(merged, d2);
1906 }
1907 if (e2) {
1908 merged = mergeInto(merged, e2);
1909 }
1910 return merged;
1911 }
1912 function mergePropsN(props) {
1913 if (props.length === 0) {
1914 return EMPTY_PROPS;
1915 }
1916 if (props.length === 1) {
1917 return createInitialMergedProps(props[0]);
1918 }
1919 let merged = createInitialMergedProps(props[0]);
1920 for (let i2 = 1; i2 < props.length; i2 += 1) {
1921 merged = mergeInto(merged, props[i2]);
1922 }
1923 return merged;
1924 }
1925 function createInitialMergedProps(inputProps) {
1926 if (isPropsGetter(inputProps)) {
1927 return {
1928 ...resolvePropsGetter(inputProps, EMPTY_PROPS)
1929 };
1930 }
1931 return copyInitialProps(inputProps);
1932 }
1933 function mergeInto(merged, inputProps) {
1934 if (isPropsGetter(inputProps)) {
1935 return resolvePropsGetter(inputProps, merged);
1936 }
1937 return mutablyMergeInto(merged, inputProps);
1938 }
1939 function copyInitialProps(inputProps) {
1940 const copiedProps = {
1941 ...inputProps
1942 };
1943 for (const propName in copiedProps) {
1944 const propValue = copiedProps[propName];
1945 if (isEventHandler(propName, propValue)) {
1946 copiedProps[propName] = wrapEventHandler(propValue);
1947 }
1948 }
1949 return copiedProps;
1950 }
1951 function mutablyMergeInto(mergedProps, externalProps) {
1952 if (!externalProps) {
1953 return mergedProps;
1954 }
1955 for (const propName in externalProps) {
1956 const externalPropValue = externalProps[propName];
1957 switch (propName) {
1958 case "style": {
1959 mergedProps[propName] = mergeObjects(mergedProps.style, externalPropValue);
1960 break;
1961 }
1962 case "className": {
1963 mergedProps[propName] = mergeClassNames(mergedProps.className, externalPropValue);
1964 break;
1965 }
1966 default: {
1967 if (isEventHandler(propName, externalPropValue)) {
1968 mergedProps[propName] = mergeEventHandlers(mergedProps[propName], externalPropValue);
1969 } else {
1970 mergedProps[propName] = externalPropValue;
1971 }
1972 }
1973 }
1974 }
1975 return mergedProps;
1976 }
1977 function isEventHandler(key, value) {
1978 const code0 = key.charCodeAt(0);
1979 const code1 = key.charCodeAt(1);
1980 const code2 = key.charCodeAt(2);
1981 return code0 === 111 && code1 === 110 && code2 >= 65 && code2 <= 90 && (typeof value === "function" || typeof value === "undefined");
1982 }
1983 function isPropsGetter(inputProps) {
1984 return typeof inputProps === "function";
1985 }
1986 function resolvePropsGetter(inputProps, previousProps) {
1987 if (isPropsGetter(inputProps)) {
1988 return inputProps(previousProps);
1989 }
1990 return inputProps ?? EMPTY_PROPS;
1991 }
1992 function mergeEventHandlers(ourHandler, theirHandler) {
1993 if (!theirHandler) {
1994 return ourHandler;
1995 }
1996 if (!ourHandler) {
1997 return wrapEventHandler(theirHandler);
1998 }
1999 return (...args) => {
2000 const event = args[0];
2001 if (isSyntheticEvent(event)) {
2002 const baseUIEvent = event;
2003 makeEventPreventable(baseUIEvent);
2004 const result2 = theirHandler(...args);
2005 if (!baseUIEvent.baseUIHandlerPrevented) {
2006 ourHandler?.(...args);
2007 }
2008 return result2;
2009 }
2010 const result = theirHandler(...args);
2011 ourHandler?.(...args);
2012 return result;
2013 };
2014 }
2015 function wrapEventHandler(handler) {
2016 if (!handler) {
2017 return handler;
2018 }
2019 return (...args) => {
2020 const event = args[0];
2021 if (isSyntheticEvent(event)) {
2022 makeEventPreventable(event);
2023 }
2024 return handler(...args);
2025 };
2026 }
2027 function makeEventPreventable(event) {
2028 event.preventBaseUIHandler = () => {
2029 event.baseUIHandlerPrevented = true;
2030 };
2031 return event;
2032 }
2033 function mergeClassNames(ourClassName, theirClassName) {
2034 if (theirClassName) {
2035 if (ourClassName) {
2036 return theirClassName + " " + ourClassName;
2037 }
2038 return theirClassName;
2039 }
2040 return ourClassName;
2041 }
2042 function isSyntheticEvent(event) {
2043 return event != null && typeof event === "object" && "nativeEvent" in event;
2044 }
2045
2046 // node_modules/@base-ui/react/esm/internals/useRenderElement.js
2047 var import_react = __toESM(require_react(), 1);
2048 function useRenderElement(element, componentProps, params = {}) {
2049 const renderProp = componentProps.render;
2050 const outProps = useRenderElementProps(componentProps, params);
2051 if (params.enabled === false) {
2052 return null;
2053 }
2054 const state = params.state ?? EMPTY_OBJECT;
2055 return evaluateRenderProp(element, renderProp, outProps, state);
2056 }
2057 function useRenderElementProps(componentProps, params = {}) {
2058 const {
2059 className: classNameProp,
2060 style: styleProp,
2061 render: renderProp
2062 } = componentProps;
2063 const {
2064 state = EMPTY_OBJECT,
2065 ref,
2066 props,
2067 stateAttributesMapping,
2068 enabled = true
2069 } = params;
2070 const className = enabled ? resolveClassName(classNameProp, state) : void 0;
2071 const style = enabled ? resolveStyle(styleProp, state) : void 0;
2072 const stateProps = enabled ? getStateAttributesProps(state, stateAttributesMapping) : EMPTY_OBJECT;
2073 const resolvedProps = enabled && props ? resolveRenderFunctionProps(props) : void 0;
2074 const outProps = enabled ? mergeObjects(stateProps, resolvedProps) ?? {} : EMPTY_OBJECT;
2075 if (typeof document !== "undefined") {
2076 if (!enabled) {
2077 useMergedRefs(null, null);
2078 } else if (Array.isArray(ref)) {
2079 outProps.ref = useMergedRefsN([outProps.ref, getReactElementRef(renderProp), ...ref]);
2080 } else {
2081 outProps.ref = useMergedRefs(outProps.ref, getReactElementRef(renderProp), ref);
2082 }
2083 }
2084 if (!enabled) {
2085 return EMPTY_OBJECT;
2086 }
2087 if (className !== void 0) {
2088 outProps.className = mergeClassNames(outProps.className, className);
2089 }
2090 if (style !== void 0) {
2091 outProps.style = mergeObjects(outProps.style, style);
2092 }
2093 return outProps;
2094 }
2095 function resolveRenderFunctionProps(props) {
2096 if (Array.isArray(props)) {
2097 return mergePropsN(props);
2098 }
2099 return mergeProps(void 0, props);
2100 }
2101 var REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for("react.lazy");
2102 var COMPONENT_IDENTIFIER_PATTERN = /^[A-Z][A-Za-z0-9$]*$/;
2103 var LOWERCASE_CHARACTER_PATTERN = /[a-z]/;
2104 function evaluateRenderProp(element, render4, props, state) {
2105 if (render4) {
2106 if (typeof render4 === "function") {
2107 if (true) {
2108 warnIfRenderPropLooksLikeComponent(render4);
2109 }
2110 return render4(props, state);
2111 }
2112 const mergedProps = mergeProps(props, render4.props);
2113 mergedProps.ref = props.ref;
2114 let newElement = render4;
2115 if (newElement?.$$typeof === REACT_LAZY_TYPE) {
2116 const children = React4.Children.toArray(render4);
2117 newElement = children[0];
2118 }
2119 if (true) {
2120 if (!/* @__PURE__ */ React4.isValidElement(newElement)) {
2121 throw new Error(["Base UI: The `render` prop was provided an invalid React element as `React.isValidElement(render)` is `false`.", "A valid React element must be provided to the `render` prop because it is cloned with props to replace the default element.", "https://base-ui.com/r/invalid-render-prop"].join("\n"));
2122 }
2123 }
2124 return /* @__PURE__ */ React4.cloneElement(newElement, mergedProps);
2125 }
2126 if (element) {
2127 if (typeof element === "string") {
2128 return renderTag(element, props);
2129 }
2130 }
2131 throw new Error(true ? "Base UI: Render element or function are not defined." : formatErrorMessage_default(8));
2132 }
2133 function warnIfRenderPropLooksLikeComponent(renderFn) {
2134 const functionName = renderFn.name;
2135 if (functionName.length === 0) {
2136 return;
2137 }
2138 if (!COMPONENT_IDENTIFIER_PATTERN.test(functionName)) {
2139 return;
2140 }
2141 if (!LOWERCASE_CHARACTER_PATTERN.test(functionName)) {
2142 return;
2143 }
2144 warn(`The \`render\` prop received a function named \`${functionName}\` that starts with an uppercase letter.`, "This usually means a React component was passed directly as `render={Component}`.", "Base UI calls `render` as a plain function, which can break the Rules of Hooks during reconciliation.", "If this is an intentional render callback, rename it to start with a lowercase letter.", "Use `render={<Component />}` or `render={(props) => <Component {...props} />}` instead.", "https://base-ui.com/r/invalid-render-prop");
2145 }
2146 function renderTag(Tag, props) {
2147 if (Tag === "button") {
2148 return /* @__PURE__ */ (0, import_react.createElement)("button", {
2149 type: "button",
2150 ...props,
2151 key: props.key
2152 });
2153 }
2154 if (Tag === "img") {
2155 return /* @__PURE__ */ (0, import_react.createElement)("img", {
2156 alt: "",
2157 ...props,
2158 key: props.key
2159 });
2160 }
2161 return /* @__PURE__ */ React4.createElement(Tag, props);
2162 }
2163
2164 // node_modules/@base-ui/react/esm/use-render/useRender.js
2165 function useRender(params) {
2166 return useRenderElement(params.defaultTagName ?? "div", params, params);
2167 }
2168
2169 // packages/ui/build-module/stack/stack.mjs
2170 var import_element2 = __toESM(require_element(), 1);
2171 if (typeof document !== "undefined" && true && !document.head.querySelector("style[data-wp-hash='b51ff41489']")) {
2172 const style = document.createElement("style");
2173 style.setAttribute("data-wp-hash", "b51ff41489");
2174 style.appendChild(document.createTextNode("@layer wp-ui-utilities, wp-ui-components, wp-ui-compositions, wp-ui-overrides;@layer wp-ui-components{._19ce0419607e1896__stack{display:flex}}"));
2175 document.head.appendChild(style);
2176 }
2177 var style_default = { "stack": "_19ce0419607e1896__stack" };
2178 var gapTokens = {
2179 xs: "var(--wpds-dimension-gap-xs, 4px)",
2180 sm: "var(--wpds-dimension-gap-sm, 8px)",
2181 md: "var(--wpds-dimension-gap-md, 12px)",
2182 lg: "var(--wpds-dimension-gap-lg, 16px)",
2183 xl: "var(--wpds-dimension-gap-xl, 24px)",
2184 "2xl": "var(--wpds-dimension-gap-2xl, 32px)",
2185 "3xl": "var(--wpds-dimension-gap-3xl, 40px)"
2186 };
2187 var Stack = (0, import_element2.forwardRef)(function Stack2({ direction, gap, align, justify, wrap, render: render4, ...props }, ref) {
2188 const style = {
2189 gap: gap && gapTokens[gap],
2190 alignItems: align,
2191 justifyContent: justify,
2192 flexDirection: direction,
2193 flexWrap: wrap
2194 };
2195 const element = useRender({
2196 render: render4,
2197 ref,
2198 props: mergeProps(props, { style, className: style_default.stack })
2199 });
2200 return element;
2201 });
2202
2203 // packages/ui/build-module/visually-hidden/visually-hidden.mjs
2204 var import_element3 = __toESM(require_element(), 1);
2205 if (typeof document !== "undefined" && true && !document.head.querySelector("style[data-wp-hash='c46e8cb841']")) {
2206 const style = document.createElement("style");
2207 style.setAttribute("data-wp-hash", "c46e8cb841");
2208 style.appendChild(document.createTextNode("@layer wp-ui-utilities, wp-ui-components, wp-ui-compositions, wp-ui-overrides;@layer wp-ui-components{.f37b9e2e191ebd66__visually-hidden{word-wrap:normal;border:0;clip-path:inset(50%);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;word-break:normal}}"));
2209 document.head.appendChild(style);
2210 }
2211 var style_default2 = { "visually-hidden": "f37b9e2e191ebd66__visually-hidden" };
2212 var VisuallyHidden = (0, import_element3.forwardRef)(
2213 function VisuallyHidden2({ render: render4, ...restProps }, ref) {
2214 const element = useRender({
2215 render: render4,
2216 ref,
2217 props: mergeProps(
2218 { className: style_default2["visually-hidden"] },
2219 restProps,
2220 {
2221 // @ts-expect-error Arbitrary data-* attributes aren't indexable on the typed div props. Kept hardcoded so consumers can't change or remove it.
2222 "data-visually-hidden": ""
2223 }
2224 )
2225 });
2226 return element;
2227 }
2228 );
2229
2230 // packages/dataviews/build-module/components/dataviews-context/index.mjs
2231 var import_element4 = __toESM(require_element(), 1);
2232
2233 // packages/dataviews/build-module/constants.mjs
2234 var import_i18n7 = __toESM(require_i18n(), 1);
2235 var OPERATOR_IS_ANY = "isAny";
2236 var OPERATOR_IS_NONE = "isNone";
2237 var OPERATOR_IS_ALL = "isAll";
2238 var OPERATOR_IS_NOT_ALL = "isNotAll";
2239 var OPERATOR_BETWEEN = "between";
2240 var OPERATOR_IN_THE_PAST = "inThePast";
2241 var OPERATOR_OVER = "over";
2242 var OPERATOR_IS = "is";
2243 var OPERATOR_IS_NOT = "isNot";
2244 var OPERATOR_LESS_THAN = "lessThan";
2245 var OPERATOR_GREATER_THAN = "greaterThan";
2246 var OPERATOR_LESS_THAN_OR_EQUAL = "lessThanOrEqual";
2247 var OPERATOR_GREATER_THAN_OR_EQUAL = "greaterThanOrEqual";
2248 var OPERATOR_BEFORE = "before";
2249 var OPERATOR_AFTER = "after";
2250 var OPERATOR_BEFORE_INC = "beforeInc";
2251 var OPERATOR_AFTER_INC = "afterInc";
2252 var OPERATOR_CONTAINS = "contains";
2253 var OPERATOR_NOT_CONTAINS = "notContains";
2254 var OPERATOR_STARTS_WITH = "startsWith";
2255 var OPERATOR_ON = "on";
2256 var OPERATOR_NOT_ON = "notOn";
2257 var SORTING_DIRECTIONS = ["asc", "desc"];
2258 var sortArrows = { asc: "\u2191", desc: "\u2193" };
2259 var sortValues = { asc: "ascending", desc: "descending" };
2260 var sortLabels = {
2261 asc: (0, import_i18n7.__)("Sort ascending"),
2262 desc: (0, import_i18n7.__)("Sort descending")
2263 };
2264 var sortIcons = {
2265 asc: arrow_up_default,
2266 desc: arrow_down_default
2267 };
2268 var LAYOUT_TABLE = "table";
2269 var LAYOUT_GRID = "grid";
2270 var LAYOUT_LIST = "list";
2271 var LAYOUT_ACTIVITY = "activity";
2272 var LAYOUT_PICKER_GRID = "pickerGrid";
2273 var LAYOUT_PICKER_TABLE = "pickerTable";
2274
2275 // packages/dataviews/build-module/components/dataviews-context/index.mjs
2276 var DataViewsContext = (0, import_element4.createContext)({
2277 view: { type: LAYOUT_TABLE },
2278 onChangeView: () => {
2279 },
2280 fields: [],
2281 data: [],
2282 paginationInfo: {
2283 totalItems: 0,
2284 totalPages: 0
2285 },
2286 selection: [],
2287 onChangeSelection: () => {
2288 },
2289 setOpenedFilter: () => {
2290 },
2291 openedFilter: null,
2292 getItemId: (item) => item.id,
2293 isItemClickable: () => true,
2294 renderItemLink: void 0,
2295 containerWidth: 0,
2296 containerRef: (0, import_element4.createRef)(),
2297 resizeObserverRef: () => {
2298 },
2299 defaultLayouts: { list: {}, grid: {}, table: {} },
2300 filters: [],
2301 isShowingFilter: false,
2302 setIsShowingFilter: () => {
2303 },
2304 hasInitiallyLoaded: false,
2305 config: {
2306 perPageSizes: []
2307 },
2308 intersectionObserver: null
2309 });
2310 DataViewsContext.displayName = "DataViewsContext";
2311 var dataviews_context_default = DataViewsContext;
2312
2313 // packages/dataviews/build-module/components/dataviews-layouts/index.mjs
2314 var import_i18n27 = __toESM(require_i18n(), 1);
2315
2316 // packages/dataviews/build-module/components/dataviews-layouts/table/index.mjs
2317 var import_i18n15 = __toESM(require_i18n(), 1);
2318 var import_components6 = __toESM(require_components(), 1);
2319 var import_element12 = __toESM(require_element(), 1);
2320 var import_keycodes = __toESM(require_keycodes(), 1);
2321
2322 // packages/dataviews/build-module/components/dataviews-selection-checkbox/index.mjs
2323 var import_components = __toESM(require_components(), 1);
2324 var import_i18n8 = __toESM(require_i18n(), 1);
2325 var import_jsx_runtime31 = __toESM(require_jsx_runtime(), 1);
2326 function DataViewsSelectionCheckbox({
2327 selection,
2328 onChangeSelection,
2329 item,
2330 getItemId,
2331 titleField,
2332 disabled,
2333 ...extraProps
2334 }) {
2335 const id = getItemId(item);
2336 const isInSelectionArray = selection.includes(id);
2337 const checked = !disabled && isInSelectionArray;
2338 const selectionLabel = titleField?.getValue?.({ item }) || (0, import_i18n8.__)("(no title)");
2339 return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2340 import_components.CheckboxControl,
2341 {
2342 className: "dataviews-selection-checkbox",
2343 "aria-label": selectionLabel,
2344 "aria-disabled": disabled,
2345 checked,
2346 onChange: () => {
2347 if (disabled) {
2348 return;
2349 }
2350 onChangeSelection(
2351 isInSelectionArray ? selection.filter((itemId) => id !== itemId) : [...selection, id]
2352 );
2353 },
2354 ...extraProps
2355 }
2356 );
2357 }
2358
2359 // packages/dataviews/build-module/components/dataviews-item-actions/index.mjs
2360 var import_components2 = __toESM(require_components(), 1);
2361 var import_i18n9 = __toESM(require_i18n(), 1);
2362 var import_element5 = __toESM(require_element(), 1);
2363 var import_data = __toESM(require_data(), 1);
2364 var import_compose = __toESM(require_compose(), 1);
2365
2366 // packages/dataviews/build-module/lock-unlock.mjs
2367 var import_private_apis = __toESM(require_private_apis(), 1);
2368 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
2369 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
2370 "@wordpress/dataviews"
2371 );
2372
2373 // packages/dataviews/build-module/components/dataviews-item-actions/index.mjs
2374 var import_jsx_runtime32 = __toESM(require_jsx_runtime(), 1);
2375 var { Menu, kebabCase } = unlock(import_components2.privateApis);
2376 function ButtonTrigger({
2377 action,
2378 onClick,
2379 items,
2380 variant
2381 }) {
2382 const label = typeof action.label === "string" ? action.label : action.label(items);
2383 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2384 import_components2.Button,
2385 {
2386 disabled: !!action.disabled,
2387 accessibleWhenDisabled: true,
2388 size: "compact",
2389 variant,
2390 onClick,
2391 children: label
2392 }
2393 );
2394 }
2395 function MenuItemTrigger({
2396 action,
2397 onClick,
2398 items
2399 }) {
2400 const label = typeof action.label === "string" ? action.label : action.label(items);
2401 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Menu.Item, { disabled: action.disabled, onClick, children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Menu.ItemLabel, { children: label }) });
2402 }
2403 function ActionModal({
2404 action,
2405 items,
2406 closeModal
2407 }) {
2408 const label = typeof action.label === "string" ? action.label : action.label(items);
2409 const modalHeader = typeof action.modalHeader === "function" ? action.modalHeader(items) : action.modalHeader;
2410 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2411 import_components2.Modal,
2412 {
2413 title: modalHeader || label,
2414 __experimentalHideHeader: !!action.hideModalHeader,
2415 onRequestClose: closeModal,
2416 focusOnMount: action.modalFocusOnMount ?? true,
2417 size: action.modalSize || "medium",
2418 overlayClassName: `dataviews-action-modal dataviews-action-modal__${kebabCase(
2419 action.id
2420 )}`,
2421 children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(action.RenderModal, { items, closeModal })
2422 }
2423 );
2424 }
2425 function ActionsMenuGroup({
2426 actions,
2427 item,
2428 registry,
2429 setActiveModalAction
2430 }) {
2431 const { primaryActions, regularActions } = (0, import_element5.useMemo)(() => {
2432 return actions.reduce(
2433 (acc, action) => {
2434 (action.isPrimary ? acc.primaryActions : acc.regularActions).push(action);
2435 return acc;
2436 },
2437 {
2438 primaryActions: [],
2439 regularActions: []
2440 }
2441 );
2442 }, [actions]);
2443 const renderActionGroup = (actionList) => actionList.map((action) => /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2444 MenuItemTrigger,
2445 {
2446 action,
2447 onClick: () => {
2448 if ("RenderModal" in action) {
2449 setActiveModalAction(action);
2450 return;
2451 }
2452 action.callback([item], { registry });
2453 },
2454 items: [item]
2455 },
2456 action.id
2457 ));
2458 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(Menu.Group, { children: [
2459 renderActionGroup(primaryActions),
2460 renderActionGroup(regularActions)
2461 ] });
2462 }
2463 function ItemActions({
2464 item,
2465 actions,
2466 isCompact
2467 }) {
2468 const registry = (0, import_data.useRegistry)();
2469 const { primaryActions, eligibleActions } = (0, import_element5.useMemo)(() => {
2470 const _eligibleActions = actions.filter(
2471 (action) => !action.isEligible || action.isEligible(item)
2472 );
2473 const _primaryActions = _eligibleActions.filter(
2474 (action) => action.isPrimary
2475 );
2476 return {
2477 primaryActions: _primaryActions,
2478 eligibleActions: _eligibleActions
2479 };
2480 }, [actions, item]);
2481 const isMobileViewport = (0, import_compose.useViewportMatch)("medium", "<");
2482 if (isCompact) {
2483 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2484 CompactItemActions,
2485 {
2486 item,
2487 actions: eligibleActions,
2488 isSmall: true,
2489 registry
2490 }
2491 );
2492 }
2493 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(
2494 Stack,
2495 {
2496 direction: "row",
2497 justify: "flex-end",
2498 className: "dataviews-item-actions",
2499 style: {
2500 flexShrink: 0,
2501 width: "auto"
2502 },
2503 children: [
2504 /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2505 PrimaryActions,
2506 {
2507 item,
2508 actions: primaryActions,
2509 registry
2510 }
2511 ),
2512 (primaryActions.length < eligibleActions.length || // Since we hide primary actions on mobile, we need to show the menu
2513 // there if there are any actions at all.
2514 isMobileViewport) && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2515 CompactItemActions,
2516 {
2517 item,
2518 actions: eligibleActions,
2519 registry
2520 }
2521 )
2522 ]
2523 }
2524 );
2525 }
2526 function CompactItemActions({
2527 item,
2528 actions,
2529 isSmall,
2530 registry
2531 }) {
2532 const [activeModalAction, setActiveModalAction] = (0, import_element5.useState)(
2533 null
2534 );
2535 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(import_jsx_runtime32.Fragment, { children: [
2536 /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(Menu, { placement: "bottom-end", children: [
2537 /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2538 Menu.TriggerButton,
2539 {
2540 render: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2541 import_components2.Button,
2542 {
2543 size: isSmall ? "small" : "compact",
2544 icon: more_vertical_default,
2545 label: (0, import_i18n9.__)("Actions"),
2546 accessibleWhenDisabled: true,
2547 disabled: !actions.length,
2548 className: "dataviews-all-actions-button"
2549 }
2550 )
2551 }
2552 ),
2553 /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Menu.Popover, { children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2554 ActionsMenuGroup,
2555 {
2556 actions,
2557 item,
2558 registry,
2559 setActiveModalAction
2560 }
2561 ) })
2562 ] }),
2563 !!activeModalAction && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2564 ActionModal,
2565 {
2566 action: activeModalAction,
2567 items: [item],
2568 closeModal: () => setActiveModalAction(null)
2569 }
2570 )
2571 ] });
2572 }
2573 function PrimaryActions({
2574 item,
2575 actions,
2576 registry,
2577 buttonVariant
2578 }) {
2579 const [activeModalAction, setActiveModalAction] = (0, import_element5.useState)(null);
2580 const isMobileViewport = (0, import_compose.useViewportMatch)("medium", "<");
2581 if (isMobileViewport) {
2582 return null;
2583 }
2584 if (!Array.isArray(actions) || actions.length === 0) {
2585 return null;
2586 }
2587 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(import_jsx_runtime32.Fragment, { children: [
2588 actions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2589 ButtonTrigger,
2590 {
2591 action,
2592 onClick: () => {
2593 if ("RenderModal" in action) {
2594 setActiveModalAction(action);
2595 return;
2596 }
2597 action.callback([item], { registry });
2598 },
2599 items: [item],
2600 variant: buttonVariant
2601 },
2602 action.id
2603 )),
2604 !!activeModalAction && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2605 ActionModal,
2606 {
2607 action: activeModalAction,
2608 items: [item],
2609 closeModal: () => setActiveModalAction(null)
2610 }
2611 )
2612 ] });
2613 }
2614
2615 // packages/dataviews/build-module/components/dataviews-bulk-actions/index.mjs
2616 var import_components3 = __toESM(require_components(), 1);
2617 var import_i18n11 = __toESM(require_i18n(), 1);
2618 var import_element6 = __toESM(require_element(), 1);
2619 var import_data2 = __toESM(require_data(), 1);
2620 var import_compose2 = __toESM(require_compose(), 1);
2621
2622 // packages/dataviews/build-module/utils/get-footer-message.mjs
2623 var import_i18n10 = __toESM(require_i18n(), 1);
2624 function getFooterMessage(selectionCount, itemsCount, totalItems, onlyTotalCount = false) {
2625 if (selectionCount > 0) {
2626 return (0, import_i18n10.sprintf)(
2627 /* translators: %d: number of items. */
2628 (0, import_i18n10._n)("%d Item selected", "%d Items selected", selectionCount),
2629 selectionCount
2630 );
2631 }
2632 if (onlyTotalCount || totalItems <= itemsCount) {
2633 return (0, import_i18n10.sprintf)(
2634 /* translators: %d: number of items. */
2635 (0, import_i18n10._n)("%d Item", "%d Items", totalItems),
2636 totalItems
2637 );
2638 }
2639 return (0, import_i18n10.sprintf)(
2640 /* translators: %1$d: number of items. %2$d: total number of items. */
2641 (0, import_i18n10._n)("%1$d of %2$d Item", "%1$d of %2$d Items", totalItems),
2642 itemsCount,
2643 totalItems
2644 );
2645 }
2646
2647 // packages/dataviews/build-module/components/dataviews-bulk-actions/index.mjs
2648 var import_jsx_runtime33 = __toESM(require_jsx_runtime(), 1);
2649 function useHasAPossibleBulkAction(actions, item) {
2650 return (0, import_element6.useMemo)(() => {
2651 return actions.some((action) => {
2652 return action.supportsBulk && (!action.isEligible || action.isEligible(item));
2653 });
2654 }, [actions, item]);
2655 }
2656 function useSomeItemHasAPossibleBulkAction(actions, data) {
2657 return (0, import_element6.useMemo)(() => {
2658 return data.some((item) => {
2659 return actions.some((action) => {
2660 return action.supportsBulk && (!action.isEligible || action.isEligible(item));
2661 });
2662 });
2663 }, [actions, data]);
2664 }
2665 function BulkSelectionCheckbox({
2666 selection,
2667 onChangeSelection,
2668 data,
2669 actions,
2670 getItemId,
2671 disableSelectAll = false
2672 }) {
2673 const selectableItems = (0, import_element6.useMemo)(() => {
2674 return data.filter((item) => {
2675 return actions.some(
2676 (action) => action.supportsBulk && (!action.isEligible || action.isEligible(item))
2677 );
2678 });
2679 }, [data, actions]);
2680 const selectedItems = data.filter(
2681 (item) => selection.includes(getItemId(item)) && selectableItems.includes(item)
2682 );
2683 const hasSelection = selection.length > 0;
2684 const areAllSelected = selectedItems.length === selectableItems.length;
2685 if (disableSelectAll) {
2686 return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2687 import_components3.CheckboxControl,
2688 {
2689 className: "dataviews-view-table-selection-checkbox",
2690 checked: hasSelection,
2691 disabled: !hasSelection,
2692 onChange: () => {
2693 onChangeSelection([]);
2694 },
2695 "aria-label": (0, import_i18n11.__)("Deselect all")
2696 }
2697 );
2698 }
2699 return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2700 import_components3.CheckboxControl,
2701 {
2702 className: "dataviews-view-table-selection-checkbox",
2703 checked: areAllSelected,
2704 indeterminate: !areAllSelected && !!selectedItems.length,
2705 onChange: () => {
2706 if (areAllSelected) {
2707 onChangeSelection([]);
2708 } else {
2709 onChangeSelection(
2710 selectableItems.map((item) => getItemId(item))
2711 );
2712 }
2713 },
2714 "aria-label": areAllSelected ? (0, import_i18n11.__)("Deselect all") : (0, import_i18n11.__)("Select all")
2715 }
2716 );
2717 }
2718
2719 // packages/dataviews/build-module/components/dataviews-layouts/table/column-header-menu.mjs
2720 var import_i18n12 = __toESM(require_i18n(), 1);
2721 var import_components4 = __toESM(require_components(), 1);
2722 var import_element7 = __toESM(require_element(), 1);
2723
2724 // packages/dataviews/build-module/utils/get-hideable-fields.mjs
2725 function getHideableFields(view, fields) {
2726 const togglableFields = [
2727 view?.titleField,
2728 view?.mediaField,
2729 view?.descriptionField
2730 ].filter(Boolean);
2731 return fields.filter(
2732 (f2) => !togglableFields.includes(f2.id) && f2.type !== "media" && f2.enableHiding !== false
2733 );
2734 }
2735
2736 // packages/dataviews/build-module/components/dataviews-layouts/table/column-header-menu.mjs
2737 var import_jsx_runtime34 = __toESM(require_jsx_runtime(), 1);
2738 var { Menu: Menu2 } = unlock(import_components4.privateApis);
2739 function WithMenuSeparators({ children }) {
2740 return import_element7.Children.toArray(children).filter(Boolean).map((child, i2) => /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_element7.Fragment, { children: [
2741 i2 > 0 && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Separator, {}),
2742 child
2743 ] }, i2));
2744 }
2745 var _HeaderMenu = (0, import_element7.forwardRef)(function HeaderMenu({
2746 fieldId,
2747 view,
2748 fields,
2749 onChangeView,
2750 onHide,
2751 setOpenedFilter,
2752 canMove = true,
2753 canInsertLeft = true,
2754 canInsertRight = true
2755 }, ref) {
2756 const visibleFieldIds = view.fields ?? [];
2757 const index = visibleFieldIds?.indexOf(fieldId);
2758 const isSorted = view.sort?.field === fieldId;
2759 let isHidable = false;
2760 let isSortable = false;
2761 let canAddFilter = false;
2762 let operators = [];
2763 const field = fields.find((f2) => f2.id === fieldId);
2764 const { setIsShowingFilter } = (0, import_element7.useContext)(dataviews_context_default);
2765 if (!field) {
2766 return null;
2767 }
2768 isHidable = field.enableHiding !== false;
2769 isSortable = field.enableSorting !== false;
2770 const header = field.header;
2771 operators = !!field.filterBy && field.filterBy?.operators || [];
2772 canAddFilter = !view.filters?.some((_filter) => fieldId === _filter.field) && !!(field.hasElements || field.Edit) && field.filterBy !== false && !field.filterBy?.isPrimary;
2773 if (!isSortable && !canMove && !isHidable && !canAddFilter) {
2774 return header;
2775 }
2776 const hiddenFields = getHideableFields(view, fields).filter(
2777 (f2) => !visibleFieldIds.includes(f2.id)
2778 );
2779 const canInsert = (canInsertLeft || canInsertRight) && !!hiddenFields.length;
2780 const isRtl = (0, import_i18n12.isRTL)();
2781 return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2, { children: [
2782 /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
2783 Menu2.TriggerButton,
2784 {
2785 render: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2786 import_components4.Button,
2787 {
2788 size: "compact",
2789 className: "dataviews-view-table-header-button",
2790 ref,
2791 variant: "tertiary"
2792 }
2793 ),
2794 children: [
2795 header,
2796 view.sort && isSorted && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("span", { "aria-hidden": "true", children: sortArrows[view.sort.direction] })
2797 ]
2798 }
2799 ),
2800 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Popover, { style: { minWidth: "240px" }, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(WithMenuSeparators, { children: [
2801 isSortable && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Group, { children: SORTING_DIRECTIONS.map(
2802 (direction) => {
2803 const isChecked = view.sort && isSorted && view.sort.direction === direction;
2804 const value = `${fieldId}-${direction}`;
2805 return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2806 Menu2.RadioItem,
2807 {
2808 name: "view-table-sorting",
2809 value,
2810 checked: isChecked,
2811 onChange: () => {
2812 onChangeView({
2813 ...view,
2814 sort: {
2815 field: fieldId,
2816 direction
2817 },
2818 showLevels: false
2819 });
2820 },
2821 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: sortLabels[direction] })
2822 },
2823 value
2824 );
2825 }
2826 ) }),
2827 canAddFilter && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Group, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2828 Menu2.Item,
2829 {
2830 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: funnel_default }),
2831 onClick: () => {
2832 setOpenedFilter(fieldId);
2833 setIsShowingFilter(true);
2834 onChangeView({
2835 ...view,
2836 page: 1,
2837 filters: [
2838 ...view.filters || [],
2839 {
2840 field: fieldId,
2841 value: void 0,
2842 operator: operators[0]
2843 }
2844 ]
2845 });
2846 },
2847 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Add filter") })
2848 }
2849 ) }),
2850 (canMove || isHidable || canInsert) && field && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2.Group, { children: [
2851 canMove && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2852 Menu2.Item,
2853 {
2854 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: arrow_left_default }),
2855 disabled: isRtl ? index >= visibleFieldIds.length - 1 : index < 1,
2856 onClick: () => {
2857 const targetIndex = isRtl ? index + 1 : index - 1;
2858 const newFields = [
2859 ...visibleFieldIds
2860 ];
2861 newFields.splice(index, 1);
2862 newFields.splice(
2863 targetIndex,
2864 0,
2865 fieldId
2866 );
2867 onChangeView({
2868 ...view,
2869 fields: newFields
2870 });
2871 },
2872 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Move left") })
2873 }
2874 ),
2875 canMove && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2876 Menu2.Item,
2877 {
2878 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: arrow_right_default }),
2879 disabled: isRtl ? index < 1 : index >= visibleFieldIds.length - 1,
2880 onClick: () => {
2881 const targetIndex = isRtl ? index - 1 : index + 1;
2882 const newFields = [
2883 ...visibleFieldIds
2884 ];
2885 newFields.splice(index, 1);
2886 newFields.splice(
2887 targetIndex,
2888 0,
2889 fieldId
2890 );
2891 onChangeView({
2892 ...view,
2893 fields: newFields
2894 });
2895 },
2896 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Move right") })
2897 }
2898 ),
2899 canInsertLeft && !!hiddenFields.length && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2, { children: [
2900 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.SubmenuTriggerItem, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Insert left") }) }),
2901 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Popover, { children: hiddenFields.map((hiddenField) => {
2902 const insertIndex = isRtl ? index + 1 : index;
2903 return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2904 Menu2.Item,
2905 {
2906 onClick: () => {
2907 onChangeView({
2908 ...view,
2909 fields: [
2910 ...visibleFieldIds.slice(
2911 0,
2912 insertIndex
2913 ),
2914 hiddenField.id,
2915 ...visibleFieldIds.slice(
2916 insertIndex
2917 )
2918 ]
2919 });
2920 },
2921 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: hiddenField.label })
2922 },
2923 hiddenField.id
2924 );
2925 }) })
2926 ] }),
2927 canInsertRight && !!hiddenFields.length && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2, { children: [
2928 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.SubmenuTriggerItem, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Insert right") }) }),
2929 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Popover, { children: hiddenFields.map((hiddenField) => {
2930 const insertIndex = isRtl ? index : index + 1;
2931 return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2932 Menu2.Item,
2933 {
2934 onClick: () => {
2935 onChangeView({
2936 ...view,
2937 fields: [
2938 ...visibleFieldIds.slice(
2939 0,
2940 insertIndex
2941 ),
2942 hiddenField.id,
2943 ...visibleFieldIds.slice(
2944 insertIndex
2945 )
2946 ]
2947 });
2948 },
2949 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: hiddenField.label })
2950 },
2951 hiddenField.id
2952 );
2953 }) })
2954 ] }),
2955 isHidable && field && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2956 Menu2.Item,
2957 {
2958 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: unseen_default }),
2959 onClick: () => {
2960 onHide(field);
2961 onChangeView({
2962 ...view,
2963 fields: visibleFieldIds.filter(
2964 (id) => id !== fieldId
2965 )
2966 });
2967 },
2968 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Hide column") })
2969 }
2970 )
2971 ] })
2972 ] }) })
2973 ] });
2974 });
2975 var ColumnHeaderMenu = _HeaderMenu;
2976 var column_header_menu_default = ColumnHeaderMenu;
2977
2978 // packages/dataviews/build-module/components/dataviews-layouts/utils/item-click-wrapper.mjs
2979 var import_element8 = __toESM(require_element(), 1);
2980 var import_jsx_runtime35 = __toESM(require_jsx_runtime(), 1);
2981 function getClickableItemProps({
2982 item,
2983 isItemClickable: isItemClickable2,
2984 onClickItem,
2985 className
2986 }) {
2987 if (!isItemClickable2(item) || !onClickItem) {
2988 return { className };
2989 }
2990 return {
2991 className: className ? `${className} ${className}--clickable` : void 0,
2992 role: "button",
2993 tabIndex: 0,
2994 onClick: (event) => {
2995 event.stopPropagation();
2996 onClickItem(item);
2997 },
2998 onKeyDown: (event) => {
2999 if (event.key === "Enter" || event.key === "" || event.key === " ") {
3000 event.stopPropagation();
3001 onClickItem(item);
3002 }
3003 }
3004 };
3005 }
3006 function ItemClickWrapper({
3007 item,
3008 isItemClickable: isItemClickable2,
3009 onClickItem,
3010 renderItemLink,
3011 className,
3012 children,
3013 ...extraProps
3014 }) {
3015 if (!isItemClickable2(item)) {
3016 return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className, ...extraProps, children });
3017 }
3018 if (renderItemLink) {
3019 const renderedElement = renderItemLink({
3020 item,
3021 className: `${className} ${className}--clickable`,
3022 ...extraProps,
3023 children
3024 });
3025 return (0, import_element8.cloneElement)(renderedElement, {
3026 onClick: (event) => {
3027 event.stopPropagation();
3028 if (renderedElement.props.onClick) {
3029 renderedElement.props.onClick(event);
3030 }
3031 },
3032 onKeyDown: (event) => {
3033 if (event.key === "Enter" || event.key === "" || event.key === " ") {
3034 event.stopPropagation();
3035 if (renderedElement.props.onKeyDown) {
3036 renderedElement.props.onKeyDown(event);
3037 }
3038 }
3039 }
3040 });
3041 }
3042 const clickProps = getClickableItemProps({
3043 item,
3044 isItemClickable: isItemClickable2,
3045 onClickItem,
3046 className
3047 });
3048 return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { ...clickProps, ...extraProps, children });
3049 }
3050
3051 // packages/dataviews/build-module/components/dataviews-layouts/table/column-primary.mjs
3052 var import_jsx_runtime36 = __toESM(require_jsx_runtime(), 1);
3053 function ColumnPrimary({
3054 item,
3055 level,
3056 titleField,
3057 mediaField,
3058 descriptionField: descriptionField2,
3059 onClickItem,
3060 renderItemLink,
3061 isItemClickable: isItemClickable2
3062 }) {
3063 return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(Stack, { direction: "row", gap: "md", align: "flex-start", justify: "flex-start", children: [
3064 mediaField && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3065 ItemClickWrapper,
3066 {
3067 item,
3068 isItemClickable: isItemClickable2,
3069 onClickItem,
3070 renderItemLink,
3071 className: "dataviews-view-table__cell-content-wrapper dataviews-column-primary__media",
3072 "aria-label": isItemClickable2(item) && (!!onClickItem || !!renderItemLink) && !!titleField ? titleField.getValue?.({ item }) : void 0,
3073 children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3074 mediaField.render,
3075 {
3076 item,
3077 field: mediaField,
3078 config: { sizes: "32px" }
3079 }
3080 )
3081 }
3082 ),
3083 /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
3084 Stack,
3085 {
3086 direction: "column",
3087 align: "flex-start",
3088 className: "dataviews-view-table__primary-column-content",
3089 children: [
3090 titleField && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
3091 ItemClickWrapper,
3092 {
3093 item,
3094 isItemClickable: isItemClickable2,
3095 onClickItem,
3096 renderItemLink,
3097 className: "dataviews-view-table__cell-content-wrapper dataviews-title-field",
3098 children: [
3099 level !== void 0 && level > 0 && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("span", { className: "dataviews-view-table__level", children: [
3100 Array(level).fill("\u2014").join(" "),
3101 "\xA0"
3102 ] }),
3103 /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(titleField.render, { item, field: titleField })
3104 ]
3105 }
3106 ),
3107 descriptionField2 && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3108 descriptionField2.render,
3109 {
3110 item,
3111 field: descriptionField2
3112 }
3113 )
3114 ]
3115 }
3116 )
3117 ] });
3118 }
3119 var column_primary_default = ColumnPrimary;
3120
3121 // packages/dataviews/build-module/components/dataviews-layouts/table/use-scroll-state.mjs
3122 var import_element9 = __toESM(require_element(), 1);
3123 var import_i18n13 = __toESM(require_i18n(), 1);
3124 var isScrolledToEnd = (element) => {
3125 if ((0, import_i18n13.isRTL)()) {
3126 const scrollLeft = Math.abs(element.scrollLeft);
3127 return scrollLeft <= 1;
3128 }
3129 return element.scrollLeft + element.clientWidth >= element.scrollWidth - 1;
3130 };
3131 function useScrollState({
3132 scrollContainerRef,
3133 enabledHorizontal = false
3134 }) {
3135 const [isHorizontalScrollEnd, setIsHorizontalScrollEnd] = (0, import_element9.useState)(false);
3136 const [isVerticallyScrolled, setIsVerticallyScrolled] = (0, import_element9.useState)(false);
3137 const handleScroll = (0, import_element9.useCallback)(() => {
3138 const scrollContainer = scrollContainerRef.current;
3139 if (!scrollContainer) {
3140 return;
3141 }
3142 if (enabledHorizontal) {
3143 setIsHorizontalScrollEnd(isScrolledToEnd(scrollContainer));
3144 }
3145 setIsVerticallyScrolled(scrollContainer.scrollTop > 0);
3146 }, [scrollContainerRef, enabledHorizontal]);
3147 (0, import_element9.useEffect)(() => {
3148 if (typeof window === "undefined" || !scrollContainerRef.current) {
3149 return () => {
3150 };
3151 }
3152 const scrollContainer = scrollContainerRef.current;
3153 handleScroll();
3154 scrollContainer.addEventListener("scroll", handleScroll);
3155 window.addEventListener("resize", handleScroll);
3156 return () => {
3157 scrollContainer.removeEventListener("scroll", handleScroll);
3158 window.removeEventListener("resize", handleScroll);
3159 };
3160 }, [scrollContainerRef, enabledHorizontal, handleScroll]);
3161 return { isHorizontalScrollEnd, isVerticallyScrolled };
3162 }
3163
3164 // packages/dataviews/build-module/components/dataviews-layouts/utils/get-data-by-group.mjs
3165 function getDataByGroup(data, groupByField) {
3166 return data.reduce((groups, item) => {
3167 const groupName = groupByField.getValue({ item });
3168 if (!groups.has(groupName)) {
3169 groups.set(groupName, []);
3170 }
3171 groups.get(groupName)?.push(item);
3172 return groups;
3173 }, /* @__PURE__ */ new Map());
3174 }
3175
3176 // packages/dataviews/build-module/components/dataviews-view-config/properties-section.mjs
3177 var import_components5 = __toESM(require_components(), 1);
3178 var import_i18n14 = __toESM(require_i18n(), 1);
3179 var import_element10 = __toESM(require_element(), 1);
3180 var import_jsx_runtime37 = __toESM(require_jsx_runtime(), 1);
3181 function FieldItem({
3182 field,
3183 isVisible: isVisible2,
3184 onToggleVisibility
3185 }) {
3186 return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_components5.__experimentalItem, { onClick: field.enableHiding ? onToggleVisibility : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(Stack, { direction: "row", gap: "sm", justify: "flex-start", align: "center", children: [
3187 /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { style: { height: 24, width: 24 }, children: isVisible2 && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_components5.Icon, { icon: check_default }) }),
3188 /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("span", { className: "dataviews-view-config__label", children: field.label })
3189 ] }) });
3190 }
3191 function isDefined(item) {
3192 return !!item;
3193 }
3194 function PropertiesSection({
3195 showLabel = true
3196 }) {
3197 const { view, fields, onChangeView } = (0, import_element10.useContext)(dataviews_context_default);
3198 const regularFields = getHideableFields(view, fields);
3199 if (!regularFields?.length) {
3200 return null;
3201 }
3202 const titleField = fields.find((f2) => f2.id === view.titleField);
3203 const previewField = fields.find((f2) => f2.id === view.mediaField);
3204 const descriptionField2 = fields.find(
3205 (f2) => f2.id === view.descriptionField
3206 );
3207 const lockedFields = [
3208 {
3209 field: titleField,
3210 isVisibleFlag: "showTitle"
3211 },
3212 {
3213 field: previewField,
3214 isVisibleFlag: "showMedia"
3215 },
3216 {
3217 field: descriptionField2,
3218 isVisibleFlag: "showDescription"
3219 }
3220 ].filter(({ field }) => isDefined(field));
3221 const visibleFieldIds = view.fields ?? [];
3222 const visibleRegularFieldsCount = regularFields.filter(
3223 (f2) => visibleFieldIds.includes(f2.id)
3224 ).length;
3225 const visibleLockedFields = lockedFields.filter(
3226 ({ isVisibleFlag }) => (
3227 // @ts-expect-error
3228 view[isVisibleFlag] ?? true
3229 )
3230 );
3231 const totalVisibleFields = visibleLockedFields.length + visibleRegularFieldsCount;
3232 const isSingleVisibleLockedField = totalVisibleFields === 1 && visibleLockedFields.length === 1;
3233 return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(Stack, { direction: "column", className: "dataviews-field-control", children: [
3234 showLabel && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_components5.BaseControl.VisualLabel, { children: (0, import_i18n14.__)("Properties") }),
3235 /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3236 Stack,
3237 {
3238 direction: "column",
3239 className: "dataviews-view-config__properties",
3240 children: /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(import_components5.__experimentalItemGroup, { isBordered: true, isSeparated: true, size: "medium", children: [
3241 lockedFields.map(({ field, isVisibleFlag }) => {
3242 const isVisible2 = view[isVisibleFlag] ?? true;
3243 const fieldToRender = isSingleVisibleLockedField && isVisible2 ? { ...field, enableHiding: false } : field;
3244 return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3245 FieldItem,
3246 {
3247 field: fieldToRender,
3248 isVisible: isVisible2,
3249 onToggleVisibility: () => {
3250 onChangeView({
3251 ...view,
3252 [isVisibleFlag]: !isVisible2
3253 });
3254 }
3255 },
3256 field.id
3257 );
3258 }),
3259 regularFields.map((field) => {
3260 const isVisible2 = visibleFieldIds.includes(field.id);
3261 const fieldToRender = totalVisibleFields === 1 && isVisible2 ? { ...field, enableHiding: false } : field;
3262 return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3263 FieldItem,
3264 {
3265 field: fieldToRender,
3266 isVisible: isVisible2,
3267 onToggleVisibility: () => {
3268 onChangeView({
3269 ...view,
3270 fields: isVisible2 ? visibleFieldIds.filter(
3271 (fieldId) => fieldId !== field.id
3272 ) : [...visibleFieldIds, field.id]
3273 });
3274 }
3275 },
3276 field.id
3277 );
3278 })
3279 ] })
3280 }
3281 )
3282 ] });
3283 }
3284
3285 // packages/dataviews/build-module/hooks/use-delayed-loading.mjs
3286 var import_element11 = __toESM(require_element(), 1);
3287 function useDelayedLoading(isLoading, options = { delay: 400 }) {
3288 const [showLoader, setShowLoader] = (0, import_element11.useState)(false);
3289 (0, import_element11.useEffect)(() => {
3290 if (!isLoading) {
3291 return;
3292 }
3293 const timeout = setTimeout(() => {
3294 setShowLoader(true);
3295 }, options.delay);
3296 return () => {
3297 clearTimeout(timeout);
3298 setShowLoader(false);
3299 };
3300 }, [isLoading, options.delay]);
3301 return showLoader;
3302 }
3303
3304 // packages/dataviews/build-module/components/dataviews-layouts/table/index.mjs
3305 var import_jsx_runtime38 = __toESM(require_jsx_runtime(), 1);
3306 function getEffectiveAlign(explicitAlign, fieldType) {
3307 if (explicitAlign) {
3308 return explicitAlign;
3309 }
3310 if (fieldType === "integer" || fieldType === "number") {
3311 return "end";
3312 }
3313 return void 0;
3314 }
3315 function TableColumnField({
3316 item,
3317 fields,
3318 column,
3319 align
3320 }) {
3321 const field = fields.find((f2) => f2.id === column);
3322 if (!field) {
3323 return null;
3324 }
3325 const className = clsx_default("dataviews-view-table__cell-content-wrapper", {
3326 "dataviews-view-table__cell-align-end": align === "end",
3327 "dataviews-view-table__cell-align-center": align === "center"
3328 });
3329 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(field.render, { item, field }) });
3330 }
3331 function TableRow({
3332 hasBulkActions,
3333 item,
3334 level,
3335 actions,
3336 fields,
3337 id,
3338 view,
3339 titleField,
3340 mediaField,
3341 descriptionField: descriptionField2,
3342 selection,
3343 getItemId,
3344 isItemClickable: isItemClickable2,
3345 onClickItem,
3346 renderItemLink,
3347 onChangeSelection,
3348 isActionsColumnSticky,
3349 posinset
3350 }) {
3351 const { paginationInfo } = (0, import_element12.useContext)(dataviews_context_default);
3352 const hasPossibleBulkAction = useHasAPossibleBulkAction(actions, item);
3353 const isSelected2 = hasPossibleBulkAction && selection.includes(id);
3354 const {
3355 showTitle = true,
3356 showMedia = true,
3357 showDescription = true,
3358 infiniteScrollEnabled
3359 } = view;
3360 const isTouchDeviceRef = (0, import_element12.useRef)(false);
3361 const columns = view.fields ?? [];
3362 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
3363 return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
3364 "tr",
3365 {
3366 className: clsx_default("dataviews-view-table__row", {
3367 "is-selected": hasPossibleBulkAction && isSelected2,
3368 "has-bulk-actions": hasPossibleBulkAction
3369 }),
3370 onTouchStart: () => {
3371 isTouchDeviceRef.current = true;
3372 },
3373 "aria-setsize": infiniteScrollEnabled ? paginationInfo.totalItems : void 0,
3374 "aria-posinset": posinset,
3375 role: infiniteScrollEnabled ? "article" : void 0,
3376 onMouseDown: (event) => {
3377 const isMetaClick = (0, import_keycodes.isAppleOS)() ? event.metaKey : event.ctrlKey;
3378 if (event.button === 0 && isMetaClick && window.navigator.userAgent.toLowerCase().includes("firefox")) {
3379 event?.preventDefault();
3380 }
3381 },
3382 onClick: (event) => {
3383 if (!hasPossibleBulkAction) {
3384 return;
3385 }
3386 const isModifierKeyPressed = (0, import_keycodes.isAppleOS)() ? event.metaKey : event.ctrlKey;
3387 if (isModifierKeyPressed && !isTouchDeviceRef.current && document.getSelection()?.type !== "Range") {
3388 onChangeSelection(
3389 selection.includes(id) ? selection.filter((itemId) => id !== itemId) : [...selection, id]
3390 );
3391 }
3392 },
3393 children: [
3394 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("td", { className: "dataviews-view-table__checkbox-column", children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className: "dataviews-view-table__cell-content-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3395 DataViewsSelectionCheckbox,
3396 {
3397 item,
3398 selection,
3399 onChangeSelection,
3400 getItemId,
3401 titleField,
3402 disabled: !hasPossibleBulkAction
3403 }
3404 ) }) }),
3405 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3406 column_primary_default,
3407 {
3408 item,
3409 level,
3410 titleField: showTitle ? titleField : void 0,
3411 mediaField: showMedia ? mediaField : void 0,
3412 descriptionField: showDescription ? descriptionField2 : void 0,
3413 isItemClickable: isItemClickable2,
3414 onClickItem,
3415 renderItemLink
3416 }
3417 ) }),
3418 columns.map((column) => {
3419 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
3420 const field = fields.find((f2) => f2.id === column);
3421 const effectiveAlign = getEffectiveAlign(align, field?.type);
3422 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3423 "td",
3424 {
3425 style: {
3426 width,
3427 maxWidth,
3428 minWidth
3429 },
3430 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3431 TableColumnField,
3432 {
3433 fields,
3434 item,
3435 column,
3436 align: effectiveAlign
3437 }
3438 )
3439 },
3440 column
3441 );
3442 }),
3443 !!actions?.length && // Disable reason: we are not making the element interactive,
3444 // but preventing any click events from bubbling up to the
3445 // table row. This allows us to add a click handler to the row
3446 // itself (to toggle row selection) without erroneously
3447 // intercepting click events from ItemActions.
3448 /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3449 "td",
3450 {
3451 className: clsx_default("dataviews-view-table__actions-column", {
3452 "dataviews-view-table__actions-column--sticky": true,
3453 "dataviews-view-table__actions-column--stuck": isActionsColumnSticky
3454 }),
3455 onClick: (e2) => e2.stopPropagation(),
3456 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(ItemActions, { item, actions })
3457 }
3458 )
3459 ]
3460 }
3461 );
3462 }
3463 function ViewTable({
3464 actions,
3465 data,
3466 fields,
3467 getItemId,
3468 getItemLevel,
3469 isLoading = false,
3470 onChangeView,
3471 onChangeSelection,
3472 selection,
3473 setOpenedFilter,
3474 onClickItem,
3475 isItemClickable: isItemClickable2,
3476 renderItemLink,
3477 view,
3478 className,
3479 empty
3480 }) {
3481 const { containerRef } = (0, import_element12.useContext)(dataviews_context_default);
3482 const isDelayedLoading = useDelayedLoading(isLoading);
3483 const headerMenuRefs = (0, import_element12.useRef)(/* @__PURE__ */ new Map());
3484 const headerMenuToFocusRef = (0, import_element12.useRef)(void 0);
3485 const [nextHeaderMenuToFocus, setNextHeaderMenuToFocus] = (0, import_element12.useState)();
3486 const [contextMenuAnchor, setContextMenuAnchor] = (0, import_element12.useState)(null);
3487 (0, import_element12.useEffect)(() => {
3488 if (headerMenuToFocusRef.current) {
3489 headerMenuToFocusRef.current.focus();
3490 headerMenuToFocusRef.current = void 0;
3491 }
3492 });
3493 const tableNoticeId = (0, import_element12.useId)();
3494 const { isHorizontalScrollEnd, isVerticallyScrolled } = useScrollState({
3495 scrollContainerRef: containerRef,
3496 enabledHorizontal: !!actions?.length
3497 });
3498 const hasBulkActions = useSomeItemHasAPossibleBulkAction(actions, data);
3499 if (nextHeaderMenuToFocus) {
3500 headerMenuToFocusRef.current = nextHeaderMenuToFocus;
3501 setNextHeaderMenuToFocus(void 0);
3502 return;
3503 }
3504 const onHide = (field) => {
3505 const hidden = headerMenuRefs.current.get(field.id);
3506 const fallback = hidden ? headerMenuRefs.current.get(hidden.fallback) : void 0;
3507 setNextHeaderMenuToFocus(fallback?.node);
3508 };
3509 const handleHeaderContextMenu = (event) => {
3510 event.preventDefault();
3511 event.stopPropagation();
3512 const virtualAnchor = {
3513 getBoundingClientRect: () => ({
3514 x: event.clientX,
3515 y: event.clientY,
3516 top: event.clientY,
3517 left: event.clientX,
3518 right: event.clientX,
3519 bottom: event.clientY,
3520 width: 0,
3521 height: 0,
3522 toJSON: () => ({})
3523 })
3524 };
3525 window.requestAnimationFrame(() => {
3526 setContextMenuAnchor(virtualAnchor);
3527 });
3528 };
3529 const hasData = !!data?.length;
3530 const titleField = fields.find((field) => field.id === view.titleField);
3531 const mediaField = fields.find((field) => field.id === view.mediaField);
3532 const descriptionField2 = fields.find(
3533 (field) => field.id === view.descriptionField
3534 );
3535 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
3536 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
3537 const { showTitle = true, showMedia = true, showDescription = true } = view;
3538 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
3539 const columns = view.fields ?? [];
3540 const headerMenuRef = (column, index) => (node) => {
3541 if (node) {
3542 headerMenuRefs.current.set(column, {
3543 node,
3544 fallback: columns[index > 0 ? index - 1 : 1]
3545 });
3546 } else {
3547 headerMenuRefs.current.delete(column);
3548 }
3549 };
3550 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
3551 const isRtl = (0, import_i18n15.isRTL)();
3552 if (!hasData) {
3553 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3554 "div",
3555 {
3556 className: clsx_default("dataviews-no-results", {
3557 "is-refreshing": isDelayedLoading
3558 }),
3559 id: tableNoticeId,
3560 children: empty
3561 }
3562 );
3563 }
3564 return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(import_jsx_runtime38.Fragment, { children: [
3565 /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
3566 "table",
3567 {
3568 className: clsx_default("dataviews-view-table", className, {
3569 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
3570 view.layout.density
3571 ),
3572 "has-bulk-actions": hasBulkActions,
3573 "is-refreshing": !isInfiniteScroll && isDelayedLoading
3574 }),
3575 "aria-busy": isLoading,
3576 "aria-describedby": tableNoticeId,
3577 role: isInfiniteScroll ? "feed" : void 0,
3578 inert: !isInfiniteScroll && isLoading ? "true" : void 0,
3579 children: [
3580 /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("colgroup", { children: [
3581 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("col", { className: "dataviews-view-table__col-checkbox" }),
3582 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("col", { className: "dataviews-view-table__col-first-data" }),
3583 columns.map((column, index) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3584 "col",
3585 {
3586 className: clsx_default(
3587 `dataviews-view-table__col-${column}`,
3588 {
3589 "dataviews-view-table__col-expand": !hasPrimaryColumn && index === columns.length - 1
3590 }
3591 )
3592 },
3593 `col-${column}`
3594 )),
3595 !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("col", { className: "dataviews-view-table__col-actions" })
3596 ] }),
3597 contextMenuAnchor && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3598 import_components6.Popover,
3599 {
3600 anchor: contextMenuAnchor,
3601 onClose: () => setContextMenuAnchor(null),
3602 placement: "bottom-start",
3603 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(PropertiesSection, { showLabel: false })
3604 }
3605 ),
3606 /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3607 "thead",
3608 {
3609 className: clsx_default({
3610 "dataviews-view-table__thead--stuck": isVerticallyScrolled
3611 }),
3612 onContextMenu: handleHeaderContextMenu,
3613 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("tr", { className: "dataviews-view-table__row", children: [
3614 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3615 "th",
3616 {
3617 className: "dataviews-view-table__checkbox-column",
3618 scope: "col",
3619 onContextMenu: handleHeaderContextMenu,
3620 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3621 BulkSelectionCheckbox,
3622 {
3623 selection,
3624 onChangeSelection,
3625 data,
3626 actions,
3627 getItemId
3628 }
3629 )
3630 }
3631 ),
3632 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("th", { scope: "col", children: titleField && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3633 column_header_menu_default,
3634 {
3635 ref: headerMenuRef(
3636 titleField.id,
3637 0
3638 ),
3639 fieldId: titleField.id,
3640 view,
3641 fields,
3642 onChangeView,
3643 onHide,
3644 setOpenedFilter,
3645 canMove: false,
3646 canInsertLeft: isRtl ? view.layout?.enableMoving ?? true : false,
3647 canInsertRight: isRtl ? false : view.layout?.enableMoving ?? true
3648 }
3649 ) }),
3650 columns.map((column, index) => {
3651 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
3652 const field = fields.find(
3653 (f2) => f2.id === column
3654 );
3655 const effectiveAlign = getEffectiveAlign(
3656 align,
3657 field?.type
3658 );
3659 const canInsertOrMove = view.layout?.enableMoving ?? true;
3660 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3661 "th",
3662 {
3663 style: {
3664 width,
3665 maxWidth,
3666 minWidth,
3667 textAlign: effectiveAlign
3668 },
3669 "aria-sort": view.sort?.direction && view.sort?.field === column ? sortValues[view.sort.direction] : void 0,
3670 scope: "col",
3671 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3672 column_header_menu_default,
3673 {
3674 ref: headerMenuRef(column, index),
3675 fieldId: column,
3676 view,
3677 fields,
3678 onChangeView,
3679 onHide,
3680 setOpenedFilter,
3681 canMove: canInsertOrMove,
3682 canInsertLeft: canInsertOrMove,
3683 canInsertRight: canInsertOrMove
3684 }
3685 )
3686 },
3687 column
3688 );
3689 }),
3690 !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3691 "th",
3692 {
3693 className: clsx_default(
3694 "dataviews-view-table__actions-column",
3695 {
3696 "dataviews-view-table__actions-column--sticky": true,
3697 "dataviews-view-table__actions-column--stuck": !isHorizontalScrollEnd
3698 }
3699 ),
3700 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("span", { className: "dataviews-view-table-header", children: (0, import_i18n15.__)("Actions") })
3701 }
3702 )
3703 ] })
3704 }
3705 ),
3706 hasData && groupField && dataByGroup ? Array.from(dataByGroup.entries()).map(
3707 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("tbody", { children: [
3708 /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("tr", { className: "dataviews-view-table__group-header-row", children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3709 "td",
3710 {
3711 colSpan: columns.length + (hasPrimaryColumn ? 1 : 0) + (hasBulkActions ? 1 : 0) + (actions?.length ? 1 : 0),
3712 className: "dataviews-view-table__group-header-cell",
3713 children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n15.sprintf)(
3714 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
3715 (0, import_i18n15.__)("%1$s: %2$s"),
3716 groupField.label,
3717 groupName
3718 )
3719 }
3720 ) }),
3721 groupItems.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3722 TableRow,
3723 {
3724 item,
3725 level: view.showLevels && typeof getItemLevel === "function" ? getItemLevel(item) : void 0,
3726 hasBulkActions,
3727 actions,
3728 fields,
3729 id: getItemId(item) || index.toString(),
3730 view,
3731 titleField,
3732 mediaField,
3733 descriptionField: descriptionField2,
3734 selection,
3735 getItemId,
3736 onChangeSelection,
3737 onClickItem,
3738 renderItemLink,
3739 isItemClickable: isItemClickable2,
3740 isActionsColumnSticky: !isHorizontalScrollEnd
3741 },
3742 getItemId(item)
3743 ))
3744 ] }, `group-${groupName}`)
3745 ) : /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("tbody", { children: hasData && data.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3746 TableRow,
3747 {
3748 item,
3749 level: view.showLevels && typeof getItemLevel === "function" ? getItemLevel(item) : void 0,
3750 hasBulkActions,
3751 actions,
3752 fields,
3753 id: getItemId(item) || index.toString(),
3754 view,
3755 titleField,
3756 mediaField,
3757 descriptionField: descriptionField2,
3758 selection,
3759 getItemId,
3760 onChangeSelection,
3761 onClickItem,
3762 renderItemLink,
3763 isItemClickable: isItemClickable2,
3764 isActionsColumnSticky: !isHorizontalScrollEnd,
3765 posinset: isInfiniteScroll ? index + 1 : void 0
3766 },
3767 getItemId(item)
3768 )) })
3769 ]
3770 }
3771 ),
3772 isInfiniteScroll && isLoading && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className: "dataviews-loading", id: tableNoticeId, children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(import_components6.Spinner, {}) }) })
3773 ] });
3774 }
3775 var table_default = ViewTable;
3776
3777 // packages/dataviews/build-module/components/dataviews-layouts/grid/index.mjs
3778 var import_components9 = __toESM(require_components(), 1);
3779 var import_i18n18 = __toESM(require_i18n(), 1);
3780
3781 // packages/dataviews/build-module/components/dataviews-layouts/grid/composite-grid.mjs
3782 var import_components8 = __toESM(require_components(), 1);
3783 var import_i18n17 = __toESM(require_i18n(), 1);
3784 var import_compose3 = __toESM(require_compose(), 1);
3785 var import_keycodes2 = __toESM(require_keycodes(), 1);
3786 var import_element16 = __toESM(require_element(), 1);
3787
3788 // packages/dataviews/build-module/components/dataviews-layouts/grid/preview-size-picker.mjs
3789 var import_components7 = __toESM(require_components(), 1);
3790 var import_i18n16 = __toESM(require_i18n(), 1);
3791 var import_element13 = __toESM(require_element(), 1);
3792 var import_jsx_runtime39 = __toESM(require_jsx_runtime(), 1);
3793 var imageSizes = [
3794 {
3795 value: 120,
3796 breakpoint: 1
3797 },
3798 {
3799 value: 170,
3800 breakpoint: 1
3801 },
3802 {
3803 value: 230,
3804 breakpoint: 1
3805 },
3806 {
3807 value: 290,
3808 breakpoint: 1112
3809 // at minimum image width, 4 images display at this container size
3810 },
3811 {
3812 value: 350,
3813 breakpoint: 1636
3814 // at minimum image width, 6 images display at this container size
3815 },
3816 {
3817 value: 430,
3818 breakpoint: 588
3819 // at minimum image width, 2 images display at this container size
3820 }
3821 ];
3822 var DEFAULT_PREVIEW_SIZE = imageSizes[2].value;
3823 function useGridColumns() {
3824 const context = (0, import_element13.useContext)(dataviews_context_default);
3825 const view = context.view;
3826 return (0, import_element13.useMemo)(() => {
3827 const containerWidth = context.containerWidth;
3828 const gap = 32;
3829 const previewSize = view.layout?.previewSize ?? DEFAULT_PREVIEW_SIZE;
3830 const columns = Math.floor(
3831 (containerWidth + gap) / (previewSize + gap)
3832 );
3833 return Math.max(1, columns);
3834 }, [context.containerWidth, view.layout?.previewSize]);
3835 }
3836
3837 // packages/dataviews/build-module/components/dataviews-layouts/utils/grid-items.mjs
3838 var import_element14 = __toESM(require_element(), 1);
3839 var import_jsx_runtime40 = __toESM(require_jsx_runtime(), 1);
3840 var GridItems = (0, import_element14.forwardRef)(({ className, previewSize, ...props }, ref) => {
3841 return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3842 "div",
3843 {
3844 ref,
3845 className: clsx_default("dataviews-view-grid-items", className),
3846 style: {
3847 gridTemplateColumns: previewSize && `repeat(auto-fill, minmax(${previewSize}px, 1fr))`
3848 },
3849 ...props
3850 }
3851 );
3852 });
3853
3854 // packages/dataviews/build-module/components/dataviews-layouts/utils/use-infinite-scroll.mjs
3855 var import_element15 = __toESM(require_element(), 1);
3856 function useIntersectionObserver(elementRef, posinset) {
3857 const { intersectionObserver } = (0, import_element15.useContext)(dataviews_context_default);
3858 (0, import_element15.useEffect)(() => {
3859 const element = elementRef.current;
3860 if (!element || posinset === void 0 || !intersectionObserver) {
3861 return;
3862 }
3863 intersectionObserver.observe(element);
3864 return () => {
3865 intersectionObserver.unobserve(element);
3866 };
3867 }, [elementRef, intersectionObserver, posinset]);
3868 }
3869 function usePlaceholdersNeeded(data, isInfiniteScroll, gridColumns) {
3870 const hasData = !!data?.length;
3871 const firstItemPosition = hasData && isInfiniteScroll ? data[0].position : void 0;
3872 return firstItemPosition && gridColumns ? (firstItemPosition - 1) % gridColumns : 0;
3873 }
3874
3875 // packages/dataviews/build-module/components/dataviews-layouts/grid/composite-grid.mjs
3876 var import_jsx_runtime41 = __toESM(require_jsx_runtime(), 1);
3877 var { Badge: WCBadge } = unlock(import_components8.privateApis);
3878 function chunk(array, size) {
3879 const chunks = [];
3880 for (let i2 = 0, j2 = array.length; i2 < j2; i2 += size) {
3881 chunks.push(array.slice(i2, i2 + size));
3882 }
3883 return chunks;
3884 }
3885 var GridItem = (0, import_element16.forwardRef)(
3886 function GridItem2({
3887 view,
3888 selection,
3889 onChangeSelection,
3890 onClickItem,
3891 isItemClickable: isItemClickable2,
3892 renderItemLink,
3893 getItemId,
3894 item,
3895 actions,
3896 mediaField,
3897 titleField,
3898 descriptionField: descriptionField2,
3899 regularFields,
3900 badgeFields,
3901 hasBulkActions,
3902 config,
3903 posinset,
3904 setsize,
3905 ...props
3906 }, forwardedRef) {
3907 const {
3908 showTitle = true,
3909 showMedia = true,
3910 showDescription = true
3911 } = view;
3912 const hasBulkAction = useHasAPossibleBulkAction(actions, item);
3913 const id = getItemId(item);
3914 const elementRef = (0, import_element16.useRef)(null);
3915 const setRefs = (0, import_element16.useCallback)(
3916 (node) => {
3917 elementRef.current = node;
3918 if (typeof forwardedRef === "function") {
3919 forwardedRef(node);
3920 } else if (forwardedRef) {
3921 forwardedRef.current = node;
3922 }
3923 },
3924 [forwardedRef]
3925 );
3926 useIntersectionObserver(elementRef, posinset);
3927 const instanceId = (0, import_compose3.useInstanceId)(GridItem2);
3928 const isSelected2 = selection.includes(id);
3929 const mediaPlaceholder = /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("span", { className: "dataviews-view-grid__media-placeholder" });
3930 const rendersMediaField = showMedia && mediaField?.render;
3931 const renderedMediaField = rendersMediaField ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3932 mediaField.render,
3933 {
3934 item,
3935 field: mediaField,
3936 config
3937 }
3938 ) : mediaPlaceholder;
3939 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(titleField.render, { item, field: titleField }) : null;
3940 let mediaA11yProps;
3941 let titleA11yProps;
3942 if (isItemClickable2(item) && onClickItem) {
3943 if (renderedTitleField) {
3944 mediaA11yProps = {
3945 "aria-labelledby": `dataviews-view-grid__title-field-${instanceId}`
3946 };
3947 titleA11yProps = {
3948 id: `dataviews-view-grid__title-field-${instanceId}`
3949 };
3950 } else {
3951 mediaA11yProps = {
3952 "aria-label": (0, import_i18n17.__)("Navigate to item")
3953 };
3954 }
3955 }
3956 return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
3957 Stack,
3958 {
3959 direction: "column",
3960 ...props,
3961 ref: setRefs,
3962 "aria-setsize": setsize,
3963 "aria-posinset": posinset,
3964 className: clsx_default(
3965 props.className,
3966 "dataviews-view-grid__row__gridcell",
3967 "dataviews-view-grid__card",
3968 {
3969 "is-selected": hasBulkAction && isSelected2
3970 }
3971 ),
3972 onClickCapture: (event) => {
3973 props.onClickCapture?.(event);
3974 if ((0, import_keycodes2.isAppleOS)() ? event.metaKey : event.ctrlKey) {
3975 event.stopPropagation();
3976 event.preventDefault();
3977 if (!hasBulkAction) {
3978 return;
3979 }
3980 onChangeSelection(
3981 isSelected2 ? selection.filter(
3982 (itemId) => id !== itemId
3983 ) : [...selection, id]
3984 );
3985 }
3986 },
3987 children: [
3988 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3989 ItemClickWrapper,
3990 {
3991 item,
3992 isItemClickable: isItemClickable2,
3993 onClickItem,
3994 renderItemLink,
3995 className: clsx_default("dataviews-view-grid__media", {
3996 "dataviews-view-grid__media--placeholder": !rendersMediaField
3997 }),
3998 ...mediaA11yProps,
3999 children: renderedMediaField
4000 }
4001 ),
4002 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4003 DataViewsSelectionCheckbox,
4004 {
4005 item,
4006 selection,
4007 onChangeSelection,
4008 getItemId,
4009 titleField,
4010 disabled: !hasBulkAction
4011 }
4012 ),
4013 !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "dataviews-view-grid__media-actions", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4014 ItemActions,
4015 {
4016 item,
4017 actions,
4018 isCompact: true
4019 }
4020 ) }),
4021 showTitle && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "dataviews-view-grid__title", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4022 ItemClickWrapper,
4023 {
4024 item,
4025 isItemClickable: isItemClickable2,
4026 onClickItem,
4027 renderItemLink,
4028 className: "dataviews-view-grid__title-field dataviews-title-field",
4029 ...titleA11yProps,
4030 title: titleField?.getValueFormatted({
4031 item,
4032 field: titleField
4033 }) || void 0,
4034 children: renderedTitleField
4035 }
4036 ) }),
4037 /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(Stack, { direction: "column", gap: "xs", children: [
4038 showDescription && descriptionField2?.render && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4039 descriptionField2.render,
4040 {
4041 item,
4042 field: descriptionField2
4043 }
4044 ),
4045 !!badgeFields?.length && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4046 Stack,
4047 {
4048 direction: "row",
4049 className: "dataviews-view-grid__badge-fields",
4050 gap: "sm",
4051 wrap: "wrap",
4052 align: "top",
4053 justify: "flex-start",
4054 children: badgeFields.map((field) => {
4055 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4056 WCBadge,
4057 {
4058 className: "dataviews-view-grid__field-value",
4059 children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4060 field.render,
4061 {
4062 item,
4063 field
4064 }
4065 )
4066 },
4067 field.id
4068 );
4069 })
4070 }
4071 ),
4072 !!regularFields?.length && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4073 Stack,
4074 {
4075 direction: "column",
4076 className: "dataviews-view-grid__fields",
4077 gap: "xs",
4078 children: regularFields.map((field) => {
4079 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4080 import_components8.Flex,
4081 {
4082 className: "dataviews-view-grid__field",
4083 gap: 1,
4084 justify: "flex-start",
4085 expanded: true,
4086 style: { height: "auto" },
4087 direction: "row",
4088 children: /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(import_jsx_runtime41.Fragment, { children: [
4089 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(import_components8.Tooltip, { text: field.label, children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(import_components8.FlexItem, { className: "dataviews-view-grid__field-name", children: field.header }) }),
4090 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4091 import_components8.FlexItem,
4092 {
4093 className: "dataviews-view-grid__field-value",
4094 style: { maxHeight: "none" },
4095 children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4096 field.render,
4097 {
4098 item,
4099 field
4100 }
4101 )
4102 }
4103 )
4104 ] })
4105 },
4106 field.id
4107 );
4108 })
4109 }
4110 )
4111 ] })
4112 ]
4113 }
4114 );
4115 }
4116 );
4117 function CompositeGrid({
4118 data,
4119 isInfiniteScroll,
4120 className,
4121 inert,
4122 isLoading,
4123 view,
4124 fields,
4125 selection,
4126 onChangeSelection,
4127 onClickItem,
4128 isItemClickable: isItemClickable2,
4129 renderItemLink,
4130 getItemId,
4131 actions
4132 }) {
4133 const { paginationInfo, resizeObserverRef } = (0, import_element16.useContext)(dataviews_context_default);
4134 const gridColumns = useGridColumns();
4135 const hasBulkActions = useSomeItemHasAPossibleBulkAction(actions, data);
4136 const titleField = fields.find(
4137 (field) => field.id === view?.titleField
4138 );
4139 const mediaField = fields.find(
4140 (field) => field.id === view?.mediaField
4141 );
4142 const descriptionField2 = fields.find(
4143 (field) => field.id === view?.descriptionField
4144 );
4145 const otherFields = view.fields ?? [];
4146 const { regularFields, badgeFields } = otherFields.reduce(
4147 (accumulator, fieldId) => {
4148 const field = fields.find((f2) => f2.id === fieldId);
4149 if (!field) {
4150 return accumulator;
4151 }
4152 const key = view.layout?.badgeFields?.includes(fieldId) ? "badgeFields" : "regularFields";
4153 accumulator[key].push(field);
4154 return accumulator;
4155 },
4156 { regularFields: [], badgeFields: [] }
4157 );
4158 const size = "900px";
4159 const totalRows = Math.ceil(data.length / gridColumns);
4160 const placeholdersNeeded = usePlaceholdersNeeded(
4161 data,
4162 isInfiniteScroll,
4163 gridColumns
4164 );
4165 return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(import_jsx_runtime41.Fragment, {
4166 // Render infinite scroll layout (no rows, feed semantics)
4167 children: [
4168 isInfiniteScroll && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
4169 import_components8.Composite,
4170 {
4171 render: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4172 GridItems,
4173 {
4174 className: clsx_default(
4175 "dataviews-view-grid-infinite-scroll",
4176 className,
4177 {
4178 [`has-${view.layout?.density}-density`]: view.layout?.density && [
4179 "compact",
4180 "comfortable"
4181 ].includes(view.layout.density)
4182 }
4183 ),
4184 previewSize: view.layout?.previewSize,
4185 "aria-busy": isLoading,
4186 ref: resizeObserverRef
4187 }
4188 ),
4189 role: "feed",
4190 focusWrap: true,
4191 inert,
4192 children: [
4193 Array.from({ length: placeholdersNeeded }).map(
4194 (_, index) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4195 import_components8.Composite.Item,
4196 {
4197 render: (props) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4198 Stack,
4199 {
4200 ...props,
4201 direction: "column",
4202 role: "article",
4203 className: "dataviews-view-grid__row__gridcell dataviews-view-grid__card dataviews-view-grid__placeholder"
4204 }
4205 ),
4206 "aria-hidden": true,
4207 tabIndex: -1
4208 },
4209 `placeholder-${index}`
4210 )
4211 ),
4212 data.map((item) => {
4213 const itemId = getItemId(item);
4214 const stablePosition = item.position;
4215 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4216 import_components8.Composite.Item,
4217 {
4218 render: (props) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4219 GridItem,
4220 {
4221 ...props,
4222 id: itemId,
4223 role: "article",
4224 view,
4225 selection,
4226 onChangeSelection,
4227 onClickItem,
4228 isItemClickable: isItemClickable2,
4229 renderItemLink,
4230 getItemId,
4231 item,
4232 actions,
4233 mediaField,
4234 titleField,
4235 descriptionField: descriptionField2,
4236 regularFields,
4237 badgeFields,
4238 hasBulkActions,
4239 posinset: stablePosition,
4240 setsize: paginationInfo.totalItems,
4241 config: {
4242 sizes: size
4243 }
4244 }
4245 )
4246 },
4247 itemId
4248 );
4249 })
4250 ]
4251 }
4252 ),
4253 // Render standard grid layout (with rows, grid semantics)
4254 !isInfiniteScroll && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4255 import_components8.Composite,
4256 {
4257 role: "grid",
4258 className: clsx_default("dataviews-view-grid", className, {
4259 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
4260 view.layout.density
4261 )
4262 }),
4263 focusWrap: true,
4264 "aria-busy": isLoading,
4265 "aria-rowcount": totalRows,
4266 ref: resizeObserverRef,
4267 inert,
4268 children: chunk(data, gridColumns).map((row, i2) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4269 import_components8.Composite.Row,
4270 {
4271 render: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4272 "div",
4273 {
4274 role: "row",
4275 "aria-rowindex": i2 + 1,
4276 "aria-label": (0, import_i18n17.sprintf)(
4277 /* translators: %d: The row number in the grid */
4278 (0, import_i18n17.__)("Row %d"),
4279 i2 + 1
4280 ),
4281 className: "dataviews-view-grid__row",
4282 style: {
4283 gridTemplateColumns: `repeat( ${gridColumns}, minmax(0, 1fr) )`
4284 }
4285 }
4286 ),
4287 children: row.map((item) => {
4288 const itemId = getItemId(item);
4289 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4290 import_components8.Composite.Item,
4291 {
4292 render: (props) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4293 GridItem,
4294 {
4295 ...props,
4296 id: itemId,
4297 role: "gridcell",
4298 view,
4299 selection,
4300 onChangeSelection,
4301 onClickItem,
4302 isItemClickable: isItemClickable2,
4303 renderItemLink,
4304 getItemId,
4305 item,
4306 actions,
4307 mediaField,
4308 titleField,
4309 descriptionField: descriptionField2,
4310 regularFields,
4311 badgeFields,
4312 hasBulkActions,
4313 config: {
4314 sizes: size
4315 }
4316 }
4317 )
4318 },
4319 itemId
4320 );
4321 })
4322 },
4323 i2
4324 ))
4325 }
4326 )
4327 ]
4328 });
4329 }
4330
4331 // packages/dataviews/build-module/components/dataviews-layouts/grid/index.mjs
4332 var import_jsx_runtime42 = __toESM(require_jsx_runtime(), 1);
4333 function ViewGrid({
4334 actions,
4335 data,
4336 fields,
4337 getItemId,
4338 isLoading,
4339 onChangeSelection,
4340 onClickItem,
4341 isItemClickable: isItemClickable2,
4342 renderItemLink,
4343 selection,
4344 view,
4345 className,
4346 empty
4347 }) {
4348 const isDelayedLoading = useDelayedLoading(!!isLoading);
4349 const hasData = !!data?.length;
4350 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
4351 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
4352 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
4353 if (!hasData) {
4354 return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
4355 "div",
4356 {
4357 className: clsx_default("dataviews-no-results", {
4358 "is-refreshing": isDelayedLoading
4359 }),
4360 children: empty
4361 }
4362 );
4363 }
4364 const gridProps = {
4365 className: clsx_default(className, {
4366 "is-refreshing": !isInfiniteScroll && isDelayedLoading
4367 }),
4368 inert: !isInfiniteScroll && !!isLoading ? "true" : void 0,
4369 isLoading,
4370 view,
4371 fields,
4372 selection,
4373 onChangeSelection,
4374 onClickItem,
4375 isItemClickable: isItemClickable2,
4376 renderItemLink,
4377 getItemId,
4378 actions
4379 };
4380 return /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(import_jsx_runtime42.Fragment, {
4381 // Render multiple groups.
4382 children: [
4383 hasData && groupField && dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(Stack, { direction: "column", gap: "lg", children: Array.from(dataByGroup.entries()).map(
4384 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(
4385 Stack,
4386 {
4387 direction: "column",
4388 gap: "sm",
4389 children: [
4390 /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("h3", { className: "dataviews-view-grid__group-header", children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n18.sprintf)(
4391 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
4392 (0, import_i18n18.__)("%1$s: %2$s"),
4393 groupField.label,
4394 groupName
4395 ) }),
4396 /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
4397 CompositeGrid,
4398 {
4399 ...gridProps,
4400 data: groupItems,
4401 isInfiniteScroll: false
4402 }
4403 )
4404 ]
4405 },
4406 groupName
4407 )
4408 ) }),
4409 // Render a single grid with all data.
4410 !dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
4411 CompositeGrid,
4412 {
4413 ...gridProps,
4414 data,
4415 isInfiniteScroll: !!isInfiniteScroll
4416 }
4417 ),
4418 isInfiniteScroll && isLoading && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(import_components9.Spinner, {}) })
4419 ]
4420 });
4421 }
4422 var grid_default = ViewGrid;
4423
4424 // packages/dataviews/build-module/components/dataviews-layouts/list/index.mjs
4425 var import_compose4 = __toESM(require_compose(), 1);
4426 var import_components10 = __toESM(require_components(), 1);
4427 var import_element17 = __toESM(require_element(), 1);
4428 var import_i18n19 = __toESM(require_i18n(), 1);
4429 var import_data3 = __toESM(require_data(), 1);
4430 var import_jsx_runtime43 = __toESM(require_jsx_runtime(), 1);
4431 var { Menu: Menu3 } = unlock(import_components10.privateApis);
4432 function generateItemWrapperCompositeId(idPrefix) {
4433 return `${idPrefix}-item-wrapper`;
4434 }
4435 function generatePrimaryActionCompositeId(idPrefix, primaryActionId) {
4436 return `${idPrefix}-primary-action-${primaryActionId}`;
4437 }
4438 function generateDropdownTriggerCompositeId(idPrefix) {
4439 return `${idPrefix}-dropdown`;
4440 }
4441 function PrimaryActionGridCell({
4442 idPrefix,
4443 primaryAction,
4444 item
4445 }) {
4446 const registry = (0, import_data3.useRegistry)();
4447 const [isModalOpen, setIsModalOpen] = (0, import_element17.useState)(false);
4448 const compositeItemId = generatePrimaryActionCompositeId(
4449 idPrefix,
4450 primaryAction.id
4451 );
4452 const label = typeof primaryAction.label === "string" ? primaryAction.label : primaryAction.label([item]);
4453 return "RenderModal" in primaryAction ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { role: "gridcell", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4454 import_components10.Composite.Item,
4455 {
4456 id: compositeItemId,
4457 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4458 import_components10.Button,
4459 {
4460 disabled: !!primaryAction.disabled,
4461 accessibleWhenDisabled: true,
4462 text: label,
4463 size: "small",
4464 onClick: () => setIsModalOpen(true)
4465 }
4466 ),
4467 children: isModalOpen && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4468 ActionModal,
4469 {
4470 action: primaryAction,
4471 items: [item],
4472 closeModal: () => setIsModalOpen(false)
4473 }
4474 )
4475 }
4476 ) }, primaryAction.id) : /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { role: "gridcell", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4477 import_components10.Composite.Item,
4478 {
4479 id: compositeItemId,
4480 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4481 import_components10.Button,
4482 {
4483 disabled: !!primaryAction.disabled,
4484 accessibleWhenDisabled: true,
4485 size: "small",
4486 onClick: () => {
4487 primaryAction.callback([item], { registry });
4488 },
4489 children: label
4490 }
4491 )
4492 }
4493 ) }, primaryAction.id);
4494 }
4495 function ListItem({
4496 view,
4497 actions,
4498 idPrefix,
4499 isSelected: isSelected2,
4500 item,
4501 titleField,
4502 mediaField,
4503 descriptionField: descriptionField2,
4504 onSelect,
4505 otherFields,
4506 onDropdownTriggerKeyDown,
4507 posinset
4508 }) {
4509 const {
4510 showTitle = true,
4511 showMedia = true,
4512 showDescription = true,
4513 infiniteScrollEnabled
4514 } = view;
4515 const itemRef = (0, import_element17.useRef)(null);
4516 const labelId = `${idPrefix}-label`;
4517 const descriptionId = `${idPrefix}-description`;
4518 const registry = (0, import_data3.useRegistry)();
4519 const [isHovered, setIsHovered] = (0, import_element17.useState)(false);
4520 const [activeModalAction, setActiveModalAction] = (0, import_element17.useState)(
4521 null
4522 );
4523 const handleHover = ({ type }) => {
4524 const isHover = type === "mouseenter";
4525 setIsHovered(isHover);
4526 };
4527 const { paginationInfo } = (0, import_element17.useContext)(dataviews_context_default);
4528 (0, import_element17.useEffect)(() => {
4529 if (isSelected2) {
4530 itemRef.current?.scrollIntoView({
4531 behavior: "auto",
4532 block: "nearest",
4533 inline: "nearest"
4534 });
4535 }
4536 }, [isSelected2]);
4537 const { primaryAction, eligibleActions } = (0, import_element17.useMemo)(() => {
4538 const _eligibleActions = actions.filter(
4539 (action) => !action.isEligible || action.isEligible(item)
4540 );
4541 const _primaryActions = _eligibleActions.filter(
4542 (action) => action.isPrimary
4543 );
4544 return {
4545 primaryAction: _primaryActions[0],
4546 eligibleActions: _eligibleActions
4547 };
4548 }, [actions, item]);
4549 const hasOnlyOnePrimaryAction = primaryAction && actions.length === 1;
4550 const renderedMediaField = showMedia && mediaField?.render ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "dataviews-view-list__media-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4551 mediaField.render,
4552 {
4553 item,
4554 field: mediaField,
4555 config: { sizes: "52px" }
4556 }
4557 ) }) : null;
4558 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(titleField.render, { item, field: titleField }) : null;
4559 const renderDescription = showDescription && descriptionField2?.render;
4560 const hasOnlyMediaAndTitle = !!renderedMediaField && !renderDescription && !otherFields.length;
4561 const usedActions = eligibleActions?.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4562 Stack,
4563 {
4564 direction: "row",
4565 gap: "md",
4566 className: "dataviews-view-list__item-actions",
4567 children: [
4568 primaryAction && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4569 PrimaryActionGridCell,
4570 {
4571 idPrefix,
4572 primaryAction,
4573 item
4574 }
4575 ),
4576 !hasOnlyOnePrimaryAction && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { role: "gridcell", children: [
4577 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Menu3, { placement: "bottom-end", children: [
4578 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4579 Menu3.TriggerButton,
4580 {
4581 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4582 import_components10.Composite.Item,
4583 {
4584 id: generateDropdownTriggerCompositeId(
4585 idPrefix
4586 ),
4587 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4588 import_components10.Button,
4589 {
4590 size: "small",
4591 icon: more_vertical_default,
4592 label: (0, import_i18n19.__)("Actions"),
4593 accessibleWhenDisabled: true,
4594 disabled: !actions.length,
4595 onKeyDown: onDropdownTriggerKeyDown
4596 }
4597 )
4598 }
4599 )
4600 }
4601 ),
4602 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Menu3.Popover, { children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4603 ActionsMenuGroup,
4604 {
4605 actions: eligibleActions,
4606 item,
4607 registry,
4608 setActiveModalAction
4609 }
4610 ) })
4611 ] }),
4612 !!activeModalAction && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4613 ActionModal,
4614 {
4615 action: activeModalAction,
4616 items: [item],
4617 closeModal: () => setActiveModalAction(null)
4618 }
4619 )
4620 ] })
4621 ]
4622 }
4623 );
4624 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4625 import_components10.Composite.Row,
4626 {
4627 ref: itemRef,
4628 render: (
4629 /* aria-posinset breaks Composite.Row if passed to it directly. */
4630 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4631 "div",
4632 {
4633 "aria-posinset": posinset,
4634 "aria-setsize": infiniteScrollEnabled ? paginationInfo.totalItems : void 0
4635 }
4636 )
4637 ),
4638 role: infiniteScrollEnabled ? "article" : "row",
4639 className: clsx_default({
4640 "is-selected": isSelected2,
4641 "is-hovered": isHovered
4642 }),
4643 onMouseEnter: handleHover,
4644 onMouseLeave: handleHover,
4645 children: /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4646 Stack,
4647 {
4648 direction: "row",
4649 className: "dataviews-view-list__item-wrapper",
4650 children: [
4651 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { role: "gridcell", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4652 import_components10.Composite.Item,
4653 {
4654 id: generateItemWrapperCompositeId(idPrefix),
4655 "aria-pressed": isSelected2,
4656 "aria-labelledby": labelId,
4657 "aria-describedby": descriptionId,
4658 className: "dataviews-view-list__item",
4659 onClick: () => onSelect(item)
4660 }
4661 ) }),
4662 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4663 Stack,
4664 {
4665 direction: "row",
4666 gap: "md",
4667 justify: "start",
4668 align: hasOnlyMediaAndTitle ? "center" : "flex-start",
4669 style: { flex: 1, minWidth: 0 },
4670 children: [
4671 renderedMediaField,
4672 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4673 Stack,
4674 {
4675 direction: "column",
4676 gap: "xs",
4677 className: "dataviews-view-list__field-wrapper",
4678 children: [
4679 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Stack, { direction: "row", align: "center", children: [
4680 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4681 "div",
4682 {
4683 className: "dataviews-title-field dataviews-view-list__title-field",
4684 id: labelId,
4685 children: renderedTitleField
4686 }
4687 ),
4688 usedActions
4689 ] }),
4690 renderDescription && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "dataviews-view-list__field", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4691 descriptionField2.render,
4692 {
4693 item,
4694 field: descriptionField2
4695 }
4696 ) }),
4697 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4698 "div",
4699 {
4700 className: "dataviews-view-list__fields",
4701 id: descriptionId,
4702 children: otherFields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4703 "div",
4704 {
4705 className: "dataviews-view-list__field",
4706 children: [
4707 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4708 VisuallyHidden,
4709 {
4710 className: "dataviews-view-list__field-label",
4711 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", {}),
4712 children: field.label
4713 }
4714 ),
4715 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "dataviews-view-list__field-value", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4716 field.render,
4717 {
4718 item,
4719 field
4720 }
4721 ) })
4722 ]
4723 },
4724 field.id
4725 ))
4726 }
4727 )
4728 ]
4729 }
4730 )
4731 ]
4732 }
4733 )
4734 ]
4735 }
4736 )
4737 }
4738 );
4739 }
4740 function isDefined2(item) {
4741 return !!item;
4742 }
4743 function ViewList(props) {
4744 const {
4745 actions,
4746 data,
4747 fields,
4748 getItemId,
4749 isLoading,
4750 onChangeSelection,
4751 selection,
4752 view,
4753 className,
4754 empty
4755 } = props;
4756 const baseId = (0, import_compose4.useInstanceId)(ViewList, "view-list");
4757 const isDelayedLoading = useDelayedLoading(!!isLoading);
4758 const selectedItem = data?.findLast(
4759 (item) => selection.includes(getItemId(item))
4760 );
4761 const titleField = fields.find((field) => field.id === view.titleField);
4762 const mediaField = fields.find((field) => field.id === view.mediaField);
4763 const descriptionField2 = fields.find(
4764 (field) => field.id === view.descriptionField
4765 );
4766 const otherFields = (view?.fields ?? []).map((fieldId) => fields.find((f2) => fieldId === f2.id)).filter(isDefined2);
4767 const onSelect = (item) => onChangeSelection([getItemId(item)]);
4768 const generateCompositeItemIdPrefix = (0, import_element17.useCallback)(
4769 (item) => `${baseId}-${getItemId(item)}`,
4770 [baseId, getItemId]
4771 );
4772 const isActiveCompositeItem = (0, import_element17.useCallback)(
4773 (item, idToCheck) => {
4774 return idToCheck.startsWith(
4775 generateCompositeItemIdPrefix(item)
4776 );
4777 },
4778 [generateCompositeItemIdPrefix]
4779 );
4780 const [activeCompositeId, setActiveCompositeId] = (0, import_element17.useState)(void 0);
4781 const compositeRef = (0, import_element17.useRef)(null);
4782 (0, import_element17.useEffect)(() => {
4783 if (selectedItem) {
4784 setActiveCompositeId(
4785 generateItemWrapperCompositeId(
4786 generateCompositeItemIdPrefix(selectedItem)
4787 )
4788 );
4789 }
4790 }, [selectedItem, generateCompositeItemIdPrefix]);
4791 const activeItemIndex = data.findIndex(
4792 (item) => isActiveCompositeItem(item, activeCompositeId ?? "")
4793 );
4794 const previousActiveItemIndex = (0, import_compose4.usePrevious)(activeItemIndex);
4795 const isActiveIdInList = activeItemIndex !== -1;
4796 const selectCompositeItem = (0, import_element17.useCallback)(
4797 (targetIndex, generateCompositeId) => {
4798 const clampedIndex = Math.min(
4799 data.length - 1,
4800 Math.max(0, targetIndex)
4801 );
4802 if (!data[clampedIndex]) {
4803 return;
4804 }
4805 const itemIdPrefix = generateCompositeItemIdPrefix(
4806 data[clampedIndex]
4807 );
4808 const targetCompositeItemId = generateCompositeId(itemIdPrefix);
4809 setActiveCompositeId(targetCompositeItemId);
4810 if (compositeRef.current?.contains(
4811 compositeRef.current.ownerDocument.activeElement
4812 )) {
4813 document.getElementById(targetCompositeItemId)?.focus();
4814 }
4815 },
4816 [data, generateCompositeItemIdPrefix]
4817 );
4818 (0, import_element17.useEffect)(() => {
4819 const wasActiveIdInList = previousActiveItemIndex !== void 0 && previousActiveItemIndex !== -1;
4820 if (!isActiveIdInList && wasActiveIdInList) {
4821 selectCompositeItem(
4822 previousActiveItemIndex,
4823 generateItemWrapperCompositeId
4824 );
4825 }
4826 }, [isActiveIdInList, selectCompositeItem, previousActiveItemIndex]);
4827 const onDropdownTriggerKeyDown = (0, import_element17.useCallback)(
4828 (event) => {
4829 if (event.key === "ArrowDown") {
4830 event.preventDefault();
4831 selectCompositeItem(
4832 activeItemIndex + 1,
4833 generateDropdownTriggerCompositeId
4834 );
4835 }
4836 if (event.key === "ArrowUp") {
4837 event.preventDefault();
4838 selectCompositeItem(
4839 activeItemIndex - 1,
4840 generateDropdownTriggerCompositeId
4841 );
4842 }
4843 },
4844 [selectCompositeItem, activeItemIndex]
4845 );
4846 const hasData = !!data?.length;
4847 const groupField = view.groupBy?.field ? fields.find((field) => field.id === view.groupBy?.field) : null;
4848 const dataByGroup = hasData && groupField ? getDataByGroup(data, groupField) : null;
4849 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
4850 if (!hasData) {
4851 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4852 "div",
4853 {
4854 className: clsx_default("dataviews-no-results", {
4855 "is-refreshing": isDelayedLoading
4856 }),
4857 children: empty
4858 }
4859 );
4860 }
4861 if (hasData && groupField && dataByGroup) {
4862 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4863 import_components10.Composite,
4864 {
4865 ref: compositeRef,
4866 id: `${baseId}`,
4867 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", {}),
4868 className: "dataviews-view-list__group",
4869 role: "grid",
4870 activeId: activeCompositeId,
4871 setActiveId: setActiveCompositeId,
4872 children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4873 Stack,
4874 {
4875 direction: "column",
4876 gap: "lg",
4877 className: clsx_default("dataviews-view-list", className),
4878 children: Array.from(dataByGroup.entries()).map(
4879 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4880 Stack,
4881 {
4882 direction: "column",
4883 gap: "sm",
4884 children: [
4885 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("h3", { className: "dataviews-view-list__group-header", children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n19.sprintf)(
4886 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
4887 (0, import_i18n19.__)("%1$s: %2$s"),
4888 groupField.label,
4889 groupName
4890 ) }),
4891 groupItems.map((item) => {
4892 const id = generateCompositeItemIdPrefix(item);
4893 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4894 ListItem,
4895 {
4896 view,
4897 idPrefix: id,
4898 actions,
4899 item,
4900 isSelected: item === selectedItem,
4901 onSelect,
4902 mediaField,
4903 titleField,
4904 descriptionField: descriptionField2,
4905 otherFields,
4906 onDropdownTriggerKeyDown
4907 },
4908 id
4909 );
4910 })
4911 ]
4912 },
4913 groupName
4914 )
4915 )
4916 }
4917 )
4918 }
4919 );
4920 }
4921 return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(import_jsx_runtime43.Fragment, { children: [
4922 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4923 import_components10.Composite,
4924 {
4925 ref: compositeRef,
4926 id: baseId,
4927 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", {}),
4928 className: clsx_default("dataviews-view-list", className, {
4929 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
4930 view.layout.density
4931 ),
4932 "is-refreshing": !isInfiniteScroll && isDelayedLoading
4933 }),
4934 role: view.infiniteScrollEnabled ? "feed" : "grid",
4935 activeId: activeCompositeId,
4936 setActiveId: setActiveCompositeId,
4937 inert: !isInfiniteScroll && !!isLoading ? "true" : void 0,
4938 children: data.map((item, index) => {
4939 const id = generateCompositeItemIdPrefix(item);
4940 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4941 ListItem,
4942 {
4943 view,
4944 idPrefix: id,
4945 actions,
4946 item,
4947 isSelected: item === selectedItem,
4948 onSelect,
4949 mediaField,
4950 titleField,
4951 descriptionField: descriptionField2,
4952 otherFields,
4953 onDropdownTriggerKeyDown,
4954 posinset: view.infiniteScrollEnabled ? index + 1 : void 0
4955 },
4956 id
4957 );
4958 })
4959 }
4960 ),
4961 isInfiniteScroll && isLoading && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(import_components10.Spinner, {}) })
4962 ] });
4963 }
4964
4965 // packages/dataviews/build-module/components/dataviews-layouts/activity/index.mjs
4966 var import_components11 = __toESM(require_components(), 1);
4967
4968 // packages/dataviews/build-module/components/dataviews-layouts/activity/activity-group.mjs
4969 var import_i18n20 = __toESM(require_i18n(), 1);
4970 var import_element18 = __toESM(require_element(), 1);
4971 var import_jsx_runtime44 = __toESM(require_jsx_runtime(), 1);
4972 function ActivityGroup({
4973 groupName,
4974 groupData,
4975 groupField,
4976 showLabel = true,
4977 children
4978 }) {
4979 const groupHeader = showLabel ? (0, import_element18.createInterpolateElement)(
4980 // translators: %s: The label of the field e.g. "Status".
4981 (0, import_i18n20.sprintf)((0, import_i18n20.__)("%s: <groupName />"), groupField.label).trim(),
4982 {
4983 groupName: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
4984 groupField.render,
4985 {
4986 item: groupData[0],
4987 field: groupField
4988 }
4989 )
4990 }
4991 ) : /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(groupField.render, { item: groupData[0], field: groupField });
4992 return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)(
4993 Stack,
4994 {
4995 direction: "column",
4996 className: "dataviews-view-activity__group",
4997 children: [
4998 /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("h3", { className: "dataviews-view-activity__group-header", children: groupHeader }),
4999 children
5000 ]
5001 },
5002 groupName
5003 );
5004 }
5005
5006 // packages/dataviews/build-module/components/dataviews-layouts/activity/activity-item.mjs
5007 var import_element19 = __toESM(require_element(), 1);
5008 var import_data4 = __toESM(require_data(), 1);
5009 var import_compose5 = __toESM(require_compose(), 1);
5010 var import_jsx_runtime45 = __toESM(require_jsx_runtime(), 1);
5011 function ActivityItem(props) {
5012 const {
5013 view,
5014 actions,
5015 item,
5016 titleField,
5017 mediaField,
5018 descriptionField: descriptionField2,
5019 otherFields,
5020 posinset,
5021 onClickItem,
5022 renderItemLink,
5023 isItemClickable: isItemClickable2
5024 } = props;
5025 const {
5026 showTitle = true,
5027 showMedia = true,
5028 showDescription = true,
5029 infiniteScrollEnabled
5030 } = view;
5031 const itemRef = (0, import_element19.useRef)(null);
5032 const registry = (0, import_data4.useRegistry)();
5033 const { paginationInfo } = (0, import_element19.useContext)(dataviews_context_default);
5034 const { primaryActions, eligibleActions } = (0, import_element19.useMemo)(() => {
5035 const _eligibleActions = actions.filter(
5036 (action) => !action.isEligible || action.isEligible(item)
5037 );
5038 const _primaryActions = _eligibleActions.filter(
5039 (action) => action.isPrimary
5040 );
5041 return {
5042 primaryActions: _primaryActions,
5043 eligibleActions: _eligibleActions
5044 };
5045 }, [actions, item]);
5046 const isMobileViewport = (0, import_compose5.useViewportMatch)("medium", "<");
5047 const density = view.layout?.density ?? "balanced";
5048 const mediaContent = showMedia && density !== "compact" && mediaField?.render ? /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5049 mediaField.render,
5050 {
5051 item,
5052 field: mediaField,
5053 config: {
5054 sizes: density === "comfortable" ? "32px" : "24px"
5055 }
5056 }
5057 ) : null;
5058 const renderedMediaField = /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-type-icon", children: mediaContent || /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5059 "span",
5060 {
5061 className: "dataviews-view-activity__item-bullet",
5062 "aria-hidden": "true"
5063 }
5064 ) });
5065 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(titleField.render, { item, field: titleField }) : null;
5066 const verticalGap = (0, import_element19.useMemo)(() => {
5067 switch (density) {
5068 case "comfortable":
5069 return "md";
5070 default:
5071 return "sm";
5072 }
5073 }, [density]);
5074 return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5075 "div",
5076 {
5077 ref: itemRef,
5078 role: infiniteScrollEnabled ? "article" : void 0,
5079 "aria-posinset": posinset,
5080 "aria-setsize": infiniteScrollEnabled ? paginationInfo.totalItems : void 0,
5081 className: clsx_default(
5082 "dataviews-view-activity__item",
5083 density === "compact" && "is-compact",
5084 density === "balanced" && "is-balanced",
5085 density === "comfortable" && "is-comfortable"
5086 ),
5087 children: /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(Stack, { direction: "row", gap: "lg", justify: "start", align: "flex-start", children: [
5088 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5089 Stack,
5090 {
5091 direction: "column",
5092 gap: "xs",
5093 align: "center",
5094 className: "dataviews-view-activity__item-type",
5095 children: renderedMediaField
5096 }
5097 ),
5098 /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
5099 Stack,
5100 {
5101 direction: "column",
5102 gap: verticalGap,
5103 align: "flex-start",
5104 className: "dataviews-view-activity__item-content",
5105 children: [
5106 renderedTitleField && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5107 ItemClickWrapper,
5108 {
5109 item,
5110 isItemClickable: isItemClickable2,
5111 onClickItem,
5112 renderItemLink,
5113 className: "dataviews-view-activity__item-title",
5114 children: renderedTitleField
5115 }
5116 ),
5117 showDescription && descriptionField2 && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-description", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5118 descriptionField2.render,
5119 {
5120 item,
5121 field: descriptionField2
5122 }
5123 ) }),
5124 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-fields", children: otherFields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
5125 "div",
5126 {
5127 className: "dataviews-view-activity__item-field",
5128 children: [
5129 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5130 VisuallyHidden,
5131 {
5132 className: "dataviews-view-activity__item-field-label",
5133 render: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("span", {}),
5134 children: field.label
5135 }
5136 ),
5137 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("span", { className: "dataviews-view-activity__item-field-value", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5138 field.render,
5139 {
5140 item,
5141 field
5142 }
5143 ) })
5144 ]
5145 },
5146 field.id
5147 )) }),
5148 !!primaryActions?.length && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5149 PrimaryActions,
5150 {
5151 item,
5152 actions: primaryActions,
5153 registry,
5154 buttonVariant: "secondary"
5155 }
5156 )
5157 ]
5158 }
5159 ),
5160 (primaryActions.length < eligibleActions.length || // Since we hide primary actions on mobile, we need to show the menu
5161 // there if there are any actions at all.
5162 isMobileViewport && // At the same time, only show the menu if there are actions to show.
5163 eligibleActions.length > 0) && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-actions", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5164 ItemActions,
5165 {
5166 item,
5167 actions: eligibleActions,
5168 isCompact: true
5169 }
5170 ) })
5171 ] })
5172 }
5173 );
5174 }
5175 var activity_item_default = ActivityItem;
5176
5177 // packages/dataviews/build-module/components/dataviews-layouts/activity/activity-items.mjs
5178 var import_react4 = __toESM(require_react(), 1);
5179 function isDefined3(item) {
5180 return !!item;
5181 }
5182 function ActivityItems(props) {
5183 const { data, fields, getItemId, view } = props;
5184 const titleField = fields.find((field) => field.id === view.titleField);
5185 const mediaField = fields.find((field) => field.id === view.mediaField);
5186 const descriptionField2 = fields.find(
5187 (field) => field.id === view.descriptionField
5188 );
5189 const otherFields = (view?.fields ?? []).map((fieldId) => fields.find((f2) => fieldId === f2.id)).filter(isDefined3);
5190 return data.map((item, index) => {
5191 return /* @__PURE__ */ (0, import_react4.createElement)(
5192 activity_item_default,
5193 {
5194 ...props,
5195 key: getItemId(item),
5196 item,
5197 mediaField,
5198 titleField,
5199 descriptionField: descriptionField2,
5200 otherFields,
5201 posinset: view.infiniteScrollEnabled ? index + 1 : void 0
5202 }
5203 );
5204 });
5205 }
5206
5207 // packages/dataviews/build-module/components/dataviews-layouts/activity/index.mjs
5208 var import_jsx_runtime46 = __toESM(require_jsx_runtime(), 1);
5209 function ViewActivity(props) {
5210 const { empty, data, fields, isLoading, view, className } = props;
5211 const isDelayedLoading = useDelayedLoading(!!isLoading);
5212 const hasData = !!data?.length;
5213 const groupField = view.groupBy?.field ? fields.find((field) => field.id === view.groupBy?.field) : null;
5214 const dataByGroup = hasData && groupField ? getDataByGroup(data, groupField) : null;
5215 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
5216 if (!hasData) {
5217 return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5218 "div",
5219 {
5220 className: clsx_default("dataviews-no-results", {
5221 "is-refreshing": isDelayedLoading
5222 }),
5223 children: empty
5224 }
5225 );
5226 }
5227 const isInert = !isInfiniteScroll && !!isLoading;
5228 const wrapperClassName = clsx_default("dataviews-view-activity", className, {
5229 "is-refreshing": !isInfiniteScroll && isDelayedLoading
5230 });
5231 const groupedEntries = dataByGroup ? Array.from(dataByGroup.entries()) : [];
5232 if (hasData && groupField && dataByGroup) {
5233 return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5234 Stack,
5235 {
5236 direction: "column",
5237 gap: "sm",
5238 className: wrapperClassName,
5239 inert: isInert ? "true" : void 0,
5240 children: groupedEntries.map(
5241 ([groupName, groupData]) => /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5242 ActivityGroup,
5243 {
5244 groupName,
5245 groupData,
5246 groupField,
5247 showLabel: view.groupBy?.showLabel !== false,
5248 children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5249 ActivityItems,
5250 {
5251 ...props,
5252 data: groupData
5253 }
5254 )
5255 },
5256 groupName
5257 )
5258 )
5259 }
5260 );
5261 }
5262 return /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)(import_jsx_runtime46.Fragment, { children: [
5263 /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5264 "div",
5265 {
5266 className: wrapperClassName,
5267 role: view.infiniteScrollEnabled ? "feed" : void 0,
5268 inert: isInert ? "true" : void 0,
5269 children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(ActivityItems, { ...props })
5270 }
5271 ),
5272 isInfiniteScroll && isLoading && /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(import_components11.Spinner, {}) })
5273 ] });
5274 }
5275
5276 // packages/dataviews/build-module/components/dataviews-layouts/picker-grid/index.mjs
5277 var import_components14 = __toESM(require_components(), 1);
5278 var import_i18n23 = __toESM(require_i18n(), 1);
5279 var import_compose6 = __toESM(require_compose(), 1);
5280 var import_element22 = __toESM(require_element(), 1);
5281
5282 // packages/dataviews/build-module/components/dataviews-picker-footer/index.mjs
5283 var import_components13 = __toESM(require_components(), 1);
5284 var import_data5 = __toESM(require_data(), 1);
5285 var import_element21 = __toESM(require_element(), 1);
5286 var import_i18n22 = __toESM(require_i18n(), 1);
5287
5288 // packages/dataviews/build-module/components/dataviews-pagination/index.mjs
5289 var import_components12 = __toESM(require_components(), 1);
5290 var import_element20 = __toESM(require_element(), 1);
5291 var import_i18n21 = __toESM(require_i18n(), 1);
5292 var import_jsx_runtime47 = __toESM(require_jsx_runtime(), 1);
5293 function DataViewsPagination() {
5294 const {
5295 view,
5296 onChangeView,
5297 paginationInfo: { totalItems = 0, totalPages }
5298 } = (0, import_element20.useContext)(dataviews_context_default);
5299 if (!totalItems || !totalPages || view.infiniteScrollEnabled) {
5300 return null;
5301 }
5302 const currentPage = view.page ?? 1;
5303 const pageSelectOptions = Array.from(Array(totalPages)).map(
5304 (_, i2) => {
5305 const page = i2 + 1;
5306 return {
5307 value: page.toString(),
5308 label: page.toString(),
5309 "aria-label": currentPage === page ? (0, import_i18n21.sprintf)(
5310 // translators: 1: current page number. 2: total number of pages.
5311 (0, import_i18n21.__)("Page %1$d of %2$d"),
5312 currentPage,
5313 totalPages
5314 ) : page.toString()
5315 };
5316 }
5317 );
5318 return !!totalItems && totalPages !== 1 && /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(
5319 Stack,
5320 {
5321 direction: "row",
5322 className: "dataviews-pagination",
5323 justify: "end",
5324 align: "center",
5325 gap: "xl",
5326 children: [
5327 /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5328 Stack,
5329 {
5330 direction: "row",
5331 justify: "flex-start",
5332 align: "center",
5333 gap: "xs",
5334 className: "dataviews-pagination__page-select",
5335 children: (0, import_element20.createInterpolateElement)(
5336 (0, import_i18n21.sprintf)(
5337 // translators: 1: Current page number, 2: Total number of pages.
5338 (0, import_i18n21._x)(
5339 "<div>Page</div>%1$s<div>of %2$d</div>",
5340 "paging"
5341 ),
5342 "<CurrentPage />",
5343 totalPages
5344 ),
5345 {
5346 div: /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("div", { "aria-hidden": true }),
5347 // @ts-expect-error — Tag injected via sprintf argument, not visible in format string.
5348 CurrentPage: /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5349 import_components12.SelectControl,
5350 {
5351 "aria-label": (0, import_i18n21.__)("Current page"),
5352 value: currentPage.toString(),
5353 options: pageSelectOptions,
5354 onChange: (newValue) => {
5355 onChangeView({
5356 ...view,
5357 page: +newValue
5358 });
5359 },
5360 size: "small",
5361 variant: "minimal"
5362 }
5363 )
5364 }
5365 )
5366 }
5367 ),
5368 /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(Stack, { direction: "row", gap: "xs", align: "center", children: [
5369 /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5370 import_components12.Button,
5371 {
5372 onClick: () => onChangeView({
5373 ...view,
5374 page: currentPage - 1
5375 }),
5376 disabled: currentPage === 1,
5377 accessibleWhenDisabled: true,
5378 label: (0, import_i18n21.__)("Previous page"),
5379 icon: (0, import_i18n21.isRTL)() ? next_default : previous_default,
5380 showTooltip: true,
5381 size: "compact",
5382 tooltipPosition: "top"
5383 }
5384 ),
5385 /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5386 import_components12.Button,
5387 {
5388 onClick: () => onChangeView({ ...view, page: currentPage + 1 }),
5389 disabled: currentPage >= totalPages,
5390 accessibleWhenDisabled: true,
5391 label: (0, import_i18n21.__)("Next page"),
5392 icon: (0, import_i18n21.isRTL)() ? previous_default : next_default,
5393 showTooltip: true,
5394 size: "compact",
5395 tooltipPosition: "top"
5396 }
5397 )
5398 ] })
5399 ]
5400 }
5401 );
5402 }
5403 var dataviews_pagination_default = (0, import_element20.memo)(DataViewsPagination);
5404
5405 // packages/dataviews/build-module/components/dataviews-picker-footer/index.mjs
5406 var import_jsx_runtime48 = __toESM(require_jsx_runtime(), 1);
5407 var EMPTY_ARRAY2 = [];
5408 function useIsMultiselectPicker(actions) {
5409 return (0, import_element21.useMemo)(() => {
5410 return actions?.every((action) => action.supportsBulk);
5411 }, [actions]);
5412 }
5413 function BulkSelectionCheckbox2({
5414 selection,
5415 selectedItems,
5416 onChangeSelection,
5417 data,
5418 getItemId,
5419 disableSelectAll = false
5420 }) {
5421 const hasSelection = selection.length > 0;
5422 const areAllSelected = selectedItems.length === data.length;
5423 if (disableSelectAll) {
5424 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5425 import_components13.CheckboxControl,
5426 {
5427 className: "dataviews-view-table-selection-checkbox",
5428 checked: hasSelection,
5429 disabled: !hasSelection,
5430 onChange: () => {
5431 onChangeSelection([]);
5432 },
5433 "aria-label": (0, import_i18n22.__)("Deselect all")
5434 }
5435 );
5436 }
5437 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5438 import_components13.CheckboxControl,
5439 {
5440 className: "dataviews-view-table-selection-checkbox",
5441 checked: areAllSelected,
5442 indeterminate: !areAllSelected && !!selectedItems.length,
5443 onChange: () => {
5444 if (areAllSelected) {
5445 onChangeSelection(
5446 selection.filter(
5447 (id) => !data.some(
5448 (item) => id === getItemId(item)
5449 )
5450 )
5451 );
5452 } else {
5453 const selectionSet = /* @__PURE__ */ new Set([
5454 ...selection,
5455 ...data.map((item) => getItemId(item))
5456 ]);
5457 onChangeSelection(Array.from(selectionSet));
5458 }
5459 },
5460 "aria-label": areAllSelected ? (0, import_i18n22.__)("Deselect all") : (0, import_i18n22.__)("Select all")
5461 }
5462 );
5463 }
5464 function ActionButtons({
5465 actions,
5466 items,
5467 selection
5468 }) {
5469 const registry = (0, import_data5.useRegistry)();
5470 const [actionInProgress, setActionInProgress] = (0, import_element21.useState)(
5471 null
5472 );
5473 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(Stack, { direction: "row", gap: "xs", children: actions.map((action) => {
5474 if (!("callback" in action)) {
5475 return null;
5476 }
5477 const { id, label, icon, isPrimary, callback } = action;
5478 const _label = typeof label === "string" ? label : label(items);
5479 const variant = isPrimary ? "primary" : "tertiary";
5480 const isInProgress = id === actionInProgress;
5481 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5482 import_components13.Button,
5483 {
5484 accessibleWhenDisabled: true,
5485 icon,
5486 disabled: isInProgress || !selection?.length,
5487 isBusy: isInProgress,
5488 onClick: async () => {
5489 setActionInProgress(id);
5490 await callback(items, {
5491 registry
5492 });
5493 setActionInProgress(null);
5494 },
5495 size: "compact",
5496 variant,
5497 children: _label
5498 },
5499 id
5500 );
5501 }) });
5502 }
5503 function DataViewsPickerFooter() {
5504 const {
5505 data,
5506 selection,
5507 onChangeSelection,
5508 getItemId,
5509 actions = EMPTY_ARRAY2,
5510 paginationInfo,
5511 view
5512 } = (0, import_element21.useContext)(dataviews_context_default);
5513 const isMultiselect = useIsMultiselectPicker(actions);
5514 const message2 = getFooterMessage(
5515 selection.length,
5516 data.length,
5517 paginationInfo.totalItems,
5518 !!view.infiniteScrollEnabled
5519 );
5520 const selectedItems = (0, import_element21.useMemo)(
5521 () => data.filter((item) => selection.includes(getItemId(item))),
5522 [selection, getItemId, data]
5523 );
5524 return /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(
5525 Stack,
5526 {
5527 direction: "row",
5528 justify: "space-between",
5529 align: "center",
5530 className: "dataviews-footer",
5531 gap: "sm",
5532 children: [
5533 /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(
5534 Stack,
5535 {
5536 direction: "row",
5537 className: "dataviews-picker-footer__bulk-selection",
5538 gap: "md",
5539 align: "center",
5540 children: [
5541 isMultiselect && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5542 BulkSelectionCheckbox2,
5543 {
5544 selection,
5545 selectedItems,
5546 onChangeSelection,
5547 data,
5548 getItemId,
5549 disableSelectAll: !!view.infiniteScrollEnabled
5550 }
5551 ),
5552 /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("span", { className: "dataviews-bulk-actions-footer__item-count", children: message2 })
5553 ]
5554 }
5555 ),
5556 /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(dataviews_pagination_default, {}),
5557 Boolean(actions?.length) && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("div", { className: "dataviews-picker-footer__actions", children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5558 ActionButtons,
5559 {
5560 actions,
5561 items: selectedItems,
5562 selection
5563 }
5564 ) })
5565 ]
5566 }
5567 );
5568 }
5569
5570 // packages/dataviews/build-module/components/dataviews-layouts/picker-grid/index.mjs
5571 var import_jsx_runtime49 = __toESM(require_jsx_runtime(), 1);
5572 var { Badge: WCBadge2 } = unlock(import_components14.privateApis);
5573 function GridItem3({
5574 view,
5575 multiselect,
5576 selection,
5577 onChangeSelection,
5578 getItemId,
5579 item,
5580 mediaField,
5581 titleField,
5582 descriptionField: descriptionField2,
5583 regularFields,
5584 badgeFields,
5585 config,
5586 posinset,
5587 setsize
5588 }) {
5589 const { showTitle = true, showMedia = true, showDescription = true } = view;
5590 const id = getItemId(item);
5591 const elementRef = (0, import_element22.useRef)(null);
5592 const isSelected2 = selection.includes(id);
5593 useIntersectionObserver(elementRef, posinset);
5594 const renderedMediaField = mediaField?.render ? /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5595 mediaField.render,
5596 {
5597 item,
5598 field: mediaField,
5599 config
5600 }
5601 ) : null;
5602 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(titleField.render, { item, field: titleField }) : null;
5603 return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5604 import_components14.Composite.Item,
5605 {
5606 ref: elementRef,
5607 "aria-label": titleField ? titleField.getValue({ item }) || (0, import_i18n23.__)("(no title)") : void 0,
5608 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack, { direction: "column", children, ...props }),
5609 role: "option",
5610 "aria-posinset": posinset,
5611 "aria-setsize": setsize,
5612 className: clsx_default("dataviews-view-picker-grid__card", {
5613 "is-selected": isSelected2
5614 }),
5615 "aria-selected": isSelected2,
5616 onClick: () => {
5617 if (isSelected2) {
5618 onChangeSelection(
5619 selection.filter((itemId) => id !== itemId)
5620 );
5621 } else {
5622 const newSelection = multiselect ? [...selection, id] : [id];
5623 onChangeSelection(newSelection);
5624 }
5625 },
5626 children: [
5627 showMedia && renderedMediaField && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { className: "dataviews-view-picker-grid__media", children: renderedMediaField }),
5628 showMedia && renderedMediaField && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5629 DataViewsSelectionCheckbox,
5630 {
5631 item,
5632 selection,
5633 onChangeSelection,
5634 getItemId,
5635 titleField,
5636 disabled: false,
5637 "aria-hidden": true,
5638 tabIndex: -1
5639 }
5640 ),
5641 showTitle && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5642 Stack,
5643 {
5644 direction: "row",
5645 justify: "space-between",
5646 className: "dataviews-view-picker-grid__title-actions",
5647 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { className: "dataviews-view-picker-grid__title-field dataviews-title-field", children: renderedTitleField })
5648 }
5649 ),
5650 /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(Stack, { direction: "column", gap: "xs", children: [
5651 showDescription && descriptionField2?.render && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5652 descriptionField2.render,
5653 {
5654 item,
5655 field: descriptionField2
5656 }
5657 ),
5658 !!badgeFields?.length && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5659 Stack,
5660 {
5661 direction: "row",
5662 className: "dataviews-view-picker-grid__badge-fields",
5663 gap: "sm",
5664 wrap: "wrap",
5665 align: "top",
5666 justify: "flex-start",
5667 children: badgeFields.map((field) => {
5668 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5669 WCBadge2,
5670 {
5671 className: "dataviews-view-picker-grid__field-value",
5672 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5673 field.render,
5674 {
5675 item,
5676 field
5677 }
5678 )
5679 },
5680 field.id
5681 );
5682 })
5683 }
5684 ),
5685 !!regularFields?.length && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5686 Stack,
5687 {
5688 direction: "column",
5689 className: "dataviews-view-picker-grid__fields",
5690 gap: "xs",
5691 children: regularFields.map((field) => {
5692 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5693 import_components14.Flex,
5694 {
5695 className: "dataviews-view-picker-grid__field",
5696 gap: 1,
5697 justify: "flex-start",
5698 expanded: true,
5699 style: { height: "auto" },
5700 direction: "row",
5701 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(import_jsx_runtime49.Fragment, { children: [
5702 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_components14.FlexItem, { className: "dataviews-view-picker-grid__field-name", children: field.header }),
5703 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5704 import_components14.FlexItem,
5705 {
5706 className: "dataviews-view-picker-grid__field-value",
5707 style: { maxHeight: "none" },
5708 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5709 field.render,
5710 {
5711 item,
5712 field
5713 }
5714 )
5715 }
5716 )
5717 ] })
5718 },
5719 field.id
5720 );
5721 })
5722 }
5723 )
5724 ] })
5725 ]
5726 },
5727 id
5728 );
5729 }
5730 function GridGroup({
5731 groupName,
5732 groupField,
5733 showLabel = true,
5734 children
5735 }) {
5736 const headerId = (0, import_compose6.useInstanceId)(
5737 GridGroup,
5738 "dataviews-view-picker-grid-group__header"
5739 );
5740 return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5741 Stack,
5742 {
5743 direction: "column",
5744 gap: "sm",
5745 role: "group",
5746 "aria-labelledby": headerId,
5747 children: [
5748 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5749 "h3",
5750 {
5751 className: "dataviews-view-picker-grid-group__header",
5752 id: headerId,
5753 children: showLabel ? (0, import_i18n23.sprintf)(
5754 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
5755 (0, import_i18n23.__)("%1$s: %2$s"),
5756 groupField.label,
5757 groupName
5758 ) : groupName
5759 }
5760 ),
5761 children
5762 ]
5763 },
5764 groupName
5765 );
5766 }
5767 function ViewPickerGrid({
5768 actions,
5769 data,
5770 fields,
5771 getItemId,
5772 isLoading,
5773 onChangeSelection,
5774 selection,
5775 view,
5776 className,
5777 empty
5778 }) {
5779 const { resizeObserverRef, paginationInfo, itemListLabel } = (0, import_element22.useContext)(dataviews_context_default);
5780 const titleField = fields.find(
5781 (field) => field.id === view?.titleField
5782 );
5783 const mediaField = fields.find(
5784 (field) => field.id === view?.mediaField
5785 );
5786 const descriptionField2 = fields.find(
5787 (field) => field.id === view?.descriptionField
5788 );
5789 const otherFields = view.fields ?? [];
5790 const { regularFields, badgeFields } = otherFields.reduce(
5791 (accumulator, fieldId) => {
5792 const field = fields.find((f2) => f2.id === fieldId);
5793 if (!field) {
5794 return accumulator;
5795 }
5796 const key = view.layout?.badgeFields?.includes(fieldId) ? "badgeFields" : "regularFields";
5797 accumulator[key].push(field);
5798 return accumulator;
5799 },
5800 { regularFields: [], badgeFields: [] }
5801 );
5802 const hasData = !!data?.length;
5803 const usedPreviewSize = view.layout?.previewSize;
5804 const isMultiselect = useIsMultiselectPicker(actions);
5805 const size = "900px";
5806 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
5807 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
5808 const isInfiniteScroll = (view.infiniteScrollEnabled && !dataByGroup) ?? false;
5809 const currentPage = view?.page ?? 1;
5810 const perPage = view?.perPage ?? 0;
5811 const setSize = isInfiniteScroll ? paginationInfo?.totalItems : void 0;
5812 const gridColumns = useGridColumns();
5813 const placeholdersNeeded = usePlaceholdersNeeded(
5814 data,
5815 isInfiniteScroll,
5816 gridColumns
5817 );
5818 return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(import_jsx_runtime49.Fragment, {
5819 // Render multiple groups.
5820 children: [
5821 hasData && groupField && dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5822 import_components14.Composite,
5823 {
5824 virtualFocus: true,
5825 orientation: "horizontal",
5826 role: "listbox",
5827 "aria-multiselectable": isMultiselect,
5828 className: clsx_default(
5829 "dataviews-view-picker-grid",
5830 className,
5831 {
5832 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
5833 view.layout.density
5834 )
5835 }
5836 ),
5837 "aria-label": itemListLabel,
5838 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5839 Stack,
5840 {
5841 direction: "column",
5842 gap: "lg",
5843 children,
5844 ...props
5845 }
5846 ),
5847 children: Array.from(dataByGroup.entries()).map(
5848 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5849 GridGroup,
5850 {
5851 groupName,
5852 groupField,
5853 showLabel: view.groupBy?.showLabel !== false,
5854 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5855 GridItems,
5856 {
5857 previewSize: usedPreviewSize,
5858 style: {
5859 gridTemplateColumns: usedPreviewSize && `repeat(auto-fill, minmax(${usedPreviewSize}px, 1fr))`
5860 },
5861 "aria-busy": isLoading,
5862 ref: resizeObserverRef,
5863 children: groupItems.map((item) => {
5864 const posInSet = item.position ?? (currentPage - 1) * perPage + data.indexOf(item) + 1;
5865 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5866 GridItem3,
5867 {
5868 view,
5869 multiselect: isMultiselect,
5870 selection,
5871 onChangeSelection,
5872 getItemId,
5873 item,
5874 mediaField,
5875 titleField,
5876 descriptionField: descriptionField2,
5877 regularFields,
5878 badgeFields,
5879 config: {
5880 sizes: size
5881 },
5882 posinset: posInSet,
5883 setsize: setSize
5884 },
5885 getItemId(item)
5886 );
5887 })
5888 }
5889 )
5890 },
5891 groupName
5892 )
5893 )
5894 }
5895 ),
5896 // Render a single grid with all data.
5897 hasData && !dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5898 import_components14.Composite,
5899 {
5900 render: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5901 GridItems,
5902 {
5903 className: clsx_default(
5904 "dataviews-view-picker-grid",
5905 className,
5906 {
5907 [`has-${view.layout?.density}-density`]: view.layout?.density && [
5908 "compact",
5909 "comfortable"
5910 ].includes(view.layout.density)
5911 }
5912 ),
5913 previewSize: usedPreviewSize,
5914 "aria-busy": isLoading,
5915 ref: resizeObserverRef
5916 }
5917 ),
5918 virtualFocus: true,
5919 orientation: "horizontal",
5920 role: "listbox",
5921 "aria-multiselectable": isMultiselect,
5922 "aria-label": itemListLabel,
5923 children: [
5924 Array.from({ length: placeholdersNeeded }).map(
5925 (_, index) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5926 import_components14.Composite.Item,
5927 {
5928 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5929 Stack,
5930 {
5931 direction: "column",
5932 children,
5933 ...props
5934 }
5935 ),
5936 role: "option",
5937 "aria-hidden": true,
5938 tabIndex: -1,
5939 className: "dataviews-view-picker-grid__card dataviews-view-picker-grid__placeholder"
5940 },
5941 `placeholder-${index}`
5942 )
5943 ),
5944 data.map((item) => {
5945 const posinset = item.position;
5946 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5947 GridItem3,
5948 {
5949 view,
5950 multiselect: isMultiselect,
5951 selection,
5952 onChangeSelection,
5953 getItemId,
5954 item,
5955 mediaField,
5956 titleField,
5957 descriptionField: descriptionField2,
5958 regularFields,
5959 badgeFields,
5960 config: {
5961 sizes: size
5962 },
5963 posinset,
5964 setsize: setSize
5965 },
5966 getItemId(item)
5967 );
5968 })
5969 ]
5970 }
5971 ),
5972 // Render empty state.
5973 !hasData && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5974 "div",
5975 {
5976 className: clsx_default({
5977 "dataviews-loading": isLoading,
5978 "dataviews-no-results": !isLoading
5979 }),
5980 children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_components14.Spinner, {}) }) : empty
5981 }
5982 ),
5983 hasData && isLoading && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_components14.Spinner, {}) })
5984 ]
5985 });
5986 }
5987 var picker_grid_default = ViewPickerGrid;
5988
5989 // packages/dataviews/build-module/components/dataviews-layouts/picker-table/index.mjs
5990 var import_i18n24 = __toESM(require_i18n(), 1);
5991 var import_components15 = __toESM(require_components(), 1);
5992 var import_element23 = __toESM(require_element(), 1);
5993 var import_jsx_runtime50 = __toESM(require_jsx_runtime(), 1);
5994 function TableColumnField2({
5995 item,
5996 fields,
5997 column,
5998 align
5999 }) {
6000 const field = fields.find((f2) => f2.id === column);
6001 if (!field) {
6002 return null;
6003 }
6004 const className = clsx_default("dataviews-view-table__cell-content-wrapper", {
6005 "dataviews-view-table__cell-align-end": align === "end",
6006 "dataviews-view-table__cell-align-center": align === "center"
6007 });
6008 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(field.render, { item, field }) });
6009 }
6010 function TableRow2({
6011 item,
6012 fields,
6013 id,
6014 view,
6015 titleField,
6016 mediaField,
6017 descriptionField: descriptionField2,
6018 selection,
6019 getItemId,
6020 onChangeSelection,
6021 multiselect,
6022 posinset
6023 }) {
6024 const { paginationInfo } = (0, import_element23.useContext)(dataviews_context_default);
6025 const isSelected2 = selection.includes(id);
6026 const [isHovered, setIsHovered] = (0, import_element23.useState)(false);
6027 const elementRef = (0, import_element23.useRef)(null);
6028 useIntersectionObserver(elementRef, posinset);
6029 const {
6030 showTitle = true,
6031 showMedia = true,
6032 showDescription = true,
6033 infiniteScrollEnabled
6034 } = view;
6035 const handleMouseEnter = () => {
6036 setIsHovered(true);
6037 };
6038 const handleMouseLeave = () => {
6039 setIsHovered(false);
6040 };
6041 const columns = view.fields ?? [];
6042 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
6043 return /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6044 import_components15.Composite.Item,
6045 {
6046 ref: elementRef,
6047 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6048 "tr",
6049 {
6050 className: clsx_default("dataviews-view-table__row", {
6051 "is-selected": isSelected2,
6052 "is-hovered": isHovered
6053 }),
6054 onMouseEnter: handleMouseEnter,
6055 onMouseLeave: handleMouseLeave,
6056 children,
6057 ...props
6058 }
6059 ),
6060 "aria-selected": isSelected2,
6061 "aria-setsize": paginationInfo.totalItems || void 0,
6062 "aria-posinset": posinset,
6063 role: infiniteScrollEnabled ? "article" : "option",
6064 onClick: () => {
6065 if (isSelected2) {
6066 onChangeSelection(
6067 selection.filter((itemId) => id !== itemId)
6068 );
6069 } else {
6070 const newSelection = multiselect ? [...selection, id] : [id];
6071 onChangeSelection(newSelection);
6072 }
6073 },
6074 children: [
6075 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6076 "td",
6077 {
6078 className: "dataviews-view-table__checkbox-column",
6079 role: "presentation",
6080 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("div", { className: "dataviews-view-table__cell-content-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6081 DataViewsSelectionCheckbox,
6082 {
6083 item,
6084 selection,
6085 onChangeSelection,
6086 getItemId,
6087 titleField,
6088 disabled: false,
6089 "aria-hidden": true,
6090 tabIndex: -1
6091 }
6092 ) })
6093 }
6094 ),
6095 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6096 "td",
6097 {
6098 role: "presentation",
6099 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6100 column_primary_default,
6101 {
6102 item,
6103 titleField: showTitle ? titleField : void 0,
6104 mediaField: showMedia ? mediaField : void 0,
6105 descriptionField: showDescription ? descriptionField2 : void 0,
6106 isItemClickable: () => false
6107 }
6108 )
6109 }
6110 ),
6111 columns.map((column) => {
6112 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
6113 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6114 "td",
6115 {
6116 style: {
6117 width,
6118 maxWidth,
6119 minWidth
6120 },
6121 role: "presentation",
6122 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6123 TableColumnField2,
6124 {
6125 fields,
6126 item,
6127 column,
6128 align
6129 }
6130 )
6131 },
6132 column
6133 );
6134 })
6135 ]
6136 },
6137 id
6138 );
6139 }
6140 function ViewPickerTable({
6141 actions,
6142 data,
6143 fields,
6144 getItemId,
6145 isLoading = false,
6146 onChangeView,
6147 onChangeSelection,
6148 selection,
6149 setOpenedFilter,
6150 view,
6151 className,
6152 empty
6153 }) {
6154 const headerMenuRefs = (0, import_element23.useRef)(/* @__PURE__ */ new Map());
6155 const headerMenuToFocusRef = (0, import_element23.useRef)(void 0);
6156 const [nextHeaderMenuToFocus, setNextHeaderMenuToFocus] = (0, import_element23.useState)();
6157 const isMultiselect = useIsMultiselectPicker(actions) ?? false;
6158 (0, import_element23.useEffect)(() => {
6159 if (headerMenuToFocusRef.current) {
6160 headerMenuToFocusRef.current.focus();
6161 headerMenuToFocusRef.current = void 0;
6162 }
6163 });
6164 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
6165 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
6166 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
6167 const tableNoticeId = (0, import_element23.useId)();
6168 if (nextHeaderMenuToFocus) {
6169 headerMenuToFocusRef.current = nextHeaderMenuToFocus;
6170 setNextHeaderMenuToFocus(void 0);
6171 return;
6172 }
6173 const onHide = (field) => {
6174 const hidden = headerMenuRefs.current.get(field.id);
6175 const fallback = hidden ? headerMenuRefs.current.get(hidden.fallback) : void 0;
6176 setNextHeaderMenuToFocus(fallback?.node);
6177 };
6178 const hasData = !!data?.length;
6179 const titleField = fields.find((field) => field.id === view.titleField);
6180 const mediaField = fields.find((field) => field.id === view.mediaField);
6181 const descriptionField2 = fields.find(
6182 (field) => field.id === view.descriptionField
6183 );
6184 const { showTitle = true, showMedia = true, showDescription = true } = view;
6185 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
6186 const columns = view.fields ?? [];
6187 const headerMenuRef = (column, index) => (node) => {
6188 if (node) {
6189 headerMenuRefs.current.set(column, {
6190 node,
6191 fallback: columns[index > 0 ? index - 1 : 1]
6192 });
6193 } else {
6194 headerMenuRefs.current.delete(column);
6195 }
6196 };
6197 return /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(import_jsx_runtime50.Fragment, { children: [
6198 /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6199 "table",
6200 {
6201 className: clsx_default(
6202 "dataviews-view-table",
6203 "dataviews-view-picker-table",
6204 className,
6205 {
6206 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
6207 view.layout.density
6208 )
6209 }
6210 ),
6211 "aria-busy": isLoading,
6212 "aria-describedby": tableNoticeId,
6213 role: isInfiniteScroll ? "feed" : "listbox",
6214 children: [
6215 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("thead", { role: "presentation", children: /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6216 "tr",
6217 {
6218 className: "dataviews-view-table__row",
6219 role: "presentation",
6220 children: [
6221 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("th", { className: "dataviews-view-table__checkbox-column", children: isMultiselect && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6222 BulkSelectionCheckbox,
6223 {
6224 selection,
6225 onChangeSelection,
6226 data,
6227 actions,
6228 getItemId,
6229 disableSelectAll: isInfiniteScroll
6230 }
6231 ) }),
6232 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("th", { children: titleField && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6233 column_header_menu_default,
6234 {
6235 ref: headerMenuRef(
6236 titleField.id,
6237 0
6238 ),
6239 fieldId: titleField.id,
6240 view,
6241 fields,
6242 onChangeView,
6243 onHide,
6244 setOpenedFilter,
6245 canMove: false
6246 }
6247 ) }),
6248 columns.map((column, index) => {
6249 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
6250 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6251 "th",
6252 {
6253 style: {
6254 width,
6255 maxWidth,
6256 minWidth,
6257 textAlign: align
6258 },
6259 "aria-sort": view.sort?.direction && view.sort?.field === column ? sortValues[view.sort.direction] : void 0,
6260 scope: "col",
6261 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6262 column_header_menu_default,
6263 {
6264 ref: headerMenuRef(column, index),
6265 fieldId: column,
6266 view,
6267 fields,
6268 onChangeView,
6269 onHide,
6270 setOpenedFilter,
6271 canMove: view.layout?.enableMoving ?? true
6272 }
6273 )
6274 },
6275 column
6276 );
6277 })
6278 ]
6279 }
6280 ) }),
6281 hasData && groupField && dataByGroup ? Array.from(dataByGroup.entries()).map(
6282 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6283 import_components15.Composite,
6284 {
6285 virtualFocus: true,
6286 orientation: "vertical",
6287 render: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("tbody", { role: "group" }),
6288 children: [
6289 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6290 "tr",
6291 {
6292 className: "dataviews-view-table__group-header-row",
6293 role: "presentation",
6294 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6295 "td",
6296 {
6297 colSpan: columns.length + (hasPrimaryColumn ? 1 : 0) + 1,
6298 className: "dataviews-view-table__group-header-cell",
6299 role: "presentation",
6300 children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n24.sprintf)(
6301 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
6302 (0, import_i18n24.__)("%1$s: %2$s"),
6303 groupField.label,
6304 groupName
6305 )
6306 }
6307 )
6308 }
6309 ),
6310 groupItems.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6311 TableRow2,
6312 {
6313 item,
6314 fields,
6315 id: getItemId(item) || index.toString(),
6316 view,
6317 titleField,
6318 mediaField,
6319 descriptionField: descriptionField2,
6320 selection,
6321 getItemId,
6322 onChangeSelection,
6323 multiselect: isMultiselect
6324 },
6325 getItemId(item)
6326 ))
6327 ]
6328 },
6329 `group-${groupName}`
6330 )
6331 ) : /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6332 import_components15.Composite,
6333 {
6334 render: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("tbody", { role: "presentation" }),
6335 virtualFocus: true,
6336 orientation: "vertical",
6337 children: hasData && data.map((item, index) => {
6338 const itemId = getItemId(item);
6339 const posinset = item.position;
6340 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6341 TableRow2,
6342 {
6343 item,
6344 fields,
6345 id: itemId || index.toString(),
6346 view,
6347 titleField,
6348 mediaField,
6349 descriptionField: descriptionField2,
6350 selection,
6351 getItemId,
6352 onChangeSelection,
6353 multiselect: isMultiselect,
6354 posinset
6355 },
6356 itemId
6357 );
6358 })
6359 }
6360 )
6361 ]
6362 }
6363 ),
6364 /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6365 "div",
6366 {
6367 className: clsx_default({
6368 "dataviews-loading": isLoading,
6369 "dataviews-no-results": !hasData && !isLoading
6370 }),
6371 id: tableNoticeId,
6372 children: [
6373 !hasData && (isLoading ? /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(import_components15.Spinner, {}) }) : empty),
6374 hasData && isLoading && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(import_components15.Spinner, {}) })
6375 ]
6376 }
6377 )
6378 ] });
6379 }
6380 var picker_table_default = ViewPickerTable;
6381
6382 // packages/dataviews/build-module/components/dataviews-layouts/utils/density-picker.mjs
6383 var import_components16 = __toESM(require_components(), 1);
6384 var import_i18n25 = __toESM(require_i18n(), 1);
6385 var import_element24 = __toESM(require_element(), 1);
6386 var import_jsx_runtime51 = __toESM(require_jsx_runtime(), 1);
6387 function DensityPicker() {
6388 const context = (0, import_element24.useContext)(dataviews_context_default);
6389 const view = context.view;
6390 return /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)(
6391 import_components16.__experimentalToggleGroupControl,
6392 {
6393 size: "__unstable-large",
6394 label: (0, import_i18n25.__)("Density"),
6395 value: view.layout?.density || "balanced",
6396 onChange: (value) => {
6397 context.onChangeView({
6398 ...view,
6399 layout: {
6400 ...view.layout,
6401 density: value
6402 }
6403 });
6404 },
6405 isBlock: true,
6406 children: [
6407 /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
6408 import_components16.__experimentalToggleGroupControlOption,
6409 {
6410 value: "comfortable",
6411 label: (0, import_i18n25._x)(
6412 "Comfortable",
6413 "Density option for DataView layout"
6414 )
6415 },
6416 "comfortable"
6417 ),
6418 /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
6419 import_components16.__experimentalToggleGroupControlOption,
6420 {
6421 value: "balanced",
6422 label: (0, import_i18n25._x)("Balanced", "Density option for DataView layout")
6423 },
6424 "balanced"
6425 ),
6426 /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
6427 import_components16.__experimentalToggleGroupControlOption,
6428 {
6429 value: "compact",
6430 label: (0, import_i18n25._x)("Compact", "Density option for DataView layout")
6431 },
6432 "compact"
6433 )
6434 ]
6435 }
6436 );
6437 }
6438
6439 // packages/dataviews/build-module/components/dataviews-layouts/utils/preview-size-picker.mjs
6440 var import_components17 = __toESM(require_components(), 1);
6441 var import_i18n26 = __toESM(require_i18n(), 1);
6442 var import_element25 = __toESM(require_element(), 1);
6443 var import_jsx_runtime52 = __toESM(require_jsx_runtime(), 1);
6444 var imageSizes2 = [
6445 {
6446 value: 120,
6447 breakpoint: 1
6448 },
6449 {
6450 value: 170,
6451 breakpoint: 1
6452 },
6453 {
6454 value: 230,
6455 breakpoint: 1
6456 },
6457 {
6458 value: 290,
6459 breakpoint: 1112
6460 // at minimum image width, 4 images display at this container size
6461 },
6462 {
6463 value: 350,
6464 breakpoint: 1636
6465 // at minimum image width, 6 images display at this container size
6466 },
6467 {
6468 value: 430,
6469 breakpoint: 588
6470 // at minimum image width, 2 images display at this container size
6471 }
6472 ];
6473 function PreviewSizePicker() {
6474 const context = (0, import_element25.useContext)(dataviews_context_default);
6475 const view = context.view;
6476 const breakValues = imageSizes2.filter((size) => {
6477 return context.containerWidth >= size.breakpoint;
6478 });
6479 const layoutPreviewSize = view.layout?.previewSize ?? 230;
6480 const previewSizeToUse = breakValues.map((size, index) => ({ ...size, index })).filter((size) => size.value <= layoutPreviewSize).sort((a2, b2) => b2.value - a2.value)[0]?.index ?? 0;
6481 const marks = breakValues.map((size, index) => {
6482 return {
6483 value: index
6484 };
6485 });
6486 return /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(
6487 import_components17.RangeControl,
6488 {
6489 __next40pxDefaultSize: true,
6490 showTooltip: false,
6491 label: (0, import_i18n26.__)("Preview size"),
6492 value: previewSizeToUse,
6493 min: 0,
6494 max: breakValues.length - 1,
6495 withInputField: false,
6496 onChange: (value = 0) => {
6497 context.onChangeView({
6498 ...view,
6499 layout: {
6500 ...view.layout,
6501 previewSize: breakValues[value].value
6502 }
6503 });
6504 },
6505 step: 1,
6506 marks
6507 }
6508 );
6509 }
6510
6511 // packages/dataviews/build-module/components/dataviews-layouts/utils/grid-config-options.mjs
6512 var import_jsx_runtime53 = __toESM(require_jsx_runtime(), 1);
6513 function GridConfigOptions() {
6514 return /* @__PURE__ */ (0, import_jsx_runtime53.jsxs)(import_jsx_runtime53.Fragment, { children: [
6515 /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(DensityPicker, {}),
6516 /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(PreviewSizePicker, {})
6517 ] });
6518 }
6519
6520 // packages/dataviews/build-module/components/dataviews-layouts/index.mjs
6521 var VIEW_LAYOUTS = [
6522 {
6523 type: LAYOUT_TABLE,
6524 label: (0, import_i18n27.__)("Table"),
6525 component: table_default,
6526 icon: block_table_default,
6527 viewConfigOptions: DensityPicker
6528 },
6529 {
6530 type: LAYOUT_GRID,
6531 label: (0, import_i18n27.__)("Grid"),
6532 component: grid_default,
6533 icon: category_default,
6534 viewConfigOptions: GridConfigOptions
6535 },
6536 {
6537 type: LAYOUT_LIST,
6538 label: (0, import_i18n27.__)("List"),
6539 component: ViewList,
6540 icon: (0, import_i18n27.isRTL)() ? format_list_bullets_rtl_default : format_list_bullets_default,
6541 viewConfigOptions: DensityPicker
6542 },
6543 {
6544 type: LAYOUT_ACTIVITY,
6545 label: (0, import_i18n27.__)("Activity"),
6546 component: ViewActivity,
6547 icon: scheduled_default,
6548 viewConfigOptions: DensityPicker
6549 },
6550 {
6551 type: LAYOUT_PICKER_GRID,
6552 label: (0, import_i18n27.__)("Grid"),
6553 component: picker_grid_default,
6554 icon: category_default,
6555 viewConfigOptions: GridConfigOptions,
6556 isPicker: true
6557 },
6558 {
6559 type: LAYOUT_PICKER_TABLE,
6560 label: (0, import_i18n27.__)("Table"),
6561 component: picker_table_default,
6562 icon: block_table_default,
6563 viewConfigOptions: DensityPicker,
6564 isPicker: true
6565 }
6566 ];
6567
6568 // packages/dataviews/build-module/components/dataviews-filters/filters.mjs
6569 var import_element33 = __toESM(require_element(), 1);
6570
6571 // packages/dataviews/build-module/components/dataviews-filters/filter.mjs
6572 var import_components20 = __toESM(require_components(), 1);
6573 var import_i18n30 = __toESM(require_i18n(), 1);
6574 var import_element30 = __toESM(require_element(), 1);
6575
6576 // node_modules/@ariakit/core/esm/__chunks/XMCVU3LR.js
6577 function noop2(..._) {
6578 }
6579 function applyState(argument, currentValue) {
6580 if (isUpdater(argument)) {
6581 const value = isLazyValue(currentValue) ? currentValue() : currentValue;
6582 return argument(value);
6583 }
6584 return argument;
6585 }
6586 function isUpdater(argument) {
6587 return typeof argument === "function";
6588 }
6589 function isLazyValue(value) {
6590 return typeof value === "function";
6591 }
6592 function hasOwnProperty(object, prop) {
6593 if (typeof Object.hasOwn === "function") {
6594 return Object.hasOwn(object, prop);
6595 }
6596 return Object.prototype.hasOwnProperty.call(object, prop);
6597 }
6598 function chain(...fns) {
6599 return (...args) => {
6600 for (const fn of fns) {
6601 if (typeof fn === "function") {
6602 fn(...args);
6603 }
6604 }
6605 };
6606 }
6607 function normalizeString(str) {
6608 return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
6609 }
6610 function omit(object, keys) {
6611 const result = { ...object };
6612 for (const key of keys) {
6613 if (hasOwnProperty(result, key)) {
6614 delete result[key];
6615 }
6616 }
6617 return result;
6618 }
6619 function pick(object, paths) {
6620 const result = {};
6621 for (const key of paths) {
6622 if (hasOwnProperty(object, key)) {
6623 result[key] = object[key];
6624 }
6625 }
6626 return result;
6627 }
6628 function identity(value) {
6629 return value;
6630 }
6631 function invariant(condition, message2) {
6632 if (condition) return;
6633 if (typeof message2 !== "string") throw new Error("Invariant failed");
6634 throw new Error(message2);
6635 }
6636 function getKeys(obj) {
6637 return Object.keys(obj);
6638 }
6639 function isFalsyBooleanCallback(booleanOrCallback, ...args) {
6640 const result = typeof booleanOrCallback === "function" ? booleanOrCallback(...args) : booleanOrCallback;
6641 if (result == null) return false;
6642 return !result;
6643 }
6644 function disabledFromProps(props) {
6645 return props.disabled || props["aria-disabled"] === true || props["aria-disabled"] === "true";
6646 }
6647 function removeUndefinedValues(obj) {
6648 const result = {};
6649 for (const key in obj) {
6650 if (obj[key] !== void 0) {
6651 result[key] = obj[key];
6652 }
6653 }
6654 return result;
6655 }
6656 function defaultValue(...values) {
6657 for (const value of values) {
6658 if (value !== void 0) return value;
6659 }
6660 return void 0;
6661 }
6662
6663 // node_modules/@ariakit/react-core/esm/__chunks/YXGXYGQX.js
6664 var import_react5 = __toESM(require_react(), 1);
6665 function setRef(ref, value) {
6666 if (typeof ref === "function") {
6667 ref(value);
6668 } else if (ref) {
6669 ref.current = value;
6670 }
6671 }
6672 function isValidElementWithRef(element) {
6673 if (!element) return false;
6674 if (!(0, import_react5.isValidElement)(element)) return false;
6675 if ("ref" in element.props) return true;
6676 if ("ref" in element) return true;
6677 return false;
6678 }
6679 function getRefProperty(element) {
6680 if (!isValidElementWithRef(element)) return null;
6681 const props = { ...element.props };
6682 return props.ref || element.ref;
6683 }
6684 function mergeProps2(base, overrides) {
6685 const props = { ...base };
6686 for (const key in overrides) {
6687 if (!hasOwnProperty(overrides, key)) continue;
6688 if (key === "className") {
6689 const prop = "className";
6690 props[prop] = base[prop] ? `${base[prop]} ${overrides[prop]}` : overrides[prop];
6691 continue;
6692 }
6693 if (key === "style") {
6694 const prop = "style";
6695 props[prop] = base[prop] ? { ...base[prop], ...overrides[prop] } : overrides[prop];
6696 continue;
6697 }
6698 const overrideValue = overrides[key];
6699 if (typeof overrideValue === "function" && key.startsWith("on")) {
6700 const baseValue = base[key];
6701 if (typeof baseValue === "function") {
6702 props[key] = (...args) => {
6703 overrideValue(...args);
6704 baseValue(...args);
6705 };
6706 continue;
6707 }
6708 }
6709 props[key] = overrideValue;
6710 }
6711 return props;
6712 }
6713
6714 // node_modules/@ariakit/core/esm/__chunks/3DNM6L6E.js
6715 var canUseDOM = checkIsBrowser();
6716 function checkIsBrowser() {
6717 var _a;
6718 return typeof window !== "undefined" && !!((_a = window.document) == null ? void 0 : _a.createElement);
6719 }
6720 function getDocument(node) {
6721 if (!node) return document;
6722 if ("self" in node) return node.document;
6723 return node.ownerDocument || document;
6724 }
6725 function getActiveElement(node, activeDescendant = false) {
6726 var _a;
6727 const { activeElement } = getDocument(node);
6728 if (!(activeElement == null ? void 0 : activeElement.nodeName)) {
6729 return null;
6730 }
6731 if (isFrame(activeElement) && ((_a = activeElement.contentDocument) == null ? void 0 : _a.body)) {
6732 return getActiveElement(
6733 activeElement.contentDocument.body,
6734 activeDescendant
6735 );
6736 }
6737 if (activeDescendant) {
6738 const id = activeElement.getAttribute("aria-activedescendant");
6739 if (id) {
6740 const element = getDocument(activeElement).getElementById(id);
6741 if (element) {
6742 return element;
6743 }
6744 }
6745 }
6746 return activeElement;
6747 }
6748 function contains(parent, child) {
6749 return parent === child || parent.contains(child);
6750 }
6751 function isFrame(element) {
6752 return element.tagName === "IFRAME";
6753 }
6754 function isButton(element) {
6755 const tagName = element.tagName.toLowerCase();
6756 if (tagName === "button") return true;
6757 if (tagName === "input" && element.type) {
6758 return buttonInputTypes.indexOf(element.type) !== -1;
6759 }
6760 return false;
6761 }
6762 var buttonInputTypes = [
6763 "button",
6764 "color",
6765 "file",
6766 "image",
6767 "reset",
6768 "submit"
6769 ];
6770 function isVisible(element) {
6771 if (typeof element.checkVisibility === "function") {
6772 return element.checkVisibility();
6773 }
6774 const htmlElement = element;
6775 return htmlElement.offsetWidth > 0 || htmlElement.offsetHeight > 0 || element.getClientRects().length > 0;
6776 }
6777 function isTextField(element) {
6778 try {
6779 const isTextInput = element instanceof HTMLInputElement && element.selectionStart !== null;
6780 const isTextArea = element.tagName === "TEXTAREA";
6781 return isTextInput || isTextArea || false;
6782 } catch (_error) {
6783 return false;
6784 }
6785 }
6786 function isTextbox(element) {
6787 return element.isContentEditable || isTextField(element);
6788 }
6789 function getTextboxValue(element) {
6790 if (isTextField(element)) {
6791 return element.value;
6792 }
6793 if (element.isContentEditable) {
6794 const range = getDocument(element).createRange();
6795 range.selectNodeContents(element);
6796 return range.toString();
6797 }
6798 return "";
6799 }
6800 function getTextboxSelection(element) {
6801 let start = 0;
6802 let end = 0;
6803 if (isTextField(element)) {
6804 start = element.selectionStart || 0;
6805 end = element.selectionEnd || 0;
6806 } else if (element.isContentEditable) {
6807 const selection = getDocument(element).getSelection();
6808 if ((selection == null ? void 0 : selection.rangeCount) && selection.anchorNode && contains(element, selection.anchorNode) && selection.focusNode && contains(element, selection.focusNode)) {
6809 const range = selection.getRangeAt(0);
6810 const nextRange = range.cloneRange();
6811 nextRange.selectNodeContents(element);
6812 nextRange.setEnd(range.startContainer, range.startOffset);
6813 start = nextRange.toString().length;
6814 nextRange.setEnd(range.endContainer, range.endOffset);
6815 end = nextRange.toString().length;
6816 }
6817 }
6818 return { start, end };
6819 }
6820 function getPopupRole(element, fallback) {
6821 const allowedPopupRoles = ["dialog", "menu", "listbox", "tree", "grid"];
6822 const role = element == null ? void 0 : element.getAttribute("role");
6823 if (role && allowedPopupRoles.indexOf(role) !== -1) {
6824 return role;
6825 }
6826 return fallback;
6827 }
6828 function getScrollingElement(element) {
6829 if (!element) return null;
6830 const isScrollableOverflow = (overflow) => {
6831 if (overflow === "auto") return true;
6832 if (overflow === "scroll") return true;
6833 return false;
6834 };
6835 if (element.clientHeight && element.scrollHeight > element.clientHeight) {
6836 const { overflowY } = getComputedStyle(element);
6837 if (isScrollableOverflow(overflowY)) return element;
6838 } else if (element.clientWidth && element.scrollWidth > element.clientWidth) {
6839 const { overflowX } = getComputedStyle(element);
6840 if (isScrollableOverflow(overflowX)) return element;
6841 }
6842 return getScrollingElement(element.parentElement) || document.scrollingElement || document.body;
6843 }
6844 function setSelectionRange(element, ...args) {
6845 if (/text|search|password|tel|url/i.test(element.type)) {
6846 element.setSelectionRange(...args);
6847 }
6848 }
6849 function sortBasedOnDOMPosition(items, getElement) {
6850 const pairs = items.map((item, index) => [index, item]);
6851 let isOrderDifferent = false;
6852 pairs.sort(([indexA, a2], [indexB, b2]) => {
6853 const elementA = getElement(a2);
6854 const elementB = getElement(b2);
6855 if (elementA === elementB) return 0;
6856 if (!elementA || !elementB) return 0;
6857 if (isElementPreceding(elementA, elementB)) {
6858 if (indexA > indexB) {
6859 isOrderDifferent = true;
6860 }
6861 return -1;
6862 }
6863 if (indexA < indexB) {
6864 isOrderDifferent = true;
6865 }
6866 return 1;
6867 });
6868 if (isOrderDifferent) {
6869 return pairs.map(([_, item]) => item);
6870 }
6871 return items;
6872 }
6873 function isElementPreceding(a2, b2) {
6874 return Boolean(
6875 b2.compareDocumentPosition(a2) & Node.DOCUMENT_POSITION_PRECEDING
6876 );
6877 }
6878
6879 // node_modules/@ariakit/core/esm/__chunks/SNHYQNEZ.js
6880 function isTouchDevice() {
6881 return canUseDOM && !!navigator.maxTouchPoints;
6882 }
6883 function isApple() {
6884 if (!canUseDOM) return false;
6885 return /mac|iphone|ipad|ipod/i.test(navigator.platform);
6886 }
6887 function isSafari() {
6888 return canUseDOM && isApple() && /apple/i.test(navigator.vendor);
6889 }
6890 function isFirefox() {
6891 return canUseDOM && /firefox\//i.test(navigator.userAgent);
6892 }
6893
6894 // node_modules/@ariakit/core/esm/utils/events.js
6895 function isPortalEvent(event) {
6896 return Boolean(
6897 event.currentTarget && !contains(event.currentTarget, event.target)
6898 );
6899 }
6900 function isSelfTarget(event) {
6901 return event.target === event.currentTarget;
6902 }
6903 function isOpeningInNewTab(event) {
6904 const element = event.currentTarget;
6905 if (!element) return false;
6906 const isAppleDevice = isApple();
6907 if (isAppleDevice && !event.metaKey) return false;
6908 if (!isAppleDevice && !event.ctrlKey) return false;
6909 const tagName = element.tagName.toLowerCase();
6910 if (tagName === "a") return true;
6911 if (tagName === "button" && element.type === "submit") return true;
6912 if (tagName === "input" && element.type === "submit") return true;
6913 return false;
6914 }
6915 function isDownloading(event) {
6916 const element = event.currentTarget;
6917 if (!element) return false;
6918 const tagName = element.tagName.toLowerCase();
6919 if (!event.altKey) return false;
6920 if (tagName === "a") return true;
6921 if (tagName === "button" && element.type === "submit") return true;
6922 if (tagName === "input" && element.type === "submit") return true;
6923 return false;
6924 }
6925 function fireBlurEvent(element, eventInit) {
6926 const event = new FocusEvent("blur", eventInit);
6927 const defaultAllowed = element.dispatchEvent(event);
6928 const bubbleInit = { ...eventInit, bubbles: true };
6929 element.dispatchEvent(new FocusEvent("focusout", bubbleInit));
6930 return defaultAllowed;
6931 }
6932 function fireKeyboardEvent(element, type, eventInit) {
6933 const event = new KeyboardEvent(type, eventInit);
6934 return element.dispatchEvent(event);
6935 }
6936 function fireClickEvent(element, eventInit) {
6937 const event = new MouseEvent("click", eventInit);
6938 return element.dispatchEvent(event);
6939 }
6940 function isFocusEventOutside(event, container) {
6941 const containerElement = container || event.currentTarget;
6942 const relatedTarget = event.relatedTarget;
6943 return !relatedTarget || !contains(containerElement, relatedTarget);
6944 }
6945 function queueBeforeEvent(element, type, callback, timeout) {
6946 const createTimer = (callback2) => {
6947 if (timeout) {
6948 const timerId2 = setTimeout(callback2, timeout);
6949 return () => clearTimeout(timerId2);
6950 }
6951 const timerId = requestAnimationFrame(callback2);
6952 return () => cancelAnimationFrame(timerId);
6953 };
6954 const cancelTimer = createTimer(() => {
6955 element.removeEventListener(type, callSync, true);
6956 callback();
6957 });
6958 const callSync = () => {
6959 cancelTimer();
6960 callback();
6961 };
6962 element.addEventListener(type, callSync, { once: true, capture: true });
6963 return cancelTimer;
6964 }
6965 function addGlobalEventListener(type, listener, options, scope = window) {
6966 const children = [];
6967 try {
6968 scope.document.addEventListener(type, listener, options);
6969 for (const frame of Array.from(scope.frames)) {
6970 children.push(addGlobalEventListener(type, listener, options, frame));
6971 }
6972 } catch (e2) {
6973 }
6974 const removeEventListener = () => {
6975 try {
6976 scope.document.removeEventListener(type, listener, options);
6977 } catch (e2) {
6978 }
6979 for (const remove of children) {
6980 remove();
6981 }
6982 };
6983 return removeEventListener;
6984 }
6985
6986 // node_modules/@ariakit/react-core/esm/__chunks/KPHZR4MB.js
6987 var React5 = __toESM(require_react(), 1);
6988 var import_react6 = __toESM(require_react(), 1);
6989 var _React = { ...React5 };
6990 var useReactId = _React.useId;
6991 var useReactDeferredValue = _React.useDeferredValue;
6992 var useReactInsertionEffect = _React.useInsertionEffect;
6993 var useSafeLayoutEffect = canUseDOM ? import_react6.useLayoutEffect : import_react6.useEffect;
6994 function useInitialValue(value) {
6995 const [initialValue] = (0, import_react6.useState)(value);
6996 return initialValue;
6997 }
6998 function useLiveRef(value) {
6999 const ref = (0, import_react6.useRef)(value);
7000 useSafeLayoutEffect(() => {
7001 ref.current = value;
7002 });
7003 return ref;
7004 }
7005 function useEvent(callback) {
7006 const ref = (0, import_react6.useRef)(() => {
7007 throw new Error("Cannot call an event handler while rendering.");
7008 });
7009 if (useReactInsertionEffect) {
7010 useReactInsertionEffect(() => {
7011 ref.current = callback;
7012 });
7013 } else {
7014 ref.current = callback;
7015 }
7016 return (0, import_react6.useCallback)((...args) => {
7017 var _a;
7018 return (_a = ref.current) == null ? void 0 : _a.call(ref, ...args);
7019 }, []);
7020 }
7021 function useTransactionState(callback) {
7022 const [state, setState] = (0, import_react6.useState)(null);
7023 useSafeLayoutEffect(() => {
7024 if (state == null) return;
7025 if (!callback) return;
7026 let prevState = null;
7027 callback((prev) => {
7028 prevState = prev;
7029 return state;
7030 });
7031 return () => {
7032 callback(prevState);
7033 };
7034 }, [state, callback]);
7035 return [state, setState];
7036 }
7037 function useMergeRefs(...refs) {
7038 return (0, import_react6.useMemo)(() => {
7039 if (!refs.some(Boolean)) return;
7040 return (value) => {
7041 for (const ref of refs) {
7042 setRef(ref, value);
7043 }
7044 };
7045 }, refs);
7046 }
7047 function useId3(defaultId) {
7048 if (useReactId) {
7049 const reactId = useReactId();
7050 if (defaultId) return defaultId;
7051 return reactId;
7052 }
7053 const [id, setId] = (0, import_react6.useState)(defaultId);
7054 useSafeLayoutEffect(() => {
7055 if (defaultId || id) return;
7056 const random = Math.random().toString(36).slice(2, 8);
7057 setId(`id-${random}`);
7058 }, [defaultId, id]);
7059 return defaultId || id;
7060 }
7061 function useTagName(refOrElement, type) {
7062 const stringOrUndefined = (type2) => {
7063 if (typeof type2 !== "string") return;
7064 return type2;
7065 };
7066 const [tagName, setTagName] = (0, import_react6.useState)(() => stringOrUndefined(type));
7067 useSafeLayoutEffect(() => {
7068 const element = refOrElement && "current" in refOrElement ? refOrElement.current : refOrElement;
7069 setTagName((element == null ? void 0 : element.tagName.toLowerCase()) || stringOrUndefined(type));
7070 }, [refOrElement, type]);
7071 return tagName;
7072 }
7073 function useAttribute(refOrElement, attributeName, defaultValue2) {
7074 const initialValue = useInitialValue(defaultValue2);
7075 const [attribute, setAttribute] = (0, import_react6.useState)(initialValue);
7076 (0, import_react6.useEffect)(() => {
7077 const element = refOrElement && "current" in refOrElement ? refOrElement.current : refOrElement;
7078 if (!element) return;
7079 const callback = () => {
7080 const value = element.getAttribute(attributeName);
7081 setAttribute(value == null ? initialValue : value);
7082 };
7083 const observer = new MutationObserver(callback);
7084 observer.observe(element, { attributeFilter: [attributeName] });
7085 callback();
7086 return () => observer.disconnect();
7087 }, [refOrElement, attributeName, initialValue]);
7088 return attribute;
7089 }
7090 function useUpdateEffect(effect, deps) {
7091 const mounted = (0, import_react6.useRef)(false);
7092 (0, import_react6.useEffect)(() => {
7093 if (mounted.current) {
7094 return effect();
7095 }
7096 mounted.current = true;
7097 }, deps);
7098 (0, import_react6.useEffect)(
7099 () => () => {
7100 mounted.current = false;
7101 },
7102 []
7103 );
7104 }
7105 function useUpdateLayoutEffect(effect, deps) {
7106 const mounted = (0, import_react6.useRef)(false);
7107 useSafeLayoutEffect(() => {
7108 if (mounted.current) {
7109 return effect();
7110 }
7111 mounted.current = true;
7112 }, deps);
7113 useSafeLayoutEffect(
7114 () => () => {
7115 mounted.current = false;
7116 },
7117 []
7118 );
7119 }
7120 function useForceUpdate() {
7121 return (0, import_react6.useReducer)(() => [], []);
7122 }
7123 function useBooleanEvent(booleanOrCallback) {
7124 return useEvent(
7125 typeof booleanOrCallback === "function" ? booleanOrCallback : () => booleanOrCallback
7126 );
7127 }
7128 function useWrapElement(props, callback, deps = []) {
7129 const wrapElement = (0, import_react6.useCallback)(
7130 (element) => {
7131 if (props.wrapElement) {
7132 element = props.wrapElement(element);
7133 }
7134 return callback(element);
7135 },
7136 [...deps, props.wrapElement]
7137 );
7138 return { ...props, wrapElement };
7139 }
7140 function useMetadataProps(props, key, value) {
7141 const parent = props.onLoadedMetadataCapture;
7142 const onLoadedMetadataCapture = (0, import_react6.useMemo)(() => {
7143 return Object.assign(() => {
7144 }, { ...parent, [key]: value });
7145 }, [parent, key, value]);
7146 return [parent == null ? void 0 : parent[key], { onLoadedMetadataCapture }];
7147 }
7148 var hasInstalledGlobalEventListeners = false;
7149 function useIsMouseMoving() {
7150 (0, import_react6.useEffect)(() => {
7151 if (hasInstalledGlobalEventListeners) return;
7152 addGlobalEventListener("mousemove", setMouseMoving, true);
7153 addGlobalEventListener("mousedown", resetMouseMoving, true);
7154 addGlobalEventListener("mouseup", resetMouseMoving, true);
7155 addGlobalEventListener("keydown", resetMouseMoving, true);
7156 addGlobalEventListener("scroll", resetMouseMoving, true);
7157 hasInstalledGlobalEventListeners = true;
7158 }, []);
7159 const isMouseMoving = useEvent(() => mouseMoving);
7160 return isMouseMoving;
7161 }
7162 var mouseMoving = false;
7163 var previousScreenX = 0;
7164 var previousScreenY = 0;
7165 function hasMouseMovement(event) {
7166 const movementX = event.movementX || event.screenX - previousScreenX;
7167 const movementY = event.movementY || event.screenY - previousScreenY;
7168 previousScreenX = event.screenX;
7169 previousScreenY = event.screenY;
7170 return movementX || movementY || false;
7171 }
7172 function setMouseMoving(event) {
7173 if (!hasMouseMovement(event)) return;
7174 mouseMoving = true;
7175 }
7176 function resetMouseMoving() {
7177 mouseMoving = false;
7178 }
7179
7180 // node_modules/@ariakit/react-core/esm/__chunks/GWSL6KNJ.js
7181 var React6 = __toESM(require_react(), 1);
7182 var import_jsx_runtime54 = __toESM(require_jsx_runtime(), 1);
7183 function forwardRef22(render4) {
7184 const Role = React6.forwardRef(
7185 // @ts-ignore Incompatible with React 19 types. Ignore for now.
7186 (props, ref) => render4({ ...props, ref })
7187 );
7188 Role.displayName = render4.displayName || render4.name;
7189 return Role;
7190 }
7191 function memo22(Component2, propsAreEqual) {
7192 return React6.memo(Component2, propsAreEqual);
7193 }
7194 function createElement3(Type, props) {
7195 const { wrapElement, render: render4, ...rest } = props;
7196 const mergedRef = useMergeRefs(props.ref, getRefProperty(render4));
7197 let element;
7198 if (React6.isValidElement(render4)) {
7199 const renderProps = {
7200 // @ts-ignore Incompatible with React 19 types. Ignore for now.
7201 ...render4.props,
7202 ref: mergedRef
7203 };
7204 element = React6.cloneElement(render4, mergeProps2(rest, renderProps));
7205 } else if (render4) {
7206 element = render4(rest);
7207 } else {
7208 element = /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(Type, { ...rest });
7209 }
7210 if (wrapElement) {
7211 return wrapElement(element);
7212 }
7213 return element;
7214 }
7215 function createHook(useProps) {
7216 const useRole = (props = {}) => {
7217 return useProps(props);
7218 };
7219 useRole.displayName = useProps.name;
7220 return useRole;
7221 }
7222 function createStoreContext(providers = [], scopedProviders = []) {
7223 const context = React6.createContext(void 0);
7224 const scopedContext = React6.createContext(void 0);
7225 const useContext28 = () => React6.useContext(context);
7226 const useScopedContext = (onlyScoped = false) => {
7227 const scoped = React6.useContext(scopedContext);
7228 const store = useContext28();
7229 if (onlyScoped) return scoped;
7230 return scoped || store;
7231 };
7232 const useProviderContext = () => {
7233 const scoped = React6.useContext(scopedContext);
7234 const store = useContext28();
7235 if (scoped && scoped === store) return;
7236 return store;
7237 };
7238 const ContextProvider = (props) => {
7239 return providers.reduceRight(
7240 (children, Provider) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(Provider, { ...props, children }),
7241 /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(context.Provider, { ...props })
7242 );
7243 };
7244 const ScopedContextProvider = (props) => {
7245 return /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(ContextProvider, { ...props, children: scopedProviders.reduceRight(
7246 (children, Provider) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(Provider, { ...props, children }),
7247 /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(scopedContext.Provider, { ...props })
7248 ) });
7249 };
7250 return {
7251 context,
7252 scopedContext,
7253 useContext: useContext28,
7254 useScopedContext,
7255 useProviderContext,
7256 ContextProvider,
7257 ScopedContextProvider
7258 };
7259 }
7260
7261 // node_modules/@ariakit/react-core/esm/__chunks/SMPCIMZM.js
7262 var ctx = createStoreContext();
7263 var useCollectionContext = ctx.useContext;
7264 var useCollectionScopedContext = ctx.useScopedContext;
7265 var useCollectionProviderContext = ctx.useProviderContext;
7266 var CollectionContextProvider = ctx.ContextProvider;
7267 var CollectionScopedContextProvider = ctx.ScopedContextProvider;
7268
7269 // node_modules/@ariakit/react-core/esm/__chunks/AVVXDJMZ.js
7270 var import_react7 = __toESM(require_react(), 1);
7271 var ctx2 = createStoreContext(
7272 [CollectionContextProvider],
7273 [CollectionScopedContextProvider]
7274 );
7275 var useCompositeContext = ctx2.useContext;
7276 var useCompositeScopedContext = ctx2.useScopedContext;
7277 var useCompositeProviderContext = ctx2.useProviderContext;
7278 var CompositeContextProvider = ctx2.ContextProvider;
7279 var CompositeScopedContextProvider = ctx2.ScopedContextProvider;
7280 var CompositeItemContext = (0, import_react7.createContext)(
7281 void 0
7282 );
7283 var CompositeRowContext = (0, import_react7.createContext)(
7284 void 0
7285 );
7286
7287 // node_modules/@ariakit/react-core/esm/__chunks/5VQZOHHZ.js
7288 function findFirstEnabledItem(items, excludeId) {
7289 return items.find((item) => {
7290 if (excludeId) {
7291 return !item.disabled && item.id !== excludeId;
7292 }
7293 return !item.disabled;
7294 });
7295 }
7296 function getEnabledItem(store, id) {
7297 if (!id) return null;
7298 return store.item(id) || null;
7299 }
7300 function groupItemsByRows(items) {
7301 const rows = [];
7302 for (const item of items) {
7303 const row = rows.find((currentRow) => {
7304 var _a;
7305 return ((_a = currentRow[0]) == null ? void 0 : _a.rowId) === item.rowId;
7306 });
7307 if (row) {
7308 row.push(item);
7309 } else {
7310 rows.push([item]);
7311 }
7312 }
7313 return rows;
7314 }
7315 function selectTextField(element, collapseToEnd = false) {
7316 if (isTextField(element)) {
7317 element.setSelectionRange(
7318 collapseToEnd ? element.value.length : 0,
7319 element.value.length
7320 );
7321 } else if (element.isContentEditable) {
7322 const selection = getDocument(element).getSelection();
7323 selection == null ? void 0 : selection.selectAllChildren(element);
7324 if (collapseToEnd) {
7325 selection == null ? void 0 : selection.collapseToEnd();
7326 }
7327 }
7328 }
7329 var FOCUS_SILENTLY = /* @__PURE__ */ Symbol("FOCUS_SILENTLY");
7330 function focusSilently(element) {
7331 element[FOCUS_SILENTLY] = true;
7332 element.focus({ preventScroll: true });
7333 }
7334 function silentlyFocused(element) {
7335 const isSilentlyFocused = element[FOCUS_SILENTLY];
7336 delete element[FOCUS_SILENTLY];
7337 return isSilentlyFocused;
7338 }
7339 function isItem(store, element, exclude) {
7340 if (!element) return false;
7341 if (element === exclude) return false;
7342 const item = store.item(element.id);
7343 if (!item) return false;
7344 if (exclude && item.element === exclude) return false;
7345 return true;
7346 }
7347
7348 // node_modules/@ariakit/react-core/esm/__chunks/Z2O3VLAQ.js
7349 var import_react8 = __toESM(require_react(), 1);
7350 var TagName = "div";
7351 var useCollectionItem = createHook(
7352 function useCollectionItem2({
7353 store,
7354 shouldRegisterItem = true,
7355 getItem = identity,
7356 // @ts-expect-error This prop may come from a collection renderer.
7357 element,
7358 ...props
7359 }) {
7360 const context = useCollectionContext();
7361 store = store || context;
7362 const id = useId3(props.id);
7363 const ref = (0, import_react8.useRef)(element);
7364 (0, import_react8.useEffect)(() => {
7365 const element2 = ref.current;
7366 if (!id) return;
7367 if (!element2) return;
7368 if (!shouldRegisterItem) return;
7369 const item = getItem({ id, element: element2 });
7370 return store == null ? void 0 : store.renderItem(item);
7371 }, [id, shouldRegisterItem, getItem, store]);
7372 props = {
7373 ...props,
7374 ref: useMergeRefs(ref, props.ref)
7375 };
7376 return removeUndefinedValues(props);
7377 }
7378 );
7379 var CollectionItem = forwardRef22(function CollectionItem2(props) {
7380 const htmlProps = useCollectionItem(props);
7381 return createElement3(TagName, htmlProps);
7382 });
7383
7384 // node_modules/@ariakit/react-core/esm/__chunks/SWN3JYXT.js
7385 var import_react9 = __toESM(require_react(), 1);
7386 var FocusableContext = (0, import_react9.createContext)(true);
7387
7388 // node_modules/@ariakit/core/esm/utils/focus.js
7389 var selector = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], summary, iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false'])";
7390 function isFocusable(element) {
7391 if (!element.matches(selector)) return false;
7392 if (!isVisible(element)) return false;
7393 if (element.closest("[inert]")) return false;
7394 return true;
7395 }
7396 function getClosestFocusable(element) {
7397 while (element && !isFocusable(element)) {
7398 element = element.closest(selector);
7399 }
7400 return element || null;
7401 }
7402 function hasFocus(element) {
7403 const activeElement = getActiveElement(element);
7404 if (!activeElement) return false;
7405 if (activeElement === element) return true;
7406 const activeDescendant = activeElement.getAttribute("aria-activedescendant");
7407 if (!activeDescendant) return false;
7408 return activeDescendant === element.id;
7409 }
7410 function hasFocusWithin(element) {
7411 const activeElement = getActiveElement(element);
7412 if (!activeElement) return false;
7413 if (contains(element, activeElement)) return true;
7414 const activeDescendant = activeElement.getAttribute("aria-activedescendant");
7415 if (!activeDescendant) return false;
7416 if (!("id" in element)) return false;
7417 if (activeDescendant === element.id) return true;
7418 return !!element.querySelector(`#${CSS.escape(activeDescendant)}`);
7419 }
7420 function focusIfNeeded(element) {
7421 if (!hasFocusWithin(element) && isFocusable(element)) {
7422 element.focus();
7423 }
7424 }
7425 function focusIntoView(element, options) {
7426 if (!("scrollIntoView" in element)) {
7427 element.focus();
7428 } else {
7429 element.focus({ preventScroll: true });
7430 element.scrollIntoView({ block: "nearest", inline: "nearest", ...options });
7431 }
7432 }
7433
7434 // node_modules/@ariakit/react-core/esm/__chunks/U6HHPQDW.js
7435 var import_react10 = __toESM(require_react(), 1);
7436 var TagName2 = "div";
7437 var isSafariBrowser = isSafari();
7438 var alwaysFocusVisibleInputTypes = [
7439 "text",
7440 "search",
7441 "url",
7442 "tel",
7443 "email",
7444 "password",
7445 "number",
7446 "date",
7447 "month",
7448 "week",
7449 "time",
7450 "datetime",
7451 "datetime-local"
7452 ];
7453 var safariFocusAncestorSymbol = /* @__PURE__ */ Symbol("safariFocusAncestor");
7454 function markSafariFocusAncestor(element, value) {
7455 if (!element) return;
7456 element[safariFocusAncestorSymbol] = value;
7457 }
7458 function isAlwaysFocusVisible(element) {
7459 const { tagName, readOnly, type } = element;
7460 if (tagName === "TEXTAREA" && !readOnly) return true;
7461 if (tagName === "SELECT" && !readOnly) return true;
7462 if (tagName === "INPUT" && !readOnly) {
7463 return alwaysFocusVisibleInputTypes.includes(type);
7464 }
7465 if (element.isContentEditable) return true;
7466 const role = element.getAttribute("role");
7467 if (role === "combobox" && element.dataset.name) {
7468 return true;
7469 }
7470 return false;
7471 }
7472 function getLabels(element) {
7473 if ("labels" in element) {
7474 return element.labels;
7475 }
7476 return null;
7477 }
7478 function isNativeCheckboxOrRadio(element) {
7479 const tagName = element.tagName.toLowerCase();
7480 if (tagName === "input" && element.type) {
7481 return element.type === "radio" || element.type === "checkbox";
7482 }
7483 return false;
7484 }
7485 function isNativeTabbable(tagName) {
7486 if (!tagName) return true;
7487 return tagName === "button" || tagName === "summary" || tagName === "input" || tagName === "select" || tagName === "textarea" || tagName === "a";
7488 }
7489 function supportsDisabledAttribute(tagName) {
7490 if (!tagName) return true;
7491 return tagName === "button" || tagName === "input" || tagName === "select" || tagName === "textarea";
7492 }
7493 function getTabIndex(focusable, trulyDisabled, nativeTabbable, supportsDisabled, tabIndexProp) {
7494 if (!focusable) {
7495 return tabIndexProp;
7496 }
7497 if (trulyDisabled) {
7498 if (nativeTabbable && !supportsDisabled) {
7499 return -1;
7500 }
7501 return;
7502 }
7503 if (nativeTabbable) {
7504 return tabIndexProp;
7505 }
7506 return tabIndexProp || 0;
7507 }
7508 function useDisableEvent(onEvent, disabled) {
7509 return useEvent((event) => {
7510 onEvent == null ? void 0 : onEvent(event);
7511 if (event.defaultPrevented) return;
7512 if (disabled) {
7513 event.stopPropagation();
7514 event.preventDefault();
7515 }
7516 });
7517 }
7518 var hasInstalledGlobalEventListeners2 = false;
7519 var isKeyboardModality = true;
7520 function onGlobalMouseDown(event) {
7521 const target = event.target;
7522 if (target && "hasAttribute" in target) {
7523 if (!target.hasAttribute("data-focus-visible")) {
7524 isKeyboardModality = false;
7525 }
7526 }
7527 }
7528 function onGlobalKeyDown(event) {
7529 if (event.metaKey) return;
7530 if (event.ctrlKey) return;
7531 if (event.altKey) return;
7532 isKeyboardModality = true;
7533 }
7534 var useFocusable = createHook(
7535 function useFocusable2({
7536 focusable = true,
7537 accessibleWhenDisabled,
7538 autoFocus,
7539 onFocusVisible,
7540 ...props
7541 }) {
7542 const ref = (0, import_react10.useRef)(null);
7543 (0, import_react10.useEffect)(() => {
7544 if (!focusable) return;
7545 if (hasInstalledGlobalEventListeners2) return;
7546 addGlobalEventListener("mousedown", onGlobalMouseDown, true);
7547 addGlobalEventListener("keydown", onGlobalKeyDown, true);
7548 hasInstalledGlobalEventListeners2 = true;
7549 }, [focusable]);
7550 if (isSafariBrowser) {
7551 (0, import_react10.useEffect)(() => {
7552 if (!focusable) return;
7553 const element = ref.current;
7554 if (!element) return;
7555 if (!isNativeCheckboxOrRadio(element)) return;
7556 const labels = getLabels(element);
7557 if (!labels) return;
7558 const onMouseUp = () => queueMicrotask(() => element.focus());
7559 for (const label of labels) {
7560 label.addEventListener("mouseup", onMouseUp);
7561 }
7562 return () => {
7563 for (const label of labels) {
7564 label.removeEventListener("mouseup", onMouseUp);
7565 }
7566 };
7567 }, [focusable]);
7568 }
7569 const disabled = focusable && disabledFromProps(props);
7570 const trulyDisabled = !!disabled && !accessibleWhenDisabled;
7571 const [focusVisible, setFocusVisible] = (0, import_react10.useState)(false);
7572 (0, import_react10.useEffect)(() => {
7573 if (!focusable) return;
7574 if (trulyDisabled && focusVisible) {
7575 setFocusVisible(false);
7576 }
7577 }, [focusable, trulyDisabled, focusVisible]);
7578 (0, import_react10.useEffect)(() => {
7579 if (!focusable) return;
7580 if (!focusVisible) return;
7581 const element = ref.current;
7582 if (!element) return;
7583 if (typeof IntersectionObserver === "undefined") return;
7584 const observer = new IntersectionObserver(() => {
7585 if (!isFocusable(element)) {
7586 setFocusVisible(false);
7587 }
7588 });
7589 observer.observe(element);
7590 return () => observer.disconnect();
7591 }, [focusable, focusVisible]);
7592 const onKeyPressCapture = useDisableEvent(
7593 props.onKeyPressCapture,
7594 disabled
7595 );
7596 const onMouseDownCapture = useDisableEvent(
7597 props.onMouseDownCapture,
7598 disabled
7599 );
7600 const onClickCapture = useDisableEvent(props.onClickCapture, disabled);
7601 const onMouseDownProp = props.onMouseDown;
7602 const onMouseDown = useEvent((event) => {
7603 onMouseDownProp == null ? void 0 : onMouseDownProp(event);
7604 if (event.defaultPrevented) return;
7605 if (!focusable) return;
7606 const element = event.currentTarget;
7607 if (!isSafariBrowser) return;
7608 if (isPortalEvent(event)) return;
7609 if (!isButton(element) && !isNativeCheckboxOrRadio(element)) return;
7610 let receivedFocus = false;
7611 const onFocus = () => {
7612 receivedFocus = true;
7613 };
7614 const options = { capture: true, once: true };
7615 element.addEventListener("focusin", onFocus, options);
7616 const focusableContainer = getClosestFocusable(element.parentElement);
7617 markSafariFocusAncestor(focusableContainer, true);
7618 queueBeforeEvent(element, "mouseup", () => {
7619 element.removeEventListener("focusin", onFocus, true);
7620 markSafariFocusAncestor(focusableContainer, false);
7621 if (receivedFocus) return;
7622 focusIfNeeded(element);
7623 });
7624 });
7625 const handleFocusVisible = (event, currentTarget) => {
7626 if (currentTarget) {
7627 event.currentTarget = currentTarget;
7628 }
7629 if (!focusable) return;
7630 const element = event.currentTarget;
7631 if (!element) return;
7632 if (!hasFocus(element)) return;
7633 onFocusVisible == null ? void 0 : onFocusVisible(event);
7634 if (event.defaultPrevented) return;
7635 element.dataset.focusVisible = "true";
7636 setFocusVisible(true);
7637 };
7638 const onKeyDownCaptureProp = props.onKeyDownCapture;
7639 const onKeyDownCapture = useEvent((event) => {
7640 onKeyDownCaptureProp == null ? void 0 : onKeyDownCaptureProp(event);
7641 if (event.defaultPrevented) return;
7642 if (!focusable) return;
7643 if (focusVisible) return;
7644 if (event.metaKey) return;
7645 if (event.altKey) return;
7646 if (event.ctrlKey) return;
7647 if (!isSelfTarget(event)) return;
7648 const element = event.currentTarget;
7649 const applyFocusVisible = () => handleFocusVisible(event, element);
7650 queueBeforeEvent(element, "focusout", applyFocusVisible);
7651 });
7652 const onFocusCaptureProp = props.onFocusCapture;
7653 const onFocusCapture = useEvent((event) => {
7654 onFocusCaptureProp == null ? void 0 : onFocusCaptureProp(event);
7655 if (event.defaultPrevented) return;
7656 if (!focusable) return;
7657 if (!isSelfTarget(event)) {
7658 setFocusVisible(false);
7659 return;
7660 }
7661 const element = event.currentTarget;
7662 const applyFocusVisible = () => handleFocusVisible(event, element);
7663 if (isKeyboardModality || isAlwaysFocusVisible(event.target)) {
7664 queueBeforeEvent(event.target, "focusout", applyFocusVisible);
7665 } else {
7666 setFocusVisible(false);
7667 }
7668 });
7669 const onBlurProp = props.onBlur;
7670 const onBlur = useEvent((event) => {
7671 onBlurProp == null ? void 0 : onBlurProp(event);
7672 if (!focusable) return;
7673 if (!isFocusEventOutside(event)) return;
7674 event.currentTarget.removeAttribute("data-focus-visible");
7675 setFocusVisible(false);
7676 });
7677 const autoFocusOnShow = (0, import_react10.useContext)(FocusableContext);
7678 const autoFocusRef = useEvent((element) => {
7679 if (!focusable) return;
7680 if (!autoFocus) return;
7681 if (!element) return;
7682 if (!autoFocusOnShow) return;
7683 queueMicrotask(() => {
7684 if (hasFocus(element)) return;
7685 if (!isFocusable(element)) return;
7686 element.focus();
7687 });
7688 });
7689 const tagName = useTagName(ref);
7690 const nativeTabbable = focusable && isNativeTabbable(tagName);
7691 const supportsDisabled = focusable && supportsDisabledAttribute(tagName);
7692 const styleProp = props.style;
7693 const style = (0, import_react10.useMemo)(() => {
7694 if (trulyDisabled) {
7695 return { pointerEvents: "none", ...styleProp };
7696 }
7697 return styleProp;
7698 }, [trulyDisabled, styleProp]);
7699 props = {
7700 "data-focus-visible": focusable && focusVisible || void 0,
7701 "data-autofocus": autoFocus || void 0,
7702 "aria-disabled": disabled || void 0,
7703 ...props,
7704 ref: useMergeRefs(ref, autoFocusRef, props.ref),
7705 style,
7706 tabIndex: getTabIndex(
7707 focusable,
7708 trulyDisabled,
7709 nativeTabbable,
7710 supportsDisabled,
7711 props.tabIndex
7712 ),
7713 disabled: supportsDisabled && trulyDisabled ? true : void 0,
7714 // TODO: Test Focusable contentEditable.
7715 contentEditable: disabled ? void 0 : props.contentEditable,
7716 onKeyPressCapture,
7717 onClickCapture,
7718 onMouseDownCapture,
7719 onMouseDown,
7720 onKeyDownCapture,
7721 onFocusCapture,
7722 onBlur
7723 };
7724 return removeUndefinedValues(props);
7725 }
7726 );
7727 var Focusable = forwardRef22(function Focusable2(props) {
7728 const htmlProps = useFocusable(props);
7729 return createElement3(TagName2, htmlProps);
7730 });
7731
7732 // node_modules/@ariakit/react-core/esm/__chunks/PZ3OL7I2.js
7733 var import_react11 = __toESM(require_react(), 1);
7734 var TagName3 = "button";
7735 function isNativeClick(event) {
7736 if (!event.isTrusted) return false;
7737 const element = event.currentTarget;
7738 if (event.key === "Enter") {
7739 return isButton(element) || element.tagName === "SUMMARY" || element.tagName === "A";
7740 }
7741 if (event.key === " ") {
7742 return isButton(element) || element.tagName === "SUMMARY" || element.tagName === "INPUT" || element.tagName === "SELECT";
7743 }
7744 return false;
7745 }
7746 var symbol = /* @__PURE__ */ Symbol("command");
7747 var useCommand = createHook(
7748 function useCommand2({ clickOnEnter = true, clickOnSpace = true, ...props }) {
7749 const ref = (0, import_react11.useRef)(null);
7750 const [isNativeButton, setIsNativeButton] = (0, import_react11.useState)(false);
7751 (0, import_react11.useEffect)(() => {
7752 if (!ref.current) return;
7753 setIsNativeButton(isButton(ref.current));
7754 }, []);
7755 const [active, setActive] = (0, import_react11.useState)(false);
7756 const activeRef = (0, import_react11.useRef)(false);
7757 const disabled = disabledFromProps(props);
7758 const [isDuplicate, metadataProps] = useMetadataProps(props, symbol, true);
7759 const onKeyDownProp = props.onKeyDown;
7760 const onKeyDown = useEvent((event) => {
7761 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
7762 const element = event.currentTarget;
7763 if (event.defaultPrevented) return;
7764 if (isDuplicate) return;
7765 if (disabled) return;
7766 if (!isSelfTarget(event)) return;
7767 if (isTextField(element)) return;
7768 if (element.isContentEditable) return;
7769 const isEnter = clickOnEnter && event.key === "Enter";
7770 const isSpace = clickOnSpace && event.key === " ";
7771 const shouldPreventEnter = event.key === "Enter" && !clickOnEnter;
7772 const shouldPreventSpace = event.key === " " && !clickOnSpace;
7773 if (shouldPreventEnter || shouldPreventSpace) {
7774 event.preventDefault();
7775 return;
7776 }
7777 if (isEnter || isSpace) {
7778 const nativeClick = isNativeClick(event);
7779 if (isEnter) {
7780 if (!nativeClick) {
7781 event.preventDefault();
7782 const { view, ...eventInit } = event;
7783 const click = () => fireClickEvent(element, eventInit);
7784 if (isFirefox()) {
7785 queueBeforeEvent(element, "keyup", click);
7786 } else {
7787 queueMicrotask(click);
7788 }
7789 }
7790 } else if (isSpace) {
7791 activeRef.current = true;
7792 if (!nativeClick) {
7793 event.preventDefault();
7794 setActive(true);
7795 }
7796 }
7797 }
7798 });
7799 const onKeyUpProp = props.onKeyUp;
7800 const onKeyUp = useEvent((event) => {
7801 onKeyUpProp == null ? void 0 : onKeyUpProp(event);
7802 if (event.defaultPrevented) return;
7803 if (isDuplicate) return;
7804 if (disabled) return;
7805 if (event.metaKey) return;
7806 const isSpace = clickOnSpace && event.key === " ";
7807 if (activeRef.current && isSpace) {
7808 activeRef.current = false;
7809 if (!isNativeClick(event)) {
7810 event.preventDefault();
7811 setActive(false);
7812 const element = event.currentTarget;
7813 const { view, ...eventInit } = event;
7814 queueMicrotask(() => fireClickEvent(element, eventInit));
7815 }
7816 }
7817 });
7818 props = {
7819 "data-active": active || void 0,
7820 type: isNativeButton ? "button" : void 0,
7821 ...metadataProps,
7822 ...props,
7823 ref: useMergeRefs(ref, props.ref),
7824 onKeyDown,
7825 onKeyUp
7826 };
7827 props = useFocusable(props);
7828 return props;
7829 }
7830 );
7831 var Command = forwardRef22(function Command2(props) {
7832 const htmlProps = useCommand(props);
7833 return createElement3(TagName3, htmlProps);
7834 });
7835
7836 // node_modules/@ariakit/core/esm/__chunks/SXKM4CGU.js
7837 function getInternal(store, key) {
7838 const internals = store.__unstableInternals;
7839 invariant(internals, "Invalid store");
7840 return internals[key];
7841 }
7842 function createStore(initialState, ...stores) {
7843 let state = initialState;
7844 let prevStateBatch = state;
7845 let lastUpdate = /* @__PURE__ */ Symbol();
7846 let destroy = noop2;
7847 const instances = /* @__PURE__ */ new Set();
7848 const updatedKeys = /* @__PURE__ */ new Set();
7849 const setups = /* @__PURE__ */ new Set();
7850 const listeners = /* @__PURE__ */ new Set();
7851 const batchListeners = /* @__PURE__ */ new Set();
7852 const disposables = /* @__PURE__ */ new WeakMap();
7853 const listenerKeys = /* @__PURE__ */ new WeakMap();
7854 const storeSetup = (callback) => {
7855 setups.add(callback);
7856 return () => setups.delete(callback);
7857 };
7858 const storeInit = () => {
7859 const initialized = instances.size;
7860 const instance = /* @__PURE__ */ Symbol();
7861 instances.add(instance);
7862 const maybeDestroy = () => {
7863 instances.delete(instance);
7864 if (instances.size) return;
7865 destroy();
7866 };
7867 if (initialized) return maybeDestroy;
7868 const desyncs = getKeys(state).map(
7869 (key) => chain(
7870 ...stores.map((store) => {
7871 var _a;
7872 const storeState = (_a = store == null ? void 0 : store.getState) == null ? void 0 : _a.call(store);
7873 if (!storeState) return;
7874 if (!hasOwnProperty(storeState, key)) return;
7875 return sync(store, [key], (state2) => {
7876 setState(
7877 key,
7878 state2[key],
7879 // @ts-expect-error - Not public API. This is just to prevent
7880 // infinite loops.
7881 true
7882 );
7883 });
7884 })
7885 )
7886 );
7887 const teardowns = [];
7888 for (const setup2 of setups) {
7889 teardowns.push(setup2());
7890 }
7891 const cleanups = stores.map(init);
7892 destroy = chain(...desyncs, ...teardowns, ...cleanups);
7893 return maybeDestroy;
7894 };
7895 const sub = (keys, listener, set2 = listeners) => {
7896 set2.add(listener);
7897 listenerKeys.set(listener, keys);
7898 return () => {
7899 var _a;
7900 (_a = disposables.get(listener)) == null ? void 0 : _a();
7901 disposables.delete(listener);
7902 listenerKeys.delete(listener);
7903 set2.delete(listener);
7904 };
7905 };
7906 const storeSubscribe = (keys, listener) => sub(keys, listener);
7907 const storeSync = (keys, listener) => {
7908 disposables.set(listener, listener(state, state));
7909 return sub(keys, listener);
7910 };
7911 const storeBatch = (keys, listener) => {
7912 disposables.set(listener, listener(state, prevStateBatch));
7913 return sub(keys, listener, batchListeners);
7914 };
7915 const storePick = (keys) => createStore(pick(state, keys), finalStore);
7916 const storeOmit = (keys) => createStore(omit(state, keys), finalStore);
7917 const getState = () => state;
7918 const setState = (key, value, fromStores = false) => {
7919 var _a;
7920 if (!hasOwnProperty(state, key)) return;
7921 const nextValue = applyState(value, state[key]);
7922 if (nextValue === state[key]) return;
7923 if (!fromStores) {
7924 for (const store of stores) {
7925 (_a = store == null ? void 0 : store.setState) == null ? void 0 : _a.call(store, key, nextValue);
7926 }
7927 }
7928 const prevState = state;
7929 state = { ...state, [key]: nextValue };
7930 const thisUpdate = /* @__PURE__ */ Symbol();
7931 lastUpdate = thisUpdate;
7932 updatedKeys.add(key);
7933 const run = (listener, prev, uKeys) => {
7934 var _a2;
7935 const keys = listenerKeys.get(listener);
7936 const updated = (k) => uKeys ? uKeys.has(k) : k === key;
7937 if (!keys || keys.some(updated)) {
7938 (_a2 = disposables.get(listener)) == null ? void 0 : _a2();
7939 disposables.set(listener, listener(state, prev));
7940 }
7941 };
7942 for (const listener of listeners) {
7943 run(listener, prevState);
7944 }
7945 queueMicrotask(() => {
7946 if (lastUpdate !== thisUpdate) return;
7947 const snapshot = state;
7948 for (const listener of batchListeners) {
7949 run(listener, prevStateBatch, updatedKeys);
7950 }
7951 prevStateBatch = snapshot;
7952 updatedKeys.clear();
7953 });
7954 };
7955 const finalStore = {
7956 getState,
7957 setState,
7958 __unstableInternals: {
7959 setup: storeSetup,
7960 init: storeInit,
7961 subscribe: storeSubscribe,
7962 sync: storeSync,
7963 batch: storeBatch,
7964 pick: storePick,
7965 omit: storeOmit
7966 }
7967 };
7968 return finalStore;
7969 }
7970 function setup(store, ...args) {
7971 if (!store) return;
7972 return getInternal(store, "setup")(...args);
7973 }
7974 function init(store, ...args) {
7975 if (!store) return;
7976 return getInternal(store, "init")(...args);
7977 }
7978 function subscribe(store, ...args) {
7979 if (!store) return;
7980 return getInternal(store, "subscribe")(...args);
7981 }
7982 function sync(store, ...args) {
7983 if (!store) return;
7984 return getInternal(store, "sync")(...args);
7985 }
7986 function batch(store, ...args) {
7987 if (!store) return;
7988 return getInternal(store, "batch")(...args);
7989 }
7990 function omit2(store, ...args) {
7991 if (!store) return;
7992 return getInternal(store, "omit")(...args);
7993 }
7994 function pick2(store, ...args) {
7995 if (!store) return;
7996 return getInternal(store, "pick")(...args);
7997 }
7998 function mergeStore(...stores) {
7999 var _a;
8000 const initialState = {};
8001 for (const store2 of stores) {
8002 const nextState = (_a = store2 == null ? void 0 : store2.getState) == null ? void 0 : _a.call(store2);
8003 if (nextState) {
8004 Object.assign(initialState, nextState);
8005 }
8006 }
8007 const store = createStore(initialState, ...stores);
8008 return Object.assign({}, ...stores, store);
8009 }
8010 function throwOnConflictingProps(props, store) {
8011 if (false) return;
8012 if (!store) return;
8013 const defaultKeys = Object.entries(props).filter(([key, value]) => key.startsWith("default") && value !== void 0).map(([key]) => {
8014 var _a;
8015 const stateKey = key.replace("default", "");
8016 return `${((_a = stateKey[0]) == null ? void 0 : _a.toLowerCase()) || ""}${stateKey.slice(1)}`;
8017 });
8018 if (!defaultKeys.length) return;
8019 const storeState = store.getState();
8020 const conflictingProps = defaultKeys.filter(
8021 (key) => hasOwnProperty(storeState, key)
8022 );
8023 if (!conflictingProps.length) return;
8024 throw new Error(
8025 `Passing a store prop in conjunction with a default state is not supported.
8026
8027 const store = useSelectStore();
8028 <SelectProvider store={store} defaultValue="Apple" />
8029 ^ ^
8030
8031 Instead, pass the default state to the topmost store:
8032
8033 const store = useSelectStore({ defaultValue: "Apple" });
8034 <SelectProvider store={store} />
8035
8036 See https://github.com/ariakit/ariakit/pull/2745 for more details.
8037
8038 If there's a particular need for this, please submit a feature request at https://github.com/ariakit/ariakit
8039 `
8040 );
8041 }
8042
8043 // node_modules/@ariakit/react-core/esm/__chunks/Q5W46E73.js
8044 var React7 = __toESM(require_react(), 1);
8045 var import_shim = __toESM(require_shim(), 1);
8046 var { useSyncExternalStore } = import_shim.default;
8047 var noopSubscribe = () => () => {
8048 };
8049 function useStoreState(store, keyOrSelector = identity) {
8050 const storeSubscribe = React7.useCallback(
8051 (callback) => {
8052 if (!store) return noopSubscribe();
8053 return subscribe(store, null, callback);
8054 },
8055 [store]
8056 );
8057 const getSnapshot = () => {
8058 const key = typeof keyOrSelector === "string" ? keyOrSelector : null;
8059 const selector2 = typeof keyOrSelector === "function" ? keyOrSelector : null;
8060 const state = store == null ? void 0 : store.getState();
8061 if (selector2) return selector2(state);
8062 if (!state) return;
8063 if (!key) return;
8064 if (!hasOwnProperty(state, key)) return;
8065 return state[key];
8066 };
8067 return useSyncExternalStore(storeSubscribe, getSnapshot, getSnapshot);
8068 }
8069 function useStoreStateObject(store, object) {
8070 const objRef = React7.useRef(
8071 {}
8072 );
8073 const storeSubscribe = React7.useCallback(
8074 (callback) => {
8075 if (!store) return noopSubscribe();
8076 return subscribe(store, null, callback);
8077 },
8078 [store]
8079 );
8080 const getSnapshot = () => {
8081 const state = store == null ? void 0 : store.getState();
8082 let updated = false;
8083 const obj = objRef.current;
8084 for (const prop in object) {
8085 const keyOrSelector = object[prop];
8086 if (typeof keyOrSelector === "function") {
8087 const value = keyOrSelector(state);
8088 if (value !== obj[prop]) {
8089 obj[prop] = value;
8090 updated = true;
8091 }
8092 }
8093 if (typeof keyOrSelector === "string") {
8094 if (!state) continue;
8095 if (!hasOwnProperty(state, keyOrSelector)) continue;
8096 const value = state[keyOrSelector];
8097 if (value !== obj[prop]) {
8098 obj[prop] = value;
8099 updated = true;
8100 }
8101 }
8102 }
8103 if (updated) {
8104 objRef.current = { ...obj };
8105 }
8106 return objRef.current;
8107 };
8108 return useSyncExternalStore(storeSubscribe, getSnapshot, getSnapshot);
8109 }
8110 function useStoreProps(store, props, key, setKey) {
8111 const value = hasOwnProperty(props, key) ? props[key] : void 0;
8112 const setValue = setKey ? props[setKey] : void 0;
8113 const propsRef = useLiveRef({ value, setValue });
8114 useSafeLayoutEffect(() => {
8115 return sync(store, [key], (state, prev) => {
8116 const { value: value2, setValue: setValue2 } = propsRef.current;
8117 if (!setValue2) return;
8118 if (state[key] === prev[key]) return;
8119 if (state[key] === value2) return;
8120 setValue2(state[key]);
8121 });
8122 }, [store, key]);
8123 useSafeLayoutEffect(() => {
8124 if (value === void 0) return;
8125 store.setState(key, value);
8126 return batch(store, [key], () => {
8127 if (value === void 0) return;
8128 store.setState(key, value);
8129 });
8130 });
8131 }
8132 function useStore(createStore2, props) {
8133 const [store, setStore] = React7.useState(() => createStore2(props));
8134 useSafeLayoutEffect(() => init(store), [store]);
8135 const useState210 = React7.useCallback(
8136 (keyOrSelector) => useStoreState(store, keyOrSelector),
8137 [store]
8138 );
8139 const memoizedStore = React7.useMemo(
8140 () => ({ ...store, useState: useState210 }),
8141 [store, useState210]
8142 );
8143 const updateStore = useEvent(() => {
8144 setStore((store2) => createStore2({ ...props, ...store2.getState() }));
8145 });
8146 return [memoizedStore, updateStore];
8147 }
8148
8149 // node_modules/@ariakit/react-core/esm/__chunks/WZWDIE3S.js
8150 var import_react12 = __toESM(require_react(), 1);
8151 var import_jsx_runtime55 = __toESM(require_jsx_runtime(), 1);
8152 var TagName4 = "button";
8153 function isEditableElement(element) {
8154 if (isTextbox(element)) return true;
8155 return element.tagName === "INPUT" && !isButton(element);
8156 }
8157 function getNextPageOffset(scrollingElement, pageUp = false) {
8158 const height = scrollingElement.clientHeight;
8159 const { top } = scrollingElement.getBoundingClientRect();
8160 const pageSize = Math.max(height * 0.875, height - 40) * 1.5;
8161 const pageOffset = pageUp ? height - pageSize + top : pageSize + top;
8162 if (scrollingElement.tagName === "HTML") {
8163 return pageOffset + scrollingElement.scrollTop;
8164 }
8165 return pageOffset;
8166 }
8167 function getItemOffset(itemElement, pageUp = false) {
8168 const { top } = itemElement.getBoundingClientRect();
8169 if (pageUp) {
8170 return top + itemElement.clientHeight;
8171 }
8172 return top;
8173 }
8174 function findNextPageItemId(element, store, next, pageUp = false) {
8175 var _a;
8176 if (!store) return;
8177 if (!next) return;
8178 const { renderedItems } = store.getState();
8179 const scrollingElement = getScrollingElement(element);
8180 if (!scrollingElement) return;
8181 const nextPageOffset = getNextPageOffset(scrollingElement, pageUp);
8182 let id;
8183 let prevDifference;
8184 for (let i2 = 0; i2 < renderedItems.length; i2 += 1) {
8185 const previousId = id;
8186 id = next(i2);
8187 if (!id) break;
8188 if (id === previousId) continue;
8189 const itemElement = (_a = getEnabledItem(store, id)) == null ? void 0 : _a.element;
8190 if (!itemElement) continue;
8191 const itemOffset = getItemOffset(itemElement, pageUp);
8192 const difference = itemOffset - nextPageOffset;
8193 const absDifference = Math.abs(difference);
8194 if (pageUp && difference <= 0 || !pageUp && difference >= 0) {
8195 if (prevDifference !== void 0 && prevDifference < absDifference) {
8196 id = previousId;
8197 }
8198 break;
8199 }
8200 prevDifference = absDifference;
8201 }
8202 return id;
8203 }
8204 function targetIsAnotherItem(event, store) {
8205 if (isSelfTarget(event)) return false;
8206 return isItem(store, event.target);
8207 }
8208 var useCompositeItem = createHook(
8209 function useCompositeItem2({
8210 store,
8211 rowId: rowIdProp,
8212 preventScrollOnKeyDown = false,
8213 moveOnKeyPress = true,
8214 tabbable = false,
8215 getItem: getItemProp,
8216 "aria-setsize": ariaSetSizeProp,
8217 "aria-posinset": ariaPosInSetProp,
8218 ...props
8219 }) {
8220 const context = useCompositeContext();
8221 store = store || context;
8222 const id = useId3(props.id);
8223 const ref = (0, import_react12.useRef)(null);
8224 const row = (0, import_react12.useContext)(CompositeRowContext);
8225 const disabled = disabledFromProps(props);
8226 const trulyDisabled = disabled && !props.accessibleWhenDisabled;
8227 const {
8228 rowId,
8229 baseElement,
8230 isActiveItem,
8231 ariaSetSize,
8232 ariaPosInSet,
8233 isTabbable
8234 } = useStoreStateObject(store, {
8235 rowId(state) {
8236 if (rowIdProp) return rowIdProp;
8237 if (!state) return;
8238 if (!(row == null ? void 0 : row.baseElement)) return;
8239 if (row.baseElement !== state.baseElement) return;
8240 return row.id;
8241 },
8242 baseElement(state) {
8243 return (state == null ? void 0 : state.baseElement) || void 0;
8244 },
8245 isActiveItem(state) {
8246 return !!state && state.activeId === id;
8247 },
8248 ariaSetSize(state) {
8249 if (ariaSetSizeProp != null) return ariaSetSizeProp;
8250 if (!state) return;
8251 if (!(row == null ? void 0 : row.ariaSetSize)) return;
8252 if (row.baseElement !== state.baseElement) return;
8253 return row.ariaSetSize;
8254 },
8255 ariaPosInSet(state) {
8256 if (ariaPosInSetProp != null) return ariaPosInSetProp;
8257 if (!state) return;
8258 if (!(row == null ? void 0 : row.ariaPosInSet)) return;
8259 if (row.baseElement !== state.baseElement) return;
8260 const itemsInRow = state.renderedItems.filter(
8261 (item) => item.rowId === rowId
8262 );
8263 return row.ariaPosInSet + itemsInRow.findIndex((item) => item.id === id);
8264 },
8265 isTabbable(state) {
8266 if (!(state == null ? void 0 : state.renderedItems.length)) return true;
8267 if (state.virtualFocus) return false;
8268 if (tabbable) return true;
8269 if (state.activeId === null) return false;
8270 const item = store == null ? void 0 : store.item(state.activeId);
8271 if (item == null ? void 0 : item.disabled) return true;
8272 if (!(item == null ? void 0 : item.element)) return true;
8273 return state.activeId === id;
8274 }
8275 });
8276 const getItem = (0, import_react12.useCallback)(
8277 (item) => {
8278 var _a;
8279 const nextItem = {
8280 ...item,
8281 id: id || item.id,
8282 rowId,
8283 disabled: !!trulyDisabled,
8284 children: (_a = item.element) == null ? void 0 : _a.textContent
8285 };
8286 if (getItemProp) {
8287 return getItemProp(nextItem);
8288 }
8289 return nextItem;
8290 },
8291 [id, rowId, trulyDisabled, getItemProp]
8292 );
8293 const onFocusProp = props.onFocus;
8294 const hasFocusedComposite = (0, import_react12.useRef)(false);
8295 const onFocus = useEvent((event) => {
8296 onFocusProp == null ? void 0 : onFocusProp(event);
8297 if (event.defaultPrevented) return;
8298 if (isPortalEvent(event)) return;
8299 if (!id) return;
8300 if (!store) return;
8301 if (targetIsAnotherItem(event, store)) return;
8302 const { virtualFocus, baseElement: baseElement2 } = store.getState();
8303 store.setActiveId(id);
8304 if (isTextbox(event.currentTarget)) {
8305 selectTextField(event.currentTarget);
8306 }
8307 if (!virtualFocus) return;
8308 if (!isSelfTarget(event)) return;
8309 if (isEditableElement(event.currentTarget)) return;
8310 if (!(baseElement2 == null ? void 0 : baseElement2.isConnected)) return;
8311 if (isSafari() && event.currentTarget.hasAttribute("data-autofocus")) {
8312 event.currentTarget.scrollIntoView({
8313 block: "nearest",
8314 inline: "nearest"
8315 });
8316 }
8317 hasFocusedComposite.current = true;
8318 const fromComposite = event.relatedTarget === baseElement2 || isItem(store, event.relatedTarget);
8319 if (fromComposite) {
8320 focusSilently(baseElement2);
8321 } else {
8322 baseElement2.focus();
8323 }
8324 });
8325 const onBlurCaptureProp = props.onBlurCapture;
8326 const onBlurCapture = useEvent((event) => {
8327 onBlurCaptureProp == null ? void 0 : onBlurCaptureProp(event);
8328 if (event.defaultPrevented) return;
8329 const state = store == null ? void 0 : store.getState();
8330 if ((state == null ? void 0 : state.virtualFocus) && hasFocusedComposite.current) {
8331 hasFocusedComposite.current = false;
8332 event.preventDefault();
8333 event.stopPropagation();
8334 }
8335 });
8336 const onKeyDownProp = props.onKeyDown;
8337 const preventScrollOnKeyDownProp = useBooleanEvent(preventScrollOnKeyDown);
8338 const moveOnKeyPressProp = useBooleanEvent(moveOnKeyPress);
8339 const onKeyDown = useEvent((event) => {
8340 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
8341 if (event.defaultPrevented) return;
8342 if (!isSelfTarget(event)) return;
8343 if (!store) return;
8344 const { currentTarget } = event;
8345 const state = store.getState();
8346 const item = store.item(id);
8347 const isGrid2 = !!(item == null ? void 0 : item.rowId);
8348 const isVertical = state.orientation !== "horizontal";
8349 const isHorizontal = state.orientation !== "vertical";
8350 const canHomeEnd = () => {
8351 if (isGrid2) return true;
8352 if (isHorizontal) return true;
8353 if (!state.baseElement) return true;
8354 if (!isTextField(state.baseElement)) return true;
8355 return false;
8356 };
8357 const keyMap = {
8358 ArrowUp: (isGrid2 || isVertical) && store.up,
8359 ArrowRight: (isGrid2 || isHorizontal) && store.next,
8360 ArrowDown: (isGrid2 || isVertical) && store.down,
8361 ArrowLeft: (isGrid2 || isHorizontal) && store.previous,
8362 Home: () => {
8363 if (!canHomeEnd()) return;
8364 if (!isGrid2 || event.ctrlKey) {
8365 return store == null ? void 0 : store.first();
8366 }
8367 return store == null ? void 0 : store.previous(-1);
8368 },
8369 End: () => {
8370 if (!canHomeEnd()) return;
8371 if (!isGrid2 || event.ctrlKey) {
8372 return store == null ? void 0 : store.last();
8373 }
8374 return store == null ? void 0 : store.next(-1);
8375 },
8376 PageUp: () => {
8377 return findNextPageItemId(currentTarget, store, store == null ? void 0 : store.up, true);
8378 },
8379 PageDown: () => {
8380 return findNextPageItemId(currentTarget, store, store == null ? void 0 : store.down);
8381 }
8382 };
8383 const action = keyMap[event.key];
8384 if (action) {
8385 if (isTextbox(currentTarget)) {
8386 const selection = getTextboxSelection(currentTarget);
8387 const isLeft = isHorizontal && event.key === "ArrowLeft";
8388 const isRight = isHorizontal && event.key === "ArrowRight";
8389 const isUp = isVertical && event.key === "ArrowUp";
8390 const isDown = isVertical && event.key === "ArrowDown";
8391 if (isRight || isDown) {
8392 const { length: valueLength } = getTextboxValue(currentTarget);
8393 if (selection.end !== valueLength) return;
8394 } else if ((isLeft || isUp) && selection.start !== 0) return;
8395 }
8396 const nextId = action();
8397 if (preventScrollOnKeyDownProp(event) || nextId !== void 0) {
8398 if (!moveOnKeyPressProp(event)) return;
8399 event.preventDefault();
8400 store.move(nextId);
8401 }
8402 }
8403 });
8404 const providerValue = (0, import_react12.useMemo)(
8405 () => ({ id, baseElement }),
8406 [id, baseElement]
8407 );
8408 props = useWrapElement(
8409 props,
8410 (element) => /* @__PURE__ */ (0, import_jsx_runtime55.jsx)(CompositeItemContext.Provider, { value: providerValue, children: element }),
8411 [providerValue]
8412 );
8413 props = {
8414 id,
8415 "data-active-item": isActiveItem || void 0,
8416 ...props,
8417 ref: useMergeRefs(ref, props.ref),
8418 tabIndex: isTabbable ? props.tabIndex : -1,
8419 onFocus,
8420 onBlurCapture,
8421 onKeyDown
8422 };
8423 props = useCommand(props);
8424 props = useCollectionItem({
8425 store,
8426 ...props,
8427 getItem,
8428 shouldRegisterItem: id ? props.shouldRegisterItem : false
8429 });
8430 return removeUndefinedValues({
8431 ...props,
8432 "aria-setsize": ariaSetSize,
8433 "aria-posinset": ariaPosInSet
8434 });
8435 }
8436 );
8437 var CompositeItem = memo22(
8438 forwardRef22(function CompositeItem2(props) {
8439 const htmlProps = useCompositeItem(props);
8440 return createElement3(TagName4, htmlProps);
8441 })
8442 );
8443
8444 // node_modules/@ariakit/core/esm/__chunks/7PRQYBBV.js
8445 function toArray(arg) {
8446 if (Array.isArray(arg)) {
8447 return arg;
8448 }
8449 return typeof arg !== "undefined" ? [arg] : [];
8450 }
8451 function flatten2DArray(array) {
8452 const flattened = [];
8453 for (const row of array) {
8454 flattened.push(...row);
8455 }
8456 return flattened;
8457 }
8458 function reverseArray(array) {
8459 return array.slice().reverse();
8460 }
8461
8462 // node_modules/@ariakit/react-core/esm/__chunks/ZMWF7ASR.js
8463 var import_react13 = __toESM(require_react(), 1);
8464 var import_jsx_runtime56 = __toESM(require_jsx_runtime(), 1);
8465 var TagName5 = "div";
8466 function isGrid(items) {
8467 return items.some((item) => !!item.rowId);
8468 }
8469 function isPrintableKey(event) {
8470 const target = event.target;
8471 if (target && !isTextField(target)) return false;
8472 return event.key.length === 1 && !event.ctrlKey && !event.metaKey;
8473 }
8474 function isModifierKey(event) {
8475 return event.key === "Shift" || event.key === "Control" || event.key === "Alt" || event.key === "Meta";
8476 }
8477 function useKeyboardEventProxy(store, onKeyboardEvent, previousElementRef) {
8478 return useEvent((event) => {
8479 var _a;
8480 onKeyboardEvent == null ? void 0 : onKeyboardEvent(event);
8481 if (event.defaultPrevented) return;
8482 if (event.isPropagationStopped()) return;
8483 if (!isSelfTarget(event)) return;
8484 if (isModifierKey(event)) return;
8485 if (isPrintableKey(event)) return;
8486 const state = store.getState();
8487 const activeElement = (_a = getEnabledItem(store, state.activeId)) == null ? void 0 : _a.element;
8488 if (!activeElement) return;
8489 const { view, ...eventInit } = event;
8490 const previousElement = previousElementRef == null ? void 0 : previousElementRef.current;
8491 if (activeElement !== previousElement) {
8492 activeElement.focus();
8493 }
8494 if (!fireKeyboardEvent(activeElement, event.type, eventInit)) {
8495 event.preventDefault();
8496 }
8497 if (event.currentTarget.contains(activeElement)) {
8498 event.stopPropagation();
8499 }
8500 });
8501 }
8502 function findFirstEnabledItemInTheLastRow(items) {
8503 return findFirstEnabledItem(
8504 flatten2DArray(reverseArray(groupItemsByRows(items)))
8505 );
8506 }
8507 function useScheduleFocus(store) {
8508 const [scheduled, setScheduled] = (0, import_react13.useState)(false);
8509 const schedule = (0, import_react13.useCallback)(() => setScheduled(true), []);
8510 const activeItem = store.useState(
8511 (state) => getEnabledItem(store, state.activeId)
8512 );
8513 (0, import_react13.useEffect)(() => {
8514 const activeElement = activeItem == null ? void 0 : activeItem.element;
8515 if (!scheduled) return;
8516 if (!activeElement) return;
8517 setScheduled(false);
8518 activeElement.focus({ preventScroll: true });
8519 }, [activeItem, scheduled]);
8520 return schedule;
8521 }
8522 var useComposite = createHook(
8523 function useComposite2({
8524 store,
8525 composite = true,
8526 focusOnMove = composite,
8527 moveOnKeyPress = true,
8528 ...props
8529 }) {
8530 const context = useCompositeProviderContext();
8531 store = store || context;
8532 invariant(
8533 store,
8534 "Composite must receive a `store` prop or be wrapped in a CompositeProvider component."
8535 );
8536 const ref = (0, import_react13.useRef)(null);
8537 const previousElementRef = (0, import_react13.useRef)(null);
8538 const scheduleFocus = useScheduleFocus(store);
8539 const moves = store.useState("moves");
8540 const [, setBaseElement] = useTransactionState(
8541 composite ? store.setBaseElement : null
8542 );
8543 (0, import_react13.useEffect)(() => {
8544 var _a;
8545 if (!store) return;
8546 if (!moves) return;
8547 if (!composite) return;
8548 if (!focusOnMove) return;
8549 const { activeId: activeId2 } = store.getState();
8550 const itemElement = (_a = getEnabledItem(store, activeId2)) == null ? void 0 : _a.element;
8551 if (!itemElement) return;
8552 focusIntoView(itemElement);
8553 }, [store, moves, composite, focusOnMove]);
8554 useSafeLayoutEffect(() => {
8555 if (!store) return;
8556 if (!moves) return;
8557 if (!composite) return;
8558 const { baseElement, activeId: activeId2 } = store.getState();
8559 const isSelfAcive = activeId2 === null;
8560 if (!isSelfAcive) return;
8561 if (!baseElement) return;
8562 const previousElement = previousElementRef.current;
8563 previousElementRef.current = null;
8564 if (previousElement) {
8565 fireBlurEvent(previousElement, { relatedTarget: baseElement });
8566 }
8567 if (!hasFocus(baseElement)) {
8568 baseElement.focus();
8569 }
8570 }, [store, moves, composite]);
8571 const activeId = store.useState("activeId");
8572 const virtualFocus = store.useState("virtualFocus");
8573 useSafeLayoutEffect(() => {
8574 var _a;
8575 if (!store) return;
8576 if (!composite) return;
8577 if (!virtualFocus) return;
8578 const previousElement = previousElementRef.current;
8579 previousElementRef.current = null;
8580 if (!previousElement) return;
8581 const activeElement = (_a = getEnabledItem(store, activeId)) == null ? void 0 : _a.element;
8582 const relatedTarget = activeElement || getActiveElement(previousElement);
8583 if (relatedTarget === previousElement) return;
8584 fireBlurEvent(previousElement, { relatedTarget });
8585 }, [store, activeId, virtualFocus, composite]);
8586 const onKeyDownCapture = useKeyboardEventProxy(
8587 store,
8588 props.onKeyDownCapture,
8589 previousElementRef
8590 );
8591 const onKeyUpCapture = useKeyboardEventProxy(
8592 store,
8593 props.onKeyUpCapture,
8594 previousElementRef
8595 );
8596 const onFocusCaptureProp = props.onFocusCapture;
8597 const onFocusCapture = useEvent((event) => {
8598 onFocusCaptureProp == null ? void 0 : onFocusCaptureProp(event);
8599 if (event.defaultPrevented) return;
8600 if (!store) return;
8601 const { virtualFocus: virtualFocus2 } = store.getState();
8602 if (!virtualFocus2) return;
8603 const previousActiveElement = event.relatedTarget;
8604 const isSilentlyFocused = silentlyFocused(event.currentTarget);
8605 if (isSelfTarget(event) && isSilentlyFocused) {
8606 event.stopPropagation();
8607 previousElementRef.current = previousActiveElement;
8608 }
8609 });
8610 const onFocusProp = props.onFocus;
8611 const onFocus = useEvent((event) => {
8612 onFocusProp == null ? void 0 : onFocusProp(event);
8613 if (event.defaultPrevented) return;
8614 if (!composite) return;
8615 if (!store) return;
8616 const { relatedTarget } = event;
8617 const { virtualFocus: virtualFocus2 } = store.getState();
8618 if (virtualFocus2) {
8619 if (isSelfTarget(event) && !isItem(store, relatedTarget)) {
8620 queueMicrotask(scheduleFocus);
8621 }
8622 } else if (isSelfTarget(event)) {
8623 store.setActiveId(null);
8624 }
8625 });
8626 const onBlurCaptureProp = props.onBlurCapture;
8627 const onBlurCapture = useEvent((event) => {
8628 var _a;
8629 onBlurCaptureProp == null ? void 0 : onBlurCaptureProp(event);
8630 if (event.defaultPrevented) return;
8631 if (!store) return;
8632 const { virtualFocus: virtualFocus2, activeId: activeId2 } = store.getState();
8633 if (!virtualFocus2) return;
8634 const activeElement = (_a = getEnabledItem(store, activeId2)) == null ? void 0 : _a.element;
8635 const nextActiveElement = event.relatedTarget;
8636 const nextActiveElementIsItem = isItem(store, nextActiveElement);
8637 const previousElement = previousElementRef.current;
8638 previousElementRef.current = null;
8639 if (isSelfTarget(event) && nextActiveElementIsItem) {
8640 if (nextActiveElement === activeElement) {
8641 if (previousElement && previousElement !== nextActiveElement) {
8642 fireBlurEvent(previousElement, event);
8643 }
8644 } else if (activeElement) {
8645 fireBlurEvent(activeElement, event);
8646 } else if (previousElement) {
8647 fireBlurEvent(previousElement, event);
8648 }
8649 event.stopPropagation();
8650 } else {
8651 const targetIsItem = isItem(store, event.target);
8652 if (!targetIsItem && activeElement) {
8653 fireBlurEvent(activeElement, event);
8654 }
8655 }
8656 });
8657 const onKeyDownProp = props.onKeyDown;
8658 const moveOnKeyPressProp = useBooleanEvent(moveOnKeyPress);
8659 const onKeyDown = useEvent((event) => {
8660 var _a;
8661 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
8662 if (event.nativeEvent.isComposing) return;
8663 if (event.defaultPrevented) return;
8664 if (!store) return;
8665 if (!isSelfTarget(event)) return;
8666 const { orientation, renderedItems, activeId: activeId2 } = store.getState();
8667 const activeItem = getEnabledItem(store, activeId2);
8668 if ((_a = activeItem == null ? void 0 : activeItem.element) == null ? void 0 : _a.isConnected) return;
8669 const isVertical = orientation !== "horizontal";
8670 const isHorizontal = orientation !== "vertical";
8671 const grid = isGrid(renderedItems);
8672 const isHorizontalKey = event.key === "ArrowLeft" || event.key === "ArrowRight" || event.key === "Home" || event.key === "End";
8673 if (isHorizontalKey && isTextField(event.currentTarget)) return;
8674 const up = () => {
8675 if (grid) {
8676 const item = findFirstEnabledItemInTheLastRow(renderedItems);
8677 return item == null ? void 0 : item.id;
8678 }
8679 return store == null ? void 0 : store.last();
8680 };
8681 const keyMap = {
8682 ArrowUp: (grid || isVertical) && up,
8683 ArrowRight: (grid || isHorizontal) && store.first,
8684 ArrowDown: (grid || isVertical) && store.first,
8685 ArrowLeft: (grid || isHorizontal) && store.last,
8686 Home: store.first,
8687 End: store.last,
8688 PageUp: store.first,
8689 PageDown: store.last
8690 };
8691 const action = keyMap[event.key];
8692 if (action) {
8693 const id = action();
8694 if (id !== void 0) {
8695 if (!moveOnKeyPressProp(event)) return;
8696 event.preventDefault();
8697 store.move(id);
8698 }
8699 }
8700 });
8701 props = useWrapElement(
8702 props,
8703 (element) => /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(CompositeContextProvider, { value: store, children: element }),
8704 [store]
8705 );
8706 const activeDescendant = store.useState((state) => {
8707 var _a;
8708 if (!store) return;
8709 if (!composite) return;
8710 if (!state.virtualFocus) return;
8711 return (_a = getEnabledItem(store, state.activeId)) == null ? void 0 : _a.id;
8712 });
8713 props = {
8714 "aria-activedescendant": activeDescendant,
8715 ...props,
8716 ref: useMergeRefs(ref, setBaseElement, props.ref),
8717 onKeyDownCapture,
8718 onKeyUpCapture,
8719 onFocusCapture,
8720 onFocus,
8721 onBlurCapture,
8722 onKeyDown
8723 };
8724 const focusable = store.useState(
8725 (state) => composite && (state.virtualFocus || state.activeId === null)
8726 );
8727 props = useFocusable({ focusable, ...props });
8728 return props;
8729 }
8730 );
8731 var Composite5 = forwardRef22(function Composite22(props) {
8732 const htmlProps = useComposite(props);
8733 return createElement3(TagName5, htmlProps);
8734 });
8735
8736 // node_modules/@ariakit/react-core/esm/__chunks/LVDQFHCH.js
8737 var ctx3 = createStoreContext();
8738 var useDisclosureContext = ctx3.useContext;
8739 var useDisclosureScopedContext = ctx3.useScopedContext;
8740 var useDisclosureProviderContext = ctx3.useProviderContext;
8741 var DisclosureContextProvider = ctx3.ContextProvider;
8742 var DisclosureScopedContextProvider = ctx3.ScopedContextProvider;
8743
8744 // node_modules/@ariakit/react-core/esm/__chunks/A62MDFCW.js
8745 var import_react14 = __toESM(require_react(), 1);
8746 var ctx4 = createStoreContext(
8747 [DisclosureContextProvider],
8748 [DisclosureScopedContextProvider]
8749 );
8750 var useDialogContext = ctx4.useContext;
8751 var useDialogScopedContext = ctx4.useScopedContext;
8752 var useDialogProviderContext = ctx4.useProviderContext;
8753 var DialogContextProvider = ctx4.ContextProvider;
8754 var DialogScopedContextProvider = ctx4.ScopedContextProvider;
8755 var DialogHeadingContext = (0, import_react14.createContext)(void 0);
8756 var DialogDescriptionContext = (0, import_react14.createContext)(void 0);
8757
8758 // node_modules/@ariakit/react-core/esm/__chunks/6B3RXHKP.js
8759 var import_react15 = __toESM(require_react(), 1);
8760 var import_react_dom = __toESM(require_react_dom(), 1);
8761 var import_jsx_runtime57 = __toESM(require_jsx_runtime(), 1);
8762 var TagName6 = "div";
8763 function afterTimeout(timeoutMs, cb) {
8764 const timeoutId = setTimeout(cb, timeoutMs);
8765 return () => clearTimeout(timeoutId);
8766 }
8767 function afterPaint2(cb) {
8768 let raf = requestAnimationFrame(() => {
8769 raf = requestAnimationFrame(cb);
8770 });
8771 return () => cancelAnimationFrame(raf);
8772 }
8773 function parseCSSTime(...times) {
8774 return times.join(", ").split(", ").reduce((longestTime, currentTimeString) => {
8775 const multiplier = currentTimeString.endsWith("ms") ? 1 : 1e3;
8776 const currentTime = Number.parseFloat(currentTimeString || "0s") * multiplier;
8777 if (currentTime > longestTime) return currentTime;
8778 return longestTime;
8779 }, 0);
8780 }
8781 function isHidden(mounted, hidden, alwaysVisible) {
8782 return !alwaysVisible && hidden !== false && (!mounted || !!hidden);
8783 }
8784 var useDisclosureContent = createHook(function useDisclosureContent2({ store, alwaysVisible, ...props }) {
8785 const context = useDisclosureProviderContext();
8786 store = store || context;
8787 invariant(
8788 store,
8789 "DisclosureContent must receive a `store` prop or be wrapped in a DisclosureProvider component."
8790 );
8791 const ref = (0, import_react15.useRef)(null);
8792 const id = useId3(props.id);
8793 const [transition, setTransition] = (0, import_react15.useState)(null);
8794 const open = store.useState("open");
8795 const mounted = store.useState("mounted");
8796 const animated = store.useState("animated");
8797 const contentElement = store.useState("contentElement");
8798 const otherElement = useStoreState(store.disclosure, "contentElement");
8799 useSafeLayoutEffect(() => {
8800 if (!ref.current) return;
8801 store == null ? void 0 : store.setContentElement(ref.current);
8802 }, [store]);
8803 useSafeLayoutEffect(() => {
8804 let previousAnimated;
8805 store == null ? void 0 : store.setState("animated", (animated2) => {
8806 previousAnimated = animated2;
8807 return true;
8808 });
8809 return () => {
8810 if (previousAnimated === void 0) return;
8811 store == null ? void 0 : store.setState("animated", previousAnimated);
8812 };
8813 }, [store]);
8814 useSafeLayoutEffect(() => {
8815 if (!animated) return;
8816 if (!(contentElement == null ? void 0 : contentElement.isConnected)) {
8817 setTransition(null);
8818 return;
8819 }
8820 return afterPaint2(() => {
8821 setTransition(open ? "enter" : mounted ? "leave" : null);
8822 });
8823 }, [animated, contentElement, open, mounted]);
8824 useSafeLayoutEffect(() => {
8825 if (!store) return;
8826 if (!animated) return;
8827 if (!transition) return;
8828 if (!contentElement) return;
8829 const stopAnimation = () => store == null ? void 0 : store.setState("animating", false);
8830 const stopAnimationSync = () => (0, import_react_dom.flushSync)(stopAnimation);
8831 if (transition === "leave" && open) return;
8832 if (transition === "enter" && !open) return;
8833 if (typeof animated === "number") {
8834 const timeout2 = animated;
8835 return afterTimeout(timeout2, stopAnimationSync);
8836 }
8837 const {
8838 transitionDuration,
8839 animationDuration,
8840 transitionDelay,
8841 animationDelay
8842 } = getComputedStyle(contentElement);
8843 const {
8844 transitionDuration: transitionDuration2 = "0",
8845 animationDuration: animationDuration2 = "0",
8846 transitionDelay: transitionDelay2 = "0",
8847 animationDelay: animationDelay2 = "0"
8848 } = otherElement ? getComputedStyle(otherElement) : {};
8849 const delay = parseCSSTime(
8850 transitionDelay,
8851 animationDelay,
8852 transitionDelay2,
8853 animationDelay2
8854 );
8855 const duration = parseCSSTime(
8856 transitionDuration,
8857 animationDuration,
8858 transitionDuration2,
8859 animationDuration2
8860 );
8861 const timeout = delay + duration;
8862 if (!timeout) {
8863 if (transition === "enter") {
8864 store.setState("animated", false);
8865 }
8866 stopAnimation();
8867 return;
8868 }
8869 const frameRate = 1e3 / 60;
8870 const maxTimeout = Math.max(timeout - frameRate, 0);
8871 return afterTimeout(maxTimeout, stopAnimationSync);
8872 }, [store, animated, contentElement, otherElement, open, transition]);
8873 props = useWrapElement(
8874 props,
8875 (element) => /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(DialogScopedContextProvider, { value: store, children: element }),
8876 [store]
8877 );
8878 const hidden = isHidden(mounted, props.hidden, alwaysVisible);
8879 const styleProp = props.style;
8880 const style = (0, import_react15.useMemo)(() => {
8881 if (hidden) {
8882 return { ...styleProp, display: "none" };
8883 }
8884 return styleProp;
8885 }, [hidden, styleProp]);
8886 props = {
8887 id,
8888 "data-open": open || void 0,
8889 "data-enter": transition === "enter" || void 0,
8890 "data-leave": transition === "leave" || void 0,
8891 hidden,
8892 ...props,
8893 ref: useMergeRefs(id ? store.setContentElement : null, ref, props.ref),
8894 style
8895 };
8896 return removeUndefinedValues(props);
8897 });
8898 var DisclosureContentImpl = forwardRef22(function DisclosureContentImpl2(props) {
8899 const htmlProps = useDisclosureContent(props);
8900 return createElement3(TagName6, htmlProps);
8901 });
8902 var DisclosureContent = forwardRef22(function DisclosureContent2({
8903 unmountOnHide,
8904 ...props
8905 }) {
8906 const context = useDisclosureProviderContext();
8907 const store = props.store || context;
8908 const mounted = useStoreState(
8909 store,
8910 (state) => !unmountOnHide || (state == null ? void 0 : state.mounted)
8911 );
8912 if (mounted === false) return null;
8913 return /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(DisclosureContentImpl, { ...props });
8914 });
8915
8916 // node_modules/@ariakit/core/esm/__chunks/75BJEVSH.js
8917 function createDisclosureStore(props = {}) {
8918 const store = mergeStore(
8919 props.store,
8920 omit2(props.disclosure, ["contentElement", "disclosureElement"])
8921 );
8922 throwOnConflictingProps(props, store);
8923 const syncState = store == null ? void 0 : store.getState();
8924 const open = defaultValue(
8925 props.open,
8926 syncState == null ? void 0 : syncState.open,
8927 props.defaultOpen,
8928 false
8929 );
8930 const animated = defaultValue(props.animated, syncState == null ? void 0 : syncState.animated, false);
8931 const initialState = {
8932 open,
8933 animated,
8934 animating: !!animated && open,
8935 mounted: open,
8936 contentElement: defaultValue(syncState == null ? void 0 : syncState.contentElement, null),
8937 disclosureElement: defaultValue(syncState == null ? void 0 : syncState.disclosureElement, null)
8938 };
8939 const disclosure = createStore(initialState, store);
8940 setup(
8941 disclosure,
8942 () => sync(disclosure, ["animated", "animating"], (state) => {
8943 if (state.animated) return;
8944 disclosure.setState("animating", false);
8945 })
8946 );
8947 setup(
8948 disclosure,
8949 () => subscribe(disclosure, ["open"], () => {
8950 if (!disclosure.getState().animated) return;
8951 disclosure.setState("animating", true);
8952 })
8953 );
8954 setup(
8955 disclosure,
8956 () => sync(disclosure, ["open", "animating"], (state) => {
8957 disclosure.setState("mounted", state.open || state.animating);
8958 })
8959 );
8960 return {
8961 ...disclosure,
8962 disclosure: props.disclosure,
8963 setOpen: (value) => disclosure.setState("open", value),
8964 show: () => disclosure.setState("open", true),
8965 hide: () => disclosure.setState("open", false),
8966 toggle: () => disclosure.setState("open", (open2) => !open2),
8967 stopAnimation: () => disclosure.setState("animating", false),
8968 setContentElement: (value) => disclosure.setState("contentElement", value),
8969 setDisclosureElement: (value) => disclosure.setState("disclosureElement", value)
8970 };
8971 }
8972
8973 // node_modules/@ariakit/react-core/esm/__chunks/WLZ6H5FH.js
8974 function useDisclosureStoreProps(store, update2, props) {
8975 useUpdateEffect(update2, [props.store, props.disclosure]);
8976 useStoreProps(store, props, "open", "setOpen");
8977 useStoreProps(store, props, "mounted", "setMounted");
8978 useStoreProps(store, props, "animated");
8979 return Object.assign(store, { disclosure: props.disclosure });
8980 }
8981
8982 // node_modules/@ariakit/react-core/esm/__chunks/JMU4N4M5.js
8983 var ctx5 = createStoreContext(
8984 [DialogContextProvider],
8985 [DialogScopedContextProvider]
8986 );
8987 var usePopoverContext = ctx5.useContext;
8988 var usePopoverScopedContext = ctx5.useScopedContext;
8989 var usePopoverProviderContext = ctx5.useProviderContext;
8990 var PopoverContextProvider = ctx5.ContextProvider;
8991 var PopoverScopedContextProvider = ctx5.ScopedContextProvider;
8992
8993 // node_modules/@ariakit/core/esm/__chunks/N5XGANPW.js
8994 function getCommonParent(items) {
8995 var _a;
8996 const firstItem = items.find((item) => !!item.element);
8997 const lastItem = [...items].reverse().find((item) => !!item.element);
8998 let parentElement = (_a = firstItem == null ? void 0 : firstItem.element) == null ? void 0 : _a.parentElement;
8999 while (parentElement && (lastItem == null ? void 0 : lastItem.element)) {
9000 const parent = parentElement;
9001 if (lastItem && parent.contains(lastItem.element)) {
9002 return parentElement;
9003 }
9004 parentElement = parentElement.parentElement;
9005 }
9006 return getDocument(parentElement).body;
9007 }
9008 function getPrivateStore(store) {
9009 return store == null ? void 0 : store.__unstablePrivateStore;
9010 }
9011 function createCollectionStore(props = {}) {
9012 var _a;
9013 throwOnConflictingProps(props, props.store);
9014 const syncState = (_a = props.store) == null ? void 0 : _a.getState();
9015 const items = defaultValue(
9016 props.items,
9017 syncState == null ? void 0 : syncState.items,
9018 props.defaultItems,
9019 []
9020 );
9021 const itemsMap = new Map(items.map((item) => [item.id, item]));
9022 const initialState = {
9023 items,
9024 renderedItems: defaultValue(syncState == null ? void 0 : syncState.renderedItems, [])
9025 };
9026 const syncPrivateStore = getPrivateStore(props.store);
9027 const privateStore = createStore(
9028 { items, renderedItems: initialState.renderedItems },
9029 syncPrivateStore
9030 );
9031 const collection = createStore(initialState, props.store);
9032 const sortItems = (renderedItems) => {
9033 const sortedItems = sortBasedOnDOMPosition(renderedItems, (i2) => i2.element);
9034 privateStore.setState("renderedItems", sortedItems);
9035 collection.setState("renderedItems", sortedItems);
9036 };
9037 setup(collection, () => init(privateStore));
9038 setup(privateStore, () => {
9039 return batch(privateStore, ["items"], (state) => {
9040 collection.setState("items", state.items);
9041 });
9042 });
9043 setup(privateStore, () => {
9044 return batch(privateStore, ["renderedItems"], (state) => {
9045 let firstRun = true;
9046 let raf = requestAnimationFrame(() => {
9047 const { renderedItems } = collection.getState();
9048 if (state.renderedItems === renderedItems) return;
9049 sortItems(state.renderedItems);
9050 });
9051 if (typeof IntersectionObserver !== "function") {
9052 return () => cancelAnimationFrame(raf);
9053 }
9054 const ioCallback = () => {
9055 if (firstRun) {
9056 firstRun = false;
9057 return;
9058 }
9059 cancelAnimationFrame(raf);
9060 raf = requestAnimationFrame(() => sortItems(state.renderedItems));
9061 };
9062 const root = getCommonParent(state.renderedItems);
9063 const observer = new IntersectionObserver(ioCallback, { root });
9064 for (const item of state.renderedItems) {
9065 if (!item.element) continue;
9066 observer.observe(item.element);
9067 }
9068 return () => {
9069 cancelAnimationFrame(raf);
9070 observer.disconnect();
9071 };
9072 });
9073 });
9074 const mergeItem = (item, setItems, canDeleteFromMap = false) => {
9075 let prevItem;
9076 setItems((items2) => {
9077 const index = items2.findIndex(({ id }) => id === item.id);
9078 const nextItems = items2.slice();
9079 if (index !== -1) {
9080 prevItem = items2[index];
9081 const nextItem = { ...prevItem, ...item };
9082 nextItems[index] = nextItem;
9083 itemsMap.set(item.id, nextItem);
9084 } else {
9085 nextItems.push(item);
9086 itemsMap.set(item.id, item);
9087 }
9088 return nextItems;
9089 });
9090 const unmergeItem = () => {
9091 setItems((items2) => {
9092 if (!prevItem) {
9093 if (canDeleteFromMap) {
9094 itemsMap.delete(item.id);
9095 }
9096 return items2.filter(({ id }) => id !== item.id);
9097 }
9098 const index = items2.findIndex(({ id }) => id === item.id);
9099 if (index === -1) return items2;
9100 const nextItems = items2.slice();
9101 nextItems[index] = prevItem;
9102 itemsMap.set(item.id, prevItem);
9103 return nextItems;
9104 });
9105 };
9106 return unmergeItem;
9107 };
9108 const registerItem = (item) => mergeItem(
9109 item,
9110 (getItems) => privateStore.setState("items", getItems),
9111 true
9112 );
9113 return {
9114 ...collection,
9115 registerItem,
9116 renderItem: (item) => chain(
9117 registerItem(item),
9118 mergeItem(
9119 item,
9120 (getItems) => privateStore.setState("renderedItems", getItems)
9121 )
9122 ),
9123 item: (id) => {
9124 if (!id) return null;
9125 let item = itemsMap.get(id);
9126 if (!item) {
9127 const { items: items2 } = privateStore.getState();
9128 item = items2.find((item2) => item2.id === id);
9129 if (item) {
9130 itemsMap.set(id, item);
9131 }
9132 }
9133 return item || null;
9134 },
9135 // @ts-expect-error Internal
9136 __unstablePrivateStore: privateStore
9137 };
9138 }
9139
9140 // node_modules/@ariakit/react-core/esm/__chunks/GVAFFF2B.js
9141 function useCollectionStoreProps(store, update2, props) {
9142 useUpdateEffect(update2, [props.store]);
9143 useStoreProps(store, props, "items", "setItems");
9144 return store;
9145 }
9146
9147 // node_modules/@ariakit/core/esm/__chunks/RVTIKFRL.js
9148 var NULL_ITEM = { id: null };
9149 function findFirstEnabledItem2(items, excludeId) {
9150 return items.find((item) => {
9151 if (excludeId) {
9152 return !item.disabled && item.id !== excludeId;
9153 }
9154 return !item.disabled;
9155 });
9156 }
9157 function getEnabledItems(items, excludeId) {
9158 return items.filter((item) => {
9159 if (excludeId) {
9160 return !item.disabled && item.id !== excludeId;
9161 }
9162 return !item.disabled;
9163 });
9164 }
9165 function getItemsInRow(items, rowId) {
9166 return items.filter((item) => item.rowId === rowId);
9167 }
9168 function flipItems(items, activeId, shouldInsertNullItem = false) {
9169 const index = items.findIndex((item) => item.id === activeId);
9170 return [
9171 ...items.slice(index + 1),
9172 ...shouldInsertNullItem ? [NULL_ITEM] : [],
9173 ...items.slice(0, index)
9174 ];
9175 }
9176 function groupItemsByRows2(items) {
9177 const rows = [];
9178 for (const item of items) {
9179 const row = rows.find((currentRow) => {
9180 var _a;
9181 return ((_a = currentRow[0]) == null ? void 0 : _a.rowId) === item.rowId;
9182 });
9183 if (row) {
9184 row.push(item);
9185 } else {
9186 rows.push([item]);
9187 }
9188 }
9189 return rows;
9190 }
9191 function getMaxRowLength(array) {
9192 let maxLength = 0;
9193 for (const { length } of array) {
9194 if (length > maxLength) {
9195 maxLength = length;
9196 }
9197 }
9198 return maxLength;
9199 }
9200 function createEmptyItem(rowId) {
9201 return {
9202 id: "__EMPTY_ITEM__",
9203 disabled: true,
9204 rowId
9205 };
9206 }
9207 function normalizeRows(rows, activeId, focusShift) {
9208 const maxLength = getMaxRowLength(rows);
9209 for (const row of rows) {
9210 for (let i2 = 0; i2 < maxLength; i2 += 1) {
9211 const item = row[i2];
9212 if (!item || focusShift && item.disabled) {
9213 const isFirst = i2 === 0;
9214 const previousItem = isFirst && focusShift ? findFirstEnabledItem2(row) : row[i2 - 1];
9215 row[i2] = previousItem && activeId !== previousItem.id && focusShift ? previousItem : createEmptyItem(previousItem == null ? void 0 : previousItem.rowId);
9216 }
9217 }
9218 }
9219 return rows;
9220 }
9221 function verticalizeItems(items) {
9222 const rows = groupItemsByRows2(items);
9223 const maxLength = getMaxRowLength(rows);
9224 const verticalized = [];
9225 for (let i2 = 0; i2 < maxLength; i2 += 1) {
9226 for (const row of rows) {
9227 const item = row[i2];
9228 if (item) {
9229 verticalized.push({
9230 ...item,
9231 // If there's no rowId, it means that it's not a grid composite, but
9232 // a single row instead. So, instead of verticalizing it, that is,
9233 // assigning a different rowId based on the column index, we keep it
9234 // undefined so they will be part of the same row. This is useful
9235 // when using up/down on one-dimensional composites.
9236 rowId: item.rowId ? `${i2}` : void 0
9237 });
9238 }
9239 }
9240 }
9241 return verticalized;
9242 }
9243 function createCompositeStore(props = {}) {
9244 var _a;
9245 const syncState = (_a = props.store) == null ? void 0 : _a.getState();
9246 const collection = createCollectionStore(props);
9247 const activeId = defaultValue(
9248 props.activeId,
9249 syncState == null ? void 0 : syncState.activeId,
9250 props.defaultActiveId
9251 );
9252 const initialState = {
9253 ...collection.getState(),
9254 id: defaultValue(
9255 props.id,
9256 syncState == null ? void 0 : syncState.id,
9257 `id-${Math.random().toString(36).slice(2, 8)}`
9258 ),
9259 activeId,
9260 baseElement: defaultValue(syncState == null ? void 0 : syncState.baseElement, null),
9261 includesBaseElement: defaultValue(
9262 props.includesBaseElement,
9263 syncState == null ? void 0 : syncState.includesBaseElement,
9264 activeId === null
9265 ),
9266 moves: defaultValue(syncState == null ? void 0 : syncState.moves, 0),
9267 orientation: defaultValue(
9268 props.orientation,
9269 syncState == null ? void 0 : syncState.orientation,
9270 "both"
9271 ),
9272 rtl: defaultValue(props.rtl, syncState == null ? void 0 : syncState.rtl, false),
9273 virtualFocus: defaultValue(
9274 props.virtualFocus,
9275 syncState == null ? void 0 : syncState.virtualFocus,
9276 false
9277 ),
9278 focusLoop: defaultValue(props.focusLoop, syncState == null ? void 0 : syncState.focusLoop, false),
9279 focusWrap: defaultValue(props.focusWrap, syncState == null ? void 0 : syncState.focusWrap, false),
9280 focusShift: defaultValue(props.focusShift, syncState == null ? void 0 : syncState.focusShift, false)
9281 };
9282 const composite = createStore(initialState, collection, props.store);
9283 setup(
9284 composite,
9285 () => sync(composite, ["renderedItems", "activeId"], (state) => {
9286 composite.setState("activeId", (activeId2) => {
9287 var _a2;
9288 if (activeId2 !== void 0) return activeId2;
9289 return (_a2 = findFirstEnabledItem2(state.renderedItems)) == null ? void 0 : _a2.id;
9290 });
9291 })
9292 );
9293 const getNextId = (direction = "next", options = {}) => {
9294 var _a2, _b;
9295 const defaultState = composite.getState();
9296 const {
9297 skip = 0,
9298 activeId: activeId2 = defaultState.activeId,
9299 focusShift = defaultState.focusShift,
9300 focusLoop = defaultState.focusLoop,
9301 focusWrap = defaultState.focusWrap,
9302 includesBaseElement = defaultState.includesBaseElement,
9303 renderedItems = defaultState.renderedItems,
9304 rtl = defaultState.rtl
9305 } = options;
9306 const isVerticalDirection = direction === "up" || direction === "down";
9307 const isNextDirection = direction === "next" || direction === "down";
9308 const canReverse = isNextDirection ? rtl && !isVerticalDirection : !rtl || isVerticalDirection;
9309 const canShift = focusShift && !skip;
9310 let items = !isVerticalDirection ? renderedItems : flatten2DArray(
9311 normalizeRows(groupItemsByRows2(renderedItems), activeId2, canShift)
9312 );
9313 items = canReverse ? reverseArray(items) : items;
9314 items = isVerticalDirection ? verticalizeItems(items) : items;
9315 if (activeId2 == null) {
9316 return (_a2 = findFirstEnabledItem2(items)) == null ? void 0 : _a2.id;
9317 }
9318 const activeItem = items.find((item) => item.id === activeId2);
9319 if (!activeItem) {
9320 return (_b = findFirstEnabledItem2(items)) == null ? void 0 : _b.id;
9321 }
9322 const isGrid2 = items.some((item) => item.rowId);
9323 const activeIndex = items.indexOf(activeItem);
9324 const nextItems = items.slice(activeIndex + 1);
9325 const nextItemsInRow = getItemsInRow(nextItems, activeItem.rowId);
9326 if (skip) {
9327 const nextEnabledItemsInRow = getEnabledItems(nextItemsInRow, activeId2);
9328 const nextItem2 = nextEnabledItemsInRow.slice(skip)[0] || // If we can't find an item, just return the last one.
9329 nextEnabledItemsInRow[nextEnabledItemsInRow.length - 1];
9330 return nextItem2 == null ? void 0 : nextItem2.id;
9331 }
9332 const canLoop = focusLoop && (isVerticalDirection ? focusLoop !== "horizontal" : focusLoop !== "vertical");
9333 const canWrap = isGrid2 && focusWrap && (isVerticalDirection ? focusWrap !== "horizontal" : focusWrap !== "vertical");
9334 const hasNullItem = isNextDirection ? (!isGrid2 || isVerticalDirection) && canLoop && includesBaseElement : isVerticalDirection ? includesBaseElement : false;
9335 if (canLoop) {
9336 const loopItems = canWrap && !hasNullItem ? items : getItemsInRow(items, activeItem.rowId);
9337 const sortedItems = flipItems(loopItems, activeId2, hasNullItem);
9338 const nextItem2 = findFirstEnabledItem2(sortedItems, activeId2);
9339 return nextItem2 == null ? void 0 : nextItem2.id;
9340 }
9341 if (canWrap) {
9342 const nextItem2 = findFirstEnabledItem2(
9343 // We can use nextItems, which contains all the next items, including
9344 // items from other rows, to wrap between rows. However, if there is a
9345 // null item (the composite container), we'll only use the next items in
9346 // the row. So moving next from the last item will focus on the
9347 // composite container. On grid composites, horizontal navigation never
9348 // focuses on the composite container, only vertical.
9349 hasNullItem ? nextItemsInRow : nextItems,
9350 activeId2
9351 );
9352 const nextId = hasNullItem ? (nextItem2 == null ? void 0 : nextItem2.id) || null : nextItem2 == null ? void 0 : nextItem2.id;
9353 return nextId;
9354 }
9355 const nextItem = findFirstEnabledItem2(nextItemsInRow, activeId2);
9356 if (!nextItem && hasNullItem) {
9357 return null;
9358 }
9359 return nextItem == null ? void 0 : nextItem.id;
9360 };
9361 return {
9362 ...collection,
9363 ...composite,
9364 setBaseElement: (element) => composite.setState("baseElement", element),
9365 setActiveId: (id) => composite.setState("activeId", id),
9366 move: (id) => {
9367 if (id === void 0) return;
9368 composite.setState("activeId", id);
9369 composite.setState("moves", (moves) => moves + 1);
9370 },
9371 first: () => {
9372 var _a2;
9373 return (_a2 = findFirstEnabledItem2(composite.getState().renderedItems)) == null ? void 0 : _a2.id;
9374 },
9375 last: () => {
9376 var _a2;
9377 return (_a2 = findFirstEnabledItem2(reverseArray(composite.getState().renderedItems))) == null ? void 0 : _a2.id;
9378 },
9379 next: (options) => {
9380 if (options !== void 0 && typeof options === "number") {
9381 options = { skip: options };
9382 }
9383 return getNextId("next", options);
9384 },
9385 previous: (options) => {
9386 if (options !== void 0 && typeof options === "number") {
9387 options = { skip: options };
9388 }
9389 return getNextId("previous", options);
9390 },
9391 down: (options) => {
9392 if (options !== void 0 && typeof options === "number") {
9393 options = { skip: options };
9394 }
9395 return getNextId("down", options);
9396 },
9397 up: (options) => {
9398 if (options !== void 0 && typeof options === "number") {
9399 options = { skip: options };
9400 }
9401 return getNextId("up", options);
9402 }
9403 };
9404 }
9405
9406 // node_modules/@ariakit/react-core/esm/__chunks/IQYAUKXT.js
9407 function useCompositeStoreOptions(props) {
9408 const id = useId3(props.id);
9409 return { id, ...props };
9410 }
9411 function useCompositeStoreProps(store, update2, props) {
9412 store = useCollectionStoreProps(store, update2, props);
9413 useStoreProps(store, props, "activeId", "setActiveId");
9414 useStoreProps(store, props, "includesBaseElement");
9415 useStoreProps(store, props, "virtualFocus");
9416 useStoreProps(store, props, "orientation");
9417 useStoreProps(store, props, "rtl");
9418 useStoreProps(store, props, "focusLoop");
9419 useStoreProps(store, props, "focusWrap");
9420 useStoreProps(store, props, "focusShift");
9421 return store;
9422 }
9423
9424 // node_modules/@ariakit/react-core/esm/__chunks/CVCFNOHX.js
9425 var import_react16 = __toESM(require_react(), 1);
9426 var ComboboxListRoleContext = (0, import_react16.createContext)(
9427 void 0
9428 );
9429 var ctx6 = createStoreContext(
9430 [PopoverContextProvider, CompositeContextProvider],
9431 [PopoverScopedContextProvider, CompositeScopedContextProvider]
9432 );
9433 var useComboboxContext = ctx6.useContext;
9434 var useComboboxScopedContext = ctx6.useScopedContext;
9435 var useComboboxProviderContext = ctx6.useProviderContext;
9436 var ComboboxContextProvider = ctx6.ContextProvider;
9437 var ComboboxScopedContextProvider = ctx6.ScopedContextProvider;
9438 var ComboboxItemValueContext = (0, import_react16.createContext)(
9439 void 0
9440 );
9441 var ComboboxItemCheckedContext = (0, import_react16.createContext)(false);
9442
9443 // node_modules/@ariakit/core/esm/__chunks/KMAUV3TY.js
9444 function createDialogStore(props = {}) {
9445 return createDisclosureStore(props);
9446 }
9447
9448 // node_modules/@ariakit/react-core/esm/__chunks/4NYSH4UO.js
9449 function useDialogStoreProps(store, update2, props) {
9450 return useDisclosureStoreProps(store, update2, props);
9451 }
9452
9453 // node_modules/@ariakit/core/esm/__chunks/BFGNM53A.js
9454 function createPopoverStore({
9455 popover: otherPopover,
9456 ...props
9457 } = {}) {
9458 const store = mergeStore(
9459 props.store,
9460 omit2(otherPopover, [
9461 "arrowElement",
9462 "anchorElement",
9463 "contentElement",
9464 "popoverElement",
9465 "disclosureElement"
9466 ])
9467 );
9468 throwOnConflictingProps(props, store);
9469 const syncState = store == null ? void 0 : store.getState();
9470 const dialog = createDialogStore({ ...props, store });
9471 const placement = defaultValue(
9472 props.placement,
9473 syncState == null ? void 0 : syncState.placement,
9474 "bottom"
9475 );
9476 const initialState = {
9477 ...dialog.getState(),
9478 placement,
9479 currentPlacement: placement,
9480 anchorElement: defaultValue(syncState == null ? void 0 : syncState.anchorElement, null),
9481 popoverElement: defaultValue(syncState == null ? void 0 : syncState.popoverElement, null),
9482 arrowElement: defaultValue(syncState == null ? void 0 : syncState.arrowElement, null),
9483 rendered: /* @__PURE__ */ Symbol("rendered")
9484 };
9485 const popover = createStore(initialState, dialog, store);
9486 return {
9487 ...dialog,
9488 ...popover,
9489 setAnchorElement: (element) => popover.setState("anchorElement", element),
9490 setPopoverElement: (element) => popover.setState("popoverElement", element),
9491 setArrowElement: (element) => popover.setState("arrowElement", element),
9492 render: () => popover.setState("rendered", /* @__PURE__ */ Symbol("rendered"))
9493 };
9494 }
9495
9496 // node_modules/@ariakit/react-core/esm/__chunks/B6FLPFJM.js
9497 function usePopoverStoreProps(store, update2, props) {
9498 useUpdateEffect(update2, [props.popover]);
9499 useStoreProps(store, props, "placement");
9500 return useDialogStoreProps(store, update2, props);
9501 }
9502
9503 // node_modules/@ariakit/react-core/esm/__chunks/4POTBZ2J.js
9504 var TagName7 = "div";
9505 var usePopoverAnchor = createHook(
9506 function usePopoverAnchor2({ store, ...props }) {
9507 const context = usePopoverProviderContext();
9508 store = store || context;
9509 props = {
9510 ...props,
9511 ref: useMergeRefs(store == null ? void 0 : store.setAnchorElement, props.ref)
9512 };
9513 return props;
9514 }
9515 );
9516 var PopoverAnchor = forwardRef22(function PopoverAnchor2(props) {
9517 const htmlProps = usePopoverAnchor(props);
9518 return createElement3(TagName7, htmlProps);
9519 });
9520
9521 // node_modules/@ariakit/react-core/esm/__chunks/X6LNAU2F.js
9522 var import_react17 = __toESM(require_react(), 1);
9523 var TagName8 = "div";
9524 function getMouseDestination(event) {
9525 const relatedTarget = event.relatedTarget;
9526 if ((relatedTarget == null ? void 0 : relatedTarget.nodeType) === Node.ELEMENT_NODE) {
9527 return relatedTarget;
9528 }
9529 return null;
9530 }
9531 function hoveringInside(event) {
9532 const nextElement = getMouseDestination(event);
9533 if (!nextElement) return false;
9534 return contains(event.currentTarget, nextElement);
9535 }
9536 var symbol2 = /* @__PURE__ */ Symbol("composite-hover");
9537 function movingToAnotherItem(event) {
9538 let dest = getMouseDestination(event);
9539 if (!dest) return false;
9540 do {
9541 if (hasOwnProperty(dest, symbol2) && dest[symbol2]) return true;
9542 dest = dest.parentElement;
9543 } while (dest);
9544 return false;
9545 }
9546 var useCompositeHover = createHook(
9547 function useCompositeHover2({
9548 store,
9549 focusOnHover = true,
9550 blurOnHoverEnd = !!focusOnHover,
9551 ...props
9552 }) {
9553 const context = useCompositeContext();
9554 store = store || context;
9555 invariant(
9556 store,
9557 "CompositeHover must be wrapped in a Composite component."
9558 );
9559 const isMouseMoving = useIsMouseMoving();
9560 const onMouseMoveProp = props.onMouseMove;
9561 const focusOnHoverProp = useBooleanEvent(focusOnHover);
9562 const onMouseMove = useEvent((event) => {
9563 onMouseMoveProp == null ? void 0 : onMouseMoveProp(event);
9564 if (event.defaultPrevented) return;
9565 if (!isMouseMoving()) return;
9566 if (!focusOnHoverProp(event)) return;
9567 if (!hasFocusWithin(event.currentTarget)) {
9568 const baseElement = store == null ? void 0 : store.getState().baseElement;
9569 if (baseElement && !hasFocus(baseElement)) {
9570 baseElement.focus();
9571 }
9572 }
9573 store == null ? void 0 : store.setActiveId(event.currentTarget.id);
9574 });
9575 const onMouseLeaveProp = props.onMouseLeave;
9576 const blurOnHoverEndProp = useBooleanEvent(blurOnHoverEnd);
9577 const onMouseLeave = useEvent((event) => {
9578 var _a;
9579 onMouseLeaveProp == null ? void 0 : onMouseLeaveProp(event);
9580 if (event.defaultPrevented) return;
9581 if (!isMouseMoving()) return;
9582 if (hoveringInside(event)) return;
9583 if (movingToAnotherItem(event)) return;
9584 if (!focusOnHoverProp(event)) return;
9585 if (!blurOnHoverEndProp(event)) return;
9586 store == null ? void 0 : store.setActiveId(null);
9587 (_a = store == null ? void 0 : store.getState().baseElement) == null ? void 0 : _a.focus();
9588 });
9589 const ref = (0, import_react17.useCallback)((element) => {
9590 if (!element) return;
9591 element[symbol2] = true;
9592 }, []);
9593 props = {
9594 ...props,
9595 ref: useMergeRefs(ref, props.ref),
9596 onMouseMove,
9597 onMouseLeave
9598 };
9599 return removeUndefinedValues(props);
9600 }
9601 );
9602 var CompositeHover = memo22(
9603 forwardRef22(function CompositeHover2(props) {
9604 const htmlProps = useCompositeHover(props);
9605 return createElement3(TagName8, htmlProps);
9606 })
9607 );
9608
9609 // node_modules/@ariakit/react-core/esm/combobox/combobox.js
9610 var import_react18 = __toESM(require_react(), 1);
9611 var TagName9 = "input";
9612 function isFirstItemAutoSelected(items, activeValue, autoSelect) {
9613 if (!autoSelect) return false;
9614 const firstItem = items.find((item) => !item.disabled && item.value);
9615 return (firstItem == null ? void 0 : firstItem.value) === activeValue;
9616 }
9617 function hasCompletionString(value, activeValue) {
9618 if (!activeValue) return false;
9619 if (value == null) return false;
9620 value = normalizeString(value);
9621 return activeValue.length > value.length && activeValue.toLowerCase().indexOf(value.toLowerCase()) === 0;
9622 }
9623 function isInputEvent(event) {
9624 return event.type === "input";
9625 }
9626 function isAriaAutoCompleteValue(value) {
9627 return value === "inline" || value === "list" || value === "both" || value === "none";
9628 }
9629 function getDefaultAutoSelectId(items) {
9630 const item = items.find((item2) => {
9631 var _a;
9632 if (item2.disabled) return false;
9633 return ((_a = item2.element) == null ? void 0 : _a.getAttribute("role")) !== "tab";
9634 });
9635 return item == null ? void 0 : item.id;
9636 }
9637 var useCombobox = createHook(
9638 function useCombobox2({
9639 store,
9640 focusable = true,
9641 autoSelect: autoSelectProp = false,
9642 getAutoSelectId,
9643 setValueOnChange,
9644 showMinLength = 0,
9645 showOnChange,
9646 showOnMouseDown,
9647 showOnClick = showOnMouseDown,
9648 showOnKeyDown,
9649 showOnKeyPress = showOnKeyDown,
9650 blurActiveItemOnClick,
9651 setValueOnClick = true,
9652 moveOnKeyPress = true,
9653 autoComplete = "list",
9654 ...props
9655 }) {
9656 const context = useComboboxProviderContext();
9657 store = store || context;
9658 invariant(
9659 store,
9660 "Combobox must receive a `store` prop or be wrapped in a ComboboxProvider component."
9661 );
9662 const ref = (0, import_react18.useRef)(null);
9663 const [valueUpdated, forceValueUpdate] = useForceUpdate();
9664 const canAutoSelectRef = (0, import_react18.useRef)(false);
9665 const composingRef = (0, import_react18.useRef)(false);
9666 const autoSelect = store.useState(
9667 (state) => state.virtualFocus && autoSelectProp
9668 );
9669 const inline = autoComplete === "inline" || autoComplete === "both";
9670 const [canInline, setCanInline] = (0, import_react18.useState)(inline);
9671 useUpdateLayoutEffect(() => {
9672 if (!inline) return;
9673 setCanInline(true);
9674 }, [inline]);
9675 const storeValue = store.useState("value");
9676 const prevSelectedValueRef = (0, import_react18.useRef)(void 0);
9677 (0, import_react18.useEffect)(() => {
9678 return sync(store, ["selectedValue", "activeId"], (_, prev) => {
9679 prevSelectedValueRef.current = prev.selectedValue;
9680 });
9681 }, []);
9682 const inlineActiveValue = store.useState((state) => {
9683 var _a;
9684 if (!inline) return;
9685 if (!canInline) return;
9686 if (state.activeValue && Array.isArray(state.selectedValue)) {
9687 if (state.selectedValue.includes(state.activeValue)) return;
9688 if ((_a = prevSelectedValueRef.current) == null ? void 0 : _a.includes(state.activeValue)) return;
9689 }
9690 return state.activeValue;
9691 });
9692 const items = store.useState("renderedItems");
9693 const open = store.useState("open");
9694 const contentElement = store.useState("contentElement");
9695 const value = (0, import_react18.useMemo)(() => {
9696 if (!inline) return storeValue;
9697 if (!canInline) return storeValue;
9698 const firstItemAutoSelected = isFirstItemAutoSelected(
9699 items,
9700 inlineActiveValue,
9701 autoSelect
9702 );
9703 if (firstItemAutoSelected) {
9704 if (hasCompletionString(storeValue, inlineActiveValue)) {
9705 const slice = (inlineActiveValue == null ? void 0 : inlineActiveValue.slice(storeValue.length)) || "";
9706 return storeValue + slice;
9707 }
9708 return storeValue;
9709 }
9710 return inlineActiveValue || storeValue;
9711 }, [inline, canInline, items, inlineActiveValue, autoSelect, storeValue]);
9712 (0, import_react18.useEffect)(() => {
9713 const element = ref.current;
9714 if (!element) return;
9715 const onCompositeItemMove = () => setCanInline(true);
9716 element.addEventListener("combobox-item-move", onCompositeItemMove);
9717 return () => {
9718 element.removeEventListener("combobox-item-move", onCompositeItemMove);
9719 };
9720 }, []);
9721 (0, import_react18.useEffect)(() => {
9722 if (!inline) return;
9723 if (!canInline) return;
9724 if (!inlineActiveValue) return;
9725 const firstItemAutoSelected = isFirstItemAutoSelected(
9726 items,
9727 inlineActiveValue,
9728 autoSelect
9729 );
9730 if (!firstItemAutoSelected) return;
9731 if (!hasCompletionString(storeValue, inlineActiveValue)) return;
9732 let cleanup = noop2;
9733 queueMicrotask(() => {
9734 const element = ref.current;
9735 if (!element) return;
9736 const { start: prevStart, end: prevEnd } = getTextboxSelection(element);
9737 const nextStart = storeValue.length;
9738 const nextEnd = inlineActiveValue.length;
9739 setSelectionRange(element, nextStart, nextEnd);
9740 cleanup = () => {
9741 if (!hasFocus(element)) return;
9742 const { start, end } = getTextboxSelection(element);
9743 if (start !== nextStart) return;
9744 if (end !== nextEnd) return;
9745 setSelectionRange(element, prevStart, prevEnd);
9746 };
9747 });
9748 return () => cleanup();
9749 }, [
9750 valueUpdated,
9751 inline,
9752 canInline,
9753 inlineActiveValue,
9754 items,
9755 autoSelect,
9756 storeValue
9757 ]);
9758 const scrollingElementRef = (0, import_react18.useRef)(null);
9759 const getAutoSelectIdProp = useEvent(getAutoSelectId);
9760 const autoSelectIdRef = (0, import_react18.useRef)(null);
9761 (0, import_react18.useEffect)(() => {
9762 if (!open) return;
9763 if (!contentElement) return;
9764 const scrollingElement = getScrollingElement(contentElement);
9765 if (!scrollingElement) return;
9766 scrollingElementRef.current = scrollingElement;
9767 const onUserScroll = () => {
9768 canAutoSelectRef.current = false;
9769 };
9770 const onScroll = () => {
9771 if (!store) return;
9772 if (!canAutoSelectRef.current) return;
9773 const { activeId } = store.getState();
9774 if (activeId === null) return;
9775 if (activeId === autoSelectIdRef.current) return;
9776 canAutoSelectRef.current = false;
9777 };
9778 const options = { passive: true, capture: true };
9779 scrollingElement.addEventListener("wheel", onUserScroll, options);
9780 scrollingElement.addEventListener("touchmove", onUserScroll, options);
9781 scrollingElement.addEventListener("scroll", onScroll, options);
9782 return () => {
9783 scrollingElement.removeEventListener("wheel", onUserScroll, true);
9784 scrollingElement.removeEventListener("touchmove", onUserScroll, true);
9785 scrollingElement.removeEventListener("scroll", onScroll, true);
9786 };
9787 }, [open, contentElement, store]);
9788 useSafeLayoutEffect(() => {
9789 if (!storeValue) return;
9790 if (composingRef.current) return;
9791 canAutoSelectRef.current = true;
9792 }, [storeValue]);
9793 useSafeLayoutEffect(() => {
9794 if (autoSelect !== "always" && open) return;
9795 canAutoSelectRef.current = open;
9796 }, [autoSelect, open]);
9797 const resetValueOnSelect = store.useState("resetValueOnSelect");
9798 useUpdateEffect(() => {
9799 var _a, _b;
9800 const canAutoSelect = canAutoSelectRef.current;
9801 if (!store) return;
9802 if (!open) return;
9803 if (!canAutoSelect && !resetValueOnSelect) return;
9804 const { baseElement, contentElement: contentElement2, activeId } = store.getState();
9805 if (baseElement && !hasFocus(baseElement)) return;
9806 if (contentElement2 == null ? void 0 : contentElement2.hasAttribute("data-placing")) {
9807 const observer = new MutationObserver(forceValueUpdate);
9808 observer.observe(contentElement2, { attributeFilter: ["data-placing"] });
9809 return () => observer.disconnect();
9810 }
9811 if (autoSelect && canAutoSelect) {
9812 const userAutoSelectId = getAutoSelectIdProp(items);
9813 const autoSelectId = userAutoSelectId !== void 0 ? userAutoSelectId : (_a = getDefaultAutoSelectId(items)) != null ? _a : store.first();
9814 autoSelectIdRef.current = autoSelectId;
9815 store.move(autoSelectId != null ? autoSelectId : null);
9816 } else {
9817 const element = (_b = store.item(activeId || store.first())) == null ? void 0 : _b.element;
9818 if (element && "scrollIntoView" in element) {
9819 element.scrollIntoView({ block: "nearest", inline: "nearest" });
9820 }
9821 }
9822 return;
9823 }, [
9824 store,
9825 open,
9826 valueUpdated,
9827 storeValue,
9828 autoSelect,
9829 resetValueOnSelect,
9830 getAutoSelectIdProp,
9831 items
9832 ]);
9833 (0, import_react18.useEffect)(() => {
9834 if (!inline) return;
9835 const combobox = ref.current;
9836 if (!combobox) return;
9837 const elements = [combobox, contentElement].filter(
9838 (value2) => !!value2
9839 );
9840 const onBlur2 = (event) => {
9841 if (elements.every((el) => isFocusEventOutside(event, el))) {
9842 store == null ? void 0 : store.setValue(value);
9843 }
9844 };
9845 for (const element of elements) {
9846 element.addEventListener("focusout", onBlur2);
9847 }
9848 return () => {
9849 for (const element of elements) {
9850 element.removeEventListener("focusout", onBlur2);
9851 }
9852 };
9853 }, [inline, contentElement, store, value]);
9854 const canShow = (event) => {
9855 const currentTarget = event.currentTarget;
9856 return currentTarget.value.length >= showMinLength;
9857 };
9858 const onChangeProp = props.onChange;
9859 const showOnChangeProp = useBooleanEvent(showOnChange != null ? showOnChange : canShow);
9860 const setValueOnChangeProp = useBooleanEvent(
9861 // If the combobox is combined with tags, the value will be set by the tag
9862 // input component.
9863 setValueOnChange != null ? setValueOnChange : !store.tag
9864 );
9865 const onChange = useEvent((event) => {
9866 onChangeProp == null ? void 0 : onChangeProp(event);
9867 if (event.defaultPrevented) return;
9868 if (!store) return;
9869 const currentTarget = event.currentTarget;
9870 const { value: value2, selectionStart, selectionEnd } = currentTarget;
9871 const nativeEvent = event.nativeEvent;
9872 canAutoSelectRef.current = true;
9873 if (isInputEvent(nativeEvent)) {
9874 if (nativeEvent.isComposing) {
9875 canAutoSelectRef.current = false;
9876 composingRef.current = true;
9877 }
9878 if (inline) {
9879 const textInserted = nativeEvent.inputType === "insertText" || nativeEvent.inputType === "insertCompositionText";
9880 const caretAtEnd = selectionStart === value2.length;
9881 setCanInline(textInserted && caretAtEnd);
9882 }
9883 }
9884 if (setValueOnChangeProp(event)) {
9885 const isSameValue = value2 === store.getState().value;
9886 store.setValue(value2);
9887 queueMicrotask(() => {
9888 setSelectionRange(currentTarget, selectionStart, selectionEnd);
9889 });
9890 if (inline && autoSelect && isSameValue) {
9891 forceValueUpdate();
9892 }
9893 }
9894 if (showOnChangeProp(event)) {
9895 store.show();
9896 }
9897 if (!autoSelect || !canAutoSelectRef.current) {
9898 store.setActiveId(null);
9899 }
9900 });
9901 const onCompositionEndProp = props.onCompositionEnd;
9902 const onCompositionEnd = useEvent((event) => {
9903 canAutoSelectRef.current = true;
9904 composingRef.current = false;
9905 onCompositionEndProp == null ? void 0 : onCompositionEndProp(event);
9906 if (event.defaultPrevented) return;
9907 if (!autoSelect) return;
9908 forceValueUpdate();
9909 });
9910 const onMouseDownProp = props.onMouseDown;
9911 const blurActiveItemOnClickProp = useBooleanEvent(
9912 blurActiveItemOnClick != null ? blurActiveItemOnClick : (() => !!(store == null ? void 0 : store.getState().includesBaseElement))
9913 );
9914 const setValueOnClickProp = useBooleanEvent(setValueOnClick);
9915 const showOnClickProp = useBooleanEvent(showOnClick != null ? showOnClick : canShow);
9916 const onMouseDown = useEvent((event) => {
9917 onMouseDownProp == null ? void 0 : onMouseDownProp(event);
9918 if (event.defaultPrevented) return;
9919 if (event.button) return;
9920 if (event.ctrlKey) return;
9921 if (!store) return;
9922 if (blurActiveItemOnClickProp(event)) {
9923 store.setActiveId(null);
9924 }
9925 if (setValueOnClickProp(event)) {
9926 store.setValue(value);
9927 }
9928 if (showOnClickProp(event)) {
9929 queueBeforeEvent(event.currentTarget, "mouseup", store.show);
9930 }
9931 });
9932 const onKeyDownProp = props.onKeyDown;
9933 const showOnKeyPressProp = useBooleanEvent(showOnKeyPress != null ? showOnKeyPress : canShow);
9934 const onKeyDown = useEvent((event) => {
9935 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
9936 if (!event.repeat) {
9937 canAutoSelectRef.current = false;
9938 }
9939 if (event.defaultPrevented) return;
9940 if (event.ctrlKey) return;
9941 if (event.altKey) return;
9942 if (event.shiftKey) return;
9943 if (event.metaKey) return;
9944 if (!store) return;
9945 const { open: open2 } = store.getState();
9946 if (open2) return;
9947 if (event.key === "ArrowUp" || event.key === "ArrowDown") {
9948 if (showOnKeyPressProp(event)) {
9949 event.preventDefault();
9950 store.show();
9951 }
9952 }
9953 });
9954 const onBlurProp = props.onBlur;
9955 const onBlur = useEvent((event) => {
9956 canAutoSelectRef.current = false;
9957 onBlurProp == null ? void 0 : onBlurProp(event);
9958 if (event.defaultPrevented) return;
9959 });
9960 const id = useId3(props.id);
9961 const ariaAutoComplete = isAriaAutoCompleteValue(autoComplete) ? autoComplete : void 0;
9962 const isActiveItem = store.useState((state) => state.activeId === null);
9963 props = {
9964 id,
9965 role: "combobox",
9966 "aria-autocomplete": ariaAutoComplete,
9967 "aria-haspopup": getPopupRole(contentElement, "listbox"),
9968 "aria-expanded": open,
9969 "aria-controls": contentElement == null ? void 0 : contentElement.id,
9970 "data-active-item": isActiveItem || void 0,
9971 value,
9972 ...props,
9973 ref: useMergeRefs(ref, props.ref),
9974 onChange,
9975 onCompositionEnd,
9976 onMouseDown,
9977 onKeyDown,
9978 onBlur
9979 };
9980 props = useComposite({
9981 store,
9982 focusable,
9983 ...props,
9984 // Enable inline autocomplete when the user moves from the combobox input
9985 // to an item.
9986 moveOnKeyPress: (event) => {
9987 if (isFalsyBooleanCallback(moveOnKeyPress, event)) return false;
9988 if (inline) setCanInline(true);
9989 return true;
9990 }
9991 });
9992 props = usePopoverAnchor({ store, ...props });
9993 return { autoComplete: "off", ...props };
9994 }
9995 );
9996 var Combobox = forwardRef22(function Combobox2(props) {
9997 const htmlProps = useCombobox(props);
9998 return createElement3(TagName9, htmlProps);
9999 });
10000
10001 // node_modules/@ariakit/react-core/esm/__chunks/IBXZ2LQC.js
10002 var import_react19 = __toESM(require_react(), 1);
10003 var import_jsx_runtime58 = __toESM(require_jsx_runtime(), 1);
10004 var TagName10 = "div";
10005 function isSelected(storeValue, itemValue) {
10006 if (itemValue == null) return;
10007 if (storeValue == null) return false;
10008 if (Array.isArray(storeValue)) {
10009 return storeValue.includes(itemValue);
10010 }
10011 return storeValue === itemValue;
10012 }
10013 function getItemRole(popupRole) {
10014 var _a;
10015 const itemRoleByPopupRole = {
10016 menu: "menuitem",
10017 listbox: "option",
10018 tree: "treeitem"
10019 };
10020 const key = popupRole;
10021 return (_a = itemRoleByPopupRole[key]) != null ? _a : "option";
10022 }
10023 var useComboboxItem = createHook(
10024 function useComboboxItem2({
10025 store,
10026 value,
10027 hideOnClick,
10028 setValueOnClick,
10029 selectValueOnClick = true,
10030 resetValueOnSelect,
10031 focusOnHover = false,
10032 moveOnKeyPress = true,
10033 getItem: getItemProp,
10034 ...props
10035 }) {
10036 var _a;
10037 const context = useComboboxScopedContext();
10038 store = store || context;
10039 invariant(
10040 store,
10041 "ComboboxItem must be wrapped in a ComboboxList or ComboboxPopover component."
10042 );
10043 const { resetValueOnSelectState, multiSelectable, selected } = useStoreStateObject(store, {
10044 resetValueOnSelectState: "resetValueOnSelect",
10045 multiSelectable(state) {
10046 return Array.isArray(state.selectedValue);
10047 },
10048 selected(state) {
10049 return isSelected(state.selectedValue, value);
10050 }
10051 });
10052 const getItem = (0, import_react19.useCallback)(
10053 (item) => {
10054 const nextItem = { ...item, value };
10055 if (getItemProp) {
10056 return getItemProp(nextItem);
10057 }
10058 return nextItem;
10059 },
10060 [value, getItemProp]
10061 );
10062 setValueOnClick = setValueOnClick != null ? setValueOnClick : !multiSelectable;
10063 hideOnClick = hideOnClick != null ? hideOnClick : value != null && !multiSelectable;
10064 const onClickProp = props.onClick;
10065 const setValueOnClickProp = useBooleanEvent(setValueOnClick);
10066 const selectValueOnClickProp = useBooleanEvent(selectValueOnClick);
10067 const resetValueOnSelectProp = useBooleanEvent(
10068 (_a = resetValueOnSelect != null ? resetValueOnSelect : resetValueOnSelectState) != null ? _a : multiSelectable
10069 );
10070 const hideOnClickProp = useBooleanEvent(hideOnClick);
10071 const onClick = useEvent((event) => {
10072 onClickProp == null ? void 0 : onClickProp(event);
10073 if (event.defaultPrevented) return;
10074 if (isDownloading(event)) return;
10075 if (isOpeningInNewTab(event)) return;
10076 if (value != null) {
10077 if (selectValueOnClickProp(event)) {
10078 if (resetValueOnSelectProp(event)) {
10079 store == null ? void 0 : store.resetValue();
10080 }
10081 store == null ? void 0 : store.setSelectedValue((prevValue) => {
10082 if (!Array.isArray(prevValue)) return value;
10083 if (prevValue.includes(value)) {
10084 return prevValue.filter((v2) => v2 !== value);
10085 }
10086 return [...prevValue, value];
10087 });
10088 }
10089 if (setValueOnClickProp(event)) {
10090 store == null ? void 0 : store.setValue(value);
10091 }
10092 }
10093 if (hideOnClickProp(event)) {
10094 store == null ? void 0 : store.hide();
10095 }
10096 });
10097 const onKeyDownProp = props.onKeyDown;
10098 const onKeyDown = useEvent((event) => {
10099 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
10100 if (event.defaultPrevented) return;
10101 const baseElement = store == null ? void 0 : store.getState().baseElement;
10102 if (!baseElement) return;
10103 if (hasFocus(baseElement)) return;
10104 const printable = event.key.length === 1;
10105 if (printable || event.key === "Backspace" || event.key === "Delete") {
10106 queueMicrotask(() => baseElement.focus());
10107 if (isTextField(baseElement)) {
10108 store == null ? void 0 : store.setValue(baseElement.value);
10109 }
10110 }
10111 });
10112 if (multiSelectable && selected != null) {
10113 props = {
10114 "aria-selected": selected,
10115 ...props
10116 };
10117 }
10118 props = useWrapElement(
10119 props,
10120 (element) => /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(ComboboxItemValueContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(ComboboxItemCheckedContext.Provider, { value: selected != null ? selected : false, children: element }) }),
10121 [value, selected]
10122 );
10123 const popupRole = (0, import_react19.useContext)(ComboboxListRoleContext);
10124 props = {
10125 role: getItemRole(popupRole),
10126 children: value,
10127 ...props,
10128 onClick,
10129 onKeyDown
10130 };
10131 const moveOnKeyPressProp = useBooleanEvent(moveOnKeyPress);
10132 props = useCompositeItem({
10133 store,
10134 ...props,
10135 getItem,
10136 // Dispatch a custom event on the combobox input when moving to an item
10137 // with the keyboard so the Combobox component can enable inline
10138 // autocompletion.
10139 moveOnKeyPress: (event) => {
10140 if (!moveOnKeyPressProp(event)) return false;
10141 const moveEvent = new Event("combobox-item-move");
10142 const baseElement = store == null ? void 0 : store.getState().baseElement;
10143 baseElement == null ? void 0 : baseElement.dispatchEvent(moveEvent);
10144 return true;
10145 }
10146 });
10147 props = useCompositeHover({ store, focusOnHover, ...props });
10148 return props;
10149 }
10150 );
10151 var ComboboxItem = memo22(
10152 forwardRef22(function ComboboxItem2(props) {
10153 const htmlProps = useComboboxItem(props);
10154 return createElement3(TagName10, htmlProps);
10155 })
10156 );
10157
10158 // node_modules/@ariakit/react-core/esm/combobox/combobox-item-value.js
10159 var import_react20 = __toESM(require_react(), 1);
10160 var import_jsx_runtime59 = __toESM(require_jsx_runtime(), 1);
10161 var TagName11 = "span";
10162 function normalizeValue(value) {
10163 return normalizeString(value).toLowerCase();
10164 }
10165 function getOffsets(string, values) {
10166 const offsets = [];
10167 for (const value of values) {
10168 let pos = 0;
10169 const length = value.length;
10170 while (string.indexOf(value, pos) !== -1) {
10171 const index = string.indexOf(value, pos);
10172 if (index !== -1) {
10173 offsets.push([index, length]);
10174 }
10175 pos = index + 1;
10176 }
10177 }
10178 return offsets;
10179 }
10180 function filterOverlappingOffsets(offsets) {
10181 return offsets.filter(([offset, length], i2, arr) => {
10182 return !arr.some(
10183 ([o2, l2], j2) => j2 !== i2 && o2 <= offset && o2 + l2 >= offset + length
10184 );
10185 });
10186 }
10187 function sortOffsets(offsets) {
10188 return offsets.sort(([a2], [b2]) => a2 - b2);
10189 }
10190 function splitValue(itemValue, userValue) {
10191 if (!itemValue) return itemValue;
10192 if (!userValue) return itemValue;
10193 const userValues = toArray(userValue).filter(Boolean).map(normalizeValue);
10194 const parts = [];
10195 const span = (value, autocomplete = false) => /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(
10196 "span",
10197 {
10198 "data-autocomplete-value": autocomplete ? "" : void 0,
10199 "data-user-value": autocomplete ? void 0 : "",
10200 children: value
10201 },
10202 parts.length
10203 );
10204 const offsets = sortOffsets(
10205 filterOverlappingOffsets(
10206 // Convert userValues into a set to avoid duplicates
10207 getOffsets(normalizeValue(itemValue), new Set(userValues))
10208 )
10209 );
10210 if (!offsets.length) {
10211 parts.push(span(itemValue, true));
10212 return parts;
10213 }
10214 const [firstOffset] = offsets[0];
10215 const values = [
10216 itemValue.slice(0, firstOffset),
10217 ...offsets.flatMap(([offset, length], i2) => {
10218 var _a;
10219 const value = itemValue.slice(offset, offset + length);
10220 const nextOffset = (_a = offsets[i2 + 1]) == null ? void 0 : _a[0];
10221 const nextValue = itemValue.slice(offset + length, nextOffset);
10222 return [value, nextValue];
10223 })
10224 ];
10225 values.forEach((value, i2) => {
10226 if (!value) return;
10227 parts.push(span(value, i2 % 2 === 0));
10228 });
10229 return parts;
10230 }
10231 var useComboboxItemValue = createHook(function useComboboxItemValue2({ store, value, userValue, ...props }) {
10232 const context = useComboboxScopedContext();
10233 store = store || context;
10234 const itemContext = (0, import_react20.useContext)(ComboboxItemValueContext);
10235 const itemValue = value != null ? value : itemContext;
10236 const inputValue = useStoreState(store, (state) => userValue != null ? userValue : state == null ? void 0 : state.value);
10237 const children = (0, import_react20.useMemo)(() => {
10238 if (!itemValue) return;
10239 if (!inputValue) return itemValue;
10240 return splitValue(itemValue, inputValue);
10241 }, [itemValue, inputValue]);
10242 props = {
10243 children,
10244 ...props
10245 };
10246 return removeUndefinedValues(props);
10247 });
10248 var ComboboxItemValue = forwardRef22(function ComboboxItemValue2(props) {
10249 const htmlProps = useComboboxItemValue(props);
10250 return createElement3(TagName11, htmlProps);
10251 });
10252
10253 // node_modules/@ariakit/react-core/esm/combobox/combobox-label.js
10254 var TagName12 = "label";
10255 var useComboboxLabel = createHook(
10256 function useComboboxLabel2({ store, ...props }) {
10257 const context = useComboboxProviderContext();
10258 store = store || context;
10259 invariant(
10260 store,
10261 "ComboboxLabel must receive a `store` prop or be wrapped in a ComboboxProvider component."
10262 );
10263 const comboboxId = store.useState((state) => {
10264 var _a;
10265 return (_a = state.baseElement) == null ? void 0 : _a.id;
10266 });
10267 props = {
10268 htmlFor: comboboxId,
10269 ...props
10270 };
10271 return removeUndefinedValues(props);
10272 }
10273 );
10274 var ComboboxLabel = memo22(
10275 forwardRef22(function ComboboxLabel2(props) {
10276 const htmlProps = useComboboxLabel(props);
10277 return createElement3(TagName12, htmlProps);
10278 })
10279 );
10280
10281 // node_modules/@ariakit/react-core/esm/__chunks/2G6YEJT4.js
10282 var import_react21 = __toESM(require_react(), 1);
10283 var import_jsx_runtime60 = __toESM(require_jsx_runtime(), 1);
10284 var TagName13 = "div";
10285 var useComboboxList = createHook(
10286 function useComboboxList2({ store, alwaysVisible, ...props }) {
10287 const scopedContext = useComboboxScopedContext(true);
10288 const context = useComboboxContext();
10289 store = store || context;
10290 const scopedContextSameStore = !!store && store === scopedContext;
10291 invariant(
10292 store,
10293 "ComboboxList must receive a `store` prop or be wrapped in a ComboboxProvider component."
10294 );
10295 const ref = (0, import_react21.useRef)(null);
10296 const id = useId3(props.id);
10297 const mounted = store.useState("mounted");
10298 const hidden = isHidden(mounted, props.hidden, alwaysVisible);
10299 const style = hidden ? { ...props.style, display: "none" } : props.style;
10300 const multiSelectable = store.useState(
10301 (state) => Array.isArray(state.selectedValue)
10302 );
10303 const role = useAttribute(ref, "role", props.role);
10304 const isCompositeRole = role === "listbox" || role === "tree" || role === "grid";
10305 const ariaMultiSelectable = isCompositeRole ? multiSelectable || void 0 : void 0;
10306 const [hasListboxInside, setHasListboxInside] = (0, import_react21.useState)(false);
10307 const contentElement = store.useState("contentElement");
10308 useSafeLayoutEffect(() => {
10309 if (!mounted) return;
10310 const element = ref.current;
10311 if (!element) return;
10312 if (contentElement !== element) return;
10313 const callback = () => {
10314 setHasListboxInside(!!element.querySelector("[role='listbox']"));
10315 };
10316 const observer = new MutationObserver(callback);
10317 observer.observe(element, {
10318 subtree: true,
10319 childList: true,
10320 attributeFilter: ["role"]
10321 });
10322 callback();
10323 return () => observer.disconnect();
10324 }, [mounted, contentElement]);
10325 if (!hasListboxInside) {
10326 props = {
10327 role: "listbox",
10328 "aria-multiselectable": ariaMultiSelectable,
10329 ...props
10330 };
10331 }
10332 props = useWrapElement(
10333 props,
10334 (element) => /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(ComboboxScopedContextProvider, { value: store, children: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(ComboboxListRoleContext.Provider, { value: role, children: element }) }),
10335 [store, role]
10336 );
10337 const setContentElement = id && (!scopedContext || !scopedContextSameStore) ? store.setContentElement : null;
10338 props = {
10339 id,
10340 hidden,
10341 ...props,
10342 ref: useMergeRefs(setContentElement, ref, props.ref),
10343 style
10344 };
10345 return removeUndefinedValues(props);
10346 }
10347 );
10348 var ComboboxList = forwardRef22(function ComboboxList2(props) {
10349 const htmlProps = useComboboxList(props);
10350 return createElement3(TagName13, htmlProps);
10351 });
10352
10353 // node_modules/@ariakit/react-core/esm/__chunks/XSIEPKGA.js
10354 var import_react22 = __toESM(require_react(), 1);
10355 var TagValueContext = (0, import_react22.createContext)(null);
10356 var TagRemoveIdContext = (0, import_react22.createContext)(
10357 null
10358 );
10359 var ctx7 = createStoreContext(
10360 [CompositeContextProvider],
10361 [CompositeScopedContextProvider]
10362 );
10363 var useTagContext = ctx7.useContext;
10364 var useTagScopedContext = ctx7.useScopedContext;
10365 var useTagProviderContext = ctx7.useProviderContext;
10366 var TagContextProvider = ctx7.ContextProvider;
10367 var TagScopedContextProvider = ctx7.ScopedContextProvider;
10368
10369 // node_modules/@ariakit/core/esm/combobox/combobox-store.js
10370 var isTouchSafari = isSafari() && isTouchDevice();
10371 function createComboboxStore({
10372 tag,
10373 ...props
10374 } = {}) {
10375 const store = mergeStore(props.store, pick2(tag, ["value", "rtl"]));
10376 throwOnConflictingProps(props, store);
10377 const tagState = tag == null ? void 0 : tag.getState();
10378 const syncState = store == null ? void 0 : store.getState();
10379 const activeId = defaultValue(
10380 props.activeId,
10381 syncState == null ? void 0 : syncState.activeId,
10382 props.defaultActiveId,
10383 null
10384 );
10385 const composite = createCompositeStore({
10386 ...props,
10387 activeId,
10388 includesBaseElement: defaultValue(
10389 props.includesBaseElement,
10390 syncState == null ? void 0 : syncState.includesBaseElement,
10391 true
10392 ),
10393 orientation: defaultValue(
10394 props.orientation,
10395 syncState == null ? void 0 : syncState.orientation,
10396 "vertical"
10397 ),
10398 focusLoop: defaultValue(props.focusLoop, syncState == null ? void 0 : syncState.focusLoop, true),
10399 focusWrap: defaultValue(props.focusWrap, syncState == null ? void 0 : syncState.focusWrap, true),
10400 virtualFocus: defaultValue(
10401 props.virtualFocus,
10402 syncState == null ? void 0 : syncState.virtualFocus,
10403 true
10404 )
10405 });
10406 const popover = createPopoverStore({
10407 ...props,
10408 placement: defaultValue(
10409 props.placement,
10410 syncState == null ? void 0 : syncState.placement,
10411 "bottom-start"
10412 )
10413 });
10414 const value = defaultValue(
10415 props.value,
10416 syncState == null ? void 0 : syncState.value,
10417 props.defaultValue,
10418 ""
10419 );
10420 const selectedValue = defaultValue(
10421 props.selectedValue,
10422 syncState == null ? void 0 : syncState.selectedValue,
10423 tagState == null ? void 0 : tagState.values,
10424 props.defaultSelectedValue,
10425 ""
10426 );
10427 const multiSelectable = Array.isArray(selectedValue);
10428 const initialState = {
10429 ...composite.getState(),
10430 ...popover.getState(),
10431 value,
10432 selectedValue,
10433 resetValueOnSelect: defaultValue(
10434 props.resetValueOnSelect,
10435 syncState == null ? void 0 : syncState.resetValueOnSelect,
10436 multiSelectable
10437 ),
10438 resetValueOnHide: defaultValue(
10439 props.resetValueOnHide,
10440 syncState == null ? void 0 : syncState.resetValueOnHide,
10441 multiSelectable && !tag
10442 ),
10443 activeValue: syncState == null ? void 0 : syncState.activeValue
10444 };
10445 const combobox = createStore(initialState, composite, popover, store);
10446 if (isTouchSafari) {
10447 setup(
10448 combobox,
10449 () => sync(combobox, ["virtualFocus"], () => {
10450 combobox.setState("virtualFocus", false);
10451 })
10452 );
10453 }
10454 setup(combobox, () => {
10455 if (!tag) return;
10456 return chain(
10457 sync(combobox, ["selectedValue"], (state) => {
10458 if (!Array.isArray(state.selectedValue)) return;
10459 tag.setValues(state.selectedValue);
10460 }),
10461 sync(tag, ["values"], (state) => {
10462 combobox.setState("selectedValue", state.values);
10463 })
10464 );
10465 });
10466 setup(
10467 combobox,
10468 () => sync(combobox, ["resetValueOnHide", "mounted"], (state) => {
10469 if (!state.resetValueOnHide) return;
10470 if (state.mounted) return;
10471 combobox.setState("value", value);
10472 })
10473 );
10474 setup(
10475 combobox,
10476 () => sync(combobox, ["open"], (state) => {
10477 if (state.open) return;
10478 combobox.setState("activeId", activeId);
10479 combobox.setState("moves", 0);
10480 })
10481 );
10482 setup(
10483 combobox,
10484 () => sync(combobox, ["moves", "activeId"], (state, prevState) => {
10485 if (state.moves === prevState.moves) {
10486 combobox.setState("activeValue", void 0);
10487 }
10488 })
10489 );
10490 setup(
10491 combobox,
10492 () => batch(combobox, ["moves", "renderedItems"], (state, prev) => {
10493 if (state.moves === prev.moves) return;
10494 const { activeId: activeId2 } = combobox.getState();
10495 const activeItem = composite.item(activeId2);
10496 combobox.setState("activeValue", activeItem == null ? void 0 : activeItem.value);
10497 })
10498 );
10499 return {
10500 ...popover,
10501 ...composite,
10502 ...combobox,
10503 tag,
10504 setValue: (value2) => combobox.setState("value", value2),
10505 resetValue: () => combobox.setState("value", initialState.value),
10506 setSelectedValue: (selectedValue2) => combobox.setState("selectedValue", selectedValue2)
10507 };
10508 }
10509
10510 // node_modules/@ariakit/react-core/esm/__chunks/SVN33SY6.js
10511 function useComboboxStoreOptions(props) {
10512 const tag = useTagContext();
10513 props = {
10514 ...props,
10515 tag: props.tag !== void 0 ? props.tag : tag
10516 };
10517 return useCompositeStoreOptions(props);
10518 }
10519 function useComboboxStoreProps(store, update2, props) {
10520 useUpdateEffect(update2, [props.tag]);
10521 useStoreProps(store, props, "value", "setValue");
10522 useStoreProps(store, props, "selectedValue", "setSelectedValue");
10523 useStoreProps(store, props, "resetValueOnHide");
10524 useStoreProps(store, props, "resetValueOnSelect");
10525 return Object.assign(
10526 useCompositeStoreProps(
10527 usePopoverStoreProps(store, update2, props),
10528 update2,
10529 props
10530 ),
10531 { tag: props.tag }
10532 );
10533 }
10534 function useComboboxStore(props = {}) {
10535 props = useComboboxStoreOptions(props);
10536 const [store, update2] = useStore(createComboboxStore, props);
10537 return useComboboxStoreProps(store, update2, props);
10538 }
10539
10540 // node_modules/@ariakit/react-core/esm/combobox/combobox-provider.js
10541 var import_jsx_runtime61 = __toESM(require_jsx_runtime(), 1);
10542 function ComboboxProvider(props = {}) {
10543 const store = useComboboxStore(props);
10544 return /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(ComboboxContextProvider, { value: store, children: props.children });
10545 }
10546
10547 // packages/dataviews/build-module/components/dataviews-filters/search-widget.mjs
10548 var import_remove_accents = __toESM(require_remove_accents(), 1);
10549 var import_compose7 = __toESM(require_compose(), 1);
10550 var import_i18n28 = __toESM(require_i18n(), 1);
10551 var import_element27 = __toESM(require_element(), 1);
10552 var import_components18 = __toESM(require_components(), 1);
10553
10554 // packages/dataviews/build-module/components/dataviews-filters/utils.mjs
10555 var EMPTY_ARRAY3 = [];
10556 var getCurrentValue = (filterDefinition, currentFilter) => {
10557 if (filterDefinition.singleSelection) {
10558 return currentFilter?.value;
10559 }
10560 if (Array.isArray(currentFilter?.value)) {
10561 return currentFilter.value;
10562 }
10563 if (!Array.isArray(currentFilter?.value) && !!currentFilter?.value) {
10564 return [currentFilter.value];
10565 }
10566 return EMPTY_ARRAY3;
10567 };
10568
10569 // packages/dataviews/build-module/hooks/use-elements.mjs
10570 var import_element26 = __toESM(require_element(), 1);
10571 var EMPTY_ARRAY4 = [];
10572 function useElements({
10573 elements,
10574 getElements
10575 }) {
10576 const staticElements = Array.isArray(elements) && elements.length > 0 ? elements : EMPTY_ARRAY4;
10577 const [records, setRecords] = (0, import_element26.useState)(staticElements);
10578 const [isLoading, setIsLoading] = (0, import_element26.useState)(false);
10579 (0, import_element26.useEffect)(() => {
10580 if (!getElements) {
10581 setRecords(staticElements);
10582 return;
10583 }
10584 let cancelled = false;
10585 setIsLoading(true);
10586 getElements().then((fetchedElements) => {
10587 if (!cancelled) {
10588 const dynamicElements = Array.isArray(fetchedElements) && fetchedElements.length > 0 ? fetchedElements : staticElements;
10589 setRecords(dynamicElements);
10590 }
10591 }).catch(() => {
10592 if (!cancelled) {
10593 setRecords(staticElements);
10594 }
10595 }).finally(() => {
10596 if (!cancelled) {
10597 setIsLoading(false);
10598 }
10599 });
10600 return () => {
10601 cancelled = true;
10602 };
10603 }, [getElements, staticElements]);
10604 return {
10605 elements: records,
10606 isLoading
10607 };
10608 }
10609
10610 // packages/dataviews/build-module/components/dataviews-filters/search-widget.mjs
10611 var import_jsx_runtime62 = __toESM(require_jsx_runtime(), 1);
10612 function normalizeSearchInput(input = "") {
10613 return (0, import_remove_accents.default)(input.trim().toLowerCase());
10614 }
10615 var getNewValue = (filterDefinition, currentFilter, value) => {
10616 if (filterDefinition.singleSelection) {
10617 return value;
10618 }
10619 if (Array.isArray(currentFilter?.value)) {
10620 return currentFilter.value.includes(value) ? currentFilter.value.filter((v2) => v2 !== value) : [...currentFilter.value, value];
10621 }
10622 return [value];
10623 };
10624 function generateFilterElementCompositeItemId(prefix, filterElementValue) {
10625 return `${prefix}-${filterElementValue}`;
10626 }
10627 var MultiSelectionOption = ({ selected }) => {
10628 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10629 "span",
10630 {
10631 className: clsx_default(
10632 "dataviews-filters__search-widget-listitem-multi-selection",
10633 { "is-selected": selected }
10634 ),
10635 children: selected && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components18.Icon, { icon: check_default })
10636 }
10637 );
10638 };
10639 var SingleSelectionOption = ({ selected }) => {
10640 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10641 "span",
10642 {
10643 className: clsx_default(
10644 "dataviews-filters__search-widget-listitem-single-selection",
10645 { "is-selected": selected }
10646 )
10647 }
10648 );
10649 };
10650 function ListBox({ view, filter, onChangeView }) {
10651 const baseId = (0, import_compose7.useInstanceId)(ListBox, "dataviews-filter-list-box");
10652 const [activeCompositeId, setActiveCompositeId] = (0, import_element27.useState)(
10653 // When there are one or less operators, the first item is set as active
10654 // (by setting the initial `activeId` to `undefined`).
10655 // With 2 or more operators, the focus is moved on the operators control
10656 // (by setting the initial `activeId` to `null`), meaning that there won't
10657 // be an active item initially. Focus is then managed via the
10658 // `onFocusVisible` callback.
10659 filter.operators?.length === 1 ? void 0 : null
10660 );
10661 const currentFilter = view.filters?.find(
10662 (f2) => f2.field === filter.field
10663 );
10664 const currentValue = getCurrentValue(filter, currentFilter);
10665 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10666 import_components18.Composite,
10667 {
10668 virtualFocus: true,
10669 focusLoop: true,
10670 activeId: activeCompositeId,
10671 setActiveId: setActiveCompositeId,
10672 role: "listbox",
10673 className: "dataviews-filters__search-widget-listbox",
10674 "aria-label": (0, import_i18n28.sprintf)(
10675 /* translators: List of items for a filter. 1: Filter name. e.g.: "List of: Author". */
10676 (0, import_i18n28.__)("List of: %1$s"),
10677 filter.name
10678 ),
10679 onFocusVisible: () => {
10680 if (!activeCompositeId && filter.elements.length) {
10681 setActiveCompositeId(
10682 generateFilterElementCompositeItemId(
10683 baseId,
10684 filter.elements[0].value
10685 )
10686 );
10687 }
10688 },
10689 render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components18.Composite.Typeahead, {}),
10690 children: filter.elements.map((element) => /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10691 import_components18.Composite.Hover,
10692 {
10693 render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10694 import_components18.Composite.Item,
10695 {
10696 id: generateFilterElementCompositeItemId(
10697 baseId,
10698 element.value
10699 ),
10700 render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10701 "div",
10702 {
10703 "aria-label": element.label,
10704 role: "option",
10705 className: "dataviews-filters__search-widget-listitem"
10706 }
10707 ),
10708 onClick: () => {
10709 const newFilters = currentFilter ? [
10710 ...(view.filters ?? []).map(
10711 (_filter) => {
10712 if (_filter.field === filter.field) {
10713 return {
10714 ..._filter,
10715 operator: currentFilter.operator || filter.operators[0],
10716 value: getNewValue(
10717 filter,
10718 currentFilter,
10719 element.value
10720 )
10721 };
10722 }
10723 return _filter;
10724 }
10725 )
10726 ] : [
10727 ...view.filters ?? [],
10728 {
10729 field: filter.field,
10730 operator: filter.operators[0],
10731 value: getNewValue(
10732 filter,
10733 currentFilter,
10734 element.value
10735 )
10736 }
10737 ];
10738 onChangeView({
10739 ...view,
10740 page: 1,
10741 filters: newFilters
10742 });
10743 }
10744 }
10745 ),
10746 children: [
10747 filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10748 SingleSelectionOption,
10749 {
10750 selected: currentValue === element.value
10751 }
10752 ),
10753 !filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10754 MultiSelectionOption,
10755 {
10756 selected: currentValue.includes(element.value)
10757 }
10758 ),
10759 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10760 "span",
10761 {
10762 className: "dataviews-filters__search-widget-listitem-value",
10763 title: element.label,
10764 children: element.label
10765 }
10766 )
10767 ]
10768 },
10769 element.value
10770 ))
10771 }
10772 );
10773 }
10774 function ComboboxList22({ view, filter, onChangeView }) {
10775 const [searchValue, setSearchValue] = (0, import_element27.useState)("");
10776 const deferredSearchValue = (0, import_element27.useDeferredValue)(searchValue);
10777 const currentFilter = view.filters?.find(
10778 (_filter) => _filter.field === filter.field
10779 );
10780 const currentValue = getCurrentValue(filter, currentFilter);
10781 const matches = (0, import_element27.useMemo)(() => {
10782 const normalizedSearch = normalizeSearchInput(deferredSearchValue);
10783 return filter.elements.filter(
10784 (item) => normalizeSearchInput(item.label).includes(normalizedSearch)
10785 );
10786 }, [filter.elements, deferredSearchValue]);
10787 return /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10788 ComboboxProvider,
10789 {
10790 selectedValue: currentValue,
10791 setSelectedValue: (value) => {
10792 const newFilters = currentFilter ? [
10793 ...(view.filters ?? []).map((_filter) => {
10794 if (_filter.field === filter.field) {
10795 return {
10796 ..._filter,
10797 operator: currentFilter.operator || filter.operators[0],
10798 value
10799 };
10800 }
10801 return _filter;
10802 })
10803 ] : [
10804 ...view.filters ?? [],
10805 {
10806 field: filter.field,
10807 operator: filter.operators[0],
10808 value
10809 }
10810 ];
10811 onChangeView({
10812 ...view,
10813 page: 1,
10814 filters: newFilters
10815 });
10816 },
10817 setValue: setSearchValue,
10818 children: [
10819 /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)("div", { className: "dataviews-filters__search-widget-filter-combobox__wrapper", children: [
10820 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(VisuallyHidden, { render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(ComboboxLabel, {}), children: (0, import_i18n28.__)("Search items") }),
10821 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10822 Combobox,
10823 {
10824 autoSelect: "always",
10825 placeholder: (0, import_i18n28.__)("Search"),
10826 className: "dataviews-filters__search-widget-filter-combobox__input"
10827 }
10828 ),
10829 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("div", { className: "dataviews-filters__search-widget-filter-combobox__icon", children: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components18.Icon, { icon: search_default }) })
10830 ] }),
10831 /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10832 ComboboxList,
10833 {
10834 className: "dataviews-filters__search-widget-filter-combobox-list",
10835 alwaysVisible: true,
10836 children: [
10837 matches.map((element) => {
10838 return /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10839 ComboboxItem,
10840 {
10841 resetValueOnSelect: false,
10842 value: element.value,
10843 className: "dataviews-filters__search-widget-listitem",
10844 hideOnClick: false,
10845 setValueOnClick: false,
10846 focusOnHover: true,
10847 children: [
10848 filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10849 SingleSelectionOption,
10850 {
10851 selected: currentValue === element.value
10852 }
10853 ),
10854 !filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10855 MultiSelectionOption,
10856 {
10857 selected: currentValue.includes(
10858 element.value
10859 )
10860 }
10861 ),
10862 /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10863 "span",
10864 {
10865 className: "dataviews-filters__search-widget-listitem-value",
10866 title: element.label,
10867 children: [
10868 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10869 ComboboxItemValue,
10870 {
10871 className: "dataviews-filters__search-widget-filter-combobox-item-value",
10872 value: element.label
10873 }
10874 ),
10875 !!element.description && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("span", { className: "dataviews-filters__search-widget-listitem-description", children: element.description })
10876 ]
10877 }
10878 )
10879 ]
10880 },
10881 element.value
10882 );
10883 }),
10884 !matches.length && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("p", { children: (0, import_i18n28.__)("No results found") })
10885 ]
10886 }
10887 )
10888 ]
10889 }
10890 );
10891 }
10892 function SearchWidget(props) {
10893 const { elements, isLoading } = useElements({
10894 elements: props.filter.elements,
10895 getElements: props.filter.getElements
10896 });
10897 if (isLoading) {
10898 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("div", { className: "dataviews-filters__search-widget-no-elements", children: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components18.Spinner, {}) });
10899 }
10900 if (elements.length === 0) {
10901 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("div", { className: "dataviews-filters__search-widget-no-elements", children: (0, import_i18n28.__)("No elements found") });
10902 }
10903 const Widget = elements.length > 10 ? ComboboxList22 : ListBox;
10904 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(Widget, { ...props, filter: { ...props.filter, elements } });
10905 }
10906
10907 // packages/dataviews/build-module/components/dataviews-filters/input-widget.mjs
10908 var import_es6 = __toESM(require_es6(), 1);
10909 var import_compose8 = __toESM(require_compose(), 1);
10910 var import_element28 = __toESM(require_element(), 1);
10911 var import_components19 = __toESM(require_components(), 1);
10912 var import_jsx_runtime63 = __toESM(require_jsx_runtime(), 1);
10913 function InputWidget({
10914 filter,
10915 view,
10916 onChangeView,
10917 fields
10918 }) {
10919 const currentFilter = view.filters?.find(
10920 (f2) => f2.field === filter.field
10921 );
10922 const currentValue = getCurrentValue(filter, currentFilter);
10923 const field = (0, import_element28.useMemo)(() => {
10924 const currentField = fields.find((f2) => f2.id === filter.field);
10925 if (currentField) {
10926 return {
10927 ...currentField,
10928 // Deactivate validation for filters.
10929 isValid: {},
10930 // Filter controls are always enabled.
10931 isDisabled: () => false,
10932 // Filter controls are always visible.
10933 isVisible: () => true,
10934 // Configure getValue/setValue as if Item was a plain object.
10935 getValue: ({ item }) => item[currentField.id],
10936 setValue: ({ value }) => ({
10937 [currentField.id]: value
10938 })
10939 };
10940 }
10941 return currentField;
10942 }, [fields, filter.field]);
10943 const data = (0, import_element28.useMemo)(() => {
10944 return (view.filters ?? []).reduce(
10945 (acc, activeFilter) => {
10946 acc[activeFilter.field] = activeFilter.value;
10947 return acc;
10948 },
10949 {}
10950 );
10951 }, [view.filters]);
10952 const handleChange = (0, import_compose8.useEvent)((updatedData) => {
10953 if (!field || !currentFilter) {
10954 return;
10955 }
10956 const nextValue = field.getValue({ item: updatedData });
10957 if ((0, import_es6.default)(nextValue, currentValue)) {
10958 return;
10959 }
10960 onChangeView({
10961 ...view,
10962 filters: (view.filters ?? []).map(
10963 (_filter) => _filter.field === filter.field ? {
10964 ..._filter,
10965 operator: currentFilter.operator || filter.operators[0],
10966 // Consider empty strings as undefined:
10967 //
10968 // - undefined as value means the filter is unset: the filter widget displays no value and the search returns all records
10969 // - empty string as value means "search empty string": returns only the records that have an empty string as value
10970 //
10971 // In practice, this means the filter will not be able to find an empty string as the value.
10972 value: nextValue === "" ? void 0 : nextValue
10973 } : _filter
10974 )
10975 });
10976 });
10977 if (!field || !field.Edit || !currentFilter) {
10978 return null;
10979 }
10980 return /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
10981 import_components19.Flex,
10982 {
10983 className: "dataviews-filters__user-input-widget",
10984 gap: 2.5,
10985 direction: "column",
10986 children: /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
10987 field.Edit,
10988 {
10989 hideLabelFromVision: true,
10990 data,
10991 field,
10992 operator: currentFilter.operator,
10993 onChange: handleChange
10994 }
10995 )
10996 }
10997 );
10998 }
10999
11000 // packages/dataviews/node_modules/date-fns/constants.js
11001 var daysInYear = 365.2425;
11002 var maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1e3;
11003 var minTime = -maxTime;
11004 var millisecondsInWeek = 6048e5;
11005 var millisecondsInDay = 864e5;
11006 var secondsInHour = 3600;
11007 var secondsInDay = secondsInHour * 24;
11008 var secondsInWeek = secondsInDay * 7;
11009 var secondsInYear = secondsInDay * daysInYear;
11010 var secondsInMonth = secondsInYear / 12;
11011 var secondsInQuarter = secondsInMonth * 3;
11012 var constructFromSymbol = /* @__PURE__ */ Symbol.for("constructDateFrom");
11013
11014 // packages/dataviews/node_modules/date-fns/constructFrom.js
11015 function constructFrom(date, value) {
11016 if (typeof date === "function") return date(value);
11017 if (date && typeof date === "object" && constructFromSymbol in date)
11018 return date[constructFromSymbol](value);
11019 if (date instanceof Date) return new date.constructor(value);
11020 return new Date(value);
11021 }
11022
11023 // packages/dataviews/node_modules/date-fns/toDate.js
11024 function toDate(argument, context) {
11025 return constructFrom(context || argument, argument);
11026 }
11027
11028 // packages/dataviews/node_modules/date-fns/addDays.js
11029 function addDays(date, amount, options) {
11030 const _date = toDate(date, options?.in);
11031 if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
11032 if (!amount) return _date;
11033 _date.setDate(_date.getDate() + amount);
11034 return _date;
11035 }
11036
11037 // packages/dataviews/node_modules/date-fns/addMonths.js
11038 function addMonths(date, amount, options) {
11039 const _date = toDate(date, options?.in);
11040 if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
11041 if (!amount) {
11042 return _date;
11043 }
11044 const dayOfMonth = _date.getDate();
11045 const endOfDesiredMonth = constructFrom(options?.in || date, _date.getTime());
11046 endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0);
11047 const daysInMonth = endOfDesiredMonth.getDate();
11048 if (dayOfMonth >= daysInMonth) {
11049 return endOfDesiredMonth;
11050 } else {
11051 _date.setFullYear(
11052 endOfDesiredMonth.getFullYear(),
11053 endOfDesiredMonth.getMonth(),
11054 dayOfMonth
11055 );
11056 return _date;
11057 }
11058 }
11059
11060 // packages/dataviews/node_modules/date-fns/_lib/defaultOptions.js
11061 var defaultOptions = {};
11062 function getDefaultOptions() {
11063 return defaultOptions;
11064 }
11065
11066 // packages/dataviews/node_modules/date-fns/startOfWeek.js
11067 function startOfWeek(date, options) {
11068 const defaultOptions2 = getDefaultOptions();
11069 const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
11070 const _date = toDate(date, options?.in);
11071 const day = _date.getDay();
11072 const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
11073 _date.setDate(_date.getDate() - diff);
11074 _date.setHours(0, 0, 0, 0);
11075 return _date;
11076 }
11077
11078 // packages/dataviews/node_modules/date-fns/startOfISOWeek.js
11079 function startOfISOWeek(date, options) {
11080 return startOfWeek(date, { ...options, weekStartsOn: 1 });
11081 }
11082
11083 // packages/dataviews/node_modules/date-fns/getISOWeekYear.js
11084 function getISOWeekYear(date, options) {
11085 const _date = toDate(date, options?.in);
11086 const year = _date.getFullYear();
11087 const fourthOfJanuaryOfNextYear = constructFrom(_date, 0);
11088 fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
11089 fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
11090 const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
11091 const fourthOfJanuaryOfThisYear = constructFrom(_date, 0);
11092 fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
11093 fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
11094 const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
11095 if (_date.getTime() >= startOfNextYear.getTime()) {
11096 return year + 1;
11097 } else if (_date.getTime() >= startOfThisYear.getTime()) {
11098 return year;
11099 } else {
11100 return year - 1;
11101 }
11102 }
11103
11104 // packages/dataviews/node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.js
11105 function getTimezoneOffsetInMilliseconds(date) {
11106 const _date = toDate(date);
11107 const utcDate = new Date(
11108 Date.UTC(
11109 _date.getFullYear(),
11110 _date.getMonth(),
11111 _date.getDate(),
11112 _date.getHours(),
11113 _date.getMinutes(),
11114 _date.getSeconds(),
11115 _date.getMilliseconds()
11116 )
11117 );
11118 utcDate.setUTCFullYear(_date.getFullYear());
11119 return +date - +utcDate;
11120 }
11121
11122 // packages/dataviews/node_modules/date-fns/_lib/normalizeDates.js
11123 function normalizeDates(context, ...dates) {
11124 const normalize = constructFrom.bind(
11125 null,
11126 context || dates.find((date) => typeof date === "object")
11127 );
11128 return dates.map(normalize);
11129 }
11130
11131 // packages/dataviews/node_modules/date-fns/startOfDay.js
11132 function startOfDay(date, options) {
11133 const _date = toDate(date, options?.in);
11134 _date.setHours(0, 0, 0, 0);
11135 return _date;
11136 }
11137
11138 // packages/dataviews/node_modules/date-fns/differenceInCalendarDays.js
11139 function differenceInCalendarDays(laterDate, earlierDate, options) {
11140 const [laterDate_, earlierDate_] = normalizeDates(
11141 options?.in,
11142 laterDate,
11143 earlierDate
11144 );
11145 const laterStartOfDay = startOfDay(laterDate_);
11146 const earlierStartOfDay = startOfDay(earlierDate_);
11147 const laterTimestamp = +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
11148 const earlierTimestamp = +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
11149 return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
11150 }
11151
11152 // packages/dataviews/node_modules/date-fns/startOfISOWeekYear.js
11153 function startOfISOWeekYear(date, options) {
11154 const year = getISOWeekYear(date, options);
11155 const fourthOfJanuary = constructFrom(options?.in || date, 0);
11156 fourthOfJanuary.setFullYear(year, 0, 4);
11157 fourthOfJanuary.setHours(0, 0, 0, 0);
11158 return startOfISOWeek(fourthOfJanuary);
11159 }
11160
11161 // packages/dataviews/node_modules/date-fns/addWeeks.js
11162 function addWeeks(date, amount, options) {
11163 return addDays(date, amount * 7, options);
11164 }
11165
11166 // packages/dataviews/node_modules/date-fns/addYears.js
11167 function addYears(date, amount, options) {
11168 return addMonths(date, amount * 12, options);
11169 }
11170
11171 // packages/dataviews/node_modules/date-fns/isDate.js
11172 function isDate(value) {
11173 return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
11174 }
11175
11176 // packages/dataviews/node_modules/date-fns/isValid.js
11177 function isValid(date) {
11178 return !(!isDate(date) && typeof date !== "number" || isNaN(+toDate(date)));
11179 }
11180
11181 // packages/dataviews/node_modules/date-fns/startOfMonth.js
11182 function startOfMonth(date, options) {
11183 const _date = toDate(date, options?.in);
11184 _date.setDate(1);
11185 _date.setHours(0, 0, 0, 0);
11186 return _date;
11187 }
11188
11189 // packages/dataviews/node_modules/date-fns/startOfYear.js
11190 function startOfYear(date, options) {
11191 const date_ = toDate(date, options?.in);
11192 date_.setFullYear(date_.getFullYear(), 0, 1);
11193 date_.setHours(0, 0, 0, 0);
11194 return date_;
11195 }
11196
11197 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/formatDistance.js
11198 var formatDistanceLocale = {
11199 lessThanXSeconds: {
11200 one: "less than a second",
11201 other: "less than {{count}} seconds"
11202 },
11203 xSeconds: {
11204 one: "1 second",
11205 other: "{{count}} seconds"
11206 },
11207 halfAMinute: "half a minute",
11208 lessThanXMinutes: {
11209 one: "less than a minute",
11210 other: "less than {{count}} minutes"
11211 },
11212 xMinutes: {
11213 one: "1 minute",
11214 other: "{{count}} minutes"
11215 },
11216 aboutXHours: {
11217 one: "about 1 hour",
11218 other: "about {{count}} hours"
11219 },
11220 xHours: {
11221 one: "1 hour",
11222 other: "{{count}} hours"
11223 },
11224 xDays: {
11225 one: "1 day",
11226 other: "{{count}} days"
11227 },
11228 aboutXWeeks: {
11229 one: "about 1 week",
11230 other: "about {{count}} weeks"
11231 },
11232 xWeeks: {
11233 one: "1 week",
11234 other: "{{count}} weeks"
11235 },
11236 aboutXMonths: {
11237 one: "about 1 month",
11238 other: "about {{count}} months"
11239 },
11240 xMonths: {
11241 one: "1 month",
11242 other: "{{count}} months"
11243 },
11244 aboutXYears: {
11245 one: "about 1 year",
11246 other: "about {{count}} years"
11247 },
11248 xYears: {
11249 one: "1 year",
11250 other: "{{count}} years"
11251 },
11252 overXYears: {
11253 one: "over 1 year",
11254 other: "over {{count}} years"
11255 },
11256 almostXYears: {
11257 one: "almost 1 year",
11258 other: "almost {{count}} years"
11259 }
11260 };
11261 var formatDistance = (token, count, options) => {
11262 let result;
11263 const tokenValue = formatDistanceLocale[token];
11264 if (typeof tokenValue === "string") {
11265 result = tokenValue;
11266 } else if (count === 1) {
11267 result = tokenValue.one;
11268 } else {
11269 result = tokenValue.other.replace("{{count}}", count.toString());
11270 }
11271 if (options?.addSuffix) {
11272 if (options.comparison && options.comparison > 0) {
11273 return "in " + result;
11274 } else {
11275 return result + " ago";
11276 }
11277 }
11278 return result;
11279 };
11280
11281 // packages/dataviews/node_modules/date-fns/locale/_lib/buildFormatLongFn.js
11282 function buildFormatLongFn(args) {
11283 return (options = {}) => {
11284 const width = options.width ? String(options.width) : args.defaultWidth;
11285 const format6 = args.formats[width] || args.formats[args.defaultWidth];
11286 return format6;
11287 };
11288 }
11289
11290 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/formatLong.js
11291 var dateFormats = {
11292 full: "EEEE, MMMM do, y",
11293 long: "MMMM do, y",
11294 medium: "MMM d, y",
11295 short: "MM/dd/yyyy"
11296 };
11297 var timeFormats = {
11298 full: "h:mm:ss a zzzz",
11299 long: "h:mm:ss a z",
11300 medium: "h:mm:ss a",
11301 short: "h:mm a"
11302 };
11303 var dateTimeFormats = {
11304 full: "{{date}} 'at' {{time}}",
11305 long: "{{date}} 'at' {{time}}",
11306 medium: "{{date}}, {{time}}",
11307 short: "{{date}}, {{time}}"
11308 };
11309 var formatLong = {
11310 date: buildFormatLongFn({
11311 formats: dateFormats,
11312 defaultWidth: "full"
11313 }),
11314 time: buildFormatLongFn({
11315 formats: timeFormats,
11316 defaultWidth: "full"
11317 }),
11318 dateTime: buildFormatLongFn({
11319 formats: dateTimeFormats,
11320 defaultWidth: "full"
11321 })
11322 };
11323
11324 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/formatRelative.js
11325 var formatRelativeLocale = {
11326 lastWeek: "'last' eeee 'at' p",
11327 yesterday: "'yesterday at' p",
11328 today: "'today at' p",
11329 tomorrow: "'tomorrow at' p",
11330 nextWeek: "eeee 'at' p",
11331 other: "P"
11332 };
11333 var formatRelative = (token, _date, _baseDate, _options) => formatRelativeLocale[token];
11334
11335 // packages/dataviews/node_modules/date-fns/locale/_lib/buildLocalizeFn.js
11336 function buildLocalizeFn(args) {
11337 return (value, options) => {
11338 const context = options?.context ? String(options.context) : "standalone";
11339 let valuesArray;
11340 if (context === "formatting" && args.formattingValues) {
11341 const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
11342 const width = options?.width ? String(options.width) : defaultWidth;
11343 valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
11344 } else {
11345 const defaultWidth = args.defaultWidth;
11346 const width = options?.width ? String(options.width) : args.defaultWidth;
11347 valuesArray = args.values[width] || args.values[defaultWidth];
11348 }
11349 const index = args.argumentCallback ? args.argumentCallback(value) : value;
11350 return valuesArray[index];
11351 };
11352 }
11353
11354 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/localize.js
11355 var eraValues = {
11356 narrow: ["B", "A"],
11357 abbreviated: ["BC", "AD"],
11358 wide: ["Before Christ", "Anno Domini"]
11359 };
11360 var quarterValues = {
11361 narrow: ["1", "2", "3", "4"],
11362 abbreviated: ["Q1", "Q2", "Q3", "Q4"],
11363 wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"]
11364 };
11365 var monthValues = {
11366 narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
11367 abbreviated: [
11368 "Jan",
11369 "Feb",
11370 "Mar",
11371 "Apr",
11372 "May",
11373 "Jun",
11374 "Jul",
11375 "Aug",
11376 "Sep",
11377 "Oct",
11378 "Nov",
11379 "Dec"
11380 ],
11381 wide: [
11382 "January",
11383 "February",
11384 "March",
11385 "April",
11386 "May",
11387 "June",
11388 "July",
11389 "August",
11390 "September",
11391 "October",
11392 "November",
11393 "December"
11394 ]
11395 };
11396 var dayValues = {
11397 narrow: ["S", "M", "T", "W", "T", "F", "S"],
11398 short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
11399 abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
11400 wide: [
11401 "Sunday",
11402 "Monday",
11403 "Tuesday",
11404 "Wednesday",
11405 "Thursday",
11406 "Friday",
11407 "Saturday"
11408 ]
11409 };
11410 var dayPeriodValues = {
11411 narrow: {
11412 am: "a",
11413 pm: "p",
11414 midnight: "mi",
11415 noon: "n",
11416 morning: "morning",
11417 afternoon: "afternoon",
11418 evening: "evening",
11419 night: "night"
11420 },
11421 abbreviated: {
11422 am: "AM",
11423 pm: "PM",
11424 midnight: "midnight",
11425 noon: "noon",
11426 morning: "morning",
11427 afternoon: "afternoon",
11428 evening: "evening",
11429 night: "night"
11430 },
11431 wide: {
11432 am: "a.m.",
11433 pm: "p.m.",
11434 midnight: "midnight",
11435 noon: "noon",
11436 morning: "morning",
11437 afternoon: "afternoon",
11438 evening: "evening",
11439 night: "night"
11440 }
11441 };
11442 var formattingDayPeriodValues = {
11443 narrow: {
11444 am: "a",
11445 pm: "p",
11446 midnight: "mi",
11447 noon: "n",
11448 morning: "in the morning",
11449 afternoon: "in the afternoon",
11450 evening: "in the evening",
11451 night: "at night"
11452 },
11453 abbreviated: {
11454 am: "AM",
11455 pm: "PM",
11456 midnight: "midnight",
11457 noon: "noon",
11458 morning: "in the morning",
11459 afternoon: "in the afternoon",
11460 evening: "in the evening",
11461 night: "at night"
11462 },
11463 wide: {
11464 am: "a.m.",
11465 pm: "p.m.",
11466 midnight: "midnight",
11467 noon: "noon",
11468 morning: "in the morning",
11469 afternoon: "in the afternoon",
11470 evening: "in the evening",
11471 night: "at night"
11472 }
11473 };
11474 var ordinalNumber = (dirtyNumber, _options) => {
11475 const number = Number(dirtyNumber);
11476 const rem100 = number % 100;
11477 if (rem100 > 20 || rem100 < 10) {
11478 switch (rem100 % 10) {
11479 case 1:
11480 return number + "st";
11481 case 2:
11482 return number + "nd";
11483 case 3:
11484 return number + "rd";
11485 }
11486 }
11487 return number + "th";
11488 };
11489 var localize = {
11490 ordinalNumber,
11491 era: buildLocalizeFn({
11492 values: eraValues,
11493 defaultWidth: "wide"
11494 }),
11495 quarter: buildLocalizeFn({
11496 values: quarterValues,
11497 defaultWidth: "wide",
11498 argumentCallback: (quarter) => quarter - 1
11499 }),
11500 month: buildLocalizeFn({
11501 values: monthValues,
11502 defaultWidth: "wide"
11503 }),
11504 day: buildLocalizeFn({
11505 values: dayValues,
11506 defaultWidth: "wide"
11507 }),
11508 dayPeriod: buildLocalizeFn({
11509 values: dayPeriodValues,
11510 defaultWidth: "wide",
11511 formattingValues: formattingDayPeriodValues,
11512 defaultFormattingWidth: "wide"
11513 })
11514 };
11515
11516 // packages/dataviews/node_modules/date-fns/locale/_lib/buildMatchFn.js
11517 function buildMatchFn(args) {
11518 return (string, options = {}) => {
11519 const width = options.width;
11520 const matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
11521 const matchResult = string.match(matchPattern);
11522 if (!matchResult) {
11523 return null;
11524 }
11525 const matchedString = matchResult[0];
11526 const parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
11527 const key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString)) : (
11528 // [TODO] -- I challenge you to fix the type
11529 findKey(parsePatterns, (pattern) => pattern.test(matchedString))
11530 );
11531 let value;
11532 value = args.valueCallback ? args.valueCallback(key) : key;
11533 value = options.valueCallback ? (
11534 // [TODO] -- I challenge you to fix the type
11535 options.valueCallback(value)
11536 ) : value;
11537 const rest = string.slice(matchedString.length);
11538 return { value, rest };
11539 };
11540 }
11541 function findKey(object, predicate) {
11542 for (const key in object) {
11543 if (Object.prototype.hasOwnProperty.call(object, key) && predicate(object[key])) {
11544 return key;
11545 }
11546 }
11547 return void 0;
11548 }
11549 function findIndex(array, predicate) {
11550 for (let key = 0; key < array.length; key++) {
11551 if (predicate(array[key])) {
11552 return key;
11553 }
11554 }
11555 return void 0;
11556 }
11557
11558 // packages/dataviews/node_modules/date-fns/locale/_lib/buildMatchPatternFn.js
11559 function buildMatchPatternFn(args) {
11560 return (string, options = {}) => {
11561 const matchResult = string.match(args.matchPattern);
11562 if (!matchResult) return null;
11563 const matchedString = matchResult[0];
11564 const parseResult = string.match(args.parsePattern);
11565 if (!parseResult) return null;
11566 let value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
11567 value = options.valueCallback ? options.valueCallback(value) : value;
11568 const rest = string.slice(matchedString.length);
11569 return { value, rest };
11570 };
11571 }
11572
11573 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/match.js
11574 var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
11575 var parseOrdinalNumberPattern = /\d+/i;
11576 var matchEraPatterns = {
11577 narrow: /^(b|a)/i,
11578 abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
11579 wide: /^(before christ|before common era|anno domini|common era)/i
11580 };
11581 var parseEraPatterns = {
11582 any: [/^b/i, /^(a|c)/i]
11583 };
11584 var matchQuarterPatterns = {
11585 narrow: /^[1234]/i,
11586 abbreviated: /^q[1234]/i,
11587 wide: /^[1234](th|st|nd|rd)? quarter/i
11588 };
11589 var parseQuarterPatterns = {
11590 any: [/1/i, /2/i, /3/i, /4/i]
11591 };
11592 var matchMonthPatterns = {
11593 narrow: /^[jfmasond]/i,
11594 abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
11595 wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
11596 };
11597 var parseMonthPatterns = {
11598 narrow: [
11599 /^j/i,
11600 /^f/i,
11601 /^m/i,
11602 /^a/i,
11603 /^m/i,
11604 /^j/i,
11605 /^j/i,
11606 /^a/i,
11607 /^s/i,
11608 /^o/i,
11609 /^n/i,
11610 /^d/i
11611 ],
11612 any: [
11613 /^ja/i,
11614 /^f/i,
11615 /^mar/i,
11616 /^ap/i,
11617 /^may/i,
11618 /^jun/i,
11619 /^jul/i,
11620 /^au/i,
11621 /^s/i,
11622 /^o/i,
11623 /^n/i,
11624 /^d/i
11625 ]
11626 };
11627 var matchDayPatterns = {
11628 narrow: /^[smtwf]/i,
11629 short: /^(su|mo|tu|we|th|fr|sa)/i,
11630 abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
11631 wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
11632 };
11633 var parseDayPatterns = {
11634 narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
11635 any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
11636 };
11637 var matchDayPeriodPatterns = {
11638 narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
11639 any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
11640 };
11641 var parseDayPeriodPatterns = {
11642 any: {
11643 am: /^a/i,
11644 pm: /^p/i,
11645 midnight: /^mi/i,
11646 noon: /^no/i,
11647 morning: /morning/i,
11648 afternoon: /afternoon/i,
11649 evening: /evening/i,
11650 night: /night/i
11651 }
11652 };
11653 var match = {
11654 ordinalNumber: buildMatchPatternFn({
11655 matchPattern: matchOrdinalNumberPattern,
11656 parsePattern: parseOrdinalNumberPattern,
11657 valueCallback: (value) => parseInt(value, 10)
11658 }),
11659 era: buildMatchFn({
11660 matchPatterns: matchEraPatterns,
11661 defaultMatchWidth: "wide",
11662 parsePatterns: parseEraPatterns,
11663 defaultParseWidth: "any"
11664 }),
11665 quarter: buildMatchFn({
11666 matchPatterns: matchQuarterPatterns,
11667 defaultMatchWidth: "wide",
11668 parsePatterns: parseQuarterPatterns,
11669 defaultParseWidth: "any",
11670 valueCallback: (index) => index + 1
11671 }),
11672 month: buildMatchFn({
11673 matchPatterns: matchMonthPatterns,
11674 defaultMatchWidth: "wide",
11675 parsePatterns: parseMonthPatterns,
11676 defaultParseWidth: "any"
11677 }),
11678 day: buildMatchFn({
11679 matchPatterns: matchDayPatterns,
11680 defaultMatchWidth: "wide",
11681 parsePatterns: parseDayPatterns,
11682 defaultParseWidth: "any"
11683 }),
11684 dayPeriod: buildMatchFn({
11685 matchPatterns: matchDayPeriodPatterns,
11686 defaultMatchWidth: "any",
11687 parsePatterns: parseDayPeriodPatterns,
11688 defaultParseWidth: "any"
11689 })
11690 };
11691
11692 // packages/dataviews/node_modules/date-fns/locale/en-US.js
11693 var enUS = {
11694 code: "en-US",
11695 formatDistance,
11696 formatLong,
11697 formatRelative,
11698 localize,
11699 match,
11700 options: {
11701 weekStartsOn: 0,
11702 firstWeekContainsDate: 1
11703 }
11704 };
11705
11706 // packages/dataviews/node_modules/date-fns/getDayOfYear.js
11707 function getDayOfYear(date, options) {
11708 const _date = toDate(date, options?.in);
11709 const diff = differenceInCalendarDays(_date, startOfYear(_date));
11710 const dayOfYear = diff + 1;
11711 return dayOfYear;
11712 }
11713
11714 // packages/dataviews/node_modules/date-fns/getISOWeek.js
11715 function getISOWeek(date, options) {
11716 const _date = toDate(date, options?.in);
11717 const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
11718 return Math.round(diff / millisecondsInWeek) + 1;
11719 }
11720
11721 // packages/dataviews/node_modules/date-fns/getWeekYear.js
11722 function getWeekYear(date, options) {
11723 const _date = toDate(date, options?.in);
11724 const year = _date.getFullYear();
11725 const defaultOptions2 = getDefaultOptions();
11726 const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
11727 const firstWeekOfNextYear = constructFrom(options?.in || date, 0);
11728 firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
11729 firstWeekOfNextYear.setHours(0, 0, 0, 0);
11730 const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
11731 const firstWeekOfThisYear = constructFrom(options?.in || date, 0);
11732 firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
11733 firstWeekOfThisYear.setHours(0, 0, 0, 0);
11734 const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
11735 if (+_date >= +startOfNextYear) {
11736 return year + 1;
11737 } else if (+_date >= +startOfThisYear) {
11738 return year;
11739 } else {
11740 return year - 1;
11741 }
11742 }
11743
11744 // packages/dataviews/node_modules/date-fns/startOfWeekYear.js
11745 function startOfWeekYear(date, options) {
11746 const defaultOptions2 = getDefaultOptions();
11747 const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
11748 const year = getWeekYear(date, options);
11749 const firstWeek = constructFrom(options?.in || date, 0);
11750 firstWeek.setFullYear(year, 0, firstWeekContainsDate);
11751 firstWeek.setHours(0, 0, 0, 0);
11752 const _date = startOfWeek(firstWeek, options);
11753 return _date;
11754 }
11755
11756 // packages/dataviews/node_modules/date-fns/getWeek.js
11757 function getWeek(date, options) {
11758 const _date = toDate(date, options?.in);
11759 const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
11760 return Math.round(diff / millisecondsInWeek) + 1;
11761 }
11762
11763 // packages/dataviews/node_modules/date-fns/_lib/addLeadingZeros.js
11764 function addLeadingZeros(number, targetLength) {
11765 const sign = number < 0 ? "-" : "";
11766 const output = Math.abs(number).toString().padStart(targetLength, "0");
11767 return sign + output;
11768 }
11769
11770 // packages/dataviews/node_modules/date-fns/_lib/format/lightFormatters.js
11771 var lightFormatters = {
11772 // Year
11773 y(date, token) {
11774 const signedYear = date.getFullYear();
11775 const year = signedYear > 0 ? signedYear : 1 - signedYear;
11776 return addLeadingZeros(token === "yy" ? year % 100 : year, token.length);
11777 },
11778 // Month
11779 M(date, token) {
11780 const month = date.getMonth();
11781 return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2);
11782 },
11783 // Day of the month
11784 d(date, token) {
11785 return addLeadingZeros(date.getDate(), token.length);
11786 },
11787 // AM or PM
11788 a(date, token) {
11789 const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am";
11790 switch (token) {
11791 case "a":
11792 case "aa":
11793 return dayPeriodEnumValue.toUpperCase();
11794 case "aaa":
11795 return dayPeriodEnumValue;
11796 case "aaaaa":
11797 return dayPeriodEnumValue[0];
11798 case "aaaa":
11799 default:
11800 return dayPeriodEnumValue === "am" ? "a.m." : "p.m.";
11801 }
11802 },
11803 // Hour [1-12]
11804 h(date, token) {
11805 return addLeadingZeros(date.getHours() % 12 || 12, token.length);
11806 },
11807 // Hour [0-23]
11808 H(date, token) {
11809 return addLeadingZeros(date.getHours(), token.length);
11810 },
11811 // Minute
11812 m(date, token) {
11813 return addLeadingZeros(date.getMinutes(), token.length);
11814 },
11815 // Second
11816 s(date, token) {
11817 return addLeadingZeros(date.getSeconds(), token.length);
11818 },
11819 // Fraction of second
11820 S(date, token) {
11821 const numberOfDigits = token.length;
11822 const milliseconds = date.getMilliseconds();
11823 const fractionalSeconds = Math.trunc(
11824 milliseconds * Math.pow(10, numberOfDigits - 3)
11825 );
11826 return addLeadingZeros(fractionalSeconds, token.length);
11827 }
11828 };
11829
11830 // packages/dataviews/node_modules/date-fns/_lib/format/formatters.js
11831 var dayPeriodEnum = {
11832 am: "am",
11833 pm: "pm",
11834 midnight: "midnight",
11835 noon: "noon",
11836 morning: "morning",
11837 afternoon: "afternoon",
11838 evening: "evening",
11839 night: "night"
11840 };
11841 var formatters = {
11842 // Era
11843 G: function(date, token, localize2) {
11844 const era = date.getFullYear() > 0 ? 1 : 0;
11845 switch (token) {
11846 // AD, BC
11847 case "G":
11848 case "GG":
11849 case "GGG":
11850 return localize2.era(era, { width: "abbreviated" });
11851 // A, B
11852 case "GGGGG":
11853 return localize2.era(era, { width: "narrow" });
11854 // Anno Domini, Before Christ
11855 case "GGGG":
11856 default:
11857 return localize2.era(era, { width: "wide" });
11858 }
11859 },
11860 // Year
11861 y: function(date, token, localize2) {
11862 if (token === "yo") {
11863 const signedYear = date.getFullYear();
11864 const year = signedYear > 0 ? signedYear : 1 - signedYear;
11865 return localize2.ordinalNumber(year, { unit: "year" });
11866 }
11867 return lightFormatters.y(date, token);
11868 },
11869 // Local week-numbering year
11870 Y: function(date, token, localize2, options) {
11871 const signedWeekYear = getWeekYear(date, options);
11872 const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
11873 if (token === "YY") {
11874 const twoDigitYear = weekYear % 100;
11875 return addLeadingZeros(twoDigitYear, 2);
11876 }
11877 if (token === "Yo") {
11878 return localize2.ordinalNumber(weekYear, { unit: "year" });
11879 }
11880 return addLeadingZeros(weekYear, token.length);
11881 },
11882 // ISO week-numbering year
11883 R: function(date, token) {
11884 const isoWeekYear = getISOWeekYear(date);
11885 return addLeadingZeros(isoWeekYear, token.length);
11886 },
11887 // Extended year. This is a single number designating the year of this calendar system.
11888 // The main difference between `y` and `u` localizers are B.C. years:
11889 // | Year | `y` | `u` |
11890 // |------|-----|-----|
11891 // | AC 1 | 1 | 1 |
11892 // | BC 1 | 1 | 0 |
11893 // | BC 2 | 2 | -1 |
11894 // Also `yy` always returns the last two digits of a year,
11895 // while `uu` pads single digit years to 2 characters and returns other years unchanged.
11896 u: function(date, token) {
11897 const year = date.getFullYear();
11898 return addLeadingZeros(year, token.length);
11899 },
11900 // Quarter
11901 Q: function(date, token, localize2) {
11902 const quarter = Math.ceil((date.getMonth() + 1) / 3);
11903 switch (token) {
11904 // 1, 2, 3, 4
11905 case "Q":
11906 return String(quarter);
11907 // 01, 02, 03, 04
11908 case "QQ":
11909 return addLeadingZeros(quarter, 2);
11910 // 1st, 2nd, 3rd, 4th
11911 case "Qo":
11912 return localize2.ordinalNumber(quarter, { unit: "quarter" });
11913 // Q1, Q2, Q3, Q4
11914 case "QQQ":
11915 return localize2.quarter(quarter, {
11916 width: "abbreviated",
11917 context: "formatting"
11918 });
11919 // 1, 2, 3, 4 (narrow quarter; could be not numerical)
11920 case "QQQQQ":
11921 return localize2.quarter(quarter, {
11922 width: "narrow",
11923 context: "formatting"
11924 });
11925 // 1st quarter, 2nd quarter, ...
11926 case "QQQQ":
11927 default:
11928 return localize2.quarter(quarter, {
11929 width: "wide",
11930 context: "formatting"
11931 });
11932 }
11933 },
11934 // Stand-alone quarter
11935 q: function(date, token, localize2) {
11936 const quarter = Math.ceil((date.getMonth() + 1) / 3);
11937 switch (token) {
11938 // 1, 2, 3, 4
11939 case "q":
11940 return String(quarter);
11941 // 01, 02, 03, 04
11942 case "qq":
11943 return addLeadingZeros(quarter, 2);
11944 // 1st, 2nd, 3rd, 4th
11945 case "qo":
11946 return localize2.ordinalNumber(quarter, { unit: "quarter" });
11947 // Q1, Q2, Q3, Q4
11948 case "qqq":
11949 return localize2.quarter(quarter, {
11950 width: "abbreviated",
11951 context: "standalone"
11952 });
11953 // 1, 2, 3, 4 (narrow quarter; could be not numerical)
11954 case "qqqqq":
11955 return localize2.quarter(quarter, {
11956 width: "narrow",
11957 context: "standalone"
11958 });
11959 // 1st quarter, 2nd quarter, ...
11960 case "qqqq":
11961 default:
11962 return localize2.quarter(quarter, {
11963 width: "wide",
11964 context: "standalone"
11965 });
11966 }
11967 },
11968 // Month
11969 M: function(date, token, localize2) {
11970 const month = date.getMonth();
11971 switch (token) {
11972 case "M":
11973 case "MM":
11974 return lightFormatters.M(date, token);
11975 // 1st, 2nd, ..., 12th
11976 case "Mo":
11977 return localize2.ordinalNumber(month + 1, { unit: "month" });
11978 // Jan, Feb, ..., Dec
11979 case "MMM":
11980 return localize2.month(month, {
11981 width: "abbreviated",
11982 context: "formatting"
11983 });
11984 // J, F, ..., D
11985 case "MMMMM":
11986 return localize2.month(month, {
11987 width: "narrow",
11988 context: "formatting"
11989 });
11990 // January, February, ..., December
11991 case "MMMM":
11992 default:
11993 return localize2.month(month, { width: "wide", context: "formatting" });
11994 }
11995 },
11996 // Stand-alone month
11997 L: function(date, token, localize2) {
11998 const month = date.getMonth();
11999 switch (token) {
12000 // 1, 2, ..., 12
12001 case "L":
12002 return String(month + 1);
12003 // 01, 02, ..., 12
12004 case "LL":
12005 return addLeadingZeros(month + 1, 2);
12006 // 1st, 2nd, ..., 12th
12007 case "Lo":
12008 return localize2.ordinalNumber(month + 1, { unit: "month" });
12009 // Jan, Feb, ..., Dec
12010 case "LLL":
12011 return localize2.month(month, {
12012 width: "abbreviated",
12013 context: "standalone"
12014 });
12015 // J, F, ..., D
12016 case "LLLLL":
12017 return localize2.month(month, {
12018 width: "narrow",
12019 context: "standalone"
12020 });
12021 // January, February, ..., December
12022 case "LLLL":
12023 default:
12024 return localize2.month(month, { width: "wide", context: "standalone" });
12025 }
12026 },
12027 // Local week of year
12028 w: function(date, token, localize2, options) {
12029 const week = getWeek(date, options);
12030 if (token === "wo") {
12031 return localize2.ordinalNumber(week, { unit: "week" });
12032 }
12033 return addLeadingZeros(week, token.length);
12034 },
12035 // ISO week of year
12036 I: function(date, token, localize2) {
12037 const isoWeek = getISOWeek(date);
12038 if (token === "Io") {
12039 return localize2.ordinalNumber(isoWeek, { unit: "week" });
12040 }
12041 return addLeadingZeros(isoWeek, token.length);
12042 },
12043 // Day of the month
12044 d: function(date, token, localize2) {
12045 if (token === "do") {
12046 return localize2.ordinalNumber(date.getDate(), { unit: "date" });
12047 }
12048 return lightFormatters.d(date, token);
12049 },
12050 // Day of year
12051 D: function(date, token, localize2) {
12052 const dayOfYear = getDayOfYear(date);
12053 if (token === "Do") {
12054 return localize2.ordinalNumber(dayOfYear, { unit: "dayOfYear" });
12055 }
12056 return addLeadingZeros(dayOfYear, token.length);
12057 },
12058 // Day of week
12059 E: function(date, token, localize2) {
12060 const dayOfWeek = date.getDay();
12061 switch (token) {
12062 // Tue
12063 case "E":
12064 case "EE":
12065 case "EEE":
12066 return localize2.day(dayOfWeek, {
12067 width: "abbreviated",
12068 context: "formatting"
12069 });
12070 // T
12071 case "EEEEE":
12072 return localize2.day(dayOfWeek, {
12073 width: "narrow",
12074 context: "formatting"
12075 });
12076 // Tu
12077 case "EEEEEE":
12078 return localize2.day(dayOfWeek, {
12079 width: "short",
12080 context: "formatting"
12081 });
12082 // Tuesday
12083 case "EEEE":
12084 default:
12085 return localize2.day(dayOfWeek, {
12086 width: "wide",
12087 context: "formatting"
12088 });
12089 }
12090 },
12091 // Local day of week
12092 e: function(date, token, localize2, options) {
12093 const dayOfWeek = date.getDay();
12094 const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
12095 switch (token) {
12096 // Numerical value (Nth day of week with current locale or weekStartsOn)
12097 case "e":
12098 return String(localDayOfWeek);
12099 // Padded numerical value
12100 case "ee":
12101 return addLeadingZeros(localDayOfWeek, 2);
12102 // 1st, 2nd, ..., 7th
12103 case "eo":
12104 return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
12105 case "eee":
12106 return localize2.day(dayOfWeek, {
12107 width: "abbreviated",
12108 context: "formatting"
12109 });
12110 // T
12111 case "eeeee":
12112 return localize2.day(dayOfWeek, {
12113 width: "narrow",
12114 context: "formatting"
12115 });
12116 // Tu
12117 case "eeeeee":
12118 return localize2.day(dayOfWeek, {
12119 width: "short",
12120 context: "formatting"
12121 });
12122 // Tuesday
12123 case "eeee":
12124 default:
12125 return localize2.day(dayOfWeek, {
12126 width: "wide",
12127 context: "formatting"
12128 });
12129 }
12130 },
12131 // Stand-alone local day of week
12132 c: function(date, token, localize2, options) {
12133 const dayOfWeek = date.getDay();
12134 const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
12135 switch (token) {
12136 // Numerical value (same as in `e`)
12137 case "c":
12138 return String(localDayOfWeek);
12139 // Padded numerical value
12140 case "cc":
12141 return addLeadingZeros(localDayOfWeek, token.length);
12142 // 1st, 2nd, ..., 7th
12143 case "co":
12144 return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
12145 case "ccc":
12146 return localize2.day(dayOfWeek, {
12147 width: "abbreviated",
12148 context: "standalone"
12149 });
12150 // T
12151 case "ccccc":
12152 return localize2.day(dayOfWeek, {
12153 width: "narrow",
12154 context: "standalone"
12155 });
12156 // Tu
12157 case "cccccc":
12158 return localize2.day(dayOfWeek, {
12159 width: "short",
12160 context: "standalone"
12161 });
12162 // Tuesday
12163 case "cccc":
12164 default:
12165 return localize2.day(dayOfWeek, {
12166 width: "wide",
12167 context: "standalone"
12168 });
12169 }
12170 },
12171 // ISO day of week
12172 i: function(date, token, localize2) {
12173 const dayOfWeek = date.getDay();
12174 const isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
12175 switch (token) {
12176 // 2
12177 case "i":
12178 return String(isoDayOfWeek);
12179 // 02
12180 case "ii":
12181 return addLeadingZeros(isoDayOfWeek, token.length);
12182 // 2nd
12183 case "io":
12184 return localize2.ordinalNumber(isoDayOfWeek, { unit: "day" });
12185 // Tue
12186 case "iii":
12187 return localize2.day(dayOfWeek, {
12188 width: "abbreviated",
12189 context: "formatting"
12190 });
12191 // T
12192 case "iiiii":
12193 return localize2.day(dayOfWeek, {
12194 width: "narrow",
12195 context: "formatting"
12196 });
12197 // Tu
12198 case "iiiiii":
12199 return localize2.day(dayOfWeek, {
12200 width: "short",
12201 context: "formatting"
12202 });
12203 // Tuesday
12204 case "iiii":
12205 default:
12206 return localize2.day(dayOfWeek, {
12207 width: "wide",
12208 context: "formatting"
12209 });
12210 }
12211 },
12212 // AM or PM
12213 a: function(date, token, localize2) {
12214 const hours = date.getHours();
12215 const dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
12216 switch (token) {
12217 case "a":
12218 case "aa":
12219 return localize2.dayPeriod(dayPeriodEnumValue, {
12220 width: "abbreviated",
12221 context: "formatting"
12222 });
12223 case "aaa":
12224 return localize2.dayPeriod(dayPeriodEnumValue, {
12225 width: "abbreviated",
12226 context: "formatting"
12227 }).toLowerCase();
12228 case "aaaaa":
12229 return localize2.dayPeriod(dayPeriodEnumValue, {
12230 width: "narrow",
12231 context: "formatting"
12232 });
12233 case "aaaa":
12234 default:
12235 return localize2.dayPeriod(dayPeriodEnumValue, {
12236 width: "wide",
12237 context: "formatting"
12238 });
12239 }
12240 },
12241 // AM, PM, midnight, noon
12242 b: function(date, token, localize2) {
12243 const hours = date.getHours();
12244 let dayPeriodEnumValue;
12245 if (hours === 12) {
12246 dayPeriodEnumValue = dayPeriodEnum.noon;
12247 } else if (hours === 0) {
12248 dayPeriodEnumValue = dayPeriodEnum.midnight;
12249 } else {
12250 dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
12251 }
12252 switch (token) {
12253 case "b":
12254 case "bb":
12255 return localize2.dayPeriod(dayPeriodEnumValue, {
12256 width: "abbreviated",
12257 context: "formatting"
12258 });
12259 case "bbb":
12260 return localize2.dayPeriod(dayPeriodEnumValue, {
12261 width: "abbreviated",
12262 context: "formatting"
12263 }).toLowerCase();
12264 case "bbbbb":
12265 return localize2.dayPeriod(dayPeriodEnumValue, {
12266 width: "narrow",
12267 context: "formatting"
12268 });
12269 case "bbbb":
12270 default:
12271 return localize2.dayPeriod(dayPeriodEnumValue, {
12272 width: "wide",
12273 context: "formatting"
12274 });
12275 }
12276 },
12277 // in the morning, in the afternoon, in the evening, at night
12278 B: function(date, token, localize2) {
12279 const hours = date.getHours();
12280 let dayPeriodEnumValue;
12281 if (hours >= 17) {
12282 dayPeriodEnumValue = dayPeriodEnum.evening;
12283 } else if (hours >= 12) {
12284 dayPeriodEnumValue = dayPeriodEnum.afternoon;
12285 } else if (hours >= 4) {
12286 dayPeriodEnumValue = dayPeriodEnum.morning;
12287 } else {
12288 dayPeriodEnumValue = dayPeriodEnum.night;
12289 }
12290 switch (token) {
12291 case "B":
12292 case "BB":
12293 case "BBB":
12294 return localize2.dayPeriod(dayPeriodEnumValue, {
12295 width: "abbreviated",
12296 context: "formatting"
12297 });
12298 case "BBBBB":
12299 return localize2.dayPeriod(dayPeriodEnumValue, {
12300 width: "narrow",
12301 context: "formatting"
12302 });
12303 case "BBBB":
12304 default:
12305 return localize2.dayPeriod(dayPeriodEnumValue, {
12306 width: "wide",
12307 context: "formatting"
12308 });
12309 }
12310 },
12311 // Hour [1-12]
12312 h: function(date, token, localize2) {
12313 if (token === "ho") {
12314 let hours = date.getHours() % 12;
12315 if (hours === 0) hours = 12;
12316 return localize2.ordinalNumber(hours, { unit: "hour" });
12317 }
12318 return lightFormatters.h(date, token);
12319 },
12320 // Hour [0-23]
12321 H: function(date, token, localize2) {
12322 if (token === "Ho") {
12323 return localize2.ordinalNumber(date.getHours(), { unit: "hour" });
12324 }
12325 return lightFormatters.H(date, token);
12326 },
12327 // Hour [0-11]
12328 K: function(date, token, localize2) {
12329 const hours = date.getHours() % 12;
12330 if (token === "Ko") {
12331 return localize2.ordinalNumber(hours, { unit: "hour" });
12332 }
12333 return addLeadingZeros(hours, token.length);
12334 },
12335 // Hour [1-24]
12336 k: function(date, token, localize2) {
12337 let hours = date.getHours();
12338 if (hours === 0) hours = 24;
12339 if (token === "ko") {
12340 return localize2.ordinalNumber(hours, { unit: "hour" });
12341 }
12342 return addLeadingZeros(hours, token.length);
12343 },
12344 // Minute
12345 m: function(date, token, localize2) {
12346 if (token === "mo") {
12347 return localize2.ordinalNumber(date.getMinutes(), { unit: "minute" });
12348 }
12349 return lightFormatters.m(date, token);
12350 },
12351 // Second
12352 s: function(date, token, localize2) {
12353 if (token === "so") {
12354 return localize2.ordinalNumber(date.getSeconds(), { unit: "second" });
12355 }
12356 return lightFormatters.s(date, token);
12357 },
12358 // Fraction of second
12359 S: function(date, token) {
12360 return lightFormatters.S(date, token);
12361 },
12362 // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
12363 X: function(date, token, _localize) {
12364 const timezoneOffset = date.getTimezoneOffset();
12365 if (timezoneOffset === 0) {
12366 return "Z";
12367 }
12368 switch (token) {
12369 // Hours and optional minutes
12370 case "X":
12371 return formatTimezoneWithOptionalMinutes(timezoneOffset);
12372 // Hours, minutes and optional seconds without `:` delimiter
12373 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12374 // so this token always has the same output as `XX`
12375 case "XXXX":
12376 case "XX":
12377 return formatTimezone(timezoneOffset);
12378 // Hours, minutes and optional seconds with `:` delimiter
12379 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12380 // so this token always has the same output as `XXX`
12381 case "XXXXX":
12382 case "XXX":
12383 // Hours and minutes with `:` delimiter
12384 default:
12385 return formatTimezone(timezoneOffset, ":");
12386 }
12387 },
12388 // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
12389 x: function(date, token, _localize) {
12390 const timezoneOffset = date.getTimezoneOffset();
12391 switch (token) {
12392 // Hours and optional minutes
12393 case "x":
12394 return formatTimezoneWithOptionalMinutes(timezoneOffset);
12395 // Hours, minutes and optional seconds without `:` delimiter
12396 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12397 // so this token always has the same output as `xx`
12398 case "xxxx":
12399 case "xx":
12400 return formatTimezone(timezoneOffset);
12401 // Hours, minutes and optional seconds with `:` delimiter
12402 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12403 // so this token always has the same output as `xxx`
12404 case "xxxxx":
12405 case "xxx":
12406 // Hours and minutes with `:` delimiter
12407 default:
12408 return formatTimezone(timezoneOffset, ":");
12409 }
12410 },
12411 // Timezone (GMT)
12412 O: function(date, token, _localize) {
12413 const timezoneOffset = date.getTimezoneOffset();
12414 switch (token) {
12415 // Short
12416 case "O":
12417 case "OO":
12418 case "OOO":
12419 return "GMT" + formatTimezoneShort(timezoneOffset, ":");
12420 // Long
12421 case "OOOO":
12422 default:
12423 return "GMT" + formatTimezone(timezoneOffset, ":");
12424 }
12425 },
12426 // Timezone (specific non-location)
12427 z: function(date, token, _localize) {
12428 const timezoneOffset = date.getTimezoneOffset();
12429 switch (token) {
12430 // Short
12431 case "z":
12432 case "zz":
12433 case "zzz":
12434 return "GMT" + formatTimezoneShort(timezoneOffset, ":");
12435 // Long
12436 case "zzzz":
12437 default:
12438 return "GMT" + formatTimezone(timezoneOffset, ":");
12439 }
12440 },
12441 // Seconds timestamp
12442 t: function(date, token, _localize) {
12443 const timestamp = Math.trunc(+date / 1e3);
12444 return addLeadingZeros(timestamp, token.length);
12445 },
12446 // Milliseconds timestamp
12447 T: function(date, token, _localize) {
12448 return addLeadingZeros(+date, token.length);
12449 }
12450 };
12451 function formatTimezoneShort(offset, delimiter = "") {
12452 const sign = offset > 0 ? "-" : "+";
12453 const absOffset = Math.abs(offset);
12454 const hours = Math.trunc(absOffset / 60);
12455 const minutes = absOffset % 60;
12456 if (minutes === 0) {
12457 return sign + String(hours);
12458 }
12459 return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
12460 }
12461 function formatTimezoneWithOptionalMinutes(offset, delimiter) {
12462 if (offset % 60 === 0) {
12463 const sign = offset > 0 ? "-" : "+";
12464 return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
12465 }
12466 return formatTimezone(offset, delimiter);
12467 }
12468 function formatTimezone(offset, delimiter = "") {
12469 const sign = offset > 0 ? "-" : "+";
12470 const absOffset = Math.abs(offset);
12471 const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2);
12472 const minutes = addLeadingZeros(absOffset % 60, 2);
12473 return sign + hours + delimiter + minutes;
12474 }
12475
12476 // packages/dataviews/node_modules/date-fns/_lib/format/longFormatters.js
12477 var dateLongFormatter = (pattern, formatLong2) => {
12478 switch (pattern) {
12479 case "P":
12480 return formatLong2.date({ width: "short" });
12481 case "PP":
12482 return formatLong2.date({ width: "medium" });
12483 case "PPP":
12484 return formatLong2.date({ width: "long" });
12485 case "PPPP":
12486 default:
12487 return formatLong2.date({ width: "full" });
12488 }
12489 };
12490 var timeLongFormatter = (pattern, formatLong2) => {
12491 switch (pattern) {
12492 case "p":
12493 return formatLong2.time({ width: "short" });
12494 case "pp":
12495 return formatLong2.time({ width: "medium" });
12496 case "ppp":
12497 return formatLong2.time({ width: "long" });
12498 case "pppp":
12499 default:
12500 return formatLong2.time({ width: "full" });
12501 }
12502 };
12503 var dateTimeLongFormatter = (pattern, formatLong2) => {
12504 const matchResult = pattern.match(/(P+)(p+)?/) || [];
12505 const datePattern = matchResult[1];
12506 const timePattern = matchResult[2];
12507 if (!timePattern) {
12508 return dateLongFormatter(pattern, formatLong2);
12509 }
12510 let dateTimeFormat;
12511 switch (datePattern) {
12512 case "P":
12513 dateTimeFormat = formatLong2.dateTime({ width: "short" });
12514 break;
12515 case "PP":
12516 dateTimeFormat = formatLong2.dateTime({ width: "medium" });
12517 break;
12518 case "PPP":
12519 dateTimeFormat = formatLong2.dateTime({ width: "long" });
12520 break;
12521 case "PPPP":
12522 default:
12523 dateTimeFormat = formatLong2.dateTime({ width: "full" });
12524 break;
12525 }
12526 return dateTimeFormat.replace("{{date}}", dateLongFormatter(datePattern, formatLong2)).replace("{{time}}", timeLongFormatter(timePattern, formatLong2));
12527 };
12528 var longFormatters = {
12529 p: timeLongFormatter,
12530 P: dateTimeLongFormatter
12531 };
12532
12533 // packages/dataviews/node_modules/date-fns/_lib/protectedTokens.js
12534 var dayOfYearTokenRE = /^D+$/;
12535 var weekYearTokenRE = /^Y+$/;
12536 var throwTokens = ["D", "DD", "YY", "YYYY"];
12537 function isProtectedDayOfYearToken(token) {
12538 return dayOfYearTokenRE.test(token);
12539 }
12540 function isProtectedWeekYearToken(token) {
12541 return weekYearTokenRE.test(token);
12542 }
12543 function warnOrThrowProtectedError(token, format6, input) {
12544 const _message = message(token, format6, input);
12545 console.warn(_message);
12546 if (throwTokens.includes(token)) throw new RangeError(_message);
12547 }
12548 function message(token, format6, input) {
12549 const subject = token[0] === "Y" ? "years" : "days of the month";
12550 return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format6}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
12551 }
12552
12553 // packages/dataviews/node_modules/date-fns/format.js
12554 var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
12555 var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
12556 var escapedStringRegExp = /^'([^]*?)'?$/;
12557 var doubleQuoteRegExp = /''/g;
12558 var unescapedLatinCharacterRegExp = /[a-zA-Z]/;
12559 function format(date, formatStr, options) {
12560 const defaultOptions2 = getDefaultOptions();
12561 const locale = options?.locale ?? defaultOptions2.locale ?? enUS;
12562 const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
12563 const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
12564 const originalDate = toDate(date, options?.in);
12565 if (!isValid(originalDate)) {
12566 throw new RangeError("Invalid time value");
12567 }
12568 let parts = formatStr.match(longFormattingTokensRegExp).map((substring) => {
12569 const firstCharacter = substring[0];
12570 if (firstCharacter === "p" || firstCharacter === "P") {
12571 const longFormatter = longFormatters[firstCharacter];
12572 return longFormatter(substring, locale.formatLong);
12573 }
12574 return substring;
12575 }).join("").match(formattingTokensRegExp).map((substring) => {
12576 if (substring === "''") {
12577 return { isToken: false, value: "'" };
12578 }
12579 const firstCharacter = substring[0];
12580 if (firstCharacter === "'") {
12581 return { isToken: false, value: cleanEscapedString(substring) };
12582 }
12583 if (formatters[firstCharacter]) {
12584 return { isToken: true, value: substring };
12585 }
12586 if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
12587 throw new RangeError(
12588 "Format string contains an unescaped latin alphabet character `" + firstCharacter + "`"
12589 );
12590 }
12591 return { isToken: false, value: substring };
12592 });
12593 if (locale.localize.preprocessor) {
12594 parts = locale.localize.preprocessor(originalDate, parts);
12595 }
12596 const formatterOptions = {
12597 firstWeekContainsDate,
12598 weekStartsOn,
12599 locale
12600 };
12601 return parts.map((part) => {
12602 if (!part.isToken) return part.value;
12603 const token = part.value;
12604 if (!options?.useAdditionalWeekYearTokens && isProtectedWeekYearToken(token) || !options?.useAdditionalDayOfYearTokens && isProtectedDayOfYearToken(token)) {
12605 warnOrThrowProtectedError(token, formatStr, String(date));
12606 }
12607 const formatter = formatters[token[0]];
12608 return formatter(originalDate, token, locale.localize, formatterOptions);
12609 }).join("");
12610 }
12611 function cleanEscapedString(input) {
12612 const matched = input.match(escapedStringRegExp);
12613 if (!matched) {
12614 return input;
12615 }
12616 return matched[1].replace(doubleQuoteRegExp, "'");
12617 }
12618
12619 // packages/dataviews/node_modules/date-fns/subDays.js
12620 function subDays(date, amount, options) {
12621 return addDays(date, -amount, options);
12622 }
12623
12624 // packages/dataviews/node_modules/date-fns/subMonths.js
12625 function subMonths(date, amount, options) {
12626 return addMonths(date, -amount, options);
12627 }
12628
12629 // packages/dataviews/node_modules/date-fns/subWeeks.js
12630 function subWeeks(date, amount, options) {
12631 return addWeeks(date, -amount, options);
12632 }
12633
12634 // packages/dataviews/node_modules/date-fns/subYears.js
12635 function subYears(date, amount, options) {
12636 return addYears(date, -amount, options);
12637 }
12638
12639 // packages/dataviews/build-module/utils/operators.mjs
12640 var import_i18n29 = __toESM(require_i18n(), 1);
12641 var import_element29 = __toESM(require_element(), 1);
12642 var import_date = __toESM(require_date(), 1);
12643 var import_jsx_runtime64 = __toESM(require_jsx_runtime(), 1);
12644 var filterTextWrappers = {
12645 Name: /* @__PURE__ */ (0, import_jsx_runtime64.jsx)("span", { className: "dataviews-filters__summary-filter-text-name" }),
12646 Value: /* @__PURE__ */ (0, import_jsx_runtime64.jsx)("span", { className: "dataviews-filters__summary-filter-text-value" })
12647 };
12648 function getRelativeDate(value, unit) {
12649 switch (unit) {
12650 case "days":
12651 return subDays(/* @__PURE__ */ new Date(), value);
12652 case "weeks":
12653 return subWeeks(/* @__PURE__ */ new Date(), value);
12654 case "months":
12655 return subMonths(/* @__PURE__ */ new Date(), value);
12656 case "years":
12657 return subYears(/* @__PURE__ */ new Date(), value);
12658 default:
12659 return /* @__PURE__ */ new Date();
12660 }
12661 }
12662 var isNoneOperatorDefinition = {
12663 /* translators: DataViews operator name */
12664 label: (0, import_i18n29.__)("Is none of"),
12665 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12666 (0, import_i18n29.sprintf)(
12667 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is none of: Admin, Editor". */
12668 (0, import_i18n29.__)("<Name>%1$s is none of: </Name><Value>%2$s</Value>"),
12669 filter.name,
12670 activeElements.map((element) => element.label).join(", ")
12671 ),
12672 filterTextWrappers
12673 ),
12674 filter: ((item, field, filterValue) => {
12675 if (!filterValue?.length) {
12676 return true;
12677 }
12678 const fieldValue = field.getValue({ item });
12679 if (Array.isArray(fieldValue)) {
12680 return !filterValue.some(
12681 (fv) => fieldValue.includes(fv)
12682 );
12683 } else if (typeof fieldValue === "string") {
12684 return !filterValue.includes(fieldValue);
12685 }
12686 return false;
12687 }),
12688 selection: "multi"
12689 };
12690 var OPERATORS = [
12691 {
12692 name: OPERATOR_IS_ANY,
12693 /* translators: DataViews operator name */
12694 label: (0, import_i18n29.__)("Includes"),
12695 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12696 (0, import_i18n29.sprintf)(
12697 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is any: Admin, Editor". */
12698 (0, import_i18n29.__)("<Name>%1$s includes: </Name><Value>%2$s</Value>"),
12699 filter.name,
12700 activeElements.map((element) => element.label).join(", ")
12701 ),
12702 filterTextWrappers
12703 ),
12704 filter(item, field, filterValue) {
12705 if (!filterValue?.length) {
12706 return true;
12707 }
12708 const fieldValue = field.getValue({ item });
12709 if (Array.isArray(fieldValue)) {
12710 return filterValue.some(
12711 (fv) => fieldValue.includes(fv)
12712 );
12713 } else if (typeof fieldValue === "string") {
12714 return filterValue.includes(fieldValue);
12715 }
12716 return false;
12717 },
12718 selection: "multi"
12719 },
12720 {
12721 name: OPERATOR_IS_NONE,
12722 ...isNoneOperatorDefinition
12723 },
12724 {
12725 name: OPERATOR_IS_ALL,
12726 /* translators: DataViews operator name */
12727 label: (0, import_i18n29.__)("Includes all"),
12728 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12729 (0, import_i18n29.sprintf)(
12730 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author includes all: Admin, Editor". */
12731 (0, import_i18n29.__)("<Name>%1$s includes all: </Name><Value>%2$s</Value>"),
12732 filter.name,
12733 activeElements.map((element) => element.label).join(", ")
12734 ),
12735 filterTextWrappers
12736 ),
12737 filter(item, field, filterValue) {
12738 if (!filterValue?.length) {
12739 return true;
12740 }
12741 return filterValue.every((value) => {
12742 return field.getValue({ item })?.includes(value);
12743 });
12744 },
12745 selection: "multi"
12746 },
12747 {
12748 name: OPERATOR_IS_NOT_ALL,
12749 ...isNoneOperatorDefinition
12750 },
12751 {
12752 name: OPERATOR_BETWEEN,
12753 /* translators: DataViews operator name */
12754 label: (0, import_i18n29.__)("Between (inc)"),
12755 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12756 (0, import_i18n29.sprintf)(
12757 /* translators: 1: Filter name (e.g. "Item count"). 2: Filter value min. 3: Filter value max. e.g.: "Item count between (inc): 10 and 180". */
12758 (0, import_i18n29.__)(
12759 "<Name>%1$s between (inc): </Name><Value>%2$s and %3$s</Value>"
12760 ),
12761 filter.name,
12762 activeElements[0].label[0],
12763 activeElements[0].label[1]
12764 ),
12765 filterTextWrappers
12766 ),
12767 filter(item, field, filterValue) {
12768 if (!Array.isArray(filterValue) || filterValue.length !== 2 || filterValue[0] === void 0 || filterValue[1] === void 0) {
12769 return true;
12770 }
12771 const fieldValue = field.getValue({ item });
12772 if (typeof fieldValue === "number" || fieldValue instanceof Date || typeof fieldValue === "string") {
12773 return fieldValue >= filterValue[0] && fieldValue <= filterValue[1];
12774 }
12775 return false;
12776 },
12777 selection: "custom"
12778 },
12779 {
12780 name: OPERATOR_IN_THE_PAST,
12781 /* translators: DataViews operator name */
12782 label: (0, import_i18n29.__)("In the past"),
12783 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12784 (0, import_i18n29.sprintf)(
12785 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "7 days"): "Date is in the past: 7 days". */
12786 (0, import_i18n29.__)(
12787 "<Name>%1$s is in the past: </Name><Value>%2$s</Value>"
12788 ),
12789 filter.name,
12790 `${activeElements[0].value.value} ${activeElements[0].value.unit}`
12791 ),
12792 filterTextWrappers
12793 ),
12794 filter(item, field, filterValue) {
12795 if (filterValue?.value === void 0 || filterValue?.unit === void 0) {
12796 return true;
12797 }
12798 const targetDate = getRelativeDate(
12799 filterValue.value,
12800 filterValue.unit
12801 );
12802 const fieldValue = (0, import_date.getDate)(field.getValue({ item }));
12803 return fieldValue >= targetDate && fieldValue <= /* @__PURE__ */ new Date();
12804 },
12805 selection: "custom"
12806 },
12807 {
12808 name: OPERATOR_OVER,
12809 /* translators: DataViews operator name */
12810 label: (0, import_i18n29.__)("Over"),
12811 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12812 (0, import_i18n29.sprintf)(
12813 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "7 days"): "Date is over: 7 days". */
12814 (0, import_i18n29.__)("<Name>%1$s is over: </Name><Value>%2$s</Value>"),
12815 filter.name,
12816 `${activeElements[0].value.value} ${activeElements[0].value.unit}`
12817 ),
12818 filterTextWrappers
12819 ),
12820 filter(item, field, filterValue) {
12821 if (filterValue?.value === void 0 || filterValue?.unit === void 0) {
12822 return true;
12823 }
12824 const targetDate = getRelativeDate(
12825 filterValue.value,
12826 filterValue.unit
12827 );
12828 const fieldValue = (0, import_date.getDate)(field.getValue({ item }));
12829 return fieldValue < targetDate;
12830 },
12831 selection: "custom"
12832 },
12833 {
12834 name: OPERATOR_IS,
12835 /* translators: DataViews operator name */
12836 label: (0, import_i18n29.__)("Is"),
12837 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12838 (0, import_i18n29.sprintf)(
12839 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is: Admin". */
12840 (0, import_i18n29.__)("<Name>%1$s is: </Name><Value>%2$s</Value>"),
12841 filter.name,
12842 activeElements[0].label
12843 ),
12844 filterTextWrappers
12845 ),
12846 filter(item, field, filterValue) {
12847 return filterValue === field.getValue({ item }) || filterValue === void 0;
12848 },
12849 selection: "single"
12850 },
12851 {
12852 name: OPERATOR_IS_NOT,
12853 /* translators: DataViews operator name */
12854 label: (0, import_i18n29.__)("Is not"),
12855 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12856 (0, import_i18n29.sprintf)(
12857 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is not: Admin". */
12858 (0, import_i18n29.__)("<Name>%1$s is not: </Name><Value>%2$s</Value>"),
12859 filter.name,
12860 activeElements[0].label
12861 ),
12862 filterTextWrappers
12863 ),
12864 filter(item, field, filterValue) {
12865 return filterValue !== field.getValue({ item });
12866 },
12867 selection: "single"
12868 },
12869 {
12870 name: OPERATOR_LESS_THAN,
12871 /* translators: DataViews operator name */
12872 label: (0, import_i18n29.__)("Less than"),
12873 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12874 (0, import_i18n29.sprintf)(
12875 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is less than: 10". */
12876 (0, import_i18n29.__)("<Name>%1$s is less than: </Name><Value>%2$s</Value>"),
12877 filter.name,
12878 activeElements[0].label
12879 ),
12880 filterTextWrappers
12881 ),
12882 filter(item, field, filterValue) {
12883 if (filterValue === void 0) {
12884 return true;
12885 }
12886 const fieldValue = field.getValue({ item });
12887 return fieldValue < filterValue;
12888 },
12889 selection: "single"
12890 },
12891 {
12892 name: OPERATOR_GREATER_THAN,
12893 /* translators: DataViews operator name */
12894 label: (0, import_i18n29.__)("Greater than"),
12895 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12896 (0, import_i18n29.sprintf)(
12897 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is greater than: 10". */
12898 (0, import_i18n29.__)(
12899 "<Name>%1$s is greater than: </Name><Value>%2$s</Value>"
12900 ),
12901 filter.name,
12902 activeElements[0].label
12903 ),
12904 filterTextWrappers
12905 ),
12906 filter(item, field, filterValue) {
12907 if (filterValue === void 0) {
12908 return true;
12909 }
12910 const fieldValue = field.getValue({ item });
12911 return fieldValue > filterValue;
12912 },
12913 selection: "single"
12914 },
12915 {
12916 name: OPERATOR_LESS_THAN_OR_EQUAL,
12917 /* translators: DataViews operator name */
12918 label: (0, import_i18n29.__)("Less than or equal"),
12919 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12920 (0, import_i18n29.sprintf)(
12921 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is less than or equal to: 10". */
12922 (0, import_i18n29.__)(
12923 "<Name>%1$s is less than or equal to: </Name><Value>%2$s</Value>"
12924 ),
12925 filter.name,
12926 activeElements[0].label
12927 ),
12928 filterTextWrappers
12929 ),
12930 filter(item, field, filterValue) {
12931 if (filterValue === void 0) {
12932 return true;
12933 }
12934 const fieldValue = field.getValue({ item });
12935 return fieldValue <= filterValue;
12936 },
12937 selection: "single"
12938 },
12939 {
12940 name: OPERATOR_GREATER_THAN_OR_EQUAL,
12941 /* translators: DataViews operator name */
12942 label: (0, import_i18n29.__)("Greater than or equal"),
12943 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12944 (0, import_i18n29.sprintf)(
12945 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is greater than or equal to: 10". */
12946 (0, import_i18n29.__)(
12947 "<Name>%1$s is greater than or equal to: </Name><Value>%2$s</Value>"
12948 ),
12949 filter.name,
12950 activeElements[0].label
12951 ),
12952 filterTextWrappers
12953 ),
12954 filter(item, field, filterValue) {
12955 if (filterValue === void 0) {
12956 return true;
12957 }
12958 const fieldValue = field.getValue({ item });
12959 return fieldValue >= filterValue;
12960 },
12961 selection: "single"
12962 },
12963 {
12964 name: OPERATOR_BEFORE,
12965 /* translators: DataViews operator name */
12966 label: (0, import_i18n29.__)("Before"),
12967 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12968 (0, import_i18n29.sprintf)(
12969 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is before: 2024-01-01". */
12970 (0, import_i18n29.__)("<Name>%1$s is before: </Name><Value>%2$s</Value>"),
12971 filter.name,
12972 activeElements[0].label
12973 ),
12974 filterTextWrappers
12975 ),
12976 filter(item, field, filterValue) {
12977 if (filterValue === void 0) {
12978 return true;
12979 }
12980 const filterDate = (0, import_date.getDate)(filterValue);
12981 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
12982 return fieldDate < filterDate;
12983 },
12984 selection: "single"
12985 },
12986 {
12987 name: OPERATOR_AFTER,
12988 /* translators: DataViews operator name */
12989 label: (0, import_i18n29.__)("After"),
12990 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12991 (0, import_i18n29.sprintf)(
12992 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is after: 2024-01-01". */
12993 (0, import_i18n29.__)("<Name>%1$s is after: </Name><Value>%2$s</Value>"),
12994 filter.name,
12995 activeElements[0].label
12996 ),
12997 filterTextWrappers
12998 ),
12999 filter(item, field, filterValue) {
13000 if (filterValue === void 0) {
13001 return true;
13002 }
13003 const filterDate = (0, import_date.getDate)(filterValue);
13004 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13005 return fieldDate > filterDate;
13006 },
13007 selection: "single"
13008 },
13009 {
13010 name: OPERATOR_BEFORE_INC,
13011 /* translators: DataViews operator name */
13012 label: (0, import_i18n29.__)("Before (inc)"),
13013 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13014 (0, import_i18n29.sprintf)(
13015 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is on or before: 2024-01-01". */
13016 (0, import_i18n29.__)(
13017 "<Name>%1$s is on or before: </Name><Value>%2$s</Value>"
13018 ),
13019 filter.name,
13020 activeElements[0].label
13021 ),
13022 filterTextWrappers
13023 ),
13024 filter(item, field, filterValue) {
13025 if (filterValue === void 0) {
13026 return true;
13027 }
13028 const filterDate = (0, import_date.getDate)(filterValue);
13029 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13030 return fieldDate <= filterDate;
13031 },
13032 selection: "single"
13033 },
13034 {
13035 name: OPERATOR_AFTER_INC,
13036 /* translators: DataViews operator name */
13037 label: (0, import_i18n29.__)("After (inc)"),
13038 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13039 (0, import_i18n29.sprintf)(
13040 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is on or after: 2024-01-01". */
13041 (0, import_i18n29.__)(
13042 "<Name>%1$s is on or after: </Name><Value>%2$s</Value>"
13043 ),
13044 filter.name,
13045 activeElements[0].label
13046 ),
13047 filterTextWrappers
13048 ),
13049 filter(item, field, filterValue) {
13050 if (filterValue === void 0) {
13051 return true;
13052 }
13053 const filterDate = (0, import_date.getDate)(filterValue);
13054 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13055 return fieldDate >= filterDate;
13056 },
13057 selection: "single"
13058 },
13059 {
13060 name: OPERATOR_CONTAINS,
13061 /* translators: DataViews operator name */
13062 label: (0, import_i18n29.__)("Contains"),
13063 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13064 (0, import_i18n29.sprintf)(
13065 /* translators: 1: Filter name (e.g. "Title"). 2: Filter value (e.g. "Hello"): "Title contains: Hello". */
13066 (0, import_i18n29.__)("<Name>%1$s contains: </Name><Value>%2$s</Value>"),
13067 filter.name,
13068 activeElements[0].label
13069 ),
13070 filterTextWrappers
13071 ),
13072 filter(item, field, filterValue) {
13073 if (filterValue === void 0) {
13074 return true;
13075 }
13076 const fieldValue = field.getValue({ item });
13077 return typeof fieldValue === "string" && filterValue && fieldValue.toLowerCase().includes(String(filterValue).toLowerCase());
13078 },
13079 selection: "single"
13080 },
13081 {
13082 name: OPERATOR_NOT_CONTAINS,
13083 /* translators: DataViews operator name */
13084 label: (0, import_i18n29.__)("Doesn't contain"),
13085 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13086 (0, import_i18n29.sprintf)(
13087 /* translators: 1: Filter name (e.g. "Title"). 2: Filter value (e.g. "Hello"): "Title doesn't contain: Hello". */
13088 (0, import_i18n29.__)(
13089 "<Name>%1$s doesn't contain: </Name><Value>%2$s</Value>"
13090 ),
13091 filter.name,
13092 activeElements[0].label
13093 ),
13094 filterTextWrappers
13095 ),
13096 filter(item, field, filterValue) {
13097 if (filterValue === void 0) {
13098 return true;
13099 }
13100 const fieldValue = field.getValue({ item });
13101 return typeof fieldValue === "string" && filterValue && !fieldValue.toLowerCase().includes(String(filterValue).toLowerCase());
13102 },
13103 selection: "single"
13104 },
13105 {
13106 name: OPERATOR_STARTS_WITH,
13107 /* translators: DataViews operator name */
13108 label: (0, import_i18n29.__)("Starts with"),
13109 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13110 (0, import_i18n29.sprintf)(
13111 /* translators: 1: Filter name (e.g. "Title"). 2: Filter value (e.g. "Hello"): "Title starts with: Hello". */
13112 (0, import_i18n29.__)("<Name>%1$s starts with: </Name><Value>%2$s</Value>"),
13113 filter.name,
13114 activeElements[0].label
13115 ),
13116 filterTextWrappers
13117 ),
13118 filter(item, field, filterValue) {
13119 if (filterValue === void 0) {
13120 return true;
13121 }
13122 const fieldValue = field.getValue({ item });
13123 return typeof fieldValue === "string" && filterValue && fieldValue.toLowerCase().startsWith(String(filterValue).toLowerCase());
13124 },
13125 selection: "single"
13126 },
13127 {
13128 name: OPERATOR_ON,
13129 /* translators: DataViews operator name */
13130 label: (0, import_i18n29.__)("On"),
13131 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13132 (0, import_i18n29.sprintf)(
13133 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is: 2024-01-01". */
13134 (0, import_i18n29.__)("<Name>%1$s is: </Name><Value>%2$s</Value>"),
13135 filter.name,
13136 activeElements[0].label
13137 ),
13138 filterTextWrappers
13139 ),
13140 filter(item, field, filterValue) {
13141 if (filterValue === void 0) {
13142 return true;
13143 }
13144 const filterDate = (0, import_date.getDate)(filterValue);
13145 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13146 return filterDate.getTime() === fieldDate.getTime();
13147 },
13148 selection: "single"
13149 },
13150 {
13151 name: OPERATOR_NOT_ON,
13152 /* translators: DataViews operator name */
13153 label: (0, import_i18n29.__)("Not on"),
13154 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13155 (0, import_i18n29.sprintf)(
13156 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is not: 2024-01-01". */
13157 (0, import_i18n29.__)("<Name>%1$s is not: </Name><Value>%2$s</Value>"),
13158 filter.name,
13159 activeElements[0].label
13160 ),
13161 filterTextWrappers
13162 ),
13163 filter(item, field, filterValue) {
13164 if (filterValue === void 0) {
13165 return true;
13166 }
13167 const filterDate = (0, import_date.getDate)(filterValue);
13168 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13169 return filterDate.getTime() !== fieldDate.getTime();
13170 },
13171 selection: "single"
13172 }
13173 ];
13174 var getOperatorByName = (name) => OPERATORS.find((op) => op.name === name);
13175 var getAllOperatorNames = () => OPERATORS.map((op) => op.name);
13176 var isSingleSelectionOperator = (name) => OPERATORS.filter((op) => op.selection === "single").some(
13177 (op) => op.name === name
13178 );
13179 var isRegisteredOperator = (name) => OPERATORS.some((op) => op.name === name);
13180
13181 // packages/dataviews/build-module/components/dataviews-filters/filter.mjs
13182 var import_jsx_runtime65 = __toESM(require_jsx_runtime(), 1);
13183 var ENTER = "Enter";
13184 var SPACE = " ";
13185 var FilterText = ({
13186 activeElements,
13187 filterInView,
13188 filter
13189 }) => {
13190 if (activeElements === void 0 || activeElements.length === 0) {
13191 return filter.name;
13192 }
13193 const operator = getOperatorByName(filterInView?.operator);
13194 if (operator !== void 0) {
13195 return operator.filterText(filter, activeElements);
13196 }
13197 return (0, import_i18n30.sprintf)(
13198 /* translators: 1: Filter name e.g.: "Unknown status for Author". */
13199 (0, import_i18n30.__)("Unknown status for %1$s"),
13200 filter.name
13201 );
13202 };
13203 function OperatorSelector({
13204 filter,
13205 view,
13206 onChangeView
13207 }) {
13208 const operatorOptions = filter.operators?.map((operator) => ({
13209 value: operator,
13210 label: getOperatorByName(operator)?.label || operator
13211 }));
13212 const currentFilter = view.filters?.find(
13213 (_filter) => _filter.field === filter.field
13214 );
13215 const value = currentFilter?.operator || filter.operators[0];
13216 return operatorOptions.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)(
13217 Stack,
13218 {
13219 direction: "row",
13220 gap: "sm",
13221 justify: "flex-start",
13222 className: "dataviews-filters__summary-operators-container",
13223 align: "center",
13224 children: [
13225 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(import_components20.FlexItem, { className: "dataviews-filters__summary-operators-filter-name", children: filter.name }),
13226 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13227 import_components20.SelectControl,
13228 {
13229 className: "dataviews-filters__summary-operators-filter-select",
13230 label: (0, import_i18n30.__)("Conditions"),
13231 value,
13232 options: operatorOptions,
13233 onChange: (newValue) => {
13234 const newOperator = newValue;
13235 const currentOperator = currentFilter?.operator;
13236 const newFilters = currentFilter ? [
13237 ...(view.filters ?? []).map(
13238 (_filter) => {
13239 if (_filter.field === filter.field) {
13240 const currentOpSelectionModel = getOperatorByName(
13241 currentOperator
13242 )?.selection;
13243 const newOpSelectionModel = getOperatorByName(
13244 newOperator
13245 )?.selection;
13246 const shouldResetValue = currentOpSelectionModel !== newOpSelectionModel || [
13247 currentOpSelectionModel,
13248 newOpSelectionModel
13249 ].includes("custom");
13250 return {
13251 ..._filter,
13252 value: shouldResetValue ? void 0 : _filter.value,
13253 operator: newOperator
13254 };
13255 }
13256 return _filter;
13257 }
13258 )
13259 ] : [
13260 ...view.filters ?? [],
13261 {
13262 field: filter.field,
13263 operator: newOperator,
13264 value: void 0
13265 }
13266 ];
13267 onChangeView({
13268 ...view,
13269 page: 1,
13270 filters: newFilters
13271 });
13272 },
13273 size: "small",
13274 variant: "minimal",
13275 hideLabelFromVision: true
13276 }
13277 )
13278 ]
13279 }
13280 );
13281 }
13282 function Filter({
13283 addFilterRef,
13284 openedFilter,
13285 fields,
13286 ...commonProps
13287 }) {
13288 const toggleRef = (0, import_element30.useRef)(null);
13289 const { filter, view, onChangeView } = commonProps;
13290 const filterInView = view.filters?.find(
13291 (f2) => f2.field === filter.field
13292 );
13293 let activeElements = [];
13294 const field = (0, import_element30.useMemo)(() => {
13295 const currentField = fields.find((f2) => f2.id === filter.field);
13296 if (currentField) {
13297 return {
13298 ...currentField,
13299 // Configure getValue as if Item was a plain object.
13300 // See related input-widget.tsx
13301 getValue: ({ item }) => item[currentField.id]
13302 };
13303 }
13304 return currentField;
13305 }, [fields, filter.field]);
13306 const { elements } = useElements({
13307 elements: filter.elements,
13308 getElements: filter.getElements
13309 });
13310 if (elements.length > 0) {
13311 activeElements = elements.filter((element) => {
13312 if (filter.singleSelection) {
13313 return element.value === filterInView?.value;
13314 }
13315 return filterInView?.value?.includes(element.value);
13316 });
13317 } else if (Array.isArray(filterInView?.value)) {
13318 const label = filterInView.value.map((v2) => {
13319 const formattedValue = field?.getValueFormatted({
13320 item: { [field.id]: v2 },
13321 field
13322 });
13323 return formattedValue || String(v2);
13324 });
13325 activeElements = [
13326 {
13327 value: filterInView.value,
13328 // @ts-ignore
13329 label
13330 }
13331 ];
13332 } else if (typeof filterInView?.value === "object") {
13333 activeElements = [
13334 { value: filterInView.value, label: filterInView.value }
13335 ];
13336 } else if (filterInView?.value !== void 0) {
13337 const label = field !== void 0 ? field.getValueFormatted({
13338 item: { [field.id]: filterInView.value },
13339 field
13340 }) : String(filterInView.value);
13341 activeElements = [
13342 {
13343 value: filterInView.value,
13344 label
13345 }
13346 ];
13347 }
13348 const isPrimary = filter.isPrimary;
13349 const isLocked = filterInView?.isLocked;
13350 const hasValues = !isLocked && filterInView?.value !== void 0;
13351 const canResetOrRemove = !isLocked && (!isPrimary || hasValues);
13352 return /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13353 import_components20.Dropdown,
13354 {
13355 defaultOpen: openedFilter === filter.field,
13356 contentClassName: "dataviews-filters__summary-popover",
13357 popoverProps: { placement: "bottom-start", role: "dialog" },
13358 onClose: () => {
13359 toggleRef.current?.focus();
13360 },
13361 renderToggle: ({ isOpen, onToggle }) => /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)("div", { className: "dataviews-filters__summary-chip-container", children: [
13362 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13363 import_components20.Tooltip,
13364 {
13365 text: (0, import_i18n30.sprintf)(
13366 /* translators: 1: Filter name. */
13367 (0, import_i18n30.__)("Filter by: %1$s"),
13368 filter.name.toLowerCase()
13369 ),
13370 placement: "top",
13371 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13372 "div",
13373 {
13374 className: clsx_default(
13375 "dataviews-filters__summary-chip",
13376 {
13377 "has-reset": canResetOrRemove,
13378 "has-values": hasValues,
13379 "is-not-clickable": isLocked
13380 }
13381 ),
13382 role: "button",
13383 tabIndex: isLocked ? -1 : 0,
13384 onClick: () => {
13385 if (!isLocked) {
13386 onToggle();
13387 }
13388 },
13389 onKeyDown: (event) => {
13390 if (!isLocked && [ENTER, SPACE].includes(event.key)) {
13391 onToggle();
13392 event.preventDefault();
13393 }
13394 },
13395 "aria-disabled": isLocked,
13396 "aria-pressed": isOpen,
13397 "aria-expanded": isOpen,
13398 ref: toggleRef,
13399 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13400 FilterText,
13401 {
13402 activeElements,
13403 filterInView,
13404 filter
13405 }
13406 )
13407 }
13408 )
13409 }
13410 ),
13411 canResetOrRemove && /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13412 import_components20.Tooltip,
13413 {
13414 text: isPrimary ? (0, import_i18n30.__)("Reset") : (0, import_i18n30.__)("Remove"),
13415 placement: "top",
13416 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13417 "button",
13418 {
13419 className: clsx_default(
13420 "dataviews-filters__summary-chip-remove",
13421 { "has-values": hasValues }
13422 ),
13423 onClick: () => {
13424 onChangeView({
13425 ...view,
13426 page: 1,
13427 filters: view.filters?.filter(
13428 (_filter) => _filter.field !== filter.field
13429 )
13430 });
13431 if (!isPrimary) {
13432 addFilterRef.current?.focus();
13433 } else {
13434 toggleRef.current?.focus();
13435 }
13436 },
13437 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(import_components20.Icon, { icon: close_small_default })
13438 }
13439 )
13440 }
13441 )
13442 ] }),
13443 renderContent: () => {
13444 return /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)(Stack, { direction: "column", justify: "flex-start", children: [
13445 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(OperatorSelector, { ...commonProps }),
13446 commonProps.filter.hasElements ? /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13447 SearchWidget,
13448 {
13449 ...commonProps,
13450 filter: {
13451 ...commonProps.filter,
13452 elements
13453 }
13454 }
13455 ) : /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(InputWidget, { ...commonProps, fields })
13456 ] });
13457 }
13458 }
13459 );
13460 }
13461
13462 // packages/dataviews/build-module/components/dataviews-filters/add-filter.mjs
13463 var import_components21 = __toESM(require_components(), 1);
13464 var import_i18n31 = __toESM(require_i18n(), 1);
13465 var import_element31 = __toESM(require_element(), 1);
13466 var import_jsx_runtime66 = __toESM(require_jsx_runtime(), 1);
13467 var { Menu: Menu4 } = unlock(import_components21.privateApis);
13468 function AddFilterMenu({
13469 filters,
13470 view,
13471 onChangeView,
13472 setOpenedFilter,
13473 triggerProps
13474 }) {
13475 const inactiveFilters = filters.filter((filter) => !filter.isVisible);
13476 return /* @__PURE__ */ (0, import_jsx_runtime66.jsxs)(Menu4, { children: [
13477 /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(Menu4.TriggerButton, { ...triggerProps }),
13478 /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(Menu4.Popover, { children: inactiveFilters.map((filter) => {
13479 return /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
13480 Menu4.Item,
13481 {
13482 onClick: () => {
13483 setOpenedFilter(filter.field);
13484 onChangeView({
13485 ...view,
13486 page: 1,
13487 filters: [
13488 ...view.filters || [],
13489 {
13490 field: filter.field,
13491 value: void 0,
13492 operator: filter.operators[0]
13493 }
13494 ]
13495 });
13496 },
13497 children: /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(Menu4.ItemLabel, { children: filter.name })
13498 },
13499 filter.field
13500 );
13501 }) })
13502 ] });
13503 }
13504 function AddFilter({ filters, view, onChangeView, setOpenedFilter }, ref) {
13505 if (!filters.length || filters.every(({ isPrimary }) => isPrimary)) {
13506 return null;
13507 }
13508 const inactiveFilters = filters.filter((filter) => !filter.isVisible);
13509 return /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
13510 AddFilterMenu,
13511 {
13512 triggerProps: {
13513 render: /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
13514 import_components21.Button,
13515 {
13516 accessibleWhenDisabled: true,
13517 size: "compact",
13518 className: "dataviews-filters-button",
13519 variant: "tertiary",
13520 disabled: !inactiveFilters.length,
13521 ref
13522 }
13523 ),
13524 children: (0, import_i18n31.__)("Add filter")
13525 },
13526 ...{ filters, view, onChangeView, setOpenedFilter }
13527 }
13528 );
13529 }
13530 var add_filter_default = (0, import_element31.forwardRef)(AddFilter);
13531
13532 // packages/dataviews/build-module/components/dataviews-filters/reset-filters.mjs
13533 var import_components22 = __toESM(require_components(), 1);
13534 var import_i18n32 = __toESM(require_i18n(), 1);
13535 var import_jsx_runtime67 = __toESM(require_jsx_runtime(), 1);
13536 function ResetFilter({
13537 filters,
13538 view,
13539 onChangeView
13540 }) {
13541 const isPrimary = (field) => filters.some(
13542 (_filter) => _filter.field === field && _filter.isPrimary
13543 );
13544 const isDisabled = !view.search && !view.filters?.some(
13545 (_filter) => !_filter.isLocked && (_filter.value !== void 0 || !isPrimary(_filter.field))
13546 );
13547 return /* @__PURE__ */ (0, import_jsx_runtime67.jsx)(
13548 import_components22.Button,
13549 {
13550 disabled: isDisabled,
13551 accessibleWhenDisabled: true,
13552 size: "compact",
13553 variant: "tertiary",
13554 className: "dataviews-filters__reset-button",
13555 onClick: () => {
13556 onChangeView({
13557 ...view,
13558 page: 1,
13559 search: "",
13560 filters: view.filters?.filter((f2) => !!f2.isLocked) || []
13561 });
13562 },
13563 children: (0, import_i18n32.__)("Reset")
13564 }
13565 );
13566 }
13567
13568 // packages/dataviews/build-module/components/dataviews-filters/use-filters.mjs
13569 var import_element32 = __toESM(require_element(), 1);
13570 function useFilters(fields, view) {
13571 return (0, import_element32.useMemo)(() => {
13572 const filters = [];
13573 fields.forEach((field) => {
13574 if (field.filterBy === false || !field.hasElements && !field.Edit) {
13575 return;
13576 }
13577 const operators = field.filterBy.operators;
13578 const isPrimary = !!field.filterBy?.isPrimary;
13579 const isLocked = view.filters?.some(
13580 (f2) => f2.field === field.id && !!f2.isLocked
13581 ) ?? false;
13582 filters.push({
13583 field: field.id,
13584 name: field.label,
13585 elements: field.elements,
13586 getElements: field.getElements,
13587 hasElements: field.hasElements,
13588 singleSelection: operators.some(
13589 (op) => isSingleSelectionOperator(op)
13590 ),
13591 operators,
13592 isVisible: isLocked || isPrimary || !!view.filters?.some(
13593 (f2) => f2.field === field.id && isRegisteredOperator(f2.operator)
13594 ),
13595 isPrimary,
13596 isLocked
13597 });
13598 });
13599 filters.sort((a2, b2) => {
13600 if (a2.isLocked && !b2.isLocked) {
13601 return -1;
13602 }
13603 if (!a2.isLocked && b2.isLocked) {
13604 return 1;
13605 }
13606 if (a2.isPrimary && !b2.isPrimary) {
13607 return -1;
13608 }
13609 if (!a2.isPrimary && b2.isPrimary) {
13610 return 1;
13611 }
13612 return a2.name.localeCompare(b2.name);
13613 });
13614 return filters;
13615 }, [fields, view]);
13616 }
13617 var use_filters_default = useFilters;
13618
13619 // packages/dataviews/build-module/components/dataviews-filters/filters.mjs
13620 var import_jsx_runtime68 = __toESM(require_jsx_runtime(), 1);
13621 function Filters({ className }) {
13622 const { fields, view, onChangeView, openedFilter, setOpenedFilter } = (0, import_element33.useContext)(dataviews_context_default);
13623 const addFilterRef = (0, import_element33.useRef)(null);
13624 const filters = use_filters_default(fields, view);
13625 const addFilter = /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13626 add_filter_default,
13627 {
13628 filters,
13629 view,
13630 onChangeView,
13631 ref: addFilterRef,
13632 setOpenedFilter
13633 },
13634 "add-filter"
13635 );
13636 const visibleFilters = filters.filter((filter) => filter.isVisible);
13637 if (visibleFilters.length === 0) {
13638 return null;
13639 }
13640 const filterComponents = [
13641 ...visibleFilters.map((filter) => {
13642 return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13643 Filter,
13644 {
13645 filter,
13646 view,
13647 fields,
13648 onChangeView,
13649 addFilterRef,
13650 openedFilter
13651 },
13652 filter.field
13653 );
13654 }),
13655 addFilter
13656 ];
13657 filterComponents.push(
13658 /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13659 ResetFilter,
13660 {
13661 filters,
13662 view,
13663 onChangeView
13664 },
13665 "reset-filters"
13666 )
13667 );
13668 return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13669 Stack,
13670 {
13671 direction: "row",
13672 justify: "flex-start",
13673 gap: "sm",
13674 style: { width: "fit-content" },
13675 wrap: "wrap",
13676 className,
13677 children: filterComponents
13678 }
13679 );
13680 }
13681 var filters_default = (0, import_element33.memo)(Filters);
13682
13683 // packages/dataviews/build-module/components/dataviews-filters/toggle.mjs
13684 var import_element34 = __toESM(require_element(), 1);
13685 var import_components23 = __toESM(require_components(), 1);
13686 var import_i18n33 = __toESM(require_i18n(), 1);
13687 var import_jsx_runtime69 = __toESM(require_jsx_runtime(), 1);
13688 function FiltersToggle() {
13689 const {
13690 filters,
13691 view,
13692 onChangeView,
13693 setOpenedFilter,
13694 isShowingFilter,
13695 setIsShowingFilter
13696 } = (0, import_element34.useContext)(dataviews_context_default);
13697 const buttonRef = (0, import_element34.useRef)(null);
13698 const onChangeViewWithFilterVisibility = (0, import_element34.useCallback)(
13699 (_view) => {
13700 onChangeView(_view);
13701 setIsShowingFilter(true);
13702 },
13703 [onChangeView, setIsShowingFilter]
13704 );
13705 if (filters.length === 0) {
13706 return null;
13707 }
13708 const hasVisibleFilters = filters.some((filter) => filter.isVisible);
13709 const addFilterButtonProps = {
13710 label: (0, import_i18n33.__)("Add filter"),
13711 "aria-expanded": false,
13712 isPressed: false
13713 };
13714 const toggleFiltersButtonProps = {
13715 label: (0, import_i18n33._x)("Filter", "verb"),
13716 "aria-expanded": isShowingFilter,
13717 isPressed: isShowingFilter,
13718 onClick: () => {
13719 if (!isShowingFilter) {
13720 setOpenedFilter(null);
13721 }
13722 setIsShowingFilter(!isShowingFilter);
13723 }
13724 };
13725 const hasPrimaryOrLockedFilters = filters.some(
13726 (filter) => filter.isPrimary || filter.isLocked
13727 );
13728 const buttonComponent = /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
13729 import_components23.Button,
13730 {
13731 ref: buttonRef,
13732 className: "dataviews-filters__visibility-toggle",
13733 size: "compact",
13734 icon: funnel_default,
13735 disabled: hasPrimaryOrLockedFilters,
13736 accessibleWhenDisabled: true,
13737 ...hasVisibleFilters ? toggleFiltersButtonProps : addFilterButtonProps
13738 }
13739 );
13740 return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)("div", { className: "dataviews-filters__container-visibility-toggle", children: !hasVisibleFilters ? /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
13741 AddFilterMenu,
13742 {
13743 filters,
13744 view,
13745 onChangeView: onChangeViewWithFilterVisibility,
13746 setOpenedFilter,
13747 triggerProps: { render: buttonComponent }
13748 }
13749 ) : /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
13750 FilterVisibilityToggle,
13751 {
13752 buttonRef,
13753 filtersCount: view.filters?.length,
13754 children: buttonComponent
13755 }
13756 ) });
13757 }
13758 function FilterVisibilityToggle({
13759 buttonRef,
13760 filtersCount,
13761 children
13762 }) {
13763 (0, import_element34.useEffect)(
13764 () => () => {
13765 buttonRef.current?.focus();
13766 },
13767 [buttonRef]
13768 );
13769 return /* @__PURE__ */ (0, import_jsx_runtime69.jsxs)(import_jsx_runtime69.Fragment, { children: [
13770 children,
13771 !!filtersCount && /* @__PURE__ */ (0, import_jsx_runtime69.jsx)("span", { className: "dataviews-filters-toggle__count", children: filtersCount })
13772 ] });
13773 }
13774 var toggle_default = FiltersToggle;
13775
13776 // packages/dataviews/build-module/components/dataviews-filters/filters-toggled.mjs
13777 var import_element35 = __toESM(require_element(), 1);
13778 var import_jsx_runtime70 = __toESM(require_jsx_runtime(), 1);
13779 function FiltersToggled(props) {
13780 const { isShowingFilter } = (0, import_element35.useContext)(dataviews_context_default);
13781 if (!isShowingFilter) {
13782 return null;
13783 }
13784 return /* @__PURE__ */ (0, import_jsx_runtime70.jsx)(filters_default, { ...props });
13785 }
13786 var filters_toggled_default = FiltersToggled;
13787
13788 // packages/dataviews/build-module/components/dataviews-layout/index.mjs
13789 var import_element36 = __toESM(require_element(), 1);
13790 var import_components24 = __toESM(require_components(), 1);
13791 var import_i18n34 = __toESM(require_i18n(), 1);
13792 var import_jsx_runtime71 = __toESM(require_jsx_runtime(), 1);
13793 function DataViewsLayout({ className }) {
13794 const {
13795 actions = [],
13796 data,
13797 fields,
13798 getItemId,
13799 getItemLevel,
13800 hasInitiallyLoaded,
13801 isLoading,
13802 view,
13803 onChangeView,
13804 selection,
13805 onChangeSelection,
13806 setOpenedFilter,
13807 onClickItem,
13808 isItemClickable: isItemClickable2,
13809 renderItemLink,
13810 defaultLayouts: defaultLayouts2,
13811 containerRef,
13812 empty = /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("p", { children: (0, import_i18n34.__)("No results") })
13813 } = (0, import_element36.useContext)(dataviews_context_default);
13814 const isDelayedInitialLoading = useDelayedLoading(!hasInitiallyLoaded, {
13815 delay: 200
13816 });
13817 if (!hasInitiallyLoaded) {
13818 if (!isDelayedInitialLoading) {
13819 return null;
13820 }
13821 return /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("div", { className: "dataviews-loading", children: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(import_components24.Spinner, {}) }) });
13822 }
13823 const ViewComponent = VIEW_LAYOUTS.find(
13824 (v2) => v2.type === view.type && defaultLayouts2[v2.type]
13825 )?.component;
13826 return /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("div", { className: "dataviews-layout__container", ref: containerRef, children: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(
13827 ViewComponent,
13828 {
13829 className,
13830 actions,
13831 data,
13832 fields,
13833 getItemId,
13834 getItemLevel,
13835 isLoading,
13836 onChangeView,
13837 onChangeSelection,
13838 selection,
13839 setOpenedFilter,
13840 onClickItem,
13841 renderItemLink,
13842 isItemClickable: isItemClickable2,
13843 view,
13844 empty
13845 }
13846 ) });
13847 }
13848
13849 // packages/dataviews/build-module/components/dataviews-search/index.mjs
13850 var import_i18n35 = __toESM(require_i18n(), 1);
13851 var import_element37 = __toESM(require_element(), 1);
13852 var import_components25 = __toESM(require_components(), 1);
13853 var import_compose9 = __toESM(require_compose(), 1);
13854 var import_jsx_runtime72 = __toESM(require_jsx_runtime(), 1);
13855 var DataViewsSearch = (0, import_element37.memo)(function Search({ label }) {
13856 const { view, onChangeView } = (0, import_element37.useContext)(dataviews_context_default);
13857 const [search, setSearch, debouncedSearch] = (0, import_compose9.useDebouncedInput)(
13858 view.search
13859 );
13860 (0, import_element37.useEffect)(() => {
13861 if (view.search !== debouncedSearch) {
13862 setSearch(view.search ?? "");
13863 }
13864 }, [view.search, setSearch]);
13865 const onChangeViewRef = (0, import_element37.useRef)(onChangeView);
13866 const viewRef = (0, import_element37.useRef)(view);
13867 (0, import_element37.useEffect)(() => {
13868 onChangeViewRef.current = onChangeView;
13869 viewRef.current = view;
13870 }, [onChangeView, view]);
13871 (0, import_element37.useEffect)(() => {
13872 if (debouncedSearch !== viewRef.current?.search) {
13873 onChangeViewRef.current({
13874 ...viewRef.current,
13875 page: view.page ? 1 : void 0,
13876 startPosition: view.startPosition ? 1 : void 0,
13877 search: debouncedSearch
13878 });
13879 }
13880 }, [debouncedSearch]);
13881 const searchLabel = label || (0, import_i18n35.__)("Search");
13882 return /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
13883 import_components25.SearchControl,
13884 {
13885 className: "dataviews-search",
13886 onChange: setSearch,
13887 value: search,
13888 label: searchLabel,
13889 placeholder: searchLabel,
13890 size: "compact"
13891 }
13892 );
13893 });
13894 var dataviews_search_default = DataViewsSearch;
13895
13896 // packages/dataviews/build-module/components/dataviews-view-config/index.mjs
13897 var import_components26 = __toESM(require_components(), 1);
13898 var import_i18n36 = __toESM(require_i18n(), 1);
13899 var import_element38 = __toESM(require_element(), 1);
13900 var import_warning = __toESM(require_warning(), 1);
13901 var import_compose10 = __toESM(require_compose(), 1);
13902 var import_jsx_runtime73 = __toESM(require_jsx_runtime(), 1);
13903 var { Menu: Menu5 } = unlock(import_components26.privateApis);
13904 var DATAVIEWS_CONFIG_POPOVER_PROPS = {
13905 className: "dataviews-config__popover",
13906 placement: "bottom-end",
13907 offset: 9
13908 };
13909 function ViewTypeMenu() {
13910 const { view, onChangeView, defaultLayouts: defaultLayouts2 } = (0, import_element38.useContext)(dataviews_context_default);
13911 const availableLayouts = Object.keys(defaultLayouts2);
13912 if (availableLayouts.length <= 1) {
13913 return null;
13914 }
13915 const activeView = VIEW_LAYOUTS.find((v2) => view.type === v2.type);
13916 return /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(Menu5, { children: [
13917 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
13918 Menu5.TriggerButton,
13919 {
13920 render: /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
13921 import_components26.Button,
13922 {
13923 size: "compact",
13924 icon: activeView?.icon,
13925 label: (0, import_i18n36.__)("Layout")
13926 }
13927 )
13928 }
13929 ),
13930 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(Menu5.Popover, { children: availableLayouts.map((layout) => {
13931 const config = VIEW_LAYOUTS.find(
13932 (v2) => v2.type === layout
13933 );
13934 if (!config) {
13935 return null;
13936 }
13937 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
13938 Menu5.RadioItem,
13939 {
13940 value: layout,
13941 name: "view-actions-available-view",
13942 checked: layout === view.type,
13943 hideOnClick: true,
13944 onChange: (e2) => {
13945 switch (e2.target.value) {
13946 case "list":
13947 case "grid":
13948 case "table":
13949 case "pickerGrid":
13950 case "pickerTable":
13951 case "activity":
13952 const viewWithoutLayout = { ...view };
13953 if ("layout" in viewWithoutLayout) {
13954 delete viewWithoutLayout.layout;
13955 }
13956 return onChangeView({
13957 ...viewWithoutLayout,
13958 type: e2.target.value,
13959 ...defaultLayouts2[e2.target.value]
13960 });
13961 }
13962 (0, import_warning.default)("Invalid dataview");
13963 },
13964 children: /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(Menu5.ItemLabel, { children: config.label })
13965 },
13966 layout
13967 );
13968 }) })
13969 ] });
13970 }
13971 function SortFieldControl() {
13972 const { view, fields, onChangeView } = (0, import_element38.useContext)(dataviews_context_default);
13973 const orderOptions = (0, import_element38.useMemo)(() => {
13974 const sortableFields = fields.filter(
13975 (field) => field.enableSorting !== false
13976 );
13977 return sortableFields.map((field) => {
13978 return {
13979 label: field.label,
13980 value: field.id
13981 };
13982 });
13983 }, [fields]);
13984 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
13985 import_components26.SelectControl,
13986 {
13987 __next40pxDefaultSize: true,
13988 label: (0, import_i18n36.__)("Sort by"),
13989 value: view.sort?.field,
13990 options: orderOptions,
13991 onChange: (value) => {
13992 onChangeView({
13993 ...view,
13994 sort: {
13995 direction: view?.sort?.direction || "desc",
13996 field: value
13997 },
13998 showLevels: false
13999 });
14000 }
14001 }
14002 );
14003 }
14004 function SortDirectionControl() {
14005 const { view, fields, onChangeView } = (0, import_element38.useContext)(dataviews_context_default);
14006 const sortableFields = fields.filter(
14007 (field) => field.enableSorting !== false
14008 );
14009 if (sortableFields.length === 0) {
14010 return null;
14011 }
14012 let value = view.sort?.direction;
14013 if (!value && view.sort?.field) {
14014 value = "desc";
14015 }
14016 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14017 import_components26.__experimentalToggleGroupControl,
14018 {
14019 className: "dataviews-view-config__sort-direction",
14020 __next40pxDefaultSize: true,
14021 isBlock: true,
14022 label: (0, import_i18n36.__)("Order"),
14023 value,
14024 onChange: (newDirection) => {
14025 if (newDirection === "asc" || newDirection === "desc") {
14026 onChangeView({
14027 ...view,
14028 sort: {
14029 direction: newDirection,
14030 field: view.sort?.field || // If there is no field assigned as the sorting field assign the first sortable field.
14031 fields.find(
14032 (field) => field.enableSorting !== false
14033 )?.id || ""
14034 },
14035 showLevels: false
14036 });
14037 return;
14038 }
14039 (0, import_warning.default)("Invalid direction");
14040 },
14041 children: SORTING_DIRECTIONS.map((direction) => {
14042 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14043 import_components26.__experimentalToggleGroupControlOptionIcon,
14044 {
14045 value: direction,
14046 icon: sortIcons[direction],
14047 label: sortLabels[direction]
14048 },
14049 direction
14050 );
14051 })
14052 }
14053 );
14054 }
14055 function ItemsPerPageControl() {
14056 const { view, config, onChangeView } = (0, import_element38.useContext)(dataviews_context_default);
14057 const { infiniteScrollEnabled } = view;
14058 if (!config || !config.perPageSizes || config.perPageSizes.length < 2 || config.perPageSizes.length > 6 || infiniteScrollEnabled) {
14059 return null;
14060 }
14061 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14062 import_components26.__experimentalToggleGroupControl,
14063 {
14064 __next40pxDefaultSize: true,
14065 isBlock: true,
14066 label: (0, import_i18n36.__)("Items per page"),
14067 value: view.perPage || 10,
14068 disabled: !view?.sort?.field,
14069 onChange: (newItemsPerPage) => {
14070 const newItemsPerPageNumber = typeof newItemsPerPage === "number" || newItemsPerPage === void 0 ? newItemsPerPage : parseInt(newItemsPerPage, 10);
14071 onChangeView({
14072 ...view,
14073 perPage: newItemsPerPageNumber,
14074 page: 1
14075 });
14076 },
14077 children: config.perPageSizes.map((value) => {
14078 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14079 import_components26.__experimentalToggleGroupControlOption,
14080 {
14081 value,
14082 label: value.toString()
14083 },
14084 value
14085 );
14086 })
14087 }
14088 );
14089 }
14090 function ResetViewButton() {
14091 const { onReset } = (0, import_element38.useContext)(dataviews_context_default);
14092 if (onReset === void 0) {
14093 return null;
14094 }
14095 const isDisabled = onReset === false;
14096 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14097 import_components26.Button,
14098 {
14099 variant: "tertiary",
14100 size: "compact",
14101 disabled: isDisabled,
14102 accessibleWhenDisabled: true,
14103 className: "dataviews-view-config__reset-button",
14104 onClick: () => {
14105 if (typeof onReset === "function") {
14106 onReset();
14107 }
14108 },
14109 children: (0, import_i18n36.__)("Reset view")
14110 }
14111 );
14112 }
14113 function DataviewsViewConfigDropdown() {
14114 const { view, onReset } = (0, import_element38.useContext)(dataviews_context_default);
14115 const popoverId = (0, import_compose10.useInstanceId)(
14116 _DataViewsViewConfig,
14117 "dataviews-view-config-dropdown"
14118 );
14119 const activeLayout = VIEW_LAYOUTS.find(
14120 (layout) => layout.type === view.type
14121 );
14122 const isModified = typeof onReset === "function";
14123 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14124 import_components26.Dropdown,
14125 {
14126 expandOnMobile: true,
14127 popoverProps: {
14128 ...DATAVIEWS_CONFIG_POPOVER_PROPS,
14129 id: popoverId
14130 },
14131 renderToggle: ({ onToggle, isOpen }) => {
14132 return /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)("div", { className: "dataviews-view-config__toggle-wrapper", children: [
14133 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14134 import_components26.Button,
14135 {
14136 size: "compact",
14137 icon: cog_default,
14138 label: (0, import_i18n36._x)(
14139 "View options",
14140 "View is used as a noun"
14141 ),
14142 onClick: onToggle,
14143 "aria-expanded": isOpen ? "true" : "false",
14144 "aria-controls": popoverId
14145 }
14146 ),
14147 isModified && /* @__PURE__ */ (0, import_jsx_runtime73.jsx)("span", { className: "dataviews-view-config__modified-indicator" })
14148 ] });
14149 },
14150 renderContent: () => /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14151 import_components26.__experimentalDropdownContentWrapper,
14152 {
14153 paddingSize: "medium",
14154 className: "dataviews-config__popover-content-wrapper",
14155 children: /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
14156 Stack,
14157 {
14158 direction: "column",
14159 className: "dataviews-view-config",
14160 gap: "xl",
14161 children: [
14162 /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
14163 Stack,
14164 {
14165 direction: "row",
14166 justify: "space-between",
14167 align: "center",
14168 className: "dataviews-view-config__header",
14169 children: [
14170 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14171 import_components26.__experimentalHeading,
14172 {
14173 level: 2,
14174 className: "dataviews-settings-section__title",
14175 children: (0, import_i18n36.__)("Appearance")
14176 }
14177 ),
14178 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(ResetViewButton, {})
14179 ]
14180 }
14181 ),
14182 /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(Stack, { direction: "column", gap: "lg", children: [
14183 /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
14184 Stack,
14185 {
14186 direction: "row",
14187 gap: "sm",
14188 className: "dataviews-view-config__sort-controls",
14189 children: [
14190 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(SortFieldControl, {}),
14191 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(SortDirectionControl, {})
14192 ]
14193 }
14194 ),
14195 !!activeLayout?.viewConfigOptions && /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(activeLayout.viewConfigOptions, {}),
14196 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(ItemsPerPageControl, {}),
14197 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(PropertiesSection, {})
14198 ] })
14199 ]
14200 }
14201 )
14202 }
14203 )
14204 }
14205 );
14206 }
14207 function _DataViewsViewConfig() {
14208 return /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(import_jsx_runtime73.Fragment, { children: [
14209 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(ViewTypeMenu, {}),
14210 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(DataviewsViewConfigDropdown, {})
14211 ] });
14212 }
14213 var DataViewsViewConfig = (0, import_element38.memo)(_DataViewsViewConfig);
14214 var dataviews_view_config_default = DataViewsViewConfig;
14215
14216 // packages/dataviews/build-module/components/dataform-controls/checkbox.mjs
14217 var import_components27 = __toESM(require_components(), 1);
14218 var import_element39 = __toESM(require_element(), 1);
14219
14220 // packages/dataviews/build-module/components/dataform-controls/utils/get-custom-validity.mjs
14221 function getCustomValidity(isValid2, validity) {
14222 let customValidity;
14223 if (isValid2?.required && validity?.required) {
14224 customValidity = validity?.required?.message ? validity.required : void 0;
14225 } else if (isValid2?.pattern && validity?.pattern) {
14226 customValidity = validity.pattern;
14227 } else if (isValid2?.min && validity?.min) {
14228 customValidity = validity.min;
14229 } else if (isValid2?.max && validity?.max) {
14230 customValidity = validity.max;
14231 } else if (isValid2?.minLength && validity?.minLength) {
14232 customValidity = validity.minLength;
14233 } else if (isValid2?.maxLength && validity?.maxLength) {
14234 customValidity = validity.maxLength;
14235 } else if (isValid2?.elements && validity?.elements) {
14236 customValidity = validity.elements;
14237 } else if (validity?.custom) {
14238 customValidity = validity.custom;
14239 }
14240 return customValidity;
14241 }
14242
14243 // packages/dataviews/build-module/components/dataform-controls/checkbox.mjs
14244 var import_jsx_runtime74 = __toESM(require_jsx_runtime(), 1);
14245 var { ValidatedCheckboxControl } = unlock(import_components27.privateApis);
14246 function Checkbox({
14247 field,
14248 onChange,
14249 data,
14250 hideLabelFromVision,
14251 markWhenOptional,
14252 validity
14253 }) {
14254 const { getValue, setValue, label, description, isValid: isValid2 } = field;
14255 const disabled = field.isDisabled({ item: data, field });
14256 const onChangeControl = (0, import_element39.useCallback)(() => {
14257 onChange(
14258 setValue({ item: data, value: !getValue({ item: data }) })
14259 );
14260 }, [data, getValue, onChange, setValue]);
14261 return /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(
14262 ValidatedCheckboxControl,
14263 {
14264 required: !!field.isValid?.required,
14265 markWhenOptional,
14266 customValidity: getCustomValidity(isValid2, validity),
14267 hidden: hideLabelFromVision,
14268 label,
14269 help: description,
14270 checked: getValue({ item: data }),
14271 onChange: onChangeControl,
14272 disabled
14273 }
14274 );
14275 }
14276
14277 // packages/dataviews/build-module/components/dataform-controls/combobox.mjs
14278 var import_components28 = __toESM(require_components(), 1);
14279 var import_element40 = __toESM(require_element(), 1);
14280 var import_jsx_runtime75 = __toESM(require_jsx_runtime(), 1);
14281 var { ValidatedComboboxControl } = unlock(import_components28.privateApis);
14282 function Combobox3({
14283 data,
14284 field,
14285 onChange,
14286 hideLabelFromVision,
14287 validity
14288 }) {
14289 const { label, description, placeholder, getValue, setValue, isValid: isValid2 } = field;
14290 const value = getValue({ item: data }) ?? "";
14291 const onChangeControl = (0, import_element40.useCallback)(
14292 (newValue) => onChange(setValue({ item: data, value: newValue ?? "" })),
14293 [data, onChange, setValue]
14294 );
14295 const { elements, isLoading } = useElements({
14296 elements: field.elements,
14297 getElements: field.getElements
14298 });
14299 if (isLoading) {
14300 return /* @__PURE__ */ (0, import_jsx_runtime75.jsx)(import_components28.Spinner, {});
14301 }
14302 return /* @__PURE__ */ (0, import_jsx_runtime75.jsx)(
14303 ValidatedComboboxControl,
14304 {
14305 required: !!field.isValid?.required,
14306 customValidity: getCustomValidity(isValid2, validity),
14307 label,
14308 value,
14309 help: description,
14310 placeholder,
14311 options: elements,
14312 onChange: onChangeControl,
14313 hideLabelFromVision,
14314 allowReset: true,
14315 expandOnFocus: true
14316 }
14317 );
14318 }
14319
14320 // packages/dataviews/build-module/components/dataform-controls/datetime.mjs
14321 var import_components30 = __toESM(require_components(), 1);
14322 var import_element43 = __toESM(require_element(), 1);
14323 var import_i18n38 = __toESM(require_i18n(), 1);
14324 var import_date3 = __toESM(require_date(), 1);
14325
14326 // packages/dataviews/build-module/components/dataform-controls/utils/relative-date-control.mjs
14327 var import_components29 = __toESM(require_components(), 1);
14328 var import_element41 = __toESM(require_element(), 1);
14329 var import_i18n37 = __toESM(require_i18n(), 1);
14330 var import_jsx_runtime76 = __toESM(require_jsx_runtime(), 1);
14331 var TIME_UNITS_OPTIONS = {
14332 [OPERATOR_IN_THE_PAST]: [
14333 { value: "days", label: (0, import_i18n37.__)("Days") },
14334 { value: "weeks", label: (0, import_i18n37.__)("Weeks") },
14335 { value: "months", label: (0, import_i18n37.__)("Months") },
14336 { value: "years", label: (0, import_i18n37.__)("Years") }
14337 ],
14338 [OPERATOR_OVER]: [
14339 { value: "days", label: (0, import_i18n37.__)("Days ago") },
14340 { value: "weeks", label: (0, import_i18n37.__)("Weeks ago") },
14341 { value: "months", label: (0, import_i18n37.__)("Months ago") },
14342 { value: "years", label: (0, import_i18n37.__)("Years ago") }
14343 ]
14344 };
14345 function RelativeDateControl({
14346 className,
14347 data,
14348 field,
14349 onChange,
14350 hideLabelFromVision,
14351 operator
14352 }) {
14353 const options = TIME_UNITS_OPTIONS[operator === OPERATOR_IN_THE_PAST ? "inThePast" : "over"];
14354 const { id, label, description, getValue, setValue } = field;
14355 const disabled = field.isDisabled({ item: data, field });
14356 const fieldValue = getValue({ item: data });
14357 const { value: relValue = "", unit = options[0].value } = fieldValue && typeof fieldValue === "object" ? fieldValue : {};
14358 const onChangeValue = (0, import_element41.useCallback)(
14359 (newValue) => onChange(
14360 setValue({
14361 item: data,
14362 value: { value: Number(newValue), unit }
14363 })
14364 ),
14365 [onChange, setValue, data, unit]
14366 );
14367 const onChangeUnit = (0, import_element41.useCallback)(
14368 (newUnit) => onChange(
14369 setValue({
14370 item: data,
14371 value: { value: relValue, unit: newUnit }
14372 })
14373 ),
14374 [onChange, setValue, data, relValue]
14375 );
14376 return /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14377 import_components29.BaseControl,
14378 {
14379 id,
14380 className: clsx_default(className, "dataviews-controls__relative-date"),
14381 label,
14382 hideLabelFromVision,
14383 help: description,
14384 children: /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)(Stack, { direction: "row", gap: "sm", children: [
14385 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14386 import_components29.__experimentalNumberControl,
14387 {
14388 __next40pxDefaultSize: true,
14389 className: "dataviews-controls__relative-date-number",
14390 spinControls: "none",
14391 min: 1,
14392 step: 1,
14393 value: relValue,
14394 onChange: onChangeValue,
14395 disabled
14396 }
14397 ),
14398 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14399 import_components29.SelectControl,
14400 {
14401 className: "dataviews-controls__relative-date-unit",
14402 __next40pxDefaultSize: true,
14403 label: (0, import_i18n37.__)("Unit"),
14404 value: unit,
14405 options,
14406 onChange: onChangeUnit,
14407 hideLabelFromVision: true,
14408 disabled
14409 }
14410 )
14411 ] })
14412 }
14413 );
14414 }
14415
14416 // packages/dataviews/build-module/components/dataform-controls/utils/use-disabled-date-matchers.mjs
14417 var import_element42 = __toESM(require_element(), 1);
14418 function useDisabledDateMatchers(isValid2, parseDateFn) {
14419 const minConstraint = typeof isValid2.min?.constraint === "string" ? isValid2.min.constraint : void 0;
14420 const maxConstraint = typeof isValid2.max?.constraint === "string" ? isValid2.max.constraint : void 0;
14421 const disabledMatchers = (0, import_element42.useMemo)(() => {
14422 const matchers = [];
14423 if (minConstraint) {
14424 const minDate = parseDateFn(minConstraint);
14425 if (minDate) {
14426 matchers.push({ before: minDate });
14427 }
14428 }
14429 if (maxConstraint) {
14430 const maxDate = parseDateFn(maxConstraint);
14431 if (maxDate) {
14432 matchers.push({ after: maxDate });
14433 }
14434 }
14435 return matchers.length > 0 ? matchers : void 0;
14436 }, [minConstraint, maxConstraint, parseDateFn]);
14437 return { minConstraint, maxConstraint, disabledMatchers };
14438 }
14439
14440 // packages/dataviews/build-module/field-types/utils/parse-date-time.mjs
14441 var import_date2 = __toESM(require_date(), 1);
14442 function parseDateTime(dateTimeString) {
14443 if (!dateTimeString) {
14444 return null;
14445 }
14446 const parsed = (0, import_date2.getDate)(dateTimeString);
14447 return parsed && isValid(parsed) ? parsed : null;
14448 }
14449
14450 // packages/dataviews/build-module/components/dataform-controls/datetime.mjs
14451 var import_jsx_runtime77 = __toESM(require_jsx_runtime(), 1);
14452 var { DateCalendar, ValidatedInputControl } = unlock(import_components30.privateApis);
14453 var formatDateTime = (value) => {
14454 if (!value) {
14455 return "";
14456 }
14457 return (0, import_date3.dateI18n)("Y-m-d\\TH:i", (0, import_date3.getDate)(value));
14458 };
14459 function CalendarDateTimeControl({
14460 data,
14461 field,
14462 onChange,
14463 hideLabelFromVision,
14464 markWhenOptional,
14465 validity,
14466 config
14467 }) {
14468 const { compact } = config || {};
14469 const { id, label, description, setValue, getValue, isValid: isValid2 } = field;
14470 const disabled = field.isDisabled({ item: data, field });
14471 const fieldValue = getValue({ item: data });
14472 const value = typeof fieldValue === "string" ? fieldValue : void 0;
14473 const [calendarMonth, setCalendarMonth] = (0, import_element43.useState)(() => {
14474 const parsedDate = parseDateTime(value);
14475 return parsedDate || /* @__PURE__ */ new Date();
14476 });
14477 const inputControlRef = (0, import_element43.useRef)(null);
14478 const validationTimeoutRef = (0, import_element43.useRef)(void 0);
14479 const previousFocusRef = (0, import_element43.useRef)(null);
14480 const { minConstraint, maxConstraint, disabledMatchers } = useDisabledDateMatchers(isValid2, parseDateTime);
14481 const onChangeCallback = (0, import_element43.useCallback)(
14482 (newValue) => onChange(setValue({ item: data, value: newValue })),
14483 [data, onChange, setValue]
14484 );
14485 (0, import_element43.useEffect)(() => {
14486 return () => {
14487 if (validationTimeoutRef.current) {
14488 clearTimeout(validationTimeoutRef.current);
14489 }
14490 };
14491 }, []);
14492 const onSelectDate = (0, import_element43.useCallback)(
14493 (newDate) => {
14494 let dateTimeValue;
14495 if (newDate) {
14496 const wpDate = (0, import_date3.dateI18n)("Y-m-d", newDate);
14497 let wpTime;
14498 if (value) {
14499 wpTime = (0, import_date3.dateI18n)("H:i", (0, import_date3.getDate)(value));
14500 } else {
14501 wpTime = (0, import_date3.dateI18n)("H:i", newDate);
14502 }
14503 const finalDateTime = (0, import_date3.getDate)(`${wpDate}T${wpTime}`);
14504 dateTimeValue = finalDateTime.toISOString();
14505 onChangeCallback(dateTimeValue);
14506 if (validationTimeoutRef.current) {
14507 clearTimeout(validationTimeoutRef.current);
14508 }
14509 } else {
14510 onChangeCallback(void 0);
14511 }
14512 previousFocusRef.current = inputControlRef.current && inputControlRef.current.ownerDocument.activeElement;
14513 validationTimeoutRef.current = setTimeout(() => {
14514 if (inputControlRef.current) {
14515 inputControlRef.current.focus();
14516 inputControlRef.current.blur();
14517 onChangeCallback(dateTimeValue);
14518 if (previousFocusRef.current && previousFocusRef.current instanceof HTMLElement) {
14519 previousFocusRef.current.focus();
14520 }
14521 }
14522 }, 0);
14523 },
14524 [onChangeCallback, value]
14525 );
14526 const handleManualDateTimeChange = (0, import_element43.useCallback)(
14527 (newValue) => {
14528 if (newValue) {
14529 const dateTime = (0, import_date3.getDate)(newValue);
14530 onChangeCallback(dateTime.toISOString());
14531 const parsedDate = parseDateTime(dateTime.toISOString());
14532 if (parsedDate) {
14533 setCalendarMonth(parsedDate);
14534 }
14535 } else {
14536 onChangeCallback(void 0);
14537 }
14538 },
14539 [onChangeCallback]
14540 );
14541 const { format: fieldFormat } = field;
14542 const weekStartsOn = fieldFormat.weekStartsOn ?? (0, import_date3.getSettings)().l10n.startOfWeek;
14543 const {
14544 timezone: { string: timezoneString }
14545 } = (0, import_date3.getSettings)();
14546 let displayLabel = label;
14547 if (isValid2?.required && !markWhenOptional && !hideLabelFromVision) {
14548 displayLabel = `${label} (${(0, import_i18n38.__)("Required")})`;
14549 } else if (!isValid2?.required && markWhenOptional && !hideLabelFromVision) {
14550 displayLabel = `${label} (${(0, import_i18n38.__)("Optional")})`;
14551 }
14552 return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14553 import_components30.BaseControl,
14554 {
14555 id,
14556 label: displayLabel,
14557 help: description,
14558 hideLabelFromVision,
14559 children: /* @__PURE__ */ (0, import_jsx_runtime77.jsxs)(Stack, { direction: "column", gap: "lg", children: [
14560 /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14561 ValidatedInputControl,
14562 {
14563 ref: inputControlRef,
14564 __next40pxDefaultSize: true,
14565 required: !!isValid2?.required,
14566 customValidity: getCustomValidity(isValid2, validity),
14567 type: "datetime-local",
14568 label: (0, import_i18n38.__)("Date time"),
14569 hideLabelFromVision: true,
14570 value: formatDateTime(value),
14571 onChange: handleManualDateTimeChange,
14572 disabled,
14573 min: minConstraint ? formatDateTime(minConstraint) : void 0,
14574 max: maxConstraint ? formatDateTime(maxConstraint) : void 0
14575 }
14576 ),
14577 !compact && /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14578 DateCalendar,
14579 {
14580 style: { width: "100%" },
14581 selected: value ? parseDateTime(value) || void 0 : void 0,
14582 onSelect: onSelectDate,
14583 month: calendarMonth,
14584 onMonthChange: setCalendarMonth,
14585 timeZone: timezoneString || void 0,
14586 weekStartsOn,
14587 disabled: disabled || disabledMatchers
14588 }
14589 )
14590 ] })
14591 }
14592 );
14593 }
14594 function DateTime({
14595 data,
14596 field,
14597 onChange,
14598 hideLabelFromVision,
14599 markWhenOptional,
14600 operator,
14601 validity,
14602 config
14603 }) {
14604 if (operator === OPERATOR_IN_THE_PAST || operator === OPERATOR_OVER) {
14605 return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14606 RelativeDateControl,
14607 {
14608 className: "dataviews-controls__datetime",
14609 data,
14610 field,
14611 onChange,
14612 hideLabelFromVision,
14613 operator
14614 }
14615 );
14616 }
14617 return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14618 CalendarDateTimeControl,
14619 {
14620 data,
14621 field,
14622 onChange,
14623 hideLabelFromVision,
14624 markWhenOptional,
14625 validity,
14626 config
14627 }
14628 );
14629 }
14630
14631 // packages/dataviews/build-module/components/dataform-controls/date.mjs
14632 var import_components31 = __toESM(require_components(), 1);
14633 var import_element44 = __toESM(require_element(), 1);
14634 var import_i18n39 = __toESM(require_i18n(), 1);
14635 var import_date4 = __toESM(require_date(), 1);
14636 var import_jsx_runtime78 = __toESM(require_jsx_runtime(), 1);
14637 var { DateCalendar: DateCalendar2, DateRangeCalendar } = unlock(import_components31.privateApis);
14638 var DATE_PRESETS = [
14639 {
14640 id: "today",
14641 label: (0, import_i18n39.__)("Today"),
14642 getValue: () => (0, import_date4.getDate)(null)
14643 },
14644 {
14645 id: "yesterday",
14646 label: (0, import_i18n39.__)("Yesterday"),
14647 getValue: () => {
14648 const today = (0, import_date4.getDate)(null);
14649 return subDays(today, 1);
14650 }
14651 },
14652 {
14653 id: "past-week",
14654 label: (0, import_i18n39.__)("Past week"),
14655 getValue: () => {
14656 const today = (0, import_date4.getDate)(null);
14657 return subDays(today, 7);
14658 }
14659 },
14660 {
14661 id: "past-month",
14662 label: (0, import_i18n39.__)("Past month"),
14663 getValue: () => {
14664 const today = (0, import_date4.getDate)(null);
14665 return subMonths(today, 1);
14666 }
14667 }
14668 ];
14669 var DATE_RANGE_PRESETS = [
14670 {
14671 id: "last-7-days",
14672 label: (0, import_i18n39.__)("Last 7 days"),
14673 getValue: () => {
14674 const today = (0, import_date4.getDate)(null);
14675 return [subDays(today, 7), today];
14676 }
14677 },
14678 {
14679 id: "last-30-days",
14680 label: (0, import_i18n39.__)("Last 30 days"),
14681 getValue: () => {
14682 const today = (0, import_date4.getDate)(null);
14683 return [subDays(today, 30), today];
14684 }
14685 },
14686 {
14687 id: "month-to-date",
14688 label: (0, import_i18n39.__)("Month to date"),
14689 getValue: () => {
14690 const today = (0, import_date4.getDate)(null);
14691 return [startOfMonth(today), today];
14692 }
14693 },
14694 {
14695 id: "last-year",
14696 label: (0, import_i18n39.__)("Last year"),
14697 getValue: () => {
14698 const today = (0, import_date4.getDate)(null);
14699 return [subYears(today, 1), today];
14700 }
14701 },
14702 {
14703 id: "year-to-date",
14704 label: (0, import_i18n39.__)("Year to date"),
14705 getValue: () => {
14706 const today = (0, import_date4.getDate)(null);
14707 return [startOfYear(today), today];
14708 }
14709 }
14710 ];
14711 var parseDate = (dateString) => {
14712 if (!dateString) {
14713 return null;
14714 }
14715 const parsed = (0, import_date4.getDate)(dateString);
14716 return parsed && isValid(parsed) ? parsed : null;
14717 };
14718 var formatDate = (date) => {
14719 if (!date) {
14720 return "";
14721 }
14722 return typeof date === "string" ? date : format(date, "yyyy-MM-dd");
14723 };
14724 function ValidatedDateControl({
14725 field,
14726 validity,
14727 inputRefs,
14728 isTouched,
14729 setIsTouched,
14730 children
14731 }) {
14732 const { isValid: isValid2 } = field;
14733 const [customValidity, setCustomValidity] = (0, import_element44.useState)(void 0);
14734 const validateRefs = (0, import_element44.useCallback)(() => {
14735 const refs = Array.isArray(inputRefs) ? inputRefs : [inputRefs];
14736 for (const ref of refs) {
14737 const input = ref.current;
14738 if (input && !input.validity.valid) {
14739 setCustomValidity({
14740 type: "invalid",
14741 message: input.validationMessage
14742 });
14743 return;
14744 }
14745 }
14746 setCustomValidity(void 0);
14747 }, [inputRefs]);
14748 (0, import_element44.useEffect)(() => {
14749 const refs = Array.isArray(inputRefs) ? inputRefs : [inputRefs];
14750 const result = validity ? getCustomValidity(isValid2, validity) : void 0;
14751 for (const ref of refs) {
14752 const input = ref.current;
14753 if (input) {
14754 input.setCustomValidity(
14755 result?.type === "invalid" && result.message ? result.message : ""
14756 );
14757 }
14758 }
14759 }, [inputRefs, isValid2, validity]);
14760 (0, import_element44.useEffect)(() => {
14761 const refs = Array.isArray(inputRefs) ? inputRefs : [inputRefs];
14762 const handleInvalid = (event) => {
14763 event.preventDefault();
14764 setIsTouched(true);
14765 };
14766 for (const ref of refs) {
14767 ref.current?.addEventListener("invalid", handleInvalid);
14768 }
14769 return () => {
14770 for (const ref of refs) {
14771 ref.current?.removeEventListener("invalid", handleInvalid);
14772 }
14773 };
14774 }, [inputRefs, setIsTouched]);
14775 (0, import_element44.useEffect)(() => {
14776 if (!isTouched) {
14777 return;
14778 }
14779 const result = validity ? getCustomValidity(isValid2, validity) : void 0;
14780 if (result) {
14781 setCustomValidity(result);
14782 } else {
14783 validateRefs();
14784 }
14785 }, [isTouched, isValid2, validity, validateRefs]);
14786 const onBlur = (event) => {
14787 if (isTouched) {
14788 return;
14789 }
14790 if (!event.relatedTarget || !event.currentTarget.contains(event.relatedTarget)) {
14791 setIsTouched(true);
14792 }
14793 };
14794 return /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)("div", { onBlur, children: [
14795 children,
14796 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)("div", { "aria-live": "polite", children: customValidity && /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
14797 "p",
14798 {
14799 className: clsx_default(
14800 "components-validated-control__indicator",
14801 customValidity.type === "invalid" ? "is-invalid" : void 0
14802 ),
14803 children: [
14804 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14805 import_components31.Icon,
14806 {
14807 className: "components-validated-control__indicator-icon",
14808 icon: error_default,
14809 size: 16,
14810 fill: "currentColor"
14811 }
14812 ),
14813 customValidity.message
14814 ]
14815 }
14816 ) })
14817 ] });
14818 }
14819 function CalendarDateControl({
14820 data,
14821 field,
14822 onChange,
14823 hideLabelFromVision,
14824 markWhenOptional,
14825 validity
14826 }) {
14827 const {
14828 id,
14829 label,
14830 description,
14831 setValue,
14832 getValue,
14833 isValid: isValid2,
14834 format: fieldFormat
14835 } = field;
14836 const disabled = field.isDisabled({ item: data, field });
14837 const [selectedPresetId, setSelectedPresetId] = (0, import_element44.useState)(
14838 null
14839 );
14840 const weekStartsOn = fieldFormat.weekStartsOn ?? (0, import_date4.getSettings)().l10n.startOfWeek;
14841 const fieldValue = getValue({ item: data });
14842 const value = typeof fieldValue === "string" ? fieldValue : void 0;
14843 const [calendarMonth, setCalendarMonth] = (0, import_element44.useState)(() => {
14844 const parsedDate = parseDate(value);
14845 return parsedDate || /* @__PURE__ */ new Date();
14846 });
14847 const [isTouched, setIsTouched] = (0, import_element44.useState)(false);
14848 const validityTargetRef = (0, import_element44.useRef)(null);
14849 const { minConstraint, maxConstraint, disabledMatchers } = useDisabledDateMatchers(isValid2, parseDate);
14850 const onChangeCallback = (0, import_element44.useCallback)(
14851 (newValue) => onChange(setValue({ item: data, value: newValue })),
14852 [data, onChange, setValue]
14853 );
14854 const onSelectDate = (0, import_element44.useCallback)(
14855 (newDate) => {
14856 const dateValue = newDate ? format(newDate, "yyyy-MM-dd") : void 0;
14857 onChangeCallback(dateValue);
14858 setSelectedPresetId(null);
14859 setIsTouched(true);
14860 },
14861 [onChangeCallback]
14862 );
14863 const handlePresetClick = (0, import_element44.useCallback)(
14864 (preset) => {
14865 const presetDate = preset.getValue();
14866 const dateValue = formatDate(presetDate);
14867 setCalendarMonth(presetDate);
14868 onChangeCallback(dateValue);
14869 setSelectedPresetId(preset.id);
14870 setIsTouched(true);
14871 },
14872 [onChangeCallback]
14873 );
14874 const handleManualDateChange = (0, import_element44.useCallback)(
14875 (newValue) => {
14876 onChangeCallback(newValue);
14877 if (newValue) {
14878 const parsedDate = parseDate(newValue);
14879 if (parsedDate) {
14880 setCalendarMonth(parsedDate);
14881 }
14882 }
14883 setSelectedPresetId(null);
14884 setIsTouched(true);
14885 },
14886 [onChangeCallback]
14887 );
14888 const {
14889 timezone: { string: timezoneString }
14890 } = (0, import_date4.getSettings)();
14891 let displayLabel = label;
14892 if (isValid2?.required && !markWhenOptional) {
14893 displayLabel = `${label} (${(0, import_i18n39.__)("Required")})`;
14894 } else if (!isValid2?.required && markWhenOptional) {
14895 displayLabel = `${label} (${(0, import_i18n39.__)("Optional")})`;
14896 }
14897 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14898 ValidatedDateControl,
14899 {
14900 field,
14901 validity,
14902 inputRefs: validityTargetRef,
14903 isTouched,
14904 setIsTouched,
14905 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14906 import_components31.BaseControl,
14907 {
14908 id,
14909 className: "dataviews-controls__date",
14910 label: displayLabel,
14911 help: description,
14912 hideLabelFromVision,
14913 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(Stack, { direction: "column", gap: "lg", children: [
14914 /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
14915 Stack,
14916 {
14917 direction: "row",
14918 gap: "sm",
14919 wrap: "wrap",
14920 justify: "flex-start",
14921 children: [
14922 DATE_PRESETS.map((preset) => {
14923 const isSelected2 = selectedPresetId === preset.id;
14924 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14925 import_components31.Button,
14926 {
14927 className: "dataviews-controls__date-preset",
14928 variant: "tertiary",
14929 isPressed: isSelected2,
14930 size: "small",
14931 disabled,
14932 accessibleWhenDisabled: true,
14933 onClick: () => handlePresetClick(preset),
14934 children: preset.label
14935 },
14936 preset.id
14937 );
14938 }),
14939 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14940 import_components31.Button,
14941 {
14942 className: "dataviews-controls__date-preset",
14943 variant: "tertiary",
14944 isPressed: !selectedPresetId,
14945 size: "small",
14946 disabled: !!selectedPresetId || disabled,
14947 accessibleWhenDisabled: true,
14948 children: (0, import_i18n39.__)("Custom")
14949 }
14950 )
14951 ]
14952 }
14953 ),
14954 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14955 import_components31.__experimentalInputControl,
14956 {
14957 __next40pxDefaultSize: true,
14958 ref: validityTargetRef,
14959 type: "date",
14960 label: (0, import_i18n39.__)("Date"),
14961 hideLabelFromVision: true,
14962 value,
14963 onChange: handleManualDateChange,
14964 required: !!field.isValid?.required,
14965 disabled,
14966 min: minConstraint,
14967 max: maxConstraint
14968 }
14969 ),
14970 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14971 DateCalendar2,
14972 {
14973 style: { width: "100%" },
14974 selected: value ? parseDate(value) || void 0 : void 0,
14975 onSelect: onSelectDate,
14976 month: calendarMonth,
14977 onMonthChange: setCalendarMonth,
14978 timeZone: timezoneString || void 0,
14979 weekStartsOn,
14980 disabled: disabled || disabledMatchers,
14981 disableNavigation: disabled
14982 }
14983 )
14984 ] })
14985 }
14986 )
14987 }
14988 );
14989 }
14990 function CalendarDateRangeControl({
14991 data,
14992 field,
14993 onChange,
14994 hideLabelFromVision,
14995 markWhenOptional,
14996 validity
14997 }) {
14998 const {
14999 id,
15000 label,
15001 description,
15002 getValue,
15003 setValue,
15004 isValid: isValid2,
15005 format: fieldFormat
15006 } = field;
15007 const disabled = field.isDisabled({ item: data, field });
15008 let value;
15009 const fieldValue = getValue({ item: data });
15010 if (Array.isArray(fieldValue) && fieldValue.length === 2 && fieldValue.every((date) => typeof date === "string")) {
15011 value = fieldValue;
15012 }
15013 const weekStartsOn = fieldFormat.weekStartsOn ?? (0, import_date4.getSettings)().l10n.startOfWeek;
15014 const { minConstraint, maxConstraint, disabledMatchers } = useDisabledDateMatchers(isValid2, parseDate);
15015 const onChangeCallback = (0, import_element44.useCallback)(
15016 (newValue) => {
15017 onChange(
15018 setValue({
15019 item: data,
15020 value: newValue
15021 })
15022 );
15023 },
15024 [data, onChange, setValue]
15025 );
15026 const [selectedPresetId, setSelectedPresetId] = (0, import_element44.useState)(
15027 null
15028 );
15029 const selectedRange = (0, import_element44.useMemo)(() => {
15030 if (!value) {
15031 return { from: void 0, to: void 0 };
15032 }
15033 const [from, to] = value;
15034 return {
15035 from: parseDate(from) || void 0,
15036 to: parseDate(to) || void 0
15037 };
15038 }, [value]);
15039 const [calendarMonth, setCalendarMonth] = (0, import_element44.useState)(() => {
15040 return selectedRange.from || /* @__PURE__ */ new Date();
15041 });
15042 const [isTouched, setIsTouched] = (0, import_element44.useState)(false);
15043 const fromInputRef = (0, import_element44.useRef)(null);
15044 const toInputRef = (0, import_element44.useRef)(null);
15045 const updateDateRange = (0, import_element44.useCallback)(
15046 (fromDate, toDate2) => {
15047 if (fromDate && toDate2) {
15048 onChangeCallback([
15049 formatDate(fromDate),
15050 formatDate(toDate2)
15051 ]);
15052 } else if (!fromDate && !toDate2) {
15053 onChangeCallback(void 0);
15054 }
15055 },
15056 [onChangeCallback]
15057 );
15058 const onSelectCalendarRange = (0, import_element44.useCallback)(
15059 (newRange) => {
15060 updateDateRange(newRange?.from, newRange?.to);
15061 setSelectedPresetId(null);
15062 setIsTouched(true);
15063 },
15064 [updateDateRange]
15065 );
15066 const handlePresetClick = (0, import_element44.useCallback)(
15067 (preset) => {
15068 const [startDate, endDate] = preset.getValue();
15069 setCalendarMonth(startDate);
15070 updateDateRange(startDate, endDate);
15071 setSelectedPresetId(preset.id);
15072 setIsTouched(true);
15073 },
15074 [updateDateRange]
15075 );
15076 const handleManualDateChange = (0, import_element44.useCallback)(
15077 (fromOrTo, newValue) => {
15078 const [currentFrom, currentTo] = value || [
15079 void 0,
15080 void 0
15081 ];
15082 const updatedFrom = fromOrTo === "from" ? newValue : currentFrom;
15083 const updatedTo = fromOrTo === "to" ? newValue : currentTo;
15084 updateDateRange(updatedFrom, updatedTo);
15085 if (newValue) {
15086 const parsedDate = parseDate(newValue);
15087 if (parsedDate) {
15088 setCalendarMonth(parsedDate);
15089 }
15090 }
15091 setSelectedPresetId(null);
15092 setIsTouched(true);
15093 },
15094 [value, updateDateRange]
15095 );
15096 const { timezone } = (0, import_date4.getSettings)();
15097 let displayLabel = label;
15098 if (field.isValid?.required && !markWhenOptional) {
15099 displayLabel = `${label} (${(0, import_i18n39.__)("Required")})`;
15100 } else if (!field.isValid?.required && markWhenOptional) {
15101 displayLabel = `${label} (${(0, import_i18n39.__)("Optional")})`;
15102 }
15103 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15104 ValidatedDateControl,
15105 {
15106 field,
15107 validity,
15108 inputRefs: [fromInputRef, toInputRef],
15109 isTouched,
15110 setIsTouched,
15111 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15112 import_components31.BaseControl,
15113 {
15114 id,
15115 className: "dataviews-controls__date",
15116 label: displayLabel,
15117 help: description,
15118 hideLabelFromVision,
15119 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(Stack, { direction: "column", gap: "lg", children: [
15120 /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
15121 Stack,
15122 {
15123 direction: "row",
15124 gap: "sm",
15125 wrap: "wrap",
15126 justify: "flex-start",
15127 children: [
15128 DATE_RANGE_PRESETS.map((preset) => {
15129 const isSelected2 = selectedPresetId === preset.id;
15130 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15131 import_components31.Button,
15132 {
15133 className: "dataviews-controls__date-preset",
15134 variant: "tertiary",
15135 isPressed: isSelected2,
15136 size: "small",
15137 disabled,
15138 accessibleWhenDisabled: true,
15139 onClick: () => handlePresetClick(preset),
15140 children: preset.label
15141 },
15142 preset.id
15143 );
15144 }),
15145 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15146 import_components31.Button,
15147 {
15148 className: "dataviews-controls__date-preset",
15149 variant: "tertiary",
15150 isPressed: !selectedPresetId,
15151 size: "small",
15152 accessibleWhenDisabled: true,
15153 disabled: !!selectedPresetId || disabled,
15154 children: (0, import_i18n39.__)("Custom")
15155 }
15156 )
15157 ]
15158 }
15159 ),
15160 /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
15161 Stack,
15162 {
15163 direction: "row",
15164 gap: "sm",
15165 justify: "space-between",
15166 className: "dataviews-controls__date-range-inputs",
15167 children: [
15168 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15169 import_components31.__experimentalInputControl,
15170 {
15171 __next40pxDefaultSize: true,
15172 ref: fromInputRef,
15173 type: "date",
15174 label: (0, import_i18n39.__)("From"),
15175 hideLabelFromVision: true,
15176 value: value?.[0],
15177 onChange: (newValue) => handleManualDateChange("from", newValue),
15178 required: !!field.isValid?.required,
15179 disabled,
15180 min: minConstraint,
15181 max: maxConstraint
15182 }
15183 ),
15184 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15185 import_components31.__experimentalInputControl,
15186 {
15187 __next40pxDefaultSize: true,
15188 ref: toInputRef,
15189 type: "date",
15190 label: (0, import_i18n39.__)("To"),
15191 hideLabelFromVision: true,
15192 value: value?.[1],
15193 onChange: (newValue) => handleManualDateChange("to", newValue),
15194 required: !!field.isValid?.required,
15195 disabled,
15196 min: minConstraint,
15197 max: maxConstraint
15198 }
15199 )
15200 ]
15201 }
15202 ),
15203 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15204 DateRangeCalendar,
15205 {
15206 style: { width: "100%" },
15207 selected: selectedRange,
15208 onSelect: onSelectCalendarRange,
15209 month: calendarMonth,
15210 onMonthChange: setCalendarMonth,
15211 timeZone: timezone.string || void 0,
15212 weekStartsOn,
15213 disabled: disabled || disabledMatchers
15214 }
15215 )
15216 ] })
15217 }
15218 )
15219 }
15220 );
15221 }
15222 function DateControl({
15223 data,
15224 field,
15225 onChange,
15226 hideLabelFromVision,
15227 markWhenOptional,
15228 operator,
15229 validity
15230 }) {
15231 if (operator === OPERATOR_IN_THE_PAST || operator === OPERATOR_OVER) {
15232 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15233 RelativeDateControl,
15234 {
15235 className: "dataviews-controls__date",
15236 data,
15237 field,
15238 onChange,
15239 hideLabelFromVision,
15240 operator
15241 }
15242 );
15243 }
15244 if (operator === OPERATOR_BETWEEN) {
15245 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15246 CalendarDateRangeControl,
15247 {
15248 data,
15249 field,
15250 onChange,
15251 hideLabelFromVision,
15252 markWhenOptional,
15253 validity
15254 }
15255 );
15256 }
15257 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15258 CalendarDateControl,
15259 {
15260 data,
15261 field,
15262 onChange,
15263 hideLabelFromVision,
15264 markWhenOptional,
15265 validity
15266 }
15267 );
15268 }
15269
15270 // packages/dataviews/build-module/components/dataform-controls/select.mjs
15271 var import_components32 = __toESM(require_components(), 1);
15272 var import_element45 = __toESM(require_element(), 1);
15273 var import_jsx_runtime79 = __toESM(require_jsx_runtime(), 1);
15274 var { ValidatedSelectControl } = unlock(import_components32.privateApis);
15275 function Select({
15276 data,
15277 field,
15278 onChange,
15279 hideLabelFromVision,
15280 markWhenOptional,
15281 validity
15282 }) {
15283 const { type, label, description, getValue, setValue, isValid: isValid2 } = field;
15284 const disabled = field.isDisabled({ item: data, field });
15285 const isMultiple = type === "array";
15286 const value = getValue({ item: data }) ?? (isMultiple ? [] : "");
15287 const onChangeControl = (0, import_element45.useCallback)(
15288 (newValue) => onChange(setValue({ item: data, value: newValue })),
15289 [data, onChange, setValue]
15290 );
15291 const { elements, isLoading } = useElements({
15292 elements: field.elements,
15293 getElements: field.getElements
15294 });
15295 if (isLoading) {
15296 return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(import_components32.Spinner, {});
15297 }
15298 return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
15299 ValidatedSelectControl,
15300 {
15301 required: !!field.isValid?.required,
15302 markWhenOptional,
15303 customValidity: getCustomValidity(isValid2, validity),
15304 label,
15305 value,
15306 help: description,
15307 options: elements,
15308 onChange: onChangeControl,
15309 __next40pxDefaultSize: true,
15310 hideLabelFromVision,
15311 multiple: isMultiple,
15312 disabled
15313 }
15314 );
15315 }
15316
15317 // packages/dataviews/build-module/components/dataform-controls/adaptive-select.mjs
15318 var import_jsx_runtime80 = __toESM(require_jsx_runtime(), 1);
15319 var ELEMENTS_THRESHOLD = 10;
15320 function AdaptiveSelect(props) {
15321 const { field } = props;
15322 const { elements } = useElements({
15323 elements: field.elements,
15324 getElements: field.getElements
15325 });
15326 if (elements.length >= ELEMENTS_THRESHOLD) {
15327 return /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(Combobox3, { ...props });
15328 }
15329 return /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(Select, { ...props });
15330 }
15331
15332 // packages/dataviews/build-module/components/dataform-controls/email.mjs
15333 var import_components34 = __toESM(require_components(), 1);
15334
15335 // packages/dataviews/build-module/components/dataform-controls/utils/validated-input.mjs
15336 var import_components33 = __toESM(require_components(), 1);
15337 var import_element46 = __toESM(require_element(), 1);
15338 var import_jsx_runtime81 = __toESM(require_jsx_runtime(), 1);
15339 var { ValidatedInputControl: ValidatedInputControl2 } = unlock(import_components33.privateApis);
15340 function ValidatedText({
15341 data,
15342 field,
15343 onChange,
15344 hideLabelFromVision,
15345 markWhenOptional,
15346 type,
15347 prefix,
15348 suffix,
15349 validity
15350 }) {
15351 const { label, placeholder, description, getValue, setValue, isValid: isValid2 } = field;
15352 const value = getValue({ item: data });
15353 const disabled = field.isDisabled({ item: data, field });
15354 const onChangeControl = (0, import_element46.useCallback)(
15355 (newValue) => onChange(
15356 setValue({
15357 item: data,
15358 value: newValue
15359 })
15360 ),
15361 [data, setValue, onChange]
15362 );
15363 return /* @__PURE__ */ (0, import_jsx_runtime81.jsx)(
15364 ValidatedInputControl2,
15365 {
15366 required: !!isValid2.required,
15367 markWhenOptional,
15368 customValidity: getCustomValidity(isValid2, validity),
15369 label,
15370 placeholder,
15371 value: value ?? "",
15372 help: description,
15373 onChange: onChangeControl,
15374 hideLabelFromVision,
15375 type,
15376 prefix,
15377 suffix,
15378 disabled,
15379 pattern: isValid2.pattern ? isValid2.pattern.constraint : void 0,
15380 minLength: isValid2.minLength ? isValid2.minLength.constraint : void 0,
15381 maxLength: isValid2.maxLength ? isValid2.maxLength.constraint : void 0,
15382 __next40pxDefaultSize: true
15383 }
15384 );
15385 }
15386
15387 // packages/dataviews/build-module/components/dataform-controls/email.mjs
15388 var import_jsx_runtime82 = __toESM(require_jsx_runtime(), 1);
15389 function Email({
15390 data,
15391 field,
15392 onChange,
15393 hideLabelFromVision,
15394 markWhenOptional,
15395 validity
15396 }) {
15397 return /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(
15398 ValidatedText,
15399 {
15400 ...{
15401 data,
15402 field,
15403 onChange,
15404 hideLabelFromVision,
15405 markWhenOptional,
15406 validity,
15407 type: "email",
15408 prefix: /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(import_components34.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(import_components34.Icon, { icon: envelope_default }) })
15409 }
15410 }
15411 );
15412 }
15413
15414 // packages/dataviews/build-module/components/dataform-controls/telephone.mjs
15415 var import_components35 = __toESM(require_components(), 1);
15416 var import_jsx_runtime83 = __toESM(require_jsx_runtime(), 1);
15417 function Telephone({
15418 data,
15419 field,
15420 onChange,
15421 hideLabelFromVision,
15422 markWhenOptional,
15423 validity
15424 }) {
15425 return /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(
15426 ValidatedText,
15427 {
15428 ...{
15429 data,
15430 field,
15431 onChange,
15432 hideLabelFromVision,
15433 markWhenOptional,
15434 validity,
15435 type: "tel",
15436 prefix: /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(import_components35.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(import_components35.Icon, { icon: mobile_default }) })
15437 }
15438 }
15439 );
15440 }
15441
15442 // packages/dataviews/build-module/components/dataform-controls/url.mjs
15443 var import_components36 = __toESM(require_components(), 1);
15444 var import_jsx_runtime84 = __toESM(require_jsx_runtime(), 1);
15445 function Url({
15446 data,
15447 field,
15448 onChange,
15449 hideLabelFromVision,
15450 markWhenOptional,
15451 validity
15452 }) {
15453 return /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(
15454 ValidatedText,
15455 {
15456 ...{
15457 data,
15458 field,
15459 onChange,
15460 hideLabelFromVision,
15461 markWhenOptional,
15462 validity,
15463 type: "url",
15464 prefix: /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(import_components36.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(import_components36.Icon, { icon: link_default }) })
15465 }
15466 }
15467 );
15468 }
15469
15470 // packages/dataviews/build-module/components/dataform-controls/utils/validated-number.mjs
15471 var import_components37 = __toESM(require_components(), 1);
15472 var import_element47 = __toESM(require_element(), 1);
15473 var import_i18n40 = __toESM(require_i18n(), 1);
15474 var import_jsx_runtime85 = __toESM(require_jsx_runtime(), 1);
15475 var { ValidatedNumberControl } = unlock(import_components37.privateApis);
15476 function toNumberOrEmpty(value) {
15477 if (value === "" || value === void 0) {
15478 return "";
15479 }
15480 const number = Number(value);
15481 return Number.isFinite(number) ? number : "";
15482 }
15483 function BetweenControls({
15484 value,
15485 onChange,
15486 hideLabelFromVision,
15487 step
15488 }) {
15489 const [min = "", max = ""] = value;
15490 const onChangeMin = (0, import_element47.useCallback)(
15491 (newValue) => onChange([toNumberOrEmpty(newValue), max]),
15492 [onChange, max]
15493 );
15494 const onChangeMax = (0, import_element47.useCallback)(
15495 (newValue) => onChange([min, toNumberOrEmpty(newValue)]),
15496 [onChange, min]
15497 );
15498 return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15499 import_components37.BaseControl,
15500 {
15501 help: (0, import_i18n40.__)("The max. value must be greater than the min. value."),
15502 children: /* @__PURE__ */ (0, import_jsx_runtime85.jsxs)(import_components37.Flex, { direction: "row", gap: 4, children: [
15503 /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15504 import_components37.__experimentalNumberControl,
15505 {
15506 label: (0, import_i18n40.__)("Min."),
15507 value: min,
15508 max: max ? Number(max) - step : void 0,
15509 onChange: onChangeMin,
15510 __next40pxDefaultSize: true,
15511 hideLabelFromVision,
15512 step
15513 }
15514 ),
15515 /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15516 import_components37.__experimentalNumberControl,
15517 {
15518 label: (0, import_i18n40.__)("Max."),
15519 value: max,
15520 min: min ? Number(min) + step : void 0,
15521 onChange: onChangeMax,
15522 __next40pxDefaultSize: true,
15523 hideLabelFromVision,
15524 step
15525 }
15526 )
15527 ] })
15528 }
15529 );
15530 }
15531 function ValidatedNumber({
15532 data,
15533 field,
15534 onChange,
15535 hideLabelFromVision,
15536 markWhenOptional,
15537 operator,
15538 validity
15539 }) {
15540 const decimals = field.format?.decimals ?? 0;
15541 const step = Math.pow(10, Math.abs(decimals) * -1);
15542 const { label, description, getValue, setValue, isValid: isValid2 } = field;
15543 const value = getValue({ item: data }) ?? "";
15544 const disabled = field.isDisabled({ item: data, field });
15545 const onChangeControl = (0, import_element47.useCallback)(
15546 (newValue) => {
15547 onChange(
15548 setValue({
15549 item: data,
15550 // Do not convert an empty string or undefined to a number,
15551 // otherwise there's a mismatch between the UI control (empty)
15552 // and the data relied by onChange (0).
15553 value: ["", void 0].includes(newValue) ? void 0 : Number(newValue)
15554 })
15555 );
15556 },
15557 [data, onChange, setValue]
15558 );
15559 const onChangeBetweenControls = (0, import_element47.useCallback)(
15560 (newValue) => {
15561 onChange(
15562 setValue({
15563 item: data,
15564 value: newValue
15565 })
15566 );
15567 },
15568 [data, onChange, setValue]
15569 );
15570 if (operator === OPERATOR_BETWEEN) {
15571 let valueBetween = ["", ""];
15572 if (Array.isArray(value) && value.length === 2 && value.every(
15573 (element) => typeof element === "number" || element === ""
15574 )) {
15575 valueBetween = value;
15576 }
15577 return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15578 BetweenControls,
15579 {
15580 value: valueBetween,
15581 onChange: onChangeBetweenControls,
15582 hideLabelFromVision,
15583 step
15584 }
15585 );
15586 }
15587 return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15588 ValidatedNumberControl,
15589 {
15590 required: !!isValid2.required,
15591 markWhenOptional,
15592 customValidity: getCustomValidity(isValid2, validity),
15593 label,
15594 help: description,
15595 value,
15596 onChange: onChangeControl,
15597 __next40pxDefaultSize: true,
15598 hideLabelFromVision,
15599 step,
15600 min: isValid2.min ? isValid2.min.constraint : void 0,
15601 max: isValid2.max ? isValid2.max.constraint : void 0,
15602 disabled
15603 }
15604 );
15605 }
15606
15607 // packages/dataviews/build-module/components/dataform-controls/integer.mjs
15608 var import_jsx_runtime86 = __toESM(require_jsx_runtime(), 1);
15609 function Integer(props) {
15610 return /* @__PURE__ */ (0, import_jsx_runtime86.jsx)(ValidatedNumber, { ...props });
15611 }
15612
15613 // packages/dataviews/build-module/components/dataform-controls/number.mjs
15614 var import_jsx_runtime87 = __toESM(require_jsx_runtime(), 1);
15615 function Number2(props) {
15616 return /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(ValidatedNumber, { ...props });
15617 }
15618
15619 // packages/dataviews/build-module/components/dataform-controls/radio.mjs
15620 var import_components38 = __toESM(require_components(), 1);
15621 var import_element48 = __toESM(require_element(), 1);
15622 var import_jsx_runtime88 = __toESM(require_jsx_runtime(), 1);
15623 var { ValidatedRadioControl } = unlock(import_components38.privateApis);
15624 function Radio({
15625 data,
15626 field,
15627 onChange,
15628 hideLabelFromVision,
15629 markWhenOptional,
15630 validity
15631 }) {
15632 const { label, description, getValue, setValue, isValid: isValid2 } = field;
15633 const disabled = field.isDisabled({ item: data, field });
15634 const { elements, isLoading } = useElements({
15635 elements: field.elements,
15636 getElements: field.getElements
15637 });
15638 const value = getValue({ item: data });
15639 const onChangeControl = (0, import_element48.useCallback)(
15640 (newValue) => onChange(setValue({ item: data, value: newValue })),
15641 [data, onChange, setValue]
15642 );
15643 if (isLoading) {
15644 return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(import_components38.Spinner, {});
15645 }
15646 return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(
15647 ValidatedRadioControl,
15648 {
15649 required: !!field.isValid?.required,
15650 markWhenOptional,
15651 customValidity: getCustomValidity(isValid2, validity),
15652 label,
15653 help: description,
15654 onChange: onChangeControl,
15655 options: elements,
15656 selected: value,
15657 hideLabelFromVision,
15658 disabled
15659 }
15660 );
15661 }
15662
15663 // packages/dataviews/build-module/components/dataform-controls/text.mjs
15664 var import_element49 = __toESM(require_element(), 1);
15665 var import_jsx_runtime89 = __toESM(require_jsx_runtime(), 1);
15666 function Text({
15667 data,
15668 field,
15669 onChange,
15670 hideLabelFromVision,
15671 markWhenOptional,
15672 config,
15673 validity
15674 }) {
15675 const { prefix, suffix } = config || {};
15676 return /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(
15677 ValidatedText,
15678 {
15679 ...{
15680 data,
15681 field,
15682 onChange,
15683 hideLabelFromVision,
15684 markWhenOptional,
15685 validity,
15686 prefix: prefix ? (0, import_element49.createElement)(prefix) : void 0,
15687 suffix: suffix ? (0, import_element49.createElement)(suffix) : void 0
15688 }
15689 }
15690 );
15691 }
15692
15693 // packages/dataviews/build-module/components/dataform-controls/toggle.mjs
15694 var import_components39 = __toESM(require_components(), 1);
15695 var import_element50 = __toESM(require_element(), 1);
15696 var import_jsx_runtime90 = __toESM(require_jsx_runtime(), 1);
15697 var { ValidatedToggleControl } = unlock(import_components39.privateApis);
15698 function Toggle({
15699 field,
15700 onChange,
15701 data,
15702 hideLabelFromVision,
15703 markWhenOptional,
15704 validity
15705 }) {
15706 const { label, description, getValue, setValue, isValid: isValid2 } = field;
15707 const disabled = field.isDisabled({ item: data, field });
15708 const onChangeControl = (0, import_element50.useCallback)(() => {
15709 onChange(
15710 setValue({ item: data, value: !getValue({ item: data }) })
15711 );
15712 }, [onChange, setValue, data, getValue]);
15713 return /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(
15714 ValidatedToggleControl,
15715 {
15716 required: !!isValid2.required,
15717 markWhenOptional,
15718 customValidity: getCustomValidity(isValid2, validity),
15719 hidden: hideLabelFromVision,
15720 label,
15721 help: description,
15722 checked: getValue({ item: data }),
15723 onChange: onChangeControl,
15724 disabled
15725 }
15726 );
15727 }
15728
15729 // packages/dataviews/build-module/components/dataform-controls/textarea.mjs
15730 var import_components40 = __toESM(require_components(), 1);
15731 var import_element51 = __toESM(require_element(), 1);
15732 var import_jsx_runtime91 = __toESM(require_jsx_runtime(), 1);
15733 var { ValidatedTextareaControl } = unlock(import_components40.privateApis);
15734 function Textarea({
15735 data,
15736 field,
15737 onChange,
15738 hideLabelFromVision,
15739 markWhenOptional,
15740 config,
15741 validity
15742 }) {
15743 const { rows = 4 } = config || {};
15744 const disabled = field.isDisabled({ item: data, field });
15745 const { label, placeholder, description, setValue, isValid: isValid2 } = field;
15746 const value = field.getValue({ item: data });
15747 const onChangeControl = (0, import_element51.useCallback)(
15748 (newValue) => onChange(setValue({ item: data, value: newValue })),
15749 [data, onChange, setValue]
15750 );
15751 return /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
15752 ValidatedTextareaControl,
15753 {
15754 required: !!isValid2.required,
15755 markWhenOptional,
15756 customValidity: getCustomValidity(isValid2, validity),
15757 label,
15758 placeholder,
15759 value: value ?? "",
15760 help: description,
15761 onChange: onChangeControl,
15762 rows,
15763 disabled,
15764 minLength: isValid2.minLength ? isValid2.minLength.constraint : void 0,
15765 maxLength: isValid2.maxLength ? isValid2.maxLength.constraint : void 0,
15766 __next40pxDefaultSize: true,
15767 hideLabelFromVision
15768 }
15769 );
15770 }
15771
15772 // packages/dataviews/build-module/components/dataform-controls/toggle-group.mjs
15773 var import_components41 = __toESM(require_components(), 1);
15774 var import_element52 = __toESM(require_element(), 1);
15775 var import_jsx_runtime92 = __toESM(require_jsx_runtime(), 1);
15776 var { ValidatedToggleGroupControl } = unlock(import_components41.privateApis);
15777 function ToggleGroup({
15778 data,
15779 field,
15780 onChange,
15781 hideLabelFromVision,
15782 markWhenOptional,
15783 validity
15784 }) {
15785 const { getValue, setValue, isValid: isValid2 } = field;
15786 const disabled = field.isDisabled({ item: data, field });
15787 const value = getValue({ item: data });
15788 const onChangeControl = (0, import_element52.useCallback)(
15789 (newValue) => onChange(setValue({ item: data, value: newValue })),
15790 [data, onChange, setValue]
15791 );
15792 const { elements, isLoading } = useElements({
15793 elements: field.elements,
15794 getElements: field.getElements
15795 });
15796 if (isLoading) {
15797 return /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(import_components41.Spinner, {});
15798 }
15799 if (elements.length === 0) {
15800 return null;
15801 }
15802 const selectedOption = elements.find((el) => el.value === value);
15803 return /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
15804 ValidatedToggleGroupControl,
15805 {
15806 required: !!field.isValid?.required,
15807 markWhenOptional,
15808 customValidity: getCustomValidity(isValid2, validity),
15809 __next40pxDefaultSize: true,
15810 isBlock: true,
15811 label: field.label,
15812 help: selectedOption?.description || field.description,
15813 onChange: onChangeControl,
15814 value,
15815 hideLabelFromVision,
15816 children: elements.map((el) => /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
15817 import_components41.__experimentalToggleGroupControlOption,
15818 {
15819 label: el.label,
15820 value: el.value,
15821 disabled
15822 },
15823 el.value
15824 ))
15825 }
15826 );
15827 }
15828
15829 // packages/dataviews/build-module/components/dataform-controls/array.mjs
15830 var import_components42 = __toESM(require_components(), 1);
15831 var import_element53 = __toESM(require_element(), 1);
15832 var import_jsx_runtime93 = __toESM(require_jsx_runtime(), 1);
15833 var { ValidatedFormTokenField } = unlock(import_components42.privateApis);
15834 function ArrayControl({
15835 data,
15836 field,
15837 onChange,
15838 hideLabelFromVision,
15839 markWhenOptional,
15840 validity
15841 }) {
15842 const { label, placeholder, description, getValue, setValue, isValid: isValid2 } = field;
15843 const value = getValue({ item: data });
15844 const disabled = field.isDisabled({ item: data, field });
15845 const { elements, isLoading } = useElements({
15846 elements: field.elements,
15847 getElements: field.getElements
15848 });
15849 const arrayValueAsElements = (0, import_element53.useMemo)(
15850 () => Array.isArray(value) ? value.map((token) => {
15851 const element = elements?.find(
15852 (suggestion) => suggestion.value === token
15853 );
15854 return element || { value: token, label: token };
15855 }) : [],
15856 [value, elements]
15857 );
15858 const onChangeControl = (0, import_element53.useCallback)(
15859 (tokens) => {
15860 const valueTokens = tokens.map((token) => {
15861 if (typeof token === "object" && "value" in token) {
15862 return token.value;
15863 }
15864 return token;
15865 });
15866 onChange(setValue({ item: data, value: valueTokens }));
15867 },
15868 [onChange, setValue, data]
15869 );
15870 if (isLoading) {
15871 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_components42.Spinner, {});
15872 }
15873 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
15874 ValidatedFormTokenField,
15875 {
15876 required: !!isValid2?.required,
15877 markWhenOptional,
15878 customValidity: getCustomValidity(isValid2, validity),
15879 label: hideLabelFromVision ? void 0 : label,
15880 value: arrayValueAsElements,
15881 onChange: onChangeControl,
15882 placeholder,
15883 suggestions: elements?.map((element) => element.value),
15884 disabled,
15885 __experimentalValidateInput: (token) => {
15886 if (field.isValid?.elements && elements) {
15887 return elements.some(
15888 (element) => element.value === token || element.label === token
15889 );
15890 }
15891 return true;
15892 },
15893 __experimentalExpandOnFocus: elements && elements.length > 0,
15894 help: description ?? (field.isValid?.elements ? "" : void 0),
15895 displayTransform: (token) => {
15896 if (typeof token === "object" && "label" in token) {
15897 return token.label;
15898 }
15899 if (typeof token === "string" && elements) {
15900 const element = elements.find(
15901 (el) => el.value === token
15902 );
15903 return element?.label || token;
15904 }
15905 return token;
15906 },
15907 __experimentalRenderItem: ({ item }) => {
15908 if (typeof item === "string" && elements) {
15909 const element = elements.find(
15910 (el) => el.value === item
15911 );
15912 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)("span", { children: element?.label || item });
15913 }
15914 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)("span", { children: item });
15915 }
15916 }
15917 );
15918 }
15919
15920 // node_modules/colord/index.mjs
15921 var r2 = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) };
15922 var t = function(r3) {
15923 return "string" == typeof r3 ? r3.length > 0 : "number" == typeof r3;
15924 };
15925 var n = function(r3, t2, n2) {
15926 return void 0 === t2 && (t2 = 0), void 0 === n2 && (n2 = Math.pow(10, t2)), Math.round(n2 * r3) / n2 + 0;
15927 };
15928 var e = function(r3, t2, n2) {
15929 return void 0 === t2 && (t2 = 0), void 0 === n2 && (n2 = 1), r3 > n2 ? n2 : r3 > t2 ? r3 : t2;
15930 };
15931 var u = function(r3) {
15932 return (r3 = isFinite(r3) ? r3 % 360 : 0) > 0 ? r3 : r3 + 360;
15933 };
15934 var a = function(r3) {
15935 return { r: e(r3.r, 0, 255), g: e(r3.g, 0, 255), b: e(r3.b, 0, 255), a: e(r3.a) };
15936 };
15937 var o = function(r3) {
15938 return { r: n(r3.r), g: n(r3.g), b: n(r3.b), a: n(r3.a, 3) };
15939 };
15940 var i = /^#([0-9a-f]{3,8})$/i;
15941 var s = function(r3) {
15942 var t2 = r3.toString(16);
15943 return t2.length < 2 ? "0" + t2 : t2;
15944 };
15945 var h = function(r3) {
15946 var t2 = r3.r, n2 = r3.g, e2 = r3.b, u2 = r3.a, a2 = Math.max(t2, n2, e2), o2 = a2 - Math.min(t2, n2, e2), i2 = o2 ? a2 === t2 ? (n2 - e2) / o2 : a2 === n2 ? 2 + (e2 - t2) / o2 : 4 + (t2 - n2) / o2 : 0;
15947 return { h: 60 * (i2 < 0 ? i2 + 6 : i2), s: a2 ? o2 / a2 * 100 : 0, v: a2 / 255 * 100, a: u2 };
15948 };
15949 var b = function(r3) {
15950 var t2 = r3.h, n2 = r3.s, e2 = r3.v, u2 = r3.a;
15951 t2 = t2 / 360 * 6, n2 /= 100, e2 /= 100;
15952 var a2 = Math.floor(t2), o2 = e2 * (1 - n2), i2 = e2 * (1 - (t2 - a2) * n2), s2 = e2 * (1 - (1 - t2 + a2) * n2), h2 = a2 % 6;
15953 return { r: 255 * [e2, i2, o2, o2, s2, e2][h2], g: 255 * [s2, e2, e2, i2, o2, o2][h2], b: 255 * [o2, o2, s2, e2, e2, i2][h2], a: u2 };
15954 };
15955 var g = function(r3) {
15956 return { h: u(r3.h), s: e(r3.s, 0, 100), l: e(r3.l, 0, 100), a: e(r3.a) };
15957 };
15958 var d = function(r3) {
15959 return { h: n(r3.h), s: n(r3.s), l: n(r3.l), a: n(r3.a, 3) };
15960 };
15961 var f = function(r3) {
15962 return b((n2 = (t2 = r3).s, { h: t2.h, s: (n2 *= ((e2 = t2.l) < 50 ? e2 : 100 - e2) / 100) > 0 ? 2 * n2 / (e2 + n2) * 100 : 0, v: e2 + n2, a: t2.a }));
15963 var t2, n2, e2;
15964 };
15965 var c = function(r3) {
15966 return { h: (t2 = h(r3)).h, s: (u2 = (200 - (n2 = t2.s)) * (e2 = t2.v) / 100) > 0 && u2 < 200 ? n2 * e2 / 100 / (u2 <= 100 ? u2 : 200 - u2) * 100 : 0, l: u2 / 2, a: t2.a };
15967 var t2, n2, e2, u2;
15968 };
15969 var l = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15970 var p = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15971 var v = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15972 var m = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15973 var y = { string: [[function(r3) {
15974 var t2 = i.exec(r3);
15975 return t2 ? (r3 = t2[1]).length <= 4 ? { r: parseInt(r3[0] + r3[0], 16), g: parseInt(r3[1] + r3[1], 16), b: parseInt(r3[2] + r3[2], 16), a: 4 === r3.length ? n(parseInt(r3[3] + r3[3], 16) / 255, 2) : 1 } : 6 === r3.length || 8 === r3.length ? { r: parseInt(r3.substr(0, 2), 16), g: parseInt(r3.substr(2, 2), 16), b: parseInt(r3.substr(4, 2), 16), a: 8 === r3.length ? n(parseInt(r3.substr(6, 2), 16) / 255, 2) : 1 } : null : null;
15976 }, "hex"], [function(r3) {
15977 var t2 = v.exec(r3) || m.exec(r3);
15978 return t2 ? t2[2] !== t2[4] || t2[4] !== t2[6] ? null : a({ r: Number(t2[1]) / (t2[2] ? 100 / 255 : 1), g: Number(t2[3]) / (t2[4] ? 100 / 255 : 1), b: Number(t2[5]) / (t2[6] ? 100 / 255 : 1), a: void 0 === t2[7] ? 1 : Number(t2[7]) / (t2[8] ? 100 : 1) }) : null;
15979 }, "rgb"], [function(t2) {
15980 var n2 = l.exec(t2) || p.exec(t2);
15981 if (!n2) return null;
15982 var e2, u2, a2 = g({ h: (e2 = n2[1], u2 = n2[2], void 0 === u2 && (u2 = "deg"), Number(e2) * (r2[u2] || 1)), s: Number(n2[3]), l: Number(n2[4]), a: void 0 === n2[5] ? 1 : Number(n2[5]) / (n2[6] ? 100 : 1) });
15983 return f(a2);
15984 }, "hsl"]], object: [[function(r3) {
15985 var n2 = r3.r, e2 = r3.g, u2 = r3.b, o2 = r3.a, i2 = void 0 === o2 ? 1 : o2;
15986 return t(n2) && t(e2) && t(u2) ? a({ r: Number(n2), g: Number(e2), b: Number(u2), a: Number(i2) }) : null;
15987 }, "rgb"], [function(r3) {
15988 var n2 = r3.h, e2 = r3.s, u2 = r3.l, a2 = r3.a, o2 = void 0 === a2 ? 1 : a2;
15989 if (!t(n2) || !t(e2) || !t(u2)) return null;
15990 var i2 = g({ h: Number(n2), s: Number(e2), l: Number(u2), a: Number(o2) });
15991 return f(i2);
15992 }, "hsl"], [function(r3) {
15993 var n2 = r3.h, a2 = r3.s, o2 = r3.v, i2 = r3.a, s2 = void 0 === i2 ? 1 : i2;
15994 if (!t(n2) || !t(a2) || !t(o2)) return null;
15995 var h2 = (function(r4) {
15996 return { h: u(r4.h), s: e(r4.s, 0, 100), v: e(r4.v, 0, 100), a: e(r4.a) };
15997 })({ h: Number(n2), s: Number(a2), v: Number(o2), a: Number(s2) });
15998 return b(h2);
15999 }, "hsv"]] };
16000 var N = function(r3, t2) {
16001 for (var n2 = 0; n2 < t2.length; n2++) {
16002 var e2 = t2[n2][0](r3);
16003 if (e2) return [e2, t2[n2][1]];
16004 }
16005 return [null, void 0];
16006 };
16007 var x = function(r3) {
16008 return "string" == typeof r3 ? N(r3.trim(), y.string) : "object" == typeof r3 && null !== r3 ? N(r3, y.object) : [null, void 0];
16009 };
16010 var M = function(r3, t2) {
16011 var n2 = c(r3);
16012 return { h: n2.h, s: e(n2.s + 100 * t2, 0, 100), l: n2.l, a: n2.a };
16013 };
16014 var H = function(r3) {
16015 return (299 * r3.r + 587 * r3.g + 114 * r3.b) / 1e3 / 255;
16016 };
16017 var $ = function(r3, t2) {
16018 var n2 = c(r3);
16019 return { h: n2.h, s: n2.s, l: e(n2.l + 100 * t2, 0, 100), a: n2.a };
16020 };
16021 var j = (function() {
16022 function r3(r4) {
16023 this.parsed = x(r4)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
16024 }
16025 return r3.prototype.isValid = function() {
16026 return null !== this.parsed;
16027 }, r3.prototype.brightness = function() {
16028 return n(H(this.rgba), 2);
16029 }, r3.prototype.isDark = function() {
16030 return H(this.rgba) < 0.5;
16031 }, r3.prototype.isLight = function() {
16032 return H(this.rgba) >= 0.5;
16033 }, r3.prototype.toHex = function() {
16034 return r4 = o(this.rgba), t2 = r4.r, e2 = r4.g, u2 = r4.b, i2 = (a2 = r4.a) < 1 ? s(n(255 * a2)) : "", "#" + s(t2) + s(e2) + s(u2) + i2;
16035 var r4, t2, e2, u2, a2, i2;
16036 }, r3.prototype.toRgb = function() {
16037 return o(this.rgba);
16038 }, r3.prototype.toRgbString = function() {
16039 return r4 = o(this.rgba), t2 = r4.r, n2 = r4.g, e2 = r4.b, (u2 = r4.a) < 1 ? "rgba(" + t2 + ", " + n2 + ", " + e2 + ", " + u2 + ")" : "rgb(" + t2 + ", " + n2 + ", " + e2 + ")";
16040 var r4, t2, n2, e2, u2;
16041 }, r3.prototype.toHsl = function() {
16042 return d(c(this.rgba));
16043 }, r3.prototype.toHslString = function() {
16044 return r4 = d(c(this.rgba)), t2 = r4.h, n2 = r4.s, e2 = r4.l, (u2 = r4.a) < 1 ? "hsla(" + t2 + ", " + n2 + "%, " + e2 + "%, " + u2 + ")" : "hsl(" + t2 + ", " + n2 + "%, " + e2 + "%)";
16045 var r4, t2, n2, e2, u2;
16046 }, r3.prototype.toHsv = function() {
16047 return r4 = h(this.rgba), { h: n(r4.h), s: n(r4.s), v: n(r4.v), a: n(r4.a, 3) };
16048 var r4;
16049 }, r3.prototype.invert = function() {
16050 return w({ r: 255 - (r4 = this.rgba).r, g: 255 - r4.g, b: 255 - r4.b, a: r4.a });
16051 var r4;
16052 }, r3.prototype.saturate = function(r4) {
16053 return void 0 === r4 && (r4 = 0.1), w(M(this.rgba, r4));
16054 }, r3.prototype.desaturate = function(r4) {
16055 return void 0 === r4 && (r4 = 0.1), w(M(this.rgba, -r4));
16056 }, r3.prototype.grayscale = function() {
16057 return w(M(this.rgba, -1));
16058 }, r3.prototype.lighten = function(r4) {
16059 return void 0 === r4 && (r4 = 0.1), w($(this.rgba, r4));
16060 }, r3.prototype.darken = function(r4) {
16061 return void 0 === r4 && (r4 = 0.1), w($(this.rgba, -r4));
16062 }, r3.prototype.rotate = function(r4) {
16063 return void 0 === r4 && (r4 = 15), this.hue(this.hue() + r4);
16064 }, r3.prototype.alpha = function(r4) {
16065 return "number" == typeof r4 ? w({ r: (t2 = this.rgba).r, g: t2.g, b: t2.b, a: r4 }) : n(this.rgba.a, 3);
16066 var t2;
16067 }, r3.prototype.hue = function(r4) {
16068 var t2 = c(this.rgba);
16069 return "number" == typeof r4 ? w({ h: r4, s: t2.s, l: t2.l, a: t2.a }) : n(t2.h);
16070 }, r3.prototype.isEqual = function(r4) {
16071 return this.toHex() === w(r4).toHex();
16072 }, r3;
16073 })();
16074 var w = function(r3) {
16075 return r3 instanceof j ? r3 : new j(r3);
16076 };
16077
16078 // packages/dataviews/build-module/components/dataform-controls/color.mjs
16079 var import_components43 = __toESM(require_components(), 1);
16080 var import_element54 = __toESM(require_element(), 1);
16081 var import_i18n41 = __toESM(require_i18n(), 1);
16082 var import_jsx_runtime94 = __toESM(require_jsx_runtime(), 1);
16083 var { ValidatedInputControl: ValidatedInputControl3 } = unlock(import_components43.privateApis);
16084 var ColorPickerDropdown = ({
16085 color,
16086 onColorChange,
16087 disabled
16088 }) => {
16089 const validColor = color && w(color).isValid() ? color : "#ffffff";
16090 return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16091 import_components43.Dropdown,
16092 {
16093 className: "dataviews-controls__color-picker-dropdown",
16094 popoverProps: { resize: false },
16095 renderToggle: ({ onToggle }) => /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16096 import_components43.Button,
16097 {
16098 onClick: onToggle,
16099 "aria-label": (0, import_i18n41.__)("Open color picker"),
16100 size: "small",
16101 disabled,
16102 accessibleWhenDisabled: true,
16103 icon: () => /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_components43.ColorIndicator, { colorValue: validColor })
16104 }
16105 ),
16106 renderContent: () => /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_components43.__experimentalDropdownContentWrapper, { paddingSize: "none", children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16107 import_components43.ColorPicker,
16108 {
16109 color: validColor,
16110 onChange: onColorChange,
16111 enableAlpha: true
16112 }
16113 ) })
16114 }
16115 );
16116 };
16117 function Color({
16118 data,
16119 field,
16120 onChange,
16121 hideLabelFromVision,
16122 markWhenOptional,
16123 validity
16124 }) {
16125 const { label, placeholder, description, setValue, isValid: isValid2 } = field;
16126 const disabled = field.isDisabled({ item: data, field });
16127 const value = field.getValue({ item: data }) || "";
16128 const handleColorChange = (0, import_element54.useCallback)(
16129 (newColor) => {
16130 onChange(setValue({ item: data, value: newColor }));
16131 },
16132 [data, onChange, setValue]
16133 );
16134 const handleInputChange = (0, import_element54.useCallback)(
16135 (newValue) => {
16136 onChange(setValue({ item: data, value: newValue || "" }));
16137 },
16138 [data, onChange, setValue]
16139 );
16140 return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16141 ValidatedInputControl3,
16142 {
16143 required: !!field.isValid?.required,
16144 markWhenOptional,
16145 customValidity: getCustomValidity(isValid2, validity),
16146 label,
16147 placeholder,
16148 value,
16149 help: description,
16150 onChange: handleInputChange,
16151 hideLabelFromVision,
16152 type: "text",
16153 disabled,
16154 prefix: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_components43.__experimentalInputControlPrefixWrapper, { variant: "control", children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16155 ColorPickerDropdown,
16156 {
16157 color: value,
16158 onColorChange: handleColorChange,
16159 disabled
16160 }
16161 ) })
16162 }
16163 );
16164 }
16165
16166 // packages/dataviews/build-module/components/dataform-controls/password.mjs
16167 var import_components44 = __toESM(require_components(), 1);
16168 var import_element55 = __toESM(require_element(), 1);
16169 var import_i18n42 = __toESM(require_i18n(), 1);
16170 var import_jsx_runtime95 = __toESM(require_jsx_runtime(), 1);
16171 function Password({
16172 data,
16173 field,
16174 onChange,
16175 hideLabelFromVision,
16176 markWhenOptional,
16177 validity
16178 }) {
16179 const [isVisible2, setIsVisible] = (0, import_element55.useState)(false);
16180 const disabled = field.isDisabled({ item: data, field });
16181 const toggleVisibility = (0, import_element55.useCallback)(() => {
16182 setIsVisible((prev) => !prev);
16183 }, []);
16184 return /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(
16185 ValidatedText,
16186 {
16187 ...{
16188 data,
16189 field,
16190 onChange,
16191 hideLabelFromVision,
16192 markWhenOptional,
16193 validity,
16194 type: isVisible2 ? "text" : "password",
16195 suffix: /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(import_components44.__experimentalInputControlSuffixWrapper, { variant: "control", children: /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(
16196 import_components44.Button,
16197 {
16198 icon: isVisible2 ? unseen_default : seen_default,
16199 onClick: toggleVisibility,
16200 size: "small",
16201 label: isVisible2 ? (0, import_i18n42.__)("Hide password") : (0, import_i18n42.__)("Show password"),
16202 disabled,
16203 accessibleWhenDisabled: true
16204 }
16205 ) })
16206 }
16207 }
16208 );
16209 }
16210
16211 // packages/dataviews/build-module/field-types/utils/has-elements.mjs
16212 function hasElements(field) {
16213 return Array.isArray(field.elements) && field.elements.length > 0 || typeof field.getElements === "function";
16214 }
16215
16216 // packages/dataviews/build-module/components/dataform-controls/index.mjs
16217 var import_jsx_runtime96 = __toESM(require_jsx_runtime(), 1);
16218 var FORM_CONTROLS = {
16219 adaptiveSelect: AdaptiveSelect,
16220 array: ArrayControl,
16221 checkbox: Checkbox,
16222 color: Color,
16223 combobox: Combobox3,
16224 datetime: DateTime,
16225 date: DateControl,
16226 email: Email,
16227 telephone: Telephone,
16228 url: Url,
16229 integer: Integer,
16230 number: Number2,
16231 password: Password,
16232 radio: Radio,
16233 select: Select,
16234 text: Text,
16235 toggle: Toggle,
16236 textarea: Textarea,
16237 toggleGroup: ToggleGroup
16238 };
16239 function isEditConfig(value) {
16240 return value && typeof value === "object" && typeof value.control === "string";
16241 }
16242 function createConfiguredControl(config) {
16243 const { control, ...controlConfig } = config;
16244 const BaseControlType = getControlByType(control);
16245 if (BaseControlType === null) {
16246 return null;
16247 }
16248 return function ConfiguredControl(props) {
16249 return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(BaseControlType, { ...props, config: controlConfig });
16250 };
16251 }
16252 function getControl(field, fallback) {
16253 if (typeof field.Edit === "function") {
16254 return field.Edit;
16255 }
16256 if (typeof field.Edit === "string") {
16257 return getControlByType(field.Edit);
16258 }
16259 if (isEditConfig(field.Edit)) {
16260 return createConfiguredControl(field.Edit);
16261 }
16262 if (hasElements(field) && field.type !== "array") {
16263 return getControlByType("adaptiveSelect");
16264 }
16265 if (fallback === null) {
16266 return null;
16267 }
16268 return getControlByType(fallback);
16269 }
16270 function getControlByType(type) {
16271 if (Object.keys(FORM_CONTROLS).includes(type)) {
16272 return FORM_CONTROLS[type];
16273 }
16274 return null;
16275 }
16276
16277 // packages/dataviews/build-module/field-types/utils/get-filter-by.mjs
16278 function getFilterBy(field, defaultOperators, validOperators) {
16279 if (field.filterBy === false) {
16280 return false;
16281 }
16282 const operators = field.filterBy?.operators?.filter(
16283 (op) => validOperators.includes(op)
16284 ) ?? defaultOperators;
16285 if (operators.length === 0) {
16286 return false;
16287 }
16288 return {
16289 isPrimary: !!field.filterBy?.isPrimary,
16290 operators
16291 };
16292 }
16293 var get_filter_by_default = getFilterBy;
16294
16295 // packages/dataviews/build-module/field-types/utils/get-value-from-id.mjs
16296 var getValueFromId = (id) => ({ item }) => {
16297 const path = id.split(".");
16298 let value = item;
16299 for (const segment of path) {
16300 if (value.hasOwnProperty(segment)) {
16301 value = value[segment];
16302 } else {
16303 value = void 0;
16304 }
16305 }
16306 return value;
16307 };
16308 var get_value_from_id_default = getValueFromId;
16309
16310 // packages/dataviews/build-module/field-types/utils/set-value-from-id.mjs
16311 var setValueFromId = (id) => ({ value }) => {
16312 const path = id.split(".");
16313 const result = {};
16314 let current = result;
16315 for (const segment of path.slice(0, -1)) {
16316 current[segment] = {};
16317 current = current[segment];
16318 }
16319 current[path.at(-1)] = value;
16320 return result;
16321 };
16322 var set_value_from_id_default = setValueFromId;
16323
16324 // packages/dataviews/build-module/field-types/email.mjs
16325 var import_i18n43 = __toESM(require_i18n(), 1);
16326
16327 // packages/dataviews/build-module/field-types/utils/render-from-elements.mjs
16328 function RenderFromElements({
16329 item,
16330 field
16331 }) {
16332 const { elements, isLoading } = useElements({
16333 elements: field.elements,
16334 getElements: field.getElements
16335 });
16336 const value = field.getValue({ item });
16337 if (isLoading) {
16338 return value;
16339 }
16340 if (elements.length === 0) {
16341 return value;
16342 }
16343 return elements?.find((element) => element.value === value)?.label || field.getValue({ item });
16344 }
16345
16346 // packages/dataviews/build-module/field-types/utils/render-default.mjs
16347 var import_jsx_runtime97 = __toESM(require_jsx_runtime(), 1);
16348 function render({
16349 item,
16350 field
16351 }) {
16352 if (field.hasElements) {
16353 return /* @__PURE__ */ (0, import_jsx_runtime97.jsx)(RenderFromElements, { item, field });
16354 }
16355 return field.getValueFormatted({ item, field });
16356 }
16357
16358 // packages/dataviews/build-module/field-types/utils/sort-text.mjs
16359 var sort_text_default = (a2, b2, direction) => {
16360 return direction === "asc" ? a2.localeCompare(b2) : b2.localeCompare(a2);
16361 };
16362
16363 // packages/dataviews/build-module/field-types/utils/is-valid-required.mjs
16364 function isValidRequired(item, field) {
16365 const value = field.getValue({ item });
16366 return ![void 0, "", null].includes(value);
16367 }
16368
16369 // packages/dataviews/build-module/field-types/utils/is-valid-min-length.mjs
16370 function isValidMinLength(item, field) {
16371 if (typeof field.isValid.minLength?.constraint !== "number") {
16372 return false;
16373 }
16374 const value = field.getValue({ item });
16375 if ([void 0, "", null].includes(value)) {
16376 return true;
16377 }
16378 return String(value).length >= field.isValid.minLength.constraint;
16379 }
16380
16381 // packages/dataviews/build-module/field-types/utils/is-valid-max-length.mjs
16382 function isValidMaxLength(item, field) {
16383 if (typeof field.isValid.maxLength?.constraint !== "number") {
16384 return false;
16385 }
16386 const value = field.getValue({ item });
16387 if ([void 0, "", null].includes(value)) {
16388 return true;
16389 }
16390 return String(value).length <= field.isValid.maxLength.constraint;
16391 }
16392
16393 // packages/dataviews/build-module/field-types/utils/is-valid-pattern.mjs
16394 function isValidPattern(item, field) {
16395 if (field.isValid.pattern?.constraint === void 0) {
16396 return true;
16397 }
16398 try {
16399 const regexp = new RegExp(field.isValid.pattern.constraint);
16400 const value = field.getValue({ item });
16401 if ([void 0, "", null].includes(value)) {
16402 return true;
16403 }
16404 return regexp.test(String(value));
16405 } catch {
16406 return false;
16407 }
16408 }
16409
16410 // packages/dataviews/build-module/field-types/utils/is-valid-elements.mjs
16411 function isValidElements(item, field) {
16412 const elements = field.elements ?? [];
16413 const validValues = elements.map((el) => el.value);
16414 if (validValues.length === 0) {
16415 return true;
16416 }
16417 const value = field.getValue({ item });
16418 return [].concat(value).every((v2) => validValues.includes(v2));
16419 }
16420
16421 // packages/dataviews/build-module/field-types/utils/get-value-formatted-default.mjs
16422 function getValueFormatted({
16423 item,
16424 field
16425 }) {
16426 return field.getValue({ item });
16427 }
16428 var get_value_formatted_default_default = getValueFormatted;
16429
16430 // packages/dataviews/build-module/field-types/email.mjs
16431 var emailRegex = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
16432 function isValidCustom(item, field) {
16433 const value = field.getValue({ item });
16434 if (![void 0, "", null].includes(value) && !emailRegex.test(value)) {
16435 return (0, import_i18n43.__)("Value must be a valid email address.");
16436 }
16437 return null;
16438 }
16439 var email_default = {
16440 type: "email",
16441 render,
16442 Edit: "email",
16443 sort: sort_text_default,
16444 enableSorting: true,
16445 enableGlobalSearch: false,
16446 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16447 validOperators: [
16448 OPERATOR_IS,
16449 OPERATOR_IS_NOT,
16450 OPERATOR_CONTAINS,
16451 OPERATOR_NOT_CONTAINS,
16452 OPERATOR_STARTS_WITH,
16453 // Multiple selection
16454 OPERATOR_IS_ANY,
16455 OPERATOR_IS_NONE,
16456 OPERATOR_IS_ALL,
16457 OPERATOR_IS_NOT_ALL
16458 ],
16459 format: {},
16460 getValueFormatted: get_value_formatted_default_default,
16461 validate: {
16462 required: isValidRequired,
16463 pattern: isValidPattern,
16464 minLength: isValidMinLength,
16465 maxLength: isValidMaxLength,
16466 elements: isValidElements,
16467 custom: isValidCustom
16468 }
16469 };
16470
16471 // packages/dataviews/build-module/field-types/integer.mjs
16472 var import_i18n44 = __toESM(require_i18n(), 1);
16473
16474 // packages/dataviews/build-module/field-types/utils/sort-number.mjs
16475 var sort_number_default = (a2, b2, direction) => {
16476 return direction === "asc" ? a2 - b2 : b2 - a2;
16477 };
16478
16479 // packages/dataviews/build-module/field-types/utils/is-valid-min.mjs
16480 function isValidMin(item, field) {
16481 if (typeof field.isValid.min?.constraint !== "number") {
16482 return false;
16483 }
16484 const value = field.getValue({ item });
16485 if ([void 0, "", null].includes(value)) {
16486 return true;
16487 }
16488 return Number(value) >= field.isValid.min.constraint;
16489 }
16490
16491 // packages/dataviews/build-module/field-types/utils/is-valid-max.mjs
16492 function isValidMax(item, field) {
16493 if (typeof field.isValid.max?.constraint !== "number") {
16494 return false;
16495 }
16496 const value = field.getValue({ item });
16497 if ([void 0, "", null].includes(value)) {
16498 return true;
16499 }
16500 return Number(value) <= field.isValid.max.constraint;
16501 }
16502
16503 // packages/dataviews/build-module/field-types/integer.mjs
16504 var format2 = {
16505 separatorThousand: ","
16506 };
16507 function getValueFormatted2({
16508 item,
16509 field
16510 }) {
16511 let value = field.getValue({ item });
16512 if (value === null || value === void 0) {
16513 return "";
16514 }
16515 value = Number(value);
16516 if (!Number.isFinite(value)) {
16517 return String(value);
16518 }
16519 let formatInteger;
16520 if (field.type !== "integer") {
16521 formatInteger = format2;
16522 } else {
16523 formatInteger = field.format;
16524 }
16525 const { separatorThousand } = formatInteger;
16526 const integerValue = Math.trunc(value);
16527 if (!separatorThousand) {
16528 return String(integerValue);
16529 }
16530 return String(integerValue).replace(
16531 /\B(?=(\d{3})+(?!\d))/g,
16532 separatorThousand
16533 );
16534 }
16535 function isValidCustom2(item, field) {
16536 const value = field.getValue({ item });
16537 if (![void 0, "", null].includes(value) && !Number.isInteger(value)) {
16538 return (0, import_i18n44.__)("Value must be an integer.");
16539 }
16540 return null;
16541 }
16542 var integer_default = {
16543 type: "integer",
16544 render,
16545 Edit: "integer",
16546 sort: sort_number_default,
16547 enableSorting: true,
16548 enableGlobalSearch: false,
16549 defaultOperators: [
16550 OPERATOR_IS,
16551 OPERATOR_IS_NOT,
16552 OPERATOR_LESS_THAN,
16553 OPERATOR_GREATER_THAN,
16554 OPERATOR_LESS_THAN_OR_EQUAL,
16555 OPERATOR_GREATER_THAN_OR_EQUAL,
16556 OPERATOR_BETWEEN
16557 ],
16558 validOperators: [
16559 // Single-selection
16560 OPERATOR_IS,
16561 OPERATOR_IS_NOT,
16562 OPERATOR_LESS_THAN,
16563 OPERATOR_GREATER_THAN,
16564 OPERATOR_LESS_THAN_OR_EQUAL,
16565 OPERATOR_GREATER_THAN_OR_EQUAL,
16566 OPERATOR_BETWEEN,
16567 // Multiple-selection
16568 OPERATOR_IS_ANY,
16569 OPERATOR_IS_NONE,
16570 OPERATOR_IS_ALL,
16571 OPERATOR_IS_NOT_ALL
16572 ],
16573 format: format2,
16574 getValueFormatted: getValueFormatted2,
16575 validate: {
16576 required: isValidRequired,
16577 min: isValidMin,
16578 max: isValidMax,
16579 elements: isValidElements,
16580 custom: isValidCustom2
16581 }
16582 };
16583
16584 // packages/dataviews/build-module/field-types/number.mjs
16585 var import_i18n45 = __toESM(require_i18n(), 1);
16586 var format3 = {
16587 separatorThousand: ",",
16588 separatorDecimal: ".",
16589 decimals: 2
16590 };
16591 function getValueFormatted3({
16592 item,
16593 field
16594 }) {
16595 let value = field.getValue({ item });
16596 if (value === null || value === void 0) {
16597 return "";
16598 }
16599 value = Number(value);
16600 if (!Number.isFinite(value)) {
16601 return String(value);
16602 }
16603 let formatNumber;
16604 if (field.type !== "number") {
16605 formatNumber = format3;
16606 } else {
16607 formatNumber = field.format;
16608 }
16609 const { separatorThousand, separatorDecimal, decimals } = formatNumber;
16610 const fixedValue = value.toFixed(decimals);
16611 const [integerPart, decimalPart] = fixedValue.split(".");
16612 const formattedInteger = separatorThousand ? integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, separatorThousand) : integerPart;
16613 return decimals === 0 ? formattedInteger : formattedInteger + separatorDecimal + decimalPart;
16614 }
16615 function isEmpty2(value) {
16616 return value === "" || value === void 0 || value === null;
16617 }
16618 function isValidCustom3(item, field) {
16619 const value = field.getValue({ item });
16620 if (!isEmpty2(value) && !Number.isFinite(value)) {
16621 return (0, import_i18n45.__)("Value must be a number.");
16622 }
16623 return null;
16624 }
16625 var number_default = {
16626 type: "number",
16627 render,
16628 Edit: "number",
16629 sort: sort_number_default,
16630 enableSorting: true,
16631 enableGlobalSearch: false,
16632 defaultOperators: [
16633 OPERATOR_IS,
16634 OPERATOR_IS_NOT,
16635 OPERATOR_LESS_THAN,
16636 OPERATOR_GREATER_THAN,
16637 OPERATOR_LESS_THAN_OR_EQUAL,
16638 OPERATOR_GREATER_THAN_OR_EQUAL,
16639 OPERATOR_BETWEEN
16640 ],
16641 validOperators: [
16642 // Single-selection
16643 OPERATOR_IS,
16644 OPERATOR_IS_NOT,
16645 OPERATOR_LESS_THAN,
16646 OPERATOR_GREATER_THAN,
16647 OPERATOR_LESS_THAN_OR_EQUAL,
16648 OPERATOR_GREATER_THAN_OR_EQUAL,
16649 OPERATOR_BETWEEN,
16650 // Multiple-selection
16651 OPERATOR_IS_ANY,
16652 OPERATOR_IS_NONE,
16653 OPERATOR_IS_ALL,
16654 OPERATOR_IS_NOT_ALL
16655 ],
16656 format: format3,
16657 getValueFormatted: getValueFormatted3,
16658 validate: {
16659 required: isValidRequired,
16660 min: isValidMin,
16661 max: isValidMax,
16662 elements: isValidElements,
16663 custom: isValidCustom3
16664 }
16665 };
16666
16667 // packages/dataviews/build-module/field-types/text.mjs
16668 var text_default = {
16669 type: "text",
16670 render,
16671 Edit: "text",
16672 sort: sort_text_default,
16673 enableSorting: true,
16674 enableGlobalSearch: false,
16675 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16676 validOperators: [
16677 // Single selection
16678 OPERATOR_IS,
16679 OPERATOR_IS_NOT,
16680 OPERATOR_CONTAINS,
16681 OPERATOR_NOT_CONTAINS,
16682 OPERATOR_STARTS_WITH,
16683 // Multiple selection
16684 OPERATOR_IS_ANY,
16685 OPERATOR_IS_NONE,
16686 OPERATOR_IS_ALL,
16687 OPERATOR_IS_NOT_ALL
16688 ],
16689 format: {},
16690 getValueFormatted: get_value_formatted_default_default,
16691 validate: {
16692 required: isValidRequired,
16693 pattern: isValidPattern,
16694 minLength: isValidMinLength,
16695 maxLength: isValidMaxLength,
16696 elements: isValidElements
16697 }
16698 };
16699
16700 // packages/dataviews/build-module/field-types/datetime.mjs
16701 var import_date7 = __toESM(require_date(), 1);
16702
16703 // packages/dataviews/build-module/field-types/utils/is-valid-date-boundary.mjs
16704 var import_date6 = __toESM(require_date(), 1);
16705 function parseDateLike(value) {
16706 if (!value) {
16707 return null;
16708 }
16709 if (!isValid(new Date(value))) {
16710 return null;
16711 }
16712 const parsed = (0, import_date6.getDate)(value);
16713 return parsed && isValid(parsed) ? parsed : null;
16714 }
16715 function validateDateLikeBoundary(item, field, boundary) {
16716 const constraint = field.isValid[boundary]?.constraint;
16717 if (typeof constraint !== "string") {
16718 return false;
16719 }
16720 const value = field.getValue({ item });
16721 const boundaryValue = Array.isArray(value) ? value[boundary === "min" ? 0 : value.length - 1] : value;
16722 if (boundaryValue === void 0 || boundaryValue === null || boundaryValue === "") {
16723 return true;
16724 }
16725 const parsedConstraint = parseDateLike(constraint);
16726 const parsedValue = parseDateLike(String(boundaryValue));
16727 return !!parsedConstraint && !!parsedValue && (boundary === "min" ? parsedValue.getTime() >= parsedConstraint.getTime() : parsedValue.getTime() <= parsedConstraint.getTime());
16728 }
16729 function isValidMinDate(item, field) {
16730 return validateDateLikeBoundary(item, field, "min");
16731 }
16732 function isValidMaxDate(item, field) {
16733 return validateDateLikeBoundary(item, field, "max");
16734 }
16735
16736 // packages/dataviews/build-module/field-types/datetime.mjs
16737 var format4 = {
16738 datetime: (0, import_date7.getSettings)().formats.datetime,
16739 weekStartsOn: (0, import_date7.getSettings)().l10n.startOfWeek
16740 };
16741 function getValueFormatted4({
16742 item,
16743 field
16744 }) {
16745 const value = field.getValue({ item });
16746 if (["", void 0, null].includes(value)) {
16747 return "";
16748 }
16749 let formatDatetime;
16750 if (field.type !== "datetime") {
16751 formatDatetime = format4;
16752 } else {
16753 formatDatetime = field.format;
16754 }
16755 return (0, import_date7.dateI18n)(formatDatetime.datetime, (0, import_date7.getDate)(value));
16756 }
16757 var sort = (a2, b2, direction) => {
16758 const timeA = new Date(a2).getTime();
16759 const timeB = new Date(b2).getTime();
16760 return direction === "asc" ? timeA - timeB : timeB - timeA;
16761 };
16762 var datetime_default = {
16763 type: "datetime",
16764 render,
16765 Edit: "datetime",
16766 sort,
16767 enableSorting: true,
16768 enableGlobalSearch: false,
16769 defaultOperators: [
16770 OPERATOR_ON,
16771 OPERATOR_NOT_ON,
16772 OPERATOR_BEFORE,
16773 OPERATOR_AFTER,
16774 OPERATOR_BEFORE_INC,
16775 OPERATOR_AFTER_INC,
16776 OPERATOR_IN_THE_PAST,
16777 OPERATOR_OVER
16778 ],
16779 validOperators: [
16780 OPERATOR_ON,
16781 OPERATOR_NOT_ON,
16782 OPERATOR_BEFORE,
16783 OPERATOR_AFTER,
16784 OPERATOR_BEFORE_INC,
16785 OPERATOR_AFTER_INC,
16786 OPERATOR_IN_THE_PAST,
16787 OPERATOR_OVER
16788 ],
16789 format: format4,
16790 getValueFormatted: getValueFormatted4,
16791 validate: {
16792 required: isValidRequired,
16793 elements: isValidElements,
16794 min: isValidMinDate,
16795 max: isValidMaxDate
16796 }
16797 };
16798
16799 // packages/dataviews/build-module/field-types/date.mjs
16800 var import_date8 = __toESM(require_date(), 1);
16801 var format5 = {
16802 date: (0, import_date8.getSettings)().formats.date,
16803 weekStartsOn: (0, import_date8.getSettings)().l10n.startOfWeek
16804 };
16805 function getValueFormatted5({
16806 item,
16807 field
16808 }) {
16809 const value = field.getValue({ item });
16810 if (["", void 0, null].includes(value)) {
16811 return "";
16812 }
16813 let formatDate2;
16814 if (field.type !== "date") {
16815 formatDate2 = format5;
16816 } else {
16817 formatDate2 = field.format;
16818 }
16819 return (0, import_date8.dateI18n)(formatDate2.date, (0, import_date8.getDate)(value));
16820 }
16821 var sort2 = (a2, b2, direction) => {
16822 const timeA = new Date(a2).getTime();
16823 const timeB = new Date(b2).getTime();
16824 return direction === "asc" ? timeA - timeB : timeB - timeA;
16825 };
16826 var date_default = {
16827 type: "date",
16828 render,
16829 Edit: "date",
16830 sort: sort2,
16831 enableSorting: true,
16832 enableGlobalSearch: false,
16833 defaultOperators: [
16834 OPERATOR_ON,
16835 OPERATOR_NOT_ON,
16836 OPERATOR_BEFORE,
16837 OPERATOR_AFTER,
16838 OPERATOR_BEFORE_INC,
16839 OPERATOR_AFTER_INC,
16840 OPERATOR_IN_THE_PAST,
16841 OPERATOR_OVER,
16842 OPERATOR_BETWEEN
16843 ],
16844 validOperators: [
16845 OPERATOR_ON,
16846 OPERATOR_NOT_ON,
16847 OPERATOR_BEFORE,
16848 OPERATOR_AFTER,
16849 OPERATOR_BEFORE_INC,
16850 OPERATOR_AFTER_INC,
16851 OPERATOR_IN_THE_PAST,
16852 OPERATOR_OVER,
16853 OPERATOR_BETWEEN
16854 ],
16855 format: format5,
16856 getValueFormatted: getValueFormatted5,
16857 validate: {
16858 required: isValidRequired,
16859 elements: isValidElements,
16860 min: isValidMinDate,
16861 max: isValidMaxDate
16862 }
16863 };
16864
16865 // packages/dataviews/build-module/field-types/boolean.mjs
16866 var import_i18n46 = __toESM(require_i18n(), 1);
16867
16868 // packages/dataviews/build-module/field-types/utils/is-valid-required-for-bool.mjs
16869 function isValidRequiredForBool(item, field) {
16870 const value = field.getValue({ item });
16871 return value === true;
16872 }
16873
16874 // packages/dataviews/build-module/field-types/boolean.mjs
16875 function getValueFormatted6({
16876 item,
16877 field
16878 }) {
16879 const value = field.getValue({ item });
16880 if (value === true) {
16881 return (0, import_i18n46.__)("True");
16882 }
16883 if (value === false) {
16884 return (0, import_i18n46.__)("False");
16885 }
16886 return "";
16887 }
16888 function isValidCustom4(item, field) {
16889 const value = field.getValue({ item });
16890 if (![void 0, "", null].includes(value) && ![true, false].includes(value)) {
16891 return (0, import_i18n46.__)("Value must be true, false, or undefined");
16892 }
16893 return null;
16894 }
16895 var sort3 = (a2, b2, direction) => {
16896 const boolA = Boolean(a2);
16897 const boolB = Boolean(b2);
16898 if (boolA === boolB) {
16899 return 0;
16900 }
16901 if (direction === "asc") {
16902 return boolA ? 1 : -1;
16903 }
16904 return boolA ? -1 : 1;
16905 };
16906 var boolean_default = {
16907 type: "boolean",
16908 render,
16909 Edit: "checkbox",
16910 sort: sort3,
16911 validate: {
16912 required: isValidRequiredForBool,
16913 elements: isValidElements,
16914 custom: isValidCustom4
16915 },
16916 enableSorting: true,
16917 enableGlobalSearch: false,
16918 defaultOperators: [OPERATOR_IS, OPERATOR_IS_NOT],
16919 validOperators: [OPERATOR_IS, OPERATOR_IS_NOT],
16920 format: {},
16921 getValueFormatted: getValueFormatted6
16922 };
16923
16924 // packages/dataviews/build-module/field-types/media.mjs
16925 var media_default = {
16926 type: "media",
16927 render: () => null,
16928 Edit: null,
16929 sort: () => 0,
16930 enableSorting: false,
16931 enableGlobalSearch: false,
16932 defaultOperators: [],
16933 validOperators: [],
16934 format: {},
16935 getValueFormatted: get_value_formatted_default_default,
16936 // cannot validate any constraint, so
16937 // the only available validation for the field author
16938 // would be providing a custom validator.
16939 validate: {}
16940 };
16941
16942 // packages/dataviews/build-module/field-types/array.mjs
16943 var import_i18n47 = __toESM(require_i18n(), 1);
16944
16945 // packages/dataviews/build-module/field-types/utils/is-valid-required-for-array.mjs
16946 function isValidRequiredForArray(item, field) {
16947 const value = field.getValue({ item });
16948 return Array.isArray(value) && value.length > 0 && value.every(
16949 (element) => ![void 0, "", null].includes(element)
16950 );
16951 }
16952
16953 // packages/dataviews/build-module/field-types/array.mjs
16954 function getValueFormatted7({
16955 item,
16956 field
16957 }) {
16958 const value = field.getValue({ item });
16959 const arr = Array.isArray(value) ? value : [];
16960 return arr.join(", ");
16961 }
16962 function render2({ item, field }) {
16963 return getValueFormatted7({ item, field });
16964 }
16965 function isValidCustom5(item, field) {
16966 const value = field.getValue({ item });
16967 if (![void 0, "", null].includes(value) && !Array.isArray(value)) {
16968 return (0, import_i18n47.__)("Value must be an array.");
16969 }
16970 if (!value.every((v2) => typeof v2 === "string")) {
16971 return (0, import_i18n47.__)("Every value must be a string.");
16972 }
16973 return null;
16974 }
16975 var sort4 = (a2, b2, direction) => {
16976 const arrA = Array.isArray(a2) ? a2 : [];
16977 const arrB = Array.isArray(b2) ? b2 : [];
16978 if (arrA.length !== arrB.length) {
16979 return direction === "asc" ? arrA.length - arrB.length : arrB.length - arrA.length;
16980 }
16981 const joinedA = arrA.join(",");
16982 const joinedB = arrB.join(",");
16983 return direction === "asc" ? joinedA.localeCompare(joinedB) : joinedB.localeCompare(joinedA);
16984 };
16985 var array_default = {
16986 type: "array",
16987 render: render2,
16988 Edit: "array",
16989 sort: sort4,
16990 enableSorting: true,
16991 enableGlobalSearch: false,
16992 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16993 validOperators: [
16994 OPERATOR_IS_ANY,
16995 OPERATOR_IS_NONE,
16996 OPERATOR_IS_ALL,
16997 OPERATOR_IS_NOT_ALL
16998 ],
16999 format: {},
17000 getValueFormatted: getValueFormatted7,
17001 validate: {
17002 required: isValidRequiredForArray,
17003 elements: isValidElements,
17004 custom: isValidCustom5
17005 }
17006 };
17007
17008 // packages/dataviews/build-module/field-types/password.mjs
17009 function getValueFormatted8({
17010 item,
17011 field
17012 }) {
17013 return field.getValue({ item }) ? "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022" : "";
17014 }
17015 var password_default = {
17016 type: "password",
17017 render,
17018 Edit: "password",
17019 sort: () => 0,
17020 // Passwords should not be sortable for security reasons
17021 enableSorting: false,
17022 enableGlobalSearch: false,
17023 defaultOperators: [],
17024 validOperators: [],
17025 format: {},
17026 getValueFormatted: getValueFormatted8,
17027 validate: {
17028 required: isValidRequired,
17029 pattern: isValidPattern,
17030 minLength: isValidMinLength,
17031 maxLength: isValidMaxLength,
17032 elements: isValidElements
17033 }
17034 };
17035
17036 // packages/dataviews/build-module/field-types/telephone.mjs
17037 var telephone_default = {
17038 type: "telephone",
17039 render,
17040 Edit: "telephone",
17041 sort: sort_text_default,
17042 enableSorting: true,
17043 enableGlobalSearch: false,
17044 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
17045 validOperators: [
17046 OPERATOR_IS,
17047 OPERATOR_IS_NOT,
17048 OPERATOR_CONTAINS,
17049 OPERATOR_NOT_CONTAINS,
17050 OPERATOR_STARTS_WITH,
17051 // Multiple selection
17052 OPERATOR_IS_ANY,
17053 OPERATOR_IS_NONE,
17054 OPERATOR_IS_ALL,
17055 OPERATOR_IS_NOT_ALL
17056 ],
17057 format: {},
17058 getValueFormatted: get_value_formatted_default_default,
17059 validate: {
17060 required: isValidRequired,
17061 pattern: isValidPattern,
17062 minLength: isValidMinLength,
17063 maxLength: isValidMaxLength,
17064 elements: isValidElements
17065 }
17066 };
17067
17068 // packages/dataviews/build-module/field-types/color.mjs
17069 var import_i18n48 = __toESM(require_i18n(), 1);
17070 var import_jsx_runtime98 = __toESM(require_jsx_runtime(), 1);
17071 function render3({ item, field }) {
17072 if (field.hasElements) {
17073 return /* @__PURE__ */ (0, import_jsx_runtime98.jsx)(RenderFromElements, { item, field });
17074 }
17075 const value = get_value_formatted_default_default({ item, field });
17076 if (!value || !w(value).isValid()) {
17077 return value;
17078 }
17079 return /* @__PURE__ */ (0, import_jsx_runtime98.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "8px" }, children: [
17080 /* @__PURE__ */ (0, import_jsx_runtime98.jsx)(
17081 "div",
17082 {
17083 style: {
17084 width: "16px",
17085 height: "16px",
17086 borderRadius: "50%",
17087 backgroundColor: value,
17088 border: "1px solid #ddd",
17089 flexShrink: 0
17090 }
17091 }
17092 ),
17093 /* @__PURE__ */ (0, import_jsx_runtime98.jsx)("span", { children: value })
17094 ] });
17095 }
17096 function isValidCustom6(item, field) {
17097 const value = field.getValue({ item });
17098 if (![void 0, "", null].includes(value) && !w(value).isValid()) {
17099 return (0, import_i18n48.__)("Value must be a valid color.");
17100 }
17101 return null;
17102 }
17103 var sort5 = (a2, b2, direction) => {
17104 const colorA = w(a2);
17105 const colorB = w(b2);
17106 if (!colorA.isValid() && !colorB.isValid()) {
17107 return 0;
17108 }
17109 if (!colorA.isValid()) {
17110 return direction === "asc" ? 1 : -1;
17111 }
17112 if (!colorB.isValid()) {
17113 return direction === "asc" ? -1 : 1;
17114 }
17115 const hslA = colorA.toHsl();
17116 const hslB = colorB.toHsl();
17117 if (hslA.h !== hslB.h) {
17118 return direction === "asc" ? hslA.h - hslB.h : hslB.h - hslA.h;
17119 }
17120 if (hslA.s !== hslB.s) {
17121 return direction === "asc" ? hslA.s - hslB.s : hslB.s - hslA.s;
17122 }
17123 return direction === "asc" ? hslA.l - hslB.l : hslB.l - hslA.l;
17124 };
17125 var color_default = {
17126 type: "color",
17127 render: render3,
17128 Edit: "color",
17129 sort: sort5,
17130 enableSorting: true,
17131 enableGlobalSearch: false,
17132 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
17133 validOperators: [
17134 OPERATOR_IS,
17135 OPERATOR_IS_NOT,
17136 OPERATOR_IS_ANY,
17137 OPERATOR_IS_NONE
17138 ],
17139 format: {},
17140 getValueFormatted: get_value_formatted_default_default,
17141 validate: {
17142 required: isValidRequired,
17143 elements: isValidElements,
17144 custom: isValidCustom6
17145 }
17146 };
17147
17148 // packages/dataviews/build-module/field-types/url.mjs
17149 var url_default = {
17150 type: "url",
17151 render,
17152 Edit: "url",
17153 sort: sort_text_default,
17154 enableSorting: true,
17155 enableGlobalSearch: false,
17156 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
17157 validOperators: [
17158 OPERATOR_IS,
17159 OPERATOR_IS_NOT,
17160 OPERATOR_CONTAINS,
17161 OPERATOR_NOT_CONTAINS,
17162 OPERATOR_STARTS_WITH,
17163 // Multiple selection
17164 OPERATOR_IS_ANY,
17165 OPERATOR_IS_NONE,
17166 OPERATOR_IS_ALL,
17167 OPERATOR_IS_NOT_ALL
17168 ],
17169 format: {},
17170 getValueFormatted: get_value_formatted_default_default,
17171 validate: {
17172 required: isValidRequired,
17173 pattern: isValidPattern,
17174 minLength: isValidMinLength,
17175 maxLength: isValidMaxLength,
17176 elements: isValidElements
17177 }
17178 };
17179
17180 // packages/dataviews/build-module/field-types/no-type.mjs
17181 var sort6 = (a2, b2, direction) => {
17182 if (typeof a2 === "number" && typeof b2 === "number") {
17183 return sort_number_default(a2, b2, direction);
17184 }
17185 return sort_text_default(a2, b2, direction);
17186 };
17187 var no_type_default = {
17188 // type: no type for this one
17189 render,
17190 Edit: null,
17191 sort: sort6,
17192 enableSorting: true,
17193 enableGlobalSearch: false,
17194 defaultOperators: [OPERATOR_IS, OPERATOR_IS_NOT],
17195 validOperators: getAllOperatorNames(),
17196 format: {},
17197 getValueFormatted: get_value_formatted_default_default,
17198 validate: {
17199 required: isValidRequired,
17200 elements: isValidElements
17201 }
17202 };
17203
17204 // packages/dataviews/build-module/field-types/utils/get-is-valid.mjs
17205 function supportsNumericRangeConstraint(type) {
17206 return type === "integer" || type === "number";
17207 }
17208 function supportsDateRangeConstraint(type) {
17209 return type === "date" || type === "datetime";
17210 }
17211 function normalizeRangeRule(value, fieldType, key) {
17212 const validator = fieldType.validate[key];
17213 if (validator && (typeof value === "number" && supportsNumericRangeConstraint(fieldType.type) || typeof value === "string" && supportsDateRangeConstraint(fieldType.type))) {
17214 return { constraint: value, validate: validator };
17215 }
17216 return void 0;
17217 }
17218 function getIsValid(field, fieldType) {
17219 const rules = field.isValid;
17220 let required;
17221 if (rules?.required === true && fieldType.validate.required !== void 0) {
17222 required = {
17223 constraint: true,
17224 validate: fieldType.validate.required
17225 };
17226 }
17227 let elements;
17228 if ((rules?.elements === true || // elements is enabled unless the field opts-out
17229 rules?.elements === void 0 && (!!field.elements || !!field.getElements)) && fieldType.validate.elements !== void 0) {
17230 elements = {
17231 constraint: true,
17232 validate: fieldType.validate.elements
17233 };
17234 }
17235 const min = normalizeRangeRule(rules?.min, fieldType, "min");
17236 const max = normalizeRangeRule(rules?.max, fieldType, "max");
17237 const minLengthValue = rules?.minLength;
17238 let minLength;
17239 if (typeof minLengthValue === "number" && fieldType.validate.minLength !== void 0) {
17240 minLength = {
17241 constraint: minLengthValue,
17242 validate: fieldType.validate.minLength
17243 };
17244 }
17245 const maxLengthValue = rules?.maxLength;
17246 let maxLength;
17247 if (typeof maxLengthValue === "number" && fieldType.validate.maxLength !== void 0) {
17248 maxLength = {
17249 constraint: maxLengthValue,
17250 validate: fieldType.validate.maxLength
17251 };
17252 }
17253 const patternValue = rules?.pattern;
17254 let pattern;
17255 if (patternValue !== void 0 && fieldType.validate.pattern !== void 0) {
17256 pattern = {
17257 constraint: patternValue,
17258 validate: fieldType.validate.pattern
17259 };
17260 }
17261 const custom = rules?.custom ?? fieldType.validate.custom;
17262 return {
17263 required,
17264 elements,
17265 min,
17266 max,
17267 minLength,
17268 maxLength,
17269 pattern,
17270 custom
17271 };
17272 }
17273
17274 // packages/dataviews/build-module/field-types/utils/get-filter.mjs
17275 function getFilter(fieldType) {
17276 return fieldType.validOperators.reduce((accumulator, operator) => {
17277 const operatorObj = getOperatorByName(operator);
17278 if (operatorObj?.filter) {
17279 accumulator[operator] = operatorObj.filter;
17280 }
17281 return accumulator;
17282 }, {});
17283 }
17284
17285 // packages/dataviews/build-module/field-types/utils/get-format.mjs
17286 function getFormat(field, fieldType) {
17287 return {
17288 ...fieldType.format,
17289 ...field.format
17290 };
17291 }
17292 var get_format_default = getFormat;
17293
17294 // packages/dataviews/build-module/field-types/index.mjs
17295 function getFieldTypeByName(type) {
17296 const found = [
17297 email_default,
17298 integer_default,
17299 number_default,
17300 text_default,
17301 datetime_default,
17302 date_default,
17303 boolean_default,
17304 media_default,
17305 array_default,
17306 password_default,
17307 telephone_default,
17308 color_default,
17309 url_default
17310 ].find((fieldType) => fieldType?.type === type);
17311 if (!!found) {
17312 return found;
17313 }
17314 return no_type_default;
17315 }
17316 function normalizeFields(fields) {
17317 return fields.map((field) => {
17318 const fieldType = getFieldTypeByName(field.type);
17319 const getValue = field.getValue || get_value_from_id_default(field.id);
17320 const sort7 = function(a2, b2, direction) {
17321 const aValue = getValue({ item: a2 });
17322 const bValue = getValue({ item: b2 });
17323 return field.sort ? field.sort(aValue, bValue, direction) : fieldType.sort(aValue, bValue, direction);
17324 };
17325 return {
17326 id: field.id,
17327 label: field.label || field.id,
17328 header: field.header || field.label || field.id,
17329 description: field.description,
17330 placeholder: field.placeholder,
17331 getValue,
17332 setValue: field.setValue || set_value_from_id_default(field.id),
17333 elements: field.elements,
17334 getElements: field.getElements,
17335 hasElements: hasElements(field),
17336 isVisible: field.isVisible,
17337 isDisabled: typeof field.isDisabled === "function" ? field.isDisabled : () => !!field.isDisabled,
17338 enableHiding: field.enableHiding ?? true,
17339 readOnly: field.readOnly ?? false,
17340 // The type provides defaults for the following props
17341 type: fieldType.type,
17342 render: field.render ?? fieldType.render,
17343 Edit: getControl(field, fieldType.Edit),
17344 sort: sort7,
17345 enableSorting: field.enableSorting ?? fieldType.enableSorting,
17346 enableGlobalSearch: field.enableGlobalSearch ?? fieldType.enableGlobalSearch,
17347 isValid: getIsValid(field, fieldType),
17348 filterBy: get_filter_by_default(
17349 field,
17350 fieldType.defaultOperators,
17351 fieldType.validOperators
17352 ),
17353 filter: getFilter(fieldType),
17354 format: get_format_default(field, fieldType),
17355 getValueFormatted: field.getValueFormatted ?? fieldType.getValueFormatted
17356 };
17357 });
17358 }
17359
17360 // packages/dataviews/build-module/hooks/use-data.mjs
17361 var import_element56 = __toESM(require_element(), 1);
17362 function useData({
17363 view,
17364 data: shownData,
17365 getItemId,
17366 isLoading,
17367 paginationInfo,
17368 selection
17369 }) {
17370 const isInfiniteScrollEnabled = view.infiniteScrollEnabled;
17371 const [hasInitiallyLoaded, setHasInitiallyLoaded] = (0, import_element56.useState)(
17372 !isLoading
17373 );
17374 (0, import_element56.useEffect)(() => {
17375 if (!isLoading) {
17376 setHasInitiallyLoaded(true);
17377 }
17378 }, [isLoading]);
17379 const previousDataRef = (0, import_element56.useRef)(shownData);
17380 const previousPaginationInfoRef = (0, import_element56.useRef)(paginationInfo);
17381 (0, import_element56.useEffect)(() => {
17382 if (!isLoading) {
17383 previousDataRef.current = shownData;
17384 previousPaginationInfoRef.current = paginationInfo;
17385 }
17386 }, [shownData, isLoading, paginationInfo]);
17387 const [visibleEntries, setVisibleEntries] = (0, import_element56.useState)([]);
17388 const positionMapRef = (0, import_element56.useRef)(/* @__PURE__ */ new Map());
17389 const allLoadedRecordsRef = (0, import_element56.useRef)([]);
17390 const prevViewParamsRef = (0, import_element56.useRef)({
17391 search: void 0,
17392 filters: void 0,
17393 perPage: void 0
17394 });
17395 const scrollDirectionRef = (0, import_element56.useRef)(void 0);
17396 const prevStartPositionRef = (0, import_element56.useRef)(void 0);
17397 const hasInitializedRef = (0, import_element56.useRef)(false);
17398 const allLoadedRecords = (0, import_element56.useMemo)(() => {
17399 if (view.startPosition !== void 0 && prevStartPositionRef.current !== void 0) {
17400 if (view.startPosition < prevStartPositionRef.current) {
17401 scrollDirectionRef.current = "up";
17402 } else if (view.startPosition > prevStartPositionRef.current) {
17403 scrollDirectionRef.current = "down";
17404 }
17405 }
17406 prevStartPositionRef.current = view.startPosition;
17407 const currentFiltersKey = JSON.stringify(view.filters ?? []);
17408 const prevFiltersKey = prevViewParamsRef.current.filters;
17409 const shouldReset = !hasInitializedRef.current || !view.infiniteScrollEnabled || view.search !== prevViewParamsRef.current.search || currentFiltersKey !== prevFiltersKey || view.perPage !== prevViewParamsRef.current.perPage;
17410 hasInitializedRef.current = true;
17411 prevViewParamsRef.current = {
17412 search: view.search,
17413 filters: currentFiltersKey,
17414 perPage: view.perPage
17415 };
17416 if (shouldReset) {
17417 positionMapRef.current.clear();
17418 scrollDirectionRef.current = void 0;
17419 const startPosition = view.search ? 1 : view.startPosition ?? 1;
17420 const records = shownData.map((record, index) => {
17421 const position = startPosition + index;
17422 positionMapRef.current.set(getItemId(record), position);
17423 return {
17424 ...record,
17425 position
17426 };
17427 });
17428 allLoadedRecordsRef.current = records;
17429 return records;
17430 }
17431 const prev = allLoadedRecordsRef.current;
17432 const shownDataIds = new Set(shownData.map(getItemId));
17433 const scrollDirection = scrollDirectionRef.current;
17434 const basePosition = view.search ? 1 : view.startPosition ?? 1;
17435 const newRecords = shownData.map((record, index) => {
17436 const itemId = getItemId(record);
17437 const position = view.infiniteScrollEnabled ? basePosition + index : void 0;
17438 if (position !== void 0) {
17439 positionMapRef.current.set(itemId, position);
17440 }
17441 return {
17442 ...record,
17443 position
17444 };
17445 });
17446 if (newRecords.length === 0) {
17447 return prev;
17448 }
17449 const prevWithoutDuplicates = prev.filter(
17450 (record) => !shownDataIds.has(getItemId(record))
17451 );
17452 const allRecords = scrollDirection === "up" ? [...newRecords, ...prevWithoutDuplicates] : [...prevWithoutDuplicates, ...newRecords];
17453 allRecords.sort((a2, b2) => {
17454 const posA = a2.position;
17455 const posB = b2.position;
17456 return posA - posB;
17457 });
17458 let result = allRecords;
17459 if (visibleEntries.length > 0) {
17460 const visibleMin = Math.min(...visibleEntries);
17461 const visibleMax = Math.max(...visibleEntries);
17462 const buffer = 20;
17463 const recordPositions = allRecords.map(
17464 (r3) => r3.position
17465 );
17466 const minRecordPos = Math.min(...recordPositions);
17467 const maxRecordPos = Math.max(...recordPositions);
17468 const hasOverlap = !(maxRecordPos < visibleMin - buffer || minRecordPos > visibleMax + buffer);
17469 if (hasOverlap) {
17470 result = allRecords.filter((record) => {
17471 const itemId = getItemId(record);
17472 const isSelected2 = selection?.includes(itemId);
17473 if (isSelected2) {
17474 return true;
17475 }
17476 const itemPosition = record.position;
17477 if (scrollDirection === "up") {
17478 return itemPosition <= visibleMax + buffer;
17479 } else if (scrollDirection === "down") {
17480 return itemPosition >= visibleMin - buffer;
17481 }
17482 return itemPosition >= visibleMin - buffer && itemPosition <= visibleMax + buffer;
17483 });
17484 }
17485 }
17486 allLoadedRecordsRef.current = result;
17487 return result;
17488 }, [
17489 shownData,
17490 view.search,
17491 view.filters,
17492 view.perPage,
17493 view.startPosition,
17494 view.infiniteScrollEnabled,
17495 visibleEntries,
17496 selection,
17497 getItemId
17498 ]);
17499 if (!isInfiniteScrollEnabled) {
17500 const dataToReturn = isLoading && previousDataRef.current?.length ? previousDataRef.current : shownData;
17501 return {
17502 data: dataToReturn.map((item) => ({
17503 ...item,
17504 position: void 0
17505 })),
17506 paginationInfo: isLoading && previousDataRef.current?.length ? previousPaginationInfoRef.current : paginationInfo,
17507 hasInitiallyLoaded,
17508 setVisibleEntries: void 0
17509 };
17510 }
17511 return {
17512 data: allLoadedRecords,
17513 paginationInfo,
17514 hasInitiallyLoaded,
17515 setVisibleEntries
17516 };
17517 }
17518
17519 // packages/dataviews/build-module/hooks/use-infinite-scroll.mjs
17520 var import_element57 = __toESM(require_element(), 1);
17521 var import_compose11 = __toESM(require_compose(), 1);
17522 function captureAnchorElement(container, anchorElementRef, direction) {
17523 const containerRect = container.getBoundingClientRect();
17524 const centerY = containerRect.top + containerRect.height / 2;
17525 const items = Array.from(container.querySelectorAll("[aria-posinset]"));
17526 if (items.length === 0) {
17527 return false;
17528 }
17529 const bestAnchor = items.reduce((best, item) => {
17530 const itemRect = item.getBoundingClientRect();
17531 const itemCenterY = itemRect.top + itemRect.height / 2;
17532 const distance = Math.abs(itemCenterY - centerY);
17533 const bestRect = best.getBoundingClientRect();
17534 const bestCenterY = bestRect.top + bestRect.height / 2;
17535 const bestDistance = Math.abs(bestCenterY - centerY);
17536 return distance < bestDistance ? item : best;
17537 });
17538 const posinset = Number(bestAnchor.getAttribute("aria-posinset"));
17539 const anchorRect = bestAnchor.getBoundingClientRect();
17540 anchorElementRef.current = {
17541 posinset,
17542 viewportOffset: anchorRect.top - containerRect.top,
17543 direction
17544 };
17545 return true;
17546 }
17547 function useInfiniteScroll({
17548 view,
17549 onChangeView,
17550 isLoading,
17551 paginationInfo,
17552 containerRef,
17553 setVisibleEntries
17554 }) {
17555 const anchorElementRef = (0, import_element57.useRef)(null);
17556 const viewRef = (0, import_element57.useRef)(view);
17557 const isLoadingRef = (0, import_element57.useRef)(isLoading);
17558 const onChangeViewRef = (0, import_element57.useRef)(onChangeView);
17559 const totalItemsRef = (0, import_element57.useRef)(paginationInfo.totalItems);
17560 (0, import_element57.useLayoutEffect)(() => {
17561 viewRef.current = view;
17562 isLoadingRef.current = isLoading;
17563 onChangeViewRef.current = onChangeView;
17564 totalItemsRef.current = paginationInfo.totalItems;
17565 }, [view, isLoading, onChangeView, paginationInfo.totalItems]);
17566 const intersectionObserverCallback = (0, import_element57.useCallback)(
17567 (entries) => {
17568 if (!setVisibleEntries) {
17569 return;
17570 }
17571 setVisibleEntries((prev) => {
17572 const newVisibleEntries = new Set(prev);
17573 let hasChanged = false;
17574 entries.forEach((entry) => {
17575 const posInSet = Number(
17576 entry.target?.attributes?.getNamedItem(
17577 "aria-posinset"
17578 )?.value
17579 );
17580 if (isNaN(posInSet)) {
17581 return;
17582 }
17583 if (entry.isIntersecting) {
17584 if (!newVisibleEntries.has(posInSet)) {
17585 newVisibleEntries.add(posInSet);
17586 hasChanged = true;
17587 }
17588 } else if (newVisibleEntries.has(posInSet)) {
17589 newVisibleEntries.delete(posInSet);
17590 hasChanged = true;
17591 }
17592 });
17593 return hasChanged ? Array.from(newVisibleEntries).sort() : prev;
17594 });
17595 },
17596 [setVisibleEntries]
17597 );
17598 (0, import_element57.useLayoutEffect)(() => {
17599 const container = containerRef.current;
17600 const anchor = anchorElementRef.current;
17601 if (!container || !view.infiniteScrollEnabled || !anchor || isLoading) {
17602 return;
17603 }
17604 const anchorElement = container.querySelector(
17605 `[aria-posinset="${anchor.posinset}"]`
17606 );
17607 if (anchorElement) {
17608 const containerRect = container.getBoundingClientRect();
17609 const anchorRect = anchorElement.getBoundingClientRect();
17610 const currentOffset = anchorRect.top - containerRect.top;
17611 const scrollAdjustment = currentOffset - anchor.viewportOffset;
17612 if (Math.abs(scrollAdjustment) > 1) {
17613 container.scrollTop += scrollAdjustment;
17614 }
17615 }
17616 anchorElementRef.current = null;
17617 }, [containerRef, isLoading, view.infiniteScrollEnabled]);
17618 const intersectionObserverRef = (0, import_element57.useRef)(
17619 null
17620 );
17621 (0, import_element57.useEffect)(() => {
17622 if (!view.infiniteScrollEnabled || !intersectionObserverCallback) {
17623 if (intersectionObserverRef.current) {
17624 intersectionObserverRef.current.disconnect();
17625 intersectionObserverRef.current = null;
17626 }
17627 return;
17628 }
17629 intersectionObserverRef.current = new IntersectionObserver(
17630 intersectionObserverCallback,
17631 { root: null, rootMargin: "0px", threshold: 0.1 }
17632 );
17633 return () => {
17634 if (intersectionObserverRef.current) {
17635 intersectionObserverRef.current.disconnect();
17636 intersectionObserverRef.current = null;
17637 }
17638 };
17639 }, [view.infiniteScrollEnabled, intersectionObserverCallback]);
17640 (0, import_element57.useEffect)(() => {
17641 if (!view.infiniteScrollEnabled || !containerRef.current) {
17642 return;
17643 }
17644 let lastScrollTop = 0;
17645 const BOTTOM_THRESHOLD = 600;
17646 const TOP_THRESHOLD = 800;
17647 const handleScroll = (0, import_compose11.throttle)((event) => {
17648 const currentView = viewRef.current;
17649 const totalItems = totalItemsRef.current;
17650 const target = event.target;
17651 const scrollTop = target.scrollTop;
17652 const scrollHeight = target.scrollHeight;
17653 const clientHeight = target.clientHeight;
17654 const scrollDirection = scrollTop > lastScrollTop ? "down" : "up";
17655 lastScrollTop = scrollTop;
17656 if (isLoadingRef.current) {
17657 return;
17658 }
17659 const currentStartPosition = currentView.startPosition || 1;
17660 const batchSize = currentView.perPage || 10;
17661 const currentEndPosition = Math.min(
17662 currentStartPosition + batchSize,
17663 totalItems
17664 );
17665 if (scrollDirection === "down" && scrollTop + clientHeight >= scrollHeight - BOTTOM_THRESHOLD) {
17666 if (currentEndPosition < totalItems) {
17667 const newStartPosition = currentEndPosition;
17668 captureAnchorElement(target, anchorElementRef, "down");
17669 onChangeViewRef.current({
17670 ...currentView,
17671 startPosition: newStartPosition
17672 });
17673 }
17674 }
17675 if (scrollDirection === "up" && scrollTop <= TOP_THRESHOLD) {
17676 if (currentStartPosition > 1) {
17677 const calculatedStartPosition = currentStartPosition - batchSize;
17678 const newStartPosition = calculatedStartPosition < 6 ? 1 : calculatedStartPosition;
17679 captureAnchorElement(target, anchorElementRef, "up");
17680 onChangeViewRef.current({
17681 ...currentView,
17682 startPosition: newStartPosition
17683 });
17684 }
17685 }
17686 }, 50);
17687 const container = containerRef.current;
17688 container.addEventListener("scroll", handleScroll);
17689 return () => {
17690 container.removeEventListener("scroll", handleScroll);
17691 handleScroll.cancel();
17692 };
17693 }, [containerRef, view.infiniteScrollEnabled]);
17694 return {
17695 intersectionObserver: intersectionObserverRef.current
17696 };
17697 }
17698
17699 // packages/dataviews/build-module/dataviews-picker/index.mjs
17700 var import_element58 = __toESM(require_element(), 1);
17701 var import_compose12 = __toESM(require_compose(), 1);
17702 var import_jsx_runtime99 = __toESM(require_jsx_runtime(), 1);
17703 var isItemClickable = () => false;
17704 var dataViewsPickerLayouts = VIEW_LAYOUTS.filter(
17705 (viewLayout) => viewLayout.isPicker
17706 );
17707 var defaultGetItemId = (item) => item.id;
17708 var EMPTY_ARRAY5 = [];
17709 var DEFAULT_PICKER_LAYOUTS = {
17710 pickerGrid: true,
17711 pickerTable: true
17712 };
17713 function DefaultUI({
17714 search = true,
17715 searchLabel = void 0
17716 }) {
17717 const { view } = (0, import_element58.useContext)(dataviews_context_default);
17718 const isInfiniteScroll = view.infiniteScrollEnabled;
17719 return /* @__PURE__ */ (0, import_jsx_runtime99.jsxs)(import_jsx_runtime99.Fragment, { children: [
17720 /* @__PURE__ */ (0, import_jsx_runtime99.jsxs)(
17721 Stack,
17722 {
17723 direction: "row",
17724 align: "top",
17725 justify: "space-between",
17726 className: clsx_default("dataviews__view-actions", {
17727 "dataviews__view-actions--infinite-scroll": isInfiniteScroll
17728 }),
17729 gap: "xs",
17730 children: [
17731 /* @__PURE__ */ (0, import_jsx_runtime99.jsxs)(
17732 Stack,
17733 {
17734 direction: "row",
17735 gap: "sm",
17736 justify: "start",
17737 className: "dataviews__search",
17738 children: [
17739 search && /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(dataviews_search_default, { label: searchLabel }),
17740 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(toggle_default, {})
17741 ]
17742 }
17743 ),
17744 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(Stack, { direction: "row", gap: "xs", style: { flexShrink: 0 }, children: /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(dataviews_view_config_default, {}) })
17745 ]
17746 }
17747 ),
17748 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(filters_toggled_default, { className: "dataviews-filters__container" }),
17749 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(DataViewsLayout, {}),
17750 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(DataViewsPickerFooter, {})
17751 ] });
17752 }
17753 function DataViewsPicker({
17754 view,
17755 onChangeView,
17756 fields,
17757 search = true,
17758 searchLabel = void 0,
17759 actions = EMPTY_ARRAY5,
17760 data,
17761 getItemId = defaultGetItemId,
17762 isLoading = false,
17763 paginationInfo,
17764 defaultLayouts: defaultLayoutsProperty = DEFAULT_PICKER_LAYOUTS,
17765 selection,
17766 onChangeSelection,
17767 children,
17768 config = { perPageSizes: [10, 20, 50, 100] },
17769 itemListLabel,
17770 empty,
17771 onReset
17772 }) {
17773 const { data: displayData, setVisibleEntries } = useData({
17774 view,
17775 data,
17776 getItemId,
17777 selection,
17778 paginationInfo
17779 });
17780 const containerRef = (0, import_element58.useRef)(null);
17781 const [containerWidth, setContainerWidth] = (0, import_element58.useState)(0);
17782 const resizeObserverRef = (0, import_compose12.useResizeObserver)(
17783 (resizeObserverEntries) => {
17784 setContainerWidth(
17785 resizeObserverEntries[0].borderBoxSize[0].inlineSize
17786 );
17787 },
17788 { box: "border-box" }
17789 );
17790 const [openedFilter, setOpenedFilter] = (0, import_element58.useState)(null);
17791 function setSelectionWithChange(value) {
17792 const newValue = typeof value === "function" ? value(selection) : value;
17793 if (onChangeSelection) {
17794 onChangeSelection(newValue);
17795 }
17796 }
17797 const _fields = (0, import_element58.useMemo)(() => normalizeFields(fields), [fields]);
17798 const filters = use_filters_default(_fields, view);
17799 const hasPrimaryOrLockedFilters = (0, import_element58.useMemo)(
17800 () => (filters || []).some(
17801 (filter) => filter.isPrimary || filter.isLocked
17802 ),
17803 [filters]
17804 );
17805 const [isShowingFilter, setIsShowingFilter] = (0, import_element58.useState)(
17806 hasPrimaryOrLockedFilters
17807 );
17808 const { intersectionObserver } = useInfiniteScroll({
17809 view,
17810 onChangeView,
17811 isLoading,
17812 paginationInfo,
17813 containerRef,
17814 setVisibleEntries
17815 });
17816 (0, import_element58.useEffect)(() => {
17817 if (hasPrimaryOrLockedFilters && !isShowingFilter) {
17818 setIsShowingFilter(true);
17819 }
17820 }, [hasPrimaryOrLockedFilters, isShowingFilter]);
17821 const defaultLayouts2 = (0, import_element58.useMemo)(
17822 () => Object.fromEntries(
17823 Object.entries(defaultLayoutsProperty).filter(([layoutType]) => {
17824 return dataViewsPickerLayouts.some(
17825 (viewLayout) => viewLayout.type === layoutType
17826 );
17827 }).map(([key, value]) => [
17828 key,
17829 value === true ? {} : value
17830 ])
17831 ),
17832 [defaultLayoutsProperty]
17833 );
17834 if (!defaultLayouts2[view.type]) {
17835 return null;
17836 }
17837 return /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(
17838 dataviews_context_default.Provider,
17839 {
17840 value: {
17841 view,
17842 onChangeView,
17843 fields: _fields,
17844 actions,
17845 data: displayData,
17846 isLoading,
17847 paginationInfo,
17848 isItemClickable,
17849 selection,
17850 onChangeSelection: setSelectionWithChange,
17851 openedFilter,
17852 setOpenedFilter,
17853 getItemId,
17854 containerWidth,
17855 containerRef,
17856 resizeObserverRef,
17857 defaultLayouts: defaultLayouts2,
17858 filters,
17859 isShowingFilter,
17860 setIsShowingFilter,
17861 config,
17862 itemListLabel,
17863 empty,
17864 onReset,
17865 hasInitiallyLoaded: true,
17866 intersectionObserver
17867 },
17868 children: /* @__PURE__ */ (0, import_jsx_runtime99.jsx)("div", { className: "dataviews-picker-wrapper", children: children ?? /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(DefaultUI, { search, searchLabel }) })
17869 }
17870 );
17871 }
17872 var DataViewsPickerSubComponents = DataViewsPicker;
17873 DataViewsPickerSubComponents.BulkActionToolbar = DataViewsPickerFooter;
17874 DataViewsPickerSubComponents.Filters = filters_default;
17875 DataViewsPickerSubComponents.FiltersToggled = filters_toggled_default;
17876 DataViewsPickerSubComponents.FiltersToggle = toggle_default;
17877 DataViewsPickerSubComponents.Layout = DataViewsLayout;
17878 DataViewsPickerSubComponents.LayoutSwitcher = ViewTypeMenu;
17879 DataViewsPickerSubComponents.Pagination = DataViewsPagination;
17880 DataViewsPickerSubComponents.Search = dataviews_search_default;
17881 DataViewsPickerSubComponents.ViewConfig = DataviewsViewConfigDropdown;
17882 var dataviews_picker_default = DataViewsPickerSubComponents;
17883
17884 // node_modules/dequal/dist/index.mjs
17885 var has = Object.prototype.hasOwnProperty;
17886 function find(iter, tar, key) {
17887 for (key of iter.keys()) {
17888 if (dequal(key, tar)) return key;
17889 }
17890 }
17891 function dequal(foo, bar) {
17892 var ctor, len, tmp;
17893 if (foo === bar) return true;
17894 if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
17895 if (ctor === Date) return foo.getTime() === bar.getTime();
17896 if (ctor === RegExp) return foo.toString() === bar.toString();
17897 if (ctor === Array) {
17898 if ((len = foo.length) === bar.length) {
17899 while (len-- && dequal(foo[len], bar[len])) ;
17900 }
17901 return len === -1;
17902 }
17903 if (ctor === Set) {
17904 if (foo.size !== bar.size) {
17905 return false;
17906 }
17907 for (len of foo) {
17908 tmp = len;
17909 if (tmp && typeof tmp === "object") {
17910 tmp = find(bar, tmp);
17911 if (!tmp) return false;
17912 }
17913 if (!bar.has(tmp)) return false;
17914 }
17915 return true;
17916 }
17917 if (ctor === Map) {
17918 if (foo.size !== bar.size) {
17919 return false;
17920 }
17921 for (len of foo) {
17922 tmp = len[0];
17923 if (tmp && typeof tmp === "object") {
17924 tmp = find(bar, tmp);
17925 if (!tmp) return false;
17926 }
17927 if (!dequal(len[1], bar.get(tmp))) {
17928 return false;
17929 }
17930 }
17931 return true;
17932 }
17933 if (ctor === ArrayBuffer) {
17934 foo = new Uint8Array(foo);
17935 bar = new Uint8Array(bar);
17936 } else if (ctor === DataView) {
17937 if ((len = foo.byteLength) === bar.byteLength) {
17938 while (len-- && foo.getInt8(len) === bar.getInt8(len)) ;
17939 }
17940 return len === -1;
17941 }
17942 if (ArrayBuffer.isView(foo)) {
17943 if ((len = foo.byteLength) === bar.byteLength) {
17944 while (len-- && foo[len] === bar[len]) ;
17945 }
17946 return len === -1;
17947 }
17948 if (!ctor || typeof foo === "object") {
17949 len = 0;
17950 for (ctor in foo) {
17951 if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
17952 if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
17953 }
17954 return Object.keys(bar).length === len;
17955 }
17956 }
17957 return foo !== foo && bar !== bar;
17958 }
17959
17960 // packages/views/build-module/use-view.mjs
17961 var import_element59 = __toESM(require_element(), 1);
17962 var import_data6 = __toESM(require_data(), 1);
17963 var import_preferences = __toESM(require_preferences(), 1);
17964
17965 // packages/views/build-module/preference-keys.mjs
17966 function generatePreferenceKey(kind, name, slug) {
17967 return `dataviews-${kind}-${name}-${slug}`;
17968 }
17969
17970 // packages/views/build-module/filter-utils.mjs
17971 var SCALAR_VALUES = [
17972 "titleField",
17973 "mediaField",
17974 "descriptionField",
17975 "showTitle",
17976 "showMedia",
17977 "showDescription",
17978 "showLevels",
17979 "infiniteScrollEnabled"
17980 ];
17981 function mergeActiveViewOverrides(view, activeViewOverrides, defaultView2) {
17982 if (!activeViewOverrides) {
17983 return view;
17984 }
17985 let result = view;
17986 for (const key of SCALAR_VALUES) {
17987 if (key in activeViewOverrides) {
17988 result = { ...result, [key]: activeViewOverrides[key] };
17989 }
17990 }
17991 if (activeViewOverrides.filters && activeViewOverrides.filters.length > 0) {
17992 const activeFields = new Set(
17993 activeViewOverrides.filters.map((f2) => f2.field)
17994 );
17995 const preserved = (view.filters ?? []).filter(
17996 (f2) => !activeFields.has(f2.field)
17997 );
17998 result = {
17999 ...result,
18000 filters: [...preserved, ...activeViewOverrides.filters]
18001 };
18002 }
18003 if (activeViewOverrides.sort) {
18004 const isDefaultSort = defaultView2 && view.sort?.field === defaultView2.sort?.field && view.sort?.direction === defaultView2.sort?.direction;
18005 if (isDefaultSort) {
18006 result = {
18007 ...result,
18008 sort: activeViewOverrides.sort
18009 };
18010 }
18011 }
18012 if (activeViewOverrides.layout) {
18013 result = {
18014 ...result,
18015 layout: {
18016 ...result.layout,
18017 ...activeViewOverrides.layout
18018 }
18019 };
18020 }
18021 if (activeViewOverrides.groupBy) {
18022 result = {
18023 ...result,
18024 groupBy: activeViewOverrides.groupBy
18025 };
18026 }
18027 return result;
18028 }
18029 function stripActiveViewOverrides(view, activeViewOverrides, defaultView2) {
18030 if (!activeViewOverrides) {
18031 return view;
18032 }
18033 let result = view;
18034 for (const key of SCALAR_VALUES) {
18035 if (key in activeViewOverrides) {
18036 const { [key]: _, ...rest } = result;
18037 result = rest;
18038 }
18039 }
18040 if (activeViewOverrides.filters && activeViewOverrides.filters.length > 0) {
18041 const activeFields = new Set(
18042 activeViewOverrides.filters.map((f2) => f2.field)
18043 );
18044 result = {
18045 ...result,
18046 filters: (view.filters ?? []).filter(
18047 (f2) => !activeFields.has(f2.field)
18048 )
18049 };
18050 }
18051 if (activeViewOverrides.sort && view.sort?.field === activeViewOverrides.sort.field && view.sort?.direction === activeViewOverrides.sort.direction) {
18052 result = {
18053 ...result,
18054 sort: defaultView2?.sort
18055 };
18056 }
18057 if (activeViewOverrides.layout && "layout" in result && result.layout) {
18058 const layout = { ...result.layout };
18059 for (const key of Object.keys(activeViewOverrides.layout)) {
18060 delete layout[key];
18061 }
18062 result = {
18063 ...result,
18064 layout: Object.keys(layout).length > 0 ? layout : void 0
18065 };
18066 }
18067 if (activeViewOverrides.groupBy && "groupBy" in result) {
18068 const { groupBy: _, ...rest } = result;
18069 result = rest;
18070 }
18071 return result;
18072 }
18073
18074 // packages/views/build-module/use-view.mjs
18075 function omit3(obj, keys) {
18076 const result = { ...obj };
18077 for (const key of keys) {
18078 delete result[key];
18079 }
18080 return result;
18081 }
18082 function useView(config) {
18083 const {
18084 kind,
18085 name,
18086 slug,
18087 defaultView: defaultView2,
18088 activeViewOverrides,
18089 queryParams,
18090 onChangeQueryParams
18091 } = config;
18092 const preferenceKey = generatePreferenceKey(kind, name, slug);
18093 const persistedView = (0, import_data6.useSelect)(
18094 (select2) => {
18095 return select2(import_preferences.store).get(
18096 "core/views",
18097 preferenceKey
18098 );
18099 },
18100 [preferenceKey]
18101 );
18102 const { set: set2 } = (0, import_data6.useDispatch)(import_preferences.store);
18103 const baseView = (0, import_element59.useMemo)(
18104 () => persistedView ?? defaultView2 ?? {},
18105 [persistedView, defaultView2]
18106 );
18107 const page = Number(queryParams?.page ?? baseView.page ?? 1);
18108 const search = queryParams?.search ?? baseView.search ?? "";
18109 const combinedOverrides = (0, import_element59.useMemo)(() => {
18110 const rawDefaults = config.defaultLayouts?.[baseView.type];
18111 const layoutTypeDefaults = !rawDefaults || rawDefaults === true ? {} : rawDefaults;
18112 return { ...layoutTypeDefaults, ...activeViewOverrides };
18113 }, [config.defaultLayouts, baseView.type, activeViewOverrides]);
18114 const view = (0, import_element59.useMemo)(() => {
18115 return mergeActiveViewOverrides(
18116 {
18117 ...baseView,
18118 page,
18119 search
18120 },
18121 combinedOverrides,
18122 defaultView2
18123 );
18124 }, [baseView, page, search, combinedOverrides, defaultView2]);
18125 const isModified = !!persistedView;
18126 const updateView = (0, import_element59.useCallback)(
18127 (newView) => {
18128 const urlParams = {
18129 page: newView?.page,
18130 search: newView?.search
18131 };
18132 const preferenceView = stripActiveViewOverrides(
18133 omit3(newView, ["page", "search"]),
18134 combinedOverrides,
18135 defaultView2
18136 );
18137 if (onChangeQueryParams && !dequal(urlParams, { page, search })) {
18138 onChangeQueryParams(urlParams);
18139 }
18140 const comparableBaseView = stripActiveViewOverrides(
18141 baseView,
18142 combinedOverrides,
18143 defaultView2
18144 );
18145 const comparableDefaultView = stripActiveViewOverrides(
18146 defaultView2,
18147 combinedOverrides,
18148 defaultView2
18149 );
18150 if (!dequal(comparableBaseView, preferenceView)) {
18151 if (dequal(preferenceView, comparableDefaultView)) {
18152 set2("core/views", preferenceKey, void 0);
18153 } else {
18154 set2("core/views", preferenceKey, preferenceView);
18155 }
18156 }
18157 },
18158 [
18159 onChangeQueryParams,
18160 page,
18161 search,
18162 baseView,
18163 defaultView2,
18164 combinedOverrides,
18165 set2,
18166 preferenceKey
18167 ]
18168 );
18169 const resetToDefault = (0, import_element59.useCallback)(() => {
18170 set2("core/views", preferenceKey, void 0);
18171 }, [preferenceKey, set2]);
18172 return {
18173 view,
18174 isModified,
18175 updateView,
18176 resetToDefault
18177 };
18178 }
18179
18180 // packages/views/build-module/load-view.mjs
18181 var import_data7 = __toESM(require_data(), 1);
18182 var import_preferences2 = __toESM(require_preferences(), 1);
18183
18184 // packages/views/build-module/use-view-config.mjs
18185 var import_data8 = __toESM(require_data(), 1);
18186 var import_core_data = __toESM(require_core_data(), 1);
18187
18188 // packages/views/build-module/lock-unlock.mjs
18189 var import_private_apis2 = __toESM(require_private_apis(), 1);
18190 var { lock: lock2, unlock: unlock2 } = (0, import_private_apis2.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
18191 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
18192 "@wordpress/views"
18193 );
18194
18195 // packages/media-fields/build-module/alt_text/index.mjs
18196 var import_i18n49 = __toESM(require_i18n(), 1);
18197 var import_components45 = __toESM(require_components(), 1);
18198 var import_jsx_runtime100 = __toESM(require_jsx_runtime(), 1);
18199 var altTextField = {
18200 id: "alt_text",
18201 type: "text",
18202 label: (0, import_i18n49.__)("Alt text"),
18203 isVisible: (item) => item?.media_type === "image",
18204 render: ({ item }) => item?.alt_text || "-",
18205 Edit: ({ field, onChange, data }) => {
18206 return /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(
18207 import_components45.TextareaControl,
18208 {
18209 label: field.label,
18210 value: data.alt_text || "",
18211 onChange: (value) => onChange({ alt_text: value }),
18212 rows: 2
18213 }
18214 );
18215 },
18216 enableSorting: false,
18217 filterBy: false
18218 };
18219 var alt_text_default = altTextField;
18220
18221 // packages/media-fields/build-module/attached_to/index.mjs
18222 var import_i18n52 = __toESM(require_i18n(), 1);
18223
18224 // packages/media-fields/build-module/attached_to/view.mjs
18225 var import_element60 = __toESM(require_element(), 1);
18226 var import_i18n50 = __toESM(require_i18n(), 1);
18227
18228 // packages/media-fields/build-module/utils/get-rendered-content.mjs
18229 function getRenderedContent(content) {
18230 if (!content) {
18231 return "";
18232 }
18233 if (typeof content === "string") {
18234 return content;
18235 }
18236 if (typeof content === "object") {
18237 return content.rendered || content.raw || "";
18238 }
18239 return "";
18240 }
18241
18242 // packages/media-fields/build-module/attached_to/view.mjs
18243 var import_jsx_runtime101 = __toESM(require_jsx_runtime(), 1);
18244 function MediaAttachedToView({
18245 item
18246 }) {
18247 const [attachedPostTitle, setAttachedPostTitle] = (0, import_element60.useState)(null);
18248 const parentId = item.post;
18249 const embeddedPostId = item._embedded?.["wp:attached-to"]?.[0]?.id;
18250 const embeddedPostTitle = item._embedded?.["wp:attached-to"]?.[0]?.title;
18251 (0, import_element60.useEffect)(() => {
18252 if (!!parentId && parentId === embeddedPostId) {
18253 setAttachedPostTitle(
18254 getRenderedContent(embeddedPostTitle) || embeddedPostId?.toString() || ""
18255 );
18256 }
18257 if (!parentId) {
18258 setAttachedPostTitle((0, import_i18n50.__)("(Unattached)"));
18259 }
18260 }, [parentId, embeddedPostId, embeddedPostTitle]);
18261 return /* @__PURE__ */ (0, import_jsx_runtime101.jsx)(import_jsx_runtime101.Fragment, { children: attachedPostTitle });
18262 }
18263
18264 // packages/media-fields/build-module/attached_to/edit.mjs
18265 var import_core_data2 = __toESM(require_core_data(), 1);
18266 var import_components46 = __toESM(require_components(), 1);
18267 var import_i18n51 = __toESM(require_i18n(), 1);
18268 var import_element61 = __toESM(require_element(), 1);
18269 var import_compose13 = __toESM(require_compose(), 1);
18270 var import_data9 = __toESM(require_data(), 1);
18271 var import_jsx_runtime102 = __toESM(require_jsx_runtime(), 1);
18272 function MediaAttachedToEdit({
18273 data,
18274 onChange
18275 }) {
18276 const defaultPost = !!data.post && !!data?._embedded?.["wp:attached-to"]?.[0] ? [
18277 {
18278 label: getRenderedContent(
18279 data._embedded?.["wp:attached-to"]?.[0]?.title
18280 ),
18281 value: data.post.toString()
18282 }
18283 ] : [];
18284 const [options, setOptions] = (0, import_element61.useState)(defaultPost);
18285 const [searchResults, setSearchResults] = (0, import_element61.useState)(
18286 []
18287 );
18288 const [isLoading, setIsLoading] = (0, import_element61.useState)(false);
18289 const [value, setValue] = (0, import_element61.useState)(
18290 data?.post?.toString() ?? null
18291 );
18292 const postTypes = (0, import_data9.useSelect)(
18293 (select2) => select2(import_core_data2.store).getPostTypes(),
18294 []
18295 );
18296 const handleDetach = () => {
18297 onChange({
18298 post: 0,
18299 _embedded: { ...data?._embedded, "wp:attached-to": void 0 }
18300 });
18301 setOptions([]);
18302 };
18303 const onValueChange = async (filterValue) => {
18304 setIsLoading(true);
18305 const results = await (0, import_core_data2.__experimentalFetchLinkSuggestions)(
18306 filterValue,
18307 /*
18308 * @TODO `fetchLinkSuggestions()` should accept `perPage` as an option argument.
18309 * `isInitialSuggestions` limits the result to 3, otherwise it's hardcoded to 20.
18310 */
18311 { type: "post", isInitialSuggestions: true },
18312 {}
18313 );
18314 setSearchResults(results);
18315 const mappedSuggestions = results.map((result) => {
18316 return {
18317 label: result.title,
18318 value: result.id.toString()
18319 };
18320 });
18321 setOptions(mappedSuggestions);
18322 setIsLoading(false);
18323 };
18324 const handleSelectOption = (selectedPostId) => {
18325 if (!selectedPostId) {
18326 handleDetach();
18327 return;
18328 }
18329 setValue(selectedPostId);
18330 if (selectedPostId) {
18331 const selectedPost = searchResults.find(
18332 (result) => result.id === Number(selectedPostId)
18333 );
18334 if (selectedPost && postTypes) {
18335 const postType = postTypes.find(
18336 (_postType) => _postType.slug === selectedPost?.type
18337 );
18338 const attachedTo = {
18339 ...postType && { type: postType.slug },
18340 id: Number(selectedPostId),
18341 title: {
18342 raw: selectedPost.title,
18343 rendered: selectedPost.title
18344 }
18345 };
18346 onChange({
18347 post: Number(selectedPostId),
18348 _embedded: {
18349 ...data?._embedded,
18350 "wp:attached-to": [attachedTo]
18351 }
18352 });
18353 }
18354 }
18355 };
18356 const help = !!data.post ? (0, import_element61.createInterpolateElement)(
18357 (0, import_i18n51.__)(
18358 "Search for a post or page to attach this media to or <button>detach current</button>."
18359 ),
18360 {
18361 button: /* @__PURE__ */ (0, import_jsx_runtime102.jsx)(
18362 import_components46.Button,
18363 {
18364 __next40pxDefaultSize: true,
18365 onClick: handleDetach,
18366 variant: "link",
18367 accessibleWhenDisabled: true
18368 }
18369 )
18370 }
18371 ) : (0, import_i18n51.__)("Search for a post or page to attach this media to.");
18372 return /* @__PURE__ */ (0, import_jsx_runtime102.jsx)(
18373 import_components46.ComboboxControl,
18374 {
18375 className: "dataviews-media-field__attached-to",
18376 __next40pxDefaultSize: true,
18377 isLoading,
18378 label: (0, import_i18n51.__)("Attached to"),
18379 help,
18380 value,
18381 options,
18382 onFilterValueChange: (0, import_compose13.debounce)(
18383 (filterValue) => onValueChange(filterValue),
18384 300
18385 ),
18386 onChange: handleSelectOption,
18387 hideLabelFromVision: true
18388 }
18389 );
18390 }
18391
18392 // packages/media-fields/build-module/attached_to/index.mjs
18393 var attachedToField = {
18394 id: "attached_to",
18395 type: "text",
18396 label: (0, import_i18n52.__)("Attached to"),
18397 Edit: MediaAttachedToEdit,
18398 render: MediaAttachedToView,
18399 enableSorting: false,
18400 filterBy: false
18401 };
18402 var attached_to_default = attachedToField;
18403
18404 // packages/media-fields/build-module/author/index.mjs
18405 var import_i18n54 = __toESM(require_i18n(), 1);
18406 var import_data10 = __toESM(require_data(), 1);
18407 var import_core_data3 = __toESM(require_core_data(), 1);
18408
18409 // packages/media-fields/build-module/author/view.mjs
18410 var import_i18n53 = __toESM(require_i18n(), 1);
18411 var import_element62 = __toESM(require_element(), 1);
18412 var import_components47 = __toESM(require_components(), 1);
18413 var import_jsx_runtime103 = __toESM(require_jsx_runtime(), 1);
18414 function AuthorView({
18415 item
18416 }) {
18417 const author = item?._embedded?.author?.[0];
18418 const text = author?.name;
18419 const imageUrl = author?.avatar_urls?.[48];
18420 const [loadingState, setLoadingState] = (0, import_element62.useState)("loading");
18421 (0, import_element62.useEffect)(() => {
18422 setLoadingState("loading");
18423 }, [imageUrl]);
18424 const imgRef = (0, import_element62.useCallback)((img) => {
18425 if (img?.complete) {
18426 setLoadingState("instant");
18427 }
18428 }, []);
18429 const handleLoad = () => {
18430 if (loadingState === "loading") {
18431 setLoadingState("loaded");
18432 }
18433 };
18434 return /* @__PURE__ */ (0, import_jsx_runtime103.jsxs)(import_components47.__experimentalHStack, { alignment: "left", spacing: 0, children: [
18435 !!imageUrl && /* @__PURE__ */ (0, import_jsx_runtime103.jsx)(
18436 "div",
18437 {
18438 className: clsx_default("media-author-field__avatar", {
18439 "is-loading": loadingState === "loading",
18440 "is-loaded": loadingState === "loaded"
18441 }),
18442 children: /* @__PURE__ */ (0, import_jsx_runtime103.jsx)(
18443 "img",
18444 {
18445 ref: imgRef,
18446 onLoad: handleLoad,
18447 alt: (0, import_i18n53.__)("Author avatar"),
18448 src: imageUrl
18449 }
18450 )
18451 }
18452 ),
18453 !imageUrl && /* @__PURE__ */ (0, import_jsx_runtime103.jsx)("div", { className: "media-author-field__icon", children: /* @__PURE__ */ (0, import_jsx_runtime103.jsx)(import_components47.Icon, { icon: comment_author_avatar_default }) }),
18454 /* @__PURE__ */ (0, import_jsx_runtime103.jsx)("span", { className: "media-author-field__name", children: text })
18455 ] });
18456 }
18457
18458 // packages/media-fields/build-module/author/index.mjs
18459 var authorField = {
18460 label: (0, import_i18n54.__)("Author"),
18461 id: "author",
18462 type: "integer",
18463 getElements: async () => {
18464 const authors = await (0, import_data10.resolveSelect)(import_core_data3.store).getEntityRecords(
18465 "root",
18466 "user",
18467 {
18468 per_page: -1,
18469 who: "authors",
18470 _fields: "id,name",
18471 context: "view"
18472 }
18473 ) ?? [];
18474 return authors.map(({ id, name }) => ({
18475 value: id,
18476 label: name
18477 }));
18478 },
18479 render: AuthorView,
18480 sort: (a2, b2, direction) => {
18481 const nameA = a2._embedded?.author?.[0]?.name || "";
18482 const nameB = b2._embedded?.author?.[0]?.name || "";
18483 return direction === "asc" ? nameA.localeCompare(nameB) : nameB.localeCompare(nameA);
18484 },
18485 filterBy: {
18486 operators: ["isAny", "isNone"]
18487 },
18488 readOnly: true
18489 };
18490 var author_default = authorField;
18491
18492 // packages/media-fields/build-module/caption/index.mjs
18493 var import_i18n55 = __toESM(require_i18n(), 1);
18494 var import_components48 = __toESM(require_components(), 1);
18495
18496 // packages/media-fields/build-module/utils/get-raw-content.mjs
18497 function getRawContent(content) {
18498 if (!content) {
18499 return "";
18500 }
18501 if (typeof content === "string") {
18502 return content;
18503 }
18504 if (typeof content === "object" && "raw" in content) {
18505 return content.raw || "";
18506 }
18507 return "";
18508 }
18509
18510 // packages/media-fields/build-module/caption/index.mjs
18511 var import_jsx_runtime104 = __toESM(require_jsx_runtime(), 1);
18512 var captionField = {
18513 id: "caption",
18514 type: "text",
18515 label: (0, import_i18n55.__)("Caption"),
18516 getValue: ({ item }) => getRawContent(item?.caption),
18517 render: ({ item }) => getRawContent(item?.caption) || "-",
18518 Edit: ({ field, onChange, data }) => {
18519 return /* @__PURE__ */ (0, import_jsx_runtime104.jsx)(
18520 import_components48.TextareaControl,
18521 {
18522 label: field.label,
18523 value: getRawContent(data.caption) || "",
18524 onChange: (value) => onChange({ caption: value }),
18525 rows: 2
18526 }
18527 );
18528 },
18529 enableSorting: false,
18530 filterBy: false
18531 };
18532 var caption_default = captionField;
18533
18534 // packages/media-fields/build-module/date_added/index.mjs
18535 var import_i18n56 = __toESM(require_i18n(), 1);
18536 var import_date10 = __toESM(require_date(), 1);
18537 var dateAddedField = {
18538 id: "date",
18539 type: "datetime",
18540 label: (0, import_i18n56.__)("Date added"),
18541 filterBy: {
18542 operators: ["before", "after"]
18543 },
18544 format: {
18545 datetime: (0, import_date10.getSettings)().formats.datetimeAbbreviated
18546 },
18547 readOnly: true
18548 };
18549 var date_added_default = dateAddedField;
18550
18551 // packages/media-fields/build-module/date_modified/index.mjs
18552 var import_i18n57 = __toESM(require_i18n(), 1);
18553 var import_date11 = __toESM(require_date(), 1);
18554 var dateModifiedField = {
18555 id: "modified",
18556 type: "datetime",
18557 label: (0, import_i18n57.__)("Date modified"),
18558 filterBy: {
18559 operators: ["before", "after"]
18560 },
18561 format: {
18562 datetime: (0, import_date11.getSettings)().formats.datetimeAbbreviated
18563 },
18564 readOnly: true
18565 };
18566 var date_modified_default = dateModifiedField;
18567
18568 // packages/media-fields/build-module/description/index.mjs
18569 var import_i18n58 = __toESM(require_i18n(), 1);
18570 var import_components49 = __toESM(require_components(), 1);
18571 var import_jsx_runtime105 = __toESM(require_jsx_runtime(), 1);
18572 var descriptionField = {
18573 id: "description",
18574 type: "text",
18575 label: (0, import_i18n58.__)("Description"),
18576 getValue: ({ item }) => getRawContent(item?.description),
18577 render: ({ item }) => /* @__PURE__ */ (0, import_jsx_runtime105.jsx)("div", { children: getRawContent(item?.description) || "-" }),
18578 Edit: ({ field, onChange, data }) => {
18579 return /* @__PURE__ */ (0, import_jsx_runtime105.jsx)(
18580 import_components49.TextareaControl,
18581 {
18582 label: field.label,
18583 value: getRawContent(data.description) || "",
18584 onChange: (value) => onChange({ description: value }),
18585 rows: 5
18586 }
18587 );
18588 },
18589 enableSorting: false,
18590 filterBy: false
18591 };
18592 var description_default = descriptionField;
18593
18594 // packages/media-fields/build-module/filename/index.mjs
18595 var import_i18n59 = __toESM(require_i18n(), 1);
18596 var import_url4 = __toESM(require_url(), 1);
18597
18598 // packages/media-fields/build-module/filename/view.mjs
18599 var import_components50 = __toESM(require_components(), 1);
18600 var import_element63 = __toESM(require_element(), 1);
18601 var import_url3 = __toESM(require_url(), 1);
18602 var import_jsx_runtime106 = __toESM(require_jsx_runtime(), 1);
18603 var TRUNCATE_LENGTH = 15;
18604 function FileNameView({
18605 item
18606 }) {
18607 const fileName = (0, import_element63.useMemo)(
18608 () => item?.source_url ? (0, import_url3.getFilename)(item.source_url) : null,
18609 [item?.source_url]
18610 );
18611 if (!fileName) {
18612 return "";
18613 }
18614 return fileName.length > TRUNCATE_LENGTH ? /* @__PURE__ */ (0, import_jsx_runtime106.jsx)(import_components50.Tooltip, { text: fileName, children: /* @__PURE__ */ (0, import_jsx_runtime106.jsx)(import_components50.__experimentalTruncate, { limit: TRUNCATE_LENGTH, ellipsizeMode: "tail", children: fileName }) }) : /* @__PURE__ */ (0, import_jsx_runtime106.jsx)(import_jsx_runtime106.Fragment, { children: fileName });
18615 }
18616
18617 // packages/media-fields/build-module/filename/index.mjs
18618 var filenameField = {
18619 id: "filename",
18620 type: "text",
18621 label: (0, import_i18n59.__)("File name"),
18622 getValue: ({ item }) => (0, import_url4.getFilename)(item?.source_url || ""),
18623 render: FileNameView,
18624 enableSorting: false,
18625 filterBy: false,
18626 readOnly: true
18627 };
18628 var filename_default = filenameField;
18629
18630 // packages/media-fields/build-module/filesize/index.mjs
18631 var import_i18n60 = __toESM(require_i18n(), 1);
18632 var KB_IN_BYTES = 1024;
18633 var MB_IN_BYTES = 1024 * KB_IN_BYTES;
18634 var GB_IN_BYTES = 1024 * MB_IN_BYTES;
18635 var TB_IN_BYTES = 1024 * GB_IN_BYTES;
18636 var PB_IN_BYTES = 1024 * TB_IN_BYTES;
18637 var EB_IN_BYTES = 1024 * PB_IN_BYTES;
18638 var ZB_IN_BYTES = 1024 * EB_IN_BYTES;
18639 var YB_IN_BYTES = 1024 * ZB_IN_BYTES;
18640 function getBytesString(bytes, unitSymbol, decimals = 2) {
18641 return (0, import_i18n60.sprintf)(
18642 // translators: 1: Actual bytes of a file. 2: The unit symbol (e.g. MB).
18643 (0, import_i18n60._x)("%1$s %2$s", "file size"),
18644 bytes.toLocaleString(void 0, {
18645 minimumFractionDigits: 0,
18646 maximumFractionDigits: decimals
18647 }),
18648 unitSymbol
18649 );
18650 }
18651 function formatFileSize(bytes, decimals = 2) {
18652 if (bytes === 0) {
18653 return getBytesString(0, (0, import_i18n60._x)("B", "unit symbol"), decimals);
18654 }
18655 const quant = {
18656 /* translators: Unit symbol for yottabyte. */
18657 [(0, import_i18n60._x)("YB", "unit symbol")]: YB_IN_BYTES,
18658 /* translators: Unit symbol for zettabyte. */
18659 [(0, import_i18n60._x)("ZB", "unit symbol")]: ZB_IN_BYTES,
18660 /* translators: Unit symbol for exabyte. */
18661 [(0, import_i18n60._x)("EB", "unit symbol")]: EB_IN_BYTES,
18662 /* translators: Unit symbol for petabyte. */
18663 [(0, import_i18n60._x)("PB", "unit symbol")]: PB_IN_BYTES,
18664 /* translators: Unit symbol for terabyte. */
18665 [(0, import_i18n60._x)("TB", "unit symbol")]: TB_IN_BYTES,
18666 /* translators: Unit symbol for gigabyte. */
18667 [(0, import_i18n60._x)("GB", "unit symbol")]: GB_IN_BYTES,
18668 /* translators: Unit symbol for megabyte. */
18669 [(0, import_i18n60._x)("MB", "unit symbol")]: MB_IN_BYTES,
18670 /* translators: Unit symbol for kilobyte. */
18671 [(0, import_i18n60._x)("KB", "unit symbol")]: KB_IN_BYTES,
18672 /* translators: Unit symbol for byte. */
18673 [(0, import_i18n60._x)("B", "unit symbol")]: 1
18674 };
18675 for (const [unit, mag] of Object.entries(quant)) {
18676 if (bytes >= mag) {
18677 return getBytesString(bytes / mag, unit, decimals);
18678 }
18679 }
18680 return "";
18681 }
18682 var filesizeField = {
18683 id: "filesize",
18684 type: "text",
18685 label: (0, import_i18n60.__)("File size"),
18686 getValue: ({ item }) => item?.media_details?.filesize ? formatFileSize(item?.media_details?.filesize) : "",
18687 isVisible: (item) => {
18688 return !!item?.media_details?.filesize;
18689 },
18690 enableSorting: false,
18691 filterBy: false,
18692 readOnly: true
18693 };
18694 var filesize_default = filesizeField;
18695
18696 // packages/media-fields/build-module/media_dimensions/index.mjs
18697 var import_i18n61 = __toESM(require_i18n(), 1);
18698 var mediaDimensionsField = {
18699 id: "media_dimensions",
18700 type: "text",
18701 label: (0, import_i18n61.__)("Dimensions"),
18702 getValue: ({ item }) => item?.media_details?.width && item?.media_details?.height ? (0, import_i18n61.sprintf)(
18703 // translators: 1: Width. 2: Height.
18704 (0, import_i18n61._x)("%1$s \xD7 %2$s", "image dimensions"),
18705 item?.media_details?.width?.toString(),
18706 item?.media_details?.height?.toString()
18707 ) : "",
18708 isVisible: (item) => {
18709 return !!(item?.media_details?.width && item?.media_details?.height);
18710 },
18711 enableSorting: false,
18712 filterBy: false,
18713 readOnly: true
18714 };
18715 var media_dimensions_default = mediaDimensionsField;
18716
18717 // packages/media-fields/build-module/media_thumbnail/index.mjs
18718 var import_i18n63 = __toESM(require_i18n(), 1);
18719
18720 // packages/media-fields/build-module/media_thumbnail/view.mjs
18721 var import_data11 = __toESM(require_data(), 1);
18722 var import_core_data4 = __toESM(require_core_data(), 1);
18723 var import_components51 = __toESM(require_components(), 1);
18724 var import_element64 = __toESM(require_element(), 1);
18725 var import_url5 = __toESM(require_url(), 1);
18726
18727 // packages/media-fields/build-module/utils/get-media-type-from-mime-type.mjs
18728 var import_i18n62 = __toESM(require_i18n(), 1);
18729 function getMediaTypeFromMimeType(mimeType) {
18730 if (mimeType.startsWith("image/")) {
18731 return {
18732 type: "image",
18733 label: (0, import_i18n62.__)("Image"),
18734 icon: image_default
18735 };
18736 }
18737 if (mimeType.startsWith("video/")) {
18738 return {
18739 type: "video",
18740 label: (0, import_i18n62.__)("Video"),
18741 icon: video_default
18742 };
18743 }
18744 if (mimeType.startsWith("audio/")) {
18745 return {
18746 type: "audio",
18747 label: (0, import_i18n62.__)("Audio"),
18748 icon: audio_default
18749 };
18750 }
18751 return {
18752 type: "application",
18753 label: (0, import_i18n62.__)("Application"),
18754 icon: file_default
18755 };
18756 }
18757
18758 // packages/media-fields/build-module/media_thumbnail/view.mjs
18759 var import_jsx_runtime107 = __toESM(require_jsx_runtime(), 1);
18760 function getBestImageUrl(featuredMedia, configSizes) {
18761 const sizes = featuredMedia?.media_details?.sizes;
18762 if (!sizes) {
18763 return featuredMedia.source_url;
18764 }
18765 const sizeEntries = Object.values(sizes);
18766 if (!sizeEntries.length) {
18767 return featuredMedia.source_url;
18768 }
18769 const targetWidth = configSizes ? parseInt(configSizes, 10) : NaN;
18770 if (!Number.isNaN(targetWidth)) {
18771 const validEntries = sizeEntries.filter(
18772 (s2) => typeof s2.width === "number" && !Number.isNaN(s2.width)
18773 );
18774 if (!validEntries.length) {
18775 return featuredMedia.source_url;
18776 }
18777 const sorted = [...validEntries].sort(
18778 (a2, b2) => a2.width - b2.width
18779 );
18780 const match2 = sorted.find((s2) => s2.width >= targetWidth);
18781 if (match2) {
18782 return match2.source_url;
18783 }
18784 return sorted[sorted.length - 1].source_url;
18785 }
18786 return featuredMedia.source_url;
18787 }
18788 function FallbackView({
18789 item,
18790 filename
18791 }) {
18792 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)("div", { className: "dataviews-media-field__media-thumbnail", children: /* @__PURE__ */ (0, import_jsx_runtime107.jsxs)(
18793 import_components51.__experimentalVStack,
18794 {
18795 justify: "center",
18796 alignment: "center",
18797 className: "dataviews-media-field__media-thumbnail__stack",
18798 spacing: 0,
18799 children: [
18800 /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
18801 import_components51.Icon,
18802 {
18803 className: "dataviews-media-field__media-thumbnail--icon",
18804 icon: getMediaTypeFromMimeType(item.mime_type).icon,
18805 size: 24
18806 }
18807 ),
18808 !!filename && /* @__PURE__ */ (0, import_jsx_runtime107.jsx)("div", { className: "dataviews-media-field__media-thumbnail__filename", children: /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(import_components51.__experimentalTruncate, { className: "dataviews-media-field__media-thumbnail__filename__truncate", children: filename }) })
18809 ]
18810 }
18811 ) });
18812 }
18813 function ImageView({
18814 item,
18815 configSizes,
18816 onError
18817 }) {
18818 const imageUrl = getBestImageUrl(item, configSizes);
18819 const imgRef = (0, import_element64.useRef)(null);
18820 const [loadingState, setLoadingState] = (0, import_element64.useState)("loading");
18821 (0, import_element64.useLayoutEffect)(() => {
18822 if (imgRef.current?.complete) {
18823 setLoadingState("instant");
18824 } else {
18825 setLoadingState("loading");
18826 }
18827 }, [imageUrl]);
18828 const handleLoad = () => {
18829 if (loadingState === "loading") {
18830 setLoadingState("loaded");
18831 }
18832 };
18833 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
18834 "div",
18835 {
18836 className: clsx_default("dataviews-media-field__media-thumbnail", {
18837 "is-loading": loadingState === "loading",
18838 "is-loaded": loadingState === "loaded"
18839 }),
18840 children: /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
18841 "img",
18842 {
18843 ref: imgRef,
18844 className: "dataviews-media-field__media-thumbnail--image",
18845 src: imageUrl,
18846 alt: item.alt_text || item.title.raw,
18847 onLoad: handleLoad,
18848 onError,
18849 loading: "lazy"
18850 }
18851 )
18852 }
18853 );
18854 }
18855 function MediaThumbnailView({
18856 item,
18857 config
18858 }) {
18859 const [imageError, setImageError] = (0, import_element64.useState)(false);
18860 const _featuredMedia = (0, import_data11.useSelect)(
18861 (select2) => {
18862 if (!item.featured_media) {
18863 return;
18864 }
18865 return select2(import_core_data4.store).getEntityRecord(
18866 "postType",
18867 "attachment",
18868 item.featured_media
18869 );
18870 },
18871 [item.featured_media]
18872 );
18873 const featuredMedia = item.featured_media ? _featuredMedia : item;
18874 if (!featuredMedia) {
18875 return null;
18876 }
18877 const filename = (0, import_url5.getFilename)(featuredMedia.source_url || "");
18878 if (imageError || getMediaTypeFromMimeType(featuredMedia.mime_type).type !== "image") {
18879 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(FallbackView, { item: featuredMedia, filename: filename || "" });
18880 }
18881 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
18882 ImageView,
18883 {
18884 item: featuredMedia,
18885 configSizes: config?.sizes,
18886 onError: () => setImageError(true)
18887 }
18888 );
18889 }
18890
18891 // packages/media-fields/build-module/media_thumbnail/index.mjs
18892 var mediaThumbnailField = {
18893 id: "media_thumbnail",
18894 type: "media",
18895 label: (0, import_i18n63.__)("Thumbnail"),
18896 render: MediaThumbnailView,
18897 enableSorting: false,
18898 filterBy: false
18899 };
18900 var media_thumbnail_default = mediaThumbnailField;
18901
18902 // packages/media-fields/build-module/mime_type/index.mjs
18903 var import_i18n64 = __toESM(require_i18n(), 1);
18904 var mimeTypeField = {
18905 id: "mime_type",
18906 type: "text",
18907 label: (0, import_i18n64.__)("File type"),
18908 getValue: ({ item }) => item?.mime_type || "",
18909 render: ({ item }) => item?.mime_type || "-",
18910 // Disable sorting until REST API support for ordering my `mime_type` is added.
18911 // See: https://core.trac.wordpress.org/ticket/64073
18912 enableSorting: false,
18913 filterBy: false,
18914 readOnly: true
18915 };
18916 var mime_type_default = mimeTypeField;
18917
18918 // packages/media-utils/build-module/components/media-upload-modal/index.mjs
18919 var import_notices = __toESM(require_notices(), 1);
18920
18921 // packages/media-utils/build-module/lock-unlock.mjs
18922 var import_private_apis3 = __toESM(require_private_apis(), 1);
18923 var { lock: lock3, unlock: unlock3 } = (0, import_private_apis3.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
18924 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
18925 "@wordpress/media-utils"
18926 );
18927
18928 // packages/media-utils/build-module/components/media-upload-modal/upload-status-popover.mjs
18929 var import_element65 = __toESM(require_element(), 1);
18930 var import_i18n65 = __toESM(require_i18n(), 1);
18931 var import_components52 = __toESM(require_components(), 1);
18932 var import_jsx_runtime108 = __toESM(require_jsx_runtime(), 1);
18933 function UploadStatusPopover({
18934 uploadingFiles,
18935 onDismissError,
18936 onOpenChange
18937 }) {
18938 const [isOpen, setIsOpen] = (0, import_element65.useState)(false);
18939 const [prevHadErrors, setPrevHadErrors] = (0, import_element65.useState)(false);
18940 const triggerRef = (0, import_element65.useRef)(null);
18941 const updateIsOpen = (0, import_element65.useCallback)(
18942 (open) => {
18943 setIsOpen(open);
18944 onOpenChange?.(open);
18945 },
18946 [onOpenChange]
18947 );
18948 const activeFiles = uploadingFiles.filter(
18949 (file) => file.status === "uploading"
18950 );
18951 const errorFiles = uploadingFiles.filter(
18952 (file) => file.status === "error"
18953 );
18954 const hasErrors = errorFiles.length > 0;
18955 const isUploading = activeFiles.length > 0;
18956 (0, import_element65.useEffect)(() => {
18957 if (hasErrors && !prevHadErrors) {
18958 updateIsOpen(true);
18959 }
18960 setPrevHadErrors(hasErrors);
18961 }, [hasErrors, prevHadErrors, updateIsOpen]);
18962 if (uploadingFiles.length === 0) {
18963 return null;
18964 }
18965 let buttonLabel, popoverHeading;
18966 if (isUploading) {
18967 buttonLabel = (0, import_i18n65.sprintf)(
18968 // translators: %s: number of files being uploaded
18969 (0, import_i18n65._n)("Uploading %s file", "Uploading %s files", activeFiles.length),
18970 activeFiles.length.toLocaleString()
18971 );
18972 popoverHeading = (0, import_i18n65.__)("Uploading");
18973 } else if (hasErrors) {
18974 buttonLabel = (0, import_i18n65.sprintf)(
18975 // translators: %s: number of upload errors
18976 (0, import_i18n65._n)("%s upload error", "%s upload errors", errorFiles.length),
18977 errorFiles.length.toLocaleString()
18978 );
18979 popoverHeading = (0, import_i18n65.__)("Upload errors");
18980 } else {
18981 buttonLabel = (0, import_i18n65.__)("Upload complete");
18982 popoverHeading = (0, import_i18n65.__)("Upload complete");
18983 }
18984 return /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)("div", { className: "media-upload-modal__upload-status", children: [
18985 isUploading && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(import_components52.Spinner, {}),
18986 /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(
18987 import_components52.Button,
18988 {
18989 className: "media-upload-modal__upload-status__trigger",
18990 size: "compact",
18991 icon: chevron_down_default,
18992 iconPosition: "right",
18993 onClick: () => updateIsOpen(!isOpen),
18994 "aria-expanded": isOpen,
18995 ref: triggerRef,
18996 children: buttonLabel
18997 }
18998 ),
18999 isOpen && /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)(
19000 import_components52.Popover,
19001 {
19002 className: "media-upload-modal__upload-status__popover",
19003 placement: "top-start",
19004 offset: 8,
19005 anchor: triggerRef.current,
19006 focusOnMount: true,
19007 onClose: () => {
19008 if (triggerRef.current?.contains(
19009 triggerRef.current.ownerDocument.activeElement
19010 )) {
19011 return;
19012 }
19013 updateIsOpen(false);
19014 },
19015 children: [
19016 /* @__PURE__ */ (0, import_jsx_runtime108.jsx)("div", { className: "media-upload-modal__upload-status__header", children: /* @__PURE__ */ (0, import_jsx_runtime108.jsx)("h3", { children: popoverHeading }) }),
19017 /* @__PURE__ */ (0, import_jsx_runtime108.jsx)("ul", { className: "media-upload-modal__upload-status__list", children: uploadingFiles.map((file) => /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)(
19018 "li",
19019 {
19020 className: "media-upload-modal__upload-status__item",
19021 children: [
19022 file.status === "uploading" && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(import_components52.Spinner, {}),
19023 file.status === "uploaded" && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(import_components52.Icon, { icon: check_default, size: 16 }),
19024 (file.status === "uploading" || file.status === "uploaded") && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(
19025 "span",
19026 {
19027 className: "media-upload-modal__upload-status__filename",
19028 title: file.name,
19029 children: file.name
19030 }
19031 ),
19032 file.status === "error" && /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)(
19033 import_components52.Notice,
19034 {
19035 status: "error",
19036 isDismissible: !!onDismissError,
19037 onRemove: () => onDismissError?.(file.id),
19038 children: [
19039 file.name,
19040 ": ",
19041 file.error
19042 ]
19043 }
19044 )
19045 ]
19046 },
19047 file.id
19048 )) })
19049 ]
19050 }
19051 )
19052 ] });
19053 }
19054
19055 // packages/media-utils/build-module/components/media-upload-modal/use-invalidate-attachment-resolutions.mjs
19056 var import_element66 = __toESM(require_element(), 1);
19057 var import_core_data5 = __toESM(require_core_data(), 1);
19058 var import_data12 = __toESM(require_data(), 1);
19059 function useInvalidateAttachmentResolutions() {
19060 const registry = (0, import_data12.useRegistry)();
19061 return (0, import_element66.useCallback)(() => {
19062 const resolvers = registry.select(import_core_data5.store).getCachedResolvers();
19063 const entityRecordResolutions = resolvers.getEntityRecords;
19064 entityRecordResolutions?.forEach((_value, args) => {
19065 if (args[0] === "postType" && args[1] === "attachment") {
19066 registry.dispatch(import_core_data5.store).invalidateResolution("getEntityRecords", args);
19067 }
19068 });
19069 }, [registry]);
19070 }
19071
19072 // packages/media-utils/build-module/components/media-upload-modal/use-upload-status.mjs
19073 var import_element67 = __toESM(require_element(), 1);
19074 var import_blob2 = __toESM(require_blob(), 1);
19075 var idCounter = 0;
19076 var batchIdCounter = 0;
19077 function useUploadStatus({
19078 onBatchComplete
19079 } = {}) {
19080 const [uploadingFiles, setUploadingFiles] = (0, import_element67.useState)(
19081 []
19082 );
19083 const clearCompleted = (0, import_element67.useCallback)(() => {
19084 setUploadingFiles(
19085 (prev) => prev.filter((item) => item.status !== "uploaded")
19086 );
19087 }, []);
19088 const dismissError = (0, import_element67.useCallback)((fileId) => {
19089 setUploadingFiles(
19090 (prev) => prev.filter((item) => item.id !== fileId)
19091 );
19092 }, []);
19093 const registerBatch = (0, import_element67.useCallback)(
19094 (files) => {
19095 const batchId = String(++batchIdCounter);
19096 const batchSize = files.length;
19097 const newEntries = files.map((file) => ({
19098 id: String(++idCounter),
19099 batchId,
19100 name: file.name,
19101 status: "uploading"
19102 }));
19103 setUploadingFiles((prev) => [...prev, ...newEntries]);
19104 let successCount = 0;
19105 let errorCount = 0;
19106 let batchDone = false;
19107 let successAttachments = [];
19108 const completeBatchIfDone = () => {
19109 if (batchDone || successCount + errorCount < batchSize) {
19110 return;
19111 }
19112 batchDone = true;
19113 setUploadingFiles(
19114 (prev) => prev.map(
19115 (item) => item.batchId === batchId && item.status === "uploading" ? {
19116 ...item,
19117 status: "uploaded"
19118 } : item
19119 )
19120 );
19121 onBatchComplete?.(successAttachments);
19122 };
19123 const onFileChange = (attachments) => {
19124 if (batchDone) {
19125 return;
19126 }
19127 const allReal = attachments.every(
19128 (attachment) => attachment.id && attachment.url && !(0, import_blob2.isBlobURL)(attachment.url)
19129 );
19130 if (!allReal) {
19131 return;
19132 }
19133 successCount = attachments.length;
19134 successAttachments = attachments;
19135 completeBatchIfDone();
19136 };
19137 const onError = (error) => {
19138 const fileName = error instanceof UploadError ? error.file.name : void 0;
19139 setUploadingFiles((prev) => {
19140 let matched = false;
19141 return prev.map((item) => {
19142 if (!matched && item.batchId === batchId && item.status === "uploading" && (!fileName || item.name === fileName)) {
19143 matched = true;
19144 return {
19145 ...item,
19146 status: "error",
19147 error: error.message
19148 };
19149 }
19150 return item;
19151 });
19152 });
19153 errorCount++;
19154 completeBatchIfDone();
19155 };
19156 return { onFileChange, onError };
19157 },
19158 [onBatchComplete]
19159 );
19160 const allComplete = uploadingFiles.length > 0 && uploadingFiles.every((item) => item.status !== "uploading");
19161 return {
19162 uploadingFiles,
19163 registerBatch,
19164 dismissError,
19165 clearCompleted,
19166 allComplete
19167 };
19168 }
19169
19170 // packages/media-utils/build-module/components/media-upload-modal/index.mjs
19171 var import_jsx_runtime109 = __toESM(require_jsx_runtime(), 1);
19172 var { useEntityRecordsWithPermissions } = unlock3(import_core_data6.privateApis);
19173 var LAYOUT_PICKER_GRID2 = "pickerGrid";
19174 var LAYOUT_PICKER_TABLE2 = "pickerTable";
19175 var NOTICES_CONTEXT = "media-modal";
19176 var NOTICE_ID_UPLOAD_PROGRESS = "media-modal-upload-progress";
19177 var defaultQueryParams = {
19178 page: 1,
19179 search: ""
19180 };
19181 var defaultView = {
19182 type: LAYOUT_PICKER_GRID2,
19183 fields: [],
19184 showTitle: false,
19185 titleField: "title",
19186 mediaField: "media_thumbnail",
19187 perPage: 50,
19188 filters: [],
19189 layout: {
19190 previewSize: 170,
19191 density: "compact"
19192 }
19193 };
19194 var defaultLayouts = {
19195 [LAYOUT_PICKER_GRID2]: {
19196 fields: [],
19197 showTitle: false,
19198 layout: {
19199 previewSize: 170,
19200 density: "compact"
19201 }
19202 },
19203 [LAYOUT_PICKER_TABLE2]: {
19204 fields: [
19205 "filename",
19206 "filesize",
19207 "media_dimensions",
19208 "author",
19209 "date"
19210 ],
19211 showTitle: true
19212 }
19213 };
19214 function MediaUploadModal({
19215 allowedTypes,
19216 multiple = false,
19217 value,
19218 onSelect,
19219 onClose,
19220 onUpload,
19221 title = (0, import_i18n66.__)("Select Media"),
19222 isOpen,
19223 isDismissible = true,
19224 modalClass,
19225 search = true,
19226 searchLabel = (0, import_i18n66.__)("Search media")
19227 }) {
19228 const [selection, setSelection] = (0, import_element68.useState)(() => {
19229 if (!value) {
19230 return [];
19231 }
19232 return Array.isArray(value) ? value.map(String) : [String(value)];
19233 });
19234 const { createSuccessNotice, removeAllNotices } = (0, import_data13.useDispatch)(import_notices.store);
19235 const invalidateAttachmentResolutions = useInvalidateAttachmentResolutions();
19236 const [queryParams, setQueryParams] = (0, import_element68.useState)(
19237 () => defaultQueryParams
19238 );
19239 const { view, updateView, isModified, resetToDefault } = useView({
19240 kind: "postType",
19241 name: "attachment",
19242 slug: "media-modal",
19243 defaultView,
19244 queryParams,
19245 onChangeQueryParams: setQueryParams
19246 });
19247 const handleChangeView = (0, import_element68.useCallback)(
19248 (nextView) => {
19249 const normalizedView = { ...nextView };
19250 if (normalizedView.startPosition === void 0) {
19251 delete normalizedView.startPosition;
19252 }
19253 updateView(normalizedView);
19254 },
19255 [updateView]
19256 );
19257 const queryArgs = (0, import_element68.useMemo)(() => {
19258 const filters = {};
19259 view.filters?.forEach((filter) => {
19260 if (filter.field === "media_type") {
19261 filters.media_type = filter.value;
19262 }
19263 if (filter.field === "author") {
19264 if (filter.operator === "isAny") {
19265 filters.author = filter.value;
19266 } else if (filter.operator === "isNone") {
19267 filters.author_exclude = filter.value;
19268 }
19269 }
19270 if (filter.field === "date" || filter.field === "modified") {
19271 if (filter.operator === "before") {
19272 filters.before = filter.value;
19273 } else if (filter.operator === "after") {
19274 filters.after = filter.value;
19275 }
19276 }
19277 if (filter.field === "mime_type") {
19278 filters.mime_type = filter.value;
19279 }
19280 });
19281 if (!filters.media_type && !filters.mime_type && allowedTypes && !allowedTypes.includes("*")) {
19282 const { mediaTypes, mimeTypes } = allowedTypes.reduce(
19283 (acc, type) => {
19284 if (type.endsWith("/*")) {
19285 acc.mediaTypes.push(type.replace("/*", ""));
19286 } else if (type.includes("/")) {
19287 acc.mimeTypes.push(type);
19288 } else {
19289 acc.mediaTypes.push(type);
19290 }
19291 return acc;
19292 },
19293 { mediaTypes: [], mimeTypes: [] }
19294 );
19295 if (mediaTypes.length) {
19296 filters.media_type = mediaTypes;
19297 }
19298 if (mimeTypes.length) {
19299 filters.mime_type = mimeTypes;
19300 }
19301 }
19302 return {
19303 per_page: view.perPage || 20,
19304 page: view.page || 1,
19305 status: "inherit",
19306 order: view.sort?.direction,
19307 orderby: view.sort?.field,
19308 search: view.search,
19309 _embed: "author,wp:attached-to",
19310 ...filters
19311 };
19312 }, [view, allowedTypes]);
19313 const handleBatchComplete = (0, import_element68.useCallback)(
19314 (attachments) => {
19315 const uploadedIds = attachments.map((attachment) => String(attachment.id)).filter(Boolean);
19316 if (multiple) {
19317 setSelection((prev) => {
19318 const existing = new Set(prev);
19319 const newIds = uploadedIds.filter(
19320 (id) => !existing.has(id)
19321 );
19322 return [...prev, ...newIds];
19323 });
19324 } else {
19325 setSelection(uploadedIds.slice(0, 1));
19326 }
19327 invalidateAttachmentResolutions();
19328 },
19329 [multiple, invalidateAttachmentResolutions]
19330 );
19331 const {
19332 uploadingFiles,
19333 registerBatch,
19334 dismissError,
19335 clearCompleted,
19336 allComplete
19337 } = useUploadStatus({ onBatchComplete: handleBatchComplete });
19338 const isPopoverOpenRef = (0, import_element68.useRef)(false);
19339 const handlePopoverOpenChange = (0, import_element68.useCallback)(
19340 (open) => {
19341 isPopoverOpenRef.current = open;
19342 if (!open) {
19343 clearCompleted();
19344 }
19345 },
19346 [clearCompleted]
19347 );
19348 const {
19349 records: mediaRecords,
19350 isResolving: isLoading,
19351 totalItems,
19352 totalPages
19353 } = useEntityRecordsWithPermissions("postType", "attachment", queryArgs);
19354 const fields = (0, import_element68.useMemo)(
19355 () => [
19356 // Media field definitions from @wordpress/media-fields
19357 // Cast is safe because RestAttachment has the same properties as Attachment
19358 {
19359 ...media_thumbnail_default,
19360 enableHiding: false
19361 // Within the modal, the thumbnail should always be shown.
19362 },
19363 {
19364 id: "title",
19365 type: "text",
19366 label: (0, import_i18n66.__)("Title"),
19367 getValue: ({ item }) => {
19368 const titleValue = item.title.raw || item.title.rendered;
19369 return titleValue || (0, import_i18n66.__)("(no title)");
19370 }
19371 },
19372 alt_text_default,
19373 caption_default,
19374 description_default,
19375 date_added_default,
19376 date_modified_default,
19377 author_default,
19378 filename_default,
19379 filesize_default,
19380 media_dimensions_default,
19381 mime_type_default,
19382 attached_to_default
19383 ],
19384 []
19385 );
19386 const actions = (0, import_element68.useMemo)(
19387 () => [
19388 {
19389 id: "select",
19390 label: (0, import_i18n66.__)("Select"),
19391 isPrimary: true,
19392 supportsBulk: multiple,
19393 async callback() {
19394 if (selection.length === 0) {
19395 return;
19396 }
19397 const selectedPostsQuery = {
19398 include: selection,
19399 per_page: -1
19400 };
19401 const selectedPosts = await (0, import_data13.resolveSelect)(
19402 import_core_data6.store
19403 ).getEntityRecords(
19404 "postType",
19405 "attachment",
19406 selectedPostsQuery
19407 );
19408 const transformedPosts = (selectedPosts ?? []).map(transformAttachment).filter(Boolean);
19409 const selectedItems = multiple ? transformedPosts : transformedPosts?.[0];
19410 removeAllNotices("snackbar", NOTICES_CONTEXT);
19411 onSelect(selectedItems);
19412 }
19413 }
19414 ],
19415 [multiple, onSelect, selection, removeAllNotices]
19416 );
19417 const handleModalClose = (0, import_element68.useCallback)(() => {
19418 removeAllNotices("snackbar", NOTICES_CONTEXT);
19419 onClose?.();
19420 }, [removeAllNotices, onClose]);
19421 (0, import_element68.useEffect)(() => {
19422 if (!isOpen) {
19423 setQueryParams(defaultQueryParams);
19424 }
19425 }, [isOpen]);
19426 const handleUpload = onUpload || uploadMedia;
19427 const prevAllCompleteRef = (0, import_element68.useRef)(false);
19428 (0, import_element68.useEffect)(() => {
19429 if (allComplete && !prevAllCompleteRef.current) {
19430 const completeCount = uploadingFiles.filter(
19431 (file) => file.status === "uploaded"
19432 ).length;
19433 if (completeCount > 0) {
19434 createSuccessNotice(
19435 (0, import_i18n66.sprintf)(
19436 // translators: %s: number of files
19437 (0, import_i18n66._n)(
19438 "Uploaded %s file",
19439 "Uploaded %s files",
19440 completeCount
19441 ),
19442 completeCount.toLocaleString()
19443 ),
19444 {
19445 type: "snackbar",
19446 context: NOTICES_CONTEXT,
19447 id: NOTICE_ID_UPLOAD_PROGRESS
19448 }
19449 );
19450 }
19451 if (!isPopoverOpenRef.current) {
19452 clearCompleted();
19453 }
19454 }
19455 prevAllCompleteRef.current = allComplete;
19456 }, [allComplete, uploadingFiles, createSuccessNotice, clearCompleted]);
19457 const handleFileSelect = (0, import_element68.useCallback)(
19458 (event) => {
19459 const files = event.target.files;
19460 if (files && files.length > 0) {
19461 const filesArray = Array.from(files);
19462 const { onFileChange, onError } = registerBatch(filesArray);
19463 handleUpload({
19464 allowedTypes,
19465 filesList: filesArray,
19466 onFileChange,
19467 onError
19468 });
19469 }
19470 },
19471 [allowedTypes, handleUpload, registerBatch]
19472 );
19473 const paginationInfo = (0, import_element68.useMemo)(
19474 () => ({
19475 totalItems,
19476 totalPages
19477 }),
19478 [totalItems, totalPages]
19479 );
19480 const acceptTypes = (0, import_element68.useMemo)(() => {
19481 if (allowedTypes?.includes("*")) {
19482 return void 0;
19483 }
19484 return allowedTypes?.join(",");
19485 }, [allowedTypes]);
19486 if (!isOpen) {
19487 return null;
19488 }
19489 return /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19490 import_components53.Modal,
19491 {
19492 title,
19493 onRequestClose: handleModalClose,
19494 isDismissible,
19495 className: modalClass,
19496 overlayClassName: "media-upload-modal",
19497 size: "fill",
19498 headerActions: /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19499 import_components53.FormFileUpload,
19500 {
19501 accept: acceptTypes,
19502 multiple: true,
19503 onChange: handleFileSelect,
19504 __next40pxDefaultSize: true,
19505 render: ({ openFileDialog }) => /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19506 import_components53.Button,
19507 {
19508 onClick: openFileDialog,
19509 icon: upload_default,
19510 __next40pxDefaultSize: true,
19511 children: (0, import_i18n66.__)("Upload media")
19512 }
19513 )
19514 }
19515 ),
19516 children: [
19517 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19518 import_components53.DropZone,
19519 {
19520 onFilesDrop: (files) => {
19521 let filteredFiles = files;
19522 if (allowedTypes && !allowedTypes.includes("*")) {
19523 filteredFiles = files.filter(
19524 (file) => allowedTypes.some((allowedType) => {
19525 return file.type === allowedType || file.type.startsWith(
19526 allowedType.replace("*", "")
19527 );
19528 })
19529 );
19530 }
19531 if (filteredFiles.length > 0) {
19532 const { onFileChange, onError } = registerBatch(filteredFiles);
19533 handleUpload({
19534 allowedTypes,
19535 filesList: filteredFiles,
19536 onFileChange,
19537 onError
19538 });
19539 }
19540 },
19541 label: (0, import_i18n66.__)("Drop files to upload")
19542 }
19543 ),
19544 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19545 dataviews_picker_default,
19546 {
19547 data: mediaRecords || [],
19548 fields,
19549 view,
19550 onChangeView: handleChangeView,
19551 actions,
19552 selection,
19553 onChangeSelection: setSelection,
19554 isLoading,
19555 paginationInfo,
19556 defaultLayouts,
19557 getItemId: (item) => String(item.id),
19558 itemListLabel: (0, import_i18n66.__)("Media items"),
19559 onReset: isModified ? resetToDefault : false,
19560 children: [
19561 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19562 Stack,
19563 {
19564 direction: "row",
19565 align: "top",
19566 justify: "space-between",
19567 className: "dataviews__view-actions",
19568 gap: "xs",
19569 children: [
19570 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19571 Stack,
19572 {
19573 direction: "row",
19574 gap: "sm",
19575 justify: "start",
19576 className: "dataviews__search",
19577 children: [
19578 search && /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.Search, { label: searchLabel }),
19579 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.FiltersToggle, {})
19580 ]
19581 }
19582 ),
19583 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(Stack, { direction: "row", gap: "xs", style: { flexShrink: 0 }, children: [
19584 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.LayoutSwitcher, {}),
19585 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.ViewConfig, {})
19586 ] })
19587 ]
19588 }
19589 ),
19590 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.FiltersToggled, { className: "dataviews-filters__container" }),
19591 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.Layout, {}),
19592 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19593 "div",
19594 {
19595 className: clsx_default("media-upload-modal__footer", {
19596 "is-uploading": uploadingFiles.length > 0
19597 }),
19598 children: [
19599 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19600 UploadStatusPopover,
19601 {
19602 uploadingFiles,
19603 onDismissError: dismissError,
19604 onOpenChange: handlePopoverOpenChange
19605 }
19606 ),
19607 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.BulkActionToolbar, {})
19608 ]
19609 }
19610 )
19611 ]
19612 }
19613 ),
19614 (0, import_element68.createPortal)(
19615 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19616 import_notices.SnackbarNotices,
19617 {
19618 className: "media-upload-modal__snackbar",
19619 context: NOTICES_CONTEXT
19620 }
19621 ),
19622 document.body
19623 )
19624 ]
19625 }
19626 );
19627 }
19628
19629 // packages/media-utils/build-module/private-apis.mjs
19630 var privateApis12 = {};
19631 lock3(privateApis12, {
19632 sideloadMedia,
19633 MediaUploadModal
19634 });
19635 return __toCommonJS(index_exports);
19636 })();
19637 /*! Bundled license information:
19638
19639 use-sync-external-store/cjs/use-sync-external-store-shim.development.js:
19640 (**
19641 * @license React
19642 * use-sync-external-store-shim.development.js
19643 *
19644 * Copyright (c) Meta Platforms, Inc. and affiliates.
19645 *
19646 * This source code is licensed under the MIT license found in the
19647 * LICENSE file in the root directory of this source tree.
19648 *)
19649 */
19650 //# sourceMappingURL=index.js.map
19651