@zendeskgarden/react-grid 8.50.0 → 8.52.0

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.
package/dist/index.cjs.js CHANGED
@@ -14,12 +14,57 @@ var PropTypes = require('prop-types');
14
14
  var styled = require('styled-components');
15
15
  var polished = require('polished');
16
16
  var reactTheming = require('@zendeskgarden/react-theming');
17
+ var containerUtilities = require('@zendeskgarden/container-utilities');
18
+ var mergeRefs = require('react-merge-refs');
19
+ var containerSplitter = require('@zendeskgarden/container-splitter');
17
20
 
18
21
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
22
 
20
23
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
21
24
  var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
22
25
  var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
26
+ var mergeRefs__default = /*#__PURE__*/_interopDefaultLegacy(mergeRefs);
27
+
28
+ function ownKeys(object, enumerableOnly) {
29
+ var keys = Object.keys(object);
30
+
31
+ if (Object.getOwnPropertySymbols) {
32
+ var symbols = Object.getOwnPropertySymbols(object);
33
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
34
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
35
+ })), keys.push.apply(keys, symbols);
36
+ }
37
+
38
+ return keys;
39
+ }
40
+
41
+ function _objectSpread2(target) {
42
+ for (var i = 1; i < arguments.length; i++) {
43
+ var source = null != arguments[i] ? arguments[i] : {};
44
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
45
+ _defineProperty(target, key, source[key]);
46
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
47
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
48
+ });
49
+ }
50
+
51
+ return target;
52
+ }
53
+
54
+ function _defineProperty(obj, key, value) {
55
+ if (key in obj) {
56
+ Object.defineProperty(obj, key, {
57
+ value: value,
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true
61
+ });
62
+ } else {
63
+ obj[key] = value;
64
+ }
65
+
66
+ return obj;
67
+ }
23
68
 
24
69
  function _extends() {
25
70
  _extends = Object.assign || function (target) {
@@ -75,6 +120,65 @@ function _objectWithoutProperties(source, excluded) {
75
120
  return target;
76
121
  }
77
122
 
123
+ function _slicedToArray(arr, i) {
124
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
125
+ }
126
+
127
+ function _arrayWithHoles(arr) {
128
+ if (Array.isArray(arr)) return arr;
129
+ }
130
+
131
+ function _iterableToArrayLimit(arr, i) {
132
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
133
+
134
+ if (_i == null) return;
135
+ var _arr = [];
136
+ var _n = true;
137
+ var _d = false;
138
+
139
+ var _s, _e;
140
+
141
+ try {
142
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
143
+ _arr.push(_s.value);
144
+
145
+ if (i && _arr.length === i) break;
146
+ }
147
+ } catch (err) {
148
+ _d = true;
149
+ _e = err;
150
+ } finally {
151
+ try {
152
+ if (!_n && _i["return"] != null) _i["return"]();
153
+ } finally {
154
+ if (_d) throw _e;
155
+ }
156
+ }
157
+
158
+ return _arr;
159
+ }
160
+
161
+ function _unsupportedIterableToArray(o, minLen) {
162
+ if (!o) return;
163
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
164
+ var n = Object.prototype.toString.call(o).slice(8, -1);
165
+ if (n === "Object" && o.constructor) n = o.constructor.name;
166
+ if (n === "Map" || n === "Set") return Array.from(o);
167
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
168
+ }
169
+
170
+ function _arrayLikeToArray(arr, len) {
171
+ if (len == null || len > arr.length) len = arr.length;
172
+
173
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
174
+
175
+ return arr2;
176
+ }
177
+
178
+ function _nonIterableRest() {
179
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
180
+ }
181
+
78
182
  var ALIGN_ITEMS = ['start', 'end', 'center', 'baseline', 'stretch'];
79
183
  var ALIGN_SELF = ['auto'].concat(ALIGN_ITEMS);
80
184
  var DIRECTION = ['row', 'row-reverse', 'column', 'column-reverse'];
@@ -82,9 +186,10 @@ var JUSTIFY_CONTENT = ['start', 'end', 'center', 'between', 'around'];
82
186
  var TEXT_ALIGN = ['start', 'end', 'center', 'justify'];
83
187
  var SPACE = [false, 'xxs', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl'];
84
188
  var WRAP = ['nowrap', 'wrap', 'wrap-reverse'];
189
+ var ORIENTATION = ['top', 'bottom', 'start', 'end'];
85
190
 
86
- var COMPONENT_ID$2 = 'grid.col';
87
- var colorStyles$2 = function colorStyles(props) {
191
+ var COMPONENT_ID$5 = 'grid.col';
192
+ var colorStyles$3 = function colorStyles(props) {
88
193
  var backgroundColor = reactTheming.getColor('primaryHue', 600, props.theme, 0.1);
89
194
  return styled.css(["background-clip:content-box;background-color:", ";"], backgroundColor);
90
195
  };
@@ -129,22 +234,22 @@ var flexStyles$1 = function flexStyles(size, alignSelf, textAlign, offset, order
129
234
  var mediaStyles$1 = function mediaStyles(minWidth, size, alignSelf, textAlign, offset, order, props) {
130
235
  return styled.css(["@media (min-width:", "){", ";}"], minWidth, flexStyles$1(size, alignSelf, textAlign, offset, order, props));
131
236
  };
132
- var sizeStyles$2 = function sizeStyles(props) {
237
+ var sizeStyles$3 = function sizeStyles(props) {
133
238
  var padding = props.gutters ? polished.math("".concat(props.theme.space[props.gutters], " / 2")) : 0;
134
239
  return styled.css(["padding-right:", ";padding-left:", ";"], padding, padding);
135
240
  };
136
241
  var StyledCol = styled__default["default"].div.attrs({
137
- 'data-garden-id': COMPONENT_ID$2,
138
- 'data-garden-version': '8.50.0'
242
+ 'data-garden-id': COMPONENT_ID$5,
243
+ 'data-garden-version': '8.52.0'
139
244
  }).withConfig({
140
245
  displayName: "StyledCol",
141
246
  componentId: "sc-inuw62-0"
142
247
  })(["box-sizing:border-box;width:100%;", ";", ";", ";", ";", ";", ";", ";", ";", ";"], function (props) {
143
248
  return flexStyles$1(!props.sizeAll && (props.xs || props.sm || props.md || props.lg || props.xl) ? undefined : props.sizeAll || false, props.alignSelf, props.textAlign, props.offset, props.order, props);
144
249
  }, function (props) {
145
- return sizeStyles$2(props);
250
+ return sizeStyles$3(props);
146
251
  }, function (props) {
147
- return props.debug && colorStyles$2(props);
252
+ return props.debug && colorStyles$3(props);
148
253
  }, function (props) {
149
254
  return mediaStyles$1(props.theme.breakpoints.xs, props.xs, props.alignSelfXs, props.textAlignXs, props.offsetXs, props.orderXs, props);
150
255
  }, function (props) {
@@ -156,45 +261,45 @@ var StyledCol = styled__default["default"].div.attrs({
156
261
  }, function (props) {
157
262
  return mediaStyles$1(props.theme.breakpoints.xl, props.xl, props.alignSelfXl, props.textAlignXl, props.offsetXl, props.orderXl, props);
158
263
  }, function (props) {
159
- return reactTheming.retrieveComponentStyles(COMPONENT_ID$2, props);
264
+ return reactTheming.retrieveComponentStyles(COMPONENT_ID$5, props);
160
265
  });
161
266
  StyledCol.defaultProps = {
162
267
  columns: 12,
163
268
  theme: reactTheming.DEFAULT_THEME
164
269
  };
165
270
 
166
- var COMPONENT_ID$1 = 'grid.grid';
167
- var colorStyles$1 = function colorStyles(props) {
271
+ var COMPONENT_ID$4 = 'grid.grid';
272
+ var colorStyles$2 = function colorStyles(props) {
168
273
  var borderColor = reactTheming.getColor(props.theme.palette.crimson, 400, props.theme, 0.5);
169
274
  var borderWidth = polished.math("".concat(props.theme.borderWidths.sm, " * 2"));
170
275
  return styled.css(["box-shadow:-", " 0 0 0 ", ",", " 0 0 0 ", ";"], borderWidth, borderColor, borderWidth, borderColor);
171
276
  };
172
- var sizeStyles$1 = function sizeStyles(props) {
277
+ var sizeStyles$2 = function sizeStyles(props) {
173
278
  var padding = props.gutters ? polished.math("".concat(props.theme.space[props.gutters], " / 2")) : 0;
174
279
  return styled.css(["padding-right:", ";padding-left:", ";"], padding, padding);
175
280
  };
176
281
  var StyledGrid = styled__default["default"].div.attrs({
177
- 'data-garden-id': COMPONENT_ID$1,
178
- 'data-garden-version': '8.50.0'
282
+ 'data-garden-id': COMPONENT_ID$4,
283
+ 'data-garden-version': '8.52.0'
179
284
  }).withConfig({
180
285
  displayName: "StyledGrid",
181
286
  componentId: "sc-oxgg5i-0"
182
287
  })(["direction:", ";margin-right:auto;margin-left:auto;width:100%;box-sizing:border-box;", ";", ";", ";"], function (props) {
183
288
  return props.theme.rtl && 'rtl';
184
289
  }, function (props) {
185
- return sizeStyles$1(props);
290
+ return sizeStyles$2(props);
186
291
  }, function (props) {
187
- return props.debug && colorStyles$1(props);
292
+ return props.debug && colorStyles$2(props);
188
293
  }, function (props) {
189
- return reactTheming.retrieveComponentStyles(COMPONENT_ID$1, props);
294
+ return reactTheming.retrieveComponentStyles(COMPONENT_ID$4, props);
190
295
  });
191
296
  StyledGrid.defaultProps = {
192
297
  gutters: 'md',
193
298
  theme: reactTheming.DEFAULT_THEME
194
299
  };
195
300
 
196
- var COMPONENT_ID = 'grid.row';
197
- var colorStyles = function colorStyles(props) {
301
+ var COMPONENT_ID$3 = 'grid.row';
302
+ var colorStyles$1 = function colorStyles(props) {
198
303
  var borderColor = reactTheming.getColor(props.theme.palette.mint, 600, props.theme, 0.5);
199
304
  var borderWidth = props.theme.borderWidths.sm;
200
305
  return styled.css(["box-shadow:inset 0 ", " 0 0 ", ",inset 0 -", " 0 0 ", ";"], borderWidth, borderColor, borderWidth, borderColor);
@@ -219,22 +324,22 @@ var flexStyles = function flexStyles(alignItems, justifyContent, wrap) {
219
324
  var mediaStyles = function mediaStyles(minWidth, alignItems, justifyContent, wrap) {
220
325
  return styled.css(["@media (min-width:", "){", ";}"], minWidth, flexStyles(alignItems, justifyContent, wrap));
221
326
  };
222
- var sizeStyles = function sizeStyles(props) {
327
+ var sizeStyles$1 = function sizeStyles(props) {
223
328
  var margin = props.gutters ? polished.math("".concat(props.theme.space[props.gutters], " / 2")) : 0;
224
329
  return styled.css(["margin-right:-", ";margin-left:-", ";"], margin, margin);
225
330
  };
226
331
  var StyledRow = styled__default["default"].div.attrs({
227
- 'data-garden-id': COMPONENT_ID,
228
- 'data-garden-version': '8.50.0'
332
+ 'data-garden-id': COMPONENT_ID$3,
333
+ 'data-garden-version': '8.52.0'
229
334
  }).withConfig({
230
335
  displayName: "StyledRow",
231
336
  componentId: "sc-xjsdg1-0"
232
337
  })(["display:flex;box-sizing:border-box;", " ", ";", ";", ";", ";", ";", ";", ";", ";"], function (props) {
233
338
  return flexStyles(props.alignItems, props.justifyContent, props.wrapAll);
234
339
  }, function (props) {
235
- return sizeStyles(props);
340
+ return sizeStyles$1(props);
236
341
  }, function (props) {
237
- return props.debug && colorStyles(props);
342
+ return props.debug && colorStyles$1(props);
238
343
  }, function (props) {
239
344
  return mediaStyles(props.theme.breakpoints.xs, props.alignItemsXs, props.justifyContentXs, props.wrapXs);
240
345
  }, function (props) {
@@ -246,13 +351,120 @@ var StyledRow = styled__default["default"].div.attrs({
246
351
  }, function (props) {
247
352
  return mediaStyles(props.theme.breakpoints.xl, props.alignItemsXl, props.justifyContentXl, props.wrapXl);
248
353
  }, function (props) {
249
- return reactTheming.retrieveComponentStyles(COMPONENT_ID, props);
354
+ return reactTheming.retrieveComponentStyles(COMPONENT_ID$3, props);
250
355
  });
251
356
  StyledRow.defaultProps = {
252
357
  wrapAll: 'wrap',
253
358
  theme: reactTheming.DEFAULT_THEME
254
359
  };
255
360
 
361
+ var COMPONENT_ID$2 = 'pane';
362
+ var StyledPane = styled__default["default"].div.attrs({
363
+ 'data-garden-id': COMPONENT_ID$2,
364
+ 'data-garden-version': '8.52.0'
365
+ }).withConfig({
366
+ displayName: "StyledPane",
367
+ componentId: "sc-1ltjst7-0"
368
+ })(["position:relative;min-width:0;min-height:0;", ";"], function (props) {
369
+ return reactTheming.retrieveComponentStyles(COMPONENT_ID$2, props);
370
+ });
371
+ StyledPane.defaultProps = {
372
+ theme: reactTheming.DEFAULT_THEME
373
+ };
374
+
375
+ var COMPONENT_ID$1 = 'pane.content';
376
+ var StyledPaneContent = styled__default["default"].div.attrs({
377
+ 'data-garden-id': COMPONENT_ID$1,
378
+ 'data-garden-version': '8.52.0'
379
+ }).withConfig({
380
+ displayName: "StyledPaneContent",
381
+ componentId: "sc-1b38mbh-0"
382
+ })(["height:100%;overflow:auto;", ";"], function (props) {
383
+ return reactTheming.retrieveComponentStyles(COMPONENT_ID$1, props);
384
+ });
385
+ StyledPaneContent.defaultProps = {
386
+ theme: reactTheming.DEFAULT_THEME
387
+ };
388
+
389
+ var COMPONENT_ID = 'pane.splitter';
390
+ var colorStyles = function colorStyles(props) {
391
+ var color = reactTheming.getColor('neutralHue', 300, props.theme);
392
+ var hoverColor = reactTheming.getColor('primaryHue', 600, props.theme);
393
+ var activeColor = reactTheming.getColor('primaryHue', 800, props.theme);
394
+ var boxShadow = props.theme.shadows.md(polished.rgba(hoverColor, 0.35));
395
+ return styled.css(["&::before{background-color:", ";}&:hover::before,&[data-garden-focus-visible]::before{background-color:", ";}&[data-garden-focus-visible]::before{box-shadow:", ";}&:active::before{background-color:", ";}"], color, hoverColor, boxShadow, activeColor);
396
+ };
397
+ var sizeStyles = function sizeStyles(props) {
398
+ var size = polished.math("".concat(props.theme.shadowWidths.md, " * 2"));
399
+ var offset = polished.math("-".concat(size, " / 2"));
400
+ var cursor;
401
+ var top;
402
+ var right;
403
+ var left;
404
+ var bottom;
405
+ var width;
406
+ var height;
407
+ var separatorWidth;
408
+ var separatorHeight;
409
+ switch (props.orientation) {
410
+ case 'top':
411
+ cursor = 'row-resize';
412
+ top = offset;
413
+ width = '100%';
414
+ height = size;
415
+ separatorWidth = width;
416
+ separatorHeight = props.theme.borderWidths.sm;
417
+ break;
418
+ case 'end':
419
+ cursor = 'col-resize';
420
+ top = 0;
421
+ width = size;
422
+ height = '100%';
423
+ separatorWidth = props.theme.borderWidths.sm;
424
+ separatorHeight = height;
425
+ if (props.theme.rtl) {
426
+ left = offset;
427
+ } else {
428
+ right = offset;
429
+ }
430
+ break;
431
+ case 'bottom':
432
+ cursor = 'row-resize';
433
+ bottom = offset;
434
+ width = '100%';
435
+ height = size;
436
+ separatorWidth = width;
437
+ separatorHeight = props.theme.borderWidths.sm;
438
+ break;
439
+ case 'start':
440
+ cursor = 'col-resize';
441
+ top = 0;
442
+ width = size;
443
+ height = '100%';
444
+ separatorWidth = props.theme.borderWidths.sm;
445
+ separatorHeight = height;
446
+ if (props.theme.rtl) {
447
+ right = offset;
448
+ } else {
449
+ left = offset;
450
+ }
451
+ break;
452
+ }
453
+ return styled.css(["display:flex;top:", ";right:", ";bottom:", ";left:", ";cursor:", ";width:", ";height:", ";&::before{transition:box-shadow 0.1s ease-in-out,background-color 0.25s ease-in-out,width 0.25s ease-in-out,height 0.25s ease-in-out;margin:auto;width:", ";height:", ";}&:hover::before,&[data-garden-focus-visible]::before,&:focus::before{", ":", ";}&[data-garden-focus-visible]::before{border-radius:", ";}"], top, right, bottom, left, cursor, width, height, separatorWidth, separatorHeight, width === '100%' ? 'height' : 'width', polished.math("".concat(props.theme.borderWidths.sm, " * 2")), props.theme.borderRadii.md);
454
+ };
455
+ var StyledPaneSplitter = styled__default["default"].div.attrs({
456
+ 'data-garden-id': COMPONENT_ID,
457
+ 'data-garden-version': '8.52.0'
458
+ }).withConfig({
459
+ displayName: "StyledPaneSplitter",
460
+ componentId: "sc-jylemn-0"
461
+ })(["position:absolute;z-index:1;user-select:none;", ";&:hover,&[data-garden-focus-visible]{z-index:2;}&:focus{outline:none;}&::before{display:block;content:'';}", ";", ";"], sizeStyles, colorStyles, function (props) {
462
+ return reactTheming.retrieveComponentStyles(COMPONENT_ID, props);
463
+ });
464
+ StyledPaneSplitter.defaultProps = {
465
+ theme: reactTheming.DEFAULT_THEME
466
+ };
467
+
256
468
  var GridContext = React.createContext({
257
469
  gutters: 'md'
258
470
  });
@@ -260,10 +472,10 @@ var useGridContext = function useGridContext() {
260
472
  return React.useContext(GridContext);
261
473
  };
262
474
 
263
- var _excluded$2 = ["size"];
475
+ var _excluded$4 = ["size"];
264
476
  var Col = React__default["default"].forwardRef(function (_ref, ref) {
265
477
  var size = _ref.size,
266
- props = _objectWithoutProperties(_ref, _excluded$2);
478
+ props = _objectWithoutProperties(_ref, _excluded$4);
267
479
  var _useGridContext = useGridContext(),
268
480
  columns = _useGridContext.columns,
269
481
  gutters = _useGridContext.gutters,
@@ -310,11 +522,11 @@ Col.propTypes = {
310
522
  orderXl: PropTypes__default["default"].oneOfType([PropTypes__default["default"].number, PropTypes__default["default"].string])
311
523
  };
312
524
 
313
- var _excluded$1 = ["columns", "debug"];
525
+ var _excluded$3 = ["columns", "debug"];
314
526
  var Grid = React__default["default"].forwardRef(function (_ref, ref) {
315
527
  var columns = _ref.columns,
316
528
  debug = _ref.debug,
317
- props = _objectWithoutProperties(_ref, _excluded$1);
529
+ props = _objectWithoutProperties(_ref, _excluded$3);
318
530
  var value = React.useMemo(function () {
319
531
  return {
320
532
  columns: columns,
@@ -340,10 +552,10 @@ Grid.defaultProps = {
340
552
  gutters: 'md'
341
553
  };
342
554
 
343
- var _excluded = ["wrap"];
555
+ var _excluded$2 = ["wrap"];
344
556
  var Row = React__default["default"].forwardRef(function (_ref, ref) {
345
557
  var wrap = _ref.wrap,
346
- props = _objectWithoutProperties(_ref, _excluded);
558
+ props = _objectWithoutProperties(_ref, _excluded$2);
347
559
  var _useGridContext = useGridContext(),
348
560
  gutters = _useGridContext.gutters,
349
561
  debug = _useGridContext.debug;
@@ -376,6 +588,334 @@ Row.propTypes = {
376
588
  wrapXl: PropTypes__default["default"].oneOf(WRAP)
377
589
  };
378
590
 
591
+ var PaneProviderContext = React.createContext({});
592
+ var usePaneProviderContextData = function usePaneProviderContextData(providerId) {
593
+ var context = React.useContext(PaneProviderContext);
594
+ var id = providerId || context.providerId;
595
+ return id && context.contextData ? context.contextData[id] : undefined;
596
+ };
597
+ var usePaneProviderContext = function usePaneProviderContext() {
598
+ return React.useContext(PaneProviderContext);
599
+ };
600
+
601
+ var getPixelsPerFr = function getPixelsPerFr(totalFrs, totalDimension) {
602
+ return totalDimension / totalFrs;
603
+ };
604
+ var convertToPixels = function convertToPixels(values, pixelsPerFr) {
605
+ return Object.entries(values).reduce(function (prev, _ref) {
606
+ var _ref2 = _slicedToArray(_ref, 2),
607
+ key = _ref2[0],
608
+ value = _ref2[1];
609
+ prev[key] = value * pixelsPerFr;
610
+ return prev;
611
+ }, {});
612
+ };
613
+ var PaneProvider = function PaneProvider(_ref3) {
614
+ var id = _ref3.id,
615
+ totalPanesWidth = _ref3.totalPanesWidth,
616
+ totalPanesHeight = _ref3.totalPanesHeight,
617
+ defaultRowValues = _ref3.defaultRowValues,
618
+ defaultColumnValues = _ref3.defaultColumnValues,
619
+ rowValues = _ref3.rowValues,
620
+ columnValues = _ref3.columnValues,
621
+ onChange = _ref3.onChange,
622
+ children = _ref3.children;
623
+ var isControlled = rowValues !== undefined && rowValues !== null && columnValues !== undefined && columnValues !== null;
624
+ var _useState = React.useState(defaultRowValues || {}),
625
+ _useState2 = _slicedToArray(_useState, 2),
626
+ rowState = _useState2[0],
627
+ setRowState = _useState2[1];
628
+ var _useState3 = React.useState(defaultColumnValues || {}),
629
+ _useState4 = _slicedToArray(_useState3, 2),
630
+ columnState = _useState4[0],
631
+ setColumnState = _useState4[1];
632
+ var rowsTrack = isControlled ? rowValues : rowState;
633
+ var columnsTrack = isControlled ? columnValues : columnState;
634
+ var setRowsTrack = React.useCallback(function (values) {
635
+ if (isControlled && onChange) {
636
+ return onChange(values(rowsTrack), columnsTrack);
637
+ }
638
+ return setRowState(values);
639
+ }, [isControlled, onChange, setRowState, columnsTrack, rowsTrack]);
640
+ var setColumnsTrack = React.useCallback(function (values) {
641
+ if (isControlled && onChange) {
642
+ return onChange(rowsTrack, values(columnsTrack));
643
+ }
644
+ return setColumnState(values);
645
+ }, [isControlled, onChange, setColumnState, rowsTrack, columnsTrack]);
646
+ var totalFractions = React.useMemo(function () {
647
+ return {
648
+ rows: Object.values(rowsTrack).reduce(function (prev, value) {
649
+ return value + prev;
650
+ }, 0),
651
+ columns: Object.values(columnsTrack).reduce(function (prev, value) {
652
+ return value + prev;
653
+ }, 0)
654
+ };
655
+ }, [rowsTrack, columnsTrack]);
656
+ var pixelsPerFr = React.useMemo(function () {
657
+ return {
658
+ rows: getPixelsPerFr(totalFractions.rows, totalPanesHeight),
659
+ columns: getPixelsPerFr(totalFractions.columns, totalPanesWidth)
660
+ };
661
+ }, [totalFractions, totalPanesHeight, totalPanesWidth]);
662
+ var layoutStateInPixels = React.useMemo(function () {
663
+ return {
664
+ rows: convertToPixels(rowsTrack, pixelsPerFr.rows),
665
+ columns: convertToPixels(columnsTrack, pixelsPerFr.columns)
666
+ };
667
+ }, [rowsTrack, columnsTrack, pixelsPerFr]);
668
+ var layoutIndices = React.useMemo(function () {
669
+ var rowArray = Object.keys(rowsTrack);
670
+ var columnArray = Object.keys(columnsTrack);
671
+ var rows = rowArray.reduce(function (prev, key, index) {
672
+ prev[key] = index;
673
+ return prev;
674
+ }, {});
675
+ var columns = columnArray.reduce(function (prev, key, index) {
676
+ prev[key] = index;
677
+ return prev;
678
+ }, {});
679
+ return {
680
+ rows: rows,
681
+ columns: columns,
682
+ rowArray: rowArray,
683
+ columnArray: columnArray
684
+ };
685
+ }, [rowsTrack, columnsTrack]);
686
+ var setRowValue = React.useCallback(function (isTop, splitterId, value) {
687
+ var rows = layoutIndices.rows,
688
+ rowArray = layoutIndices.rowArray;
689
+ var stealFromTraversal = isTop ? -1 : 1;
690
+ var addToTraversal = 0;
691
+ setRowsTrack(function (state) {
692
+ var oldValue = rowsTrack[splitterId];
693
+ var stealFromIndex = rows[splitterId] + stealFromTraversal;
694
+ var addToIndex = rows[splitterId] + addToTraversal;
695
+ var stealFromKey = rowArray[stealFromIndex];
696
+ var addToKey = rowArray[addToIndex];
697
+ var difference = oldValue - value;
698
+ var nextState = _objectSpread2({}, state);
699
+ nextState[addToKey] = rowsTrack[addToKey] - difference;
700
+ nextState[stealFromKey] = rowsTrack[stealFromKey] + difference;
701
+ return nextState;
702
+ });
703
+ }, [layoutIndices, rowsTrack, setRowsTrack]);
704
+ var setColumnValue = React.useCallback(function (isStart, splitterId, value) {
705
+ var columns = layoutIndices.columns,
706
+ columnArray = layoutIndices.columnArray;
707
+ var stealFromTraversal = isStart ? 0 : 1;
708
+ var addToTraversal = isStart ? -1 : 0;
709
+ setColumnsTrack(function (state) {
710
+ var stealFromIndex = columns[splitterId] + stealFromTraversal;
711
+ var addToIndex = columns[splitterId] + addToTraversal;
712
+ var oldValue = columnsTrack[splitterId];
713
+ var stealFromKey = columnArray[stealFromIndex];
714
+ var addToKey = columnArray[addToIndex];
715
+ var difference = oldValue - value;
716
+ var nextState = _objectSpread2({}, state);
717
+ nextState[addToKey] = columnsTrack[addToKey] - difference;
718
+ nextState[stealFromKey] = columnsTrack[stealFromKey] + difference;
719
+ return nextState;
720
+ });
721
+ }, [layoutIndices, columnsTrack, setColumnsTrack]);
722
+ var getColumnValue = React.useCallback(function (splitterKey, isPixels) {
723
+ if (isPixels) {
724
+ return layoutStateInPixels.columns[splitterKey];
725
+ }
726
+ return columnsTrack[splitterKey];
727
+ }, [columnsTrack, layoutStateInPixels]);
728
+ var getRowValue = React.useCallback(function (splitterKey, isPixels) {
729
+ if (isPixels) {
730
+ return layoutStateInPixels.rows[splitterKey];
731
+ }
732
+ return rowsTrack[splitterKey];
733
+ }, [rowsTrack, layoutStateInPixels]);
734
+ var getGridTemplateColumns = React.useCallback(function (isPixels) {
735
+ var columnArray = layoutIndices.columnArray;
736
+ if (isPixels) {
737
+ return columnArray.map(function (col) {
738
+ return "".concat(layoutStateInPixels.columns[col], "px");
739
+ }).join(' ');
740
+ }
741
+ return columnArray.map(function (col) {
742
+ return "".concat(columnsTrack[col], "fr");
743
+ }).join(' ');
744
+ }, [layoutIndices, columnsTrack, layoutStateInPixels]);
745
+ var getGridTemplateRows = React.useCallback(function (isPixels) {
746
+ var rowArray = layoutIndices.rowArray;
747
+ if (isPixels) {
748
+ return rowArray.map(function (row) {
749
+ return "".concat(layoutStateInPixels.rows[row], "px");
750
+ }).join(' ');
751
+ }
752
+ return rowArray.map(function (row) {
753
+ return "".concat(rowsTrack[row], "fr");
754
+ }).join(' ');
755
+ }, [layoutIndices, rowsTrack, layoutStateInPixels]);
756
+ var providerId = containerUtilities.useId(id);
757
+ var parentPaneProviderContext = usePaneProviderContext();
758
+ var paneProviderContext = React.useMemo(function () {
759
+ return providerId ? {
760
+ providerId: providerId,
761
+ contextData: _objectSpread2(_objectSpread2({}, parentPaneProviderContext.contextData), {}, _defineProperty({}, providerId, {
762
+ columnState: columnState,
763
+ rowState: rowState,
764
+ setRowValue: setRowValue,
765
+ setColumnValue: setColumnValue,
766
+ getRowValue: getRowValue,
767
+ getColumnValue: getColumnValue,
768
+ totalPanesHeight: totalPanesHeight,
769
+ totalPanesWidth: totalPanesWidth,
770
+ pixelsPerFr: pixelsPerFr
771
+ }))
772
+ } : {};
773
+ }, [providerId, parentPaneProviderContext, rowState, columnState, setRowValue, setColumnValue, getRowValue, getColumnValue, totalPanesHeight, totalPanesWidth, pixelsPerFr]);
774
+ return React__default["default"].createElement(PaneProviderContext.Provider, {
775
+ value: paneProviderContext
776
+ }, children === null || children === void 0 ? void 0 : children({
777
+ id: providerId,
778
+ getRowValue: getRowValue,
779
+ getColumnValue: getColumnValue,
780
+ getGridTemplateColumns: getGridTemplateColumns,
781
+ getGridTemplateRows: getGridTemplateRows
782
+ }));
783
+ };
784
+ PaneProvider.displayName = 'PaneProvider';
785
+ PaneProvider.propTypes = {
786
+ id: PropTypes__default["default"].string,
787
+ totalPanesWidth: PropTypes__default["default"].number.isRequired,
788
+ totalPanesHeight: PropTypes__default["default"].number.isRequired,
789
+ defaultRowValues: PropTypes__default["default"].object,
790
+ defaultColumnValues: PropTypes__default["default"].object,
791
+ rowValues: PropTypes__default["default"].object,
792
+ columnValues: PropTypes__default["default"].object,
793
+ onChange: PropTypes__default["default"].func,
794
+ children: PropTypes__default["default"].func
795
+ };
796
+
797
+ var PaneContext = React.createContext({
798
+ setId: function setId() {
799
+ return undefined;
800
+ }
801
+ });
802
+ var usePaneContext = function usePaneContext() {
803
+ return React.useContext(PaneContext);
804
+ };
805
+
806
+ var _excluded$1 = ["providerId", "layoutKey", "min", "max", "orientation"];
807
+ var orientationToPosition = {
808
+ start: containerSplitter.SplitterPosition.TRAILS,
809
+ end: containerSplitter.SplitterPosition.TRAILS,
810
+ top: containerSplitter.SplitterPosition.LEADS,
811
+ bottom: containerSplitter.SplitterPosition.TRAILS
812
+ };
813
+ var paneToSplitterOrientation = {
814
+ start: containerSplitter.SplitterOrientation.VERTICAL,
815
+ end: containerSplitter.SplitterOrientation.VERTICAL,
816
+ top: containerSplitter.SplitterOrientation.HORIZONTAL,
817
+ bottom: containerSplitter.SplitterOrientation.HORIZONTAL
818
+ };
819
+ var orientationToDimension = {
820
+ start: 'columns',
821
+ end: 'columns',
822
+ top: 'rows',
823
+ bottom: 'rows'
824
+ };
825
+ var SplitterComponent = React.forwardRef(function (_ref, ref) {
826
+ var providerId = _ref.providerId,
827
+ layoutKey = _ref.layoutKey,
828
+ min = _ref.min,
829
+ max = _ref.max,
830
+ orientation = _ref.orientation,
831
+ props = _objectWithoutProperties(_ref, _excluded$1);
832
+ var paneProviderContext = usePaneProviderContextData(providerId);
833
+ var paneContext = usePaneContext();
834
+ var themeContext = React.useContext(styled.ThemeContext);
835
+ var position = orientationToPosition[orientation];
836
+ var isRow = orientationToDimension[orientation] === 'rows';
837
+ var splitterOrientation = paneToSplitterOrientation[orientation];
838
+ var pixelsPerFr = paneProviderContext ? paneProviderContext.pixelsPerFr[orientationToDimension[orientation]] : 0;
839
+ var _useSplitter = containerSplitter.useSplitter({
840
+ type: containerSplitter.SplitterType.VARIABLE,
841
+ orientation: splitterOrientation,
842
+ position: position,
843
+ min: min * pixelsPerFr,
844
+ max: max * pixelsPerFr,
845
+ rtl: themeContext.rtl,
846
+ environment: window,
847
+ onChange: function onChange(valueNow) {
848
+ if (isRow) {
849
+ return paneProviderContext && paneProviderContext.setRowValue(orientation === 'top', layoutKey, valueNow / pixelsPerFr);
850
+ }
851
+ return paneProviderContext && paneProviderContext.setColumnValue(orientation === 'start', layoutKey, valueNow / pixelsPerFr);
852
+ },
853
+ valueNow: isRow ? paneProviderContext && paneProviderContext.getRowValue(layoutKey, true) : paneProviderContext && paneProviderContext.getColumnValue(layoutKey, true)
854
+ }),
855
+ getSeparatorProps = _useSplitter.getSeparatorProps,
856
+ getPrimaryPaneProps = _useSplitter.getPrimaryPaneProps;
857
+ React.useEffect(function () {
858
+ if (!paneContext.id) {
859
+ paneContext.setId(getPrimaryPaneProps().id);
860
+ }
861
+ }, [paneContext, getPrimaryPaneProps]);
862
+ var separatorProps = getSeparatorProps({
863
+ 'aria-controls': paneContext.id
864
+ });
865
+ return React__default["default"].createElement(StyledPaneSplitter, _extends({
866
+ orientation: orientation
867
+ }, separatorProps, props, {
868
+ ref: mergeRefs__default["default"]([separatorProps.ref, ref])
869
+ }));
870
+ });
871
+ SplitterComponent.displayName = 'Pane.Splitter';
872
+ SplitterComponent.propTypes = {
873
+ layoutKey: PropTypes__default["default"].string.isRequired,
874
+ min: PropTypes__default["default"].number.isRequired,
875
+ max: PropTypes__default["default"].number.isRequired,
876
+ orientation: PropTypes__default["default"].oneOf(ORIENTATION)
877
+ };
878
+ SplitterComponent.defaultProps = {
879
+ orientation: 'end'
880
+ };
881
+ var Splitter = SplitterComponent;
882
+
883
+ var ContentComponent = React.forwardRef(function (props, ref) {
884
+ return React__default["default"].createElement(StyledPaneContent, _extends({
885
+ ref: ref
886
+ }, props));
887
+ });
888
+ ContentComponent.displayName = 'Pane.Content';
889
+ var Content = ContentComponent;
890
+
891
+ var _excluded = ["children"];
892
+ var PaneComponent = React.forwardRef(function (_ref, ref) {
893
+ var children = _ref.children,
894
+ props = _objectWithoutProperties(_ref, _excluded);
895
+ var _useState = React.useState(),
896
+ _useState2 = _slicedToArray(_useState, 2),
897
+ paneId = _useState2[0],
898
+ setPaneId = _useState2[1];
899
+ var paneContext = React.useMemo(function () {
900
+ return {
901
+ id: paneId,
902
+ setId: function setId(id) {
903
+ return setPaneId(id);
904
+ }
905
+ };
906
+ }, [paneId]);
907
+ return React__default["default"].createElement(PaneContext.Provider, {
908
+ value: paneContext
909
+ }, React__default["default"].createElement(StyledPane, _extends({
910
+ id: paneId,
911
+ ref: ref
912
+ }, props), children));
913
+ });
914
+ PaneComponent.displayName = 'Pane';
915
+ var Pane = PaneComponent;
916
+ Pane.Content = Content;
917
+ Pane.Splitter = Splitter;
918
+
379
919
  exports.ARRAY_ALIGN_ITEMS = ALIGN_ITEMS;
380
920
  exports.ARRAY_ALIGN_SELF = ALIGN_SELF;
381
921
  exports.ARRAY_DIRECTION = DIRECTION;
@@ -385,4 +925,6 @@ exports.ARRAY_TEXT_ALIGN = TEXT_ALIGN;
385
925
  exports.ARRAY_WRAP = WRAP;
386
926
  exports.Col = Col;
387
927
  exports.Grid = Grid;
928
+ exports.Pane = Pane;
929
+ exports.PaneProvider = PaneProvider;
388
930
  exports.Row = Row;