@atlaskit/navigation-system 11.3.1 → 11.3.2

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 (50) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/ui/page-layout/calculate-layout-area-states.js +76 -37
  3. package/dist/cjs/ui/page-layout/chat-panel.js +6 -3
  4. package/dist/cjs/ui/page-layout/layout-area-sizing-context.js +2 -2
  5. package/dist/cjs/ui/page-layout/layout-area-sizing-provider.js +243 -247
  6. package/dist/cjs/ui/page-layout/layout-area-sizing-runtime.js +468 -0
  7. package/dist/cjs/ui/page-layout/main/main.js +1 -1
  8. package/dist/cjs/ui/page-layout/panel-splitter/panel-splitter.js +239 -99
  9. package/dist/cjs/ui/page-layout/panel-splitter/provider.js +3 -1
  10. package/dist/cjs/ui/page-layout/root.compiled.css +14 -3
  11. package/dist/cjs/ui/page-layout/root.js +43 -17
  12. package/dist/cjs/ui/page-layout/side-nav/side-nav.js +14 -3
  13. package/dist/cjs/ui/page-layout/use-css-layout-area-states.js +117 -0
  14. package/dist/cjs/ui/page-layout/use-layout-area-sizing.js +3 -1
  15. package/dist/es2019/ui/page-layout/calculate-layout-area-states.js +51 -17
  16. package/dist/es2019/ui/page-layout/chat-panel.js +29 -5
  17. package/dist/es2019/ui/page-layout/layout-area-sizing-context.js +2 -2
  18. package/dist/es2019/ui/page-layout/layout-area-sizing-provider.js +171 -241
  19. package/dist/es2019/ui/page-layout/layout-area-sizing-runtime.js +419 -0
  20. package/dist/es2019/ui/page-layout/main/main.js +2 -2
  21. package/dist/es2019/ui/page-layout/panel-splitter/panel-splitter.js +60 -10
  22. package/dist/es2019/ui/page-layout/panel-splitter/provider.js +3 -1
  23. package/dist/es2019/ui/page-layout/root.compiled.css +14 -3
  24. package/dist/es2019/ui/page-layout/root.js +30 -3
  25. package/dist/es2019/ui/page-layout/side-nav/side-nav.js +23 -3
  26. package/dist/es2019/ui/page-layout/use-css-layout-area-states.js +73 -0
  27. package/dist/es2019/ui/page-layout/use-layout-area-sizing.js +3 -1
  28. package/dist/esm/ui/page-layout/calculate-layout-area-states.js +75 -37
  29. package/dist/esm/ui/page-layout/chat-panel.js +7 -4
  30. package/dist/esm/ui/page-layout/layout-area-sizing-context.js +2 -2
  31. package/dist/esm/ui/page-layout/layout-area-sizing-provider.js +243 -248
  32. package/dist/esm/ui/page-layout/layout-area-sizing-runtime.js +459 -0
  33. package/dist/esm/ui/page-layout/main/main.js +2 -2
  34. package/dist/esm/ui/page-layout/panel-splitter/panel-splitter.js +238 -98
  35. package/dist/esm/ui/page-layout/panel-splitter/provider.js +3 -1
  36. package/dist/esm/ui/page-layout/root.compiled.css +14 -3
  37. package/dist/esm/ui/page-layout/root.js +42 -16
  38. package/dist/esm/ui/page-layout/side-nav/side-nav.js +14 -3
  39. package/dist/esm/ui/page-layout/use-css-layout-area-states.js +110 -0
  40. package/dist/esm/ui/page-layout/use-layout-area-sizing.js +3 -1
  41. package/dist/types/ui/page-layout/calculate-layout-area-states.d.ts +7 -2
  42. package/dist/types/ui/page-layout/layout-area-sizing-context.d.ts +10 -3
  43. package/dist/types/ui/page-layout/layout-area-sizing-provider.d.ts +6 -0
  44. package/dist/types/ui/page-layout/layout-area-sizing-runtime.d.ts +8 -0
  45. package/dist/types/ui/page-layout/panel-splitter/panel-splitter-context.d.ts +4 -0
  46. package/dist/types/ui/page-layout/panel-splitter/provider.d.ts +1 -1
  47. package/dist/types/ui/page-layout/root.d.ts +2 -0
  48. package/dist/types/ui/page-layout/use-css-layout-area-states.d.ts +8 -0
  49. package/dist/types/ui/page-layout/use-layout-area-sizing.d.ts +2 -0
  50. package/package.json +7 -2
@@ -0,0 +1,459 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
4
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
5
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
6
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
9
+ import { bind } from 'bind-event-listener';
10
+ import { calculateLayoutAreaStates } from './calculate-layout-area-states';
11
+ import { LayoutAreaSizingContext } from './layout-area-sizing-context';
12
+ import { layoutAreaStateContexts } from './layout-area-state-contexts';
13
+ import { resolveLayoutWidth } from './resolve-layout-width';
14
+ import { useOccupiedLayoutWidth } from './use-occupied-layout-width';
15
+ var defaultMainMinWidth = 320;
16
+ function useStableAreaState(state) {
17
+ var _ref = state !== null && state !== void 0 ? state : {},
18
+ mode = _ref.mode,
19
+ width = _ref.width,
20
+ minWidth = _ref.minWidth;
21
+ return useMemo(function () {
22
+ return mode !== undefined && width !== undefined && minWidth !== undefined ? {
23
+ mode: mode,
24
+ width: width,
25
+ minWidth: minWidth
26
+ } : undefined;
27
+ }, [mode, width, minWidth]);
28
+ }
29
+ export function LayoutAreaSizingRuntime(_ref2) {
30
+ var children = _ref2.children,
31
+ layoutRef = _ref2.layoutRef,
32
+ onReady = _ref2.onReady,
33
+ onUpdate = _ref2.onUpdate;
34
+ var occupiedWidth = useOccupiedLayoutWidth(layoutRef);
35
+ var _useState = useState(null),
36
+ _useState2 = _slicedToArray(_useState, 2),
37
+ dimensions = _useState2[0],
38
+ setDimensions = _useState2[1];
39
+ var _useState3 = useState(defaultMainMinWidth),
40
+ _useState4 = _slicedToArray(_useState3, 2),
41
+ mainMinWidth = _useState4[0],
42
+ setMainMinWidth = _useState4[1];
43
+ var _useState5 = useState({}),
44
+ _useState6 = _slicedToArray(_useState5, 2),
45
+ areas = _useState6[0],
46
+ setAreas = _useState6[1];
47
+ var _useState7 = useState(null),
48
+ _useState8 = _slicedToArray(_useState7, 2),
49
+ resizeSession = _useState8[0],
50
+ setResizeSession = _useState8[1];
51
+ var areaStatesRef = React.useRef({});
52
+ var configsRef = React.useRef({});
53
+ var _useState9 = useState(false),
54
+ _useState0 = _slicedToArray(_useState9, 2),
55
+ hasInteraction = _useState0[0],
56
+ setHasInteraction = _useState0[1];
57
+ var adoptedConstraints = React.useRef(null);
58
+ // Preserve the CSS handoff only while its available space is unchanged.
59
+ var isPreservingInitialLayout = !hasInteraction && (!adoptedConstraints.current || adoptedConstraints.current.occupiedWidth === occupiedWidth && adoptedConstraints.current.mainMinWidth === mainMinWidth);
60
+ var _useState1 = useState({}),
61
+ _useState10 = _slicedToArray(_useState1, 2),
62
+ initialStates = _useState10[0],
63
+ setInitialStates = _useState10[1];
64
+ var inputsRef = React.useRef({
65
+ dimensions: dimensions,
66
+ occupiedWidth: occupiedWidth,
67
+ mainMinWidth: mainMinWidth,
68
+ areas: areas,
69
+ resizeSession: resizeSession
70
+ });
71
+ useEffect(function () {
72
+ inputsRef.current = {
73
+ dimensions: dimensions,
74
+ occupiedWidth: occupiedWidth,
75
+ mainMinWidth: mainMinWidth,
76
+ areas: areas,
77
+ resizeSession: resizeSession
78
+ };
79
+ }, [dimensions, occupiedWidth, mainMinWidth, areas, resizeSession]);
80
+ useEffect(function () {
81
+ if (adoptedConstraints.current && (adoptedConstraints.current.occupiedWidth !== occupiedWidth || adoptedConstraints.current.mainMinWidth !== mainMinWidth)) {
82
+ setHasInteraction(true);
83
+ }
84
+ setResizeSession(null);
85
+ }, [mainMinWidth, occupiedWidth]);
86
+ useEffect(function () {
87
+ var root = layoutRef === null || layoutRef === void 0 ? void 0 : layoutRef.current;
88
+ var previous = null;
89
+ // Match the actual rem-based grid breakpoint, including browser font settings.
90
+ var inlineChatQuery = window.matchMedia('(min-width: 40rem)');
91
+ var inlineSideNavQuery = window.matchMedia('(min-width: 64rem)');
92
+ var updateDimensions = function updateDimensions(contentWidth) {
93
+ var _style$width, _style$paddingLeft, _style$paddingRight, _style$borderLeftWidt, _style$borderRightWid, _previous;
94
+ var style = root && contentWidth === undefined ? getComputedStyle(root) : null;
95
+ var computedWidth = Number.parseFloat((_style$width = style === null || style === void 0 ? void 0 : style.width) !== null && _style$width !== void 0 ? _style$width : '');
96
+ var padding = (parseFloat((_style$paddingLeft = style === null || style === void 0 ? void 0 : style.paddingLeft) !== null && _style$paddingLeft !== void 0 ? _style$paddingLeft : '') || 0) + (parseFloat((_style$paddingRight = style === null || style === void 0 ? void 0 : style.paddingRight) !== null && _style$paddingRight !== void 0 ? _style$paddingRight : '') || 0);
97
+ var border = (parseFloat((_style$borderLeftWidt = style === null || style === void 0 ? void 0 : style.borderLeftWidth) !== null && _style$borderLeftWidt !== void 0 ? _style$borderLeftWidt : '') || 0) + (parseFloat((_style$borderRightWid = style === null || style === void 0 ? void 0 : style.borderRightWidth) !== null && _style$borderRightWid !== void 0 ? _style$borderRightWid : '') || 0);
98
+ var layoutWidth = contentWidth !== null && contentWidth !== void 0 ? contentWidth : root ?
99
+ // Keep fractional CSS pixels, just as ResizeObserver does. Otherwise
100
+ // its initial delivery could be mistaken for a viewport resize.
101
+ Math.max(0, Number.isFinite(computedWidth) ? computedWidth - ((style === null || style === void 0 ? void 0 : style.boxSizing) === 'border-box' ? padding + border : 0) : root.clientWidth - padding) : window.innerWidth;
102
+ var next = {
103
+ viewportWidth: window.innerWidth,
104
+ layoutWidth: layoutWidth,
105
+ isChatPanelOverlay: !inlineChatQuery.matches,
106
+ isSideNavOverlay: !inlineSideNavQuery.matches
107
+ };
108
+ if (((_previous = previous) === null || _previous === void 0 ? void 0 : _previous.viewportWidth) === next.viewportWidth && previous.layoutWidth === next.layoutWidth && previous.isChatPanelOverlay === next.isChatPanelOverlay && previous.isSideNavOverlay === next.isSideNavOverlay) {
109
+ return;
110
+ }
111
+ if (previous) {
112
+ setHasInteraction(true);
113
+ }
114
+ previous = next;
115
+ setDimensions(next);
116
+ setResizeSession(null);
117
+ };
118
+ updateDimensions();
119
+ var observer = new ResizeObserver(function (entries) {
120
+ var entry = entries.find(function (entry) {
121
+ return entry.target === root;
122
+ });
123
+ if (entry) {
124
+ updateDimensions(entry.contentRect.width);
125
+ }
126
+ });
127
+ if (root) {
128
+ observer.observe(root);
129
+ }
130
+ var unbindResize = bind(window, {
131
+ type: 'resize',
132
+ listener: function listener() {
133
+ return updateDimensions();
134
+ }
135
+ });
136
+ var unbindQuery = bind(inlineChatQuery, {
137
+ type: 'change',
138
+ listener: function listener() {
139
+ return updateDimensions();
140
+ }
141
+ });
142
+ var unbindSideNavQuery = bind(inlineSideNavQuery, {
143
+ type: 'change',
144
+ listener: function listener() {
145
+ return updateDimensions();
146
+ }
147
+ });
148
+ return function () {
149
+ observer.disconnect();
150
+ unbindResize();
151
+ unbindQuery();
152
+ unbindSideNavQuery();
153
+ };
154
+ }, [layoutRef]);
155
+ var registerArea = useCallback(function (area, config) {
156
+ var previous = configsRef.current[area];
157
+ if (adoptedConstraints.current && (!previous || previous.isOpen !== config.isOpen || previous.requestedWidth !== config.requestedWidth || previous.minWidth !== config.minWidth || previous.maxWidth !== config.maxWidth || previous.defaultWidth !== config.defaultWidth || previous.compactDefaultWidth !== config.compactDefaultWidth)) {
158
+ setHasInteraction(true);
159
+ }
160
+ configsRef.current[area] = config;
161
+ setResizeSession(function (current) {
162
+ // A changed layout/configuration needs a fresh allocation. A controlled
163
+ // acknowledgement for the resized area keeps its siblings fixed.
164
+ return previous && (previous.isOpen === config.isOpen || area === 'side-nav' && !config.isOpen && (current === null || current === void 0 ? void 0 : current.area) !== 'side-nav') && previous.minWidth === config.minWidth && previous.maxWidth === config.maxWidth && previous.defaultWidth === config.defaultWidth && previous.compactDefaultWidth === config.compactDefaultWidth && (previous.requestedWidth === config.requestedWidth || (current === null || current === void 0 ? void 0 : current.area) === area && current.completedWidth === config.requestedWidth || area === 'side-nav' && !config.isOpen && (current === null || current === void 0 ? void 0 : current.area) !== 'side-nav') ? current : null;
165
+ });
166
+ setAreas(function (current) {
167
+ var existing = current[area];
168
+ return _objectSpread(_objectSpread({}, current), {}, _defineProperty({}, area, _objectSpread(_objectSpread(_objectSpread({}, existing), config), {}, {
169
+ liveResize: config.isOpen ? existing === null || existing === void 0 ? void 0 : existing.liveResize : undefined
170
+ })));
171
+ });
172
+ }, []);
173
+ var unregisterArea = useCallback(function (area) {
174
+ if (adoptedConstraints.current) {
175
+ setHasInteraction(true);
176
+ }
177
+ delete configsRef.current[area];
178
+ setResizeSession(null);
179
+ setAreas(function (current) {
180
+ if (!current[area]) {
181
+ return current;
182
+ }
183
+ // Closing uses isOpen: false and retains preferences. Unregistering means
184
+ // the owning component unmounted; a replacement must start with its own defaults.
185
+ var next = _objectSpread({}, current);
186
+ delete next[area];
187
+ return next;
188
+ });
189
+ }, []);
190
+ var captureSiblingWidths = useCallback(function (area) {
191
+ var mode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'inline';
192
+ var baselineWidths = {};
193
+ var overlayModes = {};
194
+ var _iterator = _createForOfIteratorHelper(['side-nav', 'panel', 'chat-panel']),
195
+ _step;
196
+ try {
197
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
198
+ var areaName = _step.value;
199
+ var state = areaStatesRef.current[areaName];
200
+ if (state) {
201
+ overlayModes[areaName] = state.mode;
202
+ }
203
+ if ((state === null || state === void 0 ? void 0 : state.mode) === 'inline') {
204
+ baselineWidths[areaName] = state.width;
205
+ }
206
+ }
207
+ } catch (err) {
208
+ _iterator.e(err);
209
+ } finally {
210
+ _iterator.f();
211
+ }
212
+ return {
213
+ area: area,
214
+ baselineWidths: baselineWidths,
215
+ overlayModes: mode === 'overlay' ? overlayModes : undefined
216
+ };
217
+ }, []);
218
+ var startResize = useCallback(function (area, mode) {
219
+ setHasInteraction(true);
220
+ setResizeSession(captureSiblingWidths(area, mode));
221
+
222
+ // Start from the effective width, which may already be compressed below the preferred width.
223
+ // Reapplying the preferred width here would move the splitter away from the pointer.
224
+ var renderedState = areaStatesRef.current[area];
225
+ if ((renderedState === null || renderedState === void 0 ? void 0 : renderedState.mode) === mode) {
226
+ setAreas(function (current) {
227
+ var existing = current[area];
228
+ return existing ? _objectSpread(_objectSpread({}, current), {}, _defineProperty({}, area, _objectSpread(_objectSpread({}, existing), {}, {
229
+ liveResize: {
230
+ mode: mode,
231
+ width: renderedState.width
232
+ }
233
+ }))) : current;
234
+ });
235
+ }
236
+ }, [captureSiblingWidths]);
237
+ var resize = useCallback(function (area, mode, width) {
238
+ setAreas(function (current) {
239
+ var _existing$liveResize;
240
+ var existing = current[area];
241
+ if ((existing === null || existing === void 0 || (_existing$liveResize = existing.liveResize) === null || _existing$liveResize === void 0 ? void 0 : _existing$liveResize.mode) === mode && existing.liveResize.width === width) {
242
+ return current;
243
+ }
244
+ return existing ? _objectSpread(_objectSpread({}, current), {}, _defineProperty({}, area, _objectSpread(_objectSpread({}, existing), {}, {
245
+ liveResize: {
246
+ mode: mode,
247
+ width: width
248
+ }
249
+ }))) : current;
250
+ });
251
+ }, []);
252
+ var completeResize = useCallback(function (area, mode, width) {
253
+ setHasInteraction(true);
254
+ if (mode === 'overlay') {
255
+ var session = inputsRef.current.resizeSession;
256
+ setResizeSession(_objectSpread(_objectSpread({}, (session === null || session === void 0 ? void 0 : session.area) === area && session.overlayModes ? session : captureSiblingWidths(area, mode)), {}, {
257
+ completedWidth: width
258
+ }));
259
+ }
260
+ if (mode === 'inline') {
261
+ var _inputs$resizeSession, _inputs$areas$area;
262
+ var inputs = inputsRef.current;
263
+ var _session = ((_inputs$resizeSession = inputs.resizeSession) === null || _inputs$resizeSession === void 0 ? void 0 : _inputs$resizeSession.area) === area && (_inputs$areas$area = inputs.areas[area]) !== null && _inputs$areas$area !== void 0 && _inputs$areas$area.liveResize ? inputs.resizeSession : captureSiblingWidths(area);
264
+ var existing = inputs.areas[area];
265
+ if (inputs.dimensions && existing) {
266
+ // Keyboard completion has no preview; calculate it using the accepted
267
+ // request, not the parent's previous controlled width. Pointer completion
268
+ // keeps below-minimum cascade results even though its payload is clamped.
269
+ var completed = existing.liveResize ? areaStatesRef.current : calculateLayoutAreaStates(_objectSpread(_objectSpread({}, inputs.dimensions), {}, {
270
+ occupiedWidth: inputs.occupiedWidth,
271
+ mainMinWidth: inputs.mainMinWidth,
272
+ areas: _objectSpread(_objectSpread({}, inputs.areas), {}, _defineProperty({}, area, _objectSpread(_objectSpread({}, existing), {}, {
273
+ liveResize: {
274
+ mode: mode,
275
+ width: width
276
+ }
277
+ }))),
278
+ resizeSession: _session
279
+ }));
280
+ var completedWidths = {};
281
+ var _iterator2 = _createForOfIteratorHelper(['side-nav', 'panel', 'chat-panel']),
282
+ _step2;
283
+ try {
284
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
285
+ var _completed$name;
286
+ var name = _step2.value;
287
+ if (((_completed$name = completed[name]) === null || _completed$name === void 0 ? void 0 : _completed$name.mode) === 'inline') {
288
+ completedWidths[name] = completed[name].width;
289
+ }
290
+ }
291
+ } catch (err) {
292
+ _iterator2.e(err);
293
+ } finally {
294
+ _iterator2.f();
295
+ }
296
+ setResizeSession(_objectSpread(_objectSpread({}, _session), {}, {
297
+ completedWidth: width,
298
+ completedWidths: completedWidths
299
+ }));
300
+ }
301
+ }
302
+ setAreas(function (current) {
303
+ var existing = current[area];
304
+ if (!existing) {
305
+ return current;
306
+ }
307
+ if (mode === 'overlay') {
308
+ return _objectSpread(_objectSpread({}, current), {}, _defineProperty({}, area, _objectSpread(_objectSpread({}, existing), {}, {
309
+ liveResize: undefined,
310
+ preferredOverlayWidth: width
311
+ })));
312
+ }
313
+ return _objectSpread(_objectSpread({}, current), {}, _defineProperty({}, area, _objectSpread(_objectSpread({}, existing), {}, {
314
+ liveResize: undefined,
315
+ preferredInlineWidth: width
316
+ })));
317
+ });
318
+ }, [captureSiblingWidths]);
319
+ useEffect(function () {
320
+ // Loading the interaction engine is not a layout event. Adopt the CSS layout
321
+ // without changing widths or modes; subsequent changes to configuration or
322
+ // available space may redistribute it. Content stays mounted during the handoff.
323
+ var root = layoutRef === null || layoutRef === void 0 ? void 0 : layoutRef.current;
324
+ if (onUpdate && root && dimensions && isPreservingInitialLayout) {
325
+ var measured = {};
326
+ var selectors = {
327
+ 'side-nav': ':scope > nav[data-layout-slot]',
328
+ panel: '[data-layout-with-panel-slot]',
329
+ 'chat-panel': ':scope > [data-layout-chat-panel]'
330
+ };
331
+ var _iterator3 = _createForOfIteratorHelper(['side-nav', 'panel', 'chat-panel']),
332
+ _step3;
333
+ try {
334
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
335
+ var name = _step3.value;
336
+ var element = root.querySelector(selectors[name]);
337
+ var config = areas[name];
338
+ if (!element || !(config !== null && config !== void 0 && config.isOpen)) {
339
+ continue;
340
+ }
341
+ var style = getComputedStyle(element);
342
+ var mode = style.gridArea.split('/')[0].trim() === name ? 'inline' : 'overlay';
343
+ measured[name] = {
344
+ mode: mode,
345
+ width: element.getBoundingClientRect().width,
346
+ minWidth: resolveLayoutWidth(config.minWidth, dimensions.viewportWidth)
347
+ };
348
+ }
349
+ } catch (err) {
350
+ _iterator3.e(err);
351
+ } finally {
352
+ _iterator3.f();
353
+ }
354
+ setInitialStates(measured);
355
+ }
356
+ }, [areas, dimensions, isPreservingInitialLayout, layoutRef, onUpdate]);
357
+ var areaStates = useMemo(function () {
358
+ var _initialStates$sideN, _initialStates$panel, _initialStates$chatP;
359
+ if (!dimensions) {
360
+ return {};
361
+ }
362
+ var allocated = calculateLayoutAreaStates(_objectSpread(_objectSpread({}, dimensions), {}, {
363
+ occupiedWidth: occupiedWidth,
364
+ mainMinWidth: mainMinWidth,
365
+ areas: areas,
366
+ resizeSession: resizeSession,
367
+ initialModes: onUpdate && layoutRef !== null && layoutRef !== void 0 && layoutRef.current && isPreservingInitialLayout ? {
368
+ 'side-nav': (_initialStates$sideN = initialStates['side-nav']) === null || _initialStates$sideN === void 0 ? void 0 : _initialStates$sideN.mode,
369
+ panel: (_initialStates$panel = initialStates.panel) === null || _initialStates$panel === void 0 ? void 0 : _initialStates$panel.mode,
370
+ 'chat-panel': (_initialStates$chatP = initialStates['chat-panel']) === null || _initialStates$chatP === void 0 ? void 0 : _initialStates$chatP.mode
371
+ } : undefined
372
+ }));
373
+ if (onUpdate && layoutRef !== null && layoutRef !== void 0 && layoutRef.current && isPreservingInitialLayout) {
374
+ var _iterator4 = _createForOfIteratorHelper(['side-nav', 'panel', 'chat-panel']),
375
+ _step4;
376
+ try {
377
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
378
+ var name = _step4.value;
379
+ if (initialStates[name] && allocated[name]) {
380
+ allocated[name] = _objectSpread(_objectSpread({}, allocated[name]), initialStates[name]);
381
+ } else {
382
+ delete allocated[name];
383
+ }
384
+ }
385
+ } catch (err) {
386
+ _iterator4.e(err);
387
+ } finally {
388
+ _iterator4.f();
389
+ }
390
+ }
391
+ return allocated;
392
+ }, [areas, mainMinWidth, resizeSession, dimensions, occupiedWidth, isPreservingInitialLayout, initialStates, layoutRef, onUpdate]);
393
+ useEffect(function () {
394
+ var _areas$sideNav;
395
+ if (hasInteraction && (resizeSession === null || resizeSession === void 0 ? void 0 : resizeSession.area) !== 'side-nav' && (_areas$sideNav = areas['side-nav']) !== null && _areas$sideNav !== void 0 && _areas$sideNav.isOpen && !areaStates['side-nav'] && dimensions) {
396
+ var _areas$sideNav$onReq, _areas$sideNav2;
397
+ (_areas$sideNav$onReq = (_areas$sideNav2 = areas['side-nav']).onRequestClose) === null || _areas$sideNav$onReq === void 0 || _areas$sideNav$onReq.call(_areas$sideNav2);
398
+ }
399
+ }, [areaStates, areas, dimensions, hasInteraction, resizeSession]);
400
+ useEffect(function () {
401
+ areaStatesRef.current = areaStates;
402
+ }, [areaStates]);
403
+
404
+ // Read bounds lazily: changing a sibling's capacity must not publish new render
405
+ // state or recreate drag listeners for a region whose own width did not change.
406
+ var getResizeBounds = useCallback(function (area) {
407
+ var _areaStatesRef$curren;
408
+ var bounds = (_areaStatesRef$curren = areaStatesRef.current[area]) === null || _areaStatesRef$curren === void 0 ? void 0 : _areaStatesRef$curren.resizeBounds;
409
+ return bounds ? {
410
+ min: "".concat(bounds.min, "px"),
411
+ max: "".concat(bounds.max, "px")
412
+ } : undefined;
413
+ }, []);
414
+ var value = useMemo(function () {
415
+ return {
416
+ getResizeBounds: getResizeBounds,
417
+ registerArea: registerArea,
418
+ unregisterArea: unregisterArea,
419
+ startResize: startResize,
420
+ resize: resize,
421
+ completeResize: completeResize,
422
+ setMainMinWidth: setMainMinWidth
423
+ };
424
+ }, [completeResize, getResizeBounds, registerArea, resize, startResize, unregisterArea]);
425
+ var sideNavState = useStableAreaState(areaStates['side-nav']);
426
+ var panelState = useStableAreaState(areaStates.panel);
427
+ var chatPanelState = useStableAreaState(areaStates['chat-panel']);
428
+ var SideNavStateProvider = layoutAreaStateContexts['side-nav'].Provider;
429
+ var PanelStateProvider = layoutAreaStateContexts.panel.Provider;
430
+ var ChatPanelStateProvider = layoutAreaStateContexts['chat-panel'].Provider;
431
+ useEffect(function () {
432
+ onReady === null || onReady === void 0 || onReady(value);
433
+ return function () {
434
+ return onReady === null || onReady === void 0 ? void 0 : onReady(null);
435
+ };
436
+ }, [onReady, value]);
437
+ useEffect(function () {
438
+ if (!adoptedConstraints.current && (sideNavState || panelState || chatPanelState)) {
439
+ adoptedConstraints.current = {
440
+ occupiedWidth: occupiedWidth,
441
+ mainMinWidth: mainMinWidth
442
+ };
443
+ }
444
+ onUpdate === null || onUpdate === void 0 || onUpdate({
445
+ 'side-nav': sideNavState,
446
+ panel: panelState,
447
+ 'chat-panel': chatPanelState
448
+ });
449
+ }, [onUpdate, sideNavState, panelState, chatPanelState, occupiedWidth, mainMinWidth]);
450
+ return /*#__PURE__*/React.createElement(LayoutAreaSizingContext.Provider, {
451
+ value: value
452
+ }, /*#__PURE__*/React.createElement(SideNavStateProvider, {
453
+ value: sideNavState
454
+ }, /*#__PURE__*/React.createElement(PanelStateProvider, {
455
+ value: panelState
456
+ }, /*#__PURE__*/React.createElement(ChatPanelStateProvider, {
457
+ value: chatPanelState
458
+ }, children))));
459
+ }
@@ -6,7 +6,7 @@ import { Fragment } from 'react';
6
6
  import { fg } from '@atlaskit/platform-feature-flags/fg';
7
7
  import { useSkipLink } from '../../../context/skip-links/use-skip-link';
8
8
  import { mainMinimumWidthVar } from '../constants';
9
- import { gridRootId } from '../root';
9
+ import { gridRootFitId, gridRootId } from '../root';
10
10
  import { useLayoutId } from '../use-layout-id';
11
11
  import { useLayoutMainSizing } from '../use-layout-main-sizing';
12
12
  var contentInsetBlockStartStatic = "calc(var(--n_bnrM, 0px) + var(--n_tNvM, 0px))";
@@ -35,7 +35,7 @@ export function Main(_ref) {
35
35
  return /*#__PURE__*/React.createElement(Fragment, null, fg('platform-dst-chat-panel-layout') &&
36
36
  /*#__PURE__*/
37
37
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles
38
- React.createElement("style", null, "#".concat(gridRootId, " { ").concat(mainMinimumWidthVar, ": ").concat(minWidth, "px; }")), /*#__PURE__*/React.createElement("div", {
38
+ React.createElement("style", null, "#".concat(gridRootId, ", #").concat(gridRootFitId, " { ").concat(mainMinimumWidthVar, ": ").concat(minWidth, "px; }")), /*#__PURE__*/React.createElement("div", {
39
39
  id: id,
40
40
  "data-layout-slot": true,
41
41
  className: ax([mainElementStyles.root, xcss]),