@activecollab/components 2.0.555 → 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 +129 -28
  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 +2 -1
  14. package/dist/esm/components/ModalRoot/ModalRoot.d.ts.map +1 -1
  15. package/dist/esm/components/ModalRoot/ModalRoot.js +130 -29
  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 +300 -125
  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
@@ -1,8 +1,11 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  const listeners = new Set();
2
3
  let stack = [];
3
4
  let lastId = 0;
4
5
  let suspensions = 0;
5
6
  const notify = () => listeners.forEach(listener => listener());
7
+ const getOpenEntries = () => stack.filter(entry => !entry.closing);
8
+ const isInside = (entry, outside) => !!outside && !!entry.overlayRoot && outside.contains(entry.overlayRoot);
6
9
  export const pushModalRoot = function (overlayRoot, suspension, belowOpenSheets) {
7
10
  if (belowOpenSheets === void 0) {
8
11
  belowOpenSheets = false;
@@ -29,11 +32,57 @@ export const popModalRoot = id => {
29
32
  stack = stack.filter(entry => entry.id !== id);
30
33
  notify();
31
34
  };
35
+
36
+ /**
37
+ * A modal root that plays its exit transition is no longer open: it leaves every query of the stack, and only keeps
38
+ * the hosts already in its overlay root until popModalRoot.
39
+ */
40
+ export const releaseModalRoot = id => {
41
+ const entry = stack.find(candidate => candidate.id === id);
42
+ if (!entry || entry.closing) {
43
+ return;
44
+ }
45
+ stack = stack.map(candidate => candidate === entry ? _extends({}, candidate, {
46
+ closing: true
47
+ }) : candidate);
48
+ notify();
49
+ };
50
+
51
+ /** Reopened during its exit, a modal root keeps its id unless a newer one is in the stack; false then. */
52
+ export const reopenModalRoot = id => {
53
+ const entry = stack[stack.length - 1];
54
+ if ((entry == null ? void 0 : entry.id) !== id) {
55
+ return false;
56
+ }
57
+ stack = stack.map(candidate => candidate === entry ? _extends({}, candidate, {
58
+ closing: false
59
+ }) : candidate);
60
+ if (suspensions > 0) {
61
+ var _entry$suspension;
62
+ (_entry$suspension = entry.suspension) == null || _entry$suspension.suspend();
63
+ }
64
+ notify();
65
+ return true;
66
+ };
67
+
68
+ /**
69
+ * The top open modal root makes a closing one inert unless it contains it, also when it opened during the exit. One
70
+ * opened from content the closing one holds sits inside it and is skipped.
71
+ */
72
+ const isLeftActive = entry => {
73
+ const top = getOpenEntries().filter(open => !isInside(open, entry.overlayRoot)).pop();
74
+ return !top || !!top.overlayRoot && !!entry.overlayRoot && top.overlayRoot.contains(entry.overlayRoot);
75
+ };
76
+
77
+ /**
78
+ * True when the host sits in the overlay root of a modal root that plays its exit transition and stays active. An
79
+ * open modal root beside it would leave the host inert, so the host moves into that one at once.
80
+ */
81
+ export const isHeldByClosingModalRoot = host => stack.some(entry => entry.closing && !!entry.overlayRoot && entry.overlayRoot === host.parentElement && isLeftActive(entry));
32
82
  export const isTopModalRoot = id => {
33
- var _stack;
34
- return ((_stack = stack[stack.length - 1]) == null ? void 0 : _stack.id) === id;
83
+ var _getOpenEntries$pop;
84
+ return ((_getOpenEntries$pop = getOpenEntries().pop()) == null ? void 0 : _getOpenEntries$pop.id) === id;
35
85
  };
36
- const isInside = (entry, outside) => !!outside && !!entry.overlayRoot && outside.contains(entry.overlayRoot);
37
86
 
38
87
  /**
39
88
  * The overlay root of the top open modal root, where content that must stay above every modal goes. A modal root
@@ -41,14 +90,14 @@ const isInside = (entry, outside) => !!outside && !!entry.overlayRoot && outside
41
90
  * itself.
42
91
  */
43
92
  export const getTopModalOverlayRoot = outside => {
44
- var _stack$filter$pop$ove, _stack$filter$pop;
45
- return (_stack$filter$pop$ove = (_stack$filter$pop = stack.filter(entry => !isInside(entry, outside)).pop()) == null ? void 0 : _stack$filter$pop.overlayRoot) != null ? _stack$filter$pop$ove : null;
93
+ var _getOpenEntries$filte, _getOpenEntries$filte2;
94
+ return (_getOpenEntries$filte = (_getOpenEntries$filte2 = getOpenEntries().filter(entry => !isInside(entry, outside)).pop()) == null ? void 0 : _getOpenEntries$filte2.overlayRoot) != null ? _getOpenEntries$filte : null;
46
95
  };
47
96
 
48
97
  /** The id of the top open modal root, or undefined when none is open. */
49
98
  export const getTopModalRootId = () => {
50
- var _stack2;
51
- return (_stack2 = stack[stack.length - 1]) == null ? void 0 : _stack2.id;
99
+ var _getOpenEntries$pop2;
100
+ return (_getOpenEntries$pop2 = getOpenEntries().pop()) == null ? void 0 : _getOpenEntries$pop2.id;
52
101
  };
53
102
 
54
103
  /**
@@ -57,14 +106,14 @@ export const getTopModalRootId = () => {
57
106
  * when another modal opened in between from outside the sheet.
58
107
  */
59
108
  export const getModalOverlayRootUpTo = (id, outside) => {
60
- var _stack$filter$pop$ove2, _stack$filter$pop2;
61
- return (_stack$filter$pop$ove2 = (_stack$filter$pop2 = stack.filter(entry => (entry.id <= id || entry.belowOpenSheets) && !isInside(entry, outside)).pop()) == null ? void 0 : _stack$filter$pop2.overlayRoot) != null ? _stack$filter$pop$ove2 : null;
109
+ var _getOpenEntries$filte3, _getOpenEntries$filte4;
110
+ return (_getOpenEntries$filte3 = (_getOpenEntries$filte4 = getOpenEntries().filter(entry => (entry.id <= id || entry.belowOpenSheets) && !isInside(entry, outside)).pop()) == null ? void 0 : _getOpenEntries$filte4.overlayRoot) != null ? _getOpenEntries$filte3 : null;
62
111
  };
63
112
 
64
113
  /** The id of the top modal root that opened below open sheets, or undefined when none is open. */
65
114
  export const getTopModalRootIdBelowOpenSheets = () => {
66
- var _stack$filter$pop3;
67
- return (_stack$filter$pop3 = stack.filter(entry => entry.belowOpenSheets).pop()) == null ? void 0 : _stack$filter$pop3.id;
115
+ var _getOpenEntries$filte5;
116
+ return (_getOpenEntries$filte5 = getOpenEntries().filter(entry => entry.belowOpenSheets).pop()) == null ? void 0 : _getOpenEntries$filte5.id;
68
117
  };
69
118
  export const subscribeToModalRoots = listener => {
70
119
  listeners.add(listener);
@@ -86,9 +135,9 @@ export const areModalRootsSuspended = () => suspensions > 0;
86
135
  export const suspendModalRoots = () => {
87
136
  suspensions += 1;
88
137
  if (suspensions === 1) {
89
- [...stack].reverse().forEach(entry => {
90
- var _entry$suspension;
91
- return (_entry$suspension = entry.suspension) == null ? void 0 : _entry$suspension.suspend();
138
+ getOpenEntries().reverse().forEach(entry => {
139
+ var _entry$suspension2;
140
+ return (_entry$suspension2 = entry.suspension) == null ? void 0 : _entry$suspension2.suspend();
92
141
  });
93
142
  }
94
143
  let released = false;
@@ -99,9 +148,9 @@ export const suspendModalRoots = () => {
99
148
  released = true;
100
149
  suspensions -= 1;
101
150
  if (suspensions === 0) {
102
- stack.forEach(entry => {
103
- var _entry$suspension2;
104
- return (_entry$suspension2 = entry.suspension) == null ? void 0 : _entry$suspension2.resume();
151
+ getOpenEntries().forEach(entry => {
152
+ var _entry$suspension3;
153
+ return (_entry$suspension3 = entry.suspension) == null ? void 0 : _entry$suspension3.resume();
105
154
  });
106
155
  }
107
156
  };
@@ -1 +1 @@
1
- {"version":3,"file":"modalRootStack.js","names":["listeners","Set","stack","lastId","suspensions","notify","forEach","listener","pushModalRoot","overlayRoot","suspension","belowOpenSheets","id","suspend","popModalRoot","some","entry","filter","isTopModalRoot","_stack","length","isInside","outside","contains","getTopModalOverlayRoot","_stack$filter$pop$ove","_stack$filter$pop","pop","getTopModalRootId","_stack2","getModalOverlayRootUpTo","_stack$filter$pop$ove2","_stack$filter$pop2","getTopModalRootIdBelowOpenSheets","_stack$filter$pop3","subscribeToModalRoots","add","delete","areModalRootsSuspended","suspendModalRoots","reverse","_entry$suspension","released","_entry$suspension2","resume"],"sources":["../../../../src/components/ModalRoot/modalRootStack.ts"],"sourcesContent":["type Listener = () => void;\n\nexport interface ModalRootSuspension {\n suspend: () => void;\n resume: () => void;\n}\n\ninterface Entry {\n id: number;\n overlayRoot: HTMLElement | null;\n suspension?: ModalRootSuspension;\n belowOpenSheets: boolean;\n}\n\nconst listeners = new Set<Listener>();\n\nlet stack: Entry[] = [];\nlet lastId = 0;\nlet suspensions = 0;\n\nconst notify = (): void => listeners.forEach((listener) => listener());\n\nexport const pushModalRoot = (\n overlayRoot: HTMLElement | null,\n suspension?: ModalRootSuspension,\n belowOpenSheets = false\n): number => {\n lastId += 1;\n stack = [...stack, { id: lastId, overlayRoot, suspension, belowOpenSheets }];\n\n // A modal root that opens while the others are suspended joins them, or it would leave the overlay inert.\n if (suspensions > 0) {\n suspension?.suspend();\n }\n\n notify();\n\n return lastId;\n};\n\nexport const popModalRoot = (id: number): void => {\n if (!stack.some((entry) => entry.id === id)) {\n return;\n }\n\n stack = stack.filter((entry) => entry.id !== id);\n notify();\n};\n\nexport const isTopModalRoot = (id: number): boolean =>\n stack[stack.length - 1]?.id === id;\n\nconst isInside = (entry: Entry, outside?: Node) =>\n !!outside && !!entry.overlayRoot && outside.contains(entry.overlayRoot);\n\n/**\n * The overlay root of the top open modal root, where content that must stay above every modal goes. A modal root\n * whose overlay root sits inside outside, one opened from that content, is skipped, since content cannot move into\n * itself.\n */\nexport const getTopModalOverlayRoot = (outside?: Node): HTMLElement | null =>\n stack.filter((entry) => !isInside(entry, outside)).pop()?.overlayRoot ?? null;\n\n/** The id of the top open modal root, or undefined when none is open. */\nexport const getTopModalRootId = (): number | undefined =>\n stack[stack.length - 1]?.id;\n\n/**\n * The overlay root of the top modal root among those opened no later than the given one, or opened below open\n * sheets, skipping as above. A modal opened below open sheets counts whatever its id, so a sheet moves into it also\n * when another modal opened in between from outside the sheet.\n */\nexport const getModalOverlayRootUpTo = (\n id: number,\n outside?: Node\n): HTMLElement | null =>\n stack\n .filter(\n (entry) =>\n (entry.id <= id || entry.belowOpenSheets) && !isInside(entry, outside)\n )\n .pop()?.overlayRoot ?? null;\n\n/** The id of the top modal root that opened below open sheets, or undefined when none is open. */\nexport const getTopModalRootIdBelowOpenSheets = (): number | undefined =>\n stack.filter((entry) => entry.belowOpenSheets).pop()?.id;\n\nexport const subscribeToModalRoots = (listener: Listener): (() => void) => {\n listeners.add(listener);\n\n return (): void => {\n listeners.delete(listener);\n };\n};\n\n/** True while suspendModalRoots holds the open modal roots non-modal. */\nexport const areModalRootsSuspended = (): boolean => suspensions > 0;\n\n/**\n * Turns every open modal root into a non-modal dialog until the returned release is called, so an overlay that a\n * third party renders into document.body, such as the Google Drive picker, can be used above them. The dialogs keep\n * their place, look, content and order, and do not close. Calls nest: the modal roots come back, from the bottom up,\n * with the last release. A suspended dialog sits at layers.cloud - 1, so the overlay must be at layers.cloud or above;\n * the frontend raises the Google Drive picker there in its own CSS.\n */\nexport const suspendModalRoots = (): (() => void) => {\n suspensions += 1;\n\n if (suspensions === 1) {\n [...stack].reverse().forEach((entry) => entry.suspension?.suspend());\n }\n\n let released = false;\n\n return () => {\n if (released) {\n return;\n }\n\n released = true;\n suspensions -= 1;\n\n if (suspensions === 0) {\n stack.forEach((entry) => entry.suspension?.resume());\n }\n };\n};\n"],"mappings":"AAcA,MAAMA,SAAS,GAAG,IAAIC,GAAG,CAAW,CAAC;AAErC,IAAIC,KAAc,GAAG,EAAE;AACvB,IAAIC,MAAM,GAAG,CAAC;AACd,IAAIC,WAAW,GAAG,CAAC;AAEnB,MAAMC,MAAM,GAAGA,CAAA,KAAYL,SAAS,CAACM,OAAO,CAAEC,QAAQ,IAAKA,QAAQ,CAAC,CAAC,CAAC;AAEtE,OAAO,MAAMC,aAAa,GAAG,SAAAA,CAC3BC,WAA+B,EAC/BC,UAAgC,EAChCC,eAAe,EACJ;EAAA,IADXA,eAAe;IAAfA,eAAe,GAAG,KAAK;EAAA;EAEvBR,MAAM,IAAI,CAAC;EACXD,KAAK,GAAG,CAAC,GAAGA,KAAK,EAAE;IAAEU,EAAE,EAAET,MAAM;IAAEM,WAAW;IAAEC,UAAU;IAAEC;EAAgB,CAAC,CAAC;;EAE5E;EACA,IAAIP,WAAW,GAAG,CAAC,EAAE;IACnBM,UAAU,YAAVA,UAAU,CAAEG,OAAO,CAAC,CAAC;EACvB;EAEAR,MAAM,CAAC,CAAC;EAER,OAAOF,MAAM;AACf,CAA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MAAM;IACX,IAAIA,QAAQ,EAAE;MACZ;IACF;IAEAA,QAAQ,GAAG,IAAI;IACftC,WAAW,IAAI,CAAC;IAEhB,IAAIA,WAAW,KAAK,CAAC,EAAE;MACrBF,KAAK,CAACI,OAAO,CAAEU,KAAK;QAAA,IAAA2B,kBAAA;QAAA,QAAAA,kBAAA,GAAK3B,KAAK,CAACN,UAAU,qBAAhBiC,kBAAA,CAAkBC,MAAM,CAAC,CAAC;MAAA,EAAC;IACtD;EACF,CAAC;AACH,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"modalRootStack.js","names":["listeners","Set","stack","lastId","suspensions","notify","forEach","listener","getOpenEntries","filter","entry","closing","isInside","outside","overlayRoot","contains","pushModalRoot","suspension","belowOpenSheets","id","suspend","popModalRoot","some","releaseModalRoot","find","candidate","map","_extends","reopenModalRoot","length","_entry$suspension","isLeftActive","top","open","pop","isHeldByClosingModalRoot","host","parentElement","isTopModalRoot","_getOpenEntries$pop","getTopModalOverlayRoot","_getOpenEntries$filte","_getOpenEntries$filte2","getTopModalRootId","_getOpenEntries$pop2","getModalOverlayRootUpTo","_getOpenEntries$filte3","_getOpenEntries$filte4","getTopModalRootIdBelowOpenSheets","_getOpenEntries$filte5","subscribeToModalRoots","add","delete","areModalRootsSuspended","suspendModalRoots","reverse","_entry$suspension2","released","_entry$suspension3","resume"],"sources":["../../../../src/components/ModalRoot/modalRootStack.ts"],"sourcesContent":["type Listener = () => void;\n\nexport interface ModalRootSuspension {\n suspend: () => void;\n resume: () => void;\n}\n\ninterface Entry {\n id: number;\n overlayRoot: HTMLElement | null;\n suspension?: ModalRootSuspension;\n belowOpenSheets: boolean;\n closing?: boolean;\n}\n\nconst listeners = new Set<Listener>();\n\nlet stack: Entry[] = [];\nlet lastId = 0;\nlet suspensions = 0;\n\nconst notify = (): void => listeners.forEach((listener) => listener());\n\nconst getOpenEntries = () => stack.filter((entry) => !entry.closing);\n\nconst isInside = (entry: Entry, outside?: Node | null) =>\n !!outside && !!entry.overlayRoot && outside.contains(entry.overlayRoot);\n\nexport const pushModalRoot = (\n overlayRoot: HTMLElement | null,\n suspension?: ModalRootSuspension,\n belowOpenSheets = false\n): number => {\n lastId += 1;\n stack = [...stack, { id: lastId, overlayRoot, suspension, belowOpenSheets }];\n\n // A modal root that opens while the others are suspended joins them, or it would leave the overlay inert.\n if (suspensions > 0) {\n suspension?.suspend();\n }\n\n notify();\n\n return lastId;\n};\n\nexport const popModalRoot = (id: number): void => {\n if (!stack.some((entry) => entry.id === id)) {\n return;\n }\n\n stack = stack.filter((entry) => entry.id !== id);\n notify();\n};\n\n/**\n * A modal root that plays its exit transition is no longer open: it leaves every query of the stack, and only keeps\n * the hosts already in its overlay root until popModalRoot.\n */\nexport const releaseModalRoot = (id: number): void => {\n const entry = stack.find((candidate) => candidate.id === id);\n\n if (!entry || entry.closing) {\n return;\n }\n\n stack = stack.map((candidate) =>\n candidate === entry ? { ...candidate, closing: true } : candidate\n );\n notify();\n};\n\n/** Reopened during its exit, a modal root keeps its id unless a newer one is in the stack; false then. */\nexport const reopenModalRoot = (id: number): boolean => {\n const entry = stack[stack.length - 1];\n\n if (entry?.id !== id) {\n return false;\n }\n\n stack = stack.map((candidate) =>\n candidate === entry ? { ...candidate, closing: false } : candidate\n );\n\n if (suspensions > 0) {\n entry.suspension?.suspend();\n }\n\n notify();\n\n return true;\n};\n\n/**\n * The top open modal root makes a closing one inert unless it contains it, also when it opened during the exit. One\n * opened from content the closing one holds sits inside it and is skipped.\n */\nconst isLeftActive = (entry: Entry): boolean => {\n const top = getOpenEntries()\n .filter((open) => !isInside(open, entry.overlayRoot))\n .pop();\n\n return (\n !top ||\n (!!top.overlayRoot &&\n !!entry.overlayRoot &&\n top.overlayRoot.contains(entry.overlayRoot))\n );\n};\n\n/**\n * True when the host sits in the overlay root of a modal root that plays its exit transition and stays active. An\n * open modal root beside it would leave the host inert, so the host moves into that one at once.\n */\nexport const isHeldByClosingModalRoot = (host: HTMLElement): boolean =>\n stack.some(\n (entry) =>\n entry.closing &&\n !!entry.overlayRoot &&\n entry.overlayRoot === host.parentElement &&\n isLeftActive(entry)\n );\n\nexport const isTopModalRoot = (id: number): boolean =>\n getOpenEntries().pop()?.id === id;\n\n/**\n * The overlay root of the top open modal root, where content that must stay above every modal goes. A modal root\n * whose overlay root sits inside outside, one opened from that content, is skipped, since content cannot move into\n * itself.\n */\nexport const getTopModalOverlayRoot = (outside?: Node): HTMLElement | null =>\n getOpenEntries()\n .filter((entry) => !isInside(entry, outside))\n .pop()?.overlayRoot ?? null;\n\n/** The id of the top open modal root, or undefined when none is open. */\nexport const getTopModalRootId = (): number | undefined =>\n getOpenEntries().pop()?.id;\n\n/**\n * The overlay root of the top modal root among those opened no later than the given one, or opened below open\n * sheets, skipping as above. A modal opened below open sheets counts whatever its id, so a sheet moves into it also\n * when another modal opened in between from outside the sheet.\n */\nexport const getModalOverlayRootUpTo = (\n id: number,\n outside?: Node\n): HTMLElement | null =>\n getOpenEntries()\n .filter(\n (entry) =>\n (entry.id <= id || entry.belowOpenSheets) && !isInside(entry, outside)\n )\n .pop()?.overlayRoot ?? null;\n\n/** The id of the top modal root that opened below open sheets, or undefined when none is open. */\nexport const getTopModalRootIdBelowOpenSheets = (): number | undefined =>\n getOpenEntries()\n .filter((entry) => entry.belowOpenSheets)\n .pop()?.id;\n\nexport const subscribeToModalRoots = (listener: Listener): (() => void) => {\n listeners.add(listener);\n\n return (): void => {\n listeners.delete(listener);\n };\n};\n\n/** True while suspendModalRoots holds the open modal roots non-modal. */\nexport const areModalRootsSuspended = (): boolean => suspensions > 0;\n\n/**\n * Turns every open modal root into a non-modal dialog until the returned release is called, so an overlay that a\n * third party renders into document.body, such as the Google Drive picker, can be used above them. The dialogs keep\n * their place, look, content and order, and do not close. Calls nest: the modal roots come back, from the bottom up,\n * with the last release. A suspended dialog sits at layers.cloud - 1, so the overlay must be at layers.cloud or above;\n * the frontend raises the Google Drive picker there in its own CSS.\n */\nexport const suspendModalRoots = (): (() => void) => {\n suspensions += 1;\n\n if (suspensions === 1) {\n getOpenEntries()\n .reverse()\n .forEach((entry) => entry.suspension?.suspend());\n }\n\n let released = false;\n\n return () => {\n if (released) {\n return;\n }\n\n released = true;\n suspensions -= 1;\n\n if (suspensions === 0) {\n getOpenEntries().forEach((entry) => entry.suspension?.resume());\n }\n };\n};\n"],"mappings":";AAeA,MAAMA,SAAS,GAAG,IAAIC,GAAG,CAAW,CAAC;AAErC,IAAIC,KAAc,GAAG,EAAE;AACvB,IAAIC,MAAM,GAAG,CAAC;AACd,IAAIC,WAAW,GAAG,CAAC;AAEnB,MAAMC,MAAM,GAAGA,CAAA,KAAYL,SAAS,CAACM,OAAO,CAAEC,QAAQ,IAAKA,QAAQ,CAAC,CAAC,CAAC;AAEtE,MAAMC,cAAc,GAAGA,CAAA,KAAMN,KAAK,CAACO,MAAM,CAAEC,KAAK,IAAK,CAACA,KAAK,CAACC,OAAO,CAAC;AAEpE,MAAMC,QAAQ,GAAGA,CAACF,KAAY,EAAEG,OAAqB,KACnD,CAAC,CAACA,OAAO,IAAI,CAAC,CAACH,KAAK,CAACI,WAAW,IAAID,OAAO,CAACE,QAAQ,CAACL,KAAK,CAACI,WAAW,CAAC;AAEzE,OAAO,MAAME,aAAa,GAAG,SAAAA,CAC3BF,WAA+B,EAC/BG,UAAgC,EAChCC,eAAe,EACJ;EAAA,IADXA,eAAe;IAAfA,eAAe,GAAG,KAAK;EAAA;EAEvBf,MAAM,IAAI,CAAC;EACXD,KAAK,GAAG,CAAC,GAAGA,KAAK,EAAE;IAAEiB,EAAE,EAAEhB,MAAM;IAAEW,WAAW;IAAEG,UAAU;IAAEC;EAAgB,CAAC,CAAC;;EAE5E;EACA,IAAId,WAAW,GAAG,CAAC,EAAE;IACnBa,UAAU,YAAVA,UAAU,CAAEG,OAAO,CAAC,CAAC;EACvB;EAEAf,MAAM,CAAC,CAAC;EAER,OAAOF,MAAM;AACf,CAAC;AAED,OAAO,MAAMkB,YAAY,GAAIF,EAAU,IAA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AAW,KAAK,CAAC,EAAE;IACrBI,cAAc,CAAC,CAAC,CACb+C,OAAO,CAAC,CAAC,CACTjD,OAAO,CAAEI,KAAK;MAAA,IAAA8C,kBAAA;MAAA,QAAAA,kBAAA,GAAK9C,KAAK,CAACO,UAAU,qBAAhBuC,kBAAA,CAAkBpC,OAAO,CAAC,CAAC;IAAA,EAAC;EACpD;EAEA,IAAIqC,QAAQ,GAAG,KAAK;EAEpB,OAAO,MAAM;IACX,IAAIA,QAAQ,EAAE;MACZ;IACF;IAEAA,QAAQ,GAAG,IAAI;IACfrD,WAAW,IAAI,CAAC;IAEhB,IAAIA,WAAW,KAAK,CAAC,EAAE;MACrBI,cAAc,CAAC,CAAC,CAACF,OAAO,CAAEI,KAAK;QAAA,IAAAgD,kBAAA;QAAA,QAAAA,kBAAA,GAAKhD,KAAK,CAACO,UAAU,qBAAhByC,kBAAA,CAAkBC,MAAM,CAAC,CAAC;MAAA,EAAC;IACjE;EACF,CAAC;AACH,CAAC","ignoreList":[]}
@@ -1,7 +1,9 @@
1
+ export declare const MODAL_STACK_HOST_ATTRIBUTE = "data-modal-stack-host";
1
2
  /**
2
3
  * Keeps a host node in the overlay root of the top open modal, or of the top one opened no later than
3
4
  * upToModalRootId, and in document.body while there is none. A modal opened from the content of the host is not
4
- * counted, since its overlay root is inside the host. The node moves as modals open and close, so content
5
+ * counted, since its overlay root is inside the host. A modal that plays its exit transition keeps the node until
6
+ * it is done. The node moves as modals open and close, so content
5
7
  * portalled into it never remounts and keeps its scroll positions and focus, and it leaves the page on unmount or
6
8
  * when the host changes. Returns whether the
7
9
  * host is in the page, which it is from a layout effect after the first render with it.
@@ -1 +1 @@
1
- {"version":3,"file":"useModalStackHost.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/useModalStackHost.ts"],"names":[],"mappings":"AA8CA;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,WAAW,GAAG,IAAI,EACxB,kBAAkB,MAAM,KACvB,OA+BF,CAAC"}
1
+ {"version":3,"file":"useModalStackHost.d.ts","sourceRoot":"","sources":["../../../../src/components/ModalRoot/useModalStackHost.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,0BAA0B,0BAA0B,CAAC;AAwClE;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,WAAW,GAAG,IAAI,EACxB,kBAAkB,MAAM,KACvB,OAoCF,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { useLayoutEffect, useState } from "react";
2
- import { getModalOverlayRootUpTo, getTopModalOverlayRoot, subscribeToModalRoots } from "./modalRootStack";
2
+ import { getModalOverlayRootUpTo, getTopModalOverlayRoot, isHeldByClosingModalRoot, subscribeToModalRoots } from "./modalRootStack";
3
+ export const MODAL_STACK_HOST_ATTRIBUTE = "data-modal-stack-host";
3
4
  const getScrollPositions = host => Array.from(host.querySelectorAll("*")).filter(element => element.scrollTop || element.scrollLeft).map(element => ({
4
5
  element,
5
6
  top: element.scrollTop,
@@ -33,7 +34,8 @@ const moveHost = (host, target) => {
33
34
  /**
34
35
  * Keeps a host node in the overlay root of the top open modal, or of the top one opened no later than
35
36
  * upToModalRootId, and in document.body while there is none. A modal opened from the content of the host is not
36
- * counted, since its overlay root is inside the host. The node moves as modals open and close, so content
37
+ * counted, since its overlay root is inside the host. A modal that plays its exit transition keeps the node until
38
+ * it is done. The node moves as modals open and close, so content
37
39
  * portalled into it never remounts and keeps its scroll positions and focus, and it leaves the page on unmount or
38
40
  * when the host changes. Returns whether the
39
41
  * host is in the page, which it is from a layout effect after the first render with it.
@@ -48,11 +50,15 @@ export const useModalStackHost = (host, upToModalRootId) => {
48
50
  }
49
51
  const place = () => {
50
52
  var _ref2;
53
+ if (isHeldByClosingModalRoot(host)) {
54
+ return;
55
+ }
51
56
  const target = (_ref2 = upToModalRootId === undefined ? getTopModalOverlayRoot(host) : getModalOverlayRootUpTo(upToModalRootId, host)) != null ? _ref2 : document.body;
52
57
  if (host.parentElement !== target) {
53
58
  moveHost(host, target);
54
59
  }
55
60
  };
61
+ host.setAttribute(MODAL_STACK_HOST_ATTRIBUTE, "");
56
62
  place();
57
63
  setPlacedHost(host);
58
64
  const unsubscribe = subscribeToModalRoots(place);
@@ -1 +1 @@
1
- {"version":3,"file":"useModalStackHost.js","names":["useLayoutEffect","useState","getModalOverlayRootUpTo","getTopModalOverlayRoot","subscribeToModalRoots","getScrollPositions","host","Array","from","querySelectorAll","filter","element","scrollTop","scrollLeft","map","top","left","moveHost","target","isConnected","moveBefore","scrollPositions","focused","contains","document","activeElement","appendChild","forEach","_ref","focus","preventScroll","useModalStackHost","upToModalRootId","_useState","placedHost","setPlacedHost","undefined","place","_ref2","body","parentElement","unsubscribe","remove"],"sources":["../../../../src/components/ModalRoot/useModalStackHost.ts"],"sourcesContent":["import { useLayoutEffect, useState } from \"react\";\n\nimport {\n getModalOverlayRootUpTo,\n getTopModalOverlayRoot,\n subscribeToModalRoots,\n} from \"./modalRootStack\";\n\ntype MovableParent = HTMLElement & {\n moveBefore?: (node: Node, child: Node | null) => void;\n};\n\nconst getScrollPositions = (host: HTMLElement) =>\n Array.from(host.querySelectorAll<HTMLElement>(\"*\"))\n .filter((element) => element.scrollTop || element.scrollLeft)\n .map((element) => ({\n element,\n top: element.scrollTop,\n left: element.scrollLeft,\n }));\n\n/**\n * moveBefore keeps the state of the moved content. appendChild resets the scroll positions inside the host and drops\n * the focus, so without moveBefore they are put back after the move.\n */\nconst moveHost = (host: HTMLElement, target: MovableParent) => {\n if (host.isConnected && target.moveBefore) {\n target.moveBefore(host, null);\n\n return;\n }\n\n const scrollPositions = host.isConnected ? getScrollPositions(host) : [];\n const focused = host.contains(document.activeElement)\n ? (document.activeElement as HTMLElement)\n : null;\n\n target.appendChild(host);\n\n scrollPositions.forEach(({ element, top, left }) => {\n element.scrollTop = top;\n element.scrollLeft = left;\n });\n focused?.focus({ preventScroll: true });\n};\n\n/**\n * Keeps a host node in the overlay root of the top open modal, or of the top one opened no later than\n * upToModalRootId, and in document.body while there is none. A modal opened from the content of the host is not\n * counted, since its overlay root is inside the host. The node moves as modals open and close, so content\n * portalled into it never remounts and keeps its scroll positions and focus, and it leaves the page on unmount or\n * when the host changes. Returns whether the\n * host is in the page, which it is from a layout effect after the first render with it.\n */\nexport const useModalStackHost = (\n host: HTMLElement | null,\n upToModalRootId?: number\n): boolean => {\n const [placedHost, setPlacedHost] = useState<HTMLElement | null>(null);\n\n useLayoutEffect(() => {\n if (!host) {\n return undefined;\n }\n\n const place = () => {\n const target =\n (upToModalRootId === undefined\n ? getTopModalOverlayRoot(host)\n : getModalOverlayRootUpTo(upToModalRootId, host)) ?? document.body;\n\n if (host.parentElement !== target) {\n moveHost(host, target);\n }\n };\n\n place();\n setPlacedHost(host);\n\n const unsubscribe = subscribeToModalRoots(place);\n\n return () => {\n unsubscribe();\n host.remove();\n };\n }, [host, upToModalRootId]);\n\n return host !== null && placedHost === host;\n};\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,QAAQ,QAAQ,OAAO;AAEjD,SACEC,uBAAuB,EACvBC,sBAAsB,EACtBC,qBAAqB,QAChB,kBAAkB;AAMzB,MAAMC,kBAAkB,GAAIC,IAAiB,IAC3CC,KAAK,CAACC,IAAI,CAACF,IAAI,CAACG,gBAAgB,CAAc,GAAG,CAAC,CAAC,CAChDC,MAAM,CAAEC,OAAO,IAAKA,OAAO,CAACC,SAAS,IAAID,OAAO,CAACE,UAAU,CAAC,CAC5DC,GAAG,CAAEH,OAAO,KAAM;EACjBA,OAAO;EACPI,GAAG,EAAEJ,OAAO,CAACC,SAAS;EACtBI,IAAI,EAAEL,OAAO,CAACE;AAChB,CAAC,CAAC,CAAC;;AAEP;AACA;AACA;AACA;AACA,MAAMI,QAAQ,GAAGA,CAACX,IAAiB,EAAEY,MAAqB,KAAK;EAC7D,IAAIZ,IAAI,CAACa,WAAW,IAAID,MAAM,CAACE,UAAU,EAAE;IACzCF,MAAM,CAACE,UAAU,CAACd,IAAI,EAAE,IAAI,CA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,MAAM,EAAE;QACjCD,QAAQ,CAACX,IAAI,EAAEY,MAAM,CAAC;MACxB;IACF,CAAC;IAEDmB,KAAK,CAAC,CAAC;IACPF,aAAa,CAAC7B,IAAI,CAAC;IAEnB,MAAMmC,WAAW,GAAGrC,qBAAqB,CAACiC,KAAK,CAAC;IAEhD,OAAO,MAAM;MACXI,WAAW,CAAC,CAAC;MACbnC,IAAI,CAACoC,MAAM,CAAC,CAAC;IACf,CAAC;EACH,CAAC,EAAE,CAACpC,IAAI,EAAE0B,eAAe,CAAC,CAAC;EAE3B,OAAO1B,IAAI,KAAK,IAAI,IAAI4B,UAAU,KAAK5B,IAAI;AAC7C,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"useModalStackHost.js","names":["useLayoutEffect","useState","getModalOverlayRootUpTo","getTopModalOverlayRoot","isHeldByClosingModalRoot","subscribeToModalRoots","MODAL_STACK_HOST_ATTRIBUTE","getScrollPositions","host","Array","from","querySelectorAll","filter","element","scrollTop","scrollLeft","map","top","left","moveHost","target","isConnected","moveBefore","scrollPositions","focused","contains","document","activeElement","appendChild","forEach","_ref","focus","preventScroll","useModalStackHost","upToModalRootId","_useState","placedHost","setPlacedHost","undefined","place","_ref2","body","parentElement","setAttribute","unsubscribe","remove"],"sources":["../../../../src/components/ModalRoot/useModalStackHost.ts"],"sourcesContent":["import { useLayoutEffect, useState } from \"react\";\n\nimport {\n getModalOverlayRootUpTo,\n getTopModalOverlayRoot,\n isHeldByClosingModalRoot,\n subscribeToModalRoots,\n} from \"./modalRootStack\";\n\nexport const MODAL_STACK_HOST_ATTRIBUTE = \"data-modal-stack-host\";\n\ntype MovableParent = HTMLElement & {\n moveBefore?: (node: Node, child: Node | null) => void;\n};\n\nconst getScrollPositions = (host: HTMLElement) =>\n Array.from(host.querySelectorAll<HTMLElement>(\"*\"))\n .filter((element) => element.scrollTop || element.scrollLeft)\n .map((element) => ({\n element,\n top: element.scrollTop,\n left: element.scrollLeft,\n }));\n\n/**\n * moveBefore keeps the state of the moved content. appendChild resets the scroll positions inside the host and drops\n * the focus, so without moveBefore they are put back after the move.\n */\nconst moveHost = (host: HTMLElement, target: MovableParent) => {\n if (host.isConnected && target.moveBefore) {\n target.moveBefore(host, null);\n\n return;\n }\n\n const scrollPositions = host.isConnected ? getScrollPositions(host) : [];\n const focused = host.contains(document.activeElement)\n ? (document.activeElement as HTMLElement)\n : null;\n\n target.appendChild(host);\n\n scrollPositions.forEach(({ element, top, left }) => {\n element.scrollTop = top;\n element.scrollLeft = left;\n });\n focused?.focus({ preventScroll: true });\n};\n\n/**\n * Keeps a host node in the overlay root of the top open modal, or of the top one opened no later than\n * upToModalRootId, and in document.body while there is none. A modal opened from the content of the host is not\n * counted, since its overlay root is inside the host. A modal that plays its exit transition keeps the node until\n * it is done. The node moves as modals open and close, so content\n * portalled into it never remounts and keeps its scroll positions and focus, and it leaves the page on unmount or\n * when the host changes. Returns whether the\n * host is in the page, which it is from a layout effect after the first render with it.\n */\nexport const useModalStackHost = (\n host: HTMLElement | null,\n upToModalRootId?: number\n): boolean => {\n const [placedHost, setPlacedHost] = useState<HTMLElement | null>(null);\n\n useLayoutEffect(() => {\n if (!host) {\n return undefined;\n }\n\n const place = () => {\n if (isHeldByClosingModalRoot(host)) {\n return;\n }\n\n const target =\n (upToModalRootId === undefined\n ? getTopModalOverlayRoot(host)\n : getModalOverlayRootUpTo(upToModalRootId, host)) ?? document.body;\n\n if (host.parentElement !== target) {\n moveHost(host, target);\n }\n };\n\n host.setAttribute(MODAL_STACK_HOST_ATTRIBUTE, \"\");\n place();\n setPlacedHost(host);\n\n const unsubscribe = subscribeToModalRoots(place);\n\n return () => {\n unsubscribe();\n host.remove();\n };\n }, [host, upToModalRootId]);\n\n return host !== null && placedHost === host;\n};\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,QAAQ,QAAQ,OAAO;AAEjD,SACEC,uBAAuB,EACvBC,sBAAsB,EACtBC,wBAAwB,EACxBC,qBAAqB,QAChB,kBAAkB;AAEzB,O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;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,iBAAiB,GAAGA,CAC/BzB,IAAwB,EACxB0B,eAAwB,KACZ;EACZ,MAAAC,SAAA,GAAoClC,QAAQ,CAAqB,IAAI,CAAC;IAA/DmC,UAAU,GAAAD,SAAA;IAAEE,aAAa,GAAAF,SAAA;EAEhCnC,eAAe,CAAC,MAAM;IACpB,IAAI,CAACQ,IAAI,EAAE;MACT,OAAO8B,SAAS;IAClB;IAEA,MAAMC,KAAK,GAAGA,CAAA,KAAM;MAAA,IAAAC,KAAA;MAClB,IAAIpC,wBAAwB,CAACI,IAAI,CAAC,EAAE;QAClC;MACF;MAEA,MAAMY,MAAM,IAAAoB,KAAA,GACTN,eAAe,KAAKI,SAAS,GAC1BnC,sBAAsB,CAACK,IAAI,CAAC,GAC5BN,uBAAuB,CAACgC,eAAe,EAAE1B,IAAI,CAAC,YAAAgC,KAAA,GAAKd,QAAQ,CAACe,IAAI;MAEtE,IAAIjC,IAAI,CAACkC,aAAa,KAAKtB,MAAM,EAAE;QACjCD,QAAQ,CAACX,IAAI,EAAEY,MAAM,CAAC;MACxB;IACF,CAAC;IAEDZ,IAAI,CAACmC,YAAY,CAACrC,0BAA0B,EAAE,EAAE,CAAC;IACjDiC,KAAK,CAAC,CAAC;IACPF,aAAa,CAAC7B,IAAI,CAAC;IAEnB,MAAMoC,WAAW,GAAGvC,qBAAqB,CAACkC,KAAK,CAAC;IAEhD,OAAO,MAAM;MACXK,WAAW,CAAC,CAAC;MACbpC,IAAI,CAACqC,MAAM,CAAC,CAAC;IACf,CAAC;EACH,CAAC,EAAE,CAACrC,IAAI,EAAE0B,eAAe,CAAC,CAAC;EAE3B,OAAO1B,IAAI,KAAK,IAAI,IAAI4B,UAAU,KAAK5B,IAAI;AAC7C,CAAC","ignoreList":[]}
@@ -6,7 +6,10 @@ export declare const layers: {
6
6
  };
7
7
  /** The layer an element sits in, or null when it sits on the page. */
8
8
  export declare const getLayerOf: (element: Element | null | undefined) => Element | null;
9
- /** The layer in front: the last open window or dialog, or null when the page itself is in front. */
9
+ /**
10
+ * The layer in front: the last open window or dialog that takes input, or null when the page itself is in front. A
11
+ * window in a dialog that plays its exit transition is inert and does not count.
12
+ */
10
13
  export declare const getTopLayer: () => HTMLElement | null;
11
14
  /**
12
15
  * True when the layer of the element is in front. A handler of a global shortcut asks this first, so the shortcut
@@ -1 +1 @@
1
- {"version":3,"file":"layers.d.ts","sourceRoot":"","sources":["../../../src/utils/layers.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;CAKlB,CAAC;AAKF,sEAAsE;AACtE,eAAO,MAAM,UAAU,GAAI,SAAS,OAAO,GAAG,IAAI,GAAG,SAAS,mBAClB,CAAC;AAE7C,oGAAoG;AACpG,eAAO,MAAM,WAAW,QAAO,WAAW,GAAG,IAI5C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,OAAO,GAAG,IAAI,GAAG,SAAS,YACP,CAAC"}
1
+ {"version":3,"file":"layers.d.ts","sourceRoot":"","sources":["../../../src/utils/layers.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;;;;CAKlB,CAAC;AAKF,sEAAsE;AACtE,eAAO,MAAM,UAAU,GAAI,SAAS,OAAO,GAAG,IAAI,GAAG,SAAS,mBAClB,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,WAAW,QAAO,WAAW,GAAG,IAM5C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,OAAO,GAAG,IAAI,GAAG,SAAS,YAGrD,CAAC"}
@@ -14,9 +14,12 @@ export const getLayerOf = element => {
14
14
  return (_element$closest = element == null || element.closest == null ? void 0 : element.closest(LAYER_SELECTOR)) != null ? _element$closest : null;
15
15
  };
16
16
 
17
- /** The layer in front: the last open window or dialog, or null when the page itself is in front. */
17
+ /**
18
+ * The layer in front: the last open window or dialog that takes input, or null when the page itself is in front. A
19
+ * window in a dialog that plays its exit transition is inert and does not count.
20
+ */
18
21
  export const getTopLayer = () => {
19
- const windows = document.querySelectorAll(LAYER_SELECTOR);
22
+ const windows = Array.from(document.querySelectorAll(LAYER_SELECTOR)).filter(layer => !layer.closest("[inert]"));
20
23
  return windows.length ? windows[windows.length - 1] : null;
21
24
  };
22
25
 
@@ -24,5 +27,5 @@ export const getTopLayer = () => {
24
27
  * True when the layer of the element is in front. A handler of a global shortcut asks this first, so the shortcut
25
28
  * goes to the layer the user works in and never to a page or a window under it.
26
29
  */
27
- export const isInTopLayer = element => element ? getLayerOf(element) === getTopLayer() : false;
30
+ export const isInTopLayer = element => element && !element.closest("[inert]") ? getLayerOf(element) === getTopLayer() : false;
28
31
  //# sourceMappingURL=layers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"layers.js","names":["layers","cloud","skyscraper","tower","house","LAYER_SELECTOR","getLayerOf","element","_element$closest","closest","getTopLayer","windows","document","querySelectorAll","length","isInTopLayer"],"sources":["../../../src/utils/layers.ts"],"sourcesContent":["export const layers = {\n cloud: 100000,\n skyscraper: 1300,\n tower: 1200,\n house: 1000,\n};\n\n// A DS window, or a native modal dialog. A window opened inside a dialog comes after it in the document.\nconst LAYER_SELECTOR = \".c-window, dialog[open]\";\n\n/** The layer an element sits in, or null when it sits on the page. */\nexport const getLayerOf = (element: Element | null | undefined) =>\n element?.closest?.(LAYER_SELECTOR) ?? null;\n\n/** The layer in front: the last open window or dialog, or null when the page itself is in front. */\nexport const getTopLayer = (): HTMLElement | null => {\n const windows = document.querySelectorAll<HTMLElement>(LAYER_SELECTOR);\n\n return windows.length ? windows[windows.length - 1] : null;\n};\n\n/**\n * True when the layer of the element is in front. A handler of a global shortcut asks this first, so the shortcut\n * goes to the layer the user works in and never to a page or a window under it.\n */\nexport const isInTopLayer = (element: Element | null | undefined) =>\n element ? getLayerOf(element) === getTopLayer() : false;\n"],"mappings":"AAAA,OAAO,MAAMA,MAAM,GAAG;EACpBC,KAAK,EAAE,MAAM;EACbC,UAAU,EAAE,IAAI;EAChBC,KAAK,EAAE,IAAI;EACXC,KAAK,EAAE;AACT,CAAC;;AAED;AACA,MAAMC,cAAc,GAAG,yBAAyB;;AAEhD;AACA,OAAO,MAAMC,UAAU,GAAIC,OAAmC;EAAA,IAAAC,gBAAA;EAAA,QAAAA,gBAAA,GAC5DD,OAAO,YAAPA,OAAO,CAAEE,OAAO,oBAAhBF,OAAO,CAAEE,OAAO,CAAGJ,cAAc,CAAC,YAAAG,gBAAA,GAAI,IAAI;AAAA;;AAE5C;AACA,OAAO,MAAME,WAAW,GAAGA,CAAA,KAA0B;EACnD,MAAMC,OAAO,GAAGC,QAAQ,CAACC,gBAAgB,CAAcR,cAAc,CAAC;EAEtE,OAAOM,OAAO,CAACG,MAAM,GAAGH,OAAO,CAACA,OAAO,CAACG,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI;AAC5D,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,GAAIR,OAAmC,IAC9DA,OAAO,GAAGD,UAAU,CAACC,OAAO,CAAC,KAAKG,WAAW,CAAC,CAAC,GAAG,KAAK","ignoreList":[]}
1
+ {"version":3,"file":"layers.js","names":["layers","cloud","skyscraper","tower","house","LAYER_SELECTOR","getLayerOf","element","_element$closest","closest","getTopLayer","windows","Array","from","document","querySelectorAll","filter","layer","length","isInTopLayer"],"sources":["../../../src/utils/layers.ts"],"sourcesContent":["export const layers = {\n cloud: 100000,\n skyscraper: 1300,\n tower: 1200,\n house: 1000,\n};\n\n// A DS window, or a native modal dialog. A window opened inside a dialog comes after it in the document.\nconst LAYER_SELECTOR = \".c-window, dialog[open]\";\n\n/** The layer an element sits in, or null when it sits on the page. */\nexport const getLayerOf = (element: Element | null | undefined) =>\n element?.closest?.(LAYER_SELECTOR) ?? null;\n\n/**\n * The layer in front: the last open window or dialog that takes input, or null when the page itself is in front. A\n * window in a dialog that plays its exit transition is inert and does not count.\n */\nexport const getTopLayer = (): HTMLElement | null => {\n const windows = Array.from(\n document.querySelectorAll<HTMLElement>(LAYER_SELECTOR)\n ).filter((layer) => !layer.closest(\"[inert]\"));\n\n return windows.length ? windows[windows.length - 1] : null;\n};\n\n/**\n * True when the layer of the element is in front. A handler of a global shortcut asks this first, so the shortcut\n * goes to the layer the user works in and never to a page or a window under it.\n */\nexport const isInTopLayer = (element: Element | null | undefined) =>\n element && !element.closest(\"[inert]\")\n ? getLayerOf(element) === getTopLayer()\n : false;\n"],"mappings":"AAAA,OAAO,MAAMA,MAAM,GAAG;EACpBC,KAAK,EAAE,MAAM;EACbC,UAAU,EAAE,IAAI;EAChBC,KAAK,EAAE,IAAI;EACXC,KAAK,EAAE;AACT,CAAC;;AAED;AACA,MAAMC,cAAc,GAAG,yBAAyB;;AAEhD;AACA,OAAO,MAAMC,UAAU,GAAIC,OAAmC;EAAA,IAAAC,gBAAA;EAAA,QAAAA,gBAAA,GAC5DD,OAAO,YAAPA,OAAO,CAAEE,OAAO,oBAAhBF,OAAO,CAAEE,OAAO,CAAGJ,cAAc,CAAC,YAAAG,gBAAA,GAAI,IAAI;AAAA;;AAE5C;AACA;AACA;AACA;AACA,OAAO,MAAME,WAAW,GAAGA,CAAA,KAA0B;EACnD,MAAMC,OAAO,GAAGC,KAAK,CAACC,IAAI,CACxBC,QAAQ,CAACC,gBAAgB,CAAcV,cAAc,CACvD,CAAC,CAACW,MAAM,CAAEC,KAAK,IAAK,CAACA,KAAK,CAACR,OAAO,CAAC,SAAS,CAAC,CAAC;EAE9C,OAAOE,OAAO,CAACO,MAAM,GAAGP,OAAO,CAACA,OAAO,CAACO,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI;AAC5D,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,GAAIZ,OAAmC,IAC9DA,OAAO,IAAI,CAACA,OAAO,CAACE,OAAO,CAAC,SAAS,CAAC,GAClCH,UAAU,CAACC,OAAO,CAAC,KAAKG,WAAW,CAAC,CAAC,GACrC,KAAK","ignoreList":[]}
@@ -55,6 +55,21 @@ describe("layers", () => {
55
55
  expect(getTopLayer()).toBeNull();
56
56
  expect(isInTopLayer(onPage)).toBe(true);
57
57
  });
58
+ it("does not count an inert window, as a menu in a dialog that plays its exit transition, nor anything in it", () => {
59
+ const onPage = document.body.appendChild(document.createElement("input"));
60
+ const under = addWindow();
61
+ const popups = document.body.appendChild(document.createElement("div"));
62
+ popups.setAttribute("inert", "");
63
+ const menu = popups.appendChild(document.createElement("div"));
64
+ menu.className = "c-window";
65
+ const inMenu = menu.appendChild(document.createElement("input"));
66
+ expect(getTopLayer()).toBe(under);
67
+ expect(isInTopLayer(inMenu)).toBe(false);
68
+ under.remove();
69
+ expect(getTopLayer()).toBeNull();
70
+ expect(isInTopLayer(onPage)).toBe(true);
71
+ expect(isInTopLayer(popups)).toBe(false);
72
+ });
58
73
  it("is false for no element", () => {
59
74
  expect(isInTopLayer(null)).toBe(false);
60
75
  });
@@ -1 +1 @@
1
- {"version":3,"file":"layers.test.js","names":["getTopLayer","isInTopLayer","addWindow","node","document","createElement","className","body","appendChild","describe","afterEach","innerHTML","it","onPage","expect","toBeNull","toBe","under","inUnder","front","inFront","dialog","setAttribute","inDialog","menu","inMenu"],"sources":["../../../src/utils/layers.test.ts"],"sourcesContent":["import { getTopLayer, isInTopLayer } from \"./layers\";\n\nconst addWindow = () => {\n const node = document.createElement(\"div\");\n node.className = \"c-window\";\n document.body.appendChild(node);\n\n return node;\n};\n\ndescribe(\"layers\", () => {\n afterEach(() => {\n document.body.innerHTML = \"\";\n });\n\n it(\"has the page in front when no window is open\", () => {\n const onPage = document.body.appendChild(document.createElement(\"input\"));\n\n expect(getTopLayer()).toBeNull();\n expect(isInTopLayer(onPage)).toBe(true);\n });\n\n it(\"has the last open window in front, and not the page or a window under it\", () => {\n const onPage = document.body.appendChild(document.createElement(\"input\"));\n const under = addWindow();\n const inUnder = under.appendChild(document.createElement(\"input\"));\n const front = addWindow();\n const inFront = front.appendChild(document.createElement(\"input\"));\n\n expect(getTopLayer()).toBe(front);\n expect(isInTopLayer(inFront)).toBe(true);\n expect(isInTopLayer(inUnder)).toBe(false);\n expect(isInTopLayer(onPage)).toBe(false);\n });\n\n it(\"has an open native dialog in front of the page and of the windows under it\", () => {\n const onPage = document.body.appendChild(document.createElement(\"input\"));\n const under = addWindow();\n const inUnder = under.appendChild(document.createElement(\"input\"));\n const dialog = document.body.appendChild(document.createElement(\"dialog\"));\n dialog.setAttribute(\"open\", \"\");\n const inDialog = dialog.appendChild(document.createElement(\"input\"));\n\n expect(getTopLayer()).toBe(dialog);\n expect(isInTopLayer(inDialog)).toBe(true);\n expect(isInTopLayer(inUnder)).toBe(false);\n expect(isInTopLayer(onPage)).toBe(false);\n });\n\n it(\"has a window opened inside a native dialog in front of the dialog\", () => {\n const dialog = document.body.appendChild(document.createElement(\"dialog\"));\n dialog.setAttribute(\"open\", \"\");\n const inDialog = dialog.appendChild(document.createElement(\"input\"));\n const menu = document.createElement(\"div\");\n menu.className = \"c-window\";\n dialog.appendChild(menu);\n const inMenu = menu.appendChild(document.createElement(\"input\"));\n\n expect(getTopLayer()).toBe(menu);\n expect(isInTopLayer(inMenu)).toBe(true);\n expect(isInTopLayer(inDialog)).toBe(false);\n });\n\n it(\"does not count a closed dialog as a layer\", () => {\n const onPage = document.body.appendChild(document.createElement(\"input\"));\n document.body.appendChild(document.createElement(\"dialog\"));\n\n expect(getTopLayer()).toBeNull();\n expect(isInTopLayer(onPage)).toBe(true);\n });\n\n it(\"is false for no element\", () => {\n expect(isInTopLayer(null)).toBe(false);\n });\n});\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,YAAY,QAAQ,UAAU;AAEpD,MAAMC,SAAS,GAAGA,CAAA,KAAM;EACtB,MAAMC,IAAI,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAC1CF,IAAI,CAACG,SAAS,GAAG,UAAU;EAC3BF,QAAQ,CAACG,IAAI,CAACC,WAAW,CAACL,IAAI,CAAC;EAE/B,OAAOA,IAAI;AACb,CAA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,CAAC,KAAK,CAAC;IAC1CmB,IAAI,CAAClB,SAAS,GAAG,UAAU;IAC3Be,MAAM,CAACb,WAAW,CAACgB,IAAI,CAAC;IACxB,MAAMC,MAAM,GAAGD,IAAI,CAAChB,WAAW,CAACJ,QAAQ,CAACC,aAAa,CAAC,OAAO,CAAC,CAAC;IAEhES,MAAM,CAACd,WAAW,CAAC,CAAC,CAAC,CAACgB,IAAI,CAACQ,IAAI,CAAC;IAChCV,MAAM,CAACb,YAAY,CAACwB,MAAM,CAAC,CAAC,CAACT,IAAI,CAAC,IAAI,CAAC;IACvCF,MAAM,CAACb,YAAY,CAACsB,QAAQ,CAAC,CAAC,CAACP,IAAI,CAAC,KAAK,CAAC;EAC5C,CAAC,CAAC;EAEFJ,EAAE,CAAC,2CAA2C,EAAE,MAAM;IACpD,MAAMC,MAAM,GAAGT,QAAQ,CAACG,IAAI,CAACC,WAAW,CAACJ,QAAQ,CAACC,aAAa,CAAC,OAAO,CAAC,CAAC;IACzED,QAAQ,CAACG,IAAI,CAACC,WAAW,CAACJ,QAAQ,CAACC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAE3DS,MAAM,CAACd,WAAW,CAAC,CAAC,CAAC,CAACe,QAAQ,CAAC,CAAC;IAChCD,MAAM,CAACb,YAAY,CAACY,MAAM,CAAC,CAAC,CAACG,IAAI,CAAC,IAAI,CAAC;EACzC,CAAC,CAAC;EAEFJ,EAAE,CAAC,yBAAyB,EAAE,MAAM;IAClCE,MAAM,CAACb,YAAY,CAAC,IAAI,CAAC,CAAC,CAACe,IAAI,CAAC,KAAK,CAAC;EACxC,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"layers.test.js","names":["getTopLayer","isInTopLayer","addWindow","node","document","createElement","className","body","appendChild","describe","afterEach","innerHTML","it","onPage","expect","toBeNull","toBe","under","inUnder","front","inFront","dialog","setAttribute","inDialog","menu","inMenu","popups","remove"],"sources":["../../../src/utils/layers.test.ts"],"sourcesContent":["import { getTopLayer, isInTopLayer } from \"./layers\";\n\nconst addWindow = () => {\n const node = document.createElement(\"div\");\n node.className = \"c-window\";\n document.body.appendChild(node);\n\n return node;\n};\n\ndescribe(\"layers\", () => {\n afterEach(() => {\n document.body.innerHTML = \"\";\n });\n\n it(\"has the page in front when no window is open\", () => {\n const onPage = document.body.appendChild(document.createElement(\"input\"));\n\n expect(getTopLayer()).toBeNull();\n expect(isInTopLayer(onPage)).toBe(true);\n });\n\n it(\"has the last open window in front, and not the page or a window under it\", () => {\n const onPage = document.body.appendChild(document.createElement(\"input\"));\n const under = addWindow();\n const inUnder = under.appendChild(document.createElement(\"input\"));\n const front = addWindow();\n const inFront = front.appendChild(document.createElement(\"input\"));\n\n expect(getTopLayer()).toBe(front);\n expect(isInTopLayer(inFront)).toBe(true);\n expect(isInTopLayer(inUnder)).toBe(false);\n expect(isInTopLayer(onPage)).toBe(false);\n });\n\n it(\"has an open native dialog in front of the page and of the windows under it\", () => {\n const onPage = document.body.appendChild(document.createElement(\"input\"));\n const under = addWindow();\n const inUnder = under.appendChild(document.createElement(\"input\"));\n const dialog = document.body.appendChild(document.createElement(\"dialog\"));\n dialog.setAttribute(\"open\", \"\");\n const inDialog = dialog.appendChild(document.createElement(\"input\"));\n\n expect(getTopLayer()).toBe(dialog);\n expect(isInTopLayer(inDialog)).toBe(true);\n expect(isInTopLayer(inUnder)).toBe(false);\n expect(isInTopLayer(onPage)).toBe(false);\n });\n\n it(\"has a window opened inside a native dialog in front of the dialog\", () => {\n const dialog = document.body.appendChild(document.createElement(\"dialog\"));\n dialog.setAttribute(\"open\", \"\");\n const inDialog = dialog.appendChild(document.createElement(\"input\"));\n const menu = document.createElement(\"div\");\n menu.className = \"c-window\";\n dialog.appendChild(menu);\n const inMenu = menu.appendChild(document.createElement(\"input\"));\n\n expect(getTopLayer()).toBe(menu);\n expect(isInTopLayer(inMenu)).toBe(true);\n expect(isInTopLayer(inDialog)).toBe(false);\n });\n\n it(\"does not count a closed dialog as a layer\", () => {\n const onPage = document.body.appendChild(document.createElement(\"input\"));\n document.body.appendChild(document.createElement(\"dialog\"));\n\n expect(getTopLayer()).toBeNull();\n expect(isInTopLayer(onPage)).toBe(true);\n });\n\n it(\"does not count an inert window, as a menu in a dialog that plays its exit transition, nor anything in it\", () => {\n const onPage = document.body.appendChild(document.createElement(\"input\"));\n const under = addWindow();\n const popups = document.body.appendChild(document.createElement(\"div\"));\n popups.setAttribute(\"inert\", \"\");\n const menu = popups.appendChild(document.createElement(\"div\"));\n menu.className = \"c-window\";\n const inMenu = menu.appendChild(document.createElement(\"input\"));\n\n expect(getTopLayer()).toBe(under);\n expect(isInTopLayer(inMenu)).toBe(false);\n\n under.remove();\n\n expect(getTopLayer()).toBeNull();\n expect(isInTopLayer(onPage)).toBe(true);\n expect(isInTopLayer(popups)).toBe(false);\n });\n\n it(\"is false for no element\", () => {\n expect(isInTopLayer(null)).toBe(false);\n });\n});\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,YAAY,QAAQ,UAAU;AAEpD,MAAMC,SAAS,GAAGA,CAAA,KAAM;EACtB,MAAMC,IAAI,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAC1CF,IAAI,CAACG,SAAS,GAAG,UAAU;EAC3BF,QAAQ,CAACG,IAAI,CAACC,WAAW,CAACL,IAAI,CAAC;EAE/B,OAAOA,IAAI;AACb,CAAC;AAEDM,QAAQ,CAAC,QAAQ,EAAE,MAAM;EACvBC,SAAS,CAAC,MAAM;IACdN,QAAQ,CAACG,IAAI,CAACI,SAAS,GAAG,EAAE;EAC9B,CAAC,CAAC;EAEFC,EAAE,CAAC,8CAA8C,EAAE,MAAM;IACvD,MAAMC,MAAM,GAAGT,QAAQ,CAACG,IAAI,CAACC,WAAW,CAACJ,QAAQ,CAACC,aAAa,CAAC,OAAO,CAAC,CAAC;IAEzES,MAAM,CAACd,WAAW,CAAC,CAAC,CAAC,CAACe,QAAQ,CAAC,CAAC;IAChCD,MAAM,CAACb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