PluginProbe
Gutenberg / 23.0.1
Gutenberg v23.0.1
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.0.1, at build/scripts/media-utils/index.js

19,597 lines 691.8 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 transformAttachment(
1480 await (0, import_api_fetch2.default)({
1481 path: `/wp/v2/media/${attachmentId}/sideload`,
1482 body: data,
1483 method: "POST",
1484 signal
1485 })
1486 );
1487 }
1488
1489 // packages/media-utils/build-module/utils/sideload-media.mjs
1490 var noop = () => {
1491 };
1492 async function sideloadMedia({
1493 file,
1494 attachmentId,
1495 additionalData = {},
1496 signal,
1497 onFileChange,
1498 onError = noop
1499 }) {
1500 try {
1501 const attachment = await sideloadToServer(
1502 file,
1503 attachmentId,
1504 additionalData,
1505 signal
1506 );
1507 onFileChange?.([attachment]);
1508 } catch (error) {
1509 let message2;
1510 if (error instanceof Error) {
1511 message2 = error.message;
1512 } else {
1513 message2 = (0, import_i18n6.sprintf)(
1514 // translators: %s: file name
1515 (0, import_i18n6.__)("Error while sideloading file %s to the server."),
1516 file.name
1517 );
1518 }
1519 onError(
1520 new UploadError({
1521 code: "GENERAL",
1522 message: message2,
1523 file,
1524 cause: error instanceof Error ? error : void 0
1525 })
1526 );
1527 }
1528 }
1529
1530 // node_modules/clsx/dist/clsx.mjs
1531 function r(e2) {
1532 var t2, f2, n2 = "";
1533 if ("string" == typeof e2 || "number" == typeof e2) n2 += e2;
1534 else if ("object" == typeof e2) if (Array.isArray(e2)) {
1535 var o2 = e2.length;
1536 for (t2 = 0; t2 < o2; t2++) e2[t2] && (f2 = r(e2[t2])) && (n2 && (n2 += " "), n2 += f2);
1537 } else for (f2 in e2) e2[f2] && (n2 && (n2 += " "), n2 += f2);
1538 return n2;
1539 }
1540 function clsx() {
1541 for (var e2, t2, f2 = 0, n2 = "", o2 = arguments.length; f2 < o2; f2++) (e2 = arguments[f2]) && (t2 = r(e2)) && (n2 && (n2 += " "), n2 += t2);
1542 return n2;
1543 }
1544 var clsx_default = clsx;
1545
1546 // packages/media-utils/build-module/components/media-upload-modal/index.mjs
1547 var import_element67 = __toESM(require_element(), 1);
1548 var import_i18n66 = __toESM(require_i18n(), 1);
1549 var import_core_data6 = __toESM(require_core_data(), 1);
1550 var import_data13 = __toESM(require_data(), 1);
1551 var import_components54 = __toESM(require_components(), 1);
1552
1553 // packages/icons/build-module/library/arrow-down.mjs
1554 var import_primitives = __toESM(require_primitives(), 1);
1555 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
1556 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" }) });
1557
1558 // packages/icons/build-module/library/arrow-left.mjs
1559 var import_primitives2 = __toESM(require_primitives(), 1);
1560 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
1561 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" }) });
1562
1563 // packages/icons/build-module/library/arrow-right.mjs
1564 var import_primitives3 = __toESM(require_primitives(), 1);
1565 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
1566 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" }) });
1567
1568 // packages/icons/build-module/library/arrow-up.mjs
1569 var import_primitives4 = __toESM(require_primitives(), 1);
1570 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
1571 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" }) });
1572
1573 // packages/icons/build-module/library/audio.mjs
1574 var import_primitives5 = __toESM(require_primitives(), 1);
1575 var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
1576 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" }) });
1577
1578 // packages/icons/build-module/library/block-table.mjs
1579 var import_primitives6 = __toESM(require_primitives(), 1);
1580 var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
1581 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" }) });
1582
1583 // packages/icons/build-module/library/category.mjs
1584 var import_primitives7 = __toESM(require_primitives(), 1);
1585 var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
1586 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" }) });
1587
1588 // packages/icons/build-module/library/check.mjs
1589 var import_primitives8 = __toESM(require_primitives(), 1);
1590 var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
1591 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" }) });
1592
1593 // packages/icons/build-module/library/chevron-down.mjs
1594 var import_primitives9 = __toESM(require_primitives(), 1);
1595 var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
1596 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" }) });
1597
1598 // packages/icons/build-module/library/close-small.mjs
1599 var import_primitives10 = __toESM(require_primitives(), 1);
1600 var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1);
1601 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" }) });
1602
1603 // packages/icons/build-module/library/cog.mjs
1604 var import_primitives11 = __toESM(require_primitives(), 1);
1605 var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1);
1606 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" }) });
1607
1608 // packages/icons/build-module/library/comment-author-avatar.mjs
1609 var import_primitives12 = __toESM(require_primitives(), 1);
1610 var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1);
1611 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" }) });
1612
1613 // packages/icons/build-module/library/envelope.mjs
1614 var import_primitives13 = __toESM(require_primitives(), 1);
1615 var import_jsx_runtime13 = __toESM(require_jsx_runtime(), 1);
1616 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" }) });
1617
1618 // packages/icons/build-module/library/error.mjs
1619 var import_primitives14 = __toESM(require_primitives(), 1);
1620 var import_jsx_runtime14 = __toESM(require_jsx_runtime(), 1);
1621 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" }) });
1622
1623 // packages/icons/build-module/library/file.mjs
1624 var import_primitives15 = __toESM(require_primitives(), 1);
1625 var import_jsx_runtime15 = __toESM(require_jsx_runtime(), 1);
1626 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" }) });
1627
1628 // packages/icons/build-module/library/format-list-bullets-rtl.mjs
1629 var import_primitives16 = __toESM(require_primitives(), 1);
1630 var import_jsx_runtime16 = __toESM(require_jsx_runtime(), 1);
1631 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" }) });
1632
1633 // packages/icons/build-module/library/format-list-bullets.mjs
1634 var import_primitives17 = __toESM(require_primitives(), 1);
1635 var import_jsx_runtime17 = __toESM(require_jsx_runtime(), 1);
1636 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" }) });
1637
1638 // packages/icons/build-module/library/funnel.mjs
1639 var import_primitives18 = __toESM(require_primitives(), 1);
1640 var import_jsx_runtime18 = __toESM(require_jsx_runtime(), 1);
1641 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" }) });
1642
1643 // packages/icons/build-module/library/image.mjs
1644 var import_primitives19 = __toESM(require_primitives(), 1);
1645 var import_jsx_runtime19 = __toESM(require_jsx_runtime(), 1);
1646 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" }) });
1647
1648 // packages/icons/build-module/library/link.mjs
1649 var import_primitives20 = __toESM(require_primitives(), 1);
1650 var import_jsx_runtime20 = __toESM(require_jsx_runtime(), 1);
1651 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" }) });
1652
1653 // packages/icons/build-module/library/mobile.mjs
1654 var import_primitives21 = __toESM(require_primitives(), 1);
1655 var import_jsx_runtime21 = __toESM(require_jsx_runtime(), 1);
1656 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" }) });
1657
1658 // packages/icons/build-module/library/more-vertical.mjs
1659 var import_primitives22 = __toESM(require_primitives(), 1);
1660 var import_jsx_runtime22 = __toESM(require_jsx_runtime(), 1);
1661 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" }) });
1662
1663 // packages/icons/build-module/library/next.mjs
1664 var import_primitives23 = __toESM(require_primitives(), 1);
1665 var import_jsx_runtime23 = __toESM(require_jsx_runtime(), 1);
1666 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" }) });
1667
1668 // packages/icons/build-module/library/previous.mjs
1669 var import_primitives24 = __toESM(require_primitives(), 1);
1670 var import_jsx_runtime24 = __toESM(require_jsx_runtime(), 1);
1671 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" }) });
1672
1673 // packages/icons/build-module/library/scheduled.mjs
1674 var import_primitives25 = __toESM(require_primitives(), 1);
1675 var import_jsx_runtime25 = __toESM(require_jsx_runtime(), 1);
1676 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" }) });
1677
1678 // packages/icons/build-module/library/search.mjs
1679 var import_primitives26 = __toESM(require_primitives(), 1);
1680 var import_jsx_runtime26 = __toESM(require_jsx_runtime(), 1);
1681 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" }) });
1682
1683 // packages/icons/build-module/library/seen.mjs
1684 var import_primitives27 = __toESM(require_primitives(), 1);
1685 var import_jsx_runtime27 = __toESM(require_jsx_runtime(), 1);
1686 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" }) });
1687
1688 // packages/icons/build-module/library/unseen.mjs
1689 var import_primitives28 = __toESM(require_primitives(), 1);
1690 var import_jsx_runtime28 = __toESM(require_jsx_runtime(), 1);
1691 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" }) });
1692
1693 // packages/icons/build-module/library/upload.mjs
1694 var import_primitives29 = __toESM(require_primitives(), 1);
1695 var import_jsx_runtime29 = __toESM(require_jsx_runtime(), 1);
1696 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" }) });
1697
1698 // packages/icons/build-module/library/video.mjs
1699 var import_primitives30 = __toESM(require_primitives(), 1);
1700 var import_jsx_runtime30 = __toESM(require_jsx_runtime(), 1);
1701 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" }) });
1702
1703 // node_modules/@base-ui/utils/esm/useRefWithInit.js
1704 var React = __toESM(require_react(), 1);
1705 var UNINITIALIZED = {};
1706 function useRefWithInit(init2, initArg) {
1707 const ref = React.useRef(UNINITIALIZED);
1708 if (ref.current === UNINITIALIZED) {
1709 ref.current = init2(initArg);
1710 }
1711 return ref;
1712 }
1713
1714 // node_modules/@base-ui/utils/esm/warn.js
1715 var set;
1716 if (true) {
1717 set = /* @__PURE__ */ new Set();
1718 }
1719 function warn(...messages) {
1720 if (true) {
1721 const messageKey = messages.join(" ");
1722 if (!set.has(messageKey)) {
1723 set.add(messageKey);
1724 console.warn(`Base UI: ${messageKey}`);
1725 }
1726 }
1727 }
1728
1729 // node_modules/@base-ui/react/esm/utils/useRenderElement.js
1730 var React4 = __toESM(require_react(), 1);
1731
1732 // node_modules/@base-ui/utils/esm/useMergedRefs.js
1733 function useMergedRefs(a2, b2, c2, d2) {
1734 const forkRef = useRefWithInit(createForkRef).current;
1735 if (didChange(forkRef, a2, b2, c2, d2)) {
1736 update(forkRef, [a2, b2, c2, d2]);
1737 }
1738 return forkRef.callback;
1739 }
1740 function useMergedRefsN(refs) {
1741 const forkRef = useRefWithInit(createForkRef).current;
1742 if (didChangeN(forkRef, refs)) {
1743 update(forkRef, refs);
1744 }
1745 return forkRef.callback;
1746 }
1747 function createForkRef() {
1748 return {
1749 callback: null,
1750 cleanup: null,
1751 refs: []
1752 };
1753 }
1754 function didChange(forkRef, a2, b2, c2, d2) {
1755 return forkRef.refs[0] !== a2 || forkRef.refs[1] !== b2 || forkRef.refs[2] !== c2 || forkRef.refs[3] !== d2;
1756 }
1757 function didChangeN(forkRef, newRefs) {
1758 return forkRef.refs.length !== newRefs.length || forkRef.refs.some((ref, index) => ref !== newRefs[index]);
1759 }
1760 function update(forkRef, refs) {
1761 forkRef.refs = refs;
1762 if (refs.every((ref) => ref == null)) {
1763 forkRef.callback = null;
1764 return;
1765 }
1766 forkRef.callback = (instance) => {
1767 if (forkRef.cleanup) {
1768 forkRef.cleanup();
1769 forkRef.cleanup = null;
1770 }
1771 if (instance != null) {
1772 const cleanupCallbacks = Array(refs.length).fill(null);
1773 for (let i2 = 0; i2 < refs.length; i2 += 1) {
1774 const ref = refs[i2];
1775 if (ref == null) {
1776 continue;
1777 }
1778 switch (typeof ref) {
1779 case "function": {
1780 const refCleanup = ref(instance);
1781 if (typeof refCleanup === "function") {
1782 cleanupCallbacks[i2] = refCleanup;
1783 }
1784 break;
1785 }
1786 case "object": {
1787 ref.current = instance;
1788 break;
1789 }
1790 default:
1791 }
1792 }
1793 forkRef.cleanup = () => {
1794 for (let i2 = 0; i2 < refs.length; i2 += 1) {
1795 const ref = refs[i2];
1796 if (ref == null) {
1797 continue;
1798 }
1799 switch (typeof ref) {
1800 case "function": {
1801 const cleanupCallback = cleanupCallbacks[i2];
1802 if (typeof cleanupCallback === "function") {
1803 cleanupCallback();
1804 } else {
1805 ref(null);
1806 }
1807 break;
1808 }
1809 case "object": {
1810 ref.current = null;
1811 break;
1812 }
1813 default:
1814 }
1815 }
1816 };
1817 }
1818 };
1819 }
1820
1821 // node_modules/@base-ui/utils/esm/getReactElementRef.js
1822 var React3 = __toESM(require_react(), 1);
1823
1824 // node_modules/@base-ui/utils/esm/reactVersion.js
1825 var React2 = __toESM(require_react(), 1);
1826 var majorVersion = parseInt(React2.version, 10);
1827 function isReactVersionAtLeast(reactVersionToCheck) {
1828 return majorVersion >= reactVersionToCheck;
1829 }
1830
1831 // node_modules/@base-ui/utils/esm/getReactElementRef.js
1832 function getReactElementRef(element) {
1833 if (!/* @__PURE__ */ React3.isValidElement(element)) {
1834 return null;
1835 }
1836 const reactElement = element;
1837 const propsWithRef = reactElement.props;
1838 return (isReactVersionAtLeast(19) ? propsWithRef?.ref : reactElement.ref) ?? null;
1839 }
1840
1841 // node_modules/@base-ui/utils/esm/mergeObjects.js
1842 function mergeObjects(a2, b2) {
1843 if (a2 && !b2) {
1844 return a2;
1845 }
1846 if (!a2 && b2) {
1847 return b2;
1848 }
1849 if (a2 || b2) {
1850 return {
1851 ...a2,
1852 ...b2
1853 };
1854 }
1855 return void 0;
1856 }
1857
1858 // node_modules/@base-ui/react/esm/utils/getStateAttributesProps.js
1859 function getStateAttributesProps(state, customMapping) {
1860 const props = {};
1861 for (const key in state) {
1862 const value = state[key];
1863 if (customMapping?.hasOwnProperty(key)) {
1864 const customProps = customMapping[key](value);
1865 if (customProps != null) {
1866 Object.assign(props, customProps);
1867 }
1868 continue;
1869 }
1870 if (value === true) {
1871 props[`data-${key.toLowerCase()}`] = "";
1872 } else if (value) {
1873 props[`data-${key.toLowerCase()}`] = value.toString();
1874 }
1875 }
1876 return props;
1877 }
1878
1879 // node_modules/@base-ui/react/esm/utils/resolveClassName.js
1880 function resolveClassName(className, state) {
1881 return typeof className === "function" ? className(state) : className;
1882 }
1883
1884 // node_modules/@base-ui/react/esm/utils/resolveStyle.js
1885 function resolveStyle(style, state) {
1886 return typeof style === "function" ? style(state) : style;
1887 }
1888
1889 // node_modules/@base-ui/react/esm/merge-props/mergeProps.js
1890 var EMPTY_PROPS = {};
1891 function mergeProps(a2, b2, c2, d2, e2) {
1892 if (!c2 && !d2 && !e2 && !a2) {
1893 return createInitialMergedProps(b2);
1894 }
1895 let merged = createInitialMergedProps(a2);
1896 if (b2) {
1897 merged = mergeInto(merged, b2);
1898 }
1899 if (c2) {
1900 merged = mergeInto(merged, c2);
1901 }
1902 if (d2) {
1903 merged = mergeInto(merged, d2);
1904 }
1905 if (e2) {
1906 merged = mergeInto(merged, e2);
1907 }
1908 return merged;
1909 }
1910 function mergePropsN(props) {
1911 if (props.length === 0) {
1912 return EMPTY_PROPS;
1913 }
1914 if (props.length === 1) {
1915 return createInitialMergedProps(props[0]);
1916 }
1917 let merged = createInitialMergedProps(props[0]);
1918 for (let i2 = 1; i2 < props.length; i2 += 1) {
1919 merged = mergeInto(merged, props[i2]);
1920 }
1921 return merged;
1922 }
1923 function createInitialMergedProps(inputProps) {
1924 if (isPropsGetter(inputProps)) {
1925 return {
1926 ...resolvePropsGetter(inputProps, EMPTY_PROPS)
1927 };
1928 }
1929 return copyInitialProps(inputProps);
1930 }
1931 function mergeInto(merged, inputProps) {
1932 if (isPropsGetter(inputProps)) {
1933 return resolvePropsGetter(inputProps, merged);
1934 }
1935 return mutablyMergeInto(merged, inputProps);
1936 }
1937 function copyInitialProps(inputProps) {
1938 const copiedProps = {
1939 ...inputProps
1940 };
1941 for (const propName in copiedProps) {
1942 const propValue = copiedProps[propName];
1943 if (isEventHandler(propName, propValue)) {
1944 copiedProps[propName] = wrapEventHandler(propValue);
1945 }
1946 }
1947 return copiedProps;
1948 }
1949 function mutablyMergeInto(mergedProps, externalProps) {
1950 if (!externalProps) {
1951 return mergedProps;
1952 }
1953 for (const propName in externalProps) {
1954 const externalPropValue = externalProps[propName];
1955 switch (propName) {
1956 case "style": {
1957 mergedProps[propName] = mergeObjects(mergedProps.style, externalPropValue);
1958 break;
1959 }
1960 case "className": {
1961 mergedProps[propName] = mergeClassNames(mergedProps.className, externalPropValue);
1962 break;
1963 }
1964 default: {
1965 if (isEventHandler(propName, externalPropValue)) {
1966 mergedProps[propName] = mergeEventHandlers(mergedProps[propName], externalPropValue);
1967 } else {
1968 mergedProps[propName] = externalPropValue;
1969 }
1970 }
1971 }
1972 }
1973 return mergedProps;
1974 }
1975 function isEventHandler(key, value) {
1976 const code0 = key.charCodeAt(0);
1977 const code1 = key.charCodeAt(1);
1978 const code2 = key.charCodeAt(2);
1979 return code0 === 111 && code1 === 110 && code2 >= 65 && code2 <= 90 && (typeof value === "function" || typeof value === "undefined");
1980 }
1981 function isPropsGetter(inputProps) {
1982 return typeof inputProps === "function";
1983 }
1984 function resolvePropsGetter(inputProps, previousProps) {
1985 if (isPropsGetter(inputProps)) {
1986 return inputProps(previousProps);
1987 }
1988 return inputProps ?? EMPTY_PROPS;
1989 }
1990 function mergeEventHandlers(ourHandler, theirHandler) {
1991 if (!theirHandler) {
1992 return ourHandler;
1993 }
1994 if (!ourHandler) {
1995 return wrapEventHandler(theirHandler);
1996 }
1997 return (event) => {
1998 if (isSyntheticEvent(event)) {
1999 const baseUIEvent = event;
2000 makeEventPreventable(baseUIEvent);
2001 const result2 = theirHandler(baseUIEvent);
2002 if (!baseUIEvent.baseUIHandlerPrevented) {
2003 ourHandler?.(baseUIEvent);
2004 }
2005 return result2;
2006 }
2007 const result = theirHandler(event);
2008 ourHandler?.(event);
2009 return result;
2010 };
2011 }
2012 function wrapEventHandler(handler) {
2013 if (!handler) {
2014 return handler;
2015 }
2016 return (event) => {
2017 if (isSyntheticEvent(event)) {
2018 makeEventPreventable(event);
2019 }
2020 return handler(event);
2021 };
2022 }
2023 function makeEventPreventable(event) {
2024 event.preventBaseUIHandler = () => {
2025 event.baseUIHandlerPrevented = true;
2026 };
2027 return event;
2028 }
2029 function mergeClassNames(ourClassName, theirClassName) {
2030 if (theirClassName) {
2031 if (ourClassName) {
2032 return theirClassName + " " + ourClassName;
2033 }
2034 return theirClassName;
2035 }
2036 return ourClassName;
2037 }
2038 function isSyntheticEvent(event) {
2039 return event != null && typeof event === "object" && "nativeEvent" in event;
2040 }
2041
2042 // node_modules/@base-ui/utils/esm/empty.js
2043 var EMPTY_ARRAY = Object.freeze([]);
2044 var EMPTY_OBJECT = Object.freeze({});
2045
2046 // node_modules/@base-ui/react/esm/utils/constants.js
2047 var BASE_UI_SWIPE_IGNORE_ATTRIBUTE = "data-base-ui-swipe-ignore";
2048 var LEGACY_SWIPE_IGNORE_ATTRIBUTE = "data-swipe-ignore";
2049 var BASE_UI_SWIPE_IGNORE_SELECTOR = `[${BASE_UI_SWIPE_IGNORE_ATTRIBUTE}]`;
2050 var LEGACY_SWIPE_IGNORE_SELECTOR = `[${LEGACY_SWIPE_IGNORE_ATTRIBUTE}]`;
2051
2052 // node_modules/@base-ui/react/esm/utils/useRenderElement.js
2053 var import_react = __toESM(require_react(), 1);
2054 function useRenderElement(element, componentProps, params = {}) {
2055 const renderProp = componentProps.render;
2056 const outProps = useRenderElementProps(componentProps, params);
2057 if (params.enabled === false) {
2058 return null;
2059 }
2060 const state = params.state ?? EMPTY_OBJECT;
2061 return evaluateRenderProp(element, renderProp, outProps, state);
2062 }
2063 function useRenderElementProps(componentProps, params = {}) {
2064 const {
2065 className: classNameProp,
2066 style: styleProp,
2067 render: renderProp
2068 } = componentProps;
2069 const {
2070 state = EMPTY_OBJECT,
2071 ref,
2072 props,
2073 stateAttributesMapping,
2074 enabled = true
2075 } = params;
2076 const className = enabled ? resolveClassName(classNameProp, state) : void 0;
2077 const style = enabled ? resolveStyle(styleProp, state) : void 0;
2078 const stateProps = enabled ? getStateAttributesProps(state, stateAttributesMapping) : EMPTY_OBJECT;
2079 const resolvedProps = enabled && props ? resolveRenderFunctionProps(props) : void 0;
2080 const outProps = enabled ? mergeObjects(stateProps, resolvedProps) ?? {} : EMPTY_OBJECT;
2081 if (typeof document !== "undefined") {
2082 if (!enabled) {
2083 useMergedRefs(null, null);
2084 } else if (Array.isArray(ref)) {
2085 outProps.ref = useMergedRefsN([outProps.ref, getReactElementRef(renderProp), ...ref]);
2086 } else {
2087 outProps.ref = useMergedRefs(outProps.ref, getReactElementRef(renderProp), ref);
2088 }
2089 }
2090 if (!enabled) {
2091 return EMPTY_OBJECT;
2092 }
2093 if (className !== void 0) {
2094 outProps.className = mergeClassNames(outProps.className, className);
2095 }
2096 if (style !== void 0) {
2097 outProps.style = mergeObjects(outProps.style, style);
2098 }
2099 return outProps;
2100 }
2101 function resolveRenderFunctionProps(props) {
2102 if (Array.isArray(props)) {
2103 return mergePropsN(props);
2104 }
2105 return mergeProps(void 0, props);
2106 }
2107 var REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for("react.lazy");
2108 var COMPONENT_IDENTIFIER_PATTERN = /^[A-Z][A-Za-z0-9$]*$/;
2109 var LOWERCASE_CHARACTER_PATTERN = /[a-z]/;
2110 function evaluateRenderProp(element, render4, props, state) {
2111 if (render4) {
2112 if (typeof render4 === "function") {
2113 if (true) {
2114 warnIfRenderPropLooksLikeComponent(render4);
2115 }
2116 return render4(props, state);
2117 }
2118 const mergedProps = mergeProps(props, render4.props);
2119 mergedProps.ref = props.ref;
2120 let newElement = render4;
2121 if (newElement?.$$typeof === REACT_LAZY_TYPE) {
2122 const children = React4.Children.toArray(render4);
2123 newElement = children[0];
2124 }
2125 if (true) {
2126 if (!/* @__PURE__ */ React4.isValidElement(newElement)) {
2127 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"));
2128 }
2129 }
2130 return /* @__PURE__ */ React4.cloneElement(newElement, mergedProps);
2131 }
2132 if (element) {
2133 if (typeof element === "string") {
2134 return renderTag(element, props);
2135 }
2136 }
2137 throw new Error(true ? "Base UI: Render element or function are not defined." : formatErrorMessage_default(8));
2138 }
2139 function warnIfRenderPropLooksLikeComponent(renderFn) {
2140 const functionName = renderFn.name;
2141 if (functionName.length === 0) {
2142 return;
2143 }
2144 if (!COMPONENT_IDENTIFIER_PATTERN.test(functionName)) {
2145 return;
2146 }
2147 if (!LOWERCASE_CHARACTER_PATTERN.test(functionName)) {
2148 return;
2149 }
2150 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");
2151 }
2152 function renderTag(Tag, props) {
2153 if (Tag === "button") {
2154 return /* @__PURE__ */ (0, import_react.createElement)("button", {
2155 type: "button",
2156 ...props,
2157 key: props.key
2158 });
2159 }
2160 if (Tag === "img") {
2161 return /* @__PURE__ */ (0, import_react.createElement)("img", {
2162 alt: "",
2163 ...props,
2164 key: props.key
2165 });
2166 }
2167 return /* @__PURE__ */ React4.createElement(Tag, props);
2168 }
2169
2170 // node_modules/@base-ui/react/esm/use-render/useRender.js
2171 function useRender(params) {
2172 return useRenderElement(params.defaultTagName ?? "div", params, params);
2173 }
2174
2175 // packages/ui/build-module/stack/stack.mjs
2176 var import_element2 = __toESM(require_element(), 1);
2177 if (typeof document !== "undefined" && true && !document.head.querySelector("style[data-wp-hash='b51ff41489']")) {
2178 const style = document.createElement("style");
2179 style.setAttribute("data-wp-hash", "b51ff41489");
2180 style.appendChild(document.createTextNode("@layer wp-ui-utilities, wp-ui-components, wp-ui-compositions, wp-ui-overrides;@layer wp-ui-components{._19ce0419607e1896__stack{display:flex}}"));
2181 document.head.appendChild(style);
2182 }
2183 var style_default = { "stack": "_19ce0419607e1896__stack" };
2184 var gapTokens = {
2185 xs: "var(--wpds-dimension-gap-xs, 4px)",
2186 sm: "var(--wpds-dimension-gap-sm, 8px)",
2187 md: "var(--wpds-dimension-gap-md, 12px)",
2188 lg: "var(--wpds-dimension-gap-lg, 16px)",
2189 xl: "var(--wpds-dimension-gap-xl, 24px)",
2190 "2xl": "var(--wpds-dimension-gap-2xl, 32px)",
2191 "3xl": "var(--wpds-dimension-gap-3xl, 40px)"
2192 };
2193 var Stack = (0, import_element2.forwardRef)(function Stack2({ direction, gap, align, justify, wrap, render: render4, ...props }, ref) {
2194 const style = {
2195 gap: gap && gapTokens[gap],
2196 alignItems: align,
2197 justifyContent: justify,
2198 flexDirection: direction,
2199 flexWrap: wrap
2200 };
2201 const element = useRender({
2202 render: render4,
2203 ref,
2204 props: mergeProps(props, { style, className: style_default.stack })
2205 });
2206 return element;
2207 });
2208
2209 // packages/dataviews/build-module/components/dataviews-context/index.mjs
2210 var import_element3 = __toESM(require_element(), 1);
2211
2212 // packages/dataviews/build-module/constants.mjs
2213 var import_i18n7 = __toESM(require_i18n(), 1);
2214 var OPERATOR_IS_ANY = "isAny";
2215 var OPERATOR_IS_NONE = "isNone";
2216 var OPERATOR_IS_ALL = "isAll";
2217 var OPERATOR_IS_NOT_ALL = "isNotAll";
2218 var OPERATOR_BETWEEN = "between";
2219 var OPERATOR_IN_THE_PAST = "inThePast";
2220 var OPERATOR_OVER = "over";
2221 var OPERATOR_IS = "is";
2222 var OPERATOR_IS_NOT = "isNot";
2223 var OPERATOR_LESS_THAN = "lessThan";
2224 var OPERATOR_GREATER_THAN = "greaterThan";
2225 var OPERATOR_LESS_THAN_OR_EQUAL = "lessThanOrEqual";
2226 var OPERATOR_GREATER_THAN_OR_EQUAL = "greaterThanOrEqual";
2227 var OPERATOR_BEFORE = "before";
2228 var OPERATOR_AFTER = "after";
2229 var OPERATOR_BEFORE_INC = "beforeInc";
2230 var OPERATOR_AFTER_INC = "afterInc";
2231 var OPERATOR_CONTAINS = "contains";
2232 var OPERATOR_NOT_CONTAINS = "notContains";
2233 var OPERATOR_STARTS_WITH = "startsWith";
2234 var OPERATOR_ON = "on";
2235 var OPERATOR_NOT_ON = "notOn";
2236 var SORTING_DIRECTIONS = ["asc", "desc"];
2237 var sortArrows = { asc: "\u2191", desc: "\u2193" };
2238 var sortValues = { asc: "ascending", desc: "descending" };
2239 var sortLabels = {
2240 asc: (0, import_i18n7.__)("Sort ascending"),
2241 desc: (0, import_i18n7.__)("Sort descending")
2242 };
2243 var sortIcons = {
2244 asc: arrow_up_default,
2245 desc: arrow_down_default
2246 };
2247 var LAYOUT_TABLE = "table";
2248 var LAYOUT_GRID = "grid";
2249 var LAYOUT_LIST = "list";
2250 var LAYOUT_ACTIVITY = "activity";
2251 var LAYOUT_PICKER_GRID = "pickerGrid";
2252 var LAYOUT_PICKER_TABLE = "pickerTable";
2253
2254 // packages/dataviews/build-module/components/dataviews-context/index.mjs
2255 var DataViewsContext = (0, import_element3.createContext)({
2256 view: { type: LAYOUT_TABLE },
2257 onChangeView: () => {
2258 },
2259 fields: [],
2260 data: [],
2261 paginationInfo: {
2262 totalItems: 0,
2263 totalPages: 0
2264 },
2265 selection: [],
2266 onChangeSelection: () => {
2267 },
2268 setOpenedFilter: () => {
2269 },
2270 openedFilter: null,
2271 getItemId: (item) => item.id,
2272 isItemClickable: () => true,
2273 renderItemLink: void 0,
2274 containerWidth: 0,
2275 containerRef: (0, import_element3.createRef)(),
2276 resizeObserverRef: () => {
2277 },
2278 defaultLayouts: { list: {}, grid: {}, table: {} },
2279 filters: [],
2280 isShowingFilter: false,
2281 setIsShowingFilter: () => {
2282 },
2283 hasInitiallyLoaded: false,
2284 config: {
2285 perPageSizes: []
2286 },
2287 intersectionObserver: null
2288 });
2289 DataViewsContext.displayName = "DataViewsContext";
2290 var dataviews_context_default = DataViewsContext;
2291
2292 // packages/dataviews/build-module/components/dataviews-layouts/index.mjs
2293 var import_i18n27 = __toESM(require_i18n(), 1);
2294
2295 // packages/dataviews/build-module/components/dataviews-layouts/table/index.mjs
2296 var import_i18n15 = __toESM(require_i18n(), 1);
2297 var import_components6 = __toESM(require_components(), 1);
2298 var import_element11 = __toESM(require_element(), 1);
2299 var import_keycodes = __toESM(require_keycodes(), 1);
2300
2301 // packages/dataviews/build-module/components/dataviews-selection-checkbox/index.mjs
2302 var import_components = __toESM(require_components(), 1);
2303 var import_i18n8 = __toESM(require_i18n(), 1);
2304 var import_jsx_runtime31 = __toESM(require_jsx_runtime(), 1);
2305 function DataViewsSelectionCheckbox({
2306 selection,
2307 onChangeSelection,
2308 item,
2309 getItemId,
2310 titleField,
2311 disabled,
2312 ...extraProps
2313 }) {
2314 const id = getItemId(item);
2315 const isInSelectionArray = selection.includes(id);
2316 const checked = !disabled && isInSelectionArray;
2317 const selectionLabel = titleField?.getValue?.({ item }) || (0, import_i18n8.__)("(no title)");
2318 return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2319 import_components.CheckboxControl,
2320 {
2321 className: "dataviews-selection-checkbox",
2322 "aria-label": selectionLabel,
2323 "aria-disabled": disabled,
2324 checked,
2325 onChange: () => {
2326 if (disabled) {
2327 return;
2328 }
2329 onChangeSelection(
2330 isInSelectionArray ? selection.filter((itemId) => id !== itemId) : [...selection, id]
2331 );
2332 },
2333 ...extraProps
2334 }
2335 );
2336 }
2337
2338 // packages/dataviews/build-module/components/dataviews-item-actions/index.mjs
2339 var import_components2 = __toESM(require_components(), 1);
2340 var import_i18n9 = __toESM(require_i18n(), 1);
2341 var import_element4 = __toESM(require_element(), 1);
2342 var import_data = __toESM(require_data(), 1);
2343 var import_compose = __toESM(require_compose(), 1);
2344
2345 // packages/dataviews/build-module/lock-unlock.mjs
2346 var import_private_apis = __toESM(require_private_apis(), 1);
2347 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
2348 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
2349 "@wordpress/dataviews"
2350 );
2351
2352 // packages/dataviews/build-module/components/dataviews-item-actions/index.mjs
2353 var import_jsx_runtime32 = __toESM(require_jsx_runtime(), 1);
2354 var { Menu, kebabCase } = unlock(import_components2.privateApis);
2355 function ButtonTrigger({
2356 action,
2357 onClick,
2358 items,
2359 variant
2360 }) {
2361 const label = typeof action.label === "string" ? action.label : action.label(items);
2362 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2363 import_components2.Button,
2364 {
2365 disabled: !!action.disabled,
2366 accessibleWhenDisabled: true,
2367 size: "compact",
2368 variant,
2369 onClick,
2370 children: label
2371 }
2372 );
2373 }
2374 function MenuItemTrigger({
2375 action,
2376 onClick,
2377 items
2378 }) {
2379 const label = typeof action.label === "string" ? action.label : action.label(items);
2380 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Menu.Item, { disabled: action.disabled, onClick, children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Menu.ItemLabel, { children: label }) });
2381 }
2382 function ActionModal({
2383 action,
2384 items,
2385 closeModal
2386 }) {
2387 const label = typeof action.label === "string" ? action.label : action.label(items);
2388 const modalHeader = typeof action.modalHeader === "function" ? action.modalHeader(items) : action.modalHeader;
2389 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2390 import_components2.Modal,
2391 {
2392 title: modalHeader || label,
2393 __experimentalHideHeader: !!action.hideModalHeader,
2394 onRequestClose: closeModal,
2395 focusOnMount: action.modalFocusOnMount ?? true,
2396 size: action.modalSize || "medium",
2397 overlayClassName: `dataviews-action-modal dataviews-action-modal__${kebabCase(
2398 action.id
2399 )}`,
2400 children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(action.RenderModal, { items, closeModal })
2401 }
2402 );
2403 }
2404 function ActionsMenuGroup({
2405 actions,
2406 item,
2407 registry,
2408 setActiveModalAction
2409 }) {
2410 const { primaryActions, regularActions } = (0, import_element4.useMemo)(() => {
2411 return actions.reduce(
2412 (acc, action) => {
2413 (action.isPrimary ? acc.primaryActions : acc.regularActions).push(action);
2414 return acc;
2415 },
2416 {
2417 primaryActions: [],
2418 regularActions: []
2419 }
2420 );
2421 }, [actions]);
2422 const renderActionGroup = (actionList) => actionList.map((action) => /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2423 MenuItemTrigger,
2424 {
2425 action,
2426 onClick: () => {
2427 if ("RenderModal" in action) {
2428 setActiveModalAction(action);
2429 return;
2430 }
2431 action.callback([item], { registry });
2432 },
2433 items: [item]
2434 },
2435 action.id
2436 ));
2437 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(Menu.Group, { children: [
2438 renderActionGroup(primaryActions),
2439 renderActionGroup(regularActions)
2440 ] });
2441 }
2442 function ItemActions({
2443 item,
2444 actions,
2445 isCompact
2446 }) {
2447 const registry = (0, import_data.useRegistry)();
2448 const { primaryActions, eligibleActions } = (0, import_element4.useMemo)(() => {
2449 const _eligibleActions = actions.filter(
2450 (action) => !action.isEligible || action.isEligible(item)
2451 );
2452 const _primaryActions = _eligibleActions.filter(
2453 (action) => action.isPrimary
2454 );
2455 return {
2456 primaryActions: _primaryActions,
2457 eligibleActions: _eligibleActions
2458 };
2459 }, [actions, item]);
2460 const isMobileViewport = (0, import_compose.useViewportMatch)("medium", "<");
2461 if (isCompact) {
2462 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2463 CompactItemActions,
2464 {
2465 item,
2466 actions: eligibleActions,
2467 isSmall: true,
2468 registry
2469 }
2470 );
2471 }
2472 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(
2473 Stack,
2474 {
2475 direction: "row",
2476 justify: "flex-end",
2477 className: "dataviews-item-actions",
2478 style: {
2479 flexShrink: 0,
2480 width: "auto"
2481 },
2482 children: [
2483 /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2484 PrimaryActions,
2485 {
2486 item,
2487 actions: primaryActions,
2488 registry
2489 }
2490 ),
2491 (primaryActions.length < eligibleActions.length || // Since we hide primary actions on mobile, we need to show the menu
2492 // there if there are any actions at all.
2493 isMobileViewport) && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2494 CompactItemActions,
2495 {
2496 item,
2497 actions: eligibleActions,
2498 registry
2499 }
2500 )
2501 ]
2502 }
2503 );
2504 }
2505 function CompactItemActions({
2506 item,
2507 actions,
2508 isSmall,
2509 registry
2510 }) {
2511 const [activeModalAction, setActiveModalAction] = (0, import_element4.useState)(
2512 null
2513 );
2514 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(import_jsx_runtime32.Fragment, { children: [
2515 /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(Menu, { placement: "bottom-end", children: [
2516 /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2517 Menu.TriggerButton,
2518 {
2519 render: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2520 import_components2.Button,
2521 {
2522 size: isSmall ? "small" : "compact",
2523 icon: more_vertical_default,
2524 label: (0, import_i18n9.__)("Actions"),
2525 accessibleWhenDisabled: true,
2526 disabled: !actions.length,
2527 className: "dataviews-all-actions-button"
2528 }
2529 )
2530 }
2531 ),
2532 /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Menu.Popover, { children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2533 ActionsMenuGroup,
2534 {
2535 actions,
2536 item,
2537 registry,
2538 setActiveModalAction
2539 }
2540 ) })
2541 ] }),
2542 !!activeModalAction && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2543 ActionModal,
2544 {
2545 action: activeModalAction,
2546 items: [item],
2547 closeModal: () => setActiveModalAction(null)
2548 }
2549 )
2550 ] });
2551 }
2552 function PrimaryActions({
2553 item,
2554 actions,
2555 registry,
2556 buttonVariant
2557 }) {
2558 const [activeModalAction, setActiveModalAction] = (0, import_element4.useState)(null);
2559 const isMobileViewport = (0, import_compose.useViewportMatch)("medium", "<");
2560 if (isMobileViewport) {
2561 return null;
2562 }
2563 if (!Array.isArray(actions) || actions.length === 0) {
2564 return null;
2565 }
2566 return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(import_jsx_runtime32.Fragment, { children: [
2567 actions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2568 ButtonTrigger,
2569 {
2570 action,
2571 onClick: () => {
2572 if ("RenderModal" in action) {
2573 setActiveModalAction(action);
2574 return;
2575 }
2576 action.callback([item], { registry });
2577 },
2578 items: [item],
2579 variant: buttonVariant
2580 },
2581 action.id
2582 )),
2583 !!activeModalAction && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2584 ActionModal,
2585 {
2586 action: activeModalAction,
2587 items: [item],
2588 closeModal: () => setActiveModalAction(null)
2589 }
2590 )
2591 ] });
2592 }
2593
2594 // packages/dataviews/build-module/components/dataviews-bulk-actions/index.mjs
2595 var import_components3 = __toESM(require_components(), 1);
2596 var import_i18n11 = __toESM(require_i18n(), 1);
2597 var import_element5 = __toESM(require_element(), 1);
2598 var import_data2 = __toESM(require_data(), 1);
2599 var import_compose2 = __toESM(require_compose(), 1);
2600
2601 // packages/dataviews/build-module/utils/get-footer-message.mjs
2602 var import_i18n10 = __toESM(require_i18n(), 1);
2603 function getFooterMessage(selectionCount, itemsCount, totalItems, onlyTotalCount = false) {
2604 if (selectionCount > 0) {
2605 return (0, import_i18n10.sprintf)(
2606 /* translators: %d: number of items. */
2607 (0, import_i18n10._n)("%d Item selected", "%d Items selected", selectionCount),
2608 selectionCount
2609 );
2610 }
2611 if (onlyTotalCount || totalItems <= itemsCount) {
2612 return (0, import_i18n10.sprintf)(
2613 /* translators: %d: number of items. */
2614 (0, import_i18n10._n)("%d Item", "%d Items", totalItems),
2615 totalItems
2616 );
2617 }
2618 return (0, import_i18n10.sprintf)(
2619 /* translators: %1$d: number of items. %2$d: total number of items. */
2620 (0, import_i18n10._n)("%1$d of %2$d Item", "%1$d of %2$d Items", totalItems),
2621 itemsCount,
2622 totalItems
2623 );
2624 }
2625
2626 // packages/dataviews/build-module/components/dataviews-bulk-actions/index.mjs
2627 var import_jsx_runtime33 = __toESM(require_jsx_runtime(), 1);
2628 function useHasAPossibleBulkAction(actions, item) {
2629 return (0, import_element5.useMemo)(() => {
2630 return actions.some((action) => {
2631 return action.supportsBulk && (!action.isEligible || action.isEligible(item));
2632 });
2633 }, [actions, item]);
2634 }
2635 function useSomeItemHasAPossibleBulkAction(actions, data) {
2636 return (0, import_element5.useMemo)(() => {
2637 return data.some((item) => {
2638 return actions.some((action) => {
2639 return action.supportsBulk && (!action.isEligible || action.isEligible(item));
2640 });
2641 });
2642 }, [actions, data]);
2643 }
2644 function BulkSelectionCheckbox({
2645 selection,
2646 onChangeSelection,
2647 data,
2648 actions,
2649 getItemId,
2650 disableSelectAll = false
2651 }) {
2652 const selectableItems = (0, import_element5.useMemo)(() => {
2653 return data.filter((item) => {
2654 return actions.some(
2655 (action) => action.supportsBulk && (!action.isEligible || action.isEligible(item))
2656 );
2657 });
2658 }, [data, actions]);
2659 const selectedItems = data.filter(
2660 (item) => selection.includes(getItemId(item)) && selectableItems.includes(item)
2661 );
2662 const hasSelection = selection.length > 0;
2663 const areAllSelected = selectedItems.length === selectableItems.length;
2664 if (disableSelectAll) {
2665 return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2666 import_components3.CheckboxControl,
2667 {
2668 className: "dataviews-view-table-selection-checkbox",
2669 checked: hasSelection,
2670 disabled: !hasSelection,
2671 onChange: () => {
2672 onChangeSelection([]);
2673 },
2674 "aria-label": (0, import_i18n11.__)("Deselect all")
2675 }
2676 );
2677 }
2678 return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2679 import_components3.CheckboxControl,
2680 {
2681 className: "dataviews-view-table-selection-checkbox",
2682 checked: areAllSelected,
2683 indeterminate: !areAllSelected && !!selectedItems.length,
2684 onChange: () => {
2685 if (areAllSelected) {
2686 onChangeSelection([]);
2687 } else {
2688 onChangeSelection(
2689 selectableItems.map((item) => getItemId(item))
2690 );
2691 }
2692 },
2693 "aria-label": areAllSelected ? (0, import_i18n11.__)("Deselect all") : (0, import_i18n11.__)("Select all")
2694 }
2695 );
2696 }
2697
2698 // packages/dataviews/build-module/components/dataviews-layouts/table/column-header-menu.mjs
2699 var import_i18n12 = __toESM(require_i18n(), 1);
2700 var import_components4 = __toESM(require_components(), 1);
2701 var import_element6 = __toESM(require_element(), 1);
2702
2703 // packages/dataviews/build-module/utils/get-hideable-fields.mjs
2704 function getHideableFields(view, fields) {
2705 const togglableFields = [
2706 view?.titleField,
2707 view?.mediaField,
2708 view?.descriptionField
2709 ].filter(Boolean);
2710 return fields.filter(
2711 (f2) => !togglableFields.includes(f2.id) && f2.type !== "media" && f2.enableHiding !== false
2712 );
2713 }
2714
2715 // packages/dataviews/build-module/components/dataviews-layouts/table/column-header-menu.mjs
2716 var import_jsx_runtime34 = __toESM(require_jsx_runtime(), 1);
2717 var { Menu: Menu2 } = unlock(import_components4.privateApis);
2718 function WithMenuSeparators({ children }) {
2719 return import_element6.Children.toArray(children).filter(Boolean).map((child, i2) => /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_element6.Fragment, { children: [
2720 i2 > 0 && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Separator, {}),
2721 child
2722 ] }, i2));
2723 }
2724 var _HeaderMenu = (0, import_element6.forwardRef)(function HeaderMenu({
2725 fieldId,
2726 view,
2727 fields,
2728 onChangeView,
2729 onHide,
2730 setOpenedFilter,
2731 canMove = true,
2732 canInsertLeft = true,
2733 canInsertRight = true
2734 }, ref) {
2735 const visibleFieldIds = view.fields ?? [];
2736 const index = visibleFieldIds?.indexOf(fieldId);
2737 const isSorted = view.sort?.field === fieldId;
2738 let isHidable = false;
2739 let isSortable = false;
2740 let canAddFilter = false;
2741 let operators = [];
2742 const field = fields.find((f2) => f2.id === fieldId);
2743 const { setIsShowingFilter } = (0, import_element6.useContext)(dataviews_context_default);
2744 if (!field) {
2745 return null;
2746 }
2747 isHidable = field.enableHiding !== false;
2748 isSortable = field.enableSorting !== false;
2749 const header = field.header;
2750 operators = !!field.filterBy && field.filterBy?.operators || [];
2751 canAddFilter = !view.filters?.some((_filter) => fieldId === _filter.field) && !!(field.hasElements || field.Edit) && field.filterBy !== false && !field.filterBy?.isPrimary;
2752 if (!isSortable && !canMove && !isHidable && !canAddFilter) {
2753 return header;
2754 }
2755 const hiddenFields = getHideableFields(view, fields).filter(
2756 (f2) => !visibleFieldIds.includes(f2.id)
2757 );
2758 const canInsert = (canInsertLeft || canInsertRight) && !!hiddenFields.length;
2759 const isRtl = (0, import_i18n12.isRTL)();
2760 return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2, { children: [
2761 /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
2762 Menu2.TriggerButton,
2763 {
2764 render: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2765 import_components4.Button,
2766 {
2767 size: "compact",
2768 className: "dataviews-view-table-header-button",
2769 ref,
2770 variant: "tertiary"
2771 }
2772 ),
2773 children: [
2774 header,
2775 view.sort && isSorted && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("span", { "aria-hidden": "true", children: sortArrows[view.sort.direction] })
2776 ]
2777 }
2778 ),
2779 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Popover, { style: { minWidth: "240px" }, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(WithMenuSeparators, { children: [
2780 isSortable && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Group, { children: SORTING_DIRECTIONS.map(
2781 (direction) => {
2782 const isChecked = view.sort && isSorted && view.sort.direction === direction;
2783 const value = `${fieldId}-${direction}`;
2784 return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2785 Menu2.RadioItem,
2786 {
2787 name: "view-table-sorting",
2788 value,
2789 checked: isChecked,
2790 onChange: () => {
2791 onChangeView({
2792 ...view,
2793 sort: {
2794 field: fieldId,
2795 direction
2796 },
2797 showLevels: false
2798 });
2799 },
2800 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: sortLabels[direction] })
2801 },
2802 value
2803 );
2804 }
2805 ) }),
2806 canAddFilter && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Group, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2807 Menu2.Item,
2808 {
2809 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: funnel_default }),
2810 onClick: () => {
2811 setOpenedFilter(fieldId);
2812 setIsShowingFilter(true);
2813 onChangeView({
2814 ...view,
2815 page: 1,
2816 filters: [
2817 ...view.filters || [],
2818 {
2819 field: fieldId,
2820 value: void 0,
2821 operator: operators[0]
2822 }
2823 ]
2824 });
2825 },
2826 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Add filter") })
2827 }
2828 ) }),
2829 (canMove || isHidable || canInsert) && field && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2.Group, { children: [
2830 canMove && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2831 Menu2.Item,
2832 {
2833 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: arrow_left_default }),
2834 disabled: isRtl ? index >= visibleFieldIds.length - 1 : index < 1,
2835 onClick: () => {
2836 const targetIndex = isRtl ? index + 1 : index - 1;
2837 const newFields = [
2838 ...visibleFieldIds
2839 ];
2840 newFields.splice(index, 1);
2841 newFields.splice(
2842 targetIndex,
2843 0,
2844 fieldId
2845 );
2846 onChangeView({
2847 ...view,
2848 fields: newFields
2849 });
2850 },
2851 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Move left") })
2852 }
2853 ),
2854 canMove && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2855 Menu2.Item,
2856 {
2857 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: arrow_right_default }),
2858 disabled: isRtl ? index < 1 : index >= visibleFieldIds.length - 1,
2859 onClick: () => {
2860 const targetIndex = isRtl ? index - 1 : index + 1;
2861 const newFields = [
2862 ...visibleFieldIds
2863 ];
2864 newFields.splice(index, 1);
2865 newFields.splice(
2866 targetIndex,
2867 0,
2868 fieldId
2869 );
2870 onChangeView({
2871 ...view,
2872 fields: newFields
2873 });
2874 },
2875 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Move right") })
2876 }
2877 ),
2878 canInsertLeft && !!hiddenFields.length && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2, { children: [
2879 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.SubmenuTriggerItem, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Insert left") }) }),
2880 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Popover, { children: hiddenFields.map((hiddenField) => {
2881 const insertIndex = isRtl ? index + 1 : index;
2882 return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2883 Menu2.Item,
2884 {
2885 onClick: () => {
2886 onChangeView({
2887 ...view,
2888 fields: [
2889 ...visibleFieldIds.slice(
2890 0,
2891 insertIndex
2892 ),
2893 hiddenField.id,
2894 ...visibleFieldIds.slice(
2895 insertIndex
2896 )
2897 ]
2898 });
2899 },
2900 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: hiddenField.label })
2901 },
2902 hiddenField.id
2903 );
2904 }) })
2905 ] }),
2906 canInsertRight && !!hiddenFields.length && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(Menu2, { children: [
2907 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.SubmenuTriggerItem, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Insert right") }) }),
2908 /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.Popover, { children: hiddenFields.map((hiddenField) => {
2909 const insertIndex = isRtl ? index : index + 1;
2910 return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2911 Menu2.Item,
2912 {
2913 onClick: () => {
2914 onChangeView({
2915 ...view,
2916 fields: [
2917 ...visibleFieldIds.slice(
2918 0,
2919 insertIndex
2920 ),
2921 hiddenField.id,
2922 ...visibleFieldIds.slice(
2923 insertIndex
2924 )
2925 ]
2926 });
2927 },
2928 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: hiddenField.label })
2929 },
2930 hiddenField.id
2931 );
2932 }) })
2933 ] }),
2934 isHidable && field && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
2935 Menu2.Item,
2936 {
2937 prefix: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_components4.Icon, { icon: unseen_default }),
2938 onClick: () => {
2939 onHide(field);
2940 onChangeView({
2941 ...view,
2942 fields: visibleFieldIds.filter(
2943 (id) => id !== fieldId
2944 )
2945 });
2946 },
2947 children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Menu2.ItemLabel, { children: (0, import_i18n12.__)("Hide column") })
2948 }
2949 )
2950 ] })
2951 ] }) })
2952 ] });
2953 });
2954 var ColumnHeaderMenu = _HeaderMenu;
2955 var column_header_menu_default = ColumnHeaderMenu;
2956
2957 // packages/dataviews/build-module/components/dataviews-layouts/utils/item-click-wrapper.mjs
2958 var import_element7 = __toESM(require_element(), 1);
2959 var import_jsx_runtime35 = __toESM(require_jsx_runtime(), 1);
2960 function getClickableItemProps({
2961 item,
2962 isItemClickable: isItemClickable2,
2963 onClickItem,
2964 className
2965 }) {
2966 if (!isItemClickable2(item) || !onClickItem) {
2967 return { className };
2968 }
2969 return {
2970 className: className ? `${className} ${className}--clickable` : void 0,
2971 role: "button",
2972 tabIndex: 0,
2973 onClick: (event) => {
2974 event.stopPropagation();
2975 onClickItem(item);
2976 },
2977 onKeyDown: (event) => {
2978 if (event.key === "Enter" || event.key === "" || event.key === " ") {
2979 event.stopPropagation();
2980 onClickItem(item);
2981 }
2982 }
2983 };
2984 }
2985 function ItemClickWrapper({
2986 item,
2987 isItemClickable: isItemClickable2,
2988 onClickItem,
2989 renderItemLink,
2990 className,
2991 children,
2992 ...extraProps
2993 }) {
2994 if (!isItemClickable2(item)) {
2995 return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className, ...extraProps, children });
2996 }
2997 if (renderItemLink) {
2998 const renderedElement = renderItemLink({
2999 item,
3000 className: `${className} ${className}--clickable`,
3001 ...extraProps,
3002 children
3003 });
3004 return (0, import_element7.cloneElement)(renderedElement, {
3005 onClick: (event) => {
3006 event.stopPropagation();
3007 if (renderedElement.props.onClick) {
3008 renderedElement.props.onClick(event);
3009 }
3010 },
3011 onKeyDown: (event) => {
3012 if (event.key === "Enter" || event.key === "" || event.key === " ") {
3013 event.stopPropagation();
3014 if (renderedElement.props.onKeyDown) {
3015 renderedElement.props.onKeyDown(event);
3016 }
3017 }
3018 }
3019 });
3020 }
3021 const clickProps = getClickableItemProps({
3022 item,
3023 isItemClickable: isItemClickable2,
3024 onClickItem,
3025 className
3026 });
3027 return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { ...clickProps, ...extraProps, children });
3028 }
3029
3030 // packages/dataviews/build-module/components/dataviews-layouts/table/column-primary.mjs
3031 var import_jsx_runtime36 = __toESM(require_jsx_runtime(), 1);
3032 function ColumnPrimary({
3033 item,
3034 level,
3035 titleField,
3036 mediaField,
3037 descriptionField: descriptionField2,
3038 onClickItem,
3039 renderItemLink,
3040 isItemClickable: isItemClickable2
3041 }) {
3042 return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(Stack, { direction: "row", gap: "md", align: "flex-start", justify: "flex-start", children: [
3043 mediaField && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3044 ItemClickWrapper,
3045 {
3046 item,
3047 isItemClickable: isItemClickable2,
3048 onClickItem,
3049 renderItemLink,
3050 className: "dataviews-view-table__cell-content-wrapper dataviews-column-primary__media",
3051 "aria-label": isItemClickable2(item) && (!!onClickItem || !!renderItemLink) && !!titleField ? titleField.getValue?.({ item }) : void 0,
3052 children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3053 mediaField.render,
3054 {
3055 item,
3056 field: mediaField,
3057 config: { sizes: "32px" }
3058 }
3059 )
3060 }
3061 ),
3062 /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
3063 Stack,
3064 {
3065 direction: "column",
3066 align: "flex-start",
3067 className: "dataviews-view-table__primary-column-content",
3068 children: [
3069 titleField && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
3070 ItemClickWrapper,
3071 {
3072 item,
3073 isItemClickable: isItemClickable2,
3074 onClickItem,
3075 renderItemLink,
3076 className: "dataviews-view-table__cell-content-wrapper dataviews-title-field",
3077 children: [
3078 level !== void 0 && level > 0 && /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("span", { className: "dataviews-view-table__level", children: [
3079 Array(level).fill("\u2014").join(" "),
3080 "\xA0"
3081 ] }),
3082 /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(titleField.render, { item, field: titleField })
3083 ]
3084 }
3085 ),
3086 descriptionField2 && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3087 descriptionField2.render,
3088 {
3089 item,
3090 field: descriptionField2
3091 }
3092 )
3093 ]
3094 }
3095 )
3096 ] });
3097 }
3098 var column_primary_default = ColumnPrimary;
3099
3100 // packages/dataviews/build-module/components/dataviews-layouts/table/use-scroll-state.mjs
3101 var import_element8 = __toESM(require_element(), 1);
3102 var import_i18n13 = __toESM(require_i18n(), 1);
3103 var isScrolledToEnd = (element) => {
3104 if ((0, import_i18n13.isRTL)()) {
3105 const scrollLeft = Math.abs(element.scrollLeft);
3106 return scrollLeft <= 1;
3107 }
3108 return element.scrollLeft + element.clientWidth >= element.scrollWidth - 1;
3109 };
3110 function useScrollState({
3111 scrollContainerRef,
3112 enabledHorizontal = false
3113 }) {
3114 const [isHorizontalScrollEnd, setIsHorizontalScrollEnd] = (0, import_element8.useState)(false);
3115 const [isVerticallyScrolled, setIsVerticallyScrolled] = (0, import_element8.useState)(false);
3116 const handleScroll = (0, import_element8.useCallback)(() => {
3117 const scrollContainer = scrollContainerRef.current;
3118 if (!scrollContainer) {
3119 return;
3120 }
3121 if (enabledHorizontal) {
3122 setIsHorizontalScrollEnd(isScrolledToEnd(scrollContainer));
3123 }
3124 setIsVerticallyScrolled(scrollContainer.scrollTop > 0);
3125 }, [scrollContainerRef, enabledHorizontal]);
3126 (0, import_element8.useEffect)(() => {
3127 if (typeof window === "undefined" || !scrollContainerRef.current) {
3128 return () => {
3129 };
3130 }
3131 const scrollContainer = scrollContainerRef.current;
3132 handleScroll();
3133 scrollContainer.addEventListener("scroll", handleScroll);
3134 window.addEventListener("resize", handleScroll);
3135 return () => {
3136 scrollContainer.removeEventListener("scroll", handleScroll);
3137 window.removeEventListener("resize", handleScroll);
3138 };
3139 }, [scrollContainerRef, enabledHorizontal, handleScroll]);
3140 return { isHorizontalScrollEnd, isVerticallyScrolled };
3141 }
3142
3143 // packages/dataviews/build-module/components/dataviews-layouts/utils/get-data-by-group.mjs
3144 function getDataByGroup(data, groupByField) {
3145 return data.reduce((groups, item) => {
3146 const groupName = groupByField.getValue({ item });
3147 if (!groups.has(groupName)) {
3148 groups.set(groupName, []);
3149 }
3150 groups.get(groupName)?.push(item);
3151 return groups;
3152 }, /* @__PURE__ */ new Map());
3153 }
3154
3155 // packages/dataviews/build-module/components/dataviews-view-config/properties-section.mjs
3156 var import_components5 = __toESM(require_components(), 1);
3157 var import_i18n14 = __toESM(require_i18n(), 1);
3158 var import_element9 = __toESM(require_element(), 1);
3159 var import_jsx_runtime37 = __toESM(require_jsx_runtime(), 1);
3160 function FieldItem({
3161 field,
3162 isVisible: isVisible2,
3163 onToggleVisibility
3164 }) {
3165 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: [
3166 /* @__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 }) }),
3167 /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("span", { className: "dataviews-view-config__label", children: field.label })
3168 ] }) });
3169 }
3170 function isDefined(item) {
3171 return !!item;
3172 }
3173 function PropertiesSection({
3174 showLabel = true
3175 }) {
3176 const { view, fields, onChangeView } = (0, import_element9.useContext)(dataviews_context_default);
3177 const regularFields = getHideableFields(view, fields);
3178 if (!regularFields?.length) {
3179 return null;
3180 }
3181 const titleField = fields.find((f2) => f2.id === view.titleField);
3182 const previewField = fields.find((f2) => f2.id === view.mediaField);
3183 const descriptionField2 = fields.find(
3184 (f2) => f2.id === view.descriptionField
3185 );
3186 const lockedFields = [
3187 {
3188 field: titleField,
3189 isVisibleFlag: "showTitle"
3190 },
3191 {
3192 field: previewField,
3193 isVisibleFlag: "showMedia"
3194 },
3195 {
3196 field: descriptionField2,
3197 isVisibleFlag: "showDescription"
3198 }
3199 ].filter(({ field }) => isDefined(field));
3200 const visibleFieldIds = view.fields ?? [];
3201 const visibleRegularFieldsCount = regularFields.filter(
3202 (f2) => visibleFieldIds.includes(f2.id)
3203 ).length;
3204 const visibleLockedFields = lockedFields.filter(
3205 ({ isVisibleFlag }) => (
3206 // @ts-expect-error
3207 view[isVisibleFlag] ?? true
3208 )
3209 );
3210 const totalVisibleFields = visibleLockedFields.length + visibleRegularFieldsCount;
3211 const isSingleVisibleLockedField = totalVisibleFields === 1 && visibleLockedFields.length === 1;
3212 return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(Stack, { direction: "column", className: "dataviews-field-control", children: [
3213 showLabel && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_components5.BaseControl.VisualLabel, { children: (0, import_i18n14.__)("Properties") }),
3214 /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3215 Stack,
3216 {
3217 direction: "column",
3218 className: "dataviews-view-config__properties",
3219 children: /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(import_components5.__experimentalItemGroup, { isBordered: true, isSeparated: true, size: "medium", children: [
3220 lockedFields.map(({ field, isVisibleFlag }) => {
3221 const isVisible2 = view[isVisibleFlag] ?? true;
3222 const fieldToRender = isSingleVisibleLockedField && isVisible2 ? { ...field, enableHiding: false } : field;
3223 return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3224 FieldItem,
3225 {
3226 field: fieldToRender,
3227 isVisible: isVisible2,
3228 onToggleVisibility: () => {
3229 onChangeView({
3230 ...view,
3231 [isVisibleFlag]: !isVisible2
3232 });
3233 }
3234 },
3235 field.id
3236 );
3237 }),
3238 regularFields.map((field) => {
3239 const isVisible2 = visibleFieldIds.includes(field.id);
3240 const fieldToRender = totalVisibleFields === 1 && isVisible2 ? { ...field, enableHiding: false } : field;
3241 return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3242 FieldItem,
3243 {
3244 field: fieldToRender,
3245 isVisible: isVisible2,
3246 onToggleVisibility: () => {
3247 onChangeView({
3248 ...view,
3249 fields: isVisible2 ? visibleFieldIds.filter(
3250 (fieldId) => fieldId !== field.id
3251 ) : [...visibleFieldIds, field.id]
3252 });
3253 }
3254 },
3255 field.id
3256 );
3257 })
3258 ] })
3259 }
3260 )
3261 ] });
3262 }
3263
3264 // packages/dataviews/build-module/hooks/use-delayed-loading.mjs
3265 var import_element10 = __toESM(require_element(), 1);
3266 function useDelayedLoading(isLoading, options = { delay: 400 }) {
3267 const [showLoader, setShowLoader] = (0, import_element10.useState)(false);
3268 (0, import_element10.useEffect)(() => {
3269 if (!isLoading) {
3270 return;
3271 }
3272 const timeout = setTimeout(() => {
3273 setShowLoader(true);
3274 }, options.delay);
3275 return () => {
3276 clearTimeout(timeout);
3277 setShowLoader(false);
3278 };
3279 }, [isLoading, options.delay]);
3280 return showLoader;
3281 }
3282
3283 // packages/dataviews/build-module/components/dataviews-layouts/table/index.mjs
3284 var import_jsx_runtime38 = __toESM(require_jsx_runtime(), 1);
3285 function getEffectiveAlign(explicitAlign, fieldType) {
3286 if (explicitAlign) {
3287 return explicitAlign;
3288 }
3289 if (fieldType === "integer" || fieldType === "number") {
3290 return "end";
3291 }
3292 return void 0;
3293 }
3294 function TableColumnField({
3295 item,
3296 fields,
3297 column,
3298 align
3299 }) {
3300 const field = fields.find((f2) => f2.id === column);
3301 if (!field) {
3302 return null;
3303 }
3304 const className = clsx_default("dataviews-view-table__cell-content-wrapper", {
3305 "dataviews-view-table__cell-align-end": align === "end",
3306 "dataviews-view-table__cell-align-center": align === "center"
3307 });
3308 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(field.render, { item, field }) });
3309 }
3310 function TableRow({
3311 hasBulkActions,
3312 item,
3313 level,
3314 actions,
3315 fields,
3316 id,
3317 view,
3318 titleField,
3319 mediaField,
3320 descriptionField: descriptionField2,
3321 selection,
3322 getItemId,
3323 isItemClickable: isItemClickable2,
3324 onClickItem,
3325 renderItemLink,
3326 onChangeSelection,
3327 isActionsColumnSticky,
3328 posinset
3329 }) {
3330 const { paginationInfo } = (0, import_element11.useContext)(dataviews_context_default);
3331 const hasPossibleBulkAction = useHasAPossibleBulkAction(actions, item);
3332 const isSelected2 = hasPossibleBulkAction && selection.includes(id);
3333 const {
3334 showTitle = true,
3335 showMedia = true,
3336 showDescription = true,
3337 infiniteScrollEnabled
3338 } = view;
3339 const isTouchDeviceRef = (0, import_element11.useRef)(false);
3340 const columns = view.fields ?? [];
3341 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
3342 return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
3343 "tr",
3344 {
3345 className: clsx_default("dataviews-view-table__row", {
3346 "is-selected": hasPossibleBulkAction && isSelected2,
3347 "has-bulk-actions": hasPossibleBulkAction
3348 }),
3349 onTouchStart: () => {
3350 isTouchDeviceRef.current = true;
3351 },
3352 "aria-setsize": infiniteScrollEnabled ? paginationInfo.totalItems : void 0,
3353 "aria-posinset": posinset,
3354 role: infiniteScrollEnabled ? "article" : void 0,
3355 onMouseDown: (event) => {
3356 const isMetaClick = (0, import_keycodes.isAppleOS)() ? event.metaKey : event.ctrlKey;
3357 if (event.button === 0 && isMetaClick && window.navigator.userAgent.toLowerCase().includes("firefox")) {
3358 event?.preventDefault();
3359 }
3360 },
3361 onClick: (event) => {
3362 if (!hasPossibleBulkAction) {
3363 return;
3364 }
3365 const isModifierKeyPressed = (0, import_keycodes.isAppleOS)() ? event.metaKey : event.ctrlKey;
3366 if (isModifierKeyPressed && !isTouchDeviceRef.current && document.getSelection()?.type !== "Range") {
3367 onChangeSelection(
3368 selection.includes(id) ? selection.filter((itemId) => id !== itemId) : [...selection, id]
3369 );
3370 }
3371 },
3372 children: [
3373 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)(
3374 DataViewsSelectionCheckbox,
3375 {
3376 item,
3377 selection,
3378 onChangeSelection,
3379 getItemId,
3380 titleField,
3381 disabled: !hasPossibleBulkAction
3382 }
3383 ) }) }),
3384 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3385 column_primary_default,
3386 {
3387 item,
3388 level,
3389 titleField: showTitle ? titleField : void 0,
3390 mediaField: showMedia ? mediaField : void 0,
3391 descriptionField: showDescription ? descriptionField2 : void 0,
3392 isItemClickable: isItemClickable2,
3393 onClickItem,
3394 renderItemLink
3395 }
3396 ) }),
3397 columns.map((column) => {
3398 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
3399 const field = fields.find((f2) => f2.id === column);
3400 const effectiveAlign = getEffectiveAlign(align, field?.type);
3401 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3402 "td",
3403 {
3404 style: {
3405 width,
3406 maxWidth,
3407 minWidth
3408 },
3409 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3410 TableColumnField,
3411 {
3412 fields,
3413 item,
3414 column,
3415 align: effectiveAlign
3416 }
3417 )
3418 },
3419 column
3420 );
3421 }),
3422 !!actions?.length && // Disable reason: we are not making the element interactive,
3423 // but preventing any click events from bubbling up to the
3424 // table row. This allows us to add a click handler to the row
3425 // itself (to toggle row selection) without erroneously
3426 // intercepting click events from ItemActions.
3427 /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3428 "td",
3429 {
3430 className: clsx_default("dataviews-view-table__actions-column", {
3431 "dataviews-view-table__actions-column--sticky": true,
3432 "dataviews-view-table__actions-column--stuck": isActionsColumnSticky
3433 }),
3434 onClick: (e2) => e2.stopPropagation(),
3435 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(ItemActions, { item, actions })
3436 }
3437 )
3438 ]
3439 }
3440 );
3441 }
3442 function ViewTable({
3443 actions,
3444 data,
3445 fields,
3446 getItemId,
3447 getItemLevel,
3448 isLoading = false,
3449 onChangeView,
3450 onChangeSelection,
3451 selection,
3452 setOpenedFilter,
3453 onClickItem,
3454 isItemClickable: isItemClickable2,
3455 renderItemLink,
3456 view,
3457 className,
3458 empty
3459 }) {
3460 const { containerRef } = (0, import_element11.useContext)(dataviews_context_default);
3461 const isDelayedLoading = useDelayedLoading(isLoading);
3462 const headerMenuRefs = (0, import_element11.useRef)(/* @__PURE__ */ new Map());
3463 const headerMenuToFocusRef = (0, import_element11.useRef)(void 0);
3464 const [nextHeaderMenuToFocus, setNextHeaderMenuToFocus] = (0, import_element11.useState)();
3465 const [contextMenuAnchor, setContextMenuAnchor] = (0, import_element11.useState)(null);
3466 (0, import_element11.useEffect)(() => {
3467 if (headerMenuToFocusRef.current) {
3468 headerMenuToFocusRef.current.focus();
3469 headerMenuToFocusRef.current = void 0;
3470 }
3471 });
3472 const tableNoticeId = (0, import_element11.useId)();
3473 const { isHorizontalScrollEnd, isVerticallyScrolled } = useScrollState({
3474 scrollContainerRef: containerRef,
3475 enabledHorizontal: !!actions?.length
3476 });
3477 const hasBulkActions = useSomeItemHasAPossibleBulkAction(actions, data);
3478 if (nextHeaderMenuToFocus) {
3479 headerMenuToFocusRef.current = nextHeaderMenuToFocus;
3480 setNextHeaderMenuToFocus(void 0);
3481 return;
3482 }
3483 const onHide = (field) => {
3484 const hidden = headerMenuRefs.current.get(field.id);
3485 const fallback = hidden ? headerMenuRefs.current.get(hidden.fallback) : void 0;
3486 setNextHeaderMenuToFocus(fallback?.node);
3487 };
3488 const handleHeaderContextMenu = (event) => {
3489 event.preventDefault();
3490 event.stopPropagation();
3491 const virtualAnchor = {
3492 getBoundingClientRect: () => ({
3493 x: event.clientX,
3494 y: event.clientY,
3495 top: event.clientY,
3496 left: event.clientX,
3497 right: event.clientX,
3498 bottom: event.clientY,
3499 width: 0,
3500 height: 0,
3501 toJSON: () => ({})
3502 })
3503 };
3504 window.requestAnimationFrame(() => {
3505 setContextMenuAnchor(virtualAnchor);
3506 });
3507 };
3508 const hasData = !!data?.length;
3509 const titleField = fields.find((field) => field.id === view.titleField);
3510 const mediaField = fields.find((field) => field.id === view.mediaField);
3511 const descriptionField2 = fields.find(
3512 (field) => field.id === view.descriptionField
3513 );
3514 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
3515 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
3516 const { showTitle = true, showMedia = true, showDescription = true } = view;
3517 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
3518 const columns = view.fields ?? [];
3519 const headerMenuRef = (column, index) => (node) => {
3520 if (node) {
3521 headerMenuRefs.current.set(column, {
3522 node,
3523 fallback: columns[index > 0 ? index - 1 : 1]
3524 });
3525 } else {
3526 headerMenuRefs.current.delete(column);
3527 }
3528 };
3529 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
3530 const isRtl = (0, import_i18n15.isRTL)();
3531 if (!hasData) {
3532 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3533 "div",
3534 {
3535 className: clsx_default("dataviews-no-results", {
3536 "is-refreshing": isDelayedLoading
3537 }),
3538 id: tableNoticeId,
3539 children: empty
3540 }
3541 );
3542 }
3543 return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(import_jsx_runtime38.Fragment, { children: [
3544 /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
3545 "table",
3546 {
3547 className: clsx_default("dataviews-view-table", className, {
3548 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
3549 view.layout.density
3550 ),
3551 "has-bulk-actions": hasBulkActions,
3552 "is-refreshing": !isInfiniteScroll && isDelayedLoading
3553 }),
3554 "aria-busy": isLoading,
3555 "aria-describedby": tableNoticeId,
3556 role: isInfiniteScroll ? "feed" : void 0,
3557 inert: !isInfiniteScroll && isLoading ? "true" : void 0,
3558 children: [
3559 /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("colgroup", { children: [
3560 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("col", { className: "dataviews-view-table__col-checkbox" }),
3561 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("col", { className: "dataviews-view-table__col-first-data" }),
3562 columns.map((column, index) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3563 "col",
3564 {
3565 className: clsx_default(
3566 `dataviews-view-table__col-${column}`,
3567 {
3568 "dataviews-view-table__col-expand": !hasPrimaryColumn && index === columns.length - 1
3569 }
3570 )
3571 },
3572 `col-${column}`
3573 )),
3574 !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("col", { className: "dataviews-view-table__col-actions" })
3575 ] }),
3576 contextMenuAnchor && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3577 import_components6.Popover,
3578 {
3579 anchor: contextMenuAnchor,
3580 onClose: () => setContextMenuAnchor(null),
3581 placement: "bottom-start",
3582 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(PropertiesSection, { showLabel: false })
3583 }
3584 ),
3585 /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3586 "thead",
3587 {
3588 className: clsx_default({
3589 "dataviews-view-table__thead--stuck": isVerticallyScrolled
3590 }),
3591 onContextMenu: handleHeaderContextMenu,
3592 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("tr", { className: "dataviews-view-table__row", children: [
3593 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3594 "th",
3595 {
3596 className: "dataviews-view-table__checkbox-column",
3597 scope: "col",
3598 onContextMenu: handleHeaderContextMenu,
3599 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3600 BulkSelectionCheckbox,
3601 {
3602 selection,
3603 onChangeSelection,
3604 data,
3605 actions,
3606 getItemId
3607 }
3608 )
3609 }
3610 ),
3611 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("th", { scope: "col", children: titleField && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3612 column_header_menu_default,
3613 {
3614 ref: headerMenuRef(
3615 titleField.id,
3616 0
3617 ),
3618 fieldId: titleField.id,
3619 view,
3620 fields,
3621 onChangeView,
3622 onHide,
3623 setOpenedFilter,
3624 canMove: false,
3625 canInsertLeft: isRtl ? view.layout?.enableMoving ?? true : false,
3626 canInsertRight: isRtl ? false : view.layout?.enableMoving ?? true
3627 }
3628 ) }),
3629 columns.map((column, index) => {
3630 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
3631 const field = fields.find(
3632 (f2) => f2.id === column
3633 );
3634 const effectiveAlign = getEffectiveAlign(
3635 align,
3636 field?.type
3637 );
3638 const canInsertOrMove = view.layout?.enableMoving ?? true;
3639 return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3640 "th",
3641 {
3642 style: {
3643 width,
3644 maxWidth,
3645 minWidth,
3646 textAlign: effectiveAlign
3647 },
3648 "aria-sort": view.sort?.direction && view.sort?.field === column ? sortValues[view.sort.direction] : void 0,
3649 scope: "col",
3650 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3651 column_header_menu_default,
3652 {
3653 ref: headerMenuRef(column, index),
3654 fieldId: column,
3655 view,
3656 fields,
3657 onChangeView,
3658 onHide,
3659 setOpenedFilter,
3660 canMove: canInsertOrMove,
3661 canInsertLeft: canInsertOrMove,
3662 canInsertRight: canInsertOrMove
3663 }
3664 )
3665 },
3666 column
3667 );
3668 }),
3669 !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3670 "th",
3671 {
3672 className: clsx_default(
3673 "dataviews-view-table__actions-column",
3674 {
3675 "dataviews-view-table__actions-column--sticky": true,
3676 "dataviews-view-table__actions-column--stuck": !isHorizontalScrollEnd
3677 }
3678 ),
3679 children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("span", { className: "dataviews-view-table-header", children: (0, import_i18n15.__)("Actions") })
3680 }
3681 )
3682 ] })
3683 }
3684 ),
3685 hasData && groupField && dataByGroup ? Array.from(dataByGroup.entries()).map(
3686 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("tbody", { children: [
3687 /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("tr", { className: "dataviews-view-table__group-header-row", children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3688 "td",
3689 {
3690 colSpan: columns.length + (hasPrimaryColumn ? 1 : 0) + (hasBulkActions ? 1 : 0) + (actions?.length ? 1 : 0),
3691 className: "dataviews-view-table__group-header-cell",
3692 children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n15.sprintf)(
3693 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
3694 (0, import_i18n15.__)("%1$s: %2$s"),
3695 groupField.label,
3696 groupName
3697 )
3698 }
3699 ) }),
3700 groupItems.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3701 TableRow,
3702 {
3703 item,
3704 level: view.showLevels && typeof getItemLevel === "function" ? getItemLevel(item) : void 0,
3705 hasBulkActions,
3706 actions,
3707 fields,
3708 id: getItemId(item) || index.toString(),
3709 view,
3710 titleField,
3711 mediaField,
3712 descriptionField: descriptionField2,
3713 selection,
3714 getItemId,
3715 onChangeSelection,
3716 onClickItem,
3717 renderItemLink,
3718 isItemClickable: isItemClickable2,
3719 isActionsColumnSticky: !isHorizontalScrollEnd
3720 },
3721 getItemId(item)
3722 ))
3723 ] }, `group-${groupName}`)
3724 ) : /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("tbody", { children: hasData && data.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
3725 TableRow,
3726 {
3727 item,
3728 level: view.showLevels && typeof getItemLevel === "function" ? getItemLevel(item) : void 0,
3729 hasBulkActions,
3730 actions,
3731 fields,
3732 id: getItemId(item) || index.toString(),
3733 view,
3734 titleField,
3735 mediaField,
3736 descriptionField: descriptionField2,
3737 selection,
3738 getItemId,
3739 onChangeSelection,
3740 onClickItem,
3741 renderItemLink,
3742 isItemClickable: isItemClickable2,
3743 isActionsColumnSticky: !isHorizontalScrollEnd,
3744 posinset: isInfiniteScroll ? index + 1 : void 0
3745 },
3746 getItemId(item)
3747 )) })
3748 ]
3749 }
3750 ),
3751 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, {}) }) })
3752 ] });
3753 }
3754 var table_default = ViewTable;
3755
3756 // packages/dataviews/build-module/components/dataviews-layouts/grid/index.mjs
3757 var import_components9 = __toESM(require_components(), 1);
3758 var import_i18n18 = __toESM(require_i18n(), 1);
3759
3760 // packages/dataviews/build-module/components/dataviews-layouts/grid/composite-grid.mjs
3761 var import_components8 = __toESM(require_components(), 1);
3762 var import_i18n17 = __toESM(require_i18n(), 1);
3763 var import_compose3 = __toESM(require_compose(), 1);
3764 var import_keycodes2 = __toESM(require_keycodes(), 1);
3765 var import_element15 = __toESM(require_element(), 1);
3766
3767 // packages/dataviews/build-module/components/dataviews-layouts/grid/preview-size-picker.mjs
3768 var import_components7 = __toESM(require_components(), 1);
3769 var import_i18n16 = __toESM(require_i18n(), 1);
3770 var import_element12 = __toESM(require_element(), 1);
3771 var import_jsx_runtime39 = __toESM(require_jsx_runtime(), 1);
3772 var imageSizes = [
3773 {
3774 value: 120,
3775 breakpoint: 1
3776 },
3777 {
3778 value: 170,
3779 breakpoint: 1
3780 },
3781 {
3782 value: 230,
3783 breakpoint: 1
3784 },
3785 {
3786 value: 290,
3787 breakpoint: 1112
3788 // at minimum image width, 4 images display at this container size
3789 },
3790 {
3791 value: 350,
3792 breakpoint: 1636
3793 // at minimum image width, 6 images display at this container size
3794 },
3795 {
3796 value: 430,
3797 breakpoint: 588
3798 // at minimum image width, 2 images display at this container size
3799 }
3800 ];
3801 var DEFAULT_PREVIEW_SIZE = imageSizes[2].value;
3802 function useGridColumns() {
3803 const context = (0, import_element12.useContext)(dataviews_context_default);
3804 const view = context.view;
3805 return (0, import_element12.useMemo)(() => {
3806 const containerWidth = context.containerWidth;
3807 const gap = 32;
3808 const previewSize = view.layout?.previewSize ?? DEFAULT_PREVIEW_SIZE;
3809 const columns = Math.floor(
3810 (containerWidth + gap) / (previewSize + gap)
3811 );
3812 return Math.max(1, columns);
3813 }, [context.containerWidth, view.layout?.previewSize]);
3814 }
3815
3816 // packages/dataviews/build-module/components/dataviews-layouts/utils/grid-items.mjs
3817 var import_element13 = __toESM(require_element(), 1);
3818 var import_jsx_runtime40 = __toESM(require_jsx_runtime(), 1);
3819 var GridItems = (0, import_element13.forwardRef)(({ className, previewSize, ...props }, ref) => {
3820 return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
3821 "div",
3822 {
3823 ref,
3824 className: clsx_default("dataviews-view-grid-items", className),
3825 style: {
3826 gridTemplateColumns: previewSize && `repeat(auto-fill, minmax(${previewSize}px, 1fr))`
3827 },
3828 ...props
3829 }
3830 );
3831 });
3832
3833 // packages/dataviews/build-module/components/dataviews-layouts/utils/use-infinite-scroll.mjs
3834 var import_element14 = __toESM(require_element(), 1);
3835 function useIntersectionObserver(elementRef, posinset) {
3836 const { intersectionObserver } = (0, import_element14.useContext)(dataviews_context_default);
3837 (0, import_element14.useEffect)(() => {
3838 const element = elementRef.current;
3839 if (!element || posinset === void 0 || !intersectionObserver) {
3840 return;
3841 }
3842 intersectionObserver.observe(element);
3843 return () => {
3844 intersectionObserver.unobserve(element);
3845 };
3846 }, [elementRef, intersectionObserver, posinset]);
3847 }
3848 function usePlaceholdersNeeded(data, isInfiniteScroll, gridColumns) {
3849 const hasData = !!data?.length;
3850 const firstItemPosition = hasData && isInfiniteScroll ? data[0].position : void 0;
3851 return firstItemPosition && gridColumns ? (firstItemPosition - 1) % gridColumns : 0;
3852 }
3853
3854 // packages/dataviews/build-module/components/dataviews-layouts/grid/composite-grid.mjs
3855 var import_jsx_runtime41 = __toESM(require_jsx_runtime(), 1);
3856 var { Badge } = unlock(import_components8.privateApis);
3857 function chunk(array, size) {
3858 const chunks = [];
3859 for (let i2 = 0, j2 = array.length; i2 < j2; i2 += size) {
3860 chunks.push(array.slice(i2, i2 + size));
3861 }
3862 return chunks;
3863 }
3864 var GridItem = (0, import_element15.forwardRef)(
3865 function GridItem2({
3866 view,
3867 selection,
3868 onChangeSelection,
3869 onClickItem,
3870 isItemClickable: isItemClickable2,
3871 renderItemLink,
3872 getItemId,
3873 item,
3874 actions,
3875 mediaField,
3876 titleField,
3877 descriptionField: descriptionField2,
3878 regularFields,
3879 badgeFields,
3880 hasBulkActions,
3881 config,
3882 posinset,
3883 setsize,
3884 ...props
3885 }, forwardedRef) {
3886 const {
3887 showTitle = true,
3888 showMedia = true,
3889 showDescription = true
3890 } = view;
3891 const hasBulkAction = useHasAPossibleBulkAction(actions, item);
3892 const id = getItemId(item);
3893 const elementRef = (0, import_element15.useRef)(null);
3894 const setRefs = (0, import_element15.useCallback)(
3895 (node) => {
3896 elementRef.current = node;
3897 if (typeof forwardedRef === "function") {
3898 forwardedRef(node);
3899 } else if (forwardedRef) {
3900 forwardedRef.current = node;
3901 }
3902 },
3903 [forwardedRef]
3904 );
3905 useIntersectionObserver(elementRef, posinset);
3906 const instanceId = (0, import_compose3.useInstanceId)(GridItem2);
3907 const isSelected2 = selection.includes(id);
3908 const mediaPlaceholder = /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("span", { className: "dataviews-view-grid__media-placeholder" });
3909 const rendersMediaField = showMedia && mediaField?.render;
3910 const renderedMediaField = rendersMediaField ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3911 mediaField.render,
3912 {
3913 item,
3914 field: mediaField,
3915 config
3916 }
3917 ) : mediaPlaceholder;
3918 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(titleField.render, { item, field: titleField }) : null;
3919 let mediaA11yProps;
3920 let titleA11yProps;
3921 if (isItemClickable2(item) && onClickItem) {
3922 if (renderedTitleField) {
3923 mediaA11yProps = {
3924 "aria-labelledby": `dataviews-view-grid__title-field-${instanceId}`
3925 };
3926 titleA11yProps = {
3927 id: `dataviews-view-grid__title-field-${instanceId}`
3928 };
3929 } else {
3930 mediaA11yProps = {
3931 "aria-label": (0, import_i18n17.__)("Navigate to item")
3932 };
3933 }
3934 }
3935 return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
3936 Stack,
3937 {
3938 direction: "column",
3939 ...props,
3940 ref: setRefs,
3941 "aria-setsize": setsize,
3942 "aria-posinset": posinset,
3943 className: clsx_default(
3944 props.className,
3945 "dataviews-view-grid__row__gridcell",
3946 "dataviews-view-grid__card",
3947 {
3948 "is-selected": hasBulkAction && isSelected2
3949 }
3950 ),
3951 onClickCapture: (event) => {
3952 props.onClickCapture?.(event);
3953 if ((0, import_keycodes2.isAppleOS)() ? event.metaKey : event.ctrlKey) {
3954 event.stopPropagation();
3955 event.preventDefault();
3956 if (!hasBulkAction) {
3957 return;
3958 }
3959 onChangeSelection(
3960 isSelected2 ? selection.filter(
3961 (itemId) => id !== itemId
3962 ) : [...selection, id]
3963 );
3964 }
3965 },
3966 children: [
3967 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3968 ItemClickWrapper,
3969 {
3970 item,
3971 isItemClickable: isItemClickable2,
3972 onClickItem,
3973 renderItemLink,
3974 className: clsx_default("dataviews-view-grid__media", {
3975 "dataviews-view-grid__media--placeholder": !rendersMediaField
3976 }),
3977 ...mediaA11yProps,
3978 children: renderedMediaField
3979 }
3980 ),
3981 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3982 DataViewsSelectionCheckbox,
3983 {
3984 item,
3985 selection,
3986 onChangeSelection,
3987 getItemId,
3988 titleField,
3989 disabled: !hasBulkAction
3990 }
3991 ),
3992 !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "dataviews-view-grid__media-actions", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
3993 ItemActions,
3994 {
3995 item,
3996 actions,
3997 isCompact: true
3998 }
3999 ) }),
4000 showTitle && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "dataviews-view-grid__title", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4001 ItemClickWrapper,
4002 {
4003 item,
4004 isItemClickable: isItemClickable2,
4005 onClickItem,
4006 renderItemLink,
4007 className: "dataviews-view-grid__title-field dataviews-title-field",
4008 ...titleA11yProps,
4009 title: titleField?.getValueFormatted({
4010 item,
4011 field: titleField
4012 }) || void 0,
4013 children: renderedTitleField
4014 }
4015 ) }),
4016 /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(Stack, { direction: "column", gap: "xs", children: [
4017 showDescription && descriptionField2?.render && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4018 descriptionField2.render,
4019 {
4020 item,
4021 field: descriptionField2
4022 }
4023 ),
4024 !!badgeFields?.length && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4025 Stack,
4026 {
4027 direction: "row",
4028 className: "dataviews-view-grid__badge-fields",
4029 gap: "sm",
4030 wrap: "wrap",
4031 align: "top",
4032 justify: "flex-start",
4033 children: badgeFields.map((field) => {
4034 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4035 Badge,
4036 {
4037 className: "dataviews-view-grid__field-value",
4038 children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4039 field.render,
4040 {
4041 item,
4042 field
4043 }
4044 )
4045 },
4046 field.id
4047 );
4048 })
4049 }
4050 ),
4051 !!regularFields?.length && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4052 Stack,
4053 {
4054 direction: "column",
4055 className: "dataviews-view-grid__fields",
4056 gap: "xs",
4057 children: regularFields.map((field) => {
4058 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4059 import_components8.Flex,
4060 {
4061 className: "dataviews-view-grid__field",
4062 gap: 1,
4063 justify: "flex-start",
4064 expanded: true,
4065 style: { height: "auto" },
4066 direction: "row",
4067 children: /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(import_jsx_runtime41.Fragment, { children: [
4068 /* @__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 }) }),
4069 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4070 import_components8.FlexItem,
4071 {
4072 className: "dataviews-view-grid__field-value",
4073 style: { maxHeight: "none" },
4074 children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4075 field.render,
4076 {
4077 item,
4078 field
4079 }
4080 )
4081 }
4082 )
4083 ] })
4084 },
4085 field.id
4086 );
4087 })
4088 }
4089 )
4090 ] })
4091 ]
4092 }
4093 );
4094 }
4095 );
4096 function CompositeGrid({
4097 data,
4098 isInfiniteScroll,
4099 className,
4100 inert,
4101 isLoading,
4102 view,
4103 fields,
4104 selection,
4105 onChangeSelection,
4106 onClickItem,
4107 isItemClickable: isItemClickable2,
4108 renderItemLink,
4109 getItemId,
4110 actions
4111 }) {
4112 const { paginationInfo, resizeObserverRef } = (0, import_element15.useContext)(dataviews_context_default);
4113 const gridColumns = useGridColumns();
4114 const hasBulkActions = useSomeItemHasAPossibleBulkAction(actions, data);
4115 const titleField = fields.find(
4116 (field) => field.id === view?.titleField
4117 );
4118 const mediaField = fields.find(
4119 (field) => field.id === view?.mediaField
4120 );
4121 const descriptionField2 = fields.find(
4122 (field) => field.id === view?.descriptionField
4123 );
4124 const otherFields = view.fields ?? [];
4125 const { regularFields, badgeFields } = otherFields.reduce(
4126 (accumulator, fieldId) => {
4127 const field = fields.find((f2) => f2.id === fieldId);
4128 if (!field) {
4129 return accumulator;
4130 }
4131 const key = view.layout?.badgeFields?.includes(fieldId) ? "badgeFields" : "regularFields";
4132 accumulator[key].push(field);
4133 return accumulator;
4134 },
4135 { regularFields: [], badgeFields: [] }
4136 );
4137 const size = "900px";
4138 const totalRows = Math.ceil(data.length / gridColumns);
4139 const placeholdersNeeded = usePlaceholdersNeeded(
4140 data,
4141 isInfiniteScroll,
4142 gridColumns
4143 );
4144 return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(import_jsx_runtime41.Fragment, {
4145 // Render infinite scroll layout (no rows, feed semantics)
4146 children: [
4147 isInfiniteScroll && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
4148 import_components8.Composite,
4149 {
4150 render: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4151 GridItems,
4152 {
4153 className: clsx_default(
4154 "dataviews-view-grid-infinite-scroll",
4155 className,
4156 {
4157 [`has-${view.layout?.density}-density`]: view.layout?.density && [
4158 "compact",
4159 "comfortable"
4160 ].includes(view.layout.density)
4161 }
4162 ),
4163 previewSize: view.layout?.previewSize,
4164 "aria-busy": isLoading,
4165 ref: resizeObserverRef
4166 }
4167 ),
4168 role: "feed",
4169 focusWrap: true,
4170 inert,
4171 children: [
4172 Array.from({ length: placeholdersNeeded }).map(
4173 (_, index) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4174 import_components8.Composite.Item,
4175 {
4176 render: (props) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4177 Stack,
4178 {
4179 ...props,
4180 direction: "column",
4181 role: "article",
4182 className: "dataviews-view-grid__row__gridcell dataviews-view-grid__card dataviews-view-grid__placeholder"
4183 }
4184 ),
4185 "aria-hidden": true,
4186 tabIndex: -1
4187 },
4188 `placeholder-${index}`
4189 )
4190 ),
4191 data.map((item) => {
4192 const itemId = getItemId(item);
4193 const stablePosition = item.position;
4194 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4195 import_components8.Composite.Item,
4196 {
4197 render: (props) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4198 GridItem,
4199 {
4200 ...props,
4201 id: itemId,
4202 role: "article",
4203 view,
4204 selection,
4205 onChangeSelection,
4206 onClickItem,
4207 isItemClickable: isItemClickable2,
4208 renderItemLink,
4209 getItemId,
4210 item,
4211 actions,
4212 mediaField,
4213 titleField,
4214 descriptionField: descriptionField2,
4215 regularFields,
4216 badgeFields,
4217 hasBulkActions,
4218 posinset: stablePosition,
4219 setsize: paginationInfo.totalItems,
4220 config: {
4221 sizes: size
4222 }
4223 }
4224 )
4225 },
4226 itemId
4227 );
4228 })
4229 ]
4230 }
4231 ),
4232 // Render standard grid layout (with rows, grid semantics)
4233 !isInfiniteScroll && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4234 import_components8.Composite,
4235 {
4236 role: "grid",
4237 className: clsx_default("dataviews-view-grid", className, {
4238 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
4239 view.layout.density
4240 )
4241 }),
4242 focusWrap: true,
4243 "aria-busy": isLoading,
4244 "aria-rowcount": totalRows,
4245 ref: resizeObserverRef,
4246 inert,
4247 children: chunk(data, gridColumns).map((row, i2) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4248 import_components8.Composite.Row,
4249 {
4250 render: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4251 "div",
4252 {
4253 role: "row",
4254 "aria-rowindex": i2 + 1,
4255 "aria-label": (0, import_i18n17.sprintf)(
4256 /* translators: %d: The row number in the grid */
4257 (0, import_i18n17.__)("Row %d"),
4258 i2 + 1
4259 ),
4260 className: "dataviews-view-grid__row",
4261 style: {
4262 gridTemplateColumns: `repeat( ${gridColumns}, minmax(0, 1fr) )`
4263 }
4264 }
4265 ),
4266 children: row.map((item) => {
4267 const itemId = getItemId(item);
4268 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4269 import_components8.Composite.Item,
4270 {
4271 render: (props) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4272 GridItem,
4273 {
4274 ...props,
4275 id: itemId,
4276 role: "gridcell",
4277 view,
4278 selection,
4279 onChangeSelection,
4280 onClickItem,
4281 isItemClickable: isItemClickable2,
4282 renderItemLink,
4283 getItemId,
4284 item,
4285 actions,
4286 mediaField,
4287 titleField,
4288 descriptionField: descriptionField2,
4289 regularFields,
4290 badgeFields,
4291 hasBulkActions,
4292 config: {
4293 sizes: size
4294 }
4295 }
4296 )
4297 },
4298 itemId
4299 );
4300 })
4301 },
4302 i2
4303 ))
4304 }
4305 )
4306 ]
4307 });
4308 }
4309
4310 // packages/dataviews/build-module/components/dataviews-layouts/grid/index.mjs
4311 var import_jsx_runtime42 = __toESM(require_jsx_runtime(), 1);
4312 function ViewGrid({
4313 actions,
4314 data,
4315 fields,
4316 getItemId,
4317 isLoading,
4318 onChangeSelection,
4319 onClickItem,
4320 isItemClickable: isItemClickable2,
4321 renderItemLink,
4322 selection,
4323 view,
4324 className,
4325 empty
4326 }) {
4327 const isDelayedLoading = useDelayedLoading(!!isLoading);
4328 const hasData = !!data?.length;
4329 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
4330 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
4331 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
4332 if (!hasData) {
4333 return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
4334 "div",
4335 {
4336 className: clsx_default("dataviews-no-results", {
4337 "is-refreshing": isDelayedLoading
4338 }),
4339 children: empty
4340 }
4341 );
4342 }
4343 const gridProps = {
4344 className: clsx_default(className, {
4345 "is-refreshing": !isInfiniteScroll && isDelayedLoading
4346 }),
4347 inert: !isInfiniteScroll && !!isLoading ? "true" : void 0,
4348 isLoading,
4349 view,
4350 fields,
4351 selection,
4352 onChangeSelection,
4353 onClickItem,
4354 isItemClickable: isItemClickable2,
4355 renderItemLink,
4356 getItemId,
4357 actions
4358 };
4359 return /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(import_jsx_runtime42.Fragment, {
4360 // Render multiple groups.
4361 children: [
4362 hasData && groupField && dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(Stack, { direction: "column", gap: "lg", children: Array.from(dataByGroup.entries()).map(
4363 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(
4364 Stack,
4365 {
4366 direction: "column",
4367 gap: "sm",
4368 children: [
4369 /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("h3", { className: "dataviews-view-grid__group-header", children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n18.sprintf)(
4370 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
4371 (0, import_i18n18.__)("%1$s: %2$s"),
4372 groupField.label,
4373 groupName
4374 ) }),
4375 /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
4376 CompositeGrid,
4377 {
4378 ...gridProps,
4379 data: groupItems,
4380 isInfiniteScroll: false
4381 }
4382 )
4383 ]
4384 },
4385 groupName
4386 )
4387 ) }),
4388 // Render a single grid with all data.
4389 !dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
4390 CompositeGrid,
4391 {
4392 ...gridProps,
4393 data,
4394 isInfiniteScroll: !!isInfiniteScroll
4395 }
4396 ),
4397 isInfiniteScroll && isLoading && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(import_components9.Spinner, {}) })
4398 ]
4399 });
4400 }
4401 var grid_default = ViewGrid;
4402
4403 // packages/dataviews/build-module/components/dataviews-layouts/list/index.mjs
4404 var import_compose4 = __toESM(require_compose(), 1);
4405 var import_components10 = __toESM(require_components(), 1);
4406 var import_element16 = __toESM(require_element(), 1);
4407 var import_i18n19 = __toESM(require_i18n(), 1);
4408 var import_data3 = __toESM(require_data(), 1);
4409 var import_jsx_runtime43 = __toESM(require_jsx_runtime(), 1);
4410 var { Menu: Menu3 } = unlock(import_components10.privateApis);
4411 function generateItemWrapperCompositeId(idPrefix) {
4412 return `${idPrefix}-item-wrapper`;
4413 }
4414 function generatePrimaryActionCompositeId(idPrefix, primaryActionId) {
4415 return `${idPrefix}-primary-action-${primaryActionId}`;
4416 }
4417 function generateDropdownTriggerCompositeId(idPrefix) {
4418 return `${idPrefix}-dropdown`;
4419 }
4420 function PrimaryActionGridCell({
4421 idPrefix,
4422 primaryAction,
4423 item
4424 }) {
4425 const registry = (0, import_data3.useRegistry)();
4426 const [isModalOpen, setIsModalOpen] = (0, import_element16.useState)(false);
4427 const compositeItemId = generatePrimaryActionCompositeId(
4428 idPrefix,
4429 primaryAction.id
4430 );
4431 const label = typeof primaryAction.label === "string" ? primaryAction.label : primaryAction.label([item]);
4432 return "RenderModal" in primaryAction ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { role: "gridcell", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4433 import_components10.Composite.Item,
4434 {
4435 id: compositeItemId,
4436 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4437 import_components10.Button,
4438 {
4439 disabled: !!primaryAction.disabled,
4440 accessibleWhenDisabled: true,
4441 text: label,
4442 size: "small",
4443 onClick: () => setIsModalOpen(true)
4444 }
4445 ),
4446 children: isModalOpen && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4447 ActionModal,
4448 {
4449 action: primaryAction,
4450 items: [item],
4451 closeModal: () => setIsModalOpen(false)
4452 }
4453 )
4454 }
4455 ) }, primaryAction.id) : /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { role: "gridcell", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4456 import_components10.Composite.Item,
4457 {
4458 id: compositeItemId,
4459 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4460 import_components10.Button,
4461 {
4462 disabled: !!primaryAction.disabled,
4463 accessibleWhenDisabled: true,
4464 size: "small",
4465 onClick: () => {
4466 primaryAction.callback([item], { registry });
4467 },
4468 children: label
4469 }
4470 )
4471 }
4472 ) }, primaryAction.id);
4473 }
4474 function ListItem({
4475 view,
4476 actions,
4477 idPrefix,
4478 isSelected: isSelected2,
4479 item,
4480 titleField,
4481 mediaField,
4482 descriptionField: descriptionField2,
4483 onSelect,
4484 otherFields,
4485 onDropdownTriggerKeyDown,
4486 posinset
4487 }) {
4488 const {
4489 showTitle = true,
4490 showMedia = true,
4491 showDescription = true,
4492 infiniteScrollEnabled
4493 } = view;
4494 const itemRef = (0, import_element16.useRef)(null);
4495 const labelId = `${idPrefix}-label`;
4496 const descriptionId = `${idPrefix}-description`;
4497 const registry = (0, import_data3.useRegistry)();
4498 const [isHovered, setIsHovered] = (0, import_element16.useState)(false);
4499 const [activeModalAction, setActiveModalAction] = (0, import_element16.useState)(
4500 null
4501 );
4502 const handleHover = ({ type }) => {
4503 const isHover = type === "mouseenter";
4504 setIsHovered(isHover);
4505 };
4506 const { paginationInfo } = (0, import_element16.useContext)(dataviews_context_default);
4507 (0, import_element16.useEffect)(() => {
4508 if (isSelected2) {
4509 itemRef.current?.scrollIntoView({
4510 behavior: "auto",
4511 block: "nearest",
4512 inline: "nearest"
4513 });
4514 }
4515 }, [isSelected2]);
4516 const { primaryAction, eligibleActions } = (0, import_element16.useMemo)(() => {
4517 const _eligibleActions = actions.filter(
4518 (action) => !action.isEligible || action.isEligible(item)
4519 );
4520 const _primaryActions = _eligibleActions.filter(
4521 (action) => action.isPrimary
4522 );
4523 return {
4524 primaryAction: _primaryActions[0],
4525 eligibleActions: _eligibleActions
4526 };
4527 }, [actions, item]);
4528 const hasOnlyOnePrimaryAction = primaryAction && actions.length === 1;
4529 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)(
4530 mediaField.render,
4531 {
4532 item,
4533 field: mediaField,
4534 config: { sizes: "52px" }
4535 }
4536 ) }) : null;
4537 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(titleField.render, { item, field: titleField }) : null;
4538 const renderDescription = showDescription && descriptionField2?.render;
4539 const hasOnlyMediaAndTitle = !!renderedMediaField && !renderDescription && !otherFields.length;
4540 const usedActions = eligibleActions?.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4541 Stack,
4542 {
4543 direction: "row",
4544 gap: "md",
4545 className: "dataviews-view-list__item-actions",
4546 children: [
4547 primaryAction && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4548 PrimaryActionGridCell,
4549 {
4550 idPrefix,
4551 primaryAction,
4552 item
4553 }
4554 ),
4555 !hasOnlyOnePrimaryAction && /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { role: "gridcell", children: [
4556 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Menu3, { placement: "bottom-end", children: [
4557 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4558 Menu3.TriggerButton,
4559 {
4560 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4561 import_components10.Composite.Item,
4562 {
4563 id: generateDropdownTriggerCompositeId(
4564 idPrefix
4565 ),
4566 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4567 import_components10.Button,
4568 {
4569 size: "small",
4570 icon: more_vertical_default,
4571 label: (0, import_i18n19.__)("Actions"),
4572 accessibleWhenDisabled: true,
4573 disabled: !actions.length,
4574 onKeyDown: onDropdownTriggerKeyDown
4575 }
4576 )
4577 }
4578 )
4579 }
4580 ),
4581 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Menu3.Popover, { children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4582 ActionsMenuGroup,
4583 {
4584 actions: eligibleActions,
4585 item,
4586 registry,
4587 setActiveModalAction
4588 }
4589 ) })
4590 ] }),
4591 !!activeModalAction && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4592 ActionModal,
4593 {
4594 action: activeModalAction,
4595 items: [item],
4596 closeModal: () => setActiveModalAction(null)
4597 }
4598 )
4599 ] })
4600 ]
4601 }
4602 );
4603 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4604 import_components10.Composite.Row,
4605 {
4606 ref: itemRef,
4607 render: (
4608 /* aria-posinset breaks Composite.Row if passed to it directly. */
4609 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4610 "div",
4611 {
4612 "aria-posinset": posinset,
4613 "aria-setsize": infiniteScrollEnabled ? paginationInfo.totalItems : void 0
4614 }
4615 )
4616 ),
4617 role: infiniteScrollEnabled ? "article" : "row",
4618 className: clsx_default({
4619 "is-selected": isSelected2,
4620 "is-hovered": isHovered
4621 }),
4622 onMouseEnter: handleHover,
4623 onMouseLeave: handleHover,
4624 children: /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4625 Stack,
4626 {
4627 direction: "row",
4628 className: "dataviews-view-list__item-wrapper",
4629 children: [
4630 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { role: "gridcell", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4631 import_components10.Composite.Item,
4632 {
4633 id: generateItemWrapperCompositeId(idPrefix),
4634 "aria-pressed": isSelected2,
4635 "aria-labelledby": labelId,
4636 "aria-describedby": descriptionId,
4637 className: "dataviews-view-list__item",
4638 onClick: () => onSelect(item)
4639 }
4640 ) }),
4641 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4642 Stack,
4643 {
4644 direction: "row",
4645 gap: "md",
4646 justify: "start",
4647 align: hasOnlyMediaAndTitle ? "center" : "flex-start",
4648 style: { flex: 1, minWidth: 0 },
4649 children: [
4650 renderedMediaField,
4651 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4652 Stack,
4653 {
4654 direction: "column",
4655 gap: "xs",
4656 className: "dataviews-view-list__field-wrapper",
4657 children: [
4658 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Stack, { direction: "row", align: "center", children: [
4659 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4660 "div",
4661 {
4662 className: "dataviews-title-field dataviews-view-list__title-field",
4663 id: labelId,
4664 children: renderedTitleField
4665 }
4666 ),
4667 usedActions
4668 ] }),
4669 renderDescription && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "dataviews-view-list__field", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4670 descriptionField2.render,
4671 {
4672 item,
4673 field: descriptionField2
4674 }
4675 ) }),
4676 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4677 "div",
4678 {
4679 className: "dataviews-view-list__fields",
4680 id: descriptionId,
4681 children: otherFields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4682 "div",
4683 {
4684 className: "dataviews-view-list__field",
4685 children: [
4686 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4687 import_components10.VisuallyHidden,
4688 {
4689 as: "span",
4690 className: "dataviews-view-list__field-label",
4691 children: field.label
4692 }
4693 ),
4694 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "dataviews-view-list__field-value", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4695 field.render,
4696 {
4697 item,
4698 field
4699 }
4700 ) })
4701 ]
4702 },
4703 field.id
4704 ))
4705 }
4706 )
4707 ]
4708 }
4709 )
4710 ]
4711 }
4712 )
4713 ]
4714 }
4715 )
4716 }
4717 );
4718 }
4719 function isDefined2(item) {
4720 return !!item;
4721 }
4722 function ViewList(props) {
4723 const {
4724 actions,
4725 data,
4726 fields,
4727 getItemId,
4728 isLoading,
4729 onChangeSelection,
4730 selection,
4731 view,
4732 className,
4733 empty
4734 } = props;
4735 const baseId = (0, import_compose4.useInstanceId)(ViewList, "view-list");
4736 const isDelayedLoading = useDelayedLoading(!!isLoading);
4737 const selectedItem = data?.findLast(
4738 (item) => selection.includes(getItemId(item))
4739 );
4740 const titleField = fields.find((field) => field.id === view.titleField);
4741 const mediaField = fields.find((field) => field.id === view.mediaField);
4742 const descriptionField2 = fields.find(
4743 (field) => field.id === view.descriptionField
4744 );
4745 const otherFields = (view?.fields ?? []).map((fieldId) => fields.find((f2) => fieldId === f2.id)).filter(isDefined2);
4746 const onSelect = (item) => onChangeSelection([getItemId(item)]);
4747 const generateCompositeItemIdPrefix = (0, import_element16.useCallback)(
4748 (item) => `${baseId}-${getItemId(item)}`,
4749 [baseId, getItemId]
4750 );
4751 const isActiveCompositeItem = (0, import_element16.useCallback)(
4752 (item, idToCheck) => {
4753 return idToCheck.startsWith(
4754 generateCompositeItemIdPrefix(item)
4755 );
4756 },
4757 [generateCompositeItemIdPrefix]
4758 );
4759 const [activeCompositeId, setActiveCompositeId] = (0, import_element16.useState)(void 0);
4760 const compositeRef = (0, import_element16.useRef)(null);
4761 (0, import_element16.useEffect)(() => {
4762 if (selectedItem) {
4763 setActiveCompositeId(
4764 generateItemWrapperCompositeId(
4765 generateCompositeItemIdPrefix(selectedItem)
4766 )
4767 );
4768 }
4769 }, [selectedItem, generateCompositeItemIdPrefix]);
4770 const activeItemIndex = data.findIndex(
4771 (item) => isActiveCompositeItem(item, activeCompositeId ?? "")
4772 );
4773 const previousActiveItemIndex = (0, import_compose4.usePrevious)(activeItemIndex);
4774 const isActiveIdInList = activeItemIndex !== -1;
4775 const selectCompositeItem = (0, import_element16.useCallback)(
4776 (targetIndex, generateCompositeId) => {
4777 const clampedIndex = Math.min(
4778 data.length - 1,
4779 Math.max(0, targetIndex)
4780 );
4781 if (!data[clampedIndex]) {
4782 return;
4783 }
4784 const itemIdPrefix = generateCompositeItemIdPrefix(
4785 data[clampedIndex]
4786 );
4787 const targetCompositeItemId = generateCompositeId(itemIdPrefix);
4788 setActiveCompositeId(targetCompositeItemId);
4789 if (compositeRef.current?.contains(
4790 compositeRef.current.ownerDocument.activeElement
4791 )) {
4792 document.getElementById(targetCompositeItemId)?.focus();
4793 }
4794 },
4795 [data, generateCompositeItemIdPrefix]
4796 );
4797 (0, import_element16.useEffect)(() => {
4798 const wasActiveIdInList = previousActiveItemIndex !== void 0 && previousActiveItemIndex !== -1;
4799 if (!isActiveIdInList && wasActiveIdInList) {
4800 selectCompositeItem(
4801 previousActiveItemIndex,
4802 generateItemWrapperCompositeId
4803 );
4804 }
4805 }, [isActiveIdInList, selectCompositeItem, previousActiveItemIndex]);
4806 const onDropdownTriggerKeyDown = (0, import_element16.useCallback)(
4807 (event) => {
4808 if (event.key === "ArrowDown") {
4809 event.preventDefault();
4810 selectCompositeItem(
4811 activeItemIndex + 1,
4812 generateDropdownTriggerCompositeId
4813 );
4814 }
4815 if (event.key === "ArrowUp") {
4816 event.preventDefault();
4817 selectCompositeItem(
4818 activeItemIndex - 1,
4819 generateDropdownTriggerCompositeId
4820 );
4821 }
4822 },
4823 [selectCompositeItem, activeItemIndex]
4824 );
4825 const hasData = !!data?.length;
4826 const groupField = view.groupBy?.field ? fields.find((field) => field.id === view.groupBy?.field) : null;
4827 const dataByGroup = hasData && groupField ? getDataByGroup(data, groupField) : null;
4828 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
4829 if (!hasData) {
4830 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4831 "div",
4832 {
4833 className: clsx_default("dataviews-no-results", {
4834 "is-refreshing": isDelayedLoading
4835 }),
4836 children: empty
4837 }
4838 );
4839 }
4840 if (hasData && groupField && dataByGroup) {
4841 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4842 import_components10.Composite,
4843 {
4844 ref: compositeRef,
4845 id: `${baseId}`,
4846 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", {}),
4847 className: "dataviews-view-list__group",
4848 role: "grid",
4849 activeId: activeCompositeId,
4850 setActiveId: setActiveCompositeId,
4851 children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4852 Stack,
4853 {
4854 direction: "column",
4855 gap: "lg",
4856 className: clsx_default("dataviews-view-list", className),
4857 children: Array.from(dataByGroup.entries()).map(
4858 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4859 Stack,
4860 {
4861 direction: "column",
4862 gap: "sm",
4863 children: [
4864 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("h3", { className: "dataviews-view-list__group-header", children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n19.sprintf)(
4865 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
4866 (0, import_i18n19.__)("%1$s: %2$s"),
4867 groupField.label,
4868 groupName
4869 ) }),
4870 groupItems.map((item) => {
4871 const id = generateCompositeItemIdPrefix(item);
4872 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4873 ListItem,
4874 {
4875 view,
4876 idPrefix: id,
4877 actions,
4878 item,
4879 isSelected: item === selectedItem,
4880 onSelect,
4881 mediaField,
4882 titleField,
4883 descriptionField: descriptionField2,
4884 otherFields,
4885 onDropdownTriggerKeyDown
4886 },
4887 id
4888 );
4889 })
4890 ]
4891 },
4892 groupName
4893 )
4894 )
4895 }
4896 )
4897 }
4898 );
4899 }
4900 return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(import_jsx_runtime43.Fragment, { children: [
4901 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4902 import_components10.Composite,
4903 {
4904 ref: compositeRef,
4905 id: baseId,
4906 render: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", {}),
4907 className: clsx_default("dataviews-view-list", className, {
4908 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
4909 view.layout.density
4910 ),
4911 "is-refreshing": !isInfiniteScroll && isDelayedLoading
4912 }),
4913 role: view.infiniteScrollEnabled ? "feed" : "grid",
4914 activeId: activeCompositeId,
4915 setActiveId: setActiveCompositeId,
4916 inert: !isInfiniteScroll && !!isLoading ? "true" : void 0,
4917 children: data.map((item, index) => {
4918 const id = generateCompositeItemIdPrefix(item);
4919 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4920 ListItem,
4921 {
4922 view,
4923 idPrefix: id,
4924 actions,
4925 item,
4926 isSelected: item === selectedItem,
4927 onSelect,
4928 mediaField,
4929 titleField,
4930 descriptionField: descriptionField2,
4931 otherFields,
4932 onDropdownTriggerKeyDown,
4933 posinset: view.infiniteScrollEnabled ? index + 1 : void 0
4934 },
4935 id
4936 );
4937 })
4938 }
4939 ),
4940 isInfiniteScroll && isLoading && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(import_components10.Spinner, {}) })
4941 ] });
4942 }
4943
4944 // packages/dataviews/build-module/components/dataviews-layouts/activity/index.mjs
4945 var import_components12 = __toESM(require_components(), 1);
4946
4947 // packages/dataviews/build-module/components/dataviews-layouts/activity/activity-group.mjs
4948 var import_i18n20 = __toESM(require_i18n(), 1);
4949 var import_element17 = __toESM(require_element(), 1);
4950 var import_jsx_runtime44 = __toESM(require_jsx_runtime(), 1);
4951 function ActivityGroup({
4952 groupName,
4953 groupData,
4954 groupField,
4955 showLabel = true,
4956 children
4957 }) {
4958 const groupHeader = showLabel ? (0, import_element17.createInterpolateElement)(
4959 // translators: %s: The label of the field e.g. "Status".
4960 (0, import_i18n20.sprintf)((0, import_i18n20.__)("%s: <groupName />"), groupField.label).trim(),
4961 {
4962 groupName: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
4963 groupField.render,
4964 {
4965 item: groupData[0],
4966 field: groupField
4967 }
4968 )
4969 }
4970 ) : /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(groupField.render, { item: groupData[0], field: groupField });
4971 return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)(
4972 Stack,
4973 {
4974 direction: "column",
4975 className: "dataviews-view-activity__group",
4976 children: [
4977 /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("h3", { className: "dataviews-view-activity__group-header", children: groupHeader }),
4978 children
4979 ]
4980 },
4981 groupName
4982 );
4983 }
4984
4985 // packages/dataviews/build-module/components/dataviews-layouts/activity/activity-item.mjs
4986 var import_components11 = __toESM(require_components(), 1);
4987 var import_element18 = __toESM(require_element(), 1);
4988 var import_data4 = __toESM(require_data(), 1);
4989 var import_compose5 = __toESM(require_compose(), 1);
4990 var import_jsx_runtime45 = __toESM(require_jsx_runtime(), 1);
4991 function ActivityItem(props) {
4992 const {
4993 view,
4994 actions,
4995 item,
4996 titleField,
4997 mediaField,
4998 descriptionField: descriptionField2,
4999 otherFields,
5000 posinset,
5001 onClickItem,
5002 renderItemLink,
5003 isItemClickable: isItemClickable2
5004 } = props;
5005 const {
5006 showTitle = true,
5007 showMedia = true,
5008 showDescription = true,
5009 infiniteScrollEnabled
5010 } = view;
5011 const itemRef = (0, import_element18.useRef)(null);
5012 const registry = (0, import_data4.useRegistry)();
5013 const { paginationInfo } = (0, import_element18.useContext)(dataviews_context_default);
5014 const { primaryActions, eligibleActions } = (0, import_element18.useMemo)(() => {
5015 const _eligibleActions = actions.filter(
5016 (action) => !action.isEligible || action.isEligible(item)
5017 );
5018 const _primaryActions = _eligibleActions.filter(
5019 (action) => action.isPrimary
5020 );
5021 return {
5022 primaryActions: _primaryActions,
5023 eligibleActions: _eligibleActions
5024 };
5025 }, [actions, item]);
5026 const isMobileViewport = (0, import_compose5.useViewportMatch)("medium", "<");
5027 const density = view.layout?.density ?? "balanced";
5028 const mediaContent = showMedia && density !== "compact" && mediaField?.render ? /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5029 mediaField.render,
5030 {
5031 item,
5032 field: mediaField,
5033 config: {
5034 sizes: density === "comfortable" ? "32px" : "24px"
5035 }
5036 }
5037 ) : null;
5038 const renderedMediaField = /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-type-icon", children: mediaContent || /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5039 "span",
5040 {
5041 className: "dataviews-view-activity__item-bullet",
5042 "aria-hidden": "true"
5043 }
5044 ) });
5045 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(titleField.render, { item, field: titleField }) : null;
5046 const verticalGap = (0, import_element18.useMemo)(() => {
5047 switch (density) {
5048 case "comfortable":
5049 return "md";
5050 default:
5051 return "sm";
5052 }
5053 }, [density]);
5054 return /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5055 "div",
5056 {
5057 ref: itemRef,
5058 role: infiniteScrollEnabled ? "article" : void 0,
5059 "aria-posinset": posinset,
5060 "aria-setsize": infiniteScrollEnabled ? paginationInfo.totalItems : void 0,
5061 className: clsx_default(
5062 "dataviews-view-activity__item",
5063 density === "compact" && "is-compact",
5064 density === "balanced" && "is-balanced",
5065 density === "comfortable" && "is-comfortable"
5066 ),
5067 children: /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(Stack, { direction: "row", gap: "lg", justify: "start", align: "flex-start", children: [
5068 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5069 Stack,
5070 {
5071 direction: "column",
5072 gap: "xs",
5073 align: "center",
5074 className: "dataviews-view-activity__item-type",
5075 children: renderedMediaField
5076 }
5077 ),
5078 /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
5079 Stack,
5080 {
5081 direction: "column",
5082 gap: verticalGap,
5083 align: "flex-start",
5084 className: "dataviews-view-activity__item-content",
5085 children: [
5086 renderedTitleField && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5087 ItemClickWrapper,
5088 {
5089 item,
5090 isItemClickable: isItemClickable2,
5091 onClickItem,
5092 renderItemLink,
5093 className: "dataviews-view-activity__item-title",
5094 children: renderedTitleField
5095 }
5096 ),
5097 showDescription && descriptionField2 && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-description", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5098 descriptionField2.render,
5099 {
5100 item,
5101 field: descriptionField2
5102 }
5103 ) }),
5104 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-fields", children: otherFields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
5105 "div",
5106 {
5107 className: "dataviews-view-activity__item-field",
5108 children: [
5109 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5110 import_components11.VisuallyHidden,
5111 {
5112 as: "span",
5113 className: "dataviews-view-activity__item-field-label",
5114 children: field.label
5115 }
5116 ),
5117 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("span", { className: "dataviews-view-activity__item-field-value", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5118 field.render,
5119 {
5120 item,
5121 field
5122 }
5123 ) })
5124 ]
5125 },
5126 field.id
5127 )) }),
5128 !!primaryActions?.length && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5129 PrimaryActions,
5130 {
5131 item,
5132 actions: primaryActions,
5133 registry,
5134 buttonVariant: "secondary"
5135 }
5136 )
5137 ]
5138 }
5139 ),
5140 (primaryActions.length < eligibleActions.length || // Since we hide primary actions on mobile, we need to show the menu
5141 // there if there are any actions at all.
5142 isMobileViewport && // At the same time, only show the menu if there are actions to show.
5143 eligibleActions.length > 0) && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "dataviews-view-activity__item-actions", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5144 ItemActions,
5145 {
5146 item,
5147 actions: eligibleActions,
5148 isCompact: true
5149 }
5150 ) })
5151 ] })
5152 }
5153 );
5154 }
5155 var activity_item_default = ActivityItem;
5156
5157 // packages/dataviews/build-module/components/dataviews-layouts/activity/activity-items.mjs
5158 var import_react3 = __toESM(require_react(), 1);
5159 function isDefined3(item) {
5160 return !!item;
5161 }
5162 function ActivityItems(props) {
5163 const { data, fields, getItemId, view } = props;
5164 const titleField = fields.find((field) => field.id === view.titleField);
5165 const mediaField = fields.find((field) => field.id === view.mediaField);
5166 const descriptionField2 = fields.find(
5167 (field) => field.id === view.descriptionField
5168 );
5169 const otherFields = (view?.fields ?? []).map((fieldId) => fields.find((f2) => fieldId === f2.id)).filter(isDefined3);
5170 return data.map((item, index) => {
5171 return /* @__PURE__ */ (0, import_react3.createElement)(
5172 activity_item_default,
5173 {
5174 ...props,
5175 key: getItemId(item),
5176 item,
5177 mediaField,
5178 titleField,
5179 descriptionField: descriptionField2,
5180 otherFields,
5181 posinset: view.infiniteScrollEnabled ? index + 1 : void 0
5182 }
5183 );
5184 });
5185 }
5186
5187 // packages/dataviews/build-module/components/dataviews-layouts/activity/index.mjs
5188 var import_jsx_runtime46 = __toESM(require_jsx_runtime(), 1);
5189 function ViewActivity(props) {
5190 const { empty, data, fields, isLoading, view, className } = props;
5191 const isDelayedLoading = useDelayedLoading(!!isLoading);
5192 const hasData = !!data?.length;
5193 const groupField = view.groupBy?.field ? fields.find((field) => field.id === view.groupBy?.field) : null;
5194 const dataByGroup = hasData && groupField ? getDataByGroup(data, groupField) : null;
5195 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
5196 if (!hasData) {
5197 return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5198 "div",
5199 {
5200 className: clsx_default("dataviews-no-results", {
5201 "is-refreshing": isDelayedLoading
5202 }),
5203 children: empty
5204 }
5205 );
5206 }
5207 const isInert = !isInfiniteScroll && !!isLoading;
5208 const wrapperClassName = clsx_default("dataviews-view-activity", className, {
5209 "is-refreshing": !isInfiniteScroll && isDelayedLoading
5210 });
5211 const groupedEntries = dataByGroup ? Array.from(dataByGroup.entries()) : [];
5212 if (hasData && groupField && dataByGroup) {
5213 return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5214 Stack,
5215 {
5216 direction: "column",
5217 gap: "sm",
5218 className: wrapperClassName,
5219 inert: isInert ? "true" : void 0,
5220 children: groupedEntries.map(
5221 ([groupName, groupData]) => /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5222 ActivityGroup,
5223 {
5224 groupName,
5225 groupData,
5226 groupField,
5227 showLabel: view.groupBy?.showLabel !== false,
5228 children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5229 ActivityItems,
5230 {
5231 ...props,
5232 data: groupData
5233 }
5234 )
5235 },
5236 groupName
5237 )
5238 )
5239 }
5240 );
5241 }
5242 return /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)(import_jsx_runtime46.Fragment, { children: [
5243 /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5244 "div",
5245 {
5246 className: wrapperClassName,
5247 role: view.infiniteScrollEnabled ? "feed" : void 0,
5248 inert: isInert ? "true" : void 0,
5249 children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(ActivityItems, { ...props })
5250 }
5251 ),
5252 isInfiniteScroll && isLoading && /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(import_components12.Spinner, {}) })
5253 ] });
5254 }
5255
5256 // packages/dataviews/build-module/components/dataviews-layouts/picker-grid/index.mjs
5257 var import_components15 = __toESM(require_components(), 1);
5258 var import_i18n23 = __toESM(require_i18n(), 1);
5259 var import_compose6 = __toESM(require_compose(), 1);
5260 var import_element21 = __toESM(require_element(), 1);
5261
5262 // packages/dataviews/build-module/components/dataviews-picker-footer/index.mjs
5263 var import_components14 = __toESM(require_components(), 1);
5264 var import_data5 = __toESM(require_data(), 1);
5265 var import_element20 = __toESM(require_element(), 1);
5266 var import_i18n22 = __toESM(require_i18n(), 1);
5267
5268 // packages/dataviews/build-module/components/dataviews-pagination/index.mjs
5269 var import_components13 = __toESM(require_components(), 1);
5270 var import_element19 = __toESM(require_element(), 1);
5271 var import_i18n21 = __toESM(require_i18n(), 1);
5272 var import_jsx_runtime47 = __toESM(require_jsx_runtime(), 1);
5273 function DataViewsPagination() {
5274 const {
5275 view,
5276 onChangeView,
5277 paginationInfo: { totalItems = 0, totalPages }
5278 } = (0, import_element19.useContext)(dataviews_context_default);
5279 if (!totalItems || !totalPages || view.infiniteScrollEnabled) {
5280 return null;
5281 }
5282 const currentPage = view.page ?? 1;
5283 const pageSelectOptions = Array.from(Array(totalPages)).map(
5284 (_, i2) => {
5285 const page = i2 + 1;
5286 return {
5287 value: page.toString(),
5288 label: page.toString(),
5289 "aria-label": currentPage === page ? (0, import_i18n21.sprintf)(
5290 // translators: 1: current page number. 2: total number of pages.
5291 (0, import_i18n21.__)("Page %1$d of %2$d"),
5292 currentPage,
5293 totalPages
5294 ) : page.toString()
5295 };
5296 }
5297 );
5298 return !!totalItems && totalPages !== 1 && /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(
5299 Stack,
5300 {
5301 direction: "row",
5302 className: "dataviews-pagination",
5303 justify: "end",
5304 align: "center",
5305 gap: "xl",
5306 children: [
5307 /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5308 Stack,
5309 {
5310 direction: "row",
5311 justify: "flex-start",
5312 align: "center",
5313 gap: "xs",
5314 className: "dataviews-pagination__page-select",
5315 children: (0, import_element19.createInterpolateElement)(
5316 (0, import_i18n21.sprintf)(
5317 // translators: 1: Current page number, 2: Total number of pages.
5318 (0, import_i18n21._x)(
5319 "<div>Page</div>%1$s<div>of %2$d</div>",
5320 "paging"
5321 ),
5322 "<CurrentPage />",
5323 totalPages
5324 ),
5325 {
5326 div: /* @__PURE__ */ (0, import_jsx_runtime47.jsx)("div", { "aria-hidden": true }),
5327 // @ts-expect-error — Tag injected via sprintf argument, not visible in format string.
5328 CurrentPage: /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5329 import_components13.SelectControl,
5330 {
5331 "aria-label": (0, import_i18n21.__)("Current page"),
5332 value: currentPage.toString(),
5333 options: pageSelectOptions,
5334 onChange: (newValue) => {
5335 onChangeView({
5336 ...view,
5337 page: +newValue
5338 });
5339 },
5340 size: "small",
5341 variant: "minimal"
5342 }
5343 )
5344 }
5345 )
5346 }
5347 ),
5348 /* @__PURE__ */ (0, import_jsx_runtime47.jsxs)(Stack, { direction: "row", gap: "xs", align: "center", children: [
5349 /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5350 import_components13.Button,
5351 {
5352 onClick: () => onChangeView({
5353 ...view,
5354 page: currentPage - 1
5355 }),
5356 disabled: currentPage === 1,
5357 accessibleWhenDisabled: true,
5358 label: (0, import_i18n21.__)("Previous page"),
5359 icon: (0, import_i18n21.isRTL)() ? next_default : previous_default,
5360 showTooltip: true,
5361 size: "compact",
5362 tooltipPosition: "top"
5363 }
5364 ),
5365 /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5366 import_components13.Button,
5367 {
5368 onClick: () => onChangeView({ ...view, page: currentPage + 1 }),
5369 disabled: currentPage >= totalPages,
5370 accessibleWhenDisabled: true,
5371 label: (0, import_i18n21.__)("Next page"),
5372 icon: (0, import_i18n21.isRTL)() ? previous_default : next_default,
5373 showTooltip: true,
5374 size: "compact",
5375 tooltipPosition: "top"
5376 }
5377 )
5378 ] })
5379 ]
5380 }
5381 );
5382 }
5383 var dataviews_pagination_default = (0, import_element19.memo)(DataViewsPagination);
5384
5385 // packages/dataviews/build-module/components/dataviews-picker-footer/index.mjs
5386 var import_jsx_runtime48 = __toESM(require_jsx_runtime(), 1);
5387 var EMPTY_ARRAY2 = [];
5388 function useIsMultiselectPicker(actions) {
5389 return (0, import_element20.useMemo)(() => {
5390 return actions?.every((action) => action.supportsBulk);
5391 }, [actions]);
5392 }
5393 function BulkSelectionCheckbox2({
5394 selection,
5395 selectedItems,
5396 onChangeSelection,
5397 data,
5398 getItemId,
5399 disableSelectAll = false
5400 }) {
5401 const hasSelection = selection.length > 0;
5402 const areAllSelected = selectedItems.length === data.length;
5403 if (disableSelectAll) {
5404 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5405 import_components14.CheckboxControl,
5406 {
5407 className: "dataviews-view-table-selection-checkbox",
5408 checked: hasSelection,
5409 disabled: !hasSelection,
5410 onChange: () => {
5411 onChangeSelection([]);
5412 },
5413 "aria-label": (0, import_i18n22.__)("Deselect all")
5414 }
5415 );
5416 }
5417 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5418 import_components14.CheckboxControl,
5419 {
5420 className: "dataviews-view-table-selection-checkbox",
5421 checked: areAllSelected,
5422 indeterminate: !areAllSelected && !!selectedItems.length,
5423 onChange: () => {
5424 if (areAllSelected) {
5425 onChangeSelection(
5426 selection.filter(
5427 (id) => !data.some(
5428 (item) => id === getItemId(item)
5429 )
5430 )
5431 );
5432 } else {
5433 const selectionSet = /* @__PURE__ */ new Set([
5434 ...selection,
5435 ...data.map((item) => getItemId(item))
5436 ]);
5437 onChangeSelection(Array.from(selectionSet));
5438 }
5439 },
5440 "aria-label": areAllSelected ? (0, import_i18n22.__)("Deselect all") : (0, import_i18n22.__)("Select all")
5441 }
5442 );
5443 }
5444 function ActionButtons({
5445 actions,
5446 items,
5447 selection
5448 }) {
5449 const registry = (0, import_data5.useRegistry)();
5450 const [actionInProgress, setActionInProgress] = (0, import_element20.useState)(
5451 null
5452 );
5453 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(Stack, { direction: "row", gap: "xs", children: actions.map((action) => {
5454 if (!("callback" in action)) {
5455 return null;
5456 }
5457 const { id, label, icon, isPrimary, callback } = action;
5458 const _label = typeof label === "string" ? label : label(items);
5459 const variant = isPrimary ? "primary" : "tertiary";
5460 const isInProgress = id === actionInProgress;
5461 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5462 import_components14.Button,
5463 {
5464 accessibleWhenDisabled: true,
5465 icon,
5466 disabled: isInProgress || !selection?.length,
5467 isBusy: isInProgress,
5468 onClick: async () => {
5469 setActionInProgress(id);
5470 await callback(items, {
5471 registry
5472 });
5473 setActionInProgress(null);
5474 },
5475 size: "compact",
5476 variant,
5477 children: _label
5478 },
5479 id
5480 );
5481 }) });
5482 }
5483 function DataViewsPickerFooter() {
5484 const {
5485 data,
5486 selection,
5487 onChangeSelection,
5488 getItemId,
5489 actions = EMPTY_ARRAY2,
5490 paginationInfo,
5491 view
5492 } = (0, import_element20.useContext)(dataviews_context_default);
5493 const isMultiselect = useIsMultiselectPicker(actions);
5494 const message2 = getFooterMessage(
5495 selection.length,
5496 data.length,
5497 paginationInfo.totalItems,
5498 !!view.infiniteScrollEnabled
5499 );
5500 const selectedItems = (0, import_element20.useMemo)(
5501 () => data.filter((item) => selection.includes(getItemId(item))),
5502 [selection, getItemId, data]
5503 );
5504 return /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(
5505 Stack,
5506 {
5507 direction: "row",
5508 justify: "space-between",
5509 align: "center",
5510 className: "dataviews-footer",
5511 gap: "sm",
5512 children: [
5513 /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(
5514 Stack,
5515 {
5516 direction: "row",
5517 className: "dataviews-picker-footer__bulk-selection",
5518 gap: "md",
5519 align: "center",
5520 children: [
5521 isMultiselect && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5522 BulkSelectionCheckbox2,
5523 {
5524 selection,
5525 selectedItems,
5526 onChangeSelection,
5527 data,
5528 getItemId,
5529 disableSelectAll: !!view.infiniteScrollEnabled
5530 }
5531 ),
5532 /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("span", { className: "dataviews-bulk-actions-footer__item-count", children: message2 })
5533 ]
5534 }
5535 ),
5536 /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(dataviews_pagination_default, {}),
5537 Boolean(actions?.length) && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("div", { className: "dataviews-picker-footer__actions", children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5538 ActionButtons,
5539 {
5540 actions,
5541 items: selectedItems,
5542 selection
5543 }
5544 ) })
5545 ]
5546 }
5547 );
5548 }
5549
5550 // packages/dataviews/build-module/components/dataviews-layouts/picker-grid/index.mjs
5551 var import_jsx_runtime49 = __toESM(require_jsx_runtime(), 1);
5552 var { Badge: Badge2 } = unlock(import_components15.privateApis);
5553 function GridItem3({
5554 view,
5555 multiselect,
5556 selection,
5557 onChangeSelection,
5558 getItemId,
5559 item,
5560 mediaField,
5561 titleField,
5562 descriptionField: descriptionField2,
5563 regularFields,
5564 badgeFields,
5565 config,
5566 posinset,
5567 setsize
5568 }) {
5569 const { showTitle = true, showMedia = true, showDescription = true } = view;
5570 const id = getItemId(item);
5571 const elementRef = (0, import_element21.useRef)(null);
5572 const isSelected2 = selection.includes(id);
5573 useIntersectionObserver(elementRef, posinset);
5574 const renderedMediaField = mediaField?.render ? /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5575 mediaField.render,
5576 {
5577 item,
5578 field: mediaField,
5579 config
5580 }
5581 ) : null;
5582 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(titleField.render, { item, field: titleField }) : null;
5583 return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5584 import_components15.Composite.Item,
5585 {
5586 ref: elementRef,
5587 "aria-label": titleField ? titleField.getValue({ item }) || (0, import_i18n23.__)("(no title)") : void 0,
5588 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack, { direction: "column", children, ...props }),
5589 role: "option",
5590 "aria-posinset": posinset,
5591 "aria-setsize": setsize,
5592 className: clsx_default("dataviews-view-picker-grid__card", {
5593 "is-selected": isSelected2
5594 }),
5595 "aria-selected": isSelected2,
5596 onClick: () => {
5597 if (isSelected2) {
5598 onChangeSelection(
5599 selection.filter((itemId) => id !== itemId)
5600 );
5601 } else {
5602 const newSelection = multiselect ? [...selection, id] : [id];
5603 onChangeSelection(newSelection);
5604 }
5605 },
5606 children: [
5607 showMedia && renderedMediaField && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { className: "dataviews-view-picker-grid__media", children: renderedMediaField }),
5608 showMedia && renderedMediaField && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5609 DataViewsSelectionCheckbox,
5610 {
5611 item,
5612 selection,
5613 onChangeSelection,
5614 getItemId,
5615 titleField,
5616 disabled: false,
5617 "aria-hidden": true,
5618 tabIndex: -1
5619 }
5620 ),
5621 showTitle && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5622 Stack,
5623 {
5624 direction: "row",
5625 justify: "space-between",
5626 className: "dataviews-view-picker-grid__title-actions",
5627 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { className: "dataviews-view-picker-grid__title-field dataviews-title-field", children: renderedTitleField })
5628 }
5629 ),
5630 /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(Stack, { direction: "column", gap: "xs", children: [
5631 showDescription && descriptionField2?.render && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5632 descriptionField2.render,
5633 {
5634 item,
5635 field: descriptionField2
5636 }
5637 ),
5638 !!badgeFields?.length && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5639 Stack,
5640 {
5641 direction: "row",
5642 className: "dataviews-view-picker-grid__badge-fields",
5643 gap: "sm",
5644 wrap: "wrap",
5645 align: "top",
5646 justify: "flex-start",
5647 children: badgeFields.map((field) => {
5648 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5649 Badge2,
5650 {
5651 className: "dataviews-view-picker-grid__field-value",
5652 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5653 field.render,
5654 {
5655 item,
5656 field
5657 }
5658 )
5659 },
5660 field.id
5661 );
5662 })
5663 }
5664 ),
5665 !!regularFields?.length && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5666 Stack,
5667 {
5668 direction: "column",
5669 className: "dataviews-view-picker-grid__fields",
5670 gap: "xs",
5671 children: regularFields.map((field) => {
5672 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5673 import_components15.Flex,
5674 {
5675 className: "dataviews-view-picker-grid__field",
5676 gap: 1,
5677 justify: "flex-start",
5678 expanded: true,
5679 style: { height: "auto" },
5680 direction: "row",
5681 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(import_jsx_runtime49.Fragment, { children: [
5682 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_components15.FlexItem, { className: "dataviews-view-picker-grid__field-name", children: field.header }),
5683 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5684 import_components15.FlexItem,
5685 {
5686 className: "dataviews-view-picker-grid__field-value",
5687 style: { maxHeight: "none" },
5688 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5689 field.render,
5690 {
5691 item,
5692 field
5693 }
5694 )
5695 }
5696 )
5697 ] })
5698 },
5699 field.id
5700 );
5701 })
5702 }
5703 )
5704 ] })
5705 ]
5706 },
5707 id
5708 );
5709 }
5710 function GridGroup({
5711 groupName,
5712 groupField,
5713 showLabel = true,
5714 children
5715 }) {
5716 const headerId = (0, import_compose6.useInstanceId)(
5717 GridGroup,
5718 "dataviews-view-picker-grid-group__header"
5719 );
5720 return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5721 Stack,
5722 {
5723 direction: "column",
5724 gap: "sm",
5725 role: "group",
5726 "aria-labelledby": headerId,
5727 children: [
5728 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5729 "h3",
5730 {
5731 className: "dataviews-view-picker-grid-group__header",
5732 id: headerId,
5733 children: showLabel ? (0, import_i18n23.sprintf)(
5734 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
5735 (0, import_i18n23.__)("%1$s: %2$s"),
5736 groupField.label,
5737 groupName
5738 ) : groupName
5739 }
5740 ),
5741 children
5742 ]
5743 },
5744 groupName
5745 );
5746 }
5747 function ViewPickerGrid({
5748 actions,
5749 data,
5750 fields,
5751 getItemId,
5752 isLoading,
5753 onChangeSelection,
5754 selection,
5755 view,
5756 className,
5757 empty
5758 }) {
5759 const { resizeObserverRef, paginationInfo, itemListLabel } = (0, import_element21.useContext)(dataviews_context_default);
5760 const titleField = fields.find(
5761 (field) => field.id === view?.titleField
5762 );
5763 const mediaField = fields.find(
5764 (field) => field.id === view?.mediaField
5765 );
5766 const descriptionField2 = fields.find(
5767 (field) => field.id === view?.descriptionField
5768 );
5769 const otherFields = view.fields ?? [];
5770 const { regularFields, badgeFields } = otherFields.reduce(
5771 (accumulator, fieldId) => {
5772 const field = fields.find((f2) => f2.id === fieldId);
5773 if (!field) {
5774 return accumulator;
5775 }
5776 const key = view.layout?.badgeFields?.includes(fieldId) ? "badgeFields" : "regularFields";
5777 accumulator[key].push(field);
5778 return accumulator;
5779 },
5780 { regularFields: [], badgeFields: [] }
5781 );
5782 const hasData = !!data?.length;
5783 const usedPreviewSize = view.layout?.previewSize;
5784 const isMultiselect = useIsMultiselectPicker(actions);
5785 const size = "900px";
5786 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
5787 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
5788 const isInfiniteScroll = (view.infiniteScrollEnabled && !dataByGroup) ?? false;
5789 const currentPage = view?.page ?? 1;
5790 const perPage = view?.perPage ?? 0;
5791 const setSize = isInfiniteScroll ? paginationInfo?.totalItems : void 0;
5792 const gridColumns = useGridColumns();
5793 const placeholdersNeeded = usePlaceholdersNeeded(
5794 data,
5795 isInfiniteScroll,
5796 gridColumns
5797 );
5798 return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(import_jsx_runtime49.Fragment, {
5799 // Render multiple groups.
5800 children: [
5801 hasData && groupField && dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5802 import_components15.Composite,
5803 {
5804 virtualFocus: true,
5805 orientation: "horizontal",
5806 role: "listbox",
5807 "aria-multiselectable": isMultiselect,
5808 className: clsx_default(
5809 "dataviews-view-picker-grid",
5810 className,
5811 {
5812 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
5813 view.layout.density
5814 )
5815 }
5816 ),
5817 "aria-label": itemListLabel,
5818 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5819 Stack,
5820 {
5821 direction: "column",
5822 gap: "lg",
5823 children,
5824 ...props
5825 }
5826 ),
5827 children: Array.from(dataByGroup.entries()).map(
5828 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5829 GridGroup,
5830 {
5831 groupName,
5832 groupField,
5833 showLabel: view.groupBy?.showLabel !== false,
5834 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5835 GridItems,
5836 {
5837 previewSize: usedPreviewSize,
5838 style: {
5839 gridTemplateColumns: usedPreviewSize && `repeat(auto-fill, minmax(${usedPreviewSize}px, 1fr))`
5840 },
5841 "aria-busy": isLoading,
5842 ref: resizeObserverRef,
5843 children: groupItems.map((item) => {
5844 const posInSet = item.position ?? (currentPage - 1) * perPage + data.indexOf(item) + 1;
5845 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5846 GridItem3,
5847 {
5848 view,
5849 multiselect: isMultiselect,
5850 selection,
5851 onChangeSelection,
5852 getItemId,
5853 item,
5854 mediaField,
5855 titleField,
5856 descriptionField: descriptionField2,
5857 regularFields,
5858 badgeFields,
5859 config: {
5860 sizes: size
5861 },
5862 posinset: posInSet,
5863 setsize: setSize
5864 },
5865 getItemId(item)
5866 );
5867 })
5868 }
5869 )
5870 },
5871 groupName
5872 )
5873 )
5874 }
5875 ),
5876 // Render a single grid with all data.
5877 hasData && !dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5878 import_components15.Composite,
5879 {
5880 render: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5881 GridItems,
5882 {
5883 className: clsx_default(
5884 "dataviews-view-picker-grid",
5885 className,
5886 {
5887 [`has-${view.layout?.density}-density`]: view.layout?.density && [
5888 "compact",
5889 "comfortable"
5890 ].includes(view.layout.density)
5891 }
5892 ),
5893 previewSize: usedPreviewSize,
5894 "aria-busy": isLoading,
5895 ref: resizeObserverRef
5896 }
5897 ),
5898 virtualFocus: true,
5899 orientation: "horizontal",
5900 role: "listbox",
5901 "aria-multiselectable": isMultiselect,
5902 "aria-label": itemListLabel,
5903 children: [
5904 Array.from({ length: placeholdersNeeded }).map(
5905 (_, index) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5906 import_components15.Composite.Item,
5907 {
5908 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5909 Stack,
5910 {
5911 direction: "column",
5912 children,
5913 ...props
5914 }
5915 ),
5916 role: "option",
5917 "aria-hidden": true,
5918 tabIndex: -1,
5919 className: "dataviews-view-picker-grid__card dataviews-view-picker-grid__placeholder"
5920 },
5921 `placeholder-${index}`
5922 )
5923 ),
5924 data.map((item) => {
5925 const posinset = item.position;
5926 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5927 GridItem3,
5928 {
5929 view,
5930 multiselect: isMultiselect,
5931 selection,
5932 onChangeSelection,
5933 getItemId,
5934 item,
5935 mediaField,
5936 titleField,
5937 descriptionField: descriptionField2,
5938 regularFields,
5939 badgeFields,
5940 config: {
5941 sizes: size
5942 },
5943 posinset,
5944 setsize: setSize
5945 },
5946 getItemId(item)
5947 );
5948 })
5949 ]
5950 }
5951 ),
5952 // Render empty state.
5953 !hasData && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5954 "div",
5955 {
5956 className: clsx_default({
5957 "dataviews-loading": isLoading,
5958 "dataviews-no-results": !isLoading
5959 }),
5960 children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_components15.Spinner, {}) }) : empty
5961 }
5962 ),
5963 hasData && isLoading && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_components15.Spinner, {}) })
5964 ]
5965 });
5966 }
5967 var picker_grid_default = ViewPickerGrid;
5968
5969 // packages/dataviews/build-module/components/dataviews-layouts/picker-table/index.mjs
5970 var import_i18n24 = __toESM(require_i18n(), 1);
5971 var import_components16 = __toESM(require_components(), 1);
5972 var import_element22 = __toESM(require_element(), 1);
5973 var import_jsx_runtime50 = __toESM(require_jsx_runtime(), 1);
5974 function TableColumnField2({
5975 item,
5976 fields,
5977 column,
5978 align
5979 }) {
5980 const field = fields.find((f2) => f2.id === column);
5981 if (!field) {
5982 return null;
5983 }
5984 const className = clsx_default("dataviews-view-table__cell-content-wrapper", {
5985 "dataviews-view-table__cell-align-end": align === "end",
5986 "dataviews-view-table__cell-align-center": align === "center"
5987 });
5988 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(field.render, { item, field }) });
5989 }
5990 function TableRow2({
5991 item,
5992 fields,
5993 id,
5994 view,
5995 titleField,
5996 mediaField,
5997 descriptionField: descriptionField2,
5998 selection,
5999 getItemId,
6000 onChangeSelection,
6001 multiselect,
6002 posinset
6003 }) {
6004 const { paginationInfo } = (0, import_element22.useContext)(dataviews_context_default);
6005 const isSelected2 = selection.includes(id);
6006 const [isHovered, setIsHovered] = (0, import_element22.useState)(false);
6007 const elementRef = (0, import_element22.useRef)(null);
6008 useIntersectionObserver(elementRef, posinset);
6009 const {
6010 showTitle = true,
6011 showMedia = true,
6012 showDescription = true,
6013 infiniteScrollEnabled
6014 } = view;
6015 const handleMouseEnter = () => {
6016 setIsHovered(true);
6017 };
6018 const handleMouseLeave = () => {
6019 setIsHovered(false);
6020 };
6021 const columns = view.fields ?? [];
6022 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
6023 return /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6024 import_components16.Composite.Item,
6025 {
6026 ref: elementRef,
6027 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6028 "tr",
6029 {
6030 className: clsx_default("dataviews-view-table__row", {
6031 "is-selected": isSelected2,
6032 "is-hovered": isHovered
6033 }),
6034 onMouseEnter: handleMouseEnter,
6035 onMouseLeave: handleMouseLeave,
6036 children,
6037 ...props
6038 }
6039 ),
6040 "aria-selected": isSelected2,
6041 "aria-setsize": paginationInfo.totalItems || void 0,
6042 "aria-posinset": posinset,
6043 role: infiniteScrollEnabled ? "article" : "option",
6044 onClick: () => {
6045 if (isSelected2) {
6046 onChangeSelection(
6047 selection.filter((itemId) => id !== itemId)
6048 );
6049 } else {
6050 const newSelection = multiselect ? [...selection, id] : [id];
6051 onChangeSelection(newSelection);
6052 }
6053 },
6054 children: [
6055 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6056 "td",
6057 {
6058 className: "dataviews-view-table__checkbox-column",
6059 role: "presentation",
6060 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("div", { className: "dataviews-view-table__cell-content-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6061 DataViewsSelectionCheckbox,
6062 {
6063 item,
6064 selection,
6065 onChangeSelection,
6066 getItemId,
6067 titleField,
6068 disabled: false,
6069 "aria-hidden": true,
6070 tabIndex: -1
6071 }
6072 ) })
6073 }
6074 ),
6075 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6076 "td",
6077 {
6078 role: "presentation",
6079 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6080 column_primary_default,
6081 {
6082 item,
6083 titleField: showTitle ? titleField : void 0,
6084 mediaField: showMedia ? mediaField : void 0,
6085 descriptionField: showDescription ? descriptionField2 : void 0,
6086 isItemClickable: () => false
6087 }
6088 )
6089 }
6090 ),
6091 columns.map((column) => {
6092 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
6093 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6094 "td",
6095 {
6096 style: {
6097 width,
6098 maxWidth,
6099 minWidth
6100 },
6101 role: "presentation",
6102 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6103 TableColumnField2,
6104 {
6105 fields,
6106 item,
6107 column,
6108 align
6109 }
6110 )
6111 },
6112 column
6113 );
6114 })
6115 ]
6116 },
6117 id
6118 );
6119 }
6120 function ViewPickerTable({
6121 actions,
6122 data,
6123 fields,
6124 getItemId,
6125 isLoading = false,
6126 onChangeView,
6127 onChangeSelection,
6128 selection,
6129 setOpenedFilter,
6130 view,
6131 className,
6132 empty
6133 }) {
6134 const headerMenuRefs = (0, import_element22.useRef)(/* @__PURE__ */ new Map());
6135 const headerMenuToFocusRef = (0, import_element22.useRef)(void 0);
6136 const [nextHeaderMenuToFocus, setNextHeaderMenuToFocus] = (0, import_element22.useState)();
6137 const isMultiselect = useIsMultiselectPicker(actions) ?? false;
6138 (0, import_element22.useEffect)(() => {
6139 if (headerMenuToFocusRef.current) {
6140 headerMenuToFocusRef.current.focus();
6141 headerMenuToFocusRef.current = void 0;
6142 }
6143 });
6144 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
6145 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
6146 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
6147 const tableNoticeId = (0, import_element22.useId)();
6148 if (nextHeaderMenuToFocus) {
6149 headerMenuToFocusRef.current = nextHeaderMenuToFocus;
6150 setNextHeaderMenuToFocus(void 0);
6151 return;
6152 }
6153 const onHide = (field) => {
6154 const hidden = headerMenuRefs.current.get(field.id);
6155 const fallback = hidden ? headerMenuRefs.current.get(hidden.fallback) : void 0;
6156 setNextHeaderMenuToFocus(fallback?.node);
6157 };
6158 const hasData = !!data?.length;
6159 const titleField = fields.find((field) => field.id === view.titleField);
6160 const mediaField = fields.find((field) => field.id === view.mediaField);
6161 const descriptionField2 = fields.find(
6162 (field) => field.id === view.descriptionField
6163 );
6164 const { showTitle = true, showMedia = true, showDescription = true } = view;
6165 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
6166 const columns = view.fields ?? [];
6167 const headerMenuRef = (column, index) => (node) => {
6168 if (node) {
6169 headerMenuRefs.current.set(column, {
6170 node,
6171 fallback: columns[index > 0 ? index - 1 : 1]
6172 });
6173 } else {
6174 headerMenuRefs.current.delete(column);
6175 }
6176 };
6177 return /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(import_jsx_runtime50.Fragment, { children: [
6178 /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6179 "table",
6180 {
6181 className: clsx_default(
6182 "dataviews-view-table",
6183 "dataviews-view-picker-table",
6184 className,
6185 {
6186 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
6187 view.layout.density
6188 )
6189 }
6190 ),
6191 "aria-busy": isLoading,
6192 "aria-describedby": tableNoticeId,
6193 role: isInfiniteScroll ? "feed" : "listbox",
6194 children: [
6195 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("thead", { role: "presentation", children: /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6196 "tr",
6197 {
6198 className: "dataviews-view-table__row",
6199 role: "presentation",
6200 children: [
6201 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("th", { className: "dataviews-view-table__checkbox-column", children: isMultiselect && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6202 BulkSelectionCheckbox,
6203 {
6204 selection,
6205 onChangeSelection,
6206 data,
6207 actions,
6208 getItemId,
6209 disableSelectAll: isInfiniteScroll
6210 }
6211 ) }),
6212 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("th", { children: titleField && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6213 column_header_menu_default,
6214 {
6215 ref: headerMenuRef(
6216 titleField.id,
6217 0
6218 ),
6219 fieldId: titleField.id,
6220 view,
6221 fields,
6222 onChangeView,
6223 onHide,
6224 setOpenedFilter,
6225 canMove: false
6226 }
6227 ) }),
6228 columns.map((column, index) => {
6229 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
6230 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6231 "th",
6232 {
6233 style: {
6234 width,
6235 maxWidth,
6236 minWidth,
6237 textAlign: align
6238 },
6239 "aria-sort": view.sort?.direction && view.sort?.field === column ? sortValues[view.sort.direction] : void 0,
6240 scope: "col",
6241 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6242 column_header_menu_default,
6243 {
6244 ref: headerMenuRef(column, index),
6245 fieldId: column,
6246 view,
6247 fields,
6248 onChangeView,
6249 onHide,
6250 setOpenedFilter,
6251 canMove: view.layout?.enableMoving ?? true
6252 }
6253 )
6254 },
6255 column
6256 );
6257 })
6258 ]
6259 }
6260 ) }),
6261 hasData && groupField && dataByGroup ? Array.from(dataByGroup.entries()).map(
6262 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6263 import_components16.Composite,
6264 {
6265 virtualFocus: true,
6266 orientation: "vertical",
6267 render: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("tbody", { role: "group" }),
6268 children: [
6269 /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6270 "tr",
6271 {
6272 className: "dataviews-view-table__group-header-row",
6273 role: "presentation",
6274 children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6275 "td",
6276 {
6277 colSpan: columns.length + (hasPrimaryColumn ? 1 : 0) + 1,
6278 className: "dataviews-view-table__group-header-cell",
6279 role: "presentation",
6280 children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n24.sprintf)(
6281 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
6282 (0, import_i18n24.__)("%1$s: %2$s"),
6283 groupField.label,
6284 groupName
6285 )
6286 }
6287 )
6288 }
6289 ),
6290 groupItems.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6291 TableRow2,
6292 {
6293 item,
6294 fields,
6295 id: getItemId(item) || index.toString(),
6296 view,
6297 titleField,
6298 mediaField,
6299 descriptionField: descriptionField2,
6300 selection,
6301 getItemId,
6302 onChangeSelection,
6303 multiselect: isMultiselect
6304 },
6305 getItemId(item)
6306 ))
6307 ]
6308 },
6309 `group-${groupName}`
6310 )
6311 ) : /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6312 import_components16.Composite,
6313 {
6314 render: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("tbody", { role: "presentation" }),
6315 virtualFocus: true,
6316 orientation: "vertical",
6317 children: hasData && data.map((item, index) => {
6318 const itemId = getItemId(item);
6319 const posinset = item.position;
6320 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6321 TableRow2,
6322 {
6323 item,
6324 fields,
6325 id: itemId || index.toString(),
6326 view,
6327 titleField,
6328 mediaField,
6329 descriptionField: descriptionField2,
6330 selection,
6331 getItemId,
6332 onChangeSelection,
6333 multiselect: isMultiselect,
6334 posinset
6335 },
6336 itemId
6337 );
6338 })
6339 }
6340 )
6341 ]
6342 }
6343 ),
6344 /* @__PURE__ */ (0, import_jsx_runtime50.jsxs)(
6345 "div",
6346 {
6347 className: clsx_default({
6348 "dataviews-loading": isLoading,
6349 "dataviews-no-results": !hasData && !isLoading
6350 }),
6351 id: tableNoticeId,
6352 children: [
6353 !hasData && (isLoading ? /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(import_components16.Spinner, {}) }) : empty),
6354 hasData && isLoading && /* @__PURE__ */ (0, import_jsx_runtime50.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(import_components16.Spinner, {}) })
6355 ]
6356 }
6357 )
6358 ] });
6359 }
6360 var picker_table_default = ViewPickerTable;
6361
6362 // packages/dataviews/build-module/components/dataviews-layouts/utils/density-picker.mjs
6363 var import_components17 = __toESM(require_components(), 1);
6364 var import_i18n25 = __toESM(require_i18n(), 1);
6365 var import_element23 = __toESM(require_element(), 1);
6366 var import_jsx_runtime51 = __toESM(require_jsx_runtime(), 1);
6367 function DensityPicker() {
6368 const context = (0, import_element23.useContext)(dataviews_context_default);
6369 const view = context.view;
6370 return /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)(
6371 import_components17.__experimentalToggleGroupControl,
6372 {
6373 size: "__unstable-large",
6374 label: (0, import_i18n25.__)("Density"),
6375 value: view.layout?.density || "balanced",
6376 onChange: (value) => {
6377 context.onChangeView({
6378 ...view,
6379 layout: {
6380 ...view.layout,
6381 density: value
6382 }
6383 });
6384 },
6385 isBlock: true,
6386 children: [
6387 /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
6388 import_components17.__experimentalToggleGroupControlOption,
6389 {
6390 value: "comfortable",
6391 label: (0, import_i18n25._x)(
6392 "Comfortable",
6393 "Density option for DataView layout"
6394 )
6395 },
6396 "comfortable"
6397 ),
6398 /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
6399 import_components17.__experimentalToggleGroupControlOption,
6400 {
6401 value: "balanced",
6402 label: (0, import_i18n25._x)("Balanced", "Density option for DataView layout")
6403 },
6404 "balanced"
6405 ),
6406 /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
6407 import_components17.__experimentalToggleGroupControlOption,
6408 {
6409 value: "compact",
6410 label: (0, import_i18n25._x)("Compact", "Density option for DataView layout")
6411 },
6412 "compact"
6413 )
6414 ]
6415 }
6416 );
6417 }
6418
6419 // packages/dataviews/build-module/components/dataviews-layouts/utils/preview-size-picker.mjs
6420 var import_components18 = __toESM(require_components(), 1);
6421 var import_i18n26 = __toESM(require_i18n(), 1);
6422 var import_element24 = __toESM(require_element(), 1);
6423 var import_jsx_runtime52 = __toESM(require_jsx_runtime(), 1);
6424 var imageSizes2 = [
6425 {
6426 value: 120,
6427 breakpoint: 1
6428 },
6429 {
6430 value: 170,
6431 breakpoint: 1
6432 },
6433 {
6434 value: 230,
6435 breakpoint: 1
6436 },
6437 {
6438 value: 290,
6439 breakpoint: 1112
6440 // at minimum image width, 4 images display at this container size
6441 },
6442 {
6443 value: 350,
6444 breakpoint: 1636
6445 // at minimum image width, 6 images display at this container size
6446 },
6447 {
6448 value: 430,
6449 breakpoint: 588
6450 // at minimum image width, 2 images display at this container size
6451 }
6452 ];
6453 function PreviewSizePicker() {
6454 const context = (0, import_element24.useContext)(dataviews_context_default);
6455 const view = context.view;
6456 const breakValues = imageSizes2.filter((size) => {
6457 return context.containerWidth >= size.breakpoint;
6458 });
6459 const layoutPreviewSize = view.layout?.previewSize ?? 230;
6460 const previewSizeToUse = breakValues.map((size, index) => ({ ...size, index })).filter((size) => size.value <= layoutPreviewSize).sort((a2, b2) => b2.value - a2.value)[0]?.index ?? 0;
6461 const marks = breakValues.map((size, index) => {
6462 return {
6463 value: index
6464 };
6465 });
6466 return /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(
6467 import_components18.RangeControl,
6468 {
6469 __next40pxDefaultSize: true,
6470 showTooltip: false,
6471 label: (0, import_i18n26.__)("Preview size"),
6472 value: previewSizeToUse,
6473 min: 0,
6474 max: breakValues.length - 1,
6475 withInputField: false,
6476 onChange: (value = 0) => {
6477 context.onChangeView({
6478 ...view,
6479 layout: {
6480 ...view.layout,
6481 previewSize: breakValues[value].value
6482 }
6483 });
6484 },
6485 step: 1,
6486 marks
6487 }
6488 );
6489 }
6490
6491 // packages/dataviews/build-module/components/dataviews-layouts/utils/grid-config-options.mjs
6492 var import_jsx_runtime53 = __toESM(require_jsx_runtime(), 1);
6493 function GridConfigOptions() {
6494 return /* @__PURE__ */ (0, import_jsx_runtime53.jsxs)(import_jsx_runtime53.Fragment, { children: [
6495 /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(DensityPicker, {}),
6496 /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(PreviewSizePicker, {})
6497 ] });
6498 }
6499
6500 // packages/dataviews/build-module/components/dataviews-layouts/index.mjs
6501 var VIEW_LAYOUTS = [
6502 {
6503 type: LAYOUT_TABLE,
6504 label: (0, import_i18n27.__)("Table"),
6505 component: table_default,
6506 icon: block_table_default,
6507 viewConfigOptions: DensityPicker
6508 },
6509 {
6510 type: LAYOUT_GRID,
6511 label: (0, import_i18n27.__)("Grid"),
6512 component: grid_default,
6513 icon: category_default,
6514 viewConfigOptions: GridConfigOptions
6515 },
6516 {
6517 type: LAYOUT_LIST,
6518 label: (0, import_i18n27.__)("List"),
6519 component: ViewList,
6520 icon: (0, import_i18n27.isRTL)() ? format_list_bullets_rtl_default : format_list_bullets_default,
6521 viewConfigOptions: DensityPicker
6522 },
6523 {
6524 type: LAYOUT_ACTIVITY,
6525 label: (0, import_i18n27.__)("Activity"),
6526 component: ViewActivity,
6527 icon: scheduled_default,
6528 viewConfigOptions: DensityPicker
6529 },
6530 {
6531 type: LAYOUT_PICKER_GRID,
6532 label: (0, import_i18n27.__)("Grid"),
6533 component: picker_grid_default,
6534 icon: category_default,
6535 viewConfigOptions: GridConfigOptions,
6536 isPicker: true
6537 },
6538 {
6539 type: LAYOUT_PICKER_TABLE,
6540 label: (0, import_i18n27.__)("Table"),
6541 component: picker_table_default,
6542 icon: block_table_default,
6543 viewConfigOptions: DensityPicker,
6544 isPicker: true
6545 }
6546 ];
6547
6548 // packages/dataviews/build-module/components/dataviews-filters/filters.mjs
6549 var import_element32 = __toESM(require_element(), 1);
6550
6551 // packages/dataviews/build-module/components/dataviews-filters/filter.mjs
6552 var import_components21 = __toESM(require_components(), 1);
6553 var import_i18n30 = __toESM(require_i18n(), 1);
6554 var import_element29 = __toESM(require_element(), 1);
6555
6556 // node_modules/@ariakit/core/esm/__chunks/XMCVU3LR.js
6557 function noop2(..._) {
6558 }
6559 function applyState(argument, currentValue) {
6560 if (isUpdater(argument)) {
6561 const value = isLazyValue(currentValue) ? currentValue() : currentValue;
6562 return argument(value);
6563 }
6564 return argument;
6565 }
6566 function isUpdater(argument) {
6567 return typeof argument === "function";
6568 }
6569 function isLazyValue(value) {
6570 return typeof value === "function";
6571 }
6572 function hasOwnProperty(object, prop) {
6573 if (typeof Object.hasOwn === "function") {
6574 return Object.hasOwn(object, prop);
6575 }
6576 return Object.prototype.hasOwnProperty.call(object, prop);
6577 }
6578 function chain(...fns) {
6579 return (...args) => {
6580 for (const fn of fns) {
6581 if (typeof fn === "function") {
6582 fn(...args);
6583 }
6584 }
6585 };
6586 }
6587 function normalizeString(str) {
6588 return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
6589 }
6590 function omit(object, keys) {
6591 const result = { ...object };
6592 for (const key of keys) {
6593 if (hasOwnProperty(result, key)) {
6594 delete result[key];
6595 }
6596 }
6597 return result;
6598 }
6599 function pick(object, paths) {
6600 const result = {};
6601 for (const key of paths) {
6602 if (hasOwnProperty(object, key)) {
6603 result[key] = object[key];
6604 }
6605 }
6606 return result;
6607 }
6608 function identity(value) {
6609 return value;
6610 }
6611 function invariant(condition, message2) {
6612 if (condition) return;
6613 if (typeof message2 !== "string") throw new Error("Invariant failed");
6614 throw new Error(message2);
6615 }
6616 function getKeys(obj) {
6617 return Object.keys(obj);
6618 }
6619 function isFalsyBooleanCallback(booleanOrCallback, ...args) {
6620 const result = typeof booleanOrCallback === "function" ? booleanOrCallback(...args) : booleanOrCallback;
6621 if (result == null) return false;
6622 return !result;
6623 }
6624 function disabledFromProps(props) {
6625 return props.disabled || props["aria-disabled"] === true || props["aria-disabled"] === "true";
6626 }
6627 function removeUndefinedValues(obj) {
6628 const result = {};
6629 for (const key in obj) {
6630 if (obj[key] !== void 0) {
6631 result[key] = obj[key];
6632 }
6633 }
6634 return result;
6635 }
6636 function defaultValue(...values) {
6637 for (const value of values) {
6638 if (value !== void 0) return value;
6639 }
6640 return void 0;
6641 }
6642
6643 // node_modules/@ariakit/react-core/esm/__chunks/YXGXYGQX.js
6644 var import_react4 = __toESM(require_react(), 1);
6645 function setRef(ref, value) {
6646 if (typeof ref === "function") {
6647 ref(value);
6648 } else if (ref) {
6649 ref.current = value;
6650 }
6651 }
6652 function isValidElementWithRef(element) {
6653 if (!element) return false;
6654 if (!(0, import_react4.isValidElement)(element)) return false;
6655 if ("ref" in element.props) return true;
6656 if ("ref" in element) return true;
6657 return false;
6658 }
6659 function getRefProperty(element) {
6660 if (!isValidElementWithRef(element)) return null;
6661 const props = { ...element.props };
6662 return props.ref || element.ref;
6663 }
6664 function mergeProps2(base, overrides) {
6665 const props = { ...base };
6666 for (const key in overrides) {
6667 if (!hasOwnProperty(overrides, key)) continue;
6668 if (key === "className") {
6669 const prop = "className";
6670 props[prop] = base[prop] ? `${base[prop]} ${overrides[prop]}` : overrides[prop];
6671 continue;
6672 }
6673 if (key === "style") {
6674 const prop = "style";
6675 props[prop] = base[prop] ? { ...base[prop], ...overrides[prop] } : overrides[prop];
6676 continue;
6677 }
6678 const overrideValue = overrides[key];
6679 if (typeof overrideValue === "function" && key.startsWith("on")) {
6680 const baseValue = base[key];
6681 if (typeof baseValue === "function") {
6682 props[key] = (...args) => {
6683 overrideValue(...args);
6684 baseValue(...args);
6685 };
6686 continue;
6687 }
6688 }
6689 props[key] = overrideValue;
6690 }
6691 return props;
6692 }
6693
6694 // node_modules/@ariakit/core/esm/__chunks/3DNM6L6E.js
6695 var canUseDOM = checkIsBrowser();
6696 function checkIsBrowser() {
6697 var _a;
6698 return typeof window !== "undefined" && !!((_a = window.document) == null ? void 0 : _a.createElement);
6699 }
6700 function getDocument(node) {
6701 if (!node) return document;
6702 if ("self" in node) return node.document;
6703 return node.ownerDocument || document;
6704 }
6705 function getActiveElement(node, activeDescendant = false) {
6706 var _a;
6707 const { activeElement } = getDocument(node);
6708 if (!(activeElement == null ? void 0 : activeElement.nodeName)) {
6709 return null;
6710 }
6711 if (isFrame(activeElement) && ((_a = activeElement.contentDocument) == null ? void 0 : _a.body)) {
6712 return getActiveElement(
6713 activeElement.contentDocument.body,
6714 activeDescendant
6715 );
6716 }
6717 if (activeDescendant) {
6718 const id = activeElement.getAttribute("aria-activedescendant");
6719 if (id) {
6720 const element = getDocument(activeElement).getElementById(id);
6721 if (element) {
6722 return element;
6723 }
6724 }
6725 }
6726 return activeElement;
6727 }
6728 function contains(parent, child) {
6729 return parent === child || parent.contains(child);
6730 }
6731 function isFrame(element) {
6732 return element.tagName === "IFRAME";
6733 }
6734 function isButton(element) {
6735 const tagName = element.tagName.toLowerCase();
6736 if (tagName === "button") return true;
6737 if (tagName === "input" && element.type) {
6738 return buttonInputTypes.indexOf(element.type) !== -1;
6739 }
6740 return false;
6741 }
6742 var buttonInputTypes = [
6743 "button",
6744 "color",
6745 "file",
6746 "image",
6747 "reset",
6748 "submit"
6749 ];
6750 function isVisible(element) {
6751 if (typeof element.checkVisibility === "function") {
6752 return element.checkVisibility();
6753 }
6754 const htmlElement = element;
6755 return htmlElement.offsetWidth > 0 || htmlElement.offsetHeight > 0 || element.getClientRects().length > 0;
6756 }
6757 function isTextField(element) {
6758 try {
6759 const isTextInput = element instanceof HTMLInputElement && element.selectionStart !== null;
6760 const isTextArea = element.tagName === "TEXTAREA";
6761 return isTextInput || isTextArea || false;
6762 } catch (_error) {
6763 return false;
6764 }
6765 }
6766 function isTextbox(element) {
6767 return element.isContentEditable || isTextField(element);
6768 }
6769 function getTextboxValue(element) {
6770 if (isTextField(element)) {
6771 return element.value;
6772 }
6773 if (element.isContentEditable) {
6774 const range = getDocument(element).createRange();
6775 range.selectNodeContents(element);
6776 return range.toString();
6777 }
6778 return "";
6779 }
6780 function getTextboxSelection(element) {
6781 let start = 0;
6782 let end = 0;
6783 if (isTextField(element)) {
6784 start = element.selectionStart || 0;
6785 end = element.selectionEnd || 0;
6786 } else if (element.isContentEditable) {
6787 const selection = getDocument(element).getSelection();
6788 if ((selection == null ? void 0 : selection.rangeCount) && selection.anchorNode && contains(element, selection.anchorNode) && selection.focusNode && contains(element, selection.focusNode)) {
6789 const range = selection.getRangeAt(0);
6790 const nextRange = range.cloneRange();
6791 nextRange.selectNodeContents(element);
6792 nextRange.setEnd(range.startContainer, range.startOffset);
6793 start = nextRange.toString().length;
6794 nextRange.setEnd(range.endContainer, range.endOffset);
6795 end = nextRange.toString().length;
6796 }
6797 }
6798 return { start, end };
6799 }
6800 function getPopupRole(element, fallback) {
6801 const allowedPopupRoles = ["dialog", "menu", "listbox", "tree", "grid"];
6802 const role = element == null ? void 0 : element.getAttribute("role");
6803 if (role && allowedPopupRoles.indexOf(role) !== -1) {
6804 return role;
6805 }
6806 return fallback;
6807 }
6808 function getScrollingElement(element) {
6809 if (!element) return null;
6810 const isScrollableOverflow = (overflow) => {
6811 if (overflow === "auto") return true;
6812 if (overflow === "scroll") return true;
6813 return false;
6814 };
6815 if (element.clientHeight && element.scrollHeight > element.clientHeight) {
6816 const { overflowY } = getComputedStyle(element);
6817 if (isScrollableOverflow(overflowY)) return element;
6818 } else if (element.clientWidth && element.scrollWidth > element.clientWidth) {
6819 const { overflowX } = getComputedStyle(element);
6820 if (isScrollableOverflow(overflowX)) return element;
6821 }
6822 return getScrollingElement(element.parentElement) || document.scrollingElement || document.body;
6823 }
6824 function setSelectionRange(element, ...args) {
6825 if (/text|search|password|tel|url/i.test(element.type)) {
6826 element.setSelectionRange(...args);
6827 }
6828 }
6829 function sortBasedOnDOMPosition(items, getElement) {
6830 const pairs = items.map((item, index) => [index, item]);
6831 let isOrderDifferent = false;
6832 pairs.sort(([indexA, a2], [indexB, b2]) => {
6833 const elementA = getElement(a2);
6834 const elementB = getElement(b2);
6835 if (elementA === elementB) return 0;
6836 if (!elementA || !elementB) return 0;
6837 if (isElementPreceding(elementA, elementB)) {
6838 if (indexA > indexB) {
6839 isOrderDifferent = true;
6840 }
6841 return -1;
6842 }
6843 if (indexA < indexB) {
6844 isOrderDifferent = true;
6845 }
6846 return 1;
6847 });
6848 if (isOrderDifferent) {
6849 return pairs.map(([_, item]) => item);
6850 }
6851 return items;
6852 }
6853 function isElementPreceding(a2, b2) {
6854 return Boolean(
6855 b2.compareDocumentPosition(a2) & Node.DOCUMENT_POSITION_PRECEDING
6856 );
6857 }
6858
6859 // node_modules/@ariakit/core/esm/__chunks/SNHYQNEZ.js
6860 function isTouchDevice() {
6861 return canUseDOM && !!navigator.maxTouchPoints;
6862 }
6863 function isApple() {
6864 if (!canUseDOM) return false;
6865 return /mac|iphone|ipad|ipod/i.test(navigator.platform);
6866 }
6867 function isSafari() {
6868 return canUseDOM && isApple() && /apple/i.test(navigator.vendor);
6869 }
6870 function isFirefox() {
6871 return canUseDOM && /firefox\//i.test(navigator.userAgent);
6872 }
6873
6874 // node_modules/@ariakit/core/esm/utils/events.js
6875 function isPortalEvent(event) {
6876 return Boolean(
6877 event.currentTarget && !contains(event.currentTarget, event.target)
6878 );
6879 }
6880 function isSelfTarget(event) {
6881 return event.target === event.currentTarget;
6882 }
6883 function isOpeningInNewTab(event) {
6884 const element = event.currentTarget;
6885 if (!element) return false;
6886 const isAppleDevice = isApple();
6887 if (isAppleDevice && !event.metaKey) return false;
6888 if (!isAppleDevice && !event.ctrlKey) return false;
6889 const tagName = element.tagName.toLowerCase();
6890 if (tagName === "a") return true;
6891 if (tagName === "button" && element.type === "submit") return true;
6892 if (tagName === "input" && element.type === "submit") return true;
6893 return false;
6894 }
6895 function isDownloading(event) {
6896 const element = event.currentTarget;
6897 if (!element) return false;
6898 const tagName = element.tagName.toLowerCase();
6899 if (!event.altKey) return false;
6900 if (tagName === "a") return true;
6901 if (tagName === "button" && element.type === "submit") return true;
6902 if (tagName === "input" && element.type === "submit") return true;
6903 return false;
6904 }
6905 function fireBlurEvent(element, eventInit) {
6906 const event = new FocusEvent("blur", eventInit);
6907 const defaultAllowed = element.dispatchEvent(event);
6908 const bubbleInit = { ...eventInit, bubbles: true };
6909 element.dispatchEvent(new FocusEvent("focusout", bubbleInit));
6910 return defaultAllowed;
6911 }
6912 function fireKeyboardEvent(element, type, eventInit) {
6913 const event = new KeyboardEvent(type, eventInit);
6914 return element.dispatchEvent(event);
6915 }
6916 function fireClickEvent(element, eventInit) {
6917 const event = new MouseEvent("click", eventInit);
6918 return element.dispatchEvent(event);
6919 }
6920 function isFocusEventOutside(event, container) {
6921 const containerElement = container || event.currentTarget;
6922 const relatedTarget = event.relatedTarget;
6923 return !relatedTarget || !contains(containerElement, relatedTarget);
6924 }
6925 function queueBeforeEvent(element, type, callback, timeout) {
6926 const createTimer = (callback2) => {
6927 if (timeout) {
6928 const timerId2 = setTimeout(callback2, timeout);
6929 return () => clearTimeout(timerId2);
6930 }
6931 const timerId = requestAnimationFrame(callback2);
6932 return () => cancelAnimationFrame(timerId);
6933 };
6934 const cancelTimer = createTimer(() => {
6935 element.removeEventListener(type, callSync, true);
6936 callback();
6937 });
6938 const callSync = () => {
6939 cancelTimer();
6940 callback();
6941 };
6942 element.addEventListener(type, callSync, { once: true, capture: true });
6943 return cancelTimer;
6944 }
6945 function addGlobalEventListener(type, listener, options, scope = window) {
6946 const children = [];
6947 try {
6948 scope.document.addEventListener(type, listener, options);
6949 for (const frame of Array.from(scope.frames)) {
6950 children.push(addGlobalEventListener(type, listener, options, frame));
6951 }
6952 } catch (e2) {
6953 }
6954 const removeEventListener = () => {
6955 try {
6956 scope.document.removeEventListener(type, listener, options);
6957 } catch (e2) {
6958 }
6959 for (const remove of children) {
6960 remove();
6961 }
6962 };
6963 return removeEventListener;
6964 }
6965
6966 // node_modules/@ariakit/react-core/esm/__chunks/KPHZR4MB.js
6967 var React5 = __toESM(require_react(), 1);
6968 var import_react5 = __toESM(require_react(), 1);
6969 var _React = { ...React5 };
6970 var useReactId = _React.useId;
6971 var useReactDeferredValue = _React.useDeferredValue;
6972 var useReactInsertionEffect = _React.useInsertionEffect;
6973 var useSafeLayoutEffect = canUseDOM ? import_react5.useLayoutEffect : import_react5.useEffect;
6974 function useInitialValue(value) {
6975 const [initialValue] = (0, import_react5.useState)(value);
6976 return initialValue;
6977 }
6978 function useLiveRef(value) {
6979 const ref = (0, import_react5.useRef)(value);
6980 useSafeLayoutEffect(() => {
6981 ref.current = value;
6982 });
6983 return ref;
6984 }
6985 function useEvent(callback) {
6986 const ref = (0, import_react5.useRef)(() => {
6987 throw new Error("Cannot call an event handler while rendering.");
6988 });
6989 if (useReactInsertionEffect) {
6990 useReactInsertionEffect(() => {
6991 ref.current = callback;
6992 });
6993 } else {
6994 ref.current = callback;
6995 }
6996 return (0, import_react5.useCallback)((...args) => {
6997 var _a;
6998 return (_a = ref.current) == null ? void 0 : _a.call(ref, ...args);
6999 }, []);
7000 }
7001 function useTransactionState(callback) {
7002 const [state, setState] = (0, import_react5.useState)(null);
7003 useSafeLayoutEffect(() => {
7004 if (state == null) return;
7005 if (!callback) return;
7006 let prevState = null;
7007 callback((prev) => {
7008 prevState = prev;
7009 return state;
7010 });
7011 return () => {
7012 callback(prevState);
7013 };
7014 }, [state, callback]);
7015 return [state, setState];
7016 }
7017 function useMergeRefs(...refs) {
7018 return (0, import_react5.useMemo)(() => {
7019 if (!refs.some(Boolean)) return;
7020 return (value) => {
7021 for (const ref of refs) {
7022 setRef(ref, value);
7023 }
7024 };
7025 }, refs);
7026 }
7027 function useId3(defaultId) {
7028 if (useReactId) {
7029 const reactId = useReactId();
7030 if (defaultId) return defaultId;
7031 return reactId;
7032 }
7033 const [id, setId] = (0, import_react5.useState)(defaultId);
7034 useSafeLayoutEffect(() => {
7035 if (defaultId || id) return;
7036 const random = Math.random().toString(36).slice(2, 8);
7037 setId(`id-${random}`);
7038 }, [defaultId, id]);
7039 return defaultId || id;
7040 }
7041 function useTagName(refOrElement, type) {
7042 const stringOrUndefined = (type2) => {
7043 if (typeof type2 !== "string") return;
7044 return type2;
7045 };
7046 const [tagName, setTagName] = (0, import_react5.useState)(() => stringOrUndefined(type));
7047 useSafeLayoutEffect(() => {
7048 const element = refOrElement && "current" in refOrElement ? refOrElement.current : refOrElement;
7049 setTagName((element == null ? void 0 : element.tagName.toLowerCase()) || stringOrUndefined(type));
7050 }, [refOrElement, type]);
7051 return tagName;
7052 }
7053 function useAttribute(refOrElement, attributeName, defaultValue2) {
7054 const initialValue = useInitialValue(defaultValue2);
7055 const [attribute, setAttribute] = (0, import_react5.useState)(initialValue);
7056 (0, import_react5.useEffect)(() => {
7057 const element = refOrElement && "current" in refOrElement ? refOrElement.current : refOrElement;
7058 if (!element) return;
7059 const callback = () => {
7060 const value = element.getAttribute(attributeName);
7061 setAttribute(value == null ? initialValue : value);
7062 };
7063 const observer = new MutationObserver(callback);
7064 observer.observe(element, { attributeFilter: [attributeName] });
7065 callback();
7066 return () => observer.disconnect();
7067 }, [refOrElement, attributeName, initialValue]);
7068 return attribute;
7069 }
7070 function useUpdateEffect(effect, deps) {
7071 const mounted = (0, import_react5.useRef)(false);
7072 (0, import_react5.useEffect)(() => {
7073 if (mounted.current) {
7074 return effect();
7075 }
7076 mounted.current = true;
7077 }, deps);
7078 (0, import_react5.useEffect)(
7079 () => () => {
7080 mounted.current = false;
7081 },
7082 []
7083 );
7084 }
7085 function useUpdateLayoutEffect(effect, deps) {
7086 const mounted = (0, import_react5.useRef)(false);
7087 useSafeLayoutEffect(() => {
7088 if (mounted.current) {
7089 return effect();
7090 }
7091 mounted.current = true;
7092 }, deps);
7093 useSafeLayoutEffect(
7094 () => () => {
7095 mounted.current = false;
7096 },
7097 []
7098 );
7099 }
7100 function useForceUpdate() {
7101 return (0, import_react5.useReducer)(() => [], []);
7102 }
7103 function useBooleanEvent(booleanOrCallback) {
7104 return useEvent(
7105 typeof booleanOrCallback === "function" ? booleanOrCallback : () => booleanOrCallback
7106 );
7107 }
7108 function useWrapElement(props, callback, deps = []) {
7109 const wrapElement = (0, import_react5.useCallback)(
7110 (element) => {
7111 if (props.wrapElement) {
7112 element = props.wrapElement(element);
7113 }
7114 return callback(element);
7115 },
7116 [...deps, props.wrapElement]
7117 );
7118 return { ...props, wrapElement };
7119 }
7120 function useMetadataProps(props, key, value) {
7121 const parent = props.onLoadedMetadataCapture;
7122 const onLoadedMetadataCapture = (0, import_react5.useMemo)(() => {
7123 return Object.assign(() => {
7124 }, { ...parent, [key]: value });
7125 }, [parent, key, value]);
7126 return [parent == null ? void 0 : parent[key], { onLoadedMetadataCapture }];
7127 }
7128 var hasInstalledGlobalEventListeners = false;
7129 function useIsMouseMoving() {
7130 (0, import_react5.useEffect)(() => {
7131 if (hasInstalledGlobalEventListeners) return;
7132 addGlobalEventListener("mousemove", setMouseMoving, true);
7133 addGlobalEventListener("mousedown", resetMouseMoving, true);
7134 addGlobalEventListener("mouseup", resetMouseMoving, true);
7135 addGlobalEventListener("keydown", resetMouseMoving, true);
7136 addGlobalEventListener("scroll", resetMouseMoving, true);
7137 hasInstalledGlobalEventListeners = true;
7138 }, []);
7139 const isMouseMoving = useEvent(() => mouseMoving);
7140 return isMouseMoving;
7141 }
7142 var mouseMoving = false;
7143 var previousScreenX = 0;
7144 var previousScreenY = 0;
7145 function hasMouseMovement(event) {
7146 const movementX = event.movementX || event.screenX - previousScreenX;
7147 const movementY = event.movementY || event.screenY - previousScreenY;
7148 previousScreenX = event.screenX;
7149 previousScreenY = event.screenY;
7150 return movementX || movementY || false;
7151 }
7152 function setMouseMoving(event) {
7153 if (!hasMouseMovement(event)) return;
7154 mouseMoving = true;
7155 }
7156 function resetMouseMoving() {
7157 mouseMoving = false;
7158 }
7159
7160 // node_modules/@ariakit/react-core/esm/__chunks/GWSL6KNJ.js
7161 var React6 = __toESM(require_react(), 1);
7162 var import_jsx_runtime54 = __toESM(require_jsx_runtime(), 1);
7163 function forwardRef22(render4) {
7164 const Role = React6.forwardRef(
7165 // @ts-ignore Incompatible with React 19 types. Ignore for now.
7166 (props, ref) => render4({ ...props, ref })
7167 );
7168 Role.displayName = render4.displayName || render4.name;
7169 return Role;
7170 }
7171 function memo22(Component2, propsAreEqual) {
7172 return React6.memo(Component2, propsAreEqual);
7173 }
7174 function createElement3(Type, props) {
7175 const { wrapElement, render: render4, ...rest } = props;
7176 const mergedRef = useMergeRefs(props.ref, getRefProperty(render4));
7177 let element;
7178 if (React6.isValidElement(render4)) {
7179 const renderProps = {
7180 // @ts-ignore Incompatible with React 19 types. Ignore for now.
7181 ...render4.props,
7182 ref: mergedRef
7183 };
7184 element = React6.cloneElement(render4, mergeProps2(rest, renderProps));
7185 } else if (render4) {
7186 element = render4(rest);
7187 } else {
7188 element = /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(Type, { ...rest });
7189 }
7190 if (wrapElement) {
7191 return wrapElement(element);
7192 }
7193 return element;
7194 }
7195 function createHook(useProps) {
7196 const useRole = (props = {}) => {
7197 return useProps(props);
7198 };
7199 useRole.displayName = useProps.name;
7200 return useRole;
7201 }
7202 function createStoreContext(providers = [], scopedProviders = []) {
7203 const context = React6.createContext(void 0);
7204 const scopedContext = React6.createContext(void 0);
7205 const useContext28 = () => React6.useContext(context);
7206 const useScopedContext = (onlyScoped = false) => {
7207 const scoped = React6.useContext(scopedContext);
7208 const store = useContext28();
7209 if (onlyScoped) return scoped;
7210 return scoped || store;
7211 };
7212 const useProviderContext = () => {
7213 const scoped = React6.useContext(scopedContext);
7214 const store = useContext28();
7215 if (scoped && scoped === store) return;
7216 return store;
7217 };
7218 const ContextProvider = (props) => {
7219 return providers.reduceRight(
7220 (children, Provider) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(Provider, { ...props, children }),
7221 /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(context.Provider, { ...props })
7222 );
7223 };
7224 const ScopedContextProvider = (props) => {
7225 return /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(ContextProvider, { ...props, children: scopedProviders.reduceRight(
7226 (children, Provider) => /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(Provider, { ...props, children }),
7227 /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(scopedContext.Provider, { ...props })
7228 ) });
7229 };
7230 return {
7231 context,
7232 scopedContext,
7233 useContext: useContext28,
7234 useScopedContext,
7235 useProviderContext,
7236 ContextProvider,
7237 ScopedContextProvider
7238 };
7239 }
7240
7241 // node_modules/@ariakit/react-core/esm/__chunks/SMPCIMZM.js
7242 var ctx = createStoreContext();
7243 var useCollectionContext = ctx.useContext;
7244 var useCollectionScopedContext = ctx.useScopedContext;
7245 var useCollectionProviderContext = ctx.useProviderContext;
7246 var CollectionContextProvider = ctx.ContextProvider;
7247 var CollectionScopedContextProvider = ctx.ScopedContextProvider;
7248
7249 // node_modules/@ariakit/react-core/esm/__chunks/AVVXDJMZ.js
7250 var import_react6 = __toESM(require_react(), 1);
7251 var ctx2 = createStoreContext(
7252 [CollectionContextProvider],
7253 [CollectionScopedContextProvider]
7254 );
7255 var useCompositeContext = ctx2.useContext;
7256 var useCompositeScopedContext = ctx2.useScopedContext;
7257 var useCompositeProviderContext = ctx2.useProviderContext;
7258 var CompositeContextProvider = ctx2.ContextProvider;
7259 var CompositeScopedContextProvider = ctx2.ScopedContextProvider;
7260 var CompositeItemContext = (0, import_react6.createContext)(
7261 void 0
7262 );
7263 var CompositeRowContext = (0, import_react6.createContext)(
7264 void 0
7265 );
7266
7267 // node_modules/@ariakit/react-core/esm/__chunks/5VQZOHHZ.js
7268 function findFirstEnabledItem(items, excludeId) {
7269 return items.find((item) => {
7270 if (excludeId) {
7271 return !item.disabled && item.id !== excludeId;
7272 }
7273 return !item.disabled;
7274 });
7275 }
7276 function getEnabledItem(store, id) {
7277 if (!id) return null;
7278 return store.item(id) || null;
7279 }
7280 function groupItemsByRows(items) {
7281 const rows = [];
7282 for (const item of items) {
7283 const row = rows.find((currentRow) => {
7284 var _a;
7285 return ((_a = currentRow[0]) == null ? void 0 : _a.rowId) === item.rowId;
7286 });
7287 if (row) {
7288 row.push(item);
7289 } else {
7290 rows.push([item]);
7291 }
7292 }
7293 return rows;
7294 }
7295 function selectTextField(element, collapseToEnd = false) {
7296 if (isTextField(element)) {
7297 element.setSelectionRange(
7298 collapseToEnd ? element.value.length : 0,
7299 element.value.length
7300 );
7301 } else if (element.isContentEditable) {
7302 const selection = getDocument(element).getSelection();
7303 selection == null ? void 0 : selection.selectAllChildren(element);
7304 if (collapseToEnd) {
7305 selection == null ? void 0 : selection.collapseToEnd();
7306 }
7307 }
7308 }
7309 var FOCUS_SILENTLY = /* @__PURE__ */ Symbol("FOCUS_SILENTLY");
7310 function focusSilently(element) {
7311 element[FOCUS_SILENTLY] = true;
7312 element.focus({ preventScroll: true });
7313 }
7314 function silentlyFocused(element) {
7315 const isSilentlyFocused = element[FOCUS_SILENTLY];
7316 delete element[FOCUS_SILENTLY];
7317 return isSilentlyFocused;
7318 }
7319 function isItem(store, element, exclude) {
7320 if (!element) return false;
7321 if (element === exclude) return false;
7322 const item = store.item(element.id);
7323 if (!item) return false;
7324 if (exclude && item.element === exclude) return false;
7325 return true;
7326 }
7327
7328 // node_modules/@ariakit/react-core/esm/__chunks/Z2O3VLAQ.js
7329 var import_react7 = __toESM(require_react(), 1);
7330 var TagName = "div";
7331 var useCollectionItem = createHook(
7332 function useCollectionItem2({
7333 store,
7334 shouldRegisterItem = true,
7335 getItem = identity,
7336 // @ts-expect-error This prop may come from a collection renderer.
7337 element,
7338 ...props
7339 }) {
7340 const context = useCollectionContext();
7341 store = store || context;
7342 const id = useId3(props.id);
7343 const ref = (0, import_react7.useRef)(element);
7344 (0, import_react7.useEffect)(() => {
7345 const element2 = ref.current;
7346 if (!id) return;
7347 if (!element2) return;
7348 if (!shouldRegisterItem) return;
7349 const item = getItem({ id, element: element2 });
7350 return store == null ? void 0 : store.renderItem(item);
7351 }, [id, shouldRegisterItem, getItem, store]);
7352 props = {
7353 ...props,
7354 ref: useMergeRefs(ref, props.ref)
7355 };
7356 return removeUndefinedValues(props);
7357 }
7358 );
7359 var CollectionItem = forwardRef22(function CollectionItem2(props) {
7360 const htmlProps = useCollectionItem(props);
7361 return createElement3(TagName, htmlProps);
7362 });
7363
7364 // node_modules/@ariakit/react-core/esm/__chunks/SWN3JYXT.js
7365 var import_react8 = __toESM(require_react(), 1);
7366 var FocusableContext = (0, import_react8.createContext)(true);
7367
7368 // node_modules/@ariakit/core/esm/utils/focus.js
7369 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'])";
7370 function isFocusable(element) {
7371 if (!element.matches(selector)) return false;
7372 if (!isVisible(element)) return false;
7373 if (element.closest("[inert]")) return false;
7374 return true;
7375 }
7376 function getClosestFocusable(element) {
7377 while (element && !isFocusable(element)) {
7378 element = element.closest(selector);
7379 }
7380 return element || null;
7381 }
7382 function hasFocus(element) {
7383 const activeElement = getActiveElement(element);
7384 if (!activeElement) return false;
7385 if (activeElement === element) return true;
7386 const activeDescendant = activeElement.getAttribute("aria-activedescendant");
7387 if (!activeDescendant) return false;
7388 return activeDescendant === element.id;
7389 }
7390 function hasFocusWithin(element) {
7391 const activeElement = getActiveElement(element);
7392 if (!activeElement) return false;
7393 if (contains(element, activeElement)) return true;
7394 const activeDescendant = activeElement.getAttribute("aria-activedescendant");
7395 if (!activeDescendant) return false;
7396 if (!("id" in element)) return false;
7397 if (activeDescendant === element.id) return true;
7398 return !!element.querySelector(`#${CSS.escape(activeDescendant)}`);
7399 }
7400 function focusIfNeeded(element) {
7401 if (!hasFocusWithin(element) && isFocusable(element)) {
7402 element.focus();
7403 }
7404 }
7405 function focusIntoView(element, options) {
7406 if (!("scrollIntoView" in element)) {
7407 element.focus();
7408 } else {
7409 element.focus({ preventScroll: true });
7410 element.scrollIntoView({ block: "nearest", inline: "nearest", ...options });
7411 }
7412 }
7413
7414 // node_modules/@ariakit/react-core/esm/__chunks/U6HHPQDW.js
7415 var import_react9 = __toESM(require_react(), 1);
7416 var TagName2 = "div";
7417 var isSafariBrowser = isSafari();
7418 var alwaysFocusVisibleInputTypes = [
7419 "text",
7420 "search",
7421 "url",
7422 "tel",
7423 "email",
7424 "password",
7425 "number",
7426 "date",
7427 "month",
7428 "week",
7429 "time",
7430 "datetime",
7431 "datetime-local"
7432 ];
7433 var safariFocusAncestorSymbol = /* @__PURE__ */ Symbol("safariFocusAncestor");
7434 function markSafariFocusAncestor(element, value) {
7435 if (!element) return;
7436 element[safariFocusAncestorSymbol] = value;
7437 }
7438 function isAlwaysFocusVisible(element) {
7439 const { tagName, readOnly, type } = element;
7440 if (tagName === "TEXTAREA" && !readOnly) return true;
7441 if (tagName === "SELECT" && !readOnly) return true;
7442 if (tagName === "INPUT" && !readOnly) {
7443 return alwaysFocusVisibleInputTypes.includes(type);
7444 }
7445 if (element.isContentEditable) return true;
7446 const role = element.getAttribute("role");
7447 if (role === "combobox" && element.dataset.name) {
7448 return true;
7449 }
7450 return false;
7451 }
7452 function getLabels(element) {
7453 if ("labels" in element) {
7454 return element.labels;
7455 }
7456 return null;
7457 }
7458 function isNativeCheckboxOrRadio(element) {
7459 const tagName = element.tagName.toLowerCase();
7460 if (tagName === "input" && element.type) {
7461 return element.type === "radio" || element.type === "checkbox";
7462 }
7463 return false;
7464 }
7465 function isNativeTabbable(tagName) {
7466 if (!tagName) return true;
7467 return tagName === "button" || tagName === "summary" || tagName === "input" || tagName === "select" || tagName === "textarea" || tagName === "a";
7468 }
7469 function supportsDisabledAttribute(tagName) {
7470 if (!tagName) return true;
7471 return tagName === "button" || tagName === "input" || tagName === "select" || tagName === "textarea";
7472 }
7473 function getTabIndex(focusable, trulyDisabled, nativeTabbable, supportsDisabled, tabIndexProp) {
7474 if (!focusable) {
7475 return tabIndexProp;
7476 }
7477 if (trulyDisabled) {
7478 if (nativeTabbable && !supportsDisabled) {
7479 return -1;
7480 }
7481 return;
7482 }
7483 if (nativeTabbable) {
7484 return tabIndexProp;
7485 }
7486 return tabIndexProp || 0;
7487 }
7488 function useDisableEvent(onEvent, disabled) {
7489 return useEvent((event) => {
7490 onEvent == null ? void 0 : onEvent(event);
7491 if (event.defaultPrevented) return;
7492 if (disabled) {
7493 event.stopPropagation();
7494 event.preventDefault();
7495 }
7496 });
7497 }
7498 var hasInstalledGlobalEventListeners2 = false;
7499 var isKeyboardModality = true;
7500 function onGlobalMouseDown(event) {
7501 const target = event.target;
7502 if (target && "hasAttribute" in target) {
7503 if (!target.hasAttribute("data-focus-visible")) {
7504 isKeyboardModality = false;
7505 }
7506 }
7507 }
7508 function onGlobalKeyDown(event) {
7509 if (event.metaKey) return;
7510 if (event.ctrlKey) return;
7511 if (event.altKey) return;
7512 isKeyboardModality = true;
7513 }
7514 var useFocusable = createHook(
7515 function useFocusable2({
7516 focusable = true,
7517 accessibleWhenDisabled,
7518 autoFocus,
7519 onFocusVisible,
7520 ...props
7521 }) {
7522 const ref = (0, import_react9.useRef)(null);
7523 (0, import_react9.useEffect)(() => {
7524 if (!focusable) return;
7525 if (hasInstalledGlobalEventListeners2) return;
7526 addGlobalEventListener("mousedown", onGlobalMouseDown, true);
7527 addGlobalEventListener("keydown", onGlobalKeyDown, true);
7528 hasInstalledGlobalEventListeners2 = true;
7529 }, [focusable]);
7530 if (isSafariBrowser) {
7531 (0, import_react9.useEffect)(() => {
7532 if (!focusable) return;
7533 const element = ref.current;
7534 if (!element) return;
7535 if (!isNativeCheckboxOrRadio(element)) return;
7536 const labels = getLabels(element);
7537 if (!labels) return;
7538 const onMouseUp = () => queueMicrotask(() => element.focus());
7539 for (const label of labels) {
7540 label.addEventListener("mouseup", onMouseUp);
7541 }
7542 return () => {
7543 for (const label of labels) {
7544 label.removeEventListener("mouseup", onMouseUp);
7545 }
7546 };
7547 }, [focusable]);
7548 }
7549 const disabled = focusable && disabledFromProps(props);
7550 const trulyDisabled = !!disabled && !accessibleWhenDisabled;
7551 const [focusVisible, setFocusVisible] = (0, import_react9.useState)(false);
7552 (0, import_react9.useEffect)(() => {
7553 if (!focusable) return;
7554 if (trulyDisabled && focusVisible) {
7555 setFocusVisible(false);
7556 }
7557 }, [focusable, trulyDisabled, focusVisible]);
7558 (0, import_react9.useEffect)(() => {
7559 if (!focusable) return;
7560 if (!focusVisible) return;
7561 const element = ref.current;
7562 if (!element) return;
7563 if (typeof IntersectionObserver === "undefined") return;
7564 const observer = new IntersectionObserver(() => {
7565 if (!isFocusable(element)) {
7566 setFocusVisible(false);
7567 }
7568 });
7569 observer.observe(element);
7570 return () => observer.disconnect();
7571 }, [focusable, focusVisible]);
7572 const onKeyPressCapture = useDisableEvent(
7573 props.onKeyPressCapture,
7574 disabled
7575 );
7576 const onMouseDownCapture = useDisableEvent(
7577 props.onMouseDownCapture,
7578 disabled
7579 );
7580 const onClickCapture = useDisableEvent(props.onClickCapture, disabled);
7581 const onMouseDownProp = props.onMouseDown;
7582 const onMouseDown = useEvent((event) => {
7583 onMouseDownProp == null ? void 0 : onMouseDownProp(event);
7584 if (event.defaultPrevented) return;
7585 if (!focusable) return;
7586 const element = event.currentTarget;
7587 if (!isSafariBrowser) return;
7588 if (isPortalEvent(event)) return;
7589 if (!isButton(element) && !isNativeCheckboxOrRadio(element)) return;
7590 let receivedFocus = false;
7591 const onFocus = () => {
7592 receivedFocus = true;
7593 };
7594 const options = { capture: true, once: true };
7595 element.addEventListener("focusin", onFocus, options);
7596 const focusableContainer = getClosestFocusable(element.parentElement);
7597 markSafariFocusAncestor(focusableContainer, true);
7598 queueBeforeEvent(element, "mouseup", () => {
7599 element.removeEventListener("focusin", onFocus, true);
7600 markSafariFocusAncestor(focusableContainer, false);
7601 if (receivedFocus) return;
7602 focusIfNeeded(element);
7603 });
7604 });
7605 const handleFocusVisible = (event, currentTarget) => {
7606 if (currentTarget) {
7607 event.currentTarget = currentTarget;
7608 }
7609 if (!focusable) return;
7610 const element = event.currentTarget;
7611 if (!element) return;
7612 if (!hasFocus(element)) return;
7613 onFocusVisible == null ? void 0 : onFocusVisible(event);
7614 if (event.defaultPrevented) return;
7615 element.dataset.focusVisible = "true";
7616 setFocusVisible(true);
7617 };
7618 const onKeyDownCaptureProp = props.onKeyDownCapture;
7619 const onKeyDownCapture = useEvent((event) => {
7620 onKeyDownCaptureProp == null ? void 0 : onKeyDownCaptureProp(event);
7621 if (event.defaultPrevented) return;
7622 if (!focusable) return;
7623 if (focusVisible) return;
7624 if (event.metaKey) return;
7625 if (event.altKey) return;
7626 if (event.ctrlKey) return;
7627 if (!isSelfTarget(event)) return;
7628 const element = event.currentTarget;
7629 const applyFocusVisible = () => handleFocusVisible(event, element);
7630 queueBeforeEvent(element, "focusout", applyFocusVisible);
7631 });
7632 const onFocusCaptureProp = props.onFocusCapture;
7633 const onFocusCapture = useEvent((event) => {
7634 onFocusCaptureProp == null ? void 0 : onFocusCaptureProp(event);
7635 if (event.defaultPrevented) return;
7636 if (!focusable) return;
7637 if (!isSelfTarget(event)) {
7638 setFocusVisible(false);
7639 return;
7640 }
7641 const element = event.currentTarget;
7642 const applyFocusVisible = () => handleFocusVisible(event, element);
7643 if (isKeyboardModality || isAlwaysFocusVisible(event.target)) {
7644 queueBeforeEvent(event.target, "focusout", applyFocusVisible);
7645 } else {
7646 setFocusVisible(false);
7647 }
7648 });
7649 const onBlurProp = props.onBlur;
7650 const onBlur = useEvent((event) => {
7651 onBlurProp == null ? void 0 : onBlurProp(event);
7652 if (!focusable) return;
7653 if (!isFocusEventOutside(event)) return;
7654 event.currentTarget.removeAttribute("data-focus-visible");
7655 setFocusVisible(false);
7656 });
7657 const autoFocusOnShow = (0, import_react9.useContext)(FocusableContext);
7658 const autoFocusRef = useEvent((element) => {
7659 if (!focusable) return;
7660 if (!autoFocus) return;
7661 if (!element) return;
7662 if (!autoFocusOnShow) return;
7663 queueMicrotask(() => {
7664 if (hasFocus(element)) return;
7665 if (!isFocusable(element)) return;
7666 element.focus();
7667 });
7668 });
7669 const tagName = useTagName(ref);
7670 const nativeTabbable = focusable && isNativeTabbable(tagName);
7671 const supportsDisabled = focusable && supportsDisabledAttribute(tagName);
7672 const styleProp = props.style;
7673 const style = (0, import_react9.useMemo)(() => {
7674 if (trulyDisabled) {
7675 return { pointerEvents: "none", ...styleProp };
7676 }
7677 return styleProp;
7678 }, [trulyDisabled, styleProp]);
7679 props = {
7680 "data-focus-visible": focusable && focusVisible || void 0,
7681 "data-autofocus": autoFocus || void 0,
7682 "aria-disabled": disabled || void 0,
7683 ...props,
7684 ref: useMergeRefs(ref, autoFocusRef, props.ref),
7685 style,
7686 tabIndex: getTabIndex(
7687 focusable,
7688 trulyDisabled,
7689 nativeTabbable,
7690 supportsDisabled,
7691 props.tabIndex
7692 ),
7693 disabled: supportsDisabled && trulyDisabled ? true : void 0,
7694 // TODO: Test Focusable contentEditable.
7695 contentEditable: disabled ? void 0 : props.contentEditable,
7696 onKeyPressCapture,
7697 onClickCapture,
7698 onMouseDownCapture,
7699 onMouseDown,
7700 onKeyDownCapture,
7701 onFocusCapture,
7702 onBlur
7703 };
7704 return removeUndefinedValues(props);
7705 }
7706 );
7707 var Focusable = forwardRef22(function Focusable2(props) {
7708 const htmlProps = useFocusable(props);
7709 return createElement3(TagName2, htmlProps);
7710 });
7711
7712 // node_modules/@ariakit/react-core/esm/__chunks/PZ3OL7I2.js
7713 var import_react10 = __toESM(require_react(), 1);
7714 var TagName3 = "button";
7715 function isNativeClick(event) {
7716 if (!event.isTrusted) return false;
7717 const element = event.currentTarget;
7718 if (event.key === "Enter") {
7719 return isButton(element) || element.tagName === "SUMMARY" || element.tagName === "A";
7720 }
7721 if (event.key === " ") {
7722 return isButton(element) || element.tagName === "SUMMARY" || element.tagName === "INPUT" || element.tagName === "SELECT";
7723 }
7724 return false;
7725 }
7726 var symbol = /* @__PURE__ */ Symbol("command");
7727 var useCommand = createHook(
7728 function useCommand2({ clickOnEnter = true, clickOnSpace = true, ...props }) {
7729 const ref = (0, import_react10.useRef)(null);
7730 const [isNativeButton, setIsNativeButton] = (0, import_react10.useState)(false);
7731 (0, import_react10.useEffect)(() => {
7732 if (!ref.current) return;
7733 setIsNativeButton(isButton(ref.current));
7734 }, []);
7735 const [active, setActive] = (0, import_react10.useState)(false);
7736 const activeRef = (0, import_react10.useRef)(false);
7737 const disabled = disabledFromProps(props);
7738 const [isDuplicate, metadataProps] = useMetadataProps(props, symbol, true);
7739 const onKeyDownProp = props.onKeyDown;
7740 const onKeyDown = useEvent((event) => {
7741 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
7742 const element = event.currentTarget;
7743 if (event.defaultPrevented) return;
7744 if (isDuplicate) return;
7745 if (disabled) return;
7746 if (!isSelfTarget(event)) return;
7747 if (isTextField(element)) return;
7748 if (element.isContentEditable) return;
7749 const isEnter = clickOnEnter && event.key === "Enter";
7750 const isSpace = clickOnSpace && event.key === " ";
7751 const shouldPreventEnter = event.key === "Enter" && !clickOnEnter;
7752 const shouldPreventSpace = event.key === " " && !clickOnSpace;
7753 if (shouldPreventEnter || shouldPreventSpace) {
7754 event.preventDefault();
7755 return;
7756 }
7757 if (isEnter || isSpace) {
7758 const nativeClick = isNativeClick(event);
7759 if (isEnter) {
7760 if (!nativeClick) {
7761 event.preventDefault();
7762 const { view, ...eventInit } = event;
7763 const click = () => fireClickEvent(element, eventInit);
7764 if (isFirefox()) {
7765 queueBeforeEvent(element, "keyup", click);
7766 } else {
7767 queueMicrotask(click);
7768 }
7769 }
7770 } else if (isSpace) {
7771 activeRef.current = true;
7772 if (!nativeClick) {
7773 event.preventDefault();
7774 setActive(true);
7775 }
7776 }
7777 }
7778 });
7779 const onKeyUpProp = props.onKeyUp;
7780 const onKeyUp = useEvent((event) => {
7781 onKeyUpProp == null ? void 0 : onKeyUpProp(event);
7782 if (event.defaultPrevented) return;
7783 if (isDuplicate) return;
7784 if (disabled) return;
7785 if (event.metaKey) return;
7786 const isSpace = clickOnSpace && event.key === " ";
7787 if (activeRef.current && isSpace) {
7788 activeRef.current = false;
7789 if (!isNativeClick(event)) {
7790 event.preventDefault();
7791 setActive(false);
7792 const element = event.currentTarget;
7793 const { view, ...eventInit } = event;
7794 queueMicrotask(() => fireClickEvent(element, eventInit));
7795 }
7796 }
7797 });
7798 props = {
7799 "data-active": active || void 0,
7800 type: isNativeButton ? "button" : void 0,
7801 ...metadataProps,
7802 ...props,
7803 ref: useMergeRefs(ref, props.ref),
7804 onKeyDown,
7805 onKeyUp
7806 };
7807 props = useFocusable(props);
7808 return props;
7809 }
7810 );
7811 var Command = forwardRef22(function Command2(props) {
7812 const htmlProps = useCommand(props);
7813 return createElement3(TagName3, htmlProps);
7814 });
7815
7816 // node_modules/@ariakit/core/esm/__chunks/SXKM4CGU.js
7817 function getInternal(store, key) {
7818 const internals = store.__unstableInternals;
7819 invariant(internals, "Invalid store");
7820 return internals[key];
7821 }
7822 function createStore(initialState, ...stores) {
7823 let state = initialState;
7824 let prevStateBatch = state;
7825 let lastUpdate = /* @__PURE__ */ Symbol();
7826 let destroy = noop2;
7827 const instances = /* @__PURE__ */ new Set();
7828 const updatedKeys = /* @__PURE__ */ new Set();
7829 const setups = /* @__PURE__ */ new Set();
7830 const listeners = /* @__PURE__ */ new Set();
7831 const batchListeners = /* @__PURE__ */ new Set();
7832 const disposables = /* @__PURE__ */ new WeakMap();
7833 const listenerKeys = /* @__PURE__ */ new WeakMap();
7834 const storeSetup = (callback) => {
7835 setups.add(callback);
7836 return () => setups.delete(callback);
7837 };
7838 const storeInit = () => {
7839 const initialized = instances.size;
7840 const instance = /* @__PURE__ */ Symbol();
7841 instances.add(instance);
7842 const maybeDestroy = () => {
7843 instances.delete(instance);
7844 if (instances.size) return;
7845 destroy();
7846 };
7847 if (initialized) return maybeDestroy;
7848 const desyncs = getKeys(state).map(
7849 (key) => chain(
7850 ...stores.map((store) => {
7851 var _a;
7852 const storeState = (_a = store == null ? void 0 : store.getState) == null ? void 0 : _a.call(store);
7853 if (!storeState) return;
7854 if (!hasOwnProperty(storeState, key)) return;
7855 return sync(store, [key], (state2) => {
7856 setState(
7857 key,
7858 state2[key],
7859 // @ts-expect-error - Not public API. This is just to prevent
7860 // infinite loops.
7861 true
7862 );
7863 });
7864 })
7865 )
7866 );
7867 const teardowns = [];
7868 for (const setup2 of setups) {
7869 teardowns.push(setup2());
7870 }
7871 const cleanups = stores.map(init);
7872 destroy = chain(...desyncs, ...teardowns, ...cleanups);
7873 return maybeDestroy;
7874 };
7875 const sub = (keys, listener, set2 = listeners) => {
7876 set2.add(listener);
7877 listenerKeys.set(listener, keys);
7878 return () => {
7879 var _a;
7880 (_a = disposables.get(listener)) == null ? void 0 : _a();
7881 disposables.delete(listener);
7882 listenerKeys.delete(listener);
7883 set2.delete(listener);
7884 };
7885 };
7886 const storeSubscribe = (keys, listener) => sub(keys, listener);
7887 const storeSync = (keys, listener) => {
7888 disposables.set(listener, listener(state, state));
7889 return sub(keys, listener);
7890 };
7891 const storeBatch = (keys, listener) => {
7892 disposables.set(listener, listener(state, prevStateBatch));
7893 return sub(keys, listener, batchListeners);
7894 };
7895 const storePick = (keys) => createStore(pick(state, keys), finalStore);
7896 const storeOmit = (keys) => createStore(omit(state, keys), finalStore);
7897 const getState = () => state;
7898 const setState = (key, value, fromStores = false) => {
7899 var _a;
7900 if (!hasOwnProperty(state, key)) return;
7901 const nextValue = applyState(value, state[key]);
7902 if (nextValue === state[key]) return;
7903 if (!fromStores) {
7904 for (const store of stores) {
7905 (_a = store == null ? void 0 : store.setState) == null ? void 0 : _a.call(store, key, nextValue);
7906 }
7907 }
7908 const prevState = state;
7909 state = { ...state, [key]: nextValue };
7910 const thisUpdate = /* @__PURE__ */ Symbol();
7911 lastUpdate = thisUpdate;
7912 updatedKeys.add(key);
7913 const run = (listener, prev, uKeys) => {
7914 var _a2;
7915 const keys = listenerKeys.get(listener);
7916 const updated = (k) => uKeys ? uKeys.has(k) : k === key;
7917 if (!keys || keys.some(updated)) {
7918 (_a2 = disposables.get(listener)) == null ? void 0 : _a2();
7919 disposables.set(listener, listener(state, prev));
7920 }
7921 };
7922 for (const listener of listeners) {
7923 run(listener, prevState);
7924 }
7925 queueMicrotask(() => {
7926 if (lastUpdate !== thisUpdate) return;
7927 const snapshot = state;
7928 for (const listener of batchListeners) {
7929 run(listener, prevStateBatch, updatedKeys);
7930 }
7931 prevStateBatch = snapshot;
7932 updatedKeys.clear();
7933 });
7934 };
7935 const finalStore = {
7936 getState,
7937 setState,
7938 __unstableInternals: {
7939 setup: storeSetup,
7940 init: storeInit,
7941 subscribe: storeSubscribe,
7942 sync: storeSync,
7943 batch: storeBatch,
7944 pick: storePick,
7945 omit: storeOmit
7946 }
7947 };
7948 return finalStore;
7949 }
7950 function setup(store, ...args) {
7951 if (!store) return;
7952 return getInternal(store, "setup")(...args);
7953 }
7954 function init(store, ...args) {
7955 if (!store) return;
7956 return getInternal(store, "init")(...args);
7957 }
7958 function subscribe(store, ...args) {
7959 if (!store) return;
7960 return getInternal(store, "subscribe")(...args);
7961 }
7962 function sync(store, ...args) {
7963 if (!store) return;
7964 return getInternal(store, "sync")(...args);
7965 }
7966 function batch(store, ...args) {
7967 if (!store) return;
7968 return getInternal(store, "batch")(...args);
7969 }
7970 function omit2(store, ...args) {
7971 if (!store) return;
7972 return getInternal(store, "omit")(...args);
7973 }
7974 function pick2(store, ...args) {
7975 if (!store) return;
7976 return getInternal(store, "pick")(...args);
7977 }
7978 function mergeStore(...stores) {
7979 var _a;
7980 const initialState = {};
7981 for (const store2 of stores) {
7982 const nextState = (_a = store2 == null ? void 0 : store2.getState) == null ? void 0 : _a.call(store2);
7983 if (nextState) {
7984 Object.assign(initialState, nextState);
7985 }
7986 }
7987 const store = createStore(initialState, ...stores);
7988 return Object.assign({}, ...stores, store);
7989 }
7990 function throwOnConflictingProps(props, store) {
7991 if (false) return;
7992 if (!store) return;
7993 const defaultKeys = Object.entries(props).filter(([key, value]) => key.startsWith("default") && value !== void 0).map(([key]) => {
7994 var _a;
7995 const stateKey = key.replace("default", "");
7996 return `${((_a = stateKey[0]) == null ? void 0 : _a.toLowerCase()) || ""}${stateKey.slice(1)}`;
7997 });
7998 if (!defaultKeys.length) return;
7999 const storeState = store.getState();
8000 const conflictingProps = defaultKeys.filter(
8001 (key) => hasOwnProperty(storeState, key)
8002 );
8003 if (!conflictingProps.length) return;
8004 throw new Error(
8005 `Passing a store prop in conjunction with a default state is not supported.
8006
8007 const store = useSelectStore();
8008 <SelectProvider store={store} defaultValue="Apple" />
8009 ^ ^
8010
8011 Instead, pass the default state to the topmost store:
8012
8013 const store = useSelectStore({ defaultValue: "Apple" });
8014 <SelectProvider store={store} />
8015
8016 See https://github.com/ariakit/ariakit/pull/2745 for more details.
8017
8018 If there's a particular need for this, please submit a feature request at https://github.com/ariakit/ariakit
8019 `
8020 );
8021 }
8022
8023 // node_modules/@ariakit/react-core/esm/__chunks/Q5W46E73.js
8024 var React7 = __toESM(require_react(), 1);
8025 var import_shim = __toESM(require_shim(), 1);
8026 var { useSyncExternalStore } = import_shim.default;
8027 var noopSubscribe = () => () => {
8028 };
8029 function useStoreState(store, keyOrSelector = identity) {
8030 const storeSubscribe = React7.useCallback(
8031 (callback) => {
8032 if (!store) return noopSubscribe();
8033 return subscribe(store, null, callback);
8034 },
8035 [store]
8036 );
8037 const getSnapshot = () => {
8038 const key = typeof keyOrSelector === "string" ? keyOrSelector : null;
8039 const selector2 = typeof keyOrSelector === "function" ? keyOrSelector : null;
8040 const state = store == null ? void 0 : store.getState();
8041 if (selector2) return selector2(state);
8042 if (!state) return;
8043 if (!key) return;
8044 if (!hasOwnProperty(state, key)) return;
8045 return state[key];
8046 };
8047 return useSyncExternalStore(storeSubscribe, getSnapshot, getSnapshot);
8048 }
8049 function useStoreStateObject(store, object) {
8050 const objRef = React7.useRef(
8051 {}
8052 );
8053 const storeSubscribe = React7.useCallback(
8054 (callback) => {
8055 if (!store) return noopSubscribe();
8056 return subscribe(store, null, callback);
8057 },
8058 [store]
8059 );
8060 const getSnapshot = () => {
8061 const state = store == null ? void 0 : store.getState();
8062 let updated = false;
8063 const obj = objRef.current;
8064 for (const prop in object) {
8065 const keyOrSelector = object[prop];
8066 if (typeof keyOrSelector === "function") {
8067 const value = keyOrSelector(state);
8068 if (value !== obj[prop]) {
8069 obj[prop] = value;
8070 updated = true;
8071 }
8072 }
8073 if (typeof keyOrSelector === "string") {
8074 if (!state) continue;
8075 if (!hasOwnProperty(state, keyOrSelector)) continue;
8076 const value = state[keyOrSelector];
8077 if (value !== obj[prop]) {
8078 obj[prop] = value;
8079 updated = true;
8080 }
8081 }
8082 }
8083 if (updated) {
8084 objRef.current = { ...obj };
8085 }
8086 return objRef.current;
8087 };
8088 return useSyncExternalStore(storeSubscribe, getSnapshot, getSnapshot);
8089 }
8090 function useStoreProps(store, props, key, setKey) {
8091 const value = hasOwnProperty(props, key) ? props[key] : void 0;
8092 const setValue = setKey ? props[setKey] : void 0;
8093 const propsRef = useLiveRef({ value, setValue });
8094 useSafeLayoutEffect(() => {
8095 return sync(store, [key], (state, prev) => {
8096 const { value: value2, setValue: setValue2 } = propsRef.current;
8097 if (!setValue2) return;
8098 if (state[key] === prev[key]) return;
8099 if (state[key] === value2) return;
8100 setValue2(state[key]);
8101 });
8102 }, [store, key]);
8103 useSafeLayoutEffect(() => {
8104 if (value === void 0) return;
8105 store.setState(key, value);
8106 return batch(store, [key], () => {
8107 if (value === void 0) return;
8108 store.setState(key, value);
8109 });
8110 });
8111 }
8112 function useStore(createStore2, props) {
8113 const [store, setStore] = React7.useState(() => createStore2(props));
8114 useSafeLayoutEffect(() => init(store), [store]);
8115 const useState210 = React7.useCallback(
8116 (keyOrSelector) => useStoreState(store, keyOrSelector),
8117 [store]
8118 );
8119 const memoizedStore = React7.useMemo(
8120 () => ({ ...store, useState: useState210 }),
8121 [store, useState210]
8122 );
8123 const updateStore = useEvent(() => {
8124 setStore((store2) => createStore2({ ...props, ...store2.getState() }));
8125 });
8126 return [memoizedStore, updateStore];
8127 }
8128
8129 // node_modules/@ariakit/react-core/esm/__chunks/WZWDIE3S.js
8130 var import_react11 = __toESM(require_react(), 1);
8131 var import_jsx_runtime55 = __toESM(require_jsx_runtime(), 1);
8132 var TagName4 = "button";
8133 function isEditableElement(element) {
8134 if (isTextbox(element)) return true;
8135 return element.tagName === "INPUT" && !isButton(element);
8136 }
8137 function getNextPageOffset(scrollingElement, pageUp = false) {
8138 const height = scrollingElement.clientHeight;
8139 const { top } = scrollingElement.getBoundingClientRect();
8140 const pageSize = Math.max(height * 0.875, height - 40) * 1.5;
8141 const pageOffset = pageUp ? height - pageSize + top : pageSize + top;
8142 if (scrollingElement.tagName === "HTML") {
8143 return pageOffset + scrollingElement.scrollTop;
8144 }
8145 return pageOffset;
8146 }
8147 function getItemOffset(itemElement, pageUp = false) {
8148 const { top } = itemElement.getBoundingClientRect();
8149 if (pageUp) {
8150 return top + itemElement.clientHeight;
8151 }
8152 return top;
8153 }
8154 function findNextPageItemId(element, store, next, pageUp = false) {
8155 var _a;
8156 if (!store) return;
8157 if (!next) return;
8158 const { renderedItems } = store.getState();
8159 const scrollingElement = getScrollingElement(element);
8160 if (!scrollingElement) return;
8161 const nextPageOffset = getNextPageOffset(scrollingElement, pageUp);
8162 let id;
8163 let prevDifference;
8164 for (let i2 = 0; i2 < renderedItems.length; i2 += 1) {
8165 const previousId = id;
8166 id = next(i2);
8167 if (!id) break;
8168 if (id === previousId) continue;
8169 const itemElement = (_a = getEnabledItem(store, id)) == null ? void 0 : _a.element;
8170 if (!itemElement) continue;
8171 const itemOffset = getItemOffset(itemElement, pageUp);
8172 const difference = itemOffset - nextPageOffset;
8173 const absDifference = Math.abs(difference);
8174 if (pageUp && difference <= 0 || !pageUp && difference >= 0) {
8175 if (prevDifference !== void 0 && prevDifference < absDifference) {
8176 id = previousId;
8177 }
8178 break;
8179 }
8180 prevDifference = absDifference;
8181 }
8182 return id;
8183 }
8184 function targetIsAnotherItem(event, store) {
8185 if (isSelfTarget(event)) return false;
8186 return isItem(store, event.target);
8187 }
8188 var useCompositeItem = createHook(
8189 function useCompositeItem2({
8190 store,
8191 rowId: rowIdProp,
8192 preventScrollOnKeyDown = false,
8193 moveOnKeyPress = true,
8194 tabbable = false,
8195 getItem: getItemProp,
8196 "aria-setsize": ariaSetSizeProp,
8197 "aria-posinset": ariaPosInSetProp,
8198 ...props
8199 }) {
8200 const context = useCompositeContext();
8201 store = store || context;
8202 const id = useId3(props.id);
8203 const ref = (0, import_react11.useRef)(null);
8204 const row = (0, import_react11.useContext)(CompositeRowContext);
8205 const disabled = disabledFromProps(props);
8206 const trulyDisabled = disabled && !props.accessibleWhenDisabled;
8207 const {
8208 rowId,
8209 baseElement,
8210 isActiveItem,
8211 ariaSetSize,
8212 ariaPosInSet,
8213 isTabbable
8214 } = useStoreStateObject(store, {
8215 rowId(state) {
8216 if (rowIdProp) return rowIdProp;
8217 if (!state) return;
8218 if (!(row == null ? void 0 : row.baseElement)) return;
8219 if (row.baseElement !== state.baseElement) return;
8220 return row.id;
8221 },
8222 baseElement(state) {
8223 return (state == null ? void 0 : state.baseElement) || void 0;
8224 },
8225 isActiveItem(state) {
8226 return !!state && state.activeId === id;
8227 },
8228 ariaSetSize(state) {
8229 if (ariaSetSizeProp != null) return ariaSetSizeProp;
8230 if (!state) return;
8231 if (!(row == null ? void 0 : row.ariaSetSize)) return;
8232 if (row.baseElement !== state.baseElement) return;
8233 return row.ariaSetSize;
8234 },
8235 ariaPosInSet(state) {
8236 if (ariaPosInSetProp != null) return ariaPosInSetProp;
8237 if (!state) return;
8238 if (!(row == null ? void 0 : row.ariaPosInSet)) return;
8239 if (row.baseElement !== state.baseElement) return;
8240 const itemsInRow = state.renderedItems.filter(
8241 (item) => item.rowId === rowId
8242 );
8243 return row.ariaPosInSet + itemsInRow.findIndex((item) => item.id === id);
8244 },
8245 isTabbable(state) {
8246 if (!(state == null ? void 0 : state.renderedItems.length)) return true;
8247 if (state.virtualFocus) return false;
8248 if (tabbable) return true;
8249 if (state.activeId === null) return false;
8250 const item = store == null ? void 0 : store.item(state.activeId);
8251 if (item == null ? void 0 : item.disabled) return true;
8252 if (!(item == null ? void 0 : item.element)) return true;
8253 return state.activeId === id;
8254 }
8255 });
8256 const getItem = (0, import_react11.useCallback)(
8257 (item) => {
8258 var _a;
8259 const nextItem = {
8260 ...item,
8261 id: id || item.id,
8262 rowId,
8263 disabled: !!trulyDisabled,
8264 children: (_a = item.element) == null ? void 0 : _a.textContent
8265 };
8266 if (getItemProp) {
8267 return getItemProp(nextItem);
8268 }
8269 return nextItem;
8270 },
8271 [id, rowId, trulyDisabled, getItemProp]
8272 );
8273 const onFocusProp = props.onFocus;
8274 const hasFocusedComposite = (0, import_react11.useRef)(false);
8275 const onFocus = useEvent((event) => {
8276 onFocusProp == null ? void 0 : onFocusProp(event);
8277 if (event.defaultPrevented) return;
8278 if (isPortalEvent(event)) return;
8279 if (!id) return;
8280 if (!store) return;
8281 if (targetIsAnotherItem(event, store)) return;
8282 const { virtualFocus, baseElement: baseElement2 } = store.getState();
8283 store.setActiveId(id);
8284 if (isTextbox(event.currentTarget)) {
8285 selectTextField(event.currentTarget);
8286 }
8287 if (!virtualFocus) return;
8288 if (!isSelfTarget(event)) return;
8289 if (isEditableElement(event.currentTarget)) return;
8290 if (!(baseElement2 == null ? void 0 : baseElement2.isConnected)) return;
8291 if (isSafari() && event.currentTarget.hasAttribute("data-autofocus")) {
8292 event.currentTarget.scrollIntoView({
8293 block: "nearest",
8294 inline: "nearest"
8295 });
8296 }
8297 hasFocusedComposite.current = true;
8298 const fromComposite = event.relatedTarget === baseElement2 || isItem(store, event.relatedTarget);
8299 if (fromComposite) {
8300 focusSilently(baseElement2);
8301 } else {
8302 baseElement2.focus();
8303 }
8304 });
8305 const onBlurCaptureProp = props.onBlurCapture;
8306 const onBlurCapture = useEvent((event) => {
8307 onBlurCaptureProp == null ? void 0 : onBlurCaptureProp(event);
8308 if (event.defaultPrevented) return;
8309 const state = store == null ? void 0 : store.getState();
8310 if ((state == null ? void 0 : state.virtualFocus) && hasFocusedComposite.current) {
8311 hasFocusedComposite.current = false;
8312 event.preventDefault();
8313 event.stopPropagation();
8314 }
8315 });
8316 const onKeyDownProp = props.onKeyDown;
8317 const preventScrollOnKeyDownProp = useBooleanEvent(preventScrollOnKeyDown);
8318 const moveOnKeyPressProp = useBooleanEvent(moveOnKeyPress);
8319 const onKeyDown = useEvent((event) => {
8320 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
8321 if (event.defaultPrevented) return;
8322 if (!isSelfTarget(event)) return;
8323 if (!store) return;
8324 const { currentTarget } = event;
8325 const state = store.getState();
8326 const item = store.item(id);
8327 const isGrid2 = !!(item == null ? void 0 : item.rowId);
8328 const isVertical = state.orientation !== "horizontal";
8329 const isHorizontal = state.orientation !== "vertical";
8330 const canHomeEnd = () => {
8331 if (isGrid2) return true;
8332 if (isHorizontal) return true;
8333 if (!state.baseElement) return true;
8334 if (!isTextField(state.baseElement)) return true;
8335 return false;
8336 };
8337 const keyMap = {
8338 ArrowUp: (isGrid2 || isVertical) && store.up,
8339 ArrowRight: (isGrid2 || isHorizontal) && store.next,
8340 ArrowDown: (isGrid2 || isVertical) && store.down,
8341 ArrowLeft: (isGrid2 || isHorizontal) && store.previous,
8342 Home: () => {
8343 if (!canHomeEnd()) return;
8344 if (!isGrid2 || event.ctrlKey) {
8345 return store == null ? void 0 : store.first();
8346 }
8347 return store == null ? void 0 : store.previous(-1);
8348 },
8349 End: () => {
8350 if (!canHomeEnd()) return;
8351 if (!isGrid2 || event.ctrlKey) {
8352 return store == null ? void 0 : store.last();
8353 }
8354 return store == null ? void 0 : store.next(-1);
8355 },
8356 PageUp: () => {
8357 return findNextPageItemId(currentTarget, store, store == null ? void 0 : store.up, true);
8358 },
8359 PageDown: () => {
8360 return findNextPageItemId(currentTarget, store, store == null ? void 0 : store.down);
8361 }
8362 };
8363 const action = keyMap[event.key];
8364 if (action) {
8365 if (isTextbox(currentTarget)) {
8366 const selection = getTextboxSelection(currentTarget);
8367 const isLeft = isHorizontal && event.key === "ArrowLeft";
8368 const isRight = isHorizontal && event.key === "ArrowRight";
8369 const isUp = isVertical && event.key === "ArrowUp";
8370 const isDown = isVertical && event.key === "ArrowDown";
8371 if (isRight || isDown) {
8372 const { length: valueLength } = getTextboxValue(currentTarget);
8373 if (selection.end !== valueLength) return;
8374 } else if ((isLeft || isUp) && selection.start !== 0) return;
8375 }
8376 const nextId = action();
8377 if (preventScrollOnKeyDownProp(event) || nextId !== void 0) {
8378 if (!moveOnKeyPressProp(event)) return;
8379 event.preventDefault();
8380 store.move(nextId);
8381 }
8382 }
8383 });
8384 const providerValue = (0, import_react11.useMemo)(
8385 () => ({ id, baseElement }),
8386 [id, baseElement]
8387 );
8388 props = useWrapElement(
8389 props,
8390 (element) => /* @__PURE__ */ (0, import_jsx_runtime55.jsx)(CompositeItemContext.Provider, { value: providerValue, children: element }),
8391 [providerValue]
8392 );
8393 props = {
8394 id,
8395 "data-active-item": isActiveItem || void 0,
8396 ...props,
8397 ref: useMergeRefs(ref, props.ref),
8398 tabIndex: isTabbable ? props.tabIndex : -1,
8399 onFocus,
8400 onBlurCapture,
8401 onKeyDown
8402 };
8403 props = useCommand(props);
8404 props = useCollectionItem({
8405 store,
8406 ...props,
8407 getItem,
8408 shouldRegisterItem: id ? props.shouldRegisterItem : false
8409 });
8410 return removeUndefinedValues({
8411 ...props,
8412 "aria-setsize": ariaSetSize,
8413 "aria-posinset": ariaPosInSet
8414 });
8415 }
8416 );
8417 var CompositeItem = memo22(
8418 forwardRef22(function CompositeItem2(props) {
8419 const htmlProps = useCompositeItem(props);
8420 return createElement3(TagName4, htmlProps);
8421 })
8422 );
8423
8424 // node_modules/@ariakit/core/esm/__chunks/7PRQYBBV.js
8425 function toArray(arg) {
8426 if (Array.isArray(arg)) {
8427 return arg;
8428 }
8429 return typeof arg !== "undefined" ? [arg] : [];
8430 }
8431 function flatten2DArray(array) {
8432 const flattened = [];
8433 for (const row of array) {
8434 flattened.push(...row);
8435 }
8436 return flattened;
8437 }
8438 function reverseArray(array) {
8439 return array.slice().reverse();
8440 }
8441
8442 // node_modules/@ariakit/react-core/esm/__chunks/ZMWF7ASR.js
8443 var import_react12 = __toESM(require_react(), 1);
8444 var import_jsx_runtime56 = __toESM(require_jsx_runtime(), 1);
8445 var TagName5 = "div";
8446 function isGrid(items) {
8447 return items.some((item) => !!item.rowId);
8448 }
8449 function isPrintableKey(event) {
8450 const target = event.target;
8451 if (target && !isTextField(target)) return false;
8452 return event.key.length === 1 && !event.ctrlKey && !event.metaKey;
8453 }
8454 function isModifierKey(event) {
8455 return event.key === "Shift" || event.key === "Control" || event.key === "Alt" || event.key === "Meta";
8456 }
8457 function useKeyboardEventProxy(store, onKeyboardEvent, previousElementRef) {
8458 return useEvent((event) => {
8459 var _a;
8460 onKeyboardEvent == null ? void 0 : onKeyboardEvent(event);
8461 if (event.defaultPrevented) return;
8462 if (event.isPropagationStopped()) return;
8463 if (!isSelfTarget(event)) return;
8464 if (isModifierKey(event)) return;
8465 if (isPrintableKey(event)) return;
8466 const state = store.getState();
8467 const activeElement = (_a = getEnabledItem(store, state.activeId)) == null ? void 0 : _a.element;
8468 if (!activeElement) return;
8469 const { view, ...eventInit } = event;
8470 const previousElement = previousElementRef == null ? void 0 : previousElementRef.current;
8471 if (activeElement !== previousElement) {
8472 activeElement.focus();
8473 }
8474 if (!fireKeyboardEvent(activeElement, event.type, eventInit)) {
8475 event.preventDefault();
8476 }
8477 if (event.currentTarget.contains(activeElement)) {
8478 event.stopPropagation();
8479 }
8480 });
8481 }
8482 function findFirstEnabledItemInTheLastRow(items) {
8483 return findFirstEnabledItem(
8484 flatten2DArray(reverseArray(groupItemsByRows(items)))
8485 );
8486 }
8487 function useScheduleFocus(store) {
8488 const [scheduled, setScheduled] = (0, import_react12.useState)(false);
8489 const schedule = (0, import_react12.useCallback)(() => setScheduled(true), []);
8490 const activeItem = store.useState(
8491 (state) => getEnabledItem(store, state.activeId)
8492 );
8493 (0, import_react12.useEffect)(() => {
8494 const activeElement = activeItem == null ? void 0 : activeItem.element;
8495 if (!scheduled) return;
8496 if (!activeElement) return;
8497 setScheduled(false);
8498 activeElement.focus({ preventScroll: true });
8499 }, [activeItem, scheduled]);
8500 return schedule;
8501 }
8502 var useComposite = createHook(
8503 function useComposite2({
8504 store,
8505 composite = true,
8506 focusOnMove = composite,
8507 moveOnKeyPress = true,
8508 ...props
8509 }) {
8510 const context = useCompositeProviderContext();
8511 store = store || context;
8512 invariant(
8513 store,
8514 "Composite must receive a `store` prop or be wrapped in a CompositeProvider component."
8515 );
8516 const ref = (0, import_react12.useRef)(null);
8517 const previousElementRef = (0, import_react12.useRef)(null);
8518 const scheduleFocus = useScheduleFocus(store);
8519 const moves = store.useState("moves");
8520 const [, setBaseElement] = useTransactionState(
8521 composite ? store.setBaseElement : null
8522 );
8523 (0, import_react12.useEffect)(() => {
8524 var _a;
8525 if (!store) return;
8526 if (!moves) return;
8527 if (!composite) return;
8528 if (!focusOnMove) return;
8529 const { activeId: activeId2 } = store.getState();
8530 const itemElement = (_a = getEnabledItem(store, activeId2)) == null ? void 0 : _a.element;
8531 if (!itemElement) return;
8532 focusIntoView(itemElement);
8533 }, [store, moves, composite, focusOnMove]);
8534 useSafeLayoutEffect(() => {
8535 if (!store) return;
8536 if (!moves) return;
8537 if (!composite) return;
8538 const { baseElement, activeId: activeId2 } = store.getState();
8539 const isSelfAcive = activeId2 === null;
8540 if (!isSelfAcive) return;
8541 if (!baseElement) return;
8542 const previousElement = previousElementRef.current;
8543 previousElementRef.current = null;
8544 if (previousElement) {
8545 fireBlurEvent(previousElement, { relatedTarget: baseElement });
8546 }
8547 if (!hasFocus(baseElement)) {
8548 baseElement.focus();
8549 }
8550 }, [store, moves, composite]);
8551 const activeId = store.useState("activeId");
8552 const virtualFocus = store.useState("virtualFocus");
8553 useSafeLayoutEffect(() => {
8554 var _a;
8555 if (!store) return;
8556 if (!composite) return;
8557 if (!virtualFocus) return;
8558 const previousElement = previousElementRef.current;
8559 previousElementRef.current = null;
8560 if (!previousElement) return;
8561 const activeElement = (_a = getEnabledItem(store, activeId)) == null ? void 0 : _a.element;
8562 const relatedTarget = activeElement || getActiveElement(previousElement);
8563 if (relatedTarget === previousElement) return;
8564 fireBlurEvent(previousElement, { relatedTarget });
8565 }, [store, activeId, virtualFocus, composite]);
8566 const onKeyDownCapture = useKeyboardEventProxy(
8567 store,
8568 props.onKeyDownCapture,
8569 previousElementRef
8570 );
8571 const onKeyUpCapture = useKeyboardEventProxy(
8572 store,
8573 props.onKeyUpCapture,
8574 previousElementRef
8575 );
8576 const onFocusCaptureProp = props.onFocusCapture;
8577 const onFocusCapture = useEvent((event) => {
8578 onFocusCaptureProp == null ? void 0 : onFocusCaptureProp(event);
8579 if (event.defaultPrevented) return;
8580 if (!store) return;
8581 const { virtualFocus: virtualFocus2 } = store.getState();
8582 if (!virtualFocus2) return;
8583 const previousActiveElement = event.relatedTarget;
8584 const isSilentlyFocused = silentlyFocused(event.currentTarget);
8585 if (isSelfTarget(event) && isSilentlyFocused) {
8586 event.stopPropagation();
8587 previousElementRef.current = previousActiveElement;
8588 }
8589 });
8590 const onFocusProp = props.onFocus;
8591 const onFocus = useEvent((event) => {
8592 onFocusProp == null ? void 0 : onFocusProp(event);
8593 if (event.defaultPrevented) return;
8594 if (!composite) return;
8595 if (!store) return;
8596 const { relatedTarget } = event;
8597 const { virtualFocus: virtualFocus2 } = store.getState();
8598 if (virtualFocus2) {
8599 if (isSelfTarget(event) && !isItem(store, relatedTarget)) {
8600 queueMicrotask(scheduleFocus);
8601 }
8602 } else if (isSelfTarget(event)) {
8603 store.setActiveId(null);
8604 }
8605 });
8606 const onBlurCaptureProp = props.onBlurCapture;
8607 const onBlurCapture = useEvent((event) => {
8608 var _a;
8609 onBlurCaptureProp == null ? void 0 : onBlurCaptureProp(event);
8610 if (event.defaultPrevented) return;
8611 if (!store) return;
8612 const { virtualFocus: virtualFocus2, activeId: activeId2 } = store.getState();
8613 if (!virtualFocus2) return;
8614 const activeElement = (_a = getEnabledItem(store, activeId2)) == null ? void 0 : _a.element;
8615 const nextActiveElement = event.relatedTarget;
8616 const nextActiveElementIsItem = isItem(store, nextActiveElement);
8617 const previousElement = previousElementRef.current;
8618 previousElementRef.current = null;
8619 if (isSelfTarget(event) && nextActiveElementIsItem) {
8620 if (nextActiveElement === activeElement) {
8621 if (previousElement && previousElement !== nextActiveElement) {
8622 fireBlurEvent(previousElement, event);
8623 }
8624 } else if (activeElement) {
8625 fireBlurEvent(activeElement, event);
8626 } else if (previousElement) {
8627 fireBlurEvent(previousElement, event);
8628 }
8629 event.stopPropagation();
8630 } else {
8631 const targetIsItem = isItem(store, event.target);
8632 if (!targetIsItem && activeElement) {
8633 fireBlurEvent(activeElement, event);
8634 }
8635 }
8636 });
8637 const onKeyDownProp = props.onKeyDown;
8638 const moveOnKeyPressProp = useBooleanEvent(moveOnKeyPress);
8639 const onKeyDown = useEvent((event) => {
8640 var _a;
8641 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
8642 if (event.nativeEvent.isComposing) return;
8643 if (event.defaultPrevented) return;
8644 if (!store) return;
8645 if (!isSelfTarget(event)) return;
8646 const { orientation, renderedItems, activeId: activeId2 } = store.getState();
8647 const activeItem = getEnabledItem(store, activeId2);
8648 if ((_a = activeItem == null ? void 0 : activeItem.element) == null ? void 0 : _a.isConnected) return;
8649 const isVertical = orientation !== "horizontal";
8650 const isHorizontal = orientation !== "vertical";
8651 const grid = isGrid(renderedItems);
8652 const isHorizontalKey = event.key === "ArrowLeft" || event.key === "ArrowRight" || event.key === "Home" || event.key === "End";
8653 if (isHorizontalKey && isTextField(event.currentTarget)) return;
8654 const up = () => {
8655 if (grid) {
8656 const item = findFirstEnabledItemInTheLastRow(renderedItems);
8657 return item == null ? void 0 : item.id;
8658 }
8659 return store == null ? void 0 : store.last();
8660 };
8661 const keyMap = {
8662 ArrowUp: (grid || isVertical) && up,
8663 ArrowRight: (grid || isHorizontal) && store.first,
8664 ArrowDown: (grid || isVertical) && store.first,
8665 ArrowLeft: (grid || isHorizontal) && store.last,
8666 Home: store.first,
8667 End: store.last,
8668 PageUp: store.first,
8669 PageDown: store.last
8670 };
8671 const action = keyMap[event.key];
8672 if (action) {
8673 const id = action();
8674 if (id !== void 0) {
8675 if (!moveOnKeyPressProp(event)) return;
8676 event.preventDefault();
8677 store.move(id);
8678 }
8679 }
8680 });
8681 props = useWrapElement(
8682 props,
8683 (element) => /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(CompositeContextProvider, { value: store, children: element }),
8684 [store]
8685 );
8686 const activeDescendant = store.useState((state) => {
8687 var _a;
8688 if (!store) return;
8689 if (!composite) return;
8690 if (!state.virtualFocus) return;
8691 return (_a = getEnabledItem(store, state.activeId)) == null ? void 0 : _a.id;
8692 });
8693 props = {
8694 "aria-activedescendant": activeDescendant,
8695 ...props,
8696 ref: useMergeRefs(ref, setBaseElement, props.ref),
8697 onKeyDownCapture,
8698 onKeyUpCapture,
8699 onFocusCapture,
8700 onFocus,
8701 onBlurCapture,
8702 onKeyDown
8703 };
8704 const focusable = store.useState(
8705 (state) => composite && (state.virtualFocus || state.activeId === null)
8706 );
8707 props = useFocusable({ focusable, ...props });
8708 return props;
8709 }
8710 );
8711 var Composite5 = forwardRef22(function Composite22(props) {
8712 const htmlProps = useComposite(props);
8713 return createElement3(TagName5, htmlProps);
8714 });
8715
8716 // node_modules/@ariakit/react-core/esm/__chunks/LVDQFHCH.js
8717 var ctx3 = createStoreContext();
8718 var useDisclosureContext = ctx3.useContext;
8719 var useDisclosureScopedContext = ctx3.useScopedContext;
8720 var useDisclosureProviderContext = ctx3.useProviderContext;
8721 var DisclosureContextProvider = ctx3.ContextProvider;
8722 var DisclosureScopedContextProvider = ctx3.ScopedContextProvider;
8723
8724 // node_modules/@ariakit/react-core/esm/__chunks/A62MDFCW.js
8725 var import_react13 = __toESM(require_react(), 1);
8726 var ctx4 = createStoreContext(
8727 [DisclosureContextProvider],
8728 [DisclosureScopedContextProvider]
8729 );
8730 var useDialogContext = ctx4.useContext;
8731 var useDialogScopedContext = ctx4.useScopedContext;
8732 var useDialogProviderContext = ctx4.useProviderContext;
8733 var DialogContextProvider = ctx4.ContextProvider;
8734 var DialogScopedContextProvider = ctx4.ScopedContextProvider;
8735 var DialogHeadingContext = (0, import_react13.createContext)(void 0);
8736 var DialogDescriptionContext = (0, import_react13.createContext)(void 0);
8737
8738 // node_modules/@ariakit/react-core/esm/__chunks/6B3RXHKP.js
8739 var import_react14 = __toESM(require_react(), 1);
8740 var import_react_dom = __toESM(require_react_dom(), 1);
8741 var import_jsx_runtime57 = __toESM(require_jsx_runtime(), 1);
8742 var TagName6 = "div";
8743 function afterTimeout(timeoutMs, cb) {
8744 const timeoutId = setTimeout(cb, timeoutMs);
8745 return () => clearTimeout(timeoutId);
8746 }
8747 function afterPaint2(cb) {
8748 let raf = requestAnimationFrame(() => {
8749 raf = requestAnimationFrame(cb);
8750 });
8751 return () => cancelAnimationFrame(raf);
8752 }
8753 function parseCSSTime(...times) {
8754 return times.join(", ").split(", ").reduce((longestTime, currentTimeString) => {
8755 const multiplier = currentTimeString.endsWith("ms") ? 1 : 1e3;
8756 const currentTime = Number.parseFloat(currentTimeString || "0s") * multiplier;
8757 if (currentTime > longestTime) return currentTime;
8758 return longestTime;
8759 }, 0);
8760 }
8761 function isHidden(mounted, hidden, alwaysVisible) {
8762 return !alwaysVisible && hidden !== false && (!mounted || !!hidden);
8763 }
8764 var useDisclosureContent = createHook(function useDisclosureContent2({ store, alwaysVisible, ...props }) {
8765 const context = useDisclosureProviderContext();
8766 store = store || context;
8767 invariant(
8768 store,
8769 "DisclosureContent must receive a `store` prop or be wrapped in a DisclosureProvider component."
8770 );
8771 const ref = (0, import_react14.useRef)(null);
8772 const id = useId3(props.id);
8773 const [transition, setTransition] = (0, import_react14.useState)(null);
8774 const open = store.useState("open");
8775 const mounted = store.useState("mounted");
8776 const animated = store.useState("animated");
8777 const contentElement = store.useState("contentElement");
8778 const otherElement = useStoreState(store.disclosure, "contentElement");
8779 useSafeLayoutEffect(() => {
8780 if (!ref.current) return;
8781 store == null ? void 0 : store.setContentElement(ref.current);
8782 }, [store]);
8783 useSafeLayoutEffect(() => {
8784 let previousAnimated;
8785 store == null ? void 0 : store.setState("animated", (animated2) => {
8786 previousAnimated = animated2;
8787 return true;
8788 });
8789 return () => {
8790 if (previousAnimated === void 0) return;
8791 store == null ? void 0 : store.setState("animated", previousAnimated);
8792 };
8793 }, [store]);
8794 useSafeLayoutEffect(() => {
8795 if (!animated) return;
8796 if (!(contentElement == null ? void 0 : contentElement.isConnected)) {
8797 setTransition(null);
8798 return;
8799 }
8800 return afterPaint2(() => {
8801 setTransition(open ? "enter" : mounted ? "leave" : null);
8802 });
8803 }, [animated, contentElement, open, mounted]);
8804 useSafeLayoutEffect(() => {
8805 if (!store) return;
8806 if (!animated) return;
8807 if (!transition) return;
8808 if (!contentElement) return;
8809 const stopAnimation = () => store == null ? void 0 : store.setState("animating", false);
8810 const stopAnimationSync = () => (0, import_react_dom.flushSync)(stopAnimation);
8811 if (transition === "leave" && open) return;
8812 if (transition === "enter" && !open) return;
8813 if (typeof animated === "number") {
8814 const timeout2 = animated;
8815 return afterTimeout(timeout2, stopAnimationSync);
8816 }
8817 const {
8818 transitionDuration,
8819 animationDuration,
8820 transitionDelay,
8821 animationDelay
8822 } = getComputedStyle(contentElement);
8823 const {
8824 transitionDuration: transitionDuration2 = "0",
8825 animationDuration: animationDuration2 = "0",
8826 transitionDelay: transitionDelay2 = "0",
8827 animationDelay: animationDelay2 = "0"
8828 } = otherElement ? getComputedStyle(otherElement) : {};
8829 const delay = parseCSSTime(
8830 transitionDelay,
8831 animationDelay,
8832 transitionDelay2,
8833 animationDelay2
8834 );
8835 const duration = parseCSSTime(
8836 transitionDuration,
8837 animationDuration,
8838 transitionDuration2,
8839 animationDuration2
8840 );
8841 const timeout = delay + duration;
8842 if (!timeout) {
8843 if (transition === "enter") {
8844 store.setState("animated", false);
8845 }
8846 stopAnimation();
8847 return;
8848 }
8849 const frameRate = 1e3 / 60;
8850 const maxTimeout = Math.max(timeout - frameRate, 0);
8851 return afterTimeout(maxTimeout, stopAnimationSync);
8852 }, [store, animated, contentElement, otherElement, open, transition]);
8853 props = useWrapElement(
8854 props,
8855 (element) => /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(DialogScopedContextProvider, { value: store, children: element }),
8856 [store]
8857 );
8858 const hidden = isHidden(mounted, props.hidden, alwaysVisible);
8859 const styleProp = props.style;
8860 const style = (0, import_react14.useMemo)(() => {
8861 if (hidden) {
8862 return { ...styleProp, display: "none" };
8863 }
8864 return styleProp;
8865 }, [hidden, styleProp]);
8866 props = {
8867 id,
8868 "data-open": open || void 0,
8869 "data-enter": transition === "enter" || void 0,
8870 "data-leave": transition === "leave" || void 0,
8871 hidden,
8872 ...props,
8873 ref: useMergeRefs(id ? store.setContentElement : null, ref, props.ref),
8874 style
8875 };
8876 return removeUndefinedValues(props);
8877 });
8878 var DisclosureContentImpl = forwardRef22(function DisclosureContentImpl2(props) {
8879 const htmlProps = useDisclosureContent(props);
8880 return createElement3(TagName6, htmlProps);
8881 });
8882 var DisclosureContent = forwardRef22(function DisclosureContent2({
8883 unmountOnHide,
8884 ...props
8885 }) {
8886 const context = useDisclosureProviderContext();
8887 const store = props.store || context;
8888 const mounted = useStoreState(
8889 store,
8890 (state) => !unmountOnHide || (state == null ? void 0 : state.mounted)
8891 );
8892 if (mounted === false) return null;
8893 return /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(DisclosureContentImpl, { ...props });
8894 });
8895
8896 // node_modules/@ariakit/core/esm/__chunks/75BJEVSH.js
8897 function createDisclosureStore(props = {}) {
8898 const store = mergeStore(
8899 props.store,
8900 omit2(props.disclosure, ["contentElement", "disclosureElement"])
8901 );
8902 throwOnConflictingProps(props, store);
8903 const syncState = store == null ? void 0 : store.getState();
8904 const open = defaultValue(
8905 props.open,
8906 syncState == null ? void 0 : syncState.open,
8907 props.defaultOpen,
8908 false
8909 );
8910 const animated = defaultValue(props.animated, syncState == null ? void 0 : syncState.animated, false);
8911 const initialState = {
8912 open,
8913 animated,
8914 animating: !!animated && open,
8915 mounted: open,
8916 contentElement: defaultValue(syncState == null ? void 0 : syncState.contentElement, null),
8917 disclosureElement: defaultValue(syncState == null ? void 0 : syncState.disclosureElement, null)
8918 };
8919 const disclosure = createStore(initialState, store);
8920 setup(
8921 disclosure,
8922 () => sync(disclosure, ["animated", "animating"], (state) => {
8923 if (state.animated) return;
8924 disclosure.setState("animating", false);
8925 })
8926 );
8927 setup(
8928 disclosure,
8929 () => subscribe(disclosure, ["open"], () => {
8930 if (!disclosure.getState().animated) return;
8931 disclosure.setState("animating", true);
8932 })
8933 );
8934 setup(
8935 disclosure,
8936 () => sync(disclosure, ["open", "animating"], (state) => {
8937 disclosure.setState("mounted", state.open || state.animating);
8938 })
8939 );
8940 return {
8941 ...disclosure,
8942 disclosure: props.disclosure,
8943 setOpen: (value) => disclosure.setState("open", value),
8944 show: () => disclosure.setState("open", true),
8945 hide: () => disclosure.setState("open", false),
8946 toggle: () => disclosure.setState("open", (open2) => !open2),
8947 stopAnimation: () => disclosure.setState("animating", false),
8948 setContentElement: (value) => disclosure.setState("contentElement", value),
8949 setDisclosureElement: (value) => disclosure.setState("disclosureElement", value)
8950 };
8951 }
8952
8953 // node_modules/@ariakit/react-core/esm/__chunks/WLZ6H5FH.js
8954 function useDisclosureStoreProps(store, update2, props) {
8955 useUpdateEffect(update2, [props.store, props.disclosure]);
8956 useStoreProps(store, props, "open", "setOpen");
8957 useStoreProps(store, props, "mounted", "setMounted");
8958 useStoreProps(store, props, "animated");
8959 return Object.assign(store, { disclosure: props.disclosure });
8960 }
8961
8962 // node_modules/@ariakit/react-core/esm/__chunks/JMU4N4M5.js
8963 var ctx5 = createStoreContext(
8964 [DialogContextProvider],
8965 [DialogScopedContextProvider]
8966 );
8967 var usePopoverContext = ctx5.useContext;
8968 var usePopoverScopedContext = ctx5.useScopedContext;
8969 var usePopoverProviderContext = ctx5.useProviderContext;
8970 var PopoverContextProvider = ctx5.ContextProvider;
8971 var PopoverScopedContextProvider = ctx5.ScopedContextProvider;
8972
8973 // node_modules/@ariakit/core/esm/__chunks/N5XGANPW.js
8974 function getCommonParent(items) {
8975 var _a;
8976 const firstItem = items.find((item) => !!item.element);
8977 const lastItem = [...items].reverse().find((item) => !!item.element);
8978 let parentElement = (_a = firstItem == null ? void 0 : firstItem.element) == null ? void 0 : _a.parentElement;
8979 while (parentElement && (lastItem == null ? void 0 : lastItem.element)) {
8980 const parent = parentElement;
8981 if (lastItem && parent.contains(lastItem.element)) {
8982 return parentElement;
8983 }
8984 parentElement = parentElement.parentElement;
8985 }
8986 return getDocument(parentElement).body;
8987 }
8988 function getPrivateStore(store) {
8989 return store == null ? void 0 : store.__unstablePrivateStore;
8990 }
8991 function createCollectionStore(props = {}) {
8992 var _a;
8993 throwOnConflictingProps(props, props.store);
8994 const syncState = (_a = props.store) == null ? void 0 : _a.getState();
8995 const items = defaultValue(
8996 props.items,
8997 syncState == null ? void 0 : syncState.items,
8998 props.defaultItems,
8999 []
9000 );
9001 const itemsMap = new Map(items.map((item) => [item.id, item]));
9002 const initialState = {
9003 items,
9004 renderedItems: defaultValue(syncState == null ? void 0 : syncState.renderedItems, [])
9005 };
9006 const syncPrivateStore = getPrivateStore(props.store);
9007 const privateStore = createStore(
9008 { items, renderedItems: initialState.renderedItems },
9009 syncPrivateStore
9010 );
9011 const collection = createStore(initialState, props.store);
9012 const sortItems = (renderedItems) => {
9013 const sortedItems = sortBasedOnDOMPosition(renderedItems, (i2) => i2.element);
9014 privateStore.setState("renderedItems", sortedItems);
9015 collection.setState("renderedItems", sortedItems);
9016 };
9017 setup(collection, () => init(privateStore));
9018 setup(privateStore, () => {
9019 return batch(privateStore, ["items"], (state) => {
9020 collection.setState("items", state.items);
9021 });
9022 });
9023 setup(privateStore, () => {
9024 return batch(privateStore, ["renderedItems"], (state) => {
9025 let firstRun = true;
9026 let raf = requestAnimationFrame(() => {
9027 const { renderedItems } = collection.getState();
9028 if (state.renderedItems === renderedItems) return;
9029 sortItems(state.renderedItems);
9030 });
9031 if (typeof IntersectionObserver !== "function") {
9032 return () => cancelAnimationFrame(raf);
9033 }
9034 const ioCallback = () => {
9035 if (firstRun) {
9036 firstRun = false;
9037 return;
9038 }
9039 cancelAnimationFrame(raf);
9040 raf = requestAnimationFrame(() => sortItems(state.renderedItems));
9041 };
9042 const root = getCommonParent(state.renderedItems);
9043 const observer = new IntersectionObserver(ioCallback, { root });
9044 for (const item of state.renderedItems) {
9045 if (!item.element) continue;
9046 observer.observe(item.element);
9047 }
9048 return () => {
9049 cancelAnimationFrame(raf);
9050 observer.disconnect();
9051 };
9052 });
9053 });
9054 const mergeItem = (item, setItems, canDeleteFromMap = false) => {
9055 let prevItem;
9056 setItems((items2) => {
9057 const index = items2.findIndex(({ id }) => id === item.id);
9058 const nextItems = items2.slice();
9059 if (index !== -1) {
9060 prevItem = items2[index];
9061 const nextItem = { ...prevItem, ...item };
9062 nextItems[index] = nextItem;
9063 itemsMap.set(item.id, nextItem);
9064 } else {
9065 nextItems.push(item);
9066 itemsMap.set(item.id, item);
9067 }
9068 return nextItems;
9069 });
9070 const unmergeItem = () => {
9071 setItems((items2) => {
9072 if (!prevItem) {
9073 if (canDeleteFromMap) {
9074 itemsMap.delete(item.id);
9075 }
9076 return items2.filter(({ id }) => id !== item.id);
9077 }
9078 const index = items2.findIndex(({ id }) => id === item.id);
9079 if (index === -1) return items2;
9080 const nextItems = items2.slice();
9081 nextItems[index] = prevItem;
9082 itemsMap.set(item.id, prevItem);
9083 return nextItems;
9084 });
9085 };
9086 return unmergeItem;
9087 };
9088 const registerItem = (item) => mergeItem(
9089 item,
9090 (getItems) => privateStore.setState("items", getItems),
9091 true
9092 );
9093 return {
9094 ...collection,
9095 registerItem,
9096 renderItem: (item) => chain(
9097 registerItem(item),
9098 mergeItem(
9099 item,
9100 (getItems) => privateStore.setState("renderedItems", getItems)
9101 )
9102 ),
9103 item: (id) => {
9104 if (!id) return null;
9105 let item = itemsMap.get(id);
9106 if (!item) {
9107 const { items: items2 } = privateStore.getState();
9108 item = items2.find((item2) => item2.id === id);
9109 if (item) {
9110 itemsMap.set(id, item);
9111 }
9112 }
9113 return item || null;
9114 },
9115 // @ts-expect-error Internal
9116 __unstablePrivateStore: privateStore
9117 };
9118 }
9119
9120 // node_modules/@ariakit/react-core/esm/__chunks/GVAFFF2B.js
9121 function useCollectionStoreProps(store, update2, props) {
9122 useUpdateEffect(update2, [props.store]);
9123 useStoreProps(store, props, "items", "setItems");
9124 return store;
9125 }
9126
9127 // node_modules/@ariakit/core/esm/__chunks/RVTIKFRL.js
9128 var NULL_ITEM = { id: null };
9129 function findFirstEnabledItem2(items, excludeId) {
9130 return items.find((item) => {
9131 if (excludeId) {
9132 return !item.disabled && item.id !== excludeId;
9133 }
9134 return !item.disabled;
9135 });
9136 }
9137 function getEnabledItems(items, excludeId) {
9138 return items.filter((item) => {
9139 if (excludeId) {
9140 return !item.disabled && item.id !== excludeId;
9141 }
9142 return !item.disabled;
9143 });
9144 }
9145 function getItemsInRow(items, rowId) {
9146 return items.filter((item) => item.rowId === rowId);
9147 }
9148 function flipItems(items, activeId, shouldInsertNullItem = false) {
9149 const index = items.findIndex((item) => item.id === activeId);
9150 return [
9151 ...items.slice(index + 1),
9152 ...shouldInsertNullItem ? [NULL_ITEM] : [],
9153 ...items.slice(0, index)
9154 ];
9155 }
9156 function groupItemsByRows2(items) {
9157 const rows = [];
9158 for (const item of items) {
9159 const row = rows.find((currentRow) => {
9160 var _a;
9161 return ((_a = currentRow[0]) == null ? void 0 : _a.rowId) === item.rowId;
9162 });
9163 if (row) {
9164 row.push(item);
9165 } else {
9166 rows.push([item]);
9167 }
9168 }
9169 return rows;
9170 }
9171 function getMaxRowLength(array) {
9172 let maxLength = 0;
9173 for (const { length } of array) {
9174 if (length > maxLength) {
9175 maxLength = length;
9176 }
9177 }
9178 return maxLength;
9179 }
9180 function createEmptyItem(rowId) {
9181 return {
9182 id: "__EMPTY_ITEM__",
9183 disabled: true,
9184 rowId
9185 };
9186 }
9187 function normalizeRows(rows, activeId, focusShift) {
9188 const maxLength = getMaxRowLength(rows);
9189 for (const row of rows) {
9190 for (let i2 = 0; i2 < maxLength; i2 += 1) {
9191 const item = row[i2];
9192 if (!item || focusShift && item.disabled) {
9193 const isFirst = i2 === 0;
9194 const previousItem = isFirst && focusShift ? findFirstEnabledItem2(row) : row[i2 - 1];
9195 row[i2] = previousItem && activeId !== previousItem.id && focusShift ? previousItem : createEmptyItem(previousItem == null ? void 0 : previousItem.rowId);
9196 }
9197 }
9198 }
9199 return rows;
9200 }
9201 function verticalizeItems(items) {
9202 const rows = groupItemsByRows2(items);
9203 const maxLength = getMaxRowLength(rows);
9204 const verticalized = [];
9205 for (let i2 = 0; i2 < maxLength; i2 += 1) {
9206 for (const row of rows) {
9207 const item = row[i2];
9208 if (item) {
9209 verticalized.push({
9210 ...item,
9211 // If there's no rowId, it means that it's not a grid composite, but
9212 // a single row instead. So, instead of verticalizing it, that is,
9213 // assigning a different rowId based on the column index, we keep it
9214 // undefined so they will be part of the same row. This is useful
9215 // when using up/down on one-dimensional composites.
9216 rowId: item.rowId ? `${i2}` : void 0
9217 });
9218 }
9219 }
9220 }
9221 return verticalized;
9222 }
9223 function createCompositeStore(props = {}) {
9224 var _a;
9225 const syncState = (_a = props.store) == null ? void 0 : _a.getState();
9226 const collection = createCollectionStore(props);
9227 const activeId = defaultValue(
9228 props.activeId,
9229 syncState == null ? void 0 : syncState.activeId,
9230 props.defaultActiveId
9231 );
9232 const initialState = {
9233 ...collection.getState(),
9234 id: defaultValue(
9235 props.id,
9236 syncState == null ? void 0 : syncState.id,
9237 `id-${Math.random().toString(36).slice(2, 8)}`
9238 ),
9239 activeId,
9240 baseElement: defaultValue(syncState == null ? void 0 : syncState.baseElement, null),
9241 includesBaseElement: defaultValue(
9242 props.includesBaseElement,
9243 syncState == null ? void 0 : syncState.includesBaseElement,
9244 activeId === null
9245 ),
9246 moves: defaultValue(syncState == null ? void 0 : syncState.moves, 0),
9247 orientation: defaultValue(
9248 props.orientation,
9249 syncState == null ? void 0 : syncState.orientation,
9250 "both"
9251 ),
9252 rtl: defaultValue(props.rtl, syncState == null ? void 0 : syncState.rtl, false),
9253 virtualFocus: defaultValue(
9254 props.virtualFocus,
9255 syncState == null ? void 0 : syncState.virtualFocus,
9256 false
9257 ),
9258 focusLoop: defaultValue(props.focusLoop, syncState == null ? void 0 : syncState.focusLoop, false),
9259 focusWrap: defaultValue(props.focusWrap, syncState == null ? void 0 : syncState.focusWrap, false),
9260 focusShift: defaultValue(props.focusShift, syncState == null ? void 0 : syncState.focusShift, false)
9261 };
9262 const composite = createStore(initialState, collection, props.store);
9263 setup(
9264 composite,
9265 () => sync(composite, ["renderedItems", "activeId"], (state) => {
9266 composite.setState("activeId", (activeId2) => {
9267 var _a2;
9268 if (activeId2 !== void 0) return activeId2;
9269 return (_a2 = findFirstEnabledItem2(state.renderedItems)) == null ? void 0 : _a2.id;
9270 });
9271 })
9272 );
9273 const getNextId = (direction = "next", options = {}) => {
9274 var _a2, _b;
9275 const defaultState = composite.getState();
9276 const {
9277 skip = 0,
9278 activeId: activeId2 = defaultState.activeId,
9279 focusShift = defaultState.focusShift,
9280 focusLoop = defaultState.focusLoop,
9281 focusWrap = defaultState.focusWrap,
9282 includesBaseElement = defaultState.includesBaseElement,
9283 renderedItems = defaultState.renderedItems,
9284 rtl = defaultState.rtl
9285 } = options;
9286 const isVerticalDirection = direction === "up" || direction === "down";
9287 const isNextDirection = direction === "next" || direction === "down";
9288 const canReverse = isNextDirection ? rtl && !isVerticalDirection : !rtl || isVerticalDirection;
9289 const canShift = focusShift && !skip;
9290 let items = !isVerticalDirection ? renderedItems : flatten2DArray(
9291 normalizeRows(groupItemsByRows2(renderedItems), activeId2, canShift)
9292 );
9293 items = canReverse ? reverseArray(items) : items;
9294 items = isVerticalDirection ? verticalizeItems(items) : items;
9295 if (activeId2 == null) {
9296 return (_a2 = findFirstEnabledItem2(items)) == null ? void 0 : _a2.id;
9297 }
9298 const activeItem = items.find((item) => item.id === activeId2);
9299 if (!activeItem) {
9300 return (_b = findFirstEnabledItem2(items)) == null ? void 0 : _b.id;
9301 }
9302 const isGrid2 = items.some((item) => item.rowId);
9303 const activeIndex = items.indexOf(activeItem);
9304 const nextItems = items.slice(activeIndex + 1);
9305 const nextItemsInRow = getItemsInRow(nextItems, activeItem.rowId);
9306 if (skip) {
9307 const nextEnabledItemsInRow = getEnabledItems(nextItemsInRow, activeId2);
9308 const nextItem2 = nextEnabledItemsInRow.slice(skip)[0] || // If we can't find an item, just return the last one.
9309 nextEnabledItemsInRow[nextEnabledItemsInRow.length - 1];
9310 return nextItem2 == null ? void 0 : nextItem2.id;
9311 }
9312 const canLoop = focusLoop && (isVerticalDirection ? focusLoop !== "horizontal" : focusLoop !== "vertical");
9313 const canWrap = isGrid2 && focusWrap && (isVerticalDirection ? focusWrap !== "horizontal" : focusWrap !== "vertical");
9314 const hasNullItem = isNextDirection ? (!isGrid2 || isVerticalDirection) && canLoop && includesBaseElement : isVerticalDirection ? includesBaseElement : false;
9315 if (canLoop) {
9316 const loopItems = canWrap && !hasNullItem ? items : getItemsInRow(items, activeItem.rowId);
9317 const sortedItems = flipItems(loopItems, activeId2, hasNullItem);
9318 const nextItem2 = findFirstEnabledItem2(sortedItems, activeId2);
9319 return nextItem2 == null ? void 0 : nextItem2.id;
9320 }
9321 if (canWrap) {
9322 const nextItem2 = findFirstEnabledItem2(
9323 // We can use nextItems, which contains all the next items, including
9324 // items from other rows, to wrap between rows. However, if there is a
9325 // null item (the composite container), we'll only use the next items in
9326 // the row. So moving next from the last item will focus on the
9327 // composite container. On grid composites, horizontal navigation never
9328 // focuses on the composite container, only vertical.
9329 hasNullItem ? nextItemsInRow : nextItems,
9330 activeId2
9331 );
9332 const nextId = hasNullItem ? (nextItem2 == null ? void 0 : nextItem2.id) || null : nextItem2 == null ? void 0 : nextItem2.id;
9333 return nextId;
9334 }
9335 const nextItem = findFirstEnabledItem2(nextItemsInRow, activeId2);
9336 if (!nextItem && hasNullItem) {
9337 return null;
9338 }
9339 return nextItem == null ? void 0 : nextItem.id;
9340 };
9341 return {
9342 ...collection,
9343 ...composite,
9344 setBaseElement: (element) => composite.setState("baseElement", element),
9345 setActiveId: (id) => composite.setState("activeId", id),
9346 move: (id) => {
9347 if (id === void 0) return;
9348 composite.setState("activeId", id);
9349 composite.setState("moves", (moves) => moves + 1);
9350 },
9351 first: () => {
9352 var _a2;
9353 return (_a2 = findFirstEnabledItem2(composite.getState().renderedItems)) == null ? void 0 : _a2.id;
9354 },
9355 last: () => {
9356 var _a2;
9357 return (_a2 = findFirstEnabledItem2(reverseArray(composite.getState().renderedItems))) == null ? void 0 : _a2.id;
9358 },
9359 next: (options) => {
9360 if (options !== void 0 && typeof options === "number") {
9361 options = { skip: options };
9362 }
9363 return getNextId("next", options);
9364 },
9365 previous: (options) => {
9366 if (options !== void 0 && typeof options === "number") {
9367 options = { skip: options };
9368 }
9369 return getNextId("previous", options);
9370 },
9371 down: (options) => {
9372 if (options !== void 0 && typeof options === "number") {
9373 options = { skip: options };
9374 }
9375 return getNextId("down", options);
9376 },
9377 up: (options) => {
9378 if (options !== void 0 && typeof options === "number") {
9379 options = { skip: options };
9380 }
9381 return getNextId("up", options);
9382 }
9383 };
9384 }
9385
9386 // node_modules/@ariakit/react-core/esm/__chunks/IQYAUKXT.js
9387 function useCompositeStoreOptions(props) {
9388 const id = useId3(props.id);
9389 return { id, ...props };
9390 }
9391 function useCompositeStoreProps(store, update2, props) {
9392 store = useCollectionStoreProps(store, update2, props);
9393 useStoreProps(store, props, "activeId", "setActiveId");
9394 useStoreProps(store, props, "includesBaseElement");
9395 useStoreProps(store, props, "virtualFocus");
9396 useStoreProps(store, props, "orientation");
9397 useStoreProps(store, props, "rtl");
9398 useStoreProps(store, props, "focusLoop");
9399 useStoreProps(store, props, "focusWrap");
9400 useStoreProps(store, props, "focusShift");
9401 return store;
9402 }
9403
9404 // node_modules/@ariakit/react-core/esm/__chunks/CVCFNOHX.js
9405 var import_react15 = __toESM(require_react(), 1);
9406 var ComboboxListRoleContext = (0, import_react15.createContext)(
9407 void 0
9408 );
9409 var ctx6 = createStoreContext(
9410 [PopoverContextProvider, CompositeContextProvider],
9411 [PopoverScopedContextProvider, CompositeScopedContextProvider]
9412 );
9413 var useComboboxContext = ctx6.useContext;
9414 var useComboboxScopedContext = ctx6.useScopedContext;
9415 var useComboboxProviderContext = ctx6.useProviderContext;
9416 var ComboboxContextProvider = ctx6.ContextProvider;
9417 var ComboboxScopedContextProvider = ctx6.ScopedContextProvider;
9418 var ComboboxItemValueContext = (0, import_react15.createContext)(
9419 void 0
9420 );
9421 var ComboboxItemCheckedContext = (0, import_react15.createContext)(false);
9422
9423 // node_modules/@ariakit/core/esm/__chunks/KMAUV3TY.js
9424 function createDialogStore(props = {}) {
9425 return createDisclosureStore(props);
9426 }
9427
9428 // node_modules/@ariakit/react-core/esm/__chunks/4NYSH4UO.js
9429 function useDialogStoreProps(store, update2, props) {
9430 return useDisclosureStoreProps(store, update2, props);
9431 }
9432
9433 // node_modules/@ariakit/core/esm/__chunks/BFGNM53A.js
9434 function createPopoverStore({
9435 popover: otherPopover,
9436 ...props
9437 } = {}) {
9438 const store = mergeStore(
9439 props.store,
9440 omit2(otherPopover, [
9441 "arrowElement",
9442 "anchorElement",
9443 "contentElement",
9444 "popoverElement",
9445 "disclosureElement"
9446 ])
9447 );
9448 throwOnConflictingProps(props, store);
9449 const syncState = store == null ? void 0 : store.getState();
9450 const dialog = createDialogStore({ ...props, store });
9451 const placement = defaultValue(
9452 props.placement,
9453 syncState == null ? void 0 : syncState.placement,
9454 "bottom"
9455 );
9456 const initialState = {
9457 ...dialog.getState(),
9458 placement,
9459 currentPlacement: placement,
9460 anchorElement: defaultValue(syncState == null ? void 0 : syncState.anchorElement, null),
9461 popoverElement: defaultValue(syncState == null ? void 0 : syncState.popoverElement, null),
9462 arrowElement: defaultValue(syncState == null ? void 0 : syncState.arrowElement, null),
9463 rendered: /* @__PURE__ */ Symbol("rendered")
9464 };
9465 const popover = createStore(initialState, dialog, store);
9466 return {
9467 ...dialog,
9468 ...popover,
9469 setAnchorElement: (element) => popover.setState("anchorElement", element),
9470 setPopoverElement: (element) => popover.setState("popoverElement", element),
9471 setArrowElement: (element) => popover.setState("arrowElement", element),
9472 render: () => popover.setState("rendered", /* @__PURE__ */ Symbol("rendered"))
9473 };
9474 }
9475
9476 // node_modules/@ariakit/react-core/esm/__chunks/B6FLPFJM.js
9477 function usePopoverStoreProps(store, update2, props) {
9478 useUpdateEffect(update2, [props.popover]);
9479 useStoreProps(store, props, "placement");
9480 return useDialogStoreProps(store, update2, props);
9481 }
9482
9483 // node_modules/@ariakit/react-core/esm/__chunks/4POTBZ2J.js
9484 var TagName7 = "div";
9485 var usePopoverAnchor = createHook(
9486 function usePopoverAnchor2({ store, ...props }) {
9487 const context = usePopoverProviderContext();
9488 store = store || context;
9489 props = {
9490 ...props,
9491 ref: useMergeRefs(store == null ? void 0 : store.setAnchorElement, props.ref)
9492 };
9493 return props;
9494 }
9495 );
9496 var PopoverAnchor = forwardRef22(function PopoverAnchor2(props) {
9497 const htmlProps = usePopoverAnchor(props);
9498 return createElement3(TagName7, htmlProps);
9499 });
9500
9501 // node_modules/@ariakit/react-core/esm/__chunks/X6LNAU2F.js
9502 var import_react16 = __toESM(require_react(), 1);
9503 var TagName8 = "div";
9504 function getMouseDestination(event) {
9505 const relatedTarget = event.relatedTarget;
9506 if ((relatedTarget == null ? void 0 : relatedTarget.nodeType) === Node.ELEMENT_NODE) {
9507 return relatedTarget;
9508 }
9509 return null;
9510 }
9511 function hoveringInside(event) {
9512 const nextElement = getMouseDestination(event);
9513 if (!nextElement) return false;
9514 return contains(event.currentTarget, nextElement);
9515 }
9516 var symbol2 = /* @__PURE__ */ Symbol("composite-hover");
9517 function movingToAnotherItem(event) {
9518 let dest = getMouseDestination(event);
9519 if (!dest) return false;
9520 do {
9521 if (hasOwnProperty(dest, symbol2) && dest[symbol2]) return true;
9522 dest = dest.parentElement;
9523 } while (dest);
9524 return false;
9525 }
9526 var useCompositeHover = createHook(
9527 function useCompositeHover2({
9528 store,
9529 focusOnHover = true,
9530 blurOnHoverEnd = !!focusOnHover,
9531 ...props
9532 }) {
9533 const context = useCompositeContext();
9534 store = store || context;
9535 invariant(
9536 store,
9537 "CompositeHover must be wrapped in a Composite component."
9538 );
9539 const isMouseMoving = useIsMouseMoving();
9540 const onMouseMoveProp = props.onMouseMove;
9541 const focusOnHoverProp = useBooleanEvent(focusOnHover);
9542 const onMouseMove = useEvent((event) => {
9543 onMouseMoveProp == null ? void 0 : onMouseMoveProp(event);
9544 if (event.defaultPrevented) return;
9545 if (!isMouseMoving()) return;
9546 if (!focusOnHoverProp(event)) return;
9547 if (!hasFocusWithin(event.currentTarget)) {
9548 const baseElement = store == null ? void 0 : store.getState().baseElement;
9549 if (baseElement && !hasFocus(baseElement)) {
9550 baseElement.focus();
9551 }
9552 }
9553 store == null ? void 0 : store.setActiveId(event.currentTarget.id);
9554 });
9555 const onMouseLeaveProp = props.onMouseLeave;
9556 const blurOnHoverEndProp = useBooleanEvent(blurOnHoverEnd);
9557 const onMouseLeave = useEvent((event) => {
9558 var _a;
9559 onMouseLeaveProp == null ? void 0 : onMouseLeaveProp(event);
9560 if (event.defaultPrevented) return;
9561 if (!isMouseMoving()) return;
9562 if (hoveringInside(event)) return;
9563 if (movingToAnotherItem(event)) return;
9564 if (!focusOnHoverProp(event)) return;
9565 if (!blurOnHoverEndProp(event)) return;
9566 store == null ? void 0 : store.setActiveId(null);
9567 (_a = store == null ? void 0 : store.getState().baseElement) == null ? void 0 : _a.focus();
9568 });
9569 const ref = (0, import_react16.useCallback)((element) => {
9570 if (!element) return;
9571 element[symbol2] = true;
9572 }, []);
9573 props = {
9574 ...props,
9575 ref: useMergeRefs(ref, props.ref),
9576 onMouseMove,
9577 onMouseLeave
9578 };
9579 return removeUndefinedValues(props);
9580 }
9581 );
9582 var CompositeHover = memo22(
9583 forwardRef22(function CompositeHover2(props) {
9584 const htmlProps = useCompositeHover(props);
9585 return createElement3(TagName8, htmlProps);
9586 })
9587 );
9588
9589 // node_modules/@ariakit/react-core/esm/combobox/combobox.js
9590 var import_react17 = __toESM(require_react(), 1);
9591 var TagName9 = "input";
9592 function isFirstItemAutoSelected(items, activeValue, autoSelect) {
9593 if (!autoSelect) return false;
9594 const firstItem = items.find((item) => !item.disabled && item.value);
9595 return (firstItem == null ? void 0 : firstItem.value) === activeValue;
9596 }
9597 function hasCompletionString(value, activeValue) {
9598 if (!activeValue) return false;
9599 if (value == null) return false;
9600 value = normalizeString(value);
9601 return activeValue.length > value.length && activeValue.toLowerCase().indexOf(value.toLowerCase()) === 0;
9602 }
9603 function isInputEvent(event) {
9604 return event.type === "input";
9605 }
9606 function isAriaAutoCompleteValue(value) {
9607 return value === "inline" || value === "list" || value === "both" || value === "none";
9608 }
9609 function getDefaultAutoSelectId(items) {
9610 const item = items.find((item2) => {
9611 var _a;
9612 if (item2.disabled) return false;
9613 return ((_a = item2.element) == null ? void 0 : _a.getAttribute("role")) !== "tab";
9614 });
9615 return item == null ? void 0 : item.id;
9616 }
9617 var useCombobox = createHook(
9618 function useCombobox2({
9619 store,
9620 focusable = true,
9621 autoSelect: autoSelectProp = false,
9622 getAutoSelectId,
9623 setValueOnChange,
9624 showMinLength = 0,
9625 showOnChange,
9626 showOnMouseDown,
9627 showOnClick = showOnMouseDown,
9628 showOnKeyDown,
9629 showOnKeyPress = showOnKeyDown,
9630 blurActiveItemOnClick,
9631 setValueOnClick = true,
9632 moveOnKeyPress = true,
9633 autoComplete = "list",
9634 ...props
9635 }) {
9636 const context = useComboboxProviderContext();
9637 store = store || context;
9638 invariant(
9639 store,
9640 "Combobox must receive a `store` prop or be wrapped in a ComboboxProvider component."
9641 );
9642 const ref = (0, import_react17.useRef)(null);
9643 const [valueUpdated, forceValueUpdate] = useForceUpdate();
9644 const canAutoSelectRef = (0, import_react17.useRef)(false);
9645 const composingRef = (0, import_react17.useRef)(false);
9646 const autoSelect = store.useState(
9647 (state) => state.virtualFocus && autoSelectProp
9648 );
9649 const inline = autoComplete === "inline" || autoComplete === "both";
9650 const [canInline, setCanInline] = (0, import_react17.useState)(inline);
9651 useUpdateLayoutEffect(() => {
9652 if (!inline) return;
9653 setCanInline(true);
9654 }, [inline]);
9655 const storeValue = store.useState("value");
9656 const prevSelectedValueRef = (0, import_react17.useRef)(void 0);
9657 (0, import_react17.useEffect)(() => {
9658 return sync(store, ["selectedValue", "activeId"], (_, prev) => {
9659 prevSelectedValueRef.current = prev.selectedValue;
9660 });
9661 }, []);
9662 const inlineActiveValue = store.useState((state) => {
9663 var _a;
9664 if (!inline) return;
9665 if (!canInline) return;
9666 if (state.activeValue && Array.isArray(state.selectedValue)) {
9667 if (state.selectedValue.includes(state.activeValue)) return;
9668 if ((_a = prevSelectedValueRef.current) == null ? void 0 : _a.includes(state.activeValue)) return;
9669 }
9670 return state.activeValue;
9671 });
9672 const items = store.useState("renderedItems");
9673 const open = store.useState("open");
9674 const contentElement = store.useState("contentElement");
9675 const value = (0, import_react17.useMemo)(() => {
9676 if (!inline) return storeValue;
9677 if (!canInline) return storeValue;
9678 const firstItemAutoSelected = isFirstItemAutoSelected(
9679 items,
9680 inlineActiveValue,
9681 autoSelect
9682 );
9683 if (firstItemAutoSelected) {
9684 if (hasCompletionString(storeValue, inlineActiveValue)) {
9685 const slice = (inlineActiveValue == null ? void 0 : inlineActiveValue.slice(storeValue.length)) || "";
9686 return storeValue + slice;
9687 }
9688 return storeValue;
9689 }
9690 return inlineActiveValue || storeValue;
9691 }, [inline, canInline, items, inlineActiveValue, autoSelect, storeValue]);
9692 (0, import_react17.useEffect)(() => {
9693 const element = ref.current;
9694 if (!element) return;
9695 const onCompositeItemMove = () => setCanInline(true);
9696 element.addEventListener("combobox-item-move", onCompositeItemMove);
9697 return () => {
9698 element.removeEventListener("combobox-item-move", onCompositeItemMove);
9699 };
9700 }, []);
9701 (0, import_react17.useEffect)(() => {
9702 if (!inline) return;
9703 if (!canInline) return;
9704 if (!inlineActiveValue) return;
9705 const firstItemAutoSelected = isFirstItemAutoSelected(
9706 items,
9707 inlineActiveValue,
9708 autoSelect
9709 );
9710 if (!firstItemAutoSelected) return;
9711 if (!hasCompletionString(storeValue, inlineActiveValue)) return;
9712 let cleanup = noop2;
9713 queueMicrotask(() => {
9714 const element = ref.current;
9715 if (!element) return;
9716 const { start: prevStart, end: prevEnd } = getTextboxSelection(element);
9717 const nextStart = storeValue.length;
9718 const nextEnd = inlineActiveValue.length;
9719 setSelectionRange(element, nextStart, nextEnd);
9720 cleanup = () => {
9721 if (!hasFocus(element)) return;
9722 const { start, end } = getTextboxSelection(element);
9723 if (start !== nextStart) return;
9724 if (end !== nextEnd) return;
9725 setSelectionRange(element, prevStart, prevEnd);
9726 };
9727 });
9728 return () => cleanup();
9729 }, [
9730 valueUpdated,
9731 inline,
9732 canInline,
9733 inlineActiveValue,
9734 items,
9735 autoSelect,
9736 storeValue
9737 ]);
9738 const scrollingElementRef = (0, import_react17.useRef)(null);
9739 const getAutoSelectIdProp = useEvent(getAutoSelectId);
9740 const autoSelectIdRef = (0, import_react17.useRef)(null);
9741 (0, import_react17.useEffect)(() => {
9742 if (!open) return;
9743 if (!contentElement) return;
9744 const scrollingElement = getScrollingElement(contentElement);
9745 if (!scrollingElement) return;
9746 scrollingElementRef.current = scrollingElement;
9747 const onUserScroll = () => {
9748 canAutoSelectRef.current = false;
9749 };
9750 const onScroll = () => {
9751 if (!store) return;
9752 if (!canAutoSelectRef.current) return;
9753 const { activeId } = store.getState();
9754 if (activeId === null) return;
9755 if (activeId === autoSelectIdRef.current) return;
9756 canAutoSelectRef.current = false;
9757 };
9758 const options = { passive: true, capture: true };
9759 scrollingElement.addEventListener("wheel", onUserScroll, options);
9760 scrollingElement.addEventListener("touchmove", onUserScroll, options);
9761 scrollingElement.addEventListener("scroll", onScroll, options);
9762 return () => {
9763 scrollingElement.removeEventListener("wheel", onUserScroll, true);
9764 scrollingElement.removeEventListener("touchmove", onUserScroll, true);
9765 scrollingElement.removeEventListener("scroll", onScroll, true);
9766 };
9767 }, [open, contentElement, store]);
9768 useSafeLayoutEffect(() => {
9769 if (!storeValue) return;
9770 if (composingRef.current) return;
9771 canAutoSelectRef.current = true;
9772 }, [storeValue]);
9773 useSafeLayoutEffect(() => {
9774 if (autoSelect !== "always" && open) return;
9775 canAutoSelectRef.current = open;
9776 }, [autoSelect, open]);
9777 const resetValueOnSelect = store.useState("resetValueOnSelect");
9778 useUpdateEffect(() => {
9779 var _a, _b;
9780 const canAutoSelect = canAutoSelectRef.current;
9781 if (!store) return;
9782 if (!open) return;
9783 if (!canAutoSelect && !resetValueOnSelect) return;
9784 const { baseElement, contentElement: contentElement2, activeId } = store.getState();
9785 if (baseElement && !hasFocus(baseElement)) return;
9786 if (contentElement2 == null ? void 0 : contentElement2.hasAttribute("data-placing")) {
9787 const observer = new MutationObserver(forceValueUpdate);
9788 observer.observe(contentElement2, { attributeFilter: ["data-placing"] });
9789 return () => observer.disconnect();
9790 }
9791 if (autoSelect && canAutoSelect) {
9792 const userAutoSelectId = getAutoSelectIdProp(items);
9793 const autoSelectId = userAutoSelectId !== void 0 ? userAutoSelectId : (_a = getDefaultAutoSelectId(items)) != null ? _a : store.first();
9794 autoSelectIdRef.current = autoSelectId;
9795 store.move(autoSelectId != null ? autoSelectId : null);
9796 } else {
9797 const element = (_b = store.item(activeId || store.first())) == null ? void 0 : _b.element;
9798 if (element && "scrollIntoView" in element) {
9799 element.scrollIntoView({ block: "nearest", inline: "nearest" });
9800 }
9801 }
9802 return;
9803 }, [
9804 store,
9805 open,
9806 valueUpdated,
9807 storeValue,
9808 autoSelect,
9809 resetValueOnSelect,
9810 getAutoSelectIdProp,
9811 items
9812 ]);
9813 (0, import_react17.useEffect)(() => {
9814 if (!inline) return;
9815 const combobox = ref.current;
9816 if (!combobox) return;
9817 const elements = [combobox, contentElement].filter(
9818 (value2) => !!value2
9819 );
9820 const onBlur2 = (event) => {
9821 if (elements.every((el) => isFocusEventOutside(event, el))) {
9822 store == null ? void 0 : store.setValue(value);
9823 }
9824 };
9825 for (const element of elements) {
9826 element.addEventListener("focusout", onBlur2);
9827 }
9828 return () => {
9829 for (const element of elements) {
9830 element.removeEventListener("focusout", onBlur2);
9831 }
9832 };
9833 }, [inline, contentElement, store, value]);
9834 const canShow = (event) => {
9835 const currentTarget = event.currentTarget;
9836 return currentTarget.value.length >= showMinLength;
9837 };
9838 const onChangeProp = props.onChange;
9839 const showOnChangeProp = useBooleanEvent(showOnChange != null ? showOnChange : canShow);
9840 const setValueOnChangeProp = useBooleanEvent(
9841 // If the combobox is combined with tags, the value will be set by the tag
9842 // input component.
9843 setValueOnChange != null ? setValueOnChange : !store.tag
9844 );
9845 const onChange = useEvent((event) => {
9846 onChangeProp == null ? void 0 : onChangeProp(event);
9847 if (event.defaultPrevented) return;
9848 if (!store) return;
9849 const currentTarget = event.currentTarget;
9850 const { value: value2, selectionStart, selectionEnd } = currentTarget;
9851 const nativeEvent = event.nativeEvent;
9852 canAutoSelectRef.current = true;
9853 if (isInputEvent(nativeEvent)) {
9854 if (nativeEvent.isComposing) {
9855 canAutoSelectRef.current = false;
9856 composingRef.current = true;
9857 }
9858 if (inline) {
9859 const textInserted = nativeEvent.inputType === "insertText" || nativeEvent.inputType === "insertCompositionText";
9860 const caretAtEnd = selectionStart === value2.length;
9861 setCanInline(textInserted && caretAtEnd);
9862 }
9863 }
9864 if (setValueOnChangeProp(event)) {
9865 const isSameValue = value2 === store.getState().value;
9866 store.setValue(value2);
9867 queueMicrotask(() => {
9868 setSelectionRange(currentTarget, selectionStart, selectionEnd);
9869 });
9870 if (inline && autoSelect && isSameValue) {
9871 forceValueUpdate();
9872 }
9873 }
9874 if (showOnChangeProp(event)) {
9875 store.show();
9876 }
9877 if (!autoSelect || !canAutoSelectRef.current) {
9878 store.setActiveId(null);
9879 }
9880 });
9881 const onCompositionEndProp = props.onCompositionEnd;
9882 const onCompositionEnd = useEvent((event) => {
9883 canAutoSelectRef.current = true;
9884 composingRef.current = false;
9885 onCompositionEndProp == null ? void 0 : onCompositionEndProp(event);
9886 if (event.defaultPrevented) return;
9887 if (!autoSelect) return;
9888 forceValueUpdate();
9889 });
9890 const onMouseDownProp = props.onMouseDown;
9891 const blurActiveItemOnClickProp = useBooleanEvent(
9892 blurActiveItemOnClick != null ? blurActiveItemOnClick : (() => !!(store == null ? void 0 : store.getState().includesBaseElement))
9893 );
9894 const setValueOnClickProp = useBooleanEvent(setValueOnClick);
9895 const showOnClickProp = useBooleanEvent(showOnClick != null ? showOnClick : canShow);
9896 const onMouseDown = useEvent((event) => {
9897 onMouseDownProp == null ? void 0 : onMouseDownProp(event);
9898 if (event.defaultPrevented) return;
9899 if (event.button) return;
9900 if (event.ctrlKey) return;
9901 if (!store) return;
9902 if (blurActiveItemOnClickProp(event)) {
9903 store.setActiveId(null);
9904 }
9905 if (setValueOnClickProp(event)) {
9906 store.setValue(value);
9907 }
9908 if (showOnClickProp(event)) {
9909 queueBeforeEvent(event.currentTarget, "mouseup", store.show);
9910 }
9911 });
9912 const onKeyDownProp = props.onKeyDown;
9913 const showOnKeyPressProp = useBooleanEvent(showOnKeyPress != null ? showOnKeyPress : canShow);
9914 const onKeyDown = useEvent((event) => {
9915 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
9916 if (!event.repeat) {
9917 canAutoSelectRef.current = false;
9918 }
9919 if (event.defaultPrevented) return;
9920 if (event.ctrlKey) return;
9921 if (event.altKey) return;
9922 if (event.shiftKey) return;
9923 if (event.metaKey) return;
9924 if (!store) return;
9925 const { open: open2 } = store.getState();
9926 if (open2) return;
9927 if (event.key === "ArrowUp" || event.key === "ArrowDown") {
9928 if (showOnKeyPressProp(event)) {
9929 event.preventDefault();
9930 store.show();
9931 }
9932 }
9933 });
9934 const onBlurProp = props.onBlur;
9935 const onBlur = useEvent((event) => {
9936 canAutoSelectRef.current = false;
9937 onBlurProp == null ? void 0 : onBlurProp(event);
9938 if (event.defaultPrevented) return;
9939 });
9940 const id = useId3(props.id);
9941 const ariaAutoComplete = isAriaAutoCompleteValue(autoComplete) ? autoComplete : void 0;
9942 const isActiveItem = store.useState((state) => state.activeId === null);
9943 props = {
9944 id,
9945 role: "combobox",
9946 "aria-autocomplete": ariaAutoComplete,
9947 "aria-haspopup": getPopupRole(contentElement, "listbox"),
9948 "aria-expanded": open,
9949 "aria-controls": contentElement == null ? void 0 : contentElement.id,
9950 "data-active-item": isActiveItem || void 0,
9951 value,
9952 ...props,
9953 ref: useMergeRefs(ref, props.ref),
9954 onChange,
9955 onCompositionEnd,
9956 onMouseDown,
9957 onKeyDown,
9958 onBlur
9959 };
9960 props = useComposite({
9961 store,
9962 focusable,
9963 ...props,
9964 // Enable inline autocomplete when the user moves from the combobox input
9965 // to an item.
9966 moveOnKeyPress: (event) => {
9967 if (isFalsyBooleanCallback(moveOnKeyPress, event)) return false;
9968 if (inline) setCanInline(true);
9969 return true;
9970 }
9971 });
9972 props = usePopoverAnchor({ store, ...props });
9973 return { autoComplete: "off", ...props };
9974 }
9975 );
9976 var Combobox = forwardRef22(function Combobox2(props) {
9977 const htmlProps = useCombobox(props);
9978 return createElement3(TagName9, htmlProps);
9979 });
9980
9981 // node_modules/@ariakit/react-core/esm/__chunks/IBXZ2LQC.js
9982 var import_react18 = __toESM(require_react(), 1);
9983 var import_jsx_runtime58 = __toESM(require_jsx_runtime(), 1);
9984 var TagName10 = "div";
9985 function isSelected(storeValue, itemValue) {
9986 if (itemValue == null) return;
9987 if (storeValue == null) return false;
9988 if (Array.isArray(storeValue)) {
9989 return storeValue.includes(itemValue);
9990 }
9991 return storeValue === itemValue;
9992 }
9993 function getItemRole(popupRole) {
9994 var _a;
9995 const itemRoleByPopupRole = {
9996 menu: "menuitem",
9997 listbox: "option",
9998 tree: "treeitem"
9999 };
10000 const key = popupRole;
10001 return (_a = itemRoleByPopupRole[key]) != null ? _a : "option";
10002 }
10003 var useComboboxItem = createHook(
10004 function useComboboxItem2({
10005 store,
10006 value,
10007 hideOnClick,
10008 setValueOnClick,
10009 selectValueOnClick = true,
10010 resetValueOnSelect,
10011 focusOnHover = false,
10012 moveOnKeyPress = true,
10013 getItem: getItemProp,
10014 ...props
10015 }) {
10016 var _a;
10017 const context = useComboboxScopedContext();
10018 store = store || context;
10019 invariant(
10020 store,
10021 "ComboboxItem must be wrapped in a ComboboxList or ComboboxPopover component."
10022 );
10023 const { resetValueOnSelectState, multiSelectable, selected } = useStoreStateObject(store, {
10024 resetValueOnSelectState: "resetValueOnSelect",
10025 multiSelectable(state) {
10026 return Array.isArray(state.selectedValue);
10027 },
10028 selected(state) {
10029 return isSelected(state.selectedValue, value);
10030 }
10031 });
10032 const getItem = (0, import_react18.useCallback)(
10033 (item) => {
10034 const nextItem = { ...item, value };
10035 if (getItemProp) {
10036 return getItemProp(nextItem);
10037 }
10038 return nextItem;
10039 },
10040 [value, getItemProp]
10041 );
10042 setValueOnClick = setValueOnClick != null ? setValueOnClick : !multiSelectable;
10043 hideOnClick = hideOnClick != null ? hideOnClick : value != null && !multiSelectable;
10044 const onClickProp = props.onClick;
10045 const setValueOnClickProp = useBooleanEvent(setValueOnClick);
10046 const selectValueOnClickProp = useBooleanEvent(selectValueOnClick);
10047 const resetValueOnSelectProp = useBooleanEvent(
10048 (_a = resetValueOnSelect != null ? resetValueOnSelect : resetValueOnSelectState) != null ? _a : multiSelectable
10049 );
10050 const hideOnClickProp = useBooleanEvent(hideOnClick);
10051 const onClick = useEvent((event) => {
10052 onClickProp == null ? void 0 : onClickProp(event);
10053 if (event.defaultPrevented) return;
10054 if (isDownloading(event)) return;
10055 if (isOpeningInNewTab(event)) return;
10056 if (value != null) {
10057 if (selectValueOnClickProp(event)) {
10058 if (resetValueOnSelectProp(event)) {
10059 store == null ? void 0 : store.resetValue();
10060 }
10061 store == null ? void 0 : store.setSelectedValue((prevValue) => {
10062 if (!Array.isArray(prevValue)) return value;
10063 if (prevValue.includes(value)) {
10064 return prevValue.filter((v2) => v2 !== value);
10065 }
10066 return [...prevValue, value];
10067 });
10068 }
10069 if (setValueOnClickProp(event)) {
10070 store == null ? void 0 : store.setValue(value);
10071 }
10072 }
10073 if (hideOnClickProp(event)) {
10074 store == null ? void 0 : store.hide();
10075 }
10076 });
10077 const onKeyDownProp = props.onKeyDown;
10078 const onKeyDown = useEvent((event) => {
10079 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
10080 if (event.defaultPrevented) return;
10081 const baseElement = store == null ? void 0 : store.getState().baseElement;
10082 if (!baseElement) return;
10083 if (hasFocus(baseElement)) return;
10084 const printable = event.key.length === 1;
10085 if (printable || event.key === "Backspace" || event.key === "Delete") {
10086 queueMicrotask(() => baseElement.focus());
10087 if (isTextField(baseElement)) {
10088 store == null ? void 0 : store.setValue(baseElement.value);
10089 }
10090 }
10091 });
10092 if (multiSelectable && selected != null) {
10093 props = {
10094 "aria-selected": selected,
10095 ...props
10096 };
10097 }
10098 props = useWrapElement(
10099 props,
10100 (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 }) }),
10101 [value, selected]
10102 );
10103 const popupRole = (0, import_react18.useContext)(ComboboxListRoleContext);
10104 props = {
10105 role: getItemRole(popupRole),
10106 children: value,
10107 ...props,
10108 onClick,
10109 onKeyDown
10110 };
10111 const moveOnKeyPressProp = useBooleanEvent(moveOnKeyPress);
10112 props = useCompositeItem({
10113 store,
10114 ...props,
10115 getItem,
10116 // Dispatch a custom event on the combobox input when moving to an item
10117 // with the keyboard so the Combobox component can enable inline
10118 // autocompletion.
10119 moveOnKeyPress: (event) => {
10120 if (!moveOnKeyPressProp(event)) return false;
10121 const moveEvent = new Event("combobox-item-move");
10122 const baseElement = store == null ? void 0 : store.getState().baseElement;
10123 baseElement == null ? void 0 : baseElement.dispatchEvent(moveEvent);
10124 return true;
10125 }
10126 });
10127 props = useCompositeHover({ store, focusOnHover, ...props });
10128 return props;
10129 }
10130 );
10131 var ComboboxItem = memo22(
10132 forwardRef22(function ComboboxItem2(props) {
10133 const htmlProps = useComboboxItem(props);
10134 return createElement3(TagName10, htmlProps);
10135 })
10136 );
10137
10138 // node_modules/@ariakit/react-core/esm/combobox/combobox-item-value.js
10139 var import_react19 = __toESM(require_react(), 1);
10140 var import_jsx_runtime59 = __toESM(require_jsx_runtime(), 1);
10141 var TagName11 = "span";
10142 function normalizeValue(value) {
10143 return normalizeString(value).toLowerCase();
10144 }
10145 function getOffsets(string, values) {
10146 const offsets = [];
10147 for (const value of values) {
10148 let pos = 0;
10149 const length = value.length;
10150 while (string.indexOf(value, pos) !== -1) {
10151 const index = string.indexOf(value, pos);
10152 if (index !== -1) {
10153 offsets.push([index, length]);
10154 }
10155 pos = index + 1;
10156 }
10157 }
10158 return offsets;
10159 }
10160 function filterOverlappingOffsets(offsets) {
10161 return offsets.filter(([offset, length], i2, arr) => {
10162 return !arr.some(
10163 ([o2, l2], j2) => j2 !== i2 && o2 <= offset && o2 + l2 >= offset + length
10164 );
10165 });
10166 }
10167 function sortOffsets(offsets) {
10168 return offsets.sort(([a2], [b2]) => a2 - b2);
10169 }
10170 function splitValue(itemValue, userValue) {
10171 if (!itemValue) return itemValue;
10172 if (!userValue) return itemValue;
10173 const userValues = toArray(userValue).filter(Boolean).map(normalizeValue);
10174 const parts = [];
10175 const span = (value, autocomplete = false) => /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(
10176 "span",
10177 {
10178 "data-autocomplete-value": autocomplete ? "" : void 0,
10179 "data-user-value": autocomplete ? void 0 : "",
10180 children: value
10181 },
10182 parts.length
10183 );
10184 const offsets = sortOffsets(
10185 filterOverlappingOffsets(
10186 // Convert userValues into a set to avoid duplicates
10187 getOffsets(normalizeValue(itemValue), new Set(userValues))
10188 )
10189 );
10190 if (!offsets.length) {
10191 parts.push(span(itemValue, true));
10192 return parts;
10193 }
10194 const [firstOffset] = offsets[0];
10195 const values = [
10196 itemValue.slice(0, firstOffset),
10197 ...offsets.flatMap(([offset, length], i2) => {
10198 var _a;
10199 const value = itemValue.slice(offset, offset + length);
10200 const nextOffset = (_a = offsets[i2 + 1]) == null ? void 0 : _a[0];
10201 const nextValue = itemValue.slice(offset + length, nextOffset);
10202 return [value, nextValue];
10203 })
10204 ];
10205 values.forEach((value, i2) => {
10206 if (!value) return;
10207 parts.push(span(value, i2 % 2 === 0));
10208 });
10209 return parts;
10210 }
10211 var useComboboxItemValue = createHook(function useComboboxItemValue2({ store, value, userValue, ...props }) {
10212 const context = useComboboxScopedContext();
10213 store = store || context;
10214 const itemContext = (0, import_react19.useContext)(ComboboxItemValueContext);
10215 const itemValue = value != null ? value : itemContext;
10216 const inputValue = useStoreState(store, (state) => userValue != null ? userValue : state == null ? void 0 : state.value);
10217 const children = (0, import_react19.useMemo)(() => {
10218 if (!itemValue) return;
10219 if (!inputValue) return itemValue;
10220 return splitValue(itemValue, inputValue);
10221 }, [itemValue, inputValue]);
10222 props = {
10223 children,
10224 ...props
10225 };
10226 return removeUndefinedValues(props);
10227 });
10228 var ComboboxItemValue = forwardRef22(function ComboboxItemValue2(props) {
10229 const htmlProps = useComboboxItemValue(props);
10230 return createElement3(TagName11, htmlProps);
10231 });
10232
10233 // node_modules/@ariakit/react-core/esm/combobox/combobox-label.js
10234 var TagName12 = "label";
10235 var useComboboxLabel = createHook(
10236 function useComboboxLabel2({ store, ...props }) {
10237 const context = useComboboxProviderContext();
10238 store = store || context;
10239 invariant(
10240 store,
10241 "ComboboxLabel must receive a `store` prop or be wrapped in a ComboboxProvider component."
10242 );
10243 const comboboxId = store.useState((state) => {
10244 var _a;
10245 return (_a = state.baseElement) == null ? void 0 : _a.id;
10246 });
10247 props = {
10248 htmlFor: comboboxId,
10249 ...props
10250 };
10251 return removeUndefinedValues(props);
10252 }
10253 );
10254 var ComboboxLabel = memo22(
10255 forwardRef22(function ComboboxLabel2(props) {
10256 const htmlProps = useComboboxLabel(props);
10257 return createElement3(TagName12, htmlProps);
10258 })
10259 );
10260
10261 // node_modules/@ariakit/react-core/esm/__chunks/2G6YEJT4.js
10262 var import_react20 = __toESM(require_react(), 1);
10263 var import_jsx_runtime60 = __toESM(require_jsx_runtime(), 1);
10264 var TagName13 = "div";
10265 var useComboboxList = createHook(
10266 function useComboboxList2({ store, alwaysVisible, ...props }) {
10267 const scopedContext = useComboboxScopedContext(true);
10268 const context = useComboboxContext();
10269 store = store || context;
10270 const scopedContextSameStore = !!store && store === scopedContext;
10271 invariant(
10272 store,
10273 "ComboboxList must receive a `store` prop or be wrapped in a ComboboxProvider component."
10274 );
10275 const ref = (0, import_react20.useRef)(null);
10276 const id = useId3(props.id);
10277 const mounted = store.useState("mounted");
10278 const hidden = isHidden(mounted, props.hidden, alwaysVisible);
10279 const style = hidden ? { ...props.style, display: "none" } : props.style;
10280 const multiSelectable = store.useState(
10281 (state) => Array.isArray(state.selectedValue)
10282 );
10283 const role = useAttribute(ref, "role", props.role);
10284 const isCompositeRole = role === "listbox" || role === "tree" || role === "grid";
10285 const ariaMultiSelectable = isCompositeRole ? multiSelectable || void 0 : void 0;
10286 const [hasListboxInside, setHasListboxInside] = (0, import_react20.useState)(false);
10287 const contentElement = store.useState("contentElement");
10288 useSafeLayoutEffect(() => {
10289 if (!mounted) return;
10290 const element = ref.current;
10291 if (!element) return;
10292 if (contentElement !== element) return;
10293 const callback = () => {
10294 setHasListboxInside(!!element.querySelector("[role='listbox']"));
10295 };
10296 const observer = new MutationObserver(callback);
10297 observer.observe(element, {
10298 subtree: true,
10299 childList: true,
10300 attributeFilter: ["role"]
10301 });
10302 callback();
10303 return () => observer.disconnect();
10304 }, [mounted, contentElement]);
10305 if (!hasListboxInside) {
10306 props = {
10307 role: "listbox",
10308 "aria-multiselectable": ariaMultiSelectable,
10309 ...props
10310 };
10311 }
10312 props = useWrapElement(
10313 props,
10314 (element) => /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(ComboboxScopedContextProvider, { value: store, children: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(ComboboxListRoleContext.Provider, { value: role, children: element }) }),
10315 [store, role]
10316 );
10317 const setContentElement = id && (!scopedContext || !scopedContextSameStore) ? store.setContentElement : null;
10318 props = {
10319 id,
10320 hidden,
10321 ...props,
10322 ref: useMergeRefs(setContentElement, ref, props.ref),
10323 style
10324 };
10325 return removeUndefinedValues(props);
10326 }
10327 );
10328 var ComboboxList = forwardRef22(function ComboboxList2(props) {
10329 const htmlProps = useComboboxList(props);
10330 return createElement3(TagName13, htmlProps);
10331 });
10332
10333 // node_modules/@ariakit/react-core/esm/__chunks/XSIEPKGA.js
10334 var import_react21 = __toESM(require_react(), 1);
10335 var TagValueContext = (0, import_react21.createContext)(null);
10336 var TagRemoveIdContext = (0, import_react21.createContext)(
10337 null
10338 );
10339 var ctx7 = createStoreContext(
10340 [CompositeContextProvider],
10341 [CompositeScopedContextProvider]
10342 );
10343 var useTagContext = ctx7.useContext;
10344 var useTagScopedContext = ctx7.useScopedContext;
10345 var useTagProviderContext = ctx7.useProviderContext;
10346 var TagContextProvider = ctx7.ContextProvider;
10347 var TagScopedContextProvider = ctx7.ScopedContextProvider;
10348
10349 // node_modules/@ariakit/core/esm/combobox/combobox-store.js
10350 var isTouchSafari = isSafari() && isTouchDevice();
10351 function createComboboxStore({
10352 tag,
10353 ...props
10354 } = {}) {
10355 const store = mergeStore(props.store, pick2(tag, ["value", "rtl"]));
10356 throwOnConflictingProps(props, store);
10357 const tagState = tag == null ? void 0 : tag.getState();
10358 const syncState = store == null ? void 0 : store.getState();
10359 const activeId = defaultValue(
10360 props.activeId,
10361 syncState == null ? void 0 : syncState.activeId,
10362 props.defaultActiveId,
10363 null
10364 );
10365 const composite = createCompositeStore({
10366 ...props,
10367 activeId,
10368 includesBaseElement: defaultValue(
10369 props.includesBaseElement,
10370 syncState == null ? void 0 : syncState.includesBaseElement,
10371 true
10372 ),
10373 orientation: defaultValue(
10374 props.orientation,
10375 syncState == null ? void 0 : syncState.orientation,
10376 "vertical"
10377 ),
10378 focusLoop: defaultValue(props.focusLoop, syncState == null ? void 0 : syncState.focusLoop, true),
10379 focusWrap: defaultValue(props.focusWrap, syncState == null ? void 0 : syncState.focusWrap, true),
10380 virtualFocus: defaultValue(
10381 props.virtualFocus,
10382 syncState == null ? void 0 : syncState.virtualFocus,
10383 true
10384 )
10385 });
10386 const popover = createPopoverStore({
10387 ...props,
10388 placement: defaultValue(
10389 props.placement,
10390 syncState == null ? void 0 : syncState.placement,
10391 "bottom-start"
10392 )
10393 });
10394 const value = defaultValue(
10395 props.value,
10396 syncState == null ? void 0 : syncState.value,
10397 props.defaultValue,
10398 ""
10399 );
10400 const selectedValue = defaultValue(
10401 props.selectedValue,
10402 syncState == null ? void 0 : syncState.selectedValue,
10403 tagState == null ? void 0 : tagState.values,
10404 props.defaultSelectedValue,
10405 ""
10406 );
10407 const multiSelectable = Array.isArray(selectedValue);
10408 const initialState = {
10409 ...composite.getState(),
10410 ...popover.getState(),
10411 value,
10412 selectedValue,
10413 resetValueOnSelect: defaultValue(
10414 props.resetValueOnSelect,
10415 syncState == null ? void 0 : syncState.resetValueOnSelect,
10416 multiSelectable
10417 ),
10418 resetValueOnHide: defaultValue(
10419 props.resetValueOnHide,
10420 syncState == null ? void 0 : syncState.resetValueOnHide,
10421 multiSelectable && !tag
10422 ),
10423 activeValue: syncState == null ? void 0 : syncState.activeValue
10424 };
10425 const combobox = createStore(initialState, composite, popover, store);
10426 if (isTouchSafari) {
10427 setup(
10428 combobox,
10429 () => sync(combobox, ["virtualFocus"], () => {
10430 combobox.setState("virtualFocus", false);
10431 })
10432 );
10433 }
10434 setup(combobox, () => {
10435 if (!tag) return;
10436 return chain(
10437 sync(combobox, ["selectedValue"], (state) => {
10438 if (!Array.isArray(state.selectedValue)) return;
10439 tag.setValues(state.selectedValue);
10440 }),
10441 sync(tag, ["values"], (state) => {
10442 combobox.setState("selectedValue", state.values);
10443 })
10444 );
10445 });
10446 setup(
10447 combobox,
10448 () => sync(combobox, ["resetValueOnHide", "mounted"], (state) => {
10449 if (!state.resetValueOnHide) return;
10450 if (state.mounted) return;
10451 combobox.setState("value", value);
10452 })
10453 );
10454 setup(
10455 combobox,
10456 () => sync(combobox, ["open"], (state) => {
10457 if (state.open) return;
10458 combobox.setState("activeId", activeId);
10459 combobox.setState("moves", 0);
10460 })
10461 );
10462 setup(
10463 combobox,
10464 () => sync(combobox, ["moves", "activeId"], (state, prevState) => {
10465 if (state.moves === prevState.moves) {
10466 combobox.setState("activeValue", void 0);
10467 }
10468 })
10469 );
10470 setup(
10471 combobox,
10472 () => batch(combobox, ["moves", "renderedItems"], (state, prev) => {
10473 if (state.moves === prev.moves) return;
10474 const { activeId: activeId2 } = combobox.getState();
10475 const activeItem = composite.item(activeId2);
10476 combobox.setState("activeValue", activeItem == null ? void 0 : activeItem.value);
10477 })
10478 );
10479 return {
10480 ...popover,
10481 ...composite,
10482 ...combobox,
10483 tag,
10484 setValue: (value2) => combobox.setState("value", value2),
10485 resetValue: () => combobox.setState("value", initialState.value),
10486 setSelectedValue: (selectedValue2) => combobox.setState("selectedValue", selectedValue2)
10487 };
10488 }
10489
10490 // node_modules/@ariakit/react-core/esm/__chunks/SVN33SY6.js
10491 function useComboboxStoreOptions(props) {
10492 const tag = useTagContext();
10493 props = {
10494 ...props,
10495 tag: props.tag !== void 0 ? props.tag : tag
10496 };
10497 return useCompositeStoreOptions(props);
10498 }
10499 function useComboboxStoreProps(store, update2, props) {
10500 useUpdateEffect(update2, [props.tag]);
10501 useStoreProps(store, props, "value", "setValue");
10502 useStoreProps(store, props, "selectedValue", "setSelectedValue");
10503 useStoreProps(store, props, "resetValueOnHide");
10504 useStoreProps(store, props, "resetValueOnSelect");
10505 return Object.assign(
10506 useCompositeStoreProps(
10507 usePopoverStoreProps(store, update2, props),
10508 update2,
10509 props
10510 ),
10511 { tag: props.tag }
10512 );
10513 }
10514 function useComboboxStore(props = {}) {
10515 props = useComboboxStoreOptions(props);
10516 const [store, update2] = useStore(createComboboxStore, props);
10517 return useComboboxStoreProps(store, update2, props);
10518 }
10519
10520 // node_modules/@ariakit/react-core/esm/combobox/combobox-provider.js
10521 var import_jsx_runtime61 = __toESM(require_jsx_runtime(), 1);
10522 function ComboboxProvider(props = {}) {
10523 const store = useComboboxStore(props);
10524 return /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(ComboboxContextProvider, { value: store, children: props.children });
10525 }
10526
10527 // packages/dataviews/build-module/components/dataviews-filters/search-widget.mjs
10528 var import_remove_accents = __toESM(require_remove_accents(), 1);
10529 var import_compose7 = __toESM(require_compose(), 1);
10530 var import_i18n28 = __toESM(require_i18n(), 1);
10531 var import_element26 = __toESM(require_element(), 1);
10532 var import_components19 = __toESM(require_components(), 1);
10533
10534 // packages/dataviews/build-module/components/dataviews-filters/utils.mjs
10535 var EMPTY_ARRAY3 = [];
10536 var getCurrentValue = (filterDefinition, currentFilter) => {
10537 if (filterDefinition.singleSelection) {
10538 return currentFilter?.value;
10539 }
10540 if (Array.isArray(currentFilter?.value)) {
10541 return currentFilter.value;
10542 }
10543 if (!Array.isArray(currentFilter?.value) && !!currentFilter?.value) {
10544 return [currentFilter.value];
10545 }
10546 return EMPTY_ARRAY3;
10547 };
10548
10549 // packages/dataviews/build-module/hooks/use-elements.mjs
10550 var import_element25 = __toESM(require_element(), 1);
10551 var EMPTY_ARRAY4 = [];
10552 function useElements({
10553 elements,
10554 getElements
10555 }) {
10556 const staticElements = Array.isArray(elements) && elements.length > 0 ? elements : EMPTY_ARRAY4;
10557 const [records, setRecords] = (0, import_element25.useState)(staticElements);
10558 const [isLoading, setIsLoading] = (0, import_element25.useState)(false);
10559 (0, import_element25.useEffect)(() => {
10560 if (!getElements) {
10561 setRecords(staticElements);
10562 return;
10563 }
10564 let cancelled = false;
10565 setIsLoading(true);
10566 getElements().then((fetchedElements) => {
10567 if (!cancelled) {
10568 const dynamicElements = Array.isArray(fetchedElements) && fetchedElements.length > 0 ? fetchedElements : staticElements;
10569 setRecords(dynamicElements);
10570 }
10571 }).catch(() => {
10572 if (!cancelled) {
10573 setRecords(staticElements);
10574 }
10575 }).finally(() => {
10576 if (!cancelled) {
10577 setIsLoading(false);
10578 }
10579 });
10580 return () => {
10581 cancelled = true;
10582 };
10583 }, [getElements, staticElements]);
10584 return {
10585 elements: records,
10586 isLoading
10587 };
10588 }
10589
10590 // packages/dataviews/build-module/components/dataviews-filters/search-widget.mjs
10591 var import_jsx_runtime62 = __toESM(require_jsx_runtime(), 1);
10592 function normalizeSearchInput(input = "") {
10593 return (0, import_remove_accents.default)(input.trim().toLowerCase());
10594 }
10595 var getNewValue = (filterDefinition, currentFilter, value) => {
10596 if (filterDefinition.singleSelection) {
10597 return value;
10598 }
10599 if (Array.isArray(currentFilter?.value)) {
10600 return currentFilter.value.includes(value) ? currentFilter.value.filter((v2) => v2 !== value) : [...currentFilter.value, value];
10601 }
10602 return [value];
10603 };
10604 function generateFilterElementCompositeItemId(prefix, filterElementValue) {
10605 return `${prefix}-${filterElementValue}`;
10606 }
10607 var MultiSelectionOption = ({ selected }) => {
10608 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10609 "span",
10610 {
10611 className: clsx_default(
10612 "dataviews-filters__search-widget-listitem-multi-selection",
10613 { "is-selected": selected }
10614 ),
10615 children: selected && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components19.Icon, { icon: check_default })
10616 }
10617 );
10618 };
10619 var SingleSelectionOption = ({ selected }) => {
10620 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10621 "span",
10622 {
10623 className: clsx_default(
10624 "dataviews-filters__search-widget-listitem-single-selection",
10625 { "is-selected": selected }
10626 )
10627 }
10628 );
10629 };
10630 function ListBox({ view, filter, onChangeView }) {
10631 const baseId = (0, import_compose7.useInstanceId)(ListBox, "dataviews-filter-list-box");
10632 const [activeCompositeId, setActiveCompositeId] = (0, import_element26.useState)(
10633 // When there are one or less operators, the first item is set as active
10634 // (by setting the initial `activeId` to `undefined`).
10635 // With 2 or more operators, the focus is moved on the operators control
10636 // (by setting the initial `activeId` to `null`), meaning that there won't
10637 // be an active item initially. Focus is then managed via the
10638 // `onFocusVisible` callback.
10639 filter.operators?.length === 1 ? void 0 : null
10640 );
10641 const currentFilter = view.filters?.find(
10642 (f2) => f2.field === filter.field
10643 );
10644 const currentValue = getCurrentValue(filter, currentFilter);
10645 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10646 import_components19.Composite,
10647 {
10648 virtualFocus: true,
10649 focusLoop: true,
10650 activeId: activeCompositeId,
10651 setActiveId: setActiveCompositeId,
10652 role: "listbox",
10653 className: "dataviews-filters__search-widget-listbox",
10654 "aria-label": (0, import_i18n28.sprintf)(
10655 /* translators: List of items for a filter. 1: Filter name. e.g.: "List of: Author". */
10656 (0, import_i18n28.__)("List of: %1$s"),
10657 filter.name
10658 ),
10659 onFocusVisible: () => {
10660 if (!activeCompositeId && filter.elements.length) {
10661 setActiveCompositeId(
10662 generateFilterElementCompositeItemId(
10663 baseId,
10664 filter.elements[0].value
10665 )
10666 );
10667 }
10668 },
10669 render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components19.Composite.Typeahead, {}),
10670 children: filter.elements.map((element) => /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10671 import_components19.Composite.Hover,
10672 {
10673 render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10674 import_components19.Composite.Item,
10675 {
10676 id: generateFilterElementCompositeItemId(
10677 baseId,
10678 element.value
10679 ),
10680 render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10681 "div",
10682 {
10683 "aria-label": element.label,
10684 role: "option",
10685 className: "dataviews-filters__search-widget-listitem"
10686 }
10687 ),
10688 onClick: () => {
10689 const newFilters = currentFilter ? [
10690 ...(view.filters ?? []).map(
10691 (_filter) => {
10692 if (_filter.field === filter.field) {
10693 return {
10694 ..._filter,
10695 operator: currentFilter.operator || filter.operators[0],
10696 value: getNewValue(
10697 filter,
10698 currentFilter,
10699 element.value
10700 )
10701 };
10702 }
10703 return _filter;
10704 }
10705 )
10706 ] : [
10707 ...view.filters ?? [],
10708 {
10709 field: filter.field,
10710 operator: filter.operators[0],
10711 value: getNewValue(
10712 filter,
10713 currentFilter,
10714 element.value
10715 )
10716 }
10717 ];
10718 onChangeView({
10719 ...view,
10720 page: 1,
10721 filters: newFilters
10722 });
10723 }
10724 }
10725 ),
10726 children: [
10727 filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10728 SingleSelectionOption,
10729 {
10730 selected: currentValue === element.value
10731 }
10732 ),
10733 !filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10734 MultiSelectionOption,
10735 {
10736 selected: currentValue.includes(element.value)
10737 }
10738 ),
10739 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10740 "span",
10741 {
10742 className: "dataviews-filters__search-widget-listitem-value",
10743 title: element.label,
10744 children: element.label
10745 }
10746 )
10747 ]
10748 },
10749 element.value
10750 ))
10751 }
10752 );
10753 }
10754 function ComboboxList22({ view, filter, onChangeView }) {
10755 const [searchValue, setSearchValue] = (0, import_element26.useState)("");
10756 const deferredSearchValue = (0, import_element26.useDeferredValue)(searchValue);
10757 const currentFilter = view.filters?.find(
10758 (_filter) => _filter.field === filter.field
10759 );
10760 const currentValue = getCurrentValue(filter, currentFilter);
10761 const matches = (0, import_element26.useMemo)(() => {
10762 const normalizedSearch = normalizeSearchInput(deferredSearchValue);
10763 return filter.elements.filter(
10764 (item) => normalizeSearchInput(item.label).includes(normalizedSearch)
10765 );
10766 }, [filter.elements, deferredSearchValue]);
10767 return /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10768 ComboboxProvider,
10769 {
10770 selectedValue: currentValue,
10771 setSelectedValue: (value) => {
10772 const newFilters = currentFilter ? [
10773 ...(view.filters ?? []).map((_filter) => {
10774 if (_filter.field === filter.field) {
10775 return {
10776 ..._filter,
10777 operator: currentFilter.operator || filter.operators[0],
10778 value
10779 };
10780 }
10781 return _filter;
10782 })
10783 ] : [
10784 ...view.filters ?? [],
10785 {
10786 field: filter.field,
10787 operator: filter.operators[0],
10788 value
10789 }
10790 ];
10791 onChangeView({
10792 ...view,
10793 page: 1,
10794 filters: newFilters
10795 });
10796 },
10797 setValue: setSearchValue,
10798 children: [
10799 /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)("div", { className: "dataviews-filters__search-widget-filter-combobox__wrapper", children: [
10800 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10801 ComboboxLabel,
10802 {
10803 render: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components19.VisuallyHidden, { children: (0, import_i18n28.__)("Search items") }),
10804 children: (0, import_i18n28.__)("Search items")
10805 }
10806 ),
10807 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10808 Combobox,
10809 {
10810 autoSelect: "always",
10811 placeholder: (0, import_i18n28.__)("Search"),
10812 className: "dataviews-filters__search-widget-filter-combobox__input"
10813 }
10814 ),
10815 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("div", { className: "dataviews-filters__search-widget-filter-combobox__icon", children: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components19.Icon, { icon: search_default }) })
10816 ] }),
10817 /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10818 ComboboxList,
10819 {
10820 className: "dataviews-filters__search-widget-filter-combobox-list",
10821 alwaysVisible: true,
10822 children: [
10823 matches.map((element) => {
10824 return /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10825 ComboboxItem,
10826 {
10827 resetValueOnSelect: false,
10828 value: element.value,
10829 className: "dataviews-filters__search-widget-listitem",
10830 hideOnClick: false,
10831 setValueOnClick: false,
10832 focusOnHover: true,
10833 children: [
10834 filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10835 SingleSelectionOption,
10836 {
10837 selected: currentValue === element.value
10838 }
10839 ),
10840 !filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10841 MultiSelectionOption,
10842 {
10843 selected: currentValue.includes(
10844 element.value
10845 )
10846 }
10847 ),
10848 /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)(
10849 "span",
10850 {
10851 className: "dataviews-filters__search-widget-listitem-value",
10852 title: element.label,
10853 children: [
10854 /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
10855 ComboboxItemValue,
10856 {
10857 className: "dataviews-filters__search-widget-filter-combobox-item-value",
10858 value: element.label
10859 }
10860 ),
10861 !!element.description && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("span", { className: "dataviews-filters__search-widget-listitem-description", children: element.description })
10862 ]
10863 }
10864 )
10865 ]
10866 },
10867 element.value
10868 );
10869 }),
10870 !matches.length && /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("p", { children: (0, import_i18n28.__)("No results found") })
10871 ]
10872 }
10873 )
10874 ]
10875 }
10876 );
10877 }
10878 function SearchWidget(props) {
10879 const { elements, isLoading } = useElements({
10880 elements: props.filter.elements,
10881 getElements: props.filter.getElements
10882 });
10883 if (isLoading) {
10884 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("div", { className: "dataviews-filters__search-widget-no-elements", children: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(import_components19.Spinner, {}) });
10885 }
10886 if (elements.length === 0) {
10887 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("div", { className: "dataviews-filters__search-widget-no-elements", children: (0, import_i18n28.__)("No elements found") });
10888 }
10889 const Widget = elements.length > 10 ? ComboboxList22 : ListBox;
10890 return /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(Widget, { ...props, filter: { ...props.filter, elements } });
10891 }
10892
10893 // packages/dataviews/build-module/components/dataviews-filters/input-widget.mjs
10894 var import_es6 = __toESM(require_es6(), 1);
10895 var import_compose8 = __toESM(require_compose(), 1);
10896 var import_element27 = __toESM(require_element(), 1);
10897 var import_components20 = __toESM(require_components(), 1);
10898 var import_jsx_runtime63 = __toESM(require_jsx_runtime(), 1);
10899 function InputWidget({
10900 filter,
10901 view,
10902 onChangeView,
10903 fields
10904 }) {
10905 const currentFilter = view.filters?.find(
10906 (f2) => f2.field === filter.field
10907 );
10908 const currentValue = getCurrentValue(filter, currentFilter);
10909 const field = (0, import_element27.useMemo)(() => {
10910 const currentField = fields.find((f2) => f2.id === filter.field);
10911 if (currentField) {
10912 return {
10913 ...currentField,
10914 // Deactivate validation for filters.
10915 isValid: {},
10916 // Filter controls are always enabled.
10917 isDisabled: () => false,
10918 // Filter controls are always visible.
10919 isVisible: () => true,
10920 // Configure getValue/setValue as if Item was a plain object.
10921 getValue: ({ item }) => item[currentField.id],
10922 setValue: ({ value }) => ({
10923 [currentField.id]: value
10924 })
10925 };
10926 }
10927 return currentField;
10928 }, [fields, filter.field]);
10929 const data = (0, import_element27.useMemo)(() => {
10930 return (view.filters ?? []).reduce(
10931 (acc, activeFilter) => {
10932 acc[activeFilter.field] = activeFilter.value;
10933 return acc;
10934 },
10935 {}
10936 );
10937 }, [view.filters]);
10938 const handleChange = (0, import_compose8.useEvent)((updatedData) => {
10939 if (!field || !currentFilter) {
10940 return;
10941 }
10942 const nextValue = field.getValue({ item: updatedData });
10943 if ((0, import_es6.default)(nextValue, currentValue)) {
10944 return;
10945 }
10946 onChangeView({
10947 ...view,
10948 filters: (view.filters ?? []).map(
10949 (_filter) => _filter.field === filter.field ? {
10950 ..._filter,
10951 operator: currentFilter.operator || filter.operators[0],
10952 // Consider empty strings as undefined:
10953 //
10954 // - undefined as value means the filter is unset: the filter widget displays no value and the search returns all records
10955 // - empty string as value means "search empty string": returns only the records that have an empty string as value
10956 //
10957 // In practice, this means the filter will not be able to find an empty string as the value.
10958 value: nextValue === "" ? void 0 : nextValue
10959 } : _filter
10960 )
10961 });
10962 });
10963 if (!field || !field.Edit || !currentFilter) {
10964 return null;
10965 }
10966 return /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
10967 import_components20.Flex,
10968 {
10969 className: "dataviews-filters__user-input-widget",
10970 gap: 2.5,
10971 direction: "column",
10972 children: /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
10973 field.Edit,
10974 {
10975 hideLabelFromVision: true,
10976 data,
10977 field,
10978 operator: currentFilter.operator,
10979 onChange: handleChange
10980 }
10981 )
10982 }
10983 );
10984 }
10985
10986 // packages/dataviews/node_modules/date-fns/constants.js
10987 var daysInYear = 365.2425;
10988 var maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1e3;
10989 var minTime = -maxTime;
10990 var millisecondsInWeek = 6048e5;
10991 var millisecondsInDay = 864e5;
10992 var secondsInHour = 3600;
10993 var secondsInDay = secondsInHour * 24;
10994 var secondsInWeek = secondsInDay * 7;
10995 var secondsInYear = secondsInDay * daysInYear;
10996 var secondsInMonth = secondsInYear / 12;
10997 var secondsInQuarter = secondsInMonth * 3;
10998 var constructFromSymbol = /* @__PURE__ */ Symbol.for("constructDateFrom");
10999
11000 // packages/dataviews/node_modules/date-fns/constructFrom.js
11001 function constructFrom(date, value) {
11002 if (typeof date === "function") return date(value);
11003 if (date && typeof date === "object" && constructFromSymbol in date)
11004 return date[constructFromSymbol](value);
11005 if (date instanceof Date) return new date.constructor(value);
11006 return new Date(value);
11007 }
11008
11009 // packages/dataviews/node_modules/date-fns/toDate.js
11010 function toDate(argument, context) {
11011 return constructFrom(context || argument, argument);
11012 }
11013
11014 // packages/dataviews/node_modules/date-fns/addDays.js
11015 function addDays(date, amount, options) {
11016 const _date = toDate(date, options?.in);
11017 if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
11018 if (!amount) return _date;
11019 _date.setDate(_date.getDate() + amount);
11020 return _date;
11021 }
11022
11023 // packages/dataviews/node_modules/date-fns/addMonths.js
11024 function addMonths(date, amount, options) {
11025 const _date = toDate(date, options?.in);
11026 if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
11027 if (!amount) {
11028 return _date;
11029 }
11030 const dayOfMonth = _date.getDate();
11031 const endOfDesiredMonth = constructFrom(options?.in || date, _date.getTime());
11032 endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0);
11033 const daysInMonth = endOfDesiredMonth.getDate();
11034 if (dayOfMonth >= daysInMonth) {
11035 return endOfDesiredMonth;
11036 } else {
11037 _date.setFullYear(
11038 endOfDesiredMonth.getFullYear(),
11039 endOfDesiredMonth.getMonth(),
11040 dayOfMonth
11041 );
11042 return _date;
11043 }
11044 }
11045
11046 // packages/dataviews/node_modules/date-fns/_lib/defaultOptions.js
11047 var defaultOptions = {};
11048 function getDefaultOptions() {
11049 return defaultOptions;
11050 }
11051
11052 // packages/dataviews/node_modules/date-fns/startOfWeek.js
11053 function startOfWeek(date, options) {
11054 const defaultOptions2 = getDefaultOptions();
11055 const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
11056 const _date = toDate(date, options?.in);
11057 const day = _date.getDay();
11058 const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
11059 _date.setDate(_date.getDate() - diff);
11060 _date.setHours(0, 0, 0, 0);
11061 return _date;
11062 }
11063
11064 // packages/dataviews/node_modules/date-fns/startOfISOWeek.js
11065 function startOfISOWeek(date, options) {
11066 return startOfWeek(date, { ...options, weekStartsOn: 1 });
11067 }
11068
11069 // packages/dataviews/node_modules/date-fns/getISOWeekYear.js
11070 function getISOWeekYear(date, options) {
11071 const _date = toDate(date, options?.in);
11072 const year = _date.getFullYear();
11073 const fourthOfJanuaryOfNextYear = constructFrom(_date, 0);
11074 fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
11075 fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
11076 const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
11077 const fourthOfJanuaryOfThisYear = constructFrom(_date, 0);
11078 fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
11079 fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
11080 const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
11081 if (_date.getTime() >= startOfNextYear.getTime()) {
11082 return year + 1;
11083 } else if (_date.getTime() >= startOfThisYear.getTime()) {
11084 return year;
11085 } else {
11086 return year - 1;
11087 }
11088 }
11089
11090 // packages/dataviews/node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.js
11091 function getTimezoneOffsetInMilliseconds(date) {
11092 const _date = toDate(date);
11093 const utcDate = new Date(
11094 Date.UTC(
11095 _date.getFullYear(),
11096 _date.getMonth(),
11097 _date.getDate(),
11098 _date.getHours(),
11099 _date.getMinutes(),
11100 _date.getSeconds(),
11101 _date.getMilliseconds()
11102 )
11103 );
11104 utcDate.setUTCFullYear(_date.getFullYear());
11105 return +date - +utcDate;
11106 }
11107
11108 // packages/dataviews/node_modules/date-fns/_lib/normalizeDates.js
11109 function normalizeDates(context, ...dates) {
11110 const normalize = constructFrom.bind(
11111 null,
11112 context || dates.find((date) => typeof date === "object")
11113 );
11114 return dates.map(normalize);
11115 }
11116
11117 // packages/dataviews/node_modules/date-fns/startOfDay.js
11118 function startOfDay(date, options) {
11119 const _date = toDate(date, options?.in);
11120 _date.setHours(0, 0, 0, 0);
11121 return _date;
11122 }
11123
11124 // packages/dataviews/node_modules/date-fns/differenceInCalendarDays.js
11125 function differenceInCalendarDays(laterDate, earlierDate, options) {
11126 const [laterDate_, earlierDate_] = normalizeDates(
11127 options?.in,
11128 laterDate,
11129 earlierDate
11130 );
11131 const laterStartOfDay = startOfDay(laterDate_);
11132 const earlierStartOfDay = startOfDay(earlierDate_);
11133 const laterTimestamp = +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
11134 const earlierTimestamp = +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
11135 return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
11136 }
11137
11138 // packages/dataviews/node_modules/date-fns/startOfISOWeekYear.js
11139 function startOfISOWeekYear(date, options) {
11140 const year = getISOWeekYear(date, options);
11141 const fourthOfJanuary = constructFrom(options?.in || date, 0);
11142 fourthOfJanuary.setFullYear(year, 0, 4);
11143 fourthOfJanuary.setHours(0, 0, 0, 0);
11144 return startOfISOWeek(fourthOfJanuary);
11145 }
11146
11147 // packages/dataviews/node_modules/date-fns/addWeeks.js
11148 function addWeeks(date, amount, options) {
11149 return addDays(date, amount * 7, options);
11150 }
11151
11152 // packages/dataviews/node_modules/date-fns/addYears.js
11153 function addYears(date, amount, options) {
11154 return addMonths(date, amount * 12, options);
11155 }
11156
11157 // packages/dataviews/node_modules/date-fns/isDate.js
11158 function isDate(value) {
11159 return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
11160 }
11161
11162 // packages/dataviews/node_modules/date-fns/isValid.js
11163 function isValid(date) {
11164 return !(!isDate(date) && typeof date !== "number" || isNaN(+toDate(date)));
11165 }
11166
11167 // packages/dataviews/node_modules/date-fns/startOfMonth.js
11168 function startOfMonth(date, options) {
11169 const _date = toDate(date, options?.in);
11170 _date.setDate(1);
11171 _date.setHours(0, 0, 0, 0);
11172 return _date;
11173 }
11174
11175 // packages/dataviews/node_modules/date-fns/startOfYear.js
11176 function startOfYear(date, options) {
11177 const date_ = toDate(date, options?.in);
11178 date_.setFullYear(date_.getFullYear(), 0, 1);
11179 date_.setHours(0, 0, 0, 0);
11180 return date_;
11181 }
11182
11183 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/formatDistance.js
11184 var formatDistanceLocale = {
11185 lessThanXSeconds: {
11186 one: "less than a second",
11187 other: "less than {{count}} seconds"
11188 },
11189 xSeconds: {
11190 one: "1 second",
11191 other: "{{count}} seconds"
11192 },
11193 halfAMinute: "half a minute",
11194 lessThanXMinutes: {
11195 one: "less than a minute",
11196 other: "less than {{count}} minutes"
11197 },
11198 xMinutes: {
11199 one: "1 minute",
11200 other: "{{count}} minutes"
11201 },
11202 aboutXHours: {
11203 one: "about 1 hour",
11204 other: "about {{count}} hours"
11205 },
11206 xHours: {
11207 one: "1 hour",
11208 other: "{{count}} hours"
11209 },
11210 xDays: {
11211 one: "1 day",
11212 other: "{{count}} days"
11213 },
11214 aboutXWeeks: {
11215 one: "about 1 week",
11216 other: "about {{count}} weeks"
11217 },
11218 xWeeks: {
11219 one: "1 week",
11220 other: "{{count}} weeks"
11221 },
11222 aboutXMonths: {
11223 one: "about 1 month",
11224 other: "about {{count}} months"
11225 },
11226 xMonths: {
11227 one: "1 month",
11228 other: "{{count}} months"
11229 },
11230 aboutXYears: {
11231 one: "about 1 year",
11232 other: "about {{count}} years"
11233 },
11234 xYears: {
11235 one: "1 year",
11236 other: "{{count}} years"
11237 },
11238 overXYears: {
11239 one: "over 1 year",
11240 other: "over {{count}} years"
11241 },
11242 almostXYears: {
11243 one: "almost 1 year",
11244 other: "almost {{count}} years"
11245 }
11246 };
11247 var formatDistance = (token, count, options) => {
11248 let result;
11249 const tokenValue = formatDistanceLocale[token];
11250 if (typeof tokenValue === "string") {
11251 result = tokenValue;
11252 } else if (count === 1) {
11253 result = tokenValue.one;
11254 } else {
11255 result = tokenValue.other.replace("{{count}}", count.toString());
11256 }
11257 if (options?.addSuffix) {
11258 if (options.comparison && options.comparison > 0) {
11259 return "in " + result;
11260 } else {
11261 return result + " ago";
11262 }
11263 }
11264 return result;
11265 };
11266
11267 // packages/dataviews/node_modules/date-fns/locale/_lib/buildFormatLongFn.js
11268 function buildFormatLongFn(args) {
11269 return (options = {}) => {
11270 const width = options.width ? String(options.width) : args.defaultWidth;
11271 const format6 = args.formats[width] || args.formats[args.defaultWidth];
11272 return format6;
11273 };
11274 }
11275
11276 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/formatLong.js
11277 var dateFormats = {
11278 full: "EEEE, MMMM do, y",
11279 long: "MMMM do, y",
11280 medium: "MMM d, y",
11281 short: "MM/dd/yyyy"
11282 };
11283 var timeFormats = {
11284 full: "h:mm:ss a zzzz",
11285 long: "h:mm:ss a z",
11286 medium: "h:mm:ss a",
11287 short: "h:mm a"
11288 };
11289 var dateTimeFormats = {
11290 full: "{{date}} 'at' {{time}}",
11291 long: "{{date}} 'at' {{time}}",
11292 medium: "{{date}}, {{time}}",
11293 short: "{{date}}, {{time}}"
11294 };
11295 var formatLong = {
11296 date: buildFormatLongFn({
11297 formats: dateFormats,
11298 defaultWidth: "full"
11299 }),
11300 time: buildFormatLongFn({
11301 formats: timeFormats,
11302 defaultWidth: "full"
11303 }),
11304 dateTime: buildFormatLongFn({
11305 formats: dateTimeFormats,
11306 defaultWidth: "full"
11307 })
11308 };
11309
11310 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/formatRelative.js
11311 var formatRelativeLocale = {
11312 lastWeek: "'last' eeee 'at' p",
11313 yesterday: "'yesterday at' p",
11314 today: "'today at' p",
11315 tomorrow: "'tomorrow at' p",
11316 nextWeek: "eeee 'at' p",
11317 other: "P"
11318 };
11319 var formatRelative = (token, _date, _baseDate, _options) => formatRelativeLocale[token];
11320
11321 // packages/dataviews/node_modules/date-fns/locale/_lib/buildLocalizeFn.js
11322 function buildLocalizeFn(args) {
11323 return (value, options) => {
11324 const context = options?.context ? String(options.context) : "standalone";
11325 let valuesArray;
11326 if (context === "formatting" && args.formattingValues) {
11327 const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
11328 const width = options?.width ? String(options.width) : defaultWidth;
11329 valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
11330 } else {
11331 const defaultWidth = args.defaultWidth;
11332 const width = options?.width ? String(options.width) : args.defaultWidth;
11333 valuesArray = args.values[width] || args.values[defaultWidth];
11334 }
11335 const index = args.argumentCallback ? args.argumentCallback(value) : value;
11336 return valuesArray[index];
11337 };
11338 }
11339
11340 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/localize.js
11341 var eraValues = {
11342 narrow: ["B", "A"],
11343 abbreviated: ["BC", "AD"],
11344 wide: ["Before Christ", "Anno Domini"]
11345 };
11346 var quarterValues = {
11347 narrow: ["1", "2", "3", "4"],
11348 abbreviated: ["Q1", "Q2", "Q3", "Q4"],
11349 wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"]
11350 };
11351 var monthValues = {
11352 narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
11353 abbreviated: [
11354 "Jan",
11355 "Feb",
11356 "Mar",
11357 "Apr",
11358 "May",
11359 "Jun",
11360 "Jul",
11361 "Aug",
11362 "Sep",
11363 "Oct",
11364 "Nov",
11365 "Dec"
11366 ],
11367 wide: [
11368 "January",
11369 "February",
11370 "March",
11371 "April",
11372 "May",
11373 "June",
11374 "July",
11375 "August",
11376 "September",
11377 "October",
11378 "November",
11379 "December"
11380 ]
11381 };
11382 var dayValues = {
11383 narrow: ["S", "M", "T", "W", "T", "F", "S"],
11384 short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
11385 abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
11386 wide: [
11387 "Sunday",
11388 "Monday",
11389 "Tuesday",
11390 "Wednesday",
11391 "Thursday",
11392 "Friday",
11393 "Saturday"
11394 ]
11395 };
11396 var dayPeriodValues = {
11397 narrow: {
11398 am: "a",
11399 pm: "p",
11400 midnight: "mi",
11401 noon: "n",
11402 morning: "morning",
11403 afternoon: "afternoon",
11404 evening: "evening",
11405 night: "night"
11406 },
11407 abbreviated: {
11408 am: "AM",
11409 pm: "PM",
11410 midnight: "midnight",
11411 noon: "noon",
11412 morning: "morning",
11413 afternoon: "afternoon",
11414 evening: "evening",
11415 night: "night"
11416 },
11417 wide: {
11418 am: "a.m.",
11419 pm: "p.m.",
11420 midnight: "midnight",
11421 noon: "noon",
11422 morning: "morning",
11423 afternoon: "afternoon",
11424 evening: "evening",
11425 night: "night"
11426 }
11427 };
11428 var formattingDayPeriodValues = {
11429 narrow: {
11430 am: "a",
11431 pm: "p",
11432 midnight: "mi",
11433 noon: "n",
11434 morning: "in the morning",
11435 afternoon: "in the afternoon",
11436 evening: "in the evening",
11437 night: "at night"
11438 },
11439 abbreviated: {
11440 am: "AM",
11441 pm: "PM",
11442 midnight: "midnight",
11443 noon: "noon",
11444 morning: "in the morning",
11445 afternoon: "in the afternoon",
11446 evening: "in the evening",
11447 night: "at night"
11448 },
11449 wide: {
11450 am: "a.m.",
11451 pm: "p.m.",
11452 midnight: "midnight",
11453 noon: "noon",
11454 morning: "in the morning",
11455 afternoon: "in the afternoon",
11456 evening: "in the evening",
11457 night: "at night"
11458 }
11459 };
11460 var ordinalNumber = (dirtyNumber, _options) => {
11461 const number = Number(dirtyNumber);
11462 const rem100 = number % 100;
11463 if (rem100 > 20 || rem100 < 10) {
11464 switch (rem100 % 10) {
11465 case 1:
11466 return number + "st";
11467 case 2:
11468 return number + "nd";
11469 case 3:
11470 return number + "rd";
11471 }
11472 }
11473 return number + "th";
11474 };
11475 var localize = {
11476 ordinalNumber,
11477 era: buildLocalizeFn({
11478 values: eraValues,
11479 defaultWidth: "wide"
11480 }),
11481 quarter: buildLocalizeFn({
11482 values: quarterValues,
11483 defaultWidth: "wide",
11484 argumentCallback: (quarter) => quarter - 1
11485 }),
11486 month: buildLocalizeFn({
11487 values: monthValues,
11488 defaultWidth: "wide"
11489 }),
11490 day: buildLocalizeFn({
11491 values: dayValues,
11492 defaultWidth: "wide"
11493 }),
11494 dayPeriod: buildLocalizeFn({
11495 values: dayPeriodValues,
11496 defaultWidth: "wide",
11497 formattingValues: formattingDayPeriodValues,
11498 defaultFormattingWidth: "wide"
11499 })
11500 };
11501
11502 // packages/dataviews/node_modules/date-fns/locale/_lib/buildMatchFn.js
11503 function buildMatchFn(args) {
11504 return (string, options = {}) => {
11505 const width = options.width;
11506 const matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
11507 const matchResult = string.match(matchPattern);
11508 if (!matchResult) {
11509 return null;
11510 }
11511 const matchedString = matchResult[0];
11512 const parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
11513 const key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString)) : (
11514 // [TODO] -- I challenge you to fix the type
11515 findKey(parsePatterns, (pattern) => pattern.test(matchedString))
11516 );
11517 let value;
11518 value = args.valueCallback ? args.valueCallback(key) : key;
11519 value = options.valueCallback ? (
11520 // [TODO] -- I challenge you to fix the type
11521 options.valueCallback(value)
11522 ) : value;
11523 const rest = string.slice(matchedString.length);
11524 return { value, rest };
11525 };
11526 }
11527 function findKey(object, predicate) {
11528 for (const key in object) {
11529 if (Object.prototype.hasOwnProperty.call(object, key) && predicate(object[key])) {
11530 return key;
11531 }
11532 }
11533 return void 0;
11534 }
11535 function findIndex(array, predicate) {
11536 for (let key = 0; key < array.length; key++) {
11537 if (predicate(array[key])) {
11538 return key;
11539 }
11540 }
11541 return void 0;
11542 }
11543
11544 // packages/dataviews/node_modules/date-fns/locale/_lib/buildMatchPatternFn.js
11545 function buildMatchPatternFn(args) {
11546 return (string, options = {}) => {
11547 const matchResult = string.match(args.matchPattern);
11548 if (!matchResult) return null;
11549 const matchedString = matchResult[0];
11550 const parseResult = string.match(args.parsePattern);
11551 if (!parseResult) return null;
11552 let value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
11553 value = options.valueCallback ? options.valueCallback(value) : value;
11554 const rest = string.slice(matchedString.length);
11555 return { value, rest };
11556 };
11557 }
11558
11559 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/match.js
11560 var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
11561 var parseOrdinalNumberPattern = /\d+/i;
11562 var matchEraPatterns = {
11563 narrow: /^(b|a)/i,
11564 abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
11565 wide: /^(before christ|before common era|anno domini|common era)/i
11566 };
11567 var parseEraPatterns = {
11568 any: [/^b/i, /^(a|c)/i]
11569 };
11570 var matchQuarterPatterns = {
11571 narrow: /^[1234]/i,
11572 abbreviated: /^q[1234]/i,
11573 wide: /^[1234](th|st|nd|rd)? quarter/i
11574 };
11575 var parseQuarterPatterns = {
11576 any: [/1/i, /2/i, /3/i, /4/i]
11577 };
11578 var matchMonthPatterns = {
11579 narrow: /^[jfmasond]/i,
11580 abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
11581 wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
11582 };
11583 var parseMonthPatterns = {
11584 narrow: [
11585 /^j/i,
11586 /^f/i,
11587 /^m/i,
11588 /^a/i,
11589 /^m/i,
11590 /^j/i,
11591 /^j/i,
11592 /^a/i,
11593 /^s/i,
11594 /^o/i,
11595 /^n/i,
11596 /^d/i
11597 ],
11598 any: [
11599 /^ja/i,
11600 /^f/i,
11601 /^mar/i,
11602 /^ap/i,
11603 /^may/i,
11604 /^jun/i,
11605 /^jul/i,
11606 /^au/i,
11607 /^s/i,
11608 /^o/i,
11609 /^n/i,
11610 /^d/i
11611 ]
11612 };
11613 var matchDayPatterns = {
11614 narrow: /^[smtwf]/i,
11615 short: /^(su|mo|tu|we|th|fr|sa)/i,
11616 abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
11617 wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
11618 };
11619 var parseDayPatterns = {
11620 narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
11621 any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
11622 };
11623 var matchDayPeriodPatterns = {
11624 narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
11625 any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
11626 };
11627 var parseDayPeriodPatterns = {
11628 any: {
11629 am: /^a/i,
11630 pm: /^p/i,
11631 midnight: /^mi/i,
11632 noon: /^no/i,
11633 morning: /morning/i,
11634 afternoon: /afternoon/i,
11635 evening: /evening/i,
11636 night: /night/i
11637 }
11638 };
11639 var match = {
11640 ordinalNumber: buildMatchPatternFn({
11641 matchPattern: matchOrdinalNumberPattern,
11642 parsePattern: parseOrdinalNumberPattern,
11643 valueCallback: (value) => parseInt(value, 10)
11644 }),
11645 era: buildMatchFn({
11646 matchPatterns: matchEraPatterns,
11647 defaultMatchWidth: "wide",
11648 parsePatterns: parseEraPatterns,
11649 defaultParseWidth: "any"
11650 }),
11651 quarter: buildMatchFn({
11652 matchPatterns: matchQuarterPatterns,
11653 defaultMatchWidth: "wide",
11654 parsePatterns: parseQuarterPatterns,
11655 defaultParseWidth: "any",
11656 valueCallback: (index) => index + 1
11657 }),
11658 month: buildMatchFn({
11659 matchPatterns: matchMonthPatterns,
11660 defaultMatchWidth: "wide",
11661 parsePatterns: parseMonthPatterns,
11662 defaultParseWidth: "any"
11663 }),
11664 day: buildMatchFn({
11665 matchPatterns: matchDayPatterns,
11666 defaultMatchWidth: "wide",
11667 parsePatterns: parseDayPatterns,
11668 defaultParseWidth: "any"
11669 }),
11670 dayPeriod: buildMatchFn({
11671 matchPatterns: matchDayPeriodPatterns,
11672 defaultMatchWidth: "any",
11673 parsePatterns: parseDayPeriodPatterns,
11674 defaultParseWidth: "any"
11675 })
11676 };
11677
11678 // packages/dataviews/node_modules/date-fns/locale/en-US.js
11679 var enUS = {
11680 code: "en-US",
11681 formatDistance,
11682 formatLong,
11683 formatRelative,
11684 localize,
11685 match,
11686 options: {
11687 weekStartsOn: 0,
11688 firstWeekContainsDate: 1
11689 }
11690 };
11691
11692 // packages/dataviews/node_modules/date-fns/getDayOfYear.js
11693 function getDayOfYear(date, options) {
11694 const _date = toDate(date, options?.in);
11695 const diff = differenceInCalendarDays(_date, startOfYear(_date));
11696 const dayOfYear = diff + 1;
11697 return dayOfYear;
11698 }
11699
11700 // packages/dataviews/node_modules/date-fns/getISOWeek.js
11701 function getISOWeek(date, options) {
11702 const _date = toDate(date, options?.in);
11703 const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
11704 return Math.round(diff / millisecondsInWeek) + 1;
11705 }
11706
11707 // packages/dataviews/node_modules/date-fns/getWeekYear.js
11708 function getWeekYear(date, options) {
11709 const _date = toDate(date, options?.in);
11710 const year = _date.getFullYear();
11711 const defaultOptions2 = getDefaultOptions();
11712 const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
11713 const firstWeekOfNextYear = constructFrom(options?.in || date, 0);
11714 firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
11715 firstWeekOfNextYear.setHours(0, 0, 0, 0);
11716 const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
11717 const firstWeekOfThisYear = constructFrom(options?.in || date, 0);
11718 firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
11719 firstWeekOfThisYear.setHours(0, 0, 0, 0);
11720 const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
11721 if (+_date >= +startOfNextYear) {
11722 return year + 1;
11723 } else if (+_date >= +startOfThisYear) {
11724 return year;
11725 } else {
11726 return year - 1;
11727 }
11728 }
11729
11730 // packages/dataviews/node_modules/date-fns/startOfWeekYear.js
11731 function startOfWeekYear(date, options) {
11732 const defaultOptions2 = getDefaultOptions();
11733 const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
11734 const year = getWeekYear(date, options);
11735 const firstWeek = constructFrom(options?.in || date, 0);
11736 firstWeek.setFullYear(year, 0, firstWeekContainsDate);
11737 firstWeek.setHours(0, 0, 0, 0);
11738 const _date = startOfWeek(firstWeek, options);
11739 return _date;
11740 }
11741
11742 // packages/dataviews/node_modules/date-fns/getWeek.js
11743 function getWeek(date, options) {
11744 const _date = toDate(date, options?.in);
11745 const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
11746 return Math.round(diff / millisecondsInWeek) + 1;
11747 }
11748
11749 // packages/dataviews/node_modules/date-fns/_lib/addLeadingZeros.js
11750 function addLeadingZeros(number, targetLength) {
11751 const sign = number < 0 ? "-" : "";
11752 const output = Math.abs(number).toString().padStart(targetLength, "0");
11753 return sign + output;
11754 }
11755
11756 // packages/dataviews/node_modules/date-fns/_lib/format/lightFormatters.js
11757 var lightFormatters = {
11758 // Year
11759 y(date, token) {
11760 const signedYear = date.getFullYear();
11761 const year = signedYear > 0 ? signedYear : 1 - signedYear;
11762 return addLeadingZeros(token === "yy" ? year % 100 : year, token.length);
11763 },
11764 // Month
11765 M(date, token) {
11766 const month = date.getMonth();
11767 return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2);
11768 },
11769 // Day of the month
11770 d(date, token) {
11771 return addLeadingZeros(date.getDate(), token.length);
11772 },
11773 // AM or PM
11774 a(date, token) {
11775 const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am";
11776 switch (token) {
11777 case "a":
11778 case "aa":
11779 return dayPeriodEnumValue.toUpperCase();
11780 case "aaa":
11781 return dayPeriodEnumValue;
11782 case "aaaaa":
11783 return dayPeriodEnumValue[0];
11784 case "aaaa":
11785 default:
11786 return dayPeriodEnumValue === "am" ? "a.m." : "p.m.";
11787 }
11788 },
11789 // Hour [1-12]
11790 h(date, token) {
11791 return addLeadingZeros(date.getHours() % 12 || 12, token.length);
11792 },
11793 // Hour [0-23]
11794 H(date, token) {
11795 return addLeadingZeros(date.getHours(), token.length);
11796 },
11797 // Minute
11798 m(date, token) {
11799 return addLeadingZeros(date.getMinutes(), token.length);
11800 },
11801 // Second
11802 s(date, token) {
11803 return addLeadingZeros(date.getSeconds(), token.length);
11804 },
11805 // Fraction of second
11806 S(date, token) {
11807 const numberOfDigits = token.length;
11808 const milliseconds = date.getMilliseconds();
11809 const fractionalSeconds = Math.trunc(
11810 milliseconds * Math.pow(10, numberOfDigits - 3)
11811 );
11812 return addLeadingZeros(fractionalSeconds, token.length);
11813 }
11814 };
11815
11816 // packages/dataviews/node_modules/date-fns/_lib/format/formatters.js
11817 var dayPeriodEnum = {
11818 am: "am",
11819 pm: "pm",
11820 midnight: "midnight",
11821 noon: "noon",
11822 morning: "morning",
11823 afternoon: "afternoon",
11824 evening: "evening",
11825 night: "night"
11826 };
11827 var formatters = {
11828 // Era
11829 G: function(date, token, localize2) {
11830 const era = date.getFullYear() > 0 ? 1 : 0;
11831 switch (token) {
11832 // AD, BC
11833 case "G":
11834 case "GG":
11835 case "GGG":
11836 return localize2.era(era, { width: "abbreviated" });
11837 // A, B
11838 case "GGGGG":
11839 return localize2.era(era, { width: "narrow" });
11840 // Anno Domini, Before Christ
11841 case "GGGG":
11842 default:
11843 return localize2.era(era, { width: "wide" });
11844 }
11845 },
11846 // Year
11847 y: function(date, token, localize2) {
11848 if (token === "yo") {
11849 const signedYear = date.getFullYear();
11850 const year = signedYear > 0 ? signedYear : 1 - signedYear;
11851 return localize2.ordinalNumber(year, { unit: "year" });
11852 }
11853 return lightFormatters.y(date, token);
11854 },
11855 // Local week-numbering year
11856 Y: function(date, token, localize2, options) {
11857 const signedWeekYear = getWeekYear(date, options);
11858 const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
11859 if (token === "YY") {
11860 const twoDigitYear = weekYear % 100;
11861 return addLeadingZeros(twoDigitYear, 2);
11862 }
11863 if (token === "Yo") {
11864 return localize2.ordinalNumber(weekYear, { unit: "year" });
11865 }
11866 return addLeadingZeros(weekYear, token.length);
11867 },
11868 // ISO week-numbering year
11869 R: function(date, token) {
11870 const isoWeekYear = getISOWeekYear(date);
11871 return addLeadingZeros(isoWeekYear, token.length);
11872 },
11873 // Extended year. This is a single number designating the year of this calendar system.
11874 // The main difference between `y` and `u` localizers are B.C. years:
11875 // | Year | `y` | `u` |
11876 // |------|-----|-----|
11877 // | AC 1 | 1 | 1 |
11878 // | BC 1 | 1 | 0 |
11879 // | BC 2 | 2 | -1 |
11880 // Also `yy` always returns the last two digits of a year,
11881 // while `uu` pads single digit years to 2 characters and returns other years unchanged.
11882 u: function(date, token) {
11883 const year = date.getFullYear();
11884 return addLeadingZeros(year, token.length);
11885 },
11886 // Quarter
11887 Q: function(date, token, localize2) {
11888 const quarter = Math.ceil((date.getMonth() + 1) / 3);
11889 switch (token) {
11890 // 1, 2, 3, 4
11891 case "Q":
11892 return String(quarter);
11893 // 01, 02, 03, 04
11894 case "QQ":
11895 return addLeadingZeros(quarter, 2);
11896 // 1st, 2nd, 3rd, 4th
11897 case "Qo":
11898 return localize2.ordinalNumber(quarter, { unit: "quarter" });
11899 // Q1, Q2, Q3, Q4
11900 case "QQQ":
11901 return localize2.quarter(quarter, {
11902 width: "abbreviated",
11903 context: "formatting"
11904 });
11905 // 1, 2, 3, 4 (narrow quarter; could be not numerical)
11906 case "QQQQQ":
11907 return localize2.quarter(quarter, {
11908 width: "narrow",
11909 context: "formatting"
11910 });
11911 // 1st quarter, 2nd quarter, ...
11912 case "QQQQ":
11913 default:
11914 return localize2.quarter(quarter, {
11915 width: "wide",
11916 context: "formatting"
11917 });
11918 }
11919 },
11920 // Stand-alone quarter
11921 q: function(date, token, localize2) {
11922 const quarter = Math.ceil((date.getMonth() + 1) / 3);
11923 switch (token) {
11924 // 1, 2, 3, 4
11925 case "q":
11926 return String(quarter);
11927 // 01, 02, 03, 04
11928 case "qq":
11929 return addLeadingZeros(quarter, 2);
11930 // 1st, 2nd, 3rd, 4th
11931 case "qo":
11932 return localize2.ordinalNumber(quarter, { unit: "quarter" });
11933 // Q1, Q2, Q3, Q4
11934 case "qqq":
11935 return localize2.quarter(quarter, {
11936 width: "abbreviated",
11937 context: "standalone"
11938 });
11939 // 1, 2, 3, 4 (narrow quarter; could be not numerical)
11940 case "qqqqq":
11941 return localize2.quarter(quarter, {
11942 width: "narrow",
11943 context: "standalone"
11944 });
11945 // 1st quarter, 2nd quarter, ...
11946 case "qqqq":
11947 default:
11948 return localize2.quarter(quarter, {
11949 width: "wide",
11950 context: "standalone"
11951 });
11952 }
11953 },
11954 // Month
11955 M: function(date, token, localize2) {
11956 const month = date.getMonth();
11957 switch (token) {
11958 case "M":
11959 case "MM":
11960 return lightFormatters.M(date, token);
11961 // 1st, 2nd, ..., 12th
11962 case "Mo":
11963 return localize2.ordinalNumber(month + 1, { unit: "month" });
11964 // Jan, Feb, ..., Dec
11965 case "MMM":
11966 return localize2.month(month, {
11967 width: "abbreviated",
11968 context: "formatting"
11969 });
11970 // J, F, ..., D
11971 case "MMMMM":
11972 return localize2.month(month, {
11973 width: "narrow",
11974 context: "formatting"
11975 });
11976 // January, February, ..., December
11977 case "MMMM":
11978 default:
11979 return localize2.month(month, { width: "wide", context: "formatting" });
11980 }
11981 },
11982 // Stand-alone month
11983 L: function(date, token, localize2) {
11984 const month = date.getMonth();
11985 switch (token) {
11986 // 1, 2, ..., 12
11987 case "L":
11988 return String(month + 1);
11989 // 01, 02, ..., 12
11990 case "LL":
11991 return addLeadingZeros(month + 1, 2);
11992 // 1st, 2nd, ..., 12th
11993 case "Lo":
11994 return localize2.ordinalNumber(month + 1, { unit: "month" });
11995 // Jan, Feb, ..., Dec
11996 case "LLL":
11997 return localize2.month(month, {
11998 width: "abbreviated",
11999 context: "standalone"
12000 });
12001 // J, F, ..., D
12002 case "LLLLL":
12003 return localize2.month(month, {
12004 width: "narrow",
12005 context: "standalone"
12006 });
12007 // January, February, ..., December
12008 case "LLLL":
12009 default:
12010 return localize2.month(month, { width: "wide", context: "standalone" });
12011 }
12012 },
12013 // Local week of year
12014 w: function(date, token, localize2, options) {
12015 const week = getWeek(date, options);
12016 if (token === "wo") {
12017 return localize2.ordinalNumber(week, { unit: "week" });
12018 }
12019 return addLeadingZeros(week, token.length);
12020 },
12021 // ISO week of year
12022 I: function(date, token, localize2) {
12023 const isoWeek = getISOWeek(date);
12024 if (token === "Io") {
12025 return localize2.ordinalNumber(isoWeek, { unit: "week" });
12026 }
12027 return addLeadingZeros(isoWeek, token.length);
12028 },
12029 // Day of the month
12030 d: function(date, token, localize2) {
12031 if (token === "do") {
12032 return localize2.ordinalNumber(date.getDate(), { unit: "date" });
12033 }
12034 return lightFormatters.d(date, token);
12035 },
12036 // Day of year
12037 D: function(date, token, localize2) {
12038 const dayOfYear = getDayOfYear(date);
12039 if (token === "Do") {
12040 return localize2.ordinalNumber(dayOfYear, { unit: "dayOfYear" });
12041 }
12042 return addLeadingZeros(dayOfYear, token.length);
12043 },
12044 // Day of week
12045 E: function(date, token, localize2) {
12046 const dayOfWeek = date.getDay();
12047 switch (token) {
12048 // Tue
12049 case "E":
12050 case "EE":
12051 case "EEE":
12052 return localize2.day(dayOfWeek, {
12053 width: "abbreviated",
12054 context: "formatting"
12055 });
12056 // T
12057 case "EEEEE":
12058 return localize2.day(dayOfWeek, {
12059 width: "narrow",
12060 context: "formatting"
12061 });
12062 // Tu
12063 case "EEEEEE":
12064 return localize2.day(dayOfWeek, {
12065 width: "short",
12066 context: "formatting"
12067 });
12068 // Tuesday
12069 case "EEEE":
12070 default:
12071 return localize2.day(dayOfWeek, {
12072 width: "wide",
12073 context: "formatting"
12074 });
12075 }
12076 },
12077 // Local day of week
12078 e: function(date, token, localize2, options) {
12079 const dayOfWeek = date.getDay();
12080 const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
12081 switch (token) {
12082 // Numerical value (Nth day of week with current locale or weekStartsOn)
12083 case "e":
12084 return String(localDayOfWeek);
12085 // Padded numerical value
12086 case "ee":
12087 return addLeadingZeros(localDayOfWeek, 2);
12088 // 1st, 2nd, ..., 7th
12089 case "eo":
12090 return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
12091 case "eee":
12092 return localize2.day(dayOfWeek, {
12093 width: "abbreviated",
12094 context: "formatting"
12095 });
12096 // T
12097 case "eeeee":
12098 return localize2.day(dayOfWeek, {
12099 width: "narrow",
12100 context: "formatting"
12101 });
12102 // Tu
12103 case "eeeeee":
12104 return localize2.day(dayOfWeek, {
12105 width: "short",
12106 context: "formatting"
12107 });
12108 // Tuesday
12109 case "eeee":
12110 default:
12111 return localize2.day(dayOfWeek, {
12112 width: "wide",
12113 context: "formatting"
12114 });
12115 }
12116 },
12117 // Stand-alone local day of week
12118 c: function(date, token, localize2, options) {
12119 const dayOfWeek = date.getDay();
12120 const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
12121 switch (token) {
12122 // Numerical value (same as in `e`)
12123 case "c":
12124 return String(localDayOfWeek);
12125 // Padded numerical value
12126 case "cc":
12127 return addLeadingZeros(localDayOfWeek, token.length);
12128 // 1st, 2nd, ..., 7th
12129 case "co":
12130 return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
12131 case "ccc":
12132 return localize2.day(dayOfWeek, {
12133 width: "abbreviated",
12134 context: "standalone"
12135 });
12136 // T
12137 case "ccccc":
12138 return localize2.day(dayOfWeek, {
12139 width: "narrow",
12140 context: "standalone"
12141 });
12142 // Tu
12143 case "cccccc":
12144 return localize2.day(dayOfWeek, {
12145 width: "short",
12146 context: "standalone"
12147 });
12148 // Tuesday
12149 case "cccc":
12150 default:
12151 return localize2.day(dayOfWeek, {
12152 width: "wide",
12153 context: "standalone"
12154 });
12155 }
12156 },
12157 // ISO day of week
12158 i: function(date, token, localize2) {
12159 const dayOfWeek = date.getDay();
12160 const isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
12161 switch (token) {
12162 // 2
12163 case "i":
12164 return String(isoDayOfWeek);
12165 // 02
12166 case "ii":
12167 return addLeadingZeros(isoDayOfWeek, token.length);
12168 // 2nd
12169 case "io":
12170 return localize2.ordinalNumber(isoDayOfWeek, { unit: "day" });
12171 // Tue
12172 case "iii":
12173 return localize2.day(dayOfWeek, {
12174 width: "abbreviated",
12175 context: "formatting"
12176 });
12177 // T
12178 case "iiiii":
12179 return localize2.day(dayOfWeek, {
12180 width: "narrow",
12181 context: "formatting"
12182 });
12183 // Tu
12184 case "iiiiii":
12185 return localize2.day(dayOfWeek, {
12186 width: "short",
12187 context: "formatting"
12188 });
12189 // Tuesday
12190 case "iiii":
12191 default:
12192 return localize2.day(dayOfWeek, {
12193 width: "wide",
12194 context: "formatting"
12195 });
12196 }
12197 },
12198 // AM or PM
12199 a: function(date, token, localize2) {
12200 const hours = date.getHours();
12201 const dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
12202 switch (token) {
12203 case "a":
12204 case "aa":
12205 return localize2.dayPeriod(dayPeriodEnumValue, {
12206 width: "abbreviated",
12207 context: "formatting"
12208 });
12209 case "aaa":
12210 return localize2.dayPeriod(dayPeriodEnumValue, {
12211 width: "abbreviated",
12212 context: "formatting"
12213 }).toLowerCase();
12214 case "aaaaa":
12215 return localize2.dayPeriod(dayPeriodEnumValue, {
12216 width: "narrow",
12217 context: "formatting"
12218 });
12219 case "aaaa":
12220 default:
12221 return localize2.dayPeriod(dayPeriodEnumValue, {
12222 width: "wide",
12223 context: "formatting"
12224 });
12225 }
12226 },
12227 // AM, PM, midnight, noon
12228 b: function(date, token, localize2) {
12229 const hours = date.getHours();
12230 let dayPeriodEnumValue;
12231 if (hours === 12) {
12232 dayPeriodEnumValue = dayPeriodEnum.noon;
12233 } else if (hours === 0) {
12234 dayPeriodEnumValue = dayPeriodEnum.midnight;
12235 } else {
12236 dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
12237 }
12238 switch (token) {
12239 case "b":
12240 case "bb":
12241 return localize2.dayPeriod(dayPeriodEnumValue, {
12242 width: "abbreviated",
12243 context: "formatting"
12244 });
12245 case "bbb":
12246 return localize2.dayPeriod(dayPeriodEnumValue, {
12247 width: "abbreviated",
12248 context: "formatting"
12249 }).toLowerCase();
12250 case "bbbbb":
12251 return localize2.dayPeriod(dayPeriodEnumValue, {
12252 width: "narrow",
12253 context: "formatting"
12254 });
12255 case "bbbb":
12256 default:
12257 return localize2.dayPeriod(dayPeriodEnumValue, {
12258 width: "wide",
12259 context: "formatting"
12260 });
12261 }
12262 },
12263 // in the morning, in the afternoon, in the evening, at night
12264 B: function(date, token, localize2) {
12265 const hours = date.getHours();
12266 let dayPeriodEnumValue;
12267 if (hours >= 17) {
12268 dayPeriodEnumValue = dayPeriodEnum.evening;
12269 } else if (hours >= 12) {
12270 dayPeriodEnumValue = dayPeriodEnum.afternoon;
12271 } else if (hours >= 4) {
12272 dayPeriodEnumValue = dayPeriodEnum.morning;
12273 } else {
12274 dayPeriodEnumValue = dayPeriodEnum.night;
12275 }
12276 switch (token) {
12277 case "B":
12278 case "BB":
12279 case "BBB":
12280 return localize2.dayPeriod(dayPeriodEnumValue, {
12281 width: "abbreviated",
12282 context: "formatting"
12283 });
12284 case "BBBBB":
12285 return localize2.dayPeriod(dayPeriodEnumValue, {
12286 width: "narrow",
12287 context: "formatting"
12288 });
12289 case "BBBB":
12290 default:
12291 return localize2.dayPeriod(dayPeriodEnumValue, {
12292 width: "wide",
12293 context: "formatting"
12294 });
12295 }
12296 },
12297 // Hour [1-12]
12298 h: function(date, token, localize2) {
12299 if (token === "ho") {
12300 let hours = date.getHours() % 12;
12301 if (hours === 0) hours = 12;
12302 return localize2.ordinalNumber(hours, { unit: "hour" });
12303 }
12304 return lightFormatters.h(date, token);
12305 },
12306 // Hour [0-23]
12307 H: function(date, token, localize2) {
12308 if (token === "Ho") {
12309 return localize2.ordinalNumber(date.getHours(), { unit: "hour" });
12310 }
12311 return lightFormatters.H(date, token);
12312 },
12313 // Hour [0-11]
12314 K: function(date, token, localize2) {
12315 const hours = date.getHours() % 12;
12316 if (token === "Ko") {
12317 return localize2.ordinalNumber(hours, { unit: "hour" });
12318 }
12319 return addLeadingZeros(hours, token.length);
12320 },
12321 // Hour [1-24]
12322 k: function(date, token, localize2) {
12323 let hours = date.getHours();
12324 if (hours === 0) hours = 24;
12325 if (token === "ko") {
12326 return localize2.ordinalNumber(hours, { unit: "hour" });
12327 }
12328 return addLeadingZeros(hours, token.length);
12329 },
12330 // Minute
12331 m: function(date, token, localize2) {
12332 if (token === "mo") {
12333 return localize2.ordinalNumber(date.getMinutes(), { unit: "minute" });
12334 }
12335 return lightFormatters.m(date, token);
12336 },
12337 // Second
12338 s: function(date, token, localize2) {
12339 if (token === "so") {
12340 return localize2.ordinalNumber(date.getSeconds(), { unit: "second" });
12341 }
12342 return lightFormatters.s(date, token);
12343 },
12344 // Fraction of second
12345 S: function(date, token) {
12346 return lightFormatters.S(date, token);
12347 },
12348 // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
12349 X: function(date, token, _localize) {
12350 const timezoneOffset = date.getTimezoneOffset();
12351 if (timezoneOffset === 0) {
12352 return "Z";
12353 }
12354 switch (token) {
12355 // Hours and optional minutes
12356 case "X":
12357 return formatTimezoneWithOptionalMinutes(timezoneOffset);
12358 // Hours, minutes and optional seconds without `:` delimiter
12359 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12360 // so this token always has the same output as `XX`
12361 case "XXXX":
12362 case "XX":
12363 return formatTimezone(timezoneOffset);
12364 // Hours, minutes and optional seconds with `:` delimiter
12365 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12366 // so this token always has the same output as `XXX`
12367 case "XXXXX":
12368 case "XXX":
12369 // Hours and minutes with `:` delimiter
12370 default:
12371 return formatTimezone(timezoneOffset, ":");
12372 }
12373 },
12374 // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
12375 x: function(date, token, _localize) {
12376 const timezoneOffset = date.getTimezoneOffset();
12377 switch (token) {
12378 // Hours and optional minutes
12379 case "x":
12380 return formatTimezoneWithOptionalMinutes(timezoneOffset);
12381 // Hours, minutes and optional seconds without `:` delimiter
12382 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12383 // so this token always has the same output as `xx`
12384 case "xxxx":
12385 case "xx":
12386 return formatTimezone(timezoneOffset);
12387 // Hours, minutes and optional seconds with `:` delimiter
12388 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
12389 // so this token always has the same output as `xxx`
12390 case "xxxxx":
12391 case "xxx":
12392 // Hours and minutes with `:` delimiter
12393 default:
12394 return formatTimezone(timezoneOffset, ":");
12395 }
12396 },
12397 // Timezone (GMT)
12398 O: function(date, token, _localize) {
12399 const timezoneOffset = date.getTimezoneOffset();
12400 switch (token) {
12401 // Short
12402 case "O":
12403 case "OO":
12404 case "OOO":
12405 return "GMT" + formatTimezoneShort(timezoneOffset, ":");
12406 // Long
12407 case "OOOO":
12408 default:
12409 return "GMT" + formatTimezone(timezoneOffset, ":");
12410 }
12411 },
12412 // Timezone (specific non-location)
12413 z: function(date, token, _localize) {
12414 const timezoneOffset = date.getTimezoneOffset();
12415 switch (token) {
12416 // Short
12417 case "z":
12418 case "zz":
12419 case "zzz":
12420 return "GMT" + formatTimezoneShort(timezoneOffset, ":");
12421 // Long
12422 case "zzzz":
12423 default:
12424 return "GMT" + formatTimezone(timezoneOffset, ":");
12425 }
12426 },
12427 // Seconds timestamp
12428 t: function(date, token, _localize) {
12429 const timestamp = Math.trunc(+date / 1e3);
12430 return addLeadingZeros(timestamp, token.length);
12431 },
12432 // Milliseconds timestamp
12433 T: function(date, token, _localize) {
12434 return addLeadingZeros(+date, token.length);
12435 }
12436 };
12437 function formatTimezoneShort(offset, delimiter = "") {
12438 const sign = offset > 0 ? "-" : "+";
12439 const absOffset = Math.abs(offset);
12440 const hours = Math.trunc(absOffset / 60);
12441 const minutes = absOffset % 60;
12442 if (minutes === 0) {
12443 return sign + String(hours);
12444 }
12445 return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
12446 }
12447 function formatTimezoneWithOptionalMinutes(offset, delimiter) {
12448 if (offset % 60 === 0) {
12449 const sign = offset > 0 ? "-" : "+";
12450 return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
12451 }
12452 return formatTimezone(offset, delimiter);
12453 }
12454 function formatTimezone(offset, delimiter = "") {
12455 const sign = offset > 0 ? "-" : "+";
12456 const absOffset = Math.abs(offset);
12457 const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2);
12458 const minutes = addLeadingZeros(absOffset % 60, 2);
12459 return sign + hours + delimiter + minutes;
12460 }
12461
12462 // packages/dataviews/node_modules/date-fns/_lib/format/longFormatters.js
12463 var dateLongFormatter = (pattern, formatLong2) => {
12464 switch (pattern) {
12465 case "P":
12466 return formatLong2.date({ width: "short" });
12467 case "PP":
12468 return formatLong2.date({ width: "medium" });
12469 case "PPP":
12470 return formatLong2.date({ width: "long" });
12471 case "PPPP":
12472 default:
12473 return formatLong2.date({ width: "full" });
12474 }
12475 };
12476 var timeLongFormatter = (pattern, formatLong2) => {
12477 switch (pattern) {
12478 case "p":
12479 return formatLong2.time({ width: "short" });
12480 case "pp":
12481 return formatLong2.time({ width: "medium" });
12482 case "ppp":
12483 return formatLong2.time({ width: "long" });
12484 case "pppp":
12485 default:
12486 return formatLong2.time({ width: "full" });
12487 }
12488 };
12489 var dateTimeLongFormatter = (pattern, formatLong2) => {
12490 const matchResult = pattern.match(/(P+)(p+)?/) || [];
12491 const datePattern = matchResult[1];
12492 const timePattern = matchResult[2];
12493 if (!timePattern) {
12494 return dateLongFormatter(pattern, formatLong2);
12495 }
12496 let dateTimeFormat;
12497 switch (datePattern) {
12498 case "P":
12499 dateTimeFormat = formatLong2.dateTime({ width: "short" });
12500 break;
12501 case "PP":
12502 dateTimeFormat = formatLong2.dateTime({ width: "medium" });
12503 break;
12504 case "PPP":
12505 dateTimeFormat = formatLong2.dateTime({ width: "long" });
12506 break;
12507 case "PPPP":
12508 default:
12509 dateTimeFormat = formatLong2.dateTime({ width: "full" });
12510 break;
12511 }
12512 return dateTimeFormat.replace("{{date}}", dateLongFormatter(datePattern, formatLong2)).replace("{{time}}", timeLongFormatter(timePattern, formatLong2));
12513 };
12514 var longFormatters = {
12515 p: timeLongFormatter,
12516 P: dateTimeLongFormatter
12517 };
12518
12519 // packages/dataviews/node_modules/date-fns/_lib/protectedTokens.js
12520 var dayOfYearTokenRE = /^D+$/;
12521 var weekYearTokenRE = /^Y+$/;
12522 var throwTokens = ["D", "DD", "YY", "YYYY"];
12523 function isProtectedDayOfYearToken(token) {
12524 return dayOfYearTokenRE.test(token);
12525 }
12526 function isProtectedWeekYearToken(token) {
12527 return weekYearTokenRE.test(token);
12528 }
12529 function warnOrThrowProtectedError(token, format6, input) {
12530 const _message = message(token, format6, input);
12531 console.warn(_message);
12532 if (throwTokens.includes(token)) throw new RangeError(_message);
12533 }
12534 function message(token, format6, input) {
12535 const subject = token[0] === "Y" ? "years" : "days of the month";
12536 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`;
12537 }
12538
12539 // packages/dataviews/node_modules/date-fns/format.js
12540 var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
12541 var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
12542 var escapedStringRegExp = /^'([^]*?)'?$/;
12543 var doubleQuoteRegExp = /''/g;
12544 var unescapedLatinCharacterRegExp = /[a-zA-Z]/;
12545 function format(date, formatStr, options) {
12546 const defaultOptions2 = getDefaultOptions();
12547 const locale = options?.locale ?? defaultOptions2.locale ?? enUS;
12548 const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
12549 const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
12550 const originalDate = toDate(date, options?.in);
12551 if (!isValid(originalDate)) {
12552 throw new RangeError("Invalid time value");
12553 }
12554 let parts = formatStr.match(longFormattingTokensRegExp).map((substring) => {
12555 const firstCharacter = substring[0];
12556 if (firstCharacter === "p" || firstCharacter === "P") {
12557 const longFormatter = longFormatters[firstCharacter];
12558 return longFormatter(substring, locale.formatLong);
12559 }
12560 return substring;
12561 }).join("").match(formattingTokensRegExp).map((substring) => {
12562 if (substring === "''") {
12563 return { isToken: false, value: "'" };
12564 }
12565 const firstCharacter = substring[0];
12566 if (firstCharacter === "'") {
12567 return { isToken: false, value: cleanEscapedString(substring) };
12568 }
12569 if (formatters[firstCharacter]) {
12570 return { isToken: true, value: substring };
12571 }
12572 if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
12573 throw new RangeError(
12574 "Format string contains an unescaped latin alphabet character `" + firstCharacter + "`"
12575 );
12576 }
12577 return { isToken: false, value: substring };
12578 });
12579 if (locale.localize.preprocessor) {
12580 parts = locale.localize.preprocessor(originalDate, parts);
12581 }
12582 const formatterOptions = {
12583 firstWeekContainsDate,
12584 weekStartsOn,
12585 locale
12586 };
12587 return parts.map((part) => {
12588 if (!part.isToken) return part.value;
12589 const token = part.value;
12590 if (!options?.useAdditionalWeekYearTokens && isProtectedWeekYearToken(token) || !options?.useAdditionalDayOfYearTokens && isProtectedDayOfYearToken(token)) {
12591 warnOrThrowProtectedError(token, formatStr, String(date));
12592 }
12593 const formatter = formatters[token[0]];
12594 return formatter(originalDate, token, locale.localize, formatterOptions);
12595 }).join("");
12596 }
12597 function cleanEscapedString(input) {
12598 const matched = input.match(escapedStringRegExp);
12599 if (!matched) {
12600 return input;
12601 }
12602 return matched[1].replace(doubleQuoteRegExp, "'");
12603 }
12604
12605 // packages/dataviews/node_modules/date-fns/subDays.js
12606 function subDays(date, amount, options) {
12607 return addDays(date, -amount, options);
12608 }
12609
12610 // packages/dataviews/node_modules/date-fns/subMonths.js
12611 function subMonths(date, amount, options) {
12612 return addMonths(date, -amount, options);
12613 }
12614
12615 // packages/dataviews/node_modules/date-fns/subWeeks.js
12616 function subWeeks(date, amount, options) {
12617 return addWeeks(date, -amount, options);
12618 }
12619
12620 // packages/dataviews/node_modules/date-fns/subYears.js
12621 function subYears(date, amount, options) {
12622 return addYears(date, -amount, options);
12623 }
12624
12625 // packages/dataviews/build-module/utils/operators.mjs
12626 var import_i18n29 = __toESM(require_i18n(), 1);
12627 var import_element28 = __toESM(require_element(), 1);
12628 var import_date = __toESM(require_date(), 1);
12629 var import_jsx_runtime64 = __toESM(require_jsx_runtime(), 1);
12630 var filterTextWrappers = {
12631 Name: /* @__PURE__ */ (0, import_jsx_runtime64.jsx)("span", { className: "dataviews-filters__summary-filter-text-name" }),
12632 Value: /* @__PURE__ */ (0, import_jsx_runtime64.jsx)("span", { className: "dataviews-filters__summary-filter-text-value" })
12633 };
12634 function getRelativeDate(value, unit) {
12635 switch (unit) {
12636 case "days":
12637 return subDays(/* @__PURE__ */ new Date(), value);
12638 case "weeks":
12639 return subWeeks(/* @__PURE__ */ new Date(), value);
12640 case "months":
12641 return subMonths(/* @__PURE__ */ new Date(), value);
12642 case "years":
12643 return subYears(/* @__PURE__ */ new Date(), value);
12644 default:
12645 return /* @__PURE__ */ new Date();
12646 }
12647 }
12648 var isNoneOperatorDefinition = {
12649 /* translators: DataViews operator name */
12650 label: (0, import_i18n29.__)("Is none of"),
12651 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12652 (0, import_i18n29.sprintf)(
12653 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is none of: Admin, Editor". */
12654 (0, import_i18n29.__)("<Name>%1$s is none of: </Name><Value>%2$s</Value>"),
12655 filter.name,
12656 activeElements.map((element) => element.label).join(", ")
12657 ),
12658 filterTextWrappers
12659 ),
12660 filter: ((item, field, filterValue) => {
12661 if (!filterValue?.length) {
12662 return true;
12663 }
12664 const fieldValue = field.getValue({ item });
12665 if (Array.isArray(fieldValue)) {
12666 return !filterValue.some(
12667 (fv) => fieldValue.includes(fv)
12668 );
12669 } else if (typeof fieldValue === "string") {
12670 return !filterValue.includes(fieldValue);
12671 }
12672 return false;
12673 }),
12674 selection: "multi"
12675 };
12676 var OPERATORS = [
12677 {
12678 name: OPERATOR_IS_ANY,
12679 /* translators: DataViews operator name */
12680 label: (0, import_i18n29.__)("Includes"),
12681 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12682 (0, import_i18n29.sprintf)(
12683 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is any: Admin, Editor". */
12684 (0, import_i18n29.__)("<Name>%1$s includes: </Name><Value>%2$s</Value>"),
12685 filter.name,
12686 activeElements.map((element) => element.label).join(", ")
12687 ),
12688 filterTextWrappers
12689 ),
12690 filter(item, field, filterValue) {
12691 if (!filterValue?.length) {
12692 return true;
12693 }
12694 const fieldValue = field.getValue({ item });
12695 if (Array.isArray(fieldValue)) {
12696 return filterValue.some(
12697 (fv) => fieldValue.includes(fv)
12698 );
12699 } else if (typeof fieldValue === "string") {
12700 return filterValue.includes(fieldValue);
12701 }
12702 return false;
12703 },
12704 selection: "multi"
12705 },
12706 {
12707 name: OPERATOR_IS_NONE,
12708 ...isNoneOperatorDefinition
12709 },
12710 {
12711 name: OPERATOR_IS_ALL,
12712 /* translators: DataViews operator name */
12713 label: (0, import_i18n29.__)("Includes all"),
12714 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12715 (0, import_i18n29.sprintf)(
12716 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author includes all: Admin, Editor". */
12717 (0, import_i18n29.__)("<Name>%1$s includes all: </Name><Value>%2$s</Value>"),
12718 filter.name,
12719 activeElements.map((element) => element.label).join(", ")
12720 ),
12721 filterTextWrappers
12722 ),
12723 filter(item, field, filterValue) {
12724 if (!filterValue?.length) {
12725 return true;
12726 }
12727 return filterValue.every((value) => {
12728 return field.getValue({ item })?.includes(value);
12729 });
12730 },
12731 selection: "multi"
12732 },
12733 {
12734 name: OPERATOR_IS_NOT_ALL,
12735 ...isNoneOperatorDefinition
12736 },
12737 {
12738 name: OPERATOR_BETWEEN,
12739 /* translators: DataViews operator name */
12740 label: (0, import_i18n29.__)("Between (inc)"),
12741 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12742 (0, import_i18n29.sprintf)(
12743 /* 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". */
12744 (0, import_i18n29.__)(
12745 "<Name>%1$s between (inc): </Name><Value>%2$s and %3$s</Value>"
12746 ),
12747 filter.name,
12748 activeElements[0].label[0],
12749 activeElements[0].label[1]
12750 ),
12751 filterTextWrappers
12752 ),
12753 filter(item, field, filterValue) {
12754 if (!Array.isArray(filterValue) || filterValue.length !== 2 || filterValue[0] === void 0 || filterValue[1] === void 0) {
12755 return true;
12756 }
12757 const fieldValue = field.getValue({ item });
12758 if (typeof fieldValue === "number" || fieldValue instanceof Date || typeof fieldValue === "string") {
12759 return fieldValue >= filterValue[0] && fieldValue <= filterValue[1];
12760 }
12761 return false;
12762 },
12763 selection: "custom"
12764 },
12765 {
12766 name: OPERATOR_IN_THE_PAST,
12767 /* translators: DataViews operator name */
12768 label: (0, import_i18n29.__)("In the past"),
12769 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12770 (0, import_i18n29.sprintf)(
12771 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "7 days"): "Date is in the past: 7 days". */
12772 (0, import_i18n29.__)(
12773 "<Name>%1$s is in the past: </Name><Value>%2$s</Value>"
12774 ),
12775 filter.name,
12776 `${activeElements[0].value.value} ${activeElements[0].value.unit}`
12777 ),
12778 filterTextWrappers
12779 ),
12780 filter(item, field, filterValue) {
12781 if (filterValue?.value === void 0 || filterValue?.unit === void 0) {
12782 return true;
12783 }
12784 const targetDate = getRelativeDate(
12785 filterValue.value,
12786 filterValue.unit
12787 );
12788 const fieldValue = (0, import_date.getDate)(field.getValue({ item }));
12789 return fieldValue >= targetDate && fieldValue <= /* @__PURE__ */ new Date();
12790 },
12791 selection: "custom"
12792 },
12793 {
12794 name: OPERATOR_OVER,
12795 /* translators: DataViews operator name */
12796 label: (0, import_i18n29.__)("Over"),
12797 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12798 (0, import_i18n29.sprintf)(
12799 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "7 days"): "Date is over: 7 days". */
12800 (0, import_i18n29.__)("<Name>%1$s is over: </Name><Value>%2$s</Value>"),
12801 filter.name,
12802 `${activeElements[0].value.value} ${activeElements[0].value.unit}`
12803 ),
12804 filterTextWrappers
12805 ),
12806 filter(item, field, filterValue) {
12807 if (filterValue?.value === void 0 || filterValue?.unit === void 0) {
12808 return true;
12809 }
12810 const targetDate = getRelativeDate(
12811 filterValue.value,
12812 filterValue.unit
12813 );
12814 const fieldValue = (0, import_date.getDate)(field.getValue({ item }));
12815 return fieldValue < targetDate;
12816 },
12817 selection: "custom"
12818 },
12819 {
12820 name: OPERATOR_IS,
12821 /* translators: DataViews operator name */
12822 label: (0, import_i18n29.__)("Is"),
12823 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12824 (0, import_i18n29.sprintf)(
12825 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is: Admin". */
12826 (0, import_i18n29.__)("<Name>%1$s is: </Name><Value>%2$s</Value>"),
12827 filter.name,
12828 activeElements[0].label
12829 ),
12830 filterTextWrappers
12831 ),
12832 filter(item, field, filterValue) {
12833 return filterValue === field.getValue({ item }) || filterValue === void 0;
12834 },
12835 selection: "single"
12836 },
12837 {
12838 name: OPERATOR_IS_NOT,
12839 /* translators: DataViews operator name */
12840 label: (0, import_i18n29.__)("Is not"),
12841 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12842 (0, import_i18n29.sprintf)(
12843 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is not: Admin". */
12844 (0, import_i18n29.__)("<Name>%1$s is not: </Name><Value>%2$s</Value>"),
12845 filter.name,
12846 activeElements[0].label
12847 ),
12848 filterTextWrappers
12849 ),
12850 filter(item, field, filterValue) {
12851 return filterValue !== field.getValue({ item });
12852 },
12853 selection: "single"
12854 },
12855 {
12856 name: OPERATOR_LESS_THAN,
12857 /* translators: DataViews operator name */
12858 label: (0, import_i18n29.__)("Less than"),
12859 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12860 (0, import_i18n29.sprintf)(
12861 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is less than: 10". */
12862 (0, import_i18n29.__)("<Name>%1$s is less than: </Name><Value>%2$s</Value>"),
12863 filter.name,
12864 activeElements[0].label
12865 ),
12866 filterTextWrappers
12867 ),
12868 filter(item, field, filterValue) {
12869 if (filterValue === void 0) {
12870 return true;
12871 }
12872 const fieldValue = field.getValue({ item });
12873 return fieldValue < filterValue;
12874 },
12875 selection: "single"
12876 },
12877 {
12878 name: OPERATOR_GREATER_THAN,
12879 /* translators: DataViews operator name */
12880 label: (0, import_i18n29.__)("Greater than"),
12881 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12882 (0, import_i18n29.sprintf)(
12883 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is greater than: 10". */
12884 (0, import_i18n29.__)(
12885 "<Name>%1$s is greater than: </Name><Value>%2$s</Value>"
12886 ),
12887 filter.name,
12888 activeElements[0].label
12889 ),
12890 filterTextWrappers
12891 ),
12892 filter(item, field, filterValue) {
12893 if (filterValue === void 0) {
12894 return true;
12895 }
12896 const fieldValue = field.getValue({ item });
12897 return fieldValue > filterValue;
12898 },
12899 selection: "single"
12900 },
12901 {
12902 name: OPERATOR_LESS_THAN_OR_EQUAL,
12903 /* translators: DataViews operator name */
12904 label: (0, import_i18n29.__)("Less than or equal"),
12905 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12906 (0, import_i18n29.sprintf)(
12907 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is less than or equal to: 10". */
12908 (0, import_i18n29.__)(
12909 "<Name>%1$s is less than or equal to: </Name><Value>%2$s</Value>"
12910 ),
12911 filter.name,
12912 activeElements[0].label
12913 ),
12914 filterTextWrappers
12915 ),
12916 filter(item, field, filterValue) {
12917 if (filterValue === void 0) {
12918 return true;
12919 }
12920 const fieldValue = field.getValue({ item });
12921 return fieldValue <= filterValue;
12922 },
12923 selection: "single"
12924 },
12925 {
12926 name: OPERATOR_GREATER_THAN_OR_EQUAL,
12927 /* translators: DataViews operator name */
12928 label: (0, import_i18n29.__)("Greater than or equal"),
12929 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12930 (0, import_i18n29.sprintf)(
12931 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is greater than or equal to: 10". */
12932 (0, import_i18n29.__)(
12933 "<Name>%1$s is greater than or equal to: </Name><Value>%2$s</Value>"
12934 ),
12935 filter.name,
12936 activeElements[0].label
12937 ),
12938 filterTextWrappers
12939 ),
12940 filter(item, field, filterValue) {
12941 if (filterValue === void 0) {
12942 return true;
12943 }
12944 const fieldValue = field.getValue({ item });
12945 return fieldValue >= filterValue;
12946 },
12947 selection: "single"
12948 },
12949 {
12950 name: OPERATOR_BEFORE,
12951 /* translators: DataViews operator name */
12952 label: (0, import_i18n29.__)("Before"),
12953 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12954 (0, import_i18n29.sprintf)(
12955 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is before: 2024-01-01". */
12956 (0, import_i18n29.__)("<Name>%1$s is before: </Name><Value>%2$s</Value>"),
12957 filter.name,
12958 activeElements[0].label
12959 ),
12960 filterTextWrappers
12961 ),
12962 filter(item, field, filterValue) {
12963 if (filterValue === void 0) {
12964 return true;
12965 }
12966 const filterDate = (0, import_date.getDate)(filterValue);
12967 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
12968 return fieldDate < filterDate;
12969 },
12970 selection: "single"
12971 },
12972 {
12973 name: OPERATOR_AFTER,
12974 /* translators: DataViews operator name */
12975 label: (0, import_i18n29.__)("After"),
12976 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
12977 (0, import_i18n29.sprintf)(
12978 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is after: 2024-01-01". */
12979 (0, import_i18n29.__)("<Name>%1$s is after: </Name><Value>%2$s</Value>"),
12980 filter.name,
12981 activeElements[0].label
12982 ),
12983 filterTextWrappers
12984 ),
12985 filter(item, field, filterValue) {
12986 if (filterValue === void 0) {
12987 return true;
12988 }
12989 const filterDate = (0, import_date.getDate)(filterValue);
12990 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
12991 return fieldDate > filterDate;
12992 },
12993 selection: "single"
12994 },
12995 {
12996 name: OPERATOR_BEFORE_INC,
12997 /* translators: DataViews operator name */
12998 label: (0, import_i18n29.__)("Before (inc)"),
12999 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
13000 (0, import_i18n29.sprintf)(
13001 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is on or before: 2024-01-01". */
13002 (0, import_i18n29.__)(
13003 "<Name>%1$s is on or before: </Name><Value>%2$s</Value>"
13004 ),
13005 filter.name,
13006 activeElements[0].label
13007 ),
13008 filterTextWrappers
13009 ),
13010 filter(item, field, filterValue) {
13011 if (filterValue === void 0) {
13012 return true;
13013 }
13014 const filterDate = (0, import_date.getDate)(filterValue);
13015 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13016 return fieldDate <= filterDate;
13017 },
13018 selection: "single"
13019 },
13020 {
13021 name: OPERATOR_AFTER_INC,
13022 /* translators: DataViews operator name */
13023 label: (0, import_i18n29.__)("After (inc)"),
13024 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
13025 (0, import_i18n29.sprintf)(
13026 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is on or after: 2024-01-01". */
13027 (0, import_i18n29.__)(
13028 "<Name>%1$s is on or after: </Name><Value>%2$s</Value>"
13029 ),
13030 filter.name,
13031 activeElements[0].label
13032 ),
13033 filterTextWrappers
13034 ),
13035 filter(item, field, filterValue) {
13036 if (filterValue === void 0) {
13037 return true;
13038 }
13039 const filterDate = (0, import_date.getDate)(filterValue);
13040 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13041 return fieldDate >= filterDate;
13042 },
13043 selection: "single"
13044 },
13045 {
13046 name: OPERATOR_CONTAINS,
13047 /* translators: DataViews operator name */
13048 label: (0, import_i18n29.__)("Contains"),
13049 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
13050 (0, import_i18n29.sprintf)(
13051 /* translators: 1: Filter name (e.g. "Title"). 2: Filter value (e.g. "Hello"): "Title contains: Hello". */
13052 (0, import_i18n29.__)("<Name>%1$s contains: </Name><Value>%2$s</Value>"),
13053 filter.name,
13054 activeElements[0].label
13055 ),
13056 filterTextWrappers
13057 ),
13058 filter(item, field, filterValue) {
13059 if (filterValue === void 0) {
13060 return true;
13061 }
13062 const fieldValue = field.getValue({ item });
13063 return typeof fieldValue === "string" && filterValue && fieldValue.toLowerCase().includes(String(filterValue).toLowerCase());
13064 },
13065 selection: "single"
13066 },
13067 {
13068 name: OPERATOR_NOT_CONTAINS,
13069 /* translators: DataViews operator name */
13070 label: (0, import_i18n29.__)("Doesn't contain"),
13071 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
13072 (0, import_i18n29.sprintf)(
13073 /* translators: 1: Filter name (e.g. "Title"). 2: Filter value (e.g. "Hello"): "Title doesn't contain: Hello". */
13074 (0, import_i18n29.__)(
13075 "<Name>%1$s doesn't contain: </Name><Value>%2$s</Value>"
13076 ),
13077 filter.name,
13078 activeElements[0].label
13079 ),
13080 filterTextWrappers
13081 ),
13082 filter(item, field, filterValue) {
13083 if (filterValue === void 0) {
13084 return true;
13085 }
13086 const fieldValue = field.getValue({ item });
13087 return typeof fieldValue === "string" && filterValue && !fieldValue.toLowerCase().includes(String(filterValue).toLowerCase());
13088 },
13089 selection: "single"
13090 },
13091 {
13092 name: OPERATOR_STARTS_WITH,
13093 /* translators: DataViews operator name */
13094 label: (0, import_i18n29.__)("Starts with"),
13095 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
13096 (0, import_i18n29.sprintf)(
13097 /* translators: 1: Filter name (e.g. "Title"). 2: Filter value (e.g. "Hello"): "Title starts with: Hello". */
13098 (0, import_i18n29.__)("<Name>%1$s starts with: </Name><Value>%2$s</Value>"),
13099 filter.name,
13100 activeElements[0].label
13101 ),
13102 filterTextWrappers
13103 ),
13104 filter(item, field, filterValue) {
13105 if (filterValue === void 0) {
13106 return true;
13107 }
13108 const fieldValue = field.getValue({ item });
13109 return typeof fieldValue === "string" && filterValue && fieldValue.toLowerCase().startsWith(String(filterValue).toLowerCase());
13110 },
13111 selection: "single"
13112 },
13113 {
13114 name: OPERATOR_ON,
13115 /* translators: DataViews operator name */
13116 label: (0, import_i18n29.__)("On"),
13117 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
13118 (0, import_i18n29.sprintf)(
13119 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is: 2024-01-01". */
13120 (0, import_i18n29.__)("<Name>%1$s is: </Name><Value>%2$s</Value>"),
13121 filter.name,
13122 activeElements[0].label
13123 ),
13124 filterTextWrappers
13125 ),
13126 filter(item, field, filterValue) {
13127 if (filterValue === void 0) {
13128 return true;
13129 }
13130 const filterDate = (0, import_date.getDate)(filterValue);
13131 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13132 return filterDate.getTime() === fieldDate.getTime();
13133 },
13134 selection: "single"
13135 },
13136 {
13137 name: OPERATOR_NOT_ON,
13138 /* translators: DataViews operator name */
13139 label: (0, import_i18n29.__)("Not on"),
13140 filterText: (filter, activeElements) => (0, import_element28.createInterpolateElement)(
13141 (0, import_i18n29.sprintf)(
13142 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is not: 2024-01-01". */
13143 (0, import_i18n29.__)("<Name>%1$s is not: </Name><Value>%2$s</Value>"),
13144 filter.name,
13145 activeElements[0].label
13146 ),
13147 filterTextWrappers
13148 ),
13149 filter(item, field, filterValue) {
13150 if (filterValue === void 0) {
13151 return true;
13152 }
13153 const filterDate = (0, import_date.getDate)(filterValue);
13154 const fieldDate = (0, import_date.getDate)(field.getValue({ item }));
13155 return filterDate.getTime() !== fieldDate.getTime();
13156 },
13157 selection: "single"
13158 }
13159 ];
13160 var getOperatorByName = (name) => OPERATORS.find((op) => op.name === name);
13161 var getAllOperatorNames = () => OPERATORS.map((op) => op.name);
13162 var isSingleSelectionOperator = (name) => OPERATORS.filter((op) => op.selection === "single").some(
13163 (op) => op.name === name
13164 );
13165 var isRegisteredOperator = (name) => OPERATORS.some((op) => op.name === name);
13166
13167 // packages/dataviews/build-module/components/dataviews-filters/filter.mjs
13168 var import_jsx_runtime65 = __toESM(require_jsx_runtime(), 1);
13169 var ENTER = "Enter";
13170 var SPACE = " ";
13171 var FilterText = ({
13172 activeElements,
13173 filterInView,
13174 filter
13175 }) => {
13176 if (activeElements === void 0 || activeElements.length === 0) {
13177 return filter.name;
13178 }
13179 const operator = getOperatorByName(filterInView?.operator);
13180 if (operator !== void 0) {
13181 return operator.filterText(filter, activeElements);
13182 }
13183 return (0, import_i18n30.sprintf)(
13184 /* translators: 1: Filter name e.g.: "Unknown status for Author". */
13185 (0, import_i18n30.__)("Unknown status for %1$s"),
13186 filter.name
13187 );
13188 };
13189 function OperatorSelector({
13190 filter,
13191 view,
13192 onChangeView
13193 }) {
13194 const operatorOptions = filter.operators?.map((operator) => ({
13195 value: operator,
13196 label: getOperatorByName(operator)?.label || operator
13197 }));
13198 const currentFilter = view.filters?.find(
13199 (_filter) => _filter.field === filter.field
13200 );
13201 const value = currentFilter?.operator || filter.operators[0];
13202 return operatorOptions.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)(
13203 Stack,
13204 {
13205 direction: "row",
13206 gap: "sm",
13207 justify: "flex-start",
13208 className: "dataviews-filters__summary-operators-container",
13209 align: "center",
13210 children: [
13211 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(import_components21.FlexItem, { className: "dataviews-filters__summary-operators-filter-name", children: filter.name }),
13212 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13213 import_components21.SelectControl,
13214 {
13215 className: "dataviews-filters__summary-operators-filter-select",
13216 label: (0, import_i18n30.__)("Conditions"),
13217 value,
13218 options: operatorOptions,
13219 onChange: (newValue) => {
13220 const newOperator = newValue;
13221 const currentOperator = currentFilter?.operator;
13222 const newFilters = currentFilter ? [
13223 ...(view.filters ?? []).map(
13224 (_filter) => {
13225 if (_filter.field === filter.field) {
13226 const currentOpSelectionModel = getOperatorByName(
13227 currentOperator
13228 )?.selection;
13229 const newOpSelectionModel = getOperatorByName(
13230 newOperator
13231 )?.selection;
13232 const shouldResetValue = currentOpSelectionModel !== newOpSelectionModel || [
13233 currentOpSelectionModel,
13234 newOpSelectionModel
13235 ].includes("custom");
13236 return {
13237 ..._filter,
13238 value: shouldResetValue ? void 0 : _filter.value,
13239 operator: newOperator
13240 };
13241 }
13242 return _filter;
13243 }
13244 )
13245 ] : [
13246 ...view.filters ?? [],
13247 {
13248 field: filter.field,
13249 operator: newOperator,
13250 value: void 0
13251 }
13252 ];
13253 onChangeView({
13254 ...view,
13255 page: 1,
13256 filters: newFilters
13257 });
13258 },
13259 size: "small",
13260 variant: "minimal",
13261 hideLabelFromVision: true
13262 }
13263 )
13264 ]
13265 }
13266 );
13267 }
13268 function Filter({
13269 addFilterRef,
13270 openedFilter,
13271 fields,
13272 ...commonProps
13273 }) {
13274 const toggleRef = (0, import_element29.useRef)(null);
13275 const { filter, view, onChangeView } = commonProps;
13276 const filterInView = view.filters?.find(
13277 (f2) => f2.field === filter.field
13278 );
13279 let activeElements = [];
13280 const field = (0, import_element29.useMemo)(() => {
13281 const currentField = fields.find((f2) => f2.id === filter.field);
13282 if (currentField) {
13283 return {
13284 ...currentField,
13285 // Configure getValue as if Item was a plain object.
13286 // See related input-widget.tsx
13287 getValue: ({ item }) => item[currentField.id]
13288 };
13289 }
13290 return currentField;
13291 }, [fields, filter.field]);
13292 const { elements } = useElements({
13293 elements: filter.elements,
13294 getElements: filter.getElements
13295 });
13296 if (elements.length > 0) {
13297 activeElements = elements.filter((element) => {
13298 if (filter.singleSelection) {
13299 return element.value === filterInView?.value;
13300 }
13301 return filterInView?.value?.includes(element.value);
13302 });
13303 } else if (Array.isArray(filterInView?.value)) {
13304 const label = filterInView.value.map((v2) => {
13305 const formattedValue = field?.getValueFormatted({
13306 item: { [field.id]: v2 },
13307 field
13308 });
13309 return formattedValue || String(v2);
13310 });
13311 activeElements = [
13312 {
13313 value: filterInView.value,
13314 // @ts-ignore
13315 label
13316 }
13317 ];
13318 } else if (typeof filterInView?.value === "object") {
13319 activeElements = [
13320 { value: filterInView.value, label: filterInView.value }
13321 ];
13322 } else if (filterInView?.value !== void 0) {
13323 const label = field !== void 0 ? field.getValueFormatted({
13324 item: { [field.id]: filterInView.value },
13325 field
13326 }) : String(filterInView.value);
13327 activeElements = [
13328 {
13329 value: filterInView.value,
13330 label
13331 }
13332 ];
13333 }
13334 const isPrimary = filter.isPrimary;
13335 const isLocked = filterInView?.isLocked;
13336 const hasValues = !isLocked && filterInView?.value !== void 0;
13337 const canResetOrRemove = !isLocked && (!isPrimary || hasValues);
13338 return /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13339 import_components21.Dropdown,
13340 {
13341 defaultOpen: openedFilter === filter.field,
13342 contentClassName: "dataviews-filters__summary-popover",
13343 popoverProps: { placement: "bottom-start", role: "dialog" },
13344 onClose: () => {
13345 toggleRef.current?.focus();
13346 },
13347 renderToggle: ({ isOpen, onToggle }) => /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)("div", { className: "dataviews-filters__summary-chip-container", children: [
13348 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13349 import_components21.Tooltip,
13350 {
13351 text: (0, import_i18n30.sprintf)(
13352 /* translators: 1: Filter name. */
13353 (0, import_i18n30.__)("Filter by: %1$s"),
13354 filter.name.toLowerCase()
13355 ),
13356 placement: "top",
13357 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13358 "div",
13359 {
13360 className: clsx_default(
13361 "dataviews-filters__summary-chip",
13362 {
13363 "has-reset": canResetOrRemove,
13364 "has-values": hasValues,
13365 "is-not-clickable": isLocked
13366 }
13367 ),
13368 role: "button",
13369 tabIndex: isLocked ? -1 : 0,
13370 onClick: () => {
13371 if (!isLocked) {
13372 onToggle();
13373 }
13374 },
13375 onKeyDown: (event) => {
13376 if (!isLocked && [ENTER, SPACE].includes(event.key)) {
13377 onToggle();
13378 event.preventDefault();
13379 }
13380 },
13381 "aria-disabled": isLocked,
13382 "aria-pressed": isOpen,
13383 "aria-expanded": isOpen,
13384 ref: toggleRef,
13385 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13386 FilterText,
13387 {
13388 activeElements,
13389 filterInView,
13390 filter
13391 }
13392 )
13393 }
13394 )
13395 }
13396 ),
13397 canResetOrRemove && /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13398 import_components21.Tooltip,
13399 {
13400 text: isPrimary ? (0, import_i18n30.__)("Reset") : (0, import_i18n30.__)("Remove"),
13401 placement: "top",
13402 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13403 "button",
13404 {
13405 className: clsx_default(
13406 "dataviews-filters__summary-chip-remove",
13407 { "has-values": hasValues }
13408 ),
13409 onClick: () => {
13410 onChangeView({
13411 ...view,
13412 page: 1,
13413 filters: view.filters?.filter(
13414 (_filter) => _filter.field !== filter.field
13415 )
13416 });
13417 if (!isPrimary) {
13418 addFilterRef.current?.focus();
13419 } else {
13420 toggleRef.current?.focus();
13421 }
13422 },
13423 children: /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(import_components21.Icon, { icon: close_small_default })
13424 }
13425 )
13426 }
13427 )
13428 ] }),
13429 renderContent: () => {
13430 return /* @__PURE__ */ (0, import_jsx_runtime65.jsxs)(Stack, { direction: "column", justify: "flex-start", children: [
13431 /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(OperatorSelector, { ...commonProps }),
13432 commonProps.filter.hasElements ? /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
13433 SearchWidget,
13434 {
13435 ...commonProps,
13436 filter: {
13437 ...commonProps.filter,
13438 elements
13439 }
13440 }
13441 ) : /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(InputWidget, { ...commonProps, fields })
13442 ] });
13443 }
13444 }
13445 );
13446 }
13447
13448 // packages/dataviews/build-module/components/dataviews-filters/add-filter.mjs
13449 var import_components22 = __toESM(require_components(), 1);
13450 var import_i18n31 = __toESM(require_i18n(), 1);
13451 var import_element30 = __toESM(require_element(), 1);
13452 var import_jsx_runtime66 = __toESM(require_jsx_runtime(), 1);
13453 var { Menu: Menu4 } = unlock(import_components22.privateApis);
13454 function AddFilterMenu({
13455 filters,
13456 view,
13457 onChangeView,
13458 setOpenedFilter,
13459 triggerProps
13460 }) {
13461 const inactiveFilters = filters.filter((filter) => !filter.isVisible);
13462 return /* @__PURE__ */ (0, import_jsx_runtime66.jsxs)(Menu4, { children: [
13463 /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(Menu4.TriggerButton, { ...triggerProps }),
13464 /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(Menu4.Popover, { children: inactiveFilters.map((filter) => {
13465 return /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
13466 Menu4.Item,
13467 {
13468 onClick: () => {
13469 setOpenedFilter(filter.field);
13470 onChangeView({
13471 ...view,
13472 page: 1,
13473 filters: [
13474 ...view.filters || [],
13475 {
13476 field: filter.field,
13477 value: void 0,
13478 operator: filter.operators[0]
13479 }
13480 ]
13481 });
13482 },
13483 children: /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(Menu4.ItemLabel, { children: filter.name })
13484 },
13485 filter.field
13486 );
13487 }) })
13488 ] });
13489 }
13490 function AddFilter({ filters, view, onChangeView, setOpenedFilter }, ref) {
13491 if (!filters.length || filters.every(({ isPrimary }) => isPrimary)) {
13492 return null;
13493 }
13494 const inactiveFilters = filters.filter((filter) => !filter.isVisible);
13495 return /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
13496 AddFilterMenu,
13497 {
13498 triggerProps: {
13499 render: /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
13500 import_components22.Button,
13501 {
13502 accessibleWhenDisabled: true,
13503 size: "compact",
13504 className: "dataviews-filters-button",
13505 variant: "tertiary",
13506 disabled: !inactiveFilters.length,
13507 ref
13508 }
13509 ),
13510 children: (0, import_i18n31.__)("Add filter")
13511 },
13512 ...{ filters, view, onChangeView, setOpenedFilter }
13513 }
13514 );
13515 }
13516 var add_filter_default = (0, import_element30.forwardRef)(AddFilter);
13517
13518 // packages/dataviews/build-module/components/dataviews-filters/reset-filters.mjs
13519 var import_components23 = __toESM(require_components(), 1);
13520 var import_i18n32 = __toESM(require_i18n(), 1);
13521 var import_jsx_runtime67 = __toESM(require_jsx_runtime(), 1);
13522 function ResetFilter({
13523 filters,
13524 view,
13525 onChangeView
13526 }) {
13527 const isPrimary = (field) => filters.some(
13528 (_filter) => _filter.field === field && _filter.isPrimary
13529 );
13530 const isDisabled = !view.search && !view.filters?.some(
13531 (_filter) => !_filter.isLocked && (_filter.value !== void 0 || !isPrimary(_filter.field))
13532 );
13533 return /* @__PURE__ */ (0, import_jsx_runtime67.jsx)(
13534 import_components23.Button,
13535 {
13536 disabled: isDisabled,
13537 accessibleWhenDisabled: true,
13538 size: "compact",
13539 variant: "tertiary",
13540 className: "dataviews-filters__reset-button",
13541 onClick: () => {
13542 onChangeView({
13543 ...view,
13544 page: 1,
13545 search: "",
13546 filters: view.filters?.filter((f2) => !!f2.isLocked) || []
13547 });
13548 },
13549 children: (0, import_i18n32.__)("Reset")
13550 }
13551 );
13552 }
13553
13554 // packages/dataviews/build-module/components/dataviews-filters/use-filters.mjs
13555 var import_element31 = __toESM(require_element(), 1);
13556 function useFilters(fields, view) {
13557 return (0, import_element31.useMemo)(() => {
13558 const filters = [];
13559 fields.forEach((field) => {
13560 if (field.filterBy === false || !field.hasElements && !field.Edit) {
13561 return;
13562 }
13563 const operators = field.filterBy.operators;
13564 const isPrimary = !!field.filterBy?.isPrimary;
13565 const isLocked = view.filters?.some(
13566 (f2) => f2.field === field.id && !!f2.isLocked
13567 ) ?? false;
13568 filters.push({
13569 field: field.id,
13570 name: field.label,
13571 elements: field.elements,
13572 getElements: field.getElements,
13573 hasElements: field.hasElements,
13574 singleSelection: operators.some(
13575 (op) => isSingleSelectionOperator(op)
13576 ),
13577 operators,
13578 isVisible: isLocked || isPrimary || !!view.filters?.some(
13579 (f2) => f2.field === field.id && isRegisteredOperator(f2.operator)
13580 ),
13581 isPrimary,
13582 isLocked
13583 });
13584 });
13585 filters.sort((a2, b2) => {
13586 if (a2.isLocked && !b2.isLocked) {
13587 return -1;
13588 }
13589 if (!a2.isLocked && b2.isLocked) {
13590 return 1;
13591 }
13592 if (a2.isPrimary && !b2.isPrimary) {
13593 return -1;
13594 }
13595 if (!a2.isPrimary && b2.isPrimary) {
13596 return 1;
13597 }
13598 return a2.name.localeCompare(b2.name);
13599 });
13600 return filters;
13601 }, [fields, view]);
13602 }
13603 var use_filters_default = useFilters;
13604
13605 // packages/dataviews/build-module/components/dataviews-filters/filters.mjs
13606 var import_jsx_runtime68 = __toESM(require_jsx_runtime(), 1);
13607 function Filters({ className }) {
13608 const { fields, view, onChangeView, openedFilter, setOpenedFilter } = (0, import_element32.useContext)(dataviews_context_default);
13609 const addFilterRef = (0, import_element32.useRef)(null);
13610 const filters = use_filters_default(fields, view);
13611 const addFilter = /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13612 add_filter_default,
13613 {
13614 filters,
13615 view,
13616 onChangeView,
13617 ref: addFilterRef,
13618 setOpenedFilter
13619 },
13620 "add-filter"
13621 );
13622 const visibleFilters = filters.filter((filter) => filter.isVisible);
13623 if (visibleFilters.length === 0) {
13624 return null;
13625 }
13626 const filterComponents = [
13627 ...visibleFilters.map((filter) => {
13628 return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13629 Filter,
13630 {
13631 filter,
13632 view,
13633 fields,
13634 onChangeView,
13635 addFilterRef,
13636 openedFilter
13637 },
13638 filter.field
13639 );
13640 }),
13641 addFilter
13642 ];
13643 filterComponents.push(
13644 /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13645 ResetFilter,
13646 {
13647 filters,
13648 view,
13649 onChangeView
13650 },
13651 "reset-filters"
13652 )
13653 );
13654 return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
13655 Stack,
13656 {
13657 direction: "row",
13658 justify: "flex-start",
13659 gap: "sm",
13660 style: { width: "fit-content" },
13661 wrap: "wrap",
13662 className,
13663 children: filterComponents
13664 }
13665 );
13666 }
13667 var filters_default = (0, import_element32.memo)(Filters);
13668
13669 // packages/dataviews/build-module/components/dataviews-filters/toggle.mjs
13670 var import_element33 = __toESM(require_element(), 1);
13671 var import_components24 = __toESM(require_components(), 1);
13672 var import_i18n33 = __toESM(require_i18n(), 1);
13673 var import_jsx_runtime69 = __toESM(require_jsx_runtime(), 1);
13674 function FiltersToggle() {
13675 const {
13676 filters,
13677 view,
13678 onChangeView,
13679 setOpenedFilter,
13680 isShowingFilter,
13681 setIsShowingFilter
13682 } = (0, import_element33.useContext)(dataviews_context_default);
13683 const buttonRef = (0, import_element33.useRef)(null);
13684 const onChangeViewWithFilterVisibility = (0, import_element33.useCallback)(
13685 (_view) => {
13686 onChangeView(_view);
13687 setIsShowingFilter(true);
13688 },
13689 [onChangeView, setIsShowingFilter]
13690 );
13691 if (filters.length === 0) {
13692 return null;
13693 }
13694 const hasVisibleFilters = filters.some((filter) => filter.isVisible);
13695 const addFilterButtonProps = {
13696 label: (0, import_i18n33.__)("Add filter"),
13697 "aria-expanded": false,
13698 isPressed: false
13699 };
13700 const toggleFiltersButtonProps = {
13701 label: (0, import_i18n33._x)("Filter", "verb"),
13702 "aria-expanded": isShowingFilter,
13703 isPressed: isShowingFilter,
13704 onClick: () => {
13705 if (!isShowingFilter) {
13706 setOpenedFilter(null);
13707 }
13708 setIsShowingFilter(!isShowingFilter);
13709 }
13710 };
13711 const hasPrimaryOrLockedFilters = filters.some(
13712 (filter) => filter.isPrimary || filter.isLocked
13713 );
13714 const buttonComponent = /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
13715 import_components24.Button,
13716 {
13717 ref: buttonRef,
13718 className: "dataviews-filters__visibility-toggle",
13719 size: "compact",
13720 icon: funnel_default,
13721 disabled: hasPrimaryOrLockedFilters,
13722 accessibleWhenDisabled: true,
13723 ...hasVisibleFilters ? toggleFiltersButtonProps : addFilterButtonProps
13724 }
13725 );
13726 return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)("div", { className: "dataviews-filters__container-visibility-toggle", children: !hasVisibleFilters ? /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
13727 AddFilterMenu,
13728 {
13729 filters,
13730 view,
13731 onChangeView: onChangeViewWithFilterVisibility,
13732 setOpenedFilter,
13733 triggerProps: { render: buttonComponent }
13734 }
13735 ) : /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
13736 FilterVisibilityToggle,
13737 {
13738 buttonRef,
13739 filtersCount: view.filters?.length,
13740 children: buttonComponent
13741 }
13742 ) });
13743 }
13744 function FilterVisibilityToggle({
13745 buttonRef,
13746 filtersCount,
13747 children
13748 }) {
13749 (0, import_element33.useEffect)(
13750 () => () => {
13751 buttonRef.current?.focus();
13752 },
13753 [buttonRef]
13754 );
13755 return /* @__PURE__ */ (0, import_jsx_runtime69.jsxs)(import_jsx_runtime69.Fragment, { children: [
13756 children,
13757 !!filtersCount && /* @__PURE__ */ (0, import_jsx_runtime69.jsx)("span", { className: "dataviews-filters-toggle__count", children: filtersCount })
13758 ] });
13759 }
13760 var toggle_default = FiltersToggle;
13761
13762 // packages/dataviews/build-module/components/dataviews-filters/filters-toggled.mjs
13763 var import_element34 = __toESM(require_element(), 1);
13764 var import_jsx_runtime70 = __toESM(require_jsx_runtime(), 1);
13765 function FiltersToggled(props) {
13766 const { isShowingFilter } = (0, import_element34.useContext)(dataviews_context_default);
13767 if (!isShowingFilter) {
13768 return null;
13769 }
13770 return /* @__PURE__ */ (0, import_jsx_runtime70.jsx)(filters_default, { ...props });
13771 }
13772 var filters_toggled_default = FiltersToggled;
13773
13774 // packages/dataviews/build-module/components/dataviews-layout/index.mjs
13775 var import_element35 = __toESM(require_element(), 1);
13776 var import_components25 = __toESM(require_components(), 1);
13777 var import_i18n34 = __toESM(require_i18n(), 1);
13778 var import_jsx_runtime71 = __toESM(require_jsx_runtime(), 1);
13779 function DataViewsLayout({ className }) {
13780 const {
13781 actions = [],
13782 data,
13783 fields,
13784 getItemId,
13785 getItemLevel,
13786 hasInitiallyLoaded,
13787 isLoading,
13788 view,
13789 onChangeView,
13790 selection,
13791 onChangeSelection,
13792 setOpenedFilter,
13793 onClickItem,
13794 isItemClickable: isItemClickable2,
13795 renderItemLink,
13796 defaultLayouts: defaultLayouts2,
13797 containerRef,
13798 empty = /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("p", { children: (0, import_i18n34.__)("No results") })
13799 } = (0, import_element35.useContext)(dataviews_context_default);
13800 const isDelayedInitialLoading = useDelayedLoading(!hasInitiallyLoaded, {
13801 delay: 200
13802 });
13803 if (!hasInitiallyLoaded) {
13804 if (!isDelayedInitialLoading) {
13805 return null;
13806 }
13807 return /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("div", { className: "dataviews-loading", children: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(import_components25.Spinner, {}) }) });
13808 }
13809 const ViewComponent = VIEW_LAYOUTS.find(
13810 (v2) => v2.type === view.type && defaultLayouts2[v2.type]
13811 )?.component;
13812 return /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("div", { className: "dataviews-layout__container", ref: containerRef, children: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(
13813 ViewComponent,
13814 {
13815 className,
13816 actions,
13817 data,
13818 fields,
13819 getItemId,
13820 getItemLevel,
13821 isLoading,
13822 onChangeView,
13823 onChangeSelection,
13824 selection,
13825 setOpenedFilter,
13826 onClickItem,
13827 renderItemLink,
13828 isItemClickable: isItemClickable2,
13829 view,
13830 empty
13831 }
13832 ) });
13833 }
13834
13835 // packages/dataviews/build-module/components/dataviews-search/index.mjs
13836 var import_i18n35 = __toESM(require_i18n(), 1);
13837 var import_element36 = __toESM(require_element(), 1);
13838 var import_components26 = __toESM(require_components(), 1);
13839 var import_compose9 = __toESM(require_compose(), 1);
13840 var import_jsx_runtime72 = __toESM(require_jsx_runtime(), 1);
13841 var DataViewsSearch = (0, import_element36.memo)(function Search({ label }) {
13842 const { view, onChangeView } = (0, import_element36.useContext)(dataviews_context_default);
13843 const [search, setSearch, debouncedSearch] = (0, import_compose9.useDebouncedInput)(
13844 view.search
13845 );
13846 (0, import_element36.useEffect)(() => {
13847 if (view.search !== debouncedSearch) {
13848 setSearch(view.search ?? "");
13849 }
13850 }, [view.search, setSearch]);
13851 const onChangeViewRef = (0, import_element36.useRef)(onChangeView);
13852 const viewRef = (0, import_element36.useRef)(view);
13853 (0, import_element36.useEffect)(() => {
13854 onChangeViewRef.current = onChangeView;
13855 viewRef.current = view;
13856 }, [onChangeView, view]);
13857 (0, import_element36.useEffect)(() => {
13858 if (debouncedSearch !== viewRef.current?.search) {
13859 onChangeViewRef.current({
13860 ...viewRef.current,
13861 page: view.page ? 1 : void 0,
13862 startPosition: view.startPosition ? 1 : void 0,
13863 search: debouncedSearch
13864 });
13865 }
13866 }, [debouncedSearch]);
13867 const searchLabel = label || (0, import_i18n35.__)("Search");
13868 return /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
13869 import_components26.SearchControl,
13870 {
13871 className: "dataviews-search",
13872 onChange: setSearch,
13873 value: search,
13874 label: searchLabel,
13875 placeholder: searchLabel,
13876 size: "compact"
13877 }
13878 );
13879 });
13880 var dataviews_search_default = DataViewsSearch;
13881
13882 // packages/dataviews/build-module/components/dataviews-view-config/index.mjs
13883 var import_components27 = __toESM(require_components(), 1);
13884 var import_i18n36 = __toESM(require_i18n(), 1);
13885 var import_element37 = __toESM(require_element(), 1);
13886 var import_warning = __toESM(require_warning(), 1);
13887 var import_compose10 = __toESM(require_compose(), 1);
13888 var import_jsx_runtime73 = __toESM(require_jsx_runtime(), 1);
13889 var { Menu: Menu5 } = unlock(import_components27.privateApis);
13890 var DATAVIEWS_CONFIG_POPOVER_PROPS = {
13891 className: "dataviews-config__popover",
13892 placement: "bottom-end",
13893 offset: 9
13894 };
13895 function ViewTypeMenu() {
13896 const { view, onChangeView, defaultLayouts: defaultLayouts2 } = (0, import_element37.useContext)(dataviews_context_default);
13897 const availableLayouts = Object.keys(defaultLayouts2);
13898 if (availableLayouts.length <= 1) {
13899 return null;
13900 }
13901 const activeView = VIEW_LAYOUTS.find((v2) => view.type === v2.type);
13902 return /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(Menu5, { children: [
13903 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
13904 Menu5.TriggerButton,
13905 {
13906 render: /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
13907 import_components27.Button,
13908 {
13909 size: "compact",
13910 icon: activeView?.icon,
13911 label: (0, import_i18n36.__)("Layout")
13912 }
13913 )
13914 }
13915 ),
13916 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(Menu5.Popover, { children: availableLayouts.map((layout) => {
13917 const config = VIEW_LAYOUTS.find(
13918 (v2) => v2.type === layout
13919 );
13920 if (!config) {
13921 return null;
13922 }
13923 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
13924 Menu5.RadioItem,
13925 {
13926 value: layout,
13927 name: "view-actions-available-view",
13928 checked: layout === view.type,
13929 hideOnClick: true,
13930 onChange: (e2) => {
13931 switch (e2.target.value) {
13932 case "list":
13933 case "grid":
13934 case "table":
13935 case "pickerGrid":
13936 case "pickerTable":
13937 case "activity":
13938 const viewWithoutLayout = { ...view };
13939 if ("layout" in viewWithoutLayout) {
13940 delete viewWithoutLayout.layout;
13941 }
13942 return onChangeView({
13943 ...viewWithoutLayout,
13944 type: e2.target.value,
13945 ...defaultLayouts2[e2.target.value]
13946 });
13947 }
13948 (0, import_warning.default)("Invalid dataview");
13949 },
13950 children: /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(Menu5.ItemLabel, { children: config.label })
13951 },
13952 layout
13953 );
13954 }) })
13955 ] });
13956 }
13957 function SortFieldControl() {
13958 const { view, fields, onChangeView } = (0, import_element37.useContext)(dataviews_context_default);
13959 const orderOptions = (0, import_element37.useMemo)(() => {
13960 const sortableFields = fields.filter(
13961 (field) => field.enableSorting !== false
13962 );
13963 return sortableFields.map((field) => {
13964 return {
13965 label: field.label,
13966 value: field.id
13967 };
13968 });
13969 }, [fields]);
13970 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
13971 import_components27.SelectControl,
13972 {
13973 __next40pxDefaultSize: true,
13974 label: (0, import_i18n36.__)("Sort by"),
13975 value: view.sort?.field,
13976 options: orderOptions,
13977 onChange: (value) => {
13978 onChangeView({
13979 ...view,
13980 sort: {
13981 direction: view?.sort?.direction || "desc",
13982 field: value
13983 },
13984 showLevels: false
13985 });
13986 }
13987 }
13988 );
13989 }
13990 function SortDirectionControl() {
13991 const { view, fields, onChangeView } = (0, import_element37.useContext)(dataviews_context_default);
13992 const sortableFields = fields.filter(
13993 (field) => field.enableSorting !== false
13994 );
13995 if (sortableFields.length === 0) {
13996 return null;
13997 }
13998 let value = view.sort?.direction;
13999 if (!value && view.sort?.field) {
14000 value = "desc";
14001 }
14002 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14003 import_components27.__experimentalToggleGroupControl,
14004 {
14005 className: "dataviews-view-config__sort-direction",
14006 __next40pxDefaultSize: true,
14007 isBlock: true,
14008 label: (0, import_i18n36.__)("Order"),
14009 value,
14010 onChange: (newDirection) => {
14011 if (newDirection === "asc" || newDirection === "desc") {
14012 onChangeView({
14013 ...view,
14014 sort: {
14015 direction: newDirection,
14016 field: view.sort?.field || // If there is no field assigned as the sorting field assign the first sortable field.
14017 fields.find(
14018 (field) => field.enableSorting !== false
14019 )?.id || ""
14020 },
14021 showLevels: false
14022 });
14023 return;
14024 }
14025 (0, import_warning.default)("Invalid direction");
14026 },
14027 children: SORTING_DIRECTIONS.map((direction) => {
14028 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14029 import_components27.__experimentalToggleGroupControlOptionIcon,
14030 {
14031 value: direction,
14032 icon: sortIcons[direction],
14033 label: sortLabels[direction]
14034 },
14035 direction
14036 );
14037 })
14038 }
14039 );
14040 }
14041 function ItemsPerPageControl() {
14042 const { view, config, onChangeView } = (0, import_element37.useContext)(dataviews_context_default);
14043 const { infiniteScrollEnabled } = view;
14044 if (!config || !config.perPageSizes || config.perPageSizes.length < 2 || config.perPageSizes.length > 6 || infiniteScrollEnabled) {
14045 return null;
14046 }
14047 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14048 import_components27.__experimentalToggleGroupControl,
14049 {
14050 __next40pxDefaultSize: true,
14051 isBlock: true,
14052 label: (0, import_i18n36.__)("Items per page"),
14053 value: view.perPage || 10,
14054 disabled: !view?.sort?.field,
14055 onChange: (newItemsPerPage) => {
14056 const newItemsPerPageNumber = typeof newItemsPerPage === "number" || newItemsPerPage === void 0 ? newItemsPerPage : parseInt(newItemsPerPage, 10);
14057 onChangeView({
14058 ...view,
14059 perPage: newItemsPerPageNumber,
14060 page: 1
14061 });
14062 },
14063 children: config.perPageSizes.map((value) => {
14064 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14065 import_components27.__experimentalToggleGroupControlOption,
14066 {
14067 value,
14068 label: value.toString()
14069 },
14070 value
14071 );
14072 })
14073 }
14074 );
14075 }
14076 function ResetViewButton() {
14077 const { onReset } = (0, import_element37.useContext)(dataviews_context_default);
14078 if (onReset === void 0) {
14079 return null;
14080 }
14081 const isDisabled = onReset === false;
14082 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14083 import_components27.Button,
14084 {
14085 variant: "tertiary",
14086 size: "compact",
14087 disabled: isDisabled,
14088 accessibleWhenDisabled: true,
14089 className: "dataviews-view-config__reset-button",
14090 onClick: () => {
14091 if (typeof onReset === "function") {
14092 onReset();
14093 }
14094 },
14095 children: (0, import_i18n36.__)("Reset view")
14096 }
14097 );
14098 }
14099 function DataviewsViewConfigDropdown() {
14100 const { view, onReset } = (0, import_element37.useContext)(dataviews_context_default);
14101 const popoverId = (0, import_compose10.useInstanceId)(
14102 _DataViewsViewConfig,
14103 "dataviews-view-config-dropdown"
14104 );
14105 const activeLayout = VIEW_LAYOUTS.find(
14106 (layout) => layout.type === view.type
14107 );
14108 const isModified = typeof onReset === "function";
14109 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14110 import_components27.Dropdown,
14111 {
14112 expandOnMobile: true,
14113 popoverProps: {
14114 ...DATAVIEWS_CONFIG_POPOVER_PROPS,
14115 id: popoverId
14116 },
14117 renderToggle: ({ onToggle, isOpen }) => {
14118 return /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)("div", { className: "dataviews-view-config__toggle-wrapper", children: [
14119 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14120 import_components27.Button,
14121 {
14122 size: "compact",
14123 icon: cog_default,
14124 label: (0, import_i18n36._x)(
14125 "View options",
14126 "View is used as a noun"
14127 ),
14128 onClick: onToggle,
14129 "aria-expanded": isOpen ? "true" : "false",
14130 "aria-controls": popoverId
14131 }
14132 ),
14133 isModified && /* @__PURE__ */ (0, import_jsx_runtime73.jsx)("span", { className: "dataviews-view-config__modified-indicator" })
14134 ] });
14135 },
14136 renderContent: () => /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14137 import_components27.__experimentalDropdownContentWrapper,
14138 {
14139 paddingSize: "medium",
14140 className: "dataviews-config__popover-content-wrapper",
14141 children: /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
14142 Stack,
14143 {
14144 direction: "column",
14145 className: "dataviews-view-config",
14146 gap: "xl",
14147 children: [
14148 /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
14149 Stack,
14150 {
14151 direction: "row",
14152 justify: "space-between",
14153 align: "center",
14154 className: "dataviews-view-config__header",
14155 children: [
14156 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
14157 import_components27.__experimentalHeading,
14158 {
14159 level: 2,
14160 className: "dataviews-settings-section__title",
14161 children: (0, import_i18n36.__)("Appearance")
14162 }
14163 ),
14164 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(ResetViewButton, {})
14165 ]
14166 }
14167 ),
14168 /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(Stack, { direction: "column", gap: "lg", children: [
14169 /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(
14170 Stack,
14171 {
14172 direction: "row",
14173 gap: "sm",
14174 className: "dataviews-view-config__sort-controls",
14175 children: [
14176 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(SortFieldControl, {}),
14177 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(SortDirectionControl, {})
14178 ]
14179 }
14180 ),
14181 !!activeLayout?.viewConfigOptions && /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(activeLayout.viewConfigOptions, {}),
14182 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(ItemsPerPageControl, {}),
14183 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(PropertiesSection, {})
14184 ] })
14185 ]
14186 }
14187 )
14188 }
14189 )
14190 }
14191 );
14192 }
14193 function _DataViewsViewConfig() {
14194 return /* @__PURE__ */ (0, import_jsx_runtime73.jsxs)(import_jsx_runtime73.Fragment, { children: [
14195 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(ViewTypeMenu, {}),
14196 /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(DataviewsViewConfigDropdown, {})
14197 ] });
14198 }
14199 var DataViewsViewConfig = (0, import_element37.memo)(_DataViewsViewConfig);
14200 var dataviews_view_config_default = DataViewsViewConfig;
14201
14202 // packages/dataviews/build-module/components/dataform-controls/checkbox.mjs
14203 var import_components28 = __toESM(require_components(), 1);
14204 var import_element38 = __toESM(require_element(), 1);
14205
14206 // packages/dataviews/build-module/components/dataform-controls/utils/get-custom-validity.mjs
14207 function getCustomValidity(isValid2, validity) {
14208 let customValidity;
14209 if (isValid2?.required && validity?.required) {
14210 customValidity = validity?.required?.message ? validity.required : void 0;
14211 } else if (isValid2?.pattern && validity?.pattern) {
14212 customValidity = validity.pattern;
14213 } else if (isValid2?.min && validity?.min) {
14214 customValidity = validity.min;
14215 } else if (isValid2?.max && validity?.max) {
14216 customValidity = validity.max;
14217 } else if (isValid2?.minLength && validity?.minLength) {
14218 customValidity = validity.minLength;
14219 } else if (isValid2?.maxLength && validity?.maxLength) {
14220 customValidity = validity.maxLength;
14221 } else if (isValid2?.elements && validity?.elements) {
14222 customValidity = validity.elements;
14223 } else if (validity?.custom) {
14224 customValidity = validity.custom;
14225 }
14226 return customValidity;
14227 }
14228
14229 // packages/dataviews/build-module/components/dataform-controls/checkbox.mjs
14230 var import_jsx_runtime74 = __toESM(require_jsx_runtime(), 1);
14231 var { ValidatedCheckboxControl } = unlock(import_components28.privateApis);
14232 function Checkbox({
14233 field,
14234 onChange,
14235 data,
14236 hideLabelFromVision,
14237 markWhenOptional,
14238 validity
14239 }) {
14240 const { getValue, setValue, label, description, isValid: isValid2 } = field;
14241 const disabled = field.isDisabled({ item: data, field });
14242 const onChangeControl = (0, import_element38.useCallback)(() => {
14243 onChange(
14244 setValue({ item: data, value: !getValue({ item: data }) })
14245 );
14246 }, [data, getValue, onChange, setValue]);
14247 return /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(
14248 ValidatedCheckboxControl,
14249 {
14250 required: !!field.isValid?.required,
14251 markWhenOptional,
14252 customValidity: getCustomValidity(isValid2, validity),
14253 hidden: hideLabelFromVision,
14254 label,
14255 help: description,
14256 checked: getValue({ item: data }),
14257 onChange: onChangeControl,
14258 disabled
14259 }
14260 );
14261 }
14262
14263 // packages/dataviews/build-module/components/dataform-controls/combobox.mjs
14264 var import_components29 = __toESM(require_components(), 1);
14265 var import_element39 = __toESM(require_element(), 1);
14266 var import_jsx_runtime75 = __toESM(require_jsx_runtime(), 1);
14267 var { ValidatedComboboxControl } = unlock(import_components29.privateApis);
14268 function Combobox3({
14269 data,
14270 field,
14271 onChange,
14272 hideLabelFromVision,
14273 validity
14274 }) {
14275 const { label, description, placeholder, getValue, setValue, isValid: isValid2 } = field;
14276 const value = getValue({ item: data }) ?? "";
14277 const onChangeControl = (0, import_element39.useCallback)(
14278 (newValue) => onChange(setValue({ item: data, value: newValue ?? "" })),
14279 [data, onChange, setValue]
14280 );
14281 const { elements, isLoading } = useElements({
14282 elements: field.elements,
14283 getElements: field.getElements
14284 });
14285 if (isLoading) {
14286 return /* @__PURE__ */ (0, import_jsx_runtime75.jsx)(import_components29.Spinner, {});
14287 }
14288 return /* @__PURE__ */ (0, import_jsx_runtime75.jsx)(
14289 ValidatedComboboxControl,
14290 {
14291 required: !!field.isValid?.required,
14292 customValidity: getCustomValidity(isValid2, validity),
14293 label,
14294 value,
14295 help: description,
14296 placeholder,
14297 options: elements,
14298 onChange: onChangeControl,
14299 hideLabelFromVision,
14300 allowReset: true,
14301 expandOnFocus: true
14302 }
14303 );
14304 }
14305
14306 // packages/dataviews/build-module/components/dataform-controls/datetime.mjs
14307 var import_components31 = __toESM(require_components(), 1);
14308 var import_element42 = __toESM(require_element(), 1);
14309 var import_i18n38 = __toESM(require_i18n(), 1);
14310 var import_date3 = __toESM(require_date(), 1);
14311
14312 // packages/dataviews/build-module/components/dataform-controls/utils/relative-date-control.mjs
14313 var import_components30 = __toESM(require_components(), 1);
14314 var import_element40 = __toESM(require_element(), 1);
14315 var import_i18n37 = __toESM(require_i18n(), 1);
14316 var import_jsx_runtime76 = __toESM(require_jsx_runtime(), 1);
14317 var TIME_UNITS_OPTIONS = {
14318 [OPERATOR_IN_THE_PAST]: [
14319 { value: "days", label: (0, import_i18n37.__)("Days") },
14320 { value: "weeks", label: (0, import_i18n37.__)("Weeks") },
14321 { value: "months", label: (0, import_i18n37.__)("Months") },
14322 { value: "years", label: (0, import_i18n37.__)("Years") }
14323 ],
14324 [OPERATOR_OVER]: [
14325 { value: "days", label: (0, import_i18n37.__)("Days ago") },
14326 { value: "weeks", label: (0, import_i18n37.__)("Weeks ago") },
14327 { value: "months", label: (0, import_i18n37.__)("Months ago") },
14328 { value: "years", label: (0, import_i18n37.__)("Years ago") }
14329 ]
14330 };
14331 function RelativeDateControl({
14332 className,
14333 data,
14334 field,
14335 onChange,
14336 hideLabelFromVision,
14337 operator
14338 }) {
14339 const options = TIME_UNITS_OPTIONS[operator === OPERATOR_IN_THE_PAST ? "inThePast" : "over"];
14340 const { id, label, description, getValue, setValue } = field;
14341 const disabled = field.isDisabled({ item: data, field });
14342 const fieldValue = getValue({ item: data });
14343 const { value: relValue = "", unit = options[0].value } = fieldValue && typeof fieldValue === "object" ? fieldValue : {};
14344 const onChangeValue = (0, import_element40.useCallback)(
14345 (newValue) => onChange(
14346 setValue({
14347 item: data,
14348 value: { value: Number(newValue), unit }
14349 })
14350 ),
14351 [onChange, setValue, data, unit]
14352 );
14353 const onChangeUnit = (0, import_element40.useCallback)(
14354 (newUnit) => onChange(
14355 setValue({
14356 item: data,
14357 value: { value: relValue, unit: newUnit }
14358 })
14359 ),
14360 [onChange, setValue, data, relValue]
14361 );
14362 return /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14363 import_components30.BaseControl,
14364 {
14365 id,
14366 className: clsx_default(className, "dataviews-controls__relative-date"),
14367 label,
14368 hideLabelFromVision,
14369 help: description,
14370 children: /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)(Stack, { direction: "row", gap: "sm", children: [
14371 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14372 import_components30.__experimentalNumberControl,
14373 {
14374 __next40pxDefaultSize: true,
14375 className: "dataviews-controls__relative-date-number",
14376 spinControls: "none",
14377 min: 1,
14378 step: 1,
14379 value: relValue,
14380 onChange: onChangeValue,
14381 disabled
14382 }
14383 ),
14384 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14385 import_components30.SelectControl,
14386 {
14387 className: "dataviews-controls__relative-date-unit",
14388 __next40pxDefaultSize: true,
14389 label: (0, import_i18n37.__)("Unit"),
14390 value: unit,
14391 options,
14392 onChange: onChangeUnit,
14393 hideLabelFromVision: true,
14394 disabled
14395 }
14396 )
14397 ] })
14398 }
14399 );
14400 }
14401
14402 // packages/dataviews/build-module/components/dataform-controls/utils/use-disabled-date-matchers.mjs
14403 var import_element41 = __toESM(require_element(), 1);
14404 function useDisabledDateMatchers(isValid2, parseDateFn) {
14405 const minConstraint = typeof isValid2.min?.constraint === "string" ? isValid2.min.constraint : void 0;
14406 const maxConstraint = typeof isValid2.max?.constraint === "string" ? isValid2.max.constraint : void 0;
14407 const disabledMatchers = (0, import_element41.useMemo)(() => {
14408 const matchers = [];
14409 if (minConstraint) {
14410 const minDate = parseDateFn(minConstraint);
14411 if (minDate) {
14412 matchers.push({ before: minDate });
14413 }
14414 }
14415 if (maxConstraint) {
14416 const maxDate = parseDateFn(maxConstraint);
14417 if (maxDate) {
14418 matchers.push({ after: maxDate });
14419 }
14420 }
14421 return matchers.length > 0 ? matchers : void 0;
14422 }, [minConstraint, maxConstraint, parseDateFn]);
14423 return { minConstraint, maxConstraint, disabledMatchers };
14424 }
14425
14426 // packages/dataviews/build-module/field-types/utils/parse-date-time.mjs
14427 var import_date2 = __toESM(require_date(), 1);
14428 function parseDateTime(dateTimeString) {
14429 if (!dateTimeString) {
14430 return null;
14431 }
14432 const parsed = (0, import_date2.getDate)(dateTimeString);
14433 return parsed && isValid(parsed) ? parsed : null;
14434 }
14435
14436 // packages/dataviews/build-module/components/dataform-controls/datetime.mjs
14437 var import_jsx_runtime77 = __toESM(require_jsx_runtime(), 1);
14438 var { DateCalendar, ValidatedInputControl } = unlock(import_components31.privateApis);
14439 var formatDateTime = (value) => {
14440 if (!value) {
14441 return "";
14442 }
14443 return (0, import_date3.dateI18n)("Y-m-d\\TH:i", (0, import_date3.getDate)(value));
14444 };
14445 function CalendarDateTimeControl({
14446 data,
14447 field,
14448 onChange,
14449 hideLabelFromVision,
14450 markWhenOptional,
14451 validity,
14452 config
14453 }) {
14454 const { compact } = config || {};
14455 const { id, label, description, setValue, getValue, isValid: isValid2 } = field;
14456 const disabled = field.isDisabled({ item: data, field });
14457 const fieldValue = getValue({ item: data });
14458 const value = typeof fieldValue === "string" ? fieldValue : void 0;
14459 const [calendarMonth, setCalendarMonth] = (0, import_element42.useState)(() => {
14460 const parsedDate = parseDateTime(value);
14461 return parsedDate || /* @__PURE__ */ new Date();
14462 });
14463 const inputControlRef = (0, import_element42.useRef)(null);
14464 const validationTimeoutRef = (0, import_element42.useRef)(void 0);
14465 const previousFocusRef = (0, import_element42.useRef)(null);
14466 const { minConstraint, maxConstraint, disabledMatchers } = useDisabledDateMatchers(isValid2, parseDateTime);
14467 const onChangeCallback = (0, import_element42.useCallback)(
14468 (newValue) => onChange(setValue({ item: data, value: newValue })),
14469 [data, onChange, setValue]
14470 );
14471 (0, import_element42.useEffect)(() => {
14472 return () => {
14473 if (validationTimeoutRef.current) {
14474 clearTimeout(validationTimeoutRef.current);
14475 }
14476 };
14477 }, []);
14478 const onSelectDate = (0, import_element42.useCallback)(
14479 (newDate) => {
14480 let dateTimeValue;
14481 if (newDate) {
14482 const wpDate = (0, import_date3.dateI18n)("Y-m-d", newDate);
14483 let wpTime;
14484 if (value) {
14485 wpTime = (0, import_date3.dateI18n)("H:i", (0, import_date3.getDate)(value));
14486 } else {
14487 wpTime = (0, import_date3.dateI18n)("H:i", newDate);
14488 }
14489 const finalDateTime = (0, import_date3.getDate)(`${wpDate}T${wpTime}`);
14490 dateTimeValue = finalDateTime.toISOString();
14491 onChangeCallback(dateTimeValue);
14492 if (validationTimeoutRef.current) {
14493 clearTimeout(validationTimeoutRef.current);
14494 }
14495 } else {
14496 onChangeCallback(void 0);
14497 }
14498 previousFocusRef.current = inputControlRef.current && inputControlRef.current.ownerDocument.activeElement;
14499 validationTimeoutRef.current = setTimeout(() => {
14500 if (inputControlRef.current) {
14501 inputControlRef.current.focus();
14502 inputControlRef.current.blur();
14503 onChangeCallback(dateTimeValue);
14504 if (previousFocusRef.current && previousFocusRef.current instanceof HTMLElement) {
14505 previousFocusRef.current.focus();
14506 }
14507 }
14508 }, 0);
14509 },
14510 [onChangeCallback, value]
14511 );
14512 const handleManualDateTimeChange = (0, import_element42.useCallback)(
14513 (newValue) => {
14514 if (newValue) {
14515 const dateTime = (0, import_date3.getDate)(newValue);
14516 onChangeCallback(dateTime.toISOString());
14517 const parsedDate = parseDateTime(dateTime.toISOString());
14518 if (parsedDate) {
14519 setCalendarMonth(parsedDate);
14520 }
14521 } else {
14522 onChangeCallback(void 0);
14523 }
14524 },
14525 [onChangeCallback]
14526 );
14527 const { format: fieldFormat } = field;
14528 const weekStartsOn = fieldFormat.weekStartsOn ?? (0, import_date3.getSettings)().l10n.startOfWeek;
14529 const {
14530 timezone: { string: timezoneString }
14531 } = (0, import_date3.getSettings)();
14532 let displayLabel = label;
14533 if (isValid2?.required && !markWhenOptional && !hideLabelFromVision) {
14534 displayLabel = `${label} (${(0, import_i18n38.__)("Required")})`;
14535 } else if (!isValid2?.required && markWhenOptional && !hideLabelFromVision) {
14536 displayLabel = `${label} (${(0, import_i18n38.__)("Optional")})`;
14537 }
14538 return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14539 import_components31.BaseControl,
14540 {
14541 id,
14542 label: displayLabel,
14543 help: description,
14544 hideLabelFromVision,
14545 children: /* @__PURE__ */ (0, import_jsx_runtime77.jsxs)(Stack, { direction: "column", gap: "lg", children: [
14546 /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14547 ValidatedInputControl,
14548 {
14549 ref: inputControlRef,
14550 __next40pxDefaultSize: true,
14551 required: !!isValid2?.required,
14552 customValidity: getCustomValidity(isValid2, validity),
14553 type: "datetime-local",
14554 label: (0, import_i18n38.__)("Date time"),
14555 hideLabelFromVision: true,
14556 value: formatDateTime(value),
14557 onChange: handleManualDateTimeChange,
14558 disabled,
14559 min: minConstraint ? formatDateTime(minConstraint) : void 0,
14560 max: maxConstraint ? formatDateTime(maxConstraint) : void 0
14561 }
14562 ),
14563 !compact && /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14564 DateCalendar,
14565 {
14566 style: { width: "100%" },
14567 selected: value ? parseDateTime(value) || void 0 : void 0,
14568 onSelect: onSelectDate,
14569 month: calendarMonth,
14570 onMonthChange: setCalendarMonth,
14571 timeZone: timezoneString || void 0,
14572 weekStartsOn,
14573 disabled: disabled || disabledMatchers
14574 }
14575 )
14576 ] })
14577 }
14578 );
14579 }
14580 function DateTime({
14581 data,
14582 field,
14583 onChange,
14584 hideLabelFromVision,
14585 markWhenOptional,
14586 operator,
14587 validity,
14588 config
14589 }) {
14590 if (operator === OPERATOR_IN_THE_PAST || operator === OPERATOR_OVER) {
14591 return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14592 RelativeDateControl,
14593 {
14594 className: "dataviews-controls__datetime",
14595 data,
14596 field,
14597 onChange,
14598 hideLabelFromVision,
14599 operator
14600 }
14601 );
14602 }
14603 return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14604 CalendarDateTimeControl,
14605 {
14606 data,
14607 field,
14608 onChange,
14609 hideLabelFromVision,
14610 markWhenOptional,
14611 validity,
14612 config
14613 }
14614 );
14615 }
14616
14617 // packages/dataviews/build-module/components/dataform-controls/date.mjs
14618 var import_components32 = __toESM(require_components(), 1);
14619 var import_element43 = __toESM(require_element(), 1);
14620 var import_i18n39 = __toESM(require_i18n(), 1);
14621 var import_date4 = __toESM(require_date(), 1);
14622 var import_jsx_runtime78 = __toESM(require_jsx_runtime(), 1);
14623 var { DateCalendar: DateCalendar2, DateRangeCalendar } = unlock(import_components32.privateApis);
14624 var DATE_PRESETS = [
14625 {
14626 id: "today",
14627 label: (0, import_i18n39.__)("Today"),
14628 getValue: () => (0, import_date4.getDate)(null)
14629 },
14630 {
14631 id: "yesterday",
14632 label: (0, import_i18n39.__)("Yesterday"),
14633 getValue: () => {
14634 const today = (0, import_date4.getDate)(null);
14635 return subDays(today, 1);
14636 }
14637 },
14638 {
14639 id: "past-week",
14640 label: (0, import_i18n39.__)("Past week"),
14641 getValue: () => {
14642 const today = (0, import_date4.getDate)(null);
14643 return subDays(today, 7);
14644 }
14645 },
14646 {
14647 id: "past-month",
14648 label: (0, import_i18n39.__)("Past month"),
14649 getValue: () => {
14650 const today = (0, import_date4.getDate)(null);
14651 return subMonths(today, 1);
14652 }
14653 }
14654 ];
14655 var DATE_RANGE_PRESETS = [
14656 {
14657 id: "last-7-days",
14658 label: (0, import_i18n39.__)("Last 7 days"),
14659 getValue: () => {
14660 const today = (0, import_date4.getDate)(null);
14661 return [subDays(today, 7), today];
14662 }
14663 },
14664 {
14665 id: "last-30-days",
14666 label: (0, import_i18n39.__)("Last 30 days"),
14667 getValue: () => {
14668 const today = (0, import_date4.getDate)(null);
14669 return [subDays(today, 30), today];
14670 }
14671 },
14672 {
14673 id: "month-to-date",
14674 label: (0, import_i18n39.__)("Month to date"),
14675 getValue: () => {
14676 const today = (0, import_date4.getDate)(null);
14677 return [startOfMonth(today), today];
14678 }
14679 },
14680 {
14681 id: "last-year",
14682 label: (0, import_i18n39.__)("Last year"),
14683 getValue: () => {
14684 const today = (0, import_date4.getDate)(null);
14685 return [subYears(today, 1), today];
14686 }
14687 },
14688 {
14689 id: "year-to-date",
14690 label: (0, import_i18n39.__)("Year to date"),
14691 getValue: () => {
14692 const today = (0, import_date4.getDate)(null);
14693 return [startOfYear(today), today];
14694 }
14695 }
14696 ];
14697 var parseDate = (dateString) => {
14698 if (!dateString) {
14699 return null;
14700 }
14701 const parsed = (0, import_date4.getDate)(dateString);
14702 return parsed && isValid(parsed) ? parsed : null;
14703 };
14704 var formatDate = (date) => {
14705 if (!date) {
14706 return "";
14707 }
14708 return typeof date === "string" ? date : format(date, "yyyy-MM-dd");
14709 };
14710 function ValidatedDateControl({
14711 field,
14712 validity,
14713 inputRefs,
14714 isTouched,
14715 setIsTouched,
14716 children
14717 }) {
14718 const { isValid: isValid2 } = field;
14719 const [customValidity, setCustomValidity] = (0, import_element43.useState)(void 0);
14720 const validateRefs = (0, import_element43.useCallback)(() => {
14721 const refs = Array.isArray(inputRefs) ? inputRefs : [inputRefs];
14722 for (const ref of refs) {
14723 const input = ref.current;
14724 if (input && !input.validity.valid) {
14725 setCustomValidity({
14726 type: "invalid",
14727 message: input.validationMessage
14728 });
14729 return;
14730 }
14731 }
14732 setCustomValidity(void 0);
14733 }, [inputRefs]);
14734 (0, import_element43.useEffect)(() => {
14735 const refs = Array.isArray(inputRefs) ? inputRefs : [inputRefs];
14736 const result = validity ? getCustomValidity(isValid2, validity) : void 0;
14737 for (const ref of refs) {
14738 const input = ref.current;
14739 if (input) {
14740 input.setCustomValidity(
14741 result?.type === "invalid" && result.message ? result.message : ""
14742 );
14743 }
14744 }
14745 }, [inputRefs, isValid2, validity]);
14746 (0, import_element43.useEffect)(() => {
14747 const refs = Array.isArray(inputRefs) ? inputRefs : [inputRefs];
14748 const handleInvalid = (event) => {
14749 event.preventDefault();
14750 setIsTouched(true);
14751 };
14752 for (const ref of refs) {
14753 ref.current?.addEventListener("invalid", handleInvalid);
14754 }
14755 return () => {
14756 for (const ref of refs) {
14757 ref.current?.removeEventListener("invalid", handleInvalid);
14758 }
14759 };
14760 }, [inputRefs, setIsTouched]);
14761 (0, import_element43.useEffect)(() => {
14762 if (!isTouched) {
14763 return;
14764 }
14765 const result = validity ? getCustomValidity(isValid2, validity) : void 0;
14766 if (result) {
14767 setCustomValidity(result);
14768 } else {
14769 validateRefs();
14770 }
14771 }, [isTouched, isValid2, validity, validateRefs]);
14772 const onBlur = (event) => {
14773 if (isTouched) {
14774 return;
14775 }
14776 if (!event.relatedTarget || !event.currentTarget.contains(event.relatedTarget)) {
14777 setIsTouched(true);
14778 }
14779 };
14780 return /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)("div", { onBlur, children: [
14781 children,
14782 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)("div", { "aria-live": "polite", children: customValidity && /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
14783 "p",
14784 {
14785 className: clsx_default(
14786 "components-validated-control__indicator",
14787 customValidity.type === "invalid" ? "is-invalid" : void 0
14788 ),
14789 children: [
14790 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14791 import_components32.Icon,
14792 {
14793 className: "components-validated-control__indicator-icon",
14794 icon: error_default,
14795 size: 16,
14796 fill: "currentColor"
14797 }
14798 ),
14799 customValidity.message
14800 ]
14801 }
14802 ) })
14803 ] });
14804 }
14805 function CalendarDateControl({
14806 data,
14807 field,
14808 onChange,
14809 hideLabelFromVision,
14810 markWhenOptional,
14811 validity
14812 }) {
14813 const {
14814 id,
14815 label,
14816 description,
14817 setValue,
14818 getValue,
14819 isValid: isValid2,
14820 format: fieldFormat
14821 } = field;
14822 const disabled = field.isDisabled({ item: data, field });
14823 const [selectedPresetId, setSelectedPresetId] = (0, import_element43.useState)(
14824 null
14825 );
14826 const weekStartsOn = fieldFormat.weekStartsOn ?? (0, import_date4.getSettings)().l10n.startOfWeek;
14827 const fieldValue = getValue({ item: data });
14828 const value = typeof fieldValue === "string" ? fieldValue : void 0;
14829 const [calendarMonth, setCalendarMonth] = (0, import_element43.useState)(() => {
14830 const parsedDate = parseDate(value);
14831 return parsedDate || /* @__PURE__ */ new Date();
14832 });
14833 const [isTouched, setIsTouched] = (0, import_element43.useState)(false);
14834 const validityTargetRef = (0, import_element43.useRef)(null);
14835 const { minConstraint, maxConstraint, disabledMatchers } = useDisabledDateMatchers(isValid2, parseDate);
14836 const onChangeCallback = (0, import_element43.useCallback)(
14837 (newValue) => onChange(setValue({ item: data, value: newValue })),
14838 [data, onChange, setValue]
14839 );
14840 const onSelectDate = (0, import_element43.useCallback)(
14841 (newDate) => {
14842 const dateValue = newDate ? format(newDate, "yyyy-MM-dd") : void 0;
14843 onChangeCallback(dateValue);
14844 setSelectedPresetId(null);
14845 setIsTouched(true);
14846 },
14847 [onChangeCallback]
14848 );
14849 const handlePresetClick = (0, import_element43.useCallback)(
14850 (preset) => {
14851 const presetDate = preset.getValue();
14852 const dateValue = formatDate(presetDate);
14853 setCalendarMonth(presetDate);
14854 onChangeCallback(dateValue);
14855 setSelectedPresetId(preset.id);
14856 setIsTouched(true);
14857 },
14858 [onChangeCallback]
14859 );
14860 const handleManualDateChange = (0, import_element43.useCallback)(
14861 (newValue) => {
14862 onChangeCallback(newValue);
14863 if (newValue) {
14864 const parsedDate = parseDate(newValue);
14865 if (parsedDate) {
14866 setCalendarMonth(parsedDate);
14867 }
14868 }
14869 setSelectedPresetId(null);
14870 setIsTouched(true);
14871 },
14872 [onChangeCallback]
14873 );
14874 const {
14875 timezone: { string: timezoneString }
14876 } = (0, import_date4.getSettings)();
14877 let displayLabel = label;
14878 if (isValid2?.required && !markWhenOptional) {
14879 displayLabel = `${label} (${(0, import_i18n39.__)("Required")})`;
14880 } else if (!isValid2?.required && markWhenOptional) {
14881 displayLabel = `${label} (${(0, import_i18n39.__)("Optional")})`;
14882 }
14883 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14884 ValidatedDateControl,
14885 {
14886 field,
14887 validity,
14888 inputRefs: validityTargetRef,
14889 isTouched,
14890 setIsTouched,
14891 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14892 import_components32.BaseControl,
14893 {
14894 id,
14895 className: "dataviews-controls__date",
14896 label: displayLabel,
14897 help: description,
14898 hideLabelFromVision,
14899 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(Stack, { direction: "column", gap: "lg", children: [
14900 /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
14901 Stack,
14902 {
14903 direction: "row",
14904 gap: "sm",
14905 wrap: "wrap",
14906 justify: "flex-start",
14907 children: [
14908 DATE_PRESETS.map((preset) => {
14909 const isSelected2 = selectedPresetId === preset.id;
14910 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14911 import_components32.Button,
14912 {
14913 className: "dataviews-controls__date-preset",
14914 variant: "tertiary",
14915 isPressed: isSelected2,
14916 size: "small",
14917 disabled,
14918 accessibleWhenDisabled: true,
14919 onClick: () => handlePresetClick(preset),
14920 children: preset.label
14921 },
14922 preset.id
14923 );
14924 }),
14925 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14926 import_components32.Button,
14927 {
14928 className: "dataviews-controls__date-preset",
14929 variant: "tertiary",
14930 isPressed: !selectedPresetId,
14931 size: "small",
14932 disabled: !!selectedPresetId || disabled,
14933 accessibleWhenDisabled: true,
14934 children: (0, import_i18n39.__)("Custom")
14935 }
14936 )
14937 ]
14938 }
14939 ),
14940 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14941 import_components32.__experimentalInputControl,
14942 {
14943 __next40pxDefaultSize: true,
14944 ref: validityTargetRef,
14945 type: "date",
14946 label: (0, import_i18n39.__)("Date"),
14947 hideLabelFromVision: true,
14948 value,
14949 onChange: handleManualDateChange,
14950 required: !!field.isValid?.required,
14951 disabled,
14952 min: minConstraint,
14953 max: maxConstraint
14954 }
14955 ),
14956 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14957 DateCalendar2,
14958 {
14959 style: { width: "100%" },
14960 selected: value ? parseDate(value) || void 0 : void 0,
14961 onSelect: onSelectDate,
14962 month: calendarMonth,
14963 onMonthChange: setCalendarMonth,
14964 timeZone: timezoneString || void 0,
14965 weekStartsOn,
14966 disabled: disabled || disabledMatchers,
14967 disableNavigation: disabled
14968 }
14969 )
14970 ] })
14971 }
14972 )
14973 }
14974 );
14975 }
14976 function CalendarDateRangeControl({
14977 data,
14978 field,
14979 onChange,
14980 hideLabelFromVision,
14981 markWhenOptional,
14982 validity
14983 }) {
14984 const {
14985 id,
14986 label,
14987 description,
14988 getValue,
14989 setValue,
14990 isValid: isValid2,
14991 format: fieldFormat
14992 } = field;
14993 const disabled = field.isDisabled({ item: data, field });
14994 let value;
14995 const fieldValue = getValue({ item: data });
14996 if (Array.isArray(fieldValue) && fieldValue.length === 2 && fieldValue.every((date) => typeof date === "string")) {
14997 value = fieldValue;
14998 }
14999 const weekStartsOn = fieldFormat.weekStartsOn ?? (0, import_date4.getSettings)().l10n.startOfWeek;
15000 const { minConstraint, maxConstraint, disabledMatchers } = useDisabledDateMatchers(isValid2, parseDate);
15001 const onChangeCallback = (0, import_element43.useCallback)(
15002 (newValue) => {
15003 onChange(
15004 setValue({
15005 item: data,
15006 value: newValue
15007 })
15008 );
15009 },
15010 [data, onChange, setValue]
15011 );
15012 const [selectedPresetId, setSelectedPresetId] = (0, import_element43.useState)(
15013 null
15014 );
15015 const selectedRange = (0, import_element43.useMemo)(() => {
15016 if (!value) {
15017 return { from: void 0, to: void 0 };
15018 }
15019 const [from, to] = value;
15020 return {
15021 from: parseDate(from) || void 0,
15022 to: parseDate(to) || void 0
15023 };
15024 }, [value]);
15025 const [calendarMonth, setCalendarMonth] = (0, import_element43.useState)(() => {
15026 return selectedRange.from || /* @__PURE__ */ new Date();
15027 });
15028 const [isTouched, setIsTouched] = (0, import_element43.useState)(false);
15029 const fromInputRef = (0, import_element43.useRef)(null);
15030 const toInputRef = (0, import_element43.useRef)(null);
15031 const updateDateRange = (0, import_element43.useCallback)(
15032 (fromDate, toDate2) => {
15033 if (fromDate && toDate2) {
15034 onChangeCallback([
15035 formatDate(fromDate),
15036 formatDate(toDate2)
15037 ]);
15038 } else if (!fromDate && !toDate2) {
15039 onChangeCallback(void 0);
15040 }
15041 },
15042 [onChangeCallback]
15043 );
15044 const onSelectCalendarRange = (0, import_element43.useCallback)(
15045 (newRange) => {
15046 updateDateRange(newRange?.from, newRange?.to);
15047 setSelectedPresetId(null);
15048 setIsTouched(true);
15049 },
15050 [updateDateRange]
15051 );
15052 const handlePresetClick = (0, import_element43.useCallback)(
15053 (preset) => {
15054 const [startDate, endDate] = preset.getValue();
15055 setCalendarMonth(startDate);
15056 updateDateRange(startDate, endDate);
15057 setSelectedPresetId(preset.id);
15058 setIsTouched(true);
15059 },
15060 [updateDateRange]
15061 );
15062 const handleManualDateChange = (0, import_element43.useCallback)(
15063 (fromOrTo, newValue) => {
15064 const [currentFrom, currentTo] = value || [
15065 void 0,
15066 void 0
15067 ];
15068 const updatedFrom = fromOrTo === "from" ? newValue : currentFrom;
15069 const updatedTo = fromOrTo === "to" ? newValue : currentTo;
15070 updateDateRange(updatedFrom, updatedTo);
15071 if (newValue) {
15072 const parsedDate = parseDate(newValue);
15073 if (parsedDate) {
15074 setCalendarMonth(parsedDate);
15075 }
15076 }
15077 setSelectedPresetId(null);
15078 setIsTouched(true);
15079 },
15080 [value, updateDateRange]
15081 );
15082 const { timezone } = (0, import_date4.getSettings)();
15083 let displayLabel = label;
15084 if (field.isValid?.required && !markWhenOptional) {
15085 displayLabel = `${label} (${(0, import_i18n39.__)("Required")})`;
15086 } else if (!field.isValid?.required && markWhenOptional) {
15087 displayLabel = `${label} (${(0, import_i18n39.__)("Optional")})`;
15088 }
15089 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15090 ValidatedDateControl,
15091 {
15092 field,
15093 validity,
15094 inputRefs: [fromInputRef, toInputRef],
15095 isTouched,
15096 setIsTouched,
15097 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15098 import_components32.BaseControl,
15099 {
15100 id,
15101 className: "dataviews-controls__date",
15102 label: displayLabel,
15103 help: description,
15104 hideLabelFromVision,
15105 children: /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(Stack, { direction: "column", gap: "lg", children: [
15106 /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
15107 Stack,
15108 {
15109 direction: "row",
15110 gap: "sm",
15111 wrap: "wrap",
15112 justify: "flex-start",
15113 children: [
15114 DATE_RANGE_PRESETS.map((preset) => {
15115 const isSelected2 = selectedPresetId === preset.id;
15116 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15117 import_components32.Button,
15118 {
15119 className: "dataviews-controls__date-preset",
15120 variant: "tertiary",
15121 isPressed: isSelected2,
15122 size: "small",
15123 disabled,
15124 accessibleWhenDisabled: true,
15125 onClick: () => handlePresetClick(preset),
15126 children: preset.label
15127 },
15128 preset.id
15129 );
15130 }),
15131 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15132 import_components32.Button,
15133 {
15134 className: "dataviews-controls__date-preset",
15135 variant: "tertiary",
15136 isPressed: !selectedPresetId,
15137 size: "small",
15138 accessibleWhenDisabled: true,
15139 disabled: !!selectedPresetId || disabled,
15140 children: (0, import_i18n39.__)("Custom")
15141 }
15142 )
15143 ]
15144 }
15145 ),
15146 /* @__PURE__ */ (0, import_jsx_runtime78.jsxs)(
15147 Stack,
15148 {
15149 direction: "row",
15150 gap: "sm",
15151 justify: "space-between",
15152 className: "dataviews-controls__date-range-inputs",
15153 children: [
15154 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15155 import_components32.__experimentalInputControl,
15156 {
15157 __next40pxDefaultSize: true,
15158 ref: fromInputRef,
15159 type: "date",
15160 label: (0, import_i18n39.__)("From"),
15161 hideLabelFromVision: true,
15162 value: value?.[0],
15163 onChange: (newValue) => handleManualDateChange("from", newValue),
15164 required: !!field.isValid?.required,
15165 disabled,
15166 min: minConstraint,
15167 max: maxConstraint
15168 }
15169 ),
15170 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15171 import_components32.__experimentalInputControl,
15172 {
15173 __next40pxDefaultSize: true,
15174 ref: toInputRef,
15175 type: "date",
15176 label: (0, import_i18n39.__)("To"),
15177 hideLabelFromVision: true,
15178 value: value?.[1],
15179 onChange: (newValue) => handleManualDateChange("to", newValue),
15180 required: !!field.isValid?.required,
15181 disabled,
15182 min: minConstraint,
15183 max: maxConstraint
15184 }
15185 )
15186 ]
15187 }
15188 ),
15189 /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15190 DateRangeCalendar,
15191 {
15192 style: { width: "100%" },
15193 selected: selectedRange,
15194 onSelect: onSelectCalendarRange,
15195 month: calendarMonth,
15196 onMonthChange: setCalendarMonth,
15197 timeZone: timezone.string || void 0,
15198 weekStartsOn,
15199 disabled: disabled || disabledMatchers
15200 }
15201 )
15202 ] })
15203 }
15204 )
15205 }
15206 );
15207 }
15208 function DateControl({
15209 data,
15210 field,
15211 onChange,
15212 hideLabelFromVision,
15213 markWhenOptional,
15214 operator,
15215 validity
15216 }) {
15217 if (operator === OPERATOR_IN_THE_PAST || operator === OPERATOR_OVER) {
15218 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15219 RelativeDateControl,
15220 {
15221 className: "dataviews-controls__date",
15222 data,
15223 field,
15224 onChange,
15225 hideLabelFromVision,
15226 operator
15227 }
15228 );
15229 }
15230 if (operator === OPERATOR_BETWEEN) {
15231 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15232 CalendarDateRangeControl,
15233 {
15234 data,
15235 field,
15236 onChange,
15237 hideLabelFromVision,
15238 markWhenOptional,
15239 validity
15240 }
15241 );
15242 }
15243 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
15244 CalendarDateControl,
15245 {
15246 data,
15247 field,
15248 onChange,
15249 hideLabelFromVision,
15250 markWhenOptional,
15251 validity
15252 }
15253 );
15254 }
15255
15256 // packages/dataviews/build-module/components/dataform-controls/select.mjs
15257 var import_components33 = __toESM(require_components(), 1);
15258 var import_element44 = __toESM(require_element(), 1);
15259 var import_jsx_runtime79 = __toESM(require_jsx_runtime(), 1);
15260 var { ValidatedSelectControl } = unlock(import_components33.privateApis);
15261 function Select({
15262 data,
15263 field,
15264 onChange,
15265 hideLabelFromVision,
15266 markWhenOptional,
15267 validity
15268 }) {
15269 const { type, label, description, getValue, setValue, isValid: isValid2 } = field;
15270 const disabled = field.isDisabled({ item: data, field });
15271 const isMultiple = type === "array";
15272 const value = getValue({ item: data }) ?? (isMultiple ? [] : "");
15273 const onChangeControl = (0, import_element44.useCallback)(
15274 (newValue) => onChange(setValue({ item: data, value: newValue })),
15275 [data, onChange, setValue]
15276 );
15277 const { elements, isLoading } = useElements({
15278 elements: field.elements,
15279 getElements: field.getElements
15280 });
15281 if (isLoading) {
15282 return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(import_components33.Spinner, {});
15283 }
15284 return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
15285 ValidatedSelectControl,
15286 {
15287 required: !!field.isValid?.required,
15288 markWhenOptional,
15289 customValidity: getCustomValidity(isValid2, validity),
15290 label,
15291 value,
15292 help: description,
15293 options: elements,
15294 onChange: onChangeControl,
15295 __next40pxDefaultSize: true,
15296 hideLabelFromVision,
15297 multiple: isMultiple,
15298 disabled
15299 }
15300 );
15301 }
15302
15303 // packages/dataviews/build-module/components/dataform-controls/adaptive-select.mjs
15304 var import_jsx_runtime80 = __toESM(require_jsx_runtime(), 1);
15305 var ELEMENTS_THRESHOLD = 10;
15306 function AdaptiveSelect(props) {
15307 const { field } = props;
15308 const { elements } = useElements({
15309 elements: field.elements,
15310 getElements: field.getElements
15311 });
15312 if (elements.length >= ELEMENTS_THRESHOLD) {
15313 return /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(Combobox3, { ...props });
15314 }
15315 return /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(Select, { ...props });
15316 }
15317
15318 // packages/dataviews/build-module/components/dataform-controls/email.mjs
15319 var import_components35 = __toESM(require_components(), 1);
15320
15321 // packages/dataviews/build-module/components/dataform-controls/utils/validated-input.mjs
15322 var import_components34 = __toESM(require_components(), 1);
15323 var import_element45 = __toESM(require_element(), 1);
15324 var import_jsx_runtime81 = __toESM(require_jsx_runtime(), 1);
15325 var { ValidatedInputControl: ValidatedInputControl2 } = unlock(import_components34.privateApis);
15326 function ValidatedText({
15327 data,
15328 field,
15329 onChange,
15330 hideLabelFromVision,
15331 markWhenOptional,
15332 type,
15333 prefix,
15334 suffix,
15335 validity
15336 }) {
15337 const { label, placeholder, description, getValue, setValue, isValid: isValid2 } = field;
15338 const value = getValue({ item: data });
15339 const disabled = field.isDisabled({ item: data, field });
15340 const onChangeControl = (0, import_element45.useCallback)(
15341 (newValue) => onChange(
15342 setValue({
15343 item: data,
15344 value: newValue
15345 })
15346 ),
15347 [data, setValue, onChange]
15348 );
15349 return /* @__PURE__ */ (0, import_jsx_runtime81.jsx)(
15350 ValidatedInputControl2,
15351 {
15352 required: !!isValid2.required,
15353 markWhenOptional,
15354 customValidity: getCustomValidity(isValid2, validity),
15355 label,
15356 placeholder,
15357 value: value ?? "",
15358 help: description,
15359 onChange: onChangeControl,
15360 hideLabelFromVision,
15361 type,
15362 prefix,
15363 suffix,
15364 disabled,
15365 pattern: isValid2.pattern ? isValid2.pattern.constraint : void 0,
15366 minLength: isValid2.minLength ? isValid2.minLength.constraint : void 0,
15367 maxLength: isValid2.maxLength ? isValid2.maxLength.constraint : void 0,
15368 __next40pxDefaultSize: true
15369 }
15370 );
15371 }
15372
15373 // packages/dataviews/build-module/components/dataform-controls/email.mjs
15374 var import_jsx_runtime82 = __toESM(require_jsx_runtime(), 1);
15375 function Email({
15376 data,
15377 field,
15378 onChange,
15379 hideLabelFromVision,
15380 markWhenOptional,
15381 validity
15382 }) {
15383 return /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(
15384 ValidatedText,
15385 {
15386 ...{
15387 data,
15388 field,
15389 onChange,
15390 hideLabelFromVision,
15391 markWhenOptional,
15392 validity,
15393 type: "email",
15394 prefix: /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(import_components35.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(import_components35.Icon, { icon: envelope_default }) })
15395 }
15396 }
15397 );
15398 }
15399
15400 // packages/dataviews/build-module/components/dataform-controls/telephone.mjs
15401 var import_components36 = __toESM(require_components(), 1);
15402 var import_jsx_runtime83 = __toESM(require_jsx_runtime(), 1);
15403 function Telephone({
15404 data,
15405 field,
15406 onChange,
15407 hideLabelFromVision,
15408 markWhenOptional,
15409 validity
15410 }) {
15411 return /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(
15412 ValidatedText,
15413 {
15414 ...{
15415 data,
15416 field,
15417 onChange,
15418 hideLabelFromVision,
15419 markWhenOptional,
15420 validity,
15421 type: "tel",
15422 prefix: /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(import_components36.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(import_components36.Icon, { icon: mobile_default }) })
15423 }
15424 }
15425 );
15426 }
15427
15428 // packages/dataviews/build-module/components/dataform-controls/url.mjs
15429 var import_components37 = __toESM(require_components(), 1);
15430 var import_jsx_runtime84 = __toESM(require_jsx_runtime(), 1);
15431 function Url({
15432 data,
15433 field,
15434 onChange,
15435 hideLabelFromVision,
15436 markWhenOptional,
15437 validity
15438 }) {
15439 return /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(
15440 ValidatedText,
15441 {
15442 ...{
15443 data,
15444 field,
15445 onChange,
15446 hideLabelFromVision,
15447 markWhenOptional,
15448 validity,
15449 type: "url",
15450 prefix: /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(import_components37.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(import_components37.Icon, { icon: link_default }) })
15451 }
15452 }
15453 );
15454 }
15455
15456 // packages/dataviews/build-module/components/dataform-controls/utils/validated-number.mjs
15457 var import_components38 = __toESM(require_components(), 1);
15458 var import_element46 = __toESM(require_element(), 1);
15459 var import_i18n40 = __toESM(require_i18n(), 1);
15460 var import_jsx_runtime85 = __toESM(require_jsx_runtime(), 1);
15461 var { ValidatedNumberControl } = unlock(import_components38.privateApis);
15462 function toNumberOrEmpty(value) {
15463 if (value === "" || value === void 0) {
15464 return "";
15465 }
15466 const number = Number(value);
15467 return Number.isFinite(number) ? number : "";
15468 }
15469 function BetweenControls({
15470 value,
15471 onChange,
15472 hideLabelFromVision,
15473 step
15474 }) {
15475 const [min = "", max = ""] = value;
15476 const onChangeMin = (0, import_element46.useCallback)(
15477 (newValue) => onChange([toNumberOrEmpty(newValue), max]),
15478 [onChange, max]
15479 );
15480 const onChangeMax = (0, import_element46.useCallback)(
15481 (newValue) => onChange([min, toNumberOrEmpty(newValue)]),
15482 [onChange, min]
15483 );
15484 return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15485 import_components38.BaseControl,
15486 {
15487 help: (0, import_i18n40.__)("The max. value must be greater than the min. value."),
15488 children: /* @__PURE__ */ (0, import_jsx_runtime85.jsxs)(import_components38.Flex, { direction: "row", gap: 4, children: [
15489 /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15490 import_components38.__experimentalNumberControl,
15491 {
15492 label: (0, import_i18n40.__)("Min."),
15493 value: min,
15494 max: max ? Number(max) - step : void 0,
15495 onChange: onChangeMin,
15496 __next40pxDefaultSize: true,
15497 hideLabelFromVision,
15498 step
15499 }
15500 ),
15501 /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15502 import_components38.__experimentalNumberControl,
15503 {
15504 label: (0, import_i18n40.__)("Max."),
15505 value: max,
15506 min: min ? Number(min) + step : void 0,
15507 onChange: onChangeMax,
15508 __next40pxDefaultSize: true,
15509 hideLabelFromVision,
15510 step
15511 }
15512 )
15513 ] })
15514 }
15515 );
15516 }
15517 function ValidatedNumber({
15518 data,
15519 field,
15520 onChange,
15521 hideLabelFromVision,
15522 markWhenOptional,
15523 operator,
15524 validity
15525 }) {
15526 const decimals = field.format?.decimals ?? 0;
15527 const step = Math.pow(10, Math.abs(decimals) * -1);
15528 const { label, description, getValue, setValue, isValid: isValid2 } = field;
15529 const value = getValue({ item: data }) ?? "";
15530 const disabled = field.isDisabled({ item: data, field });
15531 const onChangeControl = (0, import_element46.useCallback)(
15532 (newValue) => {
15533 onChange(
15534 setValue({
15535 item: data,
15536 // Do not convert an empty string or undefined to a number,
15537 // otherwise there's a mismatch between the UI control (empty)
15538 // and the data relied by onChange (0).
15539 value: ["", void 0].includes(newValue) ? void 0 : Number(newValue)
15540 })
15541 );
15542 },
15543 [data, onChange, setValue]
15544 );
15545 const onChangeBetweenControls = (0, import_element46.useCallback)(
15546 (newValue) => {
15547 onChange(
15548 setValue({
15549 item: data,
15550 value: newValue
15551 })
15552 );
15553 },
15554 [data, onChange, setValue]
15555 );
15556 if (operator === OPERATOR_BETWEEN) {
15557 let valueBetween = ["", ""];
15558 if (Array.isArray(value) && value.length === 2 && value.every(
15559 (element) => typeof element === "number" || element === ""
15560 )) {
15561 valueBetween = value;
15562 }
15563 return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15564 BetweenControls,
15565 {
15566 value: valueBetween,
15567 onChange: onChangeBetweenControls,
15568 hideLabelFromVision,
15569 step
15570 }
15571 );
15572 }
15573 return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
15574 ValidatedNumberControl,
15575 {
15576 required: !!isValid2.required,
15577 markWhenOptional,
15578 customValidity: getCustomValidity(isValid2, validity),
15579 label,
15580 help: description,
15581 value,
15582 onChange: onChangeControl,
15583 __next40pxDefaultSize: true,
15584 hideLabelFromVision,
15585 step,
15586 min: isValid2.min ? isValid2.min.constraint : void 0,
15587 max: isValid2.max ? isValid2.max.constraint : void 0,
15588 disabled
15589 }
15590 );
15591 }
15592
15593 // packages/dataviews/build-module/components/dataform-controls/integer.mjs
15594 var import_jsx_runtime86 = __toESM(require_jsx_runtime(), 1);
15595 function Integer(props) {
15596 return /* @__PURE__ */ (0, import_jsx_runtime86.jsx)(ValidatedNumber, { ...props });
15597 }
15598
15599 // packages/dataviews/build-module/components/dataform-controls/number.mjs
15600 var import_jsx_runtime87 = __toESM(require_jsx_runtime(), 1);
15601 function Number2(props) {
15602 return /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(ValidatedNumber, { ...props });
15603 }
15604
15605 // packages/dataviews/build-module/components/dataform-controls/radio.mjs
15606 var import_components39 = __toESM(require_components(), 1);
15607 var import_element47 = __toESM(require_element(), 1);
15608 var import_jsx_runtime88 = __toESM(require_jsx_runtime(), 1);
15609 var { ValidatedRadioControl } = unlock(import_components39.privateApis);
15610 function Radio({
15611 data,
15612 field,
15613 onChange,
15614 hideLabelFromVision,
15615 markWhenOptional,
15616 validity
15617 }) {
15618 const { label, description, getValue, setValue, isValid: isValid2 } = field;
15619 const disabled = field.isDisabled({ item: data, field });
15620 const { elements, isLoading } = useElements({
15621 elements: field.elements,
15622 getElements: field.getElements
15623 });
15624 const value = getValue({ item: data });
15625 const onChangeControl = (0, import_element47.useCallback)(
15626 (newValue) => onChange(setValue({ item: data, value: newValue })),
15627 [data, onChange, setValue]
15628 );
15629 if (isLoading) {
15630 return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(import_components39.Spinner, {});
15631 }
15632 return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(
15633 ValidatedRadioControl,
15634 {
15635 required: !!field.isValid?.required,
15636 markWhenOptional,
15637 customValidity: getCustomValidity(isValid2, validity),
15638 label,
15639 help: description,
15640 onChange: onChangeControl,
15641 options: elements,
15642 selected: value,
15643 hideLabelFromVision,
15644 disabled
15645 }
15646 );
15647 }
15648
15649 // packages/dataviews/build-module/components/dataform-controls/text.mjs
15650 var import_element48 = __toESM(require_element(), 1);
15651 var import_jsx_runtime89 = __toESM(require_jsx_runtime(), 1);
15652 function Text({
15653 data,
15654 field,
15655 onChange,
15656 hideLabelFromVision,
15657 markWhenOptional,
15658 config,
15659 validity
15660 }) {
15661 const { prefix, suffix } = config || {};
15662 return /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(
15663 ValidatedText,
15664 {
15665 ...{
15666 data,
15667 field,
15668 onChange,
15669 hideLabelFromVision,
15670 markWhenOptional,
15671 validity,
15672 prefix: prefix ? (0, import_element48.createElement)(prefix) : void 0,
15673 suffix: suffix ? (0, import_element48.createElement)(suffix) : void 0
15674 }
15675 }
15676 );
15677 }
15678
15679 // packages/dataviews/build-module/components/dataform-controls/toggle.mjs
15680 var import_components40 = __toESM(require_components(), 1);
15681 var import_element49 = __toESM(require_element(), 1);
15682 var import_jsx_runtime90 = __toESM(require_jsx_runtime(), 1);
15683 var { ValidatedToggleControl } = unlock(import_components40.privateApis);
15684 function Toggle({
15685 field,
15686 onChange,
15687 data,
15688 hideLabelFromVision,
15689 markWhenOptional,
15690 validity
15691 }) {
15692 const { label, description, getValue, setValue, isValid: isValid2 } = field;
15693 const disabled = field.isDisabled({ item: data, field });
15694 const onChangeControl = (0, import_element49.useCallback)(() => {
15695 onChange(
15696 setValue({ item: data, value: !getValue({ item: data }) })
15697 );
15698 }, [onChange, setValue, data, getValue]);
15699 return /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(
15700 ValidatedToggleControl,
15701 {
15702 required: !!isValid2.required,
15703 markWhenOptional,
15704 customValidity: getCustomValidity(isValid2, validity),
15705 hidden: hideLabelFromVision,
15706 label,
15707 help: description,
15708 checked: getValue({ item: data }),
15709 onChange: onChangeControl,
15710 disabled
15711 }
15712 );
15713 }
15714
15715 // packages/dataviews/build-module/components/dataform-controls/textarea.mjs
15716 var import_components41 = __toESM(require_components(), 1);
15717 var import_element50 = __toESM(require_element(), 1);
15718 var import_jsx_runtime91 = __toESM(require_jsx_runtime(), 1);
15719 var { ValidatedTextareaControl } = unlock(import_components41.privateApis);
15720 function Textarea({
15721 data,
15722 field,
15723 onChange,
15724 hideLabelFromVision,
15725 markWhenOptional,
15726 config,
15727 validity
15728 }) {
15729 const { rows = 4 } = config || {};
15730 const disabled = field.isDisabled({ item: data, field });
15731 const { label, placeholder, description, setValue, isValid: isValid2 } = field;
15732 const value = field.getValue({ item: data });
15733 const onChangeControl = (0, import_element50.useCallback)(
15734 (newValue) => onChange(setValue({ item: data, value: newValue })),
15735 [data, onChange, setValue]
15736 );
15737 return /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
15738 ValidatedTextareaControl,
15739 {
15740 required: !!isValid2.required,
15741 markWhenOptional,
15742 customValidity: getCustomValidity(isValid2, validity),
15743 label,
15744 placeholder,
15745 value: value ?? "",
15746 help: description,
15747 onChange: onChangeControl,
15748 rows,
15749 disabled,
15750 minLength: isValid2.minLength ? isValid2.minLength.constraint : void 0,
15751 maxLength: isValid2.maxLength ? isValid2.maxLength.constraint : void 0,
15752 __next40pxDefaultSize: true,
15753 hideLabelFromVision
15754 }
15755 );
15756 }
15757
15758 // packages/dataviews/build-module/components/dataform-controls/toggle-group.mjs
15759 var import_components42 = __toESM(require_components(), 1);
15760 var import_element51 = __toESM(require_element(), 1);
15761 var import_jsx_runtime92 = __toESM(require_jsx_runtime(), 1);
15762 var { ValidatedToggleGroupControl } = unlock(import_components42.privateApis);
15763 function ToggleGroup({
15764 data,
15765 field,
15766 onChange,
15767 hideLabelFromVision,
15768 markWhenOptional,
15769 validity
15770 }) {
15771 const { getValue, setValue, isValid: isValid2 } = field;
15772 const disabled = field.isDisabled({ item: data, field });
15773 const value = getValue({ item: data });
15774 const onChangeControl = (0, import_element51.useCallback)(
15775 (newValue) => onChange(setValue({ item: data, value: newValue })),
15776 [data, onChange, setValue]
15777 );
15778 const { elements, isLoading } = useElements({
15779 elements: field.elements,
15780 getElements: field.getElements
15781 });
15782 if (isLoading) {
15783 return /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(import_components42.Spinner, {});
15784 }
15785 if (elements.length === 0) {
15786 return null;
15787 }
15788 const selectedOption = elements.find((el) => el.value === value);
15789 return /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
15790 ValidatedToggleGroupControl,
15791 {
15792 required: !!field.isValid?.required,
15793 markWhenOptional,
15794 customValidity: getCustomValidity(isValid2, validity),
15795 __next40pxDefaultSize: true,
15796 isBlock: true,
15797 label: field.label,
15798 help: selectedOption?.description || field.description,
15799 onChange: onChangeControl,
15800 value,
15801 hideLabelFromVision,
15802 children: elements.map((el) => /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
15803 import_components42.__experimentalToggleGroupControlOption,
15804 {
15805 label: el.label,
15806 value: el.value,
15807 disabled
15808 },
15809 el.value
15810 ))
15811 }
15812 );
15813 }
15814
15815 // packages/dataviews/build-module/components/dataform-controls/array.mjs
15816 var import_components43 = __toESM(require_components(), 1);
15817 var import_element52 = __toESM(require_element(), 1);
15818 var import_jsx_runtime93 = __toESM(require_jsx_runtime(), 1);
15819 var { ValidatedFormTokenField } = unlock(import_components43.privateApis);
15820 function ArrayControl({
15821 data,
15822 field,
15823 onChange,
15824 hideLabelFromVision,
15825 markWhenOptional,
15826 validity
15827 }) {
15828 const { label, placeholder, getValue, setValue, isValid: isValid2 } = field;
15829 const value = getValue({ item: data });
15830 const disabled = field.isDisabled({ item: data, field });
15831 const { elements, isLoading } = useElements({
15832 elements: field.elements,
15833 getElements: field.getElements
15834 });
15835 const arrayValueAsElements = (0, import_element52.useMemo)(
15836 () => Array.isArray(value) ? value.map((token) => {
15837 const element = elements?.find(
15838 (suggestion) => suggestion.value === token
15839 );
15840 return element || { value: token, label: token };
15841 }) : [],
15842 [value, elements]
15843 );
15844 const onChangeControl = (0, import_element52.useCallback)(
15845 (tokens) => {
15846 const valueTokens = tokens.map((token) => {
15847 if (typeof token === "object" && "value" in token) {
15848 return token.value;
15849 }
15850 return token;
15851 });
15852 onChange(setValue({ item: data, value: valueTokens }));
15853 },
15854 [onChange, setValue, data]
15855 );
15856 if (isLoading) {
15857 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_components43.Spinner, {});
15858 }
15859 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
15860 ValidatedFormTokenField,
15861 {
15862 required: !!isValid2?.required,
15863 markWhenOptional,
15864 customValidity: getCustomValidity(isValid2, validity),
15865 label: hideLabelFromVision ? void 0 : label,
15866 value: arrayValueAsElements,
15867 onChange: onChangeControl,
15868 placeholder,
15869 suggestions: elements?.map((element) => element.value),
15870 disabled,
15871 __experimentalValidateInput: (token) => {
15872 if (field.isValid?.elements && elements) {
15873 return elements.some(
15874 (element) => element.value === token || element.label === token
15875 );
15876 }
15877 return true;
15878 },
15879 __experimentalExpandOnFocus: elements && elements.length > 0,
15880 __experimentalShowHowTo: !field.isValid?.elements,
15881 displayTransform: (token) => {
15882 if (typeof token === "object" && "label" in token) {
15883 return token.label;
15884 }
15885 if (typeof token === "string" && elements) {
15886 const element = elements.find(
15887 (el) => el.value === token
15888 );
15889 return element?.label || token;
15890 }
15891 return token;
15892 },
15893 __experimentalRenderItem: ({ item }) => {
15894 if (typeof item === "string" && elements) {
15895 const element = elements.find(
15896 (el) => el.value === item
15897 );
15898 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)("span", { children: element?.label || item });
15899 }
15900 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)("span", { children: item });
15901 }
15902 }
15903 );
15904 }
15905
15906 // node_modules/colord/index.mjs
15907 var r2 = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) };
15908 var t = function(r3) {
15909 return "string" == typeof r3 ? r3.length > 0 : "number" == typeof r3;
15910 };
15911 var n = function(r3, t2, n2) {
15912 return void 0 === t2 && (t2 = 0), void 0 === n2 && (n2 = Math.pow(10, t2)), Math.round(n2 * r3) / n2 + 0;
15913 };
15914 var e = function(r3, t2, n2) {
15915 return void 0 === t2 && (t2 = 0), void 0 === n2 && (n2 = 1), r3 > n2 ? n2 : r3 > t2 ? r3 : t2;
15916 };
15917 var u = function(r3) {
15918 return (r3 = isFinite(r3) ? r3 % 360 : 0) > 0 ? r3 : r3 + 360;
15919 };
15920 var a = function(r3) {
15921 return { r: e(r3.r, 0, 255), g: e(r3.g, 0, 255), b: e(r3.b, 0, 255), a: e(r3.a) };
15922 };
15923 var o = function(r3) {
15924 return { r: n(r3.r), g: n(r3.g), b: n(r3.b), a: n(r3.a, 3) };
15925 };
15926 var i = /^#([0-9a-f]{3,8})$/i;
15927 var s = function(r3) {
15928 var t2 = r3.toString(16);
15929 return t2.length < 2 ? "0" + t2 : t2;
15930 };
15931 var h = function(r3) {
15932 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;
15933 return { h: 60 * (i2 < 0 ? i2 + 6 : i2), s: a2 ? o2 / a2 * 100 : 0, v: a2 / 255 * 100, a: u2 };
15934 };
15935 var b = function(r3) {
15936 var t2 = r3.h, n2 = r3.s, e2 = r3.v, u2 = r3.a;
15937 t2 = t2 / 360 * 6, n2 /= 100, e2 /= 100;
15938 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;
15939 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 };
15940 };
15941 var g = function(r3) {
15942 return { h: u(r3.h), s: e(r3.s, 0, 100), l: e(r3.l, 0, 100), a: e(r3.a) };
15943 };
15944 var d = function(r3) {
15945 return { h: n(r3.h), s: n(r3.s), l: n(r3.l), a: n(r3.a, 3) };
15946 };
15947 var f = function(r3) {
15948 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 }));
15949 var t2, n2, e2;
15950 };
15951 var c = function(r3) {
15952 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 };
15953 var t2, n2, e2, u2;
15954 };
15955 var l = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15956 var p = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15957 var v = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15958 var m = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15959 var y = { string: [[function(r3) {
15960 var t2 = i.exec(r3);
15961 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;
15962 }, "hex"], [function(r3) {
15963 var t2 = v.exec(r3) || m.exec(r3);
15964 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;
15965 }, "rgb"], [function(t2) {
15966 var n2 = l.exec(t2) || p.exec(t2);
15967 if (!n2) return null;
15968 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) });
15969 return f(a2);
15970 }, "hsl"]], object: [[function(r3) {
15971 var n2 = r3.r, e2 = r3.g, u2 = r3.b, o2 = r3.a, i2 = void 0 === o2 ? 1 : o2;
15972 return t(n2) && t(e2) && t(u2) ? a({ r: Number(n2), g: Number(e2), b: Number(u2), a: Number(i2) }) : null;
15973 }, "rgb"], [function(r3) {
15974 var n2 = r3.h, e2 = r3.s, u2 = r3.l, a2 = r3.a, o2 = void 0 === a2 ? 1 : a2;
15975 if (!t(n2) || !t(e2) || !t(u2)) return null;
15976 var i2 = g({ h: Number(n2), s: Number(e2), l: Number(u2), a: Number(o2) });
15977 return f(i2);
15978 }, "hsl"], [function(r3) {
15979 var n2 = r3.h, a2 = r3.s, o2 = r3.v, i2 = r3.a, s2 = void 0 === i2 ? 1 : i2;
15980 if (!t(n2) || !t(a2) || !t(o2)) return null;
15981 var h2 = (function(r4) {
15982 return { h: u(r4.h), s: e(r4.s, 0, 100), v: e(r4.v, 0, 100), a: e(r4.a) };
15983 })({ h: Number(n2), s: Number(a2), v: Number(o2), a: Number(s2) });
15984 return b(h2);
15985 }, "hsv"]] };
15986 var N = function(r3, t2) {
15987 for (var n2 = 0; n2 < t2.length; n2++) {
15988 var e2 = t2[n2][0](r3);
15989 if (e2) return [e2, t2[n2][1]];
15990 }
15991 return [null, void 0];
15992 };
15993 var x = function(r3) {
15994 return "string" == typeof r3 ? N(r3.trim(), y.string) : "object" == typeof r3 && null !== r3 ? N(r3, y.object) : [null, void 0];
15995 };
15996 var M = function(r3, t2) {
15997 var n2 = c(r3);
15998 return { h: n2.h, s: e(n2.s + 100 * t2, 0, 100), l: n2.l, a: n2.a };
15999 };
16000 var H = function(r3) {
16001 return (299 * r3.r + 587 * r3.g + 114 * r3.b) / 1e3 / 255;
16002 };
16003 var $ = function(r3, t2) {
16004 var n2 = c(r3);
16005 return { h: n2.h, s: n2.s, l: e(n2.l + 100 * t2, 0, 100), a: n2.a };
16006 };
16007 var j = (function() {
16008 function r3(r4) {
16009 this.parsed = x(r4)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
16010 }
16011 return r3.prototype.isValid = function() {
16012 return null !== this.parsed;
16013 }, r3.prototype.brightness = function() {
16014 return n(H(this.rgba), 2);
16015 }, r3.prototype.isDark = function() {
16016 return H(this.rgba) < 0.5;
16017 }, r3.prototype.isLight = function() {
16018 return H(this.rgba) >= 0.5;
16019 }, r3.prototype.toHex = function() {
16020 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;
16021 var r4, t2, e2, u2, a2, i2;
16022 }, r3.prototype.toRgb = function() {
16023 return o(this.rgba);
16024 }, r3.prototype.toRgbString = function() {
16025 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 + ")";
16026 var r4, t2, n2, e2, u2;
16027 }, r3.prototype.toHsl = function() {
16028 return d(c(this.rgba));
16029 }, r3.prototype.toHslString = function() {
16030 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 + "%)";
16031 var r4, t2, n2, e2, u2;
16032 }, r3.prototype.toHsv = function() {
16033 return r4 = h(this.rgba), { h: n(r4.h), s: n(r4.s), v: n(r4.v), a: n(r4.a, 3) };
16034 var r4;
16035 }, r3.prototype.invert = function() {
16036 return w({ r: 255 - (r4 = this.rgba).r, g: 255 - r4.g, b: 255 - r4.b, a: r4.a });
16037 var r4;
16038 }, r3.prototype.saturate = function(r4) {
16039 return void 0 === r4 && (r4 = 0.1), w(M(this.rgba, r4));
16040 }, r3.prototype.desaturate = function(r4) {
16041 return void 0 === r4 && (r4 = 0.1), w(M(this.rgba, -r4));
16042 }, r3.prototype.grayscale = function() {
16043 return w(M(this.rgba, -1));
16044 }, r3.prototype.lighten = function(r4) {
16045 return void 0 === r4 && (r4 = 0.1), w($(this.rgba, r4));
16046 }, r3.prototype.darken = function(r4) {
16047 return void 0 === r4 && (r4 = 0.1), w($(this.rgba, -r4));
16048 }, r3.prototype.rotate = function(r4) {
16049 return void 0 === r4 && (r4 = 15), this.hue(this.hue() + r4);
16050 }, r3.prototype.alpha = function(r4) {
16051 return "number" == typeof r4 ? w({ r: (t2 = this.rgba).r, g: t2.g, b: t2.b, a: r4 }) : n(this.rgba.a, 3);
16052 var t2;
16053 }, r3.prototype.hue = function(r4) {
16054 var t2 = c(this.rgba);
16055 return "number" == typeof r4 ? w({ h: r4, s: t2.s, l: t2.l, a: t2.a }) : n(t2.h);
16056 }, r3.prototype.isEqual = function(r4) {
16057 return this.toHex() === w(r4).toHex();
16058 }, r3;
16059 })();
16060 var w = function(r3) {
16061 return r3 instanceof j ? r3 : new j(r3);
16062 };
16063
16064 // packages/dataviews/build-module/components/dataform-controls/color.mjs
16065 var import_components44 = __toESM(require_components(), 1);
16066 var import_element53 = __toESM(require_element(), 1);
16067 var import_i18n41 = __toESM(require_i18n(), 1);
16068 var import_jsx_runtime94 = __toESM(require_jsx_runtime(), 1);
16069 var { ValidatedInputControl: ValidatedInputControl3 } = unlock(import_components44.privateApis);
16070 var ColorPickerDropdown = ({
16071 color,
16072 onColorChange,
16073 disabled
16074 }) => {
16075 const validColor = color && w(color).isValid() ? color : "#ffffff";
16076 return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16077 import_components44.Dropdown,
16078 {
16079 className: "dataviews-controls__color-picker-dropdown",
16080 popoverProps: { resize: false },
16081 renderToggle: ({ onToggle }) => /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16082 import_components44.Button,
16083 {
16084 onClick: onToggle,
16085 "aria-label": (0, import_i18n41.__)("Open color picker"),
16086 size: "small",
16087 disabled,
16088 accessibleWhenDisabled: true,
16089 icon: () => /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_components44.ColorIndicator, { colorValue: validColor })
16090 }
16091 ),
16092 renderContent: () => /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_components44.__experimentalDropdownContentWrapper, { paddingSize: "none", children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16093 import_components44.ColorPicker,
16094 {
16095 color: validColor,
16096 onChange: onColorChange,
16097 enableAlpha: true
16098 }
16099 ) })
16100 }
16101 );
16102 };
16103 function Color({
16104 data,
16105 field,
16106 onChange,
16107 hideLabelFromVision,
16108 markWhenOptional,
16109 validity
16110 }) {
16111 const { label, placeholder, description, setValue, isValid: isValid2 } = field;
16112 const disabled = field.isDisabled({ item: data, field });
16113 const value = field.getValue({ item: data }) || "";
16114 const handleColorChange = (0, import_element53.useCallback)(
16115 (newColor) => {
16116 onChange(setValue({ item: data, value: newColor }));
16117 },
16118 [data, onChange, setValue]
16119 );
16120 const handleInputChange = (0, import_element53.useCallback)(
16121 (newValue) => {
16122 onChange(setValue({ item: data, value: newValue || "" }));
16123 },
16124 [data, onChange, setValue]
16125 );
16126 return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16127 ValidatedInputControl3,
16128 {
16129 required: !!field.isValid?.required,
16130 markWhenOptional,
16131 customValidity: getCustomValidity(isValid2, validity),
16132 label,
16133 placeholder,
16134 value,
16135 help: description,
16136 onChange: handleInputChange,
16137 hideLabelFromVision,
16138 type: "text",
16139 disabled,
16140 prefix: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_components44.__experimentalInputControlPrefixWrapper, { variant: "control", children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
16141 ColorPickerDropdown,
16142 {
16143 color: value,
16144 onColorChange: handleColorChange,
16145 disabled
16146 }
16147 ) })
16148 }
16149 );
16150 }
16151
16152 // packages/dataviews/build-module/components/dataform-controls/password.mjs
16153 var import_components45 = __toESM(require_components(), 1);
16154 var import_element54 = __toESM(require_element(), 1);
16155 var import_i18n42 = __toESM(require_i18n(), 1);
16156 var import_jsx_runtime95 = __toESM(require_jsx_runtime(), 1);
16157 function Password({
16158 data,
16159 field,
16160 onChange,
16161 hideLabelFromVision,
16162 markWhenOptional,
16163 validity
16164 }) {
16165 const [isVisible2, setIsVisible] = (0, import_element54.useState)(false);
16166 const disabled = field.isDisabled({ item: data, field });
16167 const toggleVisibility = (0, import_element54.useCallback)(() => {
16168 setIsVisible((prev) => !prev);
16169 }, []);
16170 return /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(
16171 ValidatedText,
16172 {
16173 ...{
16174 data,
16175 field,
16176 onChange,
16177 hideLabelFromVision,
16178 markWhenOptional,
16179 validity,
16180 type: isVisible2 ? "text" : "password",
16181 suffix: /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(import_components45.__experimentalInputControlSuffixWrapper, { variant: "control", children: /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(
16182 import_components45.Button,
16183 {
16184 icon: isVisible2 ? unseen_default : seen_default,
16185 onClick: toggleVisibility,
16186 size: "small",
16187 label: isVisible2 ? (0, import_i18n42.__)("Hide password") : (0, import_i18n42.__)("Show password"),
16188 disabled,
16189 accessibleWhenDisabled: true
16190 }
16191 ) })
16192 }
16193 }
16194 );
16195 }
16196
16197 // packages/dataviews/build-module/field-types/utils/has-elements.mjs
16198 function hasElements(field) {
16199 return Array.isArray(field.elements) && field.elements.length > 0 || typeof field.getElements === "function";
16200 }
16201
16202 // packages/dataviews/build-module/components/dataform-controls/index.mjs
16203 var import_jsx_runtime96 = __toESM(require_jsx_runtime(), 1);
16204 var FORM_CONTROLS = {
16205 adaptiveSelect: AdaptiveSelect,
16206 array: ArrayControl,
16207 checkbox: Checkbox,
16208 color: Color,
16209 combobox: Combobox3,
16210 datetime: DateTime,
16211 date: DateControl,
16212 email: Email,
16213 telephone: Telephone,
16214 url: Url,
16215 integer: Integer,
16216 number: Number2,
16217 password: Password,
16218 radio: Radio,
16219 select: Select,
16220 text: Text,
16221 toggle: Toggle,
16222 textarea: Textarea,
16223 toggleGroup: ToggleGroup
16224 };
16225 function isEditConfig(value) {
16226 return value && typeof value === "object" && typeof value.control === "string";
16227 }
16228 function createConfiguredControl(config) {
16229 const { control, ...controlConfig } = config;
16230 const BaseControlType = getControlByType(control);
16231 if (BaseControlType === null) {
16232 return null;
16233 }
16234 return function ConfiguredControl(props) {
16235 return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(BaseControlType, { ...props, config: controlConfig });
16236 };
16237 }
16238 function getControl(field, fallback) {
16239 if (typeof field.Edit === "function") {
16240 return field.Edit;
16241 }
16242 if (typeof field.Edit === "string") {
16243 return getControlByType(field.Edit);
16244 }
16245 if (isEditConfig(field.Edit)) {
16246 return createConfiguredControl(field.Edit);
16247 }
16248 if (hasElements(field) && field.type !== "array") {
16249 return getControlByType("adaptiveSelect");
16250 }
16251 if (fallback === null) {
16252 return null;
16253 }
16254 return getControlByType(fallback);
16255 }
16256 function getControlByType(type) {
16257 if (Object.keys(FORM_CONTROLS).includes(type)) {
16258 return FORM_CONTROLS[type];
16259 }
16260 return null;
16261 }
16262
16263 // packages/dataviews/build-module/field-types/utils/get-filter-by.mjs
16264 function getFilterBy(field, defaultOperators, validOperators) {
16265 if (field.filterBy === false) {
16266 return false;
16267 }
16268 const operators = field.filterBy?.operators?.filter(
16269 (op) => validOperators.includes(op)
16270 ) ?? defaultOperators;
16271 if (operators.length === 0) {
16272 return false;
16273 }
16274 return {
16275 isPrimary: !!field.filterBy?.isPrimary,
16276 operators
16277 };
16278 }
16279 var get_filter_by_default = getFilterBy;
16280
16281 // packages/dataviews/build-module/field-types/utils/get-value-from-id.mjs
16282 var getValueFromId = (id) => ({ item }) => {
16283 const path = id.split(".");
16284 let value = item;
16285 for (const segment of path) {
16286 if (value.hasOwnProperty(segment)) {
16287 value = value[segment];
16288 } else {
16289 value = void 0;
16290 }
16291 }
16292 return value;
16293 };
16294 var get_value_from_id_default = getValueFromId;
16295
16296 // packages/dataviews/build-module/field-types/utils/set-value-from-id.mjs
16297 var setValueFromId = (id) => ({ value }) => {
16298 const path = id.split(".");
16299 const result = {};
16300 let current = result;
16301 for (const segment of path.slice(0, -1)) {
16302 current[segment] = {};
16303 current = current[segment];
16304 }
16305 current[path.at(-1)] = value;
16306 return result;
16307 };
16308 var set_value_from_id_default = setValueFromId;
16309
16310 // packages/dataviews/build-module/field-types/email.mjs
16311 var import_i18n43 = __toESM(require_i18n(), 1);
16312
16313 // packages/dataviews/build-module/field-types/utils/render-from-elements.mjs
16314 function RenderFromElements({
16315 item,
16316 field
16317 }) {
16318 const { elements, isLoading } = useElements({
16319 elements: field.elements,
16320 getElements: field.getElements
16321 });
16322 const value = field.getValue({ item });
16323 if (isLoading) {
16324 return value;
16325 }
16326 if (elements.length === 0) {
16327 return value;
16328 }
16329 return elements?.find((element) => element.value === value)?.label || field.getValue({ item });
16330 }
16331
16332 // packages/dataviews/build-module/field-types/utils/render-default.mjs
16333 var import_jsx_runtime97 = __toESM(require_jsx_runtime(), 1);
16334 function render({
16335 item,
16336 field
16337 }) {
16338 if (field.hasElements) {
16339 return /* @__PURE__ */ (0, import_jsx_runtime97.jsx)(RenderFromElements, { item, field });
16340 }
16341 return field.getValueFormatted({ item, field });
16342 }
16343
16344 // packages/dataviews/build-module/field-types/utils/sort-text.mjs
16345 var sort_text_default = (a2, b2, direction) => {
16346 return direction === "asc" ? a2.localeCompare(b2) : b2.localeCompare(a2);
16347 };
16348
16349 // packages/dataviews/build-module/field-types/utils/is-valid-required.mjs
16350 function isValidRequired(item, field) {
16351 const value = field.getValue({ item });
16352 return ![void 0, "", null].includes(value);
16353 }
16354
16355 // packages/dataviews/build-module/field-types/utils/is-valid-min-length.mjs
16356 function isValidMinLength(item, field) {
16357 if (typeof field.isValid.minLength?.constraint !== "number") {
16358 return false;
16359 }
16360 const value = field.getValue({ item });
16361 if ([void 0, "", null].includes(value)) {
16362 return true;
16363 }
16364 return String(value).length >= field.isValid.minLength.constraint;
16365 }
16366
16367 // packages/dataviews/build-module/field-types/utils/is-valid-max-length.mjs
16368 function isValidMaxLength(item, field) {
16369 if (typeof field.isValid.maxLength?.constraint !== "number") {
16370 return false;
16371 }
16372 const value = field.getValue({ item });
16373 if ([void 0, "", null].includes(value)) {
16374 return true;
16375 }
16376 return String(value).length <= field.isValid.maxLength.constraint;
16377 }
16378
16379 // packages/dataviews/build-module/field-types/utils/is-valid-pattern.mjs
16380 function isValidPattern(item, field) {
16381 if (field.isValid.pattern?.constraint === void 0) {
16382 return true;
16383 }
16384 try {
16385 const regexp = new RegExp(field.isValid.pattern.constraint);
16386 const value = field.getValue({ item });
16387 if ([void 0, "", null].includes(value)) {
16388 return true;
16389 }
16390 return regexp.test(String(value));
16391 } catch {
16392 return false;
16393 }
16394 }
16395
16396 // packages/dataviews/build-module/field-types/utils/is-valid-elements.mjs
16397 function isValidElements(item, field) {
16398 const elements = field.elements ?? [];
16399 const validValues = elements.map((el) => el.value);
16400 if (validValues.length === 0) {
16401 return true;
16402 }
16403 const value = field.getValue({ item });
16404 return [].concat(value).every((v2) => validValues.includes(v2));
16405 }
16406
16407 // packages/dataviews/build-module/field-types/utils/get-value-formatted-default.mjs
16408 function getValueFormatted({
16409 item,
16410 field
16411 }) {
16412 return field.getValue({ item });
16413 }
16414 var get_value_formatted_default_default = getValueFormatted;
16415
16416 // packages/dataviews/build-module/field-types/email.mjs
16417 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])?)*$/;
16418 function isValidCustom(item, field) {
16419 const value = field.getValue({ item });
16420 if (![void 0, "", null].includes(value) && !emailRegex.test(value)) {
16421 return (0, import_i18n43.__)("Value must be a valid email address.");
16422 }
16423 return null;
16424 }
16425 var email_default = {
16426 type: "email",
16427 render,
16428 Edit: "email",
16429 sort: sort_text_default,
16430 enableSorting: true,
16431 enableGlobalSearch: false,
16432 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16433 validOperators: [
16434 OPERATOR_IS,
16435 OPERATOR_IS_NOT,
16436 OPERATOR_CONTAINS,
16437 OPERATOR_NOT_CONTAINS,
16438 OPERATOR_STARTS_WITH,
16439 // Multiple selection
16440 OPERATOR_IS_ANY,
16441 OPERATOR_IS_NONE,
16442 OPERATOR_IS_ALL,
16443 OPERATOR_IS_NOT_ALL
16444 ],
16445 format: {},
16446 getValueFormatted: get_value_formatted_default_default,
16447 validate: {
16448 required: isValidRequired,
16449 pattern: isValidPattern,
16450 minLength: isValidMinLength,
16451 maxLength: isValidMaxLength,
16452 elements: isValidElements,
16453 custom: isValidCustom
16454 }
16455 };
16456
16457 // packages/dataviews/build-module/field-types/integer.mjs
16458 var import_i18n44 = __toESM(require_i18n(), 1);
16459
16460 // packages/dataviews/build-module/field-types/utils/sort-number.mjs
16461 var sort_number_default = (a2, b2, direction) => {
16462 return direction === "asc" ? a2 - b2 : b2 - a2;
16463 };
16464
16465 // packages/dataviews/build-module/field-types/utils/is-valid-min.mjs
16466 function isValidMin(item, field) {
16467 if (typeof field.isValid.min?.constraint !== "number") {
16468 return false;
16469 }
16470 const value = field.getValue({ item });
16471 if ([void 0, "", null].includes(value)) {
16472 return true;
16473 }
16474 return Number(value) >= field.isValid.min.constraint;
16475 }
16476
16477 // packages/dataviews/build-module/field-types/utils/is-valid-max.mjs
16478 function isValidMax(item, field) {
16479 if (typeof field.isValid.max?.constraint !== "number") {
16480 return false;
16481 }
16482 const value = field.getValue({ item });
16483 if ([void 0, "", null].includes(value)) {
16484 return true;
16485 }
16486 return Number(value) <= field.isValid.max.constraint;
16487 }
16488
16489 // packages/dataviews/build-module/field-types/integer.mjs
16490 var format2 = {
16491 separatorThousand: ","
16492 };
16493 function getValueFormatted2({
16494 item,
16495 field
16496 }) {
16497 let value = field.getValue({ item });
16498 if (value === null || value === void 0) {
16499 return "";
16500 }
16501 value = Number(value);
16502 if (!Number.isFinite(value)) {
16503 return String(value);
16504 }
16505 let formatInteger;
16506 if (field.type !== "integer") {
16507 formatInteger = format2;
16508 } else {
16509 formatInteger = field.format;
16510 }
16511 const { separatorThousand } = formatInteger;
16512 const integerValue = Math.trunc(value);
16513 if (!separatorThousand) {
16514 return String(integerValue);
16515 }
16516 return String(integerValue).replace(
16517 /\B(?=(\d{3})+(?!\d))/g,
16518 separatorThousand
16519 );
16520 }
16521 function isValidCustom2(item, field) {
16522 const value = field.getValue({ item });
16523 if (![void 0, "", null].includes(value) && !Number.isInteger(value)) {
16524 return (0, import_i18n44.__)("Value must be an integer.");
16525 }
16526 return null;
16527 }
16528 var integer_default = {
16529 type: "integer",
16530 render,
16531 Edit: "integer",
16532 sort: sort_number_default,
16533 enableSorting: true,
16534 enableGlobalSearch: false,
16535 defaultOperators: [
16536 OPERATOR_IS,
16537 OPERATOR_IS_NOT,
16538 OPERATOR_LESS_THAN,
16539 OPERATOR_GREATER_THAN,
16540 OPERATOR_LESS_THAN_OR_EQUAL,
16541 OPERATOR_GREATER_THAN_OR_EQUAL,
16542 OPERATOR_BETWEEN
16543 ],
16544 validOperators: [
16545 // Single-selection
16546 OPERATOR_IS,
16547 OPERATOR_IS_NOT,
16548 OPERATOR_LESS_THAN,
16549 OPERATOR_GREATER_THAN,
16550 OPERATOR_LESS_THAN_OR_EQUAL,
16551 OPERATOR_GREATER_THAN_OR_EQUAL,
16552 OPERATOR_BETWEEN,
16553 // Multiple-selection
16554 OPERATOR_IS_ANY,
16555 OPERATOR_IS_NONE,
16556 OPERATOR_IS_ALL,
16557 OPERATOR_IS_NOT_ALL
16558 ],
16559 format: format2,
16560 getValueFormatted: getValueFormatted2,
16561 validate: {
16562 required: isValidRequired,
16563 min: isValidMin,
16564 max: isValidMax,
16565 elements: isValidElements,
16566 custom: isValidCustom2
16567 }
16568 };
16569
16570 // packages/dataviews/build-module/field-types/number.mjs
16571 var import_i18n45 = __toESM(require_i18n(), 1);
16572 var format3 = {
16573 separatorThousand: ",",
16574 separatorDecimal: ".",
16575 decimals: 2
16576 };
16577 function getValueFormatted3({
16578 item,
16579 field
16580 }) {
16581 let value = field.getValue({ item });
16582 if (value === null || value === void 0) {
16583 return "";
16584 }
16585 value = Number(value);
16586 if (!Number.isFinite(value)) {
16587 return String(value);
16588 }
16589 let formatNumber;
16590 if (field.type !== "number") {
16591 formatNumber = format3;
16592 } else {
16593 formatNumber = field.format;
16594 }
16595 const { separatorThousand, separatorDecimal, decimals } = formatNumber;
16596 const fixedValue = value.toFixed(decimals);
16597 const [integerPart, decimalPart] = fixedValue.split(".");
16598 const formattedInteger = separatorThousand ? integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, separatorThousand) : integerPart;
16599 return decimals === 0 ? formattedInteger : formattedInteger + separatorDecimal + decimalPart;
16600 }
16601 function isEmpty2(value) {
16602 return value === "" || value === void 0 || value === null;
16603 }
16604 function isValidCustom3(item, field) {
16605 const value = field.getValue({ item });
16606 if (!isEmpty2(value) && !Number.isFinite(value)) {
16607 return (0, import_i18n45.__)("Value must be a number.");
16608 }
16609 return null;
16610 }
16611 var number_default = {
16612 type: "number",
16613 render,
16614 Edit: "number",
16615 sort: sort_number_default,
16616 enableSorting: true,
16617 enableGlobalSearch: false,
16618 defaultOperators: [
16619 OPERATOR_IS,
16620 OPERATOR_IS_NOT,
16621 OPERATOR_LESS_THAN,
16622 OPERATOR_GREATER_THAN,
16623 OPERATOR_LESS_THAN_OR_EQUAL,
16624 OPERATOR_GREATER_THAN_OR_EQUAL,
16625 OPERATOR_BETWEEN
16626 ],
16627 validOperators: [
16628 // Single-selection
16629 OPERATOR_IS,
16630 OPERATOR_IS_NOT,
16631 OPERATOR_LESS_THAN,
16632 OPERATOR_GREATER_THAN,
16633 OPERATOR_LESS_THAN_OR_EQUAL,
16634 OPERATOR_GREATER_THAN_OR_EQUAL,
16635 OPERATOR_BETWEEN,
16636 // Multiple-selection
16637 OPERATOR_IS_ANY,
16638 OPERATOR_IS_NONE,
16639 OPERATOR_IS_ALL,
16640 OPERATOR_IS_NOT_ALL
16641 ],
16642 format: format3,
16643 getValueFormatted: getValueFormatted3,
16644 validate: {
16645 required: isValidRequired,
16646 min: isValidMin,
16647 max: isValidMax,
16648 elements: isValidElements,
16649 custom: isValidCustom3
16650 }
16651 };
16652
16653 // packages/dataviews/build-module/field-types/text.mjs
16654 var text_default = {
16655 type: "text",
16656 render,
16657 Edit: "text",
16658 sort: sort_text_default,
16659 enableSorting: true,
16660 enableGlobalSearch: false,
16661 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16662 validOperators: [
16663 // Single selection
16664 OPERATOR_IS,
16665 OPERATOR_IS_NOT,
16666 OPERATOR_CONTAINS,
16667 OPERATOR_NOT_CONTAINS,
16668 OPERATOR_STARTS_WITH,
16669 // Multiple selection
16670 OPERATOR_IS_ANY,
16671 OPERATOR_IS_NONE,
16672 OPERATOR_IS_ALL,
16673 OPERATOR_IS_NOT_ALL
16674 ],
16675 format: {},
16676 getValueFormatted: get_value_formatted_default_default,
16677 validate: {
16678 required: isValidRequired,
16679 pattern: isValidPattern,
16680 minLength: isValidMinLength,
16681 maxLength: isValidMaxLength,
16682 elements: isValidElements
16683 }
16684 };
16685
16686 // packages/dataviews/build-module/field-types/datetime.mjs
16687 var import_date7 = __toESM(require_date(), 1);
16688
16689 // packages/dataviews/build-module/field-types/utils/is-valid-date-boundary.mjs
16690 var import_date6 = __toESM(require_date(), 1);
16691 function parseDateLike(value) {
16692 if (!value) {
16693 return null;
16694 }
16695 if (!isValid(new Date(value))) {
16696 return null;
16697 }
16698 const parsed = (0, import_date6.getDate)(value);
16699 return parsed && isValid(parsed) ? parsed : null;
16700 }
16701 function validateDateLikeBoundary(item, field, boundary) {
16702 const constraint = field.isValid[boundary]?.constraint;
16703 if (typeof constraint !== "string") {
16704 return false;
16705 }
16706 const value = field.getValue({ item });
16707 const boundaryValue = Array.isArray(value) ? value[boundary === "min" ? 0 : value.length - 1] : value;
16708 if (boundaryValue === void 0 || boundaryValue === null || boundaryValue === "") {
16709 return true;
16710 }
16711 const parsedConstraint = parseDateLike(constraint);
16712 const parsedValue = parseDateLike(String(boundaryValue));
16713 return !!parsedConstraint && !!parsedValue && (boundary === "min" ? parsedValue.getTime() >= parsedConstraint.getTime() : parsedValue.getTime() <= parsedConstraint.getTime());
16714 }
16715 function isValidMinDate(item, field) {
16716 return validateDateLikeBoundary(item, field, "min");
16717 }
16718 function isValidMaxDate(item, field) {
16719 return validateDateLikeBoundary(item, field, "max");
16720 }
16721
16722 // packages/dataviews/build-module/field-types/datetime.mjs
16723 var format4 = {
16724 datetime: (0, import_date7.getSettings)().formats.datetime,
16725 weekStartsOn: (0, import_date7.getSettings)().l10n.startOfWeek
16726 };
16727 function getValueFormatted4({
16728 item,
16729 field
16730 }) {
16731 const value = field.getValue({ item });
16732 if (["", void 0, null].includes(value)) {
16733 return "";
16734 }
16735 let formatDatetime;
16736 if (field.type !== "datetime") {
16737 formatDatetime = format4;
16738 } else {
16739 formatDatetime = field.format;
16740 }
16741 return (0, import_date7.dateI18n)(formatDatetime.datetime, (0, import_date7.getDate)(value));
16742 }
16743 var sort = (a2, b2, direction) => {
16744 const timeA = new Date(a2).getTime();
16745 const timeB = new Date(b2).getTime();
16746 return direction === "asc" ? timeA - timeB : timeB - timeA;
16747 };
16748 var datetime_default = {
16749 type: "datetime",
16750 render,
16751 Edit: "datetime",
16752 sort,
16753 enableSorting: true,
16754 enableGlobalSearch: false,
16755 defaultOperators: [
16756 OPERATOR_ON,
16757 OPERATOR_NOT_ON,
16758 OPERATOR_BEFORE,
16759 OPERATOR_AFTER,
16760 OPERATOR_BEFORE_INC,
16761 OPERATOR_AFTER_INC,
16762 OPERATOR_IN_THE_PAST,
16763 OPERATOR_OVER
16764 ],
16765 validOperators: [
16766 OPERATOR_ON,
16767 OPERATOR_NOT_ON,
16768 OPERATOR_BEFORE,
16769 OPERATOR_AFTER,
16770 OPERATOR_BEFORE_INC,
16771 OPERATOR_AFTER_INC,
16772 OPERATOR_IN_THE_PAST,
16773 OPERATOR_OVER
16774 ],
16775 format: format4,
16776 getValueFormatted: getValueFormatted4,
16777 validate: {
16778 required: isValidRequired,
16779 elements: isValidElements,
16780 min: isValidMinDate,
16781 max: isValidMaxDate
16782 }
16783 };
16784
16785 // packages/dataviews/build-module/field-types/date.mjs
16786 var import_date8 = __toESM(require_date(), 1);
16787 var format5 = {
16788 date: (0, import_date8.getSettings)().formats.date,
16789 weekStartsOn: (0, import_date8.getSettings)().l10n.startOfWeek
16790 };
16791 function getValueFormatted5({
16792 item,
16793 field
16794 }) {
16795 const value = field.getValue({ item });
16796 if (["", void 0, null].includes(value)) {
16797 return "";
16798 }
16799 let formatDate2;
16800 if (field.type !== "date") {
16801 formatDate2 = format5;
16802 } else {
16803 formatDate2 = field.format;
16804 }
16805 return (0, import_date8.dateI18n)(formatDate2.date, (0, import_date8.getDate)(value));
16806 }
16807 var sort2 = (a2, b2, direction) => {
16808 const timeA = new Date(a2).getTime();
16809 const timeB = new Date(b2).getTime();
16810 return direction === "asc" ? timeA - timeB : timeB - timeA;
16811 };
16812 var date_default = {
16813 type: "date",
16814 render,
16815 Edit: "date",
16816 sort: sort2,
16817 enableSorting: true,
16818 enableGlobalSearch: false,
16819 defaultOperators: [
16820 OPERATOR_ON,
16821 OPERATOR_NOT_ON,
16822 OPERATOR_BEFORE,
16823 OPERATOR_AFTER,
16824 OPERATOR_BEFORE_INC,
16825 OPERATOR_AFTER_INC,
16826 OPERATOR_IN_THE_PAST,
16827 OPERATOR_OVER,
16828 OPERATOR_BETWEEN
16829 ],
16830 validOperators: [
16831 OPERATOR_ON,
16832 OPERATOR_NOT_ON,
16833 OPERATOR_BEFORE,
16834 OPERATOR_AFTER,
16835 OPERATOR_BEFORE_INC,
16836 OPERATOR_AFTER_INC,
16837 OPERATOR_IN_THE_PAST,
16838 OPERATOR_OVER,
16839 OPERATOR_BETWEEN
16840 ],
16841 format: format5,
16842 getValueFormatted: getValueFormatted5,
16843 validate: {
16844 required: isValidRequired,
16845 elements: isValidElements,
16846 min: isValidMinDate,
16847 max: isValidMaxDate
16848 }
16849 };
16850
16851 // packages/dataviews/build-module/field-types/boolean.mjs
16852 var import_i18n46 = __toESM(require_i18n(), 1);
16853
16854 // packages/dataviews/build-module/field-types/utils/is-valid-required-for-bool.mjs
16855 function isValidRequiredForBool(item, field) {
16856 const value = field.getValue({ item });
16857 return value === true;
16858 }
16859
16860 // packages/dataviews/build-module/field-types/boolean.mjs
16861 function getValueFormatted6({
16862 item,
16863 field
16864 }) {
16865 const value = field.getValue({ item });
16866 if (value === true) {
16867 return (0, import_i18n46.__)("True");
16868 }
16869 if (value === false) {
16870 return (0, import_i18n46.__)("False");
16871 }
16872 return "";
16873 }
16874 function isValidCustom4(item, field) {
16875 const value = field.getValue({ item });
16876 if (![void 0, "", null].includes(value) && ![true, false].includes(value)) {
16877 return (0, import_i18n46.__)("Value must be true, false, or undefined");
16878 }
16879 return null;
16880 }
16881 var sort3 = (a2, b2, direction) => {
16882 const boolA = Boolean(a2);
16883 const boolB = Boolean(b2);
16884 if (boolA === boolB) {
16885 return 0;
16886 }
16887 if (direction === "asc") {
16888 return boolA ? 1 : -1;
16889 }
16890 return boolA ? -1 : 1;
16891 };
16892 var boolean_default = {
16893 type: "boolean",
16894 render,
16895 Edit: "checkbox",
16896 sort: sort3,
16897 validate: {
16898 required: isValidRequiredForBool,
16899 elements: isValidElements,
16900 custom: isValidCustom4
16901 },
16902 enableSorting: true,
16903 enableGlobalSearch: false,
16904 defaultOperators: [OPERATOR_IS, OPERATOR_IS_NOT],
16905 validOperators: [OPERATOR_IS, OPERATOR_IS_NOT],
16906 format: {},
16907 getValueFormatted: getValueFormatted6
16908 };
16909
16910 // packages/dataviews/build-module/field-types/media.mjs
16911 var media_default = {
16912 type: "media",
16913 render: () => null,
16914 Edit: null,
16915 sort: () => 0,
16916 enableSorting: false,
16917 enableGlobalSearch: false,
16918 defaultOperators: [],
16919 validOperators: [],
16920 format: {},
16921 getValueFormatted: get_value_formatted_default_default,
16922 // cannot validate any constraint, so
16923 // the only available validation for the field author
16924 // would be providing a custom validator.
16925 validate: {}
16926 };
16927
16928 // packages/dataviews/build-module/field-types/array.mjs
16929 var import_i18n47 = __toESM(require_i18n(), 1);
16930
16931 // packages/dataviews/build-module/field-types/utils/is-valid-required-for-array.mjs
16932 function isValidRequiredForArray(item, field) {
16933 const value = field.getValue({ item });
16934 return Array.isArray(value) && value.length > 0 && value.every(
16935 (element) => ![void 0, "", null].includes(element)
16936 );
16937 }
16938
16939 // packages/dataviews/build-module/field-types/array.mjs
16940 function getValueFormatted7({
16941 item,
16942 field
16943 }) {
16944 const value = field.getValue({ item });
16945 const arr = Array.isArray(value) ? value : [];
16946 return arr.join(", ");
16947 }
16948 function render2({ item, field }) {
16949 return getValueFormatted7({ item, field });
16950 }
16951 function isValidCustom5(item, field) {
16952 const value = field.getValue({ item });
16953 if (![void 0, "", null].includes(value) && !Array.isArray(value)) {
16954 return (0, import_i18n47.__)("Value must be an array.");
16955 }
16956 if (!value.every((v2) => typeof v2 === "string")) {
16957 return (0, import_i18n47.__)("Every value must be a string.");
16958 }
16959 return null;
16960 }
16961 var sort4 = (a2, b2, direction) => {
16962 const arrA = Array.isArray(a2) ? a2 : [];
16963 const arrB = Array.isArray(b2) ? b2 : [];
16964 if (arrA.length !== arrB.length) {
16965 return direction === "asc" ? arrA.length - arrB.length : arrB.length - arrA.length;
16966 }
16967 const joinedA = arrA.join(",");
16968 const joinedB = arrB.join(",");
16969 return direction === "asc" ? joinedA.localeCompare(joinedB) : joinedB.localeCompare(joinedA);
16970 };
16971 var array_default = {
16972 type: "array",
16973 render: render2,
16974 Edit: "array",
16975 sort: sort4,
16976 enableSorting: true,
16977 enableGlobalSearch: false,
16978 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16979 validOperators: [
16980 OPERATOR_IS_ANY,
16981 OPERATOR_IS_NONE,
16982 OPERATOR_IS_ALL,
16983 OPERATOR_IS_NOT_ALL
16984 ],
16985 format: {},
16986 getValueFormatted: getValueFormatted7,
16987 validate: {
16988 required: isValidRequiredForArray,
16989 elements: isValidElements,
16990 custom: isValidCustom5
16991 }
16992 };
16993
16994 // packages/dataviews/build-module/field-types/password.mjs
16995 function getValueFormatted8({
16996 item,
16997 field
16998 }) {
16999 return field.getValue({ item }) ? "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022" : "";
17000 }
17001 var password_default = {
17002 type: "password",
17003 render,
17004 Edit: "password",
17005 sort: () => 0,
17006 // Passwords should not be sortable for security reasons
17007 enableSorting: false,
17008 enableGlobalSearch: false,
17009 defaultOperators: [],
17010 validOperators: [],
17011 format: {},
17012 getValueFormatted: getValueFormatted8,
17013 validate: {
17014 required: isValidRequired,
17015 pattern: isValidPattern,
17016 minLength: isValidMinLength,
17017 maxLength: isValidMaxLength,
17018 elements: isValidElements
17019 }
17020 };
17021
17022 // packages/dataviews/build-module/field-types/telephone.mjs
17023 var telephone_default = {
17024 type: "telephone",
17025 render,
17026 Edit: "telephone",
17027 sort: sort_text_default,
17028 enableSorting: true,
17029 enableGlobalSearch: false,
17030 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
17031 validOperators: [
17032 OPERATOR_IS,
17033 OPERATOR_IS_NOT,
17034 OPERATOR_CONTAINS,
17035 OPERATOR_NOT_CONTAINS,
17036 OPERATOR_STARTS_WITH,
17037 // Multiple selection
17038 OPERATOR_IS_ANY,
17039 OPERATOR_IS_NONE,
17040 OPERATOR_IS_ALL,
17041 OPERATOR_IS_NOT_ALL
17042 ],
17043 format: {},
17044 getValueFormatted: get_value_formatted_default_default,
17045 validate: {
17046 required: isValidRequired,
17047 pattern: isValidPattern,
17048 minLength: isValidMinLength,
17049 maxLength: isValidMaxLength,
17050 elements: isValidElements
17051 }
17052 };
17053
17054 // packages/dataviews/build-module/field-types/color.mjs
17055 var import_i18n48 = __toESM(require_i18n(), 1);
17056 var import_jsx_runtime98 = __toESM(require_jsx_runtime(), 1);
17057 function render3({ item, field }) {
17058 if (field.hasElements) {
17059 return /* @__PURE__ */ (0, import_jsx_runtime98.jsx)(RenderFromElements, { item, field });
17060 }
17061 const value = get_value_formatted_default_default({ item, field });
17062 if (!value || !w(value).isValid()) {
17063 return value;
17064 }
17065 return /* @__PURE__ */ (0, import_jsx_runtime98.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "8px" }, children: [
17066 /* @__PURE__ */ (0, import_jsx_runtime98.jsx)(
17067 "div",
17068 {
17069 style: {
17070 width: "16px",
17071 height: "16px",
17072 borderRadius: "50%",
17073 backgroundColor: value,
17074 border: "1px solid #ddd",
17075 flexShrink: 0
17076 }
17077 }
17078 ),
17079 /* @__PURE__ */ (0, import_jsx_runtime98.jsx)("span", { children: value })
17080 ] });
17081 }
17082 function isValidCustom6(item, field) {
17083 const value = field.getValue({ item });
17084 if (![void 0, "", null].includes(value) && !w(value).isValid()) {
17085 return (0, import_i18n48.__)("Value must be a valid color.");
17086 }
17087 return null;
17088 }
17089 var sort5 = (a2, b2, direction) => {
17090 const colorA = w(a2);
17091 const colorB = w(b2);
17092 if (!colorA.isValid() && !colorB.isValid()) {
17093 return 0;
17094 }
17095 if (!colorA.isValid()) {
17096 return direction === "asc" ? 1 : -1;
17097 }
17098 if (!colorB.isValid()) {
17099 return direction === "asc" ? -1 : 1;
17100 }
17101 const hslA = colorA.toHsl();
17102 const hslB = colorB.toHsl();
17103 if (hslA.h !== hslB.h) {
17104 return direction === "asc" ? hslA.h - hslB.h : hslB.h - hslA.h;
17105 }
17106 if (hslA.s !== hslB.s) {
17107 return direction === "asc" ? hslA.s - hslB.s : hslB.s - hslA.s;
17108 }
17109 return direction === "asc" ? hslA.l - hslB.l : hslB.l - hslA.l;
17110 };
17111 var color_default = {
17112 type: "color",
17113 render: render3,
17114 Edit: "color",
17115 sort: sort5,
17116 enableSorting: true,
17117 enableGlobalSearch: false,
17118 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
17119 validOperators: [
17120 OPERATOR_IS,
17121 OPERATOR_IS_NOT,
17122 OPERATOR_IS_ANY,
17123 OPERATOR_IS_NONE
17124 ],
17125 format: {},
17126 getValueFormatted: get_value_formatted_default_default,
17127 validate: {
17128 required: isValidRequired,
17129 elements: isValidElements,
17130 custom: isValidCustom6
17131 }
17132 };
17133
17134 // packages/dataviews/build-module/field-types/url.mjs
17135 var url_default = {
17136 type: "url",
17137 render,
17138 Edit: "url",
17139 sort: sort_text_default,
17140 enableSorting: true,
17141 enableGlobalSearch: false,
17142 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
17143 validOperators: [
17144 OPERATOR_IS,
17145 OPERATOR_IS_NOT,
17146 OPERATOR_CONTAINS,
17147 OPERATOR_NOT_CONTAINS,
17148 OPERATOR_STARTS_WITH,
17149 // Multiple selection
17150 OPERATOR_IS_ANY,
17151 OPERATOR_IS_NONE,
17152 OPERATOR_IS_ALL,
17153 OPERATOR_IS_NOT_ALL
17154 ],
17155 format: {},
17156 getValueFormatted: get_value_formatted_default_default,
17157 validate: {
17158 required: isValidRequired,
17159 pattern: isValidPattern,
17160 minLength: isValidMinLength,
17161 maxLength: isValidMaxLength,
17162 elements: isValidElements
17163 }
17164 };
17165
17166 // packages/dataviews/build-module/field-types/no-type.mjs
17167 var sort6 = (a2, b2, direction) => {
17168 if (typeof a2 === "number" && typeof b2 === "number") {
17169 return sort_number_default(a2, b2, direction);
17170 }
17171 return sort_text_default(a2, b2, direction);
17172 };
17173 var no_type_default = {
17174 // type: no type for this one
17175 render,
17176 Edit: null,
17177 sort: sort6,
17178 enableSorting: true,
17179 enableGlobalSearch: false,
17180 defaultOperators: [OPERATOR_IS, OPERATOR_IS_NOT],
17181 validOperators: getAllOperatorNames(),
17182 format: {},
17183 getValueFormatted: get_value_formatted_default_default,
17184 validate: {
17185 required: isValidRequired,
17186 elements: isValidElements
17187 }
17188 };
17189
17190 // packages/dataviews/build-module/field-types/utils/get-is-valid.mjs
17191 function supportsNumericRangeConstraint(type) {
17192 return type === "integer" || type === "number";
17193 }
17194 function supportsDateRangeConstraint(type) {
17195 return type === "date" || type === "datetime";
17196 }
17197 function normalizeRangeRule(value, fieldType, key) {
17198 const validator = fieldType.validate[key];
17199 if (validator && (typeof value === "number" && supportsNumericRangeConstraint(fieldType.type) || typeof value === "string" && supportsDateRangeConstraint(fieldType.type))) {
17200 return { constraint: value, validate: validator };
17201 }
17202 return void 0;
17203 }
17204 function getIsValid(field, fieldType) {
17205 const rules = field.isValid;
17206 let required;
17207 if (rules?.required === true && fieldType.validate.required !== void 0) {
17208 required = {
17209 constraint: true,
17210 validate: fieldType.validate.required
17211 };
17212 }
17213 let elements;
17214 if ((rules?.elements === true || // elements is enabled unless the field opts-out
17215 rules?.elements === void 0 && (!!field.elements || !!field.getElements)) && fieldType.validate.elements !== void 0) {
17216 elements = {
17217 constraint: true,
17218 validate: fieldType.validate.elements
17219 };
17220 }
17221 const min = normalizeRangeRule(rules?.min, fieldType, "min");
17222 const max = normalizeRangeRule(rules?.max, fieldType, "max");
17223 const minLengthValue = rules?.minLength;
17224 let minLength;
17225 if (typeof minLengthValue === "number" && fieldType.validate.minLength !== void 0) {
17226 minLength = {
17227 constraint: minLengthValue,
17228 validate: fieldType.validate.minLength
17229 };
17230 }
17231 const maxLengthValue = rules?.maxLength;
17232 let maxLength;
17233 if (typeof maxLengthValue === "number" && fieldType.validate.maxLength !== void 0) {
17234 maxLength = {
17235 constraint: maxLengthValue,
17236 validate: fieldType.validate.maxLength
17237 };
17238 }
17239 const patternValue = rules?.pattern;
17240 let pattern;
17241 if (patternValue !== void 0 && fieldType.validate.pattern !== void 0) {
17242 pattern = {
17243 constraint: patternValue,
17244 validate: fieldType.validate.pattern
17245 };
17246 }
17247 const custom = rules?.custom ?? fieldType.validate.custom;
17248 return {
17249 required,
17250 elements,
17251 min,
17252 max,
17253 minLength,
17254 maxLength,
17255 pattern,
17256 custom
17257 };
17258 }
17259
17260 // packages/dataviews/build-module/field-types/utils/get-filter.mjs
17261 function getFilter(fieldType) {
17262 return fieldType.validOperators.reduce((accumulator, operator) => {
17263 const operatorObj = getOperatorByName(operator);
17264 if (operatorObj?.filter) {
17265 accumulator[operator] = operatorObj.filter;
17266 }
17267 return accumulator;
17268 }, {});
17269 }
17270
17271 // packages/dataviews/build-module/field-types/utils/get-format.mjs
17272 function getFormat(field, fieldType) {
17273 return {
17274 ...fieldType.format,
17275 ...field.format
17276 };
17277 }
17278 var get_format_default = getFormat;
17279
17280 // packages/dataviews/build-module/field-types/index.mjs
17281 function getFieldTypeByName(type) {
17282 const found = [
17283 email_default,
17284 integer_default,
17285 number_default,
17286 text_default,
17287 datetime_default,
17288 date_default,
17289 boolean_default,
17290 media_default,
17291 array_default,
17292 password_default,
17293 telephone_default,
17294 color_default,
17295 url_default
17296 ].find((fieldType) => fieldType?.type === type);
17297 if (!!found) {
17298 return found;
17299 }
17300 return no_type_default;
17301 }
17302 function normalizeFields(fields) {
17303 return fields.map((field) => {
17304 const fieldType = getFieldTypeByName(field.type);
17305 const getValue = field.getValue || get_value_from_id_default(field.id);
17306 const sort7 = function(a2, b2, direction) {
17307 const aValue = getValue({ item: a2 });
17308 const bValue = getValue({ item: b2 });
17309 return field.sort ? field.sort(aValue, bValue, direction) : fieldType.sort(aValue, bValue, direction);
17310 };
17311 return {
17312 id: field.id,
17313 label: field.label || field.id,
17314 header: field.header || field.label || field.id,
17315 description: field.description,
17316 placeholder: field.placeholder,
17317 getValue,
17318 setValue: field.setValue || set_value_from_id_default(field.id),
17319 elements: field.elements,
17320 getElements: field.getElements,
17321 hasElements: hasElements(field),
17322 isVisible: field.isVisible,
17323 isDisabled: typeof field.isDisabled === "function" ? field.isDisabled : () => !!field.isDisabled,
17324 enableHiding: field.enableHiding ?? true,
17325 readOnly: field.readOnly ?? false,
17326 // The type provides defaults for the following props
17327 type: fieldType.type,
17328 render: field.render ?? fieldType.render,
17329 Edit: getControl(field, fieldType.Edit),
17330 sort: sort7,
17331 enableSorting: field.enableSorting ?? fieldType.enableSorting,
17332 enableGlobalSearch: field.enableGlobalSearch ?? fieldType.enableGlobalSearch,
17333 isValid: getIsValid(field, fieldType),
17334 filterBy: get_filter_by_default(
17335 field,
17336 fieldType.defaultOperators,
17337 fieldType.validOperators
17338 ),
17339 filter: getFilter(fieldType),
17340 format: get_format_default(field, fieldType),
17341 getValueFormatted: field.getValueFormatted ?? fieldType.getValueFormatted
17342 };
17343 });
17344 }
17345
17346 // packages/dataviews/build-module/hooks/use-data.mjs
17347 var import_element55 = __toESM(require_element(), 1);
17348 function useData({
17349 view,
17350 data: shownData,
17351 getItemId,
17352 isLoading,
17353 paginationInfo,
17354 selection
17355 }) {
17356 const isInfiniteScrollEnabled = view.infiniteScrollEnabled;
17357 const [hasInitiallyLoaded, setHasInitiallyLoaded] = (0, import_element55.useState)(
17358 !isLoading
17359 );
17360 (0, import_element55.useEffect)(() => {
17361 if (!isLoading) {
17362 setHasInitiallyLoaded(true);
17363 }
17364 }, [isLoading]);
17365 const previousDataRef = (0, import_element55.useRef)(shownData);
17366 const previousPaginationInfoRef = (0, import_element55.useRef)(paginationInfo);
17367 (0, import_element55.useEffect)(() => {
17368 if (!isLoading) {
17369 previousDataRef.current = shownData;
17370 previousPaginationInfoRef.current = paginationInfo;
17371 }
17372 }, [shownData, isLoading, paginationInfo]);
17373 const [visibleEntries, setVisibleEntries] = (0, import_element55.useState)([]);
17374 const positionMapRef = (0, import_element55.useRef)(/* @__PURE__ */ new Map());
17375 const allLoadedRecordsRef = (0, import_element55.useRef)([]);
17376 const prevViewParamsRef = (0, import_element55.useRef)({
17377 search: void 0,
17378 filters: void 0,
17379 perPage: void 0
17380 });
17381 const scrollDirectionRef = (0, import_element55.useRef)(void 0);
17382 const prevStartPositionRef = (0, import_element55.useRef)(void 0);
17383 const hasInitializedRef = (0, import_element55.useRef)(false);
17384 const allLoadedRecords = (0, import_element55.useMemo)(() => {
17385 if (view.startPosition !== void 0 && prevStartPositionRef.current !== void 0) {
17386 if (view.startPosition < prevStartPositionRef.current) {
17387 scrollDirectionRef.current = "up";
17388 } else if (view.startPosition > prevStartPositionRef.current) {
17389 scrollDirectionRef.current = "down";
17390 }
17391 }
17392 prevStartPositionRef.current = view.startPosition;
17393 const currentFiltersKey = JSON.stringify(view.filters ?? []);
17394 const prevFiltersKey = prevViewParamsRef.current.filters;
17395 const shouldReset = !hasInitializedRef.current || !view.infiniteScrollEnabled || view.search !== prevViewParamsRef.current.search || currentFiltersKey !== prevFiltersKey || view.perPage !== prevViewParamsRef.current.perPage;
17396 hasInitializedRef.current = true;
17397 prevViewParamsRef.current = {
17398 search: view.search,
17399 filters: currentFiltersKey,
17400 perPage: view.perPage
17401 };
17402 if (shouldReset) {
17403 positionMapRef.current.clear();
17404 scrollDirectionRef.current = void 0;
17405 const startPosition = view.search ? 1 : view.startPosition ?? 1;
17406 const records = shownData.map((record, index) => {
17407 const position = startPosition + index;
17408 positionMapRef.current.set(getItemId(record), position);
17409 return {
17410 ...record,
17411 position
17412 };
17413 });
17414 allLoadedRecordsRef.current = records;
17415 return records;
17416 }
17417 const prev = allLoadedRecordsRef.current;
17418 const shownDataIds = new Set(shownData.map(getItemId));
17419 const scrollDirection = scrollDirectionRef.current;
17420 const basePosition = view.search ? 1 : view.startPosition ?? 1;
17421 const newRecords = shownData.map((record, index) => {
17422 const itemId = getItemId(record);
17423 const position = view.infiniteScrollEnabled ? basePosition + index : void 0;
17424 if (position !== void 0) {
17425 positionMapRef.current.set(itemId, position);
17426 }
17427 return {
17428 ...record,
17429 position
17430 };
17431 });
17432 if (newRecords.length === 0) {
17433 return prev;
17434 }
17435 const prevWithoutDuplicates = prev.filter(
17436 (record) => !shownDataIds.has(getItemId(record))
17437 );
17438 const allRecords = scrollDirection === "up" ? [...newRecords, ...prevWithoutDuplicates] : [...prevWithoutDuplicates, ...newRecords];
17439 allRecords.sort((a2, b2) => {
17440 const posA = a2.position;
17441 const posB = b2.position;
17442 return posA - posB;
17443 });
17444 let result = allRecords;
17445 if (visibleEntries.length > 0) {
17446 const visibleMin = Math.min(...visibleEntries);
17447 const visibleMax = Math.max(...visibleEntries);
17448 const buffer = 20;
17449 const recordPositions = allRecords.map(
17450 (r3) => r3.position
17451 );
17452 const minRecordPos = Math.min(...recordPositions);
17453 const maxRecordPos = Math.max(...recordPositions);
17454 const hasOverlap = !(maxRecordPos < visibleMin - buffer || minRecordPos > visibleMax + buffer);
17455 if (hasOverlap) {
17456 result = allRecords.filter((record) => {
17457 const itemId = getItemId(record);
17458 const isSelected2 = selection?.includes(itemId);
17459 if (isSelected2) {
17460 return true;
17461 }
17462 const itemPosition = record.position;
17463 if (scrollDirection === "up") {
17464 return itemPosition <= visibleMax + buffer;
17465 } else if (scrollDirection === "down") {
17466 return itemPosition >= visibleMin - buffer;
17467 }
17468 return itemPosition >= visibleMin - buffer && itemPosition <= visibleMax + buffer;
17469 });
17470 }
17471 }
17472 allLoadedRecordsRef.current = result;
17473 return result;
17474 }, [
17475 shownData,
17476 view.search,
17477 view.filters,
17478 view.perPage,
17479 view.startPosition,
17480 view.infiniteScrollEnabled,
17481 visibleEntries,
17482 selection,
17483 getItemId
17484 ]);
17485 if (!isInfiniteScrollEnabled) {
17486 const dataToReturn = isLoading && previousDataRef.current?.length ? previousDataRef.current : shownData;
17487 return {
17488 data: dataToReturn.map((item) => ({
17489 ...item,
17490 position: void 0
17491 })),
17492 paginationInfo: isLoading && previousDataRef.current?.length ? previousPaginationInfoRef.current : paginationInfo,
17493 hasInitiallyLoaded,
17494 setVisibleEntries: void 0
17495 };
17496 }
17497 return {
17498 data: allLoadedRecords,
17499 paginationInfo,
17500 hasInitiallyLoaded,
17501 setVisibleEntries
17502 };
17503 }
17504
17505 // packages/dataviews/build-module/hooks/use-infinite-scroll.mjs
17506 var import_element56 = __toESM(require_element(), 1);
17507 var import_compose11 = __toESM(require_compose(), 1);
17508 function captureAnchorElement(container, anchorElementRef, direction) {
17509 const containerRect = container.getBoundingClientRect();
17510 const centerY = containerRect.top + containerRect.height / 2;
17511 const items = Array.from(container.querySelectorAll("[aria-posinset]"));
17512 if (items.length === 0) {
17513 return false;
17514 }
17515 const bestAnchor = items.reduce((best, item) => {
17516 const itemRect = item.getBoundingClientRect();
17517 const itemCenterY = itemRect.top + itemRect.height / 2;
17518 const distance = Math.abs(itemCenterY - centerY);
17519 const bestRect = best.getBoundingClientRect();
17520 const bestCenterY = bestRect.top + bestRect.height / 2;
17521 const bestDistance = Math.abs(bestCenterY - centerY);
17522 return distance < bestDistance ? item : best;
17523 });
17524 const posinset = Number(bestAnchor.getAttribute("aria-posinset"));
17525 const anchorRect = bestAnchor.getBoundingClientRect();
17526 anchorElementRef.current = {
17527 posinset,
17528 viewportOffset: anchorRect.top - containerRect.top,
17529 direction
17530 };
17531 return true;
17532 }
17533 function useInfiniteScroll({
17534 view,
17535 onChangeView,
17536 isLoading,
17537 paginationInfo,
17538 containerRef,
17539 setVisibleEntries
17540 }) {
17541 const anchorElementRef = (0, import_element56.useRef)(null);
17542 const viewRef = (0, import_element56.useRef)(view);
17543 const isLoadingRef = (0, import_element56.useRef)(isLoading);
17544 const onChangeViewRef = (0, import_element56.useRef)(onChangeView);
17545 const totalItemsRef = (0, import_element56.useRef)(paginationInfo.totalItems);
17546 (0, import_element56.useLayoutEffect)(() => {
17547 viewRef.current = view;
17548 isLoadingRef.current = isLoading;
17549 onChangeViewRef.current = onChangeView;
17550 totalItemsRef.current = paginationInfo.totalItems;
17551 }, [view, isLoading, onChangeView, paginationInfo.totalItems]);
17552 const intersectionObserverCallback = (0, import_element56.useCallback)(
17553 (entries) => {
17554 if (!setVisibleEntries) {
17555 return;
17556 }
17557 setVisibleEntries((prev) => {
17558 const newVisibleEntries = new Set(prev);
17559 let hasChanged = false;
17560 entries.forEach((entry) => {
17561 const posInSet = Number(
17562 entry.target?.attributes?.getNamedItem(
17563 "aria-posinset"
17564 )?.value
17565 );
17566 if (isNaN(posInSet)) {
17567 return;
17568 }
17569 if (entry.isIntersecting) {
17570 if (!newVisibleEntries.has(posInSet)) {
17571 newVisibleEntries.add(posInSet);
17572 hasChanged = true;
17573 }
17574 } else if (newVisibleEntries.has(posInSet)) {
17575 newVisibleEntries.delete(posInSet);
17576 hasChanged = true;
17577 }
17578 });
17579 return hasChanged ? Array.from(newVisibleEntries).sort() : prev;
17580 });
17581 },
17582 [setVisibleEntries]
17583 );
17584 (0, import_element56.useLayoutEffect)(() => {
17585 const container = containerRef.current;
17586 const anchor = anchorElementRef.current;
17587 if (!container || !view.infiniteScrollEnabled || !anchor || isLoading) {
17588 return;
17589 }
17590 const anchorElement = container.querySelector(
17591 `[aria-posinset="${anchor.posinset}"]`
17592 );
17593 if (anchorElement) {
17594 const containerRect = container.getBoundingClientRect();
17595 const anchorRect = anchorElement.getBoundingClientRect();
17596 const currentOffset = anchorRect.top - containerRect.top;
17597 const scrollAdjustment = currentOffset - anchor.viewportOffset;
17598 if (Math.abs(scrollAdjustment) > 1) {
17599 container.scrollTop += scrollAdjustment;
17600 }
17601 }
17602 anchorElementRef.current = null;
17603 }, [containerRef, isLoading, view.infiniteScrollEnabled]);
17604 const intersectionObserverRef = (0, import_element56.useRef)(
17605 null
17606 );
17607 (0, import_element56.useEffect)(() => {
17608 if (!view.infiniteScrollEnabled || !intersectionObserverCallback) {
17609 if (intersectionObserverRef.current) {
17610 intersectionObserverRef.current.disconnect();
17611 intersectionObserverRef.current = null;
17612 }
17613 return;
17614 }
17615 intersectionObserverRef.current = new IntersectionObserver(
17616 intersectionObserverCallback,
17617 { root: null, rootMargin: "0px", threshold: 0.1 }
17618 );
17619 return () => {
17620 if (intersectionObserverRef.current) {
17621 intersectionObserverRef.current.disconnect();
17622 intersectionObserverRef.current = null;
17623 }
17624 };
17625 }, [view.infiniteScrollEnabled, intersectionObserverCallback]);
17626 (0, import_element56.useEffect)(() => {
17627 if (!view.infiniteScrollEnabled || !containerRef.current) {
17628 return;
17629 }
17630 let lastScrollTop = 0;
17631 const BOTTOM_THRESHOLD = 600;
17632 const TOP_THRESHOLD = 800;
17633 const handleScroll = (0, import_compose11.throttle)((event) => {
17634 const currentView = viewRef.current;
17635 const totalItems = totalItemsRef.current;
17636 const target = event.target;
17637 const scrollTop = target.scrollTop;
17638 const scrollHeight = target.scrollHeight;
17639 const clientHeight = target.clientHeight;
17640 const scrollDirection = scrollTop > lastScrollTop ? "down" : "up";
17641 lastScrollTop = scrollTop;
17642 if (isLoadingRef.current) {
17643 return;
17644 }
17645 const currentStartPosition = currentView.startPosition || 1;
17646 const batchSize = currentView.perPage || 10;
17647 const currentEndPosition = Math.min(
17648 currentStartPosition + batchSize,
17649 totalItems
17650 );
17651 if (scrollDirection === "down" && scrollTop + clientHeight >= scrollHeight - BOTTOM_THRESHOLD) {
17652 if (currentEndPosition < totalItems) {
17653 const newStartPosition = currentEndPosition;
17654 captureAnchorElement(target, anchorElementRef, "down");
17655 onChangeViewRef.current({
17656 ...currentView,
17657 startPosition: newStartPosition
17658 });
17659 }
17660 }
17661 if (scrollDirection === "up" && scrollTop <= TOP_THRESHOLD) {
17662 if (currentStartPosition > 1) {
17663 const calculatedStartPosition = currentStartPosition - batchSize;
17664 const newStartPosition = calculatedStartPosition < 6 ? 1 : calculatedStartPosition;
17665 captureAnchorElement(target, anchorElementRef, "up");
17666 onChangeViewRef.current({
17667 ...currentView,
17668 startPosition: newStartPosition
17669 });
17670 }
17671 }
17672 }, 50);
17673 const container = containerRef.current;
17674 container.addEventListener("scroll", handleScroll);
17675 return () => {
17676 container.removeEventListener("scroll", handleScroll);
17677 handleScroll.cancel();
17678 };
17679 }, [containerRef, view.infiniteScrollEnabled]);
17680 return {
17681 intersectionObserver: intersectionObserverRef.current
17682 };
17683 }
17684
17685 // packages/dataviews/build-module/dataviews-picker/index.mjs
17686 var import_element57 = __toESM(require_element(), 1);
17687 var import_compose12 = __toESM(require_compose(), 1);
17688 var import_jsx_runtime99 = __toESM(require_jsx_runtime(), 1);
17689 var isItemClickable = () => false;
17690 var dataViewsPickerLayouts = VIEW_LAYOUTS.filter(
17691 (viewLayout) => viewLayout.isPicker
17692 );
17693 var defaultGetItemId = (item) => item.id;
17694 var EMPTY_ARRAY5 = [];
17695 var DEFAULT_PICKER_LAYOUTS = {
17696 pickerGrid: true,
17697 pickerTable: true
17698 };
17699 function DefaultUI({
17700 search = true,
17701 searchLabel = void 0
17702 }) {
17703 const { view } = (0, import_element57.useContext)(dataviews_context_default);
17704 const isInfiniteScroll = view.infiniteScrollEnabled;
17705 return /* @__PURE__ */ (0, import_jsx_runtime99.jsxs)(import_jsx_runtime99.Fragment, { children: [
17706 /* @__PURE__ */ (0, import_jsx_runtime99.jsxs)(
17707 Stack,
17708 {
17709 direction: "row",
17710 align: "top",
17711 justify: "space-between",
17712 className: clsx_default("dataviews__view-actions", {
17713 "dataviews__view-actions--infinite-scroll": isInfiniteScroll
17714 }),
17715 gap: "xs",
17716 children: [
17717 /* @__PURE__ */ (0, import_jsx_runtime99.jsxs)(
17718 Stack,
17719 {
17720 direction: "row",
17721 gap: "sm",
17722 justify: "start",
17723 className: "dataviews__search",
17724 children: [
17725 search && /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(dataviews_search_default, { label: searchLabel }),
17726 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(toggle_default, {})
17727 ]
17728 }
17729 ),
17730 /* @__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, {}) })
17731 ]
17732 }
17733 ),
17734 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(filters_toggled_default, { className: "dataviews-filters__container" }),
17735 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(DataViewsLayout, {}),
17736 /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(DataViewsPickerFooter, {})
17737 ] });
17738 }
17739 function DataViewsPicker({
17740 view,
17741 onChangeView,
17742 fields,
17743 search = true,
17744 searchLabel = void 0,
17745 actions = EMPTY_ARRAY5,
17746 data,
17747 getItemId = defaultGetItemId,
17748 isLoading = false,
17749 paginationInfo,
17750 defaultLayouts: defaultLayoutsProperty = DEFAULT_PICKER_LAYOUTS,
17751 selection,
17752 onChangeSelection,
17753 children,
17754 config = { perPageSizes: [10, 20, 50, 100] },
17755 itemListLabel,
17756 empty,
17757 onReset
17758 }) {
17759 const { data: displayData, setVisibleEntries } = useData({
17760 view,
17761 data,
17762 getItemId,
17763 selection,
17764 paginationInfo
17765 });
17766 const containerRef = (0, import_element57.useRef)(null);
17767 const [containerWidth, setContainerWidth] = (0, import_element57.useState)(0);
17768 const resizeObserverRef = (0, import_compose12.useResizeObserver)(
17769 (resizeObserverEntries) => {
17770 setContainerWidth(
17771 resizeObserverEntries[0].borderBoxSize[0].inlineSize
17772 );
17773 },
17774 { box: "border-box" }
17775 );
17776 const [openedFilter, setOpenedFilter] = (0, import_element57.useState)(null);
17777 function setSelectionWithChange(value) {
17778 const newValue = typeof value === "function" ? value(selection) : value;
17779 if (onChangeSelection) {
17780 onChangeSelection(newValue);
17781 }
17782 }
17783 const _fields = (0, import_element57.useMemo)(() => normalizeFields(fields), [fields]);
17784 const filters = use_filters_default(_fields, view);
17785 const hasPrimaryOrLockedFilters = (0, import_element57.useMemo)(
17786 () => (filters || []).some(
17787 (filter) => filter.isPrimary || filter.isLocked
17788 ),
17789 [filters]
17790 );
17791 const [isShowingFilter, setIsShowingFilter] = (0, import_element57.useState)(
17792 hasPrimaryOrLockedFilters
17793 );
17794 const { intersectionObserver } = useInfiniteScroll({
17795 view,
17796 onChangeView,
17797 isLoading,
17798 paginationInfo,
17799 containerRef,
17800 setVisibleEntries
17801 });
17802 (0, import_element57.useEffect)(() => {
17803 if (hasPrimaryOrLockedFilters && !isShowingFilter) {
17804 setIsShowingFilter(true);
17805 }
17806 }, [hasPrimaryOrLockedFilters, isShowingFilter]);
17807 const defaultLayouts2 = (0, import_element57.useMemo)(
17808 () => Object.fromEntries(
17809 Object.entries(defaultLayoutsProperty).filter(([layoutType]) => {
17810 return dataViewsPickerLayouts.some(
17811 (viewLayout) => viewLayout.type === layoutType
17812 );
17813 }).map(([key, value]) => [
17814 key,
17815 value === true ? {} : value
17816 ])
17817 ),
17818 [defaultLayoutsProperty]
17819 );
17820 if (!defaultLayouts2[view.type]) {
17821 return null;
17822 }
17823 return /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(
17824 dataviews_context_default.Provider,
17825 {
17826 value: {
17827 view,
17828 onChangeView,
17829 fields: _fields,
17830 actions,
17831 data: displayData,
17832 isLoading,
17833 paginationInfo,
17834 isItemClickable,
17835 selection,
17836 onChangeSelection: setSelectionWithChange,
17837 openedFilter,
17838 setOpenedFilter,
17839 getItemId,
17840 containerWidth,
17841 containerRef,
17842 resizeObserverRef,
17843 defaultLayouts: defaultLayouts2,
17844 filters,
17845 isShowingFilter,
17846 setIsShowingFilter,
17847 config,
17848 itemListLabel,
17849 empty,
17850 onReset,
17851 hasInitiallyLoaded: true,
17852 intersectionObserver
17853 },
17854 children: /* @__PURE__ */ (0, import_jsx_runtime99.jsx)("div", { className: "dataviews-picker-wrapper", children: children ?? /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(DefaultUI, { search, searchLabel }) })
17855 }
17856 );
17857 }
17858 var DataViewsPickerSubComponents = DataViewsPicker;
17859 DataViewsPickerSubComponents.BulkActionToolbar = DataViewsPickerFooter;
17860 DataViewsPickerSubComponents.Filters = filters_default;
17861 DataViewsPickerSubComponents.FiltersToggled = filters_toggled_default;
17862 DataViewsPickerSubComponents.FiltersToggle = toggle_default;
17863 DataViewsPickerSubComponents.Layout = DataViewsLayout;
17864 DataViewsPickerSubComponents.LayoutSwitcher = ViewTypeMenu;
17865 DataViewsPickerSubComponents.Pagination = DataViewsPagination;
17866 DataViewsPickerSubComponents.Search = dataviews_search_default;
17867 DataViewsPickerSubComponents.ViewConfig = DataviewsViewConfigDropdown;
17868 var dataviews_picker_default = DataViewsPickerSubComponents;
17869
17870 // node_modules/dequal/dist/index.mjs
17871 var has = Object.prototype.hasOwnProperty;
17872 function find(iter, tar, key) {
17873 for (key of iter.keys()) {
17874 if (dequal(key, tar)) return key;
17875 }
17876 }
17877 function dequal(foo, bar) {
17878 var ctor, len, tmp;
17879 if (foo === bar) return true;
17880 if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
17881 if (ctor === Date) return foo.getTime() === bar.getTime();
17882 if (ctor === RegExp) return foo.toString() === bar.toString();
17883 if (ctor === Array) {
17884 if ((len = foo.length) === bar.length) {
17885 while (len-- && dequal(foo[len], bar[len])) ;
17886 }
17887 return len === -1;
17888 }
17889 if (ctor === Set) {
17890 if (foo.size !== bar.size) {
17891 return false;
17892 }
17893 for (len of foo) {
17894 tmp = len;
17895 if (tmp && typeof tmp === "object") {
17896 tmp = find(bar, tmp);
17897 if (!tmp) return false;
17898 }
17899 if (!bar.has(tmp)) return false;
17900 }
17901 return true;
17902 }
17903 if (ctor === Map) {
17904 if (foo.size !== bar.size) {
17905 return false;
17906 }
17907 for (len of foo) {
17908 tmp = len[0];
17909 if (tmp && typeof tmp === "object") {
17910 tmp = find(bar, tmp);
17911 if (!tmp) return false;
17912 }
17913 if (!dequal(len[1], bar.get(tmp))) {
17914 return false;
17915 }
17916 }
17917 return true;
17918 }
17919 if (ctor === ArrayBuffer) {
17920 foo = new Uint8Array(foo);
17921 bar = new Uint8Array(bar);
17922 } else if (ctor === DataView) {
17923 if ((len = foo.byteLength) === bar.byteLength) {
17924 while (len-- && foo.getInt8(len) === bar.getInt8(len)) ;
17925 }
17926 return len === -1;
17927 }
17928 if (ArrayBuffer.isView(foo)) {
17929 if ((len = foo.byteLength) === bar.byteLength) {
17930 while (len-- && foo[len] === bar[len]) ;
17931 }
17932 return len === -1;
17933 }
17934 if (!ctor || typeof foo === "object") {
17935 len = 0;
17936 for (ctor in foo) {
17937 if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
17938 if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
17939 }
17940 return Object.keys(bar).length === len;
17941 }
17942 }
17943 return foo !== foo && bar !== bar;
17944 }
17945
17946 // packages/views/build-module/use-view.mjs
17947 var import_element58 = __toESM(require_element(), 1);
17948 var import_data6 = __toESM(require_data(), 1);
17949 var import_preferences = __toESM(require_preferences(), 1);
17950
17951 // packages/views/build-module/preference-keys.mjs
17952 function generatePreferenceKey(kind, name, slug) {
17953 return `dataviews-${kind}-${name}-${slug}`;
17954 }
17955
17956 // packages/views/build-module/filter-utils.mjs
17957 var SCALAR_VALUES = [
17958 "titleField",
17959 "mediaField",
17960 "descriptionField",
17961 "showTitle",
17962 "showMedia",
17963 "showDescription",
17964 "showLevels",
17965 "infiniteScrollEnabled"
17966 ];
17967 function mergeActiveViewOverrides(view, activeViewOverrides, defaultView2) {
17968 if (!activeViewOverrides) {
17969 return view;
17970 }
17971 let result = view;
17972 for (const key of SCALAR_VALUES) {
17973 if (key in activeViewOverrides) {
17974 result = { ...result, [key]: activeViewOverrides[key] };
17975 }
17976 }
17977 if (activeViewOverrides.filters && activeViewOverrides.filters.length > 0) {
17978 const activeFields = new Set(
17979 activeViewOverrides.filters.map((f2) => f2.field)
17980 );
17981 const preserved = (view.filters ?? []).filter(
17982 (f2) => !activeFields.has(f2.field)
17983 );
17984 result = {
17985 ...result,
17986 filters: [...preserved, ...activeViewOverrides.filters]
17987 };
17988 }
17989 if (activeViewOverrides.sort) {
17990 const isDefaultSort = defaultView2 && view.sort?.field === defaultView2.sort?.field && view.sort?.direction === defaultView2.sort?.direction;
17991 if (isDefaultSort) {
17992 result = {
17993 ...result,
17994 sort: activeViewOverrides.sort
17995 };
17996 }
17997 }
17998 if (activeViewOverrides.layout) {
17999 result = {
18000 ...result,
18001 layout: {
18002 ...result.layout,
18003 ...activeViewOverrides.layout
18004 }
18005 };
18006 }
18007 if (activeViewOverrides.groupBy) {
18008 result = {
18009 ...result,
18010 groupBy: activeViewOverrides.groupBy
18011 };
18012 }
18013 return result;
18014 }
18015 function stripActiveViewOverrides(view, activeViewOverrides, defaultView2) {
18016 if (!activeViewOverrides) {
18017 return view;
18018 }
18019 let result = view;
18020 for (const key of SCALAR_VALUES) {
18021 if (key in activeViewOverrides) {
18022 const { [key]: _, ...rest } = result;
18023 result = rest;
18024 }
18025 }
18026 if (activeViewOverrides.filters && activeViewOverrides.filters.length > 0) {
18027 const activeFields = new Set(
18028 activeViewOverrides.filters.map((f2) => f2.field)
18029 );
18030 result = {
18031 ...result,
18032 filters: (view.filters ?? []).filter(
18033 (f2) => !activeFields.has(f2.field)
18034 )
18035 };
18036 }
18037 if (activeViewOverrides.sort && view.sort?.field === activeViewOverrides.sort.field && view.sort?.direction === activeViewOverrides.sort.direction) {
18038 result = {
18039 ...result,
18040 sort: defaultView2?.sort
18041 };
18042 }
18043 if (activeViewOverrides.layout && "layout" in result && result.layout) {
18044 const layout = { ...result.layout };
18045 for (const key of Object.keys(activeViewOverrides.layout)) {
18046 delete layout[key];
18047 }
18048 result = {
18049 ...result,
18050 layout: Object.keys(layout).length > 0 ? layout : void 0
18051 };
18052 }
18053 if (activeViewOverrides.groupBy && "groupBy" in result) {
18054 const { groupBy: _, ...rest } = result;
18055 result = rest;
18056 }
18057 return result;
18058 }
18059
18060 // packages/views/build-module/use-view.mjs
18061 function omit3(obj, keys) {
18062 const result = { ...obj };
18063 for (const key of keys) {
18064 delete result[key];
18065 }
18066 return result;
18067 }
18068 function useView(config) {
18069 const {
18070 kind,
18071 name,
18072 slug,
18073 defaultView: defaultView2,
18074 activeViewOverrides,
18075 queryParams,
18076 onChangeQueryParams
18077 } = config;
18078 const preferenceKey = generatePreferenceKey(kind, name, slug);
18079 const persistedView = (0, import_data6.useSelect)(
18080 (select2) => {
18081 return select2(import_preferences.store).get(
18082 "core/views",
18083 preferenceKey
18084 );
18085 },
18086 [preferenceKey]
18087 );
18088 const { set: set2 } = (0, import_data6.useDispatch)(import_preferences.store);
18089 const baseView = (0, import_element58.useMemo)(
18090 () => persistedView ?? defaultView2 ?? {},
18091 [persistedView, defaultView2]
18092 );
18093 const page = Number(queryParams?.page ?? baseView.page ?? 1);
18094 const search = queryParams?.search ?? baseView.search ?? "";
18095 const combinedOverrides = (0, import_element58.useMemo)(() => {
18096 const rawDefaults = config.defaultLayouts?.[baseView.type];
18097 const layoutTypeDefaults = !rawDefaults || rawDefaults === true ? {} : rawDefaults;
18098 return { ...layoutTypeDefaults, ...activeViewOverrides };
18099 }, [config.defaultLayouts, baseView.type, activeViewOverrides]);
18100 const view = (0, import_element58.useMemo)(() => {
18101 return mergeActiveViewOverrides(
18102 {
18103 ...baseView,
18104 page,
18105 search
18106 },
18107 combinedOverrides,
18108 defaultView2
18109 );
18110 }, [baseView, page, search, combinedOverrides, defaultView2]);
18111 const isModified = !!persistedView;
18112 const updateView = (0, import_element58.useCallback)(
18113 (newView) => {
18114 const urlParams = {
18115 page: newView?.page,
18116 search: newView?.search
18117 };
18118 const preferenceView = stripActiveViewOverrides(
18119 omit3(newView, ["page", "search"]),
18120 combinedOverrides,
18121 defaultView2
18122 );
18123 if (onChangeQueryParams && !dequal(urlParams, { page, search })) {
18124 onChangeQueryParams(urlParams);
18125 }
18126 const comparableBaseView = stripActiveViewOverrides(
18127 baseView,
18128 combinedOverrides,
18129 defaultView2
18130 );
18131 const comparableDefaultView = stripActiveViewOverrides(
18132 defaultView2,
18133 combinedOverrides,
18134 defaultView2
18135 );
18136 if (!dequal(comparableBaseView, preferenceView)) {
18137 if (dequal(preferenceView, comparableDefaultView)) {
18138 set2("core/views", preferenceKey, void 0);
18139 } else {
18140 set2("core/views", preferenceKey, preferenceView);
18141 }
18142 }
18143 },
18144 [
18145 onChangeQueryParams,
18146 page,
18147 search,
18148 baseView,
18149 defaultView2,
18150 combinedOverrides,
18151 set2,
18152 preferenceKey
18153 ]
18154 );
18155 const resetToDefault = (0, import_element58.useCallback)(() => {
18156 set2("core/views", preferenceKey, void 0);
18157 }, [preferenceKey, set2]);
18158 return {
18159 view,
18160 isModified,
18161 updateView,
18162 resetToDefault
18163 };
18164 }
18165
18166 // packages/views/build-module/load-view.mjs
18167 var import_data7 = __toESM(require_data(), 1);
18168 var import_preferences2 = __toESM(require_preferences(), 1);
18169
18170 // packages/views/build-module/use-view-config.mjs
18171 var import_data8 = __toESM(require_data(), 1);
18172 var import_core_data = __toESM(require_core_data(), 1);
18173
18174 // packages/views/build-module/lock-unlock.mjs
18175 var import_private_apis2 = __toESM(require_private_apis(), 1);
18176 var { lock: lock2, unlock: unlock2 } = (0, import_private_apis2.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
18177 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
18178 "@wordpress/views"
18179 );
18180
18181 // packages/media-fields/build-module/alt_text/index.mjs
18182 var import_i18n49 = __toESM(require_i18n(), 1);
18183 var import_components46 = __toESM(require_components(), 1);
18184 var import_jsx_runtime100 = __toESM(require_jsx_runtime(), 1);
18185 var altTextField = {
18186 id: "alt_text",
18187 type: "text",
18188 label: (0, import_i18n49.__)("Alt text"),
18189 isVisible: (item) => item?.media_type === "image",
18190 render: ({ item }) => item?.alt_text || "-",
18191 Edit: ({ field, onChange, data }) => {
18192 return /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(
18193 import_components46.TextareaControl,
18194 {
18195 label: field.label,
18196 value: data.alt_text || "",
18197 onChange: (value) => onChange({ alt_text: value }),
18198 rows: 2
18199 }
18200 );
18201 },
18202 enableSorting: false,
18203 filterBy: false
18204 };
18205 var alt_text_default = altTextField;
18206
18207 // packages/media-fields/build-module/attached_to/index.mjs
18208 var import_i18n52 = __toESM(require_i18n(), 1);
18209
18210 // packages/media-fields/build-module/attached_to/view.mjs
18211 var import_element59 = __toESM(require_element(), 1);
18212 var import_i18n50 = __toESM(require_i18n(), 1);
18213
18214 // packages/media-fields/build-module/utils/get-rendered-content.mjs
18215 function getRenderedContent(content) {
18216 if (!content) {
18217 return "";
18218 }
18219 if (typeof content === "string") {
18220 return content;
18221 }
18222 if (typeof content === "object") {
18223 return content.rendered || content.raw || "";
18224 }
18225 return "";
18226 }
18227
18228 // packages/media-fields/build-module/attached_to/view.mjs
18229 var import_jsx_runtime101 = __toESM(require_jsx_runtime(), 1);
18230 function MediaAttachedToView({
18231 item
18232 }) {
18233 const [attachedPostTitle, setAttachedPostTitle] = (0, import_element59.useState)(null);
18234 const parentId = item.post;
18235 const embeddedPostId = item._embedded?.["wp:attached-to"]?.[0]?.id;
18236 const embeddedPostTitle = item._embedded?.["wp:attached-to"]?.[0]?.title;
18237 (0, import_element59.useEffect)(() => {
18238 if (!!parentId && parentId === embeddedPostId) {
18239 setAttachedPostTitle(
18240 getRenderedContent(embeddedPostTitle) || embeddedPostId?.toString() || ""
18241 );
18242 }
18243 if (!parentId) {
18244 setAttachedPostTitle((0, import_i18n50.__)("(Unattached)"));
18245 }
18246 }, [parentId, embeddedPostId, embeddedPostTitle]);
18247 return /* @__PURE__ */ (0, import_jsx_runtime101.jsx)(import_jsx_runtime101.Fragment, { children: attachedPostTitle });
18248 }
18249
18250 // packages/media-fields/build-module/attached_to/edit.mjs
18251 var import_core_data2 = __toESM(require_core_data(), 1);
18252 var import_components47 = __toESM(require_components(), 1);
18253 var import_i18n51 = __toESM(require_i18n(), 1);
18254 var import_element60 = __toESM(require_element(), 1);
18255 var import_compose13 = __toESM(require_compose(), 1);
18256 var import_data9 = __toESM(require_data(), 1);
18257 var import_jsx_runtime102 = __toESM(require_jsx_runtime(), 1);
18258 function MediaAttachedToEdit({
18259 data,
18260 onChange
18261 }) {
18262 const defaultPost = !!data.post && !!data?._embedded?.["wp:attached-to"]?.[0] ? [
18263 {
18264 label: getRenderedContent(
18265 data._embedded?.["wp:attached-to"]?.[0]?.title
18266 ),
18267 value: data.post.toString()
18268 }
18269 ] : [];
18270 const [options, setOptions] = (0, import_element60.useState)(defaultPost);
18271 const [searchResults, setSearchResults] = (0, import_element60.useState)(
18272 []
18273 );
18274 const [isLoading, setIsLoading] = (0, import_element60.useState)(false);
18275 const [value, setValue] = (0, import_element60.useState)(
18276 data?.post?.toString() ?? null
18277 );
18278 const postTypes = (0, import_data9.useSelect)(
18279 (select2) => select2(import_core_data2.store).getPostTypes(),
18280 []
18281 );
18282 const handleDetach = () => {
18283 onChange({
18284 post: 0,
18285 _embedded: { ...data?._embedded, "wp:attached-to": void 0 }
18286 });
18287 setOptions([]);
18288 };
18289 const onValueChange = async (filterValue) => {
18290 setIsLoading(true);
18291 const results = await (0, import_core_data2.__experimentalFetchLinkSuggestions)(
18292 filterValue,
18293 /*
18294 * @TODO `fetchLinkSuggestions()` should accept `perPage` as an option argument.
18295 * `isInitialSuggestions` limits the result to 3, otherwise it's hardcoded to 20.
18296 */
18297 { type: "post", isInitialSuggestions: true },
18298 {}
18299 );
18300 setSearchResults(results);
18301 const mappedSuggestions = results.map((result) => {
18302 return {
18303 label: result.title,
18304 value: result.id.toString()
18305 };
18306 });
18307 setOptions(mappedSuggestions);
18308 setIsLoading(false);
18309 };
18310 const handleSelectOption = (selectedPostId) => {
18311 if (!selectedPostId) {
18312 handleDetach();
18313 return;
18314 }
18315 setValue(selectedPostId);
18316 if (selectedPostId) {
18317 const selectedPost = searchResults.find(
18318 (result) => result.id === Number(selectedPostId)
18319 );
18320 if (selectedPost && postTypes) {
18321 const postType = postTypes.find(
18322 (_postType) => _postType.slug === selectedPost?.type
18323 );
18324 const attachedTo = {
18325 ...postType && { type: postType.slug },
18326 id: Number(selectedPostId),
18327 title: {
18328 raw: selectedPost.title,
18329 rendered: selectedPost.title
18330 }
18331 };
18332 onChange({
18333 post: Number(selectedPostId),
18334 _embedded: {
18335 ...data?._embedded,
18336 "wp:attached-to": [attachedTo]
18337 }
18338 });
18339 }
18340 }
18341 };
18342 const help = !!data.post ? (0, import_element60.createInterpolateElement)(
18343 (0, import_i18n51.__)(
18344 "Search for a post or page to attach this media to or <button>detach current</button>."
18345 ),
18346 {
18347 button: /* @__PURE__ */ (0, import_jsx_runtime102.jsx)(
18348 import_components47.Button,
18349 {
18350 __next40pxDefaultSize: true,
18351 onClick: handleDetach,
18352 variant: "link",
18353 accessibleWhenDisabled: true
18354 }
18355 )
18356 }
18357 ) : (0, import_i18n51.__)("Search for a post or page to attach this media to.");
18358 return /* @__PURE__ */ (0, import_jsx_runtime102.jsx)(
18359 import_components47.ComboboxControl,
18360 {
18361 className: "dataviews-media-field__attached-to",
18362 __next40pxDefaultSize: true,
18363 isLoading,
18364 label: (0, import_i18n51.__)("Attached to"),
18365 help,
18366 value,
18367 options,
18368 onFilterValueChange: (0, import_compose13.debounce)(
18369 (filterValue) => onValueChange(filterValue),
18370 300
18371 ),
18372 onChange: handleSelectOption,
18373 hideLabelFromVision: true
18374 }
18375 );
18376 }
18377
18378 // packages/media-fields/build-module/attached_to/index.mjs
18379 var attachedToField = {
18380 id: "attached_to",
18381 type: "text",
18382 label: (0, import_i18n52.__)("Attached to"),
18383 Edit: MediaAttachedToEdit,
18384 render: MediaAttachedToView,
18385 enableSorting: false,
18386 filterBy: false
18387 };
18388 var attached_to_default = attachedToField;
18389
18390 // packages/media-fields/build-module/author/index.mjs
18391 var import_i18n54 = __toESM(require_i18n(), 1);
18392 var import_data10 = __toESM(require_data(), 1);
18393 var import_core_data3 = __toESM(require_core_data(), 1);
18394
18395 // packages/media-fields/build-module/author/view.mjs
18396 var import_i18n53 = __toESM(require_i18n(), 1);
18397 var import_element61 = __toESM(require_element(), 1);
18398 var import_components48 = __toESM(require_components(), 1);
18399 var import_jsx_runtime103 = __toESM(require_jsx_runtime(), 1);
18400 function AuthorView({
18401 item
18402 }) {
18403 const author = item?._embedded?.author?.[0];
18404 const text = author?.name;
18405 const imageUrl = author?.avatar_urls?.[48];
18406 const [loadingState, setLoadingState] = (0, import_element61.useState)("loading");
18407 (0, import_element61.useEffect)(() => {
18408 setLoadingState("loading");
18409 }, [imageUrl]);
18410 const imgRef = (0, import_element61.useCallback)((img) => {
18411 if (img?.complete) {
18412 setLoadingState("instant");
18413 }
18414 }, []);
18415 const handleLoad = () => {
18416 if (loadingState === "loading") {
18417 setLoadingState("loaded");
18418 }
18419 };
18420 return /* @__PURE__ */ (0, import_jsx_runtime103.jsxs)(import_components48.__experimentalHStack, { alignment: "left", spacing: 0, children: [
18421 !!imageUrl && /* @__PURE__ */ (0, import_jsx_runtime103.jsx)(
18422 "div",
18423 {
18424 className: clsx_default("media-author-field__avatar", {
18425 "is-loading": loadingState === "loading",
18426 "is-loaded": loadingState === "loaded"
18427 }),
18428 children: /* @__PURE__ */ (0, import_jsx_runtime103.jsx)(
18429 "img",
18430 {
18431 ref: imgRef,
18432 onLoad: handleLoad,
18433 alt: (0, import_i18n53.__)("Author avatar"),
18434 src: imageUrl
18435 }
18436 )
18437 }
18438 ),
18439 !imageUrl && /* @__PURE__ */ (0, import_jsx_runtime103.jsx)("div", { className: "media-author-field__icon", children: /* @__PURE__ */ (0, import_jsx_runtime103.jsx)(import_components48.Icon, { icon: comment_author_avatar_default }) }),
18440 /* @__PURE__ */ (0, import_jsx_runtime103.jsx)("span", { className: "media-author-field__name", children: text })
18441 ] });
18442 }
18443
18444 // packages/media-fields/build-module/author/index.mjs
18445 var authorField = {
18446 label: (0, import_i18n54.__)("Author"),
18447 id: "author",
18448 type: "integer",
18449 getElements: async () => {
18450 const authors = await (0, import_data10.resolveSelect)(import_core_data3.store).getEntityRecords(
18451 "root",
18452 "user",
18453 {
18454 per_page: -1,
18455 who: "authors",
18456 _fields: "id,name",
18457 context: "view"
18458 }
18459 ) ?? [];
18460 return authors.map(({ id, name }) => ({
18461 value: id,
18462 label: name
18463 }));
18464 },
18465 render: AuthorView,
18466 sort: (a2, b2, direction) => {
18467 const nameA = a2._embedded?.author?.[0]?.name || "";
18468 const nameB = b2._embedded?.author?.[0]?.name || "";
18469 return direction === "asc" ? nameA.localeCompare(nameB) : nameB.localeCompare(nameA);
18470 },
18471 filterBy: {
18472 operators: ["isAny", "isNone"]
18473 },
18474 readOnly: true
18475 };
18476 var author_default = authorField;
18477
18478 // packages/media-fields/build-module/caption/index.mjs
18479 var import_i18n55 = __toESM(require_i18n(), 1);
18480 var import_components49 = __toESM(require_components(), 1);
18481
18482 // packages/media-fields/build-module/utils/get-raw-content.mjs
18483 function getRawContent(content) {
18484 if (!content) {
18485 return "";
18486 }
18487 if (typeof content === "string") {
18488 return content;
18489 }
18490 if (typeof content === "object" && "raw" in content) {
18491 return content.raw || "";
18492 }
18493 return "";
18494 }
18495
18496 // packages/media-fields/build-module/caption/index.mjs
18497 var import_jsx_runtime104 = __toESM(require_jsx_runtime(), 1);
18498 var captionField = {
18499 id: "caption",
18500 type: "text",
18501 label: (0, import_i18n55.__)("Caption"),
18502 getValue: ({ item }) => getRawContent(item?.caption),
18503 render: ({ item }) => getRawContent(item?.caption) || "-",
18504 Edit: ({ field, onChange, data }) => {
18505 return /* @__PURE__ */ (0, import_jsx_runtime104.jsx)(
18506 import_components49.TextareaControl,
18507 {
18508 label: field.label,
18509 value: getRawContent(data.caption) || "",
18510 onChange: (value) => onChange({ caption: value }),
18511 rows: 2
18512 }
18513 );
18514 },
18515 enableSorting: false,
18516 filterBy: false
18517 };
18518 var caption_default = captionField;
18519
18520 // packages/media-fields/build-module/date_added/index.mjs
18521 var import_i18n56 = __toESM(require_i18n(), 1);
18522 var import_date10 = __toESM(require_date(), 1);
18523 var dateAddedField = {
18524 id: "date",
18525 type: "datetime",
18526 label: (0, import_i18n56.__)("Date added"),
18527 filterBy: {
18528 operators: ["before", "after"]
18529 },
18530 format: {
18531 datetime: (0, import_date10.getSettings)().formats.datetimeAbbreviated
18532 },
18533 readOnly: true
18534 };
18535 var date_added_default = dateAddedField;
18536
18537 // packages/media-fields/build-module/date_modified/index.mjs
18538 var import_i18n57 = __toESM(require_i18n(), 1);
18539 var import_date11 = __toESM(require_date(), 1);
18540 var dateModifiedField = {
18541 id: "modified",
18542 type: "datetime",
18543 label: (0, import_i18n57.__)("Date modified"),
18544 filterBy: {
18545 operators: ["before", "after"]
18546 },
18547 format: {
18548 datetime: (0, import_date11.getSettings)().formats.datetimeAbbreviated
18549 },
18550 readOnly: true
18551 };
18552 var date_modified_default = dateModifiedField;
18553
18554 // packages/media-fields/build-module/description/index.mjs
18555 var import_i18n58 = __toESM(require_i18n(), 1);
18556 var import_components50 = __toESM(require_components(), 1);
18557 var import_jsx_runtime105 = __toESM(require_jsx_runtime(), 1);
18558 var descriptionField = {
18559 id: "description",
18560 type: "text",
18561 label: (0, import_i18n58.__)("Description"),
18562 getValue: ({ item }) => getRawContent(item?.description),
18563 render: ({ item }) => /* @__PURE__ */ (0, import_jsx_runtime105.jsx)("div", { children: getRawContent(item?.description) || "-" }),
18564 Edit: ({ field, onChange, data }) => {
18565 return /* @__PURE__ */ (0, import_jsx_runtime105.jsx)(
18566 import_components50.TextareaControl,
18567 {
18568 label: field.label,
18569 value: getRawContent(data.description) || "",
18570 onChange: (value) => onChange({ description: value }),
18571 rows: 5
18572 }
18573 );
18574 },
18575 enableSorting: false,
18576 filterBy: false
18577 };
18578 var description_default = descriptionField;
18579
18580 // packages/media-fields/build-module/filename/index.mjs
18581 var import_i18n59 = __toESM(require_i18n(), 1);
18582 var import_url4 = __toESM(require_url(), 1);
18583
18584 // packages/media-fields/build-module/filename/view.mjs
18585 var import_components51 = __toESM(require_components(), 1);
18586 var import_element62 = __toESM(require_element(), 1);
18587 var import_url3 = __toESM(require_url(), 1);
18588 var import_jsx_runtime106 = __toESM(require_jsx_runtime(), 1);
18589 var TRUNCATE_LENGTH = 15;
18590 function FileNameView({
18591 item
18592 }) {
18593 const fileName = (0, import_element62.useMemo)(
18594 () => item?.source_url ? (0, import_url3.getFilename)(item.source_url) : null,
18595 [item?.source_url]
18596 );
18597 if (!fileName) {
18598 return "";
18599 }
18600 return fileName.length > TRUNCATE_LENGTH ? /* @__PURE__ */ (0, import_jsx_runtime106.jsx)(import_components51.Tooltip, { text: fileName, children: /* @__PURE__ */ (0, import_jsx_runtime106.jsx)(import_components51.__experimentalTruncate, { limit: TRUNCATE_LENGTH, ellipsizeMode: "tail", children: fileName }) }) : /* @__PURE__ */ (0, import_jsx_runtime106.jsx)(import_jsx_runtime106.Fragment, { children: fileName });
18601 }
18602
18603 // packages/media-fields/build-module/filename/index.mjs
18604 var filenameField = {
18605 id: "filename",
18606 type: "text",
18607 label: (0, import_i18n59.__)("File name"),
18608 getValue: ({ item }) => (0, import_url4.getFilename)(item?.source_url || ""),
18609 render: FileNameView,
18610 enableSorting: false,
18611 filterBy: false,
18612 readOnly: true
18613 };
18614 var filename_default = filenameField;
18615
18616 // packages/media-fields/build-module/filesize/index.mjs
18617 var import_i18n60 = __toESM(require_i18n(), 1);
18618 var KB_IN_BYTES = 1024;
18619 var MB_IN_BYTES = 1024 * KB_IN_BYTES;
18620 var GB_IN_BYTES = 1024 * MB_IN_BYTES;
18621 var TB_IN_BYTES = 1024 * GB_IN_BYTES;
18622 var PB_IN_BYTES = 1024 * TB_IN_BYTES;
18623 var EB_IN_BYTES = 1024 * PB_IN_BYTES;
18624 var ZB_IN_BYTES = 1024 * EB_IN_BYTES;
18625 var YB_IN_BYTES = 1024 * ZB_IN_BYTES;
18626 function getBytesString(bytes, unitSymbol, decimals = 2) {
18627 return (0, import_i18n60.sprintf)(
18628 // translators: 1: Actual bytes of a file. 2: The unit symbol (e.g. MB).
18629 (0, import_i18n60._x)("%1$s %2$s", "file size"),
18630 bytes.toLocaleString(void 0, {
18631 minimumFractionDigits: 0,
18632 maximumFractionDigits: decimals
18633 }),
18634 unitSymbol
18635 );
18636 }
18637 function formatFileSize(bytes, decimals = 2) {
18638 if (bytes === 0) {
18639 return getBytesString(0, (0, import_i18n60._x)("B", "unit symbol"), decimals);
18640 }
18641 const quant = {
18642 /* translators: Unit symbol for yottabyte. */
18643 [(0, import_i18n60._x)("YB", "unit symbol")]: YB_IN_BYTES,
18644 /* translators: Unit symbol for zettabyte. */
18645 [(0, import_i18n60._x)("ZB", "unit symbol")]: ZB_IN_BYTES,
18646 /* translators: Unit symbol for exabyte. */
18647 [(0, import_i18n60._x)("EB", "unit symbol")]: EB_IN_BYTES,
18648 /* translators: Unit symbol for petabyte. */
18649 [(0, import_i18n60._x)("PB", "unit symbol")]: PB_IN_BYTES,
18650 /* translators: Unit symbol for terabyte. */
18651 [(0, import_i18n60._x)("TB", "unit symbol")]: TB_IN_BYTES,
18652 /* translators: Unit symbol for gigabyte. */
18653 [(0, import_i18n60._x)("GB", "unit symbol")]: GB_IN_BYTES,
18654 /* translators: Unit symbol for megabyte. */
18655 [(0, import_i18n60._x)("MB", "unit symbol")]: MB_IN_BYTES,
18656 /* translators: Unit symbol for kilobyte. */
18657 [(0, import_i18n60._x)("KB", "unit symbol")]: KB_IN_BYTES,
18658 /* translators: Unit symbol for byte. */
18659 [(0, import_i18n60._x)("B", "unit symbol")]: 1
18660 };
18661 for (const [unit, mag] of Object.entries(quant)) {
18662 if (bytes >= mag) {
18663 return getBytesString(bytes / mag, unit, decimals);
18664 }
18665 }
18666 return "";
18667 }
18668 var filesizeField = {
18669 id: "filesize",
18670 type: "text",
18671 label: (0, import_i18n60.__)("File size"),
18672 getValue: ({ item }) => item?.media_details?.filesize ? formatFileSize(item?.media_details?.filesize) : "",
18673 isVisible: (item) => {
18674 return !!item?.media_details?.filesize;
18675 },
18676 enableSorting: false,
18677 filterBy: false,
18678 readOnly: true
18679 };
18680 var filesize_default = filesizeField;
18681
18682 // packages/media-fields/build-module/media_dimensions/index.mjs
18683 var import_i18n61 = __toESM(require_i18n(), 1);
18684 var mediaDimensionsField = {
18685 id: "media_dimensions",
18686 type: "text",
18687 label: (0, import_i18n61.__)("Dimensions"),
18688 getValue: ({ item }) => item?.media_details?.width && item?.media_details?.height ? (0, import_i18n61.sprintf)(
18689 // translators: 1: Width. 2: Height.
18690 (0, import_i18n61._x)("%1$s \xD7 %2$s", "image dimensions"),
18691 item?.media_details?.width?.toString(),
18692 item?.media_details?.height?.toString()
18693 ) : "",
18694 isVisible: (item) => {
18695 return !!(item?.media_details?.width && item?.media_details?.height);
18696 },
18697 enableSorting: false,
18698 filterBy: false,
18699 readOnly: true
18700 };
18701 var media_dimensions_default = mediaDimensionsField;
18702
18703 // packages/media-fields/build-module/media_thumbnail/index.mjs
18704 var import_i18n63 = __toESM(require_i18n(), 1);
18705
18706 // packages/media-fields/build-module/media_thumbnail/view.mjs
18707 var import_data11 = __toESM(require_data(), 1);
18708 var import_core_data4 = __toESM(require_core_data(), 1);
18709 var import_components52 = __toESM(require_components(), 1);
18710 var import_element63 = __toESM(require_element(), 1);
18711 var import_url5 = __toESM(require_url(), 1);
18712
18713 // packages/media-fields/build-module/utils/get-media-type-from-mime-type.mjs
18714 var import_i18n62 = __toESM(require_i18n(), 1);
18715 function getMediaTypeFromMimeType(mimeType) {
18716 if (mimeType.startsWith("image/")) {
18717 return {
18718 type: "image",
18719 label: (0, import_i18n62.__)("Image"),
18720 icon: image_default
18721 };
18722 }
18723 if (mimeType.startsWith("video/")) {
18724 return {
18725 type: "video",
18726 label: (0, import_i18n62.__)("Video"),
18727 icon: video_default
18728 };
18729 }
18730 if (mimeType.startsWith("audio/")) {
18731 return {
18732 type: "audio",
18733 label: (0, import_i18n62.__)("Audio"),
18734 icon: audio_default
18735 };
18736 }
18737 return {
18738 type: "application",
18739 label: (0, import_i18n62.__)("Application"),
18740 icon: file_default
18741 };
18742 }
18743
18744 // packages/media-fields/build-module/media_thumbnail/view.mjs
18745 var import_jsx_runtime107 = __toESM(require_jsx_runtime(), 1);
18746 function getBestImageUrl(featuredMedia, configSizes) {
18747 const sizes = featuredMedia?.media_details?.sizes;
18748 if (!sizes) {
18749 return featuredMedia.source_url;
18750 }
18751 const sizeEntries = Object.values(sizes);
18752 if (!sizeEntries.length) {
18753 return featuredMedia.source_url;
18754 }
18755 const targetWidth = configSizes ? parseInt(configSizes, 10) : NaN;
18756 if (!Number.isNaN(targetWidth)) {
18757 const validEntries = sizeEntries.filter(
18758 (s2) => typeof s2.width === "number" && !Number.isNaN(s2.width)
18759 );
18760 if (!validEntries.length) {
18761 return featuredMedia.source_url;
18762 }
18763 const sorted = [...validEntries].sort(
18764 (a2, b2) => a2.width - b2.width
18765 );
18766 const match2 = sorted.find((s2) => s2.width >= targetWidth);
18767 if (match2) {
18768 return match2.source_url;
18769 }
18770 return sorted[sorted.length - 1].source_url;
18771 }
18772 return featuredMedia.source_url;
18773 }
18774 function FallbackView({
18775 item,
18776 filename
18777 }) {
18778 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)("div", { className: "dataviews-media-field__media-thumbnail", children: /* @__PURE__ */ (0, import_jsx_runtime107.jsxs)(
18779 import_components52.__experimentalVStack,
18780 {
18781 justify: "center",
18782 alignment: "center",
18783 className: "dataviews-media-field__media-thumbnail__stack",
18784 spacing: 0,
18785 children: [
18786 /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
18787 import_components52.Icon,
18788 {
18789 className: "dataviews-media-field__media-thumbnail--icon",
18790 icon: getMediaTypeFromMimeType(item.mime_type).icon,
18791 size: 24
18792 }
18793 ),
18794 !!filename && /* @__PURE__ */ (0, import_jsx_runtime107.jsx)("div", { className: "dataviews-media-field__media-thumbnail__filename", children: /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(import_components52.__experimentalTruncate, { className: "dataviews-media-field__media-thumbnail__filename__truncate", children: filename }) })
18795 ]
18796 }
18797 ) });
18798 }
18799 function ImageView({
18800 item,
18801 configSizes,
18802 onError
18803 }) {
18804 const imageUrl = getBestImageUrl(item, configSizes);
18805 const imgRef = (0, import_element63.useRef)(null);
18806 const [loadingState, setLoadingState] = (0, import_element63.useState)("loading");
18807 (0, import_element63.useLayoutEffect)(() => {
18808 if (imgRef.current?.complete) {
18809 setLoadingState("instant");
18810 } else {
18811 setLoadingState("loading");
18812 }
18813 }, [imageUrl]);
18814 const handleLoad = () => {
18815 if (loadingState === "loading") {
18816 setLoadingState("loaded");
18817 }
18818 };
18819 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
18820 "div",
18821 {
18822 className: clsx_default("dataviews-media-field__media-thumbnail", {
18823 "is-loading": loadingState === "loading",
18824 "is-loaded": loadingState === "loaded"
18825 }),
18826 children: /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
18827 "img",
18828 {
18829 ref: imgRef,
18830 className: "dataviews-media-field__media-thumbnail--image",
18831 src: imageUrl,
18832 alt: item.alt_text || item.title.raw,
18833 onLoad: handleLoad,
18834 onError,
18835 loading: "lazy"
18836 }
18837 )
18838 }
18839 );
18840 }
18841 function MediaThumbnailView({
18842 item,
18843 config
18844 }) {
18845 const [imageError, setImageError] = (0, import_element63.useState)(false);
18846 const _featuredMedia = (0, import_data11.useSelect)(
18847 (select2) => {
18848 if (!item.featured_media) {
18849 return;
18850 }
18851 return select2(import_core_data4.store).getEntityRecord(
18852 "postType",
18853 "attachment",
18854 item.featured_media
18855 );
18856 },
18857 [item.featured_media]
18858 );
18859 const featuredMedia = item.featured_media ? _featuredMedia : item;
18860 if (!featuredMedia) {
18861 return null;
18862 }
18863 const filename = (0, import_url5.getFilename)(featuredMedia.source_url || "");
18864 if (imageError || getMediaTypeFromMimeType(featuredMedia.mime_type).type !== "image") {
18865 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(FallbackView, { item: featuredMedia, filename: filename || "" });
18866 }
18867 return /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
18868 ImageView,
18869 {
18870 item: featuredMedia,
18871 configSizes: config?.sizes,
18872 onError: () => setImageError(true)
18873 }
18874 );
18875 }
18876
18877 // packages/media-fields/build-module/media_thumbnail/index.mjs
18878 var mediaThumbnailField = {
18879 id: "media_thumbnail",
18880 type: "media",
18881 label: (0, import_i18n63.__)("Thumbnail"),
18882 render: MediaThumbnailView,
18883 enableSorting: false,
18884 filterBy: false
18885 };
18886 var media_thumbnail_default = mediaThumbnailField;
18887
18888 // packages/media-fields/build-module/mime_type/index.mjs
18889 var import_i18n64 = __toESM(require_i18n(), 1);
18890 var mimeTypeField = {
18891 id: "mime_type",
18892 type: "text",
18893 label: (0, import_i18n64.__)("File type"),
18894 getValue: ({ item }) => item?.mime_type || "",
18895 render: ({ item }) => item?.mime_type || "-",
18896 // Disable sorting until REST API support for ordering my `mime_type` is added.
18897 // See: https://core.trac.wordpress.org/ticket/64073
18898 enableSorting: false,
18899 filterBy: false,
18900 readOnly: true
18901 };
18902 var mime_type_default = mimeTypeField;
18903
18904 // packages/media-utils/build-module/components/media-upload-modal/index.mjs
18905 var import_notices = __toESM(require_notices(), 1);
18906
18907 // packages/media-utils/build-module/lock-unlock.mjs
18908 var import_private_apis3 = __toESM(require_private_apis(), 1);
18909 var { lock: lock3, unlock: unlock3 } = (0, import_private_apis3.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
18910 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
18911 "@wordpress/media-utils"
18912 );
18913
18914 // packages/media-utils/build-module/components/media-upload-modal/upload-status-popover.mjs
18915 var import_element64 = __toESM(require_element(), 1);
18916 var import_i18n65 = __toESM(require_i18n(), 1);
18917 var import_components53 = __toESM(require_components(), 1);
18918 var import_jsx_runtime108 = __toESM(require_jsx_runtime(), 1);
18919 function UploadStatusPopover({
18920 uploadingFiles,
18921 onDismissError,
18922 onOpenChange
18923 }) {
18924 const [isOpen, setIsOpen] = (0, import_element64.useState)(false);
18925 const [prevHadErrors, setPrevHadErrors] = (0, import_element64.useState)(false);
18926 const triggerRef = (0, import_element64.useRef)(null);
18927 const updateIsOpen = (0, import_element64.useCallback)(
18928 (open) => {
18929 setIsOpen(open);
18930 onOpenChange?.(open);
18931 },
18932 [onOpenChange]
18933 );
18934 const activeFiles = uploadingFiles.filter(
18935 (file) => file.status === "uploading"
18936 );
18937 const errorFiles = uploadingFiles.filter(
18938 (file) => file.status === "error"
18939 );
18940 const hasErrors = errorFiles.length > 0;
18941 const isUploading = activeFiles.length > 0;
18942 (0, import_element64.useEffect)(() => {
18943 if (hasErrors && !prevHadErrors) {
18944 updateIsOpen(true);
18945 }
18946 setPrevHadErrors(hasErrors);
18947 }, [hasErrors, prevHadErrors, updateIsOpen]);
18948 if (uploadingFiles.length === 0) {
18949 return null;
18950 }
18951 let buttonLabel, popoverHeading;
18952 if (isUploading) {
18953 buttonLabel = (0, import_i18n65.sprintf)(
18954 // translators: %s: number of files being uploaded
18955 (0, import_i18n65._n)("Uploading %s file", "Uploading %s files", activeFiles.length),
18956 activeFiles.length.toLocaleString()
18957 );
18958 popoverHeading = (0, import_i18n65.__)("Uploading");
18959 } else if (hasErrors) {
18960 buttonLabel = (0, import_i18n65.sprintf)(
18961 // translators: %s: number of upload errors
18962 (0, import_i18n65._n)("%s upload error", "%s upload errors", errorFiles.length),
18963 errorFiles.length.toLocaleString()
18964 );
18965 popoverHeading = (0, import_i18n65.__)("Upload errors");
18966 } else {
18967 buttonLabel = (0, import_i18n65.__)("Upload complete");
18968 popoverHeading = (0, import_i18n65.__)("Upload complete");
18969 }
18970 return /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)("div", { className: "media-upload-modal__upload-status", children: [
18971 isUploading && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(import_components53.Spinner, {}),
18972 /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(
18973 import_components53.Button,
18974 {
18975 className: "media-upload-modal__upload-status__trigger",
18976 size: "compact",
18977 icon: chevron_down_default,
18978 iconPosition: "right",
18979 onClick: () => updateIsOpen(!isOpen),
18980 "aria-expanded": isOpen,
18981 ref: triggerRef,
18982 children: buttonLabel
18983 }
18984 ),
18985 isOpen && /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)(
18986 import_components53.Popover,
18987 {
18988 className: "media-upload-modal__upload-status__popover",
18989 placement: "top-start",
18990 offset: 8,
18991 anchor: triggerRef.current,
18992 focusOnMount: true,
18993 onClose: () => {
18994 if (triggerRef.current?.contains(
18995 triggerRef.current.ownerDocument.activeElement
18996 )) {
18997 return;
18998 }
18999 updateIsOpen(false);
19000 },
19001 children: [
19002 /* @__PURE__ */ (0, import_jsx_runtime108.jsx)("div", { className: "media-upload-modal__upload-status__header", children: /* @__PURE__ */ (0, import_jsx_runtime108.jsx)("h3", { children: popoverHeading }) }),
19003 /* @__PURE__ */ (0, import_jsx_runtime108.jsx)("ul", { className: "media-upload-modal__upload-status__list", children: uploadingFiles.map((file) => /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)(
19004 "li",
19005 {
19006 className: "media-upload-modal__upload-status__item",
19007 children: [
19008 file.status === "uploading" && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(import_components53.Spinner, {}),
19009 file.status === "uploaded" && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(import_components53.Icon, { icon: check_default, size: 16 }),
19010 (file.status === "uploading" || file.status === "uploaded") && /* @__PURE__ */ (0, import_jsx_runtime108.jsx)(
19011 "span",
19012 {
19013 className: "media-upload-modal__upload-status__filename",
19014 title: file.name,
19015 children: file.name
19016 }
19017 ),
19018 file.status === "error" && /* @__PURE__ */ (0, import_jsx_runtime108.jsxs)(
19019 import_components53.Notice,
19020 {
19021 status: "error",
19022 isDismissible: !!onDismissError,
19023 onRemove: () => onDismissError?.(file.id),
19024 children: [
19025 file.name,
19026 ": ",
19027 file.error
19028 ]
19029 }
19030 )
19031 ]
19032 },
19033 file.id
19034 )) })
19035 ]
19036 }
19037 )
19038 ] });
19039 }
19040
19041 // packages/media-utils/build-module/components/media-upload-modal/use-invalidate-attachment-resolutions.mjs
19042 var import_element65 = __toESM(require_element(), 1);
19043 var import_core_data5 = __toESM(require_core_data(), 1);
19044 var import_data12 = __toESM(require_data(), 1);
19045 function useInvalidateAttachmentResolutions() {
19046 const registry = (0, import_data12.useRegistry)();
19047 return (0, import_element65.useCallback)(() => {
19048 const resolvers = registry.select(import_core_data5.store).getCachedResolvers();
19049 const entityRecordResolutions = resolvers.getEntityRecords;
19050 entityRecordResolutions?.forEach((_value, args) => {
19051 if (args[0] === "postType" && args[1] === "attachment") {
19052 registry.dispatch(import_core_data5.store).invalidateResolution("getEntityRecords", args);
19053 }
19054 });
19055 }, [registry]);
19056 }
19057
19058 // packages/media-utils/build-module/components/media-upload-modal/use-upload-status.mjs
19059 var import_element66 = __toESM(require_element(), 1);
19060 var import_blob2 = __toESM(require_blob(), 1);
19061 var idCounter = 0;
19062 var batchIdCounter = 0;
19063 function useUploadStatus({
19064 onBatchComplete
19065 } = {}) {
19066 const [uploadingFiles, setUploadingFiles] = (0, import_element66.useState)(
19067 []
19068 );
19069 const clearCompleted = (0, import_element66.useCallback)(() => {
19070 setUploadingFiles(
19071 (prev) => prev.filter((item) => item.status !== "uploaded")
19072 );
19073 }, []);
19074 const dismissError = (0, import_element66.useCallback)((fileId) => {
19075 setUploadingFiles(
19076 (prev) => prev.filter((item) => item.id !== fileId)
19077 );
19078 }, []);
19079 const registerBatch = (0, import_element66.useCallback)(
19080 (files) => {
19081 const batchId = String(++batchIdCounter);
19082 const batchSize = files.length;
19083 const newEntries = files.map((file) => ({
19084 id: String(++idCounter),
19085 batchId,
19086 name: file.name,
19087 status: "uploading"
19088 }));
19089 setUploadingFiles((prev) => [...prev, ...newEntries]);
19090 let successCount = 0;
19091 let errorCount = 0;
19092 let batchDone = false;
19093 let successAttachments = [];
19094 const completeBatchIfDone = () => {
19095 if (batchDone || successCount + errorCount < batchSize) {
19096 return;
19097 }
19098 batchDone = true;
19099 setUploadingFiles(
19100 (prev) => prev.map(
19101 (item) => item.batchId === batchId && item.status === "uploading" ? {
19102 ...item,
19103 status: "uploaded"
19104 } : item
19105 )
19106 );
19107 onBatchComplete?.(successAttachments);
19108 };
19109 const onFileChange = (attachments) => {
19110 if (batchDone) {
19111 return;
19112 }
19113 const allReal = attachments.every(
19114 (attachment) => attachment.id && attachment.url && !(0, import_blob2.isBlobURL)(attachment.url)
19115 );
19116 if (!allReal) {
19117 return;
19118 }
19119 successCount = attachments.length;
19120 successAttachments = attachments;
19121 completeBatchIfDone();
19122 };
19123 const onError = (error) => {
19124 const fileName = error instanceof UploadError ? error.file.name : void 0;
19125 setUploadingFiles((prev) => {
19126 let matched = false;
19127 return prev.map((item) => {
19128 if (!matched && item.batchId === batchId && item.status === "uploading" && (!fileName || item.name === fileName)) {
19129 matched = true;
19130 return {
19131 ...item,
19132 status: "error",
19133 error: error.message
19134 };
19135 }
19136 return item;
19137 });
19138 });
19139 errorCount++;
19140 completeBatchIfDone();
19141 };
19142 return { onFileChange, onError };
19143 },
19144 [onBatchComplete]
19145 );
19146 const allComplete = uploadingFiles.length > 0 && uploadingFiles.every((item) => item.status !== "uploading");
19147 return {
19148 uploadingFiles,
19149 registerBatch,
19150 dismissError,
19151 clearCompleted,
19152 allComplete
19153 };
19154 }
19155
19156 // packages/media-utils/build-module/components/media-upload-modal/index.mjs
19157 var import_jsx_runtime109 = __toESM(require_jsx_runtime(), 1);
19158 var { useEntityRecordsWithPermissions } = unlock3(import_core_data6.privateApis);
19159 var LAYOUT_PICKER_GRID2 = "pickerGrid";
19160 var LAYOUT_PICKER_TABLE2 = "pickerTable";
19161 var NOTICES_CONTEXT = "media-modal";
19162 var NOTICE_ID_UPLOAD_PROGRESS = "media-modal-upload-progress";
19163 var defaultView = {
19164 type: LAYOUT_PICKER_GRID2,
19165 fields: [],
19166 showTitle: false,
19167 titleField: "title",
19168 mediaField: "media_thumbnail",
19169 search: "",
19170 page: 1,
19171 perPage: 50,
19172 filters: [],
19173 layout: {
19174 previewSize: 170,
19175 density: "compact"
19176 }
19177 };
19178 var defaultLayouts = {
19179 [LAYOUT_PICKER_GRID2]: {
19180 fields: [],
19181 showTitle: false,
19182 layout: {
19183 previewSize: 170,
19184 density: "compact"
19185 }
19186 },
19187 [LAYOUT_PICKER_TABLE2]: {
19188 fields: [
19189 "filename",
19190 "filesize",
19191 "media_dimensions",
19192 "author",
19193 "date"
19194 ],
19195 showTitle: true
19196 }
19197 };
19198 function MediaUploadModal({
19199 allowedTypes,
19200 multiple = false,
19201 value,
19202 onSelect,
19203 onClose,
19204 onUpload,
19205 title = (0, import_i18n66.__)("Select Media"),
19206 isOpen,
19207 isDismissible = true,
19208 modalClass,
19209 search = true,
19210 searchLabel = (0, import_i18n66.__)("Search media")
19211 }) {
19212 const [selection, setSelection] = (0, import_element67.useState)(() => {
19213 if (!value) {
19214 return [];
19215 }
19216 return Array.isArray(value) ? value.map(String) : [String(value)];
19217 });
19218 const { createSuccessNotice, removeAllNotices } = (0, import_data13.useDispatch)(import_notices.store);
19219 const invalidateAttachmentResolutions = useInvalidateAttachmentResolutions();
19220 const { view, updateView, isModified, resetToDefault } = useView({
19221 kind: "postType",
19222 name: "attachment",
19223 slug: "media-modal",
19224 defaultView
19225 });
19226 const queryArgs = (0, import_element67.useMemo)(() => {
19227 const filters = {};
19228 view.filters?.forEach((filter) => {
19229 if (filter.field === "media_type") {
19230 filters.media_type = filter.value;
19231 }
19232 if (filter.field === "author") {
19233 if (filter.operator === "isAny") {
19234 filters.author = filter.value;
19235 } else if (filter.operator === "isNone") {
19236 filters.author_exclude = filter.value;
19237 }
19238 }
19239 if (filter.field === "date" || filter.field === "modified") {
19240 if (filter.operator === "before") {
19241 filters.before = filter.value;
19242 } else if (filter.operator === "after") {
19243 filters.after = filter.value;
19244 }
19245 }
19246 if (filter.field === "mime_type") {
19247 filters.mime_type = filter.value;
19248 }
19249 });
19250 if (!filters.media_type) {
19251 filters.media_type = allowedTypes?.includes("*") ? void 0 : allowedTypes;
19252 }
19253 return {
19254 per_page: view.perPage || 20,
19255 page: view.page || 1,
19256 status: "inherit",
19257 order: view.sort?.direction,
19258 orderby: view.sort?.field,
19259 search: view.search,
19260 _embed: "author,wp:attached-to",
19261 ...filters
19262 };
19263 }, [view, allowedTypes]);
19264 const handleBatchComplete = (0, import_element67.useCallback)(
19265 (attachments) => {
19266 const uploadedIds = attachments.map((attachment) => String(attachment.id)).filter(Boolean);
19267 if (multiple) {
19268 setSelection((prev) => {
19269 const existing = new Set(prev);
19270 const newIds = uploadedIds.filter(
19271 (id) => !existing.has(id)
19272 );
19273 return [...prev, ...newIds];
19274 });
19275 } else {
19276 setSelection(uploadedIds.slice(0, 1));
19277 }
19278 invalidateAttachmentResolutions();
19279 },
19280 [multiple, invalidateAttachmentResolutions]
19281 );
19282 const {
19283 uploadingFiles,
19284 registerBatch,
19285 dismissError,
19286 clearCompleted,
19287 allComplete
19288 } = useUploadStatus({ onBatchComplete: handleBatchComplete });
19289 const isPopoverOpenRef = (0, import_element67.useRef)(false);
19290 const handlePopoverOpenChange = (0, import_element67.useCallback)(
19291 (open) => {
19292 isPopoverOpenRef.current = open;
19293 if (!open) {
19294 clearCompleted();
19295 }
19296 },
19297 [clearCompleted]
19298 );
19299 const {
19300 records: mediaRecords,
19301 isResolving: isLoading,
19302 totalItems,
19303 totalPages
19304 } = useEntityRecordsWithPermissions("postType", "attachment", queryArgs);
19305 const fields = (0, import_element67.useMemo)(
19306 () => [
19307 // Media field definitions from @wordpress/media-fields
19308 // Cast is safe because RestAttachment has the same properties as Attachment
19309 {
19310 ...media_thumbnail_default,
19311 enableHiding: false
19312 // Within the modal, the thumbnail should always be shown.
19313 },
19314 {
19315 id: "title",
19316 type: "text",
19317 label: (0, import_i18n66.__)("Title"),
19318 getValue: ({ item }) => {
19319 const titleValue = item.title.raw || item.title.rendered;
19320 return titleValue || (0, import_i18n66.__)("(no title)");
19321 }
19322 },
19323 alt_text_default,
19324 caption_default,
19325 description_default,
19326 date_added_default,
19327 date_modified_default,
19328 author_default,
19329 filename_default,
19330 filesize_default,
19331 media_dimensions_default,
19332 mime_type_default,
19333 attached_to_default
19334 ],
19335 []
19336 );
19337 const actions = (0, import_element67.useMemo)(
19338 () => [
19339 {
19340 id: "select",
19341 label: (0, import_i18n66.__)("Select"),
19342 isPrimary: true,
19343 supportsBulk: multiple,
19344 async callback() {
19345 if (selection.length === 0) {
19346 return;
19347 }
19348 const selectedPostsQuery = {
19349 include: selection,
19350 per_page: -1
19351 };
19352 const selectedPosts = await (0, import_data13.resolveSelect)(
19353 import_core_data6.store
19354 ).getEntityRecords(
19355 "postType",
19356 "attachment",
19357 selectedPostsQuery
19358 );
19359 const transformedPosts = (selectedPosts ?? []).map(transformAttachment).filter(Boolean);
19360 const selectedItems = multiple ? transformedPosts : transformedPosts?.[0];
19361 removeAllNotices("snackbar", NOTICES_CONTEXT);
19362 onSelect(selectedItems);
19363 }
19364 }
19365 ],
19366 [multiple, onSelect, selection, removeAllNotices]
19367 );
19368 const handleModalClose = (0, import_element67.useCallback)(() => {
19369 removeAllNotices("snackbar", NOTICES_CONTEXT);
19370 onClose?.();
19371 }, [removeAllNotices, onClose]);
19372 const handleUpload = onUpload || uploadMedia;
19373 const prevAllCompleteRef = (0, import_element67.useRef)(false);
19374 (0, import_element67.useEffect)(() => {
19375 if (allComplete && !prevAllCompleteRef.current) {
19376 const completeCount = uploadingFiles.filter(
19377 (file) => file.status === "uploaded"
19378 ).length;
19379 if (completeCount > 0) {
19380 createSuccessNotice(
19381 (0, import_i18n66.sprintf)(
19382 // translators: %s: number of files
19383 (0, import_i18n66._n)(
19384 "Uploaded %s file",
19385 "Uploaded %s files",
19386 completeCount
19387 ),
19388 completeCount.toLocaleString()
19389 ),
19390 {
19391 type: "snackbar",
19392 context: NOTICES_CONTEXT,
19393 id: NOTICE_ID_UPLOAD_PROGRESS
19394 }
19395 );
19396 }
19397 if (!isPopoverOpenRef.current) {
19398 clearCompleted();
19399 }
19400 }
19401 prevAllCompleteRef.current = allComplete;
19402 }, [allComplete, uploadingFiles, createSuccessNotice, clearCompleted]);
19403 const handleFileSelect = (0, import_element67.useCallback)(
19404 (event) => {
19405 const files = event.target.files;
19406 if (files && files.length > 0) {
19407 const filesArray = Array.from(files);
19408 const { onFileChange, onError } = registerBatch(filesArray);
19409 handleUpload({
19410 allowedTypes,
19411 filesList: filesArray,
19412 onFileChange,
19413 onError
19414 });
19415 }
19416 },
19417 [allowedTypes, handleUpload, registerBatch]
19418 );
19419 const paginationInfo = (0, import_element67.useMemo)(
19420 () => ({
19421 totalItems,
19422 totalPages
19423 }),
19424 [totalItems, totalPages]
19425 );
19426 const acceptTypes = (0, import_element67.useMemo)(() => {
19427 if (allowedTypes?.includes("*")) {
19428 return void 0;
19429 }
19430 return allowedTypes?.join(",");
19431 }, [allowedTypes]);
19432 if (!isOpen) {
19433 return null;
19434 }
19435 return /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19436 import_components54.Modal,
19437 {
19438 title,
19439 onRequestClose: handleModalClose,
19440 isDismissible,
19441 className: modalClass,
19442 overlayClassName: "media-upload-modal",
19443 size: "fill",
19444 headerActions: /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19445 import_components54.FormFileUpload,
19446 {
19447 accept: acceptTypes,
19448 multiple: true,
19449 onChange: handleFileSelect,
19450 __next40pxDefaultSize: true,
19451 render: ({ openFileDialog }) => /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19452 import_components54.Button,
19453 {
19454 onClick: openFileDialog,
19455 icon: upload_default,
19456 __next40pxDefaultSize: true,
19457 children: (0, import_i18n66.__)("Upload media")
19458 }
19459 )
19460 }
19461 ),
19462 children: [
19463 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19464 import_components54.DropZone,
19465 {
19466 onFilesDrop: (files) => {
19467 let filteredFiles = files;
19468 if (allowedTypes && !allowedTypes.includes("*")) {
19469 filteredFiles = files.filter(
19470 (file) => allowedTypes.some((allowedType) => {
19471 return file.type === allowedType || file.type.startsWith(
19472 allowedType.replace("*", "")
19473 );
19474 })
19475 );
19476 }
19477 if (filteredFiles.length > 0) {
19478 const { onFileChange, onError } = registerBatch(filteredFiles);
19479 handleUpload({
19480 allowedTypes,
19481 filesList: filteredFiles,
19482 onFileChange,
19483 onError
19484 });
19485 }
19486 },
19487 label: (0, import_i18n66.__)("Drop files to upload")
19488 }
19489 ),
19490 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19491 dataviews_picker_default,
19492 {
19493 data: mediaRecords || [],
19494 fields,
19495 view,
19496 onChangeView: updateView,
19497 actions,
19498 selection,
19499 onChangeSelection: setSelection,
19500 isLoading,
19501 paginationInfo,
19502 defaultLayouts,
19503 getItemId: (item) => String(item.id),
19504 itemListLabel: (0, import_i18n66.__)("Media items"),
19505 onReset: isModified ? resetToDefault : false,
19506 children: [
19507 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19508 Stack,
19509 {
19510 direction: "row",
19511 align: "top",
19512 justify: "space-between",
19513 className: "dataviews__view-actions",
19514 gap: "xs",
19515 children: [
19516 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19517 Stack,
19518 {
19519 direction: "row",
19520 gap: "sm",
19521 justify: "start",
19522 className: "dataviews__search",
19523 children: [
19524 search && /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.Search, { label: searchLabel }),
19525 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.FiltersToggle, {})
19526 ]
19527 }
19528 ),
19529 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(Stack, { direction: "row", gap: "xs", style: { flexShrink: 0 }, children: [
19530 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.LayoutSwitcher, {}),
19531 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.ViewConfig, {})
19532 ] })
19533 ]
19534 }
19535 ),
19536 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.FiltersToggled, { className: "dataviews-filters__container" }),
19537 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.Layout, {}),
19538 /* @__PURE__ */ (0, import_jsx_runtime109.jsxs)(
19539 "div",
19540 {
19541 className: clsx_default("media-upload-modal__footer", {
19542 "is-uploading": uploadingFiles.length > 0
19543 }),
19544 children: [
19545 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19546 UploadStatusPopover,
19547 {
19548 uploadingFiles,
19549 onDismissError: dismissError,
19550 onOpenChange: handlePopoverOpenChange
19551 }
19552 ),
19553 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(dataviews_picker_default.BulkActionToolbar, {})
19554 ]
19555 }
19556 )
19557 ]
19558 }
19559 ),
19560 (0, import_element67.createPortal)(
19561 /* @__PURE__ */ (0, import_jsx_runtime109.jsx)(
19562 import_notices.SnackbarNotices,
19563 {
19564 className: "media-upload-modal__snackbar",
19565 context: NOTICES_CONTEXT
19566 }
19567 ),
19568 document.body
19569 )
19570 ]
19571 }
19572 );
19573 }
19574
19575 // packages/media-utils/build-module/private-apis.mjs
19576 var privateApis12 = {};
19577 lock3(privateApis12, {
19578 sideloadMedia,
19579 MediaUploadModal
19580 });
19581 return __toCommonJS(index_exports);
19582 })();
19583 /*! Bundled license information:
19584
19585 use-sync-external-store/cjs/use-sync-external-store-shim.development.js:
19586 (**
19587 * @license React
19588 * use-sync-external-store-shim.development.js
19589 *
19590 * Copyright (c) Meta Platforms, Inc. and affiliates.
19591 *
19592 * This source code is licensed under the MIT license found in the
19593 * LICENSE file in the root directory of this source tree.
19594 *)
19595 */
19596 //# sourceMappingURL=index.js.map
19597