@opentiny/vue-renderless 3.1.0-alpha.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.
- package/action-sheet/index.js +28 -0
- package/action-sheet/vue.js +29 -0
- package/alert/index.js +23 -0
- package/alert/vue.js +37 -0
- package/autocomplete/index.js +175 -0
- package/autocomplete/vue.js +171 -0
- package/avatar/index.js +29 -0
- package/avatar/vue.js +24 -0
- package/badge/index.js +16 -0
- package/badge/vue.js +30 -0
- package/breadcrumb/vue.js +4 -0
- package/breadcrumb-item/vue.js +24 -0
- package/bulletin-board/index.js +21 -0
- package/bulletin-board/vue.js +36 -0
- package/button/index.js +19 -0
- package/button/vue.js +43 -0
- package/button-group/index.js +25 -0
- package/button-group/vue.js +51 -0
- package/calendar/index.js +279 -0
- package/calendar/vue.js +124 -0
- package/card-template/index.js +39 -0
- package/card-template/vue.js +34 -0
- package/carousel/index.js +206 -0
- package/carousel/vue.js +222 -0
- package/carousel-item/index.js +93 -0
- package/carousel-item/vue.js +57 -0
- package/cascader/index.js +511 -0
- package/cascader/vue.js +342 -0
- package/cascader-menu/index.js +41 -0
- package/cascader-menu/vue.js +36 -0
- package/cascader-node/index.js +63 -0
- package/cascader-node/vue.js +62 -0
- package/cascader-panel/index.js +359 -0
- package/cascader-panel/node.js +199 -0
- package/cascader-panel/store.js +80 -0
- package/cascader-panel/vue.js +217 -0
- package/checkbox/index.js +145 -0
- package/checkbox/vue.js +139 -0
- package/checkbox-button/index.js +102 -0
- package/checkbox-button/vue.js +150 -0
- package/checkbox-group/index.js +12 -0
- package/checkbox-group/vue.js +33 -0
- package/col/index.js +132 -0
- package/col/vue.js +34 -0
- package/collapse/index.js +45 -0
- package/collapse/vue.js +35 -0
- package/collapse-item/index.js +38 -0
- package/collapse-item/vue.js +48 -0
- package/common/array.js +120 -0
- package/common/bigInt.js +352 -0
- package/common/browser.js +69 -0
- package/common/dataset/index.js +135 -0
- package/common/date.js +352 -0
- package/common/decimal.js +203 -0
- package/common/deps/ResizeObserver.js +474 -0
- package/common/deps/after-leave.js +25 -0
- package/common/deps/clickoutside.js +61 -0
- package/common/deps/date-util.js +262 -0
- package/common/deps/date.js +308 -0
- package/common/deps/debounce.js +4 -0
- package/common/deps/dom.js +190 -0
- package/common/deps/fullscreen/apis.js +157 -0
- package/common/deps/fullscreen/screenfull.js +106 -0
- package/common/deps/letter-only.js +15 -0
- package/common/deps/memorize.js +149 -0
- package/common/deps/number-only.js +16 -0
- package/common/deps/popper.js +713 -0
- package/common/deps/popup-manager.js +179 -0
- package/common/deps/repeat-click.js +24 -0
- package/common/deps/requestAnimationFrame.js +25 -0
- package/common/deps/resize-event.js +29 -0
- package/common/deps/scroll-into-view.js +29 -0
- package/common/deps/scrollbar-width.js +25 -0
- package/common/deps/throttle.js +34 -0
- package/common/deps/touch.js +33 -0
- package/common/deps/tree-model/node.js +586 -0
- package/common/deps/tree-model/tree-store.js +377 -0
- package/common/deps/tree-model/util.js +14 -0
- package/common/deps/upload-ajax.js +71 -0
- package/common/deps/vue-emitter.js +30 -0
- package/common/deps/vue-popper.js +291 -0
- package/common/deps/vue-popup.js +211 -0
- package/common/event.js +17 -0
- package/common/index.js +288 -0
- package/common/object.js +228 -0
- package/common/runtime.js +52 -0
- package/common/string.js +446 -0
- package/common/type.js +65 -0
- package/common/validate/index.js +6 -0
- package/common/validate/messages.js +68 -0
- package/common/validate/rules/enum.js +8 -0
- package/common/validate/rules/index.js +14 -0
- package/common/validate/rules/pattern.js +16 -0
- package/common/validate/rules/range.js +62 -0
- package/common/validate/rules/required.js +13 -0
- package/common/validate/rules/type.js +110 -0
- package/common/validate/rules/whitespace.js +6 -0
- package/common/validate/schema.js +323 -0
- package/common/validate/util.js +198 -0
- package/common/validate/validations/array.js +25 -0
- package/common/validate/validations/date.js +35 -0
- package/common/validate/validations/enum.js +24 -0
- package/common/validate/validations/float.js +24 -0
- package/common/validate/validations/index.js +42 -0
- package/common/validate/validations/integer.js +24 -0
- package/common/validate/validations/method.js +23 -0
- package/common/validate/validations/number.js +27 -0
- package/common/validate/validations/pattern.js +23 -0
- package/common/validate/validations/required.js +15 -0
- package/common/validate/validations/string.js +29 -0
- package/common/validate/validations/type.js +25 -0
- package/common/xss.js +325 -0
- package/container/index.js +110 -0
- package/container/vue.js +63 -0
- package/credit-card/index.js +107 -0
- package/credit-card/vue.js +117 -0
- package/credit-card-form/index.js +143 -0
- package/credit-card-form/vue.js +150 -0
- package/crop/index.js +297 -0
- package/crop/vue.js +191 -0
- package/date-panel/index.js +584 -0
- package/date-panel/vue.js +319 -0
- package/date-picker/index.js +301 -0
- package/date-picker/vue.js +169 -0
- package/date-range/index.js +463 -0
- package/date-range/vue.js +297 -0
- package/date-table/index.js +457 -0
- package/date-table/vue.js +151 -0
- package/detail-page/index.js +135 -0
- package/detail-page/vue.js +145 -0
- package/dialog-box/index.js +268 -0
- package/dialog-box/vue.js +226 -0
- package/drop-times/index.js +23 -0
- package/drop-times/vue.js +28 -0
- package/dropdown/index.js +259 -0
- package/dropdown/vue.js +107 -0
- package/dropdown-item/index.js +155 -0
- package/dropdown-item/vue.js +124 -0
- package/dropdown-menu/index.js +148 -0
- package/dropdown-menu/vue.js +44 -0
- package/exception/index.js +13 -0
- package/exception/vue.js +25 -0
- package/fall-menu/index.js +121 -0
- package/fall-menu/vue.js +90 -0
- package/file-upload/index.js +1940 -0
- package/file-upload/vue.js +458 -0
- package/floatbar/index.js +10 -0
- package/floatbar/vue.js +17 -0
- package/form/index.js +186 -0
- package/form/vue.js +69 -0
- package/form-item/index.js +364 -0
- package/form-item/vue.js +210 -0
- package/fullscreen/index.js +138 -0
- package/fullscreen/vue.js +77 -0
- package/grid/core/index.js +3 -0
- package/grid/core/interceptor.js +38 -0
- package/grid/core/storeMap.js +19 -0
- package/grid/plugins/export.js +169 -0
- package/grid/plugins/exportExcel.js +749 -0
- package/grid/plugins/header.js +58 -0
- package/grid/plugins/resize.js +82 -0
- package/grid/static/array/arrayEach.js +12 -0
- package/grid/static/array/arrayIndexOf.js +11 -0
- package/grid/static/array/eachTree.js +32 -0
- package/grid/static/array/every.js +2 -0
- package/grid/static/array/filterTree.js +16 -0
- package/grid/static/array/find.js +3 -0
- package/grid/static/array/findTree.js +46 -0
- package/grid/static/array/helperCreateIterateHandle.js +59 -0
- package/grid/static/array/helperCreateTreeFunc.js +18 -0
- package/grid/static/array/includes.js +5 -0
- package/grid/static/array/lastArrayEach.js +6 -0
- package/grid/static/array/map.js +23 -0
- package/grid/static/array/mapTree.js +33 -0
- package/grid/static/array/slice.js +10 -0
- package/grid/static/array/sortBy.js +69 -0
- package/grid/static/array/sum.js +28 -0
- package/grid/static/array/toArray.js +7 -0
- package/grid/static/array/toTreeArray.js +24 -0
- package/grid/static/base/clear.js +44 -0
- package/grid/static/base/clone.js +18 -0
- package/grid/static/base/destructuring.js +18 -0
- package/grid/static/base/each.js +9 -0
- package/grid/static/base/eqNull.js +6 -0
- package/grid/static/base/findIndexOf.js +10 -0
- package/grid/static/base/get.js +42 -0
- package/grid/static/base/has.js +60 -0
- package/grid/static/base/hasOwnProp.js +4 -0
- package/grid/static/base/helperCreateGetObjects.js +26 -0
- package/grid/static/base/helperCreateInInObjectString.js +7 -0
- package/grid/static/base/helperCreateInTypeof.js +6 -0
- package/grid/static/base/helperCreateIndexOf.js +21 -0
- package/grid/static/base/helperCreateiterateIndexOf.js +21 -0
- package/grid/static/base/helperDefaultCompare.js +4 -0
- package/grid/static/base/helperDeleteProperty.js +8 -0
- package/grid/static/base/helperEqualCompare.js +60 -0
- package/grid/static/base/helperGetHGSKeys.js +4 -0
- package/grid/static/base/indexOf.js +3 -0
- package/grid/static/base/isArray.js +3 -0
- package/grid/static/base/isBoolean.js +4 -0
- package/grid/static/base/isDate.js +3 -0
- package/grid/static/base/isEmpty.js +8 -0
- package/grid/static/base/isEqual.js +11 -0
- package/grid/static/base/isFunction.js +4 -0
- package/grid/static/base/isNaN.js +5 -0
- package/grid/static/base/isNull.js +4 -0
- package/grid/static/base/isNumber.js +4 -0
- package/grid/static/base/isObject.js +5 -0
- package/grid/static/base/isPlainObject.js +2 -0
- package/grid/static/base/isRegExp.js +3 -0
- package/grid/static/base/isSet.js +5 -0
- package/grid/static/base/isString.js +4 -0
- package/grid/static/base/isUndefined.js +4 -0
- package/grid/static/base/keys.js +3 -0
- package/grid/static/base/lastEach.js +9 -0
- package/grid/static/base/remove.js +44 -0
- package/grid/static/base/set.js +43 -0
- package/grid/static/base/toJSONString.js +4 -0
- package/grid/static/base/toStringJSON.js +13 -0
- package/grid/static/base/uniqueId.js +5 -0
- package/grid/static/browse/browse.js +54 -0
- package/grid/static/function/property.js +7 -0
- package/grid/static/function/throttle.js +43 -0
- package/grid/static/index.js +55 -0
- package/grid/static/number/helperCreateToNumber.js +12 -0
- package/grid/static/number/toNumber.js +3 -0
- package/grid/static/object/assign.js +41 -0
- package/grid/static/object/extend.js +3 -0
- package/grid/static/object/lastObjectEach.js +8 -0
- package/grid/static/object/objectEach.js +11 -0
- package/grid/static/object/objectMap.js +20 -0
- package/grid/static/object/values.js +9 -0
- package/grid/static/static/staticDocument.js +4 -0
- package/grid/static/static/staticHGKeyRE.js +2 -0
- package/grid/static/static/staticParseInt.js +2 -0
- package/grid/static/static/staticStrUndefined.js +2 -0
- package/grid/static/static/staticWindow.js +4 -0
- package/grid/static/string/template.js +12 -0
- package/grid/static/string/toString.js +12 -0
- package/grid/utils/column.js +72 -0
- package/grid/utils/common.js +155 -0
- package/grid/utils/dom.js +213 -0
- package/grid/utils/event.js +40 -0
- package/grid/utils/index.js +5 -0
- package/image/index.js +187 -0
- package/image/vue.js +142 -0
- package/image-viewer/index.js +469 -0
- package/image-viewer/vue.js +243 -0
- package/input/index.js +319 -0
- package/input/vue.js +319 -0
- package/ip-address/index.js +370 -0
- package/ip-address/vue.js +185 -0
- package/layout/vue.js +4 -0
- package/link/index.js +10 -0
- package/link/vue.js +26 -0
- package/link-menu/index.js +146 -0
- package/link-menu/vue.js +138 -0
- package/list/index.js +13 -0
- package/list/vue.js +17 -0
- package/loading/index.js +29 -0
- package/loading/vue.js +28 -0
- package/milestone/index.js +92 -0
- package/milestone/vue.js +31 -0
- package/mini-picker/index.js +227 -0
- package/mini-picker/vue.js +142 -0
- package/modal/index.js +866 -0
- package/modal/vue.js +130 -0
- package/month-range/index.js +169 -0
- package/month-range/vue.js +104 -0
- package/month-table/index.js +232 -0
- package/month-table/vue.js +72 -0
- package/nav-menu/index.js +457 -0
- package/nav-menu/vue.js +187 -0
- package/notify/index.js +91 -0
- package/notify/vue.js +67 -0
- package/numeric/index.js +419 -0
- package/numeric/vue.js +218 -0
- package/option/index.js +79 -0
- package/option/vue.js +219 -0
- package/option-group/index.js +18 -0
- package/option-group/vue.js +37 -0
- package/package.json +179 -0
- package/pager-item/index.js +122 -0
- package/pager-item/vue.js +52 -0
- package/panel/index.js +30 -0
- package/panel/vue.js +26 -0
- package/picker/index.js +1039 -0
- package/picker/timezone.js +974 -0
- package/picker/vue.js +415 -0
- package/picker-column/index.js +261 -0
- package/picker-column/vue.js +163 -0
- package/pop-upload/index.js +324 -0
- package/pop-upload/vue.js +292 -0
- package/popeditor/index.js +884 -0
- package/popeditor/vue.js +368 -0
- package/popover/index.js +203 -0
- package/popover/vue.js +174 -0
- package/popup/index.js +139 -0
- package/popup/vue.js +129 -0
- package/progress/index.js +174 -0
- package/progress/vue.js +118 -0
- package/pull-refresh/index.js +104 -0
- package/pull-refresh/vue.js +64 -0
- package/radio/index.js +83 -0
- package/radio/vue.js +99 -0
- package/radio-button/index.js +58 -0
- package/radio-button/vue.js +70 -0
- package/radio-group/index.js +51 -0
- package/radio-group/vue.js +34 -0
- package/rate/index.js +254 -0
- package/rate/vue.js +158 -0
- package/row/index.js +19 -0
- package/row/vue.js +24 -0
- package/scroll-text/index.js +24 -0
- package/scroll-text/vue.js +31 -0
- package/scrollbar/index.js +127 -0
- package/scrollbar/vue-bar.js +49 -0
- package/scrollbar/vue.js +43 -0
- package/search/index.js +110 -0
- package/search/vue.js +110 -0
- package/select/index.js +1766 -0
- package/select/vue.js +693 -0
- package/select-dropdown/index.js +23 -0
- package/select-dropdown/vue.js +122 -0
- package/slide-bar/index.js +94 -0
- package/slide-bar/vue.js +58 -0
- package/slider/index.js +434 -0
- package/slider/vue.js +172 -0
- package/split/index.js +122 -0
- package/split/vue.js +131 -0
- package/steps/vue.js +4 -0
- package/switch/index.js +45 -0
- package/switch/vue.js +62 -0
- package/tab-bar/index.js +51 -0
- package/tab-bar/vue.js +16 -0
- package/tab-dropdown/index.js +11 -0
- package/tab-dropdown/vue.js +17 -0
- package/tab-item/index.js +37 -0
- package/tab-item/vue.js +49 -0
- package/tab-nav/index.js +247 -0
- package/tab-nav/vue.js +106 -0
- package/tabbar/index.js +32 -0
- package/tabbar/vue.js +54 -0
- package/tabbar-item/index.js +55 -0
- package/tabbar-item/vue.js +53 -0
- package/table/index.js +111 -0
- package/table/vue.js +66 -0
- package/tabs/index.js +174 -0
- package/tabs/vue.js +141 -0
- package/tag/index.js +14 -0
- package/tag/vue.js +13 -0
- package/tall-storage/index.js +161 -0
- package/tall-storage/vue-storage-box.js +25 -0
- package/tall-storage/vue.js +38 -0
- package/text-popup/index.js +75 -0
- package/text-popup/vue.js +64 -0
- package/time/index.js +121 -0
- package/time/vue.js +124 -0
- package/time-line/index.js +60 -0
- package/time-line/vue.js +49 -0
- package/time-panel/index.js +189 -0
- package/time-panel/scrollIntoView.js +23 -0
- package/time-panel/vue.js +110 -0
- package/time-range/index.js +199 -0
- package/time-range/vue.js +129 -0
- package/time-spinner/index.js +175 -0
- package/time-spinner/vue.js +122 -0
- package/toggle-menu/index.js +104 -0
- package/toggle-menu/vue.js +74 -0
- package/tooltip/index.js +171 -0
- package/tooltip/vue.js +133 -0
- package/top-box/index.js +81 -0
- package/top-box/vue.js +77 -0
- package/transfer/index.js +296 -0
- package/transfer/vue.js +138 -0
- package/transfer-panel/index.js +364 -0
- package/transfer-panel/vue.js +258 -0
- package/tree/index.js +642 -0
- package/tree/vue.js +268 -0
- package/tree-menu/index.js +124 -0
- package/tree-menu/vue.js +60 -0
- package/tree-node/index.js +271 -0
- package/tree-node/vue.js +211 -0
- package/upload/index.js +324 -0
- package/upload/vue.js +93 -0
- package/upload-dragger/index.js +50 -0
- package/upload-dragger/vue.js +27 -0
- package/upload-list/index.js +55 -0
- package/upload-list/vue.js +48 -0
- package/user-contact/index.js +13 -0
- package/user-contact/vue.js +20 -0
- package/user-head/index.js +71 -0
- package/user-head/vue.js +47 -0
- package/wizard/index.js +123 -0
- package/wizard/vue.js +45 -0
- package/year-table/index.js +40 -0
- package/year-table/vue.js +23 -0
package/tree/index.js
ADDED
|
@@ -0,0 +1,642 @@
|
|
|
1
|
+
import { getNodeKey as innerGetNodekey } from '@opentiny/vue-renderless/common/deps/tree-model/util';
|
|
2
|
+
import { KEY_CODE } from '@opentiny/vue-renderless/common';
|
|
3
|
+
import TreeStore from '@opentiny/vue-renderless/common/deps/tree-model/tree-store';
|
|
4
|
+
import { addClass, removeClass } from '@opentiny/vue-renderless/common/deps/dom';
|
|
5
|
+
import { on, off } from '@opentiny/vue-renderless/common/deps/dom';
|
|
6
|
+
import { getDataset } from '@opentiny/vue-renderless/common/dataset';
|
|
7
|
+
export var setChildren = function setChildren(props) {
|
|
8
|
+
return function (data) {
|
|
9
|
+
return props.data = data;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export var getChildren = function getChildren() {
|
|
13
|
+
return function (props) {
|
|
14
|
+
return props.data;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export var computedTreeItemArray = function computedTreeItemArray() {
|
|
18
|
+
return function (props, state) {
|
|
19
|
+
return Array.prototype.slice.call(state.treeItems);
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export var computedShowEmptyText = function computedShowEmptyText(_ref) {
|
|
23
|
+
var constants = _ref.constants,
|
|
24
|
+
t = _ref.t;
|
|
25
|
+
return function (props) {
|
|
26
|
+
return props.emptyText || t(constants.EMPTY_TEXT_LOCAL);
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export var computedIsEmpty = function computedIsEmpty() {
|
|
30
|
+
return function (props, state) {
|
|
31
|
+
var childNodes = state.root.childNodes;
|
|
32
|
+
return !childNodes || childNodes.length === 0 || childNodes.every(function (_ref2) {
|
|
33
|
+
var visible = _ref2.visible;
|
|
34
|
+
return !visible;
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export var watchDefaultCheckedKeys = function watchDefaultCheckedKeys(state) {
|
|
39
|
+
return function (value) {
|
|
40
|
+
state.store.setDefaultCheckedKey(value);
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export var watchDefaultExpandedKeys = function watchDefaultExpandedKeys(_ref3) {
|
|
44
|
+
var state = _ref3.state,
|
|
45
|
+
api = _ref3.api,
|
|
46
|
+
nextTick = _ref3.nextTick;
|
|
47
|
+
return function (value) {
|
|
48
|
+
api.expandAllNodes(false);
|
|
49
|
+
nextTick(function () {
|
|
50
|
+
state.store.defaultExpandedKeys = value;
|
|
51
|
+
state.store.setDefaultExpandedKeys(value);
|
|
52
|
+
api.initIsCurrent();
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export var watchData = function watchData(state) {
|
|
57
|
+
return function (value) {
|
|
58
|
+
state.store.setData(value);
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export var watchCheckboxItems = function watchCheckboxItems() {
|
|
62
|
+
return function (value) {
|
|
63
|
+
Array.prototype.forEach.call(value, function (checkbox) {
|
|
64
|
+
checkbox.setAttribute('tabindex', -1);
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export var watchCheckStrictly = function watchCheckStrictly(state) {
|
|
69
|
+
return function (value) {
|
|
70
|
+
state.store.checkStrictly = value;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
export var dragStart = function dragStart(_ref4) {
|
|
74
|
+
var props = _ref4.props,
|
|
75
|
+
state = _ref4.state,
|
|
76
|
+
emit = _ref4.emit;
|
|
77
|
+
return function (event, treeNode) {
|
|
78
|
+
if (typeof props.allowDrag === 'function' && !props.allowDrag(treeNode.node)) {
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (!event.dataTransfer) return false;
|
|
83
|
+
event.dataTransfer.effectAllowed = 'move';
|
|
84
|
+
try {
|
|
85
|
+
event.dataTransfer.setData('text/plain', '');
|
|
86
|
+
} catch (e) {}
|
|
87
|
+
state.dragState.draggingNode = treeNode;
|
|
88
|
+
emit('node-drag-start', treeNode.node, event);
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
var getDropType = function getDropType(dropPrev, dropInner, dropNext, dropNode) {
|
|
92
|
+
var dropType;
|
|
93
|
+
var targetPosition = dropNode.$el.getBoundingClientRect();
|
|
94
|
+
var prevPercent = dropPrev ? dropInner ? 0.25 : dropNext ? 0.45 : 1 : -1;
|
|
95
|
+
var nextPercent = dropNext ? dropInner ? 0.75 : dropPrev ? 0.55 : 0 : 1;
|
|
96
|
+
var distance = event.clientY - targetPosition.top;
|
|
97
|
+
if (distance < targetPosition.height * prevPercent) {
|
|
98
|
+
dropType = 'before';
|
|
99
|
+
} else if (distance > targetPosition.height * nextPercent) {
|
|
100
|
+
dropType = 'after';
|
|
101
|
+
} else if (dropInner) {
|
|
102
|
+
dropType = 'inner';
|
|
103
|
+
} else {
|
|
104
|
+
dropType = 'none';
|
|
105
|
+
}
|
|
106
|
+
return dropType;
|
|
107
|
+
};
|
|
108
|
+
var setDropIndicatorTop = function setDropIndicatorTop(dropNode, dropIndicator, parent, dropType) {
|
|
109
|
+
var iconElement = dropNode.$el.querySelector('.tiny-tree-node');
|
|
110
|
+
if (iconElement) {
|
|
111
|
+
var treePosition = parent.$el.getBoundingClientRect();
|
|
112
|
+
var iconPosition = iconElement.getBoundingClientRect();
|
|
113
|
+
var indicatorTop = -9999;
|
|
114
|
+
if (dropType === 'before') {
|
|
115
|
+
indicatorTop = iconPosition.top - treePosition.top;
|
|
116
|
+
} else if (dropType === 'after') {
|
|
117
|
+
indicatorTop = iconPosition.bottom - treePosition.top;
|
|
118
|
+
}
|
|
119
|
+
dropIndicator.style.top = indicatorTop + 'px';
|
|
120
|
+
}
|
|
121
|
+
dropType === 'inner' ? addClass(dropNode.$el, 'is-drop-inner') : removeClass(dropNode.$el, 'is-drop-inner');
|
|
122
|
+
};
|
|
123
|
+
var getDragDir = function getDragDir(_ref5) {
|
|
124
|
+
var draggingNode = _ref5.draggingNode,
|
|
125
|
+
dropNode = _ref5.dropNode,
|
|
126
|
+
allowDrop = _ref5.allowDrop,
|
|
127
|
+
emit = _ref5.emit,
|
|
128
|
+
dragState = _ref5.dragState;
|
|
129
|
+
var dropPrev = true;
|
|
130
|
+
var dropInner = true;
|
|
131
|
+
var dropNext = true;
|
|
132
|
+
var userAllowDropInner = true;
|
|
133
|
+
var oldDropNode = dragState.dropNode;
|
|
134
|
+
if (typeof allowDrop === 'function') {
|
|
135
|
+
dropPrev = allowDrop(draggingNode.node, dropNode.node, 'prev');
|
|
136
|
+
userAllowDropInner = dropInner = allowDrop(draggingNode.node, dropNode.node, 'inner');
|
|
137
|
+
dropNext = allowDrop(draggingNode.node, dropNode.node, 'next');
|
|
138
|
+
}
|
|
139
|
+
event.dataTransfer.dropEffect = dropInner ? 'move' : 'none';
|
|
140
|
+
if ((dropPrev || dropInner || dropNext) && oldDropNode !== dropNode) {
|
|
141
|
+
oldDropNode && emit('node-drag-leave', draggingNode.node, oldDropNode.node, event);
|
|
142
|
+
emit('node-drag-enter', draggingNode.node, dropNode.node, event);
|
|
143
|
+
}
|
|
144
|
+
if (dropPrev || dropInner || dropNext) {
|
|
145
|
+
dragState.dropNode = dropNode;
|
|
146
|
+
}
|
|
147
|
+
if (dropNode.node.previousSibling === draggingNode.node) {
|
|
148
|
+
dropPrev = false;
|
|
149
|
+
}
|
|
150
|
+
if (dropNode.node.nextSibling === draggingNode.node) {
|
|
151
|
+
dropNext = false;
|
|
152
|
+
}
|
|
153
|
+
if (dropNode.node.contains(draggingNode.node, false)) {
|
|
154
|
+
dropInner = false;
|
|
155
|
+
}
|
|
156
|
+
if (draggingNode.node === dropNode.node || draggingNode.node.contains(dropNode.node)) {
|
|
157
|
+
dropPrev = false;
|
|
158
|
+
dropInner = false;
|
|
159
|
+
dropNext = false;
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
dropPrev: dropPrev,
|
|
163
|
+
dropInner: dropInner,
|
|
164
|
+
dropNext: dropNext,
|
|
165
|
+
userAllowDropInner: userAllowDropInner
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
export var dragOver = function dragOver(_ref6) {
|
|
169
|
+
var state = _ref6.state,
|
|
170
|
+
emit = _ref6.emit,
|
|
171
|
+
props = _ref6.props,
|
|
172
|
+
refs = _ref6.refs,
|
|
173
|
+
vm = _ref6.vm;
|
|
174
|
+
return function (event, dropNode) {
|
|
175
|
+
var dragState = state.dragState;
|
|
176
|
+
var oldDropNode = dragState.dropNode;
|
|
177
|
+
if (oldDropNode && oldDropNode !== dropNode) {
|
|
178
|
+
removeClass(oldDropNode.$el, 'is-drop-inner');
|
|
179
|
+
}
|
|
180
|
+
var draggingNode = dragState.draggingNode;
|
|
181
|
+
if (!draggingNode || !dropNode) return;
|
|
182
|
+
var _getDragDir = getDragDir({
|
|
183
|
+
draggingNode: draggingNode,
|
|
184
|
+
dropNode: dropNode,
|
|
185
|
+
allowDrop: props.allowDrop,
|
|
186
|
+
emit: emit,
|
|
187
|
+
dragState: dragState
|
|
188
|
+
}),
|
|
189
|
+
dropPrev = _getDragDir.dropPrev,
|
|
190
|
+
dropInner = _getDragDir.dropInner,
|
|
191
|
+
dropNext = _getDragDir.dropNext,
|
|
192
|
+
userAllowDropInner = _getDragDir.userAllowDropInner;
|
|
193
|
+
var dropType = getDropType(dropPrev, dropInner, dropNext, dropNode);
|
|
194
|
+
setDropIndicatorTop(dropNode, refs.dropIndicator, vm, dropType);
|
|
195
|
+
dragState.showDropIndicator = dropType === 'before' || dropType === 'after';
|
|
196
|
+
dragState.allowDrop = dragState.showDropIndicator || userAllowDropInner;
|
|
197
|
+
dragState.dropType = dropType;
|
|
198
|
+
emit('node-drag-over', draggingNode.node, dropNode.node, event);
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
export var dragEnd = function dragEnd(_ref7) {
|
|
202
|
+
var state = _ref7.state,
|
|
203
|
+
emit = _ref7.emit;
|
|
204
|
+
return function (event) {
|
|
205
|
+
var dragState = state.dragState;
|
|
206
|
+
var draggingNode = dragState.draggingNode,
|
|
207
|
+
dropType = dragState.dropType,
|
|
208
|
+
dropNode = dragState.dropNode;
|
|
209
|
+
event.preventDefault();
|
|
210
|
+
if (!event.dataTransfer) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
event.dataTransfer.dropEffect = 'move';
|
|
214
|
+
if (draggingNode && dropNode) {
|
|
215
|
+
var draggingNodeCopy = {
|
|
216
|
+
data: draggingNode.node.data
|
|
217
|
+
};
|
|
218
|
+
var normalType = dropType !== 'none';
|
|
219
|
+
normalType && draggingNode.node.remove();
|
|
220
|
+
if (dropType === 'before') {
|
|
221
|
+
dropNode.node.parent.insertBefore(draggingNodeCopy, dropNode.node);
|
|
222
|
+
} else if (dropType === 'after') {
|
|
223
|
+
dropNode.node.parent.insertAfter(draggingNodeCopy, dropNode.node);
|
|
224
|
+
} else if (dropType === 'inner') {
|
|
225
|
+
dropNode.node.insertChild(draggingNodeCopy);
|
|
226
|
+
}
|
|
227
|
+
normalType && state.store.registerNode(draggingNodeCopy);
|
|
228
|
+
removeClass(dropNode.$el, 'is-drop-inner');
|
|
229
|
+
emit('node-drag-end', draggingNode.node, dropNode.node, dropType, event);
|
|
230
|
+
normalType && emit('node-drop', draggingNode.node, dropNode.node, dropType, event);
|
|
231
|
+
}
|
|
232
|
+
if (draggingNode && !dropNode) {
|
|
233
|
+
emit('node-drag-end', draggingNode.node, null, dropType, event);
|
|
234
|
+
}
|
|
235
|
+
dragState.draggingNode = null;
|
|
236
|
+
dragState.dropNode = null;
|
|
237
|
+
dragState.allowDrop = true;
|
|
238
|
+
dragState.showDropIndicator = false;
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
export var created = function created(_ref8) {
|
|
242
|
+
var api = _ref8.api,
|
|
243
|
+
props = _ref8.props,
|
|
244
|
+
state = _ref8.state;
|
|
245
|
+
return function () {
|
|
246
|
+
state.isTree = true;
|
|
247
|
+
var nodeKey = props.nodeKey,
|
|
248
|
+
data = props.data,
|
|
249
|
+
lazy = props.lazy,
|
|
250
|
+
load = props.load,
|
|
251
|
+
currentNodeKey = props.currentNodeKey,
|
|
252
|
+
checkStrictly = props.checkStrictly,
|
|
253
|
+
checkDescendants = props.checkDescendants;
|
|
254
|
+
var defaultCheckedKeys = props.defaultCheckedKeys,
|
|
255
|
+
defaultExpandedKeys = props.defaultExpandedKeys,
|
|
256
|
+
autoExpandParent = props.autoExpandParent,
|
|
257
|
+
defaultExpandAll = props.defaultExpandAll,
|
|
258
|
+
filterNodeMethod = props.filterNodeMethod;
|
|
259
|
+
state.store = new TreeStore({
|
|
260
|
+
key: nodeKey,
|
|
261
|
+
data: data,
|
|
262
|
+
lazy: lazy,
|
|
263
|
+
props: props.props,
|
|
264
|
+
load: load,
|
|
265
|
+
currentNodeKey: currentNodeKey,
|
|
266
|
+
checkStrictly: checkStrictly,
|
|
267
|
+
checkDescendants: checkDescendants,
|
|
268
|
+
defaultCheckedKeys: defaultCheckedKeys,
|
|
269
|
+
defaultExpandedKeys: defaultExpandedKeys,
|
|
270
|
+
autoExpandParent: autoExpandParent,
|
|
271
|
+
defaultExpandAll: defaultExpandAll,
|
|
272
|
+
filterNodeMethod: filterNodeMethod
|
|
273
|
+
});
|
|
274
|
+
state.root = state.store.root;
|
|
275
|
+
api.initIsCurrent();
|
|
276
|
+
state.emitter.on('tree-node-drag-start', api.dragStart);
|
|
277
|
+
state.emitter.on('tree-node-drag-over', api.dragOver);
|
|
278
|
+
state.emitter.on('tree-node-drag-end', api.dragEnd);
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
var doClearCurrentStore = function doClearCurrentStore(state) {
|
|
282
|
+
if (state.currentStore.node) {
|
|
283
|
+
state.currentStore.node.isCurrent = false;
|
|
284
|
+
}
|
|
285
|
+
state.currentStore.node = null;
|
|
286
|
+
state.currentStore.flag = false;
|
|
287
|
+
};
|
|
288
|
+
var setIsCurrent = function setIsCurrent(root, defaultExpandedKeys, defaultExpandedKeysHighlight, currentStore) {
|
|
289
|
+
var nodeKey = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'id';
|
|
290
|
+
if (currentStore.flag || !Array.isArray(root.childNodes)) return;
|
|
291
|
+
for (var i = 0; i < root.childNodes.length; i++) {
|
|
292
|
+
var child = root.childNodes[i];
|
|
293
|
+
if (child.data && child.data[nodeKey] && child.data[nodeKey] === defaultExpandedKeysHighlight) {
|
|
294
|
+
child.isCurrent = true;
|
|
295
|
+
currentStore.flag = true;
|
|
296
|
+
currentStore.node = child;
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
setIsCurrent(child, defaultExpandedKeys, defaultExpandedKeysHighlight, currentStore, nodeKey);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
export var initIsCurrent = function initIsCurrent(_ref9) {
|
|
303
|
+
var props = _ref9.props,
|
|
304
|
+
state = _ref9.state;
|
|
305
|
+
return function () {
|
|
306
|
+
if (state.currentStore.flag) {
|
|
307
|
+
doClearCurrentStore(state);
|
|
308
|
+
}
|
|
309
|
+
if (state.store.getCurrentNode() && props.defaultExpandedKeysHighlight) {
|
|
310
|
+
state.store.setCurrentNode(null);
|
|
311
|
+
}
|
|
312
|
+
if (props.defaultExpandedKeysHighlight && Array.isArray(props.defaultExpandedKeys) && ~props.defaultExpandedKeys.indexOf(props.defaultExpandedKeysHighlight)) {
|
|
313
|
+
setIsCurrent(state.root, props.defaultExpandedKeys, props.defaultExpandedKeysHighlight, state.currentStore, props.nodeKey);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
};
|
|
317
|
+
export var mounted = function mounted(_ref10) {
|
|
318
|
+
var api = _ref10.api,
|
|
319
|
+
vm = _ref10.vm;
|
|
320
|
+
return function () {
|
|
321
|
+
api.initTabIndex();
|
|
322
|
+
on(vm.$el, 'keydown', api.handleKeydown);
|
|
323
|
+
};
|
|
324
|
+
};
|
|
325
|
+
export var beforeUnmount = function beforeUnmount(_ref11) {
|
|
326
|
+
var api = _ref11.api,
|
|
327
|
+
vm = _ref11.vm;
|
|
328
|
+
return function () {
|
|
329
|
+
off(vm.$el, 'keydown', api.handleKeydown);
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
export var wrapMounted = function wrapMounted(_ref12) {
|
|
333
|
+
var api = _ref12.api,
|
|
334
|
+
props = _ref12.props,
|
|
335
|
+
service = _ref12.service;
|
|
336
|
+
return function () {
|
|
337
|
+
var data = props.data,
|
|
338
|
+
key = props.nodeKey,
|
|
339
|
+
parentKey = props.parentKey;
|
|
340
|
+
if (!data && props.dataset) {
|
|
341
|
+
var dataset = {
|
|
342
|
+
service: service,
|
|
343
|
+
dataset: props.dataset,
|
|
344
|
+
tree: {
|
|
345
|
+
key: key,
|
|
346
|
+
parentKey: parentKey
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
getDataset(dataset).then(api.watchData);
|
|
350
|
+
}
|
|
351
|
+
api.mounted();
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
export var updated = function updated(_ref13) {
|
|
355
|
+
var vm = _ref13.vm,
|
|
356
|
+
state = _ref13.state;
|
|
357
|
+
return function () {
|
|
358
|
+
state.treeItems = vm.$el.querySelectorAll('[role=treeitem]');
|
|
359
|
+
state.checkboxItems = vm.$el.querySelectorAll('input[type=checkbox]');
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
export var filter = function filter(_ref14) {
|
|
363
|
+
var props = _ref14.props,
|
|
364
|
+
state = _ref14.state;
|
|
365
|
+
return function (value) {
|
|
366
|
+
if (!props.filterNodeMethod) throw new Error('[Tree] filterNodeMethod is required when filter');
|
|
367
|
+
state.store.filter(value);
|
|
368
|
+
};
|
|
369
|
+
};
|
|
370
|
+
export var getNodeKey = function getNodeKey(props) {
|
|
371
|
+
return function (node) {
|
|
372
|
+
return innerGetNodekey(props.nodekey, node.data);
|
|
373
|
+
};
|
|
374
|
+
};
|
|
375
|
+
export var getNodePath = function getNodePath(_ref15) {
|
|
376
|
+
var props = _ref15.props,
|
|
377
|
+
state = _ref15.state;
|
|
378
|
+
return function (data) {
|
|
379
|
+
if (!props.nodeKey) throw new Error('[Tree] nodeKey is required in getNodePath');
|
|
380
|
+
var node = state.store.getNode(data);
|
|
381
|
+
if (!node) return [];
|
|
382
|
+
var path = [node.data];
|
|
383
|
+
var parent = node.parent;
|
|
384
|
+
while (parent && parent !== state.root) {
|
|
385
|
+
path.push(parent.data);
|
|
386
|
+
parent = parent.parent;
|
|
387
|
+
}
|
|
388
|
+
return path.reverse();
|
|
389
|
+
};
|
|
390
|
+
};
|
|
391
|
+
export var getCheckedNodes = function getCheckedNodes(state) {
|
|
392
|
+
return function (leafOnly, includeHalfChecked) {
|
|
393
|
+
return state.store.getCheckedNodes(leafOnly, includeHalfChecked);
|
|
394
|
+
};
|
|
395
|
+
};
|
|
396
|
+
export var getCheckedKeys = function getCheckedKeys(state) {
|
|
397
|
+
return function (leafOnly) {
|
|
398
|
+
return state.store.getCheckedKeys(leafOnly);
|
|
399
|
+
};
|
|
400
|
+
};
|
|
401
|
+
export var getCurrentNode = function getCurrentNode(state) {
|
|
402
|
+
return function () {
|
|
403
|
+
var currentNode = state.store.getCurrentNode();
|
|
404
|
+
return currentNode ? currentNode.data : null;
|
|
405
|
+
};
|
|
406
|
+
};
|
|
407
|
+
export var getCurrentKey = function getCurrentKey(_ref16) {
|
|
408
|
+
var api = _ref16.api,
|
|
409
|
+
props = _ref16.props;
|
|
410
|
+
return function () {
|
|
411
|
+
if (!props.nodeKey) throw new Error('[Tree] nodeKey is required in getCurrentKey');
|
|
412
|
+
var currentNode = api.getCurrentNode();
|
|
413
|
+
return currentNode ? currentNode[props.nodeKey] : null;
|
|
414
|
+
};
|
|
415
|
+
};
|
|
416
|
+
export var setCheckedNodes = function setCheckedNodes(_ref17) {
|
|
417
|
+
var props = _ref17.props,
|
|
418
|
+
state = _ref17.state;
|
|
419
|
+
return function (nodes, leafOnly) {
|
|
420
|
+
if (!props.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedNodes');
|
|
421
|
+
state.store.setCheckedNodes(nodes, leafOnly);
|
|
422
|
+
};
|
|
423
|
+
};
|
|
424
|
+
export var setCheckedKeys = function setCheckedKeys(_ref18) {
|
|
425
|
+
var props = _ref18.props,
|
|
426
|
+
state = _ref18.state;
|
|
427
|
+
return function (keys, leafOnly) {
|
|
428
|
+
if (!props.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedKeys');
|
|
429
|
+
state.store.setCheckedKeys(keys, leafOnly);
|
|
430
|
+
};
|
|
431
|
+
};
|
|
432
|
+
export var setChecked = function setChecked(state) {
|
|
433
|
+
return function (data, checked, deep) {
|
|
434
|
+
state.store.setChecked(data, checked, deep);
|
|
435
|
+
};
|
|
436
|
+
};
|
|
437
|
+
export var getHalfCheckedNodes = function getHalfCheckedNodes(state) {
|
|
438
|
+
return function () {
|
|
439
|
+
return state.store.getHalfCheckedNodes();
|
|
440
|
+
};
|
|
441
|
+
};
|
|
442
|
+
export var getHalfCheckedKeys = function getHalfCheckedKeys(state) {
|
|
443
|
+
return function () {
|
|
444
|
+
return state.store.getHalfCheckedKeys();
|
|
445
|
+
};
|
|
446
|
+
};
|
|
447
|
+
export var setCurrentNode = function setCurrentNode(_ref19) {
|
|
448
|
+
var props = _ref19.props,
|
|
449
|
+
state = _ref19.state;
|
|
450
|
+
return function (node) {
|
|
451
|
+
if (!props.nodeKey) throw new Error('[Tree] nodeKey is required in setCurrentNode');
|
|
452
|
+
state.store.setUserCurrentNode(node);
|
|
453
|
+
};
|
|
454
|
+
};
|
|
455
|
+
export var setCurrentKey = function setCurrentKey(_ref20) {
|
|
456
|
+
var props = _ref20.props,
|
|
457
|
+
state = _ref20.state;
|
|
458
|
+
return function (key) {
|
|
459
|
+
if (!props.nodeKey) throw new Error('[Tree] nodeKey is required in setCurrentKey');
|
|
460
|
+
state.store.setCurrentNodeKey(key);
|
|
461
|
+
};
|
|
462
|
+
};
|
|
463
|
+
export var getNode = function getNode(state) {
|
|
464
|
+
return function (data) {
|
|
465
|
+
return state.store.getNode(data);
|
|
466
|
+
};
|
|
467
|
+
};
|
|
468
|
+
export var remove = function remove(state) {
|
|
469
|
+
return function (data) {
|
|
470
|
+
state.store.remove(data);
|
|
471
|
+
};
|
|
472
|
+
};
|
|
473
|
+
export var append = function append(state) {
|
|
474
|
+
return function (data, parentNode) {
|
|
475
|
+
state.store.append(data, parentNode);
|
|
476
|
+
};
|
|
477
|
+
};
|
|
478
|
+
export var insertBefore = function insertBefore(state) {
|
|
479
|
+
return function (data, refNode) {
|
|
480
|
+
state.store.insertBefore(data, refNode);
|
|
481
|
+
};
|
|
482
|
+
};
|
|
483
|
+
export var insertAfter = function insertAfter(state) {
|
|
484
|
+
return function (data, refNode) {
|
|
485
|
+
state.store.insertAfter(data, refNode);
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
export var handleNodeExpand = function handleNodeExpand(emit) {
|
|
489
|
+
return function (nodeData, node, instance) {
|
|
490
|
+
emit('node-expand', nodeData, node, instance);
|
|
491
|
+
};
|
|
492
|
+
};
|
|
493
|
+
export var updateKeyChildren = function updateKeyChildren(_ref21) {
|
|
494
|
+
var props = _ref21.props,
|
|
495
|
+
state = _ref21.state;
|
|
496
|
+
return function (key, data) {
|
|
497
|
+
if (!props.nodeKey) throw new Error('[Tree] nodeKey is required in updateKeyChild');
|
|
498
|
+
state.store.updateChildren(key, data);
|
|
499
|
+
};
|
|
500
|
+
};
|
|
501
|
+
export var initTabIndex = function initTabIndex(_ref22) {
|
|
502
|
+
var vm = _ref22.vm,
|
|
503
|
+
state = _ref22.state;
|
|
504
|
+
return function () {
|
|
505
|
+
state.treeItems = vm.$el.querySelectorAll('.is-focusable[role=treeitem]');
|
|
506
|
+
state.checkboxItems = vm.$el.querySelectorAll('input[type=checkbox]');
|
|
507
|
+
var checkedItem = vm.$el.querySelectorAll('.is-checked[role=treeitem]');
|
|
508
|
+
if (checkedItem.length) {
|
|
509
|
+
checkedItem[0].setAttribute('tabindex', 0);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
state.treeItems[0] && state.treeItems[0].setAttribute('tabindex', 0);
|
|
513
|
+
};
|
|
514
|
+
};
|
|
515
|
+
export var handleKeydown = function handleKeydown(_ref23) {
|
|
516
|
+
var vm = _ref23.vm,
|
|
517
|
+
state = _ref23.state;
|
|
518
|
+
return function (event) {
|
|
519
|
+
var currentItem = event.target;
|
|
520
|
+
if (currentItem.className.indexOf('tiny-tree-node') === -1) return;
|
|
521
|
+
var keyCode = event.keyCode;
|
|
522
|
+
state.treeItems = vm.$el.querySelectorAll('.is-focusable[role=treeitem]');
|
|
523
|
+
if ([KEY_CODE.ArrowUp, KEY_CODE.ArrowDown].indexOf(keyCode) > -1) {
|
|
524
|
+
var nextIndex;
|
|
525
|
+
var currentIndex = state.treeItemArray.indexOf(currentItem);
|
|
526
|
+
event.preventDefault();
|
|
527
|
+
if (keyCode === KEY_CODE.ArrowUp) {
|
|
528
|
+
nextIndex = currentIndex !== 0 ? currentIndex - 1 : 0;
|
|
529
|
+
} else {
|
|
530
|
+
nextIndex = currentIndex < state.treeItemArray.length - 1 ? currentIndex + 1 : 0;
|
|
531
|
+
}
|
|
532
|
+
state.treeItemArray[nextIndex].focus();
|
|
533
|
+
} else if ([KEY_CODE.ArrowLeft, KEY_CODE.ArrowRight].indexOf(keyCode) > -1) {
|
|
534
|
+
event.preventDefault();
|
|
535
|
+
currentItem.click();
|
|
536
|
+
} else if ([KEY_CODE.NumpadEnter, KEY_CODE.Space].indexOf(keyCode) > -1) {
|
|
537
|
+
var hasInput = currentItem.querySelector('[type="checkbox"]');
|
|
538
|
+
if (hasInput) {
|
|
539
|
+
event.preventDefault();
|
|
540
|
+
hasInput.click();
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
};
|
|
545
|
+
var initRadio = function initRadio(_ref24) {
|
|
546
|
+
var node = _ref24.node,
|
|
547
|
+
nodeKey = _ref24.nodeKey,
|
|
548
|
+
checkedKey = _ref24.checkedKey,
|
|
549
|
+
state = _ref24.state;
|
|
550
|
+
var isFound = false;
|
|
551
|
+
if (node.data[nodeKey] === checkedKey) {
|
|
552
|
+
state.currentRadio.value = node.id;
|
|
553
|
+
isFound = true;
|
|
554
|
+
return isFound;
|
|
555
|
+
}
|
|
556
|
+
if (node.childNodes && node.childNodes.length) {
|
|
557
|
+
var childNodes = node.childNodes;
|
|
558
|
+
for (var i = 0; i < childNodes.length; i++) {
|
|
559
|
+
isFound = initRadio({
|
|
560
|
+
node: childNodes[i],
|
|
561
|
+
nodeKey: nodeKey,
|
|
562
|
+
checkedKey: checkedKey,
|
|
563
|
+
state: state
|
|
564
|
+
});
|
|
565
|
+
if (isFound) break;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
return isFound;
|
|
569
|
+
};
|
|
570
|
+
var init = function init(_ref25) {
|
|
571
|
+
var state = _ref25.state,
|
|
572
|
+
nodeKey = _ref25.nodeKey,
|
|
573
|
+
checkedKey = _ref25.checkedKey;
|
|
574
|
+
var isFound = false;
|
|
575
|
+
if (state.root && state.root.childNodes && state.root.childNodes.length) {
|
|
576
|
+
var rootChildNodes = state.root.childNodes;
|
|
577
|
+
for (var i = 0; i < rootChildNodes.length; i++) {
|
|
578
|
+
isFound = initRadio({
|
|
579
|
+
node: rootChildNodes[i],
|
|
580
|
+
nodeKey: nodeKey,
|
|
581
|
+
checkedKey: checkedKey,
|
|
582
|
+
state: state
|
|
583
|
+
});
|
|
584
|
+
if (isFound) break;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
export var setCurrentRadio = function setCurrentRadio(_ref26) {
|
|
589
|
+
var props = _ref26.props,
|
|
590
|
+
state = _ref26.state;
|
|
591
|
+
return function () {
|
|
592
|
+
if (!props.showRadio) return;
|
|
593
|
+
if (!props.nodeKey) throw new Error('[Tree] nodeKey is required in setCurrentRadio');
|
|
594
|
+
var nodeKey = props.nodeKey;
|
|
595
|
+
var defaultCheckedKeys = props.defaultCheckedKeys || [];
|
|
596
|
+
var checkedKey = defaultCheckedKeys.length ? defaultCheckedKeys[0] : null;
|
|
597
|
+
if (!checkedKey) return;
|
|
598
|
+
init({
|
|
599
|
+
state: state,
|
|
600
|
+
nodeKey: nodeKey,
|
|
601
|
+
checkedKey: checkedKey
|
|
602
|
+
});
|
|
603
|
+
};
|
|
604
|
+
};
|
|
605
|
+
export var closeMenu = function closeMenu(state) {
|
|
606
|
+
return function () {
|
|
607
|
+
return state.emitter.emit('closeMenu');
|
|
608
|
+
};
|
|
609
|
+
};
|
|
610
|
+
export var clearCurrentStore = function clearCurrentStore(state) {
|
|
611
|
+
return function (node) {
|
|
612
|
+
if (state.currentStore.flag && state.currentStore.node && state.currentStore.node.id !== node.id) {
|
|
613
|
+
doClearCurrentStore(state);
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
};
|
|
617
|
+
var innerExpandAllNodes = function innerExpandAllNodes(nodes, expandFlag) {
|
|
618
|
+
nodes.forEach(function (node) {
|
|
619
|
+
if (expandFlag) {
|
|
620
|
+
if (node.childNodes.length && node.level > 1) {
|
|
621
|
+
node.expand();
|
|
622
|
+
}
|
|
623
|
+
} else {
|
|
624
|
+
node.collapse();
|
|
625
|
+
}
|
|
626
|
+
innerExpandAllNodes(node.childNodes, expandFlag);
|
|
627
|
+
});
|
|
628
|
+
};
|
|
629
|
+
export var expandAllNodes = function expandAllNodes(_ref27) {
|
|
630
|
+
var state = _ref27.state;
|
|
631
|
+
return function (expandFlag) {
|
|
632
|
+
var nodes = state.root.childNodes;
|
|
633
|
+
if (Array.isArray(nodes) && nodes.length) {
|
|
634
|
+
innerExpandAllNodes(nodes, expandFlag);
|
|
635
|
+
nodes.forEach(function (node) {
|
|
636
|
+
if (expandFlag && node.childNodes.length) {
|
|
637
|
+
node.expand();
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
};
|