@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,670 @@
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 DraggableCore$1 = require('../../../../_virtual/DraggableCore.js');
14
+ var React$1 = require('react');
15
+ require('../../../prop-types/index.js');
16
+ var require$$2 = require('react-dom');
17
+ require('./utils/domFns.js');
18
+ require('./utils/positionFns.js');
19
+ require('./utils/shims.js');
20
+ require('./utils/log.js');
21
+ var shims = require('../../../../_virtual/shims.js');
22
+ var index = require('../../../../_virtual/index2.js');
23
+ var domFns = require('../../../../_virtual/domFns.js');
24
+ var positionFns = require('../../../../_virtual/positionFns.js');
25
+ var log = require('../../../../_virtual/log.js');
26
+ function _interopDefaultCompat(e) {
27
+ return e && _typeof2(e) === 'object' && 'default' in e ? e : {
28
+ 'default': e
29
+ };
30
+ }
31
+ var React__default = /*#__PURE__*/_interopDefaultCompat(React$1);
32
+ var require$$2__default = /*#__PURE__*/_interopDefaultCompat(require$$2);
33
+ Object.defineProperty(DraggableCore$1.__exports, "__esModule", {
34
+ value: true
35
+ });
36
+ DraggableCore$1.__exports["default"] = void 0;
37
+ var React = _interopRequireWildcard(React__default["default"]);
38
+ var _propTypes = _interopRequireDefault(index.propTypes.exports);
39
+ var _reactDom = _interopRequireDefault(require$$2__default["default"]);
40
+ var _domFns = domFns.__exports;
41
+ var _positionFns = positionFns.__exports;
42
+ var _shims = shims.__exports;
43
+ var _log = _interopRequireDefault(log.__exports);
44
+ function _interopRequireDefault(obj) {
45
+ return obj && obj.__esModule ? obj : {
46
+ "default": obj
47
+ };
48
+ }
49
+ function _getRequireWildcardCache() {
50
+ if (typeof WeakMap !== "function") return null;
51
+ var cache = new WeakMap();
52
+ _getRequireWildcardCache = function _getRequireWildcardCache() {
53
+ return cache;
54
+ };
55
+ return cache;
56
+ }
57
+ function _interopRequireWildcard(obj) {
58
+ if (obj && obj.__esModule) {
59
+ return obj;
60
+ }
61
+ if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
62
+ return {
63
+ "default": obj
64
+ };
65
+ }
66
+ var cache = _getRequireWildcardCache();
67
+ if (cache && cache.has(obj)) {
68
+ return cache.get(obj);
69
+ }
70
+ var newObj = {};
71
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
72
+ for (var key in obj) {
73
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
74
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
75
+ if (desc && (desc.get || desc.set)) {
76
+ Object.defineProperty(newObj, key, desc);
77
+ } else {
78
+ newObj[key] = obj[key];
79
+ }
80
+ }
81
+ }
82
+ newObj["default"] = obj;
83
+ if (cache) {
84
+ cache.set(obj, newObj);
85
+ }
86
+ return newObj;
87
+ }
88
+ function _typeof(obj) {
89
+ "@babel/helpers - typeof";
90
+
91
+ if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
92
+ _typeof = function _typeof(obj) {
93
+ return typeof obj;
94
+ };
95
+ } else {
96
+ _typeof = function _typeof(obj) {
97
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
98
+ };
99
+ }
100
+ return _typeof(obj);
101
+ }
102
+ function _slicedToArray(arr, i) {
103
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
104
+ }
105
+ function _nonIterableRest() {
106
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
107
+ }
108
+ function _unsupportedIterableToArray(o, minLen) {
109
+ if (!o) return;
110
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
111
+ var n = Object.prototype.toString.call(o).slice(8, -1);
112
+ if (n === "Object" && o.constructor) n = o.constructor.name;
113
+ if (n === "Map" || n === "Set") return Array.from(o);
114
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
115
+ }
116
+ function _arrayLikeToArray(arr, len) {
117
+ if (len == null || len > arr.length) len = arr.length;
118
+ for (var i = 0, arr2 = new Array(len); i < len; i++) {
119
+ arr2[i] = arr[i];
120
+ }
121
+ return arr2;
122
+ }
123
+ function _iterableToArrayLimit(arr, i) {
124
+ if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
125
+ var _arr = [];
126
+ var _n = true;
127
+ var _d = false;
128
+ var _e = undefined;
129
+ try {
130
+ for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
131
+ _arr.push(_s.value);
132
+ if (i && _arr.length === i) break;
133
+ }
134
+ } catch (err) {
135
+ _d = true;
136
+ _e = err;
137
+ } finally {
138
+ try {
139
+ if (!_n && _i["return"] != null) _i["return"]();
140
+ } finally {
141
+ if (_d) throw _e;
142
+ }
143
+ }
144
+ return _arr;
145
+ }
146
+ function _arrayWithHoles(arr) {
147
+ if (Array.isArray(arr)) return arr;
148
+ }
149
+ function _classCallCheck(instance, Constructor) {
150
+ if (!(instance instanceof Constructor)) {
151
+ throw new TypeError("Cannot call a class as a function");
152
+ }
153
+ }
154
+ function _defineProperties(target, props) {
155
+ for (var i = 0; i < props.length; i++) {
156
+ var descriptor = props[i];
157
+ descriptor.enumerable = descriptor.enumerable || false;
158
+ descriptor.configurable = true;
159
+ if ("value" in descriptor) descriptor.writable = true;
160
+ Object.defineProperty(target, descriptor.key, descriptor);
161
+ }
162
+ }
163
+ function _createClass(Constructor, protoProps, staticProps) {
164
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
165
+ if (staticProps) _defineProperties(Constructor, staticProps);
166
+ return Constructor;
167
+ }
168
+ function _inherits(subClass, superClass) {
169
+ if (typeof superClass !== "function" && superClass !== null) {
170
+ throw new TypeError("Super expression must either be null or a function");
171
+ }
172
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
173
+ constructor: {
174
+ value: subClass,
175
+ writable: true,
176
+ configurable: true
177
+ }
178
+ });
179
+ if (superClass) _setPrototypeOf(subClass, superClass);
180
+ }
181
+ function _setPrototypeOf(o, p) {
182
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
183
+ o.__proto__ = p;
184
+ return o;
185
+ };
186
+ return _setPrototypeOf(o, p);
187
+ }
188
+ function _createSuper(Derived) {
189
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
190
+ return function () {
191
+ var Super = _getPrototypeOf(Derived),
192
+ result;
193
+ if (hasNativeReflectConstruct) {
194
+ var NewTarget = _getPrototypeOf(this).constructor;
195
+ result = Reflect.construct(Super, arguments, NewTarget);
196
+ } else {
197
+ result = Super.apply(this, arguments);
198
+ }
199
+ return _possibleConstructorReturn(this, result);
200
+ };
201
+ }
202
+ function _possibleConstructorReturn(self, call) {
203
+ if (call && (_typeof(call) === "object" || typeof call === "function")) {
204
+ return call;
205
+ }
206
+ return _assertThisInitialized(self);
207
+ }
208
+ function _assertThisInitialized(self) {
209
+ if (self === void 0) {
210
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
211
+ }
212
+ return self;
213
+ }
214
+ function _isNativeReflectConstruct() {
215
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
216
+ if (Reflect.construct.sham) return false;
217
+ if (typeof Proxy === "function") return true;
218
+ try {
219
+ Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
220
+ return true;
221
+ } catch (e) {
222
+ return false;
223
+ }
224
+ }
225
+ function _getPrototypeOf(o) {
226
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
227
+ return o.__proto__ || Object.getPrototypeOf(o);
228
+ };
229
+ return _getPrototypeOf(o);
230
+ }
231
+ function _defineProperty(obj, key, value) {
232
+ if (key in obj) {
233
+ Object.defineProperty(obj, key, {
234
+ value: value,
235
+ enumerable: true,
236
+ configurable: true,
237
+ writable: true
238
+ });
239
+ } else {
240
+ obj[key] = value;
241
+ }
242
+ return obj;
243
+ }
244
+
245
+ // Simple abstraction for dragging events names.
246
+ var eventsFor = {
247
+ touch: {
248
+ start: 'touchstart',
249
+ move: 'touchmove',
250
+ stop: 'touchend'
251
+ },
252
+ mouse: {
253
+ start: 'mousedown',
254
+ move: 'mousemove',
255
+ stop: 'mouseup'
256
+ }
257
+ }; // Default to mouse events.
258
+
259
+ var dragEventFor = eventsFor.mouse;
260
+ /*:: type DraggableCoreState = {
261
+ dragging: boolean,
262
+ lastX: number,
263
+ lastY: number,
264
+ touchIdentifier: ?number
265
+ };*/
266
+
267
+ /*:: export type DraggableData = {
268
+ node: HTMLElement,
269
+ x: number, y: number,
270
+ deltaX: number, deltaY: number,
271
+ lastX: number, lastY: number,
272
+ };*/
273
+
274
+ /*:: export type DraggableEventHandler = (e: MouseEvent, data: DraggableData) => void;*/
275
+
276
+ /*:: export type ControlPosition = {x: number, y: number};*/
277
+
278
+ /*:: export type PositionOffsetControlPosition = {x: number|string, y: number|string};*/
279
+
280
+ /*:: export type DraggableCoreProps = {
281
+ allowAnyClick: boolean,
282
+ cancel: string,
283
+ children: ReactElement<any>,
284
+ disabled: boolean,
285
+ enableUserSelectHack: boolean,
286
+ offsetParent: HTMLElement,
287
+ grid: [number, number],
288
+ handle: string,
289
+ nodeRef?: ?React.ElementRef<any>,
290
+ onStart: DraggableEventHandler,
291
+ onDrag: DraggableEventHandler,
292
+ onStop: DraggableEventHandler,
293
+ onMouseDown: (e: MouseEvent) => void,
294
+ scale: number,
295
+ };*/
296
+
297
+ //
298
+ // Define <DraggableCore>.
299
+ //
300
+ // <DraggableCore> is for advanced usage of <Draggable>. It maintains minimal internal state so it can
301
+ // work well with libraries that require more control over the element.
302
+ //
303
+ var DraggableCore = /*#__PURE__*/function (_React$Component) {
304
+ _inherits(DraggableCore, _React$Component);
305
+ var _super = _createSuper(DraggableCore);
306
+ function DraggableCore() {
307
+ var _this;
308
+ _classCallCheck(this, DraggableCore);
309
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
310
+ args[_key] = arguments[_key];
311
+ }
312
+ _this = _super.call.apply(_super, [this].concat(args));
313
+ _defineProperty(_assertThisInitialized(_this), "state", {
314
+ dragging: false,
315
+ // Used while dragging to determine deltas.
316
+ lastX: NaN,
317
+ lastY: NaN,
318
+ touchIdentifier: null
319
+ });
320
+ _defineProperty(_assertThisInitialized(_this), "mounted", false);
321
+ _defineProperty(_assertThisInitialized(_this), "handleDragStart", function (e) {
322
+ // Make it possible to attach event handlers on top of this one.
323
+ _this.props.onMouseDown(e); // Only accept left-clicks.
324
+
325
+ if (!_this.props.allowAnyClick && typeof e.button === 'number' && e.button !== 0) return false; // Get nodes. Be sure to grab relative document (could be iframed)
326
+
327
+ var thisNode = _this.findDOMNode();
328
+ if (!thisNode || !thisNode.ownerDocument || !thisNode.ownerDocument.body) {
329
+ throw new Error('<DraggableCore> not mounted on DragStart!');
330
+ }
331
+ var ownerDocument = thisNode.ownerDocument; // Short circuit if handle or cancel prop was provided and selector doesn't match.
332
+
333
+ 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)) {
334
+ return;
335
+ } // Prevent scrolling on mobile devices, like ipad/iphone.
336
+ // Important that this is after handle/cancel.
337
+
338
+ if (e.type === 'touchstart') e.preventDefault(); // Set touch identifier in component state if this is a touch event. This allows us to
339
+ // distinguish between individual touches on multitouch screens by identifying which
340
+ // touchpoint was set to this element.
341
+
342
+ var touchIdentifier = (0, _domFns.getTouchIdentifier)(e);
343
+ _this.setState({
344
+ touchIdentifier: touchIdentifier
345
+ }); // Get the current drag point from the event. This is used as the offset.
346
+
347
+ var position = (0, _positionFns.getControlPosition)(e, touchIdentifier, _assertThisInitialized(_this));
348
+ if (position == null) return; // not possible but satisfies flow
349
+
350
+ var x = position.x,
351
+ y = position.y; // Create an event object with all the data parents need to make a decision here.
352
+
353
+ var coreEvent = (0, _positionFns.createCoreData)(_assertThisInitialized(_this), x, y);
354
+ (0, _log["default"])('DraggableCore: handleDragStart: %j', coreEvent); // Call event handler. If it returns explicit false, cancel.
355
+
356
+ (0, _log["default"])('calling', _this.props.onStart);
357
+ var shouldUpdate = _this.props.onStart(e, coreEvent);
358
+ if (shouldUpdate === false || _this.mounted === false) return; // Add a style to the body to disable user-select. This prevents text from
359
+ // being selected all over the page.
360
+
361
+ if (_this.props.enableUserSelectHack) (0, _domFns.addUserSelectStyles)(ownerDocument); // Initiate dragging. Set the current x and y as offsets
362
+ // so we know how much we've moved during the drag. This allows us
363
+ // to drag elements around even if they have been moved, without issue.
364
+
365
+ _this.setState({
366
+ dragging: true,
367
+ lastX: x,
368
+ lastY: y
369
+ }); // Add events to the document directly so we catch when the user's mouse/touch moves outside of
370
+ // this element. We use different events depending on whether or not we have detected that this
371
+ // is a touch-capable device.
372
+
373
+ (0, _domFns.addEvent)(ownerDocument, dragEventFor.move, _this.handleDrag);
374
+ (0, _domFns.addEvent)(ownerDocument, dragEventFor.stop, _this.handleDragStop);
375
+ });
376
+ _defineProperty(_assertThisInitialized(_this), "handleDrag", function (e) {
377
+ // Get the current drag point from the event. This is used as the offset.
378
+ var position = (0, _positionFns.getControlPosition)(e, _this.state.touchIdentifier, _assertThisInitialized(_this));
379
+ if (position == null) return;
380
+ var x = position.x,
381
+ y = position.y; // Snap to grid if prop has been provided
382
+
383
+ if (Array.isArray(_this.props.grid)) {
384
+ var deltaX = x - _this.state.lastX,
385
+ deltaY = y - _this.state.lastY;
386
+ var _snapToGrid = (0, _positionFns.snapToGrid)(_this.props.grid, deltaX, deltaY);
387
+ var _snapToGrid2 = _slicedToArray(_snapToGrid, 2);
388
+ deltaX = _snapToGrid2[0];
389
+ deltaY = _snapToGrid2[1];
390
+ if (!deltaX && !deltaY) return; // skip useless drag
391
+
392
+ x = _this.state.lastX + deltaX, y = _this.state.lastY + deltaY;
393
+ }
394
+ var coreEvent = (0, _positionFns.createCoreData)(_assertThisInitialized(_this), x, y);
395
+ (0, _log["default"])('DraggableCore: handleDrag: %j', coreEvent); // Call event handler. If it returns explicit false, trigger end.
396
+
397
+ var shouldUpdate = _this.props.onDrag(e, coreEvent);
398
+ if (shouldUpdate === false || _this.mounted === false) {
399
+ try {
400
+ // $FlowIgnore
401
+ _this.handleDragStop(new MouseEvent('mouseup'));
402
+ } catch (err) {
403
+ // Old browsers
404
+ var event = document.createEvent('MouseEvents')
405
+ /*: any*/
406
+
407
+ /*: MouseTouchEvent*/; // I see why this insanity was deprecated
408
+ // $FlowIgnore
409
+
410
+ event.initMouseEvent('mouseup', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
411
+ _this.handleDragStop(event);
412
+ }
413
+ return;
414
+ }
415
+ _this.setState({
416
+ lastX: x,
417
+ lastY: y
418
+ });
419
+ });
420
+ _defineProperty(_assertThisInitialized(_this), "handleDragStop", function (e) {
421
+ if (!_this.state.dragging) return;
422
+ var position = (0, _positionFns.getControlPosition)(e, _this.state.touchIdentifier, _assertThisInitialized(_this));
423
+ if (position == null) return;
424
+ var x = position.x,
425
+ y = position.y;
426
+ var coreEvent = (0, _positionFns.createCoreData)(_assertThisInitialized(_this), x, y); // Call event handler
427
+
428
+ var shouldContinue = _this.props.onStop(e, coreEvent);
429
+ if (shouldContinue === false || _this.mounted === false) return false;
430
+ var thisNode = _this.findDOMNode();
431
+ if (thisNode) {
432
+ // Remove user-select hack
433
+ if (_this.props.enableUserSelectHack) (0, _domFns.removeUserSelectStyles)(thisNode.ownerDocument);
434
+ }
435
+ (0, _log["default"])('DraggableCore: handleDragStop: %j', coreEvent); // Reset the el.
436
+
437
+ _this.setState({
438
+ dragging: false,
439
+ lastX: NaN,
440
+ lastY: NaN
441
+ });
442
+ if (thisNode) {
443
+ // Remove event handlers
444
+ (0, _log["default"])('DraggableCore: Removing handlers');
445
+ (0, _domFns.removeEvent)(thisNode.ownerDocument, dragEventFor.move, _this.handleDrag);
446
+ (0, _domFns.removeEvent)(thisNode.ownerDocument, dragEventFor.stop, _this.handleDragStop);
447
+ }
448
+ });
449
+ _defineProperty(_assertThisInitialized(_this), "onMouseDown", function (e) {
450
+ dragEventFor = eventsFor.mouse; // on touchscreen laptops we could switch back to mouse
451
+
452
+ return _this.handleDragStart(e);
453
+ });
454
+ _defineProperty(_assertThisInitialized(_this), "onMouseUp", function (e) {
455
+ dragEventFor = eventsFor.mouse;
456
+ return _this.handleDragStop(e);
457
+ });
458
+ _defineProperty(_assertThisInitialized(_this), "onTouchStart", function (e) {
459
+ // We're on a touch device now, so change the event handlers
460
+ dragEventFor = eventsFor.touch;
461
+ return _this.handleDragStart(e);
462
+ });
463
+ _defineProperty(_assertThisInitialized(_this), "onTouchEnd", function (e) {
464
+ // We're on a touch device now, so change the event handlers
465
+ dragEventFor = eventsFor.touch;
466
+ return _this.handleDragStop(e);
467
+ });
468
+ return _this;
469
+ }
470
+ _createClass(DraggableCore, [{
471
+ key: "componentDidMount",
472
+ value: function componentDidMount() {
473
+ this.mounted = true; // Touch handlers must be added with {passive: false} to be cancelable.
474
+ // https://developers.google.com/web/updates/2017/01/scrolling-intervention
475
+
476
+ var thisNode = this.findDOMNode();
477
+ if (thisNode) {
478
+ (0, _domFns.addEvent)(thisNode, eventsFor.touch.start, this.onTouchStart, {
479
+ passive: false
480
+ });
481
+ }
482
+ }
483
+ }, {
484
+ key: "componentWillUnmount",
485
+ value: function componentWillUnmount() {
486
+ this.mounted = false; // Remove any leftover event handlers. Remove both touch and mouse handlers in case
487
+ // some browser quirk caused a touch event to fire during a mouse move, or vice versa.
488
+
489
+ var thisNode = this.findDOMNode();
490
+ if (thisNode) {
491
+ var ownerDocument = thisNode.ownerDocument;
492
+ (0, _domFns.removeEvent)(ownerDocument, eventsFor.mouse.move, this.handleDrag);
493
+ (0, _domFns.removeEvent)(ownerDocument, eventsFor.touch.move, this.handleDrag);
494
+ (0, _domFns.removeEvent)(ownerDocument, eventsFor.mouse.stop, this.handleDragStop);
495
+ (0, _domFns.removeEvent)(ownerDocument, eventsFor.touch.stop, this.handleDragStop);
496
+ (0, _domFns.removeEvent)(thisNode, eventsFor.touch.start, this.onTouchStart, {
497
+ passive: false
498
+ });
499
+ if (this.props.enableUserSelectHack) (0, _domFns.removeUserSelectStyles)(ownerDocument);
500
+ }
501
+ } // React Strict Mode compatibility: if `nodeRef` is passed, we will use it instead of trying to find
502
+ // the underlying DOM node ourselves. See the README for more information.
503
+ }, {
504
+ key: "findDOMNode",
505
+ value: function findDOMNode() /*: ?HTMLElement*/
506
+ {
507
+ return this.props.nodeRef ? this.props.nodeRef.current : _reactDom["default"].findDOMNode(this);
508
+ }
509
+ }, {
510
+ key: "render",
511
+ value: function render() {
512
+ // Reuse the child provided
513
+ // This makes it flexible to use whatever element is wanted (div, ul, etc)
514
+ return React.cloneElement(React.Children.only(this.props.children), {
515
+ // Note: mouseMove handler is attached to document so it will still function
516
+ // when the user drags quickly and leaves the bounds of the element.
517
+ onMouseDown: this.onMouseDown,
518
+ onMouseUp: this.onMouseUp,
519
+ // onTouchStart is added on `componentDidMount` so they can be added with
520
+ // {passive: false}, which allows it to cancel. See
521
+ // https://developers.google.com/web/updates/2017/01/scrolling-intervention
522
+ onTouchEnd: this.onTouchEnd
523
+ });
524
+ }
525
+ }]);
526
+ return DraggableCore;
527
+ }(React.Component);
528
+ DraggableCore$1.__exports["default"] = DraggableCore;
529
+ _defineProperty(DraggableCore, "displayName", 'DraggableCore');
530
+ _defineProperty(DraggableCore, "propTypes", {
531
+ /**
532
+ * `allowAnyClick` allows dragging using any mouse button.
533
+ * By default, we only accept the left button.
534
+ *
535
+ * Defaults to `false`.
536
+ */
537
+ allowAnyClick: _propTypes["default"].bool,
538
+ /**
539
+ * `disabled`, if true, stops the <Draggable> from dragging. All handlers,
540
+ * with the exception of `onMouseDown`, will not fire.
541
+ */
542
+ disabled: _propTypes["default"].bool,
543
+ /**
544
+ * By default, we add 'user-select:none' attributes to the document body
545
+ * to prevent ugly text selection during drag. If this is causing problems
546
+ * for your app, set this to `false`.
547
+ */
548
+ enableUserSelectHack: _propTypes["default"].bool,
549
+ /**
550
+ * `offsetParent`, if set, uses the passed DOM node to compute drag offsets
551
+ * instead of using the parent node.
552
+ */
553
+ offsetParent: function offsetParent(props
554
+ /*: DraggableCoreProps*/, propName
555
+ /*: $Keys<DraggableCoreProps>*/) {
556
+ if (props[propName] && props[propName].nodeType !== 1) {
557
+ throw new Error('Draggable\'s offsetParent must be a DOM Node.');
558
+ }
559
+ },
560
+ /**
561
+ * `grid` specifies the x and y that dragging should snap to.
562
+ */
563
+ grid: _propTypes["default"].arrayOf(_propTypes["default"].number),
564
+ /**
565
+ * `handle` specifies a selector to be used as the handle that initiates drag.
566
+ *
567
+ * Example:
568
+ *
569
+ * ```jsx
570
+ * let App = React.createClass({
571
+ * render: function () {
572
+ * return (
573
+ * <Draggable handle=".handle">
574
+ * <div>
575
+ * <div className="handle">Click me to drag</div>
576
+ * <div>This is some other content</div>
577
+ * </div>
578
+ * </Draggable>
579
+ * );
580
+ * }
581
+ * });
582
+ * ```
583
+ */
584
+ handle: _propTypes["default"].string,
585
+ /**
586
+ * `cancel` specifies a selector to be used to prevent drag initialization.
587
+ *
588
+ * Example:
589
+ *
590
+ * ```jsx
591
+ * let App = React.createClass({
592
+ * render: function () {
593
+ * return(
594
+ * <Draggable cancel=".cancel">
595
+ * <div>
596
+ * <div className="cancel">You can't drag from here</div>
597
+ * <div>Dragging here works fine</div>
598
+ * </div>
599
+ * </Draggable>
600
+ * );
601
+ * }
602
+ * });
603
+ * ```
604
+ */
605
+ cancel: _propTypes["default"].string,
606
+ /* If running in React Strict mode, ReactDOM.findDOMNode() is deprecated.
607
+ * Unfortunately, in order for <Draggable> to work properly, we need raw access
608
+ * to the underlying DOM node. If you want to avoid the warning, pass a `nodeRef`
609
+ * as in this example:
610
+ *
611
+ * function MyComponent() {
612
+ * const nodeRef = React.useRef(null);
613
+ * return (
614
+ * <Draggable nodeRef={nodeRef}>
615
+ * <div ref={nodeRef}>Example Target</div>
616
+ * </Draggable>
617
+ * );
618
+ * }
619
+ *
620
+ * This can be used for arbitrarily nested components, so long as the ref ends up
621
+ * pointing to the actual child DOM node and not a custom component.
622
+ */
623
+ nodeRef: _propTypes["default"].object,
624
+ /**
625
+ * Called when dragging starts.
626
+ * If this function returns the boolean false, dragging will be canceled.
627
+ */
628
+ onStart: _propTypes["default"].func,
629
+ /**
630
+ * Called while dragging.
631
+ * If this function returns the boolean false, dragging will be canceled.
632
+ */
633
+ onDrag: _propTypes["default"].func,
634
+ /**
635
+ * Called when dragging stops.
636
+ * If this function returns the boolean false, the drag will remain active.
637
+ */
638
+ onStop: _propTypes["default"].func,
639
+ /**
640
+ * A workaround option which can be passed if onMouseDown needs to be accessed,
641
+ * since it'll always be blocked (as there is internal use of onMouseDown)
642
+ */
643
+ onMouseDown: _propTypes["default"].func,
644
+ /**
645
+ * `scale`, if set, applies scaling while dragging an element
646
+ */
647
+ scale: _propTypes["default"].number,
648
+ /**
649
+ * These properties should be defined on the child, not here.
650
+ */
651
+ className: _shims.dontSetMe,
652
+ style: _shims.dontSetMe,
653
+ transform: _shims.dontSetMe
654
+ });
655
+ _defineProperty(DraggableCore, "defaultProps", {
656
+ allowAnyClick: false,
657
+ // by default only accept left click
658
+ cancel: null,
659
+ disabled: false,
660
+ enableUserSelectHack: true,
661
+ offsetParent: null,
662
+ handle: null,
663
+ grid: null,
664
+ transform: null,
665
+ onStart: function onStart() {},
666
+ onDrag: function onDrag() {},
667
+ onStop: function onStop() {},
668
+ onMouseDown: function onMouseDown() {},
669
+ scale: 1
670
+ });
@@ -0,0 +1,23 @@
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 cjs = require('../../../../_virtual/cjs.js');
13
+ require('./Draggable.js');
14
+ var Draggable$1 = require('../../../../_virtual/Draggable.js');
15
+ var _require = Draggable$1.__exports,
16
+ Draggable = _require["default"],
17
+ DraggableCore = _require.DraggableCore; // 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'.
18
+ // See https://github.com/mzabriskie/react-draggable/pull/254
19
+ // and https://github.com/mzabriskie/react-draggable/issues/266
20
+
21
+ cjs.cjs.exports = Draggable;
22
+ cjs.cjs.exports["default"] = Draggable;
23
+ cjs.cjs.exports.DraggableCore = DraggableCore;