bkui-vue 2.1.0-dev-beta.15 → 2.1.0-dev-beta.17

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/lib/index.js CHANGED
@@ -3,5 +3,5 @@ export * from './hooks';
3
3
  export { default } from './preset';
4
4
  export * from './config-provider';
5
5
  export * from './directives';
6
- export const version = "2.1.0-dev-beta.15";
6
+ export const version = "2.1.0-dev-beta.17";
7
7
  window.__bkui_vue_version__ = version;
package/lib/tree/index.js CHANGED
@@ -19871,64 +19871,75 @@ var use_search_this = undefined;
19871
19871
  */
19872
19872
 
19873
19873
  /* harmony default export */ const use_search = (function (props) {
19874
- var _props$search;
19875
19874
  var refSearch = (0,external_vue_namespaceObject.toRef)(props, 'search');
19876
- var _ref = (_props$search = props.search) !== null && _props$search !== void 0 ? _props$search : {},
19877
- _ref$resultType = _ref.resultType,
19878
- resultType = _ref$resultType === void 0 ? 'tree' : _ref$resultType,
19879
- _ref$showChildNodes = _ref.showChildNodes,
19880
- showChildNodes = _ref$showChildNodes === void 0 ? true : _ref$showChildNodes;
19881
19875
  var isCommonType = function isCommonType(val) {
19882
19876
  return ['string', 'number', 'boolean'].includes(_typeof(val));
19883
19877
  };
19884
- var exactMath = function exactMath(matchValue, itemValue) {
19878
+ var exactMatch = function exactMatch(matchValue, itemValue) {
19885
19879
  return matchValue === itemValue;
19886
19880
  };
19887
- var regMatch = function regMatch(matchValue, itemValue) {
19888
- return new RegExp("".concat(matchValue), 'i').test("".concat(itemValue));
19881
+ var fuzzyMatch = function fuzzyMatch(matchValue, itemValue) {
19882
+ try {
19883
+ return new RegExp("".concat(matchValue), 'i').test("".concat(itemValue));
19884
+ } catch (_unused) {
19885
+ return "".concat(itemValue).toLowerCase().includes("".concat(matchValue).toLowerCase());
19886
+ }
19889
19887
  };
19890
19888
  var matchFn = function matchFn(match, args) {
19891
19889
  return Reflect.apply(match, use_search_this, args);
19892
19890
  };
19893
- var isSearchDisabled = refSearch.value === undefined || refSearch.value === false;
19894
- var searchFn = function searchFn(itemValue, item) {
19895
- if (isSearchDisabled) {
19896
- return true;
19891
+ var isSearchDisabled = (0,external_vue_namespaceObject.computed)(function () {
19892
+ return refSearch.value === undefined || refSearch.value === false;
19893
+ });
19894
+ var searchOption = (0,external_vue_namespaceObject.computed)(function () {
19895
+ if (refSearch.value && _typeof(refSearch.value) === 'object') {
19896
+ return refSearch.value;
19897
19897
  }
19898
+ var emptyOption = {
19899
+ value: ''
19900
+ };
19901
+ return emptyOption;
19902
+ });
19903
+ var resultType = (0,external_vue_namespaceObject.computed)(function () {
19904
+ var _searchOption$value$r;
19905
+ return (_searchOption$value$r = searchOption.value.resultType) !== null && _searchOption$value$r !== void 0 ? _searchOption$value$r : 'tree';
19906
+ });
19907
+ var showChildNodes = (0,external_vue_namespaceObject.computed)(function () {
19908
+ var _searchOption$value$s;
19909
+ return (_searchOption$value$s = searchOption.value.showChildNodes) !== null && _searchOption$value$s !== void 0 ? _searchOption$value$s : false;
19910
+ });
19911
+ var getSearchValue = function getSearchValue() {
19912
+ var _searchOption$value$v;
19898
19913
  if (isCommonType(refSearch.value)) {
19899
- if ("".concat(refSearch.value).length === 0) {
19900
- return false;
19901
- }
19902
- return matchFn(regMatch, [refSearch.value, itemValue, item]);
19914
+ return refSearch.value;
19903
19915
  }
19904
- var _refSearch$value = refSearch.value,
19905
- _refSearch$value$valu = _refSearch$value.value,
19906
- value = _refSearch$value$valu === void 0 ? '' : _refSearch$value$valu,
19907
- _refSearch$value$matc = _refSearch$value.match,
19908
- match = _refSearch$value$matc === void 0 ? 'fuzzy' : _refSearch$value$matc;
19909
- var defultMatch = match === 'fuzzy' ? regMatch : exactMath;
19910
- var matchCallback = typeof match === 'function' ? match : defultMatch;
19916
+ return (_searchOption$value$v = searchOption.value.value) !== null && _searchOption$value$v !== void 0 ? _searchOption$value$v : '';
19917
+ };
19918
+ var searchFn = function searchFn(itemValue, item) {
19919
+ if (isSearchDisabled.value) {
19920
+ return true;
19921
+ }
19922
+ var value = getSearchValue();
19911
19923
  if ("".concat(value).length === 0) {
19912
19924
  return false;
19913
19925
  }
19926
+ if (isCommonType(refSearch.value)) {
19927
+ return matchFn(fuzzyMatch, [value, itemValue, item]);
19928
+ }
19929
+ var _searchOption$value$m = searchOption.value.match,
19930
+ match = _searchOption$value$m === void 0 ? 'fuzzy' : _searchOption$value$m;
19931
+ var defaultMatch = match === 'fuzzy' ? fuzzyMatch : exactMatch;
19932
+ var matchCallback = typeof match === 'function' ? match : defaultMatch;
19914
19933
  return matchFn(matchCallback, [value, itemValue, item]);
19915
19934
  };
19916
19935
  var isSearchActive = (0,external_vue_namespaceObject.computed)(function () {
19917
- if (refSearch.value === false) {
19936
+ if (isSearchDisabled.value) {
19918
19937
  return false;
19919
19938
  }
19920
- if (isCommonType(refSearch.value)) {
19921
- return "".concat(refSearch.value).length > 0;
19922
- }
19923
- var _refSearch$value$valu2 = refSearch.value.value,
19924
- value = _refSearch$value$valu2 === void 0 ? '' : _refSearch$value$valu2;
19925
- return "".concat(value).length > 0;
19939
+ return "".concat(getSearchValue()).length > 0;
19926
19940
  });
19927
- /**
19928
- * 索索结果展示为Tree
19929
- */
19930
19941
  var isTreeUI = (0,external_vue_namespaceObject.computed)(function () {
19931
- return resultType === 'tree';
19942
+ return resultType.value === 'tree';
19932
19943
  });
19933
19944
  return {
19934
19945
  searchFn: searchFn,
@@ -20491,7 +20502,6 @@ var use_tree_init_this = undefined;
20491
20502
  isNodeChecked = _useNodeAttribute.isNodeChecked,
20492
20503
  isNodeMatched = _useNodeAttribute.isNodeMatched,
20493
20504
  hasChildNode = _useNodeAttribute.hasChildNode,
20494
- getNodePath = _useNodeAttribute.getNodePath,
20495
20505
  getNodeId = _useNodeAttribute.getNodeId,
20496
20506
  getNodeAttr = _useNodeAttribute.getNodeAttr,
20497
20507
  getNodeById = _useNodeAttribute.getNodeById,
@@ -20504,28 +20514,50 @@ var use_tree_init_this = undefined;
20504
20514
  refSearch = _useSearch.refSearch,
20505
20515
  isSearchDisabled = _useSearch.isSearchDisabled,
20506
20516
  isTreeUI = _useSearch.isTreeUI,
20517
+ resultType = _useSearch.resultType,
20507
20518
  showChildNodes = _useSearch.showChildNodes;
20508
- var matchedNodePath = (0,external_vue_namespaceObject.reactive)([]);
20519
+ var matchedNodeIds = (0,external_vue_namespaceObject.reactive)(new Set());
20520
+ var visibleNodeIds = (0,external_vue_namespaceObject.reactive)(new Set());
20521
+ var searchOriginalOpenState = new Map();
20522
+ var getRenderNodeId = function getRenderNodeId(node) {
20523
+ return "".concat(getNodeId(node));
20524
+ };
20525
+ var setSearchNodeOpen = function setSearchNodeOpen(node) {
20526
+ var nodeId = getRenderNodeId(node);
20527
+ if (!searchOriginalOpenState.has(nodeId)) {
20528
+ searchOriginalOpenState.set(nodeId, isNodeOpened(node));
20529
+ }
20530
+ setNodeAttribute(node, NODE_ATTRIBUTES.IS_OPEN, true, false);
20531
+ };
20532
+ var restoreSearchOpenState = function restoreSearchOpenState() {
20533
+ searchOriginalOpenState.forEach(function (isOpen, nodeId) {
20534
+ var node = getNodeById(nodeId);
20535
+ if (node) {
20536
+ setNodeAttribute(node, NODE_ATTRIBUTES.IS_OPEN, isOpen, false);
20537
+ }
20538
+ });
20539
+ searchOriginalOpenState.clear();
20540
+ };
20541
+ var addAncestorNodes = function addAncestorNodes(node) {
20542
+ var parent = getParentNode(node);
20543
+ while (parent) {
20544
+ var parentId = getRenderNodeId(parent);
20545
+ visibleNodeIds.add(parentId);
20546
+ setSearchNodeOpen(parent);
20547
+ parent = getParentNode(parent);
20548
+ }
20549
+ };
20550
+ var _addDescendantNodes = function addDescendantNodes(node) {
20551
+ var _flatData$childMap$ge, _flatData$childMap;
20552
+ var children = (_flatData$childMap$ge = (_flatData$childMap = flatData.childMap) === null || _flatData$childMap === void 0 ? void 0 : _flatData$childMap.get(node)) !== null && _flatData$childMap$ge !== void 0 ? _flatData$childMap$ge : [];
20553
+ children.forEach(function (child) {
20554
+ visibleNodeIds.add(getRenderNodeId(child));
20555
+ _addDescendantNodes(child);
20556
+ });
20557
+ };
20509
20558
  var filterFn = function filterFn(item) {
20510
20559
  if (isSearchActive.value) {
20511
- if (showChildNodes) {
20512
- var _getNodePath;
20513
- var itemPath = (_getNodePath = getNodePath(item)) !== null && _getNodePath !== void 0 ? _getNodePath : '';
20514
- var asParentPath = "".concat(itemPath, "-");
20515
- var isNodeOpen = checkNodeIsOpen(item);
20516
- var isNodeMatch = isNodeMatched(item);
20517
- var isNodeRoot = isRootNode(item);
20518
- if (isNodeOpen) {
20519
- if (isNodeRoot) {
20520
- return isNodeMatch;
20521
- }
20522
- return isNodeMatch || matchedNodePath.some(function (path) {
20523
- return asParentPath.indexOf("".concat(path, "-")) === 0;
20524
- });
20525
- }
20526
- return false;
20527
- }
20528
- return checkNodeIsOpen(item) && isNodeMatched(item);
20560
+ return visibleNodeIds.has(getRenderNodeId(item));
20529
20561
  }
20530
20562
  return checkNodeIsOpen(item);
20531
20563
  };
@@ -20619,23 +20651,42 @@ var use_tree_init_this = undefined;
20619
20651
  deepUpdateChildNode = _useNodeAction.deepUpdateChildNode,
20620
20652
  updateParentChecked = _useNodeAction.updateParentChecked;
20621
20653
  var handleSearch = (0,shared_namespaceObject.debounce)(120, function () {
20622
- matchedNodePath.length = 0;
20654
+ restoreSearchOpenState();
20655
+ matchedNodeIds.clear();
20656
+ visibleNodeIds.clear();
20623
20657
  flatData.data.forEach(function (item) {
20624
- var isMatch = searchFn(getLabel(item, props), item);
20658
+ var isMatch = !isSearchDisabled.value && searchFn(getLabel(item, props), item);
20659
+ var nodeId = getRenderNodeId(item);
20625
20660
  if (isMatch) {
20626
- matchedNodePath.push(getNodePath(item));
20661
+ matchedNodeIds.add(nodeId);
20662
+ visibleNodeIds.add(nodeId);
20627
20663
  }
20628
- setNodeAttribute(item, [NODE_ATTRIBUTES.IS_MATCH], [isMatch], isTreeUI.value && isMatch);
20664
+ setNodeAttribute(item, [NODE_ATTRIBUTES.IS_MATCH, NODE_ATTRIBUTES.IS_OPEN], [isMatch, isNodeOpened(item)], false);
20629
20665
  });
20630
- });
20631
- if (!isSearchDisabled) {
20632
- (0,external_vue_namespaceObject.watch)([refSearch], function () {
20633
- handleSearch();
20634
- }, {
20635
- deep: true,
20636
- immediate: true
20666
+ if (!isSearchActive.value) {
20667
+ return;
20668
+ }
20669
+ flatData.data.forEach(function (item) {
20670
+ if (!matchedNodeIds.has(getRenderNodeId(item))) {
20671
+ return;
20672
+ }
20673
+ if (resultType.value === 'tree') {
20674
+ addAncestorNodes(item);
20675
+ }
20676
+ if (showChildNodes.value) {
20677
+ setSearchNodeOpen(item);
20678
+ _addDescendantNodes(item);
20679
+ }
20637
20680
  });
20638
- }
20681
+ });
20682
+ (0,external_vue_namespaceObject.watch)([refSearch, function () {
20683
+ return flatData.data;
20684
+ }, resultType, showChildNodes], function () {
20685
+ handleSearch();
20686
+ }, {
20687
+ deep: true,
20688
+ immediate: true
20689
+ });
20639
20690
  (0,external_vue_namespaceObject.onMounted)(function () {
20640
20691
  if (props.virtualRender) {
20641
20692
  (0,external_vue_namespaceObject.nextTick)(function () {
@@ -3,9 +3,9 @@ declare const _default: (props: TreePropTypes) => {
3
3
  searchFn: (itemValue: unknown, item: unknown) => boolean;
4
4
  refSearch: import("vue").Ref<string | number | boolean | SearchOption, string | number | boolean | SearchOption>;
5
5
  isSearchActive: import("vue").ComputedRef<boolean>;
6
- isSearchDisabled: boolean;
7
- resultType: "list" | "tree";
6
+ isSearchDisabled: import("vue").ComputedRef<boolean>;
7
+ resultType: import("vue").ComputedRef<"list" | "tree">;
8
8
  isTreeUI: import("vue").ComputedRef<boolean>;
9
- showChildNodes: boolean;
9
+ showChildNodes: import("vue").ComputedRef<boolean>;
10
10
  };
11
11
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkui-vue",
3
- "version": "2.1.0-dev-beta.15",
3
+ "version": "2.1.0-dev-beta.17",
4
4
  "workspaces": [
5
5
  "packages/**",
6
6
  "scripts/cli",