@mattisvensson/strapi-plugin-webatlas 0.11.6 → 0.11.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4275 +0,0 @@
1
- import * as React from "react";
2
- import { useRef, useEffect, useState, useCallback, createContext, useMemo, createElement, useContext, Fragment, forwardRef, Children, isValidElement, cloneElement, useLayoutEffect, useReducer } from "react";
3
- import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
4
- import { Link, List, Information } from "@strapi/icons";
5
- import { useFetchClient, unstable_useContentManagerContext, useRBAC } from "@strapi/strapi/admin";
6
- import { Box, Typography, Flex, Checkbox, Field, SingleSelect, SingleSelectOption, Divider } from "@strapi/design-system";
7
- import { useIntl } from "react-intl";
8
- import * as ReactDOM from "react-dom";
9
- import ReactDOM__default, { flushSync } from "react-dom";
10
- const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
11
- const v = glob[path];
12
- if (v) {
13
- return typeof v === "function" ? v() : Promise.resolve(v);
14
- }
15
- return new Promise((_, reject) => {
16
- (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
17
- reject.bind(
18
- null,
19
- new Error(
20
- "Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
21
- )
22
- )
23
- );
24
- });
25
- };
26
- function transformToUrl(input, replaceSlash = true) {
27
- const specialCharMap = {
28
- ü: "ue",
29
- ä: "ae",
30
- ö: "oe",
31
- ß: "ss"
32
- };
33
- if (!input || typeof input !== "string") return "";
34
- input = input.toLowerCase();
35
- input = input.replace(/\/+/g, "/");
36
- input = input.startsWith("/") ? input.slice(1) : input;
37
- input = input.endsWith("/") ? input.slice(0, -1) : input;
38
- if (replaceSlash) {
39
- input = input.replace(/\//g, "-");
40
- } else {
41
- input = input.replace(/\/+/g, "/");
42
- input = input.startsWith("/") ? input.slice(1) : input;
43
- input = input.endsWith("/") ? input.slice(0, -1) : input;
44
- }
45
- for (const char in specialCharMap) {
46
- const regex = new RegExp(char, "g");
47
- input = input.replace(regex, specialCharMap[char]);
48
- }
49
- input = input.trim();
50
- input = input.replace(/\s+/g, "-");
51
- input = input.replace(/[^A-Za-z0-9$\-_.+!*'()/]/g, "");
52
- input = input.replace(/-+/g, "-");
53
- return input;
54
- }
55
- const version = "0.11.5";
56
- const strapi$1 = { "name": "webatlas", "displayName": "Webatlas" };
57
- const pluginPkg = {
58
- version,
59
- strapi: strapi$1
60
- };
61
- const PLUGIN_ID = pluginPkg.strapi.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i, "") || "webatlas";
62
- const PLUGIN_NAME = pluginPkg.strapi.displayName;
63
- const PLUGIN_VERSION = pluginPkg.version;
64
- const Initializer = ({ setPlugin }) => {
65
- const ref = useRef(setPlugin);
66
- useEffect(() => {
67
- ref.current(PLUGIN_ID);
68
- }, []);
69
- return null;
70
- };
71
- const PathIcon = () => /* @__PURE__ */ jsx(Link, {});
72
- const NavigationIcon = () => /* @__PURE__ */ jsx(List, {});
73
- function useApi() {
74
- const { get, put, del, post } = useFetchClient();
75
- const fetchAllContentTypes = async () => {
76
- try {
77
- const { data } = await get("/content-manager/content-types");
78
- return data.data;
79
- } catch (error) {
80
- strapi.log.error("Cannot fetch all content types:", error);
81
- return [];
82
- }
83
- };
84
- const fetchConfiguredContentTypes = async () => {
85
- try {
86
- const { data: config } = await get(`/${PLUGIN_ID}/config`);
87
- const configuredTypes = config?.selectedContentTypes || [];
88
- if (configuredTypes.length === 0) {
89
- return [];
90
- }
91
- const allContentTypes = await fetchAllContentTypes();
92
- const configuredUIDs = new Set(configuredTypes.map((ct) => ct.uid));
93
- return allContentTypes.filter((ct) => configuredUIDs.has(ct.uid));
94
- } catch (err) {
95
- strapi.log.error("Error fetching configured content types:", err);
96
- return [];
97
- }
98
- };
99
- const fetchAllEntities = async () => {
100
- try {
101
- const { data } = await get(`/${PLUGIN_ID}/config`);
102
- const contentTypes = data?.selectedContentTypes || [];
103
- if (!contentTypes || contentTypes.length === 0) {
104
- return [];
105
- }
106
- let entities = [];
107
- const entityResults = await Promise.allSettled(
108
- contentTypes.map(async (contentType) => {
109
- try {
110
- const { data: data2 } = await get(
111
- `/content-manager/collection-types/${contentType.uid}?pageSize=9999`
112
- );
113
- if (!data2 || !data2.results) {
114
- return null;
115
- }
116
- return {
117
- entities: data2.results,
118
- contentType
119
- };
120
- } catch (err) {
121
- strapi.log.error(`Cannot access entities for ${contentType.uid}:`, err);
122
- return null;
123
- }
124
- })
125
- );
126
- entities = entityResults.map((result) => result.status === "fulfilled" ? result.value : null).filter(Boolean);
127
- return entities;
128
- } catch (err) {
129
- strapi.log.error("Error fetching entities:", err);
130
- throw err;
131
- }
132
- };
133
- const getRelatedRoute = async (relatedDocumentId) => {
134
- const { data } = await get(`/${PLUGIN_ID}/route/related?documentId=${relatedDocumentId}`);
135
- return data;
136
- };
137
- const getRoute = async (documentId) => {
138
- const { data } = await get(`/${PLUGIN_ID}/route/${documentId}`);
139
- return data;
140
- };
141
- const getAllRoutes = async () => {
142
- const { data } = await get(`/${PLUGIN_ID}/route`);
143
- return data;
144
- };
145
- const getProhibitedRouteIds = async (documentId) => {
146
- const { data } = await get(
147
- `/${PLUGIN_ID}/route/prohibitedIds/${documentId ? `${documentId}` : ""}`
148
- );
149
- return data;
150
- };
151
- const getNavigation = async ({
152
- documentId,
153
- variant
154
- } = {}) => {
155
- const query = [];
156
- if (documentId) query.push(`documentId=${documentId}`);
157
- if (variant) query.push(`variant=${variant}`);
158
- const { data } = await get(
159
- `/${PLUGIN_ID}/navigation${query.length > 0 ? `?${query.join("&")}` : ""}`
160
- );
161
- return data;
162
- };
163
- const createNavigation = async (body) => {
164
- const { data } = await post(`/${PLUGIN_ID}/navigation`, {
165
- data: body
166
- });
167
- return data;
168
- };
169
- const deleteNavigation = async (documentId) => {
170
- const { data } = await del(`/${PLUGIN_ID}/navigation?documentId=${documentId}`);
171
- return data;
172
- };
173
- const updateNavigation = async (documentId, body) => {
174
- const { data } = await put(`/${PLUGIN_ID}/navigation?documentId=${documentId}`, {
175
- data: body
176
- });
177
- return data;
178
- };
179
- const updateNavigationItemStructure = async (documentId, navigationItems) => {
180
- const { data } = await put(`/${PLUGIN_ID}/navigation/items`, {
181
- navigationId: documentId,
182
- navigationItems
183
- });
184
- return data;
185
- };
186
- return {
187
- fetchAllContentTypes,
188
- fetchConfiguredContentTypes,
189
- fetchAllEntities,
190
- getRelatedRoute,
191
- getRoute,
192
- getAllRoutes,
193
- getProhibitedRouteIds,
194
- getNavigation,
195
- createNavigation,
196
- deleteNavigation,
197
- updateNavigation,
198
- updateNavigationItemStructure
199
- };
200
- }
201
- const useAllContentTypes = () => {
202
- const { fetchAllContentTypes } = useApi();
203
- const [contentTypes, setContentTypes] = useState([]);
204
- const [loading, setLoading] = useState(true);
205
- const [error, setError] = useState(null);
206
- useEffect(() => {
207
- const fetchEntities = async () => {
208
- try {
209
- const result = await fetchAllContentTypes();
210
- setContentTypes(result);
211
- setLoading(false);
212
- } catch (err) {
213
- setError(err);
214
- setLoading(false);
215
- }
216
- };
217
- fetchEntities();
218
- }, []);
219
- return { contentTypes, loading, error };
220
- };
221
- function usePluginConfig() {
222
- const { put, get } = useFetchClient();
223
- const [config, setConfigData] = useState(null);
224
- const [loading, setLoading] = useState(true);
225
- const [fetchError, setFetchError] = useState(null);
226
- useEffect(() => {
227
- const fetchData = async () => {
228
- setLoading(true);
229
- setFetchError(null);
230
- try {
231
- const {
232
- data: { data: contentTypesArray }
233
- } = await get("/content-manager/content-types");
234
- let { data: config2 } = await get(`/${PLUGIN_ID}/config`);
235
- if (!config2 || !config2.selectedContentTypes) {
236
- throw new Error(`Couldn't fetch plugin config`);
237
- }
238
- const allowedContentTypes = contentTypesArray.filter(
239
- (type) => type.pluginOptions?.webatlas?.enabled === true
240
- );
241
- const contentTypeUids = new Set(allowedContentTypes.map((type) => type.uid));
242
- const activeContentTypes = config2.selectedContentTypes.filter(
243
- (type) => contentTypeUids.has(type.uid)
244
- );
245
- const displayConfig = {
246
- ...config2,
247
- selectedContentTypes: activeContentTypes
248
- };
249
- setConfigData(displayConfig);
250
- } catch (error) {
251
- setFetchError(error.message);
252
- } finally {
253
- setLoading(false);
254
- }
255
- };
256
- fetchData();
257
- }, []);
258
- async function setConfig(body) {
259
- try {
260
- await put(`/${PLUGIN_ID}/config`, { ...body });
261
- } catch (error) {
262
- throw error;
263
- }
264
- }
265
- return { config, loading, fetchError, setConfig };
266
- }
267
- function debounce(func, wait) {
268
- let timeout;
269
- return function executedFunction(...args) {
270
- const later = () => {
271
- clearTimeout(timeout);
272
- func(...args);
273
- };
274
- clearTimeout(timeout);
275
- timeout = setTimeout(later, wait);
276
- };
277
- }
278
- async function duplicateCheck({
279
- fetchFunction,
280
- path,
281
- routeDocumentId,
282
- withoutTransform = false
283
- }) {
284
- if (!path) throw new Error("URL is required");
285
- try {
286
- const pathToCheck = withoutTransform ? path : transformToUrl(path);
287
- const { data } = await fetchFunction(
288
- `/${PLUGIN_ID}/checkUniquePath?path=${pathToCheck}${routeDocumentId ? `&targetRouteDocumentId=${routeDocumentId}` : ""}`
289
- );
290
- if (!data.uniquePath) {
291
- throw new Error("Network response was not ok");
292
- }
293
- return data.uniquePath;
294
- } catch (err) {
295
- throw new Error("Failed to check URL uniqueness: " + err.message);
296
- }
297
- }
298
- const getTranslation = (id) => `${PLUGIN_ID}.${id}`;
299
- function PathInfo({ validationState, replacement }) {
300
- const [color, setColor] = useState("neutral800");
301
- const [text, setText] = useState(null);
302
- const { formatMessage } = useIntl();
303
- useEffect(() => {
304
- if (validationState === "initial") return;
305
- if (validationState === "checking") {
306
- setColor("neutral800");
307
- setText(
308
- formatMessage({
309
- id: getTranslation("components.pathInfo.checking"),
310
- defaultMessage: "Checking if path is available..."
311
- })
312
- );
313
- } else if (validationState === "done") {
314
- setColor(replacement ? "danger500" : "success500");
315
- setText(
316
- replacement ? `${formatMessage({
317
- id: getTranslation("components.pathInfo.notAvailable"),
318
- defaultMessage: "Path is not available. Replaced with"
319
- })} "${replacement}".` : formatMessage({
320
- id: getTranslation("components.pathInfo.available"),
321
- defaultMessage: "Path is available."
322
- })
323
- );
324
- }
325
- }, [validationState, replacement, formatMessage]);
326
- return /* @__PURE__ */ jsx(Box, { paddingTop: 1, children: /* @__PURE__ */ jsx(Typography, { textColor: color, children: text }) });
327
- }
328
- function OverrideCheckbox({ isOverride, setIsOverride, disabledCondition }) {
329
- const { formatMessage } = useIntl();
330
- return /* @__PURE__ */ jsx(Flex, { gap: 2, paddingTop: 2, children: /* @__PURE__ */ jsx(
331
- Checkbox,
332
- {
333
- id: "path-override-checkbox",
334
- checked: isOverride,
335
- onCheckedChange: () => setIsOverride(!isOverride),
336
- disabled: disabledCondition,
337
- children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage({
338
- id: getTranslation("components.CMEditViewAside.path.overrideCheckbox"),
339
- defaultMessage: "Override automatic path generation"
340
- }) })
341
- }
342
- ) });
343
- }
344
- function NewPathInfo() {
345
- const { formatMessage } = useIntl();
346
- return /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage({
347
- id: getTranslation("components.CMEditViewAside.path.newPathInfo"),
348
- defaultMessage: "A new path will be created upon saving this entry."
349
- }) });
350
- }
351
- function UidPathDisplay({ path }) {
352
- const { formatMessage } = useIntl();
353
- return /* @__PURE__ */ jsxs(
354
- Field.Root,
355
- {
356
- hint: formatMessage({
357
- id: getTranslation("components.CMEditViewAside.path.uidPath.hint"),
358
- defaultMessage: "Permanent UID path, cannot be changed"
359
- }),
360
- children: [
361
- /* @__PURE__ */ jsx(Field.Input, { value: path, disabled: true }),
362
- /* @__PURE__ */ jsx(Field.Hint, {})
363
- ]
364
- }
365
- );
366
- }
367
- function _extends() {
368
- return _extends = Object.assign ? Object.assign.bind() : function(n) {
369
- for (var e = 1; e < arguments.length; e++) {
370
- var t = arguments[e];
371
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
372
- }
373
- return n;
374
- }, _extends.apply(null, arguments);
375
- }
376
- function $e42e1063c40fb3ef$export$b9ecd428b558ff10(originalEventHandler, ourEventHandler, { checkForDefaultPrevented = true } = {}) {
377
- return function handleEvent(event) {
378
- originalEventHandler === null || originalEventHandler === void 0 || originalEventHandler(event);
379
- if (checkForDefaultPrevented === false || !event.defaultPrevented) return ourEventHandler === null || ourEventHandler === void 0 ? void 0 : ourEventHandler(event);
380
- };
381
- }
382
- function $6ed0406888f73fc4$var$setRef(ref, value) {
383
- if (typeof ref === "function") ref(value);
384
- else if (ref !== null && ref !== void 0) ref.current = value;
385
- }
386
- function $6ed0406888f73fc4$export$43e446d32b3d21af(...refs) {
387
- return (node) => refs.forEach(
388
- (ref) => $6ed0406888f73fc4$var$setRef(ref, node)
389
- );
390
- }
391
- function $6ed0406888f73fc4$export$c7b2cbe3552a0d05(...refs) {
392
- return useCallback($6ed0406888f73fc4$export$43e446d32b3d21af(...refs), refs);
393
- }
394
- function $c512c27ab02ef895$export$50c7b4e9d9f19c1(scopeName, createContextScopeDeps = []) {
395
- let defaultContexts = [];
396
- function $c512c27ab02ef895$export$fd42f52fd3ae1109(rootComponentName, defaultContext) {
397
- const BaseContext = /* @__PURE__ */ createContext(defaultContext);
398
- const index2 = defaultContexts.length;
399
- defaultContexts = [
400
- ...defaultContexts,
401
- defaultContext
402
- ];
403
- function Provider(props) {
404
- const { scope, children, ...context } = props;
405
- const Context = (scope === null || scope === void 0 ? void 0 : scope[scopeName][index2]) || BaseContext;
406
- const value = useMemo(
407
- () => context,
408
- Object.values(context)
409
- );
410
- return /* @__PURE__ */ createElement(Context.Provider, {
411
- value
412
- }, children);
413
- }
414
- function useContext$1(consumerName, scope) {
415
- const Context = (scope === null || scope === void 0 ? void 0 : scope[scopeName][index2]) || BaseContext;
416
- const context = useContext(Context);
417
- if (context) return context;
418
- if (defaultContext !== void 0) return defaultContext;
419
- throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
420
- }
421
- Provider.displayName = rootComponentName + "Provider";
422
- return [
423
- Provider,
424
- useContext$1
425
- ];
426
- }
427
- const createScope = () => {
428
- const scopeContexts = defaultContexts.map((defaultContext) => {
429
- return /* @__PURE__ */ createContext(defaultContext);
430
- });
431
- return function useScope(scope) {
432
- const contexts = (scope === null || scope === void 0 ? void 0 : scope[scopeName]) || scopeContexts;
433
- return useMemo(
434
- () => ({
435
- [`__scope${scopeName}`]: {
436
- ...scope,
437
- [scopeName]: contexts
438
- }
439
- }),
440
- [
441
- scope,
442
- contexts
443
- ]
444
- );
445
- };
446
- };
447
- createScope.scopeName = scopeName;
448
- return [
449
- $c512c27ab02ef895$export$fd42f52fd3ae1109,
450
- $c512c27ab02ef895$var$composeContextScopes(createScope, ...createContextScopeDeps)
451
- ];
452
- }
453
- function $c512c27ab02ef895$var$composeContextScopes(...scopes) {
454
- const baseScope = scopes[0];
455
- if (scopes.length === 1) return baseScope;
456
- const createScope1 = () => {
457
- const scopeHooks = scopes.map(
458
- (createScope) => ({
459
- useScope: createScope(),
460
- scopeName: createScope.scopeName
461
- })
462
- );
463
- return function useComposedScopes(overrideScopes) {
464
- const nextScopes1 = scopeHooks.reduce((nextScopes, { useScope, scopeName }) => {
465
- const scopeProps = useScope(overrideScopes);
466
- const currentScope = scopeProps[`__scope${scopeName}`];
467
- return {
468
- ...nextScopes,
469
- ...currentScope
470
- };
471
- }, {});
472
- return useMemo(
473
- () => ({
474
- [`__scope${baseScope.scopeName}`]: nextScopes1
475
- }),
476
- [
477
- nextScopes1
478
- ]
479
- );
480
- };
481
- };
482
- createScope1.scopeName = baseScope.scopeName;
483
- return createScope1;
484
- }
485
- const $5e63c961fc1ce211$export$8c6ed5c666ac1360 = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
486
- const { children, ...slotProps } = props;
487
- const childrenArray = Children.toArray(children);
488
- const slottable = childrenArray.find($5e63c961fc1ce211$var$isSlottable);
489
- if (slottable) {
490
- const newElement = slottable.props.children;
491
- const newChildren = childrenArray.map((child) => {
492
- if (child === slottable) {
493
- if (Children.count(newElement) > 1) return Children.only(null);
494
- return /* @__PURE__ */ isValidElement(newElement) ? newElement.props.children : null;
495
- } else return child;
496
- });
497
- return /* @__PURE__ */ createElement($5e63c961fc1ce211$var$SlotClone, _extends({}, slotProps, {
498
- ref: forwardedRef
499
- }), /* @__PURE__ */ isValidElement(newElement) ? /* @__PURE__ */ cloneElement(newElement, void 0, newChildren) : null);
500
- }
501
- return /* @__PURE__ */ createElement($5e63c961fc1ce211$var$SlotClone, _extends({}, slotProps, {
502
- ref: forwardedRef
503
- }), children);
504
- });
505
- $5e63c961fc1ce211$export$8c6ed5c666ac1360.displayName = "Slot";
506
- const $5e63c961fc1ce211$var$SlotClone = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
507
- const { children, ...slotProps } = props;
508
- if (/* @__PURE__ */ isValidElement(children)) return /* @__PURE__ */ cloneElement(children, {
509
- ...$5e63c961fc1ce211$var$mergeProps(slotProps, children.props),
510
- ref: forwardedRef ? $6ed0406888f73fc4$export$43e446d32b3d21af(forwardedRef, children.ref) : children.ref
511
- });
512
- return Children.count(children) > 1 ? Children.only(null) : null;
513
- });
514
- $5e63c961fc1ce211$var$SlotClone.displayName = "SlotClone";
515
- const $5e63c961fc1ce211$export$d9f1ccf0bdb05d45 = ({ children }) => {
516
- return /* @__PURE__ */ createElement(Fragment, null, children);
517
- };
518
- function $5e63c961fc1ce211$var$isSlottable(child) {
519
- return /* @__PURE__ */ isValidElement(child) && child.type === $5e63c961fc1ce211$export$d9f1ccf0bdb05d45;
520
- }
521
- function $5e63c961fc1ce211$var$mergeProps(slotProps, childProps) {
522
- const overrideProps = {
523
- ...childProps
524
- };
525
- for (const propName in childProps) {
526
- const slotPropValue = slotProps[propName];
527
- const childPropValue = childProps[propName];
528
- const isHandler = /^on[A-Z]/.test(propName);
529
- if (isHandler) {
530
- if (slotPropValue && childPropValue) overrideProps[propName] = (...args) => {
531
- childPropValue(...args);
532
- slotPropValue(...args);
533
- };
534
- else if (slotPropValue) overrideProps[propName] = slotPropValue;
535
- } else if (propName === "style") overrideProps[propName] = {
536
- ...slotPropValue,
537
- ...childPropValue
538
- };
539
- else if (propName === "className") overrideProps[propName] = [
540
- slotPropValue,
541
- childPropValue
542
- ].filter(Boolean).join(" ");
543
- }
544
- return {
545
- ...slotProps,
546
- ...overrideProps
547
- };
548
- }
549
- const $8927f6f2acc4f386$var$NODES = [
550
- "a",
551
- "button",
552
- "div",
553
- "form",
554
- "h2",
555
- "h3",
556
- "img",
557
- "input",
558
- "label",
559
- "li",
560
- "nav",
561
- "ol",
562
- "p",
563
- "span",
564
- "svg",
565
- "ul"
566
- ];
567
- const $8927f6f2acc4f386$export$250ffa63cdc0d034 = $8927f6f2acc4f386$var$NODES.reduce((primitive, node) => {
568
- const Node2 = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
569
- const { asChild, ...primitiveProps } = props;
570
- const Comp = asChild ? $5e63c961fc1ce211$export$8c6ed5c666ac1360 : node;
571
- useEffect(() => {
572
- window[Symbol.for("radix-ui")] = true;
573
- }, []);
574
- return /* @__PURE__ */ createElement(Comp, _extends({}, primitiveProps, {
575
- ref: forwardedRef
576
- }));
577
- });
578
- Node2.displayName = `Primitive.${node}`;
579
- return {
580
- ...primitive,
581
- [node]: Node2
582
- };
583
- }, {});
584
- function $8927f6f2acc4f386$export$6d1a0317bde7de7f(target, event) {
585
- if (target) flushSync(
586
- () => target.dispatchEvent(event)
587
- );
588
- }
589
- function $b1b2314f5f9a1d84$export$25bec8c6f54ee79a(callback) {
590
- const callbackRef = useRef(callback);
591
- useEffect(() => {
592
- callbackRef.current = callback;
593
- });
594
- return useMemo(
595
- () => (...args) => {
596
- var _callbackRef$current;
597
- return (_callbackRef$current = callbackRef.current) === null || _callbackRef$current === void 0 ? void 0 : _callbackRef$current.call(callbackRef, ...args);
598
- },
599
- []
600
- );
601
- }
602
- function $addc16e1bbe58fd0$export$3a72a57244d6e765(onEscapeKeyDownProp, ownerDocument = globalThis === null || globalThis === void 0 ? void 0 : globalThis.document) {
603
- const onEscapeKeyDown = $b1b2314f5f9a1d84$export$25bec8c6f54ee79a(onEscapeKeyDownProp);
604
- useEffect(() => {
605
- const handleKeyDown = (event) => {
606
- if (event.key === "Escape") onEscapeKeyDown(event);
607
- };
608
- ownerDocument.addEventListener("keydown", handleKeyDown);
609
- return () => ownerDocument.removeEventListener("keydown", handleKeyDown);
610
- }, [
611
- onEscapeKeyDown,
612
- ownerDocument
613
- ]);
614
- }
615
- const $5cb92bef7577960e$var$CONTEXT_UPDATE = "dismissableLayer.update";
616
- const $5cb92bef7577960e$var$POINTER_DOWN_OUTSIDE = "dismissableLayer.pointerDownOutside";
617
- const $5cb92bef7577960e$var$FOCUS_OUTSIDE = "dismissableLayer.focusOutside";
618
- let $5cb92bef7577960e$var$originalBodyPointerEvents;
619
- const $5cb92bef7577960e$var$DismissableLayerContext = /* @__PURE__ */ createContext({
620
- layers: /* @__PURE__ */ new Set(),
621
- layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(),
622
- branches: /* @__PURE__ */ new Set()
623
- });
624
- const $5cb92bef7577960e$export$177fb62ff3ec1f22 = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
625
- var _node$ownerDocument;
626
- const { disableOutsidePointerEvents = false, onEscapeKeyDown, onPointerDownOutside, onFocusOutside, onInteractOutside, onDismiss, ...layerProps } = props;
627
- const context = useContext($5cb92bef7577960e$var$DismissableLayerContext);
628
- const [node1, setNode] = useState(null);
629
- const ownerDocument = (_node$ownerDocument = node1 === null || node1 === void 0 ? void 0 : node1.ownerDocument) !== null && _node$ownerDocument !== void 0 ? _node$ownerDocument : globalThis === null || globalThis === void 0 ? void 0 : globalThis.document;
630
- const [, force] = useState({});
631
- const composedRefs = $6ed0406888f73fc4$export$c7b2cbe3552a0d05(
632
- forwardedRef,
633
- (node) => setNode(node)
634
- );
635
- const layers = Array.from(context.layers);
636
- const [highestLayerWithOutsidePointerEventsDisabled] = [
637
- ...context.layersWithOutsidePointerEventsDisabled
638
- ].slice(-1);
639
- const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled);
640
- const index2 = node1 ? layers.indexOf(node1) : -1;
641
- const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;
642
- const isPointerEventsEnabled = index2 >= highestLayerWithOutsidePointerEventsDisabledIndex;
643
- const pointerDownOutside = $5cb92bef7577960e$var$usePointerDownOutside((event) => {
644
- const target = event.target;
645
- const isPointerDownOnBranch = [
646
- ...context.branches
647
- ].some(
648
- (branch) => branch.contains(target)
649
- );
650
- if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
651
- onPointerDownOutside === null || onPointerDownOutside === void 0 || onPointerDownOutside(event);
652
- onInteractOutside === null || onInteractOutside === void 0 || onInteractOutside(event);
653
- if (!event.defaultPrevented) onDismiss === null || onDismiss === void 0 || onDismiss();
654
- }, ownerDocument);
655
- const focusOutside = $5cb92bef7577960e$var$useFocusOutside((event) => {
656
- const target = event.target;
657
- const isFocusInBranch = [
658
- ...context.branches
659
- ].some(
660
- (branch) => branch.contains(target)
661
- );
662
- if (isFocusInBranch) return;
663
- onFocusOutside === null || onFocusOutside === void 0 || onFocusOutside(event);
664
- onInteractOutside === null || onInteractOutside === void 0 || onInteractOutside(event);
665
- if (!event.defaultPrevented) onDismiss === null || onDismiss === void 0 || onDismiss();
666
- }, ownerDocument);
667
- $addc16e1bbe58fd0$export$3a72a57244d6e765((event) => {
668
- const isHighestLayer = index2 === context.layers.size - 1;
669
- if (!isHighestLayer) return;
670
- onEscapeKeyDown === null || onEscapeKeyDown === void 0 || onEscapeKeyDown(event);
671
- if (!event.defaultPrevented && onDismiss) {
672
- event.preventDefault();
673
- onDismiss();
674
- }
675
- }, ownerDocument);
676
- useEffect(() => {
677
- if (!node1) return;
678
- if (disableOutsidePointerEvents) {
679
- if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
680
- $5cb92bef7577960e$var$originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;
681
- ownerDocument.body.style.pointerEvents = "none";
682
- }
683
- context.layersWithOutsidePointerEventsDisabled.add(node1);
684
- }
685
- context.layers.add(node1);
686
- $5cb92bef7577960e$var$dispatchUpdate();
687
- return () => {
688
- if (disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1) ownerDocument.body.style.pointerEvents = $5cb92bef7577960e$var$originalBodyPointerEvents;
689
- };
690
- }, [
691
- node1,
692
- ownerDocument,
693
- disableOutsidePointerEvents,
694
- context
695
- ]);
696
- useEffect(() => {
697
- return () => {
698
- if (!node1) return;
699
- context.layers.delete(node1);
700
- context.layersWithOutsidePointerEventsDisabled.delete(node1);
701
- $5cb92bef7577960e$var$dispatchUpdate();
702
- };
703
- }, [
704
- node1,
705
- context
706
- ]);
707
- useEffect(() => {
708
- const handleUpdate = () => force({});
709
- document.addEventListener($5cb92bef7577960e$var$CONTEXT_UPDATE, handleUpdate);
710
- return () => document.removeEventListener($5cb92bef7577960e$var$CONTEXT_UPDATE, handleUpdate);
711
- }, []);
712
- return /* @__PURE__ */ createElement($8927f6f2acc4f386$export$250ffa63cdc0d034.div, _extends({}, layerProps, {
713
- ref: composedRefs,
714
- style: {
715
- pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
716
- ...props.style
717
- },
718
- onFocusCapture: $e42e1063c40fb3ef$export$b9ecd428b558ff10(props.onFocusCapture, focusOutside.onFocusCapture),
719
- onBlurCapture: $e42e1063c40fb3ef$export$b9ecd428b558ff10(props.onBlurCapture, focusOutside.onBlurCapture),
720
- onPointerDownCapture: $e42e1063c40fb3ef$export$b9ecd428b558ff10(props.onPointerDownCapture, pointerDownOutside.onPointerDownCapture)
721
- }));
722
- });
723
- function $5cb92bef7577960e$var$usePointerDownOutside(onPointerDownOutside, ownerDocument = globalThis === null || globalThis === void 0 ? void 0 : globalThis.document) {
724
- const handlePointerDownOutside = $b1b2314f5f9a1d84$export$25bec8c6f54ee79a(onPointerDownOutside);
725
- const isPointerInsideReactTreeRef = useRef(false);
726
- const handleClickRef = useRef(() => {
727
- });
728
- useEffect(() => {
729
- const handlePointerDown = (event) => {
730
- if (event.target && !isPointerInsideReactTreeRef.current) {
731
- let handleAndDispatchPointerDownOutsideEvent = function() {
732
- $5cb92bef7577960e$var$handleAndDispatchCustomEvent($5cb92bef7577960e$var$POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail, {
733
- discrete: true
734
- });
735
- };
736
- const eventDetail = {
737
- originalEvent: event
738
- };
739
- if (event.pointerType === "touch") {
740
- ownerDocument.removeEventListener("click", handleClickRef.current);
741
- handleClickRef.current = handleAndDispatchPointerDownOutsideEvent;
742
- ownerDocument.addEventListener("click", handleClickRef.current, {
743
- once: true
744
- });
745
- } else handleAndDispatchPointerDownOutsideEvent();
746
- } else
747
- ownerDocument.removeEventListener("click", handleClickRef.current);
748
- isPointerInsideReactTreeRef.current = false;
749
- };
750
- const timerId = window.setTimeout(() => {
751
- ownerDocument.addEventListener("pointerdown", handlePointerDown);
752
- }, 0);
753
- return () => {
754
- window.clearTimeout(timerId);
755
- ownerDocument.removeEventListener("pointerdown", handlePointerDown);
756
- ownerDocument.removeEventListener("click", handleClickRef.current);
757
- };
758
- }, [
759
- ownerDocument,
760
- handlePointerDownOutside
761
- ]);
762
- return {
763
- // ensures we check React component tree (not just DOM tree)
764
- onPointerDownCapture: () => isPointerInsideReactTreeRef.current = true
765
- };
766
- }
767
- function $5cb92bef7577960e$var$useFocusOutside(onFocusOutside, ownerDocument = globalThis === null || globalThis === void 0 ? void 0 : globalThis.document) {
768
- const handleFocusOutside = $b1b2314f5f9a1d84$export$25bec8c6f54ee79a(onFocusOutside);
769
- const isFocusInsideReactTreeRef = useRef(false);
770
- useEffect(() => {
771
- const handleFocus = (event) => {
772
- if (event.target && !isFocusInsideReactTreeRef.current) {
773
- const eventDetail = {
774
- originalEvent: event
775
- };
776
- $5cb92bef7577960e$var$handleAndDispatchCustomEvent($5cb92bef7577960e$var$FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
777
- discrete: false
778
- });
779
- }
780
- };
781
- ownerDocument.addEventListener("focusin", handleFocus);
782
- return () => ownerDocument.removeEventListener("focusin", handleFocus);
783
- }, [
784
- ownerDocument,
785
- handleFocusOutside
786
- ]);
787
- return {
788
- onFocusCapture: () => isFocusInsideReactTreeRef.current = true,
789
- onBlurCapture: () => isFocusInsideReactTreeRef.current = false
790
- };
791
- }
792
- function $5cb92bef7577960e$var$dispatchUpdate() {
793
- const event = new CustomEvent($5cb92bef7577960e$var$CONTEXT_UPDATE);
794
- document.dispatchEvent(event);
795
- }
796
- function $5cb92bef7577960e$var$handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
797
- const target = detail.originalEvent.target;
798
- const event = new CustomEvent(name, {
799
- bubbles: false,
800
- cancelable: true,
801
- detail
802
- });
803
- if (handler) target.addEventListener(name, handler, {
804
- once: true
805
- });
806
- if (discrete) $8927f6f2acc4f386$export$6d1a0317bde7de7f(target, event);
807
- else target.dispatchEvent(event);
808
- }
809
- const $9f79659886946c16$export$e5c5a5f917a5871c = Boolean(globalThis === null || globalThis === void 0 ? void 0 : globalThis.document) ? useLayoutEffect : () => {
810
- };
811
- const $1746a345f3d73bb7$var$useReactId = React["useId".toString()] || (() => void 0);
812
- let $1746a345f3d73bb7$var$count = 0;
813
- function $1746a345f3d73bb7$export$f680877a34711e37(deterministicId) {
814
- const [id, setId] = React.useState($1746a345f3d73bb7$var$useReactId());
815
- $9f79659886946c16$export$e5c5a5f917a5871c(() => {
816
- setId(
817
- (reactId) => reactId !== null && reactId !== void 0 ? reactId : String($1746a345f3d73bb7$var$count++)
818
- );
819
- }, [
820
- deterministicId
821
- ]);
822
- return id ? `radix-${id}` : "";
823
- }
824
- const sides = ["top", "right", "bottom", "left"];
825
- const min = Math.min;
826
- const max = Math.max;
827
- const round = Math.round;
828
- const floor = Math.floor;
829
- const createCoords = (v) => ({
830
- x: v,
831
- y: v
832
- });
833
- const oppositeSideMap = {
834
- left: "right",
835
- right: "left",
836
- bottom: "top",
837
- top: "bottom"
838
- };
839
- const oppositeAlignmentMap = {
840
- start: "end",
841
- end: "start"
842
- };
843
- function clamp(start, value, end) {
844
- return max(start, min(value, end));
845
- }
846
- function evaluate(value, param) {
847
- return typeof value === "function" ? value(param) : value;
848
- }
849
- function getSide(placement) {
850
- return placement.split("-")[0];
851
- }
852
- function getAlignment(placement) {
853
- return placement.split("-")[1];
854
- }
855
- function getOppositeAxis(axis) {
856
- return axis === "x" ? "y" : "x";
857
- }
858
- function getAxisLength(axis) {
859
- return axis === "y" ? "height" : "width";
860
- }
861
- function getSideAxis(placement) {
862
- return ["top", "bottom"].includes(getSide(placement)) ? "y" : "x";
863
- }
864
- function getAlignmentAxis(placement) {
865
- return getOppositeAxis(getSideAxis(placement));
866
- }
867
- function getAlignmentSides(placement, rects, rtl) {
868
- if (rtl === void 0) {
869
- rtl = false;
870
- }
871
- const alignment = getAlignment(placement);
872
- const alignmentAxis = getAlignmentAxis(placement);
873
- const length = getAxisLength(alignmentAxis);
874
- let mainAlignmentSide = alignmentAxis === "x" ? alignment === (rtl ? "end" : "start") ? "right" : "left" : alignment === "start" ? "bottom" : "top";
875
- if (rects.reference[length] > rects.floating[length]) {
876
- mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
877
- }
878
- return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
879
- }
880
- function getExpandedPlacements(placement) {
881
- const oppositePlacement = getOppositePlacement(placement);
882
- return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
883
- }
884
- function getOppositeAlignmentPlacement(placement) {
885
- return placement.replace(/start|end/g, (alignment) => oppositeAlignmentMap[alignment]);
886
- }
887
- function getSideList(side, isStart, rtl) {
888
- const lr = ["left", "right"];
889
- const rl = ["right", "left"];
890
- const tb = ["top", "bottom"];
891
- const bt = ["bottom", "top"];
892
- switch (side) {
893
- case "top":
894
- case "bottom":
895
- if (rtl) return isStart ? rl : lr;
896
- return isStart ? lr : rl;
897
- case "left":
898
- case "right":
899
- return isStart ? tb : bt;
900
- default:
901
- return [];
902
- }
903
- }
904
- function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
905
- const alignment = getAlignment(placement);
906
- let list = getSideList(getSide(placement), direction === "start", rtl);
907
- if (alignment) {
908
- list = list.map((side) => side + "-" + alignment);
909
- if (flipAlignment) {
910
- list = list.concat(list.map(getOppositeAlignmentPlacement));
911
- }
912
- }
913
- return list;
914
- }
915
- function getOppositePlacement(placement) {
916
- return placement.replace(/left|right|bottom|top/g, (side) => oppositeSideMap[side]);
917
- }
918
- function expandPaddingObject(padding) {
919
- return {
920
- top: 0,
921
- right: 0,
922
- bottom: 0,
923
- left: 0,
924
- ...padding
925
- };
926
- }
927
- function getPaddingObject(padding) {
928
- return typeof padding !== "number" ? expandPaddingObject(padding) : {
929
- top: padding,
930
- right: padding,
931
- bottom: padding,
932
- left: padding
933
- };
934
- }
935
- function rectToClientRect(rect) {
936
- const {
937
- x,
938
- y,
939
- width,
940
- height
941
- } = rect;
942
- return {
943
- width,
944
- height,
945
- top: y,
946
- left: x,
947
- right: x + width,
948
- bottom: y + height,
949
- x,
950
- y
951
- };
952
- }
953
- function computeCoordsFromPlacement(_ref, placement, rtl) {
954
- let {
955
- reference,
956
- floating
957
- } = _ref;
958
- const sideAxis = getSideAxis(placement);
959
- const alignmentAxis = getAlignmentAxis(placement);
960
- const alignLength = getAxisLength(alignmentAxis);
961
- const side = getSide(placement);
962
- const isVertical = sideAxis === "y";
963
- const commonX = reference.x + reference.width / 2 - floating.width / 2;
964
- const commonY = reference.y + reference.height / 2 - floating.height / 2;
965
- const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
966
- let coords;
967
- switch (side) {
968
- case "top":
969
- coords = {
970
- x: commonX,
971
- y: reference.y - floating.height
972
- };
973
- break;
974
- case "bottom":
975
- coords = {
976
- x: commonX,
977
- y: reference.y + reference.height
978
- };
979
- break;
980
- case "right":
981
- coords = {
982
- x: reference.x + reference.width,
983
- y: commonY
984
- };
985
- break;
986
- case "left":
987
- coords = {
988
- x: reference.x - floating.width,
989
- y: commonY
990
- };
991
- break;
992
- default:
993
- coords = {
994
- x: reference.x,
995
- y: reference.y
996
- };
997
- }
998
- switch (getAlignment(placement)) {
999
- case "start":
1000
- coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
1001
- break;
1002
- case "end":
1003
- coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
1004
- break;
1005
- }
1006
- return coords;
1007
- }
1008
- const computePosition$1 = async (reference, floating, config) => {
1009
- const {
1010
- placement = "bottom",
1011
- strategy = "absolute",
1012
- middleware = [],
1013
- platform: platform2
1014
- } = config;
1015
- const validMiddleware = middleware.filter(Boolean);
1016
- const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(floating));
1017
- let rects = await platform2.getElementRects({
1018
- reference,
1019
- floating,
1020
- strategy
1021
- });
1022
- let {
1023
- x,
1024
- y
1025
- } = computeCoordsFromPlacement(rects, placement, rtl);
1026
- let statefulPlacement = placement;
1027
- let middlewareData = {};
1028
- let resetCount = 0;
1029
- for (let i = 0; i < validMiddleware.length; i++) {
1030
- const {
1031
- name,
1032
- fn
1033
- } = validMiddleware[i];
1034
- const {
1035
- x: nextX,
1036
- y: nextY,
1037
- data,
1038
- reset
1039
- } = await fn({
1040
- x,
1041
- y,
1042
- initialPlacement: placement,
1043
- placement: statefulPlacement,
1044
- strategy,
1045
- middlewareData,
1046
- rects,
1047
- platform: platform2,
1048
- elements: {
1049
- reference,
1050
- floating
1051
- }
1052
- });
1053
- x = nextX != null ? nextX : x;
1054
- y = nextY != null ? nextY : y;
1055
- middlewareData = {
1056
- ...middlewareData,
1057
- [name]: {
1058
- ...middlewareData[name],
1059
- ...data
1060
- }
1061
- };
1062
- if (reset && resetCount <= 50) {
1063
- resetCount++;
1064
- if (typeof reset === "object") {
1065
- if (reset.placement) {
1066
- statefulPlacement = reset.placement;
1067
- }
1068
- if (reset.rects) {
1069
- rects = reset.rects === true ? await platform2.getElementRects({
1070
- reference,
1071
- floating,
1072
- strategy
1073
- }) : reset.rects;
1074
- }
1075
- ({
1076
- x,
1077
- y
1078
- } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
1079
- }
1080
- i = -1;
1081
- }
1082
- }
1083
- return {
1084
- x,
1085
- y,
1086
- placement: statefulPlacement,
1087
- strategy,
1088
- middlewareData
1089
- };
1090
- };
1091
- async function detectOverflow(state, options) {
1092
- var _await$platform$isEle;
1093
- if (options === void 0) {
1094
- options = {};
1095
- }
1096
- const {
1097
- x,
1098
- y,
1099
- platform: platform2,
1100
- rects,
1101
- elements,
1102
- strategy
1103
- } = state;
1104
- const {
1105
- boundary = "clippingAncestors",
1106
- rootBoundary = "viewport",
1107
- elementContext = "floating",
1108
- altBoundary = false,
1109
- padding = 0
1110
- } = evaluate(options, state);
1111
- const paddingObject = getPaddingObject(padding);
1112
- const altContext = elementContext === "floating" ? "reference" : "floating";
1113
- const element = elements[altBoundary ? altContext : elementContext];
1114
- const clippingClientRect = rectToClientRect(await platform2.getClippingRect({
1115
- element: ((_await$platform$isEle = await (platform2.isElement == null ? void 0 : platform2.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || await (platform2.getDocumentElement == null ? void 0 : platform2.getDocumentElement(elements.floating)),
1116
- boundary,
1117
- rootBoundary,
1118
- strategy
1119
- }));
1120
- const rect = elementContext === "floating" ? {
1121
- x,
1122
- y,
1123
- width: rects.floating.width,
1124
- height: rects.floating.height
1125
- } : rects.reference;
1126
- const offsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(elements.floating));
1127
- const offsetScale = await (platform2.isElement == null ? void 0 : platform2.isElement(offsetParent)) ? await (platform2.getScale == null ? void 0 : platform2.getScale(offsetParent)) || {
1128
- x: 1,
1129
- y: 1
1130
- } : {
1131
- x: 1,
1132
- y: 1
1133
- };
1134
- const elementClientRect = rectToClientRect(platform2.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform2.convertOffsetParentRelativeRectToViewportRelativeRect({
1135
- elements,
1136
- rect,
1137
- offsetParent,
1138
- strategy
1139
- }) : rect);
1140
- return {
1141
- top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
1142
- bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
1143
- left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
1144
- right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
1145
- };
1146
- }
1147
- const arrow$3 = (options) => ({
1148
- name: "arrow",
1149
- options,
1150
- async fn(state) {
1151
- const {
1152
- x,
1153
- y,
1154
- placement,
1155
- rects,
1156
- platform: platform2,
1157
- elements,
1158
- middlewareData
1159
- } = state;
1160
- const {
1161
- element,
1162
- padding = 0
1163
- } = evaluate(options, state) || {};
1164
- if (element == null) {
1165
- return {};
1166
- }
1167
- const paddingObject = getPaddingObject(padding);
1168
- const coords = {
1169
- x,
1170
- y
1171
- };
1172
- const axis = getAlignmentAxis(placement);
1173
- const length = getAxisLength(axis);
1174
- const arrowDimensions = await platform2.getDimensions(element);
1175
- const isYAxis = axis === "y";
1176
- const minProp = isYAxis ? "top" : "left";
1177
- const maxProp = isYAxis ? "bottom" : "right";
1178
- const clientProp = isYAxis ? "clientHeight" : "clientWidth";
1179
- const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
1180
- const startDiff = coords[axis] - rects.reference[axis];
1181
- const arrowOffsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(element));
1182
- let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
1183
- if (!clientSize || !await (platform2.isElement == null ? void 0 : platform2.isElement(arrowOffsetParent))) {
1184
- clientSize = elements.floating[clientProp] || rects.floating[length];
1185
- }
1186
- const centerToReference = endDiff / 2 - startDiff / 2;
1187
- const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
1188
- const minPadding = min(paddingObject[minProp], largestPossiblePadding);
1189
- const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
1190
- const min$1 = minPadding;
1191
- const max2 = clientSize - arrowDimensions[length] - maxPadding;
1192
- const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
1193
- const offset2 = clamp(min$1, center, max2);
1194
- const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset2 && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
1195
- const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max2 : 0;
1196
- return {
1197
- [axis]: coords[axis] + alignmentOffset,
1198
- data: {
1199
- [axis]: offset2,
1200
- centerOffset: center - offset2 - alignmentOffset,
1201
- ...shouldAddOffset && {
1202
- alignmentOffset
1203
- }
1204
- },
1205
- reset: shouldAddOffset
1206
- };
1207
- }
1208
- });
1209
- const flip$2 = function(options) {
1210
- if (options === void 0) {
1211
- options = {};
1212
- }
1213
- return {
1214
- name: "flip",
1215
- options,
1216
- async fn(state) {
1217
- var _middlewareData$arrow, _middlewareData$flip;
1218
- const {
1219
- placement,
1220
- middlewareData,
1221
- rects,
1222
- initialPlacement,
1223
- platform: platform2,
1224
- elements
1225
- } = state;
1226
- const {
1227
- mainAxis: checkMainAxis = true,
1228
- crossAxis: checkCrossAxis = true,
1229
- fallbackPlacements: specifiedFallbackPlacements,
1230
- fallbackStrategy = "bestFit",
1231
- fallbackAxisSideDirection = "none",
1232
- flipAlignment = true,
1233
- ...detectOverflowOptions
1234
- } = evaluate(options, state);
1235
- if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
1236
- return {};
1237
- }
1238
- const side = getSide(placement);
1239
- const initialSideAxis = getSideAxis(initialPlacement);
1240
- const isBasePlacement = getSide(initialPlacement) === initialPlacement;
1241
- const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
1242
- const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
1243
- const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== "none";
1244
- if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
1245
- fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
1246
- }
1247
- const placements = [initialPlacement, ...fallbackPlacements];
1248
- const overflow = await detectOverflow(state, detectOverflowOptions);
1249
- const overflows = [];
1250
- let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
1251
- if (checkMainAxis) {
1252
- overflows.push(overflow[side]);
1253
- }
1254
- if (checkCrossAxis) {
1255
- const sides2 = getAlignmentSides(placement, rects, rtl);
1256
- overflows.push(overflow[sides2[0]], overflow[sides2[1]]);
1257
- }
1258
- overflowsData = [...overflowsData, {
1259
- placement,
1260
- overflows
1261
- }];
1262
- if (!overflows.every((side2) => side2 <= 0)) {
1263
- var _middlewareData$flip2, _overflowsData$filter;
1264
- const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
1265
- const nextPlacement = placements[nextIndex];
1266
- if (nextPlacement) {
1267
- return {
1268
- data: {
1269
- index: nextIndex,
1270
- overflows: overflowsData
1271
- },
1272
- reset: {
1273
- placement: nextPlacement
1274
- }
1275
- };
1276
- }
1277
- let resetPlacement = (_overflowsData$filter = overflowsData.filter((d) => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
1278
- if (!resetPlacement) {
1279
- switch (fallbackStrategy) {
1280
- case "bestFit": {
1281
- var _overflowsData$filter2;
1282
- const placement2 = (_overflowsData$filter2 = overflowsData.filter((d) => {
1283
- if (hasFallbackAxisSideDirection) {
1284
- const currentSideAxis = getSideAxis(d.placement);
1285
- return currentSideAxis === initialSideAxis || // Create a bias to the `y` side axis due to horizontal
1286
- // reading directions favoring greater width.
1287
- currentSideAxis === "y";
1288
- }
1289
- return true;
1290
- }).map((d) => [d.placement, d.overflows.filter((overflow2) => overflow2 > 0).reduce((acc, overflow2) => acc + overflow2, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$filter2[0];
1291
- if (placement2) {
1292
- resetPlacement = placement2;
1293
- }
1294
- break;
1295
- }
1296
- case "initialPlacement":
1297
- resetPlacement = initialPlacement;
1298
- break;
1299
- }
1300
- }
1301
- if (placement !== resetPlacement) {
1302
- return {
1303
- reset: {
1304
- placement: resetPlacement
1305
- }
1306
- };
1307
- }
1308
- }
1309
- return {};
1310
- }
1311
- };
1312
- };
1313
- function getSideOffsets(overflow, rect) {
1314
- return {
1315
- top: overflow.top - rect.height,
1316
- right: overflow.right - rect.width,
1317
- bottom: overflow.bottom - rect.height,
1318
- left: overflow.left - rect.width
1319
- };
1320
- }
1321
- function isAnySideFullyClipped(overflow) {
1322
- return sides.some((side) => overflow[side] >= 0);
1323
- }
1324
- const hide$2 = function(options) {
1325
- if (options === void 0) {
1326
- options = {};
1327
- }
1328
- return {
1329
- name: "hide",
1330
- options,
1331
- async fn(state) {
1332
- const {
1333
- rects
1334
- } = state;
1335
- const {
1336
- strategy = "referenceHidden",
1337
- ...detectOverflowOptions
1338
- } = evaluate(options, state);
1339
- switch (strategy) {
1340
- case "referenceHidden": {
1341
- const overflow = await detectOverflow(state, {
1342
- ...detectOverflowOptions,
1343
- elementContext: "reference"
1344
- });
1345
- const offsets = getSideOffsets(overflow, rects.reference);
1346
- return {
1347
- data: {
1348
- referenceHiddenOffsets: offsets,
1349
- referenceHidden: isAnySideFullyClipped(offsets)
1350
- }
1351
- };
1352
- }
1353
- case "escaped": {
1354
- const overflow = await detectOverflow(state, {
1355
- ...detectOverflowOptions,
1356
- altBoundary: true
1357
- });
1358
- const offsets = getSideOffsets(overflow, rects.floating);
1359
- return {
1360
- data: {
1361
- escapedOffsets: offsets,
1362
- escaped: isAnySideFullyClipped(offsets)
1363
- }
1364
- };
1365
- }
1366
- default: {
1367
- return {};
1368
- }
1369
- }
1370
- }
1371
- };
1372
- };
1373
- async function convertValueToCoords(state, options) {
1374
- const {
1375
- placement,
1376
- platform: platform2,
1377
- elements
1378
- } = state;
1379
- const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
1380
- const side = getSide(placement);
1381
- const alignment = getAlignment(placement);
1382
- const isVertical = getSideAxis(placement) === "y";
1383
- const mainAxisMulti = ["left", "top"].includes(side) ? -1 : 1;
1384
- const crossAxisMulti = rtl && isVertical ? -1 : 1;
1385
- const rawValue = evaluate(options, state);
1386
- let {
1387
- mainAxis,
1388
- crossAxis,
1389
- alignmentAxis
1390
- } = typeof rawValue === "number" ? {
1391
- mainAxis: rawValue,
1392
- crossAxis: 0,
1393
- alignmentAxis: null
1394
- } : {
1395
- mainAxis: rawValue.mainAxis || 0,
1396
- crossAxis: rawValue.crossAxis || 0,
1397
- alignmentAxis: rawValue.alignmentAxis
1398
- };
1399
- if (alignment && typeof alignmentAxis === "number") {
1400
- crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis;
1401
- }
1402
- return isVertical ? {
1403
- x: crossAxis * crossAxisMulti,
1404
- y: mainAxis * mainAxisMulti
1405
- } : {
1406
- x: mainAxis * mainAxisMulti,
1407
- y: crossAxis * crossAxisMulti
1408
- };
1409
- }
1410
- const offset$2 = function(options) {
1411
- if (options === void 0) {
1412
- options = 0;
1413
- }
1414
- return {
1415
- name: "offset",
1416
- options,
1417
- async fn(state) {
1418
- var _middlewareData$offse, _middlewareData$arrow;
1419
- const {
1420
- x,
1421
- y,
1422
- placement,
1423
- middlewareData
1424
- } = state;
1425
- const diffCoords = await convertValueToCoords(state, options);
1426
- if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
1427
- return {};
1428
- }
1429
- return {
1430
- x: x + diffCoords.x,
1431
- y: y + diffCoords.y,
1432
- data: {
1433
- ...diffCoords,
1434
- placement
1435
- }
1436
- };
1437
- }
1438
- };
1439
- };
1440
- const shift$2 = function(options) {
1441
- if (options === void 0) {
1442
- options = {};
1443
- }
1444
- return {
1445
- name: "shift",
1446
- options,
1447
- async fn(state) {
1448
- const {
1449
- x,
1450
- y,
1451
- placement
1452
- } = state;
1453
- const {
1454
- mainAxis: checkMainAxis = true,
1455
- crossAxis: checkCrossAxis = false,
1456
- limiter = {
1457
- fn: (_ref) => {
1458
- let {
1459
- x: x2,
1460
- y: y2
1461
- } = _ref;
1462
- return {
1463
- x: x2,
1464
- y: y2
1465
- };
1466
- }
1467
- },
1468
- ...detectOverflowOptions
1469
- } = evaluate(options, state);
1470
- const coords = {
1471
- x,
1472
- y
1473
- };
1474
- const overflow = await detectOverflow(state, detectOverflowOptions);
1475
- const crossAxis = getSideAxis(getSide(placement));
1476
- const mainAxis = getOppositeAxis(crossAxis);
1477
- let mainAxisCoord = coords[mainAxis];
1478
- let crossAxisCoord = coords[crossAxis];
1479
- if (checkMainAxis) {
1480
- const minSide = mainAxis === "y" ? "top" : "left";
1481
- const maxSide = mainAxis === "y" ? "bottom" : "right";
1482
- const min2 = mainAxisCoord + overflow[minSide];
1483
- const max2 = mainAxisCoord - overflow[maxSide];
1484
- mainAxisCoord = clamp(min2, mainAxisCoord, max2);
1485
- }
1486
- if (checkCrossAxis) {
1487
- const minSide = crossAxis === "y" ? "top" : "left";
1488
- const maxSide = crossAxis === "y" ? "bottom" : "right";
1489
- const min2 = crossAxisCoord + overflow[minSide];
1490
- const max2 = crossAxisCoord - overflow[maxSide];
1491
- crossAxisCoord = clamp(min2, crossAxisCoord, max2);
1492
- }
1493
- const limitedCoords = limiter.fn({
1494
- ...state,
1495
- [mainAxis]: mainAxisCoord,
1496
- [crossAxis]: crossAxisCoord
1497
- });
1498
- return {
1499
- ...limitedCoords,
1500
- data: {
1501
- x: limitedCoords.x - x,
1502
- y: limitedCoords.y - y,
1503
- enabled: {
1504
- [mainAxis]: checkMainAxis,
1505
- [crossAxis]: checkCrossAxis
1506
- }
1507
- }
1508
- };
1509
- }
1510
- };
1511
- };
1512
- const limitShift$2 = function(options) {
1513
- if (options === void 0) {
1514
- options = {};
1515
- }
1516
- return {
1517
- options,
1518
- fn(state) {
1519
- const {
1520
- x,
1521
- y,
1522
- placement,
1523
- rects,
1524
- middlewareData
1525
- } = state;
1526
- const {
1527
- offset: offset2 = 0,
1528
- mainAxis: checkMainAxis = true,
1529
- crossAxis: checkCrossAxis = true
1530
- } = evaluate(options, state);
1531
- const coords = {
1532
- x,
1533
- y
1534
- };
1535
- const crossAxis = getSideAxis(placement);
1536
- const mainAxis = getOppositeAxis(crossAxis);
1537
- let mainAxisCoord = coords[mainAxis];
1538
- let crossAxisCoord = coords[crossAxis];
1539
- const rawOffset = evaluate(offset2, state);
1540
- const computedOffset = typeof rawOffset === "number" ? {
1541
- mainAxis: rawOffset,
1542
- crossAxis: 0
1543
- } : {
1544
- mainAxis: 0,
1545
- crossAxis: 0,
1546
- ...rawOffset
1547
- };
1548
- if (checkMainAxis) {
1549
- const len = mainAxis === "y" ? "height" : "width";
1550
- const limitMin = rects.reference[mainAxis] - rects.floating[len] + computedOffset.mainAxis;
1551
- const limitMax = rects.reference[mainAxis] + rects.reference[len] - computedOffset.mainAxis;
1552
- if (mainAxisCoord < limitMin) {
1553
- mainAxisCoord = limitMin;
1554
- } else if (mainAxisCoord > limitMax) {
1555
- mainAxisCoord = limitMax;
1556
- }
1557
- }
1558
- if (checkCrossAxis) {
1559
- var _middlewareData$offse, _middlewareData$offse2;
1560
- const len = mainAxis === "y" ? "width" : "height";
1561
- const isOriginSide = ["top", "left"].includes(getSide(placement));
1562
- const limitMin = rects.reference[crossAxis] - rects.floating[len] + (isOriginSide ? ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse[crossAxis]) || 0 : 0) + (isOriginSide ? 0 : computedOffset.crossAxis);
1563
- const limitMax = rects.reference[crossAxis] + rects.reference[len] + (isOriginSide ? 0 : ((_middlewareData$offse2 = middlewareData.offset) == null ? void 0 : _middlewareData$offse2[crossAxis]) || 0) - (isOriginSide ? computedOffset.crossAxis : 0);
1564
- if (crossAxisCoord < limitMin) {
1565
- crossAxisCoord = limitMin;
1566
- } else if (crossAxisCoord > limitMax) {
1567
- crossAxisCoord = limitMax;
1568
- }
1569
- }
1570
- return {
1571
- [mainAxis]: mainAxisCoord,
1572
- [crossAxis]: crossAxisCoord
1573
- };
1574
- }
1575
- };
1576
- };
1577
- const size$2 = function(options) {
1578
- if (options === void 0) {
1579
- options = {};
1580
- }
1581
- return {
1582
- name: "size",
1583
- options,
1584
- async fn(state) {
1585
- var _state$middlewareData, _state$middlewareData2;
1586
- const {
1587
- placement,
1588
- rects,
1589
- platform: platform2,
1590
- elements
1591
- } = state;
1592
- const {
1593
- apply = () => {
1594
- },
1595
- ...detectOverflowOptions
1596
- } = evaluate(options, state);
1597
- const overflow = await detectOverflow(state, detectOverflowOptions);
1598
- const side = getSide(placement);
1599
- const alignment = getAlignment(placement);
1600
- const isYAxis = getSideAxis(placement) === "y";
1601
- const {
1602
- width,
1603
- height
1604
- } = rects.floating;
1605
- let heightSide;
1606
- let widthSide;
1607
- if (side === "top" || side === "bottom") {
1608
- heightSide = side;
1609
- widthSide = alignment === (await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating)) ? "start" : "end") ? "left" : "right";
1610
- } else {
1611
- widthSide = side;
1612
- heightSide = alignment === "end" ? "top" : "bottom";
1613
- }
1614
- const maximumClippingHeight = height - overflow.top - overflow.bottom;
1615
- const maximumClippingWidth = width - overflow.left - overflow.right;
1616
- const overflowAvailableHeight = min(height - overflow[heightSide], maximumClippingHeight);
1617
- const overflowAvailableWidth = min(width - overflow[widthSide], maximumClippingWidth);
1618
- const noShift = !state.middlewareData.shift;
1619
- let availableHeight = overflowAvailableHeight;
1620
- let availableWidth = overflowAvailableWidth;
1621
- if ((_state$middlewareData = state.middlewareData.shift) != null && _state$middlewareData.enabled.x) {
1622
- availableWidth = maximumClippingWidth;
1623
- }
1624
- if ((_state$middlewareData2 = state.middlewareData.shift) != null && _state$middlewareData2.enabled.y) {
1625
- availableHeight = maximumClippingHeight;
1626
- }
1627
- if (noShift && !alignment) {
1628
- const xMin = max(overflow.left, 0);
1629
- const xMax = max(overflow.right, 0);
1630
- const yMin = max(overflow.top, 0);
1631
- const yMax = max(overflow.bottom, 0);
1632
- if (isYAxis) {
1633
- availableWidth = width - 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max(overflow.left, overflow.right));
1634
- } else {
1635
- availableHeight = height - 2 * (yMin !== 0 || yMax !== 0 ? yMin + yMax : max(overflow.top, overflow.bottom));
1636
- }
1637
- }
1638
- await apply({
1639
- ...state,
1640
- availableWidth,
1641
- availableHeight
1642
- });
1643
- const nextDimensions = await platform2.getDimensions(elements.floating);
1644
- if (width !== nextDimensions.width || height !== nextDimensions.height) {
1645
- return {
1646
- reset: {
1647
- rects: true
1648
- }
1649
- };
1650
- }
1651
- return {};
1652
- }
1653
- };
1654
- };
1655
- function hasWindow() {
1656
- return typeof window !== "undefined";
1657
- }
1658
- function getNodeName(node) {
1659
- if (isNode(node)) {
1660
- return (node.nodeName || "").toLowerCase();
1661
- }
1662
- return "#document";
1663
- }
1664
- function getWindow(node) {
1665
- var _node$ownerDocument;
1666
- return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
1667
- }
1668
- function getDocumentElement(node) {
1669
- var _ref;
1670
- return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
1671
- }
1672
- function isNode(value) {
1673
- if (!hasWindow()) {
1674
- return false;
1675
- }
1676
- return value instanceof Node || value instanceof getWindow(value).Node;
1677
- }
1678
- function isElement(value) {
1679
- if (!hasWindow()) {
1680
- return false;
1681
- }
1682
- return value instanceof Element || value instanceof getWindow(value).Element;
1683
- }
1684
- function isHTMLElement(value) {
1685
- if (!hasWindow()) {
1686
- return false;
1687
- }
1688
- return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
1689
- }
1690
- function isShadowRoot(value) {
1691
- if (!hasWindow() || typeof ShadowRoot === "undefined") {
1692
- return false;
1693
- }
1694
- return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
1695
- }
1696
- function isOverflowElement(element) {
1697
- const {
1698
- overflow,
1699
- overflowX,
1700
- overflowY,
1701
- display
1702
- } = getComputedStyle$1(element);
1703
- return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !["inline", "contents"].includes(display);
1704
- }
1705
- function isTableElement(element) {
1706
- return ["table", "td", "th"].includes(getNodeName(element));
1707
- }
1708
- function isTopLayer(element) {
1709
- return [":popover-open", ":modal"].some((selector) => {
1710
- try {
1711
- return element.matches(selector);
1712
- } catch (e) {
1713
- return false;
1714
- }
1715
- });
1716
- }
1717
- function isContainingBlock(elementOrCss) {
1718
- const webkit = isWebKit();
1719
- const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss;
1720
- return css.transform !== "none" || css.perspective !== "none" || (css.containerType ? css.containerType !== "normal" : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== "none" : false) || !webkit && (css.filter ? css.filter !== "none" : false) || ["transform", "perspective", "filter"].some((value) => (css.willChange || "").includes(value)) || ["paint", "layout", "strict", "content"].some((value) => (css.contain || "").includes(value));
1721
- }
1722
- function getContainingBlock(element) {
1723
- let currentNode = getParentNode(element);
1724
- while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
1725
- if (isContainingBlock(currentNode)) {
1726
- return currentNode;
1727
- } else if (isTopLayer(currentNode)) {
1728
- return null;
1729
- }
1730
- currentNode = getParentNode(currentNode);
1731
- }
1732
- return null;
1733
- }
1734
- function isWebKit() {
1735
- if (typeof CSS === "undefined" || !CSS.supports) return false;
1736
- return CSS.supports("-webkit-backdrop-filter", "none");
1737
- }
1738
- function isLastTraversableNode(node) {
1739
- return ["html", "body", "#document"].includes(getNodeName(node));
1740
- }
1741
- function getComputedStyle$1(element) {
1742
- return getWindow(element).getComputedStyle(element);
1743
- }
1744
- function getNodeScroll(element) {
1745
- if (isElement(element)) {
1746
- return {
1747
- scrollLeft: element.scrollLeft,
1748
- scrollTop: element.scrollTop
1749
- };
1750
- }
1751
- return {
1752
- scrollLeft: element.scrollX,
1753
- scrollTop: element.scrollY
1754
- };
1755
- }
1756
- function getParentNode(node) {
1757
- if (getNodeName(node) === "html") {
1758
- return node;
1759
- }
1760
- const result = (
1761
- // Step into the shadow DOM of the parent of a slotted node.
1762
- node.assignedSlot || // DOM Element detected.
1763
- node.parentNode || // ShadowRoot detected.
1764
- isShadowRoot(node) && node.host || // Fallback.
1765
- getDocumentElement(node)
1766
- );
1767
- return isShadowRoot(result) ? result.host : result;
1768
- }
1769
- function getNearestOverflowAncestor(node) {
1770
- const parentNode = getParentNode(node);
1771
- if (isLastTraversableNode(parentNode)) {
1772
- return node.ownerDocument ? node.ownerDocument.body : node.body;
1773
- }
1774
- if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
1775
- return parentNode;
1776
- }
1777
- return getNearestOverflowAncestor(parentNode);
1778
- }
1779
- function getOverflowAncestors(node, list, traverseIframes) {
1780
- var _node$ownerDocument2;
1781
- if (list === void 0) {
1782
- list = [];
1783
- }
1784
- if (traverseIframes === void 0) {
1785
- traverseIframes = true;
1786
- }
1787
- const scrollableAncestor = getNearestOverflowAncestor(node);
1788
- const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
1789
- const win = getWindow(scrollableAncestor);
1790
- if (isBody) {
1791
- const frameElement = getFrameElement(win);
1792
- return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
1793
- }
1794
- return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
1795
- }
1796
- function getFrameElement(win) {
1797
- return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
1798
- }
1799
- function getCssDimensions(element) {
1800
- const css = getComputedStyle$1(element);
1801
- let width = parseFloat(css.width) || 0;
1802
- let height = parseFloat(css.height) || 0;
1803
- const hasOffset = isHTMLElement(element);
1804
- const offsetWidth = hasOffset ? element.offsetWidth : width;
1805
- const offsetHeight = hasOffset ? element.offsetHeight : height;
1806
- const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
1807
- if (shouldFallback) {
1808
- width = offsetWidth;
1809
- height = offsetHeight;
1810
- }
1811
- return {
1812
- width,
1813
- height,
1814
- $: shouldFallback
1815
- };
1816
- }
1817
- function unwrapElement(element) {
1818
- return !isElement(element) ? element.contextElement : element;
1819
- }
1820
- function getScale(element) {
1821
- const domElement = unwrapElement(element);
1822
- if (!isHTMLElement(domElement)) {
1823
- return createCoords(1);
1824
- }
1825
- const rect = domElement.getBoundingClientRect();
1826
- const {
1827
- width,
1828
- height,
1829
- $
1830
- } = getCssDimensions(domElement);
1831
- let x = ($ ? round(rect.width) : rect.width) / width;
1832
- let y = ($ ? round(rect.height) : rect.height) / height;
1833
- if (!x || !Number.isFinite(x)) {
1834
- x = 1;
1835
- }
1836
- if (!y || !Number.isFinite(y)) {
1837
- y = 1;
1838
- }
1839
- return {
1840
- x,
1841
- y
1842
- };
1843
- }
1844
- const noOffsets = /* @__PURE__ */ createCoords(0);
1845
- function getVisualOffsets(element) {
1846
- const win = getWindow(element);
1847
- if (!isWebKit() || !win.visualViewport) {
1848
- return noOffsets;
1849
- }
1850
- return {
1851
- x: win.visualViewport.offsetLeft,
1852
- y: win.visualViewport.offsetTop
1853
- };
1854
- }
1855
- function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
1856
- if (isFixed === void 0) {
1857
- isFixed = false;
1858
- }
1859
- if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
1860
- return false;
1861
- }
1862
- return isFixed;
1863
- }
1864
- function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
1865
- if (includeScale === void 0) {
1866
- includeScale = false;
1867
- }
1868
- if (isFixedStrategy === void 0) {
1869
- isFixedStrategy = false;
1870
- }
1871
- const clientRect = element.getBoundingClientRect();
1872
- const domElement = unwrapElement(element);
1873
- let scale = createCoords(1);
1874
- if (includeScale) {
1875
- if (offsetParent) {
1876
- if (isElement(offsetParent)) {
1877
- scale = getScale(offsetParent);
1878
- }
1879
- } else {
1880
- scale = getScale(element);
1881
- }
1882
- }
1883
- const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
1884
- let x = (clientRect.left + visualOffsets.x) / scale.x;
1885
- let y = (clientRect.top + visualOffsets.y) / scale.y;
1886
- let width = clientRect.width / scale.x;
1887
- let height = clientRect.height / scale.y;
1888
- if (domElement) {
1889
- const win = getWindow(domElement);
1890
- const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
1891
- let currentWin = win;
1892
- let currentIFrame = getFrameElement(currentWin);
1893
- while (currentIFrame && offsetParent && offsetWin !== currentWin) {
1894
- const iframeScale = getScale(currentIFrame);
1895
- const iframeRect = currentIFrame.getBoundingClientRect();
1896
- const css = getComputedStyle$1(currentIFrame);
1897
- const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
1898
- const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
1899
- x *= iframeScale.x;
1900
- y *= iframeScale.y;
1901
- width *= iframeScale.x;
1902
- height *= iframeScale.y;
1903
- x += left;
1904
- y += top;
1905
- currentWin = getWindow(currentIFrame);
1906
- currentIFrame = getFrameElement(currentWin);
1907
- }
1908
- }
1909
- return rectToClientRect({
1910
- width,
1911
- height,
1912
- x,
1913
- y
1914
- });
1915
- }
1916
- function getWindowScrollBarX(element, rect) {
1917
- const leftScroll = getNodeScroll(element).scrollLeft;
1918
- if (!rect) {
1919
- return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
1920
- }
1921
- return rect.left + leftScroll;
1922
- }
1923
- function getHTMLOffset(documentElement, scroll, ignoreScrollbarX) {
1924
- if (ignoreScrollbarX === void 0) {
1925
- ignoreScrollbarX = false;
1926
- }
1927
- const htmlRect = documentElement.getBoundingClientRect();
1928
- const x = htmlRect.left + scroll.scrollLeft - (ignoreScrollbarX ? 0 : (
1929
- // RTL <body> scrollbar.
1930
- getWindowScrollBarX(documentElement, htmlRect)
1931
- ));
1932
- const y = htmlRect.top + scroll.scrollTop;
1933
- return {
1934
- x,
1935
- y
1936
- };
1937
- }
1938
- function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
1939
- let {
1940
- elements,
1941
- rect,
1942
- offsetParent,
1943
- strategy
1944
- } = _ref;
1945
- const isFixed = strategy === "fixed";
1946
- const documentElement = getDocumentElement(offsetParent);
1947
- const topLayer = elements ? isTopLayer(elements.floating) : false;
1948
- if (offsetParent === documentElement || topLayer && isFixed) {
1949
- return rect;
1950
- }
1951
- let scroll = {
1952
- scrollLeft: 0,
1953
- scrollTop: 0
1954
- };
1955
- let scale = createCoords(1);
1956
- const offsets = createCoords(0);
1957
- const isOffsetParentAnElement = isHTMLElement(offsetParent);
1958
- if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
1959
- if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
1960
- scroll = getNodeScroll(offsetParent);
1961
- }
1962
- if (isHTMLElement(offsetParent)) {
1963
- const offsetRect = getBoundingClientRect(offsetParent);
1964
- scale = getScale(offsetParent);
1965
- offsets.x = offsetRect.x + offsetParent.clientLeft;
1966
- offsets.y = offsetRect.y + offsetParent.clientTop;
1967
- }
1968
- }
1969
- const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll, true) : createCoords(0);
1970
- return {
1971
- width: rect.width * scale.x,
1972
- height: rect.height * scale.y,
1973
- x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
1974
- y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
1975
- };
1976
- }
1977
- function getClientRects(element) {
1978
- return Array.from(element.getClientRects());
1979
- }
1980
- function getDocumentRect(element) {
1981
- const html = getDocumentElement(element);
1982
- const scroll = getNodeScroll(element);
1983
- const body = element.ownerDocument.body;
1984
- const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
1985
- const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
1986
- let x = -scroll.scrollLeft + getWindowScrollBarX(element);
1987
- const y = -scroll.scrollTop;
1988
- if (getComputedStyle$1(body).direction === "rtl") {
1989
- x += max(html.clientWidth, body.clientWidth) - width;
1990
- }
1991
- return {
1992
- width,
1993
- height,
1994
- x,
1995
- y
1996
- };
1997
- }
1998
- function getViewportRect(element, strategy) {
1999
- const win = getWindow(element);
2000
- const html = getDocumentElement(element);
2001
- const visualViewport = win.visualViewport;
2002
- let width = html.clientWidth;
2003
- let height = html.clientHeight;
2004
- let x = 0;
2005
- let y = 0;
2006
- if (visualViewport) {
2007
- width = visualViewport.width;
2008
- height = visualViewport.height;
2009
- const visualViewportBased = isWebKit();
2010
- if (!visualViewportBased || visualViewportBased && strategy === "fixed") {
2011
- x = visualViewport.offsetLeft;
2012
- y = visualViewport.offsetTop;
2013
- }
2014
- }
2015
- return {
2016
- width,
2017
- height,
2018
- x,
2019
- y
2020
- };
2021
- }
2022
- function getInnerBoundingClientRect(element, strategy) {
2023
- const clientRect = getBoundingClientRect(element, true, strategy === "fixed");
2024
- const top = clientRect.top + element.clientTop;
2025
- const left = clientRect.left + element.clientLeft;
2026
- const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
2027
- const width = element.clientWidth * scale.x;
2028
- const height = element.clientHeight * scale.y;
2029
- const x = left * scale.x;
2030
- const y = top * scale.y;
2031
- return {
2032
- width,
2033
- height,
2034
- x,
2035
- y
2036
- };
2037
- }
2038
- function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
2039
- let rect;
2040
- if (clippingAncestor === "viewport") {
2041
- rect = getViewportRect(element, strategy);
2042
- } else if (clippingAncestor === "document") {
2043
- rect = getDocumentRect(getDocumentElement(element));
2044
- } else if (isElement(clippingAncestor)) {
2045
- rect = getInnerBoundingClientRect(clippingAncestor, strategy);
2046
- } else {
2047
- const visualOffsets = getVisualOffsets(element);
2048
- rect = {
2049
- x: clippingAncestor.x - visualOffsets.x,
2050
- y: clippingAncestor.y - visualOffsets.y,
2051
- width: clippingAncestor.width,
2052
- height: clippingAncestor.height
2053
- };
2054
- }
2055
- return rectToClientRect(rect);
2056
- }
2057
- function hasFixedPositionAncestor(element, stopNode) {
2058
- const parentNode = getParentNode(element);
2059
- if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
2060
- return false;
2061
- }
2062
- return getComputedStyle$1(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
2063
- }
2064
- function getClippingElementAncestors(element, cache) {
2065
- const cachedResult = cache.get(element);
2066
- if (cachedResult) {
2067
- return cachedResult;
2068
- }
2069
- let result = getOverflowAncestors(element, [], false).filter((el) => isElement(el) && getNodeName(el) !== "body");
2070
- let currentContainingBlockComputedStyle = null;
2071
- const elementIsFixed = getComputedStyle$1(element).position === "fixed";
2072
- let currentNode = elementIsFixed ? getParentNode(element) : element;
2073
- while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
2074
- const computedStyle = getComputedStyle$1(currentNode);
2075
- const currentNodeIsContaining = isContainingBlock(currentNode);
2076
- if (!currentNodeIsContaining && computedStyle.position === "fixed") {
2077
- currentContainingBlockComputedStyle = null;
2078
- }
2079
- const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === "static" && !!currentContainingBlockComputedStyle && ["absolute", "fixed"].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
2080
- if (shouldDropCurrentNode) {
2081
- result = result.filter((ancestor) => ancestor !== currentNode);
2082
- } else {
2083
- currentContainingBlockComputedStyle = computedStyle;
2084
- }
2085
- currentNode = getParentNode(currentNode);
2086
- }
2087
- cache.set(element, result);
2088
- return result;
2089
- }
2090
- function getClippingRect(_ref) {
2091
- let {
2092
- element,
2093
- boundary,
2094
- rootBoundary,
2095
- strategy
2096
- } = _ref;
2097
- const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
2098
- const clippingAncestors = [...elementClippingAncestors, rootBoundary];
2099
- const firstClippingAncestor = clippingAncestors[0];
2100
- const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
2101
- const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
2102
- accRect.top = max(rect.top, accRect.top);
2103
- accRect.right = min(rect.right, accRect.right);
2104
- accRect.bottom = min(rect.bottom, accRect.bottom);
2105
- accRect.left = max(rect.left, accRect.left);
2106
- return accRect;
2107
- }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
2108
- return {
2109
- width: clippingRect.right - clippingRect.left,
2110
- height: clippingRect.bottom - clippingRect.top,
2111
- x: clippingRect.left,
2112
- y: clippingRect.top
2113
- };
2114
- }
2115
- function getDimensions(element) {
2116
- const {
2117
- width,
2118
- height
2119
- } = getCssDimensions(element);
2120
- return {
2121
- width,
2122
- height
2123
- };
2124
- }
2125
- function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
2126
- const isOffsetParentAnElement = isHTMLElement(offsetParent);
2127
- const documentElement = getDocumentElement(offsetParent);
2128
- const isFixed = strategy === "fixed";
2129
- const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
2130
- let scroll = {
2131
- scrollLeft: 0,
2132
- scrollTop: 0
2133
- };
2134
- const offsets = createCoords(0);
2135
- if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
2136
- if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
2137
- scroll = getNodeScroll(offsetParent);
2138
- }
2139
- if (isOffsetParentAnElement) {
2140
- const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
2141
- offsets.x = offsetRect.x + offsetParent.clientLeft;
2142
- offsets.y = offsetRect.y + offsetParent.clientTop;
2143
- } else if (documentElement) {
2144
- offsets.x = getWindowScrollBarX(documentElement);
2145
- }
2146
- }
2147
- const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
2148
- const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
2149
- const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
2150
- return {
2151
- x,
2152
- y,
2153
- width: rect.width,
2154
- height: rect.height
2155
- };
2156
- }
2157
- function isStaticPositioned(element) {
2158
- return getComputedStyle$1(element).position === "static";
2159
- }
2160
- function getTrueOffsetParent(element, polyfill) {
2161
- if (!isHTMLElement(element) || getComputedStyle$1(element).position === "fixed") {
2162
- return null;
2163
- }
2164
- if (polyfill) {
2165
- return polyfill(element);
2166
- }
2167
- let rawOffsetParent = element.offsetParent;
2168
- if (getDocumentElement(element) === rawOffsetParent) {
2169
- rawOffsetParent = rawOffsetParent.ownerDocument.body;
2170
- }
2171
- return rawOffsetParent;
2172
- }
2173
- function getOffsetParent(element, polyfill) {
2174
- const win = getWindow(element);
2175
- if (isTopLayer(element)) {
2176
- return win;
2177
- }
2178
- if (!isHTMLElement(element)) {
2179
- let svgOffsetParent = getParentNode(element);
2180
- while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
2181
- if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
2182
- return svgOffsetParent;
2183
- }
2184
- svgOffsetParent = getParentNode(svgOffsetParent);
2185
- }
2186
- return win;
2187
- }
2188
- let offsetParent = getTrueOffsetParent(element, polyfill);
2189
- while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
2190
- offsetParent = getTrueOffsetParent(offsetParent, polyfill);
2191
- }
2192
- if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
2193
- return win;
2194
- }
2195
- return offsetParent || getContainingBlock(element) || win;
2196
- }
2197
- const getElementRects = async function(data) {
2198
- const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
2199
- const getDimensionsFn = this.getDimensions;
2200
- const floatingDimensions = await getDimensionsFn(data.floating);
2201
- return {
2202
- reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
2203
- floating: {
2204
- x: 0,
2205
- y: 0,
2206
- width: floatingDimensions.width,
2207
- height: floatingDimensions.height
2208
- }
2209
- };
2210
- };
2211
- function isRTL(element) {
2212
- return getComputedStyle$1(element).direction === "rtl";
2213
- }
2214
- const platform = {
2215
- convertOffsetParentRelativeRectToViewportRelativeRect,
2216
- getDocumentElement,
2217
- getClippingRect,
2218
- getOffsetParent,
2219
- getElementRects,
2220
- getClientRects,
2221
- getDimensions,
2222
- getScale,
2223
- isElement,
2224
- isRTL
2225
- };
2226
- function observeMove(element, onMove) {
2227
- let io = null;
2228
- let timeoutId;
2229
- const root = getDocumentElement(element);
2230
- function cleanup() {
2231
- var _io;
2232
- clearTimeout(timeoutId);
2233
- (_io = io) == null || _io.disconnect();
2234
- io = null;
2235
- }
2236
- function refresh(skip, threshold) {
2237
- if (skip === void 0) {
2238
- skip = false;
2239
- }
2240
- if (threshold === void 0) {
2241
- threshold = 1;
2242
- }
2243
- cleanup();
2244
- const {
2245
- left,
2246
- top,
2247
- width,
2248
- height
2249
- } = element.getBoundingClientRect();
2250
- if (!skip) {
2251
- onMove();
2252
- }
2253
- if (!width || !height) {
2254
- return;
2255
- }
2256
- const insetTop = floor(top);
2257
- const insetRight = floor(root.clientWidth - (left + width));
2258
- const insetBottom = floor(root.clientHeight - (top + height));
2259
- const insetLeft = floor(left);
2260
- const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
2261
- const options = {
2262
- rootMargin,
2263
- threshold: max(0, min(1, threshold)) || 1
2264
- };
2265
- let isFirstUpdate = true;
2266
- function handleObserve(entries) {
2267
- const ratio = entries[0].intersectionRatio;
2268
- if (ratio !== threshold) {
2269
- if (!isFirstUpdate) {
2270
- return refresh();
2271
- }
2272
- if (!ratio) {
2273
- timeoutId = setTimeout(() => {
2274
- refresh(false, 1e-7);
2275
- }, 1e3);
2276
- } else {
2277
- refresh(false, ratio);
2278
- }
2279
- }
2280
- isFirstUpdate = false;
2281
- }
2282
- try {
2283
- io = new IntersectionObserver(handleObserve, {
2284
- ...options,
2285
- // Handle <iframe>s
2286
- root: root.ownerDocument
2287
- });
2288
- } catch (e) {
2289
- io = new IntersectionObserver(handleObserve, options);
2290
- }
2291
- io.observe(element);
2292
- }
2293
- refresh(true);
2294
- return cleanup;
2295
- }
2296
- function autoUpdate(reference, floating, update, options) {
2297
- if (options === void 0) {
2298
- options = {};
2299
- }
2300
- const {
2301
- ancestorScroll = true,
2302
- ancestorResize = true,
2303
- elementResize = typeof ResizeObserver === "function",
2304
- layoutShift = typeof IntersectionObserver === "function",
2305
- animationFrame = false
2306
- } = options;
2307
- const referenceEl = unwrapElement(reference);
2308
- const ancestors = ancestorScroll || ancestorResize ? [...referenceEl ? getOverflowAncestors(referenceEl) : [], ...getOverflowAncestors(floating)] : [];
2309
- ancestors.forEach((ancestor) => {
2310
- ancestorScroll && ancestor.addEventListener("scroll", update, {
2311
- passive: true
2312
- });
2313
- ancestorResize && ancestor.addEventListener("resize", update);
2314
- });
2315
- const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
2316
- let reobserveFrame = -1;
2317
- let resizeObserver = null;
2318
- if (elementResize) {
2319
- resizeObserver = new ResizeObserver((_ref) => {
2320
- let [firstEntry] = _ref;
2321
- if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
2322
- resizeObserver.unobserve(floating);
2323
- cancelAnimationFrame(reobserveFrame);
2324
- reobserveFrame = requestAnimationFrame(() => {
2325
- var _resizeObserver;
2326
- (_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
2327
- });
2328
- }
2329
- update();
2330
- });
2331
- if (referenceEl && !animationFrame) {
2332
- resizeObserver.observe(referenceEl);
2333
- }
2334
- resizeObserver.observe(floating);
2335
- }
2336
- let frameId;
2337
- let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
2338
- if (animationFrame) {
2339
- frameLoop();
2340
- }
2341
- function frameLoop() {
2342
- const nextRefRect = getBoundingClientRect(reference);
2343
- if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
2344
- update();
2345
- }
2346
- prevRefRect = nextRefRect;
2347
- frameId = requestAnimationFrame(frameLoop);
2348
- }
2349
- update();
2350
- return () => {
2351
- var _resizeObserver2;
2352
- ancestors.forEach((ancestor) => {
2353
- ancestorScroll && ancestor.removeEventListener("scroll", update);
2354
- ancestorResize && ancestor.removeEventListener("resize", update);
2355
- });
2356
- cleanupIo == null || cleanupIo();
2357
- (_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
2358
- resizeObserver = null;
2359
- if (animationFrame) {
2360
- cancelAnimationFrame(frameId);
2361
- }
2362
- };
2363
- }
2364
- const offset$1 = offset$2;
2365
- const shift$1 = shift$2;
2366
- const flip$1 = flip$2;
2367
- const size$1 = size$2;
2368
- const hide$1 = hide$2;
2369
- const arrow$2 = arrow$3;
2370
- const limitShift$1 = limitShift$2;
2371
- const computePosition = (reference, floating, options) => {
2372
- const cache = /* @__PURE__ */ new Map();
2373
- const mergedOptions = {
2374
- platform,
2375
- ...options
2376
- };
2377
- const platformWithCache = {
2378
- ...mergedOptions.platform,
2379
- _c: cache
2380
- };
2381
- return computePosition$1(reference, floating, {
2382
- ...mergedOptions,
2383
- platform: platformWithCache
2384
- });
2385
- };
2386
- var index$1 = typeof document !== "undefined" ? useLayoutEffect : useEffect;
2387
- function deepEqual(a, b) {
2388
- if (a === b) {
2389
- return true;
2390
- }
2391
- if (typeof a !== typeof b) {
2392
- return false;
2393
- }
2394
- if (typeof a === "function" && a.toString() === b.toString()) {
2395
- return true;
2396
- }
2397
- let length;
2398
- let i;
2399
- let keys;
2400
- if (a && b && typeof a === "object") {
2401
- if (Array.isArray(a)) {
2402
- length = a.length;
2403
- if (length !== b.length) return false;
2404
- for (i = length; i-- !== 0; ) {
2405
- if (!deepEqual(a[i], b[i])) {
2406
- return false;
2407
- }
2408
- }
2409
- return true;
2410
- }
2411
- keys = Object.keys(a);
2412
- length = keys.length;
2413
- if (length !== Object.keys(b).length) {
2414
- return false;
2415
- }
2416
- for (i = length; i-- !== 0; ) {
2417
- if (!{}.hasOwnProperty.call(b, keys[i])) {
2418
- return false;
2419
- }
2420
- }
2421
- for (i = length; i-- !== 0; ) {
2422
- const key = keys[i];
2423
- if (key === "_owner" && a.$$typeof) {
2424
- continue;
2425
- }
2426
- if (!deepEqual(a[key], b[key])) {
2427
- return false;
2428
- }
2429
- }
2430
- return true;
2431
- }
2432
- return a !== a && b !== b;
2433
- }
2434
- function getDPR(element) {
2435
- if (typeof window === "undefined") {
2436
- return 1;
2437
- }
2438
- const win = element.ownerDocument.defaultView || window;
2439
- return win.devicePixelRatio || 1;
2440
- }
2441
- function roundByDPR(element, value) {
2442
- const dpr = getDPR(element);
2443
- return Math.round(value * dpr) / dpr;
2444
- }
2445
- function useLatestRef(value) {
2446
- const ref = React.useRef(value);
2447
- index$1(() => {
2448
- ref.current = value;
2449
- });
2450
- return ref;
2451
- }
2452
- function useFloating(options) {
2453
- if (options === void 0) {
2454
- options = {};
2455
- }
2456
- const {
2457
- placement = "bottom",
2458
- strategy = "absolute",
2459
- middleware = [],
2460
- platform: platform2,
2461
- elements: {
2462
- reference: externalReference,
2463
- floating: externalFloating
2464
- } = {},
2465
- transform = true,
2466
- whileElementsMounted,
2467
- open
2468
- } = options;
2469
- const [data, setData] = React.useState({
2470
- x: 0,
2471
- y: 0,
2472
- strategy,
2473
- placement,
2474
- middlewareData: {},
2475
- isPositioned: false
2476
- });
2477
- const [latestMiddleware, setLatestMiddleware] = React.useState(middleware);
2478
- if (!deepEqual(latestMiddleware, middleware)) {
2479
- setLatestMiddleware(middleware);
2480
- }
2481
- const [_reference, _setReference] = React.useState(null);
2482
- const [_floating, _setFloating] = React.useState(null);
2483
- const setReference = React.useCallback((node) => {
2484
- if (node !== referenceRef.current) {
2485
- referenceRef.current = node;
2486
- _setReference(node);
2487
- }
2488
- }, []);
2489
- const setFloating = React.useCallback((node) => {
2490
- if (node !== floatingRef.current) {
2491
- floatingRef.current = node;
2492
- _setFloating(node);
2493
- }
2494
- }, []);
2495
- const referenceEl = externalReference || _reference;
2496
- const floatingEl = externalFloating || _floating;
2497
- const referenceRef = React.useRef(null);
2498
- const floatingRef = React.useRef(null);
2499
- const dataRef = React.useRef(data);
2500
- const hasWhileElementsMounted = whileElementsMounted != null;
2501
- const whileElementsMountedRef = useLatestRef(whileElementsMounted);
2502
- const platformRef = useLatestRef(platform2);
2503
- const openRef = useLatestRef(open);
2504
- const update = React.useCallback(() => {
2505
- if (!referenceRef.current || !floatingRef.current) {
2506
- return;
2507
- }
2508
- const config = {
2509
- placement,
2510
- strategy,
2511
- middleware: latestMiddleware
2512
- };
2513
- if (platformRef.current) {
2514
- config.platform = platformRef.current;
2515
- }
2516
- computePosition(referenceRef.current, floatingRef.current, config).then((data2) => {
2517
- const fullData = {
2518
- ...data2,
2519
- // The floating element's position may be recomputed while it's closed
2520
- // but still mounted (such as when transitioning out). To ensure
2521
- // `isPositioned` will be `false` initially on the next open, avoid
2522
- // setting it to `true` when `open === false` (must be specified).
2523
- isPositioned: openRef.current !== false
2524
- };
2525
- if (isMountedRef.current && !deepEqual(dataRef.current, fullData)) {
2526
- dataRef.current = fullData;
2527
- ReactDOM.flushSync(() => {
2528
- setData(fullData);
2529
- });
2530
- }
2531
- });
2532
- }, [latestMiddleware, placement, strategy, platformRef, openRef]);
2533
- index$1(() => {
2534
- if (open === false && dataRef.current.isPositioned) {
2535
- dataRef.current.isPositioned = false;
2536
- setData((data2) => ({
2537
- ...data2,
2538
- isPositioned: false
2539
- }));
2540
- }
2541
- }, [open]);
2542
- const isMountedRef = React.useRef(false);
2543
- index$1(() => {
2544
- isMountedRef.current = true;
2545
- return () => {
2546
- isMountedRef.current = false;
2547
- };
2548
- }, []);
2549
- index$1(() => {
2550
- if (referenceEl) referenceRef.current = referenceEl;
2551
- if (floatingEl) floatingRef.current = floatingEl;
2552
- if (referenceEl && floatingEl) {
2553
- if (whileElementsMountedRef.current) {
2554
- return whileElementsMountedRef.current(referenceEl, floatingEl, update);
2555
- }
2556
- update();
2557
- }
2558
- }, [referenceEl, floatingEl, update, whileElementsMountedRef, hasWhileElementsMounted]);
2559
- const refs = React.useMemo(() => ({
2560
- reference: referenceRef,
2561
- floating: floatingRef,
2562
- setReference,
2563
- setFloating
2564
- }), [setReference, setFloating]);
2565
- const elements = React.useMemo(() => ({
2566
- reference: referenceEl,
2567
- floating: floatingEl
2568
- }), [referenceEl, floatingEl]);
2569
- const floatingStyles = React.useMemo(() => {
2570
- const initialStyles = {
2571
- position: strategy,
2572
- left: 0,
2573
- top: 0
2574
- };
2575
- if (!elements.floating) {
2576
- return initialStyles;
2577
- }
2578
- const x = roundByDPR(elements.floating, data.x);
2579
- const y = roundByDPR(elements.floating, data.y);
2580
- if (transform) {
2581
- return {
2582
- ...initialStyles,
2583
- transform: "translate(" + x + "px, " + y + "px)",
2584
- ...getDPR(elements.floating) >= 1.5 && {
2585
- willChange: "transform"
2586
- }
2587
- };
2588
- }
2589
- return {
2590
- position: strategy,
2591
- left: x,
2592
- top: y
2593
- };
2594
- }, [strategy, transform, elements.floating, data.x, data.y]);
2595
- return React.useMemo(() => ({
2596
- ...data,
2597
- update,
2598
- refs,
2599
- elements,
2600
- floatingStyles
2601
- }), [data, update, refs, elements, floatingStyles]);
2602
- }
2603
- const arrow$1 = (options) => {
2604
- function isRef(value) {
2605
- return {}.hasOwnProperty.call(value, "current");
2606
- }
2607
- return {
2608
- name: "arrow",
2609
- options,
2610
- fn(state) {
2611
- const {
2612
- element,
2613
- padding
2614
- } = typeof options === "function" ? options(state) : options;
2615
- if (element && isRef(element)) {
2616
- if (element.current != null) {
2617
- return arrow$2({
2618
- element: element.current,
2619
- padding
2620
- }).fn(state);
2621
- }
2622
- return {};
2623
- }
2624
- if (element) {
2625
- return arrow$2({
2626
- element,
2627
- padding
2628
- }).fn(state);
2629
- }
2630
- return {};
2631
- }
2632
- };
2633
- };
2634
- const offset = (options, deps) => ({
2635
- ...offset$1(options),
2636
- options: [options, deps]
2637
- });
2638
- const shift = (options, deps) => ({
2639
- ...shift$1(options),
2640
- options: [options, deps]
2641
- });
2642
- const limitShift = (options, deps) => ({
2643
- ...limitShift$1(options),
2644
- options: [options, deps]
2645
- });
2646
- const flip = (options, deps) => ({
2647
- ...flip$1(options),
2648
- options: [options, deps]
2649
- });
2650
- const size = (options, deps) => ({
2651
- ...size$1(options),
2652
- options: [options, deps]
2653
- });
2654
- const hide = (options, deps) => ({
2655
- ...hide$1(options),
2656
- options: [options, deps]
2657
- });
2658
- const arrow = (options, deps) => ({
2659
- ...arrow$1(options),
2660
- options: [options, deps]
2661
- });
2662
- const $7e8f5cd07187803e$export$21b07c8f274aebd5 = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
2663
- const { children, width = 10, height = 5, ...arrowProps } = props;
2664
- return /* @__PURE__ */ createElement($8927f6f2acc4f386$export$250ffa63cdc0d034.svg, _extends({}, arrowProps, {
2665
- ref: forwardedRef,
2666
- width,
2667
- height,
2668
- viewBox: "0 0 30 10",
2669
- preserveAspectRatio: "none"
2670
- }), props.asChild ? children : /* @__PURE__ */ createElement("polygon", {
2671
- points: "0,0 30,0 15,10"
2672
- }));
2673
- });
2674
- const $7e8f5cd07187803e$export$be92b6f5f03c0fe9 = $7e8f5cd07187803e$export$21b07c8f274aebd5;
2675
- function $db6c3485150b8e66$export$1ab7ae714698c4b8(element) {
2676
- const [size2, setSize] = useState(void 0);
2677
- $9f79659886946c16$export$e5c5a5f917a5871c(() => {
2678
- if (element) {
2679
- setSize({
2680
- width: element.offsetWidth,
2681
- height: element.offsetHeight
2682
- });
2683
- const resizeObserver = new ResizeObserver((entries) => {
2684
- if (!Array.isArray(entries)) return;
2685
- if (!entries.length) return;
2686
- const entry = entries[0];
2687
- let width;
2688
- let height;
2689
- if ("borderBoxSize" in entry) {
2690
- const borderSizeEntry = entry["borderBoxSize"];
2691
- const borderSize = Array.isArray(borderSizeEntry) ? borderSizeEntry[0] : borderSizeEntry;
2692
- width = borderSize["inlineSize"];
2693
- height = borderSize["blockSize"];
2694
- } else {
2695
- width = element.offsetWidth;
2696
- height = element.offsetHeight;
2697
- }
2698
- setSize({
2699
- width,
2700
- height
2701
- });
2702
- });
2703
- resizeObserver.observe(element, {
2704
- box: "border-box"
2705
- });
2706
- return () => resizeObserver.unobserve(element);
2707
- } else
2708
- setSize(void 0);
2709
- }, [
2710
- element
2711
- ]);
2712
- return size2;
2713
- }
2714
- const $cf1ac5d9fe0e8206$var$POPPER_NAME = "Popper";
2715
- const [$cf1ac5d9fe0e8206$var$createPopperContext, $cf1ac5d9fe0e8206$export$722aac194ae923] = $c512c27ab02ef895$export$50c7b4e9d9f19c1($cf1ac5d9fe0e8206$var$POPPER_NAME);
2716
- const [$cf1ac5d9fe0e8206$var$PopperProvider, $cf1ac5d9fe0e8206$var$usePopperContext] = $cf1ac5d9fe0e8206$var$createPopperContext($cf1ac5d9fe0e8206$var$POPPER_NAME);
2717
- const $cf1ac5d9fe0e8206$export$badac9ada3a0bdf9 = (props) => {
2718
- const { __scopePopper, children } = props;
2719
- const [anchor, setAnchor] = useState(null);
2720
- return /* @__PURE__ */ createElement($cf1ac5d9fe0e8206$var$PopperProvider, {
2721
- scope: __scopePopper,
2722
- anchor,
2723
- onAnchorChange: setAnchor
2724
- }, children);
2725
- };
2726
- const $cf1ac5d9fe0e8206$var$ANCHOR_NAME = "PopperAnchor";
2727
- const $cf1ac5d9fe0e8206$export$ecd4e1ccab6ed6d = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
2728
- const { __scopePopper, virtualRef, ...anchorProps } = props;
2729
- const context = $cf1ac5d9fe0e8206$var$usePopperContext($cf1ac5d9fe0e8206$var$ANCHOR_NAME, __scopePopper);
2730
- const ref = useRef(null);
2731
- const composedRefs = $6ed0406888f73fc4$export$c7b2cbe3552a0d05(forwardedRef, ref);
2732
- useEffect(() => {
2733
- context.onAnchorChange((virtualRef === null || virtualRef === void 0 ? void 0 : virtualRef.current) || ref.current);
2734
- });
2735
- return virtualRef ? null : /* @__PURE__ */ createElement($8927f6f2acc4f386$export$250ffa63cdc0d034.div, _extends({}, anchorProps, {
2736
- ref: composedRefs
2737
- }));
2738
- });
2739
- const $cf1ac5d9fe0e8206$var$CONTENT_NAME = "PopperContent";
2740
- const [$cf1ac5d9fe0e8206$var$PopperContentProvider, $cf1ac5d9fe0e8206$var$useContentContext] = $cf1ac5d9fe0e8206$var$createPopperContext($cf1ac5d9fe0e8206$var$CONTENT_NAME);
2741
- const $cf1ac5d9fe0e8206$export$bc4ae5855d3c4fc = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
2742
- var _arrowSize$width, _arrowSize$height, _middlewareData$arrow, _middlewareData$arrow2, _middlewareData$arrow3, _middlewareData$trans, _middlewareData$trans2, _middlewareData$hide;
2743
- const { __scopePopper, side = "bottom", sideOffset = 0, align = "center", alignOffset = 0, arrowPadding = 0, avoidCollisions = true, collisionBoundary = [], collisionPadding: collisionPaddingProp = 0, sticky = "partial", hideWhenDetached = false, updatePositionStrategy = "optimized", onPlaced, ...contentProps } = props;
2744
- const context = $cf1ac5d9fe0e8206$var$usePopperContext($cf1ac5d9fe0e8206$var$CONTENT_NAME, __scopePopper);
2745
- const [content, setContent] = useState(null);
2746
- const composedRefs = $6ed0406888f73fc4$export$c7b2cbe3552a0d05(
2747
- forwardedRef,
2748
- (node) => setContent(node)
2749
- );
2750
- const [arrow$12, setArrow] = useState(null);
2751
- const arrowSize = $db6c3485150b8e66$export$1ab7ae714698c4b8(arrow$12);
2752
- const arrowWidth = (_arrowSize$width = arrowSize === null || arrowSize === void 0 ? void 0 : arrowSize.width) !== null && _arrowSize$width !== void 0 ? _arrowSize$width : 0;
2753
- const arrowHeight = (_arrowSize$height = arrowSize === null || arrowSize === void 0 ? void 0 : arrowSize.height) !== null && _arrowSize$height !== void 0 ? _arrowSize$height : 0;
2754
- const desiredPlacement = side + (align !== "center" ? "-" + align : "");
2755
- const collisionPadding = typeof collisionPaddingProp === "number" ? collisionPaddingProp : {
2756
- top: 0,
2757
- right: 0,
2758
- bottom: 0,
2759
- left: 0,
2760
- ...collisionPaddingProp
2761
- };
2762
- const boundary = Array.isArray(collisionBoundary) ? collisionBoundary : [
2763
- collisionBoundary
2764
- ];
2765
- const hasExplicitBoundaries = boundary.length > 0;
2766
- const detectOverflowOptions = {
2767
- padding: collisionPadding,
2768
- boundary: boundary.filter($cf1ac5d9fe0e8206$var$isNotNull),
2769
- // with `strategy: 'fixed'`, this is the only way to get it to respect boundaries
2770
- altBoundary: hasExplicitBoundaries
2771
- };
2772
- const { refs, floatingStyles, placement, isPositioned, middlewareData } = useFloating({
2773
- // default to `fixed` strategy so users don't have to pick and we also avoid focus scroll issues
2774
- strategy: "fixed",
2775
- placement: desiredPlacement,
2776
- whileElementsMounted: (...args) => {
2777
- const cleanup = autoUpdate(...args, {
2778
- animationFrame: updatePositionStrategy === "always"
2779
- });
2780
- return cleanup;
2781
- },
2782
- elements: {
2783
- reference: context.anchor
2784
- },
2785
- middleware: [
2786
- offset({
2787
- mainAxis: sideOffset + arrowHeight,
2788
- alignmentAxis: alignOffset
2789
- }),
2790
- avoidCollisions && shift({
2791
- mainAxis: true,
2792
- crossAxis: false,
2793
- limiter: sticky === "partial" ? limitShift() : void 0,
2794
- ...detectOverflowOptions
2795
- }),
2796
- avoidCollisions && flip({
2797
- ...detectOverflowOptions
2798
- }),
2799
- size({
2800
- ...detectOverflowOptions,
2801
- apply: ({ elements, rects, availableWidth, availableHeight }) => {
2802
- const { width: anchorWidth, height: anchorHeight } = rects.reference;
2803
- const contentStyle = elements.floating.style;
2804
- contentStyle.setProperty("--radix-popper-available-width", `${availableWidth}px`);
2805
- contentStyle.setProperty("--radix-popper-available-height", `${availableHeight}px`);
2806
- contentStyle.setProperty("--radix-popper-anchor-width", `${anchorWidth}px`);
2807
- contentStyle.setProperty("--radix-popper-anchor-height", `${anchorHeight}px`);
2808
- }
2809
- }),
2810
- arrow$12 && arrow({
2811
- element: arrow$12,
2812
- padding: arrowPadding
2813
- }),
2814
- $cf1ac5d9fe0e8206$var$transformOrigin({
2815
- arrowWidth,
2816
- arrowHeight
2817
- }),
2818
- hideWhenDetached && hide({
2819
- strategy: "referenceHidden",
2820
- ...detectOverflowOptions
2821
- })
2822
- ]
2823
- });
2824
- const [placedSide, placedAlign] = $cf1ac5d9fe0e8206$var$getSideAndAlignFromPlacement(placement);
2825
- const handlePlaced = $b1b2314f5f9a1d84$export$25bec8c6f54ee79a(onPlaced);
2826
- $9f79659886946c16$export$e5c5a5f917a5871c(() => {
2827
- if (isPositioned) handlePlaced === null || handlePlaced === void 0 || handlePlaced();
2828
- }, [
2829
- isPositioned,
2830
- handlePlaced
2831
- ]);
2832
- const arrowX = (_middlewareData$arrow = middlewareData.arrow) === null || _middlewareData$arrow === void 0 ? void 0 : _middlewareData$arrow.x;
2833
- const arrowY = (_middlewareData$arrow2 = middlewareData.arrow) === null || _middlewareData$arrow2 === void 0 ? void 0 : _middlewareData$arrow2.y;
2834
- const cannotCenterArrow = ((_middlewareData$arrow3 = middlewareData.arrow) === null || _middlewareData$arrow3 === void 0 ? void 0 : _middlewareData$arrow3.centerOffset) !== 0;
2835
- const [contentZIndex, setContentZIndex] = useState();
2836
- $9f79659886946c16$export$e5c5a5f917a5871c(() => {
2837
- if (content) setContentZIndex(window.getComputedStyle(content).zIndex);
2838
- }, [
2839
- content
2840
- ]);
2841
- return /* @__PURE__ */ createElement("div", {
2842
- ref: refs.setFloating,
2843
- "data-radix-popper-content-wrapper": "",
2844
- style: {
2845
- ...floatingStyles,
2846
- transform: isPositioned ? floatingStyles.transform : "translate(0, -200%)",
2847
- // keep off the page when measuring
2848
- minWidth: "max-content",
2849
- zIndex: contentZIndex,
2850
- ["--radix-popper-transform-origin"]: [
2851
- (_middlewareData$trans = middlewareData.transformOrigin) === null || _middlewareData$trans === void 0 ? void 0 : _middlewareData$trans.x,
2852
- (_middlewareData$trans2 = middlewareData.transformOrigin) === null || _middlewareData$trans2 === void 0 ? void 0 : _middlewareData$trans2.y
2853
- ].join(" ")
2854
- },
2855
- dir: props.dir
2856
- }, /* @__PURE__ */ createElement($cf1ac5d9fe0e8206$var$PopperContentProvider, {
2857
- scope: __scopePopper,
2858
- placedSide,
2859
- onArrowChange: setArrow,
2860
- arrowX,
2861
- arrowY,
2862
- shouldHideArrow: cannotCenterArrow
2863
- }, /* @__PURE__ */ createElement($8927f6f2acc4f386$export$250ffa63cdc0d034.div, _extends({
2864
- "data-side": placedSide,
2865
- "data-align": placedAlign
2866
- }, contentProps, {
2867
- ref: composedRefs,
2868
- style: {
2869
- ...contentProps.style,
2870
- // if the PopperContent hasn't been placed yet (not all measurements done)
2871
- // we prevent animations so that users's animation don't kick in too early referring wrong sides
2872
- animation: !isPositioned ? "none" : void 0,
2873
- // hide the content if using the hide middleware and should be hidden
2874
- opacity: (_middlewareData$hide = middlewareData.hide) !== null && _middlewareData$hide !== void 0 && _middlewareData$hide.referenceHidden ? 0 : void 0
2875
- }
2876
- }))));
2877
- });
2878
- const $cf1ac5d9fe0e8206$var$ARROW_NAME = "PopperArrow";
2879
- const $cf1ac5d9fe0e8206$var$OPPOSITE_SIDE = {
2880
- top: "bottom",
2881
- right: "left",
2882
- bottom: "top",
2883
- left: "right"
2884
- };
2885
- const $cf1ac5d9fe0e8206$export$79d62cd4e10a3fd0 = /* @__PURE__ */ forwardRef(function $cf1ac5d9fe0e8206$export$79d62cd4e10a3fd02(props, forwardedRef) {
2886
- const { __scopePopper, ...arrowProps } = props;
2887
- const contentContext = $cf1ac5d9fe0e8206$var$useContentContext($cf1ac5d9fe0e8206$var$ARROW_NAME, __scopePopper);
2888
- const baseSide = $cf1ac5d9fe0e8206$var$OPPOSITE_SIDE[contentContext.placedSide];
2889
- return (
2890
- // we have to use an extra wrapper because `ResizeObserver` (used by `useSize`)
2891
- // doesn't report size as we'd expect on SVG elements.
2892
- // it reports their bounding box which is effectively the largest path inside the SVG.
2893
- /* @__PURE__ */ createElement("span", {
2894
- ref: contentContext.onArrowChange,
2895
- style: {
2896
- position: "absolute",
2897
- left: contentContext.arrowX,
2898
- top: contentContext.arrowY,
2899
- [baseSide]: 0,
2900
- transformOrigin: {
2901
- top: "",
2902
- right: "0 0",
2903
- bottom: "center 0",
2904
- left: "100% 0"
2905
- }[contentContext.placedSide],
2906
- transform: {
2907
- top: "translateY(100%)",
2908
- right: "translateY(50%) rotate(90deg) translateX(-50%)",
2909
- bottom: `rotate(180deg)`,
2910
- left: "translateY(50%) rotate(-90deg) translateX(50%)"
2911
- }[contentContext.placedSide],
2912
- visibility: contentContext.shouldHideArrow ? "hidden" : void 0
2913
- }
2914
- }, /* @__PURE__ */ createElement($7e8f5cd07187803e$export$be92b6f5f03c0fe9, _extends({}, arrowProps, {
2915
- ref: forwardedRef,
2916
- style: {
2917
- ...arrowProps.style,
2918
- // ensures the element can be measured correctly (mostly for if SVG)
2919
- display: "block"
2920
- }
2921
- })))
2922
- );
2923
- });
2924
- /* @__PURE__ */ Object.assign($cf1ac5d9fe0e8206$export$79d62cd4e10a3fd0, {
2925
- displayName: $cf1ac5d9fe0e8206$var$ARROW_NAME
2926
- });
2927
- function $cf1ac5d9fe0e8206$var$isNotNull(value) {
2928
- return value !== null;
2929
- }
2930
- const $cf1ac5d9fe0e8206$var$transformOrigin = (options) => ({
2931
- name: "transformOrigin",
2932
- options,
2933
- fn(data) {
2934
- var _middlewareData$arrow4, _middlewareData$arrow5, _middlewareData$arrow6, _middlewareData$arrow7, _middlewareData$arrow8;
2935
- const { placement, rects, middlewareData } = data;
2936
- const cannotCenterArrow = ((_middlewareData$arrow4 = middlewareData.arrow) === null || _middlewareData$arrow4 === void 0 ? void 0 : _middlewareData$arrow4.centerOffset) !== 0;
2937
- const isArrowHidden = cannotCenterArrow;
2938
- const arrowWidth = isArrowHidden ? 0 : options.arrowWidth;
2939
- const arrowHeight = isArrowHidden ? 0 : options.arrowHeight;
2940
- const [placedSide, placedAlign] = $cf1ac5d9fe0e8206$var$getSideAndAlignFromPlacement(placement);
2941
- const noArrowAlign = {
2942
- start: "0%",
2943
- center: "50%",
2944
- end: "100%"
2945
- }[placedAlign];
2946
- const arrowXCenter = ((_middlewareData$arrow5 = (_middlewareData$arrow6 = middlewareData.arrow) === null || _middlewareData$arrow6 === void 0 ? void 0 : _middlewareData$arrow6.x) !== null && _middlewareData$arrow5 !== void 0 ? _middlewareData$arrow5 : 0) + arrowWidth / 2;
2947
- const arrowYCenter = ((_middlewareData$arrow7 = (_middlewareData$arrow8 = middlewareData.arrow) === null || _middlewareData$arrow8 === void 0 ? void 0 : _middlewareData$arrow8.y) !== null && _middlewareData$arrow7 !== void 0 ? _middlewareData$arrow7 : 0) + arrowHeight / 2;
2948
- let x = "";
2949
- let y = "";
2950
- if (placedSide === "bottom") {
2951
- x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
2952
- y = `${-arrowHeight}px`;
2953
- } else if (placedSide === "top") {
2954
- x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
2955
- y = `${rects.floating.height + arrowHeight}px`;
2956
- } else if (placedSide === "right") {
2957
- x = `${-arrowHeight}px`;
2958
- y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
2959
- } else if (placedSide === "left") {
2960
- x = `${rects.floating.width + arrowHeight}px`;
2961
- y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
2962
- }
2963
- return {
2964
- data: {
2965
- x,
2966
- y
2967
- }
2968
- };
2969
- }
2970
- });
2971
- function $cf1ac5d9fe0e8206$var$getSideAndAlignFromPlacement(placement) {
2972
- const [side, align = "center"] = placement.split("-");
2973
- return [
2974
- side,
2975
- align
2976
- ];
2977
- }
2978
- const $cf1ac5d9fe0e8206$export$be92b6f5f03c0fe9 = $cf1ac5d9fe0e8206$export$badac9ada3a0bdf9;
2979
- const $cf1ac5d9fe0e8206$export$b688253958b8dfe7 = $cf1ac5d9fe0e8206$export$ecd4e1ccab6ed6d;
2980
- const $cf1ac5d9fe0e8206$export$7c6e2c02157bb7d2 = $cf1ac5d9fe0e8206$export$bc4ae5855d3c4fc;
2981
- const $f1701beae083dbae$export$602eac185826482c = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
2982
- var _globalThis$document;
2983
- const { container = globalThis === null || globalThis === void 0 ? void 0 : (_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : _globalThis$document.body, ...portalProps } = props;
2984
- return container ? /* @__PURE__ */ ReactDOM__default.createPortal(/* @__PURE__ */ createElement($8927f6f2acc4f386$export$250ffa63cdc0d034.div, _extends({}, portalProps, {
2985
- ref: forwardedRef
2986
- })), container) : null;
2987
- });
2988
- function $fe963b355347cc68$export$3e6543de14f8614f(initialState, machine) {
2989
- return useReducer((state, event) => {
2990
- const nextState = machine[state][event];
2991
- return nextState !== null && nextState !== void 0 ? nextState : state;
2992
- }, initialState);
2993
- }
2994
- const $921a889cee6df7e8$export$99c2b779aa4e8b8b = (props) => {
2995
- const { present, children } = props;
2996
- const presence = $921a889cee6df7e8$var$usePresence(present);
2997
- const child = typeof children === "function" ? children({
2998
- present: presence.isPresent
2999
- }) : Children.only(children);
3000
- const ref = $6ed0406888f73fc4$export$c7b2cbe3552a0d05(presence.ref, child.ref);
3001
- const forceMount = typeof children === "function";
3002
- return forceMount || presence.isPresent ? /* @__PURE__ */ cloneElement(child, {
3003
- ref
3004
- }) : null;
3005
- };
3006
- $921a889cee6df7e8$export$99c2b779aa4e8b8b.displayName = "Presence";
3007
- function $921a889cee6df7e8$var$usePresence(present) {
3008
- const [node1, setNode] = useState();
3009
- const stylesRef = useRef({});
3010
- const prevPresentRef = useRef(present);
3011
- const prevAnimationNameRef = useRef("none");
3012
- const initialState = present ? "mounted" : "unmounted";
3013
- const [state, send] = $fe963b355347cc68$export$3e6543de14f8614f(initialState, {
3014
- mounted: {
3015
- UNMOUNT: "unmounted",
3016
- ANIMATION_OUT: "unmountSuspended"
3017
- },
3018
- unmountSuspended: {
3019
- MOUNT: "mounted",
3020
- ANIMATION_END: "unmounted"
3021
- },
3022
- unmounted: {
3023
- MOUNT: "mounted"
3024
- }
3025
- });
3026
- useEffect(() => {
3027
- const currentAnimationName = $921a889cee6df7e8$var$getAnimationName(stylesRef.current);
3028
- prevAnimationNameRef.current = state === "mounted" ? currentAnimationName : "none";
3029
- }, [
3030
- state
3031
- ]);
3032
- $9f79659886946c16$export$e5c5a5f917a5871c(() => {
3033
- const styles = stylesRef.current;
3034
- const wasPresent = prevPresentRef.current;
3035
- const hasPresentChanged = wasPresent !== present;
3036
- if (hasPresentChanged) {
3037
- const prevAnimationName = prevAnimationNameRef.current;
3038
- const currentAnimationName = $921a889cee6df7e8$var$getAnimationName(styles);
3039
- if (present) send("MOUNT");
3040
- else if (currentAnimationName === "none" || (styles === null || styles === void 0 ? void 0 : styles.display) === "none")
3041
- send("UNMOUNT");
3042
- else {
3043
- const isAnimating = prevAnimationName !== currentAnimationName;
3044
- if (wasPresent && isAnimating) send("ANIMATION_OUT");
3045
- else send("UNMOUNT");
3046
- }
3047
- prevPresentRef.current = present;
3048
- }
3049
- }, [
3050
- present,
3051
- send
3052
- ]);
3053
- $9f79659886946c16$export$e5c5a5f917a5871c(() => {
3054
- if (node1) {
3055
- const handleAnimationEnd = (event) => {
3056
- const currentAnimationName = $921a889cee6df7e8$var$getAnimationName(stylesRef.current);
3057
- const isCurrentAnimation = currentAnimationName.includes(event.animationName);
3058
- if (event.target === node1 && isCurrentAnimation)
3059
- flushSync(
3060
- () => send("ANIMATION_END")
3061
- );
3062
- };
3063
- const handleAnimationStart = (event) => {
3064
- if (event.target === node1)
3065
- prevAnimationNameRef.current = $921a889cee6df7e8$var$getAnimationName(stylesRef.current);
3066
- };
3067
- node1.addEventListener("animationstart", handleAnimationStart);
3068
- node1.addEventListener("animationcancel", handleAnimationEnd);
3069
- node1.addEventListener("animationend", handleAnimationEnd);
3070
- return () => {
3071
- node1.removeEventListener("animationstart", handleAnimationStart);
3072
- node1.removeEventListener("animationcancel", handleAnimationEnd);
3073
- node1.removeEventListener("animationend", handleAnimationEnd);
3074
- };
3075
- } else
3076
- send("ANIMATION_END");
3077
- }, [
3078
- node1,
3079
- send
3080
- ]);
3081
- return {
3082
- isPresent: [
3083
- "mounted",
3084
- "unmountSuspended"
3085
- ].includes(state),
3086
- ref: useCallback((node) => {
3087
- if (node) stylesRef.current = getComputedStyle(node);
3088
- setNode(node);
3089
- }, [])
3090
- };
3091
- }
3092
- function $921a889cee6df7e8$var$getAnimationName(styles) {
3093
- return (styles === null || styles === void 0 ? void 0 : styles.animationName) || "none";
3094
- }
3095
- function $71cd76cc60e0454e$export$6f32135080cb4c3({ prop, defaultProp, onChange = () => {
3096
- } }) {
3097
- const [uncontrolledProp, setUncontrolledProp] = $71cd76cc60e0454e$var$useUncontrolledState({
3098
- defaultProp,
3099
- onChange
3100
- });
3101
- const isControlled = prop !== void 0;
3102
- const value1 = isControlled ? prop : uncontrolledProp;
3103
- const handleChange = $b1b2314f5f9a1d84$export$25bec8c6f54ee79a(onChange);
3104
- const setValue = useCallback((nextValue) => {
3105
- if (isControlled) {
3106
- const setter = nextValue;
3107
- const value = typeof nextValue === "function" ? setter(prop) : nextValue;
3108
- if (value !== prop) handleChange(value);
3109
- } else setUncontrolledProp(nextValue);
3110
- }, [
3111
- isControlled,
3112
- prop,
3113
- setUncontrolledProp,
3114
- handleChange
3115
- ]);
3116
- return [
3117
- value1,
3118
- setValue
3119
- ];
3120
- }
3121
- function $71cd76cc60e0454e$var$useUncontrolledState({ defaultProp, onChange }) {
3122
- const uncontrolledState = useState(defaultProp);
3123
- const [value] = uncontrolledState;
3124
- const prevValueRef = useRef(value);
3125
- const handleChange = $b1b2314f5f9a1d84$export$25bec8c6f54ee79a(onChange);
3126
- useEffect(() => {
3127
- if (prevValueRef.current !== value) {
3128
- handleChange(value);
3129
- prevValueRef.current = value;
3130
- }
3131
- }, [
3132
- value,
3133
- prevValueRef,
3134
- handleChange
3135
- ]);
3136
- return uncontrolledState;
3137
- }
3138
- const $ea1ef594cf570d83$export$439d29a4e110a164 = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
3139
- return /* @__PURE__ */ createElement($8927f6f2acc4f386$export$250ffa63cdc0d034.span, _extends({}, props, {
3140
- ref: forwardedRef,
3141
- style: {
3142
- // See: https://github.com/twbs/bootstrap/blob/master/scss/mixins/_screen-reader.scss
3143
- position: "absolute",
3144
- border: 0,
3145
- width: 1,
3146
- height: 1,
3147
- padding: 0,
3148
- margin: -1,
3149
- overflow: "hidden",
3150
- clip: "rect(0, 0, 0, 0)",
3151
- whiteSpace: "nowrap",
3152
- wordWrap: "normal",
3153
- ...props.style
3154
- }
3155
- }));
3156
- });
3157
- const $ea1ef594cf570d83$export$be92b6f5f03c0fe9 = $ea1ef594cf570d83$export$439d29a4e110a164;
3158
- const [$a093c7e1ec25a057$var$createTooltipContext] = $c512c27ab02ef895$export$50c7b4e9d9f19c1("Tooltip", [
3159
- $cf1ac5d9fe0e8206$export$722aac194ae923
3160
- ]);
3161
- const $a093c7e1ec25a057$var$usePopperScope = $cf1ac5d9fe0e8206$export$722aac194ae923();
3162
- const $a093c7e1ec25a057$var$PROVIDER_NAME = "TooltipProvider";
3163
- const $a093c7e1ec25a057$var$DEFAULT_DELAY_DURATION = 700;
3164
- const $a093c7e1ec25a057$var$TOOLTIP_OPEN = "tooltip.open";
3165
- const [$a093c7e1ec25a057$var$TooltipProviderContextProvider, $a093c7e1ec25a057$var$useTooltipProviderContext] = $a093c7e1ec25a057$var$createTooltipContext($a093c7e1ec25a057$var$PROVIDER_NAME);
3166
- const $a093c7e1ec25a057$export$f78649fb9ca566b8 = (props) => {
3167
- const { __scopeTooltip, delayDuration = $a093c7e1ec25a057$var$DEFAULT_DELAY_DURATION, skipDelayDuration = 300, disableHoverableContent = false, children } = props;
3168
- const [isOpenDelayed, setIsOpenDelayed] = useState(true);
3169
- const isPointerInTransitRef = useRef(false);
3170
- const skipDelayTimerRef = useRef(0);
3171
- useEffect(() => {
3172
- const skipDelayTimer = skipDelayTimerRef.current;
3173
- return () => window.clearTimeout(skipDelayTimer);
3174
- }, []);
3175
- return /* @__PURE__ */ createElement($a093c7e1ec25a057$var$TooltipProviderContextProvider, {
3176
- scope: __scopeTooltip,
3177
- isOpenDelayed,
3178
- delayDuration,
3179
- onOpen: useCallback(() => {
3180
- window.clearTimeout(skipDelayTimerRef.current);
3181
- setIsOpenDelayed(false);
3182
- }, []),
3183
- onClose: useCallback(() => {
3184
- window.clearTimeout(skipDelayTimerRef.current);
3185
- skipDelayTimerRef.current = window.setTimeout(
3186
- () => setIsOpenDelayed(true),
3187
- skipDelayDuration
3188
- );
3189
- }, [
3190
- skipDelayDuration
3191
- ]),
3192
- isPointerInTransitRef,
3193
- onPointerInTransitChange: useCallback((inTransit) => {
3194
- isPointerInTransitRef.current = inTransit;
3195
- }, []),
3196
- disableHoverableContent
3197
- }, children);
3198
- };
3199
- const $a093c7e1ec25a057$var$TOOLTIP_NAME = "Tooltip";
3200
- const [$a093c7e1ec25a057$var$TooltipContextProvider, $a093c7e1ec25a057$var$useTooltipContext] = $a093c7e1ec25a057$var$createTooltipContext($a093c7e1ec25a057$var$TOOLTIP_NAME);
3201
- const $a093c7e1ec25a057$export$28c660c63b792dea = (props) => {
3202
- const { __scopeTooltip, children, open: openProp, defaultOpen = false, onOpenChange, disableHoverableContent: disableHoverableContentProp, delayDuration: delayDurationProp } = props;
3203
- const providerContext = $a093c7e1ec25a057$var$useTooltipProviderContext($a093c7e1ec25a057$var$TOOLTIP_NAME, props.__scopeTooltip);
3204
- const popperScope = $a093c7e1ec25a057$var$usePopperScope(__scopeTooltip);
3205
- const [trigger, setTrigger] = useState(null);
3206
- const contentId = $1746a345f3d73bb7$export$f680877a34711e37();
3207
- const openTimerRef = useRef(0);
3208
- const disableHoverableContent = disableHoverableContentProp !== null && disableHoverableContentProp !== void 0 ? disableHoverableContentProp : providerContext.disableHoverableContent;
3209
- const delayDuration = delayDurationProp !== null && delayDurationProp !== void 0 ? delayDurationProp : providerContext.delayDuration;
3210
- const wasOpenDelayedRef = useRef(false);
3211
- const [open1 = false, setOpen] = $71cd76cc60e0454e$export$6f32135080cb4c3({
3212
- prop: openProp,
3213
- defaultProp: defaultOpen,
3214
- onChange: (open) => {
3215
- if (open) {
3216
- providerContext.onOpen();
3217
- document.dispatchEvent(new CustomEvent($a093c7e1ec25a057$var$TOOLTIP_OPEN));
3218
- } else providerContext.onClose();
3219
- onOpenChange === null || onOpenChange === void 0 || onOpenChange(open);
3220
- }
3221
- });
3222
- const stateAttribute = useMemo(() => {
3223
- return open1 ? wasOpenDelayedRef.current ? "delayed-open" : "instant-open" : "closed";
3224
- }, [
3225
- open1
3226
- ]);
3227
- const handleOpen = useCallback(() => {
3228
- window.clearTimeout(openTimerRef.current);
3229
- wasOpenDelayedRef.current = false;
3230
- setOpen(true);
3231
- }, [
3232
- setOpen
3233
- ]);
3234
- const handleClose = useCallback(() => {
3235
- window.clearTimeout(openTimerRef.current);
3236
- setOpen(false);
3237
- }, [
3238
- setOpen
3239
- ]);
3240
- const handleDelayedOpen = useCallback(() => {
3241
- window.clearTimeout(openTimerRef.current);
3242
- openTimerRef.current = window.setTimeout(() => {
3243
- wasOpenDelayedRef.current = true;
3244
- setOpen(true);
3245
- }, delayDuration);
3246
- }, [
3247
- delayDuration,
3248
- setOpen
3249
- ]);
3250
- useEffect(() => {
3251
- return () => window.clearTimeout(openTimerRef.current);
3252
- }, []);
3253
- return /* @__PURE__ */ createElement($cf1ac5d9fe0e8206$export$be92b6f5f03c0fe9, popperScope, /* @__PURE__ */ createElement($a093c7e1ec25a057$var$TooltipContextProvider, {
3254
- scope: __scopeTooltip,
3255
- contentId,
3256
- open: open1,
3257
- stateAttribute,
3258
- trigger,
3259
- onTriggerChange: setTrigger,
3260
- onTriggerEnter: useCallback(() => {
3261
- if (providerContext.isOpenDelayed) handleDelayedOpen();
3262
- else handleOpen();
3263
- }, [
3264
- providerContext.isOpenDelayed,
3265
- handleDelayedOpen,
3266
- handleOpen
3267
- ]),
3268
- onTriggerLeave: useCallback(() => {
3269
- if (disableHoverableContent) handleClose();
3270
- else
3271
- window.clearTimeout(openTimerRef.current);
3272
- }, [
3273
- handleClose,
3274
- disableHoverableContent
3275
- ]),
3276
- onOpen: handleOpen,
3277
- onClose: handleClose,
3278
- disableHoverableContent
3279
- }, children));
3280
- };
3281
- const $a093c7e1ec25a057$var$TRIGGER_NAME = "TooltipTrigger";
3282
- const $a093c7e1ec25a057$export$8c610744efcf8a1d = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
3283
- const { __scopeTooltip, ...triggerProps } = props;
3284
- const context = $a093c7e1ec25a057$var$useTooltipContext($a093c7e1ec25a057$var$TRIGGER_NAME, __scopeTooltip);
3285
- const providerContext = $a093c7e1ec25a057$var$useTooltipProviderContext($a093c7e1ec25a057$var$TRIGGER_NAME, __scopeTooltip);
3286
- const popperScope = $a093c7e1ec25a057$var$usePopperScope(__scopeTooltip);
3287
- const ref = useRef(null);
3288
- const composedRefs = $6ed0406888f73fc4$export$c7b2cbe3552a0d05(forwardedRef, ref, context.onTriggerChange);
3289
- const isPointerDownRef = useRef(false);
3290
- const hasPointerMoveOpenedRef = useRef(false);
3291
- const handlePointerUp = useCallback(
3292
- () => isPointerDownRef.current = false,
3293
- []
3294
- );
3295
- useEffect(() => {
3296
- return () => document.removeEventListener("pointerup", handlePointerUp);
3297
- }, [
3298
- handlePointerUp
3299
- ]);
3300
- return /* @__PURE__ */ createElement($cf1ac5d9fe0e8206$export$b688253958b8dfe7, _extends({
3301
- asChild: true
3302
- }, popperScope), /* @__PURE__ */ createElement($8927f6f2acc4f386$export$250ffa63cdc0d034.button, _extends({
3303
- // We purposefully avoid adding `type=button` here because tooltip triggers are also
3304
- // commonly anchors and the anchor `type` attribute signifies MIME type.
3305
- "aria-describedby": context.open ? context.contentId : void 0,
3306
- "data-state": context.stateAttribute
3307
- }, triggerProps, {
3308
- ref: composedRefs,
3309
- onPointerMove: $e42e1063c40fb3ef$export$b9ecd428b558ff10(props.onPointerMove, (event) => {
3310
- if (event.pointerType === "touch") return;
3311
- if (!hasPointerMoveOpenedRef.current && !providerContext.isPointerInTransitRef.current) {
3312
- context.onTriggerEnter();
3313
- hasPointerMoveOpenedRef.current = true;
3314
- }
3315
- }),
3316
- onPointerLeave: $e42e1063c40fb3ef$export$b9ecd428b558ff10(props.onPointerLeave, () => {
3317
- context.onTriggerLeave();
3318
- hasPointerMoveOpenedRef.current = false;
3319
- }),
3320
- onPointerDown: $e42e1063c40fb3ef$export$b9ecd428b558ff10(props.onPointerDown, () => {
3321
- isPointerDownRef.current = true;
3322
- document.addEventListener("pointerup", handlePointerUp, {
3323
- once: true
3324
- });
3325
- }),
3326
- onFocus: $e42e1063c40fb3ef$export$b9ecd428b558ff10(props.onFocus, () => {
3327
- if (!isPointerDownRef.current) context.onOpen();
3328
- }),
3329
- onBlur: $e42e1063c40fb3ef$export$b9ecd428b558ff10(props.onBlur, context.onClose),
3330
- onClick: $e42e1063c40fb3ef$export$b9ecd428b558ff10(props.onClick, context.onClose)
3331
- })));
3332
- });
3333
- const $a093c7e1ec25a057$var$PORTAL_NAME = "TooltipPortal";
3334
- const [$a093c7e1ec25a057$var$PortalProvider, $a093c7e1ec25a057$var$usePortalContext] = $a093c7e1ec25a057$var$createTooltipContext($a093c7e1ec25a057$var$PORTAL_NAME, {
3335
- forceMount: void 0
3336
- });
3337
- const $a093c7e1ec25a057$export$7b36b8f925ab7497 = (props) => {
3338
- const { __scopeTooltip, forceMount, children, container } = props;
3339
- const context = $a093c7e1ec25a057$var$useTooltipContext($a093c7e1ec25a057$var$PORTAL_NAME, __scopeTooltip);
3340
- return /* @__PURE__ */ createElement($a093c7e1ec25a057$var$PortalProvider, {
3341
- scope: __scopeTooltip,
3342
- forceMount
3343
- }, /* @__PURE__ */ createElement($921a889cee6df7e8$export$99c2b779aa4e8b8b, {
3344
- present: forceMount || context.open
3345
- }, /* @__PURE__ */ createElement($f1701beae083dbae$export$602eac185826482c, {
3346
- asChild: true,
3347
- container
3348
- }, children)));
3349
- };
3350
- const $a093c7e1ec25a057$var$CONTENT_NAME = "TooltipContent";
3351
- const $a093c7e1ec25a057$export$e9003e2be37ec060 = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
3352
- const portalContext = $a093c7e1ec25a057$var$usePortalContext($a093c7e1ec25a057$var$CONTENT_NAME, props.__scopeTooltip);
3353
- const { forceMount = portalContext.forceMount, side = "top", ...contentProps } = props;
3354
- const context = $a093c7e1ec25a057$var$useTooltipContext($a093c7e1ec25a057$var$CONTENT_NAME, props.__scopeTooltip);
3355
- return /* @__PURE__ */ createElement($921a889cee6df7e8$export$99c2b779aa4e8b8b, {
3356
- present: forceMount || context.open
3357
- }, context.disableHoverableContent ? /* @__PURE__ */ createElement($a093c7e1ec25a057$var$TooltipContentImpl, _extends({
3358
- side
3359
- }, contentProps, {
3360
- ref: forwardedRef
3361
- })) : /* @__PURE__ */ createElement($a093c7e1ec25a057$var$TooltipContentHoverable, _extends({
3362
- side
3363
- }, contentProps, {
3364
- ref: forwardedRef
3365
- })));
3366
- });
3367
- const $a093c7e1ec25a057$var$TooltipContentHoverable = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
3368
- const context = $a093c7e1ec25a057$var$useTooltipContext($a093c7e1ec25a057$var$CONTENT_NAME, props.__scopeTooltip);
3369
- const providerContext = $a093c7e1ec25a057$var$useTooltipProviderContext($a093c7e1ec25a057$var$CONTENT_NAME, props.__scopeTooltip);
3370
- const ref = useRef(null);
3371
- const composedRefs = $6ed0406888f73fc4$export$c7b2cbe3552a0d05(forwardedRef, ref);
3372
- const [pointerGraceArea, setPointerGraceArea] = useState(null);
3373
- const { trigger, onClose } = context;
3374
- const content = ref.current;
3375
- const { onPointerInTransitChange } = providerContext;
3376
- const handleRemoveGraceArea = useCallback(() => {
3377
- setPointerGraceArea(null);
3378
- onPointerInTransitChange(false);
3379
- }, [
3380
- onPointerInTransitChange
3381
- ]);
3382
- const handleCreateGraceArea = useCallback((event, hoverTarget) => {
3383
- const currentTarget = event.currentTarget;
3384
- const exitPoint = {
3385
- x: event.clientX,
3386
- y: event.clientY
3387
- };
3388
- const exitSide = $a093c7e1ec25a057$var$getExitSideFromRect(exitPoint, currentTarget.getBoundingClientRect());
3389
- const paddedExitPoints = $a093c7e1ec25a057$var$getPaddedExitPoints(exitPoint, exitSide);
3390
- const hoverTargetPoints = $a093c7e1ec25a057$var$getPointsFromRect(hoverTarget.getBoundingClientRect());
3391
- const graceArea = $a093c7e1ec25a057$var$getHull([
3392
- ...paddedExitPoints,
3393
- ...hoverTargetPoints
3394
- ]);
3395
- setPointerGraceArea(graceArea);
3396
- onPointerInTransitChange(true);
3397
- }, [
3398
- onPointerInTransitChange
3399
- ]);
3400
- useEffect(() => {
3401
- return () => handleRemoveGraceArea();
3402
- }, [
3403
- handleRemoveGraceArea
3404
- ]);
3405
- useEffect(() => {
3406
- if (trigger && content) {
3407
- const handleTriggerLeave = (event) => handleCreateGraceArea(event, content);
3408
- const handleContentLeave = (event) => handleCreateGraceArea(event, trigger);
3409
- trigger.addEventListener("pointerleave", handleTriggerLeave);
3410
- content.addEventListener("pointerleave", handleContentLeave);
3411
- return () => {
3412
- trigger.removeEventListener("pointerleave", handleTriggerLeave);
3413
- content.removeEventListener("pointerleave", handleContentLeave);
3414
- };
3415
- }
3416
- }, [
3417
- trigger,
3418
- content,
3419
- handleCreateGraceArea,
3420
- handleRemoveGraceArea
3421
- ]);
3422
- useEffect(() => {
3423
- if (pointerGraceArea) {
3424
- const handleTrackPointerGrace = (event) => {
3425
- const target = event.target;
3426
- const pointerPosition = {
3427
- x: event.clientX,
3428
- y: event.clientY
3429
- };
3430
- const hasEnteredTarget = (trigger === null || trigger === void 0 ? void 0 : trigger.contains(target)) || (content === null || content === void 0 ? void 0 : content.contains(target));
3431
- const isPointerOutsideGraceArea = !$a093c7e1ec25a057$var$isPointInPolygon(pointerPosition, pointerGraceArea);
3432
- if (hasEnteredTarget) handleRemoveGraceArea();
3433
- else if (isPointerOutsideGraceArea) {
3434
- handleRemoveGraceArea();
3435
- onClose();
3436
- }
3437
- };
3438
- document.addEventListener("pointermove", handleTrackPointerGrace);
3439
- return () => document.removeEventListener("pointermove", handleTrackPointerGrace);
3440
- }
3441
- }, [
3442
- trigger,
3443
- content,
3444
- pointerGraceArea,
3445
- onClose,
3446
- handleRemoveGraceArea
3447
- ]);
3448
- return /* @__PURE__ */ createElement($a093c7e1ec25a057$var$TooltipContentImpl, _extends({}, props, {
3449
- ref: composedRefs
3450
- }));
3451
- });
3452
- const [$a093c7e1ec25a057$var$VisuallyHiddenContentContextProvider, $a093c7e1ec25a057$var$useVisuallyHiddenContentContext] = $a093c7e1ec25a057$var$createTooltipContext($a093c7e1ec25a057$var$TOOLTIP_NAME, {
3453
- isInside: false
3454
- });
3455
- const $a093c7e1ec25a057$var$TooltipContentImpl = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
3456
- const { __scopeTooltip, children, "aria-label": ariaLabel, onEscapeKeyDown, onPointerDownOutside, ...contentProps } = props;
3457
- const context = $a093c7e1ec25a057$var$useTooltipContext($a093c7e1ec25a057$var$CONTENT_NAME, __scopeTooltip);
3458
- const popperScope = $a093c7e1ec25a057$var$usePopperScope(__scopeTooltip);
3459
- const { onClose } = context;
3460
- useEffect(() => {
3461
- document.addEventListener($a093c7e1ec25a057$var$TOOLTIP_OPEN, onClose);
3462
- return () => document.removeEventListener($a093c7e1ec25a057$var$TOOLTIP_OPEN, onClose);
3463
- }, [
3464
- onClose
3465
- ]);
3466
- useEffect(() => {
3467
- if (context.trigger) {
3468
- const handleScroll = (event) => {
3469
- const target = event.target;
3470
- if (target !== null && target !== void 0 && target.contains(context.trigger)) onClose();
3471
- };
3472
- window.addEventListener("scroll", handleScroll, {
3473
- capture: true
3474
- });
3475
- return () => window.removeEventListener("scroll", handleScroll, {
3476
- capture: true
3477
- });
3478
- }
3479
- }, [
3480
- context.trigger,
3481
- onClose
3482
- ]);
3483
- return /* @__PURE__ */ createElement($5cb92bef7577960e$export$177fb62ff3ec1f22, {
3484
- asChild: true,
3485
- disableOutsidePointerEvents: false,
3486
- onEscapeKeyDown,
3487
- onPointerDownOutside,
3488
- onFocusOutside: (event) => event.preventDefault(),
3489
- onDismiss: onClose
3490
- }, /* @__PURE__ */ createElement($cf1ac5d9fe0e8206$export$7c6e2c02157bb7d2, _extends({
3491
- "data-state": context.stateAttribute
3492
- }, popperScope, contentProps, {
3493
- ref: forwardedRef,
3494
- style: {
3495
- ...contentProps.style,
3496
- "--radix-tooltip-content-transform-origin": "var(--radix-popper-transform-origin)",
3497
- "--radix-tooltip-content-available-width": "var(--radix-popper-available-width)",
3498
- "--radix-tooltip-content-available-height": "var(--radix-popper-available-height)",
3499
- "--radix-tooltip-trigger-width": "var(--radix-popper-anchor-width)",
3500
- "--radix-tooltip-trigger-height": "var(--radix-popper-anchor-height)"
3501
- }
3502
- }), /* @__PURE__ */ createElement($5e63c961fc1ce211$export$d9f1ccf0bdb05d45, null, children), /* @__PURE__ */ createElement($a093c7e1ec25a057$var$VisuallyHiddenContentContextProvider, {
3503
- scope: __scopeTooltip,
3504
- isInside: true
3505
- }, /* @__PURE__ */ createElement($ea1ef594cf570d83$export$be92b6f5f03c0fe9, {
3506
- id: context.contentId,
3507
- role: "tooltip"
3508
- }, ariaLabel || children))));
3509
- });
3510
- function $a093c7e1ec25a057$var$getExitSideFromRect(point, rect) {
3511
- const top = Math.abs(rect.top - point.y);
3512
- const bottom = Math.abs(rect.bottom - point.y);
3513
- const right = Math.abs(rect.right - point.x);
3514
- const left = Math.abs(rect.left - point.x);
3515
- switch (Math.min(top, bottom, right, left)) {
3516
- case left:
3517
- return "left";
3518
- case right:
3519
- return "right";
3520
- case top:
3521
- return "top";
3522
- case bottom:
3523
- return "bottom";
3524
- default:
3525
- throw new Error("unreachable");
3526
- }
3527
- }
3528
- function $a093c7e1ec25a057$var$getPaddedExitPoints(exitPoint, exitSide, padding = 5) {
3529
- const paddedExitPoints = [];
3530
- switch (exitSide) {
3531
- case "top":
3532
- paddedExitPoints.push({
3533
- x: exitPoint.x - padding,
3534
- y: exitPoint.y + padding
3535
- }, {
3536
- x: exitPoint.x + padding,
3537
- y: exitPoint.y + padding
3538
- });
3539
- break;
3540
- case "bottom":
3541
- paddedExitPoints.push({
3542
- x: exitPoint.x - padding,
3543
- y: exitPoint.y - padding
3544
- }, {
3545
- x: exitPoint.x + padding,
3546
- y: exitPoint.y - padding
3547
- });
3548
- break;
3549
- case "left":
3550
- paddedExitPoints.push({
3551
- x: exitPoint.x + padding,
3552
- y: exitPoint.y - padding
3553
- }, {
3554
- x: exitPoint.x + padding,
3555
- y: exitPoint.y + padding
3556
- });
3557
- break;
3558
- case "right":
3559
- paddedExitPoints.push({
3560
- x: exitPoint.x - padding,
3561
- y: exitPoint.y - padding
3562
- }, {
3563
- x: exitPoint.x - padding,
3564
- y: exitPoint.y + padding
3565
- });
3566
- break;
3567
- }
3568
- return paddedExitPoints;
3569
- }
3570
- function $a093c7e1ec25a057$var$getPointsFromRect(rect) {
3571
- const { top, right, bottom, left } = rect;
3572
- return [
3573
- {
3574
- x: left,
3575
- y: top
3576
- },
3577
- {
3578
- x: right,
3579
- y: top
3580
- },
3581
- {
3582
- x: right,
3583
- y: bottom
3584
- },
3585
- {
3586
- x: left,
3587
- y: bottom
3588
- }
3589
- ];
3590
- }
3591
- function $a093c7e1ec25a057$var$isPointInPolygon(point, polygon) {
3592
- const { x, y } = point;
3593
- let inside = false;
3594
- for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
3595
- const xi = polygon[i].x;
3596
- const yi = polygon[i].y;
3597
- const xj = polygon[j].x;
3598
- const yj = polygon[j].y;
3599
- const intersect = yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
3600
- if (intersect) inside = !inside;
3601
- }
3602
- return inside;
3603
- }
3604
- function $a093c7e1ec25a057$var$getHull(points) {
3605
- const newPoints = points.slice();
3606
- newPoints.sort((a, b) => {
3607
- if (a.x < b.x) return -1;
3608
- else if (a.x > b.x) return 1;
3609
- else if (a.y < b.y) return -1;
3610
- else if (a.y > b.y) return 1;
3611
- else return 0;
3612
- });
3613
- return $a093c7e1ec25a057$var$getHullPresorted(newPoints);
3614
- }
3615
- function $a093c7e1ec25a057$var$getHullPresorted(points) {
3616
- if (points.length <= 1) return points.slice();
3617
- const upperHull = [];
3618
- for (let i = 0; i < points.length; i++) {
3619
- const p = points[i];
3620
- while (upperHull.length >= 2) {
3621
- const q = upperHull[upperHull.length - 1];
3622
- const r = upperHull[upperHull.length - 2];
3623
- if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x)) upperHull.pop();
3624
- else break;
3625
- }
3626
- upperHull.push(p);
3627
- }
3628
- upperHull.pop();
3629
- const lowerHull = [];
3630
- for (let i1 = points.length - 1; i1 >= 0; i1--) {
3631
- const p = points[i1];
3632
- while (lowerHull.length >= 2) {
3633
- const q = lowerHull[lowerHull.length - 1];
3634
- const r = lowerHull[lowerHull.length - 2];
3635
- if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x)) lowerHull.pop();
3636
- else break;
3637
- }
3638
- lowerHull.push(p);
3639
- }
3640
- lowerHull.pop();
3641
- if (upperHull.length === 1 && lowerHull.length === 1 && upperHull[0].x === lowerHull[0].x && upperHull[0].y === lowerHull[0].y) return upperHull;
3642
- else return upperHull.concat(lowerHull);
3643
- }
3644
- const $a093c7e1ec25a057$export$2881499e37b75b9a = $a093c7e1ec25a057$export$f78649fb9ca566b8;
3645
- const $a093c7e1ec25a057$export$be92b6f5f03c0fe9 = $a093c7e1ec25a057$export$28c660c63b792dea;
3646
- const $a093c7e1ec25a057$export$41fb9f06171c75f4 = $a093c7e1ec25a057$export$8c610744efcf8a1d;
3647
- const $a093c7e1ec25a057$export$602eac185826482c = $a093c7e1ec25a057$export$7b36b8f925ab7497;
3648
- const $a093c7e1ec25a057$export$7c6e2c02157bb7d2 = $a093c7e1ec25a057$export$e9003e2be37ec060;
3649
- function Tooltip({ description }) {
3650
- return /* @__PURE__ */ jsx($a093c7e1ec25a057$export$2881499e37b75b9a, { children: /* @__PURE__ */ jsxs($a093c7e1ec25a057$export$be92b6f5f03c0fe9, { children: [
3651
- /* @__PURE__ */ jsx($a093c7e1ec25a057$export$41fb9f06171c75f4, { asChild: true, children: /* @__PURE__ */ jsx(Information, { "aria-hidden": "true" }) }),
3652
- /* @__PURE__ */ jsx($a093c7e1ec25a057$export$602eac185826482c, { children: /* @__PURE__ */ jsx($a093c7e1ec25a057$export$7c6e2c02157bb7d2, { sideOffset: 5, style: { zIndex: 9999 }, children: /* @__PURE__ */ jsx(
3653
- Box,
3654
- {
3655
- padding: 2,
3656
- margin: 2,
3657
- background: "neutral1000",
3658
- hasRadius: true,
3659
- shadow: "filterShadow",
3660
- maxWidth: "300px",
3661
- children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral0", children: description })
3662
- }
3663
- ) }) })
3664
- ] }) });
3665
- }
3666
- function PathInput({ path, dispatchPath, isOverride, config, hasUserInteracted }) {
3667
- const { formatMessage } = useIntl();
3668
- const displayedPath = isOverride && path.overridePath !== void 0 ? path.overridePath : path.value ?? "";
3669
- const inputBorder = path.replacement === null ? "" : path.replacement ? "1px solid #ee5e52" : "1px solid #5cb176";
3670
- return /* @__PURE__ */ jsxs(
3671
- Field.Root,
3672
- {
3673
- hint: config.default ? formatMessage({
3674
- id: getTranslation("components.CMEditViewAside.path.input.start"),
3675
- defaultMessage: "Edit the"
3676
- }) + ' "' + config.default + '" ' + formatMessage({
3677
- id: getTranslation("components.CMEditViewAside.path.input.end"),
3678
- defaultMessage: "field to generate a path"
3679
- }) : formatMessage({
3680
- id: getTranslation("components.CMEditViewAside.path.input.noSourceField"),
3681
- defaultMessage: "Use the override option to set a custom path"
3682
- }),
3683
- children: [
3684
- /* @__PURE__ */ jsxs(Field.Label, { children: [
3685
- formatMessage({
3686
- id: getTranslation("components.CMEditViewAside.path.input.label"),
3687
- defaultMessage: "Path"
3688
- }),
3689
- /* @__PURE__ */ jsx(
3690
- Tooltip,
3691
- {
3692
- description: formatMessage({
3693
- id: getTranslation("components.CMEditViewAside.path.input.tooltip"),
3694
- defaultMessage: "The following characters are valid: A-Z, a-z, 0-9, /, -, _, $, ., +, !, *, ', (, )"
3695
- })
3696
- }
3697
- )
3698
- ] }),
3699
- /* @__PURE__ */ jsx(
3700
- Field.Input,
3701
- {
3702
- id: "path-input",
3703
- value: displayedPath,
3704
- onChange: (e) => {
3705
- hasUserInteracted.current = true;
3706
- dispatchPath({ type: "SET_OVERRIDEPATH", payload: e.target.value });
3707
- },
3708
- disabled: !isOverride,
3709
- onBlur: (e) => {
3710
- dispatchPath({
3711
- type: "SET_OVERRIDEPATH",
3712
- payload: transformToUrl(e.target.value, false)
3713
- });
3714
- dispatchPath({
3715
- type: "SET_URL_CHECK_FLAG",
3716
- payload: true
3717
- });
3718
- },
3719
- style: { outline: inputBorder }
3720
- }
3721
- ),
3722
- /* @__PURE__ */ jsx(Field.Hint, {})
3723
- ]
3724
- }
3725
- );
3726
- }
3727
- function RouteStructure({
3728
- routes,
3729
- selectedParent,
3730
- setSelectedParent,
3731
- canonicalPath,
3732
- prohibitedRouteIds
3733
- }) {
3734
- const { formatMessage } = useIntl();
3735
- const filteredRoutes = useMemo(() => {
3736
- return [...routes].sort((a, b) => a.title.localeCompare(b.title)).filter(
3737
- (route) => !prohibitedRouteIds?.includes(route.documentId) || route.documentId === selectedParent?.documentId
3738
- );
3739
- }, [routes, prohibitedRouteIds, selectedParent]);
3740
- const handleSelectParent = (value) => {
3741
- const parentRoute = routes.find((route) => route.documentId === value) || null;
3742
- setSelectedParent(parentRoute);
3743
- };
3744
- return /* @__PURE__ */ jsxs(Box, { paddingBottom: 2, children: [
3745
- /* @__PURE__ */ jsxs(Field.Root, { children: [
3746
- /* @__PURE__ */ jsx(Field.Label, { children: formatMessage({
3747
- id: getTranslation("components.CMEditViewAside.path.input.parentSelect.label"),
3748
- defaultMessage: "Place under"
3749
- }) }),
3750
- /* @__PURE__ */ jsxs(SingleSelect, { value: selectedParent?.documentId || "", onValueChange: handleSelectParent, children: [
3751
- /* @__PURE__ */ jsx(SingleSelectOption, { value: "", children: formatMessage({
3752
- id: getTranslation("components.CMEditViewAside.path.input.parentSelect.rootPath"),
3753
- defaultMessage: "None (root path)"
3754
- }) }),
3755
- filteredRoutes.map((route) => /* @__PURE__ */ jsx(SingleSelectOption, { value: route.documentId, children: route.title }, route.documentId))
3756
- ] })
3757
- ] }),
3758
- /* @__PURE__ */ jsxs(Field.Root, { marginTop: 4, children: [
3759
- /* @__PURE__ */ jsxs(Field.Label, { children: [
3760
- formatMessage({
3761
- id: getTranslation("components.CMEditViewAside.canonicalPath.input.label"),
3762
- defaultMessage: "Canonical Path"
3763
- }),
3764
- /* @__PURE__ */ jsx(
3765
- Tooltip,
3766
- {
3767
- description: formatMessage({
3768
- id: getTranslation("components.CMEditViewAside.canonicalPath.input.tooltip"),
3769
- defaultMessage: "The path determined by your content's natural hierarchy, independent of where it appears in navigation menus."
3770
- })
3771
- }
3772
- )
3773
- ] }),
3774
- /* @__PURE__ */ jsx(Field.Input, { id: "canonicalPath-input", value: canonicalPath, disabled: true }),
3775
- /* @__PURE__ */ jsx(Field.Hint, {})
3776
- ] })
3777
- ] });
3778
- }
3779
- function buildPath(type, slug, parent) {
3780
- const parentSlug = type === "canonical" ? parent?.canonicalPath : parent?.path;
3781
- const parentPath = parentSlug ? `${parentSlug}/` : "";
3782
- return `${parentPath}${transformToUrl(slug)}`;
3783
- }
3784
- function reducer(state, action) {
3785
- switch (action.type) {
3786
- case "DEFAULT":
3787
- return {
3788
- ...state,
3789
- value: action.payload,
3790
- prevValue: state.value,
3791
- needsUrlCheck: true
3792
- };
3793
- case "NO_URL_CHECK":
3794
- return {
3795
- ...state,
3796
- value: action.payload,
3797
- prevValue: state.value,
3798
- needsUrlCheck: false
3799
- };
3800
- case "NO_TRANSFORM_AND_CHECK":
3801
- return {
3802
- ...state,
3803
- value: action.payload,
3804
- prevValue: state.value,
3805
- needsUrlCheck: false
3806
- };
3807
- case "SET_URL_CHECK_FLAG":
3808
- return { ...state, needsUrlCheck: action.payload || false };
3809
- case "SET_REPLACEMENT":
3810
- return { ...state, replacement: action.payload };
3811
- case "SET_UIDPATH":
3812
- return { ...state, uidPath: action.payload };
3813
- case "SET_SLUG":
3814
- return { ...state, slug: action.payload };
3815
- case "SET_CANONICALPATH":
3816
- return { ...state, canonicalPath: action.payload };
3817
- case "SET_OVERRIDEPATH":
3818
- return { ...state, overridePath: action.payload };
3819
- default:
3820
- throw new Error();
3821
- }
3822
- }
3823
- const Panel = ({ config }) => {
3824
- const { form, model } = unstable_useContentManagerContext();
3825
- const { initialValues, values, onChange } = form;
3826
- const { getRelatedRoute, getAllRoutes, getProhibitedRouteIds } = useApi();
3827
- const { formatMessage } = useIntl();
3828
- const { get } = useFetchClient();
3829
- const {
3830
- allowedActions: { canUpdate, canCreate }
3831
- } = useRBAC([
3832
- {
3833
- action: "plugin::content-manager.explorer.update",
3834
- subject: model,
3835
- properties: {},
3836
- conditions: []
3837
- },
3838
- {
3839
- action: "plugin::content-manager.explorer.create",
3840
- subject: model,
3841
- properties: {},
3842
- conditions: []
3843
- }
3844
- ]);
3845
- const [route, setRoute] = useState(null);
3846
- const [routes, setRoutes] = useState([]);
3847
- const [prohibitedRouteIds, setProhibitedRouteIds] = useState([]);
3848
- const [selectedParent, setSelectedParent] = useState(null);
3849
- const [isOverride, setIsOverride] = useState(false);
3850
- const [validationState, setValidationState] = useState("initial");
3851
- const [initialLoadComplete, setInitialLoadComplete] = useState(false);
3852
- const [path, dispatchPath] = useReducer(reducer, {
3853
- needsUrlCheck: false,
3854
- value: "",
3855
- prevValue: "",
3856
- replacement: null,
3857
- uidPath: "",
3858
- canonicalPath: "",
3859
- slug: "",
3860
- overridePath: ""
3861
- });
3862
- const hasUserChangedField = useRef(false);
3863
- const hasUserInteracted = useRef(false);
3864
- const initialPath = useRef("");
3865
- const prevSourceValueRef = useRef(null);
3866
- const sourceFieldValue = values[config?.default] || "";
3867
- const initialSourceFieldValue = initialValues[config?.default] || "";
3868
- const latestCheckPathRef = useRef(checkPath);
3869
- latestCheckPathRef.current = checkPath;
3870
- const debouncedCheckPath = useRef(
3871
- debounce((p, id) => latestCheckPathRef.current(p, id), 250)
3872
- ).current;
3873
- const latestCheckCanonicalRef = useRef(checkCanonicalPath);
3874
- latestCheckCanonicalRef.current = checkCanonicalPath;
3875
- const debouncedCheckCanonicalPath = useRef(
3876
- debounce((p, id) => latestCheckCanonicalRef.current(p, id), 250)
3877
- ).current;
3878
- useEffect(() => {
3879
- async function fetchAllRoutes() {
3880
- const allRoutes = await getAllRoutes();
3881
- setRoutes(allRoutes);
3882
- }
3883
- fetchAllRoutes();
3884
- }, []);
3885
- useEffect(() => {
3886
- const slug = transformToUrl(sourceFieldValue);
3887
- const overridePath = transformToUrl(path.overridePath || "", false);
3888
- const data = {
3889
- path: isOverride ? overridePath : path.value,
3890
- isOverride,
3891
- parentDocumentId: selectedParent?.documentId || null,
3892
- slug: isOverride ? overridePath : slug
3893
- };
3894
- if (hasUserChangedField.current || hasUserInteracted.current) {
3895
- onChange("webatlas", data);
3896
- }
3897
- }, [
3898
- path.value,
3899
- path.overridePath,
3900
- isOverride,
3901
- selectedParent,
3902
- sourceFieldValue,
3903
- hasUserChangedField,
3904
- hasUserInteracted
3905
- ]);
3906
- useEffect(() => {
3907
- if (!initialLoadComplete) return;
3908
- if (sourceFieldValue !== initialSourceFieldValue) {
3909
- hasUserChangedField.current = true;
3910
- }
3911
- if (!sourceFieldValue) {
3912
- dispatchPath({ type: "NO_URL_CHECK", payload: "" });
3913
- return;
3914
- }
3915
- if (initialLoadComplete && (hasUserChangedField.current || !route) && prevSourceValueRef.current !== sourceFieldValue && !isOverride) {
3916
- const newPath = buildPath("path", sourceFieldValue, selectedParent);
3917
- const type = sourceFieldValue === initialSourceFieldValue ? "NO_URL_CHECK" : "DEFAULT";
3918
- const slug = transformToUrl(sourceFieldValue);
3919
- dispatchPath({ type, payload: newPath });
3920
- dispatchPath({ type: "SET_SLUG", payload: slug });
3921
- dispatchPath({ type: "SET_OVERRIDEPATH", payload: slug });
3922
- prevSourceValueRef.current = sourceFieldValue;
3923
- }
3924
- const canonicalPath = buildPath("canonical", sourceFieldValue, selectedParent);
3925
- dispatchPath({ type: "SET_CANONICALPATH", payload: canonicalPath });
3926
- debouncedCheckCanonicalPath(canonicalPath, route?.documentId || null);
3927
- }, [
3928
- sourceFieldValue,
3929
- initialSourceFieldValue,
3930
- initialLoadComplete,
3931
- selectedParent,
3932
- isOverride,
3933
- route
3934
- ]);
3935
- useEffect(() => {
3936
- if (!initialLoadComplete) return;
3937
- if (path.needsUrlCheck && path.value) {
3938
- if (path.uidPath === path.value || initialPath.current === path.value) return;
3939
- debouncedCheckPath(path.value, route?.documentId || null);
3940
- dispatchPath({ type: "SET_URL_CHECK_FLAG" });
3941
- } else {
3942
- setValidationState("idle");
3943
- dispatchPath({ type: "SET_REPLACEMENT", payload: null });
3944
- }
3945
- }, [path.needsUrlCheck, path.value, path.uidPath, route, initialLoadComplete]);
3946
- useEffect(() => {
3947
- async function fetchRelatedRute() {
3948
- if (!initialValues.documentId) {
3949
- setInitialLoadComplete(true);
3950
- return;
3951
- }
3952
- try {
3953
- const route2 = await getRelatedRoute(initialValues.documentId);
3954
- if (!route2) return;
3955
- initialPath.current = route2.uidPath;
3956
- setRoute(route2);
3957
- setIsOverride(route2.isOverride || false);
3958
- dispatchPath({ type: "SET_OVERRIDEPATH", payload: route2.path || "" });
3959
- dispatchPath({
3960
- type: "NO_TRANSFORM_AND_CHECK",
3961
- payload: route2.path || ""
3962
- });
3963
- dispatchPath({ type: "SET_UIDPATH", payload: route2.uidPath || "" });
3964
- dispatchPath({ type: "SET_SLUG", payload: route2.slug || "" });
3965
- dispatchPath({
3966
- type: "SET_CANONICALPATH",
3967
- payload: route2.canonicalPath || ""
3968
- });
3969
- const key = config?.default;
3970
- if (key) {
3971
- prevSourceValueRef.current = values[key];
3972
- }
3973
- } catch (err) {
3974
- setRoute(null);
3975
- strapi.log.error(err);
3976
- } finally {
3977
- setInitialLoadComplete(true);
3978
- }
3979
- }
3980
- fetchRelatedRute();
3981
- }, [config]);
3982
- useEffect(() => {
3983
- if (!route || !routes.length) return;
3984
- const parentRoute = routes.find(
3985
- (singleRoute) => singleRoute.documentId === route.parent?.documentId
3986
- );
3987
- setSelectedParent(parentRoute || null);
3988
- }, [route, routes]);
3989
- useEffect(() => {
3990
- async function fetchProhibitedRouteIds() {
3991
- const prohibitedIds = await getProhibitedRouteIds(route?.documentId);
3992
- setProhibitedRouteIds(prohibitedIds);
3993
- }
3994
- fetchProhibitedRouteIds();
3995
- }, [route]);
3996
- useEffect(() => {
3997
- if (!sourceFieldValue || isOverride || !hasUserChangedField.current && !hasUserInteracted.current)
3998
- return;
3999
- const newPath = buildPath("path", sourceFieldValue, selectedParent);
4000
- dispatchPath({ type: "DEFAULT", payload: newPath });
4001
- }, [selectedParent, sourceFieldValue, route, isOverride]);
4002
- async function checkCanonicalPath(path2, routeDocumentId) {
4003
- if (!path2) return;
4004
- try {
4005
- const result = await duplicateCheck({
4006
- fetchFunction: get,
4007
- path: path2,
4008
- routeDocumentId,
4009
- withoutTransform: true
4010
- });
4011
- dispatchPath({ type: "SET_CANONICALPATH", payload: result });
4012
- } catch (err) {
4013
- strapi.log.error(err);
4014
- }
4015
- }
4016
- async function checkPath(path2, routeDocumentId) {
4017
- if (!path2) return;
4018
- setValidationState("checking");
4019
- dispatchPath({ type: "SET_REPLACEMENT", payload: "" });
4020
- try {
4021
- const data = await duplicateCheck({
4022
- fetchFunction: get,
4023
- path: path2,
4024
- routeDocumentId,
4025
- withoutTransform: true
4026
- });
4027
- if (!data || data === path2) return;
4028
- dispatchPath({ type: "NO_URL_CHECK", payload: data });
4029
- dispatchPath({ type: "SET_REPLACEMENT", payload: data });
4030
- } catch (err) {
4031
- strapi.log.error(err);
4032
- } finally {
4033
- setValidationState("done");
4034
- }
4035
- }
4036
- if (!initialLoadComplete)
4037
- return /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage({
4038
- id: getTranslation("loading"),
4039
- defaultMessage: "Loading..."
4040
- }) });
4041
- return /* @__PURE__ */ jsx(Box, { tag: "aside", "aria-labelledby": "URL Route", width: "100%", children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
4042
- !route && /* @__PURE__ */ jsxs(Fragment$1, { children: [
4043
- /* @__PURE__ */ jsx(NewPathInfo, {}),
4044
- /* @__PURE__ */ jsx(Divider, { marginTop: 2, marginBottom: 2 })
4045
- ] }),
4046
- /* @__PURE__ */ jsx(
4047
- RouteStructure,
4048
- {
4049
- canonicalPath: path.canonicalPath,
4050
- routes,
4051
- selectedParent,
4052
- setSelectedParent: (val) => {
4053
- hasUserInteracted.current = true;
4054
- setSelectedParent(val);
4055
- },
4056
- prohibitedRouteIds
4057
- }
4058
- ),
4059
- /* @__PURE__ */ jsx(Divider, { marginTop: 2, marginBottom: 2 }),
4060
- /* @__PURE__ */ jsxs(Box, { children: [
4061
- /* @__PURE__ */ jsx(
4062
- PathInput,
4063
- {
4064
- path,
4065
- dispatchPath,
4066
- isOverride,
4067
- config,
4068
- hasUserInteracted
4069
- }
4070
- ),
4071
- validationState !== "initial" && /* @__PURE__ */ jsx(PathInfo, { validationState, replacement: path.replacement })
4072
- ] }),
4073
- /* @__PURE__ */ jsx(
4074
- OverrideCheckbox,
4075
- {
4076
- isOverride,
4077
- setIsOverride: (val) => {
4078
- hasUserInteracted.current = true;
4079
- setIsOverride(val);
4080
- },
4081
- disabledCondition: !canCreate && !canUpdate
4082
- }
4083
- ),
4084
- path.uidPath && /* @__PURE__ */ jsxs(Fragment$1, { children: [
4085
- /* @__PURE__ */ jsx(Divider, { marginTop: 2, marginBottom: 2 }),
4086
- /* @__PURE__ */ jsx(UidPathDisplay, { path: path.uidPath })
4087
- ] })
4088
- ] }) });
4089
- };
4090
- const pluginPermissions = {
4091
- "cm.aside": [{ action: `plugin::${PLUGIN_ID}.cm.aside`, subject: null }],
4092
- "page.navigation": [{ action: `plugin::${PLUGIN_ID}.page.navigation`, subject: null }],
4093
- "page.routes": [{ action: `plugin::${PLUGIN_ID}.page.routes`, subject: null }],
4094
- "settings.general": [{ action: `plugin::${PLUGIN_ID}.settings.general`, subject: null }],
4095
- "settings.navigation": [{ action: `plugin::${PLUGIN_ID}.settings.navigation`, subject: null }]
4096
- };
4097
- const CMEditViewAside = ({ model }) => {
4098
- const { contentTypes } = useAllContentTypes();
4099
- const { config } = usePluginConfig();
4100
- const { formatMessage } = useIntl();
4101
- const [isAllowedContentType, setIsAllowedContentType] = useState(false);
4102
- const [isLoading, setIsLoading] = useState(true);
4103
- const [contentTypeConfig, setContentTypeConfig] = useState(null);
4104
- const [isActiveContentType, setIsActiveContentType] = useState(false);
4105
- const panelTitle = PLUGIN_NAME;
4106
- useEffect(() => {
4107
- const contentType = contentTypes?.find((ct) => ct.uid === model);
4108
- setIsAllowedContentType(!!contentType?.pluginOptions?.webatlas?.enabled);
4109
- }, [contentTypes, model]);
4110
- useEffect(() => {
4111
- if (!config) return;
4112
- setIsActiveContentType(false);
4113
- setContentTypeConfig(null);
4114
- config?.selectedContentTypes?.forEach((type) => {
4115
- if (type.uid === model) {
4116
- setIsActiveContentType(true);
4117
- setContentTypeConfig(type);
4118
- }
4119
- });
4120
- setIsLoading(false);
4121
- }, [config, model]);
4122
- const {
4123
- allowedActions: { canAside }
4124
- } = useRBAC({
4125
- cmAside: pluginPermissions["cm.aside"]
4126
- });
4127
- if (!canAside || !isAllowedContentType || !isActiveContentType || !contentTypeConfig) return null;
4128
- if (!config) {
4129
- strapi.log.error("CMEditViewAside: Plugin is not configured.");
4130
- return null;
4131
- }
4132
- if (isLoading)
4133
- return {
4134
- title: panelTitle,
4135
- content: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage({
4136
- id: getTranslation("loading"),
4137
- defaultMessage: "Loading..."
4138
- }) })
4139
- };
4140
- return {
4141
- title: panelTitle,
4142
- content: /* @__PURE__ */ jsx(Panel, { config: contentTypeConfig })
4143
- };
4144
- };
4145
- const index = {
4146
- register(app) {
4147
- app.addMenuLink({
4148
- to: `plugins/${PLUGIN_ID}/paths`,
4149
- icon: PathIcon,
4150
- intlLabel: {
4151
- id: `${PLUGIN_ID}.link.paths`,
4152
- defaultMessage: "Paths"
4153
- },
4154
- Component: () => import("./index-Bp-XFH1V.mjs"),
4155
- permissions: [pluginPermissions["page.routes"][0]]
4156
- });
4157
- app.addMenuLink({
4158
- to: `plugins/${PLUGIN_ID}/navigation`,
4159
- icon: NavigationIcon,
4160
- intlLabel: {
4161
- id: `${PLUGIN_ID}.link.navigation`,
4162
- defaultMessage: "Navigation"
4163
- },
4164
- Component: () => import("./index-DjLi4gIu.mjs"),
4165
- permissions: [pluginPermissions["page.navigation"][0]]
4166
- });
4167
- app.addSettingsLink(
4168
- {
4169
- id: PLUGIN_ID,
4170
- intlLabel: {
4171
- id: `${PLUGIN_ID}.settings.section`,
4172
- defaultMessage: PLUGIN_NAME
4173
- }
4174
- },
4175
- {
4176
- intlLabel: {
4177
- id: `${PLUGIN_ID}.settings.section.general`,
4178
- defaultMessage: "General"
4179
- },
4180
- id: `${PLUGIN_ID}-general`,
4181
- to: `${PLUGIN_ID}/general`,
4182
- Component: () => import("./index-DqA1gNsu.mjs"),
4183
- permissions: [pluginPermissions["settings.general"][0]]
4184
- }
4185
- );
4186
- app.addSettingsLink(PLUGIN_ID, {
4187
- intlLabel: {
4188
- id: `${PLUGIN_ID}.settings.navigation`,
4189
- defaultMessage: "Navigation"
4190
- },
4191
- id: `${PLUGIN_ID}-navigation`,
4192
- to: `${PLUGIN_ID}/navigation`,
4193
- Component: () => import("./index-DLMGEpc0.mjs"),
4194
- permissions: [pluginPermissions["settings.navigation"][0]]
4195
- });
4196
- app.customFields.register({
4197
- name: "route-picker",
4198
- pluginId: PLUGIN_ID,
4199
- type: "string",
4200
- intlLabel: {
4201
- id: `${PLUGIN_ID}.route-picker.label`,
4202
- defaultMessage: "Route Picker"
4203
- },
4204
- intlDescription: {
4205
- id: `${PLUGIN_ID}.route-picker.description`,
4206
- defaultMessage: "Select a route"
4207
- },
4208
- components: {
4209
- Input: async () => import("./RoutePicker-C6omysLv.mjs").then((module) => ({
4210
- default: module.default
4211
- }))
4212
- },
4213
- options: {
4214
- advanced: [
4215
- {
4216
- sectionTitle: {
4217
- id: "global.settings",
4218
- defaultMessage: "Settings"
4219
- },
4220
- items: [
4221
- {
4222
- name: "required",
4223
- type: "checkbox",
4224
- intlLabel: {
4225
- id: "content-type-builder.form.attribute.item.requiredField",
4226
- defaultMessage: "Required field"
4227
- },
4228
- description: {
4229
- id: "content-type-builder.form.attribute.item.requiredField.description",
4230
- defaultMessage: "You won't be able to create an entry if this field is empty"
4231
- }
4232
- }
4233
- ]
4234
- }
4235
- ]
4236
- }
4237
- });
4238
- app.registerPlugin({
4239
- id: PLUGIN_ID,
4240
- initializer: Initializer,
4241
- isReady: false,
4242
- name: PLUGIN_ID
4243
- });
4244
- },
4245
- bootstrap(app) {
4246
- app.getPlugin("content-manager").apis.addEditViewSidePanel([CMEditViewAside]);
4247
- },
4248
- async registerTrads({ locales }) {
4249
- return Promise.all(
4250
- locales.map(async (locale) => {
4251
- try {
4252
- const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => import("./de-B5pRvs13.mjs"), "./translations/en.json": () => import("./en-BE-zzIv8.mjs") }), `./translations/${locale}.json`, 3);
4253
- return { data, locale };
4254
- } catch {
4255
- return { data: {}, locale };
4256
- }
4257
- })
4258
- );
4259
- }
4260
- };
4261
- export {
4262
- PLUGIN_ID as P,
4263
- Tooltip as T,
4264
- duplicateCheck as a,
4265
- PathInfo as b,
4266
- usePluginConfig as c,
4267
- debounce as d,
4268
- useAllContentTypes as e,
4269
- PLUGIN_NAME as f,
4270
- getTranslation as g,
4271
- PLUGIN_VERSION as h,
4272
- index as i,
4273
- pluginPermissions as p,
4274
- useApi as u
4275
- };