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

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

17,679 lines 622.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2 var wp;
3 (wp ||= {}).mediaUtils = (() => {
4 var __create = Object.create;
5 var __defProp = Object.defineProperty;
6 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7 var __getOwnPropNames = Object.getOwnPropertyNames;
8 var __getProtoOf = Object.getPrototypeOf;
9 var __hasOwnProp = Object.prototype.hasOwnProperty;
10 var __commonJS = (cb, mod) => function __require() {
11 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12 };
13 var __export = (target, all) => {
14 for (var name in all)
15 __defProp(target, name, { get: all[name], enumerable: true });
16 };
17 var __copyProps = (to, from, except, desc) => {
18 if (from && typeof from === "object" || typeof from === "function") {
19 for (let key of __getOwnPropNames(from))
20 if (!__hasOwnProp.call(to, key) && key !== except)
21 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22 }
23 return to;
24 };
25 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26 // If the importer is in node compatibility mode or this is not an ESM
27 // file that has been converted to a CommonJS file using a Babel-
28 // compatible transform (i.e. "__esModule" has not been set), then set
29 // "default" to the CommonJS "module.exports" for node compatibility.
30 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31 mod
32 ));
33 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
35 // package-external:@wordpress/element
36 var require_element = __commonJS({
37 "package-external:@wordpress/element"(exports, module) {
38 module.exports = window.wp.element;
39 }
40 });
41
42 // package-external:@wordpress/i18n
43 var require_i18n = __commonJS({
44 "package-external:@wordpress/i18n"(exports, module) {
45 module.exports = window.wp.i18n;
46 }
47 });
48
49 // package-external:@wordpress/blob
50 var require_blob = __commonJS({
51 "package-external:@wordpress/blob"(exports, module) {
52 module.exports = window.wp.blob;
53 }
54 });
55
56 // package-external:@wordpress/api-fetch
57 var require_api_fetch = __commonJS({
58 "package-external:@wordpress/api-fetch"(exports, module) {
59 module.exports = window.wp.apiFetch;
60 }
61 });
62
63 // package-external:@wordpress/core-data
64 var require_core_data = __commonJS({
65 "package-external:@wordpress/core-data"(exports, module) {
66 module.exports = window.wp.coreData;
67 }
68 });
69
70 // package-external:@wordpress/data
71 var require_data = __commonJS({
72 "package-external:@wordpress/data"(exports, module) {
73 module.exports = window.wp.data;
74 }
75 });
76
77 // package-external:@wordpress/components
78 var require_components = __commonJS({
79 "package-external:@wordpress/components"(exports, module) {
80 module.exports = window.wp.components;
81 }
82 });
83
84 // package-external:@wordpress/primitives
85 var require_primitives = __commonJS({
86 "package-external:@wordpress/primitives"(exports, module) {
87 module.exports = window.wp.primitives;
88 }
89 });
90
91 // vendor-external:react/jsx-runtime
92 var require_jsx_runtime = __commonJS({
93 "vendor-external:react/jsx-runtime"(exports, module) {
94 module.exports = window.ReactJSXRuntime;
95 }
96 });
97
98 // package-external:@wordpress/compose
99 var require_compose = __commonJS({
100 "package-external:@wordpress/compose"(exports, module) {
101 module.exports = window.wp.compose;
102 }
103 });
104
105 // vendor-external:react
106 var require_react = __commonJS({
107 "vendor-external:react"(exports, module) {
108 module.exports = window.React;
109 }
110 });
111
112 // vendor-external:react-dom
113 var require_react_dom = __commonJS({
114 "vendor-external:react-dom"(exports, module) {
115 module.exports = window.ReactDOM;
116 }
117 });
118
119 // node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js
120 var require_use_sync_external_store_shim_development = __commonJS({
121 "node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js"(exports) {
122 "use strict";
123 (function() {
124 function is(x2, y2) {
125 return x2 === y2 && (0 !== x2 || 1 / x2 === 1 / y2) || x2 !== x2 && y2 !== y2;
126 }
127 function useSyncExternalStore$2(subscribe2, getSnapshot) {
128 didWarnOld18Alpha || void 0 === React8.startTransition || (didWarnOld18Alpha = true, console.error(
129 "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
130 ));
131 var value = getSnapshot();
132 if (!didWarnUncachedGetSnapshot) {
133 var cachedValue = getSnapshot();
134 objectIs(value, cachedValue) || (console.error(
135 "The result of getSnapshot should be cached to avoid an infinite loop"
136 ), didWarnUncachedGetSnapshot = true);
137 }
138 cachedValue = useState27({
139 inst: { value, getSnapshot }
140 });
141 var inst = cachedValue[0].inst, forceUpdate = cachedValue[1];
142 useLayoutEffect2(
143 function() {
144 inst.value = value;
145 inst.getSnapshot = getSnapshot;
146 checkIfSnapshotChanged(inst) && forceUpdate({ inst });
147 },
148 [subscribe2, value, getSnapshot]
149 );
150 useEffect19(
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, useState27 = React8.useState, useEffect19 = React8.useEffect, useLayoutEffect2 = 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/keycodes
196 var require_keycodes = __commonJS({
197 "package-external:@wordpress/keycodes"(exports, module) {
198 module.exports = window.wp.keycodes;
199 }
200 });
201
202 // package-external:@wordpress/private-apis
203 var require_private_apis = __commonJS({
204 "package-external:@wordpress/private-apis"(exports, module) {
205 module.exports = window.wp.privateApis;
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/warning
748 var require_warning = __commonJS({
749 "package-external:@wordpress/warning"(exports, module) {
750 module.exports = window.wp.warning;
751 }
752 });
753
754 // package-external:@wordpress/date
755 var require_date = __commonJS({
756 "package-external:@wordpress/date"(exports, module) {
757 module.exports = window.wp.date;
758 }
759 });
760
761 // package-external:@wordpress/url
762 var require_url = __commonJS({
763 "package-external:@wordpress/url"(exports, module) {
764 module.exports = window.wp.url;
765 }
766 });
767
768 // packages/media-utils/build-module/index.mjs
769 var index_exports = {};
770 __export(index_exports, {
771 MediaUpload: () => media_upload_default,
772 privateApis: () => privateApis11,
773 transformAttachment: () => transformAttachment,
774 uploadMedia: () => uploadMedia,
775 validateFileSize: () => validateFileSize,
776 validateMimeType: () => validateMimeType,
777 validateMimeTypeForUser: () => validateMimeTypeForUser
778 });
779
780 // packages/media-utils/build-module/components/media-upload/index.mjs
781 var import_element = __toESM(require_element(), 1);
782 var import_i18n = __toESM(require_i18n(), 1);
783 var DEFAULT_EMPTY_GALLERY = [];
784 var getFeaturedImageMediaFrame = () => {
785 const { wp } = window;
786 return wp.media.view.MediaFrame.Select.extend({
787 /**
788 * Enables the Set Featured Image Button.
789 *
790 * @param {Object} toolbar toolbar for featured image state
791 * @return {void}
792 */
793 featuredImageToolbar(toolbar) {
794 this.createSelectToolbar(toolbar, {
795 text: wp.media.view.l10n.setFeaturedImage,
796 state: this.options.state
797 });
798 },
799 /**
800 * Handle the edit state requirements of selected media item.
801 *
802 * @return {void}
803 */
804 editState() {
805 const selection = this.state("featured-image").get("selection");
806 const view = new wp.media.view.EditImage({
807 model: selection.single(),
808 controller: this
809 }).render();
810 this.content.set(view);
811 view.loadEditor();
812 },
813 /**
814 * Create the default states.
815 *
816 * @return {void}
817 */
818 createStates: function createStates() {
819 this.on(
820 "toolbar:create:featured-image",
821 this.featuredImageToolbar,
822 this
823 );
824 this.on("content:render:edit-image", this.editState, this);
825 this.states.add([
826 new wp.media.controller.FeaturedImage(),
827 new wp.media.controller.EditImage({
828 model: this.options.editImage
829 })
830 ]);
831 }
832 });
833 };
834 var getSingleMediaFrame = () => {
835 const { wp } = window;
836 return wp.media.view.MediaFrame.Select.extend({
837 /**
838 * Create the default states on the frame.
839 */
840 createStates() {
841 const options = this.options;
842 if (this.options.states) {
843 return;
844 }
845 this.states.add([
846 // Main states.
847 new wp.media.controller.Library({
848 library: wp.media.query(options.library),
849 multiple: options.multiple,
850 title: options.title,
851 priority: 20,
852 filterable: "uploaded"
853 // Allow filtering by uploaded images.
854 }),
855 new wp.media.controller.EditImage({
856 model: options.editImage
857 })
858 ]);
859 }
860 });
861 };
862 var getGalleryDetailsMediaFrame = () => {
863 const { wp } = window;
864 return wp.media.view.MediaFrame.Post.extend({
865 /**
866 * Set up gallery toolbar.
867 *
868 * @return {void}
869 */
870 galleryToolbar() {
871 const editing = this.state().get("editing");
872 this.toolbar.set(
873 new wp.media.view.Toolbar({
874 controller: this,
875 items: {
876 insert: {
877 style: "primary",
878 text: editing ? wp.media.view.l10n.updateGallery : wp.media.view.l10n.insertGallery,
879 priority: 80,
880 requires: { library: true },
881 /**
882 * @fires wp.media.controller.State#update
883 */
884 click() {
885 const controller = this.controller, state = controller.state();
886 controller.close();
887 state.trigger(
888 "update",
889 state.get("library")
890 );
891 controller.setState(controller.options.state);
892 controller.reset();
893 }
894 }
895 }
896 })
897 );
898 },
899 /**
900 * Handle the edit state requirements of selected media item.
901 *
902 * @return {void}
903 */
904 editState() {
905 const selection = this.state("gallery").get("selection");
906 const view = new wp.media.view.EditImage({
907 model: selection.single(),
908 controller: this
909 }).render();
910 this.content.set(view);
911 view.loadEditor();
912 },
913 /**
914 * Create the default states.
915 *
916 * @return {void}
917 */
918 createStates: function createStates() {
919 this.on("toolbar:create:main-gallery", this.galleryToolbar, this);
920 this.on("content:render:edit-image", this.editState, this);
921 this.states.add([
922 new wp.media.controller.Library({
923 id: "gallery",
924 title: wp.media.view.l10n.createGalleryTitle,
925 priority: 40,
926 toolbar: "main-gallery",
927 filterable: "uploaded",
928 multiple: "add",
929 editable: false,
930 library: wp.media.query({
931 type: "image",
932 ...this.options.library
933 })
934 }),
935 new wp.media.controller.EditImage({
936 model: this.options.editImage
937 }),
938 new wp.media.controller.GalleryEdit({
939 library: this.options.selection,
940 editing: this.options.editing,
941 menu: "gallery",
942 displaySettings: false,
943 multiple: true
944 }),
945 new wp.media.controller.GalleryAdd()
946 ]);
947 }
948 });
949 };
950 var slimImageObject = (img) => {
951 const attrSet = [
952 "sizes",
953 "mime",
954 "type",
955 "subtype",
956 "id",
957 "url",
958 "alt",
959 "link",
960 "caption"
961 ];
962 return attrSet.reduce((result, key) => {
963 if (img?.hasOwnProperty(key)) {
964 result[key] = img[key];
965 }
966 return result;
967 }, {});
968 };
969 var getAttachmentsCollection = (ids) => {
970 const { wp } = window;
971 return wp.media.query({
972 order: "ASC",
973 orderby: "post__in",
974 post__in: ids,
975 posts_per_page: -1,
976 query: true,
977 type: "image"
978 });
979 };
980 var MediaUpload = class extends import_element.Component {
981 constructor() {
982 super(...arguments);
983 this.openModal = this.openModal.bind(this);
984 this.onOpen = this.onOpen.bind(this);
985 this.onSelect = this.onSelect.bind(this);
986 this.onUpdate = this.onUpdate.bind(this);
987 this.onClose = this.onClose.bind(this);
988 }
989 initializeListeners() {
990 this.frame.on("select", this.onSelect);
991 this.frame.on("update", this.onUpdate);
992 this.frame.on("open", this.onOpen);
993 this.frame.on("close", this.onClose);
994 }
995 /**
996 * Sets the Gallery frame and initializes listeners.
997 *
998 * @return {void}
999 */
1000 buildAndSetGalleryFrame() {
1001 const {
1002 addToGallery = false,
1003 allowedTypes,
1004 multiple = false,
1005 value = DEFAULT_EMPTY_GALLERY
1006 } = this.props;
1007 if (value === this.lastGalleryValue) {
1008 return;
1009 }
1010 const { wp } = window;
1011 this.lastGalleryValue = value;
1012 if (this.frame) {
1013 this.frame.remove();
1014 }
1015 let currentState;
1016 if (addToGallery) {
1017 currentState = "gallery-library";
1018 } else {
1019 currentState = value && value.length ? "gallery-edit" : "gallery";
1020 }
1021 if (!this.GalleryDetailsMediaFrame) {
1022 this.GalleryDetailsMediaFrame = getGalleryDetailsMediaFrame();
1023 }
1024 const attachments = getAttachmentsCollection(value);
1025 const selection = new wp.media.model.Selection(attachments.models, {
1026 props: attachments.props.toJSON(),
1027 multiple
1028 });
1029 this.frame = new this.GalleryDetailsMediaFrame({
1030 mimeType: allowedTypes,
1031 state: currentState,
1032 multiple,
1033 selection,
1034 editing: !!value?.length
1035 });
1036 wp.media.frame = this.frame;
1037 this.initializeListeners();
1038 }
1039 /**
1040 * Initializes the Media Library requirements for the featured image flow.
1041 *
1042 * @return {void}
1043 */
1044 buildAndSetFeatureImageFrame() {
1045 const { wp } = window;
1046 const { value: featuredImageId, multiple, allowedTypes } = this.props;
1047 const featuredImageFrame = getFeaturedImageMediaFrame();
1048 const attachments = getAttachmentsCollection(featuredImageId);
1049 const selection = new wp.media.model.Selection(attachments.models, {
1050 props: attachments.props.toJSON()
1051 });
1052 this.frame = new featuredImageFrame({
1053 mimeType: allowedTypes,
1054 state: "featured-image",
1055 multiple,
1056 selection,
1057 editing: featuredImageId
1058 });
1059 wp.media.frame = this.frame;
1060 wp.media.view.settings.post = {
1061 ...wp.media.view.settings.post,
1062 featuredImageId: featuredImageId || -1
1063 };
1064 }
1065 /**
1066 * Initializes the Media Library requirements for the single image flow.
1067 *
1068 * @return {void}
1069 */
1070 buildAndSetSingleMediaFrame() {
1071 const { wp } = window;
1072 const {
1073 allowedTypes,
1074 multiple = false,
1075 title = (0, import_i18n.__)("Select or Upload Media"),
1076 value
1077 } = this.props;
1078 const frameConfig = {
1079 title,
1080 multiple
1081 };
1082 if (!!allowedTypes) {
1083 frameConfig.library = { type: allowedTypes };
1084 }
1085 if (this.frame) {
1086 this.frame.remove();
1087 }
1088 const singleImageFrame = getSingleMediaFrame();
1089 const attachments = getAttachmentsCollection(value);
1090 const selection = new wp.media.model.Selection(attachments.models, {
1091 props: attachments.props.toJSON()
1092 });
1093 this.frame = new singleImageFrame({
1094 mimeType: allowedTypes,
1095 multiple,
1096 selection,
1097 ...frameConfig
1098 });
1099 wp.media.frame = this.frame;
1100 }
1101 componentWillUnmount() {
1102 this.frame?.remove();
1103 }
1104 onUpdate(selections) {
1105 const { onSelect, multiple = false } = this.props;
1106 const state = this.frame.state();
1107 const selectedImages = selections || state.get("selection");
1108 if (!selectedImages || !selectedImages.models.length) {
1109 return;
1110 }
1111 if (multiple) {
1112 onSelect(
1113 selectedImages.models.map(
1114 (model) => slimImageObject(model.toJSON())
1115 )
1116 );
1117 } else {
1118 onSelect(slimImageObject(selectedImages.models[0].toJSON()));
1119 }
1120 }
1121 onSelect() {
1122 const { onSelect, multiple = false } = this.props;
1123 const attachment = this.frame.state().get("selection").toJSON();
1124 onSelect(multiple ? attachment : attachment[0]);
1125 }
1126 onOpen() {
1127 const { wp } = window;
1128 const { value } = this.props;
1129 this.updateCollection();
1130 if (this.props.mode) {
1131 this.frame.content.mode(this.props.mode);
1132 }
1133 const hasMedia = Array.isArray(value) ? !!value?.length : !!value;
1134 if (!hasMedia) {
1135 return;
1136 }
1137 const isGallery = this.props.gallery;
1138 const selection = this.frame.state().get("selection");
1139 const valueArray = Array.isArray(value) ? value : [value];
1140 if (!isGallery) {
1141 valueArray.forEach((id) => {
1142 selection.add(wp.media.attachment(id));
1143 });
1144 }
1145 const attachments = getAttachmentsCollection(valueArray);
1146 attachments.more().done(function() {
1147 if (isGallery && attachments?.models?.length) {
1148 selection.add(attachments.models);
1149 }
1150 });
1151 }
1152 onClose() {
1153 const { onClose } = this.props;
1154 if (onClose) {
1155 onClose();
1156 }
1157 this.frame.detach();
1158 }
1159 updateCollection() {
1160 const frameContent = this.frame.content.get();
1161 if (frameContent && frameContent.collection) {
1162 const collection = frameContent.collection;
1163 collection.toArray().forEach((model) => model.trigger("destroy", model));
1164 collection.mirroring._hasMore = true;
1165 collection.more();
1166 }
1167 }
1168 openModal() {
1169 const {
1170 gallery = false,
1171 unstableFeaturedImageFlow = false,
1172 modalClass
1173 } = this.props;
1174 if (gallery) {
1175 this.buildAndSetGalleryFrame();
1176 } else {
1177 this.buildAndSetSingleMediaFrame();
1178 }
1179 if (modalClass) {
1180 this.frame.$el.addClass(modalClass);
1181 }
1182 if (unstableFeaturedImageFlow) {
1183 this.buildAndSetFeatureImageFrame();
1184 }
1185 this.initializeListeners();
1186 this.frame.open();
1187 }
1188 render() {
1189 return this.props.render({ open: this.openModal });
1190 }
1191 };
1192 var media_upload_default = MediaUpload;
1193
1194 // packages/media-utils/build-module/utils/upload-media.mjs
1195 var import_i18n5 = __toESM(require_i18n(), 1);
1196 var import_blob = __toESM(require_blob(), 1);
1197
1198 // packages/media-utils/build-module/utils/upload-to-server.mjs
1199 var import_api_fetch = __toESM(require_api_fetch(), 1);
1200
1201 // packages/media-utils/build-module/utils/flatten-form-data.mjs
1202 function isPlainObject(data) {
1203 return data !== null && typeof data === "object" && Object.getPrototypeOf(data) === Object.prototype;
1204 }
1205 function flattenFormData(formData, key, data) {
1206 if (isPlainObject(data)) {
1207 for (const [name, value] of Object.entries(data)) {
1208 flattenFormData(formData, `${key}[${name}]`, value);
1209 }
1210 } else if (data !== void 0) {
1211 formData.append(key, String(data));
1212 }
1213 }
1214
1215 // packages/media-utils/build-module/utils/transform-attachment.mjs
1216 function transformAttachment(attachment) {
1217 const { alt_text, source_url, ...savedMediaProps } = attachment;
1218 return {
1219 ...savedMediaProps,
1220 alt: attachment.alt_text,
1221 caption: attachment.caption?.raw ?? "",
1222 title: attachment.title.raw,
1223 url: attachment.source_url,
1224 poster: attachment._embedded?.["wp:featuredmedia"]?.[0]?.source_url || void 0
1225 };
1226 }
1227
1228 // packages/media-utils/build-module/utils/upload-to-server.mjs
1229 async function uploadToServer(file, additionalData = {}, signal) {
1230 const data = new FormData();
1231 data.append("file", file, file.name || file.type.replace("/", "."));
1232 for (const [key, value] of Object.entries(additionalData)) {
1233 flattenFormData(
1234 data,
1235 key,
1236 value
1237 );
1238 }
1239 return transformAttachment(
1240 await (0, import_api_fetch.default)({
1241 // This allows the video block to directly get a video's poster image.
1242 path: "/wp/v2/media?_embed=wp:featuredmedia",
1243 body: data,
1244 method: "POST",
1245 signal
1246 })
1247 );
1248 }
1249
1250 // packages/media-utils/build-module/utils/validate-mime-type.mjs
1251 var import_i18n2 = __toESM(require_i18n(), 1);
1252
1253 // packages/media-utils/build-module/utils/upload-error.mjs
1254 var UploadError = class extends Error {
1255 code;
1256 file;
1257 constructor({ code, message: message2, file, cause }) {
1258 super(message2, { cause });
1259 Object.setPrototypeOf(this, new.target.prototype);
1260 this.code = code;
1261 this.file = file;
1262 }
1263 };
1264
1265 // packages/media-utils/build-module/utils/validate-mime-type.mjs
1266 function validateMimeType(file, allowedTypes) {
1267 if (!allowedTypes) {
1268 return;
1269 }
1270 const isAllowedType = allowedTypes.some((allowedType) => {
1271 if (allowedType.includes("/")) {
1272 return allowedType === file.type;
1273 }
1274 return file.type.startsWith(`${allowedType}/`);
1275 });
1276 if (file.type && !isAllowedType) {
1277 throw new UploadError({
1278 code: "MIME_TYPE_NOT_SUPPORTED",
1279 message: (0, import_i18n2.sprintf)(
1280 // translators: %s: file name.
1281 (0, import_i18n2.__)("%s: Sorry, this file type is not supported here."),
1282 file.name
1283 ),
1284 file
1285 });
1286 }
1287 }
1288
1289 // packages/media-utils/build-module/utils/validate-mime-type-for-user.mjs
1290 var import_i18n3 = __toESM(require_i18n(), 1);
1291
1292 // packages/media-utils/build-module/utils/get-mime-types-array.mjs
1293 function getMimeTypesArray(wpMimeTypesObject) {
1294 if (!wpMimeTypesObject) {
1295 return null;
1296 }
1297 return Object.entries(wpMimeTypesObject).flatMap(
1298 ([extensionsString, mime]) => {
1299 const [type] = mime.split("/");
1300 const extensions = extensionsString.split("|");
1301 return [
1302 mime,
1303 ...extensions.map(
1304 (extension) => `${type}/${extension}`
1305 )
1306 ];
1307 }
1308 );
1309 }
1310
1311 // packages/media-utils/build-module/utils/validate-mime-type-for-user.mjs
1312 function validateMimeTypeForUser(file, wpAllowedMimeTypes) {
1313 const allowedMimeTypesForUser = getMimeTypesArray(wpAllowedMimeTypes);
1314 if (!allowedMimeTypesForUser) {
1315 return;
1316 }
1317 const isAllowedMimeTypeForUser = allowedMimeTypesForUser.includes(
1318 file.type
1319 );
1320 if (file.type && !isAllowedMimeTypeForUser) {
1321 throw new UploadError({
1322 code: "MIME_TYPE_NOT_ALLOWED_FOR_USER",
1323 message: (0, import_i18n3.sprintf)(
1324 // translators: %s: file name.
1325 (0, import_i18n3.__)(
1326 "%s: Sorry, you are not allowed to upload this file type."
1327 ),
1328 file.name
1329 ),
1330 file
1331 });
1332 }
1333 }
1334
1335 // packages/media-utils/build-module/utils/validate-file-size.mjs
1336 var import_i18n4 = __toESM(require_i18n(), 1);
1337 function validateFileSize(file, maxUploadFileSize) {
1338 if (file.size <= 0) {
1339 throw new UploadError({
1340 code: "EMPTY_FILE",
1341 message: (0, import_i18n4.sprintf)(
1342 // translators: %s: file name.
1343 (0, import_i18n4.__)("%s: This file is empty."),
1344 file.name
1345 ),
1346 file
1347 });
1348 }
1349 if (maxUploadFileSize && file.size > maxUploadFileSize) {
1350 throw new UploadError({
1351 code: "SIZE_ABOVE_LIMIT",
1352 message: (0, import_i18n4.sprintf)(
1353 // translators: %s: file name.
1354 (0, import_i18n4.__)(
1355 "%s: This file exceeds the maximum upload size for this site."
1356 ),
1357 file.name
1358 ),
1359 file
1360 });
1361 }
1362 }
1363
1364 // packages/media-utils/build-module/utils/upload-media.mjs
1365 function uploadMedia({
1366 wpAllowedMimeTypes,
1367 allowedTypes,
1368 additionalData = {},
1369 filesList,
1370 maxUploadFileSize,
1371 onError,
1372 onFileChange,
1373 signal,
1374 multiple = true
1375 }) {
1376 if (!multiple && filesList.length > 1) {
1377 onError?.(new Error((0, import_i18n5.__)("Only one file can be used here.")));
1378 return;
1379 }
1380 const validFiles = [];
1381 const filesSet = [];
1382 const setAndUpdateFiles = (index, value) => {
1383 if (!window.__experimentalMediaProcessing) {
1384 if (filesSet[index]?.url) {
1385 (0, import_blob.revokeBlobURL)(filesSet[index].url);
1386 }
1387 }
1388 filesSet[index] = value;
1389 onFileChange?.(
1390 filesSet.filter((attachment) => attachment !== null)
1391 );
1392 };
1393 for (const mediaFile of filesList) {
1394 try {
1395 validateMimeTypeForUser(mediaFile, wpAllowedMimeTypes);
1396 } catch (error) {
1397 onError?.(error);
1398 continue;
1399 }
1400 try {
1401 validateMimeType(mediaFile, allowedTypes);
1402 } catch (error) {
1403 onError?.(error);
1404 continue;
1405 }
1406 try {
1407 validateFileSize(mediaFile, maxUploadFileSize);
1408 } catch (error) {
1409 onError?.(error);
1410 continue;
1411 }
1412 validFiles.push(mediaFile);
1413 if (!window.__experimentalMediaProcessing) {
1414 filesSet.push({ url: (0, import_blob.createBlobURL)(mediaFile) });
1415 onFileChange?.(filesSet);
1416 }
1417 }
1418 validFiles.map(async (file, index) => {
1419 try {
1420 const attachment = await uploadToServer(
1421 file,
1422 additionalData,
1423 signal
1424 );
1425 setAndUpdateFiles(index, attachment);
1426 } catch (error) {
1427 setAndUpdateFiles(index, null);
1428 let message2;
1429 if (typeof error === "object" && error !== null && "message" in error) {
1430 message2 = typeof error.message === "string" ? error.message : String(error.message);
1431 } else {
1432 message2 = (0, import_i18n5.sprintf)(
1433 // translators: %s: file name
1434 (0, import_i18n5.__)("Error while uploading file %s to the media library."),
1435 file.name
1436 );
1437 }
1438 onError?.(
1439 new UploadError({
1440 code: "GENERAL",
1441 message: message2,
1442 file,
1443 cause: error instanceof Error ? error : void 0
1444 })
1445 );
1446 }
1447 });
1448 }
1449
1450 // packages/media-utils/build-module/utils/sideload-media.mjs
1451 var import_i18n6 = __toESM(require_i18n(), 1);
1452
1453 // packages/media-utils/build-module/utils/sideload-to-server.mjs
1454 var import_api_fetch2 = __toESM(require_api_fetch(), 1);
1455 async function sideloadToServer(file, attachmentId, additionalData = {}, signal) {
1456 const data = new FormData();
1457 data.append("file", file, file.name || file.type.replace("/", "."));
1458 for (const [key, value] of Object.entries(additionalData)) {
1459 flattenFormData(
1460 data,
1461 key,
1462 value
1463 );
1464 }
1465 return transformAttachment(
1466 await (0, import_api_fetch2.default)({
1467 path: `/wp/v2/media/${attachmentId}/sideload`,
1468 body: data,
1469 method: "POST",
1470 signal
1471 })
1472 );
1473 }
1474
1475 // packages/media-utils/build-module/utils/sideload-media.mjs
1476 var noop = () => {
1477 };
1478 async function sideloadMedia({
1479 file,
1480 attachmentId,
1481 additionalData = {},
1482 signal,
1483 onFileChange,
1484 onError = noop
1485 }) {
1486 try {
1487 const attachment = await sideloadToServer(
1488 file,
1489 attachmentId,
1490 additionalData,
1491 signal
1492 );
1493 onFileChange?.([attachment]);
1494 } catch (error) {
1495 let message2;
1496 if (error instanceof Error) {
1497 message2 = error.message;
1498 } else {
1499 message2 = (0, import_i18n6.sprintf)(
1500 // translators: %s: file name
1501 (0, import_i18n6.__)("Error while sideloading file %s to the server."),
1502 file.name
1503 );
1504 }
1505 onError(
1506 new UploadError({
1507 code: "GENERAL",
1508 message: message2,
1509 file,
1510 cause: error instanceof Error ? error : void 0
1511 })
1512 );
1513 }
1514 }
1515
1516 // packages/media-utils/build-module/components/media-upload-modal/index.mjs
1517 var import_element58 = __toESM(require_element(), 1);
1518 var import_i18n64 = __toESM(require_i18n(), 1);
1519 var import_core_data4 = __toESM(require_core_data(), 1);
1520 var import_data9 = __toESM(require_data(), 1);
1521 var import_components52 = __toESM(require_components(), 1);
1522
1523 // packages/icons/build-module/library/arrow-down.mjs
1524 var import_primitives = __toESM(require_primitives(), 1);
1525 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
1526 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" }) });
1527
1528 // packages/icons/build-module/library/arrow-left.mjs
1529 var import_primitives2 = __toESM(require_primitives(), 1);
1530 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
1531 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" }) });
1532
1533 // packages/icons/build-module/library/arrow-right.mjs
1534 var import_primitives3 = __toESM(require_primitives(), 1);
1535 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
1536 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" }) });
1537
1538 // packages/icons/build-module/library/arrow-up.mjs
1539 var import_primitives4 = __toESM(require_primitives(), 1);
1540 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
1541 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" }) });
1542
1543 // packages/icons/build-module/library/audio.mjs
1544 var import_primitives5 = __toESM(require_primitives(), 1);
1545 var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
1546 var audio_default = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", 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" }) });
1547
1548 // packages/icons/build-module/library/block-table.mjs
1549 var import_primitives6 = __toESM(require_primitives(), 1);
1550 var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
1551 var block_table_default = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives6.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", 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" }) });
1552
1553 // packages/icons/build-module/library/category.mjs
1554 var import_primitives7 = __toESM(require_primitives(), 1);
1555 var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
1556 var category_default = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives7.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1557 import_primitives7.Path,
1558 {
1559 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",
1560 fillRule: "evenodd",
1561 clipRule: "evenodd"
1562 }
1563 ) });
1564
1565 // packages/icons/build-module/library/check.mjs
1566 var import_primitives8 = __toESM(require_primitives(), 1);
1567 var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
1568 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" }) });
1569
1570 // packages/icons/build-module/library/close-small.mjs
1571 var import_primitives9 = __toESM(require_primitives(), 1);
1572 var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
1573 var close_small_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: "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" }) });
1574
1575 // packages/icons/build-module/library/cog.mjs
1576 var import_primitives10 = __toESM(require_primitives(), 1);
1577 var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1);
1578 var cog_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)(
1579 import_primitives10.Path,
1580 {
1581 fillRule: "evenodd",
1582 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",
1583 clipRule: "evenodd"
1584 }
1585 ) });
1586
1587 // packages/icons/build-module/library/comment-author-avatar.mjs
1588 var import_primitives11 = __toESM(require_primitives(), 1);
1589 var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1);
1590 var comment_author_avatar_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)(
1591 import_primitives11.Path,
1592 {
1593 fillRule: "evenodd",
1594 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",
1595 clipRule: "evenodd"
1596 }
1597 ) });
1598
1599 // packages/icons/build-module/library/envelope.mjs
1600 var import_primitives12 = __toESM(require_primitives(), 1);
1601 var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1);
1602 var envelope_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)(
1603 import_primitives12.Path,
1604 {
1605 fillRule: "evenodd",
1606 clipRule: "evenodd",
1607 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"
1608 }
1609 ) });
1610
1611 // packages/icons/build-module/library/error.mjs
1612 var import_primitives13 = __toESM(require_primitives(), 1);
1613 var import_jsx_runtime13 = __toESM(require_jsx_runtime(), 1);
1614 var error_default = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_primitives13.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1615 import_primitives13.Path,
1616 {
1617 fillRule: "evenodd",
1618 clipRule: "evenodd",
1619 d: "M12.218 5.377a.25.25 0 0 0-.436 0l-7.29 12.96a.25.25 0 0 0 .218.373h14.58a.25.25 0 0 0 .218-.372l-7.29-12.96Zm-1.743-.735c.669-1.19 2.381-1.19 3.05 0l7.29 12.96a1.75 1.75 0 0 1-1.525 2.608H4.71a1.75 1.75 0 0 1-1.525-2.608l7.29-12.96ZM12.75 17.46h-1.5v-1.5h1.5v1.5Zm-1.5-3h1.5v-5h-1.5v5Z"
1620 }
1621 ) });
1622
1623 // packages/icons/build-module/library/file.mjs
1624 var import_primitives14 = __toESM(require_primitives(), 1);
1625 var import_jsx_runtime14 = __toESM(require_jsx_runtime(), 1);
1626 var file_default = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_primitives14.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1627 import_primitives14.Path,
1628 {
1629 fillRule: "evenodd",
1630 clipRule: "evenodd",
1631 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"
1632 }
1633 ) });
1634
1635 // packages/icons/build-module/library/format-list-bullets-rtl.mjs
1636 var import_primitives15 = __toESM(require_primitives(), 1);
1637 var import_jsx_runtime15 = __toESM(require_jsx_runtime(), 1);
1638 var format_list_bullets_rtl_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, { 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" }) });
1639
1640 // packages/icons/build-module/library/format-list-bullets.mjs
1641 var import_primitives16 = __toESM(require_primitives(), 1);
1642 var import_jsx_runtime16 = __toESM(require_jsx_runtime(), 1);
1643 var format_list_bullets_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: "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" }) });
1644
1645 // packages/icons/build-module/library/funnel.mjs
1646 var import_primitives17 = __toESM(require_primitives(), 1);
1647 var import_jsx_runtime17 = __toESM(require_jsx_runtime(), 1);
1648 var funnel_default = /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_primitives17.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_primitives17.Path, { d: "M10 17.5H14V16H10V17.5ZM6 6V7.5H18V6H6ZM8 12.5H16V11H8V12.5Z" }) });
1649
1650 // packages/icons/build-module/library/image.mjs
1651 var import_primitives18 = __toESM(require_primitives(), 1);
1652 var import_jsx_runtime18 = __toESM(require_jsx_runtime(), 1);
1653 var image_default = /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_primitives18.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_primitives18.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" }) });
1654
1655 // packages/icons/build-module/library/link.mjs
1656 var import_primitives19 = __toESM(require_primitives(), 1);
1657 var import_jsx_runtime19 = __toESM(require_jsx_runtime(), 1);
1658 var link_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: "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" }) });
1659
1660 // packages/icons/build-module/library/mobile.mjs
1661 var import_primitives20 = __toESM(require_primitives(), 1);
1662 var import_jsx_runtime20 = __toESM(require_jsx_runtime(), 1);
1663 var mobile_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: "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" }) });
1664
1665 // packages/icons/build-module/library/more-vertical.mjs
1666 var import_primitives21 = __toESM(require_primitives(), 1);
1667 var import_jsx_runtime21 = __toESM(require_jsx_runtime(), 1);
1668 var more_vertical_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: "M13 19h-2v-2h2v2zm0-6h-2v-2h2v2zm0-6h-2V5h2v2z" }) });
1669
1670 // packages/icons/build-module/library/next.mjs
1671 var import_primitives22 = __toESM(require_primitives(), 1);
1672 var import_jsx_runtime22 = __toESM(require_jsx_runtime(), 1);
1673 var next_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: "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" }) });
1674
1675 // packages/icons/build-module/library/previous.mjs
1676 var import_primitives23 = __toESM(require_primitives(), 1);
1677 var import_jsx_runtime23 = __toESM(require_jsx_runtime(), 1);
1678 var previous_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: "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" }) });
1679
1680 // packages/icons/build-module/library/scheduled.mjs
1681 var import_primitives24 = __toESM(require_primitives(), 1);
1682 var import_jsx_runtime24 = __toESM(require_jsx_runtime(), 1);
1683 var scheduled_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)(
1684 import_primitives24.Path,
1685 {
1686 fillRule: "evenodd",
1687 clipRule: "evenodd",
1688 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"
1689 }
1690 ) });
1691
1692 // packages/icons/build-module/library/search.mjs
1693 var import_primitives25 = __toESM(require_primitives(), 1);
1694 var import_jsx_runtime25 = __toESM(require_jsx_runtime(), 1);
1695 var search_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, { 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" }) });
1696
1697 // packages/icons/build-module/library/seen.mjs
1698 var import_primitives26 = __toESM(require_primitives(), 1);
1699 var import_jsx_runtime26 = __toESM(require_jsx_runtime(), 1);
1700 var seen_default = /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_primitives26.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_primitives26.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" }) });
1701
1702 // packages/icons/build-module/library/unseen.mjs
1703 var import_primitives27 = __toESM(require_primitives(), 1);
1704 var import_jsx_runtime27 = __toESM(require_jsx_runtime(), 1);
1705 var unseen_default = /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(import_primitives27.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(import_primitives27.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" }) });
1706
1707 // packages/icons/build-module/library/upload.mjs
1708 var import_primitives28 = __toESM(require_primitives(), 1);
1709 var import_jsx_runtime28 = __toESM(require_jsx_runtime(), 1);
1710 var upload_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: "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" }) });
1711
1712 // packages/icons/build-module/library/video.mjs
1713 var import_primitives29 = __toESM(require_primitives(), 1);
1714 var import_jsx_runtime29 = __toESM(require_jsx_runtime(), 1);
1715 var video_default = /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_primitives29.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_primitives29.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" }) });
1716
1717 // node_modules/@base-ui/utils/esm/useRefWithInit.js
1718 var React = __toESM(require_react(), 1);
1719 var UNINITIALIZED = {};
1720 function useRefWithInit(init2, initArg) {
1721 const ref = React.useRef(UNINITIALIZED);
1722 if (ref.current === UNINITIALIZED) {
1723 ref.current = init2(initArg);
1724 }
1725 return ref;
1726 }
1727
1728 // node_modules/@base-ui/react/esm/utils/useRenderElement.js
1729 var React4 = __toESM(require_react(), 1);
1730
1731 // node_modules/@base-ui/utils/esm/useMergedRefs.js
1732 function useMergedRefs(a2, b2, c2, d2) {
1733 const forkRef = useRefWithInit(createForkRef).current;
1734 if (didChange(forkRef, a2, b2, c2, d2)) {
1735 update(forkRef, [a2, b2, c2, d2]);
1736 }
1737 return forkRef.callback;
1738 }
1739 function useMergedRefsN(refs) {
1740 const forkRef = useRefWithInit(createForkRef).current;
1741 if (didChangeN(forkRef, refs)) {
1742 update(forkRef, refs);
1743 }
1744 return forkRef.callback;
1745 }
1746 function createForkRef() {
1747 return {
1748 callback: null,
1749 cleanup: null,
1750 refs: []
1751 };
1752 }
1753 function didChange(forkRef, a2, b2, c2, d2) {
1754 return forkRef.refs[0] !== a2 || forkRef.refs[1] !== b2 || forkRef.refs[2] !== c2 || forkRef.refs[3] !== d2;
1755 }
1756 function didChangeN(forkRef, newRefs) {
1757 return forkRef.refs.length !== newRefs.length || forkRef.refs.some((ref, index) => ref !== newRefs[index]);
1758 }
1759 function update(forkRef, refs) {
1760 forkRef.refs = refs;
1761 if (refs.every((ref) => ref == null)) {
1762 forkRef.callback = null;
1763 return;
1764 }
1765 forkRef.callback = (instance) => {
1766 if (forkRef.cleanup) {
1767 forkRef.cleanup();
1768 forkRef.cleanup = null;
1769 }
1770 if (instance != null) {
1771 const cleanupCallbacks = Array(refs.length).fill(null);
1772 for (let i2 = 0; i2 < refs.length; i2 += 1) {
1773 const ref = refs[i2];
1774 if (ref == null) {
1775 continue;
1776 }
1777 switch (typeof ref) {
1778 case "function": {
1779 const refCleanup = ref(instance);
1780 if (typeof refCleanup === "function") {
1781 cleanupCallbacks[i2] = refCleanup;
1782 }
1783 break;
1784 }
1785 case "object": {
1786 ref.current = instance;
1787 break;
1788 }
1789 default:
1790 }
1791 }
1792 forkRef.cleanup = () => {
1793 for (let i2 = 0; i2 < refs.length; i2 += 1) {
1794 const ref = refs[i2];
1795 if (ref == null) {
1796 continue;
1797 }
1798 switch (typeof ref) {
1799 case "function": {
1800 const cleanupCallback = cleanupCallbacks[i2];
1801 if (typeof cleanupCallback === "function") {
1802 cleanupCallback();
1803 } else {
1804 ref(null);
1805 }
1806 break;
1807 }
1808 case "object": {
1809 ref.current = null;
1810 break;
1811 }
1812 default:
1813 }
1814 }
1815 };
1816 }
1817 };
1818 }
1819
1820 // node_modules/@base-ui/utils/esm/getReactElementRef.js
1821 var React3 = __toESM(require_react(), 1);
1822
1823 // node_modules/@base-ui/utils/esm/reactVersion.js
1824 var React2 = __toESM(require_react(), 1);
1825 var majorVersion = parseInt(React2.version, 10);
1826 function isReactVersionAtLeast(reactVersionToCheck) {
1827 return majorVersion >= reactVersionToCheck;
1828 }
1829
1830 // node_modules/@base-ui/utils/esm/getReactElementRef.js
1831 function getReactElementRef(element) {
1832 if (!/* @__PURE__ */ React3.isValidElement(element)) {
1833 return null;
1834 }
1835 const reactElement = element;
1836 const propsWithRef = reactElement.props;
1837 return (isReactVersionAtLeast(19) ? propsWithRef?.ref : reactElement.ref) ?? null;
1838 }
1839
1840 // node_modules/@base-ui/utils/esm/mergeObjects.js
1841 function mergeObjects(a2, b2) {
1842 if (a2 && !b2) {
1843 return a2;
1844 }
1845 if (!a2 && b2) {
1846 return b2;
1847 }
1848 if (a2 || b2) {
1849 return {
1850 ...a2,
1851 ...b2
1852 };
1853 }
1854 return void 0;
1855 }
1856
1857 // node_modules/@base-ui/react/esm/utils/getStateAttributesProps.js
1858 function getStateAttributesProps(state, customMapping) {
1859 const props = {};
1860 for (const key in state) {
1861 const value = state[key];
1862 if (customMapping?.hasOwnProperty(key)) {
1863 const customProps = customMapping[key](value);
1864 if (customProps != null) {
1865 Object.assign(props, customProps);
1866 }
1867 continue;
1868 }
1869 if (value === true) {
1870 props[`data-${key.toLowerCase()}`] = "";
1871 } else if (value) {
1872 props[`data-${key.toLowerCase()}`] = value.toString();
1873 }
1874 }
1875 return props;
1876 }
1877
1878 // node_modules/@base-ui/react/esm/utils/resolveClassName.js
1879 function resolveClassName(className, state) {
1880 return typeof className === "function" ? className(state) : className;
1881 }
1882
1883 // node_modules/@base-ui/react/esm/utils/resolveStyle.js
1884 function resolveStyle(style, state) {
1885 return typeof style === "function" ? style(state) : style;
1886 }
1887
1888 // node_modules/@base-ui/react/esm/merge-props/mergeProps.js
1889 var EMPTY_PROPS = {};
1890 function mergeProps(a2, b2, c2, d2, e2) {
1891 let merged = {
1892 ...resolvePropsGetter(a2, EMPTY_PROPS)
1893 };
1894 if (b2) {
1895 merged = mergeOne(merged, b2);
1896 }
1897 if (c2) {
1898 merged = mergeOne(merged, c2);
1899 }
1900 if (d2) {
1901 merged = mergeOne(merged, d2);
1902 }
1903 if (e2) {
1904 merged = mergeOne(merged, e2);
1905 }
1906 return merged;
1907 }
1908 function mergePropsN(props) {
1909 if (props.length === 0) {
1910 return EMPTY_PROPS;
1911 }
1912 if (props.length === 1) {
1913 return resolvePropsGetter(props[0], EMPTY_PROPS);
1914 }
1915 let merged = {
1916 ...resolvePropsGetter(props[0], EMPTY_PROPS)
1917 };
1918 for (let i2 = 1; i2 < props.length; i2 += 1) {
1919 merged = mergeOne(merged, props[i2]);
1920 }
1921 return merged;
1922 }
1923 function mergeOne(merged, inputProps) {
1924 if (isPropsGetter(inputProps)) {
1925 return inputProps(merged);
1926 }
1927 return mutablyMergeInto(merged, inputProps);
1928 }
1929 function mutablyMergeInto(mergedProps, externalProps) {
1930 if (!externalProps) {
1931 return mergedProps;
1932 }
1933 for (const propName in externalProps) {
1934 const externalPropValue = externalProps[propName];
1935 switch (propName) {
1936 case "style": {
1937 mergedProps[propName] = mergeObjects(mergedProps.style, externalPropValue);
1938 break;
1939 }
1940 case "className": {
1941 mergedProps[propName] = mergeClassNames(mergedProps.className, externalPropValue);
1942 break;
1943 }
1944 default: {
1945 if (isEventHandler(propName, externalPropValue)) {
1946 mergedProps[propName] = mergeEventHandlers(mergedProps[propName], externalPropValue);
1947 } else {
1948 mergedProps[propName] = externalPropValue;
1949 }
1950 }
1951 }
1952 }
1953 return mergedProps;
1954 }
1955 function isEventHandler(key, value) {
1956 const code0 = key.charCodeAt(0);
1957 const code1 = key.charCodeAt(1);
1958 const code2 = key.charCodeAt(2);
1959 return code0 === 111 && code1 === 110 && code2 >= 65 && code2 <= 90 && (typeof value === "function" || typeof value === "undefined");
1960 }
1961 function isPropsGetter(inputProps) {
1962 return typeof inputProps === "function";
1963 }
1964 function resolvePropsGetter(inputProps, previousProps) {
1965 if (isPropsGetter(inputProps)) {
1966 return inputProps(previousProps);
1967 }
1968 return inputProps ?? EMPTY_PROPS;
1969 }
1970 function mergeEventHandlers(ourHandler, theirHandler) {
1971 if (!theirHandler) {
1972 return ourHandler;
1973 }
1974 if (!ourHandler) {
1975 return theirHandler;
1976 }
1977 return (event) => {
1978 if (isSyntheticEvent(event)) {
1979 const baseUIEvent = event;
1980 makeEventPreventable(baseUIEvent);
1981 const result2 = theirHandler(baseUIEvent);
1982 if (!baseUIEvent.baseUIHandlerPrevented) {
1983 ourHandler?.(baseUIEvent);
1984 }
1985 return result2;
1986 }
1987 const result = theirHandler(event);
1988 ourHandler?.(event);
1989 return result;
1990 };
1991 }
1992 function makeEventPreventable(event) {
1993 event.preventBaseUIHandler = () => {
1994 event.baseUIHandlerPrevented = true;
1995 };
1996 return event;
1997 }
1998 function mergeClassNames(ourClassName, theirClassName) {
1999 if (theirClassName) {
2000 if (ourClassName) {
2001 return theirClassName + " " + ourClassName;
2002 }
2003 return theirClassName;
2004 }
2005 return ourClassName;
2006 }
2007 function isSyntheticEvent(event) {
2008 return event != null && typeof event === "object" && "nativeEvent" in event;
2009 }
2010
2011 // node_modules/@base-ui/utils/esm/empty.js
2012 var EMPTY_ARRAY = Object.freeze([]);
2013 var EMPTY_OBJECT = Object.freeze({});
2014
2015 // node_modules/@base-ui/react/esm/utils/useRenderElement.js
2016 var import_react = __toESM(require_react(), 1);
2017 function useRenderElement(element, componentProps, params = {}) {
2018 const renderProp = componentProps.render;
2019 const outProps = useRenderElementProps(componentProps, params);
2020 if (params.enabled === false) {
2021 return null;
2022 }
2023 const state = params.state ?? EMPTY_OBJECT;
2024 return evaluateRenderProp(element, renderProp, outProps, state);
2025 }
2026 function useRenderElementProps(componentProps, params = {}) {
2027 const {
2028 className: classNameProp,
2029 style: styleProp,
2030 render: renderProp
2031 } = componentProps;
2032 const {
2033 state = EMPTY_OBJECT,
2034 ref,
2035 props,
2036 stateAttributesMapping,
2037 enabled = true
2038 } = params;
2039 const className = enabled ? resolveClassName(classNameProp, state) : void 0;
2040 const style = enabled ? resolveStyle(styleProp, state) : void 0;
2041 const stateProps = enabled ? getStateAttributesProps(state, stateAttributesMapping) : EMPTY_OBJECT;
2042 const outProps = enabled ? mergeObjects(stateProps, Array.isArray(props) ? mergePropsN(props) : props) ?? EMPTY_OBJECT : EMPTY_OBJECT;
2043 if (typeof document !== "undefined") {
2044 if (!enabled) {
2045 useMergedRefs(null, null);
2046 } else if (Array.isArray(ref)) {
2047 outProps.ref = useMergedRefsN([outProps.ref, getReactElementRef(renderProp), ...ref]);
2048 } else {
2049 outProps.ref = useMergedRefs(outProps.ref, getReactElementRef(renderProp), ref);
2050 }
2051 }
2052 if (!enabled) {
2053 return EMPTY_OBJECT;
2054 }
2055 if (className !== void 0) {
2056 outProps.className = mergeClassNames(outProps.className, className);
2057 }
2058 if (style !== void 0) {
2059 outProps.style = mergeObjects(outProps.style, style);
2060 }
2061 return outProps;
2062 }
2063 function evaluateRenderProp(element, render4, props, state) {
2064 if (render4) {
2065 if (typeof render4 === "function") {
2066 return render4(props, state);
2067 }
2068 const mergedProps = mergeProps(props, render4.props);
2069 mergedProps.ref = props.ref;
2070 return /* @__PURE__ */ React4.cloneElement(render4, mergedProps);
2071 }
2072 if (element) {
2073 if (typeof element === "string") {
2074 return renderTag(element, props);
2075 }
2076 }
2077 throw new Error(true ? "Base UI: Render element or function are not defined." : formatErrorMessage(8));
2078 }
2079 function renderTag(Tag, props) {
2080 if (Tag === "button") {
2081 return /* @__PURE__ */ (0, import_react.createElement)("button", {
2082 type: "button",
2083 ...props,
2084 key: props.key
2085 });
2086 }
2087 if (Tag === "img") {
2088 return /* @__PURE__ */ (0, import_react.createElement)("img", {
2089 alt: "",
2090 ...props,
2091 key: props.key
2092 });
2093 }
2094 return /* @__PURE__ */ React4.createElement(Tag, props);
2095 }
2096
2097 // node_modules/@base-ui/react/esm/use-render/useRender.js
2098 function useRender(params) {
2099 return useRenderElement(params.defaultTagName ?? "div", params, params);
2100 }
2101
2102 // node_modules/clsx/dist/clsx.mjs
2103 function r(e2) {
2104 var t2, f2, n2 = "";
2105 if ("string" == typeof e2 || "number" == typeof e2) n2 += e2;
2106 else if ("object" == typeof e2) if (Array.isArray(e2)) {
2107 var o2 = e2.length;
2108 for (t2 = 0; t2 < o2; t2++) e2[t2] && (f2 = r(e2[t2])) && (n2 && (n2 += " "), n2 += f2);
2109 } else for (f2 in e2) e2[f2] && (n2 && (n2 += " "), n2 += f2);
2110 return n2;
2111 }
2112 function clsx() {
2113 for (var e2, t2, f2 = 0, n2 = "", o2 = arguments.length; f2 < o2; f2++) (e2 = arguments[f2]) && (t2 = r(e2)) && (n2 && (n2 += " "), n2 += t2);
2114 return n2;
2115 }
2116 var clsx_default = clsx;
2117
2118 // packages/ui/build-module/stack/stack.mjs
2119 var import_element2 = __toESM(require_element(), 1);
2120 var css = `@layer wp-ui-utilities, wp-ui-components, wp-ui-compositions, wp-ui-overrides;
2121
2122 @layer wp-ui-components {
2123 .style-module__stack__Gc4EG {
2124 display: flex;
2125 }
2126 }
2127 `;
2128 document.head.appendChild(document.createElement("style")).appendChild(document.createTextNode(css));
2129 var style_default = {
2130 "stack": "style-module__stack__Gc4EG"
2131 };
2132 var Stack = (0, import_element2.forwardRef)(function Stack2({ direction, gap, align, justify, wrap, render: render4, ...props }, ref) {
2133 const style = {
2134 gap: gap && `var(--wpds-dimension-gap-${gap})`,
2135 alignItems: align,
2136 justifyContent: justify,
2137 flexDirection: direction,
2138 flexWrap: wrap
2139 };
2140 const element = useRender({
2141 render: render4,
2142 ref,
2143 props: mergeProps(props, { style, className: style_default.stack })
2144 });
2145 return element;
2146 });
2147
2148 // packages/dataviews/build-module/components/dataviews-context/index.mjs
2149 var import_element3 = __toESM(require_element(), 1);
2150
2151 // packages/dataviews/build-module/constants.mjs
2152 var import_i18n7 = __toESM(require_i18n(), 1);
2153 var OPERATOR_IS_ANY = "isAny";
2154 var OPERATOR_IS_NONE = "isNone";
2155 var OPERATOR_IS_ALL = "isAll";
2156 var OPERATOR_IS_NOT_ALL = "isNotAll";
2157 var OPERATOR_BETWEEN = "between";
2158 var OPERATOR_IN_THE_PAST = "inThePast";
2159 var OPERATOR_OVER = "over";
2160 var OPERATOR_IS = "is";
2161 var OPERATOR_IS_NOT = "isNot";
2162 var OPERATOR_LESS_THAN = "lessThan";
2163 var OPERATOR_GREATER_THAN = "greaterThan";
2164 var OPERATOR_LESS_THAN_OR_EQUAL = "lessThanOrEqual";
2165 var OPERATOR_GREATER_THAN_OR_EQUAL = "greaterThanOrEqual";
2166 var OPERATOR_BEFORE = "before";
2167 var OPERATOR_AFTER = "after";
2168 var OPERATOR_BEFORE_INC = "beforeInc";
2169 var OPERATOR_AFTER_INC = "afterInc";
2170 var OPERATOR_CONTAINS = "contains";
2171 var OPERATOR_NOT_CONTAINS = "notContains";
2172 var OPERATOR_STARTS_WITH = "startsWith";
2173 var OPERATOR_ON = "on";
2174 var OPERATOR_NOT_ON = "notOn";
2175 var SORTING_DIRECTIONS = ["asc", "desc"];
2176 var sortArrows = { asc: "\u2191", desc: "\u2193" };
2177 var sortValues = { asc: "ascending", desc: "descending" };
2178 var sortLabels = {
2179 asc: (0, import_i18n7.__)("Sort ascending"),
2180 desc: (0, import_i18n7.__)("Sort descending")
2181 };
2182 var sortIcons = {
2183 asc: arrow_up_default,
2184 desc: arrow_down_default
2185 };
2186 var LAYOUT_TABLE = "table";
2187 var LAYOUT_GRID = "grid";
2188 var LAYOUT_LIST = "list";
2189 var LAYOUT_ACTIVITY = "activity";
2190 var LAYOUT_PICKER_GRID = "pickerGrid";
2191 var LAYOUT_PICKER_TABLE = "pickerTable";
2192
2193 // packages/dataviews/build-module/components/dataviews-context/index.mjs
2194 var DataViewsContext = (0, import_element3.createContext)({
2195 view: { type: LAYOUT_TABLE },
2196 onChangeView: () => {
2197 },
2198 fields: [],
2199 data: [],
2200 paginationInfo: {
2201 totalItems: 0,
2202 totalPages: 0
2203 },
2204 selection: [],
2205 onChangeSelection: () => {
2206 },
2207 setOpenedFilter: () => {
2208 },
2209 openedFilter: null,
2210 getItemId: (item) => item.id,
2211 isItemClickable: () => true,
2212 renderItemLink: void 0,
2213 containerWidth: 0,
2214 containerRef: (0, import_element3.createRef)(),
2215 resizeObserverRef: () => {
2216 },
2217 defaultLayouts: { list: {}, grid: {}, table: {} },
2218 filters: [],
2219 isShowingFilter: false,
2220 setIsShowingFilter: () => {
2221 },
2222 hasInfiniteScrollHandler: false,
2223 config: {
2224 perPageSizes: []
2225 }
2226 });
2227 DataViewsContext.displayName = "DataViewsContext";
2228 var dataviews_context_default = DataViewsContext;
2229
2230 // packages/dataviews/build-module/components/dataviews-layouts/index.mjs
2231 var import_i18n26 = __toESM(require_i18n(), 1);
2232
2233 // packages/dataviews/build-module/components/dataviews-layouts/table/index.mjs
2234 var import_i18n14 = __toESM(require_i18n(), 1);
2235 var import_components6 = __toESM(require_components(), 1);
2236 var import_element10 = __toESM(require_element(), 1);
2237 var import_keycodes = __toESM(require_keycodes(), 1);
2238
2239 // packages/dataviews/build-module/components/dataviews-selection-checkbox/index.mjs
2240 var import_components = __toESM(require_components(), 1);
2241 var import_i18n8 = __toESM(require_i18n(), 1);
2242 var import_jsx_runtime30 = __toESM(require_jsx_runtime(), 1);
2243 function DataViewsSelectionCheckbox({
2244 selection,
2245 onChangeSelection,
2246 item,
2247 getItemId,
2248 titleField,
2249 disabled,
2250 ...extraProps
2251 }) {
2252 const id = getItemId(item);
2253 const checked = !disabled && selection.includes(id);
2254 const selectionLabel = titleField?.getValue?.({ item }) || (0, import_i18n8.__)("(no title)");
2255 return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
2256 import_components.CheckboxControl,
2257 {
2258 className: "dataviews-selection-checkbox",
2259 "aria-label": selectionLabel,
2260 "aria-disabled": disabled,
2261 checked,
2262 onChange: () => {
2263 if (disabled) {
2264 return;
2265 }
2266 onChangeSelection(
2267 selection.includes(id) ? selection.filter((itemId) => id !== itemId) : [...selection, id]
2268 );
2269 },
2270 ...extraProps
2271 }
2272 );
2273 }
2274
2275 // packages/dataviews/build-module/components/dataviews-item-actions/index.mjs
2276 var import_components2 = __toESM(require_components(), 1);
2277 var import_i18n9 = __toESM(require_i18n(), 1);
2278 var import_element4 = __toESM(require_element(), 1);
2279 var import_data = __toESM(require_data(), 1);
2280 var import_compose = __toESM(require_compose(), 1);
2281
2282 // packages/dataviews/build-module/lock-unlock.mjs
2283 var import_private_apis = __toESM(require_private_apis(), 1);
2284 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
2285 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
2286 "@wordpress/dataviews"
2287 );
2288
2289 // packages/dataviews/build-module/components/dataviews-item-actions/index.mjs
2290 var import_jsx_runtime31 = __toESM(require_jsx_runtime(), 1);
2291 var { Menu, kebabCase } = unlock(import_components2.privateApis);
2292 function ButtonTrigger({
2293 action,
2294 onClick,
2295 items,
2296 variant
2297 }) {
2298 const label = typeof action.label === "string" ? action.label : action.label(items);
2299 return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2300 import_components2.Button,
2301 {
2302 disabled: !!action.disabled,
2303 accessibleWhenDisabled: true,
2304 size: "compact",
2305 variant,
2306 onClick,
2307 children: label
2308 }
2309 );
2310 }
2311 function MenuItemTrigger({
2312 action,
2313 onClick,
2314 items
2315 }) {
2316 const label = typeof action.label === "string" ? action.label : action.label(items);
2317 return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Menu.Item, { disabled: action.disabled, onClick, children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Menu.ItemLabel, { children: label }) });
2318 }
2319 function ActionModal({
2320 action,
2321 items,
2322 closeModal
2323 }) {
2324 const label = typeof action.label === "string" ? action.label : action.label(items);
2325 const modalHeader = typeof action.modalHeader === "function" ? action.modalHeader(items) : action.modalHeader;
2326 return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2327 import_components2.Modal,
2328 {
2329 title: modalHeader || label,
2330 __experimentalHideHeader: !!action.hideModalHeader,
2331 onRequestClose: closeModal,
2332 focusOnMount: action.modalFocusOnMount ?? true,
2333 size: action.modalSize || "medium",
2334 overlayClassName: `dataviews-action-modal dataviews-action-modal__${kebabCase(
2335 action.id
2336 )}`,
2337 children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(action.RenderModal, { items, closeModal })
2338 }
2339 );
2340 }
2341 function ActionsMenuGroup({
2342 actions,
2343 item,
2344 registry,
2345 setActiveModalAction
2346 }) {
2347 const { primaryActions, regularActions } = (0, import_element4.useMemo)(() => {
2348 return actions.reduce(
2349 (acc, action) => {
2350 (action.isPrimary ? acc.primaryActions : acc.regularActions).push(action);
2351 return acc;
2352 },
2353 {
2354 primaryActions: [],
2355 regularActions: []
2356 }
2357 );
2358 }, [actions]);
2359 const renderActionGroup = (actionList) => actionList.map((action) => /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2360 MenuItemTrigger,
2361 {
2362 action,
2363 onClick: () => {
2364 if ("RenderModal" in action) {
2365 setActiveModalAction(action);
2366 return;
2367 }
2368 action.callback([item], { registry });
2369 },
2370 items: [item]
2371 },
2372 action.id
2373 ));
2374 return /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(Menu.Group, { children: [
2375 renderActionGroup(primaryActions),
2376 primaryActions.length > 0 && regularActions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Menu.Separator, {}),
2377 renderActionGroup(regularActions)
2378 ] });
2379 }
2380 function ItemActions({
2381 item,
2382 actions,
2383 isCompact
2384 }) {
2385 const registry = (0, import_data.useRegistry)();
2386 const { primaryActions, eligibleActions } = (0, import_element4.useMemo)(() => {
2387 const _eligibleActions = actions.filter(
2388 (action) => !action.isEligible || action.isEligible(item)
2389 );
2390 const _primaryActions = _eligibleActions.filter(
2391 (action) => action.isPrimary
2392 );
2393 return {
2394 primaryActions: _primaryActions,
2395 eligibleActions: _eligibleActions
2396 };
2397 }, [actions, item]);
2398 if (isCompact) {
2399 return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2400 CompactItemActions,
2401 {
2402 item,
2403 actions: eligibleActions,
2404 isSmall: true,
2405 registry
2406 }
2407 );
2408 }
2409 return /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(
2410 Stack,
2411 {
2412 direction: "row",
2413 justify: "flex-end",
2414 className: "dataviews-item-actions",
2415 style: {
2416 flexShrink: 0,
2417 width: "auto"
2418 },
2419 children: [
2420 /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2421 PrimaryActions,
2422 {
2423 item,
2424 actions: primaryActions,
2425 registry
2426 }
2427 ),
2428 primaryActions.length < eligibleActions.length && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2429 CompactItemActions,
2430 {
2431 item,
2432 actions: eligibleActions,
2433 registry
2434 }
2435 )
2436 ]
2437 }
2438 );
2439 }
2440 function CompactItemActions({
2441 item,
2442 actions,
2443 isSmall,
2444 registry
2445 }) {
2446 const [activeModalAction, setActiveModalAction] = (0, import_element4.useState)(
2447 null
2448 );
2449 return /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(import_jsx_runtime31.Fragment, { children: [
2450 /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(Menu, { placement: "bottom-end", children: [
2451 /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2452 Menu.TriggerButton,
2453 {
2454 render: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2455 import_components2.Button,
2456 {
2457 size: isSmall ? "small" : "compact",
2458 icon: more_vertical_default,
2459 label: (0, import_i18n9.__)("Actions"),
2460 accessibleWhenDisabled: true,
2461 disabled: !actions.length,
2462 className: "dataviews-all-actions-button"
2463 }
2464 )
2465 }
2466 ),
2467 /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Menu.Popover, { children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2468 ActionsMenuGroup,
2469 {
2470 actions,
2471 item,
2472 registry,
2473 setActiveModalAction
2474 }
2475 ) })
2476 ] }),
2477 !!activeModalAction && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2478 ActionModal,
2479 {
2480 action: activeModalAction,
2481 items: [item],
2482 closeModal: () => setActiveModalAction(null)
2483 }
2484 )
2485 ] });
2486 }
2487 function PrimaryActions({
2488 item,
2489 actions,
2490 registry,
2491 buttonVariant
2492 }) {
2493 const [activeModalAction, setActiveModalAction] = (0, import_element4.useState)(null);
2494 const isMobileViewport = (0, import_compose.useViewportMatch)("medium", "<");
2495 if (isMobileViewport) {
2496 return null;
2497 }
2498 if (!Array.isArray(actions) || actions.length === 0) {
2499 return null;
2500 }
2501 return /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(import_jsx_runtime31.Fragment, { children: [
2502 actions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2503 ButtonTrigger,
2504 {
2505 action,
2506 onClick: () => {
2507 if ("RenderModal" in action) {
2508 setActiveModalAction(action);
2509 return;
2510 }
2511 action.callback([item], { registry });
2512 },
2513 items: [item],
2514 variant: buttonVariant
2515 },
2516 action.id
2517 )),
2518 !!activeModalAction && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2519 ActionModal,
2520 {
2521 action: activeModalAction,
2522 items: [item],
2523 closeModal: () => setActiveModalAction(null)
2524 }
2525 )
2526 ] });
2527 }
2528
2529 // packages/dataviews/build-module/components/dataviews-bulk-actions/index.mjs
2530 var import_components3 = __toESM(require_components(), 1);
2531 var import_i18n10 = __toESM(require_i18n(), 1);
2532 var import_element5 = __toESM(require_element(), 1);
2533 var import_data2 = __toESM(require_data(), 1);
2534 var import_compose2 = __toESM(require_compose(), 1);
2535 var import_jsx_runtime32 = __toESM(require_jsx_runtime(), 1);
2536 function useHasAPossibleBulkAction(actions, item) {
2537 return (0, import_element5.useMemo)(() => {
2538 return actions.some((action) => {
2539 return action.supportsBulk && (!action.isEligible || action.isEligible(item));
2540 });
2541 }, [actions, item]);
2542 }
2543 function useSomeItemHasAPossibleBulkAction(actions, data) {
2544 return (0, import_element5.useMemo)(() => {
2545 return data.some((item) => {
2546 return actions.some((action) => {
2547 return action.supportsBulk && (!action.isEligible || action.isEligible(item));
2548 });
2549 });
2550 }, [actions, data]);
2551 }
2552 function BulkSelectionCheckbox({
2553 selection,
2554 onChangeSelection,
2555 data,
2556 actions,
2557 getItemId
2558 }) {
2559 const selectableItems = (0, import_element5.useMemo)(() => {
2560 return data.filter((item) => {
2561 return actions.some(
2562 (action) => action.supportsBulk && (!action.isEligible || action.isEligible(item))
2563 );
2564 });
2565 }, [data, actions]);
2566 const selectedItems = data.filter(
2567 (item) => selection.includes(getItemId(item)) && selectableItems.includes(item)
2568 );
2569 const areAllSelected = selectedItems.length === selectableItems.length;
2570 return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2571 import_components3.CheckboxControl,
2572 {
2573 className: "dataviews-view-table-selection-checkbox",
2574 checked: areAllSelected,
2575 indeterminate: !areAllSelected && !!selectedItems.length,
2576 onChange: () => {
2577 if (areAllSelected) {
2578 onChangeSelection([]);
2579 } else {
2580 onChangeSelection(
2581 selectableItems.map((item) => getItemId(item))
2582 );
2583 }
2584 },
2585 "aria-label": areAllSelected ? (0, import_i18n10.__)("Deselect all") : (0, import_i18n10.__)("Select all")
2586 }
2587 );
2588 }
2589
2590 // packages/dataviews/build-module/components/dataviews-layouts/table/column-header-menu.mjs
2591 var import_i18n11 = __toESM(require_i18n(), 1);
2592 var import_components4 = __toESM(require_components(), 1);
2593 var import_element6 = __toESM(require_element(), 1);
2594
2595 // packages/dataviews/build-module/utils/get-hideable-fields.mjs
2596 function getHideableFields(view, fields) {
2597 const togglableFields = [
2598 view?.titleField,
2599 view?.mediaField,
2600 view?.descriptionField
2601 ].filter(Boolean);
2602 return fields.filter(
2603 (f2) => !togglableFields.includes(f2.id) && f2.type !== "media" && f2.enableHiding !== false
2604 );
2605 }
2606
2607 // packages/dataviews/build-module/components/dataviews-layouts/table/column-header-menu.mjs
2608 var import_jsx_runtime33 = __toESM(require_jsx_runtime(), 1);
2609 var { Menu: Menu2 } = unlock(import_components4.privateApis);
2610 function WithMenuSeparators({ children }) {
2611 return import_element6.Children.toArray(children).filter(Boolean).map((child, i2) => /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(import_element6.Fragment, { children: [
2612 i2 > 0 && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.Separator, {}),
2613 child
2614 ] }, i2));
2615 }
2616 var _HeaderMenu = (0, import_element6.forwardRef)(function HeaderMenu({
2617 fieldId,
2618 view,
2619 fields,
2620 onChangeView,
2621 onHide,
2622 setOpenedFilter,
2623 canMove = true,
2624 canInsertLeft = true,
2625 canInsertRight = true
2626 }, ref) {
2627 const visibleFieldIds = view.fields ?? [];
2628 const index = visibleFieldIds?.indexOf(fieldId);
2629 const isSorted = view.sort?.field === fieldId;
2630 let isHidable = false;
2631 let isSortable = false;
2632 let canAddFilter = false;
2633 let operators = [];
2634 const field = fields.find((f2) => f2.id === fieldId);
2635 const { setIsShowingFilter } = (0, import_element6.useContext)(dataviews_context_default);
2636 if (!field) {
2637 return null;
2638 }
2639 isHidable = field.enableHiding !== false;
2640 isSortable = field.enableSorting !== false;
2641 const header = field.header;
2642 operators = !!field.filterBy && field.filterBy?.operators || [];
2643 canAddFilter = !view.filters?.some((_filter) => fieldId === _filter.field) && !!(field.hasElements || field.Edit) && field.filterBy !== false && !field.filterBy?.isPrimary;
2644 if (!isSortable && !canMove && !isHidable && !canAddFilter) {
2645 return header;
2646 }
2647 const hiddenFields = getHideableFields(view, fields).filter(
2648 (f2) => !visibleFieldIds.includes(f2.id)
2649 );
2650 const canInsert = (canInsertLeft || canInsertRight) && !!hiddenFields.length;
2651 const isRtl = (0, import_i18n11.isRTL)();
2652 return /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(Menu2, { children: [
2653 /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(
2654 Menu2.TriggerButton,
2655 {
2656 render: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2657 import_components4.Button,
2658 {
2659 size: "compact",
2660 className: "dataviews-view-table-header-button",
2661 ref,
2662 variant: "tertiary"
2663 }
2664 ),
2665 children: [
2666 header,
2667 view.sort && isSorted && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("span", { "aria-hidden": "true", children: sortArrows[view.sort.direction] })
2668 ]
2669 }
2670 ),
2671 /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.Popover, { style: { minWidth: "240px" }, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(WithMenuSeparators, { children: [
2672 isSortable && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.Group, { children: SORTING_DIRECTIONS.map(
2673 (direction) => {
2674 const isChecked = view.sort && isSorted && view.sort.direction === direction;
2675 const value = `${fieldId}-${direction}`;
2676 return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2677 Menu2.RadioItem,
2678 {
2679 name: "view-table-sorting",
2680 value,
2681 checked: isChecked,
2682 onChange: () => {
2683 onChangeView({
2684 ...view,
2685 sort: {
2686 field: fieldId,
2687 direction
2688 },
2689 showLevels: false
2690 });
2691 },
2692 children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.ItemLabel, { children: sortLabels[direction] })
2693 },
2694 value
2695 );
2696 }
2697 ) }),
2698 canAddFilter && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.Group, { children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2699 Menu2.Item,
2700 {
2701 prefix: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_components4.Icon, { icon: funnel_default }),
2702 onClick: () => {
2703 setOpenedFilter(fieldId);
2704 setIsShowingFilter(true);
2705 onChangeView({
2706 ...view,
2707 page: 1,
2708 filters: [
2709 ...view.filters || [],
2710 {
2711 field: fieldId,
2712 value: void 0,
2713 operator: operators[0]
2714 }
2715 ]
2716 });
2717 },
2718 children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.ItemLabel, { children: (0, import_i18n11.__)("Add filter") })
2719 }
2720 ) }),
2721 (canMove || isHidable || canInsert) && field && /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(Menu2.Group, { children: [
2722 canMove && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2723 Menu2.Item,
2724 {
2725 prefix: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_components4.Icon, { icon: arrow_left_default }),
2726 disabled: isRtl ? index >= visibleFieldIds.length - 1 : index < 1,
2727 onClick: () => {
2728 const targetIndex = isRtl ? index + 1 : index - 1;
2729 const newFields = [
2730 ...visibleFieldIds
2731 ];
2732 newFields.splice(index, 1);
2733 newFields.splice(
2734 targetIndex,
2735 0,
2736 fieldId
2737 );
2738 onChangeView({
2739 ...view,
2740 fields: newFields
2741 });
2742 },
2743 children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.ItemLabel, { children: (0, import_i18n11.__)("Move left") })
2744 }
2745 ),
2746 canMove && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2747 Menu2.Item,
2748 {
2749 prefix: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_components4.Icon, { icon: arrow_right_default }),
2750 disabled: isRtl ? index < 1 : index >= visibleFieldIds.length - 1,
2751 onClick: () => {
2752 const targetIndex = isRtl ? index - 1 : index + 1;
2753 const newFields = [
2754 ...visibleFieldIds
2755 ];
2756 newFields.splice(index, 1);
2757 newFields.splice(
2758 targetIndex,
2759 0,
2760 fieldId
2761 );
2762 onChangeView({
2763 ...view,
2764 fields: newFields
2765 });
2766 },
2767 children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.ItemLabel, { children: (0, import_i18n11.__)("Move right") })
2768 }
2769 ),
2770 canInsertLeft && !!hiddenFields.length && /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(Menu2, { children: [
2771 /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.SubmenuTriggerItem, { children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.ItemLabel, { children: (0, import_i18n11.__)("Insert left") }) }),
2772 /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.Popover, { children: hiddenFields.map((hiddenField) => /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2773 Menu2.Item,
2774 {
2775 onClick: () => {
2776 onChangeView({
2777 ...view,
2778 fields: [
2779 ...visibleFieldIds.slice(
2780 0,
2781 index
2782 ),
2783 hiddenField.id,
2784 ...visibleFieldIds.slice(
2785 index
2786 )
2787 ]
2788 });
2789 },
2790 children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.ItemLabel, { children: hiddenField.label })
2791 },
2792 hiddenField.id
2793 )) })
2794 ] }),
2795 canInsertRight && !!hiddenFields.length && /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(Menu2, { children: [
2796 /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.SubmenuTriggerItem, { children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.ItemLabel, { children: (0, import_i18n11.__)("Insert right") }) }),
2797 /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.Popover, { children: hiddenFields.map((hiddenField) => /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2798 Menu2.Item,
2799 {
2800 onClick: () => {
2801 onChangeView({
2802 ...view,
2803 fields: [
2804 ...visibleFieldIds.slice(
2805 0,
2806 index + 1
2807 ),
2808 hiddenField.id,
2809 ...visibleFieldIds.slice(
2810 index + 1
2811 )
2812 ]
2813 });
2814 },
2815 children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.ItemLabel, { children: hiddenField.label })
2816 },
2817 hiddenField.id
2818 )) })
2819 ] }),
2820 isHidable && field && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
2821 Menu2.Item,
2822 {
2823 prefix: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_components4.Icon, { icon: unseen_default }),
2824 onClick: () => {
2825 onHide(field);
2826 onChangeView({
2827 ...view,
2828 fields: visibleFieldIds.filter(
2829 (id) => id !== fieldId
2830 )
2831 });
2832 },
2833 children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Menu2.ItemLabel, { children: (0, import_i18n11.__)("Hide column") })
2834 }
2835 )
2836 ] })
2837 ] }) })
2838 ] });
2839 });
2840 var ColumnHeaderMenu = _HeaderMenu;
2841 var column_header_menu_default = ColumnHeaderMenu;
2842
2843 // packages/dataviews/build-module/components/dataviews-layouts/utils/item-click-wrapper.mjs
2844 var import_element7 = __toESM(require_element(), 1);
2845 var import_jsx_runtime34 = __toESM(require_jsx_runtime(), 1);
2846 function getClickableItemProps({
2847 item,
2848 isItemClickable: isItemClickable2,
2849 onClickItem,
2850 className
2851 }) {
2852 if (!isItemClickable2(item) || !onClickItem) {
2853 return { className };
2854 }
2855 return {
2856 className: className ? `${className} ${className}--clickable` : void 0,
2857 role: "button",
2858 tabIndex: 0,
2859 onClick: (event) => {
2860 event.stopPropagation();
2861 onClickItem(item);
2862 },
2863 onKeyDown: (event) => {
2864 if (event.key === "Enter" || event.key === "" || event.key === " ") {
2865 event.stopPropagation();
2866 onClickItem(item);
2867 }
2868 }
2869 };
2870 }
2871 function ItemClickWrapper({
2872 item,
2873 isItemClickable: isItemClickable2,
2874 onClickItem,
2875 renderItemLink,
2876 className,
2877 children,
2878 ...extraProps
2879 }) {
2880 if (!isItemClickable2(item)) {
2881 return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className, ...extraProps, children });
2882 }
2883 if (renderItemLink) {
2884 const renderedElement = renderItemLink({
2885 item,
2886 className: `${className} ${className}--clickable`,
2887 ...extraProps,
2888 children
2889 });
2890 return (0, import_element7.cloneElement)(renderedElement, {
2891 onClick: (event) => {
2892 event.stopPropagation();
2893 if (renderedElement.props.onClick) {
2894 renderedElement.props.onClick(event);
2895 }
2896 },
2897 onKeyDown: (event) => {
2898 if (event.key === "Enter" || event.key === "" || event.key === " ") {
2899 event.stopPropagation();
2900 if (renderedElement.props.onKeyDown) {
2901 renderedElement.props.onKeyDown(event);
2902 }
2903 }
2904 }
2905 });
2906 }
2907 const clickProps = getClickableItemProps({
2908 item,
2909 isItemClickable: isItemClickable2,
2910 onClickItem,
2911 className
2912 });
2913 return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { ...clickProps, ...extraProps, children });
2914 }
2915
2916 // packages/dataviews/build-module/components/dataviews-layouts/table/column-primary.mjs
2917 var import_jsx_runtime35 = __toESM(require_jsx_runtime(), 1);
2918 function ColumnPrimary({
2919 item,
2920 level,
2921 titleField,
2922 mediaField,
2923 descriptionField: descriptionField2,
2924 onClickItem,
2925 renderItemLink,
2926 isItemClickable: isItemClickable2
2927 }) {
2928 return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(Stack, { direction: "row", gap: "sm", align: "flex-start", justify: "flex-start", children: [
2929 mediaField && /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
2930 ItemClickWrapper,
2931 {
2932 item,
2933 isItemClickable: isItemClickable2,
2934 onClickItem,
2935 renderItemLink,
2936 className: "dataviews-view-table__cell-content-wrapper dataviews-column-primary__media",
2937 "aria-label": isItemClickable2(item) && (!!onClickItem || !!renderItemLink) && !!titleField ? titleField.getValue?.({ item }) : void 0,
2938 children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
2939 mediaField.render,
2940 {
2941 item,
2942 field: mediaField,
2943 config: { sizes: "32px" }
2944 }
2945 )
2946 }
2947 ),
2948 /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
2949 Stack,
2950 {
2951 direction: "column",
2952 align: "flex-start",
2953 className: "dataviews-view-table__primary-column-content",
2954 children: [
2955 titleField && /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
2956 ItemClickWrapper,
2957 {
2958 item,
2959 isItemClickable: isItemClickable2,
2960 onClickItem,
2961 renderItemLink,
2962 className: "dataviews-view-table__cell-content-wrapper dataviews-title-field",
2963 children: [
2964 level !== void 0 && level > 0 && /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("span", { className: "dataviews-view-table__level", children: [
2965 Array(level).fill("\u2014").join(" "),
2966 "\xA0"
2967 ] }),
2968 /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(titleField.render, { item, field: titleField })
2969 ]
2970 }
2971 ),
2972 descriptionField2 && /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
2973 descriptionField2.render,
2974 {
2975 item,
2976 field: descriptionField2
2977 }
2978 )
2979 ]
2980 }
2981 )
2982 ] });
2983 }
2984 var column_primary_default = ColumnPrimary;
2985
2986 // packages/dataviews/build-module/components/dataviews-layouts/table/use-is-horizontal-scroll-end.mjs
2987 var import_compose3 = __toESM(require_compose(), 1);
2988 var import_element8 = __toESM(require_element(), 1);
2989 var import_i18n12 = __toESM(require_i18n(), 1);
2990 var isScrolledToEnd = (element) => {
2991 if ((0, import_i18n12.isRTL)()) {
2992 const scrollLeft = Math.abs(element.scrollLeft);
2993 return scrollLeft <= 1;
2994 }
2995 return element.scrollLeft + element.clientWidth >= element.scrollWidth - 1;
2996 };
2997 function useIsHorizontalScrollEnd({
2998 scrollContainerRef,
2999 enabled = false
3000 }) {
3001 const [isHorizontalScrollEnd, setIsHorizontalScrollEnd] = (0, import_element8.useState)(false);
3002 const handleIsHorizontalScrollEnd = (0, import_compose3.useDebounce)(
3003 (0, import_element8.useCallback)(() => {
3004 const scrollContainer = scrollContainerRef.current;
3005 if (scrollContainer) {
3006 setIsHorizontalScrollEnd(isScrolledToEnd(scrollContainer));
3007 }
3008 }, [scrollContainerRef, setIsHorizontalScrollEnd]),
3009 200
3010 );
3011 (0, import_element8.useEffect)(() => {
3012 if (typeof window === "undefined" || !enabled || !scrollContainerRef.current) {
3013 return () => {
3014 };
3015 }
3016 handleIsHorizontalScrollEnd();
3017 scrollContainerRef.current.addEventListener(
3018 "scroll",
3019 handleIsHorizontalScrollEnd
3020 );
3021 window.addEventListener("resize", handleIsHorizontalScrollEnd);
3022 return () => {
3023 scrollContainerRef.current?.removeEventListener(
3024 "scroll",
3025 handleIsHorizontalScrollEnd
3026 );
3027 window.removeEventListener("resize", handleIsHorizontalScrollEnd);
3028 };
3029 }, [scrollContainerRef, enabled]);
3030 return isHorizontalScrollEnd;
3031 }
3032
3033 // packages/dataviews/build-module/components/dataviews-layouts/utils/get-data-by-group.mjs
3034 function getDataByGroup(data, groupByField) {
3035 return data.reduce((groups, item) => {
3036 const groupName = groupByField.getValue({ item });
3037 if (!groups.has(groupName)) {
3038 groups.set(groupName, []);
3039 }
3040 groups.get(groupName)?.push(item);
3041 return groups;
3042 }, /* @__PURE__ */ new Map());
3043 }
3044
3045 // packages/dataviews/build-module/components/dataviews-view-config/properties-section.mjs
3046 var import_components5 = __toESM(require_components(), 1);
3047 var import_i18n13 = __toESM(require_i18n(), 1);
3048 var import_element9 = __toESM(require_element(), 1);
3049 var import_jsx_runtime36 = __toESM(require_jsx_runtime(), 1);
3050 function FieldItem({
3051 field,
3052 isVisible: isVisible2,
3053 onToggleVisibility
3054 }) {
3055 return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(import_components5.__experimentalItem, { onClick: field.enableHiding ? onToggleVisibility : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(Stack, { direction: "row", gap: "xs", justify: "flex-start", align: "center", children: [
3056 /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { style: { height: 24, width: 24 }, children: isVisible2 && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(import_components5.Icon, { icon: check_default }) }),
3057 /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: "dataviews-view-config__label", children: field.label })
3058 ] }) });
3059 }
3060 function isDefined(item) {
3061 return !!item;
3062 }
3063 function PropertiesSection({
3064 showLabel = true
3065 }) {
3066 const { view, fields, onChangeView } = (0, import_element9.useContext)(dataviews_context_default);
3067 const regularFields = getHideableFields(view, fields);
3068 if (!regularFields?.length) {
3069 return null;
3070 }
3071 const titleField = fields.find((f2) => f2.id === view.titleField);
3072 const previewField = fields.find((f2) => f2.id === view.mediaField);
3073 const descriptionField2 = fields.find(
3074 (f2) => f2.id === view.descriptionField
3075 );
3076 const lockedFields = [
3077 {
3078 field: titleField,
3079 isVisibleFlag: "showTitle"
3080 },
3081 {
3082 field: previewField,
3083 isVisibleFlag: "showMedia"
3084 },
3085 {
3086 field: descriptionField2,
3087 isVisibleFlag: "showDescription"
3088 }
3089 ].filter(({ field }) => isDefined(field));
3090 const visibleFieldIds = view.fields ?? [];
3091 const visibleRegularFieldsCount = regularFields.filter(
3092 (f2) => visibleFieldIds.includes(f2.id)
3093 ).length;
3094 const visibleLockedFields = lockedFields.filter(
3095 ({ isVisibleFlag }) => (
3096 // @ts-expect-error
3097 view[isVisibleFlag] ?? true
3098 )
3099 );
3100 const totalVisibleFields = visibleLockedFields.length + visibleRegularFieldsCount;
3101 const isSingleVisibleLockedField = totalVisibleFields === 1 && visibleLockedFields.length === 1;
3102 return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(Stack, { direction: "column", className: "dataviews-field-control", children: [
3103 showLabel && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(import_components5.BaseControl.VisualLabel, { children: (0, import_i18n13.__)("Properties") }),
3104 /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3105 Stack,
3106 {
3107 direction: "column",
3108 className: "dataviews-view-config__properties",
3109 children: /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(import_components5.__experimentalItemGroup, { isBordered: true, isSeparated: true, size: "medium", children: [
3110 lockedFields.map(({ field, isVisibleFlag }) => {
3111 const isVisible2 = view[isVisibleFlag] ?? true;
3112 const fieldToRender = isSingleVisibleLockedField && isVisible2 ? { ...field, enableHiding: false } : field;
3113 return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3114 FieldItem,
3115 {
3116 field: fieldToRender,
3117 isVisible: isVisible2,
3118 onToggleVisibility: () => {
3119 onChangeView({
3120 ...view,
3121 [isVisibleFlag]: !isVisible2
3122 });
3123 }
3124 },
3125 field.id
3126 );
3127 }),
3128 regularFields.map((field) => {
3129 const isVisible2 = visibleFieldIds.includes(field.id);
3130 const fieldToRender = totalVisibleFields === 1 && isVisible2 ? { ...field, enableHiding: false } : field;
3131 return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
3132 FieldItem,
3133 {
3134 field: fieldToRender,
3135 isVisible: isVisible2,
3136 onToggleVisibility: () => {
3137 onChangeView({
3138 ...view,
3139 fields: isVisible2 ? visibleFieldIds.filter(
3140 (fieldId) => fieldId !== field.id
3141 ) : [...visibleFieldIds, field.id]
3142 });
3143 }
3144 },
3145 field.id
3146 );
3147 })
3148 ] })
3149 }
3150 )
3151 ] });
3152 }
3153
3154 // packages/dataviews/build-module/components/dataviews-layouts/table/index.mjs
3155 var import_jsx_runtime37 = __toESM(require_jsx_runtime(), 1);
3156 function TableColumnField({
3157 item,
3158 fields,
3159 column,
3160 align
3161 }) {
3162 const field = fields.find((f2) => f2.id === column);
3163 if (!field) {
3164 return null;
3165 }
3166 const className = clsx_default("dataviews-view-table__cell-content-wrapper", {
3167 "dataviews-view-table__cell-align-end": align === "end",
3168 "dataviews-view-table__cell-align-center": align === "center"
3169 });
3170 return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(field.render, { item, field }) });
3171 }
3172 function TableRow({
3173 hasBulkActions,
3174 item,
3175 level,
3176 actions,
3177 fields,
3178 id,
3179 view,
3180 titleField,
3181 mediaField,
3182 descriptionField: descriptionField2,
3183 selection,
3184 getItemId,
3185 isItemClickable: isItemClickable2,
3186 onClickItem,
3187 renderItemLink,
3188 onChangeSelection,
3189 isActionsColumnSticky,
3190 posinset
3191 }) {
3192 const { paginationInfo } = (0, import_element10.useContext)(dataviews_context_default);
3193 const hasPossibleBulkAction = useHasAPossibleBulkAction(actions, item);
3194 const isSelected2 = hasPossibleBulkAction && selection.includes(id);
3195 const {
3196 showTitle = true,
3197 showMedia = true,
3198 showDescription = true,
3199 infiniteScrollEnabled
3200 } = view;
3201 const isTouchDeviceRef = (0, import_element10.useRef)(false);
3202 const columns = view.fields ?? [];
3203 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
3204 return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(
3205 "tr",
3206 {
3207 className: clsx_default("dataviews-view-table__row", {
3208 "is-selected": hasPossibleBulkAction && isSelected2,
3209 "has-bulk-actions": hasPossibleBulkAction
3210 }),
3211 onTouchStart: () => {
3212 isTouchDeviceRef.current = true;
3213 },
3214 "aria-setsize": infiniteScrollEnabled ? paginationInfo.totalItems : void 0,
3215 "aria-posinset": posinset,
3216 role: infiniteScrollEnabled ? "article" : void 0,
3217 onMouseDown: (event) => {
3218 const isMetaClick = (0, import_keycodes.isAppleOS)() ? event.metaKey : event.ctrlKey;
3219 if (event.button === 0 && isMetaClick && window.navigator.userAgent.toLowerCase().includes("firefox")) {
3220 event?.preventDefault();
3221 }
3222 },
3223 onClick: (event) => {
3224 if (!hasPossibleBulkAction) {
3225 return;
3226 }
3227 const isModifierKeyPressed = (0, import_keycodes.isAppleOS)() ? event.metaKey : event.ctrlKey;
3228 if (isModifierKeyPressed && !isTouchDeviceRef.current && document.getSelection()?.type !== "Range") {
3229 onChangeSelection(
3230 selection.includes(id) ? selection.filter((itemId) => id !== itemId) : [...selection, id]
3231 );
3232 }
3233 },
3234 children: [
3235 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("td", { className: "dataviews-view-table__checkbox-column", children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className: "dataviews-view-table__cell-content-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3236 DataViewsSelectionCheckbox,
3237 {
3238 item,
3239 selection,
3240 onChangeSelection,
3241 getItemId,
3242 titleField,
3243 disabled: !hasPossibleBulkAction
3244 }
3245 ) }) }),
3246 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3247 column_primary_default,
3248 {
3249 item,
3250 level,
3251 titleField: showTitle ? titleField : void 0,
3252 mediaField: showMedia ? mediaField : void 0,
3253 descriptionField: showDescription ? descriptionField2 : void 0,
3254 isItemClickable: isItemClickable2,
3255 onClickItem,
3256 renderItemLink
3257 }
3258 ) }),
3259 columns.map((column) => {
3260 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
3261 return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3262 "td",
3263 {
3264 style: {
3265 width,
3266 maxWidth,
3267 minWidth
3268 },
3269 children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3270 TableColumnField,
3271 {
3272 fields,
3273 item,
3274 column,
3275 align
3276 }
3277 )
3278 },
3279 column
3280 );
3281 }),
3282 !!actions?.length && // Disable reason: we are not making the element interactive,
3283 // but preventing any click events from bubbling up to the
3284 // table row. This allows us to add a click handler to the row
3285 // itself (to toggle row selection) without erroneously
3286 // intercepting click events from ItemActions.
3287 /* eslint-disable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */
3288 /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3289 "td",
3290 {
3291 className: clsx_default("dataviews-view-table__actions-column", {
3292 "dataviews-view-table__actions-column--sticky": true,
3293 "dataviews-view-table__actions-column--stuck": isActionsColumnSticky
3294 }),
3295 onClick: (e2) => e2.stopPropagation(),
3296 children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(ItemActions, { item, actions })
3297 }
3298 )
3299 ]
3300 }
3301 );
3302 }
3303 function ViewTable({
3304 actions,
3305 data,
3306 fields,
3307 getItemId,
3308 getItemLevel,
3309 isLoading = false,
3310 onChangeView,
3311 onChangeSelection,
3312 selection,
3313 setOpenedFilter,
3314 onClickItem,
3315 isItemClickable: isItemClickable2,
3316 renderItemLink,
3317 view,
3318 className,
3319 empty
3320 }) {
3321 const { containerRef } = (0, import_element10.useContext)(dataviews_context_default);
3322 const headerMenuRefs = (0, import_element10.useRef)(/* @__PURE__ */ new Map());
3323 const headerMenuToFocusRef = (0, import_element10.useRef)();
3324 const [nextHeaderMenuToFocus, setNextHeaderMenuToFocus] = (0, import_element10.useState)();
3325 const hasBulkActions = useSomeItemHasAPossibleBulkAction(actions, data);
3326 const [contextMenuAnchor, setContextMenuAnchor] = (0, import_element10.useState)(null);
3327 (0, import_element10.useEffect)(() => {
3328 if (headerMenuToFocusRef.current) {
3329 headerMenuToFocusRef.current.focus();
3330 headerMenuToFocusRef.current = void 0;
3331 }
3332 });
3333 const tableNoticeId = (0, import_element10.useId)();
3334 const isHorizontalScrollEnd = useIsHorizontalScrollEnd({
3335 scrollContainerRef: containerRef,
3336 enabled: !!actions?.length
3337 });
3338 if (nextHeaderMenuToFocus) {
3339 headerMenuToFocusRef.current = nextHeaderMenuToFocus;
3340 setNextHeaderMenuToFocus(void 0);
3341 return;
3342 }
3343 const onHide = (field) => {
3344 const hidden = headerMenuRefs.current.get(field.id);
3345 const fallback = hidden ? headerMenuRefs.current.get(hidden.fallback) : void 0;
3346 setNextHeaderMenuToFocus(fallback?.node);
3347 };
3348 const handleHeaderContextMenu = (event) => {
3349 event.preventDefault();
3350 event.stopPropagation();
3351 const virtualAnchor = {
3352 getBoundingClientRect: () => ({
3353 x: event.clientX,
3354 y: event.clientY,
3355 top: event.clientY,
3356 left: event.clientX,
3357 right: event.clientX,
3358 bottom: event.clientY,
3359 width: 0,
3360 height: 0,
3361 toJSON: () => ({})
3362 })
3363 };
3364 window.requestAnimationFrame(() => {
3365 setContextMenuAnchor(virtualAnchor);
3366 });
3367 };
3368 const hasData = !!data?.length;
3369 const titleField = fields.find((field) => field.id === view.titleField);
3370 const mediaField = fields.find((field) => field.id === view.mediaField);
3371 const descriptionField2 = fields.find(
3372 (field) => field.id === view.descriptionField
3373 );
3374 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
3375 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
3376 const { showTitle = true, showMedia = true, showDescription = true } = view;
3377 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
3378 const columns = view.fields ?? [];
3379 const headerMenuRef = (column, index) => (node) => {
3380 if (node) {
3381 headerMenuRefs.current.set(column, {
3382 node,
3383 fallback: columns[index > 0 ? index - 1 : 1]
3384 });
3385 } else {
3386 headerMenuRefs.current.delete(column);
3387 }
3388 };
3389 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
3390 return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(import_jsx_runtime37.Fragment, { children: [
3391 /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(
3392 "table",
3393 {
3394 className: clsx_default("dataviews-view-table", className, {
3395 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
3396 view.layout.density
3397 ),
3398 "has-bulk-actions": hasBulkActions
3399 }),
3400 "aria-busy": isLoading,
3401 "aria-describedby": tableNoticeId,
3402 role: isInfiniteScroll ? "feed" : void 0,
3403 children: [
3404 /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("colgroup", { children: [
3405 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("col", { className: "dataviews-view-table__col-checkbox" }),
3406 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("col", { className: "dataviews-view-table__col-first-data" }),
3407 columns.map((column, index) => /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3408 "col",
3409 {
3410 className: clsx_default(
3411 `dataviews-view-table__col-${column}`,
3412 {
3413 "dataviews-view-table__col-first-data": !hasPrimaryColumn && index === 0
3414 }
3415 )
3416 },
3417 `col-${column}`
3418 )),
3419 !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("col", { className: "dataviews-view-table__col-actions" })
3420 ] }),
3421 contextMenuAnchor && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3422 import_components6.Popover,
3423 {
3424 anchor: contextMenuAnchor,
3425 onClose: () => setContextMenuAnchor(null),
3426 placement: "bottom-start",
3427 children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(PropertiesSection, { showLabel: false })
3428 }
3429 ),
3430 /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("thead", { onContextMenu: handleHeaderContextMenu, children: /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("tr", { className: "dataviews-view-table__row", children: [
3431 hasBulkActions && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3432 "th",
3433 {
3434 className: "dataviews-view-table__checkbox-column",
3435 scope: "col",
3436 onContextMenu: handleHeaderContextMenu,
3437 children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3438 BulkSelectionCheckbox,
3439 {
3440 selection,
3441 onChangeSelection,
3442 data,
3443 actions,
3444 getItemId
3445 }
3446 )
3447 }
3448 ),
3449 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("th", { scope: "col", children: titleField && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3450 column_header_menu_default,
3451 {
3452 ref: headerMenuRef(
3453 titleField.id,
3454 0
3455 ),
3456 fieldId: titleField.id,
3457 view,
3458 fields,
3459 onChangeView,
3460 onHide,
3461 setOpenedFilter,
3462 canMove: false,
3463 canInsertLeft: false,
3464 canInsertRight: view.layout?.enableMoving ?? true
3465 }
3466 ) }),
3467 columns.map((column, index) => {
3468 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
3469 const canInsertOrMove = view.layout?.enableMoving ?? true;
3470 return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3471 "th",
3472 {
3473 style: {
3474 width,
3475 maxWidth,
3476 minWidth,
3477 textAlign: align
3478 },
3479 "aria-sort": view.sort?.direction && view.sort?.field === column ? sortValues[view.sort.direction] : void 0,
3480 scope: "col",
3481 children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3482 column_header_menu_default,
3483 {
3484 ref: headerMenuRef(column, index),
3485 fieldId: column,
3486 view,
3487 fields,
3488 onChangeView,
3489 onHide,
3490 setOpenedFilter,
3491 canMove: canInsertOrMove,
3492 canInsertLeft: canInsertOrMove,
3493 canInsertRight: canInsertOrMove
3494 }
3495 )
3496 },
3497 column
3498 );
3499 }),
3500 !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3501 "th",
3502 {
3503 className: clsx_default(
3504 "dataviews-view-table__actions-column",
3505 {
3506 "dataviews-view-table__actions-column--sticky": true,
3507 "dataviews-view-table__actions-column--stuck": !isHorizontalScrollEnd
3508 }
3509 ),
3510 children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("span", { className: "dataviews-view-table-header", children: (0, import_i18n14.__)("Actions") })
3511 }
3512 )
3513 ] }) }),
3514 hasData && groupField && dataByGroup ? Array.from(dataByGroup.entries()).map(
3515 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("tbody", { children: [
3516 /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("tr", { className: "dataviews-view-table__group-header-row", children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3517 "td",
3518 {
3519 colSpan: columns.length + (hasPrimaryColumn ? 1 : 0) + (hasBulkActions ? 1 : 0) + (actions?.length ? 1 : 0),
3520 className: "dataviews-view-table__group-header-cell",
3521 children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n14.sprintf)(
3522 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
3523 (0, import_i18n14.__)("%1$s: %2$s"),
3524 groupField.label,
3525 groupName
3526 )
3527 }
3528 ) }),
3529 groupItems.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3530 TableRow,
3531 {
3532 item,
3533 level: view.showLevels && typeof getItemLevel === "function" ? getItemLevel(item) : void 0,
3534 hasBulkActions,
3535 actions,
3536 fields,
3537 id: getItemId(item) || index.toString(),
3538 view,
3539 titleField,
3540 mediaField,
3541 descriptionField: descriptionField2,
3542 selection,
3543 getItemId,
3544 onChangeSelection,
3545 onClickItem,
3546 renderItemLink,
3547 isItemClickable: isItemClickable2,
3548 isActionsColumnSticky: !isHorizontalScrollEnd
3549 },
3550 getItemId(item)
3551 ))
3552 ] }, `group-${groupName}`)
3553 ) : /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("tbody", { children: hasData && data.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3554 TableRow,
3555 {
3556 item,
3557 level: view.showLevels && typeof getItemLevel === "function" ? getItemLevel(item) : void 0,
3558 hasBulkActions,
3559 actions,
3560 fields,
3561 id: getItemId(item) || index.toString(),
3562 view,
3563 titleField,
3564 mediaField,
3565 descriptionField: descriptionField2,
3566 selection,
3567 getItemId,
3568 onChangeSelection,
3569 onClickItem,
3570 renderItemLink,
3571 isItemClickable: isItemClickable2,
3572 isActionsColumnSticky: !isHorizontalScrollEnd,
3573 posinset: isInfiniteScroll ? index + 1 : void 0
3574 },
3575 getItemId(item)
3576 )) })
3577 ]
3578 }
3579 ),
3580 /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(
3581 "div",
3582 {
3583 className: clsx_default({
3584 "dataviews-loading": isLoading,
3585 "dataviews-no-results": !hasData && !isLoading
3586 }),
3587 id: tableNoticeId,
3588 children: [
3589 !hasData && (isLoading ? /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_components6.Spinner, {}) }) : empty),
3590 hasData && isLoading && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_components6.Spinner, {}) })
3591 ]
3592 }
3593 )
3594 ] });
3595 }
3596 var table_default = ViewTable;
3597
3598 // packages/dataviews/build-module/components/dataviews-layouts/grid/index.mjs
3599 var import_components9 = __toESM(require_components(), 1);
3600 var import_i18n17 = __toESM(require_i18n(), 1);
3601
3602 // packages/dataviews/build-module/components/dataviews-layouts/grid/composite-grid.mjs
3603 var import_components8 = __toESM(require_components(), 1);
3604 var import_i18n16 = __toESM(require_i18n(), 1);
3605 var import_compose4 = __toESM(require_compose(), 1);
3606 var import_keycodes2 = __toESM(require_keycodes(), 1);
3607 var import_element12 = __toESM(require_element(), 1);
3608
3609 // packages/dataviews/build-module/components/dataviews-layouts/grid/preview-size-picker.mjs
3610 var import_components7 = __toESM(require_components(), 1);
3611 var import_i18n15 = __toESM(require_i18n(), 1);
3612 var import_element11 = __toESM(require_element(), 1);
3613 var import_jsx_runtime38 = __toESM(require_jsx_runtime(), 1);
3614 var imageSizes = [
3615 {
3616 value: 120,
3617 breakpoint: 1
3618 },
3619 {
3620 value: 170,
3621 breakpoint: 1
3622 },
3623 {
3624 value: 230,
3625 breakpoint: 1
3626 },
3627 {
3628 value: 290,
3629 breakpoint: 1112
3630 // at minimum image width, 4 images display at this container size
3631 },
3632 {
3633 value: 350,
3634 breakpoint: 1636
3635 // at minimum image width, 6 images display at this container size
3636 },
3637 {
3638 value: 430,
3639 breakpoint: 588
3640 // at minimum image width, 2 images display at this container size
3641 }
3642 ];
3643 var DEFAULT_PREVIEW_SIZE = imageSizes[2].value;
3644 function useGridColumns() {
3645 const context = (0, import_element11.useContext)(dataviews_context_default);
3646 const view = context.view;
3647 return (0, import_element11.useMemo)(() => {
3648 const containerWidth = context.containerWidth;
3649 const gap = 32;
3650 const previewSize = view.layout?.previewSize ?? DEFAULT_PREVIEW_SIZE;
3651 const columns = Math.floor(
3652 (containerWidth + gap) / (previewSize + gap)
3653 );
3654 return Math.max(1, columns);
3655 }, [context.containerWidth, view.layout?.previewSize]);
3656 }
3657
3658 // packages/dataviews/build-module/components/dataviews-layouts/grid/composite-grid.mjs
3659 var import_jsx_runtime39 = __toESM(require_jsx_runtime(), 1);
3660 var { Badge } = unlock(import_components8.privateApis);
3661 function chunk(array, size) {
3662 const chunks = [];
3663 for (let i2 = 0, j2 = array.length; i2 < j2; i2 += size) {
3664 chunks.push(array.slice(i2, i2 + size));
3665 }
3666 return chunks;
3667 }
3668 var GridItem = (0, import_element12.forwardRef)(function GridItem2({
3669 view,
3670 selection,
3671 onChangeSelection,
3672 onClickItem,
3673 isItemClickable: isItemClickable2,
3674 renderItemLink,
3675 getItemId,
3676 item,
3677 actions,
3678 mediaField,
3679 titleField,
3680 descriptionField: descriptionField2,
3681 regularFields,
3682 badgeFields,
3683 hasBulkActions,
3684 config,
3685 ...props
3686 }, ref) {
3687 const { showTitle = true, showMedia = true, showDescription = true } = view;
3688 const hasBulkAction = useHasAPossibleBulkAction(actions, item);
3689 const id = getItemId(item);
3690 const instanceId = (0, import_compose4.useInstanceId)(GridItem2);
3691 const isSelected2 = selection.includes(id);
3692 const renderedMediaField = mediaField?.render ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3693 mediaField.render,
3694 {
3695 item,
3696 field: mediaField,
3697 config
3698 }
3699 ) : null;
3700 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(titleField.render, { item, field: titleField }) : null;
3701 const shouldRenderMedia = showMedia && renderedMediaField;
3702 let mediaA11yProps;
3703 let titleA11yProps;
3704 if (isItemClickable2(item) && onClickItem) {
3705 if (renderedTitleField) {
3706 mediaA11yProps = {
3707 "aria-labelledby": `dataviews-view-grid__title-field-${instanceId}`
3708 };
3709 titleA11yProps = {
3710 id: `dataviews-view-grid__title-field-${instanceId}`
3711 };
3712 } else {
3713 mediaA11yProps = {
3714 "aria-label": (0, import_i18n16.__)("Navigate to item")
3715 };
3716 }
3717 }
3718 return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(
3719 Stack,
3720 {
3721 direction: "column",
3722 ...props,
3723 ref,
3724 className: clsx_default(
3725 props.className,
3726 "dataviews-view-grid__row__gridcell",
3727 "dataviews-view-grid__card",
3728 {
3729 "is-selected": hasBulkAction && isSelected2
3730 }
3731 ),
3732 onClickCapture: (event) => {
3733 props.onClickCapture?.(event);
3734 if ((0, import_keycodes2.isAppleOS)() ? event.metaKey : event.ctrlKey) {
3735 event.stopPropagation();
3736 event.preventDefault();
3737 if (!hasBulkAction) {
3738 return;
3739 }
3740 onChangeSelection(
3741 selection.includes(id) ? selection.filter((itemId) => id !== itemId) : [...selection, id]
3742 );
3743 }
3744 },
3745 children: [
3746 shouldRenderMedia && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3747 ItemClickWrapper,
3748 {
3749 item,
3750 isItemClickable: isItemClickable2,
3751 onClickItem,
3752 renderItemLink,
3753 className: "dataviews-view-grid__media",
3754 ...mediaA11yProps,
3755 children: renderedMediaField
3756 }
3757 ),
3758 hasBulkActions && shouldRenderMedia && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3759 DataViewsSelectionCheckbox,
3760 {
3761 item,
3762 selection,
3763 onChangeSelection,
3764 getItemId,
3765 titleField,
3766 disabled: !hasBulkAction
3767 }
3768 ),
3769 !showTitle && shouldRenderMedia && !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "dataviews-view-grid__media-actions", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(ItemActions, { item, actions, isCompact: true }) }),
3770 showTitle && /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(
3771 Stack,
3772 {
3773 direction: "row",
3774 gap: "xs",
3775 className: "dataviews-view-grid__title-actions",
3776 children: [
3777 /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3778 ItemClickWrapper,
3779 {
3780 item,
3781 isItemClickable: isItemClickable2,
3782 onClickItem,
3783 renderItemLink,
3784 className: "dataviews-view-grid__title-field dataviews-title-field",
3785 ...titleA11yProps,
3786 children: renderedTitleField
3787 }
3788 ),
3789 !!actions?.length && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3790 ItemActions,
3791 {
3792 item,
3793 actions,
3794 isCompact: true
3795 }
3796 )
3797 ]
3798 }
3799 ),
3800 /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(Stack, { direction: "column", gap: "2xs", children: [
3801 showDescription && descriptionField2?.render && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3802 descriptionField2.render,
3803 {
3804 item,
3805 field: descriptionField2
3806 }
3807 ),
3808 !!badgeFields?.length && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3809 Stack,
3810 {
3811 direction: "row",
3812 className: "dataviews-view-grid__badge-fields",
3813 gap: "xs",
3814 wrap: "wrap",
3815 align: "top",
3816 justify: "flex-start",
3817 children: badgeFields.map((field) => {
3818 return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3819 Badge,
3820 {
3821 className: "dataviews-view-grid__field-value",
3822 children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3823 field.render,
3824 {
3825 item,
3826 field
3827 }
3828 )
3829 },
3830 field.id
3831 );
3832 })
3833 }
3834 ),
3835 !!regularFields?.length && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3836 Stack,
3837 {
3838 direction: "column",
3839 className: "dataviews-view-grid__fields",
3840 gap: "2xs",
3841 children: regularFields.map((field) => {
3842 return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3843 import_components8.Flex,
3844 {
3845 className: "dataviews-view-grid__field",
3846 gap: 1,
3847 justify: "flex-start",
3848 expanded: true,
3849 style: { height: "auto" },
3850 direction: "row",
3851 children: /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(import_jsx_runtime39.Fragment, { children: [
3852 /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_components8.Tooltip, { text: field.label, children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_components8.FlexItem, { className: "dataviews-view-grid__field-name", children: field.header }) }),
3853 /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3854 import_components8.FlexItem,
3855 {
3856 className: "dataviews-view-grid__field-value",
3857 style: { maxHeight: "none" },
3858 children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3859 field.render,
3860 {
3861 item,
3862 field
3863 }
3864 )
3865 }
3866 )
3867 ] })
3868 },
3869 field.id
3870 );
3871 })
3872 }
3873 )
3874 ] })
3875 ]
3876 }
3877 );
3878 });
3879 function CompositeGrid({
3880 data,
3881 isInfiniteScroll,
3882 className,
3883 isLoading,
3884 view,
3885 fields,
3886 selection,
3887 onChangeSelection,
3888 onClickItem,
3889 isItemClickable: isItemClickable2,
3890 renderItemLink,
3891 getItemId,
3892 actions
3893 }) {
3894 const { paginationInfo, resizeObserverRef } = (0, import_element12.useContext)(dataviews_context_default);
3895 const gridColumns = useGridColumns();
3896 const hasBulkActions = useSomeItemHasAPossibleBulkAction(actions, data);
3897 const titleField = fields.find(
3898 (field) => field.id === view?.titleField
3899 );
3900 const mediaField = fields.find(
3901 (field) => field.id === view?.mediaField
3902 );
3903 const descriptionField2 = fields.find(
3904 (field) => field.id === view?.descriptionField
3905 );
3906 const otherFields = view.fields ?? [];
3907 const { regularFields, badgeFields } = otherFields.reduce(
3908 (accumulator, fieldId) => {
3909 const field = fields.find((f2) => f2.id === fieldId);
3910 if (!field) {
3911 return accumulator;
3912 }
3913 const key = view.layout?.badgeFields?.includes(fieldId) ? "badgeFields" : "regularFields";
3914 accumulator[key].push(field);
3915 return accumulator;
3916 },
3917 { regularFields: [], badgeFields: [] }
3918 );
3919 const size = "900px";
3920 const totalRows = Math.ceil(data.length / gridColumns);
3921 return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3922 import_components8.Composite,
3923 {
3924 role: isInfiniteScroll ? "feed" : "grid",
3925 className: clsx_default("dataviews-view-grid", className),
3926 focusWrap: true,
3927 "aria-busy": isLoading,
3928 "aria-rowcount": isInfiniteScroll ? void 0 : totalRows,
3929 ref: resizeObserverRef,
3930 children: chunk(data, gridColumns).map((row, i2) => /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3931 import_components8.Composite.Row,
3932 {
3933 render: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3934 "div",
3935 {
3936 role: "row",
3937 "aria-rowindex": i2 + 1,
3938 "aria-label": (0, import_i18n16.sprintf)(
3939 /* translators: %d: The row number in the grid */
3940 (0, import_i18n16.__)("Row %d"),
3941 i2 + 1
3942 ),
3943 className: "dataviews-view-grid__row",
3944 style: {
3945 gridTemplateColumns: `repeat( ${gridColumns}, minmax(0, 1fr) )`
3946 }
3947 }
3948 ),
3949 children: row.map((item, indexInRow) => {
3950 const index = i2 * gridColumns + indexInRow;
3951 return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3952 import_components8.Composite.Item,
3953 {
3954 render: (props) => /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
3955 GridItem,
3956 {
3957 ...props,
3958 role: isInfiniteScroll ? "article" : "gridcell",
3959 "aria-setsize": isInfiniteScroll ? paginationInfo.totalItems : void 0,
3960 "aria-posinset": isInfiniteScroll ? index + 1 : void 0,
3961 view,
3962 selection,
3963 onChangeSelection,
3964 onClickItem,
3965 isItemClickable: isItemClickable2,
3966 renderItemLink,
3967 getItemId,
3968 item,
3969 actions,
3970 mediaField,
3971 titleField,
3972 descriptionField: descriptionField2,
3973 regularFields,
3974 badgeFields,
3975 hasBulkActions,
3976 config: {
3977 sizes: size
3978 }
3979 }
3980 )
3981 },
3982 getItemId(item)
3983 );
3984 })
3985 },
3986 i2
3987 ))
3988 }
3989 );
3990 }
3991
3992 // packages/dataviews/build-module/components/dataviews-layouts/grid/index.mjs
3993 var import_jsx_runtime40 = __toESM(require_jsx_runtime(), 1);
3994 function ViewGrid({
3995 actions,
3996 data,
3997 fields,
3998 getItemId,
3999 isLoading,
4000 onChangeSelection,
4001 onClickItem,
4002 isItemClickable: isItemClickable2,
4003 renderItemLink,
4004 selection,
4005 view,
4006 className,
4007 empty
4008 }) {
4009 const hasData = !!data?.length;
4010 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
4011 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
4012 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
4013 const gridProps = {
4014 className,
4015 isLoading,
4016 view,
4017 fields,
4018 selection,
4019 onChangeSelection,
4020 onClickItem,
4021 isItemClickable: isItemClickable2,
4022 renderItemLink,
4023 getItemId,
4024 actions
4025 };
4026 return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(import_jsx_runtime40.Fragment, {
4027 // Render multiple groups.
4028 children: [
4029 hasData && groupField && dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Stack, { direction: "column", gap: "md", children: Array.from(dataByGroup.entries()).map(
4030 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(
4031 Stack,
4032 {
4033 direction: "column",
4034 gap: "xs",
4035 children: [
4036 /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("h3", { className: "dataviews-view-grid__group-header", children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n17.sprintf)(
4037 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
4038 (0, import_i18n17.__)("%1$s: %2$s"),
4039 groupField.label,
4040 groupName
4041 ) }),
4042 /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
4043 CompositeGrid,
4044 {
4045 ...gridProps,
4046 data: groupItems,
4047 isInfiniteScroll: false
4048 }
4049 )
4050 ]
4051 },
4052 groupName
4053 )
4054 ) }),
4055 // Render a single grid with all data.
4056 hasData && !dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
4057 CompositeGrid,
4058 {
4059 ...gridProps,
4060 data,
4061 isInfiniteScroll: !!isInfiniteScroll
4062 }
4063 ),
4064 // Render empty state.
4065 !hasData && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
4066 "div",
4067 {
4068 className: clsx_default({
4069 "dataviews-loading": isLoading,
4070 "dataviews-no-results": !isLoading
4071 }),
4072 children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_components9.Spinner, {}) }) : empty
4073 }
4074 ),
4075 hasData && isLoading && /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_components9.Spinner, {}) })
4076 ]
4077 });
4078 }
4079 var grid_default = ViewGrid;
4080
4081 // packages/dataviews/build-module/components/dataviews-layouts/list/index.mjs
4082 var import_compose5 = __toESM(require_compose(), 1);
4083 var import_components10 = __toESM(require_components(), 1);
4084 var import_element13 = __toESM(require_element(), 1);
4085 var import_i18n18 = __toESM(require_i18n(), 1);
4086 var import_data3 = __toESM(require_data(), 1);
4087 var import_jsx_runtime41 = __toESM(require_jsx_runtime(), 1);
4088 var { Menu: Menu3 } = unlock(import_components10.privateApis);
4089 function generateItemWrapperCompositeId(idPrefix) {
4090 return `${idPrefix}-item-wrapper`;
4091 }
4092 function generatePrimaryActionCompositeId(idPrefix, primaryActionId) {
4093 return `${idPrefix}-primary-action-${primaryActionId}`;
4094 }
4095 function generateDropdownTriggerCompositeId(idPrefix) {
4096 return `${idPrefix}-dropdown`;
4097 }
4098 function PrimaryActionGridCell({
4099 idPrefix,
4100 primaryAction,
4101 item
4102 }) {
4103 const registry = (0, import_data3.useRegistry)();
4104 const [isModalOpen, setIsModalOpen] = (0, import_element13.useState)(false);
4105 const compositeItemId = generatePrimaryActionCompositeId(
4106 idPrefix,
4107 primaryAction.id
4108 );
4109 const label = typeof primaryAction.label === "string" ? primaryAction.label : primaryAction.label([item]);
4110 return "RenderModal" in primaryAction ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { role: "gridcell", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4111 import_components10.Composite.Item,
4112 {
4113 id: compositeItemId,
4114 render: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4115 import_components10.Button,
4116 {
4117 disabled: !!primaryAction.disabled,
4118 accessibleWhenDisabled: true,
4119 text: label,
4120 size: "small",
4121 onClick: () => setIsModalOpen(true)
4122 }
4123 ),
4124 children: isModalOpen && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4125 ActionModal,
4126 {
4127 action: primaryAction,
4128 items: [item],
4129 closeModal: () => setIsModalOpen(false)
4130 }
4131 )
4132 }
4133 ) }, primaryAction.id) : /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { role: "gridcell", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4134 import_components10.Composite.Item,
4135 {
4136 id: compositeItemId,
4137 render: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4138 import_components10.Button,
4139 {
4140 disabled: !!primaryAction.disabled,
4141 accessibleWhenDisabled: true,
4142 size: "small",
4143 onClick: () => {
4144 primaryAction.callback([item], { registry });
4145 },
4146 children: label
4147 }
4148 )
4149 }
4150 ) }, primaryAction.id);
4151 }
4152 function ListItem({
4153 view,
4154 actions,
4155 idPrefix,
4156 isSelected: isSelected2,
4157 item,
4158 titleField,
4159 mediaField,
4160 descriptionField: descriptionField2,
4161 onSelect,
4162 otherFields,
4163 onDropdownTriggerKeyDown,
4164 posinset
4165 }) {
4166 const {
4167 showTitle = true,
4168 showMedia = true,
4169 showDescription = true,
4170 infiniteScrollEnabled
4171 } = view;
4172 const itemRef = (0, import_element13.useRef)(null);
4173 const labelId = `${idPrefix}-label`;
4174 const descriptionId = `${idPrefix}-description`;
4175 const registry = (0, import_data3.useRegistry)();
4176 const [isHovered, setIsHovered] = (0, import_element13.useState)(false);
4177 const [activeModalAction, setActiveModalAction] = (0, import_element13.useState)(
4178 null
4179 );
4180 const handleHover = ({ type }) => {
4181 const isHover = type === "mouseenter";
4182 setIsHovered(isHover);
4183 };
4184 const { paginationInfo } = (0, import_element13.useContext)(dataviews_context_default);
4185 (0, import_element13.useEffect)(() => {
4186 if (isSelected2) {
4187 itemRef.current?.scrollIntoView({
4188 behavior: "auto",
4189 block: "nearest",
4190 inline: "nearest"
4191 });
4192 }
4193 }, [isSelected2]);
4194 const { primaryAction, eligibleActions } = (0, import_element13.useMemo)(() => {
4195 const _eligibleActions = actions.filter(
4196 (action) => !action.isEligible || action.isEligible(item)
4197 );
4198 const _primaryActions = _eligibleActions.filter(
4199 (action) => action.isPrimary
4200 );
4201 return {
4202 primaryAction: _primaryActions[0],
4203 eligibleActions: _eligibleActions
4204 };
4205 }, [actions, item]);
4206 const hasOnlyOnePrimaryAction = primaryAction && actions.length === 1;
4207 const renderedMediaField = showMedia && mediaField?.render ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "dataviews-view-list__media-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4208 mediaField.render,
4209 {
4210 item,
4211 field: mediaField,
4212 config: { sizes: "52px" }
4213 }
4214 ) }) : null;
4215 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(titleField.render, { item, field: titleField }) : null;
4216 const usedActions = eligibleActions?.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
4217 Stack,
4218 {
4219 direction: "row",
4220 gap: "sm",
4221 className: "dataviews-view-list__item-actions",
4222 children: [
4223 primaryAction && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4224 PrimaryActionGridCell,
4225 {
4226 idPrefix,
4227 primaryAction,
4228 item
4229 }
4230 ),
4231 !hasOnlyOnePrimaryAction && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { role: "gridcell", children: [
4232 /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(Menu3, { placement: "bottom-end", children: [
4233 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4234 Menu3.TriggerButton,
4235 {
4236 render: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4237 import_components10.Composite.Item,
4238 {
4239 id: generateDropdownTriggerCompositeId(
4240 idPrefix
4241 ),
4242 render: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4243 import_components10.Button,
4244 {
4245 size: "small",
4246 icon: more_vertical_default,
4247 label: (0, import_i18n18.__)("Actions"),
4248 accessibleWhenDisabled: true,
4249 disabled: !actions.length,
4250 onKeyDown: onDropdownTriggerKeyDown
4251 }
4252 )
4253 }
4254 )
4255 }
4256 ),
4257 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(Menu3.Popover, { children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4258 ActionsMenuGroup,
4259 {
4260 actions: eligibleActions,
4261 item,
4262 registry,
4263 setActiveModalAction
4264 }
4265 ) })
4266 ] }),
4267 !!activeModalAction && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4268 ActionModal,
4269 {
4270 action: activeModalAction,
4271 items: [item],
4272 closeModal: () => setActiveModalAction(null)
4273 }
4274 )
4275 ] })
4276 ]
4277 }
4278 );
4279 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4280 import_components10.Composite.Row,
4281 {
4282 ref: itemRef,
4283 render: (
4284 /* aria-posinset breaks Composite.Row if passed to it directly. */
4285 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4286 "div",
4287 {
4288 "aria-posinset": posinset,
4289 "aria-setsize": infiniteScrollEnabled ? paginationInfo.totalItems : void 0
4290 }
4291 )
4292 ),
4293 role: infiniteScrollEnabled ? "article" : "row",
4294 className: clsx_default({
4295 "is-selected": isSelected2,
4296 "is-hovered": isHovered
4297 }),
4298 onMouseEnter: handleHover,
4299 onMouseLeave: handleHover,
4300 children: /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
4301 Stack,
4302 {
4303 direction: "row",
4304 className: "dataviews-view-list__item-wrapper",
4305 children: [
4306 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { role: "gridcell", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4307 import_components10.Composite.Item,
4308 {
4309 id: generateItemWrapperCompositeId(idPrefix),
4310 "aria-pressed": isSelected2,
4311 "aria-labelledby": labelId,
4312 "aria-describedby": descriptionId,
4313 className: "dataviews-view-list__item",
4314 onClick: () => onSelect(item)
4315 }
4316 ) }),
4317 /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
4318 Stack,
4319 {
4320 direction: "row",
4321 gap: "sm",
4322 justify: "start",
4323 align: "flex-start",
4324 style: { flex: 1 },
4325 children: [
4326 renderedMediaField,
4327 /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
4328 Stack,
4329 {
4330 direction: "column",
4331 gap: "2xs",
4332 className: "dataviews-view-list__field-wrapper",
4333 children: [
4334 /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(Stack, { direction: "row", align: "center", children: [
4335 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4336 "div",
4337 {
4338 className: "dataviews-title-field",
4339 id: labelId,
4340 style: { flex: 1 },
4341 children: renderedTitleField
4342 }
4343 ),
4344 usedActions
4345 ] }),
4346 showDescription && descriptionField2?.render && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: "dataviews-view-list__field", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4347 descriptionField2.render,
4348 {
4349 item,
4350 field: descriptionField2
4351 }
4352 ) }),
4353 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4354 "div",
4355 {
4356 className: "dataviews-view-list__fields",
4357 id: descriptionId,
4358 children: otherFields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
4359 "div",
4360 {
4361 className: "dataviews-view-list__field",
4362 children: [
4363 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4364 import_components10.VisuallyHidden,
4365 {
4366 as: "span",
4367 className: "dataviews-view-list__field-label",
4368 children: field.label
4369 }
4370 ),
4371 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("span", { className: "dataviews-view-list__field-value", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4372 field.render,
4373 {
4374 item,
4375 field
4376 }
4377 ) })
4378 ]
4379 },
4380 field.id
4381 ))
4382 }
4383 )
4384 ]
4385 }
4386 )
4387 ]
4388 }
4389 )
4390 ]
4391 }
4392 )
4393 }
4394 );
4395 }
4396 function isDefined2(item) {
4397 return !!item;
4398 }
4399 function ViewList(props) {
4400 const {
4401 actions,
4402 data,
4403 fields,
4404 getItemId,
4405 isLoading,
4406 onChangeSelection,
4407 selection,
4408 view,
4409 className,
4410 empty
4411 } = props;
4412 const baseId = (0, import_compose5.useInstanceId)(ViewList, "view-list");
4413 const selectedItem = data?.findLast(
4414 (item) => selection.includes(getItemId(item))
4415 );
4416 const titleField = fields.find((field) => field.id === view.titleField);
4417 const mediaField = fields.find((field) => field.id === view.mediaField);
4418 const descriptionField2 = fields.find(
4419 (field) => field.id === view.descriptionField
4420 );
4421 const otherFields = (view?.fields ?? []).map((fieldId) => fields.find((f2) => fieldId === f2.id)).filter(isDefined2);
4422 const onSelect = (item) => onChangeSelection([getItemId(item)]);
4423 const generateCompositeItemIdPrefix = (0, import_element13.useCallback)(
4424 (item) => `${baseId}-${getItemId(item)}`,
4425 [baseId, getItemId]
4426 );
4427 const isActiveCompositeItem = (0, import_element13.useCallback)(
4428 (item, idToCheck) => {
4429 return idToCheck.startsWith(
4430 generateCompositeItemIdPrefix(item)
4431 );
4432 },
4433 [generateCompositeItemIdPrefix]
4434 );
4435 const [activeCompositeId, setActiveCompositeId] = (0, import_element13.useState)(void 0);
4436 (0, import_element13.useEffect)(() => {
4437 if (selectedItem) {
4438 setActiveCompositeId(
4439 generateItemWrapperCompositeId(
4440 generateCompositeItemIdPrefix(selectedItem)
4441 )
4442 );
4443 }
4444 }, [selectedItem, generateCompositeItemIdPrefix]);
4445 const activeItemIndex = data.findIndex(
4446 (item) => isActiveCompositeItem(item, activeCompositeId ?? "")
4447 );
4448 const previousActiveItemIndex = (0, import_compose5.usePrevious)(activeItemIndex);
4449 const isActiveIdInList = activeItemIndex !== -1;
4450 const selectCompositeItem = (0, import_element13.useCallback)(
4451 (targetIndex, generateCompositeId) => {
4452 const clampedIndex = Math.min(
4453 data.length - 1,
4454 Math.max(0, targetIndex)
4455 );
4456 if (!data[clampedIndex]) {
4457 return;
4458 }
4459 const itemIdPrefix = generateCompositeItemIdPrefix(
4460 data[clampedIndex]
4461 );
4462 const targetCompositeItemId = generateCompositeId(itemIdPrefix);
4463 setActiveCompositeId(targetCompositeItemId);
4464 document.getElementById(targetCompositeItemId)?.focus();
4465 },
4466 [data, generateCompositeItemIdPrefix]
4467 );
4468 (0, import_element13.useEffect)(() => {
4469 const wasActiveIdInList = previousActiveItemIndex !== void 0 && previousActiveItemIndex !== -1;
4470 if (!isActiveIdInList && wasActiveIdInList) {
4471 selectCompositeItem(
4472 previousActiveItemIndex,
4473 generateItemWrapperCompositeId
4474 );
4475 }
4476 }, [isActiveIdInList, selectCompositeItem, previousActiveItemIndex]);
4477 const onDropdownTriggerKeyDown = (0, import_element13.useCallback)(
4478 (event) => {
4479 if (event.key === "ArrowDown") {
4480 event.preventDefault();
4481 selectCompositeItem(
4482 activeItemIndex + 1,
4483 generateDropdownTriggerCompositeId
4484 );
4485 }
4486 if (event.key === "ArrowUp") {
4487 event.preventDefault();
4488 selectCompositeItem(
4489 activeItemIndex - 1,
4490 generateDropdownTriggerCompositeId
4491 );
4492 }
4493 },
4494 [selectCompositeItem, activeItemIndex]
4495 );
4496 const hasData = data?.length;
4497 if (!hasData) {
4498 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4499 "div",
4500 {
4501 className: clsx_default({
4502 "dataviews-loading": isLoading,
4503 "dataviews-no-results": !hasData && !isLoading
4504 }),
4505 children: !hasData && (isLoading ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(import_components10.Spinner, {}) }) : empty)
4506 }
4507 );
4508 }
4509 const groupField = view.groupBy?.field ? fields.find((field) => field.id === view.groupBy?.field) : null;
4510 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
4511 if (hasData && groupField && dataByGroup) {
4512 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4513 import_components10.Composite,
4514 {
4515 id: `${baseId}`,
4516 render: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", {}),
4517 className: "dataviews-view-list__group",
4518 role: "grid",
4519 activeId: activeCompositeId,
4520 setActiveId: setActiveCompositeId,
4521 children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4522 Stack,
4523 {
4524 direction: "column",
4525 gap: "md",
4526 className: clsx_default("dataviews-view-list", className),
4527 children: Array.from(dataByGroup.entries()).map(
4528 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
4529 Stack,
4530 {
4531 direction: "column",
4532 gap: "xs",
4533 children: [
4534 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("h3", { className: "dataviews-view-list__group-header", children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n18.sprintf)(
4535 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
4536 (0, import_i18n18.__)("%1$s: %2$s"),
4537 groupField.label,
4538 groupName
4539 ) }),
4540 groupItems.map((item) => {
4541 const id = generateCompositeItemIdPrefix(item);
4542 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4543 ListItem,
4544 {
4545 view,
4546 idPrefix: id,
4547 actions,
4548 item,
4549 isSelected: item === selectedItem,
4550 onSelect,
4551 mediaField,
4552 titleField,
4553 descriptionField: descriptionField2,
4554 otherFields,
4555 onDropdownTriggerKeyDown
4556 },
4557 id
4558 );
4559 })
4560 ]
4561 },
4562 groupName
4563 )
4564 )
4565 }
4566 )
4567 }
4568 );
4569 }
4570 return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(import_jsx_runtime41.Fragment, { children: [
4571 /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4572 import_components10.Composite,
4573 {
4574 id: baseId,
4575 render: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", {}),
4576 className: clsx_default("dataviews-view-list", className, {
4577 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
4578 view.layout.density
4579 )
4580 }),
4581 role: view.infiniteScrollEnabled ? "feed" : "grid",
4582 activeId: activeCompositeId,
4583 setActiveId: setActiveCompositeId,
4584 children: data.map((item, index) => {
4585 const id = generateCompositeItemIdPrefix(item);
4586 return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
4587 ListItem,
4588 {
4589 view,
4590 idPrefix: id,
4591 actions,
4592 item,
4593 isSelected: item === selectedItem,
4594 onSelect,
4595 mediaField,
4596 titleField,
4597 descriptionField: descriptionField2,
4598 otherFields,
4599 onDropdownTriggerKeyDown,
4600 posinset: view.infiniteScrollEnabled ? index + 1 : void 0
4601 },
4602 id
4603 );
4604 })
4605 }
4606 ),
4607 hasData && isLoading && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(import_components10.Spinner, {}) })
4608 ] });
4609 }
4610
4611 // packages/dataviews/build-module/components/dataviews-layouts/activity/index.mjs
4612 var import_components12 = __toESM(require_components(), 1);
4613
4614 // packages/dataviews/build-module/components/dataviews-layouts/activity/activity-group.mjs
4615 var import_i18n19 = __toESM(require_i18n(), 1);
4616 var import_element14 = __toESM(require_element(), 1);
4617 var import_jsx_runtime42 = __toESM(require_jsx_runtime(), 1);
4618 function ActivityGroup({
4619 groupName,
4620 groupData,
4621 groupField,
4622 showLabel = true,
4623 children
4624 }) {
4625 const groupHeader = showLabel ? (0, import_element14.createInterpolateElement)(
4626 // translators: %s: The label of the field e.g. "Status".
4627 (0, import_i18n19.sprintf)((0, import_i18n19.__)("%s: <groupName />"), groupField.label).trim(),
4628 {
4629 groupName: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
4630 groupField.render,
4631 {
4632 item: groupData[0],
4633 field: groupField
4634 }
4635 )
4636 }
4637 ) : /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(groupField.render, { item: groupData[0], field: groupField });
4638 return /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)(
4639 Stack,
4640 {
4641 direction: "column",
4642 className: "dataviews-view-activity__group",
4643 children: [
4644 /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("h3", { className: "dataviews-view-activity__group-header", children: groupHeader }),
4645 children
4646 ]
4647 },
4648 groupName
4649 );
4650 }
4651
4652 // packages/dataviews/build-module/components/dataviews-layouts/activity/activity-item.mjs
4653 var import_components11 = __toESM(require_components(), 1);
4654 var import_element15 = __toESM(require_element(), 1);
4655 var import_data4 = __toESM(require_data(), 1);
4656 var import_jsx_runtime43 = __toESM(require_jsx_runtime(), 1);
4657 function ActivityItem(props) {
4658 const {
4659 view,
4660 actions,
4661 item,
4662 titleField,
4663 mediaField,
4664 descriptionField: descriptionField2,
4665 otherFields,
4666 posinset,
4667 onClickItem,
4668 renderItemLink,
4669 isItemClickable: isItemClickable2
4670 } = props;
4671 const {
4672 showTitle = true,
4673 showMedia = true,
4674 showDescription = true,
4675 infiniteScrollEnabled
4676 } = view;
4677 const itemRef = (0, import_element15.useRef)(null);
4678 const registry = (0, import_data4.useRegistry)();
4679 const { paginationInfo } = (0, import_element15.useContext)(dataviews_context_default);
4680 const { primaryActions, eligibleActions } = (0, import_element15.useMemo)(() => {
4681 const _eligibleActions = actions.filter(
4682 (action) => !action.isEligible || action.isEligible(item)
4683 );
4684 const _primaryActions = _eligibleActions.filter(
4685 (action) => action.isPrimary
4686 );
4687 return {
4688 primaryActions: _primaryActions,
4689 eligibleActions: _eligibleActions
4690 };
4691 }, [actions, item]);
4692 const density = view.layout?.density ?? "balanced";
4693 const mediaContent = showMedia && density !== "compact" && mediaField?.render ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4694 mediaField.render,
4695 {
4696 item,
4697 field: mediaField,
4698 config: {
4699 sizes: density === "comfortable" ? "32px" : "24px"
4700 }
4701 }
4702 ) : null;
4703 const renderedMediaField = /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "dataviews-view-activity__item-type-icon", children: mediaContent || /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4704 "span",
4705 {
4706 className: "dataviews-view-activity__item-bullet",
4707 "aria-hidden": "true"
4708 }
4709 ) });
4710 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(titleField.render, { item, field: titleField }) : null;
4711 const verticalGap = (0, import_element15.useMemo)(() => {
4712 switch (density) {
4713 case "comfortable":
4714 return "sm";
4715 default:
4716 return "xs";
4717 }
4718 }, [density]);
4719 return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4720 "div",
4721 {
4722 ref: itemRef,
4723 role: infiniteScrollEnabled ? "article" : void 0,
4724 "aria-posinset": posinset,
4725 "aria-setsize": infiniteScrollEnabled ? paginationInfo.totalItems : void 0,
4726 className: clsx_default(
4727 "dataviews-view-activity__item",
4728 density === "compact" && "is-compact",
4729 density === "balanced" && "is-balanced",
4730 density === "comfortable" && "is-comfortable"
4731 ),
4732 children: /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(Stack, { direction: "row", gap: "md", justify: "start", align: "flex-start", children: [
4733 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4734 Stack,
4735 {
4736 direction: "column",
4737 gap: "2xs",
4738 align: "center",
4739 className: "dataviews-view-activity__item-type",
4740 children: renderedMediaField
4741 }
4742 ),
4743 /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4744 Stack,
4745 {
4746 direction: "column",
4747 gap: verticalGap,
4748 align: "flex-start",
4749 className: "dataviews-view-activity__item-content",
4750 children: [
4751 renderedTitleField && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4752 ItemClickWrapper,
4753 {
4754 item,
4755 isItemClickable: isItemClickable2,
4756 onClickItem,
4757 renderItemLink,
4758 className: "dataviews-view-activity__item-title",
4759 children: renderedTitleField
4760 }
4761 ),
4762 showDescription && descriptionField2 && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "dataviews-view-activity__item-description", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4763 descriptionField2.render,
4764 {
4765 item,
4766 field: descriptionField2
4767 }
4768 ) }),
4769 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "dataviews-view-activity__item-fields", children: otherFields.map((field) => /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
4770 "div",
4771 {
4772 className: "dataviews-view-activity__item-field",
4773 children: [
4774 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4775 import_components11.VisuallyHidden,
4776 {
4777 as: "span",
4778 className: "dataviews-view-activity__item-field-label",
4779 children: field.label
4780 }
4781 ),
4782 /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "dataviews-view-activity__item-field-value", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4783 field.render,
4784 {
4785 item,
4786 field
4787 }
4788 ) })
4789 ]
4790 },
4791 field.id
4792 )) }),
4793 !!primaryActions?.length && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4794 PrimaryActions,
4795 {
4796 item,
4797 actions: primaryActions,
4798 registry,
4799 buttonVariant: "secondary"
4800 }
4801 )
4802 ]
4803 }
4804 ),
4805 primaryActions.length < eligibleActions.length && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "dataviews-view-activity__item-actions", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4806 ItemActions,
4807 {
4808 item,
4809 actions: eligibleActions,
4810 isCompact: true
4811 }
4812 ) })
4813 ] })
4814 }
4815 );
4816 }
4817 var activity_item_default = ActivityItem;
4818
4819 // packages/dataviews/build-module/components/dataviews-layouts/activity/activity-items.mjs
4820 var import_react3 = __toESM(require_react(), 1);
4821 function isDefined3(item) {
4822 return !!item;
4823 }
4824 function ActivityItems(props) {
4825 const { data, fields, getItemId, view } = props;
4826 const titleField = fields.find((field) => field.id === view.titleField);
4827 const mediaField = fields.find((field) => field.id === view.mediaField);
4828 const descriptionField2 = fields.find(
4829 (field) => field.id === view.descriptionField
4830 );
4831 const otherFields = (view?.fields ?? []).map((fieldId) => fields.find((f2) => fieldId === f2.id)).filter(isDefined3);
4832 return data.map((item, index) => {
4833 return /* @__PURE__ */ (0, import_react3.createElement)(
4834 activity_item_default,
4835 {
4836 ...props,
4837 key: getItemId(item),
4838 item,
4839 mediaField,
4840 titleField,
4841 descriptionField: descriptionField2,
4842 otherFields,
4843 posinset: view.infiniteScrollEnabled ? index + 1 : void 0
4844 }
4845 );
4846 });
4847 }
4848
4849 // packages/dataviews/build-module/components/dataviews-layouts/activity/index.mjs
4850 var import_jsx_runtime44 = __toESM(require_jsx_runtime(), 1);
4851 function ViewActivity(props) {
4852 const { empty, data, fields, isLoading, view, className } = props;
4853 const hasData = data?.length;
4854 if (!hasData) {
4855 return /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
4856 "div",
4857 {
4858 className: clsx_default({
4859 "dataviews-loading": isLoading,
4860 "dataviews-no-results": !hasData && !isLoading
4861 }),
4862 children: !hasData && (isLoading ? /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(import_components12.Spinner, {}) }) : empty)
4863 }
4864 );
4865 }
4866 const wrapperClassName = clsx_default("dataviews-view-activity", className);
4867 const groupField = view.groupBy?.field ? fields.find((field) => field.id === view.groupBy?.field) : null;
4868 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
4869 const groupedEntries = dataByGroup ? Array.from(dataByGroup.entries()) : [];
4870 if (hasData && groupField && dataByGroup) {
4871 return /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(Stack, { direction: "column", gap: "xs", className: wrapperClassName, children: groupedEntries.map(
4872 ([groupName, groupData]) => /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
4873 ActivityGroup,
4874 {
4875 groupName,
4876 groupData,
4877 groupField,
4878 showLabel: view.groupBy?.showLabel !== false,
4879 children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
4880 ActivityItems,
4881 {
4882 ...props,
4883 data: groupData
4884 }
4885 )
4886 },
4887 groupName
4888 )
4889 ) });
4890 }
4891 return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)(import_jsx_runtime44.Fragment, { children: [
4892 /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
4893 "div",
4894 {
4895 className: wrapperClassName,
4896 role: view.infiniteScrollEnabled ? "feed" : void 0,
4897 children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(ActivityItems, { ...props })
4898 }
4899 ),
4900 hasData && isLoading && /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(import_components12.Spinner, {}) })
4901 ] });
4902 }
4903
4904 // packages/dataviews/build-module/components/dataviews-layouts/picker-grid/index.mjs
4905 var import_components15 = __toESM(require_components(), 1);
4906 var import_i18n22 = __toESM(require_i18n(), 1);
4907 var import_compose6 = __toESM(require_compose(), 1);
4908 var import_element19 = __toESM(require_element(), 1);
4909
4910 // packages/dataviews/build-module/components/dataviews-picker-footer/index.mjs
4911 var import_components14 = __toESM(require_components(), 1);
4912 var import_data5 = __toESM(require_data(), 1);
4913 var import_element17 = __toESM(require_element(), 1);
4914 var import_i18n21 = __toESM(require_i18n(), 1);
4915
4916 // packages/dataviews/build-module/components/dataviews-pagination/index.mjs
4917 var import_components13 = __toESM(require_components(), 1);
4918 var import_element16 = __toESM(require_element(), 1);
4919 var import_i18n20 = __toESM(require_i18n(), 1);
4920 var import_jsx_runtime45 = __toESM(require_jsx_runtime(), 1);
4921 function DataViewsPagination() {
4922 const {
4923 view,
4924 onChangeView,
4925 paginationInfo: { totalItems = 0, totalPages }
4926 } = (0, import_element16.useContext)(dataviews_context_default);
4927 if (!totalItems || !totalPages || view.infiniteScrollEnabled) {
4928 return null;
4929 }
4930 const currentPage = view.page ?? 1;
4931 const pageSelectOptions = Array.from(Array(totalPages)).map(
4932 (_, i2) => {
4933 const page = i2 + 1;
4934 return {
4935 value: page.toString(),
4936 label: page.toString(),
4937 "aria-label": currentPage === page ? (0, import_i18n20.sprintf)(
4938 // translators: 1: current page number. 2: total number of pages.
4939 (0, import_i18n20.__)("Page %1$d of %2$d"),
4940 currentPage,
4941 totalPages
4942 ) : page.toString()
4943 };
4944 }
4945 );
4946 return !!totalItems && totalPages !== 1 && /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
4947 Stack,
4948 {
4949 direction: "row",
4950 className: "dataviews-pagination",
4951 justify: "end",
4952 align: "center",
4953 gap: "lg",
4954 children: [
4955 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
4956 Stack,
4957 {
4958 direction: "row",
4959 justify: "flex-start",
4960 align: "center",
4961 gap: "2xs",
4962 className: "dataviews-pagination__page-select",
4963 children: (0, import_element16.createInterpolateElement)(
4964 (0, import_i18n20.sprintf)(
4965 // translators: 1: Current page number, 2: Total number of pages.
4966 (0, import_i18n20._x)(
4967 "<div>Page</div>%1$s<div>of %2$d</div>",
4968 "paging"
4969 ),
4970 "<CurrentPage />",
4971 totalPages
4972 ),
4973 {
4974 div: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { "aria-hidden": true }),
4975 CurrentPage: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
4976 import_components13.SelectControl,
4977 {
4978 "aria-label": (0, import_i18n20.__)("Current page"),
4979 value: currentPage.toString(),
4980 options: pageSelectOptions,
4981 onChange: (newValue) => {
4982 onChangeView({
4983 ...view,
4984 page: +newValue
4985 });
4986 },
4987 size: "small",
4988 variant: "minimal"
4989 }
4990 )
4991 }
4992 )
4993 }
4994 ),
4995 /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(Stack, { direction: "row", gap: "2xs", align: "center", children: [
4996 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
4997 import_components13.Button,
4998 {
4999 onClick: () => onChangeView({
5000 ...view,
5001 page: currentPage - 1
5002 }),
5003 disabled: currentPage === 1,
5004 accessibleWhenDisabled: true,
5005 label: (0, import_i18n20.__)("Previous page"),
5006 icon: (0, import_i18n20.isRTL)() ? next_default : previous_default,
5007 showTooltip: true,
5008 size: "compact",
5009 tooltipPosition: "top"
5010 }
5011 ),
5012 /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
5013 import_components13.Button,
5014 {
5015 onClick: () => onChangeView({ ...view, page: currentPage + 1 }),
5016 disabled: currentPage >= totalPages,
5017 accessibleWhenDisabled: true,
5018 label: (0, import_i18n20.__)("Next page"),
5019 icon: (0, import_i18n20.isRTL)() ? previous_default : next_default,
5020 showTooltip: true,
5021 size: "compact",
5022 tooltipPosition: "top"
5023 }
5024 )
5025 ] })
5026 ]
5027 }
5028 );
5029 }
5030 var dataviews_pagination_default = (0, import_element16.memo)(DataViewsPagination);
5031
5032 // packages/dataviews/build-module/components/dataviews-picker-footer/index.mjs
5033 var import_jsx_runtime46 = __toESM(require_jsx_runtime(), 1);
5034 var EMPTY_ARRAY2 = [];
5035 function useIsMultiselectPicker(actions) {
5036 return (0, import_element17.useMemo)(() => {
5037 return actions?.every((action) => action.supportsBulk);
5038 }, [actions]);
5039 }
5040 function BulkSelectionCheckbox2({
5041 selection,
5042 selectedItems,
5043 onChangeSelection,
5044 data,
5045 getItemId
5046 }) {
5047 const areAllSelected = selectedItems.length === data.length;
5048 return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5049 import_components14.CheckboxControl,
5050 {
5051 className: "dataviews-view-table-selection-checkbox",
5052 checked: areAllSelected,
5053 indeterminate: !areAllSelected && !!selectedItems.length,
5054 onChange: () => {
5055 if (areAllSelected) {
5056 onChangeSelection(
5057 selection.filter(
5058 (id) => !data.some(
5059 (item) => id === getItemId(item)
5060 )
5061 )
5062 );
5063 } else {
5064 const selectionSet = /* @__PURE__ */ new Set([
5065 ...selection,
5066 ...data.map((item) => getItemId(item))
5067 ]);
5068 onChangeSelection(Array.from(selectionSet));
5069 }
5070 },
5071 "aria-label": areAllSelected ? (0, import_i18n21.__)("Deselect all") : (0, import_i18n21.__)("Select all")
5072 }
5073 );
5074 }
5075 function ActionButtons({
5076 actions,
5077 items,
5078 selection
5079 }) {
5080 const registry = (0, import_data5.useRegistry)();
5081 const [actionInProgress, setActionInProgress] = (0, import_element17.useState)(
5082 null
5083 );
5084 return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(Stack, { direction: "row", gap: "2xs", children: actions.map((action) => {
5085 if (!("callback" in action)) {
5086 return null;
5087 }
5088 const { id, label, icon, isPrimary, callback } = action;
5089 const _label = typeof label === "string" ? label : label(items);
5090 const variant = isPrimary ? "primary" : "tertiary";
5091 const isInProgress = id === actionInProgress;
5092 return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5093 import_components14.Button,
5094 {
5095 accessibleWhenDisabled: true,
5096 icon,
5097 disabled: isInProgress || !selection?.length,
5098 isBusy: isInProgress,
5099 onClick: async () => {
5100 setActionInProgress(id);
5101 await callback(items, {
5102 registry
5103 });
5104 setActionInProgress(null);
5105 },
5106 size: "compact",
5107 variant,
5108 children: _label
5109 },
5110 id
5111 );
5112 }) });
5113 }
5114 function DataViewsPickerFooter() {
5115 const {
5116 data,
5117 selection,
5118 onChangeSelection,
5119 getItemId,
5120 actions = EMPTY_ARRAY2
5121 } = (0, import_element17.useContext)(dataviews_context_default);
5122 const selectionCount = selection.length;
5123 const isMultiselect = useIsMultiselectPicker(actions);
5124 const message2 = selectionCount > 0 ? (0, import_i18n21.sprintf)(
5125 /* translators: %d: number of items. */
5126 (0, import_i18n21._n)(
5127 "%d Item selected",
5128 "%d Items selected",
5129 selectionCount
5130 ),
5131 selectionCount
5132 ) : (0, import_i18n21.sprintf)(
5133 /* translators: %d: number of items. */
5134 (0, import_i18n21._n)("%d Item", "%d Items", data.length),
5135 data.length
5136 );
5137 const selectedItems = (0, import_element17.useMemo)(
5138 () => data.filter((item) => selection.includes(getItemId(item))),
5139 [selection, getItemId, data]
5140 );
5141 return /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)(
5142 Stack,
5143 {
5144 direction: "row",
5145 justify: "space-between",
5146 align: "center",
5147 className: "dataviews-footer",
5148 gap: "xs",
5149 children: [
5150 /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)(
5151 Stack,
5152 {
5153 direction: "row",
5154 className: "dataviews-picker-footer__bulk-selection",
5155 gap: "sm",
5156 align: "center",
5157 children: [
5158 isMultiselect && /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5159 BulkSelectionCheckbox2,
5160 {
5161 selection,
5162 selectedItems,
5163 onChangeSelection,
5164 data,
5165 getItemId
5166 }
5167 ),
5168 /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("span", { className: "dataviews-bulk-actions-footer__item-count", children: message2 })
5169 ]
5170 }
5171 ),
5172 /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(dataviews_pagination_default, {}),
5173 Boolean(actions?.length) && /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("div", { className: "dataviews-picker-footer__actions", children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(
5174 ActionButtons,
5175 {
5176 actions,
5177 items: selectedItems,
5178 selection
5179 }
5180 ) })
5181 ]
5182 }
5183 );
5184 }
5185
5186 // packages/dataviews/build-module/components/dataviews-layouts/utils/grid-items.mjs
5187 var import_element18 = __toESM(require_element(), 1);
5188 var import_jsx_runtime47 = __toESM(require_jsx_runtime(), 1);
5189 var GridItems = (0, import_element18.forwardRef)(({ className, previewSize, ...props }, ref) => {
5190 return /* @__PURE__ */ (0, import_jsx_runtime47.jsx)(
5191 "div",
5192 {
5193 ref,
5194 className: clsx_default("dataviews-view-grid-items", className),
5195 style: {
5196 gridTemplateColumns: previewSize && `repeat(auto-fill, minmax(${previewSize}px, 1fr))`
5197 },
5198 ...props
5199 }
5200 );
5201 });
5202
5203 // packages/dataviews/build-module/components/dataviews-layouts/picker-grid/index.mjs
5204 var import_jsx_runtime48 = __toESM(require_jsx_runtime(), 1);
5205 var { Badge: Badge2 } = unlock(import_components15.privateApis);
5206 function GridItem3({
5207 view,
5208 multiselect,
5209 selection,
5210 onChangeSelection,
5211 getItemId,
5212 item,
5213 mediaField,
5214 titleField,
5215 descriptionField: descriptionField2,
5216 regularFields,
5217 badgeFields,
5218 config,
5219 posinset,
5220 setsize
5221 }) {
5222 const { showTitle = true, showMedia = true, showDescription = true } = view;
5223 const id = getItemId(item);
5224 const isSelected2 = selection.includes(id);
5225 const renderedMediaField = mediaField?.render ? /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5226 mediaField.render,
5227 {
5228 item,
5229 field: mediaField,
5230 config
5231 }
5232 ) : null;
5233 const renderedTitleField = showTitle && titleField?.render ? /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(titleField.render, { item, field: titleField }) : null;
5234 return /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(
5235 import_components15.Composite.Item,
5236 {
5237 "aria-label": titleField ? titleField.getValue({ item }) || (0, import_i18n22.__)("(no title)") : void 0,
5238 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(Stack, { direction: "column", children, ...props }),
5239 role: "option",
5240 "aria-posinset": posinset,
5241 "aria-setsize": setsize,
5242 className: clsx_default("dataviews-view-picker-grid__card", {
5243 "is-selected": isSelected2
5244 }),
5245 "aria-selected": isSelected2,
5246 onClick: () => {
5247 if (isSelected2) {
5248 onChangeSelection(
5249 selection.filter((itemId) => id !== itemId)
5250 );
5251 } else {
5252 const newSelection = multiselect ? [...selection, id] : [id];
5253 onChangeSelection(newSelection);
5254 }
5255 },
5256 children: [
5257 showMedia && renderedMediaField && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("div", { className: "dataviews-view-picker-grid__media", children: renderedMediaField }),
5258 showMedia && renderedMediaField && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5259 DataViewsSelectionCheckbox,
5260 {
5261 item,
5262 selection,
5263 onChangeSelection,
5264 getItemId,
5265 titleField,
5266 disabled: false,
5267 "aria-hidden": true,
5268 tabIndex: -1
5269 }
5270 ),
5271 showTitle && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5272 Stack,
5273 {
5274 direction: "row",
5275 justify: "space-between",
5276 className: "dataviews-view-picker-grid__title-actions",
5277 children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("div", { className: "dataviews-view-picker-grid__title-field dataviews-title-field", children: renderedTitleField })
5278 }
5279 ),
5280 /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(Stack, { direction: "column", gap: "2xs", children: [
5281 showDescription && descriptionField2?.render && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5282 descriptionField2.render,
5283 {
5284 item,
5285 field: descriptionField2
5286 }
5287 ),
5288 !!badgeFields?.length && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5289 Stack,
5290 {
5291 direction: "row",
5292 className: "dataviews-view-picker-grid__badge-fields",
5293 gap: "xs",
5294 wrap: "wrap",
5295 align: "top",
5296 justify: "flex-start",
5297 children: badgeFields.map((field) => {
5298 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5299 Badge2,
5300 {
5301 className: "dataviews-view-picker-grid__field-value",
5302 children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5303 field.render,
5304 {
5305 item,
5306 field
5307 }
5308 )
5309 },
5310 field.id
5311 );
5312 })
5313 }
5314 ),
5315 !!regularFields?.length && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5316 Stack,
5317 {
5318 direction: "column",
5319 className: "dataviews-view-picker-grid__fields",
5320 gap: "2xs",
5321 children: regularFields.map((field) => {
5322 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5323 import_components15.Flex,
5324 {
5325 className: "dataviews-view-picker-grid__field",
5326 gap: 1,
5327 justify: "flex-start",
5328 expanded: true,
5329 style: { height: "auto" },
5330 direction: "row",
5331 children: /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(import_jsx_runtime48.Fragment, { children: [
5332 /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(import_components15.FlexItem, { className: "dataviews-view-picker-grid__field-name", children: field.header }),
5333 /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5334 import_components15.FlexItem,
5335 {
5336 className: "dataviews-view-picker-grid__field-value",
5337 style: { maxHeight: "none" },
5338 children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5339 field.render,
5340 {
5341 item,
5342 field
5343 }
5344 )
5345 }
5346 )
5347 ] })
5348 },
5349 field.id
5350 );
5351 })
5352 }
5353 )
5354 ] })
5355 ]
5356 },
5357 id
5358 );
5359 }
5360 function GridGroup({
5361 groupName,
5362 groupField,
5363 showLabel = true,
5364 children
5365 }) {
5366 const headerId = (0, import_compose6.useInstanceId)(
5367 GridGroup,
5368 "dataviews-view-picker-grid-group__header"
5369 );
5370 return /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(
5371 Stack,
5372 {
5373 direction: "column",
5374 gap: "xs",
5375 role: "group",
5376 "aria-labelledby": headerId,
5377 children: [
5378 /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5379 "h3",
5380 {
5381 className: "dataviews-view-picker-grid-group__header",
5382 id: headerId,
5383 children: showLabel ? (0, import_i18n22.sprintf)(
5384 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
5385 (0, import_i18n22.__)("%1$s: %2$s"),
5386 groupField.label,
5387 groupName
5388 ) : groupName
5389 }
5390 ),
5391 children
5392 ]
5393 },
5394 groupName
5395 );
5396 }
5397 function ViewPickerGrid({
5398 actions,
5399 data,
5400 fields,
5401 getItemId,
5402 isLoading,
5403 onChangeSelection,
5404 selection,
5405 view,
5406 className,
5407 empty
5408 }) {
5409 const { resizeObserverRef, paginationInfo, itemListLabel } = (0, import_element19.useContext)(dataviews_context_default);
5410 const titleField = fields.find(
5411 (field) => field.id === view?.titleField
5412 );
5413 const mediaField = fields.find(
5414 (field) => field.id === view?.mediaField
5415 );
5416 const descriptionField2 = fields.find(
5417 (field) => field.id === view?.descriptionField
5418 );
5419 const otherFields = view.fields ?? [];
5420 const { regularFields, badgeFields } = otherFields.reduce(
5421 (accumulator, fieldId) => {
5422 const field = fields.find((f2) => f2.id === fieldId);
5423 if (!field) {
5424 return accumulator;
5425 }
5426 const key = view.layout?.badgeFields?.includes(fieldId) ? "badgeFields" : "regularFields";
5427 accumulator[key].push(field);
5428 return accumulator;
5429 },
5430 { regularFields: [], badgeFields: [] }
5431 );
5432 const hasData = !!data?.length;
5433 const usedPreviewSize = view.layout?.previewSize;
5434 const isMultiselect = useIsMultiselectPicker(actions);
5435 const size = "900px";
5436 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
5437 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
5438 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
5439 const currentPage = view?.page ?? 1;
5440 const perPage = view?.perPage ?? 0;
5441 const setSize = isInfiniteScroll ? paginationInfo?.totalItems : void 0;
5442 return /* @__PURE__ */ (0, import_jsx_runtime48.jsxs)(import_jsx_runtime48.Fragment, {
5443 // Render multiple groups.
5444 children: [
5445 hasData && groupField && dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5446 import_components15.Composite,
5447 {
5448 virtualFocus: true,
5449 orientation: "horizontal",
5450 role: "listbox",
5451 "aria-multiselectable": isMultiselect,
5452 className: clsx_default(
5453 "dataviews-view-picker-grid",
5454 className
5455 ),
5456 "aria-label": itemListLabel,
5457 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5458 Stack,
5459 {
5460 direction: "column",
5461 gap: "md",
5462 children,
5463 ...props
5464 }
5465 ),
5466 children: Array.from(dataByGroup.entries()).map(
5467 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5468 GridGroup,
5469 {
5470 groupName,
5471 groupField,
5472 showLabel: view.groupBy?.showLabel !== false,
5473 children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5474 GridItems,
5475 {
5476 previewSize: usedPreviewSize,
5477 style: {
5478 gridTemplateColumns: usedPreviewSize && `repeat(auto-fill, minmax(${usedPreviewSize}px, 1fr))`
5479 },
5480 "aria-busy": isLoading,
5481 ref: resizeObserverRef,
5482 children: groupItems.map((item) => {
5483 const posInSet = (currentPage - 1) * perPage + data.indexOf(item) + 1;
5484 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5485 GridItem3,
5486 {
5487 view,
5488 multiselect: isMultiselect,
5489 selection,
5490 onChangeSelection,
5491 getItemId,
5492 item,
5493 mediaField,
5494 titleField,
5495 descriptionField: descriptionField2,
5496 regularFields,
5497 badgeFields,
5498 config: {
5499 sizes: size
5500 },
5501 posinset: posInSet,
5502 setsize: setSize
5503 },
5504 getItemId(item)
5505 );
5506 })
5507 }
5508 )
5509 },
5510 groupName
5511 )
5512 )
5513 }
5514 ),
5515 // Render a single grid with all data.
5516 hasData && !dataByGroup && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5517 import_components15.Composite,
5518 {
5519 render: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5520 GridItems,
5521 {
5522 className: clsx_default(
5523 "dataviews-view-picker-grid",
5524 className
5525 ),
5526 previewSize: usedPreviewSize,
5527 "aria-busy": isLoading,
5528 ref: resizeObserverRef
5529 }
5530 ),
5531 virtualFocus: true,
5532 orientation: "horizontal",
5533 role: "listbox",
5534 "aria-multiselectable": isMultiselect,
5535 "aria-label": itemListLabel,
5536 children: data.map((item, index) => {
5537 let posinset = isInfiniteScroll ? index + 1 : void 0;
5538 if (!isInfiniteScroll) {
5539 posinset = (currentPage - 1) * perPage + index + 1;
5540 }
5541 return /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5542 GridItem3,
5543 {
5544 view,
5545 multiselect: isMultiselect,
5546 selection,
5547 onChangeSelection,
5548 getItemId,
5549 item,
5550 mediaField,
5551 titleField,
5552 descriptionField: descriptionField2,
5553 regularFields,
5554 badgeFields,
5555 config: {
5556 sizes: size
5557 },
5558 posinset,
5559 setsize: setSize
5560 },
5561 getItemId(item)
5562 );
5563 })
5564 }
5565 ),
5566 // Render empty state.
5567 !hasData && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(
5568 "div",
5569 {
5570 className: clsx_default({
5571 "dataviews-loading": isLoading,
5572 "dataviews-no-results": !isLoading
5573 }),
5574 children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(import_components15.Spinner, {}) }) : empty
5575 }
5576 ),
5577 hasData && isLoading && /* @__PURE__ */ (0, import_jsx_runtime48.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime48.jsx)(import_components15.Spinner, {}) })
5578 ]
5579 });
5580 }
5581 var picker_grid_default = ViewPickerGrid;
5582
5583 // packages/dataviews/build-module/components/dataviews-layouts/picker-table/index.mjs
5584 var import_i18n23 = __toESM(require_i18n(), 1);
5585 var import_components16 = __toESM(require_components(), 1);
5586 var import_element20 = __toESM(require_element(), 1);
5587 var import_jsx_runtime49 = __toESM(require_jsx_runtime(), 1);
5588 function TableColumnField2({
5589 item,
5590 fields,
5591 column,
5592 align
5593 }) {
5594 const field = fields.find((f2) => f2.id === column);
5595 if (!field) {
5596 return null;
5597 }
5598 const className = clsx_default("dataviews-view-table__cell-content-wrapper", {
5599 "dataviews-view-table__cell-align-end": align === "end",
5600 "dataviews-view-table__cell-align-center": align === "center"
5601 });
5602 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(field.render, { item, field }) });
5603 }
5604 function TableRow2({
5605 item,
5606 fields,
5607 id,
5608 view,
5609 titleField,
5610 mediaField,
5611 descriptionField: descriptionField2,
5612 selection,
5613 getItemId,
5614 onChangeSelection,
5615 multiselect,
5616 posinset
5617 }) {
5618 const { paginationInfo } = (0, import_element20.useContext)(dataviews_context_default);
5619 const isSelected2 = selection.includes(id);
5620 const [isHovered, setIsHovered] = (0, import_element20.useState)(false);
5621 const {
5622 showTitle = true,
5623 showMedia = true,
5624 showDescription = true,
5625 infiniteScrollEnabled
5626 } = view;
5627 const handleMouseEnter = () => {
5628 setIsHovered(true);
5629 };
5630 const handleMouseLeave = () => {
5631 setIsHovered(false);
5632 };
5633 const columns = view.fields ?? [];
5634 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
5635 return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5636 import_components16.Composite.Item,
5637 {
5638 render: ({ children, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5639 "tr",
5640 {
5641 className: clsx_default("dataviews-view-table__row", {
5642 "is-selected": isSelected2,
5643 "is-hovered": isHovered
5644 }),
5645 onMouseEnter: handleMouseEnter,
5646 onMouseLeave: handleMouseLeave,
5647 children,
5648 ...props
5649 }
5650 ),
5651 "aria-selected": isSelected2,
5652 "aria-setsize": paginationInfo.totalItems || void 0,
5653 "aria-posinset": posinset,
5654 role: infiniteScrollEnabled ? "article" : "option",
5655 onClick: () => {
5656 if (isSelected2) {
5657 onChangeSelection(
5658 selection.filter((itemId) => id !== itemId)
5659 );
5660 } else {
5661 const newSelection = multiselect ? [...selection, id] : [id];
5662 onChangeSelection(newSelection);
5663 }
5664 },
5665 children: [
5666 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5667 "td",
5668 {
5669 className: "dataviews-view-table__checkbox-column",
5670 role: "presentation",
5671 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("div", { className: "dataviews-view-table__cell-content-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5672 DataViewsSelectionCheckbox,
5673 {
5674 item,
5675 selection,
5676 onChangeSelection,
5677 getItemId,
5678 titleField,
5679 disabled: false,
5680 "aria-hidden": true,
5681 tabIndex: -1
5682 }
5683 ) })
5684 }
5685 ),
5686 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("td", { role: "presentation", children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5687 column_primary_default,
5688 {
5689 item,
5690 titleField: showTitle ? titleField : void 0,
5691 mediaField: showMedia ? mediaField : void 0,
5692 descriptionField: showDescription ? descriptionField2 : void 0,
5693 isItemClickable: () => false
5694 }
5695 ) }),
5696 columns.map((column) => {
5697 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
5698 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5699 "td",
5700 {
5701 style: {
5702 width,
5703 maxWidth,
5704 minWidth
5705 },
5706 role: "presentation",
5707 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5708 TableColumnField2,
5709 {
5710 fields,
5711 item,
5712 column,
5713 align
5714 }
5715 )
5716 },
5717 column
5718 );
5719 })
5720 ]
5721 },
5722 id
5723 );
5724 }
5725 function ViewPickerTable({
5726 actions,
5727 data,
5728 fields,
5729 getItemId,
5730 isLoading = false,
5731 onChangeView,
5732 onChangeSelection,
5733 selection,
5734 setOpenedFilter,
5735 view,
5736 className,
5737 empty
5738 }) {
5739 const headerMenuRefs = (0, import_element20.useRef)(/* @__PURE__ */ new Map());
5740 const headerMenuToFocusRef = (0, import_element20.useRef)();
5741 const [nextHeaderMenuToFocus, setNextHeaderMenuToFocus] = (0, import_element20.useState)();
5742 const isMultiselect = useIsMultiselectPicker(actions) ?? false;
5743 (0, import_element20.useEffect)(() => {
5744 if (headerMenuToFocusRef.current) {
5745 headerMenuToFocusRef.current.focus();
5746 headerMenuToFocusRef.current = void 0;
5747 }
5748 });
5749 const tableNoticeId = (0, import_element20.useId)();
5750 if (nextHeaderMenuToFocus) {
5751 headerMenuToFocusRef.current = nextHeaderMenuToFocus;
5752 setNextHeaderMenuToFocus(void 0);
5753 return;
5754 }
5755 const onHide = (field) => {
5756 const hidden = headerMenuRefs.current.get(field.id);
5757 const fallback = hidden ? headerMenuRefs.current.get(hidden.fallback) : void 0;
5758 setNextHeaderMenuToFocus(fallback?.node);
5759 };
5760 const hasData = !!data?.length;
5761 const titleField = fields.find((field) => field.id === view.titleField);
5762 const mediaField = fields.find((field) => field.id === view.mediaField);
5763 const descriptionField2 = fields.find(
5764 (field) => field.id === view.descriptionField
5765 );
5766 const groupField = view.groupBy?.field ? fields.find((f2) => f2.id === view.groupBy?.field) : null;
5767 const dataByGroup = groupField ? getDataByGroup(data, groupField) : null;
5768 const { showTitle = true, showMedia = true, showDescription = true } = view;
5769 const hasPrimaryColumn = titleField && showTitle || mediaField && showMedia || descriptionField2 && showDescription;
5770 const columns = view.fields ?? [];
5771 const headerMenuRef = (column, index) => (node) => {
5772 if (node) {
5773 headerMenuRefs.current.set(column, {
5774 node,
5775 fallback: columns[index > 0 ? index - 1 : 1]
5776 });
5777 } else {
5778 headerMenuRefs.current.delete(column);
5779 }
5780 };
5781 const isInfiniteScroll = view.infiniteScrollEnabled && !dataByGroup;
5782 return /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(import_jsx_runtime49.Fragment, { children: [
5783 /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5784 "table",
5785 {
5786 className: clsx_default(
5787 "dataviews-view-table",
5788 "dataviews-view-picker-table",
5789 className,
5790 {
5791 [`has-${view.layout?.density}-density`]: view.layout?.density && ["compact", "comfortable"].includes(
5792 view.layout.density
5793 )
5794 }
5795 ),
5796 "aria-busy": isLoading,
5797 "aria-describedby": tableNoticeId,
5798 role: isInfiniteScroll ? "feed" : "listbox",
5799 children: [
5800 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("thead", { role: "presentation", children: /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5801 "tr",
5802 {
5803 className: "dataviews-view-table__row",
5804 role: "presentation",
5805 children: [
5806 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("th", { className: "dataviews-view-table__checkbox-column", children: isMultiselect && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5807 BulkSelectionCheckbox,
5808 {
5809 selection,
5810 onChangeSelection,
5811 data,
5812 actions,
5813 getItemId
5814 }
5815 ) }),
5816 hasPrimaryColumn && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("th", { children: titleField && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5817 column_header_menu_default,
5818 {
5819 ref: headerMenuRef(
5820 titleField.id,
5821 0
5822 ),
5823 fieldId: titleField.id,
5824 view,
5825 fields,
5826 onChangeView,
5827 onHide,
5828 setOpenedFilter,
5829 canMove: false
5830 }
5831 ) }),
5832 columns.map((column, index) => {
5833 const { width, maxWidth, minWidth, align } = view.layout?.styles?.[column] ?? {};
5834 return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5835 "th",
5836 {
5837 style: {
5838 width,
5839 maxWidth,
5840 minWidth,
5841 textAlign: align
5842 },
5843 "aria-sort": view.sort?.direction && view.sort?.field === column ? sortValues[view.sort.direction] : void 0,
5844 scope: "col",
5845 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5846 column_header_menu_default,
5847 {
5848 ref: headerMenuRef(column, index),
5849 fieldId: column,
5850 view,
5851 fields,
5852 onChangeView,
5853 onHide,
5854 setOpenedFilter,
5855 canMove: view.layout?.enableMoving ?? true
5856 }
5857 )
5858 },
5859 column
5860 );
5861 })
5862 ]
5863 }
5864 ) }),
5865 hasData && groupField && dataByGroup ? Array.from(dataByGroup.entries()).map(
5866 ([groupName, groupItems]) => /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5867 import_components16.Composite,
5868 {
5869 virtualFocus: true,
5870 orientation: "vertical",
5871 render: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("tbody", { role: "group" }),
5872 children: [
5873 /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5874 "tr",
5875 {
5876 className: "dataviews-view-table__group-header-row",
5877 role: "presentation",
5878 children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5879 "td",
5880 {
5881 colSpan: columns.length + (hasPrimaryColumn ? 1 : 0) + 1,
5882 className: "dataviews-view-table__group-header-cell",
5883 role: "presentation",
5884 children: view.groupBy?.showLabel === false ? groupName : (0, import_i18n23.sprintf)(
5885 // translators: 1: The label of the field e.g. "Date". 2: The value of the field, e.g.: "May 2022".
5886 (0, import_i18n23.__)("%1$s: %2$s"),
5887 groupField.label,
5888 groupName
5889 )
5890 }
5891 )
5892 }
5893 ),
5894 groupItems.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5895 TableRow2,
5896 {
5897 item,
5898 fields,
5899 id: getItemId(item) || index.toString(),
5900 view,
5901 titleField,
5902 mediaField,
5903 descriptionField: descriptionField2,
5904 selection,
5905 getItemId,
5906 onChangeSelection,
5907 multiselect: isMultiselect
5908 },
5909 getItemId(item)
5910 ))
5911 ]
5912 },
5913 `group-${groupName}`
5914 )
5915 ) : /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5916 import_components16.Composite,
5917 {
5918 render: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("tbody", { role: "presentation" }),
5919 virtualFocus: true,
5920 orientation: "vertical",
5921 children: hasData && data.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
5922 TableRow2,
5923 {
5924 item,
5925 fields,
5926 id: getItemId(item) || index.toString(),
5927 view,
5928 titleField,
5929 mediaField,
5930 descriptionField: descriptionField2,
5931 selection,
5932 getItemId,
5933 onChangeSelection,
5934 multiselect: isMultiselect,
5935 posinset: index + 1
5936 },
5937 getItemId(item)
5938 ))
5939 }
5940 )
5941 ]
5942 }
5943 ),
5944 /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(
5945 "div",
5946 {
5947 className: clsx_default({
5948 "dataviews-loading": isLoading,
5949 "dataviews-no-results": !hasData && !isLoading
5950 }),
5951 id: tableNoticeId,
5952 children: [
5953 !hasData && (isLoading ? /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_components16.Spinner, {}) }) : empty),
5954 hasData && isLoading && /* @__PURE__ */ (0, import_jsx_runtime49.jsx)("p", { className: "dataviews-loading-more", children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_components16.Spinner, {}) })
5955 ]
5956 }
5957 )
5958 ] });
5959 }
5960 var picker_table_default = ViewPickerTable;
5961
5962 // packages/dataviews/build-module/components/dataviews-layouts/utils/preview-size-picker.mjs
5963 var import_components17 = __toESM(require_components(), 1);
5964 var import_i18n24 = __toESM(require_i18n(), 1);
5965 var import_element21 = __toESM(require_element(), 1);
5966 var import_jsx_runtime50 = __toESM(require_jsx_runtime(), 1);
5967 var imageSizes2 = [
5968 {
5969 value: 120,
5970 breakpoint: 1
5971 },
5972 {
5973 value: 170,
5974 breakpoint: 1
5975 },
5976 {
5977 value: 230,
5978 breakpoint: 1
5979 },
5980 {
5981 value: 290,
5982 breakpoint: 1112
5983 // at minimum image width, 4 images display at this container size
5984 },
5985 {
5986 value: 350,
5987 breakpoint: 1636
5988 // at minimum image width, 6 images display at this container size
5989 },
5990 {
5991 value: 430,
5992 breakpoint: 588
5993 // at minimum image width, 2 images display at this container size
5994 }
5995 ];
5996 function PreviewSizePicker() {
5997 const context = (0, import_element21.useContext)(dataviews_context_default);
5998 const view = context.view;
5999 const breakValues = imageSizes2.filter((size) => {
6000 return context.containerWidth >= size.breakpoint;
6001 });
6002 const layoutPreviewSize = view.layout?.previewSize ?? 230;
6003 const previewSizeToUse = breakValues.map((size, index) => ({ ...size, index })).filter((size) => size.value <= layoutPreviewSize).sort((a2, b2) => b2.value - a2.value)[0]?.index ?? 0;
6004 const marks = breakValues.map((size, index) => {
6005 return {
6006 value: index
6007 };
6008 });
6009 return /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
6010 import_components17.RangeControl,
6011 {
6012 __next40pxDefaultSize: true,
6013 showTooltip: false,
6014 label: (0, import_i18n24.__)("Preview size"),
6015 value: previewSizeToUse,
6016 min: 0,
6017 max: breakValues.length - 1,
6018 withInputField: false,
6019 onChange: (value = 0) => {
6020 context.onChangeView({
6021 ...view,
6022 layout: {
6023 ...view.layout,
6024 previewSize: breakValues[value].value
6025 }
6026 });
6027 },
6028 step: 1,
6029 marks
6030 }
6031 );
6032 }
6033
6034 // packages/dataviews/build-module/components/dataviews-layouts/utils/density-picker.mjs
6035 var import_components18 = __toESM(require_components(), 1);
6036 var import_i18n25 = __toESM(require_i18n(), 1);
6037 var import_element22 = __toESM(require_element(), 1);
6038 var import_jsx_runtime51 = __toESM(require_jsx_runtime(), 1);
6039 function DensityPicker() {
6040 const context = (0, import_element22.useContext)(dataviews_context_default);
6041 const view = context.view;
6042 return /* @__PURE__ */ (0, import_jsx_runtime51.jsxs)(
6043 import_components18.__experimentalToggleGroupControl,
6044 {
6045 size: "__unstable-large",
6046 label: (0, import_i18n25.__)("Density"),
6047 value: view.layout?.density || "balanced",
6048 onChange: (value) => {
6049 context.onChangeView({
6050 ...view,
6051 layout: {
6052 ...view.layout,
6053 density: value
6054 }
6055 });
6056 },
6057 isBlock: true,
6058 children: [
6059 /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
6060 import_components18.__experimentalToggleGroupControlOption,
6061 {
6062 value: "comfortable",
6063 label: (0, import_i18n25._x)(
6064 "Comfortable",
6065 "Density option for DataView layout"
6066 )
6067 },
6068 "comfortable"
6069 ),
6070 /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
6071 import_components18.__experimentalToggleGroupControlOption,
6072 {
6073 value: "balanced",
6074 label: (0, import_i18n25._x)("Balanced", "Density option for DataView layout")
6075 },
6076 "balanced"
6077 ),
6078 /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
6079 import_components18.__experimentalToggleGroupControlOption,
6080 {
6081 value: "compact",
6082 label: (0, import_i18n25._x)("Compact", "Density option for DataView layout")
6083 },
6084 "compact"
6085 )
6086 ]
6087 }
6088 );
6089 }
6090
6091 // packages/dataviews/build-module/components/dataviews-layouts/index.mjs
6092 var VIEW_LAYOUTS = [
6093 {
6094 type: LAYOUT_TABLE,
6095 label: (0, import_i18n26.__)("Table"),
6096 component: table_default,
6097 icon: block_table_default,
6098 viewConfigOptions: DensityPicker
6099 },
6100 {
6101 type: LAYOUT_GRID,
6102 label: (0, import_i18n26.__)("Grid"),
6103 component: grid_default,
6104 icon: category_default,
6105 viewConfigOptions: PreviewSizePicker
6106 },
6107 {
6108 type: LAYOUT_LIST,
6109 label: (0, import_i18n26.__)("List"),
6110 component: ViewList,
6111 icon: (0, import_i18n26.isRTL)() ? format_list_bullets_rtl_default : format_list_bullets_default,
6112 viewConfigOptions: DensityPicker
6113 },
6114 {
6115 type: LAYOUT_ACTIVITY,
6116 label: (0, import_i18n26.__)("Activity"),
6117 component: ViewActivity,
6118 icon: scheduled_default,
6119 viewConfigOptions: DensityPicker
6120 },
6121 {
6122 type: LAYOUT_PICKER_GRID,
6123 label: (0, import_i18n26.__)("Grid"),
6124 component: picker_grid_default,
6125 icon: category_default,
6126 viewConfigOptions: PreviewSizePicker,
6127 isPicker: true
6128 },
6129 {
6130 type: LAYOUT_PICKER_TABLE,
6131 label: (0, import_i18n26.__)("Table"),
6132 component: picker_table_default,
6133 icon: block_table_default,
6134 viewConfigOptions: DensityPicker,
6135 isPicker: true
6136 }
6137 ];
6138
6139 // packages/dataviews/build-module/components/dataviews-filters/filters.mjs
6140 var import_element30 = __toESM(require_element(), 1);
6141
6142 // packages/dataviews/build-module/components/dataviews-filters/filter.mjs
6143 var import_components21 = __toESM(require_components(), 1);
6144 var import_i18n29 = __toESM(require_i18n(), 1);
6145 var import_element27 = __toESM(require_element(), 1);
6146
6147 // node_modules/@ariakit/react-core/esm/__chunks/3YLGPPWQ.js
6148 var __defProp2 = Object.defineProperty;
6149 var __defProps = Object.defineProperties;
6150 var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6151 var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6152 var __hasOwnProp2 = Object.prototype.hasOwnProperty;
6153 var __propIsEnum = Object.prototype.propertyIsEnumerable;
6154 var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6155 var __spreadValues = (a2, b2) => {
6156 for (var prop in b2 || (b2 = {}))
6157 if (__hasOwnProp2.call(b2, prop))
6158 __defNormalProp(a2, prop, b2[prop]);
6159 if (__getOwnPropSymbols)
6160 for (var prop of __getOwnPropSymbols(b2)) {
6161 if (__propIsEnum.call(b2, prop))
6162 __defNormalProp(a2, prop, b2[prop]);
6163 }
6164 return a2;
6165 };
6166 var __spreadProps = (a2, b2) => __defProps(a2, __getOwnPropDescs(b2));
6167 var __objRest = (source, exclude) => {
6168 var target = {};
6169 for (var prop in source)
6170 if (__hasOwnProp2.call(source, prop) && exclude.indexOf(prop) < 0)
6171 target[prop] = source[prop];
6172 if (source != null && __getOwnPropSymbols)
6173 for (var prop of __getOwnPropSymbols(source)) {
6174 if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
6175 target[prop] = source[prop];
6176 }
6177 return target;
6178 };
6179
6180 // node_modules/@ariakit/core/esm/__chunks/3YLGPPWQ.js
6181 var __defProp3 = Object.defineProperty;
6182 var __defProps2 = Object.defineProperties;
6183 var __getOwnPropDescs2 = Object.getOwnPropertyDescriptors;
6184 var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
6185 var __hasOwnProp3 = Object.prototype.hasOwnProperty;
6186 var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
6187 var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6188 var __spreadValues2 = (a2, b2) => {
6189 for (var prop in b2 || (b2 = {}))
6190 if (__hasOwnProp3.call(b2, prop))
6191 __defNormalProp2(a2, prop, b2[prop]);
6192 if (__getOwnPropSymbols2)
6193 for (var prop of __getOwnPropSymbols2(b2)) {
6194 if (__propIsEnum2.call(b2, prop))
6195 __defNormalProp2(a2, prop, b2[prop]);
6196 }
6197 return a2;
6198 };
6199 var __spreadProps2 = (a2, b2) => __defProps2(a2, __getOwnPropDescs2(b2));
6200 var __objRest2 = (source, exclude) => {
6201 var target = {};
6202 for (var prop in source)
6203 if (__hasOwnProp3.call(source, prop) && exclude.indexOf(prop) < 0)
6204 target[prop] = source[prop];
6205 if (source != null && __getOwnPropSymbols2)
6206 for (var prop of __getOwnPropSymbols2(source)) {
6207 if (exclude.indexOf(prop) < 0 && __propIsEnum2.call(source, prop))
6208 target[prop] = source[prop];
6209 }
6210 return target;
6211 };
6212
6213 // node_modules/@ariakit/core/esm/__chunks/PBFD2E7P.js
6214 function noop2(..._) {
6215 }
6216 function applyState(argument, currentValue) {
6217 if (isUpdater(argument)) {
6218 const value = isLazyValue(currentValue) ? currentValue() : currentValue;
6219 return argument(value);
6220 }
6221 return argument;
6222 }
6223 function isUpdater(argument) {
6224 return typeof argument === "function";
6225 }
6226 function isLazyValue(value) {
6227 return typeof value === "function";
6228 }
6229 function hasOwnProperty(object, prop) {
6230 if (typeof Object.hasOwn === "function") {
6231 return Object.hasOwn(object, prop);
6232 }
6233 return Object.prototype.hasOwnProperty.call(object, prop);
6234 }
6235 function chain(...fns) {
6236 return (...args) => {
6237 for (const fn of fns) {
6238 if (typeof fn === "function") {
6239 fn(...args);
6240 }
6241 }
6242 };
6243 }
6244 function normalizeString(str) {
6245 return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
6246 }
6247 function omit(object, keys) {
6248 const result = __spreadValues2({}, object);
6249 for (const key of keys) {
6250 if (hasOwnProperty(result, key)) {
6251 delete result[key];
6252 }
6253 }
6254 return result;
6255 }
6256 function pick(object, paths) {
6257 const result = {};
6258 for (const key of paths) {
6259 if (hasOwnProperty(object, key)) {
6260 result[key] = object[key];
6261 }
6262 }
6263 return result;
6264 }
6265 function identity(value) {
6266 return value;
6267 }
6268 function invariant(condition, message2) {
6269 if (condition) return;
6270 if (typeof message2 !== "string") throw new Error("Invariant failed");
6271 throw new Error(message2);
6272 }
6273 function getKeys(obj) {
6274 return Object.keys(obj);
6275 }
6276 function isFalsyBooleanCallback(booleanOrCallback, ...args) {
6277 const result = typeof booleanOrCallback === "function" ? booleanOrCallback(...args) : booleanOrCallback;
6278 if (result == null) return false;
6279 return !result;
6280 }
6281 function disabledFromProps(props) {
6282 return props.disabled || props["aria-disabled"] === true || props["aria-disabled"] === "true";
6283 }
6284 function removeUndefinedValues(obj) {
6285 const result = {};
6286 for (const key in obj) {
6287 if (obj[key] !== void 0) {
6288 result[key] = obj[key];
6289 }
6290 }
6291 return result;
6292 }
6293 function defaultValue(...values) {
6294 for (const value of values) {
6295 if (value !== void 0) return value;
6296 }
6297 return void 0;
6298 }
6299
6300 // node_modules/@ariakit/react-core/esm/__chunks/SK3NAZA3.js
6301 var import_react4 = __toESM(require_react(), 1);
6302 function setRef(ref, value) {
6303 if (typeof ref === "function") {
6304 ref(value);
6305 } else if (ref) {
6306 ref.current = value;
6307 }
6308 }
6309 function isValidElementWithRef(element) {
6310 if (!element) return false;
6311 if (!(0, import_react4.isValidElement)(element)) return false;
6312 if ("ref" in element.props) return true;
6313 if ("ref" in element) return true;
6314 return false;
6315 }
6316 function getRefProperty(element) {
6317 if (!isValidElementWithRef(element)) return null;
6318 const props = __spreadValues({}, element.props);
6319 return props.ref || element.ref;
6320 }
6321 function mergeProps2(base, overrides) {
6322 const props = __spreadValues({}, base);
6323 for (const key in overrides) {
6324 if (!hasOwnProperty(overrides, key)) continue;
6325 if (key === "className") {
6326 const prop = "className";
6327 props[prop] = base[prop] ? `${base[prop]} ${overrides[prop]}` : overrides[prop];
6328 continue;
6329 }
6330 if (key === "style") {
6331 const prop = "style";
6332 props[prop] = base[prop] ? __spreadValues(__spreadValues({}, base[prop]), overrides[prop]) : overrides[prop];
6333 continue;
6334 }
6335 const overrideValue = overrides[key];
6336 if (typeof overrideValue === "function" && key.startsWith("on")) {
6337 const baseValue = base[key];
6338 if (typeof baseValue === "function") {
6339 props[key] = (...args) => {
6340 overrideValue(...args);
6341 baseValue(...args);
6342 };
6343 continue;
6344 }
6345 }
6346 props[key] = overrideValue;
6347 }
6348 return props;
6349 }
6350
6351 // node_modules/@ariakit/core/esm/__chunks/DTR5TSDJ.js
6352 var canUseDOM = checkIsBrowser();
6353 function checkIsBrowser() {
6354 var _a;
6355 return typeof window !== "undefined" && !!((_a = window.document) == null ? void 0 : _a.createElement);
6356 }
6357 function getDocument(node) {
6358 if (!node) return document;
6359 if ("self" in node) return node.document;
6360 return node.ownerDocument || document;
6361 }
6362 function getActiveElement(node, activeDescendant = false) {
6363 const { activeElement } = getDocument(node);
6364 if (!(activeElement == null ? void 0 : activeElement.nodeName)) {
6365 return null;
6366 }
6367 if (isFrame(activeElement) && activeElement.contentDocument) {
6368 return getActiveElement(
6369 activeElement.contentDocument.body,
6370 activeDescendant
6371 );
6372 }
6373 if (activeDescendant) {
6374 const id = activeElement.getAttribute("aria-activedescendant");
6375 if (id) {
6376 const element = getDocument(activeElement).getElementById(id);
6377 if (element) {
6378 return element;
6379 }
6380 }
6381 }
6382 return activeElement;
6383 }
6384 function contains(parent, child) {
6385 return parent === child || parent.contains(child);
6386 }
6387 function isFrame(element) {
6388 return element.tagName === "IFRAME";
6389 }
6390 function isButton(element) {
6391 const tagName = element.tagName.toLowerCase();
6392 if (tagName === "button") return true;
6393 if (tagName === "input" && element.type) {
6394 return buttonInputTypes.indexOf(element.type) !== -1;
6395 }
6396 return false;
6397 }
6398 var buttonInputTypes = [
6399 "button",
6400 "color",
6401 "file",
6402 "image",
6403 "reset",
6404 "submit"
6405 ];
6406 function isVisible(element) {
6407 if (typeof element.checkVisibility === "function") {
6408 return element.checkVisibility();
6409 }
6410 const htmlElement = element;
6411 return htmlElement.offsetWidth > 0 || htmlElement.offsetHeight > 0 || element.getClientRects().length > 0;
6412 }
6413 function isTextField(element) {
6414 try {
6415 const isTextInput = element instanceof HTMLInputElement && element.selectionStart !== null;
6416 const isTextArea = element.tagName === "TEXTAREA";
6417 return isTextInput || isTextArea || false;
6418 } catch (error) {
6419 return false;
6420 }
6421 }
6422 function isTextbox(element) {
6423 return element.isContentEditable || isTextField(element);
6424 }
6425 function getTextboxValue(element) {
6426 if (isTextField(element)) {
6427 return element.value;
6428 }
6429 if (element.isContentEditable) {
6430 const range = getDocument(element).createRange();
6431 range.selectNodeContents(element);
6432 return range.toString();
6433 }
6434 return "";
6435 }
6436 function getTextboxSelection(element) {
6437 let start = 0;
6438 let end = 0;
6439 if (isTextField(element)) {
6440 start = element.selectionStart || 0;
6441 end = element.selectionEnd || 0;
6442 } else if (element.isContentEditable) {
6443 const selection = getDocument(element).getSelection();
6444 if ((selection == null ? void 0 : selection.rangeCount) && selection.anchorNode && contains(element, selection.anchorNode) && selection.focusNode && contains(element, selection.focusNode)) {
6445 const range = selection.getRangeAt(0);
6446 const nextRange = range.cloneRange();
6447 nextRange.selectNodeContents(element);
6448 nextRange.setEnd(range.startContainer, range.startOffset);
6449 start = nextRange.toString().length;
6450 nextRange.setEnd(range.endContainer, range.endOffset);
6451 end = nextRange.toString().length;
6452 }
6453 }
6454 return { start, end };
6455 }
6456 function getPopupRole(element, fallback) {
6457 const allowedPopupRoles = ["dialog", "menu", "listbox", "tree", "grid"];
6458 const role = element == null ? void 0 : element.getAttribute("role");
6459 if (role && allowedPopupRoles.indexOf(role) !== -1) {
6460 return role;
6461 }
6462 return fallback;
6463 }
6464 function getScrollingElement(element) {
6465 if (!element) return null;
6466 const isScrollableOverflow = (overflow) => {
6467 if (overflow === "auto") return true;
6468 if (overflow === "scroll") return true;
6469 return false;
6470 };
6471 if (element.clientHeight && element.scrollHeight > element.clientHeight) {
6472 const { overflowY } = getComputedStyle(element);
6473 if (isScrollableOverflow(overflowY)) return element;
6474 } else if (element.clientWidth && element.scrollWidth > element.clientWidth) {
6475 const { overflowX } = getComputedStyle(element);
6476 if (isScrollableOverflow(overflowX)) return element;
6477 }
6478 return getScrollingElement(element.parentElement) || document.scrollingElement || document.body;
6479 }
6480 function setSelectionRange(element, ...args) {
6481 if (/text|search|password|tel|url/i.test(element.type)) {
6482 element.setSelectionRange(...args);
6483 }
6484 }
6485 function sortBasedOnDOMPosition(items, getElement) {
6486 const pairs = items.map((item, index) => [index, item]);
6487 let isOrderDifferent = false;
6488 pairs.sort(([indexA, a2], [indexB, b2]) => {
6489 const elementA = getElement(a2);
6490 const elementB = getElement(b2);
6491 if (elementA === elementB) return 0;
6492 if (!elementA || !elementB) return 0;
6493 if (isElementPreceding(elementA, elementB)) {
6494 if (indexA > indexB) {
6495 isOrderDifferent = true;
6496 }
6497 return -1;
6498 }
6499 if (indexA < indexB) {
6500 isOrderDifferent = true;
6501 }
6502 return 1;
6503 });
6504 if (isOrderDifferent) {
6505 return pairs.map(([_, item]) => item);
6506 }
6507 return items;
6508 }
6509 function isElementPreceding(a2, b2) {
6510 return Boolean(
6511 b2.compareDocumentPosition(a2) & Node.DOCUMENT_POSITION_PRECEDING
6512 );
6513 }
6514
6515 // node_modules/@ariakit/core/esm/__chunks/QAGXQEUG.js
6516 function isTouchDevice() {
6517 return canUseDOM && !!navigator.maxTouchPoints;
6518 }
6519 function isApple() {
6520 if (!canUseDOM) return false;
6521 return /mac|iphone|ipad|ipod/i.test(navigator.platform);
6522 }
6523 function isSafari() {
6524 return canUseDOM && isApple() && /apple/i.test(navigator.vendor);
6525 }
6526 function isFirefox() {
6527 return canUseDOM && /firefox\//i.test(navigator.userAgent);
6528 }
6529
6530 // node_modules/@ariakit/core/esm/utils/events.js
6531 function isPortalEvent(event) {
6532 return Boolean(
6533 event.currentTarget && !contains(event.currentTarget, event.target)
6534 );
6535 }
6536 function isSelfTarget(event) {
6537 return event.target === event.currentTarget;
6538 }
6539 function isOpeningInNewTab(event) {
6540 const element = event.currentTarget;
6541 if (!element) return false;
6542 const isAppleDevice = isApple();
6543 if (isAppleDevice && !event.metaKey) return false;
6544 if (!isAppleDevice && !event.ctrlKey) return false;
6545 const tagName = element.tagName.toLowerCase();
6546 if (tagName === "a") return true;
6547 if (tagName === "button" && element.type === "submit") return true;
6548 if (tagName === "input" && element.type === "submit") return true;
6549 return false;
6550 }
6551 function isDownloading(event) {
6552 const element = event.currentTarget;
6553 if (!element) return false;
6554 const tagName = element.tagName.toLowerCase();
6555 if (!event.altKey) return false;
6556 if (tagName === "a") return true;
6557 if (tagName === "button" && element.type === "submit") return true;
6558 if (tagName === "input" && element.type === "submit") return true;
6559 return false;
6560 }
6561 function fireBlurEvent(element, eventInit) {
6562 const event = new FocusEvent("blur", eventInit);
6563 const defaultAllowed = element.dispatchEvent(event);
6564 const bubbleInit = __spreadProps2(__spreadValues2({}, eventInit), { bubbles: true });
6565 element.dispatchEvent(new FocusEvent("focusout", bubbleInit));
6566 return defaultAllowed;
6567 }
6568 function fireKeyboardEvent(element, type, eventInit) {
6569 const event = new KeyboardEvent(type, eventInit);
6570 return element.dispatchEvent(event);
6571 }
6572 function fireClickEvent(element, eventInit) {
6573 const event = new MouseEvent("click", eventInit);
6574 return element.dispatchEvent(event);
6575 }
6576 function isFocusEventOutside(event, container) {
6577 const containerElement = container || event.currentTarget;
6578 const relatedTarget = event.relatedTarget;
6579 return !relatedTarget || !contains(containerElement, relatedTarget);
6580 }
6581 function queueBeforeEvent(element, type, callback, timeout) {
6582 const createTimer = (callback2) => {
6583 if (timeout) {
6584 const timerId2 = setTimeout(callback2, timeout);
6585 return () => clearTimeout(timerId2);
6586 }
6587 const timerId = requestAnimationFrame(callback2);
6588 return () => cancelAnimationFrame(timerId);
6589 };
6590 const cancelTimer = createTimer(() => {
6591 element.removeEventListener(type, callSync, true);
6592 callback();
6593 });
6594 const callSync = () => {
6595 cancelTimer();
6596 callback();
6597 };
6598 element.addEventListener(type, callSync, { once: true, capture: true });
6599 return cancelTimer;
6600 }
6601 function addGlobalEventListener(type, listener, options, scope = window) {
6602 const children = [];
6603 try {
6604 scope.document.addEventListener(type, listener, options);
6605 for (const frame of Array.from(scope.frames)) {
6606 children.push(addGlobalEventListener(type, listener, options, frame));
6607 }
6608 } catch (e2) {
6609 }
6610 const removeEventListener = () => {
6611 try {
6612 scope.document.removeEventListener(type, listener, options);
6613 } catch (e2) {
6614 }
6615 for (const remove of children) {
6616 remove();
6617 }
6618 };
6619 return removeEventListener;
6620 }
6621
6622 // node_modules/@ariakit/react-core/esm/__chunks/ABQUS43J.js
6623 var import_react5 = __toESM(require_react(), 1);
6624 var React5 = __toESM(require_react(), 1);
6625 var _React = __spreadValues({}, React5);
6626 var useReactId = _React.useId;
6627 var useReactDeferredValue = _React.useDeferredValue;
6628 var useReactInsertionEffect = _React.useInsertionEffect;
6629 var useSafeLayoutEffect = canUseDOM ? import_react5.useLayoutEffect : import_react5.useEffect;
6630 function useInitialValue(value) {
6631 const [initialValue] = (0, import_react5.useState)(value);
6632 return initialValue;
6633 }
6634 function useLiveRef(value) {
6635 const ref = (0, import_react5.useRef)(value);
6636 useSafeLayoutEffect(() => {
6637 ref.current = value;
6638 });
6639 return ref;
6640 }
6641 function useEvent(callback) {
6642 const ref = (0, import_react5.useRef)(() => {
6643 throw new Error("Cannot call an event handler while rendering.");
6644 });
6645 if (useReactInsertionEffect) {
6646 useReactInsertionEffect(() => {
6647 ref.current = callback;
6648 });
6649 } else {
6650 ref.current = callback;
6651 }
6652 return (0, import_react5.useCallback)((...args) => {
6653 var _a;
6654 return (_a = ref.current) == null ? void 0 : _a.call(ref, ...args);
6655 }, []);
6656 }
6657 function useTransactionState(callback) {
6658 const [state, setState] = (0, import_react5.useState)(null);
6659 useSafeLayoutEffect(() => {
6660 if (state == null) return;
6661 if (!callback) return;
6662 let prevState = null;
6663 callback((prev) => {
6664 prevState = prev;
6665 return state;
6666 });
6667 return () => {
6668 callback(prevState);
6669 };
6670 }, [state, callback]);
6671 return [state, setState];
6672 }
6673 function useMergeRefs(...refs) {
6674 return (0, import_react5.useMemo)(() => {
6675 if (!refs.some(Boolean)) return;
6676 return (value) => {
6677 for (const ref of refs) {
6678 setRef(ref, value);
6679 }
6680 };
6681 }, refs);
6682 }
6683 function useId3(defaultId) {
6684 if (useReactId) {
6685 const reactId = useReactId();
6686 if (defaultId) return defaultId;
6687 return reactId;
6688 }
6689 const [id, setId] = (0, import_react5.useState)(defaultId);
6690 useSafeLayoutEffect(() => {
6691 if (defaultId || id) return;
6692 const random = Math.random().toString(36).slice(2, 8);
6693 setId(`id-${random}`);
6694 }, [defaultId, id]);
6695 return defaultId || id;
6696 }
6697 function useTagName(refOrElement, type) {
6698 const stringOrUndefined = (type2) => {
6699 if (typeof type2 !== "string") return;
6700 return type2;
6701 };
6702 const [tagName, setTagName] = (0, import_react5.useState)(() => stringOrUndefined(type));
6703 useSafeLayoutEffect(() => {
6704 const element = refOrElement && "current" in refOrElement ? refOrElement.current : refOrElement;
6705 setTagName((element == null ? void 0 : element.tagName.toLowerCase()) || stringOrUndefined(type));
6706 }, [refOrElement, type]);
6707 return tagName;
6708 }
6709 function useAttribute(refOrElement, attributeName, defaultValue2) {
6710 const initialValue = useInitialValue(defaultValue2);
6711 const [attribute, setAttribute] = (0, import_react5.useState)(initialValue);
6712 (0, import_react5.useEffect)(() => {
6713 const element = refOrElement && "current" in refOrElement ? refOrElement.current : refOrElement;
6714 if (!element) return;
6715 const callback = () => {
6716 const value = element.getAttribute(attributeName);
6717 setAttribute(value == null ? initialValue : value);
6718 };
6719 const observer = new MutationObserver(callback);
6720 observer.observe(element, { attributeFilter: [attributeName] });
6721 callback();
6722 return () => observer.disconnect();
6723 }, [refOrElement, attributeName, initialValue]);
6724 return attribute;
6725 }
6726 function useUpdateEffect(effect, deps) {
6727 const mounted = (0, import_react5.useRef)(false);
6728 (0, import_react5.useEffect)(() => {
6729 if (mounted.current) {
6730 return effect();
6731 }
6732 mounted.current = true;
6733 }, deps);
6734 (0, import_react5.useEffect)(
6735 () => () => {
6736 mounted.current = false;
6737 },
6738 []
6739 );
6740 }
6741 function useUpdateLayoutEffect(effect, deps) {
6742 const mounted = (0, import_react5.useRef)(false);
6743 useSafeLayoutEffect(() => {
6744 if (mounted.current) {
6745 return effect();
6746 }
6747 mounted.current = true;
6748 }, deps);
6749 useSafeLayoutEffect(
6750 () => () => {
6751 mounted.current = false;
6752 },
6753 []
6754 );
6755 }
6756 function useForceUpdate() {
6757 return (0, import_react5.useReducer)(() => [], []);
6758 }
6759 function useBooleanEvent(booleanOrCallback) {
6760 return useEvent(
6761 typeof booleanOrCallback === "function" ? booleanOrCallback : () => booleanOrCallback
6762 );
6763 }
6764 function useWrapElement(props, callback, deps = []) {
6765 const wrapElement = (0, import_react5.useCallback)(
6766 (element) => {
6767 if (props.wrapElement) {
6768 element = props.wrapElement(element);
6769 }
6770 return callback(element);
6771 },
6772 [...deps, props.wrapElement]
6773 );
6774 return __spreadProps(__spreadValues({}, props), { wrapElement });
6775 }
6776 function useMetadataProps(props, key, value) {
6777 const parent = props.onLoadedMetadataCapture;
6778 const onLoadedMetadataCapture = (0, import_react5.useMemo)(() => {
6779 return Object.assign(() => {
6780 }, __spreadProps(__spreadValues({}, parent), { [key]: value }));
6781 }, [parent, key, value]);
6782 return [parent == null ? void 0 : parent[key], { onLoadedMetadataCapture }];
6783 }
6784 function useIsMouseMoving() {
6785 (0, import_react5.useEffect)(() => {
6786 addGlobalEventListener("mousemove", setMouseMoving, true);
6787 addGlobalEventListener("mousedown", resetMouseMoving, true);
6788 addGlobalEventListener("mouseup", resetMouseMoving, true);
6789 addGlobalEventListener("keydown", resetMouseMoving, true);
6790 addGlobalEventListener("scroll", resetMouseMoving, true);
6791 }, []);
6792 const isMouseMoving = useEvent(() => mouseMoving);
6793 return isMouseMoving;
6794 }
6795 var mouseMoving = false;
6796 var previousScreenX = 0;
6797 var previousScreenY = 0;
6798 function hasMouseMovement(event) {
6799 const movementX = event.movementX || event.screenX - previousScreenX;
6800 const movementY = event.movementY || event.screenY - previousScreenY;
6801 previousScreenX = event.screenX;
6802 previousScreenY = event.screenY;
6803 return movementX || movementY || false;
6804 }
6805 function setMouseMoving(event) {
6806 if (!hasMouseMovement(event)) return;
6807 mouseMoving = true;
6808 }
6809 function resetMouseMoving() {
6810 mouseMoving = false;
6811 }
6812
6813 // node_modules/@ariakit/react-core/esm/__chunks/LMDWO4NN.js
6814 var React6 = __toESM(require_react(), 1);
6815 var import_jsx_runtime52 = __toESM(require_jsx_runtime(), 1);
6816 function forwardRef22(render4) {
6817 const Role = React6.forwardRef((props, ref) => render4(__spreadProps(__spreadValues({}, props), { ref })));
6818 Role.displayName = render4.displayName || render4.name;
6819 return Role;
6820 }
6821 function memo22(Component2, propsAreEqual) {
6822 return React6.memo(Component2, propsAreEqual);
6823 }
6824 function createElement3(Type, props) {
6825 const _a = props, { wrapElement, render: render4 } = _a, rest = __objRest(_a, ["wrapElement", "render"]);
6826 const mergedRef = useMergeRefs(props.ref, getRefProperty(render4));
6827 let element;
6828 if (React6.isValidElement(render4)) {
6829 const renderProps = __spreadProps(__spreadValues({}, render4.props), { ref: mergedRef });
6830 element = React6.cloneElement(render4, mergeProps2(rest, renderProps));
6831 } else if (render4) {
6832 element = render4(rest);
6833 } else {
6834 element = /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(Type, __spreadValues({}, rest));
6835 }
6836 if (wrapElement) {
6837 return wrapElement(element);
6838 }
6839 return element;
6840 }
6841 function createHook(useProps) {
6842 const useRole = (props = {}) => {
6843 return useProps(props);
6844 };
6845 useRole.displayName = useProps.name;
6846 return useRole;
6847 }
6848 function createStoreContext(providers = [], scopedProviders = []) {
6849 const context = React6.createContext(void 0);
6850 const scopedContext = React6.createContext(void 0);
6851 const useContext27 = () => React6.useContext(context);
6852 const useScopedContext = (onlyScoped = false) => {
6853 const scoped = React6.useContext(scopedContext);
6854 const store = useContext27();
6855 if (onlyScoped) return scoped;
6856 return scoped || store;
6857 };
6858 const useProviderContext = () => {
6859 const scoped = React6.useContext(scopedContext);
6860 const store = useContext27();
6861 if (scoped && scoped === store) return;
6862 return store;
6863 };
6864 const ContextProvider = (props) => {
6865 return providers.reduceRight(
6866 (children, Provider) => /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(Provider, __spreadProps(__spreadValues({}, props), { children })),
6867 /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(context.Provider, __spreadValues({}, props))
6868 );
6869 };
6870 const ScopedContextProvider = (props) => {
6871 return /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(ContextProvider, __spreadProps(__spreadValues({}, props), { children: scopedProviders.reduceRight(
6872 (children, Provider) => /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(Provider, __spreadProps(__spreadValues({}, props), { children })),
6873 /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(scopedContext.Provider, __spreadValues({}, props))
6874 ) }));
6875 };
6876 return {
6877 context,
6878 scopedContext,
6879 useContext: useContext27,
6880 useScopedContext,
6881 useProviderContext,
6882 ContextProvider,
6883 ScopedContextProvider
6884 };
6885 }
6886
6887 // node_modules/@ariakit/react-core/esm/__chunks/VDHZ5F7K.js
6888 var ctx = createStoreContext();
6889 var useCollectionContext = ctx.useContext;
6890 var useCollectionScopedContext = ctx.useScopedContext;
6891 var useCollectionProviderContext = ctx.useProviderContext;
6892 var CollectionContextProvider = ctx.ContextProvider;
6893 var CollectionScopedContextProvider = ctx.ScopedContextProvider;
6894
6895 // node_modules/@ariakit/react-core/esm/__chunks/P7GR5CS5.js
6896 var import_react6 = __toESM(require_react(), 1);
6897 var ctx2 = createStoreContext(
6898 [CollectionContextProvider],
6899 [CollectionScopedContextProvider]
6900 );
6901 var useCompositeContext = ctx2.useContext;
6902 var useCompositeScopedContext = ctx2.useScopedContext;
6903 var useCompositeProviderContext = ctx2.useProviderContext;
6904 var CompositeContextProvider = ctx2.ContextProvider;
6905 var CompositeScopedContextProvider = ctx2.ScopedContextProvider;
6906 var CompositeItemContext = (0, import_react6.createContext)(
6907 void 0
6908 );
6909 var CompositeRowContext = (0, import_react6.createContext)(
6910 void 0
6911 );
6912
6913 // node_modules/@ariakit/react-core/esm/__chunks/3XAVFTCA.js
6914 var import_react7 = __toESM(require_react(), 1);
6915 var TagValueContext = (0, import_react7.createContext)(null);
6916 var TagRemoveIdContext = (0, import_react7.createContext)(
6917 null
6918 );
6919 var ctx3 = createStoreContext(
6920 [CompositeContextProvider],
6921 [CompositeScopedContextProvider]
6922 );
6923 var useTagContext = ctx3.useContext;
6924 var useTagScopedContext = ctx3.useScopedContext;
6925 var useTagProviderContext = ctx3.useProviderContext;
6926 var TagContextProvider = ctx3.ContextProvider;
6927 var TagScopedContextProvider = ctx3.ScopedContextProvider;
6928
6929 // node_modules/@ariakit/core/esm/__chunks/BCALMBPZ.js
6930 function getInternal(store, key) {
6931 const internals = store.__unstableInternals;
6932 invariant(internals, "Invalid store");
6933 return internals[key];
6934 }
6935 function createStore(initialState, ...stores) {
6936 let state = initialState;
6937 let prevStateBatch = state;
6938 let lastUpdate = /* @__PURE__ */ Symbol();
6939 let destroy = noop2;
6940 const instances = /* @__PURE__ */ new Set();
6941 const updatedKeys = /* @__PURE__ */ new Set();
6942 const setups = /* @__PURE__ */ new Set();
6943 const listeners = /* @__PURE__ */ new Set();
6944 const batchListeners = /* @__PURE__ */ new Set();
6945 const disposables = /* @__PURE__ */ new WeakMap();
6946 const listenerKeys = /* @__PURE__ */ new WeakMap();
6947 const storeSetup = (callback) => {
6948 setups.add(callback);
6949 return () => setups.delete(callback);
6950 };
6951 const storeInit = () => {
6952 const initialized = instances.size;
6953 const instance = /* @__PURE__ */ Symbol();
6954 instances.add(instance);
6955 const maybeDestroy = () => {
6956 instances.delete(instance);
6957 if (instances.size) return;
6958 destroy();
6959 };
6960 if (initialized) return maybeDestroy;
6961 const desyncs = getKeys(state).map(
6962 (key) => chain(
6963 ...stores.map((store) => {
6964 var _a;
6965 const storeState = (_a = store == null ? void 0 : store.getState) == null ? void 0 : _a.call(store);
6966 if (!storeState) return;
6967 if (!hasOwnProperty(storeState, key)) return;
6968 return sync(store, [key], (state2) => {
6969 setState(
6970 key,
6971 state2[key],
6972 // @ts-expect-error - Not public API. This is just to prevent
6973 // infinite loops.
6974 true
6975 );
6976 });
6977 })
6978 )
6979 );
6980 const teardowns = [];
6981 for (const setup2 of setups) {
6982 teardowns.push(setup2());
6983 }
6984 const cleanups = stores.map(init);
6985 destroy = chain(...desyncs, ...teardowns, ...cleanups);
6986 return maybeDestroy;
6987 };
6988 const sub = (keys, listener, set = listeners) => {
6989 set.add(listener);
6990 listenerKeys.set(listener, keys);
6991 return () => {
6992 var _a;
6993 (_a = disposables.get(listener)) == null ? void 0 : _a();
6994 disposables.delete(listener);
6995 listenerKeys.delete(listener);
6996 set.delete(listener);
6997 };
6998 };
6999 const storeSubscribe = (keys, listener) => sub(keys, listener);
7000 const storeSync = (keys, listener) => {
7001 disposables.set(listener, listener(state, state));
7002 return sub(keys, listener);
7003 };
7004 const storeBatch = (keys, listener) => {
7005 disposables.set(listener, listener(state, prevStateBatch));
7006 return sub(keys, listener, batchListeners);
7007 };
7008 const storePick = (keys) => createStore(pick(state, keys), finalStore);
7009 const storeOmit = (keys) => createStore(omit(state, keys), finalStore);
7010 const getState = () => state;
7011 const setState = (key, value, fromStores = false) => {
7012 var _a;
7013 if (!hasOwnProperty(state, key)) return;
7014 const nextValue = applyState(value, state[key]);
7015 if (nextValue === state[key]) return;
7016 if (!fromStores) {
7017 for (const store of stores) {
7018 (_a = store == null ? void 0 : store.setState) == null ? void 0 : _a.call(store, key, nextValue);
7019 }
7020 }
7021 const prevState = state;
7022 state = __spreadProps2(__spreadValues2({}, state), { [key]: nextValue });
7023 const thisUpdate = /* @__PURE__ */ Symbol();
7024 lastUpdate = thisUpdate;
7025 updatedKeys.add(key);
7026 const run = (listener, prev, uKeys) => {
7027 var _a2;
7028 const keys = listenerKeys.get(listener);
7029 const updated = (k) => uKeys ? uKeys.has(k) : k === key;
7030 if (!keys || keys.some(updated)) {
7031 (_a2 = disposables.get(listener)) == null ? void 0 : _a2();
7032 disposables.set(listener, listener(state, prev));
7033 }
7034 };
7035 for (const listener of listeners) {
7036 run(listener, prevState);
7037 }
7038 queueMicrotask(() => {
7039 if (lastUpdate !== thisUpdate) return;
7040 const snapshot = state;
7041 for (const listener of batchListeners) {
7042 run(listener, prevStateBatch, updatedKeys);
7043 }
7044 prevStateBatch = snapshot;
7045 updatedKeys.clear();
7046 });
7047 };
7048 const finalStore = {
7049 getState,
7050 setState,
7051 __unstableInternals: {
7052 setup: storeSetup,
7053 init: storeInit,
7054 subscribe: storeSubscribe,
7055 sync: storeSync,
7056 batch: storeBatch,
7057 pick: storePick,
7058 omit: storeOmit
7059 }
7060 };
7061 return finalStore;
7062 }
7063 function setup(store, ...args) {
7064 if (!store) return;
7065 return getInternal(store, "setup")(...args);
7066 }
7067 function init(store, ...args) {
7068 if (!store) return;
7069 return getInternal(store, "init")(...args);
7070 }
7071 function subscribe(store, ...args) {
7072 if (!store) return;
7073 return getInternal(store, "subscribe")(...args);
7074 }
7075 function sync(store, ...args) {
7076 if (!store) return;
7077 return getInternal(store, "sync")(...args);
7078 }
7079 function batch(store, ...args) {
7080 if (!store) return;
7081 return getInternal(store, "batch")(...args);
7082 }
7083 function omit2(store, ...args) {
7084 if (!store) return;
7085 return getInternal(store, "omit")(...args);
7086 }
7087 function pick2(store, ...args) {
7088 if (!store) return;
7089 return getInternal(store, "pick")(...args);
7090 }
7091 function mergeStore(...stores) {
7092 const initialState = stores.reduce((state, store2) => {
7093 var _a;
7094 const nextState = (_a = store2 == null ? void 0 : store2.getState) == null ? void 0 : _a.call(store2);
7095 if (!nextState) return state;
7096 return Object.assign(state, nextState);
7097 }, {});
7098 const store = createStore(initialState, ...stores);
7099 return Object.assign({}, ...stores, store);
7100 }
7101 function throwOnConflictingProps(props, store) {
7102 if (false) return;
7103 if (!store) return;
7104 const defaultKeys = Object.entries(props).filter(([key, value]) => key.startsWith("default") && value !== void 0).map(([key]) => {
7105 var _a;
7106 const stateKey = key.replace("default", "");
7107 return `${((_a = stateKey[0]) == null ? void 0 : _a.toLowerCase()) || ""}${stateKey.slice(1)}`;
7108 });
7109 if (!defaultKeys.length) return;
7110 const storeState = store.getState();
7111 const conflictingProps = defaultKeys.filter(
7112 (key) => hasOwnProperty(storeState, key)
7113 );
7114 if (!conflictingProps.length) return;
7115 throw new Error(
7116 `Passing a store prop in conjunction with a default state is not supported.
7117
7118 const store = useSelectStore();
7119 <SelectProvider store={store} defaultValue="Apple" />
7120 ^ ^
7121
7122 Instead, pass the default state to the topmost store:
7123
7124 const store = useSelectStore({ defaultValue: "Apple" });
7125 <SelectProvider store={store} />
7126
7127 See https://github.com/ariakit/ariakit/pull/2745 for more details.
7128
7129 If there's a particular need for this, please submit a feature request at https://github.com/ariakit/ariakit
7130 `
7131 );
7132 }
7133
7134 // node_modules/@ariakit/react-core/esm/__chunks/YV4JVR4I.js
7135 var React7 = __toESM(require_react(), 1);
7136 var import_shim = __toESM(require_shim(), 1);
7137 var { useSyncExternalStore } = import_shim.default;
7138 var noopSubscribe = () => () => {
7139 };
7140 function useStoreState(store, keyOrSelector = identity) {
7141 const storeSubscribe = React7.useCallback(
7142 (callback) => {
7143 if (!store) return noopSubscribe();
7144 return subscribe(store, null, callback);
7145 },
7146 [store]
7147 );
7148 const getSnapshot = () => {
7149 const key = typeof keyOrSelector === "string" ? keyOrSelector : null;
7150 const selector2 = typeof keyOrSelector === "function" ? keyOrSelector : null;
7151 const state = store == null ? void 0 : store.getState();
7152 if (selector2) return selector2(state);
7153 if (!state) return;
7154 if (!key) return;
7155 if (!hasOwnProperty(state, key)) return;
7156 return state[key];
7157 };
7158 return useSyncExternalStore(storeSubscribe, getSnapshot, getSnapshot);
7159 }
7160 function useStoreStateObject(store, object) {
7161 const objRef = React7.useRef(
7162 {}
7163 );
7164 const storeSubscribe = React7.useCallback(
7165 (callback) => {
7166 if (!store) return noopSubscribe();
7167 return subscribe(store, null, callback);
7168 },
7169 [store]
7170 );
7171 const getSnapshot = () => {
7172 const state = store == null ? void 0 : store.getState();
7173 let updated = false;
7174 const obj = objRef.current;
7175 for (const prop in object) {
7176 const keyOrSelector = object[prop];
7177 if (typeof keyOrSelector === "function") {
7178 const value = keyOrSelector(state);
7179 if (value !== obj[prop]) {
7180 obj[prop] = value;
7181 updated = true;
7182 }
7183 }
7184 if (typeof keyOrSelector === "string") {
7185 if (!state) continue;
7186 if (!hasOwnProperty(state, keyOrSelector)) continue;
7187 const value = state[keyOrSelector];
7188 if (value !== obj[prop]) {
7189 obj[prop] = value;
7190 updated = true;
7191 }
7192 }
7193 }
7194 if (updated) {
7195 objRef.current = __spreadValues({}, obj);
7196 }
7197 return objRef.current;
7198 };
7199 return useSyncExternalStore(storeSubscribe, getSnapshot, getSnapshot);
7200 }
7201 function useStoreProps(store, props, key, setKey) {
7202 const value = hasOwnProperty(props, key) ? props[key] : void 0;
7203 const setValue = setKey ? props[setKey] : void 0;
7204 const propsRef = useLiveRef({ value, setValue });
7205 useSafeLayoutEffect(() => {
7206 return sync(store, [key], (state, prev) => {
7207 const { value: value2, setValue: setValue2 } = propsRef.current;
7208 if (!setValue2) return;
7209 if (state[key] === prev[key]) return;
7210 if (state[key] === value2) return;
7211 setValue2(state[key]);
7212 });
7213 }, [store, key]);
7214 useSafeLayoutEffect(() => {
7215 if (value === void 0) return;
7216 store.setState(key, value);
7217 return batch(store, [key], () => {
7218 if (value === void 0) return;
7219 store.setState(key, value);
7220 });
7221 });
7222 }
7223 function useStore(createStore2, props) {
7224 const [store, setStore] = React7.useState(() => createStore2(props));
7225 useSafeLayoutEffect(() => init(store), [store]);
7226 const useState27 = React7.useCallback(
7227 (keyOrSelector) => useStoreState(store, keyOrSelector),
7228 [store]
7229 );
7230 const memoizedStore = React7.useMemo(
7231 () => __spreadProps(__spreadValues({}, store), { useState: useState27 }),
7232 [store, useState27]
7233 );
7234 const updateStore = useEvent(() => {
7235 setStore((store2) => createStore2(__spreadValues(__spreadValues({}, props), store2.getState())));
7236 });
7237 return [memoizedStore, updateStore];
7238 }
7239
7240 // node_modules/@ariakit/core/esm/__chunks/CYQWQL4J.js
7241 function getCommonParent(items) {
7242 var _a;
7243 const firstItem = items.find((item) => !!item.element);
7244 const lastItem = [...items].reverse().find((item) => !!item.element);
7245 let parentElement = (_a = firstItem == null ? void 0 : firstItem.element) == null ? void 0 : _a.parentElement;
7246 while (parentElement && (lastItem == null ? void 0 : lastItem.element)) {
7247 const parent = parentElement;
7248 if (lastItem && parent.contains(lastItem.element)) {
7249 return parentElement;
7250 }
7251 parentElement = parentElement.parentElement;
7252 }
7253 return getDocument(parentElement).body;
7254 }
7255 function getPrivateStore(store) {
7256 return store == null ? void 0 : store.__unstablePrivateStore;
7257 }
7258 function createCollectionStore(props = {}) {
7259 var _a;
7260 throwOnConflictingProps(props, props.store);
7261 const syncState = (_a = props.store) == null ? void 0 : _a.getState();
7262 const items = defaultValue(
7263 props.items,
7264 syncState == null ? void 0 : syncState.items,
7265 props.defaultItems,
7266 []
7267 );
7268 const itemsMap = new Map(items.map((item) => [item.id, item]));
7269 const initialState = {
7270 items,
7271 renderedItems: defaultValue(syncState == null ? void 0 : syncState.renderedItems, [])
7272 };
7273 const syncPrivateStore = getPrivateStore(props.store);
7274 const privateStore = createStore(
7275 { items, renderedItems: initialState.renderedItems },
7276 syncPrivateStore
7277 );
7278 const collection = createStore(initialState, props.store);
7279 const sortItems = (renderedItems) => {
7280 const sortedItems = sortBasedOnDOMPosition(renderedItems, (i2) => i2.element);
7281 privateStore.setState("renderedItems", sortedItems);
7282 collection.setState("renderedItems", sortedItems);
7283 };
7284 setup(collection, () => init(privateStore));
7285 setup(privateStore, () => {
7286 return batch(privateStore, ["items"], (state) => {
7287 collection.setState("items", state.items);
7288 });
7289 });
7290 setup(privateStore, () => {
7291 return batch(privateStore, ["renderedItems"], (state) => {
7292 let firstRun = true;
7293 let raf = requestAnimationFrame(() => {
7294 const { renderedItems } = collection.getState();
7295 if (state.renderedItems === renderedItems) return;
7296 sortItems(state.renderedItems);
7297 });
7298 if (typeof IntersectionObserver !== "function") {
7299 return () => cancelAnimationFrame(raf);
7300 }
7301 const ioCallback = () => {
7302 if (firstRun) {
7303 firstRun = false;
7304 return;
7305 }
7306 cancelAnimationFrame(raf);
7307 raf = requestAnimationFrame(() => sortItems(state.renderedItems));
7308 };
7309 const root = getCommonParent(state.renderedItems);
7310 const observer = new IntersectionObserver(ioCallback, { root });
7311 for (const item of state.renderedItems) {
7312 if (!item.element) continue;
7313 observer.observe(item.element);
7314 }
7315 return () => {
7316 cancelAnimationFrame(raf);
7317 observer.disconnect();
7318 };
7319 });
7320 });
7321 const mergeItem = (item, setItems, canDeleteFromMap = false) => {
7322 let prevItem;
7323 setItems((items2) => {
7324 const index = items2.findIndex(({ id }) => id === item.id);
7325 const nextItems = items2.slice();
7326 if (index !== -1) {
7327 prevItem = items2[index];
7328 const nextItem = __spreadValues2(__spreadValues2({}, prevItem), item);
7329 nextItems[index] = nextItem;
7330 itemsMap.set(item.id, nextItem);
7331 } else {
7332 nextItems.push(item);
7333 itemsMap.set(item.id, item);
7334 }
7335 return nextItems;
7336 });
7337 const unmergeItem = () => {
7338 setItems((items2) => {
7339 if (!prevItem) {
7340 if (canDeleteFromMap) {
7341 itemsMap.delete(item.id);
7342 }
7343 return items2.filter(({ id }) => id !== item.id);
7344 }
7345 const index = items2.findIndex(({ id }) => id === item.id);
7346 if (index === -1) return items2;
7347 const nextItems = items2.slice();
7348 nextItems[index] = prevItem;
7349 itemsMap.set(item.id, prevItem);
7350 return nextItems;
7351 });
7352 };
7353 return unmergeItem;
7354 };
7355 const registerItem = (item) => mergeItem(
7356 item,
7357 (getItems) => privateStore.setState("items", getItems),
7358 true
7359 );
7360 return __spreadProps2(__spreadValues2({}, collection), {
7361 registerItem,
7362 renderItem: (item) => chain(
7363 registerItem(item),
7364 mergeItem(
7365 item,
7366 (getItems) => privateStore.setState("renderedItems", getItems)
7367 )
7368 ),
7369 item: (id) => {
7370 if (!id) return null;
7371 let item = itemsMap.get(id);
7372 if (!item) {
7373 const { items: items2 } = privateStore.getState();
7374 item = items2.find((item2) => item2.id === id);
7375 if (item) {
7376 itemsMap.set(id, item);
7377 }
7378 }
7379 return item || null;
7380 },
7381 // @ts-expect-error Internal
7382 __unstablePrivateStore: privateStore
7383 });
7384 }
7385
7386 // node_modules/@ariakit/react-core/esm/__chunks/C3IKGW5T.js
7387 function useCollectionStoreProps(store, update2, props) {
7388 useUpdateEffect(update2, [props.store]);
7389 useStoreProps(store, props, "items", "setItems");
7390 return store;
7391 }
7392
7393 // node_modules/@ariakit/core/esm/__chunks/7PRQYBBV.js
7394 function toArray(arg) {
7395 if (Array.isArray(arg)) {
7396 return arg;
7397 }
7398 return typeof arg !== "undefined" ? [arg] : [];
7399 }
7400 function flatten2DArray(array) {
7401 const flattened = [];
7402 for (const row of array) {
7403 flattened.push(...row);
7404 }
7405 return flattened;
7406 }
7407 function reverseArray(array) {
7408 return array.slice().reverse();
7409 }
7410
7411 // node_modules/@ariakit/core/esm/__chunks/AJZ4BYF3.js
7412 var NULL_ITEM = { id: null };
7413 function findFirstEnabledItem(items, excludeId) {
7414 return items.find((item) => {
7415 if (excludeId) {
7416 return !item.disabled && item.id !== excludeId;
7417 }
7418 return !item.disabled;
7419 });
7420 }
7421 function getEnabledItems(items, excludeId) {
7422 return items.filter((item) => {
7423 if (excludeId) {
7424 return !item.disabled && item.id !== excludeId;
7425 }
7426 return !item.disabled;
7427 });
7428 }
7429 function getItemsInRow(items, rowId) {
7430 return items.filter((item) => item.rowId === rowId);
7431 }
7432 function flipItems(items, activeId, shouldInsertNullItem = false) {
7433 const index = items.findIndex((item) => item.id === activeId);
7434 return [
7435 ...items.slice(index + 1),
7436 ...shouldInsertNullItem ? [NULL_ITEM] : [],
7437 ...items.slice(0, index)
7438 ];
7439 }
7440 function groupItemsByRows(items) {
7441 const rows = [];
7442 for (const item of items) {
7443 const row = rows.find((currentRow) => {
7444 var _a;
7445 return ((_a = currentRow[0]) == null ? void 0 : _a.rowId) === item.rowId;
7446 });
7447 if (row) {
7448 row.push(item);
7449 } else {
7450 rows.push([item]);
7451 }
7452 }
7453 return rows;
7454 }
7455 function getMaxRowLength(array) {
7456 let maxLength = 0;
7457 for (const { length } of array) {
7458 if (length > maxLength) {
7459 maxLength = length;
7460 }
7461 }
7462 return maxLength;
7463 }
7464 function createEmptyItem(rowId) {
7465 return {
7466 id: "__EMPTY_ITEM__",
7467 disabled: true,
7468 rowId
7469 };
7470 }
7471 function normalizeRows(rows, activeId, focusShift) {
7472 const maxLength = getMaxRowLength(rows);
7473 for (const row of rows) {
7474 for (let i2 = 0; i2 < maxLength; i2 += 1) {
7475 const item = row[i2];
7476 if (!item || focusShift && item.disabled) {
7477 const isFirst = i2 === 0;
7478 const previousItem = isFirst && focusShift ? findFirstEnabledItem(row) : row[i2 - 1];
7479 row[i2] = previousItem && activeId !== previousItem.id && focusShift ? previousItem : createEmptyItem(previousItem == null ? void 0 : previousItem.rowId);
7480 }
7481 }
7482 }
7483 return rows;
7484 }
7485 function verticalizeItems(items) {
7486 const rows = groupItemsByRows(items);
7487 const maxLength = getMaxRowLength(rows);
7488 const verticalized = [];
7489 for (let i2 = 0; i2 < maxLength; i2 += 1) {
7490 for (const row of rows) {
7491 const item = row[i2];
7492 if (item) {
7493 verticalized.push(__spreadProps2(__spreadValues2({}, item), {
7494 // If there's no rowId, it means that it's not a grid composite, but
7495 // a single row instead. So, instead of verticalizing it, that is,
7496 // assigning a different rowId based on the column index, we keep it
7497 // undefined so they will be part of the same row. This is useful
7498 // when using up/down on one-dimensional composites.
7499 rowId: item.rowId ? `${i2}` : void 0
7500 }));
7501 }
7502 }
7503 }
7504 return verticalized;
7505 }
7506 function createCompositeStore(props = {}) {
7507 var _a;
7508 const syncState = (_a = props.store) == null ? void 0 : _a.getState();
7509 const collection = createCollectionStore(props);
7510 const activeId = defaultValue(
7511 props.activeId,
7512 syncState == null ? void 0 : syncState.activeId,
7513 props.defaultActiveId
7514 );
7515 const initialState = __spreadProps2(__spreadValues2({}, collection.getState()), {
7516 id: defaultValue(
7517 props.id,
7518 syncState == null ? void 0 : syncState.id,
7519 `id-${Math.random().toString(36).slice(2, 8)}`
7520 ),
7521 activeId,
7522 baseElement: defaultValue(syncState == null ? void 0 : syncState.baseElement, null),
7523 includesBaseElement: defaultValue(
7524 props.includesBaseElement,
7525 syncState == null ? void 0 : syncState.includesBaseElement,
7526 activeId === null
7527 ),
7528 moves: defaultValue(syncState == null ? void 0 : syncState.moves, 0),
7529 orientation: defaultValue(
7530 props.orientation,
7531 syncState == null ? void 0 : syncState.orientation,
7532 "both"
7533 ),
7534 rtl: defaultValue(props.rtl, syncState == null ? void 0 : syncState.rtl, false),
7535 virtualFocus: defaultValue(
7536 props.virtualFocus,
7537 syncState == null ? void 0 : syncState.virtualFocus,
7538 false
7539 ),
7540 focusLoop: defaultValue(props.focusLoop, syncState == null ? void 0 : syncState.focusLoop, false),
7541 focusWrap: defaultValue(props.focusWrap, syncState == null ? void 0 : syncState.focusWrap, false),
7542 focusShift: defaultValue(props.focusShift, syncState == null ? void 0 : syncState.focusShift, false)
7543 });
7544 const composite = createStore(initialState, collection, props.store);
7545 setup(
7546 composite,
7547 () => sync(composite, ["renderedItems", "activeId"], (state) => {
7548 composite.setState("activeId", (activeId2) => {
7549 var _a2;
7550 if (activeId2 !== void 0) return activeId2;
7551 return (_a2 = findFirstEnabledItem(state.renderedItems)) == null ? void 0 : _a2.id;
7552 });
7553 })
7554 );
7555 const getNextId = (direction = "next", options = {}) => {
7556 var _a2, _b;
7557 const defaultState = composite.getState();
7558 const {
7559 skip = 0,
7560 activeId: activeId2 = defaultState.activeId,
7561 focusShift = defaultState.focusShift,
7562 focusLoop = defaultState.focusLoop,
7563 focusWrap = defaultState.focusWrap,
7564 includesBaseElement = defaultState.includesBaseElement,
7565 renderedItems = defaultState.renderedItems,
7566 rtl = defaultState.rtl
7567 } = options;
7568 const isVerticalDirection = direction === "up" || direction === "down";
7569 const isNextDirection = direction === "next" || direction === "down";
7570 const canReverse = isNextDirection ? rtl && !isVerticalDirection : !rtl || isVerticalDirection;
7571 const canShift = focusShift && !skip;
7572 let items = !isVerticalDirection ? renderedItems : flatten2DArray(
7573 normalizeRows(groupItemsByRows(renderedItems), activeId2, canShift)
7574 );
7575 items = canReverse ? reverseArray(items) : items;
7576 items = isVerticalDirection ? verticalizeItems(items) : items;
7577 if (activeId2 == null) {
7578 return (_a2 = findFirstEnabledItem(items)) == null ? void 0 : _a2.id;
7579 }
7580 const activeItem = items.find((item) => item.id === activeId2);
7581 if (!activeItem) {
7582 return (_b = findFirstEnabledItem(items)) == null ? void 0 : _b.id;
7583 }
7584 const isGrid2 = items.some((item) => item.rowId);
7585 const activeIndex = items.indexOf(activeItem);
7586 const nextItems = items.slice(activeIndex + 1);
7587 const nextItemsInRow = getItemsInRow(nextItems, activeItem.rowId);
7588 if (skip) {
7589 const nextEnabledItemsInRow = getEnabledItems(nextItemsInRow, activeId2);
7590 const nextItem2 = nextEnabledItemsInRow.slice(skip)[0] || // If we can't find an item, just return the last one.
7591 nextEnabledItemsInRow[nextEnabledItemsInRow.length - 1];
7592 return nextItem2 == null ? void 0 : nextItem2.id;
7593 }
7594 const canLoop = focusLoop && (isVerticalDirection ? focusLoop !== "horizontal" : focusLoop !== "vertical");
7595 const canWrap = isGrid2 && focusWrap && (isVerticalDirection ? focusWrap !== "horizontal" : focusWrap !== "vertical");
7596 const hasNullItem = isNextDirection ? (!isGrid2 || isVerticalDirection) && canLoop && includesBaseElement : isVerticalDirection ? includesBaseElement : false;
7597 if (canLoop) {
7598 const loopItems = canWrap && !hasNullItem ? items : getItemsInRow(items, activeItem.rowId);
7599 const sortedItems = flipItems(loopItems, activeId2, hasNullItem);
7600 const nextItem2 = findFirstEnabledItem(sortedItems, activeId2);
7601 return nextItem2 == null ? void 0 : nextItem2.id;
7602 }
7603 if (canWrap) {
7604 const nextItem2 = findFirstEnabledItem(
7605 // We can use nextItems, which contains all the next items, including
7606 // items from other rows, to wrap between rows. However, if there is a
7607 // null item (the composite container), we'll only use the next items in
7608 // the row. So moving next from the last item will focus on the
7609 // composite container. On grid composites, horizontal navigation never
7610 // focuses on the composite container, only vertical.
7611 hasNullItem ? nextItemsInRow : nextItems,
7612 activeId2
7613 );
7614 const nextId = hasNullItem ? (nextItem2 == null ? void 0 : nextItem2.id) || null : nextItem2 == null ? void 0 : nextItem2.id;
7615 return nextId;
7616 }
7617 const nextItem = findFirstEnabledItem(nextItemsInRow, activeId2);
7618 if (!nextItem && hasNullItem) {
7619 return null;
7620 }
7621 return nextItem == null ? void 0 : nextItem.id;
7622 };
7623 return __spreadProps2(__spreadValues2(__spreadValues2({}, collection), composite), {
7624 setBaseElement: (element) => composite.setState("baseElement", element),
7625 setActiveId: (id) => composite.setState("activeId", id),
7626 move: (id) => {
7627 if (id === void 0) return;
7628 composite.setState("activeId", id);
7629 composite.setState("moves", (moves) => moves + 1);
7630 },
7631 first: () => {
7632 var _a2;
7633 return (_a2 = findFirstEnabledItem(composite.getState().renderedItems)) == null ? void 0 : _a2.id;
7634 },
7635 last: () => {
7636 var _a2;
7637 return (_a2 = findFirstEnabledItem(reverseArray(composite.getState().renderedItems))) == null ? void 0 : _a2.id;
7638 },
7639 next: (options) => {
7640 if (options !== void 0 && typeof options === "number") {
7641 options = { skip: options };
7642 }
7643 return getNextId("next", options);
7644 },
7645 previous: (options) => {
7646 if (options !== void 0 && typeof options === "number") {
7647 options = { skip: options };
7648 }
7649 return getNextId("previous", options);
7650 },
7651 down: (options) => {
7652 if (options !== void 0 && typeof options === "number") {
7653 options = { skip: options };
7654 }
7655 return getNextId("down", options);
7656 },
7657 up: (options) => {
7658 if (options !== void 0 && typeof options === "number") {
7659 options = { skip: options };
7660 }
7661 return getNextId("up", options);
7662 }
7663 });
7664 }
7665
7666 // node_modules/@ariakit/react-core/esm/__chunks/4CMBR7SL.js
7667 function useCompositeStoreOptions(props) {
7668 const id = useId3(props.id);
7669 return __spreadValues({ id }, props);
7670 }
7671 function useCompositeStoreProps(store, update2, props) {
7672 store = useCollectionStoreProps(store, update2, props);
7673 useStoreProps(store, props, "activeId", "setActiveId");
7674 useStoreProps(store, props, "includesBaseElement");
7675 useStoreProps(store, props, "virtualFocus");
7676 useStoreProps(store, props, "orientation");
7677 useStoreProps(store, props, "rtl");
7678 useStoreProps(store, props, "focusLoop");
7679 useStoreProps(store, props, "focusWrap");
7680 useStoreProps(store, props, "focusShift");
7681 return store;
7682 }
7683
7684 // node_modules/@ariakit/core/esm/__chunks/RCQ5P4YE.js
7685 function createDisclosureStore(props = {}) {
7686 const store = mergeStore(
7687 props.store,
7688 omit2(props.disclosure, ["contentElement", "disclosureElement"])
7689 );
7690 throwOnConflictingProps(props, store);
7691 const syncState = store == null ? void 0 : store.getState();
7692 const open = defaultValue(
7693 props.open,
7694 syncState == null ? void 0 : syncState.open,
7695 props.defaultOpen,
7696 false
7697 );
7698 const animated = defaultValue(props.animated, syncState == null ? void 0 : syncState.animated, false);
7699 const initialState = {
7700 open,
7701 animated,
7702 animating: !!animated && open,
7703 mounted: open,
7704 contentElement: defaultValue(syncState == null ? void 0 : syncState.contentElement, null),
7705 disclosureElement: defaultValue(syncState == null ? void 0 : syncState.disclosureElement, null)
7706 };
7707 const disclosure = createStore(initialState, store);
7708 setup(
7709 disclosure,
7710 () => sync(disclosure, ["animated", "animating"], (state) => {
7711 if (state.animated) return;
7712 disclosure.setState("animating", false);
7713 })
7714 );
7715 setup(
7716 disclosure,
7717 () => subscribe(disclosure, ["open"], () => {
7718 if (!disclosure.getState().animated) return;
7719 disclosure.setState("animating", true);
7720 })
7721 );
7722 setup(
7723 disclosure,
7724 () => sync(disclosure, ["open", "animating"], (state) => {
7725 disclosure.setState("mounted", state.open || state.animating);
7726 })
7727 );
7728 return __spreadProps2(__spreadValues2({}, disclosure), {
7729 disclosure: props.disclosure,
7730 setOpen: (value) => disclosure.setState("open", value),
7731 show: () => disclosure.setState("open", true),
7732 hide: () => disclosure.setState("open", false),
7733 toggle: () => disclosure.setState("open", (open2) => !open2),
7734 stopAnimation: () => disclosure.setState("animating", false),
7735 setContentElement: (value) => disclosure.setState("contentElement", value),
7736 setDisclosureElement: (value) => disclosure.setState("disclosureElement", value)
7737 });
7738 }
7739
7740 // node_modules/@ariakit/react-core/esm/__chunks/WYCIER3C.js
7741 function useDisclosureStoreProps(store, update2, props) {
7742 useUpdateEffect(update2, [props.store, props.disclosure]);
7743 useStoreProps(store, props, "open", "setOpen");
7744 useStoreProps(store, props, "mounted", "setMounted");
7745 useStoreProps(store, props, "animated");
7746 return Object.assign(store, { disclosure: props.disclosure });
7747 }
7748
7749 // node_modules/@ariakit/core/esm/__chunks/FZZ2AVHF.js
7750 function createDialogStore(props = {}) {
7751 return createDisclosureStore(props);
7752 }
7753
7754 // node_modules/@ariakit/react-core/esm/__chunks/BM6PGYQY.js
7755 function useDialogStoreProps(store, update2, props) {
7756 return useDisclosureStoreProps(store, update2, props);
7757 }
7758
7759 // node_modules/@ariakit/core/esm/__chunks/ME2CUF3F.js
7760 function createPopoverStore(_a = {}) {
7761 var _b = _a, {
7762 popover: otherPopover
7763 } = _b, props = __objRest2(_b, [
7764 "popover"
7765 ]);
7766 const store = mergeStore(
7767 props.store,
7768 omit2(otherPopover, [
7769 "arrowElement",
7770 "anchorElement",
7771 "contentElement",
7772 "popoverElement",
7773 "disclosureElement"
7774 ])
7775 );
7776 throwOnConflictingProps(props, store);
7777 const syncState = store == null ? void 0 : store.getState();
7778 const dialog = createDialogStore(__spreadProps2(__spreadValues2({}, props), { store }));
7779 const placement = defaultValue(
7780 props.placement,
7781 syncState == null ? void 0 : syncState.placement,
7782 "bottom"
7783 );
7784 const initialState = __spreadProps2(__spreadValues2({}, dialog.getState()), {
7785 placement,
7786 currentPlacement: placement,
7787 anchorElement: defaultValue(syncState == null ? void 0 : syncState.anchorElement, null),
7788 popoverElement: defaultValue(syncState == null ? void 0 : syncState.popoverElement, null),
7789 arrowElement: defaultValue(syncState == null ? void 0 : syncState.arrowElement, null),
7790 rendered: /* @__PURE__ */ Symbol("rendered")
7791 });
7792 const popover = createStore(initialState, dialog, store);
7793 return __spreadProps2(__spreadValues2(__spreadValues2({}, dialog), popover), {
7794 setAnchorElement: (element) => popover.setState("anchorElement", element),
7795 setPopoverElement: (element) => popover.setState("popoverElement", element),
7796 setArrowElement: (element) => popover.setState("arrowElement", element),
7797 render: () => popover.setState("rendered", /* @__PURE__ */ Symbol("rendered"))
7798 });
7799 }
7800
7801 // node_modules/@ariakit/react-core/esm/__chunks/O2PQ2652.js
7802 function usePopoverStoreProps(store, update2, props) {
7803 useUpdateEffect(update2, [props.popover]);
7804 useStoreProps(store, props, "placement");
7805 return useDialogStoreProps(store, update2, props);
7806 }
7807
7808 // node_modules/@ariakit/core/esm/combobox/combobox-store.js
7809 var isTouchSafari = isSafari() && isTouchDevice();
7810 function createComboboxStore(_a = {}) {
7811 var _b = _a, {
7812 tag
7813 } = _b, props = __objRest2(_b, [
7814 "tag"
7815 ]);
7816 const store = mergeStore(props.store, pick2(tag, ["value", "rtl"]));
7817 throwOnConflictingProps(props, store);
7818 const tagState = tag == null ? void 0 : tag.getState();
7819 const syncState = store == null ? void 0 : store.getState();
7820 const activeId = defaultValue(
7821 props.activeId,
7822 syncState == null ? void 0 : syncState.activeId,
7823 props.defaultActiveId,
7824 null
7825 );
7826 const composite = createCompositeStore(__spreadProps2(__spreadValues2({}, props), {
7827 activeId,
7828 includesBaseElement: defaultValue(
7829 props.includesBaseElement,
7830 syncState == null ? void 0 : syncState.includesBaseElement,
7831 true
7832 ),
7833 orientation: defaultValue(
7834 props.orientation,
7835 syncState == null ? void 0 : syncState.orientation,
7836 "vertical"
7837 ),
7838 focusLoop: defaultValue(props.focusLoop, syncState == null ? void 0 : syncState.focusLoop, true),
7839 focusWrap: defaultValue(props.focusWrap, syncState == null ? void 0 : syncState.focusWrap, true),
7840 virtualFocus: defaultValue(
7841 props.virtualFocus,
7842 syncState == null ? void 0 : syncState.virtualFocus,
7843 true
7844 )
7845 }));
7846 const popover = createPopoverStore(__spreadProps2(__spreadValues2({}, props), {
7847 placement: defaultValue(
7848 props.placement,
7849 syncState == null ? void 0 : syncState.placement,
7850 "bottom-start"
7851 )
7852 }));
7853 const value = defaultValue(
7854 props.value,
7855 syncState == null ? void 0 : syncState.value,
7856 props.defaultValue,
7857 ""
7858 );
7859 const selectedValue = defaultValue(
7860 props.selectedValue,
7861 syncState == null ? void 0 : syncState.selectedValue,
7862 tagState == null ? void 0 : tagState.values,
7863 props.defaultSelectedValue,
7864 ""
7865 );
7866 const multiSelectable = Array.isArray(selectedValue);
7867 const initialState = __spreadProps2(__spreadValues2(__spreadValues2({}, composite.getState()), popover.getState()), {
7868 value,
7869 selectedValue,
7870 resetValueOnSelect: defaultValue(
7871 props.resetValueOnSelect,
7872 syncState == null ? void 0 : syncState.resetValueOnSelect,
7873 multiSelectable
7874 ),
7875 resetValueOnHide: defaultValue(
7876 props.resetValueOnHide,
7877 syncState == null ? void 0 : syncState.resetValueOnHide,
7878 multiSelectable && !tag
7879 ),
7880 activeValue: syncState == null ? void 0 : syncState.activeValue
7881 });
7882 const combobox = createStore(initialState, composite, popover, store);
7883 if (isTouchSafari) {
7884 setup(
7885 combobox,
7886 () => sync(combobox, ["virtualFocus"], () => {
7887 combobox.setState("virtualFocus", false);
7888 })
7889 );
7890 }
7891 setup(combobox, () => {
7892 if (!tag) return;
7893 return chain(
7894 sync(combobox, ["selectedValue"], (state) => {
7895 if (!Array.isArray(state.selectedValue)) return;
7896 tag.setValues(state.selectedValue);
7897 }),
7898 sync(tag, ["values"], (state) => {
7899 combobox.setState("selectedValue", state.values);
7900 })
7901 );
7902 });
7903 setup(
7904 combobox,
7905 () => sync(combobox, ["resetValueOnHide", "mounted"], (state) => {
7906 if (!state.resetValueOnHide) return;
7907 if (state.mounted) return;
7908 combobox.setState("value", value);
7909 })
7910 );
7911 setup(
7912 combobox,
7913 () => sync(combobox, ["open"], (state) => {
7914 if (state.open) return;
7915 combobox.setState("activeId", activeId);
7916 combobox.setState("moves", 0);
7917 })
7918 );
7919 setup(
7920 combobox,
7921 () => sync(combobox, ["moves", "activeId"], (state, prevState) => {
7922 if (state.moves === prevState.moves) {
7923 combobox.setState("activeValue", void 0);
7924 }
7925 })
7926 );
7927 setup(
7928 combobox,
7929 () => batch(combobox, ["moves", "renderedItems"], (state, prev) => {
7930 if (state.moves === prev.moves) return;
7931 const { activeId: activeId2 } = combobox.getState();
7932 const activeItem = composite.item(activeId2);
7933 combobox.setState("activeValue", activeItem == null ? void 0 : activeItem.value);
7934 })
7935 );
7936 return __spreadProps2(__spreadValues2(__spreadValues2(__spreadValues2({}, popover), composite), combobox), {
7937 tag,
7938 setValue: (value2) => combobox.setState("value", value2),
7939 resetValue: () => combobox.setState("value", initialState.value),
7940 setSelectedValue: (selectedValue2) => combobox.setState("selectedValue", selectedValue2)
7941 });
7942 }
7943
7944 // node_modules/@ariakit/react-core/esm/__chunks/FEOFMWBY.js
7945 function useComboboxStoreOptions(props) {
7946 const tag = useTagContext();
7947 props = __spreadProps(__spreadValues({}, props), {
7948 tag: props.tag !== void 0 ? props.tag : tag
7949 });
7950 return useCompositeStoreOptions(props);
7951 }
7952 function useComboboxStoreProps(store, update2, props) {
7953 useUpdateEffect(update2, [props.tag]);
7954 useStoreProps(store, props, "value", "setValue");
7955 useStoreProps(store, props, "selectedValue", "setSelectedValue");
7956 useStoreProps(store, props, "resetValueOnHide");
7957 useStoreProps(store, props, "resetValueOnSelect");
7958 return Object.assign(
7959 useCompositeStoreProps(
7960 usePopoverStoreProps(store, update2, props),
7961 update2,
7962 props
7963 ),
7964 { tag: props.tag }
7965 );
7966 }
7967 function useComboboxStore(props = {}) {
7968 props = useComboboxStoreOptions(props);
7969 const [store, update2] = useStore(createComboboxStore, props);
7970 return useComboboxStoreProps(store, update2, props);
7971 }
7972
7973 // node_modules/@ariakit/react-core/esm/__chunks/S6EF7IVO.js
7974 var ctx4 = createStoreContext();
7975 var useDisclosureContext = ctx4.useContext;
7976 var useDisclosureScopedContext = ctx4.useScopedContext;
7977 var useDisclosureProviderContext = ctx4.useProviderContext;
7978 var DisclosureContextProvider = ctx4.ContextProvider;
7979 var DisclosureScopedContextProvider = ctx4.ScopedContextProvider;
7980
7981 // node_modules/@ariakit/react-core/esm/__chunks/RS7LB2H4.js
7982 var import_react8 = __toESM(require_react(), 1);
7983 var ctx5 = createStoreContext(
7984 [DisclosureContextProvider],
7985 [DisclosureScopedContextProvider]
7986 );
7987 var useDialogContext = ctx5.useContext;
7988 var useDialogScopedContext = ctx5.useScopedContext;
7989 var useDialogProviderContext = ctx5.useProviderContext;
7990 var DialogContextProvider = ctx5.ContextProvider;
7991 var DialogScopedContextProvider = ctx5.ScopedContextProvider;
7992 var DialogHeadingContext = (0, import_react8.createContext)(void 0);
7993 var DialogDescriptionContext = (0, import_react8.createContext)(void 0);
7994
7995 // node_modules/@ariakit/react-core/esm/__chunks/MTZPJQMC.js
7996 var ctx6 = createStoreContext(
7997 [DialogContextProvider],
7998 [DialogScopedContextProvider]
7999 );
8000 var usePopoverContext = ctx6.useContext;
8001 var usePopoverScopedContext = ctx6.useScopedContext;
8002 var usePopoverProviderContext = ctx6.useProviderContext;
8003 var PopoverContextProvider = ctx6.ContextProvider;
8004 var PopoverScopedContextProvider = ctx6.ScopedContextProvider;
8005
8006 // node_modules/@ariakit/react-core/esm/__chunks/VEVQD5MH.js
8007 var import_react9 = __toESM(require_react(), 1);
8008 var ComboboxListRoleContext = (0, import_react9.createContext)(
8009 void 0
8010 );
8011 var ctx7 = createStoreContext(
8012 [PopoverContextProvider, CompositeContextProvider],
8013 [PopoverScopedContextProvider, CompositeScopedContextProvider]
8014 );
8015 var useComboboxContext = ctx7.useContext;
8016 var useComboboxScopedContext = ctx7.useScopedContext;
8017 var useComboboxProviderContext = ctx7.useProviderContext;
8018 var ComboboxContextProvider = ctx7.ContextProvider;
8019 var ComboboxScopedContextProvider = ctx7.ScopedContextProvider;
8020 var ComboboxItemValueContext = (0, import_react9.createContext)(
8021 void 0
8022 );
8023 var ComboboxItemCheckedContext = (0, import_react9.createContext)(false);
8024
8025 // node_modules/@ariakit/react-core/esm/__chunks/OMU7RWRV.js
8026 var TagName = "div";
8027 var usePopoverAnchor = createHook(
8028 function usePopoverAnchor2(_a) {
8029 var _b = _a, { store } = _b, props = __objRest(_b, ["store"]);
8030 const context = usePopoverProviderContext();
8031 store = store || context;
8032 props = __spreadProps(__spreadValues({}, props), {
8033 ref: useMergeRefs(store == null ? void 0 : store.setAnchorElement, props.ref)
8034 });
8035 return props;
8036 }
8037 );
8038 var PopoverAnchor = forwardRef22(function PopoverAnchor2(props) {
8039 const htmlProps = usePopoverAnchor(props);
8040 return createElement3(TagName, htmlProps);
8041 });
8042
8043 // node_modules/@ariakit/react-core/esm/__chunks/5VQZOHHZ.js
8044 function findFirstEnabledItem2(items, excludeId) {
8045 return items.find((item) => {
8046 if (excludeId) {
8047 return !item.disabled && item.id !== excludeId;
8048 }
8049 return !item.disabled;
8050 });
8051 }
8052 function getEnabledItem(store, id) {
8053 if (!id) return null;
8054 return store.item(id) || null;
8055 }
8056 function groupItemsByRows2(items) {
8057 const rows = [];
8058 for (const item of items) {
8059 const row = rows.find((currentRow) => {
8060 var _a;
8061 return ((_a = currentRow[0]) == null ? void 0 : _a.rowId) === item.rowId;
8062 });
8063 if (row) {
8064 row.push(item);
8065 } else {
8066 rows.push([item]);
8067 }
8068 }
8069 return rows;
8070 }
8071 function selectTextField(element, collapseToEnd = false) {
8072 if (isTextField(element)) {
8073 element.setSelectionRange(
8074 collapseToEnd ? element.value.length : 0,
8075 element.value.length
8076 );
8077 } else if (element.isContentEditable) {
8078 const selection = getDocument(element).getSelection();
8079 selection == null ? void 0 : selection.selectAllChildren(element);
8080 if (collapseToEnd) {
8081 selection == null ? void 0 : selection.collapseToEnd();
8082 }
8083 }
8084 }
8085 var FOCUS_SILENTLY = /* @__PURE__ */ Symbol("FOCUS_SILENTLY");
8086 function focusSilently(element) {
8087 element[FOCUS_SILENTLY] = true;
8088 element.focus({ preventScroll: true });
8089 }
8090 function silentlyFocused(element) {
8091 const isSilentlyFocused = element[FOCUS_SILENTLY];
8092 delete element[FOCUS_SILENTLY];
8093 return isSilentlyFocused;
8094 }
8095 function isItem(store, element, exclude) {
8096 if (!element) return false;
8097 if (element === exclude) return false;
8098 const item = store.item(element.id);
8099 if (!item) return false;
8100 if (exclude && item.element === exclude) return false;
8101 return true;
8102 }
8103
8104 // node_modules/@ariakit/react-core/esm/__chunks/SWN3JYXT.js
8105 var import_react10 = __toESM(require_react(), 1);
8106 var FocusableContext = (0, import_react10.createContext)(true);
8107
8108 // node_modules/@ariakit/core/esm/utils/focus.js
8109 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'])";
8110 function isFocusable(element) {
8111 if (!element.matches(selector)) return false;
8112 if (!isVisible(element)) return false;
8113 if (element.closest("[inert]")) return false;
8114 return true;
8115 }
8116 function getClosestFocusable(element) {
8117 while (element && !isFocusable(element)) {
8118 element = element.closest(selector);
8119 }
8120 return element || null;
8121 }
8122 function hasFocus(element) {
8123 const activeElement = getActiveElement(element);
8124 if (!activeElement) return false;
8125 if (activeElement === element) return true;
8126 const activeDescendant = activeElement.getAttribute("aria-activedescendant");
8127 if (!activeDescendant) return false;
8128 return activeDescendant === element.id;
8129 }
8130 function hasFocusWithin(element) {
8131 const activeElement = getActiveElement(element);
8132 if (!activeElement) return false;
8133 if (contains(element, activeElement)) return true;
8134 const activeDescendant = activeElement.getAttribute("aria-activedescendant");
8135 if (!activeDescendant) return false;
8136 if (!("id" in element)) return false;
8137 if (activeDescendant === element.id) return true;
8138 return !!element.querySelector(`#${CSS.escape(activeDescendant)}`);
8139 }
8140 function focusIfNeeded(element) {
8141 if (!hasFocusWithin(element) && isFocusable(element)) {
8142 element.focus();
8143 }
8144 }
8145 function focusIntoView(element, options) {
8146 if (!("scrollIntoView" in element)) {
8147 element.focus();
8148 } else {
8149 element.focus({ preventScroll: true });
8150 element.scrollIntoView(__spreadValues2({ block: "nearest", inline: "nearest" }, options));
8151 }
8152 }
8153
8154 // node_modules/@ariakit/react-core/esm/__chunks/LVA2YJMS.js
8155 var import_react11 = __toESM(require_react(), 1);
8156 var TagName2 = "div";
8157 var isSafariBrowser = isSafari();
8158 var alwaysFocusVisibleInputTypes = [
8159 "text",
8160 "search",
8161 "url",
8162 "tel",
8163 "email",
8164 "password",
8165 "number",
8166 "date",
8167 "month",
8168 "week",
8169 "time",
8170 "datetime",
8171 "datetime-local"
8172 ];
8173 var safariFocusAncestorSymbol = /* @__PURE__ */ Symbol("safariFocusAncestor");
8174 function markSafariFocusAncestor(element, value) {
8175 if (!element) return;
8176 element[safariFocusAncestorSymbol] = value;
8177 }
8178 function isAlwaysFocusVisible(element) {
8179 const { tagName, readOnly, type } = element;
8180 if (tagName === "TEXTAREA" && !readOnly) return true;
8181 if (tagName === "SELECT" && !readOnly) return true;
8182 if (tagName === "INPUT" && !readOnly) {
8183 return alwaysFocusVisibleInputTypes.includes(type);
8184 }
8185 if (element.isContentEditable) return true;
8186 const role = element.getAttribute("role");
8187 if (role === "combobox" && element.dataset.name) {
8188 return true;
8189 }
8190 return false;
8191 }
8192 function getLabels(element) {
8193 if ("labels" in element) {
8194 return element.labels;
8195 }
8196 return null;
8197 }
8198 function isNativeCheckboxOrRadio(element) {
8199 const tagName = element.tagName.toLowerCase();
8200 if (tagName === "input" && element.type) {
8201 return element.type === "radio" || element.type === "checkbox";
8202 }
8203 return false;
8204 }
8205 function isNativeTabbable(tagName) {
8206 if (!tagName) return true;
8207 return tagName === "button" || tagName === "summary" || tagName === "input" || tagName === "select" || tagName === "textarea" || tagName === "a";
8208 }
8209 function supportsDisabledAttribute(tagName) {
8210 if (!tagName) return true;
8211 return tagName === "button" || tagName === "input" || tagName === "select" || tagName === "textarea";
8212 }
8213 function getTabIndex(focusable, trulyDisabled, nativeTabbable, supportsDisabled, tabIndexProp) {
8214 if (!focusable) {
8215 return tabIndexProp;
8216 }
8217 if (trulyDisabled) {
8218 if (nativeTabbable && !supportsDisabled) {
8219 return -1;
8220 }
8221 return;
8222 }
8223 if (nativeTabbable) {
8224 return tabIndexProp;
8225 }
8226 return tabIndexProp || 0;
8227 }
8228 function useDisableEvent(onEvent, disabled) {
8229 return useEvent((event) => {
8230 onEvent == null ? void 0 : onEvent(event);
8231 if (event.defaultPrevented) return;
8232 if (disabled) {
8233 event.stopPropagation();
8234 event.preventDefault();
8235 }
8236 });
8237 }
8238 var isKeyboardModality = true;
8239 function onGlobalMouseDown(event) {
8240 const target = event.target;
8241 if (target && "hasAttribute" in target) {
8242 if (!target.hasAttribute("data-focus-visible")) {
8243 isKeyboardModality = false;
8244 }
8245 }
8246 }
8247 function onGlobalKeyDown(event) {
8248 if (event.metaKey) return;
8249 if (event.ctrlKey) return;
8250 if (event.altKey) return;
8251 isKeyboardModality = true;
8252 }
8253 var useFocusable = createHook(
8254 function useFocusable2(_a) {
8255 var _b = _a, {
8256 focusable = true,
8257 accessibleWhenDisabled,
8258 autoFocus,
8259 onFocusVisible
8260 } = _b, props = __objRest(_b, [
8261 "focusable",
8262 "accessibleWhenDisabled",
8263 "autoFocus",
8264 "onFocusVisible"
8265 ]);
8266 const ref = (0, import_react11.useRef)(null);
8267 (0, import_react11.useEffect)(() => {
8268 if (!focusable) return;
8269 addGlobalEventListener("mousedown", onGlobalMouseDown, true);
8270 addGlobalEventListener("keydown", onGlobalKeyDown, true);
8271 }, [focusable]);
8272 if (isSafariBrowser) {
8273 (0, import_react11.useEffect)(() => {
8274 if (!focusable) return;
8275 const element = ref.current;
8276 if (!element) return;
8277 if (!isNativeCheckboxOrRadio(element)) return;
8278 const labels = getLabels(element);
8279 if (!labels) return;
8280 const onMouseUp = () => queueMicrotask(() => element.focus());
8281 for (const label of labels) {
8282 label.addEventListener("mouseup", onMouseUp);
8283 }
8284 return () => {
8285 for (const label of labels) {
8286 label.removeEventListener("mouseup", onMouseUp);
8287 }
8288 };
8289 }, [focusable]);
8290 }
8291 const disabled = focusable && disabledFromProps(props);
8292 const trulyDisabled = !!disabled && !accessibleWhenDisabled;
8293 const [focusVisible, setFocusVisible] = (0, import_react11.useState)(false);
8294 (0, import_react11.useEffect)(() => {
8295 if (!focusable) return;
8296 if (trulyDisabled && focusVisible) {
8297 setFocusVisible(false);
8298 }
8299 }, [focusable, trulyDisabled, focusVisible]);
8300 (0, import_react11.useEffect)(() => {
8301 if (!focusable) return;
8302 if (!focusVisible) return;
8303 const element = ref.current;
8304 if (!element) return;
8305 if (typeof IntersectionObserver === "undefined") return;
8306 const observer = new IntersectionObserver(() => {
8307 if (!isFocusable(element)) {
8308 setFocusVisible(false);
8309 }
8310 });
8311 observer.observe(element);
8312 return () => observer.disconnect();
8313 }, [focusable, focusVisible]);
8314 const onKeyPressCapture = useDisableEvent(
8315 props.onKeyPressCapture,
8316 disabled
8317 );
8318 const onMouseDownCapture = useDisableEvent(
8319 props.onMouseDownCapture,
8320 disabled
8321 );
8322 const onClickCapture = useDisableEvent(props.onClickCapture, disabled);
8323 const onMouseDownProp = props.onMouseDown;
8324 const onMouseDown = useEvent((event) => {
8325 onMouseDownProp == null ? void 0 : onMouseDownProp(event);
8326 if (event.defaultPrevented) return;
8327 if (!focusable) return;
8328 const element = event.currentTarget;
8329 if (!isSafariBrowser) return;
8330 if (isPortalEvent(event)) return;
8331 if (!isButton(element) && !isNativeCheckboxOrRadio(element)) return;
8332 let receivedFocus = false;
8333 const onFocus = () => {
8334 receivedFocus = true;
8335 };
8336 const options = { capture: true, once: true };
8337 element.addEventListener("focusin", onFocus, options);
8338 const focusableContainer = getClosestFocusable(element.parentElement);
8339 markSafariFocusAncestor(focusableContainer, true);
8340 queueBeforeEvent(element, "mouseup", () => {
8341 element.removeEventListener("focusin", onFocus, true);
8342 markSafariFocusAncestor(focusableContainer, false);
8343 if (receivedFocus) return;
8344 focusIfNeeded(element);
8345 });
8346 });
8347 const handleFocusVisible = (event, currentTarget) => {
8348 if (currentTarget) {
8349 event.currentTarget = currentTarget;
8350 }
8351 if (!focusable) return;
8352 const element = event.currentTarget;
8353 if (!element) return;
8354 if (!hasFocus(element)) return;
8355 onFocusVisible == null ? void 0 : onFocusVisible(event);
8356 if (event.defaultPrevented) return;
8357 element.dataset.focusVisible = "true";
8358 setFocusVisible(true);
8359 };
8360 const onKeyDownCaptureProp = props.onKeyDownCapture;
8361 const onKeyDownCapture = useEvent((event) => {
8362 onKeyDownCaptureProp == null ? void 0 : onKeyDownCaptureProp(event);
8363 if (event.defaultPrevented) return;
8364 if (!focusable) return;
8365 if (focusVisible) return;
8366 if (event.metaKey) return;
8367 if (event.altKey) return;
8368 if (event.ctrlKey) return;
8369 if (!isSelfTarget(event)) return;
8370 const element = event.currentTarget;
8371 const applyFocusVisible = () => handleFocusVisible(event, element);
8372 queueBeforeEvent(element, "focusout", applyFocusVisible);
8373 });
8374 const onFocusCaptureProp = props.onFocusCapture;
8375 const onFocusCapture = useEvent((event) => {
8376 onFocusCaptureProp == null ? void 0 : onFocusCaptureProp(event);
8377 if (event.defaultPrevented) return;
8378 if (!focusable) return;
8379 if (!isSelfTarget(event)) {
8380 setFocusVisible(false);
8381 return;
8382 }
8383 const element = event.currentTarget;
8384 const applyFocusVisible = () => handleFocusVisible(event, element);
8385 if (isKeyboardModality || isAlwaysFocusVisible(event.target)) {
8386 queueBeforeEvent(event.target, "focusout", applyFocusVisible);
8387 } else {
8388 setFocusVisible(false);
8389 }
8390 });
8391 const onBlurProp = props.onBlur;
8392 const onBlur = useEvent((event) => {
8393 onBlurProp == null ? void 0 : onBlurProp(event);
8394 if (!focusable) return;
8395 if (!isFocusEventOutside(event)) return;
8396 setFocusVisible(false);
8397 });
8398 const autoFocusOnShow = (0, import_react11.useContext)(FocusableContext);
8399 const autoFocusRef = useEvent((element) => {
8400 if (!focusable) return;
8401 if (!autoFocus) return;
8402 if (!element) return;
8403 if (!autoFocusOnShow) return;
8404 queueMicrotask(() => {
8405 if (hasFocus(element)) return;
8406 if (!isFocusable(element)) return;
8407 element.focus();
8408 });
8409 });
8410 const tagName = useTagName(ref);
8411 const nativeTabbable = focusable && isNativeTabbable(tagName);
8412 const supportsDisabled = focusable && supportsDisabledAttribute(tagName);
8413 const styleProp = props.style;
8414 const style = (0, import_react11.useMemo)(() => {
8415 if (trulyDisabled) {
8416 return __spreadValues({ pointerEvents: "none" }, styleProp);
8417 }
8418 return styleProp;
8419 }, [trulyDisabled, styleProp]);
8420 props = __spreadProps(__spreadValues({
8421 "data-focus-visible": focusable && focusVisible || void 0,
8422 "data-autofocus": autoFocus || void 0,
8423 "aria-disabled": disabled || void 0
8424 }, props), {
8425 ref: useMergeRefs(ref, autoFocusRef, props.ref),
8426 style,
8427 tabIndex: getTabIndex(
8428 focusable,
8429 trulyDisabled,
8430 nativeTabbable,
8431 supportsDisabled,
8432 props.tabIndex
8433 ),
8434 disabled: supportsDisabled && trulyDisabled ? true : void 0,
8435 // TODO: Test Focusable contentEditable.
8436 contentEditable: disabled ? void 0 : props.contentEditable,
8437 onKeyPressCapture,
8438 onClickCapture,
8439 onMouseDownCapture,
8440 onMouseDown,
8441 onKeyDownCapture,
8442 onFocusCapture,
8443 onBlur
8444 });
8445 return removeUndefinedValues(props);
8446 }
8447 );
8448 var Focusable = forwardRef22(function Focusable2(props) {
8449 const htmlProps = useFocusable(props);
8450 return createElement3(TagName2, htmlProps);
8451 });
8452
8453 // node_modules/@ariakit/react-core/esm/__chunks/ITI7HKP4.js
8454 var import_react12 = __toESM(require_react(), 1);
8455 var import_jsx_runtime53 = __toESM(require_jsx_runtime(), 1);
8456 var TagName3 = "div";
8457 function isGrid(items) {
8458 return items.some((item) => !!item.rowId);
8459 }
8460 function isPrintableKey(event) {
8461 const target = event.target;
8462 if (target && !isTextField(target)) return false;
8463 return event.key.length === 1 && !event.ctrlKey && !event.metaKey;
8464 }
8465 function isModifierKey(event) {
8466 return event.key === "Shift" || event.key === "Control" || event.key === "Alt" || event.key === "Meta";
8467 }
8468 function useKeyboardEventProxy(store, onKeyboardEvent, previousElementRef) {
8469 return useEvent((event) => {
8470 var _a;
8471 onKeyboardEvent == null ? void 0 : onKeyboardEvent(event);
8472 if (event.defaultPrevented) return;
8473 if (event.isPropagationStopped()) return;
8474 if (!isSelfTarget(event)) return;
8475 if (isModifierKey(event)) return;
8476 if (isPrintableKey(event)) return;
8477 const state = store.getState();
8478 const activeElement = (_a = getEnabledItem(store, state.activeId)) == null ? void 0 : _a.element;
8479 if (!activeElement) return;
8480 const _b = event, { view } = _b, eventInit = __objRest(_b, ["view"]);
8481 const previousElement = previousElementRef == null ? void 0 : previousElementRef.current;
8482 if (activeElement !== previousElement) {
8483 activeElement.focus();
8484 }
8485 if (!fireKeyboardEvent(activeElement, event.type, eventInit)) {
8486 event.preventDefault();
8487 }
8488 if (event.currentTarget.contains(activeElement)) {
8489 event.stopPropagation();
8490 }
8491 });
8492 }
8493 function findFirstEnabledItemInTheLastRow(items) {
8494 return findFirstEnabledItem2(
8495 flatten2DArray(reverseArray(groupItemsByRows2(items)))
8496 );
8497 }
8498 function useScheduleFocus(store) {
8499 const [scheduled, setScheduled] = (0, import_react12.useState)(false);
8500 const schedule = (0, import_react12.useCallback)(() => setScheduled(true), []);
8501 const activeItem = store.useState(
8502 (state) => getEnabledItem(store, state.activeId)
8503 );
8504 (0, import_react12.useEffect)(() => {
8505 const activeElement = activeItem == null ? void 0 : activeItem.element;
8506 if (!scheduled) return;
8507 if (!activeElement) return;
8508 setScheduled(false);
8509 activeElement.focus({ preventScroll: true });
8510 }, [activeItem, scheduled]);
8511 return schedule;
8512 }
8513 var useComposite = createHook(
8514 function useComposite2(_a) {
8515 var _b = _a, {
8516 store,
8517 composite = true,
8518 focusOnMove = composite,
8519 moveOnKeyPress = true
8520 } = _b, props = __objRest(_b, [
8521 "store",
8522 "composite",
8523 "focusOnMove",
8524 "moveOnKeyPress"
8525 ]);
8526 const context = useCompositeProviderContext();
8527 store = store || context;
8528 invariant(
8529 store,
8530 "Composite must receive a `store` prop or be wrapped in a CompositeProvider component."
8531 );
8532 const ref = (0, import_react12.useRef)(null);
8533 const previousElementRef = (0, import_react12.useRef)(null);
8534 const scheduleFocus = useScheduleFocus(store);
8535 const moves = store.useState("moves");
8536 const [, setBaseElement] = useTransactionState(
8537 composite ? store.setBaseElement : null
8538 );
8539 (0, import_react12.useEffect)(() => {
8540 var _a2;
8541 if (!store) return;
8542 if (!moves) return;
8543 if (!composite) return;
8544 if (!focusOnMove) return;
8545 const { activeId: activeId2 } = store.getState();
8546 const itemElement = (_a2 = getEnabledItem(store, activeId2)) == null ? void 0 : _a2.element;
8547 if (!itemElement) return;
8548 focusIntoView(itemElement);
8549 }, [store, moves, composite, focusOnMove]);
8550 useSafeLayoutEffect(() => {
8551 if (!store) return;
8552 if (!moves) return;
8553 if (!composite) return;
8554 const { baseElement, activeId: activeId2 } = store.getState();
8555 const isSelfAcive = activeId2 === null;
8556 if (!isSelfAcive) return;
8557 if (!baseElement) return;
8558 const previousElement = previousElementRef.current;
8559 previousElementRef.current = null;
8560 if (previousElement) {
8561 fireBlurEvent(previousElement, { relatedTarget: baseElement });
8562 }
8563 if (!hasFocus(baseElement)) {
8564 baseElement.focus();
8565 }
8566 }, [store, moves, composite]);
8567 const activeId = store.useState("activeId");
8568 const virtualFocus = store.useState("virtualFocus");
8569 useSafeLayoutEffect(() => {
8570 var _a2;
8571 if (!store) return;
8572 if (!composite) return;
8573 if (!virtualFocus) return;
8574 const previousElement = previousElementRef.current;
8575 previousElementRef.current = null;
8576 if (!previousElement) return;
8577 const activeElement = (_a2 = getEnabledItem(store, activeId)) == null ? void 0 : _a2.element;
8578 const relatedTarget = activeElement || getActiveElement(previousElement);
8579 if (relatedTarget === previousElement) return;
8580 fireBlurEvent(previousElement, { relatedTarget });
8581 }, [store, activeId, virtualFocus, composite]);
8582 const onKeyDownCapture = useKeyboardEventProxy(
8583 store,
8584 props.onKeyDownCapture,
8585 previousElementRef
8586 );
8587 const onKeyUpCapture = useKeyboardEventProxy(
8588 store,
8589 props.onKeyUpCapture,
8590 previousElementRef
8591 );
8592 const onFocusCaptureProp = props.onFocusCapture;
8593 const onFocusCapture = useEvent((event) => {
8594 onFocusCaptureProp == null ? void 0 : onFocusCaptureProp(event);
8595 if (event.defaultPrevented) return;
8596 if (!store) return;
8597 const { virtualFocus: virtualFocus2 } = store.getState();
8598 if (!virtualFocus2) return;
8599 const previousActiveElement = event.relatedTarget;
8600 const isSilentlyFocused = silentlyFocused(event.currentTarget);
8601 if (isSelfTarget(event) && isSilentlyFocused) {
8602 event.stopPropagation();
8603 previousElementRef.current = previousActiveElement;
8604 }
8605 });
8606 const onFocusProp = props.onFocus;
8607 const onFocus = useEvent((event) => {
8608 onFocusProp == null ? void 0 : onFocusProp(event);
8609 if (event.defaultPrevented) return;
8610 if (!composite) return;
8611 if (!store) return;
8612 const { relatedTarget } = event;
8613 const { virtualFocus: virtualFocus2 } = store.getState();
8614 if (virtualFocus2) {
8615 if (isSelfTarget(event) && !isItem(store, relatedTarget)) {
8616 queueMicrotask(scheduleFocus);
8617 }
8618 } else if (isSelfTarget(event)) {
8619 store.setActiveId(null);
8620 }
8621 });
8622 const onBlurCaptureProp = props.onBlurCapture;
8623 const onBlurCapture = useEvent((event) => {
8624 var _a2;
8625 onBlurCaptureProp == null ? void 0 : onBlurCaptureProp(event);
8626 if (event.defaultPrevented) return;
8627 if (!store) return;
8628 const { virtualFocus: virtualFocus2, activeId: activeId2 } = store.getState();
8629 if (!virtualFocus2) return;
8630 const activeElement = (_a2 = getEnabledItem(store, activeId2)) == null ? void 0 : _a2.element;
8631 const nextActiveElement = event.relatedTarget;
8632 const nextActiveElementIsItem = isItem(store, nextActiveElement);
8633 const previousElement = previousElementRef.current;
8634 previousElementRef.current = null;
8635 if (isSelfTarget(event) && nextActiveElementIsItem) {
8636 if (nextActiveElement === activeElement) {
8637 if (previousElement && previousElement !== nextActiveElement) {
8638 fireBlurEvent(previousElement, event);
8639 }
8640 } else if (activeElement) {
8641 fireBlurEvent(activeElement, event);
8642 } else if (previousElement) {
8643 fireBlurEvent(previousElement, event);
8644 }
8645 event.stopPropagation();
8646 } else {
8647 const targetIsItem = isItem(store, event.target);
8648 if (!targetIsItem && activeElement) {
8649 fireBlurEvent(activeElement, event);
8650 }
8651 }
8652 });
8653 const onKeyDownProp = props.onKeyDown;
8654 const moveOnKeyPressProp = useBooleanEvent(moveOnKeyPress);
8655 const onKeyDown = useEvent((event) => {
8656 var _a2;
8657 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
8658 if (event.defaultPrevented) return;
8659 if (!store) return;
8660 if (!isSelfTarget(event)) return;
8661 const { orientation, renderedItems, activeId: activeId2 } = store.getState();
8662 const activeItem = getEnabledItem(store, activeId2);
8663 if ((_a2 = activeItem == null ? void 0 : activeItem.element) == null ? void 0 : _a2.isConnected) return;
8664 const isVertical = orientation !== "horizontal";
8665 const isHorizontal = orientation !== "vertical";
8666 const grid = isGrid(renderedItems);
8667 const isHorizontalKey = event.key === "ArrowLeft" || event.key === "ArrowRight" || event.key === "Home" || event.key === "End";
8668 if (isHorizontalKey && isTextField(event.currentTarget)) return;
8669 const up = () => {
8670 if (grid) {
8671 const item = findFirstEnabledItemInTheLastRow(renderedItems);
8672 return item == null ? void 0 : item.id;
8673 }
8674 return store == null ? void 0 : store.last();
8675 };
8676 const keyMap = {
8677 ArrowUp: (grid || isVertical) && up,
8678 ArrowRight: (grid || isHorizontal) && store.first,
8679 ArrowDown: (grid || isVertical) && store.first,
8680 ArrowLeft: (grid || isHorizontal) && store.last,
8681 Home: store.first,
8682 End: store.last,
8683 PageUp: store.first,
8684 PageDown: store.last
8685 };
8686 const action = keyMap[event.key];
8687 if (action) {
8688 const id = action();
8689 if (id !== void 0) {
8690 if (!moveOnKeyPressProp(event)) return;
8691 event.preventDefault();
8692 store.move(id);
8693 }
8694 }
8695 });
8696 props = useWrapElement(
8697 props,
8698 (element) => /* @__PURE__ */ (0, import_jsx_runtime53.jsx)(CompositeContextProvider, { value: store, children: element }),
8699 [store]
8700 );
8701 const activeDescendant = store.useState((state) => {
8702 var _a2;
8703 if (!store) return;
8704 if (!composite) return;
8705 if (!state.virtualFocus) return;
8706 return (_a2 = getEnabledItem(store, state.activeId)) == null ? void 0 : _a2.id;
8707 });
8708 props = __spreadProps(__spreadValues({
8709 "aria-activedescendant": activeDescendant
8710 }, props), {
8711 ref: useMergeRefs(ref, setBaseElement, props.ref),
8712 onKeyDownCapture,
8713 onKeyUpCapture,
8714 onFocusCapture,
8715 onFocus,
8716 onBlurCapture,
8717 onKeyDown
8718 });
8719 const focusable = store.useState(
8720 (state) => composite && (state.virtualFocus || state.activeId === null)
8721 );
8722 props = useFocusable(__spreadValues({ focusable }, props));
8723 return props;
8724 }
8725 );
8726 var Composite5 = forwardRef22(function Composite22(props) {
8727 const htmlProps = useComposite(props);
8728 return createElement3(TagName3, htmlProps);
8729 });
8730
8731 // node_modules/@ariakit/react-core/esm/combobox/combobox.js
8732 var import_react13 = __toESM(require_react(), 1);
8733 var TagName4 = "input";
8734 function isFirstItemAutoSelected(items, activeValue, autoSelect) {
8735 if (!autoSelect) return false;
8736 const firstItem = items.find((item) => !item.disabled && item.value);
8737 return (firstItem == null ? void 0 : firstItem.value) === activeValue;
8738 }
8739 function hasCompletionString(value, activeValue) {
8740 if (!activeValue) return false;
8741 if (value == null) return false;
8742 value = normalizeString(value);
8743 return activeValue.length > value.length && activeValue.toLowerCase().indexOf(value.toLowerCase()) === 0;
8744 }
8745 function isInputEvent(event) {
8746 return event.type === "input";
8747 }
8748 function isAriaAutoCompleteValue(value) {
8749 return value === "inline" || value === "list" || value === "both" || value === "none";
8750 }
8751 function getDefaultAutoSelectId(items) {
8752 const item = items.find((item2) => {
8753 var _a;
8754 if (item2.disabled) return false;
8755 return ((_a = item2.element) == null ? void 0 : _a.getAttribute("role")) !== "tab";
8756 });
8757 return item == null ? void 0 : item.id;
8758 }
8759 var useCombobox = createHook(
8760 function useCombobox2(_a) {
8761 var _b = _a, {
8762 store,
8763 focusable = true,
8764 autoSelect: autoSelectProp = false,
8765 getAutoSelectId,
8766 setValueOnChange,
8767 showMinLength = 0,
8768 showOnChange,
8769 showOnMouseDown,
8770 showOnClick = showOnMouseDown,
8771 showOnKeyDown,
8772 showOnKeyPress = showOnKeyDown,
8773 blurActiveItemOnClick,
8774 setValueOnClick = true,
8775 moveOnKeyPress = true,
8776 autoComplete = "list"
8777 } = _b, props = __objRest(_b, [
8778 "store",
8779 "focusable",
8780 "autoSelect",
8781 "getAutoSelectId",
8782 "setValueOnChange",
8783 "showMinLength",
8784 "showOnChange",
8785 "showOnMouseDown",
8786 "showOnClick",
8787 "showOnKeyDown",
8788 "showOnKeyPress",
8789 "blurActiveItemOnClick",
8790 "setValueOnClick",
8791 "moveOnKeyPress",
8792 "autoComplete"
8793 ]);
8794 const context = useComboboxProviderContext();
8795 store = store || context;
8796 invariant(
8797 store,
8798 "Combobox must receive a `store` prop or be wrapped in a ComboboxProvider component."
8799 );
8800 const ref = (0, import_react13.useRef)(null);
8801 const [valueUpdated, forceValueUpdate] = useForceUpdate();
8802 const canAutoSelectRef = (0, import_react13.useRef)(false);
8803 const composingRef = (0, import_react13.useRef)(false);
8804 const autoSelect = store.useState(
8805 (state) => state.virtualFocus && autoSelectProp
8806 );
8807 const inline = autoComplete === "inline" || autoComplete === "both";
8808 const [canInline, setCanInline] = (0, import_react13.useState)(inline);
8809 useUpdateLayoutEffect(() => {
8810 if (!inline) return;
8811 setCanInline(true);
8812 }, [inline]);
8813 const storeValue = store.useState("value");
8814 const prevSelectedValueRef = (0, import_react13.useRef)();
8815 (0, import_react13.useEffect)(() => {
8816 return sync(store, ["selectedValue", "activeId"], (_, prev) => {
8817 prevSelectedValueRef.current = prev.selectedValue;
8818 });
8819 }, []);
8820 const inlineActiveValue = store.useState((state) => {
8821 var _a2;
8822 if (!inline) return;
8823 if (!canInline) return;
8824 if (state.activeValue && Array.isArray(state.selectedValue)) {
8825 if (state.selectedValue.includes(state.activeValue)) return;
8826 if ((_a2 = prevSelectedValueRef.current) == null ? void 0 : _a2.includes(state.activeValue)) return;
8827 }
8828 return state.activeValue;
8829 });
8830 const items = store.useState("renderedItems");
8831 const open = store.useState("open");
8832 const contentElement = store.useState("contentElement");
8833 const value = (0, import_react13.useMemo)(() => {
8834 if (!inline) return storeValue;
8835 if (!canInline) return storeValue;
8836 const firstItemAutoSelected = isFirstItemAutoSelected(
8837 items,
8838 inlineActiveValue,
8839 autoSelect
8840 );
8841 if (firstItemAutoSelected) {
8842 if (hasCompletionString(storeValue, inlineActiveValue)) {
8843 const slice = (inlineActiveValue == null ? void 0 : inlineActiveValue.slice(storeValue.length)) || "";
8844 return storeValue + slice;
8845 }
8846 return storeValue;
8847 }
8848 return inlineActiveValue || storeValue;
8849 }, [inline, canInline, items, inlineActiveValue, autoSelect, storeValue]);
8850 (0, import_react13.useEffect)(() => {
8851 const element = ref.current;
8852 if (!element) return;
8853 const onCompositeItemMove = () => setCanInline(true);
8854 element.addEventListener("combobox-item-move", onCompositeItemMove);
8855 return () => {
8856 element.removeEventListener("combobox-item-move", onCompositeItemMove);
8857 };
8858 }, []);
8859 (0, import_react13.useEffect)(() => {
8860 if (!inline) return;
8861 if (!canInline) return;
8862 if (!inlineActiveValue) return;
8863 const firstItemAutoSelected = isFirstItemAutoSelected(
8864 items,
8865 inlineActiveValue,
8866 autoSelect
8867 );
8868 if (!firstItemAutoSelected) return;
8869 if (!hasCompletionString(storeValue, inlineActiveValue)) return;
8870 let cleanup = noop2;
8871 queueMicrotask(() => {
8872 const element = ref.current;
8873 if (!element) return;
8874 const { start: prevStart, end: prevEnd } = getTextboxSelection(element);
8875 const nextStart = storeValue.length;
8876 const nextEnd = inlineActiveValue.length;
8877 setSelectionRange(element, nextStart, nextEnd);
8878 cleanup = () => {
8879 if (!hasFocus(element)) return;
8880 const { start, end } = getTextboxSelection(element);
8881 if (start !== nextStart) return;
8882 if (end !== nextEnd) return;
8883 setSelectionRange(element, prevStart, prevEnd);
8884 };
8885 });
8886 return () => cleanup();
8887 }, [
8888 valueUpdated,
8889 inline,
8890 canInline,
8891 inlineActiveValue,
8892 items,
8893 autoSelect,
8894 storeValue
8895 ]);
8896 const scrollingElementRef = (0, import_react13.useRef)(null);
8897 const getAutoSelectIdProp = useEvent(getAutoSelectId);
8898 const autoSelectIdRef = (0, import_react13.useRef)(null);
8899 (0, import_react13.useEffect)(() => {
8900 if (!open) return;
8901 if (!contentElement) return;
8902 const scrollingElement = getScrollingElement(contentElement);
8903 if (!scrollingElement) return;
8904 scrollingElementRef.current = scrollingElement;
8905 const onUserScroll = () => {
8906 canAutoSelectRef.current = false;
8907 };
8908 const onScroll = () => {
8909 if (!store) return;
8910 if (!canAutoSelectRef.current) return;
8911 const { activeId } = store.getState();
8912 if (activeId === null) return;
8913 if (activeId === autoSelectIdRef.current) return;
8914 canAutoSelectRef.current = false;
8915 };
8916 const options = { passive: true, capture: true };
8917 scrollingElement.addEventListener("wheel", onUserScroll, options);
8918 scrollingElement.addEventListener("touchmove", onUserScroll, options);
8919 scrollingElement.addEventListener("scroll", onScroll, options);
8920 return () => {
8921 scrollingElement.removeEventListener("wheel", onUserScroll, true);
8922 scrollingElement.removeEventListener("touchmove", onUserScroll, true);
8923 scrollingElement.removeEventListener("scroll", onScroll, true);
8924 };
8925 }, [open, contentElement, store]);
8926 useSafeLayoutEffect(() => {
8927 if (!storeValue) return;
8928 if (composingRef.current) return;
8929 canAutoSelectRef.current = true;
8930 }, [storeValue]);
8931 useSafeLayoutEffect(() => {
8932 if (autoSelect !== "always" && open) return;
8933 canAutoSelectRef.current = open;
8934 }, [autoSelect, open]);
8935 const resetValueOnSelect = store.useState("resetValueOnSelect");
8936 useUpdateEffect(() => {
8937 var _a2, _b2;
8938 const canAutoSelect = canAutoSelectRef.current;
8939 if (!store) return;
8940 if (!open) return;
8941 if (!canAutoSelect && !resetValueOnSelect) return;
8942 const { baseElement, contentElement: contentElement2, activeId } = store.getState();
8943 if (baseElement && !hasFocus(baseElement)) return;
8944 if (contentElement2 == null ? void 0 : contentElement2.hasAttribute("data-placing")) {
8945 const observer = new MutationObserver(forceValueUpdate);
8946 observer.observe(contentElement2, { attributeFilter: ["data-placing"] });
8947 return () => observer.disconnect();
8948 }
8949 if (autoSelect && canAutoSelect) {
8950 const userAutoSelectId = getAutoSelectIdProp(items);
8951 const autoSelectId = userAutoSelectId !== void 0 ? userAutoSelectId : (_a2 = getDefaultAutoSelectId(items)) != null ? _a2 : store.first();
8952 autoSelectIdRef.current = autoSelectId;
8953 store.move(autoSelectId != null ? autoSelectId : null);
8954 } else {
8955 const element = (_b2 = store.item(activeId || store.first())) == null ? void 0 : _b2.element;
8956 if (element && "scrollIntoView" in element) {
8957 element.scrollIntoView({ block: "nearest", inline: "nearest" });
8958 }
8959 }
8960 return;
8961 }, [
8962 store,
8963 open,
8964 valueUpdated,
8965 storeValue,
8966 autoSelect,
8967 resetValueOnSelect,
8968 getAutoSelectIdProp,
8969 items
8970 ]);
8971 (0, import_react13.useEffect)(() => {
8972 if (!inline) return;
8973 const combobox = ref.current;
8974 if (!combobox) return;
8975 const elements = [combobox, contentElement].filter(
8976 (value2) => !!value2
8977 );
8978 const onBlur2 = (event) => {
8979 if (elements.every((el) => isFocusEventOutside(event, el))) {
8980 store == null ? void 0 : store.setValue(value);
8981 }
8982 };
8983 for (const element of elements) {
8984 element.addEventListener("focusout", onBlur2);
8985 }
8986 return () => {
8987 for (const element of elements) {
8988 element.removeEventListener("focusout", onBlur2);
8989 }
8990 };
8991 }, [inline, contentElement, store, value]);
8992 const canShow = (event) => {
8993 const currentTarget = event.currentTarget;
8994 return currentTarget.value.length >= showMinLength;
8995 };
8996 const onChangeProp = props.onChange;
8997 const showOnChangeProp = useBooleanEvent(showOnChange != null ? showOnChange : canShow);
8998 const setValueOnChangeProp = useBooleanEvent(
8999 // If the combobox is combined with tags, the value will be set by the tag
9000 // input component.
9001 setValueOnChange != null ? setValueOnChange : !store.tag
9002 );
9003 const onChange = useEvent((event) => {
9004 onChangeProp == null ? void 0 : onChangeProp(event);
9005 if (event.defaultPrevented) return;
9006 if (!store) return;
9007 const currentTarget = event.currentTarget;
9008 const { value: value2, selectionStart, selectionEnd } = currentTarget;
9009 const nativeEvent = event.nativeEvent;
9010 canAutoSelectRef.current = true;
9011 if (isInputEvent(nativeEvent)) {
9012 if (nativeEvent.isComposing) {
9013 canAutoSelectRef.current = false;
9014 composingRef.current = true;
9015 }
9016 if (inline) {
9017 const textInserted = nativeEvent.inputType === "insertText" || nativeEvent.inputType === "insertCompositionText";
9018 const caretAtEnd = selectionStart === value2.length;
9019 setCanInline(textInserted && caretAtEnd);
9020 }
9021 }
9022 if (setValueOnChangeProp(event)) {
9023 const isSameValue = value2 === store.getState().value;
9024 store.setValue(value2);
9025 queueMicrotask(() => {
9026 setSelectionRange(currentTarget, selectionStart, selectionEnd);
9027 });
9028 if (inline && autoSelect && isSameValue) {
9029 forceValueUpdate();
9030 }
9031 }
9032 if (showOnChangeProp(event)) {
9033 store.show();
9034 }
9035 if (!autoSelect || !canAutoSelectRef.current) {
9036 store.setActiveId(null);
9037 }
9038 });
9039 const onCompositionEndProp = props.onCompositionEnd;
9040 const onCompositionEnd = useEvent((event) => {
9041 canAutoSelectRef.current = true;
9042 composingRef.current = false;
9043 onCompositionEndProp == null ? void 0 : onCompositionEndProp(event);
9044 if (event.defaultPrevented) return;
9045 if (!autoSelect) return;
9046 forceValueUpdate();
9047 });
9048 const onMouseDownProp = props.onMouseDown;
9049 const blurActiveItemOnClickProp = useBooleanEvent(
9050 blurActiveItemOnClick != null ? blurActiveItemOnClick : () => !!(store == null ? void 0 : store.getState().includesBaseElement)
9051 );
9052 const setValueOnClickProp = useBooleanEvent(setValueOnClick);
9053 const showOnClickProp = useBooleanEvent(showOnClick != null ? showOnClick : canShow);
9054 const onMouseDown = useEvent((event) => {
9055 onMouseDownProp == null ? void 0 : onMouseDownProp(event);
9056 if (event.defaultPrevented) return;
9057 if (event.button) return;
9058 if (event.ctrlKey) return;
9059 if (!store) return;
9060 if (blurActiveItemOnClickProp(event)) {
9061 store.setActiveId(null);
9062 }
9063 if (setValueOnClickProp(event)) {
9064 store.setValue(value);
9065 }
9066 if (showOnClickProp(event)) {
9067 queueBeforeEvent(event.currentTarget, "mouseup", store.show);
9068 }
9069 });
9070 const onKeyDownProp = props.onKeyDown;
9071 const showOnKeyPressProp = useBooleanEvent(showOnKeyPress != null ? showOnKeyPress : canShow);
9072 const onKeyDown = useEvent((event) => {
9073 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
9074 if (!event.repeat) {
9075 canAutoSelectRef.current = false;
9076 }
9077 if (event.defaultPrevented) return;
9078 if (event.ctrlKey) return;
9079 if (event.altKey) return;
9080 if (event.shiftKey) return;
9081 if (event.metaKey) return;
9082 if (!store) return;
9083 const { open: open2 } = store.getState();
9084 if (open2) return;
9085 if (event.key === "ArrowUp" || event.key === "ArrowDown") {
9086 if (showOnKeyPressProp(event)) {
9087 event.preventDefault();
9088 store.show();
9089 }
9090 }
9091 });
9092 const onBlurProp = props.onBlur;
9093 const onBlur = useEvent((event) => {
9094 canAutoSelectRef.current = false;
9095 onBlurProp == null ? void 0 : onBlurProp(event);
9096 if (event.defaultPrevented) return;
9097 });
9098 const id = useId3(props.id);
9099 const ariaAutoComplete = isAriaAutoCompleteValue(autoComplete) ? autoComplete : void 0;
9100 const isActiveItem = store.useState((state) => state.activeId === null);
9101 props = __spreadProps(__spreadValues({
9102 id,
9103 role: "combobox",
9104 "aria-autocomplete": ariaAutoComplete,
9105 "aria-haspopup": getPopupRole(contentElement, "listbox"),
9106 "aria-expanded": open,
9107 "aria-controls": contentElement == null ? void 0 : contentElement.id,
9108 "data-active-item": isActiveItem || void 0,
9109 value
9110 }, props), {
9111 ref: useMergeRefs(ref, props.ref),
9112 onChange,
9113 onCompositionEnd,
9114 onMouseDown,
9115 onKeyDown,
9116 onBlur
9117 });
9118 props = useComposite(__spreadProps(__spreadValues({
9119 store,
9120 focusable
9121 }, props), {
9122 // Enable inline autocomplete when the user moves from the combobox input
9123 // to an item.
9124 moveOnKeyPress: (event) => {
9125 if (isFalsyBooleanCallback(moveOnKeyPress, event)) return false;
9126 if (inline) setCanInline(true);
9127 return true;
9128 }
9129 }));
9130 props = usePopoverAnchor(__spreadValues({ store }, props));
9131 return __spreadValues({ autoComplete: "off" }, props);
9132 }
9133 );
9134 var Combobox = forwardRef22(function Combobox2(props) {
9135 const htmlProps = useCombobox(props);
9136 return createElement3(TagName4, htmlProps);
9137 });
9138
9139 // node_modules/@ariakit/react-core/esm/combobox/combobox-provider.js
9140 var import_jsx_runtime54 = __toESM(require_jsx_runtime(), 1);
9141 function ComboboxProvider(props = {}) {
9142 const store = useComboboxStore(props);
9143 return /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(ComboboxContextProvider, { value: store, children: props.children });
9144 }
9145
9146 // node_modules/@ariakit/react-core/esm/__chunks/KUU7WJ55.js
9147 var import_react14 = __toESM(require_react(), 1);
9148 var TagName5 = "button";
9149 function isNativeClick(event) {
9150 if (!event.isTrusted) return false;
9151 const element = event.currentTarget;
9152 if (event.key === "Enter") {
9153 return isButton(element) || element.tagName === "SUMMARY" || element.tagName === "A";
9154 }
9155 if (event.key === " ") {
9156 return isButton(element) || element.tagName === "SUMMARY" || element.tagName === "INPUT" || element.tagName === "SELECT";
9157 }
9158 return false;
9159 }
9160 var symbol = /* @__PURE__ */ Symbol("command");
9161 var useCommand = createHook(
9162 function useCommand2(_a) {
9163 var _b = _a, { clickOnEnter = true, clickOnSpace = true } = _b, props = __objRest(_b, ["clickOnEnter", "clickOnSpace"]);
9164 const ref = (0, import_react14.useRef)(null);
9165 const [isNativeButton, setIsNativeButton] = (0, import_react14.useState)(false);
9166 (0, import_react14.useEffect)(() => {
9167 if (!ref.current) return;
9168 setIsNativeButton(isButton(ref.current));
9169 }, []);
9170 const [active, setActive] = (0, import_react14.useState)(false);
9171 const activeRef = (0, import_react14.useRef)(false);
9172 const disabled = disabledFromProps(props);
9173 const [isDuplicate, metadataProps] = useMetadataProps(props, symbol, true);
9174 const onKeyDownProp = props.onKeyDown;
9175 const onKeyDown = useEvent((event) => {
9176 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
9177 const element = event.currentTarget;
9178 if (event.defaultPrevented) return;
9179 if (isDuplicate) return;
9180 if (disabled) return;
9181 if (!isSelfTarget(event)) return;
9182 if (isTextField(element)) return;
9183 if (element.isContentEditable) return;
9184 const isEnter = clickOnEnter && event.key === "Enter";
9185 const isSpace = clickOnSpace && event.key === " ";
9186 const shouldPreventEnter = event.key === "Enter" && !clickOnEnter;
9187 const shouldPreventSpace = event.key === " " && !clickOnSpace;
9188 if (shouldPreventEnter || shouldPreventSpace) {
9189 event.preventDefault();
9190 return;
9191 }
9192 if (isEnter || isSpace) {
9193 const nativeClick = isNativeClick(event);
9194 if (isEnter) {
9195 if (!nativeClick) {
9196 event.preventDefault();
9197 const _a2 = event, { view } = _a2, eventInit = __objRest(_a2, ["view"]);
9198 const click = () => fireClickEvent(element, eventInit);
9199 if (isFirefox()) {
9200 queueBeforeEvent(element, "keyup", click);
9201 } else {
9202 queueMicrotask(click);
9203 }
9204 }
9205 } else if (isSpace) {
9206 activeRef.current = true;
9207 if (!nativeClick) {
9208 event.preventDefault();
9209 setActive(true);
9210 }
9211 }
9212 }
9213 });
9214 const onKeyUpProp = props.onKeyUp;
9215 const onKeyUp = useEvent((event) => {
9216 onKeyUpProp == null ? void 0 : onKeyUpProp(event);
9217 if (event.defaultPrevented) return;
9218 if (isDuplicate) return;
9219 if (disabled) return;
9220 if (event.metaKey) return;
9221 const isSpace = clickOnSpace && event.key === " ";
9222 if (activeRef.current && isSpace) {
9223 activeRef.current = false;
9224 if (!isNativeClick(event)) {
9225 event.preventDefault();
9226 setActive(false);
9227 const element = event.currentTarget;
9228 const _a2 = event, { view } = _a2, eventInit = __objRest(_a2, ["view"]);
9229 queueMicrotask(() => fireClickEvent(element, eventInit));
9230 }
9231 }
9232 });
9233 props = __spreadProps(__spreadValues(__spreadValues({
9234 "data-active": active || void 0,
9235 type: isNativeButton ? "button" : void 0
9236 }, metadataProps), props), {
9237 ref: useMergeRefs(ref, props.ref),
9238 onKeyDown,
9239 onKeyUp
9240 });
9241 props = useFocusable(props);
9242 return props;
9243 }
9244 );
9245 var Command = forwardRef22(function Command2(props) {
9246 const htmlProps = useCommand(props);
9247 return createElement3(TagName5, htmlProps);
9248 });
9249
9250 // node_modules/@ariakit/react-core/esm/combobox/combobox-item-value.js
9251 var import_react15 = __toESM(require_react(), 1);
9252 var import_jsx_runtime55 = __toESM(require_jsx_runtime(), 1);
9253 var TagName6 = "span";
9254 function normalizeValue(value) {
9255 return normalizeString(value).toLowerCase();
9256 }
9257 function getOffsets(string, values) {
9258 const offsets = [];
9259 for (const value of values) {
9260 let pos = 0;
9261 const length = value.length;
9262 while (string.indexOf(value, pos) !== -1) {
9263 const index = string.indexOf(value, pos);
9264 if (index !== -1) {
9265 offsets.push([index, length]);
9266 }
9267 pos = index + 1;
9268 }
9269 }
9270 return offsets;
9271 }
9272 function filterOverlappingOffsets(offsets) {
9273 return offsets.filter(([offset, length], i2, arr) => {
9274 return !arr.some(
9275 ([o2, l2], j2) => j2 !== i2 && o2 <= offset && o2 + l2 >= offset + length
9276 );
9277 });
9278 }
9279 function sortOffsets(offsets) {
9280 return offsets.sort(([a2], [b2]) => a2 - b2);
9281 }
9282 function splitValue(itemValue, userValue) {
9283 if (!itemValue) return itemValue;
9284 if (!userValue) return itemValue;
9285 const userValues = toArray(userValue).filter(Boolean).map(normalizeValue);
9286 const parts = [];
9287 const span = (value, autocomplete = false) => /* @__PURE__ */ (0, import_jsx_runtime55.jsx)(
9288 "span",
9289 {
9290 "data-autocomplete-value": autocomplete ? "" : void 0,
9291 "data-user-value": autocomplete ? void 0 : "",
9292 children: value
9293 },
9294 parts.length
9295 );
9296 const offsets = sortOffsets(
9297 filterOverlappingOffsets(
9298 // Convert userValues into a set to avoid duplicates
9299 getOffsets(normalizeValue(itemValue), new Set(userValues))
9300 )
9301 );
9302 if (!offsets.length) {
9303 parts.push(span(itemValue, true));
9304 return parts;
9305 }
9306 const [firstOffset] = offsets[0];
9307 const values = [
9308 itemValue.slice(0, firstOffset),
9309 ...offsets.flatMap(([offset, length], i2) => {
9310 var _a;
9311 const value = itemValue.slice(offset, offset + length);
9312 const nextOffset = (_a = offsets[i2 + 1]) == null ? void 0 : _a[0];
9313 const nextValue = itemValue.slice(offset + length, nextOffset);
9314 return [value, nextValue];
9315 })
9316 ];
9317 values.forEach((value, i2) => {
9318 if (!value) return;
9319 parts.push(span(value, i2 % 2 === 0));
9320 });
9321 return parts;
9322 }
9323 var useComboboxItemValue = createHook(function useComboboxItemValue2(_a) {
9324 var _b = _a, { store, value, userValue } = _b, props = __objRest(_b, ["store", "value", "userValue"]);
9325 const context = useComboboxScopedContext();
9326 store = store || context;
9327 const itemContext = (0, import_react15.useContext)(ComboboxItemValueContext);
9328 const itemValue = value != null ? value : itemContext;
9329 const inputValue = useStoreState(store, (state) => userValue != null ? userValue : state == null ? void 0 : state.value);
9330 const children = (0, import_react15.useMemo)(() => {
9331 if (!itemValue) return;
9332 if (!inputValue) return itemValue;
9333 return splitValue(itemValue, inputValue);
9334 }, [itemValue, inputValue]);
9335 props = __spreadValues({
9336 children
9337 }, props);
9338 return removeUndefinedValues(props);
9339 });
9340 var ComboboxItemValue = forwardRef22(function ComboboxItemValue2(props) {
9341 const htmlProps = useComboboxItemValue(props);
9342 return createElement3(TagName6, htmlProps);
9343 });
9344
9345 // node_modules/@ariakit/react-core/esm/__chunks/UQQRIHDV.js
9346 var import_react16 = __toESM(require_react(), 1);
9347 var TagName7 = "div";
9348 function getMouseDestination(event) {
9349 const relatedTarget = event.relatedTarget;
9350 if ((relatedTarget == null ? void 0 : relatedTarget.nodeType) === Node.ELEMENT_NODE) {
9351 return relatedTarget;
9352 }
9353 return null;
9354 }
9355 function hoveringInside(event) {
9356 const nextElement = getMouseDestination(event);
9357 if (!nextElement) return false;
9358 return contains(event.currentTarget, nextElement);
9359 }
9360 var symbol2 = /* @__PURE__ */ Symbol("composite-hover");
9361 function movingToAnotherItem(event) {
9362 let dest = getMouseDestination(event);
9363 if (!dest) return false;
9364 do {
9365 if (hasOwnProperty(dest, symbol2) && dest[symbol2]) return true;
9366 dest = dest.parentElement;
9367 } while (dest);
9368 return false;
9369 }
9370 var useCompositeHover = createHook(
9371 function useCompositeHover2(_a) {
9372 var _b = _a, {
9373 store,
9374 focusOnHover = true,
9375 blurOnHoverEnd = !!focusOnHover
9376 } = _b, props = __objRest(_b, [
9377 "store",
9378 "focusOnHover",
9379 "blurOnHoverEnd"
9380 ]);
9381 const context = useCompositeContext();
9382 store = store || context;
9383 invariant(
9384 store,
9385 "CompositeHover must be wrapped in a Composite component."
9386 );
9387 const isMouseMoving = useIsMouseMoving();
9388 const onMouseMoveProp = props.onMouseMove;
9389 const focusOnHoverProp = useBooleanEvent(focusOnHover);
9390 const onMouseMove = useEvent((event) => {
9391 onMouseMoveProp == null ? void 0 : onMouseMoveProp(event);
9392 if (event.defaultPrevented) return;
9393 if (!isMouseMoving()) return;
9394 if (!focusOnHoverProp(event)) return;
9395 if (!hasFocusWithin(event.currentTarget)) {
9396 const baseElement = store == null ? void 0 : store.getState().baseElement;
9397 if (baseElement && !hasFocus(baseElement)) {
9398 baseElement.focus();
9399 }
9400 }
9401 store == null ? void 0 : store.setActiveId(event.currentTarget.id);
9402 });
9403 const onMouseLeaveProp = props.onMouseLeave;
9404 const blurOnHoverEndProp = useBooleanEvent(blurOnHoverEnd);
9405 const onMouseLeave = useEvent((event) => {
9406 var _a2;
9407 onMouseLeaveProp == null ? void 0 : onMouseLeaveProp(event);
9408 if (event.defaultPrevented) return;
9409 if (!isMouseMoving()) return;
9410 if (hoveringInside(event)) return;
9411 if (movingToAnotherItem(event)) return;
9412 if (!focusOnHoverProp(event)) return;
9413 if (!blurOnHoverEndProp(event)) return;
9414 store == null ? void 0 : store.setActiveId(null);
9415 (_a2 = store == null ? void 0 : store.getState().baseElement) == null ? void 0 : _a2.focus();
9416 });
9417 const ref = (0, import_react16.useCallback)((element) => {
9418 if (!element) return;
9419 element[symbol2] = true;
9420 }, []);
9421 props = __spreadProps(__spreadValues({}, props), {
9422 ref: useMergeRefs(ref, props.ref),
9423 onMouseMove,
9424 onMouseLeave
9425 });
9426 return removeUndefinedValues(props);
9427 }
9428 );
9429 var CompositeHover = memo22(
9430 forwardRef22(function CompositeHover2(props) {
9431 const htmlProps = useCompositeHover(props);
9432 return createElement3(TagName7, htmlProps);
9433 })
9434 );
9435
9436 // node_modules/@ariakit/react-core/esm/__chunks/RZ4GPYOB.js
9437 var import_react17 = __toESM(require_react(), 1);
9438 var TagName8 = "div";
9439 var useCollectionItem = createHook(
9440 function useCollectionItem2(_a) {
9441 var _b = _a, {
9442 store,
9443 shouldRegisterItem = true,
9444 getItem = identity,
9445 element
9446 } = _b, props = __objRest(_b, [
9447 "store",
9448 "shouldRegisterItem",
9449 "getItem",
9450 // @ts-expect-error This prop may come from a collection renderer.
9451 "element"
9452 ]);
9453 const context = useCollectionContext();
9454 store = store || context;
9455 const id = useId3(props.id);
9456 const ref = (0, import_react17.useRef)(element);
9457 (0, import_react17.useEffect)(() => {
9458 const element2 = ref.current;
9459 if (!id) return;
9460 if (!element2) return;
9461 if (!shouldRegisterItem) return;
9462 const item = getItem({ id, element: element2 });
9463 return store == null ? void 0 : store.renderItem(item);
9464 }, [id, shouldRegisterItem, getItem, store]);
9465 props = __spreadProps(__spreadValues({}, props), {
9466 ref: useMergeRefs(ref, props.ref)
9467 });
9468 return removeUndefinedValues(props);
9469 }
9470 );
9471 var CollectionItem = forwardRef22(function CollectionItem2(props) {
9472 const htmlProps = useCollectionItem(props);
9473 return createElement3(TagName8, htmlProps);
9474 });
9475
9476 // node_modules/@ariakit/react-core/esm/__chunks/P2CTZE2T.js
9477 var import_react18 = __toESM(require_react(), 1);
9478 var import_jsx_runtime56 = __toESM(require_jsx_runtime(), 1);
9479 var TagName9 = "button";
9480 function isEditableElement(element) {
9481 if (isTextbox(element)) return true;
9482 return element.tagName === "INPUT" && !isButton(element);
9483 }
9484 function getNextPageOffset(scrollingElement, pageUp = false) {
9485 const height = scrollingElement.clientHeight;
9486 const { top } = scrollingElement.getBoundingClientRect();
9487 const pageSize = Math.max(height * 0.875, height - 40) * 1.5;
9488 const pageOffset = pageUp ? height - pageSize + top : pageSize + top;
9489 if (scrollingElement.tagName === "HTML") {
9490 return pageOffset + scrollingElement.scrollTop;
9491 }
9492 return pageOffset;
9493 }
9494 function getItemOffset(itemElement, pageUp = false) {
9495 const { top } = itemElement.getBoundingClientRect();
9496 if (pageUp) {
9497 return top + itemElement.clientHeight;
9498 }
9499 return top;
9500 }
9501 function findNextPageItemId(element, store, next, pageUp = false) {
9502 var _a;
9503 if (!store) return;
9504 if (!next) return;
9505 const { renderedItems } = store.getState();
9506 const scrollingElement = getScrollingElement(element);
9507 if (!scrollingElement) return;
9508 const nextPageOffset = getNextPageOffset(scrollingElement, pageUp);
9509 let id;
9510 let prevDifference;
9511 for (let i2 = 0; i2 < renderedItems.length; i2 += 1) {
9512 const previousId = id;
9513 id = next(i2);
9514 if (!id) break;
9515 if (id === previousId) continue;
9516 const itemElement = (_a = getEnabledItem(store, id)) == null ? void 0 : _a.element;
9517 if (!itemElement) continue;
9518 const itemOffset = getItemOffset(itemElement, pageUp);
9519 const difference = itemOffset - nextPageOffset;
9520 const absDifference = Math.abs(difference);
9521 if (pageUp && difference <= 0 || !pageUp && difference >= 0) {
9522 if (prevDifference !== void 0 && prevDifference < absDifference) {
9523 id = previousId;
9524 }
9525 break;
9526 }
9527 prevDifference = absDifference;
9528 }
9529 return id;
9530 }
9531 function targetIsAnotherItem(event, store) {
9532 if (isSelfTarget(event)) return false;
9533 return isItem(store, event.target);
9534 }
9535 var useCompositeItem = createHook(
9536 function useCompositeItem2(_a) {
9537 var _b = _a, {
9538 store,
9539 rowId: rowIdProp,
9540 preventScrollOnKeyDown = false,
9541 moveOnKeyPress = true,
9542 tabbable = false,
9543 getItem: getItemProp,
9544 "aria-setsize": ariaSetSizeProp,
9545 "aria-posinset": ariaPosInSetProp
9546 } = _b, props = __objRest(_b, [
9547 "store",
9548 "rowId",
9549 "preventScrollOnKeyDown",
9550 "moveOnKeyPress",
9551 "tabbable",
9552 "getItem",
9553 "aria-setsize",
9554 "aria-posinset"
9555 ]);
9556 const context = useCompositeContext();
9557 store = store || context;
9558 const id = useId3(props.id);
9559 const ref = (0, import_react18.useRef)(null);
9560 const row = (0, import_react18.useContext)(CompositeRowContext);
9561 const disabled = disabledFromProps(props);
9562 const trulyDisabled = disabled && !props.accessibleWhenDisabled;
9563 const {
9564 rowId,
9565 baseElement,
9566 isActiveItem,
9567 ariaSetSize,
9568 ariaPosInSet,
9569 isTabbable
9570 } = useStoreStateObject(store, {
9571 rowId(state) {
9572 if (rowIdProp) return rowIdProp;
9573 if (!state) return;
9574 if (!(row == null ? void 0 : row.baseElement)) return;
9575 if (row.baseElement !== state.baseElement) return;
9576 return row.id;
9577 },
9578 baseElement(state) {
9579 return (state == null ? void 0 : state.baseElement) || void 0;
9580 },
9581 isActiveItem(state) {
9582 return !!state && state.activeId === id;
9583 },
9584 ariaSetSize(state) {
9585 if (ariaSetSizeProp != null) return ariaSetSizeProp;
9586 if (!state) return;
9587 if (!(row == null ? void 0 : row.ariaSetSize)) return;
9588 if (row.baseElement !== state.baseElement) return;
9589 return row.ariaSetSize;
9590 },
9591 ariaPosInSet(state) {
9592 if (ariaPosInSetProp != null) return ariaPosInSetProp;
9593 if (!state) return;
9594 if (!(row == null ? void 0 : row.ariaPosInSet)) return;
9595 if (row.baseElement !== state.baseElement) return;
9596 const itemsInRow = state.renderedItems.filter(
9597 (item) => item.rowId === rowId
9598 );
9599 return row.ariaPosInSet + itemsInRow.findIndex((item) => item.id === id);
9600 },
9601 isTabbable(state) {
9602 if (!(state == null ? void 0 : state.renderedItems.length)) return true;
9603 if (state.virtualFocus) return false;
9604 if (tabbable) return true;
9605 if (state.activeId === null) return false;
9606 const item = store == null ? void 0 : store.item(state.activeId);
9607 if (item == null ? void 0 : item.disabled) return true;
9608 if (!(item == null ? void 0 : item.element)) return true;
9609 return state.activeId === id;
9610 }
9611 });
9612 const getItem = (0, import_react18.useCallback)(
9613 (item) => {
9614 var _a2;
9615 const nextItem = __spreadProps(__spreadValues({}, item), {
9616 id: id || item.id,
9617 rowId,
9618 disabled: !!trulyDisabled,
9619 children: (_a2 = item.element) == null ? void 0 : _a2.textContent
9620 });
9621 if (getItemProp) {
9622 return getItemProp(nextItem);
9623 }
9624 return nextItem;
9625 },
9626 [id, rowId, trulyDisabled, getItemProp]
9627 );
9628 const onFocusProp = props.onFocus;
9629 const hasFocusedComposite = (0, import_react18.useRef)(false);
9630 const onFocus = useEvent((event) => {
9631 onFocusProp == null ? void 0 : onFocusProp(event);
9632 if (event.defaultPrevented) return;
9633 if (isPortalEvent(event)) return;
9634 if (!id) return;
9635 if (!store) return;
9636 if (targetIsAnotherItem(event, store)) return;
9637 const { virtualFocus, baseElement: baseElement2 } = store.getState();
9638 store.setActiveId(id);
9639 if (isTextbox(event.currentTarget)) {
9640 selectTextField(event.currentTarget);
9641 }
9642 if (!virtualFocus) return;
9643 if (!isSelfTarget(event)) return;
9644 if (isEditableElement(event.currentTarget)) return;
9645 if (!(baseElement2 == null ? void 0 : baseElement2.isConnected)) return;
9646 if (isSafari() && event.currentTarget.hasAttribute("data-autofocus")) {
9647 event.currentTarget.scrollIntoView({
9648 block: "nearest",
9649 inline: "nearest"
9650 });
9651 }
9652 hasFocusedComposite.current = true;
9653 const fromComposite = event.relatedTarget === baseElement2 || isItem(store, event.relatedTarget);
9654 if (fromComposite) {
9655 focusSilently(baseElement2);
9656 } else {
9657 baseElement2.focus();
9658 }
9659 });
9660 const onBlurCaptureProp = props.onBlurCapture;
9661 const onBlurCapture = useEvent((event) => {
9662 onBlurCaptureProp == null ? void 0 : onBlurCaptureProp(event);
9663 if (event.defaultPrevented) return;
9664 const state = store == null ? void 0 : store.getState();
9665 if ((state == null ? void 0 : state.virtualFocus) && hasFocusedComposite.current) {
9666 hasFocusedComposite.current = false;
9667 event.preventDefault();
9668 event.stopPropagation();
9669 }
9670 });
9671 const onKeyDownProp = props.onKeyDown;
9672 const preventScrollOnKeyDownProp = useBooleanEvent(preventScrollOnKeyDown);
9673 const moveOnKeyPressProp = useBooleanEvent(moveOnKeyPress);
9674 const onKeyDown = useEvent((event) => {
9675 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
9676 if (event.defaultPrevented) return;
9677 if (!isSelfTarget(event)) return;
9678 if (!store) return;
9679 const { currentTarget } = event;
9680 const state = store.getState();
9681 const item = store.item(id);
9682 const isGrid2 = !!(item == null ? void 0 : item.rowId);
9683 const isVertical = state.orientation !== "horizontal";
9684 const isHorizontal = state.orientation !== "vertical";
9685 const canHomeEnd = () => {
9686 if (isGrid2) return true;
9687 if (isHorizontal) return true;
9688 if (!state.baseElement) return true;
9689 if (!isTextField(state.baseElement)) return true;
9690 return false;
9691 };
9692 const keyMap = {
9693 ArrowUp: (isGrid2 || isVertical) && store.up,
9694 ArrowRight: (isGrid2 || isHorizontal) && store.next,
9695 ArrowDown: (isGrid2 || isVertical) && store.down,
9696 ArrowLeft: (isGrid2 || isHorizontal) && store.previous,
9697 Home: () => {
9698 if (!canHomeEnd()) return;
9699 if (!isGrid2 || event.ctrlKey) {
9700 return store == null ? void 0 : store.first();
9701 }
9702 return store == null ? void 0 : store.previous(-1);
9703 },
9704 End: () => {
9705 if (!canHomeEnd()) return;
9706 if (!isGrid2 || event.ctrlKey) {
9707 return store == null ? void 0 : store.last();
9708 }
9709 return store == null ? void 0 : store.next(-1);
9710 },
9711 PageUp: () => {
9712 return findNextPageItemId(currentTarget, store, store == null ? void 0 : store.up, true);
9713 },
9714 PageDown: () => {
9715 return findNextPageItemId(currentTarget, store, store == null ? void 0 : store.down);
9716 }
9717 };
9718 const action = keyMap[event.key];
9719 if (action) {
9720 if (isTextbox(currentTarget)) {
9721 const selection = getTextboxSelection(currentTarget);
9722 const isLeft = isHorizontal && event.key === "ArrowLeft";
9723 const isRight = isHorizontal && event.key === "ArrowRight";
9724 const isUp = isVertical && event.key === "ArrowUp";
9725 const isDown = isVertical && event.key === "ArrowDown";
9726 if (isRight || isDown) {
9727 const { length: valueLength } = getTextboxValue(currentTarget);
9728 if (selection.end !== valueLength) return;
9729 } else if ((isLeft || isUp) && selection.start !== 0) return;
9730 }
9731 const nextId = action();
9732 if (preventScrollOnKeyDownProp(event) || nextId !== void 0) {
9733 if (!moveOnKeyPressProp(event)) return;
9734 event.preventDefault();
9735 store.move(nextId);
9736 }
9737 }
9738 });
9739 const providerValue = (0, import_react18.useMemo)(
9740 () => ({ id, baseElement }),
9741 [id, baseElement]
9742 );
9743 props = useWrapElement(
9744 props,
9745 (element) => /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(CompositeItemContext.Provider, { value: providerValue, children: element }),
9746 [providerValue]
9747 );
9748 props = __spreadProps(__spreadValues({
9749 id,
9750 "data-active-item": isActiveItem || void 0
9751 }, props), {
9752 ref: useMergeRefs(ref, props.ref),
9753 tabIndex: isTabbable ? props.tabIndex : -1,
9754 onFocus,
9755 onBlurCapture,
9756 onKeyDown
9757 });
9758 props = useCommand(props);
9759 props = useCollectionItem(__spreadProps(__spreadValues({
9760 store
9761 }, props), {
9762 getItem,
9763 shouldRegisterItem: id ? props.shouldRegisterItem : false
9764 }));
9765 return removeUndefinedValues(__spreadProps(__spreadValues({}, props), {
9766 "aria-setsize": ariaSetSize,
9767 "aria-posinset": ariaPosInSet
9768 }));
9769 }
9770 );
9771 var CompositeItem = memo22(
9772 forwardRef22(function CompositeItem2(props) {
9773 const htmlProps = useCompositeItem(props);
9774 return createElement3(TagName9, htmlProps);
9775 })
9776 );
9777
9778 // node_modules/@ariakit/react-core/esm/__chunks/ZTDSJLD6.js
9779 var import_react19 = __toESM(require_react(), 1);
9780 var import_jsx_runtime57 = __toESM(require_jsx_runtime(), 1);
9781 var TagName10 = "div";
9782 function isSelected(storeValue, itemValue) {
9783 if (itemValue == null) return;
9784 if (storeValue == null) return false;
9785 if (Array.isArray(storeValue)) {
9786 return storeValue.includes(itemValue);
9787 }
9788 return storeValue === itemValue;
9789 }
9790 function getItemRole(popupRole) {
9791 var _a;
9792 const itemRoleByPopupRole = {
9793 menu: "menuitem",
9794 listbox: "option",
9795 tree: "treeitem"
9796 };
9797 const key = popupRole;
9798 return (_a = itemRoleByPopupRole[key]) != null ? _a : "option";
9799 }
9800 var useComboboxItem = createHook(
9801 function useComboboxItem2(_a) {
9802 var _b = _a, {
9803 store,
9804 value,
9805 hideOnClick,
9806 setValueOnClick,
9807 selectValueOnClick = true,
9808 resetValueOnSelect,
9809 focusOnHover = false,
9810 moveOnKeyPress = true,
9811 getItem: getItemProp
9812 } = _b, props = __objRest(_b, [
9813 "store",
9814 "value",
9815 "hideOnClick",
9816 "setValueOnClick",
9817 "selectValueOnClick",
9818 "resetValueOnSelect",
9819 "focusOnHover",
9820 "moveOnKeyPress",
9821 "getItem"
9822 ]);
9823 var _a2;
9824 const context = useComboboxScopedContext();
9825 store = store || context;
9826 invariant(
9827 store,
9828 "ComboboxItem must be wrapped in a ComboboxList or ComboboxPopover component."
9829 );
9830 const { resetValueOnSelectState, multiSelectable, selected } = useStoreStateObject(store, {
9831 resetValueOnSelectState: "resetValueOnSelect",
9832 multiSelectable(state) {
9833 return Array.isArray(state.selectedValue);
9834 },
9835 selected(state) {
9836 return isSelected(state.selectedValue, value);
9837 }
9838 });
9839 const getItem = (0, import_react19.useCallback)(
9840 (item) => {
9841 const nextItem = __spreadProps(__spreadValues({}, item), { value });
9842 if (getItemProp) {
9843 return getItemProp(nextItem);
9844 }
9845 return nextItem;
9846 },
9847 [value, getItemProp]
9848 );
9849 setValueOnClick = setValueOnClick != null ? setValueOnClick : !multiSelectable;
9850 hideOnClick = hideOnClick != null ? hideOnClick : value != null && !multiSelectable;
9851 const onClickProp = props.onClick;
9852 const setValueOnClickProp = useBooleanEvent(setValueOnClick);
9853 const selectValueOnClickProp = useBooleanEvent(selectValueOnClick);
9854 const resetValueOnSelectProp = useBooleanEvent(
9855 (_a2 = resetValueOnSelect != null ? resetValueOnSelect : resetValueOnSelectState) != null ? _a2 : multiSelectable
9856 );
9857 const hideOnClickProp = useBooleanEvent(hideOnClick);
9858 const onClick = useEvent((event) => {
9859 onClickProp == null ? void 0 : onClickProp(event);
9860 if (event.defaultPrevented) return;
9861 if (isDownloading(event)) return;
9862 if (isOpeningInNewTab(event)) return;
9863 if (value != null) {
9864 if (selectValueOnClickProp(event)) {
9865 if (resetValueOnSelectProp(event)) {
9866 store == null ? void 0 : store.resetValue();
9867 }
9868 store == null ? void 0 : store.setSelectedValue((prevValue) => {
9869 if (!Array.isArray(prevValue)) return value;
9870 if (prevValue.includes(value)) {
9871 return prevValue.filter((v2) => v2 !== value);
9872 }
9873 return [...prevValue, value];
9874 });
9875 }
9876 if (setValueOnClickProp(event)) {
9877 store == null ? void 0 : store.setValue(value);
9878 }
9879 }
9880 if (hideOnClickProp(event)) {
9881 store == null ? void 0 : store.hide();
9882 }
9883 });
9884 const onKeyDownProp = props.onKeyDown;
9885 const onKeyDown = useEvent((event) => {
9886 onKeyDownProp == null ? void 0 : onKeyDownProp(event);
9887 if (event.defaultPrevented) return;
9888 const baseElement = store == null ? void 0 : store.getState().baseElement;
9889 if (!baseElement) return;
9890 if (hasFocus(baseElement)) return;
9891 const printable = event.key.length === 1;
9892 if (printable || event.key === "Backspace" || event.key === "Delete") {
9893 queueMicrotask(() => baseElement.focus());
9894 if (isTextField(baseElement)) {
9895 store == null ? void 0 : store.setValue(baseElement.value);
9896 }
9897 }
9898 });
9899 if (multiSelectable && selected != null) {
9900 props = __spreadValues({
9901 "aria-selected": selected
9902 }, props);
9903 }
9904 props = useWrapElement(
9905 props,
9906 (element) => /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(ComboboxItemValueContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(ComboboxItemCheckedContext.Provider, { value: selected != null ? selected : false, children: element }) }),
9907 [value, selected]
9908 );
9909 const popupRole = (0, import_react19.useContext)(ComboboxListRoleContext);
9910 props = __spreadProps(__spreadValues({
9911 role: getItemRole(popupRole),
9912 children: value
9913 }, props), {
9914 onClick,
9915 onKeyDown
9916 });
9917 const moveOnKeyPressProp = useBooleanEvent(moveOnKeyPress);
9918 props = useCompositeItem(__spreadProps(__spreadValues({
9919 store
9920 }, props), {
9921 getItem,
9922 // Dispatch a custom event on the combobox input when moving to an item
9923 // with the keyboard so the Combobox component can enable inline
9924 // autocompletion.
9925 moveOnKeyPress: (event) => {
9926 if (!moveOnKeyPressProp(event)) return false;
9927 const moveEvent = new Event("combobox-item-move");
9928 const baseElement = store == null ? void 0 : store.getState().baseElement;
9929 baseElement == null ? void 0 : baseElement.dispatchEvent(moveEvent);
9930 return true;
9931 }
9932 }));
9933 props = useCompositeHover(__spreadValues({ store, focusOnHover }, props));
9934 return props;
9935 }
9936 );
9937 var ComboboxItem = memo22(
9938 forwardRef22(function ComboboxItem2(props) {
9939 const htmlProps = useComboboxItem(props);
9940 return createElement3(TagName10, htmlProps);
9941 })
9942 );
9943
9944 // node_modules/@ariakit/react-core/esm/combobox/combobox-label.js
9945 var TagName11 = "label";
9946 var useComboboxLabel = createHook(
9947 function useComboboxLabel2(_a) {
9948 var _b = _a, { store } = _b, props = __objRest(_b, ["store"]);
9949 const context = useComboboxProviderContext();
9950 store = store || context;
9951 invariant(
9952 store,
9953 "ComboboxLabel must receive a `store` prop or be wrapped in a ComboboxProvider component."
9954 );
9955 const comboboxId = store.useState((state) => {
9956 var _a2;
9957 return (_a2 = state.baseElement) == null ? void 0 : _a2.id;
9958 });
9959 props = __spreadValues({
9960 htmlFor: comboboxId
9961 }, props);
9962 return removeUndefinedValues(props);
9963 }
9964 );
9965 var ComboboxLabel = memo22(
9966 forwardRef22(function ComboboxLabel2(props) {
9967 const htmlProps = useComboboxLabel(props);
9968 return createElement3(TagName11, htmlProps);
9969 })
9970 );
9971
9972 // node_modules/@ariakit/react-core/esm/__chunks/VGCJ63VH.js
9973 var import_react20 = __toESM(require_react(), 1);
9974 var import_react_dom = __toESM(require_react_dom(), 1);
9975 var import_jsx_runtime58 = __toESM(require_jsx_runtime(), 1);
9976 var TagName12 = "div";
9977 function afterTimeout(timeoutMs, cb) {
9978 const timeoutId = setTimeout(cb, timeoutMs);
9979 return () => clearTimeout(timeoutId);
9980 }
9981 function afterPaint2(cb) {
9982 let raf = requestAnimationFrame(() => {
9983 raf = requestAnimationFrame(cb);
9984 });
9985 return () => cancelAnimationFrame(raf);
9986 }
9987 function parseCSSTime(...times) {
9988 return times.join(", ").split(", ").reduce((longestTime, currentTimeString) => {
9989 const multiplier = currentTimeString.endsWith("ms") ? 1 : 1e3;
9990 const currentTime = Number.parseFloat(currentTimeString || "0s") * multiplier;
9991 if (currentTime > longestTime) return currentTime;
9992 return longestTime;
9993 }, 0);
9994 }
9995 function isHidden(mounted, hidden, alwaysVisible) {
9996 return !alwaysVisible && hidden !== false && (!mounted || !!hidden);
9997 }
9998 var useDisclosureContent = createHook(function useDisclosureContent2(_a) {
9999 var _b = _a, { store, alwaysVisible } = _b, props = __objRest(_b, ["store", "alwaysVisible"]);
10000 const context = useDisclosureProviderContext();
10001 store = store || context;
10002 invariant(
10003 store,
10004 "DisclosureContent must receive a `store` prop or be wrapped in a DisclosureProvider component."
10005 );
10006 const ref = (0, import_react20.useRef)(null);
10007 const id = useId3(props.id);
10008 const [transition, setTransition] = (0, import_react20.useState)(null);
10009 const open = store.useState("open");
10010 const mounted = store.useState("mounted");
10011 const animated = store.useState("animated");
10012 const contentElement = store.useState("contentElement");
10013 const otherElement = useStoreState(store.disclosure, "contentElement");
10014 useSafeLayoutEffect(() => {
10015 if (!ref.current) return;
10016 store == null ? void 0 : store.setContentElement(ref.current);
10017 }, [store]);
10018 useSafeLayoutEffect(() => {
10019 let previousAnimated;
10020 store == null ? void 0 : store.setState("animated", (animated2) => {
10021 previousAnimated = animated2;
10022 return true;
10023 });
10024 return () => {
10025 if (previousAnimated === void 0) return;
10026 store == null ? void 0 : store.setState("animated", previousAnimated);
10027 };
10028 }, [store]);
10029 useSafeLayoutEffect(() => {
10030 if (!animated) return;
10031 if (!(contentElement == null ? void 0 : contentElement.isConnected)) {
10032 setTransition(null);
10033 return;
10034 }
10035 return afterPaint2(() => {
10036 setTransition(open ? "enter" : mounted ? "leave" : null);
10037 });
10038 }, [animated, contentElement, open, mounted]);
10039 useSafeLayoutEffect(() => {
10040 if (!store) return;
10041 if (!animated) return;
10042 if (!transition) return;
10043 if (!contentElement) return;
10044 const stopAnimation = () => store == null ? void 0 : store.setState("animating", false);
10045 const stopAnimationSync = () => (0, import_react_dom.flushSync)(stopAnimation);
10046 if (transition === "leave" && open) return;
10047 if (transition === "enter" && !open) return;
10048 if (typeof animated === "number") {
10049 const timeout2 = animated;
10050 return afterTimeout(timeout2, stopAnimationSync);
10051 }
10052 const {
10053 transitionDuration,
10054 animationDuration,
10055 transitionDelay,
10056 animationDelay
10057 } = getComputedStyle(contentElement);
10058 const {
10059 transitionDuration: transitionDuration2 = "0",
10060 animationDuration: animationDuration2 = "0",
10061 transitionDelay: transitionDelay2 = "0",
10062 animationDelay: animationDelay2 = "0"
10063 } = otherElement ? getComputedStyle(otherElement) : {};
10064 const delay = parseCSSTime(
10065 transitionDelay,
10066 animationDelay,
10067 transitionDelay2,
10068 animationDelay2
10069 );
10070 const duration = parseCSSTime(
10071 transitionDuration,
10072 animationDuration,
10073 transitionDuration2,
10074 animationDuration2
10075 );
10076 const timeout = delay + duration;
10077 if (!timeout) {
10078 if (transition === "enter") {
10079 store.setState("animated", false);
10080 }
10081 stopAnimation();
10082 return;
10083 }
10084 const frameRate = 1e3 / 60;
10085 const maxTimeout = Math.max(timeout - frameRate, 0);
10086 return afterTimeout(maxTimeout, stopAnimationSync);
10087 }, [store, animated, contentElement, otherElement, open, transition]);
10088 props = useWrapElement(
10089 props,
10090 (element) => /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(DialogScopedContextProvider, { value: store, children: element }),
10091 [store]
10092 );
10093 const hidden = isHidden(mounted, props.hidden, alwaysVisible);
10094 const styleProp = props.style;
10095 const style = (0, import_react20.useMemo)(() => {
10096 if (hidden) {
10097 return __spreadProps(__spreadValues({}, styleProp), { display: "none" });
10098 }
10099 return styleProp;
10100 }, [hidden, styleProp]);
10101 props = __spreadProps(__spreadValues({
10102 id,
10103 "data-open": open || void 0,
10104 "data-enter": transition === "enter" || void 0,
10105 "data-leave": transition === "leave" || void 0,
10106 hidden
10107 }, props), {
10108 ref: useMergeRefs(id ? store.setContentElement : null, ref, props.ref),
10109 style
10110 });
10111 return removeUndefinedValues(props);
10112 });
10113 var DisclosureContentImpl = forwardRef22(function DisclosureContentImpl2(props) {
10114 const htmlProps = useDisclosureContent(props);
10115 return createElement3(TagName12, htmlProps);
10116 });
10117 var DisclosureContent = forwardRef22(function DisclosureContent2(_a) {
10118 var _b = _a, {
10119 unmountOnHide
10120 } = _b, props = __objRest(_b, [
10121 "unmountOnHide"
10122 ]);
10123 const context = useDisclosureProviderContext();
10124 const store = props.store || context;
10125 const mounted = useStoreState(
10126 store,
10127 (state) => !unmountOnHide || (state == null ? void 0 : state.mounted)
10128 );
10129 if (mounted === false) return null;
10130 return /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(DisclosureContentImpl, __spreadValues({}, props));
10131 });
10132
10133 // node_modules/@ariakit/react-core/esm/__chunks/HUWAI7RB.js
10134 var import_react21 = __toESM(require_react(), 1);
10135 var import_jsx_runtime59 = __toESM(require_jsx_runtime(), 1);
10136 var TagName13 = "div";
10137 var useComboboxList = createHook(
10138 function useComboboxList2(_a) {
10139 var _b = _a, { store, alwaysVisible } = _b, props = __objRest(_b, ["store", "alwaysVisible"]);
10140 const scopedContext = useComboboxScopedContext(true);
10141 const context = useComboboxContext();
10142 store = store || context;
10143 const scopedContextSameStore = !!store && store === scopedContext;
10144 invariant(
10145 store,
10146 "ComboboxList must receive a `store` prop or be wrapped in a ComboboxProvider component."
10147 );
10148 const ref = (0, import_react21.useRef)(null);
10149 const id = useId3(props.id);
10150 const mounted = store.useState("mounted");
10151 const hidden = isHidden(mounted, props.hidden, alwaysVisible);
10152 const style = hidden ? __spreadProps(__spreadValues({}, props.style), { display: "none" }) : props.style;
10153 const multiSelectable = store.useState(
10154 (state) => Array.isArray(state.selectedValue)
10155 );
10156 const role = useAttribute(ref, "role", props.role);
10157 const isCompositeRole = role === "listbox" || role === "tree" || role === "grid";
10158 const ariaMultiSelectable = isCompositeRole ? multiSelectable || void 0 : void 0;
10159 const [hasListboxInside, setHasListboxInside] = (0, import_react21.useState)(false);
10160 const contentElement = store.useState("contentElement");
10161 useSafeLayoutEffect(() => {
10162 if (!mounted) return;
10163 const element = ref.current;
10164 if (!element) return;
10165 if (contentElement !== element) return;
10166 const callback = () => {
10167 setHasListboxInside(!!element.querySelector("[role='listbox']"));
10168 };
10169 const observer = new MutationObserver(callback);
10170 observer.observe(element, {
10171 subtree: true,
10172 childList: true,
10173 attributeFilter: ["role"]
10174 });
10175 callback();
10176 return () => observer.disconnect();
10177 }, [mounted, contentElement]);
10178 if (!hasListboxInside) {
10179 props = __spreadValues({
10180 role: "listbox",
10181 "aria-multiselectable": ariaMultiSelectable
10182 }, props);
10183 }
10184 props = useWrapElement(
10185 props,
10186 (element) => /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(ComboboxScopedContextProvider, { value: store, children: /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(ComboboxListRoleContext.Provider, { value: role, children: element }) }),
10187 [store, role]
10188 );
10189 const setContentElement = id && (!scopedContext || !scopedContextSameStore) ? store.setContentElement : null;
10190 props = __spreadProps(__spreadValues({
10191 id,
10192 hidden
10193 }, props), {
10194 ref: useMergeRefs(setContentElement, ref, props.ref),
10195 style
10196 });
10197 return removeUndefinedValues(props);
10198 }
10199 );
10200 var ComboboxList = forwardRef22(function ComboboxList2(props) {
10201 const htmlProps = useComboboxList(props);
10202 return createElement3(TagName13, htmlProps);
10203 });
10204
10205 // packages/dataviews/build-module/components/dataviews-filters/search-widget.mjs
10206 var import_remove_accents = __toESM(require_remove_accents(), 1);
10207 var import_compose7 = __toESM(require_compose(), 1);
10208 var import_i18n27 = __toESM(require_i18n(), 1);
10209 var import_element24 = __toESM(require_element(), 1);
10210 var import_components19 = __toESM(require_components(), 1);
10211
10212 // packages/dataviews/build-module/components/dataviews-filters/utils.mjs
10213 var EMPTY_ARRAY3 = [];
10214 var getCurrentValue = (filterDefinition, currentFilter) => {
10215 if (filterDefinition.singleSelection) {
10216 return currentFilter?.value;
10217 }
10218 if (Array.isArray(currentFilter?.value)) {
10219 return currentFilter.value;
10220 }
10221 if (!Array.isArray(currentFilter?.value) && !!currentFilter?.value) {
10222 return [currentFilter.value];
10223 }
10224 return EMPTY_ARRAY3;
10225 };
10226
10227 // packages/dataviews/build-module/hooks/use-elements.mjs
10228 var import_element23 = __toESM(require_element(), 1);
10229 var EMPTY_ARRAY4 = [];
10230 function useElements({
10231 elements,
10232 getElements
10233 }) {
10234 const staticElements = Array.isArray(elements) && elements.length > 0 ? elements : EMPTY_ARRAY4;
10235 const [records, setRecords] = (0, import_element23.useState)(staticElements);
10236 const [isLoading, setIsLoading] = (0, import_element23.useState)(false);
10237 (0, import_element23.useEffect)(() => {
10238 if (!getElements) {
10239 setRecords(staticElements);
10240 return;
10241 }
10242 let cancelled = false;
10243 setIsLoading(true);
10244 getElements().then((fetchedElements) => {
10245 if (!cancelled) {
10246 const dynamicElements = Array.isArray(fetchedElements) && fetchedElements.length > 0 ? fetchedElements : staticElements;
10247 setRecords(dynamicElements);
10248 }
10249 }).catch(() => {
10250 if (!cancelled) {
10251 setRecords(staticElements);
10252 }
10253 }).finally(() => {
10254 if (!cancelled) {
10255 setIsLoading(false);
10256 }
10257 });
10258 return () => {
10259 cancelled = true;
10260 };
10261 }, [getElements, staticElements]);
10262 return {
10263 elements: records,
10264 isLoading
10265 };
10266 }
10267
10268 // packages/dataviews/build-module/components/dataviews-filters/search-widget.mjs
10269 var import_jsx_runtime60 = __toESM(require_jsx_runtime(), 1);
10270 function normalizeSearchInput(input = "") {
10271 return (0, import_remove_accents.default)(input.trim().toLowerCase());
10272 }
10273 var getNewValue = (filterDefinition, currentFilter, value) => {
10274 if (filterDefinition.singleSelection) {
10275 return value;
10276 }
10277 if (Array.isArray(currentFilter?.value)) {
10278 return currentFilter.value.includes(value) ? currentFilter.value.filter((v2) => v2 !== value) : [...currentFilter.value, value];
10279 }
10280 return [value];
10281 };
10282 function generateFilterElementCompositeItemId(prefix, filterElementValue) {
10283 return `${prefix}-${filterElementValue}`;
10284 }
10285 var MultiSelectionOption = ({ selected }) => {
10286 return /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(
10287 "span",
10288 {
10289 className: clsx_default(
10290 "dataviews-filters__search-widget-listitem-multi-selection",
10291 { "is-selected": selected }
10292 ),
10293 children: selected && /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(import_components19.Icon, { icon: check_default })
10294 }
10295 );
10296 };
10297 var SingleSelectionOption = ({ selected }) => {
10298 return /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(
10299 "span",
10300 {
10301 className: clsx_default(
10302 "dataviews-filters__search-widget-listitem-single-selection",
10303 { "is-selected": selected }
10304 )
10305 }
10306 );
10307 };
10308 function ListBox({ view, filter, onChangeView }) {
10309 const baseId = (0, import_compose7.useInstanceId)(ListBox, "dataviews-filter-list-box");
10310 const [activeCompositeId, setActiveCompositeId] = (0, import_element24.useState)(
10311 // When there are one or less operators, the first item is set as active
10312 // (by setting the initial `activeId` to `undefined`).
10313 // With 2 or more operators, the focus is moved on the operators control
10314 // (by setting the initial `activeId` to `null`), meaning that there won't
10315 // be an active item initially. Focus is then managed via the
10316 // `onFocusVisible` callback.
10317 filter.operators?.length === 1 ? void 0 : null
10318 );
10319 const currentFilter = view.filters?.find(
10320 (f2) => f2.field === filter.field
10321 );
10322 const currentValue = getCurrentValue(filter, currentFilter);
10323 return /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(
10324 import_components19.Composite,
10325 {
10326 virtualFocus: true,
10327 focusLoop: true,
10328 activeId: activeCompositeId,
10329 setActiveId: setActiveCompositeId,
10330 role: "listbox",
10331 className: "dataviews-filters__search-widget-listbox",
10332 "aria-label": (0, import_i18n27.sprintf)(
10333 /* translators: List of items for a filter. 1: Filter name. e.g.: "List of: Author". */
10334 (0, import_i18n27.__)("List of: %1$s"),
10335 filter.name
10336 ),
10337 onFocusVisible: () => {
10338 if (!activeCompositeId && filter.elements.length) {
10339 setActiveCompositeId(
10340 generateFilterElementCompositeItemId(
10341 baseId,
10342 filter.elements[0].value
10343 )
10344 );
10345 }
10346 },
10347 render: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(import_components19.Composite.Typeahead, {}),
10348 children: filter.elements.map((element) => /* @__PURE__ */ (0, import_jsx_runtime60.jsxs)(
10349 import_components19.Composite.Hover,
10350 {
10351 render: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(
10352 import_components19.Composite.Item,
10353 {
10354 id: generateFilterElementCompositeItemId(
10355 baseId,
10356 element.value
10357 ),
10358 render: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(
10359 "div",
10360 {
10361 "aria-label": element.label,
10362 role: "option",
10363 className: "dataviews-filters__search-widget-listitem"
10364 }
10365 ),
10366 onClick: () => {
10367 const newFilters = currentFilter ? [
10368 ...(view.filters ?? []).map(
10369 (_filter) => {
10370 if (_filter.field === filter.field) {
10371 return {
10372 ..._filter,
10373 operator: currentFilter.operator || filter.operators[0],
10374 value: getNewValue(
10375 filter,
10376 currentFilter,
10377 element.value
10378 )
10379 };
10380 }
10381 return _filter;
10382 }
10383 )
10384 ] : [
10385 ...view.filters ?? [],
10386 {
10387 field: filter.field,
10388 operator: filter.operators[0],
10389 value: getNewValue(
10390 filter,
10391 currentFilter,
10392 element.value
10393 )
10394 }
10395 ];
10396 onChangeView({
10397 ...view,
10398 page: 1,
10399 filters: newFilters
10400 });
10401 }
10402 }
10403 ),
10404 children: [
10405 filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(
10406 SingleSelectionOption,
10407 {
10408 selected: currentValue === element.value
10409 }
10410 ),
10411 !filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(
10412 MultiSelectionOption,
10413 {
10414 selected: currentValue.includes(element.value)
10415 }
10416 ),
10417 /* @__PURE__ */ (0, import_jsx_runtime60.jsx)("span", { children: element.label })
10418 ]
10419 },
10420 element.value
10421 ))
10422 }
10423 );
10424 }
10425 function ComboboxList22({ view, filter, onChangeView }) {
10426 const [searchValue, setSearchValue] = (0, import_element24.useState)("");
10427 const deferredSearchValue = (0, import_element24.useDeferredValue)(searchValue);
10428 const currentFilter = view.filters?.find(
10429 (_filter) => _filter.field === filter.field
10430 );
10431 const currentValue = getCurrentValue(filter, currentFilter);
10432 const matches = (0, import_element24.useMemo)(() => {
10433 const normalizedSearch = normalizeSearchInput(deferredSearchValue);
10434 return filter.elements.filter(
10435 (item) => normalizeSearchInput(item.label).includes(normalizedSearch)
10436 );
10437 }, [filter.elements, deferredSearchValue]);
10438 return /* @__PURE__ */ (0, import_jsx_runtime60.jsxs)(
10439 ComboboxProvider,
10440 {
10441 selectedValue: currentValue,
10442 setSelectedValue: (value) => {
10443 const newFilters = currentFilter ? [
10444 ...(view.filters ?? []).map((_filter) => {
10445 if (_filter.field === filter.field) {
10446 return {
10447 ..._filter,
10448 operator: currentFilter.operator || filter.operators[0],
10449 value
10450 };
10451 }
10452 return _filter;
10453 })
10454 ] : [
10455 ...view.filters ?? [],
10456 {
10457 field: filter.field,
10458 operator: filter.operators[0],
10459 value
10460 }
10461 ];
10462 onChangeView({
10463 ...view,
10464 page: 1,
10465 filters: newFilters
10466 });
10467 },
10468 setValue: setSearchValue,
10469 children: [
10470 /* @__PURE__ */ (0, import_jsx_runtime60.jsxs)("div", { className: "dataviews-filters__search-widget-filter-combobox__wrapper", children: [
10471 /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(
10472 ComboboxLabel,
10473 {
10474 render: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(import_components19.VisuallyHidden, { children: (0, import_i18n27.__)("Search items") }),
10475 children: (0, import_i18n27.__)("Search items")
10476 }
10477 ),
10478 /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(
10479 Combobox,
10480 {
10481 autoSelect: "always",
10482 placeholder: (0, import_i18n27.__)("Search"),
10483 className: "dataviews-filters__search-widget-filter-combobox__input"
10484 }
10485 ),
10486 /* @__PURE__ */ (0, import_jsx_runtime60.jsx)("div", { className: "dataviews-filters__search-widget-filter-combobox__icon", children: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(import_components19.Icon, { icon: search_default }) })
10487 ] }),
10488 /* @__PURE__ */ (0, import_jsx_runtime60.jsxs)(
10489 ComboboxList,
10490 {
10491 className: "dataviews-filters__search-widget-filter-combobox-list",
10492 alwaysVisible: true,
10493 children: [
10494 matches.map((element) => {
10495 return /* @__PURE__ */ (0, import_jsx_runtime60.jsxs)(
10496 ComboboxItem,
10497 {
10498 resetValueOnSelect: false,
10499 value: element.value,
10500 className: "dataviews-filters__search-widget-listitem",
10501 hideOnClick: false,
10502 setValueOnClick: false,
10503 focusOnHover: true,
10504 children: [
10505 filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(
10506 SingleSelectionOption,
10507 {
10508 selected: currentValue === element.value
10509 }
10510 ),
10511 !filter.singleSelection && /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(
10512 MultiSelectionOption,
10513 {
10514 selected: currentValue.includes(
10515 element.value
10516 )
10517 }
10518 ),
10519 /* @__PURE__ */ (0, import_jsx_runtime60.jsxs)("span", { children: [
10520 /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(
10521 ComboboxItemValue,
10522 {
10523 className: "dataviews-filters__search-widget-filter-combobox-item-value",
10524 value: element.label
10525 }
10526 ),
10527 !!element.description && /* @__PURE__ */ (0, import_jsx_runtime60.jsx)("span", { className: "dataviews-filters__search-widget-listitem-description", children: element.description })
10528 ] })
10529 ]
10530 },
10531 element.value
10532 );
10533 }),
10534 !matches.length && /* @__PURE__ */ (0, import_jsx_runtime60.jsx)("p", { children: (0, import_i18n27.__)("No results found") })
10535 ]
10536 }
10537 )
10538 ]
10539 }
10540 );
10541 }
10542 function SearchWidget(props) {
10543 const { elements, isLoading } = useElements({
10544 elements: props.filter.elements,
10545 getElements: props.filter.getElements
10546 });
10547 if (isLoading) {
10548 return /* @__PURE__ */ (0, import_jsx_runtime60.jsx)("div", { className: "dataviews-filters__search-widget-no-elements", children: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(import_components19.Spinner, {}) });
10549 }
10550 if (elements.length === 0) {
10551 return /* @__PURE__ */ (0, import_jsx_runtime60.jsx)("div", { className: "dataviews-filters__search-widget-no-elements", children: (0, import_i18n27.__)("No elements found") });
10552 }
10553 const Widget = elements.length > 10 ? ComboboxList22 : ListBox;
10554 return /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(Widget, { ...props, filter: { ...props.filter, elements } });
10555 }
10556
10557 // packages/dataviews/build-module/components/dataviews-filters/input-widget.mjs
10558 var import_es6 = __toESM(require_es6(), 1);
10559 var import_compose8 = __toESM(require_compose(), 1);
10560 var import_element25 = __toESM(require_element(), 1);
10561 var import_components20 = __toESM(require_components(), 1);
10562 var import_jsx_runtime61 = __toESM(require_jsx_runtime(), 1);
10563 function InputWidget({
10564 filter,
10565 view,
10566 onChangeView,
10567 fields
10568 }) {
10569 const currentFilter = view.filters?.find(
10570 (f2) => f2.field === filter.field
10571 );
10572 const currentValue = getCurrentValue(filter, currentFilter);
10573 const field = (0, import_element25.useMemo)(() => {
10574 const currentField = fields.find((f2) => f2.id === filter.field);
10575 if (currentField) {
10576 return {
10577 ...currentField,
10578 // Deactivate validation for filters.
10579 isValid: {},
10580 // Configure getValue/setValue as if Item was a plain object.
10581 getValue: ({ item }) => item[currentField.id],
10582 setValue: ({ value }) => ({
10583 [currentField.id]: value
10584 })
10585 };
10586 }
10587 return currentField;
10588 }, [fields, filter.field]);
10589 const data = (0, import_element25.useMemo)(() => {
10590 return (view.filters ?? []).reduce(
10591 (acc, activeFilter) => {
10592 acc[activeFilter.field] = activeFilter.value;
10593 return acc;
10594 },
10595 {}
10596 );
10597 }, [view.filters]);
10598 const handleChange = (0, import_compose8.useEvent)((updatedData) => {
10599 if (!field || !currentFilter) {
10600 return;
10601 }
10602 const nextValue = field.getValue({ item: updatedData });
10603 if ((0, import_es6.default)(nextValue, currentValue)) {
10604 return;
10605 }
10606 onChangeView({
10607 ...view,
10608 filters: (view.filters ?? []).map(
10609 (_filter) => _filter.field === filter.field ? {
10610 ..._filter,
10611 operator: currentFilter.operator || filter.operators[0],
10612 // Consider empty strings as undefined:
10613 //
10614 // - undefined as value means the filter is unset: the filter widget displays no value and the search returns all records
10615 // - empty string as value means "search empty string": returns only the records that have an empty string as value
10616 //
10617 // In practice, this means the filter will not be able to find an empty string as the value.
10618 value: nextValue === "" ? void 0 : nextValue
10619 } : _filter
10620 )
10621 });
10622 });
10623 if (!field || !field.Edit || !currentFilter) {
10624 return null;
10625 }
10626 return /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
10627 import_components20.Flex,
10628 {
10629 className: "dataviews-filters__user-input-widget",
10630 gap: 2.5,
10631 direction: "column",
10632 children: /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
10633 field.Edit,
10634 {
10635 hideLabelFromVision: true,
10636 data,
10637 field,
10638 operator: currentFilter.operator,
10639 onChange: handleChange
10640 }
10641 )
10642 }
10643 );
10644 }
10645
10646 // packages/dataviews/build-module/utils/operators.mjs
10647 var import_i18n28 = __toESM(require_i18n(), 1);
10648 var import_element26 = __toESM(require_element(), 1);
10649 var import_jsx_runtime62 = __toESM(require_jsx_runtime(), 1);
10650 var filterTextWrappers = {
10651 Name: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("span", { className: "dataviews-filters__summary-filter-text-name" }),
10652 Value: /* @__PURE__ */ (0, import_jsx_runtime62.jsx)("span", { className: "dataviews-filters__summary-filter-text-value" })
10653 };
10654 var OPERATORS = [
10655 {
10656 name: OPERATOR_IS_ANY,
10657 /* translators: DataViews operator name */
10658 label: (0, import_i18n28.__)("Includes"),
10659 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10660 (0, import_i18n28.sprintf)(
10661 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is any: Admin, Editor". */
10662 (0, import_i18n28.__)("<Name>%1$s includes: </Name><Value>%2$s</Value>"),
10663 filter.name,
10664 activeElements.map((element) => element.label).join(", ")
10665 ),
10666 filterTextWrappers
10667 ),
10668 selection: "multi"
10669 },
10670 {
10671 name: OPERATOR_IS_NONE,
10672 /* translators: DataViews operator name */
10673 label: (0, import_i18n28.__)("Is none of"),
10674 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10675 (0, import_i18n28.sprintf)(
10676 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is none of: Admin, Editor". */
10677 (0, import_i18n28.__)("<Name>%1$s is none of: </Name><Value>%2$s</Value>"),
10678 filter.name,
10679 activeElements.map((element) => element.label).join(", ")
10680 ),
10681 filterTextWrappers
10682 ),
10683 selection: "multi"
10684 },
10685 {
10686 name: OPERATOR_IS_ALL,
10687 /* translators: DataViews operator name */
10688 label: (0, import_i18n28.__)("Includes all"),
10689 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10690 (0, import_i18n28.sprintf)(
10691 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author includes all: Admin, Editor". */
10692 (0, import_i18n28.__)("<Name>%1$s includes all: </Name><Value>%2$s</Value>"),
10693 filter.name,
10694 activeElements.map((element) => element.label).join(", ")
10695 ),
10696 filterTextWrappers
10697 ),
10698 selection: "multi"
10699 },
10700 {
10701 name: OPERATOR_IS_NOT_ALL,
10702 /* translators: DataViews operator name */
10703 label: (0, import_i18n28.__)("Is none of"),
10704 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10705 (0, import_i18n28.sprintf)(
10706 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is none of: Admin, Editor". */
10707 (0, import_i18n28.__)("<Name>%1$s is none of: </Name><Value>%2$s</Value>"),
10708 filter.name,
10709 activeElements.map((element) => element.label).join(", ")
10710 ),
10711 filterTextWrappers
10712 ),
10713 selection: "multi"
10714 },
10715 {
10716 name: OPERATOR_BETWEEN,
10717 /* translators: DataViews operator name */
10718 label: (0, import_i18n28.__)("Between (inc)"),
10719 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10720 (0, import_i18n28.sprintf)(
10721 /* 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". */
10722 (0, import_i18n28.__)(
10723 "<Name>%1$s between (inc): </Name><Value>%2$s and %3$s</Value>"
10724 ),
10725 filter.name,
10726 activeElements[0].label[0],
10727 activeElements[0].label[1]
10728 ),
10729 filterTextWrappers
10730 ),
10731 selection: "custom"
10732 },
10733 {
10734 name: OPERATOR_IN_THE_PAST,
10735 /* translators: DataViews operator name */
10736 label: (0, import_i18n28.__)("In the past"),
10737 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10738 (0, import_i18n28.sprintf)(
10739 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "7 days"): "Date is in the past: 7 days". */
10740 (0, import_i18n28.__)(
10741 "<Name>%1$s is in the past: </Name><Value>%2$s</Value>"
10742 ),
10743 filter.name,
10744 `${activeElements[0].value.value} ${activeElements[0].value.unit}`
10745 ),
10746 filterTextWrappers
10747 ),
10748 selection: "custom"
10749 },
10750 {
10751 name: OPERATOR_OVER,
10752 /* translators: DataViews operator name */
10753 label: (0, import_i18n28.__)("Over"),
10754 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10755 (0, import_i18n28.sprintf)(
10756 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "7 days"): "Date is over: 7 days". */
10757 (0, import_i18n28.__)("<Name>%1$s is over: </Name><Value>%2$s</Value>"),
10758 filter.name,
10759 `${activeElements[0].value.value} ${activeElements[0].value.unit}`
10760 ),
10761 filterTextWrappers
10762 ),
10763 selection: "custom"
10764 },
10765 {
10766 name: OPERATOR_IS,
10767 /* translators: DataViews operator name */
10768 label: (0, import_i18n28.__)("Is"),
10769 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10770 (0, import_i18n28.sprintf)(
10771 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is: Admin". */
10772 (0, import_i18n28.__)("<Name>%1$s is: </Name><Value>%2$s</Value>"),
10773 filter.name,
10774 activeElements[0].label
10775 ),
10776 filterTextWrappers
10777 ),
10778 selection: "single"
10779 },
10780 {
10781 name: OPERATOR_IS_NOT,
10782 /* translators: DataViews operator name */
10783 label: (0, import_i18n28.__)("Is not"),
10784 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10785 (0, import_i18n28.sprintf)(
10786 /* translators: 1: Filter name (e.g. "Author"). 2: Filter value (e.g. "Admin"): "Author is not: Admin". */
10787 (0, import_i18n28.__)("<Name>%1$s is not: </Name><Value>%2$s</Value>"),
10788 filter.name,
10789 activeElements[0].label
10790 ),
10791 filterTextWrappers
10792 ),
10793 selection: "single"
10794 },
10795 {
10796 name: OPERATOR_LESS_THAN,
10797 /* translators: DataViews operator name */
10798 label: (0, import_i18n28.__)("Less than"),
10799 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10800 (0, import_i18n28.sprintf)(
10801 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is less than: 10". */
10802 (0, import_i18n28.__)("<Name>%1$s is less than: </Name><Value>%2$s</Value>"),
10803 filter.name,
10804 activeElements[0].label
10805 ),
10806 filterTextWrappers
10807 ),
10808 selection: "single"
10809 },
10810 {
10811 name: OPERATOR_GREATER_THAN,
10812 /* translators: DataViews operator name */
10813 label: (0, import_i18n28.__)("Greater than"),
10814 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10815 (0, import_i18n28.sprintf)(
10816 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is greater than: 10". */
10817 (0, import_i18n28.__)(
10818 "<Name>%1$s is greater than: </Name><Value>%2$s</Value>"
10819 ),
10820 filter.name,
10821 activeElements[0].label
10822 ),
10823 filterTextWrappers
10824 ),
10825 selection: "single"
10826 },
10827 {
10828 name: OPERATOR_LESS_THAN_OR_EQUAL,
10829 /* translators: DataViews operator name */
10830 label: (0, import_i18n28.__)("Less than or equal"),
10831 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10832 (0, import_i18n28.sprintf)(
10833 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is less than or equal to: 10". */
10834 (0, import_i18n28.__)(
10835 "<Name>%1$s is less than or equal to: </Name><Value>%2$s</Value>"
10836 ),
10837 filter.name,
10838 activeElements[0].label
10839 ),
10840 filterTextWrappers
10841 ),
10842 selection: "single"
10843 },
10844 {
10845 name: OPERATOR_GREATER_THAN_OR_EQUAL,
10846 /* translators: DataViews operator name */
10847 label: (0, import_i18n28.__)("Greater than or equal"),
10848 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10849 (0, import_i18n28.sprintf)(
10850 /* translators: 1: Filter name (e.g. "Count"). 2: Filter value (e.g. "10"): "Count is greater than or equal to: 10". */
10851 (0, import_i18n28.__)(
10852 "<Name>%1$s is greater than or equal to: </Name><Value>%2$s</Value>"
10853 ),
10854 filter.name,
10855 activeElements[0].label
10856 ),
10857 filterTextWrappers
10858 ),
10859 selection: "single"
10860 },
10861 {
10862 name: OPERATOR_BEFORE,
10863 /* translators: DataViews operator name */
10864 label: (0, import_i18n28.__)("Before"),
10865 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10866 (0, import_i18n28.sprintf)(
10867 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is before: 2024-01-01". */
10868 (0, import_i18n28.__)("<Name>%1$s is before: </Name><Value>%2$s</Value>"),
10869 filter.name,
10870 activeElements[0].label
10871 ),
10872 filterTextWrappers
10873 ),
10874 selection: "single"
10875 },
10876 {
10877 name: OPERATOR_AFTER,
10878 /* translators: DataViews operator name */
10879 label: (0, import_i18n28.__)("After"),
10880 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10881 (0, import_i18n28.sprintf)(
10882 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is after: 2024-01-01". */
10883 (0, import_i18n28.__)("<Name>%1$s is after: </Name><Value>%2$s</Value>"),
10884 filter.name,
10885 activeElements[0].label
10886 ),
10887 filterTextWrappers
10888 ),
10889 selection: "single"
10890 },
10891 {
10892 name: OPERATOR_BEFORE_INC,
10893 /* translators: DataViews operator name */
10894 label: (0, import_i18n28.__)("Before (inc)"),
10895 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10896 (0, import_i18n28.sprintf)(
10897 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is on or before: 2024-01-01". */
10898 (0, import_i18n28.__)(
10899 "<Name>%1$s is on or before: </Name><Value>%2$s</Value>"
10900 ),
10901 filter.name,
10902 activeElements[0].label
10903 ),
10904 filterTextWrappers
10905 ),
10906 selection: "single"
10907 },
10908 {
10909 name: OPERATOR_AFTER_INC,
10910 /* translators: DataViews operator name */
10911 label: (0, import_i18n28.__)("After (inc)"),
10912 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10913 (0, import_i18n28.sprintf)(
10914 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is on or after: 2024-01-01". */
10915 (0, import_i18n28.__)(
10916 "<Name>%1$s is on or after: </Name><Value>%2$s</Value>"
10917 ),
10918 filter.name,
10919 activeElements[0].label
10920 ),
10921 filterTextWrappers
10922 ),
10923 selection: "single"
10924 },
10925 {
10926 name: OPERATOR_CONTAINS,
10927 /* translators: DataViews operator name */
10928 label: (0, import_i18n28.__)("Contains"),
10929 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10930 (0, import_i18n28.sprintf)(
10931 /* translators: 1: Filter name (e.g. "Title"). 2: Filter value (e.g. "Hello"): "Title contains: Hello". */
10932 (0, import_i18n28.__)("<Name>%1$s contains: </Name><Value>%2$s</Value>"),
10933 filter.name,
10934 activeElements[0].label
10935 ),
10936 filterTextWrappers
10937 ),
10938 selection: "single"
10939 },
10940 {
10941 name: OPERATOR_NOT_CONTAINS,
10942 /* translators: DataViews operator name */
10943 label: (0, import_i18n28.__)("Doesn't contain"),
10944 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10945 (0, import_i18n28.sprintf)(
10946 /* translators: 1: Filter name (e.g. "Title"). 2: Filter value (e.g. "Hello"): "Title doesn't contain: Hello". */
10947 (0, import_i18n28.__)(
10948 "<Name>%1$s doesn't contain: </Name><Value>%2$s</Value>"
10949 ),
10950 filter.name,
10951 activeElements[0].label
10952 ),
10953 filterTextWrappers
10954 ),
10955 selection: "single"
10956 },
10957 {
10958 name: OPERATOR_STARTS_WITH,
10959 /* translators: DataViews operator name */
10960 label: (0, import_i18n28.__)("Starts with"),
10961 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10962 (0, import_i18n28.sprintf)(
10963 /* translators: 1: Filter name (e.g. "Title"). 2: Filter value (e.g. "Hello"): "Title starts with: Hello". */
10964 (0, import_i18n28.__)("<Name>%1$s starts with: </Name><Value>%2$s</Value>"),
10965 filter.name,
10966 activeElements[0].label
10967 ),
10968 filterTextWrappers
10969 ),
10970 selection: "single"
10971 },
10972 {
10973 name: OPERATOR_ON,
10974 /* translators: DataViews operator name */
10975 label: (0, import_i18n28.__)("On"),
10976 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10977 (0, import_i18n28.sprintf)(
10978 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is: 2024-01-01". */
10979 (0, import_i18n28.__)("<Name>%1$s is: </Name><Value>%2$s</Value>"),
10980 filter.name,
10981 activeElements[0].label
10982 ),
10983 filterTextWrappers
10984 ),
10985 selection: "single"
10986 },
10987 {
10988 name: OPERATOR_NOT_ON,
10989 /* translators: DataViews operator name */
10990 label: (0, import_i18n28.__)("Not on"),
10991 filterText: (filter, activeElements) => (0, import_element26.createInterpolateElement)(
10992 (0, import_i18n28.sprintf)(
10993 /* translators: 1: Filter name (e.g. "Date"). 2: Filter value (e.g. "2024-01-01"): "Date is not: 2024-01-01". */
10994 (0, import_i18n28.__)("<Name>%1$s is not: </Name><Value>%2$s</Value>"),
10995 filter.name,
10996 activeElements[0].label
10997 ),
10998 filterTextWrappers
10999 ),
11000 selection: "single"
11001 }
11002 ];
11003 var getOperatorByName = (name) => OPERATORS.find((op) => op.name === name);
11004 var getAllOperatorNames = () => OPERATORS.map((op) => op.name);
11005 var isSingleSelectionOperator = (name) => OPERATORS.filter((op) => op.selection === "single").some(
11006 (op) => op.name === name
11007 );
11008 var isRegisteredOperator = (name) => OPERATORS.some((op) => op.name === name);
11009
11010 // packages/dataviews/build-module/components/dataviews-filters/filter.mjs
11011 var import_jsx_runtime63 = __toESM(require_jsx_runtime(), 1);
11012 var ENTER = "Enter";
11013 var SPACE = " ";
11014 var FilterText = ({
11015 activeElements,
11016 filterInView,
11017 filter
11018 }) => {
11019 if (activeElements === void 0 || activeElements.length === 0) {
11020 return filter.name;
11021 }
11022 const operator = getOperatorByName(filterInView?.operator);
11023 if (operator !== void 0) {
11024 return operator.filterText(filter, activeElements);
11025 }
11026 return (0, import_i18n29.sprintf)(
11027 /* translators: 1: Filter name e.g.: "Unknown status for Author". */
11028 (0, import_i18n29.__)("Unknown status for %1$s"),
11029 filter.name
11030 );
11031 };
11032 function OperatorSelector({
11033 filter,
11034 view,
11035 onChangeView
11036 }) {
11037 const operatorOptions = filter.operators?.map((operator) => ({
11038 value: operator,
11039 label: getOperatorByName(operator)?.label || operator
11040 }));
11041 const currentFilter = view.filters?.find(
11042 (_filter) => _filter.field === filter.field
11043 );
11044 const value = currentFilter?.operator || filter.operators[0];
11045 return operatorOptions.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime63.jsxs)(
11046 Stack,
11047 {
11048 direction: "row",
11049 gap: "xs",
11050 justify: "flex-start",
11051 className: "dataviews-filters__summary-operators-container",
11052 align: "center",
11053 children: [
11054 /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(import_components21.FlexItem, { className: "dataviews-filters__summary-operators-filter-name", children: filter.name }),
11055 /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
11056 import_components21.SelectControl,
11057 {
11058 className: "dataviews-filters__summary-operators-filter-select",
11059 label: (0, import_i18n29.__)("Conditions"),
11060 value,
11061 options: operatorOptions,
11062 onChange: (newValue) => {
11063 const newOperator = newValue;
11064 const currentOperator = currentFilter?.operator;
11065 const newFilters = currentFilter ? [
11066 ...(view.filters ?? []).map(
11067 (_filter) => {
11068 if (_filter.field === filter.field) {
11069 const currentOpSelectionModel = getOperatorByName(
11070 currentOperator
11071 )?.selection;
11072 const newOpSelectionModel = getOperatorByName(
11073 newOperator
11074 )?.selection;
11075 const shouldResetValue = currentOpSelectionModel !== newOpSelectionModel || [
11076 currentOpSelectionModel,
11077 newOpSelectionModel
11078 ].includes("custom");
11079 return {
11080 ..._filter,
11081 value: shouldResetValue ? void 0 : _filter.value,
11082 operator: newOperator
11083 };
11084 }
11085 return _filter;
11086 }
11087 )
11088 ] : [
11089 ...view.filters ?? [],
11090 {
11091 field: filter.field,
11092 operator: newOperator,
11093 value: void 0
11094 }
11095 ];
11096 onChangeView({
11097 ...view,
11098 page: 1,
11099 filters: newFilters
11100 });
11101 },
11102 size: "small",
11103 variant: "minimal",
11104 hideLabelFromVision: true
11105 }
11106 )
11107 ]
11108 }
11109 );
11110 }
11111 function Filter({
11112 addFilterRef,
11113 openedFilter,
11114 fields,
11115 ...commonProps
11116 }) {
11117 const toggleRef = (0, import_element27.useRef)(null);
11118 const { filter, view, onChangeView } = commonProps;
11119 const filterInView = view.filters?.find(
11120 (f2) => f2.field === filter.field
11121 );
11122 let activeElements = [];
11123 const field = (0, import_element27.useMemo)(() => {
11124 const currentField = fields.find((f2) => f2.id === filter.field);
11125 if (currentField) {
11126 return {
11127 ...currentField,
11128 // Configure getValue as if Item was a plain object.
11129 // See related input-widget.tsx
11130 getValue: ({ item }) => item[currentField.id]
11131 };
11132 }
11133 return currentField;
11134 }, [fields, filter.field]);
11135 const { elements } = useElements({
11136 elements: filter.elements,
11137 getElements: filter.getElements
11138 });
11139 if (elements.length > 0) {
11140 activeElements = elements.filter((element) => {
11141 if (filter.singleSelection) {
11142 return element.value === filterInView?.value;
11143 }
11144 return filterInView?.value?.includes(element.value);
11145 });
11146 } else if (Array.isArray(filterInView?.value)) {
11147 const label = filterInView.value.map((v2) => {
11148 const formattedValue = field?.getValueFormatted({
11149 item: { [field.id]: v2 },
11150 field
11151 });
11152 return formattedValue || String(v2);
11153 });
11154 activeElements = [
11155 {
11156 value: filterInView.value,
11157 // @ts-ignore
11158 label
11159 }
11160 ];
11161 } else if (typeof filterInView?.value === "object") {
11162 activeElements = [
11163 { value: filterInView.value, label: filterInView.value }
11164 ];
11165 } else if (filterInView?.value !== void 0) {
11166 const label = field !== void 0 ? field.getValueFormatted({
11167 item: { [field.id]: filterInView.value },
11168 field
11169 }) : String(filterInView.value);
11170 activeElements = [
11171 {
11172 value: filterInView.value,
11173 label
11174 }
11175 ];
11176 }
11177 const isPrimary = filter.isPrimary;
11178 const isLocked = filterInView?.isLocked;
11179 const hasValues = !isLocked && filterInView?.value !== void 0;
11180 const canResetOrRemove = !isLocked && (!isPrimary || hasValues);
11181 return /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
11182 import_components21.Dropdown,
11183 {
11184 defaultOpen: openedFilter === filter.field,
11185 contentClassName: "dataviews-filters__summary-popover",
11186 popoverProps: { placement: "bottom-start", role: "dialog" },
11187 onClose: () => {
11188 toggleRef.current?.focus();
11189 },
11190 renderToggle: ({ isOpen, onToggle }) => /* @__PURE__ */ (0, import_jsx_runtime63.jsxs)("div", { className: "dataviews-filters__summary-chip-container", children: [
11191 /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
11192 import_components21.Tooltip,
11193 {
11194 text: (0, import_i18n29.sprintf)(
11195 /* translators: 1: Filter name. */
11196 (0, import_i18n29.__)("Filter by: %1$s"),
11197 filter.name.toLowerCase()
11198 ),
11199 placement: "top",
11200 children: /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
11201 "div",
11202 {
11203 className: clsx_default(
11204 "dataviews-filters__summary-chip",
11205 {
11206 "has-reset": canResetOrRemove,
11207 "has-values": hasValues,
11208 "is-not-clickable": isLocked
11209 }
11210 ),
11211 role: "button",
11212 tabIndex: isLocked ? -1 : 0,
11213 onClick: () => {
11214 if (!isLocked) {
11215 onToggle();
11216 }
11217 },
11218 onKeyDown: (event) => {
11219 if (!isLocked && [ENTER, SPACE].includes(event.key)) {
11220 onToggle();
11221 event.preventDefault();
11222 }
11223 },
11224 "aria-disabled": isLocked,
11225 "aria-pressed": isOpen,
11226 "aria-expanded": isOpen,
11227 ref: toggleRef,
11228 children: /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
11229 FilterText,
11230 {
11231 activeElements,
11232 filterInView,
11233 filter
11234 }
11235 )
11236 }
11237 )
11238 }
11239 ),
11240 canResetOrRemove && /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
11241 import_components21.Tooltip,
11242 {
11243 text: isPrimary ? (0, import_i18n29.__)("Reset") : (0, import_i18n29.__)("Remove"),
11244 placement: "top",
11245 children: /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
11246 "button",
11247 {
11248 className: clsx_default(
11249 "dataviews-filters__summary-chip-remove",
11250 { "has-values": hasValues }
11251 ),
11252 onClick: () => {
11253 onChangeView({
11254 ...view,
11255 page: 1,
11256 filters: view.filters?.filter(
11257 (_filter) => _filter.field !== filter.field
11258 )
11259 });
11260 if (!isPrimary) {
11261 addFilterRef.current?.focus();
11262 } else {
11263 toggleRef.current?.focus();
11264 }
11265 },
11266 children: /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(import_components21.Icon, { icon: close_small_default })
11267 }
11268 )
11269 }
11270 )
11271 ] }),
11272 renderContent: () => {
11273 return /* @__PURE__ */ (0, import_jsx_runtime63.jsxs)(Stack, { direction: "column", justify: "flex-start", children: [
11274 /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(OperatorSelector, { ...commonProps }),
11275 commonProps.filter.hasElements ? /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(
11276 SearchWidget,
11277 {
11278 ...commonProps,
11279 filter: {
11280 ...commonProps.filter,
11281 elements
11282 }
11283 }
11284 ) : /* @__PURE__ */ (0, import_jsx_runtime63.jsx)(InputWidget, { ...commonProps, fields })
11285 ] });
11286 }
11287 }
11288 );
11289 }
11290
11291 // packages/dataviews/build-module/components/dataviews-filters/add-filter.mjs
11292 var import_components22 = __toESM(require_components(), 1);
11293 var import_i18n30 = __toESM(require_i18n(), 1);
11294 var import_element28 = __toESM(require_element(), 1);
11295 var import_jsx_runtime64 = __toESM(require_jsx_runtime(), 1);
11296 var { Menu: Menu4 } = unlock(import_components22.privateApis);
11297 function AddFilterMenu({
11298 filters,
11299 view,
11300 onChangeView,
11301 setOpenedFilter,
11302 triggerProps
11303 }) {
11304 const inactiveFilters = filters.filter((filter) => !filter.isVisible);
11305 return /* @__PURE__ */ (0, import_jsx_runtime64.jsxs)(Menu4, { children: [
11306 /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(Menu4.TriggerButton, { ...triggerProps }),
11307 /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(Menu4.Popover, { children: inactiveFilters.map((filter) => {
11308 return /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(
11309 Menu4.Item,
11310 {
11311 onClick: () => {
11312 setOpenedFilter(filter.field);
11313 onChangeView({
11314 ...view,
11315 page: 1,
11316 filters: [
11317 ...view.filters || [],
11318 {
11319 field: filter.field,
11320 value: void 0,
11321 operator: filter.operators[0]
11322 }
11323 ]
11324 });
11325 },
11326 children: /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(Menu4.ItemLabel, { children: filter.name })
11327 },
11328 filter.field
11329 );
11330 }) })
11331 ] });
11332 }
11333 function AddFilter({ filters, view, onChangeView, setOpenedFilter }, ref) {
11334 if (!filters.length || filters.every(({ isPrimary }) => isPrimary)) {
11335 return null;
11336 }
11337 const inactiveFilters = filters.filter((filter) => !filter.isVisible);
11338 return /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(
11339 AddFilterMenu,
11340 {
11341 triggerProps: {
11342 render: /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(
11343 import_components22.Button,
11344 {
11345 accessibleWhenDisabled: true,
11346 size: "compact",
11347 className: "dataviews-filters-button",
11348 variant: "tertiary",
11349 disabled: !inactiveFilters.length,
11350 ref
11351 }
11352 ),
11353 children: (0, import_i18n30.__)("Add filter")
11354 },
11355 ...{ filters, view, onChangeView, setOpenedFilter }
11356 }
11357 );
11358 }
11359 var add_filter_default = (0, import_element28.forwardRef)(AddFilter);
11360
11361 // packages/dataviews/build-module/components/dataviews-filters/reset-filters.mjs
11362 var import_components23 = __toESM(require_components(), 1);
11363 var import_i18n31 = __toESM(require_i18n(), 1);
11364 var import_jsx_runtime65 = __toESM(require_jsx_runtime(), 1);
11365 function ResetFilter({
11366 filters,
11367 view,
11368 onChangeView
11369 }) {
11370 const isPrimary = (field) => filters.some(
11371 (_filter) => _filter.field === field && _filter.isPrimary
11372 );
11373 const isDisabled = !view.search && !view.filters?.some(
11374 (_filter) => !_filter.isLocked && (_filter.value !== void 0 || !isPrimary(_filter.field))
11375 );
11376 return /* @__PURE__ */ (0, import_jsx_runtime65.jsx)(
11377 import_components23.Button,
11378 {
11379 disabled: isDisabled,
11380 accessibleWhenDisabled: true,
11381 size: "compact",
11382 variant: "tertiary",
11383 className: "dataviews-filters__reset-button",
11384 onClick: () => {
11385 onChangeView({
11386 ...view,
11387 page: 1,
11388 search: "",
11389 filters: view.filters?.filter((f2) => !!f2.isLocked) || []
11390 });
11391 },
11392 children: (0, import_i18n31.__)("Reset")
11393 }
11394 );
11395 }
11396
11397 // packages/dataviews/build-module/components/dataviews-filters/use-filters.mjs
11398 var import_element29 = __toESM(require_element(), 1);
11399 function useFilters(fields, view) {
11400 return (0, import_element29.useMemo)(() => {
11401 const filters = [];
11402 fields.forEach((field) => {
11403 if (field.filterBy === false || !field.hasElements && !field.Edit) {
11404 return;
11405 }
11406 const operators = field.filterBy.operators;
11407 const isPrimary = !!field.filterBy?.isPrimary;
11408 const isLocked = view.filters?.some(
11409 (f2) => f2.field === field.id && !!f2.isLocked
11410 ) ?? false;
11411 filters.push({
11412 field: field.id,
11413 name: field.label,
11414 elements: field.elements,
11415 getElements: field.getElements,
11416 hasElements: field.hasElements,
11417 singleSelection: operators.some(
11418 (op) => isSingleSelectionOperator(op)
11419 ),
11420 operators,
11421 isVisible: isLocked || isPrimary || !!view.filters?.some(
11422 (f2) => f2.field === field.id && isRegisteredOperator(f2.operator)
11423 ),
11424 isPrimary,
11425 isLocked
11426 });
11427 });
11428 filters.sort((a2, b2) => {
11429 if (a2.isLocked && !b2.isLocked) {
11430 return -1;
11431 }
11432 if (!a2.isLocked && b2.isLocked) {
11433 return 1;
11434 }
11435 if (a2.isPrimary && !b2.isPrimary) {
11436 return -1;
11437 }
11438 if (!a2.isPrimary && b2.isPrimary) {
11439 return 1;
11440 }
11441 return a2.name.localeCompare(b2.name);
11442 });
11443 return filters;
11444 }, [fields, view]);
11445 }
11446 var use_filters_default = useFilters;
11447
11448 // packages/dataviews/build-module/components/dataviews-filters/filters.mjs
11449 var import_jsx_runtime66 = __toESM(require_jsx_runtime(), 1);
11450 function Filters({ className }) {
11451 const { fields, view, onChangeView, openedFilter, setOpenedFilter } = (0, import_element30.useContext)(dataviews_context_default);
11452 const addFilterRef = (0, import_element30.useRef)(null);
11453 const filters = use_filters_default(fields, view);
11454 const addFilter = /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
11455 add_filter_default,
11456 {
11457 filters,
11458 view,
11459 onChangeView,
11460 ref: addFilterRef,
11461 setOpenedFilter
11462 },
11463 "add-filter"
11464 );
11465 const visibleFilters = filters.filter((filter) => filter.isVisible);
11466 if (visibleFilters.length === 0) {
11467 return null;
11468 }
11469 const filterComponents = [
11470 ...visibleFilters.map((filter) => {
11471 return /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
11472 Filter,
11473 {
11474 filter,
11475 view,
11476 fields,
11477 onChangeView,
11478 addFilterRef,
11479 openedFilter
11480 },
11481 filter.field
11482 );
11483 }),
11484 addFilter
11485 ];
11486 filterComponents.push(
11487 /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
11488 ResetFilter,
11489 {
11490 filters,
11491 view,
11492 onChangeView
11493 },
11494 "reset-filters"
11495 )
11496 );
11497 return /* @__PURE__ */ (0, import_jsx_runtime66.jsx)(
11498 Stack,
11499 {
11500 direction: "row",
11501 justify: "flex-start",
11502 gap: "xs",
11503 style: { width: "fit-content" },
11504 wrap: "wrap",
11505 className,
11506 children: filterComponents
11507 }
11508 );
11509 }
11510 var filters_default = (0, import_element30.memo)(Filters);
11511
11512 // packages/dataviews/build-module/components/dataviews-filters/toggle.mjs
11513 var import_element31 = __toESM(require_element(), 1);
11514 var import_components24 = __toESM(require_components(), 1);
11515 var import_i18n32 = __toESM(require_i18n(), 1);
11516 var import_jsx_runtime67 = __toESM(require_jsx_runtime(), 1);
11517 function FiltersToggle() {
11518 const {
11519 filters,
11520 view,
11521 onChangeView,
11522 setOpenedFilter,
11523 isShowingFilter,
11524 setIsShowingFilter
11525 } = (0, import_element31.useContext)(dataviews_context_default);
11526 const buttonRef = (0, import_element31.useRef)(null);
11527 const onChangeViewWithFilterVisibility = (0, import_element31.useCallback)(
11528 (_view) => {
11529 onChangeView(_view);
11530 setIsShowingFilter(true);
11531 },
11532 [onChangeView, setIsShowingFilter]
11533 );
11534 const visibleFilters = filters.filter((filter) => filter.isVisible);
11535 const hasVisibleFilters = !!visibleFilters.length;
11536 if (filters.length === 0) {
11537 return null;
11538 }
11539 const addFilterButtonProps = {
11540 label: (0, import_i18n32.__)("Add filter"),
11541 "aria-expanded": false,
11542 isPressed: false
11543 };
11544 const toggleFiltersButtonProps = {
11545 label: (0, import_i18n32._x)("Filter", "verb"),
11546 "aria-expanded": isShowingFilter,
11547 isPressed: isShowingFilter,
11548 onClick: () => {
11549 if (!isShowingFilter) {
11550 setOpenedFilter(null);
11551 }
11552 setIsShowingFilter(!isShowingFilter);
11553 }
11554 };
11555 const buttonComponent = /* @__PURE__ */ (0, import_jsx_runtime67.jsx)(
11556 import_components24.Button,
11557 {
11558 ref: buttonRef,
11559 className: "dataviews-filters__visibility-toggle",
11560 size: "compact",
11561 icon: funnel_default,
11562 ...hasVisibleFilters ? toggleFiltersButtonProps : addFilterButtonProps
11563 }
11564 );
11565 return /* @__PURE__ */ (0, import_jsx_runtime67.jsx)("div", { className: "dataviews-filters__container-visibility-toggle", children: !hasVisibleFilters ? /* @__PURE__ */ (0, import_jsx_runtime67.jsx)(
11566 AddFilterMenu,
11567 {
11568 filters,
11569 view,
11570 onChangeView: onChangeViewWithFilterVisibility,
11571 setOpenedFilter,
11572 triggerProps: { render: buttonComponent }
11573 }
11574 ) : /* @__PURE__ */ (0, import_jsx_runtime67.jsx)(
11575 FilterVisibilityToggle,
11576 {
11577 buttonRef,
11578 filtersCount: view.filters?.length,
11579 children: buttonComponent
11580 }
11581 ) });
11582 }
11583 function FilterVisibilityToggle({
11584 buttonRef,
11585 filtersCount,
11586 children
11587 }) {
11588 (0, import_element31.useEffect)(
11589 () => () => {
11590 buttonRef.current?.focus();
11591 },
11592 [buttonRef]
11593 );
11594 return /* @__PURE__ */ (0, import_jsx_runtime67.jsxs)(import_jsx_runtime67.Fragment, { children: [
11595 children,
11596 !!filtersCount && /* @__PURE__ */ (0, import_jsx_runtime67.jsx)("span", { className: "dataviews-filters-toggle__count", children: filtersCount })
11597 ] });
11598 }
11599 var toggle_default = FiltersToggle;
11600
11601 // packages/dataviews/build-module/components/dataviews-filters/filters-toggled.mjs
11602 var import_element32 = __toESM(require_element(), 1);
11603 var import_jsx_runtime68 = __toESM(require_jsx_runtime(), 1);
11604 function FiltersToggled(props) {
11605 const { isShowingFilter } = (0, import_element32.useContext)(dataviews_context_default);
11606 if (!isShowingFilter) {
11607 return null;
11608 }
11609 return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(filters_default, { ...props });
11610 }
11611 var filters_toggled_default = FiltersToggled;
11612
11613 // packages/dataviews/build-module/components/dataviews-layout/index.mjs
11614 var import_element33 = __toESM(require_element(), 1);
11615 var import_i18n33 = __toESM(require_i18n(), 1);
11616 var import_jsx_runtime69 = __toESM(require_jsx_runtime(), 1);
11617 function DataViewsLayout({ className }) {
11618 const {
11619 actions = [],
11620 data,
11621 fields,
11622 getItemId,
11623 getItemLevel,
11624 isLoading,
11625 view,
11626 onChangeView,
11627 selection,
11628 onChangeSelection,
11629 setOpenedFilter,
11630 onClickItem,
11631 isItemClickable: isItemClickable2,
11632 renderItemLink,
11633 defaultLayouts,
11634 empty = /* @__PURE__ */ (0, import_jsx_runtime69.jsx)("p", { children: (0, import_i18n33.__)("No results") })
11635 } = (0, import_element33.useContext)(dataviews_context_default);
11636 const ViewComponent = VIEW_LAYOUTS.find(
11637 (v2) => v2.type === view.type && defaultLayouts[v2.type]
11638 )?.component;
11639 return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
11640 ViewComponent,
11641 {
11642 className,
11643 actions,
11644 data,
11645 fields,
11646 getItemId,
11647 getItemLevel,
11648 isLoading,
11649 onChangeView,
11650 onChangeSelection,
11651 selection,
11652 setOpenedFilter,
11653 onClickItem,
11654 renderItemLink,
11655 isItemClickable: isItemClickable2,
11656 view,
11657 empty
11658 }
11659 );
11660 }
11661
11662 // packages/dataviews/build-module/components/dataviews-search/index.mjs
11663 var import_i18n34 = __toESM(require_i18n(), 1);
11664 var import_element34 = __toESM(require_element(), 1);
11665 var import_components25 = __toESM(require_components(), 1);
11666 var import_compose9 = __toESM(require_compose(), 1);
11667 var import_jsx_runtime70 = __toESM(require_jsx_runtime(), 1);
11668 var DataViewsSearch = (0, import_element34.memo)(function Search({ label }) {
11669 const { view, onChangeView } = (0, import_element34.useContext)(dataviews_context_default);
11670 const [search, setSearch, debouncedSearch] = (0, import_compose9.useDebouncedInput)(
11671 view.search
11672 );
11673 (0, import_element34.useEffect)(() => {
11674 setSearch(view.search ?? "");
11675 }, [view.search, setSearch]);
11676 const onChangeViewRef = (0, import_element34.useRef)(onChangeView);
11677 const viewRef = (0, import_element34.useRef)(view);
11678 (0, import_element34.useEffect)(() => {
11679 onChangeViewRef.current = onChangeView;
11680 viewRef.current = view;
11681 }, [onChangeView, view]);
11682 (0, import_element34.useEffect)(() => {
11683 if (debouncedSearch !== viewRef.current?.search) {
11684 onChangeViewRef.current({
11685 ...viewRef.current,
11686 page: 1,
11687 search: debouncedSearch
11688 });
11689 }
11690 }, [debouncedSearch]);
11691 const searchLabel = label || (0, import_i18n34.__)("Search");
11692 return /* @__PURE__ */ (0, import_jsx_runtime70.jsx)(
11693 import_components25.SearchControl,
11694 {
11695 className: "dataviews-search",
11696 onChange: setSearch,
11697 value: search,
11698 label: searchLabel,
11699 placeholder: searchLabel,
11700 size: "compact"
11701 }
11702 );
11703 });
11704 var dataviews_search_default = DataViewsSearch;
11705
11706 // packages/dataviews/build-module/components/dataviews-view-config/index.mjs
11707 var import_components27 = __toESM(require_components(), 1);
11708 var import_i18n36 = __toESM(require_i18n(), 1);
11709 var import_element36 = __toESM(require_element(), 1);
11710 var import_warning = __toESM(require_warning(), 1);
11711 var import_compose10 = __toESM(require_compose(), 1);
11712
11713 // packages/dataviews/build-module/components/dataviews-view-config/infinite-scroll-toggle.mjs
11714 var import_components26 = __toESM(require_components(), 1);
11715 var import_i18n35 = __toESM(require_i18n(), 1);
11716 var import_element35 = __toESM(require_element(), 1);
11717 var import_jsx_runtime71 = __toESM(require_jsx_runtime(), 1);
11718 function InfiniteScrollToggle() {
11719 const context = (0, import_element35.useContext)(dataviews_context_default);
11720 const { view, onChangeView } = context;
11721 const infiniteScrollEnabled = view.infiniteScrollEnabled ?? false;
11722 if (!context.hasInfiniteScrollHandler) {
11723 return null;
11724 }
11725 return /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(
11726 import_components26.ToggleControl,
11727 {
11728 label: (0, import_i18n35.__)("Enable infinite scroll"),
11729 help: (0, import_i18n35.__)(
11730 "Automatically load more content as you scroll, instead of showing pagination links."
11731 ),
11732 checked: infiniteScrollEnabled,
11733 onChange: (newValue) => {
11734 onChangeView({
11735 ...view,
11736 infiniteScrollEnabled: newValue
11737 });
11738 }
11739 }
11740 );
11741 }
11742
11743 // packages/dataviews/build-module/components/dataviews-view-config/index.mjs
11744 var import_jsx_runtime72 = __toESM(require_jsx_runtime(), 1);
11745 var { Menu: Menu5 } = unlock(import_components27.privateApis);
11746 var DATAVIEWS_CONFIG_POPOVER_PROPS = {
11747 className: "dataviews-config__popover",
11748 placement: "bottom-end",
11749 offset: 9
11750 };
11751 function ViewTypeMenu() {
11752 const { view, onChangeView, defaultLayouts } = (0, import_element36.useContext)(dataviews_context_default);
11753 const availableLayouts = Object.keys(defaultLayouts);
11754 if (availableLayouts.length <= 1) {
11755 return null;
11756 }
11757 const activeView = VIEW_LAYOUTS.find((v2) => view.type === v2.type);
11758 return /* @__PURE__ */ (0, import_jsx_runtime72.jsxs)(Menu5, { children: [
11759 /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
11760 Menu5.TriggerButton,
11761 {
11762 render: /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
11763 import_components27.Button,
11764 {
11765 size: "compact",
11766 icon: activeView?.icon,
11767 label: (0, import_i18n36.__)("Layout")
11768 }
11769 )
11770 }
11771 ),
11772 /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(Menu5.Popover, { children: availableLayouts.map((layout) => {
11773 const config = VIEW_LAYOUTS.find(
11774 (v2) => v2.type === layout
11775 );
11776 if (!config) {
11777 return null;
11778 }
11779 return /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
11780 Menu5.RadioItem,
11781 {
11782 value: layout,
11783 name: "view-actions-available-view",
11784 checked: layout === view.type,
11785 hideOnClick: true,
11786 onChange: (e2) => {
11787 switch (e2.target.value) {
11788 case "list":
11789 case "grid":
11790 case "table":
11791 case "pickerGrid":
11792 case "pickerTable":
11793 case "activity":
11794 const viewWithoutLayout = { ...view };
11795 if ("layout" in viewWithoutLayout) {
11796 delete viewWithoutLayout.layout;
11797 }
11798 return onChangeView({
11799 ...viewWithoutLayout,
11800 type: e2.target.value,
11801 ...defaultLayouts[e2.target.value]
11802 });
11803 }
11804 (0, import_warning.default)("Invalid dataview");
11805 },
11806 children: /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(Menu5.ItemLabel, { children: config.label })
11807 },
11808 layout
11809 );
11810 }) })
11811 ] });
11812 }
11813 function SortFieldControl() {
11814 const { view, fields, onChangeView } = (0, import_element36.useContext)(dataviews_context_default);
11815 const orderOptions = (0, import_element36.useMemo)(() => {
11816 const sortableFields = fields.filter(
11817 (field) => field.enableSorting !== false
11818 );
11819 return sortableFields.map((field) => {
11820 return {
11821 label: field.label,
11822 value: field.id
11823 };
11824 });
11825 }, [fields]);
11826 return /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
11827 import_components27.SelectControl,
11828 {
11829 __next40pxDefaultSize: true,
11830 label: (0, import_i18n36.__)("Sort by"),
11831 value: view.sort?.field,
11832 options: orderOptions,
11833 onChange: (value) => {
11834 onChangeView({
11835 ...view,
11836 sort: {
11837 direction: view?.sort?.direction || "desc",
11838 field: value
11839 },
11840 showLevels: false
11841 });
11842 }
11843 }
11844 );
11845 }
11846 function SortDirectionControl() {
11847 const { view, fields, onChangeView } = (0, import_element36.useContext)(dataviews_context_default);
11848 const sortableFields = fields.filter(
11849 (field) => field.enableSorting !== false
11850 );
11851 if (sortableFields.length === 0) {
11852 return null;
11853 }
11854 let value = view.sort?.direction;
11855 if (!value && view.sort?.field) {
11856 value = "desc";
11857 }
11858 return /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
11859 import_components27.__experimentalToggleGroupControl,
11860 {
11861 className: "dataviews-view-config__sort-direction",
11862 __next40pxDefaultSize: true,
11863 isBlock: true,
11864 label: (0, import_i18n36.__)("Order"),
11865 value,
11866 onChange: (newDirection) => {
11867 if (newDirection === "asc" || newDirection === "desc") {
11868 onChangeView({
11869 ...view,
11870 sort: {
11871 direction: newDirection,
11872 field: view.sort?.field || // If there is no field assigned as the sorting field assign the first sortable field.
11873 fields.find(
11874 (field) => field.enableSorting !== false
11875 )?.id || ""
11876 },
11877 showLevels: false
11878 });
11879 return;
11880 }
11881 (0, import_warning.default)("Invalid direction");
11882 },
11883 children: SORTING_DIRECTIONS.map((direction) => {
11884 return /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
11885 import_components27.__experimentalToggleGroupControlOptionIcon,
11886 {
11887 value: direction,
11888 icon: sortIcons[direction],
11889 label: sortLabels[direction]
11890 },
11891 direction
11892 );
11893 })
11894 }
11895 );
11896 }
11897 function ItemsPerPageControl() {
11898 const { view, config, onChangeView } = (0, import_element36.useContext)(dataviews_context_default);
11899 const { infiniteScrollEnabled } = view;
11900 if (!config || !config.perPageSizes || config.perPageSizes.length < 2 || config.perPageSizes.length > 6 || infiniteScrollEnabled) {
11901 return null;
11902 }
11903 return /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
11904 import_components27.__experimentalToggleGroupControl,
11905 {
11906 __next40pxDefaultSize: true,
11907 isBlock: true,
11908 label: (0, import_i18n36.__)("Items per page"),
11909 value: view.perPage || 10,
11910 disabled: !view?.sort?.field,
11911 onChange: (newItemsPerPage) => {
11912 const newItemsPerPageNumber = typeof newItemsPerPage === "number" || newItemsPerPage === void 0 ? newItemsPerPage : parseInt(newItemsPerPage, 10);
11913 onChangeView({
11914 ...view,
11915 perPage: newItemsPerPageNumber,
11916 page: 1
11917 });
11918 },
11919 children: config.perPageSizes.map((value) => {
11920 return /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
11921 import_components27.__experimentalToggleGroupControlOption,
11922 {
11923 value,
11924 label: value.toString()
11925 },
11926 value
11927 );
11928 })
11929 }
11930 );
11931 }
11932 function SettingsSection({
11933 title,
11934 description,
11935 children
11936 }) {
11937 return /* @__PURE__ */ (0, import_jsx_runtime72.jsxs)(import_components27.__experimentalGrid, { columns: 12, className: "dataviews-settings-section", gap: 4, children: [
11938 /* @__PURE__ */ (0, import_jsx_runtime72.jsxs)("div", { className: "dataviews-settings-section__sidebar", children: [
11939 /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
11940 import_components27.__experimentalHeading,
11941 {
11942 level: 2,
11943 className: "dataviews-settings-section__title",
11944 children: title
11945 }
11946 ),
11947 description && /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
11948 import_components27.__experimentalText,
11949 {
11950 variant: "muted",
11951 className: "dataviews-settings-section__description",
11952 children: description
11953 }
11954 )
11955 ] }),
11956 /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
11957 import_components27.__experimentalGrid,
11958 {
11959 columns: 8,
11960 gap: 4,
11961 className: "dataviews-settings-section__content",
11962 children
11963 }
11964 )
11965 ] });
11966 }
11967 function DataviewsViewConfigDropdown() {
11968 const { view } = (0, import_element36.useContext)(dataviews_context_default);
11969 const popoverId = (0, import_compose10.useInstanceId)(
11970 _DataViewsViewConfig,
11971 "dataviews-view-config-dropdown"
11972 );
11973 const activeLayout = VIEW_LAYOUTS.find(
11974 (layout) => layout.type === view.type
11975 );
11976 return /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
11977 import_components27.Dropdown,
11978 {
11979 expandOnMobile: true,
11980 popoverProps: {
11981 ...DATAVIEWS_CONFIG_POPOVER_PROPS,
11982 id: popoverId
11983 },
11984 renderToggle: ({ onToggle, isOpen }) => {
11985 return /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
11986 import_components27.Button,
11987 {
11988 size: "compact",
11989 icon: cog_default,
11990 label: (0, import_i18n36._x)("View options", "View is used as a noun"),
11991 onClick: onToggle,
11992 "aria-expanded": isOpen ? "true" : "false",
11993 "aria-controls": popoverId
11994 }
11995 );
11996 },
11997 renderContent: () => /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
11998 import_components27.__experimentalDropdownContentWrapper,
11999 {
12000 paddingSize: "medium",
12001 className: "dataviews-config__popover-content-wrapper",
12002 children: /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(
12003 Stack,
12004 {
12005 direction: "column",
12006 className: "dataviews-view-config",
12007 gap: "lg",
12008 children: /* @__PURE__ */ (0, import_jsx_runtime72.jsxs)(SettingsSection, { title: (0, import_i18n36.__)("Appearance"), children: [
12009 /* @__PURE__ */ (0, import_jsx_runtime72.jsxs)(
12010 Stack,
12011 {
12012 direction: "row",
12013 gap: "xs",
12014 className: "is-divided-in-two",
12015 children: [
12016 /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(SortFieldControl, {}),
12017 /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(SortDirectionControl, {})
12018 ]
12019 }
12020 ),
12021 !!activeLayout?.viewConfigOptions && /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(activeLayout.viewConfigOptions, {}),
12022 /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(InfiniteScrollToggle, {}),
12023 /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(ItemsPerPageControl, {}),
12024 /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(PropertiesSection, {})
12025 ] })
12026 }
12027 )
12028 }
12029 )
12030 }
12031 );
12032 }
12033 function _DataViewsViewConfig() {
12034 return /* @__PURE__ */ (0, import_jsx_runtime72.jsxs)(import_jsx_runtime72.Fragment, { children: [
12035 /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(ViewTypeMenu, {}),
12036 /* @__PURE__ */ (0, import_jsx_runtime72.jsx)(DataviewsViewConfigDropdown, {})
12037 ] });
12038 }
12039 var DataViewsViewConfig = (0, import_element36.memo)(_DataViewsViewConfig);
12040 var dataviews_view_config_default = DataViewsViewConfig;
12041
12042 // packages/dataviews/build-module/components/dataform-controls/checkbox.mjs
12043 var import_components28 = __toESM(require_components(), 1);
12044 var import_element37 = __toESM(require_element(), 1);
12045
12046 // packages/dataviews/build-module/components/dataform-controls/utils/get-custom-validity.mjs
12047 function getCustomValidity(isValid2, validity) {
12048 let customValidity;
12049 if (isValid2?.required && validity?.required) {
12050 customValidity = validity?.required?.message ? validity.required : void 0;
12051 } else if (isValid2?.pattern && validity?.pattern) {
12052 customValidity = validity.pattern;
12053 } else if (isValid2?.min && validity?.min) {
12054 customValidity = validity.min;
12055 } else if (isValid2?.max && validity?.max) {
12056 customValidity = validity.max;
12057 } else if (isValid2?.minLength && validity?.minLength) {
12058 customValidity = validity.minLength;
12059 } else if (isValid2?.maxLength && validity?.maxLength) {
12060 customValidity = validity.maxLength;
12061 } else if (isValid2?.elements && validity?.elements) {
12062 customValidity = validity.elements;
12063 } else if (validity?.custom) {
12064 customValidity = validity.custom;
12065 }
12066 return customValidity;
12067 }
12068
12069 // packages/dataviews/build-module/components/dataform-controls/checkbox.mjs
12070 var import_jsx_runtime73 = __toESM(require_jsx_runtime(), 1);
12071 var { ValidatedCheckboxControl } = unlock(import_components28.privateApis);
12072 function Checkbox({
12073 field,
12074 onChange,
12075 data,
12076 hideLabelFromVision,
12077 validity
12078 }) {
12079 const { getValue, setValue, label, description, isValid: isValid2 } = field;
12080 const onChangeControl = (0, import_element37.useCallback)(() => {
12081 onChange(
12082 setValue({ item: data, value: !getValue({ item: data }) })
12083 );
12084 }, [data, getValue, onChange, setValue]);
12085 return /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(
12086 ValidatedCheckboxControl,
12087 {
12088 required: !!field.isValid?.required,
12089 customValidity: getCustomValidity(isValid2, validity),
12090 hidden: hideLabelFromVision,
12091 label,
12092 help: description,
12093 checked: getValue({ item: data }),
12094 onChange: onChangeControl
12095 }
12096 );
12097 }
12098
12099 // packages/dataviews/node_modules/date-fns/constants.js
12100 var daysInYear = 365.2425;
12101 var maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1e3;
12102 var minTime = -maxTime;
12103 var millisecondsInWeek = 6048e5;
12104 var millisecondsInDay = 864e5;
12105 var secondsInHour = 3600;
12106 var secondsInDay = secondsInHour * 24;
12107 var secondsInWeek = secondsInDay * 7;
12108 var secondsInYear = secondsInDay * daysInYear;
12109 var secondsInMonth = secondsInYear / 12;
12110 var secondsInQuarter = secondsInMonth * 3;
12111 var constructFromSymbol = /* @__PURE__ */ Symbol.for("constructDateFrom");
12112
12113 // packages/dataviews/node_modules/date-fns/constructFrom.js
12114 function constructFrom(date, value) {
12115 if (typeof date === "function") return date(value);
12116 if (date && typeof date === "object" && constructFromSymbol in date)
12117 return date[constructFromSymbol](value);
12118 if (date instanceof Date) return new date.constructor(value);
12119 return new Date(value);
12120 }
12121
12122 // packages/dataviews/node_modules/date-fns/toDate.js
12123 function toDate(argument, context) {
12124 return constructFrom(context || argument, argument);
12125 }
12126
12127 // packages/dataviews/node_modules/date-fns/addDays.js
12128 function addDays(date, amount, options) {
12129 const _date = toDate(date, options?.in);
12130 if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
12131 if (!amount) return _date;
12132 _date.setDate(_date.getDate() + amount);
12133 return _date;
12134 }
12135
12136 // packages/dataviews/node_modules/date-fns/addMonths.js
12137 function addMonths(date, amount, options) {
12138 const _date = toDate(date, options?.in);
12139 if (isNaN(amount)) return constructFrom(options?.in || date, NaN);
12140 if (!amount) {
12141 return _date;
12142 }
12143 const dayOfMonth = _date.getDate();
12144 const endOfDesiredMonth = constructFrom(options?.in || date, _date.getTime());
12145 endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0);
12146 const daysInMonth = endOfDesiredMonth.getDate();
12147 if (dayOfMonth >= daysInMonth) {
12148 return endOfDesiredMonth;
12149 } else {
12150 _date.setFullYear(
12151 endOfDesiredMonth.getFullYear(),
12152 endOfDesiredMonth.getMonth(),
12153 dayOfMonth
12154 );
12155 return _date;
12156 }
12157 }
12158
12159 // packages/dataviews/node_modules/date-fns/_lib/defaultOptions.js
12160 var defaultOptions = {};
12161 function getDefaultOptions() {
12162 return defaultOptions;
12163 }
12164
12165 // packages/dataviews/node_modules/date-fns/startOfWeek.js
12166 function startOfWeek(date, options) {
12167 const defaultOptions2 = getDefaultOptions();
12168 const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
12169 const _date = toDate(date, options?.in);
12170 const day = _date.getDay();
12171 const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
12172 _date.setDate(_date.getDate() - diff);
12173 _date.setHours(0, 0, 0, 0);
12174 return _date;
12175 }
12176
12177 // packages/dataviews/node_modules/date-fns/startOfISOWeek.js
12178 function startOfISOWeek(date, options) {
12179 return startOfWeek(date, { ...options, weekStartsOn: 1 });
12180 }
12181
12182 // packages/dataviews/node_modules/date-fns/getISOWeekYear.js
12183 function getISOWeekYear(date, options) {
12184 const _date = toDate(date, options?.in);
12185 const year = _date.getFullYear();
12186 const fourthOfJanuaryOfNextYear = constructFrom(_date, 0);
12187 fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
12188 fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
12189 const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
12190 const fourthOfJanuaryOfThisYear = constructFrom(_date, 0);
12191 fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
12192 fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
12193 const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
12194 if (_date.getTime() >= startOfNextYear.getTime()) {
12195 return year + 1;
12196 } else if (_date.getTime() >= startOfThisYear.getTime()) {
12197 return year;
12198 } else {
12199 return year - 1;
12200 }
12201 }
12202
12203 // packages/dataviews/node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.js
12204 function getTimezoneOffsetInMilliseconds(date) {
12205 const _date = toDate(date);
12206 const utcDate = new Date(
12207 Date.UTC(
12208 _date.getFullYear(),
12209 _date.getMonth(),
12210 _date.getDate(),
12211 _date.getHours(),
12212 _date.getMinutes(),
12213 _date.getSeconds(),
12214 _date.getMilliseconds()
12215 )
12216 );
12217 utcDate.setUTCFullYear(_date.getFullYear());
12218 return +date - +utcDate;
12219 }
12220
12221 // packages/dataviews/node_modules/date-fns/_lib/normalizeDates.js
12222 function normalizeDates(context, ...dates) {
12223 const normalize = constructFrom.bind(
12224 null,
12225 context || dates.find((date) => typeof date === "object")
12226 );
12227 return dates.map(normalize);
12228 }
12229
12230 // packages/dataviews/node_modules/date-fns/startOfDay.js
12231 function startOfDay(date, options) {
12232 const _date = toDate(date, options?.in);
12233 _date.setHours(0, 0, 0, 0);
12234 return _date;
12235 }
12236
12237 // packages/dataviews/node_modules/date-fns/differenceInCalendarDays.js
12238 function differenceInCalendarDays(laterDate, earlierDate, options) {
12239 const [laterDate_, earlierDate_] = normalizeDates(
12240 options?.in,
12241 laterDate,
12242 earlierDate
12243 );
12244 const laterStartOfDay = startOfDay(laterDate_);
12245 const earlierStartOfDay = startOfDay(earlierDate_);
12246 const laterTimestamp = +laterStartOfDay - getTimezoneOffsetInMilliseconds(laterStartOfDay);
12247 const earlierTimestamp = +earlierStartOfDay - getTimezoneOffsetInMilliseconds(earlierStartOfDay);
12248 return Math.round((laterTimestamp - earlierTimestamp) / millisecondsInDay);
12249 }
12250
12251 // packages/dataviews/node_modules/date-fns/startOfISOWeekYear.js
12252 function startOfISOWeekYear(date, options) {
12253 const year = getISOWeekYear(date, options);
12254 const fourthOfJanuary = constructFrom(options?.in || date, 0);
12255 fourthOfJanuary.setFullYear(year, 0, 4);
12256 fourthOfJanuary.setHours(0, 0, 0, 0);
12257 return startOfISOWeek(fourthOfJanuary);
12258 }
12259
12260 // packages/dataviews/node_modules/date-fns/addYears.js
12261 function addYears(date, amount, options) {
12262 return addMonths(date, amount * 12, options);
12263 }
12264
12265 // packages/dataviews/node_modules/date-fns/isDate.js
12266 function isDate(value) {
12267 return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
12268 }
12269
12270 // packages/dataviews/node_modules/date-fns/isValid.js
12271 function isValid(date) {
12272 return !(!isDate(date) && typeof date !== "number" || isNaN(+toDate(date)));
12273 }
12274
12275 // packages/dataviews/node_modules/date-fns/startOfMonth.js
12276 function startOfMonth(date, options) {
12277 const _date = toDate(date, options?.in);
12278 _date.setDate(1);
12279 _date.setHours(0, 0, 0, 0);
12280 return _date;
12281 }
12282
12283 // packages/dataviews/node_modules/date-fns/startOfYear.js
12284 function startOfYear(date, options) {
12285 const date_ = toDate(date, options?.in);
12286 date_.setFullYear(date_.getFullYear(), 0, 1);
12287 date_.setHours(0, 0, 0, 0);
12288 return date_;
12289 }
12290
12291 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/formatDistance.js
12292 var formatDistanceLocale = {
12293 lessThanXSeconds: {
12294 one: "less than a second",
12295 other: "less than {{count}} seconds"
12296 },
12297 xSeconds: {
12298 one: "1 second",
12299 other: "{{count}} seconds"
12300 },
12301 halfAMinute: "half a minute",
12302 lessThanXMinutes: {
12303 one: "less than a minute",
12304 other: "less than {{count}} minutes"
12305 },
12306 xMinutes: {
12307 one: "1 minute",
12308 other: "{{count}} minutes"
12309 },
12310 aboutXHours: {
12311 one: "about 1 hour",
12312 other: "about {{count}} hours"
12313 },
12314 xHours: {
12315 one: "1 hour",
12316 other: "{{count}} hours"
12317 },
12318 xDays: {
12319 one: "1 day",
12320 other: "{{count}} days"
12321 },
12322 aboutXWeeks: {
12323 one: "about 1 week",
12324 other: "about {{count}} weeks"
12325 },
12326 xWeeks: {
12327 one: "1 week",
12328 other: "{{count}} weeks"
12329 },
12330 aboutXMonths: {
12331 one: "about 1 month",
12332 other: "about {{count}} months"
12333 },
12334 xMonths: {
12335 one: "1 month",
12336 other: "{{count}} months"
12337 },
12338 aboutXYears: {
12339 one: "about 1 year",
12340 other: "about {{count}} years"
12341 },
12342 xYears: {
12343 one: "1 year",
12344 other: "{{count}} years"
12345 },
12346 overXYears: {
12347 one: "over 1 year",
12348 other: "over {{count}} years"
12349 },
12350 almostXYears: {
12351 one: "almost 1 year",
12352 other: "almost {{count}} years"
12353 }
12354 };
12355 var formatDistance = (token, count, options) => {
12356 let result;
12357 const tokenValue = formatDistanceLocale[token];
12358 if (typeof tokenValue === "string") {
12359 result = tokenValue;
12360 } else if (count === 1) {
12361 result = tokenValue.one;
12362 } else {
12363 result = tokenValue.other.replace("{{count}}", count.toString());
12364 }
12365 if (options?.addSuffix) {
12366 if (options.comparison && options.comparison > 0) {
12367 return "in " + result;
12368 } else {
12369 return result + " ago";
12370 }
12371 }
12372 return result;
12373 };
12374
12375 // packages/dataviews/node_modules/date-fns/locale/_lib/buildFormatLongFn.js
12376 function buildFormatLongFn(args) {
12377 return (options = {}) => {
12378 const width = options.width ? String(options.width) : args.defaultWidth;
12379 const format6 = args.formats[width] || args.formats[args.defaultWidth];
12380 return format6;
12381 };
12382 }
12383
12384 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/formatLong.js
12385 var dateFormats = {
12386 full: "EEEE, MMMM do, y",
12387 long: "MMMM do, y",
12388 medium: "MMM d, y",
12389 short: "MM/dd/yyyy"
12390 };
12391 var timeFormats = {
12392 full: "h:mm:ss a zzzz",
12393 long: "h:mm:ss a z",
12394 medium: "h:mm:ss a",
12395 short: "h:mm a"
12396 };
12397 var dateTimeFormats = {
12398 full: "{{date}} 'at' {{time}}",
12399 long: "{{date}} 'at' {{time}}",
12400 medium: "{{date}}, {{time}}",
12401 short: "{{date}}, {{time}}"
12402 };
12403 var formatLong = {
12404 date: buildFormatLongFn({
12405 formats: dateFormats,
12406 defaultWidth: "full"
12407 }),
12408 time: buildFormatLongFn({
12409 formats: timeFormats,
12410 defaultWidth: "full"
12411 }),
12412 dateTime: buildFormatLongFn({
12413 formats: dateTimeFormats,
12414 defaultWidth: "full"
12415 })
12416 };
12417
12418 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/formatRelative.js
12419 var formatRelativeLocale = {
12420 lastWeek: "'last' eeee 'at' p",
12421 yesterday: "'yesterday at' p",
12422 today: "'today at' p",
12423 tomorrow: "'tomorrow at' p",
12424 nextWeek: "eeee 'at' p",
12425 other: "P"
12426 };
12427 var formatRelative = (token, _date, _baseDate, _options) => formatRelativeLocale[token];
12428
12429 // packages/dataviews/node_modules/date-fns/locale/_lib/buildLocalizeFn.js
12430 function buildLocalizeFn(args) {
12431 return (value, options) => {
12432 const context = options?.context ? String(options.context) : "standalone";
12433 let valuesArray;
12434 if (context === "formatting" && args.formattingValues) {
12435 const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
12436 const width = options?.width ? String(options.width) : defaultWidth;
12437 valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
12438 } else {
12439 const defaultWidth = args.defaultWidth;
12440 const width = options?.width ? String(options.width) : args.defaultWidth;
12441 valuesArray = args.values[width] || args.values[defaultWidth];
12442 }
12443 const index = args.argumentCallback ? args.argumentCallback(value) : value;
12444 return valuesArray[index];
12445 };
12446 }
12447
12448 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/localize.js
12449 var eraValues = {
12450 narrow: ["B", "A"],
12451 abbreviated: ["BC", "AD"],
12452 wide: ["Before Christ", "Anno Domini"]
12453 };
12454 var quarterValues = {
12455 narrow: ["1", "2", "3", "4"],
12456 abbreviated: ["Q1", "Q2", "Q3", "Q4"],
12457 wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"]
12458 };
12459 var monthValues = {
12460 narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
12461 abbreviated: [
12462 "Jan",
12463 "Feb",
12464 "Mar",
12465 "Apr",
12466 "May",
12467 "Jun",
12468 "Jul",
12469 "Aug",
12470 "Sep",
12471 "Oct",
12472 "Nov",
12473 "Dec"
12474 ],
12475 wide: [
12476 "January",
12477 "February",
12478 "March",
12479 "April",
12480 "May",
12481 "June",
12482 "July",
12483 "August",
12484 "September",
12485 "October",
12486 "November",
12487 "December"
12488 ]
12489 };
12490 var dayValues = {
12491 narrow: ["S", "M", "T", "W", "T", "F", "S"],
12492 short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
12493 abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
12494 wide: [
12495 "Sunday",
12496 "Monday",
12497 "Tuesday",
12498 "Wednesday",
12499 "Thursday",
12500 "Friday",
12501 "Saturday"
12502 ]
12503 };
12504 var dayPeriodValues = {
12505 narrow: {
12506 am: "a",
12507 pm: "p",
12508 midnight: "mi",
12509 noon: "n",
12510 morning: "morning",
12511 afternoon: "afternoon",
12512 evening: "evening",
12513 night: "night"
12514 },
12515 abbreviated: {
12516 am: "AM",
12517 pm: "PM",
12518 midnight: "midnight",
12519 noon: "noon",
12520 morning: "morning",
12521 afternoon: "afternoon",
12522 evening: "evening",
12523 night: "night"
12524 },
12525 wide: {
12526 am: "a.m.",
12527 pm: "p.m.",
12528 midnight: "midnight",
12529 noon: "noon",
12530 morning: "morning",
12531 afternoon: "afternoon",
12532 evening: "evening",
12533 night: "night"
12534 }
12535 };
12536 var formattingDayPeriodValues = {
12537 narrow: {
12538 am: "a",
12539 pm: "p",
12540 midnight: "mi",
12541 noon: "n",
12542 morning: "in the morning",
12543 afternoon: "in the afternoon",
12544 evening: "in the evening",
12545 night: "at night"
12546 },
12547 abbreviated: {
12548 am: "AM",
12549 pm: "PM",
12550 midnight: "midnight",
12551 noon: "noon",
12552 morning: "in the morning",
12553 afternoon: "in the afternoon",
12554 evening: "in the evening",
12555 night: "at night"
12556 },
12557 wide: {
12558 am: "a.m.",
12559 pm: "p.m.",
12560 midnight: "midnight",
12561 noon: "noon",
12562 morning: "in the morning",
12563 afternoon: "in the afternoon",
12564 evening: "in the evening",
12565 night: "at night"
12566 }
12567 };
12568 var ordinalNumber = (dirtyNumber, _options) => {
12569 const number = Number(dirtyNumber);
12570 const rem100 = number % 100;
12571 if (rem100 > 20 || rem100 < 10) {
12572 switch (rem100 % 10) {
12573 case 1:
12574 return number + "st";
12575 case 2:
12576 return number + "nd";
12577 case 3:
12578 return number + "rd";
12579 }
12580 }
12581 return number + "th";
12582 };
12583 var localize = {
12584 ordinalNumber,
12585 era: buildLocalizeFn({
12586 values: eraValues,
12587 defaultWidth: "wide"
12588 }),
12589 quarter: buildLocalizeFn({
12590 values: quarterValues,
12591 defaultWidth: "wide",
12592 argumentCallback: (quarter) => quarter - 1
12593 }),
12594 month: buildLocalizeFn({
12595 values: monthValues,
12596 defaultWidth: "wide"
12597 }),
12598 day: buildLocalizeFn({
12599 values: dayValues,
12600 defaultWidth: "wide"
12601 }),
12602 dayPeriod: buildLocalizeFn({
12603 values: dayPeriodValues,
12604 defaultWidth: "wide",
12605 formattingValues: formattingDayPeriodValues,
12606 defaultFormattingWidth: "wide"
12607 })
12608 };
12609
12610 // packages/dataviews/node_modules/date-fns/locale/_lib/buildMatchFn.js
12611 function buildMatchFn(args) {
12612 return (string, options = {}) => {
12613 const width = options.width;
12614 const matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
12615 const matchResult = string.match(matchPattern);
12616 if (!matchResult) {
12617 return null;
12618 }
12619 const matchedString = matchResult[0];
12620 const parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
12621 const key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString)) : (
12622 // [TODO] -- I challenge you to fix the type
12623 findKey(parsePatterns, (pattern) => pattern.test(matchedString))
12624 );
12625 let value;
12626 value = args.valueCallback ? args.valueCallback(key) : key;
12627 value = options.valueCallback ? (
12628 // [TODO] -- I challenge you to fix the type
12629 options.valueCallback(value)
12630 ) : value;
12631 const rest = string.slice(matchedString.length);
12632 return { value, rest };
12633 };
12634 }
12635 function findKey(object, predicate) {
12636 for (const key in object) {
12637 if (Object.prototype.hasOwnProperty.call(object, key) && predicate(object[key])) {
12638 return key;
12639 }
12640 }
12641 return void 0;
12642 }
12643 function findIndex(array, predicate) {
12644 for (let key = 0; key < array.length; key++) {
12645 if (predicate(array[key])) {
12646 return key;
12647 }
12648 }
12649 return void 0;
12650 }
12651
12652 // packages/dataviews/node_modules/date-fns/locale/_lib/buildMatchPatternFn.js
12653 function buildMatchPatternFn(args) {
12654 return (string, options = {}) => {
12655 const matchResult = string.match(args.matchPattern);
12656 if (!matchResult) return null;
12657 const matchedString = matchResult[0];
12658 const parseResult = string.match(args.parsePattern);
12659 if (!parseResult) return null;
12660 let value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
12661 value = options.valueCallback ? options.valueCallback(value) : value;
12662 const rest = string.slice(matchedString.length);
12663 return { value, rest };
12664 };
12665 }
12666
12667 // packages/dataviews/node_modules/date-fns/locale/en-US/_lib/match.js
12668 var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
12669 var parseOrdinalNumberPattern = /\d+/i;
12670 var matchEraPatterns = {
12671 narrow: /^(b|a)/i,
12672 abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
12673 wide: /^(before christ|before common era|anno domini|common era)/i
12674 };
12675 var parseEraPatterns = {
12676 any: [/^b/i, /^(a|c)/i]
12677 };
12678 var matchQuarterPatterns = {
12679 narrow: /^[1234]/i,
12680 abbreviated: /^q[1234]/i,
12681 wide: /^[1234](th|st|nd|rd)? quarter/i
12682 };
12683 var parseQuarterPatterns = {
12684 any: [/1/i, /2/i, /3/i, /4/i]
12685 };
12686 var matchMonthPatterns = {
12687 narrow: /^[jfmasond]/i,
12688 abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
12689 wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
12690 };
12691 var parseMonthPatterns = {
12692 narrow: [
12693 /^j/i,
12694 /^f/i,
12695 /^m/i,
12696 /^a/i,
12697 /^m/i,
12698 /^j/i,
12699 /^j/i,
12700 /^a/i,
12701 /^s/i,
12702 /^o/i,
12703 /^n/i,
12704 /^d/i
12705 ],
12706 any: [
12707 /^ja/i,
12708 /^f/i,
12709 /^mar/i,
12710 /^ap/i,
12711 /^may/i,
12712 /^jun/i,
12713 /^jul/i,
12714 /^au/i,
12715 /^s/i,
12716 /^o/i,
12717 /^n/i,
12718 /^d/i
12719 ]
12720 };
12721 var matchDayPatterns = {
12722 narrow: /^[smtwf]/i,
12723 short: /^(su|mo|tu|we|th|fr|sa)/i,
12724 abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
12725 wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
12726 };
12727 var parseDayPatterns = {
12728 narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
12729 any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
12730 };
12731 var matchDayPeriodPatterns = {
12732 narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
12733 any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
12734 };
12735 var parseDayPeriodPatterns = {
12736 any: {
12737 am: /^a/i,
12738 pm: /^p/i,
12739 midnight: /^mi/i,
12740 noon: /^no/i,
12741 morning: /morning/i,
12742 afternoon: /afternoon/i,
12743 evening: /evening/i,
12744 night: /night/i
12745 }
12746 };
12747 var match = {
12748 ordinalNumber: buildMatchPatternFn({
12749 matchPattern: matchOrdinalNumberPattern,
12750 parsePattern: parseOrdinalNumberPattern,
12751 valueCallback: (value) => parseInt(value, 10)
12752 }),
12753 era: buildMatchFn({
12754 matchPatterns: matchEraPatterns,
12755 defaultMatchWidth: "wide",
12756 parsePatterns: parseEraPatterns,
12757 defaultParseWidth: "any"
12758 }),
12759 quarter: buildMatchFn({
12760 matchPatterns: matchQuarterPatterns,
12761 defaultMatchWidth: "wide",
12762 parsePatterns: parseQuarterPatterns,
12763 defaultParseWidth: "any",
12764 valueCallback: (index) => index + 1
12765 }),
12766 month: buildMatchFn({
12767 matchPatterns: matchMonthPatterns,
12768 defaultMatchWidth: "wide",
12769 parsePatterns: parseMonthPatterns,
12770 defaultParseWidth: "any"
12771 }),
12772 day: buildMatchFn({
12773 matchPatterns: matchDayPatterns,
12774 defaultMatchWidth: "wide",
12775 parsePatterns: parseDayPatterns,
12776 defaultParseWidth: "any"
12777 }),
12778 dayPeriod: buildMatchFn({
12779 matchPatterns: matchDayPeriodPatterns,
12780 defaultMatchWidth: "any",
12781 parsePatterns: parseDayPeriodPatterns,
12782 defaultParseWidth: "any"
12783 })
12784 };
12785
12786 // packages/dataviews/node_modules/date-fns/locale/en-US.js
12787 var enUS = {
12788 code: "en-US",
12789 formatDistance,
12790 formatLong,
12791 formatRelative,
12792 localize,
12793 match,
12794 options: {
12795 weekStartsOn: 0,
12796 firstWeekContainsDate: 1
12797 }
12798 };
12799
12800 // packages/dataviews/node_modules/date-fns/getDayOfYear.js
12801 function getDayOfYear(date, options) {
12802 const _date = toDate(date, options?.in);
12803 const diff = differenceInCalendarDays(_date, startOfYear(_date));
12804 const dayOfYear = diff + 1;
12805 return dayOfYear;
12806 }
12807
12808 // packages/dataviews/node_modules/date-fns/getISOWeek.js
12809 function getISOWeek(date, options) {
12810 const _date = toDate(date, options?.in);
12811 const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
12812 return Math.round(diff / millisecondsInWeek) + 1;
12813 }
12814
12815 // packages/dataviews/node_modules/date-fns/getWeekYear.js
12816 function getWeekYear(date, options) {
12817 const _date = toDate(date, options?.in);
12818 const year = _date.getFullYear();
12819 const defaultOptions2 = getDefaultOptions();
12820 const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
12821 const firstWeekOfNextYear = constructFrom(options?.in || date, 0);
12822 firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
12823 firstWeekOfNextYear.setHours(0, 0, 0, 0);
12824 const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
12825 const firstWeekOfThisYear = constructFrom(options?.in || date, 0);
12826 firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
12827 firstWeekOfThisYear.setHours(0, 0, 0, 0);
12828 const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
12829 if (+_date >= +startOfNextYear) {
12830 return year + 1;
12831 } else if (+_date >= +startOfThisYear) {
12832 return year;
12833 } else {
12834 return year - 1;
12835 }
12836 }
12837
12838 // packages/dataviews/node_modules/date-fns/startOfWeekYear.js
12839 function startOfWeekYear(date, options) {
12840 const defaultOptions2 = getDefaultOptions();
12841 const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
12842 const year = getWeekYear(date, options);
12843 const firstWeek = constructFrom(options?.in || date, 0);
12844 firstWeek.setFullYear(year, 0, firstWeekContainsDate);
12845 firstWeek.setHours(0, 0, 0, 0);
12846 const _date = startOfWeek(firstWeek, options);
12847 return _date;
12848 }
12849
12850 // packages/dataviews/node_modules/date-fns/getWeek.js
12851 function getWeek(date, options) {
12852 const _date = toDate(date, options?.in);
12853 const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
12854 return Math.round(diff / millisecondsInWeek) + 1;
12855 }
12856
12857 // packages/dataviews/node_modules/date-fns/_lib/addLeadingZeros.js
12858 function addLeadingZeros(number, targetLength) {
12859 const sign = number < 0 ? "-" : "";
12860 const output = Math.abs(number).toString().padStart(targetLength, "0");
12861 return sign + output;
12862 }
12863
12864 // packages/dataviews/node_modules/date-fns/_lib/format/lightFormatters.js
12865 var lightFormatters = {
12866 // Year
12867 y(date, token) {
12868 const signedYear = date.getFullYear();
12869 const year = signedYear > 0 ? signedYear : 1 - signedYear;
12870 return addLeadingZeros(token === "yy" ? year % 100 : year, token.length);
12871 },
12872 // Month
12873 M(date, token) {
12874 const month = date.getMonth();
12875 return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2);
12876 },
12877 // Day of the month
12878 d(date, token) {
12879 return addLeadingZeros(date.getDate(), token.length);
12880 },
12881 // AM or PM
12882 a(date, token) {
12883 const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am";
12884 switch (token) {
12885 case "a":
12886 case "aa":
12887 return dayPeriodEnumValue.toUpperCase();
12888 case "aaa":
12889 return dayPeriodEnumValue;
12890 case "aaaaa":
12891 return dayPeriodEnumValue[0];
12892 case "aaaa":
12893 default:
12894 return dayPeriodEnumValue === "am" ? "a.m." : "p.m.";
12895 }
12896 },
12897 // Hour [1-12]
12898 h(date, token) {
12899 return addLeadingZeros(date.getHours() % 12 || 12, token.length);
12900 },
12901 // Hour [0-23]
12902 H(date, token) {
12903 return addLeadingZeros(date.getHours(), token.length);
12904 },
12905 // Minute
12906 m(date, token) {
12907 return addLeadingZeros(date.getMinutes(), token.length);
12908 },
12909 // Second
12910 s(date, token) {
12911 return addLeadingZeros(date.getSeconds(), token.length);
12912 },
12913 // Fraction of second
12914 S(date, token) {
12915 const numberOfDigits = token.length;
12916 const milliseconds = date.getMilliseconds();
12917 const fractionalSeconds = Math.trunc(
12918 milliseconds * Math.pow(10, numberOfDigits - 3)
12919 );
12920 return addLeadingZeros(fractionalSeconds, token.length);
12921 }
12922 };
12923
12924 // packages/dataviews/node_modules/date-fns/_lib/format/formatters.js
12925 var dayPeriodEnum = {
12926 am: "am",
12927 pm: "pm",
12928 midnight: "midnight",
12929 noon: "noon",
12930 morning: "morning",
12931 afternoon: "afternoon",
12932 evening: "evening",
12933 night: "night"
12934 };
12935 var formatters = {
12936 // Era
12937 G: function(date, token, localize2) {
12938 const era = date.getFullYear() > 0 ? 1 : 0;
12939 switch (token) {
12940 // AD, BC
12941 case "G":
12942 case "GG":
12943 case "GGG":
12944 return localize2.era(era, { width: "abbreviated" });
12945 // A, B
12946 case "GGGGG":
12947 return localize2.era(era, { width: "narrow" });
12948 // Anno Domini, Before Christ
12949 case "GGGG":
12950 default:
12951 return localize2.era(era, { width: "wide" });
12952 }
12953 },
12954 // Year
12955 y: function(date, token, localize2) {
12956 if (token === "yo") {
12957 const signedYear = date.getFullYear();
12958 const year = signedYear > 0 ? signedYear : 1 - signedYear;
12959 return localize2.ordinalNumber(year, { unit: "year" });
12960 }
12961 return lightFormatters.y(date, token);
12962 },
12963 // Local week-numbering year
12964 Y: function(date, token, localize2, options) {
12965 const signedWeekYear = getWeekYear(date, options);
12966 const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
12967 if (token === "YY") {
12968 const twoDigitYear = weekYear % 100;
12969 return addLeadingZeros(twoDigitYear, 2);
12970 }
12971 if (token === "Yo") {
12972 return localize2.ordinalNumber(weekYear, { unit: "year" });
12973 }
12974 return addLeadingZeros(weekYear, token.length);
12975 },
12976 // ISO week-numbering year
12977 R: function(date, token) {
12978 const isoWeekYear = getISOWeekYear(date);
12979 return addLeadingZeros(isoWeekYear, token.length);
12980 },
12981 // Extended year. This is a single number designating the year of this calendar system.
12982 // The main difference between `y` and `u` localizers are B.C. years:
12983 // | Year | `y` | `u` |
12984 // |------|-----|-----|
12985 // | AC 1 | 1 | 1 |
12986 // | BC 1 | 1 | 0 |
12987 // | BC 2 | 2 | -1 |
12988 // Also `yy` always returns the last two digits of a year,
12989 // while `uu` pads single digit years to 2 characters and returns other years unchanged.
12990 u: function(date, token) {
12991 const year = date.getFullYear();
12992 return addLeadingZeros(year, token.length);
12993 },
12994 // Quarter
12995 Q: function(date, token, localize2) {
12996 const quarter = Math.ceil((date.getMonth() + 1) / 3);
12997 switch (token) {
12998 // 1, 2, 3, 4
12999 case "Q":
13000 return String(quarter);
13001 // 01, 02, 03, 04
13002 case "QQ":
13003 return addLeadingZeros(quarter, 2);
13004 // 1st, 2nd, 3rd, 4th
13005 case "Qo":
13006 return localize2.ordinalNumber(quarter, { unit: "quarter" });
13007 // Q1, Q2, Q3, Q4
13008 case "QQQ":
13009 return localize2.quarter(quarter, {
13010 width: "abbreviated",
13011 context: "formatting"
13012 });
13013 // 1, 2, 3, 4 (narrow quarter; could be not numerical)
13014 case "QQQQQ":
13015 return localize2.quarter(quarter, {
13016 width: "narrow",
13017 context: "formatting"
13018 });
13019 // 1st quarter, 2nd quarter, ...
13020 case "QQQQ":
13021 default:
13022 return localize2.quarter(quarter, {
13023 width: "wide",
13024 context: "formatting"
13025 });
13026 }
13027 },
13028 // Stand-alone quarter
13029 q: function(date, token, localize2) {
13030 const quarter = Math.ceil((date.getMonth() + 1) / 3);
13031 switch (token) {
13032 // 1, 2, 3, 4
13033 case "q":
13034 return String(quarter);
13035 // 01, 02, 03, 04
13036 case "qq":
13037 return addLeadingZeros(quarter, 2);
13038 // 1st, 2nd, 3rd, 4th
13039 case "qo":
13040 return localize2.ordinalNumber(quarter, { unit: "quarter" });
13041 // Q1, Q2, Q3, Q4
13042 case "qqq":
13043 return localize2.quarter(quarter, {
13044 width: "abbreviated",
13045 context: "standalone"
13046 });
13047 // 1, 2, 3, 4 (narrow quarter; could be not numerical)
13048 case "qqqqq":
13049 return localize2.quarter(quarter, {
13050 width: "narrow",
13051 context: "standalone"
13052 });
13053 // 1st quarter, 2nd quarter, ...
13054 case "qqqq":
13055 default:
13056 return localize2.quarter(quarter, {
13057 width: "wide",
13058 context: "standalone"
13059 });
13060 }
13061 },
13062 // Month
13063 M: function(date, token, localize2) {
13064 const month = date.getMonth();
13065 switch (token) {
13066 case "M":
13067 case "MM":
13068 return lightFormatters.M(date, token);
13069 // 1st, 2nd, ..., 12th
13070 case "Mo":
13071 return localize2.ordinalNumber(month + 1, { unit: "month" });
13072 // Jan, Feb, ..., Dec
13073 case "MMM":
13074 return localize2.month(month, {
13075 width: "abbreviated",
13076 context: "formatting"
13077 });
13078 // J, F, ..., D
13079 case "MMMMM":
13080 return localize2.month(month, {
13081 width: "narrow",
13082 context: "formatting"
13083 });
13084 // January, February, ..., December
13085 case "MMMM":
13086 default:
13087 return localize2.month(month, { width: "wide", context: "formatting" });
13088 }
13089 },
13090 // Stand-alone month
13091 L: function(date, token, localize2) {
13092 const month = date.getMonth();
13093 switch (token) {
13094 // 1, 2, ..., 12
13095 case "L":
13096 return String(month + 1);
13097 // 01, 02, ..., 12
13098 case "LL":
13099 return addLeadingZeros(month + 1, 2);
13100 // 1st, 2nd, ..., 12th
13101 case "Lo":
13102 return localize2.ordinalNumber(month + 1, { unit: "month" });
13103 // Jan, Feb, ..., Dec
13104 case "LLL":
13105 return localize2.month(month, {
13106 width: "abbreviated",
13107 context: "standalone"
13108 });
13109 // J, F, ..., D
13110 case "LLLLL":
13111 return localize2.month(month, {
13112 width: "narrow",
13113 context: "standalone"
13114 });
13115 // January, February, ..., December
13116 case "LLLL":
13117 default:
13118 return localize2.month(month, { width: "wide", context: "standalone" });
13119 }
13120 },
13121 // Local week of year
13122 w: function(date, token, localize2, options) {
13123 const week = getWeek(date, options);
13124 if (token === "wo") {
13125 return localize2.ordinalNumber(week, { unit: "week" });
13126 }
13127 return addLeadingZeros(week, token.length);
13128 },
13129 // ISO week of year
13130 I: function(date, token, localize2) {
13131 const isoWeek = getISOWeek(date);
13132 if (token === "Io") {
13133 return localize2.ordinalNumber(isoWeek, { unit: "week" });
13134 }
13135 return addLeadingZeros(isoWeek, token.length);
13136 },
13137 // Day of the month
13138 d: function(date, token, localize2) {
13139 if (token === "do") {
13140 return localize2.ordinalNumber(date.getDate(), { unit: "date" });
13141 }
13142 return lightFormatters.d(date, token);
13143 },
13144 // Day of year
13145 D: function(date, token, localize2) {
13146 const dayOfYear = getDayOfYear(date);
13147 if (token === "Do") {
13148 return localize2.ordinalNumber(dayOfYear, { unit: "dayOfYear" });
13149 }
13150 return addLeadingZeros(dayOfYear, token.length);
13151 },
13152 // Day of week
13153 E: function(date, token, localize2) {
13154 const dayOfWeek = date.getDay();
13155 switch (token) {
13156 // Tue
13157 case "E":
13158 case "EE":
13159 case "EEE":
13160 return localize2.day(dayOfWeek, {
13161 width: "abbreviated",
13162 context: "formatting"
13163 });
13164 // T
13165 case "EEEEE":
13166 return localize2.day(dayOfWeek, {
13167 width: "narrow",
13168 context: "formatting"
13169 });
13170 // Tu
13171 case "EEEEEE":
13172 return localize2.day(dayOfWeek, {
13173 width: "short",
13174 context: "formatting"
13175 });
13176 // Tuesday
13177 case "EEEE":
13178 default:
13179 return localize2.day(dayOfWeek, {
13180 width: "wide",
13181 context: "formatting"
13182 });
13183 }
13184 },
13185 // Local day of week
13186 e: function(date, token, localize2, options) {
13187 const dayOfWeek = date.getDay();
13188 const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
13189 switch (token) {
13190 // Numerical value (Nth day of week with current locale or weekStartsOn)
13191 case "e":
13192 return String(localDayOfWeek);
13193 // Padded numerical value
13194 case "ee":
13195 return addLeadingZeros(localDayOfWeek, 2);
13196 // 1st, 2nd, ..., 7th
13197 case "eo":
13198 return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
13199 case "eee":
13200 return localize2.day(dayOfWeek, {
13201 width: "abbreviated",
13202 context: "formatting"
13203 });
13204 // T
13205 case "eeeee":
13206 return localize2.day(dayOfWeek, {
13207 width: "narrow",
13208 context: "formatting"
13209 });
13210 // Tu
13211 case "eeeeee":
13212 return localize2.day(dayOfWeek, {
13213 width: "short",
13214 context: "formatting"
13215 });
13216 // Tuesday
13217 case "eeee":
13218 default:
13219 return localize2.day(dayOfWeek, {
13220 width: "wide",
13221 context: "formatting"
13222 });
13223 }
13224 },
13225 // Stand-alone local day of week
13226 c: function(date, token, localize2, options) {
13227 const dayOfWeek = date.getDay();
13228 const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
13229 switch (token) {
13230 // Numerical value (same as in `e`)
13231 case "c":
13232 return String(localDayOfWeek);
13233 // Padded numerical value
13234 case "cc":
13235 return addLeadingZeros(localDayOfWeek, token.length);
13236 // 1st, 2nd, ..., 7th
13237 case "co":
13238 return localize2.ordinalNumber(localDayOfWeek, { unit: "day" });
13239 case "ccc":
13240 return localize2.day(dayOfWeek, {
13241 width: "abbreviated",
13242 context: "standalone"
13243 });
13244 // T
13245 case "ccccc":
13246 return localize2.day(dayOfWeek, {
13247 width: "narrow",
13248 context: "standalone"
13249 });
13250 // Tu
13251 case "cccccc":
13252 return localize2.day(dayOfWeek, {
13253 width: "short",
13254 context: "standalone"
13255 });
13256 // Tuesday
13257 case "cccc":
13258 default:
13259 return localize2.day(dayOfWeek, {
13260 width: "wide",
13261 context: "standalone"
13262 });
13263 }
13264 },
13265 // ISO day of week
13266 i: function(date, token, localize2) {
13267 const dayOfWeek = date.getDay();
13268 const isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
13269 switch (token) {
13270 // 2
13271 case "i":
13272 return String(isoDayOfWeek);
13273 // 02
13274 case "ii":
13275 return addLeadingZeros(isoDayOfWeek, token.length);
13276 // 2nd
13277 case "io":
13278 return localize2.ordinalNumber(isoDayOfWeek, { unit: "day" });
13279 // Tue
13280 case "iii":
13281 return localize2.day(dayOfWeek, {
13282 width: "abbreviated",
13283 context: "formatting"
13284 });
13285 // T
13286 case "iiiii":
13287 return localize2.day(dayOfWeek, {
13288 width: "narrow",
13289 context: "formatting"
13290 });
13291 // Tu
13292 case "iiiiii":
13293 return localize2.day(dayOfWeek, {
13294 width: "short",
13295 context: "formatting"
13296 });
13297 // Tuesday
13298 case "iiii":
13299 default:
13300 return localize2.day(dayOfWeek, {
13301 width: "wide",
13302 context: "formatting"
13303 });
13304 }
13305 },
13306 // AM or PM
13307 a: function(date, token, localize2) {
13308 const hours = date.getHours();
13309 const dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
13310 switch (token) {
13311 case "a":
13312 case "aa":
13313 return localize2.dayPeriod(dayPeriodEnumValue, {
13314 width: "abbreviated",
13315 context: "formatting"
13316 });
13317 case "aaa":
13318 return localize2.dayPeriod(dayPeriodEnumValue, {
13319 width: "abbreviated",
13320 context: "formatting"
13321 }).toLowerCase();
13322 case "aaaaa":
13323 return localize2.dayPeriod(dayPeriodEnumValue, {
13324 width: "narrow",
13325 context: "formatting"
13326 });
13327 case "aaaa":
13328 default:
13329 return localize2.dayPeriod(dayPeriodEnumValue, {
13330 width: "wide",
13331 context: "formatting"
13332 });
13333 }
13334 },
13335 // AM, PM, midnight, noon
13336 b: function(date, token, localize2) {
13337 const hours = date.getHours();
13338 let dayPeriodEnumValue;
13339 if (hours === 12) {
13340 dayPeriodEnumValue = dayPeriodEnum.noon;
13341 } else if (hours === 0) {
13342 dayPeriodEnumValue = dayPeriodEnum.midnight;
13343 } else {
13344 dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
13345 }
13346 switch (token) {
13347 case "b":
13348 case "bb":
13349 return localize2.dayPeriod(dayPeriodEnumValue, {
13350 width: "abbreviated",
13351 context: "formatting"
13352 });
13353 case "bbb":
13354 return localize2.dayPeriod(dayPeriodEnumValue, {
13355 width: "abbreviated",
13356 context: "formatting"
13357 }).toLowerCase();
13358 case "bbbbb":
13359 return localize2.dayPeriod(dayPeriodEnumValue, {
13360 width: "narrow",
13361 context: "formatting"
13362 });
13363 case "bbbb":
13364 default:
13365 return localize2.dayPeriod(dayPeriodEnumValue, {
13366 width: "wide",
13367 context: "formatting"
13368 });
13369 }
13370 },
13371 // in the morning, in the afternoon, in the evening, at night
13372 B: function(date, token, localize2) {
13373 const hours = date.getHours();
13374 let dayPeriodEnumValue;
13375 if (hours >= 17) {
13376 dayPeriodEnumValue = dayPeriodEnum.evening;
13377 } else if (hours >= 12) {
13378 dayPeriodEnumValue = dayPeriodEnum.afternoon;
13379 } else if (hours >= 4) {
13380 dayPeriodEnumValue = dayPeriodEnum.morning;
13381 } else {
13382 dayPeriodEnumValue = dayPeriodEnum.night;
13383 }
13384 switch (token) {
13385 case "B":
13386 case "BB":
13387 case "BBB":
13388 return localize2.dayPeriod(dayPeriodEnumValue, {
13389 width: "abbreviated",
13390 context: "formatting"
13391 });
13392 case "BBBBB":
13393 return localize2.dayPeriod(dayPeriodEnumValue, {
13394 width: "narrow",
13395 context: "formatting"
13396 });
13397 case "BBBB":
13398 default:
13399 return localize2.dayPeriod(dayPeriodEnumValue, {
13400 width: "wide",
13401 context: "formatting"
13402 });
13403 }
13404 },
13405 // Hour [1-12]
13406 h: function(date, token, localize2) {
13407 if (token === "ho") {
13408 let hours = date.getHours() % 12;
13409 if (hours === 0) hours = 12;
13410 return localize2.ordinalNumber(hours, { unit: "hour" });
13411 }
13412 return lightFormatters.h(date, token);
13413 },
13414 // Hour [0-23]
13415 H: function(date, token, localize2) {
13416 if (token === "Ho") {
13417 return localize2.ordinalNumber(date.getHours(), { unit: "hour" });
13418 }
13419 return lightFormatters.H(date, token);
13420 },
13421 // Hour [0-11]
13422 K: function(date, token, localize2) {
13423 const hours = date.getHours() % 12;
13424 if (token === "Ko") {
13425 return localize2.ordinalNumber(hours, { unit: "hour" });
13426 }
13427 return addLeadingZeros(hours, token.length);
13428 },
13429 // Hour [1-24]
13430 k: function(date, token, localize2) {
13431 let hours = date.getHours();
13432 if (hours === 0) hours = 24;
13433 if (token === "ko") {
13434 return localize2.ordinalNumber(hours, { unit: "hour" });
13435 }
13436 return addLeadingZeros(hours, token.length);
13437 },
13438 // Minute
13439 m: function(date, token, localize2) {
13440 if (token === "mo") {
13441 return localize2.ordinalNumber(date.getMinutes(), { unit: "minute" });
13442 }
13443 return lightFormatters.m(date, token);
13444 },
13445 // Second
13446 s: function(date, token, localize2) {
13447 if (token === "so") {
13448 return localize2.ordinalNumber(date.getSeconds(), { unit: "second" });
13449 }
13450 return lightFormatters.s(date, token);
13451 },
13452 // Fraction of second
13453 S: function(date, token) {
13454 return lightFormatters.S(date, token);
13455 },
13456 // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
13457 X: function(date, token, _localize) {
13458 const timezoneOffset = date.getTimezoneOffset();
13459 if (timezoneOffset === 0) {
13460 return "Z";
13461 }
13462 switch (token) {
13463 // Hours and optional minutes
13464 case "X":
13465 return formatTimezoneWithOptionalMinutes(timezoneOffset);
13466 // Hours, minutes and optional seconds without `:` delimiter
13467 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
13468 // so this token always has the same output as `XX`
13469 case "XXXX":
13470 case "XX":
13471 return formatTimezone(timezoneOffset);
13472 // Hours, minutes and optional seconds with `:` delimiter
13473 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
13474 // so this token always has the same output as `XXX`
13475 case "XXXXX":
13476 case "XXX":
13477 // Hours and minutes with `:` delimiter
13478 default:
13479 return formatTimezone(timezoneOffset, ":");
13480 }
13481 },
13482 // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
13483 x: function(date, token, _localize) {
13484 const timezoneOffset = date.getTimezoneOffset();
13485 switch (token) {
13486 // Hours and optional minutes
13487 case "x":
13488 return formatTimezoneWithOptionalMinutes(timezoneOffset);
13489 // Hours, minutes and optional seconds without `:` delimiter
13490 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
13491 // so this token always has the same output as `xx`
13492 case "xxxx":
13493 case "xx":
13494 return formatTimezone(timezoneOffset);
13495 // Hours, minutes and optional seconds with `:` delimiter
13496 // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
13497 // so this token always has the same output as `xxx`
13498 case "xxxxx":
13499 case "xxx":
13500 // Hours and minutes with `:` delimiter
13501 default:
13502 return formatTimezone(timezoneOffset, ":");
13503 }
13504 },
13505 // Timezone (GMT)
13506 O: function(date, token, _localize) {
13507 const timezoneOffset = date.getTimezoneOffset();
13508 switch (token) {
13509 // Short
13510 case "O":
13511 case "OO":
13512 case "OOO":
13513 return "GMT" + formatTimezoneShort(timezoneOffset, ":");
13514 // Long
13515 case "OOOO":
13516 default:
13517 return "GMT" + formatTimezone(timezoneOffset, ":");
13518 }
13519 },
13520 // Timezone (specific non-location)
13521 z: function(date, token, _localize) {
13522 const timezoneOffset = date.getTimezoneOffset();
13523 switch (token) {
13524 // Short
13525 case "z":
13526 case "zz":
13527 case "zzz":
13528 return "GMT" + formatTimezoneShort(timezoneOffset, ":");
13529 // Long
13530 case "zzzz":
13531 default:
13532 return "GMT" + formatTimezone(timezoneOffset, ":");
13533 }
13534 },
13535 // Seconds timestamp
13536 t: function(date, token, _localize) {
13537 const timestamp = Math.trunc(+date / 1e3);
13538 return addLeadingZeros(timestamp, token.length);
13539 },
13540 // Milliseconds timestamp
13541 T: function(date, token, _localize) {
13542 return addLeadingZeros(+date, token.length);
13543 }
13544 };
13545 function formatTimezoneShort(offset, delimiter = "") {
13546 const sign = offset > 0 ? "-" : "+";
13547 const absOffset = Math.abs(offset);
13548 const hours = Math.trunc(absOffset / 60);
13549 const minutes = absOffset % 60;
13550 if (minutes === 0) {
13551 return sign + String(hours);
13552 }
13553 return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
13554 }
13555 function formatTimezoneWithOptionalMinutes(offset, delimiter) {
13556 if (offset % 60 === 0) {
13557 const sign = offset > 0 ? "-" : "+";
13558 return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
13559 }
13560 return formatTimezone(offset, delimiter);
13561 }
13562 function formatTimezone(offset, delimiter = "") {
13563 const sign = offset > 0 ? "-" : "+";
13564 const absOffset = Math.abs(offset);
13565 const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2);
13566 const minutes = addLeadingZeros(absOffset % 60, 2);
13567 return sign + hours + delimiter + minutes;
13568 }
13569
13570 // packages/dataviews/node_modules/date-fns/_lib/format/longFormatters.js
13571 var dateLongFormatter = (pattern, formatLong2) => {
13572 switch (pattern) {
13573 case "P":
13574 return formatLong2.date({ width: "short" });
13575 case "PP":
13576 return formatLong2.date({ width: "medium" });
13577 case "PPP":
13578 return formatLong2.date({ width: "long" });
13579 case "PPPP":
13580 default:
13581 return formatLong2.date({ width: "full" });
13582 }
13583 };
13584 var timeLongFormatter = (pattern, formatLong2) => {
13585 switch (pattern) {
13586 case "p":
13587 return formatLong2.time({ width: "short" });
13588 case "pp":
13589 return formatLong2.time({ width: "medium" });
13590 case "ppp":
13591 return formatLong2.time({ width: "long" });
13592 case "pppp":
13593 default:
13594 return formatLong2.time({ width: "full" });
13595 }
13596 };
13597 var dateTimeLongFormatter = (pattern, formatLong2) => {
13598 const matchResult = pattern.match(/(P+)(p+)?/) || [];
13599 const datePattern = matchResult[1];
13600 const timePattern = matchResult[2];
13601 if (!timePattern) {
13602 return dateLongFormatter(pattern, formatLong2);
13603 }
13604 let dateTimeFormat;
13605 switch (datePattern) {
13606 case "P":
13607 dateTimeFormat = formatLong2.dateTime({ width: "short" });
13608 break;
13609 case "PP":
13610 dateTimeFormat = formatLong2.dateTime({ width: "medium" });
13611 break;
13612 case "PPP":
13613 dateTimeFormat = formatLong2.dateTime({ width: "long" });
13614 break;
13615 case "PPPP":
13616 default:
13617 dateTimeFormat = formatLong2.dateTime({ width: "full" });
13618 break;
13619 }
13620 return dateTimeFormat.replace("{{date}}", dateLongFormatter(datePattern, formatLong2)).replace("{{time}}", timeLongFormatter(timePattern, formatLong2));
13621 };
13622 var longFormatters = {
13623 p: timeLongFormatter,
13624 P: dateTimeLongFormatter
13625 };
13626
13627 // packages/dataviews/node_modules/date-fns/_lib/protectedTokens.js
13628 var dayOfYearTokenRE = /^D+$/;
13629 var weekYearTokenRE = /^Y+$/;
13630 var throwTokens = ["D", "DD", "YY", "YYYY"];
13631 function isProtectedDayOfYearToken(token) {
13632 return dayOfYearTokenRE.test(token);
13633 }
13634 function isProtectedWeekYearToken(token) {
13635 return weekYearTokenRE.test(token);
13636 }
13637 function warnOrThrowProtectedError(token, format6, input) {
13638 const _message = message(token, format6, input);
13639 console.warn(_message);
13640 if (throwTokens.includes(token)) throw new RangeError(_message);
13641 }
13642 function message(token, format6, input) {
13643 const subject = token[0] === "Y" ? "years" : "days of the month";
13644 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`;
13645 }
13646
13647 // packages/dataviews/node_modules/date-fns/format.js
13648 var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
13649 var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
13650 var escapedStringRegExp = /^'([^]*?)'?$/;
13651 var doubleQuoteRegExp = /''/g;
13652 var unescapedLatinCharacterRegExp = /[a-zA-Z]/;
13653 function format(date, formatStr, options) {
13654 const defaultOptions2 = getDefaultOptions();
13655 const locale = options?.locale ?? defaultOptions2.locale ?? enUS;
13656 const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
13657 const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
13658 const originalDate = toDate(date, options?.in);
13659 if (!isValid(originalDate)) {
13660 throw new RangeError("Invalid time value");
13661 }
13662 let parts = formatStr.match(longFormattingTokensRegExp).map((substring) => {
13663 const firstCharacter = substring[0];
13664 if (firstCharacter === "p" || firstCharacter === "P") {
13665 const longFormatter = longFormatters[firstCharacter];
13666 return longFormatter(substring, locale.formatLong);
13667 }
13668 return substring;
13669 }).join("").match(formattingTokensRegExp).map((substring) => {
13670 if (substring === "''") {
13671 return { isToken: false, value: "'" };
13672 }
13673 const firstCharacter = substring[0];
13674 if (firstCharacter === "'") {
13675 return { isToken: false, value: cleanEscapedString(substring) };
13676 }
13677 if (formatters[firstCharacter]) {
13678 return { isToken: true, value: substring };
13679 }
13680 if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
13681 throw new RangeError(
13682 "Format string contains an unescaped latin alphabet character `" + firstCharacter + "`"
13683 );
13684 }
13685 return { isToken: false, value: substring };
13686 });
13687 if (locale.localize.preprocessor) {
13688 parts = locale.localize.preprocessor(originalDate, parts);
13689 }
13690 const formatterOptions = {
13691 firstWeekContainsDate,
13692 weekStartsOn,
13693 locale
13694 };
13695 return parts.map((part) => {
13696 if (!part.isToken) return part.value;
13697 const token = part.value;
13698 if (!options?.useAdditionalWeekYearTokens && isProtectedWeekYearToken(token) || !options?.useAdditionalDayOfYearTokens && isProtectedDayOfYearToken(token)) {
13699 warnOrThrowProtectedError(token, formatStr, String(date));
13700 }
13701 const formatter = formatters[token[0]];
13702 return formatter(originalDate, token, locale.localize, formatterOptions);
13703 }).join("");
13704 }
13705 function cleanEscapedString(input) {
13706 const matched = input.match(escapedStringRegExp);
13707 if (!matched) {
13708 return input;
13709 }
13710 return matched[1].replace(doubleQuoteRegExp, "'");
13711 }
13712
13713 // packages/dataviews/node_modules/date-fns/subDays.js
13714 function subDays(date, amount, options) {
13715 return addDays(date, -amount, options);
13716 }
13717
13718 // packages/dataviews/node_modules/date-fns/subMonths.js
13719 function subMonths(date, amount, options) {
13720 return addMonths(date, -amount, options);
13721 }
13722
13723 // packages/dataviews/node_modules/date-fns/subYears.js
13724 function subYears(date, amount, options) {
13725 return addYears(date, -amount, options);
13726 }
13727
13728 // packages/dataviews/build-module/components/dataform-controls/datetime.mjs
13729 var import_components30 = __toESM(require_components(), 1);
13730 var import_element39 = __toESM(require_element(), 1);
13731 var import_i18n38 = __toESM(require_i18n(), 1);
13732 var import_date2 = __toESM(require_date(), 1);
13733
13734 // packages/dataviews/build-module/components/dataform-controls/utils/relative-date-control.mjs
13735 var import_components29 = __toESM(require_components(), 1);
13736 var import_element38 = __toESM(require_element(), 1);
13737 var import_i18n37 = __toESM(require_i18n(), 1);
13738 var import_jsx_runtime74 = __toESM(require_jsx_runtime(), 1);
13739 var TIME_UNITS_OPTIONS = {
13740 [OPERATOR_IN_THE_PAST]: [
13741 { value: "days", label: (0, import_i18n37.__)("Days") },
13742 { value: "weeks", label: (0, import_i18n37.__)("Weeks") },
13743 { value: "months", label: (0, import_i18n37.__)("Months") },
13744 { value: "years", label: (0, import_i18n37.__)("Years") }
13745 ],
13746 [OPERATOR_OVER]: [
13747 { value: "days", label: (0, import_i18n37.__)("Days ago") },
13748 { value: "weeks", label: (0, import_i18n37.__)("Weeks ago") },
13749 { value: "months", label: (0, import_i18n37.__)("Months ago") },
13750 { value: "years", label: (0, import_i18n37.__)("Years ago") }
13751 ]
13752 };
13753 function RelativeDateControl({
13754 className,
13755 data,
13756 field,
13757 onChange,
13758 hideLabelFromVision,
13759 operator
13760 }) {
13761 const options = TIME_UNITS_OPTIONS[operator === OPERATOR_IN_THE_PAST ? "inThePast" : "over"];
13762 const { id, label, getValue, setValue } = field;
13763 const fieldValue = getValue({ item: data });
13764 const { value: relValue = "", unit = options[0].value } = fieldValue && typeof fieldValue === "object" ? fieldValue : {};
13765 const onChangeValue = (0, import_element38.useCallback)(
13766 (newValue) => onChange(
13767 setValue({
13768 item: data,
13769 value: { value: Number(newValue), unit }
13770 })
13771 ),
13772 [onChange, setValue, data, unit]
13773 );
13774 const onChangeUnit = (0, import_element38.useCallback)(
13775 (newUnit) => onChange(
13776 setValue({
13777 item: data,
13778 value: { value: relValue, unit: newUnit }
13779 })
13780 ),
13781 [onChange, setValue, data, relValue]
13782 );
13783 return /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(
13784 import_components29.BaseControl,
13785 {
13786 id,
13787 className: clsx_default(className, "dataviews-controls__relative-date"),
13788 label,
13789 hideLabelFromVision,
13790 children: /* @__PURE__ */ (0, import_jsx_runtime74.jsxs)(Stack, { direction: "row", gap: "xs", children: [
13791 /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(
13792 import_components29.__experimentalNumberControl,
13793 {
13794 __next40pxDefaultSize: true,
13795 className: "dataviews-controls__relative-date-number",
13796 spinControls: "none",
13797 min: 1,
13798 step: 1,
13799 value: relValue,
13800 onChange: onChangeValue
13801 }
13802 ),
13803 /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(
13804 import_components29.SelectControl,
13805 {
13806 className: "dataviews-controls__relative-date-unit",
13807 __next40pxDefaultSize: true,
13808 label: (0, import_i18n37.__)("Unit"),
13809 value: unit,
13810 options,
13811 onChange: onChangeUnit,
13812 hideLabelFromVision: true
13813 }
13814 )
13815 ] })
13816 }
13817 );
13818 }
13819
13820 // packages/dataviews/build-module/field-types/utils/parse-date-time.mjs
13821 var import_date = __toESM(require_date(), 1);
13822 function parseDateTime(dateTimeString) {
13823 if (!dateTimeString) {
13824 return null;
13825 }
13826 const parsed = (0, import_date.getDate)(dateTimeString);
13827 return parsed && isValid(parsed) ? parsed : null;
13828 }
13829
13830 // packages/dataviews/build-module/components/dataform-controls/datetime.mjs
13831 var import_jsx_runtime75 = __toESM(require_jsx_runtime(), 1);
13832 var { DateCalendar, ValidatedInputControl } = unlock(import_components30.privateApis);
13833 var formatDateTime = (date) => {
13834 if (!date) {
13835 return "";
13836 }
13837 if (typeof date === "string") {
13838 return date;
13839 }
13840 return format(date, "yyyy-MM-dd'T'HH:mm");
13841 };
13842 function CalendarDateTimeControl({
13843 data,
13844 field,
13845 onChange,
13846 hideLabelFromVision,
13847 validity
13848 }) {
13849 const { id, label, description, setValue, getValue, isValid: isValid2 } = field;
13850 const fieldValue = getValue({ item: data });
13851 const value = typeof fieldValue === "string" ? fieldValue : void 0;
13852 const [calendarMonth, setCalendarMonth] = (0, import_element39.useState)(() => {
13853 const parsedDate = parseDateTime(value);
13854 return parsedDate || /* @__PURE__ */ new Date();
13855 });
13856 const inputControlRef = (0, import_element39.useRef)(null);
13857 const validationTimeoutRef = (0, import_element39.useRef)();
13858 const previousFocusRef = (0, import_element39.useRef)(null);
13859 const onChangeCallback = (0, import_element39.useCallback)(
13860 (newValue) => onChange(setValue({ item: data, value: newValue })),
13861 [data, onChange, setValue]
13862 );
13863 (0, import_element39.useEffect)(() => {
13864 return () => {
13865 if (validationTimeoutRef.current) {
13866 clearTimeout(validationTimeoutRef.current);
13867 }
13868 };
13869 }, []);
13870 const onSelectDate = (0, import_element39.useCallback)(
13871 (newDate) => {
13872 let dateTimeValue;
13873 if (newDate) {
13874 let finalDateTime = newDate;
13875 if (value) {
13876 const currentDateTime = parseDateTime(value);
13877 if (currentDateTime) {
13878 finalDateTime = new Date(newDate);
13879 finalDateTime.setHours(currentDateTime.getHours());
13880 finalDateTime.setMinutes(
13881 currentDateTime.getMinutes()
13882 );
13883 }
13884 }
13885 dateTimeValue = finalDateTime.toISOString();
13886 onChangeCallback(dateTimeValue);
13887 if (validationTimeoutRef.current) {
13888 clearTimeout(validationTimeoutRef.current);
13889 }
13890 } else {
13891 onChangeCallback(void 0);
13892 }
13893 previousFocusRef.current = inputControlRef.current && inputControlRef.current.ownerDocument.activeElement;
13894 validationTimeoutRef.current = setTimeout(() => {
13895 if (inputControlRef.current) {
13896 inputControlRef.current.focus();
13897 inputControlRef.current.blur();
13898 onChangeCallback(dateTimeValue);
13899 if (previousFocusRef.current && previousFocusRef.current instanceof HTMLElement) {
13900 previousFocusRef.current.focus();
13901 }
13902 }
13903 }, 0);
13904 },
13905 [onChangeCallback, value]
13906 );
13907 const handleManualDateTimeChange = (0, import_element39.useCallback)(
13908 (newValue) => {
13909 if (newValue) {
13910 const dateTime = new Date(newValue);
13911 onChangeCallback(dateTime.toISOString());
13912 const parsedDate = parseDateTime(dateTime.toISOString());
13913 if (parsedDate) {
13914 setCalendarMonth(parsedDate);
13915 }
13916 } else {
13917 onChangeCallback(void 0);
13918 }
13919 },
13920 [onChangeCallback]
13921 );
13922 const { format: fieldFormat } = field;
13923 const weekStartsOn = fieldFormat.weekStartsOn ?? (0, import_date2.getSettings)().l10n.startOfWeek;
13924 const {
13925 timezone: { string: timezoneString }
13926 } = (0, import_date2.getSettings)();
13927 const displayLabel = isValid2?.required && !hideLabelFromVision ? `${label} (${(0, import_i18n38.__)("Required")})` : label;
13928 return /* @__PURE__ */ (0, import_jsx_runtime75.jsx)(
13929 import_components30.BaseControl,
13930 {
13931 id,
13932 label: displayLabel,
13933 help: description,
13934 hideLabelFromVision,
13935 children: /* @__PURE__ */ (0, import_jsx_runtime75.jsxs)(Stack, { direction: "column", gap: "md", children: [
13936 /* @__PURE__ */ (0, import_jsx_runtime75.jsx)(
13937 DateCalendar,
13938 {
13939 style: { width: "100%" },
13940 selected: value ? parseDateTime(value) || void 0 : void 0,
13941 onSelect: onSelectDate,
13942 month: calendarMonth,
13943 onMonthChange: setCalendarMonth,
13944 timeZone: timezoneString || void 0,
13945 weekStartsOn
13946 }
13947 ),
13948 /* @__PURE__ */ (0, import_jsx_runtime75.jsx)(
13949 ValidatedInputControl,
13950 {
13951 ref: inputControlRef,
13952 __next40pxDefaultSize: true,
13953 required: !!isValid2?.required,
13954 customValidity: getCustomValidity(isValid2, validity),
13955 type: "datetime-local",
13956 label: (0, import_i18n38.__)("Date time"),
13957 hideLabelFromVision: true,
13958 value: value ? formatDateTime(
13959 parseDateTime(value) || void 0
13960 ) : "",
13961 onChange: handleManualDateTimeChange
13962 }
13963 )
13964 ] })
13965 }
13966 );
13967 }
13968 function DateTime({
13969 data,
13970 field,
13971 onChange,
13972 hideLabelFromVision,
13973 operator,
13974 validity
13975 }) {
13976 if (operator === OPERATOR_IN_THE_PAST || operator === OPERATOR_OVER) {
13977 return /* @__PURE__ */ (0, import_jsx_runtime75.jsx)(
13978 RelativeDateControl,
13979 {
13980 className: "dataviews-controls__datetime",
13981 data,
13982 field,
13983 onChange,
13984 hideLabelFromVision,
13985 operator
13986 }
13987 );
13988 }
13989 return /* @__PURE__ */ (0, import_jsx_runtime75.jsx)(
13990 CalendarDateTimeControl,
13991 {
13992 data,
13993 field,
13994 onChange,
13995 hideLabelFromVision,
13996 validity
13997 }
13998 );
13999 }
14000
14001 // packages/dataviews/build-module/components/dataform-controls/date.mjs
14002 var import_components31 = __toESM(require_components(), 1);
14003 var import_element40 = __toESM(require_element(), 1);
14004 var import_i18n39 = __toESM(require_i18n(), 1);
14005 var import_date3 = __toESM(require_date(), 1);
14006 var import_jsx_runtime76 = __toESM(require_jsx_runtime(), 1);
14007 var { DateCalendar: DateCalendar2, DateRangeCalendar } = unlock(import_components31.privateApis);
14008 var DATE_PRESETS = [
14009 {
14010 id: "today",
14011 label: (0, import_i18n39.__)("Today"),
14012 getValue: () => (0, import_date3.getDate)(null)
14013 },
14014 {
14015 id: "yesterday",
14016 label: (0, import_i18n39.__)("Yesterday"),
14017 getValue: () => {
14018 const today = (0, import_date3.getDate)(null);
14019 return subDays(today, 1);
14020 }
14021 },
14022 {
14023 id: "past-week",
14024 label: (0, import_i18n39.__)("Past week"),
14025 getValue: () => {
14026 const today = (0, import_date3.getDate)(null);
14027 return subDays(today, 7);
14028 }
14029 },
14030 {
14031 id: "past-month",
14032 label: (0, import_i18n39.__)("Past month"),
14033 getValue: () => {
14034 const today = (0, import_date3.getDate)(null);
14035 return subMonths(today, 1);
14036 }
14037 }
14038 ];
14039 var DATE_RANGE_PRESETS = [
14040 {
14041 id: "last-7-days",
14042 label: (0, import_i18n39.__)("Last 7 days"),
14043 getValue: () => {
14044 const today = (0, import_date3.getDate)(null);
14045 return [subDays(today, 7), today];
14046 }
14047 },
14048 {
14049 id: "last-30-days",
14050 label: (0, import_i18n39.__)("Last 30 days"),
14051 getValue: () => {
14052 const today = (0, import_date3.getDate)(null);
14053 return [subDays(today, 30), today];
14054 }
14055 },
14056 {
14057 id: "month-to-date",
14058 label: (0, import_i18n39.__)("Month to date"),
14059 getValue: () => {
14060 const today = (0, import_date3.getDate)(null);
14061 return [startOfMonth(today), today];
14062 }
14063 },
14064 {
14065 id: "last-year",
14066 label: (0, import_i18n39.__)("Last year"),
14067 getValue: () => {
14068 const today = (0, import_date3.getDate)(null);
14069 return [subYears(today, 1), today];
14070 }
14071 },
14072 {
14073 id: "year-to-date",
14074 label: (0, import_i18n39.__)("Year to date"),
14075 getValue: () => {
14076 const today = (0, import_date3.getDate)(null);
14077 return [startOfYear(today), today];
14078 }
14079 }
14080 ];
14081 var parseDate = (dateString) => {
14082 if (!dateString) {
14083 return null;
14084 }
14085 const parsed = (0, import_date3.getDate)(dateString);
14086 return parsed && isValid(parsed) ? parsed : null;
14087 };
14088 var formatDate = (date) => {
14089 if (!date) {
14090 return "";
14091 }
14092 return typeof date === "string" ? date : format(date, "yyyy-MM-dd");
14093 };
14094 function ValidatedDateControl({
14095 field,
14096 validity,
14097 inputRefs,
14098 isTouched,
14099 setIsTouched,
14100 children
14101 }) {
14102 const { isValid: isValid2 } = field;
14103 const [customValidity, setCustomValidity] = (0, import_element40.useState)(void 0);
14104 const validateRefs = (0, import_element40.useCallback)(() => {
14105 const refs = Array.isArray(inputRefs) ? inputRefs : [inputRefs];
14106 for (const ref of refs) {
14107 const input = ref.current;
14108 if (input && !input.validity.valid) {
14109 setCustomValidity({
14110 type: "invalid",
14111 message: input.validationMessage
14112 });
14113 return;
14114 }
14115 }
14116 setCustomValidity(void 0);
14117 }, [inputRefs]);
14118 (0, import_element40.useEffect)(() => {
14119 if (isTouched) {
14120 const timeoutId = setTimeout(() => {
14121 if (validity) {
14122 setCustomValidity(getCustomValidity(isValid2, validity));
14123 } else {
14124 validateRefs();
14125 }
14126 }, 0);
14127 return () => clearTimeout(timeoutId);
14128 }
14129 return void 0;
14130 }, [isTouched, isValid2, validity, validateRefs]);
14131 const onBlur = (event) => {
14132 if (isTouched) {
14133 return;
14134 }
14135 if (!event.relatedTarget || !event.currentTarget.contains(event.relatedTarget)) {
14136 setIsTouched(true);
14137 }
14138 };
14139 return /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)("div", { onBlur, children: [
14140 children,
14141 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)("div", { "aria-live": "polite", children: customValidity && /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)(
14142 "p",
14143 {
14144 className: clsx_default(
14145 "components-validated-control__indicator",
14146 customValidity.type === "invalid" ? "is-invalid" : void 0,
14147 customValidity.type === "valid" ? "is-valid" : void 0
14148 ),
14149 children: [
14150 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14151 import_components31.Icon,
14152 {
14153 className: "components-validated-control__indicator-icon",
14154 icon: error_default,
14155 size: 16,
14156 fill: "currentColor"
14157 }
14158 ),
14159 customValidity.message
14160 ]
14161 }
14162 ) })
14163 ] });
14164 }
14165 function CalendarDateControl({
14166 data,
14167 field,
14168 onChange,
14169 hideLabelFromVision,
14170 validity
14171 }) {
14172 const {
14173 id,
14174 label,
14175 setValue,
14176 getValue,
14177 isValid: isValid2,
14178 format: fieldFormat
14179 } = field;
14180 const [selectedPresetId, setSelectedPresetId] = (0, import_element40.useState)(
14181 null
14182 );
14183 const weekStartsOn = fieldFormat.weekStartsOn ?? (0, import_date3.getSettings)().l10n.startOfWeek;
14184 const fieldValue = getValue({ item: data });
14185 const value = typeof fieldValue === "string" ? fieldValue : void 0;
14186 const [calendarMonth, setCalendarMonth] = (0, import_element40.useState)(() => {
14187 const parsedDate = parseDate(value);
14188 return parsedDate || /* @__PURE__ */ new Date();
14189 });
14190 const [isTouched, setIsTouched] = (0, import_element40.useState)(false);
14191 const validityTargetRef = (0, import_element40.useRef)(null);
14192 const onChangeCallback = (0, import_element40.useCallback)(
14193 (newValue) => onChange(setValue({ item: data, value: newValue })),
14194 [data, onChange, setValue]
14195 );
14196 const onSelectDate = (0, import_element40.useCallback)(
14197 (newDate) => {
14198 const dateValue = newDate ? format(newDate, "yyyy-MM-dd") : void 0;
14199 onChangeCallback(dateValue);
14200 setSelectedPresetId(null);
14201 setIsTouched(true);
14202 },
14203 [onChangeCallback]
14204 );
14205 const handlePresetClick = (0, import_element40.useCallback)(
14206 (preset) => {
14207 const presetDate = preset.getValue();
14208 const dateValue = formatDate(presetDate);
14209 setCalendarMonth(presetDate);
14210 onChangeCallback(dateValue);
14211 setSelectedPresetId(preset.id);
14212 setIsTouched(true);
14213 },
14214 [onChangeCallback]
14215 );
14216 const handleManualDateChange = (0, import_element40.useCallback)(
14217 (newValue) => {
14218 onChangeCallback(newValue);
14219 if (newValue) {
14220 const parsedDate = parseDate(newValue);
14221 if (parsedDate) {
14222 setCalendarMonth(parsedDate);
14223 }
14224 }
14225 setSelectedPresetId(null);
14226 setIsTouched(true);
14227 },
14228 [onChangeCallback]
14229 );
14230 const {
14231 timezone: { string: timezoneString }
14232 } = (0, import_date3.getSettings)();
14233 const displayLabel = isValid2?.required ? `${label} (${(0, import_i18n39.__)("Required")})` : label;
14234 return /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14235 ValidatedDateControl,
14236 {
14237 field,
14238 validity,
14239 inputRefs: validityTargetRef,
14240 isTouched,
14241 setIsTouched,
14242 children: /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14243 import_components31.BaseControl,
14244 {
14245 id,
14246 className: "dataviews-controls__date",
14247 label: displayLabel,
14248 hideLabelFromVision,
14249 children: /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)(Stack, { direction: "column", gap: "md", children: [
14250 /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)(
14251 Stack,
14252 {
14253 direction: "row",
14254 gap: "xs",
14255 wrap: "wrap",
14256 justify: "flex-start",
14257 children: [
14258 DATE_PRESETS.map((preset) => {
14259 const isSelected2 = selectedPresetId === preset.id;
14260 return /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14261 import_components31.Button,
14262 {
14263 className: "dataviews-controls__date-preset",
14264 variant: "tertiary",
14265 isPressed: isSelected2,
14266 size: "small",
14267 onClick: () => handlePresetClick(preset),
14268 children: preset.label
14269 },
14270 preset.id
14271 );
14272 }),
14273 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14274 import_components31.Button,
14275 {
14276 className: "dataviews-controls__date-preset",
14277 variant: "tertiary",
14278 isPressed: !selectedPresetId,
14279 size: "small",
14280 disabled: !!selectedPresetId,
14281 accessibleWhenDisabled: false,
14282 children: (0, import_i18n39.__)("Custom")
14283 }
14284 )
14285 ]
14286 }
14287 ),
14288 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14289 import_components31.__experimentalInputControl,
14290 {
14291 __next40pxDefaultSize: true,
14292 ref: validityTargetRef,
14293 type: "date",
14294 label: (0, import_i18n39.__)("Date"),
14295 hideLabelFromVision: true,
14296 value,
14297 onChange: handleManualDateChange,
14298 required: !!field.isValid?.required
14299 }
14300 ),
14301 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14302 DateCalendar2,
14303 {
14304 style: { width: "100%" },
14305 selected: value ? parseDate(value) || void 0 : void 0,
14306 onSelect: onSelectDate,
14307 month: calendarMonth,
14308 onMonthChange: setCalendarMonth,
14309 timeZone: timezoneString || void 0,
14310 weekStartsOn
14311 }
14312 )
14313 ] })
14314 }
14315 )
14316 }
14317 );
14318 }
14319 function CalendarDateRangeControl({
14320 data,
14321 field,
14322 onChange,
14323 hideLabelFromVision,
14324 validity
14325 }) {
14326 const { id, label, getValue, setValue, format: fieldFormat } = field;
14327 let value;
14328 const fieldValue = getValue({ item: data });
14329 if (Array.isArray(fieldValue) && fieldValue.length === 2 && fieldValue.every((date) => typeof date === "string")) {
14330 value = fieldValue;
14331 }
14332 const weekStartsOn = fieldFormat.weekStartsOn ?? (0, import_date3.getSettings)().l10n.startOfWeek;
14333 const onChangeCallback = (0, import_element40.useCallback)(
14334 (newValue) => {
14335 onChange(
14336 setValue({
14337 item: data,
14338 value: newValue
14339 })
14340 );
14341 },
14342 [data, onChange, setValue]
14343 );
14344 const [selectedPresetId, setSelectedPresetId] = (0, import_element40.useState)(
14345 null
14346 );
14347 const selectedRange = (0, import_element40.useMemo)(() => {
14348 if (!value) {
14349 return { from: void 0, to: void 0 };
14350 }
14351 const [from, to] = value;
14352 return {
14353 from: parseDate(from) || void 0,
14354 to: parseDate(to) || void 0
14355 };
14356 }, [value]);
14357 const [calendarMonth, setCalendarMonth] = (0, import_element40.useState)(() => {
14358 return selectedRange.from || /* @__PURE__ */ new Date();
14359 });
14360 const [isTouched, setIsTouched] = (0, import_element40.useState)(false);
14361 const fromInputRef = (0, import_element40.useRef)(null);
14362 const toInputRef = (0, import_element40.useRef)(null);
14363 const updateDateRange = (0, import_element40.useCallback)(
14364 (fromDate, toDate2) => {
14365 if (fromDate && toDate2) {
14366 onChangeCallback([
14367 formatDate(fromDate),
14368 formatDate(toDate2)
14369 ]);
14370 } else if (!fromDate && !toDate2) {
14371 onChangeCallback(void 0);
14372 }
14373 },
14374 [onChangeCallback]
14375 );
14376 const onSelectCalendarRange = (0, import_element40.useCallback)(
14377 (newRange) => {
14378 updateDateRange(newRange?.from, newRange?.to);
14379 setSelectedPresetId(null);
14380 setIsTouched(true);
14381 },
14382 [updateDateRange]
14383 );
14384 const handlePresetClick = (0, import_element40.useCallback)(
14385 (preset) => {
14386 const [startDate, endDate] = preset.getValue();
14387 setCalendarMonth(startDate);
14388 updateDateRange(startDate, endDate);
14389 setSelectedPresetId(preset.id);
14390 setIsTouched(true);
14391 },
14392 [updateDateRange]
14393 );
14394 const handleManualDateChange = (0, import_element40.useCallback)(
14395 (fromOrTo, newValue) => {
14396 const [currentFrom, currentTo] = value || [
14397 void 0,
14398 void 0
14399 ];
14400 const updatedFrom = fromOrTo === "from" ? newValue : currentFrom;
14401 const updatedTo = fromOrTo === "to" ? newValue : currentTo;
14402 updateDateRange(updatedFrom, updatedTo);
14403 if (newValue) {
14404 const parsedDate = parseDate(newValue);
14405 if (parsedDate) {
14406 setCalendarMonth(parsedDate);
14407 }
14408 }
14409 setSelectedPresetId(null);
14410 setIsTouched(true);
14411 },
14412 [value, updateDateRange]
14413 );
14414 const { timezone } = (0, import_date3.getSettings)();
14415 const displayLabel = field.isValid?.required ? `${label} (${(0, import_i18n39.__)("Required")})` : label;
14416 return /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14417 ValidatedDateControl,
14418 {
14419 field,
14420 validity,
14421 inputRefs: [fromInputRef, toInputRef],
14422 isTouched,
14423 setIsTouched,
14424 children: /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14425 import_components31.BaseControl,
14426 {
14427 id,
14428 className: "dataviews-controls__date",
14429 label: displayLabel,
14430 hideLabelFromVision,
14431 children: /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)(Stack, { direction: "column", gap: "md", children: [
14432 /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)(
14433 Stack,
14434 {
14435 direction: "row",
14436 gap: "xs",
14437 wrap: "wrap",
14438 justify: "flex-start",
14439 children: [
14440 DATE_RANGE_PRESETS.map((preset) => {
14441 const isSelected2 = selectedPresetId === preset.id;
14442 return /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14443 import_components31.Button,
14444 {
14445 className: "dataviews-controls__date-preset",
14446 variant: "tertiary",
14447 isPressed: isSelected2,
14448 size: "small",
14449 onClick: () => handlePresetClick(preset),
14450 children: preset.label
14451 },
14452 preset.id
14453 );
14454 }),
14455 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14456 import_components31.Button,
14457 {
14458 className: "dataviews-controls__date-preset",
14459 variant: "tertiary",
14460 isPressed: !selectedPresetId,
14461 size: "small",
14462 accessibleWhenDisabled: false,
14463 disabled: !!selectedPresetId,
14464 children: (0, import_i18n39.__)("Custom")
14465 }
14466 )
14467 ]
14468 }
14469 ),
14470 /* @__PURE__ */ (0, import_jsx_runtime76.jsxs)(
14471 Stack,
14472 {
14473 direction: "row",
14474 gap: "xs",
14475 justify: "space-between",
14476 className: "dataviews-controls__date-range-inputs",
14477 children: [
14478 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14479 import_components31.__experimentalInputControl,
14480 {
14481 __next40pxDefaultSize: true,
14482 ref: fromInputRef,
14483 type: "date",
14484 label: (0, import_i18n39.__)("From"),
14485 hideLabelFromVision: true,
14486 value: value?.[0],
14487 onChange: (newValue) => handleManualDateChange("from", newValue),
14488 required: !!field.isValid?.required
14489 }
14490 ),
14491 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14492 import_components31.__experimentalInputControl,
14493 {
14494 __next40pxDefaultSize: true,
14495 ref: toInputRef,
14496 type: "date",
14497 label: (0, import_i18n39.__)("To"),
14498 hideLabelFromVision: true,
14499 value: value?.[1],
14500 onChange: (newValue) => handleManualDateChange("to", newValue),
14501 required: !!field.isValid?.required
14502 }
14503 )
14504 ]
14505 }
14506 ),
14507 /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14508 DateRangeCalendar,
14509 {
14510 style: { width: "100%" },
14511 selected: selectedRange,
14512 onSelect: onSelectCalendarRange,
14513 month: calendarMonth,
14514 onMonthChange: setCalendarMonth,
14515 timeZone: timezone.string || void 0,
14516 weekStartsOn
14517 }
14518 )
14519 ] })
14520 }
14521 )
14522 }
14523 );
14524 }
14525 function DateControl({
14526 data,
14527 field,
14528 onChange,
14529 hideLabelFromVision,
14530 operator,
14531 validity
14532 }) {
14533 if (operator === OPERATOR_IN_THE_PAST || operator === OPERATOR_OVER) {
14534 return /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14535 RelativeDateControl,
14536 {
14537 className: "dataviews-controls__date",
14538 data,
14539 field,
14540 onChange,
14541 hideLabelFromVision,
14542 operator
14543 }
14544 );
14545 }
14546 if (operator === OPERATOR_BETWEEN) {
14547 return /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14548 CalendarDateRangeControl,
14549 {
14550 data,
14551 field,
14552 onChange,
14553 hideLabelFromVision,
14554 validity
14555 }
14556 );
14557 }
14558 return /* @__PURE__ */ (0, import_jsx_runtime76.jsx)(
14559 CalendarDateControl,
14560 {
14561 data,
14562 field,
14563 onChange,
14564 hideLabelFromVision,
14565 validity
14566 }
14567 );
14568 }
14569
14570 // packages/dataviews/build-module/components/dataform-controls/email.mjs
14571 var import_components33 = __toESM(require_components(), 1);
14572
14573 // packages/dataviews/build-module/components/dataform-controls/utils/validated-input.mjs
14574 var import_components32 = __toESM(require_components(), 1);
14575 var import_element41 = __toESM(require_element(), 1);
14576 var import_jsx_runtime77 = __toESM(require_jsx_runtime(), 1);
14577 var { ValidatedInputControl: ValidatedInputControl2 } = unlock(import_components32.privateApis);
14578 function ValidatedText({
14579 data,
14580 field,
14581 onChange,
14582 hideLabelFromVision,
14583 type,
14584 prefix,
14585 suffix,
14586 validity
14587 }) {
14588 const { label, placeholder, description, getValue, setValue, isValid: isValid2 } = field;
14589 const value = getValue({ item: data });
14590 const onChangeControl = (0, import_element41.useCallback)(
14591 (newValue) => onChange(
14592 setValue({
14593 item: data,
14594 value: newValue
14595 })
14596 ),
14597 [data, setValue, onChange]
14598 );
14599 return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
14600 ValidatedInputControl2,
14601 {
14602 required: !!isValid2.required,
14603 customValidity: getCustomValidity(isValid2, validity),
14604 label,
14605 placeholder,
14606 value: value ?? "",
14607 help: description,
14608 onChange: onChangeControl,
14609 hideLabelFromVision,
14610 type,
14611 prefix,
14612 suffix,
14613 pattern: isValid2.pattern ? isValid2.pattern.constraint : void 0,
14614 minLength: isValid2.minLength ? isValid2.minLength.constraint : void 0,
14615 maxLength: isValid2.maxLength ? isValid2.maxLength.constraint : void 0,
14616 __next40pxDefaultSize: true
14617 }
14618 );
14619 }
14620
14621 // packages/dataviews/build-module/components/dataform-controls/email.mjs
14622 var import_jsx_runtime78 = __toESM(require_jsx_runtime(), 1);
14623 function Email({
14624 data,
14625 field,
14626 onChange,
14627 hideLabelFromVision,
14628 validity
14629 }) {
14630 return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
14631 ValidatedText,
14632 {
14633 ...{
14634 data,
14635 field,
14636 onChange,
14637 hideLabelFromVision,
14638 validity,
14639 type: "email",
14640 prefix: /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(import_components33.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(import_components33.Icon, { icon: envelope_default }) })
14641 }
14642 }
14643 );
14644 }
14645
14646 // packages/dataviews/build-module/components/dataform-controls/telephone.mjs
14647 var import_components34 = __toESM(require_components(), 1);
14648 var import_jsx_runtime79 = __toESM(require_jsx_runtime(), 1);
14649 function Telephone({
14650 data,
14651 field,
14652 onChange,
14653 hideLabelFromVision,
14654 validity
14655 }) {
14656 return /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(
14657 ValidatedText,
14658 {
14659 ...{
14660 data,
14661 field,
14662 onChange,
14663 hideLabelFromVision,
14664 validity,
14665 type: "tel",
14666 prefix: /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(import_components34.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime79.jsx)(import_components34.Icon, { icon: mobile_default }) })
14667 }
14668 }
14669 );
14670 }
14671
14672 // packages/dataviews/build-module/components/dataform-controls/url.mjs
14673 var import_components35 = __toESM(require_components(), 1);
14674 var import_jsx_runtime80 = __toESM(require_jsx_runtime(), 1);
14675 function Url({
14676 data,
14677 field,
14678 onChange,
14679 hideLabelFromVision,
14680 validity
14681 }) {
14682 return /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(
14683 ValidatedText,
14684 {
14685 ...{
14686 data,
14687 field,
14688 onChange,
14689 hideLabelFromVision,
14690 validity,
14691 type: "url",
14692 prefix: /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(import_components35.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(import_components35.Icon, { icon: link_default }) })
14693 }
14694 }
14695 );
14696 }
14697
14698 // packages/dataviews/build-module/components/dataform-controls/utils/validated-number.mjs
14699 var import_components36 = __toESM(require_components(), 1);
14700 var import_element42 = __toESM(require_element(), 1);
14701 var import_i18n40 = __toESM(require_i18n(), 1);
14702 var import_jsx_runtime81 = __toESM(require_jsx_runtime(), 1);
14703 var { ValidatedNumberControl } = unlock(import_components36.privateApis);
14704 function toNumberOrEmpty(value) {
14705 if (value === "" || value === void 0) {
14706 return "";
14707 }
14708 const number = Number(value);
14709 return Number.isFinite(number) ? number : "";
14710 }
14711 function BetweenControls({
14712 value,
14713 onChange,
14714 hideLabelFromVision,
14715 step
14716 }) {
14717 const [min = "", max = ""] = value;
14718 const onChangeMin = (0, import_element42.useCallback)(
14719 (newValue) => onChange([toNumberOrEmpty(newValue), max]),
14720 [onChange, max]
14721 );
14722 const onChangeMax = (0, import_element42.useCallback)(
14723 (newValue) => onChange([min, toNumberOrEmpty(newValue)]),
14724 [onChange, min]
14725 );
14726 return /* @__PURE__ */ (0, import_jsx_runtime81.jsx)(
14727 import_components36.BaseControl,
14728 {
14729 help: (0, import_i18n40.__)("The max. value must be greater than the min. value."),
14730 children: /* @__PURE__ */ (0, import_jsx_runtime81.jsxs)(import_components36.Flex, { direction: "row", gap: 4, children: [
14731 /* @__PURE__ */ (0, import_jsx_runtime81.jsx)(
14732 import_components36.__experimentalNumberControl,
14733 {
14734 label: (0, import_i18n40.__)("Min."),
14735 value: min,
14736 max: max ? Number(max) - step : void 0,
14737 onChange: onChangeMin,
14738 __next40pxDefaultSize: true,
14739 hideLabelFromVision,
14740 step
14741 }
14742 ),
14743 /* @__PURE__ */ (0, import_jsx_runtime81.jsx)(
14744 import_components36.__experimentalNumberControl,
14745 {
14746 label: (0, import_i18n40.__)("Max."),
14747 value: max,
14748 min: min ? Number(min) + step : void 0,
14749 onChange: onChangeMax,
14750 __next40pxDefaultSize: true,
14751 hideLabelFromVision,
14752 step
14753 }
14754 )
14755 ] })
14756 }
14757 );
14758 }
14759 function ValidatedNumber({
14760 data,
14761 field,
14762 onChange,
14763 hideLabelFromVision,
14764 operator,
14765 validity
14766 }) {
14767 const decimals = field.format?.decimals ?? 0;
14768 const step = Math.pow(10, Math.abs(decimals) * -1);
14769 const { label, description, getValue, setValue, isValid: isValid2 } = field;
14770 const value = getValue({ item: data }) ?? "";
14771 const onChangeControl = (0, import_element42.useCallback)(
14772 (newValue) => {
14773 onChange(
14774 setValue({
14775 item: data,
14776 // Do not convert an empty string or undefined to a number,
14777 // otherwise there's a mismatch between the UI control (empty)
14778 // and the data relied by onChange (0).
14779 value: ["", void 0].includes(newValue) ? void 0 : Number(newValue)
14780 })
14781 );
14782 },
14783 [data, onChange, setValue]
14784 );
14785 const onChangeBetweenControls = (0, import_element42.useCallback)(
14786 (newValue) => {
14787 onChange(
14788 setValue({
14789 item: data,
14790 value: newValue
14791 })
14792 );
14793 },
14794 [data, onChange, setValue]
14795 );
14796 if (operator === OPERATOR_BETWEEN) {
14797 let valueBetween = ["", ""];
14798 if (Array.isArray(value) && value.length === 2 && value.every(
14799 (element) => typeof element === "number" || element === ""
14800 )) {
14801 valueBetween = value;
14802 }
14803 return /* @__PURE__ */ (0, import_jsx_runtime81.jsx)(
14804 BetweenControls,
14805 {
14806 value: valueBetween,
14807 onChange: onChangeBetweenControls,
14808 hideLabelFromVision,
14809 step
14810 }
14811 );
14812 }
14813 return /* @__PURE__ */ (0, import_jsx_runtime81.jsx)(
14814 ValidatedNumberControl,
14815 {
14816 required: !!isValid2.required,
14817 customValidity: getCustomValidity(isValid2, validity),
14818 label,
14819 help: description,
14820 value,
14821 onChange: onChangeControl,
14822 __next40pxDefaultSize: true,
14823 hideLabelFromVision,
14824 step,
14825 min: isValid2.min ? isValid2.min.constraint : void 0,
14826 max: isValid2.max ? isValid2.max.constraint : void 0
14827 }
14828 );
14829 }
14830
14831 // packages/dataviews/build-module/components/dataform-controls/integer.mjs
14832 var import_jsx_runtime82 = __toESM(require_jsx_runtime(), 1);
14833 function Integer(props) {
14834 return /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(ValidatedNumber, { ...props });
14835 }
14836
14837 // packages/dataviews/build-module/components/dataform-controls/number.mjs
14838 var import_jsx_runtime83 = __toESM(require_jsx_runtime(), 1);
14839 function Number2(props) {
14840 return /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(ValidatedNumber, { ...props });
14841 }
14842
14843 // packages/dataviews/build-module/components/dataform-controls/radio.mjs
14844 var import_components37 = __toESM(require_components(), 1);
14845 var import_element43 = __toESM(require_element(), 1);
14846 var import_jsx_runtime84 = __toESM(require_jsx_runtime(), 1);
14847 var { ValidatedRadioControl } = unlock(import_components37.privateApis);
14848 function Radio({
14849 data,
14850 field,
14851 onChange,
14852 hideLabelFromVision,
14853 validity
14854 }) {
14855 const { label, description, getValue, setValue, isValid: isValid2 } = field;
14856 const { elements, isLoading } = useElements({
14857 elements: field.elements,
14858 getElements: field.getElements
14859 });
14860 const value = getValue({ item: data });
14861 const onChangeControl = (0, import_element43.useCallback)(
14862 (newValue) => onChange(setValue({ item: data, value: newValue })),
14863 [data, onChange, setValue]
14864 );
14865 if (isLoading) {
14866 return /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(import_components37.Spinner, {});
14867 }
14868 return /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(
14869 ValidatedRadioControl,
14870 {
14871 required: !!field.isValid?.required,
14872 customValidity: getCustomValidity(isValid2, validity),
14873 label,
14874 help: description,
14875 onChange: onChangeControl,
14876 options: elements,
14877 selected: value,
14878 hideLabelFromVision
14879 }
14880 );
14881 }
14882
14883 // packages/dataviews/build-module/components/dataform-controls/select.mjs
14884 var import_components38 = __toESM(require_components(), 1);
14885 var import_element44 = __toESM(require_element(), 1);
14886 var import_jsx_runtime85 = __toESM(require_jsx_runtime(), 1);
14887 var { ValidatedSelectControl } = unlock(import_components38.privateApis);
14888 function Select({
14889 data,
14890 field,
14891 onChange,
14892 hideLabelFromVision,
14893 validity
14894 }) {
14895 const { type, label, description, getValue, setValue, isValid: isValid2 } = field;
14896 const isMultiple = type === "array";
14897 const value = getValue({ item: data }) ?? (isMultiple ? [] : "");
14898 const onChangeControl = (0, import_element44.useCallback)(
14899 (newValue) => onChange(setValue({ item: data, value: newValue })),
14900 [data, onChange, setValue]
14901 );
14902 const { elements, isLoading } = useElements({
14903 elements: field.elements,
14904 getElements: field.getElements
14905 });
14906 if (isLoading) {
14907 return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(import_components38.Spinner, {});
14908 }
14909 return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
14910 ValidatedSelectControl,
14911 {
14912 required: !!field.isValid?.required,
14913 customValidity: getCustomValidity(isValid2, validity),
14914 label,
14915 value,
14916 help: description,
14917 options: elements,
14918 onChange: onChangeControl,
14919 __next40pxDefaultSize: true,
14920 hideLabelFromVision,
14921 multiple: isMultiple
14922 }
14923 );
14924 }
14925
14926 // packages/dataviews/build-module/components/dataform-controls/text.mjs
14927 var import_element45 = __toESM(require_element(), 1);
14928 var import_jsx_runtime86 = __toESM(require_jsx_runtime(), 1);
14929 function Text2({
14930 data,
14931 field,
14932 onChange,
14933 hideLabelFromVision,
14934 config,
14935 validity
14936 }) {
14937 const { prefix, suffix } = config || {};
14938 return /* @__PURE__ */ (0, import_jsx_runtime86.jsx)(
14939 ValidatedText,
14940 {
14941 ...{
14942 data,
14943 field,
14944 onChange,
14945 hideLabelFromVision,
14946 validity,
14947 prefix: prefix ? (0, import_element45.createElement)(prefix) : void 0,
14948 suffix: suffix ? (0, import_element45.createElement)(suffix) : void 0
14949 }
14950 }
14951 );
14952 }
14953
14954 // packages/dataviews/build-module/components/dataform-controls/toggle.mjs
14955 var import_components39 = __toESM(require_components(), 1);
14956 var import_element46 = __toESM(require_element(), 1);
14957 var import_jsx_runtime87 = __toESM(require_jsx_runtime(), 1);
14958 var { ValidatedToggleControl } = unlock(import_components39.privateApis);
14959 function Toggle({
14960 field,
14961 onChange,
14962 data,
14963 hideLabelFromVision,
14964 validity
14965 }) {
14966 const { label, description, getValue, setValue, isValid: isValid2 } = field;
14967 const onChangeControl = (0, import_element46.useCallback)(() => {
14968 onChange(
14969 setValue({ item: data, value: !getValue({ item: data }) })
14970 );
14971 }, [onChange, setValue, data, getValue]);
14972 return /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(
14973 ValidatedToggleControl,
14974 {
14975 required: !!isValid2.required,
14976 customValidity: getCustomValidity(isValid2, validity),
14977 hidden: hideLabelFromVision,
14978 label,
14979 help: description,
14980 checked: getValue({ item: data }),
14981 onChange: onChangeControl
14982 }
14983 );
14984 }
14985
14986 // packages/dataviews/build-module/components/dataform-controls/textarea.mjs
14987 var import_components40 = __toESM(require_components(), 1);
14988 var import_element47 = __toESM(require_element(), 1);
14989 var import_jsx_runtime88 = __toESM(require_jsx_runtime(), 1);
14990 var { ValidatedTextareaControl } = unlock(import_components40.privateApis);
14991 function Textarea({
14992 data,
14993 field,
14994 onChange,
14995 hideLabelFromVision,
14996 config,
14997 validity
14998 }) {
14999 const { rows = 4 } = config || {};
15000 const { label, placeholder, description, setValue, isValid: isValid2 } = field;
15001 const value = field.getValue({ item: data });
15002 const onChangeControl = (0, import_element47.useCallback)(
15003 (newValue) => onChange(setValue({ item: data, value: newValue })),
15004 [data, onChange, setValue]
15005 );
15006 return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(
15007 ValidatedTextareaControl,
15008 {
15009 required: !!isValid2.required,
15010 customValidity: getCustomValidity(isValid2, validity),
15011 label,
15012 placeholder,
15013 value: value ?? "",
15014 help: description,
15015 onChange: onChangeControl,
15016 rows,
15017 minLength: isValid2.minLength ? isValid2.minLength.constraint : void 0,
15018 maxLength: isValid2.maxLength ? isValid2.maxLength.constraint : void 0,
15019 __next40pxDefaultSize: true,
15020 hideLabelFromVision
15021 }
15022 );
15023 }
15024
15025 // packages/dataviews/build-module/components/dataform-controls/toggle-group.mjs
15026 var import_components41 = __toESM(require_components(), 1);
15027 var import_element48 = __toESM(require_element(), 1);
15028 var import_jsx_runtime89 = __toESM(require_jsx_runtime(), 1);
15029 var { ValidatedToggleGroupControl } = unlock(import_components41.privateApis);
15030 function ToggleGroup({
15031 data,
15032 field,
15033 onChange,
15034 hideLabelFromVision,
15035 validity
15036 }) {
15037 const { getValue, setValue, isValid: isValid2 } = field;
15038 const value = getValue({ item: data });
15039 const onChangeControl = (0, import_element48.useCallback)(
15040 (newValue) => onChange(setValue({ item: data, value: newValue })),
15041 [data, onChange, setValue]
15042 );
15043 const { elements, isLoading } = useElements({
15044 elements: field.elements,
15045 getElements: field.getElements
15046 });
15047 if (isLoading) {
15048 return /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(import_components41.Spinner, {});
15049 }
15050 if (elements.length === 0) {
15051 return null;
15052 }
15053 const selectedOption = elements.find((el) => el.value === value);
15054 return /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(
15055 ValidatedToggleGroupControl,
15056 {
15057 required: !!field.isValid?.required,
15058 customValidity: getCustomValidity(isValid2, validity),
15059 __next40pxDefaultSize: true,
15060 isBlock: true,
15061 label: field.label,
15062 help: selectedOption?.description || field.description,
15063 onChange: onChangeControl,
15064 value,
15065 hideLabelFromVision,
15066 children: elements.map((el) => /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(
15067 import_components41.__experimentalToggleGroupControlOption,
15068 {
15069 label: el.label,
15070 value: el.value
15071 },
15072 el.value
15073 ))
15074 }
15075 );
15076 }
15077
15078 // packages/dataviews/build-module/components/dataform-controls/array.mjs
15079 var import_components42 = __toESM(require_components(), 1);
15080 var import_element49 = __toESM(require_element(), 1);
15081 var import_jsx_runtime90 = __toESM(require_jsx_runtime(), 1);
15082 var { ValidatedFormTokenField } = unlock(import_components42.privateApis);
15083 function ArrayControl({
15084 data,
15085 field,
15086 onChange,
15087 hideLabelFromVision,
15088 validity
15089 }) {
15090 const { label, placeholder, getValue, setValue, isValid: isValid2 } = field;
15091 const value = getValue({ item: data });
15092 const { elements, isLoading } = useElements({
15093 elements: field.elements,
15094 getElements: field.getElements
15095 });
15096 const arrayValueAsElements = (0, import_element49.useMemo)(
15097 () => Array.isArray(value) ? value.map((token) => {
15098 const element = elements?.find(
15099 (suggestion) => suggestion.value === token
15100 );
15101 return element || { value: token, label: token };
15102 }) : [],
15103 [value, elements]
15104 );
15105 const onChangeControl = (0, import_element49.useCallback)(
15106 (tokens) => {
15107 const valueTokens = tokens.map((token) => {
15108 if (typeof token === "object" && "value" in token) {
15109 return token.value;
15110 }
15111 return token;
15112 });
15113 onChange(setValue({ item: data, value: valueTokens }));
15114 },
15115 [onChange, setValue, data]
15116 );
15117 if (isLoading) {
15118 return /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(import_components42.Spinner, {});
15119 }
15120 return /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(
15121 ValidatedFormTokenField,
15122 {
15123 required: !!isValid2?.required,
15124 customValidity: getCustomValidity(isValid2, validity),
15125 label: hideLabelFromVision ? void 0 : label,
15126 value: arrayValueAsElements,
15127 onChange: onChangeControl,
15128 placeholder,
15129 suggestions: elements?.map((element) => element.value),
15130 __experimentalValidateInput: (token) => {
15131 if (field.isValid?.elements && elements) {
15132 return elements.some(
15133 (element) => element.value === token || element.label === token
15134 );
15135 }
15136 return true;
15137 },
15138 __experimentalExpandOnFocus: elements && elements.length > 0,
15139 __experimentalShowHowTo: !field.isValid?.elements,
15140 displayTransform: (token) => {
15141 if (typeof token === "object" && "label" in token) {
15142 return token.label;
15143 }
15144 if (typeof token === "string" && elements) {
15145 const element = elements.find(
15146 (el) => el.value === token
15147 );
15148 return element?.label || token;
15149 }
15150 return token;
15151 },
15152 __experimentalRenderItem: ({ item }) => {
15153 if (typeof item === "string" && elements) {
15154 const element = elements.find(
15155 (el) => el.value === item
15156 );
15157 return /* @__PURE__ */ (0, import_jsx_runtime90.jsx)("span", { children: element?.label || item });
15158 }
15159 return /* @__PURE__ */ (0, import_jsx_runtime90.jsx)("span", { children: item });
15160 }
15161 }
15162 );
15163 }
15164
15165 // node_modules/colord/index.mjs
15166 var r2 = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) };
15167 var t = function(r3) {
15168 return "string" == typeof r3 ? r3.length > 0 : "number" == typeof r3;
15169 };
15170 var n = function(r3, t2, n2) {
15171 return void 0 === t2 && (t2 = 0), void 0 === n2 && (n2 = Math.pow(10, t2)), Math.round(n2 * r3) / n2 + 0;
15172 };
15173 var e = function(r3, t2, n2) {
15174 return void 0 === t2 && (t2 = 0), void 0 === n2 && (n2 = 1), r3 > n2 ? n2 : r3 > t2 ? r3 : t2;
15175 };
15176 var u = function(r3) {
15177 return (r3 = isFinite(r3) ? r3 % 360 : 0) > 0 ? r3 : r3 + 360;
15178 };
15179 var a = function(r3) {
15180 return { r: e(r3.r, 0, 255), g: e(r3.g, 0, 255), b: e(r3.b, 0, 255), a: e(r3.a) };
15181 };
15182 var o = function(r3) {
15183 return { r: n(r3.r), g: n(r3.g), b: n(r3.b), a: n(r3.a, 3) };
15184 };
15185 var i = /^#([0-9a-f]{3,8})$/i;
15186 var s = function(r3) {
15187 var t2 = r3.toString(16);
15188 return t2.length < 2 ? "0" + t2 : t2;
15189 };
15190 var h = function(r3) {
15191 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;
15192 return { h: 60 * (i2 < 0 ? i2 + 6 : i2), s: a2 ? o2 / a2 * 100 : 0, v: a2 / 255 * 100, a: u2 };
15193 };
15194 var b = function(r3) {
15195 var t2 = r3.h, n2 = r3.s, e2 = r3.v, u2 = r3.a;
15196 t2 = t2 / 360 * 6, n2 /= 100, e2 /= 100;
15197 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;
15198 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 };
15199 };
15200 var g = function(r3) {
15201 return { h: u(r3.h), s: e(r3.s, 0, 100), l: e(r3.l, 0, 100), a: e(r3.a) };
15202 };
15203 var d = function(r3) {
15204 return { h: n(r3.h), s: n(r3.s), l: n(r3.l), a: n(r3.a, 3) };
15205 };
15206 var f = function(r3) {
15207 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 }));
15208 var t2, n2, e2;
15209 };
15210 var c = function(r3) {
15211 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 };
15212 var t2, n2, e2, u2;
15213 };
15214 var l = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15215 var p = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15216 var v = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15217 var m = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i;
15218 var y = { string: [[function(r3) {
15219 var t2 = i.exec(r3);
15220 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;
15221 }, "hex"], [function(r3) {
15222 var t2 = v.exec(r3) || m.exec(r3);
15223 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;
15224 }, "rgb"], [function(t2) {
15225 var n2 = l.exec(t2) || p.exec(t2);
15226 if (!n2) return null;
15227 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) });
15228 return f(a2);
15229 }, "hsl"]], object: [[function(r3) {
15230 var n2 = r3.r, e2 = r3.g, u2 = r3.b, o2 = r3.a, i2 = void 0 === o2 ? 1 : o2;
15231 return t(n2) && t(e2) && t(u2) ? a({ r: Number(n2), g: Number(e2), b: Number(u2), a: Number(i2) }) : null;
15232 }, "rgb"], [function(r3) {
15233 var n2 = r3.h, e2 = r3.s, u2 = r3.l, a2 = r3.a, o2 = void 0 === a2 ? 1 : a2;
15234 if (!t(n2) || !t(e2) || !t(u2)) return null;
15235 var i2 = g({ h: Number(n2), s: Number(e2), l: Number(u2), a: Number(o2) });
15236 return f(i2);
15237 }, "hsl"], [function(r3) {
15238 var n2 = r3.h, a2 = r3.s, o2 = r3.v, i2 = r3.a, s2 = void 0 === i2 ? 1 : i2;
15239 if (!t(n2) || !t(a2) || !t(o2)) return null;
15240 var h2 = (function(r4) {
15241 return { h: u(r4.h), s: e(r4.s, 0, 100), v: e(r4.v, 0, 100), a: e(r4.a) };
15242 })({ h: Number(n2), s: Number(a2), v: Number(o2), a: Number(s2) });
15243 return b(h2);
15244 }, "hsv"]] };
15245 var N = function(r3, t2) {
15246 for (var n2 = 0; n2 < t2.length; n2++) {
15247 var e2 = t2[n2][0](r3);
15248 if (e2) return [e2, t2[n2][1]];
15249 }
15250 return [null, void 0];
15251 };
15252 var x = function(r3) {
15253 return "string" == typeof r3 ? N(r3.trim(), y.string) : "object" == typeof r3 && null !== r3 ? N(r3, y.object) : [null, void 0];
15254 };
15255 var M = function(r3, t2) {
15256 var n2 = c(r3);
15257 return { h: n2.h, s: e(n2.s + 100 * t2, 0, 100), l: n2.l, a: n2.a };
15258 };
15259 var H = function(r3) {
15260 return (299 * r3.r + 587 * r3.g + 114 * r3.b) / 1e3 / 255;
15261 };
15262 var $ = function(r3, t2) {
15263 var n2 = c(r3);
15264 return { h: n2.h, s: n2.s, l: e(n2.l + 100 * t2, 0, 100), a: n2.a };
15265 };
15266 var j = (function() {
15267 function r3(r4) {
15268 this.parsed = x(r4)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 };
15269 }
15270 return r3.prototype.isValid = function() {
15271 return null !== this.parsed;
15272 }, r3.prototype.brightness = function() {
15273 return n(H(this.rgba), 2);
15274 }, r3.prototype.isDark = function() {
15275 return H(this.rgba) < 0.5;
15276 }, r3.prototype.isLight = function() {
15277 return H(this.rgba) >= 0.5;
15278 }, r3.prototype.toHex = function() {
15279 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;
15280 var r4, t2, e2, u2, a2, i2;
15281 }, r3.prototype.toRgb = function() {
15282 return o(this.rgba);
15283 }, r3.prototype.toRgbString = function() {
15284 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 + ")";
15285 var r4, t2, n2, e2, u2;
15286 }, r3.prototype.toHsl = function() {
15287 return d(c(this.rgba));
15288 }, r3.prototype.toHslString = function() {
15289 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 + "%)";
15290 var r4, t2, n2, e2, u2;
15291 }, r3.prototype.toHsv = function() {
15292 return r4 = h(this.rgba), { h: n(r4.h), s: n(r4.s), v: n(r4.v), a: n(r4.a, 3) };
15293 var r4;
15294 }, r3.prototype.invert = function() {
15295 return w({ r: 255 - (r4 = this.rgba).r, g: 255 - r4.g, b: 255 - r4.b, a: r4.a });
15296 var r4;
15297 }, r3.prototype.saturate = function(r4) {
15298 return void 0 === r4 && (r4 = 0.1), w(M(this.rgba, r4));
15299 }, r3.prototype.desaturate = function(r4) {
15300 return void 0 === r4 && (r4 = 0.1), w(M(this.rgba, -r4));
15301 }, r3.prototype.grayscale = function() {
15302 return w(M(this.rgba, -1));
15303 }, r3.prototype.lighten = function(r4) {
15304 return void 0 === r4 && (r4 = 0.1), w($(this.rgba, r4));
15305 }, r3.prototype.darken = function(r4) {
15306 return void 0 === r4 && (r4 = 0.1), w($(this.rgba, -r4));
15307 }, r3.prototype.rotate = function(r4) {
15308 return void 0 === r4 && (r4 = 15), this.hue(this.hue() + r4);
15309 }, r3.prototype.alpha = function(r4) {
15310 return "number" == typeof r4 ? w({ r: (t2 = this.rgba).r, g: t2.g, b: t2.b, a: r4 }) : n(this.rgba.a, 3);
15311 var t2;
15312 }, r3.prototype.hue = function(r4) {
15313 var t2 = c(this.rgba);
15314 return "number" == typeof r4 ? w({ h: r4, s: t2.s, l: t2.l, a: t2.a }) : n(t2.h);
15315 }, r3.prototype.isEqual = function(r4) {
15316 return this.toHex() === w(r4).toHex();
15317 }, r3;
15318 })();
15319 var w = function(r3) {
15320 return r3 instanceof j ? r3 : new j(r3);
15321 };
15322
15323 // packages/dataviews/build-module/components/dataform-controls/color.mjs
15324 var import_components43 = __toESM(require_components(), 1);
15325 var import_element50 = __toESM(require_element(), 1);
15326 var import_jsx_runtime91 = __toESM(require_jsx_runtime(), 1);
15327 var { ValidatedInputControl: ValidatedInputControl3, Picker } = unlock(import_components43.privateApis);
15328 var ColorPicker = ({
15329 color,
15330 onColorChange
15331 }) => {
15332 const validColor = color && w(color).isValid() ? color : "#ffffff";
15333 return /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
15334 import_components43.Dropdown,
15335 {
15336 renderToggle: ({ onToggle, isOpen }) => /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(import_components43.__experimentalInputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
15337 "button",
15338 {
15339 type: "button",
15340 onClick: onToggle,
15341 style: {
15342 width: "24px",
15343 height: "24px",
15344 borderRadius: "50%",
15345 backgroundColor: validColor,
15346 border: "1px solid #ddd",
15347 cursor: "pointer",
15348 outline: isOpen ? "2px solid #007cba" : "none",
15349 outlineOffset: "2px",
15350 display: "flex",
15351 alignItems: "center",
15352 justifyContent: "center",
15353 padding: 0,
15354 margin: 0
15355 },
15356 "aria-label": "Open color picker"
15357 }
15358 ) }),
15359 renderContent: () => /* @__PURE__ */ (0, import_jsx_runtime91.jsx)("div", { style: { padding: "16px" }, children: /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
15360 Picker,
15361 {
15362 color: w(validColor),
15363 onChange: onColorChange,
15364 enableAlpha: true
15365 }
15366 ) })
15367 }
15368 );
15369 };
15370 function Color({
15371 data,
15372 field,
15373 onChange,
15374 hideLabelFromVision,
15375 validity
15376 }) {
15377 const { label, placeholder, description, setValue, isValid: isValid2 } = field;
15378 const value = field.getValue({ item: data }) || "";
15379 const handleColorChange = (0, import_element50.useCallback)(
15380 (colorObject) => {
15381 onChange(setValue({ item: data, value: colorObject.toHex() }));
15382 },
15383 [data, onChange, setValue]
15384 );
15385 const handleInputChange = (0, import_element50.useCallback)(
15386 (newValue) => {
15387 onChange(setValue({ item: data, value: newValue || "" }));
15388 },
15389 [data, onChange, setValue]
15390 );
15391 return /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
15392 ValidatedInputControl3,
15393 {
15394 required: !!field.isValid?.required,
15395 customValidity: getCustomValidity(isValid2, validity),
15396 label,
15397 placeholder,
15398 value,
15399 help: description,
15400 onChange: handleInputChange,
15401 hideLabelFromVision,
15402 type: "text",
15403 prefix: /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
15404 ColorPicker,
15405 {
15406 color: value,
15407 onColorChange: handleColorChange
15408 }
15409 )
15410 }
15411 );
15412 }
15413
15414 // packages/dataviews/build-module/components/dataform-controls/password.mjs
15415 var import_components44 = __toESM(require_components(), 1);
15416 var import_element51 = __toESM(require_element(), 1);
15417 var import_i18n41 = __toESM(require_i18n(), 1);
15418 var import_jsx_runtime92 = __toESM(require_jsx_runtime(), 1);
15419 function Password({
15420 data,
15421 field,
15422 onChange,
15423 hideLabelFromVision,
15424 validity
15425 }) {
15426 const [isVisible2, setIsVisible] = (0, import_element51.useState)(false);
15427 const toggleVisibility = (0, import_element51.useCallback)(() => {
15428 setIsVisible((prev) => !prev);
15429 }, []);
15430 return /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
15431 ValidatedText,
15432 {
15433 ...{
15434 data,
15435 field,
15436 onChange,
15437 hideLabelFromVision,
15438 validity,
15439 type: isVisible2 ? "text" : "password",
15440 suffix: /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(import_components44.__experimentalInputControlSuffixWrapper, { variant: "control", children: /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
15441 import_components44.Button,
15442 {
15443 icon: isVisible2 ? unseen_default : seen_default,
15444 onClick: toggleVisibility,
15445 size: "small",
15446 label: isVisible2 ? (0, import_i18n41.__)("Hide password") : (0, import_i18n41.__)("Show password")
15447 }
15448 ) })
15449 }
15450 }
15451 );
15452 }
15453
15454 // packages/dataviews/build-module/field-types/utils/has-elements.mjs
15455 function hasElements(field) {
15456 return Array.isArray(field.elements) && field.elements.length > 0 || typeof field.getElements === "function";
15457 }
15458
15459 // packages/dataviews/build-module/components/dataform-controls/index.mjs
15460 var import_jsx_runtime93 = __toESM(require_jsx_runtime(), 1);
15461 var FORM_CONTROLS = {
15462 array: ArrayControl,
15463 checkbox: Checkbox,
15464 color: Color,
15465 datetime: DateTime,
15466 date: DateControl,
15467 email: Email,
15468 telephone: Telephone,
15469 url: Url,
15470 integer: Integer,
15471 number: Number2,
15472 password: Password,
15473 radio: Radio,
15474 select: Select,
15475 text: Text2,
15476 toggle: Toggle,
15477 textarea: Textarea,
15478 toggleGroup: ToggleGroup
15479 };
15480 function isEditConfig(value) {
15481 return value && typeof value === "object" && typeof value.control === "string";
15482 }
15483 function createConfiguredControl(config) {
15484 const { control, ...controlConfig } = config;
15485 const BaseControlType = getControlByType(control);
15486 if (BaseControlType === null) {
15487 return null;
15488 }
15489 return function ConfiguredControl(props) {
15490 return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(BaseControlType, { ...props, config: controlConfig });
15491 };
15492 }
15493 function getControl(field, fallback) {
15494 if (typeof field.Edit === "function") {
15495 return field.Edit;
15496 }
15497 if (typeof field.Edit === "string") {
15498 return getControlByType(field.Edit);
15499 }
15500 if (isEditConfig(field.Edit)) {
15501 return createConfiguredControl(field.Edit);
15502 }
15503 if (hasElements(field) && field.type !== "array") {
15504 return getControlByType("select");
15505 }
15506 if (fallback === null) {
15507 return null;
15508 }
15509 return getControlByType(fallback);
15510 }
15511 function getControlByType(type) {
15512 if (Object.keys(FORM_CONTROLS).includes(type)) {
15513 return FORM_CONTROLS[type];
15514 }
15515 return null;
15516 }
15517
15518 // packages/dataviews/build-module/field-types/utils/get-filter-by.mjs
15519 function getFilterBy(field, defaultOperators, validOperators) {
15520 if (field.filterBy === false) {
15521 return false;
15522 }
15523 const operators = field.filterBy?.operators?.filter(
15524 (op) => validOperators.includes(op)
15525 ) ?? defaultOperators;
15526 if (operators.length === 0) {
15527 return false;
15528 }
15529 return {
15530 isPrimary: !!field.filterBy?.isPrimary,
15531 operators
15532 };
15533 }
15534 var get_filter_by_default = getFilterBy;
15535
15536 // packages/dataviews/build-module/field-types/utils/get-value-from-id.mjs
15537 var getValueFromId = (id) => ({ item }) => {
15538 const path = id.split(".");
15539 let value = item;
15540 for (const segment of path) {
15541 if (value.hasOwnProperty(segment)) {
15542 value = value[segment];
15543 } else {
15544 value = void 0;
15545 }
15546 }
15547 return value;
15548 };
15549 var get_value_from_id_default = getValueFromId;
15550
15551 // packages/dataviews/build-module/field-types/utils/set-value-from-id.mjs
15552 var setValueFromId = (id) => ({ value }) => {
15553 const path = id.split(".");
15554 const result = {};
15555 let current = result;
15556 for (const segment of path.slice(0, -1)) {
15557 current[segment] = {};
15558 current = current[segment];
15559 }
15560 current[path.at(-1)] = value;
15561 return result;
15562 };
15563 var set_value_from_id_default = setValueFromId;
15564
15565 // packages/dataviews/build-module/field-types/email.mjs
15566 var import_i18n42 = __toESM(require_i18n(), 1);
15567
15568 // packages/dataviews/build-module/field-types/utils/render-from-elements.mjs
15569 function RenderFromElements({
15570 item,
15571 field
15572 }) {
15573 const { elements, isLoading } = useElements({
15574 elements: field.elements,
15575 getElements: field.getElements
15576 });
15577 const value = field.getValue({ item });
15578 if (isLoading) {
15579 return value;
15580 }
15581 if (elements.length === 0) {
15582 return value;
15583 }
15584 return elements?.find((element) => element.value === value)?.label || field.getValue({ item });
15585 }
15586
15587 // packages/dataviews/build-module/field-types/utils/render-default.mjs
15588 var import_jsx_runtime94 = __toESM(require_jsx_runtime(), 1);
15589 function render({
15590 item,
15591 field
15592 }) {
15593 if (field.hasElements) {
15594 return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(RenderFromElements, { item, field });
15595 }
15596 return field.getValueFormatted({ item, field });
15597 }
15598
15599 // packages/dataviews/build-module/field-types/utils/sort-text.mjs
15600 var sort_text_default = (a2, b2, direction) => {
15601 return direction === "asc" ? a2.localeCompare(b2) : b2.localeCompare(a2);
15602 };
15603
15604 // packages/dataviews/build-module/field-types/utils/is-valid-required.mjs
15605 function isValidRequired(item, field) {
15606 const value = field.getValue({ item });
15607 return ![void 0, "", null].includes(value);
15608 }
15609
15610 // packages/dataviews/build-module/field-types/utils/is-valid-min-length.mjs
15611 function isValidMinLength(item, field) {
15612 if (typeof field.isValid.minLength?.constraint !== "number") {
15613 return false;
15614 }
15615 const value = field.getValue({ item });
15616 if ([void 0, "", null].includes(value)) {
15617 return true;
15618 }
15619 return String(value).length >= field.isValid.minLength.constraint;
15620 }
15621
15622 // packages/dataviews/build-module/field-types/utils/is-valid-max-length.mjs
15623 function isValidMaxLength(item, field) {
15624 if (typeof field.isValid.maxLength?.constraint !== "number") {
15625 return false;
15626 }
15627 const value = field.getValue({ item });
15628 if ([void 0, "", null].includes(value)) {
15629 return true;
15630 }
15631 return String(value).length <= field.isValid.maxLength.constraint;
15632 }
15633
15634 // packages/dataviews/build-module/field-types/utils/is-valid-pattern.mjs
15635 function isValidPattern(item, field) {
15636 if (field.isValid.pattern?.constraint === void 0) {
15637 return true;
15638 }
15639 try {
15640 const regexp = new RegExp(field.isValid.pattern.constraint);
15641 const value = field.getValue({ item });
15642 if ([void 0, "", null].includes(value)) {
15643 return true;
15644 }
15645 return regexp.test(String(value));
15646 } catch {
15647 return false;
15648 }
15649 }
15650
15651 // packages/dataviews/build-module/field-types/utils/is-valid-elements.mjs
15652 function isValidElements(item, field) {
15653 const elements = field.elements ?? [];
15654 const validValues = elements.map((el) => el.value);
15655 if (validValues.length === 0) {
15656 return true;
15657 }
15658 const value = field.getValue({ item });
15659 return [].concat(value).every((v2) => validValues.includes(v2));
15660 }
15661
15662 // packages/dataviews/build-module/field-types/utils/get-value-formatted-default.mjs
15663 function getValueFormatted({
15664 item,
15665 field
15666 }) {
15667 return field.getValue({ item });
15668 }
15669 var get_value_formatted_default_default = getValueFormatted;
15670
15671 // packages/dataviews/build-module/field-types/email.mjs
15672 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])?)*$/;
15673 function isValidCustom(item, field) {
15674 const value = field.getValue({ item });
15675 if (![void 0, "", null].includes(value) && !emailRegex.test(value)) {
15676 return (0, import_i18n42.__)("Value must be a valid email address.");
15677 }
15678 return null;
15679 }
15680 var email_default = {
15681 type: "email",
15682 render,
15683 Edit: "email",
15684 sort: sort_text_default,
15685 enableSorting: true,
15686 enableGlobalSearch: false,
15687 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
15688 validOperators: [
15689 OPERATOR_IS,
15690 OPERATOR_IS_NOT,
15691 OPERATOR_CONTAINS,
15692 OPERATOR_NOT_CONTAINS,
15693 OPERATOR_STARTS_WITH,
15694 // Multiple selection
15695 OPERATOR_IS_ANY,
15696 OPERATOR_IS_NONE,
15697 OPERATOR_IS_ALL,
15698 OPERATOR_IS_NOT_ALL
15699 ],
15700 format: {},
15701 getValueFormatted: get_value_formatted_default_default,
15702 validate: {
15703 required: isValidRequired,
15704 pattern: isValidPattern,
15705 minLength: isValidMinLength,
15706 maxLength: isValidMaxLength,
15707 elements: isValidElements,
15708 custom: isValidCustom
15709 }
15710 };
15711
15712 // packages/dataviews/build-module/field-types/integer.mjs
15713 var import_i18n43 = __toESM(require_i18n(), 1);
15714
15715 // packages/dataviews/build-module/field-types/utils/sort-number.mjs
15716 var sort_number_default = (a2, b2, direction) => {
15717 return direction === "asc" ? a2 - b2 : b2 - a2;
15718 };
15719
15720 // packages/dataviews/build-module/field-types/utils/is-valid-min.mjs
15721 function isValidMin(item, field) {
15722 if (typeof field.isValid.min?.constraint !== "number") {
15723 return false;
15724 }
15725 const value = field.getValue({ item });
15726 if ([void 0, "", null].includes(value)) {
15727 return true;
15728 }
15729 return Number(value) >= field.isValid.min.constraint;
15730 }
15731
15732 // packages/dataviews/build-module/field-types/utils/is-valid-max.mjs
15733 function isValidMax(item, field) {
15734 if (typeof field.isValid.max?.constraint !== "number") {
15735 return false;
15736 }
15737 const value = field.getValue({ item });
15738 if ([void 0, "", null].includes(value)) {
15739 return true;
15740 }
15741 return Number(value) <= field.isValid.max.constraint;
15742 }
15743
15744 // packages/dataviews/build-module/field-types/integer.mjs
15745 var format2 = {
15746 separatorThousand: ","
15747 };
15748 function getValueFormatted2({
15749 item,
15750 field
15751 }) {
15752 let value = field.getValue({ item });
15753 if (value === null || value === void 0) {
15754 return "";
15755 }
15756 value = Number(value);
15757 if (!Number.isFinite(value)) {
15758 return String(value);
15759 }
15760 let formatInteger;
15761 if (field.type !== "integer") {
15762 formatInteger = format2;
15763 } else {
15764 formatInteger = field.format;
15765 }
15766 const { separatorThousand } = formatInteger;
15767 const integerValue = Math.trunc(value);
15768 if (!separatorThousand) {
15769 return String(integerValue);
15770 }
15771 return String(integerValue).replace(
15772 /\B(?=(\d{3})+(?!\d))/g,
15773 separatorThousand
15774 );
15775 }
15776 function isValidCustom2(item, field) {
15777 const value = field.getValue({ item });
15778 if (![void 0, "", null].includes(value) && !Number.isInteger(value)) {
15779 return (0, import_i18n43.__)("Value must be an integer.");
15780 }
15781 return null;
15782 }
15783 var integer_default = {
15784 type: "integer",
15785 render,
15786 Edit: "integer",
15787 sort: sort_number_default,
15788 enableSorting: true,
15789 enableGlobalSearch: false,
15790 defaultOperators: [
15791 OPERATOR_IS,
15792 OPERATOR_IS_NOT,
15793 OPERATOR_LESS_THAN,
15794 OPERATOR_GREATER_THAN,
15795 OPERATOR_LESS_THAN_OR_EQUAL,
15796 OPERATOR_GREATER_THAN_OR_EQUAL,
15797 OPERATOR_BETWEEN
15798 ],
15799 validOperators: [
15800 // Single-selection
15801 OPERATOR_IS,
15802 OPERATOR_IS_NOT,
15803 OPERATOR_LESS_THAN,
15804 OPERATOR_GREATER_THAN,
15805 OPERATOR_LESS_THAN_OR_EQUAL,
15806 OPERATOR_GREATER_THAN_OR_EQUAL,
15807 OPERATOR_BETWEEN,
15808 // Multiple-selection
15809 OPERATOR_IS_ANY,
15810 OPERATOR_IS_NONE,
15811 OPERATOR_IS_ALL,
15812 OPERATOR_IS_NOT_ALL
15813 ],
15814 format: format2,
15815 getValueFormatted: getValueFormatted2,
15816 validate: {
15817 required: isValidRequired,
15818 min: isValidMin,
15819 max: isValidMax,
15820 elements: isValidElements,
15821 custom: isValidCustom2
15822 }
15823 };
15824
15825 // packages/dataviews/build-module/field-types/number.mjs
15826 var import_i18n44 = __toESM(require_i18n(), 1);
15827 var format3 = {
15828 separatorThousand: ",",
15829 separatorDecimal: ".",
15830 decimals: 2
15831 };
15832 function getValueFormatted3({
15833 item,
15834 field
15835 }) {
15836 let value = field.getValue({ item });
15837 if (value === null || value === void 0) {
15838 return "";
15839 }
15840 value = Number(value);
15841 if (!Number.isFinite(value)) {
15842 return String(value);
15843 }
15844 let formatNumber;
15845 if (field.type !== "number") {
15846 formatNumber = format3;
15847 } else {
15848 formatNumber = field.format;
15849 }
15850 const { separatorThousand, separatorDecimal, decimals } = formatNumber;
15851 const fixedValue = value.toFixed(decimals);
15852 const [integerPart, decimalPart] = fixedValue.split(".");
15853 const formattedInteger = separatorThousand ? integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, separatorThousand) : integerPart;
15854 return decimals === 0 ? formattedInteger : formattedInteger + separatorDecimal + decimalPart;
15855 }
15856 function isEmpty2(value) {
15857 return value === "" || value === void 0 || value === null;
15858 }
15859 function isValidCustom3(item, field) {
15860 const value = field.getValue({ item });
15861 if (!isEmpty2(value) && !Number.isFinite(value)) {
15862 return (0, import_i18n44.__)("Value must be a number.");
15863 }
15864 return null;
15865 }
15866 var number_default = {
15867 type: "number",
15868 render,
15869 Edit: "number",
15870 sort: sort_number_default,
15871 enableSorting: true,
15872 enableGlobalSearch: false,
15873 defaultOperators: [
15874 OPERATOR_IS,
15875 OPERATOR_IS_NOT,
15876 OPERATOR_LESS_THAN,
15877 OPERATOR_GREATER_THAN,
15878 OPERATOR_LESS_THAN_OR_EQUAL,
15879 OPERATOR_GREATER_THAN_OR_EQUAL,
15880 OPERATOR_BETWEEN
15881 ],
15882 validOperators: [
15883 // Single-selection
15884 OPERATOR_IS,
15885 OPERATOR_IS_NOT,
15886 OPERATOR_LESS_THAN,
15887 OPERATOR_GREATER_THAN,
15888 OPERATOR_LESS_THAN_OR_EQUAL,
15889 OPERATOR_GREATER_THAN_OR_EQUAL,
15890 OPERATOR_BETWEEN,
15891 // Multiple-selection
15892 OPERATOR_IS_ANY,
15893 OPERATOR_IS_NONE,
15894 OPERATOR_IS_ALL,
15895 OPERATOR_IS_NOT_ALL
15896 ],
15897 format: format3,
15898 getValueFormatted: getValueFormatted3,
15899 validate: {
15900 required: isValidRequired,
15901 min: isValidMin,
15902 max: isValidMax,
15903 elements: isValidElements,
15904 custom: isValidCustom3
15905 }
15906 };
15907
15908 // packages/dataviews/build-module/field-types/text.mjs
15909 var text_default = {
15910 type: "text",
15911 render,
15912 Edit: "text",
15913 sort: sort_text_default,
15914 enableSorting: true,
15915 enableGlobalSearch: false,
15916 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
15917 validOperators: [
15918 // Single selection
15919 OPERATOR_IS,
15920 OPERATOR_IS_NOT,
15921 OPERATOR_CONTAINS,
15922 OPERATOR_NOT_CONTAINS,
15923 OPERATOR_STARTS_WITH,
15924 // Multiple selection
15925 OPERATOR_IS_ANY,
15926 OPERATOR_IS_NONE,
15927 OPERATOR_IS_ALL,
15928 OPERATOR_IS_NOT_ALL
15929 ],
15930 format: {},
15931 getValueFormatted: get_value_formatted_default_default,
15932 validate: {
15933 required: isValidRequired,
15934 pattern: isValidPattern,
15935 minLength: isValidMinLength,
15936 maxLength: isValidMaxLength,
15937 elements: isValidElements
15938 }
15939 };
15940
15941 // packages/dataviews/build-module/field-types/datetime.mjs
15942 var import_date5 = __toESM(require_date(), 1);
15943 var format4 = {
15944 datetime: (0, import_date5.getSettings)().formats.datetime,
15945 weekStartsOn: (0, import_date5.getSettings)().l10n.startOfWeek
15946 };
15947 function getValueFormatted4({
15948 item,
15949 field
15950 }) {
15951 const value = field.getValue({ item });
15952 if (["", void 0, null].includes(value)) {
15953 return "";
15954 }
15955 let formatDatetime;
15956 if (field.type !== "datetime") {
15957 formatDatetime = format4;
15958 } else {
15959 formatDatetime = field.format;
15960 }
15961 return (0, import_date5.dateI18n)(formatDatetime.datetime, (0, import_date5.getDate)(value));
15962 }
15963 var sort = (a2, b2, direction) => {
15964 const timeA = new Date(a2).getTime();
15965 const timeB = new Date(b2).getTime();
15966 return direction === "asc" ? timeA - timeB : timeB - timeA;
15967 };
15968 var datetime_default = {
15969 type: "datetime",
15970 render,
15971 Edit: "datetime",
15972 sort,
15973 enableSorting: true,
15974 enableGlobalSearch: false,
15975 defaultOperators: [
15976 OPERATOR_ON,
15977 OPERATOR_NOT_ON,
15978 OPERATOR_BEFORE,
15979 OPERATOR_AFTER,
15980 OPERATOR_BEFORE_INC,
15981 OPERATOR_AFTER_INC,
15982 OPERATOR_IN_THE_PAST,
15983 OPERATOR_OVER
15984 ],
15985 validOperators: [
15986 OPERATOR_ON,
15987 OPERATOR_NOT_ON,
15988 OPERATOR_BEFORE,
15989 OPERATOR_AFTER,
15990 OPERATOR_BEFORE_INC,
15991 OPERATOR_AFTER_INC,
15992 OPERATOR_IN_THE_PAST,
15993 OPERATOR_OVER
15994 ],
15995 format: format4,
15996 getValueFormatted: getValueFormatted4,
15997 validate: {
15998 required: isValidRequired,
15999 elements: isValidElements
16000 }
16001 };
16002
16003 // packages/dataviews/build-module/field-types/date.mjs
16004 var import_date6 = __toESM(require_date(), 1);
16005 var format5 = {
16006 date: (0, import_date6.getSettings)().formats.date,
16007 weekStartsOn: (0, import_date6.getSettings)().l10n.startOfWeek
16008 };
16009 function getValueFormatted5({
16010 item,
16011 field
16012 }) {
16013 const value = field.getValue({ item });
16014 if (["", void 0, null].includes(value)) {
16015 return "";
16016 }
16017 let formatDate2;
16018 if (field.type !== "date") {
16019 formatDate2 = format5;
16020 } else {
16021 formatDate2 = field.format;
16022 }
16023 return (0, import_date6.dateI18n)(formatDate2.date, (0, import_date6.getDate)(value));
16024 }
16025 var sort2 = (a2, b2, direction) => {
16026 const timeA = new Date(a2).getTime();
16027 const timeB = new Date(b2).getTime();
16028 return direction === "asc" ? timeA - timeB : timeB - timeA;
16029 };
16030 var date_default = {
16031 type: "date",
16032 render,
16033 Edit: "date",
16034 sort: sort2,
16035 enableSorting: true,
16036 enableGlobalSearch: false,
16037 defaultOperators: [
16038 OPERATOR_ON,
16039 OPERATOR_NOT_ON,
16040 OPERATOR_BEFORE,
16041 OPERATOR_AFTER,
16042 OPERATOR_BEFORE_INC,
16043 OPERATOR_AFTER_INC,
16044 OPERATOR_IN_THE_PAST,
16045 OPERATOR_OVER,
16046 OPERATOR_BETWEEN
16047 ],
16048 validOperators: [
16049 OPERATOR_ON,
16050 OPERATOR_NOT_ON,
16051 OPERATOR_BEFORE,
16052 OPERATOR_AFTER,
16053 OPERATOR_BEFORE_INC,
16054 OPERATOR_AFTER_INC,
16055 OPERATOR_IN_THE_PAST,
16056 OPERATOR_OVER,
16057 OPERATOR_BETWEEN
16058 ],
16059 format: format5,
16060 getValueFormatted: getValueFormatted5,
16061 validate: {
16062 required: isValidRequired,
16063 elements: isValidElements
16064 }
16065 };
16066
16067 // packages/dataviews/build-module/field-types/boolean.mjs
16068 var import_i18n45 = __toESM(require_i18n(), 1);
16069
16070 // packages/dataviews/build-module/field-types/utils/is-valid-required-for-bool.mjs
16071 function isValidRequiredForBool(item, field) {
16072 const value = field.getValue({ item });
16073 return value === true;
16074 }
16075
16076 // packages/dataviews/build-module/field-types/boolean.mjs
16077 function getValueFormatted6({
16078 item,
16079 field
16080 }) {
16081 const value = field.getValue({ item });
16082 if (value === true) {
16083 return (0, import_i18n45.__)("True");
16084 }
16085 if (value === false) {
16086 return (0, import_i18n45.__)("False");
16087 }
16088 return "";
16089 }
16090 function isValidCustom4(item, field) {
16091 const value = field.getValue({ item });
16092 if (![void 0, "", null].includes(value) && ![true, false].includes(value)) {
16093 return (0, import_i18n45.__)("Value must be true, false, or undefined");
16094 }
16095 return null;
16096 }
16097 var sort3 = (a2, b2, direction) => {
16098 const boolA = Boolean(a2);
16099 const boolB = Boolean(b2);
16100 if (boolA === boolB) {
16101 return 0;
16102 }
16103 if (direction === "asc") {
16104 return boolA ? 1 : -1;
16105 }
16106 return boolA ? -1 : 1;
16107 };
16108 var boolean_default = {
16109 type: "boolean",
16110 render,
16111 Edit: "checkbox",
16112 sort: sort3,
16113 validate: {
16114 required: isValidRequiredForBool,
16115 elements: isValidElements,
16116 custom: isValidCustom4
16117 },
16118 enableSorting: true,
16119 enableGlobalSearch: false,
16120 defaultOperators: [OPERATOR_IS, OPERATOR_IS_NOT],
16121 validOperators: [OPERATOR_IS, OPERATOR_IS_NOT],
16122 format: {},
16123 getValueFormatted: getValueFormatted6
16124 };
16125
16126 // packages/dataviews/build-module/field-types/media.mjs
16127 var media_default = {
16128 type: "media",
16129 render: () => null,
16130 Edit: null,
16131 sort: () => 0,
16132 enableSorting: false,
16133 enableGlobalSearch: false,
16134 defaultOperators: [],
16135 validOperators: [],
16136 format: {},
16137 getValueFormatted: get_value_formatted_default_default,
16138 // cannot validate any constraint, so
16139 // the only available validation for the field author
16140 // would be providing a custom validator.
16141 validate: {}
16142 };
16143
16144 // packages/dataviews/build-module/field-types/array.mjs
16145 var import_i18n46 = __toESM(require_i18n(), 1);
16146
16147 // packages/dataviews/build-module/field-types/utils/is-valid-required-for-array.mjs
16148 function isValidRequiredForArray(item, field) {
16149 const value = field.getValue({ item });
16150 return Array.isArray(value) && value.length > 0 && value.every(
16151 (element) => ![void 0, "", null].includes(element)
16152 );
16153 }
16154
16155 // packages/dataviews/build-module/field-types/array.mjs
16156 function getValueFormatted7({
16157 item,
16158 field
16159 }) {
16160 const value = field.getValue({ item });
16161 const arr = Array.isArray(value) ? value : [];
16162 return arr.join(", ");
16163 }
16164 function render2({ item, field }) {
16165 return getValueFormatted7({ item, field });
16166 }
16167 function isValidCustom5(item, field) {
16168 const value = field.getValue({ item });
16169 if (![void 0, "", null].includes(value) && !Array.isArray(value)) {
16170 return (0, import_i18n46.__)("Value must be an array.");
16171 }
16172 if (!value.every((v2) => typeof v2 === "string")) {
16173 return (0, import_i18n46.__)("Every value must be a string.");
16174 }
16175 return null;
16176 }
16177 var sort4 = (a2, b2, direction) => {
16178 const arrA = Array.isArray(a2) ? a2 : [];
16179 const arrB = Array.isArray(b2) ? b2 : [];
16180 if (arrA.length !== arrB.length) {
16181 return direction === "asc" ? arrA.length - arrB.length : arrB.length - arrA.length;
16182 }
16183 const joinedA = arrA.join(",");
16184 const joinedB = arrB.join(",");
16185 return direction === "asc" ? joinedA.localeCompare(joinedB) : joinedB.localeCompare(joinedA);
16186 };
16187 var array_default = {
16188 type: "array",
16189 render: render2,
16190 Edit: "array",
16191 sort: sort4,
16192 enableSorting: true,
16193 enableGlobalSearch: false,
16194 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16195 validOperators: [
16196 OPERATOR_IS_ANY,
16197 OPERATOR_IS_NONE,
16198 OPERATOR_IS_ALL,
16199 OPERATOR_IS_NOT_ALL
16200 ],
16201 format: {},
16202 getValueFormatted: getValueFormatted7,
16203 validate: {
16204 required: isValidRequiredForArray,
16205 elements: isValidElements,
16206 custom: isValidCustom5
16207 }
16208 };
16209
16210 // packages/dataviews/build-module/field-types/password.mjs
16211 function getValueFormatted8({
16212 item,
16213 field
16214 }) {
16215 return field.getValue({ item }) ? "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022" : "";
16216 }
16217 var password_default = {
16218 type: "password",
16219 render,
16220 Edit: "password",
16221 sort: () => 0,
16222 // Passwords should not be sortable for security reasons
16223 enableSorting: false,
16224 enableGlobalSearch: false,
16225 defaultOperators: [],
16226 validOperators: [],
16227 format: {},
16228 getValueFormatted: getValueFormatted8,
16229 validate: {
16230 required: isValidRequired,
16231 pattern: isValidPattern,
16232 minLength: isValidMinLength,
16233 maxLength: isValidMaxLength,
16234 elements: isValidElements
16235 }
16236 };
16237
16238 // packages/dataviews/build-module/field-types/telephone.mjs
16239 var telephone_default = {
16240 type: "telephone",
16241 render,
16242 Edit: "telephone",
16243 sort: sort_text_default,
16244 enableSorting: true,
16245 enableGlobalSearch: false,
16246 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16247 validOperators: [
16248 OPERATOR_IS,
16249 OPERATOR_IS_NOT,
16250 OPERATOR_CONTAINS,
16251 OPERATOR_NOT_CONTAINS,
16252 OPERATOR_STARTS_WITH,
16253 // Multiple selection
16254 OPERATOR_IS_ANY,
16255 OPERATOR_IS_NONE,
16256 OPERATOR_IS_ALL,
16257 OPERATOR_IS_NOT_ALL
16258 ],
16259 format: {},
16260 getValueFormatted: get_value_formatted_default_default,
16261 validate: {
16262 required: isValidRequired,
16263 pattern: isValidPattern,
16264 minLength: isValidMinLength,
16265 maxLength: isValidMaxLength,
16266 elements: isValidElements
16267 }
16268 };
16269
16270 // packages/dataviews/build-module/field-types/color.mjs
16271 var import_i18n47 = __toESM(require_i18n(), 1);
16272 var import_jsx_runtime95 = __toESM(require_jsx_runtime(), 1);
16273 function render3({ item, field }) {
16274 if (field.hasElements) {
16275 return /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(RenderFromElements, { item, field });
16276 }
16277 const value = get_value_formatted_default_default({ item, field });
16278 if (!value || !w(value).isValid()) {
16279 return value;
16280 }
16281 return /* @__PURE__ */ (0, import_jsx_runtime95.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "8px" }, children: [
16282 /* @__PURE__ */ (0, import_jsx_runtime95.jsx)(
16283 "div",
16284 {
16285 style: {
16286 width: "16px",
16287 height: "16px",
16288 borderRadius: "50%",
16289 backgroundColor: value,
16290 border: "1px solid #ddd",
16291 flexShrink: 0
16292 }
16293 }
16294 ),
16295 /* @__PURE__ */ (0, import_jsx_runtime95.jsx)("span", { children: value })
16296 ] });
16297 }
16298 function isValidCustom6(item, field) {
16299 const value = field.getValue({ item });
16300 if (![void 0, "", null].includes(value) && !w(value).isValid()) {
16301 return (0, import_i18n47.__)("Value must be a valid color.");
16302 }
16303 return null;
16304 }
16305 var sort5 = (a2, b2, direction) => {
16306 const colorA = w(a2);
16307 const colorB = w(b2);
16308 if (!colorA.isValid() && !colorB.isValid()) {
16309 return 0;
16310 }
16311 if (!colorA.isValid()) {
16312 return direction === "asc" ? 1 : -1;
16313 }
16314 if (!colorB.isValid()) {
16315 return direction === "asc" ? -1 : 1;
16316 }
16317 const hslA = colorA.toHsl();
16318 const hslB = colorB.toHsl();
16319 if (hslA.h !== hslB.h) {
16320 return direction === "asc" ? hslA.h - hslB.h : hslB.h - hslA.h;
16321 }
16322 if (hslA.s !== hslB.s) {
16323 return direction === "asc" ? hslA.s - hslB.s : hslB.s - hslA.s;
16324 }
16325 return direction === "asc" ? hslA.l - hslB.l : hslB.l - hslA.l;
16326 };
16327 var color_default = {
16328 type: "color",
16329 render: render3,
16330 Edit: "color",
16331 sort: sort5,
16332 enableSorting: true,
16333 enableGlobalSearch: false,
16334 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16335 validOperators: [
16336 OPERATOR_IS,
16337 OPERATOR_IS_NOT,
16338 OPERATOR_IS_ANY,
16339 OPERATOR_IS_NONE
16340 ],
16341 format: {},
16342 getValueFormatted: get_value_formatted_default_default,
16343 validate: {
16344 required: isValidRequired,
16345 elements: isValidElements,
16346 custom: isValidCustom6
16347 }
16348 };
16349
16350 // packages/dataviews/build-module/field-types/url.mjs
16351 var url_default = {
16352 type: "url",
16353 render,
16354 Edit: "url",
16355 sort: sort_text_default,
16356 enableSorting: true,
16357 enableGlobalSearch: false,
16358 defaultOperators: [OPERATOR_IS_ANY, OPERATOR_IS_NONE],
16359 validOperators: [
16360 OPERATOR_IS,
16361 OPERATOR_IS_NOT,
16362 OPERATOR_CONTAINS,
16363 OPERATOR_NOT_CONTAINS,
16364 OPERATOR_STARTS_WITH,
16365 // Multiple selection
16366 OPERATOR_IS_ANY,
16367 OPERATOR_IS_NONE,
16368 OPERATOR_IS_ALL,
16369 OPERATOR_IS_NOT_ALL
16370 ],
16371 format: {},
16372 getValueFormatted: get_value_formatted_default_default,
16373 validate: {
16374 required: isValidRequired,
16375 pattern: isValidPattern,
16376 minLength: isValidMinLength,
16377 maxLength: isValidMaxLength,
16378 elements: isValidElements
16379 }
16380 };
16381
16382 // packages/dataviews/build-module/field-types/no-type.mjs
16383 var sort6 = (a2, b2, direction) => {
16384 if (typeof a2 === "number" && typeof b2 === "number") {
16385 return sort_number_default(a2, b2, direction);
16386 }
16387 return sort_text_default(a2, b2, direction);
16388 };
16389 var no_type_default = {
16390 // type: no type for this one
16391 render,
16392 Edit: null,
16393 sort: sort6,
16394 enableSorting: true,
16395 enableGlobalSearch: false,
16396 defaultOperators: [OPERATOR_IS, OPERATOR_IS_NOT],
16397 validOperators: getAllOperatorNames(),
16398 format: {},
16399 getValueFormatted: get_value_formatted_default_default,
16400 validate: {
16401 required: isValidRequired,
16402 elements: isValidElements
16403 }
16404 };
16405
16406 // packages/dataviews/build-module/field-types/utils/get-is-valid.mjs
16407 function getIsValid(field, fieldType) {
16408 let required;
16409 if (field.isValid?.required === true && fieldType.validate.required !== void 0) {
16410 required = {
16411 constraint: true,
16412 validate: fieldType.validate.required
16413 };
16414 }
16415 let elements;
16416 if ((field.isValid?.elements === true || // elements is enabled unless the field opts-out
16417 field.isValid?.elements === void 0 && (!!field.elements || !!field.getElements)) && fieldType.validate.elements !== void 0) {
16418 elements = {
16419 constraint: true,
16420 validate: fieldType.validate.elements
16421 };
16422 }
16423 let min;
16424 if (typeof field.isValid?.min === "number" && fieldType.validate.min !== void 0) {
16425 min = {
16426 constraint: field.isValid.min,
16427 validate: fieldType.validate.min
16428 };
16429 }
16430 let max;
16431 if (typeof field.isValid?.max === "number" && fieldType.validate.max !== void 0) {
16432 max = {
16433 constraint: field.isValid.max,
16434 validate: fieldType.validate.max
16435 };
16436 }
16437 let minLength;
16438 if (typeof field.isValid?.minLength === "number" && fieldType.validate.minLength !== void 0) {
16439 minLength = {
16440 constraint: field.isValid.minLength,
16441 validate: fieldType.validate.minLength
16442 };
16443 }
16444 let maxLength;
16445 if (typeof field.isValid?.maxLength === "number" && fieldType.validate.maxLength !== void 0) {
16446 maxLength = {
16447 constraint: field.isValid.maxLength,
16448 validate: fieldType.validate.maxLength
16449 };
16450 }
16451 let pattern;
16452 if (field.isValid?.pattern !== void 0 && fieldType.validate.pattern !== void 0) {
16453 pattern = {
16454 constraint: field.isValid?.pattern,
16455 validate: fieldType.validate.pattern
16456 };
16457 }
16458 const custom = field.isValid?.custom ?? fieldType.validate.custom;
16459 return {
16460 required,
16461 elements,
16462 min,
16463 max,
16464 minLength,
16465 maxLength,
16466 pattern,
16467 custom
16468 };
16469 }
16470
16471 // packages/dataviews/build-module/field-types/utils/get-format.mjs
16472 function getFormat(field, fieldType) {
16473 return {
16474 ...fieldType.format,
16475 ...field.format
16476 };
16477 }
16478 var get_format_default = getFormat;
16479
16480 // packages/dataviews/build-module/field-types/index.mjs
16481 function getFieldTypeByName(type) {
16482 const found = [
16483 email_default,
16484 integer_default,
16485 number_default,
16486 text_default,
16487 datetime_default,
16488 date_default,
16489 boolean_default,
16490 media_default,
16491 array_default,
16492 password_default,
16493 telephone_default,
16494 color_default,
16495 url_default
16496 ].find((fieldType) => fieldType?.type === type);
16497 if (!!found) {
16498 return found;
16499 }
16500 return no_type_default;
16501 }
16502 function normalizeFields(fields) {
16503 return fields.map((field) => {
16504 const fieldType = getFieldTypeByName(field.type);
16505 const getValue = field.getValue || get_value_from_id_default(field.id);
16506 const sort7 = function(a2, b2, direction) {
16507 const aValue = getValue({ item: a2 });
16508 const bValue = getValue({ item: b2 });
16509 return field.sort ? field.sort(aValue, bValue, direction) : fieldType.sort(aValue, bValue, direction);
16510 };
16511 return {
16512 id: field.id,
16513 label: field.label || field.id,
16514 header: field.header || field.label || field.id,
16515 description: field.description,
16516 placeholder: field.placeholder,
16517 getValue,
16518 setValue: field.setValue || set_value_from_id_default(field.id),
16519 elements: field.elements,
16520 getElements: field.getElements,
16521 hasElements: hasElements(field),
16522 isVisible: field.isVisible,
16523 enableHiding: field.enableHiding ?? true,
16524 readOnly: field.readOnly ?? false,
16525 // The type provides defaults for the following props
16526 type: fieldType.type,
16527 render: field.render ?? fieldType.render,
16528 Edit: getControl(field, fieldType.Edit),
16529 sort: sort7,
16530 enableSorting: field.enableSorting ?? fieldType.enableSorting,
16531 enableGlobalSearch: field.enableGlobalSearch ?? fieldType.enableGlobalSearch,
16532 isValid: getIsValid(field, fieldType),
16533 filterBy: get_filter_by_default(
16534 field,
16535 fieldType.defaultOperators,
16536 fieldType.validOperators
16537 ),
16538 format: get_format_default(field, fieldType),
16539 getValueFormatted: field.getValueFormatted ?? fieldType.getValueFormatted
16540 };
16541 });
16542 }
16543
16544 // packages/dataviews/build-module/dataviews-picker/index.mjs
16545 var import_element52 = __toESM(require_element(), 1);
16546 var import_compose11 = __toESM(require_compose(), 1);
16547 var import_jsx_runtime96 = __toESM(require_jsx_runtime(), 1);
16548 var isItemClickable = () => false;
16549 var dataViewsPickerLayouts = VIEW_LAYOUTS.filter(
16550 (viewLayout) => viewLayout.isPicker
16551 );
16552 var defaultGetItemId = (item) => item.id;
16553 var EMPTY_ARRAY5 = [];
16554 function DefaultUI({
16555 search = true,
16556 searchLabel = void 0
16557 }) {
16558 return /* @__PURE__ */ (0, import_jsx_runtime96.jsxs)(import_jsx_runtime96.Fragment, { children: [
16559 /* @__PURE__ */ (0, import_jsx_runtime96.jsxs)(
16560 Stack,
16561 {
16562 direction: "row",
16563 align: "top",
16564 justify: "space-between",
16565 className: "dataviews__view-actions",
16566 gap: "2xs",
16567 children: [
16568 /* @__PURE__ */ (0, import_jsx_runtime96.jsxs)(
16569 Stack,
16570 {
16571 direction: "row",
16572 gap: "xs",
16573 justify: "start",
16574 className: "dataviews__search",
16575 children: [
16576 search && /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(dataviews_search_default, { label: searchLabel }),
16577 /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(toggle_default, {})
16578 ]
16579 }
16580 ),
16581 /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(Stack, { direction: "row", gap: "2xs", style: { flexShrink: 0 }, children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(dataviews_view_config_default, {}) })
16582 ]
16583 }
16584 ),
16585 /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(filters_toggled_default, { className: "dataviews-filters__container" }),
16586 /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(DataViewsLayout, {}),
16587 /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(DataViewsPickerFooter, {})
16588 ] });
16589 }
16590 function DataViewsPicker({
16591 view,
16592 onChangeView,
16593 fields,
16594 search = true,
16595 searchLabel = void 0,
16596 actions = EMPTY_ARRAY5,
16597 data,
16598 getItemId = defaultGetItemId,
16599 isLoading = false,
16600 paginationInfo,
16601 defaultLayouts: defaultLayoutsProperty,
16602 selection,
16603 onChangeSelection,
16604 children,
16605 config = { perPageSizes: [10, 20, 50, 100] },
16606 itemListLabel,
16607 empty
16608 }) {
16609 const { infiniteScrollHandler } = paginationInfo;
16610 const containerRef = (0, import_element52.useRef)(null);
16611 const [containerWidth, setContainerWidth] = (0, import_element52.useState)(0);
16612 const resizeObserverRef = (0, import_compose11.useResizeObserver)(
16613 (resizeObserverEntries) => {
16614 setContainerWidth(
16615 resizeObserverEntries[0].borderBoxSize[0].inlineSize
16616 );
16617 },
16618 { box: "border-box" }
16619 );
16620 const [openedFilter, setOpenedFilter] = (0, import_element52.useState)(null);
16621 function setSelectionWithChange(value) {
16622 const newValue = typeof value === "function" ? value(selection) : value;
16623 if (onChangeSelection) {
16624 onChangeSelection(newValue);
16625 }
16626 }
16627 const _fields = (0, import_element52.useMemo)(() => normalizeFields(fields), [fields]);
16628 const filters = use_filters_default(_fields, view);
16629 const hasPrimaryOrLockedFilters = (0, import_element52.useMemo)(
16630 () => (filters || []).some(
16631 (filter) => filter.isPrimary || filter.isLocked
16632 ),
16633 [filters]
16634 );
16635 const [isShowingFilter, setIsShowingFilter] = (0, import_element52.useState)(
16636 hasPrimaryOrLockedFilters
16637 );
16638 (0, import_element52.useEffect)(() => {
16639 if (hasPrimaryOrLockedFilters && !isShowingFilter) {
16640 setIsShowingFilter(true);
16641 }
16642 }, [hasPrimaryOrLockedFilters, isShowingFilter]);
16643 (0, import_element52.useEffect)(() => {
16644 if (!view.infiniteScrollEnabled || !containerRef.current) {
16645 return;
16646 }
16647 const handleScroll = (0, import_compose11.throttle)((event) => {
16648 const target = event.target;
16649 const scrollTop = target.scrollTop;
16650 const scrollHeight = target.scrollHeight;
16651 const clientHeight = target.clientHeight;
16652 if (scrollTop + clientHeight >= scrollHeight - 100) {
16653 infiniteScrollHandler?.();
16654 }
16655 }, 100);
16656 const container = containerRef.current;
16657 container.addEventListener("scroll", handleScroll);
16658 return () => {
16659 container.removeEventListener("scroll", handleScroll);
16660 handleScroll.cancel();
16661 };
16662 }, [infiniteScrollHandler, view.infiniteScrollEnabled]);
16663 const defaultLayouts = (0, import_element52.useMemo)(
16664 () => Object.fromEntries(
16665 Object.entries(defaultLayoutsProperty).filter(
16666 ([layoutType]) => {
16667 return dataViewsPickerLayouts.some(
16668 (viewLayout) => viewLayout.type === layoutType
16669 );
16670 }
16671 )
16672 ),
16673 [defaultLayoutsProperty]
16674 );
16675 if (!defaultLayouts[view.type]) {
16676 return null;
16677 }
16678 return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(
16679 dataviews_context_default.Provider,
16680 {
16681 value: {
16682 view,
16683 onChangeView,
16684 fields: _fields,
16685 actions,
16686 data,
16687 isLoading,
16688 paginationInfo,
16689 isItemClickable,
16690 selection,
16691 onChangeSelection: setSelectionWithChange,
16692 openedFilter,
16693 setOpenedFilter,
16694 getItemId,
16695 containerWidth,
16696 containerRef,
16697 resizeObserverRef,
16698 defaultLayouts,
16699 filters,
16700 isShowingFilter,
16701 setIsShowingFilter,
16702 config,
16703 itemListLabel,
16704 empty,
16705 hasInfiniteScrollHandler: !!infiniteScrollHandler
16706 },
16707 children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)("div", { className: "dataviews-picker-wrapper", ref: containerRef, children: children ?? /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(DefaultUI, { search, searchLabel }) })
16708 }
16709 );
16710 }
16711 var DataViewsPickerSubComponents = DataViewsPicker;
16712 DataViewsPickerSubComponents.BulkActionToolbar = DataViewsPickerFooter;
16713 DataViewsPickerSubComponents.Filters = filters_default;
16714 DataViewsPickerSubComponents.FiltersToggled = filters_toggled_default;
16715 DataViewsPickerSubComponents.FiltersToggle = toggle_default;
16716 DataViewsPickerSubComponents.Layout = DataViewsLayout;
16717 DataViewsPickerSubComponents.LayoutSwitcher = ViewTypeMenu;
16718 DataViewsPickerSubComponents.Pagination = DataViewsPagination;
16719 DataViewsPickerSubComponents.Search = dataviews_search_default;
16720 DataViewsPickerSubComponents.ViewConfig = DataviewsViewConfigDropdown;
16721 var dataviews_picker_default = DataViewsPickerSubComponents;
16722
16723 // packages/media-fields/build-module/alt_text/index.mjs
16724 var import_i18n48 = __toESM(require_i18n(), 1);
16725 var import_components45 = __toESM(require_components(), 1);
16726 var import_jsx_runtime97 = __toESM(require_jsx_runtime(), 1);
16727 var altTextField = {
16728 id: "alt_text",
16729 type: "text",
16730 label: (0, import_i18n48.__)("Alt text"),
16731 isVisible: (item) => item?.media_type === "image",
16732 render: ({ item }) => item?.alt_text || "-",
16733 Edit: ({ field, onChange, data }) => {
16734 return /* @__PURE__ */ (0, import_jsx_runtime97.jsx)(
16735 import_components45.TextareaControl,
16736 {
16737 label: field.label,
16738 value: data.alt_text || "",
16739 onChange: (value) => onChange({ alt_text: value }),
16740 rows: 2
16741 }
16742 );
16743 },
16744 enableSorting: false,
16745 filterBy: false
16746 };
16747 var alt_text_default = altTextField;
16748
16749 // packages/media-fields/build-module/attached_to/index.mjs
16750 var import_i18n51 = __toESM(require_i18n(), 1);
16751
16752 // packages/media-fields/build-module/attached_to/view.mjs
16753 var import_element53 = __toESM(require_element(), 1);
16754 var import_i18n49 = __toESM(require_i18n(), 1);
16755
16756 // packages/media-fields/build-module/utils/get-rendered-content.mjs
16757 function getRenderedContent(content) {
16758 if (!content) {
16759 return "";
16760 }
16761 if (typeof content === "string") {
16762 return content;
16763 }
16764 if (typeof content === "object") {
16765 return content.rendered || content.raw || "";
16766 }
16767 return "";
16768 }
16769
16770 // packages/media-fields/build-module/attached_to/view.mjs
16771 var import_jsx_runtime98 = __toESM(require_jsx_runtime(), 1);
16772 function MediaAttachedToView({
16773 item
16774 }) {
16775 const [attachedPostTitle, setAttachedPostTitle] = (0, import_element53.useState)(null);
16776 const parentId = item.post;
16777 const embeddedPostId = item._embedded?.["wp:attached-to"]?.[0]?.id;
16778 const embeddedPostTitle = item._embedded?.["wp:attached-to"]?.[0]?.title;
16779 (0, import_element53.useEffect)(() => {
16780 if (!!parentId && parentId === embeddedPostId) {
16781 setAttachedPostTitle(
16782 getRenderedContent(embeddedPostTitle) || embeddedPostId?.toString() || ""
16783 );
16784 }
16785 if (!parentId) {
16786 setAttachedPostTitle((0, import_i18n49.__)("(Unattached)"));
16787 }
16788 }, [parentId, embeddedPostId, embeddedPostTitle]);
16789 return /* @__PURE__ */ (0, import_jsx_runtime98.jsx)(import_jsx_runtime98.Fragment, { children: attachedPostTitle });
16790 }
16791
16792 // packages/media-fields/build-module/attached_to/edit.mjs
16793 var import_core_data = __toESM(require_core_data(), 1);
16794 var import_components46 = __toESM(require_components(), 1);
16795 var import_i18n50 = __toESM(require_i18n(), 1);
16796 var import_element54 = __toESM(require_element(), 1);
16797 var import_compose12 = __toESM(require_compose(), 1);
16798 var import_data6 = __toESM(require_data(), 1);
16799 var import_jsx_runtime99 = __toESM(require_jsx_runtime(), 1);
16800 function MediaAttachedToEdit({
16801 data,
16802 onChange
16803 }) {
16804 const defaultPost = !!data.post && !!data?._embedded?.["wp:attached-to"]?.[0] ? [
16805 {
16806 label: getRenderedContent(
16807 data._embedded?.["wp:attached-to"]?.[0]?.title
16808 ),
16809 value: data.post.toString()
16810 }
16811 ] : [];
16812 const [options, setOptions] = (0, import_element54.useState)(defaultPost);
16813 const [searchResults, setSearchResults] = (0, import_element54.useState)(
16814 []
16815 );
16816 const [isLoading, setIsLoading] = (0, import_element54.useState)(false);
16817 const [value, setValue] = (0, import_element54.useState)(
16818 data?.post?.toString() ?? null
16819 );
16820 const postTypes = (0, import_data6.useSelect)(
16821 (select) => select(import_core_data.store).getPostTypes(),
16822 []
16823 );
16824 const handleDetach = () => {
16825 onChange({
16826 post: 0,
16827 _embedded: { ...data?._embedded, "wp:attached-to": void 0 }
16828 });
16829 setOptions([]);
16830 };
16831 const onValueChange = async (filterValue) => {
16832 setIsLoading(true);
16833 const results = await (0, import_core_data.__experimentalFetchLinkSuggestions)(
16834 filterValue,
16835 /*
16836 * @TODO `fetchLinkSuggestions()` should accept `perPage` as an option argument.
16837 * `isInitialSuggestions` limits the result to 3, otherwise it's hardcoded to 20.
16838 */
16839 { type: "post", isInitialSuggestions: true },
16840 {}
16841 );
16842 setSearchResults(results);
16843 const mappedSuggestions = results.map((result) => {
16844 return {
16845 label: result.title,
16846 value: result.id.toString()
16847 };
16848 });
16849 setOptions(mappedSuggestions);
16850 setIsLoading(false);
16851 };
16852 const handleSelectOption = (selectedPostId) => {
16853 if (!selectedPostId) {
16854 handleDetach();
16855 return;
16856 }
16857 setValue(selectedPostId);
16858 if (selectedPostId) {
16859 const selectedPost = searchResults.find(
16860 (result) => result.id === Number(selectedPostId)
16861 );
16862 if (selectedPost && postTypes) {
16863 const postType = postTypes.find(
16864 (_postType) => _postType.slug === selectedPost?.type
16865 );
16866 const attachedTo = {
16867 ...postType && { type: postType.slug },
16868 id: Number(selectedPostId),
16869 title: {
16870 raw: selectedPost.title,
16871 rendered: selectedPost.title
16872 }
16873 };
16874 onChange({
16875 post: Number(selectedPostId),
16876 _embedded: {
16877 ...data?._embedded,
16878 "wp:attached-to": [attachedTo]
16879 }
16880 });
16881 }
16882 }
16883 };
16884 const help = !!data.post ? (0, import_element54.createInterpolateElement)(
16885 (0, import_i18n50.__)(
16886 "Search for a post or page to attach this media to or <button>detach current</button>."
16887 ),
16888 {
16889 button: /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(
16890 import_components46.Button,
16891 {
16892 __next40pxDefaultSize: true,
16893 onClick: handleDetach,
16894 variant: "link",
16895 accessibleWhenDisabled: true
16896 }
16897 )
16898 }
16899 ) : (0, import_i18n50.__)("Search for a post or page to attach this media to.");
16900 return /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(
16901 import_components46.ComboboxControl,
16902 {
16903 className: "dataviews-media-field__attached-to",
16904 __next40pxDefaultSize: true,
16905 isLoading,
16906 label: (0, import_i18n50.__)("Attached to"),
16907 help,
16908 value,
16909 options,
16910 onFilterValueChange: (0, import_compose12.debounce)(
16911 (filterValue) => onValueChange(filterValue),
16912 300
16913 ),
16914 onChange: handleSelectOption,
16915 hideLabelFromVision: true
16916 }
16917 );
16918 }
16919
16920 // packages/media-fields/build-module/attached_to/index.mjs
16921 var attachedToField = {
16922 id: "attached_to",
16923 type: "text",
16924 label: (0, import_i18n51.__)("Attached to"),
16925 Edit: MediaAttachedToEdit,
16926 render: MediaAttachedToView,
16927 enableSorting: false,
16928 filterBy: false
16929 };
16930 var attached_to_default = attachedToField;
16931
16932 // packages/media-fields/build-module/author/index.mjs
16933 var import_i18n53 = __toESM(require_i18n(), 1);
16934 var import_data7 = __toESM(require_data(), 1);
16935 var import_core_data2 = __toESM(require_core_data(), 1);
16936
16937 // packages/media-fields/build-module/author/view.mjs
16938 var import_i18n52 = __toESM(require_i18n(), 1);
16939 var import_element55 = __toESM(require_element(), 1);
16940 var import_components47 = __toESM(require_components(), 1);
16941 var import_jsx_runtime100 = __toESM(require_jsx_runtime(), 1);
16942 function AuthorView({
16943 item
16944 }) {
16945 const author = item?._embedded?.author?.[0];
16946 const text = author?.name;
16947 const imageUrl = author?.avatar_urls?.[48];
16948 const [loadingState, setLoadingState] = (0, import_element55.useState)("loading");
16949 (0, import_element55.useEffect)(() => {
16950 setLoadingState("loading");
16951 }, [imageUrl]);
16952 const imgRef = (0, import_element55.useCallback)((img) => {
16953 if (img?.complete) {
16954 setLoadingState("instant");
16955 }
16956 }, []);
16957 const handleLoad = () => {
16958 if (loadingState === "loading") {
16959 setLoadingState("loaded");
16960 }
16961 };
16962 return /* @__PURE__ */ (0, import_jsx_runtime100.jsxs)(import_components47.__experimentalHStack, { alignment: "left", spacing: 0, children: [
16963 !!imageUrl && /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(
16964 "div",
16965 {
16966 className: clsx_default("media-author-field__avatar", {
16967 "is-loading": loadingState === "loading",
16968 "is-loaded": loadingState === "loaded"
16969 }),
16970 children: /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(
16971 "img",
16972 {
16973 ref: imgRef,
16974 onLoad: handleLoad,
16975 alt: (0, import_i18n52.__)("Author avatar"),
16976 src: imageUrl
16977 }
16978 )
16979 }
16980 ),
16981 !imageUrl && /* @__PURE__ */ (0, import_jsx_runtime100.jsx)("div", { className: "media-author-field__icon", children: /* @__PURE__ */ (0, import_jsx_runtime100.jsx)(import_components47.Icon, { icon: comment_author_avatar_default }) }),
16982 /* @__PURE__ */ (0, import_jsx_runtime100.jsx)("span", { className: "media-author-field__name", children: text })
16983 ] });
16984 }
16985
16986 // packages/media-fields/build-module/author/index.mjs
16987 var authorField = {
16988 label: (0, import_i18n53.__)("Author"),
16989 id: "author",
16990 type: "integer",
16991 getElements: async () => {
16992 const authors = await (0, import_data7.resolveSelect)(import_core_data2.store).getEntityRecords(
16993 "root",
16994 "user",
16995 {
16996 per_page: -1
16997 }
16998 ) ?? [];
16999 return authors.map(({ id, name }) => ({
17000 value: id,
17001 label: name
17002 }));
17003 },
17004 render: AuthorView,
17005 sort: (a2, b2, direction) => {
17006 const nameA = a2._embedded?.author?.[0]?.name || "";
17007 const nameB = b2._embedded?.author?.[0]?.name || "";
17008 return direction === "asc" ? nameA.localeCompare(nameB) : nameB.localeCompare(nameA);
17009 },
17010 filterBy: {
17011 operators: ["isAny", "isNone"]
17012 },
17013 readOnly: true
17014 };
17015 var author_default = authorField;
17016
17017 // packages/media-fields/build-module/caption/index.mjs
17018 var import_i18n54 = __toESM(require_i18n(), 1);
17019 var import_components48 = __toESM(require_components(), 1);
17020
17021 // packages/media-fields/build-module/utils/get-raw-content.mjs
17022 function getRawContent(content) {
17023 if (!content) {
17024 return "";
17025 }
17026 if (typeof content === "string") {
17027 return content;
17028 }
17029 if (typeof content === "object" && "raw" in content) {
17030 return content.raw || "";
17031 }
17032 return "";
17033 }
17034
17035 // packages/media-fields/build-module/caption/index.mjs
17036 var import_jsx_runtime101 = __toESM(require_jsx_runtime(), 1);
17037 var captionField = {
17038 id: "caption",
17039 type: "text",
17040 label: (0, import_i18n54.__)("Caption"),
17041 getValue: ({ item }) => getRawContent(item?.caption),
17042 render: ({ item }) => getRawContent(item?.caption) || "-",
17043 Edit: ({ field, onChange, data }) => {
17044 return /* @__PURE__ */ (0, import_jsx_runtime101.jsx)(
17045 import_components48.TextareaControl,
17046 {
17047 label: field.label,
17048 value: getRawContent(data.caption) || "",
17049 onChange: (value) => onChange({ caption: value }),
17050 rows: 2
17051 }
17052 );
17053 },
17054 enableSorting: false,
17055 filterBy: false
17056 };
17057 var caption_default = captionField;
17058
17059 // packages/media-fields/build-module/date_added/index.mjs
17060 var import_i18n55 = __toESM(require_i18n(), 1);
17061 var import_date8 = __toESM(require_date(), 1);
17062 var dateAddedField = {
17063 id: "date",
17064 type: "datetime",
17065 label: (0, import_i18n55.__)("Date added"),
17066 filterBy: {
17067 operators: ["before", "after"]
17068 },
17069 format: {
17070 datetime: (0, import_date8.getSettings)().formats.datetimeAbbreviated
17071 },
17072 readOnly: true
17073 };
17074 var date_added_default = dateAddedField;
17075
17076 // packages/media-fields/build-module/date_modified/index.mjs
17077 var import_i18n56 = __toESM(require_i18n(), 1);
17078 var import_date9 = __toESM(require_date(), 1);
17079 var dateModifiedField = {
17080 id: "modified",
17081 type: "datetime",
17082 label: (0, import_i18n56.__)("Date modified"),
17083 filterBy: {
17084 operators: ["before", "after"]
17085 },
17086 format: {
17087 datetime: (0, import_date9.getSettings)().formats.datetimeAbbreviated
17088 },
17089 readOnly: true
17090 };
17091 var date_modified_default = dateModifiedField;
17092
17093 // packages/media-fields/build-module/description/index.mjs
17094 var import_i18n57 = __toESM(require_i18n(), 1);
17095 var import_components49 = __toESM(require_components(), 1);
17096 var import_jsx_runtime102 = __toESM(require_jsx_runtime(), 1);
17097 var descriptionField = {
17098 id: "description",
17099 type: "text",
17100 label: (0, import_i18n57.__)("Description"),
17101 getValue: ({ item }) => getRawContent(item?.description),
17102 render: ({ item }) => /* @__PURE__ */ (0, import_jsx_runtime102.jsx)("div", { children: getRawContent(item?.description) || "-" }),
17103 Edit: ({ field, onChange, data }) => {
17104 return /* @__PURE__ */ (0, import_jsx_runtime102.jsx)(
17105 import_components49.TextareaControl,
17106 {
17107 label: field.label,
17108 value: getRawContent(data.description) || "",
17109 onChange: (value) => onChange({ description: value }),
17110 rows: 5
17111 }
17112 );
17113 },
17114 enableSorting: false,
17115 filterBy: false
17116 };
17117 var description_default = descriptionField;
17118
17119 // packages/media-fields/build-module/filename/index.mjs
17120 var import_i18n58 = __toESM(require_i18n(), 1);
17121 var import_url4 = __toESM(require_url(), 1);
17122
17123 // packages/media-fields/build-module/filename/view.mjs
17124 var import_components50 = __toESM(require_components(), 1);
17125 var import_element56 = __toESM(require_element(), 1);
17126 var import_url3 = __toESM(require_url(), 1);
17127 var import_jsx_runtime103 = __toESM(require_jsx_runtime(), 1);
17128 var TRUNCATE_LENGTH = 15;
17129 function FileNameView({
17130 item
17131 }) {
17132 const fileName = (0, import_element56.useMemo)(
17133 () => item?.source_url ? (0, import_url3.getFilename)(item.source_url) : null,
17134 [item?.source_url]
17135 );
17136 if (!fileName) {
17137 return "";
17138 }
17139 return fileName.length > TRUNCATE_LENGTH ? /* @__PURE__ */ (0, import_jsx_runtime103.jsx)(import_components50.Tooltip, { text: fileName, children: /* @__PURE__ */ (0, import_jsx_runtime103.jsx)(import_components50.__experimentalTruncate, { children: fileName }) }) : /* @__PURE__ */ (0, import_jsx_runtime103.jsx)(import_jsx_runtime103.Fragment, { children: fileName });
17140 }
17141
17142 // packages/media-fields/build-module/filename/index.mjs
17143 var filenameField = {
17144 id: "filename",
17145 type: "text",
17146 label: (0, import_i18n58.__)("File name"),
17147 getValue: ({ item }) => (0, import_url4.getFilename)(item?.source_url || ""),
17148 render: FileNameView,
17149 enableSorting: false,
17150 filterBy: false,
17151 readOnly: true
17152 };
17153 var filename_default = filenameField;
17154
17155 // packages/media-fields/build-module/filesize/index.mjs
17156 var import_i18n59 = __toESM(require_i18n(), 1);
17157 var KB_IN_BYTES = 1024;
17158 var MB_IN_BYTES = 1024 * KB_IN_BYTES;
17159 var GB_IN_BYTES = 1024 * MB_IN_BYTES;
17160 var TB_IN_BYTES = 1024 * GB_IN_BYTES;
17161 var PB_IN_BYTES = 1024 * TB_IN_BYTES;
17162 var EB_IN_BYTES = 1024 * PB_IN_BYTES;
17163 var ZB_IN_BYTES = 1024 * EB_IN_BYTES;
17164 var YB_IN_BYTES = 1024 * ZB_IN_BYTES;
17165 function getBytesString(bytes, unitSymbol, decimals = 2) {
17166 return (0, import_i18n59.sprintf)(
17167 // translators: 1: Actual bytes of a file. 2: The unit symbol (e.g. MB).
17168 (0, import_i18n59._x)("%1$s %2$s", "file size"),
17169 bytes.toLocaleString(void 0, {
17170 minimumFractionDigits: 0,
17171 maximumFractionDigits: decimals
17172 }),
17173 unitSymbol
17174 );
17175 }
17176 function formatFileSize(bytes, decimals = 2) {
17177 if (bytes === 0) {
17178 return getBytesString(0, (0, import_i18n59._x)("B", "unit symbol"), decimals);
17179 }
17180 const quant = {
17181 /* translators: Unit symbol for yottabyte. */
17182 [(0, import_i18n59._x)("YB", "unit symbol")]: YB_IN_BYTES,
17183 /* translators: Unit symbol for zettabyte. */
17184 [(0, import_i18n59._x)("ZB", "unit symbol")]: ZB_IN_BYTES,
17185 /* translators: Unit symbol for exabyte. */
17186 [(0, import_i18n59._x)("EB", "unit symbol")]: EB_IN_BYTES,
17187 /* translators: Unit symbol for petabyte. */
17188 [(0, import_i18n59._x)("PB", "unit symbol")]: PB_IN_BYTES,
17189 /* translators: Unit symbol for terabyte. */
17190 [(0, import_i18n59._x)("TB", "unit symbol")]: TB_IN_BYTES,
17191 /* translators: Unit symbol for gigabyte. */
17192 [(0, import_i18n59._x)("GB", "unit symbol")]: GB_IN_BYTES,
17193 /* translators: Unit symbol for megabyte. */
17194 [(0, import_i18n59._x)("MB", "unit symbol")]: MB_IN_BYTES,
17195 /* translators: Unit symbol for kilobyte. */
17196 [(0, import_i18n59._x)("KB", "unit symbol")]: KB_IN_BYTES,
17197 /* translators: Unit symbol for byte. */
17198 [(0, import_i18n59._x)("B", "unit symbol")]: 1
17199 };
17200 for (const [unit, mag] of Object.entries(quant)) {
17201 if (bytes >= mag) {
17202 return getBytesString(bytes / mag, unit, decimals);
17203 }
17204 }
17205 return "";
17206 }
17207 var filesizeField = {
17208 id: "filesize",
17209 type: "text",
17210 label: (0, import_i18n59.__)("File size"),
17211 getValue: ({ item }) => item?.media_details?.filesize ? formatFileSize(item?.media_details?.filesize) : "",
17212 isVisible: (item) => {
17213 return !!item?.media_details?.filesize;
17214 },
17215 enableSorting: false,
17216 filterBy: false,
17217 readOnly: true
17218 };
17219 var filesize_default = filesizeField;
17220
17221 // packages/media-fields/build-module/media_dimensions/index.mjs
17222 var import_i18n60 = __toESM(require_i18n(), 1);
17223 var mediaDimensionsField = {
17224 id: "media_dimensions",
17225 type: "text",
17226 label: (0, import_i18n60.__)("Dimensions"),
17227 getValue: ({ item }) => item?.media_details?.width && item?.media_details?.height ? (0, import_i18n60.sprintf)(
17228 // translators: 1: Width. 2: Height.
17229 (0, import_i18n60._x)("%1$s \xD7 %2$s", "image dimensions"),
17230 item?.media_details?.width?.toString(),
17231 item?.media_details?.height?.toString()
17232 ) : "",
17233 isVisible: (item) => {
17234 return !!(item?.media_details?.width && item?.media_details?.height);
17235 },
17236 enableSorting: false,
17237 filterBy: false,
17238 readOnly: true
17239 };
17240 var media_dimensions_default = mediaDimensionsField;
17241
17242 // packages/media-fields/build-module/media_thumbnail/index.mjs
17243 var import_i18n62 = __toESM(require_i18n(), 1);
17244
17245 // packages/media-fields/build-module/media_thumbnail/view.mjs
17246 var import_data8 = __toESM(require_data(), 1);
17247 var import_core_data3 = __toESM(require_core_data(), 1);
17248 var import_components51 = __toESM(require_components(), 1);
17249 var import_element57 = __toESM(require_element(), 1);
17250 var import_url5 = __toESM(require_url(), 1);
17251
17252 // packages/media-fields/build-module/utils/get-media-type-from-mime-type.mjs
17253 var import_i18n61 = __toESM(require_i18n(), 1);
17254 function getMediaTypeFromMimeType(mimeType) {
17255 if (mimeType.startsWith("image/")) {
17256 return {
17257 type: "image",
17258 label: (0, import_i18n61.__)("Image"),
17259 icon: image_default
17260 };
17261 }
17262 if (mimeType.startsWith("video/")) {
17263 return {
17264 type: "video",
17265 label: (0, import_i18n61.__)("Video"),
17266 icon: video_default
17267 };
17268 }
17269 if (mimeType.startsWith("audio/")) {
17270 return {
17271 type: "audio",
17272 label: (0, import_i18n61.__)("Audio"),
17273 icon: audio_default
17274 };
17275 }
17276 return {
17277 type: "application",
17278 label: (0, import_i18n61.__)("Application"),
17279 icon: file_default
17280 };
17281 }
17282
17283 // packages/media-fields/build-module/media_thumbnail/view.mjs
17284 var import_jsx_runtime104 = __toESM(require_jsx_runtime(), 1);
17285 function FallbackView({
17286 item,
17287 filename
17288 }) {
17289 return /* @__PURE__ */ (0, import_jsx_runtime104.jsx)("div", { className: "dataviews-media-field__media-thumbnail", children: /* @__PURE__ */ (0, import_jsx_runtime104.jsxs)(
17290 import_components51.__experimentalVStack,
17291 {
17292 justify: "center",
17293 alignment: "center",
17294 className: "dataviews-media-field__media-thumbnail__stack",
17295 spacing: 0,
17296 children: [
17297 /* @__PURE__ */ (0, import_jsx_runtime104.jsx)(
17298 import_components51.Icon,
17299 {
17300 className: "dataviews-media-field__media-thumbnail--icon",
17301 icon: getMediaTypeFromMimeType(item.mime_type).icon,
17302 size: 24
17303 }
17304 ),
17305 !!filename && /* @__PURE__ */ (0, import_jsx_runtime104.jsx)("div", { className: "dataviews-media-field__media-thumbnail__filename", children: /* @__PURE__ */ (0, import_jsx_runtime104.jsx)(import_components51.__experimentalTruncate, { className: "dataviews-media-field__media-thumbnail__filename__truncate", children: filename }) })
17306 ]
17307 }
17308 ) });
17309 }
17310 function MediaThumbnailView({
17311 item,
17312 config
17313 }) {
17314 const [imageError, setImageError] = (0, import_element57.useState)(false);
17315 const _featuredMedia = (0, import_data8.useSelect)(
17316 (select) => {
17317 if (!item.featured_media) {
17318 return;
17319 }
17320 return select(import_core_data3.store).getEntityRecord(
17321 "postType",
17322 "attachment",
17323 item.featured_media
17324 );
17325 },
17326 [item.featured_media]
17327 );
17328 const featuredMedia = item.featured_media ? _featuredMedia : item;
17329 if (!featuredMedia) {
17330 return null;
17331 }
17332 const filename = (0, import_url5.getFilename)(featuredMedia.source_url || "");
17333 if (imageError || getMediaTypeFromMimeType(featuredMedia.mime_type).type !== "image") {
17334 return /* @__PURE__ */ (0, import_jsx_runtime104.jsx)(FallbackView, { item: featuredMedia, filename: filename || "" });
17335 }
17336 return /* @__PURE__ */ (0, import_jsx_runtime104.jsx)("div", { className: "dataviews-media-field__media-thumbnail", children: /* @__PURE__ */ (0, import_jsx_runtime104.jsx)(
17337 "img",
17338 {
17339 className: "dataviews-media-field__media-thumbnail--image",
17340 src: featuredMedia.source_url,
17341 srcSet: featuredMedia?.media_details?.sizes ? Object.values(
17342 featuredMedia.media_details.sizes
17343 ).map(
17344 (size) => `${size.source_url} ${size.width}w`
17345 ).join(", ") : void 0,
17346 sizes: config?.sizes || "100vw",
17347 alt: featuredMedia.alt_text || featuredMedia.title.raw,
17348 onError: () => setImageError(true)
17349 }
17350 ) });
17351 }
17352
17353 // packages/media-fields/build-module/media_thumbnail/index.mjs
17354 var mediaThumbnailField = {
17355 id: "media_thumbnail",
17356 type: "media",
17357 label: (0, import_i18n62.__)("Thumbnail"),
17358 render: MediaThumbnailView,
17359 enableSorting: false,
17360 filterBy: false
17361 };
17362 var media_thumbnail_default = mediaThumbnailField;
17363
17364 // packages/media-fields/build-module/mime_type/index.mjs
17365 var import_i18n63 = __toESM(require_i18n(), 1);
17366 var mimeTypeField = {
17367 id: "mime_type",
17368 type: "text",
17369 label: (0, import_i18n63.__)("File type"),
17370 getValue: ({ item }) => item?.mime_type || "",
17371 render: ({ item }) => item?.mime_type || "-",
17372 // Disable sorting until REST API support for ordering my `mime_type` is added.
17373 // See: https://core.trac.wordpress.org/ticket/64073
17374 enableSorting: false,
17375 filterBy: false,
17376 readOnly: true
17377 };
17378 var mime_type_default = mimeTypeField;
17379
17380 // packages/media-utils/build-module/lock-unlock.mjs
17381 var import_private_apis2 = __toESM(require_private_apis(), 1);
17382 var { lock: lock2, unlock: unlock2 } = (0, import_private_apis2.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
17383 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
17384 "@wordpress/media-utils"
17385 );
17386
17387 // packages/media-utils/build-module/components/media-upload-modal/index.mjs
17388 var import_jsx_runtime105 = __toESM(require_jsx_runtime(), 1);
17389 var { useEntityRecordsWithPermissions } = unlock2(import_core_data4.privateApis);
17390 var LAYOUT_PICKER_GRID2 = "pickerGrid";
17391 var LAYOUT_PICKER_TABLE2 = "pickerTable";
17392 function MediaUploadModal({
17393 allowedTypes = ["image"],
17394 multiple = false,
17395 value,
17396 onSelect,
17397 onClose,
17398 onUpload,
17399 title = (0, import_i18n64.__)("Select Media"),
17400 isOpen,
17401 isDismissible = true,
17402 modalClass,
17403 search = true,
17404 searchLabel = (0, import_i18n64.__)("Search media")
17405 }) {
17406 const [selection, setSelection] = (0, import_element58.useState)(() => {
17407 if (!value) {
17408 return [];
17409 }
17410 return Array.isArray(value) ? value.map(String) : [String(value)];
17411 });
17412 const [view, setView] = (0, import_element58.useState)(() => ({
17413 type: LAYOUT_PICKER_GRID2,
17414 fields: [],
17415 showTitle: false,
17416 titleField: "title",
17417 mediaField: "media_thumbnail",
17418 search: "",
17419 page: 1,
17420 perPage: 20,
17421 filters: []
17422 }));
17423 const queryArgs = (0, import_element58.useMemo)(() => {
17424 const filters = {};
17425 view.filters?.forEach((filter) => {
17426 if (filter.field === "media_type") {
17427 filters.media_type = filter.value;
17428 }
17429 if (filter.field === "author") {
17430 if (filter.operator === "isAny") {
17431 filters.author = filter.value;
17432 } else if (filter.operator === "isNone") {
17433 filters.author_exclude = filter.value;
17434 }
17435 }
17436 if (filter.field === "date" || filter.field === "modified") {
17437 if (filter.operator === "before") {
17438 filters.before = filter.value;
17439 } else if (filter.operator === "after") {
17440 filters.after = filter.value;
17441 }
17442 }
17443 if (filter.field === "mime_type") {
17444 filters.mime_type = filter.value;
17445 }
17446 });
17447 if (!filters.media_type) {
17448 filters.media_type = allowedTypes.includes("*") ? void 0 : allowedTypes;
17449 }
17450 return {
17451 per_page: view.perPage || 20,
17452 page: view.page || 1,
17453 status: "inherit",
17454 order: view.sort?.direction,
17455 orderby: view.sort?.field,
17456 search: view.search,
17457 _embed: "author,wp:attached-to",
17458 ...filters
17459 };
17460 }, [view, allowedTypes]);
17461 const {
17462 records: mediaRecords,
17463 isResolving: isLoading,
17464 totalItems,
17465 totalPages
17466 } = useEntityRecordsWithPermissions("postType", "attachment", queryArgs);
17467 const fields = (0, import_element58.useMemo)(
17468 () => [
17469 // Media field definitions from @wordpress/media-fields
17470 // Cast is safe because RestAttachment has the same properties as Attachment
17471 {
17472 ...media_thumbnail_default,
17473 enableHiding: false
17474 // Within the modal, the thumbnail should always be shown.
17475 },
17476 {
17477 id: "title",
17478 type: "text",
17479 label: (0, import_i18n64.__)("Title"),
17480 getValue: ({ item }) => {
17481 const titleValue = item.title.raw || item.title.rendered;
17482 return titleValue || (0, import_i18n64.__)("(no title)");
17483 }
17484 },
17485 alt_text_default,
17486 caption_default,
17487 description_default,
17488 date_added_default,
17489 date_modified_default,
17490 author_default,
17491 filename_default,
17492 filesize_default,
17493 media_dimensions_default,
17494 mime_type_default,
17495 attached_to_default
17496 ],
17497 []
17498 );
17499 const actions = (0, import_element58.useMemo)(
17500 () => [
17501 {
17502 id: "select",
17503 label: multiple ? (0, import_i18n64.__)("Select") : (0, import_i18n64.__)("Select"),
17504 isPrimary: true,
17505 supportsBulk: multiple,
17506 async callback() {
17507 if (selection.length === 0) {
17508 return;
17509 }
17510 const selectedPostsQuery = {
17511 include: selection,
17512 per_page: -1
17513 };
17514 const selectedPosts = await (0, import_data9.resolveSelect)(
17515 import_core_data4.store
17516 ).getEntityRecords(
17517 "postType",
17518 "attachment",
17519 selectedPostsQuery
17520 );
17521 const transformedPosts = (selectedPosts ?? []).map(transformAttachment).filter(Boolean);
17522 const selectedItems = multiple ? transformedPosts : transformedPosts?.[0];
17523 onSelect(selectedItems);
17524 }
17525 }
17526 ],
17527 [multiple, onSelect, selection]
17528 );
17529 const handleModalClose = (0, import_element58.useCallback)(() => {
17530 onClose?.();
17531 }, [onClose]);
17532 const handleUpload = onUpload || uploadMedia;
17533 const handleFileSelect = (0, import_element58.useCallback)(
17534 (event) => {
17535 const files = event.target.files;
17536 if (files && files.length > 0) {
17537 const filesArray = Array.from(files);
17538 handleUpload({
17539 allowedTypes,
17540 filesList: filesArray
17541 });
17542 }
17543 },
17544 [allowedTypes, handleUpload]
17545 );
17546 const paginationInfo = (0, import_element58.useMemo)(
17547 () => ({
17548 totalItems,
17549 totalPages
17550 }),
17551 [totalItems, totalPages]
17552 );
17553 const defaultLayouts = (0, import_element58.useMemo)(
17554 () => ({
17555 [LAYOUT_PICKER_GRID2]: {
17556 fields: [],
17557 showTitle: false
17558 },
17559 [LAYOUT_PICKER_TABLE2]: {
17560 fields: [
17561 "filename",
17562 "filesize",
17563 "media_dimensions",
17564 "author",
17565 "date"
17566 ],
17567 showTitle: true
17568 }
17569 }),
17570 []
17571 );
17572 const acceptTypes = (0, import_element58.useMemo)(() => {
17573 if (allowedTypes.includes("*")) {
17574 return void 0;
17575 }
17576 return allowedTypes.join(",");
17577 }, [allowedTypes]);
17578 if (!isOpen) {
17579 return null;
17580 }
17581 return /* @__PURE__ */ (0, import_jsx_runtime105.jsxs)(
17582 import_components52.Modal,
17583 {
17584 title,
17585 onRequestClose: handleModalClose,
17586 isDismissible,
17587 className: modalClass,
17588 overlayClassName: "media-upload-modal",
17589 size: "fill",
17590 headerActions: /* @__PURE__ */ (0, import_jsx_runtime105.jsx)(
17591 import_components52.FormFileUpload,
17592 {
17593 accept: acceptTypes,
17594 multiple: true,
17595 onChange: handleFileSelect,
17596 __next40pxDefaultSize: true,
17597 render: ({ openFileDialog }) => /* @__PURE__ */ (0, import_jsx_runtime105.jsx)(
17598 import_components52.Button,
17599 {
17600 onClick: openFileDialog,
17601 icon: upload_default,
17602 __next40pxDefaultSize: true,
17603 children: (0, import_i18n64.__)("Upload media")
17604 }
17605 )
17606 }
17607 ),
17608 children: [
17609 /* @__PURE__ */ (0, import_jsx_runtime105.jsx)(
17610 import_components52.DropZone,
17611 {
17612 onFilesDrop: (files) => {
17613 let filteredFiles = files;
17614 if (allowedTypes && !allowedTypes.includes("*")) {
17615 filteredFiles = files.filter(
17616 (file) => allowedTypes.some((allowedType) => {
17617 return file.type === allowedType || file.type.startsWith(
17618 allowedType.replace("*", "")
17619 );
17620 })
17621 );
17622 }
17623 if (filteredFiles.length > 0) {
17624 handleUpload({
17625 allowedTypes,
17626 filesList: filteredFiles
17627 });
17628 }
17629 },
17630 label: (0, import_i18n64.__)("Drop files to upload")
17631 }
17632 ),
17633 /* @__PURE__ */ (0, import_jsx_runtime105.jsx)(
17634 dataviews_picker_default,
17635 {
17636 data: mediaRecords || [],
17637 fields,
17638 view,
17639 onChangeView: setView,
17640 actions,
17641 selection,
17642 onChangeSelection: setSelection,
17643 isLoading,
17644 paginationInfo,
17645 defaultLayouts,
17646 getItemId: (item) => String(item.id),
17647 search,
17648 searchLabel,
17649 itemListLabel: (0, import_i18n64.__)("Media items")
17650 }
17651 )
17652 ]
17653 }
17654 );
17655 }
17656
17657 // packages/media-utils/build-module/private-apis.mjs
17658 var privateApis11 = {};
17659 lock2(privateApis11, {
17660 sideloadMedia,
17661 MediaUploadModal
17662 });
17663 return __toCommonJS(index_exports);
17664 })();
17665 /*! Bundled license information:
17666
17667 use-sync-external-store/cjs/use-sync-external-store-shim.development.js:
17668 (**
17669 * @license React
17670 * use-sync-external-store-shim.development.js
17671 *
17672 * Copyright (c) Meta Platforms, Inc. and affiliates.
17673 *
17674 * This source code is licensed under the MIT license found in the
17675 * LICENSE file in the root directory of this source tree.
17676 *)
17677 */
17678 //# sourceMappingURL=index.js.map
17679