@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
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { isNull } from '@opentiny/vue-renderless/common/type';
|
|
2
|
+
import { isEqual } from '@opentiny/vue-renderless/common/object';
|
|
3
|
+
import { isEmpty } from '@opentiny/vue-renderless/cascader';
|
|
4
|
+
import { KEY_CODE, CASCADER } from '@opentiny/vue-renderless/common';
|
|
5
|
+
export var watchCheckedValue = function watchCheckedValue(_ref) {
|
|
6
|
+
var api = _ref.api,
|
|
7
|
+
emit = _ref.emit,
|
|
8
|
+
props = _ref.props,
|
|
9
|
+
state = _ref.state;
|
|
10
|
+
return function (value) {
|
|
11
|
+
if (!isEqual(value, props.modelValue)) {
|
|
12
|
+
state.checkStrictly && api.calculateCheckedNodePaths();
|
|
13
|
+
emit('update:modelValue', value);
|
|
14
|
+
emit('change', value);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export var initStore = function initStore(_ref2) {
|
|
19
|
+
var api = _ref2.api,
|
|
20
|
+
props = _ref2.props,
|
|
21
|
+
state = _ref2.state,
|
|
22
|
+
Store = _ref2.Store;
|
|
23
|
+
return function () {
|
|
24
|
+
if (state.config.lazy && isEmpty(props.options)) {
|
|
25
|
+
api.lazyLoad();
|
|
26
|
+
} else {
|
|
27
|
+
state.store = new Store(props.options, state.config);
|
|
28
|
+
state.menus = [state.store.getNodes()];
|
|
29
|
+
api.syncMenuState();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export var syncCheckedValue = function syncCheckedValue(_ref3) {
|
|
34
|
+
var api = _ref3.api,
|
|
35
|
+
props = _ref3.props,
|
|
36
|
+
state = _ref3.state;
|
|
37
|
+
return function () {
|
|
38
|
+
if (!isEqual(props.modelValue, state.checkedValue)) {
|
|
39
|
+
state.checkedValue = props.modelValue;
|
|
40
|
+
api.syncMenuState();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export var syncMenuState = function syncMenuState(_ref4) {
|
|
45
|
+
var api = _ref4.api,
|
|
46
|
+
nextTick = _ref4.nextTick,
|
|
47
|
+
state = _ref4.state;
|
|
48
|
+
return function () {
|
|
49
|
+
api.syncActivePath();
|
|
50
|
+
state.multiple && api.syncMultiCheckState();
|
|
51
|
+
state.checkStrictly && api.calculateCheckedNodePaths();
|
|
52
|
+
nextTick(function () {
|
|
53
|
+
return api.scrollIntoView;
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export var syncMultiCheckState = function syncMultiCheckState(_ref5) {
|
|
58
|
+
var api = _ref5.api,
|
|
59
|
+
state = _ref5.state;
|
|
60
|
+
return function () {
|
|
61
|
+
var nodes = api.getFlattedNodes(state.leafOnly);
|
|
62
|
+
nodes.forEach(function (node) {
|
|
63
|
+
node.syncCheckState(state.checkedValue);
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export var syncActivePath = function syncActivePath(_ref6) {
|
|
68
|
+
var api = _ref6.api,
|
|
69
|
+
state = _ref6.state;
|
|
70
|
+
return function () {
|
|
71
|
+
if (!isEmpty(state.activePath)) {
|
|
72
|
+
var nodes = state.activePath.map(function (node) {
|
|
73
|
+
return api.getNodeByValue(node.getValue());
|
|
74
|
+
});
|
|
75
|
+
if (isNull(nodes[0])) {
|
|
76
|
+
state.activePath = [];
|
|
77
|
+
} else {
|
|
78
|
+
api.expandNodes(nodes);
|
|
79
|
+
}
|
|
80
|
+
} else if (!isEmpty(state.checkedValue)) {
|
|
81
|
+
var value = state.multiple ? state.checkedValue[0] : state.checkedValue;
|
|
82
|
+
var checkedNode = api.getNodeByValue(value) || {};
|
|
83
|
+
var _nodes = (checkedNode.pathNodes || []).slice(0, -1);
|
|
84
|
+
api.expandNodes(_nodes);
|
|
85
|
+
} else {
|
|
86
|
+
state.activePath = [];
|
|
87
|
+
state.menus = [state.store.getNodes()];
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
export var expandNodes = function expandNodes(api) {
|
|
92
|
+
return function (nodes) {
|
|
93
|
+
return nodes.forEach(function (node) {
|
|
94
|
+
return api.handleExpand(node, true);
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
export var coerceTruthyValueToArray = function coerceTruthyValueToArray(val) {
|
|
99
|
+
if (Array.isArray(val)) {
|
|
100
|
+
return val;
|
|
101
|
+
} else if (val) {
|
|
102
|
+
return [val];
|
|
103
|
+
}
|
|
104
|
+
return [];
|
|
105
|
+
};
|
|
106
|
+
export var calculateCheckedNodePaths = function calculateCheckedNodePaths(_ref7) {
|
|
107
|
+
var api = _ref7.api,
|
|
108
|
+
state = _ref7.state;
|
|
109
|
+
return function () {
|
|
110
|
+
var checkedValues = state.multiple ? coerceTruthyValueToArray(state.checkedValue) : [state.checkedValue];
|
|
111
|
+
state.checkedNodePaths = checkedValues.map(function (v) {
|
|
112
|
+
var checkedNode = api.getNodeByValue(v);
|
|
113
|
+
return checkedNode ? checkedNode.pathNodes : [];
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
export var focusNode = function focusNode(api) {
|
|
118
|
+
return function (el) {
|
|
119
|
+
if (!el) return;
|
|
120
|
+
el.focus();
|
|
121
|
+
!api.isLeaf(el) && el.click();
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
export var getMenuIndex = function getMenuIndex() {
|
|
125
|
+
return function (el) {
|
|
126
|
+
if (!el) return;
|
|
127
|
+
var pieces = el.id.split('-');
|
|
128
|
+
return Number(pieces[pieces.length - 2]);
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
export var checkNode = function checkNode(api) {
|
|
132
|
+
return function (el) {
|
|
133
|
+
if (!el) return;
|
|
134
|
+
var input = el.querySelector('input');
|
|
135
|
+
if (input) {
|
|
136
|
+
input.click();
|
|
137
|
+
} else if (api.isLeaf(el)) {
|
|
138
|
+
el.click();
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
export var handleKeyDown = function handleKeyDown(_ref8) {
|
|
143
|
+
var api = _ref8.api,
|
|
144
|
+
emit = _ref8.emit,
|
|
145
|
+
menus = _ref8.menus;
|
|
146
|
+
return function (event) {
|
|
147
|
+
var target = event.target,
|
|
148
|
+
keyCode = event.keyCode;
|
|
149
|
+
if (keyCode === KEY_CODE.ArrowUp) {
|
|
150
|
+
var prev = api.getSibling(target, -1);
|
|
151
|
+
focusNode(prev);
|
|
152
|
+
} else if (keyCode === KEY_CODE.ArrowDown) {
|
|
153
|
+
var next = api.getSibling(target, 1);
|
|
154
|
+
focusNode(next);
|
|
155
|
+
} else if (keyCode === KEY_CODE.ArrowLeft) {
|
|
156
|
+
var preMenu = menus[getMenuIndex(target) - 1];
|
|
157
|
+
if (preMenu) {
|
|
158
|
+
var expandedNode = preMenu.$el.querySelector(CASCADER.CascaderNodeExpand);
|
|
159
|
+
focusNode(expandedNode);
|
|
160
|
+
}
|
|
161
|
+
} else if (keyCode === KEY_CODE.ArrowRight) {
|
|
162
|
+
var nextMenu = menus[getMenuIndex(target) + 1];
|
|
163
|
+
if (nextMenu) {
|
|
164
|
+
var firstNode = nextMenu.$el.querySelector(CASCADER.CascaderNodeTab);
|
|
165
|
+
focusNode(firstNode);
|
|
166
|
+
}
|
|
167
|
+
} else if (keyCode === KEY_CODE.Enter) {
|
|
168
|
+
checkNode(target);
|
|
169
|
+
} else if (~[KEY_CODE.Escape, KEY_CODE.Tab].indexOf(keyCode)) {
|
|
170
|
+
emit('close');
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
export var handleExpand = function handleExpand(_ref9) {
|
|
175
|
+
var emit = _ref9.emit,
|
|
176
|
+
state = _ref9.state;
|
|
177
|
+
return function (node, silent) {
|
|
178
|
+
var level = node.level;
|
|
179
|
+
var path = state.activePath.slice(0, level - 1);
|
|
180
|
+
var menus = state.menus.slice(0, level);
|
|
181
|
+
if (!node.isLeaf) {
|
|
182
|
+
path.push(node);
|
|
183
|
+
menus.push(node.children);
|
|
184
|
+
}
|
|
185
|
+
state.activePath = path;
|
|
186
|
+
state.menus = menus;
|
|
187
|
+
if (!silent) {
|
|
188
|
+
var pathValues = path.map(function (node) {
|
|
189
|
+
return node.getValue();
|
|
190
|
+
});
|
|
191
|
+
emit('active-item-change', pathValues);
|
|
192
|
+
emit('expand-change', pathValues);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
export var handleCheckChange = function handleCheckChange(state) {
|
|
197
|
+
return function (value) {
|
|
198
|
+
state.checkedValue = value;
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
export var lazyLoad = function lazyLoad(_ref10) {
|
|
202
|
+
var api = _ref10.api,
|
|
203
|
+
$parent = _ref10.$parent,
|
|
204
|
+
state = _ref10.state,
|
|
205
|
+
Store = _ref10.Store;
|
|
206
|
+
return function (node, onFullfiled) {
|
|
207
|
+
if (!node) {
|
|
208
|
+
node = node || {
|
|
209
|
+
root: true,
|
|
210
|
+
level: 0
|
|
211
|
+
};
|
|
212
|
+
state.store = new Store([], state.config);
|
|
213
|
+
state.menus = [state.store.getNodes()];
|
|
214
|
+
}
|
|
215
|
+
node.loading = true;
|
|
216
|
+
var afterLoad = function afterLoad(dataList) {
|
|
217
|
+
var parent = node.root ? null : node;
|
|
218
|
+
dataList && dataList.length && state.store.appendNodes(dataList, parent);
|
|
219
|
+
node.loading = false;
|
|
220
|
+
node.loaded = true;
|
|
221
|
+
if (Array.isArray(state.checkedValue)) {
|
|
222
|
+
var nodeValue = state.checkedValue[state.loadCount++];
|
|
223
|
+
var valueKey = state.config.value;
|
|
224
|
+
var leafKey = state.config.leaf;
|
|
225
|
+
if (Array.isArray(dataList) && dataList.filter(function (item) {
|
|
226
|
+
return item[valueKey] === nodeValue;
|
|
227
|
+
}).length > 0) {
|
|
228
|
+
var checkedNode = state.store.getNodeByValue(nodeValue);
|
|
229
|
+
if (!checkedNode.data[leafKey]) {
|
|
230
|
+
api.lazyLoad(checkedNode, function () {
|
|
231
|
+
api.handleExpand(checkedNode);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
if ($parent.computePresentText && state.loadCount === state.checkedValue.length) {
|
|
235
|
+
$parent.computePresentText();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
onFullfiled && onFullfiled(dataList);
|
|
240
|
+
};
|
|
241
|
+
state.config.lazyLoad(node, afterLoad);
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
export var calculateMultiCheckedValue = function calculateMultiCheckedValue(_ref11) {
|
|
245
|
+
var api = _ref11.api,
|
|
246
|
+
state = _ref11.state;
|
|
247
|
+
return function () {
|
|
248
|
+
state.checkedValue = api.getCheckedNodes(state.leafOnly).map(function (node) {
|
|
249
|
+
return node.getValueByOption();
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
export var scrollIntoView = function scrollIntoView(_ref12) {
|
|
254
|
+
var menus = _ref12.menus;
|
|
255
|
+
return function () {
|
|
256
|
+
menus.forEach(function (menu) {
|
|
257
|
+
var menuElement = menu.$el;
|
|
258
|
+
if (menuElement) {
|
|
259
|
+
var container = menuElement.querySelector(CASCADER.ScrollWrap);
|
|
260
|
+
var activeNode = menuElement.querySelector(CASCADER.CascaderActice) || menuElement.querySelector(CASCADER.ActivePath);
|
|
261
|
+
scrollIntoView(container, activeNode);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
export var getNodeByValue = function getNodeByValue(state) {
|
|
267
|
+
return function (val) {
|
|
268
|
+
return state.store.getNodeByValue(val);
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
export var getFlattedNodes = function getFlattedNodes(state) {
|
|
272
|
+
return function (leafOnly) {
|
|
273
|
+
var cached = !state.config.lazy;
|
|
274
|
+
return state.store.getFlattedNodes(leafOnly, cached);
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
export var getCheckedNodes = function getCheckedNodes(_ref13) {
|
|
278
|
+
var api = _ref13.api,
|
|
279
|
+
state = _ref13.state;
|
|
280
|
+
return function (leafOnly, cascaderCheckedValue) {
|
|
281
|
+
var isCascaderChecked = function isCascaderChecked(str, checkedValue) {
|
|
282
|
+
var flag = true;
|
|
283
|
+
if (!state.multiple || !checkedValue) {
|
|
284
|
+
return flag;
|
|
285
|
+
}
|
|
286
|
+
flag = false;
|
|
287
|
+
if (!Array.isArray(checkedValue)) {
|
|
288
|
+
return flag;
|
|
289
|
+
}
|
|
290
|
+
for (var i = 0; i < checkedValue.length; i++) {
|
|
291
|
+
if (Array.isArray(checkedValue[i]) && checkedValue[i].length) {
|
|
292
|
+
flag = checkedValue[i][checkedValue[i].length - 1] === str;
|
|
293
|
+
}
|
|
294
|
+
if (flag) break;
|
|
295
|
+
}
|
|
296
|
+
return flag;
|
|
297
|
+
};
|
|
298
|
+
if (state.multiple) {
|
|
299
|
+
var nodes = api.getFlattedNodes(leafOnly);
|
|
300
|
+
return nodes.filter(function (node) {
|
|
301
|
+
return node.checked && isCascaderChecked(node.value, cascaderCheckedValue);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
return isEmpty(state.checkedValue) ? [] : [api.getNodeByValue(state.checkedValue)];
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
export var clearCheckedNodes = function clearCheckedNodes(_ref14) {
|
|
308
|
+
var api = _ref14.api,
|
|
309
|
+
state = _ref14.state;
|
|
310
|
+
return function () {
|
|
311
|
+
var _state$config = state.config,
|
|
312
|
+
multiple = _state$config.multiple,
|
|
313
|
+
emitPath = _state$config.emitPath;
|
|
314
|
+
if (multiple) {
|
|
315
|
+
api.getCheckedNodes(state.leafOnly).filter(function (node) {
|
|
316
|
+
return !node.isDisabled;
|
|
317
|
+
}).forEach(function (node) {
|
|
318
|
+
return node.doCheck(false);
|
|
319
|
+
});
|
|
320
|
+
api.calculateMultiCheckedValue();
|
|
321
|
+
} else {
|
|
322
|
+
state.checkedValue = emitPath ? [] : null;
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
export var isLeaf = function isLeaf() {
|
|
327
|
+
return function (el) {
|
|
328
|
+
return !el.getAttribute('data-owns');
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
export var getSibling = function getSibling(el, distance) {
|
|
332
|
+
var parentNode = el.parentNode;
|
|
333
|
+
if (parentNode) {
|
|
334
|
+
var siblings = parentNode.querySelectorAll(CASCADER.CascaderNodeTab);
|
|
335
|
+
var index = Array.prototype.indexOf.call(siblings, el);
|
|
336
|
+
return siblings[index + distance] || null;
|
|
337
|
+
}
|
|
338
|
+
return null;
|
|
339
|
+
};
|
|
340
|
+
export var valueEquals = function valueEquals(a, b) {
|
|
341
|
+
if (a === b) {
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
344
|
+
if (!(b instanceof Array)) {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
if (!(a instanceof Array)) {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
if (a.length !== b.length) {
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
for (var i = 0, len = a.length; i !== len; ++i) {
|
|
354
|
+
if (a[i] !== b[i]) {
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return true;
|
|
359
|
+
};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import { isEqual } from '@opentiny/vue-renderless/common/object';
|
|
4
|
+
import { capitalize } from '@opentiny/vue-renderless/common/string';
|
|
5
|
+
import { isNull } from '@opentiny/vue-renderless/common/type';
|
|
6
|
+
var uid = 0;
|
|
7
|
+
var Node = function () {
|
|
8
|
+
function Node(data, config, parentNode) {
|
|
9
|
+
_classCallCheck(this, Node);
|
|
10
|
+
Object.assign(this, {
|
|
11
|
+
data: data,
|
|
12
|
+
config: config,
|
|
13
|
+
uid: uid++
|
|
14
|
+
});
|
|
15
|
+
this.parent = parentNode || null;
|
|
16
|
+
this.level = !this.parent ? 1 : this.parent.level + 1;
|
|
17
|
+
this.initState();
|
|
18
|
+
this.initChildren();
|
|
19
|
+
}
|
|
20
|
+
_createClass(Node, [{
|
|
21
|
+
key: "initState",
|
|
22
|
+
value: function initState() {
|
|
23
|
+
var _this$config = this.config,
|
|
24
|
+
value = _this$config.value,
|
|
25
|
+
label = _this$config.label;
|
|
26
|
+
this.value = this.data[value];
|
|
27
|
+
this.label = this.data[label];
|
|
28
|
+
this.pathNodes = this.calculatePathNodes();
|
|
29
|
+
this.path = this.pathNodes.map(function (node) {
|
|
30
|
+
return node.value;
|
|
31
|
+
});
|
|
32
|
+
this.pathLabels = this.pathNodes.map(function (node) {
|
|
33
|
+
return node.label;
|
|
34
|
+
});
|
|
35
|
+
Object.assign(this, {
|
|
36
|
+
loading: false,
|
|
37
|
+
loaded: false
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}, {
|
|
41
|
+
key: "initChildren",
|
|
42
|
+
value: function initChildren() {
|
|
43
|
+
var _this = this;
|
|
44
|
+
var config = this.config;
|
|
45
|
+
var childrenKey = config.children;
|
|
46
|
+
var childrenData = this.data[childrenKey];
|
|
47
|
+
this.hasChildren = Array.isArray(childrenData);
|
|
48
|
+
this.children = (childrenData || []).map(function (child) {
|
|
49
|
+
return new Node(child, config, _this);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
53
|
+
key: "isLeaf",
|
|
54
|
+
get: function get() {
|
|
55
|
+
var data = this.data,
|
|
56
|
+
loaded = this.loaded,
|
|
57
|
+
hasChildren = this.hasChildren,
|
|
58
|
+
children = this.children,
|
|
59
|
+
config = this.config;
|
|
60
|
+
var lazy = config.lazy,
|
|
61
|
+
leaf = config.leaf;
|
|
62
|
+
if (lazy) {
|
|
63
|
+
var leafValue = data[leaf];
|
|
64
|
+
var isLeaf = !isNull(leafValue) ? leafValue : loaded ? !children.length : false;
|
|
65
|
+
this.hasChildren = !isLeaf;
|
|
66
|
+
return isLeaf;
|
|
67
|
+
}
|
|
68
|
+
return !hasChildren;
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
key: "isDisabled",
|
|
72
|
+
get: function get() {
|
|
73
|
+
var data = this.data,
|
|
74
|
+
parent = this.parent,
|
|
75
|
+
config = this.config;
|
|
76
|
+
var checkStrictly = config.checkStrictly,
|
|
77
|
+
disabled = config.disabled;
|
|
78
|
+
var disabledKey = disabled;
|
|
79
|
+
return data[disabledKey] || !checkStrictly && parent && parent.isDisabled;
|
|
80
|
+
}
|
|
81
|
+
}, {
|
|
82
|
+
key: "calculatePathNodes",
|
|
83
|
+
value: function calculatePathNodes() {
|
|
84
|
+
var nodes = [this];
|
|
85
|
+
var parentNode = this.parent;
|
|
86
|
+
while (parentNode) {
|
|
87
|
+
nodes.unshift(parentNode);
|
|
88
|
+
parentNode = parentNode.parent;
|
|
89
|
+
}
|
|
90
|
+
return nodes;
|
|
91
|
+
}
|
|
92
|
+
}, {
|
|
93
|
+
key: "getValue",
|
|
94
|
+
value: function getValue() {
|
|
95
|
+
return this.value;
|
|
96
|
+
}
|
|
97
|
+
}, {
|
|
98
|
+
key: "getPath",
|
|
99
|
+
value: function getPath() {
|
|
100
|
+
return this.path;
|
|
101
|
+
}
|
|
102
|
+
}, {
|
|
103
|
+
key: "getValueByOption",
|
|
104
|
+
value: function getValueByOption() {
|
|
105
|
+
return this.config.emitPath ? this.getPath() : this.getValue();
|
|
106
|
+
}
|
|
107
|
+
}, {
|
|
108
|
+
key: "getText",
|
|
109
|
+
value: function getText(allLevels, separator) {
|
|
110
|
+
return allLevels ? this.pathLabels.join(separator) : this.label;
|
|
111
|
+
}
|
|
112
|
+
}, {
|
|
113
|
+
key: "isSameNode",
|
|
114
|
+
value: function isSameNode(checkedValue) {
|
|
115
|
+
var value = this.getValueByOption();
|
|
116
|
+
var isMultiple = this.config.multiple && Array.isArray(checkedValue);
|
|
117
|
+
return isMultiple ? checkedValue.some(function (val) {
|
|
118
|
+
return isEqual(val, value);
|
|
119
|
+
}) : isEqual(checkedValue, value);
|
|
120
|
+
}
|
|
121
|
+
}, {
|
|
122
|
+
key: "emit",
|
|
123
|
+
value: function emit(eventName) {
|
|
124
|
+
var parent = this.parent;
|
|
125
|
+
var handlerName = "onChild".concat(capitalize(eventName));
|
|
126
|
+
if (parent) {
|
|
127
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
128
|
+
args[_key - 1] = arguments[_key];
|
|
129
|
+
}
|
|
130
|
+
parent[handlerName] && parent[handlerName].apply(parent, args);
|
|
131
|
+
parent.emit.apply(parent, [eventName].concat(args));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}, {
|
|
135
|
+
key: "broadcast",
|
|
136
|
+
value: function broadcast(eventName) {
|
|
137
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
138
|
+
args[_key2 - 1] = arguments[_key2];
|
|
139
|
+
}
|
|
140
|
+
var handlerName = "onParent".concat(capitalize(eventName));
|
|
141
|
+
this.children.forEach(function (child) {
|
|
142
|
+
if (child) {
|
|
143
|
+
child.broadcast.apply(child, [eventName].concat(args));
|
|
144
|
+
child[handlerName] && child[handlerName].apply(child, args);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}, {
|
|
149
|
+
key: "onParentCheck",
|
|
150
|
+
value: function onParentCheck(checked) {
|
|
151
|
+
!this.isDisabled && this.setCheckState(checked);
|
|
152
|
+
}
|
|
153
|
+
}, {
|
|
154
|
+
key: "onChildCheck",
|
|
155
|
+
value: function onChildCheck() {
|
|
156
|
+
var children = this.children;
|
|
157
|
+
var validChildren = children.filter(function (child) {
|
|
158
|
+
return !child.isDisabled;
|
|
159
|
+
});
|
|
160
|
+
var checked = validChildren.length ? validChildren.every(function (child) {
|
|
161
|
+
return child.checked;
|
|
162
|
+
}) : false;
|
|
163
|
+
this.setCheckState(checked);
|
|
164
|
+
}
|
|
165
|
+
}, {
|
|
166
|
+
key: "syncCheckState",
|
|
167
|
+
value: function syncCheckState(checkedValue) {
|
|
168
|
+
var value = this.getValueByOption();
|
|
169
|
+
var checked = this.isSameNode(checkedValue, value);
|
|
170
|
+
this.doCheck(checked);
|
|
171
|
+
}
|
|
172
|
+
}, {
|
|
173
|
+
key: "setCheckState",
|
|
174
|
+
value: function setCheckState(checked) {
|
|
175
|
+
var totalNum = this.children.length;
|
|
176
|
+
var checkedNum = this.children.reduce(function (prevChild, nextChild) {
|
|
177
|
+
var num = nextChild.checked ? 1 : nextChild.indeterminate ? 0.5 : 0;
|
|
178
|
+
return prevChild + num;
|
|
179
|
+
}, 0);
|
|
180
|
+
this.checked = checked;
|
|
181
|
+
this.indeterminate = checkedNum !== totalNum && checkedNum > 0;
|
|
182
|
+
}
|
|
183
|
+
}, {
|
|
184
|
+
key: "doCheck",
|
|
185
|
+
value: function doCheck(isChecked) {
|
|
186
|
+
if (this.checked !== isChecked) {
|
|
187
|
+
if (this.config.checkStrictly) {
|
|
188
|
+
this.checked = isChecked;
|
|
189
|
+
} else {
|
|
190
|
+
this.broadcast('check', isChecked);
|
|
191
|
+
this.setCheckState(isChecked);
|
|
192
|
+
this.emit('check');
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}]);
|
|
197
|
+
return Node;
|
|
198
|
+
}();
|
|
199
|
+
export { Node as default };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import Node from './node';
|
|
4
|
+
import { valueEquals, coerceTruthyValueToArray as toArray } from './index';
|
|
5
|
+
var flatNodes = function flatNodes(data, leafOnly) {
|
|
6
|
+
return data.reduce(function (prev, node) {
|
|
7
|
+
if (node.isLeaf) {
|
|
8
|
+
prev.push(node);
|
|
9
|
+
} else {
|
|
10
|
+
!leafOnly && prev.push(node);
|
|
11
|
+
prev = prev.concat(flatNodes(node.children, leafOnly));
|
|
12
|
+
}
|
|
13
|
+
return prev;
|
|
14
|
+
}, []);
|
|
15
|
+
};
|
|
16
|
+
var Store = function () {
|
|
17
|
+
function Store(data, config) {
|
|
18
|
+
_classCallCheck(this, Store);
|
|
19
|
+
this.config = config;
|
|
20
|
+
this.initNodes(data);
|
|
21
|
+
}
|
|
22
|
+
_createClass(Store, [{
|
|
23
|
+
key: "getNodes",
|
|
24
|
+
value: function getNodes() {
|
|
25
|
+
return this.nodes;
|
|
26
|
+
}
|
|
27
|
+
}, {
|
|
28
|
+
key: "initNodes",
|
|
29
|
+
value: function initNodes(data) {
|
|
30
|
+
var _this = this;
|
|
31
|
+
data = toArray(data);
|
|
32
|
+
this.nodes = data.map(function (nodeData) {
|
|
33
|
+
return new Node(nodeData, _this.config);
|
|
34
|
+
});
|
|
35
|
+
this.flattedNodes = this.getFlattedNodes(false, false);
|
|
36
|
+
this.leafNodes = this.getFlattedNodes(true, false);
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
key: "appendNode",
|
|
40
|
+
value: function appendNode(nodeData, parentNode) {
|
|
41
|
+
var config = this.config,
|
|
42
|
+
nodes = this.nodes;
|
|
43
|
+
var node = new Node(nodeData, config, parentNode);
|
|
44
|
+
var children = parentNode ? parentNode.children : nodes;
|
|
45
|
+
children.push(node);
|
|
46
|
+
}
|
|
47
|
+
}, {
|
|
48
|
+
key: "appendNodes",
|
|
49
|
+
value: function appendNodes(nodeDataList, parentNode) {
|
|
50
|
+
var _this2 = this;
|
|
51
|
+
nodeDataList = toArray(nodeDataList);
|
|
52
|
+
nodeDataList.forEach(function (nodeData) {
|
|
53
|
+
return _this2.appendNode(nodeData, parentNode);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}, {
|
|
57
|
+
key: "getFlattedNodes",
|
|
58
|
+
value: function getFlattedNodes(leafOnly) {
|
|
59
|
+
var cached = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
60
|
+
var leafNodes = this.leafNodes,
|
|
61
|
+
flattedNodes = this.flattedNodes;
|
|
62
|
+
var cachedNodes = leafOnly ? leafNodes : flattedNodes;
|
|
63
|
+
return cached ? cachedNodes : flatNodes(this.nodes, leafOnly);
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
key: "getNodeByValue",
|
|
67
|
+
value: function getNodeByValue(value) {
|
|
68
|
+
if (value) {
|
|
69
|
+
var lazy = !this.config.lazy;
|
|
70
|
+
var nodes = this.getFlattedNodes(false, lazy).filter(function (node) {
|
|
71
|
+
return valueEquals(node.path, value) || node.value === value;
|
|
72
|
+
});
|
|
73
|
+
return nodes && nodes.length ? nodes[0] : null;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}]);
|
|
78
|
+
return Store;
|
|
79
|
+
}();
|
|
80
|
+
export { Store as default };
|