1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var React = _interopRequireWildcard(require("react"));
|
9 |
|
10 | var _reactMovable = require("react-movable");
|
11 |
|
12 | function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
13 |
|
14 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
15 |
|
16 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
17 |
|
18 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
19 |
|
20 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
21 |
|
22 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
23 |
|
24 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
25 |
|
26 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
27 |
|
28 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
29 |
|
30 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
31 |
|
32 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
33 |
|
34 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
35 |
|
36 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
37 |
|
38 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
39 |
|
40 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
41 |
|
42 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
43 |
|
44 | var defaultStateReducer = function defaultStateReducer(type, nextState) {
|
45 | return nextState;
|
46 | };
|
47 |
|
48 | var StatefulListContainer =
|
49 |
|
50 | function (_React$Component) {
|
51 | _inherits(StatefulListContainer, _React$Component);
|
52 |
|
53 | function StatefulListContainer() {
|
54 | var _getPrototypeOf2;
|
55 |
|
56 | var _this;
|
57 |
|
58 | _classCallCheck(this, StatefulListContainer);
|
59 |
|
60 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
61 | args[_key] = arguments[_key];
|
62 | }
|
63 |
|
64 | _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(StatefulListContainer)).call.apply(_getPrototypeOf2, [this].concat(args)));
|
65 |
|
66 | _defineProperty(_assertThisInitialized(_this), "state", _objectSpread({
|
67 | items: []
|
68 | }, _this.props.initialState));
|
69 |
|
70 | _defineProperty(_assertThisInitialized(_this), "onChange", function (_ref) {
|
71 | var oldIndex = _ref.oldIndex,
|
72 | newIndex = _ref.newIndex,
|
73 | targetRect = _ref.targetRect;
|
74 | var newItemsState = newIndex === -1 ? (0, _reactMovable.arrayRemove)(_this.state.items, oldIndex) : (0, _reactMovable.arrayMove)(_this.state.items, oldIndex, newIndex);
|
75 |
|
76 | _this.props.onChange({
|
77 | newState: newItemsState,
|
78 | oldIndex: oldIndex,
|
79 | newIndex: newIndex,
|
80 | targetRect: targetRect
|
81 | });
|
82 |
|
83 | _this.internalSetState('change', {
|
84 | items: newItemsState
|
85 | });
|
86 | });
|
87 |
|
88 | return _this;
|
89 | }
|
90 |
|
91 | _createClass(StatefulListContainer, [{
|
92 | key: "internalSetState",
|
93 | value: function internalSetState(type, changes) {
|
94 | var stateReducer = this.props.stateReducer;
|
95 | this.setState(function (prevState) {
|
96 | return stateReducer(type, changes, prevState);
|
97 | });
|
98 | }
|
99 | }, {
|
100 | key: "render",
|
101 | value: function render() {
|
102 | var _this$props = this.props,
|
103 | children = _this$props.children,
|
104 | initialState = _this$props.initialState,
|
105 | stateReducer = _this$props.stateReducer,
|
106 | restProps = _objectWithoutProperties(_this$props, ["children", "initialState", "stateReducer"]);
|
107 |
|
108 | return this.props.children(_objectSpread({}, restProps, {
|
109 | items: this.state.items,
|
110 | onChange: this.onChange
|
111 | }));
|
112 | }
|
113 | }]);
|
114 |
|
115 | return StatefulListContainer;
|
116 | }(React.Component);
|
117 |
|
118 | _defineProperty(StatefulListContainer, "defaultProps", {
|
119 | initialState: {
|
120 | items: []
|
121 | },
|
122 | stateReducer: defaultStateReducer,
|
123 | onChange: function onChange() {}
|
124 | });
|
125 |
|
126 | var _default = StatefulListContainer;
|
127 | exports.default = _default; |
\ | No newline at end of file |