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