hy-virtual-tree 2.0.6 → 2.0.8

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## Changelog
2
2
 
3
+ ### 2.0.8
4
+
5
+ _2026-03-17_
6
+
7
+ (1)修复自定义元素插槽传入元素节点时没有正常渲染bug
8
+
9
+ ### 2.0.7
10
+
11
+ _2026-03-16_
12
+
13
+ (1)优化tooltip销毁时的效果
14
+ (2)setChecked、setCheckedKeys、setCheckedNodes 方法新增 isForce 参数,可以不考虑隐藏逻辑,强制选中
15
+
3
16
  ### 2.0.6
4
17
 
5
18
  _2026-03-13_
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* hy-virtual-tree v2.0.6 */
1
+ /* hy-virtual-tree v2.0.8 */
2
2
  import './svg_bundle.js';
3
3
  const isString = (e) => typeof e === 'string';
4
4
  const isNumber = (e) => typeof e === 'number';
@@ -7162,38 +7162,26 @@ class Tooltip {
7162
7162
  break;
7163
7163
  }
7164
7164
  }
7165
- hide(isRealTime = false) {
7165
+ hide() {
7166
7166
  this._openTimer && clearTimeout(this._openTimer);
7167
7167
  this._closeTimer && clearTimeout(this._closeTimer);
7168
- if (isRealTime) {
7169
- if (!this._el)
7170
- return;
7171
- this._el.style.setProperty('top', '-10000px');
7172
- this._el.style.setProperty('left', '-10000px');
7173
- if (!this._el.parentElement)
7174
- return;
7175
- this._el.parentElement.removeChild(this._el);
7176
- }
7177
- else {
7168
+ if (!this._el)
7169
+ return;
7170
+ const el = this._el;
7171
+ this._closeTimer = setTimeout(() => {
7172
+ el.classList.remove('hy-tooltip-show');
7173
+ this._closeTimer && clearTimeout(this._closeTimer);
7178
7174
  this._closeTimer = setTimeout(() => {
7179
- if (!this._el)
7175
+ el.style.setProperty('top', '-10000px');
7176
+ el.style.setProperty('left', '-10000px');
7177
+ if (!el.parentElement)
7180
7178
  return;
7181
- this._el.classList.remove('hy-tooltip-show');
7182
- this._closeTimer && clearTimeout(this._closeTimer);
7183
- this._closeTimer = setTimeout(() => {
7184
- if (!this._el)
7185
- return;
7186
- this._el.style.setProperty('top', '-10000px');
7187
- this._el.style.setProperty('left', '-10000px');
7188
- if (!this._el.parentElement)
7189
- return;
7190
- this._el.parentElement.removeChild(this._el);
7191
- }, 200);
7179
+ el.parentElement.removeChild(el);
7192
7180
  }, 200);
7193
- }
7181
+ }, 200);
7194
7182
  }
7195
7183
  destroy() {
7196
- this.hide(true);
7184
+ this.hide();
7197
7185
  this._timer && clearTimeout(this._timer);
7198
7186
  this._trigger && this._trigger.destroy();
7199
7187
  this._el = undefined;
@@ -8243,7 +8231,7 @@ function useCheck(props, instance) {
8243
8231
  };
8244
8232
  const isChecked = (node) => checkedKeys.has(node.key);
8245
8233
  const isIndeterminate = (node) => indeterminateKeys.has(node.key);
8246
- const toggleCheckbox = (node, isChecked, nodeClick = true, immediateUpdate = true, checkOnDbclick = false) => {
8234
+ const toggleCheckbox = (node, isChecked, nodeClick = true, immediateUpdate = true, checkOnDbclick = false, isForce) => {
8247
8235
  const { type, checkStrictly, cancelable } = props.rowSelection;
8248
8236
  const checkedKeySet = checkedKeys;
8249
8237
  // 单选
@@ -8261,9 +8249,13 @@ function useCheck(props, instance) {
8261
8249
  }
8262
8250
  // 多选
8263
8251
  const toggle = (node, checked) => {
8264
- // 对隐藏的节点不做处理
8265
- if (instance._hiddenNodeKeySet.has(node.key) || (tree.hiddenNodeKeySet.has(node.key) && nodeClick))
8266
- return;
8252
+ // 是否强制选中
8253
+ if (!isForce) {
8254
+ // 对隐藏的节点不做处理
8255
+ if (instance._hiddenNodeKeySet.has(node.key) || (tree.hiddenNodeKeySet.has(node.key) && nodeClick))
8256
+ return;
8257
+ }
8258
+ console.log('???', checked);
8267
8259
  checkedKeySet[checked ? 'add' : 'delete'](node.key);
8268
8260
  const children = node.children;
8269
8261
  if ((!checkStrictly || checkOnDbclick) && children) {
@@ -8347,7 +8339,9 @@ function useCheck(props, instance) {
8347
8339
  checkedBusinessNodes.push(getNodeData(node));
8348
8340
  }
8349
8341
  // 通道类型业务选中
8350
- else if (business && [Business.CHANNEL, Business.PLAN_GROUP_DEVICE].includes(business) && [DataType.DEVICE, DataType.CHANNEL].includes(data.dataType)) {
8342
+ else if (business &&
8343
+ [Business.CHANNEL, Business.PLAN_GROUP_DEVICE].includes(business) &&
8344
+ [DataType.DEVICE, DataType.CHANNEL].includes(data.dataType)) {
8351
8345
  // 开启通道可选中
8352
8346
  if (props.businessConfig?.isShowChannelSelect) {
8353
8347
  // 通道类型 或 没有通道的设备
@@ -8403,7 +8397,7 @@ function useCheck(props, instance) {
8403
8397
  halfCheckedKeys
8404
8398
  };
8405
8399
  }
8406
- function setCheckedKeys(keys, isBusiness = false) {
8400
+ function setCheckedKeys(keys, isBusiness = false, isForce = false) {
8407
8401
  if (!Array.isArray(keys)) {
8408
8402
  console.warn('setCheckedKeys请传入数组');
8409
8403
  return;
@@ -8414,16 +8408,16 @@ function useCheck(props, instance) {
8414
8408
  if (type === 'radio' && keys.length > 1) {
8415
8409
  keys = [keys[0]];
8416
8410
  }
8417
- _setCheckedKeys(keys, isBusiness);
8411
+ _setCheckedKeys(keys, isBusiness, isForce);
8418
8412
  }
8419
- function setChecked(key, isChecked, isBusiness = false) {
8413
+ function setChecked(key, isChecked, isBusiness = false, isForce = false) {
8420
8414
  if (!tree || !isShowSelect(props))
8421
8415
  return;
8422
8416
  const { treeNodeMap, deviceMap, channelMap, teamMap, userMap, csMap } = tree;
8423
8417
  if (!isBusiness || !props.business) {
8424
8418
  const node = treeNodeMap.get(key);
8425
8419
  if (node) {
8426
- toggleCheckbox(node, isChecked, false);
8420
+ toggleCheckbox(node, isChecked, false, true, true, isForce);
8427
8421
  }
8428
8422
  return;
8429
8423
  }
@@ -8454,10 +8448,10 @@ function useCheck(props, instance) {
8454
8448
  for (const node of nodeList) {
8455
8449
  if (!isShowSelect(props, node))
8456
8450
  continue;
8457
- toggleCheckbox(node, isChecked, false);
8451
+ toggleCheckbox(node, isChecked, false, true, false, isForce);
8458
8452
  }
8459
8453
  }
8460
- function _setCheckedKeys(keys = [], isBusiness = false) {
8454
+ function _setCheckedKeys(keys = [], isBusiness = false, isForce = false) {
8461
8455
  if (!tree)
8462
8456
  return;
8463
8457
  const { treeNodeMap, deviceMap, channelMap, teamMap, userMap, csMap } = tree;
@@ -8468,7 +8462,7 @@ function useCheck(props, instance) {
8468
8462
  if (!isBusiness || !props.business) {
8469
8463
  const node = treeNodeMap.get(key);
8470
8464
  if (node && !isChecked(node) && isShowSelect(props, node)) {
8471
- toggleCheckbox(node, true, false, false);
8465
+ toggleCheckbox(node, true, false, false, false, isForce);
8472
8466
  }
8473
8467
  continue;
8474
8468
  }
@@ -8499,13 +8493,13 @@ function useCheck(props, instance) {
8499
8493
  }
8500
8494
  for (const node of nodeList) {
8501
8495
  if (node && !isChecked(node) && isShowSelect(props, node)) {
8502
- toggleCheckbox(node, true, false, false);
8496
+ toggleCheckbox(node, true, false, false, false, isForce);
8503
8497
  }
8504
8498
  }
8505
8499
  }
8506
8500
  updateCheckedKeys();
8507
8501
  }
8508
- function setCheckedNodes(data, isBusiness = false) {
8502
+ function setCheckedNodes(data, isBusiness = false, isForce = false) {
8509
8503
  if (!Array.isArray(data)) {
8510
8504
  console.warn('setCheckedNodes请传入数组');
8511
8505
  return;
@@ -8516,9 +8510,9 @@ function useCheck(props, instance) {
8516
8510
  if (type === 'radio' && data.length > 1) {
8517
8511
  data = [data[0]];
8518
8512
  }
8519
- _setCheckedNodes(data, isBusiness);
8513
+ _setCheckedNodes(data, isBusiness, isForce);
8520
8514
  }
8521
- function _setCheckedNodes(data = [], isBusiness = false) {
8515
+ function _setCheckedNodes(data = [], isBusiness = false, isForce = false) {
8522
8516
  if (tree) {
8523
8517
  const { treeNodeMap, deviceMap, channelMap, teamMap, userMap, csMap } = tree;
8524
8518
  if (!isShowSelect(props) || !treeNodeMap || !data.length)
@@ -8533,7 +8527,7 @@ function useCheck(props, instance) {
8533
8527
  if (!isBusiness || !props.business) {
8534
8528
  const node = treeNodeMap.get(key);
8535
8529
  if (node && !isChecked(node) && isShowSelect(props, node)) {
8536
- toggleCheckbox(node, true, false, false);
8530
+ toggleCheckbox(node, true, false, false, false, isForce);
8537
8531
  }
8538
8532
  continue;
8539
8533
  }
@@ -8571,7 +8565,7 @@ function useCheck(props, instance) {
8571
8565
  }
8572
8566
  for (const node of nodeList) {
8573
8567
  if (node && !isChecked(node) && isShowSelect(props, node)) {
8574
- toggleCheckbox(node, true, false, false);
8568
+ toggleCheckbox(node, true, false, false, false, isForce);
8575
8569
  }
8576
8570
  }
8577
8571
  }
@@ -9030,7 +9024,7 @@ const generateStats = (data, node) => {
9030
9024
  };
9031
9025
  // 自定义渲染元素
9032
9026
  const customRender = (options) => {
9033
- const { fn, node, parent, className, defaultFn, inset = false } = options || {};
9027
+ const { fn, node, parent, className, defaultFn } = options || {};
9034
9028
  let value;
9035
9029
  // 没有传入的自定义函数则使用默认函数
9036
9030
  if (!fn || !isFunction(fn)) {
@@ -9060,32 +9054,14 @@ const customRender = (options) => {
9060
9054
  return value;
9061
9055
  }
9062
9056
  else if (isElement(value)) {
9063
- if (inset) {
9064
- return createVNode('div', (vnode) => {
9065
- className && vnode.el.classList.add(className);
9066
- vnode.el.appendChild(value);
9067
- });
9068
- }
9069
- else {
9070
- className && value.classList.add(className);
9057
+ return createVNode('div', (vnode) => {
9058
+ className && vnode.el.classList.add(className);
9059
+ vnode.el.appendChild(value);
9060
+ vnode.$destroy = value.$destroy;
9071
9061
  if (parent) {
9072
- if (parent.el) {
9073
- parent.el.appendChild(value);
9074
- }
9075
- const target = {
9076
- el: value,
9077
- destroy: () => {
9078
- // @ts-ignore
9079
- value && value.$destroy && value.$destroy();
9080
- // @ts-ignore
9081
- value && value.destroy && value.destroy();
9082
- }
9083
- };
9084
- if (!parent.children)
9085
- parent.children = [];
9086
- parent.children.push(target);
9062
+ vnode.mount(parent);
9087
9063
  }
9088
- }
9064
+ });
9089
9065
  }
9090
9066
  if (isEmpty(value))
9091
9067
  return;
@@ -9718,16 +9694,16 @@ class VirtualTree {
9718
9694
  this.getCheckedKeys = getCheckedKeys;
9719
9695
  this.getCheckedNodes = getCheckedNodes;
9720
9696
  this.getCheckedBusinessNodes = getCheckedBusinessNodes;
9721
- this.setChecked = (key, isChecked, isBusiness) => {
9722
- setChecked(key, isChecked, isBusiness);
9697
+ this.setChecked = (key, isChecked, isBusiness, isForce) => {
9698
+ setChecked(key, isChecked, isBusiness, isForce);
9723
9699
  this._refreshRender();
9724
9700
  };
9725
- this.setCheckedKeys = (keys, isBusiness) => {
9726
- setCheckedKeys(keys, isBusiness);
9701
+ this.setCheckedKeys = (keys, isBusiness, isForce) => {
9702
+ setCheckedKeys(keys, isBusiness, isForce);
9727
9703
  this._refreshRender();
9728
9704
  };
9729
- this.setCheckedNodes = (data, isBusiness) => {
9730
- setCheckedNodes(data, isBusiness);
9705
+ this.setCheckedNodes = (data, isBusiness, isForce) => {
9706
+ setCheckedNodes(data, isBusiness, isForce);
9731
9707
  this._refreshRender();
9732
9708
  };
9733
9709
  this.setRowSelection = (rowSelection) => {
@@ -9782,7 +9758,6 @@ class VirtualTree {
9782
9758
  statusSlot = customRender({
9783
9759
  fn: config.renderStatus,
9784
9760
  node: item,
9785
- inset: true,
9786
9761
  className: 'hy-tree-node__status',
9787
9762
  defaultFn: (data, node) => {
9788
9763
  return useStatus(config, data);
@@ -9790,7 +9765,7 @@ class VirtualTree {
9790
9765
  });
9791
9766
  }
9792
9767
  // 右侧内容
9793
- rightSlot = customRender({ fn: config.renderRight, node: item, inset: true, className: 'hy-tree-node__right-content' });
9768
+ rightSlot = customRender({ fn: config.renderRight, node: item, className: 'hy-tree-node__right-content' });
9794
9769
  if (!statusSlot && !rightSlot)
9795
9770
  return;
9796
9771
  return createVNode('div', (vnode) => {
@@ -9901,14 +9876,13 @@ class VirtualTree {
9901
9876
  customRender({
9902
9877
  fn: config.renderItem,
9903
9878
  node: item,
9904
- inset: true,
9905
9879
  parent: contentContainer,
9906
9880
  className: 'hy-tree-node__node-content',
9907
9881
  defaultFn: (data, node) => {
9908
9882
  // 图标
9909
- customRender({ fn: config.renderIcon, node, inset: true, parent: contentContainer, className: 'hy-tree-icon', defaultFn: generateIcon });
9883
+ customRender({ fn: config.renderIcon, node, parent: contentContainer, className: 'hy-tree-icon', defaultFn: generateIcon });
9910
9884
  // 内容
9911
- customRender({ fn: config.renderContent, node, inset: true, parent: contentContainer, className: 'hy-tree-node__content', defaultFn: useContent });
9885
+ customRender({ fn: config.renderContent, node, parent: contentContainer, className: 'hy-tree-node__content', defaultFn: useContent });
9912
9886
  // 统计
9913
9887
  if (isShowCount(this._props.showCount, item)) {
9914
9888
  customRender({ fn: generateStats, node, parent: contentContainer });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hy-virtual-tree",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",