@v-c/tree 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Tree.js CHANGED
@@ -85,20 +85,22 @@ var Tree = /* @__PURE__ */ defineComponent((props, { slots, attrs, expose }) =>
85
85
  const setExpandedKeys = (keys) => {
86
86
  expandedKeys.value = keys;
87
87
  };
88
- watch(() => props.expandedKeys, () => {
89
- if (props.expandedKeys === void 0) return;
90
- const keys = props.expandedKeys || [];
88
+ watch(() => [props.expandedKeys, props.autoExpandParent], ([keys], [prevKeys]) => {
89
+ if (keys === void 0) {
90
+ if (prevKeys !== void 0) expandedKeys.value = [];
91
+ return;
92
+ }
93
+ const nextKeys = keys ?? [];
91
94
  if (props.autoExpandParent) {
92
- expandedKeys.value = conductExpandParent(keys, keyEntities.value);
95
+ expandedKeys.value = conductExpandParent(nextKeys, keyEntities.value);
93
96
  return;
94
97
  }
95
- expandedKeys.value = keys;
98
+ expandedKeys.value = nextKeys;
96
99
  });
97
100
  const flattenNodes = computed(() => flattenTreeData(mergedTreeData.value, expandedKeys.value, mergedFieldNames.value));
98
101
  const selectedKeys = shallowRef(calcSelectedKeys(props?.selectedKeys || props.defaultSelectedKeys || [], { multiple: mergedMultiple.value }) || []);
99
102
  watch(() => props.selectedKeys, () => {
100
- if (props.selectedKeys === void 0) return;
101
- selectedKeys.value = calcSelectedKeys(props.selectedKeys, { multiple: mergedMultiple.value }) || [];
103
+ selectedKeys.value = calcSelectedKeys(props.selectedKeys ?? [], { multiple: mergedMultiple.value }) || [];
102
104
  });
103
105
  const setSelectedKeys = (keys) => {
104
106
  selectedKeys.value = keys;
@@ -120,8 +122,7 @@ var Tree = /* @__PURE__ */ defineComponent((props, { slots, attrs, expose }) =>
120
122
  rawCheckedKeys.value = keys;
121
123
  };
122
124
  watch(() => props.checkedKeys, () => {
123
- if (props.checkedKeys === void 0) return;
124
- const parsed = parseCheckedKeys(props.checkedKeys);
125
+ const parsed = props.checkedKeys === void 0 ? null : parseCheckedKeys(props.checkedKeys);
125
126
  rawCheckedKeys.value = parsed?.checkedKeys || [];
126
127
  });
127
128
  const rawHalfCheckedKeys = shallowRef(defaultCheckedKeyEntity.halfCheckedKeys);
@@ -129,8 +130,7 @@ var Tree = /* @__PURE__ */ defineComponent((props, { slots, attrs, expose }) =>
129
130
  rawHalfCheckedKeys.value = keys;
130
131
  };
131
132
  watch(() => props.checkedKeys, () => {
132
- if (props.checkedKeys === void 0) return;
133
- const parsed = parseCheckedKeys(props.checkedKeys);
133
+ const parsed = props.checkedKeys === void 0 ? null : parseCheckedKeys(props.checkedKeys);
134
134
  rawHalfCheckedKeys.value = parsed?.halfCheckedKeys || [];
135
135
  });
136
136
  const mergedChecked = computed(() => {
@@ -152,10 +152,16 @@ var Tree = /* @__PURE__ */ defineComponent((props, { slots, attrs, expose }) =>
152
152
  halfCheckedKeys: halfCheckedKeysValue
153
153
  };
154
154
  });
155
- const [loadedKeys, setLoadedKeys] = useMergedState(() => [], { value: computed(() => props.loadedKeys === void 0 ? void 0 : props.loadedKeys) });
155
+ const [loadedKeys, setLoadedKeys] = useMergedState(() => [], {
156
+ value: computed(() => props.loadedKeys === void 0 ? void 0 : props.loadedKeys),
157
+ postState: (keys) => keys ?? []
158
+ });
156
159
  const loadingKeys = ref([]);
157
160
  const listChanging = ref(false);
158
- const [activeKey, setActiveKey] = useMergedState(null, { value: computed(() => props.activeKey === void 0 ? void 0 : props.activeKey) });
161
+ const [activeKey, setActiveKey] = useMergedState(null, {
162
+ value: computed(() => props.activeKey === void 0 ? void 0 : props.activeKey),
163
+ postState: (key) => key ?? null
164
+ });
159
165
  function onListChangeStart() {
160
166
  listChanging.value = true;
161
167
  }
@@ -177,8 +183,14 @@ var Tree = /* @__PURE__ */ defineComponent((props, { slots, attrs, expose }) =>
177
183
  let dragNodeProps = null;
178
184
  let dragStartMousePosition = null;
179
185
  let currentMouseOverDroppableNodeKey = null;
180
- const delayedDragEnterLogic = {};
186
+ let delayedDragEnterLogic = {};
181
187
  const loadingRetryTimes = {};
188
+ const clearDelayedDragEnterLogic = () => {
189
+ Object.values(delayedDragEnterLogic).forEach((timeoutId) => {
190
+ clearTimeout(timeoutId);
191
+ });
192
+ delayedDragEnterLogic = {};
193
+ };
182
194
  const listRef = ref();
183
195
  let focusedByMouse = false;
184
196
  const getTreeNodeRequiredProps = computed(() => ({
@@ -223,7 +235,7 @@ var Tree = /* @__PURE__ */ defineComponent((props, { slots, attrs, expose }) =>
223
235
  onActiveChange(item ? item.key : null);
224
236
  }
225
237
  function onFocus(e) {
226
- if (!focusedByMouse && !mergedDisabled.value && activeKey.value === null) {
238
+ if (e.target === e.currentTarget && !focusedByMouse && !mergedDisabled.value && activeKey.value === null) {
227
239
  const visibleSelectedKey = selectedKeys.value.find((key) => {
228
240
  return flattenNodes.value.some((nodeItem) => nodeItem.key === key);
229
241
  });
@@ -433,11 +445,9 @@ var Tree = /* @__PURE__ */ defineComponent((props, { slots, attrs, expose }) =>
433
445
  window.addEventListener("mouseup", onGlobalMouseUp);
434
446
  });
435
447
  onBeforeUnmount(() => {
448
+ clearDelayedDragEnterLogic();
436
449
  window.removeEventListener("dragend", onWindowDragEnd);
437
450
  window.removeEventListener("mouseup", onGlobalMouseUp);
438
- Object.keys(delayedDragEnterLogic).forEach((key) => {
439
- clearTimeout(delayedDragEnterLogic[key]);
440
- });
441
451
  });
442
452
  const onNodeDragStart = (event, nodeProps) => {
443
453
  dragNodeProps = nodeProps;
@@ -468,9 +478,7 @@ var Tree = /* @__PURE__ */ defineComponent((props, { slots, attrs, expose }) =>
468
478
  resetDragState();
469
479
  return;
470
480
  }
471
- Object.keys(delayedDragEnterLogic).forEach((key) => {
472
- clearTimeout(delayedDragEnterLogic[key]);
473
- });
481
+ clearDelayedDragEnterLogic();
474
482
  if (dragNodeProps.eventKey !== nodeProps.eventKey) delayedDragEnterLogic[pos] = window.setTimeout(() => {
475
483
  if (draggingNodeKey.value === null) return;
476
484
  let newExpandedKeys = [...expandedKeys.value];
package/dist/TreeNode.js CHANGED
@@ -3,7 +3,7 @@ import { TreeContextKey, UnstableContextKey } from "./contextTypes.js";
3
3
  import getEntity from "./utils/keyUtil.js";
4
4
  import { convertNodePropsToEventData, isLeafNode } from "./utils/treeUtil.js";
5
5
  import { computed, createVNode, defineComponent, inject, mergeProps, ref, watchEffect } from "vue";
6
- import { clsx } from "@v-c/util";
6
+ import { clsx, isVueRenderable } from "@v-c/util";
7
7
  import { getId } from "@v-c/util/dist/hooks/useId";
8
8
  import pickAttrs from "@v-c/util/dist/pickAttrs";
9
9
  import { filterEmpty } from "@v-c/util/dist/props-util";
@@ -173,8 +173,8 @@ var TreeNode = /* @__PURE__ */ defineComponent((props, { attrs }) => {
173
173
  const wrapClass = `${context.prefixCls}-node-content-wrapper`;
174
174
  let icon;
175
175
  if (context.showIcon) {
176
- const currentIcon = props.icon || context.icon;
177
- icon = currentIcon ? createVNode("span", {
176
+ const currentIcon = isVueRenderable(props.icon) ? props.icon : context.icon;
177
+ icon = isVueRenderable(currentIcon) ? createVNode("span", {
178
178
  "class": clsx(context.classNames?.itemIcon, `${context.prefixCls}-iconEle`, `${context.prefixCls}-icon__customize`),
179
179
  "style": context.styles?.itemIcon
180
180
  }, [typeof currentIcon === "function" ? currentIcon(props) : currentIcon]) : iconNode.value;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/tree",
3
3
  "type": "module",
4
- "version": "1.2.1",
4
+ "version": "1.2.2",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -34,7 +34,7 @@
34
34
  "vue": "^3.0.0"
35
35
  },
36
36
  "dependencies": {
37
- "@v-c/util": "^1.1.0",
37
+ "@v-c/util": "^1.2.0",
38
38
  "@v-c/virtual-list": "^1.1.1"
39
39
  },
40
40
  "scripts": {