@cloudscape-design/components 3.0.1061 → 3.0.1063

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 (134) hide show
  1. package/app-layout/utils/use-focus-control.d.ts +2 -1
  2. package/app-layout/utils/use-focus-control.d.ts.map +1 -1
  3. package/app-layout/utils/use-focus-control.js +66 -6
  4. package/app-layout/utils/use-focus-control.js.map +1 -1
  5. package/app-layout/utils/use-split-panel-focus-control.d.ts.map +1 -1
  6. package/app-layout/utils/use-split-panel-focus-control.js +15 -13
  7. package/app-layout/utils/use-split-panel-focus-control.js.map +1 -1
  8. package/app-layout/visual-refresh-toolbar/index.d.ts.map +1 -1
  9. package/app-layout/visual-refresh-toolbar/index.js +37 -350
  10. package/app-layout/visual-refresh-toolbar/index.js.map +1 -1
  11. package/app-layout/visual-refresh-toolbar/interfaces.d.ts +21 -1
  12. package/app-layout/visual-refresh-toolbar/interfaces.d.ts.map +1 -1
  13. package/app-layout/visual-refresh-toolbar/interfaces.js.map +1 -1
  14. package/app-layout/visual-refresh-toolbar/internal.d.ts +24 -1
  15. package/app-layout/visual-refresh-toolbar/internal.d.ts.map +1 -1
  16. package/app-layout/visual-refresh-toolbar/internal.js +13 -0
  17. package/app-layout/visual-refresh-toolbar/internal.js.map +1 -1
  18. package/app-layout/visual-refresh-toolbar/navigation/index.js +1 -1
  19. package/app-layout/visual-refresh-toolbar/navigation/index.js.map +1 -1
  20. package/app-layout/visual-refresh-toolbar/notifications/index.js +2 -2
  21. package/app-layout/visual-refresh-toolbar/notifications/index.js.map +1 -1
  22. package/app-layout/visual-refresh-toolbar/skeleton/index.d.ts +17 -16
  23. package/app-layout/visual-refresh-toolbar/skeleton/index.d.ts.map +1 -1
  24. package/app-layout/visual-refresh-toolbar/skeleton/index.js +21 -30
  25. package/app-layout/visual-refresh-toolbar/skeleton/index.js.map +1 -1
  26. package/app-layout/visual-refresh-toolbar/skeleton/interfaces.d.ts +20 -0
  27. package/app-layout/visual-refresh-toolbar/skeleton/interfaces.d.ts.map +1 -0
  28. package/app-layout/visual-refresh-toolbar/skeleton/interfaces.js +2 -0
  29. package/app-layout/visual-refresh-toolbar/skeleton/interfaces.js.map +1 -0
  30. package/app-layout/visual-refresh-toolbar/skeleton/multi-layout.d.ts +7 -0
  31. package/app-layout/visual-refresh-toolbar/skeleton/multi-layout.d.ts.map +1 -0
  32. package/app-layout/visual-refresh-toolbar/skeleton/multi-layout.js +41 -0
  33. package/app-layout/visual-refresh-toolbar/skeleton/multi-layout.js.map +1 -0
  34. package/app-layout/visual-refresh-toolbar/skeleton/{slot-skeletons.d.ts → skeleton-parts.d.ts} +8 -0
  35. package/app-layout/visual-refresh-toolbar/skeleton/skeleton-parts.d.ts.map +1 -0
  36. package/app-layout/visual-refresh-toolbar/skeleton/skeleton-parts.js +21 -0
  37. package/app-layout/visual-refresh-toolbar/skeleton/skeleton-parts.js.map +1 -0
  38. package/app-layout/visual-refresh-toolbar/skeleton/{slot-wrappers.d.ts → slots.d.ts} +9 -0
  39. package/app-layout/visual-refresh-toolbar/skeleton/slots.d.ts.map +1 -0
  40. package/app-layout/visual-refresh-toolbar/skeleton/{breadcrumbs/index.js → slots.js} +6 -3
  41. package/app-layout/visual-refresh-toolbar/skeleton/slots.js.map +1 -0
  42. package/app-layout/visual-refresh-toolbar/skeleton/styles.css.js +23 -21
  43. package/app-layout/visual-refresh-toolbar/skeleton/styles.scoped.css +42 -37
  44. package/app-layout/visual-refresh-toolbar/skeleton/styles.selectors.js +23 -21
  45. package/app-layout/visual-refresh-toolbar/state/index.d.ts +29 -0
  46. package/app-layout/visual-refresh-toolbar/state/index.d.ts.map +1 -0
  47. package/app-layout/visual-refresh-toolbar/state/index.js +27 -0
  48. package/app-layout/visual-refresh-toolbar/state/index.js.map +1 -0
  49. package/app-layout/visual-refresh-toolbar/{multi-layout.d.ts → state/interfaces.d.ts} +11 -16
  50. package/app-layout/visual-refresh-toolbar/state/interfaces.d.ts.map +1 -0
  51. package/app-layout/visual-refresh-toolbar/state/interfaces.js +2 -0
  52. package/app-layout/visual-refresh-toolbar/state/interfaces.js.map +1 -0
  53. package/app-layout/visual-refresh-toolbar/state/invariants.d.ts +2 -0
  54. package/app-layout/visual-refresh-toolbar/state/invariants.d.ts.map +1 -0
  55. package/app-layout/visual-refresh-toolbar/state/invariants.js +4 -0
  56. package/app-layout/visual-refresh-toolbar/state/invariants.js.map +1 -0
  57. package/app-layout/visual-refresh-toolbar/state/props-merger.d.ts +4 -0
  58. package/app-layout/visual-refresh-toolbar/state/props-merger.d.ts.map +1 -0
  59. package/app-layout/visual-refresh-toolbar/{multi-layout.js → state/props-merger.js} +28 -40
  60. package/app-layout/visual-refresh-toolbar/state/props-merger.js.map +1 -0
  61. package/app-layout/visual-refresh-toolbar/state/use-app-layout.d.ts +31 -0
  62. package/app-layout/visual-refresh-toolbar/state/use-app-layout.d.ts.map +1 -0
  63. package/app-layout/visual-refresh-toolbar/state/use-app-layout.js +322 -0
  64. package/app-layout/visual-refresh-toolbar/state/use-app-layout.js.map +1 -0
  65. package/app-layout/visual-refresh-toolbar/state/use-skeleton-slots-attributes.d.ts +3 -0
  66. package/app-layout/visual-refresh-toolbar/state/use-skeleton-slots-attributes.d.ts.map +1 -0
  67. package/app-layout/visual-refresh-toolbar/state/use-skeleton-slots-attributes.js +59 -0
  68. package/app-layout/visual-refresh-toolbar/state/use-skeleton-slots-attributes.js.map +1 -0
  69. package/app-layout/visual-refresh-toolbar/toolbar/drawer-triggers.d.ts +2 -2
  70. package/app-layout/visual-refresh-toolbar/toolbar/drawer-triggers.d.ts.map +1 -1
  71. package/app-layout/visual-refresh-toolbar/toolbar/drawer-triggers.js.map +1 -1
  72. package/app-layout/visual-refresh-toolbar/toolbar/index.d.ts.map +1 -1
  73. package/app-layout/visual-refresh-toolbar/toolbar/index.js +2 -3
  74. package/app-layout/visual-refresh-toolbar/toolbar/index.js.map +1 -1
  75. package/app-layout/visual-refresh-toolbar/widget-areas/after-main-slot.d.ts +13 -0
  76. package/app-layout/visual-refresh-toolbar/widget-areas/after-main-slot.d.ts.map +1 -0
  77. package/app-layout/visual-refresh-toolbar/widget-areas/after-main-slot.js +29 -0
  78. package/app-layout/visual-refresh-toolbar/widget-areas/after-main-slot.js.map +1 -0
  79. package/app-layout/visual-refresh-toolbar/widget-areas/before-main-slot.d.ts +16 -0
  80. package/app-layout/visual-refresh-toolbar/widget-areas/before-main-slot.d.ts.map +1 -0
  81. package/app-layout/visual-refresh-toolbar/widget-areas/before-main-slot.js +28 -0
  82. package/app-layout/visual-refresh-toolbar/widget-areas/before-main-slot.js.map +1 -0
  83. package/app-layout/visual-refresh-toolbar/widget-areas/bottom-content-slot.d.ts +13 -0
  84. package/app-layout/visual-refresh-toolbar/widget-areas/bottom-content-slot.d.ts.map +1 -0
  85. package/app-layout/visual-refresh-toolbar/widget-areas/bottom-content-slot.js +17 -0
  86. package/app-layout/visual-refresh-toolbar/widget-areas/bottom-content-slot.js.map +1 -0
  87. package/app-layout/visual-refresh-toolbar/widget-areas/top-content-slot.d.ts +13 -0
  88. package/app-layout/visual-refresh-toolbar/widget-areas/top-content-slot.d.ts.map +1 -0
  89. package/app-layout/visual-refresh-toolbar/widget-areas/top-content-slot.js +19 -0
  90. package/app-layout/visual-refresh-toolbar/widget-areas/top-content-slot.js.map +1 -0
  91. package/breadcrumb-group/internal.d.ts +2 -1
  92. package/breadcrumb-group/internal.d.ts.map +1 -1
  93. package/breadcrumb-group/internal.js +3 -2
  94. package/breadcrumb-group/internal.js.map +1 -1
  95. package/button/internal.d.ts.map +1 -1
  96. package/button/internal.js +3 -26
  97. package/button/internal.js.map +1 -1
  98. package/button/style.d.ts +7 -0
  99. package/button/style.d.ts.map +1 -0
  100. package/button/style.js +33 -0
  101. package/button/style.js.map +1 -0
  102. package/internal/base-component/styles.scoped.css +1 -1
  103. package/internal/environment.js +2 -2
  104. package/internal/environment.json +2 -2
  105. package/internal/manifest.json +1 -1
  106. package/internal/types.d.ts +9 -0
  107. package/internal/types.d.ts.map +1 -1
  108. package/internal/types.js.map +1 -1
  109. package/internal/widget-exports.d.ts +5 -0
  110. package/internal/widget-exports.d.ts.map +1 -1
  111. package/internal/widget-exports.js +7 -0
  112. package/internal/widget-exports.js.map +1 -1
  113. package/internal/widgets/index.d.ts +3 -4
  114. package/internal/widgets/index.d.ts.map +1 -1
  115. package/internal/widgets/index.js.map +1 -1
  116. package/internal/widgets/loader-mock.d.ts +2 -0
  117. package/internal/widgets/loader-mock.d.ts.map +1 -0
  118. package/internal/widgets/loader-mock.js +43 -0
  119. package/internal/widgets/loader-mock.js.map +1 -0
  120. package/package.json +1 -1
  121. package/app-layout/visual-refresh-toolbar/multi-layout.d.ts.map +0 -1
  122. package/app-layout/visual-refresh-toolbar/multi-layout.js.map +0 -1
  123. package/app-layout/visual-refresh-toolbar/skeleton/breadcrumbs/index.d.ts +0 -11
  124. package/app-layout/visual-refresh-toolbar/skeleton/breadcrumbs/index.d.ts.map +0 -1
  125. package/app-layout/visual-refresh-toolbar/skeleton/breadcrumbs/index.js.map +0 -1
  126. package/app-layout/visual-refresh-toolbar/skeleton/breadcrumbs/styles.css.js +0 -7
  127. package/app-layout/visual-refresh-toolbar/skeleton/breadcrumbs/styles.scoped.css +0 -7
  128. package/app-layout/visual-refresh-toolbar/skeleton/breadcrumbs/styles.selectors.js +0 -8
  129. package/app-layout/visual-refresh-toolbar/skeleton/slot-skeletons.d.ts.map +0 -1
  130. package/app-layout/visual-refresh-toolbar/skeleton/slot-skeletons.js +0 -9
  131. package/app-layout/visual-refresh-toolbar/skeleton/slot-skeletons.js.map +0 -1
  132. package/app-layout/visual-refresh-toolbar/skeleton/slot-wrappers.d.ts.map +0 -1
  133. package/app-layout/visual-refresh-toolbar/skeleton/slot-wrappers.js +0 -8
  134. package/app-layout/visual-refresh-toolbar/skeleton/slot-wrappers.js.map +0 -1
@@ -22,4 +22,5 @@ export interface FocusControlMultipleStates {
22
22
  loseFocus: () => void;
23
23
  }
24
24
  export declare function useMultipleFocusControl(restoreFocus: boolean, activeDrawersIds: Array<string>): FocusControlMultipleStates;
25
- export declare function useFocusControl(isOpen: boolean, restoreFocus?: boolean, activeDrawerId?: string | null): FocusControlState;
25
+ export declare function useFocusControl(isOpen: boolean, restoreFocus?: boolean, activeDrawerId?: string | null): FocusControlState;
26
+ export declare function useAsyncFocusControl(isOpen: boolean, restoreFocus?: boolean, activeDrawerId?: string | null): FocusControlState;
@@ -1 +1 @@
1
- {"version":3,"file":"use-focus-control.d.ts","sourceRoot":"","sources":["../../../../src/app-layout/utils/use-focus-control.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,SAAS,EAAkC,MAAM,OAAO,CAAC;AAE7E,MAAM,WAAW,SAAS;IACxB,KAAK,IAAI,IAAI,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC5B,MAAM,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,gBAAgB,CAAC;IACvB,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACpC,SAAS,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACvC,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IACpF,SAAS,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,OAAO,EACrB,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC,G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,iBAAiB,CAmDnB;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,EACf,YAAY,UAAQ,EACpB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,GAC7B,iBAAiB,CAuDnB"}
@@ -14,9 +14,6 @@ export function useMultipleFocusControl(restoreFocus, activeDrawersIds) {
14
14
  });
15
15
  const doFocus = useCallback((drawerId, open = true) => {
16
16
  var _a, _b, _c, _d, _e, _f;
17
- if (!shouldFocus.current) {
18
- return;
19
- }
20
17
  const ref = refs.current[drawerId];
21
18
  if (open) {
22
19
  previousFocusedElement.current =
@@ -37,14 +34,15 @@ export function useMultipleFocusControl(restoreFocus, activeDrawersIds) {
37
34
  (_f = (_e = ref === null || ref === void 0 ? void 0 : ref.toggle) === null || _e === void 0 ? void 0 : _e.current) === null || _f === void 0 ? void 0 : _f.focus();
38
35
  }
39
36
  }
40
- shouldFocus.current = false;
41
37
  }, [refs, restoreFocus]);
42
38
  const setFocus = (params) => {
43
39
  const { force = false, drawerId = null, open = true } = params || {};
44
- shouldFocus.current = true;
45
40
  if (force && (!drawerId || activeDrawersIds.includes(drawerId))) {
46
41
  doFocus(drawerId, open);
47
42
  }
43
+ else {
44
+ shouldFocus.current = true;
45
+ }
48
46
  };
49
47
  const loseFocus = useCallback(() => {
50
48
  previousFocusedElement.current = undefined;
@@ -52,7 +50,13 @@ export function useMultipleFocusControl(restoreFocus, activeDrawersIds) {
52
50
  const previousFocusedElement = useRef();
53
51
  const shouldFocus = useRef(false);
54
52
  useEffect(() => {
55
- doFocus(activeDrawersIds[0]);
53
+ const drawerId = activeDrawersIds[0];
54
+ if (shouldFocus.current) {
55
+ Promise.resolve().then(() => {
56
+ doFocus(drawerId);
57
+ shouldFocus.current = false;
58
+ });
59
+ }
56
60
  }, [activeDrawersIds, doFocus]);
57
61
  return {
58
62
  refs: refs.current,
@@ -111,4 +115,60 @@ export function useFocusControl(isOpen, restoreFocus = false, activeDrawerId) {
111
115
  loseFocus,
112
116
  };
113
117
  }
118
+ export function useAsyncFocusControl(isOpen, restoreFocus = false, activeDrawerId) {
119
+ const refs = {
120
+ toggle: useRef(null),
121
+ close: useRef(null),
122
+ slider: useRef(null),
123
+ };
124
+ const previousFocusedElement = useRef();
125
+ const shouldFocus = useRef(false);
126
+ const doFocus = () => {
127
+ var _a, _b, _c;
128
+ if (isOpen) {
129
+ previousFocusedElement.current =
130
+ document.activeElement !== document.body ? document.activeElement : undefined;
131
+ if (refs.slider.current) {
132
+ (_a = refs.slider.current) === null || _a === void 0 ? void 0 : _a.focus();
133
+ }
134
+ else {
135
+ (_b = refs.close.current) === null || _b === void 0 ? void 0 : _b.focus();
136
+ }
137
+ }
138
+ else {
139
+ if (restoreFocus && previousFocusedElement.current && document.contains(previousFocusedElement.current)) {
140
+ previousFocusedElement.current.focus();
141
+ previousFocusedElement.current = undefined;
142
+ }
143
+ else {
144
+ (_c = refs.toggle.current) === null || _c === void 0 ? void 0 : _c.focus();
145
+ }
146
+ }
147
+ };
148
+ const setFocus = (force) => {
149
+ if (force && isOpen) {
150
+ doFocus();
151
+ }
152
+ else {
153
+ shouldFocus.current = true;
154
+ }
155
+ };
156
+ useEffect(() => {
157
+ if (shouldFocus.current) {
158
+ Promise.resolve().then(() => {
159
+ doFocus();
160
+ shouldFocus.current = false;
161
+ });
162
+ }
163
+ // eslint-disable-next-line react-hooks/exhaustive-deps
164
+ }, [isOpen, activeDrawerId]);
165
+ const loseFocus = useCallback(() => {
166
+ previousFocusedElement.current = undefined;
167
+ }, []);
168
+ return {
169
+ refs,
170
+ setFocus,
171
+ loseFocus,
172
+ };
173
+ }
114
174
  //# sourceMappingURL=use-focus-control.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-focus-control.js","sourceRoot":"","sources":["../../../../src/app-layout/utils/use-focus-control.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,SAAS,EAAa,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,O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nB,OAAO,EAAE,CAAC;SACX;IACH,CAAC,CAAC;IAEF,uDAAuD;IACvD,SAAS,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IAE7C,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE;QACjC,sBAAsB,CAAC,OAAO,GAAG,SAAS,CAAC;IAC7C,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,IAAI;QACJ,QAAQ;QACR,SAAS;KACV,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { createRef, RefObject, useCallback, useEffect, useRef } from 'react';\n\nexport interface Focusable {\n focus(): void;\n}\n\nexport interface FocusControlRefs {\n toggle: RefObject<Focusable>;\n close: RefObject<Focusable>;\n slider: RefObject<HTMLDivElement>;\n}\n\nexport interface FocusControlState {\n refs: FocusControlRefs;\n setFocus: (force?: boolean) => void;\n loseFocus: () => void;\n}\n\nexport interface FocusControlMultipleStates {\n refs: Record<string, FocusControlRefs>;\n setFocus: (params?: { force?: boolean; drawerId?: string; open?: boolean }) => void;\n loseFocus: () => void;\n}\n\nexport function useMultipleFocusControl(\n restoreFocus: boolean,\n activeDrawersIds: Array<string>\n): FocusControlMultipleStates {\n const refs = useRef<Record<string, FocusControlRefs>>({});\n\n activeDrawersIds.forEach(drawerId => {\n if (!refs.current[drawerId]) {\n refs.current[drawerId] = {\n toggle: createRef<Focusable>(),\n close: createRef<Focusable>(),\n slider: createRef<HTMLDivElement>(),\n };\n }\n });\n\n const doFocus = useCallback(\n (drawerId: string, open = true) => {\n if (!shouldFocus.current) {\n return;\n }\n const ref = refs.current[drawerId];\n if (open) {\n previousFocusedElement.current =\n document.activeElement !== document.body ? (document.activeElement as HTMLElement) : undefined;\n if (ref?.slider?.current) {\n ref.slider.current?.focus();\n } else {\n ref?.close?.current?.focus();\n }\n } else {\n if (restoreFocus && previousFocusedElement.current && document.contains(previousFocusedElement.current)) {\n previousFocusedElement.current.focus();\n previousFocusedElement.current = undefined;\n } else {\n ref?.toggle?.current?.focus();\n }\n }\n shouldFocus.current = false;\n },\n [refs, restoreFocus]\n );\n\n const setFocus = (params?: { force?: boolean; drawerId?: string; open?: boolean }) => {\n const { force = false, drawerId = null, open = true } = params || {};\n shouldFocus.current = true;\n if (force && (!drawerId || activeDrawersIds.includes(drawerId))) {\n doFocus(drawerId!, open);\n }\n };\n\n const loseFocus = useCallback(() => {\n previousFocusedElement.current = undefined;\n }, []);\n\n const previousFocusedElement = useRef<HTMLElement>();\n const shouldFocus = useRef(false);\n\n useEffect(() => {\n doFocus(activeDrawersIds[0]);\n }, [activeDrawersIds, doFocus]);\n\n return {\n refs: refs.current,\n setFocus,\n loseFocus,\n };\n}\n\nexport function useFocusControl(\n isOpen: boolean,\n restoreFocus = false,\n activeDrawerId?: string | null\n): FocusControlState {\n const refs = {\n toggle: useRef<Focusable>(null),\n close: useRef<Focusable>(null),\n slider: useRef<HTMLDivElement>(null),\n };\n const previousFocusedElement = useRef<HTMLElement>();\n const shouldFocus = useRef(false);\n\n const doFocus = () => {\n if (!shouldFocus.current) {\n return;\n }\n if (isOpen) {\n previousFocusedElement.current =\n document.activeElement !== document.body ? (document.activeElement as HTMLElement) : undefined;\n if (refs.slider.current) {\n refs.slider.current?.focus();\n } else {\n refs.close.current?.focus();\n }\n } else {\n if (restoreFocus && previousFocusedElement.current && document.contains(previousFocusedElement.current)) {\n previousFocusedElement.current.focus();\n previousFocusedElement.current = undefined;\n } else {\n refs.toggle.current?.focus();\n }\n }\n shouldFocus.current = false;\n };\n\n const setFocus = (force?: boolean) => {\n shouldFocus.current = true;\n if (force && isOpen) {\n doFocus();\n }\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(doFocus, [isOpen, activeDrawerId]);\n\n const loseFocus = useCallback(() => {\n previousFocusedElement.current = undefined;\n }, []);\n\n return {\n refs,\n setFocus,\n loseFocus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.\n// SPDX-License-Identifier: Apache-2.0\nimport { createRef, RefObject, useCallback, useEffect, useRef } from 'react';\n\nexport interface Focusable {\n focus(): void;\n}\n\nexport interface FocusControlRefs {\n toggle: RefObject<Focusable>;\n close: RefObject<Focusable>;\n slider: RefObject<HTMLDivElement>;\n}\n\nexport interface FocusControlState {\n refs: FocusControlRefs;\n setFocus: (force?: boolean) => void;\n loseFocus: () => void;\n}\n\nexport interface FocusControlMultipleStates {\n refs: Record<string, FocusControlRefs>;\n setFocus: (params?: { force?: boolean; drawerId?: string; open?: boolean }) => void;\n loseFocus: () => void;\n}\n\nexport function useMultipleFocusControl(\n restoreFocus: boolean,\n activeDrawersIds: Array<string>\n): FocusControlMultipleStates {\n const refs = useRef<Record<string, FocusControlRefs>>({});\n\n activeDrawersIds.forEach(drawerId => {\n if (!refs.current[drawerId]) {\n refs.current[drawerId] = {\n toggle: createRef<Focusable>(),\n close: createRef<Focusable>(),\n slider: createRef<HTMLDivElement>(),\n };\n }\n });\n\n const doFocus = useCallback(\n (drawerId: string, open = true) => {\n const ref = refs.current[drawerId];\n if (open) {\n previousFocusedElement.current =\n document.activeElement !== document.body ? (document.activeElement as HTMLElement) : undefined;\n if (ref?.slider?.current) {\n ref.slider.current?.focus();\n } else {\n ref?.close?.current?.focus();\n }\n } else {\n if (restoreFocus && previousFocusedElement.current && document.contains(previousFocusedElement.current)) {\n previousFocusedElement.current.focus();\n previousFocusedElement.current = undefined;\n } else {\n ref?.toggle?.current?.focus();\n }\n }\n },\n [refs, restoreFocus]\n );\n\n const setFocus = (params?: { force?: boolean; drawerId?: string; open?: boolean }) => {\n const { force = false, drawerId = null, open = true } = params || {};\n if (force && (!drawerId || activeDrawersIds.includes(drawerId))) {\n doFocus(drawerId!, open);\n } else {\n shouldFocus.current = true;\n }\n };\n\n const loseFocus = useCallback(() => {\n previousFocusedElement.current = undefined;\n }, []);\n\n const previousFocusedElement = useRef<HTMLElement>();\n const shouldFocus = useRef(false);\n\n useEffect(() => {\n const drawerId = activeDrawersIds[0];\n if (shouldFocus.current) {\n Promise.resolve().then(() => {\n doFocus(drawerId);\n shouldFocus.current = false;\n });\n }\n }, [activeDrawersIds, doFocus]);\n\n return {\n refs: refs.current,\n setFocus,\n loseFocus,\n };\n}\n\nexport function useFocusControl(\n isOpen: boolean,\n restoreFocus = false,\n activeDrawerId?: string | null\n): FocusControlState {\n const refs = {\n toggle: useRef<Focusable>(null),\n close: useRef<Focusable>(null),\n slider: useRef<HTMLDivElement>(null),\n };\n const previousFocusedElement = useRef<HTMLElement>();\n const shouldFocus = useRef(false);\n\n const doFocus = () => {\n if (!shouldFocus.current) {\n return;\n }\n if (isOpen) {\n previousFocusedElement.current =\n document.activeElement !== document.body ? (document.activeElement as HTMLElement) : undefined;\n if (refs.slider.current) {\n refs.slider.current?.focus();\n } else {\n refs.close.current?.focus();\n }\n } else {\n if (restoreFocus && previousFocusedElement.current && document.contains(previousFocusedElement.current)) {\n previousFocusedElement.current.focus();\n previousFocusedElement.current = undefined;\n } else {\n refs.toggle.current?.focus();\n }\n }\n shouldFocus.current = false;\n };\n\n const setFocus = (force?: boolean) => {\n shouldFocus.current = true;\n if (force && isOpen) {\n doFocus();\n }\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(doFocus, [isOpen, activeDrawerId]);\n\n const loseFocus = useCallback(() => {\n previousFocusedElement.current = undefined;\n }, []);\n\n return {\n refs,\n setFocus,\n loseFocus,\n };\n}\n\nexport function useAsyncFocusControl(\n isOpen: boolean,\n restoreFocus = false,\n activeDrawerId?: string | null\n): FocusControlState {\n const refs = {\n toggle: useRef<Focusable>(null),\n close: useRef<Focusable>(null),\n slider: useRef<HTMLDivElement>(null),\n };\n const previousFocusedElement = useRef<HTMLElement>();\n const shouldFocus = useRef(false);\n\n const doFocus = () => {\n if (isOpen) {\n previousFocusedElement.current =\n document.activeElement !== document.body ? (document.activeElement as HTMLElement) : undefined;\n if (refs.slider.current) {\n refs.slider.current?.focus();\n } else {\n refs.close.current?.focus();\n }\n } else {\n if (restoreFocus && previousFocusedElement.current && document.contains(previousFocusedElement.current)) {\n previousFocusedElement.current.focus();\n previousFocusedElement.current = undefined;\n } else {\n refs.toggle.current?.focus();\n }\n }\n };\n\n const setFocus = (force?: boolean) => {\n if (force && isOpen) {\n doFocus();\n } else {\n shouldFocus.current = true;\n }\n };\n\n useEffect(() => {\n if (shouldFocus.current) {\n Promise.resolve().then(() => {\n doFocus();\n shouldFocus.current = false;\n });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isOpen, activeDrawerId]);\n\n const loseFocus = useCallback(() => {\n previousFocusedElement.current = undefined;\n }, []);\n\n return {\n refs,\n setFocus,\n loseFocus,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"use-split-panel-focus-control.d.ts","sourceRoot":"","sources":["../../../../src/app-layout/utils/use-split-panel-focus-control.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAqB,MAAM,OAAO,CAAC;AAErE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,KAAK,yBAAyB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;AAE7F,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,MAAM,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IAClC,WAAW,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CACnC;AACD,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,0BAA0B,CAAC;IACjC,kBAAkB,EAAE,CAAC,WAAW,EAAE,yBAAyB,KAAK,IAAI,CAAC;CACtE;AAED,wBAAgB,yBAAyB,CAAC,YAAY,EAAE,cAAc,GAAG,2BAA2B,CA4BnG"}
1
+ {"version":3,"file":"use-split-panel-focus-control.d.ts","sourceRoot":"","sources":["../../../../src/app-layout/utils/use-split-panel-focus-control.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAqB,MAAM,OAAO,CAAC;AAErE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,KAAK,yBAAyB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;AAE7F,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,MAAM,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IAClC,WAAW,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CACnC;AACD,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,0BAA0B,CAAC;IACjC,kBAAkB,EAAE,CAAC,WAAW,EAAE,yBAAyB,KAAK,IAAI,CAAC;CACtE;AAED,wBAAgB,yBAAyB,CAAC,YAAY,EAAE,cAAc,GAAG,2BAA2B,CA8BnG"}
@@ -9,19 +9,21 @@ export function useSplitPanelFocusControl(dependencies) {
9
9
  };
10
10
  const lastInteraction = useRef(null);
11
11
  useEffect(() => {
12
- var _a, _b, _c, _d;
13
- switch ((_a = lastInteraction.current) === null || _a === void 0 ? void 0 : _a.type) {
14
- case 'open':
15
- (_b = refs.slider.current) === null || _b === void 0 ? void 0 : _b.focus();
16
- break;
17
- case 'close':
18
- (_c = refs.toggle.current) === null || _c === void 0 ? void 0 : _c.focus();
19
- break;
20
- case 'position':
21
- (_d = refs.preferences.current) === null || _d === void 0 ? void 0 : _d.focus();
22
- break;
23
- }
24
- lastInteraction.current = null;
12
+ Promise.resolve().then(() => {
13
+ var _a, _b, _c, _d;
14
+ switch ((_a = lastInteraction.current) === null || _a === void 0 ? void 0 : _a.type) {
15
+ case 'open':
16
+ (_b = refs.slider.current) === null || _b === void 0 ? void 0 : _b.focus();
17
+ break;
18
+ case 'close':
19
+ (_c = refs.toggle.current) === null || _c === void 0 ? void 0 : _c.focus();
20
+ break;
21
+ case 'position':
22
+ (_d = refs.preferences.current) === null || _d === void 0 ? void 0 : _d.focus();
23
+ break;
24
+ }
25
+ lastInteraction.current = null;
26
+ });
25
27
  // eslint-disable-next-line react-hooks/exhaustive-deps
26
28
  }, dependencies);
27
29
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"use-split-panel-focus-control.js","sourceRoot":"","sources":["../../../../src/app-layout/utils/use-split-panel-focus-control.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAA6B,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAgBrE,MAAM,UAAU,yBAAyB,CAAC,YAA4B;IACpE,MAAM,IAAI,GAAG;QACX,MAAM,EAAE,MAAM,CAAY,IAAI,CAAC;QAC/B,MAAM,EAAE,MAAM,CAAiB,IAAI,CAAC;QACpC,WAAW,EAAE,MAAM,CAAY,IAAI,CAAC;KACrC,CAAC;IACF,MAAM,eAAe,GAAG,MAAM,CAAmC,IAAI,CAAC,CAAC;IAEvE,SAAS,CAAC,GAAG,EAAE;;QACb,QAAQ,MAAA,eAAe,CAAC,OAAO,0CAAE,IAAI,EAAE;YACrC,KAAK,MAAM;gBACT,MAAA,IAAI,CAAC,MAAM,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAC;gBAC7B,MAAM;YACR,KAAK,OAAO;gBACV,MAAA,IAAI,CAAC,MAAM,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAC;gBAC7B,MAAM;YACR,KAAK,UAAU;gBACb,MAAA,IAAI,CAAC,WAAW,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAC;gBAClC,MAAM;SACT;QACD,eAAe,CAAC,OAAO,GAAG,IAAI,CAAC;QAC/B,uDAAuD;IACzD,CAAC,EAAE,YAAY,CAAC,CAAC;IAEjB,OAAO;QACL,IAAI;QACJ,kBAAkB,EAAE,CAAC,WAAsC,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,OAAO,GAAG,WAAW,CAAC;KACxG,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { DependencyList, RefObject, useEffect, useRef } from 'react';\n\nimport { Focusable } from './use-focus-control';\n\ntype SplitPanelLastInteraction = { type: 'open' } | { type: 'close' } | { type: 'position' };\n\nexport interface SplitPanelFocusControlRefs {\n toggle: RefObject<Focusable>;\n slider: RefObject<HTMLDivElement>;\n preferences: RefObject<Focusable>;\n}\nexport interface SplitPanelFocusControlState {\n refs: SplitPanelFocusControlRefs;\n setLastInteraction: (interaction: SplitPanelLastInteraction) => void;\n}\n\nexport function useSplitPanelFocusControl(dependencies: DependencyList): SplitPanelFocusControlState {\n const refs = {\n toggle: useRef<Focusable>(null),\n slider: useRef<HTMLDivElement>(null),\n preferences: useRef<Focusable>(null),\n };\n const lastInteraction = useRef<SplitPanelLastInteraction | null>(null);\n\n useEffect(() => {\n switch (lastInteraction.current?.type) {\n case 'open':\n refs.slider.current?.focus();\n break;\n case 'close':\n refs.toggle.current?.focus();\n break;\n case 'position':\n refs.preferences.current?.focus();\n break;\n }\n lastInteraction.current = null;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, dependencies);\n\n return {\n refs,\n setLastInteraction: (interaction: SplitPanelLastInteraction) => (lastInteraction.current = interaction),\n };\n}\n"]}
1
+ {"version":3,"file":"use-split-panel-focus-control.js","sourceRoot":"","sources":["../../../../src/app-layout/utils/use-split-panel-focus-control.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAA6B,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAgBrE,MAAM,UAAU,yBAAyB,CAAC,YAA4B;IACpE,MAAM,IAAI,GAAG;QACX,MAAM,EAAE,MAAM,CAAY,IAAI,CAAC;QAC/B,MAAM,EAAE,MAAM,CAAiB,IAAI,CAAC;QACpC,WAAW,EAAE,MAAM,CAAY,IAAI,CAAC;KACrC,CAAC;IACF,MAAM,eAAe,GAAG,MAAM,CAAmC,IAAI,CAAC,CAAC;IAEvE,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;;YAC1B,QAAQ,MAAA,eAAe,CAAC,OAAO,0CAAE,IAAI,EAAE;gBACrC,KAAK,MAAM;oBACT,MAAA,IAAI,CAAC,MAAM,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAC;oBAC7B,MAAM;gBACR,KAAK,OAAO;oBACV,MAAA,IAAI,CAAC,MAAM,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAC;oBAC7B,MAAM;gBACR,KAAK,UAAU;oBACb,MAAA,IAAI,CAAC,WAAW,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAC;oBAClC,MAAM;aACT;YACD,eAAe,CAAC,OAAO,GAAG,IAAI,CAAC;QACjC,CAAC,CAAC,CAAC;QACH,uDAAuD;IACzD,CAAC,EAAE,YAAY,CAAC,CAAC;IAEjB,OAAO;QACL,IAAI;QACJ,kBAAkB,EAAE,CAAC,WAAsC,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,OAAO,GAAG,WAAW,CAAC;KACxG,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { DependencyList, RefObject, useEffect, useRef } from 'react';\n\nimport { Focusable } from './use-focus-control';\n\ntype SplitPanelLastInteraction = { type: 'open' } | { type: 'close' } | { type: 'position' };\n\nexport interface SplitPanelFocusControlRefs {\n toggle: RefObject<Focusable>;\n slider: RefObject<HTMLDivElement>;\n preferences: RefObject<Focusable>;\n}\nexport interface SplitPanelFocusControlState {\n refs: SplitPanelFocusControlRefs;\n setLastInteraction: (interaction: SplitPanelLastInteraction) => void;\n}\n\nexport function useSplitPanelFocusControl(dependencies: DependencyList): SplitPanelFocusControlState {\n const refs = {\n toggle: useRef<Focusable>(null),\n slider: useRef<HTMLDivElement>(null),\n preferences: useRef<Focusable>(null),\n };\n const lastInteraction = useRef<SplitPanelLastInteraction | null>(null);\n\n useEffect(() => {\n Promise.resolve().then(() => {\n switch (lastInteraction.current?.type) {\n case 'open':\n refs.slider.current?.focus();\n break;\n case 'close':\n refs.toggle.current?.focus();\n break;\n case 'position':\n refs.preferences.current?.focus();\n break;\n }\n lastInteraction.current = null;\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, dependencies);\n\n return {\n refs,\n setLastInteraction: (interaction: SplitPanelLastInteraction) => (lastInteraction.current = interaction),\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/app-layout/visual-refresh-toolbar/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4E,MAAM,OAAO,CAAC;AAajG,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAc/C,OAAO,EAAE,sBAAsB,EAAsB,MAAM,cAAc,CAAC;AAa1E,QAAA,MAAM,6BAA6B,mGAwgBlC,CAAC;AAEF,eAAe,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/app-layout/visual-refresh-toolbar/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAuD,MAAM,OAAO,CAAC;AAI5E,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,sBAAsB,EAAyB,MAAM,cAAc,CAAC;AAqD7E,QAAA,MAAM,6BAA6B,mGAgClC,CAAC;AAEF,eAAe,6BAA6B,CAAC"}
@@ -1,359 +1,46 @@
1
- import { __rest } from "tslib";
2
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
2
  // SPDX-License-Identifier: Apache-2.0
4
- import React, { useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from 'react';
5
- import { useMergeRefs, useStableCallback, useUniqueId } from '@cloudscape-design/component-toolkit/internal';
3
+ import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
4
+ import { unstable_batchedUpdates } from 'react-dom';
6
5
  import ScreenreaderOnly from '../../internal/components/screenreader-only';
7
- import { fireNonCancelableEvent } from '../../internal/events';
8
- import { useControllable } from '../../internal/hooks/use-controllable';
9
- import { useIntersectionObserver } from '../../internal/hooks/use-intersection-observer';
10
- import { useMobile } from '../../internal/hooks/use-mobile';
11
- import { useGetGlobalBreadcrumbs } from '../../internal/plugins/helpers/use-global-breadcrumbs';
12
- import globalVars from '../../internal/styles/global-vars';
13
- import { getSplitPanelDefaultSize } from '../../split-panel/utils/size-utils';
14
- import { MIN_DRAWER_SIZE, useDrawers } from '../utils/use-drawers';
15
- import { useFocusControl, useMultipleFocusControl } from '../utils/use-focus-control';
16
- import { useGlobalScrollPadding } from '../utils/use-global-scroll-padding';
17
- import { useSplitPanelFocusControl } from '../utils/use-split-panel-focus-control';
18
- import { ActiveDrawersContext } from '../utils/visibility-context';
19
- import { computeHorizontalLayout, computeSplitPanelOffsets, computeVerticalLayout, CONTENT_PADDING, } from './compute-layout';
20
6
  import { AppLayoutVisibilityContext } from './contexts';
21
- import { AppLayoutDrawer, AppLayoutGlobalDrawers, AppLayoutNavigation, AppLayoutNotifications, AppLayoutSplitPanelBottom, AppLayoutSplitPanelSide, AppLayoutToolbar, } from './internal';
22
- import { useMultiAppLayout } from './multi-layout';
7
+ import { AppLayoutWidgetizedState } from './internal';
23
8
  import { SkeletonLayout } from './skeleton';
24
- const AppLayoutVisualRefreshToolbar = React.forwardRef((_a, forwardRef) => {
25
- var _b, _c;
26
- var { ariaLabels, contentHeader, content, navigationOpen, navigationWidth, navigation, navigationHide, onNavigationChange, tools, toolsOpen: controlledToolsOpen, onToolsChange, toolsHide, toolsWidth, contentType, headerVariant, breadcrumbs, notifications, stickyNotifications, splitPanelPreferences: controlledSplitPanelPreferences, splitPanelOpen: controlledSplitPanelOpen, splitPanel, splitPanelSize: controlledSplitPanelSize, onSplitPanelToggle, onSplitPanelResize, onSplitPanelPreferencesChange, disableContentPaddings, minContentWidth, maxContentWidth, placement, navigationTriggerHide } = _a, rest = __rest(_a, ["ariaLabels", "contentHeader", "content", "navigationOpen", "navigationWidth", "navigation", "navigationHide", "onNavigationChange", "tools", "toolsOpen", "onToolsChange", "toolsHide", "toolsWidth", "contentType", "headerVariant", "breadcrumbs", "notifications", "stickyNotifications", "splitPanelPreferences", "splitPanelOpen", "splitPanel", "splitPanelSize", "onSplitPanelToggle", "onSplitPanelResize", "onSplitPanelPreferencesChange", "disableContentPaddings", "minContentWidth", "maxContentWidth", "placement", "navigationTriggerHide"]);
27
- const isMobile = useMobile();
28
- const { __embeddedViewMode: embeddedViewMode, __forceDeduplicationType: forceDeduplicationType } = rest;
29
- const splitPanelControlId = useUniqueId('split-panel');
30
- const [toolbarState, setToolbarState] = useState('show');
31
- const [toolbarHeight, setToolbarHeight] = useState(0);
32
- const [notificationsHeight, setNotificationsHeight] = useState(0);
33
- const [navigationAnimationDisabled, setNavigationAnimationDisabled] = useState(true);
34
- const [splitPanelAnimationDisabled, setSplitPanelAnimationDisabled] = useState(true);
35
- const [isNested, setIsNested] = useState(false);
36
- const rootRef = useRef(null);
37
- const [toolsOpen = false, setToolsOpen] = useControllable(controlledToolsOpen, onToolsChange, false, {
38
- componentName: 'AppLayout',
39
- controlledProp: 'toolsOpen',
40
- changeHandler: 'onToolsChange',
41
- });
42
- const onToolsToggle = (open) => {
43
- setToolsOpen(open);
44
- drawersFocusControl.setFocus();
45
- fireNonCancelableEvent(onToolsChange, { open });
46
- };
47
- const onGlobalDrawerFocus = (drawerId, open) => {
48
- globalDrawersFocusControl.setFocus({ force: true, drawerId, open });
49
- };
50
- const onAddNewActiveDrawer = (drawerId) => {
51
- var _a, _b;
52
- // If a local drawer is already open, and we attempt to open a new one,
53
- // it will replace the existing one instead of opening an additional drawer,
54
- // since only one local drawer is supported. Therefore, layout calculations are not necessary.
55
- if (activeDrawer && (drawers === null || drawers === void 0 ? void 0 : drawers.find(drawer => drawer.id === drawerId))) {
56
- return;
57
- }
58
- // get the size of drawerId. it could be either local or global drawer
59
- const combinedDrawers = [...(drawers || []), ...globalDrawers];
60
- const newDrawer = combinedDrawers.find(drawer => drawer.id === drawerId);
61
- if (!newDrawer) {
62
- return;
63
- }
64
- const newDrawerSize = Math.min((_b = (_a = newDrawer.defaultSize) !== null && _a !== void 0 ? _a : drawerSizes[drawerId]) !== null && _b !== void 0 ? _b : MIN_DRAWER_SIZE, MIN_DRAWER_SIZE);
65
- // check if the active drawers could be resized to fit the new drawers
66
- // to do this, we need to take all active drawers, sum up their min sizes, truncate it from resizableSpaceAvailable
67
- // and compare a given number with the new drawer id min size
68
- // the total size of all global drawers resized to their min size
69
- const availableSpaceForNewDrawer = resizableSpaceAvailable - totalActiveDrawersMinSize;
70
- if (availableSpaceForNewDrawer >= newDrawerSize) {
71
- return;
72
- }
73
- // now we made sure we cannot accommodate the new drawer with existing ones
74
- closeFirstDrawer();
75
- };
76
- const { drawers, activeDrawer, minDrawerSize, minGlobalDrawersSizes, activeDrawerSize, ariaLabelsWithDrawers, globalDrawers, activeGlobalDrawers, activeGlobalDrawersIds, activeGlobalDrawersSizes, drawerSizes, drawersOpenQueue, onActiveDrawerChange, onActiveDrawerResize, onActiveGlobalDrawersChange, expandedDrawerId, setExpandedDrawerId, } = useDrawers(Object.assign(Object.assign({}, rest), { onGlobalDrawerFocus, onAddNewActiveDrawer }), ariaLabels, {
77
- ariaLabels,
78
- toolsHide,
79
- toolsOpen,
80
- tools,
81
- toolsWidth,
82
- onToolsToggle,
83
- });
84
- const onActiveDrawerChangeHandler = (drawerId, params = { initiatedByUserAction: true }) => {
85
- onActiveDrawerChange(drawerId, params);
86
- drawersFocusControl.setFocus();
87
- };
88
- const [splitPanelOpen = false, setSplitPanelOpen] = useControllable(controlledSplitPanelOpen, onSplitPanelToggle, false, {
89
- componentName: 'AppLayout',
90
- controlledProp: 'splitPanelOpen',
91
- changeHandler: 'onSplitPanelToggle',
92
- });
93
- const onSplitPanelToggleHandler = () => {
94
- setSplitPanelAnimationDisabled(false);
95
- setSplitPanelOpen(!splitPanelOpen);
96
- splitPanelFocusControl.setLastInteraction({ type: splitPanelOpen ? 'close' : 'open' });
97
- fireNonCancelableEvent(onSplitPanelToggle, { open: !splitPanelOpen });
98
- };
99
- const [splitPanelPreferences, setSplitPanelPreferences] = useControllable(controlledSplitPanelPreferences, onSplitPanelPreferencesChange, undefined, {
100
- componentName: 'AppLayout',
101
- controlledProp: 'splitPanelPreferences',
102
- changeHandler: 'onSplitPanelPreferencesChange',
103
- });
104
- const onSplitPanelPreferencesChangeHandler = (detail) => {
105
- setSplitPanelPreferences(detail);
106
- splitPanelFocusControl.setLastInteraction({ type: 'position' });
107
- fireNonCancelableEvent(onSplitPanelPreferencesChange, detail);
108
- };
109
- const [splitPanelSize = 0, setSplitPanelSize] = useControllable(controlledSplitPanelSize, onSplitPanelResize, getSplitPanelDefaultSize((_b = splitPanelPreferences === null || splitPanelPreferences === void 0 ? void 0 : splitPanelPreferences.position) !== null && _b !== void 0 ? _b : 'bottom'), { componentName: 'AppLayout', controlledProp: 'splitPanelSize', changeHandler: 'onSplitPanelResize' });
110
- const [splitPanelReportedSize, setSplitPanelReportedSize] = useState(0);
111
- const [splitPanelHeaderBlockSize, setSplitPanelHeaderBlockSize] = useState(0);
112
- const onSplitPanelResizeHandler = (size) => {
113
- setSplitPanelSize(size);
114
- fireNonCancelableEvent(onSplitPanelResize, { size });
115
- };
116
- const [splitPanelToggleConfig, setSplitPanelToggleConfig] = useState({
117
- ariaLabel: undefined,
118
- displayed: false,
119
- });
120
- const globalDrawersFocusControl = useMultipleFocusControl(true, activeGlobalDrawersIds);
121
- const drawersFocusControl = useFocusControl(!!(activeDrawer === null || activeDrawer === void 0 ? void 0 : activeDrawer.id), true, activeDrawer === null || activeDrawer === void 0 ? void 0 : activeDrawer.id);
122
- const navigationFocusControl = useFocusControl(navigationOpen, navigationTriggerHide);
123
- const splitPanelFocusControl = useSplitPanelFocusControl([splitPanelPreferences, splitPanelOpen]);
124
- const onNavigationToggle = useStableCallback((open) => {
125
- setNavigationAnimationDisabled(false);
126
- navigationFocusControl.setFocus();
127
- fireNonCancelableEvent(onNavigationChange, { open });
128
- });
129
- useImperativeHandle(forwardRef, () => ({
130
- closeNavigationIfNecessary: () => isMobile && onNavigationToggle(false),
131
- openTools: () => onToolsToggle(true),
132
- focusToolsClose: () => drawersFocusControl.setFocus(true),
133
- focusActiveDrawer: () => drawersFocusControl.setFocus(true),
134
- focusSplitPanel: () => { var _a; return (_a = splitPanelFocusControl.refs.slider.current) === null || _a === void 0 ? void 0 : _a.focus(); },
135
- focusNavigation: () => navigationFocusControl.setFocus(true),
136
- }));
137
- const resolvedStickyNotifications = !!stickyNotifications && !isMobile;
138
- //navigation must be null if hidden so toolbar knows to hide the toggle button
139
- const resolvedNavigation = navigationHide ? null : navigation || React.createElement(React.Fragment, null);
140
- //navigation must not be open if navigationHide is true
141
- const resolvedNavigationOpen = !!resolvedNavigation && navigationOpen;
142
- const { maxDrawerSize, maxSplitPanelSize, splitPanelForcedPosition, splitPanelPosition, maxGlobalDrawersSizes, resizableSpaceAvailable, } = computeHorizontalLayout({
143
- activeDrawerSize: activeDrawer ? activeDrawerSize : 0,
144
- splitPanelSize,
145
- minContentWidth,
146
- navigationOpen: resolvedNavigationOpen,
147
- navigationWidth,
148
- placement,
149
- splitPanelOpen,
150
- splitPanelPosition: splitPanelPreferences === null || splitPanelPreferences === void 0 ? void 0 : splitPanelPreferences.position,
151
- isMobile,
152
- activeGlobalDrawersSizes,
153
- });
154
- const { ref: intersectionObserverRef, isIntersecting } = useIntersectionObserver({ initialState: true });
155
- const { registered, toolbarProps } = useMultiAppLayout({
156
- forceDeduplicationType,
157
- ariaLabels: ariaLabelsWithDrawers,
158
- navigation: resolvedNavigation && !navigationTriggerHide,
159
- navigationOpen: resolvedNavigationOpen,
160
- onNavigationToggle,
161
- navigationFocusRef: navigationFocusControl.refs.toggle,
162
- breadcrumbs,
163
- activeDrawerId: (_c = activeDrawer === null || activeDrawer === void 0 ? void 0 : activeDrawer.id) !== null && _c !== void 0 ? _c : null,
164
- // only pass it down if there are non-empty drawers or tools
165
- drawers: (drawers === null || drawers === void 0 ? void 0 : drawers.length) || !toolsHide ? drawers : undefined,
166
- globalDrawersFocusControl,
167
- globalDrawers: (globalDrawers === null || globalDrawers === void 0 ? void 0 : globalDrawers.length) ? globalDrawers : undefined,
168
- activeGlobalDrawersIds,
169
- onActiveGlobalDrawersChange,
170
- onActiveDrawerChange: onActiveDrawerChangeHandler,
171
- drawersFocusRef: drawersFocusControl.refs.toggle,
172
- splitPanel,
173
- splitPanelToggleProps: Object.assign(Object.assign({}, splitPanelToggleConfig), { active: splitPanelOpen, controlId: splitPanelControlId, position: splitPanelPosition }),
174
- splitPanelFocusRef: splitPanelFocusControl.refs.toggle,
175
- onSplitPanelToggle: onSplitPanelToggleHandler,
176
- expandedDrawerId,
177
- setExpandedDrawerId,
178
- }, isIntersecting);
179
- const hasToolbar = !embeddedViewMode && !!toolbarProps;
180
- const discoveredBreadcrumbs = useGetGlobalBreadcrumbs(hasToolbar && !breadcrumbs);
181
- const verticalOffsets = computeVerticalLayout({
182
- topOffset: placement.insetBlockStart,
183
- hasVisibleToolbar: hasToolbar && toolbarState !== 'hide',
184
- notificationsHeight: notificationsHeight !== null && notificationsHeight !== void 0 ? notificationsHeight : 0,
185
- toolbarHeight: toolbarHeight !== null && toolbarHeight !== void 0 ? toolbarHeight : 0,
186
- stickyNotifications: resolvedStickyNotifications,
187
- });
188
- useGlobalScrollPadding(verticalOffsets.header);
189
- const appLayoutInternals = {
190
- ariaLabels: ariaLabelsWithDrawers,
191
- headerVariant,
192
- isMobile,
193
- breadcrumbs,
194
- discoveredBreadcrumbs,
195
- stickyNotifications: resolvedStickyNotifications,
196
- navigationOpen: resolvedNavigationOpen,
197
- navigation: resolvedNavigation,
198
- navigationFocusControl,
199
- activeDrawer,
200
- activeDrawerSize,
201
- minDrawerSize,
202
- maxDrawerSize,
203
- minGlobalDrawersSizes,
204
- maxGlobalDrawersSizes,
205
- drawers: drawers,
206
- globalDrawers,
207
- activeGlobalDrawers,
208
- activeGlobalDrawersIds,
209
- activeGlobalDrawersSizes,
210
- onActiveGlobalDrawersChange,
211
- drawersFocusControl,
212
- globalDrawersFocusControl,
213
- splitPanelPosition,
214
- splitPanelToggleConfig,
215
- splitPanelOpen,
216
- splitPanelControlId,
217
- splitPanelFocusControl,
218
- placement,
219
- toolbarState,
220
- setToolbarState,
221
- verticalOffsets,
222
- drawersOpenQueue,
223
- setToolbarHeight,
224
- setNotificationsHeight,
225
- onSplitPanelToggle: onSplitPanelToggleHandler,
226
- onNavigationToggle,
227
- onActiveDrawerChange: onActiveDrawerChangeHandler,
228
- onActiveDrawerResize,
229
- splitPanelAnimationDisabled,
230
- expandedDrawerId,
231
- setExpandedDrawerId,
232
- };
233
- const splitPanelInternals = {
234
- bottomOffset: 0,
235
- getMaxHeight: () => {
236
- const availableHeight = document.documentElement.clientHeight - placement.insetBlockStart - placement.insetBlockEnd;
237
- // If the page is likely zoomed in at 200%, allow the split panel to fill the content area.
238
- return availableHeight < 400 ? availableHeight - 40 : availableHeight - 250;
239
- },
240
- maxWidth: maxSplitPanelSize,
241
- isForcedPosition: splitPanelForcedPosition,
242
- isOpen: splitPanelOpen,
243
- leftOffset: 0,
244
- onPreferencesChange: onSplitPanelPreferencesChangeHandler,
245
- onResize: onSplitPanelResizeHandler,
246
- onToggle: onSplitPanelToggleHandler,
247
- position: splitPanelPosition,
248
- reportSize: size => setSplitPanelReportedSize(size),
249
- reportHeaderHeight: size => setSplitPanelHeaderBlockSize(size),
250
- headerHeight: splitPanelHeaderBlockSize,
251
- rightOffset: 0,
252
- size: splitPanelSize,
253
- topOffset: 0,
254
- setSplitPanelToggle: setSplitPanelToggleConfig,
255
- refs: splitPanelFocusControl.refs,
256
- };
257
- const closeFirstDrawer = useStableCallback(() => {
258
- const drawerToClose = drawersOpenQueue[drawersOpenQueue.length - 1];
259
- if (activeDrawer && (activeDrawer === null || activeDrawer === void 0 ? void 0 : activeDrawer.id) === drawerToClose) {
260
- onActiveDrawerChange(null, { initiatedByUserAction: true });
261
- }
262
- else if (activeGlobalDrawersIds.includes(drawerToClose)) {
263
- onActiveGlobalDrawersChange(drawerToClose, { initiatedByUserAction: true });
264
- }
265
- });
266
- useEffect(() => {
267
- // Close navigation drawer on mobile so that the main content is visible
268
- if (isMobile) {
269
- onNavigationToggle(false);
270
- }
271
- // eslint-disable-next-line react-hooks/exhaustive-deps
272
- }, [isMobile]);
273
- const getTotalActiveDrawersMinSize = () => {
274
- var _a;
275
- const combinedDrawers = [...(drawers || []), ...globalDrawers];
276
- let result = activeGlobalDrawersIds
277
- .map(activeDrawerId => {
278
- var _a, _b;
279
- return Math.min((_b = (_a = combinedDrawers.find(drawer => drawer.id === activeDrawerId)) === null || _a === void 0 ? void 0 : _a.defaultSize) !== null && _b !== void 0 ? _b : MIN_DRAWER_SIZE, MIN_DRAWER_SIZE);
280
- })
281
- .reduce((acc, curr) => acc + curr, 0);
282
- if (activeDrawer) {
283
- result += Math.min((_a = activeDrawer === null || activeDrawer === void 0 ? void 0 : activeDrawer.defaultSize) !== null && _a !== void 0 ? _a : MIN_DRAWER_SIZE, MIN_DRAWER_SIZE);
284
- }
285
- return result;
286
- };
287
- const totalActiveDrawersMinSize = getTotalActiveDrawersMinSize();
288
- useEffect(() => {
289
- if (isMobile) {
290
- return;
291
- }
292
- const activeNavigationWidth = !navigationHide && navigationOpen ? navigationWidth : 0;
293
- const scrollWidth = activeNavigationWidth + CONTENT_PADDING + totalActiveDrawersMinSize;
294
- const hasHorizontalScroll = scrollWidth > placement.inlineSize;
295
- if (hasHorizontalScroll) {
296
- if (!navigationHide && navigationOpen) {
297
- onNavigationToggle(false);
298
- return;
299
- }
300
- closeFirstDrawer();
301
- }
302
- }, [
303
- totalActiveDrawersMinSize,
304
- closeFirstDrawer,
305
- isMobile,
306
- navigationHide,
307
- navigationOpen,
308
- navigationWidth,
309
- onNavigationToggle,
310
- placement.inlineSize,
311
- ]);
312
- /**
313
- * Returns true if the AppLayout is nested
314
- * Does not apply to iframe
315
- */
316
- const getIsNestedInAppLayout = (element) => {
317
- var _a;
318
- let currentElement = (_a = element === null || element === void 0 ? void 0 : element.parentElement) !== null && _a !== void 0 ? _a : null;
319
- // this traverse is needed only for JSDOM
320
- // in real browsers the globalVar will be propagated to all descendants and this loops exits after initial iteration
321
- while (currentElement) {
322
- if (getComputedStyle(currentElement).getPropertyValue(globalVars.stickyVerticalTopOffset)) {
323
- return true;
324
- }
325
- currentElement = currentElement.parentElement;
326
- }
327
- return false;
328
- };
9
+ import { useMultiAppLayout } from './skeleton/multi-layout';
10
+ import { getPropsToMerge, mergeProps } from './state/props-merger';
11
+ const AppLayoutStateProvider = ({ forceDeduplicationType, appLayoutProps, stateManager, children }) => {
12
+ const [appLayoutState, setAppLayoutState] = useState({ isIntersecting: true });
13
+ const [skeletonAttributes, setSkeletonAttributes] = useState({});
14
+ // use { fn: } object wrapper to avoid confusion with callback form of setState
15
+ const [deduplicator, setDeduplicator] = useState({ fn: mergeProps });
16
+ const [deduplicationProps, setDeduplicationProps] = useState(() => getPropsToMerge(appLayoutProps, appLayoutState));
17
+ const { registered, toolbarProps } = useMultiAppLayout(forceDeduplicationType, appLayoutState.isIntersecting, deduplicationProps, deduplicator.fn);
329
18
  useLayoutEffect(() => {
330
- if (!hasToolbar) {
331
- setIsNested(getIsNestedInAppLayout(rootRef.current));
332
- }
333
- }, [hasToolbar]);
334
- const splitPanelOffsets = computeSplitPanelOffsets({
335
- placement,
336
- hasSplitPanel: !!splitPanel,
337
- splitPanelOpen,
338
- splitPanelPosition,
339
- splitPanelFullHeight: splitPanelReportedSize,
340
- splitPanelHeaderHeight: splitPanelHeaderBlockSize,
341
- });
342
- return (React.createElement(AppLayoutVisibilityContext.Provider, { value: isIntersecting },
343
- !hasToolbar && breadcrumbs ? React.createElement(ScreenreaderOnly, null, breadcrumbs) : null,
344
- React.createElement(SkeletonLayout, { ref: useMergeRefs(intersectionObserverRef, rootRef), isNested: isNested,
345
- // Why not use drawerExpandedMode={!!expandedDrawerId || !!toolbarProps?.expandedDrawerId} instead?
346
- // Because in nested layouts, the parent layout hides its main content area,
347
- // which means the child layout isn't rendered at all in that case
348
- drawerExpandedModeInChildLayout: !!(toolbarProps === null || toolbarProps === void 0 ? void 0 : toolbarProps.expandedDrawerId), drawerExpandedMode: !!expandedDrawerId, style: Object.assign(Object.assign({ paddingBlockEnd: splitPanelOffsets.mainContentPaddingBlockEnd }, (hasToolbar || !isNested
349
- ? {
350
- [globalVars.stickyVerticalTopOffset]: `${verticalOffsets.header}px`,
351
- [globalVars.stickyVerticalBottomOffset]: `${splitPanelOffsets.stickyVerticalBottomOffset}px`,
352
- }
353
- : {})), (!isMobile ? { minWidth: `${minContentWidth}px` } : {})), toolbar: hasToolbar && React.createElement(AppLayoutToolbar, { appLayoutInternals: appLayoutInternals, toolbarProps: toolbarProps }), notifications: notifications && (React.createElement(AppLayoutNotifications, { appLayoutInternals: appLayoutInternals }, notifications)), headerVariant: headerVariant, contentHeader: contentHeader,
354
- // delay rendering the content until registration of this instance is complete
355
- content: registered ? content : null, navigation: resolvedNavigation && React.createElement(AppLayoutNavigation, { appLayoutInternals: appLayoutInternals }), navigationOpen: resolvedNavigationOpen, navigationWidth: navigationWidth, navigationAnimationDisabled: navigationAnimationDisabled, tools: drawers && drawers.length > 0 && React.createElement(AppLayoutDrawer, { appLayoutInternals: appLayoutInternals }), globalTools: React.createElement(ActiveDrawersContext.Provider, { value: activeGlobalDrawersIds },
356
- React.createElement(AppLayoutGlobalDrawers, { appLayoutInternals: appLayoutInternals })), globalToolsOpen: !!activeGlobalDrawersIds.length, toolsOpen: !!activeDrawer, toolsWidth: activeDrawerSize, sideSplitPanel: splitPanelPosition === 'side' && (React.createElement(AppLayoutSplitPanelSide, { appLayoutInternals: appLayoutInternals, splitPanelInternals: splitPanelInternals }, splitPanel)), bottomSplitPanel: splitPanelPosition === 'bottom' && (React.createElement(AppLayoutSplitPanelBottom, { appLayoutInternals: appLayoutInternals, splitPanelInternals: splitPanelInternals }, splitPanel)), splitPanelOpen: splitPanelOpen, placement: placement, contentType: contentType, maxContentWidth: maxContentWidth, disableContentPaddings: disableContentPaddings })));
19
+ stateManager.current.setState = (appLayoutState, skeletonAttributes, deduplicationProps, mergeProps) => {
20
+ unstable_batchedUpdates(() => {
21
+ setAppLayoutState(appLayoutState);
22
+ setSkeletonAttributes(skeletonAttributes);
23
+ setDeduplicationProps(deduplicationProps);
24
+ setDeduplicator({ fn: mergeProps });
25
+ });
26
+ };
27
+ }, [stateManager]);
28
+ const hasToolbar = !!toolbarProps;
29
+ useEffect(() => {
30
+ var _a, _b;
31
+ stateManager.current.hasToolbar = hasToolbar;
32
+ (_b = (_a = stateManager.current).setToolbar) === null || _b === void 0 ? void 0 : _b.call(_a, hasToolbar);
33
+ }, [stateManager, hasToolbar]);
34
+ return React.createElement(React.Fragment, null, children(registered, appLayoutState, toolbarProps, skeletonAttributes));
35
+ };
36
+ const AppLayoutVisualRefreshToolbar = React.forwardRef((props, forwardRef) => {
37
+ const stateManager = useRef({ setState: undefined, hasToolbar: true, setToolbar: undefined });
38
+ const { __forceDeduplicationType: forceDeduplicationType, __embeddedViewMode: embeddedViewMode } = props;
39
+ return (React.createElement(React.Fragment, null,
40
+ React.createElement(AppLayoutStateProvider, { forceDeduplicationType: forceDeduplicationType, appLayoutProps: props, stateManager: stateManager }, (registered, appLayoutState, toolbarProps, skeletonAttributes) => (React.createElement(AppLayoutVisibilityContext.Provider, { value: appLayoutState.isIntersecting },
41
+ (embeddedViewMode || !toolbarProps) && props.breadcrumbs ? (React.createElement(ScreenreaderOnly, null, props.breadcrumbs)) : null,
42
+ React.createElement(SkeletonLayout, { registered: registered, toolbarProps: toolbarProps, appLayoutProps: props, appLayoutState: appLayoutState, skeletonSlotsAttributes: skeletonAttributes })))),
43
+ React.createElement(AppLayoutWidgetizedState, { forwardRef: forwardRef, appLayoutProps: props, stateManager: stateManager })));
357
44
  });
358
45
  export default AppLayoutVisualRefreshToolbar;
359
46
  //# sourceMappingURL=index.js.map