@quirekit/ui 0.0.2 → 0.1.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-TxH_u9wJ.mjs} +318 -276
- package/dist/catalog-TxH_u9wJ.mjs.map +1 -0
- package/dist/{chat-DaOlDJNQ.mjs → chat-CDuOfk3d.mjs} +225 -144
- package/dist/chat-CDuOfk3d.mjs.map +1 -0
- package/dist/chat.d.mts +2 -2
- package/dist/chat.mjs +1 -1
- package/dist/{code-block-D1kd-gAB.mjs → code-block-5fEEwwMN.mjs} +3 -3
- package/dist/{code-block-D1kd-gAB.mjs.map → code-block-5fEEwwMN.mjs.map} +1 -1
- package/dist/{html-sandbox-BYIni0q6.mjs → html-sandbox-BJeg9mHs.mjs} +2 -2
- package/dist/{html-sandbox-BYIni0q6.mjs.map → html-sandbox-BJeg9mHs.mjs.map} +1 -1
- package/dist/html-sandbox.mjs +1 -1
- package/dist/{index-Bf9CudSF.d.mts → index-BOSlg0Xl.d.mts} +212 -142
- package/dist/index-BOSlg0Xl.d.mts.map +1 -0
- package/dist/{index-DZc5z5s2.d.mts → index-CtgUjd_A.d.mts} +3 -2
- package/dist/index-CtgUjd_A.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-DvNHVLwg.mjs} +3 -3
- package/dist/{model-D4-FbKXY.mjs.map → model-DvNHVLwg.mjs.map} +1 -1
- package/dist/{resolve-BwTfY4PS.mjs → resolve-DlCNcx0Q.mjs} +2 -2
- package/dist/{resolve-BwTfY4PS.mjs.map → resolve-DlCNcx0Q.mjs.map} +1 -1
- package/dist/vue.d.mts +492 -441
- package/dist/vue.d.mts.map +1 -1
- package/dist/vue.mjs +3295 -2837
- 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/edit-bar/index.ts +1 -0
- package/src/components/edit-bar/types.ts +24 -0
- package/src/components/icon/custom/indicators.ts +1 -0
- package/src/components/icon/custom/insert.ts +3 -1
- package/src/components/icon/metadata.ts +12 -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 +3 -0
- package/src/locale/components/icon-catalog/zh-hans.ts +3 -0
- 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/code-block/theme-surface.vue +4 -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/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/file-upload/file-upload.vue +1 -1
- package/src/vue/image-preview/theme-surface.vue +4 -1
- 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/prose/mapping/native.ts +1 -1
- package/src/vue/prose/mapping/rich.ts +2 -1
- package/src/vue/schema-form/controls/registry.ts +1 -1
- package/src/vue/schema-form/tree.ts +1 -1
- package/src/vue/shared/task/trigger.vue +1 -1
- package/src/vue/splitter/splitter.test.ts +18 -0
- package/src/vue/splitter/splitter.vue +5 -2
- package/src/vue/tags-input/tags-input.vue +1 -1
- package/src/vue/task-panel/root.vue +0 -8
- package/src/vue/theme-provider/portal.vue +4 -1
- package/src/vue/theme-provider/surface.vue +4 -1
- package/src/vue/toolbar/context.ts +5 -2
- package/src/vue/toolbar/items/control.vue +9 -1
- 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.vue +8 -3
- package/src/vue/toolbar/types.ts +3 -1
- package/dist/catalog-AqWLE58Z.mjs.map +0 -1
- package/dist/chat-DaOlDJNQ.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
|
@@ -7,7 +7,8 @@ const styles = Object.freeze({
|
|
|
7
7
|
dark: Object.freeze({ ...previewColors.dark, display: "contents" })
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
-
export default
|
|
10
|
+
// The SFC compiler drops an annotation on `export default`, so the pure call is on its own declaration.
|
|
11
|
+
const ImagePreviewThemeSurface = /* @__PURE__ */ defineComponent({
|
|
11
12
|
name: "QuireImagePreviewThemeSurface",
|
|
12
13
|
inheritAttrs: false,
|
|
13
14
|
props: {
|
|
@@ -24,4 +25,6 @@ export default defineComponent({
|
|
|
24
25
|
return () => h("div", { style: styles[props.scheme] }, context.slots.default?.());
|
|
25
26
|
}
|
|
26
27
|
});
|
|
28
|
+
|
|
29
|
+
export default ImagePreviewThemeSurface;
|
|
27
30
|
</script>
|
package/src/vue/index.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { createApp, h, nextTick } from "vue";
|
|
3
|
+
import { afterEach, expect, it } from "vitest";
|
|
4
|
+
import Menu from "../menu.vue";
|
|
5
|
+
|
|
6
|
+
const cleanups: Array<() => void> = [];
|
|
7
|
+
afterEach(() => cleanups.splice(0).forEach(cleanup => cleanup()));
|
|
8
|
+
|
|
9
|
+
it("keeps the disclosure mark on a disabled submenu so it does not read as a label", async () => {
|
|
10
|
+
const host = document.createElement("div");
|
|
11
|
+
document.body.append(host);
|
|
12
|
+
const app = createApp({ render: () => h(Menu, { defaultOpen: true, portalled: false, items: [
|
|
13
|
+
{ value: "layers", label: "层级", kind: "submenu", disabled: true, children: [{ value: "front", label: "置于顶层" }] },
|
|
14
|
+
{ value: "layout", label: "自动布局", kind: "submenu", children: [{ value: "down", label: "从上到下" }] },
|
|
15
|
+
] }, { trigger: () => h("button", { type: "button" }, "排列") }) });
|
|
16
|
+
app.mount(host);
|
|
17
|
+
cleanups.push(() => { app.unmount(); host.remove(); });
|
|
18
|
+
await nextTick(); await nextTick();
|
|
19
|
+
const rows = [...host.querySelectorAll<HTMLElement>(".qk-menu__item")];
|
|
20
|
+
const disabled = rows.find(row => row.textContent?.includes("层级"))!;
|
|
21
|
+
expect(disabled.hasAttribute("data-disabled")).toBe(true);
|
|
22
|
+
expect(disabled.querySelector(".qk-menu__disclosure")).not.toBeNull();
|
|
23
|
+
expect(rows.find(row => row.textContent?.includes("自动布局"))!.querySelector(".qk-menu__disclosure")).not.toBeNull();
|
|
24
|
+
});
|
|
@@ -3,6 +3,8 @@ import { createApp, h, nextTick, ref } from "vue";
|
|
|
3
3
|
import { LocaleProvider } from "@ark-ui/vue/locale";
|
|
4
4
|
import { expect, it } from "vitest";
|
|
5
5
|
import Menu from "../menu.vue";
|
|
6
|
+
import Group from "../menu-group.vue";
|
|
7
|
+
import Item from "../menu-item.vue";
|
|
6
8
|
import Items from "./items.vue";
|
|
7
9
|
|
|
8
10
|
it.each(["en-US", "ar-AE"])("keeps option icons separate from one trailing check in %s", async locale => {
|
|
@@ -107,3 +109,30 @@ it("accepts live root items, forwards one action, and applies disabled updates",
|
|
|
107
109
|
expect(selected).toEqual(["copy"]);
|
|
108
110
|
} finally { app.unmount(); host.remove(); }
|
|
109
111
|
});
|
|
112
|
+
|
|
113
|
+
it("lays out a group label with a leading mark and a trailing status", async () => {
|
|
114
|
+
const host = document.createElement("div"); document.body.append(host);
|
|
115
|
+
const app = createApp({ render: () => h(Menu, { defaultOpen: true, portalled: false }, {
|
|
116
|
+
trigger: () => h("button", "Source"),
|
|
117
|
+
default: () => [
|
|
118
|
+
h(Group, { label: "Claude" }, {
|
|
119
|
+
leading: () => h("span", { class: "mark" }, "C"),
|
|
120
|
+
trailing: () => "Signed in",
|
|
121
|
+
default: () => h(Item, { value: "sonnet" }, () => "Sonnet")
|
|
122
|
+
}),
|
|
123
|
+
h(Group, { label: "Plain" }, { default: () => h(Item, { value: "other" }, () => "Other") })
|
|
124
|
+
]
|
|
125
|
+
}) });
|
|
126
|
+
try {
|
|
127
|
+
app.mount(host);
|
|
128
|
+
await nextTick();
|
|
129
|
+
const [rich, plain] = [...host.querySelectorAll(".qk-menu__group-label")];
|
|
130
|
+
expect(rich?.classList.contains("qk-menu__group-label--slotted")).toBe(true);
|
|
131
|
+
expect(rich?.querySelector(".qk-menu__group-leading")?.getAttribute("aria-hidden")).toBe("true");
|
|
132
|
+
expect(rich?.querySelector(".qk-menu__group-text")?.textContent).toBe("Claude");
|
|
133
|
+
expect(rich?.querySelector(".qk-menu__trailing")?.textContent).toBe("Signed in");
|
|
134
|
+
expect(plain?.classList.contains("qk-menu__group-label--slotted")).toBe(false);
|
|
135
|
+
expect(plain?.textContent?.trim()).toBe("Plain");
|
|
136
|
+
expect(plain?.children.length).toBe(0);
|
|
137
|
+
} finally { app.unmount(); host.remove(); }
|
|
138
|
+
});
|
|
@@ -43,6 +43,12 @@ const emit = defineEmits<{ /** Enabled leaf activation, once per request. */ sel
|
|
|
43
43
|
<template v-if="$slots.leading" #leading="scope"><slot name="leading" v-bind="scope" /></template>
|
|
44
44
|
</QuireMenuItems>
|
|
45
45
|
</QuireMenuSubmenu>
|
|
46
|
+
<!-- A disabled submenu keeps its disclosure mark so it still reads as a submenu, not as a dead label. -->
|
|
47
|
+
<QuireMenuItem v-else-if="item.kind === 'submenu'" :inset="items.some(entry => !!entry.icon)" :value="item.value" disabled :tone="item.tone ?? 'neutral'" :title="item.reason">
|
|
48
|
+
<template v-if="$slots.leading || item.icon" #leading><slot name="leading" :item="item"><QuireIcon v-if="item.icon" :name="item.icon" /></slot></template>
|
|
49
|
+
{{ item.label }}
|
|
50
|
+
<template #trailing><span class="qk-menu__disclosure"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="m6 3.5 4.5 4.5L6 12.5" /></svg></span></template>
|
|
51
|
+
</QuireMenuItem>
|
|
46
52
|
<QuireMenuRadioGroup v-else-if="item.kind === 'radio-group'" :label="item.label" :model-value="item.selectedValue ?? ''" @update:model-value="emit('select', $event)">
|
|
47
53
|
<QuireMenuRadioItem v-for="option in item.children ?? []" :key="option.value" :value="option.value" :disabled="item.disabled || option.disabled || false" :shortcut="option.shortcut ?? ''" :close-on-select="option.closeOnSelect ?? false"
|
|
48
54
|
:inset="(item.children ?? []).some(entry => !!entry.icon)" :title="option.reason">
|
|
@@ -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>
|
|
@@ -7,7 +7,7 @@ import { QuireProseImg, QuireProseFigure, QuireProseFigcaption } from "../media"
|
|
|
7
7
|
import type { QuireKitProseComponentMap } from "../types";
|
|
8
8
|
|
|
9
9
|
/** Immutable native tag defaults. Spread into the host renderer map before applying local overrides. */
|
|
10
|
-
export const quireProseComponents = Object.freeze({
|
|
10
|
+
export const quireProseComponents = /* @__PURE__ */ Object.freeze({
|
|
11
11
|
h1: QuireProseH1,
|
|
12
12
|
h2: QuireProseH2,
|
|
13
13
|
h3: QuireProseH3,
|
|
@@ -3,4 +3,5 @@ import { QuireProseImage } from "../image";
|
|
|
3
3
|
import { QuireProseSource } from "../source";
|
|
4
4
|
|
|
5
5
|
/** QuireKit reading defaults: interactive images and full code display, with every other native element retained. */
|
|
6
|
-
|
|
6
|
+
// A spread counts as a side effect for bundlers, so it sits inside a pure call that can be dropped when unused.
|
|
7
|
+
export const quireRichProseComponents = /* @__PURE__ */ (() => Object.freeze({ ...quireProseComponents, img: QuireProseImage, pre: QuireProseSource }))();
|
|
@@ -12,7 +12,7 @@ import type { QuireKitSchemaRegistry } from "../types";
|
|
|
12
12
|
function textValue(value: unknown): string { return value == null ? "" : String(value); }
|
|
13
13
|
|
|
14
14
|
/** Built-in controls reuse existing QuireKit recipes and headless adapters. */
|
|
15
|
-
export const schemaControls: QuireKitSchemaRegistry = Object.freeze({
|
|
15
|
+
export const schemaControls: QuireKitSchemaRegistry = /* @__PURE__ */ Object.freeze({
|
|
16
16
|
input: { component: Input, toControl: textValue },
|
|
17
17
|
textarea: { component: Textarea, toControl: textValue },
|
|
18
18
|
// NumberInput owns localized strings; numerical payload conversion belongs to the consumer.
|
|
@@ -9,7 +9,7 @@ import type { QuireKitFormFieldSlotProps } from "../form-field/types";
|
|
|
9
9
|
import type { QuireKitSchemaCondition, QuireKitSchemaNode, QuireKitSchemaRegistry } from "./types";
|
|
10
10
|
|
|
11
11
|
/** Internal recursive renderer: identity, conditions and semantic grouping only. */
|
|
12
|
-
export default defineComponent({
|
|
12
|
+
export default /* @__PURE__ */ defineComponent({
|
|
13
13
|
name: "QuireSchemaFields",
|
|
14
14
|
props: {
|
|
15
15
|
nodes: { type: Array as PropType<readonly QuireKitSchemaNode[]>, required: true },
|
|
@@ -94,7 +94,7 @@ function findButton(nodes: readonly VNode[]): VNode | undefined {
|
|
|
94
94
|
|
|
95
95
|
// As-child normally lets child attributes win. This component has no DOM of its
|
|
96
96
|
// own; cloning keeps the original button while making task identity authoritative.
|
|
97
|
-
const SlotButton = defineComponent({
|
|
97
|
+
const SlotButton = /* @__PURE__ */ defineComponent({
|
|
98
98
|
name: "TaskTriggerSlot",
|
|
99
99
|
inheritAttrs: false,
|
|
100
100
|
setup(_props, { attrs }) {
|
|
@@ -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>
|
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
} from "./context";
|
|
10
10
|
import QuireThemeSurface from "./surface.vue";
|
|
11
11
|
|
|
12
|
-
export default
|
|
12
|
+
// The SFC compiler drops an annotation on `export default`, so the pure call is on its own declaration.
|
|
13
|
+
const ThemePortal = /* @__PURE__ */ defineComponent({
|
|
13
14
|
name: "QuireThemePortal",
|
|
14
15
|
inheritAttrs: false,
|
|
15
16
|
/**
|
|
@@ -33,4 +34,6 @@ export default defineComponent({
|
|
|
33
34
|
: h(QuireThemeSurface, { layout: "bridge" }, context.slots);
|
|
34
35
|
},
|
|
35
36
|
});
|
|
37
|
+
|
|
38
|
+
export default ThemePortal;
|
|
36
39
|
</script>
|
|
@@ -4,7 +4,8 @@ import { trackQuireKitInputModality } from "../../components/control/modality";
|
|
|
4
4
|
import { quireKitThemeKey } from "./context";
|
|
5
5
|
import { resolveThemeSurfaceStyle } from "./styles";
|
|
6
6
|
|
|
7
|
-
export default
|
|
7
|
+
// The SFC compiler drops an annotation on `export default`, so the pure call is on its own declaration.
|
|
8
|
+
const ThemeSurface = /* @__PURE__ */ defineComponent({
|
|
8
9
|
name: "QuireThemeSurface",
|
|
9
10
|
inheritAttrs: false,
|
|
10
11
|
props: {
|
|
@@ -33,4 +34,6 @@ export default defineComponent({
|
|
|
33
34
|
}, context.slots.default?.()) : context.slots.default?.();
|
|
34
35
|
},
|
|
35
36
|
});
|
|
37
|
+
|
|
38
|
+
export default ThemeSurface;
|
|
36
39
|
</script>
|
|
@@ -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>>;
|
|
@@ -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,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
|
+
}
|