@quirekit/ui 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat.d.mts +1 -1
- package/dist/{index-BaILPMtg.d.mts → index-BIsMxp8p.d.mts} +13 -13
- package/dist/{index-BaILPMtg.d.mts.map → index-BIsMxp8p.d.mts.map} +1 -1
- package/dist/vue.d.mts +112 -110
- package/dist/vue.d.mts.map +1 -1
- package/dist/vue.mjs +23 -1
- package/dist/vue.mjs.map +1 -1
- package/package.json +2 -2
- package/src/vue/tree-view/tree-view.test.ts +48 -0
- package/src/vue/tree-view/tree-view.vue +29 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quirekit/ui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Wang Yishuai (王一帅)"
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"@internationalized/date": "3.12.3",
|
|
74
74
|
"@tanstack/vue-table": "8.21.3",
|
|
75
75
|
"vee-validate": "4.15.1",
|
|
76
|
-
"@quirekit/html-sandbox": "0.3.
|
|
76
|
+
"@quirekit/html-sandbox": "0.3.2"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"build": "pnpm icons:generate && tsdown --config tsdown.config.ts",
|
|
@@ -40,6 +40,54 @@ describe("TreeView hierarchy appearance", () => {
|
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
+
it("activates a branch title on every click while its arrow alone toggles the children", async () => {
|
|
44
|
+
const activated: string[] = [];
|
|
45
|
+
const host = document.createElement("div");
|
|
46
|
+
document.body.append(host);
|
|
47
|
+
const app = createApp({ render: () => h(TreeView, {
|
|
48
|
+
label: "Outline",
|
|
49
|
+
selectedValue: ["chapter"],
|
|
50
|
+
nodes: [{ id: "chapter", label: "Chapter", children: [{ id: "section", label: "Section" }] }],
|
|
51
|
+
onNodeActivate: (node: { id: string }) => activated.push(node.id)
|
|
52
|
+
}) });
|
|
53
|
+
app.mount(host);
|
|
54
|
+
cleanup.push(() => { app.unmount(); host.remove(); });
|
|
55
|
+
await nextTick();
|
|
56
|
+
const branch = host.querySelector<HTMLElement>("[role=treeitem][data-value=chapter]")!;
|
|
57
|
+
const control = branch.querySelector<HTMLElement>('[data-part="branch-control"]')!;
|
|
58
|
+
const title = control.querySelector<HTMLElement>('[data-part="branch-text"]')!;
|
|
59
|
+
const arrow = control.querySelector<HTMLElement>('[data-part="branch-trigger"]')!;
|
|
60
|
+
title.click();
|
|
61
|
+
await nextTick();
|
|
62
|
+
title.click();
|
|
63
|
+
await nextTick();
|
|
64
|
+
expect(activated).toEqual(["chapter", "chapter"]);
|
|
65
|
+
expect(branch.getAttribute("aria-expanded")).toBe("false");
|
|
66
|
+
|
|
67
|
+
arrow.click();
|
|
68
|
+
await nextTick();
|
|
69
|
+
expect(branch.getAttribute("aria-expanded")).toBe("true");
|
|
70
|
+
expect(activated).toEqual(["chapter", "chapter"]);
|
|
71
|
+
title.click();
|
|
72
|
+
await nextTick();
|
|
73
|
+
expect(activated).toEqual(["chapter", "chapter", "chapter"]);
|
|
74
|
+
expect(branch.getAttribute("aria-expanded")).toBe("true");
|
|
75
|
+
|
|
76
|
+
control.focus();
|
|
77
|
+
await nextTick();
|
|
78
|
+
control.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true }));
|
|
79
|
+
await nextTick();
|
|
80
|
+
expect(activated).toEqual(["chapter", "chapter", "chapter", "chapter"]);
|
|
81
|
+
control.dispatchEvent(new KeyboardEvent("keydown", { key: " ", bubbles: true, cancelable: true }));
|
|
82
|
+
await nextTick();
|
|
83
|
+
expect(activated.at(-1)).toBe("chapter");
|
|
84
|
+
expect(activated).toHaveLength(5);
|
|
85
|
+
control.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowLeft", bubbles: true, cancelable: true }));
|
|
86
|
+
await nextTick();
|
|
87
|
+
expect(branch.getAttribute("aria-expanded")).toBe("false");
|
|
88
|
+
expect(activated).toHaveLength(5);
|
|
89
|
+
});
|
|
90
|
+
|
|
43
91
|
it('cascades enabled leaves and uses Space for checks without selecting the row', async () => {
|
|
44
92
|
const state = reactive({ checked: [] as string[] });
|
|
45
93
|
const host = document.createElement('div'); document.body.append(host);
|
|
@@ -67,6 +67,8 @@ interface Emits {
|
|
|
67
67
|
expandedChange: [details: PublicExpandedChangeDetails];
|
|
68
68
|
/** 选择集合变化后触发。 */
|
|
69
69
|
selectionChange: [details: PublicSelectionChangeDetails];
|
|
70
|
+
/** 每次通过标题或键盘确认节点时触发,包含重复确认已选节点。 */
|
|
71
|
+
nodeActivate: [node: QuireKitTreeNode];
|
|
70
72
|
/** 异步子节点加载并写入 collection 后触发。 */
|
|
71
73
|
loadChildrenComplete: [nodes: readonly QuireKitTreeNode[]];
|
|
72
74
|
/** 一个或多个异步分支加载失败后触发。 */
|
|
@@ -81,7 +83,7 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
81
83
|
selectionMode: "single",
|
|
82
84
|
selectionAppearance: "background",
|
|
83
85
|
showIndentGuides: true,
|
|
84
|
-
expandOnClick:
|
|
86
|
+
expandOnClick: false,
|
|
85
87
|
typeahead: true,
|
|
86
88
|
lazyMount: false,
|
|
87
89
|
unmountOnExit: false
|
|
@@ -145,6 +147,30 @@ function handleSelectionChange(details: TreeViewSelectionChangeDetails<QuireKitT
|
|
|
145
147
|
});
|
|
146
148
|
}
|
|
147
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Publishes title activation independently of changes to the selection.
|
|
152
|
+
* @param event - A captured row click or a keyboard confirmation handled by Ark.
|
|
153
|
+
*/
|
|
154
|
+
function activateNode(event: MouseEvent | KeyboardEvent): void {
|
|
155
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
156
|
+
if (event instanceof KeyboardEvent) {
|
|
157
|
+
// Ark consumes confirmation keys and leaves a typeahead Space unconsumed.
|
|
158
|
+
const activates = event.key === "Enter" || (event.key === " " && !props.checkable);
|
|
159
|
+
if (!activates || !event.defaultPrevented || event.repeat || event.isComposing) return;
|
|
160
|
+
} else if (event.button !== 0 || event.defaultPrevented) return;
|
|
161
|
+
|
|
162
|
+
const target = event.target;
|
|
163
|
+
if (!(target instanceof Element) || target.closest('[data-scope="tree-view"][data-part="root"]') !== event.currentTarget) return;
|
|
164
|
+
const row = target.closest<HTMLElement>('[data-part="branch-control"], [data-part="item"]');
|
|
165
|
+
if (!row || row.matches("[data-disabled], [data-loading], [data-renaming]")) return;
|
|
166
|
+
const control = target.closest('button, a, input, select, textarea, [role="button"], [role="checkbox"], [contenteditable]:not([contenteditable="false"])');
|
|
167
|
+
if (control && control !== row) return;
|
|
168
|
+
|
|
169
|
+
const id = row.dataset.value;
|
|
170
|
+
const node = id === undefined ? undefined : collection.value.findNode(id);
|
|
171
|
+
if (node) emit("nodeActivate", node);
|
|
172
|
+
}
|
|
173
|
+
|
|
148
174
|
/**
|
|
149
175
|
* 接管 Ark 返回的新 collection,使异步节点立即进入递归渲染。
|
|
150
176
|
*
|
|
@@ -192,7 +218,9 @@ function checkWithKeyboard(event: KeyboardEvent): void {
|
|
|
192
218
|
:unmount-on-exit="unmountOnExit"
|
|
193
219
|
:class="['qk-tree-view', `qk-tree-view--selection-${selectionAppearance}`, !showIndentGuides && 'qk-tree-view--hide-guides']"
|
|
194
220
|
@checked-change="checkedValue = $event.checkedValue"
|
|
221
|
+
@click.capture="activateNode"
|
|
195
222
|
@keydown.capture="checkWithKeyboard"
|
|
223
|
+
@keydown="activateNode"
|
|
196
224
|
@expanded-change="handleExpandedChange"
|
|
197
225
|
@selection-change="handleSelectionChange"
|
|
198
226
|
@load-children-complete="handleLoadComplete"
|