@elliemae/ds-query-builder 2.2.0-alpha.4 → 3.0.0-next.2
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.
- package/cjs/DSQueryBuilder.js +97 -117
- package/cjs/components/AndOrController/AndOrController.js +162 -148
- package/cjs/components/ConditionController/ConditionController.js +72 -88
- package/cjs/components/DisplayOutput/DisplayOutput.js +68 -63
- package/cjs/components/DragContainerController/DragContainerController.js +41 -61
- package/cjs/components/DragControllerRow/DragControllerRow.js +46 -50
- package/cjs/components/FieldControllerRow/FieldControllerRow.js +32 -54
- package/cjs/components/Nestable/Nestable.js +209 -143
- package/cjs/components/Nestable/NestableItem.js +90 -98
- package/cjs/components/Nestable/actions/events.js +95 -72
- package/cjs/components/Nestable/actions/getItemOptions.js +15 -36
- package/cjs/components/Nestable/actions/getPaths.js +51 -46
- package/cjs/components/Nestable/actions/index.js +28 -42
- package/cjs/components/Nestable/actions/moveItem.js +42 -44
- package/cjs/components/Nestable/actions/paths.js +55 -48
- package/cjs/components/Nestable/actions/tryDecreaseDepth.js +23 -39
- package/cjs/components/Nestable/actions/tryIncreaseDepth.js +26 -39
- package/cjs/components/Nestable/index.js +7 -36
- package/cjs/components/QueryBuilderContext/QueryBuilderContext.js +13 -36
- package/cjs/components/QueryBuilderImpl.js +202 -118
- package/cjs/components/QueryBuilderItem/QueryBuilderItem.js +78 -80
- package/cjs/components/QueryBuilderRow/QueryBuilderRow.js +211 -154
- package/cjs/components/ToolBarAnimation/ToolBarAnimation.js +26 -39
- package/cjs/components/format/format.js +22 -48
- package/cjs/components/format/sqlFormat.js +48 -69
- package/cjs/components/format/sqlSafeFormat.js +55 -72
- package/cjs/components/format/xmlFormat.js +50 -71
- package/cjs/components/helpers/actions.js +186 -151
- package/cjs/components/helpers/constants.js +8 -36
- package/cjs/components/helpers/dependencies.js +64 -49
- package/cjs/components/helpers/selectors.js +101 -161
- package/cjs/components/helpers/store.js +104 -86
- package/cjs/components/helpers/types.js +44 -72
- package/cjs/index.js +29 -36
- package/cjs/propTypes.js +94 -102
- package/esm/DSQueryBuilder.js +72 -103
- package/esm/components/AndOrController/AndOrController.js +147 -113
- package/esm/components/ConditionController/ConditionController.js +62 -57
- package/esm/components/DisplayOutput/DisplayOutput.js +59 -31
- package/esm/components/DragContainerController/DragContainerController.js +35 -32
- package/esm/components/DragControllerRow/DragControllerRow.js +38 -21
- package/esm/components/FieldControllerRow/FieldControllerRow.js +26 -25
- package/esm/components/Nestable/Nestable.js +186 -115
- package/esm/components/Nestable/NestableItem.js +82 -69
- package/esm/components/Nestable/actions/events.js +79 -45
- package/esm/components/Nestable/actions/getItemOptions.js +11 -7
- package/esm/components/Nestable/actions/getPaths.js +43 -17
- package/esm/components/Nestable/actions/index.js +6 -13
- package/esm/components/Nestable/actions/moveItem.js +31 -13
- package/esm/components/Nestable/actions/paths.js +47 -19
- package/esm/components/Nestable/actions/tryDecreaseDepth.js +19 -10
- package/esm/components/Nestable/actions/tryIncreaseDepth.js +22 -10
- package/esm/components/Nestable/index.js +2 -7
- package/esm/components/QueryBuilderContext/QueryBuilderContext.js +5 -7
- package/esm/components/QueryBuilderImpl.js +187 -82
- package/esm/components/QueryBuilderItem/QueryBuilderItem.js +70 -50
- package/esm/components/QueryBuilderRow/QueryBuilderRow.js +201 -123
- package/esm/components/ToolBarAnimation/ToolBarAnimation.js +17 -10
- package/esm/components/format/format.js +17 -16
- package/esm/components/format/sqlFormat.js +43 -39
- package/esm/components/format/sqlSafeFormat.js +50 -43
- package/esm/components/format/xmlFormat.js +45 -41
- package/esm/components/helpers/actions.js +160 -123
- package/esm/components/helpers/constants.js +2 -7
- package/esm/components/helpers/dependencies.js +39 -19
- package/esm/components/helpers/selectors.js +93 -132
- package/esm/components/helpers/store.js +82 -54
- package/esm/components/helpers/types.js +33 -44
- package/esm/index.js +4 -7
- package/esm/propTypes.js +72 -55
- package/package.json +12 -12
- package/cjs/DSQueryBuilder.js.map +0 -7
- package/cjs/components/AndOrController/AndOrController.js.map +0 -7
- package/cjs/components/ConditionController/ConditionController.js.map +0 -7
- package/cjs/components/DisplayOutput/DisplayOutput.js.map +0 -7
- package/cjs/components/DragContainerController/DragContainerController.js.map +0 -7
- package/cjs/components/DragControllerRow/DragControllerRow.js.map +0 -7
- package/cjs/components/FieldControllerRow/FieldControllerRow.js.map +0 -7
- package/cjs/components/Nestable/Nestable.js.map +0 -7
- package/cjs/components/Nestable/NestableItem.js.map +0 -7
- package/cjs/components/Nestable/actions/events.js.map +0 -7
- package/cjs/components/Nestable/actions/getItemOptions.js.map +0 -7
- package/cjs/components/Nestable/actions/getPaths.js.map +0 -7
- package/cjs/components/Nestable/actions/index.js.map +0 -7
- package/cjs/components/Nestable/actions/moveItem.js.map +0 -7
- package/cjs/components/Nestable/actions/paths.js.map +0 -7
- package/cjs/components/Nestable/actions/tryDecreaseDepth.js.map +0 -7
- package/cjs/components/Nestable/actions/tryIncreaseDepth.js.map +0 -7
- package/cjs/components/Nestable/index.js.map +0 -7
- package/cjs/components/QueryBuilderContext/QueryBuilderContext.js.map +0 -7
- package/cjs/components/QueryBuilderImpl.js.map +0 -7
- package/cjs/components/QueryBuilderItem/QueryBuilderItem.js.map +0 -7
- package/cjs/components/QueryBuilderRow/QueryBuilderRow.js.map +0 -7
- package/cjs/components/ToolBarAnimation/ToolBarAnimation.js.map +0 -7
- package/cjs/components/format/format.js.map +0 -7
- package/cjs/components/format/sqlFormat.js.map +0 -7
- package/cjs/components/format/sqlSafeFormat.js.map +0 -7
- package/cjs/components/format/xmlFormat.js.map +0 -7
- package/cjs/components/helpers/actions.js.map +0 -7
- package/cjs/components/helpers/constants.js.map +0 -7
- package/cjs/components/helpers/dependencies.js.map +0 -7
- package/cjs/components/helpers/selectors.js.map +0 -7
- package/cjs/components/helpers/store.js.map +0 -7
- package/cjs/components/helpers/types.js.map +0 -7
- package/cjs/index.js.map +0 -7
- package/cjs/propTypes.js.map +0 -7
- package/esm/DSQueryBuilder.js.map +0 -7
- package/esm/components/AndOrController/AndOrController.js.map +0 -7
- package/esm/components/ConditionController/ConditionController.js.map +0 -7
- package/esm/components/DisplayOutput/DisplayOutput.js.map +0 -7
- package/esm/components/DragContainerController/DragContainerController.js.map +0 -7
- package/esm/components/DragControllerRow/DragControllerRow.js.map +0 -7
- package/esm/components/FieldControllerRow/FieldControllerRow.js.map +0 -7
- package/esm/components/Nestable/Nestable.js.map +0 -7
- package/esm/components/Nestable/NestableItem.js.map +0 -7
- package/esm/components/Nestable/actions/events.js.map +0 -7
- package/esm/components/Nestable/actions/getItemOptions.js.map +0 -7
- package/esm/components/Nestable/actions/getPaths.js.map +0 -7
- package/esm/components/Nestable/actions/index.js.map +0 -7
- package/esm/components/Nestable/actions/moveItem.js.map +0 -7
- package/esm/components/Nestable/actions/paths.js.map +0 -7
- package/esm/components/Nestable/actions/tryDecreaseDepth.js.map +0 -7
- package/esm/components/Nestable/actions/tryIncreaseDepth.js.map +0 -7
- package/esm/components/Nestable/index.js.map +0 -7
- package/esm/components/QueryBuilderContext/QueryBuilderContext.js.map +0 -7
- package/esm/components/QueryBuilderImpl.js.map +0 -7
- package/esm/components/QueryBuilderItem/QueryBuilderItem.js.map +0 -7
- package/esm/components/QueryBuilderRow/QueryBuilderRow.js.map +0 -7
- package/esm/components/ToolBarAnimation/ToolBarAnimation.js.map +0 -7
- package/esm/components/format/format.js.map +0 -7
- package/esm/components/format/sqlFormat.js.map +0 -7
- package/esm/components/format/sqlSafeFormat.js.map +0 -7
- package/esm/components/format/xmlFormat.js.map +0 -7
- package/esm/components/helpers/actions.js.map +0 -7
- package/esm/components/helpers/constants.js.map +0 -7
- package/esm/components/helpers/dependencies.js.map +0 -7
- package/esm/components/helpers/selectors.js.map +0 -7
- package/esm/components/helpers/store.js.map +0 -7
- package/esm/components/helpers/types.js.map +0 -7
- package/esm/index.js.map +0 -7
- package/esm/propTypes.js.map +0 -7
|
@@ -1,90 +1,103 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
7
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
8
|
+
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
9
|
+
import 'core-js/modules/esnext.iterator.map.js';
|
|
10
|
+
import 'react';
|
|
11
|
+
import cn from 'classnames';
|
|
12
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
13
|
+
|
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
+
|
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
+
|
|
18
|
+
const NestableItem = _ref => {
|
|
19
|
+
let {
|
|
20
|
+
item,
|
|
21
|
+
isCopy,
|
|
22
|
+
options,
|
|
23
|
+
index,
|
|
24
|
+
isAndItem,
|
|
25
|
+
isOrItem,
|
|
26
|
+
isDraggableItem,
|
|
27
|
+
singleRow
|
|
28
|
+
} = _ref;
|
|
29
|
+
const {
|
|
30
|
+
dragItem,
|
|
31
|
+
renderItem,
|
|
32
|
+
handler,
|
|
33
|
+
childrenProp
|
|
34
|
+
} = options;
|
|
15
35
|
const isCollapsed = options.isCollapsed(item);
|
|
16
36
|
const isDragging = !isCopy && dragItem && dragItem.id === item.id;
|
|
17
37
|
const hasChildren = item[childrenProp] && item[childrenProp].length > 0;
|
|
18
38
|
let Handler;
|
|
19
|
-
const isOrGroup = item.element.type ===
|
|
20
|
-
const isAndGroup = item.element.type ===
|
|
39
|
+
const isOrGroup = item.element.type === 'group' && (item.element.condition === '' || item.element.condition === false);
|
|
40
|
+
const isAndGroup = item.element.type === 'group' && !(item.element.condition === '' || item.element.condition === false);
|
|
21
41
|
const itemProps = {
|
|
22
|
-
className: cn(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
42
|
+
className: cn("nestable-item".concat(isCopy ? '-copy' : ''), "nestable-item".concat(isCopy ? '-copy' : '', "-").concat(item.id), "nestable-item-type-".concat(item.element.type), {
|
|
43
|
+
'is-or-group': isOrGroup,
|
|
44
|
+
'is-and-group': isAndGroup,
|
|
45
|
+
'is-and-filter': item.element.type === 'filter' && isAndItem,
|
|
46
|
+
'is-or-filter': item.element.type === 'filter' && isOrItem
|
|
27
47
|
}, {
|
|
28
|
-
|
|
48
|
+
'is-dragging': isDragging
|
|
29
49
|
})
|
|
30
50
|
};
|
|
31
51
|
let rowProps = {};
|
|
32
52
|
let handlerProps = {};
|
|
53
|
+
|
|
33
54
|
if (!isCopy) {
|
|
34
55
|
if (dragItem) {
|
|
35
|
-
rowProps = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
56
|
+
rowProps = _objectSpread(_objectSpread({}, rowProps), {}, {
|
|
57
|
+
onMouseEnter: e => options.onMouseEnter(e, item)
|
|
58
|
+
});
|
|
39
59
|
} else {
|
|
40
|
-
handlerProps = {
|
|
41
|
-
...handlerProps,
|
|
60
|
+
handlerProps = _objectSpread(_objectSpread({}, handlerProps), {}, {
|
|
42
61
|
draggable: isDraggableItem !== false,
|
|
43
|
-
onDragStart:
|
|
44
|
-
};
|
|
62
|
+
onDragStart: e => options.onDragStart(e, item)
|
|
63
|
+
});
|
|
45
64
|
}
|
|
46
65
|
}
|
|
66
|
+
|
|
47
67
|
if (handler) {
|
|
48
|
-
Handler =
|
|
49
|
-
className: "nestable-item-handler"
|
|
50
|
-
|
|
51
|
-
|
|
68
|
+
Handler = /*#__PURE__*/jsx("span", _objectSpread(_objectSpread({
|
|
69
|
+
className: "nestable-item-handler"
|
|
70
|
+
}, handlerProps), {}, {
|
|
71
|
+
children: handler
|
|
72
|
+
})); // Handler = React.cloneElement(handler, handlerProps);
|
|
52
73
|
} else {
|
|
53
|
-
rowProps = {
|
|
54
|
-
...rowProps,
|
|
55
|
-
...handlerProps
|
|
56
|
-
};
|
|
74
|
+
rowProps = _objectSpread(_objectSpread({}, rowProps), handlerProps);
|
|
57
75
|
}
|
|
76
|
+
|
|
58
77
|
const childLength = item[childrenProp].length;
|
|
59
|
-
let childClass =
|
|
60
|
-
if (childLength === 0)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
item,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
options,
|
|
83
|
-
singleRow
|
|
84
|
-
}))));
|
|
85
|
-
};
|
|
86
|
-
var NestableItem_default = NestableItem;
|
|
87
|
-
export {
|
|
88
|
-
NestableItem_default as default
|
|
78
|
+
let childClass = 'single';
|
|
79
|
+
if (childLength === 0) childClass = 'empty';else if (childLength > 1) childClass = 'multiple';
|
|
80
|
+
return /*#__PURE__*/jsxs("li", _objectSpread(_objectSpread({}, itemProps), {}, {
|
|
81
|
+
children: [/*#__PURE__*/jsx("div", _objectSpread(_objectSpread({
|
|
82
|
+
className: "nestable-item-name nestable-item-name--".concat(item.element.type, " ")
|
|
83
|
+
}, rowProps), {}, {
|
|
84
|
+
children: renderItem({
|
|
85
|
+
item,
|
|
86
|
+
handler: Handler,
|
|
87
|
+
index
|
|
88
|
+
})
|
|
89
|
+
})), hasChildren && item.element.type === 'group' && !isCollapsed && /*#__PURE__*/_jsx("ol", {
|
|
90
|
+
className: "nestable-list nestable-child-count-".concat(childClass, " ")
|
|
91
|
+
}, void 0, item[childrenProp].map((currentitem, i) => /*#__PURE__*/_jsx(NestableItem, {
|
|
92
|
+
index: i,
|
|
93
|
+
isAndItem: isAndGroup,
|
|
94
|
+
isCopy: isCopy,
|
|
95
|
+
isOrItem: isOrGroup,
|
|
96
|
+
item: currentitem,
|
|
97
|
+
options: options,
|
|
98
|
+
singleRow: singleRow
|
|
99
|
+
}, i)))]
|
|
100
|
+
}));
|
|
89
101
|
};
|
|
90
|
-
|
|
102
|
+
|
|
103
|
+
export { NestableItem as default };
|
|
@@ -1,72 +1,91 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
6
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
7
|
+
import { closest, getTransformProps, getOffsetRect, getTotalScroll } from '@elliemae/ds-shared/utils';
|
|
8
|
+
|
|
9
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
+
|
|
11
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
8
12
|
function onDragStart(e, item) {
|
|
9
13
|
if (e) {
|
|
10
14
|
e.preventDefault();
|
|
11
15
|
e.stopPropagation();
|
|
12
16
|
}
|
|
13
|
-
|
|
17
|
+
|
|
18
|
+
this.el = closest(e.target, '.nestable-item');
|
|
14
19
|
this.startTrackMouse();
|
|
15
20
|
this.onMouseMove(e);
|
|
16
|
-
const {
|
|
21
|
+
const {
|
|
22
|
+
items
|
|
23
|
+
} = this.state;
|
|
17
24
|
this.setState({
|
|
18
25
|
dragItem: item,
|
|
19
26
|
itemsOld: items
|
|
20
27
|
});
|
|
21
28
|
}
|
|
22
29
|
function onDragEnd(e, isCancel) {
|
|
23
|
-
if (e && e.preventDefault)
|
|
24
|
-
e.preventDefault();
|
|
30
|
+
if (e && e.preventDefault) e.preventDefault();
|
|
25
31
|
this.stopTrackMouse();
|
|
26
|
-
this.el = null;
|
|
27
|
-
|
|
32
|
+
this.el = null; // check if filter has children
|
|
33
|
+
|
|
34
|
+
const {
|
|
35
|
+
items
|
|
36
|
+
} = this.state;
|
|
28
37
|
const nestedInFilter = this.checkFilterChildren(items);
|
|
29
|
-
if (nestedInFilter)
|
|
30
|
-
return this.dragRevert();
|
|
38
|
+
if (nestedInFilter) return this.dragRevert();
|
|
31
39
|
return isCancel ? this.dragRevert() : this.dragApply();
|
|
32
40
|
}
|
|
33
41
|
function onMouseMove(e) {
|
|
34
|
-
const {
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
const {
|
|
43
|
+
group,
|
|
44
|
+
threshold
|
|
45
|
+
} = this.props;
|
|
46
|
+
const {
|
|
47
|
+
dragItem
|
|
48
|
+
} = this.state;
|
|
49
|
+
const {
|
|
50
|
+
clientX,
|
|
51
|
+
clientY
|
|
52
|
+
} = e;
|
|
37
53
|
const transformProps = getTransformProps(clientX, clientY);
|
|
38
|
-
const elCopy = document.querySelector(
|
|
54
|
+
const elCopy = document.querySelector(".nestable-".concat(group, " .nestable-drag-layer > .nestable-list"));
|
|
55
|
+
|
|
39
56
|
if (!this.elCopyStyles) {
|
|
40
57
|
const offset = getOffsetRect(this.el);
|
|
41
58
|
const scroll = getTotalScroll(this.el);
|
|
42
|
-
this.elCopyStyles = {
|
|
59
|
+
this.elCopyStyles = _objectSpread({
|
|
43
60
|
marginTop: offset.top - clientY - scroll.top,
|
|
44
|
-
marginLeft: offset.left - clientX - scroll.left
|
|
45
|
-
|
|
46
|
-
};
|
|
61
|
+
marginLeft: offset.left - clientX - scroll.left
|
|
62
|
+
}, transformProps);
|
|
47
63
|
} else {
|
|
48
|
-
this.elCopyStyles = {
|
|
49
|
-
|
|
50
|
-
...transformProps
|
|
51
|
-
};
|
|
64
|
+
this.elCopyStyles = _objectSpread(_objectSpread({}, this.elCopyStyles), transformProps);
|
|
65
|
+
|
|
52
66
|
for (const key in transformProps) {
|
|
53
67
|
if (transformProps.hasOwnProperty(key)) {
|
|
54
68
|
elCopy.style[key] = transformProps[key];
|
|
55
69
|
}
|
|
56
70
|
}
|
|
71
|
+
|
|
57
72
|
const diffX = clientX - this.mouse.last.x;
|
|
73
|
+
|
|
58
74
|
if (diffX >= 0 && this.mouse.shift.x >= 0 || diffX <= 0 && this.mouse.shift.x <= 0) {
|
|
59
75
|
this.mouse.shift.x += diffX;
|
|
60
76
|
} else {
|
|
61
77
|
this.mouse.shift.x = 0;
|
|
62
78
|
}
|
|
79
|
+
|
|
63
80
|
this.mouse.last.x = clientX;
|
|
81
|
+
|
|
64
82
|
if (Math.abs(this.mouse.shift.x) > threshold) {
|
|
65
83
|
if (this.mouse.shift.x > 0) {
|
|
66
84
|
this.tryIncreaseDepth(dragItem);
|
|
67
85
|
} else {
|
|
68
86
|
this.tryDecreaseDepth(dragItem);
|
|
69
87
|
}
|
|
88
|
+
|
|
70
89
|
this.mouse.shift.x = 0;
|
|
71
90
|
}
|
|
72
91
|
}
|
|
@@ -76,44 +95,59 @@ function onMouseEnter(e, item) {
|
|
|
76
95
|
e.preventDefault();
|
|
77
96
|
e.stopPropagation();
|
|
78
97
|
}
|
|
79
|
-
|
|
80
|
-
const {
|
|
81
|
-
|
|
82
|
-
|
|
98
|
+
|
|
99
|
+
const {
|
|
100
|
+
collapsed,
|
|
101
|
+
childrenProp
|
|
102
|
+
} = this.props;
|
|
103
|
+
const {
|
|
104
|
+
dragItem
|
|
105
|
+
} = this.state;
|
|
106
|
+
if (dragItem.id === item.id) return;
|
|
83
107
|
const pathFrom = this.getPathById(dragItem.id);
|
|
84
|
-
const pathTo = this.getPathById(item.id);
|
|
108
|
+
const pathTo = this.getPathById(item.id); // if collapsed by default
|
|
109
|
+
// and move last (by count) child
|
|
110
|
+
// remove parent node from list of open nodes
|
|
111
|
+
|
|
85
112
|
let collapseProps = {};
|
|
113
|
+
|
|
86
114
|
if (collapsed && pathFrom.length > 1) {
|
|
87
115
|
const parent = this.getItemByPath(pathFrom.slice(0, -1));
|
|
116
|
+
|
|
88
117
|
if (parent[childrenProp].length === 1) {
|
|
89
118
|
collapseProps = this.onToggleCollapse(parent, true);
|
|
90
119
|
}
|
|
91
120
|
}
|
|
92
|
-
|
|
121
|
+
|
|
122
|
+
this.moveItem({
|
|
123
|
+
dragItem,
|
|
124
|
+
pathFrom,
|
|
125
|
+
pathTo
|
|
126
|
+
}, collapseProps);
|
|
93
127
|
}
|
|
94
128
|
function onToggleCollapse(item, isGetter) {
|
|
95
|
-
const {
|
|
96
|
-
|
|
129
|
+
const {
|
|
130
|
+
collapsed
|
|
131
|
+
} = this.props;
|
|
132
|
+
const {
|
|
133
|
+
collapsedGroups
|
|
134
|
+
} = this.state;
|
|
97
135
|
const isCollapsed = this.isCollapsed(item);
|
|
98
136
|
const newState = {
|
|
99
|
-
collapsedGroups: isCollapsed ^ collapsed ? collapsedGroups.filter(
|
|
137
|
+
collapsedGroups: isCollapsed ^ collapsed ? collapsedGroups.filter(id => id !== item.id) : collapsedGroups.concat(item.id)
|
|
100
138
|
};
|
|
139
|
+
|
|
101
140
|
if (isGetter) {
|
|
102
141
|
return newState;
|
|
103
142
|
}
|
|
143
|
+
|
|
104
144
|
return this.setState(newState);
|
|
105
145
|
}
|
|
106
146
|
function onKeyDown(e) {
|
|
107
147
|
if (e.which === 27) {
|
|
148
|
+
// ESC
|
|
108
149
|
this.onDragEnd(null, true);
|
|
109
150
|
}
|
|
110
151
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
onDragStart,
|
|
114
|
-
onKeyDown,
|
|
115
|
-
onMouseEnter,
|
|
116
|
-
onMouseMove,
|
|
117
|
-
onToggleCollapse
|
|
118
|
-
};
|
|
119
|
-
//# sourceMappingURL=events.js.map
|
|
152
|
+
|
|
153
|
+
export { onDragEnd, onDragStart, onKeyDown, onMouseEnter, onMouseMove, onToggleCollapse };
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
1
|
function getItemOptions() {
|
|
3
|
-
const {
|
|
4
|
-
|
|
2
|
+
const {
|
|
3
|
+
renderItem,
|
|
4
|
+
renderCollapseIcon,
|
|
5
|
+
handler,
|
|
6
|
+
childrenProp
|
|
7
|
+
} = this.props;
|
|
8
|
+
const {
|
|
9
|
+
dragItem
|
|
10
|
+
} = this.state;
|
|
5
11
|
return {
|
|
6
12
|
dragItem,
|
|
7
13
|
childrenProp,
|
|
@@ -14,7 +20,5 @@ function getItemOptions() {
|
|
|
14
20
|
onToggleCollapse: this.onToggleCollapse
|
|
15
21
|
};
|
|
16
22
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=getItemOptions.js.map
|
|
23
|
+
|
|
24
|
+
export { getItemOptions };
|
|
@@ -1,69 +1,99 @@
|
|
|
1
|
-
import
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.map.js';
|
|
3
|
+
import 'core-js/modules/esnext.async-iterator.every.js';
|
|
4
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.every.js';
|
|
6
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
7
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
8
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
9
|
+
|
|
2
10
|
function getRealNextPath(prevPath, nextPath) {
|
|
3
|
-
const {
|
|
11
|
+
const {
|
|
12
|
+
childrenProp
|
|
13
|
+
} = this.props;
|
|
4
14
|
const ppLastIndex = prevPath.length - 1;
|
|
5
15
|
const npLastIndex = nextPath.length - 1;
|
|
16
|
+
|
|
6
17
|
if (prevPath.length < nextPath.length) {
|
|
18
|
+
// move into deep
|
|
7
19
|
let wasShifted = false;
|
|
8
20
|
return nextPath.map((nextIndex, i) => {
|
|
9
21
|
if (wasShifted) {
|
|
10
22
|
return i === npLastIndex ? nextIndex + 1 : nextIndex;
|
|
11
23
|
}
|
|
12
|
-
|
|
24
|
+
|
|
25
|
+
if (typeof prevPath[i] !== 'number') {
|
|
13
26
|
return nextIndex;
|
|
14
27
|
}
|
|
28
|
+
|
|
15
29
|
if (nextPath[i] > prevPath[i] && i === ppLastIndex) {
|
|
16
30
|
wasShifted = true;
|
|
17
31
|
return nextIndex - 1;
|
|
18
32
|
}
|
|
33
|
+
|
|
19
34
|
return nextIndex;
|
|
20
35
|
});
|
|
21
36
|
}
|
|
37
|
+
|
|
22
38
|
if (prevPath.length === nextPath.length) {
|
|
39
|
+
// if move bottom + move to item with children => make it a first child instead of swap
|
|
23
40
|
if (nextPath[npLastIndex] > prevPath[npLastIndex]) {
|
|
24
41
|
const target = this.getItemByPath(nextPath);
|
|
42
|
+
|
|
25
43
|
if (target[childrenProp] && target[childrenProp].length && !this.isCollapsed(target)) {
|
|
26
44
|
return nextPath.slice(0, -1).concat(nextPath[npLastIndex] - 1).concat(0);
|
|
27
45
|
}
|
|
28
46
|
}
|
|
29
47
|
}
|
|
48
|
+
|
|
30
49
|
return nextPath;
|
|
31
50
|
}
|
|
32
51
|
function getPathById(id, items) {
|
|
33
|
-
const {
|
|
52
|
+
const {
|
|
53
|
+
childrenProp
|
|
54
|
+
} = this.props;
|
|
34
55
|
let path = [];
|
|
35
56
|
items.every((item, i) => {
|
|
36
57
|
if (item.id === id) {
|
|
37
58
|
path.push(i);
|
|
38
59
|
} else if (item[childrenProp]) {
|
|
39
60
|
const childrenPath = this.getPathById(id, item[childrenProp]);
|
|
61
|
+
|
|
40
62
|
if (childrenPath.length) {
|
|
41
63
|
path = path.concat(i).concat(childrenPath);
|
|
42
64
|
}
|
|
43
65
|
}
|
|
66
|
+
|
|
44
67
|
return path.length === 0;
|
|
45
68
|
});
|
|
46
69
|
return path;
|
|
47
70
|
}
|
|
48
71
|
function getItemByPath(path, items) {
|
|
49
|
-
const {
|
|
72
|
+
const {
|
|
73
|
+
childrenProp
|
|
74
|
+
} = this.props;
|
|
50
75
|
let item = null;
|
|
51
|
-
path.forEach(
|
|
76
|
+
path.forEach(index => {
|
|
52
77
|
const list = item ? item[childrenProp] : items;
|
|
53
78
|
item = list[index];
|
|
54
79
|
});
|
|
55
80
|
return item;
|
|
56
81
|
}
|
|
57
82
|
function getItemDepth(item) {
|
|
58
|
-
const {
|
|
83
|
+
const {
|
|
84
|
+
childrenProp
|
|
85
|
+
} = this.props;
|
|
59
86
|
let level = 1;
|
|
87
|
+
|
|
60
88
|
if (item[childrenProp].length > 0) {
|
|
61
89
|
const childrenDepths = item[childrenProp].map(this.getItemDepth);
|
|
62
90
|
level += Math.max(...childrenDepths);
|
|
63
91
|
}
|
|
92
|
+
|
|
64
93
|
return level;
|
|
65
94
|
}
|
|
66
|
-
function getSplicePath(path
|
|
95
|
+
function getSplicePath(path) {
|
|
96
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
67
97
|
const splicePath = {};
|
|
68
98
|
const numToRemove = options.numToRemove || 0;
|
|
69
99
|
const itemsToInsert = options.itemsToInsert || [];
|
|
@@ -74,17 +104,13 @@ function getSplicePath(path, options = {}) {
|
|
|
74
104
|
currentPath.$splice = [[index, numToRemove, ...itemsToInsert]];
|
|
75
105
|
} else {
|
|
76
106
|
const nextPath = {};
|
|
77
|
-
currentPath[index] = {
|
|
107
|
+
currentPath[index] = {
|
|
108
|
+
[options.childrenProp]: nextPath
|
|
109
|
+
};
|
|
78
110
|
currentPath = nextPath;
|
|
79
111
|
}
|
|
80
112
|
});
|
|
81
113
|
return splicePath;
|
|
82
114
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
getItemDepth,
|
|
86
|
-
getPathById,
|
|
87
|
-
getRealNextPath,
|
|
88
|
-
getSplicePath
|
|
89
|
-
};
|
|
90
|
-
//# sourceMappingURL=getPaths.js.map
|
|
115
|
+
|
|
116
|
+
export { getItemByPath, getItemDepth, getPathById, getRealNextPath, getSplicePath };
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export * from "./getItemOptions";
|
|
8
|
-
export {
|
|
9
|
-
moveItem,
|
|
10
|
-
tryDecreaseDepth,
|
|
11
|
-
tryIncreaseDepth
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { tryIncreaseDepth } from './tryIncreaseDepth.js';
|
|
2
|
+
export { tryDecreaseDepth } from './tryDecreaseDepth.js';
|
|
3
|
+
export { moveItem } from './moveItem.js';
|
|
4
|
+
export { getItemByPath, getItemDepth, getPathById, getRealNextPath, getSplicePath } from './paths.js';
|
|
5
|
+
export { onDragEnd, onDragStart, onKeyDown, onMouseEnter, onMouseMove, onToggleCollapse } from './events.js';
|
|
6
|
+
export { getItemOptions } from './getItemOptions.js';
|
|
@@ -1,8 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
7
|
+
import update from 'react-addons-update';
|
|
8
|
+
|
|
9
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
+
|
|
11
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
12
|
+
function moveItem(_ref) {
|
|
13
|
+
let {
|
|
14
|
+
dragItem,
|
|
15
|
+
pathFrom,
|
|
16
|
+
pathTo
|
|
17
|
+
} = _ref;
|
|
18
|
+
let extraProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
19
|
+
const {
|
|
20
|
+
childrenProp
|
|
21
|
+
} = this.props;
|
|
22
|
+
let {
|
|
23
|
+
items
|
|
24
|
+
} = this.state; // the remove action might affect the next position,
|
|
25
|
+
// so update next coordinates accordingly
|
|
26
|
+
|
|
6
27
|
const realPathTo = this.getRealNextPath(pathFrom, pathTo);
|
|
7
28
|
const removePath = this.getSplicePath(pathFrom, {
|
|
8
29
|
numToRemove: 1,
|
|
@@ -15,13 +36,10 @@ function moveItem({ dragItem, pathFrom, pathTo }, extraProps = {}) {
|
|
|
15
36
|
});
|
|
16
37
|
items = update(items, removePath);
|
|
17
38
|
items = update(items, insertPath);
|
|
18
|
-
this.setState({
|
|
39
|
+
this.setState(_objectSpread({
|
|
19
40
|
items,
|
|
20
|
-
isDirty: true
|
|
21
|
-
|
|
22
|
-
});
|
|
41
|
+
isDirty: true
|
|
42
|
+
}, extraProps));
|
|
23
43
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=moveItem.js.map
|
|
44
|
+
|
|
45
|
+
export { moveItem };
|