@v-c/tree 1.0.3 → 1.0.5

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.
@@ -34,6 +34,8 @@ export interface NodeListProps {
34
34
  onKeyDown?: (e: KeyboardEvent) => void;
35
35
  onFocus?: (e: FocusEvent) => void;
36
36
  onBlur?: (e: FocusEvent) => void;
37
+ onMouseDown?: (e: MouseEvent) => void;
38
+ onMouseUp?: (e: MouseEvent) => void;
37
39
  onActiveChange?: (key: Key | null) => void;
38
40
  onListChangeStart?: () => void;
39
41
  onListChangeEnd?: () => void;
package/dist/NodeList.js CHANGED
@@ -1,8 +1,8 @@
1
- import { getKey, getTreeNodeId, getTreeNodeProps } from "./utils/treeUtil.js";
1
+ import { getKey, getTreeNodeProps } from "./utils/treeUtil.js";
2
2
  import MotionTreeNode_default from "./MotionTreeNode.js";
3
3
  import { findExpandedKeys, getExpandRange } from "./utils/diffUtil.js";
4
4
  import { Fragment, computed, createVNode, defineComponent, mergeProps, ref, shallowRef, watch } from "vue";
5
- import useId from "@v-c/util/dist/hooks/useId";
5
+ import useId, { getId } from "@v-c/util/dist/hooks/useId";
6
6
  import { toPropsRefs } from "@v-c/util/dist/props-util";
7
7
  import VirtualList from "@v-c/virtual-list";
8
8
  function itemKey(item) {
@@ -106,7 +106,7 @@ var NodeList_default = /* @__PURE__ */ defineComponent((props, { attrs, expose }
106
106
  });
107
107
  const mergedData = computed(() => props.motion ? transitionData.value : props.data || []);
108
108
  return () => {
109
- const { motion, activeItem, focusable, disabled, tabIndex, prefixCls, virtual, itemHeight, height, scrollWidth, onScroll, onContextmenu, onKeyDown, onFocus, onBlur, onListChangeStart, onActiveChange } = props;
109
+ const { motion, activeItem, focusable, disabled, tabIndex, prefixCls, virtual, itemHeight, height, scrollWidth, onScroll, onContextmenu, onKeyDown, onFocus, onBlur, onMouseDown, onMouseUp, onListChangeStart, onActiveChange } = props;
110
110
  return createVNode(Fragment, null, [createVNode("div", {
111
111
  "class": `${prefixCls}-treenode`,
112
112
  "aria-hidden": true,
@@ -134,13 +134,15 @@ var NodeList_default = /* @__PURE__ */ defineComponent((props, { attrs, expose }
134
134
  "ref": listRef,
135
135
  "role": "tree",
136
136
  "tabindex": focusable !== false && !disabled ? tabIndex : void 0,
137
- "aria-activedescendant": activeItem ? getTreeNodeId(treeId, activeItem.key) : void 0,
137
+ "aria-activedescendant": activeItem ? getId(treeId, activeItem.key) : void 0,
138
138
  "style": props.style,
139
139
  "onContextmenu": onContextmenu,
140
140
  "onScroll": onScroll,
141
141
  "onKeydown": onKeyDown,
142
142
  "onFocus": onFocus,
143
143
  "onBlur": onBlur,
144
+ "onMousedown": onMouseDown,
145
+ "onMouseup": onMouseUp,
144
146
  "onVisibleChange": (originList) => {
145
147
  if (motionType.value && originList.every((item) => itemKey(item) !== MOTION_KEY)) onMotionEnd();
146
148
  }
@@ -310,6 +312,16 @@ var NodeList_default = /* @__PURE__ */ defineComponent((props, { attrs, expose }
310
312
  required: false,
311
313
  default: void 0
312
314
  },
315
+ onMouseDown: {
316
+ type: Function,
317
+ required: false,
318
+ default: void 0
319
+ },
320
+ onMouseUp: {
321
+ type: Function,
322
+ required: false,
323
+ default: void 0
324
+ },
313
325
  onActiveChange: {
314
326
  type: Function,
315
327
  required: false,
package/dist/Tree.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { VueNode } from '@v-c/util/dist/type';
2
2
  import { CSSMotionProps } from '@v-c/util/dist/utils/transition';
3
3
  import { CSSProperties } from 'vue';
4
- import { DraggableConfig, NodeDragEventParams, NodeMouseEventHandler, NodeMouseEventParams } from './contextTypes';
4
+ import { DraggableConfig, NodeDragEventParams, NodeMouseEventHandler, NodeMouseEventParams, SemanticName } from './contextTypes';
5
5
  import { BasicDataNode, DataNode, Direction, EventDataNode, FieldNames, IconType, Key, ScrollTo } from './interface';
6
6
  import { AllowDrop } from './util';
7
7
  export interface CheckInfo<TreeDataType extends BasicDataNode = DataNode> {
@@ -19,12 +19,13 @@ export interface CheckInfo<TreeDataType extends BasicDataNode = DataNode> {
19
19
  export type DraggableFn = (node: DataNode) => boolean;
20
20
  export type DraggableUnion = DraggableFn | boolean | DraggableConfig;
21
21
  export type ExpandAction = false | 'click' | 'doubleClick';
22
+ export type { SemanticName } from './contextTypes';
22
23
  export interface TreeProps<TreeDataType extends BasicDataNode = DataNode> {
23
24
  prefixCls?: string;
24
25
  className?: string;
25
26
  style?: CSSProperties;
26
- styles?: Partial<Record<'itemIcon' | 'item' | 'itemTitle', CSSProperties>>;
27
- classNames?: Partial<Record<'itemIcon' | 'item' | 'itemTitle', string>>;
27
+ styles?: Partial<Record<SemanticName, CSSProperties>>;
28
+ classNames?: Partial<Record<SemanticName, string>>;
28
29
  focusable?: boolean;
29
30
  activeKey?: Key | null;
30
31
  tabIndex?: number;
@@ -61,6 +62,8 @@ export interface TreeProps<TreeDataType extends BasicDataNode = DataNode> {
61
62
  prefixCls: string;
62
63
  direction: Direction;
63
64
  }) => any;
65
+ onMouseDown?: (e: MouseEvent) => void;
66
+ onMouseUp?: (e: MouseEvent) => void;
64
67
  onFocus?: (e: FocusEvent) => void;
65
68
  onBlur?: (e: FocusEvent) => void;
66
69
  onKeyDown?: (e: KeyboardEvent) => void;
package/dist/Tree.js CHANGED
@@ -177,7 +177,7 @@ var Tree_default = /* @__PURE__ */ defineComponent((props, { slots, attrs, expos
177
177
  const delayedDragEnterLogic = {};
178
178
  const loadingRetryTimes = {};
179
179
  const listRef = ref();
180
- let focusFromMouse = false;
180
+ let focusedByMouse = false;
181
181
  const getTreeNodeRequiredProps = computed(() => ({
182
182
  expandedKeys: expandedKeys.value || [],
183
183
  selectedKeys: selectedKeys.value || [],
@@ -219,12 +219,7 @@ var Tree_default = /* @__PURE__ */ defineComponent((props, { slots, attrs, expos
219
219
  onActiveChange(item ? item.key : null);
220
220
  }
221
221
  function onFocus(e) {
222
- if (focusFromMouse) {
223
- focusFromMouse = false;
224
- props.onFocus?.(e);
225
- return;
226
- }
227
- if (!mergedDisabled.value && activeKey.value === null) {
222
+ if (!focusedByMouse && !mergedDisabled.value && activeKey.value === null) {
228
223
  const visibleSelectedKey = selectedKeys.value.find((key) => {
229
224
  return flattenNodes.value.some((nodeItem) => nodeItem.key === key);
230
225
  });
@@ -234,10 +229,18 @@ var Tree_default = /* @__PURE__ */ defineComponent((props, { slots, attrs, expos
234
229
  props.onFocus?.(e);
235
230
  }
236
231
  function onBlur(e) {
237
- focusFromMouse = false;
232
+ focusedByMouse = false;
238
233
  onActiveChange(null);
239
234
  props.onBlur?.(e);
240
235
  }
236
+ function onMouseDown(e) {
237
+ focusedByMouse = true;
238
+ props.onMouseDown?.(e);
239
+ }
240
+ function onMouseUp(e) {
241
+ focusedByMouse = false;
242
+ props.onMouseUp?.(e);
243
+ }
241
244
  function onNodeLoad(treeNode) {
242
245
  const key = treeNode.key;
243
246
  if (getEntity(keyEntities.value, key)?.children?.length) return;
@@ -719,12 +722,6 @@ var Tree_default = /* @__PURE__ */ defineComponent((props, { slots, attrs, expos
719
722
  data: true
720
723
  });
721
724
  return createVNode("div", {
722
- "onMousedown": () => {
723
- focusFromMouse = true;
724
- },
725
- "onMouseup": () => {
726
- focusFromMouse = false;
727
- },
728
725
  "class": clsx(mergedPrefixCls.value, props.className, props.rootClassName, { [`${mergedPrefixCls.value}-show-line`]: mergedShowLine.value }),
729
726
  "style": props.rootStyle
730
727
  }, [createVNode(NodeList_default, mergeProps({
@@ -744,6 +741,8 @@ var Tree_default = /* @__PURE__ */ defineComponent((props, { slots, attrs, expos
744
741
  "tabIndex": mergedTabIndex.value,
745
742
  "activeItem": getActiveItem.value,
746
743
  "onFocus": onFocus,
744
+ "onMouseDown": onMouseDown,
745
+ "onMouseUp": onMouseUp,
747
746
  "onBlur": onBlur,
748
747
  "onKeyDown": onKeyDown,
749
748
  "onActiveChange": onActiveChange,
@@ -940,6 +939,16 @@ var Tree_default = /* @__PURE__ */ defineComponent((props, { slots, attrs, expos
940
939
  required: false,
941
940
  default: void 0
942
941
  },
942
+ onMouseDown: {
943
+ type: Function,
944
+ required: false,
945
+ default: void 0
946
+ },
947
+ onMouseUp: {
948
+ type: Function,
949
+ required: false,
950
+ default: void 0
951
+ },
943
952
  onFocus: {
944
953
  type: Function,
945
954
  required: false,
package/dist/TreeNode.js CHANGED
@@ -118,12 +118,16 @@ var TreeNode = /* @__PURE__ */ defineComponent((props, { attrs }) => {
118
118
  const renderSwitcher = () => {
119
119
  if (memoizedIsLeaf.value) {
120
120
  const switcherIconDom$1 = renderSwitcherIconDom(true);
121
- return switcherIconDom$1 !== false ? createVNode("span", { "class": clsx(`${context.prefixCls}-switcher`, `${context.prefixCls}-switcher-noop`) }, [switcherIconDom$1]) : null;
121
+ return switcherIconDom$1 !== false ? createVNode("span", {
122
+ "class": clsx(`${context.prefixCls}-switcher`, `${context.prefixCls}-switcher-noop`, context.classNames?.itemSwitcher),
123
+ "style": context.styles?.itemSwitcher
124
+ }, [switcherIconDom$1]) : null;
122
125
  }
123
126
  const switcherIconDom = renderSwitcherIconDom(false);
124
127
  return switcherIconDom !== false ? createVNode("span", {
125
128
  "onClick": onExpand,
126
- "class": clsx(`${context.prefixCls}-switcher`, `${context.prefixCls}-switcher_${props.expanded ? ICON_OPEN : ICON_CLOSE}`)
129
+ "class": clsx(`${context.prefixCls}-switcher`, `${context.prefixCls}-switcher_${props.expanded ? ICON_OPEN : ICON_CLOSE}`, context.classNames?.itemSwitcher),
130
+ "style": context.styles?.itemSwitcher
127
131
  }, [switcherIconDom]) : null;
128
132
  };
129
133
  const iconNode = computed(() => {
@@ -23,7 +23,7 @@ export interface DropIndicatorRenderProps {
23
23
  prefixCls: string;
24
24
  direction: Direction;
25
25
  }
26
- export type SemanticName = 'itemIcon' | 'item' | 'itemTitle';
26
+ export type SemanticName = 'itemIcon' | 'item' | 'itemTitle' | 'itemSwitcher';
27
27
  export interface TreeContextProps<TreeDataType extends BasicDataNode = DataNode> {
28
28
  styles?: Partial<Record<SemanticName, CSSProperties>>;
29
29
  classNames?: Partial<Record<SemanticName, string>>;
@@ -61,5 +61,4 @@ export declare function getTreeNodeProps<TreeDataType extends BasicDataNode = Da
61
61
  };
62
62
  export declare function convertNodePropsToEventData<TreeDataType extends BasicDataNode = DataNode>(props: TreeNodeProps<TreeDataType>): EventDataNode<TreeDataType>;
63
63
  export declare function isLeafNode<TreeDataType extends BasicDataNode = DataNode>(isLeaf: boolean | undefined, loadData: ((node: EventDataNode<TreeDataType>) => Promise<any>) | undefined, hasChildren: boolean, loaded: boolean | undefined): boolean;
64
- export declare function getTreeNodeId(treeId: string, key: Key): string;
65
64
  export {};
@@ -215,7 +215,4 @@ function isLeafNode(isLeaf, loadData, hasChildren, loaded) {
215
215
  if (isLeaf === false) return false;
216
216
  return !!isLeaf || !loadData && !hasChildren || !!(loadData && loaded && !hasChildren);
217
217
  }
218
- function getTreeNodeId(treeId, key) {
219
- return `${treeId}-${key}`;
220
- }
221
- export { convertDataToEntities, convertNodePropsToEventData, convertTreeToData, fillFieldNames, flattenTreeData, getKey, getPosition, getTreeNodeId, getTreeNodeProps, isLeafNode, isTreeNode, traverseDataNodes, warningWithoutKey };
218
+ export { convertDataToEntities, convertNodePropsToEventData, convertTreeToData, fillFieldNames, flattenTreeData, getKey, getPosition, getTreeNodeProps, isLeafNode, isTreeNode, traverseDataNodes, warningWithoutKey };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/tree",
3
3
  "type": "module",
4
- "version": "1.0.3",
4
+ "version": "1.0.5",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -29,8 +29,8 @@
29
29
  "vue": "^3.0.0"
30
30
  },
31
31
  "dependencies": {
32
- "@v-c/util": "^1.0.14",
33
- "@v-c/virtual-list": "^1.0.5"
32
+ "@v-c/util": "^1.0.18",
33
+ "@v-c/virtual-list": "^1.0.6"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "vite build",