46 | );
47 | }
48 | ```
49 |
50 | See [here](https://greggman.github.io/react-split-it/#simple)
51 |
52 | There is also [a UMD version](http://unpkg.com/react-split-it). See [Example](https://jsfiddle.net/greggman/ctreapqm/)
53 |
54 | **Important!!!**
55 |
56 | You need to make sure that `.outer` specifies some size
57 | large enough make space for the things inside ``.
58 | And it's up to you to make sure the contents of each
59 | pane expand to fill their container.
60 |
61 | Further, you must supply the your own CSS. The goal of
62 | react-split-it is to do as little as possible and pass
63 | on the rest to you. That way it's more flexible since
64 | almost nothing is hard coded.
65 |
66 | Here is the minimal css you need to provide.
67 | (assuming you don't change the class names, see below)
68 |
69 | ```css
70 | .split-horizontal {
71 | display: flex;
72 | width: 100%;
73 | height: 100%;
74 | }
75 | .split-vertical {
76 | display: flex;
77 | flex-direction: column;
78 | height: 100%;
79 | }
80 |
81 | .gutter {
82 | flex-shrink: 0;
83 | flex-grow: 0;
84 | background: gray;
85 | }
86 | .gutter-horizontal {
87 | cursor: col-resize;
88 | }
89 | .gutter-vertical {
90 | cursor: row-resize;
91 | }
92 | .gutter:hover {
93 | background: #8cF;
94 | }
95 | .gutter-dragging:hover {
96 | background: cyan;
97 | }
98 |
99 | .pane {
100 | flex-shrink: 1;
101 | flex-grow: 1;
102 | position: relative;
103 | }
104 | .pane-dragging {
105 | overflow: hidden;
106 | }
107 | ```
108 |
109 | ## How it works
110 |
111 | Given the example above this is what your actual HTML elements will look like
112 |
113 | ```html
114 |
115 |
116 |
117 |
pane one
118 |
119 |
120 |
121 |
pane two
122 |
123 |
124 |
125 |
pane three
126 |
127 |
128 |
129 | ```
130 |
131 | If you click and drag on the first gutter it will adjust
132 | the percentages in the wrappers to either side. The reason to use percentages is because if the window is resized the elements will do the correct thing. No need to run any code.
133 |
134 | The reason for the wrappers (vs split.js) is react can't
135 | set the style of children without their cooperation so
136 | react-split-it makes its own children, the wrappers,
137 | that it can manipulate.
138 |
139 | The reason it uses flex-basis is because the browser will automatically handle the gutters
140 | where as using something like `width: 33.33333%` will not.
141 |
142 | ## Props
143 |
144 | * `direction` (default: 'horizontal')
145 |
146 | Can be 'horizontal' or 'vertical'
147 |
148 | * `sizes` (default: 1 / number-of-panes)
149 |
150 | Sizes are in normalized values. In other words they should add up to 1.0.
151 | By default they are copied to local state and only used at creation time.
152 | If you want to be able to change them after creation see `onSetSizes`
153 |
154 | * `minSize` (default: 10)
155 |
156 | The minimum size of each pane in CSS pixels
157 |
158 | * `gutterSize` (default: 10)
159 |
160 | The size of gutters. Currently all gutters must be the same size
161 | and they must be specified as a number of CSS pixels.
162 |
163 | * `className` (default: 'split')
164 |
165 | The base class name to use for the outer most div. By default it will be
166 | `
...`.
167 |
168 | * `gutterClassName` (default: 'gutter')
169 |
170 | The base class name to use for the gutters. By default the gutter will
171 | have `gutter`, `gutter-`, and `gutter-dragging` if being dragged.
172 |
173 | * `paneClassName` (default: 'pane')
174 |
175 | The class name to use for each pane
176 |
177 | * `onSetSizes` (default: undefined)
178 |
179 | This is a function you supply if you want to be responsible for storing
180 | the state of the sizes. Anytime react-split-it needs to store new sizes
181 | it will call `onSetSize` with an array of normalized size numbers.
182 |
183 | If you supply this function then whatever values are sent to `onSetSize`
184 | should in general be passed back via props as `sizes`.
185 |
186 | [See this example](https://greggman.github.io/react-split-it/#add-remove-panes-managed)
187 | and [this section](#Handling-adding-and-removing-panes-and-or-recording-sizes).
188 |
189 | * `computeNewSizesFn` (default: undefined)
190 |
191 | This is a function called while dragging a gutter to compute new sizes.
192 | react-split-it provides 2 functions, the default is `Split.stableGuttersComputeNewSizes`
193 | which only lets a gutter move in the space of the 2 panes to either side.
194 |
195 | An alternative is `Split.moveGuttersComputeNewSizes`. You can see an example of its
196 | usage [here](https://greggman.githib.io/react-split-it/#move-gutters).
197 |
198 | Otherwise if you want more complex behavior you can provide your own function.
199 | See [this section](#Changing-behavior)
200 |
201 | ## Handling adding and removing panes and/or recording sizes
202 |
203 | By default react-split-it manages the sizes of the panes for you.
204 | You can pass in initial sizes but after that it's on its own.
205 |
206 | But let's say you have dynamic panes as in
207 |
208 | ```javascript
209 |
210 | {panes.map(p => )}
211 |
212 | ```
213 |
214 | Let's say it starts as 3 panes
215 |
216 | ```
217 | +---------+---------+---------+
218 | | 33% | 33% | 33% |
219 | +---------+---------+---------+
220 | ```
221 |
222 | The user drags them to this
223 |
224 | ```
225 | +---+---------------------+---+
226 | |10%| 80% |10%|
227 | +---+---------------------+---+
228 | ```
229 |
230 | Now you delete a pane so `panes` in the code above is 2 elements?
231 | Which element was deleted? The react-split-it `` component
232 | has no idea. Was the first element deleted and so it should now be
233 |
234 | ```
235 | +------------------------+----+
236 | | 85% | 15%|
237 | +------------------------+----+
238 | ```
239 |
240 | Or the second element so it should now be
241 |
242 | ```
243 | +--------------+--------------+
244 | | 50% | 50% |
245 | +--------------+--------------+
246 | ```
247 |
248 | Or the 3rd element?
249 |
250 | ```
251 | +----+------------------------+
252 | |15% | 85% |
253 | +----+------------------------+
254 | ```
255 |
256 | So, if you want to be able to tell react-split-it what happened you're required
257 | to store the state of the sizes by providing an `onSetSize` function as a prop.
258 | [See this example](https://greggman.github.io/react-split-it/#add-remove-panes-managed).
259 |
260 | Now since you are in charge of the sizes you know if you delete `pane[2]`
261 | then you should also delete `sizes[2]`.
262 |
263 | If you don't provide a `onSetSize` function then if you remove a pane
264 | the space will be evenly distributed as if the last pane was deleted.
265 | If you add a pane all the sizes will be reset to `1 / numPanes`
266 |
267 | ## Changing behavior
268 |
269 | As it is if you have a split like this
270 |
271 | ```
272 | +-----+-----+-----+
273 | | | | |
274 | | A B |
275 | | | | |
276 | +-----+-----+-----+
277 | ```
278 |
279 | If you drag `A` to the right it will stop at `B`.
280 |
281 | You can change this by providing a function `computeNewSizesFn` as a prop. The function you pass in will be called to compute the sizes off all the panes
282 | when a spitter is dragged. It is passed an object
283 | with the following properties.
284 |
285 | * `startSizes`: [number]
286 |
287 | An array of numbers of the size of each pane before dragging started.
288 | These are in normalized values. In other words each value is a number between 0 and 1 and they should all add up to 1. In a 3 pane split by default this
289 | would be an array of `[0.333, 0.333, 0.333]`
290 |
291 | * `prevPaneNdx`: integer
292 |
293 | The index of the pane before the spitter being dragged.
294 | In other words if you were dragging `B` in the diagram
295 | above this would be 1.
296 |
297 | * `minSize`: number
298 |
299 | The minimum size specified for panes in normalized values
300 |
301 | * `minSizePX`: number
302 |
303 | The minimum size specified for panes in CSS pixels
304 |
305 | * `delta`: number
306 |
307 | The amount the gutter has been dragged in normalized values
308 | since the start of dragging
309 |
310 | * `deltaPX`: number
311 |
312 | The amount the gutter has been dragged in CSS pixels
313 | since the start of dragging
314 |
315 | * `innerSizePX`: number
316 |
317 | The size of the space to work in. In other words
318 | the size of `outer` in the example above minus
319 | `gutterSize * numPanes - 1`. In other words if there are 3
320 | pane then there are 2 gutters. If the space of outer
321 | is 100px then subtracting the space for the 2 gutters
322 | means `innerSizePX` will be 80.
323 |
324 | Given this your function should return the new sizes
325 | of all the panes. As the simplest example
326 |
327 | ```javascript
328 | function badComputeNewSizes({
329 | startSizes,
330 | prevPaneNdx,
331 | delta,
332 | }) {
333 | return [
334 | ...startSizes.slice(0, prevPaneNdx),
335 | startSizes[prevPaneNdx ] + delta,
336 | startSizes[prevPaneNdx + 1] - delta,
337 | ...startSizes.slice(prevPaneNdx + 2, startSizes.length),
338 | ];
339 | }
340 | ```
341 |
342 | You can see the code above, all it does is add `delta` to
343 | the pane before the spitter and subtracts it from the pane after
344 | the splitter. [If you try it](https://greggman.github.io/react-split-it/#bad-custom-compute-sizes)
345 | you'll see it kind of works!
346 |
347 | Why it's bad is because it doesn't check that we don't make any size less then 0
348 | and it also doesn't check we don't make it less than `minSize` but it's
349 | the simplest example.
350 |
351 | You can supply your own function if you want to do something fancy like
352 | different minimum sizes per pane or some gutters able to push other gutters
353 | and some not. To see how to write one take a look at [the source for
354 | the default function](https://github.com/greggman/react-split-it/blob/main/src/stable-gutters-compute-new-sizes.js) and [the provided alternative](https://github.com/greggman/react-split-it/blob/main/src/move-gutters-compute-new-sizes.js)
355 |
356 | ## Why react-split-it?
357 |
358 | Because all the others were broken for me.
359 |
360 | `react-split` fails if you add or remove children because it's not actually a react aware solution. It's just a wrapper around split.js which inserts its own elements which
361 | are not part of the react virtual DOM. When react re-creates the elements it's managing the 2 get out of sync.
362 |
363 | `react-split-pane` didn't do what I want. I want that
364 | when you drag a splitter only the thing to the left
365 | and right of that splitter get affected. `react-split-pane` though doesn't do that.
366 |
367 | `react-reflex` would probably have been my solution but it failed to work with React 16. It's out of date.
368 |
369 | ## Disclaimer
370 |
371 | I make no promises this works for you. If it doesn't do something you need then **fork it** and adapt it for your needs.
372 |
373 | ## License
374 |
375 | [MIT](LICENSE.md)
376 |
--------------------------------------------------------------------------------
/dist/react-split-it.cjs.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | Object.defineProperty(exports, '__esModule', { value: true });
4 |
5 | var PropTypes = require('prop-types');
6 | var React$1 = require('react');
7 |
8 | function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9 |
10 | var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
11 | var React__default = /*#__PURE__*/_interopDefaultLegacy(React$1);
12 |
13 | function ownKeys(object, enumerableOnly) {
14 | var keys = Object.keys(object);
15 |
16 | if (Object.getOwnPropertySymbols) {
17 | var symbols = Object.getOwnPropertySymbols(object);
18 | enumerableOnly && (symbols = symbols.filter(function (sym) {
19 | return Object.getOwnPropertyDescriptor(object, sym).enumerable;
20 | })), keys.push.apply(keys, symbols);
21 | }
22 |
23 | return keys;
24 | }
25 |
26 | function _objectSpread2(target) {
27 | for (var i = 1; i < arguments.length; i++) {
28 | var source = null != arguments[i] ? arguments[i] : {};
29 | i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
30 | _defineProperty(target, key, source[key]);
31 | }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
32 | Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
33 | });
34 | }
35 |
36 | return target;
37 | }
38 |
39 | function _classCallCheck(instance, Constructor) {
40 | if (!(instance instanceof Constructor)) {
41 | throw new TypeError("Cannot call a class as a function");
42 | }
43 | }
44 |
45 | function _defineProperties(target, props) {
46 | for (var i = 0; i < props.length; i++) {
47 | var descriptor = props[i];
48 | descriptor.enumerable = descriptor.enumerable || false;
49 | descriptor.configurable = true;
50 | if ("value" in descriptor) descriptor.writable = true;
51 | Object.defineProperty(target, descriptor.key, descriptor);
52 | }
53 | }
54 |
55 | function _createClass(Constructor, protoProps, staticProps) {
56 | if (protoProps) _defineProperties(Constructor.prototype, protoProps);
57 | if (staticProps) _defineProperties(Constructor, staticProps);
58 | Object.defineProperty(Constructor, "prototype", {
59 | writable: false
60 | });
61 | return Constructor;
62 | }
63 |
64 | function _defineProperty(obj, key, value) {
65 | if (key in obj) {
66 | Object.defineProperty(obj, key, {
67 | value: value,
68 | enumerable: true,
69 | configurable: true,
70 | writable: true
71 | });
72 | } else {
73 | obj[key] = value;
74 | }
75 |
76 | return obj;
77 | }
78 |
79 | function _inherits(subClass, superClass) {
80 | if (typeof superClass !== "function" && superClass !== null) {
81 | throw new TypeError("Super expression must either be null or a function");
82 | }
83 |
84 | subClass.prototype = Object.create(superClass && superClass.prototype, {
85 | constructor: {
86 | value: subClass,
87 | writable: true,
88 | configurable: true
89 | }
90 | });
91 | Object.defineProperty(subClass, "prototype", {
92 | writable: false
93 | });
94 | if (superClass) _setPrototypeOf(subClass, superClass);
95 | }
96 |
97 | function _getPrototypeOf(o) {
98 | _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
99 | return o.__proto__ || Object.getPrototypeOf(o);
100 | };
101 | return _getPrototypeOf(o);
102 | }
103 |
104 | function _setPrototypeOf(o, p) {
105 | _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
106 | o.__proto__ = p;
107 | return o;
108 | };
109 |
110 | return _setPrototypeOf(o, p);
111 | }
112 |
113 | function _isNativeReflectConstruct() {
114 | if (typeof Reflect === "undefined" || !Reflect.construct) return false;
115 | if (Reflect.construct.sham) return false;
116 | if (typeof Proxy === "function") return true;
117 |
118 | try {
119 | Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
120 | return true;
121 | } catch (e) {
122 | return false;
123 | }
124 | }
125 |
126 | function _assertThisInitialized(self) {
127 | if (self === void 0) {
128 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
129 | }
130 |
131 | return self;
132 | }
133 |
134 | function _possibleConstructorReturn(self, call) {
135 | if (call && (typeof call === "object" || typeof call === "function")) {
136 | return call;
137 | } else if (call !== void 0) {
138 | throw new TypeError("Derived constructors may only return object or undefined");
139 | }
140 |
141 | return _assertThisInitialized(self);
142 | }
143 |
144 | function _createSuper(Derived) {
145 | var hasNativeReflectConstruct = _isNativeReflectConstruct();
146 |
147 | return function _createSuperInternal() {
148 | var Super = _getPrototypeOf(Derived),
149 | result;
150 |
151 | if (hasNativeReflectConstruct) {
152 | var NewTarget = _getPrototypeOf(this).constructor;
153 |
154 | result = Reflect.construct(Super, arguments, NewTarget);
155 | } else {
156 | result = Super.apply(this, arguments);
157 | }
158 |
159 | return _possibleConstructorReturn(this, result);
160 | };
161 | }
162 |
163 | function _slicedToArray(arr, i) {
164 | return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
165 | }
166 |
167 | function _toConsumableArray(arr) {
168 | return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
169 | }
170 |
171 | function _arrayWithoutHoles(arr) {
172 | if (Array.isArray(arr)) return _arrayLikeToArray(arr);
173 | }
174 |
175 | function _arrayWithHoles(arr) {
176 | if (Array.isArray(arr)) return arr;
177 | }
178 |
179 | function _iterableToArray(iter) {
180 | if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
181 | }
182 |
183 | function _iterableToArrayLimit(arr, i) {
184 | var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
185 |
186 | if (_i == null) return;
187 | var _arr = [];
188 | var _n = true;
189 | var _d = false;
190 |
191 | var _s, _e;
192 |
193 | try {
194 | for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
195 | _arr.push(_s.value);
196 |
197 | if (i && _arr.length === i) break;
198 | }
199 | } catch (err) {
200 | _d = true;
201 | _e = err;
202 | } finally {
203 | try {
204 | if (!_n && _i["return"] != null) _i["return"]();
205 | } finally {
206 | if (_d) throw _e;
207 | }
208 | }
209 |
210 | return _arr;
211 | }
212 |
213 | function _unsupportedIterableToArray(o, minLen) {
214 | if (!o) return;
215 | if (typeof o === "string") return _arrayLikeToArray(o, minLen);
216 | var n = Object.prototype.toString.call(o).slice(8, -1);
217 | if (n === "Object" && o.constructor) n = o.constructor.name;
218 | if (n === "Map" || n === "Set") return Array.from(o);
219 | if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
220 | }
221 |
222 | function _arrayLikeToArray(arr, len) {
223 | if (len == null || len > arr.length) len = arr.length;
224 |
225 | for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
226 |
227 | return arr2;
228 | }
229 |
230 | function _nonIterableSpread() {
231 | throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
232 | }
233 |
234 | function _nonIterableRest() {
235 | throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
236 | }
237 |
238 | var camelCaseRE = /([a-z])([A-Z])/g;
239 |
240 | var toDash = function toDash(_, left, right) {
241 | return "".concat(left, "-").concat(right);
242 | };
243 |
244 | var camelCaseToDash = function camelCaseToDash(s) {
245 | return s.replace(camelCaseRE, toDash).toLowerCase();
246 | };
247 |
248 | function classNames() {
249 | var names = [];
250 |
251 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
252 | args[_key] = arguments[_key];
253 | }
254 |
255 | for (var _i = 0, _args = args; _i < _args.length; _i++) {
256 | var arg = _args[_i];
257 |
258 | if (typeof arg === 'string') {
259 | names.push(arg);
260 | } else {
261 | for (var _i2 = 0, _Object$entries = Object.entries(arg); _i2 < _Object$entries.length; _i2++) {
262 | var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
263 | key = _Object$entries$_i[0],
264 | value = _Object$entries$_i[1];
265 |
266 | if (value) {
267 | names.push(camelCaseToDash(key));
268 | }
269 | }
270 | }
271 | }
272 |
273 | return names.join(' ');
274 | }
275 |
276 | function createCommonjsModule(fn, module) {
277 | return module = { exports: {} }, fn(module, module.exports), module.exports;
278 | }
279 |
280 | /*
281 | object-assign
282 | (c) Sindre Sorhus
283 | @license MIT
284 | */
285 | /* eslint-disable no-unused-vars */
286 | var getOwnPropertySymbols = Object.getOwnPropertySymbols;
287 | var hasOwnProperty = Object.prototype.hasOwnProperty;
288 | var propIsEnumerable = Object.prototype.propertyIsEnumerable;
289 |
290 | function toObject(val) {
291 | if (val === null || val === undefined) {
292 | throw new TypeError('Object.assign cannot be called with null or undefined');
293 | }
294 |
295 | return Object(val);
296 | }
297 |
298 | function shouldUseNative() {
299 | try {
300 | if (!Object.assign) {
301 | return false;
302 | }
303 |
304 | // Detect buggy property enumeration order in older V8 versions.
305 |
306 | // https://bugs.chromium.org/p/v8/issues/detail?id=4118
307 | var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
308 | test1[5] = 'de';
309 | if (Object.getOwnPropertyNames(test1)[0] === '5') {
310 | return false;
311 | }
312 |
313 | // https://bugs.chromium.org/p/v8/issues/detail?id=3056
314 | var test2 = {};
315 | for (var i = 0; i < 10; i++) {
316 | test2['_' + String.fromCharCode(i)] = i;
317 | }
318 | var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
319 | return test2[n];
320 | });
321 | if (order2.join('') !== '0123456789') {
322 | return false;
323 | }
324 |
325 | // https://bugs.chromium.org/p/v8/issues/detail?id=3056
326 | var test3 = {};
327 | 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
328 | test3[letter] = letter;
329 | });
330 | if (Object.keys(Object.assign({}, test3)).join('') !==
331 | 'abcdefghijklmnopqrst') {
332 | return false;
333 | }
334 |
335 | return true;
336 | } catch (err) {
337 | // We don't expect any of the above to throw, but better to be safe.
338 | return false;
339 | }
340 | }
341 |
342 | var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
343 | var from;
344 | var to = toObject(target);
345 | var symbols;
346 |
347 | for (var s = 1; s < arguments.length; s++) {
348 | from = Object(arguments[s]);
349 |
350 | for (var key in from) {
351 | if (hasOwnProperty.call(from, key)) {
352 | to[key] = from[key];
353 | }
354 | }
355 |
356 | if (getOwnPropertySymbols) {
357 | symbols = getOwnPropertySymbols(from);
358 | for (var i = 0; i < symbols.length; i++) {
359 | if (propIsEnumerable.call(from, symbols[i])) {
360 | to[symbols[i]] = from[symbols[i]];
361 | }
362 | }
363 | }
364 | }
365 |
366 | return to;
367 | };
368 |
369 | var react_production_min = createCommonjsModule(function (module, exports) {
370 | var n=60103,p=60106;exports.Fragment=60107;exports.StrictMode=60108;exports.Profiler=60114;var q=60109,r=60110,t=60112;exports.Suspense=60113;var u=60115,v=60116;
371 | if("function"===typeof Symbol&&Symbol.for){var w=Symbol.for;n=w("react.element");p=w("react.portal");exports.Fragment=w("react.fragment");exports.StrictMode=w("react.strict_mode");exports.Profiler=w("react.profiler");q=w("react.provider");r=w("react.context");t=w("react.forward_ref");exports.Suspense=w("react.suspense");u=w("react.memo");v=w("react.lazy");}var x="function"===typeof Symbol&&Symbol.iterator;
372 | function y(a){if(null===a||"object"!==typeof a)return null;a=x&&a[x]||a["@@iterator"];return "function"===typeof a?a:null}function z(a){for(var b="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=1;c 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
585 | args[_key - 1] = arguments[_key];
586 | }
587 |
588 | printWarning('warn', format, args);
589 | }
590 | }
591 | function error(format) {
592 | {
593 | for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
594 | args[_key2 - 1] = arguments[_key2];
595 | }
596 |
597 | printWarning('error', format, args);
598 | }
599 | }
600 |
601 | function printWarning(level, format, args) {
602 | // When changing this logic, you might want to also
603 | // update consoleWithStackDev.www.js as well.
604 | {
605 | var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
606 | var stack = ReactDebugCurrentFrame.getStackAddendum();
607 |
608 | if (stack !== '') {
609 | format += '%s';
610 | args = args.concat([stack]);
611 | }
612 |
613 | var argsWithFormat = args.map(function (item) {
614 | return '' + item;
615 | }); // Careful: RN currently depends on this prefix
616 |
617 | argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
618 | // breaks IE9: https://github.com/facebook/react/issues/13610
619 | // eslint-disable-next-line react-internal/no-production-logging
620 |
621 | Function.prototype.apply.call(console[level], console, argsWithFormat);
622 | }
623 | }
624 |
625 | var didWarnStateUpdateForUnmountedComponent = {};
626 |
627 | function warnNoop(publicInstance, callerName) {
628 | {
629 | var _constructor = publicInstance.constructor;
630 | var componentName = _constructor && (_constructor.displayName || _constructor.name) || 'ReactClass';
631 | var warningKey = componentName + "." + callerName;
632 |
633 | if (didWarnStateUpdateForUnmountedComponent[warningKey]) {
634 | return;
635 | }
636 |
637 | error("Can't call %s on a component that is not yet mounted. " + 'This is a no-op, but it might indicate a bug in your application. ' + 'Instead, assign to `this.state` directly or define a `state = {};` ' + 'class property with the desired state in the %s component.', callerName, componentName);
638 |
639 | didWarnStateUpdateForUnmountedComponent[warningKey] = true;
640 | }
641 | }
642 | /**
643 | * This is the abstract API for an update queue.
644 | */
645 |
646 |
647 | var ReactNoopUpdateQueue = {
648 | /**
649 | * Checks whether or not this composite component is mounted.
650 | * @param {ReactClass} publicInstance The instance we want to test.
651 | * @return {boolean} True if mounted, false otherwise.
652 | * @protected
653 | * @final
654 | */
655 | isMounted: function (publicInstance) {
656 | return false;
657 | },
658 |
659 | /**
660 | * Forces an update. This should only be invoked when it is known with
661 | * certainty that we are **not** in a DOM transaction.
662 | *
663 | * You may want to call this when you know that some deeper aspect of the
664 | * component's state has changed but `setState` was not called.
665 | *
666 | * This will not invoke `shouldComponentUpdate`, but it will invoke
667 | * `componentWillUpdate` and `componentDidUpdate`.
668 | *
669 | * @param {ReactClass} publicInstance The instance that should rerender.
670 | * @param {?function} callback Called after component is updated.
671 | * @param {?string} callerName name of the calling function in the public API.
672 | * @internal
673 | */
674 | enqueueForceUpdate: function (publicInstance, callback, callerName) {
675 | warnNoop(publicInstance, 'forceUpdate');
676 | },
677 |
678 | /**
679 | * Replaces all of the state. Always use this or `setState` to mutate state.
680 | * You should treat `this.state` as immutable.
681 | *
682 | * There is no guarantee that `this.state` will be immediately updated, so
683 | * accessing `this.state` after calling this method may return the old value.
684 | *
685 | * @param {ReactClass} publicInstance The instance that should rerender.
686 | * @param {object} completeState Next state.
687 | * @param {?function} callback Called after component is updated.
688 | * @param {?string} callerName name of the calling function in the public API.
689 | * @internal
690 | */
691 | enqueueReplaceState: function (publicInstance, completeState, callback, callerName) {
692 | warnNoop(publicInstance, 'replaceState');
693 | },
694 |
695 | /**
696 | * Sets a subset of the state. This only exists because _pendingState is
697 | * internal. This provides a merging strategy that is not available to deep
698 | * properties which is confusing. TODO: Expose pendingState or don't use it
699 | * during the merge.
700 | *
701 | * @param {ReactClass} publicInstance The instance that should rerender.
702 | * @param {object} partialState Next partial state to be merged with state.
703 | * @param {?function} callback Called after component is updated.
704 | * @param {?string} Name of the calling function in the public API.
705 | * @internal
706 | */
707 | enqueueSetState: function (publicInstance, partialState, callback, callerName) {
708 | warnNoop(publicInstance, 'setState');
709 | }
710 | };
711 |
712 | var emptyObject = {};
713 |
714 | {
715 | Object.freeze(emptyObject);
716 | }
717 | /**
718 | * Base class helpers for the updating state of a component.
719 | */
720 |
721 |
722 | function Component(props, context, updater) {
723 | this.props = props;
724 | this.context = context; // If a component has string refs, we will assign a different object later.
725 |
726 | this.refs = emptyObject; // We initialize the default updater but the real one gets injected by the
727 | // renderer.
728 |
729 | this.updater = updater || ReactNoopUpdateQueue;
730 | }
731 |
732 | Component.prototype.isReactComponent = {};
733 | /**
734 | * Sets a subset of the state. Always use this to mutate
735 | * state. You should treat `this.state` as immutable.
736 | *
737 | * There is no guarantee that `this.state` will be immediately updated, so
738 | * accessing `this.state` after calling this method may return the old value.
739 | *
740 | * There is no guarantee that calls to `setState` will run synchronously,
741 | * as they may eventually be batched together. You can provide an optional
742 | * callback that will be executed when the call to setState is actually
743 | * completed.
744 | *
745 | * When a function is provided to setState, it will be called at some point in
746 | * the future (not synchronously). It will be called with the up to date
747 | * component arguments (state, props, context). These values can be different
748 | * from this.* because your function may be called after receiveProps but before
749 | * shouldComponentUpdate, and this new state, props, and context will not yet be
750 | * assigned to this.
751 | *
752 | * @param {object|function} partialState Next partial state or function to
753 | * produce next partial state to be merged with current state.
754 | * @param {?function} callback Called after state is updated.
755 | * @final
756 | * @protected
757 | */
758 |
759 | Component.prototype.setState = function (partialState, callback) {
760 | if (!(typeof partialState === 'object' || typeof partialState === 'function' || partialState == null)) {
761 | {
762 | throw Error( "setState(...): takes an object of state variables to update or a function which returns an object of state variables." );
763 | }
764 | }
765 |
766 | this.updater.enqueueSetState(this, partialState, callback, 'setState');
767 | };
768 | /**
769 | * Forces an update. This should only be invoked when it is known with
770 | * certainty that we are **not** in a DOM transaction.
771 | *
772 | * You may want to call this when you know that some deeper aspect of the
773 | * component's state has changed but `setState` was not called.
774 | *
775 | * This will not invoke `shouldComponentUpdate`, but it will invoke
776 | * `componentWillUpdate` and `componentDidUpdate`.
777 | *
778 | * @param {?function} callback Called after update is complete.
779 | * @final
780 | * @protected
781 | */
782 |
783 |
784 | Component.prototype.forceUpdate = function (callback) {
785 | this.updater.enqueueForceUpdate(this, callback, 'forceUpdate');
786 | };
787 | /**
788 | * Deprecated APIs. These APIs used to exist on classic React classes but since
789 | * we would like to deprecate them, we're not going to move them over to this
790 | * modern base class. Instead, we define a getter that warns if it's accessed.
791 | */
792 |
793 |
794 | {
795 | var deprecatedAPIs = {
796 | isMounted: ['isMounted', 'Instead, make sure to clean up subscriptions and pending requests in ' + 'componentWillUnmount to prevent memory leaks.'],
797 | replaceState: ['replaceState', 'Refactor your code to use setState instead (see ' + 'https://github.com/facebook/react/issues/3236).']
798 | };
799 |
800 | var defineDeprecationWarning = function (methodName, info) {
801 | Object.defineProperty(Component.prototype, methodName, {
802 | get: function () {
803 | warn('%s(...) is deprecated in plain JavaScript React classes. %s', info[0], info[1]);
804 |
805 | return undefined;
806 | }
807 | });
808 | };
809 |
810 | for (var fnName in deprecatedAPIs) {
811 | if (deprecatedAPIs.hasOwnProperty(fnName)) {
812 | defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
813 | }
814 | }
815 | }
816 |
817 | function ComponentDummy() {}
818 |
819 | ComponentDummy.prototype = Component.prototype;
820 | /**
821 | * Convenience component with default shallow equality check for sCU.
822 | */
823 |
824 | function PureComponent(props, context, updater) {
825 | this.props = props;
826 | this.context = context; // If a component has string refs, we will assign a different object later.
827 |
828 | this.refs = emptyObject;
829 | this.updater = updater || ReactNoopUpdateQueue;
830 | }
831 |
832 | var pureComponentPrototype = PureComponent.prototype = new ComponentDummy();
833 | pureComponentPrototype.constructor = PureComponent; // Avoid an extra prototype jump for these methods.
834 |
835 | _assign(pureComponentPrototype, Component.prototype);
836 |
837 | pureComponentPrototype.isPureReactComponent = true;
838 |
839 | // an immutable object with a single mutable value
840 | function createRef() {
841 | var refObject = {
842 | current: null
843 | };
844 |
845 | {
846 | Object.seal(refObject);
847 | }
848 |
849 | return refObject;
850 | }
851 |
852 | function getWrappedName(outerType, innerType, wrapperName) {
853 | var functionName = innerType.displayName || innerType.name || '';
854 | return outerType.displayName || (functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName);
855 | }
856 |
857 | function getContextName(type) {
858 | return type.displayName || 'Context';
859 | }
860 |
861 | function getComponentName(type) {
862 | if (type == null) {
863 | // Host root, text node or just invalid type.
864 | return null;
865 | }
866 |
867 | {
868 | if (typeof type.tag === 'number') {
869 | error('Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
870 | }
871 | }
872 |
873 | if (typeof type === 'function') {
874 | return type.displayName || type.name || null;
875 | }
876 |
877 | if (typeof type === 'string') {
878 | return type;
879 | }
880 |
881 | switch (type) {
882 | case exports.Fragment:
883 | return 'Fragment';
884 |
885 | case REACT_PORTAL_TYPE:
886 | return 'Portal';
887 |
888 | case exports.Profiler:
889 | return 'Profiler';
890 |
891 | case exports.StrictMode:
892 | return 'StrictMode';
893 |
894 | case exports.Suspense:
895 | return 'Suspense';
896 |
897 | case REACT_SUSPENSE_LIST_TYPE:
898 | return 'SuspenseList';
899 | }
900 |
901 | if (typeof type === 'object') {
902 | switch (type.$$typeof) {
903 | case REACT_CONTEXT_TYPE:
904 | var context = type;
905 | return getContextName(context) + '.Consumer';
906 |
907 | case REACT_PROVIDER_TYPE:
908 | var provider = type;
909 | return getContextName(provider._context) + '.Provider';
910 |
911 | case REACT_FORWARD_REF_TYPE:
912 | return getWrappedName(type, type.render, 'ForwardRef');
913 |
914 | case REACT_MEMO_TYPE:
915 | return getComponentName(type.type);
916 |
917 | case REACT_BLOCK_TYPE:
918 | return getComponentName(type._render);
919 |
920 | case REACT_LAZY_TYPE:
921 | {
922 | var lazyComponent = type;
923 | var payload = lazyComponent._payload;
924 | var init = lazyComponent._init;
925 |
926 | try {
927 | return getComponentName(init(payload));
928 | } catch (x) {
929 | return null;
930 | }
931 | }
932 | }
933 | }
934 |
935 | return null;
936 | }
937 |
938 | var hasOwnProperty = Object.prototype.hasOwnProperty;
939 | var RESERVED_PROPS = {
940 | key: true,
941 | ref: true,
942 | __self: true,
943 | __source: true
944 | };
945 | var specialPropKeyWarningShown, specialPropRefWarningShown, didWarnAboutStringRefs;
946 |
947 | {
948 | didWarnAboutStringRefs = {};
949 | }
950 |
951 | function hasValidRef(config) {
952 | {
953 | if (hasOwnProperty.call(config, 'ref')) {
954 | var getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
955 |
956 | if (getter && getter.isReactWarning) {
957 | return false;
958 | }
959 | }
960 | }
961 |
962 | return config.ref !== undefined;
963 | }
964 |
965 | function hasValidKey(config) {
966 | {
967 | if (hasOwnProperty.call(config, 'key')) {
968 | var getter = Object.getOwnPropertyDescriptor(config, 'key').get;
969 |
970 | if (getter && getter.isReactWarning) {
971 | return false;
972 | }
973 | }
974 | }
975 |
976 | return config.key !== undefined;
977 | }
978 |
979 | function defineKeyPropWarningGetter(props, displayName) {
980 | var warnAboutAccessingKey = function () {
981 | {
982 | if (!specialPropKeyWarningShown) {
983 | specialPropKeyWarningShown = true;
984 |
985 | error('%s: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName);
986 | }
987 | }
988 | };
989 |
990 | warnAboutAccessingKey.isReactWarning = true;
991 | Object.defineProperty(props, 'key', {
992 | get: warnAboutAccessingKey,
993 | configurable: true
994 | });
995 | }
996 |
997 | function defineRefPropWarningGetter(props, displayName) {
998 | var warnAboutAccessingRef = function () {
999 | {
1000 | if (!specialPropRefWarningShown) {
1001 | specialPropRefWarningShown = true;
1002 |
1003 | error('%s: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName);
1004 | }
1005 | }
1006 | };
1007 |
1008 | warnAboutAccessingRef.isReactWarning = true;
1009 | Object.defineProperty(props, 'ref', {
1010 | get: warnAboutAccessingRef,
1011 | configurable: true
1012 | });
1013 | }
1014 |
1015 | function warnIfStringRefCannotBeAutoConverted(config) {
1016 | {
1017 | if (typeof config.ref === 'string' && ReactCurrentOwner.current && config.__self && ReactCurrentOwner.current.stateNode !== config.__self) {
1018 | var componentName = getComponentName(ReactCurrentOwner.current.type);
1019 |
1020 | if (!didWarnAboutStringRefs[componentName]) {
1021 | error('Component "%s" contains the string ref "%s". ' + 'Support for string refs will be removed in a future major release. ' + 'This case cannot be automatically converted to an arrow function. ' + 'We ask you to manually fix this case by using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-string-ref', componentName, config.ref);
1022 |
1023 | didWarnAboutStringRefs[componentName] = true;
1024 | }
1025 | }
1026 | }
1027 | }
1028 | /**
1029 | * Factory method to create a new React element. This no longer adheres to
1030 | * the class pattern, so do not use new to call it. Also, instanceof check
1031 | * will not work. Instead test $$typeof field against Symbol.for('react.element') to check
1032 | * if something is a React Element.
1033 | *
1034 | * @param {*} type
1035 | * @param {*} props
1036 | * @param {*} key
1037 | * @param {string|object} ref
1038 | * @param {*} owner
1039 | * @param {*} self A *temporary* helper to detect places where `this` is
1040 | * different from the `owner` when React.createElement is called, so that we
1041 | * can warn. We want to get rid of owner and replace string `ref`s with arrow
1042 | * functions, and as long as `this` and owner are the same, there will be no
1043 | * change in behavior.
1044 | * @param {*} source An annotation object (added by a transpiler or otherwise)
1045 | * indicating filename, line number, and/or other information.
1046 | * @internal
1047 | */
1048 |
1049 |
1050 | var ReactElement = function (type, key, ref, self, source, owner, props) {
1051 | var element = {
1052 | // This tag allows us to uniquely identify this as a React Element
1053 | $$typeof: REACT_ELEMENT_TYPE,
1054 | // Built-in properties that belong on the element
1055 | type: type,
1056 | key: key,
1057 | ref: ref,
1058 | props: props,
1059 | // Record the component responsible for creating this element.
1060 | _owner: owner
1061 | };
1062 |
1063 | {
1064 | // The validation flag is currently mutative. We put it on
1065 | // an external backing store so that we can freeze the whole object.
1066 | // This can be replaced with a WeakMap once they are implemented in
1067 | // commonly used development environments.
1068 | element._store = {}; // To make comparing ReactElements easier for testing purposes, we make
1069 | // the validation flag non-enumerable (where possible, which should
1070 | // include every environment we run tests in), so the test framework
1071 | // ignores it.
1072 |
1073 | Object.defineProperty(element._store, 'validated', {
1074 | configurable: false,
1075 | enumerable: false,
1076 | writable: true,
1077 | value: false
1078 | }); // self and source are DEV only properties.
1079 |
1080 | Object.defineProperty(element, '_self', {
1081 | configurable: false,
1082 | enumerable: false,
1083 | writable: false,
1084 | value: self
1085 | }); // Two elements created in two different places should be considered
1086 | // equal for testing purposes and therefore we hide it from enumeration.
1087 |
1088 | Object.defineProperty(element, '_source', {
1089 | configurable: false,
1090 | enumerable: false,
1091 | writable: false,
1092 | value: source
1093 | });
1094 |
1095 | if (Object.freeze) {
1096 | Object.freeze(element.props);
1097 | Object.freeze(element);
1098 | }
1099 | }
1100 |
1101 | return element;
1102 | };
1103 | /**
1104 | * Create and return a new ReactElement of the given type.
1105 | * See https://reactjs.org/docs/react-api.html#createelement
1106 | */
1107 |
1108 | function createElement(type, config, children) {
1109 | var propName; // Reserved names are extracted
1110 |
1111 | var props = {};
1112 | var key = null;
1113 | var ref = null;
1114 | var self = null;
1115 | var source = null;
1116 |
1117 | if (config != null) {
1118 | if (hasValidRef(config)) {
1119 | ref = config.ref;
1120 |
1121 | {
1122 | warnIfStringRefCannotBeAutoConverted(config);
1123 | }
1124 | }
1125 |
1126 | if (hasValidKey(config)) {
1127 | key = '' + config.key;
1128 | }
1129 |
1130 | self = config.__self === undefined ? null : config.__self;
1131 | source = config.__source === undefined ? null : config.__source; // Remaining properties are added to a new props object
1132 |
1133 | for (propName in config) {
1134 | if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
1135 | props[propName] = config[propName];
1136 | }
1137 | }
1138 | } // Children can be more than one argument, and those are transferred onto
1139 | // the newly allocated props object.
1140 |
1141 |
1142 | var childrenLength = arguments.length - 2;
1143 |
1144 | if (childrenLength === 1) {
1145 | props.children = children;
1146 | } else if (childrenLength > 1) {
1147 | var childArray = Array(childrenLength);
1148 |
1149 | for (var i = 0; i < childrenLength; i++) {
1150 | childArray[i] = arguments[i + 2];
1151 | }
1152 |
1153 | {
1154 | if (Object.freeze) {
1155 | Object.freeze(childArray);
1156 | }
1157 | }
1158 |
1159 | props.children = childArray;
1160 | } // Resolve default props
1161 |
1162 |
1163 | if (type && type.defaultProps) {
1164 | var defaultProps = type.defaultProps;
1165 |
1166 | for (propName in defaultProps) {
1167 | if (props[propName] === undefined) {
1168 | props[propName] = defaultProps[propName];
1169 | }
1170 | }
1171 | }
1172 |
1173 | {
1174 | if (key || ref) {
1175 | var displayName = typeof type === 'function' ? type.displayName || type.name || 'Unknown' : type;
1176 |
1177 | if (key) {
1178 | defineKeyPropWarningGetter(props, displayName);
1179 | }
1180 |
1181 | if (ref) {
1182 | defineRefPropWarningGetter(props, displayName);
1183 | }
1184 | }
1185 | }
1186 |
1187 | return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
1188 | }
1189 | function cloneAndReplaceKey(oldElement, newKey) {
1190 | var newElement = ReactElement(oldElement.type, newKey, oldElement.ref, oldElement._self, oldElement._source, oldElement._owner, oldElement.props);
1191 | return newElement;
1192 | }
1193 | /**
1194 | * Clone and return a new ReactElement using element as the starting point.
1195 | * See https://reactjs.org/docs/react-api.html#cloneelement
1196 | */
1197 |
1198 | function cloneElement(element, config, children) {
1199 | if (!!(element === null || element === undefined)) {
1200 | {
1201 | throw Error( "React.cloneElement(...): The argument must be a React element, but you passed " + element + "." );
1202 | }
1203 | }
1204 |
1205 | var propName; // Original props are copied
1206 |
1207 | var props = _assign({}, element.props); // Reserved names are extracted
1208 |
1209 |
1210 | var key = element.key;
1211 | var ref = element.ref; // Self is preserved since the owner is preserved.
1212 |
1213 | var self = element._self; // Source is preserved since cloneElement is unlikely to be targeted by a
1214 | // transpiler, and the original source is probably a better indicator of the
1215 | // true owner.
1216 |
1217 | var source = element._source; // Owner will be preserved, unless ref is overridden
1218 |
1219 | var owner = element._owner;
1220 |
1221 | if (config != null) {
1222 | if (hasValidRef(config)) {
1223 | // Silently steal the ref from the parent.
1224 | ref = config.ref;
1225 | owner = ReactCurrentOwner.current;
1226 | }
1227 |
1228 | if (hasValidKey(config)) {
1229 | key = '' + config.key;
1230 | } // Remaining properties override existing props
1231 |
1232 |
1233 | var defaultProps;
1234 |
1235 | if (element.type && element.type.defaultProps) {
1236 | defaultProps = element.type.defaultProps;
1237 | }
1238 |
1239 | for (propName in config) {
1240 | if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
1241 | if (config[propName] === undefined && defaultProps !== undefined) {
1242 | // Resolve default props
1243 | props[propName] = defaultProps[propName];
1244 | } else {
1245 | props[propName] = config[propName];
1246 | }
1247 | }
1248 | }
1249 | } // Children can be more than one argument, and those are transferred onto
1250 | // the newly allocated props object.
1251 |
1252 |
1253 | var childrenLength = arguments.length - 2;
1254 |
1255 | if (childrenLength === 1) {
1256 | props.children = children;
1257 | } else if (childrenLength > 1) {
1258 | var childArray = Array(childrenLength);
1259 |
1260 | for (var i = 0; i < childrenLength; i++) {
1261 | childArray[i] = arguments[i + 2];
1262 | }
1263 |
1264 | props.children = childArray;
1265 | }
1266 |
1267 | return ReactElement(element.type, key, ref, self, source, owner, props);
1268 | }
1269 | /**
1270 | * Verifies the object is a ReactElement.
1271 | * See https://reactjs.org/docs/react-api.html#isvalidelement
1272 | * @param {?object} object
1273 | * @return {boolean} True if `object` is a ReactElement.
1274 | * @final
1275 | */
1276 |
1277 | function isValidElement(object) {
1278 | return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
1279 | }
1280 |
1281 | var SEPARATOR = '.';
1282 | var SUBSEPARATOR = ':';
1283 | /**
1284 | * Escape and wrap key so it is safe to use as a reactid
1285 | *
1286 | * @param {string} key to be escaped.
1287 | * @return {string} the escaped key.
1288 | */
1289 |
1290 | function escape(key) {
1291 | var escapeRegex = /[=:]/g;
1292 | var escaperLookup = {
1293 | '=': '=0',
1294 | ':': '=2'
1295 | };
1296 | var escapedString = key.replace(escapeRegex, function (match) {
1297 | return escaperLookup[match];
1298 | });
1299 | return '$' + escapedString;
1300 | }
1301 | /**
1302 | * TODO: Test that a single child and an array with one item have the same key
1303 | * pattern.
1304 | */
1305 |
1306 |
1307 | var didWarnAboutMaps = false;
1308 | var userProvidedKeyEscapeRegex = /\/+/g;
1309 |
1310 | function escapeUserProvidedKey(text) {
1311 | return text.replace(userProvidedKeyEscapeRegex, '$&/');
1312 | }
1313 | /**
1314 | * Generate a key string that identifies a element within a set.
1315 | *
1316 | * @param {*} element A element that could contain a manual key.
1317 | * @param {number} index Index that is used if a manual key is not provided.
1318 | * @return {string}
1319 | */
1320 |
1321 |
1322 | function getElementKey(element, index) {
1323 | // Do some typechecking here since we call this blindly. We want to ensure
1324 | // that we don't block potential future ES APIs.
1325 | if (typeof element === 'object' && element !== null && element.key != null) {
1326 | // Explicit key
1327 | return escape('' + element.key);
1328 | } // Implicit key determined by the index in the set
1329 |
1330 |
1331 | return index.toString(36);
1332 | }
1333 |
1334 | function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) {
1335 | var type = typeof children;
1336 |
1337 | if (type === 'undefined' || type === 'boolean') {
1338 | // All of the above are perceived as null.
1339 | children = null;
1340 | }
1341 |
1342 | var invokeCallback = false;
1343 |
1344 | if (children === null) {
1345 | invokeCallback = true;
1346 | } else {
1347 | switch (type) {
1348 | case 'string':
1349 | case 'number':
1350 | invokeCallback = true;
1351 | break;
1352 |
1353 | case 'object':
1354 | switch (children.$$typeof) {
1355 | case REACT_ELEMENT_TYPE:
1356 | case REACT_PORTAL_TYPE:
1357 | invokeCallback = true;
1358 | }
1359 |
1360 | }
1361 | }
1362 |
1363 | if (invokeCallback) {
1364 | var _child = children;
1365 | var mappedChild = callback(_child); // If it's the only child, treat the name as if it was wrapped in an array
1366 | // so that it's consistent if the number of children grows:
1367 |
1368 | var childKey = nameSoFar === '' ? SEPARATOR + getElementKey(_child, 0) : nameSoFar;
1369 |
1370 | if (Array.isArray(mappedChild)) {
1371 | var escapedChildKey = '';
1372 |
1373 | if (childKey != null) {
1374 | escapedChildKey = escapeUserProvidedKey(childKey) + '/';
1375 | }
1376 |
1377 | mapIntoArray(mappedChild, array, escapedChildKey, '', function (c) {
1378 | return c;
1379 | });
1380 | } else if (mappedChild != null) {
1381 | if (isValidElement(mappedChild)) {
1382 | mappedChild = cloneAndReplaceKey(mappedChild, // Keep both the (mapped) and old keys if they differ, just as
1383 | // traverseAllChildren used to do for objects as children
1384 | escapedPrefix + ( // $FlowFixMe Flow incorrectly thinks React.Portal doesn't have a key
1385 | mappedChild.key && (!_child || _child.key !== mappedChild.key) ? // $FlowFixMe Flow incorrectly thinks existing element's key can be a number
1386 | escapeUserProvidedKey('' + mappedChild.key) + '/' : '') + childKey);
1387 | }
1388 |
1389 | array.push(mappedChild);
1390 | }
1391 |
1392 | return 1;
1393 | }
1394 |
1395 | var child;
1396 | var nextName;
1397 | var subtreeCount = 0; // Count of children found in the current subtree.
1398 |
1399 | var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR;
1400 |
1401 | if (Array.isArray(children)) {
1402 | for (var i = 0; i < children.length; i++) {
1403 | child = children[i];
1404 | nextName = nextNamePrefix + getElementKey(child, i);
1405 | subtreeCount += mapIntoArray(child, array, escapedPrefix, nextName, callback);
1406 | }
1407 | } else {
1408 | var iteratorFn = getIteratorFn(children);
1409 |
1410 | if (typeof iteratorFn === 'function') {
1411 | var iterableChildren = children;
1412 |
1413 | {
1414 | // Warn about using Maps as children
1415 | if (iteratorFn === iterableChildren.entries) {
1416 | if (!didWarnAboutMaps) {
1417 | warn('Using Maps as children is not supported. ' + 'Use an array of keyed ReactElements instead.');
1418 | }
1419 |
1420 | didWarnAboutMaps = true;
1421 | }
1422 | }
1423 |
1424 | var iterator = iteratorFn.call(iterableChildren);
1425 | var step;
1426 | var ii = 0;
1427 |
1428 | while (!(step = iterator.next()).done) {
1429 | child = step.value;
1430 | nextName = nextNamePrefix + getElementKey(child, ii++);
1431 | subtreeCount += mapIntoArray(child, array, escapedPrefix, nextName, callback);
1432 | }
1433 | } else if (type === 'object') {
1434 | var childrenString = '' + children;
1435 |
1436 | {
1437 | {
1438 | throw Error( "Objects are not valid as a React child (found: " + (childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString) + "). If you meant to render a collection of children, use an array instead." );
1439 | }
1440 | }
1441 | }
1442 | }
1443 |
1444 | return subtreeCount;
1445 | }
1446 |
1447 | /**
1448 | * Maps children that are typically specified as `props.children`.
1449 | *
1450 | * See https://reactjs.org/docs/react-api.html#reactchildrenmap
1451 | *
1452 | * The provided mapFunction(child, index) will be called for each
1453 | * leaf child.
1454 | *
1455 | * @param {?*} children Children tree container.
1456 | * @param {function(*, int)} func The map function.
1457 | * @param {*} context Context for mapFunction.
1458 | * @return {object} Object containing the ordered map of results.
1459 | */
1460 | function mapChildren(children, func, context) {
1461 | if (children == null) {
1462 | return children;
1463 | }
1464 |
1465 | var result = [];
1466 | var count = 0;
1467 | mapIntoArray(children, result, '', '', function (child) {
1468 | return func.call(context, child, count++);
1469 | });
1470 | return result;
1471 | }
1472 | /**
1473 | * Count the number of children that are typically specified as
1474 | * `props.children`.
1475 | *
1476 | * See https://reactjs.org/docs/react-api.html#reactchildrencount
1477 | *
1478 | * @param {?*} children Children tree container.
1479 | * @return {number} The number of children.
1480 | */
1481 |
1482 |
1483 | function countChildren(children) {
1484 | var n = 0;
1485 | mapChildren(children, function () {
1486 | n++; // Don't return anything
1487 | });
1488 | return n;
1489 | }
1490 |
1491 | /**
1492 | * Iterates through children that are typically specified as `props.children`.
1493 | *
1494 | * See https://reactjs.org/docs/react-api.html#reactchildrenforeach
1495 | *
1496 | * The provided forEachFunc(child, index) will be called for each
1497 | * leaf child.
1498 | *
1499 | * @param {?*} children Children tree container.
1500 | * @param {function(*, int)} forEachFunc
1501 | * @param {*} forEachContext Context for forEachContext.
1502 | */
1503 | function forEachChildren(children, forEachFunc, forEachContext) {
1504 | mapChildren(children, function () {
1505 | forEachFunc.apply(this, arguments); // Don't return anything.
1506 | }, forEachContext);
1507 | }
1508 | /**
1509 | * Flatten a children object (typically specified as `props.children`) and
1510 | * return an array with appropriately re-keyed children.
1511 | *
1512 | * See https://reactjs.org/docs/react-api.html#reactchildrentoarray
1513 | */
1514 |
1515 |
1516 | function toArray(children) {
1517 | return mapChildren(children, function (child) {
1518 | return child;
1519 | }) || [];
1520 | }
1521 | /**
1522 | * Returns the first child in a collection of children and verifies that there
1523 | * is only one child in the collection.
1524 | *
1525 | * See https://reactjs.org/docs/react-api.html#reactchildrenonly
1526 | *
1527 | * The current implementation of this function assumes that a single child gets
1528 | * passed without a wrapper, but the purpose of this helper function is to
1529 | * abstract away the particular structure of children.
1530 | *
1531 | * @param {?object} children Child collection structure.
1532 | * @return {ReactElement} The first and only `ReactElement` contained in the
1533 | * structure.
1534 | */
1535 |
1536 |
1537 | function onlyChild(children) {
1538 | if (!isValidElement(children)) {
1539 | {
1540 | throw Error( "React.Children.only expected to receive a single React element child." );
1541 | }
1542 | }
1543 |
1544 | return children;
1545 | }
1546 |
1547 | function createContext(defaultValue, calculateChangedBits) {
1548 | if (calculateChangedBits === undefined) {
1549 | calculateChangedBits = null;
1550 | } else {
1551 | {
1552 | if (calculateChangedBits !== null && typeof calculateChangedBits !== 'function') {
1553 | error('createContext: Expected the optional second argument to be a ' + 'function. Instead received: %s', calculateChangedBits);
1554 | }
1555 | }
1556 | }
1557 |
1558 | var context = {
1559 | $$typeof: REACT_CONTEXT_TYPE,
1560 | _calculateChangedBits: calculateChangedBits,
1561 | // As a workaround to support multiple concurrent renderers, we categorize
1562 | // some renderers as primary and others as secondary. We only expect
1563 | // there to be two concurrent renderers at most: React Native (primary) and
1564 | // Fabric (secondary); React DOM (primary) and React ART (secondary).
1565 | // Secondary renderers store their context values on separate fields.
1566 | _currentValue: defaultValue,
1567 | _currentValue2: defaultValue,
1568 | // Used to track how many concurrent renderers this context currently
1569 | // supports within in a single renderer. Such as parallel server rendering.
1570 | _threadCount: 0,
1571 | // These are circular
1572 | Provider: null,
1573 | Consumer: null
1574 | };
1575 | context.Provider = {
1576 | $$typeof: REACT_PROVIDER_TYPE,
1577 | _context: context
1578 | };
1579 | var hasWarnedAboutUsingNestedContextConsumers = false;
1580 | var hasWarnedAboutUsingConsumerProvider = false;
1581 | var hasWarnedAboutDisplayNameOnConsumer = false;
1582 |
1583 | {
1584 | // A separate object, but proxies back to the original context object for
1585 | // backwards compatibility. It has a different $$typeof, so we can properly
1586 | // warn for the incorrect usage of Context as a Consumer.
1587 | var Consumer = {
1588 | $$typeof: REACT_CONTEXT_TYPE,
1589 | _context: context,
1590 | _calculateChangedBits: context._calculateChangedBits
1591 | }; // $FlowFixMe: Flow complains about not setting a value, which is intentional here
1592 |
1593 | Object.defineProperties(Consumer, {
1594 | Provider: {
1595 | get: function () {
1596 | if (!hasWarnedAboutUsingConsumerProvider) {
1597 | hasWarnedAboutUsingConsumerProvider = true;
1598 |
1599 | error('Rendering is not supported and will be removed in ' + 'a future major release. Did you mean to render instead?');
1600 | }
1601 |
1602 | return context.Provider;
1603 | },
1604 | set: function (_Provider) {
1605 | context.Provider = _Provider;
1606 | }
1607 | },
1608 | _currentValue: {
1609 | get: function () {
1610 | return context._currentValue;
1611 | },
1612 | set: function (_currentValue) {
1613 | context._currentValue = _currentValue;
1614 | }
1615 | },
1616 | _currentValue2: {
1617 | get: function () {
1618 | return context._currentValue2;
1619 | },
1620 | set: function (_currentValue2) {
1621 | context._currentValue2 = _currentValue2;
1622 | }
1623 | },
1624 | _threadCount: {
1625 | get: function () {
1626 | return context._threadCount;
1627 | },
1628 | set: function (_threadCount) {
1629 | context._threadCount = _threadCount;
1630 | }
1631 | },
1632 | Consumer: {
1633 | get: function () {
1634 | if (!hasWarnedAboutUsingNestedContextConsumers) {
1635 | hasWarnedAboutUsingNestedContextConsumers = true;
1636 |
1637 | error('Rendering is not supported and will be removed in ' + 'a future major release. Did you mean to render instead?');
1638 | }
1639 |
1640 | return context.Consumer;
1641 | }
1642 | },
1643 | displayName: {
1644 | get: function () {
1645 | return context.displayName;
1646 | },
1647 | set: function (displayName) {
1648 | if (!hasWarnedAboutDisplayNameOnConsumer) {
1649 | warn('Setting `displayName` on Context.Consumer has no effect. ' + "You should set it directly on the context with Context.displayName = '%s'.", displayName);
1650 |
1651 | hasWarnedAboutDisplayNameOnConsumer = true;
1652 | }
1653 | }
1654 | }
1655 | }); // $FlowFixMe: Flow complains about missing properties because it doesn't understand defineProperty
1656 |
1657 | context.Consumer = Consumer;
1658 | }
1659 |
1660 | {
1661 | context._currentRenderer = null;
1662 | context._currentRenderer2 = null;
1663 | }
1664 |
1665 | return context;
1666 | }
1667 |
1668 | var Uninitialized = -1;
1669 | var Pending = 0;
1670 | var Resolved = 1;
1671 | var Rejected = 2;
1672 |
1673 | function lazyInitializer(payload) {
1674 | if (payload._status === Uninitialized) {
1675 | var ctor = payload._result;
1676 | var thenable = ctor(); // Transition to the next state.
1677 |
1678 | var pending = payload;
1679 | pending._status = Pending;
1680 | pending._result = thenable;
1681 | thenable.then(function (moduleObject) {
1682 | if (payload._status === Pending) {
1683 | var defaultExport = moduleObject.default;
1684 |
1685 | {
1686 | if (defaultExport === undefined) {
1687 | error('lazy: Expected the result of a dynamic import() call. ' + 'Instead received: %s\n\nYour code should look like: \n ' + // Break up imports to avoid accidentally parsing them as dependencies.
1688 | 'const MyComponent = lazy(() => imp' + "ort('./MyComponent'))", moduleObject);
1689 | }
1690 | } // Transition to the next state.
1691 |
1692 |
1693 | var resolved = payload;
1694 | resolved._status = Resolved;
1695 | resolved._result = defaultExport;
1696 | }
1697 | }, function (error) {
1698 | if (payload._status === Pending) {
1699 | // Transition to the next state.
1700 | var rejected = payload;
1701 | rejected._status = Rejected;
1702 | rejected._result = error;
1703 | }
1704 | });
1705 | }
1706 |
1707 | if (payload._status === Resolved) {
1708 | return payload._result;
1709 | } else {
1710 | throw payload._result;
1711 | }
1712 | }
1713 |
1714 | function lazy(ctor) {
1715 | var payload = {
1716 | // We use these fields to store the result.
1717 | _status: -1,
1718 | _result: ctor
1719 | };
1720 | var lazyType = {
1721 | $$typeof: REACT_LAZY_TYPE,
1722 | _payload: payload,
1723 | _init: lazyInitializer
1724 | };
1725 |
1726 | {
1727 | // In production, this would just set it on the object.
1728 | var defaultProps;
1729 | var propTypes; // $FlowFixMe
1730 |
1731 | Object.defineProperties(lazyType, {
1732 | defaultProps: {
1733 | configurable: true,
1734 | get: function () {
1735 | return defaultProps;
1736 | },
1737 | set: function (newDefaultProps) {
1738 | error('React.lazy(...): It is not supported to assign `defaultProps` to ' + 'a lazy component import. Either specify them where the component ' + 'is defined, or create a wrapping component around it.');
1739 |
1740 | defaultProps = newDefaultProps; // Match production behavior more closely:
1741 | // $FlowFixMe
1742 |
1743 | Object.defineProperty(lazyType, 'defaultProps', {
1744 | enumerable: true
1745 | });
1746 | }
1747 | },
1748 | propTypes: {
1749 | configurable: true,
1750 | get: function () {
1751 | return propTypes;
1752 | },
1753 | set: function (newPropTypes) {
1754 | error('React.lazy(...): It is not supported to assign `propTypes` to ' + 'a lazy component import. Either specify them where the component ' + 'is defined, or create a wrapping component around it.');
1755 |
1756 | propTypes = newPropTypes; // Match production behavior more closely:
1757 | // $FlowFixMe
1758 |
1759 | Object.defineProperty(lazyType, 'propTypes', {
1760 | enumerable: true
1761 | });
1762 | }
1763 | }
1764 | });
1765 | }
1766 |
1767 | return lazyType;
1768 | }
1769 |
1770 | function forwardRef(render) {
1771 | {
1772 | if (render != null && render.$$typeof === REACT_MEMO_TYPE) {
1773 | error('forwardRef requires a render function but received a `memo` ' + 'component. Instead of forwardRef(memo(...)), use ' + 'memo(forwardRef(...)).');
1774 | } else if (typeof render !== 'function') {
1775 | error('forwardRef requires a render function but was given %s.', render === null ? 'null' : typeof render);
1776 | } else {
1777 | if (render.length !== 0 && render.length !== 2) {
1778 | error('forwardRef render functions accept exactly two parameters: props and ref. %s', render.length === 1 ? 'Did you forget to use the ref parameter?' : 'Any additional parameter will be undefined.');
1779 | }
1780 | }
1781 |
1782 | if (render != null) {
1783 | if (render.defaultProps != null || render.propTypes != null) {
1784 | error('forwardRef render functions do not support propTypes or defaultProps. ' + 'Did you accidentally pass a React component?');
1785 | }
1786 | }
1787 | }
1788 |
1789 | var elementType = {
1790 | $$typeof: REACT_FORWARD_REF_TYPE,
1791 | render: render
1792 | };
1793 |
1794 | {
1795 | var ownName;
1796 | Object.defineProperty(elementType, 'displayName', {
1797 | enumerable: false,
1798 | configurable: true,
1799 | get: function () {
1800 | return ownName;
1801 | },
1802 | set: function (name) {
1803 | ownName = name;
1804 |
1805 | if (render.displayName == null) {
1806 | render.displayName = name;
1807 | }
1808 | }
1809 | });
1810 | }
1811 |
1812 | return elementType;
1813 | }
1814 |
1815 | // Filter certain DOM attributes (e.g. src, href) if their values are empty strings.
1816 |
1817 | var enableScopeAPI = false; // Experimental Create Event Handle API.
1818 |
1819 | function isValidElementType(type) {
1820 | if (typeof type === 'string' || typeof type === 'function') {
1821 | return true;
1822 | } // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
1823 |
1824 |
1825 | if (type === exports.Fragment || type === exports.Profiler || type === REACT_DEBUG_TRACING_MODE_TYPE || type === exports.StrictMode || type === exports.Suspense || type === REACT_SUSPENSE_LIST_TYPE || type === REACT_LEGACY_HIDDEN_TYPE || enableScopeAPI ) {
1826 | return true;
1827 | }
1828 |
1829 | if (typeof type === 'object' && type !== null) {
1830 | if (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_BLOCK_TYPE || type[0] === REACT_SERVER_BLOCK_TYPE) {
1831 | return true;
1832 | }
1833 | }
1834 |
1835 | return false;
1836 | }
1837 |
1838 | function memo(type, compare) {
1839 | {
1840 | if (!isValidElementType(type)) {
1841 | error('memo: The first argument must be a component. Instead ' + 'received: %s', type === null ? 'null' : typeof type);
1842 | }
1843 | }
1844 |
1845 | var elementType = {
1846 | $$typeof: REACT_MEMO_TYPE,
1847 | type: type,
1848 | compare: compare === undefined ? null : compare
1849 | };
1850 |
1851 | {
1852 | var ownName;
1853 | Object.defineProperty(elementType, 'displayName', {
1854 | enumerable: false,
1855 | configurable: true,
1856 | get: function () {
1857 | return ownName;
1858 | },
1859 | set: function (name) {
1860 | ownName = name;
1861 |
1862 | if (type.displayName == null) {
1863 | type.displayName = name;
1864 | }
1865 | }
1866 | });
1867 | }
1868 |
1869 | return elementType;
1870 | }
1871 |
1872 | function resolveDispatcher() {
1873 | var dispatcher = ReactCurrentDispatcher.current;
1874 |
1875 | if (!(dispatcher !== null)) {
1876 | {
1877 | throw Error( "Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem." );
1878 | }
1879 | }
1880 |
1881 | return dispatcher;
1882 | }
1883 |
1884 | function useContext(Context, unstable_observedBits) {
1885 | var dispatcher = resolveDispatcher();
1886 |
1887 | {
1888 | if (unstable_observedBits !== undefined) {
1889 | error('useContext() second argument is reserved for future ' + 'use in React. Passing it is not supported. ' + 'You passed: %s.%s', unstable_observedBits, typeof unstable_observedBits === 'number' && Array.isArray(arguments[2]) ? '\n\nDid you call array.map(useContext)? ' + 'Calling Hooks inside a loop is not supported. ' + 'Learn more at https://reactjs.org/link/rules-of-hooks' : '');
1890 | } // TODO: add a more generic warning for invalid values.
1891 |
1892 |
1893 | if (Context._context !== undefined) {
1894 | var realContext = Context._context; // Don't deduplicate because this legitimately causes bugs
1895 | // and nobody should be using this in existing code.
1896 |
1897 | if (realContext.Consumer === Context) {
1898 | error('Calling useContext(Context.Consumer) is not supported, may cause bugs, and will be ' + 'removed in a future major release. Did you mean to call useContext(Context) instead?');
1899 | } else if (realContext.Provider === Context) {
1900 | error('Calling useContext(Context.Provider) is not supported. ' + 'Did you mean to call useContext(Context) instead?');
1901 | }
1902 | }
1903 | }
1904 |
1905 | return dispatcher.useContext(Context, unstable_observedBits);
1906 | }
1907 | function useState(initialState) {
1908 | var dispatcher = resolveDispatcher();
1909 | return dispatcher.useState(initialState);
1910 | }
1911 | function useReducer(reducer, initialArg, init) {
1912 | var dispatcher = resolveDispatcher();
1913 | return dispatcher.useReducer(reducer, initialArg, init);
1914 | }
1915 | function useRef(initialValue) {
1916 | var dispatcher = resolveDispatcher();
1917 | return dispatcher.useRef(initialValue);
1918 | }
1919 | function useEffect(create, deps) {
1920 | var dispatcher = resolveDispatcher();
1921 | return dispatcher.useEffect(create, deps);
1922 | }
1923 | function useLayoutEffect(create, deps) {
1924 | var dispatcher = resolveDispatcher();
1925 | return dispatcher.useLayoutEffect(create, deps);
1926 | }
1927 | function useCallback(callback, deps) {
1928 | var dispatcher = resolveDispatcher();
1929 | return dispatcher.useCallback(callback, deps);
1930 | }
1931 | function useMemo(create, deps) {
1932 | var dispatcher = resolveDispatcher();
1933 | return dispatcher.useMemo(create, deps);
1934 | }
1935 | function useImperativeHandle(ref, create, deps) {
1936 | var dispatcher = resolveDispatcher();
1937 | return dispatcher.useImperativeHandle(ref, create, deps);
1938 | }
1939 | function useDebugValue(value, formatterFn) {
1940 | {
1941 | var dispatcher = resolveDispatcher();
1942 | return dispatcher.useDebugValue(value, formatterFn);
1943 | }
1944 | }
1945 |
1946 | // Helpers to patch console.logs to avoid logging during side-effect free
1947 | // replaying on render function. This currently only patches the object
1948 | // lazily which won't cover if the log function was extracted eagerly.
1949 | // We could also eagerly patch the method.
1950 | var disabledDepth = 0;
1951 | var prevLog;
1952 | var prevInfo;
1953 | var prevWarn;
1954 | var prevError;
1955 | var prevGroup;
1956 | var prevGroupCollapsed;
1957 | var prevGroupEnd;
1958 |
1959 | function disabledLog() {}
1960 |
1961 | disabledLog.__reactDisabledLog = true;
1962 | function disableLogs() {
1963 | {
1964 | if (disabledDepth === 0) {
1965 | /* eslint-disable react-internal/no-production-logging */
1966 | prevLog = console.log;
1967 | prevInfo = console.info;
1968 | prevWarn = console.warn;
1969 | prevError = console.error;
1970 | prevGroup = console.group;
1971 | prevGroupCollapsed = console.groupCollapsed;
1972 | prevGroupEnd = console.groupEnd; // https://github.com/facebook/react/issues/19099
1973 |
1974 | var props = {
1975 | configurable: true,
1976 | enumerable: true,
1977 | value: disabledLog,
1978 | writable: true
1979 | }; // $FlowFixMe Flow thinks console is immutable.
1980 |
1981 | Object.defineProperties(console, {
1982 | info: props,
1983 | log: props,
1984 | warn: props,
1985 | error: props,
1986 | group: props,
1987 | groupCollapsed: props,
1988 | groupEnd: props
1989 | });
1990 | /* eslint-enable react-internal/no-production-logging */
1991 | }
1992 |
1993 | disabledDepth++;
1994 | }
1995 | }
1996 | function reenableLogs() {
1997 | {
1998 | disabledDepth--;
1999 |
2000 | if (disabledDepth === 0) {
2001 | /* eslint-disable react-internal/no-production-logging */
2002 | var props = {
2003 | configurable: true,
2004 | enumerable: true,
2005 | writable: true
2006 | }; // $FlowFixMe Flow thinks console is immutable.
2007 |
2008 | Object.defineProperties(console, {
2009 | log: _assign({}, props, {
2010 | value: prevLog
2011 | }),
2012 | info: _assign({}, props, {
2013 | value: prevInfo
2014 | }),
2015 | warn: _assign({}, props, {
2016 | value: prevWarn
2017 | }),
2018 | error: _assign({}, props, {
2019 | value: prevError
2020 | }),
2021 | group: _assign({}, props, {
2022 | value: prevGroup
2023 | }),
2024 | groupCollapsed: _assign({}, props, {
2025 | value: prevGroupCollapsed
2026 | }),
2027 | groupEnd: _assign({}, props, {
2028 | value: prevGroupEnd
2029 | })
2030 | });
2031 | /* eslint-enable react-internal/no-production-logging */
2032 | }
2033 |
2034 | if (disabledDepth < 0) {
2035 | error('disabledDepth fell below zero. ' + 'This is a bug in React. Please file an issue.');
2036 | }
2037 | }
2038 | }
2039 |
2040 | var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher;
2041 | var prefix;
2042 | function describeBuiltInComponentFrame(name, source, ownerFn) {
2043 | {
2044 | if (prefix === undefined) {
2045 | // Extract the VM specific prefix used by each line.
2046 | try {
2047 | throw Error();
2048 | } catch (x) {
2049 | var match = x.stack.trim().match(/\n( *(at )?)/);
2050 | prefix = match && match[1] || '';
2051 | }
2052 | } // We use the prefix to ensure our stacks line up with native stack frames.
2053 |
2054 |
2055 | return '\n' + prefix + name;
2056 | }
2057 | }
2058 | var reentry = false;
2059 | var componentFrameCache;
2060 |
2061 | {
2062 | var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
2063 | componentFrameCache = new PossiblyWeakMap();
2064 | }
2065 |
2066 | function describeNativeComponentFrame(fn, construct) {
2067 | // If something asked for a stack inside a fake render, it should get ignored.
2068 | if (!fn || reentry) {
2069 | return '';
2070 | }
2071 |
2072 | {
2073 | var frame = componentFrameCache.get(fn);
2074 |
2075 | if (frame !== undefined) {
2076 | return frame;
2077 | }
2078 | }
2079 |
2080 | var control;
2081 | reentry = true;
2082 | var previousPrepareStackTrace = Error.prepareStackTrace; // $FlowFixMe It does accept undefined.
2083 |
2084 | Error.prepareStackTrace = undefined;
2085 | var previousDispatcher;
2086 |
2087 | {
2088 | previousDispatcher = ReactCurrentDispatcher$1.current; // Set the dispatcher in DEV because this might be call in the render function
2089 | // for warnings.
2090 |
2091 | ReactCurrentDispatcher$1.current = null;
2092 | disableLogs();
2093 | }
2094 |
2095 | try {
2096 | // This should throw.
2097 | if (construct) {
2098 | // Something should be setting the props in the constructor.
2099 | var Fake = function () {
2100 | throw Error();
2101 | }; // $FlowFixMe
2102 |
2103 |
2104 | Object.defineProperty(Fake.prototype, 'props', {
2105 | set: function () {
2106 | // We use a throwing setter instead of frozen or non-writable props
2107 | // because that won't throw in a non-strict mode function.
2108 | throw Error();
2109 | }
2110 | });
2111 |
2112 | if (typeof Reflect === 'object' && Reflect.construct) {
2113 | // We construct a different control for this case to include any extra
2114 | // frames added by the construct call.
2115 | try {
2116 | Reflect.construct(Fake, []);
2117 | } catch (x) {
2118 | control = x;
2119 | }
2120 |
2121 | Reflect.construct(fn, [], Fake);
2122 | } else {
2123 | try {
2124 | Fake.call();
2125 | } catch (x) {
2126 | control = x;
2127 | }
2128 |
2129 | fn.call(Fake.prototype);
2130 | }
2131 | } else {
2132 | try {
2133 | throw Error();
2134 | } catch (x) {
2135 | control = x;
2136 | }
2137 |
2138 | fn();
2139 | }
2140 | } catch (sample) {
2141 | // This is inlined manually because closure doesn't do it for us.
2142 | if (sample && control && typeof sample.stack === 'string') {
2143 | // This extracts the first frame from the sample that isn't also in the control.
2144 | // Skipping one frame that we assume is the frame that calls the two.
2145 | var sampleLines = sample.stack.split('\n');
2146 | var controlLines = control.stack.split('\n');
2147 | var s = sampleLines.length - 1;
2148 | var c = controlLines.length - 1;
2149 |
2150 | while (s >= 1 && c >= 0 && sampleLines[s] !== controlLines[c]) {
2151 | // We expect at least one stack frame to be shared.
2152 | // Typically this will be the root most one. However, stack frames may be
2153 | // cut off due to maximum stack limits. In this case, one maybe cut off
2154 | // earlier than the other. We assume that the sample is longer or the same
2155 | // and there for cut off earlier. So we should find the root most frame in
2156 | // the sample somewhere in the control.
2157 | c--;
2158 | }
2159 |
2160 | for (; s >= 1 && c >= 0; s--, c--) {
2161 | // Next we find the first one that isn't the same which should be the
2162 | // frame that called our sample function and the control.
2163 | if (sampleLines[s] !== controlLines[c]) {
2164 | // In V8, the first line is describing the message but other VMs don't.
2165 | // If we're about to return the first line, and the control is also on the same
2166 | // line, that's a pretty good indicator that our sample threw at same line as
2167 | // the control. I.e. before we entered the sample frame. So we ignore this result.
2168 | // This can happen if you passed a class to function component, or non-function.
2169 | if (s !== 1 || c !== 1) {
2170 | do {
2171 | s--;
2172 | c--; // We may still have similar intermediate frames from the construct call.
2173 | // The next one that isn't the same should be our match though.
2174 |
2175 | if (c < 0 || sampleLines[s] !== controlLines[c]) {
2176 | // V8 adds a "new" prefix for native classes. Let's remove it to make it prettier.
2177 | var _frame = '\n' + sampleLines[s].replace(' at new ', ' at ');
2178 |
2179 | {
2180 | if (typeof fn === 'function') {
2181 | componentFrameCache.set(fn, _frame);
2182 | }
2183 | } // Return the line we found.
2184 |
2185 |
2186 | return _frame;
2187 | }
2188 | } while (s >= 1 && c >= 0);
2189 | }
2190 |
2191 | break;
2192 | }
2193 | }
2194 | }
2195 | } finally {
2196 | reentry = false;
2197 |
2198 | {
2199 | ReactCurrentDispatcher$1.current = previousDispatcher;
2200 | reenableLogs();
2201 | }
2202 |
2203 | Error.prepareStackTrace = previousPrepareStackTrace;
2204 | } // Fallback to just using the name if we couldn't make it throw.
2205 |
2206 |
2207 | var name = fn ? fn.displayName || fn.name : '';
2208 | var syntheticFrame = name ? describeBuiltInComponentFrame(name) : '';
2209 |
2210 | {
2211 | if (typeof fn === 'function') {
2212 | componentFrameCache.set(fn, syntheticFrame);
2213 | }
2214 | }
2215 |
2216 | return syntheticFrame;
2217 | }
2218 | function describeFunctionComponentFrame(fn, source, ownerFn) {
2219 | {
2220 | return describeNativeComponentFrame(fn, false);
2221 | }
2222 | }
2223 |
2224 | function shouldConstruct(Component) {
2225 | var prototype = Component.prototype;
2226 | return !!(prototype && prototype.isReactComponent);
2227 | }
2228 |
2229 | function describeUnknownElementTypeFrameInDEV(type, source, ownerFn) {
2230 |
2231 | if (type == null) {
2232 | return '';
2233 | }
2234 |
2235 | if (typeof type === 'function') {
2236 | {
2237 | return describeNativeComponentFrame(type, shouldConstruct(type));
2238 | }
2239 | }
2240 |
2241 | if (typeof type === 'string') {
2242 | return describeBuiltInComponentFrame(type);
2243 | }
2244 |
2245 | switch (type) {
2246 | case exports.Suspense:
2247 | return describeBuiltInComponentFrame('Suspense');
2248 |
2249 | case REACT_SUSPENSE_LIST_TYPE:
2250 | return describeBuiltInComponentFrame('SuspenseList');
2251 | }
2252 |
2253 | if (typeof type === 'object') {
2254 | switch (type.$$typeof) {
2255 | case REACT_FORWARD_REF_TYPE:
2256 | return describeFunctionComponentFrame(type.render);
2257 |
2258 | case REACT_MEMO_TYPE:
2259 | // Memo may contain any component type so we recursively resolve it.
2260 | return describeUnknownElementTypeFrameInDEV(type.type, source, ownerFn);
2261 |
2262 | case REACT_BLOCK_TYPE:
2263 | return describeFunctionComponentFrame(type._render);
2264 |
2265 | case REACT_LAZY_TYPE:
2266 | {
2267 | var lazyComponent = type;
2268 | var payload = lazyComponent._payload;
2269 | var init = lazyComponent._init;
2270 |
2271 | try {
2272 | // Lazy may contain any component type so we recursively resolve it.
2273 | return describeUnknownElementTypeFrameInDEV(init(payload), source, ownerFn);
2274 | } catch (x) {}
2275 | }
2276 | }
2277 | }
2278 |
2279 | return '';
2280 | }
2281 |
2282 | var loggedTypeFailures = {};
2283 | var ReactDebugCurrentFrame$1 = ReactSharedInternals.ReactDebugCurrentFrame;
2284 |
2285 | function setCurrentlyValidatingElement(element) {
2286 | {
2287 | if (element) {
2288 | var owner = element._owner;
2289 | var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
2290 | ReactDebugCurrentFrame$1.setExtraStackFrame(stack);
2291 | } else {
2292 | ReactDebugCurrentFrame$1.setExtraStackFrame(null);
2293 | }
2294 | }
2295 | }
2296 |
2297 | function checkPropTypes(typeSpecs, values, location, componentName, element) {
2298 | {
2299 | // $FlowFixMe This is okay but Flow doesn't know it.
2300 | var has = Function.call.bind(Object.prototype.hasOwnProperty);
2301 |
2302 | for (var typeSpecName in typeSpecs) {
2303 | if (has(typeSpecs, typeSpecName)) {
2304 | var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to
2305 | // fail the render phase where it didn't fail before. So we log it.
2306 | // After these have been cleaned up, we'll let them throw.
2307 |
2308 | try {
2309 | // This is intentionally an invariant that gets caught. It's the same
2310 | // behavior as without this statement except with a better message.
2311 | if (typeof typeSpecs[typeSpecName] !== 'function') {
2312 | var err = Error((componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' + 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.');
2313 | err.name = 'Invariant Violation';
2314 | throw err;
2315 | }
2316 |
2317 | error$1 = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED');
2318 | } catch (ex) {
2319 | error$1 = ex;
2320 | }
2321 |
2322 | if (error$1 && !(error$1 instanceof Error)) {
2323 | setCurrentlyValidatingElement(element);
2324 |
2325 | error('%s: type specification of %s' + ' `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error$1);
2326 |
2327 | setCurrentlyValidatingElement(null);
2328 | }
2329 |
2330 | if (error$1 instanceof Error && !(error$1.message in loggedTypeFailures)) {
2331 | // Only monitor this failure once because there tends to be a lot of the
2332 | // same error.
2333 | loggedTypeFailures[error$1.message] = true;
2334 | setCurrentlyValidatingElement(element);
2335 |
2336 | error('Failed %s type: %s', location, error$1.message);
2337 |
2338 | setCurrentlyValidatingElement(null);
2339 | }
2340 | }
2341 | }
2342 | }
2343 | }
2344 |
2345 | function setCurrentlyValidatingElement$1(element) {
2346 | {
2347 | if (element) {
2348 | var owner = element._owner;
2349 | var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
2350 | setExtraStackFrame(stack);
2351 | } else {
2352 | setExtraStackFrame(null);
2353 | }
2354 | }
2355 | }
2356 |
2357 | var propTypesMisspellWarningShown;
2358 |
2359 | {
2360 | propTypesMisspellWarningShown = false;
2361 | }
2362 |
2363 | function getDeclarationErrorAddendum() {
2364 | if (ReactCurrentOwner.current) {
2365 | var name = getComponentName(ReactCurrentOwner.current.type);
2366 |
2367 | if (name) {
2368 | return '\n\nCheck the render method of `' + name + '`.';
2369 | }
2370 | }
2371 |
2372 | return '';
2373 | }
2374 |
2375 | function getSourceInfoErrorAddendum(source) {
2376 | if (source !== undefined) {
2377 | var fileName = source.fileName.replace(/^.*[\\\/]/, '');
2378 | var lineNumber = source.lineNumber;
2379 | return '\n\nCheck your code at ' + fileName + ':' + lineNumber + '.';
2380 | }
2381 |
2382 | return '';
2383 | }
2384 |
2385 | function getSourceInfoErrorAddendumForProps(elementProps) {
2386 | if (elementProps !== null && elementProps !== undefined) {
2387 | return getSourceInfoErrorAddendum(elementProps.__source);
2388 | }
2389 |
2390 | return '';
2391 | }
2392 | /**
2393 | * Warn if there's no key explicitly set on dynamic arrays of children or
2394 | * object keys are not valid. This allows us to keep track of children between
2395 | * updates.
2396 | */
2397 |
2398 |
2399 | var ownerHasKeyUseWarning = {};
2400 |
2401 | function getCurrentComponentErrorInfo(parentType) {
2402 | var info = getDeclarationErrorAddendum();
2403 |
2404 | if (!info) {
2405 | var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
2406 |
2407 | if (parentName) {
2408 | info = "\n\nCheck the top-level render call using <" + parentName + ">.";
2409 | }
2410 | }
2411 |
2412 | return info;
2413 | }
2414 | /**
2415 | * Warn if the element doesn't have an explicit key assigned to it.
2416 | * This element is in an array. The array could grow and shrink or be
2417 | * reordered. All children that haven't already been validated are required to
2418 | * have a "key" property assigned to it. Error statuses are cached so a warning
2419 | * will only be shown once.
2420 | *
2421 | * @internal
2422 | * @param {ReactElement} element Element that requires a key.
2423 | * @param {*} parentType element's parent's type.
2424 | */
2425 |
2426 |
2427 | function validateExplicitKey(element, parentType) {
2428 | if (!element._store || element._store.validated || element.key != null) {
2429 | return;
2430 | }
2431 |
2432 | element._store.validated = true;
2433 | var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
2434 |
2435 | if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
2436 | return;
2437 | }
2438 |
2439 | ownerHasKeyUseWarning[currentComponentErrorInfo] = true; // Usually the current owner is the offender, but if it accepts children as a
2440 | // property, it may be the creator of the child that's responsible for
2441 | // assigning it a key.
2442 |
2443 | var childOwner = '';
2444 |
2445 | if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
2446 | // Give the component that originally created this child.
2447 | childOwner = " It was passed a child from " + getComponentName(element._owner.type) + ".";
2448 | }
2449 |
2450 | {
2451 | setCurrentlyValidatingElement$1(element);
2452 |
2453 | error('Each child in a list should have a unique "key" prop.' + '%s%s See https://reactjs.org/link/warning-keys for more information.', currentComponentErrorInfo, childOwner);
2454 |
2455 | setCurrentlyValidatingElement$1(null);
2456 | }
2457 | }
2458 | /**
2459 | * Ensure that every element either is passed in a static location, in an
2460 | * array with an explicit keys property defined, or in an object literal
2461 | * with valid key property.
2462 | *
2463 | * @internal
2464 | * @param {ReactNode} node Statically passed child of any type.
2465 | * @param {*} parentType node's parent's type.
2466 | */
2467 |
2468 |
2469 | function validateChildKeys(node, parentType) {
2470 | if (typeof node !== 'object') {
2471 | return;
2472 | }
2473 |
2474 | if (Array.isArray(node)) {
2475 | for (var i = 0; i < node.length; i++) {
2476 | var child = node[i];
2477 |
2478 | if (isValidElement(child)) {
2479 | validateExplicitKey(child, parentType);
2480 | }
2481 | }
2482 | } else if (isValidElement(node)) {
2483 | // This element was passed in a valid location.
2484 | if (node._store) {
2485 | node._store.validated = true;
2486 | }
2487 | } else if (node) {
2488 | var iteratorFn = getIteratorFn(node);
2489 |
2490 | if (typeof iteratorFn === 'function') {
2491 | // Entry iterators used to provide implicit keys,
2492 | // but now we print a separate warning for them later.
2493 | if (iteratorFn !== node.entries) {
2494 | var iterator = iteratorFn.call(node);
2495 | var step;
2496 |
2497 | while (!(step = iterator.next()).done) {
2498 | if (isValidElement(step.value)) {
2499 | validateExplicitKey(step.value, parentType);
2500 | }
2501 | }
2502 | }
2503 | }
2504 | }
2505 | }
2506 | /**
2507 | * Given an element, validate that its props follow the propTypes definition,
2508 | * provided by the type.
2509 | *
2510 | * @param {ReactElement} element
2511 | */
2512 |
2513 |
2514 | function validatePropTypes(element) {
2515 | {
2516 | var type = element.type;
2517 |
2518 | if (type === null || type === undefined || typeof type === 'string') {
2519 | return;
2520 | }
2521 |
2522 | var propTypes;
2523 |
2524 | if (typeof type === 'function') {
2525 | propTypes = type.propTypes;
2526 | } else if (typeof type === 'object' && (type.$$typeof === REACT_FORWARD_REF_TYPE || // Note: Memo only checks outer props here.
2527 | // Inner props are checked in the reconciler.
2528 | type.$$typeof === REACT_MEMO_TYPE)) {
2529 | propTypes = type.propTypes;
2530 | } else {
2531 | return;
2532 | }
2533 |
2534 | if (propTypes) {
2535 | // Intentionally inside to avoid triggering lazy initializers:
2536 | var name = getComponentName(type);
2537 | checkPropTypes(propTypes, element.props, 'prop', name, element);
2538 | } else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) {
2539 | propTypesMisspellWarningShown = true; // Intentionally inside to avoid triggering lazy initializers:
2540 |
2541 | var _name = getComponentName(type);
2542 |
2543 | error('Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?', _name || 'Unknown');
2544 | }
2545 |
2546 | if (typeof type.getDefaultProps === 'function' && !type.getDefaultProps.isReactClassApproved) {
2547 | error('getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.');
2548 | }
2549 | }
2550 | }
2551 | /**
2552 | * Given a fragment, validate that it can only be provided with fragment props
2553 | * @param {ReactElement} fragment
2554 | */
2555 |
2556 |
2557 | function validateFragmentProps(fragment) {
2558 | {
2559 | var keys = Object.keys(fragment.props);
2560 |
2561 | for (var i = 0; i < keys.length; i++) {
2562 | var key = keys[i];
2563 |
2564 | if (key !== 'children' && key !== 'key') {
2565 | setCurrentlyValidatingElement$1(fragment);
2566 |
2567 | error('Invalid prop `%s` supplied to `React.Fragment`. ' + 'React.Fragment can only have `key` and `children` props.', key);
2568 |
2569 | setCurrentlyValidatingElement$1(null);
2570 | break;
2571 | }
2572 | }
2573 |
2574 | if (fragment.ref !== null) {
2575 | setCurrentlyValidatingElement$1(fragment);
2576 |
2577 | error('Invalid attribute `ref` supplied to `React.Fragment`.');
2578 |
2579 | setCurrentlyValidatingElement$1(null);
2580 | }
2581 | }
2582 | }
2583 | function createElementWithValidation(type, props, children) {
2584 | var validType = isValidElementType(type); // We warn in this case but don't throw. We expect the element creation to
2585 | // succeed and there will likely be errors in render.
2586 |
2587 | if (!validType) {
2588 | var info = '';
2589 |
2590 | if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
2591 | info += ' You likely forgot to export your component from the file ' + "it's defined in, or you might have mixed up default and named imports.";
2592 | }
2593 |
2594 | var sourceInfo = getSourceInfoErrorAddendumForProps(props);
2595 |
2596 | if (sourceInfo) {
2597 | info += sourceInfo;
2598 | } else {
2599 | info += getDeclarationErrorAddendum();
2600 | }
2601 |
2602 | var typeString;
2603 |
2604 | if (type === null) {
2605 | typeString = 'null';
2606 | } else if (Array.isArray(type)) {
2607 | typeString = 'array';
2608 | } else if (type !== undefined && type.$$typeof === REACT_ELEMENT_TYPE) {
2609 | typeString = "<" + (getComponentName(type.type) || 'Unknown') + " />";
2610 | info = ' Did you accidentally export a JSX literal instead of a component?';
2611 | } else {
2612 | typeString = typeof type;
2613 | }
2614 |
2615 | {
2616 | error('React.createElement: type is invalid -- expected a string (for ' + 'built-in components) or a class/function (for composite ' + 'components) but got: %s.%s', typeString, info);
2617 | }
2618 | }
2619 |
2620 | var element = createElement.apply(this, arguments); // The result can be nullish if a mock or a custom function is used.
2621 | // TODO: Drop this when these are no longer allowed as the type argument.
2622 |
2623 | if (element == null) {
2624 | return element;
2625 | } // Skip key warning if the type isn't valid since our key validation logic
2626 | // doesn't expect a non-string/function type and can throw confusing errors.
2627 | // We don't want exception behavior to differ between dev and prod.
2628 | // (Rendering will throw with a helpful message and as soon as the type is
2629 | // fixed, the key warnings will appear.)
2630 |
2631 |
2632 | if (validType) {
2633 | for (var i = 2; i < arguments.length; i++) {
2634 | validateChildKeys(arguments[i], type);
2635 | }
2636 | }
2637 |
2638 | if (type === exports.Fragment) {
2639 | validateFragmentProps(element);
2640 | } else {
2641 | validatePropTypes(element);
2642 | }
2643 |
2644 | return element;
2645 | }
2646 | var didWarnAboutDeprecatedCreateFactory = false;
2647 | function createFactoryWithValidation(type) {
2648 | var validatedFactory = createElementWithValidation.bind(null, type);
2649 | validatedFactory.type = type;
2650 |
2651 | {
2652 | if (!didWarnAboutDeprecatedCreateFactory) {
2653 | didWarnAboutDeprecatedCreateFactory = true;
2654 |
2655 | warn('React.createFactory() is deprecated and will be removed in ' + 'a future major release. Consider using JSX ' + 'or use React.createElement() directly instead.');
2656 | } // Legacy hook: remove it
2657 |
2658 |
2659 | Object.defineProperty(validatedFactory, 'type', {
2660 | enumerable: false,
2661 | get: function () {
2662 | warn('Factory.type is deprecated. Access the class directly ' + 'before passing it to createFactory.');
2663 |
2664 | Object.defineProperty(this, 'type', {
2665 | value: type
2666 | });
2667 | return type;
2668 | }
2669 | });
2670 | }
2671 |
2672 | return validatedFactory;
2673 | }
2674 | function cloneElementWithValidation(element, props, children) {
2675 | var newElement = cloneElement.apply(this, arguments);
2676 |
2677 | for (var i = 2; i < arguments.length; i++) {
2678 | validateChildKeys(arguments[i], newElement.type);
2679 | }
2680 |
2681 | validatePropTypes(newElement);
2682 | return newElement;
2683 | }
2684 |
2685 | {
2686 |
2687 | try {
2688 | var frozenObject = Object.freeze({});
2689 | /* eslint-disable no-new */
2690 |
2691 | new Map([[frozenObject, null]]);
2692 | new Set([frozenObject]);
2693 | /* eslint-enable no-new */
2694 | } catch (e) {
2695 | }
2696 | }
2697 |
2698 | var createElement$1 = createElementWithValidation ;
2699 | var cloneElement$1 = cloneElementWithValidation ;
2700 | var createFactory = createFactoryWithValidation ;
2701 | var Children = {
2702 | map: mapChildren,
2703 | forEach: forEachChildren,
2704 | count: countChildren,
2705 | toArray: toArray,
2706 | only: onlyChild
2707 | };
2708 |
2709 | exports.Children = Children;
2710 | exports.Component = Component;
2711 | exports.PureComponent = PureComponent;
2712 | exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = ReactSharedInternals;
2713 | exports.cloneElement = cloneElement$1;
2714 | exports.createContext = createContext;
2715 | exports.createElement = createElement$1;
2716 | exports.createFactory = createFactory;
2717 | exports.createRef = createRef;
2718 | exports.forwardRef = forwardRef;
2719 | exports.isValidElement = isValidElement;
2720 | exports.lazy = lazy;
2721 | exports.memo = memo;
2722 | exports.useCallback = useCallback;
2723 | exports.useContext = useContext;
2724 | exports.useDebugValue = useDebugValue;
2725 | exports.useEffect = useEffect;
2726 | exports.useImperativeHandle = useImperativeHandle;
2727 | exports.useLayoutEffect = useLayoutEffect;
2728 | exports.useMemo = useMemo;
2729 | exports.useReducer = useReducer;
2730 | exports.useRef = useRef;
2731 | exports.useState = useState;
2732 | exports.version = ReactVersion;
2733 | })();
2734 | }
2735 | });
2736 | react_development.Fragment;
2737 | react_development.StrictMode;
2738 | react_development.Profiler;
2739 | react_development.Suspense;
2740 | react_development.Children;
2741 | react_development.Component;
2742 | react_development.PureComponent;
2743 | react_development.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2744 | react_development.cloneElement;
2745 | react_development.createContext;
2746 | react_development.createElement;
2747 | react_development.createFactory;
2748 | react_development.createRef;
2749 | react_development.forwardRef;
2750 | react_development.isValidElement;
2751 | react_development.lazy;
2752 | react_development.memo;
2753 | react_development.useCallback;
2754 | react_development.useContext;
2755 | react_development.useDebugValue;
2756 | react_development.useEffect;
2757 | react_development.useImperativeHandle;
2758 | react_development.useLayoutEffect;
2759 | react_development.useMemo;
2760 | react_development.useReducer;
2761 | react_development.useRef;
2762 | react_development.useState;
2763 | react_development.version;
2764 |
2765 | var React = createCommonjsModule(function (module) {
2766 |
2767 | if (process.env.NODE_ENV === 'production') {
2768 | module.exports = react_production_min;
2769 | } else {
2770 | module.exports = react_development;
2771 | }
2772 | });
2773 |
2774 | var Gutter = /*#__PURE__*/function (_React$Component) {
2775 | _inherits(Gutter, _React$Component);
2776 |
2777 | var _super = _createSuper(Gutter);
2778 |
2779 | function Gutter(props) {
2780 | var _this;
2781 |
2782 | _classCallCheck(this, Gutter);
2783 |
2784 | _this = _super.call(this, props);
2785 |
2786 | _this.handleMouseDownAndTouchStart = function (e) {
2787 | var onMouseDownAndTouchStart = _this.props.onMouseDownAndTouchStart;
2788 | onMouseDownAndTouchStart(e);
2789 | };
2790 |
2791 | _this.elementRef = React.createRef();
2792 | return _this;
2793 | }
2794 |
2795 | _createClass(Gutter, [{
2796 | key: "componentDidMount",
2797 | value: function componentDidMount() {
2798 | // There's no way in React 16 to add passive false event listeners
2799 | // which means there is no way to drag a splitter and prevent mobile browsers
2800 | // from scrolling without doing this manually.
2801 | var elem = this.elementRef.current;
2802 | elem.addEventListener('mousedown', this.handleMouseDownAndTouchStart, {
2803 | passive: false
2804 | });
2805 | elem.addEventListener('touchstart', this.handleMouseDownAndTouchStart, {
2806 | passive: false
2807 | });
2808 | }
2809 | }, {
2810 | key: "componentWillUnmount",
2811 | value: function componentWillUnmount() {
2812 | var elem = this.elementRef.current;
2813 | elem.removeEventListener('mousedown', this.handleMouseDownAndTouchStart);
2814 | elem.removeEventListener('touchstart', this.handleMouseDownAndTouchStart);
2815 | }
2816 | }, {
2817 | key: "render",
2818 | value: function render() {
2819 | var _this$props = this.props,
2820 | direction = _this$props.direction,
2821 | dragging = _this$props.dragging,
2822 | current = _this$props.current,
2823 | style = _this$props.style,
2824 | gutterClassName = _this$props.gutterClassName;
2825 | return /*#__PURE__*/React.createElement("div", {
2826 | ref: this.elementRef,
2827 | className: "".concat(gutterClassName, " ").concat(gutterClassName, "-").concat(direction, " ").concat(dragging && current ? "".concat(gutterClassName, "-dragging") : ''),
2828 | style: style
2829 | });
2830 | }
2831 | }]);
2832 |
2833 | return Gutter;
2834 | }(React.Component);
2835 |
2836 | function computeSize(sizes, start, end) {
2837 | var size = 0;
2838 |
2839 | for (var i = start; i < end; ++i) {
2840 | size += sizes[i];
2841 | }
2842 |
2843 | return size;
2844 | }
2845 |
2846 | function moveGuttersComputeNewSizes(_ref) {
2847 | var startSizes = _ref.startSizes,
2848 | prevPaneNdx = _ref.prevPaneNdx,
2849 | minSize = _ref.minSize,
2850 | delta = _ref.delta;
2851 | var nextPaneNdx = prevPaneNdx + 1; // 0 1 2 3
2852 | // |---------|---prev--G--next---|------|
2853 | // u
2854 | // t
2855 | // t
2856 | // e
2857 | // r
2858 |
2859 | if (delta < 0) {
2860 | // we're dragging gutter left
2861 | var minSizeBeforeNext = nextPaneNdx * minSize;
2862 | var currentSizeBeforeNext = computeSize(startSizes, 0, nextPaneNdx);
2863 | var movableSize = currentSizeBeforeNext - minSizeBeforeNext;
2864 | var totalDelta = Math.min(-delta, movableSize); // distribute the delta to the left
2865 |
2866 | var newSizes = startSizes.slice();
2867 | newSizes[nextPaneNdx] += totalDelta;
2868 |
2869 | for (var i = prevPaneNdx; totalDelta > 0 || i >= 0; --i) {
2870 | var oldSize = newSizes[i];
2871 | var newSize = Math.max(oldSize - totalDelta, minSize);
2872 | newSizes[i] = newSize;
2873 | totalDelta -= oldSize - newSize;
2874 | }
2875 |
2876 | return newSizes;
2877 | } else {
2878 | // we're dragging gutter right
2879 | var minSizeAfterPrev = (startSizes.length - nextPaneNdx) * minSize;
2880 | var currentSizeAfterPrev = computeSize(startSizes, nextPaneNdx, startSizes.length);
2881 |
2882 | var _movableSize = currentSizeAfterPrev - minSizeAfterPrev;
2883 |
2884 | var _totalDelta = Math.min(delta, _movableSize); // distribute the delta to the right
2885 |
2886 |
2887 | var _newSizes = startSizes.slice();
2888 |
2889 | _newSizes[prevPaneNdx] += _totalDelta;
2890 |
2891 | for (var _i = nextPaneNdx; _totalDelta > 0 && _i < _newSizes.length; ++_i) {
2892 | var _oldSize = _newSizes[_i];
2893 |
2894 | var _newSize = Math.max(_oldSize - _totalDelta, minSize);
2895 |
2896 | _newSizes[_i] = _newSize;
2897 | _totalDelta -= _oldSize - _newSize;
2898 | }
2899 |
2900 | return _newSizes;
2901 | }
2902 | }
2903 |
2904 | function stableGuttersComputeNewSizes(_ref) {
2905 | var startSizes = _ref.startSizes,
2906 | prevPaneNdx = _ref.prevPaneNdx,
2907 | minSize = _ref.minSize,
2908 | delta = _ref.delta;
2909 | var nextPaneNdx = prevPaneNdx + 1;
2910 | var pairSize = startSizes[prevPaneNdx] + startSizes[nextPaneNdx];
2911 | var prevPaneStartSize = startSizes[prevPaneNdx];
2912 | var prevPaneNewSize = Math.min(Math.max(minSize, prevPaneStartSize + delta), pairSize - minSize);
2913 | var nextPaneNewSize = pairSize - prevPaneNewSize;
2914 | var newSizes = [].concat(_toConsumableArray(startSizes.slice(0, prevPaneNdx)), [prevPaneNewSize, nextPaneNewSize], _toConsumableArray(startSizes.slice(prevPaneNdx + 2, startSizes.length)));
2915 | return newSizes;
2916 | }
2917 |
2918 | function normalizeSizes(sizes) {
2919 | var totalSize = sizes.reduce(function (sum, v) {
2920 | return sum + v;
2921 | }, 0);
2922 | return sizes.map(function (v) {
2923 | return v / totalSize;
2924 | });
2925 | }
2926 |
2927 | var getMouseOrTouchPosition = function getMouseOrTouchPosition(e, clientAxis) {
2928 | return e.touches ? e.touches[0][clientAxis] : e[clientAxis];
2929 | };
2930 |
2931 | function addSpaceForChildren(sizes, numChildren, gutterSize, minSizePX, totalSizePX) {
2932 | // const numGutters = numChildren - 1;
2933 | // const totalGutterSpacePX = numGutters * gutterSize;
2934 | // const availableSpacePX = totalSizePX - totalGutterSpacePX;
2935 | //
2936 | // this is not so trivial
2937 | // let's say we have 3 items and we add 2 more.
2938 | // each of those 2 has a minSize. So need to take 2 * minSize
2939 | // from the 3 items or (2 * minSize / 3). But any of those items
2940 | // themselves might already be at or near minSize
2941 | //
2942 | // This seems like it's then iterative.
2943 | //
2944 | // go through and try to remove (minSize * numNewElements / numOldElements)
2945 | // from each old element but only remove such that that element
2946 | // is still >= minSize. When done there's possibly some amount
2947 | // you haven't distributed yet so repeat the process over and over
2948 | // until it's all distributed.
2949 | //
2950 | // given that we don't know which elements are new, for now
2951 | // lets just reset all the sizes
2952 | return new Array(numChildren).fill(1 / numChildren);
2953 | }
2954 |
2955 | var getDirectionProps = function getDirectionProps(direction) {
2956 | return direction === 'horizontal' ? {
2957 | dimension: 'width',
2958 | clientAxis: 'clientX',
2959 | position: 'left',
2960 | positionEnd: 'right',
2961 | clientSize: 'clientWidth'
2962 | } : {
2963 | dimension: 'height',
2964 | clientAxis: 'clientY',
2965 | position: 'top',
2966 | positionEnd: 'bottom',
2967 | clientSize: 'clientHeight'
2968 | };
2969 | };
2970 |
2971 | var stopMobileBrowserFromScrolling = function stopMobileBrowserFromScrolling(e) {
2972 | return e.preventDefault();
2973 | };
2974 |
2975 | var Split = /*#__PURE__*/function (_React$Component) {
2976 | _inherits(Split, _React$Component);
2977 |
2978 | var _super = _createSuper(Split);
2979 |
2980 | function Split(props) {
2981 | var _this;
2982 |
2983 | _classCallCheck(this, Split);
2984 |
2985 | _this = _super.call(this, props);
2986 |
2987 | _this._setSizes = function (sizes) {
2988 | _this.setState({
2989 | sizes: sizes
2990 | });
2991 | };
2992 |
2993 | _this.handleMouseUpAndTouchEnd = function () {
2994 | document.removeEventListener("mousemove", _this.handleMouseAndTouchMove);
2995 | document.removeEventListener("mouseup", _this.handleMouseUpAndTouchEnd);
2996 | document.removeEventListener("touchmove", _this.handleMouseAndTouchMove);
2997 | document.removeEventListener("touchend", _this.handleMouseUpAndTouchEnd);
2998 |
2999 | _this.setState({
3000 | dragging: false
3001 | });
3002 | };
3003 |
3004 | _this.handleMouseAndTouchMove = function (e) {
3005 | stopMobileBrowserFromScrolling(e);
3006 | var _this$props = _this.props,
3007 | gutterSize = _this$props.gutterSize,
3008 | direction = _this$props.direction,
3009 | minSize = _this$props.minSize,
3010 | computeNewSizesFn = _this$props.computeNewSizesFn,
3011 | onSetSizes = _this$props.onSetSizes,
3012 | propSizes = _this$props.sizes;
3013 | var _this$state = _this.state,
3014 | prevPaneNdx = _this$state.prevPaneNdx,
3015 | mouseStart = _this$state.mouseStart,
3016 | startSizes = _this$state.startSizes,
3017 | stateSizes = _this$state.sizes;
3018 | var setSizes = onSetSizes || _this._setSizes;
3019 | var sizes = onSetSizes ? propSizes : stateSizes;
3020 |
3021 | var _getDirectionProps = getDirectionProps(direction),
3022 | clientAxis = _getDirectionProps.clientAxis,
3023 | clientSize = _getDirectionProps.clientSize;
3024 |
3025 | var numPanes = sizes.length;
3026 | var numGutters = numPanes - 1;
3027 | var totalGutterSizePX = numGutters * gutterSize;
3028 | var deltaPX = getMouseOrTouchPosition(e, clientAxis) - mouseStart;
3029 | var outerSizePX = _this.elementRef.current[clientSize];
3030 | var innerSizePX = outerSizePX - totalGutterSizePX;
3031 | var newSizes = computeNewSizesFn({
3032 | startSizes: startSizes,
3033 | prevPaneNdx: prevPaneNdx,
3034 | minSize: minSize / innerSizePX,
3035 | minSizePX: minSize,
3036 | innerSizePX: innerSizePX,
3037 | delta: deltaPX / innerSizePX,
3038 | deltaPX: deltaPX
3039 | });
3040 | setSizes(newSizes);
3041 | };
3042 |
3043 | _this.handleMouseDownAndTouchStart = function (e) {
3044 | stopMobileBrowserFromScrolling(e);
3045 | var _this$props2 = _this.props,
3046 | direction = _this$props2.direction,
3047 | onSetSizes = _this$props2.onSetSizes,
3048 | propsSizes = _this$props2.sizes;
3049 |
3050 | var _getDirectionProps2 = getDirectionProps(direction),
3051 | clientAxis = _getDirectionProps2.clientAxis;
3052 |
3053 | document.addEventListener("mousemove", _this.handleMouseAndTouchMove, {
3054 | passive: false
3055 | });
3056 | document.addEventListener("mouseup", _this.handleMouseUpAndTouchEnd);
3057 | document.addEventListener("touchmove", _this.handleMouseAndTouchMove, {
3058 | passive: false
3059 | });
3060 | document.addEventListener("touchend", _this.handleMouseUpAndTouchEnd);
3061 | var gutterNdx = Array.prototype.indexOf.call(e.target.parentElement.children, e.target);
3062 | var prevPaneNdx = (gutterNdx - 1) / 2;
3063 | var sizes = onSetSizes ? propsSizes : _this.state.sizes;
3064 | var startSizes = sizes.slice();
3065 |
3066 | _this.setState({
3067 | startSizes: startSizes,
3068 | mouseStart: getMouseOrTouchPosition(e, clientAxis),
3069 | prevPaneNdx: prevPaneNdx,
3070 | dragging: true
3071 | });
3072 | };
3073 |
3074 | _this.recomputeSizes = function () {
3075 | // here it's not entirely clear what to do. Maybe we need options
3076 | // If they user removes a child which sizes do they want? I guess
3077 | // since they removed a child they passed in new sizes so we should
3078 | // pass sizes back? Ugh!
3079 | //
3080 | // Example:
3081 | //
3082 | // * start: 3 panes, sizes a(33%), b(33%), c(33%)
3083 | // * user adjusts to sizes a(10%), b(80%), c(10%)
3084 | // * user deletes pane (a)
3085 | //
3086 | // If we just continue to use the current sizes the we'd get
3087 | //
3088 | // b(10%), c(90%)
3089 | //
3090 | // We have no way of knowing that b should get the 90%
3091 | //
3092 | // One way would be to pass responsibility for saving the sizes
3093 | // up to the parent. Basically if you want to add/remove children
3094 | // then you need need to keep their state. In that case
3095 | // passing an `onSetSize` prop. It's a function that will be called
3096 | // with an array of sizes. Update your sizes and pass them in as
3097 | // props
3098 | //
3099 | // But, just so we don't completely fail if the user has not opted
3100 | // into managing the size state then at least do something.
3101 | var sizes = _this.state.sizes;
3102 | var _this$props3 = _this.props,
3103 | minSize = _this$props3.minSize,
3104 | direction = _this$props3.direction,
3105 | gutterSize = _this$props3.gutterSize;
3106 |
3107 | var _getDirectionProps3 = getDirectionProps(direction),
3108 | clientSize = _getDirectionProps3.clientSize;
3109 |
3110 | var numChildren = React__default["default"].Children.count(_this.props.children);
3111 | var newSizes = numChildren < sizes.length // a child was removed, normalizes the sizes
3112 | ? normalizeSizes(sizes.slice(0, numChildren)) // children were added, make space for them
3113 | : addSpaceForChildren(sizes, numChildren, gutterSize, minSize, _this.elementRef.current.parentElement[clientSize]);
3114 |
3115 | _this._setSizes(newSizes);
3116 | };
3117 |
3118 | var children = props.children,
3119 | _sizes = props.sizes,
3120 | _onSetSizes = props.onSetSizes;
3121 |
3122 | var _numPanes = React__default["default"].Children.count(children);
3123 |
3124 | var size = 1 / _numPanes;
3125 | _this.state = {
3126 | sizes: _sizes ? _onSetSizes ? _sizes : normalizeSizes(_sizes) : new Array(_numPanes).fill(size)
3127 | };
3128 | _this.elementRef = /*#__PURE__*/React__default["default"].createRef();
3129 | return _this;
3130 | }
3131 |
3132 | _createClass(Split, [{
3133 | key: "componentDidUpdate",
3134 | value: function componentDidUpdate() {
3135 | var _this$props4 = this.props,
3136 | children = _this$props4.children,
3137 | onSetSizes = _this$props4.onSetSizes; // we need to check if new elements were added.
3138 |
3139 | if (onSetSizes) {
3140 | return; // not our responsibility
3141 | }
3142 |
3143 | var sizes = this.state.sizes;
3144 | var numChildren = React__default["default"].Children.count(children);
3145 |
3146 | if (sizes.length !== numChildren) {
3147 | this.recomputeSizes();
3148 | }
3149 | }
3150 | }, {
3151 | key: "render",
3152 | value: function render() {
3153 | var _this2 = this;
3154 |
3155 | var _this$props5 = this.props,
3156 | children = _this$props5.children,
3157 | direction = _this$props5.direction,
3158 | gutterSize = _this$props5.gutterSize,
3159 | propSizes = _this$props5.sizes,
3160 | onSetSizes = _this$props5.onSetSizes;
3161 | _this$props5.minSize;
3162 | var splitClassName = _this$props5.className,
3163 | gutterClassName = _this$props5.gutterClassName,
3164 | paneClassName = _this$props5.paneClassName;
3165 | var _this$state2 = this.state,
3166 | dragging = _this$state2.dragging,
3167 | prevPaneNdx = _this$state2.prevPaneNdx,
3168 | stateSizes = _this$state2.sizes;
3169 | var sizes = onSetSizes ? propSizes : stateSizes;
3170 | var gutterStyle = {
3171 | flexBasis: gutterSize ? "".concat(gutterSize, "px") : '0'
3172 | };
3173 | var childNdx = 0;
3174 | var first = true;
3175 | var newChildren = [];
3176 | React__default["default"].Children.forEach(children, function (child) {
3177 | if (! /*#__PURE__*/React__default["default"].isValidElement(child)) {
3178 | return null;
3179 | }
3180 |
3181 | if (!first) {
3182 | newChildren.push( /*#__PURE__*/React__default["default"].createElement(Gutter, {
3183 | key: "gutter".concat(newChildren.length),
3184 | direction: direction,
3185 | dragging: dragging,
3186 | current: dragging && childNdx === prevPaneNdx + 1,
3187 | style: gutterStyle,
3188 | gutterClassName: gutterClassName,
3189 | onMouseDownAndTouchStart: _this2.handleMouseDownAndTouchStart
3190 | }));
3191 | }
3192 |
3193 | var style = {
3194 | flexBasis: "".concat(sizes[childNdx] * 100, "%")
3195 | };
3196 | var className = classNames(paneClassName, _defineProperty({}, "".concat(paneClassName, "-dragging"), dragging));
3197 | newChildren.push( /*#__PURE__*/React__default["default"].createElement("div", {
3198 | key: "pane".concat(newChildren.length),
3199 | className: className,
3200 | style: style
3201 | }, /*#__PURE__*/React__default["default"].cloneElement(child)));
3202 | first = false;
3203 | ++childNdx;
3204 | });
3205 | return /*#__PURE__*/React__default["default"].createElement("div", {
3206 | className: classNames(splitClassName, "".concat(splitClassName, "-").concat(direction), _defineProperty({}, "".concat(splitClassName, "-dragging"), dragging)),
3207 | ref: this.elementRef,
3208 | style: _objectSpread2(_objectSpread2({}, this.props.style), dragging && {
3209 | userSelect: 'none'
3210 | })
3211 | }, newChildren, dragging ? /*#__PURE__*/React__default["default"].createElement("style", null, "iframe ", '{', "pointer-events: none !important;", '}') : []);
3212 | }
3213 | }]);
3214 |
3215 | return Split;
3216 | }(React__default["default"].Component);
3217 | Split.defaultProps = {
3218 | className: 'split',
3219 | gutterClassName: 'gutter',
3220 | paneClassName: 'pane',
3221 | gutterSize: 10,
3222 | minSize: 10,
3223 | direction: 'horizontal',
3224 | computeNewSizesFn: stableGuttersComputeNewSizes
3225 | };
3226 | Split.propTypes = {
3227 | direction: PropTypes__default["default"].oneOf(['horizontal', 'vertical']),
3228 | sizes: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
3229 | minSize: PropTypes__default["default"].number,
3230 | gutterSize: PropTypes__default["default"].number,
3231 | className: PropTypes__default["default"].string,
3232 | gutterClassName: PropTypes__default["default"].string,
3233 | paneClassName: PropTypes__default["default"].string,
3234 | onSetSizes: PropTypes__default["default"].func,
3235 | computeNewSizesFn: PropTypes__default["default"].func
3236 | };
3237 | Split.moveGuttersComputeNewSizes = moveGuttersComputeNewSizes;
3238 | Split.stableGuttersComputeNewSizes = stableGuttersComputeNewSizes;
3239 |
3240 | exports["default"] = Split;
3241 | exports.moveGuttersComputeNewSizes = moveGuttersComputeNewSizes;
3242 | exports.stableGuttersComputeNewSizes = stableGuttersComputeNewSizes;
3243 |
--------------------------------------------------------------------------------
/examples/AddRemovePanes.css:
--------------------------------------------------------------------------------
1 | .add-remove-panes {
2 | height: 100px;
3 | }
4 |
5 | .add-remove-panes .pane .buttons {
6 | position: absolute;
7 | top: 0;
8 | right: 0;
9 | display: flex;
10 | flex-direction: column;
11 | }
12 | .add-remove-panes .pane button {
13 | border: none;
14 | outline: none;
15 | padding: 0;
16 | user-select: none;
17 | background: transparent;
18 | }
19 | .add-remove-panes .pane button:hover {
20 | color: red;
21 | cursor: pointer;
22 | }
23 |
--------------------------------------------------------------------------------
/examples/AddRemovePanes.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import Split from 'react-split-it';
3 | import './example-split.css';
4 | import './AddRemovePanes.css';
5 |
6 | let id = 0;
7 | const genName = _ => `pane${id++}`;
8 |
9 | export default class AddRemovePanes extends React.Component {
10 | constructor(props) {
11 | super(props);
12 | this.state = {panes: [genName(), genName()]};
13 | }
14 | addPane = () => {
15 | const {panes} = this.state;
16 | this.setState({panes: [...panes, genName()]});
17 | };
18 | deletePane = (i) => {
19 | const {panes} = this.state;
20 | this.setState({
21 | panes: [
22 | ...panes.slice(0, i),
23 | ...panes.slice(i + 1),
24 | ],
25 | });
26 | };
27 | render() {
28 | const {panes} = this.state
29 | return (
30 |
This is the simplest example of a computeNewSizes function but it is incomplete
70 | because it does not check for minimum sizes or even size < 0.
71 | To see the issue drag a gutter past any other gutter.
72 | For more info see the docs.
This is the simplest example of a computeNewSizes function but it is incomplete
70 | because it does not check for minimum sizes or even size < 0.
71 | To see the issue drag a gutter past any other gutter.
72 | For more info see the docs.
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-split-it",
3 | "description": "splitter for react",
4 | "version": "2.0.0",
5 | "main": "dist/react-split-it.umd.js",
6 | "module": "dist/react-split-it.cjs.js",
7 | "source": "src/split.js",
8 | "repository": {
9 | "type": "git",
10 | "url": "https://github.com/greggman/react-split-it"
11 | },
12 | "bugs": {
13 | "url": "https://github.com/greggman/react-split-it/issues"
14 | },
15 | "author": "Gregg Tavares ",
16 | "homepage": "https://greggman.github.io/react-split-it/",
17 | "license": "MIT",
18 | "keywords": [
19 | "react",
20 | "react-component",
21 | "split-pane",
22 | "react-split-it"
23 | ],
24 | "dependencies": {
25 | "prop-types": "^15.8.1"
26 | },
27 | "peerDependencies": {
28 | "react": ">= 17.0.0"
29 | },
30 | "files": [
31 | "dist",
32 | "src"
33 | ],
34 | "scripts": {
35 | "build": "rollup -c",
36 | "watch": "rollup -cw"
37 | },
38 | "devDependencies": {
39 | "@babel/core": "^7.16.7",
40 | "@babel/plugin-proposal-class-properties": "^7.16.7",
41 | "@babel/preset-env": "^7.16.8",
42 | "@babel/preset-react": "^7.16.7",
43 | "react": "^17.0.2",
44 | "react-dom": "^17.0.2",
45 | "rollup": "^2.63.0",
46 | "rollup-plugin-babel": "^4.4.0",
47 | "rollup-plugin-commonjs": "^10.1.0",
48 | "rollup-plugin-node-globals": "^1.4.0",
49 | "rollup-plugin-node-resolve": "^5.2.0"
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/resources/logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
24 |
--------------------------------------------------------------------------------
/resources/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/greggman/react-split-it/1d80e603fcfbb4db6520c1e22d7bfb080bd4b528/resources/logo192.png
--------------------------------------------------------------------------------
/resources/logo32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/greggman/react-split-it/1d80e603fcfbb4db6520c1e22d7bfb080bd4b528/resources/logo32.png
--------------------------------------------------------------------------------
/resources/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/greggman/react-split-it/1d80e603fcfbb4db6520c1e22d7bfb080bd4b528/resources/logo512.png
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import babel from 'rollup-plugin-babel';
2 | import commonjs from 'rollup-plugin-commonjs';
3 | import resolve from 'rollup-plugin-node-resolve';
4 | import globals from 'rollup-plugin-node-globals';
5 |
6 | import pkg from './package.json';
7 |
8 | const commonOptions = {
9 | external: [
10 | ...Object.keys(pkg.dependencies),
11 | ...Object.keys(pkg.peerDependencies),
12 | ],
13 | plugins: [
14 | babel({
15 | exclude: 'node_modules/**',
16 | }),
17 | resolve(),
18 | commonjs(),
19 | ],
20 | watch: {
21 | include: 'src/**',
22 | },
23 | }
24 |
25 | export default [
26 | {
27 | input: pkg.source,
28 | output: {
29 | file: pkg.module,
30 | format: 'cjs',
31 | exports: 'named',
32 | },
33 | ...commonOptions,
34 | },
35 | {
36 | input: 'src/umd.js',
37 | output: {
38 | file: pkg.main,
39 | format: 'umd',
40 | exports: 'default',
41 | name: 'Split',
42 | globals: {
43 | react: 'React',
44 | 'prop-types': 'PropTypes',
45 | },
46 | },
47 | ...commonOptions,
48 | plugins: commonOptions.plugins.concat([globals()]),
49 | },
50 | ];
--------------------------------------------------------------------------------
/src/css-utils.js:
--------------------------------------------------------------------------------
1 | const camelCaseRE = /([a-z])([A-Z])/g;
2 | const toDash = (_, left, right) => `${left}-${right}`;
3 | const camelCaseToDash = s => s.replace(camelCaseRE, toDash).toLowerCase();
4 |
5 | export function classNames(...args) {
6 | const names = [];
7 | for (const arg of args) {
8 | if (typeof arg === 'string') {
9 | names.push(arg);
10 | } else {
11 | for (const [key, value] of Object.entries(arg)) {
12 | if (value) {
13 | names.push(camelCaseToDash(key));
14 | }
15 | }
16 | }
17 | }
18 | return names.join(' ');
19 | }
--------------------------------------------------------------------------------
/src/gutter.js:
--------------------------------------------------------------------------------
1 | import React from 'React';
2 |
3 | export default class Gutter extends React.Component {
4 | constructor(props) {
5 | super(props);
6 | this.elementRef = React.createRef();
7 | }
8 | handleMouseDownAndTouchStart = (e) => {
9 | const {onMouseDownAndTouchStart} = this.props;
10 | onMouseDownAndTouchStart(e);
11 | }
12 | componentDidMount() {
13 | // There's no way in React 16 to add passive false event listeners
14 | // which means there is no way to drag a splitter and prevent mobile browsers
15 | // from scrolling without doing this manually.
16 | const elem = this.elementRef.current;
17 | elem.addEventListener('mousedown', this.handleMouseDownAndTouchStart, {passive: false});
18 | elem.addEventListener('touchstart', this.handleMouseDownAndTouchStart, {passive: false});
19 | }
20 | componentWillUnmount() {
21 | const elem = this.elementRef.current;
22 | elem.removeEventListener('mousedown', this.handleMouseDownAndTouchStart);
23 | elem.removeEventListener('touchstart', this.handleMouseDownAndTouchStart);
24 | }
25 | render() {
26 | const {direction, dragging, current, style, gutterClassName} = this.props;
27 | return (
28 |
33 | );
34 | }
35 | }
--------------------------------------------------------------------------------
/src/move-gutters-compute-new-sizes.js:
--------------------------------------------------------------------------------
1 | function computeSize(sizes, start, end) {
2 | let size = 0;
3 | for (let i = start; i < end; ++i) {
4 | size += sizes[i];
5 | }
6 | return size;
7 | }
8 |
9 | export default function moveGuttersComputeNewSizes({
10 | startSizes,
11 | prevPaneNdx,
12 | minSize,
13 | delta,
14 | }) {
15 | const nextPaneNdx = prevPaneNdx + 1;
16 | // 0 1 2 3
17 | // |---------|---prev--G--next---|------|
18 | // u
19 | // t
20 | // t
21 | // e
22 | // r
23 | if (delta < 0) {
24 | // we're dragging gutter left
25 | const minSizeBeforeNext = nextPaneNdx * minSize;
26 | const currentSizeBeforeNext = computeSize(startSizes, 0, nextPaneNdx);
27 | const movableSize = currentSizeBeforeNext - minSizeBeforeNext;
28 | let totalDelta = Math.min(-delta, movableSize);
29 | // distribute the delta to the left
30 | const newSizes = startSizes.slice();
31 | newSizes[nextPaneNdx] += totalDelta;
32 | for (let i = prevPaneNdx; totalDelta > 0 || i >= 0; --i) {
33 | const oldSize = newSizes[i];
34 | const newSize = Math.max(oldSize - totalDelta, minSize);
35 | newSizes[i] = newSize;
36 | totalDelta -= oldSize - newSize;
37 | }
38 | return newSizes;
39 | } else {
40 | // we're dragging gutter right
41 | const minSizeAfterPrev = (startSizes.length - nextPaneNdx) * minSize;
42 | const currentSizeAfterPrev = computeSize(startSizes, nextPaneNdx, startSizes.length);
43 | const movableSize = currentSizeAfterPrev - minSizeAfterPrev;
44 | let totalDelta = Math.min(delta, movableSize);
45 | // distribute the delta to the right
46 | const newSizes = startSizes.slice();
47 | newSizes[prevPaneNdx] += totalDelta;
48 | for (let i = nextPaneNdx; totalDelta > 0 && i < newSizes.length; ++i) {
49 | const oldSize = newSizes[i];
50 | const newSize = Math.max(oldSize - totalDelta, minSize);
51 | newSizes[i] = newSize;
52 | totalDelta -= oldSize - newSize;
53 | }
54 | return newSizes;
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/src/split.js:
--------------------------------------------------------------------------------
1 | import PropTypes from 'prop-types';
2 | import React from 'react';
3 |
4 | import {classNames} from './css-utils.js';
5 | import Gutter from './gutter.js';
6 | import moveGuttersComputeNewSizes from './move-gutters-compute-new-sizes.js';
7 | import stableGuttersComputeNewSizes from './stable-gutters-compute-new-sizes.js';
8 |
9 | export {
10 | moveGuttersComputeNewSizes,
11 | stableGuttersComputeNewSizes,
12 | };
13 |
14 | function normalizeSizes(sizes) {
15 | const totalSize = sizes.reduce((sum, v) => sum + v, 0);
16 | return sizes.map(v => v / totalSize);
17 | }
18 |
19 | const getMouseOrTouchPosition = (e, clientAxis) => e.touches ? e.touches[0][clientAxis] : e[clientAxis];
20 |
21 | function addSpaceForChildren(sizes, numChildren, gutterSize, minSizePX, totalSizePX) {
22 | // const numGutters = numChildren - 1;
23 | // const totalGutterSpacePX = numGutters * gutterSize;
24 | // const availableSpacePX = totalSizePX - totalGutterSpacePX;
25 | //
26 | // this is not so trivial
27 | // let's say we have 3 items and we add 2 more.
28 | // each of those 2 has a minSize. So need to take 2 * minSize
29 | // from the 3 items or (2 * minSize / 3). But any of those items
30 | // themselves might already be at or near minSize
31 | //
32 | // This seems like it's then iterative.
33 | //
34 | // go through and try to remove (minSize * numNewElements / numOldElements)
35 | // from each old element but only remove such that that element
36 | // is still >= minSize. When done there's possibly some amount
37 | // you haven't distributed yet so repeat the process over and over
38 | // until it's all distributed.
39 | //
40 | // given that we don't know which elements are new, for now
41 | // lets just reset all the sizes
42 | return new Array(numChildren).fill(1 / numChildren);
43 | }
44 |
45 | const getDirectionProps = direction => (direction === 'horizontal')
46 | ? {
47 | dimension: 'width',
48 | clientAxis: 'clientX',
49 | position: 'left',
50 | positionEnd: 'right',
51 | clientSize: 'clientWidth',
52 | }
53 | : {
54 | dimension: 'height',
55 | clientAxis: 'clientY',
56 | position: 'top',
57 | positionEnd: 'bottom',
58 | clientSize: 'clientHeight',
59 | };
60 |
61 | const stopMobileBrowserFromScrolling = e => e.preventDefault();
62 |
63 | export default class Split extends React.Component {
64 | constructor(props) {
65 | super(props);
66 | const {
67 | children,
68 | sizes,
69 | onSetSizes,
70 | } = props;
71 | const numPanes = React.Children.count(children);
72 | const size = 1 / numPanes;
73 | this.state = {
74 | sizes: sizes ? (onSetSizes ? sizes : normalizeSizes(sizes)) : new Array(numPanes).fill(size),
75 | };
76 | this.elementRef = React.createRef();
77 | }
78 | _setSizes = (sizes) => {
79 | this.setState({sizes});
80 | }
81 | handleMouseUpAndTouchEnd = () => {
82 | document.removeEventListener("mousemove", this.handleMouseAndTouchMove);
83 | document.removeEventListener("mouseup", this.handleMouseUpAndTouchEnd);
84 | document.removeEventListener("touchmove", this.handleMouseAndTouchMove);
85 | document.removeEventListener("touchend", this.handleMouseUpAndTouchEnd);
86 | this.setState({dragging: false});
87 | };
88 | handleMouseAndTouchMove = (e) => {
89 | stopMobileBrowserFromScrolling(e);
90 | const {
91 | gutterSize,
92 | direction,
93 | minSize,
94 | computeNewSizesFn,
95 | onSetSizes,
96 | sizes: propSizes,
97 | } = this.props;
98 | const {
99 | prevPaneNdx,
100 | mouseStart,
101 | startSizes,
102 | sizes: stateSizes,
103 | } = this.state;
104 | const setSizes = onSetSizes || this._setSizes;
105 | const sizes = onSetSizes ? propSizes : stateSizes;
106 |
107 | const {
108 | clientAxis,
109 | clientSize,
110 | } = getDirectionProps(direction);
111 |
112 | const numPanes = sizes.length;
113 | const numGutters = numPanes - 1;
114 | const totalGutterSizePX = numGutters * gutterSize;
115 |
116 | const deltaPX = getMouseOrTouchPosition(e, clientAxis) - mouseStart;
117 | const outerSizePX = this.elementRef.current[clientSize];
118 | const innerSizePX = outerSizePX - totalGutterSizePX;
119 |
120 | const newSizes = computeNewSizesFn({
121 | startSizes,
122 | prevPaneNdx,
123 | minSize: minSize / innerSizePX,
124 | minSizePX: minSize,
125 | innerSizePX,
126 | delta: deltaPX / innerSizePX,
127 | deltaPX,
128 | });
129 | setSizes(newSizes);
130 | };
131 | handleMouseDownAndTouchStart = (e) => {
132 | stopMobileBrowserFromScrolling(e);
133 | const {
134 | direction,
135 | onSetSizes,
136 | sizes: propsSizes,
137 | } = this.props;
138 | const {
139 | clientAxis,
140 | } = getDirectionProps(direction);
141 |
142 | document.addEventListener("mousemove", this.handleMouseAndTouchMove, {passive: false});
143 | document.addEventListener("mouseup", this.handleMouseUpAndTouchEnd);
144 | document.addEventListener("touchmove", this.handleMouseAndTouchMove, {passive: false});
145 | document.addEventListener("touchend", this.handleMouseUpAndTouchEnd);
146 | const gutterNdx = Array.prototype.indexOf.call(e.target.parentElement.children, e.target);
147 | const prevPaneNdx = (gutterNdx - 1) / 2;
148 | const sizes = onSetSizes ? propsSizes : this.state.sizes;
149 | const startSizes = sizes.slice();
150 | this.setState({
151 | startSizes: startSizes,
152 | mouseStart: getMouseOrTouchPosition(e, clientAxis),
153 | prevPaneNdx,
154 | dragging: true,
155 | });
156 | };
157 | recomputeSizes = () => {
158 | // here it's not entirely clear what to do. Maybe we need options
159 | // If they user removes a child which sizes do they want? I guess
160 | // since they removed a child they passed in new sizes so we should
161 | // pass sizes back? Ugh!
162 | //
163 | // Example:
164 | //
165 | // * start: 3 panes, sizes a(33%), b(33%), c(33%)
166 | // * user adjusts to sizes a(10%), b(80%), c(10%)
167 | // * user deletes pane (a)
168 | //
169 | // If we just continue to use the current sizes the we'd get
170 | //
171 | // b(10%), c(90%)
172 | //
173 | // We have no way of knowing that b should get the 90%
174 | //
175 | // One way would be to pass responsibility for saving the sizes
176 | // up to the parent. Basically if you want to add/remove children
177 | // then you need need to keep their state. In that case
178 | // passing an `onSetSize` prop. It's a function that will be called
179 | // with an array of sizes. Update your sizes and pass them in as
180 | // props
181 | //
182 | // But, just so we don't completely fail if the user has not opted
183 | // into managing the size state then at least do something.
184 | const {sizes} = this.state;
185 | const {minSize, direction, gutterSize} = this.props;
186 | const {
187 | clientSize,
188 | } = getDirectionProps(direction);
189 |
190 | const numChildren = React.Children.count(this.props.children);
191 | const newSizes = numChildren < sizes.length
192 | // a child was removed, normalizes the sizes
193 | ? normalizeSizes(sizes.slice(0, numChildren))
194 | // children were added, make space for them
195 | : addSpaceForChildren(sizes, numChildren, gutterSize, minSize, this.elementRef.current.parentElement[clientSize]);
196 | this._setSizes(newSizes);
197 | }
198 | componentDidUpdate() {
199 | const {children, onSetSizes} = this.props;
200 | // we need to check if new elements were added.
201 | if (onSetSizes) {
202 | return; // not our responsibility
203 | }
204 |
205 | const {sizes} = this.state;
206 | const numChildren = React.Children.count(children);
207 | if (sizes.length !== numChildren) {
208 | this.recomputeSizes();
209 | }
210 | }
211 | render() {
212 | const {
213 | children,
214 | direction,
215 | gutterSize,
216 | sizes: propSizes,
217 | onSetSizes,
218 | minSize,
219 | className: splitClassName,
220 | gutterClassName,
221 | paneClassName,
222 | } = this.props;
223 | const {
224 | dragging,
225 | prevPaneNdx,
226 | sizes: stateSizes,
227 | } = this.state;
228 |
229 | const sizes = onSetSizes ? propSizes : stateSizes;
230 | const gutterStyle = {flexBasis: gutterSize ? `${gutterSize}px` : '0'};
231 |
232 | let childNdx = 0;
233 | let first = true;
234 | const newChildren = [];
235 | React.Children.forEach(children, (child) => {
236 | if (!React.isValidElement(child)) {
237 | return null;
238 | }
239 | if (!first) {
240 | newChildren.push(
241 |
250 | );
251 | }
252 |
253 | const style = {
254 | flexBasis: `${sizes[childNdx] * 100}%`,
255 | };
256 | const className = classNames(paneClassName, {[`${paneClassName}-dragging`]: dragging});
257 |
258 | newChildren.push(
259 |