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

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

19,805 lines 697.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2 var wp;
3 (wp ||= {}).mediaUtils = (() => {
4 var __create = Object.create;
5 var __defProp = Object.defineProperty;
6 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7 var __getOwnPropNames = Object.getOwnPropertyNames;
8 var __getProtoOf = Object.getPrototypeOf;
9 var __hasOwnProp = Object.prototype.hasOwnProperty;
10 var __commonJS = (cb, mod) => function __require() {
11 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12 };
13 var __export = (target, all) => {
14 for (var name in all)
15 __defProp(target, name, { get: all[name], enumerable: true });
16 };
17 var __copyProps = (to, from, except, desc) => {
18 if (from && typeof from === "object" || typeof from === "function") {
19 for (let key of __getOwnPropNames(from))
20 if (!__hasOwnProp.call(to, key) && key !== except)
21 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22 }
23 return to;
24 };
25 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26 // If the importer is in node compatibility mode or this is not an ESM
27 // file that has been converted to a CommonJS file using a Babel-
28 // compatible transform (i.e. "__esModule" has not been set), then set
29 // "default" to the CommonJS "module.exports" for node compatibility.
30 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31 mod
32 ));
33 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
35 // package-external:@wordpress/element
36 var require_element = __commonJS({
37 "package-external:@wordpress/element"(exports, module) {
38 module.exports = window.wp.element;
39 }
40 });
41
42 // package-external:@wordpress/i18n
43 var require_i18n = __commonJS({
44 "package-external:@wordpress/i18n"(exports, module) {
45 module.exports = window.wp.i18n;
46 }
47 });
48
49 // package-external:@wordpress/blob
50 var require_blob = __commonJS({
51 "package-external:@wordpress/blob"(exports, module) {
52 module.exports = window.wp.blob;
53 }
54 });
55
56 // package-external:@wordpress/api-fetch
57 var require_api_fetch = __commonJS({
58 "package-external:@wordpress/api-fetch"(exports, module) {
59 module.exports = window.wp.apiFetch;
60 }
61 });
62
63 // package-external:@wordpress/core-data
64 var require_core_data = __commonJS({
65 "package-external:@wordpress/core-data"(exports, module) {
66 module.exports = window.wp.coreData;
67 }
68 });
69
70 // package-external:@wordpress/data
71 var require_data = __commonJS({
72 "package-external:@wordpress/data"(exports, module) {
73 module.exports = window.wp.data;
74 }
75 });
76
77 // package-external:@wordpress/components
78 var require_components = __commonJS({
79 "package-external:@wordpress/components"(exports, module) {
80 module.exports = window.wp.components;
81 }
82 });
83
84 // package-external:@wordpress/primitives
85 var require_primitives = __commonJS({
86 "package-external:@wordpress/primitives"(exports, module) {
87 module.exports = window.wp.primitives;
88 }
89 });
90
91 // vendor-external:react/jsx-runtime
92 var require_jsx_runtime = __commonJS({
93 "vendor-external:react/jsx-runtime"(exports, module) {
94 module.exports = window.ReactJSXRuntime;
95 }
96 });
97
98 // package-external:@wordpress/compose
99 var require_compose = __commonJS({
100 "package-external:@wordpress/compose"(exports, module) {
101 module.exports = window.wp.compose;
102 }
103 });
104
105 // vendor-external:react
106 var require_react = __commonJS({
107 "vendor-external:react"(exports, module) {
108 module.exports = window.React;
109 }
110 });
111
112 // vendor-external:react-dom
113 var require_react_dom = __commonJS({
114 "vendor-external:react-dom"(exports, module) {
115 module.exports = window.ReactDOM;
116 }
117 });
118
119 // node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js
120 var require_use_sync_external_store_shim_development = __commonJS({
121 "node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js"(exports) {
122 "use strict";
123 (function() {
124 function is(x2, y2) {
125 return x2 === y2 && (0 !== x2 || 1 / x2 === 1 / y2) || x2 !== x2 && y2 !== y2;
126 }
127 function useSyncExternalStore$2(subscribe2, getSnapshot) {
128 didWarnOld18Alpha || void 0 === React8.startTransition || (didWarnOld18Alpha = true, console.error(
129 "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
130 ));
131 var value = getSnapshot();
132 if (!didWarnUncachedGetSnapshot) {
133 var cachedValue = getSnapshot();
134 objectIs(value, cachedValue) || (console.error(
135 "The result of getSnapshot should be cached to avoid an infinite loop"
136 ), didWarnUncachedGetSnapshot = true);
137 }
138 cachedValue = useState31({
139 inst: { value, getSnapshot }
140 });
141 var inst = cachedValue[0].inst, forceUpdate = cachedValue[1];
142 useLayoutEffect4(
143 function() {
144 inst.value = value;
145 inst.getSnapshot = getSnapshot;
146 checkIfSnapshotChanged(inst) && forceUpdate({ inst });
147 },
148 [subscribe2, value, getSnapshot]
149 );
150 useEffect25(
151 function() {
152 checkIfSnapshotChanged(inst) && forceUpdate({ inst });
153 return subscribe2(function() {
154 checkIfSnapshotChanged(inst) && forceUpdate({ inst });
155 });
156 },
157 [subscribe2]
158 );
159 useDebugValue(value);
160 return value;
161 }
162 function checkIfSnapshotChanged(inst) {
163 var latestGetSnapshot = inst.getSnapshot;
164 inst = inst.value;
165 try {
166 var nextValue = latestGetSnapshot();
167 return !objectIs(inst, nextValue);
168 } catch (error) {
169 return true;
170 }
171 }
172 function useSyncExternalStore$1(subscribe2, getSnapshot) {
173 return getSnapshot();
174 }
175 "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
176 var React8 = require_react(), objectIs = "function" === typeof Object.is ? Object.is : is, useState31 = React8.useState, useEffect25 = React8.useEffect, useLayoutEffect4 = React8.useLayoutEffect, useDebugValue = React8.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
177 exports.useSyncExternalStore = void 0 !== React8.useSyncExternalStore ? React8.useSyncExternalStore : shim;
178 "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
179 })();
180 }
181 });
182
183 // node_modules/use-sync-external-store/shim/index.js
184 var require_shim = __commonJS({
185 "node_modules/use-sync-external-store/shim/index.js"(exports, module) {
186 "use strict";
187 if (false) {
188 module.exports = null;
189 } else {
190 module.exports = require_use_sync_external_store_shim_development();
191 }
192 }
193 });
194
195 // package-external:@wordpress/private-apis
196 var require_private_apis = __commonJS({
197 "package-external:@wordpress/private-apis"(exports, module) {
198 module.exports = window.wp.privateApis;
199 }
200 });
201
202 // package-external:@wordpress/keycodes
203 var require_keycodes = __commonJS({
204 "package-external:@wordpress/keycodes"(exports, module) {
205 module.exports = window.wp.keycodes;
206 }
207 });
208
209 // node_modules/remove-accents/index.js
210 var require_remove_accents = __commonJS({
211 "node_modules/remove-accents/index.js"(exports, module) {
212 var characterMap = {
213 "\xC0": "A",
214 "\xC1": "A",
215 "\xC2": "A",
216 "\xC3": "A",
217 "\xC4": "A",
218 "\xC5": "A",
219 "\u1EA4": "A",
220 "\u1EAE": "A",
221 "\u1EB2": "A",
222 "\u1EB4": "A",
223 "\u1EB6": "A",
224 "\xC6": "AE",
225 "\u1EA6": "A",
226 "\u1EB0": "A",
227 "\u0202": "A",
228 "\u1EA2": "A",
229 "\u1EA0": "A",
230 "\u1EA8": "A",
231 "\u1EAA": "A",
232 "\u1EAC": "A",
233 "\xC7": "C",
234 "\u1E08": "C",
235 "\xC8": "E",
236 "\xC9": "E",
237 "\xCA": "E",
238 "\xCB": "E",
239 "\u1EBE": "E",
240 "\u1E16": "E",
241 "\u1EC0": "E",
242 "\u1E14": "E",
243 "\u1E1C": "E",
244 "\u0206": "E",
245 "\u1EBA": "E",
246 "\u1EBC": "E",
247 "\u1EB8": "E",
248 "\u1EC2": "E",
249 "\u1EC4": "E",
250 "\u1EC6": "E",
251 "\xCC": "I",
252 "\xCD": "I",
253 "\xCE": "I",
254 "\xCF": "I",
255 "\u1E2E": "I",
256 "\u020A": "I",
257 "\u1EC8": "I",
258 "\u1ECA": "I",
259 "\xD0": "D",
260 "\xD1": "N",
261 "\xD2": "O",
262 "\xD3": "O",
263 "\xD4": "O",
264 "\xD5": "O",
265 "\xD6": "O",
266 "\xD8": "O",
267 "\u1ED0": "O",
268 "\u1E4C": "O",
269 "\u1E52": "O",
270 "\u020E": "O",
271 "\u1ECE": "O",
272 "\u1ECC": "O",
273 "\u1ED4": "O",
274 "\u1ED6": "O",
275 "\u1ED8": "O",
276 "\u1EDC": "O",
277 "\u1EDE": "O",
278 "\u1EE0": "O",
279 "\u1EDA": "O",
280 "\u1EE2": "O",
281 "\xD9": "U",
282 "\xDA": "U",
283 "\xDB": "U",
284 "\xDC": "U",
285 "\u1EE6": "U",
286 "\u1EE4": "U",
287 "\u1EEC": "U",
288 "\u1EEE": "U",
289 "\u1EF0": "U",
290 "\xDD": "Y",
291 "\xE0": "a",
292 "\xE1": "a",
293 "\xE2": "a",
294 "\xE3": "a",
295 "\xE4": "a",
296 "\xE5": "a",
297 "\u1EA5": "a",
298 "\u1EAF": "a",
299 "\u1EB3": "a",
300 "\u1EB5": "a",
301 "\u1EB7": "a",
302 "\xE6": "ae",
303 "\u1EA7": "a",
304 "\u1EB1": "a",
305 "\u0203": "a",
306 "\u1EA3": "a",
307 "\u1EA1": "a",
308 "\u1EA9": "a",
309 "\u1EAB": "a",
310 "\u1EAD": "a",
311 "\xE7": "c",
312 "\u1E09": "c",
313 "\xE8": "e",
314 "\xE9": "e",
315 "\xEA": "e",
316 "\xEB": "e",
317 "\u1EBF": "e",
318 "\u1E17": "e",
319 "\u1EC1": "e",
320 "\u1E15": "e",
321 "\u1E1D": "e",
322 "\u0207": "e",
323 "\u1EBB": "e",
324 "\u1EBD": "e",
325 "\u1EB9": "e",
326 "\u1EC3": "e",
327 "\u1EC5": "e",
328 "\u1EC7": "e",
329 "\xEC": "i",
330 "\xED": "i",
331 "\xEE": "i",
332 "\xEF": "i",
333 "\u1E2F": "i",
334 "\u020B": "i",
335 "\u1EC9": "i",
336 "\u1ECB": "i",
337 "\xF0": "d",
338 "\xF1": "n",
339 "\xF2": "o",
340 "\xF3": "o",
341 "\xF4": "o",
342 "\xF5": "o",
343 "\xF6": "o",
344 "\xF8": "o",
345 "\u1ED1": "o",
346 "\u1E4D": "o",
347 "\u1E53": "o",
348 "\u020F": "o",
349 "\u1ECF": "o",
350 "\u1ECD": "o",
351 "\u1ED5": "o",
352 "\u1ED7": "o",
353 "\u1ED9": "o",
354 "\u1EDD": "o",
355 "\u1EDF": "o",
356 "\u1EE1": "o",
357 "\u1EDB": "o",
358 "\u1EE3": "o",
359 "\xF9": "u",
360 "\xFA": "u",
361 "\xFB": "u",
362 "\xFC": "u",
363 "\u1EE7": "u",
364 "\u1EE5": "u",
365 "\u1EED": "u",
366 "\u1EEF": "u",
367 "\u1EF1": "u",
368 "\xFD": "y",
369 "\xFF": "y",
370 "\u0100": "A",
371 "\u0101": "a",
372 "\u0102": "A",
373 "\u0103": "a",
374 "\u0104": "A",
375 "\u0105": "a",
376 "\u0106": "C",
377 "\u0107": "c",
378 "\u0108": "C",
379 "\u0109": "c",
380 "\u010A": "C",
381 "\u010B": "c",
382 "\u010C": "C",
383 "\u010D": "c",
384 "C\u0306": "C",
385 "c\u0306": "c",
386 "\u010E": "D",
387 "\u010F": "d",
388 "\u0110": "D",
389 "\u0111": "d",
390 "\u0112": "E",
391 "\u0113": "e",
392 "\u0114": "E",
393 "\u0115": "e",
394 "\u0116": "E",
395 "\u0117": "e",
396 "\u0118": "E",
397 "\u0119": "e",
398 "\u011A": "E",
399 "\u011B": "e",
400 "\u011C": "G",
401 "\u01F4": "G",
402 "\u011D": "g",
403 "\u01F5": "g",
404 "\u011E": "G",
405 "\u011F": "g",
406 "\u0120": "G",
407 "\u0121": "g",
408 "\u0122": "G",
409 "\u0123": "g",
410 "\u0124": "H",
411 "\u0125": "h",
412 "\u0126": "H",
413 "\u0127": "h",
414 "\u1E2A": "H",
415 "\u1E2B": "h",
416 "\u0128": "I",
417 "\u0129": "i",
418 "\u012A": "I",
419 "\u012B": "i",
420 "\u012C": "I",
421 "\u012D": "i",
422 "\u012E": "I",
423 "\u012F": "i",
424 "\u0130": "I",
425 "\u0131": "i",
426 "\u0132": "IJ",
427 "\u0133": "ij",
428 "\u0134": "J",
429 "\u0135": "j",
430 "\u0136": "K",
431 "\u0137": "k",
432 "\u1E30": "K",
433 "\u1E31": "k",
434 "K\u0306": "K",
435 "k\u0306": "k",
436 "\u0139": "L",
437 "\u013A": "l",
438 "\u013B": "L",
439 "\u013C": "l",
440 "\u013D": "L",
441 "\u013E": "l",
442 "\u013F": "L",
443 "\u0140": "l",
444 "\u0141": "l",
445 "\u0142": "l",
446 "\u1E3E": "M",
447 "\u1E3F": "m",
448 "M\u0306": "M",
449 "m\u0306": "m",
450 "\u0143": "N",
451 "\u0144": "n",
452 "\u0145": "N",
453 "\u0146": "n",
454 "\u0147": "N",
455 "\u0148": "n",
456 "\u0149": "n",
457 "N\u0306": "N",
458 "n\u0306": "n",
459 "\u014C": "O",
460 "\u014D": "o",
461 "\u014E": "O",
462 "\u014F": "o",
463 "\u0150": "O",
464 "\u0151": "o",
465 "\u0152": "OE",
466 "\u0153": "oe",
467 "P\u0306": "P",
468 "p\u0306": "p",
469 "\u0154": "R",
470 "\u0155": "r",
471 "\u0156": "R",
472 "\u0157": "r",
473 "\u0158": "R",
474 "\u0159": "r",
475 "R\u0306": "R",
476 "r\u0306": "r",
477 "\u0212": "R",
478 "\u0213": "r",
479 "\u015A": "S",
480 "\u015B": "s",
481 "\u015C": "S",
482 "\u015D": "s",
483 "\u015E": "S",
484 "\u0218": "S",
485 "\u0219": "s",
486 "\u015F": "s",
487 "\u0160": "S",
488 "\u0161": "s",
489 "\u0162": "T",
490 "\u0163": "t",
491 "\u021B": "t",
492 "\u021A": "T",
493 "\u0164": "T",
494 "\u0165": "t",
495 "\u0166": "T",
496 "\u0167": "t",
497 "T\u0306": "T",
498 "t\u0306": "t",
499 "\u0168": "U",
500 "\u0169": "u",
501 "\u016A": "U",
502 "\u016B": "u",
503 "\u016C": "U",
504 "\u016D": "u",
505 "\u016E": "U",
506 "\u016F": "u",
507 "\u0170": "U",
508 "\u0171": "u",
509 "\u0172": "U",
510 "\u0173": "u",
511 "\u0216": "U",
512 "\u0217": "u",
513 "V\u0306": "V",
514 "v\u0306": "v",
515 "\u0174": "W",
516 "\u0175": "w",
517 "\u1E82": "W",
518 "\u1E83": "w",
519 "X\u0306": "X",
520 "x\u0306": "x",
521 "\u0176": "Y",
522 "\u0177": "y",
523 "\u0178": "Y",
524 "Y\u0306": "Y",
525 "y\u0306": "y",
526 "\u0179": "Z",
527 "\u017A": "z",
528 "\u017B": "Z",
529 "\u017C": "z",
530 "\u017D": "Z",
531 "\u017E": "z",
532 "\u017F": "s",
533 "\u0192": "f",
534 "\u01A0": "O",
535 "\u01A1": "o",
536 "\u01AF": "U",
537 "\u01B0": "u",
538 "\u01CD": "A",
539 "\u01CE": "a",
540 "\u01CF": "I",
541 "\u01D0": "i",
542 "\u01D1": "O",
543 "\u01D2": "o",
544 "\u01D3": "U",
545 "\u01D4": "u",
546 "\u01D5": "U",
547 "\u01D6": "u",
548 "\u01D7": "U",
549 "\u01D8": "u",
550 "\u01D9": "U",
551 "\u01DA": "u",
552 "\u01DB": "U",
553 "\u01DC": "u",
554 "\u1EE8": "U",
555 "\u1EE9": "u",
556 "\u1E78": "U",
557 "\u1E79": "u",
558 "\u01FA": "A",
559 "\u01FB": "a",
560 "\u01FC": "AE",
561 "\u01FD": "ae",
562 "\u01FE": "O",
563 "\u01FF": "o",
564 "\xDE": "TH",
565 "\xFE": "th",
566 "\u1E54": "P",
567 "\u1E55": "p",
568 "\u1E64": "S",
569 "\u1E65": "s",
570 "X\u0301": "X",
571 "x\u0301": "x",
572 "\u0403": "\u0413",
573 "\u0453": "\u0433",
574 "\u040C": "\u041A",
575 "\u045C": "\u043A",
576 "A\u030B": "A",
577 "a\u030B": "a",
578 "E\u030B": "E",
579 "e\u030B": "e",
580 "I\u030B": "I",
581 "i\u030B": "i",
582 "\u01F8": "N",
583 "\u01F9": "n",
584 "\u1ED2": "O",
585 "\u1ED3": "o",
586 "\u1E50": "O",
587 "\u1E51": "o",
588 "\u1EEA": "U",
589 "\u1EEB": "u",
590 "\u1E80": "W",
591 "\u1E81": "w",
592 "\u1EF2": "Y",
593 "\u1EF3": "y",
594 "\u0200": "A",
595 "\u0201": "a",
596 "\u0204": "E",
597 "\u0205": "e",
598 "\u0208": "I",
599 "\u0209": "i",
600 "\u020C": "O",
601 "\u020D": "o",
602 "\u0210": "R",
603 "\u0211": "r",
604 "\u0214": "U",
605 "\u0215": "u",
606 "B\u030C": "B",
607 "b\u030C": "b",
608 "\u010C\u0323": "C",
609 "\u010D\u0323": "c",
610 "\xCA\u030C": "E",
611 "\xEA\u030C": "e",
612 "F\u030C": "F",
613 "f\u030C": "f",
614 "\u01E6": "G",
615 "\u01E7": "g",
616 "\u021E": "H",
617 "\u021F": "h",
618 "J\u030C": "J",
619 "\u01F0": "j",
620 "\u01E8": "K",
621 "\u01E9": "k",
622 "M\u030C": "M",
623 "m\u030C": "m",
624 "P\u030C": "P",
625 "p\u030C": "p",
626 "Q\u030C": "Q",
627 "q\u030C": "q",
628 "\u0158\u0329": "R",
629 "\u0159\u0329": "r",
630 "\u1E66": "S",
631 "\u1E67": "s",
632 "V\u030C": "V",
633 "v\u030C": "v",
634 "W\u030C": "W",
635 "w\u030C": "w",
636 "X\u030C": "X",
637 "x\u030C": "x",
638 "Y\u030C": "Y",
639 "y\u030C": "y",
640 "A\u0327": "A",
641 "a\u0327": "a",
642 "B\u0327": "B",
643 "b\u0327": "b",
644 "\u1E10": "D",
645 "\u1E11": "d",
646 "\u0228": "E",
647 "\u0229": "e",
648 "\u0190\u0327": "E",
649 "\u025B\u0327": "e",
650 "\u1E28": "H",
651 "\u1E29": "h",
652 "I\u0327": "I",
653 "i\u0327": "i",
654 "\u0197\u0327": "I",
655 "\u0268\u0327": "i",
656 "M\u0327": "M",
657 "m\u0327": "m",
658 "O\u0327": "O",
659 "o\u0327": "o",
660 "Q\u0327": "Q",
661 "q\u0327": "q",
662 "U\u0327": "U",
663 "u\u0327": "u",
664 "X\u0327": "X",
665 "x\u0327": "x",
666 "Z\u0327": "Z",
667 "z\u0327": "z",
668 "\u0439": "\u0438",
669 "\u0419": "\u0418",
670 "\u0451": "\u0435",
671 "\u0401": "\u0415"
672 };
673 var chars = Object.keys(characterMap).join("|");
674 var allAccents = new RegExp(chars, "g");
675 var firstAccent = new RegExp(chars, "");
676 function matcher(match2) {
677 return characterMap[match2];
678 }
679 var removeAccents2 = function(string) {
680 return string.replace(allAccents, matcher);
681 };
682 var hasAccents = function(string) {
683 return !!string.match(firstAccent);
684 };
685 module.exports = removeAccents2;
686 module.exports.has = hasAccents;
687 module.exports.remove = removeAccents2;
688 }
689 });
690
691 // node_modules/fast-deep-equal/es6/index.js
692 var require_es6 = __commonJS({
693 "node_modules/fast-deep-equal/es6/index.js"(exports, module) {
694 "use strict";
695 module.exports = function equal(a2, b2) {
696 if (a2 === b2) return true;
697 if (a2 && b2 && typeof a2 == "object" && typeof b2 == "object") {
698 if (a2.constructor !== b2.constructor) return false;
699 var length, i2, keys;
700 if (Array.isArray(a2)) {
701 length = a2.length;
702 if (length != b2.length) return false;
703 for (i2 = length; i2-- !== 0; )
704 if (!equal(a2[i2], b2[i2])) return false;
705 return true;
706 }
707 if (a2 instanceof Map && b2 instanceof Map) {
708 if (a2.size !== b2.size) return false;
709 for (i2 of a2.entries())
710 if (!b2.has(i2[0])) return false;
711 for (i2 of a2.entries())
712 if (!equal(i2[1], b2.get(i2[0]))) return false;
713 return true;
714 }
715 if (a2 instanceof Set && b2 instanceof Set) {
716 if (a2.size !== b2.size) return false;
717 for (i2 of a2.entries())
718 if (!b2.has(i2[0])) return false;
719 return true;
720 }
721 if (ArrayBuffer.isView(a2) && ArrayBuffer.isView(b2)) {
722 length = a2.length;
723 if (length != b2.length) return false;
724 for (i2 = length; i2-- !== 0; )
725 if (a2[i2] !== b2[i2]) return false;
726 return true;
727 }
728 if (a2.constructor === RegExp) return a2.source === b2.source && a2.flags === b2.flags;
729 if (a2.valueOf !== Object.prototype.valueOf) return a2.valueOf() === b2.valueOf();
730 if (a2.toString !== Object.prototype.toString) return a2.toString() === b2.toString();
731 keys = Object.keys(a2);
732 length = keys.length;
733 if (length !== Object.keys(b2).length) return false;
734 for (i2 = length; i2-- !== 0; )
735 if (!Object.prototype.hasOwnProperty.call(b2, keys[i2])) return false;
736 for (i2 = length; i2-- !== 0; ) {
737 var key = keys[i2];
738 if (!equal(a2[key], b2[key])) return false;
739 }
740 return true;
741 }
742 return a2 !== a2 && b2 !== b2;
743 };
744 }
745 });
746
747 // package-external:@wordpress/date
748 var require_date = __commonJS({
749 "package-external:@wordpress/date"(exports, module) {
750 module.exports = window.wp.date;
751 }
752 });
753
754 // package-external:@wordpress/warning
755 var require_warning = __commonJS({
756 "package-external:@wordpress/warning"(exports, module) {
757 module.exports = window.wp.warning;
758 }
759 });
760
761 // package-external:@wordpress/preferences
762 var require_preferences = __commonJS({
763 "package-external:@wordpress/preferences"(exports, module) {
764 module.exports = window.wp.preferences;
765 }
766 });
767
768 // package-external:@wordpress/url
769 var require_url = __commonJS({
770 "package-external:@wordpress/url"(exports, module) {
771 module.exports = window.wp.url;
772 }
773 });
774
775 // package-external:@wordpress/notices
776 var require_notices = __commonJS({
777 "package-external:@wordpress/notices"(exports, module) {
778 module.exports = window.wp.notices;
779 }
780 });
781
782 // packages/media-utils/build-module/index.mjs
783 var index_exports = {};
784 __export(index_exports, {
785 MediaUpload: () => media_upload_default,
786 privateApis: () => privateApis12,
787 transformAttachment: () => transformAttachment,
788 uploadMedia: () => uploadMedia,
789 validateFileSize: () => validateFileSize,
790 validateMimeType: () => validateMimeType,
791 validateMimeTypeForUser: () => validateMimeTypeForUser
792 });
793
794 // packages/media-utils/build-module/components/media-upload/index.mjs
795 var import_element = __toESM(require_element(), 1);
796 var import_i18n = __toESM(require_i18n(), 1);
797 var DEFAULT_EMPTY_GALLERY = [];
798 var getFeaturedImageMediaFrame = () => {
799 const { wp } = window;
800 return wp.media.view.MediaFrame.Select.extend({
801 /**
802 * Enables the Set Featured Image Button.
803 *
804 * @param {Object} toolbar toolbar for featured image state
805 * @return {void}
806 */
807 featuredImageToolbar(toolbar) {
808 this.createSelectToolbar(toolbar, {
809 text: wp.media.view.l10n.setFeaturedImage,
810 state: this.options.state
811 });
812 },
813 /**
814 * Handle the edit state requirements of selected media item.
815 *
816 * @return {void}
817 */
818 editState() {
819 const selection = this.state("featured-image").get("selection");
820 const view = new wp.media.view.EditImage({
821 model: selection.single(),
822 controller: this
823 }).render();
824 this.content.set(view);
825 view.loadEditor();
826 },
827 /**
828 * Create the default states.
829 *
830 * @return {void}
831 */
832 createStates: function createStates() {
833 this.on(
834 "toolbar:create:featured-image",
835 this.featuredImageToolbar,
836 this
837 );
838 this.on("content:render:edit-image", this.editState, this);
839 this.states.add([
840 new wp.media.controller.FeaturedImage(),
841 new wp.media.controller.EditImage({
842 model: this.options.editImage
843 })
844 ]);
845 }
846 });
847 };
848 var getSingleMediaFrame = () => {
849 const { wp } = window;
850 return wp.media.view.MediaFrame.Select.extend({
851 /**
852 * Create the default states on the frame.
853 */
854 createStates() {
855 const options = this.options;
856 if (this.options.states) {
857 return;
858 }
859 this.states.add([
860 // Main states.
861 new wp.media.controller.Library({
862 library: wp.media.query(options.library),
863 multiple: options.multiple,
864 title: options.title,
865 priority: 20,
866 filterable: "uploaded"
867 // Allow filtering by uploaded images.
868 }),
869 new wp.media.controller.EditImage({
870 model: options.editImage
871 })
872 ]);
873 }
874 });
875 };
876 var getGalleryDetailsMediaFrame = () => {
877 const { wp } = window;
878 return wp.media.view.MediaFrame.Post.extend({
879 /**
880 * Set up gallery toolbar.
881 *
882 * @return {void}
883 */
884 galleryToolbar() {
885 const editing = this.state().get("editing");
886 this.toolbar.set(
887 new wp.media.view.Toolbar({
888 controller: this,
889 items: {
890 insert: {
891 style: "primary",
892 text: editing ? wp.media.view.l10n.updateGallery : wp.media.view.l10n.insertGallery,
893 priority: 80,
894 requires: { library: true },
895 /**
896 * @fires wp.media.controller.State#update
897 */
898 click() {
899 const controller = this.controller, state = controller.state();
900 controller.close();
901 state.trigger(
902 "update",
903 state.get("library")
904 );
905 controller.setState(controller.options.state);
906 controller.reset();
907 }
908 }
909 }
910 })
911 );
912 },
913 /**
914 * Handle the edit state requirements of selected media item.
915 *
916 * @return {void}
917 */
918 editState() {
919 const selection = this.state("gallery").get("selection");
920 const view = new wp.media.view.EditImage({
921 model: selection.single(),
922 controller: this
923 }).render();
924 this.content.set(view);
925 view.loadEditor();
926 },
927 /**
928 * Create the default states.
929 *
930 * @return {void}
931 */
932 createStates: function createStates() {
933 this.on("toolbar:create:main-gallery", this.galleryToolbar, this);
934 this.on("content:render:edit-image", this.editState, this);
935 this.states.add([
936 new wp.media.controller.Library({
937 id: "gallery",
938 title: wp.media.view.l10n.createGalleryTitle,
939 priority: 40,
940 toolbar: "main-gallery",
941 filterable: "uploaded",
942 multiple: "add",
943 editable: false,
944 library: wp.media.query({
945 type: "image",
946 ...this.options.library
947 })
948 }),
949 new wp.media.controller.EditImage({
950 model: this.options.editImage
951 }),
952 new wp.media.controller.GalleryEdit({
953 library: this.options.selection,
954 editing: this.options.editing,
955 menu: "gallery",
956 displaySettings: false,
957 multiple: true
958 }),
959 new wp.media.controller.GalleryAdd()
960 ]);
961 }
962 });
963 };
964 var slimImageObject = (img) => {
965 const attrSet = [
966 "sizes",
967 "mime",
968 "type",
969 "subtype",
970 "id",
971 "url",
972 "alt",
973 "link",
974 "caption"
975 ];
976 return attrSet.reduce((result, key) => {
977 if (img?.hasOwnProperty(key)) {
978 result[key] = img[key];
979 }
980 return result;
981 }, {});
982 };
983 var getAttachmentsCollection = (ids) => {
984 const { wp } = window;
985 return wp.media.query({
986 order: "ASC",
987 orderby: "post__in",
988 post__in: ids,
989 posts_per_page: -1,
990 query: true,
991 type: "image"
992 });
993 };
994 var MediaUpload = class extends import_element.Component {
995 constructor() {
996 super(...arguments);
997 this.openModal = this.openModal.bind(this);
998 this.onOpen = this.onOpen.bind(this);
999 this.onSelect = this.onSelect.bind(this);
1000 this.onUpdate = this.onUpdate.bind(this);
1001 this.onClose = this.onClose.bind(this);
1002 }
1003 initializeListeners() {
1004 this.frame.on("select", this.onSelect);
1005 this.frame.on("update", this.onUpdate);
1006 this.frame.on("open", this.onOpen);
1007 this.frame.on("close", this.onClose);
1008 }
1009 /**
1010 * Sets the Gallery frame and initializes listeners.
1011 *
1012 * @return {void}
1013 */
1014 buildAndSetGalleryFrame() {
1015 const {
1016 addToGallery = false,
1017 allowedTypes,
1018 multiple = false,
1019 value = DEFAULT_EMPTY_GALLERY
1020 } = this.props;
1021 if (value === this.lastGalleryValue) {
1022 return;
1023 }
1024 const { wp } = window;
1025 this.lastGalleryValue = value;
1026 if (this.frame) {
1027 this.frame.remove();
1028 }
1029 let currentState;
1030 if (addToGallery) {
1031 currentState = "gallery-library";
1032 } else {
1033 currentState = value && value.length ? "gallery-edit" : "gallery";
1034 }
1035 if (!this.GalleryDetailsMediaFrame) {
1036 this.GalleryDetailsMediaFrame = getGalleryDetailsMediaFrame();
1037 }
1038 const attachments = getAttachmentsCollection(value);
1039 const selection = new wp.media.model.Selection(attachments.models, {
1040 props: attachments.props.toJSON(),
1041 multiple
1042 });
1043 this.frame = new this.GalleryDetailsMediaFrame({
1044 mimeType: allowedTypes,
1045 state: currentState,
1046 multiple,
1047 selection,
1048 editing: !!value?.length
1049 });
1050 wp.media.frame = this.frame;
1051 this.initializeListeners();
1052 }
1053 /**
1054 * Initializes the Media Library requirements for the featured image flow.
1055 *
1056 * @return {void}
1057 */
1058 buildAndSetFeatureImageFrame() {
1059 const { wp } = window;
1060 const { value: featuredImageId, multiple, allowedTypes } = this.props;
1061 const featuredImageFrame = getFeaturedImageMediaFrame();
1062 const attachments = getAttachmentsCollection(featuredImageId);
1063 const selection = new wp.media.model.Selection(attachments.models, {
1064 props: attachments.props.toJSON()
1065 });
1066 this.frame = new featuredImageFrame({
1067 mimeType: allowedTypes,
1068 state: "featured-image",
1069 multiple,
1070 selection,
1071 editing: featuredImageId
1072 });
1073 wp.media.frame = this.frame;
1074 wp.media.view.settings.post = {
1075 ...wp.media.view.settings.post,
1076 featuredImageId: featuredImageId || -1
1077 };
1078 }
1079 /**
1080 * Initializes the Media Library requirements for the single image flow.
1081 *
1082 * @return {void}
1083 */
1084 buildAndSetSingleMediaFrame() {
1085 const { wp } = window;
1086 const {
1087 allowedTypes,
1088 multiple = false,
1089 title = (0, import_i18n.__)("Select or Upload Media"),
1090 value
1091 } = this.props;
1092 const frameConfig = {
1093 title,
1094 multiple
1095 };
1096 if (!!allowedTypes) {
1097 frameConfig.library = { type: allowedTypes };
1098 }
1099 if (this.frame) {
1100 this.frame.remove();
1101 }
1102 const singleImageFrame = getSingleMediaFrame();
1103 const attachments = getAttachmentsCollection(value);
1104 const selection = new wp.media.model.Selection(attachments.models, {
1105 props: attachments.props.toJSON()
1106 });
1107 this.frame = new singleImageFrame({
1108 mimeType: allowedTypes,
1109 multiple,
1110 selection,
1111 ...frameConfig
1112 });
1113 wp.media.frame = this.frame;
1114 }
1115 componentWillUnmount() {
1116 this.frame?.remove();
1117 }
1118 onUpdate(selections) {
1119 const { onSelect, multiple = false } = this.props;
1120 const state = this.frame.state();
1121 const selectedImages = selections || state.get("selection");
1122 if (!selectedImages || !selectedImages.models.length) {
1123 return;
1124 }
1125 if (multiple) {
1126 onSelect(
1127 selectedImages.models.map(
1128 (model) => slimImageObject(model.toJSON())
1129 )
1130 );
1131 } else {
1132 onSelect(slimImageObject(selectedImages.models[0].toJSON()));
1133 }
1134 }
1135 onSelect() {
1136 const { onSelect, multiple = false } = this.props;
1137 const attachment = this.frame.state().get("selection").toJSON();
1138 onSelect(multiple ? attachment : attachment[0]);
1139 }
1140 onOpen() {
1141 const { wp } = window;
1142 const { value } = this.props;
1143 this.updateCollection();
1144 if (this.props.mode) {
1145 this.frame.content.mode(this.props.mode);
1146 }
1147 const hasMedia = Array.isArray(value) ? !!value?.length : !!value;
1148 if (!hasMedia) {
1149 return;
1150 }
1151 const isGallery = this.props.gallery;
1152 const selection = this.frame.state().get("selection");
1153 const valueArray = Array.isArray(value) ? value : [value];
1154 if (!isGallery) {
1155 valueArray.forEach((id) => {
1156 selection.add(wp.media.attachment(id));
1157 });
1158 }
1159 const attachments = getAttachmentsCollection(valueArray);
1160 attachments.more().done(function() {
1161 if (isGallery && attachments?.models?.length) {
1162 selection.add(attachments.models);
1163 }
1164 });
1165 }
1166 onClose() {
1167 const { onClose } = this.props;
1168 if (onClose) {
1169 onClose();
1170 }
1171 this.frame.detach();
1172 }
1173 updateCollection() {
1174 const frameContent = this.frame.content.get();
1175 if (frameContent && frameContent.collection) {
1176 const collection = frameContent.collection;
1177 collection.toArray().forEach((model) => model.trigger("destroy", model));
1178 collection.mirroring._hasMore = true;
1179 collection.more();
1180 }
1181 }
1182 openModal() {
1183 const {
1184 gallery = false,
1185 unstableFeaturedImageFlow = false,
1186 modalClass
1187 } = this.props;
1188 if (gallery) {
1189 this.buildAndSetGalleryFrame();
1190 } else {
1191 this.buildAndSetSingleMediaFrame();
1192 }
1193 if (modalClass) {
1194 this.frame.$el.addClass(modalClass);
1195 }
1196 if (unstableFeaturedImageFlow) {
1197 this.buildAndSetFeatureImageFrame();
1198 }
1199 this.initializeListeners();
1200 this.frame.open();
1201 }
1202 render() {
1203 return this.props.render({ open: this.openModal });
1204 }
1205 };
1206 var media_upload_default = MediaUpload;
1207
1208 // packages/media-utils/build-module/utils/upload-media.mjs
1209 var import_i18n5 = __toESM(require_i18n(), 1);
1210 var import_blob = __toESM(require_blob(), 1);
1211
1212 // packages/media-utils/build-module/utils/upload-to-server.mjs
1213 var import_api_fetch = __toESM(require_api_fetch(), 1);
1214
1215 // packages/media-utils/build-module/utils/flatten-form-data.mjs
1216 function isPlainObject(data) {
1217 return data !== null && typeof data === "object" && Object.getPrototypeOf(data) === Object.prototype;
1218 }
1219 function flattenFormData(formData, key, data) {
1220 if (isPlainObject(data)) {
1221 for (const [name, value] of Object.entries(data)) {
1222 flattenFormData(formData, `${key}[${name}]`, value);
1223 }
1224 } else if (data !== void 0) {
1225 formData.append(key, String(data));
1226 }
1227 }
1228
1229 // packages/media-utils/build-module/utils/transform-attachment.mjs
1230 function transformAttachment(attachment) {
1231 const { alt_text, source_url, ...savedMediaProps } = attachment;
1232 return {
1233 ...savedMediaProps,
1234 alt: attachment.alt_text,
1235 caption: attachment.caption?.raw ?? "",
1236 title: attachment.title.raw,
1237 url: attachment.source_url,
1238 poster: attachment._embedded?.["wp:featuredmedia"]?.[0]?.source_url || void 0
1239 };
1240 }
1241
1242 // packages/media-utils/build-module/utils/upload-to-server.mjs
1243 async function uploadToServer(file, additionalData = {}, signal) {
1244 const data = new FormData();
1245 data.append("file", file, file.name || file.type.replace("/", "."));
1246 for (const [key, value] of Object.entries(additionalData)) {
1247 flattenFormData(
1248 data,
1249 key,
1250 value
1251 );
1252 }
1253 return transformAttachment(
1254 await (0, import_api_fetch.default)({
1255 // This allows the video block to directly get a video's poster image.
1256 path: "/wp/v2/media?_embed=wp:featuredmedia",
1257 body: data,
1258 method: "POST",
1259 signal
1260 })
1261 );
1262 }
1263
1264 // packages/media-utils/build-module/utils/validate-mime-type.mjs
1265 var import_i18n2 = __toESM(require_i18n(), 1);
1266
1267 // packages/media-utils/build-module/utils/upload-error.mjs
1268 var UploadError = class extends Error {
1269 code;
1270 file;
1271 constructor({ code, message: message2, file, cause }) {
1272 super(message2, { cause });
1273 Object.setPrototypeOf(this, new.target.prototype);
1274 this.code = code;
1275 this.file = file;
1276 }
1277 };
1278
1279 // packages/media-utils/build-module/utils/validate-mime-type.mjs
1280 function validateMimeType(file, allowedTypes) {
1281 if (!allowedTypes || allowedTypes.includes("*")) {
1282 return;
1283 }
1284 const isAllowedType = allowedTypes.some((allowedType) => {
1285 if (allowedType.includes("/")) {
1286 return allowedType === file.type;
1287 }
1288 return file.type.startsWith(`${allowedType}/`);
1289 });
1290 if (file.type && !isAllowedType) {
1291 throw new UploadError({
1292 code: "MIME_TYPE_NOT_SUPPORTED",
1293 message: (0, import_i18n2.sprintf)(
1294 // translators: %s: file name.
1295 (0, import_i18n2.__)("%s: Sorry, this file type is not supported here."),
1296 file.name
1297 ),
1298 file
1299 });
1300 }
1301 }
1302
1303 // packages/media-utils/build-module/utils/validate-mime-type-for-user.mjs
1304 var import_i18n3 = __toESM(require_i18n(), 1);
1305
1306 // packages/media-utils/build-module/utils/get-mime-types-array.mjs
1307 function getMimeTypesArray(wpMimeTypesObject) {
1308 if (!wpMimeTypesObject) {
1309 return null;
1310 }
1311 return Object.entries(wpMimeTypesObject).flatMap(
1312 ([extensionsString, mime]) => {
1313 const [type] = mime.split("/");
1314 const extensions = extensionsString.split("|");
1315 return [
1316 mime,
1317 ...extensions.map(
1318 (extension) => `${type}/${extension}`
1319 )
1320 ];
1321 }
1322 );
1323 }
1324
1325 // packages/media-utils/build-module/utils/validate-mime-type-for-user.mjs
1326 function validateMimeTypeForUser(file, wpAllowedMimeTypes) {
1327 const allowedMimeTypesForUser = getMimeTypesArray(wpAllowedMimeTypes);
1328 if (!allowedMimeTypesForUser) {
1329 return;
1330 }
1331 const isAllowedMimeTypeForUser = allowedMimeTypesForUser.includes(
1332 file.type
1333 );
1334 if (file.type && !isAllowedMimeTypeForUser) {
1335 throw new UploadError({
1336 code: "MIME_TYPE_NOT_ALLOWED_FOR_USER",
1337 message: (0, import_i18n3.sprintf)(
1338 // translators: %s: file name.
1339 (0, import_i18n3.__)(
1340 "%s: Sorry, you are not allowed to upload this file type."
1341 ),
1342 file.name
1343 ),
1344 file
1345 });
1346 }
1347 }
1348
1349 // packages/media-utils/build-module/utils/validate-file-size.mjs
1350 var import_i18n4 = __toESM(require_i18n(), 1);
1351 function validateFileSize(file, maxUploadFileSize) {
1352 if (file.size <= 0) {
1353 throw new UploadError({
1354 code: "EMPTY_FILE",
1355 message: (0, import_i18n4.sprintf)(
1356 // translators: %s: file name.
1357 (0, import_i18n4.__)("%s: This file is empty."),
1358 file.name
1359 ),
1360 file
1361 });
1362 }
1363 if (maxUploadFileSize && file.size > maxUploadFileSize) {
1364 throw new UploadError({
1365 code: "SIZE_ABOVE_LIMIT",
1366 message: (0, import_i18n4.sprintf)(
1367 // translators: %s: file name.
1368 (0, import_i18n4.__)(
1369 "%s: This file exceeds the maximum upload size for this site."
1370 ),
1371 file.name
1372 ),
1373 file
1374 });
1375 }
1376 }
1377
1378 // packages/media-utils/build-module/utils/upload-media.mjs
1379 function uploadMedia({
1380 wpAllowedMimeTypes,
1381 allowedTypes,
1382 additionalData = {},
1383 filesList,
1384 maxUploadFileSize,
1385 onError,
1386 onFileChange,
1387 signal,
1388 multiple = true
1389 }) {
1390 if (!multiple && filesList.length > 1) {
1391 onError?.(new Error((0, import_i18n5.__)("Only one file can be used here.")));
1392 return;
1393 }
1394 const validFiles = [];
1395 const filesSet = [];
1396 const setAndUpdateFiles = (index, value) => {
1397 if (!window.__clientSideMediaProcessing) {
1398 if (filesSet[index]?.url) {
1399 (0, import_blob.revokeBlobURL)(filesSet[index].url);
1400 }
1401 }
1402 filesSet[index] = value;
1403 onFileChange?.(
1404 filesSet.filter((attachment) => attachment !== null)
1405 );
1406 };
1407 for (const mediaFile of filesList) {
1408 try {
1409 validateMimeTypeForUser(mediaFile, wpAllowedMimeTypes);
1410 } catch (error) {
1411 onError?.(error);
1412 continue;
1413 }
1414 try {
1415 validateMimeType(mediaFile, allowedTypes);
1416 } catch (error) {
1417 onError?.(error);
1418 continue;
1419 }
1420 try {
1421 validateFileSize(mediaFile, maxUploadFileSize);
1422 } catch (error) {
1423 onError?.(error);
1424 continue;
1425 }
1426 validFiles.push(mediaFile);
1427 if (!window.__clientSideMediaProcessing) {
1428 filesSet.push({ url: (0, import_blob.createBlobURL)(mediaFile) });
1429 onFileChange?.(filesSet);
1430 }
1431 }
1432 validFiles.map(async (file, index) => {
1433 try {
1434 const attachment = await uploadToServer(
1435 file,
1436 additionalData,
1437 signal
1438 );
1439 setAndUpdateFiles(index, attachment);
1440 } catch (error) {
1441 setAndUpdateFiles(index, null);
1442 let message2;
1443 if (typeof error === "object" && error !== null && "message" in error) {
1444 message2 = typeof error.message === "string" ? error.message : String(error.message);
1445 } else {
1446 message2 = (0, import_i18n5.sprintf)(
1447 // translators: %s: file name
1448 (0, import_i18n5.__)("Error while uploading file %s to the media library."),
1449 file.name
1450 );
1451 }
1452 onError?.(
1453 new UploadError({
1454 code: "GENERAL",
1455 message: message2,
1456 file,
1457 cause: error instanceof Error ? error : void 0
1458 })
1459 );
1460 }
1461 });
1462 }
1463
1464 // packages/media-utils/build-module/utils/sideload-media.mjs
1465 var import_i18n6 = __toESM(require_i18n(), 1);
1466
1467 // packages/media-utils/build-module/utils/sideload-to-server.mjs
1468 var import_api_fetch2 = __toESM(require_api_fetch(), 1);
1469 async function sideloadToServer(file, attachmentId, additionalData = {}, signal) {
1470 const data = new FormData();
1471 data.append("file", file, file.name || file.type.replace("/", "."));
1472 for (const [key, value] of Object.entries(additionalData)) {
1473 flattenFormData(
1474 data,
1475 key,
1476 value
1477 );
1478 }
1479 return (0, import_api_fetch2.default)({
1480 path: `/wp/v2/media/${attachmentId}/sideload`,
1481 body: data,
1482 method: "POST",
1483 signal
1484 });
1485 }
1486
1487 // packages/media-utils/build-module/utils/sideload-media.mjs
1488 var noop = () => {
1489 };
1490 async function sideloadMedia({
1491 file,
1492 attachmentId,
1493 additionalData = {},
1494 signal,
1495 onSuccess,
1496 onError = noop
1497 }) {
1498 try {
1499 const subSizeData = await sideloadToServer(
1500 file,
1501 attachmentId,
1502 additionalData,
1503 signal
1504 );
1505 onSuccess?.(subSizeData);
1506 } catch (error) {
1507 let message2;
1508 if (error instanceof Error) {
1509 message2 = error.message;
1510 } else {
1511 message2 = (0, import_i18n6.sprintf)(
1512 // translators: %s: file name
1513 (0, import_i18n6.__)("Error while sideloading file %s to the server."),
1514 file.name
1515 );
1516 }
1517 onError(
1518 new UploadError({
1519 code: "GENERAL",
1520 message: message2,
1521 file,
1522 cause: error instanceof Error ? error : void 0
1523 })
1524 );
1525 }
1526 }
1527
1528 // node_modules/clsx/dist/clsx.mjs
1529 function r(e2) {
1530 var t2, f2, n2 = "";
1531 if ("string" == typeof e2 || "number" == typeof e2) n2 += e2;
1532 else if ("object" == typeof e2) if (Array.isArray(e2)) {
1533 var o2 = e2.length;
1534 for (t2 = 0; t2 < o2; t2++) e2[t2] && (f2 = r(e2[t2])) && (n2 && (n2 += " "), n2 += f2);
1535 } else for (f2 in e2) e2[f2] && (n2 && (n2 += " "), n2 += f2);
1536 return n2;
1537 }
1538 function clsx() {
1539 for (var e2, t2, f2 = 0, n2 = "", o2 = arguments.length; f2 < o2; f2++) (e2 = arguments[f2]) && (t2 = r(e2)) && (n2 && (n2 += " "), n2 += t2);
1540 return n2;
1541 }
1542 var clsx_default = clsx;
1543
1544 // packages/media-utils/build-module/components/media-upload-modal/index.mjs
1545 var import_element68 = __toESM(require_element(), 1);
1546 var import_i18n66 = __toESM(require_i18n(), 1);
1547 var import_core_data6 = __toESM(require_core_data(), 1);
1548 var import_data13 = __toESM(require_data(), 1);
1549 var import_components53 = __toESM(require_components(), 1);
1550
1551 // packages/icons/build-module/library/arrow-down.mjs
1552 var import_primitives = __toESM(require_primitives(), 1);
1553 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
1554 var arrow_down_default = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.Path, { d: "m16.5 13.5-3.7 3.7V4h-1.5v13.2l-3.8-3.7-1 1 5.5 5.6 5.5-5.6z" }) });
1555
1556 // packages/icons/build-module/library/arrow-left.mjs
1557 var import_primitives2 = __toESM(require_primitives(), 1);
1558 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
1559 var arrow_left_default = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.Path, { d: "M20 11.2H6.8l3.7-3.7-1-1L3.9 12l5.6 5.5 1-1-3.7-3.7H20z" }) });
1560
1561 // packages/icons/build-module/library/arrow-right.mjs
1562 var import_primitives3 = __toESM(require_primitives(), 1);
1563 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
1564 var arrow_right_default = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.Path, { d: "m14.5 6.5-1 1 3.7 3.7H4v1.6h13.2l-3.7 3.7 1 1 5.6-5.5z" }) });
1565
1566 // packages/icons/build-module/library/arrow-up.mjs
1567 var import_primitives4 = __toESM(require_primitives(), 1);
1568 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
1569 var arrow_up_default = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.Path, { d: "M12 3.9 6.5 9.5l1 1 3.8-3.7V20h1.5V6.8l3.7 3.7 1-1z" }) });
1570
1571 // packages/icons/build-module/library/audio.mjs
1572 var import_primitives5 = __toESM(require_primitives(), 1);
1573 var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
1574 var audio_default = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.Path, { d: "M17.7 4.3c-1.2 0-2.8 0-3.8 1-.6.6-.9 1.5-.9 2.6V14c-.6-.6-1.5-1-2.5-1C8.6 13 7 14.6 7 16.5S8.6 20 10.5 20c1.5 0 2.8-1 3.3-2.3.5-.8.7-1.8.7-2.5V7.9c0-.7.2-1.2.5-1.6.6-.6 1.8-.6 2.8-.6h.3V4.3h-.4z" }) });
1575
1576 // packages/icons/build-module/library/block-table.mjs
1577 var import_primitives6 = __toESM(require_primitives(), 1);
1578 var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
1579 var block_table_default = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives6.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives6.Path, { d: "M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM5 4.5h14c.3 0 .5.2.5.5v3.5h-15V5c0-.3.2-.5.5-.5zm8 5.5h6.5v3.5H13V10zm-1.5 3.5h-7V10h7v3.5zm-7 5.5v-4h7v4.5H5c-.3 0-.5-.2-.5-.5zm14.5.5h-6V15h6.5v4c0 .3-.2.5-.5.5z" }) });
1580
1581 // packages/icons/build-module/library/category.mjs
1582 var import_primitives7 = __toESM(require_primitives(), 1);
1583 var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
1584 var category_default = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives7.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives7.Path, { fillRule: "evenodd", clipRule: "evenodd", d: "M6 5.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5H6a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM4 6a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2H6a2 2 0 01-2-2V6zm11-.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5h-3a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM13 6a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2h-3a2 2 0 01-2-2V6zm5 8.5h-3a.5.5 0 00-.5.5v3a.5.5 0 00.5.5h3a.5.5 0 00.5-.5v-3a.5.5 0 00-.5-.5zM15 13a2 2 0 00-2 2v3a2 2 0 002 2h3a2 2 0 002-2v-3a2 2 0 00-2-2h-3zm-9 1.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5H6a.5.5 0 01-.5-.5v-3a.5.5 0 01.5-.5zM4 15a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2H6a2 2 0 01-2-2v-3z" }) });
1585
1586 // packages/icons/build-module/library/check.mjs
1587 var import_primitives8 = __toESM(require_primitives(), 1);
1588 var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
1589 var check_default = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_primitives8.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_primitives8.Path, { d: "M16.5 7.5 10 13.9l-2.5-2.4-1 1 3.5 3.6 7.5-7.6z" }) });
1590
1591 // packages/icons/build-module/library/chevron-down.mjs
1592 var import_primitives9 = __toESM(require_primitives(), 1);
1593 var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
1594 var chevron_down_default = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_primitives9.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_primitives9.Path, { d: "M17.5 11.6L12 16l-5.5-4.4.9-1.2L12 14l4.5-3.6 1 1.2z" }) });
1595
1596 // packages/icons/build-module/library/close-small.mjs
1597 var import_primitives10 = __toESM(require_primitives(), 1);
1598 var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1);
1599 var close_small_default = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_primitives10.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_primitives10.Path, { d: "M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z" }) });
1600
1601 // packages/icons/build-module/library/cog.mjs
1602 var import_primitives11 = __toESM(require_primitives(), 1);
1603 var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1);
1604 var cog_default = /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_primitives11.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_primitives11.Path, { fillRule: "evenodd", clipRule: "evenodd", d: "M10.289 4.836A1 1 0 0111.275 4h1.306a1 1 0 01.987.836l.244 1.466c.787.26 1.503.679 2.108 1.218l1.393-.522a1 1 0 011.216.437l.653 1.13a1 1 0 01-.23 1.273l-1.148.944a6.025 6.025 0 010 2.435l1.149.946a1 1 0 01.23 1.272l-.653 1.13a1 1 0 01-1.216.437l-1.394-.522c-.605.54-1.32.958-2.108 1.218l-.244 1.466a1 1 0 01-.987.836h-1.306a1 1 0 01-.986-.836l-.244-1.466a5.995 5.995 0 01-2.108-1.218l-1.394.522a1 1 0 01-1.217-.436l-.653-1.131a1 1 0 01.23-1.272l1.149-.946a6.026 6.026 0 010-2.435l-1.148-.944a1 1 0 01-.23-1.272l.653-1.131a1 1 0 011.217-.437l1.393.522a5.994 5.994 0 012.108-1.218l.244-1.466zM14.929 12a3 3 0 11-6 0 3 3 0 016 0z" }) });
1605
1606 // packages/icons/build-module/library/comment-author-avatar.mjs
1607 var import_primitives12 = __toESM(require_primitives(), 1);
1608 var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1);
1609 var comment_author_avatar_default = /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_primitives12.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_primitives12.Path, { fillRule: "evenodd", clipRule: "evenodd", d: "M7.25 16.437a6.5 6.5 0 1 1 9.5 0V16A2.75 2.75 0 0 0 14 13.25h-4A2.75 2.75 0 0 0 7.25 16v.437Zm1.5 1.193a6.47 6.47 0 0 0 3.25.87 6.47 6.47 0 0 0 3.25-.87V16c0-.69-.56-1.25-1.25-1.25h-4c-.69 0-1.25.56-1.25 1.25v1.63ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Zm10-2a2 2 0 1 1-4 0 2 2 0 0 1 4 0Z" }) });
1610
1611 // packages/icons/build-module/library/envelope.mjs
1612 var import_primitives13 = __toESM(require_primitives(), 1);
1613 var import_jsx_runtime13 = __toESM(require_jsx_runtime(), 1);
1614 var envelope_default = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_primitives13.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_primitives13.Path, { fillRule: "evenodd", clipRule: "evenodd", d: "M3 7c0-1.1.9-2 2-2h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Zm2-.5h14c.3 0 .5.2.5.5v1L12 13.5 4.5 7.9V7c0-.3.2-.5.5-.5Zm-.5 3.3V17c0 .3.2.5.5.5h14c.3 0 .5-.2.5-.5V9.8L12 15.4 4.5 9.8Z" }) });
1615
1616 // packages/icons/build-module/library/error.mjs
1617 var import_primitives14 = __toESM(require_primitives(), 1);
1618 var import_jsx_runtime14 = __toESM(require_jsx_runtime(), 1);
1619 var error_default = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_primitives14.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_primitives14.Path, { fillRule: "evenodd", clipRule: "evenodd", d: "M12.218 5.377a.25.25 0 0 0-.436 0l-7.29 12.96a.25.25 0 0 0 .218.373h14.58a.25.25 0 0 0 .218-.372l-7.29-12.96Zm-1.743-.735c.669-1.19 2.381-1.19 3.05 0l7.29 12.96a1.75 1.75 0 0 1-1.525 2.608H4.71a1.75 1.75 0 0 1-1.525-2.608l7.29-12.96ZM12.75 17.46h-1.5v-1.5h1.5v1.5Zm-1.5-3h1.5v-5h-1.5v5Z" }) });
1620
1621 // packages/icons/build-module/library/file.mjs
1622 var import_primitives15 = __toESM(require_primitives(), 1);
1623 var import_jsx_runtime15 = __toESM(require_jsx_runtime(), 1);
1624 var file_default = /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_primitives15.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_primitives15.Path, { fillRule: "evenodd", clipRule: "evenodd", d: "M12.848 8a1 1 0 0 1-.914-.594l-.723-1.63a.5.5 0 0 0-.447-.276H5a.5.5 0 0 0-.5.5v11.5a.5.5 0 0 0 .5.5h14a.5.5 0 0 0 .5-.5v-9A.5.5 0 0 0 19 8h-6.152Zm.612-1.5a.5.5 0 0 1-.462-.31l-.445-1.084A2 2 0 0 0 10.763 4H5a2 2 0 0 0-2 2v11.5a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-9a2 2 0 0 0-2-2h-5.54Z" }) });
1625
1626 // packages/icons/build-module/library/format-list-bullets-rtl.mjs
1627 var import_primitives16 = __toESM(require_primitives(), 1);
1628 var import_jsx_runtime16 = __toESM(require_jsx_runtime(), 1);
1629 var format_list_bullets_rtl_default = /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_primitives16.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_primitives16.Path, { d: "M4 8.8h8.9V7.2H4v1.6zm0 7h8.9v-1.5H4v1.5zM18 13c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0-3c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2z" }) });
1630
1631 // packages/icons/build-module/library/format-list-bullets.mjs
1632 var import_primitives17 = __toESM(require_primitives(), 1);
1633 var import_jsx_runtime17 = __toESM(require_jsx_runtime(), 1);
1634 var format_list_bullets_default = /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_primitives17.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_primitives17.Path, { d: "M11.1 15.8H20v-1.5h-8.9v1.5zm0-8.6v1.5H20V7.2h-8.9zM6 13c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0-7c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z" }) });
1635
1636 // packages/icons/build-module/library/funnel.mjs
1637 var import_primitives18 = __toESM(require_primitives(), 1);
1638 var import_jsx_runtime18 = __toESM(require_jsx_runtime(), 1);
1639 var funnel_default = /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_primitives18.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_primitives18.Path, { d: "M10 17.5H14V16H10V17.5ZM6 6V7.5H18V6H6ZM8 12.5H16V11H8V12.5Z" }) });
1640
1641 // packages/icons/build-module/library/image.mjs
1642 var import_primitives19 = __toESM(require_primitives(), 1);
1643 var import_jsx_runtime19 = __toESM(require_jsx_runtime(), 1);
1644 var image_default = /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_primitives19.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_primitives19.Path, { d: "M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM5 4.5h14c.3 0 .5.2.5.5v8.4l-3-2.9c-.3-.3-.8-.3-1 0L11.9 14 9 12c-.3-.2-.6-.2-.8 0l-3.6 2.6V5c-.1-.3.1-.5.4-.5zm14 15H5c-.3 0-.5-.2-.5-.5v-2.4l4.1-3 3 1.9c.3.2.7.2.9-.1L16 12l3.5 3.4V19c0 .3-.2.5-.5.5z" }) });
1645
1646 // packages/icons/build-module/library/link.mjs
1647 var import_primitives20 = __toESM(require_primitives(), 1);
1648 var import_jsx_runtime20 = __toESM(require_jsx_runtime(), 1);
1649 var link_default = /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_primitives20.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_primitives20.Path, { d: "M10 17.389H8.444A5.194 5.194 0 1 1 8.444 7H10v1.5H8.444a3.694 3.694 0 0 0 0 7.389H10v1.5ZM14 7h1.556a5.194 5.194 0 0 1 0 10.39H14v-1.5h1.556a3.694 3.694 0 0 0 0-7.39H14V7Zm-4.5 6h5v-1.5h-5V13Z" }) });
1650
1651 // packages/icons/build-module/library/mobile.mjs
1652 var import_primitives21 = __toESM(require_primitives(), 1);
1653 var import_jsx_runtime21 = __toESM(require_jsx_runtime(), 1);
1654 var mobile_default = /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_primitives21.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_primitives21.Path, { d: "M15 4H9c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h6c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm.5 14c0 .3-.2.5-.5.5H9c-.3 0-.5-.2-.5-.5V6c0-.3.2-.5.5-.5h6c.3 0 .5.2.5.5v12zm-4.5-.5h2V16h-2v1.5z" }) });
1655
1656 // packages/icons/build-module/library/more-vertical.mjs
1657 var import_primitives22 = __toESM(require_primitives(), 1);
1658 var import_jsx_runtime22 = __toESM(require_jsx_runtime(), 1);
1659 var more_vertical_default = /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_primitives22.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_primitives22.Path, { d: "M13 19h-2v-2h2v2zm0-6h-2v-2h2v2zm0-6h-2V5h2v2z" }) });
1660
1661 // packages/icons/build-module/library/next.mjs
1662 var import_primitives23 = __toESM(require_primitives(), 1);
1663 var import_jsx_runtime23 = __toESM(require_jsx_runtime(), 1);
1664 var next_default = /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_primitives23.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_primitives23.Path, { d: "M6.6 6L5.4 7l4.5 5-4.5 5 1.1 1 5.5-6-5.4-6zm6 0l-1.1 1 4.5 5-4.5 5 1.1 1 5.5-6-5.5-6z" }) });
1665
1666 // packages/icons/build-module/library/previous.mjs
1667 var import_primitives24 = __toESM(require_primitives(), 1);
1668 var import_jsx_runtime24 = __toESM(require_jsx_runtime(), 1);
1669 var previous_default = /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_primitives24.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_primitives24.Path, { d: "M11.6 7l-1.1-1L5 12l5.5 6 1.1-1L7 12l4.6-5zm6 0l-1.1-1-5.5 6 5.5 6 1.1-1-4.6-5 4.6-5z" }) });
1670
1671 // packages/icons/build-module/library/scheduled.mjs
1672 var import_primitives25 = __toESM(require_primitives(), 1);
1673 var import_jsx_runtime25 = __toESM(require_jsx_runtime(), 1);
1674 var scheduled_default = /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_primitives25.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_primitives25.Path, { fillRule: "evenodd", clipRule: "evenodd", d: "M12 18.5a6.5 6.5 0 1 1 0-13 6.5 6.5 0 0 1 0 13ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Zm9 1V8h-1.5v3.5h-2V13H13Z" }) });
1675
1676 // packages/icons/build-module/library/search.mjs
1677 var import_primitives26 = __toESM(require_primitives(), 1);
1678 var import_jsx_runtime26 = __toESM(require_jsx_runtime(), 1);
1679 var search_default = /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_primitives26.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_primitives26.Path, { d: "M13 5c-3.3 0-6 2.7-6 6 0 1.4.5 2.7 1.3 3.7l-3.8 3.8 1.1 1.1 3.8-3.8c1 .8 2.3 1.3 3.7 1.3 3.3 0 6-2.7 6-6S16.3 5 13 5zm0 10.5c-2.5 0-4.5-2-4.5-4.5s2-4.5 4.5-4.5 4.5 2 4.5 4.5-2 4.5-4.5 4.5z" }) });
1680
1681 // packages/icons/build-module/library/seen.mjs
1682 var import_primitives27 = __toESM(require_primitives(), 1);
1683 var import_jsx_runtime27 = __toESM(require_jsx_runtime(), 1);
1684 var seen_default = /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(import_primitives27.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(import_primitives27.Path, { d: "M3.99961 13C4.67043 13.3354 4.6703 13.3357 4.67017 13.3359L4.67298 13.3305C4.67621 13.3242 4.68184 13.3135 4.68988 13.2985C4.70595 13.2686 4.7316 13.2218 4.76695 13.1608C4.8377 13.0385 4.94692 12.8592 5.09541 12.6419C5.39312 12.2062 5.84436 11.624 6.45435 11.0431C7.67308 9.88241 9.49719 8.75 11.9996 8.75C14.502 8.75 16.3261 9.88241 17.5449 11.0431C18.1549 11.624 18.6061 12.2062 18.9038 12.6419C19.0523 12.8592 19.1615 13.0385 19.2323 13.1608C19.2676 13.2218 19.2933 13.2686 19.3093 13.2985C19.3174 13.3135 19.323 13.3242 19.3262 13.3305L19.3291 13.3359C19.3289 13.3357 19.3288 13.3354 19.9996 13C20.6704 12.6646 20.6703 12.6643 20.6701 12.664L20.6697 12.6632L20.6688 12.6614L20.6662 12.6563L20.6583 12.6408C20.6517 12.6282 20.6427 12.6108 20.631 12.5892C20.6078 12.5459 20.5744 12.4852 20.5306 12.4096C20.4432 12.2584 20.3141 12.0471 20.1423 11.7956C19.7994 11.2938 19.2819 10.626 18.5794 9.9569C17.1731 8.61759 14.9972 7.25 11.9996 7.25C9.00203 7.25 6.82614 8.61759 5.41987 9.9569C4.71736 10.626 4.19984 11.2938 3.85694 11.7956C3.68511 12.0471 3.55605 12.2584 3.4686 12.4096C3.42484 12.4852 3.39142 12.5459 3.36818 12.5892C3.35656 12.6108 3.34748 12.6282 3.34092 12.6408L3.33297 12.6563L3.33041 12.6614L3.32948 12.6632L3.32911 12.664C3.32894 12.6643 3.32879 12.6646 3.99961 13ZM11.9996 16C13.9326 16 15.4996 14.433 15.4996 12.5C15.4996 10.567 13.9326 9 11.9996 9C10.0666 9 8.49961 10.567 8.49961 12.5C8.49961 14.433 10.0666 16 11.9996 16Z" }) });
1685
1686 // packages/icons/build-module/library/unseen.mjs
1687 var import_primitives28 = __toESM(require_primitives(), 1);
1688 var import_jsx_runtime28 = __toESM(require_jsx_runtime(), 1);
1689 var unseen_default = /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_primitives28.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_primitives28.Path, { d: "M20.7 12.7s0-.1-.1-.2c0-.2-.2-.4-.4-.6-.3-.5-.9-1.2-1.6-1.8-.7-.6-1.5-1.3-2.6-1.8l-.6 1.4c.9.4 1.6 1 2.1 1.5.6.6 1.1 1.2 1.4 1.6.1.2.3.4.3.5v.1l.7-.3.7-.3Zm-5.2-9.3-1.8 4c-.5-.1-1.1-.2-1.7-.2-3 0-5.2 1.4-6.6 2.7-.7.7-1.2 1.3-1.6 1.8-.2.3-.3.5-.4.6 0 0 0 .1-.1.2s0 0 .7.3l.7.3V13c0-.1.2-.3.3-.5.3-.4.7-1 1.4-1.6 1.2-1.2 3-2.3 5.5-2.3H13v.3c-.4 0-.8-.1-1.1-.1-1.9 0-3.5 1.6-3.5 3.5s.6 2.3 1.6 2.9l-2 4.4.9.4 7.6-16.2-.9-.4Zm-3 12.6c1.7-.2 3-1.7 3-3.5s-.2-1.4-.6-1.9L12.4 16Z" }) });
1690
1691 // packages/icons/build-module/library/upload.mjs
1692 var import_primitives29 = __toESM(require_primitives(), 1);
1693 var import_jsx_runtime29 = __toESM(require_jsx_runtime(), 1);
1694 var upload_default = /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_primitives29.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_primitives29.Path, { d: "M18.5 15v3.5H13V6.7l4.5 4.1 1-1.1-6.2-5.8-5.8 5.8 1 1.1 4-4v11.7h-6V15H4v5h16v-5z" }) });
1695
1696 // packages/icons/build-module/library/video.mjs
1697 var import_primitives30 = __toESM(require_primitives(), 1);
1698 var import_jsx_runtime30 = __toESM(require_jsx_runtime(), 1);
1699 var video_default = /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_primitives30.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_primitives30.Path, { d: "M18.7 3H5.3C4 3 3 4 3 5.3v13.4C3 20 4 21 5.3 21h13.4c1.3 0 2.3-1 2.3-2.3V5.3C21 4 20 3 18.7 3zm.8 15.7c0 .4-.4.8-.8.8H5.3c-.4 0-.8-.4-.8-.8V5.3c0-.4.4-.8.8-.8h13.4c.4 0 .8.4.8.8v13.4zM10 15l5-3-5-3v6z" }) });
1700
1701 // node_modules/@base-ui/utils/esm/useRefWithInit.js
1702 var React = __toESM(require_react(), 1);
1703 var UNINITIALIZED = {};
1704 function useRefWithInit(init2, initArg) {
1705 const ref = React.useRef(UNINITIALIZED);
1706 if (ref.current === UNINITIALIZED) {
1707 ref.current = init2(initArg);
1708 }
1709 return ref;
1710 }
1711
1712 // node_modules/@base-ui/utils/esm/warn.js
1713 var set;
1714 if (true) {
1715 set = /* @__PURE__ */ new Set();
1716 }
1717 function warn(...messages) {
1718 if (true) {
1719 const messageKey = messages.join(" ");
1720 if (!set.has(messageKey)) {
1721 set.add(messageKey);
1722 console.warn(`Base UI: ${messageKey}`);
1723 }
1724 }
1725 }
1726
1727 // node_modules/@base-ui/react/esm/internals/useRenderElement.js
1728 var React4 = __toESM(require_react(), 1);
1729
1730 // node_modules/@base-ui/utils/esm/useMergedRefs.js
1731 function useMergedRefs(a2, b2, c2, d2) {
1732 const forkRef = useRefWithInit(createForkRef).current;
1733 if (didChange(forkRef, a2, b2, c2, d2)) {
1734 update(forkRef, [a2, b2, c2, d2]);
1735 }
1736 return forkRef.callback;
1737 }
1738 function useMergedRefsN(refs) {
1739 const forkRef = useRefWithInit(createForkRef).current;
1740 if (didChangeN(forkRef, refs)) {
1741 update(forkRef, refs);
1742 }
1743 return forkRef.callback;
1744 }
1745 function createForkRef() {
1746 return {
1747 callback: null,
1748 cleanup: null,
1749 refs: []
1750 };
1751 }
1752 function didChange(forkRef, a2, b2, c2, d2) {
1753 return forkRef.refs[0] !== a2 || forkRef.refs[1] !== b2 || forkRef.refs[2] !== c2 || forkRef.refs[3] !== d2;
1754 }
1755 function didChangeN(forkRef, newRefs) {
1756 return forkRef.refs.length !== newRefs.length || forkRef.refs.some((ref, index) => ref !== newRefs[index]);
1757 }
1758 function update(forkRef, refs) {
1759 forkRef.refs = refs;
1760 if (refs.every((ref) => ref == null)) {
1761 forkRef.callback = null;
1762 return;
1763 }
1764 forkRef.callback = (instance) => {
1765 if (forkRef.cleanup) {
1766 forkRef.cleanup();
1767 forkRef.cleanup = null;
1768 }
1769 if (instance != null) {
1770 const cleanupCallbacks = Array(refs.length).fill(null);
1771 for (let i2 = 0; i2 < refs.length; i2 += 1) {
1772 const ref = refs[i2];
1773 if (ref == null) {
1774 continue;
1775 }
1776 switch (typeof ref) {
1777 case "function": {
1778 const refCleanup = ref(instance);
1779 if (typeof refCleanup === "function") {
1780 cleanupCallbacks[i2] = refCleanup;
1781 }
1782 break;
1783 }
1784 case "object": {
1785 ref.current = instance;
1786 break;
1787 }
1788 default:
1789 }
1790 }
1791 forkRef.cleanup = () => {
1792 for (let i2 = 0; i2 < refs.length; i2 += 1) {
1793 const ref = refs[i2];
1794 if (ref == null) {
1795 continue;
1796 }
1797 switch (typeof ref) {
1798 case "function": {
1799 const cleanupCallback = cleanupCallbacks[i2];
1800 if (typeof cleanupCallback === "function") {
1801 cleanupCallback();
1802 } else {
1803 ref(null);
1804 }
1805 break;
1806 }
1807 case "object": {
1808 ref.current = null;
1809 break;
1810 }
1811 default:
1812 }
1813 }
1814 };
1815 }
1816 };
1817 }
1818
1819 // node_modules/@base-ui/utils/esm/getReactElementRef.js
1820 var React3 = __toESM(require_react(), 1);
1821
1822 // node_modules/@base-ui/utils/esm/reactVersion.js
1823 var React2 = __toESM(require_react(), 1);
1824 var majorVersion = parseInt(React2.version, 10);
1825 function isReactVersionAtLeast(reactVersionToCheck) {
1826 return majorVersion >= reactVersionToCheck;
1827 }
1828
1829 // node_modules/@base-ui/utils/esm/getReactElementRef.js
1830 function getReactElementRef(element) {
1831 if (!/* @__PURE__ */ React3.isValidElement(element)) {
1832 return null;
1833 }
1834 const reactElement = element;
1835 const propsWithRef = reactElement.props;
1836 return (isReactVersionAtLeast(19) ? propsWithRef?.ref : reactElement.ref) ?? null;
1837 }
1838
1839 // node_modules/@base-ui/utils/esm/mergeObjects.js
1840 function mergeObjects(a2, b2) {
1841 if (a2 && !b2) {
1842 return a2;
1843 }
1844 if (!a2 && b2) {
1845 return b2;
1846 }
1847 if (a2 || b2) {
1848 return {
1849 ...a2,
1850 ...b2
1851 };
1852 }
1853 return void 0;
1854 }
1855
1856 // node_modules/@base-ui/utils/esm/empty.js
1857 var EMPTY_ARRAY = Object.freeze([]);
1858 var EMPTY_OBJECT = Object.freeze({});
1859
1860 // node_modules/@base-ui/react/esm/internals/getStateAttributesProps.js
1861 function getStateAttributesProps(state, customMapping) {
1862 const props = {};
1863 for (const key in state) {
1864 const value = state[key];
1865 if (customMapping?.hasOwnProperty(key)) {
1866 const customProps = customMapping[key](value);
1867 if (customProps != null) {
1868 Object.assign(props, customProps);
1869 }
1870 continue;
1871 }
1872 if (value === true) {
1873 props[`data-${key.toLowerCase()}`] = "";
1874 } else if (value) {
1875 props[`data-${key.toLowerCase()}`] = value.toString();
1876 }
1877 }
1878 return props;
1879 }
1880
1881 // node_modules/@base-ui/react/esm/utils/resolveClassName.js
1882 function resolveClassName(className, state) {
1883 return typeof className === "function" ? className(state) : className;
1884 }
1885
1886 // node_modules/@base-ui/react/esm/utils/resolveStyle.js
1887 function resolveStyle(style, state) {
1888 return typeof style === "function" ? style(state) : style;
1889 }
1890
1891 // node_modules/@base-ui/react/esm/merge-props/mergeProps.js
1892 var EMPTY_PROPS = {};
1893 function mergeProps(a2, b2, c2, d2, e2) {
1894 if (!c2 && !d2 && !e2 && !a2) {
1895 return createInitialMergedProps(b2);
1896 }
1897 let merged = createInitialMergedProps(a2);
1898 if (b2) {
1899 merged = mergeInto(merged, b2);
1900 }
1901 if (c2) {
1902 merged = mergeInto(merged, c2);
1903 }
1904 if (d2) {
1905 merged = mergeInto(merged, d2);
1906 }
1907 if (e2) {
1908 merged = mergeInto(merged, e2);
1909 }
1910 return merged;
1911 }
1912 function mergePropsN(props) {
1913 if (props.length === 0) {
1914 return EMPTY_PROPS;
1915 }
1916 if (props.length === 1) {
1917 return createInitialMergedProps(props[0]);
1918 }
1919 let merged = createInitialMergedProps(props[0]);
1920 for (let i2 = 1; i2 < props.length; i2 += 1) {
1921 merged = mergeInto(merged, props[i2]);
1922 }
1923 return merged;
1924 }
1925 function createInitialMergedProps(inputProps) {
1926 if (isPropsGetter(inputProps)) {
1927 return {
1928 ...resolvePropsGetter(inputProps, EMPTY_PROPS)
1929 };
1930 }
1931 return copyInitialProps(inputProps);
1932 }
1933 function mergeInto(merged, inputProps) {
1934 if (isPropsGetter(inputProps)) {
1935 return resolvePropsGetter(inputProps, merged);
1936 }
1937 return mutablyMergeInto(merged, inputProps);
1938 }
1939 function copyInitialProps(inputProps) {
1940 const copiedProps = {
1941 ...inputProps
1942 };
1943 for (const propName in copiedProps) {
1944 const propValue = copiedProps[propName];
1945 if (isEventHandler(propName, propValue)) {
1946 copiedProps[propName] = wrapEventHandler(propValue);
1947 }
1948 }
1949 return copiedProps;
1950 }
1951 function mutablyMergeInto(mergedProps, externalProps) {
1952 if (!externalProps) {
1953 return mergedProps;
1954 }
1955 for (const propName in externalProps) {
1956 const externalPropValue = externalProps[propName];
1957 switch (propName) {
1958 case "style": {
1959 mergedProps[propName] = mergeObjects(mergedProps.style, externalPropValue);
1960 break;
1961 }
1962 case "className": {
1963 mergedProps[propName] = mergeClassNames(mergedProps.className, externalPropValue);
1964 break;
1965 }
1966 default: {
1967 if (isEventHandler(propName, externalPropValue)) {
1968 mergedProps[propName] = mergeEventHandlers(mergedProps[propName], externalPropValue);
1969 } else {
1970 mergedProps[propName] = externalPropValue;
1971 }
1972 }
1973 }
1974 }
1975 return mergedProps;
1976 }
1977 function isEventHandler(key, value) {
1978 const code0 = key.charCodeAt(0);
1979 const code1 = key.charCodeAt(1);
1980 const code2 = key.charCodeAt(2);
1981 return code0 === 111 && code1 === 110 && code2 >= 65 && code2 <= 90 && (typeof value === "function" || typeof value === "undefined");
1982 }
1983 function isPropsGetter(inputProps) {
1984 return typeof inputProps === "function";
1985 }
1986 function resolvePropsGetter(inputProps, previousProps) {
1987 if (isPropsGetter(inputProps)) {
1988 return inputProps(previousProps);
1989 }
1990 return inputProps ?? EMPTY_PROPS;
1991 }
1992 function mergeEventHandlers(ourHandler, theirHandler) {
1993 if (!theirHandler) {
1994 return ourHandler;
1995 }
1996 if (!ourHandler) {
1997 return wrapEventHandler(theirHandler);
1998 }
1999 return (...args) => {
2000 const event = args[0];
2001 if (isSyntheticEvent(event)) {
2002 const baseUIEvent = event;
2003 makeEventPreventable(baseUIEvent);
2004 const result2 = theirHandler(...args);
2005 if (!baseUIEvent.baseUIHandlerPrevented) {
2006 ourHandler?.(...args);
2007 }
2008 return result2;
2009 }
2010 const result = theirHandler(...args);
2011 ourHandler?.(...args);
2012 return result;
2013 };
2014 }
2015 function wrapEventHandler(handler) {
2016 if (!handler) {
2017 return handler;
2018 }
2019 return (...args) => {
2020 const event = args[0];
2021 if (isSyntheticEvent(event)) {
2022 makeEventPreventable(event);
2023 }
2024 return handler(...args);
2025 };
2026 }
2027 function makeEventPreventable(event) {
2028 event.preventBaseUIHandler = () => {
2029 event.baseUIHandlerPrevented = true;
2030 };
2031 return event;
2032 }
2033 function mergeClassNames(ourClassName, theirClassName) {
2034 if (theirClassName) {
2035 if (ourClassName) {
2036 return theirClassName + " " + ourClassName;
2037 }
2038 return theirClassName;
2039 }
2040 return ourClassName;
2041 }
2042 function isSyntheticEvent(event) {
2043 return event != null && typeof event === "object" && "nativeEvent" in event;
2044 }
2045
2046 // node_modules/@base-ui/react/esm/internals/useRenderElement.js
2047 var import_react = __toESM(require_react(), 1);
2048 function useRenderElement(element, componentProps, params = {}) {
2049 const renderProp = componentProps.render;
2050 const outProps = useRenderElementProps(componentProps, params);
2051 if (params.enabled === false) {
2052 return null;
2053 }
2054 const state = params.state ?? EMPTY_OBJECT;
2055 return evaluateRenderProp(element, renderProp, outProps, state);
2056 }
2057 function useRenderElementProps(componentProps, params = {}) {
2058 const {
2059 className: classNameProp,
2060 style: styleProp,
2061 render: renderProp
2062 } = componentProps;
2063 const {
2064 state = EMPTY_OBJECT,
2065 ref,
2066 props,
2067 stateAttributesMapping,
2068 enabled = true
2069 } = params;
2070 const className = enabled ? resolveClassName(classNameProp, state) : void 0;
2071 const style = enabled ? resolveStyle(styleProp, state) : void 0;
2072 const stateProps = enabled ? getStateAttributesProps(state, stateAttributesMapping) : EMPTY_OBJECT;
2073 const resolvedProps = enabled && props ? resolveRenderFunctionProps(props) : void 0;
2074 const outProps = enabled ? mergeObjects(stateProps, resolvedProps) ?? {} : EMPTY_OBJECT;
2075 if (typeof document !== "undefined") {
2076 if (!enabled) {
2077 useMergedRefs(null, null);
2078 } else if (Array.isArray(ref)) {
2079 outProps.ref = useMergedRefsN([outProps.ref, getReactElementRef(renderProp), ...ref]);
2080 } else {
2081 outProps.ref = useMergedRefs(outProps.ref, getReactElementRef(renderProp), ref);
2082 }
2083 }
2084 if (!enabled) {
2085 return EMPTY_OBJECT;
2086 }
2087 if (className !== void 0) {
2088 outProps.className = mergeClassNames(outProps.className, className);
2089 }
2090 if (style !== void 0) {
2091 outProps.style = mergeObjects(outProps.style, style);
2092 }
2093 return outProps;
2094 }
2095 function resolveRenderFunctionProps(props) {
2096 if (Array.isArray(props)) {
2097 return mergePropsN(props);
2098 }
2099 return mergeProps(void 0, props);
2100 }
2101 var REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for("react.lazy");
2102 var COMPONENT_IDENTIFIER_PATTERN = /^[A-Z][A-Za-z0-9$]*$/;
2103 var LOWERCASE_CHARACTER_PATTERN = /[a-z]/;
2104 function evaluateRenderProp(element, render4, props, state) {
2105 if (render4) {
2106 if (typeof render4 === "function") {
2107 if (true) {
2108 warnIfRenderPropLooksLikeComponent(render4);
2109 }
2110 return render4(props, state);
2111 }
2112 const mergedProps = mergeProps(props, render4.props);
2113 mergedProps.ref = props.ref;
2114 let newElement = render4;
2115 if (newElement?.$$typeof === REACT_LAZY_TYPE) {
2116 const children = React4.Children.toArray(render4);
2117 newElement = children[0];
2118 }
2119 if (true) {
2120 if (!/* @__PURE__ */ React4.isValidElement(newElement)) {
2121 throw new Error(["Base UI: The `render` prop was provided an invalid React element as `React.isValidElement(render)` is `false`.", "A valid React element must be provided to the `render` prop because it is cloned with props to replace the default element.", "https://base-ui.com/r/invalid-render-prop"].join("\n"));
2122 }
2123 }
2124 return /* @__PURE__ */ React4.cloneElement(newElement, mergedProps);
2125 }
2126 if (element) {
2127 if (typeof element === "string") {
2128 return renderTag(element, props);
2129 }
2130 }
2131 throw new Error(true ? "Base UI: Render element or function are not defined." : formatErrorMessage_default(8));
2132 }
2133 function warnIfRenderPropLooksLikeComponent(renderFn) {
2134 const functionName = renderFn.name;
2135 if (functionName.length === 0) {
2136 return;
2137 }
2138 if (!COMPONENT_IDENTIFIER_PATTERN.test(functionName)) {
2139 return;
2140 }
2141 if (!LOWERCASE_CHARACTER_PATTERN.test(functionName)) {
2142 return;
2143 }
2144 warn(`The \`render\` prop received a function named \`${functionName}\` that starts with an uppercase letter.`, "This usually means a React component was passed directly as `render={Component}`.", "Base UI calls `render` as a plain function, which can break the Rules of Hooks during reconciliation.", "If this is an intentional render callback, rename it to start with a lowercase letter.", "Use `render={<Component />}` or `render={(props) => <Component {...props} />}` instead.", "https://base-ui.com/r/invalid-render-prop");
2145 }
2146 function renderTag(Tag, props) {
2147 if (Tag === "button") {
2148 return /* @__PURE__ */ (0, import_react.createElement)("button", {
2149 type: "button",
2150 ...props,
2151 key: props.key
2152 });
2153 }
2154 if (Tag === "img") {
2155 return /* @__PURE__ */ (0, import_react.createElement)("img", {
2156 alt: "",
2157 ...props,
2158 key: props.key
2159 });
2160 }
2161 return /* @__PURE__ */ React4.createElement(Tag, props);
2162 }
2163
2164 // node_modules/@base-ui/react/esm/use-render/useRender.js
2165 function useRender(params) {
2166 return useRenderElement(params.defaultTagName ?? "div", params, params);
2167 }
2168
2169 // packages/ui/build-module/stack/stack.mjs
2170 var import_element2 = __toESM(require_element(), 1);
2171 var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
2172 function getRuntime() {
2173 const globalScope = globalThis;
2174 if (globalScope.__wpStyleRuntime) {
2175 return globalScope.__wpStyleRuntime;
2176 }
2177 globalScope.__wpStyleRuntime = {
2178 documents: /* @__PURE__ */ new Map(),
2179 styles: /* @__PURE__ */ new Map(),
2180 injectedStyles: /* @__PURE__ */ new WeakMap()
2181 };
2182 if (typeof document !== "undefined") {
2183 registerDocument(document);
2184 }
2185 return globalScope.__wpStyleRuntime;
2186 }
2187 function documentContainsStyleHash(targetDocument, hash) {
2188 if (!targetDocument.head) {
2189 return false;
2190 }
2191 for (const style of targetDocument.head.querySelectorAll(
2192 `style[${STYLE_HASH_ATTRIBUTE}]`
2193 )) {
2194 if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {
2195 return true;
2196 }
2197 }
2198 return false;
2199 }
2200 function injectStyle(targetDocument, hash, css) {
2201 if (!targetDocument.head) {
2202 return;
2203 }
2204 const runtime = getRuntime();
2205 let injectedStyles = runtime.injectedStyles.get(targetDocument);
2206 if (!injectedStyles) {
2207 injectedStyles = /* @__PURE__ */ new Set();
2208 runtime.injectedStyles.set(targetDocument, injectedStyles);
2209 }
2210 if (injectedStyles.has(hash)) {
2211 return;
2212 }
2213 if (documentContainsStyleHash(targetDocument, hash)) {
2214 injectedStyles.add(hash);
2215 return;
2216 }
2217 const style = targetDocument.createElement("style");
2218 style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
2219 style.appendChild(targetDocument.createTextNode(css));
2220 targetDocument.head.appendChild(style);
2221 injectedStyles.add(hash);
2222 }
2223 function registerDocument(targetDocument) {
2224 const runtime = getRuntime();
2225 runtime.documents.set(
2226 targetDocument,
2227 (runtime.documents.get(targetDocument) ?? 0) + 1
2228 );
2229 for (const [hash, css] of runtime.styles) {
2230 injectStyle(targetDocument, hash, css);
2231 }
2232 return () => {
2233 const count = runtime.documents.get(targetDocument);
2234 if (count === void 0) {
2235 return;
2236 }
2237 if (count <= 1) {
2238 runtime.documents.delete(targetDocument);
2239 return;
2240 }
2241 runtime.documents.set(targetDocument, count - 1);
2242 };
2243 }
2244 function registerStyle(hash, css) {
2245 const runtime = getRuntime();
2246 runtime.styles.set(hash, css);
2247 for (const targetDocument of runtime.documents.keys()) {
2248 injectStyle(targetDocument, hash, css);
2249 }
2250 }
2251 if (typeof process === "undefined" || true) {
2252 registerStyle("b51ff41489", "@layer wp-ui-utilities, wp-ui-components, wp-ui-compositions, wp-ui-overrides;@layer wp-ui-components{._19ce0419607e1896__stack{display:flex}}");
2253 }
2254 var style_default = { "stack": "_19ce0419607e1896__stack" };
2255 var gapTokens = {
2256 xs: "var(--wpds-dimension-gap-xs, 4px)",
2257 sm: "var(--wpds-dimension-gap-sm, 8px)",
2258 md: "var(--wpds-dimension-gap-md, 12px)",
2259 lg: "var(--wpds-dimension-gap-lg, 16px)",
2260 xl: "var(--wpds-dimension-gap-xl, 24px)",
2261 "2xl": "var(--wpds-dimension-gap-2xl, 32px)",
2262 "3xl": "var(--wpds-dimension-gap-3xl, 40px)"
2263 };
2264 var Stack = (0, import_element2.forwardRef)(function Stack2({ direction, gap, align, justify, wrap, render: render4, ...props }, ref) {
2265 const style = {
2266 gap: gap && gapTokens[gap],
2267 alignItems: align,
2268 justifyContent: justify,
2269 flexDirection: direction,
2270 flexWrap: wrap
2271 };
2272 const element = useRender({
2273 render: render4,
2274 ref,
2275 props: mergeProps(props, { style, className: style_default.stack })
2276 });
2277 return element;
2278 });
2279
2280 // packages/ui/build-module/visually-hidden/visually-hidden.mjs
2281 var import_element3 = __toESM(require_element(), 1);
2282 var STYLE_HASH_ATTRIBUTE2 = "data-wp-hash";
2283 function getRuntime2() {
2284 const globalScope = globalThis;
2285 if (globalScope.__wpStyleRuntime) {
2286 return globalScope.__wpStyleRuntime;
2287 }
2288 globalScope.__wpStyleRuntime = {
2289 documents: /* @__PURE__ */ new Map(),
2290 styles: /* @__PURE__ */ new Map(),
2291 injectedStyles: /* @__PURE__ */ new WeakMap()
2292 };
2293 if (typeof document !== "undefined") {
2294 registerDocument2(document);
2295 }
2296 return globalScope.__wpStyleRuntime;
2297 }
2298 function documentContainsStyleHash2(targetDocument, hash) {
2299 if (!targetDocument.head) {
2300 return false;
2301 }
2302 for (const style of targetDocument.head.querySelectorAll(
2303 `style[${STYLE_HASH_ATTRIBUTE2}]`
2304 )) {
2305 if (style.getAttribute(STYLE_HASH_ATTRIBUTE2) === hash) {
2306 return true;
2307 }
2308 }
2309 return false;
2310 }
2311 function injectStyle2(targetDocument, hash, css) {
2312 if (!targetDocument.head) {
2313 return;
2314 }
2315 const runtime = getRuntime2();
2316 let injectedStyles = runtime.injectedStyles.get(targetDocument);
2317 if (!injectedStyles) {
2318 injectedStyles = /* @__PURE__ */ new Set();
2319 runtime.injectedStyles.set(targetDocument, injectedStyles);
2320 }
2321 if (injectedStyles.has(hash)) {
2322 return;
2323 }
2324 if (documentContainsStyleHash2(targetDocument, hash)) {
2325 injectedStyles.add(hash);
2326 return;
2327 }
2328 const style = targetDocument.createElement("style");
2329 style.setAttribute(STYLE_HASH_ATTRIBUTE2, hash);
2330 style.appendChild(targetDocument.createTextNode(css));
2331 targetDocument.head.appendChild(style);
2332 injectedStyles.add(hash);
2333 }
2334 function registerDocument2(targetDocument) {
2335 const runtime = getRuntime2();
2336 runtime.documents.set(
2337 targetDocument,
2338 (runtime.documents.get(targetDocument) ?? 0) + 1
2339 );
2340 for (const [hash, css] of runtime.styles) {
2341 injectStyle2(targetDocument, hash, css);
2342 }
2343 return () => {
2344 const count = runtime.documents.get(targetDocument);
2345 if (count === void 0) {
2346 return;
2347 }
2348 if (count <= 1) {
2349 runtime.documents.delete(targetDocument);
2350 return;
2351 }
2352 runtime.documents.set(targetDocument, count - 1);
2353 };
2354 }
2355 function registerStyle2(hash, css) {
2356 const runtime = getRuntime2();
2357 runtime.styles.set(hash, css);
2358 for (const targetDocument of runtime.documents.keys()) {
2359 injectStyle2(targetDocument, hash, css);
2360 }
2361 }
2362 if (typeof process === "undefined" || true) {
2363 registerStyle2("c46e8cb841", "@layer wp-ui-utilities, wp-ui-components, wp-ui-compositions, wp-ui-overrides;@layer wp-ui-components{.f37b9e2e191ebd66__visually-hidden{word-wrap:normal;border:0;clip-path:inset(50%);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;word-break:normal}}");
2364 }
2365 var style_default2 = { "visually-hidden": "f37b9e2e191ebd66__visually-hidden" };
2366 var VisuallyHidden = (0, import_element3.forwardRef)(
2367 function VisuallyHidden2({ render: render4, ...restProps }, ref) {
2368 const element = useRender({
2369 render: render4,
2370 ref,
2371 props: mergeProps(
2372 { className: style_default2["visually-hidden"] },
2373 restProps,
2374 {
2375 // @ts-expect-error Arbitrary data-* attributes aren't indexable on the typed div props. Kept hardcoded so consumers can't change or remove it.
2376 "data-visually-hidden": ""
2377 }
2378 )
2379 });
2380 return element;
2381 }
2382 );
2383
2384 // packages/dataviews/build-module/components/dataviews-context/index.mjs
2385 var import_element4 = __toESM(require_element(), 1);
2386
2387 // packages/dataviews/build-module/constants.mjs
2388 var import_i18n7 = __toESM(require_i18n(), 1);
2389 var OPERATOR_IS_ANY = "isAny";
2390 var OPERATOR_IS_NONE = "isNone";
2391 var OPERATOR_IS_ALL = "isAll";
2392 var OPERATOR_IS_NOT_ALL = "isNotAll";
2393 var OPERATOR_BETWEEN = "between";
2394 var OPERATOR_IN_THE_PAST = "inThePast";
2395 var OPERATOR_OVER = "over";
2396 var OPERATOR_IS = "is";
2397 var OPERATOR_IS_NOT = "isNot";
2398 var OPERATOR_LESS_THAN = "lessThan";
2399 var OPERATOR_GREATER_THAN = "greaterThan";
2400 var OPERATOR_LESS_THAN_OR_EQUAL = "lessThanOrEqual";
2401 var OPERATOR_GREATER_THAN_OR_EQUAL = "greaterThanOrEqual";
2402 var OPERATOR_BEFORE = "before";
2403 var OPERATOR_AFTER = "after";
2404 var OPERATOR_BEFORE_INC = "beforeInc";
2405 var OPERATOR_AFTER_INC = "afterInc";
2406 var OPERATOR_CONTAINS = "contains";
2407 var OPERATOR_NOT_CONTAINS = "notContains";
2408 var OPERATOR_STARTS_WITH = "startsWith";
2409 var OPERATOR_ON = "on";
2410 var OPERATOR_NOT_ON = "notOn";
2411 var SORTING_DIRECTIONS = ["asc", "desc"];
2412 var sortArrows = { asc: "\u2191", desc: "\u2193" };
2413 var sortValues = { asc: "ascending", desc: "descending" };
2414 var sortLabels = {
2415 asc: (0, import_i18n7.__)("Sort ascending"),
2416 desc: (0, import_i18n7.__)("Sort descending")
2417 };
2418 var sortIcons = {
2419 asc: arrow_up_default,
2420 desc: arrow_down_default
2421 };
2422 var LAYOUT_TABLE = "table";
2423 var LAYOUT_GRID = "grid";
2424 var LAYOUT_LIST = "list";
2425 var LAYOUT_ACTIVITY = "activity";
2426 var LAYOUT_PICKER_GRID = "pickerGrid";
2427 var LAYOUT_PICKER_TABLE = "pickerTable";
2428
2429 // packages/dataviews/build-module/components/dataviews-context/index.mjs
2430 var DataViewsContext = (0, import_element4.createContext)({
2431 view: { type: LAYOUT_TABLE },
2432 onChangeView: () => {
2433 },
2434 fields: [],
2435 data: [],
2436 paginationInfo: {
2437 totalItems: 0,
2438 totalPages: 0
2439 },
2440 selection: [],
2441 onChangeSelection: () => {
2442 },
2443 setOpenedFilter: () => {
2444 },
2445 openedFilter: null,
2446 getItemId: (item) => item.id,
2447 isItemClickable: () => true,
2448 renderItemLink: void 0,
2449 containerWidth: 0,
2450 containerRef: (0, import_element4.createRef)(),
2451 resizeObserverRef: () => {
2452 },
2453 defaultLayouts: { list: {}, grid: {}, table: {} },
2454 filters: [],
2455 isShowingFilter: false,
2456 setIsShowingFilter: () => {
2457 },
2458 hasInitiallyLoaded: false,
2459 config: {
2460 perPageSizes: []
2461 },
2462 intersectionObserver: null
2463 });
2464 DataViewsContext.displayName = "DataViewsContext";
2465 var dataviews_context_default = DataViewsContext;
2466
2467 // packages/dataviews/build-module/components/dataviews-layouts/index.mjs
2468 var import_i18n27 = __toESM(require_i18n(), 1);
2469
2470 // packages/dataviews/build-module/components/dataviews-layouts/table/index.mjs
2471 var import_i18n15 = __toESM(require_i18n(), 1);
2472 var import_components6 = __toESM(require_components(), 1);
2473 var import_element12 = __toESM(require_element(), 1);
2474 var import_keycodes = __toESM(require_keycodes(), 1);
2475
2476 // packages/dataviews/build-module/components/dataviews-selection-checkbox/index.mjs
2477 var import_components = __toESM(require_components(), 1);
2478 var import_i18n8 = __toESM(require_i18n(), 1);
2479 var import_jsx_runtime31 = __toESM(require_jsx_runtime(), 1);
2480 function DataViewsSelectionCheckbox({
2481 selection,
2482 onChangeSelection,
2483 item,
2484 getItemId,
2485 titleField,
2486 disabled,
2487 ...extraProps
2488 }) {
2489 const id = getItemId(item);
2490 const isInSelectionArray = selection.includes(id);
2491 const checked = !disabled && isInSelectionArray;
2492 const selectionLabel = titleField?.getValue?.({ item }) || (0, import_i18n8.__)("(no title)");
2493 return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2494 import_components.CheckboxControl,
2495 {
2496 className: "dataviews-selection-checkbox",
2497 "aria-label": selectionLabel,
2498 "aria-disabled": disabled,
2499 checked,
2500 onChange: () => {
2501 if (disabled) {
2502 return;
2503 }
2504 onChangeSelection(
2505 isInSelectionArray ? selection.filter((itemId) => id !== itemId) : [...selection, id]
2506 );
2507 },
2508 ...extraProps
2509 }
2510 );
2511 }
2512
2513 // packages/dataviews/build-module/components/dataviews-item-actions/index.mjs
2514 var import_components2 = __toESM(require_components(), 1);
2515 var import_i18n9 = __toESM(require_i18n(), 1);
2516 var import_element5 = __toESM(require_element(), 1);
2517 var import_data = __toESM(require_data(), 1);
2518 var import_compose = __toESM(require_compose(), 1);
2519
2520 // packages/dataviews/build-module/lock-unlock.mjs
2521 var import_private_apis = __toESM(require_private_apis(), 1);
2522 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
2523 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
2524 "@wordpress/dataviews"
2525 );
2526
2527 // packages/dataviews/build-module/components/dataviews-item-actions/index.mjs
2528 var import_jsx_runtime32 = __toESM(require_jsx_runtime(), 1);
2529 var { Menu, kebabCase } = unlock(import_components2.privateApis);
2530 function ButtonTrigger({
2531 action,
2532 onClick,
2533 items,
2534 variant
2535 }) {
2536 const label = typeof action.label === "string" ? action.label : action.label(items);
2537 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2538 import_components2.Button,
2539 {
2540 disabled: !!action.disabled,
2541 accessibleWhenDisabled: true,
2542 size: "compact",
2543 variant,
2544 onClick,
2545 children: label
2546 }
2547 );
2548 }
2549 function MenuItemTrigger({
2550 action,
2551 onClick,
2552 items
2553 }) {
2554 const label = typeof action.label === "string" ? action.label : action.label(items);
2555 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Menu.Item, { disabled: action.disabled, onClick, children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Menu.ItemLabel, { children: label }) });
2556 }
2557 function ActionModal({
2558 action,
2559 items,
2560 closeModal
2561 }) {
2562 const label = typeof action.label === "string" ? action.label : action.label(items);
2563 const modalHeader = typeof action.modalHeader === "function" ? action.modalHeader(items) : action.modalHeader;
2564 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2565 import_components2.Modal,
2566 {
2567 title: modalHeader || label,
2568 __experimentalHideHeader: !!action.hideModalHeader,
2569 onRequestClose: closeModal,
2570 focusOnMount: action.modalFocusOnMount ?? true,
2571 size: action.modalSize || "medium",
2572 overlayClassName: `dataviews-action-modal dataviews-action-modal__${kebabCase(
2573 action.id
2574 )}`,
2575 children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(action.RenderModal, { items, closeModal })
2576 }
2577 );
2578 }
2579 function ActionsMenuGroup({
2580 actions,
2581 item,
2582 registry,
2583 setActiveModalAction
2584 }) {
2585 const { primaryActions, regularActions } = (0, import_element5.useMemo)(() => {
2586 return actions.reduce(
2587 (acc, action) => {
2588 (action.isPrimary ? acc.primaryActions : acc.regularActions).push(action);
2589 return acc;
2590 },
2591 {
2592 primaryActions: [],
2593 regularActions: []
2594 }
2595 );
2596 }, [actions]);
2597 const renderActionGroup = (actionList) => actionList.map((action) => /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2598 MenuItemTrigger,
2599 {
2600 action,
2601 onClick: () => {
2602 if ("RenderModal" in action) {
2603 setActiveModalAction(action);
2604 return;
2605 }
2606 action.callback([item], { registry });
2607 },
2608 items: [item]
2609 },
2610 action.id
2611 ));
2612 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(Menu.Group, { children: [
2613 renderActionGroup(primaryActions),
2614 renderActionGroup(regularActions)
2615 ] });
2616 }
2617 function ItemActions({
2618 item,
2619 actions,
2620 isCompact
2621 }) {
2622 const registry = (0, import_data.useRegistry)();
2623 const { primaryActions, eligibleActions } = (0, import_element5.useMemo)(() => {
2624 const _eligibleActions = actions.filter(
2625 (action) => !action.isEligible || action.isEligible(item)
2626 );
2627 const _primaryActions = _eligibleActions.filter(
2628 (action) => action.isPrimary
2629 );
2630 return {
2631 primaryActions: _primaryActions,
2632 eligibleActions: _eligibleActions
2633 };
2634 }, [actions, item]);
2635 const isMobileViewport = (0, import_compose.useViewportMatch)("medium", "<");
2636 if (isCompact) {
2637 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2638 CompactItemActions,
2639 {
2640 item,
2641 actions: eligibleActions,
2642 isSmall: true,
2643 registry
2644 }
2645 );
2646 }
2647 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(
2648 Stack,
2649 {
2650 direction: "row",
2651 justify: "flex-end",
2652 className: "dataviews-item-actions",
2653 style: {
2654 flexShrink: 0,
2655 width: "auto"
2656 },
2657 children: [
2658 /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2659 PrimaryActions,
2660 {
2661 item,
2662 actions: primaryActions,
2663 registry
2664 }
2665 ),
2666 (primaryActions.length < eligibleActions.length || // Since we hide primary actions on mobile, we need to show the menu
2667 // there if there are any actions at all.
2668 isMobileViewport) && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2669 CompactItemActions,
2670 {
2671 item,
2672 actions: eligibleActions,
2673 registry
2674 }
2675 )
2676 ]
2677 }
2678 );
2679 }
2680 function CompactItemActions({
2681 item,
2682 actions,
2683 isSmall,
2684 registry
2685 }) {
2686 const [activeModalAction, setActiveModalAction] = (0, import_element5.useState)(
2687 null
2688 );
2689 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(import_jsx_runtime32.Fragment, { children: [
2690 /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(Menu, { placement: "bottom-end", children: [
2691 /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2692 Menu.TriggerButton,
2693 {
2694 render: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2695 import_components2.Button,
2696 {
2697 size: isSmall ? "small" : "compact",
2698 icon: more_vertical_default,
2699 label: (0, import_i18n9.__)("Actions"),
2700 accessibleWhenDisabled: true,
2701 disabled: !actions.length,
2702 className: "dataviews-all-actions-button"
2703 }
2704 )
2705 }
2706 ),
2707 /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Menu.Popover, { children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2708 ActionsMenuGroup,
2709 {
2710 actions,
2711 item,
2712 registry,
2713 setActiveModalAction
2714 }
2715 ) })
2716 ] }),
2717 !!activeModalAction && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2718 ActionModal,
2719 {
2720 action: activeModalAction,
2721 items: [item],
2722 closeModal: () => setActiveModalAction(null)
2723 }
2724 )
2725 ] });
2726 }
2727 function PrimaryActions({
2728 item,
2729 actions,
2730 registry,
2731 buttonVariant
2732 }) {
2733 const [activeModalAction, setActiveModalAction] = (0, import_element5.useState)(null);
2734 const isMobileViewport = (0, import_compose.useViewportMatch)("medium", "<");
2735 if (isMobileViewport) {
2736 return null;
2737 }
2738 if (!Array.isArray(actions) || actions.length === 0) {
2739 return null;
2740 }
2741 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(import_jsx_runtime32.Fragment, { children: [
2742 actions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2743 ButtonTrigger,
2744 {
2745 action,
2746 onClick: () => {
2747 if ("RenderModal" in action) {
2748 setActiveModalAction(action);
2749 return;
2750 }
2751 action.callback([item], { registry });
2752 },
2753 items: [item],
2754 variant: buttonVariant
2755 },
2756 action.id
2757 )),
2758 !!activeModalAction && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2759 ActionModal,
2760 {
2761 action: activeModalAction,
2762 items: [item],
2763 closeModal: () => setActiveModalAction(null)
2764 }
2765 )
2766 ] });
2767 }
2768
2769 // packages/dataviews/build-module/components/dataviews-bulk-actions/index.mjs
2770 var import_components3 = __toESM(require_components(), 1);
2771 var import_i18n11 = __toESM(require_i18n(), 1);
2772 var import_element6 = __toESM(require_element(), 1);
2773 var import_data2 = __toESM(require_data(), 1);
2774 var import_compose2 = __toESM(require_compose(), 1);
2775
2776 // packages/dataviews/build-module/utils/get-footer-message.mjs
2777 var import_i18n10 = __toESM(require_i18n(), 1);
2778 function getFooterMessage(selectionCount, itemsCount, totalItems, onlyTotalCount = false) {
2779 if (selectionCount > 0) {
2780 return (0, import_i18n10.sprintf)(
2781 /* translators: %d: number of items. */
2782 (0, import_i18n10._n)("%d Item selected", "%d Items selected", selectionCount),
2783 selectionCount
2784 );
2785 }
2786 if (onlyTotalCount || totalItems <= itemsCount) {
2787 return (0, import_i18n10.sprintf)(
2788 /* translators: %d: number of items. */
2789 (0, import_i18n10._n)("%d Item", "%d Items", totalItems),
2790 totalItems
2791 );
2792 }
2793 return (0, import_i18n10.sprintf)(
2794 /* translators: %1$d: number of items. %2$d: total number of items. */
2795 (0, import_i18n10._n)("%1$d of %2$d Item", "%1$d of %2$d Items", totalItems),
2796 itemsCount,
2797 totalItems
2798 );
2799 }
2800
2801 // packages/dataviews/build-module/components/dataviews-bulk-actions/index.mjs
2802 var import_jsx_runtime33 = __toESM(require_jsx_runtime(), 1);
2803 function useHasAPossibleBulkAction(actions, item) {
2804 return (0, import_element6.useMemo)(() => {
2805 return actions.some((action) => {
2806 return action.supportsBulk && (!action.isEligible || action.isEligible(item));
2807 });
2808 }, [actions, item]);
2809 }
2810 function useSomeItemHasAPossibleBulkAction(actions, data) {
2811 return (0, import_element6.useMemo)(() => {
2812 return data.some((item) => {
2813 return actions.some((action) => {
2814 return action.supportsBulk && (!action.isEligible || action.isEligible(item));
2815 });
2816 });
2817 }, [actions, data]);
2818 }
2819 function BulkSelectionCheckbox({
2820 selection,
2821 onChangeSelection,
2822 data,
2823 actions,
2824 getItemId,
2825 disableSelectAll = false
2826 }) {
2827 const selectableItems = (0, import_element6.useMemo)(() => {
2828 return data.filter((item) => {
2829 return actions.some(
2830 (action) => action.supportsBulk && (!action.isEligible || action.isEligible(item))
2831 );
2832 });
2833 }, [data, actions]);
2834 const selectedItems = data.filter(
2835 (item) => selection.includes(getItemId(item)) && selectableItems.includes(item)
2836 );
2837 const hasSelection = selection.length > 0;
2838 const areAllSelected = selectedItems.length === selectableItems.length;
2839 if (disableSelectAll) {
2840 return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2841 import_components3.CheckboxControl,
2842 {
2843 className: "dataviews-view-table-selection-checkbox",
2844 checked: hasSelection,
2845 disabled: !hasSelection,
2846 onChange: () => {
2847 onChangeSelection([]);
2848 },
2849 "aria-label": (0, import_i18n11.__)("Deselect all")
2850 }
2851 );
2852 }
2853 return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2854 import_components3.CheckboxControl,
2855 {
2856 className: "dataviews-view-table-selection-checkbox",
2857 checked: areAllSelected,
2858 indeterminate: !areAllSelected && !!selectedItems.length,
2859 onChange: () => {
2860 if (areAllSelected) {
2861 onChangeSelection([]);
2862 } else {
2863 onChangeSelection(
2864 selectableItems.map((item) => getItemId(item))
2865 );
2866 }
2867 },
2868 "aria-label": areAllSelected ? (0, import_i18n11.__)("Deselect all") : (0, import_i18n11.__)("Select all")
2869 }
2870 );
2871 }
2872
2873 // packages/dataviews/build-module/components/dataviews-layouts/table/column-header-menu.mjs
2874 var import_i18n12 = __toESM(require_i18n(), 1);
2875 var import_components4 = __toESM(require_components(), 1);
2876 var import_element7 = __toESM(require_element(), 1);
2877
2878 // packages/dataviews/build-module/utils/get-hideable-fields.mjs
2879 function getHideableFields(view, fields) {
2880 const togglableFields = [
2881 view?.titleField,
2882 view?.mediaField,
2883 view?.descriptionField
2884 ].filter(Boolean);
2885 return fields.filter(
2886 (f2) => !togglableFields.includes(f2.id) && f2.type !== "media" && f2.enableHiding !== false
2887 );
2888 }
2889
2890 // packages/dataviews/build-module/components/dataviews-layouts/table/column-header-menu.mjs
2891 var import_jsx_runtime34 = __toESM(require_jsx_runtime(), 1);
2892 var { Menu: Menu2 } = unlock(import_components4.privateApis);
2893 function WithMenuSeparators({ children }) {
2894 return import_element7.Children.toArray(children).filter(Boolean).map((child, i2) => /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_element7.Fragment, { children: [
2895 i2 > 0 && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Separator, {}),
2896 child
2897 ] }, i2));
2898 }
2899 var _HeaderMenu = (0, import_element7.forwardRef)(function HeaderMenu({
2900 fieldId,
2901 view,
2902 fields,
2903 onChangeView,
2904 onHide,
2905 setOpenedFilter,
2906 canMove = true,
2907 canInsertLeft = true,
2908 canInsertRight = true
2909 }, ref) {
2910 const visibleFieldIds = view.fields ?? [];
2911 const index = visibleFieldIds?.indexOf(fieldId);
2912 const isSorted = view.sort?.field === fieldId;
2913 let isHidable = false;
2914 let isSortable = false;
2915 let canAddFilter = false;
2916 let operators = [];
2917 const field = fields.find((f2) => f2.id === fieldId);
2918 const { setIsShowingFilter } = (0, import_element7.useContext)(dataviews_context_default);
2919 if (!field) {
2920 return null;
2921 }
2922 isHidable = field.enableHiding !== false;
2923 isSortable = field.enableSorting !== false;
2924 const header = field.header;
2925 operators = !!field.filterBy && field.filterBy?.operators || [];
2926 canAddFilter = !view.filters?.some((_filter) => fieldId === _filter.field) && !!(field.hasElements || field.Edit) && field.filterBy !== false && !field.filterBy?.isPrimary;
2927 if (!isSortable && !canMove && !isHidable && !canAddFilter) {
2928 return header;
2929 }
2930 const hiddenFields = getHideableFields(view, fields).filter(
2931 (f2) => !visibleFieldIds.includes(f2.id)
2932 );
2933 const canInsert = (canInsertLeft || canInsertRight) && !!hiddenFields.length;
2934 const isRtl = (0, import_i18n12.isRTL)();
2935 return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2, { children: [
2936 /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
2937 Menu2.TriggerButton,
2938 {
2939 render: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2940 import_components4.Button,
2941 {
2942 size: "compact",
2943 className: "dataviews-view-table-header-button",
2944 ref,
2945 variant: "tertiary"
2946 }
2947 ),
2948 children: [
2949 header,
2950 view.sort && isSorted && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("span", { "aria-hidden": "true", children: sortArrows[view.sort.direction] })
2951 ]
2952 }
2953 ),
2954 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Popover, { style: { minWidth: "240px" }, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(WithMenuSeparators, { children: [
2955 isSortable && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Group, { children: SORTING_DIRECTIONS.map(
2956 (direction) => {
2957 const isChecked = view.sort && isSorted && view.sort.direction === direction;
2958 const value = `${fieldId}-${direction}`;
2959 return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2960 Menu2.RadioItem,
2961 {
2962 name: "view-table-sorting",
2963 value,
2964 checked: isChecked,
2965 onChange: () => {
2966 onChangeView({
2967 ...view,
2968 sort: {
2969 field: fieldId,
2970 direction
2971 },
2972 showLevels: false
2973 });
2974 },
2975 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: sortLabels[direction] })
2976 },
2977 value
2978 );
2979 }
2980 ) }),
2981 canAddFilter && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Group, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2982 Menu2.Item,
2983 {
2984 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: funnel_default }),
2985 onClick: () => {
2986 setOpenedFilter(fieldId);
2987 setIsShowingFilter(true);
2988 onChangeView({
2989 ...view,
2990 page: 1,
2991 filters: [
2992 ...view.filters || [],
2993 {
2994 field: fieldId,
2995 value: void 0,
2996 operator: operators[0]
2997 }
2998 ]
2999 });
3000 },
3001 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Add filter") })
3002 }
3003 ) }),
3004 (canMove || isHidable || canInsert) && field && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2.Group, { children: [
3005 canMove && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
3006 Menu2.Item,
3007 {
3008 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: arrow_left_default }),
3009 disabled: isRtl ? index >= visibleFieldIds.length - 1 : index < 1,
3010 onClick: () => {
3011 const targetIndex = isRtl ? index + 1 : index - 1;
3012 const newFields = [
3013 ...visibleFieldIds
3014 ];
3015 newFields.splice(index, 1);
3016 newFields.splice(
3017 targetIndex,
3018 0,
3019 fieldId
3020 );
3021 onChangeView({
3022 ...view,
3023 fields: newFields
3024 });
3025 },
3026 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Move left") })
3027 }
3028 ),
3029 canMove && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
3030 Menu2.Item,
3031 {
3032 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: arrow_right_default }),
3033 disabled: isRtl ? index < 1 : index >= visibleFieldIds.length - 1,
3034 onClick: () => {
3035 const targetIndex = isRtl ? index - 1 : index + 1;
3036 const newFields = [
3037 ...visibleFieldIds
3038 ];
3039 newFields.splice(index, 1);
3040 newFields.splice(
3041 targetIndex,
3042 0,
3043 fieldId
3044 );
3045 onChangeView({
3046 ...view,
3047 fields: newFields
3048 });
3049 },
3050 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Move right") })
3051 }
3052 ),
3053 canInsertLeft && !!hiddenFields.length && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2, { children: [
3054 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.SubmenuTriggerItem, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Insert left") }) }),
3055 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Popover, { children: hiddenFields.map((hiddenField) => {
3056 const insertIndex = isRtl ? index + 1 : index;
3057 return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
3058 Menu2.Item,
3059 {
3060 onClick: () => {
3061 onChangeView({
3062 ...view,
3063 fields: [
3064 ...visibleFieldIds.slice(
3065 0,
3066 insertIndex
3067 ),
3068 hiddenField.id,
3069 ...visibleFieldIds.slice(
3070 insertIndex
3071 )
3072 ]
3073 });
3074 },
3075 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: hiddenField.label })
3076 },
3077 hiddenField.id
3078 );
3079 }) })
3080 ] }),
3081 canInsertRight && !!hiddenFields.length && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2, { children: [
3082 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.SubmenuTriggerItem, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Insert right") }) }),
3083 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Popover, { children: hiddenFields.map((hiddenField) => {
3084 const insertIndex = isRtl ? index : index + 1;
3085 return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
3086 Menu2.Item,
3087 {
3088 onClick: () => {
3089 onChangeView({
3090 ...view,
3091 fields: [
3092 ...visibleFieldIds.slice(
3093 0,
3094 insertIndex
3095 ),
3096 hiddenField.id,
3097 ...visibleFieldIds.slice(
3098 insertIndex
3099 )
3100 ]
3101 });
3102 },
3103 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: hiddenField.label })
3104 },
3105 hiddenField.id
3106 );
3107 }) })
3108 ] }),
3109 isHidable && field && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
3110 Menu2.Item,
3111 {
3112 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: unseen_default }),
3113 onClick: () => {
3114 onHide(field);
3115 onChangeView({
3116 ...view,
3117 fields: visibleFieldIds.filter(
3118 (id) => id !== fieldId
3119 )
3120 });
3121 },
3122 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Hide column") })
3123 }
3124 )
3125 ] })
3126 ] }) })
3127 ] });
3128 });
3129 var ColumnHeaderMenu = _HeaderMenu;
3130 var column_header_menu_default = ColumnHeaderMenu;
3131
3132 // packages/dataviews/build-module/components/dataviews-layouts/utils/item-click-wrapper.mjs
3133 var import_element8 = __toESM(require_element(), 1);
3134 var import_jsx_runtime35 = __toESM(require_jsx_runtime(), 1);
3135 function getClickableItemProps({
3136 item,
3137 isItemClickable: isItemClickable2,
3138 onClickItem,
3139 className
3140 }) {
3141 if (!isItemClickable2(item) || !onClickItem) {
3142 return { className };
3143 }
3144 return {
3145 className: className ? `${className} ${className}--clickable` : void 0,
3146 role: "button",
3147 tabIndex: 0,
3148 onClick: (event) => {
3149 event.stopPropagation();
3150 onClickItem(item);
3151 },
3152 onKeyDown: (event) => {
3153 if (event.key === "Enter" || event.key === "" || event.key === " ") {
3154 event.stopPropagation();
3155 onClickItem(item);
3156 }
3157 }
3158 };
3159 }
3160 function ItemClickWrapper({
3161 item,
3162 isItemClickable: isItemClickable2,
3163 onClickItem,
3164 renderItemLink,
3165 className,
3166 children,
3167 ...extraProps
3168 }) {
3169 if (!isItemClickable2(item)) {
3170 return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className, ...extraProps, children });
3171 }
3172 if (renderItemLink) {
3173 const renderedElement = renderItemLink({
3174 item,
3175 className: `${className} ${className}--clickable`,
3176 ...extraProps,
3177 children
3178 });
3179 return (0, import_element8.cloneElement)(renderedElement, {
3180 onClick: (event) => {
3181 event.stopPropagation();
3182 if (renderedElement.props.onClick) {
3183 renderedElement.props.onClick(event);
3184 }
3185 },
3186 onKeyDown: (event) => {
3187 if (event.key === "Enter" || event.key === "" || event.key === " ") {
3188 event.stopPropagation();
3189 if (renderedElement.props.onKeyDown) {
3190 renderedElement.props.onKeyDown(event);
3191 }
3192 }
3193 }
3194 });
3195 }
3196 const clickProps = getClickableItemProps({
3197 item,
3198 isItemClickable: isItemClickable2,
3199 onClickItem,
3200 className
3201 });
3202 return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { ...clickProps, ...extraProps, children });
3203 }
3204
3205 // packages/dataviews/build-module/components/dataviews-layouts/table/column-primary.mjs
3206 var import_jsx_runtime36 = __toESM(require_jsx_runtime(), 1);
3207 function ColumnPrimary({
3208 item,
3209 level,
3210 titleField,
3211 mediaField,
3212 descriptionField: descriptionField2,
3213 onClickItem,
3214 renderItemLink,
3215 isItemClickable: isItemClickable2
3216 }) {
3217 return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(Stack, { direction: "row", gap: "md", align: "flex-start", justify: "flex-start", children: [
3218 mediaField && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3219 ItemClickWrapper,
3220 {
3221 item,
3222 isItemClickable: isItemClickable2,
3223 onClickItem,
3224 renderItemLink,
3225 className: "dataviews-view-table__cell-content-wrapper dataviews-column-primary__media",
3226 "aria-label": isItemClickable2(item) && (!!onClickItem || !!renderItemLink) && !!titleField ? titleField.getValue?.({ item }) : void 0,
3227 children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3228 mediaField.render,
3229 {
3230 item,
3231 field: mediaField,
3232 config: { sizes: "32px" }
3233 }
3234 )
3235 }
3236 ),
3237 /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
3238 Stack,
3239 {
3240 direction: "column",
3241 align: "flex-start",
3242 className: "dataviews-view-table__primary-column-content",
3243 children: [
3244 titleField && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
3245 ItemClickWrapper,
3246 {
3247 item,
3248 isItemClickable: isItemClickable2,
3249 onClickItem,
3250 renderItemLink,
3251 className: "dataviews-view-table__cell-content-wrapper dataviews-title-field",
3252 children: [
3253 level !== void 0 && level > 0 && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("span", { className: "dataviews-view-table__level", children: [
3254 Array(level).fill("\u2014").join(" "),
3255 "\xA0"
3256 ] }),
3257 /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(titleField.render, { item, field: titleField })
3258 ]
3259 }
3260 ),
3261 descriptionField2 && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3262 descriptionField2.render,
3263 {
3264 item,
3265 field: descriptionField2
3266 }
3267 )
3268 ]
3269 }
3270 )
3271 ] });
3272 }
3273 var column_primary_default = ColumnPrimary;
3274
3275 // packages/dataviews/build-module/components/dataviews-layouts/table/use-scroll-state.mjs
3276 var import_element9 = __toESM(require_element(), 1);
3277 var import_i18n13 = __toESM(require_i18n(), 1);
3278 var isScrolledToEnd = (element) => {
3279 if ((0, import_i18n13.isRTL)()) {
3280 const scrollLeft = Math.abs(element.scrollLeft);
3281 return scrollLeft <= 1;
3282 }
3283 return element.scrollLeft + element.clientWidth >= element.scrollWidth - 1;
3284 };
3285 function useScrollState({
3286 scrollContainerRef,
3287 enabledHorizontal = false
3288 }) {
3289 const [isHorizontalScrollEnd, setIsHorizontalScrollEnd] = (0, import_element9.useState)(false);
3290 const [isVerticallyScrolled, setIsVerticallyScrolled] = (0, import_element9.useState)(false);
3291 const handleScroll = (0, import_element9.useCallback)(() => {
3292 const scrollContainer = scrollContainerRef.current;
3293 if (!scrollContainer) {
3294 return;
3295 }
3296 if (enabledHorizontal) {
3297 setIsHorizontalScrollEnd(isScrolledToEnd(scrollContainer));
3298 }
3299 setIsVerticallyScrolled(scrollContainer.scrollTop > 0);
3300 }, [scrollContainerRef, enabledHorizontal]);
3301 (0, import_element9.useEffect)(() => {
3302 if (typeof window === "undefined" || !scrollContainerRef.current) {
3303 return () => {
3304 };
3305 }
3306 const scrollContainer = scrollContainerRef.current;
3307 handleScroll();
3308 scrollContainer.addEventListener("scroll", handleScroll);
3309 window.addEventListener("resize", handleScroll);
3310 return () => {
3311 scrollContainer.removeEventListener("scroll", handleScroll);
3312 window.removeEventListener("resize", handleScroll);
3313 };
3314 }, [scrollContainerRef, enabledHorizontal, handleScroll]);
3315 return { isHorizontalScrollEnd, isVerticallyScrolled };
3316 }
3317
3318 // packages/dataviews/build-module/components/dataviews-layouts/utils/get-data-by-group.mjs
3319 function getDataByGroup(data, groupByField) {
3320 return data.reduce((groups, item) => {
3321 const groupName = groupByField.getValue({ item });
3322 if (!groups.has(groupName)) {
3323 groups.set(groupName, []);
3324 }
3325 groups.get(groupName)?.push(item);
3326 return groups;
3327 }, /* @__PURE__ */ new Map());
3328 }
3329
3330 // packages/dataviews/build-module/components/dataviews-view-config/properties-section.mjs
3331 var import_components5 = __toESM(require_components(), 1);
3332 var import_i18n14 = __toESM(require_i18n(), 1);
3333 var import_element10 = __toESM(require_element(), 1);
3334 var import_jsx_runtime37 = __toESM(require_jsx_runtime(), 1);
3335 function FieldItem({
3336 field,
3337 isVisible: isVisible2,
3338 onToggleVisibility
3339 }) {
3340 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: [
3341 /* @__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 }) }),
3342 /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("span", { className: "dataviews-view-config__label", children: field.label })
3343 ] }) });
3344 }
3345 function isDefined(item) {
3346 return !!item;
3347 }
3348 function PropertiesSection({
3349 showLabel = true
3350 }) {
3351 const { view, fields, onChangeView } = (0, import_element10.useContext)(dataviews_context_default);
3352 const regularFields = getHideableFields(view, fields);
3353 if (!regularFields?.length) {
3354 return null;
3355 }
3356 const titleField = fields.find((f2) => f2.id === view.titleField);
3357 const previewField = fields.find((f2) => f2.id === view.mediaField);
3358 const descriptionField2 = fields.find(
3359 (f2) => f2.id === view.descriptionField
3360 );
3361 const lockedFields = [
3362 {
3363 field: titleField,
3364 isVisibleFlag: "showTitle"
3365 },
3366 {
3367 field: previewField,
3368 isVisibleFlag: "showMedia"
3369 },
3370 {
3371 field: descriptionField2,
3372 isVisibleFlag: "showDescription"
3373 }
3374 ].filter(({ field }) => isDefined(field));
3375 const visibleFieldIds = view.fields ?? [];
3376 const visibleRegularFieldsCount = regularFields.filter(
3377 (f2) => visibleFieldIds.includes(f2.id)
3378 ).length;
3379 const visibleLockedFields = lockedFields.filter(
3380 ({ isVisibleFlag }) => (
3381 // @ts-expect-error
3382 view[isVisibleFlag] ?? true
3383 )
3384 );
3385 const totalVisibleFields = visibleLockedFields.length + visibleRegularFieldsCount;
3386 const isSingleVisibleLockedField = totalVisibleFields === 1 && visibleLockedFields.length === 1;
3387 return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(Stack, { direction: "column", className: "dataviews-field-control", children: [
3388 showLabel && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_components5.BaseControl.VisualLabel, { children: (0, import_i18n14.__)("Properties") }),
3389 /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3390 Stack,
3391 {
3392 direction: "column",
3393 className: "dataviews-view-config__properties",
3394 children: /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(import_components5.__experimentalItemGroup, { isBordered: true, isSeparated: true, size: "medium", children: [
3395 lockedFields.map(({ field, isVisibleFlag }) => {
3396 const isVisible2 = view[isVisibleFlag] ?? true;
3397 const fieldToRender = isSingleVisibleLockedField && isVisible2 ? { ...field, enableHiding: false } : field;
3398 return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3399 FieldItem,
3400 {
3401 field: fieldToRender,
3402 isVisible: isVisible2,
3403 onToggleVisibility: () => {
3404 onChangeView({
3405 ...view,
3406 [isVisibleFlag]: !isVisible2
3407 });
3408 }
3409 },
3410 field.id
3411 );
3412 }),
3413 regularFields.map((field) => {
3414 const isVisible2 = visibleFieldIds.includes(field.id);
3415 const fieldToRender = totalVisibleFields === 1 && isVisible2 ? { ...field, enableHiding: false } : field;
3416 return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3417 FieldItem,
3418 {
3419 field: fieldToRender,
3420 isVisible: isVisible2,
3421 onToggleVisibility: () => {
3422 onChangeView({
3423 ...view,
3424 fields: isVisible2 ? visibleFieldIds.filter(
3425 (fieldId) => fieldId !== field.id
3426 ) : [...visibleFieldIds, field.id]
3427 });
3428 }
3429 },
3430 field.id
3431 );
3432 })
3433 ] })
3434 }
3435 )
3436 ] });
3437 }
3438
3439 // packages/dataviews/build-module/hooks/use-delayed-loading.mjs
3440 var import_element11 = __toESM(require_element(), 1);
3441 function useDelayedLoading(isLoading, options = { delay: 400 }) {
3442 const [showLoader, setShowLoader] = (0, import_element11.useState)(false);
3443 (0, import_element11.useEffect)(() => {
3444 if (!isLoading) {
3445 return;
3446 }
3447 const timeout = setTimeout(() => {
3448 setShowLoader(true);
3449 }, options.delay);
3450 return () => {
3451 clearTimeout(timeout);
3452 setShowLoader(false);
3453 };
3454 }, [isLoading, options.delay]);
3455 return showLoader;
3456 }
3457
3458 // packages/dataviews/build-module/components/dataviews-layouts/table/index.mjs
3459 var import_jsx_runtime38 = __toESM(require_jsx_runtime(), 1);
3460 function getEffectiveAlign(explicitAlign, fieldType) {
3461 if (explicitAlign) {
3462 return explicitAlign;
3463 }
3464 if (fieldType === "integer" || fieldType === "number") {
3465 return "end";
3466 }
3467 return void 0;
3468 }
3469 function TableColumnField({
3470 item,
3471 fields,
3472 column,
3473 align
3474 }) {
3475 const field = fields.find((f2) => f2.id === column);
3476 if (!field) {
3477 return null;
3478 }
3479 const className = clsx_default("dataviews-view-table__cell-content-wrapper", {
3480 "dataviews-view-table__cell-align-end": align === "end",
3481 "dataviews-view-table__cell-align-center": align === "center"
3482 });
3483 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(field.render, { item, field }) });
3484 }
3485 function TableRow({
3486 hasBulkActions,
3487 item,
3488 level,
3489 actions,
3490 fields,
3491 id,
3492 view,
3493 titleField,
3494 mediaField,
3495 descriptionField: descriptionField2,
3496 selection,
3497 getItemId,
3498 isItemClickable: isItemClickable2,
3499 onClickItem,
3500 renderItemLink,
3501 onChangeSelection,
3502 isActionsColumnSticky,
3503 posinset
3504 }) {
3505 const { paginationInfo } = (0, import_element12.useContext)(dataviews_context_default);
3506 const hasPossibleBulkAction = useHasAPossibleBulkAction(actions, item);
3507 const isSelected2 = hasPossibleBulkAction && selection.includes(id);
3508 const {
3509 showTitle = true,
3510 showMedia = true,
3511 showDescription = true,
3512 infiniteScrollEnabled
3513 } = view;
3514 const isTouchDeviceRef = (0, import_element12.useRef)(false);
3515 const columns = view.fields ?? [];
3516 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
3517 return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
3518 "tr",
3519 {
3520 className: clsx_default("dataviews-view-table__row", {
3521 "is-selected": hasPossibleBulkAction && isSelected2,
3522 "has-bulk-actions": hasPossibleBulkAction
3523 }),
3524 onTouchStart: () => {
3525 isTouchDeviceRef.current = true;
3526 },
3527 "aria-setsize": infiniteScrollEnabled ? paginationInfo.totalItems : void 0,
3528 "aria-posinset": posinset,
3529 role: infiniteScrollEnabled ? "article" : void 0,
3530 onMouseDown: (event) => {
3531 const isMetaClick = (0, import_keycodes.isAppleOS)() ? event.metaKey : event.ctrlKey;
3532 if (event.button === 0 && isMetaClick && window.navigator.userAgent.toLowerCase().includes("firefox")) {
3533 event?.preventDefault();
3534 }
3535 },
3536 onClick: (event) => {
3537 if (!hasPossibleBulkAction) {
3538 return;
3539 }
3540 const isModifierKeyPressed = (0, import_keycodes.isAppleOS)() ? event.metaKey : event.ctrlKey;
3541 if (isModifierKeyPressed && !isTouchDeviceRef.current && document.getSelection()?.type !== "Range") {
3542 onChangeSelection(
3543 selection.includes(id) ? selection.filter((itemId) => id !== itemId) : [...selection, id]
3544 );
3545 }
3546 },
3547 children: [
3548 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)(
3549 DataViewsSelectionCheckbox,
3550 {
3551 item,
3552 selection,
3553 onChangeSelection,
3554 getItemId,
3555 titleField,
3556 disabled: !hasPossibleBulkAction
3557 }
3558 ) }) }),
3559 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3560 column_primary_default,
3561 {
3562 item,
3563 level,
3564 titleField: showTitle ? titleField : void 0,
3565 mediaField: showMedia ? mediaField : void 0,
3566 descriptionField: showDescription ? descriptionField2 : void 0,
3567 isItemClickable: isItemClickable2,
3568 onClickItem,
3569 renderItemLink
3570 }
3571 ) }),
3572 columns.map((column) => {
3573 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
3574 const field = fields.find((f2) => f2.id === column);
3575 const effectiveAlign = getEffectiveAlign(align, field?.type);
3576 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3577 "td",
3578 {
3579 style: {
3580 width,
3581 maxWidth,
3582 minWidth
3583 },
3584 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3585 TableColumnField,
3586 {
3587 fields,
3588 item,
3589 column,
3590 align: effectiveAlign
3591 }
3592 )
3593 },
3594 column
3595 );
3596 }),
3597 !!actions?.length && // Disable reason: we are not making the element interactive,
3598 // but preventing any click events from bubbling up to the
3599 // table row. This allows us to add a click handler to the row
3600 // itself (to toggle row selection) without erroneously
3601 // intercepting click events from ItemActions.
3602 /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3603 "td",
3604 {
3605 className: clsx_default("dataviews-view-table__actions-column", {
3606 "dataviews-view-table__actions-column--sticky": true,
3607 "dataviews-view-table__actions-column--stuck": isActionsColumnSticky
3608 }),
3609 onClick: (e2) => e2.stopPropagation(),
3610 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(ItemActions, { item, actions })
3611 }
3612 )
3613 ]
3614 }
3615 );
3616 }
3617 function ViewTable({
3618 actions,
3619 data,
3620 fields,
3621 getItemId,
3622 getItemLevel,
3623 isLoading = false,
3624 onChangeView,
3625 onChangeSelection,
3626 selection,
3627 setOpenedFilter,
3628 onClickItem,
3629 isItemClickable: isItemClickable2,
3630 renderItemLink,
3631 view,
3632 className,
3633 empty
3634 }) {
3635 const { containerRef } = (0, import_element12.useContext)(dataviews_context_default);
3636 const isDelayedLoading = useDelayedLoading(isLoading);
3637 const headerMenuRefs = (0, import_element12.useRef)(/* @__PURE__ */ new Map());
3638 const headerMenuToFocusRef = (0, import_element12.useRef)(void 0);
3639 const [nextHeaderMenuToFocus, setNextHeaderMenuToFocus] = (0, import_element12.useState)();
3640 const [contextMenuAnchor, setContextMenuAnchor] = (0, import_element12.useState)(null);
3641 (0, import_element12.useEffect)(() => {
3642 if (headerMenuToFocusRef.current) {
3643 headerMenuToFocusRef.current.focus();
3644 headerMenuToFocusRef.current = void 0;
3645 }
3646 });
3647 const tableNoticeId = (0, import_element12.useId)();
3648 const { isHorizontalScrollEnd, isVerticallyScrolled } = useScrollState({
3649 scrollContainerRef: containerRef,
3650 enabledHorizontal: !!actions?.length
3651 });
3652 const hasBulkActions = useSomeItemHasAPossibleBulkAction(actions, data);
3653 if (nextHeaderMenuToFocus) {
3654 headerMenuToFocusRef.current = nextHeaderMenuToFocus;
3655 setNextHeaderMenuToFocus(void 0);
3656 return;
3657 }
3658 const onHide = (field) => {
3659 const hidden = headerMenuRefs.current.get(field.id);
3660 const fallback = hidden ? headerMenuRefs.current.get(hidden.fallback) : void 0;
3661 setNextHeaderMenuToFocus(fallback?.node);
3662 };
3663 const handleHeaderContextMenu = (event) => {
3664 event.preventDefault();
3665 event.stopPropagation();
3666 const virtualAnchor = {
3667 getBoundingClientRect: () => ({
3668 x: event.clientX,
3669 y: event.clientY,
3670 top: event.clientY,
3671 left: event.clientX,
3672 right: event.clientX,
3673 bottom: event.clientY,
3674 width: 0,
3675 height: 0,
3676 toJSON: () => ({})
3677 })
3678 };
3679 window.requestAnimationFrame(() => {
3680 setContextMenuAnchor(virtualAnchor);
3681 });
3682 };
3683 const hasData = !!data?.length;
3684 const titleField = fields.find((field) => field.id === view.titleField);
3685 const mediaField = fields.find((field) => field.id === view.mediaField);
3686 const descriptionField2 = fields.find(
3687 (field) => field.id === view.descriptionField
3688 );
3689 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
3690 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
3691 const { showTitle = true, showMedia = true, showDescription = true } = view;
3692 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
3693 const columns = view.fields ?? [];
3694 const headerMenuRef = (column, index) => (node) => {
3695 if (node) {
3696 headerMenuRefs.current.set(column, {
3697 node,
3698 fallback: columns[index > 0 ? index - 1 : 1]
3699 });
3700 } else {
3701 headerMenuRefs.current.delete(column);
3702 }
3703 };
3704 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
3705 const isRtl = (0, import_i18n15.isRTL)();
3706 if (!hasData) {
3707 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3708 "div",
3709 {
3710 className: clsx_default("dataviews-no-results", {
3711 "is-refreshing": isDelayedLoading
3712 }),
3713 id: tableNoticeId,
3714 children: empty
3715 }
3716 );
3717 }
3718 return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(import_jsx_runtime38.Fragment, { children: [
3719 /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
3720 "table",
3721 {
3722 className: clsx_default("dataviews-view-table", className, {
3723 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
3724 view.layout.density
3725 ),
3726 "has-bulk-actions": hasBulkActions,
3727 "is-refreshing": !isInfiniteScroll && isDelayedLoading
3728 }),
3729 "aria-busy": isLoading,
3730 "aria-describedby": tableNoticeId,
3731 role: isInfiniteScroll ? "feed" : void 0,
3732 inert: !isInfiniteScroll && isLoading ? "true" : void 0,
3733 children: [
3734 /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("colgroup", { children: [
3735 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("col", { className: "dataviews-view-table__col-checkbox" }),
3736 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("col", { className: "dataviews-view-table__col-first-data" }),
3737 columns.map((column, index) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3738 "col",
3739 {
3740 className: clsx_default(
3741 `dataviews-view-table__col-${column}`,
3742 {
3743 "dataviews-view-table__col-expand": !hasPrimaryColumn && index === columns.length - 1
3744 }
3745 )
3746 },
3747 `col-${column}`
3748 )),
3749 !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("col", { className: "dataviews-view-table__col-actions" })
3750 ] }),
3751 contextMenuAnchor && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3752 import_components6.Popover,
3753 {
3754 anchor: contextMenuAnchor,
3755 onClose: () => setContextMenuAnchor(null),
3756 placement: "bottom-start",
3757 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(PropertiesSection, { showLabel: false })
3758 }
3759 ),
3760 /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3761 "thead",
3762 {
3763 className: clsx_default({
3764 "dataviews-view-table__thead--stuck": isVerticallyScrolled
3765 }),
3766 onContextMenu: handleHeaderContextMenu,
3767 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("tr", { className: "dataviews-view-table__row", children: [
3768 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3769 "th",
3770 {
3771 className: "dataviews-view-table__checkbox-column",
3772 scope: "col",
3773 onContextMenu: handleHeaderContextMenu,
3774 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3775 BulkSelectionCheckbox,
3776 {
3777 selection,
3778 onChangeSelection,
3779 data,
3780 actions,
3781 getItemId
3782 }
3783 )
3784 }
3785 ),
3786 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("th", { scope: "col", children: titleField && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3787 column_header_menu_default,
3788 {
3789 ref: headerMenuRef(
3790 titleField.id,
3791 0
3792 ),
3793 fieldId: titleField.id,
3794 view,
3795 fields,
3796 onChangeView,
3797 onHide,
3798 setOpenedFilter,
3799 canMove: false,
3800 canInsertLeft: isRtl ? view.layout?.enableMoving ?? true : false,
3801 canInsertRight: isRtl ? false : view.layout?.enableMoving ?? true
3802 }
3803 ) }),
3804 columns.map((column, index) => {
3805 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
3806 const field = fields.find(
3807 (f2) => f2.id === column
3808 );
3809 const effectiveAlign = getEffectiveAlign(
3810 align,
3811 field?.type
3812 );
3813 const canInsertOrMove = view.layout?.enableMoving ?? true;
3814 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3815 "th",
3816 {
3817 style: {
3818 width,
3819 maxWidth,
3820 minWidth,
3821 textAlign: effectiveAlign
3822 },
3823 "aria-sort": view.sort?.direction && view.sort?.field === column ? sortValues[view.sort.direction] : void 0,
3824 scope: "col",
3825 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3826 column_header_menu_default,
3827 {
3828 ref: headerMenuRef(column, index),
3829 fieldId: column,
3830 view,
3831 fields,
3832 onChangeView,
3833 onHide,
3834 setOpenedFilter,
3835 canMove: canInsertOrMove,
3836 canInsertLeft: canInsertOrMove,
3837 canInsertRight: canInsertOrMove
3838 }
3839 )
3840 },
3841 column
3842 );
3843 }),
3844 !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3845 "th",
3846 {
3847 className: clsx_default(
3848 "dataviews-view-table__actions-column",
3849 {
3850 "dataviews-view-table__actions-column--sticky": true,
3851 "dataviews-view-table__actions-column--stuck": !isHorizontalScrollEnd
3852 }
3853 ),
3854 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("span", { className: "dataviews-view-table-header", children: (0, import_i18n15.__)("Actions") })
3855 }
3856 )
3857 ] })
3858 }
3859 ),
3860 hasData && groupField && dataByGroup ? Array.from(dataByGroup.entries()).map(
3861 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("tbody", { children: [
3862 /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("tr", { className: "dataviews-view-table__group-header-row", children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3863 "td",
3864 {
3865 colSpan: columns.length + (hasPrimaryColumn ? 1 : 0) + (hasBulkActions ? 1 : 0) + (actions?.length ? 1 : 0),
3866 className: "dataviews-view-table__group-header-cell",
3867 children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n15.sprintf)(
3868 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
3869 (0, import_i18n15.__)("%1$s: %2$s"),
3870 groupField.label,
3871 groupName
3872 )
3873 }
3874 ) }),
3875 groupItems.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3876 TableRow,
3877 {
3878 item,
3879 level: view.showLevels && typeof getItemLevel === "function" ? getItemLevel(item) : void 0,
3880 hasBulkActions,
3881 actions,
3882 fields,
3883 id: getItemId(item) || index.toString(),
3884 view,
3885 titleField,
3886 mediaField,
3887 descriptionField: descriptionField2,
3888 selection,
3889 getItemId,
3890 onChangeSelection,
3891 onClickItem,
3892 renderItemLink,
3893 isItemClickable: isItemClickable2,
3894 isActionsColumnSticky: !isHorizontalScrollEnd
3895 },
3896 getItemId(item)
3897 ))
3898 ] }, `group-${groupName}`)
3899 ) : /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("tbody", { children: hasData && data.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3900 TableRow,
3901 {
3902 item,
3903 level: view.showLevels && typeof getItemLevel === "function" ? getItemLevel(item) : void 0,
3904 hasBulkActions,
3905 actions,
3906 fields,
3907 id: getItemId(item) || index.toString(),
3908 view,
3909 titleField,
3910 mediaField,
3911 descriptionField: descriptionField2,
3912 selection,
3913 getItemId,
3914 onChangeSelection,
3915 onClickItem,
3916 renderItemLink,
3917 isItemClickable: isItemClickable2,
3918 isActionsColumnSticky: !isHorizontalScrollEnd,
3919 posinset: isInfiniteScroll ? index + 1 : void 0
3920 },
3921 getItemId(item)
3922 )) })
3923 ]
3924 }
3925 ),
3926 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, {}) }) })
3927 ] });
3928 }
3929 var table_default = ViewTable;
3930
3931 // packages/dataviews/build-module/components/dataviews-layouts/grid/index.mjs
3932 var import_components9 = __toESM(require_components(), 1);
3933 var import_i18n18 = __toESM(require_i18n(), 1);
3934
3935 // packages/dataviews/build-module/components/dataviews-layouts/grid/composite-grid.mjs
3936 var import_components8 = __toESM(require_components(), 1);
3937 var import_i18n17 = __toESM(require_i18n(), 1);
3938 var import_compose3 = __toESM(require_compose(), 1);
3939 var import_keycodes2 = __toESM(require_keycodes(), 1);
3940 var import_element16 = __toESM(require_element(), 1);
3941
3942 // packages/dataviews/build-module/components/dataviews-layouts/grid/preview-size-picker.mjs
3943 var import_components7 = __toESM(require_components(), 1);
3944 var import_i18n16 = __toESM(require_i18n(), 1);
3945 var import_element13 = __toESM(require_element(), 1);
3946 var import_jsx_runtime39 = __toESM(require_jsx_runtime(), 1);
3947 var imageSizes = [
3948 {
3949 value: 120,
3950 breakpoint: 1
3951 },
3952 {
3953 value: 170,
3954 breakpoint: 1
3955 },
3956 {
3957 value: 230,
3958 breakpoint: 1
3959 },
3960 {
3961 value: 290,
3962 breakpoint: 1112
3963 // at minimum image width, 4 images display at this container size
3964 },
3965 {
3966 value: 350,
3967 breakpoint: 1636
3968 // at minimum image width, 6 images display at this container size
3969 },
3970 {
3971 value: 430,
3972 breakpoint: 588
3973 // at minimum image width, 2 images display at this container size
3974 }
3975 ];
3976 var DEFAULT_PREVIEW_SIZE = imageSizes[2].value;
3977 function useGridColumns() {
3978 const context = (0, import_element13.useContext)(dataviews_context_default);
3979 const view = context.view;
3980 return (0, import_element13.useMemo)(() => {
3981 const containerWidth = context.containerWidth;
3982 const gap = 32;
3983 const previewSize = view.layout?.previewSize ?? DEFAULT_PREVIEW_SIZE;
3984 const columns = Math.floor(
3985 (containerWidth + gap) / (previewSize + gap)
3986 );
3987 return Math.max(1, columns);
3988 }, [context.containerWidth, view.layout?.previewSize]);
3989 }
3990
3991 // packages/dataviews/build-module/components/dataviews-layouts/utils/grid-items.mjs
3992 var import_element14 = __toESM(require_element(), 1);
3993 var import_jsx_runtime40 = __toESM(require_jsx_runtime(), 1);
3994 var GridItems = (0, import_element14.forwardRef)(({ className, previewSize, ...props }, ref) => {
3995 return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3996 "div",
3997 {
3998 ref,
3999 className: clsx_default("dataviews-view-grid-items", className),
4000 style: {
4001 gridTemplateColumns: previewSize && `repeat(auto-fill, minmax(${previewSize}px, 1fr))`
4002 },
4003 ...props
4004 }
4005 );
4006 });
4007
4008 // packages/dataviews/build-module/components/dataviews-layouts/utils/use-infinite-scroll.mjs
4009 var import_element15 = __toESM(require_element(), 1);
4010 function useIntersectionObserver(elementRef, posinset) {
4011 const { intersectionObserver } = (0, import_element15.useContext)(dataviews_context_default);
4012 (0, import_element15.useEffect)(() => {
4013 const element = elementRef.current;
4014 if (!element || posinset === void 0 || !intersectionObserver) {
4015 return;
4016 }
4017 intersectionObserver.observe(element);
4018 return () => {
4019 intersectionObserver.unobserve(element);
4020 };
4021 }, [elementRef, intersectionObserver, posinset]);
4022 }
4023 function usePlaceholdersNeeded(data, isInfiniteScroll, gridColumns) {
4024 const hasData = !!data?.length;
4025 const firstItemPosition = hasData && isInfiniteScroll ? data[0].position : void 0;
4026 return firstItemPosition && gridColumns ? (firstItemPosition - 1) % gridColumns : 0;
4027 }
4028
4029 // packages/dataviews/build-module/components/dataviews-layouts/grid/composite-grid.mjs
4030 var import_jsx_runtime41 = __toESM(require_jsx_runtime(), 1);
4031 var { Badge: WCBadge } = unlock(import_components8.privateApis);
4032 function chunk(array, size) {
4033 const chunks = [];
4034 for (let i2 = 0, j2 = array.length; i2 < j2; i2 += size) {
4035 chunks.push(array.slice(i2, i2 + size));
4036 }
4037 return chunks;
4038 }
4039 var GridItem = (0, import_element16.forwardRef)(
4040 function GridItem2({
4041 view,
4042 selection,
4043 onChangeSelection,
4044 onClickItem,
4045 isItemClickable: isItemClickable2,
4046 renderItemLink,
4047 getItemId,
4048 item,
4049 actions,
4050 mediaField,
4051 titleField,
4052 descriptionField: descriptionField2,
4053 regularFields,
4054 badgeFields,
4055 hasBulkActions,
4056 config,
4057 posinset,
4058 setsize,
4059 ...props
4060 }, forwardedRef) {
4061 const {
4062 showTitle = true,
4063 showMedia = true,
4064 showDescription = true
4065 } = view;
4066 const hasBulkAction = useHasAPossibleBulkAction(actions, item);
4067 const id = getItemId(item);
4068 const elementRef = (0, import_element16.useRef)(null);
4069 const setRefs = (0, import_element16.useCallback)(
4070 (node) => {
4071 elementRef.current = node;
4072 if (typeof forwardedRef === "function") {
4073 forwardedRef(node);
4074 } else if (forwardedRef) {
4075 forwardedRef.current = node;
4076 }
4077 },
4078 [forwardedRef]
4079 );
4080 useIntersectionObserver(elementRef, posinset);
4081 const instanceId = (0, import_compose3.useInstanceId)(GridItem2);
4082 const isSelected2 = selection.includes(id);
4083 const mediaPlaceholder = /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("span", { className: "dataviews-view-grid__media-placeholder" });
4084 const rendersMediaField = showMedia && mediaField?.render;
4085 const renderedMediaField = rendersMediaField ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4086 mediaField.render,
4087 {
4088 item,
4089 field: mediaField,
4090 config
4091 }
4092 ) : mediaPlaceholder;
4093 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(titleField.render, { item, field: titleField }) : null;
4094 let mediaA11yProps;
4095 let titleA11yProps;
4096 if (isItemClickable2(item) && onClickItem) {
4097 if (renderedTitleField) {
4098 mediaA11yProps = {
4099 "aria-labelledby": `dataviews-view-grid__title-field-${instanceId}`
4100 };
4101 titleA11yProps = {
4102 id: `dataviews-view-grid__title-field-${instanceId}`
4103 };
4104 } else {
4105 mediaA11yProps = {
4106 "aria-label": (0, import_i18n17.__)("Navigate to item")
4107 };
4108 }
4109 }
4110 return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
4111 Stack,
4112 {
4113 direction: "column",
4114 ...props,
4115 ref: setRefs,
4116 "aria-setsize": setsize,
4117 "aria-posinset": posinset,
4118 className: clsx_default(
4119 props.className,
4120 "dataviews-view-grid__row__gridcell",
4121 "dataviews-view-grid__card",
4122 {
4123 "is-selected": hasBulkAction && isSelected2
4124 }
4125 ),
4126 onClickCapture: (event) => {
4127 props.onClickCapture?.(event);
4128 if ((0, import_keycodes2.isAppleOS)() ? event.metaKey : event.ctrlKey) {
4129 event.stopPropagation();
4130 event.preventDefault();
4131 if (!hasBulkAction) {
4132 return;
4133 }
4134 onChangeSelection(
4135 isSelected2 ? selection.filter(
4136 (itemId) => id !== itemId
4137 ) : [...selection, id]
4138 );
4139 }
4140 },
4141 children: [
4142 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4143 ItemClickWrapper,
4144 {
4145 item,
4146 isItemClickable: isItemClickable2,
4147 onClickItem,
4148 renderItemLink,
4149 className: clsx_default("dataviews-view-grid__media", {
4150 "dataviews-view-grid__media--placeholder": !rendersMediaField
4151 }),
4152 ...mediaA11yProps,
4153 children: renderedMediaField
4154 }
4155 ),
4156 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4157 DataViewsSelectionCheckbox,
4158 {
4159 item,
4160 selection,
4161 onChangeSelection,
4162 getItemId,
4163 titleField,
4164 disabled: !hasBulkAction
4165 }
4166 ),
4167 !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "dataviews-view-grid__media-actions", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4168 ItemActions,
4169 {
4170 item,
4171 actions,
4172 isCompact: true
4173 }
4174 ) }),
4175 showTitle && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "dataviews-view-grid__title", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4176 ItemClickWrapper,
4177 {
4178 item,
4179 isItemClickable: isItemClickable2,
4180 onClickItem,
4181 renderItemLink,
4182 className: "dataviews-view-grid__title-field dataviews-title-field",
4183 ...titleA11yProps,
4184 title: titleField?.getValueFormatted({
4185 item,
4186 field: titleField
4187 }) || void 0,
4188 children: renderedTitleField
4189 }
4190 ) }),
4191 /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(Stack, { direction: "column", gap: "xs", children: [
4192 showDescription && descriptionField2?.render && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4193 descriptionField2.render,
4194 {
4195 item,
4196 field: descriptionField2
4197 }
4198 ),
4199 !!badgeFields?.length && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4200 Stack,
4201 {
4202 direction: "row",
4203 className: "dataviews-view-grid__badge-fields",
4204 gap: "sm",
4205 wrap: "wrap",
4206 align: "top",
4207 justify: "flex-start",
4208 children: badgeFields.map((field) => {
4209 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4210 WCBadge,
4211 {
4212 className: "dataviews-view-grid__field-value",
4213 children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4214 field.render,
4215 {
4216 item,
4217 field
4218 }
4219 )
4220 },
4221 field.id
4222 );
4223 })
4224 }
4225 ),
4226 !!regularFields?.length && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4227 Stack,
4228 {
4229 direction: "column",
4230 className: "dataviews-view-grid__fields",
4231 gap: "xs",
4232 children: regularFields.map((field) => {
4233 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4234 import_components8.Flex,
4235 {
4236 className: "dataviews-view-grid__field",
4237 gap: 1,
4238 justify: "flex-start",
4239 expanded: true,
4240 style: { height: "auto" },
4241 direction: "row",
4242 children: /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(import_jsx_runtime41.Fragment, { children: [
4243 /* @__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 }) }),
4244 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4245 import_components8.FlexItem,
4246 {
4247 className: "dataviews-view-grid__field-value",
4248 style: { maxHeight: "none" },
4249 children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4250 field.render,
4251 {
4252 item,
4253 field
4254 }
4255 )
4256 }
4257 )
4258 ] })
4259 },
4260 field.id
4261 );
4262 })
4263 }
4264 )
4265 ] })
4266 ]
4267 }
4268 );
4269 }
4270 );
4271 function CompositeGrid({
4272 data,
4273 isInfiniteScroll,
4274 className,
4275 inert,
4276 isLoading,
4277 view,
4278 fields,
4279 selection,
4280 onChangeSelection,
4281 onClickItem,
4282 isItemClickable: isItemClickable2,
4283 renderItemLink,
4284 getItemId,
4285 actions
4286 }) {
4287 const { paginationInfo, resizeObserverRef } = (0, import_element16.useContext)(dataviews_context_default);
4288 const gridColumns = useGridColumns();
4289 const hasBulkActions = useSomeItemHasAPossibleBulkAction(actions, data);
4290 const titleField = fields.find(
4291 (field) => field.id === view?.titleField
4292 );
4293 const mediaField = fields.find(
4294 (field) => field.id === view?.mediaField
4295 );
4296 const descriptionField2 = fields.find(
4297 (field) => field.id === view?.descriptionField
4298 );
4299 const otherFields = view.fields ?? [];
4300 const { regularFields, badgeFields } = otherFields.reduce(
4301 (accumulator, fieldId) => {
4302 const field = fields.find((f2) => f2.id === fieldId);
4303 if (!field) {
4304 return accumulator;
4305 }
4306 const key = view.layout?.badgeFields?.includes(fieldId) ? "badgeFields" : "regularFields";
4307 accumulator[key].push(field);
4308 return accumulator;
4309 },
4310 { regularFields: [], badgeFields: [] }
4311 );
4312 const size = "900px";
4313 const totalRows = Math.ceil(data.length / gridColumns);
4314 const placeholdersNeeded = usePlaceholdersNeeded(
4315 data,
4316 isInfiniteScroll,
4317 gridColumns
4318 );
4319 return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(import_jsx_runtime41.Fragment, {
4320 // Render infinite scroll layout (no rows, feed semantics)
4321 children: [
4322 isInfiniteScroll && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
4323 import_components8.Composite,
4324 {
4325 render: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4326 GridItems,
4327 {
4328 className: clsx_default(
4329 "dataviews-view-grid-infinite-scroll",
4330 className,
4331 {
4332 [`has-${view.layout?.density}-density`]: view.layout?.density && [
4333 "compact",
4334 "comfortable"
4335 ].includes(view.layout.density)
4336 }
4337 ),
4338 previewSize: view.layout?.previewSize,
4339 "aria-busy": isLoading,
4340 ref: resizeObserverRef
4341 }
4342 ),
4343 role: "feed",
4344 focusWrap: true,
4345 inert,
4346 children: [
4347 Array.from({ length: placeholdersNeeded }).map(
4348 (_, index) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4349 import_components8.Composite.Item,
4350 {
4351 render: (props) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4352 Stack,
4353 {
4354 ...props,
4355 direction: "column",
4356 role: "article",
4357 className: "dataviews-view-grid__row__gridcell dataviews-view-grid__card dataviews-view-grid__placeholder"
4358 }
4359 ),
4360 "aria-hidden": true,
4361 tabIndex: -1
4362 },
4363 `placeholder-${index}`
4364 )
4365 ),
4366 data.map((item) => {
4367 const itemId = getItemId(item);
4368 const stablePosition = item.position;
4369 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4370 import_components8.Composite.Item,
4371 {
4372 render: (props) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4373 GridItem,
4374 {
4375 ...props,
4376 id: itemId,
4377 role: "article",
4378 view,
4379 selection,
4380 onChangeSelection,
4381 onClickItem,
4382 isItemClickable: isItemClickable2,
4383 renderItemLink,
4384 getItemId,
4385 item,
4386 actions,
4387 mediaField,
4388 titleField,
4389 descriptionField: descriptionField2,
4390 regularFields,
4391 badgeFields,
4392 hasBulkActions,
4393 posinset: stablePosition,
4394 setsize: paginationInfo.totalItems,
4395 config: {
4396 sizes: size
4397 }
4398 }
4399 )
4400 },
4401 itemId
4402 );
4403 })
4404 ]
4405 }
4406 ),
4407 // Render standard grid layout (with rows, grid semantics)
4408 !isInfiniteScroll && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4409 import_components8.Composite,
4410 {
4411 role: "grid",
4412 className: clsx_default("dataviews-view-grid", className, {
4413 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
4414 view.layout.density
4415 )
4416 }),
4417 focusWrap: true,
4418 "aria-busy": isLoading,
4419 "aria-rowcount": totalRows,
4420 ref: resizeObserverRef,
4421 inert,
4422 children: chunk(data, gridColumns).map((row, i2) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4423 import_components8.Composite.Row,
4424 {
4425 render: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4426 "div",
4427 {
4428 role: "row",
4429 "aria-rowindex": i2 + 1,
4430 "aria-label": (0, import_i18n17.sprintf)(
4431 /* translators: %d: The row number in the grid */
4432 (0, import_i18n17.__)("Row %d"),
4433 i2 + 1
4434 ),
4435 className: "dataviews-view-grid__row",
4436 style: {
4437 gridTemplateColumns: `repeat( ${gridColumns}, minmax(0, 1fr) )`
4438 }
4439 }
4440 ),
4441 children: row.map((item) => {
4442 const itemId = getItemId(item);
4443 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4444 import_components8.Composite.Item,
4445 {
4446 render: (props) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4447 GridItem,
4448 {
4449 ...props,
4450 id: itemId,
4451 role: "gridcell",
4452 view,
4453 selection,
4454 onChangeSelection,
4455 onClickItem,
4456 isItemClickable: isItemClickable2,
4457 renderItemLink,
4458 getItemId,
4459 item,
4460 actions,
4461 mediaField,
4462 titleField,
4463 descriptionField: descriptionField2,
4464 regularFields,
4465 badgeFields,
4466 hasBulkActions,
4467 config: {
4468 sizes: size
4469 }
4470 }
4471 )
4472 },
4473 itemId
4474 );
4475 })
4476 },
4477 i2
4478 ))
4479 }
4480 )
4481 ]
4482 });
4483 }
4484
4485 // packages/dataviews/build-module/components/dataviews-layouts/grid/index.mjs
4486 var import_jsx_runtime42 = __toESM(require_jsx_runtime(), 1);
4487 function ViewGrid({
4488 actions,
4489 data,
4490 fields,
4491 getItemId,
4492 isLoading,
4493 onChangeSelection,
4494 onClickItem,
4495 isItemClickable: isItemClickable2,
4496 renderItemLink,
4497 selection,
4498 view,
4499 className,
4500 empty
4501 }) {
4502 const isDelayedLoading = useDelayedLoading(!!isLoading);
4503 const hasData = !!data?.length;
4504 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
4505 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
4506 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
4507 if (!hasData) {
4508 return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
4509 "div",
4510 {
4511 className: clsx_default("dataviews-no-results", {
4512 "is-refreshing": isDelayedLoading
4513 }),
4514 children: empty
4515 }
4516 );
4517 }
4518 const gridProps = {
4519 className: clsx_default(className, {
4520 "is-refreshing": !isInfiniteScroll && isDelayedLoading
4521 }),
4522 inert: !isInfiniteScroll && !!isLoading ? "true" : void 0,
4523 isLoading,
4524 view,
4525 fields,
4526 selection,
4527 onChangeSelection,
4528 onClickItem,
4529 isItemClickable: isItemClickable2,
4530 renderItemLink,
4531 getItemId,
4532 actions
4533 };
4534 return /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(import_jsx_runtime42.Fragment, {
4535 // Render multiple groups.
4536 children: [
4537 hasData && groupField && dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(Stack, { direction: "column", gap: "lg", children: Array.from(dataByGroup.entries()).map(
4538 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(
4539 Stack,
4540 {
4541 direction: "column",
4542 gap: "sm",
4543 children: [
4544 /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("h3", { className: "dataviews-view-grid__group-header", children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n18.sprintf)(
4545 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
4546 (0, import_i18n18.__)("%1$s: %2$s"),
4547 groupField.label,
4548 groupName
4549 ) }),
4550 /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
4551 CompositeGrid,
4552 {
4553 ...gridProps,
4554 data: groupItems,
4555 isInfiniteScroll: false
4556 }
4557 )
4558 ]
4559 },
4560 groupName
4561 )
4562 ) }),
4563 // Render a single grid with all data.
4564 !dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
4565 CompositeGrid,
4566 {
4567 ...gridProps,
4568 data,
4569 isInfiniteScroll: !!isInfiniteScroll
4570 }
4571 ),
4572 isInfiniteScroll && isLoading && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(import_components9.Spinner, {}) })
4573 ]
4574 });
4575 }
4576 var grid_default = ViewGrid;
4577
4578 // packages/dataviews/build-module/components/dataviews-layouts/list/index.mjs
4579 var import_compose4 = __toESM(require_compose(), 1);
4580 var import_components10 = __toESM(require_components(), 1);
4581 var import_element17 = __toESM(require_element(), 1);
4582 var import_i18n19 = __toESM(require_i18n(), 1);
4583 var import_data3 = __toESM(require_data(), 1);
4584 var import_jsx_runtime43 = __toESM(require_jsx_runtime(), 1);
4585 var { Menu: Menu3 } = unlock(import_components10.privateApis);
4586 function generateItemWrapperCompositeId(idPrefix) {
4587 return `${idPrefix}-item-wrapper`;
4588 }
4589 function generatePrimaryActionCompositeId(idPrefix, primaryActionId) {
4590 return `${idPrefix}-primary-action-${primaryActionId}`;
4591 }
4592 function generateDropdownTriggerCompositeId(idPrefix) {
4593 return `${idPrefix}-dropdown`;
4594 }
4595 function PrimaryActionGridCell({
4596 idPrefix,
4597 primaryAction,
4598 item
4599 }) {
4600 const registry = (0, import_data3.useRegistry)();
4601 const [isModalOpen, setIsModalOpen] = (0, import_element17.useState)(false);
4602 const compositeItemId = generatePrimaryActionCompositeId(
4603 idPrefix,
4604 primaryAction.id
4605 );
4606 const label = typeof primaryAction.label === "string" ? primaryAction.label : primaryAction.label([item]);
4607 return "RenderModal" in primaryAction ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { role: "gridcell", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4608 import_components10.Composite.Item,
4609 {
4610 id: compositeItemId,
4611 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4612 import_components10.Button,
4613 {
4614 disabled: !!primaryAction.disabled,
4615 accessibleWhenDisabled: true,
4616 text: label,
4617 size: "small",
4618 onClick: () => setIsModalOpen(true)
4619 }
4620 ),
4621 children: isModalOpen && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4622 ActionModal,
4623 {
4624 action: primaryAction,
4625 items: [item],
4626 closeModal: () => setIsModalOpen(false)
4627 }
4628 )
4629 }
4630 ) }, primaryAction.id) : /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { role: "gridcell", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4631 import_components10.Composite.Item,
4632 {
4633 id: compositeItemId,
4634 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4635 import_components10.Button,
4636 {
4637 disabled: !!primaryAction.disabled,
4638 accessibleWhenDisabled: true,
4639 size: "small",
4640 onClick: () => {
4641 primaryAction.callback([item], { registry });
4642 },
4643 children: label
4644 }
4645 )
4646 }
4647 ) }, primaryAction.id);
4648 }
4649 function ListItem({
4650 view,
4651 actions,
4652 idPrefix,
4653 isSelected: isSelected2,
4654 item,
4655 titleField,
4656 mediaField,
4657 descriptionField: descriptionField2,
4658 onSelect,
4659 otherFields,
4660 onDropdownTriggerKeyDown,
4661 posinset
4662 }) {
4663 const {
4664 showTitle = true,
4665 showMedia = true,
4666 showDescription = true,
4667 infiniteScrollEnabled
4668 } = view;
4669 const itemRef = (0, import_element17.useRef)(null);
4670 const labelId = `${idPrefix}-label`;
4671 const descriptionId = `${idPrefix}-description`;
4672 const registry = (0, import_data3.useRegistry)();
4673 const [isHovered, setIsHovered] = (0, import_element17.useState)(false);
4674 const [activeModalAction, setActiveModalAction] = (0, import_element17.useState)(
4675 null
4676 );
4677 const handleHover = ({ type }) => {
4678 const isHover = type === "mouseenter";
4679 setIsHovered(isHover);
4680 };
4681 const { paginationInfo } = (0, import_element17.useContext)(dataviews_context_default);
4682 (0, import_element17.useEffect)(() => {
4683 if (isSelected2) {
4684 itemRef.current?.scrollIntoView({
4685 behavior: "auto",
4686 block: "nearest",
4687 inline: "nearest"
4688 });
4689 }
4690 }, [isSelected2]);
4691 const { primaryAction, eligibleActions } = (0, import_element17.useMemo)(() => {
4692 const _eligibleActions = actions.filter(
4693 (action) => !action.isEligible || action.isEligible(item)
4694 );
4695 const _primaryActions = _eligibleActions.filter(
4696 (action) => action.isPrimary
4697 );
4698 return {
4699 primaryAction: _primaryActions[0],
4700 eligibleActions: _eligibleActions
4701 };
4702 }, [actions, item]);
4703 const hasOnlyOnePrimaryAction = primaryAction && actions.length === 1;
4704 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)(
4705 mediaField.render,
4706 {
4707 item,
4708 field: mediaField,
4709 config: { sizes: "52px" }
4710 }
4711 ) }) : null;
4712 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(titleField.render, { item, field: titleField }) : null;
4713 const renderDescription = showDescription && descriptionField2?.render;
4714 const hasOnlyMediaAndTitle = !!renderedMediaField && !renderDescription && !otherFields.length;
4715 const usedActions = eligibleActions?.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4716 Stack,
4717 {
4718 direction: "row",
4719 gap: "md",
4720 className: "dataviews-view-list__item-actions",
4721 children: [
4722 primaryAction && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4723 PrimaryActionGridCell,
4724 {
4725 idPrefix,
4726 primaryAction,
4727 item
4728 }
4729 ),
4730 !hasOnlyOnePrimaryAction && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { role: "gridcell", children: [
4731 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Menu3, { placement: "bottom-end", children: [
4732 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4733 Menu3.TriggerButton,
4734 {
4735 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4736 import_components10.Composite.Item,
4737 {
4738 id: generateDropdownTriggerCompositeId(
4739 idPrefix
4740 ),
4741 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4742 import_components10.Button,
4743 {
4744 size: "small",
4745 icon: more_vertical_default,
4746 label: (0, import_i18n19.__)("Actions"),
4747 accessibleWhenDisabled: true,
4748 disabled: !actions.length,
4749 onKeyDown: onDropdownTriggerKeyDown
4750 }
4751 )
4752 }
4753 )
4754 }
4755 ),
4756 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Menu3.Popover, { children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4757 ActionsMenuGroup,
4758 {
4759 actions: eligibleActions,
4760 item,
4761 registry,
4762 setActiveModalAction
4763 }
4764 ) })
4765 ] }),
4766 !!activeModalAction && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4767 ActionModal,
4768 {
4769 action: activeModalAction,
4770 items: [item],
4771 closeModal: () => setActiveModalAction(null)
4772 }
4773 )
4774 ] })
4775 ]
4776 }
4777 );
4778 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4779 import_components10.Composite.Row,
4780 {
4781 ref: itemRef,
4782 render: (
4783 /* aria-posinset breaks Composite.Row if passed to it directly. */
4784 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4785 "div",
4786 {
4787 "aria-posinset": posinset,
4788 "aria-setsize": infiniteScrollEnabled ? paginationInfo.totalItems : void 0
4789 }
4790 )
4791 ),
4792 role: infiniteScrollEnabled ? "article" : "row",
4793 className: clsx_default({
4794 "is-selected": isSelected2,
4795 "is-hovered": isHovered
4796 }),
4797 onMouseEnter: handleHover,
4798 onMouseLeave: handleHover,
4799 children: /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4800 Stack,
4801 {
4802 direction: "row",
4803 className: "dataviews-view-list__item-wrapper",
4804 children: [
4805 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { role: "gridcell", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4806 import_components10.Composite.Item,
4807 {
4808 id: generateItemWrapperCompositeId(idPrefix),
4809 "aria-pressed": isSelected2,
4810 "aria-labelledby": labelId,
4811 "aria-describedby": descriptionId,
4812 className: "dataviews-view-list__item",
4813 onClick: () => onSelect(item)
4814 }
4815 ) }),
4816 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4817 Stack,
4818 {
4819 direction: "row",
4820 gap: "md",
4821 justify: "start",
4822 align: hasOnlyMediaAndTitle ? "center" : "flex-start",
4823 style: { flex: 1, minWidth: 0 },
4824 children: [
4825 renderedMediaField,
4826 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4827 Stack,
4828 {
4829 direction: "column",
4830 gap: "xs",
4831 className: "dataviews-view-list__field-wrapper",
4832 children: [
4833 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Stack, { direction: "row", align: "center", children: [
4834 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4835 "div",
4836 {
4837 className: "dataviews-title-field dataviews-view-list__title-field",
4838 id: labelId,
4839 children: renderedTitleField
4840 }
4841 ),
4842 usedActions
4843 ] }),
4844 renderDescription && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "dataviews-view-list__field", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4845 descriptionField2.render,
4846 {
4847 item,
4848 field: descriptionField2
4849 }
4850 ) }),
4851 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4852 "div",
4853 {
4854 className: "dataviews-view-list__fields",
4855 id: descriptionId,
4856 children: otherFields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4857 "div",
4858 {
4859 className: "dataviews-view-list__field",
4860 children: [
4861 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4862 VisuallyHidden,
4863 {
4864 className: "dataviews-view-list__field-label",
4865 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", {}),
4866 children: field.label
4867 }
4868 ),
4869 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "dataviews-view-list__field-value", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4870 field.render,
4871 {
4872 item,
4873 field
4874 }
4875 ) })
4876 ]
4877 },
4878 field.id
4879 ))
4880 }
4881 )
4882 ]
4883 }
4884 )
4885 ]
4886 }
4887 )
4888 ]
4889 }
4890 )
4891 }
4892 );
4893 }
4894 function isDefined2(item) {
4895 return !!item;
4896 }
4897 function ViewList(props) {
4898 const {
4899 actions,
4900 data,
4901 fields,
4902 getItemId,
4903 isLoading,
4904 onChangeSelection,
4905 selection,
4906 view,
4907 className,
4908 empty
4909 } = props;
4910 const baseId = (0, import_compose4.useInstanceId)(ViewList, "view-list");
4911 const isDelayedLoading = useDelayedLoading(!!isLoading);
4912 const selectedItem = data?.findLast(
4913 (item) => selection.includes(getItemId(item))
4914 );
4915 const titleField = fields.find((field) => field.id === view.titleField);
4916 const mediaField = fields.find((field) => field.id === view.mediaField);
4917 const descriptionField2 = fields.find(
4918 (field) => field.id === view.descriptionField
4919 );
4920 const otherFields = (view?.fields ?? []).map((fieldId) => fields.find((f2) => fieldId === f2.id)).filter(isDefined2);
4921 const onSelect = (item) => onChangeSelection([getItemId(item)]);
4922 const generateCompositeItemIdPrefix = (0, import_element17.useCallback)(
4923 (item) => `${baseId}-${getItemId(item)}`,
4924 [baseId, getItemId]
4925 );
4926 const isActiveCompositeItem = (0, import_element17.useCallback)(
4927 (item, idToCheck) => {
4928 return idToCheck.startsWith(
4929 generateCompositeItemIdPrefix(item)
4930 );
4931 },
4932 [generateCompositeItemIdPrefix]
4933 );
4934 const [activeCompositeId, setActiveCompositeId] = (0, import_element17.useState)(void 0);
4935 const compositeRef = (0, import_element17.useRef)(null);
4936 (0, import_element17.useEffect)(() => {
4937 if (selectedItem) {
4938 setActiveCompositeId(
4939 generateItemWrapperCompositeId(
4940 generateCompositeItemIdPrefix(selectedItem)
4941 )
4942 );
4943 }
4944 }, [selectedItem, generateCompositeItemIdPrefix]);
4945 const activeItemIndex = data.findIndex(
4946 (item) => isActiveCompositeItem(item, activeCompositeId ?? "")
4947 );
4948 const previousActiveItemIndex = (0, import_compose4.usePrevious)(activeItemIndex);
4949 const isActiveIdInList = activeItemIndex !== -1;
4950 const selectCompositeItem = (0, import_element17.useCallback)(
4951 (targetIndex, generateCompositeId) => {
4952 const clampedIndex = Math.min(
4953 data.length - 1,
4954 Math.max(0, targetIndex)
4955 );
4956 if (!data[clampedIndex]) {
4957 return;
4958 }
4959 const itemIdPrefix = generateCompositeItemIdPrefix(
4960 data[clampedIndex]
4961 );
4962 const targetCompositeItemId = generateCompositeId(itemIdPrefix);
4963 setActiveCompositeId(targetCompositeItemId);
4964 if (compositeRef.current?.contains(
4965 compositeRef.current.ownerDocument.activeElement
4966 )) {
4967 document.getElementById(targetCompositeItemId)?.focus();
4968 }
4969 },
4970 [data, generateCompositeItemIdPrefix]
4971 );
4972 (0, import_element17.useEffect)(() => {
4973 const wasActiveIdInList = previousActiveItemIndex !== void 0 && previousActiveItemIndex !== -1;
4974 if (!isActiveIdInList && wasActiveIdInList) {
4975 selectCompositeItem(
4976 previousActiveItemIndex,
4977 generateItemWrapperCompositeId
4978 );
4979 }
4980 }, [isActiveIdInList, selectCompositeItem, previousActiveItemIndex]);
4981 const onDropdownTriggerKeyDown = (0, import_element17.useCallback)(
4982 (event) => {
4983 if (event.key === "ArrowDown") {
4984 event.preventDefault();
4985 selectCompositeItem(
4986 activeItemIndex + 1,
4987 generateDropdownTriggerCompositeId
4988 );
4989 }
4990 if (event.key === "ArrowUp") {
4991 event.preventDefault();
4992 selectCompositeItem(
4993 activeItemIndex - 1,
4994 generateDropdownTriggerCompositeId
4995 );
4996 }
4997 },
4998 [selectCompositeItem, activeItemIndex]
4999 );
5000 const hasData = !!data?.length;
5001 const groupField = view.groupBy?.field ? fields.find((field) => field.id === view.groupBy?.field) : null;
5002 const dataByGroup = hasData && groupField ? getDataByGroup(data, groupField) : null;
5003 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
5004 if (!hasData) {
5005 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
5006 "div",
5007 {
5008 className: clsx_default("dataviews-no-results", {
5009 "is-refreshing": isDelayedLoading
5010 }),
5011 children: empty
5012 }
5013 );
5014 }
5015 if (hasData && groupField && dataByGroup) {
5016 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
5017 import_components10.Composite,
5018 {
5019 ref: compositeRef,
5020 id: `${baseId}`,
5021 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", {}),
5022 className: "dataviews-view-list__group",
5023 role: "grid",
5024 activeId: activeCompositeId,
5025 setActiveId: setActiveCompositeId,
5026 children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
5027 Stack,
5028 {
5029 direction: "column",
5030 gap: "lg",
5031 className: clsx_default("dataviews-view-list", className),
5032 children: Array.from(dataByGroup.entries()).map(
5033 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
5034 Stack,
5035 {
5036 direction: "column",
5037 gap: "sm",
5038 children: [
5039 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("h3", { className: "dataviews-view-list__group-header", children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n19.sprintf)(
5040 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
5041 (0, import_i18n19.__)("%1$s: %2$s"),
5042 groupField.label,
5043 groupName
5044 ) }),
5045 groupItems.map((item) => {
5046 const id = generateCompositeItemIdPrefix(item);
5047 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
5048 ListItem,
5049 {
5050 view,
5051 idPrefix: id,
5052 actions,
5053 item,
5054 isSelected: item === selectedItem,
5055 onSelect,
5056 mediaField,
5057 titleField,
5058 descriptionField: descriptionField2,
5059 otherFields,
5060 onDropdownTriggerKeyDown
5061 },
5062 id
5063 );
5064 })
5065 ]
5066 },
5067 groupName
5068 )
5069 )
5070 }
5071 )
5072 }
5073 );
5074 }
5075 return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(import_jsx_runtime43.Fragment, { children: [
5076 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
5077 import_components10.Composite,
5078 {
5079 ref: compositeRef,
5080 id: baseId,
5081 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", {}),
5082 className: clsx_default("dataviews-view-list", className, {
5083 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
5084 view.layout.density
5085 ),
5086 "is-refreshing": !isInfiniteScroll && isDelayedLoading
5087 }),
5088 role: view.infiniteScrollEnabled ? "feed" : "grid",
5089 activeId: activeCompositeId,
5090 setActiveId: setActiveCompositeId,
5091 inert: !isInfiniteScroll && !!isLoading ? "true" : void 0,
5092 children: data.map((item, index) => {
5093 const id = generateCompositeItemIdPrefix(item);
5094 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
5095 ListItem,
5096 {
5097 view,
5098 idPrefix: id,
5099 actions,
5100 item,
5101 isSelected: item === selectedItem,
5102 onSelect,
5103 mediaField,
5104 titleField,
5105 descriptionField: descriptionField2,
5106 otherFields,
5107 onDropdownTriggerKeyDown,
5108 posinset: view.infiniteScrollEnabled ? index + 1 : void 0
5109 },
5110 id
5111 );
5112 })
5113 }
5114 ),
5115 isInfiniteScroll && isLoading && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(import_components10.Spinner, {}) })
5116 ] });
5117 }
5118
5119 // packages/dataviews/build-module/components/dataviews-layouts/activity/index.mjs
5120 var import_components11 = __toESM(require_components(), 1);
5121
5122 // packages/dataviews/build-module/components/dataviews-layouts/activity/activity-group.mjs
5123 var import_i18n20 = __toESM(require_i18n(), 1);
5124 var import_element18 = __toESM(require_element(), 1);
5125 var import_jsx_runtime44 = __toESM(require_jsx_runtime(), 1);
5126 function ActivityGroup({
5127 groupName,
5128 groupData,
5129 groupField,
5130 showLabel = true,
5131 children
5132 }) {
5133 const groupHeader = showLabel ? (0, import_element18.createInterpolateElement)(
5134 // translators: %s: The label of the field e.g. "Status".
5135 (0, import_i18n20.sprintf)((0, import_i18n20.__)("%s: <groupName />"), groupField.label).trim(),
5136 {
5137 groupName: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
5138 groupField.render,
5139 {
5140 item: groupData[0],
5141 field: groupField
5142 }
5143 )
5144 }
5145 ) : /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(groupField.render, { item: groupData[0], field: groupField });
5146 return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)(
5147 Stack,
5148 {
5149 direction: "column",
5150 className: "dataviews-view-activity__group",
5151 children: [
5152 /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("h3", { className: "dataviews-view-activity__group-header", children: groupHeader }),
5153 children
5154 ]
5155 },
5156 groupName
5157 );
5158 }
5159
5160 // packages/dataviews/build-module/components/dataviews-layouts/activity/activity-item.mjs
5161 var import_element19 = __toESM(require_element(), 1);
5162 var import_data4 = __toESM(require_data(), 1);
5163 var import_compose5 = __toESM(require_compose(), 1);
5164 var import_jsx_runtime45 = __toESM(require_jsx_runtime(), 1);
5165 function ActivityItem(props) {
5166 const {
5167 view,
5168 actions,
5169 item,
5170 titleField,
5171 mediaField,
5172 descriptionField: descriptionField2,
5173 otherFields,
5174 posinset,
5175 onClickItem,
5176 renderItemLink,
5177 isItemClickable: isItemClickable2
5178 } = props;
5179 const {
5180 showTitle = true,
5181 showMedia = true,
5182 showDescription = true,
5183 infiniteScrollEnabled
5184 } = view;
5185 const itemRef = (0, import_element19.useRef)(null);
5186 const registry = (0, import_data4.useRegistry)();
5187 const { paginationInfo } = (0, import_element19.useContext)(dataviews_context_default);
5188 const { primaryActions, eligibleActions } = (0, import_element19.useMemo)(() => {
5189 const _eligibleActions = actions.filter(
5190 (action) => !action.isEligible || action.isEligible(item)
5191 );
5192 const _primaryActions = _eligibleActions.filter(
5193 (action) => action.isPrimary
5194 );
5195 return {
5196 primaryActions: _primaryActions,
5197 eligibleActions: _eligibleActions
5198 };
5199 }, [actions, item]);
5200 const isMobileViewport = (0, import_compose5.useViewportMatch)("medium", "<");
5201 const density = view.layout?.density ?? "balanced";
5202 const mediaContent = showMedia && density !== "compact" && mediaField?.render ? /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5203 mediaField.render,
5204 {
5205 item,
5206 field: mediaField,
5207 config: {
5208 sizes: density === "comfortable" ? "32px" : "24px"
5209 }
5210 }
5211 ) : null;
5212 const renderedMediaField = /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-type-icon", children: mediaContent || /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5213 "span",
5214 {
5215 className: "dataviews-view-activity__item-bullet",
5216 "aria-hidden": "true"
5217 }
5218 ) });
5219 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(titleField.render, { item, field: titleField }) : null;
5220 const verticalGap = (0, import_element19.useMemo)(() => {
5221 switch (density) {
5222 case "comfortable":
5223 return "md";
5224 default:
5225 return "sm";
5226 }
5227 }, [density]);
5228 return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5229 "div",
5230 {
5231 ref: itemRef,
5232 role: infiniteScrollEnabled ? "article" : void 0,
5233 "aria-posinset": posinset,
5234 "aria-setsize": infiniteScrollEnabled ? paginationInfo.totalItems : void 0,
5235 className: clsx_default(
5236 "dataviews-view-activity__item",
5237 density === "compact" && "is-compact",
5238 density === "balanced" && "is-balanced",
5239 density === "comfortable" && "is-comfortable"
5240 ),
5241 children: /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(Stack, { direction: "row", gap: "lg", justify: "start", align: "flex-start", children: [
5242 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5243 Stack,
5244 {
5245 direction: "column",
5246 gap: "xs",
5247 align: "center",
5248 className: "dataviews-view-activity__item-type",
5249 children: renderedMediaField
5250 }
5251 ),
5252 /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
5253 Stack,
5254 {
5255 direction: "column",
5256 gap: verticalGap,
5257 align: "flex-start",
5258 className: "dataviews-view-activity__item-content",
5259 children: [
5260 renderedTitleField && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5261 ItemClickWrapper,
5262 {
5263 item,
5264 isItemClickable: isItemClickable2,
5265 onClickItem,
5266 renderItemLink,
5267 className: "dataviews-view-activity__item-title",
5268 children: renderedTitleField
5269 }
5270 ),
5271 showDescription && descriptionField2 && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-description", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5272 descriptionField2.render,
5273 {
5274 item,
5275 field: descriptionField2
5276 }
5277 ) }),
5278 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-fields", children: otherFields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
5279 "div",
5280 {
5281 className: "dataviews-view-activity__item-field",
5282 children: [
5283 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5284 VisuallyHidden,
5285 {
5286 className: "dataviews-view-activity__item-field-label",
5287 render: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("span", {}),
5288 children: field.label
5289 }
5290 ),
5291 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("span", { className: "dataviews-view-activity__item-field-value", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5292 field.render,
5293 {
5294 item,
5295 field
5296 }
5297 ) })
5298 ]
5299 },
5300 field.id
5301 )) }),
5302 !!primaryActions?.length && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5303 PrimaryActions,
5304 {
5305 item,
5306 actions: primaryActions,
5307 registry,
5308 buttonVariant: "secondary"
5309 }
5310 )
5311 ]
5312 }
5313 ),
5314 (primaryActions.length < eligibleActions.length || // Since we hide primary actions on mobile, we need to show the menu
5315 // there if there are any actions at all.
5316 isMobileViewport && // At the same time, only show the menu if there are actions to show.
5317 eligibleActions.length > 0) && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-actions", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5318 ItemActions,
5319 {
5320 item,
5321 actions: eligibleActions,
5322 isCompact: true
5323 }
5324 ) })
5325 ] })
5326 }
5327 );
5328 }
5329 var activity_item_default = ActivityItem;
5330
5331 // packages/dataviews/build-module/components/dataviews-layouts/activity/activity-items.mjs
5332 var import_react4 = __toESM(require_react(), 1);
5333 function isDefined3(item) {
5334 return !!item;
5335 }
5336 function ActivityItems(props) {
5337 const { data, fields, getItemId, view } = props;
5338 const titleField = fields.find((field) => field.id === view.titleField);
5339 const mediaField = fields.find((field) => field.id === view.mediaField);
5340 const descriptionField2 = fields.find(
5341 (field) => field.id === view.descriptionField
5342 );
5343 const otherFields = (view?.fields ?? []).map((fieldId) => fields.find((f2) => fieldId === f2.id)).filter(isDefined3);
5344 return data.map((item, index) => {
5345 return /* @__PURE__ */ (0, import_react4.createElement)(
5346 activity_item_default,
5347 {
5348 ...props,
5349 key: getItemId(item),
5350 item,
5351 mediaField,
5352 titleField,
5353 descriptionField: descriptionField2,
5354 otherFields,
5355 posinset: view.infiniteScrollEnabled ? index + 1 : void 0
5356 }
5357 );
5358 });
5359 }
5360
5361 // packages/dataviews/build-module/components/dataviews-layouts/activity/index.mjs
5362 var import_jsx_runtime46 = __toESM(require_jsx_runtime(), 1);
5363 function ViewActivity(props) {
5364 const { empty, data, fields, isLoading, view, className } = props;
5365 const isDelayedLoading = useDelayedLoading(!!isLoading);
5366 const hasData = !!data?.length;
5367 const groupField = view.groupBy?.field ? fields.find((field) => field.id === view.groupBy?.field) : null;
5368 const dataByGroup = hasData && groupField ? getDataByGroup(data, groupField) : null;
5369 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
5370 if (!hasData) {
5371 return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5372 "div",
5373 {
5374 className: clsx_default("dataviews-no-results", {
5375 "is-refreshing": isDelayedLoading
5376 }),
5377 children: empty
5378 }
5379 );
5380 }
5381 const isInert = !isInfiniteScroll && !!isLoading;
5382 const wrapperClassName = clsx_default("dataviews-view-activity", className, {
5383 "is-refreshing": !isInfiniteScroll && isDelayedLoading
5384 });
5385 const groupedEntries = dataByGroup ? Array.from(dataByGroup.entries()) : [];
5386 if (hasData && groupField && dataByGroup) {
5387 return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5388 Stack,
5389 {
5390 direction: "column",
5391 gap: "sm",
5392 className: wrapperClassName,
5393 inert: isInert ? "true" : void 0,
5394 children: groupedEntries.map(
5395 ([groupName, groupData]) => /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5396 ActivityGroup,
5397 {
5398 groupName,
5399 groupData,
5400 groupField,
5401 showLabel: view.groupBy?.showLabel !== false,
5402 children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5403 ActivityItems,
5404 {
5405 ...props,
5406 data: groupData
5407 }
5408 )
5409 },
5410 groupName
5411 )
5412 )
5413 }
5414 );
5415 }
5416 return /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)(import_jsx_runtime46.Fragment, { children: [
5417 /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5418 "div",
5419 {
5420 className: wrapperClassName,
5421 role: view.infiniteScrollEnabled ? "feed" : void 0,
5422 inert: isInert ? "true" : void 0,
5423 children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(ActivityItems, { ...props })
5424 }
5425 ),
5426 isInfiniteScroll && isLoading && /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(import_components11.Spinner, {}) })
5427 ] });
5428 }
5429
5430 // packages/dataviews/build-module/components/dataviews-layouts/picker-grid/index.mjs
5431 var import_components14 = __toESM(require_components(), 1);
5432 var import_i18n23 = __toESM(require_i18n(), 1);
5433 var import_compose6 = __toESM(require_compose(), 1);
5434 var import_element22 = __toESM(require_element(), 1);
5435
5436 // packages/dataviews/build-module/components/dataviews-picker-footer/index.mjs
5437 var import_components13 = __toESM(require_components(), 1);
5438 var import_data5 = __toESM(require_data(), 1);
5439 var import_element21 = __toESM(require_element(), 1);
5440 var import_i18n22 = __toESM(require_i18n(), 1);
5441
5442 // packages/dataviews/build-module/components/dataviews-pagination/index.mjs
5443 var import_components12 = __toESM(require_components(), 1);
5444 var import_element20 = __toESM(require_element(), 1);
5445 var import_i18n21 = __toESM(require_i18n(), 1);
5446 var import_jsx_runtime47 = __toESM(require_jsx_runtime(), 1);
5447 function DataViewsPagination() {
5448 const {
5449 view,
5450 onChangeView,
5451 paginationInfo: { totalItems = 0, totalPages }
5452 } = (0, import_element20.useContext)(dataviews_context_default);
5453 if (!totalItems || !totalPages || view.infiniteScrollEnabled) {
5454 return null;
5455 }
5456 const currentPage = view.page ?? 1;
5457 const pageSelectOptions = Array.from(Array(totalPages)).map(
5458 (_, i2) => {
5459 const page = i2 + 1;
5460 return {
5461 value: page.toString(),
5462 label: page.toString(),
5463 "aria-label": currentPage === page ? (0, import_i18n21.sprintf)(
5464 // translators: 1: current page number. 2: total number of pages.
5465 (0, import_i18n21.__)("Page %1$d of %2$d"),
5466 currentPage,
5467 totalPages
5468 ) : page.toString()
5469 };
5470 }
5471 );
5472 return !!totalItems && totalPages !== 1 && /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(
5473 Stack,
5474 {
5475 direction: "row",
5476 className: "dataviews-pagination",
5477 justify: "end",
5478 align: "center",
5479 gap: "xl",
5480 children: [
5481 /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5482 Stack,
5483 {
5484 direction: "row",
5485 justify: "flex-start",
5486 align: "center",
5487 gap: "xs",
5488 className: "dataviews-pagination__page-select",
5489 children: (0, import_element20.createInterpolateElement)(
5490 (0, import_i18n21.sprintf)(
5491 // translators: 1: Current page number, 2: Total number of pages.
5492 (0, import_i18n21._x)(
5493 "<div>Page</div>%1$s<div>of %2$d</div>",
5494 "paging"
5495 ),
5496 "<CurrentPage />",
5497 totalPages
5498 ),
5499 {
5500 div: /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("div", { "aria-hidden": true }),
5501 // @ts-expect-error — Tag injected via sprintf argument, not visible in format string.
5502 CurrentPage: /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5503 import_components12.SelectControl,
5504 {
5505 "aria-label": (0, import_i18n21.__)("Current page"),
5506 value: currentPage.toString(),
5507 options: pageSelectOptions,
5508 onChange: (newValue) => {
5509 onChangeView({
5510 ...view,
5511 page: +newValue
5512 });
5513 },
5514 size: "small",
5515 variant: "minimal"
5516 }
5517 )
5518 }
5519 )
5520 }
5521 ),
5522 /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(Stack, { direction: "row", gap: "xs", align: "center", children: [
5523 /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5524 import_components12.Button,
5525 {
5526 onClick: () => onChangeView({
5527 ...view,
5528 page: currentPage - 1
5529 }),
5530 disabled: currentPage === 1,
5531 accessibleWhenDisabled: true,
5532 label: (0, import_i18n21.__)("Previous page"),
5533 icon: (0, import_i18n21.isRTL)() ? next_default : previous_default,
5534 showTooltip: true,
5535 size: "compact",
5536 tooltipPosition: "top"
5537 }
5538 ),
5539 /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5540 import_components12.Button,
5541 {
5542 onClick: () => onChangeView({ ...view, page: currentPage + 1 }),
5543 disabled: currentPage >= totalPages,
5544 accessibleWhenDisabled: true,
5545 label: (0, import_i18n21.__)("Next page"),
5546 icon: (0, import_i18n21.isRTL)() ? previous_default : next_default,
5547 showTooltip: true,
5548 size: "compact",
5549 tooltipPosition: "top"
5550 }
5551 )
5552 ] })
5553 ]
5554 }
5555 );
5556 }
5557 var dataviews_pagination_default = (0, import_element20.memo)(DataViewsPagination);
5558
5559 // packages/dataviews/build-module/components/dataviews-picker-footer/index.mjs
5560 var import_jsx_runtime48 = __toESM(require_jsx_runtime(), 1);
5561 var EMPTY_ARRAY2 = [];
5562 function useIsMultiselectPicker(actions) {
5563 return (0, import_element21.useMemo)(() => {
5564 return actions?.every((action) => action.supportsBulk);
5565 }, [actions]);
5566 }
5567 function BulkSelectionCheckbox2({
5568 selection,
5569 selectedItems,
5570 onChangeSelection,
5571 data,
5572 getItemId,
5573 disableSelectAll = false
5574 }) {
5575 const hasSelection = selection.length > 0;
5576 const areAllSelected = selectedItems.length === data.length;
5577 if (disableSelectAll) {
5578 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5579 import_components13.CheckboxControl,
5580 {
5581 className: "dataviews-view-table-selection-checkbox",
5582 checked: hasSelection,
5583 disabled: !hasSelection,
5584 onChange: () => {
5585 onChangeSelection([]);
5586 },
5587 "aria-label": (0, import_i18n22.__)("Deselect all")
5588 }
5589 );
5590 }
5591 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5592 import_components13.CheckboxControl,
5593 {
5594 className: "dataviews-view-table-selection-checkbox",
5595 checked: areAllSelected,
5596 indeterminate: !areAllSelected && !!selectedItems.length,
5597 onChange: () => {
5598 if (areAllSelected) {
5599 onChangeSelection(
5600 selection.filter(
5601 (id) => !data.some(
5602 (item) => id === getItemId(item)
5603 )
5604 )
5605 );
5606 } else {
5607 const selectionSet = /* @__PURE__ */ new Set([
5608 ...selection,
5609 ...data.map((item) => getItemId(item))
5610 ]);
5611 onChangeSelection(Array.from(selectionSet));
5612 }
5613 },
5614 "aria-label": areAllSelected ? (0, import_i18n22.__)("Deselect all") : (0, import_i18n22.__)("Select all")
5615 }
5616 );
5617 }
5618 function ActionButtons({
5619 actions,
5620 items,
5621 selection
5622 }) {
5623 const registry = (0, import_data5.useRegistry)();
5624 const [actionInProgress, setActionInProgress] = (0, import_element21.useState)(
5625 null
5626 );
5627 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(Stack, { direction: "row", gap: "xs", children: actions.map((action) => {
5628 if (!("callback" in action)) {
5629 return null;
5630 }
5631 const { id, label, icon, isPrimary, callback } = action;
5632 const _label = typeof label === "string" ? label : label(items);
5633 const variant = isPrimary ? "primary" : "tertiary";
5634 const isInProgress = id === actionInProgress;
5635 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5636 import_components13.Button,
5637 {
5638 accessibleWhenDisabled: true,
5639 icon,
5640 disabled: isInProgress || !selection?.length,
5641 isBusy: isInProgress,
5642 onClick: async () => {
5643 setActionInProgress(id);
5644 await callback(items, {
5645 registry
5646 });
5647 setActionInProgress(null);
5648 },
5649 size: "compact",
5650 variant,
5651 children: _label
5652 },
5653 id
5654 );
5655 }) });
5656 }
5657 function DataViewsPickerFooter() {
5658 const {
5659 data,
5660 selection,
5661 onChangeSelection,
5662 getItemId,
5663 actions = EMPTY_ARRAY2,
5664 paginationInfo,
5665 view
5666 } = (0, import_element21.useContext)(dataviews_context_default);
5667 const isMultiselect = useIsMultiselectPicker(actions);
5668 const message2 = getFooterMessage(
5669 selection.length,
5670 data.length,
5671 paginationInfo.totalItems,
5672 !!view.infiniteScrollEnabled
5673 );
5674 const selectedItems = (0, import_element21.useMemo)(
5675 () => data.filter((item) => selection.includes(getItemId(item))),
5676 [selection, getItemId, data]
5677 );
5678 return /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(
5679 Stack,
5680 {
5681 direction: "row",
5682 justify: "space-between",
5683 align: "center",
5684 className: "dataviews-footer",
5685 gap: "sm",
5686 children: [
5687 /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(
5688 Stack,
5689 {
5690 direction: "row",
5691 className: "dataviews-picker-footer__bulk-selection",
5692 gap: "md",
5693 align: "center",
5694 children: [
5695 isMultiselect && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5696 BulkSelectionCheckbox2,
5697 {
5698 selection,
5699 selectedItems,
5700 onChangeSelection,
5701 data,
5702 getItemId,
5703 disableSelectAll: !!view.infiniteScrollEnabled
5704 }
5705 ),
5706 /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("span", { className: "dataviews-bulk-actions-footer__item-count", children: message2 })
5707 ]
5708 }
5709 ),
5710 /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(dataviews_pagination_default, {}),
5711 Boolean(actions?.length) && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("div", { className: "dataviews-picker-footer__actions", children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5712 ActionButtons,
5713 {
5714 actions,
5715 items: selectedItems,
5716 selection
5717 }
5718 ) })
5719 ]
5720 }
5721 );
5722 }
5723
5724 // packages/dataviews/build-module/components/dataviews-layouts/picker-grid/index.mjs
5725 var import_jsx_runtime49 = __toESM(require_jsx_runtime(), 1);
5726 var { Badge: WCBadge2 } = unlock(import_components14.privateApis);
5727 function GridItem3({
5728 view,
5729 multiselect,
5730 selection,
5731 onChangeSelection,
5732 getItemId,
5733 item,
5734 mediaField,
5735 titleField,
5736 descriptionField: descriptionField2,
5737 regularFields,
5738 badgeFields,
5739 config,
5740 posinset,
5741 setsize
5742 }) {
5743 const { showTitle = true, showMedia = true, showDescription = true } = view;
5744 const id = getItemId(item);
5745 const elementRef = (0, import_element22.useRef)(null);
5746 const isSelected2 = selection.includes(id);
5747 useIntersectionObserver(elementRef, posinset);
5748 const renderedMediaField = mediaField?.render ? /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5749 mediaField.render,
5750 {
5751 item,
5752 field: mediaField,
5753 config
5754 }
5755 ) : null;
5756 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(titleField.render, { item, field: titleField }) : null;
5757 return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5758 import_components14.Composite.Item,
5759 {
5760 ref: elementRef,
5761 "aria-label": titleField ? titleField.getValue({ item }) || (0, import_i18n23.__)("(no title)") : void 0,
5762 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack, { direction: "column", children, ...props }),
5763 role: "option",
5764 "aria-posinset": posinset,
5765 "aria-setsize": setsize,
5766 className: clsx_default("dataviews-view-picker-grid__card", {
5767 "is-selected": isSelected2
5768 }),
5769 "aria-selected": isSelected2,
5770 onClick: () => {
5771 if (isSelected2) {
5772 onChangeSelection(
5773 selection.filter((itemId) => id !== itemId)
5774 );
5775 } else {
5776 const newSelection = multiselect ? [...selection, id] : [id];
5777 onChangeSelection(newSelection);
5778 }
5779 },
5780 children: [
5781 showMedia && renderedMediaField && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { className: "dataviews-view-picker-grid__media", children: renderedMediaField }),
5782 showMedia && renderedMediaField && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5783 DataViewsSelectionCheckbox,
5784 {
5785 item,
5786 selection,
5787 onChangeSelection,
5788 getItemId,
5789 titleField,
5790 disabled: false,
5791 "aria-hidden": true,
5792 tabIndex: -1
5793 }
5794 ),
5795 showTitle && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5796 Stack,
5797 {
5798 direction: "row",
5799 justify: "space-between",
5800 className: "dataviews-view-picker-grid__title-actions",
5801 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { className: "dataviews-view-picker-grid__title-field dataviews-title-field", children: renderedTitleField })
5802 }
5803 ),
5804 /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(Stack, { direction: "column", gap: "xs", children: [
5805 showDescription && descriptionField2?.render && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5806 descriptionField2.render,
5807 {
5808 item,
5809 field: descriptionField2
5810 }
5811 ),
5812 !!badgeFields?.length && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5813 Stack,
5814 {
5815 direction: "row",
5816 className: "dataviews-view-picker-grid__badge-fields",
5817 gap: "sm",
5818 wrap: "wrap",
5819 align: "top",
5820 justify: "flex-start",
5821 children: badgeFields.map((field) => {
5822 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5823 WCBadge2,
5824 {
5825 className: "dataviews-view-picker-grid__field-value",
5826 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5827 field.render,
5828 {
5829 item,
5830 field
5831 }
5832 )
5833 },
5834 field.id
5835 );
5836 })
5837 }
5838 ),
5839 !!regularFields?.length && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5840 Stack,
5841 {
5842 direction: "column",
5843 className: "dataviews-view-picker-grid__fields",
5844 gap: "xs",
5845 children: regularFields.map((field) => {
5846 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5847 import_components14.Flex,
5848 {
5849 className: "dataviews-view-picker-grid__field",
5850 gap: 1,
5851 justify: "flex-start",
5852 expanded: true,
5853 style: { height: "auto" },
5854 direction: "row",
5855 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(import_jsx_runtime49.Fragment, { children: [
5856 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_components14.FlexItem, { className: "dataviews-view-picker-grid__field-name", children: field.header }),
5857 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5858 import_components14.FlexItem,
5859 {
5860 className: "dataviews-view-picker-grid__field-value",
5861 style: { maxHeight: "none" },
5862 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5863 field.render,
5864 {
5865 item,
5866 field
5867 }
5868 )
5869 }
5870 )
5871 ] })
5872 },
5873 field.id
5874 );
5875 })
5876 }
5877 )
5878 ] })
5879 ]
5880 },
5881 id
5882 );
5883 }
5884 function GridGroup({
5885 groupName,
5886 groupField,
5887 showLabel = true,
5888 children
5889 }) {
5890 const headerId = (0, import_compose6.useInstanceId)(
5891 GridGroup,
5892 "dataviews-view-picker-grid-group__header"
5893 );
5894 return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5895 Stack,
5896 {
5897 direction: "column",
5898 gap: "sm",
5899 role: "group",
5900 "aria-labelledby": headerId,
5901 children: [
5902 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5903 "h3",
5904 {
5905 className: "dataviews-view-picker-grid-group__header",
5906 id: headerId,
5907 children: showLabel ? (0, import_i18n23.sprintf)(
5908 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
5909 (0, import_i18n23.__)("%1$s: %2$s"),
5910 groupField.label,
5911 groupName
5912 ) : groupName
5913 }
5914 ),
5915 children
5916 ]
5917 },
5918 groupName
5919 );
5920 }
5921 function ViewPickerGrid({
5922 actions,
5923 data,
5924 fields,
5925 getItemId,
5926 isLoading,
5927 onChangeSelection,
5928 selection,
5929 view,
5930 className,
5931 empty
5932 }) {
5933 const { resizeObserverRef, paginationInfo, itemListLabel } = (0, import_element22.useContext)(dataviews_context_default);
5934 const titleField = fields.find(
5935 (field) => field.id === view?.titleField
5936 );
5937 const mediaField = fields.find(
5938 (field) => field.id === view?.mediaField
5939 );
5940 const descriptionField2 = fields.find(
5941 (field) => field.id === view?.descriptionField
5942 );
5943 const otherFields = view.fields ?? [];
5944 const { regularFields, badgeFields } = otherFields.reduce(
5945 (accumulator, fieldId) => {
5946 const field = fields.find((f2) => f2.id === fieldId);
5947 if (!field) {
5948 return accumulator;
5949 }
5950 const key = view.layout?.badgeFields?.includes(fieldId) ? "badgeFields" : "regularFields";
5951 accumulator[key].push(field);
5952 return accumulator;
5953 },
5954 { regularFields: [], badgeFields: [] }
5955 );
5956 const hasData = !!data?.length;
5957 const usedPreviewSize = view.layout?.previewSize;
5958 const isMultiselect = useIsMultiselectPicker(actions);
5959 const size = "900px";
5960 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
5961 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
5962 const isInfiniteScroll = (view.infiniteScrollEnabled && !dataByGroup) ?? false;
5963 const currentPage = view?.page ?? 1;
5964 const perPage = view?.perPage ?? 0;
5965 const setSize = isInfiniteScroll ? paginationInfo?.totalItems : void 0;
5966 const gridColumns = useGridColumns();
5967 const placeholdersNeeded = usePlaceholdersNeeded(
5968 data,
5969 isInfiniteScroll,
5970 gridColumns
5971 );
5972 return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(import_jsx_runtime49.Fragment, {
5973 // Render multiple groups.
5974 children: [
5975 hasData && groupField && dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5976 import_components14.Composite,
5977 {
5978 virtualFocus: true,
5979 orientation: "horizontal",
5980 role: "listbox",
5981 "aria-multiselectable": isMultiselect,
5982 className: clsx_default(
5983 "dataviews-view-picker-grid",
5984 className,
5985 {
5986 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
5987 view.layout.density
5988 )
5989 }
5990 ),
5991 "aria-label": itemListLabel,
5992 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5993 Stack,
5994 {
5995 direction: "column",
5996 gap: "lg",
5997 children,
5998 ...props
5999 }
6000 ),
6001 children: Array.from(dataByGroup.entries()).map(
6002 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
6003 GridGroup,
6004 {
6005 groupName,
6006 groupField,
6007 showLabel: view.groupBy?.showLabel !== false,
6008 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
6009 GridItems,
6010 {
6011 previewSize: usedPreviewSize,
6012 style: {
6013 gridTemplateColumns: usedPreviewSize && `repeat(auto-fill, minmax(${usedPreviewSize}px, 1fr))`
6014 },
6015 "aria-busy": isLoading,
6016 ref: resizeObserverRef,
6017 children: groupItems.map((item) => {
6018 const posInSet = item.position ?? (currentPage - 1) * perPage + data.indexOf(item) + 1;
6019 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
6020 GridItem3,
6021 {
6022 view,
6023 multiselect: isMultiselect,
6024 selection,
6025 onChangeSelection,
6026 getItemId,
6027 item,
6028 mediaField,
6029 titleField,
6030 descriptionField: descriptionField2,
6031 regularFields,
6032 badgeFields,
6033 config: {
6034 sizes: size
6035 },
6036 posinset: posInSet,
6037 setsize: setSize
6038 },
6039 getItemId(item)
6040 );
6041 })
6042 }
6043 )
6044 },
6045 groupName
6046 )
6047 )
6048 }
6049 ),
6050 // Render a single grid with all data.
6051 hasData && !dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
6052 import_components14.Composite,
6053 {
6054 render: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
6055 GridItems,
6056 {
6057 className: clsx_default(
6058 "dataviews-view-picker-grid",
6059 className,
6060 {
6061 [`has-${view.layout?.density}-density`]: view.layout?.density && [
6062 "compact",
6063 "comfortable"
6064 ].includes(view.layout.density)
6065 }
6066 ),
6067 previewSize: usedPreviewSize,
6068 "aria-busy": isLoading,
6069 ref: resizeObserverRef
6070 }
6071 ),
6072 virtualFocus: true,
6073 orientation: "horizontal",
6074 role: "listbox",
6075 "aria-multiselectable": isMultiselect,
6076 "aria-label": itemListLabel,
6077 children: [
6078 Array.from({ length: placeholdersNeeded }).map(
6079 (_, index) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
6080 import_components14.Composite.Item,
6081 {
6082 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
6083 Stack,
6084 {
6085 direction: "column",
6086 children,
6087 ...props
6088 }
6089 ),
6090 role: "option",
6091 "aria-hidden": true,
6092 tabIndex: -1,
6093 className: "dataviews-view-picker-grid__card dataviews-view-picker-grid__placeholder"
6094 },
6095 `placeholder-${index}`
6096 )
6097 ),
6098 data.map((item) => {
6099 const posinset = item.position;
6100 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
6101 GridItem3,
6102 {
6103 view,
6104 multiselect: isMultiselect,
6105 selection,
6106 onChangeSelection,
6107 getItemId,
6108 item,
6109 mediaField,
6110 titleField,
6111 descriptionField: descriptionField2,
6112 regularFields,
6113 badgeFields,
6114 config: {
6115 sizes: size
6116 },
6117 posinset,
6118 setsize: setSize
6119 },
6120 getItemId(item)
6121 );
6122 })
6123 ]
6124 }
6125 ),
6126 // Render empty state.
6127 !hasData && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
6128 "div",
6129 {
6130 className: clsx_default({
6131 "dataviews-loading": isLoading,
6132 "dataviews-no-results": !isLoading
6133 }),
6134 children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_components14.Spinner, {}) }) : empty
6135 }
6136 ),
6137 hasData && isLoading && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_components14.Spinner, {}) })
6138 ]
6139 });
6140 }
6141 var picker_grid_default = ViewPickerGrid;
6142
6143 // packages/dataviews/build-module/components/dataviews-layouts/picker-table/index.mjs
6144 var import_i18n24 = __toESM(require_i18n(), 1);
6145 var import_components15 = __toESM(require_components(), 1);
6146 var import_element23 = __toESM(require_element(), 1);
6147 var import_jsx_runtime50 = __toESM(require_jsx_runtime(), 1);
6148 function TableColumnField2({
6149 item,
6150 fields,
6151 column,
6152 align
6153 }) {
6154 const field = fields.find((f2) => f2.id === column);
6155 if (!field) {
6156 return null;
6157 }
6158 const className = clsx_default("dataviews-view-table__cell-content-wrapper", {
6159 "dataviews-view-table__cell-align-end": align === "end",
6160 "dataviews-view-table__cell-align-center": align === "center"
6161 });
6162 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(field.render, { item, field }) });
6163 }
6164 function TableRow2({
6165 item,
6166 fields,
6167 id,
6168 view,
6169 titleField,
6170 mediaField,
6171 descriptionField: descriptionField2,
6172 selection,
6173 getItemId,
6174 onChangeSelection,
6175 multiselect,
6176 posinset
6177 }) {
6178 const { paginationInfo } = (0, import_element23.useContext)(dataviews_context_default);
6179 const isSelected2 = selection.includes(id);
6180 const [isHovered, setIsHovered] = (0, import_element23.useState)(false);
6181 const elementRef = (0, import_element23.useRef)(null);
6182 useIntersectionObserver(elementRef, posinset);
6183 const {
6184 showTitle = true,
6185 showMedia = true,
6186 showDescription = true,
6187 infiniteScrollEnabled
6188 } = view;
6189 const handleMouseEnter = () => {
6190 setIsHovered(true);
6191 };
6192 const handleMouseLeave = () => {
6193 setIsHovered(false);
6194 };
6195 const columns = view.fields ?? [];
6196 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
6197 return /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6198 import_components15.Composite.Item,
6199 {
6200 ref: elementRef,
6201 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6202 "tr",
6203 {
6204 className: clsx_default("dataviews-view-table__row", {
6205 "is-selected": isSelected2,
6206 "is-hovered": isHovered
6207 }),
6208 onMouseEnter: handleMouseEnter,
6209 onMouseLeave: handleMouseLeave,
6210 children,
6211 ...props
6212 }
6213 ),
6214 "aria-selected": isSelected2,
6215 "aria-setsize": paginationInfo.totalItems || void 0,
6216 "aria-posinset": posinset,
6217 role: infiniteScrollEnabled ? "article" : "option",
6218 onClick: () => {
6219 if (isSelected2) {
6220 onChangeSelection(
6221 selection.filter((itemId) => id !== itemId)
6222 );
6223 } else {
6224 const newSelection = multiselect ? [...selection, id] : [id];
6225 onChangeSelection(newSelection);
6226 }
6227 },
6228 children: [
6229 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6230 "td",
6231 {
6232 className: "dataviews-view-table__checkbox-column",
6233 role: "presentation",
6234 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("div", { className: "dataviews-view-table__cell-content-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6235 DataViewsSelectionCheckbox,
6236 {
6237 item,
6238 selection,
6239 onChangeSelection,
6240 getItemId,
6241 titleField,
6242 disabled: false,
6243 "aria-hidden": true,
6244 tabIndex: -1
6245 }
6246 ) })
6247 }
6248 ),
6249 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6250 "td",
6251 {
6252 role: "presentation",
6253 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6254 column_primary_default,
6255 {
6256 item,
6257 titleField: showTitle ? titleField : void 0,
6258 mediaField: showMedia ? mediaField : void 0,
6259 descriptionField: showDescription ? descriptionField2 : void 0,
6260 isItemClickable: () => false
6261 }
6262 )
6263 }
6264 ),
6265 columns.map((column) => {
6266 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
6267 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6268 "td",
6269 {
6270 style: {
6271 width,
6272 maxWidth,
6273 minWidth
6274 },
6275 role: "presentation",
6276 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6277 TableColumnField2,
6278 {
6279 fields,
6280 item,
6281 column,
6282 align
6283 }
6284 )
6285 },
6286 column
6287 );
6288 })
6289 ]
6290 },
6291 id
6292 );
6293 }
6294 function ViewPickerTable({
6295 actions,
6296 data,
6297 fields,
6298 getItemId,
6299 isLoading = false,
6300 onChangeView,
6301 onChangeSelection,
6302 selection,
6303 setOpenedFilter,
6304 view,
6305 className,
6306 empty
6307 }) {
6308 const headerMenuRefs = (0, import_element23.useRef)(/* @__PURE__ */ new Map());
6309 const headerMenuToFocusRef = (0, import_element23.useRef)(void 0);
6310 const [nextHeaderMenuToFocus, setNextHeaderMenuToFocus] = (0, import_element23.useState)();
6311 const isMultiselect = useIsMultiselectPicker(actions) ?? false;
6312 (0, import_element23.useEffect)(() => {
6313 if (headerMenuToFocusRef.current) {
6314 headerMenuToFocusRef.current.focus();
6315 headerMenuToFocusRef.current = void 0;
6316 }
6317 });
6318 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
6319 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
6320 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
6321 const tableNoticeId = (0, import_element23.useId)();
6322 if (nextHeaderMenuToFocus) {
6323 headerMenuToFocusRef.current = nextHeaderMenuToFocus;
6324 setNextHeaderMenuToFocus(void 0);
6325 return;
6326 }
6327 const onHide = (field) => {
6328 const hidden = headerMenuRefs.current.get(field.id);
6329 const fallback = hidden ? headerMenuRefs.current.get(hidden.fallback) : void 0;
6330 setNextHeaderMenuToFocus(fallback?.node);
6331 };
6332 const hasData = !!data?.length;
6333 const titleField = fields.find((field) => field.id === view.titleField);
6334 const mediaField = fields.find((field) => field.id === view.mediaField);
6335 const descriptionField2 = fields.find(
6336 (field) => field.id === view.descriptionField
6337 );
6338 const { showTitle = true, showMedia = true, showDescription = true } = view;
6339 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
6340 const columns = view.fields ?? [];
6341 const headerMenuRef = (column, index) => (node) => {
6342 if (node) {
6343 headerMenuRefs.current.set(column, {
6344 node,
6345 fallback: columns[index > 0 ? index - 1 : 1]
6346 });
6347 } else {
6348 headerMenuRefs.current.delete(column);
6349 }
6350 };
6351 return /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(import_jsx_runtime50.Fragment, { children: [
6352 /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6353 "table",
6354 {
6355 className: clsx_default(
6356 "dataviews-view-table",
6357 "dataviews-view-picker-table",
6358 className,
6359 {
6360 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
6361 view.layout.density
6362 )
6363 }
6364 ),
6365 "aria-busy": isLoading,
6366 "aria-describedby": tableNoticeId,
6367 role: isInfiniteScroll ? "feed" : "listbox",
6368 children: [
6369 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("thead", { role: "presentation", children: /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6370 "tr",
6371 {
6372 className: "dataviews-view-table__row",
6373 role: "presentation",
6374 children: [
6375 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("th", { className: "dataviews-view-table__checkbox-column", children: isMultiselect && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6376 BulkSelectionCheckbox,
6377 {
6378 selection,
6379 onChangeSelection,
6380 data,
6381 actions,
6382 getItemId,
6383 disableSelectAll: isInfiniteScroll
6384 }
6385 ) }),
6386 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("th", { children: titleField && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6387 column_header_menu_default,
6388 {
6389 ref: headerMenuRef(
6390 titleField.id,
6391 0
6392 ),
6393 fieldId: titleField.id,
6394 view,
6395 fields,
6396 onChangeView,
6397 onHide,
6398 setOpenedFilter,
6399 canMove: false
6400 }
6401 ) }),
6402 columns.map((column, index) => {
6403 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
6404 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6405 "th",
6406 {
6407 style: {
6408 width,
6409 maxWidth,
6410 minWidth,
6411 textAlign: align
6412 },
6413 "aria-sort": view.sort?.direction && view.sort?.field === column ? sortValues[view.sort.direction] : void 0,
6414 scope: "col",
6415 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6416 column_header_menu_default,
6417 {
6418 ref: headerMenuRef(column, index),
6419 fieldId: column,
6420 view,
6421 fields,
6422 onChangeView,
6423 onHide,
6424 setOpenedFilter,
6425 canMove: view.layout?.enableMoving ?? true
6426 }
6427 )
6428 },
6429 column
6430 );
6431 })
6432 ]
6433 }
6434 ) }),
6435 hasData && groupField && dataByGroup ? Array.from(dataByGroup.entries()).map(
6436 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6437 import_components15.Composite,
6438 {
6439 virtualFocus: true,
6440 orientation: "vertical",
6441 render: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("tbody", { role: "group" }),
6442 children: [
6443 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6444 "tr",
6445 {
6446 className: "dataviews-view-table__group-header-row",
6447 role: "presentation",
6448 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6449 "td",
6450 {
6451 colSpan: columns.length + (hasPrimaryColumn ? 1 : 0) + 1,
6452 className: "dataviews-view-table__group-header-cell",
6453 role: "presentation",
6454 children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n24.sprintf)(
6455 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
6456 (0, import_i18n24.__)("%1$s: %2$s"),
6457 groupField.label,
6458 groupName
6459 )
6460 }
6461 )
6462 }
6463 ),
6464 groupItems.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6465 TableRow2,
6466 {
6467 item,
6468 fields,
6469 id: getItemId(item) || index.toString(),
6470 view,
6471 titleField,
6472 mediaField,
6473 descriptionField: descriptionField2,
6474 selection,
6475 getItemId,
6476 onChangeSelection,
6477 multiselect: isMultiselect
6478 },
6479 getItemId(item)
6480 ))
6481 ]
6482 },
6483 `group-${groupName}`
6484 )
6485 ) : /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6486 import_components15.Composite,
6487 {
6488 render: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("tbody", { role: "presentation" }),
6489 virtualFocus: true,
6490 orientation: "vertical",
6491 children: hasData && data.map((item, index) => {
6492 const itemId = getItemId(item);
6493 const posinset = item.position;
6494 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6495 TableRow2,
6496 {
6497 item,
6498 fields,
6499 id: itemId || index.toString(),
6500 view,
6501 titleField,
6502 mediaField,
6503 descriptionField: descriptionField2,
6504 selection,
6505 getItemId,
6506 onChangeSelection,
6507 multiselect: isMultiselect,
6508 posinset
6509 },
6510 itemId
6511 );
6512 })
6513 }
6514 )
6515 ]
6516 }
6517 ),
6518 /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6519 "div",
6520 {
6521 className: clsx_default({
6522 "dataviews-loading": isLoading,
6523 "dataviews-no-results": !hasData && !isLoading
6524 }),
6525 id: tableNoticeId,
6526 children: [
6527 !hasData && (isLoading ? /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(import_components15.Spinner, {}) }) : empty),
6528 hasData && isLoading && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(import_components15.Spinner, {}) })
6529 ]
6530 }
6531 )
6532 ] });
6533 }
6534 var picker_table_default = ViewPickerTable;
6535
6536 // packages/dataviews/build-module/components/dataviews-layouts/utils/density-picker.mjs
6537 var import_components16 = __toESM(require_components(), 1);
6538 var import_i18n25 = __toESM(require_i18n(), 1);
6539 var import_element24 = __toESM(require_element(), 1);
6540 var import_jsx_runtime51 = __toESM(require_jsx_runtime(), 1);
6541 function DensityPicker() {
6542 const context = (0, import_element24.useContext)(dataviews_context_default);
6543 const view = context.view;
6544 return /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)(
6545 import_components16.__experimentalToggleGroupControl,
6546 {
6547 size: "__unstable-large",
6548 label: (0, import_i18n25.__)("Density"),
6549 value: view.layout?.density || "balanced",
6550 onChange: (value) => {
6551 context.onChangeView({
6552 ...view,
6553 layout: {
6554 ...view.layout,
6555 density: value
6556 }
6557 });
6558 },
6559 isBlock: true,
6560 children: [
6561 /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
6562 import_components16.__experimentalToggleGroupControlOption,
6563 {
6564 value: "comfortable",
6565 label: (0, import_i18n25._x)(
6566 "Comfortable",
6567 "Density option for DataView layout"
6568 )
6569 },
6570 "comfortable"
6571 ),
6572 /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
6573 import_components16.__experimentalToggleGroupControlOption,
6574 {
6575 value: "balanced",
6576 label: (0, import_i18n25._x)("Balanced", "Density option for DataView layout")
6577 },
6578 "balanced"
6579 ),
6580 /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
6581 import_components16.__experimentalToggleGroupControlOption,
6582 {
6583 value: "compact",
6584 label: (0, import_i18n25._x)("Compact", "Density option for DataView layout")
6585 },
6586 "compact"
6587 )
6588 ]
6589 }
6590 );
6591 }
6592
6593 // packages/dataviews/build-module/components/dataviews-layouts/utils/preview-size-picker.mjs
6594 var import_components17 = __toESM(require_components(), 1);
6595 var import_i18n26 = __toESM(require_i18n(), 1);
6596 var import_element25 = __toESM(require_element(), 1);
6597 var import_jsx_runtime52 = __toESM(require_jsx_runtime(), 1);
6598 var imageSizes2 = [
6599 {
6600 value: 120,
6601 breakpoint: 1
6602 },
6603 {
6604 value: 170,
6605 breakpoint: 1
6606 },
6607 {
6608 value: 230,
6609 breakpoint: 1
6610 },
6611 {
6612 value: 290,
6613 breakpoint: 1112
6614 // at minimum image width, 4 images display at this container size
6615 },
6616 {
6617 value: 350,
6618 breakpoint: 1636
6619 // at minimum image width, 6 images display at this container size
6620 },
6621 {
6622 value: 430,
6623 breakpoint: 588
6624 // at minimum image width, 2 images display at this container size
6625 }
6626 ];
6627 function PreviewSizePicker() {
6628 const context = (0, import_element25.useContext)(dataviews_context_default);
6629 const view = context.view;
6630 const breakValues = imageSizes2.filter((size) => {
6631 return context.containerWidth >= size.breakpoint;
6632 });
6633 const layoutPreviewSize = view.layout?.previewSize ?? 230;
6634 const previewSizeToUse = breakValues.map((size, index) => ({ ...size, index })).filter((size) => size.value <= layoutPreviewSize).sort((a2, b2) => b2.value - a2.value)[0]?.index ?? 0;
6635 const marks = breakValues.map((size, index) => {
6636 return {
6637 value: index
6638 };
6639 });
6640 return /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(
6641 import_components17.RangeControl,
6642 {
6643 __next40pxDefaultSize: true,
6644 showTooltip: false,
6645 label: (0, import_i18n26.__)("Preview size"),
6646 value: previewSizeToUse,
6647 min: 0,
6648 max: breakValues.length - 1,
6649 withInputField: false,
6650 onChange: (value = 0) => {
6651 context.onChangeView({
6652 ...view,
6653 layout: {
6654 ...view.layout,
6655 previewSize: breakValues[value].value
6656 }
6657 });
6658 },
6659 step: 1,
6660 marks
6661 }
6662 );
6663 }
6664
6665 // packages/dataviews/build-module/components/dataviews-layouts/utils/grid-config-options.mjs
6666 var import_jsx_runtime53 = __toESM(require_jsx_runtime(), 1);
6667 function GridConfigOptions() {
6668 return /* @__PURE__ */ (0, import_jsx_runtime53.jsxs)(import_jsx_runtime53.Fragment, { children: [
6669 /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(DensityPicker, {}),
6670 /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(PreviewSizePicker, {})
6671 ] });
6672 }
6673
6674 // packages/dataviews/build-module/components/dataviews-layouts/index.mjs
6675 var VIEW_LAYOUTS = [
6676 {
6677 type: LAYOUT_TABLE,
6678 label: (0, import_i18n27.__)("Table"),
6679 component: table_default,
6680 icon: block_table_default,
6681 viewConfigOptions: DensityPicker
6682 },
6683 {
6684 type: LAYOUT_GRID,
6685 label: (0, import_i18n27.__)("Grid"),
6686 component: grid_default,
6687 icon: category_default,
6688 viewConfigOptions: GridConfigOptions
6689 },
6690 {
6691 type: LAYOUT_LIST,
6692 label: (0, import_i18n27.__)("List"),
6693 component: ViewList,
6694 icon: (0, import_i18n27.isRTL)() ? format_list_bullets_rtl_default : format_list_bullets_default,
6695 viewConfigOptions: DensityPicker
6696 },
6697 {
6698 type: LAYOUT_ACTIVITY,
6699 label: (0, import_i18n27.__)("Activity"),
6700 component: ViewActivity,
6701 icon: scheduled_default,
6702 viewConfigOptions: DensityPicker
6703 },
6704 {
6705 type: LAYOUT_PICKER_GRID,
6706 label: (0, import_i18n27.__)("Grid"),
6707 component: picker_grid_default,
6708 icon: category_default,
6709 viewConfigOptions: GridConfigOptions,
6710 isPicker: true
6711 },
6712 {
6713 type: LAYOUT_PICKER_TABLE,
6714 label: (0, import_i18n27.__)("Table"),
6715 component: picker_table_default,
6716 icon: block_table_default,
6717 viewConfigOptions: DensityPicker,
6718 isPicker: true
6719 }
6720 ];
6721
6722 // packages/dataviews/build-module/components/dataviews-filters/filters.mjs
6723 var import_element33 = __toESM(require_element(), 1);
6724
6725 // packages/dataviews/build-module/components/dataviews-filters/filter.mjs
6726 var import_components20 = __toESM(require_components(), 1);
6727 var import_i18n30 = __toESM(require_i18n(), 1);
6728 var import_element30 = __toESM(require_element(), 1);
6729
6730 // node_modules/@ariakit/core/esm/__chunks/XMCVU3LR.js
6731 function noop2(..._) {
6732 }
6733 function applyState(argument, currentValue) {
6734 if (isUpdater(argument)) {
6735 const value = isLazyValue(currentValue) ? currentValue() : currentValue;
6736 return argument(value);
6737 }
6738 return argument;
6739 }
6740 function isUpdater(argument) {
6741 return typeof argument === "function";
6742 }
6743 function isLazyValue(value) {
6744 return typeof value === "function";
6745 }
6746 function hasOwnProperty(object, prop) {
6747 if (typeof Object.hasOwn === "function") {
6748 return Object.hasOwn(object, prop);
6749 }
6750 return Object.prototype.hasOwnProperty.call(object, prop);
6751 }
6752 function chain(...fns) {
6753 return (...args) => {
6754 for (const fn of fns) {
6755 if (typeof fn === "function") {
6756 fn(...args);
6757 }
6758 }
6759 };
6760 }
6761 function normalizeString(str) {
6762 return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
6763 }
6764 function omit(object, keys) {
6765 const result = { ...object };
6766 for (const key of keys) {
6767 if (hasOwnProperty(result, key)) {
6768 delete result[key];
6769 }
6770 }
6771 return result;
6772 }
6773 function pick(object, paths) {
6774 const result = {};
6775 for (const key of paths) {
6776 if (hasOwnProperty(object, key)) {
6777 result[key] = object[key];
6778 }
6779 }
6780 return result;
6781 }
6782 function identity(value) {
6783 return value;
6784 }
6785 function invariant(condition, message2) {
6786 if (condition) return;
6787 if (typeof message2 !== "string") throw new Error("Invariant failed");
6788 throw new Error(message2);
6789 }
6790 function getKeys(obj) {
6791 return Object.keys(obj);
6792 }
6793 function isFalsyBooleanCallback(booleanOrCallback, ...args) {
6794 const result = typeof booleanOrCallback === "function" ? booleanOrCallback(...args) : booleanOrCallback;
6795 if (result == null) return false;
6796 return !result;
6797 }
6798 function disabledFromProps(props) {
6799 return props.disabled || props["aria-disabled"] === true || props["aria-disabled"] === "true";
6800 }
6801 function removeUndefinedValues(obj) {
6802 const result = {};
6803 for (const key in obj) {
6804 if (obj[key] !== void 0) {
6805 result[key] = obj[key];
6806 }
6807 }
6808 return result;
6809 }
6810 function defaultValue(...values) {
6811 for (const value of values) {
6812 if (value !== void 0) return value;
6813 }
6814 return void 0;
6815 }
6816
6817 // node_modules/@ariakit/react-core/esm/__chunks/YXGXYGQX.js
6818 var import_react5 = __toESM(require_react(), 1);
6819 function setRef(ref, value) {
6820 if (typeof ref === "function") {
6821 ref(value);
6822 } else if (ref) {
6823 ref.current = value;
6824 }
6825 }
6826 function isValidElementWithRef(element) {
6827 if (!element) return false;
6828 if (!(0, import_react5.isValidElement)(element)) return false;
6829 if ("ref" in element.props) return true;
6830 if ("ref" in element) return true;
6831 return false;
6832 }
6833 function getRefProperty(element) {
6834 if (!isValidElementWithRef(element)) return null;
6835 const props = { ...element.props };
6836 return props.ref || element.ref;
6837 }
6838 function mergeProps2(base, overrides) {
6839 const props = { ...base };
6840 for (const key in overrides) {
6841 if (!hasOwnProperty(overrides, key)) continue;
6842 if (key === "className") {
6843 const prop = "className";
6844 props[prop] = base[prop] ? `${base[prop]} ${overrides[prop]}` : overrides[prop];
6845 continue;
6846 }
6847 if (key === "style") {
6848 const prop = "style";
6849 props[prop] = base[prop] ? { ...base[prop], ...overrides[prop] } : overrides[prop];
6850 continue;
6851 }
6852 const overrideValue = overrides[key];
6853 if (typeof overrideValue === "function" && key.startsWith("on")) {
6854 const baseValue = base[key];
6855 if (typeof baseValue === "function") {
6856 props[key] = (...args) => {
6857 overrideValue(...args);
6858 baseValue(...args);
6859 };
6860 continue;
6861 }
6862 }
6863 props[key] = overrideValue;
6864 }
6865 return props;
6866 }
6867
6868 // node_modules/@ariakit/core/esm/__chunks/3DNM6L6E.js
6869 var canUseDOM = checkIsBrowser();
6870 function checkIsBrowser() {
6871 var _a;
6872 return typeof window !== "undefined" && !!((_a = window.document) == null ? void 0 : _a.createElement);
6873 }
6874 function getDocument(node) {
6875 if (!node) return document;
6876 if ("self" in node) return node.document;
6877 return node.ownerDocument || document;
6878 }
6879 function getActiveElement(node, activeDescendant = false) {
6880 var _a;
6881 const { activeElement } = getDocument(node);
6882 if (!(activeElement == null ? void 0 : activeElement.nodeName)) {
6883 return null;
6884 }
6885 if (isFrame(activeElement) && ((_a = activeElement.contentDocument) == null ? void 0 : _a.body)) {
6886 return getActiveElement(
6887 activeElement.contentDocument.body,
6888 activeDescendant
6889 );
6890 }
6891 if (activeDescendant) {
6892 const id = activeElement.getAttribute("aria-activedescendant");
6893 if (id) {
6894 const element = getDocument(activeElement).getElementById(id);
6895 if (element) {
6896 return element;
6897 }
6898 }
6899 }
6900 return activeElement;
6901 }
6902 function contains(parent, child) {
6903 return parent === child || parent.contains(child);
6904 }
6905 function isFrame(element) {
6906 return element.tagName === "IFRAME";
6907 }
6908 function isButton(element) {
6909 const tagName = element.tagName.toLowerCase();
6910 if (tagName === "button") return true;
6911 if (tagName === "input" && element.type) {
6912 return buttonInputTypes.indexOf(element.type) !== -1;
6913 }
6914 return false;
6915 }
6916 var buttonInputTypes = [
6917 "button",
6918 "color",
6919 "file",
6920 "image",
6921 "reset",
6922 "submit"
6923 ];
6924 function isVisible(element) {
6925 if (typeof element.checkVisibility === "function") {
6926 return element.checkVisibility();
6927 }
6928 const htmlElement = element;
6929 return htmlElement.offsetWidth > 0 || htmlElement.offsetHeight > 0 || element.getClientRects().length > 0;
6930 }
6931 function isTextField(element) {
6932 try {
6933 const isTextInput = element instanceof HTMLInputElement && element.selectionStart !== null;
6934 const isTextArea = element.tagName === "TEXTAREA";
6935 return isTextInput || isTextArea || false;
6936 } catch (_error) {
6937 return false;
6938 }
6939 }
6940 function isTextbox(element) {
6941 return element.isContentEditable || isTextField(element);
6942 }
6943 function getTextboxValue(element) {
6944 if (isTextField(element)) {
6945 return element.value;
6946 }
6947 if (element.isContentEditable) {
6948 const range = getDocument(element).createRange();
6949 range.selectNodeContents(element);
6950 return range.toString();
6951 }
6952 return "";
6953 }
6954 function getTextboxSelection(element) {
6955 let start = 0;
6956 let end = 0;
6957 if (isTextField(element)) {
6958 start = element.selectionStart || 0;
6959 end = element.selectionEnd || 0;
6960 } else if (element.isContentEditable) {
6961 const selection = getDocument(element).getSelection();
6962 if ((selection == null ? void 0 : selection.rangeCount) && selection.anchorNode && contains(element, selection.anchorNode) && selection.focusNode && contains(element, selection.focusNode)) {
6963 const range = selection.getRangeAt(0);
6964 const nextRange = range.cloneRange();
6965 nextRange.selectNodeContents(element);
6966 nextRange.setEnd(range.startContainer, range.startOffset);
6967 start = nextRange.toString().length;
6968 nextRange.setEnd(range.endContainer, range.endOffset);
6969 end = nextRange.toString().length;
6970 }
6971 }
6972 return { start, end };
6973 }
6974 function getPopupRole(element, fallback) {
6975 const allowedPopupRoles = ["dialog", "menu", "listbox", "tree", "grid"];
6976 const role = element == null ? void 0 : element.getAttribute("role");
6977 if (role && allowedPopupRoles.indexOf(role) !== -1) {
6978 return role;
6979 }
6980 return fallback;
6981 }
6982 function getScrollingElement(element) {
6983 if (!element) return null;
6984 const isScrollableOverflow = (overflow) => {
6985 if (overflow === "auto") return true;
6986 if (overflow === "scroll") return true;
6987 return false;
6988 };
6989 if (element.clientHeight && element.scrollHeight > element.clientHeight) {
6990 const { overflowY } = getComputedStyle(element);
6991 if (isScrollableOverflow(overflowY)) return element;
6992 } else if (element.clientWidth && element.scrollWidth > element.clientWidth) {
6993 const { overflowX } = getComputedStyle(element);
6994 if (isScrollableOverflow(overflowX)) return element;
6995 }
6996 return getScrollingElement(element.parentElement) || document.scrollingElement || document.body;
6997 }
6998 function setSelectionRange(element, ...args) {
6999 if (/text|search|password|tel|url/i.test(element.type)) {
7000 element.setSelectionRange(...args);
7001 }
7002 }
7003 function sortBasedOnDOMPosition(items, getElement) {
7004 const pairs = items.map((item, index) => [index, item]);
7005 let isOrderDifferent = false;
7006 pairs.sort(([indexA, a2], [indexB, b2]) => {
7007 const elementA = getElement(a2);
7008 const elementB = getElement(b2);
7009 if (elementA === elementB) return 0;
7010 if (!elementA || !elementB) return 0;
7011 if (isElementPreceding(elementA, elementB)) {
7012 if (indexA > indexB) {
7013 isOrderDifferent = true;
7014 }
7015 return -1;
7016 }
7017 if (indexA < indexB) {
7018 isOrderDifferent = true;
7019 }
7020 return 1;
7021 });
7022 if (isOrderDifferent) {
7023 return pairs.map(([_, item]) => item);
7024 }
7025 return items;
7026 }
7027 function isElementPreceding(a2, b2) {
7028 return Boolean(
7029 b2.compareDocumentPosition(a2) & Node.DOCUMENT_POSITION_PRECEDING
7030 );
7031 }
7032
7033 // node_modules/@ariakit/core/esm/__chunks/SNHYQNEZ.js
7034 function isTouchDevice() {
7035 return canUseDOM && !!navigator.maxTouchPoints;
7036 }
7037 function isApple() {
7038 if (!canUseDOM) return false;
7039 return /mac|iphone|ipad|ipod/i.test(navigator.platform);
7040 }
7041 function isSafari() {
7042 return canUseDOM && isApple() && /apple/i.test(navigator.vendor);
7043 }
7044 function isFirefox() {
7045 return canUseDOM && /firefox\//i.test(navigator.userAgent);
7046 }
7047
7048 // node_modules/@ariakit/core/esm/utils/events.js
7049 function isPortalEvent(event) {
7050 return Boolean(
7051 event.currentTarget && !contains(event.currentTarget, event.target)
7052 );
7053 }
7054 function isSelfTarget(event) {
7055 return event.target === event.currentTarget;
7056 }
7057 function isOpeningInNewTab(event) {
7058 const element = event.currentTarget;
7059 if (!element) return false;
7060 const isAppleDevice = isApple();
7061 if (isAppleDevice && !event.metaKey) return false;
7062 if (!isAppleDevice && !event.ctrlKey) return false;
7063 const tagName = element.tagName.toLowerCase();
7064 if (tagName === "a") return true;
7065 if (tagName === "button" && element.type === "submit") return true;
7066 if (tagName === "input" && element.type === "submit") return true;
7067 return false;
7068 }
7069 function isDownloading(event) {
7070 const element = event.currentTarget;
7071 if (!element) return false;
7072 const tagName = element.tagName.toLowerCase();
7073 if (!event.altKey) return false;
7074 if (tagName === "a") return true;
7075 if (tagName === "button" && element.type === "submit") return true;
7076 if (tagName === "input" && element.type === "submit") return true;
7077 return false;
7078 }
7079 function fireBlurEvent(element, eventInit) {
7080 const event = new FocusEvent("blur", eventInit);
7081 const defaultAllowed = element.dispatchEvent(event);
7082 const bubbleInit = { ...eventInit, bubbles: true };
7083 element.dispatchEvent(new FocusEvent("focusout", bubbleInit));
7084 return defaultAllowed;
7085 }
7086 function fireKeyboardEvent(element, type, eventInit) {
7087 const event = new KeyboardEvent(type, eventInit);
7088 return element.dispatchEvent(event);
7089 }
7090 function fireClickEvent(element, eventInit) {
7091 const event = new MouseEvent("click", eventInit);
7092 return element.dispatchEvent(event);
7093 }
7094 function isFocusEventOutside(event, container) {
7095 const containerElement = container || event.currentTarget;
7096 const relatedTarget = event.relatedTarget;
7097 return !relatedTarget || !contains(containerElement, relatedTarget);
7098 }
7099 function queueBeforeEvent(element, type, callback, timeout) {
7100 const createTimer = (callback2) => {
7101 if (timeout) {
7102 const timerId2 = setTimeout(callback2, timeout);
7103 return () => clearTimeout(timerId2);
7104 }
7105 const timerId = requestAnimationFrame(callback2);
7106 return () => cancelAnimationFrame(timerId);
7107 };
7108 const cancelTimer = createTimer(() => {
7109 element.removeEventListener(type, callSync, true);
7110 callback();
7111 });
7112 const callSync = () => {
7113 cancelTimer();
7114 callback();
7115 };
7116 element.addEventListener(type, callSync, { once: true, capture: true });
7117 return cancelTimer;
7118 }
7119 function addGlobalEventListener(type, listener, options, scope = window) {
7120 const children = [];
7121 try {
7122 scope.document.addEventListener(type, listener, options);
7123 for (const frame of Array.from(scope.frames)) {
7124 children.push(addGlobalEventListener(type, listener, options, frame));
7125 }
7126 } catch (e2) {
7127 }
7128 const removeEventListener = () => {
7129 try {
7130 scope.document.removeEventListener(type, listener, options);
7131 } catch (e2) {
7132 }
7133 for (const remove of children) {
7134 remove();
7135 }
7136 };
7137 return removeEventListener;
7138 }
7139
7140 // node_modules/@ariakit/react-core/esm/__chunks/KPHZR4MB.js
7141 var React5 = __toESM(require_react(), 1);
7142 var import_react6 = __toESM(require_react(), 1);
7143 var _React = { ...React5 };
7144 var useReactId = _React.useId;
7145 var useReactDeferredValue = _React.useDeferredValue;
7146 var useReactInsertionEffect = _React.useInsertionEffect;
7147 var useSafeLayoutEffect = canUseDOM ? import_react6.useLayoutEffect : import_react6.useEffect;
7148 function useInitialValue(value) {
7149 const [initialValue] = (0, import_react6.useState)(value);
7150 return initialValue;
7151 }
7152 function useLiveRef(value) {
7153 const ref = (0, import_react6.useRef)(value);
7154 useSafeLayoutEffect(() => {
7155 ref.current = value;
7156 });
7157 return ref;
7158 }
7159 function useEvent(callback) {
7160 const ref = (0, import_react6.useRef)(() => {
7161 throw new Error("Cannot call an event handler while rendering.");
7162 });
7163 if (useReactInsertionEffect) {
7164 useReactInsertionEffect(() => {
7165 ref.current = callback;
7166 });
7167 } else {
7168 ref.current = callback;
7169 }
7170 return (0, import_react6.useCallback)((...args) => {
7171 var _a;
7172 return (_a = ref.current) == null ? void 0 : _a.call(ref, ...args);
7173 }, []);
7174 }
7175 function useTransactionState(callback) {
7176 const [state, setState] = (0, import_react6.useState)(null);
7177 useSafeLayoutEffect(() => {
7178 if (state == null) return;
7179 if (!callback) return;
7180 let prevState = null;
7181 callback((prev) => {
7182 prevState = prev;
7183 return state;
7184 });
7185 return () => {
7186 callback(prevState);
7187 };
7188 }, [state, callback]);
7189 return [state, setState];
7190 }
7191 function useMergeRefs(...refs) {
7192 return (0, import_react6.useMemo)(() => {
7193 if (!refs.some(Boolean)) return;
7194 return (value) => {
7195 for (const ref of refs) {
7196 setRef(ref, value);
7197 }
7198 };
7199 }, refs);
7200 }
7201 function useId3(defaultId) {
7202 if (useReactId) {
7203 const reactId = useReactId();
7204 if (defaultId) return defaultId;
7205 return reactId;
7206 }
7207 const [id, setId] = (0, import_react6.useState)(defaultId);
7208 useSafeLayoutEffect(() => {
7209 if (defaultId || id) return;
7210 const random = Math.random().toString(36).slice(2, 8);
7211 setId(`id-${random}`);
7212 }, [defaultId, id]);
7213 return defaultId || id;
7214 }
7215 function useTagName(refOrElement, type) {
7216 const stringOrUndefined = (type2) => {
7217 if (typeof type2 !== "string") return;
7218 return type2;
7219 };
7220 const [tagName, setTagName] = (0, import_react6.useState)(() => stringOrUndefined(type));
7221 useSafeLayoutEffect(() => {
7222 const element = refOrElement && "current" in refOrElement ? refOrElement.current : refOrElement;
7223 setTagName((element == null ? void 0 : element.tagName.toLowerCase()) || stringOrUndefined(type));
7224 }, [refOrElement, type]);
7225 return tagName;
7226 }
7227 function useAttribute(refOrElement, attributeName, defaultValue2) {
7228 const initialValue = useInitialValue(defaultValue2);
7229 const [attribute, setAttribute] = (0, import_react6.useState)(initialValue);
7230 (0, import_react6.useEffect)(() => {
7231 const element = refOrElement && "current" in refOrElement ? refOrElement.current : refOrElement;
7232 if (!element) return;
7233 const callback = () => {
7234 const value = element.getAttribute(attributeName);
7235 setAttribute(value == null ? initialValue : value);
7236 };
7237 const observer = new MutationObserver(callback);
7238 observer.observe(element, { attributeFilter: [attributeName] });
7239 callback();
7240 return () => observer.disconnect();
7241 }, [refOrElement, attributeName, initialValue]);
7242 return attribute;
7243 }
7244 function useUpdateEffect(effect, deps) {
7245 const mounted = (0, import_react6.useRef)(false);
7246 (0, import_react6.useEffect)(() => {
7247 if (mounted.current) {
7248 return effect();
7249 }
7250 mounted.current = true;
7251 }, deps);
7252 (0, import_react6.useEffect)(
7253 () => () => {
7254 mounted.current = false;
7255 },
7256 []
7257 );
7258 }
7259 function useUpdateLayoutEffect(effect, deps) {
7260 const mounted = (0, import_react6.useRef)(false);
7261 useSafeLayoutEffect(() => {
7262 if (mounted.current) {
7263 return effect();
7264 }
7265 mounted.current = true;
7266 }, deps);
7267 useSafeLayoutEffect(
7268 () => () => {
7269 mounted.current = false;
7270 },
7271 []
7272 );
7273 }
7274 function useForceUpdate() {
7275 return (0, import_react6.useReducer)(() => [], []);
7276 }
7277 function useBooleanEvent(booleanOrCallback) {
7278 return useEvent(
7279 typeof booleanOrCallback === "function" ? booleanOrCallback : () => booleanOrCallback
7280 );
7281 }
7282 function useWrapElement(props, callback, deps = []) {
7283 const wrapElement = (0, import_react6.useCallback)(
7284 (element) => {
7285 if (props.wrapElement) {
7286 element = props.wrapElement(element);
7287 }
7288 return callback(element);
7289 },
7290 [...deps, props.wrapElement]
7291 );
7292 return { ...props, wrapElement };
7293 }
7294 function useMetadataProps(props, key, value) {
7295 const parent = props.onLoadedMetadataCapture;
7296 const onLoadedMetadataCapture = (0, import_react6.useMemo)(() => {
7297 return Object.assign(() => {
7298 }, { ...parent, [key]: value });
7299 }, [parent, key, value]);
7300 return [parent == null ? void 0 : parent[key], { onLoadedMetadataCapture }];
7301 }
7302 var hasInstalledGlobalEventListeners = false;
7303 function useIsMouseMoving() {
7304 (0, import_react6.useEffect)(() => {
7305 if (hasInstalledGlobalEventListeners) return;
7306 addGlobalEventListener("mousemove", setMouseMoving, true);
7307 addGlobalEventListener("mousedown", resetMouseMoving, true);
7308 addGlobalEventListener("mouseup", resetMouseMoving, true);
7309 addGlobalEventListener("keydown", resetMouseMoving, true);
7310 addGlobalEventListener("scroll", resetMouseMoving, true);
7311 hasInstalledGlobalEventListeners = true;
7312 }, []);
7313 const isMouseMoving = useEvent(() => mouseMoving);
7314 return isMouseMoving;
7315 }
7316 var mouseMoving = false;
7317 var previousScreenX = 0;
7318 var previousScreenY = 0;
7319 function hasMouseMovement(event) {
7320 const movementX = event.movementX || event.screenX - previousScreenX;
7321 const movementY = event.movementY || event.screenY - previousScreenY;
7322 previousScreenX = event.screenX;
7323 previousScreenY = event.screenY;
7324 return movementX || movementY || false;
7325 }
7326 function setMouseMoving(event) {
7327 if (!hasMouseMovement(event)) return;
7328 mouseMoving = true;
7329 }
7330 function resetMouseMoving() {
7331 mouseMoving = false;
7332 }
7333
7334 // node_modules/@ariakit/react-core/esm/__chunks/GWSL6KNJ.js
7335 var React6 = __toESM(require_react(), 1);
7336 var import_jsx_runtime54 = __toESM(require_jsx_runtime(), 1);
7337 function forwardRef22(render4) {
7338 const Role = React6.forwardRef(
7339 // @ts-ignore Incompatible with React 19 types. Ignore for now.
7340 (props, ref) => render4({ ...props, ref })
7341 );
7342 Role.displayName = render4.displayName || render4.name;
7343 return Role;
7344 }
7345 function memo22(Component2, propsAreEqual) {
7346 return React6.memo(Component2, propsAreEqual);
7347 }
7348 function createElement3(Type, props) {
7349 const { wrapElement, render: render4, ...rest } = props;
7350 const mergedRef = useMergeRefs(props.ref, getRefProperty(render4));
7351 let element;
7352 if (React6.isValidElement(render4)) {
7353 const renderProps = {
7354 // @ts-ignore Incompatible with React 19 types. Ignore for now.
7355 ...render4.props,
7356 ref: mergedRef
7357 };
7358 element = React6.cloneElement(render4, mergeProps2(rest, renderProps));
7359 } else if (render4) {
7360 element = render4(rest);
7361 } else {
7362 element = /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(Type, { ...rest });
7363 }
7364 if (wrapElement) {
7365 return wrapElement(element);
7366 }
7367 return element;
7368 }
7369 function createHook(useProps) {
7370 const useRole = (props = {}) => {
7371 return useProps(props);
7372 };
7373 useRole.displayName = useProps.name;
7374 return useRole;
7375 }
7376 function createStoreContext(providers = [], scopedProviders = []) {
7377 const context = React6.createContext(void 0);
7378 const scopedContext = React6.createContext(void 0);
7379 const useContext28 = () => React6.useContext(context);
7380 const useScopedContext = (onlyScoped = false) => {
7381 const scoped = React6.useContext(scopedContext);
7382 const store = useContext28();
7383 if (onlyScoped) return scoped;
7384 return scoped || store;
7385 };
7386 const useProviderContext = () => {
7387 const scoped = React6.useContext(scopedContext);
7388 const store = useContext28();
7389 if (scoped && scoped === store) return;
7390 return store;
7391 };
7392 const ContextProvider = (props) => {
7393 return providers.reduceRight(
7394 (children, Provider) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(Provider, { ...props, children }),
7395 /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(context.Provider, { ...props })
7396 );
7397 };
7398 const ScopedContextProvider = (props) => {
7399 return /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(ContextProvider, { ...props, children: scopedProviders.reduceRight(
7400 (children, Provider) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(Provider, { ...props, children }),
7401 /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(scopedContext.Provider, { ...props })
7402 ) });
7403 };
7404 return {
7405 context,
7406 scopedContext,
7407 useContext: useContext28,
7408 useScopedContext,
7409 useProviderContext,
7410 ContextProvider,
7411 ScopedContextProvider
7412 };
7413 }
7414
7415 // node_modules/@ariakit/react-core/esm/__chunks/SMPCIMZM.js
7416 var ctx = createStoreContext();
7417 var useCollectionContext = ctx.useContext;
7418 var useCollectionScopedContext = ctx.useScopedContext;
7419 var useCollectionProviderContext = ctx.useProviderContext;
7420 var CollectionContextProvider = ctx.ContextProvider;
7421 var CollectionScopedContextProvider = ctx.ScopedContextProvider;
7422
7423 // node_modules/@ariakit/react-core/esm/__chunks/AVVXDJMZ.js
7424 var import_react7 = __toESM(require_react(), 1);
7425 var ctx2 = createStoreContext(
7426 [CollectionContextProvider],
7427 [CollectionScopedContextProvider]
7428 );
7429 var useCompositeContext = ctx2.useContext;
7430 var useCompositeScopedContext = ctx2.useScopedContext;
7431 var useCompositeProviderContext = ctx2.useProviderContext;
7432 var CompositeContextProvider = ctx2.ContextProvider;
7433 var CompositeScopedContextProvider = ctx2.ScopedContextProvider;
7434 var CompositeItemContext = (0, import_react7.createContext)(
7435 void 0
7436 );
7437 var CompositeRowContext = (0, import_react7.createContext)(
7438 void 0
7439 );
7440
7441 // node_modules/@ariakit/react-core/esm/__chunks/5VQZOHHZ.js
7442 function findFirstEnabledItem(items, excludeId) {
7443 return items.find((item) => {
7444 if (excludeId) {
7445 return !item.disabled && item.id !== excludeId;
7446 }
7447 return !item.disabled;
7448 });
7449 }
7450 function getEnabledItem(store, id) {
7451 if (!id) return null;
7452 return store.item(id) || null;
7453 }
7454 function groupItemsByRows(items) {
7455 const rows = [];
7456 for (const item of items) {
7457 const row = rows.find((currentRow) => {
7458 var _a;
7459 return ((_a = currentRow[0]) == null ? void 0 : _a.rowId) === item.rowId;
7460 });
7461 if (row) {
7462 row.push(item);
7463 } else {
7464 rows.push([item]);
7465 }
7466 }
7467 return rows;
7468 }
7469 function selectTextField(element, collapseToEnd = false) {
7470 if (isTextField(element)) {
7471 element.setSelectionRange(
7472 collapseToEnd ? element.value.length : 0,
7473 element.value.length
7474 );
7475 } else if (element.isContentEditable) {
7476 const selection = getDocument(element).getSelection();
7477 selection == null ? void 0 : selection.selectAllChildren(element);
7478 if (collapseToEnd) {
7479 selection == null ? void 0 : selection.collapseToEnd();
7480 }
7481 }
7482 }
7483 var FOCUS_SILENTLY = /* @__PURE__ */ Symbol("FOCUS_SILENTLY");
7484 function focusSilently(element) {
7485 element[FOCUS_SILENTLY] = true;
7486 element.focus({ preventScroll: true });
7487 }
7488 function silentlyFocused(element) {
7489 const isSilentlyFocused = element[FOCUS_SILENTLY];
7490 delete element[FOCUS_SILENTLY];
7491 return isSilentlyFocused;
7492 }
7493 function isItem(store, element, exclude) {
7494 if (!element) return false;
7495 if (element === exclude) return false;
7496 const item = store.item(element.id);
7497 if (!item) return false;
7498 if (exclude && item.element === exclude) return false;
7499 return true;
7500 }
7501
7502 // node_modules/@ariakit/react-core/esm/__chunks/Z2O3VLAQ.js
7503 var import_react8 = __toESM(require_react(), 1);
7504 var TagName = "div";
7505 var useCollectionItem = createHook(
7506 function useCollectionItem2({
7507 store,
7508 shouldRegisterItem = true,
7509 getItem = identity,
7510 // @ts-expect-error This prop may come from a collection renderer.
7511 element,
7512 ...props
7513 }) {
7514 const context = useCollectionContext();
7515 store = store || context;
7516 const id = useId3(props.id);
7517 const ref = (0, import_react8.useRef)(element);
7518 (0, import_react8.useEffect)(() => {
7519 const element2 = ref.current;
7520 if (!id) return;
7521 if (!element2) return;
7522 if (!shouldRegisterItem) return;
7523 const item = getItem({ id, element: element2 });
7524 return store == null ? void 0 : store.renderItem(item);
7525 }, [id, shouldRegisterItem, getItem, store]);
7526 props = {
7527 ...props,
7528 ref: useMergeRefs(ref, props.ref)
7529 };
7530 return removeUndefinedValues(props);
7531 }
7532 );
7533 var CollectionItem = forwardRef22(function CollectionItem2(props) {
7534 const htmlProps = useCollectionItem(props);
7535 return createElement3(TagName, htmlProps);
7536 });
7537
7538 // node_modules/@ariakit/react-core/esm/__chunks/SWN3JYXT.js
7539 var import_react9 = __toESM(require_react(), 1);
7540 var FocusableContext = (0, import_react9.createContext)(true);
7541
7542 // node_modules/@ariakit/core/esm/utils/focus.js
7543 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'])";
7544 function isFocusable(element) {
7545 if (!element.matches(selector)) return false;
7546 if (!isVisible(element)) return false;
7547 if (element.closest("[inert]")) return false;
7548 return true;
7549 }
7550 function getClosestFocusable(element) {
7551 while (element && !isFocusable(element)) {
7552 element = element.closest(selector);
7553 }
7554 return element || null;
7555 }
7556 function hasFocus(element) {
7557 const activeElement = getActiveElement(element);
7558 if (!activeElement) return false;
7559 if (activeElement === element) return true;
7560 const activeDescendant = activeElement.getAttribute("aria-activedescendant");
7561 if (!activeDescendant) return false;
7562 return activeDescendant === element.id;
7563 }
7564 function hasFocusWithin(element) {
7565 const activeElement = getActiveElement(element);
7566 if (!activeElement) return false;
7567 if (contains(element, activeElement)) return true;
7568 const activeDescendant = activeElement.getAttribute("aria-activedescendant");
7569 if (!activeDescendant) return false;
7570 if (!("id" in element)) return false;
7571 if (activeDescendant === element.id) return true;
7572 return !!element.querySelector(`#${CSS.escape(activeDescendant)}`);
7573 }
7574 function focusIfNeeded(element) {
7575 if (!hasFocusWithin(element) && isFocusable(element)) {
7576 element.focus();
7577 }
7578 }
7579 function focusIntoView(element, options) {
7580 if (!("scrollIntoView" in element)) {
7581 element.focus();
7582 } else {
7583 element.focus({ preventScroll: true });
7584 element.scrollIntoView({ block: "nearest", inline: "nearest", ...options });
7585 }
7586 }
7587
7588 // node_modules/@ariakit/react-core/esm/__chunks/U6HHPQDW.js
7589 var import_react10 = __toESM(require_react(), 1);
7590 var TagName2 = "div";
7591 var isSafariBrowser = isSafari();
7592 var alwaysFocusVisibleInputTypes = [
7593 "text",
7594 "search",
7595 "url",
7596 "tel",
7597 "email",
7598 "password",
7599 "number",
7600 "date",
7601 "month",
7602 "week",
7603 "time",
7604 "datetime",
7605 "datetime-local"
7606 ];
7607 var safariFocusAncestorSymbol = /* @__PURE__ */ Symbol("safariFocusAncestor");
7608 function markSafariFocusAncestor(element, value) {
7609 if (!element) return;
7610 element[safariFocusAncestorSymbol] = value;
7611 }
7612 function isAlwaysFocusVisible(element) {
7613 const { tagName, readOnly, type } = element;
7614 if (tagName === "TEXTAREA" && !readOnly) return true;
7615 if (tagName === "SELECT" && !readOnly) return true;
7616 if (tagName === "INPUT" && !readOnly) {
7617 return alwaysFocusVisibleInputTypes.includes(type);
7618 }
7619 if (element.isContentEditable) return true;
7620 const role = element.getAttribute("role");
7621 if (role === "combobox" && element.dataset.name) {
7622 return true;
7623 }
7624 return false;
7625 }
7626 function getLabels(element) {
7627 if ("labels" in element) {
7628 return element.labels;
7629 }
7630 return null;
7631 }
7632 function isNativeCheckboxOrRadio(element) {
7633 const tagName = element.tagName.toLowerCase();
7634 if (tagName === "input" && element.type) {
7635 return element.type === "radio" || element.type === "checkbox";
7636 }
7637 return false;
7638 }
7639 function isNativeTabbable(tagName) {
7640 if (!tagName) return true;
7641 return tagName === "button" || tagName === "summary" || tagName === "input" || tagName === "select" || tagName === "textarea" || tagName === "a";
7642 }
7643 function supportsDisabledAttribute(tagName) {
7644 if (!tagName) return true;
7645 return tagName === "button" || tagName === "input" || tagName === "select" || tagName === "textarea";
7646 }
7647 function getTabIndex(focusable, trulyDisabled, nativeTabbable, supportsDisabled, tabIndexProp) {
7648 if (!focusable) {
7649 return tabIndexProp;
7650 }
7651 if (trulyDisabled) {
7652 if (nativeTabbable && !supportsDisabled) {
7653 return -1;
7654 }
7655 return;
7656 }
7657 if (nativeTabbable) {
7658 return tabIndexProp;
7659 }
7660 return tabIndexProp || 0;
7661 }
7662 function useDisableEvent(onEvent, disabled) {
7663 return useEvent((event) => {
7664 onEvent == null ? void 0 : onEvent(event);
7665 if (event.defaultPrevented) return;
7666 if (disabled) {
7667 event.stopPropagation();
7668 event.preventDefault();
7669 }
7670 });
7671 }
7672 var hasInstalledGlobalEventListeners2 = false;
7673 var isKeyboardModality = true;
7674 function onGlobalMouseDown(event) {
7675 const target = event.target;
7676 if (target && "hasAttribute" in target) {
7677 if (!target.hasAttribute("data-focus-visible")) {
7678 isKeyboardModality = false;
7679 }
7680 }
7681 }
7682 function onGlobalKeyDown(event) {
7683 if (event.metaKey) return;
7684 if (event.ctrlKey) return;
7685 if (event.altKey) return;
7686 isKeyboardModality = true;
7687 }
7688 var useFocusable = createHook(
7689 function useFocusable2({
7690 focusable = true,
7691 accessibleWhenDisabled,
7692 autoFocus,
7693 onFocusVisible,
7694 ...props
7695 }) {
7696 const ref = (0, import_react10.useRef)(null);
7697 (0, import_react10.useEffect)(() => {
7698 if (!focusable) return;
7699 if (hasInstalledGlobalEventListeners2) return;
7700 addGlobalEventListener("mousedown", onGlobalMouseDown, true);
7701 addGlobalEventListener("keydown", onGlobalKeyDown, true);
7702 hasInstalledGlobalEventListeners2 = true;
7703 }, [focusable]);
7704 if (isSafariBrowser) {
7705 (0, import_react10.useEffect)(() => {
7706 if (!focusable) return;
7707 const element = ref.current;
7708 if (!element) return;
7709 if (!isNativeCheckboxOrRadio(element)) return;
7710 const labels = getLabels(element);
7711 if (!labels) return;
7712 const onMouseUp = () => queueMicrotask(() => element.focus());
7713 for (const label of labels) {
7714 label.addEventListener("mouseup", onMouseUp);
7715 }
7716 return () => {
7717 for (const label of labels) {
7718 label.removeEventListener("mouseup", onMouseUp);
7719 }
7720 };
7721 }, [focusable]);
7722 }
7723 const disabled = focusable && disabledFromProps(props);
7724 const trulyDisabled = !!disabled && !accessibleWhenDisabled;
7725 const [focusVisible, setFocusVisible] = (0, import_react10.useState)(false);
7726 (0, import_react10.useEffect)(() => {
7727 if (!focusable) return;
7728 if (trulyDisabled && focusVisible) {
7729 setFocusVisible(false);
7730 }
7731 }, [focusable, trulyDisabled, focusVisible]);
7732 (0, import_react10.useEffect)(() => {
7733 if (!focusable) return;
7734 if (!focusVisible) return;
7735 const element = ref.current;
7736 if (!element) return;
7737 if (typeof IntersectionObserver === "undefined") return;
7738 const observer = new IntersectionObserver(() => {
7739 if (!isFocusable(element)) {
7740 setFocusVisible(false);
7741 }
7742 });
7743 observer.observe(element);
7744 return () => observer.disconnect();
7745 }, [focusable, focusVisible]);
7746 const onKeyPressCapture = useDisableEvent(
7747 props.onKeyPressCapture,
7748 disabled
7749 );
7750 const onMouseDownCapture = useDisableEvent(
7751 props.onMouseDownCapture,
7752 disabled
7753 );
7754 const onClickCapture = useDisableEvent(props.onClickCapture, disabled);
7755 const onMouseDownProp = props.onMouseDown;
7756 const onMouseDown = useEvent((event) => {
7757 onMouseDownProp == null ? void 0 : onMouseDownProp(event);
7758 if (event.defaultPrevented) return;
7759 if (!focusable) return;
7760 const element = event.currentTarget;
7761 if (!isSafariBrowser) return;
7762 if (isPortalEvent(event)) return;
7763 if (!isButton(element) && !isNativeCheckboxOrRadio(element)) return;
7764 let receivedFocus = false;
7765 const onFocus = () => {
7766 receivedFocus = true;
7767 };
7768 const options = { capture: true, once: true };
7769 element.addEventListener("focusin", onFocus, options);
7770 const focusableContainer = getClosestFocusable(element.parentElement);
7771 markSafariFocusAncestor(focusableContainer, true);
7772 queueBeforeEvent(element, "mouseup", () => {
7773 element.removeEventListener("focusin", onFocus, true);
7774 markSafariFocusAncestor(focusableContainer, false);
7775 if (receivedFocus) return;
7776 focusIfNeeded(element);
7777 });
7778 });
7779 const handleFocusVisible = (event, currentTarget) => {
7780 if (currentTarget) {
7781 event.currentTarget = currentTarget;
7782 }
7783 if (!focusable) return;
7784 const element = event.currentTarget;
7785 if (!element) return;
7786 if (!hasFocus(element)) return;
7787 onFocusVisible == null ? void 0 : onFocusVisible(event);
7788 if (event.defaultPrevented) return;
7789 element.dataset.focusVisible = "true";
7790 setFocusVisible(true);
7791 };
7792 const onKeyDownCaptureProp = props.onKeyDownCapture;
7793 const onKeyDownCapture = useEvent((event) => {
7794 onKeyDownCaptureProp == null ? void 0 : onKeyDownCaptureProp(event);
7795 if (event.defaultPrevented) return;
7796 if (!focusable) return;
7797 if (focusVisible) return;
7798 if (event.metaKey) return;
7799 if (event.altKey) return;
7800 if (event.ctrlKey) return;
7801 if (!isSelfTarget(event)) return;
7802 const element = event.currentTarget;
7803 const applyFocusVisible = () => handleFocusVisible(event, element);
7804 queueBeforeEvent(element, "focusout", applyFocusVisible);
7805 });
7806 const onFocusCaptureProp = props.onFocusCapture;
7807 const onFocusCapture = useEvent((event) => {
7808 onFocusCaptureProp == null ? void 0 : onFocusCaptureProp(event);
7809 if (event.defaultPrevented) return;
7810 if (!focusable) return;
7811 if (!isSelfTarget(event)) {
7812 setFocusVisible(false);
7813 return;
7814 }
7815 const element = event.currentTarget;
7816 const applyFocusVisible = () => handleFocusVisible(event, element);
7817 if (isKeyboardModality || isAlwaysFocusVisible(event.target)) {
7818 queueBeforeEvent(event.target, "focusout", applyFocusVisible);
7819 } else {
7820 setFocusVisible(false);
7821 }
7822 });
7823 const onBlurProp = props.onBlur;
7824 const onBlur = useEvent((event) => {
7825 onBlurProp == null ? void 0 : onBlurProp(event);
7826 if (!focusable) return;
7827 if (!isFocusEventOutside(event)) return;
7828 event.currentTarget.removeAttribute("data-focus-visible");
7829 setFocusVisible(false);
7830 });
7831 const autoFocusOnShow = (0, import_react10.useContext)(FocusableContext);
7832 const autoFocusRef = useEvent((element) => {
7833 if (!focusable) return;
7834 if (!autoFocus) return;
7835 if (!element) return;
7836 if (!autoFocusOnShow) return;
7837 queueMicrotask(() => {
7838 if (hasFocus(element)) return;
7839 if (!isFocusable(element)) return;
7840 element.focus();
7841 });
7842 });
7843 const tagName = useTagName(ref);
7844 const nativeTabbable = focusable && isNativeTabbable(tagName);
7845 const supportsDisabled = focusable && supportsDisabledAttribute(tagName);
7846 const styleProp = props.style;
7847 const style = (0, import_react10.useMemo)(() => {
7848 if (trulyDisabled) {
7849 return { pointerEvents: "none", ...styleProp };
7850 }
7851 return styleProp;
7852 }, [trulyDisabled, styleProp]);
7853 props = {
7854 "data-focus-visible": focusable && focusVisible || void 0,
7855 "data-autofocus": autoFocus || void 0,
7856 "aria-disabled": disabled || void 0,
7857 ...props,
7858 ref: useMergeRefs(ref, autoFocusRef, props.ref),
7859 style,
7860 tabIndex: getTabIndex(
7861 focusable,
7862 trulyDisabled,
7863 nativeTabbable,
7864 supportsDisabled,
7865 props.tabIndex
7866 ),
7867 disabled: supportsDisabled && trulyDisabled ? true : void 0,
7868 // TODO: Test Focusable contentEditable.
7869 contentEditable: disabled ? void 0 : props.contentEditable,
7870 onKeyPressCapture,
7871 onClickCapture,
7872 onMouseDownCapture,
7873 onMouseDown,
7874 onKeyDownCapture,
7875 onFocusCapture,
7876 onBlur
7877 };
7878 return removeUndefinedValues(props);
7879 }
7880 );
7881 var Focusable = forwardRef22(function Focusable2(props) {
7882 const htmlProps = useFocusable(props);
7883 return createElement3(TagName2, htmlProps);
7884 });
7885
7886 // node_modules/@ariakit/react-core/esm/__chunks/PZ3OL7I2.js
7887 var import_react11 = __toESM(require_react(), 1);
7888 var TagName3 = "button";
7889 function isNativeClick(event) {
7890 if (!event.isTrusted) return false;
7891 const element = event.currentTarget;
7892 if (event.key === "Enter") {
7893 return isButton(element) || element.tagName === "SUMMARY" || element.tagName === "A";
7894 }
7895 if (event.key === " ") {
7896 return isButton(element) || element.tagName === "SUMMARY" || element.tagName === "INPUT" || element.tagName === "SELECT";
7897 }
7898 return false;
7899 }
7900 var symbol = /* @__PURE__ */ Symbol("command");
7901 var useCommand = createHook(
7902 function useCommand2({ clickOnEnter = true, clickOnSpace = true, ...props }) {
7903 const ref = (0, import_react11.useRef)(null);
7904 const [isNativeButton, setIsNativeButton] = (0, import_react11.useState)(false);
7905 (0, import_react11.useEffect)(() => {
7906 if (!ref.current) return;
7907 setIsNativeButton(isButton(ref.current));
7908 }, []);
7909 const [active, setActive] = (0, import_react11.useState)(false);
7910 const activeRef = (0, import_react11.useRef)(false);
7911 const disabled = disabledFromProps(props);
7912 const [isDuplicate, metadataProps] = useMetadataProps(props, symbol, true);
7913 const onKeyDownProp = props.onKeyDown;
7914 const onKeyDown = useEvent((event) => {
7915 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
7916 const element = event.currentTarget;
7917 if (event.defaultPrevented) return;
7918 if (isDuplicate) return;
7919 if (disabled) return;
7920 if (!isSelfTarget(event)) return;
7921 if (isTextField(element)) return;
7922 if (element.isContentEditable) return;
7923 const isEnter = clickOnEnter && event.key === "Enter";
7924 const isSpace = clickOnSpace && event.key === " ";
7925 const shouldPreventEnter = event.key === "Enter" && !clickOnEnter;
7926 const shouldPreventSpace = event.key === " " && !clickOnSpace;
7927 if (shouldPreventEnter || shouldPreventSpace) {
7928 event.preventDefault();
7929 return;
7930 }
7931 if (isEnter || isSpace) {
7932 const nativeClick = isNativeClick(event);
7933 if (isEnter) {
7934 if (!nativeClick) {
7935 event.preventDefault();
7936 const { view, ...eventInit } = event;
7937 const click = () => fireClickEvent(element, eventInit);
7938 if (isFirefox()) {
7939 queueBeforeEvent(element, "keyup", click);
7940 } else {
7941 queueMicrotask(click);
7942 }
7943 }
7944 } else if (isSpace) {
7945 activeRef.current = true;
7946 if (!nativeClick) {
7947 event.preventDefault();
7948 setActive(true);
7949 }
7950 }
7951 }
7952 });
7953 const onKeyUpProp = props.onKeyUp;
7954 const onKeyUp = useEvent((event) => {
7955 onKeyUpProp == null ? void 0 : onKeyUpProp(event);
7956 if (event.defaultPrevented) return;
7957 if (isDuplicate) return;
7958 if (disabled) return;
7959 if (event.metaKey) return;
7960 const isSpace = clickOnSpace && event.key === " ";
7961 if (activeRef.current && isSpace) {
7962 activeRef.current = false;
7963 if (!isNativeClick(event)) {
7964 event.preventDefault();
7965 setActive(false);
7966 const element = event.currentTarget;
7967 const { view, ...eventInit } = event;
7968 queueMicrotask(() => fireClickEvent(element, eventInit));
7969 }
7970 }
7971 });
7972 props = {
7973 "data-active": active || void 0,
7974 type: isNativeButton ? "button" : void 0,
7975 ...metadataProps,
7976 ...props,
7977 ref: useMergeRefs(ref, props.ref),
7978 onKeyDown,
7979 onKeyUp
7980 };
7981 props = useFocusable(props);
7982 return props;
7983 }
7984 );
7985 var Command = forwardRef22(function Command2(props) {
7986 const htmlProps = useCommand(props);
7987 return createElement3(TagName3, htmlProps);
7988 });
7989
7990 // node_modules/@ariakit/core/esm/__chunks/SXKM4CGU.js
7991 function getInternal(store, key) {
7992 const internals = store.__unstableInternals;
7993 invariant(internals, "Invalid store");
7994 return internals[key];
7995 }
7996 function createStore(initialState, ...stores) {
7997 let state = initialState;
7998 let prevStateBatch = state;
7999 let lastUpdate = /* @__PURE__ */ Symbol();
8000 let destroy = noop2;
8001 const instances = /* @__PURE__ */ new Set();
8002 const updatedKeys = /* @__PURE__ */ new Set();
8003 const setups = /* @__PURE__ */ new Set();
8004 const listeners = /* @__PURE__ */ new Set();
8005 const batchListeners = /* @__PURE__ */ new Set();
8006 const disposables = /* @__PURE__ */ new WeakMap();
8007 const listenerKeys = /* @__PURE__ */ new WeakMap();
8008 const storeSetup = (callback) => {
8009 setups.add(callback);
8010 return () => setups.delete(callback);
8011 };
8012 const storeInit = () => {
8013 const initialized = instances.size;
8014 const instance = /* @__PURE__ */ Symbol();
8015 instances.add(instance);
8016 const maybeDestroy = () => {
8017 instances.delete(instance);
8018 if (instances.size) return;
8019 destroy();
8020 };
8021 if (initialized) return maybeDestroy;
8022 const desyncs = getKeys(state).map(
8023 (key) => chain(
8024 ...stores.map((store) => {
8025 var _a;
8026 const storeState = (_a = store == null ? void 0 : store.getState) == null ? void 0 : _a.call(store);
8027 if (!storeState) return;
8028 if (!hasOwnProperty(storeState, key)) return;
8029 return sync(store, [key], (state2) => {
8030 setState(
8031 key,
8032 state2[key],
8033 // @ts-expect-error - Not public API. This is just to prevent
8034 // infinite loops.
8035 true
8036 );
8037 });
8038 })
8039 )
8040 );
8041 const teardowns = [];
8042 for (const setup2 of setups) {
8043 teardowns.push(setup2());
8044 }
8045 const cleanups = stores.map(init);
8046 destroy = chain(...desyncs, ...teardowns, ...cleanups);
8047 return maybeDestroy;
8048 };
8049 const sub = (keys, listener, set2 = listeners) => {
8050 set2.add(listener);
8051 listenerKeys.set(listener, keys);
8052 return () => {
8053 var _a;
8054 (_a = disposables.get(listener)) == null ? void 0 : _a();
8055 disposables.delete(listener);
8056 listenerKeys.delete(listener);
8057 set2.delete(listener);
8058 };
8059 };
8060 const storeSubscribe = (keys, listener) => sub(keys, listener);
8061 const storeSync = (keys, listener) => {
8062 disposables.set(listener, listener(state, state));
8063 return sub(keys, listener);
8064 };
8065 const storeBatch = (keys, listener) => {
8066 disposables.set(listener, listener(state, prevStateBatch));
8067 return sub(keys, listener, batchListeners);
8068 };
8069 const storePick = (keys) => createStore(pick(state, keys), finalStore);
8070 const storeOmit = (keys) => createStore(omit(state, keys), finalStore);
8071 const getState = () => state;
8072 const setState = (key, value, fromStores = false) => {
8073 var _a;
8074 if (!hasOwnProperty(state, key)) return;
8075 const nextValue = applyState(value, state[key]);
8076 if (nextValue === state[key]) return;
8077 if (!fromStores) {
8078 for (const store of stores) {
8079 (_a = store == null ? void 0 : store.setState) == null ? void 0 : _a.call(store, key, nextValue);
8080 }
8081 }
8082 const prevState = state;
8083 state = { ...state, [key]: nextValue };
8084 const thisUpdate = /* @__PURE__ */ Symbol();
8085 lastUpdate = thisUpdate;
8086 updatedKeys.add(key);
8087 const run = (listener, prev, uKeys) => {
8088 var _a2;
8089 const keys = listenerKeys.get(listener);
8090 const updated = (k) => uKeys ? uKeys.has(k) : k === key;
8091 if (!keys || keys.some(updated)) {
8092 (_a2 = disposables.get(listener)) == null ? void 0 : _a2();
8093 disposables.set(listener, listener(state, prev));
8094 }
8095 };
8096 for (const listener of listeners) {
8097 run(listener, prevState);
8098 }
8099 queueMicrotask(() => {
8100 if (lastUpdate !== thisUpdate) return;
8101 const snapshot = state;
8102 for (const listener of batchListeners) {
8103 run(listener, prevStateBatch, updatedKeys);
8104 }
8105 prevStateBatch = snapshot;
8106 updatedKeys.clear();
8107 });
8108 };
8109 const finalStore = {
8110 getState,
8111 setState,
8112 __unstableInternals: {
8113 setup: storeSetup,
8114 init: storeInit,
8115 subscribe: storeSubscribe,
8116 sync: storeSync,
8117 batch: storeBatch,
8118 pick: storePick,
8119 omit: storeOmit
8120 }
8121 };
8122 return finalStore;
8123 }
8124 function setup(store, ...args) {
8125 if (!store) return;
8126 return getInternal(store, "setup")(...args);
8127 }
8128 function init(store, ...args) {
8129 if (!store) return;
8130 return getInternal(store, "init")(...args);
8131 }
8132 function subscribe(store, ...args) {
8133 if (!store) return;
8134 return getInternal(store, "subscribe")(...args);
8135 }
8136 function sync(store, ...args) {
8137 if (!store) return;
8138 return getInternal(store, "sync")(...args);
8139 }
8140 function batch(store, ...args) {
8141 if (!store) return;
8142 return getInternal(store, "batch")(...args);
8143 }
8144 function omit2(store, ...args) {
8145 if (!store) return;
8146 return getInternal(store, "omit")(...args);
8147 }
8148 function pick2(store, ...args) {
8149 if (!store) return;
8150 return getInternal(store, "pick")(...args);
8151 }
8152 function mergeStore(...stores) {
8153 var _a;
8154 const initialState = {};
8155 for (const store2 of stores) {
8156 const nextState = (_a = store2 == null ? void 0 : store2.getState) == null ? void 0 : _a.call(store2);
8157 if (nextState) {
8158 Object.assign(initialState, nextState);
8159 }
8160 }
8161 const store = createStore(initialState, ...stores);
8162 return Object.assign({}, ...stores, store);
8163 }
8164 function throwOnConflictingProps(props, store) {
8165 if (false) return;
8166 if (!store) return;
8167 const defaultKeys = Object.entries(props).filter(([key, value]) => key.startsWith("default") && value !== void 0).map(([key]) => {
8168 var _a;
8169 const stateKey = key.replace("default", "");
8170 return `${((_a = stateKey[0]) == null ? void 0 : _a.toLowerCase()) || ""}${stateKey.slice(1)}`;
8171 });
8172 if (!defaultKeys.length) return;
8173 const storeState = store.getState();
8174 const conflictingProps = defaultKeys.filter(
8175 (key) => hasOwnProperty(storeState, key)
8176 );
8177 if (!conflictingProps.length) return;
8178 throw new Error(
8179 `Passing a store prop in conjunction with a default state is not supported.
8180
8181 const store = useSelectStore();
8182 <SelectProvider store={store} defaultValue="Apple" />
8183 ^ ^
8184
8185 Instead, pass the default state to the topmost store:
8186
8187 const store = useSelectStore({ defaultValue: "Apple" });
8188 <SelectProvider store={store} />
8189
8190 See https://github.com/ariakit/ariakit/pull/2745 for more details.
8191
8192 If there's a particular need for this, please submit a feature request at https://github.com/ariakit/ariakit
8193 `
8194 );
8195 }
8196
8197 // node_modules/@ariakit/react-core/esm/__chunks/Q5W46E73.js
8198 var React7 = __toESM(require_react(), 1);
8199 var import_shim = __toESM(require_shim(), 1);
8200 var { useSyncExternalStore } = import_shim.default;
8201 var noopSubscribe = () => () => {
8202 };
8203 function useStoreState(store, keyOrSelector = identity) {
8204 const storeSubscribe = React7.useCallback(
8205 (callback) => {
8206 if (!store) return noopSubscribe();
8207 return subscribe(store, null, callback);
8208 },
8209 [store]
8210 );
8211 const getSnapshot = () => {
8212 const key = typeof keyOrSelector === "string" ? keyOrSelector : null;
8213 const selector2 = typeof keyOrSelector === "function" ? keyOrSelector : null;
8214 const state = store == null ? void 0 : store.getState();
8215 if (selector2) return selector2(state);
8216 if (!state) return;
8217 if (!key) return;
8218 if (!hasOwnProperty(state, key)) return;
8219 return state[key];
8220 };
8221 return useSyncExternalStore(storeSubscribe, getSnapshot, getSnapshot);
8222 }
8223 function useStoreStateObject(store, object) {
8224 const objRef = React7.useRef(
8225 {}
8226 );
8227 const storeSubscribe = React7.useCallback(
8228 (callback) => {
8229 if (!store) return noopSubscribe();
8230 return subscribe(store, null, callback);
8231 },
8232 [store]
8233 );
8234 const getSnapshot = () => {
8235 const state = store == null ? void 0 : store.getState();
8236 let updated = false;
8237 const obj = objRef.current;
8238 for (const prop in object) {
8239 const keyOrSelector = object[prop];
8240 if (typeof keyOrSelector === "function") {
8241 const value = keyOrSelector(state);
8242 if (value !== obj[prop]) {
8243 obj[prop] = value;
8244 updated = true;
8245 }
8246 }
8247 if (typeof keyOrSelector === "string") {
8248 if (!state) continue;
8249 if (!hasOwnProperty(state, keyOrSelector)) continue;
8250 const value = state[keyOrSelector];
8251 if (value !== obj[prop]) {
8252 obj[prop] = value;
8253 updated = true;
8254 }
8255 }
8256 }
8257 if (updated) {
8258 objRef.current = { ...obj };
8259 }
8260 return objRef.current;
8261 };
8262 return useSyncExternalStore(storeSubscribe, getSnapshot, getSnapshot);
8263 }
8264 function useStoreProps(store, props, key, setKey) {
8265 const value = hasOwnProperty(props, key) ? props[key] : void 0;
8266 const setValue = setKey ? props[setKey] : void 0;
8267 const propsRef = useLiveRef({ value, setValue });
8268 useSafeLayoutEffect(() => {
8269 return sync(store, [key], (state, prev) => {
8270 const { value: value2, setValue: setValue2 } = propsRef.current;
8271 if (!setValue2) return;
8272 if (state[key] === prev[key]) return;
8273 if (state[key] === value2) return;
8274 setValue2(state[key]);
8275 });
8276 }, [store, key]);
8277 useSafeLayoutEffect(() => {
8278 if (value === void 0) return;
8279 store.setState(key, value);
8280 return batch(store, [key], () => {
8281 if (value === void 0) return;
8282 store.setState(key, value);
8283 });
8284 });
8285 }
8286 function useStore(createStore2, props) {
8287 const [store, setStore] = React7.useState(() => createStore2(props));
8288 useSafeLayoutEffect(() => init(store), [store]);
8289 const useState210 = React7.useCallback(
8290 (keyOrSelector) => useStoreState(store, keyOrSelector),
8291 [store]
8292 );
8293 const memoizedStore = React7.useMemo(
8294 () => ({ ...store, useState: useState210 }),
8295 [store, useState210]
8296 );
8297 const updateStore = useEvent(() => {
8298 setStore((store2) => createStore2({ ...props, ...store2.getState() }));
8299 });
8300 return [memoizedStore, updateStore];
8301 }
8302
8303 // node_modules/@ariakit/react-core/esm/__chunks/WZWDIE3S.js
8304 var import_react12 = __toESM(require_react(), 1);
8305 var import_jsx_runtime55 = __toESM(require_jsx_runtime(), 1);
8306 var TagName4 = "button";
8307 function isEditableElement(element) {
8308 if (isTextbox(element)) return true;
8309 return element.tagName === "INPUT" && !isButton(element);
8310 }
8311 function getNextPageOffset(scrollingElement, pageUp = false) {
8312 const height = scrollingElement.clientHeight;
8313 const { top } = scrollingElement.getBoundingClientRect();
8314 const pageSize = Math.max(height * 0.875, height - 40) * 1.5;
8315 const pageOffset = pageUp ? height - pageSize + top : pageSize + top;
8316 if (scrollingElement.tagName === "HTML") {
8317 return pageOffset + scrollingElement.scrollTop;
8318 }
8319 return pageOffset;
8320 }
8321 function getItemOffset(itemElement, pageUp = false) {
8322 const { top } = itemElement.getBoundingClientRect();
8323 if (pageUp) {
8324 return top + itemElement.clientHeight;
8325 }
8326 return top;
8327 }
8328 function findNextPageItemId(element, store, next, pageUp = false) {
8329 var _a;
8330 if (!store) return;
8331 if (!next) return;
8332 const { renderedItems } = store.getState();
8333 const scrollingElement = getScrollingElement(element);
8334 if (!scrollingElement) return;
8335 const nextPageOffset = getNextPageOffset(scrollingElement, pageUp);
8336 let id;
8337 let prevDifference;
8338 for (let i2 = 0; i2 < renderedItems.length; i2 += 1) {
8339 const previousId = id;
8340 id = next(i2);
8341 if (!id) break;
8342 if (id === previousId) continue;
8343 const itemElement = (_a = getEnabledItem(store, id)) == null ? void 0 : _a.element;
8344 if (!itemElement) continue;
8345 const itemOffset = getItemOffset(itemElement, pageUp);
8346 const difference = itemOffset - nextPageOffset;
8347 const absDifference = Math.abs(difference);
8348 if (pageUp && difference <= 0 || !pageUp && difference >= 0) {
8349 if (prevDifference !== void 0 && prevDifference < absDifference) {
8350 id = previousId;
8351 }
8352 break;
8353 }
8354 prevDifference = absDifference;
8355 }
8356 return id;
8357 }
8358 function targetIsAnotherItem(event, store) {
8359 if (isSelfTarget(event)) return false;
8360 return isItem(store, event.target);
8361 }
8362 var useCompositeItem = createHook(
8363 function useCompositeItem2({
8364 store,
8365 rowId: rowIdProp,
8366 preventScrollOnKeyDown = false,
8367 moveOnKeyPress = true,
8368 tabbable = false,
8369 getItem: getItemProp,
8370 "aria-setsize": ariaSetSizeProp,
8371 "aria-posinset": ariaPosInSetProp,
8372 ...props
8373 }) {
8374 const context = useCompositeContext();
8375 store = store || context;
8376 const id = useId3(props.id);
8377 const ref = (0, import_react12.useRef)(null);
8378 const row = (0, import_react12.useContext)(CompositeRowContext);
8379 const disabled = disabledFromProps(props);
8380 const trulyDisabled = disabled && !props.accessibleWhenDisabled;
8381 const {
8382 rowId,
8383 baseElement,
8384 isActiveItem,
8385 ariaSetSize,
8386 ariaPosInSet,
8387 isTabbable
8388 } = useStoreStateObject(store, {
8389 rowId(state) {
8390 if (rowIdProp) return rowIdProp;
8391 if (!state) return;
8392 if (!(row == null ? void 0 : row.baseElement)) return;
8393 if (row.baseElement !== state.baseElement) return;
8394 return row.id;
8395 },
8396 baseElement(state) {
8397 return (state == null ? void 0 : state.baseElement) || void 0;
8398 },
8399 isActiveItem(state) {
8400 return !!state && state.activeId === id;
8401 },
8402 ariaSetSize(state) {
8403 if (ariaSetSizeProp != null) return ariaSetSizeProp;
8404 if (!state) return;
8405 if (!(row == null ? void 0 : row.ariaSetSize)) return;
8406 if (row.baseElement !== state.baseElement) return;
8407 return row.ariaSetSize;
8408 },
8409 ariaPosInSet(state) {
8410 if (ariaPosInSetProp != null) return ariaPosInSetProp;
8411 if (!state) return;
8412 if (!(row == null ? void 0 : row.ariaPosInSet)) return;
8413 if (row.baseElement !== state.baseElement) return;
8414 const itemsInRow = state.renderedItems.filter(
8415 (item) => item.rowId === rowId
8416 );
8417 return row.ariaPosInSet + itemsInRow.findIndex((item) => item.id === id);
8418 },
8419 isTabbable(state) {
8420 if (!(state == null ? void 0 : state.renderedItems.length)) return true;
8421 if (state.virtualFocus) return false;
8422 if (tabbable) return true;
8423 if (state.activeId === null) return false;
8424 const item = store == null ? void 0 : store.item(state.activeId);
8425 if (item == null ? void 0 : item.disabled) return true;
8426 if (!(item == null ? void 0 : item.element)) return true;
8427 return state.activeId === id;
8428 }
8429 });
8430 const getItem = (0, import_react12.useCallback)(
8431 (item) => {
8432 var _a;
8433 const nextItem = {
8434 ...item,
8435 id: id || item.id,
8436 rowId,
8437 disabled: !!trulyDisabled,
8438 children: (_a = item.element) == null ? void 0 : _a.textContent
8439 };
8440 if (getItemProp) {
8441 return getItemProp(nextItem);
8442 }
8443 return nextItem;
8444 },
8445 [id, rowId, trulyDisabled, getItemProp]
8446 );
8447 const onFocusProp = props.onFocus;
8448 const hasFocusedComposite = (0, import_react12.useRef)(false);
8449 const onFocus = useEvent((event) => {
8450 onFocusProp == null ? void 0 : onFocusProp(event);
8451 if (event.defaultPrevented) return;
8452 if (isPortalEvent(event)) return;
8453 if (!id) return;
8454 if (!store) return;
8455 if (targetIsAnotherItem(event, store)) return;
8456 const { virtualFocus, baseElement: baseElement2 } = store.getState();
8457 store.setActiveId(id);
8458 if (isTextbox(event.currentTarget)) {
8459 selectTextField(event.currentTarget);
8460 }
8461 if (!virtualFocus) return;
8462 if (!isSelfTarget(event)) return;
8463 if (isEditableElement(event.currentTarget)) return;
8464 if (!(baseElement2 == null ? void 0 : baseElement2.isConnected)) return;
8465 if (isSafari() && event.currentTarget.hasAttribute("data-autofocus")) {
8466 event.currentTarget.scrollIntoView({
8467 block: "nearest",
8468 inline: "nearest"
8469 });
8470 }
8471 hasFocusedComposite.current = true;
8472 const fromComposite = event.relatedTarget === baseElement2 || isItem(store, event.relatedTarget);
8473 if (fromComposite) {
8474 focusSilently(baseElement2);
8475 } else {
8476 baseElement2.focus();
8477 }
8478 });
8479 const onBlurCaptureProp = props.onBlurCapture;
8480 const onBlurCapture = useEvent((event) => {
8481 onBlurCaptureProp == null ? void 0 : onBlurCaptureProp(event);
8482 if (event.defaultPrevented) return;
8483 const state = store == null ? void 0 : store.getState();
8484 if ((state == null ? void 0 : state.virtualFocus) && hasFocusedComposite.current) {
8485 hasFocusedComposite.current = false;
8486 event.preventDefault();
8487 event.stopPropagation();
8488 }
8489 });
8490 const onKeyDownProp = props.onKeyDown;
8491 const preventScrollOnKeyDownProp = useBooleanEvent(preventScrollOnKeyDown);
8492 const moveOnKeyPressProp = useBooleanEvent(moveOnKeyPress);
8493 const onKeyDown = useEvent((event) => {
8494 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
8495 if (event.defaultPrevented) return;
8496 if (!isSelfTarget(event)) return;
8497 if (!store) return;
8498 const { currentTarget } = event;
8499 const state = store.getState();
8500 const item = store.item(id);
8501 const isGrid2 = !!(item == null ? void 0 : item.rowId);
8502 const isVertical = state.orientation !== "horizontal";
8503 const isHorizontal = state.orientation !== "vertical";
8504 const canHomeEnd = () => {
8505 if (isGrid2) return true;
8506 if (isHorizontal) return true;
8507 if (!state.baseElement) return true;
8508 if (!isTextField(state.baseElement)) return true;
8509 return false;
8510 };
8511 const keyMap = {
8512 ArrowUp: (isGrid2 || isVertical) && store.up,
8513 ArrowRight: (isGrid2 || isHorizontal) && store.next,
8514 ArrowDown: (isGrid2 || isVertical) && store.down,
8515 ArrowLeft: (isGrid2 || isHorizontal) && store.previous,
8516 Home: () => {
8517 if (!canHomeEnd()) return;
8518 if (!isGrid2 || event.ctrlKey) {
8519 return store == null ? void 0 : store.first();
8520 }
8521 return store == null ? void 0 : store.previous(-1);
8522 },
8523 End: () => {
8524 if (!canHomeEnd()) return;
8525 if (!isGrid2 || event.ctrlKey) {
8526 return store == null ? void 0 : store.last();
8527 }
8528 return store == null ? void 0 : store.next(-1);
8529 },
8530 PageUp: () => {
8531 return findNextPageItemId(currentTarget, store, store == null ? void 0 : store.up, true);
8532 },
8533 PageDown: () => {
8534 return findNextPageItemId(currentTarget, store, store == null ? void 0 : store.down);
8535 }
8536 };
8537 const action = keyMap[event.key];
8538 if (action) {
8539 if (isTextbox(currentTarget)) {
8540 const selection = getTextboxSelection(currentTarget);
8541 const isLeft = isHorizontal && event.key === "ArrowLeft";
8542 const isRight = isHorizontal && event.key === "ArrowRight";
8543 const isUp = isVertical && event.key === "ArrowUp";
8544 const isDown = isVertical && event.key === "ArrowDown";
8545 if (isRight || isDown) {
8546 const { length: valueLength } = getTextboxValue(currentTarget);
8547 if (selection.end !== valueLength) return;
8548 } else if ((isLeft || isUp) && selection.start !== 0) return;
8549 }
8550 const nextId = action();
8551 if (preventScrollOnKeyDownProp(event) || nextId !== void 0) {
8552 if (!moveOnKeyPressProp(event)) return;
8553 event.preventDefault();
8554 store.move(nextId);
8555 }
8556 }
8557 });
8558 const providerValue = (0, import_react12.useMemo)(
8559 () => ({ id, baseElement }),
8560 [id, baseElement]
8561 );
8562 props = useWrapElement(
8563 props,
8564 (element) => /* @__PURE__ */ (0, import_jsx_runtime55.jsx)(CompositeItemContext.Provider, { value: providerValue, children: element }),
8565 [providerValue]
8566 );
8567 props = {
8568 id,
8569 "data-active-item": isActiveItem || void 0,
8570 ...props,
8571 ref: useMergeRefs(ref, props.ref),
8572 tabIndex: isTabbable ? props.tabIndex : -1,
8573 onFocus,
8574 onBlurCapture,
8575 onKeyDown
8576 };
8577 props = useCommand(props);
8578 props = useCollectionItem({
8579 store,
8580 ...props,
8581 getItem,
8582 shouldRegisterItem: id ? props.shouldRegisterItem : false
8583 });
8584 return removeUndefinedValues({
8585 ...props,
8586 "aria-setsize": ariaSetSize,
8587 "aria-posinset": ariaPosInSet
8588 });
8589 }
8590 );
8591 var CompositeItem = memo22(
8592 forwardRef22(function CompositeItem2(props) {
8593 const htmlProps = useCompositeItem(props);
8594 return createElement3(TagName4, htmlProps);
8595 })
8596 );
8597
8598 // node_modules/@ariakit/core/esm/__chunks/7PRQYBBV.js
8599 function toArray(arg) {
8600 if (Array.isArray(arg)) {
8601 return arg;
8602 }
8603 return typeof arg !== "undefined" ? [arg] : [];
8604 }
8605 function flatten2DArray(array) {
8606 const flattened = [];
8607 for (const row of array) {
8608 flattened.push(...row);
8609 }
8610 return flattened;
8611 }
8612 function reverseArray(array) {
8613 return array.slice().reverse();
8614 }
8615
8616 // node_modules/@ariakit/react-core/esm/__chunks/ZMWF7ASR.js
8617 var import_react13 = __toESM(require_react(), 1);
8618 var import_jsx_runtime56 = __toESM(require_jsx_runtime(), 1);
8619 var TagName5 = "div";
8620 function isGrid(items) {
8621 return items.some((item) => !!item.rowId);
8622 }
8623 function isPrintableKey(event) {
8624 const target = event.target;
8625 if (target && !isTextField(target)) return false;
8626 return event.key.length === 1 && !event.ctrlKey && !event.metaKey;
8627 }
8628 function isModifierKey(event) {
8629 return event.key === "Shift" || event.key === "Control" || event.key === "Alt" || event.key === "Meta";
8630 }
8631 function useKeyboardEventProxy(store, onKeyboardEvent, previousElementRef) {
8632 return useEvent((event) => {
8633 var _a;
8634 onKeyboardEvent == null ? void 0 : onKeyboardEvent(event);
8635 if (event.defaultPrevented) return;
8636 if (event.isPropagationStopped()) return;
8637 if (!isSelfTarget(event)) return;
8638 if (isModifierKey(event)) return;
8639 if (isPrintableKey(event)) return;
8640 const state = store.getState();
8641 const activeElement = (_a = getEnabledItem(store, state.activeId)) == null ? void 0 : _a.element;
8642 if (!activeElement) return;
8643 const { view, ...eventInit } = event;
8644 const previousElement = previousElementRef == null ? void 0 : previousElementRef.current;
8645 if (activeElement !== previousElement) {
8646 activeElement.focus();
8647 }
8648 if (!fireKeyboardEvent(activeElement, event.type, eventInit)) {
8649 event.preventDefault();
8650 }
8651 if (event.currentTarget.contains(activeElement)) {
8652 event.stopPropagation();
8653 }
8654 });
8655 }
8656 function findFirstEnabledItemInTheLastRow(items) {
8657 return findFirstEnabledItem(
8658 flatten2DArray(reverseArray(groupItemsByRows(items)))
8659 );
8660 }
8661 function useScheduleFocus(store) {
8662 const [scheduled, setScheduled] = (0, import_react13.useState)(false);
8663 const schedule = (0, import_react13.useCallback)(() => setScheduled(true), []);
8664 const activeItem = store.useState(
8665 (state) => getEnabledItem(store, state.activeId)
8666 );
8667 (0, import_react13.useEffect)(() => {
8668 const activeElement = activeItem == null ? void 0 : activeItem.element;
8669 if (!scheduled) return;
8670 if (!activeElement) return;
8671 setScheduled(false);
8672 activeElement.focus({ preventScroll: true });
8673 }, [activeItem, scheduled]);
8674 return schedule;
8675 }
8676 var useComposite = createHook(
8677 function useComposite2({
8678 store,
8679 composite = true,
8680 focusOnMove = composite,
8681 moveOnKeyPress = true,
8682 ...props
8683 }) {
8684 const context = useCompositeProviderContext();
8685 store = store || context;
8686 invariant(
8687 store,
8688 "Composite must receive a `store` prop or be wrapped in a CompositeProvider component."
8689 );
8690 const ref = (0, import_react13.useRef)(null);
8691 const previousElementRef = (0, import_react13.useRef)(null);
8692 const scheduleFocus = useScheduleFocus(store);
8693 const moves = store.useState("moves");
8694 const [, setBaseElement] = useTransactionState(
8695 composite ? store.setBaseElement : null
8696 );
8697 (0, import_react13.useEffect)(() => {
8698 var _a;
8699 if (!store) return;
8700 if (!moves) return;
8701 if (!composite) return;
8702 if (!focusOnMove) return;
8703 const { activeId: activeId2 } = store.getState();
8704 const itemElement = (_a = getEnabledItem(store, activeId2)) == null ? void 0 : _a.element;
8705 if (!itemElement) return;
8706 focusIntoView(itemElement);
8707 }, [store, moves, composite, focusOnMove]);
8708 useSafeLayoutEffect(() => {
8709 if (!store) return;
8710 if (!moves) return;
8711 if (!composite) return;
8712 const { baseElement, activeId: activeId2 } = store.getState();
8713 const isSelfAcive = activeId2 === null;
8714 if (!isSelfAcive) return;
8715 if (!baseElement) return;
8716 const previousElement = previousElementRef.current;
8717 previousElementRef.current = null;
8718 if (previousElement) {
8719 fireBlurEvent(previousElement, { relatedTarget: baseElement });
8720 }
8721 if (!hasFocus(baseElement)) {
8722 baseElement.focus();
8723 }
8724 }, [store, moves, composite]);
8725 const activeId = store.useState("activeId");
8726 const virtualFocus = store.useState("virtualFocus");
8727 useSafeLayoutEffect(() => {
8728 var _a;
8729 if (!store) return;
8730 if (!composite) return;
8731 if (!virtualFocus) return;
8732 const previousElement = previousElementRef.current;
8733 previousElementRef.current = null;
8734 if (!previousElement) return;
8735 const activeElement = (_a = getEnabledItem(store, activeId)) == null ? void 0 : _a.element;
8736 const relatedTarget = activeElement || getActiveElement(previousElement);
8737 if (relatedTarget === previousElement) return;
8738 fireBlurEvent(previousElement, { relatedTarget });
8739 }, [store, activeId, virtualFocus, composite]);
8740 const onKeyDownCapture = useKeyboardEventProxy(
8741 store,
8742 props.onKeyDownCapture,
8743 previousElementRef
8744 );
8745 const onKeyUpCapture = useKeyboardEventProxy(
8746 store,
8747 props.onKeyUpCapture,
8748 previousElementRef
8749 );
8750 const onFocusCaptureProp = props.onFocusCapture;
8751 const onFocusCapture = useEvent((event) => {
8752 onFocusCaptureProp == null ? void 0 : onFocusCaptureProp(event);
8753 if (event.defaultPrevented) return;
8754 if (!store) return;
8755 const { virtualFocus: virtualFocus2 } = store.getState();
8756 if (!virtualFocus2) return;
8757 const previousActiveElement = event.relatedTarget;
8758 const isSilentlyFocused = silentlyFocused(event.currentTarget);
8759 if (isSelfTarget(event) && isSilentlyFocused) {
8760 event.stopPropagation();
8761 previousElementRef.current = previousActiveElement;
8762 }
8763 });
8764 const onFocusProp = props.onFocus;
8765 const onFocus = useEvent((event) => {
8766 onFocusProp == null ? void 0 : onFocusProp(event);
8767 if (event.defaultPrevented) return;
8768 if (!composite) return;
8769 if (!store) return;
8770 const { relatedTarget } = event;
8771 const { virtualFocus: virtualFocus2 } = store.getState();
8772 if (virtualFocus2) {
8773 if (isSelfTarget(event) && !isItem(store, relatedTarget)) {
8774 queueMicrotask(scheduleFocus);
8775 }
8776 } else if (isSelfTarget(event)) {
8777 store.setActiveId(null);
8778 }
8779 });
8780 const onBlurCaptureProp = props.onBlurCapture;
8781 const onBlurCapture = useEvent((event) => {
8782 var _a;
8783 onBlurCaptureProp == null ? void 0 : onBlurCaptureProp(event);
8784 if (event.defaultPrevented) return;
8785 if (!store) return;
8786 const { virtualFocus: virtualFocus2, activeId: activeId2 } = store.getState();
8787 if (!virtualFocus2) return;
8788 const activeElement = (_a = getEnabledItem(store, activeId2)) == null ? void 0 : _a.element;
8789 const nextActiveElement = event.relatedTarget;
8790 const nextActiveElementIsItem = isItem(store, nextActiveElement);
8791 const previousElement = previousElementRef.current;
8792 previousElementRef.current = null;
8793 if (isSelfTarget(event) && nextActiveElementIsItem) {
8794 if (nextActiveElement === activeElement) {
8795 if (previousElement && previousElement !== nextActiveElement) {
8796 fireBlurEvent(previousElement, event);
8797 }
8798 } else if (activeElement) {
8799 fireBlurEvent(activeElement, event);
8800 } else if (previousElement) {
8801 fireBlurEvent(previousElement, event);
8802 }
8803 event.stopPropagation();
8804 } else {
8805 const targetIsItem = isItem(store, event.target);
8806 if (!targetIsItem && activeElement) {
8807 fireBlurEvent(activeElement, event);
8808 }
8809 }
8810 });
8811 const onKeyDownProp = props.onKeyDown;
8812 const moveOnKeyPressProp = useBooleanEvent(moveOnKeyPress);
8813 const onKeyDown = useEvent((event) => {
8814 var _a;
8815 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
8816 if (event.nativeEvent.isComposing) return;
8817 if (event.defaultPrevented) return;
8818 if (!store) return;
8819 if (!isSelfTarget(event)) return;
8820 const { orientation, renderedItems, activeId: activeId2 } = store.getState();
8821 const activeItem = getEnabledItem(store, activeId2);
8822 if ((_a = activeItem == null ? void 0 : activeItem.element) == null ? void 0 : _a.isConnected) return;
8823 const isVertical = orientation !== "horizontal";
8824 const isHorizontal = orientation !== "vertical";
8825 const grid = isGrid(renderedItems);
8826 const isHorizontalKey = event.key === "ArrowLeft" || event.key === "ArrowRight" || event.key === "Home" || event.key === "End";
8827 if (isHorizontalKey && isTextField(event.currentTarget)) return;
8828 const up = () => {
8829 if (grid) {
8830 const item = findFirstEnabledItemInTheLastRow(renderedItems);
8831 return item == null ? void 0 : item.id;
8832 }
8833 return store == null ? void 0 : store.last();
8834 };
8835 const keyMap = {
8836 ArrowUp: (grid || isVertical) && up,
8837 ArrowRight: (grid || isHorizontal) && store.first,
8838 ArrowDown: (grid || isVertical) && store.first,
8839 ArrowLeft: (grid || isHorizontal) && store.last,
8840 Home: store.first,
8841 End: store.last,
8842 PageUp: store.first,
8843 PageDown: store.last
8844 };
8845 const action = keyMap[event.key];
8846 if (action) {
8847 const id = action();
8848 if (id !== void 0) {
8849 if (!moveOnKeyPressProp(event)) return;
8850 event.preventDefault();
8851 store.move(id);
8852 }
8853 }
8854 });
8855 props = useWrapElement(
8856 props,
8857 (element) => /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(CompositeContextProvider, { value: store, children: element }),
8858 [store]
8859 );
8860 const activeDescendant = store.useState((state) => {
8861 var _a;
8862 if (!store) return;
8863 if (!composite) return;
8864 if (!state.virtualFocus) return;
8865 return (_a = getEnabledItem(store, state.activeId)) == null ? void 0 : _a.id;
8866 });
8867 props = {
8868 "aria-activedescendant": activeDescendant,
8869 ...props,
8870 ref: useMergeRefs(ref, setBaseElement, props.ref),
8871 onKeyDownCapture,
8872 onKeyUpCapture,
8873 onFocusCapture,
8874 onFocus,
8875 onBlurCapture,
8876 onKeyDown
8877 };
8878 const focusable = store.useState(
8879 (state) => composite && (state.virtualFocus || state.activeId === null)
8880 );
8881 props = useFocusable({ focusable, ...props });
8882 return props;
8883 }
8884 );
8885 var Composite5 = forwardRef22(function Composite22(props) {
8886 const htmlProps = useComposite(props);
8887 return createElement3(TagName5, htmlProps);
8888 });
8889
8890 // node_modules/@ariakit/react-core/esm/__chunks/LVDQFHCH.js
8891 var ctx3 = createStoreContext();
8892 var useDisclosureContext = ctx3.useContext;
8893 var useDisclosureScopedContext = ctx3.useScopedContext;
8894 var useDisclosureProviderContext = ctx3.useProviderContext;
8895 var DisclosureContextProvider = ctx3.ContextProvider;
8896 var DisclosureScopedContextProvider = ctx3.ScopedContextProvider;
8897
8898 // node_modules/@ariakit/react-core/esm/__chunks/A62MDFCW.js
8899 var import_react14 = __toESM(require_react(), 1);
8900 var ctx4 = createStoreContext(
8901 [DisclosureContextProvider],
8902 [DisclosureScopedContextProvider]
8903 );
8904 var useDialogContext = ctx4.useContext;
8905 var useDialogScopedContext = ctx4.useScopedContext;
8906 var useDialogProviderContext = ctx4.useProviderContext;
8907 var DialogContextProvider = ctx4.ContextProvider;
8908 var DialogScopedContextProvider = ctx4.ScopedContextProvider;
8909 var DialogHeadingContext = (0, import_react14.createContext)(void 0);
8910 var DialogDescriptionContext = (0, import_react14.createContext)(void 0);
8911
8912 // node_modules/@ariakit/react-core/esm/__chunks/6B3RXHKP.js
8913 var import_react15 = __toESM(require_react(), 1);
8914 var import_react_dom = __toESM(require_react_dom(), 1);
8915 var import_jsx_runtime57 = __toESM(require_jsx_runtime(), 1);
8916 var TagName6 = "div";
8917 function afterTimeout(timeoutMs, cb) {
8918 const timeoutId = setTimeout(cb, timeoutMs);
8919 return () => clearTimeout(timeoutId);
8920 }
8921 function afterPaint2(cb) {
8922 let raf = requestAnimationFrame(() => {
8923 raf = requestAnimationFrame(cb);
8924 });
8925 return () => cancelAnimationFrame(raf);
8926 }
8927 function parseCSSTime(...times) {
8928 return times.join(", ").split(", ").reduce((longestTime, currentTimeString) => {
8929 const multiplier = currentTimeString.endsWith("ms") ? 1 : 1e3;
8930 const currentTime = Number.parseFloat(currentTimeString || "0s") * multiplier;
8931 if (currentTime > longestTime) return currentTime;
8932 return longestTime;
8933 }, 0);
8934 }
8935 function isHidden(mounted, hidden, alwaysVisible) {
8936 return !alwaysVisible && hidden !== false && (!mounted || !!hidden);
8937 }
8938 var useDisclosureContent = createHook(function useDisclosureContent2({ store, alwaysVisible, ...props }) {
8939 const context = useDisclosureProviderContext();
8940 store = store || context;
8941 invariant(
8942 store,
8943 "DisclosureContent must receive a `store` prop or be wrapped in a DisclosureProvider component."
8944 );
8945 const ref = (0, import_react15.useRef)(null);
8946 const id = useId3(props.id);
8947 const [transition, setTransition] = (0, import_react15.useState)(null);
8948 const open = store.useState("open");
8949 const mounted = store.useState("mounted");
8950 const animated = store.useState("animated");
8951 const contentElement = store.useState("contentElement");
8952 const otherElement = useStoreState(store.disclosure, "contentElement");
8953 useSafeLayoutEffect(() => {
8954 if (!ref.current) return;
8955 store == null ? void 0 : store.setContentElement(ref.current);
8956 }, [store]);
8957 useSafeLayoutEffect(() => {
8958 let previousAnimated;
8959 store == null ? void 0 : store.setState("animated", (animated2) => {
8960 previousAnimated = animated2;
8961 return true;
8962 });
8963 return () => {
8964 if (previousAnimated === void 0) return;
8965 store == null ? void 0 : store.setState("animated", previousAnimated);
8966 };
8967 }, [store]);
8968 useSafeLayoutEffect(() => {
8969 if (!animated) return;
8970 if (!(contentElement == null ? void 0 : contentElement.isConnected)) {
8971 setTransition(null);
8972 return;
8973 }
8974 return afterPaint2(() => {
8975 setTransition(open ? "enter" : mounted ? "leave" : null);
8976 });
8977 }, [animated, contentElement, open, mounted]);
8978 useSafeLayoutEffect(() => {
8979 if (!store) return;
8980 if (!animated) return;
8981 if (!transition) return;
8982 if (!contentElement) return;
8983 const stopAnimation = () => store == null ? void 0 : store.setState("animating", false);
8984 const stopAnimationSync = () => (0, import_react_dom.flushSync)(stopAnimation);
8985 if (transition === "leave" && open) return;
8986 if (transition === "enter" && !open) return;
8987 if (typeof animated === "number") {
8988 const timeout2 = animated;
8989 return afterTimeout(timeout2, stopAnimationSync);
8990 }
8991 const {
8992 transitionDuration,
8993 animationDuration,
8994 transitionDelay,
8995 animationDelay
8996 } = getComputedStyle(contentElement);
8997 const {
8998 transitionDuration: transitionDuration2 = "0",
8999 animationDuration: animationDuration2 = "0",
9000 transitionDelay: transitionDelay2 = "0",
9001 animationDelay: animationDelay2 = "0"
9002 } = otherElement ? getComputedStyle(otherElement) : {};
9003 const delay = parseCSSTime(
9004 transitionDelay,
9005 animationDelay,
9006 transitionDelay2,
9007 animationDelay2
9008 );
9009 const duration = parseCSSTime(
9010 transitionDuration,
9011 animationDuration,
9012 transitionDuration2,
9013 animationDuration2
9014 );
9015 const timeout = delay + duration;
9016 if (!timeout) {
9017 if (transition === "enter") {
9018 store.setState("animated", false);
9019 }
9020 stopAnimation();
9021 return;
9022 }
9023 const frameRate = 1e3 / 60;
9024 const maxTimeout = Math.max(timeout - frameRate, 0);
9025 return afterTimeout(maxTimeout, stopAnimationSync);
9026 }, [store, animated, contentElement, otherElement, open, transition]);
9027 props = useWrapElement(
9028 props,
9029 (element) => /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(DialogScopedContextProvider, { value: store, children: element }),
9030 [store]
9031 );
9032 const hidden = isHidden(mounted, props.hidden, alwaysVisible);
9033 const styleProp = props.style;
9034 const style = (0, import_react15.useMemo)(() => {
9035 if (hidden) {
9036 return { ...styleProp, display: "none" };
9037 }
9038 return styleProp;
9039 }, [hidden, styleProp]);
9040 props = {
9041 id,
9042 "data-open": open || void 0,
9043 "data-enter": transition === "enter" || void 0,
9044 "data-leave": transition === "leave" || void 0,
9045 hidden,
9046 ...props,
9047 ref: useMergeRefs(id ? store.setContentElement : null, ref, props.ref),
9048 style
9049 };
9050 return removeUndefinedValues(props);
9051 });
9052 var DisclosureContentImpl = forwardRef22(function DisclosureContentImpl2(props) {
9053 const htmlProps = useDisclosureContent(props);
9054 return createElement3(TagName6, htmlProps);
9055 });
9056 var DisclosureContent = forwardRef22(function DisclosureContent2({
9057 unmountOnHide,
9058 ...props
9059 }) {
9060 const context = useDisclosureProviderContext();
9061 const store = props.store || context;
9062 const mounted = useStoreState(
9063 store,
9064 (state) => !unmountOnHide || (state == null ? void 0 : state.mounted)
9065 );
9066 if (mounted === false) return null;
9067 return /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(DisclosureContentImpl, { ...props });
9068 });
9069
9070 // node_modules/@ariakit/core/esm/__chunks/75BJEVSH.js
9071 function createDisclosureStore(props = {}) {
9072 const store = mergeStore(
9073 props.store,
9074 omit2(props.disclosure, ["contentElement", "disclosureElement"])
9075 );
9076 throwOnConflictingProps(props, store);
9077 const syncState = store == null ? void 0 : store.getState();
9078 const open = defaultValue(
9079 props.open,
9080 syncState == null ? void 0 : syncState.open,
9081 props.defaultOpen,
9082 false
9083 );
9084 const animated = defaultValue(props.animated, syncState == null ? void 0 : syncState.animated, false);
9085 const initialState = {
9086 open,
9087 animated,
9088 animating: !!animated && open,
9089 mounted: open,
9090 contentElement: defaultValue(syncState == null ? void 0 : syncState.contentElement, null),
9091 disclosureElement: defaultValue(syncState == null ? void 0 : syncState.disclosureElement, null)
9092 };
9093 const disclosure = createStore(initialState, store);
9094 setup(
9095 disclosure,
9096 () => sync(disclosure, ["animated", "animating"], (state) => {
9097 if (state.animated) return;
9098 disclosure.setState("animating", false);
9099 })
9100 );
9101 setup(
9102 disclosure,
9103 () => subscribe(disclosure, ["open"], () => {
9104 if (!disclosure.getState().animated) return;
9105 disclosure.setState("animating", true);
9106 })
9107 );
9108 setup(
9109 disclosure,
9110 () => sync(disclosure, ["open", "animating"], (state) => {
9111 disclosure.setState("mounted", state.open || state.animating);
9112 })
9113 );
9114 return {
9115 ...disclosure,
9116 disclosure: props.disclosure,
9117 setOpen: (value) => disclosure.setState("open", value),
9118 show: () => disclosure.setState("open", true),
9119 hide: () => disclosure.setState("open", false),
9120 toggle: () => disclosure.setState("open", (open2) => !open2),
9121 stopAnimation: () => disclosure.setState("animating", false),
9122 setContentElement: (value) => disclosure.setState("contentElement", value),
9123 setDisclosureElement: (value) => disclosure.setState("disclosureElement", value)
9124 };
9125 }
9126
9127 // node_modules/@ariakit/react-core/esm/__chunks/WLZ6H5FH.js
9128 function useDisclosureStoreProps(store, update2, props) {
9129 useUpdateEffect(update2, [props.store, props.disclosure]);
9130 useStoreProps(store, props, "open", "setOpen");
9131 useStoreProps(store, props, "mounted", "setMounted");
9132 useStoreProps(store, props, "animated");
9133 return Object.assign(store, { disclosure: props.disclosure });
9134 }
9135
9136 // node_modules/@ariakit/react-core/esm/__chunks/JMU4N4M5.js
9137 var ctx5 = createStoreContext(
9138 [DialogContextProvider],
9139 [DialogScopedContextProvider]
9140 );
9141 var usePopoverContext = ctx5.useContext;
9142 var usePopoverScopedContext = ctx5.useScopedContext;
9143 var usePopoverProviderContext = ctx5.useProviderContext;
9144 var PopoverContextProvider = ctx5.ContextProvider;
9145 var PopoverScopedContextProvider = ctx5.ScopedContextProvider;
9146
9147 // node_modules/@ariakit/core/esm/__chunks/N5XGANPW.js
9148 function getCommonParent(items) {
9149 var _a;
9150 const firstItem = items.find((item) => !!item.element);
9151 const lastItem = [...items].reverse().find((item) => !!item.element);
9152 let parentElement = (_a = firstItem == null ? void 0 : firstItem.element) == null ? void 0 : _a.parentElement;
9153 while (parentElement && (lastItem == null ? void 0 : lastItem.element)) {
9154 const parent = parentElement;
9155 if (lastItem && parent.contains(lastItem.element)) {
9156 return parentElement;
9157 }
9158 parentElement = parentElement.parentElement;
9159 }
9160 return getDocument(parentElement).body;
9161 }
9162 function getPrivateStore(store) {
9163 return store == null ? void 0 : store.__unstablePrivateStore;
9164 }
9165 function createCollectionStore(props = {}) {
9166 var _a;
9167 throwOnConflictingProps(props, props.store);
9168 const syncState = (_a = props.store) == null ? void 0 : _a.getState();
9169 const items = defaultValue(
9170 props.items,
9171 syncState == null ? void 0 : syncState.items,
9172 props.defaultItems,
9173 []
9174 );
9175 const itemsMap = new Map(items.map((item) => [item.id, item]));
9176 const initialState = {
9177 items,
9178 renderedItems: defaultValue(syncState == null ? void 0 : syncState.renderedItems, [])
9179 };
9180 const syncPrivateStore = getPrivateStore(props.store);
9181 const privateStore = createStore(
9182 { items, renderedItems: initialState.renderedItems },
9183 syncPrivateStore
9184 );
9185 const collection = createStore(initialState, props.store);
9186 const sortItems = (renderedItems) => {
9187 const sortedItems = sortBasedOnDOMPosition(renderedItems, (i2) => i2.element);
9188 privateStore.setState("renderedItems", sortedItems);
9189 collection.setState("renderedItems", sortedItems);
9190 };
9191 setup(collection, () => init(privateStore));
9192 setup(privateStore, () => {
9193 return batch(privateStore, ["items"], (state) => {
9194 collection.setState("items", state.items);
9195 });
9196 });
9197 setup(privateStore, () => {
9198 return batch(privateStore, ["renderedItems"], (state) => {
9199 let firstRun = true;
9200 let raf = requestAnimationFrame(() => {
9201 const { renderedItems } = collection.getState();
9202 if (state.renderedItems === renderedItems) return;
9203 sortItems(state.renderedItems);
9204 });
9205 if (typeof IntersectionObserver !== "function") {
9206 return () => cancelAnimationFrame(raf);
9207 }
9208 const ioCallback = () => {
9209 if (firstRun) {
9210 firstRun = false;
9211 return;
9212 }
9213 cancelAnimationFrame(raf);
9214 raf = requestAnimationFrame(() => sortItems(state.renderedItems));
9215 };
9216 const root = getCommonParent(state.renderedItems);
9217 const observer = new IntersectionObserver(ioCallback, { root });
9218 for (const item of state.renderedItems) {
9219 if (!item.element) continue;
9220 observer.observe(item.element);
9221 }
9222 return () => {
9223 cancelAnimationFrame(raf);
9224 observer.disconnect();
9225 };
9226 });
9227 });
9228 const mergeItem = (item, setItems, canDeleteFromMap = false) => {
9229 let prevItem;
9230 setItems((items2) => {
9231 const index = items2.findIndex(({ id }) => id === item.id);
9232 const nextItems = items2.slice();
9233 if (index !== -1) {
9234 prevItem = items2[index];
9235 const nextItem = { ...prevItem, ...item };
9236 nextItems[index] = nextItem;
9237 itemsMap.set(item.id, nextItem);
9238 } else {
9239 nextItems.push(item);
9240 itemsMap.set(item.id, item);
9241 }
9242 return nextItems;
9243 });
9244 const unmergeItem = () => {
9245 setItems((items2) => {
9246 if (!prevItem) {
9247 if (canDeleteFromMap) {
9248 itemsMap.delete(item.id);
9249 }
9250 return items2.filter(({ id }) => id !== item.id);
9251 }
9252 const index = items2.findIndex(({ id }) => id === item.id);
9253 if (index === -1) return items2;
9254 const nextItems = items2.slice();
9255 nextItems[index] = prevItem;
9256 itemsMap.set(item.id, prevItem);
9257 return nextItems;
9258 });
9259 };
9260 return unmergeItem;
9261 };
9262 const registerItem = (item) => mergeItem(
9263 item,
9264 (getItems) => privateStore.setState("items", getItems),
9265 true
9266 );
9267 return {
9268 ...collection,
9269 registerItem,
9270 renderItem: (item) => chain(
9271 registerItem(item),
9272 mergeItem(
9273 item,
9274 (getItems) => privateStore.setState("renderedItems", getItems)
9275 )
9276 ),
9277 item: (id) => {
9278 if (!id) return null;
9279 let item = itemsMap.get(id);
9280 if (!item) {
9281 const { items: items2 } = privateStore.getState();
9282 item = items2.find((item2) => item2.id === id);
9283 if (item) {
9284 itemsMap.set(id, item);
9285 }
9286 }
9287 return item || null;
9288 },
9289 // @ts-expect-error Internal
9290 __unstablePrivateStore: privateStore
9291 };
9292 }
9293
9294 // node_modules/@ariakit/react-core/esm/__chunks/GVAFFF2B.js
9295 function useCollectionStoreProps(store, update2, props) {
9296 useUpdateEffect(update2, [props.store]);
9297 useStoreProps(store, props, "items", "setItems");
9298 return store;
9299 }
9300
9301 // node_modules/@ariakit/core/esm/__chunks/RVTIKFRL.js
9302 var NULL_ITEM = { id: null };
9303 function findFirstEnabledItem2(items, excludeId) {
9304 return items.find((item) => {
9305 if (excludeId) {
9306 return !item.disabled && item.id !== excludeId;
9307 }
9308 return !item.disabled;
9309 });
9310 }
9311 function getEnabledItems(items, excludeId) {
9312 return items.filter((item) => {
9313 if (excludeId) {
9314 return !item.disabled && item.id !== excludeId;
9315 }
9316 return !item.disabled;
9317 });
9318 }
9319 function getItemsInRow(items, rowId) {
9320 return items.filter((item) => item.rowId === rowId);
9321 }
9322 function flipItems(items, activeId, shouldInsertNullItem = false) {
9323 const index = items.findIndex((item) => item.id === activeId);
9324 return [
9325 ...items.slice(index + 1),
9326 ...shouldInsertNullItem ? [NULL_ITEM] : [],
9327 ...items.slice(0, index)
9328 ];
9329 }
9330 function groupItemsByRows2(items) {
9331 const rows = [];
9332 for (const item of items) {
9333 const row = rows.find((currentRow) => {
9334 var _a;
9335 return ((_a = currentRow[0]) == null ? void 0 : _a.rowId) === item.rowId;
9336 });
9337 if (row) {
9338 row.push(item);
9339 } else {
9340 rows.push([item]);
9341 }
9342 }
9343 return rows;
9344 }
9345 function getMaxRowLength(array) {
9346 let maxLength = 0;
9347 for (const { length } of array) {
9348 if (length > maxLength) {
9349 maxLength = length;
9350 }
9351 }
9352 return maxLength;
9353 }
9354 function createEmptyItem(rowId) {
9355 return {
9356 id: "__EMPTY_ITEM__",
9357 disabled: true,
9358 rowId
9359 };
9360 }
9361 function normalizeRows(rows, activeId, focusShift) {
9362 const maxLength = getMaxRowLength(rows);
9363 for (const row of rows) {
9364 for (let i2 = 0; i2 < maxLength; i2 += 1) {
9365 const item = row[i2];
9366 if (!item || focusShift && item.disabled) {
9367 const isFirst = i2 === 0;
9368 const previousItem = isFirst && focusShift ? findFirstEnabledItem2(row) : row[i2 - 1];
9369 row[i2] = previousItem && activeId !== previousItem.id && focusShift ? previousItem : createEmptyItem(previousItem == null ? void 0 : previousItem.rowId);
9370 }
9371 }
9372 }
9373 return rows;
9374 }
9375 function verticalizeItems(items) {
9376 const rows = groupItemsByRows2(items);
9377 const maxLength = getMaxRowLength(rows);
9378 const verticalized = [];
9379 for (let i2 = 0; i2 < maxLength; i2 += 1) {
9380 for (const row of rows) {
9381 const item = row[i2];
9382 if (item) {
9383 verticalized.push({
9384 ...item,
9385 // If there's no rowId, it means that it's not a grid composite, but
9386 // a single row instead. So, instead of verticalizing it, that is,
9387 // assigning a different rowId based on the column index, we keep it
9388 // undefined so they will be part of the same row. This is useful
9389 // when using up/down on one-dimensional composites.
9390 rowId: item.rowId ? `${i2}` : void 0
9391 });
9392 }
9393 }
9394 }
9395 return verticalized;
9396 }
9397 function createCompositeStore(props = {}) {
9398 var _a;
9399 const syncState = (_a = props.store) == null ? void 0 : _a.getState();
9400 const collection = createCollectionStore(props);
9401 const activeId = defaultValue(
9402 props.activeId,
9403 syncState == null ? void 0 : syncState.activeId,
9404 props.defaultActiveId
9405 );
9406 const initialState = {
9407 ...collection.getState(),
9408 id: defaultValue(
9409 props.id,
9410 syncState == null ? void 0 : syncState.id,
9411 `id-${Math.random().toString(36).slice(2, 8)}`
9412 ),
9413 activeId,
9414 baseElement: defaultValue(syncState == null ? void 0 : syncState.baseElement, null),
9415 includesBaseElement: defaultValue(
9416 props.includesBaseElement,
9417 syncState == null ? void 0 : syncState.includesBaseElement,
9418 activeId === null
9419 ),
9420 moves: defaultValue(syncState == null ? void 0 : syncState.moves, 0),
9421 orientation: defaultValue(
9422 props.orientation,
9423 syncState == null ? void 0 : syncState.orientation,
9424 "both"
9425 ),
9426 rtl: defaultValue(props.rtl, syncState == null ? void 0 : syncState.rtl, false),
9427 virtualFocus: defaultValue(
9428 props.virtualFocus,
9429 syncState == null ? void 0 : syncState.virtualFocus,
9430 false
9431 ),
9432 focusLoop: defaultValue(props.focusLoop, syncState == null ? void 0 : syncState.focusLoop, false),
9433 focusWrap: defaultValue(props.focusWrap, syncState == null ? void 0 : syncState.focusWrap, false),
9434 focusShift: defaultValue(props.focusShift, syncState == null ? void 0 : syncState.focusShift, false)
9435 };
9436 const composite = createStore(initialState, collection, props.store);
9437 setup(
9438 composite,
9439 () => sync(composite, ["renderedItems", "activeId"], (state) => {
9440 composite.setState("activeId", (activeId2) => {
9441 var _a2;
9442 if (activeId2 !== void 0) return activeId2;
9443 return (_a2 = findFirstEnabledItem2(state.renderedItems)) == null ? void 0 : _a2.id;
9444 });
9445 })
9446 );
9447 const getNextId = (direction = "next", options = {}) => {
9448 var _a2, _b;
9449 const defaultState = composite.getState();
9450 const {
9451 skip = 0,
9452 activeId: activeId2 = defaultState.activeId,
9453 focusShift = defaultState.focusShift,
9454 focusLoop = defaultState.focusLoop,
9455 focusWrap = defaultState.focusWrap,
9456 includesBaseElement = defaultState.includesBaseElement,
9457 renderedItems = defaultState.renderedItems,
9458 rtl = defaultState.rtl
9459 } = options;
9460 const isVerticalDirection = direction === "up" || direction === "down";
9461 const isNextDirection = direction === "next" || direction === "down";
9462 const canReverse = isNextDirection ? rtl && !isVerticalDirection : !rtl || isVerticalDirection;
9463 const canShift = focusShift && !skip;
9464 let items = !isVerticalDirection ? renderedItems : flatten2DArray(
9465 normalizeRows(groupItemsByRows2(renderedItems), activeId2, canShift)
9466 );
9467 items = canReverse ? reverseArray(items) : items;
9468 items = isVerticalDirection ? verticalizeItems(items) : items;
9469 if (activeId2 == null) {
9470 return (_a2 = findFirstEnabledItem2(items)) == null ? void 0 : _a2.id;
9471 }
9472 const activeItem = items.find((item) => item.id === activeId2);
9473 if (!activeItem) {
9474 return (_b = findFirstEnabledItem2(items)) == null ? void 0 : _b.id;
9475 }
9476 const isGrid2 = items.some((item) => item.rowId);
9477 const activeIndex = items.indexOf(activeItem);
9478 const nextItems = items.slice(activeIndex + 1);
9479 const nextItemsInRow = getItemsInRow(nextItems, activeItem.rowId);
9480 if (skip) {
9481 const nextEnabledItemsInRow = getEnabledItems(nextItemsInRow, activeId2);
9482 const nextItem2 = nextEnabledItemsInRow.slice(skip)[0] || // If we can't find an item, just return the last one.
9483 nextEnabledItemsInRow[nextEnabledItemsInRow.length - 1];
9484 return nextItem2 == null ? void 0 : nextItem2.id;
9485 }
9486 const canLoop = focusLoop && (isVerticalDirection ? focusLoop !== "horizontal" : focusLoop !== "vertical");
9487 const canWrap = isGrid2 && focusWrap && (isVerticalDirection ? focusWrap !== "horizontal" : focusWrap !== "vertical");
9488 const hasNullItem = isNextDirection ? (!isGrid2 || isVerticalDirection) && canLoop && includesBaseElement : isVerticalDirection ? includesBaseElement : false;
9489 if (canLoop) {
9490 const loopItems = canWrap && !hasNullItem ? items : getItemsInRow(items, activeItem.rowId);
9491 const sortedItems = flipItems(loopItems, activeId2, hasNullItem);
9492 const nextItem2 = findFirstEnabledItem2(sortedItems, activeId2);
9493 return nextItem2 == null ? void 0 : nextItem2.id;
9494 }
9495 if (canWrap) {
9496 const nextItem2 = findFirstEnabledItem2(
9497 // We can use nextItems, which contains all the next items, including
9498 // items from other rows, to wrap between rows. However, if there is a
9499 // null item (the composite container), we'll only use the next items in
9500 // the row. So moving next from the last item will focus on the
9501 // composite container. On grid composites, horizontal navigation never
9502 // focuses on the composite container, only vertical.
9503 hasNullItem ? nextItemsInRow : nextItems,
9504 activeId2
9505 );
9506 const nextId = hasNullItem ? (nextItem2 == null ? void 0 : nextItem2.id) || null : nextItem2 == null ? void 0 : nextItem2.id;
9507 return nextId;
9508 }
9509 const nextItem = findFirstEnabledItem2(nextItemsInRow, activeId2);
9510 if (!nextItem && hasNullItem) {
9511 return null;
9512 }
9513 return nextItem == null ? void 0 : nextItem.id;
9514 };
9515 return {
9516 ...collection,
9517 ...composite,
9518 setBaseElement: (element) => composite.setState("baseElement", element),
9519 setActiveId: (id) => composite.setState("activeId", id),
9520 move: (id) => {
9521 if (id === void 0) return;
9522 composite.setState("activeId", id);
9523 composite.setState("moves", (moves) => moves + 1);
9524 },
9525 first: () => {
9526 var _a2;
9527 return (_a2 = findFirstEnabledItem2(composite.getState().renderedItems)) == null ? void 0 : _a2.id;
9528 },
9529 last: () => {
9530 var _a2;
9531 return (_a2 = findFirstEnabledItem2(reverseArray(composite.getState().renderedItems))) == null ? void 0 : _a2.id;
9532 },
9533 next: (options) => {
9534 if (options !== void 0 && typeof options === "number") {
9535 options = { skip: options };
9536 }
9537 return getNextId("next", options);
9538 },
9539 previous: (options) => {
9540 if (options !== void 0 && typeof options === "number") {
9541 options = { skip: options };
9542 }
9543 return getNextId("previous", options);
9544 },
9545 down: (options) => {
9546 if (options !== void 0 && typeof options === "number") {
9547 options = { skip: options };
9548 }
9549 return getNextId("down", options);
9550 },
9551 up: (options) => {
9552 if (options !== void 0 && typeof options === "number") {
9553 options = { skip: options };
9554 }
9555 return getNextId("up", options);
9556 }
9557 };
9558 }
9559
9560 // node_modules/@ariakit/react-core/esm/__chunks/IQYAUKXT.js
9561 function useCompositeStoreOptions(props) {
9562 const id = useId3(props.id);
9563 return { id, ...props };
9564 }
9565 function useCompositeStoreProps(store, update2, props) {
9566 store = useCollectionStoreProps(store, update2, props);
9567 useStoreProps(store, props, "activeId", "setActiveId");
9568 useStoreProps(store, props, "includesBaseElement");
9569 useStoreProps(store, props, "virtualFocus");
9570 useStoreProps(store, props, "orientation");
9571 useStoreProps(store, props, "rtl");
9572 useStoreProps(store, props, "focusLoop");
9573 useStoreProps(store, props, "focusWrap");
9574 useStoreProps(store, props, "focusShift");
9575 return store;
9576 }
9577
9578 // node_modules/@ariakit/react-core/esm/__chunks/CVCFNOHX.js
9579 var import_react16 = __toESM(require_react(), 1);
9580 var ComboboxListRoleContext = (0, import_react16.createContext)(
9581 void 0
9582 );
9583 var ctx6 = createStoreContext(
9584 [PopoverContextProvider, CompositeContextProvider],
9585 [PopoverScopedContextProvider, CompositeScopedContextProvider]
9586 );
9587 var useComboboxContext = ctx6.useContext;
9588 var useComboboxScopedContext = ctx6.useScopedContext;
9589 var useComboboxProviderContext = ctx6.useProviderContext;
9590 var ComboboxContextProvider = ctx6.ContextProvider;
9591 var ComboboxScopedContextProvider = ctx6.ScopedContextProvider;
9592 var ComboboxItemValueContext = (0, import_react16.createContext)(
9593 void 0
9594 );
9595 var ComboboxItemCheckedContext = (0, import_react16.createContext)(false);
9596
9597 // node_modules/@ariakit/core/esm/__chunks/KMAUV3TY.js
9598 function createDialogStore(props = {}) {
9599 return createDisclosureStore(props);
9600 }
9601
9602 // node_modules/@ariakit/react-core/esm/__chunks/4NYSH4UO.js
9603 function useDialogStoreProps(store, update2, props) {
9604 return useDisclosureStoreProps(store, update2, props);
9605 }
9606
9607 // node_modules/@ariakit/core/esm/__chunks/BFGNM53A.js
9608 function createPopoverStore({
9609 popover: otherPopover,
9610 ...props
9611 } = {}) {
9612 const store = mergeStore(
9613 props.store,
9614 omit2(otherPopover, [
9615 "arrowElement",
9616 "anchorElement",
9617 "contentElement",
9618 "popoverElement",
9619 "disclosureElement"
9620 ])
9621 );
9622 throwOnConflictingProps(props, store);
9623 const syncState = store == null ? void 0 : store.getState();
9624 const dialog = createDialogStore({ ...props, store });
9625 const placement = defaultValue(
9626 props.placement,
9627 syncState == null ? void 0 : syncState.placement,
9628 "bottom"
9629 );
9630 const initialState = {
9631 ...dialog.getState(),
9632 placement,
9633 currentPlacement: placement,
9634 anchorElement: defaultValue(syncState == null ? void 0 : syncState.anchorElement, null),
9635 popoverElement: defaultValue(syncState == null ? void 0 : syncState.popoverElement, null),
9636 arrowElement: defaultValue(syncState == null ? void 0 : syncState.arrowElement, null),
9637 rendered: /* @__PURE__ */ Symbol("rendered")
9638 };
9639 const popover = createStore(initialState, dialog, store);
9640 return {
9641 ...dialog,
9642 ...popover,
9643 setAnchorElement: (element) => popover.setState("anchorElement", element),
9644 setPopoverElement: (element) => popover.setState("popoverElement", element),
9645 setArrowElement: (element) => popover.setState("arrowElement", element),
9646 render: () => popover.setState("rendered", /* @__PURE__ */ Symbol("rendered"))
9647 };
9648 }
9649
9650 // node_modules/@ariakit/react-core/esm/__chunks/B6FLPFJM.js
9651 function usePopoverStoreProps(store, update2, props) {
9652 useUpdateEffect(update2, [props.popover]);
9653 useStoreProps(store, props, "placement");
9654 return useDialogStoreProps(store, update2, props);
9655 }
9656
9657 // node_modules/@ariakit/react-core/esm/__chunks/4POTBZ2J.js
9658 var TagName7 = "div";
9659 var usePopoverAnchor = createHook(
9660 function usePopoverAnchor2({ store, ...props }) {
9661 const context = usePopoverProviderContext();
9662 store = store || context;
9663 props = {
9664 ...props,
9665 ref: useMergeRefs(store == null ? void 0 : store.setAnchorElement, props.ref)
9666 };
9667 return props;
9668 }
9669 );
9670 var PopoverAnchor = forwardRef22(function PopoverAnchor2(props) {
9671 const htmlProps = usePopoverAnchor(props);
9672 return createElement3(TagName7, htmlProps);
9673 });
9674
9675 // node_modules/@ariakit/react-core/esm/__chunks/X6LNAU2F.js
9676 var import_react17 = __toESM(require_react(), 1);
9677 var TagName8 = "div";
9678 function getMouseDestination(event) {
9679 const relatedTarget = event.relatedTarget;
9680 if ((relatedTarget == null ? void 0 : relatedTarget.nodeType) === Node.ELEMENT_NODE) {
9681 return relatedTarget;
9682 }
9683 return null;
9684 }
9685 function hoveringInside(event) {
9686 const nextElement = getMouseDestination(event);
9687 if (!nextElement) return false;
9688 return contains(event.currentTarget, nextElement);
9689 }
9690 var symbol2 = /* @__PURE__ */ Symbol("composite-hover");
9691 function movingToAnotherItem(event) {
9692 let dest = getMouseDestination(event);
9693 if (!dest) return false;
9694 do {
9695 if (hasOwnProperty(dest, symbol2) && dest[symbol2]) return true;
9696 dest = dest.parentElement;
9697 } while (dest);
9698 return false;
9699 }
9700 var useCompositeHover = createHook(
9701 function useCompositeHover2({
9702 store,
9703 focusOnHover = true,
9704 blurOnHoverEnd = !!focusOnHover,
9705 ...props
9706 }) {
9707 const context = useCompositeContext();
9708 store = store || context;
9709 invariant(
9710 store,
9711 "CompositeHover must be wrapped in a Composite component."
9712 );
9713 const isMouseMoving = useIsMouseMoving();
9714 const onMouseMoveProp = props.onMouseMove;
9715 const focusOnHoverProp = useBooleanEvent(focusOnHover);
9716 const onMouseMove = useEvent((event) => {
9717 onMouseMoveProp == null ? void 0 : onMouseMoveProp(event);
9718 if (event.defaultPrevented) return;
9719 if (!isMouseMoving()) return;
9720 if (!focusOnHoverProp(event)) return;
9721 if (!hasFocusWithin(event.currentTarget)) {
9722 const baseElement = store == null ? void 0 : store.getState().baseElement;
9723 if (baseElement && !hasFocus(baseElement)) {
9724 baseElement.focus();
9725 }
9726 }
9727 store == null ? void 0 : store.setActiveId(event.currentTarget.id);
9728 });
9729 const onMouseLeaveProp = props.onMouseLeave;
9730 const blurOnHoverEndProp = useBooleanEvent(blurOnHoverEnd);
9731 const onMouseLeave = useEvent((event) => {
9732 var _a;
9733 onMouseLeaveProp == null ? void 0 : onMouseLeaveProp(event);
9734 if (event.defaultPrevented) return;
9735 if (!isMouseMoving()) return;
9736 if (hoveringInside(event)) return;
9737 if (movingToAnotherItem(event)) return;
9738 if (!focusOnHoverProp(event)) return;
9739 if (!blurOnHoverEndProp(event)) return;
9740 store == null ? void 0 : store.setActiveId(null);
9741 (_a = store == null ? void 0 : store.getState().baseElement) == null ? void 0 : _a.focus();
9742 });
9743 const ref = (0, import_react17.useCallback)((element) => {
9744 if (!element) return;
9745 element[symbol2] = true;
9746 }, []);
9747 props = {
9748 ...props,
9749 ref: useMergeRefs(ref, props.ref),
9750 onMouseMove,
9751 onMouseLeave
9752 };
9753 return removeUndefinedValues(props);
9754 }
9755 );
9756 var CompositeHover = memo22(
9757 forwardRef22(function CompositeHover2(props) {
9758 const htmlProps = useCompositeHover(props);
9759 return createElement3(TagName8, htmlProps);
9760 })
9761 );
9762
9763 // node_modules/@ariakit/react-core/esm/combobox/combobox.js
9764 var import_react18 = __toESM(require_react(), 1);
9765 var TagName9 = "input";
9766 function isFirstItemAutoSelected(items, activeValue, autoSelect) {
9767 if (!autoSelect) return false;
9768 const firstItem = items.find((item) => !item.disabled && item.value);
9769 return (firstItem == null ? void 0 : firstItem.value) === activeValue;
9770 }
9771 function hasCompletionString(value, activeValue) {
9772 if (!activeValue) return false;
9773 if (value == null) return false;
9774 value = normalizeString(value);
9775 return activeValue.length > value.length && activeValue.toLowerCase().indexOf(value.toLowerCase()) === 0;
9776 }
9777 function isInputEvent(event) {
9778 return event.type === "input";
9779 }
9780 function isAriaAutoCompleteValue(value) {
9781 return value === "inline" || value === "list" || value === "both" || value === "none";
9782 }
9783 function getDefaultAutoSelectId(items) {
9784 const item = items.find((item2) => {
9785 var _a;
9786 if (item2.disabled) return false;
9787 return ((_a = item2.element) == null ? void 0 : _a.getAttribute("role")) !== "tab";
9788 });
9789 return item == null ? void 0 : item.id;
9790 }
9791 var useCombobox = createHook(
9792 function useCombobox2({
9793 store,
9794 focusable = true,
9795 autoSelect: autoSelectProp = false,
9796 getAutoSelectId,
9797 setValueOnChange,
9798 showMinLength = 0,
9799 showOnChange,
9800 showOnMouseDown,
9801 showOnClick = showOnMouseDown,
9802 showOnKeyDown,
9803 showOnKeyPress = showOnKeyDown,
9804 blurActiveItemOnClick,
9805 setValueOnClick = true,
9806 moveOnKeyPress = true,
9807 autoComplete = "list",
9808 ...props
9809 }) {
9810 const context = useComboboxProviderContext();
9811 store = store || context;
9812 invariant(
9813 store,
9814 "Combobox must receive a `store` prop or be wrapped in a ComboboxProvider component."
9815 );
9816 const ref = (0, import_react18.useRef)(null);
9817 const [valueUpdated, forceValueUpdate] = useForceUpdate();
9818 const canAutoSelectRef = (0, import_react18.useRef)(false);
9819 const composingRef = (0, import_react18.useRef)(false);
9820 const autoSelect = store.useState(
9821 (state) => state.virtualFocus && autoSelectProp
9822 );
9823 const inline = autoComplete === "inline" || autoComplete === "both";
9824 const [canInline, setCanInline] = (0, import_react18.useState)(inline);
9825 useUpdateLayoutEffect(() => {
9826 if (!inline) return;
9827 setCanInline(true);
9828 }, [inline]);
9829 const storeValue = store.useState("value");
9830 const prevSelectedValueRef = (0, import_react18.useRef)(void 0);
9831 (0, import_react18.useEffect)(() => {
9832 return sync(store, ["selectedValue", "activeId"], (_, prev) => {
9833 prevSelectedValueRef.current = prev.selectedValue;
9834 });
9835 }, []);
9836 const inlineActiveValue = store.useState((state) => {
9837 var _a;
9838 if (!inline) return;
9839 if (!canInline) return;
9840 if (state.activeValue && Array.isArray(state.selectedValue)) {
9841 if (state.selectedValue.includes(state.activeValue)) return;
9842 if ((_a = prevSelectedValueRef.current) == null ? void 0 : _a.includes(state.activeValue)) return;
9843 }
9844 return state.activeValue;
9845 });
9846 const items = store.useState("renderedItems");
9847 const open = store.useState("open");
9848 const contentElement = store.useState("contentElement");
9849 const value = (0, import_react18.useMemo)(() => {
9850 if (!inline) return storeValue;
9851 if (!canInline) return storeValue;
9852 const firstItemAutoSelected = isFirstItemAutoSelected(
9853 items,
9854 inlineActiveValue,
9855 autoSelect
9856 );
9857 if (firstItemAutoSelected) {
9858 if (hasCompletionString(storeValue, inlineActiveValue)) {
9859 const slice = (inlineActiveValue == null ? void 0 : inlineActiveValue.slice(storeValue.length)) || "";
9860 return storeValue + slice;
9861 }
9862 return storeValue;
9863 }
9864 return inlineActiveValue || storeValue;
9865 }, [inline, canInline, items, inlineActiveValue, autoSelect, storeValue]);
9866 (0, import_react18.useEffect)(() => {
9867 const element = ref.current;
9868 if (!element) return;
9869 const onCompositeItemMove = () => setCanInline(true);
9870 element.addEventListener("combobox-item-move", onCompositeItemMove);
9871 return () => {
9872 element.removeEventListener("combobox-item-move", onCompositeItemMove);
9873 };
9874 }, []);
9875 (0, import_react18.useEffect)(() => {
9876 if (!inline) return;
9877 if (!canInline) return;
9878 if (!inlineActiveValue) return;
9879 const firstItemAutoSelected = isFirstItemAutoSelected(
9880 items,
9881 inlineActiveValue,
9882 autoSelect
9883 );
9884 if (!firstItemAutoSelected) return;
9885 if (!hasCompletionString(storeValue, inlineActiveValue)) return;
9886 let cleanup = noop2;
9887 queueMicrotask(() => {
9888 const element = ref.current;
9889 if (!element) return;
9890 const { start: prevStart, end: prevEnd } = getTextboxSelection(element);
9891 const nextStart = storeValue.length;
9892 const nextEnd = inlineActiveValue.length;
9893 setSelectionRange(element, nextStart, nextEnd);
9894 cleanup = () => {
9895 if (!hasFocus(element)) return;
9896 const { start, end } = getTextboxSelection(element);
9897 if (start !== nextStart) return;
9898 if (end !== nextEnd) return;
9899 setSelectionRange(element, prevStart, prevEnd);
9900 };
9901 });
9902 return () => cleanup();
9903 }, [
9904 valueUpdated,
9905 inline,
9906 canInline,
9907 inlineActiveValue,
9908 items,
9909 autoSelect,
9910 storeValue
9911 ]);
9912 const scrollingElementRef = (0, import_react18.useRef)(null);
9913 const getAutoSelectIdProp = useEvent(getAutoSelectId);
9914 const autoSelectIdRef = (0, import_react18.useRef)(null);
9915 (0, import_react18.useEffect)(() => {
9916 if (!open) return;
9917 if (!contentElement) return;
9918 const scrollingElement = getScrollingElement(contentElement);
9919 if (!scrollingElement) return;
9920 scrollingElementRef.current = scrollingElement;
9921 const onUserScroll = () => {
9922 canAutoSelectRef.current = false;
9923 };
9924 const onScroll = () => {
9925 if (!store) return;
9926 if (!canAutoSelectRef.current) return;
9927 const { activeId } = store.getState();
9928 if (activeId === null) return;
9929 if (activeId === autoSelectIdRef.current) return;
9930 canAutoSelectRef.current = false;
9931 };
9932 const options = { passive: true, capture: true };
9933 scrollingElement.addEventListener("wheel", onUserScroll, options);
9934 scrollingElement.addEventListener("touchmove", onUserScroll, options);
9935 scrollingElement.addEventListener("scroll", onScroll, options);
9936 return () => {
9937 scrollingElement.removeEventListener("wheel", onUserScroll, true);
9938 scrollingElement.removeEventListener("touchmove", onUserScroll, true);
9939 scrollingElement.removeEventListener("scroll", onScroll, true);
9940 };
9941 }, [open, contentElement, store]);
9942 useSafeLayoutEffect(() => {
9943 if (!storeValue) return;
9944 if (composingRef.current) return;
9945 canAutoSelectRef.current = true;
9946 }, [storeValue]);
9947 useSafeLayoutEffect(() => {
9948 if (autoSelect !== "always" && open) return;
9949 canAutoSelectRef.current = open;
9950 }, [autoSelect, open]);
9951 const resetValueOnSelect = store.useState("resetValueOnSelect");
9952 useUpdateEffect(() => {
9953 var _a, _b;
9954 const canAutoSelect = canAutoSelectRef.current;
9955 if (!store) return;
9956 if (!open) return;
9957 if (!canAutoSelect && !resetValueOnSelect) return;
9958 const { baseElement, contentElement: contentElement2, activeId } = store.getState();
9959 if (baseElement && !hasFocus(baseElement)) return;
9960 if (contentElement2 == null ? void 0 : contentElement2.hasAttribute("data-placing")) {
9961 const observer = new MutationObserver(forceValueUpdate);
9962 observer.observe(contentElement2, { attributeFilter: ["data-placing"] });
9963 return () => observer.disconnect();
9964 }
9965 if (autoSelect && canAutoSelect) {
9966 const userAutoSelectId = getAutoSelectIdProp(items);
9967 const autoSelectId = userAutoSelectId !== void 0 ? userAutoSelectId : (_a = getDefaultAutoSelectId(items)) != null ? _a : store.first();
9968 autoSelectIdRef.current = autoSelectId;
9969 store.move(autoSelectId != null ? autoSelectId : null);
9970 } else {
9971 const element = (_b = store.item(activeId || store.first())) == null ? void 0 : _b.element;
9972 if (element && "scrollIntoView" in element) {
9973 element.scrollIntoView({ block: "nearest", inline: "nearest" });
9974 }
9975 }
9976 return;
9977 }, [
9978 store,
9979 open,
9980 valueUpdated,
9981 storeValue,
9982 autoSelect,
9983 resetValueOnSelect,
9984 getAutoSelectIdProp,
9985 items
9986 ]);
9987 (0, import_react18.useEffect)(() => {
9988 if (!inline) return;
9989 const combobox = ref.current;
9990 if (!combobox) return;
9991 const elements = [combobox, contentElement].filter(
9992 (value2) => !!value2
9993 );
9994 const onBlur2 = (event) => {
9995 if (elements.every((el) => isFocusEventOutside(event, el))) {
9996 store == null ? void 0 : store.setValue(value);
9997 }
9998 };
9999 for (const element of elements) {
10000 element.addEventListener("focusout", onBlur2);
10001 }
10002 return () => {
10003 for (const element of elements) {
10004 element.removeEventListener("focusout", onBlur2);
10005 }
10006 };
10007 }, [inline, contentElement, store, value]);
10008 const canShow = (event) => {
10009 const currentTarget = event.currentTarget;
10010 return currentTarget.value.length >= showMinLength;
10011 };
10012 const onChangeProp = props.onChange;
10013 const showOnChangeProp = useBooleanEvent(showOnChange != null ? showOnChange : canShow);
10014 const setValueOnChangeProp = useBooleanEvent(
10015 // If the combobox is combined with tags, the value will be set by the tag
10016 // input component.
10017 setValueOnChange != null ? setValueOnChange : !store.tag
10018 );
10019 const onChange = useEvent((event) => {
10020 onChangeProp == null ? void 0 : onChangeProp(event);
10021 if (event.defaultPrevented) return;
10022 if (!store) return;
10023 const currentTarget = event.currentTarget;
10024 const { value: value2, selectionStart, selectionEnd } = currentTarget;
10025 const nativeEvent = event.nativeEvent;
10026 canAutoSelectRef.current = true;
10027 if (isInputEvent(nativeEvent)) {
10028 if (nativeEvent.isComposing) {
10029 canAutoSelectRef.current = false;
10030 composingRef.current = true;
10031 }
10032 if (inline) {
10033 const textInserted = nativeEvent.inputType === "insertText" || nativeEvent.inputType === "insertCompositionText";
10034 const caretAtEnd = selectionStart === value2.length;
10035 setCanInline(textInserted && caretAtEnd);
10036 }
10037 }
10038 if (setValueOnChangeProp(event)) {
10039 const isSameValue = value2 === store.getState().value;
10040 store.setValue(value2);
10041 queueMicrotask(() => {
10042 setSelectionRange(currentTarget, selectionStart, selectionEnd);
10043 });
10044 if (inline && autoSelect && isSameValue) {
10045 forceValueUpdate();
10046 }
10047 }
10048 if (showOnChangeProp(event)) {
10049 store.show();
10050 }
10051 if (!autoSelect || !canAutoSelectRef.current) {
10052 store.setActiveId(null);
10053 }
10054 });
10055 const onCompositionEndProp = props.onCompositionEnd;
10056 const onCompositionEnd = useEvent((event) => {
10057 canAutoSelectRef.current = true;
10058 composingRef.current = false;
10059 onCompositionEndProp == null ? void 0 : onCompositionEndProp(event);
10060 if (event.defaultPrevented) return;
10061 if (!autoSelect) return;
10062 forceValueUpdate();
10063 });
10064 const onMouseDownProp = props.onMouseDown;
10065 const blurActiveItemOnClickProp = useBooleanEvent(
10066 blurActiveItemOnClick != null ? blurActiveItemOnClick : (() => !!(store == null ? void 0 : store.getState().includesBaseElement))
10067 );
10068 const setValueOnClickProp = useBooleanEvent(setValueOnClick);
10069 const showOnClickProp = useBooleanEvent(showOnClick != null ? showOnClick : canShow);
10070 const onMouseDown = useEvent((event) => {
10071 onMouseDownProp == null ? void 0 : onMouseDownProp(event);
10072 if (event.defaultPrevented) return;
10073 if (event.button) return;
10074 if (event.ctrlKey) return;
10075 if (!store) return;
10076 if (blurActiveItemOnClickProp(event)) {
10077 store.setActiveId(null);
10078 }
10079 if (setValueOnClickProp(event)) {
10080 store.setValue(value);
10081 }
10082 if (showOnClickProp(event)) {
10083 queueBeforeEvent(event.currentTarget, "mouseup", store.show);
10084 }
10085 });
10086 const onKeyDownProp = props.onKeyDown;
10087 const showOnKeyPressProp = useBooleanEvent(showOnKeyPress != null ? showOnKeyPress : canShow);
10088 const onKeyDown = useEvent((event) => {
10089 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
10090 if (!event.repeat) {
10091 canAutoSelectRef.current = false;
10092 }
10093 if (event.defaultPrevented) return;
10094 if (event.ctrlKey) return;
10095 if (event.altKey) return;
10096 if (event.shiftKey) return;
10097 if (event.metaKey) return;
10098 if (!store) return;
10099 const { open: open2 } = store.getState();
10100 if (open2) return;
10101 if (event.key === "ArrowUp" || event.key === "ArrowDown") {
10102 if (showOnKeyPressProp(event)) {
10103 event.preventDefault();
10104 store.show();
10105 }
10106 }
10107 });
10108 const onBlurProp = props.onBlur;
10109 const onBlur = useEvent((event) => {
10110 canAutoSelectRef.current = false;
10111 onBlurProp == null ? void 0 : onBlurProp(event);
10112 if (event.defaultPrevented) return;
10113 });
10114 const id = useId3(props.id);
10115 const ariaAutoComplete = isAriaAutoCompleteValue(autoComplete) ? autoComplete : void 0;
10116 const isActiveItem = store.useState((state) => state.activeId === null);
10117 props = {
10118 id,
10119 role: "combobox",
10120 "aria-autocomplete": ariaAutoComplete,
10121 "aria-haspopup": getPopupRole(contentElement, "listbox"),
10122 "aria-expanded": open,
10123 "aria-controls": contentElement == null ? void 0 : contentElement.id,
10124 "data-active-item": isActiveItem || void 0,
10125 value,
10126 ...props,
10127 ref: useMergeRefs(ref, props.ref),
10128 onChange,
10129 onCompositionEnd,
10130 onMouseDown,
10131 onKeyDown,
10132 onBlur
10133 };
10134 props = useComposite({
10135 store,
10136 focusable,
10137 ...props,
10138 // Enable inline autocomplete when the user moves from the combobox input
10139 // to an item.
10140 moveOnKeyPress: (event) => {
10141 if (isFalsyBooleanCallback(moveOnKeyPress, event)) return false;
10142 if (inline) setCanInline(true);
10143 return true;
10144 }
10145 });
10146 props = usePopoverAnchor({ store, ...props });
10147 return { autoComplete: "off", ...props };
10148 }
10149 );
10150 var Combobox = forwardRef22(function Combobox2(props) {
10151 const htmlProps = useCombobox(props);
10152 return createElement3(TagName9, htmlProps);
10153 });
10154
10155 // node_modules/@ariakit/react-core/esm/__chunks/IBXZ2LQC.js
10156 var import_react19 = __toESM(require_react(), 1);
10157 var import_jsx_runtime58 = __toESM(require_jsx_runtime(), 1);
10158 var TagName10 = "div";
10159 function isSelected(storeValue, itemValue) {
10160 if (itemValue == null) return;
10161 if (storeValue == null) return false;
10162 if (Array.isArray(storeValue)) {
10163 return storeValue.includes(itemValue);
10164 }
10165 return storeValue === itemValue;
10166 }
10167 function getItemRole(popupRole) {
10168 var _a;
10169 const itemRoleByPopupRole = {
10170 menu: "menuitem",
10171 listbox: "option",
10172 tree: "treeitem"
10173 };
10174 const key = popupRole;
10175 return (_a = itemRoleByPopupRole[key]) != null ? _a : "option";
10176 }
10177 var useComboboxItem = createHook(
10178 function useComboboxItem2({
10179 store,
10180 value,
10181 hideOnClick,
10182 setValueOnClick,
10183 selectValueOnClick = true,
10184 resetValueOnSelect,
10185 focusOnHover = false,
10186 moveOnKeyPress = true,
10187 getItem: getItemProp,
10188 ...props
10189 }) {
10190 var _a;
10191 const context = useComboboxScopedContext();
10192 store = store || context;
10193 invariant(
10194 store,
10195 "ComboboxItem must be wrapped in a ComboboxList or ComboboxPopover component."
10196 );
10197 const { resetValueOnSelectState, multiSelectable, selected } = useStoreStateObject(store, {
10198 resetValueOnSelectState: "resetValueOnSelect",
10199 multiSelectable(state) {
10200 return Array.isArray(state.selectedValue);
10201 },
10202 selected(state) {
10203 return isSelected(state.selectedValue, value);
10204 }
10205 });
10206 const getItem = (0, import_react19.useCallback)(
10207 (item) => {
10208 const nextItem = { ...item, value };
10209 if (getItemProp) {
10210 return getItemProp(nextItem);
10211 }
10212 return nextItem;
10213 },
10214 [value, getItemProp]
10215 );
10216 setValueOnClick = setValueOnClick != null ? setValueOnClick : !multiSelectable;
10217 hideOnClick = hideOnClick != null ? hideOnClick : value != null && !multiSelectable;
10218 const onClickProp = props.onClick;
10219 const setValueOnClickProp = useBooleanEvent(setValueOnClick);
10220 const selectValueOnClickProp = useBooleanEvent(selectValueOnClick);
10221 const resetValueOnSelectProp = useBooleanEvent(
10222 (_a = resetValueOnSelect != null ? resetValueOnSelect : resetValueOnSelectState) != null ? _a : multiSelectable
10223 );
10224 const hideOnClickProp = useBooleanEvent(hideOnClick);
10225 const onClick = useEvent((event) => {
10226 onClickProp == null ? void 0 : onClickProp(event);
10227 if (event.defaultPrevented) return;
10228 if (isDownloading(event)) return;
10229 if (isOpeningInNewTab(event)) return;
10230 if (value != null) {
10231 if (selectValueOnClickProp(event)) {
10232 if (resetValueOnSelectProp(event)) {
10233 store == null ? void 0 : store.resetValue();
10234 }
10235 store == null ? void 0 : store.setSelectedValue((prevValue) => {
10236 if (!Array.isArray(prevValue)) return value;
10237 if (prevValue.includes(value)) {
10238 return prevValue.filter((v2) => v2 !== value);
10239 }
10240 return [...prevValue, value];
10241 });
10242 }
10243 if (setValueOnClickProp(event)) {
10244 store == null ? void 0 : store.setValue(value);
10245 }
10246 }
10247 if (hideOnClickProp(event)) {
10248 store == null ? void 0 : store.hide();
10249 }
10250 });
10251 const onKeyDownProp = props.onKeyDown;
10252 const onKeyDown = useEvent((event) => {
10253 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
10254 if (event.defaultPrevented) return;
10255 const baseElement = store == null ? void 0 : store.getState().baseElement;
10256 if (!baseElement) return;
10257 if (hasFocus(baseElement)) return;
10258 const printable = event.key.length === 1;
10259 if (printable || event.key === "Backspace" || event.key === "Delete") {
10260 queueMicrotask(() => baseElement.focus());
10261 if (isTextField(baseElement)) {
10262 store == null ? void 0 : store.setValue(baseElement.value);
10263 }
10264 }
10265 });
10266 if (multiSelectable && selected != null) {
10267 props = {
10268 "aria-selected": selected,
10269 ...props
10270 };
10271 }
10272 props = useWrapElement(
10273 props,
10274 (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 }) }),
10275 [value, selected]
10276 );
10277 const popupRole = (0, import_react19.useContext)(ComboboxListRoleContext);
10278 props = {
10279 role: getItemRole(popupRole),
10280 children: value,
10281 ...props,
10282 onClick,
10283 onKeyDown
10284 };
10285 const moveOnKeyPressProp = useBooleanEvent(moveOnKeyPress);
10286 props = useCompositeItem({
10287 store,
10288 ...props,
10289 getItem,
10290 // Dispatch a custom event on the combobox input when moving to an item
10291 // with the keyboard so the Combobox component can enable inline
10292 // autocompletion.
10293 moveOnKeyPress: (event) => {
10294 if (!moveOnKeyPressProp(event)) return false;
10295 const moveEvent = new Event("combobox-item-move");
10296 const baseElement = store == null ? void 0 : store.getState().baseElement;
10297 baseElement == null ? void 0 : baseElement.dispatchEvent(moveEvent);
10298 return true;
10299 }
10300 });
10301 props = useCompositeHover({ store, focusOnHover, ...props });
10302 return props;
10303 }
10304 );
10305 var ComboboxItem = memo22(
10306 forwardRef22(function ComboboxItem2(props) {
10307 const htmlProps = useComboboxItem(props);
10308 return createElement3(TagName10, htmlProps);
10309 })
10310 );
10311
10312 // node_modules/@ariakit/react-core/esm/combobox/combobox-item-value.js
10313 var import_react20 = __toESM(require_react(), 1);
10314 var import_jsx_runtime59 = __toESM(require_jsx_runtime(), 1);
10315 var TagName11 = "span";
10316 function normalizeValue(value) {
10317 return normalizeString(value).toLowerCase();
10318 }
10319 function getOffsets(string, values) {
10320 const offsets = [];
10321 for (const value of values) {
10322 let pos = 0;
10323 const length = value.length;
10324 while (string.indexOf(value, pos) !== -1) {
10325 const index = string.indexOf(value, pos);
10326 if (index !== -1) {
10327 offsets.push([index, length]);
10328 }
10329 pos = index + 1;
10330 }
10331 }
10332 return offsets;
10333 }
10334 function filterOverlappingOffsets(offsets) {
10335 return offsets.filter(([offset, length], i2, arr) => {
10336 return !arr.some(
10337 ([o2, l2], j2) => j2 !== i2 && o2 <= offset && o2 + l2 >= offset + length
10338 );
10339 });
10340 }
10341 function sortOffsets(offsets) {
10342 return offsets.sort(([a2], [b2]) => a2 - b2);
10343 }
10344 function splitValue(itemValue, userValue) {
10345 if (!itemValue) return itemValue;
10346 if (!userValue) return itemValue;
10347 const userValues = toArray(userValue).filter(Boolean).map(normalizeValue);
10348 const parts = [];
10349 const span = (value, autocomplete = false) => /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(
10350 "span",
10351 {
10352 "data-autocomplete-value": autocomplete ? "" : void 0,
10353 "data-user-value": autocomplete ? void 0 : "",
10354 children: value
10355 },
10356 parts.length
10357 );
10358 const offsets = sortOffsets(
10359 filterOverlappingOffsets(
10360 // Convert userValues into a set to avoid duplicates
10361 getOffsets(normalizeValue(itemValue), new Set(userValues))
10362 )
10363 );
10364 if (!offsets.length) {
10365 parts.push(span(itemValue, true));
10366 return parts;
10367 }
10368 const [firstOffset] = offsets[0];
10369 const values = [
10370 itemValue.slice(0, firstOffset),
10371 ...offsets.flatMap(([offset, length], i2) => {
10372 var _a;
10373 const value = itemValue.slice(offset, offset + length);
10374 const nextOffset = (_a = offsets[i2 + 1]) == null ? void 0 : _a[0];
10375 const nextValue = itemValue.slice(offset + length, nextOffset);
10376 return [value, nextValue];
10377 })
10378 ];
10379 values.forEach((value, i2) => {
10380 if (!value) return;
10381 parts.push(span(value, i2 % 2 === 0));
10382 });
10383 return parts;
10384 }
10385 var useComboboxItemValue = createHook(function useComboboxItemValue2({ store, value, userValue, ...props }) {
10386 const context = useComboboxScopedContext();
10387 store = store || context;
10388 const itemContext = (0, import_react20.useContext)(ComboboxItemValueContext);
10389 const itemValue = value != null ? value : itemContext;
10390 const inputValue = useStoreState(store, (state) => userValue != null ? userValue : state == null ? void 0 : state.value);
10391 const children = (0, import_react20.useMemo)(() => {
10392 if (!itemValue) return;
10393 if (!inputValue) return itemValue;
10394 return splitValue(itemValue, inputValue);
10395 }, [itemValue, inputValue]);
10396 props = {
10397 children,
10398 ...props
10399 };
10400 return removeUndefinedValues(props);
10401 });
10402 var ComboboxItemValue = forwardRef22(function ComboboxItemValue2(props) {
10403 const htmlProps = useComboboxItemValue(props);
10404 return createElement3(TagName11, htmlProps);
10405 });
10406
10407 // node_modules/@ariakit/react-core/esm/combobox/combobox-label.js
10408 var TagName12 = "label";
10409 var useComboboxLabel = createHook(
10410 function useComboboxLabel2({ store, ...props }) {
10411 const context = useComboboxProviderContext();
10412 store = store || context;
10413 invariant(
10414 store,
10415 "ComboboxLabel must receive a `store` prop or be wrapped in a ComboboxProvider component."
10416 );
10417 const comboboxId = store.useState((state) => {
10418 var _a;
10419 return (_a = state.baseElement) == null ? void 0 : _a.id;
10420 });
10421 props = {
10422 htmlFor: comboboxId,
10423 ...props
10424 };
10425 return removeUndefinedValues(props);
10426 }
10427 );
10428 var ComboboxLabel = memo22(
10429 forwardRef22(function ComboboxLabel2(props) {
10430 const htmlProps = useComboboxLabel(props);
10431 return createElement3(TagName12, htmlProps);
10432 })
10433 );
10434
10435 // node_modules/@ariakit/react-core/esm/__chunks/2G6YEJT4.js
10436 var import_react21 = __toESM(require_react(), 1);
10437 var import_jsx_runtime60 = __toESM(require_jsx_runtime(), 1);
10438 var TagName13 = "div";
10439 var useComboboxList = createHook(
10440 function useComboboxList2({ store, alwaysVisible, ...props }) {
10441 const scopedContext = useComboboxScopedContext(true);
10442 const context = useComboboxContext();
10443 store = store || context;
10444 const scopedContextSameStore = !!store && store === scopedContext;
10445 invariant(
10446 store,
10447 "ComboboxList must receive a `store` prop or be wrapped in a ComboboxProvider component."
10448 );
10449 const ref = (0, import_react21.useRef)(null);
10450 const id = useId3(props.id);
10451 const mounted = store.useState("mounted");
10452 const hidden = isHidden(mounted, props.hidden, alwaysVisible);
10453 const style = hidden ? { ...props.style, display: "none" } : props.style;
10454 const multiSelectable = store.useState(
10455 (state) => Array.isArray(state.selectedValue)
10456 );
10457 const role = useAttribute(ref, "role", props.role);
10458 const isCompositeRole = role === "listbox" || role === "tree" || role === "grid";
10459 const ariaMultiSelectable = isCompositeRole ? multiSelectable || void 0 : void 0;
10460 const [hasListboxInside, setHasListboxInside] = (0, import_react21.useState)(false);
10461 const contentElement = store.useState("contentElement");
10462 useSafeLayoutEffect(() => {
10463 if (!mounted) return;
10464 const element = ref.current;
10465 if (!element) return;
10466 if (contentElement !== element) return;
10467 const callback = () => {
10468 setHasListboxInside(!!element.querySelector("[role='listbox']"));
10469 };
10470 const observer = new MutationObserver(callback);
10471 observer.observe(element, {
10472 subtree: true,
10473 childList: true,
10474 attributeFilter: ["role"]
10475 });
10476 callback();
10477 return () => observer.disconnect();
10478 }, [mounted, contentElement]);
10479 if (!hasListboxInside) {
10480 props = {
10481 role: "listbox",
10482 "aria-multiselectable": ariaMultiSelectable,
10483 ...props
10484 };
10485 }
10486 props = useWrapElement(
10487 props,
10488 (element) => /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(ComboboxScopedContextProvider, { value: store, children: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(ComboboxListRoleContext.Provider, { value: role, children: element }) }),
10489 [store, role]
10490 );
10491 const setContentElement = id && (!scopedContext || !scopedContextSameStore) ? store.setContentElement : null;
10492 props = {
10493 id,
10494 hidden,
10495 ...props,
10496 ref: useMergeRefs(setContentElement, ref, props.ref),
10497 style
10498 };
10499 return removeUndefinedValues(props);
10500 }
10501 );
10502 var ComboboxList = forwardRef22(function ComboboxList2(props) {
10503 const htmlProps = useComboboxList(props);
10504 return createElement3(TagName13, htmlProps);
10505 });
10506
10507 // node_modules/@ariakit/react-core/esm/__chunks/XSIEPKGA.js
10508 var import_react22 = __toESM(require_react(), 1);
10509 var TagValueContext = (0, import_react22.createContext)(null);
10510 var TagRemoveIdContext = (0, import_react22.createContext)(
10511 null
10512 );
10513 var ctx7 = createStoreContext(
10514 [CompositeContextProvider],
10515 [CompositeScopedContextProvider]
10516 );
10517 var useTagContext = ctx7.useContext;
10518 var useTagScopedContext = ctx7.useScopedContext;
10519 var useTagProviderContext = ctx7.useProviderContext;
10520 var TagContextProvider = ctx7.ContextProvider;
10521 var TagScopedContextProvider = ctx7.ScopedContextProvider;
10522
10523 // node_modules/@ariakit/core/esm/combobox/combobox-store.js
10524 var isTouchSafari = isSafari() && isTouchDevice();
10525 function createComboboxStore({
10526 tag,
10527 ...props
10528 } = {}) {
10529 const store = mergeStore(props.store, pick2(tag, ["value", "rtl"]));
10530 throwOnConflictingProps(props, store);
10531 const tagState = tag == null ? void 0 : tag.getState();
10532 const syncState = store == null ? void 0 : store.getState();
10533 const activeId = defaultValue(
10534 props.activeId,
10535 syncState == null ? void 0 : syncState.activeId,
10536 props.defaultActiveId,
10537 null
10538 );
10539 const composite = createCompositeStore({
10540 ...props,
10541 activeId,
10542 includesBaseElement: defaultValue(
10543 props.includesBaseElement,
10544 syncState == null ? void 0 : syncState.includesBaseElement,
10545 true
10546 ),
10547 orientation: defaultValue(
10548 props.orientation,
10549 syncState == null ? void 0 : syncState.orientation,
10550 "vertical"
10551 ),
10552 focusLoop: defaultValue(props.focusLoop, syncState == null ? void 0 : syncState.focusLoop, true),
10553 focusWrap: defaultValue(props.focusWrap, syncState == null ? void 0 : syncState.focusWrap, true),
10554 virtualFocus: defaultValue(
10555 props.virtualFocus,
10556 syncState == null ? void 0 : syncState.virtualFocus,
10557 true
10558 )
10559 });
10560 const popover = createPopoverStore({
10561 ...props,
10562 placement: defaultValue(
10563 props.placement,
10564 syncState == null ? void 0 : syncState.placement,
10565 "bottom-start"
10566 )
10567 });
10568 const value = defaultValue(
10569 props.value,
10570 syncState == null ? void 0 : syncState.value,
10571 props.defaultValue,
10572 ""
10573 );
10574 const selectedValue = defaultValue(
10575 props.selectedValue,
10576 syncState == null ? void 0 : syncState.selectedValue,
10577 tagState == null ? void 0 : tagState.values,
10578 props.defaultSelectedValue,
10579 ""
10580 );
10581 const multiSelectable = Array.isArray(selectedValue);
10582 const initialState = {
10583 ...composite.getState(),
10584 ...popover.getState(),
10585 value,
10586 selectedValue,
10587 resetValueOnSelect: defaultValue(
10588 props.resetValueOnSelect,
10589 syncState == null ? void 0 : syncState.resetValueOnSelect,
10590 multiSelectable
10591 ),
10592 resetValueOnHide: defaultValue(
10593 props.resetValueOnHide,
10594 syncState == null ? void 0 : syncState.resetValueOnHide,
10595 multiSelectable && !tag
10596 ),
10597 activeValue: syncState == null ? void 0 : syncState.activeValue
10598 };
10599 const combobox = createStore(initialState, composite, popover, store);
10600 if (isTouchSafari) {
10601 setup(
10602 combobox,
10603 () => sync(combobox, ["virtualFocus"], () => {
10604 combobox.setState("virtualFocus", false);
10605 })
10606 );
10607 }
10608 setup(combobox, () => {
10609 if (!tag) return;
10610 return chain(
10611 sync(combobox, ["selectedValue"], (state) => {
10612 if (!Array.isArray(state.selectedValue)) return;
10613 tag.setValues(state.selectedValue);
10614 }),
10615 sync(tag, ["values"], (state) => {
10616 combobox.setState("selectedValue", state.values);
10617 })
10618 );
10619 });
10620 setup(
10621 combobox,
10622 () => sync(combobox, ["resetValueOnHide", "mounted"], (state) => {
10623 if (!state.resetValueOnHide) return;
10624 if (state.mounted) return;
10625 combobox.setState("value", value);
10626 })
10627 );
10628 setup(
10629 combobox,
10630 () => sync(combobox, ["open"], (state) => {
10631 if (state.open) return;
10632 combobox.setState("activeId", activeId);
10633 combobox.setState("moves", 0);
10634 })
10635 );
10636 setup(
10637 combobox,
10638 () => sync(combobox, ["moves", "activeId"], (state, prevState) => {
10639 if (state.moves === prevState.moves) {
10640 combobox.setState("activeValue", void 0);
10641 }
10642 })
10643 );
10644 setup(
10645 combobox,
10646 () => batch(combobox, ["moves", "renderedItems"], (state, prev) => {
10647 if (state.moves === prev.moves) return;
10648 const { activeId: activeId2 } = combobox.getState();
10649 const activeItem = composite.item(activeId2);
10650 combobox.setState("activeValue", activeItem == null ? void 0 : activeItem.value);
10651 })
10652 );
10653 return {
10654 ...popover,
10655 ...composite,
10656 ...combobox,
10657 tag,
10658 setValue: (value2) => combobox.setState("value", value2),
10659 resetValue: () => combobox.setState("value", initialState.value),
10660 setSelectedValue: (selectedValue2) => combobox.setState("selectedValue", selectedValue2)
10661 };
10662 }
10663
10664 // node_modules/@ariakit/react-core/esm/__chunks/SVN33SY6.js
10665 function useComboboxStoreOptions(props) {
10666 const tag = useTagContext();
10667 props = {
10668 ...props,
10669 tag: props.tag !== void 0 ? props.tag : tag
10670 };
10671 return useCompositeStoreOptions(props);
10672 }
10673 function useComboboxStoreProps(store, update2, props) {
10674 useUpdateEffect(update2, [props.tag]);
10675 useStoreProps(store, props, "value", "setValue");
10676 useStoreProps(store, props, "selectedValue", "setSelectedValue");
10677 useStoreProps(store, props, "resetValueOnHide");
10678 useStoreProps(store, props, "resetValueOnSelect");
10679 return Object.assign(
10680 useCompositeStoreProps(
10681 usePopoverStoreProps(store, update2, props),
10682 update2,
10683 props
10684 ),
10685 { tag: props.tag }
10686 );
10687 }
10688 function useComboboxStore(props = {}) {
10689 props = useComboboxStoreOptions(props);
10690 const [store, update2] = useStore(createComboboxStore, props);
10691 return useComboboxStoreProps(store, update2, props);
10692 }
10693
10694 // node_modules/@ariakit/react-core/esm/combobox/combobox-provider.js
10695 var import_jsx_runtime61 = __toESM(require_jsx_runtime(), 1);
10696 function ComboboxProvider(props = {}) {
10697 const store = useComboboxStore(props);
10698 return /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(ComboboxContextProvider, { value: store, children: props.children });
10699 }
10700
10701 // packages/dataviews/build-module/components/dataviews-filters/search-widget.mjs
10702 var import_remove_accents = __toESM(require_remove_accents(), 1);
10703 var import_compose7 = __toESM(require_compose(), 1);
10704 var import_i18n28 = __toESM(require_i18n(), 1);
10705 var import_element27 = __toESM(require_element(), 1);
10706 var import_components18 = __toESM(require_components(), 1);
10707
10708 // packages/dataviews/build-module/components/dataviews-filters/utils.mjs
10709 var EMPTY_ARRAY3 = [];
10710 var getCurrentValue = (filterDefinition, currentFilter) => {
10711 if (filterDefinition.singleSelection) {
10712 return currentFilter?.value;
10713 }
10714 if (Array.isArray(currentFilter?.value)) {
10715 return currentFilter.value;
10716 }
10717 if (!Array.isArray(currentFilter?.value) && !!currentFilter?.value) {
10718 return [currentFilter.value];
10719 }
10720 return EMPTY_ARRAY3;
10721 };
10722
10723 // packages/dataviews/build-module/hooks/use-elements.mjs
10724 var import_element26 = __toESM(require_element(), 1);
10725 var EMPTY_ARRAY4 = [];
10726 function useElements({
10727 elements,
10728 getElements
10729 }) {
10730 const staticElements = Array.isArray(elements) && elements.length > 0 ? elements : EMPTY_ARRAY4;
10731 const [records, setRecords] = (0, import_element26.useState)(staticElements);
10732 const [isLoading, setIsLoading] = (0, import_element26.useState)(false);
10733 (0, import_element26.useEffect)(() => {
10734 if (!getElements) {
10735 setRecords(staticElements);
10736 return;
10737 }
10738 let cancelled = false;
10739 setIsLoading(true);
10740 getElements().then((fetchedElements) => {
10741 if (!cancelled) {
10742 const dynamicElements = Array.isArray(fetchedElements) && fetchedElements.length > 0 ? fetchedElements : staticElements;
10743 setRecords(dynamicElements);
10744 }
10745 }).catch(() => {
10746 if (!cancelled) {
10747 setRecords(staticElements);
10748 }
10749 }).finally(() => {
10750 if (!cancelled) {
10751 setIsLoading(false);
10752 }
10753 });
10754 return () => {
10755 cancelled = true;
10756 };
10757 }, [getElements, staticElements]);
10758 return {
10759 elements: records,
10760 isLoading
10761 };
10762 }
10763
10764 // packages/dataviews/build-module/components/dataviews-filters/search-widget.mjs
10765 var import_jsx_runtime62 = __toESM(require_jsx_runtime(), 1);
10766 function normalizeSearchInput(input = "") {
10767 return (0, import_remove_accents.default)(input.trim().toLowerCase());
10768 }
10769 var getNewValue = (filterDefinition, currentFilter, value) => {
10770 if (filterDefinition.singleSelection) {
10771 return value;
10772 }
10773 if (Array.isArray(currentFilter?.value)) {
10774 return currentFilter.value.includes(value) ? currentFilter.value.filter((v2) => v2 !== value) : [...currentFilter.value, value];
10775 }
10776 return [value];
10777 };
10778 function generateFilterElementCompositeItemId(prefix, filterElementValue) {
10779 return `${prefix}-${filterElementValue}`;
10780 }
10781 var MultiSelectionOption = ({ selected }) => {
10782 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10783 "span",
10784 {
10785 className: clsx_default(
10786 "dataviews-filters__search-widget-listitem-multi-selection",
10787 { "is-selected": selected }
10788 ),
10789 children: selected && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components18.Icon, { icon: check_default })
10790 }
10791 );
10792 };
10793 var SingleSelectionOption = ({ selected }) => {
10794 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10795 "span",
10796 {
10797 className: clsx_default(
10798 "dataviews-filters__search-widget-listitem-single-selection",
10799 { "is-selected": selected }
10800 )
10801 }
10802 );
10803 };
10804 function ListBox({ view, filter, onChangeView }) {
10805 const baseId = (0, import_compose7.useInstanceId)(ListBox, "dataviews-filter-list-box");
10806 const [activeCompositeId, setActiveCompositeId] = (0, import_element27.useState)(
10807 // When there are one or less operators, the first item is set as active
10808 // (by setting the initial `activeId` to `undefined`).
10809 // With 2 or more operators, the focus is moved on the operators control
10810 // (by setting the initial `activeId` to `null`), meaning that there won't
10811 // be an active item initially. Focus is then managed via the
10812 // `onFocusVisible` callback.
10813 filter.operators?.length === 1 ? void 0 : null
10814 );
10815 const currentFilter = view.filters?.find(
10816 (f2) => f2.field === filter.field
10817 );
10818 const currentValue = getCurrentValue(filter, currentFilter);
10819 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10820 import_components18.Composite,
10821 {
10822 virtualFocus: true,
10823 focusLoop: true,
10824 activeId: activeCompositeId,
10825 setActiveId: setActiveCompositeId,
10826 role: "listbox",
10827 className: "dataviews-filters__search-widget-listbox",
10828 "aria-label": (0, import_i18n28.sprintf)(
10829 /* translators: List of items for a filter. 1: Filter name. e.g.: "List of: Author". */
10830 (0, import_i18n28.__)("List of: %1$s"),
10831 filter.name
10832 ),
10833 onFocusVisible: () => {
10834 if (!activeCompositeId && filter.elements.length) {
10835 setActiveCompositeId(
10836 generateFilterElementCompositeItemId(
10837 baseId,
10838 filter.elements[0].value
10839 )
10840 );
10841 }
10842 },
10843 render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components18.Composite.Typeahead, {}),
10844 children: filter.elements.map((element) => /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10845 import_components18.Composite.Hover,
10846 {
10847 render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10848 import_components18.Composite.Item,
10849 {
10850 id: generateFilterElementCompositeItemId(
10851 baseId,
10852 element.value
10853 ),
10854 render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10855 "div",
10856 {
10857 "aria-label": element.label,
10858 role: "option",
10859 className: "dataviews-filters__search-widget-listitem"
10860 }
10861 ),
10862 onClick: () => {
10863 const newFilters = currentFilter ? [
10864 ...(view.filters ?? []).map(
10865 (_filter) => {
10866 if (_filter.field === filter.field) {
10867 return {
10868 ..._filter,
10869 operator: currentFilter.operator || filter.operators[0],
10870 value: getNewValue(
10871 filter,
10872 currentFilter,
10873 element.value
10874 )
10875 };
10876 }
10877 return _filter;
10878 }
10879 )
10880 ] : [
10881 ...view.filters ?? [],
10882 {
10883 field: filter.field,
10884 operator: filter.operators[0],
10885 value: getNewValue(
10886 filter,
10887 currentFilter,
10888 element.value
10889 )
10890 }
10891 ];
10892 onChangeView({
10893 ...view,
10894 page: 1,
10895 filters: newFilters
10896 });
10897 }
10898 }
10899 ),
10900 children: [
10901 filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10902 SingleSelectionOption,
10903 {
10904 selected: currentValue === element.value
10905 }
10906 ),
10907 !filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10908 MultiSelectionOption,
10909 {
10910 selected: currentValue.includes(element.value)
10911 }
10912 ),
10913 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10914 "span",
10915 {
10916 className: "dataviews-filters__search-widget-listitem-value",
10917 title: element.label,
10918 children: element.label
10919 }
10920 )
10921 ]
10922 },
10923 element.value
10924 ))
10925 }
10926 );
10927 }
10928 function ComboboxList22({ view, filter, onChangeView }) {
10929 const [searchValue, setSearchValue] = (0, import_element27.useState)("");
10930 const deferredSearchValue = (0, import_element27.useDeferredValue)(searchValue);
10931 const currentFilter = view.filters?.find(
10932 (_filter) => _filter.field === filter.field
10933 );
10934 const currentValue = getCurrentValue(filter, currentFilter);
10935 const matches = (0, import_element27.useMemo)(() => {
10936 const normalizedSearch = normalizeSearchInput(deferredSearchValue);
10937 return filter.elements.filter(
10938 (item) => normalizeSearchInput(item.label).includes(normalizedSearch)
10939 );
10940 }, [filter.elements, deferredSearchValue]);
10941 return /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10942 ComboboxProvider,
10943 {
10944 selectedValue: currentValue,
10945 setSelectedValue: (value) => {
10946 const newFilters = currentFilter ? [
10947 ...(view.filters ?? []).map((_filter) => {
10948 if (_filter.field === filter.field) {
10949 return {
10950 ..._filter,
10951 operator: currentFilter.operator || filter.operators[0],
10952 value
10953 };
10954 }
10955 return _filter;
10956 })
10957 ] : [
10958 ...view.filters ?? [],
10959 {
10960 field: filter.field,
10961 operator: filter.operators[0],
10962 value
10963 }
10964 ];
10965 onChangeView({
10966 ...view,
10967 page: 1,
10968 filters: newFilters
10969 });
10970 },
10971 setValue: setSearchValue,
10972 children: [
10973 /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)("div", { className: "dataviews-filters__search-widget-filter-combobox__wrapper", children: [
10974 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(VisuallyHidden, { render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(ComboboxLabel, {}), children: (0, import_i18n28.__)("Search items") }),
10975 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10976 Combobox,
10977 {
10978 autoSelect: "always",
10979 placeholder: (0, import_i18n28.__)("Search"),
10980 className: "dataviews-filters__search-widget-filter-combobox__input"
10981 }
10982 ),
10983 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("div", { className: "dataviews-filters__search-widget-filter-combobox__icon", children: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components18.Icon, { icon: search_default }) })
10984 ] }),
10985 /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10986 ComboboxList,
10987 {
10988 className: "dataviews-filters__search-widget-filter-combobox-list",
10989 alwaysVisible: true,
10990 children: [
10991 matches.map((element) => {
10992 return /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10993 ComboboxItem,
10994 {
10995 resetValueOnSelect: false,
10996 value: element.value,
10997 className: "dataviews-filters__search-widget-listitem",
10998 hideOnClick: false,
10999 setValueOnClick: false,
11000 focusOnHover: true,
11001 children: [
11002 filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
11003 SingleSelectionOption,
11004 {
11005 selected: currentValue === element.value
11006 }
11007 ),
11008 !filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
11009 MultiSelectionOption,
11010 {
11011 selected: currentValue.includes(
11012 element.value
11013 )
11014 }
11015 ),
11016 /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
11017 "span",
11018 {
11019 className: "dataviews-filters__search-widget-listitem-value",
11020 title: element.label,
11021 children: [
11022 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
11023 ComboboxItemValue,
11024 {
11025 className: "dataviews-filters__search-widget-filter-combobox-item-value",
11026 value: element.label
11027 }
11028 ),
11029 !!element.description && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("span", { className: "dataviews-filters__search-widget-listitem-description", children: element.description })
11030 ]
11031 }
11032 )
11033 ]
11034 },
11035 element.value
11036 );
11037 }),
11038 !matches.length && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("p", { children: (0, import_i18n28.__)("No results found") })
11039 ]
11040 }
11041 )
11042 ]
11043 }
11044 );
11045 }
11046 function SearchWidget(props) {
11047 const { elements, isLoading } = useElements({
11048 elements: props.filter.elements,
11049 getElements: props.filter.getElements
11050 });
11051 if (isLoading) {
11052 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("div", { className: "dataviews-filters__search-widget-no-elements", children: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components18.Spinner, {}) });
11053 }
11054 if (elements.length === 0) {
11055 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("div", { className: "dataviews-filters__search-widget-no-elements", children: (0, import_i18n28.__)("No elements found") });
11056 }
11057 const Widget = elements.length > 10 ? ComboboxList22 : ListBox;
11058 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(Widget, { ...props, filter: { ...props.filter, elements } });
11059 }
11060
11061 // packages/dataviews/build-module/components/dataviews-filters/input-widget.mjs
11062 var import_es6 = __toESM(require_es6(), 1);
11063 var import_compose8 = __toESM(require_compose(), 1);
11064 var import_element28 = __toESM(require_element(), 1);
11065 var import_components19 = __toESM(require_components(), 1);
11066 var import_jsx_runtime63 = __toESM(require_jsx_runtime(), 1);
11067 function InputWidget({
11068 filter,
11069 view,
11070 onChangeView,
11071 fields
11072 }) {
11073 const currentFilter = view.filters?.find(
11074 (f2) => f2.field === filter.field
11075 );
11076 const currentValue = getCurrentValue(filter, currentFilter);
11077 const field = (0, import_element28.useMemo)(() => {
11078 const currentField = fields.find((f2) => f2.id === filter.field);
11079 if (currentField) {
11080 return {
11081 ...currentField,
11082 // Deactivate validation for filters.
11083 isValid: {},
11084 // Filter controls are always enabled.
11085 isDisabled: () => false,
11086 // Filter controls are always visible.
11087 isVisible: () => true,
11088 // Configure getValue/setValue as if Item was a plain object.
11089 getValue: ({ item }) => item[currentField.id],
11090 setValue: ({ value }) => ({
11091 [currentField.id]: value
11092 })
11093 };
11094 }
11095 return currentField;
11096 }, [fields, filter.field]);
11097 const data = (0, import_element28.useMemo)(() => {
11098 return (view.filters ?? []).reduce(
11099 (acc, activeFilter) => {
11100 acc[activeFilter.field] = activeFilter.value;
11101 return acc;
11102 },
11103 {}
11104 );
11105 }, [view.filters]);
11106 const handleChange = (0, import_compose8.useEvent)((updatedData) => {
11107 if (!field || !currentFilter) {
11108 return;
11109 }
11110 const nextValue = field.getValue({ item: updatedData });
11111 if ((0, import_es6.default)(nextValue, currentValue)) {
11112 return;
11113 }
11114 onChangeView({
11115 ...view,
11116 filters: (view.filters ?? []).map(
11117 (_filter) => _filter.field === filter.field ? {
11118 ..._filter,
11119 operator: currentFilter.operator || filter.operators[0],
11120 // Consider empty strings as undefined:
11121 //
11122 // - undefined as value means the filter is unset: the filter widget displays no value and the search returns all records
11123 // - empty string as value means "search empty string": returns only the records that have an empty string as value
11124 //
11125 // In practice, this means the filter will not be able to find an empty string as the value.
11126 value: nextValue === "" ? void 0 : nextValue
11127 } : _filter
11128 )
11129 });
11130 });
11131 if (!field || !field.Edit || !currentFilter) {
11132 return null;
11133 }
11134 return /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
11135 import_components19.Flex,
11136 {
11137 className: "dataviews-filters__user-input-widget",
11138 gap: 2.5,
11139 direction: "column",
11140 children: /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
11141 field.Edit,
11142 {
11143 hideLabelFromVision: true,
11144 data,
11145 field,
11146 operator: currentFilter.operator,
11147 onChange: handleChange
11148 }
11149 )
11150 }
11151 );
11152 }
11153
11154 // node_modules/date-fns/constants.js
11155 var daysInYear = 365.2425;
11156 var maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1e3;
11157 var minTime = -maxTime;
11158 var millisecondsInWeek = 6048e5;
11159 var millisecondsInDay = 864e5;
11160 var secondsInHour = 3600;
11161 var secondsInDay = secondsInHour * 24;
11162 var secondsInWeek = secondsInDay * 7;
11163 var secondsInYear = secondsInDay * daysInYear;
11164 var secondsInMonth = secondsInYear / 12;
11165 var secondsInQuarter = secondsInMonth * 3;
11166 var constructFromSymbol = /* @__PURE__ */ Symbol.for("constructDateFrom");
11167
11168 // node_modules/date-fns/constructFrom.js
11169 function constructFrom(date, value) {
11170 if (typeof date === "function") return date(value);
11171 if (date && typeof date === "object" && constructFromSymbol in date)
11172 return date[constructFromSymbol](value);
11173 if (date instanceof Date) return new date.constructor(value);
11174 return new Date(value);
11175 }
11176
11177 // node_modules/date-fns/toDate.js
11178 function toDate(argument, context) {
11179 return constructFrom(context || argument, argument);
11180 }
11181
11182 // node_modules/date-fns/addDays.js
11183 function addDays(date, amount, options) {
11184 const _date = toDate(date, options?.in);
11185 if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
11186 if (!amount) return _date;
11187 _date.setDate(_date.getDate() + amount);
11188 return _date;
11189 }
11190
11191 // node_modules/date-fns/addMonths.js
11192 function addMonths(date, amount, options) {
11193 const _date = toDate(date, options?.in);
11194 if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
11195 if (!amount) {
11196 return _date;
11197 }
11198 const dayOfMonth = _date.getDate();
11199 const endOfDesiredMonth = constructFrom(options?.in || date, _date.getTime());
11200 endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0);
11201 const daysInMonth = endOfDesiredMonth.getDate();
11202 if (dayOfMonth >= daysInMonth) {
11203 return endOfDesiredMonth;
11204 } else {
11205 _date.setFullYear(
11206 endOfDesiredMonth.getFullYear(),
11207 endOfDesiredMonth.getMonth(),
11208 dayOfMonth
11209 );
11210 return _date;
11211 }
11212 }
11213
11214 // node_modules/date-fns/_lib/defaultOptions.js
11215 var defaultOptions = {};
11216 function getDefaultOptions() {
11217 return defaultOptions;
11218 }
11219
11220 // node_modules/date-fns/startOfWeek.js
11221 function startOfWeek(date, options) {
11222 const defaultOptions2 = getDefaultOptions();
11223 const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
11224 const _date = toDate(date, options?.in);
11225 const day = _date.getDay();
11226 const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
11227 _date.setDate(_date.getDate() - diff);
11228 _date.setHours(0, 0, 0, 0);
11229 return _date;
11230 }
11231
11232 // node_modules/date-fns/startOfISOWeek.js
11233 function startOfISOWeek(date, options) {
11234 return startOfWeek(date, { ...options, weekStartsOn: 1 });
11235 }
11236
11237 // node_modules/date-fns/getISOWeekYear.js
11238 function getISOWeekYear(date, options) {
11239 const _date = toDate(date, options?.in);
11240 const year = _date.getFullYear();
11241 const fourthOfJanuaryOfNextYear = constructFrom(_date, 0);
11242 fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
11243 fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
11244 const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
11245 const fourthOfJanuaryOfThisYear = constructFrom(_date, 0);
11246 fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
11247 fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
11248 const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
11249 if (_date.getTime() >= startOfNextYear.getTime()) {
11250 return year + 1;
11251 } else if (_date.getTime() >= startOfThisYear.getTime()) {
11252 return year;
11253 } else {
11254 return year - 1;
11255 }
11256 }
11257
11258 // node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.js
11259 function getTimezoneOffsetInMilliseconds(date) {
11260 const _date = toDate(date);
11261 const utcDate = new Date(
11262 Date.UTC(
11263 _date.getFullYear(),
11264 _date.getMonth(),
11265 _date.getDate(),
11266 _date.getHours(),
11267 _date.getMinutes(),
11268 _date.getSeconds(),
11269 _date.getMilliseconds()
11270 )
11271 );
11272 utcDate.setUTCFullYear(_date.getFullYear());
11273 return +date - +utcDate;
11274 }
11275
11276 // node_modules/date-fns/_lib/normalizeDates.js
11277 function normalizeDates(context, ...dates) {
11278 const normalize = constructFrom.bind(
11279 null,
11280 context || dates.find((date) => typeof date === "object")
11281 );
11282 return dates.map(normalize);
11283 }
11284
11285 // node_modules/date-fns/startOfDay.js
11286 function startOfDay(date, options) {
11287 const _date = toDate(date, options?.in);
11288 _date.setHours(0, 0, 0, 0);
11289 return _date;
11290 }
11291
11292 // node_modules/date-fns/differenceInCalendarDays.js
11293 function differenceInCalendarDays(laterDate, earlierDate, options) {
11294 const [laterDate_, earlierDate_] = normalizeDates(
11295 options?.in,
11296 laterDate,
11297 earlierDate
11298 );
11299 const laterStartOfDay = startOfDay(laterDate_);
11300 const earlierStartOfDay = startOfDay(earlierDate_);
11301 const laterTimestamp = +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
11302 const earlierTimestamp = +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
11303 return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
11304 }
11305
11306 // node_modules/date-fns/startOfISOWeekYear.js
11307 function startOfISOWeekYear(date, options) {
11308 const year = getISOWeekYear(date, options);
11309 const fourthOfJanuary = constructFrom(options?.in || date, 0);
11310 fourthOfJanuary.setFullYear(year, 0, 4);
11311 fourthOfJanuary.setHours(0, 0, 0, 0);
11312 return startOfISOWeek(fourthOfJanuary);
11313 }
11314
11315 // node_modules/date-fns/addWeeks.js
11316 function addWeeks(date, amount, options) {
11317 return addDays(date, amount * 7, options);
11318 }
11319
11320 // node_modules/date-fns/addYears.js
11321 function addYears(date, amount, options) {
11322 return addMonths(date, amount * 12, options);
11323 }
11324
11325 // node_modules/date-fns/isDate.js
11326 function isDate(value) {
11327 return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
11328 }
11329
11330 // node_modules/date-fns/isValid.js
11331 function isValid(date) {
11332 return !(!isDate(date) && typeof date !== "number" || isNaN(+toDate(date)));
11333 }
11334
11335 // node_modules/date-fns/startOfMonth.js
11336 function startOfMonth(date, options) {
11337 const _date = toDate(date, options?.in);
11338 _date.setDate(1);
11339 _date.setHours(0, 0, 0, 0);
11340 return _date;
11341 }
11342
11343 // node_modules/date-fns/startOfYear.js
11344 function startOfYear(date, options) {
11345 const date_ = toDate(date, options?.in);
11346 date_.setFullYear(date_.getFullYear(), 0, 1);
11347 date_.setHours(0, 0, 0, 0);
11348 return date_;
11349 }
11350
11351 // node_modules/date-fns/locale/en-US/_lib/formatDistance.js
11352 var formatDistanceLocale = {
11353 lessThanXSeconds: {
11354 one: "less than a second",
11355 other: "less than {{count}} seconds"
11356 },
11357 xSeconds: {
11358 one: "1 second",
11359 other: "{{count}} seconds"
11360 },
11361 halfAMinute: "half a minute",
11362 lessThanXMinutes: {
11363 one: "less than a minute",
11364 other: "less than {{count}} minutes"
11365 },
11366 xMinutes: {
11367 one: "1 minute",
11368 other: "{{count}} minutes"
11369 },
11370 aboutXHours: {
11371 one: "about 1 hour",
11372 other: "about {{count}} hours"
11373 },
11374 xHours: {
11375 one: "1 hour",
11376 other: "{{count}} hours"
11377 },
11378 xDays: {
11379 one: "1 day",
11380 other: "{{count}} days"
11381 },
11382 aboutXWeeks: {
11383 one: "about 1 week",
11384 other: "about {{count}} weeks"
11385 },
11386 xWeeks: {
11387 one: "1 week",
11388 other: "{{count}} weeks"
11389 },
11390 aboutXMonths: {
11391 one: "about 1 month",
11392 other: "about {{count}} months"
11393 },
11394 xMonths: {
11395 one: "1 month",
11396 other: "{{count}} months"
11397 },
11398 aboutXYears: {
11399 one: "about 1 year",
11400 other: "about {{count}} years"
11401 },
11402 xYears: {
11403 one: "1 year",
11404 other: "{{count}} years"
11405 },
11406 overXYears: {
11407 one: "over 1 year",
11408 other: "over {{count}} years"
11409 },
11410 almostXYears: {
11411 one: "almost 1 year",
11412 other: "almost {{count}} years"
11413 }
11414 };
11415 var formatDistance = (token, count, options) => {
11416 let result;
11417 const tokenValue = formatDistanceLocale[token];
11418 if (typeof tokenValue === "string") {
11419 result = tokenValue;
11420 } else if (count === 1) {
11421 result = tokenValue.one;
11422 } else {
11423 result = tokenValue.other.replace("{{count}}", count.toString());
11424 }
11425 if (options?.addSuffix) {
11426 if (options.comparison && options.comparison > 0) {
11427 return "in " + result;
11428 } else {
11429 return result + " ago";
11430 }
11431 }
11432 return result;
11433 };
11434
11435 // node_modules/date-fns/locale/_lib/buildFormatLongFn.js
11436 function buildFormatLongFn(args) {
11437 return (options = {}) => {
11438 const width = options.width ? String(options.width) : args.defaultWidth;
11439 const format6 = args.formats[width] || args.formats[args.defaultWidth];
11440 return format6;
11441 };
11442 }
11443
11444 // node_modules/date-fns/locale/en-US/_lib/formatLong.js
11445 var dateFormats = {
11446 full: "EEEE, MMMM do, y",
11447 long: "MMMM do, y",
11448 medium: "MMM d, y",
11449 short: "MM/dd/yyyy"
11450 };
11451 var timeFormats = {
11452 full: "h:mm:ss a zzzz",
11453 long: "h:mm:ss a z",
11454 medium: "h:mm:ss a",
11455 short: "h:mm a"
11456 };
11457 var dateTimeFormats = {
11458 full: "{{date}} 'at' {{time}}",
11459 long: "{{date}} 'at' {{time}}",
11460 medium: "{{date}}, {{time}}",
11461 short: "{{date}}, {{time}}"
11462 };
11463 var formatLong = {
11464 date: buildFormatLongFn({
11465 formats: dateFormats,
11466 defaultWidth: "full"
11467 }),
11468 time: buildFormatLongFn({
11469 formats: timeFormats,
11470 defaultWidth: "full"
11471 }),
11472 dateTime: buildFormatLongFn({
11473 formats: dateTimeFormats,
11474 defaultWidth: "full"
11475 })
11476 };
11477
11478 // node_modules/date-fns/locale/en-US/_lib/formatRelative.js
11479 var formatRelativeLocale = {
11480 lastWeek: "'last' eeee 'at' p",
11481 yesterday: "'yesterday at' p",
11482 today: "'today at' p",
11483 tomorrow: "'tomorrow at' p",
11484 nextWeek: "eeee 'at' p",
11485 other: "P"
11486 };
11487 var formatRelative = (token, _date, _baseDate, _options) => formatRelativeLocale[token];
11488
11489 // node_modules/date-fns/locale/_lib/buildLocalizeFn.js
11490 function buildLocalizeFn(args) {
11491 return (value, options) => {
11492 const context = options?.context ? String(options.context) : "standalone";
11493 let valuesArray;
11494 if (context === "formatting" && args.formattingValues) {
11495 const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
11496 const width = options?.width ? String(options.width) : defaultWidth;
11497 valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
11498 } else {
11499 const defaultWidth = args.defaultWidth;
11500 const width = options?.width ? String(options.width) : args.defaultWidth;
11501 valuesArray = args.values[width] || args.values[defaultWidth];
11502 }
11503 const index = args.argumentCallback ? args.argumentCallback(value) : value;
11504 return valuesArray[index];
11505 };
11506 }
11507
11508 // node_modules/date-fns/locale/en-US/_lib/localize.js
11509 var eraValues = {
11510 narrow: ["B", "A"],
11511 abbreviated: ["BC", "AD"],
11512 wide: ["Before Christ", "Anno Domini"]
11513 };
11514 var quarterValues = {
11515 narrow: ["1", "2", "3", "4"],
11516 abbreviated: ["Q1", "Q2", "Q3", "Q4"],
11517 wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"]
11518 };
11519 var monthValues = {
11520 narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
11521 abbreviated: [
11522 "Jan",
11523 "Feb",
11524 "Mar",
11525 "Apr",
11526 "May",
11527 "Jun",
11528 "Jul",
11529 "Aug",
11530 "Sep",
11531 "Oct",
11532 "Nov",
11533 "Dec"
11534 ],
11535 wide: [
11536 "January",
11537 "February",
11538 "March",
11539 "April",
11540 "May",
11541 "June",
11542 "July",
11543 "August",
11544 "September",
11545 "October",
11546 "November",
11547 "December"
11548 ]
11549 };
11550 var dayValues = {
11551 narrow: ["S", "M", "T", "W", "T", "F", "S"],
11552 short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
11553 abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
11554 wide: [
11555 "Sunday",
11556 "Monday",
11557 "Tuesday",
11558 "Wednesday",
11559 "Thursday",
11560 "Friday",
11561 "Saturday"
11562 ]
11563 };
11564 var dayPeriodValues = {
11565 narrow: {
11566 am: "a",
11567 pm: "p",
11568 midnight: "mi",
11569 noon: "n",
11570 morning: "morning",
11571 afternoon: "afternoon",
11572 evening: "evening",
11573 night: "night"
11574 },
11575 abbreviated: {
11576 am: "AM",
11577 pm: "PM",
11578 midnight: "midnight",
11579 noon: "noon",
11580 morning: "morning",
11581 afternoon: "afternoon",
11582 evening: "evening",
11583 night: "night"
11584 },
11585 wide: {
11586 am: "a.m.",
11587 pm: "p.m.",
11588 midnight: "midnight",
11589 noon: "noon",
11590 morning: "morning",
11591 afternoon: "afternoon",
11592 evening: "evening",
11593 night: "night"
11594 }
11595 };
11596 var formattingDayPeriodValues = {
11597 narrow: {
11598 am: "a",
11599 pm: "p",
11600 midnight: "mi",
11601 noon: "n",
11602 morning: "in the morning",
11603 afternoon: "in the afternoon",
11604 evening: "in the evening",
11605 night: "at night"
11606 },
11607 abbreviated: {
11608 am: "AM",
11609 pm: "PM",
11610 midnight: "midnight",
11611 noon: "noon",
11612 morning: "in the morning",
11613 afternoon: "in the afternoon",
11614 evening: "in the evening",
11615 night: "at night"
11616 },
11617 wide: {
11618 am: "a.m.",
11619 pm: "p.m.",
11620 midnight: "midnight",
11621 noon: "noon",
11622 morning: "in the morning",
11623 afternoon: "in the afternoon",
11624 evening: "in the evening",
11625 night: "at night"
11626 }
11627 };
11628 var ordinalNumber = (dirtyNumber, _options) => {
11629 const number = Number(dirtyNumber);
11630 const rem100 = number % 100;
11631 if (rem100 > 20 || rem100 < 10) {
11632 switch (rem100 % 10) {
11633 case 1:
11634 return number + "st";
11635 case 2:
11636 return number + "nd";
11637 case 3:
11638 return number + "rd";
11639 }
11640 }
11641 return number + "th";
11642 };
11643 var localize = {
11644 ordinalNumber,
11645 era: buildLocalizeFn({
11646 values: eraValues,
11647 defaultWidth: "wide"
11648 }),
11649 quarter: buildLocalizeFn({
11650 values: quarterValues,
11651 defaultWidth: "wide",
11652 argumentCallback: (quarter) => quarter - 1
11653 }),
11654 month: buildLocalizeFn({
11655 values: monthValues,
11656 defaultWidth: "wide"
11657 }),
11658 day: buildLocalizeFn({
11659 values: dayValues,
11660 defaultWidth: "wide"
11661 }),
11662 dayPeriod: buildLocalizeFn({
11663 values: dayPeriodValues,
11664 defaultWidth: "wide",
11665 formattingValues: formattingDayPeriodValues,
11666 defaultFormattingWidth: "wide"
11667 })
11668 };
11669
11670 // node_modules/date-fns/locale/_lib/buildMatchFn.js
11671 function buildMatchFn(args) {
11672 return (string, options = {}) => {
11673 const width = options.width;
11674 const matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
11675 const matchResult = string.match(matchPattern);
11676 if (!matchResult) {
11677 return null;
11678 }
11679 const matchedString = matchResult[0];
11680 const parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
11681 const key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString)) : (
11682 // [TODO] -- I challenge you to fix the type
11683 findKey(parsePatterns, (pattern) => pattern.test(matchedString))
11684 );
11685 let value;
11686 value = args.valueCallback ? args.valueCallback(key) : key;
11687 value = options.valueCallback ? (
11688 // [TODO] -- I challenge you to fix the type
11689 options.valueCallback(value)
11690 ) : value;
11691 const rest = string.slice(matchedString.length);
11692 return { value, rest };
11693 };
11694 }
11695 function findKey(object, predicate) {
11696 for (const key in object) {
11697 if (Object.prototype.hasOwnProperty.call(object, key) && predicate(object[key])) {
11698 return key;
11699 }
11700 }
11701 return void 0;
11702 }
11703 function findIndex(array, predicate) {
11704 for (let key = 0; key < array.length; key++) {
11705 if (predicate(array[key])) {
11706 return key;
11707 }
11708 }
11709 return void 0;
11710 }
11711
11712 // node_modules/date-fns/locale/_lib/buildMatchPatternFn.js
11713 function buildMatchPatternFn(args) {
11714 return (string, options = {}) => {
11715 const matchResult = string.match(args.matchPattern);
11716 if (!matchResult) return null;
11717 const matchedString = matchResult[0];
11718 const parseResult = string.match(args.parsePattern);
11719 if (!parseResult) return null;
11720 let value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
11721 value = options.valueCallback ? options.valueCallback(value) : value;
11722 const rest = string.slice(matchedString.length);
11723 return { value, rest };
11724 };
11725 }
11726
11727 // node_modules/date-fns/locale/en-US/_lib/match.js
11728 var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
11729 var parseOrdinalNumberPattern = /\d+/i;
11730 var matchEraPatterns = {
11731 narrow: /^(b|a)/i,
11732 abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
11733 wide: /^(before christ|before common era|anno domini|common era)/i
11734 };
11735 var parseEraPatterns = {
11736 any: [/^b/i, /^(a|c)/i]
11737 };
11738 var matchQuarterPatterns = {
11739 narrow: /^[1234]/i,
11740 abbreviated: /^q[1234]/i,
11741 wide: /^[1234](th|st|nd|rd)? quarter/i
11742 };
11743 var parseQuarterPatterns = {
11744 any: [/1/i, /2/i, /3/i, /4/i]
11745 };
11746 var matchMonthPatterns = {
11747 narrow: /^[jfmasond]/i,
11748 abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
11749 wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
11750 };
11751 var parseMonthPatterns = {
11752 narrow: [
11753 /^j/i,
11754 /^f/i,
11755 /^m/i,
11756 /^a/i,
11757 /^m/i,
11758 /^j/i,
11759 /^j/i,
11760 /^a/i,
11761 /^s/i,
11762 /^o/i,
11763 /^n/i,
11764 /^d/i
11765 ],
11766 any: [
11767 /^ja/i,
11768 /^f/i,
11769 /^mar/i,
11770 /^ap/i,
11771 /^may/i,
11772 /^jun/i,
11773 /^jul/i,
11774 /^au/i,
11775 /^s/i,
11776 /^o/i,
11777 /^n/i,
11778 /^d/i
11779 ]
11780 };
11781 var matchDayPatterns = {
11782 narrow: /^[smtwf]/i,
11783 short: /^(su|mo|tu|we|th|fr|sa)/i,
11784 abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
11785 wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
11786 };
11787 var parseDayPatterns = {
11788 narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
11789 any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
11790 };
11791 var matchDayPeriodPatterns = {
11792 narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
11793 any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
11794 };
11795 var parseDayPeriodPatterns = {
11796 any: {
11797 am: /^a/i,
11798 pm: /^p/i,
11799 midnight: /^mi/i,
11800 noon: /^no/i,
11801 morning: /morning/i,
11802 afternoon: /afternoon/i,
11803 evening: /evening/i,
11804 night: /night/i
11805 }
11806 };
11807 var match = {
11808 ordinalNumber: buildMatchPatternFn({
11809 matchPattern: matchOrdinalNumberPattern,
11810 parsePattern: parseOrdinalNumberPattern,
11811 valueCallback: (value) => parseInt(value, 10)
11812 }),
11813 era: buildMatchFn({
11814 matchPatterns: matchEraPatterns,
11815 defaultMatchWidth: "wide",
11816 parsePatterns: parseEraPatterns,
11817 defaultParseWidth: "any"
11818 }),
11819 quarter: buildMatchFn({
11820 matchPatterns: matchQuarterPatterns,
11821 defaultMatchWidth: "wide",
11822 parsePatterns: parseQuarterPatterns,
11823 defaultParseWidth: "any",
11824 valueCallback: (index) => index + 1
11825 }),
11826 month: buildMatchFn({
11827 matchPatterns: matchMonthPatterns,
11828 defaultMatchWidth: "wide",
11829 parsePatterns: parseMonthPatterns,
11830 defaultParseWidth: "any"
11831 }),
11832 day: buildMatchFn({
11833 matchPatterns: matchDayPatterns,
11834 defaultMatchWidth: "wide",
11835 parsePatterns: parseDayPatterns,
11836 defaultParseWidth: "any"
11837 }),
11838 dayPeriod: buildMatchFn({
11839 matchPatterns: matchDayPeriodPatterns,
11840 defaultMatchWidth: "any",
11841 parsePatterns: parseDayPeriodPatterns,
11842 defaultParseWidth: "any"
11843 })
11844 };
11845
11846 // node_modules/date-fns/locale/en-US.js
11847 var enUS = {
11848 code: "en-US",
11849 formatDistance,
11850 formatLong,
11851 formatRelative,
11852 localize,
11853 match,
11854 options: {
11855 weekStartsOn: 0,
11856 firstWeekContainsDate: 1
11857 }
11858 };
11859
11860 // node_modules/date-fns/getDayOfYear.js
11861 function getDayOfYear(date, options) {
11862 const _date = toDate(date, options?.in);
11863 const diff = differenceInCalendarDays(_date, startOfYear(_date));
11864 const dayOfYear = diff + 1;
11865 return dayOfYear;
11866 }
11867
11868 // node_modules/date-fns/getISOWeek.js
11869 function getISOWeek(date, options) {
11870 const _date = toDate(date, options?.in);
11871 const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
11872 return Math.round(diff / millisecondsInWeek) + 1;
11873 }
11874
11875 // node_modules/date-fns/getWeekYear.js
11876 function getWeekYear(date, options) {
11877 const _date = toDate(date, options?.in);
11878 const year = _date.getFullYear();
11879 const defaultOptions2 = getDefaultOptions();
11880 const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
11881 const firstWeekOfNextYear = constructFrom(options?.in || date, 0);
11882 firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
11883 firstWeekOfNextYear.setHours(0, 0, 0, 0);
11884 const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
11885 const firstWeekOfThisYear = constructFrom(options?.in || date, 0);
11886 firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
11887 firstWeekOfThisYear.setHours(0, 0, 0, 0);
11888 const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
11889 if (+_date >= +startOfNextYear) {
11890 return year + 1;
11891 } else if (+_date >= +startOfThisYear) {
11892 return year;
11893 } else {
11894 return year - 1;
11895 }
11896 }
11897
11898 // node_modules/date-fns/startOfWeekYear.js
11899 function startOfWeekYear(date, options) {
11900 const defaultOptions2 = getDefaultOptions();
11901 const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
11902 const year = getWeekYear(date, options);
11903 const firstWeek = constructFrom(options?.in || date, 0);
11904 firstWeek.setFullYear(year, 0, firstWeekContainsDate);
11905 firstWeek.setHours(0, 0, 0, 0);
11906 const _date = startOfWeek(firstWeek, options);
11907 return _date;
11908 }
11909
11910 // node_modules/date-fns/getWeek.js
11911 function getWeek(date, options) {
11912 const _date = toDate(date, options?.in);
11913 const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
11914 return Math.round(diff / millisecondsInWeek) + 1;
11915 }
11916
11917 // node_modules/date-fns/_lib/addLeadingZeros.js
11918 function addLeadingZeros(number, targetLength) {
11919 const sign = number < 0 ? "-" : "";
11920 const output = Math.abs(number).toString().padStart(targetLength, "0");
11921 return sign + output;
11922 }
11923
11924 // node_modules/date-fns/_lib/format/lightFormatters.js
11925 var lightFormatters = {
11926 // Year
11927 y(date, token) {
11928 const signedYear = date.getFullYear();
11929 const year = signedYear > 0 ? signedYear : 1 - signedYear;
11930 return addLeadingZeros(token === "yy" ? year % 100 : year, token.length);
11931 },
11932 // Month
11933 M(date, token) {
11934 const month = date.getMonth();
11935 return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2);
11936 },
11937 // Day of the month
11938 d(date, token) {
11939 return addLeadingZeros(date.getDate(), token.length);
11940 },
11941 // AM or PM
11942 a(date, token) {
11943 const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am";
11944 switch (token) {
11945 case "a":
11946 case "aa":
11947 return dayPeriodEnumValue.toUpperCase();
11948 case "aaa":
11949 return dayPeriodEnumValue;
11950 case "aaaaa":
11951 return dayPeriodEnumValue[0];
11952 case "aaaa":
11953 default:
11954 return dayPeriodEnumValue === "am" ? "a.m." : "p.m.";
11955 }
11956 },
11957 // Hour [1-12]
11958 h(date, token) {
11959 return addLeadingZeros(date.getHours() % 12 || 12, token.length);
11960 },
11961 // Hour [0-23]
11962 H(date, token) {
11963 return addLeadingZeros(date.getHours(), token.length);
11964 },
11965 // Minute
11966 m(date, token) {
11967 return addLeadingZeros(date.getMinutes(), token.length);
11968 },
11969 // Second
11970 s(date, token) {
11971 return addLeadingZeros(date.getSeconds(), token.length);
11972 },
11973 // Fraction of second
11974 S(date, token) {
11975 const numberOfDigits = token.length;
11976 const milliseconds = date.getMilliseconds();
11977 const fractionalSeconds = Math.trunc(
11978 milliseconds * Math.pow(10, numberOfDigits - 3)
11979 );
11980 return addLeadingZeros(fractionalSeconds, token.length);
11981 }
11982 };
11983
11984 // node_modules/date-fns/_lib/format/formatters.js
11985 var dayPeriodEnum = {
11986 am: "am",
11987 pm: "pm",
11988 midnight: "midnight",
11989 noon: "noon",
11990 morning: "morning",
11991 afternoon: "afternoon",
11992 evening: "evening",
11993 night: "night"
11994 };
11995 var formatters = {
11996 // Era
11997 G: function(date, token, localize2) {
11998 const era = date.getFullYear() > 0 ? 1 : 0;
11999 switch (token) {
12000 // AD, BC
12001 case "G":
12002 case "GG":
12003 case "GGG":
12004 return localize2.era(era, { width: "abbreviated" });
12005 // A, B
12006 case "GGGGG":
12007 return localize2.era(era, { width: "narrow" });
12008 // Anno Domini, Before Christ
12009 case "GGGG":
12010 default:
12011 return localize2.era(era, { width: "wide" });
12012 }
12013 },
12014 // Year
12015 y: function(date, token, localize2) {
12016 if (token === "yo") {
12017 const signedYear = date.getFullYear();
12018 const year = signedYear > 0 ? signedYear : 1 - signedYear;
12019 return localize2.ordinalNumber(year, { unit: "year" });
12020 }
12021 return lightFormatters.y(date, token);
12022 },
12023 // Local week-numbering year
12024 Y: function(date, token, localize2, options) {
12025 const signedWeekYear = getWeekYear(date, options);
12026 const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
12027 if (token === "YY") {
12028 const twoDigitYear = weekYear % 100;
12029 return addLeadingZeros(twoDigitYear, 2);
12030 }
12031 if (token === "Yo") {
12032 return localize2.ordinalNumber(weekYear, { unit: "year" });
12033 }
12034 return addLeadingZeros(weekYear, token.length);
12035 },
12036 // ISO week-numbering year
12037 R: function(date, token) {
12038 const isoWeekYear = getISOWeekYear(date);
12039 return addLeadingZeros(isoWeekYear, token.length);
12040 },
12041 // Extended year. This is a single number designating the year of this calendar system.
12042 // The main difference between `y` and `u` localizers are B.C. years:
12043 // | Year | `y` | `u` |
12044 // |------|-----|-----|
12045 // | AC 1 | 1 | 1 |
12046 // | BC 1 | 1 | 0 |
12047 // | BC 2 | 2 | -1 |
12048 // Also `yy` always returns the last two digits of a year,
12049 // while `uu` pads single digit years to 2 characters and returns other years unchanged.
12050 u: function(date, token) {
12051 const year = date.getFullYear();
12052 return addLeadingZeros(year, token.length);
12053 },
12054 // Quarter
12055 Q: function(date, token, localize2) {
12056 const quarter = Math.ceil((date.getMonth() + 1) / 3);
12057 switch (token) {
12058 // 1, 2, 3, 4
12059 case "Q":
12060 return String(quarter);
12061 // 01, 02, 03, 04
12062 case "QQ":
12063 return addLeadingZeros(quarter, 2);
12064 // 1st, 2nd, 3rd, 4th
12065 case "Qo":
12066 return localize2.ordinalNumber(quarter, { unit: "quarter" });
12067 // Q1, Q2, Q3, Q4
12068 case "QQQ":
12069 return localize2.quarter(quarter, {
12070 width: "abbreviated",
12071 context: "formatting"
12072 });
12073 // 1, 2, 3, 4 (narrow quarter; could be not numerical)
12074 case "QQQQQ":
12075 return localize2.quarter(quarter, {
12076 width: "narrow",
12077 context: "formatting"
12078 });
12079 // 1st quarter, 2nd quarter, ...
12080 case "QQQQ":
12081 default:
12082 return localize2.quarter(quarter, {
12083 width: "wide",
12084 context: "formatting"
12085 });
12086 }
12087 },
12088 // Stand-alone quarter
12089 q: function(date, token, localize2) {
12090 const quarter = Math.ceil((date.getMonth() + 1) / 3);
12091 switch (token) {
12092 // 1, 2, 3, 4
12093 case "q":
12094 return String(quarter);
12095 // 01, 02, 03, 04
12096 case "qq":
12097 return addLeadingZeros(quarter, 2);
12098 // 1st, 2nd, 3rd, 4th
12099 case "qo":
12100 return localize2.ordinalNumber(quarter, { unit: "quarter" });
12101 // Q1, Q2, Q3, Q4
12102 case "qqq":
12103 return localize2.quarter(quarter, {
12104 width: "abbreviated",
12105 context: "standalone"
12106 });
12107 // 1, 2, 3, 4 (narrow quarter; could be not numerical)
12108 case "qqqqq":
12109 return localize2.quarter(quarter, {
12110 width: "narrow",
12111 context: "standalone"
12112 });
12113 // 1st quarter, 2nd quarter, ...
12114 case "qqqq":
12115 default:
12116 return localize2.quarter(quarter, {
12117 width: "wide",
12118 context: "standalone"
12119 });
12120 }
12121 },
12122 // Month
12123 M: function(date, token, localize2) {
12124 const month = date.getMonth();
12125 switch (token) {
12126 case "M":
12127 case "MM":
12128 return lightFormatters.M(date, token);
12129 // 1st, 2nd, ..., 12th
12130 case "Mo":
12131 return localize2.ordinalNumber(month + 1, { unit: "month" });
12132 // Jan, Feb, ..., Dec
12133 case "MMM":
12134 return localize2.month(month, {
12135 width: "abbreviated",
12136 context: "formatting"
12137 });
12138 // J, F, ..., D
12139 case "MMMMM":
12140 return localize2.month(month, {
12141 width: "narrow",
12142 context: "formatting"
12143 });
12144 // January, February, ..., December
12145 case "MMMM":
12146 default:
12147 return localize2.month(month, { width: "wide", context: "formatting" });
12148 }
12149 },
12150 // Stand-alone month
12151 L: function(date, token, localize2) {
12152 const month = date.getMonth();
12153 switch (token) {
12154 // 1, 2, ..., 12
12155 case "L":
12156 return String(month + 1);
12157 // 01, 02, ..., 12
12158 case "LL":
12159 return addLeadingZeros(month + 1, 2);
12160 // 1st, 2nd, ..., 12th
12161 case "Lo":
12162 return localize2.ordinalNumber(month + 1, { unit: "month" });
12163 // Jan, Feb, ..., Dec
12164 case "LLL":
12165 return localize2.month(month, {
12166 width: "abbreviated",
12167 context: "standalone"
12168 });
12169 // J, F, ..., D
12170 case "LLLLL":
12171 return localize2.month(month, {
12172 width: "narrow",
12173 context: "standalone"
12174 });
12175 // January, February, ..., December
12176 case "LLLL":
12177 default:
12178 return localize2.month(month, { width: "wide", context: "standalone" });
12179 }
12180 },
12181 // Local week of year
12182 w: function(date, token, localize2, options) {
12183 const week = getWeek(date, options);
12184 if (token === "wo") {
12185 return localize2.ordinalNumber(week, { unit: "week" });
12186 }
12187 return addLeadingZeros(week, token.length);
12188 },
12189 // ISO week of year
12190 I: function(date, token, localize2) {
12191 const isoWeek = getISOWeek(date);
12192 if (token === "Io") {
12193 return localize2.ordinalNumber(isoWeek, { unit: "week" });
12194 }
12195 return addLeadingZeros(isoWeek, token.length);
12196 },
12197 // Day of the month
12198 d: function(date, token, localize2) {
12199 if (token === "do") {
12200 return localize2.ordinalNumber(date.getDate(), { unit: "date" });
12201 }
12202 return lightFormatters.d(date, token);
12203 },
12204 // Day of year
12205 D: function(date, token, localize2) {
12206 const dayOfYear = getDayOfYear(date);
12207 if (token === "Do") {
12208 return localize2.ordinalNumber(dayOfYear, { unit: "dayOfYear" });
12209 }
12210 return addLeadingZeros(dayOfYear, token.length);
12211 },
12212 // Day of week
12213 E: function(date, token, localize2) {
12214 const dayOfWeek = date.getDay();
12215 switch (token) {
12216 // Tue
12217 case "E":
12218 case "EE":
12219 case "EEE":
12220 return localize2.day(dayOfWeek, {
12221 width: "abbreviated",
12222 context: "formatting"
12223 });
12224 // T
12225 case "EEEEE":
12226 return localize2.day(dayOfWeek, {
12227 width: "narrow",
12228 context: "formatting"
12229 });
12230 // Tu
12231 case "EEEEEE":
12232 return localize2.day(dayOfWeek, {
12233 width: "short",
12234 context: "formatting"
12235 });
12236 // Tuesday
12237 case "EEEE":
12238 default:
12239 return localize2.day(dayOfWeek, {
12240 width: "wide",
12241 context: "formatting"
12242 });
12243 }
12244 },
12245 // Local day of week
12246 e: function(date, token, localize2, options) {
12247 const dayOfWeek = date.getDay();
12248 const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
12249 switch (token) {
12250 // Numerical value (Nth day of week with current locale or weekStartsOn)
12251 case "e":
12252 return String(localDayOfWeek);
12253 // Padded numerical value
12254 case "ee":
12255 return addLeadingZeros(localDayOfWeek, 2);
12256 // 1st, 2nd, ..., 7th
12257 case "eo":
12258 return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
12259 case "eee":
12260 return localize2.day(dayOfWeek, {
12261 width: "abbreviated",
12262 context: "formatting"
12263 });
12264 // T
12265 case "eeeee":
12266 return localize2.day(dayOfWeek, {
12267 width: "narrow",
12268 context: "formatting"
12269 });
12270 // Tu
12271 case "eeeeee":
12272 return localize2.day(dayOfWeek, {
12273 width: "short",
12274 context: "formatting"
12275 });
12276 // Tuesday
12277 case "eeee":
12278 default:
12279 return localize2.day(dayOfWeek, {
12280 width: "wide",
12281 context: "formatting"
12282 });
12283 }
12284 },
12285 // Stand-alone local day of week
12286 c: function(date, token, localize2, options) {
12287 const dayOfWeek = date.getDay();
12288 const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
12289 switch (token) {
12290 // Numerical value (same as in `e`)
12291 case "c":
12292 return String(localDayOfWeek);
12293 // Padded numerical value
12294 case "cc":
12295 return addLeadingZeros(localDayOfWeek, token.length);
12296 // 1st, 2nd, ..., 7th
12297 case "co":
12298 return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
12299 case "ccc":
12300 return localize2.day(dayOfWeek, {
12301 width: "abbreviated",
12302 context: "standalone"
12303 });
12304 // T
12305 case "ccccc":
12306 return localize2.day(dayOfWeek, {
12307 width: "narrow",
12308 context: "standalone"
12309 });
12310 // Tu
12311 case "cccccc":
12312 return localize2.day(dayOfWeek, {
12313 width: "short",
12314 context: "standalone"
12315 });
12316 // Tuesday
12317 case "cccc":
12318 default:
12319 return localize2.day(dayOfWeek, {
12320 width: "wide",
12321 context: "standalone"
12322 });
12323 }
12324 },
12325 // ISO day of week
12326 i: function(date, token, localize2) {
12327 const dayOfWeek = date.getDay();
12328 const isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
12329 switch (token) {
12330 // 2
12331 case "i":
12332 return String(isoDayOfWeek);
12333 // 02
12334 case "ii":
12335 return addLeadingZeros(isoDayOfWeek, token.length);
12336 // 2nd
12337 case "io":
12338 return localize2.ordinalNumber(isoDayOfWeek, { unit: "day" });
12339 // Tue
12340 case "iii":
12341 return localize2.day(dayOfWeek, {
12342 width: "abbreviated",
12343 context: "formatting"
12344 });
12345 // T
12346 case "iiiii":
12347 return localize2.day(dayOfWeek, {
12348 width: "narrow",
12349 context: "formatting"
12350 });
12351 // Tu
12352 case "iiiiii":
12353 return localize2.day(dayOfWeek, {
12354 width: "short",
12355 context: "formatting"
12356 });
12357 // Tuesday
12358 case "iiii":
12359 default:
12360 return localize2.day(dayOfWeek, {
12361 width: "wide",
12362 context: "formatting"
12363 });
12364 }
12365 },
12366 // AM or PM
12367 a: function(date, token, localize2) {
12368 const hours = date.getHours();
12369 const dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
12370 switch (token) {
12371 case "a":
12372 case "aa":
12373 return localize2.dayPeriod(dayPeriodEnumValue, {
12374 width: "abbreviated",
12375 context: "formatting"
12376 });
12377 case "aaa":
12378 return localize2.dayPeriod(dayPeriodEnumValue, {
12379 width: "abbreviated",
12380 context: "formatting"
12381 }).toLowerCase();
12382 case "aaaaa":
12383 return localize2.dayPeriod(dayPeriodEnumValue, {
12384 width: "narrow",
12385 context: "formatting"
12386 });
12387 case "aaaa":
12388 default:
12389 return localize2.dayPeriod(dayPeriodEnumValue, {
12390 width: "wide",
12391 context: "formatting"
12392 });
12393 }
12394 },
12395 // AM, PM, midnight, noon
12396 b: function(date, token, localize2) {
12397 const hours = date.getHours();
12398 let dayPeriodEnumValue;
12399 if (hours === 12) {
12400 dayPeriodEnumValue = dayPeriodEnum.noon;
12401 } else if (hours === 0) {
12402 dayPeriodEnumValue = dayPeriodEnum.midnight;
12403 } else {
12404 dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
12405 }
12406 switch (token) {
12407 case "b":
12408 case "bb":
12409 return localize2.dayPeriod(dayPeriodEnumValue, {
12410 width: "abbreviated",
12411 context: "formatting"
12412 });
12413 case "bbb":
12414 return localize2.dayPeriod(dayPeriodEnumValue, {
12415 width: "abbreviated",
12416 context: "formatting"
12417 }).toLowerCase();
12418 case "bbbbb":
12419 return localize2.dayPeriod(dayPeriodEnumValue, {
12420 width: "narrow",
12421 context: "formatting"
12422 });
12423 case "bbbb":
12424 default:
12425 return localize2.dayPeriod(dayPeriodEnumValue, {
12426 width: "wide",
12427 context: "formatting"
12428 });
12429 }
12430 },
12431 // in the morning, in the afternoon, in the evening, at night
12432 B: function(date, token, localize2) {
12433 const hours = date.getHours();
12434 let dayPeriodEnumValue;
12435 if (hours >= 17) {
12436 dayPeriodEnumValue = dayPeriodEnum.evening;
12437 } else if (hours >= 12) {
12438 dayPeriodEnumValue = dayPeriodEnum.afternoon;
12439 } else if (hours >= 4) {
12440 dayPeriodEnumValue = dayPeriodEnum.morning;
12441 } else {
12442 dayPeriodEnumValue = dayPeriodEnum.night;
12443 }
12444 switch (token) {
12445 case "B":
12446 case "BB":
12447 case "BBB":
12448 return localize2.dayPeriod(dayPeriodEnumValue, {
12449 width: "abbreviated",
12450 context: "formatting"
12451 });
12452 case "BBBBB":
12453 return localize2.dayPeriod(dayPeriodEnumValue, {
12454 width: "narrow",
12455 context: "formatting"
12456 });
12457 case "BBBB":
12458 default:
12459 return localize2.dayPeriod(dayPeriodEnumValue, {
12460 width: "wide",
12461 context: "formatting"
12462 });
12463 }
12464 },
12465 // Hour [1-12]
12466 h: function(date, token, localize2) {
12467 if (token === "ho") {
12468 let hours = date.getHours() % 12;
12469 if (hours === 0) hours = 12;
12470 return localize2.ordinalNumber(hours, { unit: "hour" });
12471 }
12472 return lightFormatters.h(date, token);
12473 },
12474 // Hour [0-23]
12475 H: function(date, token, localize2) {
12476 if (token === "Ho") {
12477 return localize2.ordinalNumber(date.getHours(), { unit: "hour" });
12478 }
12479 return lightFormatters.H(date, token);
12480 },
12481 // Hour [0-11]
12482 K: function(date, token, localize2) {
12483 const hours = date.getHours() % 12;
12484 if (token === "Ko") {
12485 return localize2.ordinalNumber(hours, { unit: "hour" });
12486 }
12487 return addLeadingZeros(hours, token.length);
12488 },
12489 // Hour [1-24]
12490 k: function(date, token, localize2) {
12491 let hours = date.getHours();
12492 if (hours === 0) hours = 24;
12493 if (token === "ko") {
12494 return localize2.ordinalNumber(hours, { unit: "hour" });
12495 }
12496 return addLeadingZeros(hours, token.length);
12497 },
12498 // Minute
12499 m: function(date, token, localize2) {
12500 if (token === "mo") {
12501 return localize2.ordinalNumber(date.getMinutes(), { unit: "minute" });
12502 }
12503 return lightFormatters.m(date, token);
12504 },
12505 // Second
12506 s: function(date, token, localize2) {
12507 if (token === "so") {
12508 return localize2.ordinalNumber(date.getSeconds(), { unit: "second" });
12509 }
12510 return lightFormatters.s(date, token);
12511 },
12512 // Fraction of second
12513 S: function(date, token) {
12514 return lightFormatters.S(date, token);
12515 },
12516 // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
12517 X: function(date, token, _localize) {
12518 const timezoneOffset = date.getTimezoneOffset();
12519 if (timezoneOffset === 0) {
12520 return "Z";
12521 }
12522 switch (token) {
12523 // Hours and optional minutes
12524 case "X":
12525 return formatTimezoneWithOptionalMinutes(timezoneOffset);
12526 // Hours, minutes and optional seconds without `:` delimiter
12527 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12528 // so this token always has the same output as `XX`
12529 case "XXXX":
12530 case "XX":
12531 return formatTimezone(timezoneOffset);
12532 // Hours, minutes and optional seconds with `:` delimiter
12533 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12534 // so this token always has the same output as `XXX`
12535 case "XXXXX":
12536 case "XXX":
12537 // Hours and minutes with `:` delimiter
12538 default:
12539 return formatTimezone(timezoneOffset, ":");
12540 }
12541 },
12542 // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
12543 x: function(date, token, _localize) {
12544 const timezoneOffset = date.getTimezoneOffset();
12545 switch (token) {
12546 // Hours and optional minutes
12547 case "x":
12548 return formatTimezoneWithOptionalMinutes(timezoneOffset);
12549 // Hours, minutes and optional seconds without `:` delimiter
12550 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12551 // so this token always has the same output as `xx`
12552 case "xxxx":
12553 case "xx":
12554 return formatTimezone(timezoneOffset);
12555 // Hours, minutes and optional seconds with `:` delimiter
12556 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12557 // so this token always has the same output as `xxx`
12558 case "xxxxx":
12559 case "xxx":
12560 // Hours and minutes with `:` delimiter
12561 default:
12562 return formatTimezone(timezoneOffset, ":");
12563 }
12564 },
12565 // Timezone (GMT)
12566 O: function(date, token, _localize) {
12567 const timezoneOffset = date.getTimezoneOffset();
12568 switch (token) {
12569 // Short
12570 case "O":
12571 case "OO":
12572 case "OOO":
12573 return "GMT" + formatTimezoneShort(timezoneOffset, ":");
12574 // Long
12575 case "OOOO":
12576 default:
12577 return "GMT" + formatTimezone(timezoneOffset, ":");
12578 }
12579 },
12580 // Timezone (specific non-location)
12581 z: function(date, token, _localize) {
12582 const timezoneOffset = date.getTimezoneOffset();
12583 switch (token) {
12584 // Short
12585 case "z":
12586 case "zz":
12587 case "zzz":
12588 return "GMT" + formatTimezoneShort(timezoneOffset, ":");
12589 // Long
12590 case "zzzz":
12591 default:
12592 return "GMT" + formatTimezone(timezoneOffset, ":");
12593 }
12594 },
12595 // Seconds timestamp
12596 t: function(date, token, _localize) {
12597 const timestamp = Math.trunc(+date / 1e3);
12598 return addLeadingZeros(timestamp, token.length);
12599 },
12600 // Milliseconds timestamp
12601 T: function(date, token, _localize) {
12602 return addLeadingZeros(+date, token.length);
12603 }
12604 };
12605 function formatTimezoneShort(offset, delimiter = "") {
12606 const sign = offset > 0 ? "-" : "+";
12607 const absOffset = Math.abs(offset);
12608 const hours = Math.trunc(absOffset / 60);
12609 const minutes = absOffset % 60;
12610 if (minutes === 0) {
12611 return sign + String(hours);
12612 }
12613 return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
12614 }
12615 function formatTimezoneWithOptionalMinutes(offset, delimiter) {
12616 if (offset % 60 === 0) {
12617 const sign = offset > 0 ? "-" : "+";
12618 return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
12619 }
12620 return formatTimezone(offset, delimiter);
12621 }
12622 function formatTimezone(offset, delimiter = "") {
12623 const sign = offset > 0 ? "-" : "+";
12624 const absOffset = Math.abs(offset);
12625 const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2);
12626 const minutes = addLeadingZeros(absOffset % 60, 2);
12627 return sign + hours + delimiter + minutes;
12628 }
12629
12630 // node_modules/date-fns/_lib/format/longFormatters.js
12631 var dateLongFormatter = (pattern, formatLong2) => {
12632 switch (pattern) {
12633 case "P":
12634 return formatLong2.date({ width: "short" });
12635 case "PP":
12636 return formatLong2.date({ width: "medium" });
12637 case "PPP":
12638 return formatLong2.date({ width: "long" });
12639 case "PPPP":
12640 default:
12641 return formatLong2.date({ width: "full" });
12642 }
12643 };
12644 var timeLongFormatter = (pattern, formatLong2) => {
12645 switch (pattern) {
12646 case "p":
12647 return formatLong2.time({ width: "short" });
12648 case "pp":
12649 return formatLong2.time({ width: "medium" });
12650 case "ppp":
12651 return formatLong2.time({ width: "long" });
12652 case "pppp":
12653 default:
12654 return formatLong2.time({ width: "full" });
12655 }
12656 };
12657 var dateTimeLongFormatter = (pattern, formatLong2) => {
12658 const matchResult = pattern.match(/(P+)(p+)?/) || [];
12659 const datePattern = matchResult[1];
12660 const timePattern = matchResult[2];
12661 if (!timePattern) {
12662 return dateLongFormatter(pattern, formatLong2);
12663 }
12664 let dateTimeFormat;
12665 switch (datePattern) {
12666 case "P":
12667 dateTimeFormat = formatLong2.dateTime({ width: "short" });
12668 break;
12669 case "PP":
12670 dateTimeFormat = formatLong2.dateTime({ width: "medium" });
12671 break;
12672 case "PPP":
12673 dateTimeFormat = formatLong2.dateTime({ width: "long" });
12674 break;
12675 case "PPPP":
12676 default:
12677 dateTimeFormat = formatLong2.dateTime({ width: "full" });
12678 break;
12679 }
12680 return dateTimeFormat.replace("{{date}}", dateLongFormatter(datePattern, formatLong2)).replace("{{time}}", timeLongFormatter(timePattern, formatLong2));
12681 };
12682 var longFormatters = {
12683 p: timeLongFormatter,
12684 P: dateTimeLongFormatter
12685 };
12686
12687 // node_modules/date-fns/_lib/protectedTokens.js
12688 var dayOfYearTokenRE = /^D+$/;
12689 var weekYearTokenRE = /^Y+$/;
12690 var throwTokens = ["D", "DD", "YY", "YYYY"];
12691 function isProtectedDayOfYearToken(token) {
12692 return dayOfYearTokenRE.test(token);
12693 }
12694 function isProtectedWeekYearToken(token) {
12695 return weekYearTokenRE.test(token);
12696 }
12697 function warnOrThrowProtectedError(token, format6, input) {
12698 const _message = message(token, format6, input);
12699 console.warn(_message);
12700 if (throwTokens.includes(token)) throw new RangeError(_message);
12701 }
12702 function message(token, format6, input) {
12703 const subject = token[0] === "Y" ? "years" : "days of the month";
12704 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`;
12705 }
12706
12707 // node_modules/date-fns/format.js
12708 var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
12709 var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
12710 var escapedStringRegExp = /^'([^]*?)'?$/;
12711 var doubleQuoteRegExp = /''/g;
12712 var unescapedLatinCharacterRegExp = /[a-zA-Z]/;
12713 function format(date, formatStr, options) {
12714 const defaultOptions2 = getDefaultOptions();
12715 const locale = options?.locale ?? defaultOptions2.locale ?? enUS;
12716 const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
12717 const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
12718 const originalDate = toDate(date, options?.in);
12719 if (!isValid(originalDate)) {
12720 throw new RangeError("Invalid time value");
12721 }
12722 let parts = formatStr.match(longFormattingTokensRegExp).map((substring) => {
12723 const firstCharacter = substring[0];
12724 if (firstCharacter === "p" || firstCharacter === "P") {
12725 const longFormatter = longFormatters[firstCharacter];
12726 return longFormatter(substring, locale.formatLong);
12727 }
12728 return substring;
12729 }).join("").match(formattingTokensRegExp).map((substring) => {
12730 if (substring === "''") {
12731 return { isToken: false, value: "'" };
12732 }
12733 const firstCharacter = substring[0];
12734 if (firstCharacter === "'") {
12735 return { isToken: false, value: cleanEscapedString(substring) };
12736 }
12737 if (formatters[firstCharacter]) {
12738 return { isToken: true, value: substring };
12739 }
12740 if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
12741 throw new RangeError(
12742 "Format string contains an unescaped latin alphabet character `" + firstCharacter + "`"
12743 );
12744 }
12745 return { isToken: false, value: substring };
12746 });
12747 if (locale.localize.preprocessor) {
12748 parts = locale.localize.preprocessor(originalDate, parts);
12749 }
12750 const formatterOptions = {
12751 firstWeekContainsDate,
12752 weekStartsOn,
12753 locale
12754 };
12755 return parts.map((part) => {
12756 if (!part.isToken) return part.value;
12757 const token = part.value;
12758 if (!options?.useAdditionalWeekYearTokens && isProtectedWeekYearToken(token) || !options?.useAdditionalDayOfYearTokens && isProtectedDayOfYearToken(token)) {
12759 warnOrThrowProtectedError(token, formatStr, String(date));
12760 }
12761 const formatter = formatters[token[0]];
12762 return formatter(originalDate, token, locale.localize, formatterOptions);
12763 }).join("");
12764 }
12765 function cleanEscapedString(input) {
12766 const matched = input.match(escapedStringRegExp);
12767 if (!matched) {
12768 return input;
12769 }
12770 return matched[1].replace(doubleQuoteRegExp, "'");
12771 }
12772
12773 // node_modules/date-fns/subDays.js
12774 function subDays(date, amount, options) {
12775 return addDays(date, -amount, options);
12776 }
12777
12778 // node_modules/date-fns/subMonths.js
12779 function subMonths(date, amount, options) {
12780 return addMonths(date, -amount, options);
12781 }
12782
12783 // node_modules/date-fns/subWeeks.js
12784 function subWeeks(date, amount, options) {
12785 return addWeeks(date, -amount, options);
12786 }
12787
12788 // node_modules/date-fns/subYears.js
12789 function subYears(date, amount, options) {
12790 return addYears(date, -amount, options);
12791 }
12792
12793 // packages/dataviews/build-module/utils/operators.mjs
12794 var import_i18n29 = __toESM(require_i18n(), 1);
12795 var import_element29 = __toESM(require_element(), 1);
12796 var import_date = __toESM(require_date(), 1);
12797 var import_jsx_runtime64 = __toESM(require_jsx_runtime(), 1);
12798 var filterTextWrappers = {
12799 Name: /* @__PURE__ */ (0, import_jsx_runtime64.jsx)("span", { className: "dataviews-filters__summary-filter-text-name" }),
12800 Value: /* @__PURE__ */ (0, import_jsx_runtime64.jsx)("span", { className: "dataviews-filters__summary-filter-text-value" })
12801 };
12802 function getRelativeDate(value, unit) {
12803 switch (unit) {
12804 case "days":
12805 return subDays(/* @__PURE__ */ new Date(), value);
12806 case "weeks":
12807 return subWeeks(/* @__PURE__ */ new Date(), value);
12808 case "months":
12809 return subMonths(/* @__PURE__ */ new Date(), value);
12810 case "years":
12811 return subYears(/* @__PURE__ */ new Date(), value);
12812 default:
12813 return /* @__PURE__ */ new Date();
12814 }
12815 }
12816 var isNoneOperatorDefinition = {
12817 /* translators: DataViews operator name */
12818 label: (0, import_i18n29.__)("Is none of"),
12819 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12820 (0, import_i18n29.sprintf)(
12821 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is none of: Admin, Editor". */
12822 (0, import_i18n29.__)("<Name>%1$s is none of: </Name><Value>%2$s</Value>"),
12823 filter.name,
12824 activeElements.map((element) => element.label).join(", ")
12825 ),
12826 filterTextWrappers
12827 ),
12828 filter: ((item, field, filterValue) => {
12829 if (!filterValue?.length) {
12830 return true;
12831 }
12832 const fieldValue = field.getValue({ item });
12833 if (Array.isArray(fieldValue)) {
12834 return !filterValue.some(
12835 (fv) => fieldValue.includes(fv)
12836 );
12837 } else if (typeof fieldValue === "string") {
12838 return !filterValue.includes(fieldValue);
12839 }
12840 return false;
12841 }),
12842 selection: "multi"
12843 };
12844 var OPERATORS = [
12845 {
12846 name: OPERATOR_IS_ANY,
12847 /* translators: DataViews operator name */
12848 label: (0, import_i18n29.__)("Includes"),
12849 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12850 (0, import_i18n29.sprintf)(
12851 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is any: Admin, Editor". */
12852 (0, import_i18n29.__)("<Name>%1$s includes: </Name><Value>%2$s</Value>"),
12853 filter.name,
12854 activeElements.map((element) => element.label).join(", ")
12855 ),
12856 filterTextWrappers
12857 ),
12858 filter(item, field, filterValue) {
12859 if (!filterValue?.length) {
12860 return true;
12861 }
12862 const fieldValue = field.getValue({ item });
12863 if (Array.isArray(fieldValue)) {
12864 return filterValue.some(
12865 (fv) => fieldValue.includes(fv)
12866 );
12867 } else if (typeof fieldValue === "string") {
12868 return filterValue.includes(fieldValue);
12869 }
12870 return false;
12871 },
12872 selection: "multi"
12873 },
12874 {
12875 name: OPERATOR_IS_NONE,
12876 ...isNoneOperatorDefinition
12877 },
12878 {
12879 name: OPERATOR_IS_ALL,
12880 /* translators: DataViews operator name */
12881 label: (0, import_i18n29.__)("Includes all"),
12882 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12883 (0, import_i18n29.sprintf)(
12884 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author includes all: Admin, Editor". */
12885 (0, import_i18n29.__)("<Name>%1$s includes all: </Name><Value>%2$s</Value>"),
12886 filter.name,
12887 activeElements.map((element) => element.label).join(", ")
12888 ),
12889 filterTextWrappers
12890 ),
12891 filter(item, field, filterValue) {
12892 if (!filterValue?.length) {
12893 return true;
12894 }
12895 return filterValue.every((value) => {
12896 return field.getValue({ item })?.includes(value);
12897 });
12898 },
12899 selection: "multi"
12900 },
12901 {
12902 name: OPERATOR_IS_NOT_ALL,
12903 ...isNoneOperatorDefinition
12904 },
12905 {
12906 name: OPERATOR_BETWEEN,
12907 /* translators: DataViews operator name */
12908 label: (0, import_i18n29.__)("Between (inc)"),
12909 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12910 (0, import_i18n29.sprintf)(
12911 /* 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". */
12912 (0, import_i18n29.__)(
12913 "<Name>%1$s between (inc): </Name><Value>%2$s and %3$s</Value>"
12914 ),
12915 filter.name,
12916 activeElements[0].label[0],
12917 activeElements[0].label[1]
12918 ),
12919 filterTextWrappers
12920 ),
12921 filter(item, field, filterValue) {
12922 if (!Array.isArray(filterValue) || filterValue.length !== 2 || filterValue[0] === void 0 || filterValue[1] === void 0) {
12923 return true;
12924 }
12925 const fieldValue = field.getValue({ item });
12926 if (typeof fieldValue === "number" || fieldValue instanceof Date || typeof fieldValue === "string") {
12927 return fieldValue >= filterValue[0] && fieldValue <= filterValue[1];
12928 }
12929 return false;
12930 },
12931 selection: "custom"
12932 },
12933 {
12934 name: OPERATOR_IN_THE_PAST,
12935 /* translators: DataViews operator name */
12936 label: (0, import_i18n29.__)("In the past"),
12937 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12938 (0, import_i18n29.sprintf)(
12939 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "7 days"): "Date is in the past: 7 days". */
12940 (0, import_i18n29.__)(
12941 "<Name>%1$s is in the past: </Name><Value>%2$s</Value>"
12942 ),
12943 filter.name,
12944 `${activeElements[0].value.value} ${activeElements[0].value.unit}`
12945 ),
12946 filterTextWrappers
12947 ),
12948 filter(item, field, filterValue) {
12949 if (filterValue?.value === void 0 || filterValue?.unit === void 0) {
12950 return true;
12951 }
12952 const targetDate = getRelativeDate(
12953 filterValue.value,
12954 filterValue.unit
12955 );
12956 const fieldValue = (0, import_date.getDate)(field.getValue({ item }));
12957 return fieldValue >= targetDate && fieldValue <= /* @__PURE__ */ new Date();
12958 },
12959 selection: "custom"
12960 },
12961 {
12962 name: OPERATOR_OVER,
12963 /* translators: DataViews operator name */
12964 label: (0, import_i18n29.__)("Over"),
12965 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12966 (0, import_i18n29.sprintf)(
12967 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "7 days"): "Date is over: 7 days". */
12968 (0, import_i18n29.__)("<Name>%1$s is over: </Name><Value>%2$s</Value>"),
12969 filter.name,
12970 `${activeElements[0].value.value} ${activeElements[0].value.unit}`
12971 ),
12972 filterTextWrappers
12973 ),
12974 filter(item, field, filterValue) {
12975 if (filterValue?.value === void 0 || filterValue?.unit === void 0) {
12976 return true;
12977 }
12978 const targetDate = getRelativeDate(
12979 filterValue.value,
12980 filterValue.unit
12981 );
12982 const fieldValue = (0, import_date.getDate)(field.getValue({ item }));
12983 return fieldValue < targetDate;
12984 },
12985 selection: "custom"
12986 },
12987 {
12988 name: OPERATOR_IS,
12989 /* translators: DataViews operator name */
12990 label: (0, import_i18n29.__)("Is"),
12991 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
12992 (0, import_i18n29.sprintf)(
12993 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is: Admin". */
12994 (0, import_i18n29.__)("<Name>%1$s is: </Name><Value>%2$s</Value>"),
12995 filter.name,
12996 activeElements[0].label
12997 ),
12998 filterTextWrappers
12999 ),
13000 filter(item, field, filterValue) {
13001 return filterValue === field.getValue({ item }) || filterValue === void 0;
13002 },
13003 selection: "single"
13004 },
13005 {
13006 name: OPERATOR_IS_NOT,
13007 /* translators: DataViews operator name */
13008 label: (0, import_i18n29.__)("Is not"),
13009 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13010 (0, import_i18n29.sprintf)(
13011 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is not: Admin". */
13012 (0, import_i18n29.__)("<Name>%1$s is not: </Name><Value>%2$s</Value>"),
13013 filter.name,
13014 activeElements[0].label
13015 ),
13016 filterTextWrappers
13017 ),
13018 filter(item, field, filterValue) {
13019 return filterValue !== field.getValue({ item });
13020 },
13021 selection: "single"
13022 },
13023 {
13024 name: OPERATOR_LESS_THAN,
13025 /* translators: DataViews operator name */
13026 label: (0, import_i18n29.__)("Less than"),
13027 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13028 (0, import_i18n29.sprintf)(
13029 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is less than: 10". */
13030 (0, import_i18n29.__)("<Name>%1$s is less than: </Name><Value>%2$s</Value>"),
13031 filter.name,
13032 activeElements[0].label
13033 ),
13034 filterTextWrappers
13035 ),
13036 filter(item, field, filterValue) {
13037 if (filterValue === void 0) {
13038 return true;
13039 }
13040 const fieldValue = field.getValue({ item });
13041 return fieldValue < filterValue;
13042 },
13043 selection: "single"
13044 },
13045 {
13046 name: OPERATOR_GREATER_THAN,
13047 /* translators: DataViews operator name */
13048 label: (0, import_i18n29.__)("Greater than"),
13049 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13050 (0, import_i18n29.sprintf)(
13051 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is greater than: 10". */
13052 (0, import_i18n29.__)(
13053 "<Name>%1$s is greater than: </Name><Value>%2$s</Value>"
13054 ),
13055 filter.name,
13056 activeElements[0].label
13057 ),
13058 filterTextWrappers
13059 ),
13060 filter(item, field, filterValue) {
13061 if (filterValue === void 0) {
13062 return true;
13063 }
13064 const fieldValue = field.getValue({ item });
13065 return fieldValue > filterValue;
13066 },
13067 selection: "single"
13068 },
13069 {
13070 name: OPERATOR_LESS_THAN_OR_EQUAL,
13071 /* translators: DataViews operator name */
13072 label: (0, import_i18n29.__)("Less than or equal"),
13073 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13074 (0, import_i18n29.sprintf)(
13075 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is less than or equal to: 10". */
13076 (0, import_i18n29.__)(
13077 "<Name>%1$s is less than or equal to: </Name><Value>%2$s</Value>"
13078 ),
13079 filter.name,
13080 activeElements[0].label
13081 ),
13082 filterTextWrappers
13083 ),
13084 filter(item, field, filterValue) {
13085 if (filterValue === void 0) {
13086 return true;
13087 }
13088 const fieldValue = field.getValue({ item });
13089 return fieldValue <= filterValue;
13090 },
13091 selection: "single"
13092 },
13093 {
13094 name: OPERATOR_GREATER_THAN_OR_EQUAL,
13095 /* translators: DataViews operator name */
13096 label: (0, import_i18n29.__)("Greater than or equal"),
13097 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13098 (0, import_i18n29.sprintf)(
13099 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is greater than or equal to: 10". */
13100 (0, import_i18n29.__)(
13101 "<Name>%1$s is greater than or equal to: </Name><Value>%2$s</Value>"
13102 ),
13103 filter.name,
13104 activeElements[0].label
13105 ),
13106 filterTextWrappers
13107 ),
13108 filter(item, field, filterValue) {
13109 if (filterValue === void 0) {
13110 return true;
13111 }
13112 const fieldValue = field.getValue({ item });
13113 return fieldValue >= filterValue;
13114 },
13115 selection: "single"
13116 },
13117 {
13118 name: OPERATOR_BEFORE,
13119 /* translators: DataViews operator name */
13120 label: (0, import_i18n29.__)("Before"),
13121 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13122 (0, import_i18n29.sprintf)(
13123 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is before: 2024-01-01". */
13124 (0, import_i18n29.__)("<Name>%1$s is before: </Name><Value>%2$s</Value>"),
13125 filter.name,
13126 activeElements[0].label
13127 ),
13128 filterTextWrappers
13129 ),
13130 filter(item, field, filterValue) {
13131 if (filterValue === void 0) {
13132 return true;
13133 }
13134 const filterDate = (0, import_date.getDate)(filterValue);
13135 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13136 return fieldDate < filterDate;
13137 },
13138 selection: "single"
13139 },
13140 {
13141 name: OPERATOR_AFTER,
13142 /* translators: DataViews operator name */
13143 label: (0, import_i18n29.__)("After"),
13144 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13145 (0, import_i18n29.sprintf)(
13146 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is after: 2024-01-01". */
13147 (0, import_i18n29.__)("<Name>%1$s is after: </Name><Value>%2$s</Value>"),
13148 filter.name,
13149 activeElements[0].label
13150 ),
13151 filterTextWrappers
13152 ),
13153 filter(item, field, filterValue) {
13154 if (filterValue === void 0) {
13155 return true;
13156 }
13157 const filterDate = (0, import_date.getDate)(filterValue);
13158 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13159 return fieldDate > filterDate;
13160 },
13161 selection: "single"
13162 },
13163 {
13164 name: OPERATOR_BEFORE_INC,
13165 /* translators: DataViews operator name */
13166 label: (0, import_i18n29.__)("Before (inc)"),
13167 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13168 (0, import_i18n29.sprintf)(
13169 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is on or before: 2024-01-01". */
13170 (0, import_i18n29.__)(
13171 "<Name>%1$s is on or before: </Name><Value>%2$s</Value>"
13172 ),
13173 filter.name,
13174 activeElements[0].label
13175 ),
13176 filterTextWrappers
13177 ),
13178 filter(item, field, filterValue) {
13179 if (filterValue === void 0) {
13180 return true;
13181 }
13182 const filterDate = (0, import_date.getDate)(filterValue);
13183 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13184 return fieldDate <= filterDate;
13185 },
13186 selection: "single"
13187 },
13188 {
13189 name: OPERATOR_AFTER_INC,
13190 /* translators: DataViews operator name */
13191 label: (0, import_i18n29.__)("After (inc)"),
13192 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13193 (0, import_i18n29.sprintf)(
13194 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is on or after: 2024-01-01". */
13195 (0, import_i18n29.__)(
13196 "<Name>%1$s is on or after: </Name><Value>%2$s</Value>"
13197 ),
13198 filter.name,
13199 activeElements[0].label
13200 ),
13201 filterTextWrappers
13202 ),
13203 filter(item, field, filterValue) {
13204 if (filterValue === void 0) {
13205 return true;
13206 }
13207 const filterDate = (0, import_date.getDate)(filterValue);
13208 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13209 return fieldDate >= filterDate;
13210 },
13211 selection: "single"
13212 },
13213 {
13214 name: OPERATOR_CONTAINS,
13215 /* translators: DataViews operator name */
13216 label: (0, import_i18n29.__)("Contains"),
13217 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13218 (0, import_i18n29.sprintf)(
13219 /* translators: 1: Filter name (e.g. "Title"). 2: Filter value (e.g. "Hello"): "Title contains: Hello". */
13220 (0, import_i18n29.__)("<Name>%1$s contains: </Name><Value>%2$s</Value>"),
13221 filter.name,
13222 activeElements[0].label
13223 ),
13224 filterTextWrappers
13225 ),
13226 filter(item, field, filterValue) {
13227 if (filterValue === void 0) {
13228 return true;
13229 }
13230 const fieldValue = field.getValue({ item });
13231 return typeof fieldValue === "string" && filterValue && fieldValue.toLowerCase().includes(String(filterValue).toLowerCase());
13232 },
13233 selection: "single"
13234 },
13235 {
13236 name: OPERATOR_NOT_CONTAINS,
13237 /* translators: DataViews operator name */
13238 label: (0, import_i18n29.__)("Doesn't contain"),
13239 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13240 (0, import_i18n29.sprintf)(
13241 /* translators: 1: Filter name (e.g. "Title"). 2: Filter value (e.g. "Hello"): "Title doesn't contain: Hello". */
13242 (0, import_i18n29.__)(
13243 "<Name>%1$s doesn't contain: </Name><Value>%2$s</Value>"
13244 ),
13245 filter.name,
13246 activeElements[0].label
13247 ),
13248 filterTextWrappers
13249 ),
13250 filter(item, field, filterValue) {
13251 if (filterValue === void 0) {
13252 return true;
13253 }
13254 const fieldValue = field.getValue({ item });
13255 return typeof fieldValue === "string" && filterValue && !fieldValue.toLowerCase().includes(String(filterValue).toLowerCase());
13256 },
13257 selection: "single"
13258 },
13259 {
13260 name: OPERATOR_STARTS_WITH,
13261 /* translators: DataViews operator name */
13262 label: (0, import_i18n29.__)("Starts with"),
13263 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13264 (0, import_i18n29.sprintf)(
13265 /* translators: 1: Filter name (e.g. "Title"). 2: Filter value (e.g. "Hello"): "Title starts with: Hello". */
13266 (0, import_i18n29.__)("<Name>%1$s starts with: </Name><Value>%2$s</Value>"),
13267 filter.name,
13268 activeElements[0].label
13269 ),
13270 filterTextWrappers
13271 ),
13272 filter(item, field, filterValue) {
13273 if (filterValue === void 0) {
13274 return true;
13275 }
13276 const fieldValue = field.getValue({ item });
13277 return typeof fieldValue === "string" && filterValue && fieldValue.toLowerCase().startsWith(String(filterValue).toLowerCase());
13278 },
13279 selection: "single"
13280 },
13281 {
13282 name: OPERATOR_ON,
13283 /* translators: DataViews operator name */
13284 label: (0, import_i18n29.__)("On"),
13285 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13286 (0, import_i18n29.sprintf)(
13287 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is: 2024-01-01". */
13288 (0, import_i18n29.__)("<Name>%1$s is: </Name><Value>%2$s</Value>"),
13289 filter.name,
13290 activeElements[0].label
13291 ),
13292 filterTextWrappers
13293 ),
13294 filter(item, field, filterValue) {
13295 if (filterValue === void 0) {
13296 return true;
13297 }
13298 const filterDate = (0, import_date.getDate)(filterValue);
13299 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13300 return filterDate.getTime() === fieldDate.getTime();
13301 },
13302 selection: "single"
13303 },
13304 {
13305 name: OPERATOR_NOT_ON,
13306 /* translators: DataViews operator name */
13307 label: (0, import_i18n29.__)("Not on"),
13308 filterText: (filter, activeElements) => (0, import_element29.createInterpolateElement)(
13309 (0, import_i18n29.sprintf)(
13310 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is not: 2024-01-01". */
13311 (0, import_i18n29.__)("<Name>%1$s is not: </Name><Value>%2$s</Value>"),
13312 filter.name,
13313 activeElements[0].label
13314 ),
13315 filterTextWrappers
13316 ),
13317 filter(item, field, filterValue) {
13318 if (filterValue === void 0) {
13319 return true;
13320 }
13321 const filterDate = (0, import_date.getDate)(filterValue);
13322 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13323 return filterDate.getTime() !== fieldDate.getTime();
13324 },
13325 selection: "single"
13326 }
13327 ];
13328 var getOperatorByName = (name) => OPERATORS.find((op) => op.name === name);
13329 var getAllOperatorNames = () => OPERATORS.map((op) => op.name);
13330 var isSingleSelectionOperator = (name) => OPERATORS.filter((op) => op.selection === "single").some(
13331 (op) => op.name === name
13332 );
13333 var isRegisteredOperator = (name) => OPERATORS.some((op) => op.name === name);
13334
13335 // packages/dataviews/build-module/components/dataviews-filters/filter.mjs
13336 var import_jsx_runtime65 = __toESM(require_jsx_runtime(), 1);
13337 var ENTER = "Enter";
13338 var SPACE = " ";
13339 var FilterText = ({
13340 activeElements,
13341 filterInView,
13342 filter
13343 }) => {
13344 if (activeElements === void 0 || activeElements.length === 0) {
13345 return filter.name;
13346 }
13347 const operator = getOperatorByName(filterInView?.operator);
13348 if (operator !== void 0) {
13349 return operator.filterText(filter, activeElements);
13350 }
13351 return (0, import_i18n30.sprintf)(
13352 /* translators: 1: Filter name e.g.: "Unknown status for Author". */
13353 (0, import_i18n30.__)("Unknown status for %1$s"),
13354 filter.name
13355 );
13356 };
13357 function OperatorSelector({
13358 filter,
13359 view,
13360 onChangeView
13361 }) {
13362 const operatorOptions = filter.operators?.map((operator) => ({
13363 value: operator,
13364 label: getOperatorByName(operator)?.label || operator
13365 }));
13366 const currentFilter = view.filters?.find(
13367 (_filter) => _filter.field === filter.field
13368 );
13369 const value = currentFilter?.operator || filter.operators[0];
13370 return operatorOptions.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)(
13371 Stack,
13372 {
13373 direction: "row",
13374 gap: "sm",
13375 justify: "flex-start",
13376 className: "dataviews-filters__summary-operators-container",
13377 align: "center",
13378 children: [
13379 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(import_components20.FlexItem, { className: "dataviews-filters__summary-operators-filter-name", children: filter.name }),
13380 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13381 import_components20.SelectControl,
13382 {
13383 className: "dataviews-filters__summary-operators-filter-select",
13384 label: (0, import_i18n30.__)("Conditions"),
13385 value,
13386 options: operatorOptions,
13387 onChange: (newValue) => {
13388 const newOperator = newValue;
13389 const currentOperator = currentFilter?.operator;
13390 const newFilters = currentFilter ? [
13391 ...(view.filters ?? []).map(
13392 (_filter) => {
13393 if (_filter.field === filter.field) {
13394 const currentOpSelectionModel = getOperatorByName(
13395 currentOperator
13396 )?.selection;
13397 const newOpSelectionModel = getOperatorByName(
13398 newOperator
13399 )?.selection;
13400 const shouldResetValue = currentOpSelectionModel !== newOpSelectionModel || [
13401 currentOpSelectionModel,
13402 newOpSelectionModel
13403 ].includes("custom");
13404 return {
13405 ..._filter,
13406 value: shouldResetValue ? void 0 : _filter.value,
13407 operator: newOperator
13408 };
13409 }
13410 return _filter;
13411 }
13412 )
13413 ] : [
13414 ...view.filters ?? [],
13415 {
13416 field: filter.field,
13417 operator: newOperator,
13418 value: void 0
13419 }
13420 ];
13421 onChangeView({
13422 ...view,
13423 page: 1,
13424 filters: newFilters
13425 });
13426 },
13427 size: "small",
13428 variant: "minimal",
13429 hideLabelFromVision: true
13430 }
13431 )
13432 ]
13433 }
13434 );
13435 }
13436 function Filter({
13437 addFilterRef,
13438 openedFilter,
13439 fields,
13440 ...commonProps
13441 }) {
13442 const toggleRef = (0, import_element30.useRef)(null);
13443 const { filter, view, onChangeView } = commonProps;
13444 const filterInView = view.filters?.find(
13445 (f2) => f2.field === filter.field
13446 );
13447 let activeElements = [];
13448 const field = (0, import_element30.useMemo)(() => {
13449 const currentField = fields.find((f2) => f2.id === filter.field);
13450 if (currentField) {
13451 return {
13452 ...currentField,
13453 // Configure getValue as if Item was a plain object.
13454 // See related input-widget.tsx
13455 getValue: ({ item }) => item[currentField.id]
13456 };
13457 }
13458 return currentField;
13459 }, [fields, filter.field]);
13460 const { elements } = useElements({
13461 elements: filter.elements,
13462 getElements: filter.getElements
13463 });
13464 if (elements.length > 0) {
13465 activeElements = elements.filter((element) => {
13466 if (filter.singleSelection) {
13467 return element.value === filterInView?.value;
13468 }
13469 return filterInView?.value?.includes(element.value);
13470 });
13471 } else if (Array.isArray(filterInView?.value)) {
13472 const label = filterInView.value.map((v2) => {
13473 const formattedValue = field?.getValueFormatted({
13474 item: { [field.id]: v2 },
13475 field
13476 });
13477 return formattedValue || String(v2);
13478 });
13479 activeElements = [
13480 {
13481 value: filterInView.value,
13482 // @ts-ignore
13483 label
13484 }
13485 ];
13486 } else if (typeof filterInView?.value === "object") {
13487 activeElements = [
13488 { value: filterInView.value, label: filterInView.value }
13489 ];
13490 } else if (filterInView?.value !== void 0) {
13491 const label = field !== void 0 ? field.getValueFormatted({
13492 item: { [field.id]: filterInView.value },
13493 field
13494 }) : String(filterInView.value);
13495 activeElements = [
13496 {
13497 value: filterInView.value,
13498 label
13499 }
13500 ];
13501 }
13502 const isPrimary = filter.isPrimary;
13503 const isLocked = filterInView?.isLocked;
13504 const hasValues = !isLocked && filterInView?.value !== void 0;
13505 const canResetOrRemove = !isLocked && (!isPrimary || hasValues);
13506 return /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13507 import_components20.Dropdown,
13508 {
13509 defaultOpen: openedFilter === filter.field,
13510 contentClassName: "dataviews-filters__summary-popover",
13511 popoverProps: { placement: "bottom-start", role: "dialog" },
13512 onClose: () => {
13513 toggleRef.current?.focus();
13514 },
13515 renderToggle: ({ isOpen, onToggle }) => /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)("div", { className: "dataviews-filters__summary-chip-container", children: [
13516 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13517 import_components20.Tooltip,
13518 {
13519 text: (0, import_i18n30.sprintf)(
13520 /* translators: 1: Filter name. */
13521 (0, import_i18n30.__)("Filter by: %1$s"),
13522 filter.name.toLowerCase()
13523 ),
13524 placement: "top",
13525 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13526 "div",
13527 {
13528 className: clsx_default(
13529 "dataviews-filters__summary-chip",
13530 {
13531 "has-reset": canResetOrRemove,
13532 "has-values": hasValues,
13533 "is-not-clickable": isLocked
13534 }
13535 ),
13536 role: "button",
13537 tabIndex: isLocked ? -1 : 0,
13538 onClick: () => {
13539 if (!isLocked) {
13540 onToggle();
13541 }
13542 },
13543 onKeyDown: (event) => {
13544 if (!isLocked && [ENTER, SPACE].includes(event.key)) {
13545 onToggle();
13546 event.preventDefault();
13547 }
13548 },
13549 "aria-disabled": isLocked,
13550 "aria-pressed": isOpen,
13551 "aria-expanded": isOpen,
13552 ref: toggleRef,
13553 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13554 FilterText,
13555 {
13556 activeElements,
13557 filterInView,
13558 filter
13559 }
13560 )
13561 }
13562 )
13563 }
13564 ),
13565 canResetOrRemove && /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13566 import_components20.Tooltip,
13567 {
13568 text: isPrimary ? (0, import_i18n30.__)("Reset") : (0, import_i18n30.__)("Remove"),
13569 placement: "top",
13570 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13571 "button",
13572 {
13573 className: clsx_default(
13574 "dataviews-filters__summary-chip-remove",
13575 { "has-values": hasValues }
13576 ),
13577 onClick: () => {
13578 onChangeView({
13579 ...view,
13580 page: 1,
13581 filters: view.filters?.filter(
13582 (_filter) => _filter.field !== filter.field
13583 )
13584 });
13585 if (!isPrimary) {
13586 addFilterRef.current?.focus();
13587 } else {
13588 toggleRef.current?.focus();
13589 }
13590 },
13591 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(import_components20.Icon, { icon: close_small_default })
13592 }
13593 )
13594 }
13595 )
13596 ] }),
13597 renderContent: () => {
13598 return /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)(Stack, { direction: "column", justify: "flex-start", children: [
13599 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(OperatorSelector, { ...commonProps }),
13600 commonProps.filter.hasElements ? /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13601 SearchWidget,
13602 {
13603 ...commonProps,
13604 filter: {
13605 ...commonProps.filter,
13606 elements
13607 }
13608 }
13609 ) : /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(InputWidget, { ...commonProps, fields })
13610 ] });
13611 }
13612 }
13613 );
13614 }
13615
13616 // packages/dataviews/build-module/components/dataviews-filters/add-filter.mjs
13617 var import_components21 = __toESM(require_components(), 1);
13618 var import_i18n31 = __toESM(require_i18n(), 1);
13619 var import_element31 = __toESM(require_element(), 1);
13620 var import_jsx_runtime66 = __toESM(require_jsx_runtime(), 1);
13621 var { Menu: Menu4 } = unlock(import_components21.privateApis);
13622 function AddFilterMenu({
13623 filters,
13624 view,
13625 onChangeView,
13626 setOpenedFilter,
13627 triggerProps
13628 }) {
13629 const inactiveFilters = filters.filter((filter) => !filter.isVisible);
13630 return /* @__PURE__ */ (0, import_jsx_runtime66.jsxs)(Menu4, { children: [
13631 /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(Menu4.TriggerButton, { ...triggerProps }),
13632 /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(Menu4.Popover, { children: inactiveFilters.map((filter) => {
13633 return /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
13634 Menu4.Item,
13635 {
13636 onClick: () => {
13637 setOpenedFilter(filter.field);
13638 onChangeView({
13639 ...view,
13640 page: 1,
13641 filters: [
13642 ...view.filters || [],
13643 {
13644 field: filter.field,
13645 value: void 0,
13646 operator: filter.operators[0]
13647 }
13648 ]
13649 });
13650 },
13651 children: /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(Menu4.ItemLabel, { children: filter.name })
13652 },
13653 filter.field
13654 );
13655 }) })
13656 ] });
13657 }
13658 function AddFilter({ filters, view, onChangeView, setOpenedFilter }, ref) {
13659 if (!filters.length || filters.every(({ isPrimary }) => isPrimary)) {
13660 return null;
13661 }
13662 const inactiveFilters = filters.filter((filter) => !filter.isVisible);
13663 return /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
13664 AddFilterMenu,
13665 {
13666 triggerProps: {
13667 render: /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
13668 import_components21.Button,
13669 {
13670 accessibleWhenDisabled: true,
13671 size: "compact",
13672 className: "dataviews-filters-button",
13673 variant: "tertiary",
13674 disabled: !inactiveFilters.length,
13675 ref
13676 }
13677 ),
13678 children: (0, import_i18n31.__)("Add filter")
13679 },
13680 ...{ filters, view, onChangeView, setOpenedFilter }
13681 }
13682 );
13683 }
13684 var add_filter_default = (0, import_element31.forwardRef)(AddFilter);
13685
13686 // packages/dataviews/build-module/components/dataviews-filters/reset-filters.mjs
13687 var import_components22 = __toESM(require_components(), 1);
13688 var import_i18n32 = __toESM(require_i18n(), 1);
13689 var import_jsx_runtime67 = __toESM(require_jsx_runtime(), 1);
13690 function ResetFilter({
13691 filters,
13692 view,
13693 onChangeView
13694 }) {
13695 const isPrimary = (field) => filters.some(
13696 (_filter) => _filter.field === field && _filter.isPrimary
13697 );
13698 const isDisabled = !view.search && !view.filters?.some(
13699 (_filter) => !_filter.isLocked && (_filter.value !== void 0 || !isPrimary(_filter.field))
13700 );
13701 return /* @__PURE__ */ (0, import_jsx_runtime67.jsx)(
13702 import_components22.Button,
13703 {
13704 disabled: isDisabled,
13705 accessibleWhenDisabled: true,
13706 size: "compact",
13707 variant: "tertiary",
13708 className: "dataviews-filters__reset-button",
13709 onClick: () => {
13710 onChangeView({
13711 ...view,
13712 page: 1,
13713 search: "",
13714 filters: view.filters?.filter((f2) => !!f2.isLocked) || []
13715 });
13716 },
13717 children: (0, import_i18n32.__)("Reset")
13718 }
13719 );
13720 }
13721
13722 // packages/dataviews/build-module/components/dataviews-filters/use-filters.mjs
13723 var import_element32 = __toESM(require_element(), 1);
13724 function useFilters(fields, view) {
13725 return (0, import_element32.useMemo)(() => {
13726 const filters = [];
13727 fields.forEach((field) => {
13728 if (field.filterBy === false || !field.hasElements && !field.Edit) {
13729 return;
13730 }
13731 const operators = field.filterBy.operators;
13732 const isPrimary = !!field.filterBy?.isPrimary;
13733 const isLocked = view.filters?.some(
13734 (f2) => f2.field === field.id && !!f2.isLocked
13735 ) ?? false;
13736 filters.push({
13737 field: field.id,
13738 name: field.label,
13739 elements: field.elements,
13740 getElements: field.getElements,
13741 hasElements: field.hasElements,
13742 singleSelection: operators.some(
13743 (op) => isSingleSelectionOperator(op)
13744 ),
13745 operators,
13746 isVisible: isLocked || isPrimary || !!view.filters?.some(
13747 (f2) => f2.field === field.id && isRegisteredOperator(f2.operator)
13748 ),
13749 isPrimary,
13750 isLocked
13751 });
13752 });
13753 filters.sort((a2, b2) => {
13754 if (a2.isLocked && !b2.isLocked) {
13755 return -1;
13756 }
13757 if (!a2.isLocked && b2.isLocked) {
13758 return 1;
13759 }
13760 if (a2.isPrimary && !b2.isPrimary) {
13761 return -1;
13762 }
13763 if (!a2.isPrimary && b2.isPrimary) {
13764 return 1;
13765 }
13766 return a2.name.localeCompare(b2.name);
13767 });
13768 return filters;
13769 }, [fields, view]);
13770 }
13771 var use_filters_default = useFilters;
13772
13773 // packages/dataviews/build-module/components/dataviews-filters/filters.mjs
13774 var import_jsx_runtime68 = __toESM(require_jsx_runtime(), 1);
13775 function Filters({ className }) {
13776 const { fields, view, onChangeView, openedFilter, setOpenedFilter } = (0, import_element33.useContext)(dataviews_context_default);
13777 const addFilterRef = (0, import_element33.useRef)(null);
13778 const filters = use_filters_default(fields, view);
13779 const addFilter = /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13780 add_filter_default,
13781 {
13782 filters,
13783 view,
13784 onChangeView,
13785 ref: addFilterRef,
13786 setOpenedFilter
13787 },
13788 "add-filter"
13789 );
13790 const visibleFilters = filters.filter((filter) => filter.isVisible);
13791 if (visibleFilters.length === 0) {
13792 return null;
13793 }
13794 const filterComponents = [
13795 ...visibleFilters.map((filter) => {
13796 return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13797 Filter,
13798 {
13799 filter,
13800 view,
13801 fields,
13802 onChangeView,
13803 addFilterRef,
13804 openedFilter
13805 },
13806 filter.field
13807 );
13808 }),
13809 addFilter
13810 ];
13811 filterComponents.push(
13812 /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13813 ResetFilter,
13814 {
13815 filters,
13816 view,
13817 onChangeView
13818 },
13819 "reset-filters"
13820 )
13821 );
13822 return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13823 Stack,
13824 {
13825 direction: "row",
13826 justify: "flex-start",
13827 gap: "sm",
13828 style: { width: "fit-content" },
13829 wrap: "wrap",
13830 className,
13831 children: filterComponents
13832 }
13833 );
13834 }
13835 var filters_default = (0, import_element33.memo)(Filters);
13836
13837 // packages/dataviews/build-module/components/dataviews-filters/toggle.mjs
13838 var import_element34 = __toESM(require_element(), 1);
13839 var import_components23 = __toESM(require_components(), 1);
13840 var import_i18n33 = __toESM(require_i18n(), 1);
13841 var import_jsx_runtime69 = __toESM(require_jsx_runtime(), 1);
13842 function FiltersToggle() {
13843 const {
13844 filters,
13845 view,
13846 onChangeView,
13847 setOpenedFilter,
13848 isShowingFilter,
13849 setIsShowingFilter
13850 } = (0, import_element34.useContext)(dataviews_context_default);
13851 const buttonRef = (0, import_element34.useRef)(null);
13852 const onChangeViewWithFilterVisibility = (0, import_element34.useCallback)(
13853 (_view) => {
13854 onChangeView(_view);
13855 setIsShowingFilter(true);
13856 },
13857 [onChangeView, setIsShowingFilter]
13858 );
13859 if (filters.length === 0) {
13860 return null;
13861 }
13862 const hasVisibleFilters = filters.some((filter) => filter.isVisible);
13863 const addFilterButtonProps = {
13864 label: (0, import_i18n33.__)("Add filter"),
13865 "aria-expanded": false,
13866 isPressed: false
13867 };
13868 const toggleFiltersButtonProps = {
13869 label: (0, import_i18n33._x)("Filter", "verb"),
13870 "aria-expanded": isShowingFilter,
13871 isPressed: isShowingFilter,
13872 onClick: () => {
13873 if (!isShowingFilter) {
13874 setOpenedFilter(null);
13875 }
13876 setIsShowingFilter(!isShowingFilter);
13877 }
13878 };
13879 const hasPrimaryOrLockedFilters = filters.some(
13880 (filter) => filter.isPrimary || filter.isLocked
13881 );
13882 const buttonComponent = /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
13883 import_components23.Button,
13884 {
13885 ref: buttonRef,
13886 className: "dataviews-filters__visibility-toggle",
13887 size: "compact",
13888 icon: funnel_default,
13889 disabled: hasPrimaryOrLockedFilters,
13890 accessibleWhenDisabled: true,
13891 ...hasVisibleFilters ? toggleFiltersButtonProps : addFilterButtonProps
13892 }
13893 );
13894 return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)("div", { className: "dataviews-filters__container-visibility-toggle", children: !hasVisibleFilters ? /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
13895 AddFilterMenu,
13896 {
13897 filters,
13898 view,
13899 onChangeView: onChangeViewWithFilterVisibility,
13900 setOpenedFilter,
13901 triggerProps: { render: buttonComponent }
13902 }
13903 ) : /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
13904 FilterVisibilityToggle,
13905 {
13906 buttonRef,
13907 filtersCount: view.filters?.length,
13908 children: buttonComponent
13909 }
13910 ) });
13911 }
13912 function FilterVisibilityToggle({
13913 buttonRef,
13914 filtersCount,
13915 children
13916 }) {
13917 (0, import_element34.useEffect)(
13918 () => () => {
13919 buttonRef.current?.focus();
13920 },
13921 [buttonRef]
13922 );
13923 return /* @__PURE__ */ (0, import_jsx_runtime69.jsxs)(import_jsx_runtime69.Fragment, { children: [
13924 children,
13925 !!filtersCount && /* @__PURE__ */ (0, import_jsx_runtime69.jsx)("span", { className: "dataviews-filters-toggle__count", children: filtersCount })
13926 ] });
13927 }
13928 var toggle_default = FiltersToggle;
13929
13930 // packages/dataviews/build-module/components/dataviews-filters/filters-toggled.mjs
13931 var import_element35 = __toESM(require_element(), 1);
13932 var import_jsx_runtime70 = __toESM(require_jsx_runtime(), 1);
13933 function FiltersToggled(props) {
13934 const { isShowingFilter } = (0, import_element35.useContext)(dataviews_context_default);
13935 if (!isShowingFilter) {
13936 return null;
13937 }
13938 return /* @__PURE__ */ (0, import_jsx_runtime70.jsx)(filters_default, { ...props });
13939 }
13940 var filters_toggled_default = FiltersToggled;
13941
13942 // packages/dataviews/build-module/components/dataviews-layout/index.mjs
13943 var import_element36 = __toESM(require_element(), 1);
13944 var import_components24 = __toESM(require_components(), 1);
13945 var import_i18n34 = __toESM(require_i18n(), 1);
13946 var import_jsx_runtime71 = __toESM(require_jsx_runtime(), 1);
13947 function DataViewsLayout({ className }) {
13948 const {
13949 actions = [],
13950 data,
13951 fields,
13952 getItemId,
13953 getItemLevel,
13954 hasInitiallyLoaded,
13955 isLoading,
13956 view,
13957 onChangeView,
13958 selection,
13959 onChangeSelection,
13960 setOpenedFilter,
13961 onClickItem,
13962 isItemClickable: isItemClickable2,
13963 renderItemLink,
13964 defaultLayouts: defaultLayouts2,
13965 containerRef,
13966 empty = /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("p", { children: (0, import_i18n34.__)("No results") })
13967 } = (0, import_element36.useContext)(dataviews_context_default);
13968 const isDelayedInitialLoading = useDelayedLoading(!hasInitiallyLoaded, {
13969 delay: 200
13970 });
13971 if (!hasInitiallyLoaded) {
13972 if (!isDelayedInitialLoading) {
13973 return null;
13974 }
13975 return /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("div", { className: "dataviews-loading", children: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(import_components24.Spinner, {}) }) });
13976 }
13977 const ViewComponent = VIEW_LAYOUTS.find(
13978 (v2) => v2.type === view.type && defaultLayouts2[v2.type]
13979 )?.component;
13980 return /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("div", { className: "dataviews-layout__container", ref: containerRef, children: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(
13981 ViewComponent,
13982 {
13983 className,
13984 actions,
13985 data,
13986 fields,
13987 getItemId,
13988 getItemLevel,
13989 isLoading,
13990 onChangeView,
13991 onChangeSelection,
13992 selection,
13993 setOpenedFilter,
13994 onClickItem,
13995 renderItemLink,
13996 isItemClickable: isItemClickable2,
13997 view,
13998 empty
13999 }
14000 ) });
14001 }
14002
14003 // packages/dataviews/build-module/components/dataviews-search/index.mjs
14004 var import_i18n35 = __toESM(require_i18n(), 1);
14005 var import_element37 = __toESM(require_element(), 1);
14006 var import_components25 = __toESM(require_components(), 1);
14007 var import_compose9 = __toESM(require_compose(), 1);
14008 var import_jsx_runtime72 = __toESM(require_jsx_runtime(), 1);
14009 var DataViewsSearch = (0, import_element37.memo)(function Search({ label }) {
14010 const { view, onChangeView } = (0, import_element37.useContext)(dataviews_context_default);
14011 const [search, setSearch, debouncedSearch] = (0, import_compose9.useDebouncedInput)(
14012 view.search
14013 );
14014 (0, import_element37.useEffect)(() => {
14015 if (view.search !== debouncedSearch) {
14016 setSearch(view.search ?? "");
14017 }
14018 }, [view.search, setSearch]);
14019 const onChangeViewRef = (0, import_element37.useRef)(onChangeView);
14020 const viewRef = (0, import_element37.useRef)(view);
14021 (0, import_element37.useEffect)(() => {
14022 onChangeViewRef.current = onChangeView;
14023 viewRef.current = view;
14024 }, [onChangeView, view]);
14025 (0, import_element37.useEffect)(() => {
14026 if (debouncedSearch !== viewRef.current?.search) {
14027 onChangeViewRef.current({
14028 ...viewRef.current,
14029 page: view.page ? 1 : void 0,
14030 startPosition: view.startPosition ? 1 : void 0,
14031 search: debouncedSearch
14032 });
14033 }
14034 }, [debouncedSearch]);
14035 const searchLabel = label || (0, import_i18n35.__)("Search");
14036 return /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
14037 import_components25.SearchControl,
14038 {
14039 className: "dataviews-search",
14040 onChange: setSearch,
14041 value: search,
14042 label: searchLabel,
14043 placeholder: searchLabel,
14044 size: "compact"
14045 }
14046 );
14047 });
14048 var dataviews_search_default = DataViewsSearch;
14049
14050 // packages/dataviews/build-module/components/dataviews-view-config/index.mjs
14051 var import_components26 = __toESM(require_components(), 1);
14052 var import_i18n36 = __toESM(require_i18n(), 1);
14053 var import_element38 = __toESM(require_element(), 1);
14054 var import_warning = __toESM(require_warning(), 1);
14055 var import_compose10 = __toESM(require_compose(), 1);
14056 var import_jsx_runtime73 = __toESM(require_jsx_runtime(), 1);
14057 var { Menu: Menu5 } = unlock(import_components26.privateApis);
14058 var DATAVIEWS_CONFIG_POPOVER_PROPS = {
14059 className: "dataviews-config__popover",
14060 placement: "bottom-end",
14061 offset: 9
14062 };
14063 function ViewTypeMenu() {
14064 const { view, onChangeView, defaultLayouts: defaultLayouts2 } = (0, import_element38.useContext)(dataviews_context_default);
14065 const availableLayouts = Object.keys(defaultLayouts2);
14066 if (availableLayouts.length <= 1) {
14067 return null;
14068 }
14069 const activeView = VIEW_LAYOUTS.find((v2) => view.type === v2.type);
14070 return /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(Menu5, { children: [
14071 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14072 Menu5.TriggerButton,
14073 {
14074 render: /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14075 import_components26.Button,
14076 {
14077 size: "compact",
14078 icon: activeView?.icon,
14079 label: (0, import_i18n36.__)("Layout")
14080 }
14081 )
14082 }
14083 ),
14084 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(Menu5.Popover, { children: availableLayouts.map((layout) => {
14085 const config = VIEW_LAYOUTS.find(
14086 (v2) => v2.type === layout
14087 );
14088 if (!config) {
14089 return null;
14090 }
14091 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14092 Menu5.RadioItem,
14093 {
14094 value: layout,
14095 name: "view-actions-available-view",
14096 checked: layout === view.type,
14097 hideOnClick: true,
14098 onChange: (e2) => {
14099 switch (e2.target.value) {
14100 case "list":
14101 case "grid":
14102 case "table":
14103 case "pickerGrid":
14104 case "pickerTable":
14105 case "activity":
14106 const viewWithoutLayout = { ...view };
14107 if ("layout" in viewWithoutLayout) {
14108 delete viewWithoutLayout.layout;
14109 }
14110 return onChangeView({
14111 ...viewWithoutLayout,
14112 type: e2.target.value,
14113 ...defaultLayouts2[e2.target.value]
14114 });
14115 }
14116 (0, import_warning.default)("Invalid dataview");
14117 },
14118 children: /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(Menu5.ItemLabel, { children: config.label })
14119 },
14120 layout
14121 );
14122 }) })
14123 ] });
14124 }
14125 function SortFieldControl() {
14126 const { view, fields, onChangeView } = (0, import_element38.useContext)(dataviews_context_default);
14127 const orderOptions = (0, import_element38.useMemo)(() => {
14128 const sortableFields = fields.filter(
14129 (field) => field.enableSorting !== false
14130 );
14131 return sortableFields.map((field) => {
14132 return {
14133 label: field.label,
14134 value: field.id
14135 };
14136 });
14137 }, [fields]);
14138 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14139 import_components26.SelectControl,
14140 {
14141 __next40pxDefaultSize: true,
14142 label: (0, import_i18n36.__)("Sort by"),
14143 value: view.sort?.field,
14144 options: orderOptions,
14145 onChange: (value) => {
14146 onChangeView({
14147 ...view,
14148 sort: {
14149 direction: view?.sort?.direction || "desc",
14150 field: value
14151 },
14152 showLevels: false
14153 });
14154 }
14155 }
14156 );
14157 }
14158 function SortDirectionControl() {
14159 const { view, fields, onChangeView } = (0, import_element38.useContext)(dataviews_context_default);
14160 const sortableFields = fields.filter(
14161 (field) => field.enableSorting !== false
14162 );
14163 if (sortableFields.length === 0) {
14164 return null;
14165 }
14166 let value = view.sort?.direction;
14167 if (!value && view.sort?.field) {
14168 value = "desc";
14169 }
14170 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14171 import_components26.__experimentalToggleGroupControl,
14172 {
14173 className: "dataviews-view-config__sort-direction",
14174 __next40pxDefaultSize: true,
14175 isBlock: true,
14176 label: (0, import_i18n36.__)("Order"),
14177 value,
14178 onChange: (newDirection) => {
14179 if (newDirection === "asc" || newDirection === "desc") {
14180 onChangeView({
14181 ...view,
14182 sort: {
14183 direction: newDirection,
14184 field: view.sort?.field || // If there is no field assigned as the sorting field assign the first sortable field.
14185 fields.find(
14186 (field) => field.enableSorting !== false
14187 )?.id || ""
14188 },
14189 showLevels: false
14190 });
14191 return;
14192 }
14193 (0, import_warning.default)("Invalid direction");
14194 },
14195 children: SORTING_DIRECTIONS.map((direction) => {
14196 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14197 import_components26.__experimentalToggleGroupControlOptionIcon,
14198 {
14199 value: direction,
14200 icon: sortIcons[direction],
14201 label: sortLabels[direction]
14202 },
14203 direction
14204 );
14205 })
14206 }
14207 );
14208 }
14209 function ItemsPerPageControl() {
14210 const { view, config, onChangeView } = (0, import_element38.useContext)(dataviews_context_default);
14211 const { infiniteScrollEnabled } = view;
14212 if (!config || !config.perPageSizes || config.perPageSizes.length < 2 || config.perPageSizes.length > 6 || infiniteScrollEnabled) {
14213 return null;
14214 }
14215 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14216 import_components26.__experimentalToggleGroupControl,
14217 {
14218 __next40pxDefaultSize: true,
14219 isBlock: true,
14220 label: (0, import_i18n36.__)("Items per page"),
14221 value: view.perPage || 10,
14222 disabled: !view?.sort?.field,
14223 onChange: (newItemsPerPage) => {
14224 const newItemsPerPageNumber = typeof newItemsPerPage === "number" || newItemsPerPage === void 0 ? newItemsPerPage : parseInt(newItemsPerPage, 10);
14225 onChangeView({
14226 ...view,
14227 perPage: newItemsPerPageNumber,
14228 page: 1
14229 });
14230 },
14231 children: config.perPageSizes.map((value) => {
14232 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14233 import_components26.__experimentalToggleGroupControlOption,
14234 {
14235 value,
14236 label: value.toString()
14237 },
14238 value
14239 );
14240 })
14241 }
14242 );
14243 }
14244 function ResetViewButton() {
14245 const { onReset } = (0, import_element38.useContext)(dataviews_context_default);
14246 if (onReset === void 0) {
14247 return null;
14248 }
14249 const isDisabled = onReset === false;
14250 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14251 import_components26.Button,
14252 {
14253 variant: "tertiary",
14254 size: "compact",
14255 disabled: isDisabled,
14256 accessibleWhenDisabled: true,
14257 className: "dataviews-view-config__reset-button",
14258 onClick: () => {
14259 if (typeof onReset === "function") {
14260 onReset();
14261 }
14262 },
14263 children: (0, import_i18n36.__)("Reset view")
14264 }
14265 );
14266 }
14267 function DataviewsViewConfigDropdown() {
14268 const { view, onReset } = (0, import_element38.useContext)(dataviews_context_default);
14269 const popoverId = (0, import_compose10.useInstanceId)(
14270 _DataViewsViewConfig,
14271 "dataviews-view-config-dropdown"
14272 );
14273 const activeLayout = VIEW_LAYOUTS.find(
14274 (layout) => layout.type === view.type
14275 );
14276 const isModified = typeof onReset === "function";
14277 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14278 import_components26.Dropdown,
14279 {
14280 expandOnMobile: true,
14281 popoverProps: {
14282 ...DATAVIEWS_CONFIG_POPOVER_PROPS,
14283 id: popoverId
14284 },
14285 renderToggle: ({ onToggle, isOpen }) => {
14286 return /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)("div", { className: "dataviews-view-config__toggle-wrapper", children: [
14287 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14288 import_components26.Button,
14289 {
14290 size: "compact",
14291 icon: cog_default,
14292 label: (0, import_i18n36._x)(
14293 "View options",
14294 "View is used as a noun"
14295 ),
14296 onClick: onToggle,
14297 "aria-expanded": isOpen ? "true" : "false",
14298 "aria-controls": popoverId
14299 }
14300 ),
14301 isModified && /* @__PURE__ */ (0, import_jsx_runtime73.jsx)("span", { className: "dataviews-view-config__modified-indicator" })
14302 ] });
14303 },
14304 renderContent: () => /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14305 import_components26.__experimentalDropdownContentWrapper,
14306 {
14307 paddingSize: "medium",
14308 className: "dataviews-config__popover-content-wrapper",
14309 children: /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
14310 Stack,
14311 {
14312 direction: "column",
14313 className: "dataviews-view-config",
14314 gap: "xl",
14315 children: [
14316 /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
14317 Stack,
14318 {
14319 direction: "row",
14320 justify: "space-between",
14321 align: "center",
14322 className: "dataviews-view-config__header",
14323 children: [
14324 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14325 import_components26.__experimentalHeading,
14326 {
14327 level: 2,
14328 className: "dataviews-settings-section__title",
14329 children: (0, import_i18n36.__)("Appearance")
14330 }
14331 ),
14332 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(ResetViewButton, {})
14333 ]
14334 }
14335 ),
14336 /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(Stack, { direction: "column", gap: "lg", children: [
14337 /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
14338 Stack,
14339 {
14340 direction: "row",
14341 gap: "sm",
14342 className: "dataviews-view-config__sort-controls",
14343 children: [
14344 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(SortFieldControl, {}),
14345 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(SortDirectionControl, {})
14346 ]
14347 }
14348 ),
14349 !!activeLayout?.viewConfigOptions && /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(activeLayout.viewConfigOptions, {}),
14350 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(ItemsPerPageControl, {}),
14351 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(PropertiesSection, {})
14352 ] })
14353 ]
14354 }
14355 )
14356 }
14357 )
14358 }
14359 );
14360 }
14361 function _DataViewsViewConfig() {
14362 return /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(import_jsx_runtime73.Fragment, { children: [
14363 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(ViewTypeMenu, {}),
14364 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(DataviewsViewConfigDropdown, {})
14365 ] });
14366 }
14367 var DataViewsViewConfig = (0, import_element38.memo)(_DataViewsViewConfig);
14368 var dataviews_view_config_default = DataViewsViewConfig;
14369
14370 // packages/dataviews/build-module/components/dataform-controls/checkbox.mjs
14371 var import_components27 = __toESM(require_components(), 1);
14372 var import_element39 = __toESM(require_element(), 1);
14373
14374 // packages/dataviews/build-module/components/dataform-controls/utils/get-custom-validity.mjs
14375 function getCustomValidity(isValid2, validity) {
14376 let customValidity;
14377 if (isValid2?.required && validity?.required) {
14378 customValidity = validity?.required?.message ? validity.required : void 0;
14379 } else if (isValid2?.pattern && validity?.pattern) {
14380 customValidity = validity.pattern;
14381 } else if (isValid2?.min && validity?.min) {
14382 customValidity = validity.min;
14383 } else if (isValid2?.max && validity?.max) {
14384 customValidity = validity.max;
14385 } else if (isValid2?.minLength && validity?.minLength) {
14386 customValidity = validity.minLength;
14387 } else if (isValid2?.maxLength && validity?.maxLength) {
14388 customValidity = validity.maxLength;
14389 } else if (isValid2?.elements && validity?.elements) {
14390 customValidity = validity.elements;
14391 } else if (validity?.custom) {
14392 customValidity = validity.custom;
14393 }
14394 return customValidity;
14395 }
14396
14397 // packages/dataviews/build-module/components/dataform-controls/checkbox.mjs
14398 var import_jsx_runtime74 = __toESM(require_jsx_runtime(), 1);
14399 var { ValidatedCheckboxControl } = unlock(import_components27.privateApis);
14400 function Checkbox({
14401 field,
14402 onChange,
14403 data,
14404 hideLabelFromVision,
14405 markWhenOptional,
14406 validity
14407 }) {
14408 const { getValue, setValue, label, description, isValid: isValid2 } = field;
14409 const disabled = field.isDisabled({ item: data, field });
14410 const onChangeControl = (0, import_element39.useCallback)(() => {
14411 onChange(
14412 setValue({ item: data, value: !getValue({ item: data }) })
14413 );
14414 }, [data, getValue, onChange, setValue]);
14415 return /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(
14416 ValidatedCheckboxControl,
14417 {
14418 required: !!field.isValid?.required,
14419 markWhenOptional,
14420 customValidity: getCustomValidity(isValid2, validity),
14421 hidden: hideLabelFromVision,
14422 label,
14423 help: description,
14424 checked: getValue({ item: data }),
14425 onChange: onChangeControl,
14426 disabled
14427 }
14428 );
14429 }
14430
14431 // packages/dataviews/build-module/components/dataform-controls/combobox.mjs
14432 var import_components28 = __toESM(require_components(), 1);
14433 var import_element40 = __toESM(require_element(), 1);
14434 var import_jsx_runtime75 = __toESM(require_jsx_runtime(), 1);
14435 var { ValidatedComboboxControl } = unlock(import_components28.privateApis);
14436 function Combobox3({
14437 data,
14438 field,
14439 onChange,
14440 hideLabelFromVision,
14441 validity
14442 }) {
14443 const { label, description, placeholder, getValue, setValue, isValid: isValid2 } = field;
14444 const value = getValue({ item: data }) ?? "";
14445 const onChangeControl = (0, import_element40.useCallback)(
14446 (newValue) => onChange(setValue({ item: data, value: newValue ?? "" })),
14447 [data, onChange, setValue]
14448 );
14449 const { elements, isLoading } = useElements({
14450 elements: field.elements,
14451 getElements: field.getElements
14452 });
14453 if (isLoading) {
14454 return /* @__PURE__ */ (0, import_jsx_runtime75.jsx)(import_components28.Spinner, {});
14455 }
14456 return /* @__PURE__ */ (0, import_jsx_runtime75.jsx)(
14457 ValidatedComboboxControl,
14458 {
14459 required: !!field.isValid?.required,
14460 customValidity: getCustomValidity(isValid2, validity),
14461 label,
14462 value,
14463 help: description,
14464 placeholder,
14465 options: elements,
14466 onChange: onChangeControl,
14467 hideLabelFromVision,
14468 allowReset: true,
14469 expandOnFocus: true
14470 }
14471 );
14472 }
14473
14474 // packages/dataviews/build-module/components/dataform-controls/datetime.mjs
14475 var import_components30 = __toESM(require_components(), 1);
14476 var import_element43 = __toESM(require_element(), 1);
14477 var import_i18n38 = __toESM(require_i18n(), 1);
14478 var import_date3 = __toESM(require_date(), 1);
14479
14480 // packages/dataviews/build-module/components/dataform-controls/utils/relative-date-control.mjs
14481 var import_components29 = __toESM(require_components(), 1);
14482 var import_element41 = __toESM(require_element(), 1);
14483 var import_i18n37 = __toESM(require_i18n(), 1);
14484 var import_jsx_runtime76 = __toESM(require_jsx_runtime(), 1);
14485 var TIME_UNITS_OPTIONS = {
14486 [OPERATOR_IN_THE_PAST]: [
14487 { value: "days", label: (0, import_i18n37.__)("Days") },
14488 { value: "weeks", label: (0, import_i18n37.__)("Weeks") },
14489 { value: "months", label: (0, import_i18n37.__)("Months") },
14490 { value: "years", label: (0, import_i18n37.__)("Years") }
14491 ],
14492 [OPERATOR_OVER]: [
14493 { value: "days", label: (0, import_i18n37.__)("Days ago") },
14494 { value: "weeks", label: (0, import_i18n37.__)("Weeks ago") },
14495 { value: "months", label: (0, import_i18n37.__)("Months ago") },
14496 { value: "years", label: (0, import_i18n37.__)("Years ago") }
14497 ]
14498 };
14499 function RelativeDateControl({
14500 className,
14501 data,
14502 field,
14503 onChange,
14504 hideLabelFromVision,
14505 operator
14506 }) {
14507 const options = TIME_UNITS_OPTIONS[operator === OPERATOR_IN_THE_PAST ? "inThePast" : "over"];
14508 const { id, label, description, getValue, setValue } = field;
14509 const disabled = field.isDisabled({ item: data, field });
14510 const fieldValue = getValue({ item: data });
14511 const { value: relValue = "", unit = options[0].value } = fieldValue && typeof fieldValue === "object" ? fieldValue : {};
14512 const onChangeValue = (0, import_element41.useCallback)(
14513 (newValue) => onChange(
14514 setValue({
14515 item: data,
14516 value: { value: Number(newValue), unit }
14517 })
14518 ),
14519 [onChange, setValue, data, unit]
14520 );
14521 const onChangeUnit = (0, import_element41.useCallback)(
14522 (newUnit) => onChange(
14523 setValue({
14524 item: data,
14525 value: { value: relValue, unit: newUnit }
14526 })
14527 ),
14528 [onChange, setValue, data, relValue]
14529 );
14530 return /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14531 import_components29.BaseControl,
14532 {
14533 id,
14534 className: clsx_default(className, "dataviews-controls__relative-date"),
14535 label,
14536 hideLabelFromVision,
14537 help: description,
14538 children: /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)(Stack, { direction: "row", gap: "sm", children: [
14539 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14540 import_components29.__experimentalNumberControl,
14541 {
14542 __next40pxDefaultSize: true,
14543 className: "dataviews-controls__relative-date-number",
14544 spinControls: "none",
14545 min: 1,
14546 step: 1,
14547 value: relValue,
14548 onChange: onChangeValue,
14549 disabled
14550 }
14551 ),
14552 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14553 import_components29.SelectControl,
14554 {
14555 className: "dataviews-controls__relative-date-unit",
14556 __next40pxDefaultSize: true,
14557 label: (0, import_i18n37.__)("Unit"),
14558 value: unit,
14559 options,
14560 onChange: onChangeUnit,
14561 hideLabelFromVision: true,
14562 disabled
14563 }
14564 )
14565 ] })
14566 }
14567 );
14568 }
14569
14570 // packages/dataviews/build-module/components/dataform-controls/utils/use-disabled-date-matchers.mjs
14571 var import_element42 = __toESM(require_element(), 1);
14572 function useDisabledDateMatchers(isValid2, parseDateFn) {
14573 const minConstraint = typeof isValid2.min?.constraint === "string" ? isValid2.min.constraint : void 0;
14574 const maxConstraint = typeof isValid2.max?.constraint === "string" ? isValid2.max.constraint : void 0;
14575 const disabledMatchers = (0, import_element42.useMemo)(() => {
14576 const matchers = [];
14577 if (minConstraint) {
14578 const minDate = parseDateFn(minConstraint);
14579 if (minDate) {
14580 matchers.push({ before: minDate });
14581 }
14582 }
14583 if (maxConstraint) {
14584 const maxDate = parseDateFn(maxConstraint);
14585 if (maxDate) {
14586 matchers.push({ after: maxDate });
14587 }
14588 }
14589 return matchers.length > 0 ? matchers : void 0;
14590 }, [minConstraint, maxConstraint, parseDateFn]);
14591 return { minConstraint, maxConstraint, disabledMatchers };
14592 }
14593
14594 // packages/dataviews/build-module/field-types/utils/parse-date-time.mjs
14595 var import_date2 = __toESM(require_date(), 1);
14596 function parseDateTime(dateTimeString) {
14597 if (!dateTimeString) {
14598 return null;
14599 }
14600 const parsed = (0, import_date2.getDate)(dateTimeString);
14601 return parsed && isValid(parsed) ? parsed : null;
14602 }
14603
14604 // packages/dataviews/build-module/components/dataform-controls/datetime.mjs
14605 var import_jsx_runtime77 = __toESM(require_jsx_runtime(), 1);
14606 var { DateCalendar, ValidatedInputControl } = unlock(import_components30.privateApis);
14607 var formatDateTime = (value) => {
14608 if (!value) {
14609 return "";
14610 }
14611 return (0, import_date3.dateI18n)("Y-m-d\\TH:i", (0, import_date3.getDate)(value));
14612 };
14613 function CalendarDateTimeControl({
14614 data,
14615 field,
14616 onChange,
14617 hideLabelFromVision,
14618 markWhenOptional,
14619 validity,
14620 config
14621 }) {
14622 const { compact } = config || {};
14623 const { id, label, description, setValue, getValue, isValid: isValid2 } = field;
14624 const disabled = field.isDisabled({ item: data, field });
14625 const fieldValue = getValue({ item: data });
14626 const value = typeof fieldValue === "string" ? fieldValue : void 0;
14627 const [calendarMonth, setCalendarMonth] = (0, import_element43.useState)(() => {
14628 const parsedDate = parseDateTime(value);
14629 return parsedDate || /* @__PURE__ */ new Date();
14630 });
14631 const inputControlRef = (0, import_element43.useRef)(null);
14632 const validationTimeoutRef = (0, import_element43.useRef)(void 0);
14633 const previousFocusRef = (0, import_element43.useRef)(null);
14634 const { minConstraint, maxConstraint, disabledMatchers } = useDisabledDateMatchers(isValid2, parseDateTime);
14635 const onChangeCallback = (0, import_element43.useCallback)(
14636 (newValue) => onChange(setValue({ item: data, value: newValue })),
14637 [data, onChange, setValue]
14638 );
14639 (0, import_element43.useEffect)(() => {
14640 return () => {
14641 if (validationTimeoutRef.current) {
14642 clearTimeout(validationTimeoutRef.current);
14643 }
14644 };
14645 }, []);
14646 const onSelectDate = (0, import_element43.useCallback)(
14647 (newDate) => {
14648 let dateTimeValue;
14649 if (newDate) {
14650 const wpDate = (0, import_date3.dateI18n)("Y-m-d", newDate);
14651 let wpTime;
14652 if (value) {
14653 wpTime = (0, import_date3.dateI18n)("H:i", (0, import_date3.getDate)(value));
14654 } else {
14655 wpTime = (0, import_date3.dateI18n)("H:i", newDate);
14656 }
14657 const finalDateTime = (0, import_date3.getDate)(`${wpDate}T${wpTime}`);
14658 dateTimeValue = finalDateTime.toISOString();
14659 onChangeCallback(dateTimeValue);
14660 if (validationTimeoutRef.current) {
14661 clearTimeout(validationTimeoutRef.current);
14662 }
14663 } else {
14664 onChangeCallback(void 0);
14665 }
14666 previousFocusRef.current = inputControlRef.current && inputControlRef.current.ownerDocument.activeElement;
14667 validationTimeoutRef.current = setTimeout(() => {
14668 if (inputControlRef.current) {
14669 inputControlRef.current.focus();
14670 inputControlRef.current.blur();
14671 onChangeCallback(dateTimeValue);
14672 if (previousFocusRef.current && previousFocusRef.current instanceof HTMLElement) {
14673 previousFocusRef.current.focus();
14674 }
14675 }
14676 }, 0);
14677 },
14678 [onChangeCallback, value]
14679 );
14680 const handleManualDateTimeChange = (0, import_element43.useCallback)(
14681 (newValue) => {
14682 if (newValue) {
14683 const dateTime = (0, import_date3.getDate)(newValue);
14684 onChangeCallback(dateTime.toISOString());
14685 const parsedDate = parseDateTime(dateTime.toISOString());
14686 if (parsedDate) {
14687 setCalendarMonth(parsedDate);
14688 }
14689 } else {
14690 onChangeCallback(void 0);
14691 }
14692 },
14693 [onChangeCallback]
14694 );
14695 const { format: fieldFormat } = field;
14696 const weekStartsOn = fieldFormat.weekStartsOn ?? (0, import_date3.getSettings)().l10n.startOfWeek;
14697 const {
14698 timezone: { string: timezoneString }
14699 } = (0, import_date3.getSettings)();
14700 let displayLabel = label;
14701 if (isValid2?.required && !markWhenOptional && !hideLabelFromVision) {
14702 displayLabel = `${label} (${(0, import_i18n38.__)("Required")})`;
14703 } else if (!isValid2?.required && markWhenOptional && !hideLabelFromVision) {
14704 displayLabel = `${label} (${(0, import_i18n38.__)("Optional")})`;
14705 }
14706 return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14707 import_components30.BaseControl,
14708 {
14709 id,
14710 label: displayLabel,
14711 help: description,
14712 hideLabelFromVision,
14713 children: /* @__PURE__ */ (0, import_jsx_runtime77.jsxs)(Stack, { direction: "column", gap: "lg", children: [
14714 /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14715 ValidatedInputControl,
14716 {
14717 ref: inputControlRef,
14718 __next40pxDefaultSize: true,
14719 required: !!isValid2?.required,
14720 customValidity: getCustomValidity(isValid2, validity),
14721 type: "datetime-local",
14722 label: (0, import_i18n38.__)("Date time"),
14723 hideLabelFromVision: true,
14724 value: formatDateTime(value),
14725 onChange: handleManualDateTimeChange,
14726 disabled,
14727 min: minConstraint ? formatDateTime(minConstraint) : void 0,
14728 max: maxConstraint ? formatDateTime(maxConstraint) : void 0
14729 }
14730 ),
14731 !compact && /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14732 DateCalendar,
14733 {
14734 style: { width: "100%" },
14735 selected: value ? parseDateTime(value) || void 0 : void 0,
14736 onSelect: onSelectDate,
14737 month: calendarMonth,
14738 onMonthChange: setCalendarMonth,
14739 timeZone: timezoneString || void 0,
14740 weekStartsOn,
14741 disabled: disabled || disabledMatchers
14742 }
14743 )
14744 ] })
14745 }
14746 );
14747 }
14748 function DateTime({
14749 data,
14750 field,
14751 onChange,
14752 hideLabelFromVision,
14753 markWhenOptional,
14754 operator,
14755 validity,
14756 config
14757 }) {
14758 if (operator === OPERATOR_IN_THE_PAST || operator === OPERATOR_OVER) {
14759 return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14760 RelativeDateControl,
14761 {
14762 className: "dataviews-controls__datetime",
14763 data,
14764 field,
14765 onChange,
14766 hideLabelFromVision,
14767 operator
14768 }
14769 );
14770 }
14771 return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14772 CalendarDateTimeControl,
14773 {
14774 data,
14775 field,
14776 onChange,
14777 hideLabelFromVision,
14778 markWhenOptional,
14779 validity,
14780 config
14781 }
14782 );
14783 }
14784
14785 // packages/dataviews/build-module/components/dataform-controls/date.mjs
14786 var import_components31 = __toESM(require_components(), 1);
14787 var import_element44 = __toESM(require_element(), 1);
14788 var import_i18n39 = __toESM(require_i18n(), 1);
14789 var import_date4 = __toESM(require_date(), 1);
14790 var import_jsx_runtime78 = __toESM(require_jsx_runtime(), 1);
14791 var { DateCalendar: DateCalendar2, DateRangeCalendar } = unlock(import_components31.privateApis);
14792 var DATE_PRESETS = [
14793 {
14794 id: "today",
14795 label: (0, import_i18n39.__)("Today"),
14796 getValue: () => (0, import_date4.getDate)(null)
14797 },
14798 {
14799 id: "yesterday",
14800 label: (0, import_i18n39.__)("Yesterday"),
14801 getValue: () => {
14802 const today = (0, import_date4.getDate)(null);
14803 return subDays(today, 1);
14804 }
14805 },
14806 {
14807 id: "past-week",
14808 label: (0, import_i18n39.__)("Past week"),
14809 getValue: () => {
14810 const today = (0, import_date4.getDate)(null);
14811 return subDays(today, 7);
14812 }
14813 },
14814 {
14815 id: "past-month",
14816 label: (0, import_i18n39.__)("Past month"),
14817 getValue: () => {
14818 const today = (0, import_date4.getDate)(null);
14819 return subMonths(today, 1);
14820 }
14821 }
14822 ];
14823 var DATE_RANGE_PRESETS = [
14824 {
14825 id: "last-7-days",
14826 label: (0, import_i18n39.__)("Last 7 days"),
14827 getValue: () => {
14828 const today = (0, import_date4.getDate)(null);
14829 return [subDays(today, 7), today];
14830 }
14831 },
14832 {
14833 id: "last-30-days",
14834 label: (0, import_i18n39.__)("Last 30 days"),
14835 getValue: () => {
14836 const today = (0, import_date4.getDate)(null);
14837 return [subDays(today, 30), today];
14838 }
14839 },
14840 {
14841 id: "month-to-date",
14842 label: (0, import_i18n39.__)("Month to date"),
14843 getValue: () => {
14844 const today = (0, import_date4.getDate)(null);
14845 return [startOfMonth(today), today];
14846 }
14847 },
14848 {
14849 id: "last-year",
14850 label: (0, import_i18n39.__)("Last year"),
14851 getValue: () => {
14852 const today = (0, import_date4.getDate)(null);
14853 return [subYears(today, 1), today];
14854 }
14855 },
14856 {
14857 id: "year-to-date",
14858 label: (0, import_i18n39.__)("Year to date"),
14859 getValue: () => {
14860 const today = (0, import_date4.getDate)(null);
14861 return [startOfYear(today), today];
14862 }
14863 }
14864 ];
14865 var parseDate = (dateString) => {
14866 if (!dateString) {
14867 return null;
14868 }
14869 const parsed = (0, import_date4.getDate)(dateString);
14870 return parsed && isValid(parsed) ? parsed : null;
14871 };
14872 var formatDate = (date) => {
14873 if (!date) {
14874 return "";
14875 }
14876 return typeof date === "string" ? date : format(date, "yyyy-MM-dd");
14877 };
14878 function ValidatedDateControl({
14879 field,
14880 validity,
14881 inputRefs,
14882 isTouched,
14883 setIsTouched,
14884 children
14885 }) {
14886 const { isValid: isValid2 } = field;
14887 const [customValidity, setCustomValidity] = (0, import_element44.useState)(void 0);
14888 const validateRefs = (0, import_element44.useCallback)(() => {
14889 const refs = Array.isArray(inputRefs) ? inputRefs : [inputRefs];
14890 for (const ref of refs) {
14891 const input = ref.current;
14892 if (input && !input.validity.valid) {
14893 setCustomValidity({
14894 type: "invalid",
14895 message: input.validationMessage
14896 });
14897 return;
14898 }
14899 }
14900 setCustomValidity(void 0);
14901 }, [inputRefs]);
14902 (0, import_element44.useEffect)(() => {
14903 const refs = Array.isArray(inputRefs) ? inputRefs : [inputRefs];
14904 const result = validity ? getCustomValidity(isValid2, validity) : void 0;
14905 for (const ref of refs) {
14906 const input = ref.current;
14907 if (input) {
14908 input.setCustomValidity(
14909 result?.type === "invalid" && result.message ? result.message : ""
14910 );
14911 }
14912 }
14913 }, [inputRefs, isValid2, validity]);
14914 (0, import_element44.useEffect)(() => {
14915 const refs = Array.isArray(inputRefs) ? inputRefs : [inputRefs];
14916 const handleInvalid = (event) => {
14917 event.preventDefault();
14918 setIsTouched(true);
14919 };
14920 for (const ref of refs) {
14921 ref.current?.addEventListener("invalid", handleInvalid);
14922 }
14923 return () => {
14924 for (const ref of refs) {
14925 ref.current?.removeEventListener("invalid", handleInvalid);
14926 }
14927 };
14928 }, [inputRefs, setIsTouched]);
14929 (0, import_element44.useEffect)(() => {
14930 if (!isTouched) {
14931 return;
14932 }
14933 const result = validity ? getCustomValidity(isValid2, validity) : void 0;
14934 if (result) {
14935 setCustomValidity(result);
14936 } else {
14937 validateRefs();
14938 }
14939 }, [isTouched, isValid2, validity, validateRefs]);
14940 const onBlur = (event) => {
14941 if (isTouched) {
14942 return;
14943 }
14944 if (!event.relatedTarget || !event.currentTarget.contains(event.relatedTarget)) {
14945 setIsTouched(true);
14946 }
14947 };
14948 return /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)("div", { onBlur, children: [
14949 children,
14950 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)("div", { "aria-live": "polite", children: customValidity && /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
14951 "p",
14952 {
14953 className: clsx_default(
14954 "components-validated-control__indicator",
14955 customValidity.type === "invalid" ? "is-invalid" : void 0
14956 ),
14957 children: [
14958 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14959 import_components31.Icon,
14960 {
14961 className: "components-validated-control__indicator-icon",
14962 icon: error_default,
14963 size: 16,
14964 fill: "currentColor"
14965 }
14966 ),
14967 customValidity.message
14968 ]
14969 }
14970 ) })
14971 ] });
14972 }
14973 function CalendarDateControl({
14974 data,
14975 field,
14976 onChange,
14977 hideLabelFromVision,
14978 markWhenOptional,
14979 validity
14980 }) {
14981 const {
14982 id,
14983 label,
14984 description,
14985 setValue,
14986 getValue,
14987 isValid: isValid2,
14988 format: fieldFormat
14989 } = field;
14990 const disabled = field.isDisabled({ item: data, field });
14991 const [selectedPresetId, setSelectedPresetId] = (0, import_element44.useState)(
14992 null
14993 );
14994 const weekStartsOn = fieldFormat.weekStartsOn ?? (0, import_date4.getSettings)().l10n.startOfWeek;
14995 const fieldValue = getValue({ item: data });
14996 const value = typeof fieldValue === "string" ? fieldValue : void 0;
14997 const [calendarMonth, setCalendarMonth] = (0, import_element44.useState)(() => {
14998 const parsedDate = parseDate(value);
14999 return parsedDate || /* @__PURE__ */ new Date();
15000 });
15001 const [isTouched, setIsTouched] = (0, import_element44.useState)(false);
15002 const validityTargetRef = (0, import_element44.useRef)(null);
15003 const { minConstraint, maxConstraint, disabledMatchers } = useDisabledDateMatchers(isValid2, parseDate);
15004 const onChangeCallback = (0, import_element44.useCallback)(
15005 (newValue) => onChange(setValue({ item: data, value: newValue })),
15006 [data, onChange, setValue]
15007 );
15008 const onSelectDate = (0, import_element44.useCallback)(
15009 (newDate) => {
15010 const dateValue = newDate ? format(newDate, "yyyy-MM-dd") : void 0;
15011 onChangeCallback(dateValue);
15012 setSelectedPresetId(null);
15013 setIsTouched(true);
15014 },
15015 [onChangeCallback]
15016 );
15017 const handlePresetClick = (0, import_element44.useCallback)(
15018 (preset) => {
15019 const presetDate = preset.getValue();
15020 const dateValue = formatDate(presetDate);
15021 setCalendarMonth(presetDate);
15022 onChangeCallback(dateValue);
15023 setSelectedPresetId(preset.id);
15024 setIsTouched(true);
15025 },
15026 [onChangeCallback]
15027 );
15028 const handleManualDateChange = (0, import_element44.useCallback)(
15029 (newValue) => {
15030 onChangeCallback(newValue);
15031 if (newValue) {
15032 const parsedDate = parseDate(newValue);
15033 if (parsedDate) {
15034 setCalendarMonth(parsedDate);
15035 }
15036 }
15037 setSelectedPresetId(null);
15038 setIsTouched(true);
15039 },
15040 [onChangeCallback]
15041 );
15042 const {
15043 timezone: { string: timezoneString }
15044 } = (0, import_date4.getSettings)();
15045 let displayLabel = label;
15046 if (isValid2?.required && !markWhenOptional) {
15047 displayLabel = `${label} (${(0, import_i18n39.__)("Required")})`;
15048 } else if (!isValid2?.required && markWhenOptional) {
15049 displayLabel = `${label} (${(0, import_i18n39.__)("Optional")})`;
15050 }
15051 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15052 ValidatedDateControl,
15053 {
15054 field,
15055 validity,
15056 inputRefs: validityTargetRef,
15057 isTouched,
15058 setIsTouched,
15059 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15060 import_components31.BaseControl,
15061 {
15062 id,
15063 className: "dataviews-controls__date",
15064 label: displayLabel,
15065 help: description,
15066 hideLabelFromVision,
15067 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(Stack, { direction: "column", gap: "lg", children: [
15068 /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
15069 Stack,
15070 {
15071 direction: "row",
15072 gap: "sm",
15073 wrap: "wrap",
15074 justify: "flex-start",
15075 children: [
15076 DATE_PRESETS.map((preset) => {
15077 const isSelected2 = selectedPresetId === preset.id;
15078 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15079 import_components31.Button,
15080 {
15081 className: "dataviews-controls__date-preset",
15082 variant: "tertiary",
15083 isPressed: isSelected2,
15084 size: "small",
15085 disabled,
15086 accessibleWhenDisabled: true,
15087 onClick: () => handlePresetClick(preset),
15088 children: preset.label
15089 },
15090 preset.id
15091 );
15092 }),
15093 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15094 import_components31.Button,
15095 {
15096 className: "dataviews-controls__date-preset",
15097 variant: "tertiary",
15098 isPressed: !selectedPresetId,
15099 size: "small",
15100 disabled: !!selectedPresetId || disabled,
15101 accessibleWhenDisabled: true,
15102 children: (0, import_i18n39.__)("Custom")
15103 }
15104 )
15105 ]
15106 }
15107 ),
15108 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15109 import_components31.__experimentalInputControl,
15110 {
15111 __next40pxDefaultSize: true,
15112 ref: validityTargetRef,
15113 type: "date",
15114 label: (0, import_i18n39.__)("Date"),
15115 hideLabelFromVision: true,
15116 value,
15117 onChange: handleManualDateChange,
15118 required: !!field.isValid?.required,
15119 disabled,
15120 min: minConstraint,
15121 max: maxConstraint
15122 }
15123 ),
15124 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15125 DateCalendar2,
15126 {
15127 style: { width: "100%" },
15128 selected: value ? parseDate(value) || void 0 : void 0,
15129 onSelect: onSelectDate,
15130 month: calendarMonth,
15131 onMonthChange: setCalendarMonth,
15132 timeZone: timezoneString || void 0,
15133 weekStartsOn,
15134 disabled: disabled || disabledMatchers,
15135 disableNavigation: disabled
15136 }
15137 )
15138 ] })
15139 }
15140 )
15141 }
15142 );
15143 }
15144 function CalendarDateRangeControl({
15145 data,
15146 field,
15147 onChange,
15148 hideLabelFromVision,
15149 markWhenOptional,
15150 validity
15151 }) {
15152 const {
15153 id,
15154 label,
15155 description,
15156 getValue,
15157 setValue,
15158 isValid: isValid2,
15159 format: fieldFormat
15160 } = field;
15161 const disabled = field.isDisabled({ item: data, field });
15162 let value;
15163 const fieldValue = getValue({ item: data });
15164 if (Array.isArray(fieldValue) && fieldValue.length === 2 && fieldValue.every((date) => typeof date === "string")) {
15165 value = fieldValue;
15166 }
15167 const weekStartsOn = fieldFormat.weekStartsOn ?? (0, import_date4.getSettings)().l10n.startOfWeek;
15168 const { minConstraint, maxConstraint, disabledMatchers } = useDisabledDateMatchers(isValid2, parseDate);
15169 const onChangeCallback = (0, import_element44.useCallback)(
15170 (newValue) => {
15171 onChange(
15172 setValue({
15173 item: data,
15174 value: newValue
15175 })
15176 );
15177 },
15178 [data, onChange, setValue]
15179 );
15180 const [selectedPresetId, setSelectedPresetId] = (0, import_element44.useState)(
15181 null
15182 );
15183 const selectedRange = (0, import_element44.useMemo)(() => {
15184 if (!value) {
15185 return { from: void 0, to: void 0 };
15186 }
15187 const [from, to] = value;
15188 return {
15189 from: parseDate(from) || void 0,
15190 to: parseDate(to) || void 0
15191 };
15192 }, [value]);
15193 const [calendarMonth, setCalendarMonth] = (0, import_element44.useState)(() => {
15194 return selectedRange.from || /* @__PURE__ */ new Date();
15195 });
15196 const [isTouched, setIsTouched] = (0, import_element44.useState)(false);
15197 const fromInputRef = (0, import_element44.useRef)(null);
15198 const toInputRef = (0, import_element44.useRef)(null);
15199 const updateDateRange = (0, import_element44.useCallback)(
15200 (fromDate, toDate2) => {
15201 if (fromDate && toDate2) {
15202 onChangeCallback([
15203 formatDate(fromDate),
15204 formatDate(toDate2)
15205 ]);
15206 } else if (!fromDate && !toDate2) {
15207 onChangeCallback(void 0);
15208 }
15209 },
15210 [onChangeCallback]
15211 );
15212 const onSelectCalendarRange = (0, import_element44.useCallback)(
15213 (newRange) => {
15214 updateDateRange(newRange?.from, newRange?.to);
15215 setSelectedPresetId(null);
15216 setIsTouched(true);
15217 },
15218 [updateDateRange]
15219 );
15220 const handlePresetClick = (0, import_element44.useCallback)(
15221 (preset) => {
15222 const [startDate, endDate] = preset.getValue();
15223 setCalendarMonth(startDate);
15224 updateDateRange(startDate, endDate);
15225 setSelectedPresetId(preset.id);
15226 setIsTouched(true);
15227 },
15228 [updateDateRange]
15229 );
15230 const handleManualDateChange = (0, import_element44.useCallback)(
15231 (fromOrTo, newValue) => {
15232 const [currentFrom, currentTo] = value || [
15233 void 0,
15234 void 0
15235 ];
15236 const updatedFrom = fromOrTo === "from" ? newValue : currentFrom;
15237 const updatedTo = fromOrTo === "to" ? newValue : currentTo;
15238 updateDateRange(updatedFrom, updatedTo);
15239 if (newValue) {
15240 const parsedDate = parseDate(newValue);
15241 if (parsedDate) {
15242 setCalendarMonth(parsedDate);
15243 }
15244 }
15245 setSelectedPresetId(null);
15246 setIsTouched(true);
15247 },
15248 [value, updateDateRange]
15249 );
15250 const { timezone } = (0, import_date4.getSettings)();
15251 let displayLabel = label;
15252 if (field.isValid?.required && !markWhenOptional) {
15253 displayLabel = `${label} (${(0, import_i18n39.__)("Required")})`;
15254 } else if (!field.isValid?.required && markWhenOptional) {
15255 displayLabel = `${label} (${(0, import_i18n39.__)("Optional")})`;
15256 }
15257 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15258 ValidatedDateControl,
15259 {
15260 field,
15261 validity,
15262 inputRefs: [fromInputRef, toInputRef],
15263 isTouched,
15264 setIsTouched,
15265 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15266 import_components31.BaseControl,
15267 {
15268 id,
15269 className: "dataviews-controls__date",
15270 label: displayLabel,
15271 help: description,
15272 hideLabelFromVision,
15273 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(Stack, { direction: "column", gap: "lg", children: [
15274 /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
15275 Stack,
15276 {
15277 direction: "row",
15278 gap: "sm",
15279 wrap: "wrap",
15280 justify: "flex-start",
15281 children: [
15282 DATE_RANGE_PRESETS.map((preset) => {
15283 const isSelected2 = selectedPresetId === preset.id;
15284 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15285 import_components31.Button,
15286 {
15287 className: "dataviews-controls__date-preset",
15288 variant: "tertiary",
15289 isPressed: isSelected2,
15290 size: "small",
15291 disabled,
15292 accessibleWhenDisabled: true,
15293 onClick: () => handlePresetClick(preset),
15294 children: preset.label
15295 },
15296 preset.id
15297 );
15298 }),
15299 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15300 import_components31.Button,
15301 {
15302 className: "dataviews-controls__date-preset",
15303 variant: "tertiary",
15304 isPressed: !selectedPresetId,
15305 size: "small",
15306 accessibleWhenDisabled: true,
15307 disabled: !!selectedPresetId || disabled,
15308 children: (0, import_i18n39.__)("Custom")
15309 }
15310 )
15311 ]
15312 }
15313 ),
15314 /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
15315 Stack,
15316 {
15317 direction: "row",
15318 gap: "sm",
15319 justify: "space-between",
15320 className: "dataviews-controls__date-range-inputs",
15321 children: [
15322 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15323 import_components31.__experimentalInputControl,
15324 {
15325 __next40pxDefaultSize: true,
15326 ref: fromInputRef,
15327 type: "date",
15328 label: (0, import_i18n39.__)("From"),
15329 hideLabelFromVision: true,
15330 value: value?.[0],
15331 onChange: (newValue) => handleManualDateChange("from", newValue),
15332 required: !!field.isValid?.required,
15333 disabled,
15334 min: minConstraint,
15335 max: maxConstraint
15336 }
15337 ),
15338 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15339 import_components31.__experimentalInputControl,
15340 {
15341 __next40pxDefaultSize: true,
15342 ref: toInputRef,
15343 type: "date",
15344 label: (0, import_i18n39.__)("To"),
15345 hideLabelFromVision: true,
15346 value: value?.[1],
15347 onChange: (newValue) => handleManualDateChange("to", newValue),
15348 required: !!field.isValid?.required,
15349 disabled,
15350 min: minConstraint,
15351 max: maxConstraint
15352 }
15353 )
15354 ]
15355 }
15356 ),
15357 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15358 DateRangeCalendar,
15359 {
15360 style: { width: "100%" },
15361 selected: selectedRange,
15362 onSelect: onSelectCalendarRange,
15363 month: calendarMonth,
15364 onMonthChange: setCalendarMonth,
15365 timeZone: timezone.string || void 0,
15366 weekStartsOn,
15367 disabled: disabled || disabledMatchers
15368 }
15369 )
15370 ] })
15371 }
15372 )
15373 }
15374 );
15375 }
15376 function DateControl({
15377 data,
15378 field,
15379 onChange,
15380 hideLabelFromVision,
15381 markWhenOptional,
15382 operator,
15383 validity
15384 }) {
15385 if (operator === OPERATOR_IN_THE_PAST || operator === OPERATOR_OVER) {
15386 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15387 RelativeDateControl,
15388 {
15389 className: "dataviews-controls__date",
15390 data,
15391 field,
15392 onChange,
15393 hideLabelFromVision,
15394 operator
15395 }
15396 );
15397 }
15398 if (operator === OPERATOR_BETWEEN) {
15399 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15400 CalendarDateRangeControl,
15401 {
15402 data,
15403 field,
15404 onChange,
15405 hideLabelFromVision,
15406 markWhenOptional,
15407 validity
15408 }
15409 );
15410 }
15411 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15412 CalendarDateControl,
15413 {
15414 data,
15415 field,
15416 onChange,
15417 hideLabelFromVision,
15418 markWhenOptional,
15419 validity
15420 }
15421 );
15422 }
15423
15424 // packages/dataviews/build-module/components/dataform-controls/select.mjs
15425 var import_components32 = __toESM(require_components(), 1);
15426 var import_element45 = __toESM(require_element(), 1);
15427 var import_jsx_runtime79 = __toESM(require_jsx_runtime(), 1);
15428 var { ValidatedSelectControl } = unlock(import_components32.privateApis);
15429 function Select({
15430 data,
15431 field,
15432 onChange,
15433 hideLabelFromVision,
15434 markWhenOptional,
15435 validity
15436 }) {
15437 const { type, label, description, getValue, setValue, isValid: isValid2 } = field;
15438 const disabled = field.isDisabled({ item: data, field });
15439 const isMultiple = type === "array";
15440 const value = getValue({ item: data }) ?? (isMultiple ? [] : "");
15441 const onChangeControl = (0, import_element45.useCallback)(
15442 (newValue) => onChange(setValue({ item: data, value: newValue })),
15443 [data, onChange, setValue]
15444 );
15445 const { elements, isLoading } = useElements({
15446 elements: field.elements,
15447 getElements: field.getElements
15448 });
15449 if (isLoading) {
15450 return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(import_components32.Spinner, {});
15451 }
15452 return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
15453 ValidatedSelectControl,
15454 {
15455 required: !!field.isValid?.required,
15456 markWhenOptional,
15457 customValidity: getCustomValidity(isValid2, validity),
15458 label,
15459 value,
15460 help: description,
15461 options: elements,
15462 onChange: onChangeControl,
15463 __next40pxDefaultSize: true,
15464 hideLabelFromVision,
15465 multiple: isMultiple,
15466 disabled
15467 }
15468 );
15469 }
15470
15471 // packages/dataviews/build-module/components/dataform-controls/adaptive-select.mjs
15472 var import_jsx_runtime80 = __toESM(require_jsx_runtime(), 1);
15473 var ELEMENTS_THRESHOLD = 10;
15474 function AdaptiveSelect(props) {
15475 const { field } = props;
15476 const { elements } = useElements({
15477 elements: field.elements,
15478 getElements: field.getElements
15479 });
15480 if (elements.length >= ELEMENTS_THRESHOLD) {
15481 return /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(Combobox3, { ...props });
15482 }
15483 return /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(Select, { ...props });
15484 }
15485
15486 // packages/dataviews/build-module/components/dataform-controls/email.mjs
15487 var import_components34 = __toESM(require_components(), 1);
15488
15489 // packages/dataviews/build-module/components/dataform-controls/utils/validated-input.mjs
15490 var import_components33 = __toESM(require_components(), 1);
15491 var import_element46 = __toESM(require_element(), 1);
15492 var import_jsx_runtime81 = __toESM(require_jsx_runtime(), 1);
15493 var { ValidatedInputControl: ValidatedInputControl2 } = unlock(import_components33.privateApis);
15494 function ValidatedText({
15495 data,
15496 field,
15497 onChange,
15498 hideLabelFromVision,
15499 markWhenOptional,
15500 type,
15501 prefix,
15502 suffix,
15503 validity
15504 }) {
15505 const { label, placeholder, description, getValue, setValue, isValid: isValid2 } = field;
15506 const value = getValue({ item: data });
15507 const disabled = field.isDisabled({ item: data, field });
15508 const onChangeControl = (0, import_element46.useCallback)(
15509 (newValue) => onChange(
15510 setValue({
15511 item: data,
15512 value: newValue
15513 })
15514 ),
15515 [data, setValue, onChange]
15516 );
15517 return /* @__PURE__ */ (0, import_jsx_runtime81.jsx)(
15518 ValidatedInputControl2,
15519 {
15520 required: !!isValid2.required,
15521 markWhenOptional,
15522 customValidity: getCustomValidity(isValid2, validity),
15523 label,
15524 placeholder,
15525 value: value ?? "",
15526 help: description,
15527 onChange: onChangeControl,
15528 hideLabelFromVision,
15529 type,
15530 prefix,
15531 suffix,
15532 disabled,
15533 pattern: isValid2.pattern ? isValid2.pattern.constraint : void 0,
15534 minLength: isValid2.minLength ? isValid2.minLength.constraint : void 0,
15535 maxLength: isValid2.maxLength ? isValid2.maxLength.constraint : void 0,
15536 __next40pxDefaultSize: true
15537 }
15538 );
15539 }
15540
15541 // packages/dataviews/build-module/components/dataform-controls/email.mjs
15542 var import_jsx_runtime82 = __toESM(require_jsx_runtime(), 1);
15543 function Email({
15544 data,
15545 field,
15546 onChange,
15547 hideLabelFromVision,
15548 markWhenOptional,
15549 validity
15550 }) {
15551 return /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(
15552 ValidatedText,
15553 {
15554 ...{
15555 data,
15556 field,
15557 onChange,
15558 hideLabelFromVision,
15559 markWhenOptional,
15560 validity,
15561 type: "email",
15562 prefix: /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(import_components34.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(import_components34.Icon, { icon: envelope_default }) })
15563 }
15564 }
15565 );
15566 }
15567
15568 // packages/dataviews/build-module/components/dataform-controls/telephone.mjs
15569 var import_components35 = __toESM(require_components(), 1);
15570 var import_jsx_runtime83 = __toESM(require_jsx_runtime(), 1);
15571 function Telephone({
15572 data,
15573 field,
15574 onChange,
15575 hideLabelFromVision,
15576 markWhenOptional,
15577 validity
15578 }) {
15579 return /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(
15580 ValidatedText,
15581 {
15582 ...{
15583 data,
15584 field,
15585 onChange,
15586 hideLabelFromVision,
15587 markWhenOptional,
15588 validity,
15589 type: "tel",
15590 prefix: /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(import_components35.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(import_components35.Icon, { icon: mobile_default }) })
15591 }
15592 }
15593 );
15594 }
15595
15596 // packages/dataviews/build-module/components/dataform-controls/url.mjs
15597 var import_components36 = __toESM(require_components(), 1);
15598 var import_jsx_runtime84 = __toESM(require_jsx_runtime(), 1);
15599 function Url({
15600 data,
15601 field,
15602 onChange,
15603 hideLabelFromVision,
15604 markWhenOptional,
15605 validity
15606 }) {
15607 return /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(
15608 ValidatedText,
15609 {
15610 ...{
15611 data,
15612 field,
15613 onChange,
15614 hideLabelFromVision,
15615 markWhenOptional,
15616 validity,
15617 type: "url",
15618 prefix: /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(import_components36.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(import_components36.Icon, { icon: link_default }) })
15619 }
15620 }
15621 );
15622 }
15623
15624 // packages/dataviews/build-module/components/dataform-controls/utils/validated-number.mjs
15625 var import_components37 = __toESM(require_components(), 1);
15626 var import_element47 = __toESM(require_element(), 1);
15627 var import_i18n40 = __toESM(require_i18n(), 1);
15628 var import_jsx_runtime85 = __toESM(require_jsx_runtime(), 1);
15629 var { ValidatedNumberControl } = unlock(import_components37.privateApis);
15630 function toNumberOrEmpty(value) {
15631 if (value === "" || value === void 0) {
15632 return "";
15633 }
15634 const number = Number(value);
15635 return Number.isFinite(number) ? number : "";
15636 }
15637 function BetweenControls({
15638 value,
15639 onChange,
15640 hideLabelFromVision,
15641 step
15642 }) {
15643 const [min = "", max = ""] = value;
15644 const onChangeMin = (0, import_element47.useCallback)(
15645 (newValue) => onChange([toNumberOrEmpty(newValue), max]),
15646 [onChange, max]
15647 );
15648 const onChangeMax = (0, import_element47.useCallback)(
15649 (newValue) => onChange([min, toNumberOrEmpty(newValue)]),
15650 [onChange, min]
15651 );
15652 return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15653 import_components37.BaseControl,
15654 {
15655 help: (0, import_i18n40.__)("The max. value must be greater than the min. value."),
15656 children: /* @__PURE__ */ (0, import_jsx_runtime85.jsxs)(import_components37.Flex, { direction: "row", gap: 4, children: [
15657 /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15658 import_components37.__experimentalNumberControl,
15659 {
15660 label: (0, import_i18n40.__)("Min."),
15661 value: min,
15662 max: max ? Number(max) - step : void 0,
15663 onChange: onChangeMin,
15664 __next40pxDefaultSize: true,
15665 hideLabelFromVision,
15666 step
15667 }
15668 ),
15669 /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15670 import_components37.__experimentalNumberControl,
15671 {
15672 label: (0, import_i18n40.__)("Max."),
15673 value: max,
15674 min: min ? Number(min) + step : void 0,
15675 onChange: onChangeMax,
15676 __next40pxDefaultSize: true,
15677 hideLabelFromVision,
15678 step
15679 }
15680 )
15681 ] })
15682 }
15683 );
15684 }
15685 function ValidatedNumber({
15686 data,
15687 field,
15688 onChange,
15689 hideLabelFromVision,
15690 markWhenOptional,
15691 operator,
15692 validity
15693 }) {
15694 const decimals = field.format?.decimals ?? 0;
15695 const step = Math.pow(10, Math.abs(decimals) * -1);
15696 const { label, description, getValue, setValue, isValid: isValid2 } = field;
15697 const value = getValue({ item: data }) ?? "";
15698 const disabled = field.isDisabled({ item: data, field });
15699 const onChangeControl = (0, import_element47.useCallback)(
15700 (newValue) => {
15701 onChange(
15702 setValue({
15703 item: data,
15704 // Do not convert an empty string or undefined to a number,
15705 // otherwise there's a mismatch between the UI control (empty)
15706 // and the data relied by onChange (0).
15707 value: ["", void 0].includes(newValue) ? void 0 : Number(newValue)
15708 })
15709 );
15710 },
15711 [data, onChange, setValue]
15712 );
15713 const onChangeBetweenControls = (0, import_element47.useCallback)(
15714 (newValue) => {
15715 onChange(
15716 setValue({
15717 item: data,
15718 value: newValue
15719 })
15720 );
15721 },
15722 [data, onChange, setValue]
15723 );
15724 if (operator === OPERATOR_BETWEEN) {
15725 let valueBetween = ["", ""];
15726 if (Array.isArray(value) && value.length === 2 && value.every(
15727 (element) => typeof element === "number" || element === ""
15728 )) {
15729 valueBetween = value;
15730 }
15731 return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15732 BetweenControls,
15733 {
15734 value: valueBetween,
15735 onChange: onChangeBetweenControls,
15736 hideLabelFromVision,
15737 step
15738 }
15739 );
15740 }
15741 return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15742 ValidatedNumberControl,
15743 {
15744 required: !!isValid2.required,
15745 markWhenOptional,
15746 customValidity: getCustomValidity(isValid2, validity),
15747 label,
15748 help: description,
15749 value,
15750 onChange: onChangeControl,
15751 __next40pxDefaultSize: true,
15752 hideLabelFromVision,
15753 step,
15754 min: isValid2.min ? isValid2.min.constraint : void 0,
15755 max: isValid2.max ? isValid2.max.constraint : void 0,
15756 disabled
15757 }
15758 );
15759 }
15760
15761 // packages/dataviews/build-module/components/dataform-controls/integer.mjs
15762 var import_jsx_runtime86 = __toESM(require_jsx_runtime(), 1);
15763 function Integer(props) {
15764 return /* @__PURE__ */ (0, import_jsx_runtime86.jsx)(ValidatedNumber, { ...props });
15765 }
15766
15767 // packages/dataviews/build-module/components/dataform-controls/number.mjs
15768 var import_jsx_runtime87 = __toESM(require_jsx_runtime(), 1);
15769 function Number2(props) {
15770 return /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(ValidatedNumber, { ...props });
15771 }
15772
15773 // packages/dataviews/build-module/components/dataform-controls/radio.mjs
15774 var import_components38 = __toESM(require_components(), 1);
15775 var import_element48 = __toESM(require_element(), 1);
15776 var import_jsx_runtime88 = __toESM(require_jsx_runtime(), 1);
15777 var { ValidatedRadioControl } = unlock(import_components38.privateApis);
15778 function Radio({
15779 data,
15780 field,
15781 onChange,
15782 hideLabelFromVision,
15783 markWhenOptional,
15784 validity
15785 }) {
15786 const { label, description, getValue, setValue, isValid: isValid2 } = field;
15787 const disabled = field.isDisabled({ item: data, field });
15788 const { elements, isLoading } = useElements({
15789 elements: field.elements,
15790 getElements: field.getElements
15791 });
15792 const value = getValue({ item: data });
15793 const onChangeControl = (0, import_element48.useCallback)(
15794 (newValue) => onChange(setValue({ item: data, value: newValue })),
15795 [data, onChange, setValue]
15796 );
15797 if (isLoading) {
15798 return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(import_components38.Spinner, {});
15799 }
15800 return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(
15801 ValidatedRadioControl,
15802 {
15803 required: !!field.isValid?.required,
15804 markWhenOptional,
15805 customValidity: getCustomValidity(isValid2, validity),
15806 label,
15807 help: description,
15808 onChange: onChangeControl,
15809 options: elements,
15810 selected: value,
15811 hideLabelFromVision,
15812 disabled
15813 }
15814 );
15815 }
15816
15817 // packages/dataviews/build-module/components/dataform-controls/text.mjs
15818 var import_element49 = __toESM(require_element(), 1);
15819 var import_jsx_runtime89 = __toESM(require_jsx_runtime(), 1);
15820 function Text({
15821 data,
15822 field,
15823 onChange,
15824 hideLabelFromVision,
15825 markWhenOptional,
15826 config,
15827 validity
15828 }) {
15829 const { prefix, suffix } = config || {};
15830 return /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(
15831 ValidatedText,
15832 {
15833 ...{
15834 data,
15835 field,
15836 onChange,
15837 hideLabelFromVision,
15838 markWhenOptional,
15839 validity,
15840 prefix: prefix ? (0, import_element49.createElement)(prefix) : void 0,
15841 suffix: suffix ? (0, import_element49.createElement)(suffix) : void 0
15842 }
15843 }
15844 );
15845 }
15846
15847 // packages/dataviews/build-module/components/dataform-controls/toggle.mjs
15848 var import_components39 = __toESM(require_components(), 1);
15849 var import_element50 = __toESM(require_element(), 1);
15850 var import_jsx_runtime90 = __toESM(require_jsx_runtime(), 1);
15851 var { ValidatedToggleControl } = unlock(import_components39.privateApis);
15852 function Toggle({
15853 field,
15854 onChange,
15855 data,
15856 hideLabelFromVision,
15857 markWhenOptional,
15858 validity
15859 }) {
15860 const { label, description, getValue, setValue, isValid: isValid2 } = field;
15861 const disabled = field.isDisabled({ item: data, field });
15862 const onChangeControl = (0, import_element50.useCallback)(() => {
15863 onChange(
15864 setValue({ item: data, value: !getValue({ item: data }) })
15865 );
15866 }, [onChange, setValue, data, getValue]);
15867 return /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(
15868 ValidatedToggleControl,
15869 {
15870 required: !!isValid2.required,
15871 markWhenOptional,
15872 customValidity: getCustomValidity(isValid2, validity),
15873 hidden: hideLabelFromVision,
15874 label,
15875 help: description,
15876 checked: getValue({ item: data }),
15877 onChange: onChangeControl,
15878 disabled
15879 }
15880 );
15881 }
15882
15883 // packages/dataviews/build-module/components/dataform-controls/textarea.mjs
15884 var import_components40 = __toESM(require_components(), 1);
15885 var import_element51 = __toESM(require_element(), 1);
15886 var import_jsx_runtime91 = __toESM(require_jsx_runtime(), 1);
15887 var { ValidatedTextareaControl } = unlock(import_components40.privateApis);
15888 function Textarea({
15889 data,
15890 field,
15891 onChange,
15892 hideLabelFromVision,
15893 markWhenOptional,
15894 config,
15895 validity
15896 }) {
15897 const { rows = 4 } = config || {};
15898 const disabled = field.isDisabled({ item: data, field });
15899 const { label, placeholder, description, setValue, isValid: isValid2 } = field;
15900 const value = field.getValue({ item: data });
15901 const onChangeControl = (0, import_element51.useCallback)(
15902 (newValue) => onChange(setValue({ item: data, value: newValue })),
15903 [data, onChange, setValue]
15904 );
15905 return /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
15906 ValidatedTextareaControl,
15907 {
15908 required: !!isValid2.required,
15909 markWhenOptional,
15910 customValidity: getCustomValidity(isValid2, validity),
15911 label,
15912 placeholder,
15913 value: value ?? "",
15914 help: description,
15915 onChange: onChangeControl,
15916 rows,
15917 disabled,
15918 minLength: isValid2.minLength ? isValid2.minLength.constraint : void 0,
15919 maxLength: isValid2.maxLength ? isValid2.maxLength.constraint : void 0,
15920 __next40pxDefaultSize: true,
15921 hideLabelFromVision
15922 }
15923 );
15924 }
15925
15926 // packages/dataviews/build-module/components/dataform-controls/toggle-group.mjs
15927 var import_components41 = __toESM(require_components(), 1);
15928 var import_element52 = __toESM(require_element(), 1);
15929 var import_jsx_runtime92 = __toESM(require_jsx_runtime(), 1);
15930 var { ValidatedToggleGroupControl } = unlock(import_components41.privateApis);
15931 function ToggleGroup({
15932 data,
15933 field,
15934 onChange,
15935 hideLabelFromVision,
15936 markWhenOptional,
15937 validity
15938 }) {
15939 const { getValue, setValue, isValid: isValid2 } = field;
15940 const disabled = field.isDisabled({ item: data, field });
15941 const value = getValue({ item: data });
15942 const onChangeControl = (0, import_element52.useCallback)(
15943 (newValue) => onChange(setValue({ item: data, value: newValue })),
15944 [data, onChange, setValue]
15945 );
15946 const { elements, isLoading } = useElements({
15947 elements: field.elements,
15948 getElements: field.getElements
15949 });
15950 if (isLoading) {
15951 return /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(import_components41.Spinner, {});
15952 }
15953 if (elements.length === 0) {
15954 return null;
15955 }
15956 const selectedOption = elements.find((el) => el.value === value);
15957 return /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
15958 ValidatedToggleGroupControl,
15959 {
15960 required: !!field.isValid?.required,
15961 markWhenOptional,
15962 customValidity: getCustomValidity(isValid2, validity),
15963 __next40pxDefaultSize: true,
15964 isBlock: true,
15965 label: field.label,
15966 help: selectedOption?.description || field.description,
15967 onChange: onChangeControl,
15968 value,
15969 hideLabelFromVision,
15970 children: elements.map((el) => /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
15971 import_components41.__experimentalToggleGroupControlOption,
15972 {
15973 label: el.label,
15974 value: el.value,
15975 disabled
15976 },
15977 el.value
15978 ))
15979 }
15980 );
15981 }
15982
15983 // packages/dataviews/build-module/components/dataform-controls/array.mjs
15984 var import_components42 = __toESM(require_components(), 1);
15985 var import_element53 = __toESM(require_element(), 1);
15986 var import_jsx_runtime93 = __toESM(require_jsx_runtime(), 1);
15987 var { ValidatedFormTokenField } = unlock(import_components42.privateApis);
15988 function ArrayControl({
15989 data,
15990 field,
15991 onChange,
15992 hideLabelFromVision,
15993 markWhenOptional,
15994 validity
15995 }) {
15996 const { label, placeholder, description, getValue, setValue, isValid: isValid2 } = field;
15997 const value = getValue({ item: data });
15998 const disabled = field.isDisabled({ item: data, field });
15999 const { elements, isLoading } = useElements({
16000 elements: field.elements,
16001 getElements: field.getElements
16002 });
16003 const arrayValueAsElements = (0, import_element53.useMemo)(
16004 () => Array.isArray(value) ? value.map((token) => {
16005 const element = elements?.find(
16006 (suggestion) => suggestion.value === token
16007 );
16008 return element || { value: token, label: token };
16009 }) : [],
16010 [value, elements]
16011 );
16012 const onChangeControl = (0, import_element53.useCallback)(
16013 (tokens) => {
16014 const valueTokens = tokens.map((token) => {
16015 if (typeof token === "object" && "value" in token) {
16016 return token.value;
16017 }
16018 return token;
16019 });
16020 onChange(setValue({ item: data, value: valueTokens }));
16021 },
16022 [onChange, setValue, data]
16023 );
16024 if (isLoading) {
16025 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_components42.Spinner, {});
16026 }
16027 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
16028 ValidatedFormTokenField,
16029 {
16030 required: !!isValid2?.required,
16031 markWhenOptional,
16032 customValidity: getCustomValidity(isValid2, validity),
16033 label: hideLabelFromVision ? void 0 : label,
16034 value: arrayValueAsElements,
16035 onChange: onChangeControl,
16036 placeholder,
16037 suggestions: elements?.map((element) => element.value),
16038 disabled,
16039 __experimentalValidateInput: (token) => {
16040 if (field.isValid?.elements && elements) {
16041 return elements.some(
16042 (element) => element.value === token || element.label === token
16043 );
16044 }
16045 return true;
16046 },
16047 __experimentalExpandOnFocus: elements && elements.length > 0,
16048 help: description ?? (field.isValid?.elements ? "" : void 0),
16049 displayTransform: (token) => {
16050 if (typeof token === "object" && "label" in token) {
16051 return token.label;
16052 }
16053 if (typeof token === "string" && elements) {
16054 const element = elements.find(
16055 (el) => el.value === token
16056 );
16057 return element?.label || token;
16058 }
16059 return token;
16060 },
16061 __experimentalRenderItem: ({ item }) => {
16062 if (typeof item === "string" && elements) {
16063 const element = elements.find(
16064 (el) => el.value === item
16065 );
16066 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)("span", { children: element?.label || item });
16067 }
16068 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)("span", { children: item });
16069 }
16070 }
16071 );
16072 }
16073
16074 // node_modules/colord/index.mjs
16075 var r2 = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) };
16076 var t = function(r3) {
16077 return "string" == typeof r3 ? r3.length > 0 : "number" == typeof r3;
16078 };
16079 var n = function(r3, t2, n2) {
16080 return void 0 === t2 && (t2 = 0), void 0 === n2 && (n2 = Math.pow(10, t2)), Math.round(n2 * r3) / n2 + 0;
16081 };
16082 var e = function(r3, t2, n2) {
16083 return void 0 === t2 && (t2 = 0), void 0 === n2 && (n2 = 1), r3 > n2 ? n2 : r3 > t2 ? r3 : t2;
16084 };
16085 var u = function(r3) {
16086 return (r3 = isFinite(r3) ? r3 % 360 : 0) > 0 ? r3 : r3 + 360;
16087 };
16088 var a = function(r3) {
16089 return { r: e(r3.r, 0, 255), g: e(r3.g, 0, 255), b: e(r3.b, 0, 255), a: e(r3.a) };
16090 };
16091 var o = function(r3) {
16092 return { r: n(r3.r), g: n(r3.g), b: n(r3.b), a: n(r3.a, 3) };
16093 };
16094 var i = /^#([0-9a-f]{3,8})$/i;
16095 var s = function(r3) {
16096 var t2 = r3.toString(16);
16097 return t2.length < 2 ? "0" + t2 : t2;
16098 };
16099 var h = function(r3) {
16100 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;
16101 return { h: 60 * (i2 < 0 ? i2 + 6 : i2), s: a2 ? o2 / a2 * 100 : 0, v: a2 / 255 * 100, a: u2 };
16102 };
16103 var b = function(r3) {
16104 var t2 = r3.h, n2 = r3.s, e2 = r3.v, u2 = r3.a;
16105 t2 = t2 / 360 * 6, n2 /= 100, e2 /= 100;
16106 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;
16107 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 };
16108 };
16109 var g = function(r3) {
16110 return { h: u(r3.h), s: e(r3.s, 0, 100), l: e(r3.l, 0, 100), a: e(r3.a) };
16111 };
16112 var d = function(r3) {
16113 return { h: n(r3.h), s: n(r3.s), l: n(r3.l), a: n(r3.a, 3) };
16114 };
16115 var f = function(r3) {
16116 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 }));
16117 var t2, n2, e2;
16118 };
16119 var c = function(r3) {
16120 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 };
16121 var t2, n2, e2, u2;
16122 };
16123 var l = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
16124 var p = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
16125 var v = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
16126 var m = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
16127 var y = { string: [[function(r3) {
16128 var t2 = i.exec(r3);
16129 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;
16130 }, "hex"], [function(r3) {
16131 var t2 = v.exec(r3) || m.exec(r3);
16132 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;
16133 }, "rgb"], [function(t2) {
16134 var n2 = l.exec(t2) || p.exec(t2);
16135 if (!n2) return null;
16136 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) });
16137 return f(a2);
16138 }, "hsl"]], object: [[function(r3) {
16139 var n2 = r3.r, e2 = r3.g, u2 = r3.b, o2 = r3.a, i2 = void 0 === o2 ? 1 : o2;
16140 return t(n2) && t(e2) && t(u2) ? a({ r: Number(n2), g: Number(e2), b: Number(u2), a: Number(i2) }) : null;
16141 }, "rgb"], [function(r3) {
16142 var n2 = r3.h, e2 = r3.s, u2 = r3.l, a2 = r3.a, o2 = void 0 === a2 ? 1 : a2;
16143 if (!t(n2) || !t(e2) || !t(u2)) return null;
16144 var i2 = g({ h: Number(n2), s: Number(e2), l: Number(u2), a: Number(o2) });
16145 return f(i2);
16146 }, "hsl"], [function(r3) {
16147 var n2 = r3.h, a2 = r3.s, o2 = r3.v, i2 = r3.a, s2 = void 0 === i2 ? 1 : i2;
16148 if (!t(n2) || !t(a2) || !t(o2)) return null;
16149 var h2 = (function(r4) {
16150 return { h: u(r4.h), s: e(r4.s, 0, 100), v: e(r4.v, 0, 100), a: e(r4.a) };
16151 })({ h: Number(n2), s: Number(a2), v: Number(o2), a: Number(s2) });
16152 return b(h2);
16153 }, "hsv"]] };
16154 var N = function(r3, t2) {
16155 for (var n2 = 0; n2 < t2.length; n2++) {
16156 var e2 = t2[n2][0](r3);
16157 if (e2) return [e2, t2[n2][1]];
16158 }
16159 return [null, void 0];
16160 };
16161 var x = function(r3) {
16162 return "string" == typeof r3 ? N(r3.trim(), y.string) : "object" == typeof r3 && null !== r3 ? N(r3, y.object) : [null, void 0];
16163 };
16164 var M = function(r3, t2) {
16165 var n2 = c(r3);
16166 return { h: n2.h, s: e(n2.s + 100 * t2, 0, 100), l: n2.l, a: n2.a };
16167 };
16168 var H = function(r3) {
16169 return (299 * r3.r + 587 * r3.g + 114 * r3.b) / 1e3 / 255;
16170 };
16171 var $ = function(r3, t2) {
16172 var n2 = c(r3);
16173 return { h: n2.h, s: n2.s, l: e(n2.l + 100 * t2, 0, 100), a: n2.a };
16174 };
16175 var j = (function() {
16176 function r3(r4) {
16177 this.parsed = x(r4)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
16178 }
16179 return r3.prototype.isValid = function() {
16180 return null !== this.parsed;
16181 }, r3.prototype.brightness = function() {
16182 return n(H(this.rgba), 2);
16183 }, r3.prototype.isDark = function() {
16184 return H(this.rgba) < 0.5;
16185 }, r3.prototype.isLight = function() {
16186 return H(this.rgba) >= 0.5;
16187 }, r3.prototype.toHex = function() {
16188 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;
16189 var r4, t2, e2, u2, a2, i2;
16190 }, r3.prototype.toRgb = function() {
16191 return o(this.rgba);
16192 }, r3.prototype.toRgbString = function() {
16193 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 + ")";
16194 var r4, t2, n2, e2, u2;
16195 }, r3.prototype.toHsl = function() {
16196 return d(c(this.rgba));
16197 }, r3.prototype.toHslString = function() {
16198 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 + "%)";
16199 var r4, t2, n2, e2, u2;
16200 }, r3.prototype.toHsv = function() {
16201 return r4 = h(this.rgba), { h: n(r4.h), s: n(r4.s), v: n(r4.v), a: n(r4.a, 3) };
16202 var r4;
16203 }, r3.prototype.invert = function() {
16204 return w({ r: 255 - (r4 = this.rgba).r, g: 255 - r4.g, b: 255 - r4.b, a: r4.a });
16205 var r4;
16206 }, r3.prototype.saturate = function(r4) {
16207 return void 0 === r4 && (r4 = 0.1), w(M(this.rgba, r4));
16208 }, r3.prototype.desaturate = function(r4) {
16209 return void 0 === r4 && (r4 = 0.1), w(M(this.rgba, -r4));
16210 }, r3.prototype.grayscale = function() {
16211 return w(M(this.rgba, -1));
16212 }, r3.prototype.lighten = function(r4) {
16213 return void 0 === r4 && (r4 = 0.1), w($(this.rgba, r4));
16214 }, r3.prototype.darken = function(r4) {
16215 return void 0 === r4 && (r4 = 0.1), w($(this.rgba, -r4));
16216 }, r3.prototype.rotate = function(r4) {
16217 return void 0 === r4 && (r4 = 15), this.hue(this.hue() + r4);
16218 }, r3.prototype.alpha = function(r4) {
16219 return "number" == typeof r4 ? w({ r: (t2 = this.rgba).r, g: t2.g, b: t2.b, a: r4 }) : n(this.rgba.a, 3);
16220 var t2;
16221 }, r3.prototype.hue = function(r4) {
16222 var t2 = c(this.rgba);
16223 return "number" == typeof r4 ? w({ h: r4, s: t2.s, l: t2.l, a: t2.a }) : n(t2.h);
16224 }, r3.prototype.isEqual = function(r4) {
16225 return this.toHex() === w(r4).toHex();
16226 }, r3;
16227 })();
16228 var w = function(r3) {
16229 return r3 instanceof j ? r3 : new j(r3);
16230 };
16231
16232 // packages/dataviews/build-module/components/dataform-controls/color.mjs
16233 var import_components43 = __toESM(require_components(), 1);
16234 var import_element54 = __toESM(require_element(), 1);
16235 var import_i18n41 = __toESM(require_i18n(), 1);
16236 var import_jsx_runtime94 = __toESM(require_jsx_runtime(), 1);
16237 var { ValidatedInputControl: ValidatedInputControl3 } = unlock(import_components43.privateApis);
16238 var ColorPickerDropdown = ({
16239 color,
16240 onColorChange,
16241 disabled
16242 }) => {
16243 const validColor = color && w(color).isValid() ? color : "#ffffff";
16244 return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16245 import_components43.Dropdown,
16246 {
16247 className: "dataviews-controls__color-picker-dropdown",
16248 popoverProps: { resize: false },
16249 renderToggle: ({ onToggle }) => /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16250 import_components43.Button,
16251 {
16252 onClick: onToggle,
16253 "aria-label": (0, import_i18n41.__)("Open color picker"),
16254 size: "small",
16255 disabled,
16256 accessibleWhenDisabled: true,
16257 icon: () => /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_components43.ColorIndicator, { colorValue: validColor })
16258 }
16259 ),
16260 renderContent: () => /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_components43.__experimentalDropdownContentWrapper, { paddingSize: "none", children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16261 import_components43.ColorPicker,
16262 {
16263 color: validColor,
16264 onChange: onColorChange,
16265 enableAlpha: true
16266 }
16267 ) })
16268 }
16269 );
16270 };
16271 function Color({
16272 data,
16273 field,
16274 onChange,
16275 hideLabelFromVision,
16276 markWhenOptional,
16277 validity
16278 }) {
16279 const { label, placeholder, description, setValue, isValid: isValid2 } = field;
16280 const disabled = field.isDisabled({ item: data, field });
16281 const value = field.getValue({ item: data }) || "";
16282 const handleColorChange = (0, import_element54.useCallback)(
16283 (newColor) => {
16284 onChange(setValue({ item: data, value: newColor }));
16285 },
16286 [data, onChange, setValue]
16287 );
16288 const handleInputChange = (0, import_element54.useCallback)(
16289 (newValue) => {
16290 onChange(setValue({ item: data, value: newValue || "" }));
16291 },
16292 [data, onChange, setValue]
16293 );
16294 return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16295 ValidatedInputControl3,
16296 {
16297 required: !!field.isValid?.required,
16298 markWhenOptional,
16299 customValidity: getCustomValidity(isValid2, validity),
16300 label,
16301 placeholder,
16302 value,
16303 help: description,
16304 onChange: handleInputChange,
16305 hideLabelFromVision,
16306 type: "text",
16307 disabled,
16308 prefix: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_components43.__experimentalInputControlPrefixWrapper, { variant: "control", children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16309 ColorPickerDropdown,
16310 {
16311 color: value,
16312 onColorChange: handleColorChange,
16313 disabled
16314 }
16315 ) })
16316 }
16317 );
16318 }
16319
16320 // packages/dataviews/build-module/components/dataform-controls/password.mjs
16321 var import_components44 = __toESM(require_components(), 1);
16322 var import_element55 = __toESM(require_element(), 1);
16323 var import_i18n42 = __toESM(require_i18n(), 1);
16324 var import_jsx_runtime95 = __toESM(require_jsx_runtime(), 1);
16325 function Password({
16326 data,
16327 field,
16328 onChange,
16329 hideLabelFromVision,
16330 markWhenOptional,
16331 validity
16332 }) {
16333 const [isVisible2, setIsVisible] = (0, import_element55.useState)(false);
16334 const disabled = field.isDisabled({ item: data, field });
16335 const toggleVisibility = (0, import_element55.useCallback)(() => {
16336 setIsVisible((prev) => !prev);
16337 }, []);
16338 return /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(
16339 ValidatedText,
16340 {
16341 ...{
16342 data,
16343 field,
16344 onChange,
16345 hideLabelFromVision,
16346 markWhenOptional,
16347 validity,
16348 type: isVisible2 ? "text" : "password",
16349 suffix: /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(import_components44.__experimentalInputControlSuffixWrapper, { variant: "control", children: /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(
16350 import_components44.Button,
16351 {
16352 icon: isVisible2 ? unseen_default : seen_default,
16353 onClick: toggleVisibility,
16354 size: "small",
16355 label: isVisible2 ? (0, import_i18n42.__)("Hide password") : (0, import_i18n42.__)("Show password"),
16356 disabled,
16357 accessibleWhenDisabled: true
16358 }
16359 ) })
16360 }
16361 }
16362 );
16363 }
16364
16365 // packages/dataviews/build-module/field-types/utils/has-elements.mjs
16366 function hasElements(field) {
16367 return Array.isArray(field.elements) && field.elements.length > 0 || typeof field.getElements === "function";
16368 }
16369
16370 // packages/dataviews/build-module/components/dataform-controls/index.mjs
16371 var import_jsx_runtime96 = __toESM(require_jsx_runtime(), 1);
16372 var FORM_CONTROLS = {
16373 adaptiveSelect: AdaptiveSelect,
16374 array: ArrayControl,
16375 checkbox: Checkbox,
16376 color: Color,
16377 combobox: Combobox3,
16378 datetime: DateTime,
16379 date: DateControl,
16380 email: Email,
16381 telephone: Telephone,
16382 url: Url,
16383 integer: Integer,
16384 number: Number2,
16385 password: Password,
16386 radio: Radio,
16387 select: Select,
16388 text: Text,
16389 toggle: Toggle,
16390 textarea: Textarea,
16391 toggleGroup: ToggleGroup
16392 };
16393 function isEditConfig(value) {
16394 return value && typeof value === "object" && typeof value.control === "string";
16395 }
16396 function createConfiguredControl(config) {
16397 const { control, ...controlConfig } = config;
16398 const BaseControlType = getControlByType(control);
16399 if (BaseControlType === null) {
16400 return null;
16401 }
16402 return function ConfiguredControl(props) {
16403 return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(BaseControlType, { ...props, config: controlConfig });
16404 };
16405 }
16406 function getControl(field, fallback) {
16407 if (typeof field.Edit === "function") {
16408 return field.Edit;
16409 }
16410 if (typeof field.Edit === "string") {
16411 return getControlByType(field.Edit);
16412 }
16413 if (isEditConfig(field.Edit)) {
16414 return createConfiguredControl(field.Edit);
16415 }
16416 if (hasElements(field) && field.type !== "array") {
16417 return getControlByType("adaptiveSelect");
16418 }
16419 if (fallback === null) {
16420 return null;
16421 }
16422 return getControlByType(fallback);
16423 }
16424 function getControlByType(type) {
16425 if (Object.keys(FORM_CONTROLS).includes(type)) {
16426 return FORM_CONTROLS[type];
16427 }
16428 return null;
16429 }
16430
16431 // packages/dataviews/build-module/field-types/utils/get-filter-by.mjs
16432 function getFilterBy(field, defaultOperators, validOperators) {
16433 if (field.filterBy === false) {
16434 return false;
16435 }
16436 const operators = field.filterBy?.operators?.filter(
16437 (op) => validOperators.includes(op)
16438 ) ?? defaultOperators;
16439 if (operators.length === 0) {
16440 return false;
16441 }
16442 return {
16443 isPrimary: !!field.filterBy?.isPrimary,
16444 operators
16445 };
16446 }
16447 var get_filter_by_default = getFilterBy;
16448
16449 // packages/dataviews/build-module/field-types/utils/get-value-from-id.mjs
16450 var getValueFromId = (id) => ({ item }) => {
16451 const path = id.split(".");
16452 let value = item;
16453 for (const segment of path) {
16454 if (value.hasOwnProperty(segment)) {
16455 value = value[segment];
16456 } else {
16457 value = void 0;
16458 }
16459 }
16460 return value;
16461 };
16462 var get_value_from_id_default = getValueFromId;
16463
16464 // packages/dataviews/build-module/field-types/utils/set-value-from-id.mjs
16465 var setValueFromId = (id) => ({ value }) => {
16466 const path = id.split(".");
16467 const result = {};
16468 let current = result;
16469 for (const segment of path.slice(0, -1)) {
16470 current[segment] = {};
16471 current = current[segment];
16472 }
16473 current[path.at(-1)] = value;
16474 return result;
16475 };
16476 var set_value_from_id_default = setValueFromId;
16477
16478 // packages/dataviews/build-module/field-types/email.mjs
16479 var import_i18n43 = __toESM(require_i18n(), 1);
16480
16481 // packages/dataviews/build-module/field-types/utils/render-from-elements.mjs
16482 function RenderFromElements({
16483 item,
16484 field
16485 }) {
16486 const { elements, isLoading } = useElements({
16487 elements: field.elements,
16488 getElements: field.getElements
16489 });
16490 const value = field.getValue({ item });
16491 if (isLoading) {
16492 return value;
16493 }
16494 if (elements.length === 0) {
16495 return value;
16496 }
16497 return elements?.find((element) => element.value === value)?.label || field.getValue({ item });
16498 }
16499
16500 // packages/dataviews/build-module/field-types/utils/render-default.mjs
16501 var import_jsx_runtime97 = __toESM(require_jsx_runtime(), 1);
16502 function render({
16503 item,
16504 field
16505 }) {
16506 if (field.hasElements) {
16507 return /* @__PURE__ */ (0, import_jsx_runtime97.jsx)(RenderFromElements, { item, field });
16508 }
16509 return field.getValueFormatted({ item, field });
16510 }
16511
16512 // packages/dataviews/build-module/field-types/utils/sort-text.mjs
16513 var sort_text_default = (a2, b2, direction) => {
16514 return direction === "asc" ? a2.localeCompare(b2) : b2.localeCompare(a2);
16515 };
16516
16517 // packages/dataviews/build-module/field-types/utils/is-valid-required.mjs
16518 function isValidRequired(item, field) {
16519 const value = field.getValue({ item });
16520 return ![void 0, "", null].includes(value);
16521 }
16522
16523 // packages/dataviews/build-module/field-types/utils/is-valid-min-length.mjs
16524 function isValidMinLength(item, field) {
16525 if (typeof field.isValid.minLength?.constraint !== "number") {
16526 return false;
16527 }
16528 const value = field.getValue({ item });
16529 if ([void 0, "", null].includes(value)) {
16530 return true;
16531 }
16532 return String(value).length >= field.isValid.minLength.constraint;
16533 }
16534
16535 // packages/dataviews/build-module/field-types/utils/is-valid-max-length.mjs
16536 function isValidMaxLength(item, field) {
16537 if (typeof field.isValid.maxLength?.constraint !== "number") {
16538 return false;
16539 }
16540 const value = field.getValue({ item });
16541 if ([void 0, "", null].includes(value)) {
16542 return true;
16543 }
16544 return String(value).length <= field.isValid.maxLength.constraint;
16545 }
16546
16547 // packages/dataviews/build-module/field-types/utils/is-valid-pattern.mjs
16548 function isValidPattern(item, field) {
16549 if (field.isValid.pattern?.constraint === void 0) {
16550 return true;
16551 }
16552 try {
16553 const regexp = new RegExp(field.isValid.pattern.constraint);
16554 const value = field.getValue({ item });
16555 if ([void 0, "", null].includes(value)) {
16556 return true;
16557 }
16558 return regexp.test(String(value));
16559 } catch {
16560 return false;
16561 }
16562 }
16563
16564 // packages/dataviews/build-module/field-types/utils/is-valid-elements.mjs
16565 function isValidElements(item, field) {
16566 const elements = field.elements ?? [];
16567 const validValues = elements.map((el) => el.value);
16568 if (validValues.length === 0) {
16569 return true;
16570 }
16571 const value = field.getValue({ item });
16572 return [].concat(value).every((v2) => validValues.includes(v2));
16573 }
16574
16575 // packages/dataviews/build-module/field-types/utils/get-value-formatted-default.mjs
16576 function getValueFormatted({
16577 item,
16578 field
16579 }) {
16580 return field.getValue({ item });
16581 }
16582 var get_value_formatted_default_default = getValueFormatted;
16583
16584 // packages/dataviews/build-module/field-types/email.mjs
16585 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])?)*$/;
16586 function isValidCustom(item, field) {
16587 const value = field.getValue({ item });
16588 if (![void 0, "", null].includes(value) && !emailRegex.test(value)) {
16589 return (0, import_i18n43.__)("Value must be a valid email address.");
16590 }
16591 return null;
16592 }
16593 var email_default = {
16594 type: "email",
16595 render,
16596 Edit: "email",
16597 sort: sort_text_default,
16598 enableSorting: true,
16599 enableGlobalSearch: false,
16600 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16601 validOperators: [
16602 OPERATOR_IS,
16603 OPERATOR_IS_NOT,
16604 OPERATOR_CONTAINS,
16605 OPERATOR_NOT_CONTAINS,
16606 OPERATOR_STARTS_WITH,
16607 // Multiple selection
16608 OPERATOR_IS_ANY,
16609 OPERATOR_IS_NONE,
16610 OPERATOR_IS_ALL,
16611 OPERATOR_IS_NOT_ALL
16612 ],
16613 format: {},
16614 getValueFormatted: get_value_formatted_default_default,
16615 validate: {
16616 required: isValidRequired,
16617 pattern: isValidPattern,
16618 minLength: isValidMinLength,
16619 maxLength: isValidMaxLength,
16620 elements: isValidElements,
16621 custom: isValidCustom
16622 }
16623 };
16624
16625 // packages/dataviews/build-module/field-types/integer.mjs
16626 var import_i18n44 = __toESM(require_i18n(), 1);
16627
16628 // packages/dataviews/build-module/field-types/utils/sort-number.mjs
16629 var sort_number_default = (a2, b2, direction) => {
16630 return direction === "asc" ? a2 - b2 : b2 - a2;
16631 };
16632
16633 // packages/dataviews/build-module/field-types/utils/is-valid-min.mjs
16634 function isValidMin(item, field) {
16635 if (typeof field.isValid.min?.constraint !== "number") {
16636 return false;
16637 }
16638 const value = field.getValue({ item });
16639 if ([void 0, "", null].includes(value)) {
16640 return true;
16641 }
16642 return Number(value) >= field.isValid.min.constraint;
16643 }
16644
16645 // packages/dataviews/build-module/field-types/utils/is-valid-max.mjs
16646 function isValidMax(item, field) {
16647 if (typeof field.isValid.max?.constraint !== "number") {
16648 return false;
16649 }
16650 const value = field.getValue({ item });
16651 if ([void 0, "", null].includes(value)) {
16652 return true;
16653 }
16654 return Number(value) <= field.isValid.max.constraint;
16655 }
16656
16657 // packages/dataviews/build-module/field-types/integer.mjs
16658 var format2 = {
16659 separatorThousand: ","
16660 };
16661 function getValueFormatted2({
16662 item,
16663 field
16664 }) {
16665 let value = field.getValue({ item });
16666 if (value === null || value === void 0) {
16667 return "";
16668 }
16669 value = Number(value);
16670 if (!Number.isFinite(value)) {
16671 return String(value);
16672 }
16673 let formatInteger;
16674 if (field.type !== "integer") {
16675 formatInteger = format2;
16676 } else {
16677 formatInteger = field.format;
16678 }
16679 const { separatorThousand } = formatInteger;
16680 const integerValue = Math.trunc(value);
16681 if (!separatorThousand) {
16682 return String(integerValue);
16683 }
16684 return String(integerValue).replace(
16685 /\B(?=(\d{3})+(?!\d))/g,
16686 separatorThousand
16687 );
16688 }
16689 function isValidCustom2(item, field) {
16690 const value = field.getValue({ item });
16691 if (![void 0, "", null].includes(value) && !Number.isInteger(value)) {
16692 return (0, import_i18n44.__)("Value must be an integer.");
16693 }
16694 return null;
16695 }
16696 var integer_default = {
16697 type: "integer",
16698 render,
16699 Edit: "integer",
16700 sort: sort_number_default,
16701 enableSorting: true,
16702 enableGlobalSearch: false,
16703 defaultOperators: [
16704 OPERATOR_IS,
16705 OPERATOR_IS_NOT,
16706 OPERATOR_LESS_THAN,
16707 OPERATOR_GREATER_THAN,
16708 OPERATOR_LESS_THAN_OR_EQUAL,
16709 OPERATOR_GREATER_THAN_OR_EQUAL,
16710 OPERATOR_BETWEEN
16711 ],
16712 validOperators: [
16713 // Single-selection
16714 OPERATOR_IS,
16715 OPERATOR_IS_NOT,
16716 OPERATOR_LESS_THAN,
16717 OPERATOR_GREATER_THAN,
16718 OPERATOR_LESS_THAN_OR_EQUAL,
16719 OPERATOR_GREATER_THAN_OR_EQUAL,
16720 OPERATOR_BETWEEN,
16721 // Multiple-selection
16722 OPERATOR_IS_ANY,
16723 OPERATOR_IS_NONE,
16724 OPERATOR_IS_ALL,
16725 OPERATOR_IS_NOT_ALL
16726 ],
16727 format: format2,
16728 getValueFormatted: getValueFormatted2,
16729 validate: {
16730 required: isValidRequired,
16731 min: isValidMin,
16732 max: isValidMax,
16733 elements: isValidElements,
16734 custom: isValidCustom2
16735 }
16736 };
16737
16738 // packages/dataviews/build-module/field-types/number.mjs
16739 var import_i18n45 = __toESM(require_i18n(), 1);
16740 var format3 = {
16741 separatorThousand: ",",
16742 separatorDecimal: ".",
16743 decimals: 2
16744 };
16745 function getValueFormatted3({
16746 item,
16747 field
16748 }) {
16749 let value = field.getValue({ item });
16750 if (value === null || value === void 0) {
16751 return "";
16752 }
16753 value = Number(value);
16754 if (!Number.isFinite(value)) {
16755 return String(value);
16756 }
16757 let formatNumber;
16758 if (field.type !== "number") {
16759 formatNumber = format3;
16760 } else {
16761 formatNumber = field.format;
16762 }
16763 const { separatorThousand, separatorDecimal, decimals } = formatNumber;
16764 const fixedValue = value.toFixed(decimals);
16765 const [integerPart, decimalPart] = fixedValue.split(".");
16766 const formattedInteger = separatorThousand ? integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, separatorThousand) : integerPart;
16767 return decimals === 0 ? formattedInteger : formattedInteger + separatorDecimal + decimalPart;
16768 }
16769 function isEmpty2(value) {
16770 return value === "" || value === void 0 || value === null;
16771 }
16772 function isValidCustom3(item, field) {
16773 const value = field.getValue({ item });
16774 if (!isEmpty2(value) && !Number.isFinite(value)) {
16775 return (0, import_i18n45.__)("Value must be a number.");
16776 }
16777 return null;
16778 }
16779 var number_default = {
16780 type: "number",
16781 render,
16782 Edit: "number",
16783 sort: sort_number_default,
16784 enableSorting: true,
16785 enableGlobalSearch: false,
16786 defaultOperators: [
16787 OPERATOR_IS,
16788 OPERATOR_IS_NOT,
16789 OPERATOR_LESS_THAN,
16790 OPERATOR_GREATER_THAN,
16791 OPERATOR_LESS_THAN_OR_EQUAL,
16792 OPERATOR_GREATER_THAN_OR_EQUAL,
16793 OPERATOR_BETWEEN
16794 ],
16795 validOperators: [
16796 // Single-selection
16797 OPERATOR_IS,
16798 OPERATOR_IS_NOT,
16799 OPERATOR_LESS_THAN,
16800 OPERATOR_GREATER_THAN,
16801 OPERATOR_LESS_THAN_OR_EQUAL,
16802 OPERATOR_GREATER_THAN_OR_EQUAL,
16803 OPERATOR_BETWEEN,
16804 // Multiple-selection
16805 OPERATOR_IS_ANY,
16806 OPERATOR_IS_NONE,
16807 OPERATOR_IS_ALL,
16808 OPERATOR_IS_NOT_ALL
16809 ],
16810 format: format3,
16811 getValueFormatted: getValueFormatted3,
16812 validate: {
16813 required: isValidRequired,
16814 min: isValidMin,
16815 max: isValidMax,
16816 elements: isValidElements,
16817 custom: isValidCustom3
16818 }
16819 };
16820
16821 // packages/dataviews/build-module/field-types/text.mjs
16822 var text_default = {
16823 type: "text",
16824 render,
16825 Edit: "text",
16826 sort: sort_text_default,
16827 enableSorting: true,
16828 enableGlobalSearch: false,
16829 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16830 validOperators: [
16831 // Single selection
16832 OPERATOR_IS,
16833 OPERATOR_IS_NOT,
16834 OPERATOR_CONTAINS,
16835 OPERATOR_NOT_CONTAINS,
16836 OPERATOR_STARTS_WITH,
16837 // Multiple selection
16838 OPERATOR_IS_ANY,
16839 OPERATOR_IS_NONE,
16840 OPERATOR_IS_ALL,
16841 OPERATOR_IS_NOT_ALL
16842 ],
16843 format: {},
16844 getValueFormatted: get_value_formatted_default_default,
16845 validate: {
16846 required: isValidRequired,
16847 pattern: isValidPattern,
16848 minLength: isValidMinLength,
16849 maxLength: isValidMaxLength,
16850 elements: isValidElements
16851 }
16852 };
16853
16854 // packages/dataviews/build-module/field-types/datetime.mjs
16855 var import_date7 = __toESM(require_date(), 1);
16856
16857 // packages/dataviews/build-module/field-types/utils/is-valid-date-boundary.mjs
16858 var import_date6 = __toESM(require_date(), 1);
16859 function parseDateLike(value) {
16860 if (!value) {
16861 return null;
16862 }
16863 if (!isValid(new Date(value))) {
16864 return null;
16865 }
16866 const parsed = (0, import_date6.getDate)(value);
16867 return parsed && isValid(parsed) ? parsed : null;
16868 }
16869 function validateDateLikeBoundary(item, field, boundary) {
16870 const constraint = field.isValid[boundary]?.constraint;
16871 if (typeof constraint !== "string") {
16872 return false;
16873 }
16874 const value = field.getValue({ item });
16875 const boundaryValue = Array.isArray(value) ? value[boundary === "min" ? 0 : value.length - 1] : value;
16876 if (boundaryValue === void 0 || boundaryValue === null || boundaryValue === "") {
16877 return true;
16878 }
16879 const parsedConstraint = parseDateLike(constraint);
16880 const parsedValue = parseDateLike(String(boundaryValue));
16881 return !!parsedConstraint && !!parsedValue && (boundary === "min" ? parsedValue.getTime() >= parsedConstraint.getTime() : parsedValue.getTime() <= parsedConstraint.getTime());
16882 }
16883 function isValidMinDate(item, field) {
16884 return validateDateLikeBoundary(item, field, "min");
16885 }
16886 function isValidMaxDate(item, field) {
16887 return validateDateLikeBoundary(item, field, "max");
16888 }
16889
16890 // packages/dataviews/build-module/field-types/datetime.mjs
16891 var format4 = {
16892 datetime: (0, import_date7.getSettings)().formats.datetime,
16893 weekStartsOn: (0, import_date7.getSettings)().l10n.startOfWeek
16894 };
16895 function getValueFormatted4({
16896 item,
16897 field
16898 }) {
16899 const value = field.getValue({ item });
16900 if (["", void 0, null].includes(value)) {
16901 return "";
16902 }
16903 let formatDatetime;
16904 if (field.type !== "datetime") {
16905 formatDatetime = format4;
16906 } else {
16907 formatDatetime = field.format;
16908 }
16909 return (0, import_date7.dateI18n)(formatDatetime.datetime, (0, import_date7.getDate)(value));
16910 }
16911 var sort = (a2, b2, direction) => {
16912 const timeA = new Date(a2).getTime();
16913 const timeB = new Date(b2).getTime();
16914 return direction === "asc" ? timeA - timeB : timeB - timeA;
16915 };
16916 var datetime_default = {
16917 type: "datetime",
16918 render,
16919 Edit: "datetime",
16920 sort,
16921 enableSorting: true,
16922 enableGlobalSearch: false,
16923 defaultOperators: [
16924 OPERATOR_ON,
16925 OPERATOR_NOT_ON,
16926 OPERATOR_BEFORE,
16927 OPERATOR_AFTER,
16928 OPERATOR_BEFORE_INC,
16929 OPERATOR_AFTER_INC,
16930 OPERATOR_IN_THE_PAST,
16931 OPERATOR_OVER
16932 ],
16933 validOperators: [
16934 OPERATOR_ON,
16935 OPERATOR_NOT_ON,
16936 OPERATOR_BEFORE,
16937 OPERATOR_AFTER,
16938 OPERATOR_BEFORE_INC,
16939 OPERATOR_AFTER_INC,
16940 OPERATOR_IN_THE_PAST,
16941 OPERATOR_OVER
16942 ],
16943 format: format4,
16944 getValueFormatted: getValueFormatted4,
16945 validate: {
16946 required: isValidRequired,
16947 elements: isValidElements,
16948 min: isValidMinDate,
16949 max: isValidMaxDate
16950 }
16951 };
16952
16953 // packages/dataviews/build-module/field-types/date.mjs
16954 var import_date8 = __toESM(require_date(), 1);
16955 var format5 = {
16956 date: (0, import_date8.getSettings)().formats.date,
16957 weekStartsOn: (0, import_date8.getSettings)().l10n.startOfWeek
16958 };
16959 function getValueFormatted5({
16960 item,
16961 field
16962 }) {
16963 const value = field.getValue({ item });
16964 if (["", void 0, null].includes(value)) {
16965 return "";
16966 }
16967 let formatDate2;
16968 if (field.type !== "date") {
16969 formatDate2 = format5;
16970 } else {
16971 formatDate2 = field.format;
16972 }
16973 return (0, import_date8.dateI18n)(formatDate2.date, (0, import_date8.getDate)(value));
16974 }
16975 var sort2 = (a2, b2, direction) => {
16976 const timeA = new Date(a2).getTime();
16977 const timeB = new Date(b2).getTime();
16978 return direction === "asc" ? timeA - timeB : timeB - timeA;
16979 };
16980 var date_default = {
16981 type: "date",
16982 render,
16983 Edit: "date",
16984 sort: sort2,
16985 enableSorting: true,
16986 enableGlobalSearch: false,
16987 defaultOperators: [
16988 OPERATOR_ON,
16989 OPERATOR_NOT_ON,
16990 OPERATOR_BEFORE,
16991 OPERATOR_AFTER,
16992 OPERATOR_BEFORE_INC,
16993 OPERATOR_AFTER_INC,
16994 OPERATOR_IN_THE_PAST,
16995 OPERATOR_OVER,
16996 OPERATOR_BETWEEN
16997 ],
16998 validOperators: [
16999 OPERATOR_ON,
17000 OPERATOR_NOT_ON,
17001 OPERATOR_BEFORE,
17002 OPERATOR_AFTER,
17003 OPERATOR_BEFORE_INC,
17004 OPERATOR_AFTER_INC,
17005 OPERATOR_IN_THE_PAST,
17006 OPERATOR_OVER,
17007 OPERATOR_BETWEEN
17008 ],
17009 format: format5,
17010 getValueFormatted: getValueFormatted5,
17011 validate: {
17012 required: isValidRequired,
17013 elements: isValidElements,
17014 min: isValidMinDate,
17015 max: isValidMaxDate
17016 }
17017 };
17018
17019 // packages/dataviews/build-module/field-types/boolean.mjs
17020 var import_i18n46 = __toESM(require_i18n(), 1);
17021
17022 // packages/dataviews/build-module/field-types/utils/is-valid-required-for-bool.mjs
17023 function isValidRequiredForBool(item, field) {
17024 const value = field.getValue({ item });
17025 return value === true;
17026 }
17027
17028 // packages/dataviews/build-module/field-types/boolean.mjs
17029 function getValueFormatted6({
17030 item,
17031 field
17032 }) {
17033 const value = field.getValue({ item });
17034 if (value === true) {
17035 return (0, import_i18n46.__)("True");
17036 }
17037 if (value === false) {
17038 return (0, import_i18n46.__)("False");
17039 }
17040 return "";
17041 }
17042 function isValidCustom4(item, field) {
17043 const value = field.getValue({ item });
17044 if (![void 0, "", null].includes(value) && ![true, false].includes(value)) {
17045 return (0, import_i18n46.__)("Value must be true, false, or undefined");
17046 }
17047 return null;
17048 }
17049 var sort3 = (a2, b2, direction) => {
17050 const boolA = Boolean(a2);
17051 const boolB = Boolean(b2);
17052 if (boolA === boolB) {
17053 return 0;
17054 }
17055 if (direction === "asc") {
17056 return boolA ? 1 : -1;
17057 }
17058 return boolA ? -1 : 1;
17059 };
17060 var boolean_default = {
17061 type: "boolean",
17062 render,
17063 Edit: "checkbox",
17064 sort: sort3,
17065 validate: {
17066 required: isValidRequiredForBool,
17067 elements: isValidElements,
17068 custom: isValidCustom4
17069 },
17070 enableSorting: true,
17071 enableGlobalSearch: false,
17072 defaultOperators: [OPERATOR_IS, OPERATOR_IS_NOT],
17073 validOperators: [OPERATOR_IS, OPERATOR_IS_NOT],
17074 format: {},
17075 getValueFormatted: getValueFormatted6
17076 };
17077
17078 // packages/dataviews/build-module/field-types/media.mjs
17079 var media_default = {
17080 type: "media",
17081 render: () => null,
17082 Edit: null,
17083 sort: () => 0,
17084 enableSorting: false,
17085 enableGlobalSearch: false,
17086 defaultOperators: [],
17087 validOperators: [],
17088 format: {},
17089 getValueFormatted: get_value_formatted_default_default,
17090 // cannot validate any constraint, so
17091 // the only available validation for the field author
17092 // would be providing a custom validator.
17093 validate: {}
17094 };
17095
17096 // packages/dataviews/build-module/field-types/array.mjs
17097 var import_i18n47 = __toESM(require_i18n(), 1);
17098
17099 // packages/dataviews/build-module/field-types/utils/is-valid-required-for-array.mjs
17100 function isValidRequiredForArray(item, field) {
17101 const value = field.getValue({ item });
17102 return Array.isArray(value) && value.length > 0 && value.every(
17103 (element) => ![void 0, "", null].includes(element)
17104 );
17105 }
17106
17107 // packages/dataviews/build-module/field-types/array.mjs
17108 function getValueFormatted7({
17109 item,
17110 field
17111 }) {
17112 const value = field.getValue({ item });
17113 const arr = Array.isArray(value) ? value : [];
17114 return arr.join(", ");
17115 }
17116 function render2({ item, field }) {
17117 return getValueFormatted7({ item, field });
17118 }
17119 function isValidCustom5(item, field) {
17120 const value = field.getValue({ item });
17121 if (![void 0, "", null].includes(value) && !Array.isArray(value)) {
17122 return (0, import_i18n47.__)("Value must be an array.");
17123 }
17124 if (!value.every((v2) => typeof v2 === "string")) {
17125 return (0, import_i18n47.__)("Every value must be a string.");
17126 }
17127 return null;
17128 }
17129 var sort4 = (a2, b2, direction) => {
17130 const arrA = Array.isArray(a2) ? a2 : [];
17131 const arrB = Array.isArray(b2) ? b2 : [];
17132 if (arrA.length !== arrB.length) {
17133 return direction === "asc" ? arrA.length - arrB.length : arrB.length - arrA.length;
17134 }
17135 const joinedA = arrA.join(",");
17136 const joinedB = arrB.join(",");
17137 return direction === "asc" ? joinedA.localeCompare(joinedB) : joinedB.localeCompare(joinedA);
17138 };
17139 var array_default = {
17140 type: "array",
17141 render: render2,
17142 Edit: "array",
17143 sort: sort4,
17144 enableSorting: true,
17145 enableGlobalSearch: false,
17146 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
17147 validOperators: [
17148 OPERATOR_IS_ANY,
17149 OPERATOR_IS_NONE,
17150 OPERATOR_IS_ALL,
17151 OPERATOR_IS_NOT_ALL
17152 ],
17153 format: {},
17154 getValueFormatted: getValueFormatted7,
17155 validate: {
17156 required: isValidRequiredForArray,
17157 elements: isValidElements,
17158 custom: isValidCustom5
17159 }
17160 };
17161
17162 // packages/dataviews/build-module/field-types/password.mjs
17163 function getValueFormatted8({
17164 item,
17165 field
17166 }) {
17167 return field.getValue({ item }) ? "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022" : "";
17168 }
17169 var password_default = {
17170 type: "password",
17171 render,
17172 Edit: "password",
17173 sort: () => 0,
17174 // Passwords should not be sortable for security reasons
17175 enableSorting: false,
17176 enableGlobalSearch: false,
17177 defaultOperators: [],
17178 validOperators: [],
17179 format: {},
17180 getValueFormatted: getValueFormatted8,
17181 validate: {
17182 required: isValidRequired,
17183 pattern: isValidPattern,
17184 minLength: isValidMinLength,
17185 maxLength: isValidMaxLength,
17186 elements: isValidElements
17187 }
17188 };
17189
17190 // packages/dataviews/build-module/field-types/telephone.mjs
17191 var telephone_default = {
17192 type: "telephone",
17193 render,
17194 Edit: "telephone",
17195 sort: sort_text_default,
17196 enableSorting: true,
17197 enableGlobalSearch: false,
17198 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
17199 validOperators: [
17200 OPERATOR_IS,
17201 OPERATOR_IS_NOT,
17202 OPERATOR_CONTAINS,
17203 OPERATOR_NOT_CONTAINS,
17204 OPERATOR_STARTS_WITH,
17205 // Multiple selection
17206 OPERATOR_IS_ANY,
17207 OPERATOR_IS_NONE,
17208 OPERATOR_IS_ALL,
17209 OPERATOR_IS_NOT_ALL
17210 ],
17211 format: {},
17212 getValueFormatted: get_value_formatted_default_default,
17213 validate: {
17214 required: isValidRequired,
17215 pattern: isValidPattern,
17216 minLength: isValidMinLength,
17217 maxLength: isValidMaxLength,
17218 elements: isValidElements
17219 }
17220 };
17221
17222 // packages/dataviews/build-module/field-types/color.mjs
17223 var import_i18n48 = __toESM(require_i18n(), 1);
17224 var import_jsx_runtime98 = __toESM(require_jsx_runtime(), 1);
17225 function render3({ item, field }) {
17226 if (field.hasElements) {
17227 return /* @__PURE__ */ (0, import_jsx_runtime98.jsx)(RenderFromElements, { item, field });
17228 }
17229 const value = get_value_formatted_default_default({ item, field });
17230 if (!value || !w(value).isValid()) {
17231 return value;
17232 }
17233 return /* @__PURE__ */ (0, import_jsx_runtime98.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "8px" }, children: [
17234 /* @__PURE__ */ (0, import_jsx_runtime98.jsx)(
17235 "div",
17236 {
17237 style: {
17238 width: "16px",
17239 height: "16px",
17240 borderRadius: "50%",
17241 backgroundColor: value,
17242 border: "1px solid #ddd",
17243 flexShrink: 0
17244 }
17245 }
17246 ),
17247 /* @__PURE__ */ (0, import_jsx_runtime98.jsx)("span", { children: value })
17248 ] });
17249 }
17250 function isValidCustom6(item, field) {
17251 const value = field.getValue({ item });
17252 if (![void 0, "", null].includes(value) && !w(value).isValid()) {
17253 return (0, import_i18n48.__)("Value must be a valid color.");
17254 }
17255 return null;
17256 }
17257 var sort5 = (a2, b2, direction) => {
17258 const colorA = w(a2);
17259 const colorB = w(b2);
17260 if (!colorA.isValid() && !colorB.isValid()) {
17261 return 0;
17262 }
17263 if (!colorA.isValid()) {
17264 return direction === "asc" ? 1 : -1;
17265 }
17266 if (!colorB.isValid()) {
17267 return direction === "asc" ? -1 : 1;
17268 }
17269 const hslA = colorA.toHsl();
17270 const hslB = colorB.toHsl();
17271 if (hslA.h !== hslB.h) {
17272 return direction === "asc" ? hslA.h - hslB.h : hslB.h - hslA.h;
17273 }
17274 if (hslA.s !== hslB.s) {
17275 return direction === "asc" ? hslA.s - hslB.s : hslB.s - hslA.s;
17276 }
17277 return direction === "asc" ? hslA.l - hslB.l : hslB.l - hslA.l;
17278 };
17279 var color_default = {
17280 type: "color",
17281 render: render3,
17282 Edit: "color",
17283 sort: sort5,
17284 enableSorting: true,
17285 enableGlobalSearch: false,
17286 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
17287 validOperators: [
17288 OPERATOR_IS,
17289 OPERATOR_IS_NOT,
17290 OPERATOR_IS_ANY,
17291 OPERATOR_IS_NONE
17292 ],
17293 format: {},
17294 getValueFormatted: get_value_formatted_default_default,
17295 validate: {
17296 required: isValidRequired,
17297 elements: isValidElements,
17298 custom: isValidCustom6
17299 }
17300 };
17301
17302 // packages/dataviews/build-module/field-types/url.mjs
17303 var url_default = {
17304 type: "url",
17305 render,
17306 Edit: "url",
17307 sort: sort_text_default,
17308 enableSorting: true,
17309 enableGlobalSearch: false,
17310 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
17311 validOperators: [
17312 OPERATOR_IS,
17313 OPERATOR_IS_NOT,
17314 OPERATOR_CONTAINS,
17315 OPERATOR_NOT_CONTAINS,
17316 OPERATOR_STARTS_WITH,
17317 // Multiple selection
17318 OPERATOR_IS_ANY,
17319 OPERATOR_IS_NONE,
17320 OPERATOR_IS_ALL,
17321 OPERATOR_IS_NOT_ALL
17322 ],
17323 format: {},
17324 getValueFormatted: get_value_formatted_default_default,
17325 validate: {
17326 required: isValidRequired,
17327 pattern: isValidPattern,
17328 minLength: isValidMinLength,
17329 maxLength: isValidMaxLength,
17330 elements: isValidElements
17331 }
17332 };
17333
17334 // packages/dataviews/build-module/field-types/no-type.mjs
17335 var sort6 = (a2, b2, direction) => {
17336 if (typeof a2 === "number" && typeof b2 === "number") {
17337 return sort_number_default(a2, b2, direction);
17338 }
17339 return sort_text_default(a2, b2, direction);
17340 };
17341 var no_type_default = {
17342 // type: no type for this one
17343 render,
17344 Edit: null,
17345 sort: sort6,
17346 enableSorting: true,
17347 enableGlobalSearch: false,
17348 defaultOperators: [OPERATOR_IS, OPERATOR_IS_NOT],
17349 validOperators: getAllOperatorNames(),
17350 format: {},
17351 getValueFormatted: get_value_formatted_default_default,
17352 validate: {
17353 required: isValidRequired,
17354 elements: isValidElements
17355 }
17356 };
17357
17358 // packages/dataviews/build-module/field-types/utils/get-is-valid.mjs
17359 function supportsNumericRangeConstraint(type) {
17360 return type === "integer" || type === "number";
17361 }
17362 function supportsDateRangeConstraint(type) {
17363 return type === "date" || type === "datetime";
17364 }
17365 function normalizeRangeRule(value, fieldType, key) {
17366 const validator = fieldType.validate[key];
17367 if (validator && (typeof value === "number" && supportsNumericRangeConstraint(fieldType.type) || typeof value === "string" && supportsDateRangeConstraint(fieldType.type))) {
17368 return { constraint: value, validate: validator };
17369 }
17370 return void 0;
17371 }
17372 function getIsValid(field, fieldType) {
17373 const rules = field.isValid;
17374 let required;
17375 if (rules?.required === true && fieldType.validate.required !== void 0) {
17376 required = {
17377 constraint: true,
17378 validate: fieldType.validate.required
17379 };
17380 }
17381 let elements;
17382 if ((rules?.elements === true || // elements is enabled unless the field opts-out
17383 rules?.elements === void 0 && (!!field.elements || !!field.getElements)) && fieldType.validate.elements !== void 0) {
17384 elements = {
17385 constraint: true,
17386 validate: fieldType.validate.elements
17387 };
17388 }
17389 const min = normalizeRangeRule(rules?.min, fieldType, "min");
17390 const max = normalizeRangeRule(rules?.max, fieldType, "max");
17391 const minLengthValue = rules?.minLength;
17392 let minLength;
17393 if (typeof minLengthValue === "number" && fieldType.validate.minLength !== void 0) {
17394 minLength = {
17395 constraint: minLengthValue,
17396 validate: fieldType.validate.minLength
17397 };
17398 }
17399 const maxLengthValue = rules?.maxLength;
17400 let maxLength;
17401 if (typeof maxLengthValue === "number" && fieldType.validate.maxLength !== void 0) {
17402 maxLength = {
17403 constraint: maxLengthValue,
17404 validate: fieldType.validate.maxLength
17405 };
17406 }
17407 const patternValue = rules?.pattern;
17408 let pattern;
17409 if (patternValue !== void 0 && fieldType.validate.pattern !== void 0) {
17410 pattern = {
17411 constraint: patternValue,
17412 validate: fieldType.validate.pattern
17413 };
17414 }
17415 const custom = rules?.custom ?? fieldType.validate.custom;
17416 return {
17417 required,
17418 elements,
17419 min,
17420 max,
17421 minLength,
17422 maxLength,
17423 pattern,
17424 custom
17425 };
17426 }
17427
17428 // packages/dataviews/build-module/field-types/utils/get-filter.mjs
17429 function getFilter(fieldType) {
17430 return fieldType.validOperators.reduce((accumulator, operator) => {
17431 const operatorObj = getOperatorByName(operator);
17432 if (operatorObj?.filter) {
17433 accumulator[operator] = operatorObj.filter;
17434 }
17435 return accumulator;
17436 }, {});
17437 }
17438
17439 // packages/dataviews/build-module/field-types/utils/get-format.mjs
17440 function getFormat(field, fieldType) {
17441 return {
17442 ...fieldType.format,
17443 ...field.format
17444 };
17445 }
17446 var get_format_default = getFormat;
17447
17448 // packages/dataviews/build-module/field-types/index.mjs
17449 function getFieldTypeByName(type) {
17450 const found = [
17451 email_default,
17452 integer_default,
17453 number_default,
17454 text_default,
17455 datetime_default,
17456 date_default,
17457 boolean_default,
17458 media_default,
17459 array_default,
17460 password_default,
17461 telephone_default,
17462 color_default,
17463 url_default
17464 ].find((fieldType) => fieldType?.type === type);
17465 if (!!found) {
17466 return found;
17467 }
17468 return no_type_default;
17469 }
17470 function normalizeFields(fields) {
17471 return fields.map((field) => {
17472 const fieldType = getFieldTypeByName(field.type);
17473 const getValue = field.getValue || get_value_from_id_default(field.id);
17474 const sort7 = function(a2, b2, direction) {
17475 const aValue = getValue({ item: a2 });
17476 const bValue = getValue({ item: b2 });
17477 return field.sort ? field.sort(aValue, bValue, direction) : fieldType.sort(aValue, bValue, direction);
17478 };
17479 return {
17480 id: field.id,
17481 label: field.label || field.id,
17482 header: field.header || field.label || field.id,
17483 description: field.description,
17484 placeholder: field.placeholder,
17485 getValue,
17486 setValue: field.setValue || set_value_from_id_default(field.id),
17487 elements: field.elements,
17488 getElements: field.getElements,
17489 hasElements: hasElements(field),
17490 isVisible: field.isVisible,
17491 isDisabled: typeof field.isDisabled === "function" ? field.isDisabled : () => !!field.isDisabled,
17492 enableHiding: field.enableHiding ?? true,
17493 readOnly: field.readOnly ?? false,
17494 // The type provides defaults for the following props
17495 type: fieldType.type,
17496 render: field.render ?? fieldType.render,
17497 Edit: getControl(field, fieldType.Edit),
17498 sort: sort7,
17499 enableSorting: field.enableSorting ?? fieldType.enableSorting,
17500 enableGlobalSearch: field.enableGlobalSearch ?? fieldType.enableGlobalSearch,
17501 isValid: getIsValid(field, fieldType),
17502 filterBy: get_filter_by_default(
17503 field,
17504 fieldType.defaultOperators,
17505 fieldType.validOperators
17506 ),
17507 filter: getFilter(fieldType),
17508 format: get_format_default(field, fieldType),
17509 getValueFormatted: field.getValueFormatted ?? fieldType.getValueFormatted
17510 };
17511 });
17512 }
17513
17514 // packages/dataviews/build-module/hooks/use-data.mjs
17515 var import_element56 = __toESM(require_element(), 1);
17516 function useData({
17517 view,
17518 data: shownData,
17519 getItemId,
17520 isLoading,
17521 paginationInfo,
17522 selection
17523 }) {
17524 const isInfiniteScrollEnabled = view.infiniteScrollEnabled;
17525 const [hasInitiallyLoaded, setHasInitiallyLoaded] = (0, import_element56.useState)(
17526 !isLoading
17527 );
17528 (0, import_element56.useEffect)(() => {
17529 if (!isLoading) {
17530 setHasInitiallyLoaded(true);
17531 }
17532 }, [isLoading]);
17533 const previousDataRef = (0, import_element56.useRef)(shownData);
17534 const previousPaginationInfoRef = (0, import_element56.useRef)(paginationInfo);
17535 (0, import_element56.useEffect)(() => {
17536 if (!isLoading) {
17537 previousDataRef.current = shownData;
17538 previousPaginationInfoRef.current = paginationInfo;
17539 }
17540 }, [shownData, isLoading, paginationInfo]);
17541 const [visibleEntries, setVisibleEntries] = (0, import_element56.useState)([]);
17542 const positionMapRef = (0, import_element56.useRef)(/* @__PURE__ */ new Map());
17543 const allLoadedRecordsRef = (0, import_element56.useRef)([]);
17544 const prevViewParamsRef = (0, import_element56.useRef)({
17545 search: void 0,
17546 filters: void 0,
17547 perPage: void 0
17548 });
17549 const scrollDirectionRef = (0, import_element56.useRef)(void 0);
17550 const prevStartPositionRef = (0, import_element56.useRef)(void 0);
17551 const hasInitializedRef = (0, import_element56.useRef)(false);
17552 const allLoadedRecords = (0, import_element56.useMemo)(() => {
17553 if (view.startPosition !== void 0 && prevStartPositionRef.current !== void 0) {
17554 if (view.startPosition < prevStartPositionRef.current) {
17555 scrollDirectionRef.current = "up";
17556 } else if (view.startPosition > prevStartPositionRef.current) {
17557 scrollDirectionRef.current = "down";
17558 }
17559 }
17560 prevStartPositionRef.current = view.startPosition;
17561 const currentFiltersKey = JSON.stringify(view.filters ?? []);
17562 const prevFiltersKey = prevViewParamsRef.current.filters;
17563 const shouldReset = !hasInitializedRef.current || !view.infiniteScrollEnabled || view.search !== prevViewParamsRef.current.search || currentFiltersKey !== prevFiltersKey || view.perPage !== prevViewParamsRef.current.perPage;
17564 hasInitializedRef.current = true;
17565 prevViewParamsRef.current = {
17566 search: view.search,
17567 filters: currentFiltersKey,
17568 perPage: view.perPage
17569 };
17570 if (shouldReset) {
17571 positionMapRef.current.clear();
17572 scrollDirectionRef.current = void 0;
17573 const startPosition = view.search ? 1 : view.startPosition ?? 1;
17574 const records = shownData.map((record, index) => {
17575 const position = startPosition + index;
17576 positionMapRef.current.set(getItemId(record), position);
17577 return {
17578 ...record,
17579 position
17580 };
17581 });
17582 allLoadedRecordsRef.current = records;
17583 return records;
17584 }
17585 const prev = allLoadedRecordsRef.current;
17586 const shownDataIds = new Set(shownData.map(getItemId));
17587 const scrollDirection = scrollDirectionRef.current;
17588 const basePosition = view.search ? 1 : view.startPosition ?? 1;
17589 const newRecords = shownData.map((record, index) => {
17590 const itemId = getItemId(record);
17591 const position = view.infiniteScrollEnabled ? basePosition + index : void 0;
17592 if (position !== void 0) {
17593 positionMapRef.current.set(itemId, position);
17594 }
17595 return {
17596 ...record,
17597 position
17598 };
17599 });
17600 if (newRecords.length === 0) {
17601 return prev;
17602 }
17603 const prevWithoutDuplicates = prev.filter(
17604 (record) => !shownDataIds.has(getItemId(record))
17605 );
17606 const allRecords = scrollDirection === "up" ? [...newRecords, ...prevWithoutDuplicates] : [...prevWithoutDuplicates, ...newRecords];
17607 allRecords.sort((a2, b2) => {
17608 const posA = a2.position;
17609 const posB = b2.position;
17610 return posA - posB;
17611 });
17612 let result = allRecords;
17613 if (visibleEntries.length > 0) {
17614 const visibleMin = Math.min(...visibleEntries);
17615 const visibleMax = Math.max(...visibleEntries);
17616 const buffer = 20;
17617 const recordPositions = allRecords.map(
17618 (r3) => r3.position
17619 );
17620 const minRecordPos = Math.min(...recordPositions);
17621 const maxRecordPos = Math.max(...recordPositions);
17622 const hasOverlap = !(maxRecordPos < visibleMin - buffer || minRecordPos > visibleMax + buffer);
17623 if (hasOverlap) {
17624 result = allRecords.filter((record) => {
17625 const itemId = getItemId(record);
17626 const isSelected2 = selection?.includes(itemId);
17627 if (isSelected2) {
17628 return true;
17629 }
17630 const itemPosition = record.position;
17631 if (scrollDirection === "up") {
17632 return itemPosition <= visibleMax + buffer;
17633 } else if (scrollDirection === "down") {
17634 return itemPosition >= visibleMin - buffer;
17635 }
17636 return itemPosition >= visibleMin - buffer && itemPosition <= visibleMax + buffer;
17637 });
17638 }
17639 }
17640 allLoadedRecordsRef.current = result;
17641 return result;
17642 }, [
17643 shownData,
17644 view.search,
17645 view.filters,
17646 view.perPage,
17647 view.startPosition,
17648 view.infiniteScrollEnabled,
17649 visibleEntries,
17650 selection,
17651 getItemId
17652 ]);
17653 if (!isInfiniteScrollEnabled) {
17654 const dataToReturn = isLoading && previousDataRef.current?.length ? previousDataRef.current : shownData;
17655 return {
17656 data: dataToReturn.map((item) => ({
17657 ...item,
17658 position: void 0
17659 })),
17660 paginationInfo: isLoading && previousDataRef.current?.length ? previousPaginationInfoRef.current : paginationInfo,
17661 hasInitiallyLoaded,
17662 setVisibleEntries: void 0
17663 };
17664 }
17665 return {
17666 data: allLoadedRecords,
17667 paginationInfo,
17668 hasInitiallyLoaded,
17669 setVisibleEntries
17670 };
17671 }
17672
17673 // packages/dataviews/build-module/hooks/use-infinite-scroll.mjs
17674 var import_element57 = __toESM(require_element(), 1);
17675 var import_compose11 = __toESM(require_compose(), 1);
17676 function captureAnchorElement(container, anchorElementRef, direction) {
17677 const containerRect = container.getBoundingClientRect();
17678 const centerY = containerRect.top + containerRect.height / 2;
17679 const items = Array.from(container.querySelectorAll("[aria-posinset]"));
17680 if (items.length === 0) {
17681 return false;
17682 }
17683 const bestAnchor = items.reduce((best, item) => {
17684 const itemRect = item.getBoundingClientRect();
17685 const itemCenterY = itemRect.top + itemRect.height / 2;
17686 const distance = Math.abs(itemCenterY - centerY);
17687 const bestRect = best.getBoundingClientRect();
17688 const bestCenterY = bestRect.top + bestRect.height / 2;
17689 const bestDistance = Math.abs(bestCenterY - centerY);
17690 return distance < bestDistance ? item : best;
17691 });
17692 const posinset = Number(bestAnchor.getAttribute("aria-posinset"));
17693 const anchorRect = bestAnchor.getBoundingClientRect();
17694 anchorElementRef.current = {
17695 posinset,
17696 viewportOffset: anchorRect.top - containerRect.top,
17697 direction
17698 };
17699 return true;
17700 }
17701 function useInfiniteScroll({
17702 view,
17703 onChangeView,
17704 isLoading,
17705 paginationInfo,
17706 containerRef,
17707 setVisibleEntries
17708 }) {
17709 const anchorElementRef = (0, import_element57.useRef)(null);
17710 const viewRef = (0, import_element57.useRef)(view);
17711 const isLoadingRef = (0, import_element57.useRef)(isLoading);
17712 const onChangeViewRef = (0, import_element57.useRef)(onChangeView);
17713 const totalItemsRef = (0, import_element57.useRef)(paginationInfo.totalItems);
17714 (0, import_element57.useLayoutEffect)(() => {
17715 viewRef.current = view;
17716 isLoadingRef.current = isLoading;
17717 onChangeViewRef.current = onChangeView;
17718 totalItemsRef.current = paginationInfo.totalItems;
17719 }, [view, isLoading, onChangeView, paginationInfo.totalItems]);
17720 const intersectionObserverCallback = (0, import_element57.useCallback)(
17721 (entries) => {
17722 if (!setVisibleEntries) {
17723 return;
17724 }
17725 setVisibleEntries((prev) => {
17726 const newVisibleEntries = new Set(prev);
17727 let hasChanged = false;
17728 entries.forEach((entry) => {
17729 const posInSet = Number(
17730 entry.target?.attributes?.getNamedItem(
17731 "aria-posinset"
17732 )?.value
17733 );
17734 if (isNaN(posInSet)) {
17735 return;
17736 }
17737 if (entry.isIntersecting) {
17738 if (!newVisibleEntries.has(posInSet)) {
17739 newVisibleEntries.add(posInSet);
17740 hasChanged = true;
17741 }
17742 } else if (newVisibleEntries.has(posInSet)) {
17743 newVisibleEntries.delete(posInSet);
17744 hasChanged = true;
17745 }
17746 });
17747 return hasChanged ? Array.from(newVisibleEntries).sort() : prev;
17748 });
17749 },
17750 [setVisibleEntries]
17751 );
17752 (0, import_element57.useLayoutEffect)(() => {
17753 const container = containerRef.current;
17754 const anchor = anchorElementRef.current;
17755 if (!container || !view.infiniteScrollEnabled || !anchor || isLoading) {
17756 return;
17757 }
17758 const anchorElement = container.querySelector(
17759 `[aria-posinset="${anchor.posinset}"]`
17760 );
17761 if (anchorElement) {
17762 const containerRect = container.getBoundingClientRect();
17763 const anchorRect = anchorElement.getBoundingClientRect();
17764 const currentOffset = anchorRect.top - containerRect.top;
17765 const scrollAdjustment = currentOffset - anchor.viewportOffset;
17766 if (Math.abs(scrollAdjustment) > 1) {
17767 container.scrollTop += scrollAdjustment;
17768 }
17769 }
17770 anchorElementRef.current = null;
17771 }, [containerRef, isLoading, view.infiniteScrollEnabled]);
17772 const intersectionObserverRef = (0, import_element57.useRef)(
17773 null
17774 );
17775 (0, import_element57.useEffect)(() => {
17776 if (!view.infiniteScrollEnabled || !intersectionObserverCallback) {
17777 if (intersectionObserverRef.current) {
17778 intersectionObserverRef.current.disconnect();
17779 intersectionObserverRef.current = null;
17780 }
17781 return;
17782 }
17783 intersectionObserverRef.current = new IntersectionObserver(
17784 intersectionObserverCallback,
17785 { root: null, rootMargin: "0px", threshold: 0.1 }
17786 );
17787 return () => {
17788 if (intersectionObserverRef.current) {
17789 intersectionObserverRef.current.disconnect();
17790 intersectionObserverRef.current = null;
17791 }
17792 };
17793 }, [view.infiniteScrollEnabled, intersectionObserverCallback]);
17794 (0, import_element57.useEffect)(() => {
17795 if (!view.infiniteScrollEnabled || !containerRef.current) {
17796 return;
17797 }
17798 let lastScrollTop = 0;
17799 const BOTTOM_THRESHOLD = 600;
17800 const TOP_THRESHOLD = 800;
17801 const handleScroll = (0, import_compose11.throttle)((event) => {
17802 const currentView = viewRef.current;
17803 const totalItems = totalItemsRef.current;
17804 const target = event.target;
17805 const scrollTop = target.scrollTop;
17806 const scrollHeight = target.scrollHeight;
17807 const clientHeight = target.clientHeight;
17808 const scrollDirection = scrollTop > lastScrollTop ? "down" : "up";
17809 lastScrollTop = scrollTop;
17810 if (isLoadingRef.current) {
17811 return;
17812 }
17813 const currentStartPosition = currentView.startPosition || 1;
17814 const batchSize = currentView.perPage || 10;
17815 const currentEndPosition = Math.min(
17816 currentStartPosition + batchSize,
17817 totalItems
17818 );
17819 if (scrollDirection === "down" && scrollTop + clientHeight >= scrollHeight - BOTTOM_THRESHOLD) {
17820 if (currentEndPosition < totalItems) {
17821 const newStartPosition = currentEndPosition;
17822 captureAnchorElement(target, anchorElementRef, "down");
17823 onChangeViewRef.current({
17824 ...currentView,
17825 startPosition: newStartPosition
17826 });
17827 }
17828 }
17829 if (scrollDirection === "up" && scrollTop <= TOP_THRESHOLD) {
17830 if (currentStartPosition > 1) {
17831 const calculatedStartPosition = currentStartPosition - batchSize;
17832 const newStartPosition = calculatedStartPosition < 6 ? 1 : calculatedStartPosition;
17833 captureAnchorElement(target, anchorElementRef, "up");
17834 onChangeViewRef.current({
17835 ...currentView,
17836 startPosition: newStartPosition
17837 });
17838 }
17839 }
17840 }, 50);
17841 const container = containerRef.current;
17842 container.addEventListener("scroll", handleScroll);
17843 return () => {
17844 container.removeEventListener("scroll", handleScroll);
17845 handleScroll.cancel();
17846 };
17847 }, [containerRef, view.infiniteScrollEnabled]);
17848 return {
17849 intersectionObserver: intersectionObserverRef.current
17850 };
17851 }
17852
17853 // packages/dataviews/build-module/dataviews-picker/index.mjs
17854 var import_element58 = __toESM(require_element(), 1);
17855 var import_compose12 = __toESM(require_compose(), 1);
17856 var import_jsx_runtime99 = __toESM(require_jsx_runtime(), 1);
17857 var isItemClickable = () => false;
17858 var dataViewsPickerLayouts = VIEW_LAYOUTS.filter(
17859 (viewLayout) => viewLayout.isPicker
17860 );
17861 var defaultGetItemId = (item) => item.id;
17862 var EMPTY_ARRAY5 = [];
17863 var DEFAULT_PICKER_LAYOUTS = {
17864 pickerGrid: true,
17865 pickerTable: true
17866 };
17867 function DefaultUI({
17868 search = true,
17869 searchLabel = void 0
17870 }) {
17871 const { view } = (0, import_element58.useContext)(dataviews_context_default);
17872 const isInfiniteScroll = view.infiniteScrollEnabled;
17873 return /* @__PURE__ */ (0, import_jsx_runtime99.jsxs)(import_jsx_runtime99.Fragment, { children: [
17874 /* @__PURE__ */ (0, import_jsx_runtime99.jsxs)(
17875 Stack,
17876 {
17877 direction: "row",
17878 align: "top",
17879 justify: "space-between",
17880 className: clsx_default("dataviews__view-actions", {
17881 "dataviews__view-actions--infinite-scroll": isInfiniteScroll
17882 }),
17883 gap: "xs",
17884 children: [
17885 /* @__PURE__ */ (0, import_jsx_runtime99.jsxs)(
17886 Stack,
17887 {
17888 direction: "row",
17889 gap: "sm",
17890 justify: "start",
17891 className: "dataviews__search",
17892 children: [
17893 search && /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(dataviews_search_default, { label: searchLabel }),
17894 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(toggle_default, {})
17895 ]
17896 }
17897 ),
17898 /* @__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, {}) })
17899 ]
17900 }
17901 ),
17902 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(filters_toggled_default, { className: "dataviews-filters__container" }),
17903 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(DataViewsLayout, {}),
17904 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(DataViewsPickerFooter, {})
17905 ] });
17906 }
17907 function DataViewsPicker({
17908 view,
17909 onChangeView,
17910 fields,
17911 search = true,
17912 searchLabel = void 0,
17913 actions = EMPTY_ARRAY5,
17914 data,
17915 getItemId = defaultGetItemId,
17916 isLoading = false,
17917 paginationInfo,
17918 defaultLayouts: defaultLayoutsProperty = DEFAULT_PICKER_LAYOUTS,
17919 selection,
17920 onChangeSelection,
17921 children,
17922 config = { perPageSizes: [10, 20, 50, 100] },
17923 itemListLabel,
17924 empty,
17925 onReset
17926 }) {
17927 const { data: displayData, setVisibleEntries } = useData({
17928 view,
17929 data,
17930 getItemId,
17931 selection,
17932 paginationInfo
17933 });
17934 const containerRef = (0, import_element58.useRef)(null);
17935 const [containerWidth, setContainerWidth] = (0, import_element58.useState)(0);
17936 const resizeObserverRef = (0, import_compose12.useResizeObserver)(
17937 (resizeObserverEntries) => {
17938 setContainerWidth(
17939 resizeObserverEntries[0].borderBoxSize[0].inlineSize
17940 );
17941 },
17942 { box: "border-box" }
17943 );
17944 const [openedFilter, setOpenedFilter] = (0, import_element58.useState)(null);
17945 function setSelectionWithChange(value) {
17946 const newValue = typeof value === "function" ? value(selection) : value;
17947 if (onChangeSelection) {
17948 onChangeSelection(newValue);
17949 }
17950 }
17951 const _fields = (0, import_element58.useMemo)(() => normalizeFields(fields), [fields]);
17952 const filters = use_filters_default(_fields, view);
17953 const hasPrimaryOrLockedFilters = (0, import_element58.useMemo)(
17954 () => (filters || []).some(
17955 (filter) => filter.isPrimary || filter.isLocked
17956 ),
17957 [filters]
17958 );
17959 const [isShowingFilter, setIsShowingFilter] = (0, import_element58.useState)(
17960 hasPrimaryOrLockedFilters
17961 );
17962 const { intersectionObserver } = useInfiniteScroll({
17963 view,
17964 onChangeView,
17965 isLoading,
17966 paginationInfo,
17967 containerRef,
17968 setVisibleEntries
17969 });
17970 (0, import_element58.useEffect)(() => {
17971 if (hasPrimaryOrLockedFilters && !isShowingFilter) {
17972 setIsShowingFilter(true);
17973 }
17974 }, [hasPrimaryOrLockedFilters, isShowingFilter]);
17975 const defaultLayouts2 = (0, import_element58.useMemo)(
17976 () => Object.fromEntries(
17977 Object.entries(defaultLayoutsProperty).filter(([layoutType]) => {
17978 return dataViewsPickerLayouts.some(
17979 (viewLayout) => viewLayout.type === layoutType
17980 );
17981 }).map(([key, value]) => [
17982 key,
17983 value === true ? {} : value
17984 ])
17985 ),
17986 [defaultLayoutsProperty]
17987 );
17988 if (!defaultLayouts2[view.type]) {
17989 return null;
17990 }
17991 return /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(
17992 dataviews_context_default.Provider,
17993 {
17994 value: {
17995 view,
17996 onChangeView,
17997 fields: _fields,
17998 actions,
17999 data: displayData,
18000 isLoading,
18001 paginationInfo,
18002 isItemClickable,
18003 selection,
18004 onChangeSelection: setSelectionWithChange,
18005 openedFilter,
18006 setOpenedFilter,
18007 getItemId,
18008 containerWidth,
18009 containerRef,
18010 resizeObserverRef,
18011 defaultLayouts: defaultLayouts2,
18012 filters,
18013 isShowingFilter,
18014 setIsShowingFilter,
18015 config,
18016 itemListLabel,
18017 empty,
18018 onReset,
18019 hasInitiallyLoaded: true,
18020 intersectionObserver
18021 },
18022 children: /* @__PURE__ */ (0, import_jsx_runtime99.jsx)("div", { className: "dataviews-picker-wrapper", children: children ?? /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(DefaultUI, { search, searchLabel }) })
18023 }
18024 );
18025 }
18026 var DataViewsPickerSubComponents = DataViewsPicker;
18027 DataViewsPickerSubComponents.BulkActionToolbar = DataViewsPickerFooter;
18028 DataViewsPickerSubComponents.Filters = filters_default;
18029 DataViewsPickerSubComponents.FiltersToggled = filters_toggled_default;
18030 DataViewsPickerSubComponents.FiltersToggle = toggle_default;
18031 DataViewsPickerSubComponents.Layout = DataViewsLayout;
18032 DataViewsPickerSubComponents.LayoutSwitcher = ViewTypeMenu;
18033 DataViewsPickerSubComponents.Pagination = DataViewsPagination;
18034 DataViewsPickerSubComponents.Search = dataviews_search_default;
18035 DataViewsPickerSubComponents.ViewConfig = DataviewsViewConfigDropdown;
18036 var dataviews_picker_default = DataViewsPickerSubComponents;
18037
18038 // node_modules/dequal/dist/index.mjs
18039 var has = Object.prototype.hasOwnProperty;
18040 function find(iter, tar, key) {
18041 for (key of iter.keys()) {
18042 if (dequal(key, tar)) return key;
18043 }
18044 }
18045 function dequal(foo, bar) {
18046 var ctor, len, tmp;
18047 if (foo === bar) return true;
18048 if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
18049 if (ctor === Date) return foo.getTime() === bar.getTime();
18050 if (ctor === RegExp) return foo.toString() === bar.toString();
18051 if (ctor === Array) {
18052 if ((len = foo.length) === bar.length) {
18053 while (len-- && dequal(foo[len], bar[len])) ;
18054 }
18055 return len === -1;
18056 }
18057 if (ctor === Set) {
18058 if (foo.size !== bar.size) {
18059 return false;
18060 }
18061 for (len of foo) {
18062 tmp = len;
18063 if (tmp && typeof tmp === "object") {
18064 tmp = find(bar, tmp);
18065 if (!tmp) return false;
18066 }
18067 if (!bar.has(tmp)) return false;
18068 }
18069 return true;
18070 }
18071 if (ctor === Map) {
18072 if (foo.size !== bar.size) {
18073 return false;
18074 }
18075 for (len of foo) {
18076 tmp = len[0];
18077 if (tmp && typeof tmp === "object") {
18078 tmp = find(bar, tmp);
18079 if (!tmp) return false;
18080 }
18081 if (!dequal(len[1], bar.get(tmp))) {
18082 return false;
18083 }
18084 }
18085 return true;
18086 }
18087 if (ctor === ArrayBuffer) {
18088 foo = new Uint8Array(foo);
18089 bar = new Uint8Array(bar);
18090 } else if (ctor === DataView) {
18091 if ((len = foo.byteLength) === bar.byteLength) {
18092 while (len-- && foo.getInt8(len) === bar.getInt8(len)) ;
18093 }
18094 return len === -1;
18095 }
18096 if (ArrayBuffer.isView(foo)) {
18097 if ((len = foo.byteLength) === bar.byteLength) {
18098 while (len-- && foo[len] === bar[len]) ;
18099 }
18100 return len === -1;
18101 }
18102 if (!ctor || typeof foo === "object") {
18103 len = 0;
18104 for (ctor in foo) {
18105 if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
18106 if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
18107 }
18108 return Object.keys(bar).length === len;
18109 }
18110 }
18111 return foo !== foo && bar !== bar;
18112 }
18113
18114 // packages/views/build-module/use-view.mjs
18115 var import_element59 = __toESM(require_element(), 1);
18116 var import_data6 = __toESM(require_data(), 1);
18117 var import_preferences = __toESM(require_preferences(), 1);
18118
18119 // packages/views/build-module/preference-keys.mjs
18120 function generatePreferenceKey(kind, name, slug) {
18121 return `dataviews-${kind}-${name}-${slug}`;
18122 }
18123
18124 // packages/views/build-module/filter-utils.mjs
18125 var SCALAR_VALUES = [
18126 "titleField",
18127 "mediaField",
18128 "descriptionField",
18129 "showTitle",
18130 "showMedia",
18131 "showDescription",
18132 "showLevels",
18133 "infiniteScrollEnabled"
18134 ];
18135 function mergeActiveViewOverrides(view, activeViewOverrides, defaultView2) {
18136 if (!activeViewOverrides) {
18137 return view;
18138 }
18139 let result = view;
18140 for (const key of SCALAR_VALUES) {
18141 if (key in activeViewOverrides) {
18142 result = { ...result, [key]: activeViewOverrides[key] };
18143 }
18144 }
18145 if (activeViewOverrides.filters && activeViewOverrides.filters.length > 0) {
18146 const activeFields = new Set(
18147 activeViewOverrides.filters.map((f2) => f2.field)
18148 );
18149 const preserved = (view.filters ?? []).filter(
18150 (f2) => !activeFields.has(f2.field)
18151 );
18152 result = {
18153 ...result,
18154 filters: [...preserved, ...activeViewOverrides.filters]
18155 };
18156 }
18157 if (activeViewOverrides.sort) {
18158 const isDefaultSort = defaultView2 && view.sort?.field === defaultView2.sort?.field && view.sort?.direction === defaultView2.sort?.direction;
18159 if (isDefaultSort) {
18160 result = {
18161 ...result,
18162 sort: activeViewOverrides.sort
18163 };
18164 }
18165 }
18166 if (activeViewOverrides.layout) {
18167 result = {
18168 ...result,
18169 layout: {
18170 ...result.layout,
18171 ...activeViewOverrides.layout
18172 }
18173 };
18174 }
18175 if (activeViewOverrides.groupBy) {
18176 result = {
18177 ...result,
18178 groupBy: activeViewOverrides.groupBy
18179 };
18180 }
18181 return result;
18182 }
18183 function stripActiveViewOverrides(view, activeViewOverrides, defaultView2) {
18184 if (!activeViewOverrides) {
18185 return view;
18186 }
18187 let result = view;
18188 for (const key of SCALAR_VALUES) {
18189 if (key in activeViewOverrides) {
18190 const { [key]: _, ...rest } = result;
18191 result = rest;
18192 }
18193 }
18194 if (activeViewOverrides.filters && activeViewOverrides.filters.length > 0) {
18195 const activeFields = new Set(
18196 activeViewOverrides.filters.map((f2) => f2.field)
18197 );
18198 result = {
18199 ...result,
18200 filters: (view.filters ?? []).filter(
18201 (f2) => !activeFields.has(f2.field)
18202 )
18203 };
18204 }
18205 if (activeViewOverrides.sort && view.sort?.field === activeViewOverrides.sort.field && view.sort?.direction === activeViewOverrides.sort.direction) {
18206 result = {
18207 ...result,
18208 sort: defaultView2?.sort
18209 };
18210 }
18211 if (activeViewOverrides.layout && "layout" in result && result.layout) {
18212 const layout = { ...result.layout };
18213 for (const key of Object.keys(activeViewOverrides.layout)) {
18214 delete layout[key];
18215 }
18216 result = {
18217 ...result,
18218 layout: Object.keys(layout).length > 0 ? layout : void 0
18219 };
18220 }
18221 if (activeViewOverrides.groupBy && "groupBy" in result) {
18222 const { groupBy: _, ...rest } = result;
18223 result = rest;
18224 }
18225 return result;
18226 }
18227
18228 // packages/views/build-module/use-view.mjs
18229 function omit3(obj, keys) {
18230 const result = { ...obj };
18231 for (const key of keys) {
18232 delete result[key];
18233 }
18234 return result;
18235 }
18236 function useView(config) {
18237 const {
18238 kind,
18239 name,
18240 slug,
18241 defaultView: defaultView2,
18242 activeViewOverrides,
18243 queryParams,
18244 onChangeQueryParams
18245 } = config;
18246 const preferenceKey = generatePreferenceKey(kind, name, slug);
18247 const persistedView = (0, import_data6.useSelect)(
18248 (select2) => {
18249 return select2(import_preferences.store).get(
18250 "core/views",
18251 preferenceKey
18252 );
18253 },
18254 [preferenceKey]
18255 );
18256 const { set: set2 } = (0, import_data6.useDispatch)(import_preferences.store);
18257 const baseView = (0, import_element59.useMemo)(
18258 () => persistedView ?? defaultView2 ?? {},
18259 [persistedView, defaultView2]
18260 );
18261 const page = Number(queryParams?.page ?? baseView.page ?? 1);
18262 const search = queryParams?.search ?? baseView.search ?? "";
18263 const combinedOverrides = (0, import_element59.useMemo)(() => {
18264 const rawDefaults = config.defaultLayouts?.[baseView.type];
18265 const layoutTypeDefaults = !rawDefaults || rawDefaults === true ? {} : rawDefaults;
18266 return { ...layoutTypeDefaults, ...activeViewOverrides };
18267 }, [config.defaultLayouts, baseView.type, activeViewOverrides]);
18268 const view = (0, import_element59.useMemo)(() => {
18269 return mergeActiveViewOverrides(
18270 {
18271 ...baseView,
18272 page,
18273 search
18274 },
18275 combinedOverrides,
18276 defaultView2
18277 );
18278 }, [baseView, page, search, combinedOverrides, defaultView2]);
18279 const isModified = !!persistedView;
18280 const updateView = (0, import_element59.useCallback)(
18281 (newView) => {
18282 const urlParams = {
18283 page: newView?.page,
18284 search: newView?.search
18285 };
18286 const preferenceView = stripActiveViewOverrides(
18287 omit3(newView, ["page", "search"]),
18288 combinedOverrides,
18289 defaultView2
18290 );
18291 if (onChangeQueryParams && !dequal(urlParams, { page, search })) {
18292 onChangeQueryParams(urlParams);
18293 }
18294 const comparableBaseView = stripActiveViewOverrides(
18295 baseView,
18296 combinedOverrides,
18297 defaultView2
18298 );
18299 const comparableDefaultView = stripActiveViewOverrides(
18300 defaultView2,
18301 combinedOverrides,
18302 defaultView2
18303 );
18304 if (!dequal(comparableBaseView, preferenceView)) {
18305 if (dequal(preferenceView, comparableDefaultView)) {
18306 set2("core/views", preferenceKey, void 0);
18307 } else {
18308 set2("core/views", preferenceKey, preferenceView);
18309 }
18310 }
18311 },
18312 [
18313 onChangeQueryParams,
18314 page,
18315 search,
18316 baseView,
18317 defaultView2,
18318 combinedOverrides,
18319 set2,
18320 preferenceKey
18321 ]
18322 );
18323 const resetToDefault = (0, import_element59.useCallback)(() => {
18324 set2("core/views", preferenceKey, void 0);
18325 }, [preferenceKey, set2]);
18326 return {
18327 view,
18328 isModified,
18329 updateView,
18330 resetToDefault
18331 };
18332 }
18333
18334 // packages/views/build-module/load-view.mjs
18335 var import_data7 = __toESM(require_data(), 1);
18336 var import_preferences2 = __toESM(require_preferences(), 1);
18337
18338 // packages/views/build-module/use-view-config.mjs
18339 var import_data8 = __toESM(require_data(), 1);
18340 var import_core_data = __toESM(require_core_data(), 1);
18341
18342 // packages/views/build-module/lock-unlock.mjs
18343 var import_private_apis2 = __toESM(require_private_apis(), 1);
18344 var { lock: lock2, unlock: unlock2 } = (0, import_private_apis2.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
18345 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
18346 "@wordpress/views"
18347 );
18348
18349 // packages/media-fields/build-module/alt_text/index.mjs
18350 var import_i18n49 = __toESM(require_i18n(), 1);
18351 var import_components45 = __toESM(require_components(), 1);
18352 var import_jsx_runtime100 = __toESM(require_jsx_runtime(), 1);
18353 var altTextField = {
18354 id: "alt_text",
18355 type: "text",
18356 label: (0, import_i18n49.__)("Alt text"),
18357 isVisible: (item) => item?.media_type === "image",
18358 render: ({ item }) => item?.alt_text || "-",
18359 Edit: ({ field, onChange, data }) => {
18360 return /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(
18361 import_components45.TextareaControl,
18362 {
18363 label: field.label,
18364 value: data.alt_text || "",
18365 onChange: (value) => onChange({ alt_text: value }),
18366 rows: 2
18367 }
18368 );
18369 },
18370 enableSorting: false,
18371 filterBy: false
18372 };
18373 var alt_text_default = altTextField;
18374
18375 // packages/media-fields/build-module/attached_to/index.mjs
18376 var import_i18n52 = __toESM(require_i18n(), 1);
18377
18378 // packages/media-fields/build-module/attached_to/view.mjs
18379 var import_element60 = __toESM(require_element(), 1);
18380 var import_i18n50 = __toESM(require_i18n(), 1);
18381
18382 // packages/media-fields/build-module/utils/get-rendered-content.mjs
18383 function getRenderedContent(content) {
18384 if (!content) {
18385 return "";
18386 }
18387 if (typeof content === "string") {
18388 return content;
18389 }
18390 if (typeof content === "object") {
18391 return content.rendered || content.raw || "";
18392 }
18393 return "";
18394 }
18395
18396 // packages/media-fields/build-module/attached_to/view.mjs
18397 var import_jsx_runtime101 = __toESM(require_jsx_runtime(), 1);
18398 function MediaAttachedToView({
18399 item
18400 }) {
18401 const [attachedPostTitle, setAttachedPostTitle] = (0, import_element60.useState)(null);
18402 const parentId = item.post;
18403 const embeddedPostId = item._embedded?.["wp:attached-to"]?.[0]?.id;
18404 const embeddedPostTitle = item._embedded?.["wp:attached-to"]?.[0]?.title;
18405 (0, import_element60.useEffect)(() => {
18406 if (!!parentId && parentId === embeddedPostId) {
18407 setAttachedPostTitle(
18408 getRenderedContent(embeddedPostTitle) || (0, import_i18n50.__)("(no title)")
18409 );
18410 }
18411 if (!parentId) {
18412 setAttachedPostTitle((0, import_i18n50.__)("(Unattached)"));
18413 }
18414 }, [parentId, embeddedPostId, embeddedPostTitle]);
18415 return /* @__PURE__ */ (0, import_jsx_runtime101.jsx)(import_jsx_runtime101.Fragment, { children: attachedPostTitle });
18416 }
18417
18418 // packages/media-fields/build-module/attached_to/edit.mjs
18419 var import_core_data2 = __toESM(require_core_data(), 1);
18420 var import_components46 = __toESM(require_components(), 1);
18421 var import_i18n51 = __toESM(require_i18n(), 1);
18422 var import_element61 = __toESM(require_element(), 1);
18423 var import_compose13 = __toESM(require_compose(), 1);
18424 var import_data9 = __toESM(require_data(), 1);
18425 var import_jsx_runtime102 = __toESM(require_jsx_runtime(), 1);
18426 function MediaAttachedToEdit({
18427 data,
18428 onChange
18429 }) {
18430 const defaultPost = !!data.post && !!data?._embedded?.["wp:attached-to"]?.[0] ? [
18431 {
18432 label: getRenderedContent(
18433 data._embedded?.["wp:attached-to"]?.[0]?.title
18434 ),
18435 value: data.post.toString()
18436 }
18437 ] : [];
18438 const [options, setOptions] = (0, import_element61.useState)(defaultPost);
18439 const [searchResults, setSearchResults] = (0, import_element61.useState)(
18440 []
18441 );
18442 const [isLoading, setIsLoading] = (0, import_element61.useState)(false);
18443 const [value, setValue] = (0, import_element61.useState)(
18444 data?.post?.toString() ?? null
18445 );
18446 const postTypes = (0, import_data9.useSelect)(
18447 (select2) => select2(import_core_data2.store).getPostTypes(),
18448 []
18449 );
18450 const handleDetach = () => {
18451 onChange({
18452 post: 0,
18453 _embedded: { ...data?._embedded, "wp:attached-to": void 0 }
18454 });
18455 setOptions([]);
18456 };
18457 const onValueChange = async (filterValue) => {
18458 setIsLoading(true);
18459 const results = await (0, import_core_data2.__experimentalFetchLinkSuggestions)(
18460 filterValue,
18461 /*
18462 * @TODO `fetchLinkSuggestions()` should accept `perPage` as an option argument.
18463 * `isInitialSuggestions` limits the result to 3, otherwise it's hardcoded to 20.
18464 */
18465 { type: "post", isInitialSuggestions: true },
18466 {}
18467 );
18468 setSearchResults(results);
18469 const mappedSuggestions = results.map((result) => {
18470 return {
18471 label: result.title,
18472 value: result.id.toString()
18473 };
18474 });
18475 setOptions(mappedSuggestions);
18476 setIsLoading(false);
18477 };
18478 const handleSelectOption = (selectedPostId) => {
18479 if (!selectedPostId) {
18480 handleDetach();
18481 return;
18482 }
18483 setValue(selectedPostId);
18484 if (selectedPostId) {
18485 const selectedPost = searchResults.find(
18486 (result) => result.id === Number(selectedPostId)
18487 );
18488 if (selectedPost && postTypes) {
18489 const postType = postTypes.find(
18490 (_postType) => _postType.slug === selectedPost?.type
18491 );
18492 const attachedTo = {
18493 ...postType && { type: postType.slug },
18494 id: Number(selectedPostId),
18495 title: {
18496 raw: selectedPost.title,
18497 rendered: selectedPost.title
18498 }
18499 };
18500 onChange({
18501 post: Number(selectedPostId),
18502 _embedded: {
18503 ...data?._embedded,
18504 "wp:attached-to": [attachedTo]
18505 }
18506 });
18507 }
18508 }
18509 };
18510 const help = !!data.post ? (0, import_element61.createInterpolateElement)(
18511 (0, import_i18n51.__)(
18512 "Search for a post or page to attach this media to or <button>detach current</button>."
18513 ),
18514 {
18515 button: /* @__PURE__ */ (0, import_jsx_runtime102.jsx)(
18516 import_components46.Button,
18517 {
18518 __next40pxDefaultSize: true,
18519 onClick: handleDetach,
18520 variant: "link",
18521 accessibleWhenDisabled: true
18522 }
18523 )
18524 }
18525 ) : (0, import_i18n51.__)("Search for a post or page to attach this media to.");
18526 return /* @__PURE__ */ (0, import_jsx_runtime102.jsx)(
18527 import_components46.ComboboxControl,
18528 {
18529 className: "dataviews-media-field__attached-to",
18530 __next40pxDefaultSize: true,
18531 isLoading,
18532 label: (0, import_i18n51.__)("Attached to"),
18533 help,
18534 value,
18535 options,
18536 onFilterValueChange: (0, import_compose13.debounce)(
18537 (filterValue) => onValueChange(filterValue),
18538 300
18539 ),
18540 onChange: handleSelectOption,
18541 hideLabelFromVision: true
18542 }
18543 );
18544 }
18545
18546 // packages/media-fields/build-module/attached_to/index.mjs
18547 var attachedToField = {
18548 id: "attached_to",
18549 type: "text",
18550 label: (0, import_i18n52.__)("Attached to"),
18551 Edit: MediaAttachedToEdit,
18552 render: MediaAttachedToView,
18553 enableSorting: false,
18554 filterBy: false
18555 };
18556 var attached_to_default = attachedToField;
18557
18558 // packages/media-fields/build-module/author/index.mjs
18559 var import_i18n54 = __toESM(require_i18n(), 1);
18560 var import_data10 = __toESM(require_data(), 1);
18561 var import_core_data3 = __toESM(require_core_data(), 1);
18562
18563 // packages/media-fields/build-module/author/view.mjs
18564 var import_i18n53 = __toESM(require_i18n(), 1);
18565 var import_element62 = __toESM(require_element(), 1);
18566 var import_components47 = __toESM(require_components(), 1);
18567 var import_jsx_runtime103 = __toESM(require_jsx_runtime(), 1);
18568 function AuthorView({
18569 item
18570 }) {
18571 const author = item?._embedded?.author?.[0];
18572 const text = author?.name;
18573 const imageUrl = author?.avatar_urls?.[48];
18574 const [loadingState, setLoadingState] = (0, import_element62.useState)("loading");
18575 (0, import_element62.useEffect)(() => {
18576 setLoadingState("loading");
18577 }, [imageUrl]);
18578 const imgRef = (0, import_element62.useCallback)((img) => {
18579 if (img?.complete) {
18580 setLoadingState("instant");
18581 }
18582 }, []);
18583 const handleLoad = () => {
18584 if (loadingState === "loading") {
18585 setLoadingState("loaded");
18586 }
18587 };
18588 return /* @__PURE__ */ (0, import_jsx_runtime103.jsxs)(import_components47.__experimentalHStack, { alignment: "left", spacing: 0, children: [
18589 !!imageUrl && /* @__PURE__ */ (0, import_jsx_runtime103.jsx)(
18590 "div",
18591 {
18592 className: clsx_default("media-author-field__avatar", {
18593 "is-loading": loadingState === "loading",
18594 "is-loaded": loadingState === "loaded"
18595 }),
18596 children: /* @__PURE__ */ (0, import_jsx_runtime103.jsx)(
18597 "img",
18598 {
18599 ref: imgRef,
18600 onLoad: handleLoad,
18601 alt: (0, import_i18n53.__)("Author avatar"),
18602 src: imageUrl
18603 }
18604 )
18605 }
18606 ),
18607 !imageUrl && /* @__PURE__ */ (0, import_jsx_runtime103.jsx)("div", { className: "media-author-field__icon", children: /* @__PURE__ */ (0, import_jsx_runtime103.jsx)(import_components47.Icon, { icon: comment_author_avatar_default }) }),
18608 /* @__PURE__ */ (0, import_jsx_runtime103.jsx)("span", { className: "media-author-field__name", children: text })
18609 ] });
18610 }
18611
18612 // packages/media-fields/build-module/author/index.mjs
18613 var authorField = {
18614 label: (0, import_i18n54.__)("Author"),
18615 id: "author",
18616 type: "integer",
18617 getElements: async () => {
18618 const authors = await (0, import_data10.resolveSelect)(import_core_data3.store).getEntityRecords(
18619 "root",
18620 "user",
18621 {
18622 per_page: -1,
18623 who: "authors",
18624 _fields: "id,name",
18625 context: "view"
18626 }
18627 ) ?? [];
18628 return authors.map(({ id, name }) => ({
18629 value: id,
18630 label: name
18631 }));
18632 },
18633 render: AuthorView,
18634 sort: (a2, b2, direction) => {
18635 const nameA = a2._embedded?.author?.[0]?.name || "";
18636 const nameB = b2._embedded?.author?.[0]?.name || "";
18637 return direction === "asc" ? nameA.localeCompare(nameB) : nameB.localeCompare(nameA);
18638 },
18639 filterBy: {
18640 operators: ["isAny", "isNone"]
18641 },
18642 readOnly: true
18643 };
18644 var author_default = authorField;
18645
18646 // packages/media-fields/build-module/caption/index.mjs
18647 var import_i18n55 = __toESM(require_i18n(), 1);
18648 var import_components48 = __toESM(require_components(), 1);
18649
18650 // packages/media-fields/build-module/utils/get-raw-content.mjs
18651 function getRawContent(content) {
18652 if (!content) {
18653 return "";
18654 }
18655 if (typeof content === "string") {
18656 return content;
18657 }
18658 if (typeof content === "object" && "raw" in content) {
18659 return content.raw || "";
18660 }
18661 return "";
18662 }
18663
18664 // packages/media-fields/build-module/caption/index.mjs
18665 var import_jsx_runtime104 = __toESM(require_jsx_runtime(), 1);
18666 var captionField = {
18667 id: "caption",
18668 type: "text",
18669 label: (0, import_i18n55.__)("Caption"),
18670 getValue: ({ item }) => getRawContent(item?.caption),
18671 render: ({ item }) => getRawContent(item?.caption) || "-",
18672 Edit: ({ field, onChange, data }) => {
18673 return /* @__PURE__ */ (0, import_jsx_runtime104.jsx)(
18674 import_components48.TextareaControl,
18675 {
18676 label: field.label,
18677 value: getRawContent(data.caption) || "",
18678 onChange: (value) => onChange({ caption: value }),
18679 rows: 2
18680 }
18681 );
18682 },
18683 enableSorting: false,
18684 filterBy: false
18685 };
18686 var caption_default = captionField;
18687
18688 // packages/media-fields/build-module/date_added/index.mjs
18689 var import_i18n56 = __toESM(require_i18n(), 1);
18690 var import_date10 = __toESM(require_date(), 1);
18691 var dateAddedField = {
18692 id: "date",
18693 type: "datetime",
18694 label: (0, import_i18n56.__)("Date added"),
18695 filterBy: {
18696 operators: ["before", "after"]
18697 },
18698 format: {
18699 datetime: (0, import_date10.getSettings)().formats.datetimeAbbreviated
18700 },
18701 readOnly: true
18702 };
18703 var date_added_default = dateAddedField;
18704
18705 // packages/media-fields/build-module/date_modified/index.mjs
18706 var import_i18n57 = __toESM(require_i18n(), 1);
18707 var import_date11 = __toESM(require_date(), 1);
18708 var dateModifiedField = {
18709 id: "modified",
18710 type: "datetime",
18711 label: (0, import_i18n57.__)("Date modified"),
18712 filterBy: {
18713 operators: ["before", "after"]
18714 },
18715 format: {
18716 datetime: (0, import_date11.getSettings)().formats.datetimeAbbreviated
18717 },
18718 readOnly: true
18719 };
18720 var date_modified_default = dateModifiedField;
18721
18722 // packages/media-fields/build-module/description/index.mjs
18723 var import_i18n58 = __toESM(require_i18n(), 1);
18724 var import_components49 = __toESM(require_components(), 1);
18725 var import_jsx_runtime105 = __toESM(require_jsx_runtime(), 1);
18726 var descriptionField = {
18727 id: "description",
18728 type: "text",
18729 label: (0, import_i18n58.__)("Description"),
18730 getValue: ({ item }) => getRawContent(item?.description),
18731 render: ({ item }) => /* @__PURE__ */ (0, import_jsx_runtime105.jsx)("div", { children: getRawContent(item?.description) || "-" }),
18732 Edit: ({ field, onChange, data }) => {
18733 return /* @__PURE__ */ (0, import_jsx_runtime105.jsx)(
18734 import_components49.TextareaControl,
18735 {
18736 label: field.label,
18737 value: getRawContent(data.description) || "",
18738 onChange: (value) => onChange({ description: value }),
18739 rows: 5
18740 }
18741 );
18742 },
18743 enableSorting: false,
18744 filterBy: false
18745 };
18746 var description_default = descriptionField;
18747
18748 // packages/media-fields/build-module/filename/index.mjs
18749 var import_i18n59 = __toESM(require_i18n(), 1);
18750 var import_url4 = __toESM(require_url(), 1);
18751
18752 // packages/media-fields/build-module/filename/view.mjs
18753 var import_components50 = __toESM(require_components(), 1);
18754 var import_element63 = __toESM(require_element(), 1);
18755 var import_url3 = __toESM(require_url(), 1);
18756 var import_jsx_runtime106 = __toESM(require_jsx_runtime(), 1);
18757 var TRUNCATE_LENGTH = 15;
18758 function FileNameView({
18759 item
18760 }) {
18761 const fileName = (0, import_element63.useMemo)(
18762 () => item?.source_url ? (0, import_url3.getFilename)(item.source_url) : null,
18763 [item?.source_url]
18764 );
18765 if (!fileName) {
18766 return "";
18767 }
18768 return fileName.length > TRUNCATE_LENGTH ? /* @__PURE__ */ (0, import_jsx_runtime106.jsx)(import_components50.Tooltip, { text: fileName, children: /* @__PURE__ */ (0, import_jsx_runtime106.jsx)(import_components50.__experimentalTruncate, { limit: TRUNCATE_LENGTH, ellipsizeMode: "tail", children: fileName }) }) : /* @__PURE__ */ (0, import_jsx_runtime106.jsx)(import_jsx_runtime106.Fragment, { children: fileName });
18769 }
18770
18771 // packages/media-fields/build-module/filename/index.mjs
18772 var filenameField = {
18773 id: "filename",
18774 type: "text",
18775 label: (0, import_i18n59.__)("File name"),
18776 getValue: ({ item }) => (0, import_url4.getFilename)(item?.source_url || ""),
18777 render: FileNameView,
18778 enableSorting: false,
18779 filterBy: false,
18780 readOnly: true
18781 };
18782 var filename_default = filenameField;
18783
18784 // packages/media-fields/build-module/filesize/index.mjs
18785 var import_i18n60 = __toESM(require_i18n(), 1);
18786 var KB_IN_BYTES = 1024;
18787 var MB_IN_BYTES = 1024 * KB_IN_BYTES;
18788 var GB_IN_BYTES = 1024 * MB_IN_BYTES;
18789 var TB_IN_BYTES = 1024 * GB_IN_BYTES;
18790 var PB_IN_BYTES = 1024 * TB_IN_BYTES;
18791 var EB_IN_BYTES = 1024 * PB_IN_BYTES;
18792 var ZB_IN_BYTES = 1024 * EB_IN_BYTES;
18793 var YB_IN_BYTES = 1024 * ZB_IN_BYTES;
18794 function getBytesString(bytes, unitSymbol, decimals = 2) {
18795 return (0, import_i18n60.sprintf)(
18796 // translators: 1: Actual bytes of a file. 2: The unit symbol (e.g. MB).
18797 (0, import_i18n60._x)("%1$s %2$s", "file size"),
18798 bytes.toLocaleString(void 0, {
18799 minimumFractionDigits: 0,
18800 maximumFractionDigits: decimals
18801 }),
18802 unitSymbol
18803 );
18804 }
18805 function formatFileSize(bytes, decimals = 2) {
18806 if (bytes === 0) {
18807 return getBytesString(0, (0, import_i18n60._x)("B", "unit symbol"), decimals);
18808 }
18809 const quant = {
18810 /* translators: Unit symbol for yottabyte. */
18811 [(0, import_i18n60._x)("YB", "unit symbol")]: YB_IN_BYTES,
18812 /* translators: Unit symbol for zettabyte. */
18813 [(0, import_i18n60._x)("ZB", "unit symbol")]: ZB_IN_BYTES,
18814 /* translators: Unit symbol for exabyte. */
18815 [(0, import_i18n60._x)("EB", "unit symbol")]: EB_IN_BYTES,
18816 /* translators: Unit symbol for petabyte. */
18817 [(0, import_i18n60._x)("PB", "unit symbol")]: PB_IN_BYTES,
18818 /* translators: Unit symbol for terabyte. */
18819 [(0, import_i18n60._x)("TB", "unit symbol")]: TB_IN_BYTES,
18820 /* translators: Unit symbol for gigabyte. */
18821 [(0, import_i18n60._x)("GB", "unit symbol")]: GB_IN_BYTES,
18822 /* translators: Unit symbol for megabyte. */
18823 [(0, import_i18n60._x)("MB", "unit symbol")]: MB_IN_BYTES,
18824 /* translators: Unit symbol for kilobyte. */
18825 [(0, import_i18n60._x)("KB", "unit symbol")]: KB_IN_BYTES,
18826 /* translators: Unit symbol for byte. */
18827 [(0, import_i18n60._x)("B", "unit symbol")]: 1
18828 };
18829 for (const [unit, mag] of Object.entries(quant)) {
18830 if (bytes >= mag) {
18831 return getBytesString(bytes / mag, unit, decimals);
18832 }
18833 }
18834 return "";
18835 }
18836 var filesizeField = {
18837 id: "filesize",
18838 type: "text",
18839 label: (0, import_i18n60.__)("File size"),
18840 getValue: ({ item }) => item?.media_details?.filesize ? formatFileSize(item?.media_details?.filesize) : "",
18841 isVisible: (item) => {
18842 return !!item?.media_details?.filesize;
18843 },
18844 enableSorting: false,
18845 filterBy: false,
18846 readOnly: true
18847 };
18848 var filesize_default = filesizeField;
18849
18850 // packages/media-fields/build-module/media_dimensions/index.mjs
18851 var import_i18n61 = __toESM(require_i18n(), 1);
18852 var mediaDimensionsField = {
18853 id: "media_dimensions",
18854 type: "text",
18855 label: (0, import_i18n61.__)("Dimensions"),
18856 getValue: ({ item }) => item?.media_details?.width && item?.media_details?.height ? (0, import_i18n61.sprintf)(
18857 // translators: 1: Width. 2: Height.
18858 (0, import_i18n61._x)("%1$s \xD7 %2$s", "image dimensions"),
18859 item?.media_details?.width?.toString(),
18860 item?.media_details?.height?.toString()
18861 ) : "",
18862 isVisible: (item) => {
18863 return !!(item?.media_details?.width && item?.media_details?.height);
18864 },
18865 enableSorting: false,
18866 filterBy: false,
18867 readOnly: true
18868 };
18869 var media_dimensions_default = mediaDimensionsField;
18870
18871 // packages/media-fields/build-module/media_thumbnail/index.mjs
18872 var import_i18n63 = __toESM(require_i18n(), 1);
18873
18874 // packages/media-fields/build-module/media_thumbnail/view.mjs
18875 var import_data11 = __toESM(require_data(), 1);
18876 var import_core_data4 = __toESM(require_core_data(), 1);
18877 var import_components51 = __toESM(require_components(), 1);
18878 var import_element64 = __toESM(require_element(), 1);
18879 var import_url5 = __toESM(require_url(), 1);
18880
18881 // packages/media-fields/build-module/utils/get-media-type-from-mime-type.mjs
18882 var import_i18n62 = __toESM(require_i18n(), 1);
18883 function getMediaTypeFromMimeType(mimeType) {
18884 if (mimeType.startsWith("image/")) {
18885 return {
18886 type: "image",
18887 label: (0, import_i18n62.__)("Image"),
18888 icon: image_default
18889 };
18890 }
18891 if (mimeType.startsWith("video/")) {
18892 return {
18893 type: "video",
18894 label: (0, import_i18n62.__)("Video"),
18895 icon: video_default
18896 };
18897 }
18898 if (mimeType.startsWith("audio/")) {
18899 return {
18900 type: "audio",
18901 label: (0, import_i18n62.__)("Audio"),
18902 icon: audio_default
18903 };
18904 }
18905 return {
18906 type: "application",
18907 label: (0, import_i18n62.__)("Application"),
18908 icon: file_default
18909 };
18910 }
18911
18912 // packages/media-fields/build-module/media_thumbnail/view.mjs
18913 var import_jsx_runtime107 = __toESM(require_jsx_runtime(), 1);
18914 function getBestImageUrl(featuredMedia, configSizes) {
18915 const sizes = featuredMedia?.media_details?.sizes;
18916 if (!sizes) {
18917 return featuredMedia.source_url;
18918 }
18919 const sizeEntries = Object.values(sizes);
18920 if (!sizeEntries.length) {
18921 return featuredMedia.source_url;
18922 }
18923 const targetWidth = configSizes ? parseInt(configSizes, 10) : NaN;
18924 if (!Number.isNaN(targetWidth)) {
18925 const validEntries = sizeEntries.filter(
18926 (s2) => typeof s2.width === "number" && !Number.isNaN(s2.width)
18927 );
18928 if (!validEntries.length) {
18929 return featuredMedia.source_url;
18930 }
18931 const sorted = [...validEntries].sort(
18932 (a2, b2) => a2.width - b2.width
18933 );
18934 const match2 = sorted.find((s2) => s2.width >= targetWidth);
18935 if (match2) {
18936 return match2.source_url;
18937 }
18938 return sorted[sorted.length - 1].source_url;
18939 }
18940 return featuredMedia.source_url;
18941 }
18942 function FallbackView({
18943 item,
18944 filename
18945 }) {
18946 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)("div", { className: "dataviews-media-field__media-thumbnail", children: /* @__PURE__ */ (0, import_jsx_runtime107.jsxs)(
18947 import_components51.__experimentalVStack,
18948 {
18949 justify: "center",
18950 alignment: "center",
18951 className: "dataviews-media-field__media-thumbnail__stack",
18952 spacing: 0,
18953 children: [
18954 /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
18955 import_components51.Icon,
18956 {
18957 className: "dataviews-media-field__media-thumbnail--icon",
18958 icon: getMediaTypeFromMimeType(item.mime_type).icon,
18959 size: 24
18960 }
18961 ),
18962 !!filename && /* @__PURE__ */ (0, import_jsx_runtime107.jsx)("div", { className: "dataviews-media-field__media-thumbnail__filename", children: /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(import_components51.__experimentalTruncate, { className: "dataviews-media-field__media-thumbnail__filename__truncate", children: filename }) })
18963 ]
18964 }
18965 ) });
18966 }
18967 function ImageView({
18968 item,
18969 configSizes,
18970 onError
18971 }) {
18972 const imageUrl = getBestImageUrl(item, configSizes);
18973 const imgRef = (0, import_element64.useRef)(null);
18974 const [loadingState, setLoadingState] = (0, import_element64.useState)("loading");
18975 (0, import_element64.useLayoutEffect)(() => {
18976 if (imgRef.current?.complete) {
18977 setLoadingState("instant");
18978 } else {
18979 setLoadingState("loading");
18980 }
18981 }, [imageUrl]);
18982 const handleLoad = () => {
18983 if (loadingState === "loading") {
18984 setLoadingState("loaded");
18985 }
18986 };
18987 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
18988 "div",
18989 {
18990 className: clsx_default("dataviews-media-field__media-thumbnail", {
18991 "is-loading": loadingState === "loading",
18992 "is-loaded": loadingState === "loaded"
18993 }),
18994 children: /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
18995 "img",
18996 {
18997 ref: imgRef,
18998 className: "dataviews-media-field__media-thumbnail--image",
18999 src: imageUrl,
19000 alt: item.alt_text || item.title.raw,
19001 onLoad: handleLoad,
19002 onError,
19003 loading: "lazy"
19004 }
19005 )
19006 }
19007 );
19008 }
19009 function MediaThumbnailView({
19010 item,
19011 config
19012 }) {
19013 const [imageError, setImageError] = (0, import_element64.useState)(false);
19014 const _featuredMedia = (0, import_data11.useSelect)(
19015 (select2) => {
19016 if (!item.featured_media) {
19017 return;
19018 }
19019 return select2(import_core_data4.store).getEntityRecord(
19020 "postType",
19021 "attachment",
19022 item.featured_media
19023 );
19024 },
19025 [item.featured_media]
19026 );
19027 const featuredMedia = item.featured_media ? _featuredMedia : item;
19028 if (!featuredMedia) {
19029 return null;
19030 }
19031 const filename = (0, import_url5.getFilename)(featuredMedia.source_url || "");
19032 if (imageError || getMediaTypeFromMimeType(featuredMedia.mime_type).type !== "image") {
19033 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(FallbackView, { item: featuredMedia, filename: filename || "" });
19034 }
19035 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
19036 ImageView,
19037 {
19038 item: featuredMedia,
19039 configSizes: config?.sizes,
19040 onError: () => setImageError(true)
19041 }
19042 );
19043 }
19044
19045 // packages/media-fields/build-module/media_thumbnail/index.mjs
19046 var mediaThumbnailField = {
19047 id: "media_thumbnail",
19048 type: "media",
19049 label: (0, import_i18n63.__)("Thumbnail"),
19050 render: MediaThumbnailView,
19051 enableSorting: false,
19052 filterBy: false
19053 };
19054 var media_thumbnail_default = mediaThumbnailField;
19055
19056 // packages/media-fields/build-module/mime_type/index.mjs
19057 var import_i18n64 = __toESM(require_i18n(), 1);
19058 var mimeTypeField = {
19059 id: "mime_type",
19060 type: "text",
19061 label: (0, import_i18n64.__)("File type"),
19062 getValue: ({ item }) => item?.mime_type || "",
19063 render: ({ item }) => item?.mime_type || "-",
19064 // Disable sorting until REST API support for ordering my `mime_type` is added.
19065 // See: https://core.trac.wordpress.org/ticket/64073
19066 enableSorting: false,
19067 filterBy: false,
19068 readOnly: true
19069 };
19070 var mime_type_default = mimeTypeField;
19071
19072 // packages/media-utils/build-module/components/media-upload-modal/index.mjs
19073 var import_notices = __toESM(require_notices(), 1);
19074
19075 // packages/media-utils/build-module/lock-unlock.mjs
19076 var import_private_apis3 = __toESM(require_private_apis(), 1);
19077 var { lock: lock3, unlock: unlock3 } = (0, import_private_apis3.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
19078 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
19079 "@wordpress/media-utils"
19080 );
19081
19082 // packages/media-utils/build-module/components/media-upload-modal/upload-status-popover.mjs
19083 var import_element65 = __toESM(require_element(), 1);
19084 var import_i18n65 = __toESM(require_i18n(), 1);
19085 var import_components52 = __toESM(require_components(), 1);
19086 var import_jsx_runtime108 = __toESM(require_jsx_runtime(), 1);
19087 function UploadStatusPopover({
19088 uploadingFiles,
19089 onDismissError,
19090 onOpenChange
19091 }) {
19092 const [isOpen, setIsOpen] = (0, import_element65.useState)(false);
19093 const [prevHadErrors, setPrevHadErrors] = (0, import_element65.useState)(false);
19094 const triggerRef = (0, import_element65.useRef)(null);
19095 const updateIsOpen = (0, import_element65.useCallback)(
19096 (open) => {
19097 setIsOpen(open);
19098 onOpenChange?.(open);
19099 },
19100 [onOpenChange]
19101 );
19102 const activeFiles = uploadingFiles.filter(
19103 (file) => file.status === "uploading"
19104 );
19105 const errorFiles = uploadingFiles.filter(
19106 (file) => file.status === "error"
19107 );
19108 const hasErrors = errorFiles.length > 0;
19109 const isUploading = activeFiles.length > 0;
19110 (0, import_element65.useEffect)(() => {
19111 if (hasErrors && !prevHadErrors) {
19112 updateIsOpen(true);
19113 }
19114 setPrevHadErrors(hasErrors);
19115 }, [hasErrors, prevHadErrors, updateIsOpen]);
19116 if (uploadingFiles.length === 0) {
19117 return null;
19118 }
19119 let buttonLabel, popoverHeading;
19120 if (isUploading) {
19121 buttonLabel = (0, import_i18n65.sprintf)(
19122 // translators: %s: number of files being uploaded
19123 (0, import_i18n65._n)("Uploading %s file", "Uploading %s files", activeFiles.length),
19124 activeFiles.length.toLocaleString()
19125 );
19126 popoverHeading = (0, import_i18n65.__)("Uploading");
19127 } else if (hasErrors) {
19128 buttonLabel = (0, import_i18n65.sprintf)(
19129 // translators: %s: number of upload errors
19130 (0, import_i18n65._n)("%s upload error", "%s upload errors", errorFiles.length),
19131 errorFiles.length.toLocaleString()
19132 );
19133 popoverHeading = (0, import_i18n65.__)("Upload errors");
19134 } else {
19135 buttonLabel = (0, import_i18n65.__)("Upload complete");
19136 popoverHeading = (0, import_i18n65.__)("Upload complete");
19137 }
19138 return /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)("div", { className: "media-upload-modal__upload-status", children: [
19139 isUploading && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(import_components52.Spinner, {}),
19140 /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(
19141 import_components52.Button,
19142 {
19143 className: "media-upload-modal__upload-status__trigger",
19144 size: "compact",
19145 icon: chevron_down_default,
19146 iconPosition: "right",
19147 onClick: () => updateIsOpen(!isOpen),
19148 "aria-expanded": isOpen,
19149 ref: triggerRef,
19150 children: buttonLabel
19151 }
19152 ),
19153 isOpen && /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)(
19154 import_components52.Popover,
19155 {
19156 className: "media-upload-modal__upload-status__popover",
19157 placement: "top-start",
19158 offset: 8,
19159 anchor: triggerRef.current,
19160 focusOnMount: true,
19161 onClose: () => {
19162 if (triggerRef.current?.contains(
19163 triggerRef.current.ownerDocument.activeElement
19164 )) {
19165 return;
19166 }
19167 updateIsOpen(false);
19168 },
19169 children: [
19170 /* @__PURE__ */ (0, import_jsx_runtime108.jsx)("div", { className: "media-upload-modal__upload-status__header", children: /* @__PURE__ */ (0, import_jsx_runtime108.jsx)("h3", { children: popoverHeading }) }),
19171 /* @__PURE__ */ (0, import_jsx_runtime108.jsx)("ul", { className: "media-upload-modal__upload-status__list", children: uploadingFiles.map((file) => /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)(
19172 "li",
19173 {
19174 className: "media-upload-modal__upload-status__item",
19175 children: [
19176 file.status === "uploading" && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(import_components52.Spinner, {}),
19177 file.status === "uploaded" && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(import_components52.Icon, { icon: check_default, size: 16 }),
19178 (file.status === "uploading" || file.status === "uploaded") && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(
19179 "span",
19180 {
19181 className: "media-upload-modal__upload-status__filename",
19182 title: file.name,
19183 children: file.name
19184 }
19185 ),
19186 file.status === "error" && /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)(
19187 import_components52.Notice,
19188 {
19189 status: "error",
19190 isDismissible: !!onDismissError,
19191 onRemove: () => onDismissError?.(file.id),
19192 children: [
19193 file.name,
19194 ": ",
19195 file.error
19196 ]
19197 }
19198 )
19199 ]
19200 },
19201 file.id
19202 )) })
19203 ]
19204 }
19205 )
19206 ] });
19207 }
19208
19209 // packages/media-utils/build-module/components/media-upload-modal/use-invalidate-attachment-resolutions.mjs
19210 var import_element66 = __toESM(require_element(), 1);
19211 var import_core_data5 = __toESM(require_core_data(), 1);
19212 var import_data12 = __toESM(require_data(), 1);
19213 function useInvalidateAttachmentResolutions() {
19214 const registry = (0, import_data12.useRegistry)();
19215 return (0, import_element66.useCallback)(() => {
19216 const resolvers = registry.select(import_core_data5.store).getCachedResolvers();
19217 const entityRecordResolutions = resolvers.getEntityRecords;
19218 entityRecordResolutions?.forEach((_value, args) => {
19219 if (args[0] === "postType" && args[1] === "attachment") {
19220 registry.dispatch(import_core_data5.store).invalidateResolution("getEntityRecords", args);
19221 }
19222 });
19223 }, [registry]);
19224 }
19225
19226 // packages/media-utils/build-module/components/media-upload-modal/use-upload-status.mjs
19227 var import_element67 = __toESM(require_element(), 1);
19228 var import_blob2 = __toESM(require_blob(), 1);
19229 var idCounter = 0;
19230 var batchIdCounter = 0;
19231 function useUploadStatus({
19232 onBatchComplete
19233 } = {}) {
19234 const [uploadingFiles, setUploadingFiles] = (0, import_element67.useState)(
19235 []
19236 );
19237 const clearCompleted = (0, import_element67.useCallback)(() => {
19238 setUploadingFiles(
19239 (prev) => prev.filter((item) => item.status !== "uploaded")
19240 );
19241 }, []);
19242 const dismissError = (0, import_element67.useCallback)((fileId) => {
19243 setUploadingFiles(
19244 (prev) => prev.filter((item) => item.id !== fileId)
19245 );
19246 }, []);
19247 const registerBatch = (0, import_element67.useCallback)(
19248 (files) => {
19249 const batchId = String(++batchIdCounter);
19250 const batchSize = files.length;
19251 const newEntries = files.map((file) => ({
19252 id: String(++idCounter),
19253 batchId,
19254 name: file.name,
19255 status: "uploading"
19256 }));
19257 setUploadingFiles((prev) => [...prev, ...newEntries]);
19258 let successCount = 0;
19259 let errorCount = 0;
19260 let batchDone = false;
19261 let successAttachments = [];
19262 const completeBatchIfDone = () => {
19263 if (batchDone || successCount + errorCount < batchSize) {
19264 return;
19265 }
19266 batchDone = true;
19267 setUploadingFiles(
19268 (prev) => prev.map(
19269 (item) => item.batchId === batchId && item.status === "uploading" ? {
19270 ...item,
19271 status: "uploaded"
19272 } : item
19273 )
19274 );
19275 onBatchComplete?.(successAttachments);
19276 };
19277 const onFileChange = (attachments) => {
19278 if (batchDone) {
19279 return;
19280 }
19281 const allReal = attachments.every(
19282 (attachment) => attachment.id && attachment.url && !(0, import_blob2.isBlobURL)(attachment.url)
19283 );
19284 if (!allReal) {
19285 return;
19286 }
19287 successCount = attachments.length;
19288 successAttachments = attachments;
19289 completeBatchIfDone();
19290 };
19291 const onError = (error) => {
19292 const fileName = error instanceof UploadError ? error.file.name : void 0;
19293 setUploadingFiles((prev) => {
19294 let matched = false;
19295 return prev.map((item) => {
19296 if (!matched && item.batchId === batchId && item.status === "uploading" && (!fileName || item.name === fileName)) {
19297 matched = true;
19298 return {
19299 ...item,
19300 status: "error",
19301 error: error.message
19302 };
19303 }
19304 return item;
19305 });
19306 });
19307 errorCount++;
19308 completeBatchIfDone();
19309 };
19310 return { onFileChange, onError };
19311 },
19312 [onBatchComplete]
19313 );
19314 const allComplete = uploadingFiles.length > 0 && uploadingFiles.every((item) => item.status !== "uploading");
19315 return {
19316 uploadingFiles,
19317 registerBatch,
19318 dismissError,
19319 clearCompleted,
19320 allComplete
19321 };
19322 }
19323
19324 // packages/media-utils/build-module/components/media-upload-modal/index.mjs
19325 var import_jsx_runtime109 = __toESM(require_jsx_runtime(), 1);
19326 var { useEntityRecordsWithPermissions } = unlock3(import_core_data6.privateApis);
19327 var LAYOUT_PICKER_GRID2 = "pickerGrid";
19328 var LAYOUT_PICKER_TABLE2 = "pickerTable";
19329 var NOTICES_CONTEXT = "media-modal";
19330 var NOTICE_ID_UPLOAD_PROGRESS = "media-modal-upload-progress";
19331 var defaultQueryParams = {
19332 page: 1,
19333 search: ""
19334 };
19335 var defaultView = {
19336 type: LAYOUT_PICKER_GRID2,
19337 fields: [],
19338 showTitle: false,
19339 titleField: "title",
19340 mediaField: "media_thumbnail",
19341 perPage: 50,
19342 filters: [],
19343 layout: {
19344 previewSize: 170,
19345 density: "compact"
19346 }
19347 };
19348 var defaultLayouts = {
19349 [LAYOUT_PICKER_GRID2]: {
19350 fields: [],
19351 showTitle: false,
19352 layout: {
19353 previewSize: 170,
19354 density: "compact"
19355 }
19356 },
19357 [LAYOUT_PICKER_TABLE2]: {
19358 fields: [
19359 "filename",
19360 "filesize",
19361 "media_dimensions",
19362 "author",
19363 "date"
19364 ],
19365 showTitle: true
19366 }
19367 };
19368 function MediaUploadModal({
19369 allowedTypes,
19370 multiple = false,
19371 value,
19372 onSelect,
19373 onClose,
19374 onUpload,
19375 title = (0, import_i18n66.__)("Select Media"),
19376 isOpen,
19377 isDismissible = true,
19378 modalClass,
19379 search = true,
19380 searchLabel = (0, import_i18n66.__)("Search media")
19381 }) {
19382 const [selection, setSelection] = (0, import_element68.useState)(() => {
19383 if (!value) {
19384 return [];
19385 }
19386 return Array.isArray(value) ? value.map(String) : [String(value)];
19387 });
19388 const { createSuccessNotice, removeAllNotices } = (0, import_data13.useDispatch)(import_notices.store);
19389 const invalidateAttachmentResolutions = useInvalidateAttachmentResolutions();
19390 const [queryParams, setQueryParams] = (0, import_element68.useState)(
19391 () => defaultQueryParams
19392 );
19393 const { view, updateView, isModified, resetToDefault } = useView({
19394 kind: "postType",
19395 name: "attachment",
19396 slug: "media-modal",
19397 defaultView,
19398 queryParams,
19399 onChangeQueryParams: setQueryParams
19400 });
19401 const handleChangeView = (0, import_element68.useCallback)(
19402 (nextView) => {
19403 const normalizedView = { ...nextView };
19404 if (normalizedView.startPosition === void 0) {
19405 delete normalizedView.startPosition;
19406 }
19407 updateView(normalizedView);
19408 },
19409 [updateView]
19410 );
19411 const queryArgs = (0, import_element68.useMemo)(() => {
19412 const filters = {};
19413 view.filters?.forEach((filter) => {
19414 if (filter.field === "media_type") {
19415 filters.media_type = filter.value;
19416 }
19417 if (filter.field === "author") {
19418 if (filter.operator === "isAny") {
19419 filters.author = filter.value;
19420 } else if (filter.operator === "isNone") {
19421 filters.author_exclude = filter.value;
19422 }
19423 }
19424 if (filter.field === "date" || filter.field === "modified") {
19425 if (filter.operator === "before") {
19426 filters.before = filter.value;
19427 } else if (filter.operator === "after") {
19428 filters.after = filter.value;
19429 }
19430 }
19431 if (filter.field === "mime_type") {
19432 filters.mime_type = filter.value;
19433 }
19434 });
19435 if (!filters.media_type && !filters.mime_type && allowedTypes && !allowedTypes.includes("*")) {
19436 const { mediaTypes, mimeTypes } = allowedTypes.reduce(
19437 (acc, type) => {
19438 if (type.endsWith("/*")) {
19439 acc.mediaTypes.push(type.replace("/*", ""));
19440 } else if (type.includes("/")) {
19441 acc.mimeTypes.push(type);
19442 } else {
19443 acc.mediaTypes.push(type);
19444 }
19445 return acc;
19446 },
19447 { mediaTypes: [], mimeTypes: [] }
19448 );
19449 if (mediaTypes.length) {
19450 filters.media_type = mediaTypes;
19451 }
19452 if (mimeTypes.length) {
19453 filters.mime_type = mimeTypes;
19454 }
19455 }
19456 return {
19457 per_page: view.perPage || 20,
19458 page: view.page || 1,
19459 status: "inherit",
19460 order: view.sort?.direction,
19461 orderby: view.sort?.field,
19462 search: view.search,
19463 _embed: "author,wp:attached-to",
19464 ...filters
19465 };
19466 }, [view, allowedTypes]);
19467 const handleBatchComplete = (0, import_element68.useCallback)(
19468 (attachments) => {
19469 const uploadedIds = attachments.map((attachment) => String(attachment.id)).filter(Boolean);
19470 if (multiple) {
19471 setSelection((prev) => {
19472 const existing = new Set(prev);
19473 const newIds = uploadedIds.filter(
19474 (id) => !existing.has(id)
19475 );
19476 return [...prev, ...newIds];
19477 });
19478 } else {
19479 setSelection(uploadedIds.slice(0, 1));
19480 }
19481 invalidateAttachmentResolutions();
19482 },
19483 [multiple, invalidateAttachmentResolutions]
19484 );
19485 const {
19486 uploadingFiles,
19487 registerBatch,
19488 dismissError,
19489 clearCompleted,
19490 allComplete
19491 } = useUploadStatus({ onBatchComplete: handleBatchComplete });
19492 const isPopoverOpenRef = (0, import_element68.useRef)(false);
19493 const handlePopoverOpenChange = (0, import_element68.useCallback)(
19494 (open) => {
19495 isPopoverOpenRef.current = open;
19496 if (!open) {
19497 clearCompleted();
19498 }
19499 },
19500 [clearCompleted]
19501 );
19502 const {
19503 records: mediaRecords,
19504 isResolving: isLoading,
19505 totalItems,
19506 totalPages
19507 } = useEntityRecordsWithPermissions("postType", "attachment", queryArgs);
19508 const fields = (0, import_element68.useMemo)(
19509 () => [
19510 // Media field definitions from @wordpress/media-fields
19511 // Cast is safe because RestAttachment has the same properties as Attachment
19512 {
19513 ...media_thumbnail_default,
19514 enableHiding: false
19515 // Within the modal, the thumbnail should always be shown.
19516 },
19517 {
19518 id: "title",
19519 type: "text",
19520 label: (0, import_i18n66.__)("Title"),
19521 getValue: ({ item }) => {
19522 const titleValue = item.title.raw || item.title.rendered;
19523 return titleValue || (0, import_i18n66.__)("(no title)");
19524 }
19525 },
19526 alt_text_default,
19527 caption_default,
19528 description_default,
19529 date_added_default,
19530 date_modified_default,
19531 author_default,
19532 filename_default,
19533 filesize_default,
19534 media_dimensions_default,
19535 mime_type_default,
19536 attached_to_default
19537 ],
19538 []
19539 );
19540 const actions = (0, import_element68.useMemo)(
19541 () => [
19542 {
19543 id: "select",
19544 label: (0, import_i18n66.__)("Select"),
19545 isPrimary: true,
19546 supportsBulk: multiple,
19547 async callback() {
19548 if (selection.length === 0) {
19549 return;
19550 }
19551 const selectedPostsQuery = {
19552 include: selection,
19553 per_page: -1
19554 };
19555 const selectedPosts = await (0, import_data13.resolveSelect)(
19556 import_core_data6.store
19557 ).getEntityRecords(
19558 "postType",
19559 "attachment",
19560 selectedPostsQuery
19561 );
19562 const transformedPosts = (selectedPosts ?? []).map(transformAttachment).filter(Boolean);
19563 const selectedItems = multiple ? transformedPosts : transformedPosts?.[0];
19564 removeAllNotices("snackbar", NOTICES_CONTEXT);
19565 onSelect(selectedItems);
19566 }
19567 }
19568 ],
19569 [multiple, onSelect, selection, removeAllNotices]
19570 );
19571 const handleModalClose = (0, import_element68.useCallback)(() => {
19572 removeAllNotices("snackbar", NOTICES_CONTEXT);
19573 onClose?.();
19574 }, [removeAllNotices, onClose]);
19575 (0, import_element68.useEffect)(() => {
19576 if (!isOpen) {
19577 setQueryParams(defaultQueryParams);
19578 }
19579 }, [isOpen]);
19580 const handleUpload = onUpload || uploadMedia;
19581 const prevAllCompleteRef = (0, import_element68.useRef)(false);
19582 (0, import_element68.useEffect)(() => {
19583 if (allComplete && !prevAllCompleteRef.current) {
19584 const completeCount = uploadingFiles.filter(
19585 (file) => file.status === "uploaded"
19586 ).length;
19587 if (completeCount > 0) {
19588 createSuccessNotice(
19589 (0, import_i18n66.sprintf)(
19590 // translators: %s: number of files
19591 (0, import_i18n66._n)(
19592 "Uploaded %s file",
19593 "Uploaded %s files",
19594 completeCount
19595 ),
19596 completeCount.toLocaleString()
19597 ),
19598 {
19599 type: "snackbar",
19600 context: NOTICES_CONTEXT,
19601 id: NOTICE_ID_UPLOAD_PROGRESS
19602 }
19603 );
19604 }
19605 if (!isPopoverOpenRef.current) {
19606 clearCompleted();
19607 }
19608 }
19609 prevAllCompleteRef.current = allComplete;
19610 }, [allComplete, uploadingFiles, createSuccessNotice, clearCompleted]);
19611 const handleFileSelect = (0, import_element68.useCallback)(
19612 (event) => {
19613 const files = event.target.files;
19614 if (files && files.length > 0) {
19615 const filesArray = Array.from(files);
19616 const { onFileChange, onError } = registerBatch(filesArray);
19617 handleUpload({
19618 allowedTypes,
19619 filesList: filesArray,
19620 onFileChange,
19621 onError
19622 });
19623 }
19624 },
19625 [allowedTypes, handleUpload, registerBatch]
19626 );
19627 const paginationInfo = (0, import_element68.useMemo)(
19628 () => ({
19629 totalItems,
19630 totalPages
19631 }),
19632 [totalItems, totalPages]
19633 );
19634 const acceptTypes = (0, import_element68.useMemo)(() => {
19635 if (allowedTypes?.includes("*")) {
19636 return void 0;
19637 }
19638 return allowedTypes?.join(",");
19639 }, [allowedTypes]);
19640 if (!isOpen) {
19641 return null;
19642 }
19643 return /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19644 import_components53.Modal,
19645 {
19646 title,
19647 onRequestClose: handleModalClose,
19648 isDismissible,
19649 className: modalClass,
19650 overlayClassName: "media-upload-modal",
19651 size: "fill",
19652 headerActions: /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19653 import_components53.FormFileUpload,
19654 {
19655 accept: acceptTypes,
19656 multiple: true,
19657 onChange: handleFileSelect,
19658 __next40pxDefaultSize: true,
19659 render: ({ openFileDialog }) => /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19660 import_components53.Button,
19661 {
19662 onClick: openFileDialog,
19663 icon: upload_default,
19664 __next40pxDefaultSize: true,
19665 children: (0, import_i18n66.__)("Upload media")
19666 }
19667 )
19668 }
19669 ),
19670 children: [
19671 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19672 import_components53.DropZone,
19673 {
19674 onFilesDrop: (files) => {
19675 let filteredFiles = files;
19676 if (allowedTypes && !allowedTypes.includes("*")) {
19677 filteredFiles = files.filter(
19678 (file) => allowedTypes.some((allowedType) => {
19679 return file.type === allowedType || file.type.startsWith(
19680 allowedType.replace("*", "")
19681 );
19682 })
19683 );
19684 }
19685 if (filteredFiles.length > 0) {
19686 const { onFileChange, onError } = registerBatch(filteredFiles);
19687 handleUpload({
19688 allowedTypes,
19689 filesList: filteredFiles,
19690 onFileChange,
19691 onError
19692 });
19693 }
19694 },
19695 label: (0, import_i18n66.__)("Drop files to upload")
19696 }
19697 ),
19698 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19699 dataviews_picker_default,
19700 {
19701 data: mediaRecords || [],
19702 fields,
19703 view,
19704 onChangeView: handleChangeView,
19705 actions,
19706 selection,
19707 onChangeSelection: setSelection,
19708 isLoading,
19709 paginationInfo,
19710 defaultLayouts,
19711 getItemId: (item) => String(item.id),
19712 itemListLabel: (0, import_i18n66.__)("Media items"),
19713 onReset: isModified ? resetToDefault : false,
19714 children: [
19715 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19716 Stack,
19717 {
19718 direction: "row",
19719 align: "top",
19720 justify: "space-between",
19721 className: "dataviews__view-actions",
19722 gap: "xs",
19723 children: [
19724 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19725 Stack,
19726 {
19727 direction: "row",
19728 gap: "sm",
19729 justify: "start",
19730 className: "dataviews__search",
19731 children: [
19732 search && /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.Search, { label: searchLabel }),
19733 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.FiltersToggle, {})
19734 ]
19735 }
19736 ),
19737 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(Stack, { direction: "row", gap: "xs", style: { flexShrink: 0 }, children: [
19738 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.LayoutSwitcher, {}),
19739 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.ViewConfig, {})
19740 ] })
19741 ]
19742 }
19743 ),
19744 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.FiltersToggled, { className: "dataviews-filters__container" }),
19745 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.Layout, {}),
19746 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19747 "div",
19748 {
19749 className: clsx_default("media-upload-modal__footer", {
19750 "is-uploading": uploadingFiles.length > 0
19751 }),
19752 children: [
19753 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19754 UploadStatusPopover,
19755 {
19756 uploadingFiles,
19757 onDismissError: dismissError,
19758 onOpenChange: handlePopoverOpenChange
19759 }
19760 ),
19761 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.BulkActionToolbar, {})
19762 ]
19763 }
19764 )
19765 ]
19766 }
19767 ),
19768 (0, import_element68.createPortal)(
19769 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19770 import_notices.SnackbarNotices,
19771 {
19772 className: "media-upload-modal__snackbar",
19773 context: NOTICES_CONTEXT
19774 }
19775 ),
19776 document.body
19777 )
19778 ]
19779 }
19780 );
19781 }
19782
19783 // packages/media-utils/build-module/private-apis.mjs
19784 var privateApis12 = {};
19785 lock3(privateApis12, {
19786 sideloadMedia,
19787 MediaUploadModal
19788 });
19789 return __toCommonJS(index_exports);
19790 })();
19791 /*! Bundled license information:
19792
19793 use-sync-external-store/cjs/use-sync-external-store-shim.development.js:
19794 (**
19795 * @license React
19796 * use-sync-external-store-shim.development.js
19797 *
19798 * Copyright (c) Meta Platforms, Inc. and affiliates.
19799 *
19800 * This source code is licensed under the MIT license found in the
19801 * LICENSE file in the root directory of this source tree.
19802 *)
19803 */
19804 //# sourceMappingURL=index.js.map
19805