@hi-ui/layout 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +11 -0
  2. package/lib/cjs/Content.js +48 -0
  3. package/lib/cjs/Layout.js +48 -0
  4. package/lib/cjs/SearchTrigger.js +55 -0
  5. package/lib/cjs/Sider.js +100 -0
  6. package/lib/cjs/_virtual/Draggable.js +16 -0
  7. package/lib/cjs/_virtual/DraggableCore.js +16 -0
  8. package/lib/cjs/_virtual/Resizable.js +16 -0
  9. package/lib/cjs/_virtual/ResizableBox.js +16 -0
  10. package/lib/cjs/_virtual/cjs.js +18 -0
  11. package/lib/cjs/_virtual/domFns.js +16 -0
  12. package/lib/cjs/_virtual/getPrefix.js +16 -0
  13. package/lib/cjs/_virtual/index.js +18 -0
  14. package/lib/cjs/_virtual/index2.js +18 -0
  15. package/lib/cjs/_virtual/index3.js +18 -0
  16. package/lib/cjs/_virtual/index4.js +18 -0
  17. package/lib/cjs/_virtual/log.js +16 -0
  18. package/lib/cjs/_virtual/positionFns.js +16 -0
  19. package/lib/cjs/_virtual/propTypes.js +16 -0
  20. package/lib/cjs/_virtual/react-is.development.js +16 -0
  21. package/lib/cjs/_virtual/react-is.production.min.js +16 -0
  22. package/lib/cjs/_virtual/shims.js +16 -0
  23. package/lib/cjs/_virtual/utils.js +16 -0
  24. package/lib/cjs/index.js +24 -0
  25. package/lib/cjs/node_modules/classnames/index.js +62 -0
  26. package/lib/cjs/node_modules/object-assign/index.js +94 -0
  27. package/lib/cjs/node_modules/prop-types/checkPropTypes.js +101 -0
  28. package/lib/cjs/node_modules/prop-types/factoryWithThrowingShims.js +68 -0
  29. package/lib/cjs/node_modules/prop-types/factoryWithTypeCheckers.js +553 -0
  30. package/lib/cjs/node_modules/prop-types/index.js +36 -0
  31. package/lib/cjs/node_modules/prop-types/lib/ReactPropTypesSecret.js +25 -0
  32. package/lib/cjs/node_modules/react-draggable/build/cjs/Draggable.js +655 -0
  33. package/lib/cjs/node_modules/react-draggable/build/cjs/DraggableCore.js +670 -0
  34. package/lib/cjs/node_modules/react-draggable/build/cjs/cjs.js +23 -0
  35. package/lib/cjs/node_modules/react-draggable/build/cjs/utils/domFns.js +366 -0
  36. package/lib/cjs/node_modules/react-draggable/build/cjs/utils/getPrefix.js +69 -0
  37. package/lib/cjs/node_modules/react-draggable/build/cjs/utils/log.js +19 -0
  38. package/lib/cjs/node_modules/react-draggable/build/cjs/utils/positionFns.js +176 -0
  39. package/lib/cjs/node_modules/react-draggable/build/cjs/utils/shims.js +57 -0
  40. package/lib/cjs/node_modules/react-is/cjs/react-is.development.js +182 -0
  41. package/lib/cjs/node_modules/react-is/cjs/react-is.production.min.js +132 -0
  42. package/lib/cjs/node_modules/react-is/index.js +21 -0
  43. package/lib/cjs/node_modules/react-resizable/build/Resizable.js +366 -0
  44. package/lib/cjs/node_modules/react-resizable/build/ResizableBox.js +244 -0
  45. package/lib/cjs/node_modules/react-resizable/build/propTypes.js +115 -0
  46. package/lib/cjs/node_modules/react-resizable/build/utils.js +86 -0
  47. package/lib/cjs/node_modules/react-resizable/index.js +25 -0
  48. package/lib/cjs/packages/icons/lib/esm/components/common/search-outlined.js +65 -0
  49. package/lib/cjs/packages/icons/lib/esm/styles/index.scss.js +35 -0
  50. package/lib/cjs/styles/index.scss.js +18 -0
  51. package/lib/esm/Content.js +36 -0
  52. package/lib/esm/Layout.js +36 -0
  53. package/lib/esm/SearchTrigger.js +43 -0
  54. package/lib/esm/Sider.js +88 -0
  55. package/lib/esm/_virtual/Draggable.js +11 -0
  56. package/lib/esm/_virtual/DraggableCore.js +11 -0
  57. package/lib/esm/_virtual/Resizable.js +11 -0
  58. package/lib/esm/_virtual/ResizableBox.js +11 -0
  59. package/lib/esm/_virtual/cjs.js +13 -0
  60. package/lib/esm/_virtual/domFns.js +11 -0
  61. package/lib/esm/_virtual/getPrefix.js +11 -0
  62. package/lib/esm/_virtual/index.js +13 -0
  63. package/lib/esm/_virtual/index2.js +13 -0
  64. package/lib/esm/_virtual/index3.js +13 -0
  65. package/lib/esm/_virtual/index4.js +13 -0
  66. package/lib/esm/_virtual/log.js +11 -0
  67. package/lib/esm/_virtual/positionFns.js +11 -0
  68. package/lib/esm/_virtual/propTypes.js +11 -0
  69. package/lib/esm/_virtual/react-is.development.js +11 -0
  70. package/lib/esm/_virtual/react-is.production.min.js +11 -0
  71. package/lib/esm/_virtual/shims.js +11 -0
  72. package/lib/esm/_virtual/utils.js +11 -0
  73. package/lib/esm/index.js +14 -0
  74. package/lib/esm/node_modules/classnames/index.js +60 -0
  75. package/lib/esm/node_modules/object-assign/index.js +88 -0
  76. package/lib/esm/node_modules/prop-types/checkPropTypes.js +96 -0
  77. package/lib/esm/node_modules/prop-types/factoryWithThrowingShims.js +63 -0
  78. package/lib/esm/node_modules/prop-types/factoryWithTypeCheckers.js +548 -0
  79. package/lib/esm/node_modules/prop-types/index.js +34 -0
  80. package/lib/esm/node_modules/prop-types/lib/ReactPropTypesSecret.js +19 -0
  81. package/lib/esm/node_modules/react-draggable/build/cjs/Draggable.js +645 -0
  82. package/lib/esm/node_modules/react-draggable/build/cjs/DraggableCore.js +660 -0
  83. package/lib/esm/node_modules/react-draggable/build/cjs/cjs.js +21 -0
  84. package/lib/esm/node_modules/react-draggable/build/cjs/utils/domFns.js +361 -0
  85. package/lib/esm/node_modules/react-draggable/build/cjs/utils/getPrefix.js +67 -0
  86. package/lib/esm/node_modules/react-draggable/build/cjs/utils/log.js +17 -0
  87. package/lib/esm/node_modules/react-draggable/build/cjs/utils/positionFns.js +171 -0
  88. package/lib/esm/node_modules/react-draggable/build/cjs/utils/shims.js +52 -0
  89. package/lib/esm/node_modules/react-is/cjs/react-is.development.js +177 -0
  90. package/lib/esm/node_modules/react-is/cjs/react-is.production.min.js +127 -0
  91. package/lib/esm/node_modules/react-is/index.js +19 -0
  92. package/lib/esm/node_modules/react-resizable/build/Resizable.js +358 -0
  93. package/lib/esm/node_modules/react-resizable/build/ResizableBox.js +236 -0
  94. package/lib/esm/node_modules/react-resizable/build/propTypes.js +110 -0
  95. package/lib/esm/node_modules/react-resizable/build/utils.js +74 -0
  96. package/lib/esm/node_modules/react-resizable/index.js +20 -0
  97. package/lib/esm/packages/icons/lib/esm/components/common/search-outlined.js +53 -0
  98. package/lib/esm/packages/icons/lib/esm/styles/index.scss.js +23 -0
  99. package/lib/esm/styles/index.scss.js +13 -0
  100. package/lib/types/Content.d.ts +8 -0
  101. package/lib/types/Layout.d.ts +8 -0
  102. package/lib/types/SearchTrigger.d.ts +10 -0
  103. package/lib/types/Sider.d.ts +10 -0
  104. package/lib/types/index.d.ts +6 -0
  105. package/package.json +61 -0
@@ -0,0 +1,655 @@
1
+ /** @LICENSE
2
+ * @hi-ui/layout
3
+ * https://github.com/XiaoMi/hiui/tree/master/packages/ui/layout#readme
4
+ *
5
+ * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ 'use strict';
11
+
12
+ var _typeof2 = require("@babel/runtime/helpers/typeof");
13
+ var Draggable = require('../../../../_virtual/Draggable.js');
14
+ var React = require('react');
15
+ require('../../../prop-types/index.js');
16
+ var require$$2 = require('react-dom');
17
+ require('../../../classnames/index.js');
18
+ require('./utils/domFns.js');
19
+ require('./utils/positionFns.js');
20
+ require('./utils/shims.js');
21
+ require('./DraggableCore.js');
22
+ require('./utils/log.js');
23
+ var index = require('../../../../_virtual/index2.js');
24
+ var shims = require('../../../../_virtual/shims.js');
25
+ var DraggableCore = require('../../../../_virtual/DraggableCore.js');
26
+ var index$1 = require('../../../../_virtual/index4.js');
27
+ var domFns = require('../../../../_virtual/domFns.js');
28
+ var positionFns = require('../../../../_virtual/positionFns.js');
29
+ var log = require('../../../../_virtual/log.js');
30
+ function _interopDefaultCompat(e) {
31
+ return e && _typeof2(e) === 'object' && 'default' in e ? e : {
32
+ 'default': e
33
+ };
34
+ }
35
+ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
36
+ var require$$2__default = /*#__PURE__*/_interopDefaultCompat(require$$2);
37
+ (function (exports) {
38
+ Object.defineProperty(exports, "__esModule", {
39
+ value: true
40
+ });
41
+ Object.defineProperty(exports, "DraggableCore", {
42
+ enumerable: true,
43
+ get: function get() {
44
+ return _DraggableCore["default"];
45
+ }
46
+ });
47
+ exports["default"] = void 0;
48
+ var React = _interopRequireWildcard(React__default["default"]);
49
+ var _propTypes = _interopRequireDefault(index.propTypes.exports);
50
+ var _reactDom = _interopRequireDefault(require$$2__default["default"]);
51
+ var _classnames = _interopRequireDefault(index$1.classnames.exports);
52
+ var _domFns = domFns.__exports;
53
+ var _positionFns = positionFns.__exports;
54
+ var _shims = shims.__exports;
55
+ var _DraggableCore = _interopRequireDefault(DraggableCore.__exports);
56
+ var _log = _interopRequireDefault(log.__exports);
57
+ function _interopRequireDefault(obj) {
58
+ return obj && obj.__esModule ? obj : {
59
+ "default": obj
60
+ };
61
+ }
62
+ function _getRequireWildcardCache() {
63
+ if (typeof WeakMap !== "function") return null;
64
+ var cache = new WeakMap();
65
+ _getRequireWildcardCache = function _getRequireWildcardCache() {
66
+ return cache;
67
+ };
68
+ return cache;
69
+ }
70
+ function _interopRequireWildcard(obj) {
71
+ if (obj && obj.__esModule) {
72
+ return obj;
73
+ }
74
+ if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
75
+ return {
76
+ "default": obj
77
+ };
78
+ }
79
+ var cache = _getRequireWildcardCache();
80
+ if (cache && cache.has(obj)) {
81
+ return cache.get(obj);
82
+ }
83
+ var newObj = {};
84
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
85
+ for (var key in obj) {
86
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
87
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
88
+ if (desc && (desc.get || desc.set)) {
89
+ Object.defineProperty(newObj, key, desc);
90
+ } else {
91
+ newObj[key] = obj[key];
92
+ }
93
+ }
94
+ }
95
+ newObj["default"] = obj;
96
+ if (cache) {
97
+ cache.set(obj, newObj);
98
+ }
99
+ return newObj;
100
+ }
101
+ function _typeof(obj) {
102
+ "@babel/helpers - typeof";
103
+
104
+ if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
105
+ _typeof = function _typeof(obj) {
106
+ return typeof obj;
107
+ };
108
+ } else {
109
+ _typeof = function _typeof(obj) {
110
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
111
+ };
112
+ }
113
+ return _typeof(obj);
114
+ }
115
+ function _extends() {
116
+ _extends = Object.assign || function (target) {
117
+ for (var i = 1; i < arguments.length; i++) {
118
+ var source = arguments[i];
119
+ for (var key in source) {
120
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
121
+ target[key] = source[key];
122
+ }
123
+ }
124
+ }
125
+ return target;
126
+ };
127
+ return _extends.apply(this, arguments);
128
+ }
129
+ function _objectWithoutProperties(source, excluded) {
130
+ if (source == null) return {};
131
+ var target = _objectWithoutPropertiesLoose(source, excluded);
132
+ var key, i;
133
+ if (Object.getOwnPropertySymbols) {
134
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
135
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
136
+ key = sourceSymbolKeys[i];
137
+ if (excluded.indexOf(key) >= 0) continue;
138
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
139
+ target[key] = source[key];
140
+ }
141
+ }
142
+ return target;
143
+ }
144
+ function _objectWithoutPropertiesLoose(source, excluded) {
145
+ if (source == null) return {};
146
+ var target = {};
147
+ var sourceKeys = Object.keys(source);
148
+ var key, i;
149
+ for (i = 0; i < sourceKeys.length; i++) {
150
+ key = sourceKeys[i];
151
+ if (excluded.indexOf(key) >= 0) continue;
152
+ target[key] = source[key];
153
+ }
154
+ return target;
155
+ }
156
+ function _slicedToArray(arr, i) {
157
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
158
+ }
159
+ function _nonIterableRest() {
160
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
161
+ }
162
+ function _unsupportedIterableToArray(o, minLen) {
163
+ if (!o) return;
164
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
165
+ var n = Object.prototype.toString.call(o).slice(8, -1);
166
+ if (n === "Object" && o.constructor) n = o.constructor.name;
167
+ if (n === "Map" || n === "Set") return Array.from(o);
168
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
169
+ }
170
+ function _arrayLikeToArray(arr, len) {
171
+ if (len == null || len > arr.length) len = arr.length;
172
+ for (var i = 0, arr2 = new Array(len); i < len; i++) {
173
+ arr2[i] = arr[i];
174
+ }
175
+ return arr2;
176
+ }
177
+ function _iterableToArrayLimit(arr, i) {
178
+ if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
179
+ var _arr = [];
180
+ var _n = true;
181
+ var _d = false;
182
+ var _e = undefined;
183
+ try {
184
+ for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
185
+ _arr.push(_s.value);
186
+ if (i && _arr.length === i) break;
187
+ }
188
+ } catch (err) {
189
+ _d = true;
190
+ _e = err;
191
+ } finally {
192
+ try {
193
+ if (!_n && _i["return"] != null) _i["return"]();
194
+ } finally {
195
+ if (_d) throw _e;
196
+ }
197
+ }
198
+ return _arr;
199
+ }
200
+ function _arrayWithHoles(arr) {
201
+ if (Array.isArray(arr)) return arr;
202
+ }
203
+ function ownKeys(object, enumerableOnly) {
204
+ var keys = Object.keys(object);
205
+ if (Object.getOwnPropertySymbols) {
206
+ var symbols = Object.getOwnPropertySymbols(object);
207
+ if (enumerableOnly) symbols = symbols.filter(function (sym) {
208
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
209
+ });
210
+ keys.push.apply(keys, symbols);
211
+ }
212
+ return keys;
213
+ }
214
+ function _objectSpread(target) {
215
+ for (var i = 1; i < arguments.length; i++) {
216
+ var source = arguments[i] != null ? arguments[i] : {};
217
+ if (i % 2) {
218
+ ownKeys(Object(source), true).forEach(function (key) {
219
+ _defineProperty(target, key, source[key]);
220
+ });
221
+ } else if (Object.getOwnPropertyDescriptors) {
222
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
223
+ } else {
224
+ ownKeys(Object(source)).forEach(function (key) {
225
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
226
+ });
227
+ }
228
+ }
229
+ return target;
230
+ }
231
+ function _classCallCheck(instance, Constructor) {
232
+ if (!(instance instanceof Constructor)) {
233
+ throw new TypeError("Cannot call a class as a function");
234
+ }
235
+ }
236
+ function _defineProperties(target, props) {
237
+ for (var i = 0; i < props.length; i++) {
238
+ var descriptor = props[i];
239
+ descriptor.enumerable = descriptor.enumerable || false;
240
+ descriptor.configurable = true;
241
+ if ("value" in descriptor) descriptor.writable = true;
242
+ Object.defineProperty(target, descriptor.key, descriptor);
243
+ }
244
+ }
245
+ function _createClass(Constructor, protoProps, staticProps) {
246
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
247
+ if (staticProps) _defineProperties(Constructor, staticProps);
248
+ return Constructor;
249
+ }
250
+ function _inherits(subClass, superClass) {
251
+ if (typeof superClass !== "function" && superClass !== null) {
252
+ throw new TypeError("Super expression must either be null or a function");
253
+ }
254
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
255
+ constructor: {
256
+ value: subClass,
257
+ writable: true,
258
+ configurable: true
259
+ }
260
+ });
261
+ if (superClass) _setPrototypeOf(subClass, superClass);
262
+ }
263
+ function _setPrototypeOf(o, p) {
264
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
265
+ o.__proto__ = p;
266
+ return o;
267
+ };
268
+ return _setPrototypeOf(o, p);
269
+ }
270
+ function _createSuper(Derived) {
271
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
272
+ return function () {
273
+ var Super = _getPrototypeOf(Derived),
274
+ result;
275
+ if (hasNativeReflectConstruct) {
276
+ var NewTarget = _getPrototypeOf(this).constructor;
277
+ result = Reflect.construct(Super, arguments, NewTarget);
278
+ } else {
279
+ result = Super.apply(this, arguments);
280
+ }
281
+ return _possibleConstructorReturn(this, result);
282
+ };
283
+ }
284
+ function _possibleConstructorReturn(self, call) {
285
+ if (call && (_typeof(call) === "object" || typeof call === "function")) {
286
+ return call;
287
+ }
288
+ return _assertThisInitialized(self);
289
+ }
290
+ function _assertThisInitialized(self) {
291
+ if (self === void 0) {
292
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
293
+ }
294
+ return self;
295
+ }
296
+ function _isNativeReflectConstruct() {
297
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
298
+ if (Reflect.construct.sham) return false;
299
+ if (typeof Proxy === "function") return true;
300
+ try {
301
+ Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
302
+ return true;
303
+ } catch (e) {
304
+ return false;
305
+ }
306
+ }
307
+ function _getPrototypeOf(o) {
308
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
309
+ return o.__proto__ || Object.getPrototypeOf(o);
310
+ };
311
+ return _getPrototypeOf(o);
312
+ }
313
+ function _defineProperty(obj, key, value) {
314
+ if (key in obj) {
315
+ Object.defineProperty(obj, key, {
316
+ value: value,
317
+ enumerable: true,
318
+ configurable: true,
319
+ writable: true
320
+ });
321
+ } else {
322
+ obj[key] = value;
323
+ }
324
+ return obj;
325
+ }
326
+
327
+ //
328
+ // Define <Draggable>
329
+ //
330
+ var Draggable = /*#__PURE__*/function (_React$Component) {
331
+ _inherits(Draggable, _React$Component);
332
+ var _super = _createSuper(Draggable);
333
+ _createClass(Draggable, null, [{
334
+ key: "getDerivedStateFromProps",
335
+ // React 16.3+
336
+ // Arity (props, state)
337
+ value: function getDerivedStateFromProps(_ref, _ref2) {
338
+ var position = _ref.position;
339
+ var prevPropsPosition = _ref2.prevPropsPosition;
340
+
341
+ // Set x/y if a new position is provided in props that is different than the previous.
342
+ if (position && (!prevPropsPosition || position.x !== prevPropsPosition.x || position.y !== prevPropsPosition.y)) {
343
+ (0, _log["default"])('Draggable: getDerivedStateFromProps %j', {
344
+ position: position,
345
+ prevPropsPosition: prevPropsPosition
346
+ });
347
+ return {
348
+ x: position.x,
349
+ y: position.y,
350
+ prevPropsPosition: _objectSpread({}, position)
351
+ };
352
+ }
353
+ return null;
354
+ }
355
+ }]);
356
+ function Draggable(props
357
+ /*: DraggableProps*/) {
358
+ var _this;
359
+ _classCallCheck(this, Draggable);
360
+ _this = _super.call(this, props);
361
+ _defineProperty(_assertThisInitialized(_this), "onDragStart", function (e, coreData) {
362
+ (0, _log["default"])('Draggable: onDragStart: %j', coreData); // Short-circuit if user's callback killed it.
363
+
364
+ var shouldStart = _this.props.onStart(e, (0, _positionFns.createDraggableData)(_assertThisInitialized(_this), coreData)); // Kills start event on core as well, so move handlers are never bound.
365
+
366
+ if (shouldStart === false) return false;
367
+ _this.setState({
368
+ dragging: true,
369
+ dragged: true
370
+ });
371
+ });
372
+ _defineProperty(_assertThisInitialized(_this), "onDrag", function (e, coreData) {
373
+ if (!_this.state.dragging) return false;
374
+ (0, _log["default"])('Draggable: onDrag: %j', coreData);
375
+ var uiData = (0, _positionFns.createDraggableData)(_assertThisInitialized(_this), coreData);
376
+ var newState
377
+ /*: $Shape<DraggableState>*/ = {
378
+ x: uiData.x,
379
+ y: uiData.y
380
+ }; // Keep within bounds.
381
+
382
+ if (_this.props.bounds) {
383
+ // Save original x and y.
384
+ var x = newState.x,
385
+ y = newState.y; // Add slack to the values used to calculate bound position. This will ensure that if
386
+ // we start removing slack, the element won't react to it right away until it's been
387
+ // completely removed.
388
+
389
+ newState.x += _this.state.slackX;
390
+ newState.y += _this.state.slackY; // Get bound position. This will ceil/floor the x and y within the boundaries.
391
+
392
+ var _getBoundPosition = (0, _positionFns.getBoundPosition)(_assertThisInitialized(_this), newState.x, newState.y),
393
+ _getBoundPosition2 = _slicedToArray(_getBoundPosition, 2),
394
+ newStateX = _getBoundPosition2[0],
395
+ newStateY = _getBoundPosition2[1];
396
+ newState.x = newStateX;
397
+ newState.y = newStateY; // Recalculate slack by noting how much was shaved by the boundPosition handler.
398
+
399
+ newState.slackX = _this.state.slackX + (x - newState.x);
400
+ newState.slackY = _this.state.slackY + (y - newState.y); // Update the event we fire to reflect what really happened after bounds took effect.
401
+
402
+ uiData.x = newState.x;
403
+ uiData.y = newState.y;
404
+ uiData.deltaX = newState.x - _this.state.x;
405
+ uiData.deltaY = newState.y - _this.state.y;
406
+ } // Short-circuit if user's callback killed it.
407
+
408
+ var shouldUpdate = _this.props.onDrag(e, uiData);
409
+ if (shouldUpdate === false) return false;
410
+ _this.setState(newState);
411
+ });
412
+ _defineProperty(_assertThisInitialized(_this), "onDragStop", function (e, coreData) {
413
+ if (!_this.state.dragging) return false; // Short-circuit if user's callback killed it.
414
+
415
+ var shouldContinue = _this.props.onStop(e, (0, _positionFns.createDraggableData)(_assertThisInitialized(_this), coreData));
416
+ if (shouldContinue === false) return false;
417
+ (0, _log["default"])('Draggable: onDragStop: %j', coreData);
418
+ var newState
419
+ /*: $Shape<DraggableState>*/ = {
420
+ dragging: false,
421
+ slackX: 0,
422
+ slackY: 0
423
+ }; // If this is a controlled component, the result of this operation will be to
424
+ // revert back to the old position. We expect a handler on `onDragStop`, at the least.
425
+
426
+ var controlled = Boolean(_this.props.position);
427
+ if (controlled) {
428
+ var _this$props$position = _this.props.position,
429
+ x = _this$props$position.x,
430
+ y = _this$props$position.y;
431
+ newState.x = x;
432
+ newState.y = y;
433
+ }
434
+ _this.setState(newState);
435
+ });
436
+ _this.state = {
437
+ // Whether or not we are currently dragging.
438
+ dragging: false,
439
+ // Whether or not we have been dragged before.
440
+ dragged: false,
441
+ // Current transform x and y.
442
+ x: props.position ? props.position.x : props.defaultPosition.x,
443
+ y: props.position ? props.position.y : props.defaultPosition.y,
444
+ prevPropsPosition: _objectSpread({}, props.position),
445
+ // Used for compensating for out-of-bounds drags
446
+ slackX: 0,
447
+ slackY: 0,
448
+ // Can only determine if SVG after mounting
449
+ isElementSVG: false
450
+ };
451
+ if (props.position && !(props.onDrag || props.onStop)) {
452
+ // eslint-disable-next-line no-console
453
+ 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.');
454
+ }
455
+ return _this;
456
+ }
457
+ _createClass(Draggable, [{
458
+ key: "componentDidMount",
459
+ value: function componentDidMount() {
460
+ // Check to see if the element passed is an instanceof SVGElement
461
+ if (typeof window.SVGElement !== 'undefined' && this.findDOMNode() instanceof window.SVGElement) {
462
+ this.setState({
463
+ isElementSVG: true
464
+ });
465
+ }
466
+ }
467
+ }, {
468
+ key: "componentWillUnmount",
469
+ value: function componentWillUnmount() {
470
+ this.setState({
471
+ dragging: false
472
+ }); // prevents invariant if unmounted while dragging
473
+ } // React Strict Mode compatibility: if `nodeRef` is passed, we will use it instead of trying to find
474
+ // the underlying DOM node ourselves. See the README for more information.
475
+ }, {
476
+ key: "findDOMNode",
477
+ value: function findDOMNode() /*: ?HTMLElement*/
478
+ {
479
+ return this.props.nodeRef ? this.props.nodeRef.current : _reactDom["default"].findDOMNode(this);
480
+ }
481
+ }, {
482
+ key: "render",
483
+ value: function render() /*: ReactElement<any>*/
484
+ {
485
+ var _classNames;
486
+ var _this$props = this.props,
487
+ children = _this$props.children,
488
+ defaultPosition = _this$props.defaultPosition,
489
+ defaultClassName = _this$props.defaultClassName,
490
+ defaultClassNameDragging = _this$props.defaultClassNameDragging,
491
+ defaultClassNameDragged = _this$props.defaultClassNameDragged,
492
+ position = _this$props.position,
493
+ positionOffset = _this$props.positionOffset,
494
+ draggableCoreProps = _objectWithoutProperties(_this$props, ["axis", "bounds", "children", "defaultPosition", "defaultClassName", "defaultClassNameDragging", "defaultClassNameDragged", "position", "positionOffset", "scale"]);
495
+ var style = {};
496
+ var svgTransform = null; // If this is controlled, we don't want to move it - unless it's dragging.
497
+
498
+ var controlled = Boolean(position);
499
+ var draggable = !controlled || this.state.dragging;
500
+ var validPosition = position || defaultPosition;
501
+ var transformOpts = {
502
+ // Set left if horizontal drag is enabled
503
+ x: (0, _positionFns.canDragX)(this) && draggable ? this.state.x : validPosition.x,
504
+ // Set top if vertical drag is enabled
505
+ y: (0, _positionFns.canDragY)(this) && draggable ? this.state.y : validPosition.y
506
+ }; // If this element was SVG, we use the `transform` attribute.
507
+
508
+ if (this.state.isElementSVG) {
509
+ svgTransform = (0, _domFns.createSVGTransform)(transformOpts, positionOffset);
510
+ } else {
511
+ // Add a CSS transform to move the element around. This allows us to move the element around
512
+ // without worrying about whether or not it is relatively or absolutely positioned.
513
+ // If the item you are dragging already has a transform set, wrap it in a <span> so <Draggable>
514
+ // has a clean slate.
515
+ style = (0, _domFns.createCSSTransform)(transformOpts, positionOffset);
516
+ } // Mark with class while dragging
517
+
518
+ var className = (0, _classnames["default"])(children.props.className || '', defaultClassName, (_classNames = {}, _defineProperty(_classNames, defaultClassNameDragging, this.state.dragging), _defineProperty(_classNames, defaultClassNameDragged, this.state.dragged), _classNames)); // Reuse the child provided
519
+ // This makes it flexible to use whatever element is wanted (div, ul, etc)
520
+
521
+ return /*#__PURE__*/React.createElement(_DraggableCore["default"], _extends({}, draggableCoreProps, {
522
+ onStart: this.onDragStart,
523
+ onDrag: this.onDrag,
524
+ onStop: this.onDragStop
525
+ }), React.cloneElement(React.Children.only(children), {
526
+ className: className,
527
+ style: _objectSpread(_objectSpread({}, children.props.style), style),
528
+ transform: svgTransform
529
+ }));
530
+ }
531
+ }]);
532
+ return Draggable;
533
+ }(React.Component);
534
+ exports["default"] = Draggable;
535
+ _defineProperty(Draggable, "displayName", 'Draggable');
536
+ _defineProperty(Draggable, "propTypes", _objectSpread(_objectSpread({}, _DraggableCore["default"].propTypes), {}, {
537
+ /**
538
+ * `axis` determines which axis the draggable can move.
539
+ *
540
+ * Note that all callbacks will still return data as normal. This only
541
+ * controls flushing to the DOM.
542
+ *
543
+ * 'both' allows movement horizontally and vertically.
544
+ * 'x' limits movement to horizontal axis.
545
+ * 'y' limits movement to vertical axis.
546
+ * 'none' limits all movement.
547
+ *
548
+ * Defaults to 'both'.
549
+ */
550
+ axis: _propTypes["default"].oneOf(['both', 'x', 'y', 'none']),
551
+ /**
552
+ * `bounds` determines the range of movement available to the element.
553
+ * Available values are:
554
+ *
555
+ * 'parent' restricts movement within the Draggable's parent node.
556
+ *
557
+ * Alternatively, pass an object with the following properties, all of which are optional:
558
+ *
559
+ * {left: LEFT_BOUND, right: RIGHT_BOUND, bottom: BOTTOM_BOUND, top: TOP_BOUND}
560
+ *
561
+ * All values are in px.
562
+ *
563
+ * Example:
564
+ *
565
+ * ```jsx
566
+ * let App = React.createClass({
567
+ * render: function () {
568
+ * return (
569
+ * <Draggable bounds={{right: 300, bottom: 300}}>
570
+ * <div>Content</div>
571
+ * </Draggable>
572
+ * );
573
+ * }
574
+ * });
575
+ * ```
576
+ */
577
+ bounds: _propTypes["default"].oneOfType([_propTypes["default"].shape({
578
+ left: _propTypes["default"].number,
579
+ right: _propTypes["default"].number,
580
+ top: _propTypes["default"].number,
581
+ bottom: _propTypes["default"].number
582
+ }), _propTypes["default"].string, _propTypes["default"].oneOf([false])]),
583
+ defaultClassName: _propTypes["default"].string,
584
+ defaultClassNameDragging: _propTypes["default"].string,
585
+ defaultClassNameDragged: _propTypes["default"].string,
586
+ /**
587
+ * `defaultPosition` specifies the x and y that the dragged item should start at
588
+ *
589
+ * Example:
590
+ *
591
+ * ```jsx
592
+ * let App = React.createClass({
593
+ * render: function () {
594
+ * return (
595
+ * <Draggable defaultPosition={{x: 25, y: 25}}>
596
+ * <div>I start with transformX: 25px and transformY: 25px;</div>
597
+ * </Draggable>
598
+ * );
599
+ * }
600
+ * });
601
+ * ```
602
+ */
603
+ defaultPosition: _propTypes["default"].shape({
604
+ x: _propTypes["default"].number,
605
+ y: _propTypes["default"].number
606
+ }),
607
+ positionOffset: _propTypes["default"].shape({
608
+ x: _propTypes["default"].oneOfType([_propTypes["default"].number, _propTypes["default"].string]),
609
+ y: _propTypes["default"].oneOfType([_propTypes["default"].number, _propTypes["default"].string])
610
+ }),
611
+ /**
612
+ * `position`, if present, defines the current position of the element.
613
+ *
614
+ * This is similar to how form elements in React work - if no `position` is supplied, the component
615
+ * is uncontrolled.
616
+ *
617
+ * Example:
618
+ *
619
+ * ```jsx
620
+ * let App = React.createClass({
621
+ * render: function () {
622
+ * return (
623
+ * <Draggable position={{x: 25, y: 25}}>
624
+ * <div>I start with transformX: 25px and transformY: 25px;</div>
625
+ * </Draggable>
626
+ * );
627
+ * }
628
+ * });
629
+ * ```
630
+ */
631
+ position: _propTypes["default"].shape({
632
+ x: _propTypes["default"].number,
633
+ y: _propTypes["default"].number
634
+ }),
635
+ /**
636
+ * These properties should be defined on the child, not here.
637
+ */
638
+ className: _shims.dontSetMe,
639
+ style: _shims.dontSetMe,
640
+ transform: _shims.dontSetMe
641
+ }));
642
+ _defineProperty(Draggable, "defaultProps", _objectSpread(_objectSpread({}, _DraggableCore["default"].defaultProps), {}, {
643
+ axis: 'both',
644
+ bounds: false,
645
+ defaultClassName: 'react-draggable',
646
+ defaultClassNameDragging: 'react-draggable-dragging',
647
+ defaultClassNameDragged: 'react-draggable-dragged',
648
+ defaultPosition: {
649
+ x: 0,
650
+ y: 0
651
+ },
652
+ position: null,
653
+ scale: 1
654
+ }));
655
+ })(Draggable.__exports);