@yoopta/themes-shadcn 6.0.0-beta.14 → 6.0.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/dist/table/components/row-controls.d.ts.map +1 -1
  2. package/package.json +2 -2
  3. package/dist/accordion.js.map +0 -1
  4. package/dist/blockquote.js.map +0 -1
  5. package/dist/callout.js.map +0 -1
  6. package/dist/carousel.js.map +0 -1
  7. package/dist/chunks/Combination-2202c874.js +0 -1080
  8. package/dist/chunks/Combination-2202c874.js.map +0 -1
  9. package/dist/chunks/_tslib-514d60fe.js +0 -67
  10. package/dist/chunks/_tslib-514d60fe.js.map +0 -1
  11. package/dist/chunks/arrow-right-cc37c75c.js +0 -30
  12. package/dist/chunks/arrow-right-cc37c75c.js.map +0 -1
  13. package/dist/chunks/button-f9af7cb3.js +0 -76
  14. package/dist/chunks/button-f9af7cb3.js.map +0 -1
  15. package/dist/chunks/card-29720641.js +0 -38
  16. package/dist/chunks/card-29720641.js.map +0 -1
  17. package/dist/chunks/check-530fff0e.js +0 -14
  18. package/dist/chunks/check-530fff0e.js.map +0 -1
  19. package/dist/chunks/chevron-down-544d1acd.js +0 -16
  20. package/dist/chunks/chevron-down-544d1acd.js.map +0 -1
  21. package/dist/chunks/chevron-up-053cba03.js +0 -14
  22. package/dist/chunks/chevron-up-053cba03.js.map +0 -1
  23. package/dist/chunks/code-2ff9cc0c.js +0 -17
  24. package/dist/chunks/code-2ff9cc0c.js.map +0 -1
  25. package/dist/chunks/createLucideIcon-02eb7854.js +0 -95
  26. package/dist/chunks/createLucideIcon-02eb7854.js.map +0 -1
  27. package/dist/chunks/dropdown-menu-ac777fdc.js +0 -1165
  28. package/dist/chunks/dropdown-menu-ac777fdc.js.map +0 -1
  29. package/dist/chunks/external-link-43895ded.js +0 -18
  30. package/dist/chunks/external-link-43895ded.js.map +0 -1
  31. package/dist/chunks/file-text-99674d8d.js +0 -20
  32. package/dist/chunks/file-text-99674d8d.js.map +0 -1
  33. package/dist/chunks/hover-card-134f053d.js +0 -257
  34. package/dist/chunks/hover-card-134f053d.js.map +0 -1
  35. package/dist/chunks/index-056b596e.js +0 -16
  36. package/dist/chunks/index-056b596e.js.map +0 -1
  37. package/dist/chunks/index-35823769.js +0 -222
  38. package/dist/chunks/index-35823769.js.map +0 -1
  39. package/dist/chunks/index-41c4abc4.js +0 -3805
  40. package/dist/chunks/index-41c4abc4.js.map +0 -1
  41. package/dist/chunks/index-454935af.js +0 -71
  42. package/dist/chunks/index-454935af.js.map +0 -1
  43. package/dist/chunks/index-ae9b48d5.js +0 -12
  44. package/dist/chunks/index-ae9b48d5.js.map +0 -1
  45. package/dist/chunks/index-b8a83ba5.js +0 -335
  46. package/dist/chunks/index-b8a83ba5.js.map +0 -1
  47. package/dist/chunks/index-b8f2908d.js +0 -40
  48. package/dist/chunks/index-b8f2908d.js.map +0 -1
  49. package/dist/chunks/index-c655a86f.js +0 -7
  50. package/dist/chunks/index-c655a86f.js.map +0 -1
  51. package/dist/chunks/index-c90e54a4.js +0 -190
  52. package/dist/chunks/index-c90e54a4.js.map +0 -1
  53. package/dist/chunks/index-cf5f0d71.js +0 -2907
  54. package/dist/chunks/index-cf5f0d71.js.map +0 -1
  55. package/dist/chunks/index-d9171717.js +0 -13
  56. package/dist/chunks/index-d9171717.js.map +0 -1
  57. package/dist/chunks/index-dd0fd848.js +0 -70
  58. package/dist/chunks/index-dd0fd848.js.map +0 -1
  59. package/dist/chunks/input-5608c2c9.js +0 -13
  60. package/dist/chunks/input-5608c2c9.js.map +0 -1
  61. package/dist/chunks/label-c9152e49.js +0 -168
  62. package/dist/chunks/label-c9152e49.js.map +0 -1
  63. package/dist/chunks/language-select-bdc50f20.js +0 -44
  64. package/dist/chunks/language-select-bdc50f20.js.map +0 -1
  65. package/dist/chunks/play-1a34ad05.js +0 -16
  66. package/dist/chunks/play-1a34ad05.js.map +0 -1
  67. package/dist/chunks/plus-fcea2532.js +0 -17
  68. package/dist/chunks/plus-fcea2532.js.map +0 -1
  69. package/dist/chunks/popover-ef29b0ac.js +0 -300
  70. package/dist/chunks/popover-ef29b0ac.js.map +0 -1
  71. package/dist/chunks/scroll-area-17d8c584.js +0 -726
  72. package/dist/chunks/scroll-area-17d8c584.js.map +0 -1
  73. package/dist/chunks/select-98610101.js +0 -1213
  74. package/dist/chunks/select-98610101.js.map +0 -1
  75. package/dist/chunks/separator-9e6aa45b.js +0 -172
  76. package/dist/chunks/separator-9e6aa45b.js.map +0 -1
  77. package/dist/chunks/sparkles-8922a4af.js +0 -26
  78. package/dist/chunks/sparkles-8922a4af.js.map +0 -1
  79. package/dist/chunks/style-inject.es-746bb8ed.js +0 -29
  80. package/dist/chunks/style-inject.es-746bb8ed.js.map +0 -1
  81. package/dist/chunks/tabs-9cfbd3cc.js +0 -204
  82. package/dist/chunks/tabs-9cfbd3cc.js.map +0 -1
  83. package/dist/chunks/tooltip-f1e02ae0.js +0 -800
  84. package/dist/chunks/tooltip-f1e02ae0.js.map +0 -1
  85. package/dist/chunks/trash-2-be728dd2.js +0 -20
  86. package/dist/chunks/trash-2-be728dd2.js.map +0 -1
  87. package/dist/chunks/upload-0f56ec3e.js +0 -44
  88. package/dist/chunks/upload-0f56ec3e.js.map +0 -1
  89. package/dist/chunks/utils-131071a4.js +0 -2500
  90. package/dist/chunks/utils-131071a4.js.map +0 -1
  91. package/dist/chunks/x-2f6cf742.js +0 -17
  92. package/dist/chunks/x-2f6cf742.js.map +0 -1
  93. package/dist/code-group.js.map +0 -1
  94. package/dist/code.js.map +0 -1
  95. package/dist/divider.js.map +0 -1
  96. package/dist/embed.js.map +0 -1
  97. package/dist/file.js.map +0 -1
  98. package/dist/headings.js.map +0 -1
  99. package/dist/image.js.map +0 -1
  100. package/dist/index.js.map +0 -1
  101. package/dist/link.js.map +0 -1
  102. package/dist/lists.js.map +0 -1
  103. package/dist/mention.js.map +0 -1
  104. package/dist/paragraph.js.map +0 -1
  105. package/dist/steps.js.map +0 -1
  106. package/dist/table-of-contents.js.map +0 -1
  107. package/dist/table.js.map +0 -1
  108. package/dist/tabs.js.map +0 -1
  109. package/dist/video.js.map +0 -1
@@ -1,3805 +0,0 @@
1
- import { c as createLucideIcon } from './createLucideIcon-02eb7854.js';
2
- import React__default, { memo, useCallback, useMemo, PureComponent, createElement } from 'react';
3
- import ReactDOM__default, { flushSync } from 'react-dom';
4
- import { jsx, jsxs } from 'react/jsx-runtime';
5
-
6
- /**
7
- * @license lucide-react v0.378.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */
12
-
13
-
14
- const AlignCenter = createLucideIcon("AlignCenter", [
15
- ["line", { x1: "21", x2: "3", y1: "6", y2: "6", key: "1fp77t" }],
16
- ["line", { x1: "17", x2: "7", y1: "12", y2: "12", key: "rsh8ii" }],
17
- ["line", { x1: "19", x2: "5", y1: "18", y2: "18", key: "1t0tuv" }]
18
- ]);
19
-
20
- /**
21
- * @license lucide-react v0.378.0 - ISC
22
- *
23
- * This source code is licensed under the ISC license.
24
- * See the LICENSE file in the root directory of this source tree.
25
- */
26
-
27
-
28
- const AlignLeft = createLucideIcon("AlignLeft", [
29
- ["line", { x1: "21", x2: "3", y1: "6", y2: "6", key: "1fp77t" }],
30
- ["line", { x1: "15", x2: "3", y1: "12", y2: "12", key: "v6grx8" }],
31
- ["line", { x1: "17", x2: "3", y1: "18", y2: "18", key: "1awlsn" }]
32
- ]);
33
-
34
- /**
35
- * @license lucide-react v0.378.0 - ISC
36
- *
37
- * This source code is licensed under the ISC license.
38
- * See the LICENSE file in the root directory of this source tree.
39
- */
40
-
41
-
42
- const AlignRight = createLucideIcon("AlignRight", [
43
- ["line", { x1: "21", x2: "3", y1: "6", y2: "6", key: "1fp77t" }],
44
- ["line", { x1: "21", x2: "9", y1: "12", y2: "12", key: "1uyos4" }],
45
- ["line", { x1: "21", x2: "7", y1: "18", y2: "18", key: "1g9eri" }]
46
- ]);
47
-
48
- /**
49
- * @license lucide-react v0.378.0 - ISC
50
- *
51
- * This source code is licensed under the ISC license.
52
- * See the LICENSE file in the root directory of this source tree.
53
- */
54
-
55
-
56
- const Link = createLucideIcon("Link", [
57
- ["path", { d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71", key: "1cjeqo" }],
58
- ["path", { d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71", key: "19qd67" }]
59
- ]);
60
-
61
- function getAugmentedNamespace(n) {
62
- if (n.__esModule) return n;
63
- var f = n.default;
64
- if (typeof f == "function") {
65
- var a = function a () {
66
- if (this instanceof a) {
67
- var args = [null];
68
- args.push.apply(args, arguments);
69
- var Ctor = Function.bind.apply(f, args);
70
- return new Ctor();
71
- }
72
- return f.apply(this, arguments);
73
- };
74
- a.prototype = f.prototype;
75
- } else a = {};
76
- Object.defineProperty(a, '__esModule', {value: true});
77
- Object.keys(n).forEach(function (k) {
78
- var d = Object.getOwnPropertyDescriptor(n, k);
79
- Object.defineProperty(a, k, d.get ? d : {
80
- enumerable: true,
81
- get: function () {
82
- return n[k];
83
- }
84
- });
85
- });
86
- return a;
87
- }
88
-
89
- var cjsExports = {};
90
- var cjs = {
91
- get exports(){ return cjsExports; },
92
- set exports(v){ cjsExports = v; },
93
- };
94
-
95
- var Draggable$1 = {};
96
-
97
- var propTypesExports = {};
98
- var propTypes = {
99
- get exports(){ return propTypesExports; },
100
- set exports(v){ propTypesExports = v; },
101
- };
102
-
103
- var reactIsExports = {};
104
- var reactIs = {
105
- get exports(){ return reactIsExports; },
106
- set exports(v){ reactIsExports = v; },
107
- };
108
-
109
- var reactIs_development = {};
110
-
111
- /** @license React v16.13.1
112
- * react-is.development.js
113
- *
114
- * Copyright (c) Facebook, Inc. and its affiliates.
115
- *
116
- * This source code is licensed under the MIT license found in the
117
- * LICENSE file in the root directory of this source tree.
118
- */
119
-
120
- var hasRequiredReactIs_development;
121
-
122
- function requireReactIs_development () {
123
- if (hasRequiredReactIs_development) return reactIs_development;
124
- hasRequiredReactIs_development = 1;
125
-
126
-
127
-
128
- {
129
- (function() {
130
-
131
- // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
132
- // nor polyfill, then a plain number is used for performance.
133
- var hasSymbol = typeof Symbol === 'function' && Symbol.for;
134
- var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
135
- var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
136
- var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
137
- var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
138
- var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
139
- var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
140
- var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
141
- // (unstable) APIs that have been removed. Can we remove the symbols?
142
-
143
- var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
144
- var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
145
- var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
146
- var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
147
- var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
148
- var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
149
- var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
150
- var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9;
151
- var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
152
- var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
153
- var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7;
154
-
155
- function isValidElementType(type) {
156
- return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
157
- type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (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_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE || type.$$typeof === REACT_BLOCK_TYPE);
158
- }
159
-
160
- function typeOf(object) {
161
- if (typeof object === 'object' && object !== null) {
162
- var $$typeof = object.$$typeof;
163
-
164
- switch ($$typeof) {
165
- case REACT_ELEMENT_TYPE:
166
- var type = object.type;
167
-
168
- switch (type) {
169
- case REACT_ASYNC_MODE_TYPE:
170
- case REACT_CONCURRENT_MODE_TYPE:
171
- case REACT_FRAGMENT_TYPE:
172
- case REACT_PROFILER_TYPE:
173
- case REACT_STRICT_MODE_TYPE:
174
- case REACT_SUSPENSE_TYPE:
175
- return type;
176
-
177
- default:
178
- var $$typeofType = type && type.$$typeof;
179
-
180
- switch ($$typeofType) {
181
- case REACT_CONTEXT_TYPE:
182
- case REACT_FORWARD_REF_TYPE:
183
- case REACT_LAZY_TYPE:
184
- case REACT_MEMO_TYPE:
185
- case REACT_PROVIDER_TYPE:
186
- return $$typeofType;
187
-
188
- default:
189
- return $$typeof;
190
- }
191
-
192
- }
193
-
194
- case REACT_PORTAL_TYPE:
195
- return $$typeof;
196
- }
197
- }
198
-
199
- return undefined;
200
- } // AsyncMode is deprecated along with isAsyncMode
201
-
202
- var AsyncMode = REACT_ASYNC_MODE_TYPE;
203
- var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
204
- var ContextConsumer = REACT_CONTEXT_TYPE;
205
- var ContextProvider = REACT_PROVIDER_TYPE;
206
- var Element = REACT_ELEMENT_TYPE;
207
- var ForwardRef = REACT_FORWARD_REF_TYPE;
208
- var Fragment = REACT_FRAGMENT_TYPE;
209
- var Lazy = REACT_LAZY_TYPE;
210
- var Memo = REACT_MEMO_TYPE;
211
- var Portal = REACT_PORTAL_TYPE;
212
- var Profiler = REACT_PROFILER_TYPE;
213
- var StrictMode = REACT_STRICT_MODE_TYPE;
214
- var Suspense = REACT_SUSPENSE_TYPE;
215
- var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated
216
-
217
- function isAsyncMode(object) {
218
- {
219
- if (!hasWarnedAboutDeprecatedIsAsyncMode) {
220
- hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
221
-
222
- console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
223
- }
224
- }
225
-
226
- return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
227
- }
228
- function isConcurrentMode(object) {
229
- return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
230
- }
231
- function isContextConsumer(object) {
232
- return typeOf(object) === REACT_CONTEXT_TYPE;
233
- }
234
- function isContextProvider(object) {
235
- return typeOf(object) === REACT_PROVIDER_TYPE;
236
- }
237
- function isElement(object) {
238
- return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
239
- }
240
- function isForwardRef(object) {
241
- return typeOf(object) === REACT_FORWARD_REF_TYPE;
242
- }
243
- function isFragment(object) {
244
- return typeOf(object) === REACT_FRAGMENT_TYPE;
245
- }
246
- function isLazy(object) {
247
- return typeOf(object) === REACT_LAZY_TYPE;
248
- }
249
- function isMemo(object) {
250
- return typeOf(object) === REACT_MEMO_TYPE;
251
- }
252
- function isPortal(object) {
253
- return typeOf(object) === REACT_PORTAL_TYPE;
254
- }
255
- function isProfiler(object) {
256
- return typeOf(object) === REACT_PROFILER_TYPE;
257
- }
258
- function isStrictMode(object) {
259
- return typeOf(object) === REACT_STRICT_MODE_TYPE;
260
- }
261
- function isSuspense(object) {
262
- return typeOf(object) === REACT_SUSPENSE_TYPE;
263
- }
264
-
265
- reactIs_development.AsyncMode = AsyncMode;
266
- reactIs_development.ConcurrentMode = ConcurrentMode;
267
- reactIs_development.ContextConsumer = ContextConsumer;
268
- reactIs_development.ContextProvider = ContextProvider;
269
- reactIs_development.Element = Element;
270
- reactIs_development.ForwardRef = ForwardRef;
271
- reactIs_development.Fragment = Fragment;
272
- reactIs_development.Lazy = Lazy;
273
- reactIs_development.Memo = Memo;
274
- reactIs_development.Portal = Portal;
275
- reactIs_development.Profiler = Profiler;
276
- reactIs_development.StrictMode = StrictMode;
277
- reactIs_development.Suspense = Suspense;
278
- reactIs_development.isAsyncMode = isAsyncMode;
279
- reactIs_development.isConcurrentMode = isConcurrentMode;
280
- reactIs_development.isContextConsumer = isContextConsumer;
281
- reactIs_development.isContextProvider = isContextProvider;
282
- reactIs_development.isElement = isElement;
283
- reactIs_development.isForwardRef = isForwardRef;
284
- reactIs_development.isFragment = isFragment;
285
- reactIs_development.isLazy = isLazy;
286
- reactIs_development.isMemo = isMemo;
287
- reactIs_development.isPortal = isPortal;
288
- reactIs_development.isProfiler = isProfiler;
289
- reactIs_development.isStrictMode = isStrictMode;
290
- reactIs_development.isSuspense = isSuspense;
291
- reactIs_development.isValidElementType = isValidElementType;
292
- reactIs_development.typeOf = typeOf;
293
- })();
294
- }
295
- return reactIs_development;
296
- }
297
-
298
- var hasRequiredReactIs;
299
-
300
- function requireReactIs () {
301
- if (hasRequiredReactIs) return reactIsExports;
302
- hasRequiredReactIs = 1;
303
- (function (module) {
304
-
305
- {
306
- module.exports = requireReactIs_development();
307
- }
308
- } (reactIs));
309
- return reactIsExports;
310
- }
311
-
312
- /*
313
- object-assign
314
- (c) Sindre Sorhus
315
- @license MIT
316
- */
317
-
318
- var objectAssign;
319
- var hasRequiredObjectAssign;
320
-
321
- function requireObjectAssign () {
322
- if (hasRequiredObjectAssign) return objectAssign;
323
- hasRequiredObjectAssign = 1;
324
- /* eslint-disable no-unused-vars */
325
- var getOwnPropertySymbols = Object.getOwnPropertySymbols;
326
- var hasOwnProperty = Object.prototype.hasOwnProperty;
327
- var propIsEnumerable = Object.prototype.propertyIsEnumerable;
328
-
329
- function toObject(val) {
330
- if (val === null || val === undefined) {
331
- throw new TypeError('Object.assign cannot be called with null or undefined');
332
- }
333
-
334
- return Object(val);
335
- }
336
-
337
- function shouldUseNative() {
338
- try {
339
- if (!Object.assign) {
340
- return false;
341
- }
342
-
343
- // Detect buggy property enumeration order in older V8 versions.
344
-
345
- // https://bugs.chromium.org/p/v8/issues/detail?id=4118
346
- var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
347
- test1[5] = 'de';
348
- if (Object.getOwnPropertyNames(test1)[0] === '5') {
349
- return false;
350
- }
351
-
352
- // https://bugs.chromium.org/p/v8/issues/detail?id=3056
353
- var test2 = {};
354
- for (var i = 0; i < 10; i++) {
355
- test2['_' + String.fromCharCode(i)] = i;
356
- }
357
- var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
358
- return test2[n];
359
- });
360
- if (order2.join('') !== '0123456789') {
361
- return false;
362
- }
363
-
364
- // https://bugs.chromium.org/p/v8/issues/detail?id=3056
365
- var test3 = {};
366
- 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
367
- test3[letter] = letter;
368
- });
369
- if (Object.keys(Object.assign({}, test3)).join('') !==
370
- 'abcdefghijklmnopqrst') {
371
- return false;
372
- }
373
-
374
- return true;
375
- } catch (err) {
376
- // We don't expect any of the above to throw, but better to be safe.
377
- return false;
378
- }
379
- }
380
-
381
- objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
382
- var from;
383
- var to = toObject(target);
384
- var symbols;
385
-
386
- for (var s = 1; s < arguments.length; s++) {
387
- from = Object(arguments[s]);
388
-
389
- for (var key in from) {
390
- if (hasOwnProperty.call(from, key)) {
391
- to[key] = from[key];
392
- }
393
- }
394
-
395
- if (getOwnPropertySymbols) {
396
- symbols = getOwnPropertySymbols(from);
397
- for (var i = 0; i < symbols.length; i++) {
398
- if (propIsEnumerable.call(from, symbols[i])) {
399
- to[symbols[i]] = from[symbols[i]];
400
- }
401
- }
402
- }
403
- }
404
-
405
- return to;
406
- };
407
- return objectAssign;
408
- }
409
-
410
- /**
411
- * Copyright (c) 2013-present, Facebook, Inc.
412
- *
413
- * This source code is licensed under the MIT license found in the
414
- * LICENSE file in the root directory of this source tree.
415
- */
416
-
417
- var ReactPropTypesSecret_1;
418
- var hasRequiredReactPropTypesSecret;
419
-
420
- function requireReactPropTypesSecret () {
421
- if (hasRequiredReactPropTypesSecret) return ReactPropTypesSecret_1;
422
- hasRequiredReactPropTypesSecret = 1;
423
-
424
- var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
425
-
426
- ReactPropTypesSecret_1 = ReactPropTypesSecret;
427
- return ReactPropTypesSecret_1;
428
- }
429
-
430
- var has;
431
- var hasRequiredHas;
432
-
433
- function requireHas () {
434
- if (hasRequiredHas) return has;
435
- hasRequiredHas = 1;
436
- has = Function.call.bind(Object.prototype.hasOwnProperty);
437
- return has;
438
- }
439
-
440
- /**
441
- * Copyright (c) 2013-present, Facebook, Inc.
442
- *
443
- * This source code is licensed under the MIT license found in the
444
- * LICENSE file in the root directory of this source tree.
445
- */
446
-
447
- var checkPropTypes_1;
448
- var hasRequiredCheckPropTypes;
449
-
450
- function requireCheckPropTypes () {
451
- if (hasRequiredCheckPropTypes) return checkPropTypes_1;
452
- hasRequiredCheckPropTypes = 1;
453
-
454
- var printWarning = function() {};
455
-
456
- {
457
- var ReactPropTypesSecret = requireReactPropTypesSecret();
458
- var loggedTypeFailures = {};
459
- var has = requireHas();
460
-
461
- printWarning = function(text) {
462
- var message = 'Warning: ' + text;
463
- if (typeof console !== 'undefined') {
464
- console.error(message);
465
- }
466
- try {
467
- // --- Welcome to debugging React ---
468
- // This error was thrown as a convenience so that you can use this stack
469
- // to find the callsite that caused this warning to fire.
470
- throw new Error(message);
471
- } catch (x) { /**/ }
472
- };
473
- }
474
-
475
- /**
476
- * Assert that the values match with the type specs.
477
- * Error messages are memorized and will only be shown once.
478
- *
479
- * @param {object} typeSpecs Map of name to a ReactPropType
480
- * @param {object} values Runtime values that need to be type-checked
481
- * @param {string} location e.g. "prop", "context", "child context"
482
- * @param {string} componentName Name of the component for error messages.
483
- * @param {?Function} getStack Returns the component stack.
484
- * @private
485
- */
486
- function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
487
- {
488
- for (var typeSpecName in typeSpecs) {
489
- if (has(typeSpecs, typeSpecName)) {
490
- var error;
491
- // Prop type validation may throw. In case they do, we don't want to
492
- // fail the render phase where it didn't fail before. So we log it.
493
- // After these have been cleaned up, we'll let them throw.
494
- try {
495
- // This is intentionally an invariant that gets caught. It's the same
496
- // behavior as without this statement except with a better message.
497
- if (typeof typeSpecs[typeSpecName] !== 'function') {
498
- var err = Error(
499
- (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
500
- 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' +
501
- 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.'
502
- );
503
- err.name = 'Invariant Violation';
504
- throw err;
505
- }
506
- error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
507
- } catch (ex) {
508
- error = ex;
509
- }
510
- if (error && !(error instanceof Error)) {
511
- printWarning(
512
- (componentName || 'React class') + ': type specification of ' +
513
- location + ' `' + typeSpecName + '` is invalid; the type checker ' +
514
- 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
515
- 'You may have forgotten to pass an argument to the type checker ' +
516
- 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
517
- 'shape all require an argument).'
518
- );
519
- }
520
- if (error instanceof Error && !(error.message in loggedTypeFailures)) {
521
- // Only monitor this failure once because there tends to be a lot of the
522
- // same error.
523
- loggedTypeFailures[error.message] = true;
524
-
525
- var stack = getStack ? getStack() : '';
526
-
527
- printWarning(
528
- 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
529
- );
530
- }
531
- }
532
- }
533
- }
534
- }
535
-
536
- /**
537
- * Resets warning cache when testing.
538
- *
539
- * @private
540
- */
541
- checkPropTypes.resetWarningCache = function() {
542
- {
543
- loggedTypeFailures = {};
544
- }
545
- };
546
-
547
- checkPropTypes_1 = checkPropTypes;
548
- return checkPropTypes_1;
549
- }
550
-
551
- /**
552
- * Copyright (c) 2013-present, Facebook, Inc.
553
- *
554
- * This source code is licensed under the MIT license found in the
555
- * LICENSE file in the root directory of this source tree.
556
- */
557
-
558
- var factoryWithTypeCheckers;
559
- var hasRequiredFactoryWithTypeCheckers;
560
-
561
- function requireFactoryWithTypeCheckers () {
562
- if (hasRequiredFactoryWithTypeCheckers) return factoryWithTypeCheckers;
563
- hasRequiredFactoryWithTypeCheckers = 1;
564
-
565
- var ReactIs = requireReactIs();
566
- var assign = requireObjectAssign();
567
-
568
- var ReactPropTypesSecret = requireReactPropTypesSecret();
569
- var has = requireHas();
570
- var checkPropTypes = requireCheckPropTypes();
571
-
572
- var printWarning = function() {};
573
-
574
- {
575
- printWarning = function(text) {
576
- var message = 'Warning: ' + text;
577
- if (typeof console !== 'undefined') {
578
- console.error(message);
579
- }
580
- try {
581
- // --- Welcome to debugging React ---
582
- // This error was thrown as a convenience so that you can use this stack
583
- // to find the callsite that caused this warning to fire.
584
- throw new Error(message);
585
- } catch (x) {}
586
- };
587
- }
588
-
589
- function emptyFunctionThatReturnsNull() {
590
- return null;
591
- }
592
-
593
- factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
594
- /* global Symbol */
595
- var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
596
- var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
597
-
598
- /**
599
- * Returns the iterator method function contained on the iterable object.
600
- *
601
- * Be sure to invoke the function with the iterable as context:
602
- *
603
- * var iteratorFn = getIteratorFn(myIterable);
604
- * if (iteratorFn) {
605
- * var iterator = iteratorFn.call(myIterable);
606
- * ...
607
- * }
608
- *
609
- * @param {?object} maybeIterable
610
- * @return {?function}
611
- */
612
- function getIteratorFn(maybeIterable) {
613
- var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
614
- if (typeof iteratorFn === 'function') {
615
- return iteratorFn;
616
- }
617
- }
618
-
619
- /**
620
- * Collection of methods that allow declaration and validation of props that are
621
- * supplied to React components. Example usage:
622
- *
623
- * var Props = require('ReactPropTypes');
624
- * var MyArticle = React.createClass({
625
- * propTypes: {
626
- * // An optional string prop named "description".
627
- * description: Props.string,
628
- *
629
- * // A required enum prop named "category".
630
- * category: Props.oneOf(['News','Photos']).isRequired,
631
- *
632
- * // A prop named "dialog" that requires an instance of Dialog.
633
- * dialog: Props.instanceOf(Dialog).isRequired
634
- * },
635
- * render: function() { ... }
636
- * });
637
- *
638
- * A more formal specification of how these methods are used:
639
- *
640
- * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
641
- * decl := ReactPropTypes.{type}(.isRequired)?
642
- *
643
- * Each and every declaration produces a function with the same signature. This
644
- * allows the creation of custom validation functions. For example:
645
- *
646
- * var MyLink = React.createClass({
647
- * propTypes: {
648
- * // An optional string or URI prop named "href".
649
- * href: function(props, propName, componentName) {
650
- * var propValue = props[propName];
651
- * if (propValue != null && typeof propValue !== 'string' &&
652
- * !(propValue instanceof URI)) {
653
- * return new Error(
654
- * 'Expected a string or an URI for ' + propName + ' in ' +
655
- * componentName
656
- * );
657
- * }
658
- * }
659
- * },
660
- * render: function() {...}
661
- * });
662
- *
663
- * @internal
664
- */
665
-
666
- var ANONYMOUS = '<<anonymous>>';
667
-
668
- // Important!
669
- // Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
670
- var ReactPropTypes = {
671
- array: createPrimitiveTypeChecker('array'),
672
- bigint: createPrimitiveTypeChecker('bigint'),
673
- bool: createPrimitiveTypeChecker('boolean'),
674
- func: createPrimitiveTypeChecker('function'),
675
- number: createPrimitiveTypeChecker('number'),
676
- object: createPrimitiveTypeChecker('object'),
677
- string: createPrimitiveTypeChecker('string'),
678
- symbol: createPrimitiveTypeChecker('symbol'),
679
-
680
- any: createAnyTypeChecker(),
681
- arrayOf: createArrayOfTypeChecker,
682
- element: createElementTypeChecker(),
683
- elementType: createElementTypeTypeChecker(),
684
- instanceOf: createInstanceTypeChecker,
685
- node: createNodeChecker(),
686
- objectOf: createObjectOfTypeChecker,
687
- oneOf: createEnumTypeChecker,
688
- oneOfType: createUnionTypeChecker,
689
- shape: createShapeTypeChecker,
690
- exact: createStrictShapeTypeChecker,
691
- };
692
-
693
- /**
694
- * inlined Object.is polyfill to avoid requiring consumers ship their own
695
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
696
- */
697
- /*eslint-disable no-self-compare*/
698
- function is(x, y) {
699
- // SameValue algorithm
700
- if (x === y) {
701
- // Steps 1-5, 7-10
702
- // Steps 6.b-6.e: +0 != -0
703
- return x !== 0 || 1 / x === 1 / y;
704
- } else {
705
- // Step 6.a: NaN == NaN
706
- return x !== x && y !== y;
707
- }
708
- }
709
- /*eslint-enable no-self-compare*/
710
-
711
- /**
712
- * We use an Error-like object for backward compatibility as people may call
713
- * PropTypes directly and inspect their output. However, we don't use real
714
- * Errors anymore. We don't inspect their stack anyway, and creating them
715
- * is prohibitively expensive if they are created too often, such as what
716
- * happens in oneOfType() for any type before the one that matched.
717
- */
718
- function PropTypeError(message, data) {
719
- this.message = message;
720
- this.data = data && typeof data === 'object' ? data: {};
721
- this.stack = '';
722
- }
723
- // Make `instanceof Error` still work for returned errors.
724
- PropTypeError.prototype = Error.prototype;
725
-
726
- function createChainableTypeChecker(validate) {
727
- {
728
- var manualPropTypeCallCache = {};
729
- var manualPropTypeWarningCount = 0;
730
- }
731
- function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
732
- componentName = componentName || ANONYMOUS;
733
- propFullName = propFullName || propName;
734
-
735
- if (secret !== ReactPropTypesSecret) {
736
- if (throwOnDirectAccess) {
737
- // New behavior only for users of `prop-types` package
738
- var err = new Error(
739
- 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
740
- 'Use `PropTypes.checkPropTypes()` to call them. ' +
741
- 'Read more at http://fb.me/use-check-prop-types'
742
- );
743
- err.name = 'Invariant Violation';
744
- throw err;
745
- } else if (typeof console !== 'undefined') {
746
- // Old behavior for people using React.PropTypes
747
- var cacheKey = componentName + ':' + propName;
748
- if (
749
- !manualPropTypeCallCache[cacheKey] &&
750
- // Avoid spamming the console because they are often not actionable except for lib authors
751
- manualPropTypeWarningCount < 3
752
- ) {
753
- printWarning(
754
- 'You are manually calling a React.PropTypes validation ' +
755
- 'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
756
- 'and will throw in the standalone `prop-types` package. ' +
757
- 'You may be seeing this warning due to a third-party PropTypes ' +
758
- 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'
759
- );
760
- manualPropTypeCallCache[cacheKey] = true;
761
- manualPropTypeWarningCount++;
762
- }
763
- }
764
- }
765
- if (props[propName] == null) {
766
- if (isRequired) {
767
- if (props[propName] === null) {
768
- return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
769
- }
770
- return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
771
- }
772
- return null;
773
- } else {
774
- return validate(props, propName, componentName, location, propFullName);
775
- }
776
- }
777
-
778
- var chainedCheckType = checkType.bind(null, false);
779
- chainedCheckType.isRequired = checkType.bind(null, true);
780
-
781
- return chainedCheckType;
782
- }
783
-
784
- function createPrimitiveTypeChecker(expectedType) {
785
- function validate(props, propName, componentName, location, propFullName, secret) {
786
- var propValue = props[propName];
787
- var propType = getPropType(propValue);
788
- if (propType !== expectedType) {
789
- // `propValue` being instance of, say, date/regexp, pass the 'object'
790
- // check, but we can offer a more precise error message here rather than
791
- // 'of type `object`'.
792
- var preciseType = getPreciseType(propValue);
793
-
794
- return new PropTypeError(
795
- 'Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'),
796
- {expectedType: expectedType}
797
- );
798
- }
799
- return null;
800
- }
801
- return createChainableTypeChecker(validate);
802
- }
803
-
804
- function createAnyTypeChecker() {
805
- return createChainableTypeChecker(emptyFunctionThatReturnsNull);
806
- }
807
-
808
- function createArrayOfTypeChecker(typeChecker) {
809
- function validate(props, propName, componentName, location, propFullName) {
810
- if (typeof typeChecker !== 'function') {
811
- return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
812
- }
813
- var propValue = props[propName];
814
- if (!Array.isArray(propValue)) {
815
- var propType = getPropType(propValue);
816
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
817
- }
818
- for (var i = 0; i < propValue.length; i++) {
819
- var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret);
820
- if (error instanceof Error) {
821
- return error;
822
- }
823
- }
824
- return null;
825
- }
826
- return createChainableTypeChecker(validate);
827
- }
828
-
829
- function createElementTypeChecker() {
830
- function validate(props, propName, componentName, location, propFullName) {
831
- var propValue = props[propName];
832
- if (!isValidElement(propValue)) {
833
- var propType = getPropType(propValue);
834
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
835
- }
836
- return null;
837
- }
838
- return createChainableTypeChecker(validate);
839
- }
840
-
841
- function createElementTypeTypeChecker() {
842
- function validate(props, propName, componentName, location, propFullName) {
843
- var propValue = props[propName];
844
- if (!ReactIs.isValidElementType(propValue)) {
845
- var propType = getPropType(propValue);
846
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.'));
847
- }
848
- return null;
849
- }
850
- return createChainableTypeChecker(validate);
851
- }
852
-
853
- function createInstanceTypeChecker(expectedClass) {
854
- function validate(props, propName, componentName, location, propFullName) {
855
- if (!(props[propName] instanceof expectedClass)) {
856
- var expectedClassName = expectedClass.name || ANONYMOUS;
857
- var actualClassName = getClassName(props[propName]);
858
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
859
- }
860
- return null;
861
- }
862
- return createChainableTypeChecker(validate);
863
- }
864
-
865
- function createEnumTypeChecker(expectedValues) {
866
- if (!Array.isArray(expectedValues)) {
867
- {
868
- if (arguments.length > 1) {
869
- printWarning(
870
- 'Invalid arguments supplied to oneOf, expected an array, got ' + arguments.length + ' arguments. ' +
871
- 'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).'
872
- );
873
- } else {
874
- printWarning('Invalid argument supplied to oneOf, expected an array.');
875
- }
876
- }
877
- return emptyFunctionThatReturnsNull;
878
- }
879
-
880
- function validate(props, propName, componentName, location, propFullName) {
881
- var propValue = props[propName];
882
- for (var i = 0; i < expectedValues.length; i++) {
883
- if (is(propValue, expectedValues[i])) {
884
- return null;
885
- }
886
- }
887
-
888
- var valuesString = JSON.stringify(expectedValues, function replacer(key, value) {
889
- var type = getPreciseType(value);
890
- if (type === 'symbol') {
891
- return String(value);
892
- }
893
- return value;
894
- });
895
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + String(propValue) + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
896
- }
897
- return createChainableTypeChecker(validate);
898
- }
899
-
900
- function createObjectOfTypeChecker(typeChecker) {
901
- function validate(props, propName, componentName, location, propFullName) {
902
- if (typeof typeChecker !== 'function') {
903
- return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
904
- }
905
- var propValue = props[propName];
906
- var propType = getPropType(propValue);
907
- if (propType !== 'object') {
908
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
909
- }
910
- for (var key in propValue) {
911
- if (has(propValue, key)) {
912
- var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
913
- if (error instanceof Error) {
914
- return error;
915
- }
916
- }
917
- }
918
- return null;
919
- }
920
- return createChainableTypeChecker(validate);
921
- }
922
-
923
- function createUnionTypeChecker(arrayOfTypeCheckers) {
924
- if (!Array.isArray(arrayOfTypeCheckers)) {
925
- printWarning('Invalid argument supplied to oneOfType, expected an instance of array.') ;
926
- return emptyFunctionThatReturnsNull;
927
- }
928
-
929
- for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
930
- var checker = arrayOfTypeCheckers[i];
931
- if (typeof checker !== 'function') {
932
- printWarning(
933
- 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' +
934
- 'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.'
935
- );
936
- return emptyFunctionThatReturnsNull;
937
- }
938
- }
939
-
940
- function validate(props, propName, componentName, location, propFullName) {
941
- var expectedTypes = [];
942
- for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
943
- var checker = arrayOfTypeCheckers[i];
944
- var checkerResult = checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret);
945
- if (checkerResult == null) {
946
- return null;
947
- }
948
- if (checkerResult.data && has(checkerResult.data, 'expectedType')) {
949
- expectedTypes.push(checkerResult.data.expectedType);
950
- }
951
- }
952
- var expectedTypesMessage = (expectedTypes.length > 0) ? ', expected one of type [' + expectedTypes.join(', ') + ']': '';
953
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`' + expectedTypesMessage + '.'));
954
- }
955
- return createChainableTypeChecker(validate);
956
- }
957
-
958
- function createNodeChecker() {
959
- function validate(props, propName, componentName, location, propFullName) {
960
- if (!isNode(props[propName])) {
961
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
962
- }
963
- return null;
964
- }
965
- return createChainableTypeChecker(validate);
966
- }
967
-
968
- function invalidValidatorError(componentName, location, propFullName, key, type) {
969
- return new PropTypeError(
970
- (componentName || 'React class') + ': ' + location + ' type `' + propFullName + '.' + key + '` is invalid; ' +
971
- 'it must be a function, usually from the `prop-types` package, but received `' + type + '`.'
972
- );
973
- }
974
-
975
- function createShapeTypeChecker(shapeTypes) {
976
- function validate(props, propName, componentName, location, propFullName) {
977
- var propValue = props[propName];
978
- var propType = getPropType(propValue);
979
- if (propType !== 'object') {
980
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
981
- }
982
- for (var key in shapeTypes) {
983
- var checker = shapeTypes[key];
984
- if (typeof checker !== 'function') {
985
- return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
986
- }
987
- var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
988
- if (error) {
989
- return error;
990
- }
991
- }
992
- return null;
993
- }
994
- return createChainableTypeChecker(validate);
995
- }
996
-
997
- function createStrictShapeTypeChecker(shapeTypes) {
998
- function validate(props, propName, componentName, location, propFullName) {
999
- var propValue = props[propName];
1000
- var propType = getPropType(propValue);
1001
- if (propType !== 'object') {
1002
- return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
1003
- }
1004
- // We need to check all keys in case some are required but missing from props.
1005
- var allKeys = assign({}, props[propName], shapeTypes);
1006
- for (var key in allKeys) {
1007
- var checker = shapeTypes[key];
1008
- if (has(shapeTypes, key) && typeof checker !== 'function') {
1009
- return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
1010
- }
1011
- if (!checker) {
1012
- return new PropTypeError(
1013
- 'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +
1014
- '\nBad object: ' + JSON.stringify(props[propName], null, ' ') +
1015
- '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
1016
- );
1017
- }
1018
- var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
1019
- if (error) {
1020
- return error;
1021
- }
1022
- }
1023
- return null;
1024
- }
1025
-
1026
- return createChainableTypeChecker(validate);
1027
- }
1028
-
1029
- function isNode(propValue) {
1030
- switch (typeof propValue) {
1031
- case 'number':
1032
- case 'string':
1033
- case 'undefined':
1034
- return true;
1035
- case 'boolean':
1036
- return !propValue;
1037
- case 'object':
1038
- if (Array.isArray(propValue)) {
1039
- return propValue.every(isNode);
1040
- }
1041
- if (propValue === null || isValidElement(propValue)) {
1042
- return true;
1043
- }
1044
-
1045
- var iteratorFn = getIteratorFn(propValue);
1046
- if (iteratorFn) {
1047
- var iterator = iteratorFn.call(propValue);
1048
- var step;
1049
- if (iteratorFn !== propValue.entries) {
1050
- while (!(step = iterator.next()).done) {
1051
- if (!isNode(step.value)) {
1052
- return false;
1053
- }
1054
- }
1055
- } else {
1056
- // Iterator will provide entry [k,v] tuples rather than values.
1057
- while (!(step = iterator.next()).done) {
1058
- var entry = step.value;
1059
- if (entry) {
1060
- if (!isNode(entry[1])) {
1061
- return false;
1062
- }
1063
- }
1064
- }
1065
- }
1066
- } else {
1067
- return false;
1068
- }
1069
-
1070
- return true;
1071
- default:
1072
- return false;
1073
- }
1074
- }
1075
-
1076
- function isSymbol(propType, propValue) {
1077
- // Native Symbol.
1078
- if (propType === 'symbol') {
1079
- return true;
1080
- }
1081
-
1082
- // falsy value can't be a Symbol
1083
- if (!propValue) {
1084
- return false;
1085
- }
1086
-
1087
- // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
1088
- if (propValue['@@toStringTag'] === 'Symbol') {
1089
- return true;
1090
- }
1091
-
1092
- // Fallback for non-spec compliant Symbols which are polyfilled.
1093
- if (typeof Symbol === 'function' && propValue instanceof Symbol) {
1094
- return true;
1095
- }
1096
-
1097
- return false;
1098
- }
1099
-
1100
- // Equivalent of `typeof` but with special handling for array and regexp.
1101
- function getPropType(propValue) {
1102
- var propType = typeof propValue;
1103
- if (Array.isArray(propValue)) {
1104
- return 'array';
1105
- }
1106
- if (propValue instanceof RegExp) {
1107
- // Old webkits (at least until Android 4.0) return 'function' rather than
1108
- // 'object' for typeof a RegExp. We'll normalize this here so that /bla/
1109
- // passes PropTypes.object.
1110
- return 'object';
1111
- }
1112
- if (isSymbol(propType, propValue)) {
1113
- return 'symbol';
1114
- }
1115
- return propType;
1116
- }
1117
-
1118
- // This handles more types than `getPropType`. Only used for error messages.
1119
- // See `createPrimitiveTypeChecker`.
1120
- function getPreciseType(propValue) {
1121
- if (typeof propValue === 'undefined' || propValue === null) {
1122
- return '' + propValue;
1123
- }
1124
- var propType = getPropType(propValue);
1125
- if (propType === 'object') {
1126
- if (propValue instanceof Date) {
1127
- return 'date';
1128
- } else if (propValue instanceof RegExp) {
1129
- return 'regexp';
1130
- }
1131
- }
1132
- return propType;
1133
- }
1134
-
1135
- // Returns a string that is postfixed to a warning about an invalid type.
1136
- // For example, "undefined" or "of type array"
1137
- function getPostfixForTypeWarning(value) {
1138
- var type = getPreciseType(value);
1139
- switch (type) {
1140
- case 'array':
1141
- case 'object':
1142
- return 'an ' + type;
1143
- case 'boolean':
1144
- case 'date':
1145
- case 'regexp':
1146
- return 'a ' + type;
1147
- default:
1148
- return type;
1149
- }
1150
- }
1151
-
1152
- // Returns class name of the object, if any.
1153
- function getClassName(propValue) {
1154
- if (!propValue.constructor || !propValue.constructor.name) {
1155
- return ANONYMOUS;
1156
- }
1157
- return propValue.constructor.name;
1158
- }
1159
-
1160
- ReactPropTypes.checkPropTypes = checkPropTypes;
1161
- ReactPropTypes.resetWarningCache = checkPropTypes.resetWarningCache;
1162
- ReactPropTypes.PropTypes = ReactPropTypes;
1163
-
1164
- return ReactPropTypes;
1165
- };
1166
- return factoryWithTypeCheckers;
1167
- }
1168
-
1169
- /**
1170
- * Copyright (c) 2013-present, Facebook, Inc.
1171
- *
1172
- * This source code is licensed under the MIT license found in the
1173
- * LICENSE file in the root directory of this source tree.
1174
- */
1175
-
1176
- {
1177
- var ReactIs = requireReactIs();
1178
-
1179
- // By explicitly using `prop-types` you are opting into new development behavior.
1180
- // http://fb.me/prop-types-in-prod
1181
- var throwOnDirectAccess = true;
1182
- propTypes.exports = requireFactoryWithTypeCheckers()(ReactIs.isElement, throwOnDirectAccess);
1183
- }
1184
-
1185
- function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e))for(t=0;t<e.length;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);else for(t in e)e[t]&&(n&&(n+=" "),n+=t);return n}function clsx(){for(var e,t,f=0,n="";f<arguments.length;)(e=arguments[f++])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
1186
-
1187
- var clsx_m = /*#__PURE__*/Object.freeze({
1188
- __proto__: null,
1189
- clsx: clsx,
1190
- default: clsx
1191
- });
1192
-
1193
- var require$$3 = /*@__PURE__*/getAugmentedNamespace(clsx_m);
1194
-
1195
- var domFns = {};
1196
-
1197
- var shims = {};
1198
-
1199
- Object.defineProperty(shims, "__esModule", {
1200
- value: true
1201
- });
1202
- shims.dontSetMe = dontSetMe;
1203
- shims.findInArray = findInArray;
1204
- shims.int = int;
1205
- shims.isFunction = isFunction;
1206
- shims.isNum = isNum;
1207
- // @credits https://gist.github.com/rogozhnikoff/a43cfed27c41e4e68cdc
1208
- function findInArray(array /*: Array<any> | TouchList*/, callback /*: Function*/) /*: any*/{
1209
- for (let i = 0, length = array.length; i < length; i++) {
1210
- if (callback.apply(callback, [array[i], i, array])) return array[i];
1211
- }
1212
- }
1213
- function isFunction(func /*: any*/) /*: boolean %checks*/{
1214
- // $FlowIgnore[method-unbinding]
1215
- return typeof func === 'function' || Object.prototype.toString.call(func) === '[object Function]';
1216
- }
1217
- function isNum(num /*: any*/) /*: boolean %checks*/{
1218
- return typeof num === 'number' && !isNaN(num);
1219
- }
1220
- function int(a /*: string*/) /*: number*/{
1221
- return parseInt(a, 10);
1222
- }
1223
- function dontSetMe(props /*: Object*/, propName /*: string*/, componentName /*: string*/) /*: ?Error*/{
1224
- if (props[propName]) {
1225
- return new Error("Invalid prop ".concat(propName, " passed to ").concat(componentName, " - do not set this, set it on the child."));
1226
- }
1227
- }
1228
-
1229
- var getPrefix$1 = {};
1230
-
1231
- Object.defineProperty(getPrefix$1, "__esModule", {
1232
- value: true
1233
- });
1234
- getPrefix$1.browserPrefixToKey = browserPrefixToKey;
1235
- getPrefix$1.browserPrefixToStyle = browserPrefixToStyle;
1236
- getPrefix$1.default = void 0;
1237
- getPrefix$1.getPrefix = getPrefix;
1238
- const prefixes = ['Moz', 'Webkit', 'O', 'ms'];
1239
- function getPrefix() /*: string*/{
1240
- var _window$document;
1241
- let prop /*: string*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'transform';
1242
- // Ensure we're running in an environment where there is actually a global
1243
- // `window` obj
1244
- if (typeof window === 'undefined') return '';
1245
-
1246
- // If we're in a pseudo-browser server-side environment, this access
1247
- // path may not exist, so bail out if it doesn't.
1248
- const style = (_window$document = window.document) === null || _window$document === void 0 || (_window$document = _window$document.documentElement) === null || _window$document === void 0 ? void 0 : _window$document.style;
1249
- if (!style) return '';
1250
- if (prop in style) return '';
1251
- for (let i = 0; i < prefixes.length; i++) {
1252
- if (browserPrefixToKey(prop, prefixes[i]) in style) return prefixes[i];
1253
- }
1254
- return '';
1255
- }
1256
- function browserPrefixToKey(prop /*: string*/, prefix /*: string*/) /*: string*/{
1257
- return prefix ? "".concat(prefix).concat(kebabToTitleCase(prop)) : prop;
1258
- }
1259
- function browserPrefixToStyle(prop /*: string*/, prefix /*: string*/) /*: string*/{
1260
- return prefix ? "-".concat(prefix.toLowerCase(), "-").concat(prop) : prop;
1261
- }
1262
- function kebabToTitleCase(str /*: string*/) /*: string*/{
1263
- let out = '';
1264
- let shouldCapitalize = true;
1265
- for (let i = 0; i < str.length; i++) {
1266
- if (shouldCapitalize) {
1267
- out += str[i].toUpperCase();
1268
- shouldCapitalize = false;
1269
- } else if (str[i] === '-') {
1270
- shouldCapitalize = true;
1271
- } else {
1272
- out += str[i];
1273
- }
1274
- }
1275
- return out;
1276
- }
1277
-
1278
- // Default export is the prefix itself, like 'Moz', 'Webkit', etc
1279
- // Note that you may have to re-test for certain things; for instance, Chrome 50
1280
- // can handle unprefixed `transform`, but not unprefixed `user-select`
1281
- getPrefix$1.default = (getPrefix() /*: string*/);
1282
-
1283
- Object.defineProperty(domFns, "__esModule", {
1284
- value: true
1285
- });
1286
- domFns.addClassName = addClassName;
1287
- domFns.addEvent = addEvent;
1288
- domFns.addUserSelectStyles = addUserSelectStyles;
1289
- domFns.createCSSTransform = createCSSTransform;
1290
- domFns.createSVGTransform = createSVGTransform;
1291
- domFns.getTouch = getTouch;
1292
- domFns.getTouchIdentifier = getTouchIdentifier;
1293
- domFns.getTranslation = getTranslation;
1294
- domFns.innerHeight = innerHeight;
1295
- domFns.innerWidth = innerWidth;
1296
- domFns.matchesSelector = matchesSelector;
1297
- domFns.matchesSelectorAndParentsTo = matchesSelectorAndParentsTo;
1298
- domFns.offsetXYFromParent = offsetXYFromParent;
1299
- domFns.outerHeight = outerHeight;
1300
- domFns.outerWidth = outerWidth;
1301
- domFns.removeClassName = removeClassName;
1302
- domFns.removeEvent = removeEvent;
1303
- domFns.removeUserSelectStyles = removeUserSelectStyles;
1304
- var _shims$2 = shims;
1305
- var _getPrefix = _interopRequireWildcard$1(getPrefix$1);
1306
- function _getRequireWildcardCache$1(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache$1 = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
1307
- function _interopRequireWildcard$1(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache$1(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
1308
- /*:: import type {ControlPosition, PositionOffsetControlPosition, MouseTouchEvent} from './types';*/
1309
- let matchesSelectorFunc = '';
1310
- function matchesSelector(el /*: Node*/, selector /*: string*/) /*: boolean*/{
1311
- if (!matchesSelectorFunc) {
1312
- matchesSelectorFunc = (0, _shims$2.findInArray)(['matches', 'webkitMatchesSelector', 'mozMatchesSelector', 'msMatchesSelector', 'oMatchesSelector'], function (method) {
1313
- // $FlowIgnore: Doesn't think elements are indexable
1314
- return (0, _shims$2.isFunction)(el[method]);
1315
- });
1316
- }
1317
-
1318
- // Might not be found entirely (not an Element?) - in that case, bail
1319
- // $FlowIgnore: Doesn't think elements are indexable
1320
- if (!(0, _shims$2.isFunction)(el[matchesSelectorFunc])) return false;
1321
-
1322
- // $FlowIgnore: Doesn't think elements are indexable
1323
- return el[matchesSelectorFunc](selector);
1324
- }
1325
-
1326
- // Works up the tree to the draggable itself attempting to match selector.
1327
- function matchesSelectorAndParentsTo(el /*: Node*/, selector /*: string*/, baseNode /*: Node*/) /*: boolean*/{
1328
- let node = el;
1329
- do {
1330
- if (matchesSelector(node, selector)) return true;
1331
- if (node === baseNode) return false;
1332
- // $FlowIgnore[incompatible-type]
1333
- node = node.parentNode;
1334
- } while (node);
1335
- return false;
1336
- }
1337
- function addEvent(el /*: ?Node*/, event /*: string*/, handler /*: Function*/, inputOptions /*: Object*/) /*: void*/{
1338
- if (!el) return;
1339
- const options = {
1340
- capture: true,
1341
- ...inputOptions
1342
- };
1343
- // $FlowIgnore[method-unbinding]
1344
- if (el.addEventListener) {
1345
- el.addEventListener(event, handler, options);
1346
- } else if (el.attachEvent) {
1347
- el.attachEvent('on' + event, handler);
1348
- } else {
1349
- // $FlowIgnore: Doesn't think elements are indexable
1350
- el['on' + event] = handler;
1351
- }
1352
- }
1353
- function removeEvent(el /*: ?Node*/, event /*: string*/, handler /*: Function*/, inputOptions /*: Object*/) /*: void*/{
1354
- if (!el) return;
1355
- const options = {
1356
- capture: true,
1357
- ...inputOptions
1358
- };
1359
- // $FlowIgnore[method-unbinding]
1360
- if (el.removeEventListener) {
1361
- el.removeEventListener(event, handler, options);
1362
- } else if (el.detachEvent) {
1363
- el.detachEvent('on' + event, handler);
1364
- } else {
1365
- // $FlowIgnore: Doesn't think elements are indexable
1366
- el['on' + event] = null;
1367
- }
1368
- }
1369
- function outerHeight(node /*: HTMLElement*/) /*: number*/{
1370
- // This is deliberately excluding margin for our calculations, since we are using
1371
- // offsetTop which is including margin. See getBoundPosition
1372
- let height = node.clientHeight;
1373
- const computedStyle = node.ownerDocument.defaultView.getComputedStyle(node);
1374
- height += (0, _shims$2.int)(computedStyle.borderTopWidth);
1375
- height += (0, _shims$2.int)(computedStyle.borderBottomWidth);
1376
- return height;
1377
- }
1378
- function outerWidth(node /*: HTMLElement*/) /*: number*/{
1379
- // This is deliberately excluding margin for our calculations, since we are using
1380
- // offsetLeft which is including margin. See getBoundPosition
1381
- let width = node.clientWidth;
1382
- const computedStyle = node.ownerDocument.defaultView.getComputedStyle(node);
1383
- width += (0, _shims$2.int)(computedStyle.borderLeftWidth);
1384
- width += (0, _shims$2.int)(computedStyle.borderRightWidth);
1385
- return width;
1386
- }
1387
- function innerHeight(node /*: HTMLElement*/) /*: number*/{
1388
- let height = node.clientHeight;
1389
- const computedStyle = node.ownerDocument.defaultView.getComputedStyle(node);
1390
- height -= (0, _shims$2.int)(computedStyle.paddingTop);
1391
- height -= (0, _shims$2.int)(computedStyle.paddingBottom);
1392
- return height;
1393
- }
1394
- function innerWidth(node /*: HTMLElement*/) /*: number*/{
1395
- let width = node.clientWidth;
1396
- const computedStyle = node.ownerDocument.defaultView.getComputedStyle(node);
1397
- width -= (0, _shims$2.int)(computedStyle.paddingLeft);
1398
- width -= (0, _shims$2.int)(computedStyle.paddingRight);
1399
- return width;
1400
- }
1401
- /*:: interface EventWithOffset {
1402
- clientX: number, clientY: number
1403
- }*/
1404
- // Get from offsetParent
1405
- function offsetXYFromParent(evt /*: EventWithOffset*/, offsetParent /*: HTMLElement*/, scale /*: number*/) /*: ControlPosition*/{
1406
- const isBody = offsetParent === offsetParent.ownerDocument.body;
1407
- const offsetParentRect = isBody ? {
1408
- left: 0,
1409
- top: 0
1410
- } : offsetParent.getBoundingClientRect();
1411
- const x = (evt.clientX + offsetParent.scrollLeft - offsetParentRect.left) / scale;
1412
- const y = (evt.clientY + offsetParent.scrollTop - offsetParentRect.top) / scale;
1413
- return {
1414
- x,
1415
- y
1416
- };
1417
- }
1418
- function createCSSTransform(controlPos /*: ControlPosition*/, positionOffset /*: PositionOffsetControlPosition*/) /*: Object*/{
1419
- const translation = getTranslation(controlPos, positionOffset, 'px');
1420
- return {
1421
- [(0, _getPrefix.browserPrefixToKey)('transform', _getPrefix.default)]: translation
1422
- };
1423
- }
1424
- function createSVGTransform(controlPos /*: ControlPosition*/, positionOffset /*: PositionOffsetControlPosition*/) /*: string*/{
1425
- const translation = getTranslation(controlPos, positionOffset, '');
1426
- return translation;
1427
- }
1428
- function getTranslation(_ref /*:: */, positionOffset /*: PositionOffsetControlPosition*/, unitSuffix /*: string*/) /*: string*/{
1429
- let {
1430
- x,
1431
- y
1432
- } /*: ControlPosition*/ = _ref /*: ControlPosition*/;
1433
- let translation = "translate(".concat(x).concat(unitSuffix, ",").concat(y).concat(unitSuffix, ")");
1434
- if (positionOffset) {
1435
- const defaultX = "".concat(typeof positionOffset.x === 'string' ? positionOffset.x : positionOffset.x + unitSuffix);
1436
- const defaultY = "".concat(typeof positionOffset.y === 'string' ? positionOffset.y : positionOffset.y + unitSuffix);
1437
- translation = "translate(".concat(defaultX, ", ").concat(defaultY, ")") + translation;
1438
- }
1439
- return translation;
1440
- }
1441
- function getTouch(e /*: MouseTouchEvent*/, identifier /*: number*/) /*: ?{clientX: number, clientY: number}*/{
1442
- return e.targetTouches && (0, _shims$2.findInArray)(e.targetTouches, t => identifier === t.identifier) || e.changedTouches && (0, _shims$2.findInArray)(e.changedTouches, t => identifier === t.identifier);
1443
- }
1444
- function getTouchIdentifier(e /*: MouseTouchEvent*/) /*: ?number*/{
1445
- if (e.targetTouches && e.targetTouches[0]) return e.targetTouches[0].identifier;
1446
- if (e.changedTouches && e.changedTouches[0]) return e.changedTouches[0].identifier;
1447
- }
1448
-
1449
- // User-select Hacks:
1450
- //
1451
- // Useful for preventing blue highlights all over everything when dragging.
1452
-
1453
- // Note we're passing `document` b/c we could be iframed
1454
- function addUserSelectStyles(doc /*: ?Document*/) {
1455
- if (!doc) return;
1456
- let styleEl = doc.getElementById('react-draggable-style-el');
1457
- if (!styleEl) {
1458
- styleEl = doc.createElement('style');
1459
- styleEl.type = 'text/css';
1460
- styleEl.id = 'react-draggable-style-el';
1461
- styleEl.innerHTML = '.react-draggable-transparent-selection *::-moz-selection {all: inherit;}\n';
1462
- styleEl.innerHTML += '.react-draggable-transparent-selection *::selection {all: inherit;}\n';
1463
- doc.getElementsByTagName('head')[0].appendChild(styleEl);
1464
- }
1465
- if (doc.body) addClassName(doc.body, 'react-draggable-transparent-selection');
1466
- }
1467
- function removeUserSelectStyles(doc /*: ?Document*/) {
1468
- if (!doc) return;
1469
- try {
1470
- if (doc.body) removeClassName(doc.body, 'react-draggable-transparent-selection');
1471
- // $FlowIgnore: IE
1472
- if (doc.selection) {
1473
- // $FlowIgnore: IE
1474
- doc.selection.empty();
1475
- } else {
1476
- // Remove selection caused by scroll, unless it's a focused input
1477
- // (we use doc.defaultView in case we're in an iframe)
1478
- const selection = (doc.defaultView || window).getSelection();
1479
- if (selection && selection.type !== 'Caret') {
1480
- selection.removeAllRanges();
1481
- }
1482
- }
1483
- } catch (e) {
1484
- // probably IE
1485
- }
1486
- }
1487
- function addClassName(el /*: HTMLElement*/, className /*: string*/) {
1488
- if (el.classList) {
1489
- el.classList.add(className);
1490
- } else {
1491
- if (!el.className.match(new RegExp("(?:^|\\s)".concat(className, "(?!\\S)")))) {
1492
- el.className += " ".concat(className);
1493
- }
1494
- }
1495
- }
1496
- function removeClassName(el /*: HTMLElement*/, className /*: string*/) {
1497
- if (el.classList) {
1498
- el.classList.remove(className);
1499
- } else {
1500
- el.className = el.className.replace(new RegExp("(?:^|\\s)".concat(className, "(?!\\S)"), 'g'), '');
1501
- }
1502
- }
1503
-
1504
- var positionFns = {};
1505
-
1506
- Object.defineProperty(positionFns, "__esModule", {
1507
- value: true
1508
- });
1509
- positionFns.canDragX = canDragX;
1510
- positionFns.canDragY = canDragY;
1511
- positionFns.createCoreData = createCoreData;
1512
- positionFns.createDraggableData = createDraggableData;
1513
- positionFns.getBoundPosition = getBoundPosition;
1514
- positionFns.getControlPosition = getControlPosition;
1515
- positionFns.snapToGrid = snapToGrid;
1516
- var _shims$1 = shims;
1517
- var _domFns$1 = domFns;
1518
- /*:: import type Draggable from '../Draggable';*/
1519
- /*:: import type {Bounds, ControlPosition, DraggableData, MouseTouchEvent} from './types';*/
1520
- /*:: import type DraggableCore from '../DraggableCore';*/
1521
- function getBoundPosition(draggable /*: Draggable*/, x /*: number*/, y /*: number*/) /*: [number, number]*/{
1522
- // If no bounds, short-circuit and move on
1523
- if (!draggable.props.bounds) return [x, y];
1524
-
1525
- // Clone new bounds
1526
- let {
1527
- bounds
1528
- } = draggable.props;
1529
- bounds = typeof bounds === 'string' ? bounds : cloneBounds(bounds);
1530
- const node = findDOMNode(draggable);
1531
- if (typeof bounds === 'string') {
1532
- const {
1533
- ownerDocument
1534
- } = node;
1535
- const ownerWindow = ownerDocument.defaultView;
1536
- let boundNode;
1537
- if (bounds === 'parent') {
1538
- boundNode = node.parentNode;
1539
- } else {
1540
- boundNode = ownerDocument.querySelector(bounds);
1541
- }
1542
- if (!(boundNode instanceof ownerWindow.HTMLElement)) {
1543
- throw new Error('Bounds selector "' + bounds + '" could not find an element.');
1544
- }
1545
- const boundNodeEl /*: HTMLElement*/ = boundNode; // for Flow, can't seem to refine correctly
1546
- const nodeStyle = ownerWindow.getComputedStyle(node);
1547
- const boundNodeStyle = ownerWindow.getComputedStyle(boundNodeEl);
1548
- // Compute bounds. This is a pain with padding and offsets but this gets it exactly right.
1549
- bounds = {
1550
- left: -node.offsetLeft + (0, _shims$1.int)(boundNodeStyle.paddingLeft) + (0, _shims$1.int)(nodeStyle.marginLeft),
1551
- top: -node.offsetTop + (0, _shims$1.int)(boundNodeStyle.paddingTop) + (0, _shims$1.int)(nodeStyle.marginTop),
1552
- right: (0, _domFns$1.innerWidth)(boundNodeEl) - (0, _domFns$1.outerWidth)(node) - node.offsetLeft + (0, _shims$1.int)(boundNodeStyle.paddingRight) - (0, _shims$1.int)(nodeStyle.marginRight),
1553
- bottom: (0, _domFns$1.innerHeight)(boundNodeEl) - (0, _domFns$1.outerHeight)(node) - node.offsetTop + (0, _shims$1.int)(boundNodeStyle.paddingBottom) - (0, _shims$1.int)(nodeStyle.marginBottom)
1554
- };
1555
- }
1556
-
1557
- // Keep x and y below right and bottom limits...
1558
- if ((0, _shims$1.isNum)(bounds.right)) x = Math.min(x, bounds.right);
1559
- if ((0, _shims$1.isNum)(bounds.bottom)) y = Math.min(y, bounds.bottom);
1560
-
1561
- // But above left and top limits.
1562
- if ((0, _shims$1.isNum)(bounds.left)) x = Math.max(x, bounds.left);
1563
- if ((0, _shims$1.isNum)(bounds.top)) y = Math.max(y, bounds.top);
1564
- return [x, y];
1565
- }
1566
- function snapToGrid(grid /*: [number, number]*/, pendingX /*: number*/, pendingY /*: number*/) /*: [number, number]*/{
1567
- const x = Math.round(pendingX / grid[0]) * grid[0];
1568
- const y = Math.round(pendingY / grid[1]) * grid[1];
1569
- return [x, y];
1570
- }
1571
- function canDragX(draggable /*: Draggable*/) /*: boolean*/{
1572
- return draggable.props.axis === 'both' || draggable.props.axis === 'x';
1573
- }
1574
- function canDragY(draggable /*: Draggable*/) /*: boolean*/{
1575
- return draggable.props.axis === 'both' || draggable.props.axis === 'y';
1576
- }
1577
-
1578
- // Get {x, y} positions from event.
1579
- function getControlPosition(e /*: MouseTouchEvent*/, touchIdentifier /*: ?number*/, draggableCore /*: DraggableCore*/) /*: ?ControlPosition*/{
1580
- const touchObj = typeof touchIdentifier === 'number' ? (0, _domFns$1.getTouch)(e, touchIdentifier) : null;
1581
- if (typeof touchIdentifier === 'number' && !touchObj) return null; // not the right touch
1582
- const node = findDOMNode(draggableCore);
1583
- // User can provide an offsetParent if desired.
1584
- const offsetParent = draggableCore.props.offsetParent || node.offsetParent || node.ownerDocument.body;
1585
- return (0, _domFns$1.offsetXYFromParent)(touchObj || e, offsetParent, draggableCore.props.scale);
1586
- }
1587
-
1588
- // Create an data object exposed by <DraggableCore>'s events
1589
- function createCoreData(draggable /*: DraggableCore*/, x /*: number*/, y /*: number*/) /*: DraggableData*/{
1590
- const isStart = !(0, _shims$1.isNum)(draggable.lastX);
1591
- const node = findDOMNode(draggable);
1592
- if (isStart) {
1593
- // If this is our first move, use the x and y as last coords.
1594
- return {
1595
- node,
1596
- deltaX: 0,
1597
- deltaY: 0,
1598
- lastX: x,
1599
- lastY: y,
1600
- x,
1601
- y
1602
- };
1603
- } else {
1604
- // Otherwise calculate proper values.
1605
- return {
1606
- node,
1607
- deltaX: x - draggable.lastX,
1608
- deltaY: y - draggable.lastY,
1609
- lastX: draggable.lastX,
1610
- lastY: draggable.lastY,
1611
- x,
1612
- y
1613
- };
1614
- }
1615
- }
1616
-
1617
- // Create an data exposed by <Draggable>'s events
1618
- function createDraggableData(draggable /*: Draggable*/, coreData /*: DraggableData*/) /*: DraggableData*/{
1619
- const scale = draggable.props.scale;
1620
- return {
1621
- node: coreData.node,
1622
- x: draggable.state.x + coreData.deltaX / scale,
1623
- y: draggable.state.y + coreData.deltaY / scale,
1624
- deltaX: coreData.deltaX / scale,
1625
- deltaY: coreData.deltaY / scale,
1626
- lastX: draggable.state.x,
1627
- lastY: draggable.state.y
1628
- };
1629
- }
1630
-
1631
- // A lot faster than stringify/parse
1632
- function cloneBounds(bounds /*: Bounds*/) /*: Bounds*/{
1633
- return {
1634
- left: bounds.left,
1635
- top: bounds.top,
1636
- right: bounds.right,
1637
- bottom: bounds.bottom
1638
- };
1639
- }
1640
- function findDOMNode(draggable /*: Draggable | DraggableCore*/) /*: HTMLElement*/{
1641
- const node = draggable.findDOMNode();
1642
- if (!node) {
1643
- throw new Error('<DraggableCore>: Unmounted during event!');
1644
- }
1645
- // $FlowIgnore we can't assert on HTMLElement due to tests... FIXME
1646
- return node;
1647
- }
1648
-
1649
- var DraggableCore$2 = {};
1650
-
1651
- var log$1 = {};
1652
-
1653
- Object.defineProperty(log$1, "__esModule", {
1654
- value: true
1655
- });
1656
- log$1.default = log;
1657
- /*eslint no-console:0*/
1658
- function log() {
1659
- }
1660
-
1661
- Object.defineProperty(DraggableCore$2, "__esModule", {
1662
- value: true
1663
- });
1664
- DraggableCore$2.default = void 0;
1665
- var React = _interopRequireWildcard(React__default);
1666
- var _propTypes = _interopRequireDefault(propTypesExports);
1667
- var _reactDom = _interopRequireDefault(ReactDOM__default);
1668
- var _domFns = domFns;
1669
- var _positionFns = positionFns;
1670
- var _shims = shims;
1671
- var _log = _interopRequireDefault(log$1);
1672
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1673
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
1674
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
1675
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
1676
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
1677
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1678
- /*:: import type {EventHandler, MouseTouchEvent} from './utils/types';*/
1679
- /*:: import type {Element as ReactElement} from 'react';*/
1680
- // Simple abstraction for dragging events names.
1681
- const eventsFor = {
1682
- touch: {
1683
- start: 'touchstart',
1684
- move: 'touchmove',
1685
- stop: 'touchend'
1686
- },
1687
- mouse: {
1688
- start: 'mousedown',
1689
- move: 'mousemove',
1690
- stop: 'mouseup'
1691
- }
1692
- };
1693
-
1694
- // Default to mouse events.
1695
- let dragEventFor = eventsFor.mouse;
1696
- /*:: export type DraggableData = {
1697
- node: HTMLElement,
1698
- x: number, y: number,
1699
- deltaX: number, deltaY: number,
1700
- lastX: number, lastY: number,
1701
- };*/
1702
- /*:: export type DraggableEventHandler = (e: MouseEvent, data: DraggableData) => void | false;*/
1703
- /*:: export type ControlPosition = {x: number, y: number};*/
1704
- /*:: export type PositionOffsetControlPosition = {x: number|string, y: number|string};*/
1705
- /*:: export type DraggableCoreDefaultProps = {
1706
- allowAnyClick: boolean,
1707
- disabled: boolean,
1708
- enableUserSelectHack: boolean,
1709
- onStart: DraggableEventHandler,
1710
- onDrag: DraggableEventHandler,
1711
- onStop: DraggableEventHandler,
1712
- onMouseDown: (e: MouseEvent) => void,
1713
- scale: number,
1714
- };*/
1715
- /*:: export type DraggableCoreProps = {
1716
- ...DraggableCoreDefaultProps,
1717
- cancel: string,
1718
- children: ReactElement<any>,
1719
- offsetParent: HTMLElement,
1720
- grid: [number, number],
1721
- handle: string,
1722
- nodeRef?: ?React.ElementRef<any>,
1723
- };*/
1724
- //
1725
- // Define <DraggableCore>.
1726
- //
1727
- // <DraggableCore> is for advanced usage of <Draggable>. It maintains minimal internal state so it can
1728
- // work well with libraries that require more control over the element.
1729
- //
1730
-
1731
- let DraggableCore$1 = class DraggableCore extends React.Component /*:: <DraggableCoreProps>*/{
1732
- constructor() {
1733
- super(...arguments);
1734
- _defineProperty(this, "dragging", false);
1735
- // Used while dragging to determine deltas.
1736
- _defineProperty(this, "lastX", NaN);
1737
- _defineProperty(this, "lastY", NaN);
1738
- _defineProperty(this, "touchIdentifier", null);
1739
- _defineProperty(this, "mounted", false);
1740
- _defineProperty(this, "handleDragStart", e => {
1741
- // Make it possible to attach event handlers on top of this one.
1742
- this.props.onMouseDown(e);
1743
-
1744
- // Only accept left-clicks.
1745
- if (!this.props.allowAnyClick && typeof e.button === 'number' && e.button !== 0) return false;
1746
-
1747
- // Get nodes. Be sure to grab relative document (could be iframed)
1748
- const thisNode = this.findDOMNode();
1749
- if (!thisNode || !thisNode.ownerDocument || !thisNode.ownerDocument.body) {
1750
- throw new Error('<DraggableCore> not mounted on DragStart!');
1751
- }
1752
- const {
1753
- ownerDocument
1754
- } = thisNode;
1755
-
1756
- // Short circuit if handle or cancel prop was provided and selector doesn't match.
1757
- if (this.props.disabled || !(e.target instanceof ownerDocument.defaultView.Node) || this.props.handle && !(0, _domFns.matchesSelectorAndParentsTo)(e.target, this.props.handle, thisNode) || this.props.cancel && (0, _domFns.matchesSelectorAndParentsTo)(e.target, this.props.cancel, thisNode)) {
1758
- return;
1759
- }
1760
-
1761
- // Prevent scrolling on mobile devices, like ipad/iphone.
1762
- // Important that this is after handle/cancel.
1763
- if (e.type === 'touchstart') e.preventDefault();
1764
-
1765
- // Set touch identifier in component state if this is a touch event. This allows us to
1766
- // distinguish between individual touches on multitouch screens by identifying which
1767
- // touchpoint was set to this element.
1768
- const touchIdentifier = (0, _domFns.getTouchIdentifier)(e);
1769
- this.touchIdentifier = touchIdentifier;
1770
-
1771
- // Get the current drag point from the event. This is used as the offset.
1772
- const position = (0, _positionFns.getControlPosition)(e, touchIdentifier, this);
1773
- if (position == null) return; // not possible but satisfies flow
1774
- const {
1775
- x,
1776
- y
1777
- } = position;
1778
-
1779
- // Create an event object with all the data parents need to make a decision here.
1780
- const coreEvent = (0, _positionFns.createCoreData)(this, x, y);
1781
- (0, _log.default)('DraggableCore: handleDragStart: %j', coreEvent);
1782
-
1783
- // Call event handler. If it returns explicit false, cancel.
1784
- (0, _log.default)('calling', this.props.onStart);
1785
- const shouldUpdate = this.props.onStart(e, coreEvent);
1786
- if (shouldUpdate === false || this.mounted === false) return;
1787
-
1788
- // Add a style to the body to disable user-select. This prevents text from
1789
- // being selected all over the page.
1790
- if (this.props.enableUserSelectHack) (0, _domFns.addUserSelectStyles)(ownerDocument);
1791
-
1792
- // Initiate dragging. Set the current x and y as offsets
1793
- // so we know how much we've moved during the drag. This allows us
1794
- // to drag elements around even if they have been moved, without issue.
1795
- this.dragging = true;
1796
- this.lastX = x;
1797
- this.lastY = y;
1798
-
1799
- // Add events to the document directly so we catch when the user's mouse/touch moves outside of
1800
- // this element. We use different events depending on whether or not we have detected that this
1801
- // is a touch-capable device.
1802
- (0, _domFns.addEvent)(ownerDocument, dragEventFor.move, this.handleDrag);
1803
- (0, _domFns.addEvent)(ownerDocument, dragEventFor.stop, this.handleDragStop);
1804
- });
1805
- _defineProperty(this, "handleDrag", e => {
1806
- // Get the current drag point from the event. This is used as the offset.
1807
- const position = (0, _positionFns.getControlPosition)(e, this.touchIdentifier, this);
1808
- if (position == null) return;
1809
- let {
1810
- x,
1811
- y
1812
- } = position;
1813
-
1814
- // Snap to grid if prop has been provided
1815
- if (Array.isArray(this.props.grid)) {
1816
- let deltaX = x - this.lastX,
1817
- deltaY = y - this.lastY;
1818
- [deltaX, deltaY] = (0, _positionFns.snapToGrid)(this.props.grid, deltaX, deltaY);
1819
- if (!deltaX && !deltaY) return; // skip useless drag
1820
- x = this.lastX + deltaX, y = this.lastY + deltaY;
1821
- }
1822
- const coreEvent = (0, _positionFns.createCoreData)(this, x, y);
1823
- (0, _log.default)('DraggableCore: handleDrag: %j', coreEvent);
1824
-
1825
- // Call event handler. If it returns explicit false, trigger end.
1826
- const shouldUpdate = this.props.onDrag(e, coreEvent);
1827
- if (shouldUpdate === false || this.mounted === false) {
1828
- try {
1829
- // $FlowIgnore
1830
- this.handleDragStop(new MouseEvent('mouseup'));
1831
- } catch (err) {
1832
- // Old browsers
1833
- const event = ((document.createEvent('MouseEvents') /*: any*/) /*: MouseTouchEvent*/);
1834
- // I see why this insanity was deprecated
1835
- // $FlowIgnore
1836
- event.initMouseEvent('mouseup', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
1837
- this.handleDragStop(event);
1838
- }
1839
- return;
1840
- }
1841
- this.lastX = x;
1842
- this.lastY = y;
1843
- });
1844
- _defineProperty(this, "handleDragStop", e => {
1845
- if (!this.dragging) return;
1846
- const position = (0, _positionFns.getControlPosition)(e, this.touchIdentifier, this);
1847
- if (position == null) return;
1848
- let {
1849
- x,
1850
- y
1851
- } = position;
1852
-
1853
- // Snap to grid if prop has been provided
1854
- if (Array.isArray(this.props.grid)) {
1855
- let deltaX = x - this.lastX || 0;
1856
- let deltaY = y - this.lastY || 0;
1857
- [deltaX, deltaY] = (0, _positionFns.snapToGrid)(this.props.grid, deltaX, deltaY);
1858
- x = this.lastX + deltaX, y = this.lastY + deltaY;
1859
- }
1860
- const coreEvent = (0, _positionFns.createCoreData)(this, x, y);
1861
-
1862
- // Call event handler
1863
- const shouldContinue = this.props.onStop(e, coreEvent);
1864
- if (shouldContinue === false || this.mounted === false) return false;
1865
- const thisNode = this.findDOMNode();
1866
- if (thisNode) {
1867
- // Remove user-select hack
1868
- if (this.props.enableUserSelectHack) (0, _domFns.removeUserSelectStyles)(thisNode.ownerDocument);
1869
- }
1870
- (0, _log.default)('DraggableCore: handleDragStop: %j', coreEvent);
1871
-
1872
- // Reset the el.
1873
- this.dragging = false;
1874
- this.lastX = NaN;
1875
- this.lastY = NaN;
1876
- if (thisNode) {
1877
- // Remove event handlers
1878
- (0, _log.default)('DraggableCore: Removing handlers');
1879
- (0, _domFns.removeEvent)(thisNode.ownerDocument, dragEventFor.move, this.handleDrag);
1880
- (0, _domFns.removeEvent)(thisNode.ownerDocument, dragEventFor.stop, this.handleDragStop);
1881
- }
1882
- });
1883
- _defineProperty(this, "onMouseDown", e => {
1884
- dragEventFor = eventsFor.mouse; // on touchscreen laptops we could switch back to mouse
1885
-
1886
- return this.handleDragStart(e);
1887
- });
1888
- _defineProperty(this, "onMouseUp", e => {
1889
- dragEventFor = eventsFor.mouse;
1890
- return this.handleDragStop(e);
1891
- });
1892
- // Same as onMouseDown (start drag), but now consider this a touch device.
1893
- _defineProperty(this, "onTouchStart", e => {
1894
- // We're on a touch device now, so change the event handlers
1895
- dragEventFor = eventsFor.touch;
1896
- return this.handleDragStart(e);
1897
- });
1898
- _defineProperty(this, "onTouchEnd", e => {
1899
- // We're on a touch device now, so change the event handlers
1900
- dragEventFor = eventsFor.touch;
1901
- return this.handleDragStop(e);
1902
- });
1903
- }
1904
- componentDidMount() {
1905
- this.mounted = true;
1906
- // Touch handlers must be added with {passive: false} to be cancelable.
1907
- // https://developers.google.com/web/updates/2017/01/scrolling-intervention
1908
- const thisNode = this.findDOMNode();
1909
- if (thisNode) {
1910
- (0, _domFns.addEvent)(thisNode, eventsFor.touch.start, this.onTouchStart, {
1911
- passive: false
1912
- });
1913
- }
1914
- }
1915
- componentWillUnmount() {
1916
- this.mounted = false;
1917
- // Remove any leftover event handlers. Remove both touch and mouse handlers in case
1918
- // some browser quirk caused a touch event to fire during a mouse move, or vice versa.
1919
- const thisNode = this.findDOMNode();
1920
- if (thisNode) {
1921
- const {
1922
- ownerDocument
1923
- } = thisNode;
1924
- (0, _domFns.removeEvent)(ownerDocument, eventsFor.mouse.move, this.handleDrag);
1925
- (0, _domFns.removeEvent)(ownerDocument, eventsFor.touch.move, this.handleDrag);
1926
- (0, _domFns.removeEvent)(ownerDocument, eventsFor.mouse.stop, this.handleDragStop);
1927
- (0, _domFns.removeEvent)(ownerDocument, eventsFor.touch.stop, this.handleDragStop);
1928
- (0, _domFns.removeEvent)(thisNode, eventsFor.touch.start, this.onTouchStart, {
1929
- passive: false
1930
- });
1931
- if (this.props.enableUserSelectHack) (0, _domFns.removeUserSelectStyles)(ownerDocument);
1932
- }
1933
- }
1934
-
1935
- // React Strict Mode compatibility: if `nodeRef` is passed, we will use it instead of trying to find
1936
- // the underlying DOM node ourselves. See the README for more information.
1937
- findDOMNode() /*: ?HTMLElement*/{
1938
- var _this$props, _this$props2;
1939
- return (_this$props = this.props) !== null && _this$props !== void 0 && _this$props.nodeRef ? (_this$props2 = this.props) === null || _this$props2 === void 0 || (_this$props2 = _this$props2.nodeRef) === null || _this$props2 === void 0 ? void 0 : _this$props2.current : _reactDom.default.findDOMNode(this);
1940
- }
1941
- render() /*: React.Element<any>*/{
1942
- // Reuse the child provided
1943
- // This makes it flexible to use whatever element is wanted (div, ul, etc)
1944
- return /*#__PURE__*/React.cloneElement(React.Children.only(this.props.children), {
1945
- // Note: mouseMove handler is attached to document so it will still function
1946
- // when the user drags quickly and leaves the bounds of the element.
1947
- onMouseDown: this.onMouseDown,
1948
- onMouseUp: this.onMouseUp,
1949
- // onTouchStart is added on `componentDidMount` so they can be added with
1950
- // {passive: false}, which allows it to cancel. See
1951
- // https://developers.google.com/web/updates/2017/01/scrolling-intervention
1952
- onTouchEnd: this.onTouchEnd
1953
- });
1954
- }
1955
- };
1956
- DraggableCore$2.default = DraggableCore$1;
1957
- _defineProperty(DraggableCore$1, "displayName", 'DraggableCore');
1958
- _defineProperty(DraggableCore$1, "propTypes", {
1959
- /**
1960
- * `allowAnyClick` allows dragging using any mouse button.
1961
- * By default, we only accept the left button.
1962
- *
1963
- * Defaults to `false`.
1964
- */
1965
- allowAnyClick: _propTypes.default.bool,
1966
- children: _propTypes.default.node.isRequired,
1967
- /**
1968
- * `disabled`, if true, stops the <Draggable> from dragging. All handlers,
1969
- * with the exception of `onMouseDown`, will not fire.
1970
- */
1971
- disabled: _propTypes.default.bool,
1972
- /**
1973
- * By default, we add 'user-select:none' attributes to the document body
1974
- * to prevent ugly text selection during drag. If this is causing problems
1975
- * for your app, set this to `false`.
1976
- */
1977
- enableUserSelectHack: _propTypes.default.bool,
1978
- /**
1979
- * `offsetParent`, if set, uses the passed DOM node to compute drag offsets
1980
- * instead of using the parent node.
1981
- */
1982
- offsetParent: function (props /*: DraggableCoreProps*/, propName /*: $Keys<DraggableCoreProps>*/) {
1983
- if (props[propName] && props[propName].nodeType !== 1) {
1984
- throw new Error('Draggable\'s offsetParent must be a DOM Node.');
1985
- }
1986
- },
1987
- /**
1988
- * `grid` specifies the x and y that dragging should snap to.
1989
- */
1990
- grid: _propTypes.default.arrayOf(_propTypes.default.number),
1991
- /**
1992
- * `handle` specifies a selector to be used as the handle that initiates drag.
1993
- *
1994
- * Example:
1995
- *
1996
- * ```jsx
1997
- * let App = React.createClass({
1998
- * render: function () {
1999
- * return (
2000
- * <Draggable handle=".handle">
2001
- * <div>
2002
- * <div className="handle">Click me to drag</div>
2003
- * <div>This is some other content</div>
2004
- * </div>
2005
- * </Draggable>
2006
- * );
2007
- * }
2008
- * });
2009
- * ```
2010
- */
2011
- handle: _propTypes.default.string,
2012
- /**
2013
- * `cancel` specifies a selector to be used to prevent drag initialization.
2014
- *
2015
- * Example:
2016
- *
2017
- * ```jsx
2018
- * let App = React.createClass({
2019
- * render: function () {
2020
- * return(
2021
- * <Draggable cancel=".cancel">
2022
- * <div>
2023
- * <div className="cancel">You can't drag from here</div>
2024
- * <div>Dragging here works fine</div>
2025
- * </div>
2026
- * </Draggable>
2027
- * );
2028
- * }
2029
- * });
2030
- * ```
2031
- */
2032
- cancel: _propTypes.default.string,
2033
- /* If running in React Strict mode, ReactDOM.findDOMNode() is deprecated.
2034
- * Unfortunately, in order for <Draggable> to work properly, we need raw access
2035
- * to the underlying DOM node. If you want to avoid the warning, pass a `nodeRef`
2036
- * as in this example:
2037
- *
2038
- * function MyComponent() {
2039
- * const nodeRef = React.useRef(null);
2040
- * return (
2041
- * <Draggable nodeRef={nodeRef}>
2042
- * <div ref={nodeRef}>Example Target</div>
2043
- * </Draggable>
2044
- * );
2045
- * }
2046
- *
2047
- * This can be used for arbitrarily nested components, so long as the ref ends up
2048
- * pointing to the actual child DOM node and not a custom component.
2049
- */
2050
- nodeRef: _propTypes.default.object,
2051
- /**
2052
- * Called when dragging starts.
2053
- * If this function returns the boolean false, dragging will be canceled.
2054
- */
2055
- onStart: _propTypes.default.func,
2056
- /**
2057
- * Called while dragging.
2058
- * If this function returns the boolean false, dragging will be canceled.
2059
- */
2060
- onDrag: _propTypes.default.func,
2061
- /**
2062
- * Called when dragging stops.
2063
- * If this function returns the boolean false, the drag will remain active.
2064
- */
2065
- onStop: _propTypes.default.func,
2066
- /**
2067
- * A workaround option which can be passed if onMouseDown needs to be accessed,
2068
- * since it'll always be blocked (as there is internal use of onMouseDown)
2069
- */
2070
- onMouseDown: _propTypes.default.func,
2071
- /**
2072
- * `scale`, if set, applies scaling while dragging an element
2073
- */
2074
- scale: _propTypes.default.number,
2075
- /**
2076
- * These properties should be defined on the child, not here.
2077
- */
2078
- className: _shims.dontSetMe,
2079
- style: _shims.dontSetMe,
2080
- transform: _shims.dontSetMe
2081
- });
2082
- _defineProperty(DraggableCore$1, "defaultProps", {
2083
- allowAnyClick: false,
2084
- // by default only accept left click
2085
- disabled: false,
2086
- enableUserSelectHack: true,
2087
- onStart: function () {},
2088
- onDrag: function () {},
2089
- onStop: function () {},
2090
- onMouseDown: function () {},
2091
- scale: 1
2092
- });
2093
-
2094
- (function (exports) {
2095
-
2096
- Object.defineProperty(exports, "__esModule", {
2097
- value: true
2098
- });
2099
- Object.defineProperty(exports, "DraggableCore", {
2100
- enumerable: true,
2101
- get: function () {
2102
- return _DraggableCore.default;
2103
- }
2104
- });
2105
- exports.default = void 0;
2106
- var React = _interopRequireWildcard(React__default);
2107
- var _propTypes = _interopRequireDefault(propTypesExports);
2108
- var _reactDom = _interopRequireDefault(ReactDOM__default);
2109
- var _clsx = _interopRequireDefault(require$$3);
2110
- var _domFns = domFns;
2111
- var _positionFns = positionFns;
2112
- var _shims = shims;
2113
- var _DraggableCore = _interopRequireDefault(DraggableCore$2);
2114
- var _log = _interopRequireDefault(log$1);
2115
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2116
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
2117
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
2118
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2119
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2120
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
2121
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /*:: import type {ControlPosition, PositionOffsetControlPosition, DraggableCoreProps, DraggableCoreDefaultProps} from './DraggableCore';*/
2122
- /*:: import type {Bounds, DraggableEventHandler} from './utils/types';*/
2123
- /*:: import type {Element as ReactElement} from 'react';*/
2124
- /*:: type DraggableState = {
2125
- dragging: boolean,
2126
- dragged: boolean,
2127
- x: number, y: number,
2128
- slackX: number, slackY: number,
2129
- isElementSVG: boolean,
2130
- prevPropsPosition: ?ControlPosition,
2131
- };*/
2132
- /*:: export type DraggableDefaultProps = {
2133
- ...DraggableCoreDefaultProps,
2134
- axis: 'both' | 'x' | 'y' | 'none',
2135
- bounds: Bounds | string | false,
2136
- defaultClassName: string,
2137
- defaultClassNameDragging: string,
2138
- defaultClassNameDragged: string,
2139
- defaultPosition: ControlPosition,
2140
- scale: number,
2141
- };*/
2142
- /*:: export type DraggableProps = {
2143
- ...DraggableCoreProps,
2144
- ...DraggableDefaultProps,
2145
- positionOffset: PositionOffsetControlPosition,
2146
- position: ControlPosition,
2147
- };*/
2148
- //
2149
- // Define <Draggable>
2150
- //
2151
- class Draggable extends React.Component /*:: <DraggableProps, DraggableState>*/{
2152
- // React 16.3+
2153
- // Arity (props, state)
2154
- static getDerivedStateFromProps(_ref /*:: */, _ref2 /*:: */) /*: ?Partial<DraggableState>*/{
2155
- let {
2156
- position
2157
- } /*: DraggableProps*/ = _ref /*: DraggableProps*/;
2158
- let {
2159
- prevPropsPosition
2160
- } /*: DraggableState*/ = _ref2 /*: DraggableState*/;
2161
- // Set x/y if a new position is provided in props that is different than the previous.
2162
- if (position && (!prevPropsPosition || position.x !== prevPropsPosition.x || position.y !== prevPropsPosition.y)) {
2163
- (0, _log.default)('Draggable: getDerivedStateFromProps %j', {
2164
- position,
2165
- prevPropsPosition
2166
- });
2167
- return {
2168
- x: position.x,
2169
- y: position.y,
2170
- prevPropsPosition: {
2171
- ...position
2172
- }
2173
- };
2174
- }
2175
- return null;
2176
- }
2177
- constructor(props /*: DraggableProps*/) {
2178
- super(props);
2179
- _defineProperty(this, "onDragStart", (e, coreData) => {
2180
- (0, _log.default)('Draggable: onDragStart: %j', coreData);
2181
-
2182
- // Short-circuit if user's callback killed it.
2183
- const shouldStart = this.props.onStart(e, (0, _positionFns.createDraggableData)(this, coreData));
2184
- // Kills start event on core as well, so move handlers are never bound.
2185
- if (shouldStart === false) return false;
2186
- this.setState({
2187
- dragging: true,
2188
- dragged: true
2189
- });
2190
- });
2191
- _defineProperty(this, "onDrag", (e, coreData) => {
2192
- if (!this.state.dragging) return false;
2193
- (0, _log.default)('Draggable: onDrag: %j', coreData);
2194
- const uiData = (0, _positionFns.createDraggableData)(this, coreData);
2195
- const newState = {
2196
- x: uiData.x,
2197
- y: uiData.y,
2198
- slackX: 0,
2199
- slackY: 0
2200
- };
2201
-
2202
- // Keep within bounds.
2203
- if (this.props.bounds) {
2204
- // Save original x and y.
2205
- const {
2206
- x,
2207
- y
2208
- } = newState;
2209
-
2210
- // Add slack to the values used to calculate bound position. This will ensure that if
2211
- // we start removing slack, the element won't react to it right away until it's been
2212
- // completely removed.
2213
- newState.x += this.state.slackX;
2214
- newState.y += this.state.slackY;
2215
-
2216
- // Get bound position. This will ceil/floor the x and y within the boundaries.
2217
- const [newStateX, newStateY] = (0, _positionFns.getBoundPosition)(this, newState.x, newState.y);
2218
- newState.x = newStateX;
2219
- newState.y = newStateY;
2220
-
2221
- // Recalculate slack by noting how much was shaved by the boundPosition handler.
2222
- newState.slackX = this.state.slackX + (x - newState.x);
2223
- newState.slackY = this.state.slackY + (y - newState.y);
2224
-
2225
- // Update the event we fire to reflect what really happened after bounds took effect.
2226
- uiData.x = newState.x;
2227
- uiData.y = newState.y;
2228
- uiData.deltaX = newState.x - this.state.x;
2229
- uiData.deltaY = newState.y - this.state.y;
2230
- }
2231
-
2232
- // Short-circuit if user's callback killed it.
2233
- const shouldUpdate = this.props.onDrag(e, uiData);
2234
- if (shouldUpdate === false) return false;
2235
- this.setState(newState);
2236
- });
2237
- _defineProperty(this, "onDragStop", (e, coreData) => {
2238
- if (!this.state.dragging) return false;
2239
-
2240
- // Short-circuit if user's callback killed it.
2241
- const shouldContinue = this.props.onStop(e, (0, _positionFns.createDraggableData)(this, coreData));
2242
- if (shouldContinue === false) return false;
2243
- (0, _log.default)('Draggable: onDragStop: %j', coreData);
2244
- const newState /*: Partial<DraggableState>*/ = {
2245
- dragging: false,
2246
- slackX: 0,
2247
- slackY: 0
2248
- };
2249
-
2250
- // If this is a controlled component, the result of this operation will be to
2251
- // revert back to the old position. We expect a handler on `onDragStop`, at the least.
2252
- const controlled = Boolean(this.props.position);
2253
- if (controlled) {
2254
- const {
2255
- x,
2256
- y
2257
- } = this.props.position;
2258
- newState.x = x;
2259
- newState.y = y;
2260
- }
2261
- this.setState(newState);
2262
- });
2263
- this.state = {
2264
- // Whether or not we are currently dragging.
2265
- dragging: false,
2266
- // Whether or not we have been dragged before.
2267
- dragged: false,
2268
- // Current transform x and y.
2269
- x: props.position ? props.position.x : props.defaultPosition.x,
2270
- y: props.position ? props.position.y : props.defaultPosition.y,
2271
- prevPropsPosition: {
2272
- ...props.position
2273
- },
2274
- // Used for compensating for out-of-bounds drags
2275
- slackX: 0,
2276
- slackY: 0,
2277
- // Can only determine if SVG after mounting
2278
- isElementSVG: false
2279
- };
2280
- if (props.position && !(props.onDrag || props.onStop)) {
2281
- // eslint-disable-next-line no-console
2282
- console.warn('A `position` was applied to this <Draggable>, without drag handlers. This will make this ' + 'component effectively undraggable. Please attach `onDrag` or `onStop` handlers so you can adjust the ' + '`position` of this element.');
2283
- }
2284
- }
2285
- componentDidMount() {
2286
- // Check to see if the element passed is an instanceof SVGElement
2287
- if (typeof window.SVGElement !== 'undefined' && this.findDOMNode() instanceof window.SVGElement) {
2288
- this.setState({
2289
- isElementSVG: true
2290
- });
2291
- }
2292
- }
2293
- componentWillUnmount() {
2294
- this.setState({
2295
- dragging: false
2296
- }); // prevents invariant if unmounted while dragging
2297
- }
2298
-
2299
- // React Strict Mode compatibility: if `nodeRef` is passed, we will use it instead of trying to find
2300
- // the underlying DOM node ourselves. See the README for more information.
2301
- findDOMNode() /*: ?HTMLElement*/{
2302
- var _this$props$nodeRef$c, _this$props;
2303
- return (_this$props$nodeRef$c = (_this$props = this.props) === null || _this$props === void 0 || (_this$props = _this$props.nodeRef) === null || _this$props === void 0 ? void 0 : _this$props.current) !== null && _this$props$nodeRef$c !== void 0 ? _this$props$nodeRef$c : _reactDom.default.findDOMNode(this);
2304
- }
2305
- render() /*: ReactElement<any>*/{
2306
- const {
2307
- axis,
2308
- bounds,
2309
- children,
2310
- defaultPosition,
2311
- defaultClassName,
2312
- defaultClassNameDragging,
2313
- defaultClassNameDragged,
2314
- position,
2315
- positionOffset,
2316
- scale,
2317
- ...draggableCoreProps
2318
- } = this.props;
2319
- let style = {};
2320
- let svgTransform = null;
2321
-
2322
- // If this is controlled, we don't want to move it - unless it's dragging.
2323
- const controlled = Boolean(position);
2324
- const draggable = !controlled || this.state.dragging;
2325
- const validPosition = position || defaultPosition;
2326
- const transformOpts = {
2327
- // Set left if horizontal drag is enabled
2328
- x: (0, _positionFns.canDragX)(this) && draggable ? this.state.x : validPosition.x,
2329
- // Set top if vertical drag is enabled
2330
- y: (0, _positionFns.canDragY)(this) && draggable ? this.state.y : validPosition.y
2331
- };
2332
-
2333
- // If this element was SVG, we use the `transform` attribute.
2334
- if (this.state.isElementSVG) {
2335
- svgTransform = (0, _domFns.createSVGTransform)(transformOpts, positionOffset);
2336
- } else {
2337
- // Add a CSS transform to move the element around. This allows us to move the element around
2338
- // without worrying about whether or not it is relatively or absolutely positioned.
2339
- // If the item you are dragging already has a transform set, wrap it in a <span> so <Draggable>
2340
- // has a clean slate.
2341
- style = (0, _domFns.createCSSTransform)(transformOpts, positionOffset);
2342
- }
2343
-
2344
- // Mark with class while dragging
2345
- const className = (0, _clsx.default)(children.props.className || '', defaultClassName, {
2346
- [defaultClassNameDragging]: this.state.dragging,
2347
- [defaultClassNameDragged]: this.state.dragged
2348
- });
2349
-
2350
- // Reuse the child provided
2351
- // This makes it flexible to use whatever element is wanted (div, ul, etc)
2352
- return /*#__PURE__*/React.createElement(_DraggableCore.default, _extends({}, draggableCoreProps, {
2353
- onStart: this.onDragStart,
2354
- onDrag: this.onDrag,
2355
- onStop: this.onDragStop
2356
- }), /*#__PURE__*/React.cloneElement(React.Children.only(children), {
2357
- className: className,
2358
- style: {
2359
- ...children.props.style,
2360
- ...style
2361
- },
2362
- transform: svgTransform
2363
- }));
2364
- }
2365
- }
2366
- exports.default = Draggable;
2367
- _defineProperty(Draggable, "displayName", 'Draggable');
2368
- _defineProperty(Draggable, "propTypes", {
2369
- // Accepts all props <DraggableCore> accepts.
2370
- ..._DraggableCore.default.propTypes,
2371
- /**
2372
- * `axis` determines which axis the draggable can move.
2373
- *
2374
- * Note that all callbacks will still return data as normal. This only
2375
- * controls flushing to the DOM.
2376
- *
2377
- * 'both' allows movement horizontally and vertically.
2378
- * 'x' limits movement to horizontal axis.
2379
- * 'y' limits movement to vertical axis.
2380
- * 'none' limits all movement.
2381
- *
2382
- * Defaults to 'both'.
2383
- */
2384
- axis: _propTypes.default.oneOf(['both', 'x', 'y', 'none']),
2385
- /**
2386
- * `bounds` determines the range of movement available to the element.
2387
- * Available values are:
2388
- *
2389
- * 'parent' restricts movement within the Draggable's parent node.
2390
- *
2391
- * Alternatively, pass an object with the following properties, all of which are optional:
2392
- *
2393
- * {left: LEFT_BOUND, right: RIGHT_BOUND, bottom: BOTTOM_BOUND, top: TOP_BOUND}
2394
- *
2395
- * All values are in px.
2396
- *
2397
- * Example:
2398
- *
2399
- * ```jsx
2400
- * let App = React.createClass({
2401
- * render: function () {
2402
- * return (
2403
- * <Draggable bounds={{right: 300, bottom: 300}}>
2404
- * <div>Content</div>
2405
- * </Draggable>
2406
- * );
2407
- * }
2408
- * });
2409
- * ```
2410
- */
2411
- bounds: _propTypes.default.oneOfType([_propTypes.default.shape({
2412
- left: _propTypes.default.number,
2413
- right: _propTypes.default.number,
2414
- top: _propTypes.default.number,
2415
- bottom: _propTypes.default.number
2416
- }), _propTypes.default.string, _propTypes.default.oneOf([false])]),
2417
- defaultClassName: _propTypes.default.string,
2418
- defaultClassNameDragging: _propTypes.default.string,
2419
- defaultClassNameDragged: _propTypes.default.string,
2420
- /**
2421
- * `defaultPosition` specifies the x and y that the dragged item should start at
2422
- *
2423
- * Example:
2424
- *
2425
- * ```jsx
2426
- * let App = React.createClass({
2427
- * render: function () {
2428
- * return (
2429
- * <Draggable defaultPosition={{x: 25, y: 25}}>
2430
- * <div>I start with transformX: 25px and transformY: 25px;</div>
2431
- * </Draggable>
2432
- * );
2433
- * }
2434
- * });
2435
- * ```
2436
- */
2437
- defaultPosition: _propTypes.default.shape({
2438
- x: _propTypes.default.number,
2439
- y: _propTypes.default.number
2440
- }),
2441
- positionOffset: _propTypes.default.shape({
2442
- x: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
2443
- y: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
2444
- }),
2445
- /**
2446
- * `position`, if present, defines the current position of the element.
2447
- *
2448
- * This is similar to how form elements in React work - if no `position` is supplied, the component
2449
- * is uncontrolled.
2450
- *
2451
- * Example:
2452
- *
2453
- * ```jsx
2454
- * let App = React.createClass({
2455
- * render: function () {
2456
- * return (
2457
- * <Draggable position={{x: 25, y: 25}}>
2458
- * <div>I start with transformX: 25px and transformY: 25px;</div>
2459
- * </Draggable>
2460
- * );
2461
- * }
2462
- * });
2463
- * ```
2464
- */
2465
- position: _propTypes.default.shape({
2466
- x: _propTypes.default.number,
2467
- y: _propTypes.default.number
2468
- }),
2469
- /**
2470
- * These properties should be defined on the child, not here.
2471
- */
2472
- className: _shims.dontSetMe,
2473
- style: _shims.dontSetMe,
2474
- transform: _shims.dontSetMe
2475
- });
2476
- _defineProperty(Draggable, "defaultProps", {
2477
- ..._DraggableCore.default.defaultProps,
2478
- axis: 'both',
2479
- bounds: false,
2480
- defaultClassName: 'react-draggable',
2481
- defaultClassNameDragging: 'react-draggable-dragging',
2482
- defaultClassNameDragged: 'react-draggable-dragged',
2483
- defaultPosition: {
2484
- x: 0,
2485
- y: 0
2486
- },
2487
- scale: 1
2488
- });
2489
- } (Draggable$1));
2490
-
2491
- const {
2492
- default: Draggable,
2493
- DraggableCore
2494
- } = Draggable$1;
2495
-
2496
- // Previous versions of this lib exported <Draggable> as the root export. As to no-// them, or TypeScript, we export *both* as the root and as 'default'.
2497
- // See https://github.com/mzabriskie/react-draggable/pull/254
2498
- // and https://github.com/mzabriskie/react-draggable/issues/266
2499
- cjs.exports = Draggable;
2500
- cjsExports.default = Draggable;
2501
- cjsExports.DraggableCore = DraggableCore;
2502
-
2503
- var __assign$2 = (undefined && undefined.__assign) || function () {
2504
- __assign$2 = Object.assign || function(t) {
2505
- for (var s, i = 1, n = arguments.length; i < n; i++) {
2506
- s = arguments[i];
2507
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
2508
- t[p] = s[p];
2509
- }
2510
- return t;
2511
- };
2512
- return __assign$2.apply(this, arguments);
2513
- };
2514
- var rowSizeBase = {
2515
- width: '100%',
2516
- height: '10px',
2517
- top: '0px',
2518
- left: '0px',
2519
- cursor: 'row-resize',
2520
- };
2521
- var colSizeBase = {
2522
- width: '10px',
2523
- height: '100%',
2524
- top: '0px',
2525
- left: '0px',
2526
- cursor: 'col-resize',
2527
- };
2528
- var edgeBase = {
2529
- width: '20px',
2530
- height: '20px',
2531
- position: 'absolute',
2532
- zIndex: 1,
2533
- };
2534
- var styles = {
2535
- top: __assign$2(__assign$2({}, rowSizeBase), { top: '-5px' }),
2536
- right: __assign$2(__assign$2({}, colSizeBase), { left: undefined, right: '-5px' }),
2537
- bottom: __assign$2(__assign$2({}, rowSizeBase), { top: undefined, bottom: '-5px' }),
2538
- left: __assign$2(__assign$2({}, colSizeBase), { left: '-5px' }),
2539
- topRight: __assign$2(__assign$2({}, edgeBase), { right: '-10px', top: '-10px', cursor: 'ne-resize' }),
2540
- bottomRight: __assign$2(__assign$2({}, edgeBase), { right: '-10px', bottom: '-10px', cursor: 'se-resize' }),
2541
- bottomLeft: __assign$2(__assign$2({}, edgeBase), { left: '-10px', bottom: '-10px', cursor: 'sw-resize' }),
2542
- topLeft: __assign$2(__assign$2({}, edgeBase), { left: '-10px', top: '-10px', cursor: 'nw-resize' }),
2543
- };
2544
- var Resizer = memo(function (props) {
2545
- var onResizeStart = props.onResizeStart, direction = props.direction, children = props.children, replaceStyles = props.replaceStyles, className = props.className;
2546
- var onMouseDown = useCallback(function (e) {
2547
- onResizeStart(e, direction);
2548
- }, [onResizeStart, direction]);
2549
- var onTouchStart = useCallback(function (e) {
2550
- onResizeStart(e, direction);
2551
- }, [onResizeStart, direction]);
2552
- var style = useMemo(function () {
2553
- return __assign$2(__assign$2({ position: 'absolute', userSelect: 'none' }, styles[direction]), (replaceStyles !== null && replaceStyles !== void 0 ? replaceStyles : {}));
2554
- }, [replaceStyles, direction]);
2555
- return (jsx("div", { className: className || undefined, style: style, onMouseDown: onMouseDown, onTouchStart: onTouchStart, children: children }));
2556
- });
2557
-
2558
- var __extends$1 = (undefined && undefined.__extends) || (function () {
2559
- var extendStatics = function (d, b) {
2560
- extendStatics = Object.setPrototypeOf ||
2561
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
2562
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
2563
- return extendStatics(d, b);
2564
- };
2565
- return function (d, b) {
2566
- if (typeof b !== "function" && b !== null)
2567
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
2568
- extendStatics(d, b);
2569
- function __() { this.constructor = d; }
2570
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
2571
- };
2572
- })();
2573
- var __assign$1 = (undefined && undefined.__assign) || function () {
2574
- __assign$1 = Object.assign || function(t) {
2575
- for (var s, i = 1, n = arguments.length; i < n; i++) {
2576
- s = arguments[i];
2577
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
2578
- t[p] = s[p];
2579
- }
2580
- return t;
2581
- };
2582
- return __assign$1.apply(this, arguments);
2583
- };
2584
- var DEFAULT_SIZE = {
2585
- width: 'auto',
2586
- height: 'auto',
2587
- };
2588
- var clamp = function (n, min, max) { return Math.max(Math.min(n, max), min); };
2589
- var snap = function (n, size, gridGap) {
2590
- var v = Math.round(n / size);
2591
- return v * size + gridGap * (v - 1);
2592
- };
2593
- var hasDirection = function (dir, target) {
2594
- return new RegExp(dir, 'i').test(target);
2595
- };
2596
- // INFO: In case of window is a Proxy and does not porxy Events correctly, use isTouchEvent & isMouseEvent to distinguish event type instead of `instanceof`.
2597
- var isTouchEvent = function (event) {
2598
- return Boolean(event.touches && event.touches.length);
2599
- };
2600
- var isMouseEvent = function (event) {
2601
- return Boolean((event.clientX || event.clientX === 0) &&
2602
- (event.clientY || event.clientY === 0));
2603
- };
2604
- var findClosestSnap = function (n, snapArray, snapGap) {
2605
- if (snapGap === void 0) { snapGap = 0; }
2606
- var closestGapIndex = snapArray.reduce(function (prev, curr, index) { return (Math.abs(curr - n) < Math.abs(snapArray[prev] - n) ? index : prev); }, 0);
2607
- var gap = Math.abs(snapArray[closestGapIndex] - n);
2608
- return snapGap === 0 || gap < snapGap ? snapArray[closestGapIndex] : n;
2609
- };
2610
- var getStringSize = function (n) {
2611
- n = n.toString();
2612
- if (n === 'auto') {
2613
- return n;
2614
- }
2615
- if (n.endsWith('px')) {
2616
- return n;
2617
- }
2618
- if (n.endsWith('%')) {
2619
- return n;
2620
- }
2621
- if (n.endsWith('vh')) {
2622
- return n;
2623
- }
2624
- if (n.endsWith('vw')) {
2625
- return n;
2626
- }
2627
- if (n.endsWith('vmax')) {
2628
- return n;
2629
- }
2630
- if (n.endsWith('vmin')) {
2631
- return n;
2632
- }
2633
- return "".concat(n, "px");
2634
- };
2635
- var getPixelSize = function (size, parentSize, innerWidth, innerHeight) {
2636
- if (size && typeof size === 'string') {
2637
- if (size.endsWith('px')) {
2638
- return Number(size.replace('px', ''));
2639
- }
2640
- if (size.endsWith('%')) {
2641
- var ratio = Number(size.replace('%', '')) / 100;
2642
- return parentSize * ratio;
2643
- }
2644
- if (size.endsWith('vw')) {
2645
- var ratio = Number(size.replace('vw', '')) / 100;
2646
- return innerWidth * ratio;
2647
- }
2648
- if (size.endsWith('vh')) {
2649
- var ratio = Number(size.replace('vh', '')) / 100;
2650
- return innerHeight * ratio;
2651
- }
2652
- }
2653
- return size;
2654
- };
2655
- var calculateNewMax = function (parentSize, innerWidth, innerHeight, maxWidth, maxHeight, minWidth, minHeight) {
2656
- maxWidth = getPixelSize(maxWidth, parentSize.width, innerWidth, innerHeight);
2657
- maxHeight = getPixelSize(maxHeight, parentSize.height, innerWidth, innerHeight);
2658
- minWidth = getPixelSize(minWidth, parentSize.width, innerWidth, innerHeight);
2659
- minHeight = getPixelSize(minHeight, parentSize.height, innerWidth, innerHeight);
2660
- return {
2661
- maxWidth: typeof maxWidth === 'undefined' ? undefined : Number(maxWidth),
2662
- maxHeight: typeof maxHeight === 'undefined' ? undefined : Number(maxHeight),
2663
- minWidth: typeof minWidth === 'undefined' ? undefined : Number(minWidth),
2664
- minHeight: typeof minHeight === 'undefined' ? undefined : Number(minHeight),
2665
- };
2666
- };
2667
- /**
2668
- * transform T | [T, T] to [T, T]
2669
- * @param val
2670
- * @returns
2671
- */
2672
- // tslint:disable-next-line
2673
- var normalizeToPair = function (val) { return (Array.isArray(val) ? val : [val, val]); };
2674
- var definedProps = [
2675
- 'as',
2676
- 'ref',
2677
- 'style',
2678
- 'className',
2679
- 'grid',
2680
- 'gridGap',
2681
- 'snap',
2682
- 'bounds',
2683
- 'boundsByDirection',
2684
- 'size',
2685
- 'defaultSize',
2686
- 'minWidth',
2687
- 'minHeight',
2688
- 'maxWidth',
2689
- 'maxHeight',
2690
- 'lockAspectRatio',
2691
- 'lockAspectRatioExtraWidth',
2692
- 'lockAspectRatioExtraHeight',
2693
- 'enable',
2694
- 'handleStyles',
2695
- 'handleClasses',
2696
- 'handleWrapperStyle',
2697
- 'handleWrapperClass',
2698
- 'children',
2699
- 'onResizeStart',
2700
- 'onResize',
2701
- 'onResizeStop',
2702
- 'handleComponent',
2703
- 'scale',
2704
- 'resizeRatio',
2705
- 'snapGap',
2706
- ];
2707
- // HACK: This class is used to calculate % size.
2708
- var baseClassName = '__resizable_base__';
2709
- var Resizable = /** @class */ (function (_super) {
2710
- __extends$1(Resizable, _super);
2711
- function Resizable(props) {
2712
- var _a, _b, _c, _d;
2713
- var _this = _super.call(this, props) || this;
2714
- _this.ratio = 1;
2715
- _this.resizable = null;
2716
- // For parent boundary
2717
- _this.parentLeft = 0;
2718
- _this.parentTop = 0;
2719
- // For boundary
2720
- _this.resizableLeft = 0;
2721
- _this.resizableRight = 0;
2722
- _this.resizableTop = 0;
2723
- _this.resizableBottom = 0;
2724
- // For target boundary
2725
- _this.targetLeft = 0;
2726
- _this.targetTop = 0;
2727
- _this.delta = {
2728
- width: 0,
2729
- height: 0,
2730
- };
2731
- _this.appendBase = function () {
2732
- if (!_this.resizable || !_this.window) {
2733
- return null;
2734
- }
2735
- var parent = _this.parentNode;
2736
- if (!parent) {
2737
- return null;
2738
- }
2739
- var element = _this.window.document.createElement('div');
2740
- element.style.width = '100%';
2741
- element.style.height = '100%';
2742
- element.style.position = 'absolute';
2743
- element.style.transform = 'scale(0, 0)';
2744
- element.style.left = '0';
2745
- element.style.flex = '0 0 100%';
2746
- if (element.classList) {
2747
- element.classList.add(baseClassName);
2748
- }
2749
- else {
2750
- element.className += baseClassName;
2751
- }
2752
- parent.appendChild(element);
2753
- return element;
2754
- };
2755
- _this.removeBase = function (base) {
2756
- var parent = _this.parentNode;
2757
- if (!parent) {
2758
- return;
2759
- }
2760
- parent.removeChild(base);
2761
- };
2762
- _this.state = {
2763
- isResizing: false,
2764
- width: (_b = (_a = _this.propsSize) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 'auto',
2765
- height: (_d = (_c = _this.propsSize) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : 'auto',
2766
- direction: 'right',
2767
- original: {
2768
- x: 0,
2769
- y: 0,
2770
- width: 0,
2771
- height: 0,
2772
- },
2773
- backgroundStyle: {
2774
- height: '100%',
2775
- width: '100%',
2776
- backgroundColor: 'rgba(0,0,0,0)',
2777
- cursor: 'auto',
2778
- opacity: 0,
2779
- position: 'fixed',
2780
- zIndex: 9999,
2781
- top: '0',
2782
- left: '0',
2783
- bottom: '0',
2784
- right: '0',
2785
- },
2786
- flexBasis: undefined,
2787
- };
2788
- _this.onResizeStart = _this.onResizeStart.bind(_this);
2789
- _this.onMouseMove = _this.onMouseMove.bind(_this);
2790
- _this.onMouseUp = _this.onMouseUp.bind(_this);
2791
- return _this;
2792
- }
2793
- Object.defineProperty(Resizable.prototype, "parentNode", {
2794
- get: function () {
2795
- if (!this.resizable) {
2796
- return null;
2797
- }
2798
- return this.resizable.parentNode;
2799
- },
2800
- enumerable: false,
2801
- configurable: true
2802
- });
2803
- Object.defineProperty(Resizable.prototype, "window", {
2804
- get: function () {
2805
- if (!this.resizable) {
2806
- return null;
2807
- }
2808
- if (!this.resizable.ownerDocument) {
2809
- return null;
2810
- }
2811
- return this.resizable.ownerDocument.defaultView;
2812
- },
2813
- enumerable: false,
2814
- configurable: true
2815
- });
2816
- Object.defineProperty(Resizable.prototype, "propsSize", {
2817
- get: function () {
2818
- return this.props.size || this.props.defaultSize || DEFAULT_SIZE;
2819
- },
2820
- enumerable: false,
2821
- configurable: true
2822
- });
2823
- Object.defineProperty(Resizable.prototype, "size", {
2824
- get: function () {
2825
- var width = 0;
2826
- var height = 0;
2827
- if (this.resizable && this.window) {
2828
- var orgWidth = this.resizable.offsetWidth;
2829
- var orgHeight = this.resizable.offsetHeight;
2830
- // HACK: Set position `relative` to get parent size.
2831
- // This is because when re-resizable set `absolute`, I can not get base width correctly.
2832
- var orgPosition = this.resizable.style.position;
2833
- if (orgPosition !== 'relative') {
2834
- this.resizable.style.position = 'relative';
2835
- }
2836
- // INFO: Use original width or height if set auto.
2837
- width = this.resizable.style.width !== 'auto' ? this.resizable.offsetWidth : orgWidth;
2838
- height = this.resizable.style.height !== 'auto' ? this.resizable.offsetHeight : orgHeight;
2839
- // Restore original position
2840
- this.resizable.style.position = orgPosition;
2841
- }
2842
- return { width: width, height: height };
2843
- },
2844
- enumerable: false,
2845
- configurable: true
2846
- });
2847
- Object.defineProperty(Resizable.prototype, "sizeStyle", {
2848
- get: function () {
2849
- var _this = this;
2850
- var size = this.props.size;
2851
- var getSize = function (key) {
2852
- var _a;
2853
- if (typeof _this.state[key] === 'undefined' || _this.state[key] === 'auto') {
2854
- return 'auto';
2855
- }
2856
- if (_this.propsSize && _this.propsSize[key] && ((_a = _this.propsSize[key]) === null || _a === void 0 ? void 0 : _a.toString().endsWith('%'))) {
2857
- if (_this.state[key].toString().endsWith('%')) {
2858
- return _this.state[key].toString();
2859
- }
2860
- var parentSize = _this.getParentSize();
2861
- var value = Number(_this.state[key].toString().replace('px', ''));
2862
- var percent = (value / parentSize[key]) * 100;
2863
- return "".concat(percent, "%");
2864
- }
2865
- return getStringSize(_this.state[key]);
2866
- };
2867
- var width = size && typeof size.width !== 'undefined' && !this.state.isResizing
2868
- ? getStringSize(size.width)
2869
- : getSize('width');
2870
- var height = size && typeof size.height !== 'undefined' && !this.state.isResizing
2871
- ? getStringSize(size.height)
2872
- : getSize('height');
2873
- return { width: width, height: height };
2874
- },
2875
- enumerable: false,
2876
- configurable: true
2877
- });
2878
- Resizable.prototype.getParentSize = function () {
2879
- if (!this.parentNode) {
2880
- if (!this.window) {
2881
- return { width: 0, height: 0 };
2882
- }
2883
- return { width: this.window.innerWidth, height: this.window.innerHeight };
2884
- }
2885
- var base = this.appendBase();
2886
- if (!base) {
2887
- return { width: 0, height: 0 };
2888
- }
2889
- // INFO: To calculate parent width with flex layout
2890
- var wrapChanged = false;
2891
- var wrap = this.parentNode.style.flexWrap;
2892
- if (wrap !== 'wrap') {
2893
- wrapChanged = true;
2894
- this.parentNode.style.flexWrap = 'wrap';
2895
- // HACK: Use relative to get parent padding size
2896
- }
2897
- base.style.position = 'relative';
2898
- base.style.minWidth = '100%';
2899
- base.style.minHeight = '100%';
2900
- var size = {
2901
- width: base.offsetWidth,
2902
- height: base.offsetHeight,
2903
- };
2904
- if (wrapChanged) {
2905
- this.parentNode.style.flexWrap = wrap;
2906
- }
2907
- this.removeBase(base);
2908
- return size;
2909
- };
2910
- Resizable.prototype.bindEvents = function () {
2911
- if (this.window) {
2912
- this.window.addEventListener('mouseup', this.onMouseUp);
2913
- this.window.addEventListener('mousemove', this.onMouseMove);
2914
- this.window.addEventListener('mouseleave', this.onMouseUp);
2915
- this.window.addEventListener('touchmove', this.onMouseMove, {
2916
- capture: true,
2917
- passive: false,
2918
- });
2919
- this.window.addEventListener('touchend', this.onMouseUp);
2920
- }
2921
- };
2922
- Resizable.prototype.unbindEvents = function () {
2923
- if (this.window) {
2924
- this.window.removeEventListener('mouseup', this.onMouseUp);
2925
- this.window.removeEventListener('mousemove', this.onMouseMove);
2926
- this.window.removeEventListener('mouseleave', this.onMouseUp);
2927
- this.window.removeEventListener('touchmove', this.onMouseMove, true);
2928
- this.window.removeEventListener('touchend', this.onMouseUp);
2929
- }
2930
- };
2931
- Resizable.prototype.componentDidMount = function () {
2932
- if (!this.resizable || !this.window) {
2933
- return;
2934
- }
2935
- var computedStyle = this.window.getComputedStyle(this.resizable);
2936
- this.setState({
2937
- width: this.state.width || this.size.width,
2938
- height: this.state.height || this.size.height,
2939
- flexBasis: computedStyle.flexBasis !== 'auto' ? computedStyle.flexBasis : undefined,
2940
- });
2941
- };
2942
- Resizable.prototype.componentWillUnmount = function () {
2943
- if (this.window) {
2944
- this.unbindEvents();
2945
- }
2946
- };
2947
- Resizable.prototype.createSizeForCssProperty = function (newSize, kind) {
2948
- var propsSize = this.propsSize && this.propsSize[kind];
2949
- return this.state[kind] === 'auto' &&
2950
- this.state.original[kind] === newSize &&
2951
- (typeof propsSize === 'undefined' || propsSize === 'auto')
2952
- ? 'auto'
2953
- : newSize;
2954
- };
2955
- Resizable.prototype.calculateNewMaxFromBoundary = function (maxWidth, maxHeight) {
2956
- var boundsByDirection = this.props.boundsByDirection;
2957
- var direction = this.state.direction;
2958
- var widthByDirection = boundsByDirection && hasDirection('left', direction);
2959
- var heightByDirection = boundsByDirection && hasDirection('top', direction);
2960
- var boundWidth;
2961
- var boundHeight;
2962
- if (this.props.bounds === 'parent') {
2963
- var parent_1 = this.parentNode;
2964
- if (parent_1) {
2965
- boundWidth = widthByDirection
2966
- ? this.resizableRight - this.parentLeft
2967
- : parent_1.offsetWidth + (this.parentLeft - this.resizableLeft);
2968
- boundHeight = heightByDirection
2969
- ? this.resizableBottom - this.parentTop
2970
- : parent_1.offsetHeight + (this.parentTop - this.resizableTop);
2971
- }
2972
- }
2973
- else if (this.props.bounds === 'window') {
2974
- if (this.window) {
2975
- boundWidth = widthByDirection ? this.resizableRight : this.window.innerWidth - this.resizableLeft;
2976
- boundHeight = heightByDirection ? this.resizableBottom : this.window.innerHeight - this.resizableTop;
2977
- }
2978
- }
2979
- else if (this.props.bounds) {
2980
- boundWidth = widthByDirection
2981
- ? this.resizableRight - this.targetLeft
2982
- : this.props.bounds.offsetWidth + (this.targetLeft - this.resizableLeft);
2983
- boundHeight = heightByDirection
2984
- ? this.resizableBottom - this.targetTop
2985
- : this.props.bounds.offsetHeight + (this.targetTop - this.resizableTop);
2986
- }
2987
- if (boundWidth && Number.isFinite(boundWidth)) {
2988
- maxWidth = maxWidth && maxWidth < boundWidth ? maxWidth : boundWidth;
2989
- }
2990
- if (boundHeight && Number.isFinite(boundHeight)) {
2991
- maxHeight = maxHeight && maxHeight < boundHeight ? maxHeight : boundHeight;
2992
- }
2993
- return { maxWidth: maxWidth, maxHeight: maxHeight };
2994
- };
2995
- Resizable.prototype.calculateNewSizeFromDirection = function (clientX, clientY) {
2996
- var scale = this.props.scale || 1;
2997
- var _a = normalizeToPair(this.props.resizeRatio || 1), resizeRatioX = _a[0], resizeRatioY = _a[1];
2998
- var _b = this.state, direction = _b.direction, original = _b.original;
2999
- var _c = this.props, lockAspectRatio = _c.lockAspectRatio, lockAspectRatioExtraHeight = _c.lockAspectRatioExtraHeight, lockAspectRatioExtraWidth = _c.lockAspectRatioExtraWidth;
3000
- var newWidth = original.width;
3001
- var newHeight = original.height;
3002
- var extraHeight = lockAspectRatioExtraHeight || 0;
3003
- var extraWidth = lockAspectRatioExtraWidth || 0;
3004
- if (hasDirection('right', direction)) {
3005
- newWidth = original.width + ((clientX - original.x) * resizeRatioX) / scale;
3006
- if (lockAspectRatio) {
3007
- newHeight = (newWidth - extraWidth) / this.ratio + extraHeight;
3008
- }
3009
- }
3010
- if (hasDirection('left', direction)) {
3011
- newWidth = original.width - ((clientX - original.x) * resizeRatioX) / scale;
3012
- if (lockAspectRatio) {
3013
- newHeight = (newWidth - extraWidth) / this.ratio + extraHeight;
3014
- }
3015
- }
3016
- if (hasDirection('bottom', direction)) {
3017
- newHeight = original.height + ((clientY - original.y) * resizeRatioY) / scale;
3018
- if (lockAspectRatio) {
3019
- newWidth = (newHeight - extraHeight) * this.ratio + extraWidth;
3020
- }
3021
- }
3022
- if (hasDirection('top', direction)) {
3023
- newHeight = original.height - ((clientY - original.y) * resizeRatioY) / scale;
3024
- if (lockAspectRatio) {
3025
- newWidth = (newHeight - extraHeight) * this.ratio + extraWidth;
3026
- }
3027
- }
3028
- return { newWidth: newWidth, newHeight: newHeight };
3029
- };
3030
- Resizable.prototype.calculateNewSizeFromAspectRatio = function (newWidth, newHeight, max, min) {
3031
- var _a = this.props, lockAspectRatio = _a.lockAspectRatio, lockAspectRatioExtraHeight = _a.lockAspectRatioExtraHeight, lockAspectRatioExtraWidth = _a.lockAspectRatioExtraWidth;
3032
- var computedMinWidth = typeof min.width === 'undefined' ? 10 : min.width;
3033
- var computedMaxWidth = typeof max.width === 'undefined' || max.width < 0 ? newWidth : max.width;
3034
- var computedMinHeight = typeof min.height === 'undefined' ? 10 : min.height;
3035
- var computedMaxHeight = typeof max.height === 'undefined' || max.height < 0 ? newHeight : max.height;
3036
- var extraHeight = lockAspectRatioExtraHeight || 0;
3037
- var extraWidth = lockAspectRatioExtraWidth || 0;
3038
- if (lockAspectRatio) {
3039
- var extraMinWidth = (computedMinHeight - extraHeight) * this.ratio + extraWidth;
3040
- var extraMaxWidth = (computedMaxHeight - extraHeight) * this.ratio + extraWidth;
3041
- var extraMinHeight = (computedMinWidth - extraWidth) / this.ratio + extraHeight;
3042
- var extraMaxHeight = (computedMaxWidth - extraWidth) / this.ratio + extraHeight;
3043
- var lockedMinWidth = Math.max(computedMinWidth, extraMinWidth);
3044
- var lockedMaxWidth = Math.min(computedMaxWidth, extraMaxWidth);
3045
- var lockedMinHeight = Math.max(computedMinHeight, extraMinHeight);
3046
- var lockedMaxHeight = Math.min(computedMaxHeight, extraMaxHeight);
3047
- newWidth = clamp(newWidth, lockedMinWidth, lockedMaxWidth);
3048
- newHeight = clamp(newHeight, lockedMinHeight, lockedMaxHeight);
3049
- }
3050
- else {
3051
- newWidth = clamp(newWidth, computedMinWidth, computedMaxWidth);
3052
- newHeight = clamp(newHeight, computedMinHeight, computedMaxHeight);
3053
- }
3054
- return { newWidth: newWidth, newHeight: newHeight };
3055
- };
3056
- Resizable.prototype.setBoundingClientRect = function () {
3057
- var adjustedScale = 1 / (this.props.scale || 1);
3058
- // For parent boundary
3059
- if (this.props.bounds === 'parent') {
3060
- var parent_2 = this.parentNode;
3061
- if (parent_2) {
3062
- var parentRect = parent_2.getBoundingClientRect();
3063
- this.parentLeft = parentRect.left * adjustedScale;
3064
- this.parentTop = parentRect.top * adjustedScale;
3065
- }
3066
- }
3067
- // For target(html element) boundary
3068
- if (this.props.bounds && typeof this.props.bounds !== 'string') {
3069
- var targetRect = this.props.bounds.getBoundingClientRect();
3070
- this.targetLeft = targetRect.left * adjustedScale;
3071
- this.targetTop = targetRect.top * adjustedScale;
3072
- }
3073
- // For boundary
3074
- if (this.resizable) {
3075
- var _a = this.resizable.getBoundingClientRect(), left = _a.left, top_1 = _a.top, right = _a.right, bottom = _a.bottom;
3076
- this.resizableLeft = left * adjustedScale;
3077
- this.resizableRight = right * adjustedScale;
3078
- this.resizableTop = top_1 * adjustedScale;
3079
- this.resizableBottom = bottom * adjustedScale;
3080
- }
3081
- };
3082
- Resizable.prototype.onResizeStart = function (event, direction) {
3083
- if (!this.resizable || !this.window) {
3084
- return;
3085
- }
3086
- var clientX = 0;
3087
- var clientY = 0;
3088
- if (event.nativeEvent && isMouseEvent(event.nativeEvent)) {
3089
- clientX = event.nativeEvent.clientX;
3090
- clientY = event.nativeEvent.clientY;
3091
- }
3092
- else if (event.nativeEvent && isTouchEvent(event.nativeEvent)) {
3093
- clientX = event.nativeEvent.touches[0].clientX;
3094
- clientY = event.nativeEvent.touches[0].clientY;
3095
- }
3096
- if (this.props.onResizeStart) {
3097
- if (this.resizable) {
3098
- var startResize = this.props.onResizeStart(event, direction, this.resizable);
3099
- if (startResize === false) {
3100
- return;
3101
- }
3102
- }
3103
- }
3104
- // Fix #168
3105
- if (this.props.size) {
3106
- if (typeof this.props.size.height !== 'undefined' && this.props.size.height !== this.state.height) {
3107
- this.setState({ height: this.props.size.height });
3108
- }
3109
- if (typeof this.props.size.width !== 'undefined' && this.props.size.width !== this.state.width) {
3110
- this.setState({ width: this.props.size.width });
3111
- }
3112
- }
3113
- // For lockAspectRatio case
3114
- this.ratio =
3115
- typeof this.props.lockAspectRatio === 'number' ? this.props.lockAspectRatio : this.size.width / this.size.height;
3116
- var flexBasis;
3117
- var computedStyle = this.window.getComputedStyle(this.resizable);
3118
- if (computedStyle.flexBasis !== 'auto') {
3119
- var parent_3 = this.parentNode;
3120
- if (parent_3) {
3121
- var dir = this.window.getComputedStyle(parent_3).flexDirection;
3122
- this.flexDir = dir.startsWith('row') ? 'row' : 'column';
3123
- flexBasis = computedStyle.flexBasis;
3124
- }
3125
- }
3126
- // For boundary
3127
- this.setBoundingClientRect();
3128
- this.bindEvents();
3129
- var state = {
3130
- original: {
3131
- x: clientX,
3132
- y: clientY,
3133
- width: this.size.width,
3134
- height: this.size.height,
3135
- },
3136
- isResizing: true,
3137
- backgroundStyle: __assign$1(__assign$1({}, this.state.backgroundStyle), { cursor: this.window.getComputedStyle(event.target).cursor || 'auto' }),
3138
- direction: direction,
3139
- flexBasis: flexBasis,
3140
- };
3141
- this.setState(state);
3142
- };
3143
- Resizable.prototype.onMouseMove = function (event) {
3144
- var _this = this;
3145
- if (!this.state.isResizing || !this.resizable || !this.window) {
3146
- return;
3147
- }
3148
- if (this.window.TouchEvent && isTouchEvent(event)) {
3149
- try {
3150
- event.preventDefault();
3151
- event.stopPropagation();
3152
- }
3153
- catch (e) {
3154
- // Ignore on fail
3155
- }
3156
- }
3157
- var _a = this.props, maxWidth = _a.maxWidth, maxHeight = _a.maxHeight, minWidth = _a.minWidth, minHeight = _a.minHeight;
3158
- var clientX = isTouchEvent(event) ? event.touches[0].clientX : event.clientX;
3159
- var clientY = isTouchEvent(event) ? event.touches[0].clientY : event.clientY;
3160
- var _b = this.state, direction = _b.direction, original = _b.original, width = _b.width, height = _b.height;
3161
- var parentSize = this.getParentSize();
3162
- var max = calculateNewMax(parentSize, this.window.innerWidth, this.window.innerHeight, maxWidth, maxHeight, minWidth, minHeight);
3163
- maxWidth = max.maxWidth;
3164
- maxHeight = max.maxHeight;
3165
- minWidth = max.minWidth;
3166
- minHeight = max.minHeight;
3167
- // Calculate new size
3168
- var _c = this.calculateNewSizeFromDirection(clientX, clientY), newHeight = _c.newHeight, newWidth = _c.newWidth;
3169
- // Calculate max size from boundary settings
3170
- var boundaryMax = this.calculateNewMaxFromBoundary(maxWidth, maxHeight);
3171
- if (this.props.snap && this.props.snap.x) {
3172
- newWidth = findClosestSnap(newWidth, this.props.snap.x, this.props.snapGap);
3173
- }
3174
- if (this.props.snap && this.props.snap.y) {
3175
- newHeight = findClosestSnap(newHeight, this.props.snap.y, this.props.snapGap);
3176
- }
3177
- // Calculate new size from aspect ratio
3178
- var newSize = this.calculateNewSizeFromAspectRatio(newWidth, newHeight, { width: boundaryMax.maxWidth, height: boundaryMax.maxHeight }, { width: minWidth, height: minHeight });
3179
- newWidth = newSize.newWidth;
3180
- newHeight = newSize.newHeight;
3181
- if (this.props.grid) {
3182
- var newGridWidth = snap(newWidth, this.props.grid[0], this.props.gridGap ? this.props.gridGap[0] : 0);
3183
- var newGridHeight = snap(newHeight, this.props.grid[1], this.props.gridGap ? this.props.gridGap[1] : 0);
3184
- var gap = this.props.snapGap || 0;
3185
- var w = gap === 0 || Math.abs(newGridWidth - newWidth) <= gap ? newGridWidth : newWidth;
3186
- var h = gap === 0 || Math.abs(newGridHeight - newHeight) <= gap ? newGridHeight : newHeight;
3187
- newWidth = w;
3188
- newHeight = h;
3189
- }
3190
- var delta = {
3191
- width: newWidth - original.width,
3192
- height: newHeight - original.height,
3193
- };
3194
- this.delta = delta;
3195
- if (width && typeof width === 'string') {
3196
- if (width.endsWith('%')) {
3197
- var percent = (newWidth / parentSize.width) * 100;
3198
- newWidth = "".concat(percent, "%");
3199
- }
3200
- else if (width.endsWith('vw')) {
3201
- var vw = (newWidth / this.window.innerWidth) * 100;
3202
- newWidth = "".concat(vw, "vw");
3203
- }
3204
- else if (width.endsWith('vh')) {
3205
- var vh = (newWidth / this.window.innerHeight) * 100;
3206
- newWidth = "".concat(vh, "vh");
3207
- }
3208
- }
3209
- if (height && typeof height === 'string') {
3210
- if (height.endsWith('%')) {
3211
- var percent = (newHeight / parentSize.height) * 100;
3212
- newHeight = "".concat(percent, "%");
3213
- }
3214
- else if (height.endsWith('vw')) {
3215
- var vw = (newHeight / this.window.innerWidth) * 100;
3216
- newHeight = "".concat(vw, "vw");
3217
- }
3218
- else if (height.endsWith('vh')) {
3219
- var vh = (newHeight / this.window.innerHeight) * 100;
3220
- newHeight = "".concat(vh, "vh");
3221
- }
3222
- }
3223
- var newState = {
3224
- width: this.createSizeForCssProperty(newWidth, 'width'),
3225
- height: this.createSizeForCssProperty(newHeight, 'height'),
3226
- };
3227
- if (this.flexDir === 'row') {
3228
- newState.flexBasis = newState.width;
3229
- }
3230
- else if (this.flexDir === 'column') {
3231
- newState.flexBasis = newState.height;
3232
- }
3233
- var widthChanged = this.state.width !== newState.width;
3234
- var heightChanged = this.state.height !== newState.height;
3235
- var flexBaseChanged = this.state.flexBasis !== newState.flexBasis;
3236
- var changed = widthChanged || heightChanged || flexBaseChanged;
3237
- if (changed) {
3238
- // For v18, update state sync
3239
- flushSync(function () {
3240
- _this.setState(newState);
3241
- });
3242
- }
3243
- if (this.props.onResize) {
3244
- if (changed) {
3245
- this.props.onResize(event, direction, this.resizable, delta);
3246
- }
3247
- }
3248
- };
3249
- Resizable.prototype.onMouseUp = function (event) {
3250
- var _a, _b;
3251
- var _c = this.state, isResizing = _c.isResizing, direction = _c.direction; _c.original;
3252
- if (!isResizing || !this.resizable) {
3253
- return;
3254
- }
3255
- if (this.props.onResizeStop) {
3256
- this.props.onResizeStop(event, direction, this.resizable, this.delta);
3257
- }
3258
- if (this.props.size) {
3259
- this.setState({ width: (_a = this.props.size.width) !== null && _a !== void 0 ? _a : 'auto', height: (_b = this.props.size.height) !== null && _b !== void 0 ? _b : 'auto' });
3260
- }
3261
- this.unbindEvents();
3262
- this.setState({
3263
- isResizing: false,
3264
- backgroundStyle: __assign$1(__assign$1({}, this.state.backgroundStyle), { cursor: 'auto' }),
3265
- });
3266
- };
3267
- Resizable.prototype.updateSize = function (size) {
3268
- var _a, _b;
3269
- this.setState({ width: (_a = size.width) !== null && _a !== void 0 ? _a : 'auto', height: (_b = size.height) !== null && _b !== void 0 ? _b : 'auto' });
3270
- };
3271
- Resizable.prototype.renderResizer = function () {
3272
- var _this = this;
3273
- var _a = this.props, enable = _a.enable, handleStyles = _a.handleStyles, handleClasses = _a.handleClasses, handleWrapperStyle = _a.handleWrapperStyle, handleWrapperClass = _a.handleWrapperClass, handleComponent = _a.handleComponent;
3274
- if (!enable) {
3275
- return null;
3276
- }
3277
- var resizers = Object.keys(enable).map(function (dir) {
3278
- if (enable[dir] !== false) {
3279
- return (jsx(Resizer, { direction: dir, onResizeStart: _this.onResizeStart, replaceStyles: handleStyles && handleStyles[dir], className: handleClasses && handleClasses[dir], children: handleComponent && handleComponent[dir] ? handleComponent[dir] : null }, dir));
3280
- }
3281
- return null;
3282
- });
3283
- // #93 Wrap the resize box in span (will not break 100% width/height)
3284
- return (jsx("div", { className: handleWrapperClass, style: handleWrapperStyle, children: resizers }));
3285
- };
3286
- Resizable.prototype.render = function () {
3287
- var _this = this;
3288
- var extendsProps = Object.keys(this.props).reduce(function (acc, key) {
3289
- if (definedProps.indexOf(key) !== -1) {
3290
- return acc;
3291
- }
3292
- acc[key] = _this.props[key];
3293
- return acc;
3294
- }, {});
3295
- var style = __assign$1(__assign$1(__assign$1({ position: 'relative', userSelect: this.state.isResizing ? 'none' : 'auto' }, this.props.style), this.sizeStyle), { maxWidth: this.props.maxWidth, maxHeight: this.props.maxHeight, minWidth: this.props.minWidth, minHeight: this.props.minHeight, boxSizing: 'border-box', flexShrink: 0 });
3296
- if (this.state.flexBasis) {
3297
- style.flexBasis = this.state.flexBasis;
3298
- }
3299
- var Wrapper = this.props.as || 'div';
3300
- return (jsxs(Wrapper, __assign$1({ style: style, className: this.props.className }, extendsProps, {
3301
- // `ref` is after `extendsProps` to ensure this one wins over a version
3302
- // passed in
3303
- ref: function (c) {
3304
- if (c) {
3305
- _this.resizable = c;
3306
- }
3307
- }, children: [this.state.isResizing && jsx("div", { style: this.state.backgroundStyle }), this.props.children, this.renderResizer()] })));
3308
- };
3309
- Resizable.defaultProps = {
3310
- as: 'div',
3311
- onResizeStart: function () { },
3312
- onResize: function () { },
3313
- onResizeStop: function () { },
3314
- enable: {
3315
- top: true,
3316
- right: true,
3317
- bottom: true,
3318
- left: true,
3319
- topRight: true,
3320
- bottomRight: true,
3321
- bottomLeft: true,
3322
- topLeft: true,
3323
- },
3324
- style: {},
3325
- grid: [1, 1],
3326
- gridGap: [0, 0],
3327
- lockAspectRatio: false,
3328
- lockAspectRatioExtraWidth: 0,
3329
- lockAspectRatioExtraHeight: 0,
3330
- scale: 1,
3331
- resizeRatio: 1,
3332
- snapGap: 0,
3333
- };
3334
- return Resizable;
3335
- }(PureComponent));
3336
-
3337
- /*! *****************************************************************************
3338
- Copyright (c) Microsoft Corporation. All rights reserved.
3339
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
3340
- this file except in compliance with the License. You may obtain a copy of the
3341
- License at http://www.apache.org/licenses/LICENSE-2.0
3342
-
3343
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
3344
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
3345
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
3346
- MERCHANTABLITY OR NON-INFRINGEMENT.
3347
-
3348
- See the Apache Version 2.0 License for specific language governing permissions
3349
- and limitations under the License.
3350
- ***************************************************************************** */
3351
- /* global Reflect, Promise */
3352
-
3353
- var extendStatics = function(d, b) {
3354
- extendStatics = Object.setPrototypeOf ||
3355
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
3356
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
3357
- return extendStatics(d, b);
3358
- };
3359
-
3360
- function __extends(d, b) {
3361
- extendStatics(d, b);
3362
- function __() { this.constructor = d; }
3363
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
3364
- }
3365
-
3366
- var __assign = function() {
3367
- __assign = Object.assign || function __assign(t) {
3368
- for (var s, i = 1, n = arguments.length; i < n; i++) {
3369
- s = arguments[i];
3370
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
3371
- }
3372
- return t;
3373
- };
3374
- return __assign.apply(this, arguments);
3375
- };
3376
-
3377
- function __rest(s, e) {
3378
- var t = {};
3379
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3380
- t[p] = s[p];
3381
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
3382
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3383
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3384
- t[p[i]] = s[p[i]];
3385
- }
3386
- return t;
3387
- }
3388
-
3389
- var resizableStyle = {
3390
- width: "auto",
3391
- height: "auto",
3392
- display: "inline-block",
3393
- position: "absolute",
3394
- top: 0,
3395
- left: 0,
3396
- };
3397
- var getEnableResizingByFlag = function (flag) { return ({
3398
- bottom: flag,
3399
- bottomLeft: flag,
3400
- bottomRight: flag,
3401
- left: flag,
3402
- right: flag,
3403
- top: flag,
3404
- topLeft: flag,
3405
- topRight: flag,
3406
- }); };
3407
- var Rnd = /** @class */ (function (_super) {
3408
- __extends(Rnd, _super);
3409
- function Rnd(props) {
3410
- var _this = _super.call(this, props) || this;
3411
- _this.resizingPosition = { x: 0, y: 0 };
3412
- _this.offsetFromParent = { left: 0, top: 0 };
3413
- _this.resizableElement = { current: null };
3414
- _this.originalPosition = { x: 0, y: 0 };
3415
- _this.state = {
3416
- resizing: false,
3417
- bounds: {
3418
- top: 0,
3419
- right: 0,
3420
- bottom: 0,
3421
- left: 0,
3422
- },
3423
- maxWidth: props.maxWidth,
3424
- maxHeight: props.maxHeight,
3425
- };
3426
- _this.onResizeStart = _this.onResizeStart.bind(_this);
3427
- _this.onResize = _this.onResize.bind(_this);
3428
- _this.onResizeStop = _this.onResizeStop.bind(_this);
3429
- _this.onDragStart = _this.onDragStart.bind(_this);
3430
- _this.onDrag = _this.onDrag.bind(_this);
3431
- _this.onDragStop = _this.onDragStop.bind(_this);
3432
- _this.getMaxSizesFromProps = _this.getMaxSizesFromProps.bind(_this);
3433
- return _this;
3434
- }
3435
- Rnd.prototype.componentDidMount = function () {
3436
- this.updateOffsetFromParent();
3437
- var _a = this.offsetFromParent, left = _a.left, top = _a.top;
3438
- var _b = this.getDraggablePosition(), x = _b.x, y = _b.y;
3439
- this.draggable.setState({
3440
- x: x - left,
3441
- y: y - top,
3442
- });
3443
- // HACK: Apply position adjustment
3444
- this.forceUpdate();
3445
- };
3446
- // HACK: To get `react-draggable` state x and y.
3447
- Rnd.prototype.getDraggablePosition = function () {
3448
- var _a = this.draggable.state, x = _a.x, y = _a.y;
3449
- return { x: x, y: y };
3450
- };
3451
- Rnd.prototype.getParent = function () {
3452
- return this.resizable && this.resizable.parentNode;
3453
- };
3454
- Rnd.prototype.getParentSize = function () {
3455
- return this.resizable.getParentSize();
3456
- };
3457
- Rnd.prototype.getMaxSizesFromProps = function () {
3458
- var maxWidth = typeof this.props.maxWidth === "undefined" ? Number.MAX_SAFE_INTEGER : this.props.maxWidth;
3459
- var maxHeight = typeof this.props.maxHeight === "undefined" ? Number.MAX_SAFE_INTEGER : this.props.maxHeight;
3460
- return { maxWidth: maxWidth, maxHeight: maxHeight };
3461
- };
3462
- Rnd.prototype.getSelfElement = function () {
3463
- return this.resizable && this.resizable.resizable;
3464
- };
3465
- Rnd.prototype.getOffsetHeight = function (boundary) {
3466
- var scale = this.props.scale;
3467
- switch (this.props.bounds) {
3468
- case "window":
3469
- return window.innerHeight / scale;
3470
- case "body":
3471
- return document.body.offsetHeight / scale;
3472
- default:
3473
- return boundary.offsetHeight;
3474
- }
3475
- };
3476
- Rnd.prototype.getOffsetWidth = function (boundary) {
3477
- var scale = this.props.scale;
3478
- switch (this.props.bounds) {
3479
- case "window":
3480
- return window.innerWidth / scale;
3481
- case "body":
3482
- return document.body.offsetWidth / scale;
3483
- default:
3484
- return boundary.offsetWidth;
3485
- }
3486
- };
3487
- Rnd.prototype.onDragStart = function (e, data) {
3488
- if (this.props.onDragStart) {
3489
- this.props.onDragStart(e, data);
3490
- }
3491
- var pos = this.getDraggablePosition();
3492
- this.originalPosition = pos;
3493
- if (!this.props.bounds)
3494
- return;
3495
- var parent = this.getParent();
3496
- var scale = this.props.scale;
3497
- var boundary;
3498
- if (this.props.bounds === "parent") {
3499
- boundary = parent;
3500
- }
3501
- else if (this.props.bounds === "body") {
3502
- var parentRect_1 = parent.getBoundingClientRect();
3503
- var parentLeft_1 = parentRect_1.left;
3504
- var parentTop_1 = parentRect_1.top;
3505
- var bodyRect = document.body.getBoundingClientRect();
3506
- var left_1 = -(parentLeft_1 - parent.offsetLeft * scale - bodyRect.left) / scale;
3507
- var top_1 = -(parentTop_1 - parent.offsetTop * scale - bodyRect.top) / scale;
3508
- var right = (document.body.offsetWidth - this.resizable.size.width * scale) / scale + left_1;
3509
- var bottom = (document.body.offsetHeight - this.resizable.size.height * scale) / scale + top_1;
3510
- return this.setState({ bounds: { top: top_1, right: right, bottom: bottom, left: left_1 } });
3511
- }
3512
- else if (this.props.bounds === "window") {
3513
- if (!this.resizable)
3514
- return;
3515
- var parentRect_2 = parent.getBoundingClientRect();
3516
- var parentLeft_2 = parentRect_2.left;
3517
- var parentTop_2 = parentRect_2.top;
3518
- var left_2 = -(parentLeft_2 - parent.offsetLeft * scale) / scale;
3519
- var top_2 = -(parentTop_2 - parent.offsetTop * scale) / scale;
3520
- var right = (window.innerWidth - this.resizable.size.width * scale) / scale + left_2;
3521
- var bottom = (window.innerHeight - this.resizable.size.height * scale) / scale + top_2;
3522
- return this.setState({ bounds: { top: top_2, right: right, bottom: bottom, left: left_2 } });
3523
- }
3524
- else if (typeof this.props.bounds === "string") {
3525
- boundary = document.querySelector(this.props.bounds);
3526
- }
3527
- else if (this.props.bounds instanceof HTMLElement) {
3528
- boundary = this.props.bounds;
3529
- }
3530
- if (!(boundary instanceof HTMLElement) || !(parent instanceof HTMLElement)) {
3531
- return;
3532
- }
3533
- var boundaryRect = boundary.getBoundingClientRect();
3534
- var boundaryLeft = boundaryRect.left;
3535
- var boundaryTop = boundaryRect.top;
3536
- var parentRect = parent.getBoundingClientRect();
3537
- var parentLeft = parentRect.left;
3538
- var parentTop = parentRect.top;
3539
- var left = (boundaryLeft - parentLeft) / scale;
3540
- var top = boundaryTop - parentTop;
3541
- if (!this.resizable)
3542
- return;
3543
- this.updateOffsetFromParent();
3544
- var offset = this.offsetFromParent;
3545
- this.setState({
3546
- bounds: {
3547
- top: top - offset.top,
3548
- right: left + (boundary.offsetWidth - this.resizable.size.width) - offset.left / scale,
3549
- bottom: top + (boundary.offsetHeight - this.resizable.size.height) - offset.top,
3550
- left: left - offset.left / scale,
3551
- },
3552
- });
3553
- };
3554
- Rnd.prototype.onDrag = function (e, data) {
3555
- if (!this.props.onDrag)
3556
- return;
3557
- var _a = this.offsetFromParent, left = _a.left, top = _a.top;
3558
- if (!this.props.dragAxis || this.props.dragAxis === "both") {
3559
- return this.props.onDrag(e, __assign(__assign({}, data), { x: data.x + left, y: data.y + top }));
3560
- }
3561
- else if (this.props.dragAxis === "x") {
3562
- return this.props.onDrag(e, __assign(__assign({}, data), { x: data.x + left, y: this.originalPosition.y + top, deltaY: 0 }));
3563
- }
3564
- else if (this.props.dragAxis === "y") {
3565
- return this.props.onDrag(e, __assign(__assign({}, data), { x: this.originalPosition.x + left, y: data.y + top, deltaX: 0 }));
3566
- }
3567
- };
3568
- Rnd.prototype.onDragStop = function (e, data) {
3569
- if (!this.props.onDragStop)
3570
- return;
3571
- var _a = this.offsetFromParent, left = _a.left, top = _a.top;
3572
- if (!this.props.dragAxis || this.props.dragAxis === "both") {
3573
- return this.props.onDragStop(e, __assign(__assign({}, data), { x: data.x + left, y: data.y + top }));
3574
- }
3575
- else if (this.props.dragAxis === "x") {
3576
- return this.props.onDragStop(e, __assign(__assign({}, data), { x: data.x + left, y: this.originalPosition.y + top, deltaY: 0 }));
3577
- }
3578
- else if (this.props.dragAxis === "y") {
3579
- return this.props.onDragStop(e, __assign(__assign({}, data), { x: this.originalPosition.x + left, y: data.y + top, deltaX: 0 }));
3580
- }
3581
- };
3582
- Rnd.prototype.onResizeStart = function (e, dir, elementRef) {
3583
- e.stopPropagation();
3584
- this.setState({
3585
- resizing: true,
3586
- });
3587
- var scale = this.props.scale;
3588
- var offset = this.offsetFromParent;
3589
- var pos = this.getDraggablePosition();
3590
- this.resizingPosition = { x: pos.x + offset.left, y: pos.y + offset.top };
3591
- this.originalPosition = pos;
3592
- if (this.props.bounds) {
3593
- var parent_1 = this.getParent();
3594
- var boundary = void 0;
3595
- if (this.props.bounds === "parent") {
3596
- boundary = parent_1;
3597
- }
3598
- else if (this.props.bounds === "body") {
3599
- boundary = document.body;
3600
- }
3601
- else if (this.props.bounds === "window") {
3602
- boundary = window;
3603
- }
3604
- else if (typeof this.props.bounds === "string") {
3605
- boundary = document.querySelector(this.props.bounds);
3606
- }
3607
- else if (this.props.bounds instanceof HTMLElement) {
3608
- boundary = this.props.bounds;
3609
- }
3610
- var self_1 = this.getSelfElement();
3611
- if (self_1 instanceof Element &&
3612
- (boundary instanceof HTMLElement || boundary === window) &&
3613
- parent_1 instanceof HTMLElement) {
3614
- var _a = this.getMaxSizesFromProps(), maxWidth = _a.maxWidth, maxHeight = _a.maxHeight;
3615
- var parentSize = this.getParentSize();
3616
- if (maxWidth && typeof maxWidth === "string") {
3617
- if (maxWidth.endsWith("%")) {
3618
- var ratio = Number(maxWidth.replace("%", "")) / 100;
3619
- maxWidth = parentSize.width * ratio;
3620
- }
3621
- else if (maxWidth.endsWith("px")) {
3622
- maxWidth = Number(maxWidth.replace("px", ""));
3623
- }
3624
- }
3625
- if (maxHeight && typeof maxHeight === "string") {
3626
- if (maxHeight.endsWith("%")) {
3627
- var ratio = Number(maxHeight.replace("%", "")) / 100;
3628
- maxHeight = parentSize.height * ratio;
3629
- }
3630
- else if (maxHeight.endsWith("px")) {
3631
- maxHeight = Number(maxHeight.replace("px", ""));
3632
- }
3633
- }
3634
- var selfRect = self_1.getBoundingClientRect();
3635
- var selfLeft = selfRect.left;
3636
- var selfTop = selfRect.top;
3637
- var boundaryRect = this.props.bounds === "window" ? { left: 0, top: 0 } : boundary.getBoundingClientRect();
3638
- var boundaryLeft = boundaryRect.left;
3639
- var boundaryTop = boundaryRect.top;
3640
- var offsetWidth = this.getOffsetWidth(boundary);
3641
- var offsetHeight = this.getOffsetHeight(boundary);
3642
- var hasLeft = dir.toLowerCase().endsWith("left");
3643
- var hasRight = dir.toLowerCase().endsWith("right");
3644
- var hasTop = dir.startsWith("top");
3645
- var hasBottom = dir.startsWith("bottom");
3646
- if ((hasLeft || hasTop) && this.resizable) {
3647
- var max = (selfLeft - boundaryLeft) / scale + this.resizable.size.width;
3648
- this.setState({ maxWidth: max > Number(maxWidth) ? maxWidth : max });
3649
- }
3650
- // INFO: To set bounds in `lock aspect ratio with bounds` case. See also that story.
3651
- if (hasRight || (this.props.lockAspectRatio && !hasLeft && !hasTop)) {
3652
- var max = offsetWidth + (boundaryLeft - selfLeft) / scale;
3653
- this.setState({ maxWidth: max > Number(maxWidth) ? maxWidth : max });
3654
- }
3655
- if ((hasTop || hasLeft) && this.resizable) {
3656
- var max = (selfTop - boundaryTop) / scale + this.resizable.size.height;
3657
- this.setState({
3658
- maxHeight: max > Number(maxHeight) ? maxHeight : max,
3659
- });
3660
- }
3661
- // INFO: To set bounds in `lock aspect ratio with bounds` case. See also that story.
3662
- if (hasBottom || (this.props.lockAspectRatio && !hasTop && !hasLeft)) {
3663
- var max = offsetHeight + (boundaryTop - selfTop) / scale;
3664
- this.setState({
3665
- maxHeight: max > Number(maxHeight) ? maxHeight : max,
3666
- });
3667
- }
3668
- }
3669
- }
3670
- else {
3671
- this.setState({
3672
- maxWidth: this.props.maxWidth,
3673
- maxHeight: this.props.maxHeight,
3674
- });
3675
- }
3676
- if (this.props.onResizeStart) {
3677
- this.props.onResizeStart(e, dir, elementRef);
3678
- }
3679
- };
3680
- Rnd.prototype.onResize = function (e, direction, elementRef, delta) {
3681
- var _this = this;
3682
- // INFO: Apply x and y position adjustments caused by resizing to draggable
3683
- var newPos = { x: this.originalPosition.x, y: this.originalPosition.y };
3684
- var left = -delta.width;
3685
- var top = -delta.height;
3686
- var directions = ["top", "left", "topLeft", "bottomLeft", "topRight"];
3687
- if (directions.includes(direction)) {
3688
- if (direction === "bottomLeft") {
3689
- newPos.x += left;
3690
- }
3691
- else if (direction === "topRight") {
3692
- newPos.y += top;
3693
- }
3694
- else {
3695
- newPos.x += left;
3696
- newPos.y += top;
3697
- }
3698
- }
3699
- var draggableState = this.draggable.state;
3700
- if (newPos.x !== draggableState.x || newPos.y !== draggableState.y) {
3701
- flushSync(function () {
3702
- _this.draggable.setState(newPos);
3703
- });
3704
- }
3705
- this.updateOffsetFromParent();
3706
- var offset = this.offsetFromParent;
3707
- var x = this.getDraggablePosition().x + offset.left;
3708
- var y = this.getDraggablePosition().y + offset.top;
3709
- this.resizingPosition = { x: x, y: y };
3710
- if (!this.props.onResize)
3711
- return;
3712
- this.props.onResize(e, direction, elementRef, delta, {
3713
- x: x,
3714
- y: y,
3715
- });
3716
- };
3717
- Rnd.prototype.onResizeStop = function (e, direction, elementRef, delta) {
3718
- this.setState({
3719
- resizing: false,
3720
- });
3721
- var _a = this.getMaxSizesFromProps(), maxWidth = _a.maxWidth, maxHeight = _a.maxHeight;
3722
- this.setState({ maxWidth: maxWidth, maxHeight: maxHeight });
3723
- if (this.props.onResizeStop) {
3724
- this.props.onResizeStop(e, direction, elementRef, delta, this.resizingPosition);
3725
- }
3726
- };
3727
- Rnd.prototype.updateSize = function (size) {
3728
- if (!this.resizable)
3729
- return;
3730
- this.resizable.updateSize({ width: size.width, height: size.height });
3731
- };
3732
- Rnd.prototype.updatePosition = function (position) {
3733
- this.draggable.setState(position);
3734
- };
3735
- Rnd.prototype.updateOffsetFromParent = function () {
3736
- var scale = this.props.scale;
3737
- var parent = this.getParent();
3738
- var self = this.getSelfElement();
3739
- if (!parent || self === null) {
3740
- return {
3741
- top: 0,
3742
- left: 0,
3743
- };
3744
- }
3745
- var parentRect = parent.getBoundingClientRect();
3746
- var parentLeft = parentRect.left;
3747
- var parentTop = parentRect.top;
3748
- var selfRect = self.getBoundingClientRect();
3749
- var position = this.getDraggablePosition();
3750
- var scrollLeft = parent.scrollLeft;
3751
- var scrollTop = parent.scrollTop;
3752
- this.offsetFromParent = {
3753
- left: selfRect.left - parentLeft + scrollLeft - position.x * scale,
3754
- top: selfRect.top - parentTop + scrollTop - position.y * scale,
3755
- };
3756
- };
3757
- Rnd.prototype.render = function () {
3758
- var _this = this;
3759
- var _a = this.props, disableDragging = _a.disableDragging, style = _a.style, dragHandleClassName = _a.dragHandleClassName, position = _a.position, onMouseDown = _a.onMouseDown, onMouseUp = _a.onMouseUp, dragAxis = _a.dragAxis, dragGrid = _a.dragGrid, bounds = _a.bounds, enableUserSelectHack = _a.enableUserSelectHack, cancel = _a.cancel, children = _a.children; _a.onResizeStart; _a.onResize; _a.onResizeStop; _a.onDragStart; _a.onDrag; _a.onDragStop; var resizeHandleStyles = _a.resizeHandleStyles, resizeHandleClasses = _a.resizeHandleClasses, resizeHandleComponent = _a.resizeHandleComponent, enableResizing = _a.enableResizing, resizeGrid = _a.resizeGrid, resizeHandleWrapperClass = _a.resizeHandleWrapperClass, resizeHandleWrapperStyle = _a.resizeHandleWrapperStyle, scale = _a.scale, allowAnyClick = _a.allowAnyClick, dragPositionOffset = _a.dragPositionOffset, resizableProps = __rest(_a, ["disableDragging", "style", "dragHandleClassName", "position", "onMouseDown", "onMouseUp", "dragAxis", "dragGrid", "bounds", "enableUserSelectHack", "cancel", "children", "onResizeStart", "onResize", "onResizeStop", "onDragStart", "onDrag", "onDragStop", "resizeHandleStyles", "resizeHandleClasses", "resizeHandleComponent", "enableResizing", "resizeGrid", "resizeHandleWrapperClass", "resizeHandleWrapperStyle", "scale", "allowAnyClick", "dragPositionOffset"]);
3760
- var defaultValue = this.props.default ? __assign({}, this.props.default) : undefined;
3761
- // Remove unknown props, see also https://reactjs.org/warnings/unknown-prop.html
3762
- delete resizableProps.default;
3763
- var cursorStyle = disableDragging || dragHandleClassName ? { cursor: "auto" } : { cursor: "move" };
3764
- var innerStyle = __assign(__assign(__assign({}, resizableStyle), cursorStyle), style);
3765
- var _b = this.offsetFromParent, left = _b.left, top = _b.top;
3766
- var draggablePosition;
3767
- if (position) {
3768
- draggablePosition = {
3769
- x: position.x - left,
3770
- y: position.y - top,
3771
- };
3772
- }
3773
- // INFO: Make uncontorolled component when resizing to control position by setPostion.
3774
- var pos = this.state.resizing ? undefined : draggablePosition;
3775
- var dragAxisOrUndefined = this.state.resizing ? "both" : dragAxis;
3776
- return (createElement(cjsExports, { ref: function (c) {
3777
- if (!c)
3778
- return;
3779
- _this.draggable = c;
3780
- }, handle: dragHandleClassName ? ".".concat(dragHandleClassName) : undefined, defaultPosition: defaultValue, onMouseDown: onMouseDown,
3781
- // @ts-expect-error
3782
- onMouseUp: onMouseUp, onStart: this.onDragStart, onDrag: this.onDrag, onStop: this.onDragStop, axis: dragAxisOrUndefined, disabled: disableDragging, grid: dragGrid, bounds: bounds ? this.state.bounds : undefined, position: pos, enableUserSelectHack: enableUserSelectHack, cancel: cancel, scale: scale, allowAnyClick: allowAnyClick, nodeRef: this.resizableElement, positionOffset: dragPositionOffset },
3783
- createElement(Resizable, __assign({}, resizableProps, { ref: function (c) {
3784
- if (!c)
3785
- return;
3786
- _this.resizable = c;
3787
- _this.resizableElement.current = c.resizable;
3788
- }, defaultSize: defaultValue, size: this.props.size, enable: typeof enableResizing === "boolean" ? getEnableResizingByFlag(enableResizing) : enableResizing, onResizeStart: this.onResizeStart, onResize: this.onResize, onResizeStop: this.onResizeStop, style: innerStyle, minWidth: this.props.minWidth, minHeight: this.props.minHeight, maxWidth: this.state.resizing ? this.state.maxWidth : this.props.maxWidth, maxHeight: this.state.resizing ? this.state.maxHeight : this.props.maxHeight, grid: resizeGrid, handleWrapperClass: resizeHandleWrapperClass, handleWrapperStyle: resizeHandleWrapperStyle, lockAspectRatio: this.props.lockAspectRatio, lockAspectRatioExtraWidth: this.props.lockAspectRatioExtraWidth, lockAspectRatioExtraHeight: this.props.lockAspectRatioExtraHeight, handleStyles: resizeHandleStyles, handleClasses: resizeHandleClasses, handleComponent: resizeHandleComponent, scale: this.props.scale }), children)));
3789
- };
3790
- Rnd.defaultProps = {
3791
- maxWidth: Number.MAX_SAFE_INTEGER,
3792
- maxHeight: Number.MAX_SAFE_INTEGER,
3793
- scale: 1,
3794
- onResizeStart: function () { },
3795
- onResize: function () { },
3796
- onResizeStop: function () { },
3797
- onDragStart: function () { },
3798
- onDrag: function () { },
3799
- onDragStop: function () { },
3800
- };
3801
- return Rnd;
3802
- }(PureComponent));
3803
-
3804
- export { AlignLeft as A, Link as L, Rnd as R, AlignCenter as a, AlignRight as b };
3805
- //# sourceMappingURL=index-41c4abc4.js.map