PluginProbe
Gutenberg / 22.9.0
Gutenberg v22.9.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 22.9.0, at build/scripts/media-utils/index.js

19,093 lines 675.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/url
762 var require_url = __commonJS({
763 "package-external:@wordpress/url"(exports, module) {
764 module.exports = window.wp.url;
765 }
766 });
767
768 // package-external:@wordpress/notices
769 var require_notices = __commonJS({
770 "package-external:@wordpress/notices"(exports, module) {
771 module.exports = window.wp.notices;
772 }
773 });
774
775 // packages/media-utils/build-module/index.mjs
776 var index_exports = {};
777 __export(index_exports, {
778 MediaUpload: () => media_upload_default,
779 privateApis: () => privateApis12,
780 transformAttachment: () => transformAttachment,
781 uploadMedia: () => uploadMedia,
782 validateFileSize: () => validateFileSize,
783 validateMimeType: () => validateMimeType,
784 validateMimeTypeForUser: () => validateMimeTypeForUser
785 });
786
787 // packages/media-utils/build-module/components/media-upload/index.mjs
788 var import_element = __toESM(require_element(), 1);
789 var import_i18n = __toESM(require_i18n(), 1);
790 var DEFAULT_EMPTY_GALLERY = [];
791 var getFeaturedImageMediaFrame = () => {
792 const { wp } = window;
793 return wp.media.view.MediaFrame.Select.extend({
794 /**
795 * Enables the Set Featured Image Button.
796 *
797 * @param {Object} toolbar toolbar for featured image state
798 * @return {void}
799 */
800 featuredImageToolbar(toolbar) {
801 this.createSelectToolbar(toolbar, {
802 text: wp.media.view.l10n.setFeaturedImage,
803 state: this.options.state
804 });
805 },
806 /**
807 * Handle the edit state requirements of selected media item.
808 *
809 * @return {void}
810 */
811 editState() {
812 const selection = this.state("featured-image").get("selection");
813 const view = new wp.media.view.EditImage({
814 model: selection.single(),
815 controller: this
816 }).render();
817 this.content.set(view);
818 view.loadEditor();
819 },
820 /**
821 * Create the default states.
822 *
823 * @return {void}
824 */
825 createStates: function createStates() {
826 this.on(
827 "toolbar:create:featured-image",
828 this.featuredImageToolbar,
829 this
830 );
831 this.on("content:render:edit-image", this.editState, this);
832 this.states.add([
833 new wp.media.controller.FeaturedImage(),
834 new wp.media.controller.EditImage({
835 model: this.options.editImage
836 })
837 ]);
838 }
839 });
840 };
841 var getSingleMediaFrame = () => {
842 const { wp } = window;
843 return wp.media.view.MediaFrame.Select.extend({
844 /**
845 * Create the default states on the frame.
846 */
847 createStates() {
848 const options = this.options;
849 if (this.options.states) {
850 return;
851 }
852 this.states.add([
853 // Main states.
854 new wp.media.controller.Library({
855 library: wp.media.query(options.library),
856 multiple: options.multiple,
857 title: options.title,
858 priority: 20,
859 filterable: "uploaded"
860 // Allow filtering by uploaded images.
861 }),
862 new wp.media.controller.EditImage({
863 model: options.editImage
864 })
865 ]);
866 }
867 });
868 };
869 var getGalleryDetailsMediaFrame = () => {
870 const { wp } = window;
871 return wp.media.view.MediaFrame.Post.extend({
872 /**
873 * Set up gallery toolbar.
874 *
875 * @return {void}
876 */
877 galleryToolbar() {
878 const editing = this.state().get("editing");
879 this.toolbar.set(
880 new wp.media.view.Toolbar({
881 controller: this,
882 items: {
883 insert: {
884 style: "primary",
885 text: editing ? wp.media.view.l10n.updateGallery : wp.media.view.l10n.insertGallery,
886 priority: 80,
887 requires: { library: true },
888 /**
889 * @fires wp.media.controller.State#update
890 */
891 click() {
892 const controller = this.controller, state = controller.state();
893 controller.close();
894 state.trigger(
895 "update",
896 state.get("library")
897 );
898 controller.setState(controller.options.state);
899 controller.reset();
900 }
901 }
902 }
903 })
904 );
905 },
906 /**
907 * Handle the edit state requirements of selected media item.
908 *
909 * @return {void}
910 */
911 editState() {
912 const selection = this.state("gallery").get("selection");
913 const view = new wp.media.view.EditImage({
914 model: selection.single(),
915 controller: this
916 }).render();
917 this.content.set(view);
918 view.loadEditor();
919 },
920 /**
921 * Create the default states.
922 *
923 * @return {void}
924 */
925 createStates: function createStates() {
926 this.on("toolbar:create:main-gallery", this.galleryToolbar, this);
927 this.on("content:render:edit-image", this.editState, this);
928 this.states.add([
929 new wp.media.controller.Library({
930 id: "gallery",
931 title: wp.media.view.l10n.createGalleryTitle,
932 priority: 40,
933 toolbar: "main-gallery",
934 filterable: "uploaded",
935 multiple: "add",
936 editable: false,
937 library: wp.media.query({
938 type: "image",
939 ...this.options.library
940 })
941 }),
942 new wp.media.controller.EditImage({
943 model: this.options.editImage
944 }),
945 new wp.media.controller.GalleryEdit({
946 library: this.options.selection,
947 editing: this.options.editing,
948 menu: "gallery",
949 displaySettings: false,
950 multiple: true
951 }),
952 new wp.media.controller.GalleryAdd()
953 ]);
954 }
955 });
956 };
957 var slimImageObject = (img) => {
958 const attrSet = [
959 "sizes",
960 "mime",
961 "type",
962 "subtype",
963 "id",
964 "url",
965 "alt",
966 "link",
967 "caption"
968 ];
969 return attrSet.reduce((result, key) => {
970 if (img?.hasOwnProperty(key)) {
971 result[key] = img[key];
972 }
973 return result;
974 }, {});
975 };
976 var getAttachmentsCollection = (ids) => {
977 const { wp } = window;
978 return wp.media.query({
979 order: "ASC",
980 orderby: "post__in",
981 post__in: ids,
982 posts_per_page: -1,
983 query: true,
984 type: "image"
985 });
986 };
987 var MediaUpload = class extends import_element.Component {
988 constructor() {
989 super(...arguments);
990 this.openModal = this.openModal.bind(this);
991 this.onOpen = this.onOpen.bind(this);
992 this.onSelect = this.onSelect.bind(this);
993 this.onUpdate = this.onUpdate.bind(this);
994 this.onClose = this.onClose.bind(this);
995 }
996 initializeListeners() {
997 this.frame.on("select", this.onSelect);
998 this.frame.on("update", this.onUpdate);
999 this.frame.on("open", this.onOpen);
1000 this.frame.on("close", this.onClose);
1001 }
1002 /**
1003 * Sets the Gallery frame and initializes listeners.
1004 *
1005 * @return {void}
1006 */
1007 buildAndSetGalleryFrame() {
1008 const {
1009 addToGallery = false,
1010 allowedTypes,
1011 multiple = false,
1012 value = DEFAULT_EMPTY_GALLERY
1013 } = this.props;
1014 if (value === this.lastGalleryValue) {
1015 return;
1016 }
1017 const { wp } = window;
1018 this.lastGalleryValue = value;
1019 if (this.frame) {
1020 this.frame.remove();
1021 }
1022 let currentState;
1023 if (addToGallery) {
1024 currentState = "gallery-library";
1025 } else {
1026 currentState = value && value.length ? "gallery-edit" : "gallery";
1027 }
1028 if (!this.GalleryDetailsMediaFrame) {
1029 this.GalleryDetailsMediaFrame = getGalleryDetailsMediaFrame();
1030 }
1031 const attachments = getAttachmentsCollection(value);
1032 const selection = new wp.media.model.Selection(attachments.models, {
1033 props: attachments.props.toJSON(),
1034 multiple
1035 });
1036 this.frame = new this.GalleryDetailsMediaFrame({
1037 mimeType: allowedTypes,
1038 state: currentState,
1039 multiple,
1040 selection,
1041 editing: !!value?.length
1042 });
1043 wp.media.frame = this.frame;
1044 this.initializeListeners();
1045 }
1046 /**
1047 * Initializes the Media Library requirements for the featured image flow.
1048 *
1049 * @return {void}
1050 */
1051 buildAndSetFeatureImageFrame() {
1052 const { wp } = window;
1053 const { value: featuredImageId, multiple, allowedTypes } = this.props;
1054 const featuredImageFrame = getFeaturedImageMediaFrame();
1055 const attachments = getAttachmentsCollection(featuredImageId);
1056 const selection = new wp.media.model.Selection(attachments.models, {
1057 props: attachments.props.toJSON()
1058 });
1059 this.frame = new featuredImageFrame({
1060 mimeType: allowedTypes,
1061 state: "featured-image",
1062 multiple,
1063 selection,
1064 editing: featuredImageId
1065 });
1066 wp.media.frame = this.frame;
1067 wp.media.view.settings.post = {
1068 ...wp.media.view.settings.post,
1069 featuredImageId: featuredImageId || -1
1070 };
1071 }
1072 /**
1073 * Initializes the Media Library requirements for the single image flow.
1074 *
1075 * @return {void}
1076 */
1077 buildAndSetSingleMediaFrame() {
1078 const { wp } = window;
1079 const {
1080 allowedTypes,
1081 multiple = false,
1082 title = (0, import_i18n.__)("Select or Upload Media"),
1083 value
1084 } = this.props;
1085 const frameConfig = {
1086 title,
1087 multiple
1088 };
1089 if (!!allowedTypes) {
1090 frameConfig.library = { type: allowedTypes };
1091 }
1092 if (this.frame) {
1093 this.frame.remove();
1094 }
1095 const singleImageFrame = getSingleMediaFrame();
1096 const attachments = getAttachmentsCollection(value);
1097 const selection = new wp.media.model.Selection(attachments.models, {
1098 props: attachments.props.toJSON()
1099 });
1100 this.frame = new singleImageFrame({
1101 mimeType: allowedTypes,
1102 multiple,
1103 selection,
1104 ...frameConfig
1105 });
1106 wp.media.frame = this.frame;
1107 }
1108 componentWillUnmount() {
1109 this.frame?.remove();
1110 }
1111 onUpdate(selections) {
1112 const { onSelect, multiple = false } = this.props;
1113 const state = this.frame.state();
1114 const selectedImages = selections || state.get("selection");
1115 if (!selectedImages || !selectedImages.models.length) {
1116 return;
1117 }
1118 if (multiple) {
1119 onSelect(
1120 selectedImages.models.map(
1121 (model) => slimImageObject(model.toJSON())
1122 )
1123 );
1124 } else {
1125 onSelect(slimImageObject(selectedImages.models[0].toJSON()));
1126 }
1127 }
1128 onSelect() {
1129 const { onSelect, multiple = false } = this.props;
1130 const attachment = this.frame.state().get("selection").toJSON();
1131 onSelect(multiple ? attachment : attachment[0]);
1132 }
1133 onOpen() {
1134 const { wp } = window;
1135 const { value } = this.props;
1136 this.updateCollection();
1137 if (this.props.mode) {
1138 this.frame.content.mode(this.props.mode);
1139 }
1140 const hasMedia = Array.isArray(value) ? !!value?.length : !!value;
1141 if (!hasMedia) {
1142 return;
1143 }
1144 const isGallery = this.props.gallery;
1145 const selection = this.frame.state().get("selection");
1146 const valueArray = Array.isArray(value) ? value : [value];
1147 if (!isGallery) {
1148 valueArray.forEach((id) => {
1149 selection.add(wp.media.attachment(id));
1150 });
1151 }
1152 const attachments = getAttachmentsCollection(valueArray);
1153 attachments.more().done(function() {
1154 if (isGallery && attachments?.models?.length) {
1155 selection.add(attachments.models);
1156 }
1157 });
1158 }
1159 onClose() {
1160 const { onClose } = this.props;
1161 if (onClose) {
1162 onClose();
1163 }
1164 this.frame.detach();
1165 }
1166 updateCollection() {
1167 const frameContent = this.frame.content.get();
1168 if (frameContent && frameContent.collection) {
1169 const collection = frameContent.collection;
1170 collection.toArray().forEach((model) => model.trigger("destroy", model));
1171 collection.mirroring._hasMore = true;
1172 collection.more();
1173 }
1174 }
1175 openModal() {
1176 const {
1177 gallery = false,
1178 unstableFeaturedImageFlow = false,
1179 modalClass
1180 } = this.props;
1181 if (gallery) {
1182 this.buildAndSetGalleryFrame();
1183 } else {
1184 this.buildAndSetSingleMediaFrame();
1185 }
1186 if (modalClass) {
1187 this.frame.$el.addClass(modalClass);
1188 }
1189 if (unstableFeaturedImageFlow) {
1190 this.buildAndSetFeatureImageFrame();
1191 }
1192 this.initializeListeners();
1193 this.frame.open();
1194 }
1195 render() {
1196 return this.props.render({ open: this.openModal });
1197 }
1198 };
1199 var media_upload_default = MediaUpload;
1200
1201 // packages/media-utils/build-module/utils/upload-media.mjs
1202 var import_i18n5 = __toESM(require_i18n(), 1);
1203 var import_blob = __toESM(require_blob(), 1);
1204
1205 // packages/media-utils/build-module/utils/upload-to-server.mjs
1206 var import_api_fetch = __toESM(require_api_fetch(), 1);
1207
1208 // packages/media-utils/build-module/utils/flatten-form-data.mjs
1209 function isPlainObject(data) {
1210 return data !== null && typeof data === "object" && Object.getPrototypeOf(data) === Object.prototype;
1211 }
1212 function flattenFormData(formData, key, data) {
1213 if (isPlainObject(data)) {
1214 for (const [name, value] of Object.entries(data)) {
1215 flattenFormData(formData, `${key}[${name}]`, value);
1216 }
1217 } else if (data !== void 0) {
1218 formData.append(key, String(data));
1219 }
1220 }
1221
1222 // packages/media-utils/build-module/utils/transform-attachment.mjs
1223 function transformAttachment(attachment) {
1224 const { alt_text, source_url, ...savedMediaProps } = attachment;
1225 return {
1226 ...savedMediaProps,
1227 alt: attachment.alt_text,
1228 caption: attachment.caption?.raw ?? "",
1229 title: attachment.title.raw,
1230 url: attachment.source_url,
1231 poster: attachment._embedded?.["wp:featuredmedia"]?.[0]?.source_url || void 0
1232 };
1233 }
1234
1235 // packages/media-utils/build-module/utils/upload-to-server.mjs
1236 async function uploadToServer(file, additionalData = {}, signal) {
1237 const data = new FormData();
1238 data.append("file", file, file.name || file.type.replace("/", "."));
1239 for (const [key, value] of Object.entries(additionalData)) {
1240 flattenFormData(
1241 data,
1242 key,
1243 value
1244 );
1245 }
1246 return transformAttachment(
1247 await (0, import_api_fetch.default)({
1248 // This allows the video block to directly get a video's poster image.
1249 path: "/wp/v2/media?_embed=wp:featuredmedia",
1250 body: data,
1251 method: "POST",
1252 signal
1253 })
1254 );
1255 }
1256
1257 // packages/media-utils/build-module/utils/validate-mime-type.mjs
1258 var import_i18n2 = __toESM(require_i18n(), 1);
1259
1260 // packages/media-utils/build-module/utils/upload-error.mjs
1261 var UploadError = class extends Error {
1262 code;
1263 file;
1264 constructor({ code, message: message2, file, cause }) {
1265 super(message2, { cause });
1266 Object.setPrototypeOf(this, new.target.prototype);
1267 this.code = code;
1268 this.file = file;
1269 }
1270 };
1271
1272 // packages/media-utils/build-module/utils/validate-mime-type.mjs
1273 function validateMimeType(file, allowedTypes) {
1274 if (!allowedTypes) {
1275 return;
1276 }
1277 const isAllowedType = allowedTypes.some((allowedType) => {
1278 if (allowedType.includes("/")) {
1279 return allowedType === file.type;
1280 }
1281 return file.type.startsWith(`${allowedType}/`);
1282 });
1283 if (file.type && !isAllowedType) {
1284 throw new UploadError({
1285 code: "MIME_TYPE_NOT_SUPPORTED",
1286 message: (0, import_i18n2.sprintf)(
1287 // translators: %s: file name.
1288 (0, import_i18n2.__)("%s: Sorry, this file type is not supported here."),
1289 file.name
1290 ),
1291 file
1292 });
1293 }
1294 }
1295
1296 // packages/media-utils/build-module/utils/validate-mime-type-for-user.mjs
1297 var import_i18n3 = __toESM(require_i18n(), 1);
1298
1299 // packages/media-utils/build-module/utils/get-mime-types-array.mjs
1300 function getMimeTypesArray(wpMimeTypesObject) {
1301 if (!wpMimeTypesObject) {
1302 return null;
1303 }
1304 return Object.entries(wpMimeTypesObject).flatMap(
1305 ([extensionsString, mime]) => {
1306 const [type] = mime.split("/");
1307 const extensions = extensionsString.split("|");
1308 return [
1309 mime,
1310 ...extensions.map(
1311 (extension) => `${type}/${extension}`
1312 )
1313 ];
1314 }
1315 );
1316 }
1317
1318 // packages/media-utils/build-module/utils/validate-mime-type-for-user.mjs
1319 function validateMimeTypeForUser(file, wpAllowedMimeTypes) {
1320 const allowedMimeTypesForUser = getMimeTypesArray(wpAllowedMimeTypes);
1321 if (!allowedMimeTypesForUser) {
1322 return;
1323 }
1324 const isAllowedMimeTypeForUser = allowedMimeTypesForUser.includes(
1325 file.type
1326 );
1327 if (file.type && !isAllowedMimeTypeForUser) {
1328 throw new UploadError({
1329 code: "MIME_TYPE_NOT_ALLOWED_FOR_USER",
1330 message: (0, import_i18n3.sprintf)(
1331 // translators: %s: file name.
1332 (0, import_i18n3.__)(
1333 "%s: Sorry, you are not allowed to upload this file type."
1334 ),
1335 file.name
1336 ),
1337 file
1338 });
1339 }
1340 }
1341
1342 // packages/media-utils/build-module/utils/validate-file-size.mjs
1343 var import_i18n4 = __toESM(require_i18n(), 1);
1344 function validateFileSize(file, maxUploadFileSize) {
1345 if (file.size <= 0) {
1346 throw new UploadError({
1347 code: "EMPTY_FILE",
1348 message: (0, import_i18n4.sprintf)(
1349 // translators: %s: file name.
1350 (0, import_i18n4.__)("%s: This file is empty."),
1351 file.name
1352 ),
1353 file
1354 });
1355 }
1356 if (maxUploadFileSize && file.size > maxUploadFileSize) {
1357 throw new UploadError({
1358 code: "SIZE_ABOVE_LIMIT",
1359 message: (0, import_i18n4.sprintf)(
1360 // translators: %s: file name.
1361 (0, import_i18n4.__)(
1362 "%s: This file exceeds the maximum upload size for this site."
1363 ),
1364 file.name
1365 ),
1366 file
1367 });
1368 }
1369 }
1370
1371 // packages/media-utils/build-module/utils/upload-media.mjs
1372 function uploadMedia({
1373 wpAllowedMimeTypes,
1374 allowedTypes,
1375 additionalData = {},
1376 filesList,
1377 maxUploadFileSize,
1378 onError,
1379 onFileChange,
1380 signal,
1381 multiple = true
1382 }) {
1383 if (!multiple && filesList.length > 1) {
1384 onError?.(new Error((0, import_i18n5.__)("Only one file can be used here.")));
1385 return;
1386 }
1387 const validFiles = [];
1388 const filesSet = [];
1389 const setAndUpdateFiles = (index, value) => {
1390 if (!window.__clientSideMediaProcessing) {
1391 if (filesSet[index]?.url) {
1392 (0, import_blob.revokeBlobURL)(filesSet[index].url);
1393 }
1394 }
1395 filesSet[index] = value;
1396 onFileChange?.(
1397 filesSet.filter((attachment) => attachment !== null)
1398 );
1399 };
1400 for (const mediaFile of filesList) {
1401 try {
1402 validateMimeTypeForUser(mediaFile, wpAllowedMimeTypes);
1403 } catch (error) {
1404 onError?.(error);
1405 continue;
1406 }
1407 try {
1408 validateMimeType(mediaFile, allowedTypes);
1409 } catch (error) {
1410 onError?.(error);
1411 continue;
1412 }
1413 try {
1414 validateFileSize(mediaFile, maxUploadFileSize);
1415 } catch (error) {
1416 onError?.(error);
1417 continue;
1418 }
1419 validFiles.push(mediaFile);
1420 if (!window.__clientSideMediaProcessing) {
1421 filesSet.push({ url: (0, import_blob.createBlobURL)(mediaFile) });
1422 onFileChange?.(filesSet);
1423 }
1424 }
1425 validFiles.map(async (file, index) => {
1426 try {
1427 const attachment = await uploadToServer(
1428 file,
1429 additionalData,
1430 signal
1431 );
1432 setAndUpdateFiles(index, attachment);
1433 } catch (error) {
1434 setAndUpdateFiles(index, null);
1435 let message2;
1436 if (typeof error === "object" && error !== null && "message" in error) {
1437 message2 = typeof error.message === "string" ? error.message : String(error.message);
1438 } else {
1439 message2 = (0, import_i18n5.sprintf)(
1440 // translators: %s: file name
1441 (0, import_i18n5.__)("Error while uploading file %s to the media library."),
1442 file.name
1443 );
1444 }
1445 onError?.(
1446 new UploadError({
1447 code: "GENERAL",
1448 message: message2,
1449 file,
1450 cause: error instanceof Error ? error : void 0
1451 })
1452 );
1453 }
1454 });
1455 }
1456
1457 // packages/media-utils/build-module/utils/sideload-media.mjs
1458 var import_i18n6 = __toESM(require_i18n(), 1);
1459
1460 // packages/media-utils/build-module/utils/sideload-to-server.mjs
1461 var import_api_fetch2 = __toESM(require_api_fetch(), 1);
1462 async function sideloadToServer(file, attachmentId, additionalData = {}, signal) {
1463 const data = new FormData();
1464 data.append("file", file, file.name || file.type.replace("/", "."));
1465 for (const [key, value] of Object.entries(additionalData)) {
1466 flattenFormData(
1467 data,
1468 key,
1469 value
1470 );
1471 }
1472 return transformAttachment(
1473 await (0, import_api_fetch2.default)({
1474 path: `/wp/v2/media/${attachmentId}/sideload`,
1475 body: data,
1476 method: "POST",
1477 signal
1478 })
1479 );
1480 }
1481
1482 // packages/media-utils/build-module/utils/sideload-media.mjs
1483 var noop = () => {
1484 };
1485 async function sideloadMedia({
1486 file,
1487 attachmentId,
1488 additionalData = {},
1489 signal,
1490 onFileChange,
1491 onError = noop
1492 }) {
1493 try {
1494 const attachment = await sideloadToServer(
1495 file,
1496 attachmentId,
1497 additionalData,
1498 signal
1499 );
1500 onFileChange?.([attachment]);
1501 } catch (error) {
1502 let message2;
1503 if (error instanceof Error) {
1504 message2 = error.message;
1505 } else {
1506 message2 = (0, import_i18n6.sprintf)(
1507 // translators: %s: file name
1508 (0, import_i18n6.__)("Error while sideloading file %s to the server."),
1509 file.name
1510 );
1511 }
1512 onError(
1513 new UploadError({
1514 code: "GENERAL",
1515 message: message2,
1516 file,
1517 cause: error instanceof Error ? error : void 0
1518 })
1519 );
1520 }
1521 }
1522
1523 // node_modules/clsx/dist/clsx.mjs
1524 function r(e2) {
1525 var t2, f2, n2 = "";
1526 if ("string" == typeof e2 || "number" == typeof e2) n2 += e2;
1527 else if ("object" == typeof e2) if (Array.isArray(e2)) {
1528 var o2 = e2.length;
1529 for (t2 = 0; t2 < o2; t2++) e2[t2] && (f2 = r(e2[t2])) && (n2 && (n2 += " "), n2 += f2);
1530 } else for (f2 in e2) e2[f2] && (n2 && (n2 += " "), n2 += f2);
1531 return n2;
1532 }
1533 function clsx() {
1534 for (var e2, t2, f2 = 0, n2 = "", o2 = arguments.length; f2 < o2; f2++) (e2 = arguments[f2]) && (t2 = r(e2)) && (n2 && (n2 += " "), n2 += t2);
1535 return n2;
1536 }
1537 var clsx_default = clsx;
1538
1539 // packages/media-utils/build-module/components/media-upload-modal/index.mjs
1540 var import_element65 = __toESM(require_element(), 1);
1541 var import_i18n66 = __toESM(require_i18n(), 1);
1542 var import_core_data5 = __toESM(require_core_data(), 1);
1543 var import_data10 = __toESM(require_data(), 1);
1544 var import_components54 = __toESM(require_components(), 1);
1545
1546 // packages/icons/build-module/library/arrow-down.mjs
1547 var import_primitives = __toESM(require_primitives(), 1);
1548 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
1549 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" }) });
1550
1551 // packages/icons/build-module/library/arrow-left.mjs
1552 var import_primitives2 = __toESM(require_primitives(), 1);
1553 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
1554 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" }) });
1555
1556 // packages/icons/build-module/library/arrow-right.mjs
1557 var import_primitives3 = __toESM(require_primitives(), 1);
1558 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
1559 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" }) });
1560
1561 // packages/icons/build-module/library/arrow-up.mjs
1562 var import_primitives4 = __toESM(require_primitives(), 1);
1563 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
1564 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" }) });
1565
1566 // packages/icons/build-module/library/audio.mjs
1567 var import_primitives5 = __toESM(require_primitives(), 1);
1568 var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
1569 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" }) });
1570
1571 // packages/icons/build-module/library/block-table.mjs
1572 var import_primitives6 = __toESM(require_primitives(), 1);
1573 var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
1574 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" }) });
1575
1576 // packages/icons/build-module/library/category.mjs
1577 var import_primitives7 = __toESM(require_primitives(), 1);
1578 var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
1579 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" }) });
1580
1581 // packages/icons/build-module/library/check.mjs
1582 var import_primitives8 = __toESM(require_primitives(), 1);
1583 var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
1584 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" }) });
1585
1586 // packages/icons/build-module/library/chevron-down.mjs
1587 var import_primitives9 = __toESM(require_primitives(), 1);
1588 var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
1589 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" }) });
1590
1591 // packages/icons/build-module/library/close-small.mjs
1592 var import_primitives10 = __toESM(require_primitives(), 1);
1593 var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1);
1594 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" }) });
1595
1596 // packages/icons/build-module/library/cog.mjs
1597 var import_primitives11 = __toESM(require_primitives(), 1);
1598 var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1);
1599 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" }) });
1600
1601 // packages/icons/build-module/library/comment-author-avatar.mjs
1602 var import_primitives12 = __toESM(require_primitives(), 1);
1603 var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1);
1604 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" }) });
1605
1606 // packages/icons/build-module/library/envelope.mjs
1607 var import_primitives13 = __toESM(require_primitives(), 1);
1608 var import_jsx_runtime13 = __toESM(require_jsx_runtime(), 1);
1609 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" }) });
1610
1611 // packages/icons/build-module/library/error.mjs
1612 var import_primitives14 = __toESM(require_primitives(), 1);
1613 var import_jsx_runtime14 = __toESM(require_jsx_runtime(), 1);
1614 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" }) });
1615
1616 // packages/icons/build-module/library/file.mjs
1617 var import_primitives15 = __toESM(require_primitives(), 1);
1618 var import_jsx_runtime15 = __toESM(require_jsx_runtime(), 1);
1619 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" }) });
1620
1621 // packages/icons/build-module/library/format-list-bullets-rtl.mjs
1622 var import_primitives16 = __toESM(require_primitives(), 1);
1623 var import_jsx_runtime16 = __toESM(require_jsx_runtime(), 1);
1624 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" }) });
1625
1626 // packages/icons/build-module/library/format-list-bullets.mjs
1627 var import_primitives17 = __toESM(require_primitives(), 1);
1628 var import_jsx_runtime17 = __toESM(require_jsx_runtime(), 1);
1629 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" }) });
1630
1631 // packages/icons/build-module/library/funnel.mjs
1632 var import_primitives18 = __toESM(require_primitives(), 1);
1633 var import_jsx_runtime18 = __toESM(require_jsx_runtime(), 1);
1634 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" }) });
1635
1636 // packages/icons/build-module/library/image.mjs
1637 var import_primitives19 = __toESM(require_primitives(), 1);
1638 var import_jsx_runtime19 = __toESM(require_jsx_runtime(), 1);
1639 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" }) });
1640
1641 // packages/icons/build-module/library/link.mjs
1642 var import_primitives20 = __toESM(require_primitives(), 1);
1643 var import_jsx_runtime20 = __toESM(require_jsx_runtime(), 1);
1644 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" }) });
1645
1646 // packages/icons/build-module/library/mobile.mjs
1647 var import_primitives21 = __toESM(require_primitives(), 1);
1648 var import_jsx_runtime21 = __toESM(require_jsx_runtime(), 1);
1649 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" }) });
1650
1651 // packages/icons/build-module/library/more-vertical.mjs
1652 var import_primitives22 = __toESM(require_primitives(), 1);
1653 var import_jsx_runtime22 = __toESM(require_jsx_runtime(), 1);
1654 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" }) });
1655
1656 // packages/icons/build-module/library/next.mjs
1657 var import_primitives23 = __toESM(require_primitives(), 1);
1658 var import_jsx_runtime23 = __toESM(require_jsx_runtime(), 1);
1659 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" }) });
1660
1661 // packages/icons/build-module/library/previous.mjs
1662 var import_primitives24 = __toESM(require_primitives(), 1);
1663 var import_jsx_runtime24 = __toESM(require_jsx_runtime(), 1);
1664 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" }) });
1665
1666 // packages/icons/build-module/library/scheduled.mjs
1667 var import_primitives25 = __toESM(require_primitives(), 1);
1668 var import_jsx_runtime25 = __toESM(require_jsx_runtime(), 1);
1669 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" }) });
1670
1671 // packages/icons/build-module/library/search.mjs
1672 var import_primitives26 = __toESM(require_primitives(), 1);
1673 var import_jsx_runtime26 = __toESM(require_jsx_runtime(), 1);
1674 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" }) });
1675
1676 // packages/icons/build-module/library/seen.mjs
1677 var import_primitives27 = __toESM(require_primitives(), 1);
1678 var import_jsx_runtime27 = __toESM(require_jsx_runtime(), 1);
1679 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" }) });
1680
1681 // packages/icons/build-module/library/unseen.mjs
1682 var import_primitives28 = __toESM(require_primitives(), 1);
1683 var import_jsx_runtime28 = __toESM(require_jsx_runtime(), 1);
1684 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" }) });
1685
1686 // packages/icons/build-module/library/upload.mjs
1687 var import_primitives29 = __toESM(require_primitives(), 1);
1688 var import_jsx_runtime29 = __toESM(require_jsx_runtime(), 1);
1689 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" }) });
1690
1691 // packages/icons/build-module/library/video.mjs
1692 var import_primitives30 = __toESM(require_primitives(), 1);
1693 var import_jsx_runtime30 = __toESM(require_jsx_runtime(), 1);
1694 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" }) });
1695
1696 // node_modules/@base-ui/utils/esm/useRefWithInit.js
1697 var React = __toESM(require_react(), 1);
1698 var UNINITIALIZED = {};
1699 function useRefWithInit(init2, initArg) {
1700 const ref = React.useRef(UNINITIALIZED);
1701 if (ref.current === UNINITIALIZED) {
1702 ref.current = init2(initArg);
1703 }
1704 return ref;
1705 }
1706
1707 // node_modules/@base-ui/utils/esm/warn.js
1708 var set;
1709 if (true) {
1710 set = /* @__PURE__ */ new Set();
1711 }
1712 function warn(...messages) {
1713 if (true) {
1714 const messageKey = messages.join(" ");
1715 if (!set.has(messageKey)) {
1716 set.add(messageKey);
1717 console.warn(`Base UI: ${messageKey}`);
1718 }
1719 }
1720 }
1721
1722 // node_modules/@base-ui/react/esm/utils/useRenderElement.js
1723 var React4 = __toESM(require_react(), 1);
1724
1725 // node_modules/@base-ui/utils/esm/useMergedRefs.js
1726 function useMergedRefs(a2, b2, c2, d2) {
1727 const forkRef = useRefWithInit(createForkRef).current;
1728 if (didChange(forkRef, a2, b2, c2, d2)) {
1729 update(forkRef, [a2, b2, c2, d2]);
1730 }
1731 return forkRef.callback;
1732 }
1733 function useMergedRefsN(refs) {
1734 const forkRef = useRefWithInit(createForkRef).current;
1735 if (didChangeN(forkRef, refs)) {
1736 update(forkRef, refs);
1737 }
1738 return forkRef.callback;
1739 }
1740 function createForkRef() {
1741 return {
1742 callback: null,
1743 cleanup: null,
1744 refs: []
1745 };
1746 }
1747 function didChange(forkRef, a2, b2, c2, d2) {
1748 return forkRef.refs[0] !== a2 || forkRef.refs[1] !== b2 || forkRef.refs[2] !== c2 || forkRef.refs[3] !== d2;
1749 }
1750 function didChangeN(forkRef, newRefs) {
1751 return forkRef.refs.length !== newRefs.length || forkRef.refs.some((ref, index) => ref !== newRefs[index]);
1752 }
1753 function update(forkRef, refs) {
1754 forkRef.refs = refs;
1755 if (refs.every((ref) => ref == null)) {
1756 forkRef.callback = null;
1757 return;
1758 }
1759 forkRef.callback = (instance) => {
1760 if (forkRef.cleanup) {
1761 forkRef.cleanup();
1762 forkRef.cleanup = null;
1763 }
1764 if (instance != null) {
1765 const cleanupCallbacks = Array(refs.length).fill(null);
1766 for (let i2 = 0; i2 < refs.length; i2 += 1) {
1767 const ref = refs[i2];
1768 if (ref == null) {
1769 continue;
1770 }
1771 switch (typeof ref) {
1772 case "function": {
1773 const refCleanup = ref(instance);
1774 if (typeof refCleanup === "function") {
1775 cleanupCallbacks[i2] = refCleanup;
1776 }
1777 break;
1778 }
1779 case "object": {
1780 ref.current = instance;
1781 break;
1782 }
1783 default:
1784 }
1785 }
1786 forkRef.cleanup = () => {
1787 for (let i2 = 0; i2 < refs.length; i2 += 1) {
1788 const ref = refs[i2];
1789 if (ref == null) {
1790 continue;
1791 }
1792 switch (typeof ref) {
1793 case "function": {
1794 const cleanupCallback = cleanupCallbacks[i2];
1795 if (typeof cleanupCallback === "function") {
1796 cleanupCallback();
1797 } else {
1798 ref(null);
1799 }
1800 break;
1801 }
1802 case "object": {
1803 ref.current = null;
1804 break;
1805 }
1806 default:
1807 }
1808 }
1809 };
1810 }
1811 };
1812 }
1813
1814 // node_modules/@base-ui/utils/esm/getReactElementRef.js
1815 var React3 = __toESM(require_react(), 1);
1816
1817 // node_modules/@base-ui/utils/esm/reactVersion.js
1818 var React2 = __toESM(require_react(), 1);
1819 var majorVersion = parseInt(React2.version, 10);
1820 function isReactVersionAtLeast(reactVersionToCheck) {
1821 return majorVersion >= reactVersionToCheck;
1822 }
1823
1824 // node_modules/@base-ui/utils/esm/getReactElementRef.js
1825 function getReactElementRef(element) {
1826 if (!/* @__PURE__ */ React3.isValidElement(element)) {
1827 return null;
1828 }
1829 const reactElement = element;
1830 const propsWithRef = reactElement.props;
1831 return (isReactVersionAtLeast(19) ? propsWithRef?.ref : reactElement.ref) ?? null;
1832 }
1833
1834 // node_modules/@base-ui/utils/esm/mergeObjects.js
1835 function mergeObjects(a2, b2) {
1836 if (a2 && !b2) {
1837 return a2;
1838 }
1839 if (!a2 && b2) {
1840 return b2;
1841 }
1842 if (a2 || b2) {
1843 return {
1844 ...a2,
1845 ...b2
1846 };
1847 }
1848 return void 0;
1849 }
1850
1851 // node_modules/@base-ui/react/esm/utils/getStateAttributesProps.js
1852 function getStateAttributesProps(state, customMapping) {
1853 const props = {};
1854 for (const key in state) {
1855 const value = state[key];
1856 if (customMapping?.hasOwnProperty(key)) {
1857 const customProps = customMapping[key](value);
1858 if (customProps != null) {
1859 Object.assign(props, customProps);
1860 }
1861 continue;
1862 }
1863 if (value === true) {
1864 props[`data-${key.toLowerCase()}`] = "";
1865 } else if (value) {
1866 props[`data-${key.toLowerCase()}`] = value.toString();
1867 }
1868 }
1869 return props;
1870 }
1871
1872 // node_modules/@base-ui/react/esm/utils/resolveClassName.js
1873 function resolveClassName(className, state) {
1874 return typeof className === "function" ? className(state) : className;
1875 }
1876
1877 // node_modules/@base-ui/react/esm/utils/resolveStyle.js
1878 function resolveStyle(style, state) {
1879 return typeof style === "function" ? style(state) : style;
1880 }
1881
1882 // node_modules/@base-ui/react/esm/merge-props/mergeProps.js
1883 var EMPTY_PROPS = {};
1884 function mergeProps(a2, b2, c2, d2, e2) {
1885 let merged = {
1886 ...resolvePropsGetter(a2, EMPTY_PROPS)
1887 };
1888 if (b2) {
1889 merged = mergeOne(merged, b2);
1890 }
1891 if (c2) {
1892 merged = mergeOne(merged, c2);
1893 }
1894 if (d2) {
1895 merged = mergeOne(merged, d2);
1896 }
1897 if (e2) {
1898 merged = mergeOne(merged, e2);
1899 }
1900 return merged;
1901 }
1902 function mergePropsN(props) {
1903 if (props.length === 0) {
1904 return EMPTY_PROPS;
1905 }
1906 if (props.length === 1) {
1907 return resolvePropsGetter(props[0], EMPTY_PROPS);
1908 }
1909 let merged = {
1910 ...resolvePropsGetter(props[0], EMPTY_PROPS)
1911 };
1912 for (let i2 = 1; i2 < props.length; i2 += 1) {
1913 merged = mergeOne(merged, props[i2]);
1914 }
1915 return merged;
1916 }
1917 function mergeOne(merged, inputProps) {
1918 if (isPropsGetter(inputProps)) {
1919 return inputProps(merged);
1920 }
1921 return mutablyMergeInto(merged, inputProps);
1922 }
1923 function mutablyMergeInto(mergedProps, externalProps) {
1924 if (!externalProps) {
1925 return mergedProps;
1926 }
1927 for (const propName in externalProps) {
1928 const externalPropValue = externalProps[propName];
1929 switch (propName) {
1930 case "style": {
1931 mergedProps[propName] = mergeObjects(mergedProps.style, externalPropValue);
1932 break;
1933 }
1934 case "className": {
1935 mergedProps[propName] = mergeClassNames(mergedProps.className, externalPropValue);
1936 break;
1937 }
1938 default: {
1939 if (isEventHandler(propName, externalPropValue)) {
1940 mergedProps[propName] = mergeEventHandlers(mergedProps[propName], externalPropValue);
1941 } else {
1942 mergedProps[propName] = externalPropValue;
1943 }
1944 }
1945 }
1946 }
1947 return mergedProps;
1948 }
1949 function isEventHandler(key, value) {
1950 const code0 = key.charCodeAt(0);
1951 const code1 = key.charCodeAt(1);
1952 const code2 = key.charCodeAt(2);
1953 return code0 === 111 && code1 === 110 && code2 >= 65 && code2 <= 90 && (typeof value === "function" || typeof value === "undefined");
1954 }
1955 function isPropsGetter(inputProps) {
1956 return typeof inputProps === "function";
1957 }
1958 function resolvePropsGetter(inputProps, previousProps) {
1959 if (isPropsGetter(inputProps)) {
1960 return inputProps(previousProps);
1961 }
1962 return inputProps ?? EMPTY_PROPS;
1963 }
1964 function mergeEventHandlers(ourHandler, theirHandler) {
1965 if (!theirHandler) {
1966 return ourHandler;
1967 }
1968 if (!ourHandler) {
1969 return theirHandler;
1970 }
1971 return (event) => {
1972 if (isSyntheticEvent(event)) {
1973 const baseUIEvent = event;
1974 makeEventPreventable(baseUIEvent);
1975 const result2 = theirHandler(baseUIEvent);
1976 if (!baseUIEvent.baseUIHandlerPrevented) {
1977 ourHandler?.(baseUIEvent);
1978 }
1979 return result2;
1980 }
1981 const result = theirHandler(event);
1982 ourHandler?.(event);
1983 return result;
1984 };
1985 }
1986 function makeEventPreventable(event) {
1987 event.preventBaseUIHandler = () => {
1988 event.baseUIHandlerPrevented = true;
1989 };
1990 return event;
1991 }
1992 function mergeClassNames(ourClassName, theirClassName) {
1993 if (theirClassName) {
1994 if (ourClassName) {
1995 return theirClassName + " " + ourClassName;
1996 }
1997 return theirClassName;
1998 }
1999 return ourClassName;
2000 }
2001 function isSyntheticEvent(event) {
2002 return event != null && typeof event === "object" && "nativeEvent" in event;
2003 }
2004
2005 // node_modules/@base-ui/utils/esm/empty.js
2006 var EMPTY_ARRAY = Object.freeze([]);
2007 var EMPTY_OBJECT = Object.freeze({});
2008
2009 // node_modules/@base-ui/react/esm/utils/constants.js
2010 var BASE_UI_SWIPE_IGNORE_ATTRIBUTE = "data-base-ui-swipe-ignore";
2011 var LEGACY_SWIPE_IGNORE_ATTRIBUTE = "data-swipe-ignore";
2012 var BASE_UI_SWIPE_IGNORE_SELECTOR = `[${BASE_UI_SWIPE_IGNORE_ATTRIBUTE}]`;
2013 var LEGACY_SWIPE_IGNORE_SELECTOR = `[${LEGACY_SWIPE_IGNORE_ATTRIBUTE}]`;
2014
2015 // node_modules/@base-ui/react/esm/utils/useRenderElement.js
2016 var import_react = __toESM(require_react(), 1);
2017 function useRenderElement(element, componentProps, params = {}) {
2018 const renderProp = componentProps.render;
2019 const outProps = useRenderElementProps(componentProps, params);
2020 if (params.enabled === false) {
2021 return null;
2022 }
2023 const state = params.state ?? EMPTY_OBJECT;
2024 return evaluateRenderProp(element, renderProp, outProps, state);
2025 }
2026 function useRenderElementProps(componentProps, params = {}) {
2027 const {
2028 className: classNameProp,
2029 style: styleProp,
2030 render: renderProp
2031 } = componentProps;
2032 const {
2033 state = EMPTY_OBJECT,
2034 ref,
2035 props,
2036 stateAttributesMapping,
2037 enabled = true
2038 } = params;
2039 const className = enabled ? resolveClassName(classNameProp, state) : void 0;
2040 const style = enabled ? resolveStyle(styleProp, state) : void 0;
2041 const stateProps = enabled ? getStateAttributesProps(state, stateAttributesMapping) : EMPTY_OBJECT;
2042 const outProps = enabled ? mergeObjects(stateProps, Array.isArray(props) ? mergePropsN(props) : props) ?? EMPTY_OBJECT : EMPTY_OBJECT;
2043 if (typeof document !== "undefined") {
2044 if (!enabled) {
2045 useMergedRefs(null, null);
2046 } else if (Array.isArray(ref)) {
2047 outProps.ref = useMergedRefsN([outProps.ref, getReactElementRef(renderProp), ...ref]);
2048 } else {
2049 outProps.ref = useMergedRefs(outProps.ref, getReactElementRef(renderProp), ref);
2050 }
2051 }
2052 if (!enabled) {
2053 return EMPTY_OBJECT;
2054 }
2055 if (className !== void 0) {
2056 outProps.className = mergeClassNames(outProps.className, className);
2057 }
2058 if (style !== void 0) {
2059 outProps.style = mergeObjects(outProps.style, style);
2060 }
2061 return outProps;
2062 }
2063 var REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for("react.lazy");
2064 function evaluateRenderProp(element, render4, props, state) {
2065 if (render4) {
2066 if (typeof render4 === "function") {
2067 if (true) {
2068 warnIfRenderPropLooksLikeComponent(render4);
2069 }
2070 return render4(props, state);
2071 }
2072 const mergedProps = mergeProps(props, render4.props);
2073 mergedProps.ref = props.ref;
2074 let newElement = render4;
2075 if (newElement?.$$typeof === REACT_LAZY_TYPE) {
2076 const children = React4.Children.toArray(render4);
2077 newElement = children[0];
2078 }
2079 if (true) {
2080 if (!/* @__PURE__ */ React4.isValidElement(newElement)) {
2081 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"));
2082 }
2083 }
2084 return /* @__PURE__ */ React4.cloneElement(newElement, mergedProps);
2085 }
2086 if (element) {
2087 if (typeof element === "string") {
2088 return renderTag(element, props);
2089 }
2090 }
2091 throw new Error(true ? "Base UI: Render element or function are not defined." : formatErrorMessage_default(8));
2092 }
2093 function warnIfRenderPropLooksLikeComponent(renderFn) {
2094 const functionName = renderFn.name;
2095 if (functionName.length === 0) {
2096 return;
2097 }
2098 const firstCharacterCode = functionName.charCodeAt(0);
2099 if (firstCharacterCode < 65 || firstCharacterCode > 90) {
2100 return;
2101 }
2102 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");
2103 }
2104 function renderTag(Tag, props) {
2105 if (Tag === "button") {
2106 return /* @__PURE__ */ (0, import_react.createElement)("button", {
2107 type: "button",
2108 ...props,
2109 key: props.key
2110 });
2111 }
2112 if (Tag === "img") {
2113 return /* @__PURE__ */ (0, import_react.createElement)("img", {
2114 alt: "",
2115 ...props,
2116 key: props.key
2117 });
2118 }
2119 return /* @__PURE__ */ React4.createElement(Tag, props);
2120 }
2121
2122 // node_modules/@base-ui/react/esm/use-render/useRender.js
2123 function useRender(params) {
2124 return useRenderElement(params.defaultTagName ?? "div", params, params);
2125 }
2126
2127 // packages/ui/build-module/stack/stack.mjs
2128 var import_element2 = __toESM(require_element(), 1);
2129 if (typeof document !== "undefined" && true && !document.head.querySelector("style[data-wp-hash='b51ff41489']")) {
2130 const style = document.createElement("style");
2131 style.setAttribute("data-wp-hash", "b51ff41489");
2132 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}}"));
2133 document.head.appendChild(style);
2134 }
2135 var style_default = { "stack": "_19ce0419607e1896__stack" };
2136 var gapTokens = {
2137 xs: "var(--wpds-dimension-gap-xs, 4px)",
2138 sm: "var(--wpds-dimension-gap-sm, 8px)",
2139 md: "var(--wpds-dimension-gap-md, 12px)",
2140 lg: "var(--wpds-dimension-gap-lg, 16px)",
2141 xl: "var(--wpds-dimension-gap-xl, 24px)",
2142 "2xl": "var(--wpds-dimension-gap-2xl, 32px)",
2143 "3xl": "var(--wpds-dimension-gap-3xl, 40px)"
2144 };
2145 var Stack = (0, import_element2.forwardRef)(function Stack2({ direction, gap, align, justify, wrap, render: render4, ...props }, ref) {
2146 const style = {
2147 gap: gap && gapTokens[gap],
2148 alignItems: align,
2149 justifyContent: justify,
2150 flexDirection: direction,
2151 flexWrap: wrap
2152 };
2153 const element = useRender({
2154 render: render4,
2155 ref,
2156 props: mergeProps(props, { style, className: style_default.stack })
2157 });
2158 return element;
2159 });
2160
2161 // packages/dataviews/build-module/components/dataviews-context/index.mjs
2162 var import_element3 = __toESM(require_element(), 1);
2163
2164 // packages/dataviews/build-module/constants.mjs
2165 var import_i18n7 = __toESM(require_i18n(), 1);
2166 var OPERATOR_IS_ANY = "isAny";
2167 var OPERATOR_IS_NONE = "isNone";
2168 var OPERATOR_IS_ALL = "isAll";
2169 var OPERATOR_IS_NOT_ALL = "isNotAll";
2170 var OPERATOR_BETWEEN = "between";
2171 var OPERATOR_IN_THE_PAST = "inThePast";
2172 var OPERATOR_OVER = "over";
2173 var OPERATOR_IS = "is";
2174 var OPERATOR_IS_NOT = "isNot";
2175 var OPERATOR_LESS_THAN = "lessThan";
2176 var OPERATOR_GREATER_THAN = "greaterThan";
2177 var OPERATOR_LESS_THAN_OR_EQUAL = "lessThanOrEqual";
2178 var OPERATOR_GREATER_THAN_OR_EQUAL = "greaterThanOrEqual";
2179 var OPERATOR_BEFORE = "before";
2180 var OPERATOR_AFTER = "after";
2181 var OPERATOR_BEFORE_INC = "beforeInc";
2182 var OPERATOR_AFTER_INC = "afterInc";
2183 var OPERATOR_CONTAINS = "contains";
2184 var OPERATOR_NOT_CONTAINS = "notContains";
2185 var OPERATOR_STARTS_WITH = "startsWith";
2186 var OPERATOR_ON = "on";
2187 var OPERATOR_NOT_ON = "notOn";
2188 var SORTING_DIRECTIONS = ["asc", "desc"];
2189 var sortArrows = { asc: "\u2191", desc: "\u2193" };
2190 var sortValues = { asc: "ascending", desc: "descending" };
2191 var sortLabels = {
2192 asc: (0, import_i18n7.__)("Sort ascending"),
2193 desc: (0, import_i18n7.__)("Sort descending")
2194 };
2195 var sortIcons = {
2196 asc: arrow_up_default,
2197 desc: arrow_down_default
2198 };
2199 var LAYOUT_TABLE = "table";
2200 var LAYOUT_GRID = "grid";
2201 var LAYOUT_LIST = "list";
2202 var LAYOUT_ACTIVITY = "activity";
2203 var LAYOUT_PICKER_GRID = "pickerGrid";
2204 var LAYOUT_PICKER_TABLE = "pickerTable";
2205
2206 // packages/dataviews/build-module/components/dataviews-context/index.mjs
2207 var DataViewsContext = (0, import_element3.createContext)({
2208 view: { type: LAYOUT_TABLE },
2209 onChangeView: () => {
2210 },
2211 fields: [],
2212 data: [],
2213 paginationInfo: {
2214 totalItems: 0,
2215 totalPages: 0
2216 },
2217 selection: [],
2218 onChangeSelection: () => {
2219 },
2220 setOpenedFilter: () => {
2221 },
2222 openedFilter: null,
2223 getItemId: (item) => item.id,
2224 isItemClickable: () => true,
2225 renderItemLink: void 0,
2226 containerWidth: 0,
2227 containerRef: (0, import_element3.createRef)(),
2228 resizeObserverRef: () => {
2229 },
2230 defaultLayouts: { list: {}, grid: {}, table: {} },
2231 filters: [],
2232 isShowingFilter: false,
2233 setIsShowingFilter: () => {
2234 },
2235 hasInitiallyLoaded: false,
2236 config: {
2237 perPageSizes: []
2238 },
2239 intersectionObserver: null
2240 });
2241 DataViewsContext.displayName = "DataViewsContext";
2242 var dataviews_context_default = DataViewsContext;
2243
2244 // packages/dataviews/build-module/components/dataviews-layouts/index.mjs
2245 var import_i18n27 = __toESM(require_i18n(), 1);
2246
2247 // packages/dataviews/build-module/components/dataviews-layouts/table/index.mjs
2248 var import_i18n15 = __toESM(require_i18n(), 1);
2249 var import_components6 = __toESM(require_components(), 1);
2250 var import_element11 = __toESM(require_element(), 1);
2251 var import_keycodes = __toESM(require_keycodes(), 1);
2252
2253 // packages/dataviews/build-module/components/dataviews-selection-checkbox/index.mjs
2254 var import_components = __toESM(require_components(), 1);
2255 var import_i18n8 = __toESM(require_i18n(), 1);
2256 var import_jsx_runtime31 = __toESM(require_jsx_runtime(), 1);
2257 function DataViewsSelectionCheckbox({
2258 selection,
2259 onChangeSelection,
2260 item,
2261 getItemId,
2262 titleField,
2263 disabled,
2264 ...extraProps
2265 }) {
2266 const id = getItemId(item);
2267 const isInSelectionArray = selection.includes(id);
2268 const checked = !disabled && isInSelectionArray;
2269 const selectionLabel = titleField?.getValue?.({ item }) || (0, import_i18n8.__)("(no title)");
2270 return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2271 import_components.CheckboxControl,
2272 {
2273 className: "dataviews-selection-checkbox",
2274 "aria-label": selectionLabel,
2275 "aria-disabled": disabled,
2276 checked,
2277 onChange: () => {
2278 if (disabled) {
2279 return;
2280 }
2281 onChangeSelection(
2282 isInSelectionArray ? selection.filter((itemId) => id !== itemId) : [...selection, id]
2283 );
2284 },
2285 ...extraProps
2286 }
2287 );
2288 }
2289
2290 // packages/dataviews/build-module/components/dataviews-item-actions/index.mjs
2291 var import_components2 = __toESM(require_components(), 1);
2292 var import_i18n9 = __toESM(require_i18n(), 1);
2293 var import_element4 = __toESM(require_element(), 1);
2294 var import_data = __toESM(require_data(), 1);
2295 var import_compose = __toESM(require_compose(), 1);
2296
2297 // packages/dataviews/build-module/lock-unlock.mjs
2298 var import_private_apis = __toESM(require_private_apis(), 1);
2299 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
2300 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
2301 "@wordpress/dataviews"
2302 );
2303
2304 // packages/dataviews/build-module/components/dataviews-item-actions/index.mjs
2305 var import_jsx_runtime32 = __toESM(require_jsx_runtime(), 1);
2306 var { Menu, kebabCase } = unlock(import_components2.privateApis);
2307 function ButtonTrigger({
2308 action,
2309 onClick,
2310 items,
2311 variant
2312 }) {
2313 const label = typeof action.label === "string" ? action.label : action.label(items);
2314 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2315 import_components2.Button,
2316 {
2317 disabled: !!action.disabled,
2318 accessibleWhenDisabled: true,
2319 size: "compact",
2320 variant,
2321 onClick,
2322 children: label
2323 }
2324 );
2325 }
2326 function MenuItemTrigger({
2327 action,
2328 onClick,
2329 items
2330 }) {
2331 const label = typeof action.label === "string" ? action.label : action.label(items);
2332 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Menu.Item, { disabled: action.disabled, onClick, children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Menu.ItemLabel, { children: label }) });
2333 }
2334 function ActionModal({
2335 action,
2336 items,
2337 closeModal
2338 }) {
2339 const label = typeof action.label === "string" ? action.label : action.label(items);
2340 const modalHeader = typeof action.modalHeader === "function" ? action.modalHeader(items) : action.modalHeader;
2341 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2342 import_components2.Modal,
2343 {
2344 title: modalHeader || label,
2345 __experimentalHideHeader: !!action.hideModalHeader,
2346 onRequestClose: closeModal,
2347 focusOnMount: action.modalFocusOnMount ?? true,
2348 size: action.modalSize || "medium",
2349 overlayClassName: `dataviews-action-modal dataviews-action-modal__${kebabCase(
2350 action.id
2351 )}`,
2352 children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(action.RenderModal, { items, closeModal })
2353 }
2354 );
2355 }
2356 function ActionsMenuGroup({
2357 actions,
2358 item,
2359 registry,
2360 setActiveModalAction
2361 }) {
2362 const { primaryActions, regularActions } = (0, import_element4.useMemo)(() => {
2363 return actions.reduce(
2364 (acc, action) => {
2365 (action.isPrimary ? acc.primaryActions : acc.regularActions).push(action);
2366 return acc;
2367 },
2368 {
2369 primaryActions: [],
2370 regularActions: []
2371 }
2372 );
2373 }, [actions]);
2374 const renderActionGroup = (actionList) => actionList.map((action) => /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2375 MenuItemTrigger,
2376 {
2377 action,
2378 onClick: () => {
2379 if ("RenderModal" in action) {
2380 setActiveModalAction(action);
2381 return;
2382 }
2383 action.callback([item], { registry });
2384 },
2385 items: [item]
2386 },
2387 action.id
2388 ));
2389 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(Menu.Group, { children: [
2390 renderActionGroup(primaryActions),
2391 renderActionGroup(regularActions)
2392 ] });
2393 }
2394 function ItemActions({
2395 item,
2396 actions,
2397 isCompact
2398 }) {
2399 const registry = (0, import_data.useRegistry)();
2400 const { primaryActions, eligibleActions } = (0, import_element4.useMemo)(() => {
2401 const _eligibleActions = actions.filter(
2402 (action) => !action.isEligible || action.isEligible(item)
2403 );
2404 const _primaryActions = _eligibleActions.filter(
2405 (action) => action.isPrimary
2406 );
2407 return {
2408 primaryActions: _primaryActions,
2409 eligibleActions: _eligibleActions
2410 };
2411 }, [actions, item]);
2412 const isMobileViewport = (0, import_compose.useViewportMatch)("medium", "<");
2413 if (isCompact) {
2414 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2415 CompactItemActions,
2416 {
2417 item,
2418 actions: eligibleActions,
2419 isSmall: true,
2420 registry
2421 }
2422 );
2423 }
2424 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(
2425 Stack,
2426 {
2427 direction: "row",
2428 justify: "flex-end",
2429 className: "dataviews-item-actions",
2430 style: {
2431 flexShrink: 0,
2432 width: "auto"
2433 },
2434 children: [
2435 /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2436 PrimaryActions,
2437 {
2438 item,
2439 actions: primaryActions,
2440 registry
2441 }
2442 ),
2443 (primaryActions.length < eligibleActions.length || // Since we hide primary actions on mobile, we need to show the menu
2444 // there if there are any actions at all.
2445 isMobileViewport) && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2446 CompactItemActions,
2447 {
2448 item,
2449 actions: eligibleActions,
2450 registry
2451 }
2452 )
2453 ]
2454 }
2455 );
2456 }
2457 function CompactItemActions({
2458 item,
2459 actions,
2460 isSmall,
2461 registry
2462 }) {
2463 const [activeModalAction, setActiveModalAction] = (0, import_element4.useState)(
2464 null
2465 );
2466 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(import_jsx_runtime32.Fragment, { children: [
2467 /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(Menu, { placement: "bottom-end", children: [
2468 /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2469 Menu.TriggerButton,
2470 {
2471 render: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2472 import_components2.Button,
2473 {
2474 size: isSmall ? "small" : "compact",
2475 icon: more_vertical_default,
2476 label: (0, import_i18n9.__)("Actions"),
2477 accessibleWhenDisabled: true,
2478 disabled: !actions.length,
2479 className: "dataviews-all-actions-button"
2480 }
2481 )
2482 }
2483 ),
2484 /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Menu.Popover, { children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2485 ActionsMenuGroup,
2486 {
2487 actions,
2488 item,
2489 registry,
2490 setActiveModalAction
2491 }
2492 ) })
2493 ] }),
2494 !!activeModalAction && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2495 ActionModal,
2496 {
2497 action: activeModalAction,
2498 items: [item],
2499 closeModal: () => setActiveModalAction(null)
2500 }
2501 )
2502 ] });
2503 }
2504 function PrimaryActions({
2505 item,
2506 actions,
2507 registry,
2508 buttonVariant
2509 }) {
2510 const [activeModalAction, setActiveModalAction] = (0, import_element4.useState)(null);
2511 const isMobileViewport = (0, import_compose.useViewportMatch)("medium", "<");
2512 if (isMobileViewport) {
2513 return null;
2514 }
2515 if (!Array.isArray(actions) || actions.length === 0) {
2516 return null;
2517 }
2518 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(import_jsx_runtime32.Fragment, { children: [
2519 actions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2520 ButtonTrigger,
2521 {
2522 action,
2523 onClick: () => {
2524 if ("RenderModal" in action) {
2525 setActiveModalAction(action);
2526 return;
2527 }
2528 action.callback([item], { registry });
2529 },
2530 items: [item],
2531 variant: buttonVariant
2532 },
2533 action.id
2534 )),
2535 !!activeModalAction && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2536 ActionModal,
2537 {
2538 action: activeModalAction,
2539 items: [item],
2540 closeModal: () => setActiveModalAction(null)
2541 }
2542 )
2543 ] });
2544 }
2545
2546 // packages/dataviews/build-module/components/dataviews-bulk-actions/index.mjs
2547 var import_components3 = __toESM(require_components(), 1);
2548 var import_i18n11 = __toESM(require_i18n(), 1);
2549 var import_element5 = __toESM(require_element(), 1);
2550 var import_data2 = __toESM(require_data(), 1);
2551 var import_compose2 = __toESM(require_compose(), 1);
2552
2553 // packages/dataviews/build-module/utils/get-footer-message.mjs
2554 var import_i18n10 = __toESM(require_i18n(), 1);
2555 function getFooterMessage(selectionCount, itemsCount, totalItems, onlyTotalCount = false) {
2556 if (selectionCount > 0) {
2557 return (0, import_i18n10.sprintf)(
2558 /* translators: %d: number of items. */
2559 (0, import_i18n10._n)("%d Item selected", "%d Items selected", selectionCount),
2560 selectionCount
2561 );
2562 }
2563 if (onlyTotalCount || totalItems <= itemsCount) {
2564 return (0, import_i18n10.sprintf)(
2565 /* translators: %d: number of items. */
2566 (0, import_i18n10._n)("%d Item", "%d Items", totalItems),
2567 totalItems
2568 );
2569 }
2570 return (0, import_i18n10.sprintf)(
2571 /* translators: %1$d: number of items. %2$d: total number of items. */
2572 (0, import_i18n10._n)("%1$d of %2$d Item", "%1$d of %2$d Items", totalItems),
2573 itemsCount,
2574 totalItems
2575 );
2576 }
2577
2578 // packages/dataviews/build-module/components/dataviews-bulk-actions/index.mjs
2579 var import_jsx_runtime33 = __toESM(require_jsx_runtime(), 1);
2580 function useHasAPossibleBulkAction(actions, item) {
2581 return (0, import_element5.useMemo)(() => {
2582 return actions.some((action) => {
2583 return action.supportsBulk && (!action.isEligible || action.isEligible(item));
2584 });
2585 }, [actions, item]);
2586 }
2587 function useSomeItemHasAPossibleBulkAction(actions, data) {
2588 return (0, import_element5.useMemo)(() => {
2589 return data.some((item) => {
2590 return actions.some((action) => {
2591 return action.supportsBulk && (!action.isEligible || action.isEligible(item));
2592 });
2593 });
2594 }, [actions, data]);
2595 }
2596 function BulkSelectionCheckbox({
2597 selection,
2598 onChangeSelection,
2599 data,
2600 actions,
2601 getItemId,
2602 disableSelectAll = false
2603 }) {
2604 const selectableItems = (0, import_element5.useMemo)(() => {
2605 return data.filter((item) => {
2606 return actions.some(
2607 (action) => action.supportsBulk && (!action.isEligible || action.isEligible(item))
2608 );
2609 });
2610 }, [data, actions]);
2611 const selectedItems = data.filter(
2612 (item) => selection.includes(getItemId(item)) && selectableItems.includes(item)
2613 );
2614 const hasSelection = selection.length > 0;
2615 const areAllSelected = selectedItems.length === selectableItems.length;
2616 if (disableSelectAll) {
2617 return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2618 import_components3.CheckboxControl,
2619 {
2620 className: "dataviews-view-table-selection-checkbox",
2621 checked: hasSelection,
2622 disabled: !hasSelection,
2623 onChange: () => {
2624 onChangeSelection([]);
2625 },
2626 "aria-label": (0, import_i18n11.__)("Deselect all")
2627 }
2628 );
2629 }
2630 return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2631 import_components3.CheckboxControl,
2632 {
2633 className: "dataviews-view-table-selection-checkbox",
2634 checked: areAllSelected,
2635 indeterminate: !areAllSelected && !!selectedItems.length,
2636 onChange: () => {
2637 if (areAllSelected) {
2638 onChangeSelection([]);
2639 } else {
2640 onChangeSelection(
2641 selectableItems.map((item) => getItemId(item))
2642 );
2643 }
2644 },
2645 "aria-label": areAllSelected ? (0, import_i18n11.__)("Deselect all") : (0, import_i18n11.__)("Select all")
2646 }
2647 );
2648 }
2649
2650 // packages/dataviews/build-module/components/dataviews-layouts/table/column-header-menu.mjs
2651 var import_i18n12 = __toESM(require_i18n(), 1);
2652 var import_components4 = __toESM(require_components(), 1);
2653 var import_element6 = __toESM(require_element(), 1);
2654
2655 // packages/dataviews/build-module/utils/get-hideable-fields.mjs
2656 function getHideableFields(view, fields) {
2657 const togglableFields = [
2658 view?.titleField,
2659 view?.mediaField,
2660 view?.descriptionField
2661 ].filter(Boolean);
2662 return fields.filter(
2663 (f2) => !togglableFields.includes(f2.id) && f2.type !== "media" && f2.enableHiding !== false
2664 );
2665 }
2666
2667 // packages/dataviews/build-module/components/dataviews-layouts/table/column-header-menu.mjs
2668 var import_jsx_runtime34 = __toESM(require_jsx_runtime(), 1);
2669 var { Menu: Menu2 } = unlock(import_components4.privateApis);
2670 function WithMenuSeparators({ children }) {
2671 return import_element6.Children.toArray(children).filter(Boolean).map((child, i2) => /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_element6.Fragment, { children: [
2672 i2 > 0 && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Separator, {}),
2673 child
2674 ] }, i2));
2675 }
2676 var _HeaderMenu = (0, import_element6.forwardRef)(function HeaderMenu({
2677 fieldId,
2678 view,
2679 fields,
2680 onChangeView,
2681 onHide,
2682 setOpenedFilter,
2683 canMove = true,
2684 canInsertLeft = true,
2685 canInsertRight = true
2686 }, ref) {
2687 const visibleFieldIds = view.fields ?? [];
2688 const index = visibleFieldIds?.indexOf(fieldId);
2689 const isSorted = view.sort?.field === fieldId;
2690 let isHidable = false;
2691 let isSortable = false;
2692 let canAddFilter = false;
2693 let operators = [];
2694 const field = fields.find((f2) => f2.id === fieldId);
2695 const { setIsShowingFilter } = (0, import_element6.useContext)(dataviews_context_default);
2696 if (!field) {
2697 return null;
2698 }
2699 isHidable = field.enableHiding !== false;
2700 isSortable = field.enableSorting !== false;
2701 const header = field.header;
2702 operators = !!field.filterBy && field.filterBy?.operators || [];
2703 canAddFilter = !view.filters?.some((_filter) => fieldId === _filter.field) && !!(field.hasElements || field.Edit) && field.filterBy !== false && !field.filterBy?.isPrimary;
2704 if (!isSortable && !canMove && !isHidable && !canAddFilter) {
2705 return header;
2706 }
2707 const hiddenFields = getHideableFields(view, fields).filter(
2708 (f2) => !visibleFieldIds.includes(f2.id)
2709 );
2710 const canInsert = (canInsertLeft || canInsertRight) && !!hiddenFields.length;
2711 const isRtl = (0, import_i18n12.isRTL)();
2712 return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2, { children: [
2713 /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
2714 Menu2.TriggerButton,
2715 {
2716 render: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2717 import_components4.Button,
2718 {
2719 size: "compact",
2720 className: "dataviews-view-table-header-button",
2721 ref,
2722 variant: "tertiary"
2723 }
2724 ),
2725 children: [
2726 header,
2727 view.sort && isSorted && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("span", { "aria-hidden": "true", children: sortArrows[view.sort.direction] })
2728 ]
2729 }
2730 ),
2731 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Popover, { style: { minWidth: "240px" }, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(WithMenuSeparators, { children: [
2732 isSortable && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Group, { children: SORTING_DIRECTIONS.map(
2733 (direction) => {
2734 const isChecked = view.sort && isSorted && view.sort.direction === direction;
2735 const value = `${fieldId}-${direction}`;
2736 return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2737 Menu2.RadioItem,
2738 {
2739 name: "view-table-sorting",
2740 value,
2741 checked: isChecked,
2742 onChange: () => {
2743 onChangeView({
2744 ...view,
2745 sort: {
2746 field: fieldId,
2747 direction
2748 },
2749 showLevels: false
2750 });
2751 },
2752 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: sortLabels[direction] })
2753 },
2754 value
2755 );
2756 }
2757 ) }),
2758 canAddFilter && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Group, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2759 Menu2.Item,
2760 {
2761 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: funnel_default }),
2762 onClick: () => {
2763 setOpenedFilter(fieldId);
2764 setIsShowingFilter(true);
2765 onChangeView({
2766 ...view,
2767 page: 1,
2768 filters: [
2769 ...view.filters || [],
2770 {
2771 field: fieldId,
2772 value: void 0,
2773 operator: operators[0]
2774 }
2775 ]
2776 });
2777 },
2778 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Add filter") })
2779 }
2780 ) }),
2781 (canMove || isHidable || canInsert) && field && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2.Group, { children: [
2782 canMove && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2783 Menu2.Item,
2784 {
2785 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: arrow_left_default }),
2786 disabled: isRtl ? index >= visibleFieldIds.length - 1 : index < 1,
2787 onClick: () => {
2788 const targetIndex = isRtl ? index + 1 : index - 1;
2789 const newFields = [
2790 ...visibleFieldIds
2791 ];
2792 newFields.splice(index, 1);
2793 newFields.splice(
2794 targetIndex,
2795 0,
2796 fieldId
2797 );
2798 onChangeView({
2799 ...view,
2800 fields: newFields
2801 });
2802 },
2803 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Move left") })
2804 }
2805 ),
2806 canMove && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2807 Menu2.Item,
2808 {
2809 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: arrow_right_default }),
2810 disabled: isRtl ? index < 1 : index >= visibleFieldIds.length - 1,
2811 onClick: () => {
2812 const targetIndex = isRtl ? index - 1 : index + 1;
2813 const newFields = [
2814 ...visibleFieldIds
2815 ];
2816 newFields.splice(index, 1);
2817 newFields.splice(
2818 targetIndex,
2819 0,
2820 fieldId
2821 );
2822 onChangeView({
2823 ...view,
2824 fields: newFields
2825 });
2826 },
2827 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Move right") })
2828 }
2829 ),
2830 canInsertLeft && !!hiddenFields.length && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2, { children: [
2831 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.SubmenuTriggerItem, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Insert left") }) }),
2832 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Popover, { children: hiddenFields.map((hiddenField) => {
2833 const insertIndex = isRtl ? index + 1 : index;
2834 return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2835 Menu2.Item,
2836 {
2837 onClick: () => {
2838 onChangeView({
2839 ...view,
2840 fields: [
2841 ...visibleFieldIds.slice(
2842 0,
2843 insertIndex
2844 ),
2845 hiddenField.id,
2846 ...visibleFieldIds.slice(
2847 insertIndex
2848 )
2849 ]
2850 });
2851 },
2852 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: hiddenField.label })
2853 },
2854 hiddenField.id
2855 );
2856 }) })
2857 ] }),
2858 canInsertRight && !!hiddenFields.length && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2, { children: [
2859 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.SubmenuTriggerItem, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Insert right") }) }),
2860 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Popover, { children: hiddenFields.map((hiddenField) => {
2861 const insertIndex = isRtl ? index : index + 1;
2862 return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2863 Menu2.Item,
2864 {
2865 onClick: () => {
2866 onChangeView({
2867 ...view,
2868 fields: [
2869 ...visibleFieldIds.slice(
2870 0,
2871 insertIndex
2872 ),
2873 hiddenField.id,
2874 ...visibleFieldIds.slice(
2875 insertIndex
2876 )
2877 ]
2878 });
2879 },
2880 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: hiddenField.label })
2881 },
2882 hiddenField.id
2883 );
2884 }) })
2885 ] }),
2886 isHidable && field && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2887 Menu2.Item,
2888 {
2889 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: unseen_default }),
2890 onClick: () => {
2891 onHide(field);
2892 onChangeView({
2893 ...view,
2894 fields: visibleFieldIds.filter(
2895 (id) => id !== fieldId
2896 )
2897 });
2898 },
2899 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Hide column") })
2900 }
2901 )
2902 ] })
2903 ] }) })
2904 ] });
2905 });
2906 var ColumnHeaderMenu = _HeaderMenu;
2907 var column_header_menu_default = ColumnHeaderMenu;
2908
2909 // packages/dataviews/build-module/components/dataviews-layouts/utils/item-click-wrapper.mjs
2910 var import_element7 = __toESM(require_element(), 1);
2911 var import_jsx_runtime35 = __toESM(require_jsx_runtime(), 1);
2912 function getClickableItemProps({
2913 item,
2914 isItemClickable: isItemClickable2,
2915 onClickItem,
2916 className
2917 }) {
2918 if (!isItemClickable2(item) || !onClickItem) {
2919 return { className };
2920 }
2921 return {
2922 className: className ? `${className} ${className}--clickable` : void 0,
2923 role: "button",
2924 tabIndex: 0,
2925 onClick: (event) => {
2926 event.stopPropagation();
2927 onClickItem(item);
2928 },
2929 onKeyDown: (event) => {
2930 if (event.key === "Enter" || event.key === "" || event.key === " ") {
2931 event.stopPropagation();
2932 onClickItem(item);
2933 }
2934 }
2935 };
2936 }
2937 function ItemClickWrapper({
2938 item,
2939 isItemClickable: isItemClickable2,
2940 onClickItem,
2941 renderItemLink,
2942 className,
2943 children,
2944 ...extraProps
2945 }) {
2946 if (!isItemClickable2(item)) {
2947 return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className, ...extraProps, children });
2948 }
2949 if (renderItemLink) {
2950 const renderedElement = renderItemLink({
2951 item,
2952 className: `${className} ${className}--clickable`,
2953 ...extraProps,
2954 children
2955 });
2956 return (0, import_element7.cloneElement)(renderedElement, {
2957 onClick: (event) => {
2958 event.stopPropagation();
2959 if (renderedElement.props.onClick) {
2960 renderedElement.props.onClick(event);
2961 }
2962 },
2963 onKeyDown: (event) => {
2964 if (event.key === "Enter" || event.key === "" || event.key === " ") {
2965 event.stopPropagation();
2966 if (renderedElement.props.onKeyDown) {
2967 renderedElement.props.onKeyDown(event);
2968 }
2969 }
2970 }
2971 });
2972 }
2973 const clickProps = getClickableItemProps({
2974 item,
2975 isItemClickable: isItemClickable2,
2976 onClickItem,
2977 className
2978 });
2979 return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { ...clickProps, ...extraProps, children });
2980 }
2981
2982 // packages/dataviews/build-module/components/dataviews-layouts/table/column-primary.mjs
2983 var import_jsx_runtime36 = __toESM(require_jsx_runtime(), 1);
2984 function ColumnPrimary({
2985 item,
2986 level,
2987 titleField,
2988 mediaField,
2989 descriptionField: descriptionField2,
2990 onClickItem,
2991 renderItemLink,
2992 isItemClickable: isItemClickable2
2993 }) {
2994 return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(Stack, { direction: "row", gap: "md", align: "flex-start", justify: "flex-start", children: [
2995 mediaField && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
2996 ItemClickWrapper,
2997 {
2998 item,
2999 isItemClickable: isItemClickable2,
3000 onClickItem,
3001 renderItemLink,
3002 className: "dataviews-view-table__cell-content-wrapper dataviews-column-primary__media",
3003 "aria-label": isItemClickable2(item) && (!!onClickItem || !!renderItemLink) && !!titleField ? titleField.getValue?.({ item }) : void 0,
3004 children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3005 mediaField.render,
3006 {
3007 item,
3008 field: mediaField,
3009 config: { sizes: "32px" }
3010 }
3011 )
3012 }
3013 ),
3014 /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
3015 Stack,
3016 {
3017 direction: "column",
3018 align: "flex-start",
3019 className: "dataviews-view-table__primary-column-content",
3020 children: [
3021 titleField && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
3022 ItemClickWrapper,
3023 {
3024 item,
3025 isItemClickable: isItemClickable2,
3026 onClickItem,
3027 renderItemLink,
3028 className: "dataviews-view-table__cell-content-wrapper dataviews-title-field",
3029 children: [
3030 level !== void 0 && level > 0 && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("span", { className: "dataviews-view-table__level", children: [
3031 Array(level).fill("\u2014").join(" "),
3032 "\xA0"
3033 ] }),
3034 /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(titleField.render, { item, field: titleField })
3035 ]
3036 }
3037 ),
3038 descriptionField2 && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3039 descriptionField2.render,
3040 {
3041 item,
3042 field: descriptionField2
3043 }
3044 )
3045 ]
3046 }
3047 )
3048 ] });
3049 }
3050 var column_primary_default = ColumnPrimary;
3051
3052 // packages/dataviews/build-module/components/dataviews-layouts/table/use-scroll-state.mjs
3053 var import_element8 = __toESM(require_element(), 1);
3054 var import_i18n13 = __toESM(require_i18n(), 1);
3055 var isScrolledToEnd = (element) => {
3056 if ((0, import_i18n13.isRTL)()) {
3057 const scrollLeft = Math.abs(element.scrollLeft);
3058 return scrollLeft <= 1;
3059 }
3060 return element.scrollLeft + element.clientWidth >= element.scrollWidth - 1;
3061 };
3062 function useScrollState({
3063 scrollContainerRef,
3064 enabledHorizontal = false
3065 }) {
3066 const [isHorizontalScrollEnd, setIsHorizontalScrollEnd] = (0, import_element8.useState)(false);
3067 const [isVerticallyScrolled, setIsVerticallyScrolled] = (0, import_element8.useState)(false);
3068 const handleScroll = (0, import_element8.useCallback)(() => {
3069 const scrollContainer = scrollContainerRef.current;
3070 if (!scrollContainer) {
3071 return;
3072 }
3073 if (enabledHorizontal) {
3074 setIsHorizontalScrollEnd(isScrolledToEnd(scrollContainer));
3075 }
3076 setIsVerticallyScrolled(scrollContainer.scrollTop > 0);
3077 }, [scrollContainerRef, enabledHorizontal]);
3078 (0, import_element8.useEffect)(() => {
3079 if (typeof window === "undefined" || !scrollContainerRef.current) {
3080 return () => {
3081 };
3082 }
3083 const scrollContainer = scrollContainerRef.current;
3084 handleScroll();
3085 scrollContainer.addEventListener("scroll", handleScroll);
3086 window.addEventListener("resize", handleScroll);
3087 return () => {
3088 scrollContainer.removeEventListener("scroll", handleScroll);
3089 window.removeEventListener("resize", handleScroll);
3090 };
3091 }, [scrollContainerRef, enabledHorizontal, handleScroll]);
3092 return { isHorizontalScrollEnd, isVerticallyScrolled };
3093 }
3094
3095 // packages/dataviews/build-module/components/dataviews-layouts/utils/get-data-by-group.mjs
3096 function getDataByGroup(data, groupByField) {
3097 return data.reduce((groups, item) => {
3098 const groupName = groupByField.getValue({ item });
3099 if (!groups.has(groupName)) {
3100 groups.set(groupName, []);
3101 }
3102 groups.get(groupName)?.push(item);
3103 return groups;
3104 }, /* @__PURE__ */ new Map());
3105 }
3106
3107 // packages/dataviews/build-module/components/dataviews-view-config/properties-section.mjs
3108 var import_components5 = __toESM(require_components(), 1);
3109 var import_i18n14 = __toESM(require_i18n(), 1);
3110 var import_element9 = __toESM(require_element(), 1);
3111 var import_jsx_runtime37 = __toESM(require_jsx_runtime(), 1);
3112 function FieldItem({
3113 field,
3114 isVisible: isVisible2,
3115 onToggleVisibility
3116 }) {
3117 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: [
3118 /* @__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 }) }),
3119 /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("span", { className: "dataviews-view-config__label", children: field.label })
3120 ] }) });
3121 }
3122 function isDefined(item) {
3123 return !!item;
3124 }
3125 function PropertiesSection({
3126 showLabel = true
3127 }) {
3128 const { view, fields, onChangeView } = (0, import_element9.useContext)(dataviews_context_default);
3129 const regularFields = getHideableFields(view, fields);
3130 if (!regularFields?.length) {
3131 return null;
3132 }
3133 const titleField = fields.find((f2) => f2.id === view.titleField);
3134 const previewField = fields.find((f2) => f2.id === view.mediaField);
3135 const descriptionField2 = fields.find(
3136 (f2) => f2.id === view.descriptionField
3137 );
3138 const lockedFields = [
3139 {
3140 field: titleField,
3141 isVisibleFlag: "showTitle"
3142 },
3143 {
3144 field: previewField,
3145 isVisibleFlag: "showMedia"
3146 },
3147 {
3148 field: descriptionField2,
3149 isVisibleFlag: "showDescription"
3150 }
3151 ].filter(({ field }) => isDefined(field));
3152 const visibleFieldIds = view.fields ?? [];
3153 const visibleRegularFieldsCount = regularFields.filter(
3154 (f2) => visibleFieldIds.includes(f2.id)
3155 ).length;
3156 const visibleLockedFields = lockedFields.filter(
3157 ({ isVisibleFlag }) => (
3158 // @ts-expect-error
3159 view[isVisibleFlag] ?? true
3160 )
3161 );
3162 const totalVisibleFields = visibleLockedFields.length + visibleRegularFieldsCount;
3163 const isSingleVisibleLockedField = totalVisibleFields === 1 && visibleLockedFields.length === 1;
3164 return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(Stack, { direction: "column", className: "dataviews-field-control", children: [
3165 showLabel && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_components5.BaseControl.VisualLabel, { children: (0, import_i18n14.__)("Properties") }),
3166 /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3167 Stack,
3168 {
3169 direction: "column",
3170 className: "dataviews-view-config__properties",
3171 children: /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(import_components5.__experimentalItemGroup, { isBordered: true, isSeparated: true, size: "medium", children: [
3172 lockedFields.map(({ field, isVisibleFlag }) => {
3173 const isVisible2 = view[isVisibleFlag] ?? true;
3174 const fieldToRender = isSingleVisibleLockedField && isVisible2 ? { ...field, enableHiding: false } : field;
3175 return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3176 FieldItem,
3177 {
3178 field: fieldToRender,
3179 isVisible: isVisible2,
3180 onToggleVisibility: () => {
3181 onChangeView({
3182 ...view,
3183 [isVisibleFlag]: !isVisible2
3184 });
3185 }
3186 },
3187 field.id
3188 );
3189 }),
3190 regularFields.map((field) => {
3191 const isVisible2 = visibleFieldIds.includes(field.id);
3192 const fieldToRender = totalVisibleFields === 1 && isVisible2 ? { ...field, enableHiding: false } : field;
3193 return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3194 FieldItem,
3195 {
3196 field: fieldToRender,
3197 isVisible: isVisible2,
3198 onToggleVisibility: () => {
3199 onChangeView({
3200 ...view,
3201 fields: isVisible2 ? visibleFieldIds.filter(
3202 (fieldId) => fieldId !== field.id
3203 ) : [...visibleFieldIds, field.id]
3204 });
3205 }
3206 },
3207 field.id
3208 );
3209 })
3210 ] })
3211 }
3212 )
3213 ] });
3214 }
3215
3216 // packages/dataviews/build-module/hooks/use-delayed-loading.mjs
3217 var import_element10 = __toESM(require_element(), 1);
3218 function useDelayedLoading(isLoading, options = { delay: 400 }) {
3219 const [showLoader, setShowLoader] = (0, import_element10.useState)(false);
3220 (0, import_element10.useEffect)(() => {
3221 if (!isLoading) {
3222 return;
3223 }
3224 const timeout = setTimeout(() => {
3225 setShowLoader(true);
3226 }, options.delay);
3227 return () => {
3228 clearTimeout(timeout);
3229 setShowLoader(false);
3230 };
3231 }, [isLoading, options.delay]);
3232 return showLoader;
3233 }
3234
3235 // packages/dataviews/build-module/components/dataviews-layouts/table/index.mjs
3236 var import_jsx_runtime38 = __toESM(require_jsx_runtime(), 1);
3237 function getEffectiveAlign(explicitAlign, fieldType) {
3238 if (explicitAlign) {
3239 return explicitAlign;
3240 }
3241 if (fieldType === "integer" || fieldType === "number") {
3242 return "end";
3243 }
3244 return void 0;
3245 }
3246 function TableColumnField({
3247 item,
3248 fields,
3249 column,
3250 align
3251 }) {
3252 const field = fields.find((f2) => f2.id === column);
3253 if (!field) {
3254 return null;
3255 }
3256 const className = clsx_default("dataviews-view-table__cell-content-wrapper", {
3257 "dataviews-view-table__cell-align-end": align === "end",
3258 "dataviews-view-table__cell-align-center": align === "center"
3259 });
3260 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(field.render, { item, field }) });
3261 }
3262 function TableRow({
3263 hasBulkActions,
3264 item,
3265 level,
3266 actions,
3267 fields,
3268 id,
3269 view,
3270 titleField,
3271 mediaField,
3272 descriptionField: descriptionField2,
3273 selection,
3274 getItemId,
3275 isItemClickable: isItemClickable2,
3276 onClickItem,
3277 renderItemLink,
3278 onChangeSelection,
3279 isActionsColumnSticky,
3280 posinset
3281 }) {
3282 const { paginationInfo } = (0, import_element11.useContext)(dataviews_context_default);
3283 const hasPossibleBulkAction = useHasAPossibleBulkAction(actions, item);
3284 const isSelected2 = hasPossibleBulkAction && selection.includes(id);
3285 const {
3286 showTitle = true,
3287 showMedia = true,
3288 showDescription = true,
3289 infiniteScrollEnabled
3290 } = view;
3291 const isTouchDeviceRef = (0, import_element11.useRef)(false);
3292 const columns = view.fields ?? [];
3293 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
3294 return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
3295 "tr",
3296 {
3297 className: clsx_default("dataviews-view-table__row", {
3298 "is-selected": hasPossibleBulkAction && isSelected2,
3299 "has-bulk-actions": hasPossibleBulkAction
3300 }),
3301 onTouchStart: () => {
3302 isTouchDeviceRef.current = true;
3303 },
3304 "aria-setsize": infiniteScrollEnabled ? paginationInfo.totalItems : void 0,
3305 "aria-posinset": posinset,
3306 role: infiniteScrollEnabled ? "article" : void 0,
3307 onMouseDown: (event) => {
3308 const isMetaClick = (0, import_keycodes.isAppleOS)() ? event.metaKey : event.ctrlKey;
3309 if (event.button === 0 && isMetaClick && window.navigator.userAgent.toLowerCase().includes("firefox")) {
3310 event?.preventDefault();
3311 }
3312 },
3313 onClick: (event) => {
3314 if (!hasPossibleBulkAction) {
3315 return;
3316 }
3317 const isModifierKeyPressed = (0, import_keycodes.isAppleOS)() ? event.metaKey : event.ctrlKey;
3318 if (isModifierKeyPressed && !isTouchDeviceRef.current && document.getSelection()?.type !== "Range") {
3319 onChangeSelection(
3320 selection.includes(id) ? selection.filter((itemId) => id !== itemId) : [...selection, id]
3321 );
3322 }
3323 },
3324 children: [
3325 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)(
3326 DataViewsSelectionCheckbox,
3327 {
3328 item,
3329 selection,
3330 onChangeSelection,
3331 getItemId,
3332 titleField,
3333 disabled: !hasPossibleBulkAction
3334 }
3335 ) }) }),
3336 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3337 column_primary_default,
3338 {
3339 item,
3340 level,
3341 titleField: showTitle ? titleField : void 0,
3342 mediaField: showMedia ? mediaField : void 0,
3343 descriptionField: showDescription ? descriptionField2 : void 0,
3344 isItemClickable: isItemClickable2,
3345 onClickItem,
3346 renderItemLink
3347 }
3348 ) }),
3349 columns.map((column) => {
3350 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
3351 const field = fields.find((f2) => f2.id === column);
3352 const effectiveAlign = getEffectiveAlign(align, field?.type);
3353 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3354 "td",
3355 {
3356 style: {
3357 width,
3358 maxWidth,
3359 minWidth
3360 },
3361 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3362 TableColumnField,
3363 {
3364 fields,
3365 item,
3366 column,
3367 align: effectiveAlign
3368 }
3369 )
3370 },
3371 column
3372 );
3373 }),
3374 !!actions?.length && // Disable reason: we are not making the element interactive,
3375 // but preventing any click events from bubbling up to the
3376 // table row. This allows us to add a click handler to the row
3377 // itself (to toggle row selection) without erroneously
3378 // intercepting click events from ItemActions.
3379 /* eslint-disable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */
3380 /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3381 "td",
3382 {
3383 className: clsx_default("dataviews-view-table__actions-column", {
3384 "dataviews-view-table__actions-column--sticky": true,
3385 "dataviews-view-table__actions-column--stuck": isActionsColumnSticky
3386 }),
3387 onClick: (e2) => e2.stopPropagation(),
3388 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(ItemActions, { item, actions })
3389 }
3390 )
3391 ]
3392 }
3393 );
3394 }
3395 function ViewTable({
3396 actions,
3397 data,
3398 fields,
3399 getItemId,
3400 getItemLevel,
3401 isLoading = false,
3402 onChangeView,
3403 onChangeSelection,
3404 selection,
3405 setOpenedFilter,
3406 onClickItem,
3407 isItemClickable: isItemClickable2,
3408 renderItemLink,
3409 view,
3410 className,
3411 empty
3412 }) {
3413 const { containerRef } = (0, import_element11.useContext)(dataviews_context_default);
3414 const isDelayedLoading = useDelayedLoading(isLoading);
3415 const headerMenuRefs = (0, import_element11.useRef)(/* @__PURE__ */ new Map());
3416 const headerMenuToFocusRef = (0, import_element11.useRef)(void 0);
3417 const [nextHeaderMenuToFocus, setNextHeaderMenuToFocus] = (0, import_element11.useState)();
3418 const [contextMenuAnchor, setContextMenuAnchor] = (0, import_element11.useState)(null);
3419 (0, import_element11.useEffect)(() => {
3420 if (headerMenuToFocusRef.current) {
3421 headerMenuToFocusRef.current.focus();
3422 headerMenuToFocusRef.current = void 0;
3423 }
3424 });
3425 const tableNoticeId = (0, import_element11.useId)();
3426 const { isHorizontalScrollEnd, isVerticallyScrolled } = useScrollState({
3427 scrollContainerRef: containerRef,
3428 enabledHorizontal: !!actions?.length
3429 });
3430 const hasBulkActions = useSomeItemHasAPossibleBulkAction(actions, data);
3431 if (nextHeaderMenuToFocus) {
3432 headerMenuToFocusRef.current = nextHeaderMenuToFocus;
3433 setNextHeaderMenuToFocus(void 0);
3434 return;
3435 }
3436 const onHide = (field) => {
3437 const hidden = headerMenuRefs.current.get(field.id);
3438 const fallback = hidden ? headerMenuRefs.current.get(hidden.fallback) : void 0;
3439 setNextHeaderMenuToFocus(fallback?.node);
3440 };
3441 const handleHeaderContextMenu = (event) => {
3442 event.preventDefault();
3443 event.stopPropagation();
3444 const virtualAnchor = {
3445 getBoundingClientRect: () => ({
3446 x: event.clientX,
3447 y: event.clientY,
3448 top: event.clientY,
3449 left: event.clientX,
3450 right: event.clientX,
3451 bottom: event.clientY,
3452 width: 0,
3453 height: 0,
3454 toJSON: () => ({})
3455 })
3456 };
3457 window.requestAnimationFrame(() => {
3458 setContextMenuAnchor(virtualAnchor);
3459 });
3460 };
3461 const hasData = !!data?.length;
3462 const titleField = fields.find((field) => field.id === view.titleField);
3463 const mediaField = fields.find((field) => field.id === view.mediaField);
3464 const descriptionField2 = fields.find(
3465 (field) => field.id === view.descriptionField
3466 );
3467 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
3468 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
3469 const { showTitle = true, showMedia = true, showDescription = true } = view;
3470 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
3471 const columns = view.fields ?? [];
3472 const headerMenuRef = (column, index) => (node) => {
3473 if (node) {
3474 headerMenuRefs.current.set(column, {
3475 node,
3476 fallback: columns[index > 0 ? index - 1 : 1]
3477 });
3478 } else {
3479 headerMenuRefs.current.delete(column);
3480 }
3481 };
3482 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
3483 const isRtl = (0, import_i18n15.isRTL)();
3484 if (!hasData) {
3485 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3486 "div",
3487 {
3488 className: clsx_default("dataviews-no-results", {
3489 "is-refreshing": isDelayedLoading
3490 }),
3491 id: tableNoticeId,
3492 children: empty
3493 }
3494 );
3495 }
3496 return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(import_jsx_runtime38.Fragment, { children: [
3497 /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
3498 "table",
3499 {
3500 className: clsx_default("dataviews-view-table", className, {
3501 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
3502 view.layout.density
3503 ),
3504 "has-bulk-actions": hasBulkActions,
3505 "is-refreshing": !isInfiniteScroll && isDelayedLoading
3506 }),
3507 "aria-busy": isLoading,
3508 "aria-describedby": tableNoticeId,
3509 role: isInfiniteScroll ? "feed" : void 0,
3510 inert: !isInfiniteScroll && isLoading ? "true" : void 0,
3511 children: [
3512 /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("colgroup", { children: [
3513 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("col", { className: "dataviews-view-table__col-checkbox" }),
3514 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("col", { className: "dataviews-view-table__col-first-data" }),
3515 columns.map((column, index) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3516 "col",
3517 {
3518 className: clsx_default(
3519 `dataviews-view-table__col-${column}`,
3520 {
3521 "dataviews-view-table__col-expand": !hasPrimaryColumn && index === columns.length - 1
3522 }
3523 )
3524 },
3525 `col-${column}`
3526 )),
3527 !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("col", { className: "dataviews-view-table__col-actions" })
3528 ] }),
3529 contextMenuAnchor && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3530 import_components6.Popover,
3531 {
3532 anchor: contextMenuAnchor,
3533 onClose: () => setContextMenuAnchor(null),
3534 placement: "bottom-start",
3535 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(PropertiesSection, { showLabel: false })
3536 }
3537 ),
3538 /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3539 "thead",
3540 {
3541 className: clsx_default({
3542 "dataviews-view-table__thead--stuck": isVerticallyScrolled
3543 }),
3544 onContextMenu: handleHeaderContextMenu,
3545 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("tr", { className: "dataviews-view-table__row", children: [
3546 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3547 "th",
3548 {
3549 className: "dataviews-view-table__checkbox-column",
3550 scope: "col",
3551 onContextMenu: handleHeaderContextMenu,
3552 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3553 BulkSelectionCheckbox,
3554 {
3555 selection,
3556 onChangeSelection,
3557 data,
3558 actions,
3559 getItemId
3560 }
3561 )
3562 }
3563 ),
3564 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("th", { scope: "col", children: titleField && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3565 column_header_menu_default,
3566 {
3567 ref: headerMenuRef(
3568 titleField.id,
3569 0
3570 ),
3571 fieldId: titleField.id,
3572 view,
3573 fields,
3574 onChangeView,
3575 onHide,
3576 setOpenedFilter,
3577 canMove: false,
3578 canInsertLeft: isRtl ? view.layout?.enableMoving ?? true : false,
3579 canInsertRight: isRtl ? false : view.layout?.enableMoving ?? true
3580 }
3581 ) }),
3582 columns.map((column, index) => {
3583 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
3584 const field = fields.find(
3585 (f2) => f2.id === column
3586 );
3587 const effectiveAlign = getEffectiveAlign(
3588 align,
3589 field?.type
3590 );
3591 const canInsertOrMove = view.layout?.enableMoving ?? true;
3592 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3593 "th",
3594 {
3595 style: {
3596 width,
3597 maxWidth,
3598 minWidth,
3599 textAlign: effectiveAlign
3600 },
3601 "aria-sort": view.sort?.direction && view.sort?.field === column ? sortValues[view.sort.direction] : void 0,
3602 scope: "col",
3603 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3604 column_header_menu_default,
3605 {
3606 ref: headerMenuRef(column, index),
3607 fieldId: column,
3608 view,
3609 fields,
3610 onChangeView,
3611 onHide,
3612 setOpenedFilter,
3613 canMove: canInsertOrMove,
3614 canInsertLeft: canInsertOrMove,
3615 canInsertRight: canInsertOrMove
3616 }
3617 )
3618 },
3619 column
3620 );
3621 }),
3622 !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3623 "th",
3624 {
3625 className: clsx_default(
3626 "dataviews-view-table__actions-column",
3627 {
3628 "dataviews-view-table__actions-column--sticky": true,
3629 "dataviews-view-table__actions-column--stuck": !isHorizontalScrollEnd
3630 }
3631 ),
3632 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("span", { className: "dataviews-view-table-header", children: (0, import_i18n15.__)("Actions") })
3633 }
3634 )
3635 ] })
3636 }
3637 ),
3638 hasData && groupField && dataByGroup ? Array.from(dataByGroup.entries()).map(
3639 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("tbody", { children: [
3640 /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("tr", { className: "dataviews-view-table__group-header-row", children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3641 "td",
3642 {
3643 colSpan: columns.length + (hasPrimaryColumn ? 1 : 0) + (hasBulkActions ? 1 : 0) + (actions?.length ? 1 : 0),
3644 className: "dataviews-view-table__group-header-cell",
3645 children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n15.sprintf)(
3646 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
3647 (0, import_i18n15.__)("%1$s: %2$s"),
3648 groupField.label,
3649 groupName
3650 )
3651 }
3652 ) }),
3653 groupItems.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3654 TableRow,
3655 {
3656 item,
3657 level: view.showLevels && typeof getItemLevel === "function" ? getItemLevel(item) : void 0,
3658 hasBulkActions,
3659 actions,
3660 fields,
3661 id: getItemId(item) || index.toString(),
3662 view,
3663 titleField,
3664 mediaField,
3665 descriptionField: descriptionField2,
3666 selection,
3667 getItemId,
3668 onChangeSelection,
3669 onClickItem,
3670 renderItemLink,
3671 isItemClickable: isItemClickable2,
3672 isActionsColumnSticky: !isHorizontalScrollEnd
3673 },
3674 getItemId(item)
3675 ))
3676 ] }, `group-${groupName}`)
3677 ) : /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("tbody", { children: hasData && data.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3678 TableRow,
3679 {
3680 item,
3681 level: view.showLevels && typeof getItemLevel === "function" ? getItemLevel(item) : void 0,
3682 hasBulkActions,
3683 actions,
3684 fields,
3685 id: getItemId(item) || index.toString(),
3686 view,
3687 titleField,
3688 mediaField,
3689 descriptionField: descriptionField2,
3690 selection,
3691 getItemId,
3692 onChangeSelection,
3693 onClickItem,
3694 renderItemLink,
3695 isItemClickable: isItemClickable2,
3696 isActionsColumnSticky: !isHorizontalScrollEnd,
3697 posinset: isInfiniteScroll ? index + 1 : void 0
3698 },
3699 getItemId(item)
3700 )) })
3701 ]
3702 }
3703 ),
3704 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, {}) }) })
3705 ] });
3706 }
3707 var table_default = ViewTable;
3708
3709 // packages/dataviews/build-module/components/dataviews-layouts/grid/index.mjs
3710 var import_components9 = __toESM(require_components(), 1);
3711 var import_i18n18 = __toESM(require_i18n(), 1);
3712
3713 // packages/dataviews/build-module/components/dataviews-layouts/grid/composite-grid.mjs
3714 var import_components8 = __toESM(require_components(), 1);
3715 var import_i18n17 = __toESM(require_i18n(), 1);
3716 var import_compose3 = __toESM(require_compose(), 1);
3717 var import_keycodes2 = __toESM(require_keycodes(), 1);
3718 var import_element15 = __toESM(require_element(), 1);
3719
3720 // packages/dataviews/build-module/components/dataviews-layouts/grid/preview-size-picker.mjs
3721 var import_components7 = __toESM(require_components(), 1);
3722 var import_i18n16 = __toESM(require_i18n(), 1);
3723 var import_element12 = __toESM(require_element(), 1);
3724 var import_jsx_runtime39 = __toESM(require_jsx_runtime(), 1);
3725 var imageSizes = [
3726 {
3727 value: 120,
3728 breakpoint: 1
3729 },
3730 {
3731 value: 170,
3732 breakpoint: 1
3733 },
3734 {
3735 value: 230,
3736 breakpoint: 1
3737 },
3738 {
3739 value: 290,
3740 breakpoint: 1112
3741 // at minimum image width, 4 images display at this container size
3742 },
3743 {
3744 value: 350,
3745 breakpoint: 1636
3746 // at minimum image width, 6 images display at this container size
3747 },
3748 {
3749 value: 430,
3750 breakpoint: 588
3751 // at minimum image width, 2 images display at this container size
3752 }
3753 ];
3754 var DEFAULT_PREVIEW_SIZE = imageSizes[2].value;
3755 function useGridColumns() {
3756 const context = (0, import_element12.useContext)(dataviews_context_default);
3757 const view = context.view;
3758 return (0, import_element12.useMemo)(() => {
3759 const containerWidth = context.containerWidth;
3760 const gap = 32;
3761 const previewSize = view.layout?.previewSize ?? DEFAULT_PREVIEW_SIZE;
3762 const columns = Math.floor(
3763 (containerWidth + gap) / (previewSize + gap)
3764 );
3765 return Math.max(1, columns);
3766 }, [context.containerWidth, view.layout?.previewSize]);
3767 }
3768
3769 // packages/dataviews/build-module/components/dataviews-layouts/utils/grid-items.mjs
3770 var import_element13 = __toESM(require_element(), 1);
3771 var import_jsx_runtime40 = __toESM(require_jsx_runtime(), 1);
3772 var GridItems = (0, import_element13.forwardRef)(({ className, previewSize, ...props }, ref) => {
3773 return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3774 "div",
3775 {
3776 ref,
3777 className: clsx_default("dataviews-view-grid-items", className),
3778 style: {
3779 gridTemplateColumns: previewSize && `repeat(auto-fill, minmax(${previewSize}px, 1fr))`
3780 },
3781 ...props
3782 }
3783 );
3784 });
3785
3786 // packages/dataviews/build-module/components/dataviews-layouts/utils/use-infinite-scroll.mjs
3787 var import_element14 = __toESM(require_element(), 1);
3788 function useIntersectionObserver(elementRef, posinset) {
3789 const { intersectionObserver } = (0, import_element14.useContext)(dataviews_context_default);
3790 (0, import_element14.useEffect)(() => {
3791 const element = elementRef.current;
3792 if (!element || posinset === void 0 || !intersectionObserver) {
3793 return;
3794 }
3795 intersectionObserver.observe(element);
3796 return () => {
3797 intersectionObserver.unobserve(element);
3798 };
3799 }, [elementRef, intersectionObserver, posinset]);
3800 }
3801 function usePlaceholdersNeeded(data, isInfiniteScroll, gridColumns) {
3802 const hasData = !!data?.length;
3803 const firstItemPosition = hasData && isInfiniteScroll ? data[0].position : void 0;
3804 return firstItemPosition && gridColumns ? (firstItemPosition - 1) % gridColumns : 0;
3805 }
3806
3807 // packages/dataviews/build-module/components/dataviews-layouts/grid/composite-grid.mjs
3808 var import_jsx_runtime41 = __toESM(require_jsx_runtime(), 1);
3809 var { Badge } = unlock(import_components8.privateApis);
3810 function chunk(array, size) {
3811 const chunks = [];
3812 for (let i2 = 0, j2 = array.length; i2 < j2; i2 += size) {
3813 chunks.push(array.slice(i2, i2 + size));
3814 }
3815 return chunks;
3816 }
3817 var GridItem = (0, import_element15.forwardRef)(
3818 function GridItem2({
3819 view,
3820 selection,
3821 onChangeSelection,
3822 onClickItem,
3823 isItemClickable: isItemClickable2,
3824 renderItemLink,
3825 getItemId,
3826 item,
3827 actions,
3828 mediaField,
3829 titleField,
3830 descriptionField: descriptionField2,
3831 regularFields,
3832 badgeFields,
3833 hasBulkActions,
3834 config,
3835 posinset,
3836 setsize,
3837 ...props
3838 }, forwardedRef) {
3839 const {
3840 showTitle = true,
3841 showMedia = true,
3842 showDescription = true
3843 } = view;
3844 const hasBulkAction = useHasAPossibleBulkAction(actions, item);
3845 const id = getItemId(item);
3846 const elementRef = (0, import_element15.useRef)(null);
3847 const setRefs = (0, import_element15.useCallback)(
3848 (node) => {
3849 elementRef.current = node;
3850 if (typeof forwardedRef === "function") {
3851 forwardedRef(node);
3852 } else if (forwardedRef) {
3853 forwardedRef.current = node;
3854 }
3855 },
3856 [forwardedRef]
3857 );
3858 useIntersectionObserver(elementRef, posinset);
3859 const instanceId = (0, import_compose3.useInstanceId)(GridItem2);
3860 const isSelected2 = selection.includes(id);
3861 const mediaPlaceholder = /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("span", { className: "dataviews-view-grid__media-placeholder" });
3862 const rendersMediaField = showMedia && mediaField?.render;
3863 const renderedMediaField = rendersMediaField ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3864 mediaField.render,
3865 {
3866 item,
3867 field: mediaField,
3868 config
3869 }
3870 ) : mediaPlaceholder;
3871 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(titleField.render, { item, field: titleField }) : null;
3872 let mediaA11yProps;
3873 let titleA11yProps;
3874 if (isItemClickable2(item) && onClickItem) {
3875 if (renderedTitleField) {
3876 mediaA11yProps = {
3877 "aria-labelledby": `dataviews-view-grid__title-field-${instanceId}`
3878 };
3879 titleA11yProps = {
3880 id: `dataviews-view-grid__title-field-${instanceId}`
3881 };
3882 } else {
3883 mediaA11yProps = {
3884 "aria-label": (0, import_i18n17.__)("Navigate to item")
3885 };
3886 }
3887 }
3888 return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
3889 Stack,
3890 {
3891 direction: "column",
3892 ...props,
3893 ref: setRefs,
3894 "aria-setsize": setsize,
3895 "aria-posinset": posinset,
3896 className: clsx_default(
3897 props.className,
3898 "dataviews-view-grid__row__gridcell",
3899 "dataviews-view-grid__card",
3900 {
3901 "is-selected": hasBulkAction && isSelected2
3902 }
3903 ),
3904 onClickCapture: (event) => {
3905 props.onClickCapture?.(event);
3906 if ((0, import_keycodes2.isAppleOS)() ? event.metaKey : event.ctrlKey) {
3907 event.stopPropagation();
3908 event.preventDefault();
3909 if (!hasBulkAction) {
3910 return;
3911 }
3912 onChangeSelection(
3913 isSelected2 ? selection.filter(
3914 (itemId) => id !== itemId
3915 ) : [...selection, id]
3916 );
3917 }
3918 },
3919 children: [
3920 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3921 ItemClickWrapper,
3922 {
3923 item,
3924 isItemClickable: isItemClickable2,
3925 onClickItem,
3926 renderItemLink,
3927 className: clsx_default("dataviews-view-grid__media", {
3928 "dataviews-view-grid__media--placeholder": !rendersMediaField
3929 }),
3930 ...mediaA11yProps,
3931 children: renderedMediaField
3932 }
3933 ),
3934 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3935 DataViewsSelectionCheckbox,
3936 {
3937 item,
3938 selection,
3939 onChangeSelection,
3940 getItemId,
3941 titleField,
3942 disabled: !hasBulkAction
3943 }
3944 ),
3945 !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "dataviews-view-grid__media-actions", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3946 ItemActions,
3947 {
3948 item,
3949 actions,
3950 isCompact: true
3951 }
3952 ) }),
3953 showTitle && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "dataviews-view-grid__title", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3954 ItemClickWrapper,
3955 {
3956 item,
3957 isItemClickable: isItemClickable2,
3958 onClickItem,
3959 renderItemLink,
3960 className: "dataviews-view-grid__title-field dataviews-title-field",
3961 ...titleA11yProps,
3962 title: titleField?.getValueFormatted({
3963 item,
3964 field: titleField
3965 }) || void 0,
3966 children: renderedTitleField
3967 }
3968 ) }),
3969 /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(Stack, { direction: "column", gap: "xs", children: [
3970 showDescription && descriptionField2?.render && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3971 descriptionField2.render,
3972 {
3973 item,
3974 field: descriptionField2
3975 }
3976 ),
3977 !!badgeFields?.length && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3978 Stack,
3979 {
3980 direction: "row",
3981 className: "dataviews-view-grid__badge-fields",
3982 gap: "sm",
3983 wrap: "wrap",
3984 align: "top",
3985 justify: "flex-start",
3986 children: badgeFields.map((field) => {
3987 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3988 Badge,
3989 {
3990 className: "dataviews-view-grid__field-value",
3991 children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3992 field.render,
3993 {
3994 item,
3995 field
3996 }
3997 )
3998 },
3999 field.id
4000 );
4001 })
4002 }
4003 ),
4004 !!regularFields?.length && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4005 Stack,
4006 {
4007 direction: "column",
4008 className: "dataviews-view-grid__fields",
4009 gap: "xs",
4010 children: regularFields.map((field) => {
4011 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4012 import_components8.Flex,
4013 {
4014 className: "dataviews-view-grid__field",
4015 gap: 1,
4016 justify: "flex-start",
4017 expanded: true,
4018 style: { height: "auto" },
4019 direction: "row",
4020 children: /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(import_jsx_runtime41.Fragment, { children: [
4021 /* @__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 }) }),
4022 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4023 import_components8.FlexItem,
4024 {
4025 className: "dataviews-view-grid__field-value",
4026 style: { maxHeight: "none" },
4027 children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4028 field.render,
4029 {
4030 item,
4031 field
4032 }
4033 )
4034 }
4035 )
4036 ] })
4037 },
4038 field.id
4039 );
4040 })
4041 }
4042 )
4043 ] })
4044 ]
4045 }
4046 );
4047 }
4048 );
4049 function CompositeGrid({
4050 data,
4051 isInfiniteScroll,
4052 className,
4053 inert,
4054 isLoading,
4055 view,
4056 fields,
4057 selection,
4058 onChangeSelection,
4059 onClickItem,
4060 isItemClickable: isItemClickable2,
4061 renderItemLink,
4062 getItemId,
4063 actions
4064 }) {
4065 const { paginationInfo, resizeObserverRef } = (0, import_element15.useContext)(dataviews_context_default);
4066 const gridColumns = useGridColumns();
4067 const hasBulkActions = useSomeItemHasAPossibleBulkAction(actions, data);
4068 const titleField = fields.find(
4069 (field) => field.id === view?.titleField
4070 );
4071 const mediaField = fields.find(
4072 (field) => field.id === view?.mediaField
4073 );
4074 const descriptionField2 = fields.find(
4075 (field) => field.id === view?.descriptionField
4076 );
4077 const otherFields = view.fields ?? [];
4078 const { regularFields, badgeFields } = otherFields.reduce(
4079 (accumulator, fieldId) => {
4080 const field = fields.find((f2) => f2.id === fieldId);
4081 if (!field) {
4082 return accumulator;
4083 }
4084 const key = view.layout?.badgeFields?.includes(fieldId) ? "badgeFields" : "regularFields";
4085 accumulator[key].push(field);
4086 return accumulator;
4087 },
4088 { regularFields: [], badgeFields: [] }
4089 );
4090 const size = "900px";
4091 const totalRows = Math.ceil(data.length / gridColumns);
4092 const placeholdersNeeded = usePlaceholdersNeeded(
4093 data,
4094 isInfiniteScroll,
4095 gridColumns
4096 );
4097 return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(import_jsx_runtime41.Fragment, {
4098 // Render infinite scroll layout (no rows, feed semantics)
4099 children: [
4100 isInfiniteScroll && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
4101 import_components8.Composite,
4102 {
4103 render: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4104 GridItems,
4105 {
4106 className: clsx_default(
4107 "dataviews-view-grid-infinite-scroll",
4108 className,
4109 {
4110 [`has-${view.layout?.density}-density`]: view.layout?.density && [
4111 "compact",
4112 "comfortable"
4113 ].includes(view.layout.density)
4114 }
4115 ),
4116 previewSize: view.layout?.previewSize,
4117 "aria-busy": isLoading,
4118 ref: resizeObserverRef
4119 }
4120 ),
4121 role: "feed",
4122 focusWrap: true,
4123 inert,
4124 children: [
4125 Array.from({ length: placeholdersNeeded }).map(
4126 (_, index) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4127 import_components8.Composite.Item,
4128 {
4129 render: (props) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4130 Stack,
4131 {
4132 ...props,
4133 direction: "column",
4134 role: "article",
4135 className: "dataviews-view-grid__row__gridcell dataviews-view-grid__card dataviews-view-grid__placeholder"
4136 }
4137 ),
4138 "aria-hidden": true,
4139 tabIndex: -1
4140 },
4141 `placeholder-${index}`
4142 )
4143 ),
4144 data.map((item) => {
4145 const itemId = getItemId(item);
4146 const stablePosition = item.position;
4147 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4148 import_components8.Composite.Item,
4149 {
4150 render: (props) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4151 GridItem,
4152 {
4153 ...props,
4154 id: itemId,
4155 role: "article",
4156 view,
4157 selection,
4158 onChangeSelection,
4159 onClickItem,
4160 isItemClickable: isItemClickable2,
4161 renderItemLink,
4162 getItemId,
4163 item,
4164 actions,
4165 mediaField,
4166 titleField,
4167 descriptionField: descriptionField2,
4168 regularFields,
4169 badgeFields,
4170 hasBulkActions,
4171 posinset: stablePosition,
4172 setsize: paginationInfo.totalItems,
4173 config: {
4174 sizes: size
4175 }
4176 }
4177 )
4178 },
4179 itemId
4180 );
4181 })
4182 ]
4183 }
4184 ),
4185 // Render standard grid layout (with rows, grid semantics)
4186 !isInfiniteScroll && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4187 import_components8.Composite,
4188 {
4189 role: "grid",
4190 className: clsx_default("dataviews-view-grid", className, {
4191 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
4192 view.layout.density
4193 )
4194 }),
4195 focusWrap: true,
4196 "aria-busy": isLoading,
4197 "aria-rowcount": totalRows,
4198 ref: resizeObserverRef,
4199 inert,
4200 children: chunk(data, gridColumns).map((row, i2) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4201 import_components8.Composite.Row,
4202 {
4203 render: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4204 "div",
4205 {
4206 role: "row",
4207 "aria-rowindex": i2 + 1,
4208 "aria-label": (0, import_i18n17.sprintf)(
4209 /* translators: %d: The row number in the grid */
4210 (0, import_i18n17.__)("Row %d"),
4211 i2 + 1
4212 ),
4213 className: "dataviews-view-grid__row",
4214 style: {
4215 gridTemplateColumns: `repeat( ${gridColumns}, minmax(0, 1fr) )`
4216 }
4217 }
4218 ),
4219 children: row.map((item) => {
4220 const itemId = getItemId(item);
4221 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4222 import_components8.Composite.Item,
4223 {
4224 render: (props) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4225 GridItem,
4226 {
4227 ...props,
4228 id: itemId,
4229 role: "gridcell",
4230 view,
4231 selection,
4232 onChangeSelection,
4233 onClickItem,
4234 isItemClickable: isItemClickable2,
4235 renderItemLink,
4236 getItemId,
4237 item,
4238 actions,
4239 mediaField,
4240 titleField,
4241 descriptionField: descriptionField2,
4242 regularFields,
4243 badgeFields,
4244 hasBulkActions,
4245 config: {
4246 sizes: size
4247 }
4248 }
4249 )
4250 },
4251 itemId
4252 );
4253 })
4254 },
4255 i2
4256 ))
4257 }
4258 )
4259 ]
4260 });
4261 }
4262
4263 // packages/dataviews/build-module/components/dataviews-layouts/grid/index.mjs
4264 var import_jsx_runtime42 = __toESM(require_jsx_runtime(), 1);
4265 function ViewGrid({
4266 actions,
4267 data,
4268 fields,
4269 getItemId,
4270 isLoading,
4271 onChangeSelection,
4272 onClickItem,
4273 isItemClickable: isItemClickable2,
4274 renderItemLink,
4275 selection,
4276 view,
4277 className,
4278 empty
4279 }) {
4280 const isDelayedLoading = useDelayedLoading(!!isLoading);
4281 const hasData = !!data?.length;
4282 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
4283 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
4284 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
4285 if (!hasData) {
4286 return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
4287 "div",
4288 {
4289 className: clsx_default("dataviews-no-results", {
4290 "is-refreshing": isDelayedLoading
4291 }),
4292 children: empty
4293 }
4294 );
4295 }
4296 const gridProps = {
4297 className: clsx_default(className, {
4298 "is-refreshing": !isInfiniteScroll && isDelayedLoading
4299 }),
4300 inert: !isInfiniteScroll && !!isLoading ? "true" : void 0,
4301 isLoading,
4302 view,
4303 fields,
4304 selection,
4305 onChangeSelection,
4306 onClickItem,
4307 isItemClickable: isItemClickable2,
4308 renderItemLink,
4309 getItemId,
4310 actions
4311 };
4312 return /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(import_jsx_runtime42.Fragment, {
4313 // Render multiple groups.
4314 children: [
4315 hasData && groupField && dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(Stack, { direction: "column", gap: "lg", children: Array.from(dataByGroup.entries()).map(
4316 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(
4317 Stack,
4318 {
4319 direction: "column",
4320 gap: "sm",
4321 children: [
4322 /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("h3", { className: "dataviews-view-grid__group-header", children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n18.sprintf)(
4323 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
4324 (0, import_i18n18.__)("%1$s: %2$s"),
4325 groupField.label,
4326 groupName
4327 ) }),
4328 /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
4329 CompositeGrid,
4330 {
4331 ...gridProps,
4332 data: groupItems,
4333 isInfiniteScroll: false
4334 }
4335 )
4336 ]
4337 },
4338 groupName
4339 )
4340 ) }),
4341 // Render a single grid with all data.
4342 !dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
4343 CompositeGrid,
4344 {
4345 ...gridProps,
4346 data,
4347 isInfiniteScroll: !!isInfiniteScroll
4348 }
4349 ),
4350 isInfiniteScroll && isLoading && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(import_components9.Spinner, {}) })
4351 ]
4352 });
4353 }
4354 var grid_default = ViewGrid;
4355
4356 // packages/dataviews/build-module/components/dataviews-layouts/list/index.mjs
4357 var import_compose4 = __toESM(require_compose(), 1);
4358 var import_components10 = __toESM(require_components(), 1);
4359 var import_element16 = __toESM(require_element(), 1);
4360 var import_i18n19 = __toESM(require_i18n(), 1);
4361 var import_data3 = __toESM(require_data(), 1);
4362 var import_jsx_runtime43 = __toESM(require_jsx_runtime(), 1);
4363 var { Menu: Menu3 } = unlock(import_components10.privateApis);
4364 function generateItemWrapperCompositeId(idPrefix) {
4365 return `${idPrefix}-item-wrapper`;
4366 }
4367 function generatePrimaryActionCompositeId(idPrefix, primaryActionId) {
4368 return `${idPrefix}-primary-action-${primaryActionId}`;
4369 }
4370 function generateDropdownTriggerCompositeId(idPrefix) {
4371 return `${idPrefix}-dropdown`;
4372 }
4373 function PrimaryActionGridCell({
4374 idPrefix,
4375 primaryAction,
4376 item
4377 }) {
4378 const registry = (0, import_data3.useRegistry)();
4379 const [isModalOpen, setIsModalOpen] = (0, import_element16.useState)(false);
4380 const compositeItemId = generatePrimaryActionCompositeId(
4381 idPrefix,
4382 primaryAction.id
4383 );
4384 const label = typeof primaryAction.label === "string" ? primaryAction.label : primaryAction.label([item]);
4385 return "RenderModal" in primaryAction ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { role: "gridcell", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4386 import_components10.Composite.Item,
4387 {
4388 id: compositeItemId,
4389 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4390 import_components10.Button,
4391 {
4392 disabled: !!primaryAction.disabled,
4393 accessibleWhenDisabled: true,
4394 text: label,
4395 size: "small",
4396 onClick: () => setIsModalOpen(true)
4397 }
4398 ),
4399 children: isModalOpen && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4400 ActionModal,
4401 {
4402 action: primaryAction,
4403 items: [item],
4404 closeModal: () => setIsModalOpen(false)
4405 }
4406 )
4407 }
4408 ) }, primaryAction.id) : /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { role: "gridcell", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4409 import_components10.Composite.Item,
4410 {
4411 id: compositeItemId,
4412 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4413 import_components10.Button,
4414 {
4415 disabled: !!primaryAction.disabled,
4416 accessibleWhenDisabled: true,
4417 size: "small",
4418 onClick: () => {
4419 primaryAction.callback([item], { registry });
4420 },
4421 children: label
4422 }
4423 )
4424 }
4425 ) }, primaryAction.id);
4426 }
4427 function ListItem({
4428 view,
4429 actions,
4430 idPrefix,
4431 isSelected: isSelected2,
4432 item,
4433 titleField,
4434 mediaField,
4435 descriptionField: descriptionField2,
4436 onSelect,
4437 otherFields,
4438 onDropdownTriggerKeyDown,
4439 posinset
4440 }) {
4441 const {
4442 showTitle = true,
4443 showMedia = true,
4444 showDescription = true,
4445 infiniteScrollEnabled
4446 } = view;
4447 const itemRef = (0, import_element16.useRef)(null);
4448 const labelId = `${idPrefix}-label`;
4449 const descriptionId = `${idPrefix}-description`;
4450 const registry = (0, import_data3.useRegistry)();
4451 const [isHovered, setIsHovered] = (0, import_element16.useState)(false);
4452 const [activeModalAction, setActiveModalAction] = (0, import_element16.useState)(
4453 null
4454 );
4455 const handleHover = ({ type }) => {
4456 const isHover = type === "mouseenter";
4457 setIsHovered(isHover);
4458 };
4459 const { paginationInfo } = (0, import_element16.useContext)(dataviews_context_default);
4460 (0, import_element16.useEffect)(() => {
4461 if (isSelected2) {
4462 itemRef.current?.scrollIntoView({
4463 behavior: "auto",
4464 block: "nearest",
4465 inline: "nearest"
4466 });
4467 }
4468 }, [isSelected2]);
4469 const { primaryAction, eligibleActions } = (0, import_element16.useMemo)(() => {
4470 const _eligibleActions = actions.filter(
4471 (action) => !action.isEligible || action.isEligible(item)
4472 );
4473 const _primaryActions = _eligibleActions.filter(
4474 (action) => action.isPrimary
4475 );
4476 return {
4477 primaryAction: _primaryActions[0],
4478 eligibleActions: _eligibleActions
4479 };
4480 }, [actions, item]);
4481 const hasOnlyOnePrimaryAction = primaryAction && actions.length === 1;
4482 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)(
4483 mediaField.render,
4484 {
4485 item,
4486 field: mediaField,
4487 config: { sizes: "52px" }
4488 }
4489 ) }) : null;
4490 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(titleField.render, { item, field: titleField }) : null;
4491 const renderDescription = showDescription && descriptionField2?.render;
4492 const hasOnlyMediaAndTitle = !!renderedMediaField && !renderDescription && !otherFields.length;
4493 const usedActions = eligibleActions?.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4494 Stack,
4495 {
4496 direction: "row",
4497 gap: "md",
4498 className: "dataviews-view-list__item-actions",
4499 children: [
4500 primaryAction && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4501 PrimaryActionGridCell,
4502 {
4503 idPrefix,
4504 primaryAction,
4505 item
4506 }
4507 ),
4508 !hasOnlyOnePrimaryAction && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { role: "gridcell", children: [
4509 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Menu3, { placement: "bottom-end", children: [
4510 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4511 Menu3.TriggerButton,
4512 {
4513 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4514 import_components10.Composite.Item,
4515 {
4516 id: generateDropdownTriggerCompositeId(
4517 idPrefix
4518 ),
4519 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4520 import_components10.Button,
4521 {
4522 size: "small",
4523 icon: more_vertical_default,
4524 label: (0, import_i18n19.__)("Actions"),
4525 accessibleWhenDisabled: true,
4526 disabled: !actions.length,
4527 onKeyDown: onDropdownTriggerKeyDown
4528 }
4529 )
4530 }
4531 )
4532 }
4533 ),
4534 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Menu3.Popover, { children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4535 ActionsMenuGroup,
4536 {
4537 actions: eligibleActions,
4538 item,
4539 registry,
4540 setActiveModalAction
4541 }
4542 ) })
4543 ] }),
4544 !!activeModalAction && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4545 ActionModal,
4546 {
4547 action: activeModalAction,
4548 items: [item],
4549 closeModal: () => setActiveModalAction(null)
4550 }
4551 )
4552 ] })
4553 ]
4554 }
4555 );
4556 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4557 import_components10.Composite.Row,
4558 {
4559 ref: itemRef,
4560 render: (
4561 /* aria-posinset breaks Composite.Row if passed to it directly. */
4562 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4563 "div",
4564 {
4565 "aria-posinset": posinset,
4566 "aria-setsize": infiniteScrollEnabled ? paginationInfo.totalItems : void 0
4567 }
4568 )
4569 ),
4570 role: infiniteScrollEnabled ? "article" : "row",
4571 className: clsx_default({
4572 "is-selected": isSelected2,
4573 "is-hovered": isHovered
4574 }),
4575 onMouseEnter: handleHover,
4576 onMouseLeave: handleHover,
4577 children: /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4578 Stack,
4579 {
4580 direction: "row",
4581 className: "dataviews-view-list__item-wrapper",
4582 children: [
4583 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { role: "gridcell", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4584 import_components10.Composite.Item,
4585 {
4586 id: generateItemWrapperCompositeId(idPrefix),
4587 "aria-pressed": isSelected2,
4588 "aria-labelledby": labelId,
4589 "aria-describedby": descriptionId,
4590 className: "dataviews-view-list__item",
4591 onClick: () => onSelect(item)
4592 }
4593 ) }),
4594 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4595 Stack,
4596 {
4597 direction: "row",
4598 gap: "md",
4599 justify: "start",
4600 align: hasOnlyMediaAndTitle ? "center" : "flex-start",
4601 style: { flex: 1, minWidth: 0 },
4602 children: [
4603 renderedMediaField,
4604 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4605 Stack,
4606 {
4607 direction: "column",
4608 gap: "xs",
4609 className: "dataviews-view-list__field-wrapper",
4610 children: [
4611 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Stack, { direction: "row", align: "center", children: [
4612 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4613 "div",
4614 {
4615 className: "dataviews-title-field dataviews-view-list__title-field",
4616 id: labelId,
4617 children: renderedTitleField
4618 }
4619 ),
4620 usedActions
4621 ] }),
4622 renderDescription && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "dataviews-view-list__field", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4623 descriptionField2.render,
4624 {
4625 item,
4626 field: descriptionField2
4627 }
4628 ) }),
4629 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4630 "div",
4631 {
4632 className: "dataviews-view-list__fields",
4633 id: descriptionId,
4634 children: otherFields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4635 "div",
4636 {
4637 className: "dataviews-view-list__field",
4638 children: [
4639 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4640 import_components10.VisuallyHidden,
4641 {
4642 as: "span",
4643 className: "dataviews-view-list__field-label",
4644 children: field.label
4645 }
4646 ),
4647 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "dataviews-view-list__field-value", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4648 field.render,
4649 {
4650 item,
4651 field
4652 }
4653 ) })
4654 ]
4655 },
4656 field.id
4657 ))
4658 }
4659 )
4660 ]
4661 }
4662 )
4663 ]
4664 }
4665 )
4666 ]
4667 }
4668 )
4669 }
4670 );
4671 }
4672 function isDefined2(item) {
4673 return !!item;
4674 }
4675 function ViewList(props) {
4676 const {
4677 actions,
4678 data,
4679 fields,
4680 getItemId,
4681 isLoading,
4682 onChangeSelection,
4683 selection,
4684 view,
4685 className,
4686 empty
4687 } = props;
4688 const baseId = (0, import_compose4.useInstanceId)(ViewList, "view-list");
4689 const isDelayedLoading = useDelayedLoading(!!isLoading);
4690 const selectedItem = data?.findLast(
4691 (item) => selection.includes(getItemId(item))
4692 );
4693 const titleField = fields.find((field) => field.id === view.titleField);
4694 const mediaField = fields.find((field) => field.id === view.mediaField);
4695 const descriptionField2 = fields.find(
4696 (field) => field.id === view.descriptionField
4697 );
4698 const otherFields = (view?.fields ?? []).map((fieldId) => fields.find((f2) => fieldId === f2.id)).filter(isDefined2);
4699 const onSelect = (item) => onChangeSelection([getItemId(item)]);
4700 const generateCompositeItemIdPrefix = (0, import_element16.useCallback)(
4701 (item) => `${baseId}-${getItemId(item)}`,
4702 [baseId, getItemId]
4703 );
4704 const isActiveCompositeItem = (0, import_element16.useCallback)(
4705 (item, idToCheck) => {
4706 return idToCheck.startsWith(
4707 generateCompositeItemIdPrefix(item)
4708 );
4709 },
4710 [generateCompositeItemIdPrefix]
4711 );
4712 const [activeCompositeId, setActiveCompositeId] = (0, import_element16.useState)(void 0);
4713 const compositeRef = (0, import_element16.useRef)(null);
4714 (0, import_element16.useEffect)(() => {
4715 if (selectedItem) {
4716 setActiveCompositeId(
4717 generateItemWrapperCompositeId(
4718 generateCompositeItemIdPrefix(selectedItem)
4719 )
4720 );
4721 }
4722 }, [selectedItem, generateCompositeItemIdPrefix]);
4723 const activeItemIndex = data.findIndex(
4724 (item) => isActiveCompositeItem(item, activeCompositeId ?? "")
4725 );
4726 const previousActiveItemIndex = (0, import_compose4.usePrevious)(activeItemIndex);
4727 const isActiveIdInList = activeItemIndex !== -1;
4728 const selectCompositeItem = (0, import_element16.useCallback)(
4729 (targetIndex, generateCompositeId) => {
4730 const clampedIndex = Math.min(
4731 data.length - 1,
4732 Math.max(0, targetIndex)
4733 );
4734 if (!data[clampedIndex]) {
4735 return;
4736 }
4737 const itemIdPrefix = generateCompositeItemIdPrefix(
4738 data[clampedIndex]
4739 );
4740 const targetCompositeItemId = generateCompositeId(itemIdPrefix);
4741 setActiveCompositeId(targetCompositeItemId);
4742 if (compositeRef.current?.contains(
4743 compositeRef.current.ownerDocument.activeElement
4744 )) {
4745 document.getElementById(targetCompositeItemId)?.focus();
4746 }
4747 },
4748 [data, generateCompositeItemIdPrefix]
4749 );
4750 (0, import_element16.useEffect)(() => {
4751 const wasActiveIdInList = previousActiveItemIndex !== void 0 && previousActiveItemIndex !== -1;
4752 if (!isActiveIdInList && wasActiveIdInList) {
4753 selectCompositeItem(
4754 previousActiveItemIndex,
4755 generateItemWrapperCompositeId
4756 );
4757 }
4758 }, [isActiveIdInList, selectCompositeItem, previousActiveItemIndex]);
4759 const onDropdownTriggerKeyDown = (0, import_element16.useCallback)(
4760 (event) => {
4761 if (event.key === "ArrowDown") {
4762 event.preventDefault();
4763 selectCompositeItem(
4764 activeItemIndex + 1,
4765 generateDropdownTriggerCompositeId
4766 );
4767 }
4768 if (event.key === "ArrowUp") {
4769 event.preventDefault();
4770 selectCompositeItem(
4771 activeItemIndex - 1,
4772 generateDropdownTriggerCompositeId
4773 );
4774 }
4775 },
4776 [selectCompositeItem, activeItemIndex]
4777 );
4778 const hasData = !!data?.length;
4779 const groupField = view.groupBy?.field ? fields.find((field) => field.id === view.groupBy?.field) : null;
4780 const dataByGroup = hasData && groupField ? getDataByGroup(data, groupField) : null;
4781 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
4782 if (!hasData) {
4783 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4784 "div",
4785 {
4786 className: clsx_default("dataviews-no-results", {
4787 "is-refreshing": isDelayedLoading
4788 }),
4789 children: empty
4790 }
4791 );
4792 }
4793 if (hasData && groupField && dataByGroup) {
4794 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4795 import_components10.Composite,
4796 {
4797 ref: compositeRef,
4798 id: `${baseId}`,
4799 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", {}),
4800 className: "dataviews-view-list__group",
4801 role: "grid",
4802 activeId: activeCompositeId,
4803 setActiveId: setActiveCompositeId,
4804 children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4805 Stack,
4806 {
4807 direction: "column",
4808 gap: "lg",
4809 className: clsx_default("dataviews-view-list", className),
4810 children: Array.from(dataByGroup.entries()).map(
4811 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4812 Stack,
4813 {
4814 direction: "column",
4815 gap: "sm",
4816 children: [
4817 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("h3", { className: "dataviews-view-list__group-header", children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n19.sprintf)(
4818 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
4819 (0, import_i18n19.__)("%1$s: %2$s"),
4820 groupField.label,
4821 groupName
4822 ) }),
4823 groupItems.map((item) => {
4824 const id = generateCompositeItemIdPrefix(item);
4825 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4826 ListItem,
4827 {
4828 view,
4829 idPrefix: id,
4830 actions,
4831 item,
4832 isSelected: item === selectedItem,
4833 onSelect,
4834 mediaField,
4835 titleField,
4836 descriptionField: descriptionField2,
4837 otherFields,
4838 onDropdownTriggerKeyDown
4839 },
4840 id
4841 );
4842 })
4843 ]
4844 },
4845 groupName
4846 )
4847 )
4848 }
4849 )
4850 }
4851 );
4852 }
4853 return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(import_jsx_runtime43.Fragment, { children: [
4854 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4855 import_components10.Composite,
4856 {
4857 ref: compositeRef,
4858 id: baseId,
4859 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", {}),
4860 className: clsx_default("dataviews-view-list", className, {
4861 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
4862 view.layout.density
4863 ),
4864 "is-refreshing": !isInfiniteScroll && isDelayedLoading
4865 }),
4866 role: view.infiniteScrollEnabled ? "feed" : "grid",
4867 activeId: activeCompositeId,
4868 setActiveId: setActiveCompositeId,
4869 inert: !isInfiniteScroll && !!isLoading ? "true" : void 0,
4870 children: data.map((item, index) => {
4871 const id = generateCompositeItemIdPrefix(item);
4872 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4873 ListItem,
4874 {
4875 view,
4876 idPrefix: id,
4877 actions,
4878 item,
4879 isSelected: item === selectedItem,
4880 onSelect,
4881 mediaField,
4882 titleField,
4883 descriptionField: descriptionField2,
4884 otherFields,
4885 onDropdownTriggerKeyDown,
4886 posinset: view.infiniteScrollEnabled ? index + 1 : void 0
4887 },
4888 id
4889 );
4890 })
4891 }
4892 ),
4893 isInfiniteScroll && isLoading && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(import_components10.Spinner, {}) })
4894 ] });
4895 }
4896
4897 // packages/dataviews/build-module/components/dataviews-layouts/activity/index.mjs
4898 var import_components12 = __toESM(require_components(), 1);
4899
4900 // packages/dataviews/build-module/components/dataviews-layouts/activity/activity-group.mjs
4901 var import_i18n20 = __toESM(require_i18n(), 1);
4902 var import_element17 = __toESM(require_element(), 1);
4903 var import_jsx_runtime44 = __toESM(require_jsx_runtime(), 1);
4904 function ActivityGroup({
4905 groupName,
4906 groupData,
4907 groupField,
4908 showLabel = true,
4909 children
4910 }) {
4911 const groupHeader = showLabel ? (0, import_element17.createInterpolateElement)(
4912 // translators: %s: The label of the field e.g. "Status".
4913 (0, import_i18n20.sprintf)((0, import_i18n20.__)("%s: <groupName />"), groupField.label).trim(),
4914 {
4915 groupName: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
4916 groupField.render,
4917 {
4918 item: groupData[0],
4919 field: groupField
4920 }
4921 )
4922 }
4923 ) : /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(groupField.render, { item: groupData[0], field: groupField });
4924 return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)(
4925 Stack,
4926 {
4927 direction: "column",
4928 className: "dataviews-view-activity__group",
4929 children: [
4930 /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("h3", { className: "dataviews-view-activity__group-header", children: groupHeader }),
4931 children
4932 ]
4933 },
4934 groupName
4935 );
4936 }
4937
4938 // packages/dataviews/build-module/components/dataviews-layouts/activity/activity-item.mjs
4939 var import_components11 = __toESM(require_components(), 1);
4940 var import_element18 = __toESM(require_element(), 1);
4941 var import_data4 = __toESM(require_data(), 1);
4942 var import_compose5 = __toESM(require_compose(), 1);
4943 var import_jsx_runtime45 = __toESM(require_jsx_runtime(), 1);
4944 function ActivityItem(props) {
4945 const {
4946 view,
4947 actions,
4948 item,
4949 titleField,
4950 mediaField,
4951 descriptionField: descriptionField2,
4952 otherFields,
4953 posinset,
4954 onClickItem,
4955 renderItemLink,
4956 isItemClickable: isItemClickable2
4957 } = props;
4958 const {
4959 showTitle = true,
4960 showMedia = true,
4961 showDescription = true,
4962 infiniteScrollEnabled
4963 } = view;
4964 const itemRef = (0, import_element18.useRef)(null);
4965 const registry = (0, import_data4.useRegistry)();
4966 const { paginationInfo } = (0, import_element18.useContext)(dataviews_context_default);
4967 const { primaryActions, eligibleActions } = (0, import_element18.useMemo)(() => {
4968 const _eligibleActions = actions.filter(
4969 (action) => !action.isEligible || action.isEligible(item)
4970 );
4971 const _primaryActions = _eligibleActions.filter(
4972 (action) => action.isPrimary
4973 );
4974 return {
4975 primaryActions: _primaryActions,
4976 eligibleActions: _eligibleActions
4977 };
4978 }, [actions, item]);
4979 const isMobileViewport = (0, import_compose5.useViewportMatch)("medium", "<");
4980 const density = view.layout?.density ?? "balanced";
4981 const mediaContent = showMedia && density !== "compact" && mediaField?.render ? /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
4982 mediaField.render,
4983 {
4984 item,
4985 field: mediaField,
4986 config: {
4987 sizes: density === "comfortable" ? "32px" : "24px"
4988 }
4989 }
4990 ) : null;
4991 const renderedMediaField = /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-type-icon", children: mediaContent || /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
4992 "span",
4993 {
4994 className: "dataviews-view-activity__item-bullet",
4995 "aria-hidden": "true"
4996 }
4997 ) });
4998 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(titleField.render, { item, field: titleField }) : null;
4999 const verticalGap = (0, import_element18.useMemo)(() => {
5000 switch (density) {
5001 case "comfortable":
5002 return "md";
5003 default:
5004 return "sm";
5005 }
5006 }, [density]);
5007 return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5008 "div",
5009 {
5010 ref: itemRef,
5011 role: infiniteScrollEnabled ? "article" : void 0,
5012 "aria-posinset": posinset,
5013 "aria-setsize": infiniteScrollEnabled ? paginationInfo.totalItems : void 0,
5014 className: clsx_default(
5015 "dataviews-view-activity__item",
5016 density === "compact" && "is-compact",
5017 density === "balanced" && "is-balanced",
5018 density === "comfortable" && "is-comfortable"
5019 ),
5020 children: /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(Stack, { direction: "row", gap: "lg", justify: "start", align: "flex-start", children: [
5021 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5022 Stack,
5023 {
5024 direction: "column",
5025 gap: "xs",
5026 align: "center",
5027 className: "dataviews-view-activity__item-type",
5028 children: renderedMediaField
5029 }
5030 ),
5031 /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
5032 Stack,
5033 {
5034 direction: "column",
5035 gap: verticalGap,
5036 align: "flex-start",
5037 className: "dataviews-view-activity__item-content",
5038 children: [
5039 renderedTitleField && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5040 ItemClickWrapper,
5041 {
5042 item,
5043 isItemClickable: isItemClickable2,
5044 onClickItem,
5045 renderItemLink,
5046 className: "dataviews-view-activity__item-title",
5047 children: renderedTitleField
5048 }
5049 ),
5050 showDescription && descriptionField2 && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-description", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5051 descriptionField2.render,
5052 {
5053 item,
5054 field: descriptionField2
5055 }
5056 ) }),
5057 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-fields", children: otherFields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
5058 "div",
5059 {
5060 className: "dataviews-view-activity__item-field",
5061 children: [
5062 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5063 import_components11.VisuallyHidden,
5064 {
5065 as: "span",
5066 className: "dataviews-view-activity__item-field-label",
5067 children: field.label
5068 }
5069 ),
5070 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("span", { className: "dataviews-view-activity__item-field-value", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5071 field.render,
5072 {
5073 item,
5074 field
5075 }
5076 ) })
5077 ]
5078 },
5079 field.id
5080 )) }),
5081 !!primaryActions?.length && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5082 PrimaryActions,
5083 {
5084 item,
5085 actions: primaryActions,
5086 registry,
5087 buttonVariant: "secondary"
5088 }
5089 )
5090 ]
5091 }
5092 ),
5093 (primaryActions.length < eligibleActions.length || // Since we hide primary actions on mobile, we need to show the menu
5094 // there if there are any actions at all.
5095 isMobileViewport && // At the same time, only show the menu if there are actions to show.
5096 eligibleActions.length > 0) && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-actions", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5097 ItemActions,
5098 {
5099 item,
5100 actions: eligibleActions,
5101 isCompact: true
5102 }
5103 ) })
5104 ] })
5105 }
5106 );
5107 }
5108 var activity_item_default = ActivityItem;
5109
5110 // packages/dataviews/build-module/components/dataviews-layouts/activity/activity-items.mjs
5111 var import_react3 = __toESM(require_react(), 1);
5112 function isDefined3(item) {
5113 return !!item;
5114 }
5115 function ActivityItems(props) {
5116 const { data, fields, getItemId, view } = props;
5117 const titleField = fields.find((field) => field.id === view.titleField);
5118 const mediaField = fields.find((field) => field.id === view.mediaField);
5119 const descriptionField2 = fields.find(
5120 (field) => field.id === view.descriptionField
5121 );
5122 const otherFields = (view?.fields ?? []).map((fieldId) => fields.find((f2) => fieldId === f2.id)).filter(isDefined3);
5123 return data.map((item, index) => {
5124 return /* @__PURE__ */ (0, import_react3.createElement)(
5125 activity_item_default,
5126 {
5127 ...props,
5128 key: getItemId(item),
5129 item,
5130 mediaField,
5131 titleField,
5132 descriptionField: descriptionField2,
5133 otherFields,
5134 posinset: view.infiniteScrollEnabled ? index + 1 : void 0
5135 }
5136 );
5137 });
5138 }
5139
5140 // packages/dataviews/build-module/components/dataviews-layouts/activity/index.mjs
5141 var import_jsx_runtime46 = __toESM(require_jsx_runtime(), 1);
5142 function ViewActivity(props) {
5143 const { empty, data, fields, isLoading, view, className } = props;
5144 const isDelayedLoading = useDelayedLoading(!!isLoading);
5145 const hasData = !!data?.length;
5146 const groupField = view.groupBy?.field ? fields.find((field) => field.id === view.groupBy?.field) : null;
5147 const dataByGroup = hasData && groupField ? getDataByGroup(data, groupField) : null;
5148 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
5149 if (!hasData) {
5150 return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5151 "div",
5152 {
5153 className: clsx_default("dataviews-no-results", {
5154 "is-refreshing": isDelayedLoading
5155 }),
5156 children: empty
5157 }
5158 );
5159 }
5160 const isInert = !isInfiniteScroll && !!isLoading;
5161 const wrapperClassName = clsx_default("dataviews-view-activity", className, {
5162 "is-refreshing": !isInfiniteScroll && isDelayedLoading
5163 });
5164 const groupedEntries = dataByGroup ? Array.from(dataByGroup.entries()) : [];
5165 if (hasData && groupField && dataByGroup) {
5166 return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5167 Stack,
5168 {
5169 direction: "column",
5170 gap: "sm",
5171 className: wrapperClassName,
5172 inert: isInert ? "true" : void 0,
5173 children: groupedEntries.map(
5174 ([groupName, groupData]) => /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5175 ActivityGroup,
5176 {
5177 groupName,
5178 groupData,
5179 groupField,
5180 showLabel: view.groupBy?.showLabel !== false,
5181 children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5182 ActivityItems,
5183 {
5184 ...props,
5185 data: groupData
5186 }
5187 )
5188 },
5189 groupName
5190 )
5191 )
5192 }
5193 );
5194 }
5195 return /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)(import_jsx_runtime46.Fragment, { children: [
5196 /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5197 "div",
5198 {
5199 className: wrapperClassName,
5200 role: view.infiniteScrollEnabled ? "feed" : void 0,
5201 inert: isInert ? "true" : void 0,
5202 children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(ActivityItems, { ...props })
5203 }
5204 ),
5205 isInfiniteScroll && isLoading && /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(import_components12.Spinner, {}) })
5206 ] });
5207 }
5208
5209 // packages/dataviews/build-module/components/dataviews-layouts/picker-grid/index.mjs
5210 var import_components15 = __toESM(require_components(), 1);
5211 var import_i18n23 = __toESM(require_i18n(), 1);
5212 var import_compose6 = __toESM(require_compose(), 1);
5213 var import_element21 = __toESM(require_element(), 1);
5214
5215 // packages/dataviews/build-module/components/dataviews-picker-footer/index.mjs
5216 var import_components14 = __toESM(require_components(), 1);
5217 var import_data5 = __toESM(require_data(), 1);
5218 var import_element20 = __toESM(require_element(), 1);
5219 var import_i18n22 = __toESM(require_i18n(), 1);
5220
5221 // packages/dataviews/build-module/components/dataviews-pagination/index.mjs
5222 var import_components13 = __toESM(require_components(), 1);
5223 var import_element19 = __toESM(require_element(), 1);
5224 var import_i18n21 = __toESM(require_i18n(), 1);
5225 var import_jsx_runtime47 = __toESM(require_jsx_runtime(), 1);
5226 function DataViewsPagination() {
5227 const {
5228 view,
5229 onChangeView,
5230 paginationInfo: { totalItems = 0, totalPages }
5231 } = (0, import_element19.useContext)(dataviews_context_default);
5232 if (!totalItems || !totalPages || view.infiniteScrollEnabled) {
5233 return null;
5234 }
5235 const currentPage = view.page ?? 1;
5236 const pageSelectOptions = Array.from(Array(totalPages)).map(
5237 (_, i2) => {
5238 const page = i2 + 1;
5239 return {
5240 value: page.toString(),
5241 label: page.toString(),
5242 "aria-label": currentPage === page ? (0, import_i18n21.sprintf)(
5243 // translators: 1: current page number. 2: total number of pages.
5244 (0, import_i18n21.__)("Page %1$d of %2$d"),
5245 currentPage,
5246 totalPages
5247 ) : page.toString()
5248 };
5249 }
5250 );
5251 return !!totalItems && totalPages !== 1 && /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(
5252 Stack,
5253 {
5254 direction: "row",
5255 className: "dataviews-pagination",
5256 justify: "end",
5257 align: "center",
5258 gap: "xl",
5259 children: [
5260 /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5261 Stack,
5262 {
5263 direction: "row",
5264 justify: "flex-start",
5265 align: "center",
5266 gap: "xs",
5267 className: "dataviews-pagination__page-select",
5268 children: (0, import_element19.createInterpolateElement)(
5269 (0, import_i18n21.sprintf)(
5270 // translators: 1: Current page number, 2: Total number of pages.
5271 (0, import_i18n21._x)(
5272 "<div>Page</div>%1$s<div>of %2$d</div>",
5273 "paging"
5274 ),
5275 "<CurrentPage />",
5276 totalPages
5277 ),
5278 {
5279 div: /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("div", { "aria-hidden": true }),
5280 CurrentPage: /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5281 import_components13.SelectControl,
5282 {
5283 "aria-label": (0, import_i18n21.__)("Current page"),
5284 value: currentPage.toString(),
5285 options: pageSelectOptions,
5286 onChange: (newValue) => {
5287 onChangeView({
5288 ...view,
5289 page: +newValue
5290 });
5291 },
5292 size: "small",
5293 variant: "minimal"
5294 }
5295 )
5296 }
5297 )
5298 }
5299 ),
5300 /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(Stack, { direction: "row", gap: "xs", align: "center", children: [
5301 /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5302 import_components13.Button,
5303 {
5304 onClick: () => onChangeView({
5305 ...view,
5306 page: currentPage - 1
5307 }),
5308 disabled: currentPage === 1,
5309 accessibleWhenDisabled: true,
5310 label: (0, import_i18n21.__)("Previous page"),
5311 icon: (0, import_i18n21.isRTL)() ? next_default : previous_default,
5312 showTooltip: true,
5313 size: "compact",
5314 tooltipPosition: "top"
5315 }
5316 ),
5317 /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5318 import_components13.Button,
5319 {
5320 onClick: () => onChangeView({ ...view, page: currentPage + 1 }),
5321 disabled: currentPage >= totalPages,
5322 accessibleWhenDisabled: true,
5323 label: (0, import_i18n21.__)("Next page"),
5324 icon: (0, import_i18n21.isRTL)() ? previous_default : next_default,
5325 showTooltip: true,
5326 size: "compact",
5327 tooltipPosition: "top"
5328 }
5329 )
5330 ] })
5331 ]
5332 }
5333 );
5334 }
5335 var dataviews_pagination_default = (0, import_element19.memo)(DataViewsPagination);
5336
5337 // packages/dataviews/build-module/components/dataviews-picker-footer/index.mjs
5338 var import_jsx_runtime48 = __toESM(require_jsx_runtime(), 1);
5339 var EMPTY_ARRAY2 = [];
5340 function useIsMultiselectPicker(actions) {
5341 return (0, import_element20.useMemo)(() => {
5342 return actions?.every((action) => action.supportsBulk);
5343 }, [actions]);
5344 }
5345 function BulkSelectionCheckbox2({
5346 selection,
5347 selectedItems,
5348 onChangeSelection,
5349 data,
5350 getItemId,
5351 disableSelectAll = false
5352 }) {
5353 const hasSelection = selection.length > 0;
5354 const areAllSelected = selectedItems.length === data.length;
5355 if (disableSelectAll) {
5356 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5357 import_components14.CheckboxControl,
5358 {
5359 className: "dataviews-view-table-selection-checkbox",
5360 checked: hasSelection,
5361 disabled: !hasSelection,
5362 onChange: () => {
5363 onChangeSelection([]);
5364 },
5365 "aria-label": (0, import_i18n22.__)("Deselect all")
5366 }
5367 );
5368 }
5369 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5370 import_components14.CheckboxControl,
5371 {
5372 className: "dataviews-view-table-selection-checkbox",
5373 checked: areAllSelected,
5374 indeterminate: !areAllSelected && !!selectedItems.length,
5375 onChange: () => {
5376 if (areAllSelected) {
5377 onChangeSelection(
5378 selection.filter(
5379 (id) => !data.some(
5380 (item) => id === getItemId(item)
5381 )
5382 )
5383 );
5384 } else {
5385 const selectionSet = /* @__PURE__ */ new Set([
5386 ...selection,
5387 ...data.map((item) => getItemId(item))
5388 ]);
5389 onChangeSelection(Array.from(selectionSet));
5390 }
5391 },
5392 "aria-label": areAllSelected ? (0, import_i18n22.__)("Deselect all") : (0, import_i18n22.__)("Select all")
5393 }
5394 );
5395 }
5396 function ActionButtons({
5397 actions,
5398 items,
5399 selection
5400 }) {
5401 const registry = (0, import_data5.useRegistry)();
5402 const [actionInProgress, setActionInProgress] = (0, import_element20.useState)(
5403 null
5404 );
5405 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(Stack, { direction: "row", gap: "xs", children: actions.map((action) => {
5406 if (!("callback" in action)) {
5407 return null;
5408 }
5409 const { id, label, icon, isPrimary, callback } = action;
5410 const _label = typeof label === "string" ? label : label(items);
5411 const variant = isPrimary ? "primary" : "tertiary";
5412 const isInProgress = id === actionInProgress;
5413 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5414 import_components14.Button,
5415 {
5416 accessibleWhenDisabled: true,
5417 icon,
5418 disabled: isInProgress || !selection?.length,
5419 isBusy: isInProgress,
5420 onClick: async () => {
5421 setActionInProgress(id);
5422 await callback(items, {
5423 registry
5424 });
5425 setActionInProgress(null);
5426 },
5427 size: "compact",
5428 variant,
5429 children: _label
5430 },
5431 id
5432 );
5433 }) });
5434 }
5435 function DataViewsPickerFooter() {
5436 const {
5437 data,
5438 selection,
5439 onChangeSelection,
5440 getItemId,
5441 actions = EMPTY_ARRAY2,
5442 paginationInfo,
5443 view
5444 } = (0, import_element20.useContext)(dataviews_context_default);
5445 const isMultiselect = useIsMultiselectPicker(actions);
5446 const message2 = getFooterMessage(
5447 selection.length,
5448 data.length,
5449 paginationInfo.totalItems,
5450 !!view.infiniteScrollEnabled
5451 );
5452 const selectedItems = (0, import_element20.useMemo)(
5453 () => data.filter((item) => selection.includes(getItemId(item))),
5454 [selection, getItemId, data]
5455 );
5456 return /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(
5457 Stack,
5458 {
5459 direction: "row",
5460 justify: "space-between",
5461 align: "center",
5462 className: "dataviews-footer",
5463 gap: "sm",
5464 children: [
5465 /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(
5466 Stack,
5467 {
5468 direction: "row",
5469 className: "dataviews-picker-footer__bulk-selection",
5470 gap: "md",
5471 align: "center",
5472 children: [
5473 isMultiselect && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5474 BulkSelectionCheckbox2,
5475 {
5476 selection,
5477 selectedItems,
5478 onChangeSelection,
5479 data,
5480 getItemId,
5481 disableSelectAll: !!view.infiniteScrollEnabled
5482 }
5483 ),
5484 /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("span", { className: "dataviews-bulk-actions-footer__item-count", children: message2 })
5485 ]
5486 }
5487 ),
5488 /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(dataviews_pagination_default, {}),
5489 Boolean(actions?.length) && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("div", { className: "dataviews-picker-footer__actions", children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5490 ActionButtons,
5491 {
5492 actions,
5493 items: selectedItems,
5494 selection
5495 }
5496 ) })
5497 ]
5498 }
5499 );
5500 }
5501
5502 // packages/dataviews/build-module/components/dataviews-layouts/picker-grid/index.mjs
5503 var import_jsx_runtime49 = __toESM(require_jsx_runtime(), 1);
5504 var { Badge: Badge2 } = unlock(import_components15.privateApis);
5505 function GridItem3({
5506 view,
5507 multiselect,
5508 selection,
5509 onChangeSelection,
5510 getItemId,
5511 item,
5512 mediaField,
5513 titleField,
5514 descriptionField: descriptionField2,
5515 regularFields,
5516 badgeFields,
5517 config,
5518 posinset,
5519 setsize
5520 }) {
5521 const { showTitle = true, showMedia = true, showDescription = true } = view;
5522 const id = getItemId(item);
5523 const elementRef = (0, import_element21.useRef)(null);
5524 const isSelected2 = selection.includes(id);
5525 const setElementRef = (element) => {
5526 elementRef.current = element;
5527 };
5528 useIntersectionObserver(elementRef, posinset);
5529 const renderedMediaField = mediaField?.render ? /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5530 mediaField.render,
5531 {
5532 item,
5533 field: mediaField,
5534 config
5535 }
5536 ) : null;
5537 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(titleField.render, { item, field: titleField }) : null;
5538 return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5539 import_components15.Composite.Item,
5540 {
5541 ref: setElementRef,
5542 "aria-label": titleField ? titleField.getValue({ item }) || (0, import_i18n23.__)("(no title)") : void 0,
5543 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack, { direction: "column", children, ...props }),
5544 role: "option",
5545 "aria-posinset": posinset,
5546 "aria-setsize": setsize,
5547 className: clsx_default("dataviews-view-picker-grid__card", {
5548 "is-selected": isSelected2
5549 }),
5550 "aria-selected": isSelected2,
5551 onClick: () => {
5552 if (isSelected2) {
5553 onChangeSelection(
5554 selection.filter((itemId) => id !== itemId)
5555 );
5556 } else {
5557 const newSelection = multiselect ? [...selection, id] : [id];
5558 onChangeSelection(newSelection);
5559 }
5560 },
5561 children: [
5562 showMedia && renderedMediaField && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { className: "dataviews-view-picker-grid__media", children: renderedMediaField }),
5563 showMedia && renderedMediaField && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5564 DataViewsSelectionCheckbox,
5565 {
5566 item,
5567 selection,
5568 onChangeSelection,
5569 getItemId,
5570 titleField,
5571 disabled: false,
5572 "aria-hidden": true,
5573 tabIndex: -1
5574 }
5575 ),
5576 showTitle && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5577 Stack,
5578 {
5579 direction: "row",
5580 justify: "space-between",
5581 className: "dataviews-view-picker-grid__title-actions",
5582 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { className: "dataviews-view-picker-grid__title-field dataviews-title-field", children: renderedTitleField })
5583 }
5584 ),
5585 /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(Stack, { direction: "column", gap: "xs", children: [
5586 showDescription && descriptionField2?.render && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5587 descriptionField2.render,
5588 {
5589 item,
5590 field: descriptionField2
5591 }
5592 ),
5593 !!badgeFields?.length && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5594 Stack,
5595 {
5596 direction: "row",
5597 className: "dataviews-view-picker-grid__badge-fields",
5598 gap: "sm",
5599 wrap: "wrap",
5600 align: "top",
5601 justify: "flex-start",
5602 children: badgeFields.map((field) => {
5603 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5604 Badge2,
5605 {
5606 className: "dataviews-view-picker-grid__field-value",
5607 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5608 field.render,
5609 {
5610 item,
5611 field
5612 }
5613 )
5614 },
5615 field.id
5616 );
5617 })
5618 }
5619 ),
5620 !!regularFields?.length && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5621 Stack,
5622 {
5623 direction: "column",
5624 className: "dataviews-view-picker-grid__fields",
5625 gap: "xs",
5626 children: regularFields.map((field) => {
5627 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5628 import_components15.Flex,
5629 {
5630 className: "dataviews-view-picker-grid__field",
5631 gap: 1,
5632 justify: "flex-start",
5633 expanded: true,
5634 style: { height: "auto" },
5635 direction: "row",
5636 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(import_jsx_runtime49.Fragment, { children: [
5637 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_components15.FlexItem, { className: "dataviews-view-picker-grid__field-name", children: field.header }),
5638 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5639 import_components15.FlexItem,
5640 {
5641 className: "dataviews-view-picker-grid__field-value",
5642 style: { maxHeight: "none" },
5643 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5644 field.render,
5645 {
5646 item,
5647 field
5648 }
5649 )
5650 }
5651 )
5652 ] })
5653 },
5654 field.id
5655 );
5656 })
5657 }
5658 )
5659 ] })
5660 ]
5661 },
5662 id
5663 );
5664 }
5665 function GridGroup({
5666 groupName,
5667 groupField,
5668 showLabel = true,
5669 children
5670 }) {
5671 const headerId = (0, import_compose6.useInstanceId)(
5672 GridGroup,
5673 "dataviews-view-picker-grid-group__header"
5674 );
5675 return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5676 Stack,
5677 {
5678 direction: "column",
5679 gap: "sm",
5680 role: "group",
5681 "aria-labelledby": headerId,
5682 children: [
5683 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5684 "h3",
5685 {
5686 className: "dataviews-view-picker-grid-group__header",
5687 id: headerId,
5688 children: showLabel ? (0, import_i18n23.sprintf)(
5689 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
5690 (0, import_i18n23.__)("%1$s: %2$s"),
5691 groupField.label,
5692 groupName
5693 ) : groupName
5694 }
5695 ),
5696 children
5697 ]
5698 },
5699 groupName
5700 );
5701 }
5702 function ViewPickerGrid({
5703 actions,
5704 data,
5705 fields,
5706 getItemId,
5707 isLoading,
5708 onChangeSelection,
5709 selection,
5710 view,
5711 className,
5712 empty
5713 }) {
5714 const { resizeObserverRef, paginationInfo, itemListLabel } = (0, import_element21.useContext)(dataviews_context_default);
5715 const titleField = fields.find(
5716 (field) => field.id === view?.titleField
5717 );
5718 const mediaField = fields.find(
5719 (field) => field.id === view?.mediaField
5720 );
5721 const descriptionField2 = fields.find(
5722 (field) => field.id === view?.descriptionField
5723 );
5724 const otherFields = view.fields ?? [];
5725 const { regularFields, badgeFields } = otherFields.reduce(
5726 (accumulator, fieldId) => {
5727 const field = fields.find((f2) => f2.id === fieldId);
5728 if (!field) {
5729 return accumulator;
5730 }
5731 const key = view.layout?.badgeFields?.includes(fieldId) ? "badgeFields" : "regularFields";
5732 accumulator[key].push(field);
5733 return accumulator;
5734 },
5735 { regularFields: [], badgeFields: [] }
5736 );
5737 const hasData = !!data?.length;
5738 const usedPreviewSize = view.layout?.previewSize;
5739 const isMultiselect = useIsMultiselectPicker(actions);
5740 const size = "900px";
5741 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
5742 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
5743 const isInfiniteScroll = (view.infiniteScrollEnabled && !dataByGroup) ?? false;
5744 const currentPage = view?.page ?? 1;
5745 const perPage = view?.perPage ?? 0;
5746 const setSize = isInfiniteScroll ? paginationInfo?.totalItems : void 0;
5747 const gridColumns = useGridColumns();
5748 const placeholdersNeeded = usePlaceholdersNeeded(
5749 data,
5750 isInfiniteScroll,
5751 gridColumns
5752 );
5753 return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(import_jsx_runtime49.Fragment, {
5754 // Render multiple groups.
5755 children: [
5756 hasData && groupField && dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5757 import_components15.Composite,
5758 {
5759 virtualFocus: true,
5760 orientation: "horizontal",
5761 role: "listbox",
5762 "aria-multiselectable": isMultiselect,
5763 className: clsx_default(
5764 "dataviews-view-picker-grid",
5765 className,
5766 {
5767 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
5768 view.layout.density
5769 )
5770 }
5771 ),
5772 "aria-label": itemListLabel,
5773 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5774 Stack,
5775 {
5776 direction: "column",
5777 gap: "lg",
5778 children,
5779 ...props
5780 }
5781 ),
5782 children: Array.from(dataByGroup.entries()).map(
5783 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5784 GridGroup,
5785 {
5786 groupName,
5787 groupField,
5788 showLabel: view.groupBy?.showLabel !== false,
5789 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5790 GridItems,
5791 {
5792 previewSize: usedPreviewSize,
5793 style: {
5794 gridTemplateColumns: usedPreviewSize && `repeat(auto-fill, minmax(${usedPreviewSize}px, 1fr))`
5795 },
5796 "aria-busy": isLoading,
5797 ref: resizeObserverRef,
5798 children: groupItems.map((item) => {
5799 const posInSet = item.position ?? (currentPage - 1) * perPage + data.indexOf(item) + 1;
5800 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5801 GridItem3,
5802 {
5803 view,
5804 multiselect: isMultiselect,
5805 selection,
5806 onChangeSelection,
5807 getItemId,
5808 item,
5809 mediaField,
5810 titleField,
5811 descriptionField: descriptionField2,
5812 regularFields,
5813 badgeFields,
5814 config: {
5815 sizes: size
5816 },
5817 posinset: posInSet,
5818 setsize: setSize
5819 },
5820 getItemId(item)
5821 );
5822 })
5823 }
5824 )
5825 },
5826 groupName
5827 )
5828 )
5829 }
5830 ),
5831 // Render a single grid with all data.
5832 hasData && !dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5833 import_components15.Composite,
5834 {
5835 render: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5836 GridItems,
5837 {
5838 className: clsx_default(
5839 "dataviews-view-picker-grid",
5840 className,
5841 {
5842 [`has-${view.layout?.density}-density`]: view.layout?.density && [
5843 "compact",
5844 "comfortable"
5845 ].includes(view.layout.density)
5846 }
5847 ),
5848 previewSize: usedPreviewSize,
5849 "aria-busy": isLoading,
5850 ref: resizeObserverRef
5851 }
5852 ),
5853 virtualFocus: true,
5854 orientation: "horizontal",
5855 role: "listbox",
5856 "aria-multiselectable": isMultiselect,
5857 "aria-label": itemListLabel,
5858 children: [
5859 Array.from({ length: placeholdersNeeded }).map(
5860 (_, index) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5861 import_components15.Composite.Item,
5862 {
5863 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5864 Stack,
5865 {
5866 direction: "column",
5867 children,
5868 ...props
5869 }
5870 ),
5871 role: "option",
5872 "aria-hidden": true,
5873 tabIndex: -1,
5874 className: "dataviews-view-picker-grid__card dataviews-view-picker-grid__placeholder"
5875 },
5876 `placeholder-${index}`
5877 )
5878 ),
5879 data.map((item) => {
5880 const posinset = item.position;
5881 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5882 GridItem3,
5883 {
5884 view,
5885 multiselect: isMultiselect,
5886 selection,
5887 onChangeSelection,
5888 getItemId,
5889 item,
5890 mediaField,
5891 titleField,
5892 descriptionField: descriptionField2,
5893 regularFields,
5894 badgeFields,
5895 config: {
5896 sizes: size
5897 },
5898 posinset,
5899 setsize: setSize
5900 },
5901 getItemId(item)
5902 );
5903 })
5904 ]
5905 }
5906 ),
5907 // Render empty state.
5908 !hasData && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5909 "div",
5910 {
5911 className: clsx_default({
5912 "dataviews-loading": isLoading,
5913 "dataviews-no-results": !isLoading
5914 }),
5915 children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_components15.Spinner, {}) }) : empty
5916 }
5917 ),
5918 hasData && isLoading && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_components15.Spinner, {}) })
5919 ]
5920 });
5921 }
5922 var picker_grid_default = ViewPickerGrid;
5923
5924 // packages/dataviews/build-module/components/dataviews-layouts/picker-table/index.mjs
5925 var import_i18n24 = __toESM(require_i18n(), 1);
5926 var import_components16 = __toESM(require_components(), 1);
5927 var import_element22 = __toESM(require_element(), 1);
5928 var import_jsx_runtime50 = __toESM(require_jsx_runtime(), 1);
5929 function TableColumnField2({
5930 item,
5931 fields,
5932 column,
5933 align
5934 }) {
5935 const field = fields.find((f2) => f2.id === column);
5936 if (!field) {
5937 return null;
5938 }
5939 const className = clsx_default("dataviews-view-table__cell-content-wrapper", {
5940 "dataviews-view-table__cell-align-end": align === "end",
5941 "dataviews-view-table__cell-align-center": align === "center"
5942 });
5943 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(field.render, { item, field }) });
5944 }
5945 function TableRow2({
5946 item,
5947 fields,
5948 id,
5949 view,
5950 titleField,
5951 mediaField,
5952 descriptionField: descriptionField2,
5953 selection,
5954 getItemId,
5955 onChangeSelection,
5956 multiselect,
5957 posinset
5958 }) {
5959 const { paginationInfo } = (0, import_element22.useContext)(dataviews_context_default);
5960 const isSelected2 = selection.includes(id);
5961 const [isHovered, setIsHovered] = (0, import_element22.useState)(false);
5962 const elementRef = (0, import_element22.useRef)(null);
5963 const setElementRef = (element) => {
5964 elementRef.current = element;
5965 };
5966 useIntersectionObserver(elementRef, posinset);
5967 const {
5968 showTitle = true,
5969 showMedia = true,
5970 showDescription = true,
5971 infiniteScrollEnabled
5972 } = view;
5973 const handleMouseEnter = () => {
5974 setIsHovered(true);
5975 };
5976 const handleMouseLeave = () => {
5977 setIsHovered(false);
5978 };
5979 const columns = view.fields ?? [];
5980 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
5981 return /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
5982 import_components16.Composite.Item,
5983 {
5984 ref: setElementRef,
5985 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
5986 "tr",
5987 {
5988 className: clsx_default("dataviews-view-table__row", {
5989 "is-selected": isSelected2,
5990 "is-hovered": isHovered
5991 }),
5992 onMouseEnter: handleMouseEnter,
5993 onMouseLeave: handleMouseLeave,
5994 children,
5995 ...props
5996 }
5997 ),
5998 "aria-selected": isSelected2,
5999 "aria-setsize": paginationInfo.totalItems || void 0,
6000 "aria-posinset": posinset,
6001 role: infiniteScrollEnabled ? "article" : "option",
6002 onClick: () => {
6003 if (isSelected2) {
6004 onChangeSelection(
6005 selection.filter((itemId) => id !== itemId)
6006 );
6007 } else {
6008 const newSelection = multiselect ? [...selection, id] : [id];
6009 onChangeSelection(newSelection);
6010 }
6011 },
6012 children: [
6013 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6014 "td",
6015 {
6016 className: "dataviews-view-table__checkbox-column",
6017 role: "presentation",
6018 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("div", { className: "dataviews-view-table__cell-content-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6019 DataViewsSelectionCheckbox,
6020 {
6021 item,
6022 selection,
6023 onChangeSelection,
6024 getItemId,
6025 titleField,
6026 disabled: false,
6027 "aria-hidden": true,
6028 tabIndex: -1
6029 }
6030 ) })
6031 }
6032 ),
6033 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("td", { role: "presentation", children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6034 column_primary_default,
6035 {
6036 item,
6037 titleField: showTitle ? titleField : void 0,
6038 mediaField: showMedia ? mediaField : void 0,
6039 descriptionField: showDescription ? descriptionField2 : void 0,
6040 isItemClickable: () => false
6041 }
6042 ) }),
6043 columns.map((column) => {
6044 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
6045 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6046 "td",
6047 {
6048 style: {
6049 width,
6050 maxWidth,
6051 minWidth
6052 },
6053 role: "presentation",
6054 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6055 TableColumnField2,
6056 {
6057 fields,
6058 item,
6059 column,
6060 align
6061 }
6062 )
6063 },
6064 column
6065 );
6066 })
6067 ]
6068 },
6069 id
6070 );
6071 }
6072 function ViewPickerTable({
6073 actions,
6074 data,
6075 fields,
6076 getItemId,
6077 isLoading = false,
6078 onChangeView,
6079 onChangeSelection,
6080 selection,
6081 setOpenedFilter,
6082 view,
6083 className,
6084 empty
6085 }) {
6086 const headerMenuRefs = (0, import_element22.useRef)(/* @__PURE__ */ new Map());
6087 const headerMenuToFocusRef = (0, import_element22.useRef)(void 0);
6088 const [nextHeaderMenuToFocus, setNextHeaderMenuToFocus] = (0, import_element22.useState)();
6089 const isMultiselect = useIsMultiselectPicker(actions) ?? false;
6090 (0, import_element22.useEffect)(() => {
6091 if (headerMenuToFocusRef.current) {
6092 headerMenuToFocusRef.current.focus();
6093 headerMenuToFocusRef.current = void 0;
6094 }
6095 });
6096 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
6097 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
6098 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
6099 const tableNoticeId = (0, import_element22.useId)();
6100 if (nextHeaderMenuToFocus) {
6101 headerMenuToFocusRef.current = nextHeaderMenuToFocus;
6102 setNextHeaderMenuToFocus(void 0);
6103 return;
6104 }
6105 const onHide = (field) => {
6106 const hidden = headerMenuRefs.current.get(field.id);
6107 const fallback = hidden ? headerMenuRefs.current.get(hidden.fallback) : void 0;
6108 setNextHeaderMenuToFocus(fallback?.node);
6109 };
6110 const hasData = !!data?.length;
6111 const titleField = fields.find((field) => field.id === view.titleField);
6112 const mediaField = fields.find((field) => field.id === view.mediaField);
6113 const descriptionField2 = fields.find(
6114 (field) => field.id === view.descriptionField
6115 );
6116 const { showTitle = true, showMedia = true, showDescription = true } = view;
6117 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
6118 const columns = view.fields ?? [];
6119 const headerMenuRef = (column, index) => (node) => {
6120 if (node) {
6121 headerMenuRefs.current.set(column, {
6122 node,
6123 fallback: columns[index > 0 ? index - 1 : 1]
6124 });
6125 } else {
6126 headerMenuRefs.current.delete(column);
6127 }
6128 };
6129 return /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(import_jsx_runtime50.Fragment, { children: [
6130 /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6131 "table",
6132 {
6133 className: clsx_default(
6134 "dataviews-view-table",
6135 "dataviews-view-picker-table",
6136 className,
6137 {
6138 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
6139 view.layout.density
6140 )
6141 }
6142 ),
6143 "aria-busy": isLoading,
6144 "aria-describedby": tableNoticeId,
6145 role: isInfiniteScroll ? "feed" : "listbox",
6146 children: [
6147 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("thead", { role: "presentation", children: /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6148 "tr",
6149 {
6150 className: "dataviews-view-table__row",
6151 role: "presentation",
6152 children: [
6153 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("th", { className: "dataviews-view-table__checkbox-column", children: isMultiselect && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6154 BulkSelectionCheckbox,
6155 {
6156 selection,
6157 onChangeSelection,
6158 data,
6159 actions,
6160 getItemId,
6161 disableSelectAll: isInfiniteScroll
6162 }
6163 ) }),
6164 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("th", { children: titleField && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6165 column_header_menu_default,
6166 {
6167 ref: headerMenuRef(
6168 titleField.id,
6169 0
6170 ),
6171 fieldId: titleField.id,
6172 view,
6173 fields,
6174 onChangeView,
6175 onHide,
6176 setOpenedFilter,
6177 canMove: false
6178 }
6179 ) }),
6180 columns.map((column, index) => {
6181 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
6182 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6183 "th",
6184 {
6185 style: {
6186 width,
6187 maxWidth,
6188 minWidth,
6189 textAlign: align
6190 },
6191 "aria-sort": view.sort?.direction && view.sort?.field === column ? sortValues[view.sort.direction] : void 0,
6192 scope: "col",
6193 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6194 column_header_menu_default,
6195 {
6196 ref: headerMenuRef(column, index),
6197 fieldId: column,
6198 view,
6199 fields,
6200 onChangeView,
6201 onHide,
6202 setOpenedFilter,
6203 canMove: view.layout?.enableMoving ?? true
6204 }
6205 )
6206 },
6207 column
6208 );
6209 })
6210 ]
6211 }
6212 ) }),
6213 hasData && groupField && dataByGroup ? Array.from(dataByGroup.entries()).map(
6214 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6215 import_components16.Composite,
6216 {
6217 virtualFocus: true,
6218 orientation: "vertical",
6219 render: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("tbody", { role: "group" }),
6220 children: [
6221 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6222 "tr",
6223 {
6224 className: "dataviews-view-table__group-header-row",
6225 role: "presentation",
6226 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6227 "td",
6228 {
6229 colSpan: columns.length + (hasPrimaryColumn ? 1 : 0) + 1,
6230 className: "dataviews-view-table__group-header-cell",
6231 role: "presentation",
6232 children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n24.sprintf)(
6233 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
6234 (0, import_i18n24.__)("%1$s: %2$s"),
6235 groupField.label,
6236 groupName
6237 )
6238 }
6239 )
6240 }
6241 ),
6242 groupItems.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6243 TableRow2,
6244 {
6245 item,
6246 fields,
6247 id: getItemId(item) || index.toString(),
6248 view,
6249 titleField,
6250 mediaField,
6251 descriptionField: descriptionField2,
6252 selection,
6253 getItemId,
6254 onChangeSelection,
6255 multiselect: isMultiselect
6256 },
6257 getItemId(item)
6258 ))
6259 ]
6260 },
6261 `group-${groupName}`
6262 )
6263 ) : /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6264 import_components16.Composite,
6265 {
6266 render: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("tbody", { role: "presentation" }),
6267 virtualFocus: true,
6268 orientation: "vertical",
6269 children: hasData && data.map((item, index) => {
6270 const itemId = getItemId(item);
6271 const posinset = item.position;
6272 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6273 TableRow2,
6274 {
6275 item,
6276 fields,
6277 id: itemId || index.toString(),
6278 view,
6279 titleField,
6280 mediaField,
6281 descriptionField: descriptionField2,
6282 selection,
6283 getItemId,
6284 onChangeSelection,
6285 multiselect: isMultiselect,
6286 posinset
6287 },
6288 itemId
6289 );
6290 })
6291 }
6292 )
6293 ]
6294 }
6295 ),
6296 /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6297 "div",
6298 {
6299 className: clsx_default({
6300 "dataviews-loading": isLoading,
6301 "dataviews-no-results": !hasData && !isLoading
6302 }),
6303 id: tableNoticeId,
6304 children: [
6305 !hasData && (isLoading ? /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(import_components16.Spinner, {}) }) : empty),
6306 hasData && isLoading && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(import_components16.Spinner, {}) })
6307 ]
6308 }
6309 )
6310 ] });
6311 }
6312 var picker_table_default = ViewPickerTable;
6313
6314 // packages/dataviews/build-module/components/dataviews-layouts/utils/density-picker.mjs
6315 var import_components17 = __toESM(require_components(), 1);
6316 var import_i18n25 = __toESM(require_i18n(), 1);
6317 var import_element23 = __toESM(require_element(), 1);
6318 var import_jsx_runtime51 = __toESM(require_jsx_runtime(), 1);
6319 function DensityPicker() {
6320 const context = (0, import_element23.useContext)(dataviews_context_default);
6321 const view = context.view;
6322 return /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)(
6323 import_components17.__experimentalToggleGroupControl,
6324 {
6325 size: "__unstable-large",
6326 label: (0, import_i18n25.__)("Density"),
6327 value: view.layout?.density || "balanced",
6328 onChange: (value) => {
6329 context.onChangeView({
6330 ...view,
6331 layout: {
6332 ...view.layout,
6333 density: value
6334 }
6335 });
6336 },
6337 isBlock: true,
6338 children: [
6339 /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
6340 import_components17.__experimentalToggleGroupControlOption,
6341 {
6342 value: "comfortable",
6343 label: (0, import_i18n25._x)(
6344 "Comfortable",
6345 "Density option for DataView layout"
6346 )
6347 },
6348 "comfortable"
6349 ),
6350 /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
6351 import_components17.__experimentalToggleGroupControlOption,
6352 {
6353 value: "balanced",
6354 label: (0, import_i18n25._x)("Balanced", "Density option for DataView layout")
6355 },
6356 "balanced"
6357 ),
6358 /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
6359 import_components17.__experimentalToggleGroupControlOption,
6360 {
6361 value: "compact",
6362 label: (0, import_i18n25._x)("Compact", "Density option for DataView layout")
6363 },
6364 "compact"
6365 )
6366 ]
6367 }
6368 );
6369 }
6370
6371 // packages/dataviews/build-module/components/dataviews-layouts/utils/preview-size-picker.mjs
6372 var import_components18 = __toESM(require_components(), 1);
6373 var import_i18n26 = __toESM(require_i18n(), 1);
6374 var import_element24 = __toESM(require_element(), 1);
6375 var import_jsx_runtime52 = __toESM(require_jsx_runtime(), 1);
6376 var imageSizes2 = [
6377 {
6378 value: 120,
6379 breakpoint: 1
6380 },
6381 {
6382 value: 170,
6383 breakpoint: 1
6384 },
6385 {
6386 value: 230,
6387 breakpoint: 1
6388 },
6389 {
6390 value: 290,
6391 breakpoint: 1112
6392 // at minimum image width, 4 images display at this container size
6393 },
6394 {
6395 value: 350,
6396 breakpoint: 1636
6397 // at minimum image width, 6 images display at this container size
6398 },
6399 {
6400 value: 430,
6401 breakpoint: 588
6402 // at minimum image width, 2 images display at this container size
6403 }
6404 ];
6405 function PreviewSizePicker() {
6406 const context = (0, import_element24.useContext)(dataviews_context_default);
6407 const view = context.view;
6408 const breakValues = imageSizes2.filter((size) => {
6409 return context.containerWidth >= size.breakpoint;
6410 });
6411 const layoutPreviewSize = view.layout?.previewSize ?? 230;
6412 const previewSizeToUse = breakValues.map((size, index) => ({ ...size, index })).filter((size) => size.value <= layoutPreviewSize).sort((a2, b2) => b2.value - a2.value)[0]?.index ?? 0;
6413 const marks = breakValues.map((size, index) => {
6414 return {
6415 value: index
6416 };
6417 });
6418 return /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(
6419 import_components18.RangeControl,
6420 {
6421 __next40pxDefaultSize: true,
6422 showTooltip: false,
6423 label: (0, import_i18n26.__)("Preview size"),
6424 value: previewSizeToUse,
6425 min: 0,
6426 max: breakValues.length - 1,
6427 withInputField: false,
6428 onChange: (value = 0) => {
6429 context.onChangeView({
6430 ...view,
6431 layout: {
6432 ...view.layout,
6433 previewSize: breakValues[value].value
6434 }
6435 });
6436 },
6437 step: 1,
6438 marks
6439 }
6440 );
6441 }
6442
6443 // packages/dataviews/build-module/components/dataviews-layouts/utils/grid-config-options.mjs
6444 var import_jsx_runtime53 = __toESM(require_jsx_runtime(), 1);
6445 function GridConfigOptions() {
6446 return /* @__PURE__ */ (0, import_jsx_runtime53.jsxs)(import_jsx_runtime53.Fragment, { children: [
6447 /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(DensityPicker, {}),
6448 /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(PreviewSizePicker, {})
6449 ] });
6450 }
6451
6452 // packages/dataviews/build-module/components/dataviews-layouts/index.mjs
6453 var VIEW_LAYOUTS = [
6454 {
6455 type: LAYOUT_TABLE,
6456 label: (0, import_i18n27.__)("Table"),
6457 component: table_default,
6458 icon: block_table_default,
6459 viewConfigOptions: DensityPicker
6460 },
6461 {
6462 type: LAYOUT_GRID,
6463 label: (0, import_i18n27.__)("Grid"),
6464 component: grid_default,
6465 icon: category_default,
6466 viewConfigOptions: GridConfigOptions
6467 },
6468 {
6469 type: LAYOUT_LIST,
6470 label: (0, import_i18n27.__)("List"),
6471 component: ViewList,
6472 icon: (0, import_i18n27.isRTL)() ? format_list_bullets_rtl_default : format_list_bullets_default,
6473 viewConfigOptions: DensityPicker
6474 },
6475 {
6476 type: LAYOUT_ACTIVITY,
6477 label: (0, import_i18n27.__)("Activity"),
6478 component: ViewActivity,
6479 icon: scheduled_default,
6480 viewConfigOptions: DensityPicker
6481 },
6482 {
6483 type: LAYOUT_PICKER_GRID,
6484 label: (0, import_i18n27.__)("Grid"),
6485 component: picker_grid_default,
6486 icon: category_default,
6487 viewConfigOptions: GridConfigOptions,
6488 isPicker: true
6489 },
6490 {
6491 type: LAYOUT_PICKER_TABLE,
6492 label: (0, import_i18n27.__)("Table"),
6493 component: picker_table_default,
6494 icon: block_table_default,
6495 viewConfigOptions: DensityPicker,
6496 isPicker: true
6497 }
6498 ];
6499
6500 // packages/dataviews/build-module/components/dataviews-filters/filters.mjs
6501 var import_element32 = __toESM(require_element(), 1);
6502
6503 // packages/dataviews/build-module/components/dataviews-filters/filter.mjs
6504 var import_components21 = __toESM(require_components(), 1);
6505 var import_i18n30 = __toESM(require_i18n(), 1);
6506 var import_element29 = __toESM(require_element(), 1);
6507
6508 // node_modules/@ariakit/core/esm/__chunks/XMCVU3LR.js
6509 function noop2(..._) {
6510 }
6511 function applyState(argument, currentValue) {
6512 if (isUpdater(argument)) {
6513 const value = isLazyValue(currentValue) ? currentValue() : currentValue;
6514 return argument(value);
6515 }
6516 return argument;
6517 }
6518 function isUpdater(argument) {
6519 return typeof argument === "function";
6520 }
6521 function isLazyValue(value) {
6522 return typeof value === "function";
6523 }
6524 function hasOwnProperty(object, prop) {
6525 if (typeof Object.hasOwn === "function") {
6526 return Object.hasOwn(object, prop);
6527 }
6528 return Object.prototype.hasOwnProperty.call(object, prop);
6529 }
6530 function chain(...fns) {
6531 return (...args) => {
6532 for (const fn of fns) {
6533 if (typeof fn === "function") {
6534 fn(...args);
6535 }
6536 }
6537 };
6538 }
6539 function normalizeString(str) {
6540 return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
6541 }
6542 function omit(object, keys) {
6543 const result = { ...object };
6544 for (const key of keys) {
6545 if (hasOwnProperty(result, key)) {
6546 delete result[key];
6547 }
6548 }
6549 return result;
6550 }
6551 function pick(object, paths) {
6552 const result = {};
6553 for (const key of paths) {
6554 if (hasOwnProperty(object, key)) {
6555 result[key] = object[key];
6556 }
6557 }
6558 return result;
6559 }
6560 function identity(value) {
6561 return value;
6562 }
6563 function invariant(condition, message2) {
6564 if (condition) return;
6565 if (typeof message2 !== "string") throw new Error("Invariant failed");
6566 throw new Error(message2);
6567 }
6568 function getKeys(obj) {
6569 return Object.keys(obj);
6570 }
6571 function isFalsyBooleanCallback(booleanOrCallback, ...args) {
6572 const result = typeof booleanOrCallback === "function" ? booleanOrCallback(...args) : booleanOrCallback;
6573 if (result == null) return false;
6574 return !result;
6575 }
6576 function disabledFromProps(props) {
6577 return props.disabled || props["aria-disabled"] === true || props["aria-disabled"] === "true";
6578 }
6579 function removeUndefinedValues(obj) {
6580 const result = {};
6581 for (const key in obj) {
6582 if (obj[key] !== void 0) {
6583 result[key] = obj[key];
6584 }
6585 }
6586 return result;
6587 }
6588 function defaultValue(...values) {
6589 for (const value of values) {
6590 if (value !== void 0) return value;
6591 }
6592 return void 0;
6593 }
6594
6595 // node_modules/@ariakit/react-core/esm/__chunks/YXGXYGQX.js
6596 var import_react4 = __toESM(require_react(), 1);
6597 function setRef(ref, value) {
6598 if (typeof ref === "function") {
6599 ref(value);
6600 } else if (ref) {
6601 ref.current = value;
6602 }
6603 }
6604 function isValidElementWithRef(element) {
6605 if (!element) return false;
6606 if (!(0, import_react4.isValidElement)(element)) return false;
6607 if ("ref" in element.props) return true;
6608 if ("ref" in element) return true;
6609 return false;
6610 }
6611 function getRefProperty(element) {
6612 if (!isValidElementWithRef(element)) return null;
6613 const props = { ...element.props };
6614 return props.ref || element.ref;
6615 }
6616 function mergeProps2(base, overrides) {
6617 const props = { ...base };
6618 for (const key in overrides) {
6619 if (!hasOwnProperty(overrides, key)) continue;
6620 if (key === "className") {
6621 const prop = "className";
6622 props[prop] = base[prop] ? `${base[prop]} ${overrides[prop]}` : overrides[prop];
6623 continue;
6624 }
6625 if (key === "style") {
6626 const prop = "style";
6627 props[prop] = base[prop] ? { ...base[prop], ...overrides[prop] } : overrides[prop];
6628 continue;
6629 }
6630 const overrideValue = overrides[key];
6631 if (typeof overrideValue === "function" && key.startsWith("on")) {
6632 const baseValue = base[key];
6633 if (typeof baseValue === "function") {
6634 props[key] = (...args) => {
6635 overrideValue(...args);
6636 baseValue(...args);
6637 };
6638 continue;
6639 }
6640 }
6641 props[key] = overrideValue;
6642 }
6643 return props;
6644 }
6645
6646 // node_modules/@ariakit/core/esm/__chunks/3DNM6L6E.js
6647 var canUseDOM = checkIsBrowser();
6648 function checkIsBrowser() {
6649 var _a;
6650 return typeof window !== "undefined" && !!((_a = window.document) == null ? void 0 : _a.createElement);
6651 }
6652 function getDocument(node) {
6653 if (!node) return document;
6654 if ("self" in node) return node.document;
6655 return node.ownerDocument || document;
6656 }
6657 function getActiveElement(node, activeDescendant = false) {
6658 var _a;
6659 const { activeElement } = getDocument(node);
6660 if (!(activeElement == null ? void 0 : activeElement.nodeName)) {
6661 return null;
6662 }
6663 if (isFrame(activeElement) && ((_a = activeElement.contentDocument) == null ? void 0 : _a.body)) {
6664 return getActiveElement(
6665 activeElement.contentDocument.body,
6666 activeDescendant
6667 );
6668 }
6669 if (activeDescendant) {
6670 const id = activeElement.getAttribute("aria-activedescendant");
6671 if (id) {
6672 const element = getDocument(activeElement).getElementById(id);
6673 if (element) {
6674 return element;
6675 }
6676 }
6677 }
6678 return activeElement;
6679 }
6680 function contains(parent, child) {
6681 return parent === child || parent.contains(child);
6682 }
6683 function isFrame(element) {
6684 return element.tagName === "IFRAME";
6685 }
6686 function isButton(element) {
6687 const tagName = element.tagName.toLowerCase();
6688 if (tagName === "button") return true;
6689 if (tagName === "input" && element.type) {
6690 return buttonInputTypes.indexOf(element.type) !== -1;
6691 }
6692 return false;
6693 }
6694 var buttonInputTypes = [
6695 "button",
6696 "color",
6697 "file",
6698 "image",
6699 "reset",
6700 "submit"
6701 ];
6702 function isVisible(element) {
6703 if (typeof element.checkVisibility === "function") {
6704 return element.checkVisibility();
6705 }
6706 const htmlElement = element;
6707 return htmlElement.offsetWidth > 0 || htmlElement.offsetHeight > 0 || element.getClientRects().length > 0;
6708 }
6709 function isTextField(element) {
6710 try {
6711 const isTextInput = element instanceof HTMLInputElement && element.selectionStart !== null;
6712 const isTextArea = element.tagName === "TEXTAREA";
6713 return isTextInput || isTextArea || false;
6714 } catch (_error) {
6715 return false;
6716 }
6717 }
6718 function isTextbox(element) {
6719 return element.isContentEditable || isTextField(element);
6720 }
6721 function getTextboxValue(element) {
6722 if (isTextField(element)) {
6723 return element.value;
6724 }
6725 if (element.isContentEditable) {
6726 const range = getDocument(element).createRange();
6727 range.selectNodeContents(element);
6728 return range.toString();
6729 }
6730 return "";
6731 }
6732 function getTextboxSelection(element) {
6733 let start = 0;
6734 let end = 0;
6735 if (isTextField(element)) {
6736 start = element.selectionStart || 0;
6737 end = element.selectionEnd || 0;
6738 } else if (element.isContentEditable) {
6739 const selection = getDocument(element).getSelection();
6740 if ((selection == null ? void 0 : selection.rangeCount) && selection.anchorNode && contains(element, selection.anchorNode) && selection.focusNode && contains(element, selection.focusNode)) {
6741 const range = selection.getRangeAt(0);
6742 const nextRange = range.cloneRange();
6743 nextRange.selectNodeContents(element);
6744 nextRange.setEnd(range.startContainer, range.startOffset);
6745 start = nextRange.toString().length;
6746 nextRange.setEnd(range.endContainer, range.endOffset);
6747 end = nextRange.toString().length;
6748 }
6749 }
6750 return { start, end };
6751 }
6752 function getPopupRole(element, fallback) {
6753 const allowedPopupRoles = ["dialog", "menu", "listbox", "tree", "grid"];
6754 const role = element == null ? void 0 : element.getAttribute("role");
6755 if (role && allowedPopupRoles.indexOf(role) !== -1) {
6756 return role;
6757 }
6758 return fallback;
6759 }
6760 function getScrollingElement(element) {
6761 if (!element) return null;
6762 const isScrollableOverflow = (overflow) => {
6763 if (overflow === "auto") return true;
6764 if (overflow === "scroll") return true;
6765 return false;
6766 };
6767 if (element.clientHeight && element.scrollHeight > element.clientHeight) {
6768 const { overflowY } = getComputedStyle(element);
6769 if (isScrollableOverflow(overflowY)) return element;
6770 } else if (element.clientWidth && element.scrollWidth > element.clientWidth) {
6771 const { overflowX } = getComputedStyle(element);
6772 if (isScrollableOverflow(overflowX)) return element;
6773 }
6774 return getScrollingElement(element.parentElement) || document.scrollingElement || document.body;
6775 }
6776 function setSelectionRange(element, ...args) {
6777 if (/text|search|password|tel|url/i.test(element.type)) {
6778 element.setSelectionRange(...args);
6779 }
6780 }
6781 function sortBasedOnDOMPosition(items, getElement) {
6782 const pairs = items.map((item, index) => [index, item]);
6783 let isOrderDifferent = false;
6784 pairs.sort(([indexA, a2], [indexB, b2]) => {
6785 const elementA = getElement(a2);
6786 const elementB = getElement(b2);
6787 if (elementA === elementB) return 0;
6788 if (!elementA || !elementB) return 0;
6789 if (isElementPreceding(elementA, elementB)) {
6790 if (indexA > indexB) {
6791 isOrderDifferent = true;
6792 }
6793 return -1;
6794 }
6795 if (indexA < indexB) {
6796 isOrderDifferent = true;
6797 }
6798 return 1;
6799 });
6800 if (isOrderDifferent) {
6801 return pairs.map(([_, item]) => item);
6802 }
6803 return items;
6804 }
6805 function isElementPreceding(a2, b2) {
6806 return Boolean(
6807 b2.compareDocumentPosition(a2) & Node.DOCUMENT_POSITION_PRECEDING
6808 );
6809 }
6810
6811 // node_modules/@ariakit/core/esm/__chunks/SNHYQNEZ.js
6812 function isTouchDevice() {
6813 return canUseDOM && !!navigator.maxTouchPoints;
6814 }
6815 function isApple() {
6816 if (!canUseDOM) return false;
6817 return /mac|iphone|ipad|ipod/i.test(navigator.platform);
6818 }
6819 function isSafari() {
6820 return canUseDOM && isApple() && /apple/i.test(navigator.vendor);
6821 }
6822 function isFirefox() {
6823 return canUseDOM && /firefox\//i.test(navigator.userAgent);
6824 }
6825
6826 // node_modules/@ariakit/core/esm/utils/events.js
6827 function isPortalEvent(event) {
6828 return Boolean(
6829 event.currentTarget && !contains(event.currentTarget, event.target)
6830 );
6831 }
6832 function isSelfTarget(event) {
6833 return event.target === event.currentTarget;
6834 }
6835 function isOpeningInNewTab(event) {
6836 const element = event.currentTarget;
6837 if (!element) return false;
6838 const isAppleDevice = isApple();
6839 if (isAppleDevice && !event.metaKey) return false;
6840 if (!isAppleDevice && !event.ctrlKey) return false;
6841 const tagName = element.tagName.toLowerCase();
6842 if (tagName === "a") return true;
6843 if (tagName === "button" && element.type === "submit") return true;
6844 if (tagName === "input" && element.type === "submit") return true;
6845 return false;
6846 }
6847 function isDownloading(event) {
6848 const element = event.currentTarget;
6849 if (!element) return false;
6850 const tagName = element.tagName.toLowerCase();
6851 if (!event.altKey) return false;
6852 if (tagName === "a") return true;
6853 if (tagName === "button" && element.type === "submit") return true;
6854 if (tagName === "input" && element.type === "submit") return true;
6855 return false;
6856 }
6857 function fireBlurEvent(element, eventInit) {
6858 const event = new FocusEvent("blur", eventInit);
6859 const defaultAllowed = element.dispatchEvent(event);
6860 const bubbleInit = { ...eventInit, bubbles: true };
6861 element.dispatchEvent(new FocusEvent("focusout", bubbleInit));
6862 return defaultAllowed;
6863 }
6864 function fireKeyboardEvent(element, type, eventInit) {
6865 const event = new KeyboardEvent(type, eventInit);
6866 return element.dispatchEvent(event);
6867 }
6868 function fireClickEvent(element, eventInit) {
6869 const event = new MouseEvent("click", eventInit);
6870 return element.dispatchEvent(event);
6871 }
6872 function isFocusEventOutside(event, container) {
6873 const containerElement = container || event.currentTarget;
6874 const relatedTarget = event.relatedTarget;
6875 return !relatedTarget || !contains(containerElement, relatedTarget);
6876 }
6877 function queueBeforeEvent(element, type, callback, timeout) {
6878 const createTimer = (callback2) => {
6879 if (timeout) {
6880 const timerId2 = setTimeout(callback2, timeout);
6881 return () => clearTimeout(timerId2);
6882 }
6883 const timerId = requestAnimationFrame(callback2);
6884 return () => cancelAnimationFrame(timerId);
6885 };
6886 const cancelTimer = createTimer(() => {
6887 element.removeEventListener(type, callSync, true);
6888 callback();
6889 });
6890 const callSync = () => {
6891 cancelTimer();
6892 callback();
6893 };
6894 element.addEventListener(type, callSync, { once: true, capture: true });
6895 return cancelTimer;
6896 }
6897 function addGlobalEventListener(type, listener, options, scope = window) {
6898 const children = [];
6899 try {
6900 scope.document.addEventListener(type, listener, options);
6901 for (const frame of Array.from(scope.frames)) {
6902 children.push(addGlobalEventListener(type, listener, options, frame));
6903 }
6904 } catch (e2) {
6905 }
6906 const removeEventListener = () => {
6907 try {
6908 scope.document.removeEventListener(type, listener, options);
6909 } catch (e2) {
6910 }
6911 for (const remove of children) {
6912 remove();
6913 }
6914 };
6915 return removeEventListener;
6916 }
6917
6918 // node_modules/@ariakit/react-core/esm/__chunks/KPHZR4MB.js
6919 var React5 = __toESM(require_react(), 1);
6920 var import_react5 = __toESM(require_react(), 1);
6921 var _React = { ...React5 };
6922 var useReactId = _React.useId;
6923 var useReactDeferredValue = _React.useDeferredValue;
6924 var useReactInsertionEffect = _React.useInsertionEffect;
6925 var useSafeLayoutEffect = canUseDOM ? import_react5.useLayoutEffect : import_react5.useEffect;
6926 function useInitialValue(value) {
6927 const [initialValue] = (0, import_react5.useState)(value);
6928 return initialValue;
6929 }
6930 function useLiveRef(value) {
6931 const ref = (0, import_react5.useRef)(value);
6932 useSafeLayoutEffect(() => {
6933 ref.current = value;
6934 });
6935 return ref;
6936 }
6937 function useEvent(callback) {
6938 const ref = (0, import_react5.useRef)(() => {
6939 throw new Error("Cannot call an event handler while rendering.");
6940 });
6941 if (useReactInsertionEffect) {
6942 useReactInsertionEffect(() => {
6943 ref.current = callback;
6944 });
6945 } else {
6946 ref.current = callback;
6947 }
6948 return (0, import_react5.useCallback)((...args) => {
6949 var _a;
6950 return (_a = ref.current) == null ? void 0 : _a.call(ref, ...args);
6951 }, []);
6952 }
6953 function useTransactionState(callback) {
6954 const [state, setState] = (0, import_react5.useState)(null);
6955 useSafeLayoutEffect(() => {
6956 if (state == null) return;
6957 if (!callback) return;
6958 let prevState = null;
6959 callback((prev) => {
6960 prevState = prev;
6961 return state;
6962 });
6963 return () => {
6964 callback(prevState);
6965 };
6966 }, [state, callback]);
6967 return [state, setState];
6968 }
6969 function useMergeRefs(...refs) {
6970 return (0, import_react5.useMemo)(() => {
6971 if (!refs.some(Boolean)) return;
6972 return (value) => {
6973 for (const ref of refs) {
6974 setRef(ref, value);
6975 }
6976 };
6977 }, refs);
6978 }
6979 function useId3(defaultId) {
6980 if (useReactId) {
6981 const reactId = useReactId();
6982 if (defaultId) return defaultId;
6983 return reactId;
6984 }
6985 const [id, setId] = (0, import_react5.useState)(defaultId);
6986 useSafeLayoutEffect(() => {
6987 if (defaultId || id) return;
6988 const random = Math.random().toString(36).slice(2, 8);
6989 setId(`id-${random}`);
6990 }, [defaultId, id]);
6991 return defaultId || id;
6992 }
6993 function useTagName(refOrElement, type) {
6994 const stringOrUndefined = (type2) => {
6995 if (typeof type2 !== "string") return;
6996 return type2;
6997 };
6998 const [tagName, setTagName] = (0, import_react5.useState)(() => stringOrUndefined(type));
6999 useSafeLayoutEffect(() => {
7000 const element = refOrElement && "current" in refOrElement ? refOrElement.current : refOrElement;
7001 setTagName((element == null ? void 0 : element.tagName.toLowerCase()) || stringOrUndefined(type));
7002 }, [refOrElement, type]);
7003 return tagName;
7004 }
7005 function useAttribute(refOrElement, attributeName, defaultValue2) {
7006 const initialValue = useInitialValue(defaultValue2);
7007 const [attribute, setAttribute] = (0, import_react5.useState)(initialValue);
7008 (0, import_react5.useEffect)(() => {
7009 const element = refOrElement && "current" in refOrElement ? refOrElement.current : refOrElement;
7010 if (!element) return;
7011 const callback = () => {
7012 const value = element.getAttribute(attributeName);
7013 setAttribute(value == null ? initialValue : value);
7014 };
7015 const observer = new MutationObserver(callback);
7016 observer.observe(element, { attributeFilter: [attributeName] });
7017 callback();
7018 return () => observer.disconnect();
7019 }, [refOrElement, attributeName, initialValue]);
7020 return attribute;
7021 }
7022 function useUpdateEffect(effect, deps) {
7023 const mounted = (0, import_react5.useRef)(false);
7024 (0, import_react5.useEffect)(() => {
7025 if (mounted.current) {
7026 return effect();
7027 }
7028 mounted.current = true;
7029 }, deps);
7030 (0, import_react5.useEffect)(
7031 () => () => {
7032 mounted.current = false;
7033 },
7034 []
7035 );
7036 }
7037 function useUpdateLayoutEffect(effect, deps) {
7038 const mounted = (0, import_react5.useRef)(false);
7039 useSafeLayoutEffect(() => {
7040 if (mounted.current) {
7041 return effect();
7042 }
7043 mounted.current = true;
7044 }, deps);
7045 useSafeLayoutEffect(
7046 () => () => {
7047 mounted.current = false;
7048 },
7049 []
7050 );
7051 }
7052 function useForceUpdate() {
7053 return (0, import_react5.useReducer)(() => [], []);
7054 }
7055 function useBooleanEvent(booleanOrCallback) {
7056 return useEvent(
7057 typeof booleanOrCallback === "function" ? booleanOrCallback : () => booleanOrCallback
7058 );
7059 }
7060 function useWrapElement(props, callback, deps = []) {
7061 const wrapElement = (0, import_react5.useCallback)(
7062 (element) => {
7063 if (props.wrapElement) {
7064 element = props.wrapElement(element);
7065 }
7066 return callback(element);
7067 },
7068 [...deps, props.wrapElement]
7069 );
7070 return { ...props, wrapElement };
7071 }
7072 function useMetadataProps(props, key, value) {
7073 const parent = props.onLoadedMetadataCapture;
7074 const onLoadedMetadataCapture = (0, import_react5.useMemo)(() => {
7075 return Object.assign(() => {
7076 }, { ...parent, [key]: value });
7077 }, [parent, key, value]);
7078 return [parent == null ? void 0 : parent[key], { onLoadedMetadataCapture }];
7079 }
7080 var hasInstalledGlobalEventListeners = false;
7081 function useIsMouseMoving() {
7082 (0, import_react5.useEffect)(() => {
7083 if (hasInstalledGlobalEventListeners) return;
7084 addGlobalEventListener("mousemove", setMouseMoving, true);
7085 addGlobalEventListener("mousedown", resetMouseMoving, true);
7086 addGlobalEventListener("mouseup", resetMouseMoving, true);
7087 addGlobalEventListener("keydown", resetMouseMoving, true);
7088 addGlobalEventListener("scroll", resetMouseMoving, true);
7089 hasInstalledGlobalEventListeners = true;
7090 }, []);
7091 const isMouseMoving = useEvent(() => mouseMoving);
7092 return isMouseMoving;
7093 }
7094 var mouseMoving = false;
7095 var previousScreenX = 0;
7096 var previousScreenY = 0;
7097 function hasMouseMovement(event) {
7098 const movementX = event.movementX || event.screenX - previousScreenX;
7099 const movementY = event.movementY || event.screenY - previousScreenY;
7100 previousScreenX = event.screenX;
7101 previousScreenY = event.screenY;
7102 return movementX || movementY || false;
7103 }
7104 function setMouseMoving(event) {
7105 if (!hasMouseMovement(event)) return;
7106 mouseMoving = true;
7107 }
7108 function resetMouseMoving() {
7109 mouseMoving = false;
7110 }
7111
7112 // node_modules/@ariakit/react-core/esm/__chunks/GWSL6KNJ.js
7113 var React6 = __toESM(require_react(), 1);
7114 var import_jsx_runtime54 = __toESM(require_jsx_runtime(), 1);
7115 function forwardRef22(render4) {
7116 const Role = React6.forwardRef(
7117 // @ts-ignore Incompatible with React 19 types. Ignore for now.
7118 (props, ref) => render4({ ...props, ref })
7119 );
7120 Role.displayName = render4.displayName || render4.name;
7121 return Role;
7122 }
7123 function memo22(Component2, propsAreEqual) {
7124 return React6.memo(Component2, propsAreEqual);
7125 }
7126 function createElement3(Type, props) {
7127 const { wrapElement, render: render4, ...rest } = props;
7128 const mergedRef = useMergeRefs(props.ref, getRefProperty(render4));
7129 let element;
7130 if (React6.isValidElement(render4)) {
7131 const renderProps = {
7132 // @ts-ignore Incompatible with React 19 types. Ignore for now.
7133 ...render4.props,
7134 ref: mergedRef
7135 };
7136 element = React6.cloneElement(render4, mergeProps2(rest, renderProps));
7137 } else if (render4) {
7138 element = render4(rest);
7139 } else {
7140 element = /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(Type, { ...rest });
7141 }
7142 if (wrapElement) {
7143 return wrapElement(element);
7144 }
7145 return element;
7146 }
7147 function createHook(useProps) {
7148 const useRole = (props = {}) => {
7149 return useProps(props);
7150 };
7151 useRole.displayName = useProps.name;
7152 return useRole;
7153 }
7154 function createStoreContext(providers = [], scopedProviders = []) {
7155 const context = React6.createContext(void 0);
7156 const scopedContext = React6.createContext(void 0);
7157 const useContext28 = () => React6.useContext(context);
7158 const useScopedContext = (onlyScoped = false) => {
7159 const scoped = React6.useContext(scopedContext);
7160 const store = useContext28();
7161 if (onlyScoped) return scoped;
7162 return scoped || store;
7163 };
7164 const useProviderContext = () => {
7165 const scoped = React6.useContext(scopedContext);
7166 const store = useContext28();
7167 if (scoped && scoped === store) return;
7168 return store;
7169 };
7170 const ContextProvider = (props) => {
7171 return providers.reduceRight(
7172 (children, Provider) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(Provider, { ...props, children }),
7173 /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(context.Provider, { ...props })
7174 );
7175 };
7176 const ScopedContextProvider = (props) => {
7177 return /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(ContextProvider, { ...props, children: scopedProviders.reduceRight(
7178 (children, Provider) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(Provider, { ...props, children }),
7179 /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(scopedContext.Provider, { ...props })
7180 ) });
7181 };
7182 return {
7183 context,
7184 scopedContext,
7185 useContext: useContext28,
7186 useScopedContext,
7187 useProviderContext,
7188 ContextProvider,
7189 ScopedContextProvider
7190 };
7191 }
7192
7193 // node_modules/@ariakit/react-core/esm/__chunks/SMPCIMZM.js
7194 var ctx = createStoreContext();
7195 var useCollectionContext = ctx.useContext;
7196 var useCollectionScopedContext = ctx.useScopedContext;
7197 var useCollectionProviderContext = ctx.useProviderContext;
7198 var CollectionContextProvider = ctx.ContextProvider;
7199 var CollectionScopedContextProvider = ctx.ScopedContextProvider;
7200
7201 // node_modules/@ariakit/react-core/esm/__chunks/AVVXDJMZ.js
7202 var import_react6 = __toESM(require_react(), 1);
7203 var ctx2 = createStoreContext(
7204 [CollectionContextProvider],
7205 [CollectionScopedContextProvider]
7206 );
7207 var useCompositeContext = ctx2.useContext;
7208 var useCompositeScopedContext = ctx2.useScopedContext;
7209 var useCompositeProviderContext = ctx2.useProviderContext;
7210 var CompositeContextProvider = ctx2.ContextProvider;
7211 var CompositeScopedContextProvider = ctx2.ScopedContextProvider;
7212 var CompositeItemContext = (0, import_react6.createContext)(
7213 void 0
7214 );
7215 var CompositeRowContext = (0, import_react6.createContext)(
7216 void 0
7217 );
7218
7219 // node_modules/@ariakit/react-core/esm/__chunks/5VQZOHHZ.js
7220 function findFirstEnabledItem(items, excludeId) {
7221 return items.find((item) => {
7222 if (excludeId) {
7223 return !item.disabled && item.id !== excludeId;
7224 }
7225 return !item.disabled;
7226 });
7227 }
7228 function getEnabledItem(store, id) {
7229 if (!id) return null;
7230 return store.item(id) || null;
7231 }
7232 function groupItemsByRows(items) {
7233 const rows = [];
7234 for (const item of items) {
7235 const row = rows.find((currentRow) => {
7236 var _a;
7237 return ((_a = currentRow[0]) == null ? void 0 : _a.rowId) === item.rowId;
7238 });
7239 if (row) {
7240 row.push(item);
7241 } else {
7242 rows.push([item]);
7243 }
7244 }
7245 return rows;
7246 }
7247 function selectTextField(element, collapseToEnd = false) {
7248 if (isTextField(element)) {
7249 element.setSelectionRange(
7250 collapseToEnd ? element.value.length : 0,
7251 element.value.length
7252 );
7253 } else if (element.isContentEditable) {
7254 const selection = getDocument(element).getSelection();
7255 selection == null ? void 0 : selection.selectAllChildren(element);
7256 if (collapseToEnd) {
7257 selection == null ? void 0 : selection.collapseToEnd();
7258 }
7259 }
7260 }
7261 var FOCUS_SILENTLY = /* @__PURE__ */ Symbol("FOCUS_SILENTLY");
7262 function focusSilently(element) {
7263 element[FOCUS_SILENTLY] = true;
7264 element.focus({ preventScroll: true });
7265 }
7266 function silentlyFocused(element) {
7267 const isSilentlyFocused = element[FOCUS_SILENTLY];
7268 delete element[FOCUS_SILENTLY];
7269 return isSilentlyFocused;
7270 }
7271 function isItem(store, element, exclude) {
7272 if (!element) return false;
7273 if (element === exclude) return false;
7274 const item = store.item(element.id);
7275 if (!item) return false;
7276 if (exclude && item.element === exclude) return false;
7277 return true;
7278 }
7279
7280 // node_modules/@ariakit/react-core/esm/__chunks/Z2O3VLAQ.js
7281 var import_react7 = __toESM(require_react(), 1);
7282 var TagName = "div";
7283 var useCollectionItem = createHook(
7284 function useCollectionItem2({
7285 store,
7286 shouldRegisterItem = true,
7287 getItem = identity,
7288 // @ts-expect-error This prop may come from a collection renderer.
7289 element,
7290 ...props
7291 }) {
7292 const context = useCollectionContext();
7293 store = store || context;
7294 const id = useId3(props.id);
7295 const ref = (0, import_react7.useRef)(element);
7296 (0, import_react7.useEffect)(() => {
7297 const element2 = ref.current;
7298 if (!id) return;
7299 if (!element2) return;
7300 if (!shouldRegisterItem) return;
7301 const item = getItem({ id, element: element2 });
7302 return store == null ? void 0 : store.renderItem(item);
7303 }, [id, shouldRegisterItem, getItem, store]);
7304 props = {
7305 ...props,
7306 ref: useMergeRefs(ref, props.ref)
7307 };
7308 return removeUndefinedValues(props);
7309 }
7310 );
7311 var CollectionItem = forwardRef22(function CollectionItem2(props) {
7312 const htmlProps = useCollectionItem(props);
7313 return createElement3(TagName, htmlProps);
7314 });
7315
7316 // node_modules/@ariakit/react-core/esm/__chunks/SWN3JYXT.js
7317 var import_react8 = __toESM(require_react(), 1);
7318 var FocusableContext = (0, import_react8.createContext)(true);
7319
7320 // node_modules/@ariakit/core/esm/utils/focus.js
7321 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'])";
7322 function isFocusable(element) {
7323 if (!element.matches(selector)) return false;
7324 if (!isVisible(element)) return false;
7325 if (element.closest("[inert]")) return false;
7326 return true;
7327 }
7328 function getClosestFocusable(element) {
7329 while (element && !isFocusable(element)) {
7330 element = element.closest(selector);
7331 }
7332 return element || null;
7333 }
7334 function hasFocus(element) {
7335 const activeElement = getActiveElement(element);
7336 if (!activeElement) return false;
7337 if (activeElement === element) return true;
7338 const activeDescendant = activeElement.getAttribute("aria-activedescendant");
7339 if (!activeDescendant) return false;
7340 return activeDescendant === element.id;
7341 }
7342 function hasFocusWithin(element) {
7343 const activeElement = getActiveElement(element);
7344 if (!activeElement) return false;
7345 if (contains(element, activeElement)) return true;
7346 const activeDescendant = activeElement.getAttribute("aria-activedescendant");
7347 if (!activeDescendant) return false;
7348 if (!("id" in element)) return false;
7349 if (activeDescendant === element.id) return true;
7350 return !!element.querySelector(`#${CSS.escape(activeDescendant)}`);
7351 }
7352 function focusIfNeeded(element) {
7353 if (!hasFocusWithin(element) && isFocusable(element)) {
7354 element.focus();
7355 }
7356 }
7357 function focusIntoView(element, options) {
7358 if (!("scrollIntoView" in element)) {
7359 element.focus();
7360 } else {
7361 element.focus({ preventScroll: true });
7362 element.scrollIntoView({ block: "nearest", inline: "nearest", ...options });
7363 }
7364 }
7365
7366 // node_modules/@ariakit/react-core/esm/__chunks/U6HHPQDW.js
7367 var import_react9 = __toESM(require_react(), 1);
7368 var TagName2 = "div";
7369 var isSafariBrowser = isSafari();
7370 var alwaysFocusVisibleInputTypes = [
7371 "text",
7372 "search",
7373 "url",
7374 "tel",
7375 "email",
7376 "password",
7377 "number",
7378 "date",
7379 "month",
7380 "week",
7381 "time",
7382 "datetime",
7383 "datetime-local"
7384 ];
7385 var safariFocusAncestorSymbol = /* @__PURE__ */ Symbol("safariFocusAncestor");
7386 function markSafariFocusAncestor(element, value) {
7387 if (!element) return;
7388 element[safariFocusAncestorSymbol] = value;
7389 }
7390 function isAlwaysFocusVisible(element) {
7391 const { tagName, readOnly, type } = element;
7392 if (tagName === "TEXTAREA" && !readOnly) return true;
7393 if (tagName === "SELECT" && !readOnly) return true;
7394 if (tagName === "INPUT" && !readOnly) {
7395 return alwaysFocusVisibleInputTypes.includes(type);
7396 }
7397 if (element.isContentEditable) return true;
7398 const role = element.getAttribute("role");
7399 if (role === "combobox" && element.dataset.name) {
7400 return true;
7401 }
7402 return false;
7403 }
7404 function getLabels(element) {
7405 if ("labels" in element) {
7406 return element.labels;
7407 }
7408 return null;
7409 }
7410 function isNativeCheckboxOrRadio(element) {
7411 const tagName = element.tagName.toLowerCase();
7412 if (tagName === "input" && element.type) {
7413 return element.type === "radio" || element.type === "checkbox";
7414 }
7415 return false;
7416 }
7417 function isNativeTabbable(tagName) {
7418 if (!tagName) return true;
7419 return tagName === "button" || tagName === "summary" || tagName === "input" || tagName === "select" || tagName === "textarea" || tagName === "a";
7420 }
7421 function supportsDisabledAttribute(tagName) {
7422 if (!tagName) return true;
7423 return tagName === "button" || tagName === "input" || tagName === "select" || tagName === "textarea";
7424 }
7425 function getTabIndex(focusable, trulyDisabled, nativeTabbable, supportsDisabled, tabIndexProp) {
7426 if (!focusable) {
7427 return tabIndexProp;
7428 }
7429 if (trulyDisabled) {
7430 if (nativeTabbable && !supportsDisabled) {
7431 return -1;
7432 }
7433 return;
7434 }
7435 if (nativeTabbable) {
7436 return tabIndexProp;
7437 }
7438 return tabIndexProp || 0;
7439 }
7440 function useDisableEvent(onEvent, disabled) {
7441 return useEvent((event) => {
7442 onEvent == null ? void 0 : onEvent(event);
7443 if (event.defaultPrevented) return;
7444 if (disabled) {
7445 event.stopPropagation();
7446 event.preventDefault();
7447 }
7448 });
7449 }
7450 var hasInstalledGlobalEventListeners2 = false;
7451 var isKeyboardModality = true;
7452 function onGlobalMouseDown(event) {
7453 const target = event.target;
7454 if (target && "hasAttribute" in target) {
7455 if (!target.hasAttribute("data-focus-visible")) {
7456 isKeyboardModality = false;
7457 }
7458 }
7459 }
7460 function onGlobalKeyDown(event) {
7461 if (event.metaKey) return;
7462 if (event.ctrlKey) return;
7463 if (event.altKey) return;
7464 isKeyboardModality = true;
7465 }
7466 var useFocusable = createHook(
7467 function useFocusable2({
7468 focusable = true,
7469 accessibleWhenDisabled,
7470 autoFocus,
7471 onFocusVisible,
7472 ...props
7473 }) {
7474 const ref = (0, import_react9.useRef)(null);
7475 (0, import_react9.useEffect)(() => {
7476 if (!focusable) return;
7477 if (hasInstalledGlobalEventListeners2) return;
7478 addGlobalEventListener("mousedown", onGlobalMouseDown, true);
7479 addGlobalEventListener("keydown", onGlobalKeyDown, true);
7480 hasInstalledGlobalEventListeners2 = true;
7481 }, [focusable]);
7482 if (isSafariBrowser) {
7483 (0, import_react9.useEffect)(() => {
7484 if (!focusable) return;
7485 const element = ref.current;
7486 if (!element) return;
7487 if (!isNativeCheckboxOrRadio(element)) return;
7488 const labels = getLabels(element);
7489 if (!labels) return;
7490 const onMouseUp = () => queueMicrotask(() => element.focus());
7491 for (const label of labels) {
7492 label.addEventListener("mouseup", onMouseUp);
7493 }
7494 return () => {
7495 for (const label of labels) {
7496 label.removeEventListener("mouseup", onMouseUp);
7497 }
7498 };
7499 }, [focusable]);
7500 }
7501 const disabled = focusable && disabledFromProps(props);
7502 const trulyDisabled = !!disabled && !accessibleWhenDisabled;
7503 const [focusVisible, setFocusVisible] = (0, import_react9.useState)(false);
7504 (0, import_react9.useEffect)(() => {
7505 if (!focusable) return;
7506 if (trulyDisabled && focusVisible) {
7507 setFocusVisible(false);
7508 }
7509 }, [focusable, trulyDisabled, focusVisible]);
7510 (0, import_react9.useEffect)(() => {
7511 if (!focusable) return;
7512 if (!focusVisible) return;
7513 const element = ref.current;
7514 if (!element) return;
7515 if (typeof IntersectionObserver === "undefined") return;
7516 const observer = new IntersectionObserver(() => {
7517 if (!isFocusable(element)) {
7518 setFocusVisible(false);
7519 }
7520 });
7521 observer.observe(element);
7522 return () => observer.disconnect();
7523 }, [focusable, focusVisible]);
7524 const onKeyPressCapture = useDisableEvent(
7525 props.onKeyPressCapture,
7526 disabled
7527 );
7528 const onMouseDownCapture = useDisableEvent(
7529 props.onMouseDownCapture,
7530 disabled
7531 );
7532 const onClickCapture = useDisableEvent(props.onClickCapture, disabled);
7533 const onMouseDownProp = props.onMouseDown;
7534 const onMouseDown = useEvent((event) => {
7535 onMouseDownProp == null ? void 0 : onMouseDownProp(event);
7536 if (event.defaultPrevented) return;
7537 if (!focusable) return;
7538 const element = event.currentTarget;
7539 if (!isSafariBrowser) return;
7540 if (isPortalEvent(event)) return;
7541 if (!isButton(element) && !isNativeCheckboxOrRadio(element)) return;
7542 let receivedFocus = false;
7543 const onFocus = () => {
7544 receivedFocus = true;
7545 };
7546 const options = { capture: true, once: true };
7547 element.addEventListener("focusin", onFocus, options);
7548 const focusableContainer = getClosestFocusable(element.parentElement);
7549 markSafariFocusAncestor(focusableContainer, true);
7550 queueBeforeEvent(element, "mouseup", () => {
7551 element.removeEventListener("focusin", onFocus, true);
7552 markSafariFocusAncestor(focusableContainer, false);
7553 if (receivedFocus) return;
7554 focusIfNeeded(element);
7555 });
7556 });
7557 const handleFocusVisible = (event, currentTarget) => {
7558 if (currentTarget) {
7559 event.currentTarget = currentTarget;
7560 }
7561 if (!focusable) return;
7562 const element = event.currentTarget;
7563 if (!element) return;
7564 if (!hasFocus(element)) return;
7565 onFocusVisible == null ? void 0 : onFocusVisible(event);
7566 if (event.defaultPrevented) return;
7567 element.dataset.focusVisible = "true";
7568 setFocusVisible(true);
7569 };
7570 const onKeyDownCaptureProp = props.onKeyDownCapture;
7571 const onKeyDownCapture = useEvent((event) => {
7572 onKeyDownCaptureProp == null ? void 0 : onKeyDownCaptureProp(event);
7573 if (event.defaultPrevented) return;
7574 if (!focusable) return;
7575 if (focusVisible) return;
7576 if (event.metaKey) return;
7577 if (event.altKey) return;
7578 if (event.ctrlKey) return;
7579 if (!isSelfTarget(event)) return;
7580 const element = event.currentTarget;
7581 const applyFocusVisible = () => handleFocusVisible(event, element);
7582 queueBeforeEvent(element, "focusout", applyFocusVisible);
7583 });
7584 const onFocusCaptureProp = props.onFocusCapture;
7585 const onFocusCapture = useEvent((event) => {
7586 onFocusCaptureProp == null ? void 0 : onFocusCaptureProp(event);
7587 if (event.defaultPrevented) return;
7588 if (!focusable) return;
7589 if (!isSelfTarget(event)) {
7590 setFocusVisible(false);
7591 return;
7592 }
7593 const element = event.currentTarget;
7594 const applyFocusVisible = () => handleFocusVisible(event, element);
7595 if (isKeyboardModality || isAlwaysFocusVisible(event.target)) {
7596 queueBeforeEvent(event.target, "focusout", applyFocusVisible);
7597 } else {
7598 setFocusVisible(false);
7599 }
7600 });
7601 const onBlurProp = props.onBlur;
7602 const onBlur = useEvent((event) => {
7603 onBlurProp == null ? void 0 : onBlurProp(event);
7604 if (!focusable) return;
7605 if (!isFocusEventOutside(event)) return;
7606 event.currentTarget.removeAttribute("data-focus-visible");
7607 setFocusVisible(false);
7608 });
7609 const autoFocusOnShow = (0, import_react9.useContext)(FocusableContext);
7610 const autoFocusRef = useEvent((element) => {
7611 if (!focusable) return;
7612 if (!autoFocus) return;
7613 if (!element) return;
7614 if (!autoFocusOnShow) return;
7615 queueMicrotask(() => {
7616 if (hasFocus(element)) return;
7617 if (!isFocusable(element)) return;
7618 element.focus();
7619 });
7620 });
7621 const tagName = useTagName(ref);
7622 const nativeTabbable = focusable && isNativeTabbable(tagName);
7623 const supportsDisabled = focusable && supportsDisabledAttribute(tagName);
7624 const styleProp = props.style;
7625 const style = (0, import_react9.useMemo)(() => {
7626 if (trulyDisabled) {
7627 return { pointerEvents: "none", ...styleProp };
7628 }
7629 return styleProp;
7630 }, [trulyDisabled, styleProp]);
7631 props = {
7632 "data-focus-visible": focusable && focusVisible || void 0,
7633 "data-autofocus": autoFocus || void 0,
7634 "aria-disabled": disabled || void 0,
7635 ...props,
7636 ref: useMergeRefs(ref, autoFocusRef, props.ref),
7637 style,
7638 tabIndex: getTabIndex(
7639 focusable,
7640 trulyDisabled,
7641 nativeTabbable,
7642 supportsDisabled,
7643 props.tabIndex
7644 ),
7645 disabled: supportsDisabled && trulyDisabled ? true : void 0,
7646 // TODO: Test Focusable contentEditable.
7647 contentEditable: disabled ? void 0 : props.contentEditable,
7648 onKeyPressCapture,
7649 onClickCapture,
7650 onMouseDownCapture,
7651 onMouseDown,
7652 onKeyDownCapture,
7653 onFocusCapture,
7654 onBlur
7655 };
7656 return removeUndefinedValues(props);
7657 }
7658 );
7659 var Focusable = forwardRef22(function Focusable2(props) {
7660 const htmlProps = useFocusable(props);
7661 return createElement3(TagName2, htmlProps);
7662 });
7663
7664 // node_modules/@ariakit/react-core/esm/__chunks/PZ3OL7I2.js
7665 var import_react10 = __toESM(require_react(), 1);
7666 var TagName3 = "button";
7667 function isNativeClick(event) {
7668 if (!event.isTrusted) return false;
7669 const element = event.currentTarget;
7670 if (event.key === "Enter") {
7671 return isButton(element) || element.tagName === "SUMMARY" || element.tagName === "A";
7672 }
7673 if (event.key === " ") {
7674 return isButton(element) || element.tagName === "SUMMARY" || element.tagName === "INPUT" || element.tagName === "SELECT";
7675 }
7676 return false;
7677 }
7678 var symbol = /* @__PURE__ */ Symbol("command");
7679 var useCommand = createHook(
7680 function useCommand2({ clickOnEnter = true, clickOnSpace = true, ...props }) {
7681 const ref = (0, import_react10.useRef)(null);
7682 const [isNativeButton, setIsNativeButton] = (0, import_react10.useState)(false);
7683 (0, import_react10.useEffect)(() => {
7684 if (!ref.current) return;
7685 setIsNativeButton(isButton(ref.current));
7686 }, []);
7687 const [active, setActive] = (0, import_react10.useState)(false);
7688 const activeRef = (0, import_react10.useRef)(false);
7689 const disabled = disabledFromProps(props);
7690 const [isDuplicate, metadataProps] = useMetadataProps(props, symbol, true);
7691 const onKeyDownProp = props.onKeyDown;
7692 const onKeyDown = useEvent((event) => {
7693 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
7694 const element = event.currentTarget;
7695 if (event.defaultPrevented) return;
7696 if (isDuplicate) return;
7697 if (disabled) return;
7698 if (!isSelfTarget(event)) return;
7699 if (isTextField(element)) return;
7700 if (element.isContentEditable) return;
7701 const isEnter = clickOnEnter && event.key === "Enter";
7702 const isSpace = clickOnSpace && event.key === " ";
7703 const shouldPreventEnter = event.key === "Enter" && !clickOnEnter;
7704 const shouldPreventSpace = event.key === " " && !clickOnSpace;
7705 if (shouldPreventEnter || shouldPreventSpace) {
7706 event.preventDefault();
7707 return;
7708 }
7709 if (isEnter || isSpace) {
7710 const nativeClick = isNativeClick(event);
7711 if (isEnter) {
7712 if (!nativeClick) {
7713 event.preventDefault();
7714 const { view, ...eventInit } = event;
7715 const click = () => fireClickEvent(element, eventInit);
7716 if (isFirefox()) {
7717 queueBeforeEvent(element, "keyup", click);
7718 } else {
7719 queueMicrotask(click);
7720 }
7721 }
7722 } else if (isSpace) {
7723 activeRef.current = true;
7724 if (!nativeClick) {
7725 event.preventDefault();
7726 setActive(true);
7727 }
7728 }
7729 }
7730 });
7731 const onKeyUpProp = props.onKeyUp;
7732 const onKeyUp = useEvent((event) => {
7733 onKeyUpProp == null ? void 0 : onKeyUpProp(event);
7734 if (event.defaultPrevented) return;
7735 if (isDuplicate) return;
7736 if (disabled) return;
7737 if (event.metaKey) return;
7738 const isSpace = clickOnSpace && event.key === " ";
7739 if (activeRef.current && isSpace) {
7740 activeRef.current = false;
7741 if (!isNativeClick(event)) {
7742 event.preventDefault();
7743 setActive(false);
7744 const element = event.currentTarget;
7745 const { view, ...eventInit } = event;
7746 queueMicrotask(() => fireClickEvent(element, eventInit));
7747 }
7748 }
7749 });
7750 props = {
7751 "data-active": active || void 0,
7752 type: isNativeButton ? "button" : void 0,
7753 ...metadataProps,
7754 ...props,
7755 ref: useMergeRefs(ref, props.ref),
7756 onKeyDown,
7757 onKeyUp
7758 };
7759 props = useFocusable(props);
7760 return props;
7761 }
7762 );
7763 var Command = forwardRef22(function Command2(props) {
7764 const htmlProps = useCommand(props);
7765 return createElement3(TagName3, htmlProps);
7766 });
7767
7768 // node_modules/@ariakit/core/esm/__chunks/SXKM4CGU.js
7769 function getInternal(store, key) {
7770 const internals = store.__unstableInternals;
7771 invariant(internals, "Invalid store");
7772 return internals[key];
7773 }
7774 function createStore(initialState, ...stores) {
7775 let state = initialState;
7776 let prevStateBatch = state;
7777 let lastUpdate = /* @__PURE__ */ Symbol();
7778 let destroy = noop2;
7779 const instances = /* @__PURE__ */ new Set();
7780 const updatedKeys = /* @__PURE__ */ new Set();
7781 const setups = /* @__PURE__ */ new Set();
7782 const listeners = /* @__PURE__ */ new Set();
7783 const batchListeners = /* @__PURE__ */ new Set();
7784 const disposables = /* @__PURE__ */ new WeakMap();
7785 const listenerKeys = /* @__PURE__ */ new WeakMap();
7786 const storeSetup = (callback) => {
7787 setups.add(callback);
7788 return () => setups.delete(callback);
7789 };
7790 const storeInit = () => {
7791 const initialized = instances.size;
7792 const instance = /* @__PURE__ */ Symbol();
7793 instances.add(instance);
7794 const maybeDestroy = () => {
7795 instances.delete(instance);
7796 if (instances.size) return;
7797 destroy();
7798 };
7799 if (initialized) return maybeDestroy;
7800 const desyncs = getKeys(state).map(
7801 (key) => chain(
7802 ...stores.map((store) => {
7803 var _a;
7804 const storeState = (_a = store == null ? void 0 : store.getState) == null ? void 0 : _a.call(store);
7805 if (!storeState) return;
7806 if (!hasOwnProperty(storeState, key)) return;
7807 return sync(store, [key], (state2) => {
7808 setState(
7809 key,
7810 state2[key],
7811 // @ts-expect-error - Not public API. This is just to prevent
7812 // infinite loops.
7813 true
7814 );
7815 });
7816 })
7817 )
7818 );
7819 const teardowns = [];
7820 for (const setup2 of setups) {
7821 teardowns.push(setup2());
7822 }
7823 const cleanups = stores.map(init);
7824 destroy = chain(...desyncs, ...teardowns, ...cleanups);
7825 return maybeDestroy;
7826 };
7827 const sub = (keys, listener, set2 = listeners) => {
7828 set2.add(listener);
7829 listenerKeys.set(listener, keys);
7830 return () => {
7831 var _a;
7832 (_a = disposables.get(listener)) == null ? void 0 : _a();
7833 disposables.delete(listener);
7834 listenerKeys.delete(listener);
7835 set2.delete(listener);
7836 };
7837 };
7838 const storeSubscribe = (keys, listener) => sub(keys, listener);
7839 const storeSync = (keys, listener) => {
7840 disposables.set(listener, listener(state, state));
7841 return sub(keys, listener);
7842 };
7843 const storeBatch = (keys, listener) => {
7844 disposables.set(listener, listener(state, prevStateBatch));
7845 return sub(keys, listener, batchListeners);
7846 };
7847 const storePick = (keys) => createStore(pick(state, keys), finalStore);
7848 const storeOmit = (keys) => createStore(omit(state, keys), finalStore);
7849 const getState = () => state;
7850 const setState = (key, value, fromStores = false) => {
7851 var _a;
7852 if (!hasOwnProperty(state, key)) return;
7853 const nextValue = applyState(value, state[key]);
7854 if (nextValue === state[key]) return;
7855 if (!fromStores) {
7856 for (const store of stores) {
7857 (_a = store == null ? void 0 : store.setState) == null ? void 0 : _a.call(store, key, nextValue);
7858 }
7859 }
7860 const prevState = state;
7861 state = { ...state, [key]: nextValue };
7862 const thisUpdate = /* @__PURE__ */ Symbol();
7863 lastUpdate = thisUpdate;
7864 updatedKeys.add(key);
7865 const run = (listener, prev, uKeys) => {
7866 var _a2;
7867 const keys = listenerKeys.get(listener);
7868 const updated = (k) => uKeys ? uKeys.has(k) : k === key;
7869 if (!keys || keys.some(updated)) {
7870 (_a2 = disposables.get(listener)) == null ? void 0 : _a2();
7871 disposables.set(listener, listener(state, prev));
7872 }
7873 };
7874 for (const listener of listeners) {
7875 run(listener, prevState);
7876 }
7877 queueMicrotask(() => {
7878 if (lastUpdate !== thisUpdate) return;
7879 const snapshot = state;
7880 for (const listener of batchListeners) {
7881 run(listener, prevStateBatch, updatedKeys);
7882 }
7883 prevStateBatch = snapshot;
7884 updatedKeys.clear();
7885 });
7886 };
7887 const finalStore = {
7888 getState,
7889 setState,
7890 __unstableInternals: {
7891 setup: storeSetup,
7892 init: storeInit,
7893 subscribe: storeSubscribe,
7894 sync: storeSync,
7895 batch: storeBatch,
7896 pick: storePick,
7897 omit: storeOmit
7898 }
7899 };
7900 return finalStore;
7901 }
7902 function setup(store, ...args) {
7903 if (!store) return;
7904 return getInternal(store, "setup")(...args);
7905 }
7906 function init(store, ...args) {
7907 if (!store) return;
7908 return getInternal(store, "init")(...args);
7909 }
7910 function subscribe(store, ...args) {
7911 if (!store) return;
7912 return getInternal(store, "subscribe")(...args);
7913 }
7914 function sync(store, ...args) {
7915 if (!store) return;
7916 return getInternal(store, "sync")(...args);
7917 }
7918 function batch(store, ...args) {
7919 if (!store) return;
7920 return getInternal(store, "batch")(...args);
7921 }
7922 function omit2(store, ...args) {
7923 if (!store) return;
7924 return getInternal(store, "omit")(...args);
7925 }
7926 function pick2(store, ...args) {
7927 if (!store) return;
7928 return getInternal(store, "pick")(...args);
7929 }
7930 function mergeStore(...stores) {
7931 var _a;
7932 const initialState = {};
7933 for (const store2 of stores) {
7934 const nextState = (_a = store2 == null ? void 0 : store2.getState) == null ? void 0 : _a.call(store2);
7935 if (nextState) {
7936 Object.assign(initialState, nextState);
7937 }
7938 }
7939 const store = createStore(initialState, ...stores);
7940 return Object.assign({}, ...stores, store);
7941 }
7942 function throwOnConflictingProps(props, store) {
7943 if (false) return;
7944 if (!store) return;
7945 const defaultKeys = Object.entries(props).filter(([key, value]) => key.startsWith("default") && value !== void 0).map(([key]) => {
7946 var _a;
7947 const stateKey = key.replace("default", "");
7948 return `${((_a = stateKey[0]) == null ? void 0 : _a.toLowerCase()) || ""}${stateKey.slice(1)}`;
7949 });
7950 if (!defaultKeys.length) return;
7951 const storeState = store.getState();
7952 const conflictingProps = defaultKeys.filter(
7953 (key) => hasOwnProperty(storeState, key)
7954 );
7955 if (!conflictingProps.length) return;
7956 throw new Error(
7957 `Passing a store prop in conjunction with a default state is not supported.
7958
7959 const store = useSelectStore();
7960 <SelectProvider store={store} defaultValue="Apple" />
7961 ^ ^
7962
7963 Instead, pass the default state to the topmost store:
7964
7965 const store = useSelectStore({ defaultValue: "Apple" });
7966 <SelectProvider store={store} />
7967
7968 See https://github.com/ariakit/ariakit/pull/2745 for more details.
7969
7970 If there's a particular need for this, please submit a feature request at https://github.com/ariakit/ariakit
7971 `
7972 );
7973 }
7974
7975 // node_modules/@ariakit/react-core/esm/__chunks/Q5W46E73.js
7976 var React7 = __toESM(require_react(), 1);
7977 var import_shim = __toESM(require_shim(), 1);
7978 var { useSyncExternalStore } = import_shim.default;
7979 var noopSubscribe = () => () => {
7980 };
7981 function useStoreState(store, keyOrSelector = identity) {
7982 const storeSubscribe = React7.useCallback(
7983 (callback) => {
7984 if (!store) return noopSubscribe();
7985 return subscribe(store, null, callback);
7986 },
7987 [store]
7988 );
7989 const getSnapshot = () => {
7990 const key = typeof keyOrSelector === "string" ? keyOrSelector : null;
7991 const selector2 = typeof keyOrSelector === "function" ? keyOrSelector : null;
7992 const state = store == null ? void 0 : store.getState();
7993 if (selector2) return selector2(state);
7994 if (!state) return;
7995 if (!key) return;
7996 if (!hasOwnProperty(state, key)) return;
7997 return state[key];
7998 };
7999 return useSyncExternalStore(storeSubscribe, getSnapshot, getSnapshot);
8000 }
8001 function useStoreStateObject(store, object) {
8002 const objRef = React7.useRef(
8003 {}
8004 );
8005 const storeSubscribe = React7.useCallback(
8006 (callback) => {
8007 if (!store) return noopSubscribe();
8008 return subscribe(store, null, callback);
8009 },
8010 [store]
8011 );
8012 const getSnapshot = () => {
8013 const state = store == null ? void 0 : store.getState();
8014 let updated = false;
8015 const obj = objRef.current;
8016 for (const prop in object) {
8017 const keyOrSelector = object[prop];
8018 if (typeof keyOrSelector === "function") {
8019 const value = keyOrSelector(state);
8020 if (value !== obj[prop]) {
8021 obj[prop] = value;
8022 updated = true;
8023 }
8024 }
8025 if (typeof keyOrSelector === "string") {
8026 if (!state) continue;
8027 if (!hasOwnProperty(state, keyOrSelector)) continue;
8028 const value = state[keyOrSelector];
8029 if (value !== obj[prop]) {
8030 obj[prop] = value;
8031 updated = true;
8032 }
8033 }
8034 }
8035 if (updated) {
8036 objRef.current = { ...obj };
8037 }
8038 return objRef.current;
8039 };
8040 return useSyncExternalStore(storeSubscribe, getSnapshot, getSnapshot);
8041 }
8042 function useStoreProps(store, props, key, setKey) {
8043 const value = hasOwnProperty(props, key) ? props[key] : void 0;
8044 const setValue = setKey ? props[setKey] : void 0;
8045 const propsRef = useLiveRef({ value, setValue });
8046 useSafeLayoutEffect(() => {
8047 return sync(store, [key], (state, prev) => {
8048 const { value: value2, setValue: setValue2 } = propsRef.current;
8049 if (!setValue2) return;
8050 if (state[key] === prev[key]) return;
8051 if (state[key] === value2) return;
8052 setValue2(state[key]);
8053 });
8054 }, [store, key]);
8055 useSafeLayoutEffect(() => {
8056 if (value === void 0) return;
8057 store.setState(key, value);
8058 return batch(store, [key], () => {
8059 if (value === void 0) return;
8060 store.setState(key, value);
8061 });
8062 });
8063 }
8064 function useStore(createStore2, props) {
8065 const [store, setStore] = React7.useState(() => createStore2(props));
8066 useSafeLayoutEffect(() => init(store), [store]);
8067 const useState210 = React7.useCallback(
8068 (keyOrSelector) => useStoreState(store, keyOrSelector),
8069 [store]
8070 );
8071 const memoizedStore = React7.useMemo(
8072 () => ({ ...store, useState: useState210 }),
8073 [store, useState210]
8074 );
8075 const updateStore = useEvent(() => {
8076 setStore((store2) => createStore2({ ...props, ...store2.getState() }));
8077 });
8078 return [memoizedStore, updateStore];
8079 }
8080
8081 // node_modules/@ariakit/react-core/esm/__chunks/WZWDIE3S.js
8082 var import_react11 = __toESM(require_react(), 1);
8083 var import_jsx_runtime55 = __toESM(require_jsx_runtime(), 1);
8084 var TagName4 = "button";
8085 function isEditableElement(element) {
8086 if (isTextbox(element)) return true;
8087 return element.tagName === "INPUT" && !isButton(element);
8088 }
8089 function getNextPageOffset(scrollingElement, pageUp = false) {
8090 const height = scrollingElement.clientHeight;
8091 const { top } = scrollingElement.getBoundingClientRect();
8092 const pageSize = Math.max(height * 0.875, height - 40) * 1.5;
8093 const pageOffset = pageUp ? height - pageSize + top : pageSize + top;
8094 if (scrollingElement.tagName === "HTML") {
8095 return pageOffset + scrollingElement.scrollTop;
8096 }
8097 return pageOffset;
8098 }
8099 function getItemOffset(itemElement, pageUp = false) {
8100 const { top } = itemElement.getBoundingClientRect();
8101 if (pageUp) {
8102 return top + itemElement.clientHeight;
8103 }
8104 return top;
8105 }
8106 function findNextPageItemId(element, store, next, pageUp = false) {
8107 var _a;
8108 if (!store) return;
8109 if (!next) return;
8110 const { renderedItems } = store.getState();
8111 const scrollingElement = getScrollingElement(element);
8112 if (!scrollingElement) return;
8113 const nextPageOffset = getNextPageOffset(scrollingElement, pageUp);
8114 let id;
8115 let prevDifference;
8116 for (let i2 = 0; i2 < renderedItems.length; i2 += 1) {
8117 const previousId = id;
8118 id = next(i2);
8119 if (!id) break;
8120 if (id === previousId) continue;
8121 const itemElement = (_a = getEnabledItem(store, id)) == null ? void 0 : _a.element;
8122 if (!itemElement) continue;
8123 const itemOffset = getItemOffset(itemElement, pageUp);
8124 const difference = itemOffset - nextPageOffset;
8125 const absDifference = Math.abs(difference);
8126 if (pageUp && difference <= 0 || !pageUp && difference >= 0) {
8127 if (prevDifference !== void 0 && prevDifference < absDifference) {
8128 id = previousId;
8129 }
8130 break;
8131 }
8132 prevDifference = absDifference;
8133 }
8134 return id;
8135 }
8136 function targetIsAnotherItem(event, store) {
8137 if (isSelfTarget(event)) return false;
8138 return isItem(store, event.target);
8139 }
8140 var useCompositeItem = createHook(
8141 function useCompositeItem2({
8142 store,
8143 rowId: rowIdProp,
8144 preventScrollOnKeyDown = false,
8145 moveOnKeyPress = true,
8146 tabbable = false,
8147 getItem: getItemProp,
8148 "aria-setsize": ariaSetSizeProp,
8149 "aria-posinset": ariaPosInSetProp,
8150 ...props
8151 }) {
8152 const context = useCompositeContext();
8153 store = store || context;
8154 const id = useId3(props.id);
8155 const ref = (0, import_react11.useRef)(null);
8156 const row = (0, import_react11.useContext)(CompositeRowContext);
8157 const disabled = disabledFromProps(props);
8158 const trulyDisabled = disabled && !props.accessibleWhenDisabled;
8159 const {
8160 rowId,
8161 baseElement,
8162 isActiveItem,
8163 ariaSetSize,
8164 ariaPosInSet,
8165 isTabbable
8166 } = useStoreStateObject(store, {
8167 rowId(state) {
8168 if (rowIdProp) return rowIdProp;
8169 if (!state) return;
8170 if (!(row == null ? void 0 : row.baseElement)) return;
8171 if (row.baseElement !== state.baseElement) return;
8172 return row.id;
8173 },
8174 baseElement(state) {
8175 return (state == null ? void 0 : state.baseElement) || void 0;
8176 },
8177 isActiveItem(state) {
8178 return !!state && state.activeId === id;
8179 },
8180 ariaSetSize(state) {
8181 if (ariaSetSizeProp != null) return ariaSetSizeProp;
8182 if (!state) return;
8183 if (!(row == null ? void 0 : row.ariaSetSize)) return;
8184 if (row.baseElement !== state.baseElement) return;
8185 return row.ariaSetSize;
8186 },
8187 ariaPosInSet(state) {
8188 if (ariaPosInSetProp != null) return ariaPosInSetProp;
8189 if (!state) return;
8190 if (!(row == null ? void 0 : row.ariaPosInSet)) return;
8191 if (row.baseElement !== state.baseElement) return;
8192 const itemsInRow = state.renderedItems.filter(
8193 (item) => item.rowId === rowId
8194 );
8195 return row.ariaPosInSet + itemsInRow.findIndex((item) => item.id === id);
8196 },
8197 isTabbable(state) {
8198 if (!(state == null ? void 0 : state.renderedItems.length)) return true;
8199 if (state.virtualFocus) return false;
8200 if (tabbable) return true;
8201 if (state.activeId === null) return false;
8202 const item = store == null ? void 0 : store.item(state.activeId);
8203 if (item == null ? void 0 : item.disabled) return true;
8204 if (!(item == null ? void 0 : item.element)) return true;
8205 return state.activeId === id;
8206 }
8207 });
8208 const getItem = (0, import_react11.useCallback)(
8209 (item) => {
8210 var _a;
8211 const nextItem = {
8212 ...item,
8213 id: id || item.id,
8214 rowId,
8215 disabled: !!trulyDisabled,
8216 children: (_a = item.element) == null ? void 0 : _a.textContent
8217 };
8218 if (getItemProp) {
8219 return getItemProp(nextItem);
8220 }
8221 return nextItem;
8222 },
8223 [id, rowId, trulyDisabled, getItemProp]
8224 );
8225 const onFocusProp = props.onFocus;
8226 const hasFocusedComposite = (0, import_react11.useRef)(false);
8227 const onFocus = useEvent((event) => {
8228 onFocusProp == null ? void 0 : onFocusProp(event);
8229 if (event.defaultPrevented) return;
8230 if (isPortalEvent(event)) return;
8231 if (!id) return;
8232 if (!store) return;
8233 if (targetIsAnotherItem(event, store)) return;
8234 const { virtualFocus, baseElement: baseElement2 } = store.getState();
8235 store.setActiveId(id);
8236 if (isTextbox(event.currentTarget)) {
8237 selectTextField(event.currentTarget);
8238 }
8239 if (!virtualFocus) return;
8240 if (!isSelfTarget(event)) return;
8241 if (isEditableElement(event.currentTarget)) return;
8242 if (!(baseElement2 == null ? void 0 : baseElement2.isConnected)) return;
8243 if (isSafari() && event.currentTarget.hasAttribute("data-autofocus")) {
8244 event.currentTarget.scrollIntoView({
8245 block: "nearest",
8246 inline: "nearest"
8247 });
8248 }
8249 hasFocusedComposite.current = true;
8250 const fromComposite = event.relatedTarget === baseElement2 || isItem(store, event.relatedTarget);
8251 if (fromComposite) {
8252 focusSilently(baseElement2);
8253 } else {
8254 baseElement2.focus();
8255 }
8256 });
8257 const onBlurCaptureProp = props.onBlurCapture;
8258 const onBlurCapture = useEvent((event) => {
8259 onBlurCaptureProp == null ? void 0 : onBlurCaptureProp(event);
8260 if (event.defaultPrevented) return;
8261 const state = store == null ? void 0 : store.getState();
8262 if ((state == null ? void 0 : state.virtualFocus) && hasFocusedComposite.current) {
8263 hasFocusedComposite.current = false;
8264 event.preventDefault();
8265 event.stopPropagation();
8266 }
8267 });
8268 const onKeyDownProp = props.onKeyDown;
8269 const preventScrollOnKeyDownProp = useBooleanEvent(preventScrollOnKeyDown);
8270 const moveOnKeyPressProp = useBooleanEvent(moveOnKeyPress);
8271 const onKeyDown = useEvent((event) => {
8272 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
8273 if (event.defaultPrevented) return;
8274 if (!isSelfTarget(event)) return;
8275 if (!store) return;
8276 const { currentTarget } = event;
8277 const state = store.getState();
8278 const item = store.item(id);
8279 const isGrid2 = !!(item == null ? void 0 : item.rowId);
8280 const isVertical = state.orientation !== "horizontal";
8281 const isHorizontal = state.orientation !== "vertical";
8282 const canHomeEnd = () => {
8283 if (isGrid2) return true;
8284 if (isHorizontal) return true;
8285 if (!state.baseElement) return true;
8286 if (!isTextField(state.baseElement)) return true;
8287 return false;
8288 };
8289 const keyMap = {
8290 ArrowUp: (isGrid2 || isVertical) && store.up,
8291 ArrowRight: (isGrid2 || isHorizontal) && store.next,
8292 ArrowDown: (isGrid2 || isVertical) && store.down,
8293 ArrowLeft: (isGrid2 || isHorizontal) && store.previous,
8294 Home: () => {
8295 if (!canHomeEnd()) return;
8296 if (!isGrid2 || event.ctrlKey) {
8297 return store == null ? void 0 : store.first();
8298 }
8299 return store == null ? void 0 : store.previous(-1);
8300 },
8301 End: () => {
8302 if (!canHomeEnd()) return;
8303 if (!isGrid2 || event.ctrlKey) {
8304 return store == null ? void 0 : store.last();
8305 }
8306 return store == null ? void 0 : store.next(-1);
8307 },
8308 PageUp: () => {
8309 return findNextPageItemId(currentTarget, store, store == null ? void 0 : store.up, true);
8310 },
8311 PageDown: () => {
8312 return findNextPageItemId(currentTarget, store, store == null ? void 0 : store.down);
8313 }
8314 };
8315 const action = keyMap[event.key];
8316 if (action) {
8317 if (isTextbox(currentTarget)) {
8318 const selection = getTextboxSelection(currentTarget);
8319 const isLeft = isHorizontal && event.key === "ArrowLeft";
8320 const isRight = isHorizontal && event.key === "ArrowRight";
8321 const isUp = isVertical && event.key === "ArrowUp";
8322 const isDown = isVertical && event.key === "ArrowDown";
8323 if (isRight || isDown) {
8324 const { length: valueLength } = getTextboxValue(currentTarget);
8325 if (selection.end !== valueLength) return;
8326 } else if ((isLeft || isUp) && selection.start !== 0) return;
8327 }
8328 const nextId = action();
8329 if (preventScrollOnKeyDownProp(event) || nextId !== void 0) {
8330 if (!moveOnKeyPressProp(event)) return;
8331 event.preventDefault();
8332 store.move(nextId);
8333 }
8334 }
8335 });
8336 const providerValue = (0, import_react11.useMemo)(
8337 () => ({ id, baseElement }),
8338 [id, baseElement]
8339 );
8340 props = useWrapElement(
8341 props,
8342 (element) => /* @__PURE__ */ (0, import_jsx_runtime55.jsx)(CompositeItemContext.Provider, { value: providerValue, children: element }),
8343 [providerValue]
8344 );
8345 props = {
8346 id,
8347 "data-active-item": isActiveItem || void 0,
8348 ...props,
8349 ref: useMergeRefs(ref, props.ref),
8350 tabIndex: isTabbable ? props.tabIndex : -1,
8351 onFocus,
8352 onBlurCapture,
8353 onKeyDown
8354 };
8355 props = useCommand(props);
8356 props = useCollectionItem({
8357 store,
8358 ...props,
8359 getItem,
8360 shouldRegisterItem: id ? props.shouldRegisterItem : false
8361 });
8362 return removeUndefinedValues({
8363 ...props,
8364 "aria-setsize": ariaSetSize,
8365 "aria-posinset": ariaPosInSet
8366 });
8367 }
8368 );
8369 var CompositeItem = memo22(
8370 forwardRef22(function CompositeItem2(props) {
8371 const htmlProps = useCompositeItem(props);
8372 return createElement3(TagName4, htmlProps);
8373 })
8374 );
8375
8376 // node_modules/@ariakit/core/esm/__chunks/7PRQYBBV.js
8377 function toArray(arg) {
8378 if (Array.isArray(arg)) {
8379 return arg;
8380 }
8381 return typeof arg !== "undefined" ? [arg] : [];
8382 }
8383 function flatten2DArray(array) {
8384 const flattened = [];
8385 for (const row of array) {
8386 flattened.push(...row);
8387 }
8388 return flattened;
8389 }
8390 function reverseArray(array) {
8391 return array.slice().reverse();
8392 }
8393
8394 // node_modules/@ariakit/react-core/esm/__chunks/ZMWF7ASR.js
8395 var import_react12 = __toESM(require_react(), 1);
8396 var import_jsx_runtime56 = __toESM(require_jsx_runtime(), 1);
8397 var TagName5 = "div";
8398 function isGrid(items) {
8399 return items.some((item) => !!item.rowId);
8400 }
8401 function isPrintableKey(event) {
8402 const target = event.target;
8403 if (target && !isTextField(target)) return false;
8404 return event.key.length === 1 && !event.ctrlKey && !event.metaKey;
8405 }
8406 function isModifierKey(event) {
8407 return event.key === "Shift" || event.key === "Control" || event.key === "Alt" || event.key === "Meta";
8408 }
8409 function useKeyboardEventProxy(store, onKeyboardEvent, previousElementRef) {
8410 return useEvent((event) => {
8411 var _a;
8412 onKeyboardEvent == null ? void 0 : onKeyboardEvent(event);
8413 if (event.defaultPrevented) return;
8414 if (event.isPropagationStopped()) return;
8415 if (!isSelfTarget(event)) return;
8416 if (isModifierKey(event)) return;
8417 if (isPrintableKey(event)) return;
8418 const state = store.getState();
8419 const activeElement = (_a = getEnabledItem(store, state.activeId)) == null ? void 0 : _a.element;
8420 if (!activeElement) return;
8421 const { view, ...eventInit } = event;
8422 const previousElement = previousElementRef == null ? void 0 : previousElementRef.current;
8423 if (activeElement !== previousElement) {
8424 activeElement.focus();
8425 }
8426 if (!fireKeyboardEvent(activeElement, event.type, eventInit)) {
8427 event.preventDefault();
8428 }
8429 if (event.currentTarget.contains(activeElement)) {
8430 event.stopPropagation();
8431 }
8432 });
8433 }
8434 function findFirstEnabledItemInTheLastRow(items) {
8435 return findFirstEnabledItem(
8436 flatten2DArray(reverseArray(groupItemsByRows(items)))
8437 );
8438 }
8439 function useScheduleFocus(store) {
8440 const [scheduled, setScheduled] = (0, import_react12.useState)(false);
8441 const schedule = (0, import_react12.useCallback)(() => setScheduled(true), []);
8442 const activeItem = store.useState(
8443 (state) => getEnabledItem(store, state.activeId)
8444 );
8445 (0, import_react12.useEffect)(() => {
8446 const activeElement = activeItem == null ? void 0 : activeItem.element;
8447 if (!scheduled) return;
8448 if (!activeElement) return;
8449 setScheduled(false);
8450 activeElement.focus({ preventScroll: true });
8451 }, [activeItem, scheduled]);
8452 return schedule;
8453 }
8454 var useComposite = createHook(
8455 function useComposite2({
8456 store,
8457 composite = true,
8458 focusOnMove = composite,
8459 moveOnKeyPress = true,
8460 ...props
8461 }) {
8462 const context = useCompositeProviderContext();
8463 store = store || context;
8464 invariant(
8465 store,
8466 "Composite must receive a `store` prop or be wrapped in a CompositeProvider component."
8467 );
8468 const ref = (0, import_react12.useRef)(null);
8469 const previousElementRef = (0, import_react12.useRef)(null);
8470 const scheduleFocus = useScheduleFocus(store);
8471 const moves = store.useState("moves");
8472 const [, setBaseElement] = useTransactionState(
8473 composite ? store.setBaseElement : null
8474 );
8475 (0, import_react12.useEffect)(() => {
8476 var _a;
8477 if (!store) return;
8478 if (!moves) return;
8479 if (!composite) return;
8480 if (!focusOnMove) return;
8481 const { activeId: activeId2 } = store.getState();
8482 const itemElement = (_a = getEnabledItem(store, activeId2)) == null ? void 0 : _a.element;
8483 if (!itemElement) return;
8484 focusIntoView(itemElement);
8485 }, [store, moves, composite, focusOnMove]);
8486 useSafeLayoutEffect(() => {
8487 if (!store) return;
8488 if (!moves) return;
8489 if (!composite) return;
8490 const { baseElement, activeId: activeId2 } = store.getState();
8491 const isSelfAcive = activeId2 === null;
8492 if (!isSelfAcive) return;
8493 if (!baseElement) return;
8494 const previousElement = previousElementRef.current;
8495 previousElementRef.current = null;
8496 if (previousElement) {
8497 fireBlurEvent(previousElement, { relatedTarget: baseElement });
8498 }
8499 if (!hasFocus(baseElement)) {
8500 baseElement.focus();
8501 }
8502 }, [store, moves, composite]);
8503 const activeId = store.useState("activeId");
8504 const virtualFocus = store.useState("virtualFocus");
8505 useSafeLayoutEffect(() => {
8506 var _a;
8507 if (!store) return;
8508 if (!composite) return;
8509 if (!virtualFocus) return;
8510 const previousElement = previousElementRef.current;
8511 previousElementRef.current = null;
8512 if (!previousElement) return;
8513 const activeElement = (_a = getEnabledItem(store, activeId)) == null ? void 0 : _a.element;
8514 const relatedTarget = activeElement || getActiveElement(previousElement);
8515 if (relatedTarget === previousElement) return;
8516 fireBlurEvent(previousElement, { relatedTarget });
8517 }, [store, activeId, virtualFocus, composite]);
8518 const onKeyDownCapture = useKeyboardEventProxy(
8519 store,
8520 props.onKeyDownCapture,
8521 previousElementRef
8522 );
8523 const onKeyUpCapture = useKeyboardEventProxy(
8524 store,
8525 props.onKeyUpCapture,
8526 previousElementRef
8527 );
8528 const onFocusCaptureProp = props.onFocusCapture;
8529 const onFocusCapture = useEvent((event) => {
8530 onFocusCaptureProp == null ? void 0 : onFocusCaptureProp(event);
8531 if (event.defaultPrevented) return;
8532 if (!store) return;
8533 const { virtualFocus: virtualFocus2 } = store.getState();
8534 if (!virtualFocus2) return;
8535 const previousActiveElement = event.relatedTarget;
8536 const isSilentlyFocused = silentlyFocused(event.currentTarget);
8537 if (isSelfTarget(event) && isSilentlyFocused) {
8538 event.stopPropagation();
8539 previousElementRef.current = previousActiveElement;
8540 }
8541 });
8542 const onFocusProp = props.onFocus;
8543 const onFocus = useEvent((event) => {
8544 onFocusProp == null ? void 0 : onFocusProp(event);
8545 if (event.defaultPrevented) return;
8546 if (!composite) return;
8547 if (!store) return;
8548 const { relatedTarget } = event;
8549 const { virtualFocus: virtualFocus2 } = store.getState();
8550 if (virtualFocus2) {
8551 if (isSelfTarget(event) && !isItem(store, relatedTarget)) {
8552 queueMicrotask(scheduleFocus);
8553 }
8554 } else if (isSelfTarget(event)) {
8555 store.setActiveId(null);
8556 }
8557 });
8558 const onBlurCaptureProp = props.onBlurCapture;
8559 const onBlurCapture = useEvent((event) => {
8560 var _a;
8561 onBlurCaptureProp == null ? void 0 : onBlurCaptureProp(event);
8562 if (event.defaultPrevented) return;
8563 if (!store) return;
8564 const { virtualFocus: virtualFocus2, activeId: activeId2 } = store.getState();
8565 if (!virtualFocus2) return;
8566 const activeElement = (_a = getEnabledItem(store, activeId2)) == null ? void 0 : _a.element;
8567 const nextActiveElement = event.relatedTarget;
8568 const nextActiveElementIsItem = isItem(store, nextActiveElement);
8569 const previousElement = previousElementRef.current;
8570 previousElementRef.current = null;
8571 if (isSelfTarget(event) && nextActiveElementIsItem) {
8572 if (nextActiveElement === activeElement) {
8573 if (previousElement && previousElement !== nextActiveElement) {
8574 fireBlurEvent(previousElement, event);
8575 }
8576 } else if (activeElement) {
8577 fireBlurEvent(activeElement, event);
8578 } else if (previousElement) {
8579 fireBlurEvent(previousElement, event);
8580 }
8581 event.stopPropagation();
8582 } else {
8583 const targetIsItem = isItem(store, event.target);
8584 if (!targetIsItem && activeElement) {
8585 fireBlurEvent(activeElement, event);
8586 }
8587 }
8588 });
8589 const onKeyDownProp = props.onKeyDown;
8590 const moveOnKeyPressProp = useBooleanEvent(moveOnKeyPress);
8591 const onKeyDown = useEvent((event) => {
8592 var _a;
8593 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
8594 if (event.nativeEvent.isComposing) return;
8595 if (event.defaultPrevented) return;
8596 if (!store) return;
8597 if (!isSelfTarget(event)) return;
8598 const { orientation, renderedItems, activeId: activeId2 } = store.getState();
8599 const activeItem = getEnabledItem(store, activeId2);
8600 if ((_a = activeItem == null ? void 0 : activeItem.element) == null ? void 0 : _a.isConnected) return;
8601 const isVertical = orientation !== "horizontal";
8602 const isHorizontal = orientation !== "vertical";
8603 const grid = isGrid(renderedItems);
8604 const isHorizontalKey = event.key === "ArrowLeft" || event.key === "ArrowRight" || event.key === "Home" || event.key === "End";
8605 if (isHorizontalKey && isTextField(event.currentTarget)) return;
8606 const up = () => {
8607 if (grid) {
8608 const item = findFirstEnabledItemInTheLastRow(renderedItems);
8609 return item == null ? void 0 : item.id;
8610 }
8611 return store == null ? void 0 : store.last();
8612 };
8613 const keyMap = {
8614 ArrowUp: (grid || isVertical) && up,
8615 ArrowRight: (grid || isHorizontal) && store.first,
8616 ArrowDown: (grid || isVertical) && store.first,
8617 ArrowLeft: (grid || isHorizontal) && store.last,
8618 Home: store.first,
8619 End: store.last,
8620 PageUp: store.first,
8621 PageDown: store.last
8622 };
8623 const action = keyMap[event.key];
8624 if (action) {
8625 const id = action();
8626 if (id !== void 0) {
8627 if (!moveOnKeyPressProp(event)) return;
8628 event.preventDefault();
8629 store.move(id);
8630 }
8631 }
8632 });
8633 props = useWrapElement(
8634 props,
8635 (element) => /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(CompositeContextProvider, { value: store, children: element }),
8636 [store]
8637 );
8638 const activeDescendant = store.useState((state) => {
8639 var _a;
8640 if (!store) return;
8641 if (!composite) return;
8642 if (!state.virtualFocus) return;
8643 return (_a = getEnabledItem(store, state.activeId)) == null ? void 0 : _a.id;
8644 });
8645 props = {
8646 "aria-activedescendant": activeDescendant,
8647 ...props,
8648 ref: useMergeRefs(ref, setBaseElement, props.ref),
8649 onKeyDownCapture,
8650 onKeyUpCapture,
8651 onFocusCapture,
8652 onFocus,
8653 onBlurCapture,
8654 onKeyDown
8655 };
8656 const focusable = store.useState(
8657 (state) => composite && (state.virtualFocus || state.activeId === null)
8658 );
8659 props = useFocusable({ focusable, ...props });
8660 return props;
8661 }
8662 );
8663 var Composite5 = forwardRef22(function Composite22(props) {
8664 const htmlProps = useComposite(props);
8665 return createElement3(TagName5, htmlProps);
8666 });
8667
8668 // node_modules/@ariakit/react-core/esm/__chunks/LVDQFHCH.js
8669 var ctx3 = createStoreContext();
8670 var useDisclosureContext = ctx3.useContext;
8671 var useDisclosureScopedContext = ctx3.useScopedContext;
8672 var useDisclosureProviderContext = ctx3.useProviderContext;
8673 var DisclosureContextProvider = ctx3.ContextProvider;
8674 var DisclosureScopedContextProvider = ctx3.ScopedContextProvider;
8675
8676 // node_modules/@ariakit/react-core/esm/__chunks/A62MDFCW.js
8677 var import_react13 = __toESM(require_react(), 1);
8678 var ctx4 = createStoreContext(
8679 [DisclosureContextProvider],
8680 [DisclosureScopedContextProvider]
8681 );
8682 var useDialogContext = ctx4.useContext;
8683 var useDialogScopedContext = ctx4.useScopedContext;
8684 var useDialogProviderContext = ctx4.useProviderContext;
8685 var DialogContextProvider = ctx4.ContextProvider;
8686 var DialogScopedContextProvider = ctx4.ScopedContextProvider;
8687 var DialogHeadingContext = (0, import_react13.createContext)(void 0);
8688 var DialogDescriptionContext = (0, import_react13.createContext)(void 0);
8689
8690 // node_modules/@ariakit/react-core/esm/__chunks/6B3RXHKP.js
8691 var import_react14 = __toESM(require_react(), 1);
8692 var import_react_dom = __toESM(require_react_dom(), 1);
8693 var import_jsx_runtime57 = __toESM(require_jsx_runtime(), 1);
8694 var TagName6 = "div";
8695 function afterTimeout(timeoutMs, cb) {
8696 const timeoutId = setTimeout(cb, timeoutMs);
8697 return () => clearTimeout(timeoutId);
8698 }
8699 function afterPaint2(cb) {
8700 let raf = requestAnimationFrame(() => {
8701 raf = requestAnimationFrame(cb);
8702 });
8703 return () => cancelAnimationFrame(raf);
8704 }
8705 function parseCSSTime(...times) {
8706 return times.join(", ").split(", ").reduce((longestTime, currentTimeString) => {
8707 const multiplier = currentTimeString.endsWith("ms") ? 1 : 1e3;
8708 const currentTime = Number.parseFloat(currentTimeString || "0s") * multiplier;
8709 if (currentTime > longestTime) return currentTime;
8710 return longestTime;
8711 }, 0);
8712 }
8713 function isHidden(mounted, hidden, alwaysVisible) {
8714 return !alwaysVisible && hidden !== false && (!mounted || !!hidden);
8715 }
8716 var useDisclosureContent = createHook(function useDisclosureContent2({ store, alwaysVisible, ...props }) {
8717 const context = useDisclosureProviderContext();
8718 store = store || context;
8719 invariant(
8720 store,
8721 "DisclosureContent must receive a `store` prop or be wrapped in a DisclosureProvider component."
8722 );
8723 const ref = (0, import_react14.useRef)(null);
8724 const id = useId3(props.id);
8725 const [transition, setTransition] = (0, import_react14.useState)(null);
8726 const open = store.useState("open");
8727 const mounted = store.useState("mounted");
8728 const animated = store.useState("animated");
8729 const contentElement = store.useState("contentElement");
8730 const otherElement = useStoreState(store.disclosure, "contentElement");
8731 useSafeLayoutEffect(() => {
8732 if (!ref.current) return;
8733 store == null ? void 0 : store.setContentElement(ref.current);
8734 }, [store]);
8735 useSafeLayoutEffect(() => {
8736 let previousAnimated;
8737 store == null ? void 0 : store.setState("animated", (animated2) => {
8738 previousAnimated = animated2;
8739 return true;
8740 });
8741 return () => {
8742 if (previousAnimated === void 0) return;
8743 store == null ? void 0 : store.setState("animated", previousAnimated);
8744 };
8745 }, [store]);
8746 useSafeLayoutEffect(() => {
8747 if (!animated) return;
8748 if (!(contentElement == null ? void 0 : contentElement.isConnected)) {
8749 setTransition(null);
8750 return;
8751 }
8752 return afterPaint2(() => {
8753 setTransition(open ? "enter" : mounted ? "leave" : null);
8754 });
8755 }, [animated, contentElement, open, mounted]);
8756 useSafeLayoutEffect(() => {
8757 if (!store) return;
8758 if (!animated) return;
8759 if (!transition) return;
8760 if (!contentElement) return;
8761 const stopAnimation = () => store == null ? void 0 : store.setState("animating", false);
8762 const stopAnimationSync = () => (0, import_react_dom.flushSync)(stopAnimation);
8763 if (transition === "leave" && open) return;
8764 if (transition === "enter" && !open) return;
8765 if (typeof animated === "number") {
8766 const timeout2 = animated;
8767 return afterTimeout(timeout2, stopAnimationSync);
8768 }
8769 const {
8770 transitionDuration,
8771 animationDuration,
8772 transitionDelay,
8773 animationDelay
8774 } = getComputedStyle(contentElement);
8775 const {
8776 transitionDuration: transitionDuration2 = "0",
8777 animationDuration: animationDuration2 = "0",
8778 transitionDelay: transitionDelay2 = "0",
8779 animationDelay: animationDelay2 = "0"
8780 } = otherElement ? getComputedStyle(otherElement) : {};
8781 const delay = parseCSSTime(
8782 transitionDelay,
8783 animationDelay,
8784 transitionDelay2,
8785 animationDelay2
8786 );
8787 const duration = parseCSSTime(
8788 transitionDuration,
8789 animationDuration,
8790 transitionDuration2,
8791 animationDuration2
8792 );
8793 const timeout = delay + duration;
8794 if (!timeout) {
8795 if (transition === "enter") {
8796 store.setState("animated", false);
8797 }
8798 stopAnimation();
8799 return;
8800 }
8801 const frameRate = 1e3 / 60;
8802 const maxTimeout = Math.max(timeout - frameRate, 0);
8803 return afterTimeout(maxTimeout, stopAnimationSync);
8804 }, [store, animated, contentElement, otherElement, open, transition]);
8805 props = useWrapElement(
8806 props,
8807 (element) => /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(DialogScopedContextProvider, { value: store, children: element }),
8808 [store]
8809 );
8810 const hidden = isHidden(mounted, props.hidden, alwaysVisible);
8811 const styleProp = props.style;
8812 const style = (0, import_react14.useMemo)(() => {
8813 if (hidden) {
8814 return { ...styleProp, display: "none" };
8815 }
8816 return styleProp;
8817 }, [hidden, styleProp]);
8818 props = {
8819 id,
8820 "data-open": open || void 0,
8821 "data-enter": transition === "enter" || void 0,
8822 "data-leave": transition === "leave" || void 0,
8823 hidden,
8824 ...props,
8825 ref: useMergeRefs(id ? store.setContentElement : null, ref, props.ref),
8826 style
8827 };
8828 return removeUndefinedValues(props);
8829 });
8830 var DisclosureContentImpl = forwardRef22(function DisclosureContentImpl2(props) {
8831 const htmlProps = useDisclosureContent(props);
8832 return createElement3(TagName6, htmlProps);
8833 });
8834 var DisclosureContent = forwardRef22(function DisclosureContent2({
8835 unmountOnHide,
8836 ...props
8837 }) {
8838 const context = useDisclosureProviderContext();
8839 const store = props.store || context;
8840 const mounted = useStoreState(
8841 store,
8842 (state) => !unmountOnHide || (state == null ? void 0 : state.mounted)
8843 );
8844 if (mounted === false) return null;
8845 return /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(DisclosureContentImpl, { ...props });
8846 });
8847
8848 // node_modules/@ariakit/core/esm/__chunks/75BJEVSH.js
8849 function createDisclosureStore(props = {}) {
8850 const store = mergeStore(
8851 props.store,
8852 omit2(props.disclosure, ["contentElement", "disclosureElement"])
8853 );
8854 throwOnConflictingProps(props, store);
8855 const syncState = store == null ? void 0 : store.getState();
8856 const open = defaultValue(
8857 props.open,
8858 syncState == null ? void 0 : syncState.open,
8859 props.defaultOpen,
8860 false
8861 );
8862 const animated = defaultValue(props.animated, syncState == null ? void 0 : syncState.animated, false);
8863 const initialState = {
8864 open,
8865 animated,
8866 animating: !!animated && open,
8867 mounted: open,
8868 contentElement: defaultValue(syncState == null ? void 0 : syncState.contentElement, null),
8869 disclosureElement: defaultValue(syncState == null ? void 0 : syncState.disclosureElement, null)
8870 };
8871 const disclosure = createStore(initialState, store);
8872 setup(
8873 disclosure,
8874 () => sync(disclosure, ["animated", "animating"], (state) => {
8875 if (state.animated) return;
8876 disclosure.setState("animating", false);
8877 })
8878 );
8879 setup(
8880 disclosure,
8881 () => subscribe(disclosure, ["open"], () => {
8882 if (!disclosure.getState().animated) return;
8883 disclosure.setState("animating", true);
8884 })
8885 );
8886 setup(
8887 disclosure,
8888 () => sync(disclosure, ["open", "animating"], (state) => {
8889 disclosure.setState("mounted", state.open || state.animating);
8890 })
8891 );
8892 return {
8893 ...disclosure,
8894 disclosure: props.disclosure,
8895 setOpen: (value) => disclosure.setState("open", value),
8896 show: () => disclosure.setState("open", true),
8897 hide: () => disclosure.setState("open", false),
8898 toggle: () => disclosure.setState("open", (open2) => !open2),
8899 stopAnimation: () => disclosure.setState("animating", false),
8900 setContentElement: (value) => disclosure.setState("contentElement", value),
8901 setDisclosureElement: (value) => disclosure.setState("disclosureElement", value)
8902 };
8903 }
8904
8905 // node_modules/@ariakit/react-core/esm/__chunks/WLZ6H5FH.js
8906 function useDisclosureStoreProps(store, update2, props) {
8907 useUpdateEffect(update2, [props.store, props.disclosure]);
8908 useStoreProps(store, props, "open", "setOpen");
8909 useStoreProps(store, props, "mounted", "setMounted");
8910 useStoreProps(store, props, "animated");
8911 return Object.assign(store, { disclosure: props.disclosure });
8912 }
8913
8914 // node_modules/@ariakit/react-core/esm/__chunks/JMU4N4M5.js
8915 var ctx5 = createStoreContext(
8916 [DialogContextProvider],
8917 [DialogScopedContextProvider]
8918 );
8919 var usePopoverContext = ctx5.useContext;
8920 var usePopoverScopedContext = ctx5.useScopedContext;
8921 var usePopoverProviderContext = ctx5.useProviderContext;
8922 var PopoverContextProvider = ctx5.ContextProvider;
8923 var PopoverScopedContextProvider = ctx5.ScopedContextProvider;
8924
8925 // node_modules/@ariakit/core/esm/__chunks/N5XGANPW.js
8926 function getCommonParent(items) {
8927 var _a;
8928 const firstItem = items.find((item) => !!item.element);
8929 const lastItem = [...items].reverse().find((item) => !!item.element);
8930 let parentElement = (_a = firstItem == null ? void 0 : firstItem.element) == null ? void 0 : _a.parentElement;
8931 while (parentElement && (lastItem == null ? void 0 : lastItem.element)) {
8932 const parent = parentElement;
8933 if (lastItem && parent.contains(lastItem.element)) {
8934 return parentElement;
8935 }
8936 parentElement = parentElement.parentElement;
8937 }
8938 return getDocument(parentElement).body;
8939 }
8940 function getPrivateStore(store) {
8941 return store == null ? void 0 : store.__unstablePrivateStore;
8942 }
8943 function createCollectionStore(props = {}) {
8944 var _a;
8945 throwOnConflictingProps(props, props.store);
8946 const syncState = (_a = props.store) == null ? void 0 : _a.getState();
8947 const items = defaultValue(
8948 props.items,
8949 syncState == null ? void 0 : syncState.items,
8950 props.defaultItems,
8951 []
8952 );
8953 const itemsMap = new Map(items.map((item) => [item.id, item]));
8954 const initialState = {
8955 items,
8956 renderedItems: defaultValue(syncState == null ? void 0 : syncState.renderedItems, [])
8957 };
8958 const syncPrivateStore = getPrivateStore(props.store);
8959 const privateStore = createStore(
8960 { items, renderedItems: initialState.renderedItems },
8961 syncPrivateStore
8962 );
8963 const collection = createStore(initialState, props.store);
8964 const sortItems = (renderedItems) => {
8965 const sortedItems = sortBasedOnDOMPosition(renderedItems, (i2) => i2.element);
8966 privateStore.setState("renderedItems", sortedItems);
8967 collection.setState("renderedItems", sortedItems);
8968 };
8969 setup(collection, () => init(privateStore));
8970 setup(privateStore, () => {
8971 return batch(privateStore, ["items"], (state) => {
8972 collection.setState("items", state.items);
8973 });
8974 });
8975 setup(privateStore, () => {
8976 return batch(privateStore, ["renderedItems"], (state) => {
8977 let firstRun = true;
8978 let raf = requestAnimationFrame(() => {
8979 const { renderedItems } = collection.getState();
8980 if (state.renderedItems === renderedItems) return;
8981 sortItems(state.renderedItems);
8982 });
8983 if (typeof IntersectionObserver !== "function") {
8984 return () => cancelAnimationFrame(raf);
8985 }
8986 const ioCallback = () => {
8987 if (firstRun) {
8988 firstRun = false;
8989 return;
8990 }
8991 cancelAnimationFrame(raf);
8992 raf = requestAnimationFrame(() => sortItems(state.renderedItems));
8993 };
8994 const root = getCommonParent(state.renderedItems);
8995 const observer = new IntersectionObserver(ioCallback, { root });
8996 for (const item of state.renderedItems) {
8997 if (!item.element) continue;
8998 observer.observe(item.element);
8999 }
9000 return () => {
9001 cancelAnimationFrame(raf);
9002 observer.disconnect();
9003 };
9004 });
9005 });
9006 const mergeItem = (item, setItems, canDeleteFromMap = false) => {
9007 let prevItem;
9008 setItems((items2) => {
9009 const index = items2.findIndex(({ id }) => id === item.id);
9010 const nextItems = items2.slice();
9011 if (index !== -1) {
9012 prevItem = items2[index];
9013 const nextItem = { ...prevItem, ...item };
9014 nextItems[index] = nextItem;
9015 itemsMap.set(item.id, nextItem);
9016 } else {
9017 nextItems.push(item);
9018 itemsMap.set(item.id, item);
9019 }
9020 return nextItems;
9021 });
9022 const unmergeItem = () => {
9023 setItems((items2) => {
9024 if (!prevItem) {
9025 if (canDeleteFromMap) {
9026 itemsMap.delete(item.id);
9027 }
9028 return items2.filter(({ id }) => id !== item.id);
9029 }
9030 const index = items2.findIndex(({ id }) => id === item.id);
9031 if (index === -1) return items2;
9032 const nextItems = items2.slice();
9033 nextItems[index] = prevItem;
9034 itemsMap.set(item.id, prevItem);
9035 return nextItems;
9036 });
9037 };
9038 return unmergeItem;
9039 };
9040 const registerItem = (item) => mergeItem(
9041 item,
9042 (getItems) => privateStore.setState("items", getItems),
9043 true
9044 );
9045 return {
9046 ...collection,
9047 registerItem,
9048 renderItem: (item) => chain(
9049 registerItem(item),
9050 mergeItem(
9051 item,
9052 (getItems) => privateStore.setState("renderedItems", getItems)
9053 )
9054 ),
9055 item: (id) => {
9056 if (!id) return null;
9057 let item = itemsMap.get(id);
9058 if (!item) {
9059 const { items: items2 } = privateStore.getState();
9060 item = items2.find((item2) => item2.id === id);
9061 if (item) {
9062 itemsMap.set(id, item);
9063 }
9064 }
9065 return item || null;
9066 },
9067 // @ts-expect-error Internal
9068 __unstablePrivateStore: privateStore
9069 };
9070 }
9071
9072 // node_modules/@ariakit/react-core/esm/__chunks/GVAFFF2B.js
9073 function useCollectionStoreProps(store, update2, props) {
9074 useUpdateEffect(update2, [props.store]);
9075 useStoreProps(store, props, "items", "setItems");
9076 return store;
9077 }
9078
9079 // node_modules/@ariakit/core/esm/__chunks/RVTIKFRL.js
9080 var NULL_ITEM = { id: null };
9081 function findFirstEnabledItem2(items, excludeId) {
9082 return items.find((item) => {
9083 if (excludeId) {
9084 return !item.disabled && item.id !== excludeId;
9085 }
9086 return !item.disabled;
9087 });
9088 }
9089 function getEnabledItems(items, excludeId) {
9090 return items.filter((item) => {
9091 if (excludeId) {
9092 return !item.disabled && item.id !== excludeId;
9093 }
9094 return !item.disabled;
9095 });
9096 }
9097 function getItemsInRow(items, rowId) {
9098 return items.filter((item) => item.rowId === rowId);
9099 }
9100 function flipItems(items, activeId, shouldInsertNullItem = false) {
9101 const index = items.findIndex((item) => item.id === activeId);
9102 return [
9103 ...items.slice(index + 1),
9104 ...shouldInsertNullItem ? [NULL_ITEM] : [],
9105 ...items.slice(0, index)
9106 ];
9107 }
9108 function groupItemsByRows2(items) {
9109 const rows = [];
9110 for (const item of items) {
9111 const row = rows.find((currentRow) => {
9112 var _a;
9113 return ((_a = currentRow[0]) == null ? void 0 : _a.rowId) === item.rowId;
9114 });
9115 if (row) {
9116 row.push(item);
9117 } else {
9118 rows.push([item]);
9119 }
9120 }
9121 return rows;
9122 }
9123 function getMaxRowLength(array) {
9124 let maxLength = 0;
9125 for (const { length } of array) {
9126 if (length > maxLength) {
9127 maxLength = length;
9128 }
9129 }
9130 return maxLength;
9131 }
9132 function createEmptyItem(rowId) {
9133 return {
9134 id: "__EMPTY_ITEM__",
9135 disabled: true,
9136 rowId
9137 };
9138 }
9139 function normalizeRows(rows, activeId, focusShift) {
9140 const maxLength = getMaxRowLength(rows);
9141 for (const row of rows) {
9142 for (let i2 = 0; i2 < maxLength; i2 += 1) {
9143 const item = row[i2];
9144 if (!item || focusShift && item.disabled) {
9145 const isFirst = i2 === 0;
9146 const previousItem = isFirst && focusShift ? findFirstEnabledItem2(row) : row[i2 - 1];
9147 row[i2] = previousItem && activeId !== previousItem.id && focusShift ? previousItem : createEmptyItem(previousItem == null ? void 0 : previousItem.rowId);
9148 }
9149 }
9150 }
9151 return rows;
9152 }
9153 function verticalizeItems(items) {
9154 const rows = groupItemsByRows2(items);
9155 const maxLength = getMaxRowLength(rows);
9156 const verticalized = [];
9157 for (let i2 = 0; i2 < maxLength; i2 += 1) {
9158 for (const row of rows) {
9159 const item = row[i2];
9160 if (item) {
9161 verticalized.push({
9162 ...item,
9163 // If there's no rowId, it means that it's not a grid composite, but
9164 // a single row instead. So, instead of verticalizing it, that is,
9165 // assigning a different rowId based on the column index, we keep it
9166 // undefined so they will be part of the same row. This is useful
9167 // when using up/down on one-dimensional composites.
9168 rowId: item.rowId ? `${i2}` : void 0
9169 });
9170 }
9171 }
9172 }
9173 return verticalized;
9174 }
9175 function createCompositeStore(props = {}) {
9176 var _a;
9177 const syncState = (_a = props.store) == null ? void 0 : _a.getState();
9178 const collection = createCollectionStore(props);
9179 const activeId = defaultValue(
9180 props.activeId,
9181 syncState == null ? void 0 : syncState.activeId,
9182 props.defaultActiveId
9183 );
9184 const initialState = {
9185 ...collection.getState(),
9186 id: defaultValue(
9187 props.id,
9188 syncState == null ? void 0 : syncState.id,
9189 `id-${Math.random().toString(36).slice(2, 8)}`
9190 ),
9191 activeId,
9192 baseElement: defaultValue(syncState == null ? void 0 : syncState.baseElement, null),
9193 includesBaseElement: defaultValue(
9194 props.includesBaseElement,
9195 syncState == null ? void 0 : syncState.includesBaseElement,
9196 activeId === null
9197 ),
9198 moves: defaultValue(syncState == null ? void 0 : syncState.moves, 0),
9199 orientation: defaultValue(
9200 props.orientation,
9201 syncState == null ? void 0 : syncState.orientation,
9202 "both"
9203 ),
9204 rtl: defaultValue(props.rtl, syncState == null ? void 0 : syncState.rtl, false),
9205 virtualFocus: defaultValue(
9206 props.virtualFocus,
9207 syncState == null ? void 0 : syncState.virtualFocus,
9208 false
9209 ),
9210 focusLoop: defaultValue(props.focusLoop, syncState == null ? void 0 : syncState.focusLoop, false),
9211 focusWrap: defaultValue(props.focusWrap, syncState == null ? void 0 : syncState.focusWrap, false),
9212 focusShift: defaultValue(props.focusShift, syncState == null ? void 0 : syncState.focusShift, false)
9213 };
9214 const composite = createStore(initialState, collection, props.store);
9215 setup(
9216 composite,
9217 () => sync(composite, ["renderedItems", "activeId"], (state) => {
9218 composite.setState("activeId", (activeId2) => {
9219 var _a2;
9220 if (activeId2 !== void 0) return activeId2;
9221 return (_a2 = findFirstEnabledItem2(state.renderedItems)) == null ? void 0 : _a2.id;
9222 });
9223 })
9224 );
9225 const getNextId = (direction = "next", options = {}) => {
9226 var _a2, _b;
9227 const defaultState = composite.getState();
9228 const {
9229 skip = 0,
9230 activeId: activeId2 = defaultState.activeId,
9231 focusShift = defaultState.focusShift,
9232 focusLoop = defaultState.focusLoop,
9233 focusWrap = defaultState.focusWrap,
9234 includesBaseElement = defaultState.includesBaseElement,
9235 renderedItems = defaultState.renderedItems,
9236 rtl = defaultState.rtl
9237 } = options;
9238 const isVerticalDirection = direction === "up" || direction === "down";
9239 const isNextDirection = direction === "next" || direction === "down";
9240 const canReverse = isNextDirection ? rtl && !isVerticalDirection : !rtl || isVerticalDirection;
9241 const canShift = focusShift && !skip;
9242 let items = !isVerticalDirection ? renderedItems : flatten2DArray(
9243 normalizeRows(groupItemsByRows2(renderedItems), activeId2, canShift)
9244 );
9245 items = canReverse ? reverseArray(items) : items;
9246 items = isVerticalDirection ? verticalizeItems(items) : items;
9247 if (activeId2 == null) {
9248 return (_a2 = findFirstEnabledItem2(items)) == null ? void 0 : _a2.id;
9249 }
9250 const activeItem = items.find((item) => item.id === activeId2);
9251 if (!activeItem) {
9252 return (_b = findFirstEnabledItem2(items)) == null ? void 0 : _b.id;
9253 }
9254 const isGrid2 = items.some((item) => item.rowId);
9255 const activeIndex = items.indexOf(activeItem);
9256 const nextItems = items.slice(activeIndex + 1);
9257 const nextItemsInRow = getItemsInRow(nextItems, activeItem.rowId);
9258 if (skip) {
9259 const nextEnabledItemsInRow = getEnabledItems(nextItemsInRow, activeId2);
9260 const nextItem2 = nextEnabledItemsInRow.slice(skip)[0] || // If we can't find an item, just return the last one.
9261 nextEnabledItemsInRow[nextEnabledItemsInRow.length - 1];
9262 return nextItem2 == null ? void 0 : nextItem2.id;
9263 }
9264 const canLoop = focusLoop && (isVerticalDirection ? focusLoop !== "horizontal" : focusLoop !== "vertical");
9265 const canWrap = isGrid2 && focusWrap && (isVerticalDirection ? focusWrap !== "horizontal" : focusWrap !== "vertical");
9266 const hasNullItem = isNextDirection ? (!isGrid2 || isVerticalDirection) && canLoop && includesBaseElement : isVerticalDirection ? includesBaseElement : false;
9267 if (canLoop) {
9268 const loopItems = canWrap && !hasNullItem ? items : getItemsInRow(items, activeItem.rowId);
9269 const sortedItems = flipItems(loopItems, activeId2, hasNullItem);
9270 const nextItem2 = findFirstEnabledItem2(sortedItems, activeId2);
9271 return nextItem2 == null ? void 0 : nextItem2.id;
9272 }
9273 if (canWrap) {
9274 const nextItem2 = findFirstEnabledItem2(
9275 // We can use nextItems, which contains all the next items, including
9276 // items from other rows, to wrap between rows. However, if there is a
9277 // null item (the composite container), we'll only use the next items in
9278 // the row. So moving next from the last item will focus on the
9279 // composite container. On grid composites, horizontal navigation never
9280 // focuses on the composite container, only vertical.
9281 hasNullItem ? nextItemsInRow : nextItems,
9282 activeId2
9283 );
9284 const nextId = hasNullItem ? (nextItem2 == null ? void 0 : nextItem2.id) || null : nextItem2 == null ? void 0 : nextItem2.id;
9285 return nextId;
9286 }
9287 const nextItem = findFirstEnabledItem2(nextItemsInRow, activeId2);
9288 if (!nextItem && hasNullItem) {
9289 return null;
9290 }
9291 return nextItem == null ? void 0 : nextItem.id;
9292 };
9293 return {
9294 ...collection,
9295 ...composite,
9296 setBaseElement: (element) => composite.setState("baseElement", element),
9297 setActiveId: (id) => composite.setState("activeId", id),
9298 move: (id) => {
9299 if (id === void 0) return;
9300 composite.setState("activeId", id);
9301 composite.setState("moves", (moves) => moves + 1);
9302 },
9303 first: () => {
9304 var _a2;
9305 return (_a2 = findFirstEnabledItem2(composite.getState().renderedItems)) == null ? void 0 : _a2.id;
9306 },
9307 last: () => {
9308 var _a2;
9309 return (_a2 = findFirstEnabledItem2(reverseArray(composite.getState().renderedItems))) == null ? void 0 : _a2.id;
9310 },
9311 next: (options) => {
9312 if (options !== void 0 && typeof options === "number") {
9313 options = { skip: options };
9314 }
9315 return getNextId("next", options);
9316 },
9317 previous: (options) => {
9318 if (options !== void 0 && typeof options === "number") {
9319 options = { skip: options };
9320 }
9321 return getNextId("previous", options);
9322 },
9323 down: (options) => {
9324 if (options !== void 0 && typeof options === "number") {
9325 options = { skip: options };
9326 }
9327 return getNextId("down", options);
9328 },
9329 up: (options) => {
9330 if (options !== void 0 && typeof options === "number") {
9331 options = { skip: options };
9332 }
9333 return getNextId("up", options);
9334 }
9335 };
9336 }
9337
9338 // node_modules/@ariakit/react-core/esm/__chunks/IQYAUKXT.js
9339 function useCompositeStoreOptions(props) {
9340 const id = useId3(props.id);
9341 return { id, ...props };
9342 }
9343 function useCompositeStoreProps(store, update2, props) {
9344 store = useCollectionStoreProps(store, update2, props);
9345 useStoreProps(store, props, "activeId", "setActiveId");
9346 useStoreProps(store, props, "includesBaseElement");
9347 useStoreProps(store, props, "virtualFocus");
9348 useStoreProps(store, props, "orientation");
9349 useStoreProps(store, props, "rtl");
9350 useStoreProps(store, props, "focusLoop");
9351 useStoreProps(store, props, "focusWrap");
9352 useStoreProps(store, props, "focusShift");
9353 return store;
9354 }
9355
9356 // node_modules/@ariakit/react-core/esm/__chunks/CVCFNOHX.js
9357 var import_react15 = __toESM(require_react(), 1);
9358 var ComboboxListRoleContext = (0, import_react15.createContext)(
9359 void 0
9360 );
9361 var ctx6 = createStoreContext(
9362 [PopoverContextProvider, CompositeContextProvider],
9363 [PopoverScopedContextProvider, CompositeScopedContextProvider]
9364 );
9365 var useComboboxContext = ctx6.useContext;
9366 var useComboboxScopedContext = ctx6.useScopedContext;
9367 var useComboboxProviderContext = ctx6.useProviderContext;
9368 var ComboboxContextProvider = ctx6.ContextProvider;
9369 var ComboboxScopedContextProvider = ctx6.ScopedContextProvider;
9370 var ComboboxItemValueContext = (0, import_react15.createContext)(
9371 void 0
9372 );
9373 var ComboboxItemCheckedContext = (0, import_react15.createContext)(false);
9374
9375 // node_modules/@ariakit/core/esm/__chunks/KMAUV3TY.js
9376 function createDialogStore(props = {}) {
9377 return createDisclosureStore(props);
9378 }
9379
9380 // node_modules/@ariakit/react-core/esm/__chunks/4NYSH4UO.js
9381 function useDialogStoreProps(store, update2, props) {
9382 return useDisclosureStoreProps(store, update2, props);
9383 }
9384
9385 // node_modules/@ariakit/core/esm/__chunks/BFGNM53A.js
9386 function createPopoverStore({
9387 popover: otherPopover,
9388 ...props
9389 } = {}) {
9390 const store = mergeStore(
9391 props.store,
9392 omit2(otherPopover, [
9393 "arrowElement",
9394 "anchorElement",
9395 "contentElement",
9396 "popoverElement",
9397 "disclosureElement"
9398 ])
9399 );
9400 throwOnConflictingProps(props, store);
9401 const syncState = store == null ? void 0 : store.getState();
9402 const dialog = createDialogStore({ ...props, store });
9403 const placement = defaultValue(
9404 props.placement,
9405 syncState == null ? void 0 : syncState.placement,
9406 "bottom"
9407 );
9408 const initialState = {
9409 ...dialog.getState(),
9410 placement,
9411 currentPlacement: placement,
9412 anchorElement: defaultValue(syncState == null ? void 0 : syncState.anchorElement, null),
9413 popoverElement: defaultValue(syncState == null ? void 0 : syncState.popoverElement, null),
9414 arrowElement: defaultValue(syncState == null ? void 0 : syncState.arrowElement, null),
9415 rendered: /* @__PURE__ */ Symbol("rendered")
9416 };
9417 const popover = createStore(initialState, dialog, store);
9418 return {
9419 ...dialog,
9420 ...popover,
9421 setAnchorElement: (element) => popover.setState("anchorElement", element),
9422 setPopoverElement: (element) => popover.setState("popoverElement", element),
9423 setArrowElement: (element) => popover.setState("arrowElement", element),
9424 render: () => popover.setState("rendered", /* @__PURE__ */ Symbol("rendered"))
9425 };
9426 }
9427
9428 // node_modules/@ariakit/react-core/esm/__chunks/B6FLPFJM.js
9429 function usePopoverStoreProps(store, update2, props) {
9430 useUpdateEffect(update2, [props.popover]);
9431 useStoreProps(store, props, "placement");
9432 return useDialogStoreProps(store, update2, props);
9433 }
9434
9435 // node_modules/@ariakit/react-core/esm/__chunks/4POTBZ2J.js
9436 var TagName7 = "div";
9437 var usePopoverAnchor = createHook(
9438 function usePopoverAnchor2({ store, ...props }) {
9439 const context = usePopoverProviderContext();
9440 store = store || context;
9441 props = {
9442 ...props,
9443 ref: useMergeRefs(store == null ? void 0 : store.setAnchorElement, props.ref)
9444 };
9445 return props;
9446 }
9447 );
9448 var PopoverAnchor = forwardRef22(function PopoverAnchor2(props) {
9449 const htmlProps = usePopoverAnchor(props);
9450 return createElement3(TagName7, htmlProps);
9451 });
9452
9453 // node_modules/@ariakit/react-core/esm/__chunks/X6LNAU2F.js
9454 var import_react16 = __toESM(require_react(), 1);
9455 var TagName8 = "div";
9456 function getMouseDestination(event) {
9457 const relatedTarget = event.relatedTarget;
9458 if ((relatedTarget == null ? void 0 : relatedTarget.nodeType) === Node.ELEMENT_NODE) {
9459 return relatedTarget;
9460 }
9461 return null;
9462 }
9463 function hoveringInside(event) {
9464 const nextElement = getMouseDestination(event);
9465 if (!nextElement) return false;
9466 return contains(event.currentTarget, nextElement);
9467 }
9468 var symbol2 = /* @__PURE__ */ Symbol("composite-hover");
9469 function movingToAnotherItem(event) {
9470 let dest = getMouseDestination(event);
9471 if (!dest) return false;
9472 do {
9473 if (hasOwnProperty(dest, symbol2) && dest[symbol2]) return true;
9474 dest = dest.parentElement;
9475 } while (dest);
9476 return false;
9477 }
9478 var useCompositeHover = createHook(
9479 function useCompositeHover2({
9480 store,
9481 focusOnHover = true,
9482 blurOnHoverEnd = !!focusOnHover,
9483 ...props
9484 }) {
9485 const context = useCompositeContext();
9486 store = store || context;
9487 invariant(
9488 store,
9489 "CompositeHover must be wrapped in a Composite component."
9490 );
9491 const isMouseMoving = useIsMouseMoving();
9492 const onMouseMoveProp = props.onMouseMove;
9493 const focusOnHoverProp = useBooleanEvent(focusOnHover);
9494 const onMouseMove = useEvent((event) => {
9495 onMouseMoveProp == null ? void 0 : onMouseMoveProp(event);
9496 if (event.defaultPrevented) return;
9497 if (!isMouseMoving()) return;
9498 if (!focusOnHoverProp(event)) return;
9499 if (!hasFocusWithin(event.currentTarget)) {
9500 const baseElement = store == null ? void 0 : store.getState().baseElement;
9501 if (baseElement && !hasFocus(baseElement)) {
9502 baseElement.focus();
9503 }
9504 }
9505 store == null ? void 0 : store.setActiveId(event.currentTarget.id);
9506 });
9507 const onMouseLeaveProp = props.onMouseLeave;
9508 const blurOnHoverEndProp = useBooleanEvent(blurOnHoverEnd);
9509 const onMouseLeave = useEvent((event) => {
9510 var _a;
9511 onMouseLeaveProp == null ? void 0 : onMouseLeaveProp(event);
9512 if (event.defaultPrevented) return;
9513 if (!isMouseMoving()) return;
9514 if (hoveringInside(event)) return;
9515 if (movingToAnotherItem(event)) return;
9516 if (!focusOnHoverProp(event)) return;
9517 if (!blurOnHoverEndProp(event)) return;
9518 store == null ? void 0 : store.setActiveId(null);
9519 (_a = store == null ? void 0 : store.getState().baseElement) == null ? void 0 : _a.focus();
9520 });
9521 const ref = (0, import_react16.useCallback)((element) => {
9522 if (!element) return;
9523 element[symbol2] = true;
9524 }, []);
9525 props = {
9526 ...props,
9527 ref: useMergeRefs(ref, props.ref),
9528 onMouseMove,
9529 onMouseLeave
9530 };
9531 return removeUndefinedValues(props);
9532 }
9533 );
9534 var CompositeHover = memo22(
9535 forwardRef22(function CompositeHover2(props) {
9536 const htmlProps = useCompositeHover(props);
9537 return createElement3(TagName8, htmlProps);
9538 })
9539 );
9540
9541 // node_modules/@ariakit/react-core/esm/combobox/combobox.js
9542 var import_react17 = __toESM(require_react(), 1);
9543 var TagName9 = "input";
9544 function isFirstItemAutoSelected(items, activeValue, autoSelect) {
9545 if (!autoSelect) return false;
9546 const firstItem = items.find((item) => !item.disabled && item.value);
9547 return (firstItem == null ? void 0 : firstItem.value) === activeValue;
9548 }
9549 function hasCompletionString(value, activeValue) {
9550 if (!activeValue) return false;
9551 if (value == null) return false;
9552 value = normalizeString(value);
9553 return activeValue.length > value.length && activeValue.toLowerCase().indexOf(value.toLowerCase()) === 0;
9554 }
9555 function isInputEvent(event) {
9556 return event.type === "input";
9557 }
9558 function isAriaAutoCompleteValue(value) {
9559 return value === "inline" || value === "list" || value === "both" || value === "none";
9560 }
9561 function getDefaultAutoSelectId(items) {
9562 const item = items.find((item2) => {
9563 var _a;
9564 if (item2.disabled) return false;
9565 return ((_a = item2.element) == null ? void 0 : _a.getAttribute("role")) !== "tab";
9566 });
9567 return item == null ? void 0 : item.id;
9568 }
9569 var useCombobox = createHook(
9570 function useCombobox2({
9571 store,
9572 focusable = true,
9573 autoSelect: autoSelectProp = false,
9574 getAutoSelectId,
9575 setValueOnChange,
9576 showMinLength = 0,
9577 showOnChange,
9578 showOnMouseDown,
9579 showOnClick = showOnMouseDown,
9580 showOnKeyDown,
9581 showOnKeyPress = showOnKeyDown,
9582 blurActiveItemOnClick,
9583 setValueOnClick = true,
9584 moveOnKeyPress = true,
9585 autoComplete = "list",
9586 ...props
9587 }) {
9588 const context = useComboboxProviderContext();
9589 store = store || context;
9590 invariant(
9591 store,
9592 "Combobox must receive a `store` prop or be wrapped in a ComboboxProvider component."
9593 );
9594 const ref = (0, import_react17.useRef)(null);
9595 const [valueUpdated, forceValueUpdate] = useForceUpdate();
9596 const canAutoSelectRef = (0, import_react17.useRef)(false);
9597 const composingRef = (0, import_react17.useRef)(false);
9598 const autoSelect = store.useState(
9599 (state) => state.virtualFocus && autoSelectProp
9600 );
9601 const inline = autoComplete === "inline" || autoComplete === "both";
9602 const [canInline, setCanInline] = (0, import_react17.useState)(inline);
9603 useUpdateLayoutEffect(() => {
9604 if (!inline) return;
9605 setCanInline(true);
9606 }, [inline]);
9607 const storeValue = store.useState("value");
9608 const prevSelectedValueRef = (0, import_react17.useRef)(void 0);
9609 (0, import_react17.useEffect)(() => {
9610 return sync(store, ["selectedValue", "activeId"], (_, prev) => {
9611 prevSelectedValueRef.current = prev.selectedValue;
9612 });
9613 }, []);
9614 const inlineActiveValue = store.useState((state) => {
9615 var _a;
9616 if (!inline) return;
9617 if (!canInline) return;
9618 if (state.activeValue && Array.isArray(state.selectedValue)) {
9619 if (state.selectedValue.includes(state.activeValue)) return;
9620 if ((_a = prevSelectedValueRef.current) == null ? void 0 : _a.includes(state.activeValue)) return;
9621 }
9622 return state.activeValue;
9623 });
9624 const items = store.useState("renderedItems");
9625 const open = store.useState("open");
9626 const contentElement = store.useState("contentElement");
9627 const value = (0, import_react17.useMemo)(() => {
9628 if (!inline) return storeValue;
9629 if (!canInline) return storeValue;
9630 const firstItemAutoSelected = isFirstItemAutoSelected(
9631 items,
9632 inlineActiveValue,
9633 autoSelect
9634 );
9635 if (firstItemAutoSelected) {
9636 if (hasCompletionString(storeValue, inlineActiveValue)) {
9637 const slice = (inlineActiveValue == null ? void 0 : inlineActiveValue.slice(storeValue.length)) || "";
9638 return storeValue + slice;
9639 }
9640 return storeValue;
9641 }
9642 return inlineActiveValue || storeValue;
9643 }, [inline, canInline, items, inlineActiveValue, autoSelect, storeValue]);
9644 (0, import_react17.useEffect)(() => {
9645 const element = ref.current;
9646 if (!element) return;
9647 const onCompositeItemMove = () => setCanInline(true);
9648 element.addEventListener("combobox-item-move", onCompositeItemMove);
9649 return () => {
9650 element.removeEventListener("combobox-item-move", onCompositeItemMove);
9651 };
9652 }, []);
9653 (0, import_react17.useEffect)(() => {
9654 if (!inline) return;
9655 if (!canInline) return;
9656 if (!inlineActiveValue) return;
9657 const firstItemAutoSelected = isFirstItemAutoSelected(
9658 items,
9659 inlineActiveValue,
9660 autoSelect
9661 );
9662 if (!firstItemAutoSelected) return;
9663 if (!hasCompletionString(storeValue, inlineActiveValue)) return;
9664 let cleanup = noop2;
9665 queueMicrotask(() => {
9666 const element = ref.current;
9667 if (!element) return;
9668 const { start: prevStart, end: prevEnd } = getTextboxSelection(element);
9669 const nextStart = storeValue.length;
9670 const nextEnd = inlineActiveValue.length;
9671 setSelectionRange(element, nextStart, nextEnd);
9672 cleanup = () => {
9673 if (!hasFocus(element)) return;
9674 const { start, end } = getTextboxSelection(element);
9675 if (start !== nextStart) return;
9676 if (end !== nextEnd) return;
9677 setSelectionRange(element, prevStart, prevEnd);
9678 };
9679 });
9680 return () => cleanup();
9681 }, [
9682 valueUpdated,
9683 inline,
9684 canInline,
9685 inlineActiveValue,
9686 items,
9687 autoSelect,
9688 storeValue
9689 ]);
9690 const scrollingElementRef = (0, import_react17.useRef)(null);
9691 const getAutoSelectIdProp = useEvent(getAutoSelectId);
9692 const autoSelectIdRef = (0, import_react17.useRef)(null);
9693 (0, import_react17.useEffect)(() => {
9694 if (!open) return;
9695 if (!contentElement) return;
9696 const scrollingElement = getScrollingElement(contentElement);
9697 if (!scrollingElement) return;
9698 scrollingElementRef.current = scrollingElement;
9699 const onUserScroll = () => {
9700 canAutoSelectRef.current = false;
9701 };
9702 const onScroll = () => {
9703 if (!store) return;
9704 if (!canAutoSelectRef.current) return;
9705 const { activeId } = store.getState();
9706 if (activeId === null) return;
9707 if (activeId === autoSelectIdRef.current) return;
9708 canAutoSelectRef.current = false;
9709 };
9710 const options = { passive: true, capture: true };
9711 scrollingElement.addEventListener("wheel", onUserScroll, options);
9712 scrollingElement.addEventListener("touchmove", onUserScroll, options);
9713 scrollingElement.addEventListener("scroll", onScroll, options);
9714 return () => {
9715 scrollingElement.removeEventListener("wheel", onUserScroll, true);
9716 scrollingElement.removeEventListener("touchmove", onUserScroll, true);
9717 scrollingElement.removeEventListener("scroll", onScroll, true);
9718 };
9719 }, [open, contentElement, store]);
9720 useSafeLayoutEffect(() => {
9721 if (!storeValue) return;
9722 if (composingRef.current) return;
9723 canAutoSelectRef.current = true;
9724 }, [storeValue]);
9725 useSafeLayoutEffect(() => {
9726 if (autoSelect !== "always" && open) return;
9727 canAutoSelectRef.current = open;
9728 }, [autoSelect, open]);
9729 const resetValueOnSelect = store.useState("resetValueOnSelect");
9730 useUpdateEffect(() => {
9731 var _a, _b;
9732 const canAutoSelect = canAutoSelectRef.current;
9733 if (!store) return;
9734 if (!open) return;
9735 if (!canAutoSelect && !resetValueOnSelect) return;
9736 const { baseElement, contentElement: contentElement2, activeId } = store.getState();
9737 if (baseElement && !hasFocus(baseElement)) return;
9738 if (contentElement2 == null ? void 0 : contentElement2.hasAttribute("data-placing")) {
9739 const observer = new MutationObserver(forceValueUpdate);
9740 observer.observe(contentElement2, { attributeFilter: ["data-placing"] });
9741 return () => observer.disconnect();
9742 }
9743 if (autoSelect && canAutoSelect) {
9744 const userAutoSelectId = getAutoSelectIdProp(items);
9745 const autoSelectId = userAutoSelectId !== void 0 ? userAutoSelectId : (_a = getDefaultAutoSelectId(items)) != null ? _a : store.first();
9746 autoSelectIdRef.current = autoSelectId;
9747 store.move(autoSelectId != null ? autoSelectId : null);
9748 } else {
9749 const element = (_b = store.item(activeId || store.first())) == null ? void 0 : _b.element;
9750 if (element && "scrollIntoView" in element) {
9751 element.scrollIntoView({ block: "nearest", inline: "nearest" });
9752 }
9753 }
9754 return;
9755 }, [
9756 store,
9757 open,
9758 valueUpdated,
9759 storeValue,
9760 autoSelect,
9761 resetValueOnSelect,
9762 getAutoSelectIdProp,
9763 items
9764 ]);
9765 (0, import_react17.useEffect)(() => {
9766 if (!inline) return;
9767 const combobox = ref.current;
9768 if (!combobox) return;
9769 const elements = [combobox, contentElement].filter(
9770 (value2) => !!value2
9771 );
9772 const onBlur2 = (event) => {
9773 if (elements.every((el) => isFocusEventOutside(event, el))) {
9774 store == null ? void 0 : store.setValue(value);
9775 }
9776 };
9777 for (const element of elements) {
9778 element.addEventListener("focusout", onBlur2);
9779 }
9780 return () => {
9781 for (const element of elements) {
9782 element.removeEventListener("focusout", onBlur2);
9783 }
9784 };
9785 }, [inline, contentElement, store, value]);
9786 const canShow = (event) => {
9787 const currentTarget = event.currentTarget;
9788 return currentTarget.value.length >= showMinLength;
9789 };
9790 const onChangeProp = props.onChange;
9791 const showOnChangeProp = useBooleanEvent(showOnChange != null ? showOnChange : canShow);
9792 const setValueOnChangeProp = useBooleanEvent(
9793 // If the combobox is combined with tags, the value will be set by the tag
9794 // input component.
9795 setValueOnChange != null ? setValueOnChange : !store.tag
9796 );
9797 const onChange = useEvent((event) => {
9798 onChangeProp == null ? void 0 : onChangeProp(event);
9799 if (event.defaultPrevented) return;
9800 if (!store) return;
9801 const currentTarget = event.currentTarget;
9802 const { value: value2, selectionStart, selectionEnd } = currentTarget;
9803 const nativeEvent = event.nativeEvent;
9804 canAutoSelectRef.current = true;
9805 if (isInputEvent(nativeEvent)) {
9806 if (nativeEvent.isComposing) {
9807 canAutoSelectRef.current = false;
9808 composingRef.current = true;
9809 }
9810 if (inline) {
9811 const textInserted = nativeEvent.inputType === "insertText" || nativeEvent.inputType === "insertCompositionText";
9812 const caretAtEnd = selectionStart === value2.length;
9813 setCanInline(textInserted && caretAtEnd);
9814 }
9815 }
9816 if (setValueOnChangeProp(event)) {
9817 const isSameValue = value2 === store.getState().value;
9818 store.setValue(value2);
9819 queueMicrotask(() => {
9820 setSelectionRange(currentTarget, selectionStart, selectionEnd);
9821 });
9822 if (inline && autoSelect && isSameValue) {
9823 forceValueUpdate();
9824 }
9825 }
9826 if (showOnChangeProp(event)) {
9827 store.show();
9828 }
9829 if (!autoSelect || !canAutoSelectRef.current) {
9830 store.setActiveId(null);
9831 }
9832 });
9833 const onCompositionEndProp = props.onCompositionEnd;
9834 const onCompositionEnd = useEvent((event) => {
9835 canAutoSelectRef.current = true;
9836 composingRef.current = false;
9837 onCompositionEndProp == null ? void 0 : onCompositionEndProp(event);
9838 if (event.defaultPrevented) return;
9839 if (!autoSelect) return;
9840 forceValueUpdate();
9841 });
9842 const onMouseDownProp = props.onMouseDown;
9843 const blurActiveItemOnClickProp = useBooleanEvent(
9844 blurActiveItemOnClick != null ? blurActiveItemOnClick : (() => !!(store == null ? void 0 : store.getState().includesBaseElement))
9845 );
9846 const setValueOnClickProp = useBooleanEvent(setValueOnClick);
9847 const showOnClickProp = useBooleanEvent(showOnClick != null ? showOnClick : canShow);
9848 const onMouseDown = useEvent((event) => {
9849 onMouseDownProp == null ? void 0 : onMouseDownProp(event);
9850 if (event.defaultPrevented) return;
9851 if (event.button) return;
9852 if (event.ctrlKey) return;
9853 if (!store) return;
9854 if (blurActiveItemOnClickProp(event)) {
9855 store.setActiveId(null);
9856 }
9857 if (setValueOnClickProp(event)) {
9858 store.setValue(value);
9859 }
9860 if (showOnClickProp(event)) {
9861 queueBeforeEvent(event.currentTarget, "mouseup", store.show);
9862 }
9863 });
9864 const onKeyDownProp = props.onKeyDown;
9865 const showOnKeyPressProp = useBooleanEvent(showOnKeyPress != null ? showOnKeyPress : canShow);
9866 const onKeyDown = useEvent((event) => {
9867 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
9868 if (!event.repeat) {
9869 canAutoSelectRef.current = false;
9870 }
9871 if (event.defaultPrevented) return;
9872 if (event.ctrlKey) return;
9873 if (event.altKey) return;
9874 if (event.shiftKey) return;
9875 if (event.metaKey) return;
9876 if (!store) return;
9877 const { open: open2 } = store.getState();
9878 if (open2) return;
9879 if (event.key === "ArrowUp" || event.key === "ArrowDown") {
9880 if (showOnKeyPressProp(event)) {
9881 event.preventDefault();
9882 store.show();
9883 }
9884 }
9885 });
9886 const onBlurProp = props.onBlur;
9887 const onBlur = useEvent((event) => {
9888 canAutoSelectRef.current = false;
9889 onBlurProp == null ? void 0 : onBlurProp(event);
9890 if (event.defaultPrevented) return;
9891 });
9892 const id = useId3(props.id);
9893 const ariaAutoComplete = isAriaAutoCompleteValue(autoComplete) ? autoComplete : void 0;
9894 const isActiveItem = store.useState((state) => state.activeId === null);
9895 props = {
9896 id,
9897 role: "combobox",
9898 "aria-autocomplete": ariaAutoComplete,
9899 "aria-haspopup": getPopupRole(contentElement, "listbox"),
9900 "aria-expanded": open,
9901 "aria-controls": contentElement == null ? void 0 : contentElement.id,
9902 "data-active-item": isActiveItem || void 0,
9903 value,
9904 ...props,
9905 ref: useMergeRefs(ref, props.ref),
9906 onChange,
9907 onCompositionEnd,
9908 onMouseDown,
9909 onKeyDown,
9910 onBlur
9911 };
9912 props = useComposite({
9913 store,
9914 focusable,
9915 ...props,
9916 // Enable inline autocomplete when the user moves from the combobox input
9917 // to an item.
9918 moveOnKeyPress: (event) => {
9919 if (isFalsyBooleanCallback(moveOnKeyPress, event)) return false;
9920 if (inline) setCanInline(true);
9921 return true;
9922 }
9923 });
9924 props = usePopoverAnchor({ store, ...props });
9925 return { autoComplete: "off", ...props };
9926 }
9927 );
9928 var Combobox = forwardRef22(function Combobox2(props) {
9929 const htmlProps = useCombobox(props);
9930 return createElement3(TagName9, htmlProps);
9931 });
9932
9933 // node_modules/@ariakit/react-core/esm/__chunks/IBXZ2LQC.js
9934 var import_react18 = __toESM(require_react(), 1);
9935 var import_jsx_runtime58 = __toESM(require_jsx_runtime(), 1);
9936 var TagName10 = "div";
9937 function isSelected(storeValue, itemValue) {
9938 if (itemValue == null) return;
9939 if (storeValue == null) return false;
9940 if (Array.isArray(storeValue)) {
9941 return storeValue.includes(itemValue);
9942 }
9943 return storeValue === itemValue;
9944 }
9945 function getItemRole(popupRole) {
9946 var _a;
9947 const itemRoleByPopupRole = {
9948 menu: "menuitem",
9949 listbox: "option",
9950 tree: "treeitem"
9951 };
9952 const key = popupRole;
9953 return (_a = itemRoleByPopupRole[key]) != null ? _a : "option";
9954 }
9955 var useComboboxItem = createHook(
9956 function useComboboxItem2({
9957 store,
9958 value,
9959 hideOnClick,
9960 setValueOnClick,
9961 selectValueOnClick = true,
9962 resetValueOnSelect,
9963 focusOnHover = false,
9964 moveOnKeyPress = true,
9965 getItem: getItemProp,
9966 ...props
9967 }) {
9968 var _a;
9969 const context = useComboboxScopedContext();
9970 store = store || context;
9971 invariant(
9972 store,
9973 "ComboboxItem must be wrapped in a ComboboxList or ComboboxPopover component."
9974 );
9975 const { resetValueOnSelectState, multiSelectable, selected } = useStoreStateObject(store, {
9976 resetValueOnSelectState: "resetValueOnSelect",
9977 multiSelectable(state) {
9978 return Array.isArray(state.selectedValue);
9979 },
9980 selected(state) {
9981 return isSelected(state.selectedValue, value);
9982 }
9983 });
9984 const getItem = (0, import_react18.useCallback)(
9985 (item) => {
9986 const nextItem = { ...item, value };
9987 if (getItemProp) {
9988 return getItemProp(nextItem);
9989 }
9990 return nextItem;
9991 },
9992 [value, getItemProp]
9993 );
9994 setValueOnClick = setValueOnClick != null ? setValueOnClick : !multiSelectable;
9995 hideOnClick = hideOnClick != null ? hideOnClick : value != null && !multiSelectable;
9996 const onClickProp = props.onClick;
9997 const setValueOnClickProp = useBooleanEvent(setValueOnClick);
9998 const selectValueOnClickProp = useBooleanEvent(selectValueOnClick);
9999 const resetValueOnSelectProp = useBooleanEvent(
10000 (_a = resetValueOnSelect != null ? resetValueOnSelect : resetValueOnSelectState) != null ? _a : multiSelectable
10001 );
10002 const hideOnClickProp = useBooleanEvent(hideOnClick);
10003 const onClick = useEvent((event) => {
10004 onClickProp == null ? void 0 : onClickProp(event);
10005 if (event.defaultPrevented) return;
10006 if (isDownloading(event)) return;
10007 if (isOpeningInNewTab(event)) return;
10008 if (value != null) {
10009 if (selectValueOnClickProp(event)) {
10010 if (resetValueOnSelectProp(event)) {
10011 store == null ? void 0 : store.resetValue();
10012 }
10013 store == null ? void 0 : store.setSelectedValue((prevValue) => {
10014 if (!Array.isArray(prevValue)) return value;
10015 if (prevValue.includes(value)) {
10016 return prevValue.filter((v2) => v2 !== value);
10017 }
10018 return [...prevValue, value];
10019 });
10020 }
10021 if (setValueOnClickProp(event)) {
10022 store == null ? void 0 : store.setValue(value);
10023 }
10024 }
10025 if (hideOnClickProp(event)) {
10026 store == null ? void 0 : store.hide();
10027 }
10028 });
10029 const onKeyDownProp = props.onKeyDown;
10030 const onKeyDown = useEvent((event) => {
10031 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
10032 if (event.defaultPrevented) return;
10033 const baseElement = store == null ? void 0 : store.getState().baseElement;
10034 if (!baseElement) return;
10035 if (hasFocus(baseElement)) return;
10036 const printable = event.key.length === 1;
10037 if (printable || event.key === "Backspace" || event.key === "Delete") {
10038 queueMicrotask(() => baseElement.focus());
10039 if (isTextField(baseElement)) {
10040 store == null ? void 0 : store.setValue(baseElement.value);
10041 }
10042 }
10043 });
10044 if (multiSelectable && selected != null) {
10045 props = {
10046 "aria-selected": selected,
10047 ...props
10048 };
10049 }
10050 props = useWrapElement(
10051 props,
10052 (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 }) }),
10053 [value, selected]
10054 );
10055 const popupRole = (0, import_react18.useContext)(ComboboxListRoleContext);
10056 props = {
10057 role: getItemRole(popupRole),
10058 children: value,
10059 ...props,
10060 onClick,
10061 onKeyDown
10062 };
10063 const moveOnKeyPressProp = useBooleanEvent(moveOnKeyPress);
10064 props = useCompositeItem({
10065 store,
10066 ...props,
10067 getItem,
10068 // Dispatch a custom event on the combobox input when moving to an item
10069 // with the keyboard so the Combobox component can enable inline
10070 // autocompletion.
10071 moveOnKeyPress: (event) => {
10072 if (!moveOnKeyPressProp(event)) return false;
10073 const moveEvent = new Event("combobox-item-move");
10074 const baseElement = store == null ? void 0 : store.getState().baseElement;
10075 baseElement == null ? void 0 : baseElement.dispatchEvent(moveEvent);
10076 return true;
10077 }
10078 });
10079 props = useCompositeHover({ store, focusOnHover, ...props });
10080 return props;
10081 }
10082 );
10083 var ComboboxItem = memo22(
10084 forwardRef22(function ComboboxItem2(props) {
10085 const htmlProps = useComboboxItem(props);
10086 return createElement3(TagName10, htmlProps);
10087 })
10088 );
10089
10090 // node_modules/@ariakit/react-core/esm/combobox/combobox-item-value.js
10091 var import_react19 = __toESM(require_react(), 1);
10092 var import_jsx_runtime59 = __toESM(require_jsx_runtime(), 1);
10093 var TagName11 = "span";
10094 function normalizeValue(value) {
10095 return normalizeString(value).toLowerCase();
10096 }
10097 function getOffsets(string, values) {
10098 const offsets = [];
10099 for (const value of values) {
10100 let pos = 0;
10101 const length = value.length;
10102 while (string.indexOf(value, pos) !== -1) {
10103 const index = string.indexOf(value, pos);
10104 if (index !== -1) {
10105 offsets.push([index, length]);
10106 }
10107 pos = index + 1;
10108 }
10109 }
10110 return offsets;
10111 }
10112 function filterOverlappingOffsets(offsets) {
10113 return offsets.filter(([offset, length], i2, arr) => {
10114 return !arr.some(
10115 ([o2, l2], j2) => j2 !== i2 && o2 <= offset && o2 + l2 >= offset + length
10116 );
10117 });
10118 }
10119 function sortOffsets(offsets) {
10120 return offsets.sort(([a2], [b2]) => a2 - b2);
10121 }
10122 function splitValue(itemValue, userValue) {
10123 if (!itemValue) return itemValue;
10124 if (!userValue) return itemValue;
10125 const userValues = toArray(userValue).filter(Boolean).map(normalizeValue);
10126 const parts = [];
10127 const span = (value, autocomplete = false) => /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(
10128 "span",
10129 {
10130 "data-autocomplete-value": autocomplete ? "" : void 0,
10131 "data-user-value": autocomplete ? void 0 : "",
10132 children: value
10133 },
10134 parts.length
10135 );
10136 const offsets = sortOffsets(
10137 filterOverlappingOffsets(
10138 // Convert userValues into a set to avoid duplicates
10139 getOffsets(normalizeValue(itemValue), new Set(userValues))
10140 )
10141 );
10142 if (!offsets.length) {
10143 parts.push(span(itemValue, true));
10144 return parts;
10145 }
10146 const [firstOffset] = offsets[0];
10147 const values = [
10148 itemValue.slice(0, firstOffset),
10149 ...offsets.flatMap(([offset, length], i2) => {
10150 var _a;
10151 const value = itemValue.slice(offset, offset + length);
10152 const nextOffset = (_a = offsets[i2 + 1]) == null ? void 0 : _a[0];
10153 const nextValue = itemValue.slice(offset + length, nextOffset);
10154 return [value, nextValue];
10155 })
10156 ];
10157 values.forEach((value, i2) => {
10158 if (!value) return;
10159 parts.push(span(value, i2 % 2 === 0));
10160 });
10161 return parts;
10162 }
10163 var useComboboxItemValue = createHook(function useComboboxItemValue2({ store, value, userValue, ...props }) {
10164 const context = useComboboxScopedContext();
10165 store = store || context;
10166 const itemContext = (0, import_react19.useContext)(ComboboxItemValueContext);
10167 const itemValue = value != null ? value : itemContext;
10168 const inputValue = useStoreState(store, (state) => userValue != null ? userValue : state == null ? void 0 : state.value);
10169 const children = (0, import_react19.useMemo)(() => {
10170 if (!itemValue) return;
10171 if (!inputValue) return itemValue;
10172 return splitValue(itemValue, inputValue);
10173 }, [itemValue, inputValue]);
10174 props = {
10175 children,
10176 ...props
10177 };
10178 return removeUndefinedValues(props);
10179 });
10180 var ComboboxItemValue = forwardRef22(function ComboboxItemValue2(props) {
10181 const htmlProps = useComboboxItemValue(props);
10182 return createElement3(TagName11, htmlProps);
10183 });
10184
10185 // node_modules/@ariakit/react-core/esm/combobox/combobox-label.js
10186 var TagName12 = "label";
10187 var useComboboxLabel = createHook(
10188 function useComboboxLabel2({ store, ...props }) {
10189 const context = useComboboxProviderContext();
10190 store = store || context;
10191 invariant(
10192 store,
10193 "ComboboxLabel must receive a `store` prop or be wrapped in a ComboboxProvider component."
10194 );
10195 const comboboxId = store.useState((state) => {
10196 var _a;
10197 return (_a = state.baseElement) == null ? void 0 : _a.id;
10198 });
10199 props = {
10200 htmlFor: comboboxId,
10201 ...props
10202 };
10203 return removeUndefinedValues(props);
10204 }
10205 );
10206 var ComboboxLabel = memo22(
10207 forwardRef22(function ComboboxLabel2(props) {
10208 const htmlProps = useComboboxLabel(props);
10209 return createElement3(TagName12, htmlProps);
10210 })
10211 );
10212
10213 // node_modules/@ariakit/react-core/esm/__chunks/2G6YEJT4.js
10214 var import_react20 = __toESM(require_react(), 1);
10215 var import_jsx_runtime60 = __toESM(require_jsx_runtime(), 1);
10216 var TagName13 = "div";
10217 var useComboboxList = createHook(
10218 function useComboboxList2({ store, alwaysVisible, ...props }) {
10219 const scopedContext = useComboboxScopedContext(true);
10220 const context = useComboboxContext();
10221 store = store || context;
10222 const scopedContextSameStore = !!store && store === scopedContext;
10223 invariant(
10224 store,
10225 "ComboboxList must receive a `store` prop or be wrapped in a ComboboxProvider component."
10226 );
10227 const ref = (0, import_react20.useRef)(null);
10228 const id = useId3(props.id);
10229 const mounted = store.useState("mounted");
10230 const hidden = isHidden(mounted, props.hidden, alwaysVisible);
10231 const style = hidden ? { ...props.style, display: "none" } : props.style;
10232 const multiSelectable = store.useState(
10233 (state) => Array.isArray(state.selectedValue)
10234 );
10235 const role = useAttribute(ref, "role", props.role);
10236 const isCompositeRole = role === "listbox" || role === "tree" || role === "grid";
10237 const ariaMultiSelectable = isCompositeRole ? multiSelectable || void 0 : void 0;
10238 const [hasListboxInside, setHasListboxInside] = (0, import_react20.useState)(false);
10239 const contentElement = store.useState("contentElement");
10240 useSafeLayoutEffect(() => {
10241 if (!mounted) return;
10242 const element = ref.current;
10243 if (!element) return;
10244 if (contentElement !== element) return;
10245 const callback = () => {
10246 setHasListboxInside(!!element.querySelector("[role='listbox']"));
10247 };
10248 const observer = new MutationObserver(callback);
10249 observer.observe(element, {
10250 subtree: true,
10251 childList: true,
10252 attributeFilter: ["role"]
10253 });
10254 callback();
10255 return () => observer.disconnect();
10256 }, [mounted, contentElement]);
10257 if (!hasListboxInside) {
10258 props = {
10259 role: "listbox",
10260 "aria-multiselectable": ariaMultiSelectable,
10261 ...props
10262 };
10263 }
10264 props = useWrapElement(
10265 props,
10266 (element) => /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(ComboboxScopedContextProvider, { value: store, children: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(ComboboxListRoleContext.Provider, { value: role, children: element }) }),
10267 [store, role]
10268 );
10269 const setContentElement = id && (!scopedContext || !scopedContextSameStore) ? store.setContentElement : null;
10270 props = {
10271 id,
10272 hidden,
10273 ...props,
10274 ref: useMergeRefs(setContentElement, ref, props.ref),
10275 style
10276 };
10277 return removeUndefinedValues(props);
10278 }
10279 );
10280 var ComboboxList = forwardRef22(function ComboboxList2(props) {
10281 const htmlProps = useComboboxList(props);
10282 return createElement3(TagName13, htmlProps);
10283 });
10284
10285 // node_modules/@ariakit/react-core/esm/__chunks/XSIEPKGA.js
10286 var import_react21 = __toESM(require_react(), 1);
10287 var TagValueContext = (0, import_react21.createContext)(null);
10288 var TagRemoveIdContext = (0, import_react21.createContext)(
10289 null
10290 );
10291 var ctx7 = createStoreContext(
10292 [CompositeContextProvider],
10293 [CompositeScopedContextProvider]
10294 );
10295 var useTagContext = ctx7.useContext;
10296 var useTagScopedContext = ctx7.useScopedContext;
10297 var useTagProviderContext = ctx7.useProviderContext;
10298 var TagContextProvider = ctx7.ContextProvider;
10299 var TagScopedContextProvider = ctx7.ScopedContextProvider;
10300
10301 // node_modules/@ariakit/core/esm/combobox/combobox-store.js
10302 var isTouchSafari = isSafari() && isTouchDevice();
10303 function createComboboxStore({
10304 tag,
10305 ...props
10306 } = {}) {
10307 const store = mergeStore(props.store, pick2(tag, ["value", "rtl"]));
10308 throwOnConflictingProps(props, store);
10309 const tagState = tag == null ? void 0 : tag.getState();
10310 const syncState = store == null ? void 0 : store.getState();
10311 const activeId = defaultValue(
10312 props.activeId,
10313 syncState == null ? void 0 : syncState.activeId,
10314 props.defaultActiveId,
10315 null
10316 );
10317 const composite = createCompositeStore({
10318 ...props,
10319 activeId,
10320 includesBaseElement: defaultValue(
10321 props.includesBaseElement,
10322 syncState == null ? void 0 : syncState.includesBaseElement,
10323 true
10324 ),
10325 orientation: defaultValue(
10326 props.orientation,
10327 syncState == null ? void 0 : syncState.orientation,
10328 "vertical"
10329 ),
10330 focusLoop: defaultValue(props.focusLoop, syncState == null ? void 0 : syncState.focusLoop, true),
10331 focusWrap: defaultValue(props.focusWrap, syncState == null ? void 0 : syncState.focusWrap, true),
10332 virtualFocus: defaultValue(
10333 props.virtualFocus,
10334 syncState == null ? void 0 : syncState.virtualFocus,
10335 true
10336 )
10337 });
10338 const popover = createPopoverStore({
10339 ...props,
10340 placement: defaultValue(
10341 props.placement,
10342 syncState == null ? void 0 : syncState.placement,
10343 "bottom-start"
10344 )
10345 });
10346 const value = defaultValue(
10347 props.value,
10348 syncState == null ? void 0 : syncState.value,
10349 props.defaultValue,
10350 ""
10351 );
10352 const selectedValue = defaultValue(
10353 props.selectedValue,
10354 syncState == null ? void 0 : syncState.selectedValue,
10355 tagState == null ? void 0 : tagState.values,
10356 props.defaultSelectedValue,
10357 ""
10358 );
10359 const multiSelectable = Array.isArray(selectedValue);
10360 const initialState = {
10361 ...composite.getState(),
10362 ...popover.getState(),
10363 value,
10364 selectedValue,
10365 resetValueOnSelect: defaultValue(
10366 props.resetValueOnSelect,
10367 syncState == null ? void 0 : syncState.resetValueOnSelect,
10368 multiSelectable
10369 ),
10370 resetValueOnHide: defaultValue(
10371 props.resetValueOnHide,
10372 syncState == null ? void 0 : syncState.resetValueOnHide,
10373 multiSelectable && !tag
10374 ),
10375 activeValue: syncState == null ? void 0 : syncState.activeValue
10376 };
10377 const combobox = createStore(initialState, composite, popover, store);
10378 if (isTouchSafari) {
10379 setup(
10380 combobox,
10381 () => sync(combobox, ["virtualFocus"], () => {
10382 combobox.setState("virtualFocus", false);
10383 })
10384 );
10385 }
10386 setup(combobox, () => {
10387 if (!tag) return;
10388 return chain(
10389 sync(combobox, ["selectedValue"], (state) => {
10390 if (!Array.isArray(state.selectedValue)) return;
10391 tag.setValues(state.selectedValue);
10392 }),
10393 sync(tag, ["values"], (state) => {
10394 combobox.setState("selectedValue", state.values);
10395 })
10396 );
10397 });
10398 setup(
10399 combobox,
10400 () => sync(combobox, ["resetValueOnHide", "mounted"], (state) => {
10401 if (!state.resetValueOnHide) return;
10402 if (state.mounted) return;
10403 combobox.setState("value", value);
10404 })
10405 );
10406 setup(
10407 combobox,
10408 () => sync(combobox, ["open"], (state) => {
10409 if (state.open) return;
10410 combobox.setState("activeId", activeId);
10411 combobox.setState("moves", 0);
10412 })
10413 );
10414 setup(
10415 combobox,
10416 () => sync(combobox, ["moves", "activeId"], (state, prevState) => {
10417 if (state.moves === prevState.moves) {
10418 combobox.setState("activeValue", void 0);
10419 }
10420 })
10421 );
10422 setup(
10423 combobox,
10424 () => batch(combobox, ["moves", "renderedItems"], (state, prev) => {
10425 if (state.moves === prev.moves) return;
10426 const { activeId: activeId2 } = combobox.getState();
10427 const activeItem = composite.item(activeId2);
10428 combobox.setState("activeValue", activeItem == null ? void 0 : activeItem.value);
10429 })
10430 );
10431 return {
10432 ...popover,
10433 ...composite,
10434 ...combobox,
10435 tag,
10436 setValue: (value2) => combobox.setState("value", value2),
10437 resetValue: () => combobox.setState("value", initialState.value),
10438 setSelectedValue: (selectedValue2) => combobox.setState("selectedValue", selectedValue2)
10439 };
10440 }
10441
10442 // node_modules/@ariakit/react-core/esm/__chunks/SVN33SY6.js
10443 function useComboboxStoreOptions(props) {
10444 const tag = useTagContext();
10445 props = {
10446 ...props,
10447 tag: props.tag !== void 0 ? props.tag : tag
10448 };
10449 return useCompositeStoreOptions(props);
10450 }
10451 function useComboboxStoreProps(store, update2, props) {
10452 useUpdateEffect(update2, [props.tag]);
10453 useStoreProps(store, props, "value", "setValue");
10454 useStoreProps(store, props, "selectedValue", "setSelectedValue");
10455 useStoreProps(store, props, "resetValueOnHide");
10456 useStoreProps(store, props, "resetValueOnSelect");
10457 return Object.assign(
10458 useCompositeStoreProps(
10459 usePopoverStoreProps(store, update2, props),
10460 update2,
10461 props
10462 ),
10463 { tag: props.tag }
10464 );
10465 }
10466 function useComboboxStore(props = {}) {
10467 props = useComboboxStoreOptions(props);
10468 const [store, update2] = useStore(createComboboxStore, props);
10469 return useComboboxStoreProps(store, update2, props);
10470 }
10471
10472 // node_modules/@ariakit/react-core/esm/combobox/combobox-provider.js
10473 var import_jsx_runtime61 = __toESM(require_jsx_runtime(), 1);
10474 function ComboboxProvider(props = {}) {
10475 const store = useComboboxStore(props);
10476 return /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(ComboboxContextProvider, { value: store, children: props.children });
10477 }
10478
10479 // packages/dataviews/build-module/components/dataviews-filters/search-widget.mjs
10480 var import_remove_accents = __toESM(require_remove_accents(), 1);
10481 var import_compose7 = __toESM(require_compose(), 1);
10482 var import_i18n28 = __toESM(require_i18n(), 1);
10483 var import_element26 = __toESM(require_element(), 1);
10484 var import_components19 = __toESM(require_components(), 1);
10485
10486 // packages/dataviews/build-module/components/dataviews-filters/utils.mjs
10487 var EMPTY_ARRAY3 = [];
10488 var getCurrentValue = (filterDefinition, currentFilter) => {
10489 if (filterDefinition.singleSelection) {
10490 return currentFilter?.value;
10491 }
10492 if (Array.isArray(currentFilter?.value)) {
10493 return currentFilter.value;
10494 }
10495 if (!Array.isArray(currentFilter?.value) && !!currentFilter?.value) {
10496 return [currentFilter.value];
10497 }
10498 return EMPTY_ARRAY3;
10499 };
10500
10501 // packages/dataviews/build-module/hooks/use-elements.mjs
10502 var import_element25 = __toESM(require_element(), 1);
10503 var EMPTY_ARRAY4 = [];
10504 function useElements({
10505 elements,
10506 getElements
10507 }) {
10508 const staticElements = Array.isArray(elements) && elements.length > 0 ? elements : EMPTY_ARRAY4;
10509 const [records, setRecords] = (0, import_element25.useState)(staticElements);
10510 const [isLoading, setIsLoading] = (0, import_element25.useState)(false);
10511 (0, import_element25.useEffect)(() => {
10512 if (!getElements) {
10513 setRecords(staticElements);
10514 return;
10515 }
10516 let cancelled = false;
10517 setIsLoading(true);
10518 getElements().then((fetchedElements) => {
10519 if (!cancelled) {
10520 const dynamicElements = Array.isArray(fetchedElements) && fetchedElements.length > 0 ? fetchedElements : staticElements;
10521 setRecords(dynamicElements);
10522 }
10523 }).catch(() => {
10524 if (!cancelled) {
10525 setRecords(staticElements);
10526 }
10527 }).finally(() => {
10528 if (!cancelled) {
10529 setIsLoading(false);
10530 }
10531 });
10532 return () => {
10533 cancelled = true;
10534 };
10535 }, [getElements, staticElements]);
10536 return {
10537 elements: records,
10538 isLoading
10539 };
10540 }
10541
10542 // packages/dataviews/build-module/components/dataviews-filters/search-widget.mjs
10543 var import_jsx_runtime62 = __toESM(require_jsx_runtime(), 1);
10544 function normalizeSearchInput(input = "") {
10545 return (0, import_remove_accents.default)(input.trim().toLowerCase());
10546 }
10547 var getNewValue = (filterDefinition, currentFilter, value) => {
10548 if (filterDefinition.singleSelection) {
10549 return value;
10550 }
10551 if (Array.isArray(currentFilter?.value)) {
10552 return currentFilter.value.includes(value) ? currentFilter.value.filter((v2) => v2 !== value) : [...currentFilter.value, value];
10553 }
10554 return [value];
10555 };
10556 function generateFilterElementCompositeItemId(prefix, filterElementValue) {
10557 return `${prefix}-${filterElementValue}`;
10558 }
10559 var MultiSelectionOption = ({ selected }) => {
10560 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10561 "span",
10562 {
10563 className: clsx_default(
10564 "dataviews-filters__search-widget-listitem-multi-selection",
10565 { "is-selected": selected }
10566 ),
10567 children: selected && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components19.Icon, { icon: check_default })
10568 }
10569 );
10570 };
10571 var SingleSelectionOption = ({ selected }) => {
10572 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10573 "span",
10574 {
10575 className: clsx_default(
10576 "dataviews-filters__search-widget-listitem-single-selection",
10577 { "is-selected": selected }
10578 )
10579 }
10580 );
10581 };
10582 function ListBox({ view, filter, onChangeView }) {
10583 const baseId = (0, import_compose7.useInstanceId)(ListBox, "dataviews-filter-list-box");
10584 const [activeCompositeId, setActiveCompositeId] = (0, import_element26.useState)(
10585 // When there are one or less operators, the first item is set as active
10586 // (by setting the initial `activeId` to `undefined`).
10587 // With 2 or more operators, the focus is moved on the operators control
10588 // (by setting the initial `activeId` to `null`), meaning that there won't
10589 // be an active item initially. Focus is then managed via the
10590 // `onFocusVisible` callback.
10591 filter.operators?.length === 1 ? void 0 : null
10592 );
10593 const currentFilter = view.filters?.find(
10594 (f2) => f2.field === filter.field
10595 );
10596 const currentValue = getCurrentValue(filter, currentFilter);
10597 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10598 import_components19.Composite,
10599 {
10600 virtualFocus: true,
10601 focusLoop: true,
10602 activeId: activeCompositeId,
10603 setActiveId: setActiveCompositeId,
10604 role: "listbox",
10605 className: "dataviews-filters__search-widget-listbox",
10606 "aria-label": (0, import_i18n28.sprintf)(
10607 /* translators: List of items for a filter. 1: Filter name. e.g.: "List of: Author". */
10608 (0, import_i18n28.__)("List of: %1$s"),
10609 filter.name
10610 ),
10611 onFocusVisible: () => {
10612 if (!activeCompositeId && filter.elements.length) {
10613 setActiveCompositeId(
10614 generateFilterElementCompositeItemId(
10615 baseId,
10616 filter.elements[0].value
10617 )
10618 );
10619 }
10620 },
10621 render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components19.Composite.Typeahead, {}),
10622 children: filter.elements.map((element) => /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10623 import_components19.Composite.Hover,
10624 {
10625 render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10626 import_components19.Composite.Item,
10627 {
10628 id: generateFilterElementCompositeItemId(
10629 baseId,
10630 element.value
10631 ),
10632 render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10633 "div",
10634 {
10635 "aria-label": element.label,
10636 role: "option",
10637 className: "dataviews-filters__search-widget-listitem"
10638 }
10639 ),
10640 onClick: () => {
10641 const newFilters = currentFilter ? [
10642 ...(view.filters ?? []).map(
10643 (_filter) => {
10644 if (_filter.field === filter.field) {
10645 return {
10646 ..._filter,
10647 operator: currentFilter.operator || filter.operators[0],
10648 value: getNewValue(
10649 filter,
10650 currentFilter,
10651 element.value
10652 )
10653 };
10654 }
10655 return _filter;
10656 }
10657 )
10658 ] : [
10659 ...view.filters ?? [],
10660 {
10661 field: filter.field,
10662 operator: filter.operators[0],
10663 value: getNewValue(
10664 filter,
10665 currentFilter,
10666 element.value
10667 )
10668 }
10669 ];
10670 onChangeView({
10671 ...view,
10672 page: 1,
10673 filters: newFilters
10674 });
10675 }
10676 }
10677 ),
10678 children: [
10679 filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10680 SingleSelectionOption,
10681 {
10682 selected: currentValue === element.value
10683 }
10684 ),
10685 !filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10686 MultiSelectionOption,
10687 {
10688 selected: currentValue.includes(element.value)
10689 }
10690 ),
10691 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10692 "span",
10693 {
10694 className: "dataviews-filters__search-widget-listitem-value",
10695 title: element.label,
10696 children: element.label
10697 }
10698 )
10699 ]
10700 },
10701 element.value
10702 ))
10703 }
10704 );
10705 }
10706 function ComboboxList22({ view, filter, onChangeView }) {
10707 const [searchValue, setSearchValue] = (0, import_element26.useState)("");
10708 const deferredSearchValue = (0, import_element26.useDeferredValue)(searchValue);
10709 const currentFilter = view.filters?.find(
10710 (_filter) => _filter.field === filter.field
10711 );
10712 const currentValue = getCurrentValue(filter, currentFilter);
10713 const matches = (0, import_element26.useMemo)(() => {
10714 const normalizedSearch = normalizeSearchInput(deferredSearchValue);
10715 return filter.elements.filter(
10716 (item) => normalizeSearchInput(item.label).includes(normalizedSearch)
10717 );
10718 }, [filter.elements, deferredSearchValue]);
10719 return /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10720 ComboboxProvider,
10721 {
10722 selectedValue: currentValue,
10723 setSelectedValue: (value) => {
10724 const newFilters = currentFilter ? [
10725 ...(view.filters ?? []).map((_filter) => {
10726 if (_filter.field === filter.field) {
10727 return {
10728 ..._filter,
10729 operator: currentFilter.operator || filter.operators[0],
10730 value
10731 };
10732 }
10733 return _filter;
10734 })
10735 ] : [
10736 ...view.filters ?? [],
10737 {
10738 field: filter.field,
10739 operator: filter.operators[0],
10740 value
10741 }
10742 ];
10743 onChangeView({
10744 ...view,
10745 page: 1,
10746 filters: newFilters
10747 });
10748 },
10749 setValue: setSearchValue,
10750 children: [
10751 /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)("div", { className: "dataviews-filters__search-widget-filter-combobox__wrapper", children: [
10752 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10753 ComboboxLabel,
10754 {
10755 render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components19.VisuallyHidden, { children: (0, import_i18n28.__)("Search items") }),
10756 children: (0, import_i18n28.__)("Search items")
10757 }
10758 ),
10759 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10760 Combobox,
10761 {
10762 autoSelect: "always",
10763 placeholder: (0, import_i18n28.__)("Search"),
10764 className: "dataviews-filters__search-widget-filter-combobox__input"
10765 }
10766 ),
10767 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("div", { className: "dataviews-filters__search-widget-filter-combobox__icon", children: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components19.Icon, { icon: search_default }) })
10768 ] }),
10769 /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10770 ComboboxList,
10771 {
10772 className: "dataviews-filters__search-widget-filter-combobox-list",
10773 alwaysVisible: true,
10774 children: [
10775 matches.map((element) => {
10776 return /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10777 ComboboxItem,
10778 {
10779 resetValueOnSelect: false,
10780 value: element.value,
10781 className: "dataviews-filters__search-widget-listitem",
10782 hideOnClick: false,
10783 setValueOnClick: false,
10784 focusOnHover: true,
10785 children: [
10786 filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10787 SingleSelectionOption,
10788 {
10789 selected: currentValue === element.value
10790 }
10791 ),
10792 !filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10793 MultiSelectionOption,
10794 {
10795 selected: currentValue.includes(
10796 element.value
10797 )
10798 }
10799 ),
10800 /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10801 "span",
10802 {
10803 className: "dataviews-filters__search-widget-listitem-value",
10804 title: element.label,
10805 children: [
10806 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10807 ComboboxItemValue,
10808 {
10809 className: "dataviews-filters__search-widget-filter-combobox-item-value",
10810 value: element.label
10811 }
10812 ),
10813 !!element.description && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("span", { className: "dataviews-filters__search-widget-listitem-description", children: element.description })
10814 ]
10815 }
10816 )
10817 ]
10818 },
10819 element.value
10820 );
10821 }),
10822 !matches.length && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("p", { children: (0, import_i18n28.__)("No results found") })
10823 ]
10824 }
10825 )
10826 ]
10827 }
10828 );
10829 }
10830 function SearchWidget(props) {
10831 const { elements, isLoading } = useElements({
10832 elements: props.filter.elements,
10833 getElements: props.filter.getElements
10834 });
10835 if (isLoading) {
10836 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("div", { className: "dataviews-filters__search-widget-no-elements", children: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components19.Spinner, {}) });
10837 }
10838 if (elements.length === 0) {
10839 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("div", { className: "dataviews-filters__search-widget-no-elements", children: (0, import_i18n28.__)("No elements found") });
10840 }
10841 const Widget = elements.length > 10 ? ComboboxList22 : ListBox;
10842 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(Widget, { ...props, filter: { ...props.filter, elements } });
10843 }
10844
10845 // packages/dataviews/build-module/components/dataviews-filters/input-widget.mjs
10846 var import_es6 = __toESM(require_es6(), 1);
10847 var import_compose8 = __toESM(require_compose(), 1);
10848 var import_element27 = __toESM(require_element(), 1);
10849 var import_components20 = __toESM(require_components(), 1);
10850 var import_jsx_runtime63 = __toESM(require_jsx_runtime(), 1);
10851 function InputWidget({
10852 filter,
10853 view,
10854 onChangeView,
10855 fields
10856 }) {
10857 const currentFilter = view.filters?.find(
10858 (f2) => f2.field === filter.field
10859 );
10860 const currentValue = getCurrentValue(filter, currentFilter);
10861 const field = (0, import_element27.useMemo)(() => {
10862 const currentField = fields.find((f2) => f2.id === filter.field);
10863 if (currentField) {
10864 return {
10865 ...currentField,
10866 // Deactivate validation for filters.
10867 isValid: {},
10868 // Configure getValue/setValue as if Item was a plain object.
10869 getValue: ({ item }) => item[currentField.id],
10870 setValue: ({ value }) => ({
10871 [currentField.id]: value
10872 })
10873 };
10874 }
10875 return currentField;
10876 }, [fields, filter.field]);
10877 const data = (0, import_element27.useMemo)(() => {
10878 return (view.filters ?? []).reduce(
10879 (acc, activeFilter) => {
10880 acc[activeFilter.field] = activeFilter.value;
10881 return acc;
10882 },
10883 {}
10884 );
10885 }, [view.filters]);
10886 const handleChange = (0, import_compose8.useEvent)((updatedData) => {
10887 if (!field || !currentFilter) {
10888 return;
10889 }
10890 const nextValue = field.getValue({ item: updatedData });
10891 if ((0, import_es6.default)(nextValue, currentValue)) {
10892 return;
10893 }
10894 onChangeView({
10895 ...view,
10896 filters: (view.filters ?? []).map(
10897 (_filter) => _filter.field === filter.field ? {
10898 ..._filter,
10899 operator: currentFilter.operator || filter.operators[0],
10900 // Consider empty strings as undefined:
10901 //
10902 // - undefined as value means the filter is unset: the filter widget displays no value and the search returns all records
10903 // - empty string as value means "search empty string": returns only the records that have an empty string as value
10904 //
10905 // In practice, this means the filter will not be able to find an empty string as the value.
10906 value: nextValue === "" ? void 0 : nextValue
10907 } : _filter
10908 )
10909 });
10910 });
10911 if (!field || !field.Edit || !currentFilter) {
10912 return null;
10913 }
10914 return /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
10915 import_components20.Flex,
10916 {
10917 className: "dataviews-filters__user-input-widget",
10918 gap: 2.5,
10919 direction: "column",
10920 children: /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
10921 field.Edit,
10922 {
10923 hideLabelFromVision: true,
10924 data,
10925 field,
10926 operator: currentFilter.operator,
10927 onChange: handleChange
10928 }
10929 )
10930 }
10931 );
10932 }
10933
10934 // packages/dataviews/node_modules/date-fns/constants.js
10935 var daysInYear = 365.2425;
10936 var maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1e3;
10937 var minTime = -maxTime;
10938 var millisecondsInWeek = 6048e5;
10939 var millisecondsInDay = 864e5;
10940 var secondsInHour = 3600;
10941 var secondsInDay = secondsInHour * 24;
10942 var secondsInWeek = secondsInDay * 7;
10943 var secondsInYear = secondsInDay * daysInYear;
10944 var secondsInMonth = secondsInYear / 12;
10945 var secondsInQuarter = secondsInMonth * 3;
10946 var constructFromSymbol = /* @__PURE__ */ Symbol.for("constructDateFrom");
10947
10948 // packages/dataviews/node_modules/date-fns/constructFrom.js
10949 function constructFrom(date, value) {
10950 if (typeof date === "function") return date(value);
10951 if (date && typeof date === "object" && constructFromSymbol in date)
10952 return date[constructFromSymbol](value);
10953 if (date instanceof Date) return new date.constructor(value);
10954 return new Date(value);
10955 }
10956
10957 // packages/dataviews/node_modules/date-fns/toDate.js
10958 function toDate(argument, context) {
10959 return constructFrom(context || argument, argument);
10960 }
10961
10962 // packages/dataviews/node_modules/date-fns/addDays.js
10963 function addDays(date, amount, options) {
10964 const _date = toDate(date, options?.in);
10965 if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
10966 if (!amount) return _date;
10967 _date.setDate(_date.getDate() + amount);
10968 return _date;
10969 }
10970
10971 // packages/dataviews/node_modules/date-fns/addMonths.js
10972 function addMonths(date, amount, options) {
10973 const _date = toDate(date, options?.in);
10974 if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
10975 if (!amount) {
10976 return _date;
10977 }
10978 const dayOfMonth = _date.getDate();
10979 const endOfDesiredMonth = constructFrom(options?.in || date, _date.getTime());
10980 endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0);
10981 const daysInMonth = endOfDesiredMonth.getDate();
10982 if (dayOfMonth >= daysInMonth) {
10983 return endOfDesiredMonth;
10984 } else {
10985 _date.setFullYear(
10986 endOfDesiredMonth.getFullYear(),
10987 endOfDesiredMonth.getMonth(),
10988 dayOfMonth
10989 );
10990 return _date;
10991 }
10992 }
10993
10994 // packages/dataviews/node_modules/date-fns/_lib/defaultOptions.js
10995 var defaultOptions = {};
10996 function getDefaultOptions() {
10997 return defaultOptions;
10998 }
10999
11000 // packages/dataviews/node_modules/date-fns/startOfWeek.js
11001 function startOfWeek(date, options) {
11002 const defaultOptions2 = getDefaultOptions();
11003 const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
11004 const _date = toDate(date, options?.in);
11005 const day = _date.getDay();
11006 const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
11007 _date.setDate(_date.getDate() - diff);
11008 _date.setHours(0, 0, 0, 0);
11009 return _date;
11010 }
11011
11012 // packages/dataviews/node_modules/date-fns/startOfISOWeek.js
11013 function startOfISOWeek(date, options) {
11014 return startOfWeek(date, { ...options, weekStartsOn: 1 });
11015 }
11016
11017 // packages/dataviews/node_modules/date-fns/getISOWeekYear.js
11018 function getISOWeekYear(date, options) {
11019 const _date = toDate(date, options?.in);
11020 const year = _date.getFullYear();
11021 const fourthOfJanuaryOfNextYear = constructFrom(_date, 0);
11022 fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
11023 fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
11024 const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
11025 const fourthOfJanuaryOfThisYear = constructFrom(_date, 0);
11026 fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
11027 fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
11028 const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
11029 if (_date.getTime() >= startOfNextYear.getTime()) {
11030 return year + 1;
11031 } else if (_date.getTime() >= startOfThisYear.getTime()) {
11032 return year;
11033 } else {
11034 return year - 1;
11035 }
11036 }
11037
11038 // packages/dataviews/node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.js
11039 function getTimezoneOffsetInMilliseconds(date) {
11040 const _date = toDate(date);
11041 const utcDate = new Date(
11042 Date.UTC(
11043 _date.getFullYear(),
11044 _date.getMonth(),
11045 _date.getDate(),
11046 _date.getHours(),
11047 _date.getMinutes(),
11048 _date.getSeconds(),
11049 _date.getMilliseconds()
11050 )
11051 );
11052 utcDate.setUTCFullYear(_date.getFullYear());
11053 return +date - +utcDate;
11054 }
11055
11056 // packages/dataviews/node_modules/date-fns/_lib/normalizeDates.js
11057 function normalizeDates(context, ...dates) {
11058 const normalize = constructFrom.bind(
11059 null,
11060 context || dates.find((date) => typeof date === "object")
11061 );
11062 return dates.map(normalize);
11063 }
11064
11065 // packages/dataviews/node_modules/date-fns/startOfDay.js
11066 function startOfDay(date, options) {
11067 const _date = toDate(date, options?.in);
11068 _date.setHours(0, 0, 0, 0);
11069 return _date;
11070 }
11071
11072 // packages/dataviews/node_modules/date-fns/differenceInCalendarDays.js
11073 function differenceInCalendarDays(laterDate, earlierDate, options) {
11074 const [laterDate_, earlierDate_] = normalizeDates(
11075 options?.in,
11076 laterDate,
11077 earlierDate
11078 );
11079 const laterStartOfDay = startOfDay(laterDate_);
11080 const earlierStartOfDay = startOfDay(earlierDate_);
11081 const laterTimestamp = +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
11082 const earlierTimestamp = +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
11083 return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
11084 }
11085
11086 // packages/dataviews/node_modules/date-fns/startOfISOWeekYear.js
11087 function startOfISOWeekYear(date, options) {
11088 const year = getISOWeekYear(date, options);
11089 const fourthOfJanuary = constructFrom(options?.in || date, 0);
11090 fourthOfJanuary.setFullYear(year, 0, 4);
11091 fourthOfJanuary.setHours(0, 0, 0, 0);
11092 return startOfISOWeek(fourthOfJanuary);
11093 }
11094
11095 // packages/dataviews/node_modules/date-fns/addWeeks.js
11096 function addWeeks(date, amount, options) {
11097 return addDays(date, amount * 7, options);
11098 }
11099
11100 // packages/dataviews/node_modules/date-fns/addYears.js
11101 function addYears(date, amount, options) {
11102 return addMonths(date, amount * 12, options);
11103 }
11104
11105 // packages/dataviews/node_modules/date-fns/isDate.js
11106 function isDate(value) {
11107 return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
11108 }
11109
11110 // packages/dataviews/node_modules/date-fns/isValid.js
11111 function isValid(date) {
11112 return !(!isDate(date) && typeof date !== "number" || isNaN(+toDate(date)));
11113 }
11114
11115 // packages/dataviews/node_modules/date-fns/startOfMonth.js
11116 function startOfMonth(date, options) {
11117 const _date = toDate(date, options?.in);
11118 _date.setDate(1);
11119 _date.setHours(0, 0, 0, 0);
11120 return _date;
11121 }
11122
11123 // packages/dataviews/node_modules/date-fns/startOfYear.js
11124 function startOfYear(date, options) {
11125 const date_ = toDate(date, options?.in);
11126 date_.setFullYear(date_.getFullYear(), 0, 1);
11127 date_.setHours(0, 0, 0, 0);
11128 return date_;
11129 }
11130
11131 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/formatDistance.js
11132 var formatDistanceLocale = {
11133 lessThanXSeconds: {
11134 one: "less than a second",
11135 other: "less than {{count}} seconds"
11136 },
11137 xSeconds: {
11138 one: "1 second",
11139 other: "{{count}} seconds"
11140 },
11141 halfAMinute: "half a minute",
11142 lessThanXMinutes: {
11143 one: "less than a minute",
11144 other: "less than {{count}} minutes"
11145 },
11146 xMinutes: {
11147 one: "1 minute",
11148 other: "{{count}} minutes"
11149 },
11150 aboutXHours: {
11151 one: "about 1 hour",
11152 other: "about {{count}} hours"
11153 },
11154 xHours: {
11155 one: "1 hour",
11156 other: "{{count}} hours"
11157 },
11158 xDays: {
11159 one: "1 day",
11160 other: "{{count}} days"
11161 },
11162 aboutXWeeks: {
11163 one: "about 1 week",
11164 other: "about {{count}} weeks"
11165 },
11166 xWeeks: {
11167 one: "1 week",
11168 other: "{{count}} weeks"
11169 },
11170 aboutXMonths: {
11171 one: "about 1 month",
11172 other: "about {{count}} months"
11173 },
11174 xMonths: {
11175 one: "1 month",
11176 other: "{{count}} months"
11177 },
11178 aboutXYears: {
11179 one: "about 1 year",
11180 other: "about {{count}} years"
11181 },
11182 xYears: {
11183 one: "1 year",
11184 other: "{{count}} years"
11185 },
11186 overXYears: {
11187 one: "over 1 year",
11188 other: "over {{count}} years"
11189 },
11190 almostXYears: {
11191 one: "almost 1 year",
11192 other: "almost {{count}} years"
11193 }
11194 };
11195 var formatDistance = (token, count, options) => {
11196 let result;
11197 const tokenValue = formatDistanceLocale[token];
11198 if (typeof tokenValue === "string") {
11199 result = tokenValue;
11200 } else if (count === 1) {
11201 result = tokenValue.one;
11202 } else {
11203 result = tokenValue.other.replace("{{count}}", count.toString());
11204 }
11205 if (options?.addSuffix) {
11206 if (options.comparison && options.comparison > 0) {
11207 return "in " + result;
11208 } else {
11209 return result + " ago";
11210 }
11211 }
11212 return result;
11213 };
11214
11215 // packages/dataviews/node_modules/date-fns/locale/_lib/buildFormatLongFn.js
11216 function buildFormatLongFn(args) {
11217 return (options = {}) => {
11218 const width = options.width ? String(options.width) : args.defaultWidth;
11219 const format6 = args.formats[width] || args.formats[args.defaultWidth];
11220 return format6;
11221 };
11222 }
11223
11224 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/formatLong.js
11225 var dateFormats = {
11226 full: "EEEE, MMMM do, y",
11227 long: "MMMM do, y",
11228 medium: "MMM d, y",
11229 short: "MM/dd/yyyy"
11230 };
11231 var timeFormats = {
11232 full: "h:mm:ss a zzzz",
11233 long: "h:mm:ss a z",
11234 medium: "h:mm:ss a",
11235 short: "h:mm a"
11236 };
11237 var dateTimeFormats = {
11238 full: "{{date}} 'at' {{time}}",
11239 long: "{{date}} 'at' {{time}}",
11240 medium: "{{date}}, {{time}}",
11241 short: "{{date}}, {{time}}"
11242 };
11243 var formatLong = {
11244 date: buildFormatLongFn({
11245 formats: dateFormats,
11246 defaultWidth: "full"
11247 }),
11248 time: buildFormatLongFn({
11249 formats: timeFormats,
11250 defaultWidth: "full"
11251 }),
11252 dateTime: buildFormatLongFn({
11253 formats: dateTimeFormats,
11254 defaultWidth: "full"
11255 })
11256 };
11257
11258 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/formatRelative.js
11259 var formatRelativeLocale = {
11260 lastWeek: "'last' eeee 'at' p",
11261 yesterday: "'yesterday at' p",
11262 today: "'today at' p",
11263 tomorrow: "'tomorrow at' p",
11264 nextWeek: "eeee 'at' p",
11265 other: "P"
11266 };
11267 var formatRelative = (token, _date, _baseDate, _options) => formatRelativeLocale[token];
11268
11269 // packages/dataviews/node_modules/date-fns/locale/_lib/buildLocalizeFn.js
11270 function buildLocalizeFn(args) {
11271 return (value, options) => {
11272 const context = options?.context ? String(options.context) : "standalone";
11273 let valuesArray;
11274 if (context === "formatting" && args.formattingValues) {
11275 const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
11276 const width = options?.width ? String(options.width) : defaultWidth;
11277 valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
11278 } else {
11279 const defaultWidth = args.defaultWidth;
11280 const width = options?.width ? String(options.width) : args.defaultWidth;
11281 valuesArray = args.values[width] || args.values[defaultWidth];
11282 }
11283 const index = args.argumentCallback ? args.argumentCallback(value) : value;
11284 return valuesArray[index];
11285 };
11286 }
11287
11288 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/localize.js
11289 var eraValues = {
11290 narrow: ["B", "A"],
11291 abbreviated: ["BC", "AD"],
11292 wide: ["Before Christ", "Anno Domini"]
11293 };
11294 var quarterValues = {
11295 narrow: ["1", "2", "3", "4"],
11296 abbreviated: ["Q1", "Q2", "Q3", "Q4"],
11297 wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"]
11298 };
11299 var monthValues = {
11300 narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
11301 abbreviated: [
11302 "Jan",
11303 "Feb",
11304 "Mar",
11305 "Apr",
11306 "May",
11307 "Jun",
11308 "Jul",
11309 "Aug",
11310 "Sep",
11311 "Oct",
11312 "Nov",
11313 "Dec"
11314 ],
11315 wide: [
11316 "January",
11317 "February",
11318 "March",
11319 "April",
11320 "May",
11321 "June",
11322 "July",
11323 "August",
11324 "September",
11325 "October",
11326 "November",
11327 "December"
11328 ]
11329 };
11330 var dayValues = {
11331 narrow: ["S", "M", "T", "W", "T", "F", "S"],
11332 short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
11333 abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
11334 wide: [
11335 "Sunday",
11336 "Monday",
11337 "Tuesday",
11338 "Wednesday",
11339 "Thursday",
11340 "Friday",
11341 "Saturday"
11342 ]
11343 };
11344 var dayPeriodValues = {
11345 narrow: {
11346 am: "a",
11347 pm: "p",
11348 midnight: "mi",
11349 noon: "n",
11350 morning: "morning",
11351 afternoon: "afternoon",
11352 evening: "evening",
11353 night: "night"
11354 },
11355 abbreviated: {
11356 am: "AM",
11357 pm: "PM",
11358 midnight: "midnight",
11359 noon: "noon",
11360 morning: "morning",
11361 afternoon: "afternoon",
11362 evening: "evening",
11363 night: "night"
11364 },
11365 wide: {
11366 am: "a.m.",
11367 pm: "p.m.",
11368 midnight: "midnight",
11369 noon: "noon",
11370 morning: "morning",
11371 afternoon: "afternoon",
11372 evening: "evening",
11373 night: "night"
11374 }
11375 };
11376 var formattingDayPeriodValues = {
11377 narrow: {
11378 am: "a",
11379 pm: "p",
11380 midnight: "mi",
11381 noon: "n",
11382 morning: "in the morning",
11383 afternoon: "in the afternoon",
11384 evening: "in the evening",
11385 night: "at night"
11386 },
11387 abbreviated: {
11388 am: "AM",
11389 pm: "PM",
11390 midnight: "midnight",
11391 noon: "noon",
11392 morning: "in the morning",
11393 afternoon: "in the afternoon",
11394 evening: "in the evening",
11395 night: "at night"
11396 },
11397 wide: {
11398 am: "a.m.",
11399 pm: "p.m.",
11400 midnight: "midnight",
11401 noon: "noon",
11402 morning: "in the morning",
11403 afternoon: "in the afternoon",
11404 evening: "in the evening",
11405 night: "at night"
11406 }
11407 };
11408 var ordinalNumber = (dirtyNumber, _options) => {
11409 const number = Number(dirtyNumber);
11410 const rem100 = number % 100;
11411 if (rem100 > 20 || rem100 < 10) {
11412 switch (rem100 % 10) {
11413 case 1:
11414 return number + "st";
11415 case 2:
11416 return number + "nd";
11417 case 3:
11418 return number + "rd";
11419 }
11420 }
11421 return number + "th";
11422 };
11423 var localize = {
11424 ordinalNumber,
11425 era: buildLocalizeFn({
11426 values: eraValues,
11427 defaultWidth: "wide"
11428 }),
11429 quarter: buildLocalizeFn({
11430 values: quarterValues,
11431 defaultWidth: "wide",
11432 argumentCallback: (quarter) => quarter - 1
11433 }),
11434 month: buildLocalizeFn({
11435 values: monthValues,
11436 defaultWidth: "wide"
11437 }),
11438 day: buildLocalizeFn({
11439 values: dayValues,
11440 defaultWidth: "wide"
11441 }),
11442 dayPeriod: buildLocalizeFn({
11443 values: dayPeriodValues,
11444 defaultWidth: "wide",
11445 formattingValues: formattingDayPeriodValues,
11446 defaultFormattingWidth: "wide"
11447 })
11448 };
11449
11450 // packages/dataviews/node_modules/date-fns/locale/_lib/buildMatchFn.js
11451 function buildMatchFn(args) {
11452 return (string, options = {}) => {
11453 const width = options.width;
11454 const matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
11455 const matchResult = string.match(matchPattern);
11456 if (!matchResult) {
11457 return null;
11458 }
11459 const matchedString = matchResult[0];
11460 const parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
11461 const key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString)) : (
11462 // [TODO] -- I challenge you to fix the type
11463 findKey(parsePatterns, (pattern) => pattern.test(matchedString))
11464 );
11465 let value;
11466 value = args.valueCallback ? args.valueCallback(key) : key;
11467 value = options.valueCallback ? (
11468 // [TODO] -- I challenge you to fix the type
11469 options.valueCallback(value)
11470 ) : value;
11471 const rest = string.slice(matchedString.length);
11472 return { value, rest };
11473 };
11474 }
11475 function findKey(object, predicate) {
11476 for (const key in object) {
11477 if (Object.prototype.hasOwnProperty.call(object, key) && predicate(object[key])) {
11478 return key;
11479 }
11480 }
11481 return void 0;
11482 }
11483 function findIndex(array, predicate) {
11484 for (let key = 0; key < array.length; key++) {
11485 if (predicate(array[key])) {
11486 return key;
11487 }
11488 }
11489 return void 0;
11490 }
11491
11492 // packages/dataviews/node_modules/date-fns/locale/_lib/buildMatchPatternFn.js
11493 function buildMatchPatternFn(args) {
11494 return (string, options = {}) => {
11495 const matchResult = string.match(args.matchPattern);
11496 if (!matchResult) return null;
11497 const matchedString = matchResult[0];
11498 const parseResult = string.match(args.parsePattern);
11499 if (!parseResult) return null;
11500 let value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
11501 value = options.valueCallback ? options.valueCallback(value) : value;
11502 const rest = string.slice(matchedString.length);
11503 return { value, rest };
11504 };
11505 }
11506
11507 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/match.js
11508 var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
11509 var parseOrdinalNumberPattern = /\d+/i;
11510 var matchEraPatterns = {
11511 narrow: /^(b|a)/i,
11512 abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
11513 wide: /^(before christ|before common era|anno domini|common era)/i
11514 };
11515 var parseEraPatterns = {
11516 any: [/^b/i, /^(a|c)/i]
11517 };
11518 var matchQuarterPatterns = {
11519 narrow: /^[1234]/i,
11520 abbreviated: /^q[1234]/i,
11521 wide: /^[1234](th|st|nd|rd)? quarter/i
11522 };
11523 var parseQuarterPatterns = {
11524 any: [/1/i, /2/i, /3/i, /4/i]
11525 };
11526 var matchMonthPatterns = {
11527 narrow: /^[jfmasond]/i,
11528 abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
11529 wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
11530 };
11531 var parseMonthPatterns = {
11532 narrow: [
11533 /^j/i,
11534 /^f/i,
11535 /^m/i,
11536 /^a/i,
11537 /^m/i,
11538 /^j/i,
11539 /^j/i,
11540 /^a/i,
11541 /^s/i,
11542 /^o/i,
11543 /^n/i,
11544 /^d/i
11545 ],
11546 any: [
11547 /^ja/i,
11548 /^f/i,
11549 /^mar/i,
11550 /^ap/i,
11551 /^may/i,
11552 /^jun/i,
11553 /^jul/i,
11554 /^au/i,
11555 /^s/i,
11556 /^o/i,
11557 /^n/i,
11558 /^d/i
11559 ]
11560 };
11561 var matchDayPatterns = {
11562 narrow: /^[smtwf]/i,
11563 short: /^(su|mo|tu|we|th|fr|sa)/i,
11564 abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
11565 wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
11566 };
11567 var parseDayPatterns = {
11568 narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
11569 any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
11570 };
11571 var matchDayPeriodPatterns = {
11572 narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
11573 any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
11574 };
11575 var parseDayPeriodPatterns = {
11576 any: {
11577 am: /^a/i,
11578 pm: /^p/i,
11579 midnight: /^mi/i,
11580 noon: /^no/i,
11581 morning: /morning/i,
11582 afternoon: /afternoon/i,
11583 evening: /evening/i,
11584 night: /night/i
11585 }
11586 };
11587 var match = {
11588 ordinalNumber: buildMatchPatternFn({
11589 matchPattern: matchOrdinalNumberPattern,
11590 parsePattern: parseOrdinalNumberPattern,
11591 valueCallback: (value) => parseInt(value, 10)
11592 }),
11593 era: buildMatchFn({
11594 matchPatterns: matchEraPatterns,
11595 defaultMatchWidth: "wide",
11596 parsePatterns: parseEraPatterns,
11597 defaultParseWidth: "any"
11598 }),
11599 quarter: buildMatchFn({
11600 matchPatterns: matchQuarterPatterns,
11601 defaultMatchWidth: "wide",
11602 parsePatterns: parseQuarterPatterns,
11603 defaultParseWidth: "any",
11604 valueCallback: (index) => index + 1
11605 }),
11606 month: buildMatchFn({
11607 matchPatterns: matchMonthPatterns,
11608 defaultMatchWidth: "wide",
11609 parsePatterns: parseMonthPatterns,
11610 defaultParseWidth: "any"
11611 }),
11612 day: buildMatchFn({
11613 matchPatterns: matchDayPatterns,
11614 defaultMatchWidth: "wide",
11615 parsePatterns: parseDayPatterns,
11616 defaultParseWidth: "any"
11617 }),
11618 dayPeriod: buildMatchFn({
11619 matchPatterns: matchDayPeriodPatterns,
11620 defaultMatchWidth: "any",
11621 parsePatterns: parseDayPeriodPatterns,
11622 defaultParseWidth: "any"
11623 })
11624 };
11625
11626 // packages/dataviews/node_modules/date-fns/locale/en-US.js
11627 var enUS = {
11628 code: "en-US",
11629 formatDistance,
11630 formatLong,
11631 formatRelative,
11632 localize,
11633 match,
11634 options: {
11635 weekStartsOn: 0,
11636 firstWeekContainsDate: 1
11637 }
11638 };
11639
11640 // packages/dataviews/node_modules/date-fns/getDayOfYear.js
11641 function getDayOfYear(date, options) {
11642 const _date = toDate(date, options?.in);
11643 const diff = differenceInCalendarDays(_date, startOfYear(_date));
11644 const dayOfYear = diff + 1;
11645 return dayOfYear;
11646 }
11647
11648 // packages/dataviews/node_modules/date-fns/getISOWeek.js
11649 function getISOWeek(date, options) {
11650 const _date = toDate(date, options?.in);
11651 const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
11652 return Math.round(diff / millisecondsInWeek) + 1;
11653 }
11654
11655 // packages/dataviews/node_modules/date-fns/getWeekYear.js
11656 function getWeekYear(date, options) {
11657 const _date = toDate(date, options?.in);
11658 const year = _date.getFullYear();
11659 const defaultOptions2 = getDefaultOptions();
11660 const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
11661 const firstWeekOfNextYear = constructFrom(options?.in || date, 0);
11662 firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
11663 firstWeekOfNextYear.setHours(0, 0, 0, 0);
11664 const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
11665 const firstWeekOfThisYear = constructFrom(options?.in || date, 0);
11666 firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
11667 firstWeekOfThisYear.setHours(0, 0, 0, 0);
11668 const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
11669 if (+_date >= +startOfNextYear) {
11670 return year + 1;
11671 } else if (+_date >= +startOfThisYear) {
11672 return year;
11673 } else {
11674 return year - 1;
11675 }
11676 }
11677
11678 // packages/dataviews/node_modules/date-fns/startOfWeekYear.js
11679 function startOfWeekYear(date, options) {
11680 const defaultOptions2 = getDefaultOptions();
11681 const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
11682 const year = getWeekYear(date, options);
11683 const firstWeek = constructFrom(options?.in || date, 0);
11684 firstWeek.setFullYear(year, 0, firstWeekContainsDate);
11685 firstWeek.setHours(0, 0, 0, 0);
11686 const _date = startOfWeek(firstWeek, options);
11687 return _date;
11688 }
11689
11690 // packages/dataviews/node_modules/date-fns/getWeek.js
11691 function getWeek(date, options) {
11692 const _date = toDate(date, options?.in);
11693 const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
11694 return Math.round(diff / millisecondsInWeek) + 1;
11695 }
11696
11697 // packages/dataviews/node_modules/date-fns/_lib/addLeadingZeros.js
11698 function addLeadingZeros(number, targetLength) {
11699 const sign = number < 0 ? "-" : "";
11700 const output = Math.abs(number).toString().padStart(targetLength, "0");
11701 return sign + output;
11702 }
11703
11704 // packages/dataviews/node_modules/date-fns/_lib/format/lightFormatters.js
11705 var lightFormatters = {
11706 // Year
11707 y(date, token) {
11708 const signedYear = date.getFullYear();
11709 const year = signedYear > 0 ? signedYear : 1 - signedYear;
11710 return addLeadingZeros(token === "yy" ? year % 100 : year, token.length);
11711 },
11712 // Month
11713 M(date, token) {
11714 const month = date.getMonth();
11715 return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2);
11716 },
11717 // Day of the month
11718 d(date, token) {
11719 return addLeadingZeros(date.getDate(), token.length);
11720 },
11721 // AM or PM
11722 a(date, token) {
11723 const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am";
11724 switch (token) {
11725 case "a":
11726 case "aa":
11727 return dayPeriodEnumValue.toUpperCase();
11728 case "aaa":
11729 return dayPeriodEnumValue;
11730 case "aaaaa":
11731 return dayPeriodEnumValue[0];
11732 case "aaaa":
11733 default:
11734 return dayPeriodEnumValue === "am" ? "a.m." : "p.m.";
11735 }
11736 },
11737 // Hour [1-12]
11738 h(date, token) {
11739 return addLeadingZeros(date.getHours() % 12 || 12, token.length);
11740 },
11741 // Hour [0-23]
11742 H(date, token) {
11743 return addLeadingZeros(date.getHours(), token.length);
11744 },
11745 // Minute
11746 m(date, token) {
11747 return addLeadingZeros(date.getMinutes(), token.length);
11748 },
11749 // Second
11750 s(date, token) {
11751 return addLeadingZeros(date.getSeconds(), token.length);
11752 },
11753 // Fraction of second
11754 S(date, token) {
11755 const numberOfDigits = token.length;
11756 const milliseconds = date.getMilliseconds();
11757 const fractionalSeconds = Math.trunc(
11758 milliseconds * Math.pow(10, numberOfDigits - 3)
11759 );
11760 return addLeadingZeros(fractionalSeconds, token.length);
11761 }
11762 };
11763
11764 // packages/dataviews/node_modules/date-fns/_lib/format/formatters.js
11765 var dayPeriodEnum = {
11766 am: "am",
11767 pm: "pm",
11768 midnight: "midnight",
11769 noon: "noon",
11770 morning: "morning",
11771 afternoon: "afternoon",
11772 evening: "evening",
11773 night: "night"
11774 };
11775 var formatters = {
11776 // Era
11777 G: function(date, token, localize2) {
11778 const era = date.getFullYear() > 0 ? 1 : 0;
11779 switch (token) {
11780 // AD, BC
11781 case "G":
11782 case "GG":
11783 case "GGG":
11784 return localize2.era(era, { width: "abbreviated" });
11785 // A, B
11786 case "GGGGG":
11787 return localize2.era(era, { width: "narrow" });
11788 // Anno Domini, Before Christ
11789 case "GGGG":
11790 default:
11791 return localize2.era(era, { width: "wide" });
11792 }
11793 },
11794 // Year
11795 y: function(date, token, localize2) {
11796 if (token === "yo") {
11797 const signedYear = date.getFullYear();
11798 const year = signedYear > 0 ? signedYear : 1 - signedYear;
11799 return localize2.ordinalNumber(year, { unit: "year" });
11800 }
11801 return lightFormatters.y(date, token);
11802 },
11803 // Local week-numbering year
11804 Y: function(date, token, localize2, options) {
11805 const signedWeekYear = getWeekYear(date, options);
11806 const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
11807 if (token === "YY") {
11808 const twoDigitYear = weekYear % 100;
11809 return addLeadingZeros(twoDigitYear, 2);
11810 }
11811 if (token === "Yo") {
11812 return localize2.ordinalNumber(weekYear, { unit: "year" });
11813 }
11814 return addLeadingZeros(weekYear, token.length);
11815 },
11816 // ISO week-numbering year
11817 R: function(date, token) {
11818 const isoWeekYear = getISOWeekYear(date);
11819 return addLeadingZeros(isoWeekYear, token.length);
11820 },
11821 // Extended year. This is a single number designating the year of this calendar system.
11822 // The main difference between `y` and `u` localizers are B.C. years:
11823 // | Year | `y` | `u` |
11824 // |------|-----|-----|
11825 // | AC 1 | 1 | 1 |
11826 // | BC 1 | 1 | 0 |
11827 // | BC 2 | 2 | -1 |
11828 // Also `yy` always returns the last two digits of a year,
11829 // while `uu` pads single digit years to 2 characters and returns other years unchanged.
11830 u: function(date, token) {
11831 const year = date.getFullYear();
11832 return addLeadingZeros(year, token.length);
11833 },
11834 // Quarter
11835 Q: function(date, token, localize2) {
11836 const quarter = Math.ceil((date.getMonth() + 1) / 3);
11837 switch (token) {
11838 // 1, 2, 3, 4
11839 case "Q":
11840 return String(quarter);
11841 // 01, 02, 03, 04
11842 case "QQ":
11843 return addLeadingZeros(quarter, 2);
11844 // 1st, 2nd, 3rd, 4th
11845 case "Qo":
11846 return localize2.ordinalNumber(quarter, { unit: "quarter" });
11847 // Q1, Q2, Q3, Q4
11848 case "QQQ":
11849 return localize2.quarter(quarter, {
11850 width: "abbreviated",
11851 context: "formatting"
11852 });
11853 // 1, 2, 3, 4 (narrow quarter; could be not numerical)
11854 case "QQQQQ":
11855 return localize2.quarter(quarter, {
11856 width: "narrow",
11857 context: "formatting"
11858 });
11859 // 1st quarter, 2nd quarter, ...
11860 case "QQQQ":
11861 default:
11862 return localize2.quarter(quarter, {
11863 width: "wide",
11864 context: "formatting"
11865 });
11866 }
11867 },
11868 // Stand-alone quarter
11869 q: function(date, token, localize2) {
11870 const quarter = Math.ceil((date.getMonth() + 1) / 3);
11871 switch (token) {
11872 // 1, 2, 3, 4
11873 case "q":
11874 return String(quarter);
11875 // 01, 02, 03, 04
11876 case "qq":
11877 return addLeadingZeros(quarter, 2);
11878 // 1st, 2nd, 3rd, 4th
11879 case "qo":
11880 return localize2.ordinalNumber(quarter, { unit: "quarter" });
11881 // Q1, Q2, Q3, Q4
11882 case "qqq":
11883 return localize2.quarter(quarter, {
11884 width: "abbreviated",
11885 context: "standalone"
11886 });
11887 // 1, 2, 3, 4 (narrow quarter; could be not numerical)
11888 case "qqqqq":
11889 return localize2.quarter(quarter, {
11890 width: "narrow",
11891 context: "standalone"
11892 });
11893 // 1st quarter, 2nd quarter, ...
11894 case "qqqq":
11895 default:
11896 return localize2.quarter(quarter, {
11897 width: "wide",
11898 context: "standalone"
11899 });
11900 }
11901 },
11902 // Month
11903 M: function(date, token, localize2) {
11904 const month = date.getMonth();
11905 switch (token) {
11906 case "M":
11907 case "MM":
11908 return lightFormatters.M(date, token);
11909 // 1st, 2nd, ..., 12th
11910 case "Mo":
11911 return localize2.ordinalNumber(month + 1, { unit: "month" });
11912 // Jan, Feb, ..., Dec
11913 case "MMM":
11914 return localize2.month(month, {
11915 width: "abbreviated",
11916 context: "formatting"
11917 });
11918 // J, F, ..., D
11919 case "MMMMM":
11920 return localize2.month(month, {
11921 width: "narrow",
11922 context: "formatting"
11923 });
11924 // January, February, ..., December
11925 case "MMMM":
11926 default:
11927 return localize2.month(month, { width: "wide", context: "formatting" });
11928 }
11929 },
11930 // Stand-alone month
11931 L: function(date, token, localize2) {
11932 const month = date.getMonth();
11933 switch (token) {
11934 // 1, 2, ..., 12
11935 case "L":
11936 return String(month + 1);
11937 // 01, 02, ..., 12
11938 case "LL":
11939 return addLeadingZeros(month + 1, 2);
11940 // 1st, 2nd, ..., 12th
11941 case "Lo":
11942 return localize2.ordinalNumber(month + 1, { unit: "month" });
11943 // Jan, Feb, ..., Dec
11944 case "LLL":
11945 return localize2.month(month, {
11946 width: "abbreviated",
11947 context: "standalone"
11948 });
11949 // J, F, ..., D
11950 case "LLLLL":
11951 return localize2.month(month, {
11952 width: "narrow",
11953 context: "standalone"
11954 });
11955 // January, February, ..., December
11956 case "LLLL":
11957 default:
11958 return localize2.month(month, { width: "wide", context: "standalone" });
11959 }
11960 },
11961 // Local week of year
11962 w: function(date, token, localize2, options) {
11963 const week = getWeek(date, options);
11964 if (token === "wo") {
11965 return localize2.ordinalNumber(week, { unit: "week" });
11966 }
11967 return addLeadingZeros(week, token.length);
11968 },
11969 // ISO week of year
11970 I: function(date, token, localize2) {
11971 const isoWeek = getISOWeek(date);
11972 if (token === "Io") {
11973 return localize2.ordinalNumber(isoWeek, { unit: "week" });
11974 }
11975 return addLeadingZeros(isoWeek, token.length);
11976 },
11977 // Day of the month
11978 d: function(date, token, localize2) {
11979 if (token === "do") {
11980 return localize2.ordinalNumber(date.getDate(), { unit: "date" });
11981 }
11982 return lightFormatters.d(date, token);
11983 },
11984 // Day of year
11985 D: function(date, token, localize2) {
11986 const dayOfYear = getDayOfYear(date);
11987 if (token === "Do") {
11988 return localize2.ordinalNumber(dayOfYear, { unit: "dayOfYear" });
11989 }
11990 return addLeadingZeros(dayOfYear, token.length);
11991 },
11992 // Day of week
11993 E: function(date, token, localize2) {
11994 const dayOfWeek = date.getDay();
11995 switch (token) {
11996 // Tue
11997 case "E":
11998 case "EE":
11999 case "EEE":
12000 return localize2.day(dayOfWeek, {
12001 width: "abbreviated",
12002 context: "formatting"
12003 });
12004 // T
12005 case "EEEEE":
12006 return localize2.day(dayOfWeek, {
12007 width: "narrow",
12008 context: "formatting"
12009 });
12010 // Tu
12011 case "EEEEEE":
12012 return localize2.day(dayOfWeek, {
12013 width: "short",
12014 context: "formatting"
12015 });
12016 // Tuesday
12017 case "EEEE":
12018 default:
12019 return localize2.day(dayOfWeek, {
12020 width: "wide",
12021 context: "formatting"
12022 });
12023 }
12024 },
12025 // Local day of week
12026 e: function(date, token, localize2, options) {
12027 const dayOfWeek = date.getDay();
12028 const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
12029 switch (token) {
12030 // Numerical value (Nth day of week with current locale or weekStartsOn)
12031 case "e":
12032 return String(localDayOfWeek);
12033 // Padded numerical value
12034 case "ee":
12035 return addLeadingZeros(localDayOfWeek, 2);
12036 // 1st, 2nd, ..., 7th
12037 case "eo":
12038 return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
12039 case "eee":
12040 return localize2.day(dayOfWeek, {
12041 width: "abbreviated",
12042 context: "formatting"
12043 });
12044 // T
12045 case "eeeee":
12046 return localize2.day(dayOfWeek, {
12047 width: "narrow",
12048 context: "formatting"
12049 });
12050 // Tu
12051 case "eeeeee":
12052 return localize2.day(dayOfWeek, {
12053 width: "short",
12054 context: "formatting"
12055 });
12056 // Tuesday
12057 case "eeee":
12058 default:
12059 return localize2.day(dayOfWeek, {
12060 width: "wide",
12061 context: "formatting"
12062 });
12063 }
12064 },
12065 // Stand-alone local day of week
12066 c: function(date, token, localize2, options) {
12067 const dayOfWeek = date.getDay();
12068 const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
12069 switch (token) {
12070 // Numerical value (same as in `e`)
12071 case "c":
12072 return String(localDayOfWeek);
12073 // Padded numerical value
12074 case "cc":
12075 return addLeadingZeros(localDayOfWeek, token.length);
12076 // 1st, 2nd, ..., 7th
12077 case "co":
12078 return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
12079 case "ccc":
12080 return localize2.day(dayOfWeek, {
12081 width: "abbreviated",
12082 context: "standalone"
12083 });
12084 // T
12085 case "ccccc":
12086 return localize2.day(dayOfWeek, {
12087 width: "narrow",
12088 context: "standalone"
12089 });
12090 // Tu
12091 case "cccccc":
12092 return localize2.day(dayOfWeek, {
12093 width: "short",
12094 context: "standalone"
12095 });
12096 // Tuesday
12097 case "cccc":
12098 default:
12099 return localize2.day(dayOfWeek, {
12100 width: "wide",
12101 context: "standalone"
12102 });
12103 }
12104 },
12105 // ISO day of week
12106 i: function(date, token, localize2) {
12107 const dayOfWeek = date.getDay();
12108 const isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
12109 switch (token) {
12110 // 2
12111 case "i":
12112 return String(isoDayOfWeek);
12113 // 02
12114 case "ii":
12115 return addLeadingZeros(isoDayOfWeek, token.length);
12116 // 2nd
12117 case "io":
12118 return localize2.ordinalNumber(isoDayOfWeek, { unit: "day" });
12119 // Tue
12120 case "iii":
12121 return localize2.day(dayOfWeek, {
12122 width: "abbreviated",
12123 context: "formatting"
12124 });
12125 // T
12126 case "iiiii":
12127 return localize2.day(dayOfWeek, {
12128 width: "narrow",
12129 context: "formatting"
12130 });
12131 // Tu
12132 case "iiiiii":
12133 return localize2.day(dayOfWeek, {
12134 width: "short",
12135 context: "formatting"
12136 });
12137 // Tuesday
12138 case "iiii":
12139 default:
12140 return localize2.day(dayOfWeek, {
12141 width: "wide",
12142 context: "formatting"
12143 });
12144 }
12145 },
12146 // AM or PM
12147 a: function(date, token, localize2) {
12148 const hours = date.getHours();
12149 const dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
12150 switch (token) {
12151 case "a":
12152 case "aa":
12153 return localize2.dayPeriod(dayPeriodEnumValue, {
12154 width: "abbreviated",
12155 context: "formatting"
12156 });
12157 case "aaa":
12158 return localize2.dayPeriod(dayPeriodEnumValue, {
12159 width: "abbreviated",
12160 context: "formatting"
12161 }).toLowerCase();
12162 case "aaaaa":
12163 return localize2.dayPeriod(dayPeriodEnumValue, {
12164 width: "narrow",
12165 context: "formatting"
12166 });
12167 case "aaaa":
12168 default:
12169 return localize2.dayPeriod(dayPeriodEnumValue, {
12170 width: "wide",
12171 context: "formatting"
12172 });
12173 }
12174 },
12175 // AM, PM, midnight, noon
12176 b: function(date, token, localize2) {
12177 const hours = date.getHours();
12178 let dayPeriodEnumValue;
12179 if (hours === 12) {
12180 dayPeriodEnumValue = dayPeriodEnum.noon;
12181 } else if (hours === 0) {
12182 dayPeriodEnumValue = dayPeriodEnum.midnight;
12183 } else {
12184 dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
12185 }
12186 switch (token) {
12187 case "b":
12188 case "bb":
12189 return localize2.dayPeriod(dayPeriodEnumValue, {
12190 width: "abbreviated",
12191 context: "formatting"
12192 });
12193 case "bbb":
12194 return localize2.dayPeriod(dayPeriodEnumValue, {
12195 width: "abbreviated",
12196 context: "formatting"
12197 }).toLowerCase();
12198 case "bbbbb":
12199 return localize2.dayPeriod(dayPeriodEnumValue, {
12200 width: "narrow",
12201 context: "formatting"
12202 });
12203 case "bbbb":
12204 default:
12205 return localize2.dayPeriod(dayPeriodEnumValue, {
12206 width: "wide",
12207 context: "formatting"
12208 });
12209 }
12210 },
12211 // in the morning, in the afternoon, in the evening, at night
12212 B: function(date, token, localize2) {
12213 const hours = date.getHours();
12214 let dayPeriodEnumValue;
12215 if (hours >= 17) {
12216 dayPeriodEnumValue = dayPeriodEnum.evening;
12217 } else if (hours >= 12) {
12218 dayPeriodEnumValue = dayPeriodEnum.afternoon;
12219 } else if (hours >= 4) {
12220 dayPeriodEnumValue = dayPeriodEnum.morning;
12221 } else {
12222 dayPeriodEnumValue = dayPeriodEnum.night;
12223 }
12224 switch (token) {
12225 case "B":
12226 case "BB":
12227 case "BBB":
12228 return localize2.dayPeriod(dayPeriodEnumValue, {
12229 width: "abbreviated",
12230 context: "formatting"
12231 });
12232 case "BBBBB":
12233 return localize2.dayPeriod(dayPeriodEnumValue, {
12234 width: "narrow",
12235 context: "formatting"
12236 });
12237 case "BBBB":
12238 default:
12239 return localize2.dayPeriod(dayPeriodEnumValue, {
12240 width: "wide",
12241 context: "formatting"
12242 });
12243 }
12244 },
12245 // Hour [1-12]
12246 h: function(date, token, localize2) {
12247 if (token === "ho") {
12248 let hours = date.getHours() % 12;
12249 if (hours === 0) hours = 12;
12250 return localize2.ordinalNumber(hours, { unit: "hour" });
12251 }
12252 return lightFormatters.h(date, token);
12253 },
12254 // Hour [0-23]
12255 H: function(date, token, localize2) {
12256 if (token === "Ho") {
12257 return localize2.ordinalNumber(date.getHours(), { unit: "hour" });
12258 }
12259 return lightFormatters.H(date, token);
12260 },
12261 // Hour [0-11]
12262 K: function(date, token, localize2) {
12263 const hours = date.getHours() % 12;
12264 if (token === "Ko") {
12265 return localize2.ordinalNumber(hours, { unit: "hour" });
12266 }
12267 return addLeadingZeros(hours, token.length);
12268 },
12269 // Hour [1-24]
12270 k: function(date, token, localize2) {
12271 let hours = date.getHours();
12272 if (hours === 0) hours = 24;
12273 if (token === "ko") {
12274 return localize2.ordinalNumber(hours, { unit: "hour" });
12275 }
12276 return addLeadingZeros(hours, token.length);
12277 },
12278 // Minute
12279 m: function(date, token, localize2) {
12280 if (token === "mo") {
12281 return localize2.ordinalNumber(date.getMinutes(), { unit: "minute" });
12282 }
12283 return lightFormatters.m(date, token);
12284 },
12285 // Second
12286 s: function(date, token, localize2) {
12287 if (token === "so") {
12288 return localize2.ordinalNumber(date.getSeconds(), { unit: "second" });
12289 }
12290 return lightFormatters.s(date, token);
12291 },
12292 // Fraction of second
12293 S: function(date, token) {
12294 return lightFormatters.S(date, token);
12295 },
12296 // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
12297 X: function(date, token, _localize) {
12298 const timezoneOffset = date.getTimezoneOffset();
12299 if (timezoneOffset === 0) {
12300 return "Z";
12301 }
12302 switch (token) {
12303 // Hours and optional minutes
12304 case "X":
12305 return formatTimezoneWithOptionalMinutes(timezoneOffset);
12306 // Hours, minutes and optional seconds without `:` delimiter
12307 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12308 // so this token always has the same output as `XX`
12309 case "XXXX":
12310 case "XX":
12311 return formatTimezone(timezoneOffset);
12312 // Hours, minutes and optional seconds with `:` delimiter
12313 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12314 // so this token always has the same output as `XXX`
12315 case "XXXXX":
12316 case "XXX":
12317 // Hours and minutes with `:` delimiter
12318 default:
12319 return formatTimezone(timezoneOffset, ":");
12320 }
12321 },
12322 // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
12323 x: function(date, token, _localize) {
12324 const timezoneOffset = date.getTimezoneOffset();
12325 switch (token) {
12326 // Hours and optional minutes
12327 case "x":
12328 return formatTimezoneWithOptionalMinutes(timezoneOffset);
12329 // Hours, minutes and optional seconds without `:` delimiter
12330 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12331 // so this token always has the same output as `xx`
12332 case "xxxx":
12333 case "xx":
12334 return formatTimezone(timezoneOffset);
12335 // Hours, minutes and optional seconds with `:` delimiter
12336 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12337 // so this token always has the same output as `xxx`
12338 case "xxxxx":
12339 case "xxx":
12340 // Hours and minutes with `:` delimiter
12341 default:
12342 return formatTimezone(timezoneOffset, ":");
12343 }
12344 },
12345 // Timezone (GMT)
12346 O: function(date, token, _localize) {
12347 const timezoneOffset = date.getTimezoneOffset();
12348 switch (token) {
12349 // Short
12350 case "O":
12351 case "OO":
12352 case "OOO":
12353 return "GMT" + formatTimezoneShort(timezoneOffset, ":");
12354 // Long
12355 case "OOOO":
12356 default:
12357 return "GMT" + formatTimezone(timezoneOffset, ":");
12358 }
12359 },
12360 // Timezone (specific non-location)
12361 z: function(date, token, _localize) {
12362 const timezoneOffset = date.getTimezoneOffset();
12363 switch (token) {
12364 // Short
12365 case "z":
12366 case "zz":
12367 case "zzz":
12368 return "GMT" + formatTimezoneShort(timezoneOffset, ":");
12369 // Long
12370 case "zzzz":
12371 default:
12372 return "GMT" + formatTimezone(timezoneOffset, ":");
12373 }
12374 },
12375 // Seconds timestamp
12376 t: function(date, token, _localize) {
12377 const timestamp = Math.trunc(+date / 1e3);
12378 return addLeadingZeros(timestamp, token.length);
12379 },
12380 // Milliseconds timestamp
12381 T: function(date, token, _localize) {
12382 return addLeadingZeros(+date, token.length);
12383 }
12384 };
12385 function formatTimezoneShort(offset, delimiter = "") {
12386 const sign = offset > 0 ? "-" : "+";
12387 const absOffset = Math.abs(offset);
12388 const hours = Math.trunc(absOffset / 60);
12389 const minutes = absOffset % 60;
12390 if (minutes === 0) {
12391 return sign + String(hours);
12392 }
12393 return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
12394 }
12395 function formatTimezoneWithOptionalMinutes(offset, delimiter) {
12396 if (offset % 60 === 0) {
12397 const sign = offset > 0 ? "-" : "+";
12398 return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
12399 }
12400 return formatTimezone(offset, delimiter);
12401 }
12402 function formatTimezone(offset, delimiter = "") {
12403 const sign = offset > 0 ? "-" : "+";
12404 const absOffset = Math.abs(offset);
12405 const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2);
12406 const minutes = addLeadingZeros(absOffset % 60, 2);
12407 return sign + hours + delimiter + minutes;
12408 }
12409
12410 // packages/dataviews/node_modules/date-fns/_lib/format/longFormatters.js
12411 var dateLongFormatter = (pattern, formatLong2) => {
12412 switch (pattern) {
12413 case "P":
12414 return formatLong2.date({ width: "short" });
12415 case "PP":
12416 return formatLong2.date({ width: "medium" });
12417 case "PPP":
12418 return formatLong2.date({ width: "long" });
12419 case "PPPP":
12420 default:
12421 return formatLong2.date({ width: "full" });
12422 }
12423 };
12424 var timeLongFormatter = (pattern, formatLong2) => {
12425 switch (pattern) {
12426 case "p":
12427 return formatLong2.time({ width: "short" });
12428 case "pp":
12429 return formatLong2.time({ width: "medium" });
12430 case "ppp":
12431 return formatLong2.time({ width: "long" });
12432 case "pppp":
12433 default:
12434 return formatLong2.time({ width: "full" });
12435 }
12436 };
12437 var dateTimeLongFormatter = (pattern, formatLong2) => {
12438 const matchResult = pattern.match(/(P+)(p+)?/) || [];
12439 const datePattern = matchResult[1];
12440 const timePattern = matchResult[2];
12441 if (!timePattern) {
12442 return dateLongFormatter(pattern, formatLong2);
12443 }
12444 let dateTimeFormat;
12445 switch (datePattern) {
12446 case "P":
12447 dateTimeFormat = formatLong2.dateTime({ width: "short" });
12448 break;
12449 case "PP":
12450 dateTimeFormat = formatLong2.dateTime({ width: "medium" });
12451 break;
12452 case "PPP":
12453 dateTimeFormat = formatLong2.dateTime({ width: "long" });
12454 break;
12455 case "PPPP":
12456 default:
12457 dateTimeFormat = formatLong2.dateTime({ width: "full" });
12458 break;
12459 }
12460 return dateTimeFormat.replace("{{date}}", dateLongFormatter(datePattern, formatLong2)).replace("{{time}}", timeLongFormatter(timePattern, formatLong2));
12461 };
12462 var longFormatters = {
12463 p: timeLongFormatter,
12464 P: dateTimeLongFormatter
12465 };
12466
12467 // packages/dataviews/node_modules/date-fns/_lib/protectedTokens.js
12468 var dayOfYearTokenRE = /^D+$/;
12469 var weekYearTokenRE = /^Y+$/;
12470 var throwTokens = ["D", "DD", "YY", "YYYY"];
12471 function isProtectedDayOfYearToken(token) {
12472 return dayOfYearTokenRE.test(token);
12473 }
12474 function isProtectedWeekYearToken(token) {
12475 return weekYearTokenRE.test(token);
12476 }
12477 function warnOrThrowProtectedError(token, format6, input) {
12478 const _message = message(token, format6, input);
12479 console.warn(_message);
12480 if (throwTokens.includes(token)) throw new RangeError(_message);
12481 }
12482 function message(token, format6, input) {
12483 const subject = token[0] === "Y" ? "years" : "days of the month";
12484 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`;
12485 }
12486
12487 // packages/dataviews/node_modules/date-fns/format.js
12488 var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
12489 var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
12490 var escapedStringRegExp = /^'([^]*?)'?$/;
12491 var doubleQuoteRegExp = /''/g;
12492 var unescapedLatinCharacterRegExp = /[a-zA-Z]/;
12493 function format(date, formatStr, options) {
12494 const defaultOptions2 = getDefaultOptions();
12495 const locale = options?.locale ?? defaultOptions2.locale ?? enUS;
12496 const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
12497 const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
12498 const originalDate = toDate(date, options?.in);
12499 if (!isValid(originalDate)) {
12500 throw new RangeError("Invalid time value");
12501 }
12502 let parts = formatStr.match(longFormattingTokensRegExp).map((substring) => {
12503 const firstCharacter = substring[0];
12504 if (firstCharacter === "p" || firstCharacter === "P") {
12505 const longFormatter = longFormatters[firstCharacter];
12506 return longFormatter(substring, locale.formatLong);
12507 }
12508 return substring;
12509 }).join("").match(formattingTokensRegExp).map((substring) => {
12510 if (substring === "''") {
12511 return { isToken: false, value: "'" };
12512 }
12513 const firstCharacter = substring[0];
12514 if (firstCharacter === "'") {
12515 return { isToken: false, value: cleanEscapedString(substring) };
12516 }
12517 if (formatters[firstCharacter]) {
12518 return { isToken: true, value: substring };
12519 }
12520 if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
12521 throw new RangeError(
12522 "Format string contains an unescaped latin alphabet character `" + firstCharacter + "`"
12523 );
12524 }
12525 return { isToken: false, value: substring };
12526 });
12527 if (locale.localize.preprocessor) {
12528 parts = locale.localize.preprocessor(originalDate, parts);
12529 }
12530 const formatterOptions = {
12531 firstWeekContainsDate,
12532 weekStartsOn,
12533 locale
12534 };
12535 return parts.map((part) => {
12536 if (!part.isToken) return part.value;
12537 const token = part.value;
12538 if (!options?.useAdditionalWeekYearTokens && isProtectedWeekYearToken(token) || !options?.useAdditionalDayOfYearTokens && isProtectedDayOfYearToken(token)) {
12539 warnOrThrowProtectedError(token, formatStr, String(date));
12540 }
12541 const formatter = formatters[token[0]];
12542 return formatter(originalDate, token, locale.localize, formatterOptions);
12543 }).join("");
12544 }
12545 function cleanEscapedString(input) {
12546 const matched = input.match(escapedStringRegExp);
12547 if (!matched) {
12548 return input;
12549 }
12550 return matched[1].replace(doubleQuoteRegExp, "'");
12551 }
12552
12553 // packages/dataviews/node_modules/date-fns/subDays.js
12554 function subDays(date, amount, options) {
12555 return addDays(date, -amount, options);
12556 }
12557
12558 // packages/dataviews/node_modules/date-fns/subMonths.js
12559 function subMonths(date, amount, options) {
12560 return addMonths(date, -amount, options);
12561 }
12562
12563 // packages/dataviews/node_modules/date-fns/subWeeks.js
12564 function subWeeks(date, amount, options) {
12565 return addWeeks(date, -amount, options);
12566 }
12567
12568 // packages/dataviews/node_modules/date-fns/subYears.js
12569 function subYears(date, amount, options) {
12570 return addYears(date, -amount, options);
12571 }
12572
12573 // packages/dataviews/build-module/utils/operators.mjs
12574 var import_i18n29 = __toESM(require_i18n(), 1);
12575 var import_element28 = __toESM(require_element(), 1);
12576 var import_date = __toESM(require_date(), 1);
12577 var import_jsx_runtime64 = __toESM(require_jsx_runtime(), 1);
12578 var filterTextWrappers = {
12579 Name: /* @__PURE__ */ (0, import_jsx_runtime64.jsx)("span", { className: "dataviews-filters__summary-filter-text-name" }),
12580 Value: /* @__PURE__ */ (0, import_jsx_runtime64.jsx)("span", { className: "dataviews-filters__summary-filter-text-value" })
12581 };
12582 function getRelativeDate(value, unit) {
12583 switch (unit) {
12584 case "days":
12585 return subDays(/* @__PURE__ */ new Date(), value);
12586 case "weeks":
12587 return subWeeks(/* @__PURE__ */ new Date(), value);
12588 case "months":
12589 return subMonths(/* @__PURE__ */ new Date(), value);
12590 case "years":
12591 return subYears(/* @__PURE__ */ new Date(), value);
12592 default:
12593 return /* @__PURE__ */ new Date();
12594 }
12595 }
12596 var isNoneOperatorDefinition = {
12597 /* translators: DataViews operator name */
12598 label: (0, import_i18n29.__)("Is none of"),
12599 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12600 (0, import_i18n29.sprintf)(
12601 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is none of: Admin, Editor". */
12602 (0, import_i18n29.__)("<Name>%1$s is none of: </Name><Value>%2$s</Value>"),
12603 filter.name,
12604 activeElements.map((element) => element.label).join(", ")
12605 ),
12606 filterTextWrappers
12607 ),
12608 filter: ((item, field, filterValue) => {
12609 if (!filterValue?.length) {
12610 return true;
12611 }
12612 const fieldValue = field.getValue({ item });
12613 if (Array.isArray(fieldValue)) {
12614 return !filterValue.some(
12615 (fv) => fieldValue.includes(fv)
12616 );
12617 } else if (typeof fieldValue === "string") {
12618 return !filterValue.includes(fieldValue);
12619 }
12620 return false;
12621 }),
12622 selection: "multi"
12623 };
12624 var OPERATORS = [
12625 {
12626 name: OPERATOR_IS_ANY,
12627 /* translators: DataViews operator name */
12628 label: (0, import_i18n29.__)("Includes"),
12629 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12630 (0, import_i18n29.sprintf)(
12631 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is any: Admin, Editor". */
12632 (0, import_i18n29.__)("<Name>%1$s includes: </Name><Value>%2$s</Value>"),
12633 filter.name,
12634 activeElements.map((element) => element.label).join(", ")
12635 ),
12636 filterTextWrappers
12637 ),
12638 filter(item, field, filterValue) {
12639 if (!filterValue?.length) {
12640 return true;
12641 }
12642 const fieldValue = field.getValue({ item });
12643 if (Array.isArray(fieldValue)) {
12644 return filterValue.some(
12645 (fv) => fieldValue.includes(fv)
12646 );
12647 } else if (typeof fieldValue === "string") {
12648 return filterValue.includes(fieldValue);
12649 }
12650 return false;
12651 },
12652 selection: "multi"
12653 },
12654 {
12655 name: OPERATOR_IS_NONE,
12656 ...isNoneOperatorDefinition
12657 },
12658 {
12659 name: OPERATOR_IS_ALL,
12660 /* translators: DataViews operator name */
12661 label: (0, import_i18n29.__)("Includes all"),
12662 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12663 (0, import_i18n29.sprintf)(
12664 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author includes all: Admin, Editor". */
12665 (0, import_i18n29.__)("<Name>%1$s includes all: </Name><Value>%2$s</Value>"),
12666 filter.name,
12667 activeElements.map((element) => element.label).join(", ")
12668 ),
12669 filterTextWrappers
12670 ),
12671 filter(item, field, filterValue) {
12672 if (!filterValue?.length) {
12673 return true;
12674 }
12675 return filterValue.every((value) => {
12676 return field.getValue({ item })?.includes(value);
12677 });
12678 },
12679 selection: "multi"
12680 },
12681 {
12682 name: OPERATOR_IS_NOT_ALL,
12683 ...isNoneOperatorDefinition
12684 },
12685 {
12686 name: OPERATOR_BETWEEN,
12687 /* translators: DataViews operator name */
12688 label: (0, import_i18n29.__)("Between (inc)"),
12689 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12690 (0, import_i18n29.sprintf)(
12691 /* 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". */
12692 (0, import_i18n29.__)(
12693 "<Name>%1$s between (inc): </Name><Value>%2$s and %3$s</Value>"
12694 ),
12695 filter.name,
12696 activeElements[0].label[0],
12697 activeElements[0].label[1]
12698 ),
12699 filterTextWrappers
12700 ),
12701 filter(item, field, filterValue) {
12702 if (!Array.isArray(filterValue) || filterValue.length !== 2 || filterValue[0] === void 0 || filterValue[1] === void 0) {
12703 return true;
12704 }
12705 const fieldValue = field.getValue({ item });
12706 if (typeof fieldValue === "number" || fieldValue instanceof Date || typeof fieldValue === "string") {
12707 return fieldValue >= filterValue[0] && fieldValue <= filterValue[1];
12708 }
12709 return false;
12710 },
12711 selection: "custom"
12712 },
12713 {
12714 name: OPERATOR_IN_THE_PAST,
12715 /* translators: DataViews operator name */
12716 label: (0, import_i18n29.__)("In the past"),
12717 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12718 (0, import_i18n29.sprintf)(
12719 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "7 days"): "Date is in the past: 7 days". */
12720 (0, import_i18n29.__)(
12721 "<Name>%1$s is in the past: </Name><Value>%2$s</Value>"
12722 ),
12723 filter.name,
12724 `${activeElements[0].value.value} ${activeElements[0].value.unit}`
12725 ),
12726 filterTextWrappers
12727 ),
12728 filter(item, field, filterValue) {
12729 if (filterValue?.value === void 0 || filterValue?.unit === void 0) {
12730 return true;
12731 }
12732 const targetDate = getRelativeDate(
12733 filterValue.value,
12734 filterValue.unit
12735 );
12736 const fieldValue = (0, import_date.getDate)(field.getValue({ item }));
12737 return fieldValue >= targetDate && fieldValue <= /* @__PURE__ */ new Date();
12738 },
12739 selection: "custom"
12740 },
12741 {
12742 name: OPERATOR_OVER,
12743 /* translators: DataViews operator name */
12744 label: (0, import_i18n29.__)("Over"),
12745 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12746 (0, import_i18n29.sprintf)(
12747 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "7 days"): "Date is over: 7 days". */
12748 (0, import_i18n29.__)("<Name>%1$s is over: </Name><Value>%2$s</Value>"),
12749 filter.name,
12750 `${activeElements[0].value.value} ${activeElements[0].value.unit}`
12751 ),
12752 filterTextWrappers
12753 ),
12754 filter(item, field, filterValue) {
12755 if (filterValue?.value === void 0 || filterValue?.unit === void 0) {
12756 return true;
12757 }
12758 const targetDate = getRelativeDate(
12759 filterValue.value,
12760 filterValue.unit
12761 );
12762 const fieldValue = (0, import_date.getDate)(field.getValue({ item }));
12763 return fieldValue < targetDate;
12764 },
12765 selection: "custom"
12766 },
12767 {
12768 name: OPERATOR_IS,
12769 /* translators: DataViews operator name */
12770 label: (0, import_i18n29.__)("Is"),
12771 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12772 (0, import_i18n29.sprintf)(
12773 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is: Admin". */
12774 (0, import_i18n29.__)("<Name>%1$s is: </Name><Value>%2$s</Value>"),
12775 filter.name,
12776 activeElements[0].label
12777 ),
12778 filterTextWrappers
12779 ),
12780 filter(item, field, filterValue) {
12781 return filterValue === field.getValue({ item }) || filterValue === void 0;
12782 },
12783 selection: "single"
12784 },
12785 {
12786 name: OPERATOR_IS_NOT,
12787 /* translators: DataViews operator name */
12788 label: (0, import_i18n29.__)("Is not"),
12789 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12790 (0, import_i18n29.sprintf)(
12791 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is not: Admin". */
12792 (0, import_i18n29.__)("<Name>%1$s is not: </Name><Value>%2$s</Value>"),
12793 filter.name,
12794 activeElements[0].label
12795 ),
12796 filterTextWrappers
12797 ),
12798 filter(item, field, filterValue) {
12799 return filterValue !== field.getValue({ item });
12800 },
12801 selection: "single"
12802 },
12803 {
12804 name: OPERATOR_LESS_THAN,
12805 /* translators: DataViews operator name */
12806 label: (0, import_i18n29.__)("Less than"),
12807 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12808 (0, import_i18n29.sprintf)(
12809 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is less than: 10". */
12810 (0, import_i18n29.__)("<Name>%1$s is less than: </Name><Value>%2$s</Value>"),
12811 filter.name,
12812 activeElements[0].label
12813 ),
12814 filterTextWrappers
12815 ),
12816 filter(item, field, filterValue) {
12817 if (filterValue === void 0) {
12818 return true;
12819 }
12820 const fieldValue = field.getValue({ item });
12821 return fieldValue < filterValue;
12822 },
12823 selection: "single"
12824 },
12825 {
12826 name: OPERATOR_GREATER_THAN,
12827 /* translators: DataViews operator name */
12828 label: (0, import_i18n29.__)("Greater than"),
12829 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12830 (0, import_i18n29.sprintf)(
12831 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is greater than: 10". */
12832 (0, import_i18n29.__)(
12833 "<Name>%1$s is greater than: </Name><Value>%2$s</Value>"
12834 ),
12835 filter.name,
12836 activeElements[0].label
12837 ),
12838 filterTextWrappers
12839 ),
12840 filter(item, field, filterValue) {
12841 if (filterValue === void 0) {
12842 return true;
12843 }
12844 const fieldValue = field.getValue({ item });
12845 return fieldValue > filterValue;
12846 },
12847 selection: "single"
12848 },
12849 {
12850 name: OPERATOR_LESS_THAN_OR_EQUAL,
12851 /* translators: DataViews operator name */
12852 label: (0, import_i18n29.__)("Less than or equal"),
12853 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12854 (0, import_i18n29.sprintf)(
12855 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is less than or equal to: 10". */
12856 (0, import_i18n29.__)(
12857 "<Name>%1$s is less than or equal to: </Name><Value>%2$s</Value>"
12858 ),
12859 filter.name,
12860 activeElements[0].label
12861 ),
12862 filterTextWrappers
12863 ),
12864 filter(item, field, filterValue) {
12865 if (filterValue === void 0) {
12866 return true;
12867 }
12868 const fieldValue = field.getValue({ item });
12869 return fieldValue <= filterValue;
12870 },
12871 selection: "single"
12872 },
12873 {
12874 name: OPERATOR_GREATER_THAN_OR_EQUAL,
12875 /* translators: DataViews operator name */
12876 label: (0, import_i18n29.__)("Greater than or equal"),
12877 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12878 (0, import_i18n29.sprintf)(
12879 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is greater than or equal to: 10". */
12880 (0, import_i18n29.__)(
12881 "<Name>%1$s is greater than or equal to: </Name><Value>%2$s</Value>"
12882 ),
12883 filter.name,
12884 activeElements[0].label
12885 ),
12886 filterTextWrappers
12887 ),
12888 filter(item, field, filterValue) {
12889 if (filterValue === void 0) {
12890 return true;
12891 }
12892 const fieldValue = field.getValue({ item });
12893 return fieldValue >= filterValue;
12894 },
12895 selection: "single"
12896 },
12897 {
12898 name: OPERATOR_BEFORE,
12899 /* translators: DataViews operator name */
12900 label: (0, import_i18n29.__)("Before"),
12901 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12902 (0, import_i18n29.sprintf)(
12903 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is before: 2024-01-01". */
12904 (0, import_i18n29.__)("<Name>%1$s is before: </Name><Value>%2$s</Value>"),
12905 filter.name,
12906 activeElements[0].label
12907 ),
12908 filterTextWrappers
12909 ),
12910 filter(item, field, filterValue) {
12911 if (filterValue === void 0) {
12912 return true;
12913 }
12914 const filterDate = (0, import_date.getDate)(filterValue);
12915 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
12916 return fieldDate < filterDate;
12917 },
12918 selection: "single"
12919 },
12920 {
12921 name: OPERATOR_AFTER,
12922 /* translators: DataViews operator name */
12923 label: (0, import_i18n29.__)("After"),
12924 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12925 (0, import_i18n29.sprintf)(
12926 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is after: 2024-01-01". */
12927 (0, import_i18n29.__)("<Name>%1$s is after: </Name><Value>%2$s</Value>"),
12928 filter.name,
12929 activeElements[0].label
12930 ),
12931 filterTextWrappers
12932 ),
12933 filter(item, field, filterValue) {
12934 if (filterValue === void 0) {
12935 return true;
12936 }
12937 const filterDate = (0, import_date.getDate)(filterValue);
12938 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
12939 return fieldDate > filterDate;
12940 },
12941 selection: "single"
12942 },
12943 {
12944 name: OPERATOR_BEFORE_INC,
12945 /* translators: DataViews operator name */
12946 label: (0, import_i18n29.__)("Before (inc)"),
12947 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12948 (0, import_i18n29.sprintf)(
12949 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is on or before: 2024-01-01". */
12950 (0, import_i18n29.__)(
12951 "<Name>%1$s is on or before: </Name><Value>%2$s</Value>"
12952 ),
12953 filter.name,
12954 activeElements[0].label
12955 ),
12956 filterTextWrappers
12957 ),
12958 filter(item, field, filterValue) {
12959 if (filterValue === void 0) {
12960 return true;
12961 }
12962 const filterDate = (0, import_date.getDate)(filterValue);
12963 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
12964 return fieldDate <= filterDate;
12965 },
12966 selection: "single"
12967 },
12968 {
12969 name: OPERATOR_AFTER_INC,
12970 /* translators: DataViews operator name */
12971 label: (0, import_i18n29.__)("After (inc)"),
12972 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12973 (0, import_i18n29.sprintf)(
12974 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is on or after: 2024-01-01". */
12975 (0, import_i18n29.__)(
12976 "<Name>%1$s is on or after: </Name><Value>%2$s</Value>"
12977 ),
12978 filter.name,
12979 activeElements[0].label
12980 ),
12981 filterTextWrappers
12982 ),
12983 filter(item, field, filterValue) {
12984 if (filterValue === void 0) {
12985 return true;
12986 }
12987 const filterDate = (0, import_date.getDate)(filterValue);
12988 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
12989 return fieldDate >= filterDate;
12990 },
12991 selection: "single"
12992 },
12993 {
12994 name: OPERATOR_CONTAINS,
12995 /* translators: DataViews operator name */
12996 label: (0, import_i18n29.__)("Contains"),
12997 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12998 (0, import_i18n29.sprintf)(
12999 /* translators: 1: Filter name (e.g. "Title"). 2: Filter value (e.g. "Hello"): "Title contains: Hello". */
13000 (0, import_i18n29.__)("<Name>%1$s contains: </Name><Value>%2$s</Value>"),
13001 filter.name,
13002 activeElements[0].label
13003 ),
13004 filterTextWrappers
13005 ),
13006 filter(item, field, filterValue) {
13007 if (filterValue === void 0) {
13008 return true;
13009 }
13010 const fieldValue = field.getValue({ item });
13011 return typeof fieldValue === "string" && filterValue && fieldValue.toLowerCase().includes(String(filterValue).toLowerCase());
13012 },
13013 selection: "single"
13014 },
13015 {
13016 name: OPERATOR_NOT_CONTAINS,
13017 /* translators: DataViews operator name */
13018 label: (0, import_i18n29.__)("Doesn't contain"),
13019 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
13020 (0, import_i18n29.sprintf)(
13021 /* translators: 1: Filter name (e.g. "Title"). 2: Filter value (e.g. "Hello"): "Title doesn't contain: Hello". */
13022 (0, import_i18n29.__)(
13023 "<Name>%1$s doesn't contain: </Name><Value>%2$s</Value>"
13024 ),
13025 filter.name,
13026 activeElements[0].label
13027 ),
13028 filterTextWrappers
13029 ),
13030 filter(item, field, filterValue) {
13031 if (filterValue === void 0) {
13032 return true;
13033 }
13034 const fieldValue = field.getValue({ item });
13035 return typeof fieldValue === "string" && filterValue && !fieldValue.toLowerCase().includes(String(filterValue).toLowerCase());
13036 },
13037 selection: "single"
13038 },
13039 {
13040 name: OPERATOR_STARTS_WITH,
13041 /* translators: DataViews operator name */
13042 label: (0, import_i18n29.__)("Starts with"),
13043 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
13044 (0, import_i18n29.sprintf)(
13045 /* translators: 1: Filter name (e.g. "Title"). 2: Filter value (e.g. "Hello"): "Title starts with: Hello". */
13046 (0, import_i18n29.__)("<Name>%1$s starts with: </Name><Value>%2$s</Value>"),
13047 filter.name,
13048 activeElements[0].label
13049 ),
13050 filterTextWrappers
13051 ),
13052 filter(item, field, filterValue) {
13053 if (filterValue === void 0) {
13054 return true;
13055 }
13056 const fieldValue = field.getValue({ item });
13057 return typeof fieldValue === "string" && filterValue && fieldValue.toLowerCase().startsWith(String(filterValue).toLowerCase());
13058 },
13059 selection: "single"
13060 },
13061 {
13062 name: OPERATOR_ON,
13063 /* translators: DataViews operator name */
13064 label: (0, import_i18n29.__)("On"),
13065 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
13066 (0, import_i18n29.sprintf)(
13067 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is: 2024-01-01". */
13068 (0, import_i18n29.__)("<Name>%1$s is: </Name><Value>%2$s</Value>"),
13069 filter.name,
13070 activeElements[0].label
13071 ),
13072 filterTextWrappers
13073 ),
13074 filter(item, field, filterValue) {
13075 if (filterValue === void 0) {
13076 return true;
13077 }
13078 const filterDate = (0, import_date.getDate)(filterValue);
13079 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13080 return filterDate.getTime() === fieldDate.getTime();
13081 },
13082 selection: "single"
13083 },
13084 {
13085 name: OPERATOR_NOT_ON,
13086 /* translators: DataViews operator name */
13087 label: (0, import_i18n29.__)("Not on"),
13088 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
13089 (0, import_i18n29.sprintf)(
13090 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is not: 2024-01-01". */
13091 (0, import_i18n29.__)("<Name>%1$s is not: </Name><Value>%2$s</Value>"),
13092 filter.name,
13093 activeElements[0].label
13094 ),
13095 filterTextWrappers
13096 ),
13097 filter(item, field, filterValue) {
13098 if (filterValue === void 0) {
13099 return true;
13100 }
13101 const filterDate = (0, import_date.getDate)(filterValue);
13102 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13103 return filterDate.getTime() !== fieldDate.getTime();
13104 },
13105 selection: "single"
13106 }
13107 ];
13108 var getOperatorByName = (name) => OPERATORS.find((op) => op.name === name);
13109 var getAllOperatorNames = () => OPERATORS.map((op) => op.name);
13110 var isSingleSelectionOperator = (name) => OPERATORS.filter((op) => op.selection === "single").some(
13111 (op) => op.name === name
13112 );
13113 var isRegisteredOperator = (name) => OPERATORS.some((op) => op.name === name);
13114
13115 // packages/dataviews/build-module/components/dataviews-filters/filter.mjs
13116 var import_jsx_runtime65 = __toESM(require_jsx_runtime(), 1);
13117 var ENTER = "Enter";
13118 var SPACE = " ";
13119 var FilterText = ({
13120 activeElements,
13121 filterInView,
13122 filter
13123 }) => {
13124 if (activeElements === void 0 || activeElements.length === 0) {
13125 return filter.name;
13126 }
13127 const operator = getOperatorByName(filterInView?.operator);
13128 if (operator !== void 0) {
13129 return operator.filterText(filter, activeElements);
13130 }
13131 return (0, import_i18n30.sprintf)(
13132 /* translators: 1: Filter name e.g.: "Unknown status for Author". */
13133 (0, import_i18n30.__)("Unknown status for %1$s"),
13134 filter.name
13135 );
13136 };
13137 function OperatorSelector({
13138 filter,
13139 view,
13140 onChangeView
13141 }) {
13142 const operatorOptions = filter.operators?.map((operator) => ({
13143 value: operator,
13144 label: getOperatorByName(operator)?.label || operator
13145 }));
13146 const currentFilter = view.filters?.find(
13147 (_filter) => _filter.field === filter.field
13148 );
13149 const value = currentFilter?.operator || filter.operators[0];
13150 return operatorOptions.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)(
13151 Stack,
13152 {
13153 direction: "row",
13154 gap: "sm",
13155 justify: "flex-start",
13156 className: "dataviews-filters__summary-operators-container",
13157 align: "center",
13158 children: [
13159 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(import_components21.FlexItem, { className: "dataviews-filters__summary-operators-filter-name", children: filter.name }),
13160 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13161 import_components21.SelectControl,
13162 {
13163 className: "dataviews-filters__summary-operators-filter-select",
13164 label: (0, import_i18n30.__)("Conditions"),
13165 value,
13166 options: operatorOptions,
13167 onChange: (newValue) => {
13168 const newOperator = newValue;
13169 const currentOperator = currentFilter?.operator;
13170 const newFilters = currentFilter ? [
13171 ...(view.filters ?? []).map(
13172 (_filter) => {
13173 if (_filter.field === filter.field) {
13174 const currentOpSelectionModel = getOperatorByName(
13175 currentOperator
13176 )?.selection;
13177 const newOpSelectionModel = getOperatorByName(
13178 newOperator
13179 )?.selection;
13180 const shouldResetValue = currentOpSelectionModel !== newOpSelectionModel || [
13181 currentOpSelectionModel,
13182 newOpSelectionModel
13183 ].includes("custom");
13184 return {
13185 ..._filter,
13186 value: shouldResetValue ? void 0 : _filter.value,
13187 operator: newOperator
13188 };
13189 }
13190 return _filter;
13191 }
13192 )
13193 ] : [
13194 ...view.filters ?? [],
13195 {
13196 field: filter.field,
13197 operator: newOperator,
13198 value: void 0
13199 }
13200 ];
13201 onChangeView({
13202 ...view,
13203 page: 1,
13204 filters: newFilters
13205 });
13206 },
13207 size: "small",
13208 variant: "minimal",
13209 hideLabelFromVision: true
13210 }
13211 )
13212 ]
13213 }
13214 );
13215 }
13216 function Filter({
13217 addFilterRef,
13218 openedFilter,
13219 fields,
13220 ...commonProps
13221 }) {
13222 const toggleRef = (0, import_element29.useRef)(null);
13223 const { filter, view, onChangeView } = commonProps;
13224 const filterInView = view.filters?.find(
13225 (f2) => f2.field === filter.field
13226 );
13227 let activeElements = [];
13228 const field = (0, import_element29.useMemo)(() => {
13229 const currentField = fields.find((f2) => f2.id === filter.field);
13230 if (currentField) {
13231 return {
13232 ...currentField,
13233 // Configure getValue as if Item was a plain object.
13234 // See related input-widget.tsx
13235 getValue: ({ item }) => item[currentField.id]
13236 };
13237 }
13238 return currentField;
13239 }, [fields, filter.field]);
13240 const { elements } = useElements({
13241 elements: filter.elements,
13242 getElements: filter.getElements
13243 });
13244 if (elements.length > 0) {
13245 activeElements = elements.filter((element) => {
13246 if (filter.singleSelection) {
13247 return element.value === filterInView?.value;
13248 }
13249 return filterInView?.value?.includes(element.value);
13250 });
13251 } else if (Array.isArray(filterInView?.value)) {
13252 const label = filterInView.value.map((v2) => {
13253 const formattedValue = field?.getValueFormatted({
13254 item: { [field.id]: v2 },
13255 field
13256 });
13257 return formattedValue || String(v2);
13258 });
13259 activeElements = [
13260 {
13261 value: filterInView.value,
13262 // @ts-ignore
13263 label
13264 }
13265 ];
13266 } else if (typeof filterInView?.value === "object") {
13267 activeElements = [
13268 { value: filterInView.value, label: filterInView.value }
13269 ];
13270 } else if (filterInView?.value !== void 0) {
13271 const label = field !== void 0 ? field.getValueFormatted({
13272 item: { [field.id]: filterInView.value },
13273 field
13274 }) : String(filterInView.value);
13275 activeElements = [
13276 {
13277 value: filterInView.value,
13278 label
13279 }
13280 ];
13281 }
13282 const isPrimary = filter.isPrimary;
13283 const isLocked = filterInView?.isLocked;
13284 const hasValues = !isLocked && filterInView?.value !== void 0;
13285 const canResetOrRemove = !isLocked && (!isPrimary || hasValues);
13286 return /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13287 import_components21.Dropdown,
13288 {
13289 defaultOpen: openedFilter === filter.field,
13290 contentClassName: "dataviews-filters__summary-popover",
13291 popoverProps: { placement: "bottom-start", role: "dialog" },
13292 onClose: () => {
13293 toggleRef.current?.focus();
13294 },
13295 renderToggle: ({ isOpen, onToggle }) => /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)("div", { className: "dataviews-filters__summary-chip-container", children: [
13296 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13297 import_components21.Tooltip,
13298 {
13299 text: (0, import_i18n30.sprintf)(
13300 /* translators: 1: Filter name. */
13301 (0, import_i18n30.__)("Filter by: %1$s"),
13302 filter.name.toLowerCase()
13303 ),
13304 placement: "top",
13305 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13306 "div",
13307 {
13308 className: clsx_default(
13309 "dataviews-filters__summary-chip",
13310 {
13311 "has-reset": canResetOrRemove,
13312 "has-values": hasValues,
13313 "is-not-clickable": isLocked
13314 }
13315 ),
13316 role: "button",
13317 tabIndex: isLocked ? -1 : 0,
13318 onClick: () => {
13319 if (!isLocked) {
13320 onToggle();
13321 }
13322 },
13323 onKeyDown: (event) => {
13324 if (!isLocked && [ENTER, SPACE].includes(event.key)) {
13325 onToggle();
13326 event.preventDefault();
13327 }
13328 },
13329 "aria-disabled": isLocked,
13330 "aria-pressed": isOpen,
13331 "aria-expanded": isOpen,
13332 ref: toggleRef,
13333 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13334 FilterText,
13335 {
13336 activeElements,
13337 filterInView,
13338 filter
13339 }
13340 )
13341 }
13342 )
13343 }
13344 ),
13345 canResetOrRemove && /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13346 import_components21.Tooltip,
13347 {
13348 text: isPrimary ? (0, import_i18n30.__)("Reset") : (0, import_i18n30.__)("Remove"),
13349 placement: "top",
13350 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13351 "button",
13352 {
13353 className: clsx_default(
13354 "dataviews-filters__summary-chip-remove",
13355 { "has-values": hasValues }
13356 ),
13357 onClick: () => {
13358 onChangeView({
13359 ...view,
13360 page: 1,
13361 filters: view.filters?.filter(
13362 (_filter) => _filter.field !== filter.field
13363 )
13364 });
13365 if (!isPrimary) {
13366 addFilterRef.current?.focus();
13367 } else {
13368 toggleRef.current?.focus();
13369 }
13370 },
13371 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(import_components21.Icon, { icon: close_small_default })
13372 }
13373 )
13374 }
13375 )
13376 ] }),
13377 renderContent: () => {
13378 return /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)(Stack, { direction: "column", justify: "flex-start", children: [
13379 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(OperatorSelector, { ...commonProps }),
13380 commonProps.filter.hasElements ? /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13381 SearchWidget,
13382 {
13383 ...commonProps,
13384 filter: {
13385 ...commonProps.filter,
13386 elements
13387 }
13388 }
13389 ) : /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(InputWidget, { ...commonProps, fields })
13390 ] });
13391 }
13392 }
13393 );
13394 }
13395
13396 // packages/dataviews/build-module/components/dataviews-filters/add-filter.mjs
13397 var import_components22 = __toESM(require_components(), 1);
13398 var import_i18n31 = __toESM(require_i18n(), 1);
13399 var import_element30 = __toESM(require_element(), 1);
13400 var import_jsx_runtime66 = __toESM(require_jsx_runtime(), 1);
13401 var { Menu: Menu4 } = unlock(import_components22.privateApis);
13402 function AddFilterMenu({
13403 filters,
13404 view,
13405 onChangeView,
13406 setOpenedFilter,
13407 triggerProps
13408 }) {
13409 const inactiveFilters = filters.filter((filter) => !filter.isVisible);
13410 return /* @__PURE__ */ (0, import_jsx_runtime66.jsxs)(Menu4, { children: [
13411 /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(Menu4.TriggerButton, { ...triggerProps }),
13412 /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(Menu4.Popover, { children: inactiveFilters.map((filter) => {
13413 return /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
13414 Menu4.Item,
13415 {
13416 onClick: () => {
13417 setOpenedFilter(filter.field);
13418 onChangeView({
13419 ...view,
13420 page: 1,
13421 filters: [
13422 ...view.filters || [],
13423 {
13424 field: filter.field,
13425 value: void 0,
13426 operator: filter.operators[0]
13427 }
13428 ]
13429 });
13430 },
13431 children: /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(Menu4.ItemLabel, { children: filter.name })
13432 },
13433 filter.field
13434 );
13435 }) })
13436 ] });
13437 }
13438 function AddFilter({ filters, view, onChangeView, setOpenedFilter }, ref) {
13439 if (!filters.length || filters.every(({ isPrimary }) => isPrimary)) {
13440 return null;
13441 }
13442 const inactiveFilters = filters.filter((filter) => !filter.isVisible);
13443 return /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
13444 AddFilterMenu,
13445 {
13446 triggerProps: {
13447 render: /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
13448 import_components22.Button,
13449 {
13450 accessibleWhenDisabled: true,
13451 size: "compact",
13452 className: "dataviews-filters-button",
13453 variant: "tertiary",
13454 disabled: !inactiveFilters.length,
13455 ref
13456 }
13457 ),
13458 children: (0, import_i18n31.__)("Add filter")
13459 },
13460 ...{ filters, view, onChangeView, setOpenedFilter }
13461 }
13462 );
13463 }
13464 var add_filter_default = (0, import_element30.forwardRef)(AddFilter);
13465
13466 // packages/dataviews/build-module/components/dataviews-filters/reset-filters.mjs
13467 var import_components23 = __toESM(require_components(), 1);
13468 var import_i18n32 = __toESM(require_i18n(), 1);
13469 var import_jsx_runtime67 = __toESM(require_jsx_runtime(), 1);
13470 function ResetFilter({
13471 filters,
13472 view,
13473 onChangeView
13474 }) {
13475 const isPrimary = (field) => filters.some(
13476 (_filter) => _filter.field === field && _filter.isPrimary
13477 );
13478 const isDisabled = !view.search && !view.filters?.some(
13479 (_filter) => !_filter.isLocked && (_filter.value !== void 0 || !isPrimary(_filter.field))
13480 );
13481 return /* @__PURE__ */ (0, import_jsx_runtime67.jsx)(
13482 import_components23.Button,
13483 {
13484 disabled: isDisabled,
13485 accessibleWhenDisabled: true,
13486 size: "compact",
13487 variant: "tertiary",
13488 className: "dataviews-filters__reset-button",
13489 onClick: () => {
13490 onChangeView({
13491 ...view,
13492 page: 1,
13493 search: "",
13494 filters: view.filters?.filter((f2) => !!f2.isLocked) || []
13495 });
13496 },
13497 children: (0, import_i18n32.__)("Reset")
13498 }
13499 );
13500 }
13501
13502 // packages/dataviews/build-module/components/dataviews-filters/use-filters.mjs
13503 var import_element31 = __toESM(require_element(), 1);
13504 function useFilters(fields, view) {
13505 return (0, import_element31.useMemo)(() => {
13506 const filters = [];
13507 fields.forEach((field) => {
13508 if (field.filterBy === false || !field.hasElements && !field.Edit) {
13509 return;
13510 }
13511 const operators = field.filterBy.operators;
13512 const isPrimary = !!field.filterBy?.isPrimary;
13513 const isLocked = view.filters?.some(
13514 (f2) => f2.field === field.id && !!f2.isLocked
13515 ) ?? false;
13516 filters.push({
13517 field: field.id,
13518 name: field.label,
13519 elements: field.elements,
13520 getElements: field.getElements,
13521 hasElements: field.hasElements,
13522 singleSelection: operators.some(
13523 (op) => isSingleSelectionOperator(op)
13524 ),
13525 operators,
13526 isVisible: isLocked || isPrimary || !!view.filters?.some(
13527 (f2) => f2.field === field.id && isRegisteredOperator(f2.operator)
13528 ),
13529 isPrimary,
13530 isLocked
13531 });
13532 });
13533 filters.sort((a2, b2) => {
13534 if (a2.isLocked && !b2.isLocked) {
13535 return -1;
13536 }
13537 if (!a2.isLocked && b2.isLocked) {
13538 return 1;
13539 }
13540 if (a2.isPrimary && !b2.isPrimary) {
13541 return -1;
13542 }
13543 if (!a2.isPrimary && b2.isPrimary) {
13544 return 1;
13545 }
13546 return a2.name.localeCompare(b2.name);
13547 });
13548 return filters;
13549 }, [fields, view]);
13550 }
13551 var use_filters_default = useFilters;
13552
13553 // packages/dataviews/build-module/components/dataviews-filters/filters.mjs
13554 var import_jsx_runtime68 = __toESM(require_jsx_runtime(), 1);
13555 function Filters({ className }) {
13556 const { fields, view, onChangeView, openedFilter, setOpenedFilter } = (0, import_element32.useContext)(dataviews_context_default);
13557 const addFilterRef = (0, import_element32.useRef)(null);
13558 const filters = use_filters_default(fields, view);
13559 const addFilter = /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13560 add_filter_default,
13561 {
13562 filters,
13563 view,
13564 onChangeView,
13565 ref: addFilterRef,
13566 setOpenedFilter
13567 },
13568 "add-filter"
13569 );
13570 const visibleFilters = filters.filter((filter) => filter.isVisible);
13571 if (visibleFilters.length === 0) {
13572 return null;
13573 }
13574 const filterComponents = [
13575 ...visibleFilters.map((filter) => {
13576 return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13577 Filter,
13578 {
13579 filter,
13580 view,
13581 fields,
13582 onChangeView,
13583 addFilterRef,
13584 openedFilter
13585 },
13586 filter.field
13587 );
13588 }),
13589 addFilter
13590 ];
13591 filterComponents.push(
13592 /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13593 ResetFilter,
13594 {
13595 filters,
13596 view,
13597 onChangeView
13598 },
13599 "reset-filters"
13600 )
13601 );
13602 return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13603 Stack,
13604 {
13605 direction: "row",
13606 justify: "flex-start",
13607 gap: "sm",
13608 style: { width: "fit-content" },
13609 wrap: "wrap",
13610 className,
13611 children: filterComponents
13612 }
13613 );
13614 }
13615 var filters_default = (0, import_element32.memo)(Filters);
13616
13617 // packages/dataviews/build-module/components/dataviews-filters/toggle.mjs
13618 var import_element33 = __toESM(require_element(), 1);
13619 var import_components24 = __toESM(require_components(), 1);
13620 var import_i18n33 = __toESM(require_i18n(), 1);
13621 var import_jsx_runtime69 = __toESM(require_jsx_runtime(), 1);
13622 function FiltersToggle() {
13623 const {
13624 filters,
13625 view,
13626 onChangeView,
13627 setOpenedFilter,
13628 isShowingFilter,
13629 setIsShowingFilter
13630 } = (0, import_element33.useContext)(dataviews_context_default);
13631 const buttonRef = (0, import_element33.useRef)(null);
13632 const onChangeViewWithFilterVisibility = (0, import_element33.useCallback)(
13633 (_view) => {
13634 onChangeView(_view);
13635 setIsShowingFilter(true);
13636 },
13637 [onChangeView, setIsShowingFilter]
13638 );
13639 if (filters.length === 0) {
13640 return null;
13641 }
13642 const hasVisibleFilters = filters.some((filter) => filter.isVisible);
13643 const addFilterButtonProps = {
13644 label: (0, import_i18n33.__)("Add filter"),
13645 "aria-expanded": false,
13646 isPressed: false
13647 };
13648 const toggleFiltersButtonProps = {
13649 label: (0, import_i18n33._x)("Filter", "verb"),
13650 "aria-expanded": isShowingFilter,
13651 isPressed: isShowingFilter,
13652 onClick: () => {
13653 if (!isShowingFilter) {
13654 setOpenedFilter(null);
13655 }
13656 setIsShowingFilter(!isShowingFilter);
13657 }
13658 };
13659 const hasPrimaryOrLockedFilters = filters.some(
13660 (filter) => filter.isPrimary || filter.isLocked
13661 );
13662 const buttonComponent = /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
13663 import_components24.Button,
13664 {
13665 ref: buttonRef,
13666 className: "dataviews-filters__visibility-toggle",
13667 size: "compact",
13668 icon: funnel_default,
13669 disabled: hasPrimaryOrLockedFilters,
13670 accessibleWhenDisabled: true,
13671 ...hasVisibleFilters ? toggleFiltersButtonProps : addFilterButtonProps
13672 }
13673 );
13674 return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)("div", { className: "dataviews-filters__container-visibility-toggle", children: !hasVisibleFilters ? /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
13675 AddFilterMenu,
13676 {
13677 filters,
13678 view,
13679 onChangeView: onChangeViewWithFilterVisibility,
13680 setOpenedFilter,
13681 triggerProps: { render: buttonComponent }
13682 }
13683 ) : /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
13684 FilterVisibilityToggle,
13685 {
13686 buttonRef,
13687 filtersCount: view.filters?.length,
13688 children: buttonComponent
13689 }
13690 ) });
13691 }
13692 function FilterVisibilityToggle({
13693 buttonRef,
13694 filtersCount,
13695 children
13696 }) {
13697 (0, import_element33.useEffect)(
13698 () => () => {
13699 buttonRef.current?.focus();
13700 },
13701 [buttonRef]
13702 );
13703 return /* @__PURE__ */ (0, import_jsx_runtime69.jsxs)(import_jsx_runtime69.Fragment, { children: [
13704 children,
13705 !!filtersCount && /* @__PURE__ */ (0, import_jsx_runtime69.jsx)("span", { className: "dataviews-filters-toggle__count", children: filtersCount })
13706 ] });
13707 }
13708 var toggle_default = FiltersToggle;
13709
13710 // packages/dataviews/build-module/components/dataviews-filters/filters-toggled.mjs
13711 var import_element34 = __toESM(require_element(), 1);
13712 var import_jsx_runtime70 = __toESM(require_jsx_runtime(), 1);
13713 function FiltersToggled(props) {
13714 const { isShowingFilter } = (0, import_element34.useContext)(dataviews_context_default);
13715 if (!isShowingFilter) {
13716 return null;
13717 }
13718 return /* @__PURE__ */ (0, import_jsx_runtime70.jsx)(filters_default, { ...props });
13719 }
13720 var filters_toggled_default = FiltersToggled;
13721
13722 // packages/dataviews/build-module/components/dataviews-layout/index.mjs
13723 var import_element35 = __toESM(require_element(), 1);
13724 var import_components25 = __toESM(require_components(), 1);
13725 var import_i18n34 = __toESM(require_i18n(), 1);
13726 var import_jsx_runtime71 = __toESM(require_jsx_runtime(), 1);
13727 function DataViewsLayout({ className }) {
13728 const {
13729 actions = [],
13730 data,
13731 fields,
13732 getItemId,
13733 getItemLevel,
13734 hasInitiallyLoaded,
13735 isLoading,
13736 view,
13737 onChangeView,
13738 selection,
13739 onChangeSelection,
13740 setOpenedFilter,
13741 onClickItem,
13742 isItemClickable: isItemClickable2,
13743 renderItemLink,
13744 defaultLayouts,
13745 containerRef,
13746 empty = /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("p", { children: (0, import_i18n34.__)("No results") })
13747 } = (0, import_element35.useContext)(dataviews_context_default);
13748 const isDelayedInitialLoading = useDelayedLoading(!hasInitiallyLoaded, {
13749 delay: 200
13750 });
13751 if (!hasInitiallyLoaded) {
13752 if (!isDelayedInitialLoading) {
13753 return null;
13754 }
13755 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_components25.Spinner, {}) }) });
13756 }
13757 const ViewComponent = VIEW_LAYOUTS.find(
13758 (v2) => v2.type === view.type && defaultLayouts[v2.type]
13759 )?.component;
13760 return /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("div", { className: "dataviews-layout__container", ref: containerRef, children: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(
13761 ViewComponent,
13762 {
13763 className,
13764 actions,
13765 data,
13766 fields,
13767 getItemId,
13768 getItemLevel,
13769 isLoading,
13770 onChangeView,
13771 onChangeSelection,
13772 selection,
13773 setOpenedFilter,
13774 onClickItem,
13775 renderItemLink,
13776 isItemClickable: isItemClickable2,
13777 view,
13778 empty
13779 }
13780 ) });
13781 }
13782
13783 // packages/dataviews/build-module/components/dataviews-search/index.mjs
13784 var import_i18n35 = __toESM(require_i18n(), 1);
13785 var import_element36 = __toESM(require_element(), 1);
13786 var import_components26 = __toESM(require_components(), 1);
13787 var import_compose9 = __toESM(require_compose(), 1);
13788 var import_jsx_runtime72 = __toESM(require_jsx_runtime(), 1);
13789 var DataViewsSearch = (0, import_element36.memo)(function Search({ label }) {
13790 const { view, onChangeView } = (0, import_element36.useContext)(dataviews_context_default);
13791 const [search, setSearch, debouncedSearch] = (0, import_compose9.useDebouncedInput)(
13792 view.search
13793 );
13794 (0, import_element36.useEffect)(() => {
13795 if (view.search !== debouncedSearch) {
13796 setSearch(view.search ?? "");
13797 }
13798 }, [view.search, setSearch]);
13799 const onChangeViewRef = (0, import_element36.useRef)(onChangeView);
13800 const viewRef = (0, import_element36.useRef)(view);
13801 (0, import_element36.useEffect)(() => {
13802 onChangeViewRef.current = onChangeView;
13803 viewRef.current = view;
13804 }, [onChangeView, view]);
13805 (0, import_element36.useEffect)(() => {
13806 if (debouncedSearch !== viewRef.current?.search) {
13807 onChangeViewRef.current({
13808 ...viewRef.current,
13809 page: view.page ? 1 : void 0,
13810 startPosition: view.startPosition ? 1 : void 0,
13811 search: debouncedSearch
13812 });
13813 }
13814 }, [debouncedSearch]);
13815 const searchLabel = label || (0, import_i18n35.__)("Search");
13816 return /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
13817 import_components26.SearchControl,
13818 {
13819 className: "dataviews-search",
13820 onChange: setSearch,
13821 value: search,
13822 label: searchLabel,
13823 placeholder: searchLabel,
13824 size: "compact"
13825 }
13826 );
13827 });
13828 var dataviews_search_default = DataViewsSearch;
13829
13830 // packages/dataviews/build-module/components/dataviews-view-config/index.mjs
13831 var import_components27 = __toESM(require_components(), 1);
13832 var import_i18n36 = __toESM(require_i18n(), 1);
13833 var import_element37 = __toESM(require_element(), 1);
13834 var import_warning = __toESM(require_warning(), 1);
13835 var import_compose10 = __toESM(require_compose(), 1);
13836 var import_jsx_runtime73 = __toESM(require_jsx_runtime(), 1);
13837 var { Menu: Menu5 } = unlock(import_components27.privateApis);
13838 var DATAVIEWS_CONFIG_POPOVER_PROPS = {
13839 className: "dataviews-config__popover",
13840 placement: "bottom-end",
13841 offset: 9
13842 };
13843 function ViewTypeMenu() {
13844 const { view, onChangeView, defaultLayouts } = (0, import_element37.useContext)(dataviews_context_default);
13845 const availableLayouts = Object.keys(defaultLayouts);
13846 if (availableLayouts.length <= 1) {
13847 return null;
13848 }
13849 const activeView = VIEW_LAYOUTS.find((v2) => view.type === v2.type);
13850 return /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(Menu5, { children: [
13851 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
13852 Menu5.TriggerButton,
13853 {
13854 render: /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
13855 import_components27.Button,
13856 {
13857 size: "compact",
13858 icon: activeView?.icon,
13859 label: (0, import_i18n36.__)("Layout")
13860 }
13861 )
13862 }
13863 ),
13864 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(Menu5.Popover, { children: availableLayouts.map((layout) => {
13865 const config = VIEW_LAYOUTS.find(
13866 (v2) => v2.type === layout
13867 );
13868 if (!config) {
13869 return null;
13870 }
13871 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
13872 Menu5.RadioItem,
13873 {
13874 value: layout,
13875 name: "view-actions-available-view",
13876 checked: layout === view.type,
13877 hideOnClick: true,
13878 onChange: (e2) => {
13879 switch (e2.target.value) {
13880 case "list":
13881 case "grid":
13882 case "table":
13883 case "pickerGrid":
13884 case "pickerTable":
13885 case "activity":
13886 const viewWithoutLayout = { ...view };
13887 if ("layout" in viewWithoutLayout) {
13888 delete viewWithoutLayout.layout;
13889 }
13890 return onChangeView({
13891 ...viewWithoutLayout,
13892 type: e2.target.value,
13893 ...defaultLayouts[e2.target.value]
13894 });
13895 }
13896 (0, import_warning.default)("Invalid dataview");
13897 },
13898 children: /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(Menu5.ItemLabel, { children: config.label })
13899 },
13900 layout
13901 );
13902 }) })
13903 ] });
13904 }
13905 function SortFieldControl() {
13906 const { view, fields, onChangeView } = (0, import_element37.useContext)(dataviews_context_default);
13907 const orderOptions = (0, import_element37.useMemo)(() => {
13908 const sortableFields = fields.filter(
13909 (field) => field.enableSorting !== false
13910 );
13911 return sortableFields.map((field) => {
13912 return {
13913 label: field.label,
13914 value: field.id
13915 };
13916 });
13917 }, [fields]);
13918 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
13919 import_components27.SelectControl,
13920 {
13921 __next40pxDefaultSize: true,
13922 label: (0, import_i18n36.__)("Sort by"),
13923 value: view.sort?.field,
13924 options: orderOptions,
13925 onChange: (value) => {
13926 onChangeView({
13927 ...view,
13928 sort: {
13929 direction: view?.sort?.direction || "desc",
13930 field: value
13931 },
13932 showLevels: false
13933 });
13934 }
13935 }
13936 );
13937 }
13938 function SortDirectionControl() {
13939 const { view, fields, onChangeView } = (0, import_element37.useContext)(dataviews_context_default);
13940 const sortableFields = fields.filter(
13941 (field) => field.enableSorting !== false
13942 );
13943 if (sortableFields.length === 0) {
13944 return null;
13945 }
13946 let value = view.sort?.direction;
13947 if (!value && view.sort?.field) {
13948 value = "desc";
13949 }
13950 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
13951 import_components27.__experimentalToggleGroupControl,
13952 {
13953 className: "dataviews-view-config__sort-direction",
13954 __next40pxDefaultSize: true,
13955 isBlock: true,
13956 label: (0, import_i18n36.__)("Order"),
13957 value,
13958 onChange: (newDirection) => {
13959 if (newDirection === "asc" || newDirection === "desc") {
13960 onChangeView({
13961 ...view,
13962 sort: {
13963 direction: newDirection,
13964 field: view.sort?.field || // If there is no field assigned as the sorting field assign the first sortable field.
13965 fields.find(
13966 (field) => field.enableSorting !== false
13967 )?.id || ""
13968 },
13969 showLevels: false
13970 });
13971 return;
13972 }
13973 (0, import_warning.default)("Invalid direction");
13974 },
13975 children: SORTING_DIRECTIONS.map((direction) => {
13976 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
13977 import_components27.__experimentalToggleGroupControlOptionIcon,
13978 {
13979 value: direction,
13980 icon: sortIcons[direction],
13981 label: sortLabels[direction]
13982 },
13983 direction
13984 );
13985 })
13986 }
13987 );
13988 }
13989 function ItemsPerPageControl() {
13990 const { view, config, onChangeView } = (0, import_element37.useContext)(dataviews_context_default);
13991 const { infiniteScrollEnabled } = view;
13992 if (!config || !config.perPageSizes || config.perPageSizes.length < 2 || config.perPageSizes.length > 6 || infiniteScrollEnabled) {
13993 return null;
13994 }
13995 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
13996 import_components27.__experimentalToggleGroupControl,
13997 {
13998 __next40pxDefaultSize: true,
13999 isBlock: true,
14000 label: (0, import_i18n36.__)("Items per page"),
14001 value: view.perPage || 10,
14002 disabled: !view?.sort?.field,
14003 onChange: (newItemsPerPage) => {
14004 const newItemsPerPageNumber = typeof newItemsPerPage === "number" || newItemsPerPage === void 0 ? newItemsPerPage : parseInt(newItemsPerPage, 10);
14005 onChangeView({
14006 ...view,
14007 perPage: newItemsPerPageNumber,
14008 page: 1
14009 });
14010 },
14011 children: config.perPageSizes.map((value) => {
14012 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14013 import_components27.__experimentalToggleGroupControlOption,
14014 {
14015 value,
14016 label: value.toString()
14017 },
14018 value
14019 );
14020 })
14021 }
14022 );
14023 }
14024 function ResetViewButton() {
14025 const { onReset } = (0, import_element37.useContext)(dataviews_context_default);
14026 if (onReset === void 0) {
14027 return null;
14028 }
14029 const isDisabled = onReset === false;
14030 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14031 import_components27.Button,
14032 {
14033 variant: "tertiary",
14034 size: "compact",
14035 disabled: isDisabled,
14036 accessibleWhenDisabled: true,
14037 className: "dataviews-view-config__reset-button",
14038 onClick: () => {
14039 if (typeof onReset === "function") {
14040 onReset();
14041 }
14042 },
14043 children: (0, import_i18n36.__)("Reset view")
14044 }
14045 );
14046 }
14047 function DataviewsViewConfigDropdown() {
14048 const { view, onReset } = (0, import_element37.useContext)(dataviews_context_default);
14049 const popoverId = (0, import_compose10.useInstanceId)(
14050 _DataViewsViewConfig,
14051 "dataviews-view-config-dropdown"
14052 );
14053 const activeLayout = VIEW_LAYOUTS.find(
14054 (layout) => layout.type === view.type
14055 );
14056 const isModified = typeof onReset === "function";
14057 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14058 import_components27.Dropdown,
14059 {
14060 expandOnMobile: true,
14061 popoverProps: {
14062 ...DATAVIEWS_CONFIG_POPOVER_PROPS,
14063 id: popoverId
14064 },
14065 renderToggle: ({ onToggle, isOpen }) => {
14066 return /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)("div", { className: "dataviews-view-config__toggle-wrapper", children: [
14067 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14068 import_components27.Button,
14069 {
14070 size: "compact",
14071 icon: cog_default,
14072 label: (0, import_i18n36._x)(
14073 "View options",
14074 "View is used as a noun"
14075 ),
14076 onClick: onToggle,
14077 "aria-expanded": isOpen ? "true" : "false",
14078 "aria-controls": popoverId
14079 }
14080 ),
14081 isModified && /* @__PURE__ */ (0, import_jsx_runtime73.jsx)("span", { className: "dataviews-view-config__modified-indicator" })
14082 ] });
14083 },
14084 renderContent: () => /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14085 import_components27.__experimentalDropdownContentWrapper,
14086 {
14087 paddingSize: "medium",
14088 className: "dataviews-config__popover-content-wrapper",
14089 children: /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
14090 Stack,
14091 {
14092 direction: "column",
14093 className: "dataviews-view-config",
14094 gap: "xl",
14095 children: [
14096 /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
14097 Stack,
14098 {
14099 direction: "row",
14100 justify: "space-between",
14101 align: "center",
14102 className: "dataviews-view-config__header",
14103 children: [
14104 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14105 import_components27.__experimentalHeading,
14106 {
14107 level: 2,
14108 className: "dataviews-settings-section__title",
14109 children: (0, import_i18n36.__)("Appearance")
14110 }
14111 ),
14112 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(ResetViewButton, {})
14113 ]
14114 }
14115 ),
14116 /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(Stack, { direction: "column", gap: "lg", children: [
14117 /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
14118 Stack,
14119 {
14120 direction: "row",
14121 gap: "sm",
14122 className: "dataviews-view-config__sort-controls",
14123 children: [
14124 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(SortFieldControl, {}),
14125 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(SortDirectionControl, {})
14126 ]
14127 }
14128 ),
14129 !!activeLayout?.viewConfigOptions && /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(activeLayout.viewConfigOptions, {}),
14130 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(ItemsPerPageControl, {}),
14131 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(PropertiesSection, {})
14132 ] })
14133 ]
14134 }
14135 )
14136 }
14137 )
14138 }
14139 );
14140 }
14141 function _DataViewsViewConfig() {
14142 return /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(import_jsx_runtime73.Fragment, { children: [
14143 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(ViewTypeMenu, {}),
14144 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(DataviewsViewConfigDropdown, {})
14145 ] });
14146 }
14147 var DataViewsViewConfig = (0, import_element37.memo)(_DataViewsViewConfig);
14148 var dataviews_view_config_default = DataViewsViewConfig;
14149
14150 // packages/dataviews/build-module/components/dataform-controls/checkbox.mjs
14151 var import_components28 = __toESM(require_components(), 1);
14152 var import_element38 = __toESM(require_element(), 1);
14153
14154 // packages/dataviews/build-module/components/dataform-controls/utils/get-custom-validity.mjs
14155 function getCustomValidity(isValid2, validity) {
14156 let customValidity;
14157 if (isValid2?.required && validity?.required) {
14158 customValidity = validity?.required?.message ? validity.required : void 0;
14159 } else if (isValid2?.pattern && validity?.pattern) {
14160 customValidity = validity.pattern;
14161 } else if (isValid2?.min && validity?.min) {
14162 customValidity = validity.min;
14163 } else if (isValid2?.max && validity?.max) {
14164 customValidity = validity.max;
14165 } else if (isValid2?.minLength && validity?.minLength) {
14166 customValidity = validity.minLength;
14167 } else if (isValid2?.maxLength && validity?.maxLength) {
14168 customValidity = validity.maxLength;
14169 } else if (isValid2?.elements && validity?.elements) {
14170 customValidity = validity.elements;
14171 } else if (validity?.custom) {
14172 customValidity = validity.custom;
14173 }
14174 return customValidity;
14175 }
14176
14177 // packages/dataviews/build-module/components/dataform-controls/checkbox.mjs
14178 var import_jsx_runtime74 = __toESM(require_jsx_runtime(), 1);
14179 var { ValidatedCheckboxControl } = unlock(import_components28.privateApis);
14180 function Checkbox({
14181 field,
14182 onChange,
14183 data,
14184 hideLabelFromVision,
14185 markWhenOptional,
14186 validity
14187 }) {
14188 const { getValue, setValue, label, description, isValid: isValid2 } = field;
14189 const onChangeControl = (0, import_element38.useCallback)(() => {
14190 onChange(
14191 setValue({ item: data, value: !getValue({ item: data }) })
14192 );
14193 }, [data, getValue, onChange, setValue]);
14194 return /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(
14195 ValidatedCheckboxControl,
14196 {
14197 required: !!field.isValid?.required,
14198 markWhenOptional,
14199 customValidity: getCustomValidity(isValid2, validity),
14200 hidden: hideLabelFromVision,
14201 label,
14202 help: description,
14203 checked: getValue({ item: data }),
14204 onChange: onChangeControl
14205 }
14206 );
14207 }
14208
14209 // packages/dataviews/build-module/components/dataform-controls/combobox.mjs
14210 var import_components29 = __toESM(require_components(), 1);
14211 var import_element39 = __toESM(require_element(), 1);
14212 var import_jsx_runtime75 = __toESM(require_jsx_runtime(), 1);
14213 var { ValidatedComboboxControl } = unlock(import_components29.privateApis);
14214 function Combobox3({
14215 data,
14216 field,
14217 onChange,
14218 hideLabelFromVision,
14219 validity
14220 }) {
14221 const { label, description, placeholder, getValue, setValue, isValid: isValid2 } = field;
14222 const value = getValue({ item: data }) ?? "";
14223 const onChangeControl = (0, import_element39.useCallback)(
14224 (newValue) => onChange(setValue({ item: data, value: newValue ?? "" })),
14225 [data, onChange, setValue]
14226 );
14227 const { elements, isLoading } = useElements({
14228 elements: field.elements,
14229 getElements: field.getElements
14230 });
14231 if (isLoading) {
14232 return /* @__PURE__ */ (0, import_jsx_runtime75.jsx)(import_components29.Spinner, {});
14233 }
14234 return /* @__PURE__ */ (0, import_jsx_runtime75.jsx)(
14235 ValidatedComboboxControl,
14236 {
14237 required: !!field.isValid?.required,
14238 customValidity: getCustomValidity(isValid2, validity),
14239 label,
14240 value,
14241 help: description,
14242 placeholder,
14243 options: elements,
14244 onChange: onChangeControl,
14245 hideLabelFromVision,
14246 allowReset: true,
14247 expandOnFocus: true
14248 }
14249 );
14250 }
14251
14252 // packages/dataviews/build-module/components/dataform-controls/datetime.mjs
14253 var import_components31 = __toESM(require_components(), 1);
14254 var import_element41 = __toESM(require_element(), 1);
14255 var import_i18n38 = __toESM(require_i18n(), 1);
14256 var import_date3 = __toESM(require_date(), 1);
14257
14258 // packages/dataviews/build-module/components/dataform-controls/utils/relative-date-control.mjs
14259 var import_components30 = __toESM(require_components(), 1);
14260 var import_element40 = __toESM(require_element(), 1);
14261 var import_i18n37 = __toESM(require_i18n(), 1);
14262 var import_jsx_runtime76 = __toESM(require_jsx_runtime(), 1);
14263 var TIME_UNITS_OPTIONS = {
14264 [OPERATOR_IN_THE_PAST]: [
14265 { value: "days", label: (0, import_i18n37.__)("Days") },
14266 { value: "weeks", label: (0, import_i18n37.__)("Weeks") },
14267 { value: "months", label: (0, import_i18n37.__)("Months") },
14268 { value: "years", label: (0, import_i18n37.__)("Years") }
14269 ],
14270 [OPERATOR_OVER]: [
14271 { value: "days", label: (0, import_i18n37.__)("Days ago") },
14272 { value: "weeks", label: (0, import_i18n37.__)("Weeks ago") },
14273 { value: "months", label: (0, import_i18n37.__)("Months ago") },
14274 { value: "years", label: (0, import_i18n37.__)("Years ago") }
14275 ]
14276 };
14277 function RelativeDateControl({
14278 className,
14279 data,
14280 field,
14281 onChange,
14282 hideLabelFromVision,
14283 operator
14284 }) {
14285 const options = TIME_UNITS_OPTIONS[operator === OPERATOR_IN_THE_PAST ? "inThePast" : "over"];
14286 const { id, label, description, getValue, setValue } = field;
14287 const fieldValue = getValue({ item: data });
14288 const { value: relValue = "", unit = options[0].value } = fieldValue && typeof fieldValue === "object" ? fieldValue : {};
14289 const onChangeValue = (0, import_element40.useCallback)(
14290 (newValue) => onChange(
14291 setValue({
14292 item: data,
14293 value: { value: Number(newValue), unit }
14294 })
14295 ),
14296 [onChange, setValue, data, unit]
14297 );
14298 const onChangeUnit = (0, import_element40.useCallback)(
14299 (newUnit) => onChange(
14300 setValue({
14301 item: data,
14302 value: { value: relValue, unit: newUnit }
14303 })
14304 ),
14305 [onChange, setValue, data, relValue]
14306 );
14307 return /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14308 import_components30.BaseControl,
14309 {
14310 id,
14311 className: clsx_default(className, "dataviews-controls__relative-date"),
14312 label,
14313 hideLabelFromVision,
14314 help: description,
14315 children: /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)(Stack, { direction: "row", gap: "sm", children: [
14316 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14317 import_components30.__experimentalNumberControl,
14318 {
14319 __next40pxDefaultSize: true,
14320 className: "dataviews-controls__relative-date-number",
14321 spinControls: "none",
14322 min: 1,
14323 step: 1,
14324 value: relValue,
14325 onChange: onChangeValue
14326 }
14327 ),
14328 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14329 import_components30.SelectControl,
14330 {
14331 className: "dataviews-controls__relative-date-unit",
14332 __next40pxDefaultSize: true,
14333 label: (0, import_i18n37.__)("Unit"),
14334 value: unit,
14335 options,
14336 onChange: onChangeUnit,
14337 hideLabelFromVision: true
14338 }
14339 )
14340 ] })
14341 }
14342 );
14343 }
14344
14345 // packages/dataviews/build-module/field-types/utils/parse-date-time.mjs
14346 var import_date2 = __toESM(require_date(), 1);
14347 function parseDateTime(dateTimeString) {
14348 if (!dateTimeString) {
14349 return null;
14350 }
14351 const parsed = (0, import_date2.getDate)(dateTimeString);
14352 return parsed && isValid(parsed) ? parsed : null;
14353 }
14354
14355 // packages/dataviews/build-module/components/dataform-controls/datetime.mjs
14356 var import_jsx_runtime77 = __toESM(require_jsx_runtime(), 1);
14357 var { DateCalendar, ValidatedInputControl } = unlock(import_components31.privateApis);
14358 var formatDateTime = (value) => {
14359 if (!value) {
14360 return "";
14361 }
14362 return (0, import_date3.dateI18n)("Y-m-d\\TH:i", (0, import_date3.getDate)(value));
14363 };
14364 function CalendarDateTimeControl({
14365 data,
14366 field,
14367 onChange,
14368 hideLabelFromVision,
14369 markWhenOptional,
14370 validity,
14371 config
14372 }) {
14373 const { compact } = config || {};
14374 const { id, label, description, setValue, getValue, isValid: isValid2 } = field;
14375 const fieldValue = getValue({ item: data });
14376 const value = typeof fieldValue === "string" ? fieldValue : void 0;
14377 const [calendarMonth, setCalendarMonth] = (0, import_element41.useState)(() => {
14378 const parsedDate = parseDateTime(value);
14379 return parsedDate || /* @__PURE__ */ new Date();
14380 });
14381 const inputControlRef = (0, import_element41.useRef)(null);
14382 const validationTimeoutRef = (0, import_element41.useRef)(void 0);
14383 const previousFocusRef = (0, import_element41.useRef)(null);
14384 const onChangeCallback = (0, import_element41.useCallback)(
14385 (newValue) => onChange(setValue({ item: data, value: newValue })),
14386 [data, onChange, setValue]
14387 );
14388 (0, import_element41.useEffect)(() => {
14389 return () => {
14390 if (validationTimeoutRef.current) {
14391 clearTimeout(validationTimeoutRef.current);
14392 }
14393 };
14394 }, []);
14395 const onSelectDate = (0, import_element41.useCallback)(
14396 (newDate) => {
14397 let dateTimeValue;
14398 if (newDate) {
14399 const wpDate = (0, import_date3.dateI18n)("Y-m-d", newDate);
14400 let wpTime;
14401 if (value) {
14402 wpTime = (0, import_date3.dateI18n)("H:i", (0, import_date3.getDate)(value));
14403 } else {
14404 wpTime = (0, import_date3.dateI18n)("H:i", newDate);
14405 }
14406 const finalDateTime = (0, import_date3.getDate)(`${wpDate}T${wpTime}`);
14407 dateTimeValue = finalDateTime.toISOString();
14408 onChangeCallback(dateTimeValue);
14409 if (validationTimeoutRef.current) {
14410 clearTimeout(validationTimeoutRef.current);
14411 }
14412 } else {
14413 onChangeCallback(void 0);
14414 }
14415 previousFocusRef.current = inputControlRef.current && inputControlRef.current.ownerDocument.activeElement;
14416 validationTimeoutRef.current = setTimeout(() => {
14417 if (inputControlRef.current) {
14418 inputControlRef.current.focus();
14419 inputControlRef.current.blur();
14420 onChangeCallback(dateTimeValue);
14421 if (previousFocusRef.current && previousFocusRef.current instanceof HTMLElement) {
14422 previousFocusRef.current.focus();
14423 }
14424 }
14425 }, 0);
14426 },
14427 [onChangeCallback, value]
14428 );
14429 const handleManualDateTimeChange = (0, import_element41.useCallback)(
14430 (newValue) => {
14431 if (newValue) {
14432 const dateTime = (0, import_date3.getDate)(newValue);
14433 onChangeCallback(dateTime.toISOString());
14434 const parsedDate = parseDateTime(dateTime.toISOString());
14435 if (parsedDate) {
14436 setCalendarMonth(parsedDate);
14437 }
14438 } else {
14439 onChangeCallback(void 0);
14440 }
14441 },
14442 [onChangeCallback]
14443 );
14444 const { format: fieldFormat } = field;
14445 const weekStartsOn = fieldFormat.weekStartsOn ?? (0, import_date3.getSettings)().l10n.startOfWeek;
14446 const {
14447 timezone: { string: timezoneString }
14448 } = (0, import_date3.getSettings)();
14449 let displayLabel = label;
14450 if (isValid2?.required && !markWhenOptional && !hideLabelFromVision) {
14451 displayLabel = `${label} (${(0, import_i18n38.__)("Required")})`;
14452 } else if (!isValid2?.required && markWhenOptional && !hideLabelFromVision) {
14453 displayLabel = `${label} (${(0, import_i18n38.__)("Optional")})`;
14454 }
14455 return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14456 import_components31.BaseControl,
14457 {
14458 id,
14459 label: displayLabel,
14460 help: description,
14461 hideLabelFromVision,
14462 children: /* @__PURE__ */ (0, import_jsx_runtime77.jsxs)(Stack, { direction: "column", gap: "lg", children: [
14463 /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14464 ValidatedInputControl,
14465 {
14466 ref: inputControlRef,
14467 __next40pxDefaultSize: true,
14468 required: !!isValid2?.required,
14469 customValidity: getCustomValidity(isValid2, validity),
14470 type: "datetime-local",
14471 label: (0, import_i18n38.__)("Date time"),
14472 hideLabelFromVision: true,
14473 value: formatDateTime(value),
14474 onChange: handleManualDateTimeChange
14475 }
14476 ),
14477 !compact && /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14478 DateCalendar,
14479 {
14480 style: { width: "100%" },
14481 selected: value ? parseDateTime(value) || void 0 : void 0,
14482 onSelect: onSelectDate,
14483 month: calendarMonth,
14484 onMonthChange: setCalendarMonth,
14485 timeZone: timezoneString || void 0,
14486 weekStartsOn
14487 }
14488 )
14489 ] })
14490 }
14491 );
14492 }
14493 function DateTime({
14494 data,
14495 field,
14496 onChange,
14497 hideLabelFromVision,
14498 markWhenOptional,
14499 operator,
14500 validity,
14501 config
14502 }) {
14503 if (operator === OPERATOR_IN_THE_PAST || operator === OPERATOR_OVER) {
14504 return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14505 RelativeDateControl,
14506 {
14507 className: "dataviews-controls__datetime",
14508 data,
14509 field,
14510 onChange,
14511 hideLabelFromVision,
14512 operator
14513 }
14514 );
14515 }
14516 return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14517 CalendarDateTimeControl,
14518 {
14519 data,
14520 field,
14521 onChange,
14522 hideLabelFromVision,
14523 markWhenOptional,
14524 validity,
14525 config
14526 }
14527 );
14528 }
14529
14530 // packages/dataviews/build-module/components/dataform-controls/date.mjs
14531 var import_components32 = __toESM(require_components(), 1);
14532 var import_element42 = __toESM(require_element(), 1);
14533 var import_i18n39 = __toESM(require_i18n(), 1);
14534 var import_date4 = __toESM(require_date(), 1);
14535 var import_jsx_runtime78 = __toESM(require_jsx_runtime(), 1);
14536 var { DateCalendar: DateCalendar2, DateRangeCalendar } = unlock(import_components32.privateApis);
14537 var DATE_PRESETS = [
14538 {
14539 id: "today",
14540 label: (0, import_i18n39.__)("Today"),
14541 getValue: () => (0, import_date4.getDate)(null)
14542 },
14543 {
14544 id: "yesterday",
14545 label: (0, import_i18n39.__)("Yesterday"),
14546 getValue: () => {
14547 const today = (0, import_date4.getDate)(null);
14548 return subDays(today, 1);
14549 }
14550 },
14551 {
14552 id: "past-week",
14553 label: (0, import_i18n39.__)("Past week"),
14554 getValue: () => {
14555 const today = (0, import_date4.getDate)(null);
14556 return subDays(today, 7);
14557 }
14558 },
14559 {
14560 id: "past-month",
14561 label: (0, import_i18n39.__)("Past month"),
14562 getValue: () => {
14563 const today = (0, import_date4.getDate)(null);
14564 return subMonths(today, 1);
14565 }
14566 }
14567 ];
14568 var DATE_RANGE_PRESETS = [
14569 {
14570 id: "last-7-days",
14571 label: (0, import_i18n39.__)("Last 7 days"),
14572 getValue: () => {
14573 const today = (0, import_date4.getDate)(null);
14574 return [subDays(today, 7), today];
14575 }
14576 },
14577 {
14578 id: "last-30-days",
14579 label: (0, import_i18n39.__)("Last 30 days"),
14580 getValue: () => {
14581 const today = (0, import_date4.getDate)(null);
14582 return [subDays(today, 30), today];
14583 }
14584 },
14585 {
14586 id: "month-to-date",
14587 label: (0, import_i18n39.__)("Month to date"),
14588 getValue: () => {
14589 const today = (0, import_date4.getDate)(null);
14590 return [startOfMonth(today), today];
14591 }
14592 },
14593 {
14594 id: "last-year",
14595 label: (0, import_i18n39.__)("Last year"),
14596 getValue: () => {
14597 const today = (0, import_date4.getDate)(null);
14598 return [subYears(today, 1), today];
14599 }
14600 },
14601 {
14602 id: "year-to-date",
14603 label: (0, import_i18n39.__)("Year to date"),
14604 getValue: () => {
14605 const today = (0, import_date4.getDate)(null);
14606 return [startOfYear(today), today];
14607 }
14608 }
14609 ];
14610 var parseDate = (dateString) => {
14611 if (!dateString) {
14612 return null;
14613 }
14614 const parsed = (0, import_date4.getDate)(dateString);
14615 return parsed && isValid(parsed) ? parsed : null;
14616 };
14617 var formatDate = (date) => {
14618 if (!date) {
14619 return "";
14620 }
14621 return typeof date === "string" ? date : format(date, "yyyy-MM-dd");
14622 };
14623 function ValidatedDateControl({
14624 field,
14625 validity,
14626 inputRefs,
14627 isTouched,
14628 setIsTouched,
14629 children
14630 }) {
14631 const { isValid: isValid2 } = field;
14632 const [customValidity, setCustomValidity] = (0, import_element42.useState)(void 0);
14633 const validateRefs = (0, import_element42.useCallback)(() => {
14634 const refs = Array.isArray(inputRefs) ? inputRefs : [inputRefs];
14635 for (const ref of refs) {
14636 const input = ref.current;
14637 if (input && !input.validity.valid) {
14638 setCustomValidity({
14639 type: "invalid",
14640 message: input.validationMessage
14641 });
14642 return;
14643 }
14644 }
14645 setCustomValidity(void 0);
14646 }, [inputRefs]);
14647 (0, import_element42.useEffect)(() => {
14648 const refs = Array.isArray(inputRefs) ? inputRefs : [inputRefs];
14649 const result = validity ? getCustomValidity(isValid2, validity) : void 0;
14650 for (const ref of refs) {
14651 const input = ref.current;
14652 if (input) {
14653 input.setCustomValidity(
14654 result?.type === "invalid" && result.message ? result.message : ""
14655 );
14656 }
14657 }
14658 }, [inputRefs, isValid2, validity]);
14659 (0, import_element42.useEffect)(() => {
14660 const refs = Array.isArray(inputRefs) ? inputRefs : [inputRefs];
14661 const handleInvalid = (event) => {
14662 event.preventDefault();
14663 setIsTouched(true);
14664 };
14665 for (const ref of refs) {
14666 ref.current?.addEventListener("invalid", handleInvalid);
14667 }
14668 return () => {
14669 for (const ref of refs) {
14670 ref.current?.removeEventListener("invalid", handleInvalid);
14671 }
14672 };
14673 }, [inputRefs, setIsTouched]);
14674 (0, import_element42.useEffect)(() => {
14675 if (!isTouched) {
14676 return;
14677 }
14678 const result = validity ? getCustomValidity(isValid2, validity) : void 0;
14679 if (result) {
14680 setCustomValidity(result);
14681 } else {
14682 validateRefs();
14683 }
14684 }, [isTouched, isValid2, validity, validateRefs]);
14685 const onBlur = (event) => {
14686 if (isTouched) {
14687 return;
14688 }
14689 if (!event.relatedTarget || !event.currentTarget.contains(event.relatedTarget)) {
14690 setIsTouched(true);
14691 }
14692 };
14693 return /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)("div", { onBlur, children: [
14694 children,
14695 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)("div", { "aria-live": "polite", children: customValidity && /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
14696 "p",
14697 {
14698 className: clsx_default(
14699 "components-validated-control__indicator",
14700 customValidity.type === "invalid" ? "is-invalid" : void 0
14701 ),
14702 children: [
14703 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14704 import_components32.Icon,
14705 {
14706 className: "components-validated-control__indicator-icon",
14707 icon: error_default,
14708 size: 16,
14709 fill: "currentColor"
14710 }
14711 ),
14712 customValidity.message
14713 ]
14714 }
14715 ) })
14716 ] });
14717 }
14718 function CalendarDateControl({
14719 data,
14720 field,
14721 onChange,
14722 hideLabelFromVision,
14723 markWhenOptional,
14724 validity
14725 }) {
14726 const {
14727 id,
14728 label,
14729 description,
14730 setValue,
14731 getValue,
14732 isValid: isValid2,
14733 format: fieldFormat
14734 } = field;
14735 const [selectedPresetId, setSelectedPresetId] = (0, import_element42.useState)(
14736 null
14737 );
14738 const weekStartsOn = fieldFormat.weekStartsOn ?? (0, import_date4.getSettings)().l10n.startOfWeek;
14739 const fieldValue = getValue({ item: data });
14740 const value = typeof fieldValue === "string" ? fieldValue : void 0;
14741 const [calendarMonth, setCalendarMonth] = (0, import_element42.useState)(() => {
14742 const parsedDate = parseDate(value);
14743 return parsedDate || /* @__PURE__ */ new Date();
14744 });
14745 const [isTouched, setIsTouched] = (0, import_element42.useState)(false);
14746 const validityTargetRef = (0, import_element42.useRef)(null);
14747 const onChangeCallback = (0, import_element42.useCallback)(
14748 (newValue) => onChange(setValue({ item: data, value: newValue })),
14749 [data, onChange, setValue]
14750 );
14751 const onSelectDate = (0, import_element42.useCallback)(
14752 (newDate) => {
14753 const dateValue = newDate ? format(newDate, "yyyy-MM-dd") : void 0;
14754 onChangeCallback(dateValue);
14755 setSelectedPresetId(null);
14756 setIsTouched(true);
14757 },
14758 [onChangeCallback]
14759 );
14760 const handlePresetClick = (0, import_element42.useCallback)(
14761 (preset) => {
14762 const presetDate = preset.getValue();
14763 const dateValue = formatDate(presetDate);
14764 setCalendarMonth(presetDate);
14765 onChangeCallback(dateValue);
14766 setSelectedPresetId(preset.id);
14767 setIsTouched(true);
14768 },
14769 [onChangeCallback]
14770 );
14771 const handleManualDateChange = (0, import_element42.useCallback)(
14772 (newValue) => {
14773 onChangeCallback(newValue);
14774 if (newValue) {
14775 const parsedDate = parseDate(newValue);
14776 if (parsedDate) {
14777 setCalendarMonth(parsedDate);
14778 }
14779 }
14780 setSelectedPresetId(null);
14781 setIsTouched(true);
14782 },
14783 [onChangeCallback]
14784 );
14785 const {
14786 timezone: { string: timezoneString }
14787 } = (0, import_date4.getSettings)();
14788 let displayLabel = label;
14789 if (isValid2?.required && !markWhenOptional) {
14790 displayLabel = `${label} (${(0, import_i18n39.__)("Required")})`;
14791 } else if (!isValid2?.required && markWhenOptional) {
14792 displayLabel = `${label} (${(0, import_i18n39.__)("Optional")})`;
14793 }
14794 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14795 ValidatedDateControl,
14796 {
14797 field,
14798 validity,
14799 inputRefs: validityTargetRef,
14800 isTouched,
14801 setIsTouched,
14802 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14803 import_components32.BaseControl,
14804 {
14805 id,
14806 className: "dataviews-controls__date",
14807 label: displayLabel,
14808 help: description,
14809 hideLabelFromVision,
14810 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(Stack, { direction: "column", gap: "lg", children: [
14811 /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
14812 Stack,
14813 {
14814 direction: "row",
14815 gap: "sm",
14816 wrap: "wrap",
14817 justify: "flex-start",
14818 children: [
14819 DATE_PRESETS.map((preset) => {
14820 const isSelected2 = selectedPresetId === preset.id;
14821 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14822 import_components32.Button,
14823 {
14824 className: "dataviews-controls__date-preset",
14825 variant: "tertiary",
14826 isPressed: isSelected2,
14827 size: "small",
14828 onClick: () => handlePresetClick(preset),
14829 children: preset.label
14830 },
14831 preset.id
14832 );
14833 }),
14834 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14835 import_components32.Button,
14836 {
14837 className: "dataviews-controls__date-preset",
14838 variant: "tertiary",
14839 isPressed: !selectedPresetId,
14840 size: "small",
14841 disabled: !!selectedPresetId,
14842 accessibleWhenDisabled: false,
14843 children: (0, import_i18n39.__)("Custom")
14844 }
14845 )
14846 ]
14847 }
14848 ),
14849 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14850 import_components32.__experimentalInputControl,
14851 {
14852 __next40pxDefaultSize: true,
14853 ref: validityTargetRef,
14854 type: "date",
14855 label: (0, import_i18n39.__)("Date"),
14856 hideLabelFromVision: true,
14857 value,
14858 onChange: handleManualDateChange,
14859 required: !!field.isValid?.required
14860 }
14861 ),
14862 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14863 DateCalendar2,
14864 {
14865 style: { width: "100%" },
14866 selected: value ? parseDate(value) || void 0 : void 0,
14867 onSelect: onSelectDate,
14868 month: calendarMonth,
14869 onMonthChange: setCalendarMonth,
14870 timeZone: timezoneString || void 0,
14871 weekStartsOn
14872 }
14873 )
14874 ] })
14875 }
14876 )
14877 }
14878 );
14879 }
14880 function CalendarDateRangeControl({
14881 data,
14882 field,
14883 onChange,
14884 hideLabelFromVision,
14885 markWhenOptional,
14886 validity
14887 }) {
14888 const {
14889 id,
14890 label,
14891 description,
14892 getValue,
14893 setValue,
14894 format: fieldFormat
14895 } = field;
14896 let value;
14897 const fieldValue = getValue({ item: data });
14898 if (Array.isArray(fieldValue) && fieldValue.length === 2 && fieldValue.every((date) => typeof date === "string")) {
14899 value = fieldValue;
14900 }
14901 const weekStartsOn = fieldFormat.weekStartsOn ?? (0, import_date4.getSettings)().l10n.startOfWeek;
14902 const onChangeCallback = (0, import_element42.useCallback)(
14903 (newValue) => {
14904 onChange(
14905 setValue({
14906 item: data,
14907 value: newValue
14908 })
14909 );
14910 },
14911 [data, onChange, setValue]
14912 );
14913 const [selectedPresetId, setSelectedPresetId] = (0, import_element42.useState)(
14914 null
14915 );
14916 const selectedRange = (0, import_element42.useMemo)(() => {
14917 if (!value) {
14918 return { from: void 0, to: void 0 };
14919 }
14920 const [from, to] = value;
14921 return {
14922 from: parseDate(from) || void 0,
14923 to: parseDate(to) || void 0
14924 };
14925 }, [value]);
14926 const [calendarMonth, setCalendarMonth] = (0, import_element42.useState)(() => {
14927 return selectedRange.from || /* @__PURE__ */ new Date();
14928 });
14929 const [isTouched, setIsTouched] = (0, import_element42.useState)(false);
14930 const fromInputRef = (0, import_element42.useRef)(null);
14931 const toInputRef = (0, import_element42.useRef)(null);
14932 const updateDateRange = (0, import_element42.useCallback)(
14933 (fromDate, toDate2) => {
14934 if (fromDate && toDate2) {
14935 onChangeCallback([
14936 formatDate(fromDate),
14937 formatDate(toDate2)
14938 ]);
14939 } else if (!fromDate && !toDate2) {
14940 onChangeCallback(void 0);
14941 }
14942 },
14943 [onChangeCallback]
14944 );
14945 const onSelectCalendarRange = (0, import_element42.useCallback)(
14946 (newRange) => {
14947 updateDateRange(newRange?.from, newRange?.to);
14948 setSelectedPresetId(null);
14949 setIsTouched(true);
14950 },
14951 [updateDateRange]
14952 );
14953 const handlePresetClick = (0, import_element42.useCallback)(
14954 (preset) => {
14955 const [startDate, endDate] = preset.getValue();
14956 setCalendarMonth(startDate);
14957 updateDateRange(startDate, endDate);
14958 setSelectedPresetId(preset.id);
14959 setIsTouched(true);
14960 },
14961 [updateDateRange]
14962 );
14963 const handleManualDateChange = (0, import_element42.useCallback)(
14964 (fromOrTo, newValue) => {
14965 const [currentFrom, currentTo] = value || [
14966 void 0,
14967 void 0
14968 ];
14969 const updatedFrom = fromOrTo === "from" ? newValue : currentFrom;
14970 const updatedTo = fromOrTo === "to" ? newValue : currentTo;
14971 updateDateRange(updatedFrom, updatedTo);
14972 if (newValue) {
14973 const parsedDate = parseDate(newValue);
14974 if (parsedDate) {
14975 setCalendarMonth(parsedDate);
14976 }
14977 }
14978 setSelectedPresetId(null);
14979 setIsTouched(true);
14980 },
14981 [value, updateDateRange]
14982 );
14983 const { timezone } = (0, import_date4.getSettings)();
14984 let displayLabel = label;
14985 if (field.isValid?.required && !markWhenOptional) {
14986 displayLabel = `${label} (${(0, import_i18n39.__)("Required")})`;
14987 } else if (!field.isValid?.required && markWhenOptional) {
14988 displayLabel = `${label} (${(0, import_i18n39.__)("Optional")})`;
14989 }
14990 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14991 ValidatedDateControl,
14992 {
14993 field,
14994 validity,
14995 inputRefs: [fromInputRef, toInputRef],
14996 isTouched,
14997 setIsTouched,
14998 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14999 import_components32.BaseControl,
15000 {
15001 id,
15002 className: "dataviews-controls__date",
15003 label: displayLabel,
15004 help: description,
15005 hideLabelFromVision,
15006 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(Stack, { direction: "column", gap: "lg", children: [
15007 /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
15008 Stack,
15009 {
15010 direction: "row",
15011 gap: "sm",
15012 wrap: "wrap",
15013 justify: "flex-start",
15014 children: [
15015 DATE_RANGE_PRESETS.map((preset) => {
15016 const isSelected2 = selectedPresetId === preset.id;
15017 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15018 import_components32.Button,
15019 {
15020 className: "dataviews-controls__date-preset",
15021 variant: "tertiary",
15022 isPressed: isSelected2,
15023 size: "small",
15024 onClick: () => handlePresetClick(preset),
15025 children: preset.label
15026 },
15027 preset.id
15028 );
15029 }),
15030 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15031 import_components32.Button,
15032 {
15033 className: "dataviews-controls__date-preset",
15034 variant: "tertiary",
15035 isPressed: !selectedPresetId,
15036 size: "small",
15037 accessibleWhenDisabled: false,
15038 disabled: !!selectedPresetId,
15039 children: (0, import_i18n39.__)("Custom")
15040 }
15041 )
15042 ]
15043 }
15044 ),
15045 /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
15046 Stack,
15047 {
15048 direction: "row",
15049 gap: "sm",
15050 justify: "space-between",
15051 className: "dataviews-controls__date-range-inputs",
15052 children: [
15053 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15054 import_components32.__experimentalInputControl,
15055 {
15056 __next40pxDefaultSize: true,
15057 ref: fromInputRef,
15058 type: "date",
15059 label: (0, import_i18n39.__)("From"),
15060 hideLabelFromVision: true,
15061 value: value?.[0],
15062 onChange: (newValue) => handleManualDateChange("from", newValue),
15063 required: !!field.isValid?.required
15064 }
15065 ),
15066 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15067 import_components32.__experimentalInputControl,
15068 {
15069 __next40pxDefaultSize: true,
15070 ref: toInputRef,
15071 type: "date",
15072 label: (0, import_i18n39.__)("To"),
15073 hideLabelFromVision: true,
15074 value: value?.[1],
15075 onChange: (newValue) => handleManualDateChange("to", newValue),
15076 required: !!field.isValid?.required
15077 }
15078 )
15079 ]
15080 }
15081 ),
15082 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15083 DateRangeCalendar,
15084 {
15085 style: { width: "100%" },
15086 selected: selectedRange,
15087 onSelect: onSelectCalendarRange,
15088 month: calendarMonth,
15089 onMonthChange: setCalendarMonth,
15090 timeZone: timezone.string || void 0,
15091 weekStartsOn
15092 }
15093 )
15094 ] })
15095 }
15096 )
15097 }
15098 );
15099 }
15100 function DateControl({
15101 data,
15102 field,
15103 onChange,
15104 hideLabelFromVision,
15105 markWhenOptional,
15106 operator,
15107 validity
15108 }) {
15109 if (operator === OPERATOR_IN_THE_PAST || operator === OPERATOR_OVER) {
15110 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15111 RelativeDateControl,
15112 {
15113 className: "dataviews-controls__date",
15114 data,
15115 field,
15116 onChange,
15117 hideLabelFromVision,
15118 operator
15119 }
15120 );
15121 }
15122 if (operator === OPERATOR_BETWEEN) {
15123 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15124 CalendarDateRangeControl,
15125 {
15126 data,
15127 field,
15128 onChange,
15129 hideLabelFromVision,
15130 markWhenOptional,
15131 validity
15132 }
15133 );
15134 }
15135 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15136 CalendarDateControl,
15137 {
15138 data,
15139 field,
15140 onChange,
15141 hideLabelFromVision,
15142 markWhenOptional,
15143 validity
15144 }
15145 );
15146 }
15147
15148 // packages/dataviews/build-module/components/dataform-controls/select.mjs
15149 var import_components33 = __toESM(require_components(), 1);
15150 var import_element43 = __toESM(require_element(), 1);
15151 var import_jsx_runtime79 = __toESM(require_jsx_runtime(), 1);
15152 var { ValidatedSelectControl } = unlock(import_components33.privateApis);
15153 function Select({
15154 data,
15155 field,
15156 onChange,
15157 hideLabelFromVision,
15158 markWhenOptional,
15159 validity
15160 }) {
15161 const { type, label, description, getValue, setValue, isValid: isValid2 } = field;
15162 const isMultiple = type === "array";
15163 const value = getValue({ item: data }) ?? (isMultiple ? [] : "");
15164 const onChangeControl = (0, import_element43.useCallback)(
15165 (newValue) => onChange(setValue({ item: data, value: newValue })),
15166 [data, onChange, setValue]
15167 );
15168 const { elements, isLoading } = useElements({
15169 elements: field.elements,
15170 getElements: field.getElements
15171 });
15172 if (isLoading) {
15173 return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(import_components33.Spinner, {});
15174 }
15175 return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
15176 ValidatedSelectControl,
15177 {
15178 required: !!field.isValid?.required,
15179 markWhenOptional,
15180 customValidity: getCustomValidity(isValid2, validity),
15181 label,
15182 value,
15183 help: description,
15184 options: elements,
15185 onChange: onChangeControl,
15186 __next40pxDefaultSize: true,
15187 hideLabelFromVision,
15188 multiple: isMultiple
15189 }
15190 );
15191 }
15192
15193 // packages/dataviews/build-module/components/dataform-controls/adaptive-select.mjs
15194 var import_jsx_runtime80 = __toESM(require_jsx_runtime(), 1);
15195 var ELEMENTS_THRESHOLD = 10;
15196 function AdaptiveSelect(props) {
15197 const { field } = props;
15198 const { elements } = useElements({
15199 elements: field.elements,
15200 getElements: field.getElements
15201 });
15202 if (elements.length >= ELEMENTS_THRESHOLD) {
15203 return /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(Combobox3, { ...props });
15204 }
15205 return /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(Select, { ...props });
15206 }
15207
15208 // packages/dataviews/build-module/components/dataform-controls/email.mjs
15209 var import_components35 = __toESM(require_components(), 1);
15210
15211 // packages/dataviews/build-module/components/dataform-controls/utils/validated-input.mjs
15212 var import_components34 = __toESM(require_components(), 1);
15213 var import_element44 = __toESM(require_element(), 1);
15214 var import_jsx_runtime81 = __toESM(require_jsx_runtime(), 1);
15215 var { ValidatedInputControl: ValidatedInputControl2 } = unlock(import_components34.privateApis);
15216 function ValidatedText({
15217 data,
15218 field,
15219 onChange,
15220 hideLabelFromVision,
15221 markWhenOptional,
15222 type,
15223 prefix,
15224 suffix,
15225 validity
15226 }) {
15227 const { label, placeholder, description, getValue, setValue, isValid: isValid2 } = field;
15228 const value = getValue({ item: data });
15229 const onChangeControl = (0, import_element44.useCallback)(
15230 (newValue) => onChange(
15231 setValue({
15232 item: data,
15233 value: newValue
15234 })
15235 ),
15236 [data, setValue, onChange]
15237 );
15238 return /* @__PURE__ */ (0, import_jsx_runtime81.jsx)(
15239 ValidatedInputControl2,
15240 {
15241 required: !!isValid2.required,
15242 markWhenOptional,
15243 customValidity: getCustomValidity(isValid2, validity),
15244 label,
15245 placeholder,
15246 value: value ?? "",
15247 help: description,
15248 onChange: onChangeControl,
15249 hideLabelFromVision,
15250 type,
15251 prefix,
15252 suffix,
15253 pattern: isValid2.pattern ? isValid2.pattern.constraint : void 0,
15254 minLength: isValid2.minLength ? isValid2.minLength.constraint : void 0,
15255 maxLength: isValid2.maxLength ? isValid2.maxLength.constraint : void 0,
15256 __next40pxDefaultSize: true
15257 }
15258 );
15259 }
15260
15261 // packages/dataviews/build-module/components/dataform-controls/email.mjs
15262 var import_jsx_runtime82 = __toESM(require_jsx_runtime(), 1);
15263 function Email({
15264 data,
15265 field,
15266 onChange,
15267 hideLabelFromVision,
15268 markWhenOptional,
15269 validity
15270 }) {
15271 return /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(
15272 ValidatedText,
15273 {
15274 ...{
15275 data,
15276 field,
15277 onChange,
15278 hideLabelFromVision,
15279 markWhenOptional,
15280 validity,
15281 type: "email",
15282 prefix: /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(import_components35.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(import_components35.Icon, { icon: envelope_default }) })
15283 }
15284 }
15285 );
15286 }
15287
15288 // packages/dataviews/build-module/components/dataform-controls/telephone.mjs
15289 var import_components36 = __toESM(require_components(), 1);
15290 var import_jsx_runtime83 = __toESM(require_jsx_runtime(), 1);
15291 function Telephone({
15292 data,
15293 field,
15294 onChange,
15295 hideLabelFromVision,
15296 markWhenOptional,
15297 validity
15298 }) {
15299 return /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(
15300 ValidatedText,
15301 {
15302 ...{
15303 data,
15304 field,
15305 onChange,
15306 hideLabelFromVision,
15307 markWhenOptional,
15308 validity,
15309 type: "tel",
15310 prefix: /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(import_components36.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(import_components36.Icon, { icon: mobile_default }) })
15311 }
15312 }
15313 );
15314 }
15315
15316 // packages/dataviews/build-module/components/dataform-controls/url.mjs
15317 var import_components37 = __toESM(require_components(), 1);
15318 var import_jsx_runtime84 = __toESM(require_jsx_runtime(), 1);
15319 function Url({
15320 data,
15321 field,
15322 onChange,
15323 hideLabelFromVision,
15324 markWhenOptional,
15325 validity
15326 }) {
15327 return /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(
15328 ValidatedText,
15329 {
15330 ...{
15331 data,
15332 field,
15333 onChange,
15334 hideLabelFromVision,
15335 markWhenOptional,
15336 validity,
15337 type: "url",
15338 prefix: /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(import_components37.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(import_components37.Icon, { icon: link_default }) })
15339 }
15340 }
15341 );
15342 }
15343
15344 // packages/dataviews/build-module/components/dataform-controls/utils/validated-number.mjs
15345 var import_components38 = __toESM(require_components(), 1);
15346 var import_element45 = __toESM(require_element(), 1);
15347 var import_i18n40 = __toESM(require_i18n(), 1);
15348 var import_jsx_runtime85 = __toESM(require_jsx_runtime(), 1);
15349 var { ValidatedNumberControl } = unlock(import_components38.privateApis);
15350 function toNumberOrEmpty(value) {
15351 if (value === "" || value === void 0) {
15352 return "";
15353 }
15354 const number = Number(value);
15355 return Number.isFinite(number) ? number : "";
15356 }
15357 function BetweenControls({
15358 value,
15359 onChange,
15360 hideLabelFromVision,
15361 step
15362 }) {
15363 const [min = "", max = ""] = value;
15364 const onChangeMin = (0, import_element45.useCallback)(
15365 (newValue) => onChange([toNumberOrEmpty(newValue), max]),
15366 [onChange, max]
15367 );
15368 const onChangeMax = (0, import_element45.useCallback)(
15369 (newValue) => onChange([min, toNumberOrEmpty(newValue)]),
15370 [onChange, min]
15371 );
15372 return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15373 import_components38.BaseControl,
15374 {
15375 help: (0, import_i18n40.__)("The max. value must be greater than the min. value."),
15376 children: /* @__PURE__ */ (0, import_jsx_runtime85.jsxs)(import_components38.Flex, { direction: "row", gap: 4, children: [
15377 /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15378 import_components38.__experimentalNumberControl,
15379 {
15380 label: (0, import_i18n40.__)("Min."),
15381 value: min,
15382 max: max ? Number(max) - step : void 0,
15383 onChange: onChangeMin,
15384 __next40pxDefaultSize: true,
15385 hideLabelFromVision,
15386 step
15387 }
15388 ),
15389 /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15390 import_components38.__experimentalNumberControl,
15391 {
15392 label: (0, import_i18n40.__)("Max."),
15393 value: max,
15394 min: min ? Number(min) + step : void 0,
15395 onChange: onChangeMax,
15396 __next40pxDefaultSize: true,
15397 hideLabelFromVision,
15398 step
15399 }
15400 )
15401 ] })
15402 }
15403 );
15404 }
15405 function ValidatedNumber({
15406 data,
15407 field,
15408 onChange,
15409 hideLabelFromVision,
15410 markWhenOptional,
15411 operator,
15412 validity
15413 }) {
15414 const decimals = field.format?.decimals ?? 0;
15415 const step = Math.pow(10, Math.abs(decimals) * -1);
15416 const { label, description, getValue, setValue, isValid: isValid2 } = field;
15417 const value = getValue({ item: data }) ?? "";
15418 const onChangeControl = (0, import_element45.useCallback)(
15419 (newValue) => {
15420 onChange(
15421 setValue({
15422 item: data,
15423 // Do not convert an empty string or undefined to a number,
15424 // otherwise there's a mismatch between the UI control (empty)
15425 // and the data relied by onChange (0).
15426 value: ["", void 0].includes(newValue) ? void 0 : Number(newValue)
15427 })
15428 );
15429 },
15430 [data, onChange, setValue]
15431 );
15432 const onChangeBetweenControls = (0, import_element45.useCallback)(
15433 (newValue) => {
15434 onChange(
15435 setValue({
15436 item: data,
15437 value: newValue
15438 })
15439 );
15440 },
15441 [data, onChange, setValue]
15442 );
15443 if (operator === OPERATOR_BETWEEN) {
15444 let valueBetween = ["", ""];
15445 if (Array.isArray(value) && value.length === 2 && value.every(
15446 (element) => typeof element === "number" || element === ""
15447 )) {
15448 valueBetween = value;
15449 }
15450 return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15451 BetweenControls,
15452 {
15453 value: valueBetween,
15454 onChange: onChangeBetweenControls,
15455 hideLabelFromVision,
15456 step
15457 }
15458 );
15459 }
15460 return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15461 ValidatedNumberControl,
15462 {
15463 required: !!isValid2.required,
15464 markWhenOptional,
15465 customValidity: getCustomValidity(isValid2, validity),
15466 label,
15467 help: description,
15468 value,
15469 onChange: onChangeControl,
15470 __next40pxDefaultSize: true,
15471 hideLabelFromVision,
15472 step,
15473 min: isValid2.min ? isValid2.min.constraint : void 0,
15474 max: isValid2.max ? isValid2.max.constraint : void 0
15475 }
15476 );
15477 }
15478
15479 // packages/dataviews/build-module/components/dataform-controls/integer.mjs
15480 var import_jsx_runtime86 = __toESM(require_jsx_runtime(), 1);
15481 function Integer(props) {
15482 return /* @__PURE__ */ (0, import_jsx_runtime86.jsx)(ValidatedNumber, { ...props });
15483 }
15484
15485 // packages/dataviews/build-module/components/dataform-controls/number.mjs
15486 var import_jsx_runtime87 = __toESM(require_jsx_runtime(), 1);
15487 function Number2(props) {
15488 return /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(ValidatedNumber, { ...props });
15489 }
15490
15491 // packages/dataviews/build-module/components/dataform-controls/radio.mjs
15492 var import_components39 = __toESM(require_components(), 1);
15493 var import_element46 = __toESM(require_element(), 1);
15494 var import_jsx_runtime88 = __toESM(require_jsx_runtime(), 1);
15495 var { ValidatedRadioControl } = unlock(import_components39.privateApis);
15496 function Radio({
15497 data,
15498 field,
15499 onChange,
15500 hideLabelFromVision,
15501 markWhenOptional,
15502 validity
15503 }) {
15504 const { label, description, getValue, setValue, isValid: isValid2 } = field;
15505 const { elements, isLoading } = useElements({
15506 elements: field.elements,
15507 getElements: field.getElements
15508 });
15509 const value = getValue({ item: data });
15510 const onChangeControl = (0, import_element46.useCallback)(
15511 (newValue) => onChange(setValue({ item: data, value: newValue })),
15512 [data, onChange, setValue]
15513 );
15514 if (isLoading) {
15515 return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(import_components39.Spinner, {});
15516 }
15517 return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(
15518 ValidatedRadioControl,
15519 {
15520 required: !!field.isValid?.required,
15521 markWhenOptional,
15522 customValidity: getCustomValidity(isValid2, validity),
15523 label,
15524 help: description,
15525 onChange: onChangeControl,
15526 options: elements,
15527 selected: value,
15528 hideLabelFromVision
15529 }
15530 );
15531 }
15532
15533 // packages/dataviews/build-module/components/dataform-controls/text.mjs
15534 var import_element47 = __toESM(require_element(), 1);
15535 var import_jsx_runtime89 = __toESM(require_jsx_runtime(), 1);
15536 function Text({
15537 data,
15538 field,
15539 onChange,
15540 hideLabelFromVision,
15541 markWhenOptional,
15542 config,
15543 validity
15544 }) {
15545 const { prefix, suffix } = config || {};
15546 return /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(
15547 ValidatedText,
15548 {
15549 ...{
15550 data,
15551 field,
15552 onChange,
15553 hideLabelFromVision,
15554 markWhenOptional,
15555 validity,
15556 prefix: prefix ? (0, import_element47.createElement)(prefix) : void 0,
15557 suffix: suffix ? (0, import_element47.createElement)(suffix) : void 0
15558 }
15559 }
15560 );
15561 }
15562
15563 // packages/dataviews/build-module/components/dataform-controls/toggle.mjs
15564 var import_components40 = __toESM(require_components(), 1);
15565 var import_element48 = __toESM(require_element(), 1);
15566 var import_jsx_runtime90 = __toESM(require_jsx_runtime(), 1);
15567 var { ValidatedToggleControl } = unlock(import_components40.privateApis);
15568 function Toggle({
15569 field,
15570 onChange,
15571 data,
15572 hideLabelFromVision,
15573 markWhenOptional,
15574 validity
15575 }) {
15576 const { label, description, getValue, setValue, isValid: isValid2 } = field;
15577 const onChangeControl = (0, import_element48.useCallback)(() => {
15578 onChange(
15579 setValue({ item: data, value: !getValue({ item: data }) })
15580 );
15581 }, [onChange, setValue, data, getValue]);
15582 return /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(
15583 ValidatedToggleControl,
15584 {
15585 required: !!isValid2.required,
15586 markWhenOptional,
15587 customValidity: getCustomValidity(isValid2, validity),
15588 hidden: hideLabelFromVision,
15589 label,
15590 help: description,
15591 checked: getValue({ item: data }),
15592 onChange: onChangeControl
15593 }
15594 );
15595 }
15596
15597 // packages/dataviews/build-module/components/dataform-controls/textarea.mjs
15598 var import_components41 = __toESM(require_components(), 1);
15599 var import_element49 = __toESM(require_element(), 1);
15600 var import_jsx_runtime91 = __toESM(require_jsx_runtime(), 1);
15601 var { ValidatedTextareaControl } = unlock(import_components41.privateApis);
15602 function Textarea({
15603 data,
15604 field,
15605 onChange,
15606 hideLabelFromVision,
15607 markWhenOptional,
15608 config,
15609 validity
15610 }) {
15611 const { rows = 4 } = config || {};
15612 const { label, placeholder, description, setValue, isValid: isValid2 } = field;
15613 const value = field.getValue({ item: data });
15614 const onChangeControl = (0, import_element49.useCallback)(
15615 (newValue) => onChange(setValue({ item: data, value: newValue })),
15616 [data, onChange, setValue]
15617 );
15618 return /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
15619 ValidatedTextareaControl,
15620 {
15621 required: !!isValid2.required,
15622 markWhenOptional,
15623 customValidity: getCustomValidity(isValid2, validity),
15624 label,
15625 placeholder,
15626 value: value ?? "",
15627 help: description,
15628 onChange: onChangeControl,
15629 rows,
15630 minLength: isValid2.minLength ? isValid2.minLength.constraint : void 0,
15631 maxLength: isValid2.maxLength ? isValid2.maxLength.constraint : void 0,
15632 __next40pxDefaultSize: true,
15633 hideLabelFromVision
15634 }
15635 );
15636 }
15637
15638 // packages/dataviews/build-module/components/dataform-controls/toggle-group.mjs
15639 var import_components42 = __toESM(require_components(), 1);
15640 var import_element50 = __toESM(require_element(), 1);
15641 var import_jsx_runtime92 = __toESM(require_jsx_runtime(), 1);
15642 var { ValidatedToggleGroupControl } = unlock(import_components42.privateApis);
15643 function ToggleGroup({
15644 data,
15645 field,
15646 onChange,
15647 hideLabelFromVision,
15648 markWhenOptional,
15649 validity
15650 }) {
15651 const { getValue, setValue, isValid: isValid2 } = field;
15652 const value = getValue({ item: data });
15653 const onChangeControl = (0, import_element50.useCallback)(
15654 (newValue) => onChange(setValue({ item: data, value: newValue })),
15655 [data, onChange, setValue]
15656 );
15657 const { elements, isLoading } = useElements({
15658 elements: field.elements,
15659 getElements: field.getElements
15660 });
15661 if (isLoading) {
15662 return /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(import_components42.Spinner, {});
15663 }
15664 if (elements.length === 0) {
15665 return null;
15666 }
15667 const selectedOption = elements.find((el) => el.value === value);
15668 return /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
15669 ValidatedToggleGroupControl,
15670 {
15671 required: !!field.isValid?.required,
15672 markWhenOptional,
15673 customValidity: getCustomValidity(isValid2, validity),
15674 __next40pxDefaultSize: true,
15675 isBlock: true,
15676 label: field.label,
15677 help: selectedOption?.description || field.description,
15678 onChange: onChangeControl,
15679 value,
15680 hideLabelFromVision,
15681 children: elements.map((el) => /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
15682 import_components42.__experimentalToggleGroupControlOption,
15683 {
15684 label: el.label,
15685 value: el.value
15686 },
15687 el.value
15688 ))
15689 }
15690 );
15691 }
15692
15693 // packages/dataviews/build-module/components/dataform-controls/array.mjs
15694 var import_components43 = __toESM(require_components(), 1);
15695 var import_element51 = __toESM(require_element(), 1);
15696 var import_jsx_runtime93 = __toESM(require_jsx_runtime(), 1);
15697 var { ValidatedFormTokenField } = unlock(import_components43.privateApis);
15698 function ArrayControl({
15699 data,
15700 field,
15701 onChange,
15702 hideLabelFromVision,
15703 markWhenOptional,
15704 validity
15705 }) {
15706 const { label, placeholder, getValue, setValue, isValid: isValid2 } = field;
15707 const value = getValue({ item: data });
15708 const { elements, isLoading } = useElements({
15709 elements: field.elements,
15710 getElements: field.getElements
15711 });
15712 const arrayValueAsElements = (0, import_element51.useMemo)(
15713 () => Array.isArray(value) ? value.map((token) => {
15714 const element = elements?.find(
15715 (suggestion) => suggestion.value === token
15716 );
15717 return element || { value: token, label: token };
15718 }) : [],
15719 [value, elements]
15720 );
15721 const onChangeControl = (0, import_element51.useCallback)(
15722 (tokens) => {
15723 const valueTokens = tokens.map((token) => {
15724 if (typeof token === "object" && "value" in token) {
15725 return token.value;
15726 }
15727 return token;
15728 });
15729 onChange(setValue({ item: data, value: valueTokens }));
15730 },
15731 [onChange, setValue, data]
15732 );
15733 if (isLoading) {
15734 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_components43.Spinner, {});
15735 }
15736 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
15737 ValidatedFormTokenField,
15738 {
15739 required: !!isValid2?.required,
15740 markWhenOptional,
15741 customValidity: getCustomValidity(isValid2, validity),
15742 label: hideLabelFromVision ? void 0 : label,
15743 value: arrayValueAsElements,
15744 onChange: onChangeControl,
15745 placeholder,
15746 suggestions: elements?.map((element) => element.value),
15747 __experimentalValidateInput: (token) => {
15748 if (field.isValid?.elements && elements) {
15749 return elements.some(
15750 (element) => element.value === token || element.label === token
15751 );
15752 }
15753 return true;
15754 },
15755 __experimentalExpandOnFocus: elements && elements.length > 0,
15756 __experimentalShowHowTo: !field.isValid?.elements,
15757 displayTransform: (token) => {
15758 if (typeof token === "object" && "label" in token) {
15759 return token.label;
15760 }
15761 if (typeof token === "string" && elements) {
15762 const element = elements.find(
15763 (el) => el.value === token
15764 );
15765 return element?.label || token;
15766 }
15767 return token;
15768 },
15769 __experimentalRenderItem: ({ item }) => {
15770 if (typeof item === "string" && elements) {
15771 const element = elements.find(
15772 (el) => el.value === item
15773 );
15774 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)("span", { children: element?.label || item });
15775 }
15776 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)("span", { children: item });
15777 }
15778 }
15779 );
15780 }
15781
15782 // node_modules/colord/index.mjs
15783 var r2 = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) };
15784 var t = function(r3) {
15785 return "string" == typeof r3 ? r3.length > 0 : "number" == typeof r3;
15786 };
15787 var n = function(r3, t2, n2) {
15788 return void 0 === t2 && (t2 = 0), void 0 === n2 && (n2 = Math.pow(10, t2)), Math.round(n2 * r3) / n2 + 0;
15789 };
15790 var e = function(r3, t2, n2) {
15791 return void 0 === t2 && (t2 = 0), void 0 === n2 && (n2 = 1), r3 > n2 ? n2 : r3 > t2 ? r3 : t2;
15792 };
15793 var u = function(r3) {
15794 return (r3 = isFinite(r3) ? r3 % 360 : 0) > 0 ? r3 : r3 + 360;
15795 };
15796 var a = function(r3) {
15797 return { r: e(r3.r, 0, 255), g: e(r3.g, 0, 255), b: e(r3.b, 0, 255), a: e(r3.a) };
15798 };
15799 var o = function(r3) {
15800 return { r: n(r3.r), g: n(r3.g), b: n(r3.b), a: n(r3.a, 3) };
15801 };
15802 var i = /^#([0-9a-f]{3,8})$/i;
15803 var s = function(r3) {
15804 var t2 = r3.toString(16);
15805 return t2.length < 2 ? "0" + t2 : t2;
15806 };
15807 var h = function(r3) {
15808 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;
15809 return { h: 60 * (i2 < 0 ? i2 + 6 : i2), s: a2 ? o2 / a2 * 100 : 0, v: a2 / 255 * 100, a: u2 };
15810 };
15811 var b = function(r3) {
15812 var t2 = r3.h, n2 = r3.s, e2 = r3.v, u2 = r3.a;
15813 t2 = t2 / 360 * 6, n2 /= 100, e2 /= 100;
15814 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;
15815 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 };
15816 };
15817 var g = function(r3) {
15818 return { h: u(r3.h), s: e(r3.s, 0, 100), l: e(r3.l, 0, 100), a: e(r3.a) };
15819 };
15820 var d = function(r3) {
15821 return { h: n(r3.h), s: n(r3.s), l: n(r3.l), a: n(r3.a, 3) };
15822 };
15823 var f = function(r3) {
15824 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 }));
15825 var t2, n2, e2;
15826 };
15827 var c = function(r3) {
15828 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 };
15829 var t2, n2, e2, u2;
15830 };
15831 var l = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15832 var p = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15833 var v = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15834 var m = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15835 var y = { string: [[function(r3) {
15836 var t2 = i.exec(r3);
15837 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;
15838 }, "hex"], [function(r3) {
15839 var t2 = v.exec(r3) || m.exec(r3);
15840 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;
15841 }, "rgb"], [function(t2) {
15842 var n2 = l.exec(t2) || p.exec(t2);
15843 if (!n2) return null;
15844 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) });
15845 return f(a2);
15846 }, "hsl"]], object: [[function(r3) {
15847 var n2 = r3.r, e2 = r3.g, u2 = r3.b, o2 = r3.a, i2 = void 0 === o2 ? 1 : o2;
15848 return t(n2) && t(e2) && t(u2) ? a({ r: Number(n2), g: Number(e2), b: Number(u2), a: Number(i2) }) : null;
15849 }, "rgb"], [function(r3) {
15850 var n2 = r3.h, e2 = r3.s, u2 = r3.l, a2 = r3.a, o2 = void 0 === a2 ? 1 : a2;
15851 if (!t(n2) || !t(e2) || !t(u2)) return null;
15852 var i2 = g({ h: Number(n2), s: Number(e2), l: Number(u2), a: Number(o2) });
15853 return f(i2);
15854 }, "hsl"], [function(r3) {
15855 var n2 = r3.h, a2 = r3.s, o2 = r3.v, i2 = r3.a, s2 = void 0 === i2 ? 1 : i2;
15856 if (!t(n2) || !t(a2) || !t(o2)) return null;
15857 var h2 = (function(r4) {
15858 return { h: u(r4.h), s: e(r4.s, 0, 100), v: e(r4.v, 0, 100), a: e(r4.a) };
15859 })({ h: Number(n2), s: Number(a2), v: Number(o2), a: Number(s2) });
15860 return b(h2);
15861 }, "hsv"]] };
15862 var N = function(r3, t2) {
15863 for (var n2 = 0; n2 < t2.length; n2++) {
15864 var e2 = t2[n2][0](r3);
15865 if (e2) return [e2, t2[n2][1]];
15866 }
15867 return [null, void 0];
15868 };
15869 var x = function(r3) {
15870 return "string" == typeof r3 ? N(r3.trim(), y.string) : "object" == typeof r3 && null !== r3 ? N(r3, y.object) : [null, void 0];
15871 };
15872 var M = function(r3, t2) {
15873 var n2 = c(r3);
15874 return { h: n2.h, s: e(n2.s + 100 * t2, 0, 100), l: n2.l, a: n2.a };
15875 };
15876 var H = function(r3) {
15877 return (299 * r3.r + 587 * r3.g + 114 * r3.b) / 1e3 / 255;
15878 };
15879 var $ = function(r3, t2) {
15880 var n2 = c(r3);
15881 return { h: n2.h, s: n2.s, l: e(n2.l + 100 * t2, 0, 100), a: n2.a };
15882 };
15883 var j = (function() {
15884 function r3(r4) {
15885 this.parsed = x(r4)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
15886 }
15887 return r3.prototype.isValid = function() {
15888 return null !== this.parsed;
15889 }, r3.prototype.brightness = function() {
15890 return n(H(this.rgba), 2);
15891 }, r3.prototype.isDark = function() {
15892 return H(this.rgba) < 0.5;
15893 }, r3.prototype.isLight = function() {
15894 return H(this.rgba) >= 0.5;
15895 }, r3.prototype.toHex = function() {
15896 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;
15897 var r4, t2, e2, u2, a2, i2;
15898 }, r3.prototype.toRgb = function() {
15899 return o(this.rgba);
15900 }, r3.prototype.toRgbString = function() {
15901 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 + ")";
15902 var r4, t2, n2, e2, u2;
15903 }, r3.prototype.toHsl = function() {
15904 return d(c(this.rgba));
15905 }, r3.prototype.toHslString = function() {
15906 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 + "%)";
15907 var r4, t2, n2, e2, u2;
15908 }, r3.prototype.toHsv = function() {
15909 return r4 = h(this.rgba), { h: n(r4.h), s: n(r4.s), v: n(r4.v), a: n(r4.a, 3) };
15910 var r4;
15911 }, r3.prototype.invert = function() {
15912 return w({ r: 255 - (r4 = this.rgba).r, g: 255 - r4.g, b: 255 - r4.b, a: r4.a });
15913 var r4;
15914 }, r3.prototype.saturate = function(r4) {
15915 return void 0 === r4 && (r4 = 0.1), w(M(this.rgba, r4));
15916 }, r3.prototype.desaturate = function(r4) {
15917 return void 0 === r4 && (r4 = 0.1), w(M(this.rgba, -r4));
15918 }, r3.prototype.grayscale = function() {
15919 return w(M(this.rgba, -1));
15920 }, r3.prototype.lighten = function(r4) {
15921 return void 0 === r4 && (r4 = 0.1), w($(this.rgba, r4));
15922 }, r3.prototype.darken = function(r4) {
15923 return void 0 === r4 && (r4 = 0.1), w($(this.rgba, -r4));
15924 }, r3.prototype.rotate = function(r4) {
15925 return void 0 === r4 && (r4 = 15), this.hue(this.hue() + r4);
15926 }, r3.prototype.alpha = function(r4) {
15927 return "number" == typeof r4 ? w({ r: (t2 = this.rgba).r, g: t2.g, b: t2.b, a: r4 }) : n(this.rgba.a, 3);
15928 var t2;
15929 }, r3.prototype.hue = function(r4) {
15930 var t2 = c(this.rgba);
15931 return "number" == typeof r4 ? w({ h: r4, s: t2.s, l: t2.l, a: t2.a }) : n(t2.h);
15932 }, r3.prototype.isEqual = function(r4) {
15933 return this.toHex() === w(r4).toHex();
15934 }, r3;
15935 })();
15936 var w = function(r3) {
15937 return r3 instanceof j ? r3 : new j(r3);
15938 };
15939
15940 // packages/dataviews/build-module/components/dataform-controls/color.mjs
15941 var import_components44 = __toESM(require_components(), 1);
15942 var import_element52 = __toESM(require_element(), 1);
15943 var import_i18n41 = __toESM(require_i18n(), 1);
15944 var import_jsx_runtime94 = __toESM(require_jsx_runtime(), 1);
15945 var { ValidatedInputControl: ValidatedInputControl3 } = unlock(import_components44.privateApis);
15946 var ColorPickerDropdown = ({
15947 color,
15948 onColorChange
15949 }) => {
15950 const validColor = color && w(color).isValid() ? color : "#ffffff";
15951 return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
15952 import_components44.Dropdown,
15953 {
15954 className: "dataviews-controls__color-picker-dropdown",
15955 popoverProps: { resize: false },
15956 renderToggle: ({ onToggle }) => /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
15957 import_components44.Button,
15958 {
15959 onClick: onToggle,
15960 "aria-label": (0, import_i18n41.__)("Open color picker"),
15961 size: "small",
15962 icon: () => /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_components44.ColorIndicator, { colorValue: validColor })
15963 }
15964 ),
15965 renderContent: () => /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_components44.__experimentalDropdownContentWrapper, { paddingSize: "none", children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
15966 import_components44.ColorPicker,
15967 {
15968 color: validColor,
15969 onChange: onColorChange,
15970 enableAlpha: true
15971 }
15972 ) })
15973 }
15974 );
15975 };
15976 function Color({
15977 data,
15978 field,
15979 onChange,
15980 hideLabelFromVision,
15981 markWhenOptional,
15982 validity
15983 }) {
15984 const { label, placeholder, description, setValue, isValid: isValid2 } = field;
15985 const value = field.getValue({ item: data }) || "";
15986 const handleColorChange = (0, import_element52.useCallback)(
15987 (newColor) => {
15988 onChange(setValue({ item: data, value: newColor }));
15989 },
15990 [data, onChange, setValue]
15991 );
15992 const handleInputChange = (0, import_element52.useCallback)(
15993 (newValue) => {
15994 onChange(setValue({ item: data, value: newValue || "" }));
15995 },
15996 [data, onChange, setValue]
15997 );
15998 return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
15999 ValidatedInputControl3,
16000 {
16001 required: !!field.isValid?.required,
16002 markWhenOptional,
16003 customValidity: getCustomValidity(isValid2, validity),
16004 label,
16005 placeholder,
16006 value,
16007 help: description,
16008 onChange: handleInputChange,
16009 hideLabelFromVision,
16010 type: "text",
16011 prefix: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_components44.__experimentalInputControlPrefixWrapper, { variant: "control", children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16012 ColorPickerDropdown,
16013 {
16014 color: value,
16015 onColorChange: handleColorChange
16016 }
16017 ) })
16018 }
16019 );
16020 }
16021
16022 // packages/dataviews/build-module/components/dataform-controls/password.mjs
16023 var import_components45 = __toESM(require_components(), 1);
16024 var import_element53 = __toESM(require_element(), 1);
16025 var import_i18n42 = __toESM(require_i18n(), 1);
16026 var import_jsx_runtime95 = __toESM(require_jsx_runtime(), 1);
16027 function Password({
16028 data,
16029 field,
16030 onChange,
16031 hideLabelFromVision,
16032 markWhenOptional,
16033 validity
16034 }) {
16035 const [isVisible2, setIsVisible] = (0, import_element53.useState)(false);
16036 const toggleVisibility = (0, import_element53.useCallback)(() => {
16037 setIsVisible((prev) => !prev);
16038 }, []);
16039 return /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(
16040 ValidatedText,
16041 {
16042 ...{
16043 data,
16044 field,
16045 onChange,
16046 hideLabelFromVision,
16047 markWhenOptional,
16048 validity,
16049 type: isVisible2 ? "text" : "password",
16050 suffix: /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(import_components45.__experimentalInputControlSuffixWrapper, { variant: "control", children: /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(
16051 import_components45.Button,
16052 {
16053 icon: isVisible2 ? unseen_default : seen_default,
16054 onClick: toggleVisibility,
16055 size: "small",
16056 label: isVisible2 ? (0, import_i18n42.__)("Hide password") : (0, import_i18n42.__)("Show password")
16057 }
16058 ) })
16059 }
16060 }
16061 );
16062 }
16063
16064 // packages/dataviews/build-module/field-types/utils/has-elements.mjs
16065 function hasElements(field) {
16066 return Array.isArray(field.elements) && field.elements.length > 0 || typeof field.getElements === "function";
16067 }
16068
16069 // packages/dataviews/build-module/components/dataform-controls/index.mjs
16070 var import_jsx_runtime96 = __toESM(require_jsx_runtime(), 1);
16071 var FORM_CONTROLS = {
16072 adaptiveSelect: AdaptiveSelect,
16073 array: ArrayControl,
16074 checkbox: Checkbox,
16075 color: Color,
16076 combobox: Combobox3,
16077 datetime: DateTime,
16078 date: DateControl,
16079 email: Email,
16080 telephone: Telephone,
16081 url: Url,
16082 integer: Integer,
16083 number: Number2,
16084 password: Password,
16085 radio: Radio,
16086 select: Select,
16087 text: Text,
16088 toggle: Toggle,
16089 textarea: Textarea,
16090 toggleGroup: ToggleGroup
16091 };
16092 function isEditConfig(value) {
16093 return value && typeof value === "object" && typeof value.control === "string";
16094 }
16095 function createConfiguredControl(config) {
16096 const { control, ...controlConfig } = config;
16097 const BaseControlType = getControlByType(control);
16098 if (BaseControlType === null) {
16099 return null;
16100 }
16101 return function ConfiguredControl(props) {
16102 return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(BaseControlType, { ...props, config: controlConfig });
16103 };
16104 }
16105 function getControl(field, fallback) {
16106 if (typeof field.Edit === "function") {
16107 return field.Edit;
16108 }
16109 if (typeof field.Edit === "string") {
16110 return getControlByType(field.Edit);
16111 }
16112 if (isEditConfig(field.Edit)) {
16113 return createConfiguredControl(field.Edit);
16114 }
16115 if (hasElements(field) && field.type !== "array") {
16116 return getControlByType("adaptiveSelect");
16117 }
16118 if (fallback === null) {
16119 return null;
16120 }
16121 return getControlByType(fallback);
16122 }
16123 function getControlByType(type) {
16124 if (Object.keys(FORM_CONTROLS).includes(type)) {
16125 return FORM_CONTROLS[type];
16126 }
16127 return null;
16128 }
16129
16130 // packages/dataviews/build-module/field-types/utils/get-filter-by.mjs
16131 function getFilterBy(field, defaultOperators, validOperators) {
16132 if (field.filterBy === false) {
16133 return false;
16134 }
16135 const operators = field.filterBy?.operators?.filter(
16136 (op) => validOperators.includes(op)
16137 ) ?? defaultOperators;
16138 if (operators.length === 0) {
16139 return false;
16140 }
16141 return {
16142 isPrimary: !!field.filterBy?.isPrimary,
16143 operators
16144 };
16145 }
16146 var get_filter_by_default = getFilterBy;
16147
16148 // packages/dataviews/build-module/field-types/utils/get-value-from-id.mjs
16149 var getValueFromId = (id) => ({ item }) => {
16150 const path = id.split(".");
16151 let value = item;
16152 for (const segment of path) {
16153 if (value.hasOwnProperty(segment)) {
16154 value = value[segment];
16155 } else {
16156 value = void 0;
16157 }
16158 }
16159 return value;
16160 };
16161 var get_value_from_id_default = getValueFromId;
16162
16163 // packages/dataviews/build-module/field-types/utils/set-value-from-id.mjs
16164 var setValueFromId = (id) => ({ value }) => {
16165 const path = id.split(".");
16166 const result = {};
16167 let current = result;
16168 for (const segment of path.slice(0, -1)) {
16169 current[segment] = {};
16170 current = current[segment];
16171 }
16172 current[path.at(-1)] = value;
16173 return result;
16174 };
16175 var set_value_from_id_default = setValueFromId;
16176
16177 // packages/dataviews/build-module/field-types/email.mjs
16178 var import_i18n43 = __toESM(require_i18n(), 1);
16179
16180 // packages/dataviews/build-module/field-types/utils/render-from-elements.mjs
16181 function RenderFromElements({
16182 item,
16183 field
16184 }) {
16185 const { elements, isLoading } = useElements({
16186 elements: field.elements,
16187 getElements: field.getElements
16188 });
16189 const value = field.getValue({ item });
16190 if (isLoading) {
16191 return value;
16192 }
16193 if (elements.length === 0) {
16194 return value;
16195 }
16196 return elements?.find((element) => element.value === value)?.label || field.getValue({ item });
16197 }
16198
16199 // packages/dataviews/build-module/field-types/utils/render-default.mjs
16200 var import_jsx_runtime97 = __toESM(require_jsx_runtime(), 1);
16201 function render({
16202 item,
16203 field
16204 }) {
16205 if (field.hasElements) {
16206 return /* @__PURE__ */ (0, import_jsx_runtime97.jsx)(RenderFromElements, { item, field });
16207 }
16208 return field.getValueFormatted({ item, field });
16209 }
16210
16211 // packages/dataviews/build-module/field-types/utils/sort-text.mjs
16212 var sort_text_default = (a2, b2, direction) => {
16213 return direction === "asc" ? a2.localeCompare(b2) : b2.localeCompare(a2);
16214 };
16215
16216 // packages/dataviews/build-module/field-types/utils/is-valid-required.mjs
16217 function isValidRequired(item, field) {
16218 const value = field.getValue({ item });
16219 return ![void 0, "", null].includes(value);
16220 }
16221
16222 // packages/dataviews/build-module/field-types/utils/is-valid-min-length.mjs
16223 function isValidMinLength(item, field) {
16224 if (typeof field.isValid.minLength?.constraint !== "number") {
16225 return false;
16226 }
16227 const value = field.getValue({ item });
16228 if ([void 0, "", null].includes(value)) {
16229 return true;
16230 }
16231 return String(value).length >= field.isValid.minLength.constraint;
16232 }
16233
16234 // packages/dataviews/build-module/field-types/utils/is-valid-max-length.mjs
16235 function isValidMaxLength(item, field) {
16236 if (typeof field.isValid.maxLength?.constraint !== "number") {
16237 return false;
16238 }
16239 const value = field.getValue({ item });
16240 if ([void 0, "", null].includes(value)) {
16241 return true;
16242 }
16243 return String(value).length <= field.isValid.maxLength.constraint;
16244 }
16245
16246 // packages/dataviews/build-module/field-types/utils/is-valid-pattern.mjs
16247 function isValidPattern(item, field) {
16248 if (field.isValid.pattern?.constraint === void 0) {
16249 return true;
16250 }
16251 try {
16252 const regexp = new RegExp(field.isValid.pattern.constraint);
16253 const value = field.getValue({ item });
16254 if ([void 0, "", null].includes(value)) {
16255 return true;
16256 }
16257 return regexp.test(String(value));
16258 } catch {
16259 return false;
16260 }
16261 }
16262
16263 // packages/dataviews/build-module/field-types/utils/is-valid-elements.mjs
16264 function isValidElements(item, field) {
16265 const elements = field.elements ?? [];
16266 const validValues = elements.map((el) => el.value);
16267 if (validValues.length === 0) {
16268 return true;
16269 }
16270 const value = field.getValue({ item });
16271 return [].concat(value).every((v2) => validValues.includes(v2));
16272 }
16273
16274 // packages/dataviews/build-module/field-types/utils/get-value-formatted-default.mjs
16275 function getValueFormatted({
16276 item,
16277 field
16278 }) {
16279 return field.getValue({ item });
16280 }
16281 var get_value_formatted_default_default = getValueFormatted;
16282
16283 // packages/dataviews/build-module/field-types/email.mjs
16284 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])?)*$/;
16285 function isValidCustom(item, field) {
16286 const value = field.getValue({ item });
16287 if (![void 0, "", null].includes(value) && !emailRegex.test(value)) {
16288 return (0, import_i18n43.__)("Value must be a valid email address.");
16289 }
16290 return null;
16291 }
16292 var email_default = {
16293 type: "email",
16294 render,
16295 Edit: "email",
16296 sort: sort_text_default,
16297 enableSorting: true,
16298 enableGlobalSearch: false,
16299 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16300 validOperators: [
16301 OPERATOR_IS,
16302 OPERATOR_IS_NOT,
16303 OPERATOR_CONTAINS,
16304 OPERATOR_NOT_CONTAINS,
16305 OPERATOR_STARTS_WITH,
16306 // Multiple selection
16307 OPERATOR_IS_ANY,
16308 OPERATOR_IS_NONE,
16309 OPERATOR_IS_ALL,
16310 OPERATOR_IS_NOT_ALL
16311 ],
16312 format: {},
16313 getValueFormatted: get_value_formatted_default_default,
16314 validate: {
16315 required: isValidRequired,
16316 pattern: isValidPattern,
16317 minLength: isValidMinLength,
16318 maxLength: isValidMaxLength,
16319 elements: isValidElements,
16320 custom: isValidCustom
16321 }
16322 };
16323
16324 // packages/dataviews/build-module/field-types/integer.mjs
16325 var import_i18n44 = __toESM(require_i18n(), 1);
16326
16327 // packages/dataviews/build-module/field-types/utils/sort-number.mjs
16328 var sort_number_default = (a2, b2, direction) => {
16329 return direction === "asc" ? a2 - b2 : b2 - a2;
16330 };
16331
16332 // packages/dataviews/build-module/field-types/utils/is-valid-min.mjs
16333 function isValidMin(item, field) {
16334 if (typeof field.isValid.min?.constraint !== "number") {
16335 return false;
16336 }
16337 const value = field.getValue({ item });
16338 if ([void 0, "", null].includes(value)) {
16339 return true;
16340 }
16341 return Number(value) >= field.isValid.min.constraint;
16342 }
16343
16344 // packages/dataviews/build-module/field-types/utils/is-valid-max.mjs
16345 function isValidMax(item, field) {
16346 if (typeof field.isValid.max?.constraint !== "number") {
16347 return false;
16348 }
16349 const value = field.getValue({ item });
16350 if ([void 0, "", null].includes(value)) {
16351 return true;
16352 }
16353 return Number(value) <= field.isValid.max.constraint;
16354 }
16355
16356 // packages/dataviews/build-module/field-types/integer.mjs
16357 var format2 = {
16358 separatorThousand: ","
16359 };
16360 function getValueFormatted2({
16361 item,
16362 field
16363 }) {
16364 let value = field.getValue({ item });
16365 if (value === null || value === void 0) {
16366 return "";
16367 }
16368 value = Number(value);
16369 if (!Number.isFinite(value)) {
16370 return String(value);
16371 }
16372 let formatInteger;
16373 if (field.type !== "integer") {
16374 formatInteger = format2;
16375 } else {
16376 formatInteger = field.format;
16377 }
16378 const { separatorThousand } = formatInteger;
16379 const integerValue = Math.trunc(value);
16380 if (!separatorThousand) {
16381 return String(integerValue);
16382 }
16383 return String(integerValue).replace(
16384 /\B(?=(\d{3})+(?!\d))/g,
16385 separatorThousand
16386 );
16387 }
16388 function isValidCustom2(item, field) {
16389 const value = field.getValue({ item });
16390 if (![void 0, "", null].includes(value) && !Number.isInteger(value)) {
16391 return (0, import_i18n44.__)("Value must be an integer.");
16392 }
16393 return null;
16394 }
16395 var integer_default = {
16396 type: "integer",
16397 render,
16398 Edit: "integer",
16399 sort: sort_number_default,
16400 enableSorting: true,
16401 enableGlobalSearch: false,
16402 defaultOperators: [
16403 OPERATOR_IS,
16404 OPERATOR_IS_NOT,
16405 OPERATOR_LESS_THAN,
16406 OPERATOR_GREATER_THAN,
16407 OPERATOR_LESS_THAN_OR_EQUAL,
16408 OPERATOR_GREATER_THAN_OR_EQUAL,
16409 OPERATOR_BETWEEN
16410 ],
16411 validOperators: [
16412 // Single-selection
16413 OPERATOR_IS,
16414 OPERATOR_IS_NOT,
16415 OPERATOR_LESS_THAN,
16416 OPERATOR_GREATER_THAN,
16417 OPERATOR_LESS_THAN_OR_EQUAL,
16418 OPERATOR_GREATER_THAN_OR_EQUAL,
16419 OPERATOR_BETWEEN,
16420 // Multiple-selection
16421 OPERATOR_IS_ANY,
16422 OPERATOR_IS_NONE,
16423 OPERATOR_IS_ALL,
16424 OPERATOR_IS_NOT_ALL
16425 ],
16426 format: format2,
16427 getValueFormatted: getValueFormatted2,
16428 validate: {
16429 required: isValidRequired,
16430 min: isValidMin,
16431 max: isValidMax,
16432 elements: isValidElements,
16433 custom: isValidCustom2
16434 }
16435 };
16436
16437 // packages/dataviews/build-module/field-types/number.mjs
16438 var import_i18n45 = __toESM(require_i18n(), 1);
16439 var format3 = {
16440 separatorThousand: ",",
16441 separatorDecimal: ".",
16442 decimals: 2
16443 };
16444 function getValueFormatted3({
16445 item,
16446 field
16447 }) {
16448 let value = field.getValue({ item });
16449 if (value === null || value === void 0) {
16450 return "";
16451 }
16452 value = Number(value);
16453 if (!Number.isFinite(value)) {
16454 return String(value);
16455 }
16456 let formatNumber;
16457 if (field.type !== "number") {
16458 formatNumber = format3;
16459 } else {
16460 formatNumber = field.format;
16461 }
16462 const { separatorThousand, separatorDecimal, decimals } = formatNumber;
16463 const fixedValue = value.toFixed(decimals);
16464 const [integerPart, decimalPart] = fixedValue.split(".");
16465 const formattedInteger = separatorThousand ? integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, separatorThousand) : integerPart;
16466 return decimals === 0 ? formattedInteger : formattedInteger + separatorDecimal + decimalPart;
16467 }
16468 function isEmpty2(value) {
16469 return value === "" || value === void 0 || value === null;
16470 }
16471 function isValidCustom3(item, field) {
16472 const value = field.getValue({ item });
16473 if (!isEmpty2(value) && !Number.isFinite(value)) {
16474 return (0, import_i18n45.__)("Value must be a number.");
16475 }
16476 return null;
16477 }
16478 var number_default = {
16479 type: "number",
16480 render,
16481 Edit: "number",
16482 sort: sort_number_default,
16483 enableSorting: true,
16484 enableGlobalSearch: false,
16485 defaultOperators: [
16486 OPERATOR_IS,
16487 OPERATOR_IS_NOT,
16488 OPERATOR_LESS_THAN,
16489 OPERATOR_GREATER_THAN,
16490 OPERATOR_LESS_THAN_OR_EQUAL,
16491 OPERATOR_GREATER_THAN_OR_EQUAL,
16492 OPERATOR_BETWEEN
16493 ],
16494 validOperators: [
16495 // Single-selection
16496 OPERATOR_IS,
16497 OPERATOR_IS_NOT,
16498 OPERATOR_LESS_THAN,
16499 OPERATOR_GREATER_THAN,
16500 OPERATOR_LESS_THAN_OR_EQUAL,
16501 OPERATOR_GREATER_THAN_OR_EQUAL,
16502 OPERATOR_BETWEEN,
16503 // Multiple-selection
16504 OPERATOR_IS_ANY,
16505 OPERATOR_IS_NONE,
16506 OPERATOR_IS_ALL,
16507 OPERATOR_IS_NOT_ALL
16508 ],
16509 format: format3,
16510 getValueFormatted: getValueFormatted3,
16511 validate: {
16512 required: isValidRequired,
16513 min: isValidMin,
16514 max: isValidMax,
16515 elements: isValidElements,
16516 custom: isValidCustom3
16517 }
16518 };
16519
16520 // packages/dataviews/build-module/field-types/text.mjs
16521 var text_default = {
16522 type: "text",
16523 render,
16524 Edit: "text",
16525 sort: sort_text_default,
16526 enableSorting: true,
16527 enableGlobalSearch: false,
16528 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16529 validOperators: [
16530 // Single selection
16531 OPERATOR_IS,
16532 OPERATOR_IS_NOT,
16533 OPERATOR_CONTAINS,
16534 OPERATOR_NOT_CONTAINS,
16535 OPERATOR_STARTS_WITH,
16536 // Multiple selection
16537 OPERATOR_IS_ANY,
16538 OPERATOR_IS_NONE,
16539 OPERATOR_IS_ALL,
16540 OPERATOR_IS_NOT_ALL
16541 ],
16542 format: {},
16543 getValueFormatted: get_value_formatted_default_default,
16544 validate: {
16545 required: isValidRequired,
16546 pattern: isValidPattern,
16547 minLength: isValidMinLength,
16548 maxLength: isValidMaxLength,
16549 elements: isValidElements
16550 }
16551 };
16552
16553 // packages/dataviews/build-module/field-types/datetime.mjs
16554 var import_date6 = __toESM(require_date(), 1);
16555 var format4 = {
16556 datetime: (0, import_date6.getSettings)().formats.datetime,
16557 weekStartsOn: (0, import_date6.getSettings)().l10n.startOfWeek
16558 };
16559 function getValueFormatted4({
16560 item,
16561 field
16562 }) {
16563 const value = field.getValue({ item });
16564 if (["", void 0, null].includes(value)) {
16565 return "";
16566 }
16567 let formatDatetime;
16568 if (field.type !== "datetime") {
16569 formatDatetime = format4;
16570 } else {
16571 formatDatetime = field.format;
16572 }
16573 return (0, import_date6.dateI18n)(formatDatetime.datetime, (0, import_date6.getDate)(value));
16574 }
16575 var sort = (a2, b2, direction) => {
16576 const timeA = new Date(a2).getTime();
16577 const timeB = new Date(b2).getTime();
16578 return direction === "asc" ? timeA - timeB : timeB - timeA;
16579 };
16580 var datetime_default = {
16581 type: "datetime",
16582 render,
16583 Edit: "datetime",
16584 sort,
16585 enableSorting: true,
16586 enableGlobalSearch: false,
16587 defaultOperators: [
16588 OPERATOR_ON,
16589 OPERATOR_NOT_ON,
16590 OPERATOR_BEFORE,
16591 OPERATOR_AFTER,
16592 OPERATOR_BEFORE_INC,
16593 OPERATOR_AFTER_INC,
16594 OPERATOR_IN_THE_PAST,
16595 OPERATOR_OVER
16596 ],
16597 validOperators: [
16598 OPERATOR_ON,
16599 OPERATOR_NOT_ON,
16600 OPERATOR_BEFORE,
16601 OPERATOR_AFTER,
16602 OPERATOR_BEFORE_INC,
16603 OPERATOR_AFTER_INC,
16604 OPERATOR_IN_THE_PAST,
16605 OPERATOR_OVER
16606 ],
16607 format: format4,
16608 getValueFormatted: getValueFormatted4,
16609 validate: {
16610 required: isValidRequired,
16611 elements: isValidElements
16612 }
16613 };
16614
16615 // packages/dataviews/build-module/field-types/date.mjs
16616 var import_date7 = __toESM(require_date(), 1);
16617 var format5 = {
16618 date: (0, import_date7.getSettings)().formats.date,
16619 weekStartsOn: (0, import_date7.getSettings)().l10n.startOfWeek
16620 };
16621 function getValueFormatted5({
16622 item,
16623 field
16624 }) {
16625 const value = field.getValue({ item });
16626 if (["", void 0, null].includes(value)) {
16627 return "";
16628 }
16629 let formatDate2;
16630 if (field.type !== "date") {
16631 formatDate2 = format5;
16632 } else {
16633 formatDate2 = field.format;
16634 }
16635 return (0, import_date7.dateI18n)(formatDate2.date, (0, import_date7.getDate)(value));
16636 }
16637 var sort2 = (a2, b2, direction) => {
16638 const timeA = new Date(a2).getTime();
16639 const timeB = new Date(b2).getTime();
16640 return direction === "asc" ? timeA - timeB : timeB - timeA;
16641 };
16642 var date_default = {
16643 type: "date",
16644 render,
16645 Edit: "date",
16646 sort: sort2,
16647 enableSorting: true,
16648 enableGlobalSearch: false,
16649 defaultOperators: [
16650 OPERATOR_ON,
16651 OPERATOR_NOT_ON,
16652 OPERATOR_BEFORE,
16653 OPERATOR_AFTER,
16654 OPERATOR_BEFORE_INC,
16655 OPERATOR_AFTER_INC,
16656 OPERATOR_IN_THE_PAST,
16657 OPERATOR_OVER,
16658 OPERATOR_BETWEEN
16659 ],
16660 validOperators: [
16661 OPERATOR_ON,
16662 OPERATOR_NOT_ON,
16663 OPERATOR_BEFORE,
16664 OPERATOR_AFTER,
16665 OPERATOR_BEFORE_INC,
16666 OPERATOR_AFTER_INC,
16667 OPERATOR_IN_THE_PAST,
16668 OPERATOR_OVER,
16669 OPERATOR_BETWEEN
16670 ],
16671 format: format5,
16672 getValueFormatted: getValueFormatted5,
16673 validate: {
16674 required: isValidRequired,
16675 elements: isValidElements
16676 }
16677 };
16678
16679 // packages/dataviews/build-module/field-types/boolean.mjs
16680 var import_i18n46 = __toESM(require_i18n(), 1);
16681
16682 // packages/dataviews/build-module/field-types/utils/is-valid-required-for-bool.mjs
16683 function isValidRequiredForBool(item, field) {
16684 const value = field.getValue({ item });
16685 return value === true;
16686 }
16687
16688 // packages/dataviews/build-module/field-types/boolean.mjs
16689 function getValueFormatted6({
16690 item,
16691 field
16692 }) {
16693 const value = field.getValue({ item });
16694 if (value === true) {
16695 return (0, import_i18n46.__)("True");
16696 }
16697 if (value === false) {
16698 return (0, import_i18n46.__)("False");
16699 }
16700 return "";
16701 }
16702 function isValidCustom4(item, field) {
16703 const value = field.getValue({ item });
16704 if (![void 0, "", null].includes(value) && ![true, false].includes(value)) {
16705 return (0, import_i18n46.__)("Value must be true, false, or undefined");
16706 }
16707 return null;
16708 }
16709 var sort3 = (a2, b2, direction) => {
16710 const boolA = Boolean(a2);
16711 const boolB = Boolean(b2);
16712 if (boolA === boolB) {
16713 return 0;
16714 }
16715 if (direction === "asc") {
16716 return boolA ? 1 : -1;
16717 }
16718 return boolA ? -1 : 1;
16719 };
16720 var boolean_default = {
16721 type: "boolean",
16722 render,
16723 Edit: "checkbox",
16724 sort: sort3,
16725 validate: {
16726 required: isValidRequiredForBool,
16727 elements: isValidElements,
16728 custom: isValidCustom4
16729 },
16730 enableSorting: true,
16731 enableGlobalSearch: false,
16732 defaultOperators: [OPERATOR_IS, OPERATOR_IS_NOT],
16733 validOperators: [OPERATOR_IS, OPERATOR_IS_NOT],
16734 format: {},
16735 getValueFormatted: getValueFormatted6
16736 };
16737
16738 // packages/dataviews/build-module/field-types/media.mjs
16739 var media_default = {
16740 type: "media",
16741 render: () => null,
16742 Edit: null,
16743 sort: () => 0,
16744 enableSorting: false,
16745 enableGlobalSearch: false,
16746 defaultOperators: [],
16747 validOperators: [],
16748 format: {},
16749 getValueFormatted: get_value_formatted_default_default,
16750 // cannot validate any constraint, so
16751 // the only available validation for the field author
16752 // would be providing a custom validator.
16753 validate: {}
16754 };
16755
16756 // packages/dataviews/build-module/field-types/array.mjs
16757 var import_i18n47 = __toESM(require_i18n(), 1);
16758
16759 // packages/dataviews/build-module/field-types/utils/is-valid-required-for-array.mjs
16760 function isValidRequiredForArray(item, field) {
16761 const value = field.getValue({ item });
16762 return Array.isArray(value) && value.length > 0 && value.every(
16763 (element) => ![void 0, "", null].includes(element)
16764 );
16765 }
16766
16767 // packages/dataviews/build-module/field-types/array.mjs
16768 function getValueFormatted7({
16769 item,
16770 field
16771 }) {
16772 const value = field.getValue({ item });
16773 const arr = Array.isArray(value) ? value : [];
16774 return arr.join(", ");
16775 }
16776 function render2({ item, field }) {
16777 return getValueFormatted7({ item, field });
16778 }
16779 function isValidCustom5(item, field) {
16780 const value = field.getValue({ item });
16781 if (![void 0, "", null].includes(value) && !Array.isArray(value)) {
16782 return (0, import_i18n47.__)("Value must be an array.");
16783 }
16784 if (!value.every((v2) => typeof v2 === "string")) {
16785 return (0, import_i18n47.__)("Every value must be a string.");
16786 }
16787 return null;
16788 }
16789 var sort4 = (a2, b2, direction) => {
16790 const arrA = Array.isArray(a2) ? a2 : [];
16791 const arrB = Array.isArray(b2) ? b2 : [];
16792 if (arrA.length !== arrB.length) {
16793 return direction === "asc" ? arrA.length - arrB.length : arrB.length - arrA.length;
16794 }
16795 const joinedA = arrA.join(",");
16796 const joinedB = arrB.join(",");
16797 return direction === "asc" ? joinedA.localeCompare(joinedB) : joinedB.localeCompare(joinedA);
16798 };
16799 var array_default = {
16800 type: "array",
16801 render: render2,
16802 Edit: "array",
16803 sort: sort4,
16804 enableSorting: true,
16805 enableGlobalSearch: false,
16806 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16807 validOperators: [
16808 OPERATOR_IS_ANY,
16809 OPERATOR_IS_NONE,
16810 OPERATOR_IS_ALL,
16811 OPERATOR_IS_NOT_ALL
16812 ],
16813 format: {},
16814 getValueFormatted: getValueFormatted7,
16815 validate: {
16816 required: isValidRequiredForArray,
16817 elements: isValidElements,
16818 custom: isValidCustom5
16819 }
16820 };
16821
16822 // packages/dataviews/build-module/field-types/password.mjs
16823 function getValueFormatted8({
16824 item,
16825 field
16826 }) {
16827 return field.getValue({ item }) ? "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022" : "";
16828 }
16829 var password_default = {
16830 type: "password",
16831 render,
16832 Edit: "password",
16833 sort: () => 0,
16834 // Passwords should not be sortable for security reasons
16835 enableSorting: false,
16836 enableGlobalSearch: false,
16837 defaultOperators: [],
16838 validOperators: [],
16839 format: {},
16840 getValueFormatted: getValueFormatted8,
16841 validate: {
16842 required: isValidRequired,
16843 pattern: isValidPattern,
16844 minLength: isValidMinLength,
16845 maxLength: isValidMaxLength,
16846 elements: isValidElements
16847 }
16848 };
16849
16850 // packages/dataviews/build-module/field-types/telephone.mjs
16851 var telephone_default = {
16852 type: "telephone",
16853 render,
16854 Edit: "telephone",
16855 sort: sort_text_default,
16856 enableSorting: true,
16857 enableGlobalSearch: false,
16858 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16859 validOperators: [
16860 OPERATOR_IS,
16861 OPERATOR_IS_NOT,
16862 OPERATOR_CONTAINS,
16863 OPERATOR_NOT_CONTAINS,
16864 OPERATOR_STARTS_WITH,
16865 // Multiple selection
16866 OPERATOR_IS_ANY,
16867 OPERATOR_IS_NONE,
16868 OPERATOR_IS_ALL,
16869 OPERATOR_IS_NOT_ALL
16870 ],
16871 format: {},
16872 getValueFormatted: get_value_formatted_default_default,
16873 validate: {
16874 required: isValidRequired,
16875 pattern: isValidPattern,
16876 minLength: isValidMinLength,
16877 maxLength: isValidMaxLength,
16878 elements: isValidElements
16879 }
16880 };
16881
16882 // packages/dataviews/build-module/field-types/color.mjs
16883 var import_i18n48 = __toESM(require_i18n(), 1);
16884 var import_jsx_runtime98 = __toESM(require_jsx_runtime(), 1);
16885 function render3({ item, field }) {
16886 if (field.hasElements) {
16887 return /* @__PURE__ */ (0, import_jsx_runtime98.jsx)(RenderFromElements, { item, field });
16888 }
16889 const value = get_value_formatted_default_default({ item, field });
16890 if (!value || !w(value).isValid()) {
16891 return value;
16892 }
16893 return /* @__PURE__ */ (0, import_jsx_runtime98.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "8px" }, children: [
16894 /* @__PURE__ */ (0, import_jsx_runtime98.jsx)(
16895 "div",
16896 {
16897 style: {
16898 width: "16px",
16899 height: "16px",
16900 borderRadius: "50%",
16901 backgroundColor: value,
16902 border: "1px solid #ddd",
16903 flexShrink: 0
16904 }
16905 }
16906 ),
16907 /* @__PURE__ */ (0, import_jsx_runtime98.jsx)("span", { children: value })
16908 ] });
16909 }
16910 function isValidCustom6(item, field) {
16911 const value = field.getValue({ item });
16912 if (![void 0, "", null].includes(value) && !w(value).isValid()) {
16913 return (0, import_i18n48.__)("Value must be a valid color.");
16914 }
16915 return null;
16916 }
16917 var sort5 = (a2, b2, direction) => {
16918 const colorA = w(a2);
16919 const colorB = w(b2);
16920 if (!colorA.isValid() && !colorB.isValid()) {
16921 return 0;
16922 }
16923 if (!colorA.isValid()) {
16924 return direction === "asc" ? 1 : -1;
16925 }
16926 if (!colorB.isValid()) {
16927 return direction === "asc" ? -1 : 1;
16928 }
16929 const hslA = colorA.toHsl();
16930 const hslB = colorB.toHsl();
16931 if (hslA.h !== hslB.h) {
16932 return direction === "asc" ? hslA.h - hslB.h : hslB.h - hslA.h;
16933 }
16934 if (hslA.s !== hslB.s) {
16935 return direction === "asc" ? hslA.s - hslB.s : hslB.s - hslA.s;
16936 }
16937 return direction === "asc" ? hslA.l - hslB.l : hslB.l - hslA.l;
16938 };
16939 var color_default = {
16940 type: "color",
16941 render: render3,
16942 Edit: "color",
16943 sort: sort5,
16944 enableSorting: true,
16945 enableGlobalSearch: false,
16946 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16947 validOperators: [
16948 OPERATOR_IS,
16949 OPERATOR_IS_NOT,
16950 OPERATOR_IS_ANY,
16951 OPERATOR_IS_NONE
16952 ],
16953 format: {},
16954 getValueFormatted: get_value_formatted_default_default,
16955 validate: {
16956 required: isValidRequired,
16957 elements: isValidElements,
16958 custom: isValidCustom6
16959 }
16960 };
16961
16962 // packages/dataviews/build-module/field-types/url.mjs
16963 var url_default = {
16964 type: "url",
16965 render,
16966 Edit: "url",
16967 sort: sort_text_default,
16968 enableSorting: true,
16969 enableGlobalSearch: false,
16970 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16971 validOperators: [
16972 OPERATOR_IS,
16973 OPERATOR_IS_NOT,
16974 OPERATOR_CONTAINS,
16975 OPERATOR_NOT_CONTAINS,
16976 OPERATOR_STARTS_WITH,
16977 // Multiple selection
16978 OPERATOR_IS_ANY,
16979 OPERATOR_IS_NONE,
16980 OPERATOR_IS_ALL,
16981 OPERATOR_IS_NOT_ALL
16982 ],
16983 format: {},
16984 getValueFormatted: get_value_formatted_default_default,
16985 validate: {
16986 required: isValidRequired,
16987 pattern: isValidPattern,
16988 minLength: isValidMinLength,
16989 maxLength: isValidMaxLength,
16990 elements: isValidElements
16991 }
16992 };
16993
16994 // packages/dataviews/build-module/field-types/no-type.mjs
16995 var sort6 = (a2, b2, direction) => {
16996 if (typeof a2 === "number" && typeof b2 === "number") {
16997 return sort_number_default(a2, b2, direction);
16998 }
16999 return sort_text_default(a2, b2, direction);
17000 };
17001 var no_type_default = {
17002 // type: no type for this one
17003 render,
17004 Edit: null,
17005 sort: sort6,
17006 enableSorting: true,
17007 enableGlobalSearch: false,
17008 defaultOperators: [OPERATOR_IS, OPERATOR_IS_NOT],
17009 validOperators: getAllOperatorNames(),
17010 format: {},
17011 getValueFormatted: get_value_formatted_default_default,
17012 validate: {
17013 required: isValidRequired,
17014 elements: isValidElements
17015 }
17016 };
17017
17018 // packages/dataviews/build-module/field-types/utils/get-is-valid.mjs
17019 function getIsValid(field, fieldType) {
17020 let required;
17021 if (field.isValid?.required === true && fieldType.validate.required !== void 0) {
17022 required = {
17023 constraint: true,
17024 validate: fieldType.validate.required
17025 };
17026 }
17027 let elements;
17028 if ((field.isValid?.elements === true || // elements is enabled unless the field opts-out
17029 field.isValid?.elements === void 0 && (!!field.elements || !!field.getElements)) && fieldType.validate.elements !== void 0) {
17030 elements = {
17031 constraint: true,
17032 validate: fieldType.validate.elements
17033 };
17034 }
17035 let min;
17036 if (typeof field.isValid?.min === "number" && fieldType.validate.min !== void 0) {
17037 min = {
17038 constraint: field.isValid.min,
17039 validate: fieldType.validate.min
17040 };
17041 }
17042 let max;
17043 if (typeof field.isValid?.max === "number" && fieldType.validate.max !== void 0) {
17044 max = {
17045 constraint: field.isValid.max,
17046 validate: fieldType.validate.max
17047 };
17048 }
17049 let minLength;
17050 if (typeof field.isValid?.minLength === "number" && fieldType.validate.minLength !== void 0) {
17051 minLength = {
17052 constraint: field.isValid.minLength,
17053 validate: fieldType.validate.minLength
17054 };
17055 }
17056 let maxLength;
17057 if (typeof field.isValid?.maxLength === "number" && fieldType.validate.maxLength !== void 0) {
17058 maxLength = {
17059 constraint: field.isValid.maxLength,
17060 validate: fieldType.validate.maxLength
17061 };
17062 }
17063 let pattern;
17064 if (field.isValid?.pattern !== void 0 && fieldType.validate.pattern !== void 0) {
17065 pattern = {
17066 constraint: field.isValid?.pattern,
17067 validate: fieldType.validate.pattern
17068 };
17069 }
17070 const custom = field.isValid?.custom ?? fieldType.validate.custom;
17071 return {
17072 required,
17073 elements,
17074 min,
17075 max,
17076 minLength,
17077 maxLength,
17078 pattern,
17079 custom
17080 };
17081 }
17082
17083 // packages/dataviews/build-module/field-types/utils/get-filter.mjs
17084 function getFilter(fieldType) {
17085 return fieldType.validOperators.reduce((accumulator, operator) => {
17086 const operatorObj = getOperatorByName(operator);
17087 if (operatorObj?.filter) {
17088 accumulator[operator] = operatorObj.filter;
17089 }
17090 return accumulator;
17091 }, {});
17092 }
17093
17094 // packages/dataviews/build-module/field-types/utils/get-format.mjs
17095 function getFormat(field, fieldType) {
17096 return {
17097 ...fieldType.format,
17098 ...field.format
17099 };
17100 }
17101 var get_format_default = getFormat;
17102
17103 // packages/dataviews/build-module/field-types/index.mjs
17104 function getFieldTypeByName(type) {
17105 const found = [
17106 email_default,
17107 integer_default,
17108 number_default,
17109 text_default,
17110 datetime_default,
17111 date_default,
17112 boolean_default,
17113 media_default,
17114 array_default,
17115 password_default,
17116 telephone_default,
17117 color_default,
17118 url_default
17119 ].find((fieldType) => fieldType?.type === type);
17120 if (!!found) {
17121 return found;
17122 }
17123 return no_type_default;
17124 }
17125 function normalizeFields(fields) {
17126 return fields.map((field) => {
17127 const fieldType = getFieldTypeByName(field.type);
17128 const getValue = field.getValue || get_value_from_id_default(field.id);
17129 const sort7 = function(a2, b2, direction) {
17130 const aValue = getValue({ item: a2 });
17131 const bValue = getValue({ item: b2 });
17132 return field.sort ? field.sort(aValue, bValue, direction) : fieldType.sort(aValue, bValue, direction);
17133 };
17134 return {
17135 id: field.id,
17136 label: field.label || field.id,
17137 header: field.header || field.label || field.id,
17138 description: field.description,
17139 placeholder: field.placeholder,
17140 getValue,
17141 setValue: field.setValue || set_value_from_id_default(field.id),
17142 elements: field.elements,
17143 getElements: field.getElements,
17144 hasElements: hasElements(field),
17145 isVisible: field.isVisible,
17146 enableHiding: field.enableHiding ?? true,
17147 readOnly: field.readOnly ?? false,
17148 // The type provides defaults for the following props
17149 type: fieldType.type,
17150 render: field.render ?? fieldType.render,
17151 Edit: getControl(field, fieldType.Edit),
17152 sort: sort7,
17153 enableSorting: field.enableSorting ?? fieldType.enableSorting,
17154 enableGlobalSearch: field.enableGlobalSearch ?? fieldType.enableGlobalSearch,
17155 isValid: getIsValid(field, fieldType),
17156 filterBy: get_filter_by_default(
17157 field,
17158 fieldType.defaultOperators,
17159 fieldType.validOperators
17160 ),
17161 filter: getFilter(fieldType),
17162 format: get_format_default(field, fieldType),
17163 getValueFormatted: field.getValueFormatted ?? fieldType.getValueFormatted
17164 };
17165 });
17166 }
17167
17168 // packages/dataviews/build-module/hooks/use-data.mjs
17169 var import_element54 = __toESM(require_element(), 1);
17170 function useData({
17171 view,
17172 data: shownData,
17173 getItemId,
17174 isLoading,
17175 paginationInfo,
17176 selection
17177 }) {
17178 const isInfiniteScrollEnabled = view.infiniteScrollEnabled;
17179 const [hasInitiallyLoaded, setHasInitiallyLoaded] = (0, import_element54.useState)(
17180 !isLoading
17181 );
17182 (0, import_element54.useEffect)(() => {
17183 if (!isLoading) {
17184 setHasInitiallyLoaded(true);
17185 }
17186 }, [isLoading]);
17187 const previousDataRef = (0, import_element54.useRef)(shownData);
17188 const previousPaginationInfoRef = (0, import_element54.useRef)(paginationInfo);
17189 (0, import_element54.useEffect)(() => {
17190 if (!isLoading) {
17191 previousDataRef.current = shownData;
17192 previousPaginationInfoRef.current = paginationInfo;
17193 }
17194 }, [shownData, isLoading, paginationInfo]);
17195 const [visibleEntries, setVisibleEntries] = (0, import_element54.useState)([]);
17196 const positionMapRef = (0, import_element54.useRef)(/* @__PURE__ */ new Map());
17197 const allLoadedRecordsRef = (0, import_element54.useRef)([]);
17198 const prevViewParamsRef = (0, import_element54.useRef)({
17199 search: void 0,
17200 filters: void 0,
17201 perPage: void 0
17202 });
17203 const scrollDirectionRef = (0, import_element54.useRef)(void 0);
17204 const prevStartPositionRef = (0, import_element54.useRef)(void 0);
17205 const hasInitializedRef = (0, import_element54.useRef)(false);
17206 const allLoadedRecords = (0, import_element54.useMemo)(() => {
17207 if (view.startPosition !== void 0 && prevStartPositionRef.current !== void 0) {
17208 if (view.startPosition < prevStartPositionRef.current) {
17209 scrollDirectionRef.current = "up";
17210 } else if (view.startPosition > prevStartPositionRef.current) {
17211 scrollDirectionRef.current = "down";
17212 }
17213 }
17214 prevStartPositionRef.current = view.startPosition;
17215 const currentFiltersKey = JSON.stringify(view.filters ?? []);
17216 const prevFiltersKey = prevViewParamsRef.current.filters;
17217 const shouldReset = !hasInitializedRef.current || !view.infiniteScrollEnabled || view.search !== prevViewParamsRef.current.search || currentFiltersKey !== prevFiltersKey || view.perPage !== prevViewParamsRef.current.perPage;
17218 hasInitializedRef.current = true;
17219 prevViewParamsRef.current = {
17220 search: view.search,
17221 filters: currentFiltersKey,
17222 perPage: view.perPage
17223 };
17224 if (shouldReset) {
17225 positionMapRef.current.clear();
17226 scrollDirectionRef.current = void 0;
17227 const startPosition = view.search ? 1 : view.startPosition ?? 1;
17228 const records = shownData.map((record, index) => {
17229 const position = startPosition + index;
17230 positionMapRef.current.set(getItemId(record), position);
17231 return {
17232 ...record,
17233 position
17234 };
17235 });
17236 allLoadedRecordsRef.current = records;
17237 return records;
17238 }
17239 const prev = allLoadedRecordsRef.current;
17240 const shownDataIds = new Set(shownData.map(getItemId));
17241 const scrollDirection = scrollDirectionRef.current;
17242 const basePosition = view.search ? 1 : view.startPosition ?? 1;
17243 const newRecords = shownData.map((record, index) => {
17244 const itemId = getItemId(record);
17245 const position = view.infiniteScrollEnabled ? basePosition + index : void 0;
17246 if (position !== void 0) {
17247 positionMapRef.current.set(itemId, position);
17248 }
17249 return {
17250 ...record,
17251 position
17252 };
17253 });
17254 if (newRecords.length === 0) {
17255 return prev;
17256 }
17257 const prevWithoutDuplicates = prev.filter(
17258 (record) => !shownDataIds.has(getItemId(record))
17259 );
17260 const allRecords = scrollDirection === "up" ? [...newRecords, ...prevWithoutDuplicates] : [...prevWithoutDuplicates, ...newRecords];
17261 allRecords.sort((a2, b2) => {
17262 const posA = a2.position;
17263 const posB = b2.position;
17264 return posA - posB;
17265 });
17266 let result = allRecords;
17267 if (visibleEntries.length > 0) {
17268 const visibleMin = Math.min(...visibleEntries);
17269 const visibleMax = Math.max(...visibleEntries);
17270 const buffer = 20;
17271 const recordPositions = allRecords.map(
17272 (r3) => r3.position
17273 );
17274 const minRecordPos = Math.min(...recordPositions);
17275 const maxRecordPos = Math.max(...recordPositions);
17276 const hasOverlap = !(maxRecordPos < visibleMin - buffer || minRecordPos > visibleMax + buffer);
17277 if (hasOverlap) {
17278 result = allRecords.filter((record) => {
17279 const itemId = getItemId(record);
17280 const isSelected2 = selection?.includes(itemId);
17281 if (isSelected2) {
17282 return true;
17283 }
17284 const itemPosition = record.position;
17285 if (scrollDirection === "up") {
17286 return itemPosition <= visibleMax + buffer;
17287 } else if (scrollDirection === "down") {
17288 return itemPosition >= visibleMin - buffer;
17289 }
17290 return itemPosition >= visibleMin - buffer && itemPosition <= visibleMax + buffer;
17291 });
17292 }
17293 }
17294 allLoadedRecordsRef.current = result;
17295 return result;
17296 }, [
17297 shownData,
17298 view.search,
17299 view.filters,
17300 view.perPage,
17301 view.startPosition,
17302 view.infiniteScrollEnabled,
17303 visibleEntries,
17304 selection,
17305 getItemId
17306 ]);
17307 if (!isInfiniteScrollEnabled) {
17308 const dataToReturn = isLoading && previousDataRef.current?.length ? previousDataRef.current : shownData;
17309 return {
17310 data: dataToReturn.map((item) => ({
17311 ...item,
17312 position: void 0
17313 })),
17314 paginationInfo: isLoading && previousDataRef.current?.length ? previousPaginationInfoRef.current : paginationInfo,
17315 hasInitiallyLoaded,
17316 setVisibleEntries: void 0
17317 };
17318 }
17319 return {
17320 data: allLoadedRecords,
17321 paginationInfo,
17322 hasInitiallyLoaded,
17323 setVisibleEntries
17324 };
17325 }
17326
17327 // packages/dataviews/build-module/hooks/use-infinite-scroll.mjs
17328 var import_element55 = __toESM(require_element(), 1);
17329 var import_compose11 = __toESM(require_compose(), 1);
17330 function captureAnchorElement(container, anchorElementRef, direction) {
17331 const containerRect = container.getBoundingClientRect();
17332 const centerY = containerRect.top + containerRect.height / 2;
17333 const items = Array.from(container.querySelectorAll("[aria-posinset]"));
17334 if (items.length === 0) {
17335 return false;
17336 }
17337 const bestAnchor = items.reduce((best, item) => {
17338 const itemRect = item.getBoundingClientRect();
17339 const itemCenterY = itemRect.top + itemRect.height / 2;
17340 const distance = Math.abs(itemCenterY - centerY);
17341 const bestRect = best.getBoundingClientRect();
17342 const bestCenterY = bestRect.top + bestRect.height / 2;
17343 const bestDistance = Math.abs(bestCenterY - centerY);
17344 return distance < bestDistance ? item : best;
17345 });
17346 const posinset = Number(bestAnchor.getAttribute("aria-posinset"));
17347 const anchorRect = bestAnchor.getBoundingClientRect();
17348 anchorElementRef.current = {
17349 posinset,
17350 viewportOffset: anchorRect.top - containerRect.top,
17351 direction
17352 };
17353 return true;
17354 }
17355 function useInfiniteScroll({
17356 view,
17357 onChangeView,
17358 isLoading,
17359 paginationInfo,
17360 containerRef,
17361 setVisibleEntries
17362 }) {
17363 const anchorElementRef = (0, import_element55.useRef)(null);
17364 const viewRef = (0, import_element55.useRef)(view);
17365 const isLoadingRef = (0, import_element55.useRef)(isLoading);
17366 const onChangeViewRef = (0, import_element55.useRef)(onChangeView);
17367 const totalItemsRef = (0, import_element55.useRef)(paginationInfo.totalItems);
17368 (0, import_element55.useLayoutEffect)(() => {
17369 viewRef.current = view;
17370 isLoadingRef.current = isLoading;
17371 onChangeViewRef.current = onChangeView;
17372 totalItemsRef.current = paginationInfo.totalItems;
17373 }, [view, isLoading, onChangeView, paginationInfo.totalItems]);
17374 const intersectionObserverCallback = (0, import_element55.useCallback)(
17375 (entries) => {
17376 if (!setVisibleEntries) {
17377 return;
17378 }
17379 setVisibleEntries((prev) => {
17380 const newVisibleEntries = new Set(prev);
17381 let hasChanged = false;
17382 entries.forEach((entry) => {
17383 const posInSet = Number(
17384 entry.target?.attributes?.getNamedItem(
17385 "aria-posinset"
17386 )?.value
17387 );
17388 if (isNaN(posInSet)) {
17389 return;
17390 }
17391 if (entry.isIntersecting) {
17392 if (!newVisibleEntries.has(posInSet)) {
17393 newVisibleEntries.add(posInSet);
17394 hasChanged = true;
17395 }
17396 } else if (newVisibleEntries.has(posInSet)) {
17397 newVisibleEntries.delete(posInSet);
17398 hasChanged = true;
17399 }
17400 });
17401 return hasChanged ? Array.from(newVisibleEntries).sort() : prev;
17402 });
17403 },
17404 [setVisibleEntries]
17405 );
17406 (0, import_element55.useLayoutEffect)(() => {
17407 const container = containerRef.current;
17408 const anchor = anchorElementRef.current;
17409 if (!container || !view.infiniteScrollEnabled || !anchor || isLoading) {
17410 return;
17411 }
17412 const anchorElement = container.querySelector(
17413 `[aria-posinset="${anchor.posinset}"]`
17414 );
17415 if (anchorElement) {
17416 const containerRect = container.getBoundingClientRect();
17417 const anchorRect = anchorElement.getBoundingClientRect();
17418 const currentOffset = anchorRect.top - containerRect.top;
17419 const scrollAdjustment = currentOffset - anchor.viewportOffset;
17420 if (Math.abs(scrollAdjustment) > 1) {
17421 container.scrollTop += scrollAdjustment;
17422 }
17423 }
17424 anchorElementRef.current = null;
17425 }, [containerRef, isLoading, view.infiniteScrollEnabled]);
17426 const intersectionObserverRef = (0, import_element55.useRef)(
17427 null
17428 );
17429 (0, import_element55.useEffect)(() => {
17430 if (!view.infiniteScrollEnabled || !intersectionObserverCallback) {
17431 if (intersectionObserverRef.current) {
17432 intersectionObserverRef.current.disconnect();
17433 intersectionObserverRef.current = null;
17434 }
17435 return;
17436 }
17437 intersectionObserverRef.current = new IntersectionObserver(
17438 intersectionObserverCallback,
17439 { root: null, rootMargin: "0px", threshold: 0.1 }
17440 );
17441 return () => {
17442 if (intersectionObserverRef.current) {
17443 intersectionObserverRef.current.disconnect();
17444 intersectionObserverRef.current = null;
17445 }
17446 };
17447 }, [view.infiniteScrollEnabled, intersectionObserverCallback]);
17448 (0, import_element55.useEffect)(() => {
17449 if (!view.infiniteScrollEnabled || !containerRef.current) {
17450 return;
17451 }
17452 let lastScrollTop = 0;
17453 const BOTTOM_THRESHOLD = 600;
17454 const TOP_THRESHOLD = 800;
17455 const handleScroll = (0, import_compose11.throttle)((event) => {
17456 const currentView = viewRef.current;
17457 const totalItems = totalItemsRef.current;
17458 const target = event.target;
17459 const scrollTop = target.scrollTop;
17460 const scrollHeight = target.scrollHeight;
17461 const clientHeight = target.clientHeight;
17462 const scrollDirection = scrollTop > lastScrollTop ? "down" : "up";
17463 lastScrollTop = scrollTop;
17464 if (isLoadingRef.current) {
17465 return;
17466 }
17467 const currentStartPosition = currentView.startPosition || 1;
17468 const batchSize = currentView.perPage || 10;
17469 const currentEndPosition = Math.min(
17470 currentStartPosition + batchSize,
17471 totalItems
17472 );
17473 if (scrollDirection === "down" && scrollTop + clientHeight >= scrollHeight - BOTTOM_THRESHOLD) {
17474 if (currentEndPosition < totalItems) {
17475 const newStartPosition = currentEndPosition;
17476 captureAnchorElement(target, anchorElementRef, "down");
17477 onChangeViewRef.current({
17478 ...currentView,
17479 startPosition: newStartPosition
17480 });
17481 }
17482 }
17483 if (scrollDirection === "up" && scrollTop <= TOP_THRESHOLD) {
17484 if (currentStartPosition > 1) {
17485 const calculatedStartPosition = currentStartPosition - batchSize;
17486 const newStartPosition = calculatedStartPosition < 6 ? 1 : calculatedStartPosition;
17487 captureAnchorElement(target, anchorElementRef, "up");
17488 onChangeViewRef.current({
17489 ...currentView,
17490 startPosition: newStartPosition
17491 });
17492 }
17493 }
17494 }, 50);
17495 const container = containerRef.current;
17496 container.addEventListener("scroll", handleScroll);
17497 return () => {
17498 container.removeEventListener("scroll", handleScroll);
17499 handleScroll.cancel();
17500 };
17501 }, [containerRef, view.infiniteScrollEnabled]);
17502 return {
17503 intersectionObserver: intersectionObserverRef.current
17504 };
17505 }
17506
17507 // packages/dataviews/build-module/dataviews-picker/index.mjs
17508 var import_element56 = __toESM(require_element(), 1);
17509 var import_compose12 = __toESM(require_compose(), 1);
17510 var import_jsx_runtime99 = __toESM(require_jsx_runtime(), 1);
17511 var isItemClickable = () => false;
17512 var dataViewsPickerLayouts = VIEW_LAYOUTS.filter(
17513 (viewLayout) => viewLayout.isPicker
17514 );
17515 var defaultGetItemId = (item) => item.id;
17516 var EMPTY_ARRAY5 = [];
17517 function DefaultUI({
17518 search = true,
17519 searchLabel = void 0
17520 }) {
17521 const { view } = (0, import_element56.useContext)(dataviews_context_default);
17522 const isInfiniteScroll = view.infiniteScrollEnabled;
17523 return /* @__PURE__ */ (0, import_jsx_runtime99.jsxs)(import_jsx_runtime99.Fragment, { children: [
17524 /* @__PURE__ */ (0, import_jsx_runtime99.jsxs)(
17525 Stack,
17526 {
17527 direction: "row",
17528 align: "top",
17529 justify: "space-between",
17530 className: clsx_default("dataviews__view-actions", {
17531 "dataviews__view-actions--infinite-scroll": isInfiniteScroll
17532 }),
17533 gap: "xs",
17534 children: [
17535 /* @__PURE__ */ (0, import_jsx_runtime99.jsxs)(
17536 Stack,
17537 {
17538 direction: "row",
17539 gap: "sm",
17540 justify: "start",
17541 className: "dataviews__search",
17542 children: [
17543 search && /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(dataviews_search_default, { label: searchLabel }),
17544 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(toggle_default, {})
17545 ]
17546 }
17547 ),
17548 /* @__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, {}) })
17549 ]
17550 }
17551 ),
17552 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(filters_toggled_default, { className: "dataviews-filters__container" }),
17553 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(DataViewsLayout, {}),
17554 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(DataViewsPickerFooter, {})
17555 ] });
17556 }
17557 function DataViewsPicker({
17558 view,
17559 onChangeView,
17560 fields,
17561 search = true,
17562 searchLabel = void 0,
17563 actions = EMPTY_ARRAY5,
17564 data,
17565 getItemId = defaultGetItemId,
17566 isLoading = false,
17567 paginationInfo,
17568 defaultLayouts: defaultLayoutsProperty,
17569 selection,
17570 onChangeSelection,
17571 children,
17572 config = { perPageSizes: [10, 20, 50, 100] },
17573 itemListLabel,
17574 empty
17575 }) {
17576 const { data: displayData, setVisibleEntries } = useData({
17577 view,
17578 data,
17579 getItemId,
17580 selection,
17581 paginationInfo
17582 });
17583 const containerRef = (0, import_element56.useRef)(null);
17584 const [containerWidth, setContainerWidth] = (0, import_element56.useState)(0);
17585 const resizeObserverRef = (0, import_compose12.useResizeObserver)(
17586 (resizeObserverEntries) => {
17587 setContainerWidth(
17588 resizeObserverEntries[0].borderBoxSize[0].inlineSize
17589 );
17590 },
17591 { box: "border-box" }
17592 );
17593 const [openedFilter, setOpenedFilter] = (0, import_element56.useState)(null);
17594 function setSelectionWithChange(value) {
17595 const newValue = typeof value === "function" ? value(selection) : value;
17596 if (onChangeSelection) {
17597 onChangeSelection(newValue);
17598 }
17599 }
17600 const _fields = (0, import_element56.useMemo)(() => normalizeFields(fields), [fields]);
17601 const filters = use_filters_default(_fields, view);
17602 const hasPrimaryOrLockedFilters = (0, import_element56.useMemo)(
17603 () => (filters || []).some(
17604 (filter) => filter.isPrimary || filter.isLocked
17605 ),
17606 [filters]
17607 );
17608 const [isShowingFilter, setIsShowingFilter] = (0, import_element56.useState)(
17609 hasPrimaryOrLockedFilters
17610 );
17611 const { intersectionObserver } = useInfiniteScroll({
17612 view,
17613 onChangeView,
17614 isLoading,
17615 paginationInfo,
17616 containerRef,
17617 setVisibleEntries
17618 });
17619 (0, import_element56.useEffect)(() => {
17620 if (hasPrimaryOrLockedFilters && !isShowingFilter) {
17621 setIsShowingFilter(true);
17622 }
17623 }, [hasPrimaryOrLockedFilters, isShowingFilter]);
17624 const defaultLayouts = (0, import_element56.useMemo)(
17625 () => Object.fromEntries(
17626 Object.entries(defaultLayoutsProperty).filter(
17627 ([layoutType]) => {
17628 return dataViewsPickerLayouts.some(
17629 (viewLayout) => viewLayout.type === layoutType
17630 );
17631 }
17632 )
17633 ),
17634 [defaultLayoutsProperty]
17635 );
17636 if (!defaultLayouts[view.type]) {
17637 return null;
17638 }
17639 return /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(
17640 dataviews_context_default.Provider,
17641 {
17642 value: {
17643 view,
17644 onChangeView,
17645 fields: _fields,
17646 actions,
17647 data: displayData,
17648 isLoading,
17649 paginationInfo,
17650 isItemClickable,
17651 selection,
17652 onChangeSelection: setSelectionWithChange,
17653 openedFilter,
17654 setOpenedFilter,
17655 getItemId,
17656 containerWidth,
17657 containerRef,
17658 resizeObserverRef,
17659 defaultLayouts,
17660 filters,
17661 isShowingFilter,
17662 setIsShowingFilter,
17663 config,
17664 itemListLabel,
17665 empty,
17666 hasInitiallyLoaded: true,
17667 intersectionObserver
17668 },
17669 children: /* @__PURE__ */ (0, import_jsx_runtime99.jsx)("div", { className: "dataviews-picker-wrapper", children: children ?? /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(DefaultUI, { search, searchLabel }) })
17670 }
17671 );
17672 }
17673 var DataViewsPickerSubComponents = DataViewsPicker;
17674 DataViewsPickerSubComponents.BulkActionToolbar = DataViewsPickerFooter;
17675 DataViewsPickerSubComponents.Filters = filters_default;
17676 DataViewsPickerSubComponents.FiltersToggled = filters_toggled_default;
17677 DataViewsPickerSubComponents.FiltersToggle = toggle_default;
17678 DataViewsPickerSubComponents.Layout = DataViewsLayout;
17679 DataViewsPickerSubComponents.LayoutSwitcher = ViewTypeMenu;
17680 DataViewsPickerSubComponents.Pagination = DataViewsPagination;
17681 DataViewsPickerSubComponents.Search = dataviews_search_default;
17682 DataViewsPickerSubComponents.ViewConfig = DataviewsViewConfigDropdown;
17683 var dataviews_picker_default = DataViewsPickerSubComponents;
17684
17685 // packages/media-fields/build-module/alt_text/index.mjs
17686 var import_i18n49 = __toESM(require_i18n(), 1);
17687 var import_components46 = __toESM(require_components(), 1);
17688 var import_jsx_runtime100 = __toESM(require_jsx_runtime(), 1);
17689 var altTextField = {
17690 id: "alt_text",
17691 type: "text",
17692 label: (0, import_i18n49.__)("Alt text"),
17693 isVisible: (item) => item?.media_type === "image",
17694 render: ({ item }) => item?.alt_text || "-",
17695 Edit: ({ field, onChange, data }) => {
17696 return /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(
17697 import_components46.TextareaControl,
17698 {
17699 label: field.label,
17700 value: data.alt_text || "",
17701 onChange: (value) => onChange({ alt_text: value }),
17702 rows: 2
17703 }
17704 );
17705 },
17706 enableSorting: false,
17707 filterBy: false
17708 };
17709 var alt_text_default = altTextField;
17710
17711 // packages/media-fields/build-module/attached_to/index.mjs
17712 var import_i18n52 = __toESM(require_i18n(), 1);
17713
17714 // packages/media-fields/build-module/attached_to/view.mjs
17715 var import_element57 = __toESM(require_element(), 1);
17716 var import_i18n50 = __toESM(require_i18n(), 1);
17717
17718 // packages/media-fields/build-module/utils/get-rendered-content.mjs
17719 function getRenderedContent(content) {
17720 if (!content) {
17721 return "";
17722 }
17723 if (typeof content === "string") {
17724 return content;
17725 }
17726 if (typeof content === "object") {
17727 return content.rendered || content.raw || "";
17728 }
17729 return "";
17730 }
17731
17732 // packages/media-fields/build-module/attached_to/view.mjs
17733 var import_jsx_runtime101 = __toESM(require_jsx_runtime(), 1);
17734 function MediaAttachedToView({
17735 item
17736 }) {
17737 const [attachedPostTitle, setAttachedPostTitle] = (0, import_element57.useState)(null);
17738 const parentId = item.post;
17739 const embeddedPostId = item._embedded?.["wp:attached-to"]?.[0]?.id;
17740 const embeddedPostTitle = item._embedded?.["wp:attached-to"]?.[0]?.title;
17741 (0, import_element57.useEffect)(() => {
17742 if (!!parentId && parentId === embeddedPostId) {
17743 setAttachedPostTitle(
17744 getRenderedContent(embeddedPostTitle) || embeddedPostId?.toString() || ""
17745 );
17746 }
17747 if (!parentId) {
17748 setAttachedPostTitle((0, import_i18n50.__)("(Unattached)"));
17749 }
17750 }, [parentId, embeddedPostId, embeddedPostTitle]);
17751 return /* @__PURE__ */ (0, import_jsx_runtime101.jsx)(import_jsx_runtime101.Fragment, { children: attachedPostTitle });
17752 }
17753
17754 // packages/media-fields/build-module/attached_to/edit.mjs
17755 var import_core_data = __toESM(require_core_data(), 1);
17756 var import_components47 = __toESM(require_components(), 1);
17757 var import_i18n51 = __toESM(require_i18n(), 1);
17758 var import_element58 = __toESM(require_element(), 1);
17759 var import_compose13 = __toESM(require_compose(), 1);
17760 var import_data6 = __toESM(require_data(), 1);
17761 var import_jsx_runtime102 = __toESM(require_jsx_runtime(), 1);
17762 function MediaAttachedToEdit({
17763 data,
17764 onChange
17765 }) {
17766 const defaultPost = !!data.post && !!data?._embedded?.["wp:attached-to"]?.[0] ? [
17767 {
17768 label: getRenderedContent(
17769 data._embedded?.["wp:attached-to"]?.[0]?.title
17770 ),
17771 value: data.post.toString()
17772 }
17773 ] : [];
17774 const [options, setOptions] = (0, import_element58.useState)(defaultPost);
17775 const [searchResults, setSearchResults] = (0, import_element58.useState)(
17776 []
17777 );
17778 const [isLoading, setIsLoading] = (0, import_element58.useState)(false);
17779 const [value, setValue] = (0, import_element58.useState)(
17780 data?.post?.toString() ?? null
17781 );
17782 const postTypes = (0, import_data6.useSelect)(
17783 (select) => select(import_core_data.store).getPostTypes(),
17784 []
17785 );
17786 const handleDetach = () => {
17787 onChange({
17788 post: 0,
17789 _embedded: { ...data?._embedded, "wp:attached-to": void 0 }
17790 });
17791 setOptions([]);
17792 };
17793 const onValueChange = async (filterValue) => {
17794 setIsLoading(true);
17795 const results = await (0, import_core_data.__experimentalFetchLinkSuggestions)(
17796 filterValue,
17797 /*
17798 * @TODO `fetchLinkSuggestions()` should accept `perPage` as an option argument.
17799 * `isInitialSuggestions` limits the result to 3, otherwise it's hardcoded to 20.
17800 */
17801 { type: "post", isInitialSuggestions: true },
17802 {}
17803 );
17804 setSearchResults(results);
17805 const mappedSuggestions = results.map((result) => {
17806 return {
17807 label: result.title,
17808 value: result.id.toString()
17809 };
17810 });
17811 setOptions(mappedSuggestions);
17812 setIsLoading(false);
17813 };
17814 const handleSelectOption = (selectedPostId) => {
17815 if (!selectedPostId) {
17816 handleDetach();
17817 return;
17818 }
17819 setValue(selectedPostId);
17820 if (selectedPostId) {
17821 const selectedPost = searchResults.find(
17822 (result) => result.id === Number(selectedPostId)
17823 );
17824 if (selectedPost && postTypes) {
17825 const postType = postTypes.find(
17826 (_postType) => _postType.slug === selectedPost?.type
17827 );
17828 const attachedTo = {
17829 ...postType && { type: postType.slug },
17830 id: Number(selectedPostId),
17831 title: {
17832 raw: selectedPost.title,
17833 rendered: selectedPost.title
17834 }
17835 };
17836 onChange({
17837 post: Number(selectedPostId),
17838 _embedded: {
17839 ...data?._embedded,
17840 "wp:attached-to": [attachedTo]
17841 }
17842 });
17843 }
17844 }
17845 };
17846 const help = !!data.post ? (0, import_element58.createInterpolateElement)(
17847 (0, import_i18n51.__)(
17848 "Search for a post or page to attach this media to or <button>detach current</button>."
17849 ),
17850 {
17851 button: /* @__PURE__ */ (0, import_jsx_runtime102.jsx)(
17852 import_components47.Button,
17853 {
17854 __next40pxDefaultSize: true,
17855 onClick: handleDetach,
17856 variant: "link",
17857 accessibleWhenDisabled: true
17858 }
17859 )
17860 }
17861 ) : (0, import_i18n51.__)("Search for a post or page to attach this media to.");
17862 return /* @__PURE__ */ (0, import_jsx_runtime102.jsx)(
17863 import_components47.ComboboxControl,
17864 {
17865 className: "dataviews-media-field__attached-to",
17866 __next40pxDefaultSize: true,
17867 isLoading,
17868 label: (0, import_i18n51.__)("Attached to"),
17869 help,
17870 value,
17871 options,
17872 onFilterValueChange: (0, import_compose13.debounce)(
17873 (filterValue) => onValueChange(filterValue),
17874 300
17875 ),
17876 onChange: handleSelectOption,
17877 hideLabelFromVision: true
17878 }
17879 );
17880 }
17881
17882 // packages/media-fields/build-module/attached_to/index.mjs
17883 var attachedToField = {
17884 id: "attached_to",
17885 type: "text",
17886 label: (0, import_i18n52.__)("Attached to"),
17887 Edit: MediaAttachedToEdit,
17888 render: MediaAttachedToView,
17889 enableSorting: false,
17890 filterBy: false
17891 };
17892 var attached_to_default = attachedToField;
17893
17894 // packages/media-fields/build-module/author/index.mjs
17895 var import_i18n54 = __toESM(require_i18n(), 1);
17896 var import_data7 = __toESM(require_data(), 1);
17897 var import_core_data2 = __toESM(require_core_data(), 1);
17898
17899 // packages/media-fields/build-module/author/view.mjs
17900 var import_i18n53 = __toESM(require_i18n(), 1);
17901 var import_element59 = __toESM(require_element(), 1);
17902 var import_components48 = __toESM(require_components(), 1);
17903 var import_jsx_runtime103 = __toESM(require_jsx_runtime(), 1);
17904 function AuthorView({
17905 item
17906 }) {
17907 const author = item?._embedded?.author?.[0];
17908 const text = author?.name;
17909 const imageUrl = author?.avatar_urls?.[48];
17910 const [loadingState, setLoadingState] = (0, import_element59.useState)("loading");
17911 (0, import_element59.useEffect)(() => {
17912 setLoadingState("loading");
17913 }, [imageUrl]);
17914 const imgRef = (0, import_element59.useCallback)((img) => {
17915 if (img?.complete) {
17916 setLoadingState("instant");
17917 }
17918 }, []);
17919 const handleLoad = () => {
17920 if (loadingState === "loading") {
17921 setLoadingState("loaded");
17922 }
17923 };
17924 return /* @__PURE__ */ (0, import_jsx_runtime103.jsxs)(import_components48.__experimentalHStack, { alignment: "left", spacing: 0, children: [
17925 !!imageUrl && /* @__PURE__ */ (0, import_jsx_runtime103.jsx)(
17926 "div",
17927 {
17928 className: clsx_default("media-author-field__avatar", {
17929 "is-loading": loadingState === "loading",
17930 "is-loaded": loadingState === "loaded"
17931 }),
17932 children: /* @__PURE__ */ (0, import_jsx_runtime103.jsx)(
17933 "img",
17934 {
17935 ref: imgRef,
17936 onLoad: handleLoad,
17937 alt: (0, import_i18n53.__)("Author avatar"),
17938 src: imageUrl
17939 }
17940 )
17941 }
17942 ),
17943 !imageUrl && /* @__PURE__ */ (0, import_jsx_runtime103.jsx)("div", { className: "media-author-field__icon", children: /* @__PURE__ */ (0, import_jsx_runtime103.jsx)(import_components48.Icon, { icon: comment_author_avatar_default }) }),
17944 /* @__PURE__ */ (0, import_jsx_runtime103.jsx)("span", { className: "media-author-field__name", children: text })
17945 ] });
17946 }
17947
17948 // packages/media-fields/build-module/author/index.mjs
17949 var authorField = {
17950 label: (0, import_i18n54.__)("Author"),
17951 id: "author",
17952 type: "integer",
17953 getElements: async () => {
17954 const authors = await (0, import_data7.resolveSelect)(import_core_data2.store).getEntityRecords(
17955 "root",
17956 "user",
17957 {
17958 per_page: -1,
17959 who: "authors",
17960 _fields: "id,name",
17961 context: "view"
17962 }
17963 ) ?? [];
17964 return authors.map(({ id, name }) => ({
17965 value: id,
17966 label: name
17967 }));
17968 },
17969 render: AuthorView,
17970 sort: (a2, b2, direction) => {
17971 const nameA = a2._embedded?.author?.[0]?.name || "";
17972 const nameB = b2._embedded?.author?.[0]?.name || "";
17973 return direction === "asc" ? nameA.localeCompare(nameB) : nameB.localeCompare(nameA);
17974 },
17975 filterBy: {
17976 operators: ["isAny", "isNone"]
17977 },
17978 readOnly: true
17979 };
17980 var author_default = authorField;
17981
17982 // packages/media-fields/build-module/caption/index.mjs
17983 var import_i18n55 = __toESM(require_i18n(), 1);
17984 var import_components49 = __toESM(require_components(), 1);
17985
17986 // packages/media-fields/build-module/utils/get-raw-content.mjs
17987 function getRawContent(content) {
17988 if (!content) {
17989 return "";
17990 }
17991 if (typeof content === "string") {
17992 return content;
17993 }
17994 if (typeof content === "object" && "raw" in content) {
17995 return content.raw || "";
17996 }
17997 return "";
17998 }
17999
18000 // packages/media-fields/build-module/caption/index.mjs
18001 var import_jsx_runtime104 = __toESM(require_jsx_runtime(), 1);
18002 var captionField = {
18003 id: "caption",
18004 type: "text",
18005 label: (0, import_i18n55.__)("Caption"),
18006 getValue: ({ item }) => getRawContent(item?.caption),
18007 render: ({ item }) => getRawContent(item?.caption) || "-",
18008 Edit: ({ field, onChange, data }) => {
18009 return /* @__PURE__ */ (0, import_jsx_runtime104.jsx)(
18010 import_components49.TextareaControl,
18011 {
18012 label: field.label,
18013 value: getRawContent(data.caption) || "",
18014 onChange: (value) => onChange({ caption: value }),
18015 rows: 2
18016 }
18017 );
18018 },
18019 enableSorting: false,
18020 filterBy: false
18021 };
18022 var caption_default = captionField;
18023
18024 // packages/media-fields/build-module/date_added/index.mjs
18025 var import_i18n56 = __toESM(require_i18n(), 1);
18026 var import_date9 = __toESM(require_date(), 1);
18027 var dateAddedField = {
18028 id: "date",
18029 type: "datetime",
18030 label: (0, import_i18n56.__)("Date added"),
18031 filterBy: {
18032 operators: ["before", "after"]
18033 },
18034 format: {
18035 datetime: (0, import_date9.getSettings)().formats.datetimeAbbreviated
18036 },
18037 readOnly: true
18038 };
18039 var date_added_default = dateAddedField;
18040
18041 // packages/media-fields/build-module/date_modified/index.mjs
18042 var import_i18n57 = __toESM(require_i18n(), 1);
18043 var import_date10 = __toESM(require_date(), 1);
18044 var dateModifiedField = {
18045 id: "modified",
18046 type: "datetime",
18047 label: (0, import_i18n57.__)("Date modified"),
18048 filterBy: {
18049 operators: ["before", "after"]
18050 },
18051 format: {
18052 datetime: (0, import_date10.getSettings)().formats.datetimeAbbreviated
18053 },
18054 readOnly: true
18055 };
18056 var date_modified_default = dateModifiedField;
18057
18058 // packages/media-fields/build-module/description/index.mjs
18059 var import_i18n58 = __toESM(require_i18n(), 1);
18060 var import_components50 = __toESM(require_components(), 1);
18061 var import_jsx_runtime105 = __toESM(require_jsx_runtime(), 1);
18062 var descriptionField = {
18063 id: "description",
18064 type: "text",
18065 label: (0, import_i18n58.__)("Description"),
18066 getValue: ({ item }) => getRawContent(item?.description),
18067 render: ({ item }) => /* @__PURE__ */ (0, import_jsx_runtime105.jsx)("div", { children: getRawContent(item?.description) || "-" }),
18068 Edit: ({ field, onChange, data }) => {
18069 return /* @__PURE__ */ (0, import_jsx_runtime105.jsx)(
18070 import_components50.TextareaControl,
18071 {
18072 label: field.label,
18073 value: getRawContent(data.description) || "",
18074 onChange: (value) => onChange({ description: value }),
18075 rows: 5
18076 }
18077 );
18078 },
18079 enableSorting: false,
18080 filterBy: false
18081 };
18082 var description_default = descriptionField;
18083
18084 // packages/media-fields/build-module/filename/index.mjs
18085 var import_i18n59 = __toESM(require_i18n(), 1);
18086 var import_url4 = __toESM(require_url(), 1);
18087
18088 // packages/media-fields/build-module/filename/view.mjs
18089 var import_components51 = __toESM(require_components(), 1);
18090 var import_element60 = __toESM(require_element(), 1);
18091 var import_url3 = __toESM(require_url(), 1);
18092 var import_jsx_runtime106 = __toESM(require_jsx_runtime(), 1);
18093 var TRUNCATE_LENGTH = 15;
18094 function FileNameView({
18095 item
18096 }) {
18097 const fileName = (0, import_element60.useMemo)(
18098 () => item?.source_url ? (0, import_url3.getFilename)(item.source_url) : null,
18099 [item?.source_url]
18100 );
18101 if (!fileName) {
18102 return "";
18103 }
18104 return fileName.length > TRUNCATE_LENGTH ? /* @__PURE__ */ (0, import_jsx_runtime106.jsx)(import_components51.Tooltip, { text: fileName, children: /* @__PURE__ */ (0, import_jsx_runtime106.jsx)(import_components51.__experimentalTruncate, { limit: TRUNCATE_LENGTH, ellipsizeMode: "tail", children: fileName }) }) : /* @__PURE__ */ (0, import_jsx_runtime106.jsx)(import_jsx_runtime106.Fragment, { children: fileName });
18105 }
18106
18107 // packages/media-fields/build-module/filename/index.mjs
18108 var filenameField = {
18109 id: "filename",
18110 type: "text",
18111 label: (0, import_i18n59.__)("File name"),
18112 getValue: ({ item }) => (0, import_url4.getFilename)(item?.source_url || ""),
18113 render: FileNameView,
18114 enableSorting: false,
18115 filterBy: false,
18116 readOnly: true
18117 };
18118 var filename_default = filenameField;
18119
18120 // packages/media-fields/build-module/filesize/index.mjs
18121 var import_i18n60 = __toESM(require_i18n(), 1);
18122 var KB_IN_BYTES = 1024;
18123 var MB_IN_BYTES = 1024 * KB_IN_BYTES;
18124 var GB_IN_BYTES = 1024 * MB_IN_BYTES;
18125 var TB_IN_BYTES = 1024 * GB_IN_BYTES;
18126 var PB_IN_BYTES = 1024 * TB_IN_BYTES;
18127 var EB_IN_BYTES = 1024 * PB_IN_BYTES;
18128 var ZB_IN_BYTES = 1024 * EB_IN_BYTES;
18129 var YB_IN_BYTES = 1024 * ZB_IN_BYTES;
18130 function getBytesString(bytes, unitSymbol, decimals = 2) {
18131 return (0, import_i18n60.sprintf)(
18132 // translators: 1: Actual bytes of a file. 2: The unit symbol (e.g. MB).
18133 (0, import_i18n60._x)("%1$s %2$s", "file size"),
18134 bytes.toLocaleString(void 0, {
18135 minimumFractionDigits: 0,
18136 maximumFractionDigits: decimals
18137 }),
18138 unitSymbol
18139 );
18140 }
18141 function formatFileSize(bytes, decimals = 2) {
18142 if (bytes === 0) {
18143 return getBytesString(0, (0, import_i18n60._x)("B", "unit symbol"), decimals);
18144 }
18145 const quant = {
18146 /* translators: Unit symbol for yottabyte. */
18147 [(0, import_i18n60._x)("YB", "unit symbol")]: YB_IN_BYTES,
18148 /* translators: Unit symbol for zettabyte. */
18149 [(0, import_i18n60._x)("ZB", "unit symbol")]: ZB_IN_BYTES,
18150 /* translators: Unit symbol for exabyte. */
18151 [(0, import_i18n60._x)("EB", "unit symbol")]: EB_IN_BYTES,
18152 /* translators: Unit symbol for petabyte. */
18153 [(0, import_i18n60._x)("PB", "unit symbol")]: PB_IN_BYTES,
18154 /* translators: Unit symbol for terabyte. */
18155 [(0, import_i18n60._x)("TB", "unit symbol")]: TB_IN_BYTES,
18156 /* translators: Unit symbol for gigabyte. */
18157 [(0, import_i18n60._x)("GB", "unit symbol")]: GB_IN_BYTES,
18158 /* translators: Unit symbol for megabyte. */
18159 [(0, import_i18n60._x)("MB", "unit symbol")]: MB_IN_BYTES,
18160 /* translators: Unit symbol for kilobyte. */
18161 [(0, import_i18n60._x)("KB", "unit symbol")]: KB_IN_BYTES,
18162 /* translators: Unit symbol for byte. */
18163 [(0, import_i18n60._x)("B", "unit symbol")]: 1
18164 };
18165 for (const [unit, mag] of Object.entries(quant)) {
18166 if (bytes >= mag) {
18167 return getBytesString(bytes / mag, unit, decimals);
18168 }
18169 }
18170 return "";
18171 }
18172 var filesizeField = {
18173 id: "filesize",
18174 type: "text",
18175 label: (0, import_i18n60.__)("File size"),
18176 getValue: ({ item }) => item?.media_details?.filesize ? formatFileSize(item?.media_details?.filesize) : "",
18177 isVisible: (item) => {
18178 return !!item?.media_details?.filesize;
18179 },
18180 enableSorting: false,
18181 filterBy: false,
18182 readOnly: true
18183 };
18184 var filesize_default = filesizeField;
18185
18186 // packages/media-fields/build-module/media_dimensions/index.mjs
18187 var import_i18n61 = __toESM(require_i18n(), 1);
18188 var mediaDimensionsField = {
18189 id: "media_dimensions",
18190 type: "text",
18191 label: (0, import_i18n61.__)("Dimensions"),
18192 getValue: ({ item }) => item?.media_details?.width && item?.media_details?.height ? (0, import_i18n61.sprintf)(
18193 // translators: 1: Width. 2: Height.
18194 (0, import_i18n61._x)("%1$s \xD7 %2$s", "image dimensions"),
18195 item?.media_details?.width?.toString(),
18196 item?.media_details?.height?.toString()
18197 ) : "",
18198 isVisible: (item) => {
18199 return !!(item?.media_details?.width && item?.media_details?.height);
18200 },
18201 enableSorting: false,
18202 filterBy: false,
18203 readOnly: true
18204 };
18205 var media_dimensions_default = mediaDimensionsField;
18206
18207 // packages/media-fields/build-module/media_thumbnail/index.mjs
18208 var import_i18n63 = __toESM(require_i18n(), 1);
18209
18210 // packages/media-fields/build-module/media_thumbnail/view.mjs
18211 var import_data8 = __toESM(require_data(), 1);
18212 var import_core_data3 = __toESM(require_core_data(), 1);
18213 var import_components52 = __toESM(require_components(), 1);
18214 var import_element61 = __toESM(require_element(), 1);
18215 var import_url5 = __toESM(require_url(), 1);
18216
18217 // packages/media-fields/build-module/utils/get-media-type-from-mime-type.mjs
18218 var import_i18n62 = __toESM(require_i18n(), 1);
18219 function getMediaTypeFromMimeType(mimeType) {
18220 if (mimeType.startsWith("image/")) {
18221 return {
18222 type: "image",
18223 label: (0, import_i18n62.__)("Image"),
18224 icon: image_default
18225 };
18226 }
18227 if (mimeType.startsWith("video/")) {
18228 return {
18229 type: "video",
18230 label: (0, import_i18n62.__)("Video"),
18231 icon: video_default
18232 };
18233 }
18234 if (mimeType.startsWith("audio/")) {
18235 return {
18236 type: "audio",
18237 label: (0, import_i18n62.__)("Audio"),
18238 icon: audio_default
18239 };
18240 }
18241 return {
18242 type: "application",
18243 label: (0, import_i18n62.__)("Application"),
18244 icon: file_default
18245 };
18246 }
18247
18248 // packages/media-fields/build-module/media_thumbnail/view.mjs
18249 var import_jsx_runtime107 = __toESM(require_jsx_runtime(), 1);
18250 function getBestImageUrl(featuredMedia, configSizes) {
18251 const sizes = featuredMedia?.media_details?.sizes;
18252 if (!sizes) {
18253 return featuredMedia.source_url;
18254 }
18255 const sizeEntries = Object.values(sizes);
18256 if (!sizeEntries.length) {
18257 return featuredMedia.source_url;
18258 }
18259 const targetWidth = configSizes ? parseInt(configSizes, 10) : NaN;
18260 if (!Number.isNaN(targetWidth)) {
18261 const validEntries = sizeEntries.filter(
18262 (s2) => typeof s2.width === "number" && !Number.isNaN(s2.width)
18263 );
18264 if (!validEntries.length) {
18265 return featuredMedia.source_url;
18266 }
18267 const sorted = [...validEntries].sort(
18268 (a2, b2) => a2.width - b2.width
18269 );
18270 const match2 = sorted.find((s2) => s2.width >= targetWidth);
18271 if (match2) {
18272 return match2.source_url;
18273 }
18274 return sorted[sorted.length - 1].source_url;
18275 }
18276 return featuredMedia.source_url;
18277 }
18278 function FallbackView({
18279 item,
18280 filename
18281 }) {
18282 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)("div", { className: "dataviews-media-field__media-thumbnail", children: /* @__PURE__ */ (0, import_jsx_runtime107.jsxs)(
18283 import_components52.__experimentalVStack,
18284 {
18285 justify: "center",
18286 alignment: "center",
18287 className: "dataviews-media-field__media-thumbnail__stack",
18288 spacing: 0,
18289 children: [
18290 /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
18291 import_components52.Icon,
18292 {
18293 className: "dataviews-media-field__media-thumbnail--icon",
18294 icon: getMediaTypeFromMimeType(item.mime_type).icon,
18295 size: 24
18296 }
18297 ),
18298 !!filename && /* @__PURE__ */ (0, import_jsx_runtime107.jsx)("div", { className: "dataviews-media-field__media-thumbnail__filename", children: /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(import_components52.__experimentalTruncate, { className: "dataviews-media-field__media-thumbnail__filename__truncate", children: filename }) })
18299 ]
18300 }
18301 ) });
18302 }
18303 function ImageView({
18304 item,
18305 configSizes,
18306 onError
18307 }) {
18308 const imageUrl = getBestImageUrl(item, configSizes);
18309 const imgRef = (0, import_element61.useRef)(null);
18310 const [loadingState, setLoadingState] = (0, import_element61.useState)("loading");
18311 (0, import_element61.useLayoutEffect)(() => {
18312 if (imgRef.current?.complete) {
18313 setLoadingState("instant");
18314 } else {
18315 setLoadingState("loading");
18316 }
18317 }, [imageUrl]);
18318 const handleLoad = () => {
18319 if (loadingState === "loading") {
18320 setLoadingState("loaded");
18321 }
18322 };
18323 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
18324 "div",
18325 {
18326 className: clsx_default("dataviews-media-field__media-thumbnail", {
18327 "is-loading": loadingState === "loading",
18328 "is-loaded": loadingState === "loaded"
18329 }),
18330 children: /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
18331 "img",
18332 {
18333 ref: imgRef,
18334 className: "dataviews-media-field__media-thumbnail--image",
18335 src: imageUrl,
18336 alt: item.alt_text || item.title.raw,
18337 onLoad: handleLoad,
18338 onError,
18339 loading: "lazy"
18340 }
18341 )
18342 }
18343 );
18344 }
18345 function MediaThumbnailView({
18346 item,
18347 config
18348 }) {
18349 const [imageError, setImageError] = (0, import_element61.useState)(false);
18350 const _featuredMedia = (0, import_data8.useSelect)(
18351 (select) => {
18352 if (!item.featured_media) {
18353 return;
18354 }
18355 return select(import_core_data3.store).getEntityRecord(
18356 "postType",
18357 "attachment",
18358 item.featured_media
18359 );
18360 },
18361 [item.featured_media]
18362 );
18363 const featuredMedia = item.featured_media ? _featuredMedia : item;
18364 if (!featuredMedia) {
18365 return null;
18366 }
18367 const filename = (0, import_url5.getFilename)(featuredMedia.source_url || "");
18368 if (imageError || getMediaTypeFromMimeType(featuredMedia.mime_type).type !== "image") {
18369 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(FallbackView, { item: featuredMedia, filename: filename || "" });
18370 }
18371 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
18372 ImageView,
18373 {
18374 item: featuredMedia,
18375 configSizes: config?.sizes,
18376 onError: () => setImageError(true)
18377 }
18378 );
18379 }
18380
18381 // packages/media-fields/build-module/media_thumbnail/index.mjs
18382 var mediaThumbnailField = {
18383 id: "media_thumbnail",
18384 type: "media",
18385 label: (0, import_i18n63.__)("Thumbnail"),
18386 render: MediaThumbnailView,
18387 enableSorting: false,
18388 filterBy: false
18389 };
18390 var media_thumbnail_default = mediaThumbnailField;
18391
18392 // packages/media-fields/build-module/mime_type/index.mjs
18393 var import_i18n64 = __toESM(require_i18n(), 1);
18394 var mimeTypeField = {
18395 id: "mime_type",
18396 type: "text",
18397 label: (0, import_i18n64.__)("File type"),
18398 getValue: ({ item }) => item?.mime_type || "",
18399 render: ({ item }) => item?.mime_type || "-",
18400 // Disable sorting until REST API support for ordering my `mime_type` is added.
18401 // See: https://core.trac.wordpress.org/ticket/64073
18402 enableSorting: false,
18403 filterBy: false,
18404 readOnly: true
18405 };
18406 var mime_type_default = mimeTypeField;
18407
18408 // packages/media-utils/build-module/components/media-upload-modal/index.mjs
18409 var import_notices = __toESM(require_notices(), 1);
18410
18411 // packages/media-utils/build-module/lock-unlock.mjs
18412 var import_private_apis2 = __toESM(require_private_apis(), 1);
18413 var { lock: lock2, unlock: unlock2 } = (0, import_private_apis2.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
18414 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
18415 "@wordpress/media-utils"
18416 );
18417
18418 // packages/media-utils/build-module/components/media-upload-modal/upload-status-popover.mjs
18419 var import_element62 = __toESM(require_element(), 1);
18420 var import_i18n65 = __toESM(require_i18n(), 1);
18421 var import_components53 = __toESM(require_components(), 1);
18422 var import_jsx_runtime108 = __toESM(require_jsx_runtime(), 1);
18423 function UploadStatusPopover({
18424 uploadingFiles,
18425 onDismissError,
18426 onOpenChange
18427 }) {
18428 const [isOpen, setIsOpen] = (0, import_element62.useState)(false);
18429 const [prevHadErrors, setPrevHadErrors] = (0, import_element62.useState)(false);
18430 const triggerRef = (0, import_element62.useRef)(null);
18431 const updateIsOpen = (0, import_element62.useCallback)(
18432 (open) => {
18433 setIsOpen(open);
18434 onOpenChange?.(open);
18435 },
18436 [onOpenChange]
18437 );
18438 const activeFiles = uploadingFiles.filter(
18439 (file) => file.status === "uploading"
18440 );
18441 const errorFiles = uploadingFiles.filter(
18442 (file) => file.status === "error"
18443 );
18444 const hasErrors = errorFiles.length > 0;
18445 const isUploading = activeFiles.length > 0;
18446 (0, import_element62.useEffect)(() => {
18447 if (hasErrors && !prevHadErrors) {
18448 updateIsOpen(true);
18449 }
18450 setPrevHadErrors(hasErrors);
18451 }, [hasErrors, prevHadErrors, updateIsOpen]);
18452 if (uploadingFiles.length === 0) {
18453 return null;
18454 }
18455 let buttonLabel, popoverHeading;
18456 if (isUploading) {
18457 buttonLabel = (0, import_i18n65.sprintf)(
18458 // translators: %s: number of files being uploaded
18459 (0, import_i18n65._n)("Uploading %s file", "Uploading %s files", activeFiles.length),
18460 activeFiles.length.toLocaleString()
18461 );
18462 popoverHeading = (0, import_i18n65.__)("Uploading");
18463 } else if (hasErrors) {
18464 buttonLabel = (0, import_i18n65.sprintf)(
18465 // translators: %s: number of upload errors
18466 (0, import_i18n65._n)("%s upload error", "%s upload errors", errorFiles.length),
18467 errorFiles.length.toLocaleString()
18468 );
18469 popoverHeading = (0, import_i18n65.__)("Upload errors");
18470 } else {
18471 buttonLabel = (0, import_i18n65.__)("Upload complete");
18472 popoverHeading = (0, import_i18n65.__)("Upload complete");
18473 }
18474 return /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)("div", { className: "media-upload-modal__upload-status", children: [
18475 isUploading && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(import_components53.Spinner, {}),
18476 /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(
18477 import_components53.Button,
18478 {
18479 className: "media-upload-modal__upload-status__trigger",
18480 size: "compact",
18481 icon: chevron_down_default,
18482 iconPosition: "right",
18483 onClick: () => updateIsOpen(!isOpen),
18484 "aria-expanded": isOpen,
18485 ref: triggerRef,
18486 children: buttonLabel
18487 }
18488 ),
18489 isOpen && /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)(
18490 import_components53.Popover,
18491 {
18492 className: "media-upload-modal__upload-status__popover",
18493 placement: "top-start",
18494 offset: 8,
18495 anchor: triggerRef.current,
18496 focusOnMount: true,
18497 onClose: () => {
18498 if (triggerRef.current?.contains(
18499 triggerRef.current.ownerDocument.activeElement
18500 )) {
18501 return;
18502 }
18503 updateIsOpen(false);
18504 },
18505 children: [
18506 /* @__PURE__ */ (0, import_jsx_runtime108.jsx)("div", { className: "media-upload-modal__upload-status__header", children: /* @__PURE__ */ (0, import_jsx_runtime108.jsx)("h3", { children: popoverHeading }) }),
18507 /* @__PURE__ */ (0, import_jsx_runtime108.jsx)("ul", { className: "media-upload-modal__upload-status__list", children: uploadingFiles.map((file) => /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)(
18508 "li",
18509 {
18510 className: "media-upload-modal__upload-status__item",
18511 children: [
18512 file.status === "uploading" && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(import_components53.Spinner, {}),
18513 file.status === "uploaded" && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(import_components53.Icon, { icon: check_default, size: 16 }),
18514 (file.status === "uploading" || file.status === "uploaded") && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(
18515 "span",
18516 {
18517 className: "media-upload-modal__upload-status__filename",
18518 title: file.name,
18519 children: file.name
18520 }
18521 ),
18522 file.status === "error" && /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)(
18523 import_components53.Notice,
18524 {
18525 status: "error",
18526 isDismissible: !!onDismissError,
18527 onRemove: () => onDismissError?.(file.id),
18528 children: [
18529 file.name,
18530 ": ",
18531 file.error
18532 ]
18533 }
18534 )
18535 ]
18536 },
18537 file.id
18538 )) })
18539 ]
18540 }
18541 )
18542 ] });
18543 }
18544
18545 // packages/media-utils/build-module/components/media-upload-modal/use-invalidate-attachment-resolutions.mjs
18546 var import_element63 = __toESM(require_element(), 1);
18547 var import_core_data4 = __toESM(require_core_data(), 1);
18548 var import_data9 = __toESM(require_data(), 1);
18549 function useInvalidateAttachmentResolutions() {
18550 const registry = (0, import_data9.useRegistry)();
18551 return (0, import_element63.useCallback)(() => {
18552 const resolvers = registry.select(import_core_data4.store).getCachedResolvers();
18553 const entityRecordResolutions = resolvers.getEntityRecords;
18554 entityRecordResolutions?.forEach((_value, args) => {
18555 if (args[0] === "postType" && args[1] === "attachment") {
18556 registry.dispatch(import_core_data4.store).invalidateResolution("getEntityRecords", args);
18557 }
18558 });
18559 }, [registry]);
18560 }
18561
18562 // packages/media-utils/build-module/components/media-upload-modal/use-upload-status.mjs
18563 var import_element64 = __toESM(require_element(), 1);
18564 var import_blob2 = __toESM(require_blob(), 1);
18565 var idCounter = 0;
18566 var batchIdCounter = 0;
18567 function useUploadStatus({
18568 onBatchComplete
18569 } = {}) {
18570 const [uploadingFiles, setUploadingFiles] = (0, import_element64.useState)(
18571 []
18572 );
18573 const clearCompleted = (0, import_element64.useCallback)(() => {
18574 setUploadingFiles(
18575 (prev) => prev.filter((item) => item.status !== "uploaded")
18576 );
18577 }, []);
18578 const dismissError = (0, import_element64.useCallback)((fileId) => {
18579 setUploadingFiles(
18580 (prev) => prev.filter((item) => item.id !== fileId)
18581 );
18582 }, []);
18583 const registerBatch = (0, import_element64.useCallback)(
18584 (files) => {
18585 const batchId = String(++batchIdCounter);
18586 const batchSize = files.length;
18587 const newEntries = files.map((file) => ({
18588 id: String(++idCounter),
18589 batchId,
18590 name: file.name,
18591 status: "uploading"
18592 }));
18593 setUploadingFiles((prev) => [...prev, ...newEntries]);
18594 let successCount = 0;
18595 let errorCount = 0;
18596 let batchDone = false;
18597 let successAttachments = [];
18598 const completeBatchIfDone = () => {
18599 if (batchDone || successCount + errorCount < batchSize) {
18600 return;
18601 }
18602 batchDone = true;
18603 setUploadingFiles(
18604 (prev) => prev.map(
18605 (item) => item.batchId === batchId && item.status === "uploading" ? {
18606 ...item,
18607 status: "uploaded"
18608 } : item
18609 )
18610 );
18611 onBatchComplete?.(successAttachments);
18612 };
18613 const onFileChange = (attachments) => {
18614 if (batchDone) {
18615 return;
18616 }
18617 const allReal = attachments.every(
18618 (attachment) => attachment.id && attachment.url && !(0, import_blob2.isBlobURL)(attachment.url)
18619 );
18620 if (!allReal) {
18621 return;
18622 }
18623 successCount = attachments.length;
18624 successAttachments = attachments;
18625 completeBatchIfDone();
18626 };
18627 const onError = (error) => {
18628 const fileName = error instanceof UploadError ? error.file.name : void 0;
18629 setUploadingFiles((prev) => {
18630 let matched = false;
18631 return prev.map((item) => {
18632 if (!matched && item.batchId === batchId && item.status === "uploading" && (!fileName || item.name === fileName)) {
18633 matched = true;
18634 return {
18635 ...item,
18636 status: "error",
18637 error: error.message
18638 };
18639 }
18640 return item;
18641 });
18642 });
18643 errorCount++;
18644 completeBatchIfDone();
18645 };
18646 return { onFileChange, onError };
18647 },
18648 [onBatchComplete]
18649 );
18650 const allComplete = uploadingFiles.length > 0 && uploadingFiles.every((item) => item.status !== "uploading");
18651 return {
18652 uploadingFiles,
18653 registerBatch,
18654 dismissError,
18655 clearCompleted,
18656 allComplete
18657 };
18658 }
18659
18660 // packages/media-utils/build-module/components/media-upload-modal/index.mjs
18661 var import_jsx_runtime109 = __toESM(require_jsx_runtime(), 1);
18662 var { useEntityRecordsWithPermissions } = unlock2(import_core_data5.privateApis);
18663 var LAYOUT_PICKER_GRID2 = "pickerGrid";
18664 var LAYOUT_PICKER_TABLE2 = "pickerTable";
18665 var NOTICES_CONTEXT = "media-modal";
18666 var NOTICE_ID_UPLOAD_PROGRESS = "media-modal-upload-progress";
18667 function MediaUploadModal({
18668 allowedTypes,
18669 multiple = false,
18670 value,
18671 onSelect,
18672 onClose,
18673 onUpload,
18674 title = (0, import_i18n66.__)("Select Media"),
18675 isOpen,
18676 isDismissible = true,
18677 modalClass,
18678 search = true,
18679 searchLabel = (0, import_i18n66.__)("Search media")
18680 }) {
18681 const [selection, setSelection] = (0, import_element65.useState)(() => {
18682 if (!value) {
18683 return [];
18684 }
18685 return Array.isArray(value) ? value.map(String) : [String(value)];
18686 });
18687 const { createSuccessNotice, removeAllNotices } = (0, import_data10.useDispatch)(import_notices.store);
18688 const invalidateAttachmentResolutions = useInvalidateAttachmentResolutions();
18689 const [view, setView] = (0, import_element65.useState)(() => ({
18690 type: LAYOUT_PICKER_GRID2,
18691 fields: [],
18692 showTitle: false,
18693 titleField: "title",
18694 mediaField: "media_thumbnail",
18695 search: "",
18696 page: 1,
18697 perPage: 50,
18698 filters: [],
18699 layout: {
18700 previewSize: 170,
18701 density: "compact"
18702 }
18703 }));
18704 const queryArgs = (0, import_element65.useMemo)(() => {
18705 const filters = {};
18706 view.filters?.forEach((filter) => {
18707 if (filter.field === "media_type") {
18708 filters.media_type = filter.value;
18709 }
18710 if (filter.field === "author") {
18711 if (filter.operator === "isAny") {
18712 filters.author = filter.value;
18713 } else if (filter.operator === "isNone") {
18714 filters.author_exclude = filter.value;
18715 }
18716 }
18717 if (filter.field === "date" || filter.field === "modified") {
18718 if (filter.operator === "before") {
18719 filters.before = filter.value;
18720 } else if (filter.operator === "after") {
18721 filters.after = filter.value;
18722 }
18723 }
18724 if (filter.field === "mime_type") {
18725 filters.mime_type = filter.value;
18726 }
18727 });
18728 if (!filters.media_type) {
18729 filters.media_type = allowedTypes?.includes("*") ? void 0 : allowedTypes;
18730 }
18731 return {
18732 per_page: view.perPage || 20,
18733 page: view.page || 1,
18734 status: "inherit",
18735 order: view.sort?.direction,
18736 orderby: view.sort?.field,
18737 search: view.search,
18738 _embed: "author,wp:attached-to",
18739 ...filters
18740 };
18741 }, [view, allowedTypes]);
18742 const handleBatchComplete = (0, import_element65.useCallback)(
18743 (attachments) => {
18744 const uploadedIds = attachments.map((attachment) => String(attachment.id)).filter(Boolean);
18745 if (multiple) {
18746 setSelection((prev) => {
18747 const existing = new Set(prev);
18748 const newIds = uploadedIds.filter(
18749 (id) => !existing.has(id)
18750 );
18751 return [...prev, ...newIds];
18752 });
18753 } else {
18754 setSelection(uploadedIds.slice(0, 1));
18755 }
18756 invalidateAttachmentResolutions();
18757 },
18758 [multiple, invalidateAttachmentResolutions]
18759 );
18760 const {
18761 uploadingFiles,
18762 registerBatch,
18763 dismissError,
18764 clearCompleted,
18765 allComplete
18766 } = useUploadStatus({ onBatchComplete: handleBatchComplete });
18767 const isPopoverOpenRef = (0, import_element65.useRef)(false);
18768 const handlePopoverOpenChange = (0, import_element65.useCallback)(
18769 (open) => {
18770 isPopoverOpenRef.current = open;
18771 if (!open) {
18772 clearCompleted();
18773 }
18774 },
18775 [clearCompleted]
18776 );
18777 const {
18778 records: mediaRecords,
18779 isResolving: isLoading,
18780 totalItems,
18781 totalPages
18782 } = useEntityRecordsWithPermissions("postType", "attachment", queryArgs);
18783 const fields = (0, import_element65.useMemo)(
18784 () => [
18785 // Media field definitions from @wordpress/media-fields
18786 // Cast is safe because RestAttachment has the same properties as Attachment
18787 {
18788 ...media_thumbnail_default,
18789 enableHiding: false
18790 // Within the modal, the thumbnail should always be shown.
18791 },
18792 {
18793 id: "title",
18794 type: "text",
18795 label: (0, import_i18n66.__)("Title"),
18796 getValue: ({ item }) => {
18797 const titleValue = item.title.raw || item.title.rendered;
18798 return titleValue || (0, import_i18n66.__)("(no title)");
18799 }
18800 },
18801 alt_text_default,
18802 caption_default,
18803 description_default,
18804 date_added_default,
18805 date_modified_default,
18806 author_default,
18807 filename_default,
18808 filesize_default,
18809 media_dimensions_default,
18810 mime_type_default,
18811 attached_to_default
18812 ],
18813 []
18814 );
18815 const actions = (0, import_element65.useMemo)(
18816 () => [
18817 {
18818 id: "select",
18819 label: (0, import_i18n66.__)("Select"),
18820 isPrimary: true,
18821 supportsBulk: multiple,
18822 async callback() {
18823 if (selection.length === 0) {
18824 return;
18825 }
18826 const selectedPostsQuery = {
18827 include: selection,
18828 per_page: -1
18829 };
18830 const selectedPosts = await (0, import_data10.resolveSelect)(
18831 import_core_data5.store
18832 ).getEntityRecords(
18833 "postType",
18834 "attachment",
18835 selectedPostsQuery
18836 );
18837 const transformedPosts = (selectedPosts ?? []).map(transformAttachment).filter(Boolean);
18838 const selectedItems = multiple ? transformedPosts : transformedPosts?.[0];
18839 removeAllNotices("snackbar", NOTICES_CONTEXT);
18840 onSelect(selectedItems);
18841 }
18842 }
18843 ],
18844 [multiple, onSelect, selection, removeAllNotices]
18845 );
18846 const handleModalClose = (0, import_element65.useCallback)(() => {
18847 removeAllNotices("snackbar", NOTICES_CONTEXT);
18848 onClose?.();
18849 }, [removeAllNotices, onClose]);
18850 const handleUpload = onUpload || uploadMedia;
18851 const prevAllCompleteRef = (0, import_element65.useRef)(false);
18852 (0, import_element65.useEffect)(() => {
18853 if (allComplete && !prevAllCompleteRef.current) {
18854 const completeCount = uploadingFiles.filter(
18855 (file) => file.status === "uploaded"
18856 ).length;
18857 if (completeCount > 0) {
18858 createSuccessNotice(
18859 (0, import_i18n66.sprintf)(
18860 // translators: %s: number of files
18861 (0, import_i18n66._n)(
18862 "Uploaded %s file",
18863 "Uploaded %s files",
18864 completeCount
18865 ),
18866 completeCount.toLocaleString()
18867 ),
18868 {
18869 type: "snackbar",
18870 context: NOTICES_CONTEXT,
18871 id: NOTICE_ID_UPLOAD_PROGRESS
18872 }
18873 );
18874 }
18875 if (!isPopoverOpenRef.current) {
18876 clearCompleted();
18877 }
18878 }
18879 prevAllCompleteRef.current = allComplete;
18880 }, [allComplete, uploadingFiles, createSuccessNotice, clearCompleted]);
18881 const handleFileSelect = (0, import_element65.useCallback)(
18882 (event) => {
18883 const files = event.target.files;
18884 if (files && files.length > 0) {
18885 const filesArray = Array.from(files);
18886 const { onFileChange, onError } = registerBatch(filesArray);
18887 handleUpload({
18888 allowedTypes,
18889 filesList: filesArray,
18890 onFileChange,
18891 onError
18892 });
18893 }
18894 },
18895 [allowedTypes, handleUpload, registerBatch]
18896 );
18897 const paginationInfo = (0, import_element65.useMemo)(
18898 () => ({
18899 totalItems,
18900 totalPages
18901 }),
18902 [totalItems, totalPages]
18903 );
18904 const defaultLayouts = (0, import_element65.useMemo)(
18905 () => ({
18906 [LAYOUT_PICKER_GRID2]: {
18907 fields: [],
18908 showTitle: false
18909 },
18910 [LAYOUT_PICKER_TABLE2]: {
18911 fields: [
18912 "filename",
18913 "filesize",
18914 "media_dimensions",
18915 "author",
18916 "date"
18917 ],
18918 showTitle: true
18919 }
18920 }),
18921 []
18922 );
18923 const acceptTypes = (0, import_element65.useMemo)(() => {
18924 if (allowedTypes?.includes("*")) {
18925 return void 0;
18926 }
18927 return allowedTypes?.join(",");
18928 }, [allowedTypes]);
18929 if (!isOpen) {
18930 return null;
18931 }
18932 return /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
18933 import_components54.Modal,
18934 {
18935 title,
18936 onRequestClose: handleModalClose,
18937 isDismissible,
18938 className: modalClass,
18939 overlayClassName: "media-upload-modal",
18940 size: "fill",
18941 headerActions: /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
18942 import_components54.FormFileUpload,
18943 {
18944 accept: acceptTypes,
18945 multiple: true,
18946 onChange: handleFileSelect,
18947 __next40pxDefaultSize: true,
18948 render: ({ openFileDialog }) => /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
18949 import_components54.Button,
18950 {
18951 onClick: openFileDialog,
18952 icon: upload_default,
18953 __next40pxDefaultSize: true,
18954 children: (0, import_i18n66.__)("Upload media")
18955 }
18956 )
18957 }
18958 ),
18959 children: [
18960 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
18961 import_components54.DropZone,
18962 {
18963 onFilesDrop: (files) => {
18964 let filteredFiles = files;
18965 if (allowedTypes && !allowedTypes.includes("*")) {
18966 filteredFiles = files.filter(
18967 (file) => allowedTypes.some((allowedType) => {
18968 return file.type === allowedType || file.type.startsWith(
18969 allowedType.replace("*", "")
18970 );
18971 })
18972 );
18973 }
18974 if (filteredFiles.length > 0) {
18975 const { onFileChange, onError } = registerBatch(filteredFiles);
18976 handleUpload({
18977 allowedTypes,
18978 filesList: filteredFiles,
18979 onFileChange,
18980 onError
18981 });
18982 }
18983 },
18984 label: (0, import_i18n66.__)("Drop files to upload")
18985 }
18986 ),
18987 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
18988 dataviews_picker_default,
18989 {
18990 data: mediaRecords || [],
18991 fields,
18992 view,
18993 onChangeView: setView,
18994 actions,
18995 selection,
18996 onChangeSelection: setSelection,
18997 isLoading,
18998 paginationInfo,
18999 defaultLayouts,
19000 getItemId: (item) => String(item.id),
19001 itemListLabel: (0, import_i18n66.__)("Media items"),
19002 children: [
19003 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19004 Stack,
19005 {
19006 direction: "row",
19007 align: "top",
19008 justify: "space-between",
19009 className: "dataviews__view-actions",
19010 gap: "xs",
19011 children: [
19012 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19013 Stack,
19014 {
19015 direction: "row",
19016 gap: "sm",
19017 justify: "start",
19018 className: "dataviews__search",
19019 children: [
19020 search && /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.Search, { label: searchLabel }),
19021 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.FiltersToggle, {})
19022 ]
19023 }
19024 ),
19025 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(Stack, { direction: "row", gap: "xs", style: { flexShrink: 0 }, children: [
19026 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.LayoutSwitcher, {}),
19027 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.ViewConfig, {})
19028 ] })
19029 ]
19030 }
19031 ),
19032 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.FiltersToggled, { className: "dataviews-filters__container" }),
19033 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.Layout, {}),
19034 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19035 "div",
19036 {
19037 className: clsx_default("media-upload-modal__footer", {
19038 "is-uploading": uploadingFiles.length > 0
19039 }),
19040 children: [
19041 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19042 UploadStatusPopover,
19043 {
19044 uploadingFiles,
19045 onDismissError: dismissError,
19046 onOpenChange: handlePopoverOpenChange
19047 }
19048 ),
19049 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.BulkActionToolbar, {})
19050 ]
19051 }
19052 )
19053 ]
19054 }
19055 ),
19056 (0, import_element65.createPortal)(
19057 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19058 import_notices.SnackbarNotices,
19059 {
19060 className: "media-upload-modal__snackbar",
19061 context: NOTICES_CONTEXT
19062 }
19063 ),
19064 document.body
19065 )
19066 ]
19067 }
19068 );
19069 }
19070
19071 // packages/media-utils/build-module/private-apis.mjs
19072 var privateApis12 = {};
19073 lock2(privateApis12, {
19074 sideloadMedia,
19075 MediaUploadModal
19076 });
19077 return __toCommonJS(index_exports);
19078 })();
19079 /*! Bundled license information:
19080
19081 use-sync-external-store/cjs/use-sync-external-store-shim.development.js:
19082 (**
19083 * @license React
19084 * use-sync-external-store-shim.development.js
19085 *
19086 * Copyright (c) Meta Platforms, Inc. and affiliates.
19087 *
19088 * This source code is licensed under the MIT license found in the
19089 * LICENSE file in the root directory of this source tree.
19090 *)
19091 */
19092 //# sourceMappingURL=index.js.map
19093