@quirekit/ui 0.0.3 → 0.2.0
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.md +1 -1
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/{catalog-AqWLE58Z.mjs → catalog-Dn7izrV5.mjs} +859 -290
- package/dist/catalog-Dn7izrV5.mjs.map +1 -0
- package/dist/{chat-BSVF78Hu.mjs → chat-1THPEdHw.mjs} +224 -143
- package/dist/chat-1THPEdHw.mjs.map +1 -0
- package/dist/chat.d.mts +2 -2
- package/dist/chat.mjs +1 -1
- package/dist/{code-block-pXaSN9eY.mjs → code-block-BLzjRjTb.mjs} +2 -2
- package/dist/{code-block-pXaSN9eY.mjs.map → code-block-BLzjRjTb.mjs.map} +1 -1
- package/dist/{html-sandbox-CMsenGYi.mjs → html-sandbox-D9a7iXbU.mjs} +2 -2
- package/dist/{html-sandbox-CMsenGYi.mjs.map → html-sandbox-D9a7iXbU.mjs.map} +1 -1
- package/dist/html-sandbox.mjs +1 -1
- package/dist/{index-Bf9CudSF.d.mts → index-BkzB7Lb6.d.mts} +487 -144
- package/dist/index-BkzB7Lb6.d.mts.map +1 -0
- package/dist/{index-DZc5z5s2.d.mts → index-DVBEYJNY.d.mts} +3 -2
- package/dist/index-DVBEYJNY.d.mts.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +21 -4
- package/dist/index.mjs.map +1 -1
- package/dist/{model-D4-FbKXY.mjs → model-BjGYjpa9.mjs} +3 -3
- package/dist/{model-D4-FbKXY.mjs.map → model-BjGYjpa9.mjs.map} +1 -1
- package/dist/{resolve-BwTfY4PS.mjs → resolve-nFmJOtS9.mjs} +2 -2
- package/dist/{resolve-BwTfY4PS.mjs.map → resolve-nFmJOtS9.mjs.map} +1 -1
- package/dist/vue.d.mts +546 -487
- package/dist/vue.d.mts.map +1 -1
- package/dist/vue.mjs +3379 -2828
- package/dist/vue.mjs.map +1 -1
- package/package.json +11 -4
- package/src/components/chat/composer/types.ts +2 -0
- package/src/components/chat/message-part/types.ts +3 -1
- package/src/components/chat/reasoning/types.ts +1 -1
- package/src/components/chat/tool/types.ts +1 -1
- package/src/components/dialog/index.ts +1 -1
- package/src/components/dialog/types.ts +5 -2
- package/src/components/edit-bar/index.ts +1 -0
- package/src/components/edit-bar/types.ts +24 -0
- package/src/components/icon/custom/formatting.ts +3 -0
- package/src/components/icon/custom/indicators.ts +1 -0
- package/src/components/icon/custom/insert.ts +33 -1
- package/src/components/icon/custom/mind-map.ts +28 -0
- package/src/components/icon/custom.ts +3 -1
- package/src/components/icon/lucide.ts +21 -1
- package/src/components/icon/metadata.ts +289 -0
- package/src/components/index.ts +1 -0
- package/src/components/kbd/index.ts +1 -0
- package/src/components/kbd/platform.test.ts +16 -0
- package/src/components/kbd/platform.ts +16 -0
- package/src/components/toolbar/index.ts +1 -0
- package/src/components/toolbar/types.ts +8 -0
- package/src/locale/components/chat.ts +9 -7
- package/src/locale/components/edit-bar.ts +15 -0
- package/src/locale/components/icon-catalog/en.ts +89 -2
- package/src/locale/components/icon-catalog/zh-hans.ts +89 -2
- package/src/locale/packs/en.ts +2 -0
- package/src/locale/packs/zh-cn.ts +2 -0
- package/src/locale/types.ts +3 -0
- package/src/vue/action-menu/directory.vue +0 -7
- package/src/vue/block-handle/block-handle.test.ts +5 -0
- package/src/vue/block-handle/block-handle.vue +4 -11
- package/src/vue/block-handle/index.ts +1 -1
- package/src/vue/block-handle/presentation.ts +4 -0
- package/src/vue/chat/composer/composer.test.ts +11 -2
- package/src/vue/chat/composer/composer.vue +15 -3
- package/src/vue/chat/composer-submit/composer-submit.test.ts +5 -1
- package/src/vue/chat/composer-submit/composer-submit.vue +1 -1
- package/src/vue/chat/confirmation/confirmation.vue +3 -2
- package/src/vue/chat/locale.test.ts +2 -2
- package/src/vue/chat/message/message.test.ts +1 -1
- package/src/vue/chat/message/message.vue +8 -3
- package/src/vue/chat/message-actions/message-actions.vue +1 -1
- package/src/vue/chat/message-list/message-list.test.ts +2 -2
- package/src/vue/chat/message-list/message-list.vue +2 -2
- package/src/vue/chat/message-list/types.ts +2 -0
- package/src/vue/chat/message-list/use-scroll.test.ts +7 -1
- package/src/vue/chat/message-list/use-scroll.ts +12 -9
- package/src/vue/chat/message-part/message-part.test.ts +1 -1
- package/src/vue/chat/message-part/message-part.vue +2 -3
- package/src/vue/chat/shared/disclosure.vue +1 -1
- package/src/vue/chat/shared/part-actions.ts +1 -1
- package/src/vue/chat/shared/state-icon.ts +2 -1
- package/src/vue/combobox/async-value.test.ts +49 -0
- package/src/vue/combobox/use-combobox-model.ts +3 -1
- package/src/vue/component-styles.test.ts +17 -0
- package/src/vue/dialog/content.vue +29 -5
- package/src/vue/dialog/size.test.ts +61 -0
- package/src/vue/edit-bar/edit-bar.test.ts +125 -0
- package/src/vue/edit-bar/edit-bar.vue +108 -0
- package/src/vue/edit-bar/index.ts +2 -0
- package/src/vue/edit-bar/types.ts +21 -0
- package/src/vue/index.ts +1 -0
- package/src/vue/menu/items/disabled-submenu.test.ts +24 -0
- package/src/vue/menu/items/items.test.ts +29 -0
- package/src/vue/menu/items/items.vue +6 -0
- package/src/vue/menu/menu-group.vue +11 -2
- package/src/vue/scroll-area/scroll-area.test.ts +10 -0
- package/src/vue/scroll-area/scroll-area.vue +1 -1
- package/src/vue/select/select.test.ts +18 -0
- package/src/vue/select/select.vue +3 -0
- package/src/vue/slider/slider.test.ts +13 -0
- package/src/vue/slider/slider.vue +4 -2
- package/src/vue/splitter/splitter.test.ts +18 -0
- package/src/vue/splitter/splitter.vue +5 -2
- package/src/vue/task-panel/root.vue +0 -8
- package/src/vue/toolbar/context.ts +5 -2
- package/src/vue/toolbar/items/body.vue +5 -3
- package/src/vue/toolbar/items/control.vue +9 -1
- package/src/vue/toolbar/items/memo.test.ts +49 -0
- package/src/vue/toolbar/items/memo.ts +24 -0
- package/src/vue/toolbar/items/sheet-entries.ts +52 -0
- package/src/vue/toolbar/items/sheet.test.ts +61 -0
- package/src/vue/toolbar/items/sheet.vue +78 -0
- package/src/vue/toolbar/presentation/mobile.test.ts +14 -0
- package/src/vue/toolbar/presentation/visibility.ts +38 -0
- package/src/vue/toolbar/toolbar-split-button.test.ts +2 -0
- package/src/vue/toolbar/toolbar-split-button.vue +1 -0
- package/src/vue/toolbar/toolbar.vue +8 -3
- package/src/vue/toolbar/types.ts +3 -1
- package/dist/catalog-AqWLE58Z.mjs.map +0 -1
- package/dist/chat-BSVF78Hu.mjs.map +0 -1
- package/dist/index-Bf9CudSF.d.mts.map +0 -1
- package/dist/index-DZc5z5s2.d.mts.map +0 -1
- package/dist/style.css +0 -37
|
@@ -15,6 +15,10 @@ interface Props {
|
|
|
15
15
|
interface Slots {
|
|
16
16
|
/** Rows contained by this visual and semantic group. */
|
|
17
17
|
readonly default: () => unknown;
|
|
18
|
+
/** Decorative mark before the label, such as the icon of the source the rows belong to. */
|
|
19
|
+
readonly leading?: () => unknown;
|
|
20
|
+
/** Short status after the label, such as a signed-in state; it is not read as part of the label. */
|
|
21
|
+
readonly trailing?: () => unknown;
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
const { id, label, inset = false } = defineProps<Props>();
|
|
@@ -25,9 +29,14 @@ defineSlots<Slots>();
|
|
|
25
29
|
<Menu.ItemGroup v-bind="id === undefined ? {} : { id }" class="qk-menu__group">
|
|
26
30
|
<Menu.ItemGroupLabel
|
|
27
31
|
v-if="label"
|
|
28
|
-
:class="['qk-menu__group-label', { 'qk-menu__group-label--inset': inset }]"
|
|
32
|
+
:class="['qk-menu__group-label', { 'qk-menu__group-label--inset': inset, 'qk-menu__group-label--slotted': $slots.leading || $slots.trailing }]"
|
|
29
33
|
>
|
|
30
|
-
|
|
34
|
+
<template v-if="$slots.leading || $slots.trailing">
|
|
35
|
+
<span v-if="$slots.leading" class="qk-menu__group-leading" aria-hidden="true"><slot name="leading" /></span>
|
|
36
|
+
<span class="qk-menu__group-text">{{ label }}</span>
|
|
37
|
+
<span v-if="$slots.trailing" class="qk-menu__trailing"><slot name="trailing" /></span>
|
|
38
|
+
</template>
|
|
39
|
+
<template v-else>{{ label }}</template>
|
|
31
40
|
</Menu.ItemGroupLabel>
|
|
32
41
|
<slot />
|
|
33
42
|
</Menu.ItemGroup>
|
|
@@ -51,3 +51,13 @@ it('syncs the thumb once per frame without re-rendering slot content or writing
|
|
|
51
51
|
app.unmount(); host.remove();
|
|
52
52
|
globalThis.ResizeObserver = NativeObserver; globalThis.requestAnimationFrame = nativeFrame;
|
|
53
53
|
});
|
|
54
|
+
|
|
55
|
+
it('lets vertical content take the viewport width, so long rows truncate instead of being clipped', () => {
|
|
56
|
+
const host = document.createElement('div'); document.body.append(host);
|
|
57
|
+
const app = createApp({ render: () => [h(ScrollArea, { label: '纵向' }, () => '正文'), h(ScrollArea, { label: '横向', axis: 'horizontal' }, () => '正文')] });
|
|
58
|
+
app.mount(host);
|
|
59
|
+
const [vertical, horizontal] = [...host.querySelectorAll<HTMLElement>('.qk-scroll-area__content')];
|
|
60
|
+
expect(vertical!.style.minWidth).toBe('');
|
|
61
|
+
expect(horizontal!.style.minWidth).toBe('fit-content');
|
|
62
|
+
app.unmount(); host.remove();
|
|
63
|
+
});
|
|
@@ -142,7 +142,7 @@ defineExpose<Exposed>({ scrollTo, scrollToEdge, getViewportElement });
|
|
|
142
142
|
style="overflow: auto"
|
|
143
143
|
@scroll.passive="handleScroll"
|
|
144
144
|
>
|
|
145
|
-
<div ref="content" data-scope="scroll-area" data-part="content" role="presentation" :class="['qk-scroll-area__content', contentClass]" style="
|
|
145
|
+
<div ref="content" data-scope="scroll-area" data-part="content" role="presentation" :class="['qk-scroll-area__content', contentClass]" :style="axis === 'vertical' ? undefined : { minWidth: 'fit-content' }">
|
|
146
146
|
<slot />
|
|
147
147
|
</div>
|
|
148
148
|
</div>
|
|
@@ -76,3 +76,21 @@ describe("Select visibility and portal attributes", () => {
|
|
|
76
76
|
expect(trigger.getAttribute("aria-expanded")).toBe("false");
|
|
77
77
|
});
|
|
78
78
|
});
|
|
79
|
+
|
|
80
|
+
describe("Select leading content", () => {
|
|
81
|
+
it("places leading content before the value text and keeps it out of the accessible name", async () => {
|
|
82
|
+
const host = document.createElement("div");
|
|
83
|
+
document.body.append(host);
|
|
84
|
+
const app = createApp({
|
|
85
|
+
setup: () => () => h(Select, { label: "Provider", modelValue: "a", items: [{ label: "Alpha", value: "a" }], portalled: false },
|
|
86
|
+
{ leading: () => h("img", { class: "logo", alt: "" }) })
|
|
87
|
+
});
|
|
88
|
+
app.mount(host);
|
|
89
|
+
cleanups.push(() => { app.unmount(); host.remove(); });
|
|
90
|
+
await nextTick();
|
|
91
|
+
const leading = host.querySelector(".qk-select__leading")!;
|
|
92
|
+
expect(leading.getAttribute("aria-hidden")).toBe("true");
|
|
93
|
+
expect(leading.querySelector(".logo")).not.toBeNull();
|
|
94
|
+
expect(leading.nextElementSibling?.classList.contains("qk-select__value")).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -81,6 +81,8 @@ interface ItemSlotProps {
|
|
|
81
81
|
interface Slots {
|
|
82
82
|
/** 替换选项的可见内容,保留可访问名称。 */
|
|
83
83
|
readonly item?: (props: ItemSlotProps) => unknown;
|
|
84
|
+
/** 触发器中值文字前的内容,例如所选项的图标。 */
|
|
85
|
+
readonly leading?: () => unknown;
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
const portal = useQuireOverlayHost();
|
|
@@ -185,6 +187,7 @@ function updateValue(values: string[]): void {
|
|
|
185
187
|
style="width: 100%"
|
|
186
188
|
:class="['qk-select__trigger', `qk-select__trigger--${size}`]"
|
|
187
189
|
>
|
|
190
|
+
<span v-if="$slots.leading" class="qk-select__leading" aria-hidden="true"><slot name="leading" /></span>
|
|
188
191
|
<Select.ValueText :placeholder="placeholder ?? text.placeholder" class="qk-select__value" />
|
|
189
192
|
<Select.Indicator class="qk-select__indicator">
|
|
190
193
|
<QuireIcon name="chevronDown" :size="16" />
|
|
@@ -50,3 +50,16 @@ describe("Slider native form state", () => {
|
|
|
50
50
|
expect(new FormData(form).getAll("pages[]")).toEqual(["20", "80"]);
|
|
51
51
|
});
|
|
52
52
|
});
|
|
53
|
+
|
|
54
|
+
describe("Slider label", () => {
|
|
55
|
+
it("keeps a hidden label as the thumb's name and drops the header row when nothing in it shows", async () => {
|
|
56
|
+
const host = document.createElement("div");
|
|
57
|
+
document.body.append(host);
|
|
58
|
+
const app = createApp(defineComponent({ setup: () => () => h(Slider, { label: "Duration", hideLabel: true, showValue: false, modelValue: [1] }) }));
|
|
59
|
+
app.mount(host);
|
|
60
|
+
cleanups.push(() => { app.unmount(); host.remove(); });
|
|
61
|
+
await nextTick();
|
|
62
|
+
expect(host.querySelector(".qk-slider__header")).toBeNull();
|
|
63
|
+
expect(host.querySelector("[role=slider]")?.getAttribute("aria-label")).toBe("Duration");
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -27,6 +27,8 @@ interface Props {
|
|
|
27
27
|
readonly origin?: QuireKitSliderOrigin;
|
|
28
28
|
/** 是否显示当前值文字。 */
|
|
29
29
|
readonly showValue?: boolean;
|
|
30
|
+
/** 只为辅助技术保留名称,不显示标签;外层已有字段名时使用。 */
|
|
31
|
+
readonly hideLabel?: boolean;
|
|
30
32
|
/** 当前值之后显示的单位。 */
|
|
31
33
|
readonly unit?: string;
|
|
32
34
|
/** 原生表单字段名。 */
|
|
@@ -90,8 +92,8 @@ function updateValues(nextValues: number[]): void {
|
|
|
90
92
|
:class="['qk-slider', `qk-slider--${orientation}`]"
|
|
91
93
|
@update:model-value="updateValues"
|
|
92
94
|
>
|
|
93
|
-
<div class="qk-slider__header">
|
|
94
|
-
<span class="qk-slider__label">{{ label }}</span>
|
|
95
|
+
<div v-if="!hideLabel || showValue" class="qk-slider__header">
|
|
96
|
+
<span :class="['qk-slider__label', hideLabel && 'sr-only']">{{ label }}</span>
|
|
95
97
|
<Slider.ValueText v-if="showValue" class="qk-slider__value">
|
|
96
98
|
{{ currentValues.join(" – ") }}{{ unit }}
|
|
97
99
|
</Slider.ValueText>
|
|
@@ -65,3 +65,21 @@ describe("Splitter separator semantics and keyboard resizing", () => {
|
|
|
65
65
|
expect(handle.tabIndex).toBe(-1);
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
|
+
|
|
69
|
+
describe("Splitter frame", () => {
|
|
70
|
+
it("drops its own border and radius when embedded as an application shell", async () => {
|
|
71
|
+
const host = document.createElement("div");
|
|
72
|
+
document.body.append(host);
|
|
73
|
+
const state = reactive({ bordered: true });
|
|
74
|
+
const app = createApp(defineComponent({
|
|
75
|
+
setup: () => () => h(Splitter, { label: "工作区", bordered: state.bordered, panels: [{ id: "a" }, { id: "b" }], defaultSize: [50, 50] })
|
|
76
|
+
}));
|
|
77
|
+
app.mount(host);
|
|
78
|
+
cleanups.push(() => { app.unmount(); host.remove(); });
|
|
79
|
+
await nextTick();
|
|
80
|
+
const root = host.querySelector(".qk-splitter")!;
|
|
81
|
+
expect(root.classList.contains("qk-splitter--borderless")).toBe(false);
|
|
82
|
+
state.bordered = false; await nextTick();
|
|
83
|
+
expect(root.classList.contains("qk-splitter--borderless")).toBe(true);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -32,6 +32,8 @@ interface Props {
|
|
|
32
32
|
readonly handleVariant?: QuireKitSplitterHandleVariant;
|
|
33
33
|
/** 是否禁止全部调整柄交互。 */
|
|
34
34
|
readonly disabled?: boolean;
|
|
35
|
+
/** 是否绘制外框、圆角与底色;作为应用外壳铺满窗口时关闭,面板外观由内容决定。 */
|
|
36
|
+
readonly bordered?: boolean;
|
|
35
37
|
/** Splitter 的可访问名称。 */
|
|
36
38
|
readonly label: string;
|
|
37
39
|
}
|
|
@@ -64,7 +66,8 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
64
66
|
keyboardResizeBy: 10,
|
|
65
67
|
handleSize: "sm",
|
|
66
68
|
handleVariant: "line",
|
|
67
|
-
disabled: false
|
|
69
|
+
disabled: false,
|
|
70
|
+
bordered: true
|
|
68
71
|
});
|
|
69
72
|
const sizes = defineModel<number[] | undefined>("size");
|
|
70
73
|
const emit = defineEmits<Emits>();
|
|
@@ -214,7 +217,7 @@ defineExpose<QuireKitSplitterHandle>({
|
|
|
214
217
|
<Splitter.RootProvider
|
|
215
218
|
:value="splitter"
|
|
216
219
|
:aria-label="label"
|
|
217
|
-
:class="['qk-splitter', `qk-splitter--${orientation}
|
|
220
|
+
:class="['qk-splitter', `qk-splitter--${orientation}`, { 'qk-splitter--borderless': !bordered }]"
|
|
218
221
|
>
|
|
219
222
|
<template v-for="(panel, index) in panels" :key="panel.id">
|
|
220
223
|
<Splitter.Panel :id="panel.id" class="qk-splitter__panel">
|
|
@@ -63,11 +63,3 @@ defineExpose({ requestClose });
|
|
|
63
63
|
</DrawerFrame>
|
|
64
64
|
</Drawer.RootProvider>
|
|
65
65
|
</template>
|
|
66
|
-
<style scoped>
|
|
67
|
-
.qk-task-panel__header { display: flex; align-items: center; gap: var(--qk-space-inline); padding: var(--qk-space-surface-compact); }
|
|
68
|
-
.qk-task-panel__header > :nth-last-child(2) { flex: 1; min-width: 0; }
|
|
69
|
-
.qk-task-panel__body { overflow: auto; min-height: 0; padding: var(--qk-space-surface-compact); }
|
|
70
|
-
.qk-task-panel__footer { padding: var(--qk-space-surface-compact); }
|
|
71
|
-
.qk-task-panel__header--bottom > button { min-width: 44px; min-height: 44px; }
|
|
72
|
-
.qk-task-panel__header--bottom { padding-block: var(--qk-space-inline); }
|
|
73
|
-
</style>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComputedRef, InjectionKey, ShallowRef } from "vue";
|
|
2
|
-
import type { QuireKitToolbarOrientation } from "../../components/toolbar/types";
|
|
2
|
+
import type { QuireKitToolbarOrientation, QuireKitToolbarSizing } from "../../components/toolbar/types";
|
|
3
3
|
|
|
4
4
|
/** One mounted toolbar control registered with its nearest root. */
|
|
5
5
|
export interface QuireKitToolbarItemRegistration {
|
|
@@ -42,7 +42,10 @@ export const toolbarSplitDisclosureDisabledKey = Symbol(
|
|
|
42
42
|
/** Width model chosen by the nearest Toolbar root. */
|
|
43
43
|
export const toolbarSizingKey = Symbol(
|
|
44
44
|
"QuireKitToolbarSizing"
|
|
45
|
-
) as InjectionKey<ComputedRef<
|
|
45
|
+
) as InjectionKey<ComputedRef<QuireKitToolbarSizing>>;
|
|
46
|
+
|
|
47
|
+
/** Whether second-level surfaces open as bottom sheets instead of anchored popups. */
|
|
48
|
+
export const toolbarSheetKey = Symbol("ToolbarSheet") as InjectionKey<ComputedRef<boolean>>;
|
|
46
49
|
|
|
47
50
|
/** Touch presentation inherited by every built-in control, including Tooltip and overflow. */
|
|
48
51
|
export const toolbarMobileKey = Symbol("ToolbarMobile") as InjectionKey<ComputedRef<boolean>>;
|
|
@@ -4,6 +4,7 @@ import type { QuireKitToolbarRendererScope, QuireKitToolbarRenderers } from "./t
|
|
|
4
4
|
import ToolbarItems from "./items.vue";
|
|
5
5
|
import QuireToolbarGroup from "../toolbar-group.vue";
|
|
6
6
|
import { toolbarCollapseKey } from "../collapse/units";
|
|
7
|
+
import { entryMemo, entryReadsContext } from "./memo";
|
|
7
8
|
|
|
8
9
|
defineProps<{
|
|
9
10
|
/** Legacy single-row contributions. */
|
|
@@ -33,9 +34,10 @@ const emit = defineEmits<{
|
|
|
33
34
|
|
|
34
35
|
<template>
|
|
35
36
|
<!-- One keyed anatomy retains open/focused controls across overflow modes.
|
|
36
|
-
Only collapse wrappers create boxes; other single-row modes flatten them.
|
|
37
|
+
Only collapse wrappers create boxes; other single-row modes flatten them.
|
|
38
|
+
v-memo skips entries the host kept by identity, so a change to a few entries patches only those. -->
|
|
37
39
|
<template v-if="rows === undefined">
|
|
38
|
-
<template v-for="item in (items ?? []).filter(entry => !entry.hidden)" :key="item.value">
|
|
40
|
+
<template v-for="item in (items ?? []).filter(entry => !entry.hidden)" :key="item.value" v-memo="entryMemo(item, context, [units, renderers, $slots.item, $slots.content])">
|
|
39
41
|
<QuireToolbarGroup v-if="item.kind === 'group'" :label="item.label">
|
|
40
42
|
<div v-for="child in (item.children ?? []).filter(entry => !entry.hidden)" :key="child.value" :class="units ? 'qk-toolbar__unit' : undefined" :style="units ? undefined : { display: 'contents' }" :data-qk-toolbar-unit="units ? toolbarCollapseKey(item, child) : undefined">
|
|
41
43
|
<ToolbarItems :items="[child]" :path="[item.value]" :disabled="!!item.disabled" :context="context" :renderers="renderers"
|
|
@@ -54,7 +56,7 @@ const emit = defineEmits<{
|
|
|
54
56
|
</div>
|
|
55
57
|
</template>
|
|
56
58
|
</template>
|
|
57
|
-
<template v-else v-for="row in rows" :key="row.value">
|
|
59
|
+
<template v-else v-for="row in rows" :key="row.value" v-memo="[row, row.items.some(entryReadsContext) ? context : undefined, renderers, $slots.item, $slots.content]">
|
|
58
60
|
<div v-if="!row.hidden && row.items.some(item => !item.hidden)" role="group" :aria-label="row.label" :data-qk-toolbar-row="row.value" class="qk-toolbar__row">
|
|
59
61
|
<ToolbarItems :items="row.items" :path="[row.value]" :disabled="row.disabled ?? false" :context="context" :renderers="renderers"
|
|
60
62
|
@execute="emit('execute', $event)" @open-change="emit('openChange', $event)">
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { computed, inject } from "vue";
|
|
3
|
-
import { toolbarLabelsKey } from "../context";
|
|
3
|
+
import { toolbarLabelsKey, toolbarSheetKey } from "../context";
|
|
4
4
|
import type { QuireKitToolbarEntry, QuireKitToolbarExecuteEvent, QuireKitToolbarOpenChangeEvent } from "../../../components/toolbar/types";
|
|
5
5
|
import type { QuireKitToolbarRendererScope, QuireKitToolbarRenderers } from "./types";
|
|
6
6
|
import QuireIcon from "../../icon/icon.vue";
|
|
@@ -13,6 +13,7 @@ import QuireToolbarSelector from "../toolbar-selector.vue";
|
|
|
13
13
|
import QuireToolbarDisclosure from "../toolbar-disclosure.vue";
|
|
14
14
|
import QuireToolbarSplitButton from "../toolbar-split-button.vue";
|
|
15
15
|
import PopupBody from "./popup-body.vue";
|
|
16
|
+
import ToolbarSheet from "./sheet.vue";
|
|
16
17
|
import { useToolbarEntry } from "./use-entry";
|
|
17
18
|
import { quireKitEditorIconData } from "../../../components/icon/catalog";
|
|
18
19
|
const props = defineProps<{
|
|
@@ -44,6 +45,7 @@ const { unavailable, expanded, setExpanded, dispatch, scope } = useToolbarEntry(
|
|
|
44
45
|
);
|
|
45
46
|
const hasIcon = computed(() => !!(props.item.icon || props.item.iconData));
|
|
46
47
|
const showLabels = inject(toolbarLabelsKey);
|
|
48
|
+
const sheet = inject(toolbarSheetKey, computed(() => false));
|
|
47
49
|
const common = computed(() => ({
|
|
48
50
|
...props.item.attributes, label: props.item.label, disabled: unavailable.value,
|
|
49
51
|
...(props.item.tooltip === undefined ? {} : { tooltip: props.item.tooltip }),
|
|
@@ -62,6 +64,12 @@ const menuProps = computed(() => {
|
|
|
62
64
|
<component v-if="item.renderer && renderers[item.renderer]" :is="renderers[item.renderer]" :scope="scope" />
|
|
63
65
|
<slot v-else name="item" v-bind="scope" />
|
|
64
66
|
</template>
|
|
67
|
+
<!-- A bottom-sheet toolbar keeps the same trigger but opens second-level content from the bottom. -->
|
|
68
|
+
<ToolbarSheet v-else-if="sheet && (item.kind === 'menu' || item.kind === 'selector' || item.kind === 'disclosure' && (item.contentRenderer || $slots.content))"
|
|
69
|
+
:scope="scope" :renderers="renderers" :common="common" :text="text" @update:expanded="setExpanded"
|
|
70
|
+
@select="(value, event) => dispatch('menu', item.payload, value, undefined, event)">
|
|
71
|
+
<template v-if="$slots.content" #content="body"><slot name="content" v-bind="body" /></template>
|
|
72
|
+
</ToolbarSheet>
|
|
65
73
|
<QuireMenu v-else-if="item.kind === 'menu'" v-bind="menuProps" :open="expanded" @update:open="setExpanded($event === true)"
|
|
66
74
|
:aria-label="item.label" :items="item.items ?? []" @select="dispatch('menu', item.payload, $event)">
|
|
67
75
|
<template #trigger>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { createApp, defineComponent, h, nextTick, shallowRef } from "vue";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import type { QuireKitToolbarEntry } from "../../../components/toolbar/types";
|
|
5
|
+
import Toolbar from "../toolbar.vue";
|
|
6
|
+
import { entryReadsContext } from "./memo";
|
|
7
|
+
|
|
8
|
+
it("knows which entries read the host context", () => {
|
|
9
|
+
expect(entryReadsContext({ value: "cut", label: "Cut" })).toBe(false);
|
|
10
|
+
expect(entryReadsContext({ value: "bold", label: "Bold", kind: "toggle" })).toBe(false);
|
|
11
|
+
expect(entryReadsContext({ value: "size", label: "Size", kind: "custom", renderer: "size" })).toBe(true);
|
|
12
|
+
expect(entryReadsContext({ value: "font", label: "Font", kind: "group", children: [{ value: "cut", label: "Cut" }, { value: "color", label: "Color", kind: "split" }] })).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("patches only the entries that changed or read a changed context", async () => {
|
|
16
|
+
const host = document.createElement("div");
|
|
17
|
+
document.body.append(host);
|
|
18
|
+
const draws: string[] = [];
|
|
19
|
+
const Size = defineComponent({
|
|
20
|
+
props: { scope: { type: Object, required: true } },
|
|
21
|
+
setup: props => () => { draws.push("size"); return h("span", { "data-size": String((props.scope as { context: { size: number } }).context.size) }); }
|
|
22
|
+
});
|
|
23
|
+
const cut: QuireKitToolbarEntry = { value: "cut", label: "Cut" };
|
|
24
|
+
const size: QuireKitToolbarEntry = { value: "size", label: "Size", kind: "custom", renderer: "size" };
|
|
25
|
+
const items = shallowRef<QuireKitToolbarEntry[]>([cut, size, { value: "bold", label: "Bold", kind: "toggle", pressed: false }]);
|
|
26
|
+
const context = shallowRef({ size: 12 });
|
|
27
|
+
const renderers = { size: Size };
|
|
28
|
+
const app = createApp({ render: () => h(Toolbar, { label: "Format", items: items.value, context: context.value, renderers }) });
|
|
29
|
+
try {
|
|
30
|
+
app.mount(host);
|
|
31
|
+
await nextTick();
|
|
32
|
+
draws.length = 0;
|
|
33
|
+
// Only the toggle is a new entry: the custom control is not drawn again.
|
|
34
|
+
items.value = [cut, size, { value: "bold", label: "Bold", kind: "toggle", pressed: true }];
|
|
35
|
+
await nextTick();
|
|
36
|
+
expect(host.querySelector("[aria-pressed]")?.getAttribute("aria-pressed")).toBe("true");
|
|
37
|
+
expect(draws).toEqual([]);
|
|
38
|
+
// A new context reaches the custom control, which reads it.
|
|
39
|
+
context.value = { size: 14 };
|
|
40
|
+
await nextTick();
|
|
41
|
+
expect(draws).toEqual(["size"]);
|
|
42
|
+
expect(host.querySelector("[data-size]")?.getAttribute("data-size")).toBe("14");
|
|
43
|
+
// Entries rebuilt by the host are drawn again, as before.
|
|
44
|
+
items.value = [{ ...cut, disabled: true }, { ...size }, items.value[2]!];
|
|
45
|
+
await nextTick();
|
|
46
|
+
expect(draws).toEqual(["size", "size"]);
|
|
47
|
+
expect(host.querySelector("button")?.getAttribute("aria-disabled") ?? String(host.querySelector("button")?.disabled)).toMatch(/true/u);
|
|
48
|
+
} finally { app.unmount(); host.remove(); }
|
|
49
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { QuireKitToolbarEntry } from "../../../components/toolbar/types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Whether an entry hands the host context to what it draws: custom renderers and popup bodies receive it in their
|
|
5
|
+
* scope, while plain actions, toggles and separators draw from the entry alone.
|
|
6
|
+
* @param entry - Configured entry.
|
|
7
|
+
* @returns Whether the entry, or one of its group children, reads the context.
|
|
8
|
+
*/
|
|
9
|
+
export function entryReadsContext(entry: QuireKitToolbarEntry): boolean {
|
|
10
|
+
if (entry.kind === "group") return (entry.children ?? []).some(entryReadsContext);
|
|
11
|
+
return entry.kind !== undefined && entry.kind !== "action" && entry.kind !== "toggle" && entry.kind !== "separator";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* What one top-level entry's rendering depends on, for `v-memo`: an entry the host kept by identity is not patched
|
|
16
|
+
* again when other entries or a context it does not read change.
|
|
17
|
+
* @param entry - Configured entry.
|
|
18
|
+
* @param context - Host context.
|
|
19
|
+
* @param shared - Values every entry depends on, such as renderers, slots and layout mode.
|
|
20
|
+
* @returns Memo dependencies.
|
|
21
|
+
*/
|
|
22
|
+
export function entryMemo(entry: QuireKitToolbarEntry, context: unknown, shared: readonly unknown[]): unknown[] {
|
|
23
|
+
return [entry, entryReadsContext(entry) ? context : undefined, ...shared];
|
|
24
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { QuireKitMenuEntry } from "../../../components/menu/types";
|
|
2
|
+
import type { QuireKitToolbarEntry } from "../../../components/toolbar/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Projects menu rows onto Toolbar entries for a touch sheet, so the sheet reuses
|
|
6
|
+
* the same controls, labels and focus model as the overflow panel.
|
|
7
|
+
*
|
|
8
|
+
* @param entries - Declarative menu rows of one menu-trigger entry.
|
|
9
|
+
* @returns Entries where radio options and checkable rows become toggles.
|
|
10
|
+
*/
|
|
11
|
+
export function toolbarSheetEntries(entries: readonly QuireKitMenuEntry[]): QuireKitToolbarEntry[] {
|
|
12
|
+
return entries.map((entry): QuireKitToolbarEntry => {
|
|
13
|
+
if (entry.kind === "separator") return { value: entry.value, label: "", kind: "separator" };
|
|
14
|
+
const base = {
|
|
15
|
+
value: entry.value, label: entry.label,
|
|
16
|
+
...(entry.icon === undefined ? {} : { icon: entry.icon }),
|
|
17
|
+
...(entry.disabled === true ? { disabled: true } : {}),
|
|
18
|
+
...(entry.reason === undefined ? {} : { disabledReason: entry.reason })
|
|
19
|
+
};
|
|
20
|
+
if (entry.kind === "radio-group") {
|
|
21
|
+
return { ...base, kind: "group", children: (entry.children ?? []).map(child => ({
|
|
22
|
+
...toolbarSheetEntries([child])[0]!, kind: "toggle" as const, pressed: child.value === entry.selectedValue
|
|
23
|
+
})) };
|
|
24
|
+
}
|
|
25
|
+
if (entry.kind === "group" || entry.kind === "submenu") return { ...base, kind: "group", children: toolbarSheetEntries(entry.children ?? []) };
|
|
26
|
+
return entry.checked === undefined ? base : { ...base, kind: "toggle", pressed: entry.checked };
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Decides whether choosing a sheet row ends the sheet: checkable rows stay open
|
|
32
|
+
* for further changes, every other choice closes it unless the row opts out.
|
|
33
|
+
*
|
|
34
|
+
* @param entries - Declarative menu rows of the sheet.
|
|
35
|
+
* @param value - Chosen row identity.
|
|
36
|
+
* @returns Whether the sheet closes after this choice.
|
|
37
|
+
*/
|
|
38
|
+
export function toolbarSheetClosesOn(entries: readonly QuireKitMenuEntry[], value: string): boolean {
|
|
39
|
+
for (const entry of entries) {
|
|
40
|
+
if (entry.value === value && entry.kind !== "group" && entry.kind !== "submenu" && entry.kind !== "radio-group") {
|
|
41
|
+
return entry.closeOnSelect ?? entry.checked === undefined;
|
|
42
|
+
}
|
|
43
|
+
const children = entry.children ?? [];
|
|
44
|
+
if (entry.kind === "radio-group" && children.some(child => child.value === value)) {
|
|
45
|
+
return children.find(child => child.value === value)?.closeOnSelect ?? true;
|
|
46
|
+
}
|
|
47
|
+
if (children.length > 0 && entry.kind !== "radio-group" && children.some(function contains(child): boolean {
|
|
48
|
+
return child.value === value || (child.children ?? []).some(contains);
|
|
49
|
+
})) return toolbarSheetClosesOn(children, value);
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { createApp, h, nextTick, ref } from "vue";
|
|
3
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
4
|
+
import Toolbar from "../toolbar.vue";
|
|
5
|
+
import { toolbarSheetClosesOn, toolbarSheetEntries } from "./sheet-entries";
|
|
6
|
+
import type { QuireKitMenuEntry } from "../../../components/menu/types";
|
|
7
|
+
import type { QuireKitToolbarExecuteEvent } from "../../../components/toolbar/types";
|
|
8
|
+
|
|
9
|
+
const cleanups: (() => void)[] = [];
|
|
10
|
+
afterEach(() => { for (const cleanup of cleanups.splice(0)) cleanup(); });
|
|
11
|
+
|
|
12
|
+
const fonts: QuireKitMenuEntry[] = [
|
|
13
|
+
{ value: "fonts", label: "Font", kind: "radio-group", selectedValue: "serif", children: [{ value: "sans", label: "Sans" }, { value: "serif", label: "Serif" }] },
|
|
14
|
+
{ value: "line", label: "", kind: "separator" },
|
|
15
|
+
{ value: "ruler", label: "Ruler", checked: false },
|
|
16
|
+
{ value: "manage", label: "Manage fonts", icon: "settings" }
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
it("maps radio options and checkable rows to toggles and keeps checkable choices open", () => {
|
|
20
|
+
const entries = toolbarSheetEntries(fonts);
|
|
21
|
+
expect(entries[0]).toMatchObject({ kind: "group", children: [{ value: "sans", kind: "toggle", pressed: false }, { value: "serif", kind: "toggle", pressed: true }] });
|
|
22
|
+
expect(entries[1]?.kind).toBe("separator");
|
|
23
|
+
expect(entries[2]).toMatchObject({ kind: "toggle", pressed: false });
|
|
24
|
+
expect(entries[3]).toMatchObject({ value: "manage", icon: "settings" });
|
|
25
|
+
expect(toolbarSheetClosesOn(fonts, "serif")).toBe(true);
|
|
26
|
+
expect(toolbarSheetClosesOn(fonts, "ruler")).toBe(false);
|
|
27
|
+
expect(toolbarSheetClosesOn(fonts, "manage")).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("opens a mobile menu entry as a bottom sheet and closes it after a choice", async () => {
|
|
31
|
+
const host = document.createElement("div");
|
|
32
|
+
document.body.append(host);
|
|
33
|
+
const events: QuireKitToolbarExecuteEvent[] = [];
|
|
34
|
+
const mode = ref<"mobile" | "desktop">("mobile");
|
|
35
|
+
const app = createApp({ render: () => h(Toolbar, { label: "Format", mode: mode.value, popupPresentation: "bottom", overflow: "visible",
|
|
36
|
+
items: [{ value: "font", label: "Font", kind: "menu", text: "Serif", items: fonts }],
|
|
37
|
+
onExecute: (event: QuireKitToolbarExecuteEvent) => events.push(event) }) });
|
|
38
|
+
app.mount(host);
|
|
39
|
+
cleanups.push(() => { app.unmount(); host.remove(); });
|
|
40
|
+
await nextTick();
|
|
41
|
+
host.querySelector<HTMLButtonElement>('[aria-label="Font"]')!.click();
|
|
42
|
+
await vi.waitFor(() => expect(document.querySelector('.qk-drawer__content[role="dialog"]')).not.toBeNull());
|
|
43
|
+
const sheet = document.querySelector<HTMLElement>('.qk-drawer__content[role="dialog"]')!;
|
|
44
|
+
expect(sheet.querySelector('[aria-label="Serif"]')?.getAttribute("aria-pressed")).toBe("true");
|
|
45
|
+
sheet.querySelector<HTMLButtonElement>('[aria-label="Sans"]')!.click();
|
|
46
|
+
expect(events.map(event => [event.source, event.value, event.path])).toEqual([["menu", "sans", ["font", "sans"]]]);
|
|
47
|
+
await vi.waitFor(() => expect(document.querySelector('.qk-drawer__content[role="dialog"]')).toBeNull());
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("keeps menus anchored unless the toolbar asks for bottom sheets", async () => {
|
|
51
|
+
const host = document.createElement("div");
|
|
52
|
+
document.body.append(host);
|
|
53
|
+
const app = createApp({ render: () => h(Toolbar, { label: "Selection", mode: "mobile", overflow: "visible",
|
|
54
|
+
items: [{ value: "more", label: "More", kind: "menu", trigger: "disclosure", items: fonts }] }) });
|
|
55
|
+
app.mount(host);
|
|
56
|
+
cleanups.push(() => { app.unmount(); host.remove(); });
|
|
57
|
+
await nextTick();
|
|
58
|
+
host.querySelector<HTMLButtonElement>('[aria-label="More"]')!.click();
|
|
59
|
+
await vi.waitFor(() => expect(document.querySelector('[role="menu"]')).not.toBeNull());
|
|
60
|
+
expect(document.querySelector('.qk-drawer__content[role="dialog"]')).toBeNull();
|
|
61
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, getCurrentInstance, useId } from "vue";
|
|
3
|
+
import QuireTaskPanel from "../../task-panel/root.vue";
|
|
4
|
+
import QuireButton from "../../button/button.vue";
|
|
5
|
+
import QuireIcon from "../../icon/icon.vue";
|
|
6
|
+
import QuireToolbar from "../toolbar.vue";
|
|
7
|
+
import QuireToolbarDisclosure from "../toolbar-disclosure.vue";
|
|
8
|
+
import QuireToolbarSelector from "../toolbar-selector.vue";
|
|
9
|
+
import { useQuireKitMessages } from "../../locale-provider/context";
|
|
10
|
+
import type { QuireKitToolbarExecuteEvent } from "../../../components/toolbar/types";
|
|
11
|
+
import type { QuireKitToolbarRendererScope, QuireKitToolbarRenderers } from "./types";
|
|
12
|
+
import { toolbarSheetClosesOn, toolbarSheetEntries } from "./sheet-entries";
|
|
13
|
+
|
|
14
|
+
// Touch presentation of a menu or popup entry: the same trigger opens a bottom
|
|
15
|
+
// sheet, as the overflow panel does, instead of a small anchored surface.
|
|
16
|
+
const props = defineProps<{
|
|
17
|
+
/** Live entry state; its item, expanded state and popup bridge. */
|
|
18
|
+
scope: QuireKitToolbarRendererScope;
|
|
19
|
+
/** Named application popup bodies. */
|
|
20
|
+
renderers: QuireKitToolbarRenderers;
|
|
21
|
+
/** Shared trigger attributes: name, availability, tooltip and description. */
|
|
22
|
+
common: Record<string, unknown>;
|
|
23
|
+
/** Visible trigger text, when the entry shows one. */
|
|
24
|
+
text: Record<string, unknown>;
|
|
25
|
+
}>();
|
|
26
|
+
defineSlots<{
|
|
27
|
+
/** Application popup fallback when no registered body is provided. */
|
|
28
|
+
content?: (scope: QuireKitToolbarRendererScope) => unknown;
|
|
29
|
+
}>();
|
|
30
|
+
const emit = defineEmits<{
|
|
31
|
+
/** Requested sheet state; the entry adapter owns it. */
|
|
32
|
+
"update:expanded": [expanded: boolean];
|
|
33
|
+
/** One chosen menu row. */
|
|
34
|
+
select: [value: string, nativeEvent: Event | undefined];
|
|
35
|
+
}>();
|
|
36
|
+
const cancelText = useQuireKitMessages("actionSheet");
|
|
37
|
+
// The trigger sits inside a Tooltip fragment, so the sheet finds the real button by a marker in its own document.
|
|
38
|
+
const marker = useId();
|
|
39
|
+
const instance = getCurrentInstance();
|
|
40
|
+
/** @returns Native trigger button that owns the sheet's viewport and focus return. */
|
|
41
|
+
function trigger(): HTMLElement | null {
|
|
42
|
+
const owner = (instance?.vnode.el as Node | null | undefined)?.ownerDocument;
|
|
43
|
+
return owner?.querySelector<HTMLElement>(`[data-qk-toolbar-sheet="${marker}"]`) ?? null;
|
|
44
|
+
}
|
|
45
|
+
const item = computed(() => props.scope.item);
|
|
46
|
+
const hasIcon = computed(() => !!(item.value.icon || item.value.iconData));
|
|
47
|
+
const rows = computed(() => item.value.items === undefined ? undefined : toolbarSheetEntries(item.value.items));
|
|
48
|
+
const disclosure = computed(() => item.value.kind === "disclosure" || item.value.kind === "menu" && item.value.trigger === "disclosure");
|
|
49
|
+
|
|
50
|
+
/** @param event - Choice from the sheet's rows; checkable rows keep the sheet open. */
|
|
51
|
+
function choose(event: QuireKitToolbarExecuteEvent): void {
|
|
52
|
+
emit("select", event.value, event.nativeEvent);
|
|
53
|
+
if (toolbarSheetClosesOn(item.value.items ?? [], event.value)) emit("update:expanded", false);
|
|
54
|
+
}
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<template>
|
|
58
|
+
<QuireTaskPanel :open="scope.expanded" :title="item.label" presentation="bottom" max-height="72dvh" :anchor-el="trigger"
|
|
59
|
+
:portal-target="item.overlayProps?.portalTarget ?? 'body'" :restore-focus="item.overlayProps?.restoreFocus ?? true"
|
|
60
|
+
@update:open="emit('update:expanded', $event)">
|
|
61
|
+
<template #trigger="task">
|
|
62
|
+
<QuireToolbarDisclosure v-if="disclosure" v-bind="{ ...common, ...text }" :label="item.label" :data-qk-toolbar-sheet="marker" :toggle-on-click="false" popup="dialog"
|
|
63
|
+
:indicator="item.indicator ?? item.kind === 'menu'" :expanded="task.open">
|
|
64
|
+
<template v-if="hasIcon" #default><QuireIcon :name="item.icon" :data="item.iconData" :accent-color="item.iconAccentColor" :empty="item.iconEmpty" /></template>
|
|
65
|
+
</QuireToolbarDisclosure>
|
|
66
|
+
<QuireToolbarSelector v-else v-bind="common" :label="item.label" :data-qk-toolbar-sheet="marker" :toggle-on-click="false" popup="dialog" :text="item.text ?? item.label" :expanded="task.open">
|
|
67
|
+
<template v-if="hasIcon" #default><QuireIcon :name="item.icon" :data="item.iconData" :accent-color="item.iconAccentColor" :empty="item.iconEmpty" /></template>
|
|
68
|
+
</QuireToolbarSelector>
|
|
69
|
+
</template>
|
|
70
|
+
<QuireToolbar v-if="rows !== undefined" :label="item.label" :items="rows" mode="mobile" orientation="vertical" overflow="visible" align="start"
|
|
71
|
+
class="qk-toolbar--overflow-sheet" @execute="choose" />
|
|
72
|
+
<template v-else-if="scope.expanded">
|
|
73
|
+
<component v-if="item.contentRenderer && renderers[item.contentRenderer]" :is="renderers[item.contentRenderer]" :scope="scope" />
|
|
74
|
+
<slot v-else name="content" v-bind="scope" />
|
|
75
|
+
</template>
|
|
76
|
+
<template #footer><QuireButton variant="text" class="qk-task__target w-full" @click="emit('update:expanded', false)">{{ cancelText.cancel }}</QuireButton></template>
|
|
77
|
+
</QuireTaskPanel>
|
|
78
|
+
</template>
|
|
@@ -79,3 +79,17 @@ it("an open mobile overflow retains a custom draft and its shell through a mode
|
|
|
79
79
|
expect(document.querySelector('[aria-label="Note draft"]')).toBe(input); expect(input.value).toBe("Unsaved draft");
|
|
80
80
|
expect(input.closest('.qk-drawer__content')).not.toBeNull(); expect(document.activeElement).toBe(input);
|
|
81
81
|
});
|
|
82
|
+
|
|
83
|
+
it("leaves desktop-only entries out of mobile items and rows and restores them on desktop", async () => {
|
|
84
|
+
const mode = ref("mobile" as "mobile" | "desktop");
|
|
85
|
+
const settings = { value: "settings", label: "Settings", mobile: false };
|
|
86
|
+
const host = mount(() => h("div", [
|
|
87
|
+
h(Toolbar, { label: "Items", mode: mode.value, overflow: "visible", items: [{ value: "bold", label: "Bold" }, { value: "group", label: "Group", kind: "group", children: [{ value: "italic", label: "Italic" }, settings] }] }),
|
|
88
|
+
h(Toolbar, { label: "Rows", mode: mode.value, rows: [{ value: "row", label: "Row", items: [{ value: "center", label: "Center" }, settings] }] })
|
|
89
|
+
]));
|
|
90
|
+
await nextTick();
|
|
91
|
+
const labels = () => [...host.querySelectorAll("[data-qk-toolbar-item]")].map(button => button.getAttribute("aria-label"));
|
|
92
|
+
expect(labels()).toEqual(["Bold", "Italic", "Center"]);
|
|
93
|
+
mode.value = "desktop"; await nextTick();
|
|
94
|
+
expect(labels()).toEqual(["Bold", "Italic", "Settings", "Center", "Settings"]);
|
|
95
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { QuireKitToolbarEntry, QuireKitToolbarRow } from "../../../components/toolbar/types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Leaves out entries marked desktop-only while the Toolbar presents touch controls.
|
|
5
|
+
* @param entries - Configured entries, including group children.
|
|
6
|
+
* @param mobile - Whether the Toolbar is in mobile mode.
|
|
7
|
+
* @returns The configured array when nothing is left out, otherwise the shown entries.
|
|
8
|
+
*/
|
|
9
|
+
export function shownToolbarEntries(entries: readonly QuireKitToolbarEntry[], mobile: boolean): readonly QuireKitToolbarEntry[] {
|
|
10
|
+
if (!mobile) return entries;
|
|
11
|
+
let changed = false;
|
|
12
|
+
const shown: QuireKitToolbarEntry[] = [];
|
|
13
|
+
for (const entry of entries) {
|
|
14
|
+
if (entry.mobile === false) { changed = true; continue; }
|
|
15
|
+
const children = entry.children === undefined ? undefined : shownToolbarEntries(entry.children, true);
|
|
16
|
+
if (children !== entry.children) changed = true;
|
|
17
|
+
shown.push(children === entry.children ? entry : { ...entry, children: children ?? [] });
|
|
18
|
+
}
|
|
19
|
+
return changed ? shown : entries;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Applies {@link shownToolbarEntries} to every row.
|
|
24
|
+
* @param rows - Configured rows.
|
|
25
|
+
* @param mobile - Whether the Toolbar is in mobile mode.
|
|
26
|
+
* @returns The configured rows when nothing is left out, otherwise rows with their shown entries.
|
|
27
|
+
*/
|
|
28
|
+
export function shownToolbarRows(rows: readonly QuireKitToolbarRow[], mobile: boolean): readonly QuireKitToolbarRow[] {
|
|
29
|
+
if (!mobile) return rows;
|
|
30
|
+
let changed = false;
|
|
31
|
+
const shown = rows.map(row => {
|
|
32
|
+
const items = shownToolbarEntries(row.items, true);
|
|
33
|
+
if (items === row.items) return row;
|
|
34
|
+
changed = true;
|
|
35
|
+
return { ...row, items };
|
|
36
|
+
});
|
|
37
|
+
return changed ? shown : rows;
|
|
38
|
+
}
|
|
@@ -37,6 +37,8 @@ it("keeps optional primary toggle state separate from disclosure and single exec
|
|
|
37
37
|
await nextTick();
|
|
38
38
|
expect(primary.getAttribute("aria-pressed")).toBe(String(pressed));
|
|
39
39
|
expect(disclosure.hasAttribute("aria-pressed")).toBe(false);
|
|
40
|
+
// The whole button shows the pressed state, not only its action half.
|
|
41
|
+
expect(primary.closest(".qk-toolbar__split")!.hasAttribute("data-pressed")).toBe(pressed !== false);
|
|
40
42
|
}
|
|
41
43
|
primary.focus();
|
|
42
44
|
primary.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowRight", bubbles: true }));
|
|
@@ -141,6 +141,7 @@ function handleDisclosure(next: boolean): void {
|
|
|
141
141
|
role="group"
|
|
142
142
|
:aria-label="label"
|
|
143
143
|
:data-state="expanded ? 'open' : 'closed'"
|
|
144
|
+
:data-pressed="pressed === true || pressed === 'mixed' ? '' : undefined"
|
|
144
145
|
class="qk-toolbar__split"
|
|
145
146
|
data-kind="split-button"
|
|
146
147
|
>
|