amazing-tree 1.2.4 → 1.3.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 [Maxkang]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,25 +1,28 @@
1
1
  # AmazingTree (Vue 3)
2
2
 
3
- > :warning:该组件因设计需求,是非受控组件,组件的拖拽功能会修改树形数据 `props.data`
4
- > 使用需谨慎
5
-
6
3
  一个高性能、可拖拽、可选择的虚拟滚动树组件,支持泛型类型自动推导,适合在大型数据集下渲染与交互。
7
4
 
5
+ > :warning:该组件因设计需求,是非受控组件,组件的拖拽功能会修改树形数据 `props.data`,使用需谨慎
6
+
8
7
  **特性**
9
8
 
10
- - 虚拟滚动渲染,平滑滚动与自动测量行高
9
+ - 虚拟滚动渲染,平滑滚动与自动测量行高(20w节点无压力)
11
10
  - 可选中(复选框),支持父子联动或严格模式
11
+ - 可筛选,可快速定位节点
12
12
  - 拖拽换位与嵌套,提供前置、后置、内部三种放置方式
13
- - 泛型组件:从 `data` 推导节点业务类型 `T`,事件与插槽类型随之推导
13
+ - 支持自定义内容(节点插槽和空数据占位插槽)
14
+ - 支持自定义拖拽/释放禁用逻辑
14
15
  - 轻量依赖,仅依赖 `vue`
15
16
 
16
17
  **安装**
17
18
 
18
- - 待发布到 npm 后:`npm i amazing-tree`
19
- - 当前仓库本地打包:`npm run build:lib`,产物在 `dist/`
19
+ - `npm i amazing-tree`
20
20
 
21
21
  **使用**
22
22
 
23
+ > 导入组件 `import { AmazingTree } from 'amazing-tree'`
24
+ > 导入样式:`import 'amazing-tree/style.css'`
25
+
23
26
  - 基本示例
24
27
 
25
28
  ```vue
@@ -30,6 +33,12 @@ import 'amazing-tree/style.css'
30
33
 
31
34
  type NodeItem = { uuid: string; name: string; children?: NodeItem[]; [k: string]: unknown }
32
35
  const data = ref<NodeItem[]>([])
36
+ const filterName = ref('')
37
+ const filterNodeMethod = (q: unknown, node: NodeItem) => {
38
+ const s = String(q || '')
39
+ if (!s) return true
40
+ return node.name.includes(s)
41
+ }
33
42
 
34
43
  function onDrop(drag: NodeItem, target: NodeItem, type: 'prev' | 'next' | 'inner') {
35
44
  console.log(drag, target, type)
@@ -40,80 +49,66 @@ function onDrop(drag: NodeItem, target: NodeItem, type: 'prev' | 'next' | 'inner
40
49
  <AmazingTree
41
50
  :data="data"
42
51
  :props="{ value: 'uuid', label: 'name', children: 'children' }"
52
+ :filter-node-method="filterNodeMethod"
43
53
  :show-checkbox="true"
44
54
  :check-strictly="false"
45
55
  :default-checked-keys="['id-1', 'id-2']"
46
56
  @node-drop="onDrop"
47
57
  />
58
+ <input v-model="filterName" placeholder="输入名称筛选" />
59
+ <button @click="$refs.tree?.filter(filterName)">筛选</button>
48
60
  </template>
49
61
  ```
50
62
 
51
- > 使用时请显式导入样式:`import 'amazing-tree/style.css'`
52
-
53
63
  **Props**
54
64
 
55
- - `data: T[]` 树数据源
56
- - `props?: { value: string; label: string; children: string }` 字段映射,默认 `{ value:'value', label:'label', children:'children' }`
57
- - `allowDrag?: (node: T) => boolean` 是否允许拖拽某节点
58
- - `allowDrop?: (drag: T, drop: T, type: 'prev'|'next'|'inner') => boolean` 是否允许目标位置
59
- - `height?: number | string` 容器高度,默认 `100%`
60
- - `highlightColor?: string` 选中行高亮色,默认 `#1e71ff`
61
- - `backgroundColor?: string` 背景色,默认 `#1d1d24`
62
- - `textColor?: string` 文本色,默认 `#c8d3de`
63
- - `hoverColor?: string` 悬浮色,默认 `#5d90e5`
64
- - `currentNodeKey?: Key` 当前行的 `value`
65
- - `defaultExpandedKeys?: Key[]` 默认展开的节点 `value` 列表
66
- - `defaultExpandAll?: boolean` 是否默认全部展开
67
- - `draggable?: boolean` 是否允许拖拽,默认 `false`
68
- - `emptyText?: string` 空状态文案,默认 `暂无数据`
69
- - `showCheckbox?: boolean` 是否显示复选框,默认 `false`
70
- - `checkStrictly?: boolean` 选择严格模式,父子不联动,默认 `false`
71
- - `defaultCheckedKeys?: Key[]` 默认勾选的 `value` 列表,默认 `[]`
72
- - `disabledChecked?: (node: T) => boolean` 是否禁用当前节点复选框,默认 `false`
65
+ | 属性名 | 说明 | 类型 | 默认值 | 是否可选 |
66
+ | --------------------- | --------------------------- | -------------------------------------------------------------- | ------------------------------------------------------- | -------- |
67
+ | `data` | 树数据源 | `T[]` | — | 否 |
68
+ | `props` | 字段映射 | `{ value: string; label: string; children: string }` | `{ value:'value', label:'label', children:'children' }` | 是 |
69
+ | `allowDrag` | 是否允许拖拽某节点 | `(node: T) => boolean` | — | 是 |
70
+ | `allowDrop` | 是否允许目标位置 | `(drag: T, drop: T, type: 'prev'\|'next'\|'inner') => boolean` | — | 是 |
71
+ | `height` | 容器高度 | `number \| string` | `'100%'` | 是 |
72
+ | `highlightColor` | 选中行高亮色 | `string` | `'#1e71ff'` | 是 |
73
+ | `backgroundColor` | 背景色 | `string` | `'#1d1d24'` | 是 |
74
+ | `textColor` | 文本色 | `string` | `'#c8d3de'` | 是 |
75
+ | `hoverColor` | 悬浮色 | `string` | `'#5d90e5'` | 是 |
76
+ | `currentNodeKey` | 当前行的 `value` | `Key` | — | 是 |
77
+ | `defaultExpandedKeys` | 默认展开的节点 `value` 列表 | `Key[]` | — | 是 |
78
+ | `defaultExpandAll` | 是否默认全部展开 | `boolean` | — | 是 |
79
+ | `draggable` | 是否允许拖拽 | `boolean` | `false` | 是 |
80
+ | `emptyText` | 空状态文案 | `string` | `'暂无数据'` | 是 |
81
+ | `showCheckbox` | 是否显示复选框 | `boolean` | `false` | 是 |
82
+ | `checkStrictly` | 选择严格模式,父子不联动 | `boolean` | `false` | 是 |
83
+ | `defaultCheckedKeys` | 默认勾选的 `value` 列表 | `Key[]` | `[]` | 是 |
84
+ | `disabledChecked` | 是否禁用当前节点复选框 | `(node: T) => boolean` | — | 是 |
85
+ | `filterNodeMethod` | 过滤方法(返回 false 隐藏) | `(value: unknown, node: T) => boolean` | — | 是 |
73
86
 
74
87
  **Events**
75
88
 
76
- - `node-click(node: T, ev: MouseEvent)` 点击行
77
- - `node-contextmenu(node: T, ev: MouseEvent)` 右键菜单
78
- - `node-drop(drag: T, target: T, type: 'prev'|'next'|'inner')` 拖拽放置
79
- - `current-change(node: T)` 当前行变化(配合 `currentNodeKey`)
80
- - `check-change(node: T, checked: boolean)` 勾选框点击时触发;禁用状态不触发
89
+ | 事件名 | 说明 | 回调参数 |
90
+ | ------------------ | ----------------------------------- | --------------------------------------------------------- |
91
+ | `node-click` | 点击行 | `(node: T, ev: MouseEvent)` |
92
+ | `node-contextmenu` | 右键菜单 | `(node: T, ev: MouseEvent)` |
93
+ | `node-drop` | 拖拽放置 | `(drag: T, target: T, type: 'prev' \| 'next' \| 'inner')` |
94
+ | `current-change` | 当前行变化(配合 `currentNodeKey`) | `(node: T)` |
95
+ | `check-change` | 勾选框点击时触发;禁用状态不触发 | `(node: T, checked: boolean)` |
81
96
 
82
97
  **Slots**
83
98
 
84
- - `default`:`{ node: T; data: T; level: number; expanded: boolean; isLeaf: boolean }`
85
- - `empty`:空状态自定义
86
-
87
- **Expose API**
88
-
89
- - `getCurrentKey(): Key | null` 获取当前行 `value`
90
- - `setCurrentKey(id: Key | null): void` 设置当前行并滚动可见
91
- - `scrollTo(id: Key | null): void` 滚动到指定行(自动展开祖先)
92
- - `getCheckedKeys(): Key[]` 获取当前勾选集合
93
- - `setCheckedKeys(keys: Key[]): void` 批量设置勾选(应用联动/严格逻辑)
94
- - `setChecked(id: Key, checked: boolean): void` 设置单个节点勾选状态
95
-
96
- **类型与泛型**
97
-
98
- - 组件声明为泛型:`generic="T extends Record<string, unknown>"`
99
- - `T` 会从 `data: T[]` 自动推导,事件与插槽参数均按 `T` 类型约束
100
- - 在模板中若需要强类型事件回调,可在脚本中声明具体 `T`(例如 `NodeItem`)并书写对应函数签名
101
-
102
- **样式**
103
-
104
- - 复选框遵循暗色主题风格,支持禁用态 `cursor:not-allowed`,可通过 CSS 变量定制:
105
- - `--vtree-primary` 主色(默认 `#409eff`)
106
- - `--vtree-checkbox-*` 系列变量控制背景、边框、禁用与勾选颜色
107
-
108
- **构建与发布**
109
-
110
- - 开发:`npm run dev`
111
- - 类型检查:`npm run type-check`
112
- - 构建应用:`npm run build`
113
- - 构建库:`npm run build:lib`(生成 `dist/amazing-tree.es.js`、`amazing-tree.cjs.js`、`amazing-tree.umd.js`)
114
- - 发布到 npm:在确认 `package.json` 中 `name`、`version`、`files`、`exports` 配置正确后执行 `npm publish`
115
-
116
- **注意事项**
117
-
118
- - 库构建将 `vue` 作为外部依赖,使用方需自行安装 `vue@^3.5`
119
- - 若需要声明文件(`.d.ts`),可引入 `vite-plugin-dts` 或单独生成并随包发布
99
+ | 插槽名 | 插槽参数 |
100
+ | --------- | ------------------------------------------------------------------------- |
101
+ | `default` | `{ node: T; data: T; level: number; expanded: boolean; isLeaf: boolean }` |
102
+ | `empty` | —(空状态自定义) |
103
+
104
+ **Exposes**
105
+
106
+ | 方法名 | 说明 | 返回类型 |
107
+ | ---------------- | --------------------------------- | ------------------------------------- |
108
+ | `getCurrentKey` | 获取当前行 `value` | `Key \| null` |
109
+ | `setCurrentKey` | 设置当前行并滚动可见 | `(id: Key \| null) => void` |
110
+ | `scrollTo` | 滚动到指定行(自动展开祖先) | `(id: Key \| null) => void` |
111
+ | `getCheckedKeys` | 获取当前勾选集合 | `Key[]` |
112
+ | `setCheckedKeys` | 批量设置勾选(应用联动/严格逻辑) | `(keys: Key[]) => void` |
113
+ | `setChecked` | 设置单个节点勾选状态 | `(id: Key, checked: boolean) => void` |
114
+ | `filter` | 触发过滤,参数作为回调第 1 个参数 | `(value: unknown) => void` |
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),Me=["onMousedown","onClick","onContextmenu"],Ae=["onClick"],Ke=["checked","indeterminate","disabled","onClick"],Ie={class:"amazing-tree-label"},Le={key:1,class:"amazing-tree-empty"},Ne={class:"amazing-tree-empty-inner"},H=28,Re=t.defineComponent({__name:"AmazingTree",props:{data:{},props:{default:()=>({value:"value",label:"label",children:"children"})},allowDrag:{},allowDrop:{},height:{default:void 0},highlightColor:{default:"#1e71ff"},backgroundColor:{default:"#1d1d24"},textColor:{default:"#c8d3de"},hoverColor:{default:"#5d90e5"},currentNodeKey:{},defaultExpandedKeys:{},defaultExpandAll:{type:Boolean,default:!1},draggable:{type:Boolean,default:!1},emptyText:{default:"暂无数据"},showCheckbox:{type:Boolean,default:!1},checkStrictly:{type:Boolean,default:!1},defaultCheckedKeys:{default:()=>[]},disabledChecked:{}},emits:["node-click","node-contextmenu","node-drop","current-change","check-change"],setup(m,{expose:j,emit:Y}){const a=m,M=Y,de=t.computed(()=>a.props.value||"value"),ve=t.computed(()=>a.props.label||"label"),_=t.computed(()=>a.props.children||"children"),fe=t.computed(()=>Array.isArray(a.data)?a.data.length===0:!0),y=t.ref(new Set),h=t.ref(new Set),p=t.ref(new Set);function ee(e){return y.value.has(e)}function he(e){y.value.has(e)?y.value.delete(e):y.value.add(e),i.value=C(a.data||[]),t.nextTick(()=>{B(),k()})}function w(e){return e[de.value]}function z(e){const n=e[_.value];return Array.isArray(n)?n:[]}function me(e){return h.value.has(e)}function pe(e){return p.value.has(e)}function G(e,n){if(n?h.value.add(e):h.value.delete(e),p.value.delete(e),!a.checkStrictly){const l=Z(e,a.data||[]);if(l){const o=[l];for(;o.length;){const r=o.pop(),c=w(r);n?h.value.add(c):h.value.delete(c),p.value.delete(c);const f=z(r);for(const s of f)o.push(s)}const u=q(e,a.data||[])||[];for(const r of u){const c=w(r),f=z(r);let s=!0,d=!1;for(const x of f){const $=w(x),re=h.value.has($),ie=p.value.has($);(re||ie)&&(d=!0),(!re||ie)&&(s=!1)}f.length===0?(h.value.has(c),p.value.delete(c)):s?(h.value.add(c),p.value.delete(c)):d?(h.value.delete(c),p.value.add(c)):(h.value.delete(c),p.value.delete(c))}}}}function te(e){h.value=new Set,p.value=new Set;for(const n of e||[])G(n,!0)}function ge(e,n){const l=n.target;a.disabledChecked&&a.disabledChecked(e.node)||(M("check-change",e.node,!!l.checked),G(e.id,!!l.checked))}function C(e){const n=[];function l(o,u,r){for(let c=0;c<o.length;c++){const f=o[c],s=w(f),d=z(f),x=d.length===0;n.push({id:s,node:f,parent:u,level:r,index:c,isLeaf:x}),!x&&y.value.has(s)&&l(d,f,r+1)}}return l(e,null,0),n}const v=t.ref(null),E=t.ref(0),R=t.ref(0),i=t.ref([]),A=t.reactive(new Map),g=t.computed(()=>{let e=0;const n=[];for(const l of i.value){const o=A.get(l.id)||H;e+=o,n.push(e)}return n}),ne=t.computed(()=>{const e=g.value;return e.length?e[e.length-1]:0});function le(e){let n=0,l=g.value.length-1,o=0;for(;n<=l;){const u=n+l>>1;g.value[u]!==void 0&&g.value[u]>=e?(o=u,l=u-1):n=u+1}return o}const K=t.ref(0),b=t.ref(0),I=t.ref(0),J=t.ref(0);function k(){if(R.value=v.value?.clientHeight||0,g.value.length===0||i.value.length===0){K.value=0,b.value=0,I.value=0,J.value=0;return}const e=le(E.value);K.value=Math.max(0,e-3);const n=i.value[K.value],l=n?A.get(n.id)||H:0,u=(g.value[K.value]??0)-l;I.value=Math.max(0,u);let r=K.value;const c=E.value+R.value+3*H;for(;r<i.value.length&&(g.value[r]??0)<c;)r++;b.value=Math.min(i.value.length,r+1);const s=(g.value[b.value-1]??0)-I.value;if(s<R.value&&b.value<i.value.length){let d=b.value,x=s;for(;x<R.value&&d<i.value.length;)d++,x=(g.value[d-1]??0)-I.value;b.value=d}J.value=Math.max(0,ne.value-I.value-((g.value[b.value-1]??0)-I.value))}t.watch([E,()=>a.data,y],()=>{i.value=C(a.data||[]),t.nextTick(B),k()}),t.onMounted(()=>{i.value=C(a.data||[]),t.nextTick(B),k(),a.defaultCheckedKeys&&a.defaultCheckedKeys.length&&te(a.defaultCheckedKeys),v.value&&(V=new ResizeObserver(()=>{R.value=v.value?.clientHeight||0,k()}),V.observe(v.value))});let V=null;t.onUnmounted(()=>{V&&(V.disconnect(),V=null)});const O=t.reactive(new Map);function ke(e,n){n?O.set(e,n):O.delete(e)}function B(){let e=!1;for(const n of i.value.slice(K.value,b.value)){const l=O.get(n.id);if(l){const o=l.offsetHeight;(!A.has(n.id)||A.get(n.id)!==o)&&(A.set(n.id,o),e=!0)}}e&&k()}function xe(){E.value=v.value?.scrollTop||0,k()}const S=t.ref(!1),Q=t.ref(null),D=t.ref(null),T=t.ref(null),X=t.ref(0),L=t.ref(null),F=t.ref(0);let N=null;function P(){N!=null&&(cancelAnimationFrame(N),N=null)}function ae(){if(!S.value||F.value===0){P();return}const e=v.value;if(!e){P();return}const n=e.scrollHeight-e.clientHeight,l=12;e.scrollTop=Math.max(0,Math.min(n,e.scrollTop+F.value*l)),E.value=e.scrollTop,k(),N=requestAnimationFrame(ae)}function ye(){F.value!==0&&N==null&&(N=requestAnimationFrame(ae)),F.value===0&&P()}function W(e){if(e==null)return null;for(const n of i.value)if(n.id===e)return n;return null}function we(e){const n=v.value.getBoundingClientRect(),l=e-n.top+E.value;return le(l)}function Ce(e,n){!a.draggable||n.button!==0||!(!a.allowDrag||a.allowDrag(e.node))||(S.value=!0,Q.value=e.id,X.value=n.clientY,n.preventDefault(),window.addEventListener("mousemove",oe),window.addEventListener("mouseup",ce))}function oe(e){if(!S.value)return;X.value=e.clientY;const n=we(e.clientY),l=i.value[Math.min(Math.max(n,0),i.value.length-1)];if(D.value=l?.id??null,!l){T.value=null;return}const o=g.value[n]??0,u=A.get(l.id)??H,r=o-u,c=v.value.getBoundingClientRect(),s=(e.clientY-c.top+E.value-r)/u;let d="inner";s<.25?d="prev":s>.75&&(d="next");const x=W(Q.value),$=a.allowDrop?!!(x&&a.allowDrop(x.node,l.node,d)):!0;T.value=$?d:null,F.value=e.clientY>c.bottom?1:e.clientY<c.top?-1:0,ye()}function q(e,n,l=[]){for(const o of n){if(w(o)===e)return l;const u=z(o);if(u.length){const r=q(e,u,[...l,o]);if(r)return r}}return null}function Z(e,n){if(e==null)return null;for(const l of n){if(w(l)===e)return l;const o=z(l),u=Z(e,o);if(u)return u}return null}function U(e){const n=[];for(const l of e){n.push(w(l));const o=z(l);o.length&&n.push(...U(o))}return n}function be(e){const n=e.parent;if(n)z(n).splice(e.index,1);else{const l=a.data.findIndex(o=>w(o)===e.id);l>=0&&a.data.splice(l,1)}}function Se(e,n,l){if(l==="inner"){Array.isArray(n.node[_.value])||(n.node[_.value]=[]),n.node[_.value].push(e),y.value.add(n.id);return}const o=n.parent;if(o){const u=z(o),r=n.index+(l==="next"?1:0);u.splice(r,0,e)}else{const u=n.index+(l==="next"?1:0);a.data.splice(u,0,e)}}function ce(){if(window.removeEventListener("mousemove",oe),window.removeEventListener("mouseup",ce),P(),!S.value)return;const e=W(Q.value),n=W(D.value),l=T.value;if(S.value=!1,T.value=null,D.value=null,!e||!n||!l||a.allowDrop&&!a.allowDrop(e.node,n.node,l)||e.id===n.id)return;const o=l==="inner"?n.node:n.parent||null;if(o){const f=q(w(o),a.data||[])||[];for(const s of f)if(w(s)===e.id)return}const u=e.node;be(e);const r=C(a.data||[]);i.value=r;const c=W(n.id)||n;Se(u,c,l),i.value=C(a.data||[]),t.nextTick(()=>{B(),k()}),M("node-drop",u,c.node,l)}function Te(e,n){L.value=e.id,M("node-click",e.node,n)}function ze(e,n){M("node-contextmenu",e.node,n)}t.watchEffect(()=>{t.nextTick(B)}),t.watch(()=>a.currentNodeKey,e=>{L.value=e??null},{immediate:!0}),t.watch(()=>a.defaultExpandedKeys,e=>{y.value=new Set(e||[]),i.value=C(a.data||[]),t.nextTick(()=>{B(),k()})},{immediate:!0}),t.watch(()=>a.defaultExpandAll,e=>{e&&(y.value=new Set(U(a.data||[])),i.value=C(a.data||[]),t.nextTick(()=>{B(),k()}))},{immediate:!0}),t.watch(()=>a.data,()=>{a.defaultExpandAll&&(y.value=new Set(U(a.data||[]))),i.value=C(a.data||[]),t.nextTick(()=>{B(),k()});const e=new Set(U(a.data||[]));h.value=new Set([...h.value].filter(n=>e.has(n))),p.value=new Set([...p.value].filter(n=>e.has(n)))},{deep:!0});function Ee(e){const n=q(e,a.data||[])||[];for(const l of n)y.value.add(w(l));i.value=C(a.data||[])}function ue(e){e!=null&&(Ee(e),t.nextTick(()=>{const n=i.value.findIndex(c=>c.id===e);if(n<0||!v.value)return;const l=A.get(e)||H,o=(g.value[n]??0)-l,u=v.value.clientHeight,r=Math.max(0,o-Math.max(0,(u-l)/2));v.value.scrollTop=r,E.value=r,k(),t.nextTick(()=>{const c=O.get(e);if(!c||!v.value)return;const f=c.offsetLeft,s=c.offsetWidth,d=v.value.clientWidth,x=Math.max(0,f+Math.max(0,s/2)-Math.max(0,d/2));v.value.scrollLeft=x})}))}function Be(e){L.value=e??null,ue(L.value)}return j({getCurrentKey:()=>L.value,setCurrentKey:Be,scrollTo:ue,getCheckedKeys:()=>Array.from(h.value),setCheckedKeys:te,setChecked:(e,n)=>G(e,n)}),t.watch(L,e=>{const n=Z(e,a.data||[]);n&&M("current-change",n)}),(e,n)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"containerRef",ref:v,class:t.normalizeClass(["amazing-tree",{"is-dragging":S.value}]),style:t.normalizeStyle({height:typeof m.height=="number"?m.height+"px":m.height||"100%","--vtree-bg":m.backgroundColor,"--vtree-text":m.textColor,"--vtree-hover":m.hoverColor}),onScroll:xe},[fe.value?(t.openBlock(),t.createElementBlock("div",Le,[t.renderSlot(e.$slots,"empty",{},()=>[t.createElementVNode("div",Ne,t.toDisplayString(m.emptyText),1)],!0)])):(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.createElementVNode("div",{style:t.normalizeStyle({height:ne.value+"px",position:"relative",minWidth:"100%",width:"max-content"})},[t.createElementVNode("div",{style:t.normalizeStyle({height:I.value+"px"})},null,4),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(i.value.slice(K.value,b.value),l=>(t.openBlock(),t.createElementBlock("div",{key:l.id,class:"amazing-tree-row-wrapper"},[t.createElementVNode("div",{class:t.normalizeClass(["amazing-tree-row",{"is-target-inner":S.value&&D.value===l.id&&T.value==="inner","is-active":L.value===l.id}]),style:t.normalizeStyle({paddingLeft:l.level*16+"px","--active-color":m.highlightColor}),onMousedown:o=>Ce(l,o),onClick:o=>Te(l,o),onContextmenu:t.withModifiers(o=>ze(l,o),["prevent"]),ref_for:!0,ref:o=>ke(l.id,o)},[t.createElementVNode("span",{class:t.normalizeClass(["amazing-tree-caret-box",{"is-leaf":l.isLeaf}]),onClick:t.withModifiers(o=>!l.isLeaf&&he(l.id),["stop"])},[l.isLeaf?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock("span",{key:0,class:t.normalizeClass(["amazing-tree-caret",{expanded:ee(l.id)}])},null,2))],10,Ae),m.showCheckbox?(t.openBlock(),t.createElementBlock("input",{key:0,class:"amazing-tree-checkbox",type:"checkbox",checked:me(l.id),indeterminate:pe(l.id),disabled:a.disabledChecked?a.disabledChecked(l.node):!1,onClick:t.withModifiers(o=>ge(l,o),["stop"])},null,8,Ke)):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"default",{node:l.node,data:l.node,level:l.level,expanded:ee(l.id),isLeaf:l.isLeaf},()=>[t.createElementVNode("span",Ie,t.toDisplayString(l.node[ve.value]),1)],!0)],46,Me),S.value&&D.value===l.id&&(T.value==="prev"||T.value==="next")?(t.openBlock(),t.createElementBlock("div",{key:0,class:t.normalizeClass(["amazing-tree-drop-line",{"is-prev":T.value==="prev","is-next":T.value==="next"}])},null,2)):t.createCommentVNode("",!0)]))),128)),t.createElementVNode("div",{style:t.normalizeStyle({height:J.value+"px"})},null,4)],4),S.value?(t.openBlock(),t.createElementBlock("div",{key:0,class:"amazing-tree-ghost",style:t.normalizeStyle({top:X.value+"px"})},null,4)):t.createCommentVNode("",!0)],64))],38))}}),Ve=(m,j)=>{const Y=m.__vccOpts||m;for(const[a,M]of j)Y[a]=M;return Y},se=Ve(Re,[["__scopeId","data-v-6ef943bb"]]);exports.AmazingTree=se;exports.default=se;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),De=["onMousedown","onClick","onContextmenu"],Ve=["onClick"],Ye=["checked","indeterminate","disabled","onClick"],Fe={class:"amazing-tree-label"},Oe={key:1,class:"amazing-tree-empty"},Pe={class:"amazing-tree-empty-inner"},We=t.defineComponent({__name:"AmazingTree",props:{data:{},props:{default:()=>({value:"value",label:"label",children:"children"})},allowDrag:{},allowDrop:{},height:{default:void 0},rowHeight:{default:32},dropLineColor:{default:"#ffd400"},innerDashColor:{default:"#ffd400"},siblingZoneRatio:{default:.35},dragStartThreshold:{default:4},highlightColor:{default:"#1e71ff"},backgroundColor:{default:"#1d1d24"},textColor:{default:"#c8d3de"},hoverColor:{default:"#5d90e5"},currentNodeKey:{},defaultExpandedKeys:{},defaultExpandAll:{type:Boolean,default:!1},draggable:{type:Boolean,default:!1},emptyText:{default:"暂无数据"},showCheckbox:{type:Boolean,default:!1},checkStrictly:{type:Boolean,default:!1},defaultCheckedKeys:{default:()=>[]},disabledChecked:{},filterNodeMethod:{}},emits:["node-click","node-contextmenu","node-drop","current-change","check-change"],setup(f,{expose:J,emit:U}){const a=f,K=U,ge=t.computed(()=>a.props.value||"value"),pe=t.computed(()=>a.props.label||"label"),X=t.computed(()=>a.props.children||"children"),we=t.computed(()=>Array.isArray(a.data)?a.data.length===0:!0),w=t.ref(new Set),g=t.ref(new Set),x=t.ref(new Set),_=t.ref(null);function ae(e){return w.value.has(e)}function xe(e){w.value.has(e)?w.value.delete(e):w.value.add(e),i.value=C(a.data||[]),t.nextTick(()=>{T(),p()})}function k(e){return e[ge.value]}function S(e){const l=e[X.value];return Array.isArray(l)?l:[]}function ke(e){return g.value.has(e)}function ye(e){return x.value.has(e)}function ee(e,l){if(l?g.value.add(e):g.value.delete(e),x.value.delete(e),!a.checkStrictly){const n=ne(e,a.data||[]);if(n){const o=[n];for(;o.length;){const c=o.pop(),u=k(c);l?g.value.add(u):g.value.delete(u),x.value.delete(u);const v=S(c);for(const s of v)o.push(s)}const r=Q(e,a.data||[])||[];for(const c of r){const u=k(c),v=S(c);let s=!0,d=!1;for(const m of v){const z=k(m),q=g.value.has(z),G=x.value.has(z);(q||G)&&(d=!0),(!q||G)&&(s=!1)}v.length===0?(g.value.has(u),x.value.delete(u)):s?(g.value.add(u),x.value.delete(u)):d?(g.value.delete(u),x.value.add(u)):(g.value.delete(u),x.value.delete(u))}}}}function oe(e){g.value=new Set,x.value=new Set;for(const l of e||[])ee(l,!0)}function Ce(e,l){const n=l.target;a.disabledChecked&&a.disabledChecked(e.node)||(K("check-change",e.node,!!n.checked),ee(e.id,!!n.checked))}function C(e){const l=[];function n(o,r,c){for(let u=0;u<o.length;u++){const v=o[u],s=k(v),d=S(v),m=d.length===0;l.push({id:s,node:v,parent:r,level:c,index:u,isLeaf:m}),!m&&w.value.has(s)&&n(d,v,c+1)}}if(n(e,null,0),a.filterNodeMethod&&_.value!=null){let o=function(u){const v=k(u),s=S(u);let d=!1;for(const z of s)d=o(z)||d;const m=!!a.filterNodeMethod(_.value,u);return m&&r.add(v),d&&c.add(v),m||d};const r=new Set,c=new Set;for(const u of e)o(u);return l.filter(u=>r.has(u.id)||c.has(u.id))}return l}const h=t.ref(null),E=t.ref(0),D=t.ref(0),i=t.ref([]),N=t.reactive(new Map);function be(e){if(typeof e=="number")return e;if(typeof e=="string"){const l=e.match(/(\d+(\.\d+)?)/);return l?Number(l[1]):32}return 32}const V=be(a.rowHeight),y=t.computed(()=>{let e=0;const l=[];for(const n of i.value){const o=N.get(n.id)||V;e+=o,l.push(e)}return l}),ue=t.computed(()=>{const e=y.value;return e.length?e[e.length-1]:0});function re(e){let l=0,n=y.value.length-1,o=0;for(;l<=n;){const r=l+n>>1;y.value[r]!==void 0&&y.value[r]>=e?(o=r,n=r-1):l=r+1}return o}const H=t.ref(0),M=t.ref(0),R=t.ref(0),te=t.ref(0);function p(){if(D.value=h.value?.clientHeight||0,y.value.length===0||i.value.length===0){H.value=0,M.value=0,R.value=0,te.value=0;return}const e=re(E.value);H.value=Math.max(0,e-3);const l=i.value[H.value],n=l?N.get(l.id)||V:0,r=(y.value[H.value]??0)-n;R.value=Math.max(0,r);let c=H.value;const u=E.value+D.value+3*V;for(;c<i.value.length&&(y.value[c]??0)<u;)c++;M.value=Math.min(i.value.length,c+1);const s=(y.value[M.value-1]??0)-R.value;if(s<D.value&&M.value<i.value.length){let d=M.value,m=s;for(;m<D.value&&d<i.value.length;)d++,m=(y.value[d-1]??0)-R.value;M.value=d}te.value=Math.max(0,ue.value-R.value-((y.value[M.value-1]??0)-R.value))}t.watch([E,()=>a.data,w],()=>{i.value=C(a.data||[]),t.nextTick(T),p()}),t.onMounted(()=>{i.value=C(a.data||[]),t.nextTick(T),p(),a.defaultCheckedKeys&&a.defaultCheckedKeys.length&&oe(a.defaultCheckedKeys),h.value&&(Y=new ResizeObserver(()=>{D.value=h.value?.clientHeight||0,p()}),Y.observe(h.value))});let Y=null;t.onUnmounted(()=>{Y&&(Y.disconnect(),Y=null)});const $=t.reactive(new Map);function Se(e,l){l?$.set(e,l):$.delete(e)}function T(){let e=!1;for(const l of i.value.slice(H.value,M.value)){const n=$.get(l.id);if(n){const o=n.offsetHeight;(!N.has(l.id)||N.get(l.id)!==o)&&(N.set(l.id,o),e=!0)}}e&&p()}function Me(){E.value=h.value?.scrollTop||0,p()}const B=t.ref(!1),F=t.ref(null),L=t.ref(null),b=t.ref(null),le=t.ref(0),O=t.ref(!1),ce=t.ref(0),ie=t.ref(0),A=t.ref(null),P=t.ref(0);let I=null;function Z(){I!=null&&(cancelAnimationFrame(I),I=null)}function se(){if(!B.value||P.value===0){Z();return}const e=h.value;if(!e){Z();return}const l=e.scrollHeight-e.clientHeight,n=12;e.scrollTop=Math.max(0,Math.min(l,e.scrollTop+P.value*n)),E.value=e.scrollTop,p(),I=requestAnimationFrame(se)}function Te(){P.value!==0&&I==null&&(I=requestAnimationFrame(se)),P.value===0&&Z()}function j(e){if(e==null)return null;for(const l of i.value)if(l.id===e)return l;return null}function ze(e){const l=h.value.getBoundingClientRect(),n=e-l.top+E.value;return re(n)}function Ee(e,l){!a.draggable||l.button!==0||!(!a.allowDrag||a.allowDrag(e.node))||(F.value=e.id,le.value=l.clientY,ce.value=l.clientX,ie.value=l.clientY,O.value=!1,l.preventDefault(),window.addEventListener("mousemove",de),window.addEventListener("mouseup",fe))}function de(e){if(F.value==null)return;if(!O.value){const Le=Math.abs(e.clientX-ce.value),Ie=Math.abs(e.clientY-ie.value),he=Math.max(1,a.dragStartThreshold??4);if(Le<he&&Ie<he)return;O.value=!0,B.value=!0}le.value=e.clientY;const l=ze(e.clientY),n=i.value[Math.min(Math.max(l,0),i.value.length-1)];if(L.value=n?.id??null,!n){b.value=null;return}const o=y.value[l]??0,r=N.get(n.id)??V,c=o-r,u=h.value.getBoundingClientRect(),s=(e.clientY-u.top+E.value-c)/r,d=a.siblingZoneRatio??.35,m=Math.max(.05,Math.min(.49,d));let z="inner";s<m?z="prev":s>1-m&&(z="next");const q=j(F.value),G=a.allowDrop?!!(q&&a.allowDrop(q.node,n.node,z)):!0;b.value=G?z:null,P.value=e.clientY>u.bottom?1:e.clientY<u.top?-1:0,Te()}function Q(e,l,n=[]){for(const o of l){if(k(o)===e)return n;const r=S(o);if(r.length){const c=Q(e,r,[...n,o]);if(c)return c}}return null}function ne(e,l){if(e==null)return null;for(const n of l){if(k(n)===e)return n;const o=S(n),r=ne(e,o);if(r)return r}return null}function W(e){const l=[];for(const n of e){l.push(k(n));const o=S(n);o.length&&l.push(...W(o))}return l}function Be(e){const l=e.parent;if(l)S(l).splice(e.index,1);else{const n=a.data.findIndex(o=>k(o)===e.id);n>=0&&a.data.splice(n,1)}}function Ae(e,l,n){if(n==="inner"){Array.isArray(l.node[X.value])||(l.node[X.value]=[]),l.node[X.value].push(e),w.value.add(l.id);return}const o=l.parent;if(o){const r=S(o),c=l.index+(n==="next"?1:0);r.splice(c,0,e)}else{const r=l.index+(n==="next"?1:0);a.data.splice(r,0,e)}}function fe(){if(window.removeEventListener("mousemove",de),window.removeEventListener("mouseup",fe),Z(),!B.value){F.value=null,b.value=null,L.value=null,O.value=!1;return}const e=j(F.value),l=j(L.value),n=b.value;if(B.value=!1,O.value=!1,b.value=null,L.value=null,!e||!l||!n||a.allowDrop&&!a.allowDrop(e.node,l.node,n)||e.id===l.id)return;const o=n==="inner"?l.node:l.parent||null;if(o){const v=Q(k(o),a.data||[])||[];for(const s of v)if(k(s)===e.id)return}const r=e.node;Be(e);const c=C(a.data||[]);i.value=c;const u=j(l.id)||l;Ae(r,u,n),i.value=C(a.data||[]),t.nextTick(()=>{T(),p()}),K("node-drop",r,u.node,n)}function Ke(e,l){A.value=e.id,K("node-click",e.node,l)}function Ne(e,l){A.value=e.id,K("node-contextmenu",e.node,l)}t.watchEffect(()=>{t.nextTick(T)}),t.watch(()=>a.currentNodeKey,e=>{A.value=e??null},{immediate:!0}),t.watch(()=>a.defaultExpandedKeys,e=>{w.value=new Set(e||[]),i.value=C(a.data||[]),t.nextTick(()=>{T(),p()})},{immediate:!0}),t.watch(()=>a.defaultExpandAll,e=>{e&&(w.value=new Set(W(a.data||[])),i.value=C(a.data||[]),t.nextTick(()=>{T(),p()}))},{immediate:!0}),t.watch(()=>a.data,()=>{a.defaultExpandAll&&(w.value=new Set(W(a.data||[]))),i.value=C(a.data||[]),t.nextTick(()=>{T(),p()});const e=new Set(W(a.data||[]));g.value=new Set([...g.value].filter(l=>e.has(l))),x.value=new Set([...x.value].filter(l=>e.has(l)))},{deep:!0});function He(e){const l=Q(e,a.data||[])||[];for(const n of l)w.value.add(k(n));i.value=C(a.data||[])}function ve(e){e!=null&&(He(e),t.nextTick(()=>{const l=i.value.findIndex(u=>u.id===e);if(l<0||!h.value)return;const n=N.get(e)||V,o=(y.value[l]??0)-n,r=h.value.clientHeight,c=Math.max(0,o-Math.max(0,(r-n)/2));h.value.scrollTop=c,E.value=c,p(),t.nextTick(()=>{const u=$.get(e);if(!u||!h.value)return;const v=u.offsetLeft,s=u.offsetWidth,d=h.value.clientWidth,m=Math.max(0,v+Math.max(0,s/2)-Math.max(0,d/2));h.value.scrollLeft=m})}))}function Re(e){A.value=e??null,ve(A.value)}return J({getCurrentKey:()=>A.value,setCurrentKey:Re,scrollTo:ve,getCheckedKeys:()=>Array.from(g.value),setCheckedKeys:oe,setChecked:(e,l)=>ee(e,l),filter:e=>{_.value=e,w.value=new Set(W(a.data||[])),i.value=C(a.data||[]),t.nextTick(()=>{T(),p()})}}),t.watch(A,e=>{const l=ne(e,a.data||[]);l&&K("current-change",l)}),(e,l)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"containerRef",ref:h,class:t.normalizeClass(["amazing-tree",{"is-dragging":B.value}]),style:t.normalizeStyle({height:typeof f.height=="number"?f.height+"px":f.height||"100%","--vtree-bg":f.backgroundColor,"--vtree-text":f.textColor,"--vtree-hover":f.hoverColor,"--vtree-row-height":typeof f.rowHeight=="number"?f.rowHeight+"px":f.rowHeight||"32px","--vtree-drop-line":f.dropLineColor,"--vtree-drop-inner":f.innerDashColor}),onScroll:Me},[we.value?(t.openBlock(),t.createElementBlock("div",Oe,[t.renderSlot(e.$slots,"empty",{},()=>[t.createElementVNode("div",Pe,t.toDisplayString(f.emptyText),1)],!0)])):(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.createElementVNode("div",{style:t.normalizeStyle({height:ue.value+"px",position:"relative",minWidth:"100%",width:"max-content"})},[t.createElementVNode("div",{style:t.normalizeStyle({height:R.value+"px"})},null,4),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(i.value.slice(H.value,M.value),n=>(t.openBlock(),t.createElementBlock("div",{key:n.id,class:"amazing-tree-row-wrapper"},[t.createElementVNode("div",{class:t.normalizeClass(["amazing-tree-row",{"is-target-inner":B.value&&L.value===n.id&&b.value==="inner","is-active":A.value===n.id}]),style:t.normalizeStyle({paddingLeft:n.level*16+"px","--active-color":f.highlightColor}),onMousedown:o=>Ee(n,o),onClick:o=>Ke(n,o),onContextmenu:t.withModifiers(o=>Ne(n,o),["prevent"]),ref_for:!0,ref:o=>Se(n.id,o)},[t.createElementVNode("span",{class:t.normalizeClass(["amazing-tree-caret-box",{"is-leaf":n.isLeaf}]),onMousedown:l[0]||(l[0]=t.withModifiers(()=>{},["stop"])),onClick:t.withModifiers(o=>!n.isLeaf&&xe(n.id),["stop"])},[n.isLeaf?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock("span",{key:0,class:t.normalizeClass(["amazing-tree-caret",{expanded:ae(n.id)}])},null,2))],42,Ve),f.showCheckbox?(t.openBlock(),t.createElementBlock("input",{key:0,class:"amazing-tree-checkbox",type:"checkbox",checked:ke(n.id),onMousedown:l[1]||(l[1]=t.withModifiers(()=>{},["stop"])),indeterminate:ye(n.id),disabled:a.disabledChecked?a.disabledChecked(n.node):!1,onClick:t.withModifiers(o=>Ce(n,o),["stop"])},null,40,Ye)):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"default",{node:n.node,data:n.node,level:n.level,expanded:ae(n.id),isLeaf:n.isLeaf},()=>[t.createElementVNode("span",Fe,t.toDisplayString(n.node[pe.value]),1)],!0)],46,De),B.value&&L.value===n.id&&(b.value==="prev"||b.value==="next")?(t.openBlock(),t.createElementBlock("div",{key:0,class:t.normalizeClass(["amazing-tree-drop-line",{"is-prev":b.value==="prev","is-next":b.value==="next"}])},null,2)):t.createCommentVNode("",!0)]))),128)),t.createElementVNode("div",{style:t.normalizeStyle({height:te.value+"px"})},null,4)],4),B.value?(t.openBlock(),t.createElementBlock("div",{key:0,class:"amazing-tree-ghost",style:t.normalizeStyle({top:le.value+"px"})},null,4)):t.createCommentVNode("",!0)],64))],38))}}),qe=(f,J)=>{const U=f.__vccOpts||f;for(const[a,K]of J)U[a]=K;return U},me=qe(We,[["__scopeId","data-v-fc218005"]]);exports.AmazingTree=me;exports.default=me;
@@ -1 +1 @@
1
- .amazing-tree[data-v-6ef943bb]{width:100%;overflow:auto;position:relative;background:var(--vtree-bg);color:var(--vtree-text);scrollbar-width:thin;scrollbar-color:rgba(144,147,153,.3) transparent;cursor:pointer;--vtree-primary: #409eff;--vtree-checkbox-bg: #1d1d24;--vtree-checkbox-border: #4c4d4f;--vtree-checkbox-hover-border: #8d8e91;--vtree-checkbox-disabled-bg: #2c2f33;--vtree-checkbox-disabled-border: #5c5f63;--vtree-checkbox-check: #ffffff;--vtree-checkbox-check-disabled: #cfd3dc}.amazing-tree.is-dragging[data-v-6ef943bb],.amazing-tree.is-dragging[data-v-6ef943bb] *{-webkit-user-select:none;user-select:none}.amazing-tree[data-v-6ef943bb] *{cursor:pointer}.amazing-tree input[type=checkbox][data-v-6ef943bb]:disabled{cursor:not-allowed}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]{-webkit-appearance:none;appearance:none;position:relative;width:14px;height:14px;border:1px solid var(--vtree-checkbox-border);background:var(--vtree-checkbox-bg);border-radius:2px;outline:none;transition:border-color .12s ease,background-color .12s ease,box-shadow .12s ease;vertical-align:middle;margin-right:6px}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]:not(:disabled):hover{border-color:var(--vtree-checkbox-hover-border)}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]:focus-visible{box-shadow:0 0 0 2px #409eff33}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]:checked{background:var(--vtree-primary);border-color:var(--vtree-primary)}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]:checked:after{content:"";position:absolute;left:3px;top:0;width:4px;height:8px;border:2px solid var(--vtree-checkbox-check);border-top:0;border-left:0;transform:rotate(45deg)}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]:indeterminate{background:var(--vtree-primary);border-color:var(--vtree-primary)}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]:indeterminate:after{content:"";position:absolute;left:2px;top:5px;width:10px;height:2px;background:var(--vtree-checkbox-check);border-radius:1px}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]:disabled{background:var(--vtree-checkbox-disabled-bg);border-color:var(--vtree-checkbox-disabled-border)}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]:disabled:checked:after{border-color:var(--vtree-checkbox-check-disabled)}.amazing-tree .amazing-tree-checkbox[data-v-6ef943bb]:disabled:indeterminate:after{background:var(--vtree-checkbox-check-disabled)}.amazing-tree .amazing-tree-row-wrapper[data-v-6ef943bb]{position:relative}.amazing-tree .amazing-tree-row-wrapper .amazing-tree-drop-line[data-v-6ef943bb]{position:absolute;left:0;right:0;height:0;border-top:2px solid #409eff}.amazing-tree .amazing-tree-row-wrapper .amazing-tree-drop-line.is-prev[data-v-6ef943bb]{top:0}.amazing-tree .amazing-tree-row-wrapper .amazing-tree-drop-line.is-next[data-v-6ef943bb]{bottom:0}.amazing-tree .amazing-tree-row[data-v-6ef943bb]{display:flex;align-items:center;gap:4px;box-sizing:border-box;min-height:24px;padding:0 8px;white-space:nowrap}.amazing-tree .amazing-tree-row[data-v-6ef943bb]:hover{background:var(--vtree-hover)}.amazing-tree .amazing-tree-row.is-active[data-v-6ef943bb],.amazing-tree .amazing-tree-row.is-active[data-v-6ef943bb]:hover{background:var(--active-color)}.amazing-tree .amazing-tree-row.is-target-inner[data-v-6ef943bb]{outline:2px dashed #409eff}.amazing-tree .amazing-tree-row .amazing-tree-caret-box[data-v-6ef943bb]{display:inline-flex;align-items:center;justify-content:center;height:100%;aspect-ratio:1/1;min-width:16px;margin-right:4px;cursor:pointer}.amazing-tree .amazing-tree-row .amazing-tree-caret-box.is-leaf[data-v-6ef943bb]{pointer-events:none}.amazing-tree .amazing-tree-row .amazing-tree-caret[data-v-6ef943bb]{display:block;width:0;height:0;border-left:5px solid transparent;border-right:5px solid transparent;border-top:6px solid #909399;transform:rotate(-90deg);transition:transform .1s linear}.amazing-tree .amazing-tree-row .amazing-tree-caret.expanded[data-v-6ef943bb]{transform:rotate(0)}.amazing-tree .amazing-tree-row .amazing-tree-label[data-v-6ef943bb]{color:inherit}.amazing-tree .amazing-tree-ghost[data-v-6ef943bb]{position:fixed;left:16px;width:120px;height:24px;background:#409eff33;border:1px solid #409eff;pointer-events:none}.amazing-tree .amazing-tree-empty[data-v-6ef943bb]{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.amazing-tree .amazing-tree-empty[data-v-6ef943bb]>*{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.amazing-tree .amazing-tree-empty .amazing-tree-empty-inner[data-v-6ef943bb]{color:var(--vtree-text)}[data-v-6ef943bb] .amazing-tree::-webkit-scrollbar{width:8px;height:8px}[data-v-6ef943bb] .amazing-tree::-webkit-scrollbar-track{background:transparent}[data-v-6ef943bb] .amazing-tree::-webkit-scrollbar-thumb{background-color:#9093994d;border-radius:4px}[data-v-6ef943bb] .amazing-tree::-webkit-scrollbar-thumb:hover{background-color:#90939980}
1
+ .amazing-tree[data-v-fc218005]{width:100%;overflow:auto;position:relative;background:var(--vtree-bg);color:var(--vtree-text);scrollbar-width:thin;scrollbar-color:rgba(144,147,153,.3) transparent;cursor:pointer;--vtree-primary: #409eff;--vtree-checkbox-bg: #1d1d24;--vtree-checkbox-border: #4c4d4f;--vtree-checkbox-hover-border: #8d8e91;--vtree-checkbox-disabled-bg: #2c2f33;--vtree-checkbox-disabled-border: #5c5f63;--vtree-checkbox-check: #ffffff;--vtree-checkbox-check-disabled: #cfd3dc}.amazing-tree.is-dragging[data-v-fc218005],.amazing-tree.is-dragging[data-v-fc218005] *{-webkit-user-select:none;user-select:none}.amazing-tree[data-v-fc218005] *{cursor:pointer}.amazing-tree input[type=checkbox][data-v-fc218005]:disabled{cursor:not-allowed}.amazing-tree .amazing-tree-checkbox[data-v-fc218005]{-webkit-appearance:none;appearance:none;position:relative;width:14px;height:14px;border:1px solid var(--vtree-checkbox-border);background:var(--vtree-checkbox-bg);border-radius:2px;outline:none;transition:border-color .12s ease,background-color .12s ease,box-shadow .12s ease;vertical-align:middle;margin-right:6px}.amazing-tree .amazing-tree-checkbox[data-v-fc218005]:not(:disabled):hover{border-color:var(--vtree-checkbox-hover-border)}.amazing-tree .amazing-tree-checkbox[data-v-fc218005]:focus-visible{box-shadow:0 0 0 2px #409eff33}.amazing-tree .amazing-tree-checkbox[data-v-fc218005]:checked{background:var(--vtree-primary);border-color:var(--vtree-primary)}.amazing-tree .amazing-tree-checkbox[data-v-fc218005]:checked:after{content:"";position:absolute;left:3px;top:0;width:4px;height:8px;border:2px solid var(--vtree-checkbox-check);border-top:0;border-left:0;transform:rotate(45deg)}.amazing-tree .amazing-tree-checkbox[data-v-fc218005]:indeterminate{background:var(--vtree-primary);border-color:var(--vtree-primary)}.amazing-tree .amazing-tree-checkbox[data-v-fc218005]:indeterminate:after{content:"";position:absolute;left:2px;top:5px;width:10px;height:2px;background:var(--vtree-checkbox-check);border-radius:1px}.amazing-tree .amazing-tree-checkbox[data-v-fc218005]:disabled{background:var(--vtree-checkbox-disabled-bg);border-color:var(--vtree-checkbox-disabled-border)}.amazing-tree .amazing-tree-checkbox[data-v-fc218005]:disabled:checked:after{border-color:var(--vtree-checkbox-check-disabled)}.amazing-tree .amazing-tree-checkbox[data-v-fc218005]:disabled:indeterminate:after{background:var(--vtree-checkbox-check-disabled)}.amazing-tree .amazing-tree-row-wrapper[data-v-fc218005]{position:relative}.amazing-tree .amazing-tree-row-wrapper .amazing-tree-drop-line[data-v-fc218005]{position:absolute;left:0;right:0;height:0;border-top:2px solid var(--vtree-drop-line, #ffd400)}.amazing-tree .amazing-tree-row-wrapper .amazing-tree-drop-line.is-prev[data-v-fc218005]{top:0}.amazing-tree .amazing-tree-row-wrapper .amazing-tree-drop-line.is-next[data-v-fc218005]{bottom:0}.amazing-tree .amazing-tree-row[data-v-fc218005]{display:flex;align-items:center;gap:4px;box-sizing:border-box;position:relative;min-height:var(--vtree-row-height, 32px);line-height:var(--vtree-row-height, 32px);padding:0 8px;white-space:nowrap}.amazing-tree .amazing-tree-row[data-v-fc218005]:hover{background:var(--vtree-hover)}.amazing-tree .amazing-tree-row.is-active[data-v-fc218005],.amazing-tree .amazing-tree-row.is-active[data-v-fc218005]:hover{background:var(--active-color)}.amazing-tree .amazing-tree-row.is-target-inner[data-v-fc218005]:before,.amazing-tree .amazing-tree-row.is-target-inner[data-v-fc218005]:after{content:"";position:absolute;left:0;right:0;pointer-events:none}.amazing-tree .amazing-tree-row.is-target-inner[data-v-fc218005]:before{top:0;border-top:2px dashed var(--vtree-drop-inner, #ffd400)}.amazing-tree .amazing-tree-row.is-target-inner[data-v-fc218005]:after{bottom:0;border-bottom:2px dashed var(--vtree-drop-inner, #ffd400)}.amazing-tree .amazing-tree-row .amazing-tree-caret-box[data-v-fc218005]{display:inline-flex;align-items:center;justify-content:center;height:100%;aspect-ratio:1/1;min-width:16px;margin-right:4px;cursor:pointer}.amazing-tree .amazing-tree-row .amazing-tree-caret-box.is-leaf[data-v-fc218005]{pointer-events:none}.amazing-tree .amazing-tree-row .amazing-tree-caret[data-v-fc218005]{display:block;width:0;height:0;border-left:5px solid transparent;border-right:5px solid transparent;border-top:6px solid #909399;transform:rotate(-90deg);transition:transform .1s linear}.amazing-tree .amazing-tree-row .amazing-tree-caret.expanded[data-v-fc218005]{transform:rotate(0)}.amazing-tree .amazing-tree-row .amazing-tree-label[data-v-fc218005]{color:inherit}.amazing-tree .amazing-tree-ghost[data-v-fc218005]{position:fixed;left:16px;width:120px;height:var(--vtree-row-height, 32px);background:#409eff33;border:1px solid #409eff;pointer-events:none}.amazing-tree .amazing-tree-empty[data-v-fc218005]{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.amazing-tree .amazing-tree-empty[data-v-fc218005]>*{width:100%;height:100%;display:flex;align-items:center;justify-content:center}.amazing-tree .amazing-tree-empty .amazing-tree-empty-inner[data-v-fc218005]{color:var(--vtree-text)}[data-v-fc218005] .amazing-tree::-webkit-scrollbar{width:8px;height:8px}[data-v-fc218005] .amazing-tree::-webkit-scrollbar-track{background:transparent}[data-v-fc218005] .amazing-tree::-webkit-scrollbar-thumb{background-color:#9093994d;border-radius:4px}[data-v-fc218005] .amazing-tree::-webkit-scrollbar-thumb:hover{background-color:#90939980}
@@ -1,8 +1,8 @@
1
- import { defineComponent as Oe, computed as N, ref as s, reactive as we, watch as _, nextTick as C, onMounted as Pe, onUnmounted as Ve, watchEffect as Ue, createElementBlock as z, openBlock as T, normalizeStyle as W, normalizeClass as $, Fragment as ke, createElementVNode as Y, createCommentVNode as ne, renderList as $e, withModifiers as se, renderSlot as Ce, toDisplayString as be } from "vue";
2
- const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = ["checked", "indeterminate", "disabled", "onClick"], Je = { class: "amazing-tree-label" }, Qe = {
1
+ import { defineComponent as je, computed as O, ref as s, reactive as Me, watch as P, nextTick as C, onMounted as Ge, onUnmounted as Je, watchEffect as _e, createElementBlock as K, openBlock as H, normalizeStyle as V, normalizeClass as J, Fragment as Ae, createElementVNode as N, createCommentVNode as ie, renderList as et, withModifiers as _, renderSlot as Te, toDisplayString as ze } from "vue";
2
+ const tt = ["onMousedown", "onClick", "onContextmenu"], nt = ["onClick"], lt = ["checked", "indeterminate", "disabled", "onClick"], at = { class: "amazing-tree-label" }, ot = {
3
3
  key: 1,
4
4
  class: "amazing-tree-empty"
5
- }, Xe = { class: "amazing-tree-empty-inner" }, q = 28, Ze = /* @__PURE__ */ Oe({
5
+ }, ut = { class: "amazing-tree-empty-inner" }, it = /* @__PURE__ */ je({
6
6
  __name: "AmazingTree",
7
7
  props: {
8
8
  data: {},
@@ -10,6 +10,11 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
10
10
  allowDrag: {},
11
11
  allowDrop: {},
12
12
  height: { default: void 0 },
13
+ rowHeight: { default: 32 },
14
+ dropLineColor: { default: "#ffd400" },
15
+ innerDashColor: { default: "#ffd400" },
16
+ siblingZoneRatio: { default: 0.35 },
17
+ dragStartThreshold: { default: 4 },
13
18
  highlightColor: { default: "#1e71ff" },
14
19
  backgroundColor: { default: "#1d1d24" },
15
20
  textColor: { default: "#c8d3de" },
@@ -22,418 +27,457 @@ const qe = ["onMousedown", "onClick", "onContextmenu"], je = ["onClick"], Ge = [
22
27
  showCheckbox: { type: Boolean, default: !1 },
23
28
  checkStrictly: { type: Boolean, default: !1 },
24
29
  defaultCheckedKeys: { default: () => [] },
25
- disabledChecked: {}
30
+ disabledChecked: {},
31
+ filterNodeMethod: {}
26
32
  },
27
33
  emits: ["node-click", "node-contextmenu", "node-drop", "current-change", "check-change"],
28
- setup(p, { expose: le, emit: j }) {
29
- const l = p, L = j, Se = N(() => l.props.value || "value"), Me = N(() => l.props.label || "label"), G = N(() => l.props.children || "children"), Ae = N(() => Array.isArray(l.data) ? l.data.length === 0 : !0), w = s(/* @__PURE__ */ new Set()), h = s(/* @__PURE__ */ new Set()), g = s(/* @__PURE__ */ new Set());
30
- function re(e) {
34
+ setup(f, { expose: re, emit: ee }) {
35
+ const l = f, I = ee, Ke = O(() => l.props.value || "value"), He = O(() => l.props.label || "label"), te = O(() => l.props.children || "children"), Re = O(() => Array.isArray(l.data) ? l.data.length === 0 : !0), w = s(/* @__PURE__ */ new Set()), p = s(/* @__PURE__ */ new Set()), x = s(/* @__PURE__ */ new Set()), se = s(null);
36
+ function he(e) {
31
37
  return w.value.has(e);
32
38
  }
33
- function ze(e) {
34
- w.value.has(e) ? w.value.delete(e) : w.value.add(e), i.value = b(l.data || []), C(() => {
35
- I(), x();
39
+ function Le(e) {
40
+ w.value.has(e) ? w.value.delete(e) : w.value.add(e), r.value = b(l.data || []), C(() => {
41
+ T(), m();
36
42
  });
37
43
  }
38
- function k(e) {
39
- return e[Se.value];
44
+ function y(e) {
45
+ return e[Ke.value];
40
46
  }
41
- function K(e) {
42
- const t = e[G.value];
47
+ function M(e) {
48
+ const t = e[te.value];
43
49
  return Array.isArray(t) ? t : [];
44
50
  }
45
- function Te(e) {
46
- return h.value.has(e);
51
+ function Ee(e) {
52
+ return p.value.has(e);
47
53
  }
48
- function Ke(e) {
49
- return g.value.has(e);
54
+ function Ie(e) {
55
+ return x.value.has(e);
50
56
  }
51
- function ae(e, t) {
52
- if (t ? h.value.add(e) : h.value.delete(e), g.value.delete(e), !l.checkStrictly) {
53
- const n = ie(e, l.data || []);
57
+ function ce(e, t) {
58
+ if (t ? p.value.add(e) : p.value.delete(e), x.value.delete(e), !l.checkStrictly) {
59
+ const n = ve(e, l.data || []);
54
60
  if (n) {
55
61
  const a = [n];
56
62
  for (; a.length; ) {
57
- const c = a.pop(), o = k(c);
58
- t ? h.value.add(o) : h.value.delete(o), g.value.delete(o);
59
- const f = K(c);
60
- for (const r of f) a.push(r);
63
+ const i = a.pop(), o = y(i);
64
+ t ? p.value.add(o) : p.value.delete(o), x.value.delete(o);
65
+ const v = M(i);
66
+ for (const c of v) a.push(c);
61
67
  }
62
- const u = Z(e, l.data || []) || [];
63
- for (const c of u) {
64
- const o = k(c), f = K(c);
65
- let r = !0, d = !1;
66
- for (const y of f) {
67
- const te = k(y), xe = h.value.has(te), ye = g.value.has(te);
68
- (xe || ye) && (d = !0), (!xe || ye) && (r = !1);
68
+ const u = oe(e, l.data || []) || [];
69
+ for (const i of u) {
70
+ const o = y(i), v = M(i);
71
+ let c = !0, d = !1;
72
+ for (const g of v) {
73
+ const z = y(g), G = p.value.has(z), ue = x.value.has(z);
74
+ (G || ue) && (d = !0), (!G || ue) && (c = !1);
69
75
  }
70
- f.length === 0 ? (h.value.has(o), g.value.delete(o)) : r ? (h.value.add(o), g.value.delete(o)) : d ? (h.value.delete(o), g.value.add(o)) : (h.value.delete(o), g.value.delete(o));
76
+ v.length === 0 ? (p.value.has(o), x.value.delete(o)) : c ? (p.value.add(o), x.value.delete(o)) : d ? (p.value.delete(o), x.value.add(o)) : (p.value.delete(o), x.value.delete(o));
71
77
  }
72
78
  }
73
79
  }
74
80
  }
75
- function de(e) {
76
- h.value = /* @__PURE__ */ new Set(), g.value = /* @__PURE__ */ new Set();
77
- for (const t of e || []) ae(t, !0);
81
+ function ge(e) {
82
+ p.value = /* @__PURE__ */ new Set(), x.value = /* @__PURE__ */ new Set();
83
+ for (const t of e || []) ce(t, !0);
78
84
  }
79
- function Ee(e, t) {
85
+ function De(e, t) {
80
86
  const n = t.target;
81
- l.disabledChecked && l.disabledChecked(e.node) || (L("check-change", e.node, !!n.checked), ae(e.id, !!n.checked));
87
+ l.disabledChecked && l.disabledChecked(e.node) || (I("check-change", e.node, !!n.checked), ce(e.id, !!n.checked));
82
88
  }
83
89
  function b(e) {
84
90
  const t = [];
85
- function n(a, u, c) {
91
+ function n(a, u, i) {
86
92
  for (let o = 0; o < a.length; o++) {
87
- const f = a[o], r = k(f), d = K(f), y = d.length === 0;
88
- t.push({ id: r, node: f, parent: u, level: c, index: o, isLeaf: y }), !y && w.value.has(r) && n(d, f, c + 1);
93
+ const v = a[o], c = y(v), d = M(v), g = d.length === 0;
94
+ t.push({ id: c, node: v, parent: u, level: i, index: o, isLeaf: g }), !g && w.value.has(c) && n(d, v, i + 1);
89
95
  }
90
96
  }
91
- return n(e, null, 0), t;
97
+ if (n(e, null, 0), l.filterNodeMethod && se.value != null) {
98
+ let a = function(o) {
99
+ const v = y(o), c = M(o);
100
+ let d = !1;
101
+ for (const z of c) d = a(z) || d;
102
+ const g = !!l.filterNodeMethod(se.value, o);
103
+ return g && u.add(v), d && i.add(v), g || d;
104
+ };
105
+ const u = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
106
+ for (const o of e) a(o);
107
+ return t.filter((o) => u.has(o.id) || i.has(o.id));
108
+ }
109
+ return t;
110
+ }
111
+ const h = s(null), R = s(0), U = s(0), r = s([]), D = Me(/* @__PURE__ */ new Map());
112
+ function Ye(e) {
113
+ if (typeof e == "number") return e;
114
+ if (typeof e == "string") {
115
+ const t = e.match(/(\d+(\.\d+)?)/);
116
+ return t ? Number(t[1]) : 32;
117
+ }
118
+ return 32;
92
119
  }
93
- const v = s(null), E = s(0), O = s(0), i = s([]), R = we(/* @__PURE__ */ new Map()), m = N(() => {
120
+ const X = Ye(l.rowHeight), k = O(() => {
94
121
  let e = 0;
95
122
  const t = [];
96
- for (const n of i.value) {
97
- const a = R.get(n.id) || q;
123
+ for (const n of r.value) {
124
+ const a = D.get(n.id) || X;
98
125
  e += a, t.push(e);
99
126
  }
100
127
  return t;
101
- }), ve = N(() => {
102
- const e = m.value;
128
+ }), pe = O(() => {
129
+ const e = k.value;
103
130
  return e.length ? e[e.length - 1] : 0;
104
131
  });
105
- function fe(e) {
106
- let t = 0, n = m.value.length - 1, a = 0;
132
+ function me(e) {
133
+ let t = 0, n = k.value.length - 1, a = 0;
107
134
  for (; t <= n; ) {
108
135
  const u = t + n >> 1;
109
- m.value[u] !== void 0 && m.value[u] >= e ? (a = u, n = u - 1) : t = u + 1;
136
+ k.value[u] !== void 0 && k.value[u] >= e ? (a = u, n = u - 1) : t = u + 1;
110
137
  }
111
138
  return a;
112
139
  }
113
- const B = s(0), S = s(0), D = s(0), oe = s(0);
114
- function x() {
115
- if (O.value = v.value?.clientHeight || 0, m.value.length === 0 || i.value.length === 0) {
116
- B.value = 0, S.value = 0, D.value = 0, oe.value = 0;
140
+ const Y = s(0), A = s(0), B = s(0), de = s(0);
141
+ function m() {
142
+ if (U.value = h.value?.clientHeight || 0, k.value.length === 0 || r.value.length === 0) {
143
+ Y.value = 0, A.value = 0, B.value = 0, de.value = 0;
117
144
  return;
118
145
  }
119
- const e = fe(E.value);
120
- B.value = Math.max(0, e - 3);
121
- const t = i.value[B.value], n = t ? R.get(t.id) || q : 0, u = (m.value[B.value] ?? 0) - n;
122
- D.value = Math.max(0, u);
123
- let c = B.value;
124
- const o = E.value + O.value + 3 * q;
125
- for (; c < i.value.length && (m.value[c] ?? 0) < o; ) c++;
126
- S.value = Math.min(i.value.length, c + 1);
127
- const r = (m.value[S.value - 1] ?? 0) - D.value;
128
- if (r < O.value && S.value < i.value.length) {
129
- let d = S.value, y = r;
130
- for (; y < O.value && d < i.value.length; )
131
- d++, y = (m.value[d - 1] ?? 0) - D.value;
132
- S.value = d;
146
+ const e = me(R.value);
147
+ Y.value = Math.max(0, e - 3);
148
+ const t = r.value[Y.value], n = t ? D.get(t.id) || X : 0, u = (k.value[Y.value] ?? 0) - n;
149
+ B.value = Math.max(0, u);
150
+ let i = Y.value;
151
+ const o = R.value + U.value + 3 * X;
152
+ for (; i < r.value.length && (k.value[i] ?? 0) < o; ) i++;
153
+ A.value = Math.min(r.value.length, i + 1);
154
+ const c = (k.value[A.value - 1] ?? 0) - B.value;
155
+ if (c < U.value && A.value < r.value.length) {
156
+ let d = A.value, g = c;
157
+ for (; g < U.value && d < r.value.length; )
158
+ d++, g = (k.value[d - 1] ?? 0) - B.value;
159
+ A.value = d;
133
160
  }
134
- oe.value = Math.max(0, ve.value - D.value - ((m.value[S.value - 1] ?? 0) - D.value));
135
- }
136
- _([E, () => l.data, w], () => {
137
- i.value = b(l.data || []), C(I), x();
138
- }), Pe(() => {
139
- i.value = b(l.data || []), C(I), x(), l.defaultCheckedKeys && l.defaultCheckedKeys.length && de(l.defaultCheckedKeys), v.value && (P = new ResizeObserver(() => {
140
- O.value = v.value?.clientHeight || 0, x();
141
- }), P.observe(v.value));
161
+ de.value = Math.max(0, pe.value - B.value - ((k.value[A.value - 1] ?? 0) - B.value));
162
+ }
163
+ P([R, () => l.data, w], () => {
164
+ r.value = b(l.data || []), C(T), m();
165
+ }), Ge(() => {
166
+ r.value = b(l.data || []), C(T), m(), l.defaultCheckedKeys && l.defaultCheckedKeys.length && ge(l.defaultCheckedKeys), h.value && ($ = new ResizeObserver(() => {
167
+ U.value = h.value?.clientHeight || 0, m();
168
+ }), $.observe(h.value));
142
169
  });
143
- let P = null;
144
- Ve(() => {
145
- P && (P.disconnect(), P = null);
170
+ let $ = null;
171
+ Je(() => {
172
+ $ && ($.disconnect(), $ = null);
146
173
  });
147
- const J = we(/* @__PURE__ */ new Map());
148
- function Ie(e, t) {
149
- t ? J.set(e, t) : J.delete(e);
174
+ const ne = Me(/* @__PURE__ */ new Map());
175
+ function Be(e, t) {
176
+ t ? ne.set(e, t) : ne.delete(e);
150
177
  }
151
- function I() {
178
+ function T() {
152
179
  let e = !1;
153
- for (const t of i.value.slice(B.value, S.value)) {
154
- const n = J.get(t.id);
180
+ for (const t of r.value.slice(Y.value, A.value)) {
181
+ const n = ne.get(t.id);
155
182
  if (n) {
156
183
  const a = n.offsetHeight;
157
- (!R.has(t.id) || R.get(t.id) !== a) && (R.set(t.id, a), e = !0);
184
+ (!D.has(t.id) || D.get(t.id) !== a) && (D.set(t.id, a), e = !0);
158
185
  }
159
186
  }
160
- e && x();
187
+ e && m();
161
188
  }
162
- function Le() {
163
- E.value = v.value?.scrollTop || 0, x();
189
+ function Ne() {
190
+ R.value = h.value?.scrollTop || 0, m();
164
191
  }
165
- const M = s(!1), ue = s(null), V = s(null), A = s(null), ce = s(0), H = s(null), U = s(0);
166
- let F = null;
167
- function Q() {
168
- F != null && (cancelAnimationFrame(F), F = null);
192
+ const L = s(!1), q = s(null), F = s(null), S = s(null), fe = s(0), Z = s(!1), we = s(0), xe = s(0), E = s(null), Q = s(0);
193
+ let W = null;
194
+ function le() {
195
+ W != null && (cancelAnimationFrame(W), W = null);
169
196
  }
170
- function he() {
171
- if (!M.value || U.value === 0) {
172
- Q();
197
+ function ye() {
198
+ if (!L.value || Q.value === 0) {
199
+ le();
173
200
  return;
174
201
  }
175
- const e = v.value;
202
+ const e = h.value;
176
203
  if (!e) {
177
- Q();
204
+ le();
178
205
  return;
179
206
  }
180
207
  const t = e.scrollHeight - e.clientHeight, n = 12;
181
- e.scrollTop = Math.max(0, Math.min(t, e.scrollTop + U.value * n)), E.value = e.scrollTop, x(), F = requestAnimationFrame(he);
208
+ e.scrollTop = Math.max(0, Math.min(t, e.scrollTop + Q.value * n)), R.value = e.scrollTop, m(), W = requestAnimationFrame(ye);
182
209
  }
183
- function Re() {
184
- U.value !== 0 && F == null && (F = requestAnimationFrame(he)), U.value === 0 && Q();
210
+ function Fe() {
211
+ Q.value !== 0 && W == null && (W = requestAnimationFrame(ye)), Q.value === 0 && le();
185
212
  }
186
- function X(e) {
213
+ function ae(e) {
187
214
  if (e == null) return null;
188
- for (const t of i.value) if (t.id === e) return t;
215
+ for (const t of r.value) if (t.id === e) return t;
189
216
  return null;
190
217
  }
191
- function Be(e) {
192
- const t = v.value.getBoundingClientRect(), n = e - t.top + E.value;
193
- return fe(n);
194
- }
195
- function De(e, t) {
196
- !l.draggable || t.button !== 0 || !(!l.allowDrag || l.allowDrag(e.node)) || (M.value = !0, ue.value = e.id, ce.value = t.clientY, t.preventDefault(), window.addEventListener("mousemove", pe), window.addEventListener("mouseup", ge));
197
- }
198
- function pe(e) {
199
- if (!M.value) return;
200
- ce.value = e.clientY;
201
- const t = Be(e.clientY), n = i.value[Math.min(Math.max(t, 0), i.value.length - 1)];
202
- if (V.value = n?.id ?? null, !n) {
203
- A.value = null;
218
+ function We(e) {
219
+ const t = h.value.getBoundingClientRect(), n = e - t.top + R.value;
220
+ return me(n);
221
+ }
222
+ function Oe(e, t) {
223
+ !l.draggable || t.button !== 0 || !(!l.allowDrag || l.allowDrag(e.node)) || (q.value = e.id, fe.value = t.clientY, we.value = t.clientX, xe.value = t.clientY, Z.value = !1, t.preventDefault(), window.addEventListener("mousemove", ke), window.addEventListener("mouseup", Ce));
224
+ }
225
+ function ke(e) {
226
+ if (q.value == null) return;
227
+ if (!Z.value) {
228
+ const Ze = Math.abs(e.clientX - we.value), Qe = Math.abs(e.clientY - xe.value), Se = Math.max(1, l.dragStartThreshold ?? 4);
229
+ if (Ze < Se && Qe < Se) return;
230
+ Z.value = !0, L.value = !0;
231
+ }
232
+ fe.value = e.clientY;
233
+ const t = We(e.clientY), n = r.value[Math.min(Math.max(t, 0), r.value.length - 1)];
234
+ if (F.value = n?.id ?? null, !n) {
235
+ S.value = null;
204
236
  return;
205
237
  }
206
- const a = m.value[t] ?? 0, u = R.get(n.id) ?? q, c = a - u, o = v.value.getBoundingClientRect(), r = (e.clientY - o.top + E.value - c) / u;
207
- let d = "inner";
208
- r < 0.25 ? d = "prev" : r > 0.75 && (d = "next");
209
- const y = X(ue.value), te = l.allowDrop ? !!(y && l.allowDrop(y.node, n.node, d)) : !0;
210
- A.value = te ? d : null, U.value = e.clientY > o.bottom ? 1 : e.clientY < o.top ? -1 : 0, Re();
238
+ const a = k.value[t] ?? 0, u = D.get(n.id) ?? X, i = a - u, o = h.value.getBoundingClientRect(), c = (e.clientY - o.top + R.value - i) / u, d = l.siblingZoneRatio ?? 0.35, g = Math.max(0.05, Math.min(0.49, d));
239
+ let z = "inner";
240
+ c < g ? z = "prev" : c > 1 - g && (z = "next");
241
+ const G = ae(q.value), ue = l.allowDrop ? !!(G && l.allowDrop(G.node, n.node, z)) : !0;
242
+ S.value = ue ? z : null, Q.value = e.clientY > o.bottom ? 1 : e.clientY < o.top ? -1 : 0, Fe();
211
243
  }
212
- function Z(e, t, n = []) {
244
+ function oe(e, t, n = []) {
213
245
  for (const a of t) {
214
- if (k(a) === e) return n;
215
- const u = K(a);
246
+ if (y(a) === e) return n;
247
+ const u = M(a);
216
248
  if (u.length) {
217
- const c = Z(e, u, [...n, a]);
218
- if (c) return c;
249
+ const i = oe(e, u, [...n, a]);
250
+ if (i) return i;
219
251
  }
220
252
  }
221
253
  return null;
222
254
  }
223
- function ie(e, t) {
255
+ function ve(e, t) {
224
256
  if (e == null) return null;
225
257
  for (const n of t) {
226
- if (k(n) === e) return n;
227
- const a = K(n), u = ie(e, a);
258
+ if (y(n) === e) return n;
259
+ const a = M(n), u = ve(e, a);
228
260
  if (u) return u;
229
261
  }
230
262
  return null;
231
263
  }
232
- function ee(e) {
264
+ function j(e) {
233
265
  const t = [];
234
266
  for (const n of e) {
235
- t.push(k(n));
236
- const a = K(n);
237
- a.length && t.push(...ee(a));
267
+ t.push(y(n));
268
+ const a = M(n);
269
+ a.length && t.push(...j(a));
238
270
  }
239
271
  return t;
240
272
  }
241
- function He(e) {
273
+ function Pe(e) {
242
274
  const t = e.parent;
243
275
  if (t)
244
- K(t).splice(e.index, 1);
276
+ M(t).splice(e.index, 1);
245
277
  else {
246
- const n = l.data.findIndex((a) => k(a) === e.id);
278
+ const n = l.data.findIndex((a) => y(a) === e.id);
247
279
  n >= 0 && l.data.splice(n, 1);
248
280
  }
249
281
  }
250
- function Ye(e, t, n) {
282
+ function Ve(e, t, n) {
251
283
  if (n === "inner") {
252
- Array.isArray(t.node[G.value]) || (t.node[G.value] = []), t.node[G.value].push(e), w.value.add(t.id);
284
+ Array.isArray(t.node[te.value]) || (t.node[te.value] = []), t.node[te.value].push(e), w.value.add(t.id);
253
285
  return;
254
286
  }
255
287
  const a = t.parent;
256
288
  if (a) {
257
- const u = K(a), c = t.index + (n === "next" ? 1 : 0);
258
- u.splice(c, 0, e);
289
+ const u = M(a), i = t.index + (n === "next" ? 1 : 0);
290
+ u.splice(i, 0, e);
259
291
  } else {
260
292
  const u = t.index + (n === "next" ? 1 : 0);
261
293
  l.data.splice(u, 0, e);
262
294
  }
263
295
  }
264
- function ge() {
265
- if (window.removeEventListener("mousemove", pe), window.removeEventListener("mouseup", ge), Q(), !M.value) return;
266
- const e = X(ue.value), t = X(V.value), n = A.value;
267
- if (M.value = !1, A.value = null, V.value = null, !e || !t || !n || l.allowDrop && !l.allowDrop(e.node, t.node, n) || e.id === t.id) return;
296
+ function Ce() {
297
+ if (window.removeEventListener("mousemove", ke), window.removeEventListener("mouseup", Ce), le(), !L.value) {
298
+ q.value = null, S.value = null, F.value = null, Z.value = !1;
299
+ return;
300
+ }
301
+ const e = ae(q.value), t = ae(F.value), n = S.value;
302
+ if (L.value = !1, Z.value = !1, S.value = null, F.value = null, !e || !t || !n || l.allowDrop && !l.allowDrop(e.node, t.node, n) || e.id === t.id) return;
268
303
  const a = n === "inner" ? t.node : t.parent || null;
269
304
  if (a) {
270
- const f = Z(k(a), l.data || []) || [];
271
- for (const r of f) if (k(r) === e.id) return;
305
+ const v = oe(y(a), l.data || []) || [];
306
+ for (const c of v) if (y(c) === e.id) return;
272
307
  }
273
308
  const u = e.node;
274
- He(e);
275
- const c = b(l.data || []);
276
- i.value = c;
277
- const o = X(t.id) || t;
278
- Ye(u, o, n), i.value = b(l.data || []), C(() => {
279
- I(), x();
280
- }), L("node-drop", u, o.node, n);
281
- }
282
- function Fe(e, t) {
283
- H.value = e.id, L("node-click", e.node, t);
284
- }
285
- function Ne(e, t) {
286
- L("node-contextmenu", e.node, t);
287
- }
288
- Ue(() => {
289
- C(I);
290
- }), _(
309
+ Pe(e);
310
+ const i = b(l.data || []);
311
+ r.value = i;
312
+ const o = ae(t.id) || t;
313
+ Ve(u, o, n), r.value = b(l.data || []), C(() => {
314
+ T(), m();
315
+ }), I("node-drop", u, o.node, n);
316
+ }
317
+ function Ue(e, t) {
318
+ E.value = e.id, I("node-click", e.node, t);
319
+ }
320
+ function Xe(e, t) {
321
+ E.value = e.id, I("node-contextmenu", e.node, t);
322
+ }
323
+ _e(() => {
324
+ C(T);
325
+ }), P(
291
326
  () => l.currentNodeKey,
292
327
  (e) => {
293
- H.value = e ?? null;
328
+ E.value = e ?? null;
294
329
  },
295
330
  { immediate: !0 }
296
- ), _(
331
+ ), P(
297
332
  () => l.defaultExpandedKeys,
298
333
  (e) => {
299
- w.value = new Set(e || []), i.value = b(l.data || []), C(() => {
300
- I(), x();
334
+ w.value = new Set(e || []), r.value = b(l.data || []), C(() => {
335
+ T(), m();
301
336
  });
302
337
  },
303
338
  { immediate: !0 }
304
- ), _(
339
+ ), P(
305
340
  () => l.defaultExpandAll,
306
341
  (e) => {
307
- e && (w.value = new Set(ee(l.data || [])), i.value = b(l.data || []), C(() => {
308
- I(), x();
342
+ e && (w.value = new Set(j(l.data || [])), r.value = b(l.data || []), C(() => {
343
+ T(), m();
309
344
  }));
310
345
  },
311
346
  { immediate: !0 }
312
- ), _(
347
+ ), P(
313
348
  () => l.data,
314
349
  () => {
315
- l.defaultExpandAll && (w.value = new Set(ee(l.data || []))), i.value = b(l.data || []), C(() => {
316
- I(), x();
350
+ l.defaultExpandAll && (w.value = new Set(j(l.data || []))), r.value = b(l.data || []), C(() => {
351
+ T(), m();
317
352
  });
318
- const e = new Set(ee(l.data || []));
319
- h.value = new Set([...h.value].filter((t) => e.has(t))), g.value = new Set([...g.value].filter((t) => e.has(t)));
353
+ const e = new Set(j(l.data || []));
354
+ p.value = new Set([...p.value].filter((t) => e.has(t))), x.value = new Set([...x.value].filter((t) => e.has(t)));
320
355
  },
321
356
  { deep: !0 }
322
357
  );
323
- function _e(e) {
324
- const t = Z(e, l.data || []) || [];
325
- for (const n of t) w.value.add(k(n));
326
- i.value = b(l.data || []);
327
- }
328
- function me(e) {
329
- e != null && (_e(e), C(() => {
330
- const t = i.value.findIndex((o) => o.id === e);
331
- if (t < 0 || !v.value) return;
332
- const n = R.get(e) || q, a = (m.value[t] ?? 0) - n, u = v.value.clientHeight, c = Math.max(0, a - Math.max(0, (u - n) / 2));
333
- v.value.scrollTop = c, E.value = c, x(), C(() => {
334
- const o = J.get(e);
335
- if (!o || !v.value) return;
336
- const f = o.offsetLeft, r = o.offsetWidth, d = v.value.clientWidth, y = Math.max(0, f + Math.max(0, r / 2) - Math.max(0, d / 2));
337
- v.value.scrollLeft = y;
358
+ function $e(e) {
359
+ const t = oe(e, l.data || []) || [];
360
+ for (const n of t) w.value.add(y(n));
361
+ r.value = b(l.data || []);
362
+ }
363
+ function be(e) {
364
+ e != null && ($e(e), C(() => {
365
+ const t = r.value.findIndex((o) => o.id === e);
366
+ if (t < 0 || !h.value) return;
367
+ const n = D.get(e) || X, a = (k.value[t] ?? 0) - n, u = h.value.clientHeight, i = Math.max(0, a - Math.max(0, (u - n) / 2));
368
+ h.value.scrollTop = i, R.value = i, m(), C(() => {
369
+ const o = ne.get(e);
370
+ if (!o || !h.value) return;
371
+ const v = o.offsetLeft, c = o.offsetWidth, d = h.value.clientWidth, g = Math.max(0, v + Math.max(0, c / 2) - Math.max(0, d / 2));
372
+ h.value.scrollLeft = g;
338
373
  });
339
374
  }));
340
375
  }
341
- function We(e) {
342
- H.value = e ?? null, me(H.value);
343
- }
344
- return le({
345
- getCurrentKey: () => H.value,
346
- setCurrentKey: We,
347
- scrollTo: me,
348
- getCheckedKeys: () => Array.from(h.value),
349
- setCheckedKeys: de,
350
- setChecked: (e, t) => ae(e, t)
351
- }), _(H, (e) => {
352
- const t = ie(e, l.data || []);
353
- t && L("current-change", t);
354
- }), (e, t) => (T(), z("div", {
376
+ function qe(e) {
377
+ E.value = e ?? null, be(E.value);
378
+ }
379
+ return re({
380
+ getCurrentKey: () => E.value,
381
+ setCurrentKey: qe,
382
+ scrollTo: be,
383
+ getCheckedKeys: () => Array.from(p.value),
384
+ setCheckedKeys: ge,
385
+ setChecked: (e, t) => ce(e, t),
386
+ filter: (e) => {
387
+ se.value = e, w.value = new Set(j(l.data || [])), r.value = b(l.data || []), C(() => {
388
+ T(), m();
389
+ });
390
+ }
391
+ }), P(E, (e) => {
392
+ const t = ve(e, l.data || []);
393
+ t && I("current-change", t);
394
+ }), (e, t) => (H(), K("div", {
355
395
  ref_key: "containerRef",
356
- ref: v,
357
- class: $(["amazing-tree", { "is-dragging": M.value }]),
358
- style: W({ height: typeof p.height == "number" ? p.height + "px" : p.height || "100%", "--vtree-bg": p.backgroundColor, "--vtree-text": p.textColor, "--vtree-hover": p.hoverColor }),
359
- onScroll: Le
396
+ ref: h,
397
+ class: J(["amazing-tree", { "is-dragging": L.value }]),
398
+ style: V({ height: typeof f.height == "number" ? f.height + "px" : f.height || "100%", "--vtree-bg": f.backgroundColor, "--vtree-text": f.textColor, "--vtree-hover": f.hoverColor, "--vtree-row-height": typeof f.rowHeight == "number" ? f.rowHeight + "px" : f.rowHeight || "32px", "--vtree-drop-line": f.dropLineColor, "--vtree-drop-inner": f.innerDashColor }),
399
+ onScroll: Ne
360
400
  }, [
361
- Ae.value ? (T(), z("div", Qe, [
362
- Ce(e.$slots, "empty", {}, () => [
363
- Y("div", Xe, be(p.emptyText), 1)
401
+ Re.value ? (H(), K("div", ot, [
402
+ Te(e.$slots, "empty", {}, () => [
403
+ N("div", ut, ze(f.emptyText), 1)
364
404
  ], !0)
365
- ])) : (T(), z(ke, { key: 0 }, [
366
- Y("div", {
367
- style: W({ height: ve.value + "px", position: "relative", minWidth: "100%", width: "max-content" })
405
+ ])) : (H(), K(Ae, { key: 0 }, [
406
+ N("div", {
407
+ style: V({ height: pe.value + "px", position: "relative", minWidth: "100%", width: "max-content" })
368
408
  }, [
369
- Y("div", {
370
- style: W({ height: D.value + "px" })
409
+ N("div", {
410
+ style: V({ height: B.value + "px" })
371
411
  }, null, 4),
372
- (T(!0), z(ke, null, $e(i.value.slice(B.value, S.value), (n) => (T(), z("div", {
412
+ (H(!0), K(Ae, null, et(r.value.slice(Y.value, A.value), (n) => (H(), K("div", {
373
413
  key: n.id,
374
414
  class: "amazing-tree-row-wrapper"
375
415
  }, [
376
- Y("div", {
377
- class: $(["amazing-tree-row", { "is-target-inner": M.value && V.value === n.id && A.value === "inner", "is-active": H.value === n.id }]),
378
- style: W({ paddingLeft: n.level * 16 + "px", "--active-color": p.highlightColor }),
379
- onMousedown: (a) => De(n, a),
380
- onClick: (a) => Fe(n, a),
381
- onContextmenu: se((a) => Ne(n, a), ["prevent"]),
416
+ N("div", {
417
+ class: J(["amazing-tree-row", { "is-target-inner": L.value && F.value === n.id && S.value === "inner", "is-active": E.value === n.id }]),
418
+ style: V({ paddingLeft: n.level * 16 + "px", "--active-color": f.highlightColor }),
419
+ onMousedown: (a) => Oe(n, a),
420
+ onClick: (a) => Ue(n, a),
421
+ onContextmenu: _((a) => Xe(n, a), ["prevent"]),
382
422
  ref_for: !0,
383
- ref: (a) => Ie(n.id, a)
423
+ ref: (a) => Be(n.id, a)
384
424
  }, [
385
- Y("span", {
386
- class: $(["amazing-tree-caret-box", { "is-leaf": n.isLeaf }]),
387
- onClick: se((a) => !n.isLeaf && ze(n.id), ["stop"])
425
+ N("span", {
426
+ class: J(["amazing-tree-caret-box", { "is-leaf": n.isLeaf }]),
427
+ onMousedown: t[0] || (t[0] = _(() => {
428
+ }, ["stop"])),
429
+ onClick: _((a) => !n.isLeaf && Le(n.id), ["stop"])
388
430
  }, [
389
- n.isLeaf ? ne("", !0) : (T(), z("span", {
431
+ n.isLeaf ? ie("", !0) : (H(), K("span", {
390
432
  key: 0,
391
- class: $(["amazing-tree-caret", { expanded: re(n.id) }])
433
+ class: J(["amazing-tree-caret", { expanded: he(n.id) }])
392
434
  }, null, 2))
393
- ], 10, je),
394
- p.showCheckbox ? (T(), z("input", {
435
+ ], 42, nt),
436
+ f.showCheckbox ? (H(), K("input", {
395
437
  key: 0,
396
438
  class: "amazing-tree-checkbox",
397
439
  type: "checkbox",
398
- checked: Te(n.id),
399
- indeterminate: Ke(n.id),
440
+ checked: Ee(n.id),
441
+ onMousedown: t[1] || (t[1] = _(() => {
442
+ }, ["stop"])),
443
+ indeterminate: Ie(n.id),
400
444
  disabled: l.disabledChecked ? l.disabledChecked(n.node) : !1,
401
- onClick: se((a) => Ee(n, a), ["stop"])
402
- }, null, 8, Ge)) : ne("", !0),
403
- Ce(e.$slots, "default", {
445
+ onClick: _((a) => De(n, a), ["stop"])
446
+ }, null, 40, lt)) : ie("", !0),
447
+ Te(e.$slots, "default", {
404
448
  node: n.node,
405
449
  data: n.node,
406
450
  level: n.level,
407
- expanded: re(n.id),
451
+ expanded: he(n.id),
408
452
  isLeaf: n.isLeaf
409
453
  }, () => [
410
- Y("span", Je, be(n.node[Me.value]), 1)
454
+ N("span", at, ze(n.node[He.value]), 1)
411
455
  ], !0)
412
- ], 46, qe),
413
- M.value && V.value === n.id && (A.value === "prev" || A.value === "next") ? (T(), z("div", {
456
+ ], 46, tt),
457
+ L.value && F.value === n.id && (S.value === "prev" || S.value === "next") ? (H(), K("div", {
414
458
  key: 0,
415
- class: $(["amazing-tree-drop-line", { "is-prev": A.value === "prev", "is-next": A.value === "next" }])
416
- }, null, 2)) : ne("", !0)
459
+ class: J(["amazing-tree-drop-line", { "is-prev": S.value === "prev", "is-next": S.value === "next" }])
460
+ }, null, 2)) : ie("", !0)
417
461
  ]))), 128)),
418
- Y("div", {
419
- style: W({ height: oe.value + "px" })
462
+ N("div", {
463
+ style: V({ height: de.value + "px" })
420
464
  }, null, 4)
421
465
  ], 4),
422
- M.value ? (T(), z("div", {
466
+ L.value ? (H(), K("div", {
423
467
  key: 0,
424
468
  class: "amazing-tree-ghost",
425
- style: W({ top: ce.value + "px" })
426
- }, null, 4)) : ne("", !0)
469
+ style: V({ top: fe.value + "px" })
470
+ }, null, 4)) : ie("", !0)
427
471
  ], 64))
428
472
  ], 38));
429
473
  }
430
- }), et = (p, le) => {
431
- const j = p.__vccOpts || p;
432
- for (const [l, L] of le)
433
- j[l] = L;
434
- return j;
435
- }, nt = /* @__PURE__ */ et(Ze, [["__scopeId", "data-v-6ef943bb"]]);
474
+ }), rt = (f, re) => {
475
+ const ee = f.__vccOpts || f;
476
+ for (const [l, I] of re)
477
+ ee[l] = I;
478
+ return ee;
479
+ }, ct = /* @__PURE__ */ rt(it, [["__scopeId", "data-v-fc218005"]]);
436
480
  export {
437
- nt as AmazingTree,
438
- nt as default
481
+ ct as AmazingTree,
482
+ ct as default
439
483
  };
@@ -1 +1 @@
1
- (function(z,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(z=typeof globalThis<"u"?globalThis:z||self,t(z.AmazingTree={},z.Vue))})(this,(function(z,t){"use strict";const fe=["onMousedown","onClick","onContextmenu"],he=["onClick"],ve=["checked","indeterminate","disabled","onClick"],me={class:"amazing-tree-label"},pe={key:1,class:"amazing-tree-empty"},ge={class:"amazing-tree-empty-inner"},V=28,te=((m,G)=>{const Y=m.__vccOpts||m;for(const[a,A]of G)Y[a]=A;return Y})(t.defineComponent({__name:"AmazingTree",props:{data:{},props:{default:()=>({value:"value",label:"label",children:"children"})},allowDrag:{},allowDrop:{},height:{default:void 0},highlightColor:{default:"#1e71ff"},backgroundColor:{default:"#1d1d24"},textColor:{default:"#c8d3de"},hoverColor:{default:"#5d90e5"},currentNodeKey:{},defaultExpandedKeys:{},defaultExpandAll:{type:Boolean,default:!1},draggable:{type:Boolean,default:!1},emptyText:{default:"暂无数据"},showCheckbox:{type:Boolean,default:!1},checkStrictly:{type:Boolean,default:!1},defaultCheckedKeys:{default:()=>[]},disabledChecked:{}},emits:["node-click","node-contextmenu","node-drop","current-change","check-change"],setup(m,{expose:G,emit:Y}){const a=m,A=Y,ke=t.computed(()=>a.props.value||"value"),xe=t.computed(()=>a.props.label||"label"),O=t.computed(()=>a.props.children||"children"),ye=t.computed(()=>Array.isArray(a.data)?a.data.length===0:!0),y=t.ref(new Set),v=t.ref(new Set),p=t.ref(new Set);function ne(e){return y.value.has(e)}function we(e){y.value.has(e)?y.value.delete(e):y.value.add(e),s.value=C(a.data||[]),t.nextTick(()=>{M(),k()})}function w(e){return e[ke.value]}function E(e){const n=e[O.value];return Array.isArray(n)?n:[]}function Ce(e){return v.value.has(e)}function be(e){return p.value.has(e)}function J(e,n){if(n?v.value.add(e):v.value.delete(e),p.value.delete(e),!a.checkStrictly){const l=ee(e,a.data||[]);if(l){const o=[l];for(;o.length;){const r=o.pop(),c=w(r);n?v.value.add(c):v.value.delete(c),p.value.delete(c);const h=E(r);for(const d of h)o.push(d)}const i=U(e,a.data||[])||[];for(const r of i){const c=w(r),h=E(r);let d=!0,u=!1;for(const x of h){const j=w(x),de=v.value.has(j),ue=p.value.has(j);(de||ue)&&(u=!0),(!de||ue)&&(d=!1)}h.length===0?(v.value.has(c),p.value.delete(c)):d?(v.value.add(c),p.value.delete(c)):u?(v.value.delete(c),p.value.add(c)):(v.value.delete(c),p.value.delete(c))}}}}function le(e){v.value=new Set,p.value=new Set;for(const n of e||[])J(n,!0)}function Se(e,n){const l=n.target;a.disabledChecked&&a.disabledChecked(e.node)||(A("check-change",e.node,!!l.checked),J(e.id,!!l.checked))}function C(e){const n=[];function l(o,i,r){for(let c=0;c<o.length;c++){const h=o[c],d=w(h),u=E(h),x=u.length===0;n.push({id:d,node:h,parent:i,level:r,index:c,isLeaf:x}),!x&&y.value.has(d)&&l(u,h,r+1)}}return l(e,null,0),n}const f=t.ref(null),B=t.ref(0),D=t.ref(0),s=t.ref([]),K=t.reactive(new Map),g=t.computed(()=>{let e=0;const n=[];for(const l of s.value){const o=K.get(l.id)||V;e+=o,n.push(e)}return n}),ae=t.computed(()=>{const e=g.value;return e.length?e[e.length-1]:0});function oe(e){let n=0,l=g.value.length-1,o=0;for(;n<=l;){const i=n+l>>1;g.value[i]!==void 0&&g.value[i]>=e?(o=i,l=i-1):n=i+1}return o}const I=t.ref(0),b=t.ref(0),L=t.ref(0),Q=t.ref(0);function k(){if(D.value=f.value?.clientHeight||0,g.value.length===0||s.value.length===0){I.value=0,b.value=0,L.value=0,Q.value=0;return}const e=oe(B.value);I.value=Math.max(0,e-3);const n=s.value[I.value],l=n?K.get(n.id)||V:0,i=(g.value[I.value]??0)-l;L.value=Math.max(0,i);let r=I.value;const c=B.value+D.value+3*V;for(;r<s.value.length&&(g.value[r]??0)<c;)r++;b.value=Math.min(s.value.length,r+1);const d=(g.value[b.value-1]??0)-L.value;if(d<D.value&&b.value<s.value.length){let u=b.value,x=d;for(;x<D.value&&u<s.value.length;)u++,x=(g.value[u-1]??0)-L.value;b.value=u}Q.value=Math.max(0,ae.value-L.value-((g.value[b.value-1]??0)-L.value))}t.watch([B,()=>a.data,y],()=>{s.value=C(a.data||[]),t.nextTick(M),k()}),t.onMounted(()=>{s.value=C(a.data||[]),t.nextTick(M),k(),a.defaultCheckedKeys&&a.defaultCheckedKeys.length&&le(a.defaultCheckedKeys),f.value&&(_=new ResizeObserver(()=>{D.value=f.value?.clientHeight||0,k()}),_.observe(f.value))});let _=null;t.onUnmounted(()=>{_&&(_.disconnect(),_=null)});const P=t.reactive(new Map);function Te(e,n){n?P.set(e,n):P.delete(e)}function M(){let e=!1;for(const n of s.value.slice(I.value,b.value)){const l=P.get(n.id);if(l){const o=l.offsetHeight;(!K.has(n.id)||K.get(n.id)!==o)&&(K.set(n.id,o),e=!0)}}e&&k()}function ze(){B.value=f.value?.scrollTop||0,k()}const S=t.ref(!1),X=t.ref(null),F=t.ref(null),T=t.ref(null),Z=t.ref(0),N=t.ref(null),H=t.ref(0);let R=null;function W(){R!=null&&(cancelAnimationFrame(R),R=null)}function ce(){if(!S.value||H.value===0){W();return}const e=f.value;if(!e){W();return}const n=e.scrollHeight-e.clientHeight,l=12;e.scrollTop=Math.max(0,Math.min(n,e.scrollTop+H.value*l)),B.value=e.scrollTop,k(),R=requestAnimationFrame(ce)}function Ee(){H.value!==0&&R==null&&(R=requestAnimationFrame(ce)),H.value===0&&W()}function q(e){if(e==null)return null;for(const n of s.value)if(n.id===e)return n;return null}function Be(e){const n=f.value.getBoundingClientRect(),l=e-n.top+B.value;return oe(l)}function Me(e,n){!a.draggable||n.button!==0||!(!a.allowDrag||a.allowDrag(e.node))||(S.value=!0,X.value=e.id,Z.value=n.clientY,n.preventDefault(),window.addEventListener("mousemove",ie),window.addEventListener("mouseup",re))}function ie(e){if(!S.value)return;Z.value=e.clientY;const n=Be(e.clientY),l=s.value[Math.min(Math.max(n,0),s.value.length-1)];if(F.value=l?.id??null,!l){T.value=null;return}const o=g.value[n]??0,i=K.get(l.id)??V,r=o-i,c=f.value.getBoundingClientRect(),d=(e.clientY-c.top+B.value-r)/i;let u="inner";d<.25?u="prev":d>.75&&(u="next");const x=q(X.value),j=a.allowDrop?!!(x&&a.allowDrop(x.node,l.node,u)):!0;T.value=j?u:null,H.value=e.clientY>c.bottom?1:e.clientY<c.top?-1:0,Ee()}function U(e,n,l=[]){for(const o of n){if(w(o)===e)return l;const i=E(o);if(i.length){const r=U(e,i,[...l,o]);if(r)return r}}return null}function ee(e,n){if(e==null)return null;for(const l of n){if(w(l)===e)return l;const o=E(l),i=ee(e,o);if(i)return i}return null}function $(e){const n=[];for(const l of e){n.push(w(l));const o=E(l);o.length&&n.push(...$(o))}return n}function Ae(e){const n=e.parent;if(n)E(n).splice(e.index,1);else{const l=a.data.findIndex(o=>w(o)===e.id);l>=0&&a.data.splice(l,1)}}function Ke(e,n,l){if(l==="inner"){Array.isArray(n.node[O.value])||(n.node[O.value]=[]),n.node[O.value].push(e),y.value.add(n.id);return}const o=n.parent;if(o){const i=E(o),r=n.index+(l==="next"?1:0);i.splice(r,0,e)}else{const i=n.index+(l==="next"?1:0);a.data.splice(i,0,e)}}function re(){if(window.removeEventListener("mousemove",ie),window.removeEventListener("mouseup",re),W(),!S.value)return;const e=q(X.value),n=q(F.value),l=T.value;if(S.value=!1,T.value=null,F.value=null,!e||!n||!l||a.allowDrop&&!a.allowDrop(e.node,n.node,l)||e.id===n.id)return;const o=l==="inner"?n.node:n.parent||null;if(o){const h=U(w(o),a.data||[])||[];for(const d of h)if(w(d)===e.id)return}const i=e.node;Ae(e);const r=C(a.data||[]);s.value=r;const c=q(n.id)||n;Ke(i,c,l),s.value=C(a.data||[]),t.nextTick(()=>{M(),k()}),A("node-drop",i,c.node,l)}function Ie(e,n){N.value=e.id,A("node-click",e.node,n)}function Le(e,n){A("node-contextmenu",e.node,n)}t.watchEffect(()=>{t.nextTick(M)}),t.watch(()=>a.currentNodeKey,e=>{N.value=e??null},{immediate:!0}),t.watch(()=>a.defaultExpandedKeys,e=>{y.value=new Set(e||[]),s.value=C(a.data||[]),t.nextTick(()=>{M(),k()})},{immediate:!0}),t.watch(()=>a.defaultExpandAll,e=>{e&&(y.value=new Set($(a.data||[])),s.value=C(a.data||[]),t.nextTick(()=>{M(),k()}))},{immediate:!0}),t.watch(()=>a.data,()=>{a.defaultExpandAll&&(y.value=new Set($(a.data||[]))),s.value=C(a.data||[]),t.nextTick(()=>{M(),k()});const e=new Set($(a.data||[]));v.value=new Set([...v.value].filter(n=>e.has(n))),p.value=new Set([...p.value].filter(n=>e.has(n)))},{deep:!0});function Ne(e){const n=U(e,a.data||[])||[];for(const l of n)y.value.add(w(l));s.value=C(a.data||[])}function se(e){e!=null&&(Ne(e),t.nextTick(()=>{const n=s.value.findIndex(c=>c.id===e);if(n<0||!f.value)return;const l=K.get(e)||V,o=(g.value[n]??0)-l,i=f.value.clientHeight,r=Math.max(0,o-Math.max(0,(i-l)/2));f.value.scrollTop=r,B.value=r,k(),t.nextTick(()=>{const c=P.get(e);if(!c||!f.value)return;const h=c.offsetLeft,d=c.offsetWidth,u=f.value.clientWidth,x=Math.max(0,h+Math.max(0,d/2)-Math.max(0,u/2));f.value.scrollLeft=x})}))}function Re(e){N.value=e??null,se(N.value)}return G({getCurrentKey:()=>N.value,setCurrentKey:Re,scrollTo:se,getCheckedKeys:()=>Array.from(v.value),setCheckedKeys:le,setChecked:(e,n)=>J(e,n)}),t.watch(N,e=>{const n=ee(e,a.data||[]);n&&A("current-change",n)}),(e,n)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"containerRef",ref:f,class:t.normalizeClass(["amazing-tree",{"is-dragging":S.value}]),style:t.normalizeStyle({height:typeof m.height=="number"?m.height+"px":m.height||"100%","--vtree-bg":m.backgroundColor,"--vtree-text":m.textColor,"--vtree-hover":m.hoverColor}),onScroll:ze},[ye.value?(t.openBlock(),t.createElementBlock("div",pe,[t.renderSlot(e.$slots,"empty",{},()=>[t.createElementVNode("div",ge,t.toDisplayString(m.emptyText),1)],!0)])):(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.createElementVNode("div",{style:t.normalizeStyle({height:ae.value+"px",position:"relative",minWidth:"100%",width:"max-content"})},[t.createElementVNode("div",{style:t.normalizeStyle({height:L.value+"px"})},null,4),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(s.value.slice(I.value,b.value),l=>(t.openBlock(),t.createElementBlock("div",{key:l.id,class:"amazing-tree-row-wrapper"},[t.createElementVNode("div",{class:t.normalizeClass(["amazing-tree-row",{"is-target-inner":S.value&&F.value===l.id&&T.value==="inner","is-active":N.value===l.id}]),style:t.normalizeStyle({paddingLeft:l.level*16+"px","--active-color":m.highlightColor}),onMousedown:o=>Me(l,o),onClick:o=>Ie(l,o),onContextmenu:t.withModifiers(o=>Le(l,o),["prevent"]),ref_for:!0,ref:o=>Te(l.id,o)},[t.createElementVNode("span",{class:t.normalizeClass(["amazing-tree-caret-box",{"is-leaf":l.isLeaf}]),onClick:t.withModifiers(o=>!l.isLeaf&&we(l.id),["stop"])},[l.isLeaf?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock("span",{key:0,class:t.normalizeClass(["amazing-tree-caret",{expanded:ne(l.id)}])},null,2))],10,he),m.showCheckbox?(t.openBlock(),t.createElementBlock("input",{key:0,class:"amazing-tree-checkbox",type:"checkbox",checked:Ce(l.id),indeterminate:be(l.id),disabled:a.disabledChecked?a.disabledChecked(l.node):!1,onClick:t.withModifiers(o=>Se(l,o),["stop"])},null,8,ve)):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"default",{node:l.node,data:l.node,level:l.level,expanded:ne(l.id),isLeaf:l.isLeaf},()=>[t.createElementVNode("span",me,t.toDisplayString(l.node[xe.value]),1)],!0)],46,fe),S.value&&F.value===l.id&&(T.value==="prev"||T.value==="next")?(t.openBlock(),t.createElementBlock("div",{key:0,class:t.normalizeClass(["amazing-tree-drop-line",{"is-prev":T.value==="prev","is-next":T.value==="next"}])},null,2)):t.createCommentVNode("",!0)]))),128)),t.createElementVNode("div",{style:t.normalizeStyle({height:Q.value+"px"})},null,4)],4),S.value?(t.openBlock(),t.createElementBlock("div",{key:0,class:"amazing-tree-ghost",style:t.normalizeStyle({top:Z.value+"px"})},null,4)):t.createCommentVNode("",!0)],64))],38))}}),[["__scopeId","data-v-6ef943bb"]]);z.AmazingTree=te,z.default=te,Object.defineProperties(z,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
1
+ (function(E,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(E=typeof globalThis<"u"?globalThis:E||self,t(E.AmazingTree={},E.Vue))})(this,(function(E,t){"use strict";const ge=["onMousedown","onClick","onContextmenu"],xe=["onClick"],we=["checked","indeterminate","disabled","onClick"],ke={class:"amazing-tree-label"},ye={key:1,class:"amazing-tree-empty"},Ce={class:"amazing-tree-empty-inner"},oe=((f,_)=>{const X=f.__vccOpts||f;for(const[a,N]of _)X[a]=N;return X})(t.defineComponent({__name:"AmazingTree",props:{data:{},props:{default:()=>({value:"value",label:"label",children:"children"})},allowDrag:{},allowDrop:{},height:{default:void 0},rowHeight:{default:32},dropLineColor:{default:"#ffd400"},innerDashColor:{default:"#ffd400"},siblingZoneRatio:{default:.35},dragStartThreshold:{default:4},highlightColor:{default:"#1e71ff"},backgroundColor:{default:"#1d1d24"},textColor:{default:"#c8d3de"},hoverColor:{default:"#5d90e5"},currentNodeKey:{},defaultExpandedKeys:{},defaultExpandAll:{type:Boolean,default:!1},draggable:{type:Boolean,default:!1},emptyText:{default:"暂无数据"},showCheckbox:{type:Boolean,default:!1},checkStrictly:{type:Boolean,default:!1},defaultCheckedKeys:{default:()=>[]},disabledChecked:{},filterNodeMethod:{}},emits:["node-click","node-contextmenu","node-drop","current-change","check-change"],setup(f,{expose:_,emit:X}){const a=f,N=X,be=t.computed(()=>a.props.value||"value"),Se=t.computed(()=>a.props.label||"label"),$=t.computed(()=>a.props.children||"children"),Me=t.computed(()=>Array.isArray(a.data)?a.data.length===0:!0),x=t.ref(new Set),p=t.ref(new Set),w=t.ref(new Set),ee=t.ref(null);function re(e){return x.value.has(e)}function Te(e){x.value.has(e)?x.value.delete(e):x.value.add(e),s.value=C(a.data||[]),t.nextTick(()=>{T(),g()})}function k(e){return e[be.value]}function S(e){const n=e[$.value];return Array.isArray(n)?n:[]}function ze(e){return p.value.has(e)}function Ee(e){return w.value.has(e)}function te(e,n){if(n?p.value.add(e):p.value.delete(e),w.value.delete(e),!a.checkStrictly){const l=ae(e,a.data||[]);if(l){const o=[l];for(;o.length;){const c=o.pop(),r=k(c);n?p.value.add(r):p.value.delete(r),w.value.delete(r);const h=S(c);for(const d of h)o.push(d)}const i=G(e,a.data||[])||[];for(const c of i){const r=k(c),h=S(c);let d=!0,u=!1;for(const m of h){const z=k(m),U=p.value.has(z),J=w.value.has(z);(U||J)&&(u=!0),(!U||J)&&(d=!1)}h.length===0?(p.value.has(r),w.value.delete(r)):d?(p.value.add(r),w.value.delete(r)):u?(p.value.delete(r),w.value.add(r)):(p.value.delete(r),w.value.delete(r))}}}}function ie(e){p.value=new Set,w.value=new Set;for(const n of e||[])te(n,!0)}function Be(e,n){const l=n.target;a.disabledChecked&&a.disabledChecked(e.node)||(N("check-change",e.node,!!l.checked),te(e.id,!!l.checked))}function C(e){const n=[];function l(o,i,c){for(let r=0;r<o.length;r++){const h=o[r],d=k(h),u=S(h),m=u.length===0;n.push({id:d,node:h,parent:i,level:c,index:r,isLeaf:m}),!m&&x.value.has(d)&&l(u,h,c+1)}}if(l(e,null,0),a.filterNodeMethod&&ee.value!=null){let o=function(r){const h=k(r),d=S(r);let u=!1;for(const z of d)u=o(z)||u;const m=!!a.filterNodeMethod(ee.value,r);return m&&i.add(h),u&&c.add(h),m||u};const i=new Set,c=new Set;for(const r of e)o(r);return n.filter(r=>i.has(r.id)||c.has(r.id))}return n}const v=t.ref(null),B=t.ref(0),V=t.ref(0),s=t.ref([]),H=t.reactive(new Map);function Ae(e){if(typeof e=="number")return e;if(typeof e=="string"){const n=e.match(/(\d+(\.\d+)?)/);return n?Number(n[1]):32}return 32}const Y=Ae(a.rowHeight),y=t.computed(()=>{let e=0;const n=[];for(const l of s.value){const o=H.get(l.id)||Y;e+=o,n.push(e)}return n}),ce=t.computed(()=>{const e=y.value;return e.length?e[e.length-1]:0});function se(e){let n=0,l=y.value.length-1,o=0;for(;n<=l;){const i=n+l>>1;y.value[i]!==void 0&&y.value[i]>=e?(o=i,l=i-1):n=i+1}return o}const R=t.ref(0),M=t.ref(0),L=t.ref(0),ne=t.ref(0);function g(){if(V.value=v.value?.clientHeight||0,y.value.length===0||s.value.length===0){R.value=0,M.value=0,L.value=0,ne.value=0;return}const e=se(B.value);R.value=Math.max(0,e-3);const n=s.value[R.value],l=n?H.get(n.id)||Y:0,i=(y.value[R.value]??0)-l;L.value=Math.max(0,i);let c=R.value;const r=B.value+V.value+3*Y;for(;c<s.value.length&&(y.value[c]??0)<r;)c++;M.value=Math.min(s.value.length,c+1);const d=(y.value[M.value-1]??0)-L.value;if(d<V.value&&M.value<s.value.length){let u=M.value,m=d;for(;m<V.value&&u<s.value.length;)u++,m=(y.value[u-1]??0)-L.value;M.value=u}ne.value=Math.max(0,ce.value-L.value-((y.value[M.value-1]??0)-L.value))}t.watch([B,()=>a.data,x],()=>{s.value=C(a.data||[]),t.nextTick(T),g()}),t.onMounted(()=>{s.value=C(a.data||[]),t.nextTick(T),g(),a.defaultCheckedKeys&&a.defaultCheckedKeys.length&&ie(a.defaultCheckedKeys),v.value&&(F=new ResizeObserver(()=>{V.value=v.value?.clientHeight||0,g()}),F.observe(v.value))});let F=null;t.onUnmounted(()=>{F&&(F.disconnect(),F=null)});const j=t.reactive(new Map);function Ke(e,n){n?j.set(e,n):j.delete(e)}function T(){let e=!1;for(const n of s.value.slice(R.value,M.value)){const l=j.get(n.id);if(l){const o=l.offsetHeight;(!H.has(n.id)||H.get(n.id)!==o)&&(H.set(n.id,o),e=!0)}}e&&g()}function Ne(){B.value=v.value?.scrollTop||0,g()}const A=t.ref(!1),O=t.ref(null),I=t.ref(null),b=t.ref(null),le=t.ref(0),P=t.ref(!1),de=t.ref(0),ue=t.ref(0),K=t.ref(null),W=t.ref(0);let D=null;function Z(){D!=null&&(cancelAnimationFrame(D),D=null)}function fe(){if(!A.value||W.value===0){Z();return}const e=v.value;if(!e){Z();return}const n=e.scrollHeight-e.clientHeight,l=12;e.scrollTop=Math.max(0,Math.min(n,e.scrollTop+W.value*l)),B.value=e.scrollTop,g(),D=requestAnimationFrame(fe)}function He(){W.value!==0&&D==null&&(D=requestAnimationFrame(fe)),W.value===0&&Z()}function Q(e){if(e==null)return null;for(const n of s.value)if(n.id===e)return n;return null}function Re(e){const n=v.value.getBoundingClientRect(),l=e-n.top+B.value;return se(l)}function Le(e,n){!a.draggable||n.button!==0||!(!a.allowDrag||a.allowDrag(e.node))||(O.value=e.id,le.value=n.clientY,de.value=n.clientX,ue.value=n.clientY,P.value=!1,n.preventDefault(),window.addEventListener("mousemove",he),window.addEventListener("mouseup",ve))}function he(e){if(O.value==null)return;if(!P.value){const Pe=Math.abs(e.clientX-de.value),We=Math.abs(e.clientY-ue.value),pe=Math.max(1,a.dragStartThreshold??4);if(Pe<pe&&We<pe)return;P.value=!0,A.value=!0}le.value=e.clientY;const n=Re(e.clientY),l=s.value[Math.min(Math.max(n,0),s.value.length-1)];if(I.value=l?.id??null,!l){b.value=null;return}const o=y.value[n]??0,i=H.get(l.id)??Y,c=o-i,r=v.value.getBoundingClientRect(),d=(e.clientY-r.top+B.value-c)/i,u=a.siblingZoneRatio??.35,m=Math.max(.05,Math.min(.49,u));let z="inner";d<m?z="prev":d>1-m&&(z="next");const U=Q(O.value),J=a.allowDrop?!!(U&&a.allowDrop(U.node,l.node,z)):!0;b.value=J?z:null,W.value=e.clientY>r.bottom?1:e.clientY<r.top?-1:0,He()}function G(e,n,l=[]){for(const o of n){if(k(o)===e)return l;const i=S(o);if(i.length){const c=G(e,i,[...l,o]);if(c)return c}}return null}function ae(e,n){if(e==null)return null;for(const l of n){if(k(l)===e)return l;const o=S(l),i=ae(e,o);if(i)return i}return null}function q(e){const n=[];for(const l of e){n.push(k(l));const o=S(l);o.length&&n.push(...q(o))}return n}function Ie(e){const n=e.parent;if(n)S(n).splice(e.index,1);else{const l=a.data.findIndex(o=>k(o)===e.id);l>=0&&a.data.splice(l,1)}}function De(e,n,l){if(l==="inner"){Array.isArray(n.node[$.value])||(n.node[$.value]=[]),n.node[$.value].push(e),x.value.add(n.id);return}const o=n.parent;if(o){const i=S(o),c=n.index+(l==="next"?1:0);i.splice(c,0,e)}else{const i=n.index+(l==="next"?1:0);a.data.splice(i,0,e)}}function ve(){if(window.removeEventListener("mousemove",he),window.removeEventListener("mouseup",ve),Z(),!A.value){O.value=null,b.value=null,I.value=null,P.value=!1;return}const e=Q(O.value),n=Q(I.value),l=b.value;if(A.value=!1,P.value=!1,b.value=null,I.value=null,!e||!n||!l||a.allowDrop&&!a.allowDrop(e.node,n.node,l)||e.id===n.id)return;const o=l==="inner"?n.node:n.parent||null;if(o){const h=G(k(o),a.data||[])||[];for(const d of h)if(k(d)===e.id)return}const i=e.node;Ie(e);const c=C(a.data||[]);s.value=c;const r=Q(n.id)||n;De(i,r,l),s.value=C(a.data||[]),t.nextTick(()=>{T(),g()}),N("node-drop",i,r.node,l)}function Ve(e,n){K.value=e.id,N("node-click",e.node,n)}function Ye(e,n){K.value=e.id,N("node-contextmenu",e.node,n)}t.watchEffect(()=>{t.nextTick(T)}),t.watch(()=>a.currentNodeKey,e=>{K.value=e??null},{immediate:!0}),t.watch(()=>a.defaultExpandedKeys,e=>{x.value=new Set(e||[]),s.value=C(a.data||[]),t.nextTick(()=>{T(),g()})},{immediate:!0}),t.watch(()=>a.defaultExpandAll,e=>{e&&(x.value=new Set(q(a.data||[])),s.value=C(a.data||[]),t.nextTick(()=>{T(),g()}))},{immediate:!0}),t.watch(()=>a.data,()=>{a.defaultExpandAll&&(x.value=new Set(q(a.data||[]))),s.value=C(a.data||[]),t.nextTick(()=>{T(),g()});const e=new Set(q(a.data||[]));p.value=new Set([...p.value].filter(n=>e.has(n))),w.value=new Set([...w.value].filter(n=>e.has(n)))},{deep:!0});function Fe(e){const n=G(e,a.data||[])||[];for(const l of n)x.value.add(k(l));s.value=C(a.data||[])}function me(e){e!=null&&(Fe(e),t.nextTick(()=>{const n=s.value.findIndex(r=>r.id===e);if(n<0||!v.value)return;const l=H.get(e)||Y,o=(y.value[n]??0)-l,i=v.value.clientHeight,c=Math.max(0,o-Math.max(0,(i-l)/2));v.value.scrollTop=c,B.value=c,g(),t.nextTick(()=>{const r=j.get(e);if(!r||!v.value)return;const h=r.offsetLeft,d=r.offsetWidth,u=v.value.clientWidth,m=Math.max(0,h+Math.max(0,d/2)-Math.max(0,u/2));v.value.scrollLeft=m})}))}function Oe(e){K.value=e??null,me(K.value)}return _({getCurrentKey:()=>K.value,setCurrentKey:Oe,scrollTo:me,getCheckedKeys:()=>Array.from(p.value),setCheckedKeys:ie,setChecked:(e,n)=>te(e,n),filter:e=>{ee.value=e,x.value=new Set(q(a.data||[])),s.value=C(a.data||[]),t.nextTick(()=>{T(),g()})}}),t.watch(K,e=>{const n=ae(e,a.data||[]);n&&N("current-change",n)}),(e,n)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"containerRef",ref:v,class:t.normalizeClass(["amazing-tree",{"is-dragging":A.value}]),style:t.normalizeStyle({height:typeof f.height=="number"?f.height+"px":f.height||"100%","--vtree-bg":f.backgroundColor,"--vtree-text":f.textColor,"--vtree-hover":f.hoverColor,"--vtree-row-height":typeof f.rowHeight=="number"?f.rowHeight+"px":f.rowHeight||"32px","--vtree-drop-line":f.dropLineColor,"--vtree-drop-inner":f.innerDashColor}),onScroll:Ne},[Me.value?(t.openBlock(),t.createElementBlock("div",ye,[t.renderSlot(e.$slots,"empty",{},()=>[t.createElementVNode("div",Ce,t.toDisplayString(f.emptyText),1)],!0)])):(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[t.createElementVNode("div",{style:t.normalizeStyle({height:ce.value+"px",position:"relative",minWidth:"100%",width:"max-content"})},[t.createElementVNode("div",{style:t.normalizeStyle({height:L.value+"px"})},null,4),(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(s.value.slice(R.value,M.value),l=>(t.openBlock(),t.createElementBlock("div",{key:l.id,class:"amazing-tree-row-wrapper"},[t.createElementVNode("div",{class:t.normalizeClass(["amazing-tree-row",{"is-target-inner":A.value&&I.value===l.id&&b.value==="inner","is-active":K.value===l.id}]),style:t.normalizeStyle({paddingLeft:l.level*16+"px","--active-color":f.highlightColor}),onMousedown:o=>Le(l,o),onClick:o=>Ve(l,o),onContextmenu:t.withModifiers(o=>Ye(l,o),["prevent"]),ref_for:!0,ref:o=>Ke(l.id,o)},[t.createElementVNode("span",{class:t.normalizeClass(["amazing-tree-caret-box",{"is-leaf":l.isLeaf}]),onMousedown:n[0]||(n[0]=t.withModifiers(()=>{},["stop"])),onClick:t.withModifiers(o=>!l.isLeaf&&Te(l.id),["stop"])},[l.isLeaf?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock("span",{key:0,class:t.normalizeClass(["amazing-tree-caret",{expanded:re(l.id)}])},null,2))],42,xe),f.showCheckbox?(t.openBlock(),t.createElementBlock("input",{key:0,class:"amazing-tree-checkbox",type:"checkbox",checked:ze(l.id),onMousedown:n[1]||(n[1]=t.withModifiers(()=>{},["stop"])),indeterminate:Ee(l.id),disabled:a.disabledChecked?a.disabledChecked(l.node):!1,onClick:t.withModifiers(o=>Be(l,o),["stop"])},null,40,we)):t.createCommentVNode("",!0),t.renderSlot(e.$slots,"default",{node:l.node,data:l.node,level:l.level,expanded:re(l.id),isLeaf:l.isLeaf},()=>[t.createElementVNode("span",ke,t.toDisplayString(l.node[Se.value]),1)],!0)],46,ge),A.value&&I.value===l.id&&(b.value==="prev"||b.value==="next")?(t.openBlock(),t.createElementBlock("div",{key:0,class:t.normalizeClass(["amazing-tree-drop-line",{"is-prev":b.value==="prev","is-next":b.value==="next"}])},null,2)):t.createCommentVNode("",!0)]))),128)),t.createElementVNode("div",{style:t.normalizeStyle({height:ne.value+"px"})},null,4)],4),A.value?(t.openBlock(),t.createElementBlock("div",{key:0,class:"amazing-tree-ghost",style:t.normalizeStyle({top:le.value+"px"})},null,4)):t.createCommentVNode("",!0)],64))],38))}}),[["__scopeId","data-v-fc218005"]]);E.AmazingTree=oe,E.default=oe,Object.defineProperties(E,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amazing-tree",
3
- "version": "1.2.4",
3
+ "version": "1.3.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "engines": {
@@ -54,6 +54,6 @@
54
54
  "sideEffects": [
55
55
  "dist/*.css"
56
56
  ],
57
- "author": "maxkang",
57
+ "author": "Maxkang",
58
58
  "style": "./dist/amazing-tree.css"
59
59
  }