@activecollab/components 2.0.554 → 2.0.556

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.
Files changed (38) hide show
  1. package/dist/cjs/components/ModalRoot/ModalRoot.js +248 -25
  2. package/dist/cjs/components/ModalRoot/ModalRoot.js.map +1 -1
  3. package/dist/cjs/components/ModalRoot/Styles.js +2 -1
  4. package/dist/cjs/components/ModalRoot/Styles.js.map +1 -1
  5. package/dist/cjs/components/ModalRoot/modalRootStack.js +92 -23
  6. package/dist/cjs/components/ModalRoot/modalRootStack.js.map +1 -1
  7. package/dist/cjs/components/ModalRoot/useModalStackHost.js +8 -2
  8. package/dist/cjs/components/ModalRoot/useModalStackHost.js.map +1 -1
  9. package/dist/cjs/utils/layers.js +8 -3
  10. package/dist/cjs/utils/layers.js.map +1 -1
  11. package/dist/cjs/utils/layers.test.js +15 -0
  12. package/dist/cjs/utils/layers.test.js.map +1 -1
  13. package/dist/esm/components/ModalRoot/ModalRoot.d.ts +6 -2
  14. package/dist/esm/components/ModalRoot/ModalRoot.d.ts.map +1 -1
  15. package/dist/esm/components/ModalRoot/ModalRoot.js +246 -27
  16. package/dist/esm/components/ModalRoot/ModalRoot.js.map +1 -1
  17. package/dist/esm/components/ModalRoot/Styles.d.ts.map +1 -1
  18. package/dist/esm/components/ModalRoot/Styles.js +2 -1
  19. package/dist/esm/components/ModalRoot/Styles.js.map +1 -1
  20. package/dist/esm/components/ModalRoot/modalRootStack.d.ts +12 -0
  21. package/dist/esm/components/ModalRoot/modalRootStack.d.ts.map +1 -1
  22. package/dist/esm/components/ModalRoot/modalRootStack.js +66 -17
  23. package/dist/esm/components/ModalRoot/modalRootStack.js.map +1 -1
  24. package/dist/esm/components/ModalRoot/useModalStackHost.d.ts +3 -1
  25. package/dist/esm/components/ModalRoot/useModalStackHost.d.ts.map +1 -1
  26. package/dist/esm/components/ModalRoot/useModalStackHost.js +8 -2
  27. package/dist/esm/components/ModalRoot/useModalStackHost.js.map +1 -1
  28. package/dist/esm/utils/layers.d.ts +4 -1
  29. package/dist/esm/utils/layers.d.ts.map +1 -1
  30. package/dist/esm/utils/layers.js +6 -3
  31. package/dist/esm/utils/layers.js.map +1 -1
  32. package/dist/esm/utils/layers.test.js +15 -0
  33. package/dist/esm/utils/layers.test.js.map +1 -1
  34. package/dist/index.js +419 -122
  35. package/dist/index.js.map +1 -1
  36. package/dist/index.min.js +1 -1
  37. package/dist/index.min.js.map +1 -1
  38. package/package.json +1 -1
@@ -4,10 +4,11 @@ const _excluded = ["open", "onRequestClose", "onDismissBlocked", "onClose", "dis
4
4
  import React, { forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
5
5
  import { RemoveScroll } from "react-remove-scroll";
6
6
  import classnames from "classnames";
7
- import { areModalRootsSuspended, isTopModalRoot, popModalRoot, pushModalRoot } from "./modalRootStack";
7
+ import { areModalRootsSuspended, getTopModalRootId, isTopModalRoot, popModalRoot, pushModalRoot, releaseModalRoot, reopenModalRoot, subscribeToModalRoots } from "./modalRootStack";
8
8
  import { StyledModalRoot } from "./Styles";
9
+ import { MODAL_STACK_HOST_ATTRIBUTE } from "./useModalStackHost";
9
10
  import { Portal, PortalContainerProvider } from "../../helpers";
10
- import { layers } from "../../utils/layers";
11
+ import { getTopLayer, layers } from "../../utils/layers";
11
12
  import useForkRef from "../../utils/useForkRef";
12
13
  const FOCUSABLE = "button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, iframe, audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), [tabindex]";
13
14
 
@@ -22,6 +23,80 @@ const focusFirstFocusable = (dialog, overlayRoot) => {
22
23
  return document.activeElement === candidate;
23
24
  });
24
25
  };
26
+ const FOCUS_HISTORY_SIZE = 5;
27
+
28
+ // Neither removed, disabled nor hidden, so the element could take the focus back.
29
+ const isFocusable = element => element.isConnected && element.matches(FOCUSABLE) && (
30
+ // eslint-disable-next-line compat/compat
31
+ typeof element.checkVisibility !== "function" || element.checkVisibility());
32
+
33
+ // A focused element that a closed dialog hides, or that turned inert, keeps the focus until the browser renders again.
34
+ const isFocusLost = () => {
35
+ const focus = document.activeElement;
36
+ if (!focus || focus === document.body || !focus.isConnected || focus.closest("[inert]")) {
37
+ return true;
38
+ }
39
+ const layer = focus.closest("dialog, .c-window");
40
+ return layer instanceof HTMLDialogElement && !layer.open;
41
+ };
42
+
43
+ // A sheet is a window, not a dialog, so once the last dialog is closed nothing else takes a lost focus back.
44
+ const focusTopWindowIfLost = () => {
45
+ const topLayer = getTopLayer();
46
+ if (getTopModalRootId() === undefined && isFocusLost() && topLayer != null && topLayer.matches(".c-window")) {
47
+ topLayer.focus({
48
+ preventScroll: true
49
+ });
50
+ }
51
+ };
52
+ const keepFocusOn = element => {
53
+ if (element instanceof HTMLElement && element !== document.body && element.isConnected && document.activeElement !== element) {
54
+ element.focus({
55
+ preventScroll: true
56
+ });
57
+ }
58
+ };
59
+
60
+ // A closed dialog shown as a manual popover stays in the top layer without blocking the page. showPopover focuses a
61
+ // dialog, so the focus goes back to where close() left it.
62
+ const keepInTopLayer = node => {
63
+ if (typeof node.showPopover !== "function") {
64
+ return;
65
+ }
66
+ const focus = document.activeElement;
67
+ node.setAttribute("popover", "manual");
68
+ // eslint-disable-next-line compat/compat
69
+ node.showPopover();
70
+ keepFocusOn(focus);
71
+ if (document.activeElement !== focus && node.contains(document.activeElement)) {
72
+ document.activeElement.blur();
73
+ }
74
+ };
75
+ const leaveTopLayer = node => {
76
+ if (!node.hasAttribute("popover")) {
77
+ return;
78
+ }
79
+ if (node.matches(":popover-open")) {
80
+ // eslint-disable-next-line compat/compat
81
+ node.hidePopover();
82
+ }
83
+ node.removeAttribute("popover");
84
+ };
85
+ const isHeldStackHost = (element, overlayRoot) => {
86
+ var _element$closest;
87
+ return !!overlayRoot && (element == null || (_element$closest = element.closest("[" + MODAL_STACK_HOST_ATTRIBUTE + "]")) == null ? void 0 : _element$closest.parentElement) === overlayRoot;
88
+ };
89
+
90
+ // Popups of the content sit in the overlay root next to the stack hosts and leave with the content.
91
+ const setContentInert = (content, overlayRoot, inert) => {
92
+ var _overlayRoot$children;
93
+ content == null || content.toggleAttribute("inert", inert);
94
+ Array.from((_overlayRoot$children = overlayRoot == null ? void 0 : overlayRoot.children) != null ? _overlayRoot$children : []).forEach(child => {
95
+ if (!child.hasAttribute(MODAL_STACK_HOST_ATTRIBUTE)) {
96
+ child.toggleAttribute("inert", inert);
97
+ }
98
+ });
99
+ };
25
100
  export const ModalRoot = /*#__PURE__*/forwardRef((_ref, ref) => {
26
101
  let open = _ref.open,
27
102
  onRequestClose = _ref.onRequestClose,
@@ -67,6 +142,8 @@ export const ModalRoot = /*#__PURE__*/forwardRef((_ref, ref) => {
67
142
  const openRef = useRef(open);
68
143
  const pressStartedOnBackdrop = useRef(false);
69
144
  const stackIdRef = useRef();
145
+ const exitingRef = useRef(false);
146
+ const contentRef = useRef(null);
70
147
  const overlayRootRef = useRef(null);
71
148
  // Menus and pickers opened inside portal here, into the top layer with the dialog, not under it.
72
149
  const getOverlayRoot = useCallback(() => overlayRootRef.current, []);
@@ -74,15 +151,61 @@ export const ModalRoot = /*#__PURE__*/forwardRef((_ref, ref) => {
74
151
  const disableReturnFocusRef = useRef(disableReturnFocus);
75
152
  disableReturnFocusRef.current = disableReturnFocus;
76
153
 
77
- // close() gives the focus back to the element that had it before showModal when the focus is in the dialog, so
78
- // a dialog that leaves it there takes it off again. A focus outside, as in a sheet that left the overlay root,
79
- // stays where it is.
154
+ // close() of a modal gives the focus back to the element that had it before showModal, so a dialog that leaves it
155
+ // there takes it off again. A focus outside, as in a sheet that left the overlay root, stays where it is, and so
156
+ // does a focus in a sheet the overlay root holds for the exit transition. When that element is gone, also when it
157
+ // goes with the same update right after, and the last dialog closes over a sheet, the sheet takes it.
80
158
  const closeDialog = useCallback(node => {
81
- const focusInside = node.contains(document.activeElement);
159
+ const focus = document.activeElement;
160
+ const focusHeld = isHeldStackHost(focus, overlayRootRef.current);
161
+ const focusInside = node.contains(focus) && !focusHeld;
82
162
  node.close();
83
- if (disableReturnFocusRef.current && focusInside) {
163
+ if (!focusInside) {
164
+ keepFocusOn(focus);
165
+ return;
166
+ }
167
+ if (disableReturnFocusRef.current) {
84
168
  var _document$activeEleme;
85
169
  (_document$activeEleme = document.activeElement) == null || _document$activeEleme.blur();
170
+ return;
171
+ }
172
+ focusTopWindowIfLost();
173
+ requestAnimationFrame(focusTopWindowIfLost);
174
+ }, []);
175
+ const focusHistoryRef = useRef([]);
176
+ const blurredRef = useRef(null);
177
+
178
+ // The browser drops the focus to the body when the focused element goes, as a toast that closes or a button that
179
+ // another replaces, so the top dialog takes it back: on the newest element focused before that is still there, or
180
+ // on itself. A layer in front of it, such as a sheet in the overlay root, keeps its own focus. A field that blurs
181
+ // itself, as on Escape or Enter, can still take the focus, so it let it go on purpose and the dialog takes it.
182
+ const restoreLostFocus = useCallback(() => {
183
+ const node = dialogRef.current;
184
+ const stackId = stackIdRef.current;
185
+ const blurred = blurredRef.current;
186
+ blurredRef.current = null;
187
+ if (!(node != null && node.open) || stackId === undefined || !isTopModalRoot(stackId) || areModalRootsSuspended() || !isFocusLost() || getTopLayer() !== node) {
188
+ return;
189
+ }
190
+ if (blurred && node.contains(blurred) && isFocusable(blurred)) {
191
+ node.focus({
192
+ preventScroll: true
193
+ });
194
+ return;
195
+ }
196
+ const restored = focusHistoryRef.current.some(candidate => {
197
+ if (!candidate.isConnected || !node.contains(candidate)) {
198
+ return false;
199
+ }
200
+ candidate.focus({
201
+ preventScroll: true
202
+ });
203
+ return document.activeElement === candidate;
204
+ });
205
+ if (!restored) {
206
+ node.focus({
207
+ preventScroll: true
208
+ });
86
209
  }
87
210
  }, []);
88
211
  if (open && !mounted) {
@@ -123,26 +246,56 @@ export const ModalRoot = /*#__PURE__*/forwardRef((_ref, ref) => {
123
246
  preventScroll: true
124
247
  });
125
248
  }
249
+ restoreLostFocus();
126
250
  }
127
251
  });
128
- const finishClose = useCallback(() => {
252
+ const leaveStack = useCallback(() => {
253
+ if (stackIdRef.current !== undefined) {
254
+ popModalRoot(stackIdRef.current);
255
+ stackIdRef.current = undefined;
256
+ }
257
+ }, []);
258
+
259
+ // The closed dialog stays shown for its exit transition, and its content takes no input until it unmounts.
260
+ // Sheets in its overlay root stay there until the transition is done.
261
+ const releaseForExit = useCallback(() => {
262
+ const node = dialogRef.current;
263
+ if (!node || exitingRef.current) {
264
+ return;
265
+ }
266
+ exitingRef.current = true;
129
267
  // A dialog that closes while suspended leaves the stack before the resume, so it drops its layer here.
130
- if (dialogRef.current) {
131
- dialogRef.current.style.zIndex = "";
268
+ node.style.zIndex = "";
269
+ if (stackIdRef.current !== undefined) {
270
+ releaseModalRoot(stackIdRef.current);
271
+ }
272
+
273
+ // Inert before close(), so a focus lock in a popup cannot take back the focus close() gives the opener.
274
+ setContentInert(contentRef.current, overlayRootRef.current, true);
275
+ if (node.open) {
276
+ closeDialog(node);
277
+ }
278
+ keepInTopLayer(node);
279
+ }, [closeDialog]);
280
+ const finishClose = useCallback(() => {
281
+ const node = dialogRef.current;
282
+ exitingRef.current = false;
283
+ if (node) {
284
+ node.style.zIndex = "";
132
285
  }
133
286
 
134
287
  // Content that sits in the overlay root moves out before the dialog hides it.
135
- if (stackIdRef.current !== undefined) {
136
- popModalRoot(stackIdRef.current);
137
- stackIdRef.current = undefined;
288
+ leaveStack();
289
+ if (node != null && node.open) {
290
+ closeDialog(node);
138
291
  }
139
- if (dialogRef.current) {
140
- closeDialog(dialogRef.current);
292
+ if (node) {
293
+ leaveTopLayer(node);
141
294
  }
142
295
  setMounted(false);
143
296
  setShownDialog(null);
144
297
  onClose == null || onClose();
145
- }, [closeDialog, onClose]);
298
+ }, [closeDialog, leaveStack, onClose]);
146
299
 
147
300
  // The entry joins the stack with every showModal, so an owner that opens the dialog again from onClose, on the
148
301
  // same node, gets it back. It joins after showModal, so content that moves into the overlay root lands where it
@@ -151,14 +304,26 @@ export const ModalRoot = /*#__PURE__*/forwardRef((_ref, ref) => {
151
304
  if (!open || !dialog) {
152
305
  return;
153
306
  }
307
+ const reopenedDuringExit = exitingRef.current;
308
+ if (reopenedDuringExit) {
309
+ exitingRef.current = false;
310
+ leaveTopLayer(dialog);
311
+ setContentInert(contentRef.current, overlayRootRef.current, false);
312
+ }
154
313
  if (!dialog.open) {
155
314
  dialog.showModal();
156
315
  }
316
+ if (reopenedDuringExit && stackIdRef.current !== undefined && !reopenModalRoot(stackIdRef.current)) {
317
+ leaveStack();
318
+ }
319
+ if (reopenedDuringExit && !areModalRootsSuspended() && !dialog.contains(document.activeElement)) {
320
+ focusFirstFocusable(dialog, overlayRootRef.current);
321
+ }
157
322
  if (stackIdRef.current === undefined) {
158
323
  stackIdRef.current = pushModalRoot(overlayRootRef.current, suspensionRef.current, belowOpenSheets);
159
324
  }
160
325
  setShownDialog(dialog);
161
- }, [open, dialog, belowOpenSheets]);
326
+ }, [open, dialog, belowOpenSheets, leaveStack]);
162
327
 
163
328
  // showModal found no content to focus, so the dialog moves the focus in once the content is there, unless an
164
329
  // autoFocus field took it. A dialog that opened suspended stays out of the way of the overlay above it.
@@ -177,19 +342,22 @@ export const ModalRoot = /*#__PURE__*/forwardRef((_ref, ref) => {
177
342
  // An owner that unmounts the dialog while it is open, as a form does on submit, gets the focus back on the
178
343
  // opener: a dialog removed while open would leave it on the body.
179
344
  useLayoutEffect(() => () => {
180
- if (stackIdRef.current !== undefined) {
181
- popModalRoot(stackIdRef.current);
182
- stackIdRef.current = undefined;
183
- }
345
+ exitingRef.current = false;
346
+ leaveStack();
184
347
  if (dialog != null && dialog.open) {
185
348
  closeDialog(dialog);
186
349
  }
187
- }, [dialog, closeDialog]);
350
+ }, [dialog, closeDialog, leaveStack]);
188
351
  useLayoutEffect(() => {
189
- if (!open && mounted && !hasTransition) {
352
+ if (open || !mounted) {
353
+ return;
354
+ }
355
+ if (hasTransition) {
356
+ releaseForExit();
357
+ } else {
190
358
  finishClose();
191
359
  }
192
- }, [open, mounted, hasTransition, finishClose]);
360
+ }, [open, mounted, hasTransition, releaseForExit, finishClose]);
193
361
  const dismissRef = useRef();
194
362
  dismissRef.current = (reason, event) => {
195
363
  if (areModalRootsSuspended()) {
@@ -263,6 +431,52 @@ export const ModalRoot = /*#__PURE__*/forwardRef((_ref, ref) => {
263
431
  dialog.removeEventListener("close", handleNativeClose);
264
432
  };
265
433
  }, [dialog]);
434
+
435
+ // The check waits a frame, so a close() that gives the focus back to an opener runs first. A modal root above
436
+ // leaves the stack before its close(), and may sit outside this dialog, so the stack starts the check too.
437
+ useEffect(() => {
438
+ if (!dialog) {
439
+ return undefined;
440
+ }
441
+ let frame;
442
+ const scheduleRestore = () => {
443
+ if (frame === undefined) {
444
+ frame = requestAnimationFrame(() => {
445
+ frame = undefined;
446
+ restoreLostFocus();
447
+ });
448
+ }
449
+ };
450
+ const handleFocusIn = event => {
451
+ const target = event.target;
452
+ if (target instanceof HTMLElement && target !== dialog) {
453
+ focusHistoryRef.current = [target, ...focusHistoryRef.current.filter(element => element !== target)].slice(0, FOCUS_HISTORY_SIZE);
454
+ }
455
+ };
456
+ const handleFocusOut = event => {
457
+ if (!event.relatedTarget) {
458
+ blurredRef.current = event.target instanceof HTMLElement ? event.target : null;
459
+ scheduleRestore();
460
+ }
461
+ };
462
+ const observer = new MutationObserver(scheduleRestore);
463
+ observer.observe(dialog, {
464
+ childList: true,
465
+ subtree: true
466
+ });
467
+ dialog.addEventListener("focusin", handleFocusIn);
468
+ dialog.addEventListener("focusout", handleFocusOut);
469
+ const unsubscribe = subscribeToModalRoots(scheduleRestore);
470
+ return () => {
471
+ unsubscribe();
472
+ observer.disconnect();
473
+ dialog.removeEventListener("focusin", handleFocusIn);
474
+ dialog.removeEventListener("focusout", handleFocusOut);
475
+ if (frame !== undefined) {
476
+ cancelAnimationFrame(frame);
477
+ }
478
+ };
479
+ }, [dialog, restoreLostFocus]);
266
480
  const handlePointerDown = useCallback(event => {
267
481
  pressStartedOnBackdrop.current = event.target === event.currentTarget;
268
482
  onPointerDown == null || onPointerDown(event);
@@ -322,15 +536,20 @@ export const ModalRoot = /*#__PURE__*/forwardRef((_ref, ref) => {
322
536
  ref: handleRef,
323
537
  enabled: !disableScrollLock,
324
538
  noIsolation: true
325
- }, /*#__PURE__*/React.createElement(StyledModalRoot, _extends({}, rest, {
539
+ }, /*#__PURE__*/React.createElement(StyledModalRoot, _extends({
540
+ tabIndex: -1
541
+ }, rest, {
326
542
  className: classnames("c-modal-root", className),
327
543
  "data-state": open ? "open" : "closing",
328
544
  onPointerDown: handlePointerDown,
329
545
  onClick: handleClick,
330
546
  onKeyDown: handleKeyDown
331
- }), /*#__PURE__*/React.createElement(PortalContainerProvider, {
547
+ }), /*#__PURE__*/React.createElement("div", {
548
+ ref: contentRef,
549
+ className: "c-modal-root__content"
550
+ }, /*#__PURE__*/React.createElement(PortalContainerProvider, {
332
551
  value: getOverlayRoot
333
- }, content), /*#__PURE__*/React.createElement("div", {
552
+ }, content)), /*#__PURE__*/React.createElement("div", {
334
553
  ref: overlayRootRef,
335
554
  className: "c-modal-root__overlays"
336
555
  }))));
@@ -1 +1 @@
1
- {"version":3,"file":"ModalRoot.js","names":["React","forwardRef","useCallback","useEffect","useLayoutEffect","useRef","useState","RemoveScroll","classnames","areModalRootsSuspended","isTopModalRoot","popModalRoot","pushModalRoot","StyledModalRoot","Portal","PortalContainerProvider","layers","useForkRef","FOCUSABLE","focusFirstFocusable","dialog","overlayRoot","Array","from","querySelectorAll","some","candidate","contains","focus","document","activeElement","ModalRoot","_ref","ref","open","onRequestClose","onDismissBlocked","onClose","_ref$disableCloseOnEs","disableCloseOnEsc","_ref$disableBackgroun","disableBackgroundClick","_ref$disableScrollLoc","disableScrollLock","_ref$disableReturnFoc","disableReturnFocus","_ref$belowOpenSheets","belowOpenSheets","children","className","onPointerDown","onClick","onKeyDown","rest","_objectWithoutPropertiesLoose","_excluded","_useState","mounted","setMounted","_useState2","setDialog","dialogRef","setDialogNode","node","current","handleRef","_useState3","shownDialog","setShownDialog","contentShown","hasTransition","openRef","pressStartedOnBackdrop","stackIdRef","overlayRootRef","getOverlayRoot","disableReturnFocusRef","closeDialog","focusInside","close","_document$activeEleme","blur","focusBeforeSuspendRef","suspensionRef","suspend","style","zIndex","String","cloud","show","resume","showModal","HTMLElement","preventScroll","finishClose","undefined","dismissRef","reason","event","blocked","handleKeyDown","_overlayRootRef$curre","_overlayRootRef$curre2","stackId","defaultPrevented","key","target","body","querySelector","preventDefault","addEventListener","removeEventListener","handleCancel","_overlayRootRef$curre3","handleNativeClose","isConnected","handlePointerDown","currentTarget","handleClick","stopPropagation","_overlayRootRef$curre4","handleExited","content","in","onExited","createElement","forwardProps","enabled","noIsolation","_extends","value","displayName"],"sources":["../../../../src/components/ModalRoot/ModalRoot.tsx"],"sourcesContent":["import React, {\n forwardRef,\n HTMLAttributes,\n KeyboardEvent as ReactKeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { RemoveScroll } from \"react-remove-scroll\";\n\nimport classnames from \"classnames\";\n\nimport {\n areModalRootsSuspended,\n isTopModalRoot,\n ModalRootSuspension,\n popModalRoot,\n pushModalRoot,\n} from \"./modalRootStack\";\nimport { StyledModalRoot } from \"./Styles\";\nimport { Portal, PortalContainerProvider } from \"../../helpers\";\nimport { layers } from \"../../utils/layers\";\nimport useForkRef from \"../../utils/useForkRef\";\n\nexport type ModalRootDismissReason = \"escape\" | \"backdrop\";\n\nconst FOCUSABLE =\n \"button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, iframe, audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), [tabindex]\";\n\n// What showModal does for content that was not there yet: the first node that takes the focus gets it, so a\n// disabled or hidden one is skipped as the browser skips it.\nconst focusFirstFocusable = (\n dialog: HTMLDialogElement,\n overlayRoot: HTMLElement | null\n) => {\n Array.from(dialog.querySelectorAll<HTMLElement>(FOCUSABLE)).some(\n (candidate) => {\n if (overlayRoot?.contains(candidate)) {\n return false;\n }\n\n candidate.focus();\n\n return document.activeElement === candidate;\n }\n );\n};\n\nexport interface ModalRootTransition {\n in: boolean;\n onExited: () => void;\n}\n\nexport interface ModalRootProps\n extends Omit<\n HTMLAttributes<HTMLDialogElement>,\n \"children\" | \"open\" | \"onClose\" | \"onCancel\"\n > {\n open: boolean;\n /** Escape or a backdrop click asks the owner to set open to false */\n onRequestClose?: (reason: ModalRootDismissReason) => void;\n /** Escape or a backdrop click that disableCloseOnEsc or disableBackgroundClick blocked; a backdrop click passes its event */\n onDismissBlocked?: (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void;\n /** The exit transition is done and the dialog is closed */\n onClose?: () => void;\n disableCloseOnEsc?: boolean;\n disableBackgroundClick?: boolean;\n disableScrollLock?: boolean;\n /** Closing leaves the focus off the element that had it before the dialog opened, also when the owner unmounts it */\n disableReturnFocus?: boolean;\n /**\n * The dialog counts as opened before the sheets that are open, so they move into its overlay root and stay above\n * it. For a page dialog that a sheet covers, such as an archive that opens a task, also when the dialog mounts after\n * the sheet on a reload. A sheet that sits in the page mounts its content again in the overlay root; one that sits\n * in another modal moves without remounting, also above a modal opened in between from outside the sheet. Read when\n * the dialog opens; a later change does not move the stack entry.\n */\n belowOpenSheets?: boolean;\n /**\n * A function gets the transition state, and the dialog closes when it calls onExited. A node closes at once.\n * The content mounts once the dialog is open, a render after the dialog node, so an autoFocus field takes the focus;\n * an owner effect in the opening commit sees no content. It mounts again on every open, also when the owner reopens\n * the dialog from onClose, and loses its local state.\n */\n children: ReactNode | ((transition: ModalRootTransition) => ReactNode);\n}\n\nexport const ModalRoot = forwardRef<HTMLDialogElement, ModalRootProps>(\n (\n {\n open,\n onRequestClose,\n onDismissBlocked,\n onClose,\n disableCloseOnEsc = false,\n disableBackgroundClick = false,\n disableScrollLock = false,\n disableReturnFocus = false,\n belowOpenSheets = false,\n children,\n className,\n onPointerDown,\n onClick,\n onKeyDown,\n ...rest\n },\n ref\n ) => {\n const [mounted, setMounted] = useState(open);\n // Inside another root the dialog mounts a render after its first one, once the outer overlay root exists,\n // so opening, the stack and the listeners wait for the node instead of the first commit.\n const [dialog, setDialog] = useState<HTMLDialogElement | null>(null);\n const dialogRef = useRef<HTMLDialogElement | null>(null);\n const setDialogNode = useCallback((node: HTMLDialogElement | null) => {\n dialogRef.current = node;\n setDialog(node);\n }, []);\n const handleRef = useForkRef(setDialogNode, ref);\n // A closed dialog hides its content, and React focuses an autoFocus field while it mounts, so the content mounts\n // only once showModal ran on this node.\n const [shownDialog, setShownDialog] = useState<HTMLDialogElement | null>(\n null\n );\n const contentShown = dialog !== null && shownDialog === dialog;\n const hasTransition = typeof children === \"function\";\n const openRef = useRef(open);\n const pressStartedOnBackdrop = useRef(false);\n const stackIdRef = useRef<number>();\n const overlayRootRef = useRef<HTMLDivElement>(null);\n // Menus and pickers opened inside portal here, into the top layer with the dialog, not under it.\n const getOverlayRoot = useCallback(\n () => overlayRootRef.current as HTMLElement,\n []\n );\n\n openRef.current = open;\n const disableReturnFocusRef = useRef(disableReturnFocus);\n disableReturnFocusRef.current = disableReturnFocus;\n\n // close() gives the focus back to the element that had it before showModal when the focus is in the dialog, so\n // a dialog that leaves it there takes it off again. A focus outside, as in a sheet that left the overlay root,\n // stays where it is.\n const closeDialog = useCallback((node: HTMLDialogElement) => {\n const focusInside = node.contains(document.activeElement);\n node.close();\n\n if (disableReturnFocusRef.current && focusInside) {\n (document.activeElement as HTMLElement | null)?.blur();\n }\n }, []);\n\n if (open && !mounted) {\n setMounted(true);\n }\n\n // While suspended the dialog is open without being modal, in the page instead of the top layer, so it keeps a\n // layer just under the overlay it was suspended for. A dismiss then would close it under that overlay.\n // The stack calls suspend once for an entry and resume at most once, so the suspension is the stack's state.\n const focusBeforeSuspendRef = useRef<Element | null>(null);\n const suspensionRef = useRef<ModalRootSuspension>({\n suspend: () => {\n const node = dialogRef.current;\n\n if (!node) {\n return;\n }\n\n focusBeforeSuspendRef.current = node.contains(document.activeElement)\n ? document.activeElement\n : null;\n node.style.zIndex = String(layers.cloud - 1);\n\n if (node.open) {\n node.close();\n node.show();\n }\n },\n resume: () => {\n const node = dialogRef.current;\n\n if (!node) {\n return;\n }\n\n node.style.zIndex = \"\";\n\n if (node.open) {\n node.close();\n node.showModal();\n }\n\n const focus = focusBeforeSuspendRef.current;\n focusBeforeSuspendRef.current = null;\n\n if (focus instanceof HTMLElement && node.contains(focus)) {\n focus.focus({ preventScroll: true });\n }\n },\n });\n\n const finishClose = useCallback(() => {\n // A dialog that closes while suspended leaves the stack before the resume, so it drops its layer here.\n if (dialogRef.current) {\n dialogRef.current.style.zIndex = \"\";\n }\n\n // Content that sits in the overlay root moves out before the dialog hides it.\n if (stackIdRef.current !== undefined) {\n popModalRoot(stackIdRef.current);\n stackIdRef.current = undefined;\n }\n if (dialogRef.current) {\n closeDialog(dialogRef.current);\n }\n setMounted(false);\n setShownDialog(null);\n onClose?.();\n }, [closeDialog, onClose]);\n\n // The entry joins the stack with every showModal, so an owner that opens the dialog again from onClose, on the\n // same node, gets it back. It joins after showModal, so content that moves into the overlay root lands where it\n // is rendered and can get its scroll positions back.\n useLayoutEffect(() => {\n if (!open || !dialog) {\n return;\n }\n\n if (!dialog.open) {\n dialog.showModal();\n }\n\n if (stackIdRef.current === undefined) {\n stackIdRef.current = pushModalRoot(\n overlayRootRef.current,\n suspensionRef.current,\n belowOpenSheets\n );\n }\n\n setShownDialog(dialog);\n }, [open, dialog, belowOpenSheets]);\n\n // showModal found no content to focus, so the dialog moves the focus in once the content is there, unless an\n // autoFocus field took it. A dialog that opened suspended stays out of the way of the overlay above it.\n useLayoutEffect(() => {\n if (!contentShown || !dialog || areModalRootsSuspended()) {\n return;\n }\n\n const focus = document.activeElement;\n\n if (focus !== dialog && dialog.contains(focus)) {\n return;\n }\n\n focusFirstFocusable(dialog, overlayRootRef.current);\n }, [contentShown, dialog]);\n\n // A layout effect, so the entry leaves the stack before an unmount removes the dialog and its overlay root.\n // An owner that unmounts the dialog while it is open, as a form does on submit, gets the focus back on the\n // opener: a dialog removed while open would leave it on the body.\n useLayoutEffect(\n () => () => {\n if (stackIdRef.current !== undefined) {\n popModalRoot(stackIdRef.current);\n stackIdRef.current = undefined;\n }\n\n if (dialog?.open) {\n closeDialog(dialog);\n }\n },\n [dialog, closeDialog]\n );\n\n useLayoutEffect(() => {\n if (!open && mounted && !hasTransition) {\n finishClose();\n }\n }, [open, mounted, hasTransition, finishClose]);\n\n const dismissRef =\n useRef<\n (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void\n >();\n\n dismissRef.current = (reason, event) => {\n if (areModalRootsSuspended()) {\n return;\n }\n\n const blocked =\n reason === \"escape\" ? disableCloseOnEsc : disableBackgroundClick;\n\n if (blocked) {\n onDismissBlocked?.(reason, event);\n } else {\n onRequestClose?.(reason);\n }\n };\n\n // A prevented Escape keydown starts no close request, and the browser stops honouring a prevented cancel\n // after a while, so Escape is caught here and the cancel event only covers the other close requests.\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n const stackId = stackIdRef.current;\n\n if (\n stackId === undefined ||\n !isTopModalRoot(stackId) ||\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\")\n ) {\n return;\n }\n\n // A menu inside closes on an Escape that reaches the body, from a listener that runs after this one.\n if (\n event.target === document.body &&\n overlayRootRef.current?.querySelector(\".c-window\")\n ) {\n return;\n }\n\n event.preventDefault();\n\n // A sheet, a menu or the chat in the overlay root is a layer above the dialog. An Escape it did not take\n // still belongs to it, so the dialog only stops the browser from closing itself.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n document.addEventListener(\"keydown\", handleKeyDown);\n\n return () => document.removeEventListener(\"keydown\", handleKeyDown);\n }, [dialog]);\n\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleCancel = (event: Event) => {\n event.preventDefault();\n\n // A layer in the overlay root may stop its Escape before the document sees it, so the cancel that follows\n // would close the dialog under the layer. While the focus is in that layer, the close request is its own.\n if (overlayRootRef.current?.contains(document.activeElement)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n const handleNativeClose = () => {\n if (\n openRef.current &&\n dialog.isConnected &&\n !dialog.open &&\n !areModalRootsSuspended()\n ) {\n dialog.showModal();\n }\n };\n\n dialog.addEventListener(\"cancel\", handleCancel);\n dialog.addEventListener(\"close\", handleNativeClose);\n\n return () => {\n dialog.removeEventListener(\"cancel\", handleCancel);\n dialog.removeEventListener(\"close\", handleNativeClose);\n };\n }, [dialog]);\n\n const handlePointerDown = useCallback(\n (event: PointerEvent<HTMLDialogElement>) => {\n pressStartedOnBackdrop.current = event.target === event.currentTarget;\n onPointerDown?.(event);\n },\n [onPointerDown]\n );\n\n // The dialog covers the viewport and its content sits inside it, so a click on the dialog itself is a\n // click on the backdrop. A press that started on the content and ended outside it is a text selection.\n // A click does not bubble on through the React tree, as from a legacy window: a confirmation rendered in a\n // clickable row would otherwise click the row as well. React listens at the portal's container, so a click\n // listener on document or window does not see a click inside the dialog either, as with the window.\n const handleClick = useCallback(\n (event: MouseEvent<HTMLDialogElement>) => {\n if (\n event.target === event.currentTarget &&\n pressStartedOnBackdrop.current &&\n openRef.current\n ) {\n dismissRef.current?.(\"backdrop\", event);\n }\n pressStartedOnBackdrop.current = false;\n onClick?.(event);\n event.stopPropagation();\n },\n [onClick]\n );\n\n // React events from a portal bubble through the React tree, so an Escape from the content would reach an\n // ancestor's handler, like an older Sheet's, before the document listener. The dialog takes it here first.\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent<HTMLDialogElement>) => {\n onKeyDown?.(event);\n\n if (\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\") ||\n stackIdRef.current === undefined ||\n !isTopModalRoot(stackIdRef.current)\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n // An Escape a layer in the overlay root did not take stops here too, so it does not close the sheet that\n // opened this dialog, but it leaves the dialog open.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n },\n [onKeyDown]\n );\n\n const handleExited = useCallback(() => {\n if (!open) {\n finishClose();\n }\n }, [open, finishClose]);\n\n if (!mounted) {\n return null;\n }\n\n let content: ReactNode = null;\n\n if (contentShown) {\n content =\n typeof children === \"function\"\n ? children({ in: open, onExited: handleExited })\n : children;\n }\n\n return (\n <Portal>\n <RemoveScroll\n forwardProps\n ref={handleRef}\n enabled={!disableScrollLock}\n noIsolation\n >\n <StyledModalRoot\n {...rest}\n className={classnames(\"c-modal-root\", className)}\n data-state={open ? \"open\" : \"closing\"}\n onPointerDown={handlePointerDown}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n >\n <PortalContainerProvider value={getOverlayRoot}>\n {content}\n </PortalContainerProvider>\n <div ref={overlayRootRef} className=\"c-modal-root__overlays\" />\n </StyledModalRoot>\n </RemoveScroll>\n </Portal>\n );\n }\n);\n\nModalRoot.displayName = \"ModalRoot\";\n"],"mappings":";;;AAAA,OAAOA,KAAK,IACVC,UAAU,EAMVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,MAAM,EACNC,QAAQ,QACH,OAAO;AACd,SAASC,YAAY,QAAQ,qBAAqB;AAElD,OAAOC,UAAU,MAAM,YAAY;AAEnC,SACEC,sBAAsB,EACtBC,cAAc,EAEdC,YAAY,EACZC,aAAa,QACR,kBAAkB;AACzB,SAASC,eAAe,QAAQ,UAAU;AAC1C,SAASC,MAAM,EAAEC,uBAAuB,QAAQ,eAAe;AAC/D,SAASC,MAAM,QAAQ,oBAAoB;AAC3C,OAAOC,UAAU,MAAM,wBAAwB;AAI/C,MAAMC,SAAS,GACb,0NAA0N;;AAE5N;AACA;AACA,MAAMC,m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C5C+C,OACsB,CAAC,eAC1B1H,KAAA,CAAA6H,aAAA;IAAK5F,GAAG,EAAEyC,cAAe;IAACzB,SAAS,EAAC;EAAwB,CAAE,CAC/C,CACL,CACR,CAAC;AAEb,CACF,CAAC;AAEDlB,SAAS,CAACoG,WAAW,GAAG,WAAW","ignoreList":[]}
1
+ {"version":3,"file":"ModalRoot.js","names":["React","forwardRef","useCallback","useEffect","useLayoutEffect","useRef","useState","RemoveScroll","classnames","areModalRootsSuspended","getTopModalRootId","isTopModalRoot","popModalRoot","pushModalRoot","releaseModalRoot","reopenModalRoot","subscribeToModalRoots","StyledModalRoot","MODAL_STACK_HOST_ATTRIBUTE","Portal","PortalContainerProvider","getTopLayer","layers","useForkRef","FOCUSABLE","focusFirstFocusable","dialog","overlayRoot","Array","from","querySelectorAll","some","candidate","contains","focus","document","activeElement","FOCUS_HISTORY_SIZE","isFocusable","element","isConnected","matches","checkVisibility","isFocusLost","body","closest","layer","HTMLDialogElement","open","focusTopWindowIfLost","topLayer","undefined","preventScroll","keepFocusOn","HTMLElement","keepInTopLayer","node","showPopover","setAttribute","blur","leaveTopLayer","hasAttribute","hidePopover","removeAttribute","isHeldStackHost","_element$closest","parentElement","setContentInert","content","inert","_overlayRoot$children","toggleAttribute","children","forEach","child","ModalRoot","_ref","ref","onRequestClose","onDismissBlocked","onClose","_ref$disableCloseOnEs","disableCloseOnEsc","_ref$disableBackgroun","disableBackgroundClick","_ref$disableScrollLoc","disableScrollLock","_ref$disableReturnFoc","disableReturnFocus","_ref$belowOpenSheets","belowOpenSheets","className","onPointerDown","onClick","onKeyDown","rest","_objectWithoutPropertiesLoose","_excluded","_useState","mounted","setMounted","_useState2","setDialog","dialogRef","setDialogNode","current","handleRef","_useState3","shownDialog","setShownDialog","contentShown","hasTransition","openRef","pressStartedOnBackdrop","stackIdRef","exitingRef","contentRef","overlayRootRef","getOverlayRoot","disableReturnFocusRef","closeDialog","focusHeld","focusInside","close","_document$activeEleme","requestAnimationFrame","focusHistoryRef","blurredRef","restoreLostFocus","stackId","blurred","restored","focusBeforeSuspendRef","suspensionRef","suspend","style","zIndex","String","cloud","show","resume","showModal","leaveStack","releaseForExit","finishClose","reopenedDuringExit","dismissRef","reason","event","blocked","handleKeyDown","_overlayRootRef$curre","_overlayRootRef$curre2","defaultPrevented","key","target","querySelector","preventDefault","addEventListener","removeEventListener","handleCancel","_overlayRootRef$curre3","handleNativeClose","frame","scheduleRestore","handleFocusIn","filter","slice","handleFocusOut","relatedTarget","observer","MutationObserver","observe","childList","subtree","unsubscribe","disconnect","cancelAnimationFrame","handlePointerDown","currentTarget","handleClick","stopPropagation","_overlayRootRef$curre4","handleExited","in","onExited","createElement","forwardProps","enabled","noIsolation","_extends","tabIndex","value","displayName"],"sources":["../../../../src/components/ModalRoot/ModalRoot.tsx"],"sourcesContent":["import React, {\n forwardRef,\n HTMLAttributes,\n KeyboardEvent as ReactKeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { RemoveScroll } from \"react-remove-scroll\";\n\nimport classnames from \"classnames\";\n\nimport {\n areModalRootsSuspended,\n getTopModalRootId,\n isTopModalRoot,\n ModalRootSuspension,\n popModalRoot,\n pushModalRoot,\n releaseModalRoot,\n reopenModalRoot,\n subscribeToModalRoots,\n} from \"./modalRootStack\";\nimport { StyledModalRoot } from \"./Styles\";\nimport { MODAL_STACK_HOST_ATTRIBUTE } from \"./useModalStackHost\";\nimport { Portal, PortalContainerProvider } from \"../../helpers\";\nimport { getTopLayer, layers } from \"../../utils/layers\";\nimport useForkRef from \"../../utils/useForkRef\";\n\nexport type ModalRootDismissReason = \"escape\" | \"backdrop\";\n\nconst FOCUSABLE =\n \"button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, iframe, audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), [tabindex]\";\n\n// What showModal does for content that was not there yet: the first node that takes the focus gets it, so a\n// disabled or hidden one is skipped as the browser skips it.\nconst focusFirstFocusable = (\n dialog: HTMLDialogElement,\n overlayRoot: HTMLElement | null\n) => {\n Array.from(dialog.querySelectorAll<HTMLElement>(FOCUSABLE)).some(\n (candidate) => {\n if (overlayRoot?.contains(candidate)) {\n return false;\n }\n\n candidate.focus();\n\n return document.activeElement === candidate;\n }\n );\n};\n\nconst FOCUS_HISTORY_SIZE = 5;\n\n// Neither removed, disabled nor hidden, so the element could take the focus back.\nconst isFocusable = (element: HTMLElement) =>\n element.isConnected &&\n element.matches(FOCUSABLE) &&\n // eslint-disable-next-line compat/compat\n (typeof element.checkVisibility !== \"function\" || element.checkVisibility());\n\n// A focused element that a closed dialog hides, or that turned inert, keeps the focus until the browser renders again.\nconst isFocusLost = () => {\n const focus = document.activeElement;\n\n if (\n !focus ||\n focus === document.body ||\n !focus.isConnected ||\n focus.closest(\"[inert]\")\n ) {\n return true;\n }\n\n const layer = focus.closest(\"dialog, .c-window\");\n\n return layer instanceof HTMLDialogElement && !layer.open;\n};\n\n// A sheet is a window, not a dialog, so once the last dialog is closed nothing else takes a lost focus back.\nconst focusTopWindowIfLost = () => {\n const topLayer = getTopLayer();\n\n if (\n getTopModalRootId() === undefined &&\n isFocusLost() &&\n topLayer?.matches(\".c-window\")\n ) {\n topLayer.focus({ preventScroll: true });\n }\n};\n\nconst keepFocusOn = (element: Element | null) => {\n if (\n element instanceof HTMLElement &&\n element !== document.body &&\n element.isConnected &&\n document.activeElement !== element\n ) {\n element.focus({ preventScroll: true });\n }\n};\n\n// A closed dialog shown as a manual popover stays in the top layer without blocking the page. showPopover focuses a\n// dialog, so the focus goes back to where close() left it.\nconst keepInTopLayer = (node: HTMLDialogElement) => {\n if (typeof node.showPopover !== \"function\") {\n return;\n }\n\n const focus = document.activeElement;\n node.setAttribute(\"popover\", \"manual\");\n // eslint-disable-next-line compat/compat\n node.showPopover();\n\n keepFocusOn(focus);\n\n if (\n document.activeElement !== focus &&\n node.contains(document.activeElement)\n ) {\n (document.activeElement as HTMLElement).blur();\n }\n};\n\nconst leaveTopLayer = (node: HTMLDialogElement) => {\n if (!node.hasAttribute(\"popover\")) {\n return;\n }\n\n if (node.matches(\":popover-open\")) {\n // eslint-disable-next-line compat/compat\n node.hidePopover();\n }\n node.removeAttribute(\"popover\");\n};\n\nconst isHeldStackHost = (\n element: Element | null,\n overlayRoot: Element | null\n) =>\n !!overlayRoot &&\n element?.closest(`[${MODAL_STACK_HOST_ATTRIBUTE}]`)?.parentElement ===\n overlayRoot;\n\n// Popups of the content sit in the overlay root next to the stack hosts and leave with the content.\nconst setContentInert = (\n content: Element | null,\n overlayRoot: Element | null,\n inert: boolean\n) => {\n content?.toggleAttribute(\"inert\", inert);\n Array.from(overlayRoot?.children ?? []).forEach((child) => {\n if (!child.hasAttribute(MODAL_STACK_HOST_ATTRIBUTE)) {\n child.toggleAttribute(\"inert\", inert);\n }\n });\n};\n\nexport interface ModalRootTransition {\n in: boolean;\n onExited: () => void;\n}\n\nexport interface ModalRootProps\n extends Omit<\n HTMLAttributes<HTMLDialogElement>,\n \"children\" | \"open\" | \"onClose\" | \"onCancel\"\n > {\n open: boolean;\n /** Escape or a backdrop click asks the owner to set open to false */\n onRequestClose?: (reason: ModalRootDismissReason) => void;\n /** Escape or a backdrop click that disableCloseOnEsc or disableBackgroundClick blocked; a backdrop click passes its event */\n onDismissBlocked?: (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void;\n /** The exit transition is done and the dialog is closed */\n onClose?: () => void;\n disableCloseOnEsc?: boolean;\n disableBackgroundClick?: boolean;\n disableScrollLock?: boolean;\n /**\n * Closing leaves the focus off the element that had it before the dialog opened, also when the owner unmounts it.\n * An open dialog under it takes the focus itself.\n */\n disableReturnFocus?: boolean;\n /**\n * The dialog counts as opened before the sheets that are open, so they move into its overlay root and stay above\n * it. For a page dialog that a sheet covers, such as an archive that opens a task, also when the dialog mounts after\n * the sheet on a reload. A sheet that sits in the page mounts its content again in the overlay root; one that sits\n * in another modal moves without remounting, also above a modal opened in between from outside the sheet. Read when\n * the dialog opens; a later change does not move the stack entry.\n */\n belowOpenSheets?: boolean;\n /**\n * A function gets the transition state. The dialog closes, gives the focus back and turns inert as the exit\n * starts, stays shown for the transition, and unmounts when it calls onExited. A node closes at once.\n * The content mounts once the dialog is open, a render after the dialog node, so an autoFocus field takes the focus;\n * an owner effect in the opening commit sees no content. It mounts again on every open, also when the owner reopens\n * the dialog from onClose, and loses its local state.\n */\n children: ReactNode | ((transition: ModalRootTransition) => ReactNode);\n}\n\nexport const ModalRoot = forwardRef<HTMLDialogElement, ModalRootProps>(\n (\n {\n open,\n onRequestClose,\n onDismissBlocked,\n onClose,\n disableCloseOnEsc = false,\n disableBackgroundClick = false,\n disableScrollLock = false,\n disableReturnFocus = false,\n belowOpenSheets = false,\n children,\n className,\n onPointerDown,\n onClick,\n onKeyDown,\n ...rest\n },\n ref\n ) => {\n const [mounted, setMounted] = useState(open);\n // Inside another root the dialog mounts a render after its first one, once the outer overlay root exists,\n // so opening, the stack and the listeners wait for the node instead of the first commit.\n const [dialog, setDialog] = useState<HTMLDialogElement | null>(null);\n const dialogRef = useRef<HTMLDialogElement | null>(null);\n const setDialogNode = useCallback((node: HTMLDialogElement | null) => {\n dialogRef.current = node;\n setDialog(node);\n }, []);\n const handleRef = useForkRef(setDialogNode, ref);\n // A closed dialog hides its content, and React focuses an autoFocus field while it mounts, so the content mounts\n // only once showModal ran on this node.\n const [shownDialog, setShownDialog] = useState<HTMLDialogElement | null>(\n null\n );\n const contentShown = dialog !== null && shownDialog === dialog;\n const hasTransition = typeof children === \"function\";\n const openRef = useRef(open);\n const pressStartedOnBackdrop = useRef(false);\n const stackIdRef = useRef<number>();\n const exitingRef = useRef(false);\n const contentRef = useRef<HTMLDivElement>(null);\n const overlayRootRef = useRef<HTMLDivElement>(null);\n // Menus and pickers opened inside portal here, into the top layer with the dialog, not under it.\n const getOverlayRoot = useCallback(\n () => overlayRootRef.current as HTMLElement,\n []\n );\n\n openRef.current = open;\n const disableReturnFocusRef = useRef(disableReturnFocus);\n disableReturnFocusRef.current = disableReturnFocus;\n\n // close() of a modal gives the focus back to the element that had it before showModal, so a dialog that leaves it\n // there takes it off again. A focus outside, as in a sheet that left the overlay root, stays where it is, and so\n // does a focus in a sheet the overlay root holds for the exit transition. When that element is gone, also when it\n // goes with the same update right after, and the last dialog closes over a sheet, the sheet takes it.\n const closeDialog = useCallback((node: HTMLDialogElement) => {\n const focus = document.activeElement;\n const focusHeld = isHeldStackHost(focus, overlayRootRef.current);\n const focusInside = node.contains(focus) && !focusHeld;\n node.close();\n\n if (!focusInside) {\n keepFocusOn(focus);\n\n return;\n }\n\n if (disableReturnFocusRef.current) {\n (document.activeElement as HTMLElement | null)?.blur();\n\n return;\n }\n\n focusTopWindowIfLost();\n requestAnimationFrame(focusTopWindowIfLost);\n }, []);\n\n const focusHistoryRef = useRef<HTMLElement[]>([]);\n const blurredRef = useRef<HTMLElement | null>(null);\n\n // The browser drops the focus to the body when the focused element goes, as a toast that closes or a button that\n // another replaces, so the top dialog takes it back: on the newest element focused before that is still there, or\n // on itself. A layer in front of it, such as a sheet in the overlay root, keeps its own focus. A field that blurs\n // itself, as on Escape or Enter, can still take the focus, so it let it go on purpose and the dialog takes it.\n const restoreLostFocus = useCallback(() => {\n const node = dialogRef.current;\n const stackId = stackIdRef.current;\n const blurred = blurredRef.current;\n blurredRef.current = null;\n\n if (\n !node?.open ||\n stackId === undefined ||\n !isTopModalRoot(stackId) ||\n areModalRootsSuspended() ||\n !isFocusLost() ||\n getTopLayer() !== node\n ) {\n return;\n }\n\n if (blurred && node.contains(blurred) && isFocusable(blurred)) {\n node.focus({ preventScroll: true });\n\n return;\n }\n\n const restored = focusHistoryRef.current.some((candidate) => {\n if (!candidate.isConnected || !node.contains(candidate)) {\n return false;\n }\n\n candidate.focus({ preventScroll: true });\n\n return document.activeElement === candidate;\n });\n\n if (!restored) {\n node.focus({ preventScroll: true });\n }\n }, []);\n\n if (open && !mounted) {\n setMounted(true);\n }\n\n // While suspended the dialog is open without being modal, in the page instead of the top layer, so it keeps a\n // layer just under the overlay it was suspended for. A dismiss then would close it under that overlay.\n // The stack calls suspend once for an entry and resume at most once, so the suspension is the stack's state.\n const focusBeforeSuspendRef = useRef<Element | null>(null);\n const suspensionRef = useRef<ModalRootSuspension>({\n suspend: () => {\n const node = dialogRef.current;\n\n if (!node) {\n return;\n }\n\n focusBeforeSuspendRef.current = node.contains(document.activeElement)\n ? document.activeElement\n : null;\n node.style.zIndex = String(layers.cloud - 1);\n\n if (node.open) {\n node.close();\n node.show();\n }\n },\n resume: () => {\n const node = dialogRef.current;\n\n if (!node) {\n return;\n }\n\n node.style.zIndex = \"\";\n\n if (node.open) {\n node.close();\n node.showModal();\n }\n\n const focus = focusBeforeSuspendRef.current;\n focusBeforeSuspendRef.current = null;\n\n if (focus instanceof HTMLElement && node.contains(focus)) {\n focus.focus({ preventScroll: true });\n }\n\n restoreLostFocus();\n },\n });\n\n const leaveStack = useCallback(() => {\n if (stackIdRef.current !== undefined) {\n popModalRoot(stackIdRef.current);\n stackIdRef.current = undefined;\n }\n }, []);\n\n // The closed dialog stays shown for its exit transition, and its content takes no input until it unmounts.\n // Sheets in its overlay root stay there until the transition is done.\n const releaseForExit = useCallback(() => {\n const node = dialogRef.current;\n\n if (!node || exitingRef.current) {\n return;\n }\n\n exitingRef.current = true;\n // A dialog that closes while suspended leaves the stack before the resume, so it drops its layer here.\n node.style.zIndex = \"\";\n\n if (stackIdRef.current !== undefined) {\n releaseModalRoot(stackIdRef.current);\n }\n\n // Inert before close(), so a focus lock in a popup cannot take back the focus close() gives the opener.\n setContentInert(contentRef.current, overlayRootRef.current, true);\n\n if (node.open) {\n closeDialog(node);\n }\n\n keepInTopLayer(node);\n }, [closeDialog]);\n\n const finishClose = useCallback(() => {\n const node = dialogRef.current;\n\n exitingRef.current = false;\n\n if (node) {\n node.style.zIndex = \"\";\n }\n\n // Content that sits in the overlay root moves out before the dialog hides it.\n leaveStack();\n\n if (node?.open) {\n closeDialog(node);\n }\n\n if (node) {\n leaveTopLayer(node);\n }\n setMounted(false);\n setShownDialog(null);\n onClose?.();\n }, [closeDialog, leaveStack, onClose]);\n\n // The entry joins the stack with every showModal, so an owner that opens the dialog again from onClose, on the\n // same node, gets it back. It joins after showModal, so content that moves into the overlay root lands where it\n // is rendered and can get its scroll positions back.\n useLayoutEffect(() => {\n if (!open || !dialog) {\n return;\n }\n\n const reopenedDuringExit = exitingRef.current;\n\n if (reopenedDuringExit) {\n exitingRef.current = false;\n leaveTopLayer(dialog);\n setContentInert(contentRef.current, overlayRootRef.current, false);\n }\n\n if (!dialog.open) {\n dialog.showModal();\n }\n\n if (\n reopenedDuringExit &&\n stackIdRef.current !== undefined &&\n !reopenModalRoot(stackIdRef.current)\n ) {\n leaveStack();\n }\n\n if (\n reopenedDuringExit &&\n !areModalRootsSuspended() &&\n !dialog.contains(document.activeElement)\n ) {\n focusFirstFocusable(dialog, overlayRootRef.current);\n }\n\n if (stackIdRef.current === undefined) {\n stackIdRef.current = pushModalRoot(\n overlayRootRef.current,\n suspensionRef.current,\n belowOpenSheets\n );\n }\n\n setShownDialog(dialog);\n }, [open, dialog, belowOpenSheets, leaveStack]);\n\n // showModal found no content to focus, so the dialog moves the focus in once the content is there, unless an\n // autoFocus field took it. A dialog that opened suspended stays out of the way of the overlay above it.\n useLayoutEffect(() => {\n if (!contentShown || !dialog || areModalRootsSuspended()) {\n return;\n }\n\n const focus = document.activeElement;\n\n if (focus !== dialog && dialog.contains(focus)) {\n return;\n }\n\n focusFirstFocusable(dialog, overlayRootRef.current);\n }, [contentShown, dialog]);\n\n // A layout effect, so the entry leaves the stack before an unmount removes the dialog and its overlay root.\n // An owner that unmounts the dialog while it is open, as a form does on submit, gets the focus back on the\n // opener: a dialog removed while open would leave it on the body.\n useLayoutEffect(\n () => () => {\n exitingRef.current = false;\n leaveStack();\n\n if (dialog?.open) {\n closeDialog(dialog);\n }\n },\n [dialog, closeDialog, leaveStack]\n );\n\n useLayoutEffect(() => {\n if (open || !mounted) {\n return;\n }\n\n if (hasTransition) {\n releaseForExit();\n } else {\n finishClose();\n }\n }, [open, mounted, hasTransition, releaseForExit, finishClose]);\n\n const dismissRef =\n useRef<\n (\n reason: ModalRootDismissReason,\n event?: MouseEvent<HTMLDialogElement>\n ) => void\n >();\n\n dismissRef.current = (reason, event) => {\n if (areModalRootsSuspended()) {\n return;\n }\n\n const blocked =\n reason === \"escape\" ? disableCloseOnEsc : disableBackgroundClick;\n\n if (blocked) {\n onDismissBlocked?.(reason, event);\n } else {\n onRequestClose?.(reason);\n }\n };\n\n // A prevented Escape keydown starts no close request, and the browser stops honouring a prevented cancel\n // after a while, so Escape is caught here and the cancel event only covers the other close requests.\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n const stackId = stackIdRef.current;\n\n if (\n stackId === undefined ||\n !isTopModalRoot(stackId) ||\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\")\n ) {\n return;\n }\n\n // A menu inside closes on an Escape that reaches the body, from a listener that runs after this one.\n if (\n event.target === document.body &&\n overlayRootRef.current?.querySelector(\".c-window\")\n ) {\n return;\n }\n\n event.preventDefault();\n\n // A sheet, a menu or the chat in the overlay root is a layer above the dialog. An Escape it did not take\n // still belongs to it, so the dialog only stops the browser from closing itself.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n document.addEventListener(\"keydown\", handleKeyDown);\n\n return () => document.removeEventListener(\"keydown\", handleKeyDown);\n }, [dialog]);\n\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n const handleCancel = (event: Event) => {\n event.preventDefault();\n\n // A layer in the overlay root may stop its Escape before the document sees it, so the cancel that follows\n // would close the dialog under the layer. While the focus is in that layer, the close request is its own.\n if (overlayRootRef.current?.contains(document.activeElement)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n };\n\n const handleNativeClose = () => {\n if (\n openRef.current &&\n dialog.isConnected &&\n !dialog.open &&\n !areModalRootsSuspended()\n ) {\n dialog.showModal();\n }\n };\n\n dialog.addEventListener(\"cancel\", handleCancel);\n dialog.addEventListener(\"close\", handleNativeClose);\n\n return () => {\n dialog.removeEventListener(\"cancel\", handleCancel);\n dialog.removeEventListener(\"close\", handleNativeClose);\n };\n }, [dialog]);\n\n // The check waits a frame, so a close() that gives the focus back to an opener runs first. A modal root above\n // leaves the stack before its close(), and may sit outside this dialog, so the stack starts the check too.\n useEffect(() => {\n if (!dialog) {\n return undefined;\n }\n\n let frame: number | undefined;\n\n const scheduleRestore = () => {\n if (frame === undefined) {\n frame = requestAnimationFrame(() => {\n frame = undefined;\n restoreLostFocus();\n });\n }\n };\n\n const handleFocusIn = (event: FocusEvent) => {\n const target = event.target;\n\n if (target instanceof HTMLElement && target !== dialog) {\n focusHistoryRef.current = [\n target,\n ...focusHistoryRef.current.filter((element) => element !== target),\n ].slice(0, FOCUS_HISTORY_SIZE);\n }\n };\n\n const handleFocusOut = (event: FocusEvent) => {\n if (!event.relatedTarget) {\n blurredRef.current =\n event.target instanceof HTMLElement ? event.target : null;\n scheduleRestore();\n }\n };\n\n const observer = new MutationObserver(scheduleRestore);\n\n observer.observe(dialog, { childList: true, subtree: true });\n dialog.addEventListener(\"focusin\", handleFocusIn);\n dialog.addEventListener(\"focusout\", handleFocusOut);\n const unsubscribe = subscribeToModalRoots(scheduleRestore);\n\n return () => {\n unsubscribe();\n observer.disconnect();\n dialog.removeEventListener(\"focusin\", handleFocusIn);\n dialog.removeEventListener(\"focusout\", handleFocusOut);\n\n if (frame !== undefined) {\n cancelAnimationFrame(frame);\n }\n };\n }, [dialog, restoreLostFocus]);\n\n const handlePointerDown = useCallback(\n (event: PointerEvent<HTMLDialogElement>) => {\n pressStartedOnBackdrop.current = event.target === event.currentTarget;\n onPointerDown?.(event);\n },\n [onPointerDown]\n );\n\n // The dialog covers the viewport and its content sits inside it, so a click on the dialog itself is a\n // click on the backdrop. A press that started on the content and ended outside it is a text selection.\n // A click does not bubble on through the React tree, as from a legacy window: a confirmation rendered in a\n // clickable row would otherwise click the row as well. React listens at the portal's container, so a click\n // listener on document or window does not see a click inside the dialog either, as with the window.\n const handleClick = useCallback(\n (event: MouseEvent<HTMLDialogElement>) => {\n if (\n event.target === event.currentTarget &&\n pressStartedOnBackdrop.current &&\n openRef.current\n ) {\n dismissRef.current?.(\"backdrop\", event);\n }\n pressStartedOnBackdrop.current = false;\n onClick?.(event);\n event.stopPropagation();\n },\n [onClick]\n );\n\n // React events from a portal bubble through the React tree, so an Escape from the content would reach an\n // ancestor's handler, like an older Sheet's, before the document listener. The dialog takes it here first.\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent<HTMLDialogElement>) => {\n onKeyDown?.(event);\n\n if (\n event.defaultPrevented ||\n (event.key !== \"Escape\" && event.key !== \"Esc\") ||\n stackIdRef.current === undefined ||\n !isTopModalRoot(stackIdRef.current)\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n // An Escape a layer in the overlay root did not take stops here too, so it does not close the sheet that\n // opened this dialog, but it leaves the dialog open.\n if (overlayRootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n if (openRef.current) {\n dismissRef.current?.(\"escape\");\n }\n },\n [onKeyDown]\n );\n\n const handleExited = useCallback(() => {\n if (!open) {\n finishClose();\n }\n }, [open, finishClose]);\n\n if (!mounted) {\n return null;\n }\n\n let content: ReactNode = null;\n\n if (contentShown) {\n content =\n typeof children === \"function\"\n ? children({ in: open, onExited: handleExited })\n : children;\n }\n\n return (\n <Portal>\n <RemoveScroll\n forwardProps\n ref={handleRef}\n enabled={!disableScrollLock}\n noIsolation\n >\n <StyledModalRoot\n tabIndex={-1}\n {...rest}\n className={classnames(\"c-modal-root\", className)}\n data-state={open ? \"open\" : \"closing\"}\n onPointerDown={handlePointerDown}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n >\n <div ref={contentRef} className=\"c-modal-root__content\">\n <PortalContainerProvider value={getOverlayRoot}>\n {content}\n </PortalContainerProvider>\n </div>\n <div ref={overlayRootRef} className=\"c-modal-root__overlays\" />\n </StyledModalRoot>\n </RemoveScroll>\n </Portal>\n );\n }\n);\n\nModalRoot.displayName = \"ModalRoot\";\n"],"mappings":";;;AAAA,OAAOA,KAAK,IACVC,UAAU,EAMVC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,MAAM,EACNC,QAAQ,QACH,OAAO;AACd,SAASC,YAAY,QAAQ,qBAAqB;AAElD,OAAOC,UAAU,MAAM,YAAY;AAEnC,SACEC,sBAAsB,EACtBC,iBAAiB,EACjBC,cAAc,EAEdC,YAAY,EACZC,aAAa,EACbC,gBAAgB,EAChBC,eAAe,EACfC,qBAAqB,QAChB,kBAAkB;AACzB,SAASC,eAAe,QAAQ,UAAU;AAC1C,SAASC,0BAA0B,QAAQ,qBAAqB;AAChE,SAASC,MAAM,EAAEC,uBAAuB,QAAQ,eAAe;AAC/D,SAASC,WAAW,EAAEC,MAAM,QAAQ,oBAAoB;AACxD,OAAOC,UAAU,MAAM,wBAAwB;AAI/C,MAAMC,SAAS,GACb,0NAA0N;;AAE5N;AACA;AACA,MAAMC,mBAAmB,GAAGA,CAC1BC,MAAyB,EACzBC,WAA+B,KAC5B;EACHC,KAAK,CAACC,IAAI,CAACH,MAAM,CAACI,gBAAgB,CAAcN,SAAS,CAAC,CAAC,CAACO,IAAI,CAC7DC,SAAS,IAAK;IACb,IAAIL,WAAW,YAAXA,WAAW,CAAEM,QAAQ,CAACD,SAAS,CAAC,EAAE;MACpC,OAAO,KAAK;IACd;IAEAA,SAAS,CAACE,KAAK,CAAC,CAAC;IAEjB,OAAOC,QAAQ,CAACC,aAAa,KAAKJ,SAAS;EAC7C,CACF,CAAC;AACH,CAAC;AAED,MAAMK,kBAAkB,GAAG,CAAC;;AAE5B;AACA,MAAMC,W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ACsH,WAAW,GAAG,WAAW","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"Styles.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/Styles.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAQ1C,eAAO,MAAM,eAAe,uEAgC3B,CAAC"}
1
+ {"version":3,"file":"Styles.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/Styles.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAQ1C,eAAO,MAAM,eAAe,uEAoD3B,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import styled, { keyframes } from "styled-components";
2
+ import { layers } from "../../utils/layers";
2
3
  import { BoxSizingStyle } from "../BoxSizingStyle";
3
4
  import { FontStyle } from "../FontStyle";
4
5
  export const MODAL_ROOT_BACKDROP_MS = 200;
@@ -6,6 +7,6 @@ const backdropIn = keyframes(["from{background-color:transparent;}"]);
6
7
  export const StyledModalRoot = styled.dialog.withConfig({
7
8
  displayName: "Styles__StyledModalRoot",
8
9
  componentId: "sc-48b5xq-0"
9
- })(["", " ", " position:fixed;inset:0;width:100%;height:100%;max-width:none;max-height:none;margin:0;padding:0;border:0;background:var(--modal-background);color:inherit;overflow:visible;animation:", " ", "ms ease;transition:background-color ", "ms ease;&[data-state=\"closing\"]{background-color:transparent;}&:focus-visible{outline:none;}&::backdrop{background:transparent;}"], FontStyle, BoxSizingStyle, backdropIn, MODAL_ROOT_BACKDROP_MS, MODAL_ROOT_BACKDROP_MS);
10
+ })(["", " ", " position:fixed;inset:0;width:100%;height:100%;max-width:none;max-height:none;margin:0;padding:0;border:0;background:var(--modal-background);color:inherit;overflow:visible;animation:", " ", "ms ease;transition:background-color ", "ms ease;&[data-state=\"closing\"]{background-color:transparent;}&[data-state=\"closing\"]:not([open]){display:block;z-index:", ";pointer-events:none;}&[data-state=\"closing\"]:not([open]) > .c-modal-root__overlays{pointer-events:auto;}&[data-state=\"closing\"]::backdrop{pointer-events:none;}> .c-modal-root__content{display:contents;}&:focus{outline:none;}&::backdrop{background:transparent;}"], FontStyle, BoxSizingStyle, backdropIn, MODAL_ROOT_BACKDROP_MS, MODAL_ROOT_BACKDROP_MS, layers.cloud - 1);
10
11
  StyledModalRoot.displayName = "StyledModalRoot";
11
12
  //# sourceMappingURL=Styles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Styles.js","names":["styled","keyframes","BoxSizingStyle","FontStyle","MODAL_ROOT_BACKDROP_MS","backdropIn","StyledModalRoot","dialog","withConfig","displayName","componentId"],"sources":["../../../../src/components/ModalRoot/Styles.ts"],"sourcesContent":["import styled, { keyframes } from \"styled-components\";\n\nimport { BoxSizingStyle } from \"../BoxSizingStyle\";\nimport { FontStyle } from \"../FontStyle\";\n\nexport const MODAL_ROOT_BACKDROP_MS = 200;\n\nconst backdropIn = keyframes`\n from {\n background-color: transparent;\n }\n`;\n\nexport const StyledModalRoot = styled.dialog`\n ${FontStyle}\n ${BoxSizingStyle}\n\n position: fixed;\n inset: 0;\n width: 100%;\n height: 100%;\n max-width: none;\n max-height: none;\n margin: 0;\n padding: 0;\n border: 0;\n // The dialog covers the viewport, so it carries the backdrop colour itself. ::backdrop only inherits the\n // custom properties from Chrome 122 and Safari 17.4 on, and would be transparent before that.\n background: var(--modal-background);\n color: inherit;\n overflow: visible;\n animation: ${backdropIn} ${MODAL_ROOT_BACKDROP_MS}ms ease;\n transition: background-color ${MODAL_ROOT_BACKDROP_MS}ms ease;\n\n &[data-state=\"closing\"] {\n background-color: transparent;\n }\n\n &:focus-visible {\n outline: none;\n }\n\n &::backdrop {\n background: transparent;\n }\n`;\n\nStyledModalRoot.displayName = \"StyledModalRoot\";\n"],"mappings":"AAAA,OAAOA,MAAM,IAAIC,SAAS,QAAQ,mBAAmB;AAErD,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,SAAS,QAAQ,cAAc;AAExC,OAAO,MAAMC,sBAAsB,GAAG,GAAG;AAEzC,MAAMC,UAAU,GAAGJ,SAAS,yCAI3B;AAED,OAAO,MAAMK,eAAe,GAAGN,MAAM,CAACO,MAAM,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,2XACxCP,SAAS,EACTD,cAAc,EAgBHG,UAAU,EAAID,sBAAsB,EAClBA,sBAAsB,CAatD;AAEDE,eAAe,CAACG,WAAW,GAAG,iBAAiB","ignoreList":[]}
1
+ {"version":3,"file":"Styles.js","names":["styled","keyframes","layers","BoxSizingStyle","FontStyle","MODAL_ROOT_BACKDROP_MS","backdropIn","StyledModalRoot","dialog","withConfig","displayName","componentId","cloud"],"sources":["../../../../src/components/ModalRoot/Styles.ts"],"sourcesContent":["import styled, { keyframes } from \"styled-components\";\n\nimport { layers } from \"../../utils/layers\";\nimport { BoxSizingStyle } from \"../BoxSizingStyle\";\nimport { FontStyle } from \"../FontStyle\";\n\nexport const MODAL_ROOT_BACKDROP_MS = 200;\n\nconst backdropIn = keyframes`\n from {\n background-color: transparent;\n }\n`;\n\nexport const StyledModalRoot = styled.dialog`\n ${FontStyle}\n ${BoxSizingStyle}\n\n position: fixed;\n inset: 0;\n width: 100%;\n height: 100%;\n max-width: none;\n max-height: none;\n margin: 0;\n padding: 0;\n border: 0;\n // The dialog covers the viewport, so it carries the backdrop colour itself. ::backdrop only inherits the\n // custom properties from Chrome 122 and Safari 17.4 on, and would be transparent before that.\n background: var(--modal-background);\n color: inherit;\n overflow: visible;\n animation: ${backdropIn} ${MODAL_ROOT_BACKDROP_MS}ms ease;\n transition: background-color ${MODAL_ROOT_BACKDROP_MS}ms ease;\n\n &[data-state=\"closing\"] {\n background-color: transparent;\n }\n\n // Closed as its exit starts, the dialog stays shown until it unmounts, and clicks pass through it to the page. Where\n // popovers are missing it leaves the top layer and stays above the page only.\n &[data-state=\"closing\"]:not([open]) {\n display: block;\n z-index: ${layers.cloud - 1};\n pointer-events: none;\n }\n\n &[data-state=\"closing\"]:not([open]) > .c-modal-root__overlays {\n pointer-events: auto;\n }\n\n &[data-state=\"closing\"]::backdrop {\n pointer-events: none;\n }\n\n > .c-modal-root__content {\n display: contents;\n }\n\n &:focus {\n outline: none;\n }\n\n &::backdrop {\n background: transparent;\n }\n`;\n\nStyledModalRoot.displayName = \"StyledModalRoot\";\n"],"mappings":"AAAA,OAAOA,MAAM,IAAIC,SAAS,QAAQ,mBAAmB;AAErD,SAASC,MAAM,QAAQ,oBAAoB;AAC3C,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,SAAS,QAAQ,cAAc;AAExC,OAAO,MAAMC,sBAAsB,GAAG,GAAG;AAEzC,MAAMC,UAAU,GAAGL,SAAS,yCAI3B;AAED,OAAO,MAAMM,eAAe,GAAGP,MAAM,CAACQ,MAAM,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,koBACxCP,SAAS,EACTD,cAAc,EAgBHG,UAAU,EAAID,sBAAsB,EAClBA,sBAAsB,EAUxCH,MAAM,CAACU,KAAK,GAAG,CAAC,CAuB9B;AAEDL,eAAe,CAACG,WAAW,GAAG,iBAAiB","ignoreList":[]}
@@ -5,6 +5,18 @@ export interface ModalRootSuspension {
5
5
  }
6
6
  export declare const pushModalRoot: (overlayRoot: HTMLElement | null, suspension?: ModalRootSuspension, belowOpenSheets?: boolean) => number;
7
7
  export declare const popModalRoot: (id: number) => void;
8
+ /**
9
+ * A modal root that plays its exit transition is no longer open: it leaves every query of the stack, and only keeps
10
+ * the hosts already in its overlay root until popModalRoot.
11
+ */
12
+ export declare const releaseModalRoot: (id: number) => void;
13
+ /** Reopened during its exit, a modal root keeps its id unless a newer one is in the stack; false then. */
14
+ export declare const reopenModalRoot: (id: number) => boolean;
15
+ /**
16
+ * True when the host sits in the overlay root of a modal root that plays its exit transition and stays active. An
17
+ * open modal root beside it would leave the host inert, so the host moves into that one at once.
18
+ */
19
+ export declare const isHeldByClosingModalRoot: (host: HTMLElement) => boolean;
8
20
  export declare const isTopModalRoot: (id: number) => boolean;
9
21
  /**
10
22
  * The overlay root of the top open modal root, where content that must stay above every modal goes. A modal root
@@ -1 +1 @@
1
- {"version":3,"file":"modalRootStack.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/modalRootStack.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC;AAE3B,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAiBD,eAAO,MAAM,aAAa,GACxB,aAAa,WAAW,GAAG,IAAI,EAC/B,aAAa,mBAAmB,EAChC,yBAAuB,KACtB,MAYF,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,IAAI,MAAM,KAAG,IAOzC,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,IAAI,MAAM,KAAG,OACR,CAAC;AAKrC;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,UAAU,IAAI,KAAG,WAAW,GAAG,IACS,CAAC;AAEhF,yEAAyE;AACzE,eAAO,MAAM,iBAAiB,QAAO,MAAM,GAAG,SACjB,CAAC;AAE9B;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAClC,IAAI,MAAM,EACV,UAAU,IAAI,KACb,WAAW,GAAG,IAMc,CAAC;AAEhC,kGAAkG;AAClG,eAAO,MAAM,gCAAgC,QAAO,MAAM,GAAG,SACH,CAAC;AAE3D,eAAO,MAAM,qBAAqB,GAAI,UAAU,QAAQ,KAAG,CAAC,MAAM,IAAI,CAMrE,CAAC;AAEF,yEAAyE;AACzE,eAAO,MAAM,sBAAsB,QAAO,OAA0B,CAAC;AAErE;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,QAAO,CAAC,MAAM,IAAI,CAqB/C,CAAC"}
1
+ {"version":3,"file":"modalRootStack.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/modalRootStack.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAC;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