@movk/nuxt 1.4.0 → 1.4.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/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/components/Tree.vue +57 -14
- package/dist/runtime/domains/tree/components/TreeToolbar.d.vue.ts +2 -0
- package/dist/runtime/domains/tree/components/TreeToolbar.vue +5 -0
- package/dist/runtime/domains/tree/components/TreeToolbar.vue.d.ts +2 -0
- package/dist/runtime/domains/tree/resolve-tree.d.ts +4 -5
- package/dist/runtime/domains/tree/resolve-tree.js +2 -1
- package/dist/runtime/domains/tree/tree-disabled.d.ts +3 -0
- package/dist/runtime/domains/tree/tree-disabled.js +12 -0
- package/dist/runtime/domains/tree/tree-icon.d.ts +3 -0
- package/dist/runtime/domains/tree/tree-icon.js +5 -0
- package/dist/runtime/domains/tree/tree-lazy.d.ts +3 -4
- package/dist/runtime/domains/tree/tree-search.d.ts +3 -0
- package/dist/runtime/domains/tree/tree-search.js +4 -0
- package/dist/runtime/types/components/tree.d.ts +13 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed, ref, useSlots, watch } from "vue";
|
|
3
3
|
import { reactiveOmit } from "@vueuse/core";
|
|
4
|
-
import { Tree, omitUndefined, splitHighlight } from "@movk/core";
|
|
4
|
+
import { Tree, omitUndefined, splitHighlight, getPath } from "@movk/core";
|
|
5
5
|
import { UCheckbox, UIcon, UTree } from "#components";
|
|
6
6
|
import { useAppConfig } from "#imports";
|
|
7
7
|
import { useExtendedTv } from "../utils/extend-theme";
|
|
8
8
|
import treeTheme from "#build/ui/tree";
|
|
9
9
|
import theme from "#build/movk-ui/tree";
|
|
10
10
|
import { createGetKey, normalizeChildren } from "../domains/tree/resolve-tree";
|
|
11
|
-
import {
|
|
11
|
+
import { resolveLeadingIcon } from "../domains/tree/tree-icon";
|
|
12
|
+
import { matchNode } from "../domains/tree/tree-search";
|
|
12
13
|
import { isPlaceholder, LAZY_KEY_FIELD, markLazyPlaceholders } from "../domains/tree/tree-lazy";
|
|
14
|
+
import { collectDisabledKeys } from "../domains/tree/tree-disabled";
|
|
13
15
|
import { computeTreeSelection, selectionSummary } from "../utils/tree-selection";
|
|
14
16
|
import { resolveDefaultExpandedKeys } from "../utils/tree-expand";
|
|
15
17
|
import TreeToolbar from "../domains/tree/components/TreeToolbar.vue";
|
|
@@ -26,6 +28,9 @@ const props = defineProps({
|
|
|
26
28
|
bubbleSelect: { type: Boolean, required: false },
|
|
27
29
|
size: { type: null, required: false },
|
|
28
30
|
color: { type: null, required: false },
|
|
31
|
+
expandedIcon: { type: null, required: false },
|
|
32
|
+
collapsedIcon: { type: null, required: false },
|
|
33
|
+
disabled: { type: Boolean, required: false },
|
|
29
34
|
searchable: { type: Boolean, required: false },
|
|
30
35
|
filter: { type: Function, required: false },
|
|
31
36
|
highlight: { type: Boolean, required: false, default: true },
|
|
@@ -45,6 +50,12 @@ const expanded = defineModel("expanded", { type: Array, ...{ default: () => [] }
|
|
|
45
50
|
const slots = useSlots();
|
|
46
51
|
const appConfig = useAppConfig();
|
|
47
52
|
const labelKey = computed(() => props.labelKey ?? "label");
|
|
53
|
+
function folderIcon(expanded2) {
|
|
54
|
+
return expanded2 ? props.expandedIcon ?? appConfig.ui?.icons?.folderOpen ?? "i-lucide-folder-open" : props.collapsedIcon ?? appConfig.ui?.icons?.folder ?? "i-lucide-folder";
|
|
55
|
+
}
|
|
56
|
+
function leadingIcon(node, expanded2) {
|
|
57
|
+
return resolveLeadingIcon(node, folderIcon(expanded2));
|
|
58
|
+
}
|
|
48
59
|
const getKey = computed(() => createGetKey(props.getKey, labelKey.value));
|
|
49
60
|
const { baseUi, extraUi } = useExtendedTv(
|
|
50
61
|
treeTheme,
|
|
@@ -74,13 +85,26 @@ watch(() => props.items, (items) => {
|
|
|
74
85
|
}
|
|
75
86
|
}, { immediate: true });
|
|
76
87
|
const searching = computed(() => !!(props.searchable && search.value.trim()));
|
|
88
|
+
const disabledKeys = computed(() => collectDisabledKeys(baseItems.value, getKey.value));
|
|
89
|
+
function applyDisabled(nodes) {
|
|
90
|
+
if (!disabledKeys.value.size) return nodes;
|
|
91
|
+
const inject = (list) => list.map((node) => {
|
|
92
|
+
const rawChildren = node.children;
|
|
93
|
+
const children = Array.isArray(rawChildren) ? inject(rawChildren) : rawChildren;
|
|
94
|
+
const disabled = disabledKeys.value.has(getKey.value(node));
|
|
95
|
+
if (!disabled && children === rawChildren) return node;
|
|
96
|
+
return {
|
|
97
|
+
...node,
|
|
98
|
+
...disabled ? { disabled: true } : null,
|
|
99
|
+
...children !== rawChildren ? { children } : null
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
return inject(nodes);
|
|
103
|
+
}
|
|
77
104
|
const displayItems = computed(() => {
|
|
78
|
-
if (!searching.value) return baseItems.value;
|
|
79
105
|
const term = search.value;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
({ node }) => props.filter ? props.filter(node, term) : matchLabel(node[labelKey.value], term)
|
|
83
|
-
);
|
|
106
|
+
const filtered = !searching.value ? baseItems.value : Tree.filter(baseItems.value, ({ node }) => props.filter ? props.filter(node, term) : matchNode(node, labelKey.value, term));
|
|
107
|
+
return applyDisabled(filtered);
|
|
84
108
|
});
|
|
85
109
|
const isEmpty = computed(() => searching.value && displayItems.value.length === 0);
|
|
86
110
|
watch([searching, displayItems], () => {
|
|
@@ -89,8 +113,10 @@ watch([searching, displayItems], () => {
|
|
|
89
113
|
}
|
|
90
114
|
});
|
|
91
115
|
const loadingKeys = ref(/* @__PURE__ */ new Set());
|
|
92
|
-
async function onExpandedUpdate(
|
|
116
|
+
async function onExpandedUpdate(incoming) {
|
|
117
|
+
if (props.disabled) return;
|
|
93
118
|
const previous = expanded.value;
|
|
119
|
+
const keys = disabledKeys.value.size ? [...incoming.filter((k) => !disabledKeys.value.has(k)), ...previous.filter((k) => disabledKeys.value.has(k))] : incoming;
|
|
94
120
|
expanded.value = keys;
|
|
95
121
|
if (!props.lazy || !props.loadChildren) return;
|
|
96
122
|
for (const key of keys.filter((k) => !previous.includes(k))) {
|
|
@@ -150,12 +176,12 @@ const utreeProps = computed(() => {
|
|
|
150
176
|
const RESERVED_SLOTS = ["toolbar", "toolbar-leading", "toolbar-trailing", "empty", "loading"];
|
|
151
177
|
const forwardSlots = computed(() => Object.keys(slots).filter((name) => !RESERVED_SLOTS.includes(name)));
|
|
152
178
|
function nodeLabel(node) {
|
|
153
|
-
const value = node
|
|
179
|
+
const value = getPath(node, labelKey.value);
|
|
154
180
|
return value == null ? "" : String(value);
|
|
155
181
|
}
|
|
156
182
|
const isMultiple = computed(() => !!(props.checkable || props.multiple));
|
|
157
183
|
const selectableNodes = computed(
|
|
158
|
-
() => Tree.findAll(baseItems.value, ({ node }) => !isPlaceholder(node) && !node
|
|
184
|
+
() => Tree.findAll(baseItems.value, ({ node }) => !isPlaceholder(node) && !disabledKeys.value.has(getKey.value(node)))
|
|
159
185
|
);
|
|
160
186
|
const nodesByKey = computed(() => {
|
|
161
187
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -184,7 +210,7 @@ const treeSelection = computed(
|
|
|
184
210
|
})
|
|
185
211
|
);
|
|
186
212
|
const selectableLeafCount = computed(
|
|
187
|
-
() => Tree.findAll(baseItems.value, ({ node }) => !isPlaceholder(node) && !node
|
|
213
|
+
() => Tree.findAll(baseItems.value, ({ node }) => !isPlaceholder(node) && !disabledKeys.value.has(getKey.value(node)) && !(Array.isArray(node.children) && node.children.length > 0)).length
|
|
188
214
|
);
|
|
189
215
|
const selectionSummaryValue = computed(
|
|
190
216
|
() => selectionSummary(treeSelection.value.leaves.length, selectableLeafCount.value)
|
|
@@ -199,6 +225,15 @@ function setModel(value) {
|
|
|
199
225
|
});
|
|
200
226
|
emit("change", { value, keys, selection });
|
|
201
227
|
}
|
|
228
|
+
function onModelUpdate(value) {
|
|
229
|
+
if (props.disabled) return;
|
|
230
|
+
if (Array.isArray(value)) {
|
|
231
|
+
setModel(value.filter((node) => !node.disabled));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (value && value.disabled) return;
|
|
235
|
+
setModel(value);
|
|
236
|
+
}
|
|
202
237
|
const expandableKeys = computed(
|
|
203
238
|
() => Tree.findAll(baseItems.value, ({ node }) => !!node.children?.length).map((n) => getKey.value(n))
|
|
204
239
|
);
|
|
@@ -251,6 +286,7 @@ defineExpose({
|
|
|
251
286
|
:select-all="selectAll"
|
|
252
287
|
:clear="clearSelection"
|
|
253
288
|
:search="search"
|
|
289
|
+
:disabled="props.disabled"
|
|
254
290
|
:selection-summary="selectionSummaryValue"
|
|
255
291
|
>
|
|
256
292
|
<TreeToolbar
|
|
@@ -260,6 +296,7 @@ defineExpose({
|
|
|
260
296
|
:search="search"
|
|
261
297
|
:size="props.size"
|
|
262
298
|
:color="props.color"
|
|
299
|
+
:disabled="props.disabled"
|
|
263
300
|
:expanded="allExpanded"
|
|
264
301
|
:selection-summary="selectionSummaryValue"
|
|
265
302
|
:ui="{ toolbar: extraUi.toolbar, toolbarButton: extraUi.toolbarButton, search: extraUi.search }"
|
|
@@ -290,27 +327,33 @@ defineExpose({
|
|
|
290
327
|
:model-value="effectiveModel"
|
|
291
328
|
:expanded="expanded"
|
|
292
329
|
:ui="baseUi"
|
|
293
|
-
@update:model-value="
|
|
330
|
+
@update:model-value="onModelUpdate($event)"
|
|
294
331
|
@update:expanded="onExpandedUpdate"
|
|
295
332
|
>
|
|
296
333
|
<template v-for="name in forwardSlots" #[name]="slotProps" :key="name">
|
|
297
334
|
<slot :name="name" v-bind="slotProps ?? {}" />
|
|
298
335
|
</template>
|
|
299
336
|
|
|
300
|
-
<template v-if="props.checkable && !slots['item-leading']" #item-leading="{ item, selected, indeterminate, handleSelect }">
|
|
337
|
+
<template v-if="props.checkable && !slots['item-leading']" #item-leading="{ item, expanded: nodeExpanded, selected, indeterminate, handleSelect, ui: nodeUi }">
|
|
301
338
|
<UCheckbox
|
|
302
339
|
v-if="!isPlaceholder(item)"
|
|
303
340
|
:model-value="indeterminate ? 'indeterminate' : selected"
|
|
304
341
|
:size="props.size"
|
|
305
342
|
:color="props.color"
|
|
343
|
+
:disabled="item.disabled || props.disabled"
|
|
306
344
|
:class="extraUi.checkbox"
|
|
307
345
|
tabindex="-1"
|
|
308
346
|
@change="handleSelect"
|
|
309
347
|
@click.stop
|
|
310
348
|
/>
|
|
349
|
+
<UIcon
|
|
350
|
+
v-if="leadingIcon(item, nodeExpanded)"
|
|
351
|
+
:name="leadingIcon(item, nodeExpanded)"
|
|
352
|
+
:class="nodeUi.linkLeadingIcon({ class: item.ui?.linkLeadingIcon })"
|
|
353
|
+
/>
|
|
311
354
|
</template>
|
|
312
355
|
|
|
313
|
-
<template v-if="!slots['item-label']" #item-label="{ item }">
|
|
356
|
+
<template v-if="!slots['item-label'] && (props.lazy || searching && props.highlight)" #item-label="{ item }">
|
|
314
357
|
<slot v-if="isPlaceholder(item)" name="loading" :node="item">
|
|
315
358
|
<span :class="extraUi.loading">
|
|
316
359
|
<UIcon name="i-lucide-loader-circle" :class="extraUi.loadingIcon" />加载中
|
|
@@ -9,6 +9,7 @@ const props = defineProps({
|
|
|
9
9
|
size: { type: null, required: false },
|
|
10
10
|
color: { type: null, required: false },
|
|
11
11
|
expanded: { type: Boolean, required: false },
|
|
12
|
+
disabled: { type: Boolean, required: false },
|
|
12
13
|
selectionSummary: { type: Object, required: false },
|
|
13
14
|
ui: { type: Object, required: true }
|
|
14
15
|
});
|
|
@@ -34,6 +35,7 @@ function onToggleAll(checked) {
|
|
|
34
35
|
icon="i-lucide-search"
|
|
35
36
|
placeholder="搜索节点"
|
|
36
37
|
:size="size"
|
|
38
|
+
:disabled="disabled"
|
|
37
39
|
:class="ui.search"
|
|
38
40
|
@update:model-value="emit('update:search', String($event))"
|
|
39
41
|
>
|
|
@@ -43,6 +45,7 @@ function onToggleAll(checked) {
|
|
|
43
45
|
color="neutral"
|
|
44
46
|
variant="link"
|
|
45
47
|
:size="size"
|
|
48
|
+
:disabled="disabled"
|
|
46
49
|
aria-label="清除搜索"
|
|
47
50
|
@click="emit('update:search', '')"
|
|
48
51
|
/>
|
|
@@ -55,6 +58,7 @@ function onToggleAll(checked) {
|
|
|
55
58
|
color="neutral"
|
|
56
59
|
variant="ghost"
|
|
57
60
|
:size="size"
|
|
61
|
+
:disabled="disabled"
|
|
58
62
|
:class="ui.toolbarButton"
|
|
59
63
|
:aria-label="expandTooltip"
|
|
60
64
|
@click="emit('toggle-expand')"
|
|
@@ -67,6 +71,7 @@ function onToggleAll(checked) {
|
|
|
67
71
|
:indeterminate="selectionSummary?.indeterminate ?? false"
|
|
68
72
|
:size="size"
|
|
69
73
|
:color="color"
|
|
74
|
+
:disabled="disabled"
|
|
70
75
|
:label="checkboxLabel"
|
|
71
76
|
@update:model-value="onToggleAll(Boolean($event))"
|
|
72
77
|
/>
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
type
|
|
1
|
+
import type { AnyObject } from '@movk/core';
|
|
2
2
|
/**
|
|
3
3
|
* 构造与 UTree 一致的取键函数
|
|
4
4
|
*
|
|
5
|
-
* 复刻 UTree:提供 getKey 时取其返回值(为空则回退 label
|
|
5
|
+
* 复刻 UTree:提供 getKey 时取其返回值(为空则回退 label),否则按 labelKey 取值(支持点路径,与 UTree 内部 get 一致)。
|
|
6
6
|
*/
|
|
7
|
-
export declare function createGetKey<T extends
|
|
7
|
+
export declare function createGetKey<T extends AnyObject>(getKey?: (node: T) => string, labelKey?: string): (node: T) => string;
|
|
8
8
|
/**
|
|
9
9
|
* 将自定义 childrenKey 归一化为 UTree 的 children 字段(UTree 写死 children)
|
|
10
10
|
*
|
|
11
11
|
* childrenKey 为默认 children 时原样返回(零拷贝);否则深拷贝重命名并移除原字段,不修改入参。
|
|
12
12
|
*/
|
|
13
|
-
export declare function normalizeChildren<T extends
|
|
14
|
-
export {};
|
|
13
|
+
export declare function normalizeChildren<T extends AnyObject>(items: T[], childrenKey?: string): T[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { getPath } from "@movk/core";
|
|
1
2
|
export function createGetKey(getKey, labelKey = "label") {
|
|
2
3
|
return (node) => {
|
|
3
|
-
const label = node
|
|
4
|
+
const label = getPath(node, labelKey);
|
|
4
5
|
const key = getKey ? getKey(node) || label : label;
|
|
5
6
|
return String(key);
|
|
6
7
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function collectDisabledKeys(items, getKey) {
|
|
2
|
+
const set = /* @__PURE__ */ new Set();
|
|
3
|
+
const walk = (nodes, ancestorDisabled) => {
|
|
4
|
+
for (const node of nodes) {
|
|
5
|
+
const disabled = ancestorDisabled || !!node.disabled;
|
|
6
|
+
if (disabled) set.add(getKey(node));
|
|
7
|
+
if (Array.isArray(node.children)) walk(node.children, disabled);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
walk(items, false);
|
|
11
|
+
return set;
|
|
12
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type
|
|
1
|
+
import type { AnyObject } from '@movk/core';
|
|
2
2
|
/** 懒加载占位节点标记字段 */
|
|
3
3
|
export declare const PLACEHOLDER_FLAG = "__movkLazyPlaceholder";
|
|
4
4
|
/**
|
|
@@ -9,12 +9,11 @@ export declare const PLACEHOLDER_FLAG = "__movkLazyPlaceholder";
|
|
|
9
9
|
*/
|
|
10
10
|
export declare const LAZY_KEY_FIELD = "__movkKey";
|
|
11
11
|
/** 判断节点是否为懒加载占位 */
|
|
12
|
-
export declare function isPlaceholder(node:
|
|
12
|
+
export declare function isPlaceholder(node: AnyObject): boolean;
|
|
13
13
|
/**
|
|
14
14
|
* 为懒加载父节点注入占位子节点
|
|
15
15
|
*
|
|
16
16
|
* UTree 仅在 `children.length` 为真时渲染展开箭头;对 `children` 未加载(缺省)且非叶子的节点,
|
|
17
17
|
* 注入一个占位子节点使其可展开。展开时再由 `Tree.updateNode` 用真实子节点替换。不修改入参。
|
|
18
18
|
*/
|
|
19
|
-
export declare function markLazyPlaceholders<T extends
|
|
20
|
-
export {};
|
|
19
|
+
export declare function markLazyPlaceholders<T extends AnyObject>(items: T[], getKey: (node: T) => string, labelKey?: string): T[];
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import type { AnyObject } from '@movk/core';
|
|
1
2
|
/**
|
|
2
3
|
* 默认搜索谓词:不区分大小写的文本包含匹配,空关键字视为全部命中
|
|
3
4
|
*
|
|
4
5
|
* 作为 `Tree.filter` 的默认匹配函数;高亮切分由 `@movk/core` 的 `splitHighlight` 承担。
|
|
5
6
|
*/
|
|
6
7
|
export declare function matchLabel(label: unknown, term: string): boolean;
|
|
8
|
+
/** 按 labelKey 取节点文本(点路径,与 nodeLabel / createGetKey 一致)后做默认匹配 */
|
|
9
|
+
export declare function matchNode(node: AnyObject, labelKey: string, term: string): boolean;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { getPath } from "@movk/core";
|
|
1
2
|
export function matchLabel(label, term) {
|
|
2
3
|
if (!term.trim()) return true;
|
|
3
4
|
if (label == null) return false;
|
|
4
5
|
return String(label).toLowerCase().includes(term.toLowerCase());
|
|
5
6
|
}
|
|
7
|
+
export function matchNode(node, labelKey, term) {
|
|
8
|
+
return matchLabel(getPath(node, labelKey), term);
|
|
9
|
+
}
|
|
@@ -54,6 +54,18 @@ export interface TreeProps<T extends TreeItem[] = TreeItem[], M extends boolean
|
|
|
54
54
|
size?: NuxtTreeProps<T, M>['size'];
|
|
55
55
|
/** 主色 */
|
|
56
56
|
color?: NuxtTreeProps<T, M>['color'];
|
|
57
|
+
/**
|
|
58
|
+
* 父节点展开时的图标
|
|
59
|
+
* @defaultValue 取 app.config 的 ui.icons.folderOpen
|
|
60
|
+
*/
|
|
61
|
+
expandedIcon?: NuxtTreeProps<T, M>['expandedIcon'];
|
|
62
|
+
/**
|
|
63
|
+
* 父节点折叠时的图标
|
|
64
|
+
* @defaultValue 取 app.config 的 ui.icons.folder
|
|
65
|
+
*/
|
|
66
|
+
collapsedIcon?: NuxtTreeProps<T, M>['collapsedIcon'];
|
|
67
|
+
/** 禁用整棵树,阻断点击、工具栏与复选框的展开、折叠、选中 */
|
|
68
|
+
disabled?: NuxtTreeProps<T, M>['disabled'];
|
|
57
69
|
/** 开启顶部搜索过滤 */
|
|
58
70
|
searchable?: boolean;
|
|
59
71
|
/** 自定义匹配谓词,缺省按 labelKey 文本不区分大小写包含匹配 */
|
|
@@ -120,6 +132,7 @@ interface TreeExtraSlots<T extends TreeItem[] = TreeItem[]> {
|
|
|
120
132
|
selectAll: () => void;
|
|
121
133
|
clear: () => void;
|
|
122
134
|
search: string;
|
|
135
|
+
disabled?: boolean;
|
|
123
136
|
selectionSummary: TreeSelectionSummary;
|
|
124
137
|
}): VNode[];
|
|
125
138
|
/** 默认工具栏起始处追加内容 */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@movk/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.1",
|
|
5
5
|
"packageManager": "pnpm@11.8.0",
|
|
6
6
|
"description": "An engineering suite built on Nuxt UI: schema-driven AutoForm (Zod v4), a full-featured DataTable, standalone UI components and composables. Get the full capabilities — including API integration with auth & progress — in Nuxt 4, and use its UI, forms, tables and theming in plain Vue + Vite via the Vite plugin.",
|
|
7
7
|
"author": "YiXuan <mhaibaraai@gmail.com>",
|