dou-ui 0.1.0-alpha.12 → 0.1.0-alpha.13
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/components/button/button.js.map +1 -1
- package/dist/components/button/button.vue_vue_type_script_setup_true_lang.js +29 -17
- package/dist/components/button/button.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-input/chat-input.vue_vue_type_script_setup_true_lang.js +8 -1
- package/dist/components/chat-input/chat-input.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/chat-input/chat-input2.js.map +1 -1
- package/dist/components/check-tag/check-tag.vue_vue_type_script_setup_true_lang.js +8 -5
- package/dist/components/check-tag/check-tag.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/check-tag/check-tag2.js.map +1 -1
- package/dist/components/command/command-dialog.js.map +1 -1
- package/dist/components/command/command-dialog.vue_vue_type_script_setup_true_lang.js +7 -1
- package/dist/components/command/command-dialog.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/command/command.js.map +1 -1
- package/dist/components/command/command.vue_vue_type_script_setup_true_lang.js +65 -12
- package/dist/components/command/command.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/command/command2.js.map +1 -1
- package/dist/components/link/link.js.map +1 -1
- package/dist/components/link/link.vue_vue_type_script_setup_true_lang.js +6 -4
- package/dist/components/link/link.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/menu/menu-actions.js +3 -13
- package/dist/components/menu/menu-actions.js.map +1 -1
- package/dist/components/status-dot/status-dot.vue_vue_type_script_lang.js +3 -11
- package/dist/components/status-dot/status-dot.vue_vue_type_script_lang.js.map +1 -1
- package/dist/components/status-dot/status-dot2.js.map +1 -1
- package/dist/components/tag/tag.js.map +1 -1
- package/dist/components/tag/tag.vue_vue_type_script_setup_true_lang.js +9 -6
- package/dist/components/tag/tag.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/composables/use-grouped-window.js +4 -1
- package/dist/composables/use-grouped-window.js.map +1 -1
- package/dist/composables/use-measured-sizes.js +6 -5
- package/dist/composables/use-measured-sizes.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/components/command/command-dialog.vue.d.ts +1 -0
- package/dist/types/components/command/command.d.ts +7 -1
- package/dist/types/components/command/index.d.ts +3 -0
- package/dist/types/composables/use-grouped-window.d.ts +1 -0
- package/dist/types/composables/use-measured-sizes.d.ts +6 -0
- package/dist/types/utils/slot.d.ts +19 -0
- package/dist/utils/slot.js +36 -0
- package/dist/utils/slot.js.map +1 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.js","names":[],"sources":["../../../src/components/command/command.ts"],"sourcesContent":["export type CommandValue = string | number\n\nexport interface CommandItem {\n /** Unique among the items. */\n value: CommandValue\n /** What the item reads as, and what the search matches first. */\n label: string\n /** Items with the same group are listed together under its name. */\n group?: string\n /** A quieter line after the label; also searched. */\n description?: string\n /** Other words that should find this item, e.g. synonyms. */\n keywords?: string[]\n /**\n * A hotkey in `useHotkey` syntax shown at the end, e.g. `mod+k`, with this\n * platform's key names. Only shown, not bound.\n */\n shortcut?: string\n disabled?: boolean\n [extra: string]: unknown\n}\n\n/** How well an item matched, with the positions in its label to pick out. */\nexport interface CommandMatch {\n score: number\n indices: number[]\n}\n\nexport interface CommandProps {\n items: CommandItem[]\n /** The search text, bound with `v-model:query`. */\n query?: string\n placeholder?: string\n /** Shown when nothing matches. Defaults to the locale's. */\n emptyText?: string\n /**\n * Scores an item against the query; `null` hides it. Defaults to a\n * fuzzy match: the letters in order, ranked by how close together and\n * how near word starts they fall.\n */\n filter?: (query: string, item: CommandItem) => CommandMatch | null\n /** Wrap from the last item to the first with the arrow keys. */\n loop?: boolean\n /** The height the list scrolls past. A number is in px. */\n maxHeight?: number | string\n /**\n * Render only the items in view. By default this turns on by itself past\n * 100 items
|
|
1
|
+
{"version":3,"file":"command.js","names":[],"sources":["../../../src/components/command/command.ts"],"sourcesContent":["export type CommandValue = string | number\n\nexport interface CommandItem {\n /** Unique among the items. */\n value: CommandValue\n /** What the item reads as, and what the search matches first. */\n label: string\n /** Items with the same group are listed together under its name. */\n group?: string\n /** A quieter line after the label; also searched. */\n description?: string\n /** Other words that should find this item, e.g. synonyms. */\n keywords?: string[]\n /**\n * A hotkey in `useHotkey` syntax shown at the end, e.g. `mod+k`, with this\n * platform's key names. Only shown, not bound.\n */\n shortcut?: string\n disabled?: boolean\n [extra: string]: unknown\n}\n\n/** How well an item matched, with the positions in its label to pick out. */\nexport interface CommandMatch {\n score: number\n indices: number[]\n}\n\nexport interface CommandProps {\n items: CommandItem[]\n /** The search text, bound with `v-model:query`. */\n query?: string\n placeholder?: string\n /** Shown when nothing matches. Defaults to the locale's. */\n emptyText?: string\n /**\n * Scores an item against the query; `null` hides it. Defaults to a\n * fuzzy match: the letters in order, ranked by how close together and\n * how near word starts they fall.\n */\n filter?: (query: string, item: CommandItem) => CommandMatch | null\n /** Wrap from the last item to the first with the arrow keys. */\n loop?: boolean\n /** The height the list scrolls past. A number is in px. */\n maxHeight?: number | string\n /**\n * Render only the items in view. By default this turns on by itself past\n * 100 items.\n */\n virtual?: boolean\n /**\n * The height of a row in px while `virtual` is on, or a function giving\n * each item's. Rows are exactly this tall then. Left out, rows grow to\n * fit and are measured once rendered. Unused with `virtual` off.\n */\n itemSize?: number | ((item: CommandItem) => number)\n /** Names the search box when there is no visible label. */\n ariaLabel?: string\n}\n\nexport interface CommandEmits {\n 'update:query': [query: string]\n /** An item was chosen with a click or `Enter`. */\n select: [item: CommandItem]\n}\n\nexport interface CommandSlots {\n /** Replaces an item's content. `indices` are the matched positions in its label. */\n item?: (props: { item: CommandItem; active: boolean; indices: number[] }) => unknown\n /** Before the search box, replacing the magnifier. */\n prefix?: () => unknown\n /** Shown when nothing matches. */\n empty?: () => unknown\n /** Under the list, e.g. hints about keys. */\n footer?: () => unknown\n}\n\nexport interface CommandExpose {\n focus: () => void\n}\n\nexport interface CommandDialogProps extends CommandProps {\n /** Whether the palette is open, bound with `v-model:open`. */\n open?: boolean\n /**\n * A key that opens and closes the palette from anywhere, e.g. `mod+k`;\n * `mod` is `⌘` on Apple systems and `Ctrl` elsewhere. `false` binds none.\n */\n hotkey?: string | false\n /** Close after an item is chosen. */\n closeOnSelect?: boolean\n /** The width of the panel; a number is in px. */\n width?: string | number\n}\n\nexport interface CommandDialogEmits extends CommandEmits {\n 'update:open': [open: boolean]\n}\n\nconst isBoundary = (text: string, index: number) => {\n if (index === 0) return true\n const before = text[index - 1]!\n const here = text[index]!\n return (\n /[\\s\\-_./:]/.test(before) || (before === before.toLowerCase() && here !== here.toLowerCase())\n )\n}\n\n/**\n * Match `query` against `text` as a subsequence, ignoring case. Letters\n * that follow each other, sit at the start of a word, or begin the text\n * score higher; a plain substring scores highest of all.\n */\nexport function fuzzyMatch(text: string, query: string): CommandMatch | null {\n const needle = query.trim().toLowerCase()\n if (!needle) return { score: 0, indices: [] }\n const haystack = text.toLowerCase()\n\n const at = haystack.indexOf(needle)\n if (at >= 0) {\n const indices = Array.from({ length: needle.length }, (_, offset) => at + offset)\n return { score: 100 + (at === 0 ? 20 : isBoundary(text, at) ? 10 : 0) - at * 0.1, indices }\n }\n\n const indices: number[] = []\n let score = 0\n let from = 0\n for (const char of needle) {\n if (char === ' ') continue\n const index = haystack.indexOf(char, from)\n if (index < 0) return null\n score += 1\n if (indices.length && index === indices.at(-1)! + 1) score += 5\n if (isBoundary(text, index)) score += 8\n indices.push(index)\n from = index + 1\n }\n return { score: score - (indices[0] ?? 0) * 0.1, indices }\n}\n\n/** The default `filter`: the label first, then the description and keywords. */\nexport function matchCommand(query: string, item: CommandItem): CommandMatch | null {\n const label = fuzzyMatch(item.label, query)\n if (label) return label\n for (const extra of [item.description, ...(item.keywords ?? [])]) {\n const match = extra ? fuzzyMatch(extra, query) : null\n if (match) return { score: match.score / 2, indices: [] }\n }\n return null\n}\n"],"mappings":";AAmGA,IAAM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,CAAC,CAAE,GAAG;EAChE,MAAM,QAAQ,QAAQ,WAAW,OAAO,KAAK,IAAI;EACjD,IAAI,OAAO,OAAO;GAAE,OAAO,MAAM,QAAQ;GAAG,SAAS,CAAC;EAAE;CAC1D;CACA,OAAO;AACT"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { useNamespace } from "../../utils/namespace.js";
|
|
2
2
|
import { useLocale } from "../config-provider/use-config.js";
|
|
3
|
+
import { devWarn } from "../../utils/status-check.js";
|
|
3
4
|
import { isComposing } from "../../utils/keyboard.js";
|
|
4
5
|
import { ariaHotkey, useApplePlatform } from "../../composables/use-hotkey.js";
|
|
6
|
+
import { useMeasuredSizes } from "../../composables/use-measured-sizes.js";
|
|
5
7
|
import { DouKbd } from "../kbd/index.js";
|
|
6
8
|
import { useGroupedWindow } from "../../composables/use-grouped-window.js";
|
|
7
9
|
import { matchCommand } from "./command.js";
|
|
8
|
-
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, mergeModels, nextTick, normalizeClass, normalizeProps, normalizeStyle, openBlock, ref, renderList, renderSlot, toDisplayString, unref, useId, useModel, useSlots, useTemplateRef, vModelText, watch, withDirectives, withModifiers } from "vue";
|
|
10
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, mergeModels, nextTick, normalizeClass, normalizeProps, normalizeStyle, onUpdated, openBlock, ref, renderList, renderSlot, toDisplayString, unref, useId, useModel, useSlots, useTemplateRef, vModelText, watch, withDirectives, withModifiers } from "vue";
|
|
9
11
|
import { SearchIcon } from "@dou-ui/icons";
|
|
10
12
|
// src/components/command/command.vue?vue&type=script&setup=true&lang.ts
|
|
11
13
|
var _hoisted_1 = [
|
|
@@ -44,6 +46,7 @@ var command_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCo
|
|
|
44
46
|
type: Boolean,
|
|
45
47
|
default: void 0
|
|
46
48
|
},
|
|
49
|
+
itemSize: {},
|
|
47
50
|
ariaLabel: {}
|
|
48
51
|
}, {
|
|
49
52
|
"query": { default: "" },
|
|
@@ -118,10 +121,28 @@ var command_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCo
|
|
|
118
121
|
first();
|
|
119
122
|
}, { immediate: true });
|
|
120
123
|
const listRef = useTemplateRef("list");
|
|
124
|
+
const fixed = computed(() => props.itemSize !== void 0);
|
|
125
|
+
function fixedSize(item) {
|
|
126
|
+
const size = props.itemSize;
|
|
127
|
+
return typeof size === "function" ? size(item) : size;
|
|
128
|
+
}
|
|
129
|
+
/** Each item's group and place in it, by its index in the flat list. */
|
|
130
|
+
const places = computed(() => groups.value.flatMap((group, at) => group.entries.map((_, index) => [at, index])));
|
|
131
|
+
let estimate;
|
|
132
|
+
const measured = useMeasuredSizes({
|
|
133
|
+
count: () => flat.value.length,
|
|
134
|
+
keyOf: (index) => flat.value[index].item.value,
|
|
135
|
+
estimate: () => estimate ?? 36,
|
|
136
|
+
container: () => listRef.value,
|
|
137
|
+
start: (index) => windowing.startOf(...places.value[index])
|
|
138
|
+
});
|
|
121
139
|
const windowing = useGroupedWindow({
|
|
122
140
|
container: () => listRef.value,
|
|
123
141
|
sizes: () => groups.value.map((group) => group.entries.length),
|
|
124
|
-
itemSize: () =>
|
|
142
|
+
itemSize: (group, index) => {
|
|
143
|
+
const entry = groups.value[group].entries[index];
|
|
144
|
+
return fixedSize(entry.item) ?? measured.sizeOf(entry.index);
|
|
145
|
+
},
|
|
125
146
|
virtual: () => props.virtual
|
|
126
147
|
});
|
|
127
148
|
const groupWindows = computed(() => groups.value.map((group, at) => {
|
|
@@ -134,19 +155,41 @@ var command_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCo
|
|
|
134
155
|
watch(flatKey, () => {
|
|
135
156
|
if (listRef.value) listRef.value.scrollTop = 0;
|
|
136
157
|
});
|
|
137
|
-
watch(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
158
|
+
watch(() => props.items, () => estimate = void 0);
|
|
159
|
+
function trackRow(el, entry) {
|
|
160
|
+
if (windowing.enabled.value && !fixed.value) measured.track(el, entry.item.value, entry.index);
|
|
161
|
+
}
|
|
162
|
+
onUpdated(() => {
|
|
163
|
+
measured.prune();
|
|
164
|
+
if (!windowing.enabled.value || !listRef.value) return;
|
|
165
|
+
const rows = listRef.value.querySelectorAll("[role=\"option\"]");
|
|
166
|
+
if (!fixed.value) {
|
|
167
|
+
if (estimate === void 0) {
|
|
168
|
+
let sum = 0;
|
|
169
|
+
for (const row of rows) sum += row.offsetHeight;
|
|
170
|
+
if (sum) estimate = sum / rows.length;
|
|
146
171
|
}
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (process.env.NODE_ENV !== "production") for (const row of rows) {
|
|
175
|
+
if (row.scrollHeight <= row.clientHeight + 1) continue;
|
|
176
|
+
return devWarn("[dou-ui] DouCommand: an item is taller than `itemSize`. Pass a larger `itemSize`, or leave it out to have rows measured.");
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
async function reveal(index, settle) {
|
|
180
|
+
if (windowing.enabled.value) {
|
|
181
|
+
const place = places.value[index];
|
|
182
|
+
if (place) windowing.scrollToItem(...place);
|
|
147
183
|
}
|
|
148
184
|
await nextTick();
|
|
185
|
+
if (index !== active.value) return;
|
|
149
186
|
listRef.value?.querySelector(`#${CSS.escape(optionId(index))}`)?.scrollIntoView?.({ block: "nearest" });
|
|
187
|
+
if (settle > 0 && windowing.enabled.value && !fixed.value) {
|
|
188
|
+
if (typeof requestAnimationFrame !== "undefined") requestAnimationFrame(() => index === active.value && void reveal(index, settle - 1));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
watch(active, (index) => {
|
|
192
|
+
if (index >= 0) reveal(index, 3);
|
|
150
193
|
});
|
|
151
194
|
function choose(index) {
|
|
152
195
|
if (!enabled(index)) return;
|
|
@@ -190,6 +233,13 @@ var command_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCo
|
|
|
190
233
|
}
|
|
191
234
|
return result;
|
|
192
235
|
}
|
|
236
|
+
function rowStyle(entry) {
|
|
237
|
+
const size = windowing.enabled.value ? fixedSize(entry.item) : void 0;
|
|
238
|
+
return size === void 0 ? void 0 : {
|
|
239
|
+
height: `${size}px`,
|
|
240
|
+
minHeight: `${size}px`
|
|
241
|
+
};
|
|
242
|
+
}
|
|
193
243
|
const inputRef = useTemplateRef("input");
|
|
194
244
|
__expose({ focus: () => inputRef.value?.focus() });
|
|
195
245
|
const maxHeight = computed(() => typeof props.maxHeight === "number" ? `${props.maxHeight}px` : props.maxHeight);
|
|
@@ -255,6 +305,9 @@ var command_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCo
|
|
|
255
305
|
unref(ns).is("active", entry.index === active.value),
|
|
256
306
|
unref(ns).is("disabled", !!entry.item.disabled)
|
|
257
307
|
]),
|
|
308
|
+
ref_for: true,
|
|
309
|
+
ref: (el) => trackRow(el, entry),
|
|
310
|
+
style: normalizeStyle(rowStyle(entry)),
|
|
258
311
|
onMousedown: _cache[1] || (_cache[1] = withModifiers(() => {}, ["prevent"])),
|
|
259
312
|
onClick: ($event) => choose(entry.index),
|
|
260
313
|
onMousemove: ($event) => enabled(entry.index) && (active.value = entry.index)
|
|
@@ -279,7 +332,7 @@ var command_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCo
|
|
|
279
332
|
size: "sm",
|
|
280
333
|
keys: entry.item.shortcut
|
|
281
334
|
}, null, 8, ["class", "keys"])) : createCommentVNode("", true)
|
|
282
|
-
])],
|
|
335
|
+
])], 46, _hoisted_5);
|
|
283
336
|
}), 128)),
|
|
284
337
|
unref(windowing).enabled.value && groupWindows.value[groupIndex].after ? (openBlock(), createElementBlock("div", {
|
|
285
338
|
key: 2,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.vue_vue_type_script_setup_true_lang.js","names":["_useModel","_useSlots","_openBlock","_createElementBlock","_normalizeClass","_unref","_createElementVNode","_renderSlot","_createVNode","_withDirectives","_vModelText","_normalizeStyle","_Fragment","_renderList","_toDisplayString","_createCommentVNode","_normalizeProps","_withModifiers","_createTextVNode","_createBlock"],"sources":["../../../src/components/command/command.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { SearchIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, useId, useTemplateRef, watch } from 'vue'\nimport { GROUP_START, useGroupedWindow } from '../../composables/use-grouped-window'\nimport { ariaHotkey, useApplePlatform } from '../../composables/use-hotkey'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouKbd } from '../kbd'\nimport { matchCommand } from './command'\nimport type { CommandExpose, CommandItem, CommandProps, CommandSlots } from './command'\n\ndefineOptions({ name: 'DouCommand' })\n\nconst props = withDefaults(defineProps<CommandProps>(), {\n loop: true,\n maxHeight: 320,\n virtual: undefined,\n})\nconst query = defineModel<string>('query', { default: '' })\nconst emit = defineEmits<{ select: [item: CommandItem] }>()\nconst slots = defineSlots<CommandSlots>()\n\nconst ns = useNamespace('command')\nconst apple = useApplePlatform()\nconst { t } = useLocale()\nconst id = `dou-command-${useId()}`\nconst listboxId = `${id}-list`\nconst optionId = (index: number) => `${id}-option-${index}`\n\ninterface Entry {\n item: CommandItem\n indices: number[]\n index: number\n}\ninterface Group {\n name: string | undefined\n entries: Entry[]\n}\n\n// The matching items, best first, gathered under their groups. Without a\n// query the items keep their own order.\nconst groups = computed<Group[]>(() => {\n const text = query.value.trim()\n const filter = props.filter ?? matchCommand\n let matched = props.items.map((item, order) => ({\n item,\n order,\n match: text ? filter(text, item) : { score: 0, indices: [] },\n }))\n if (text) {\n const kept = matched.filter((entry) => entry.match)\n kept.sort((a, b) => b.match!.score - a.match!.score || a.order - b.order)\n matched = kept\n }\n const byName = new Map<string | undefined, Group>()\n for (const { item, match } of matched) {\n let group = byName.get(item.group)\n if (!group) byName.set(item.group, (group = { name: item.group, entries: [] }))\n group.entries.push({ item, indices: match!.indices, index: 0 })\n }\n // Ungrouped items lead, and every entry learns its place in the flat list.\n const named = [...byName.values()].filter((group) => group.name !== undefined)\n const list = byName.has(undefined) ? [byName.get(undefined)!, ...named] : named\n let index = 0\n for (const group of list) for (const entry of group.entries) entry.index = index++\n return list\n})\nconst flat = computed(() => groups.value.flatMap((group) => group.entries))\n\nconst active = ref(-1)\nconst enabled = (index: number) => !!flat.value[index] && !flat.value[index]!.item.disabled\n\nfunction move(from: number, step: 1 | -1) {\n const count = flat.value.length\n for (let offset = 1; offset <= count; offset++) {\n let index = from + step * offset\n if (props.loop) index = ((index % count) + count) % count\n else if (index < 0 || index >= count) return\n if (enabled(index)) {\n active.value = index\n return\n }\n }\n}\nconst first = () => move(-1, 1)\n\n// A parent that re-renders passes a new but equal list: only a different\n// list of items moves the highlight back to the top.\nconst flatKey = computed(() =>\n flat.value.map((entry) => `${typeof entry.item.value}:${entry.item.value}`).join('\\u0000'),\n)\nwatch(\n flatKey,\n () => {\n active.value = -1\n first()\n },\n { immediate: true },\n)\n\nconst listRef = useTemplateRef<HTMLElement>('list')\n\n// Long lists render only the items in view; every item is one row tall.\nconst windowing = useGroupedWindow({\n container: () => listRef.value,\n sizes: () => groups.value.map((group) => group.entries.length),\n itemSize: () => 36,\n virtual: () => props.virtual,\n})\nconst groupWindows = computed(() =>\n groups.value.map((group, at) => {\n const view = windowing.windows.value[at]!\n return { ...view, entries: group.entries.slice(view.from, view.to) }\n }),\n)\nwatch(flatKey, () => {\n if (listRef.value) listRef.value.scrollTop = 0\n})\n\nwatch(active, async (index) => {\n if (windowing.enabled.value && index >= 0) {\n // The item may not be rendered: scroll by its place in its group.\n let at = index\n for (const [group, { entries }] of groups.value.entries()) {\n if (at < entries.length) {\n windowing.scrollToItem(group, at)\n break\n }\n at -= entries.length\n }\n }\n await nextTick()\n listRef.value?.querySelector(`#${CSS.escape(optionId(index))}`)?.scrollIntoView?.({\n block: 'nearest',\n })\n})\n\nfunction choose(index: number) {\n if (!enabled(index)) return\n emit('select', flat.value[index]!.item)\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (isComposing(event)) return\n switch (event.key) {\n case 'ArrowDown':\n event.preventDefault()\n return move(active.value, 1)\n case 'ArrowUp':\n event.preventDefault()\n return move(active.value < 0 ? flat.value.length : active.value, -1)\n case 'Enter':\n event.preventDefault()\n return choose(active.value)\n }\n // Ctrl/⌘ with Home and End leave the caret alone and jump through the list.\n if ((event.ctrlKey || event.metaKey) && (event.key === 'Home' || event.key === 'End')) {\n event.preventDefault()\n if (event.key === 'Home') first()\n else move(flat.value.length, -1)\n }\n}\n\nfunction parts(entry: Entry) {\n const label = entry.item.label\n if (!entry.indices.length) return [{ text: label, match: false }]\n const picked = new Set(entry.indices)\n const result: { text: string; match: boolean }[] = []\n for (let index = 0; index < label.length; index++) {\n const match = picked.has(index)\n const last = result.at(-1)\n if (last && last.match === match) last.text += label[index]\n else result.push({ text: label[index]!, match })\n }\n return result\n}\n\nconst inputRef = useTemplateRef<HTMLInputElement>('input')\ndefineExpose<CommandExpose>({ focus: () => inputRef.value?.focus() })\n\nconst maxHeight = computed(() =>\n typeof props.maxHeight === 'number' ? `${props.maxHeight}px` : props.maxHeight,\n)\n</script>\n\n<template>\n <div :class=\"ns.b()\">\n <div :class=\"ns.e('search')\">\n <span :class=\"ns.e('prefix')\" aria-hidden=\"true\">\n <slot name=\"prefix\">\n <SearchIcon />\n </slot>\n </span>\n <input\n ref=\"input\"\n v-model=\"query\"\n :class=\"ns.e('input')\"\n type=\"text\"\n role=\"combobox\"\n autocomplete=\"off\"\n spellcheck=\"false\"\n aria-autocomplete=\"list\"\n aria-expanded=\"true\"\n :aria-controls=\"listboxId\"\n :aria-activedescendant=\"active >= 0 ? optionId(active) : undefined\"\n :aria-label=\"ariaLabel ?? placeholder ?? t('command.placeholder')\"\n :placeholder=\"placeholder ?? t('command.placeholder')\"\n @keydown=\"onKeydown\"\n />\n </div>\n <div\n :id=\"listboxId\"\n ref=\"list\"\n role=\"listbox\"\n :class=\"ns.e('list')\"\n :style=\"{ maxHeight }\"\n :aria-label=\"ariaLabel ?? placeholder ?? t('command.placeholder')\"\n >\n <div\n v-for=\"(group, groupIndex) in groups\"\n :key=\"group.name ?? ''\"\n role=\"group\"\n :class=\"ns.e('group')\"\n :aria-labelledby=\"group.name ? `${id}-group-${groupIndex}` : undefined\"\n >\n <div\n v-if=\"group.name\"\n :id=\"`${id}-group-${groupIndex}`\"\n :class=\"ns.e('group-label')\"\n aria-hidden=\"true\"\n >\n {{ group.name }}\n </div>\n <div\n v-if=\"windowing.enabled.value\"\n role=\"presentation\"\n :[GROUP_START]=\"''\"\n :style=\"{ height: `${groupWindows[groupIndex]!.before}px` }\"\n />\n <div\n v-for=\"entry in groupWindows[groupIndex]!.entries\"\n :id=\"optionId(entry.index)\"\n :key=\"String(entry.item.value)\"\n role=\"option\"\n :aria-selected=\"entry.index === active\"\n :aria-setsize=\"windowing.enabled.value ? flat.length : undefined\"\n :aria-posinset=\"windowing.enabled.value ? entry.index + 1 : undefined\"\n :aria-disabled=\"entry.item.disabled || undefined\"\n :aria-keyshortcuts=\"\n entry.item.shortcut ? ariaHotkey(entry.item.shortcut, apple) : undefined\n \"\n :class=\"[\n ns.e('item'),\n ns.is('active', entry.index === active),\n ns.is('disabled', !!entry.item.disabled),\n ]\"\n @mousedown.prevent\n @click=\"choose(entry.index)\"\n @mousemove=\"enabled(entry.index) && (active = entry.index)\"\n >\n <slot\n name=\"item\"\n :item=\"entry.item\"\n :active=\"entry.index === active\"\n :indices=\"entry.indices\"\n >\n <span :class=\"ns.e('label')\">\n <template v-for=\"(part, at) in parts(entry)\" :key=\"at\">\n <mark v-if=\"part.match\" :class=\"ns.e('match')\">{{ part.text }}</mark>\n <template v-else>{{ part.text }}</template>\n </template>\n </span>\n <span v-if=\"entry.item.description\" :class=\"ns.e('description')\">\n {{ entry.item.description }}\n </span>\n <DouKbd\n v-if=\"entry.item.shortcut\"\n :class=\"ns.e('shortcut')\"\n size=\"sm\"\n :keys=\"entry.item.shortcut\"\n />\n </slot>\n </div>\n <div\n v-if=\"windowing.enabled.value && groupWindows[groupIndex]!.after\"\n role=\"presentation\"\n :style=\"{ height: `${groupWindows[groupIndex]!.after}px` }\"\n />\n </div>\n <div v-if=\"!flat.length\" :class=\"ns.e('empty')\" role=\"presentation\">\n <slot name=\"empty\">{{ emptyText ?? t('command.empty') }}</slot>\n </div>\n </div>\n <div v-if=\"slots.footer\" :class=\"ns.e('footer')\"><slot name=\"footer\" /></div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAcA,MAAM,QAAQ;EAKd,MAAM,QAAQA,SAAmB,SAAC,OAAwB;EAC1D,MAAM,OAAO;EACb,MAAM,QAAQC,SAAA;EAEd,MAAM,KAAK,aAAa,SAAS;EACjC,MAAM,QAAQ,iBAAiB;EAC/B,MAAM,EAAE,MAAM,UAAU;EACxB,MAAM,KAAK,eAAe,MAAM;EAChC,MAAM,YAAY,GAAG,GAAG;EACxB,MAAM,YAAY,UAAkB,GAAG,GAAG,UAAU;EAcpD,MAAM,SAAS,eAAwB;GACrC,MAAM,OAAO,MAAM,MAAM,KAAK;GAC9B,MAAM,SAAS,MAAM,UAAU;GAC/B,IAAI,UAAU,MAAM,MAAM,KAAK,MAAM,WAAW;IAC9C;IACA;IACA,OAAO,OAAO,OAAO,MAAM,IAAI,IAAI;KAAE,OAAO;KAAG,SAAS,CAAC;IAAE;GAC7D,EAAE;GACF,IAAI,MAAM;IACR,MAAM,OAAO,QAAQ,QAAQ,UAAU,MAAM,KAAK;IAClD,KAAK,MAAM,GAAG,MAAM,EAAE,MAAO,QAAQ,EAAE,MAAO,SAAS,EAAE,QAAQ,EAAE,KAAK;IACxE,UAAU;GACZ;GACA,MAAM,yBAA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,MAAA,EAAA,CAAE,CAAC,EAAC,OAAA,CAAA;KAAW,MAAK;I,IACnDE,WAA+D,KAAA,QAAA,SAAA,CAAA,SAAA,CAAzCW,gBAAAJ,gBAAA,QAAA,aAAaT,MAAA,CAAA,CAAC,CAAA,eAAA,CAAA,GAAA,CAAA,C;IAG7B,MAAM,UAAjBH,UAAA,GAAAC,mBAA6E,OAAA;;KAAnD,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA;I,IAAYE,WAAsB,KAAA,QAAA,QAAA,C"}
|
|
1
|
+
{"version":3,"file":"command.vue_vue_type_script_setup_true_lang.js","names":["_useModel","_useSlots","_openBlock","_createElementBlock","_normalizeClass","_unref","_createElementVNode","_renderSlot","_createVNode","_withDirectives","_vModelText","_normalizeStyle","_Fragment","_renderList","_toDisplayString","_createCommentVNode","_normalizeProps","_withModifiers","_createTextVNode","_createBlock"],"sources":["../../../src/components/command/command.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { SearchIcon } from '@dou-ui/icons'\nimport { computed, nextTick, onUpdated, ref, useId, useTemplateRef, watch } from 'vue'\nimport { GROUP_START, useGroupedWindow } from '../../composables/use-grouped-window'\nimport { ariaHotkey, useApplePlatform } from '../../composables/use-hotkey'\nimport { useMeasuredSizes } from '../../composables/use-measured-sizes'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouKbd } from '../kbd'\nimport { matchCommand } from './command'\nimport type {\n CommandExpose,\n CommandItem,\n CommandProps,\n CommandSlots,\n CommandValue,\n} from './command'\n\ndefineOptions({ name: 'DouCommand' })\n\nconst props = withDefaults(defineProps<CommandProps>(), {\n loop: true,\n maxHeight: 320,\n virtual: undefined,\n})\nconst query = defineModel<string>('query', { default: '' })\nconst emit = defineEmits<{ select: [item: CommandItem] }>()\nconst slots = defineSlots<CommandSlots>()\n\nconst ns = useNamespace('command')\nconst apple = useApplePlatform()\nconst { t } = useLocale()\nconst id = `dou-command-${useId()}`\nconst listboxId = `${id}-list`\nconst optionId = (index: number) => `${id}-option-${index}`\n\ninterface Entry {\n item: CommandItem\n indices: number[]\n index: number\n}\ninterface Group {\n name: string | undefined\n entries: Entry[]\n}\n\n// The matching items, best first, gathered under their groups. Without a\n// query the items keep their own order.\nconst groups = computed<Group[]>(() => {\n const text = query.value.trim()\n const filter = props.filter ?? matchCommand\n let matched = props.items.map((item, order) => ({\n item,\n order,\n match: text ? filter(text, item) : { score: 0, indices: [] },\n }))\n if (text) {\n const kept = matched.filter((entry) => entry.match)\n kept.sort((a, b) => b.match!.score - a.match!.score || a.order - b.order)\n matched = kept\n }\n const byName = new Map<string | undefined, Group>()\n for (const { item, match } of matched) {\n let group = byName.get(item.group)\n if (!group) byName.set(item.group, (group = { name: item.group, entries: [] }))\n group.entries.push({ item, indices: match!.indices, index: 0 })\n }\n // Ungrouped items lead, and every entry learns its place in the flat list.\n const named = [...byName.values()].filter((group) => group.name !== undefined)\n const list = byName.has(undefined) ? [byName.get(undefined)!, ...named] : named\n let index = 0\n for (const group of list) for (const entry of group.entries) entry.index = index++\n return list\n})\nconst flat = computed(() => groups.value.flatMap((group) => group.entries))\n\nconst active = ref(-1)\nconst enabled = (index: number) => !!flat.value[index] && !flat.value[index]!.item.disabled\n\nfunction move(from: number, step: 1 | -1) {\n const count = flat.value.length\n for (let offset = 1; offset <= count; offset++) {\n let index = from + step * offset\n if (props.loop) index = ((index % count) + count) % count\n else if (index < 0 || index >= count) return\n if (enabled(index)) {\n active.value = index\n return\n }\n }\n}\nconst first = () => move(-1, 1)\n\n// A parent that re-renders passes a new but equal list: only a different\n// list of items moves the highlight back to the top.\nconst flatKey = computed(() =>\n flat.value.map((entry) => `${typeof entry.item.value}:${entry.item.value}`).join('\\u0000'),\n)\nwatch(\n flatKey,\n () => {\n active.value = -1\n first()\n },\n { immediate: true },\n)\n\nconst listRef = useTemplateRef<HTMLElement>('list')\n\n// Long lists render only the items in view. With `itemSize` every row is\n// that tall; without it rows grow to fit and are measured once rendered,\n// rows not rendered yet count as tall as the last ones measured, and a row\n// changing height above the view keeps what is in view in place.\nconst fixed = computed(() => props.itemSize !== undefined)\nfunction fixedSize(item: CommandItem) {\n const size = props.itemSize\n return typeof size === 'function' ? size(item) : size\n}\n/** Each item's group and place in it, by its index in the flat list. */\nconst places = computed(() =>\n groups.value.flatMap((group, at) => group.entries.map((_, index) => [at, index] as const)),\n)\nlet estimate: number | undefined\nconst measured = useMeasuredSizes<CommandValue>({\n count: () => flat.value.length,\n keyOf: (index) => flat.value[index]!.item.value,\n estimate: () => estimate ?? 36,\n container: () => listRef.value,\n start: (index) => windowing.startOf(...places.value[index]!),\n})\nconst windowing = useGroupedWindow({\n container: () => listRef.value,\n sizes: () => groups.value.map((group) => group.entries.length),\n itemSize: (group, index) => {\n const entry = groups.value[group]!.entries[index]!\n return fixedSize(entry.item) ?? measured.sizeOf(entry.index)\n },\n virtual: () => props.virtual,\n})\nconst groupWindows = computed(() =>\n groups.value.map((group, at) => {\n const view = windowing.windows.value[at]!\n return { ...view, entries: group.entries.slice(view.from, view.to) }\n }),\n)\nwatch(flatKey, () => {\n if (listRef.value) listRef.value.scrollTop = 0\n})\nwatch(\n () => props.items,\n () => (estimate = undefined),\n)\n\nfunction trackRow(el: unknown, entry: Entry) {\n if (windowing.enabled.value && !fixed.value) {\n measured.track(el as Element | null, entry.item.value, entry.index)\n }\n}\nonUpdated(() => {\n measured.prune()\n if (!windowing.enabled.value || !listRef.value) return\n const rows = listRef.value.querySelectorAll<HTMLElement>('[role=\"option\"]')\n if (!fixed.value) {\n // Rows still to be rendered are taken to be like the first ones shown.\n // Set once: a later change would move every row not measured yet.\n if (estimate === undefined) {\n let sum = 0\n for (const row of rows) sum += row.offsetHeight\n if (sum) estimate = sum / rows.length\n }\n return\n }\n // A row cut to its size overlaps the next one: say so while developing.\n if (process.env.NODE_ENV !== 'production') {\n for (const row of rows) {\n if (row.scrollHeight <= row.clientHeight + 1) continue\n return devWarn(\n '[dou-ui] DouCommand: an item is taller than `itemSize`. Pass a larger `itemSize`, or leave it out to have rows measured.',\n )\n }\n }\n})\n\n// Bring the active item into view. A far jump in a virtual list first\n// scrolls to where the item is estimated to be; once the rows there are\n// rendered and measured, it aims again, for a few frames at most.\nasync function reveal(index: number, settle: number) {\n if (windowing.enabled.value) {\n const place = places.value[index]\n if (place) windowing.scrollToItem(...place)\n }\n await nextTick()\n if (index !== active.value) return\n listRef.value?.querySelector(`#${CSS.escape(optionId(index))}`)?.scrollIntoView?.({\n block: 'nearest',\n })\n if (settle > 0 && windowing.enabled.value && !fixed.value) {\n if (typeof requestAnimationFrame !== 'undefined')\n requestAnimationFrame(() => index === active.value && void reveal(index, settle - 1))\n }\n}\nwatch(active, (index) => {\n if (index >= 0) void reveal(index, 3)\n})\n\nfunction choose(index: number) {\n if (!enabled(index)) return\n emit('select', flat.value[index]!.item)\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (isComposing(event)) return\n switch (event.key) {\n case 'ArrowDown':\n event.preventDefault()\n return move(active.value, 1)\n case 'ArrowUp':\n event.preventDefault()\n return move(active.value < 0 ? flat.value.length : active.value, -1)\n case 'Enter':\n event.preventDefault()\n return choose(active.value)\n }\n // Ctrl/⌘ with Home and End leave the caret alone and jump through the list.\n if ((event.ctrlKey || event.metaKey) && (event.key === 'Home' || event.key === 'End')) {\n event.preventDefault()\n if (event.key === 'Home') first()\n else move(flat.value.length, -1)\n }\n}\n\nfunction parts(entry: Entry) {\n const label = entry.item.label\n if (!entry.indices.length) return [{ text: label, match: false }]\n const picked = new Set(entry.indices)\n const result: { text: string; match: boolean }[] = []\n for (let index = 0; index < label.length; index++) {\n const match = picked.has(index)\n const last = result.at(-1)\n if (last && last.match === match) last.text += label[index]\n else result.push({ text: label[index]!, match })\n }\n return result\n}\n\nfunction rowStyle(entry: Entry) {\n const size = windowing.enabled.value ? fixedSize(entry.item) : undefined\n return size === undefined ? undefined : { height: `${size}px`, minHeight: `${size}px` }\n}\n\nconst inputRef = useTemplateRef<HTMLInputElement>('input')\ndefineExpose<CommandExpose>({ focus: () => inputRef.value?.focus() })\n\nconst maxHeight = computed(() =>\n typeof props.maxHeight === 'number' ? `${props.maxHeight}px` : props.maxHeight,\n)\n</script>\n\n<template>\n <div :class=\"ns.b()\">\n <div :class=\"ns.e('search')\">\n <span :class=\"ns.e('prefix')\" aria-hidden=\"true\">\n <slot name=\"prefix\">\n <SearchIcon />\n </slot>\n </span>\n <input\n ref=\"input\"\n v-model=\"query\"\n :class=\"ns.e('input')\"\n type=\"text\"\n role=\"combobox\"\n autocomplete=\"off\"\n spellcheck=\"false\"\n aria-autocomplete=\"list\"\n aria-expanded=\"true\"\n :aria-controls=\"listboxId\"\n :aria-activedescendant=\"active >= 0 ? optionId(active) : undefined\"\n :aria-label=\"ariaLabel ?? placeholder ?? t('command.placeholder')\"\n :placeholder=\"placeholder ?? t('command.placeholder')\"\n @keydown=\"onKeydown\"\n />\n </div>\n <div\n :id=\"listboxId\"\n ref=\"list\"\n role=\"listbox\"\n :class=\"ns.e('list')\"\n :style=\"{ maxHeight }\"\n :aria-label=\"ariaLabel ?? placeholder ?? t('command.placeholder')\"\n >\n <div\n v-for=\"(group, groupIndex) in groups\"\n :key=\"group.name ?? ''\"\n role=\"group\"\n :class=\"ns.e('group')\"\n :aria-labelledby=\"group.name ? `${id}-group-${groupIndex}` : undefined\"\n >\n <div\n v-if=\"group.name\"\n :id=\"`${id}-group-${groupIndex}`\"\n :class=\"ns.e('group-label')\"\n aria-hidden=\"true\"\n >\n {{ group.name }}\n </div>\n <div\n v-if=\"windowing.enabled.value\"\n role=\"presentation\"\n :[GROUP_START]=\"''\"\n :style=\"{ height: `${groupWindows[groupIndex]!.before}px` }\"\n />\n <div\n v-for=\"entry in groupWindows[groupIndex]!.entries\"\n :id=\"optionId(entry.index)\"\n :key=\"String(entry.item.value)\"\n role=\"option\"\n :aria-selected=\"entry.index === active\"\n :aria-setsize=\"windowing.enabled.value ? flat.length : undefined\"\n :aria-posinset=\"windowing.enabled.value ? entry.index + 1 : undefined\"\n :aria-disabled=\"entry.item.disabled || undefined\"\n :aria-keyshortcuts=\"\n entry.item.shortcut ? ariaHotkey(entry.item.shortcut, apple) : undefined\n \"\n :class=\"[\n ns.e('item'),\n ns.is('active', entry.index === active),\n ns.is('disabled', !!entry.item.disabled),\n ]\"\n :ref=\"(el) => trackRow(el, entry)\"\n :style=\"rowStyle(entry)\"\n @mousedown.prevent\n @click=\"choose(entry.index)\"\n @mousemove=\"enabled(entry.index) && (active = entry.index)\"\n >\n <slot\n name=\"item\"\n :item=\"entry.item\"\n :active=\"entry.index === active\"\n :indices=\"entry.indices\"\n >\n <span :class=\"ns.e('label')\">\n <template v-for=\"(part, at) in parts(entry)\" :key=\"at\">\n <mark v-if=\"part.match\" :class=\"ns.e('match')\">{{ part.text }}</mark>\n <template v-else>{{ part.text }}</template>\n </template>\n </span>\n <span v-if=\"entry.item.description\" :class=\"ns.e('description')\">\n {{ entry.item.description }}\n </span>\n <DouKbd\n v-if=\"entry.item.shortcut\"\n :class=\"ns.e('shortcut')\"\n size=\"sm\"\n :keys=\"entry.item.shortcut\"\n />\n </slot>\n </div>\n <div\n v-if=\"windowing.enabled.value && groupWindows[groupIndex]!.after\"\n role=\"presentation\"\n :style=\"{ height: `${groupWindows[groupIndex]!.after}px` }\"\n />\n </div>\n <div v-if=\"!flat.length\" :class=\"ns.e('empty')\" role=\"presentation\">\n <slot name=\"empty\">{{ emptyText ?? t('command.empty') }}</slot>\n </div>\n </div>\n <div v-if=\"slots.footer\" :class=\"ns.e('footer')\"><slot name=\"footer\" /></div>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsBA,MAAM,QAAQ;EAKd,MAAM,QAAQA,SAAmB,SAAC,OAAwB;EAC1D,MAAM,OAAO;EACb,MAAM,QAAQC,SA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,CAAA,CAAC,CAAA,eAAA,CAAA,GAAA,CAAA,C;IAG7B,MAAM,UAAjBH,UAAA,GAAAC,mBAA6E,OAAA;;KAAnD,OAAKC,eAAEC,MAAA,EAAA,CAAE,CAAC,EAAC,QAAA,CAAA;I,IAAYE,WAAsB,KAAA,QAAA,QAAA,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command2.js","names":["_sfc_main"],"sources":["../../../src/components/command/command.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { SearchIcon } from '@dou-ui/icons'\nimport { computed, nextTick, ref, useId, useTemplateRef, watch } from 'vue'\nimport { GROUP_START, useGroupedWindow } from '../../composables/use-grouped-window'\nimport { ariaHotkey, useApplePlatform } from '../../composables/use-hotkey'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouKbd } from '../kbd'\nimport { matchCommand } from './command'\nimport type { CommandExpose, CommandItem, CommandProps, CommandSlots } from './command'\n\ndefineOptions({ name: 'DouCommand' })\n\nconst props = withDefaults(defineProps<CommandProps>(), {\n loop: true,\n maxHeight: 320,\n virtual: undefined,\n})\nconst query = defineModel<string>('query', { default: '' })\nconst emit = defineEmits<{ select: [item: CommandItem] }>()\nconst slots = defineSlots<CommandSlots>()\n\nconst ns = useNamespace('command')\nconst apple = useApplePlatform()\nconst { t } = useLocale()\nconst id = `dou-command-${useId()}`\nconst listboxId = `${id}-list`\nconst optionId = (index: number) => `${id}-option-${index}`\n\ninterface Entry {\n item: CommandItem\n indices: number[]\n index: number\n}\ninterface Group {\n name: string | undefined\n entries: Entry[]\n}\n\n// The matching items, best first, gathered under their groups. Without a\n// query the items keep their own order.\nconst groups = computed<Group[]>(() => {\n const text = query.value.trim()\n const filter = props.filter ?? matchCommand\n let matched = props.items.map((item, order) => ({\n item,\n order,\n match: text ? filter(text, item) : { score: 0, indices: [] },\n }))\n if (text) {\n const kept = matched.filter((entry) => entry.match)\n kept.sort((a, b) => b.match!.score - a.match!.score || a.order - b.order)\n matched = kept\n }\n const byName = new Map<string | undefined, Group>()\n for (const { item, match } of matched) {\n let group = byName.get(item.group)\n if (!group) byName.set(item.group, (group = { name: item.group, entries: [] }))\n group.entries.push({ item, indices: match!.indices, index: 0 })\n }\n // Ungrouped items lead, and every entry learns its place in the flat list.\n const named = [...byName.values()].filter((group) => group.name !== undefined)\n const list = byName.has(undefined) ? [byName.get(undefined)!, ...named] : named\n let index = 0\n for (const group of list) for (const entry of group.entries) entry.index = index++\n return list\n})\nconst flat = computed(() => groups.value.flatMap((group) => group.entries))\n\nconst active = ref(-1)\nconst enabled = (index: number) => !!flat.value[index] && !flat.value[index]!.item.disabled\n\nfunction move(from: number, step: 1 | -1) {\n const count = flat.value.length\n for (let offset = 1; offset <= count; offset++) {\n let index = from + step * offset\n if (props.loop) index = ((index % count) + count) % count\n else if (index < 0 || index >= count) return\n if (enabled(index)) {\n active.value = index\n return\n }\n }\n}\nconst first = () => move(-1, 1)\n\n// A parent that re-renders passes a new but equal list: only a different\n// list of items moves the highlight back to the top.\nconst flatKey = computed(() =>\n flat.value.map((entry) => `${typeof entry.item.value}:${entry.item.value}`).join('\\u0000'),\n)\nwatch(\n flatKey,\n () => {\n active.value = -1\n first()\n },\n { immediate: true },\n)\n\nconst listRef = useTemplateRef<HTMLElement>('list')\n\n// Long lists render only the items in view; every item is one row tall.\nconst windowing = useGroupedWindow({\n container: () => listRef.value,\n sizes: () => groups.value.map((group) => group.entries.length),\n itemSize: () => 36,\n virtual: () => props.virtual,\n})\nconst groupWindows = computed(() =>\n groups.value.map((group, at) => {\n const view = windowing.windows.value[at]!\n return { ...view, entries: group.entries.slice(view.from, view.to) }\n }),\n)\nwatch(flatKey, () => {\n if (listRef.value) listRef.value.scrollTop = 0\n})\n\nwatch(active, async (index) => {\n if (windowing.enabled.value && index >= 0) {\n // The item may not be rendered: scroll by its place in its group.\n let at = index\n for (const [group, { entries }] of groups.value.entries()) {\n if (at < entries.length) {\n windowing.scrollToItem(group, at)\n break\n }\n at -= entries.length\n }\n }\n await nextTick()\n listRef.value?.querySelector(`#${CSS.escape(optionId(index))}`)?.scrollIntoView?.({\n block: 'nearest',\n })\n})\n\nfunction choose(index: number) {\n if (!enabled(index)) return\n emit('select', flat.value[index]!.item)\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (isComposing(event)) return\n switch (event.key) {\n case 'ArrowDown':\n event.preventDefault()\n return move(active.value, 1)\n case 'ArrowUp':\n event.preventDefault()\n return move(active.value < 0 ? flat.value.length : active.value, -1)\n case 'Enter':\n event.preventDefault()\n return choose(active.value)\n }\n // Ctrl/⌘ with Home and End leave the caret alone and jump through the list.\n if ((event.ctrlKey || event.metaKey) && (event.key === 'Home' || event.key === 'End')) {\n event.preventDefault()\n if (event.key === 'Home') first()\n else move(flat.value.length, -1)\n }\n}\n\nfunction parts(entry: Entry) {\n const label = entry.item.label\n if (!entry.indices.length) return [{ text: label, match: false }]\n const picked = new Set(entry.indices)\n const result: { text: string; match: boolean }[] = []\n for (let index = 0; index < label.length; index++) {\n const match = picked.has(index)\n const last = result.at(-1)\n if (last && last.match === match) last.text += label[index]\n else result.push({ text: label[index]!, match })\n }\n return result\n}\n\nconst inputRef = useTemplateRef<HTMLInputElement>('input')\ndefineExpose<CommandExpose>({ focus: () => inputRef.value?.focus() })\n\nconst maxHeight = computed(() =>\n typeof props.maxHeight === 'number' ? `${props.maxHeight}px` : props.maxHeight,\n)\n</script>\n\n<template>\n <div :class=\"ns.b()\">\n <div :class=\"ns.e('search')\">\n <span :class=\"ns.e('prefix')\" aria-hidden=\"true\">\n <slot name=\"prefix\">\n <SearchIcon />\n </slot>\n </span>\n <input\n ref=\"input\"\n v-model=\"query\"\n :class=\"ns.e('input')\"\n type=\"text\"\n role=\"combobox\"\n autocomplete=\"off\"\n spellcheck=\"false\"\n aria-autocomplete=\"list\"\n aria-expanded=\"true\"\n :aria-controls=\"listboxId\"\n :aria-activedescendant=\"active >= 0 ? optionId(active) : undefined\"\n :aria-label=\"ariaLabel ?? placeholder ?? t('command.placeholder')\"\n :placeholder=\"placeholder ?? t('command.placeholder')\"\n @keydown=\"onKeydown\"\n />\n </div>\n <div\n :id=\"listboxId\"\n ref=\"list\"\n role=\"listbox\"\n :class=\"ns.e('list')\"\n :style=\"{ maxHeight }\"\n :aria-label=\"ariaLabel ?? placeholder ?? t('command.placeholder')\"\n >\n <div\n v-for=\"(group, groupIndex) in groups\"\n :key=\"group.name ?? ''\"\n role=\"group\"\n :class=\"ns.e('group')\"\n :aria-labelledby=\"group.name ? `${id}-group-${groupIndex}` : undefined\"\n >\n <div\n v-if=\"group.name\"\n :id=\"`${id}-group-${groupIndex}`\"\n :class=\"ns.e('group-label')\"\n aria-hidden=\"true\"\n >\n {{ group.name }}\n </div>\n <div\n v-if=\"windowing.enabled.value\"\n role=\"presentation\"\n :[GROUP_START]=\"''\"\n :style=\"{ height: `${groupWindows[groupIndex]!.before}px` }\"\n />\n <div\n v-for=\"entry in groupWindows[groupIndex]!.entries\"\n :id=\"optionId(entry.index)\"\n :key=\"String(entry.item.value)\"\n role=\"option\"\n :aria-selected=\"entry.index === active\"\n :aria-setsize=\"windowing.enabled.value ? flat.length : undefined\"\n :aria-posinset=\"windowing.enabled.value ? entry.index + 1 : undefined\"\n :aria-disabled=\"entry.item.disabled || undefined\"\n :aria-keyshortcuts=\"\n entry.item.shortcut ? ariaHotkey(entry.item.shortcut, apple) : undefined\n \"\n :class=\"[\n ns.e('item'),\n ns.is('active', entry.index === active),\n ns.is('disabled', !!entry.item.disabled),\n ]\"\n @mousedown.prevent\n @click=\"choose(entry.index)\"\n @mousemove=\"enabled(entry.index) && (active = entry.index)\"\n >\n <slot\n name=\"item\"\n :item=\"entry.item\"\n :active=\"entry.index === active\"\n :indices=\"entry.indices\"\n >\n <span :class=\"ns.e('label')\">\n <template v-for=\"(part, at) in parts(entry)\" :key=\"at\">\n <mark v-if=\"part.match\" :class=\"ns.e('match')\">{{ part.text }}</mark>\n <template v-else>{{ part.text }}</template>\n </template>\n </span>\n <span v-if=\"entry.item.description\" :class=\"ns.e('description')\">\n {{ entry.item.description }}\n </span>\n <DouKbd\n v-if=\"entry.item.shortcut\"\n :class=\"ns.e('shortcut')\"\n size=\"sm\"\n :keys=\"entry.item.shortcut\"\n />\n </slot>\n </div>\n <div\n v-if=\"windowing.enabled.value && groupWindows[groupIndex]!.after\"\n role=\"presentation\"\n :style=\"{ height: `${groupWindows[groupIndex]!.after}px` }\"\n />\n </div>\n <div v-if=\"!flat.length\" :class=\"ns.e('empty')\" role=\"presentation\">\n <slot name=\"empty\">{{ emptyText ?? t('command.empty') }}</slot>\n </div>\n </div>\n <div v-if=\"slots.footer\" :class=\"ns.e('footer')\"><slot name=\"footer\" /></div>\n </div>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"command2.js","names":["_sfc_main"],"sources":["../../../src/components/command/command.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { SearchIcon } from '@dou-ui/icons'\nimport { computed, nextTick, onUpdated, ref, useId, useTemplateRef, watch } from 'vue'\nimport { GROUP_START, useGroupedWindow } from '../../composables/use-grouped-window'\nimport { ariaHotkey, useApplePlatform } from '../../composables/use-hotkey'\nimport { useMeasuredSizes } from '../../composables/use-measured-sizes'\nimport { isComposing } from '../../utils/keyboard'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport { useLocale } from '../config-provider/use-config'\nimport { DouKbd } from '../kbd'\nimport { matchCommand } from './command'\nimport type {\n CommandExpose,\n CommandItem,\n CommandProps,\n CommandSlots,\n CommandValue,\n} from './command'\n\ndefineOptions({ name: 'DouCommand' })\n\nconst props = withDefaults(defineProps<CommandProps>(), {\n loop: true,\n maxHeight: 320,\n virtual: undefined,\n})\nconst query = defineModel<string>('query', { default: '' })\nconst emit = defineEmits<{ select: [item: CommandItem] }>()\nconst slots = defineSlots<CommandSlots>()\n\nconst ns = useNamespace('command')\nconst apple = useApplePlatform()\nconst { t } = useLocale()\nconst id = `dou-command-${useId()}`\nconst listboxId = `${id}-list`\nconst optionId = (index: number) => `${id}-option-${index}`\n\ninterface Entry {\n item: CommandItem\n indices: number[]\n index: number\n}\ninterface Group {\n name: string | undefined\n entries: Entry[]\n}\n\n// The matching items, best first, gathered under their groups. Without a\n// query the items keep their own order.\nconst groups = computed<Group[]>(() => {\n const text = query.value.trim()\n const filter = props.filter ?? matchCommand\n let matched = props.items.map((item, order) => ({\n item,\n order,\n match: text ? filter(text, item) : { score: 0, indices: [] },\n }))\n if (text) {\n const kept = matched.filter((entry) => entry.match)\n kept.sort((a, b) => b.match!.score - a.match!.score || a.order - b.order)\n matched = kept\n }\n const byName = new Map<string | undefined, Group>()\n for (const { item, match } of matched) {\n let group = byName.get(item.group)\n if (!group) byName.set(item.group, (group = { name: item.group, entries: [] }))\n group.entries.push({ item, indices: match!.indices, index: 0 })\n }\n // Ungrouped items lead, and every entry learns its place in the flat list.\n const named = [...byName.values()].filter((group) => group.name !== undefined)\n const list = byName.has(undefined) ? [byName.get(undefined)!, ...named] : named\n let index = 0\n for (const group of list) for (const entry of group.entries) entry.index = index++\n return list\n})\nconst flat = computed(() => groups.value.flatMap((group) => group.entries))\n\nconst active = ref(-1)\nconst enabled = (index: number) => !!flat.value[index] && !flat.value[index]!.item.disabled\n\nfunction move(from: number, step: 1 | -1) {\n const count = flat.value.length\n for (let offset = 1; offset <= count; offset++) {\n let index = from + step * offset\n if (props.loop) index = ((index % count) + count) % count\n else if (index < 0 || index >= count) return\n if (enabled(index)) {\n active.value = index\n return\n }\n }\n}\nconst first = () => move(-1, 1)\n\n// A parent that re-renders passes a new but equal list: only a different\n// list of items moves the highlight back to the top.\nconst flatKey = computed(() =>\n flat.value.map((entry) => `${typeof entry.item.value}:${entry.item.value}`).join('\\u0000'),\n)\nwatch(\n flatKey,\n () => {\n active.value = -1\n first()\n },\n { immediate: true },\n)\n\nconst listRef = useTemplateRef<HTMLElement>('list')\n\n// Long lists render only the items in view. With `itemSize` every row is\n// that tall; without it rows grow to fit and are measured once rendered,\n// rows not rendered yet count as tall as the last ones measured, and a row\n// changing height above the view keeps what is in view in place.\nconst fixed = computed(() => props.itemSize !== undefined)\nfunction fixedSize(item: CommandItem) {\n const size = props.itemSize\n return typeof size === 'function' ? size(item) : size\n}\n/** Each item's group and place in it, by its index in the flat list. */\nconst places = computed(() =>\n groups.value.flatMap((group, at) => group.entries.map((_, index) => [at, index] as const)),\n)\nlet estimate: number | undefined\nconst measured = useMeasuredSizes<CommandValue>({\n count: () => flat.value.length,\n keyOf: (index) => flat.value[index]!.item.value,\n estimate: () => estimate ?? 36,\n container: () => listRef.value,\n start: (index) => windowing.startOf(...places.value[index]!),\n})\nconst windowing = useGroupedWindow({\n container: () => listRef.value,\n sizes: () => groups.value.map((group) => group.entries.length),\n itemSize: (group, index) => {\n const entry = groups.value[group]!.entries[index]!\n return fixedSize(entry.item) ?? measured.sizeOf(entry.index)\n },\n virtual: () => props.virtual,\n})\nconst groupWindows = computed(() =>\n groups.value.map((group, at) => {\n const view = windowing.windows.value[at]!\n return { ...view, entries: group.entries.slice(view.from, view.to) }\n }),\n)\nwatch(flatKey, () => {\n if (listRef.value) listRef.value.scrollTop = 0\n})\nwatch(\n () => props.items,\n () => (estimate = undefined),\n)\n\nfunction trackRow(el: unknown, entry: Entry) {\n if (windowing.enabled.value && !fixed.value) {\n measured.track(el as Element | null, entry.item.value, entry.index)\n }\n}\nonUpdated(() => {\n measured.prune()\n if (!windowing.enabled.value || !listRef.value) return\n const rows = listRef.value.querySelectorAll<HTMLElement>('[role=\"option\"]')\n if (!fixed.value) {\n // Rows still to be rendered are taken to be like the first ones shown.\n // Set once: a later change would move every row not measured yet.\n if (estimate === undefined) {\n let sum = 0\n for (const row of rows) sum += row.offsetHeight\n if (sum) estimate = sum / rows.length\n }\n return\n }\n // A row cut to its size overlaps the next one: say so while developing.\n if (process.env.NODE_ENV !== 'production') {\n for (const row of rows) {\n if (row.scrollHeight <= row.clientHeight + 1) continue\n return devWarn(\n '[dou-ui] DouCommand: an item is taller than `itemSize`. Pass a larger `itemSize`, or leave it out to have rows measured.',\n )\n }\n }\n})\n\n// Bring the active item into view. A far jump in a virtual list first\n// scrolls to where the item is estimated to be; once the rows there are\n// rendered and measured, it aims again, for a few frames at most.\nasync function reveal(index: number, settle: number) {\n if (windowing.enabled.value) {\n const place = places.value[index]\n if (place) windowing.scrollToItem(...place)\n }\n await nextTick()\n if (index !== active.value) return\n listRef.value?.querySelector(`#${CSS.escape(optionId(index))}`)?.scrollIntoView?.({\n block: 'nearest',\n })\n if (settle > 0 && windowing.enabled.value && !fixed.value) {\n if (typeof requestAnimationFrame !== 'undefined')\n requestAnimationFrame(() => index === active.value && void reveal(index, settle - 1))\n }\n}\nwatch(active, (index) => {\n if (index >= 0) void reveal(index, 3)\n})\n\nfunction choose(index: number) {\n if (!enabled(index)) return\n emit('select', flat.value[index]!.item)\n}\n\nfunction onKeydown(event: KeyboardEvent) {\n if (isComposing(event)) return\n switch (event.key) {\n case 'ArrowDown':\n event.preventDefault()\n return move(active.value, 1)\n case 'ArrowUp':\n event.preventDefault()\n return move(active.value < 0 ? flat.value.length : active.value, -1)\n case 'Enter':\n event.preventDefault()\n return choose(active.value)\n }\n // Ctrl/⌘ with Home and End leave the caret alone and jump through the list.\n if ((event.ctrlKey || event.metaKey) && (event.key === 'Home' || event.key === 'End')) {\n event.preventDefault()\n if (event.key === 'Home') first()\n else move(flat.value.length, -1)\n }\n}\n\nfunction parts(entry: Entry) {\n const label = entry.item.label\n if (!entry.indices.length) return [{ text: label, match: false }]\n const picked = new Set(entry.indices)\n const result: { text: string; match: boolean }[] = []\n for (let index = 0; index < label.length; index++) {\n const match = picked.has(index)\n const last = result.at(-1)\n if (last && last.match === match) last.text += label[index]\n else result.push({ text: label[index]!, match })\n }\n return result\n}\n\nfunction rowStyle(entry: Entry) {\n const size = windowing.enabled.value ? fixedSize(entry.item) : undefined\n return size === undefined ? undefined : { height: `${size}px`, minHeight: `${size}px` }\n}\n\nconst inputRef = useTemplateRef<HTMLInputElement>('input')\ndefineExpose<CommandExpose>({ focus: () => inputRef.value?.focus() })\n\nconst maxHeight = computed(() =>\n typeof props.maxHeight === 'number' ? `${props.maxHeight}px` : props.maxHeight,\n)\n</script>\n\n<template>\n <div :class=\"ns.b()\">\n <div :class=\"ns.e('search')\">\n <span :class=\"ns.e('prefix')\" aria-hidden=\"true\">\n <slot name=\"prefix\">\n <SearchIcon />\n </slot>\n </span>\n <input\n ref=\"input\"\n v-model=\"query\"\n :class=\"ns.e('input')\"\n type=\"text\"\n role=\"combobox\"\n autocomplete=\"off\"\n spellcheck=\"false\"\n aria-autocomplete=\"list\"\n aria-expanded=\"true\"\n :aria-controls=\"listboxId\"\n :aria-activedescendant=\"active >= 0 ? optionId(active) : undefined\"\n :aria-label=\"ariaLabel ?? placeholder ?? t('command.placeholder')\"\n :placeholder=\"placeholder ?? t('command.placeholder')\"\n @keydown=\"onKeydown\"\n />\n </div>\n <div\n :id=\"listboxId\"\n ref=\"list\"\n role=\"listbox\"\n :class=\"ns.e('list')\"\n :style=\"{ maxHeight }\"\n :aria-label=\"ariaLabel ?? placeholder ?? t('command.placeholder')\"\n >\n <div\n v-for=\"(group, groupIndex) in groups\"\n :key=\"group.name ?? ''\"\n role=\"group\"\n :class=\"ns.e('group')\"\n :aria-labelledby=\"group.name ? `${id}-group-${groupIndex}` : undefined\"\n >\n <div\n v-if=\"group.name\"\n :id=\"`${id}-group-${groupIndex}`\"\n :class=\"ns.e('group-label')\"\n aria-hidden=\"true\"\n >\n {{ group.name }}\n </div>\n <div\n v-if=\"windowing.enabled.value\"\n role=\"presentation\"\n :[GROUP_START]=\"''\"\n :style=\"{ height: `${groupWindows[groupIndex]!.before}px` }\"\n />\n <div\n v-for=\"entry in groupWindows[groupIndex]!.entries\"\n :id=\"optionId(entry.index)\"\n :key=\"String(entry.item.value)\"\n role=\"option\"\n :aria-selected=\"entry.index === active\"\n :aria-setsize=\"windowing.enabled.value ? flat.length : undefined\"\n :aria-posinset=\"windowing.enabled.value ? entry.index + 1 : undefined\"\n :aria-disabled=\"entry.item.disabled || undefined\"\n :aria-keyshortcuts=\"\n entry.item.shortcut ? ariaHotkey(entry.item.shortcut, apple) : undefined\n \"\n :class=\"[\n ns.e('item'),\n ns.is('active', entry.index === active),\n ns.is('disabled', !!entry.item.disabled),\n ]\"\n :ref=\"(el) => trackRow(el, entry)\"\n :style=\"rowStyle(entry)\"\n @mousedown.prevent\n @click=\"choose(entry.index)\"\n @mousemove=\"enabled(entry.index) && (active = entry.index)\"\n >\n <slot\n name=\"item\"\n :item=\"entry.item\"\n :active=\"entry.index === active\"\n :indices=\"entry.indices\"\n >\n <span :class=\"ns.e('label')\">\n <template v-for=\"(part, at) in parts(entry)\" :key=\"at\">\n <mark v-if=\"part.match\" :class=\"ns.e('match')\">{{ part.text }}</mark>\n <template v-else>{{ part.text }}</template>\n </template>\n </span>\n <span v-if=\"entry.item.description\" :class=\"ns.e('description')\">\n {{ entry.item.description }}\n </span>\n <DouKbd\n v-if=\"entry.item.shortcut\"\n :class=\"ns.e('shortcut')\"\n size=\"sm\"\n :keys=\"entry.item.shortcut\"\n />\n </slot>\n </div>\n <div\n v-if=\"windowing.enabled.value && groupWindows[groupIndex]!.after\"\n role=\"presentation\"\n :style=\"{ height: `${groupWindows[groupIndex]!.after}px` }\"\n />\n </div>\n <div v-if=\"!flat.length\" :class=\"ns.e('empty')\" role=\"presentation\">\n <slot name=\"empty\">{{ emptyText ?? t('command.empty') }}</slot>\n </div>\n </div>\n <div v-if=\"slots.footer\" :class=\"ns.e('footer')\"><slot name=\"footer\" /></div>\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","names":["_sfc_main"],"sources":["../../../src/components/link/link.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ArrowUpRightIcon } from '@dou-ui/icons'\nimport {\n Comment,\n Fragment,\n Text,\n computed,\n createTextVNode,\n h,\n isVNode,\n onMounted,\n useTemplateRef,\n watchEffect,\n} from 'vue'\nimport type { VNode } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport type { LinkEmits, LinkProps, LinkSlots } from './link'\n\ndefineOptions({ name: 'DouLink' })\n\nconst props = withDefaults(defineProps<LinkProps>(), {\n tone: 'neutral',\n variant: 'text',\n underline: undefined,\n disabled: false,\n external: false,\n})\nconst emit = defineEmits<LinkEmits>()\nconst slots = defineSlots<LinkSlots>()\n\nconst ns = useNamespace('link')\n\n// Without an address there is nowhere to go: the link is an action, so it is\n// a button, which takes focus and responds to Enter and Space.\nconst isButton = computed(() => !props.href)\n\nif (process.env.NODE_ENV !== 'production')\n watchEffect(() => {\n if (props.external && !props.href)\n devWarn(\n '[dou-ui] DouLink: `external` opens `href` in a new tab; without an `href` the link is a button and `external` does nothing.',\n )\n })\n\n// A button inside a button is invalid: the parser splits them apart and\n// server-rendered markup no longer matches on hydration.\nconst root = useTemplateRef<HTMLElement>('root')\nif (process.env.NODE_ENV !== 'production')\n onMounted(() => {\n if (isButton.value && root.value?.parentElement?.closest('button'))\n devWarn(\n '[dou-ui] DouLink: without an `href` the link is a button, and it sits inside another button. Pass an `href`, or move it out of the clickable element.',\n )\n })\n\n// A label written on its own lines in a template starts and ends with a\n// space, which would show under the underline or inside a soft fill. Slots\n// passed on by a wrapper come as fragments, and a `v-if` leaves a comment:\n// look through both for the first and last text. A fragment that holds\n// nothing but spaces is passed over for the next node.\n//\n// A soft link breaks with the line, and an icon must not be left alone at\n// the end of one: the first and last characters of the label are taken out\n// to sit beside the icons in a span that never breaks. A character inside\n// an element of its own (`<strong>`) stays where it is.\ntype Edge = 'start' | 'end'\ntype Walk = { nodes: unknown[]; done: boolean; char: string }\nfunction cut(text: string, edge: Edge, take: boolean): [rest: string, char: string] {\n const trimmed = edge === 'start' ? text.trimStart() : text.trimEnd()\n if (!take || !trimmed) return [trimmed, '']\n const chars = Array.from(trimmed)\n return edge === 'start'\n ? [chars.slice(1).join(''), chars[0] ?? '']\n : [chars.slice(0, -1).join(''), chars[chars.length - 1] ?? '']\n}\nfunction walk(nodes: unknown[], edge: Edge, take: boolean): Walk {\n const out = [...nodes]\n const step = edge === 'start' ? 1 : -1\n for (let index = step > 0 ? 0 : out.length - 1; index >= 0 && index < out.length; index += step) {\n const node = out[index]\n if (typeof node === 'string' || (isVNode(node) && node.type === Text)) {\n const text = typeof node === 'string' ? node : node.children\n if (typeof text !== 'string') return { nodes: out, done: true, char: '' }\n const [rest, char] = cut(text, edge, take)\n out[index] = typeof node === 'string' ? rest : createTextVNode(rest)\n if (char || rest) return { nodes: out, done: true, char }\n continue\n }\n if (!isVNode(node) || node.type === Comment) continue\n if (node.type === Fragment && Array.isArray(node.children)) {\n const inner = walk(node.children, edge, take)\n out[index] = { ...node, children: inner.nodes } as VNode\n if (inner.done) return { ...inner, nodes: out }\n continue\n }\n return { nodes: out, done: true, char: '' }\n }\n return { nodes: out, done: false, char: '' }\n}\n// Called in this component's own render, so it follows slots that come\n// and go; `Nodes` only puts the result down.\nconst parts = () => {\n const label = (slots.default?.() ?? []) as unknown[]\n const soft = props.variant === 'soft'\n const leading = slots.leading
|
|
1
|
+
{"version":3,"file":"link.js","names":["_sfc_main"],"sources":["../../../src/components/link/link.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ArrowUpRightIcon } from '@dou-ui/icons'\nimport {\n Comment,\n Fragment,\n Text,\n computed,\n createTextVNode,\n h,\n isVNode,\n onMounted,\n useTemplateRef,\n watchEffect,\n} from 'vue'\nimport type { VNode } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { filled } from '../../utils/slot'\nimport { devWarn } from '../../utils/status-check'\nimport type { LinkEmits, LinkProps, LinkSlots } from './link'\n\ndefineOptions({ name: 'DouLink' })\n\nconst props = withDefaults(defineProps<LinkProps>(), {\n tone: 'neutral',\n variant: 'text',\n underline: undefined,\n disabled: false,\n external: false,\n})\nconst emit = defineEmits<LinkEmits>()\nconst slots = defineSlots<LinkSlots>()\n\nconst ns = useNamespace('link')\n\n// Without an address there is nowhere to go: the link is an action, so it is\n// a button, which takes focus and responds to Enter and Space.\nconst isButton = computed(() => !props.href)\n\nif (process.env.NODE_ENV !== 'production')\n watchEffect(() => {\n if (props.external && !props.href)\n devWarn(\n '[dou-ui] DouLink: `external` opens `href` in a new tab; without an `href` the link is a button and `external` does nothing.',\n )\n })\n\n// A button inside a button is invalid: the parser splits them apart and\n// server-rendered markup no longer matches on hydration.\nconst root = useTemplateRef<HTMLElement>('root')\nif (process.env.NODE_ENV !== 'production')\n onMounted(() => {\n if (isButton.value && root.value?.parentElement?.closest('button'))\n devWarn(\n '[dou-ui] DouLink: without an `href` the link is a button, and it sits inside another button. Pass an `href`, or move it out of the clickable element.',\n )\n })\n\n// A label written on its own lines in a template starts and ends with a\n// space, which would show under the underline or inside a soft fill. Slots\n// passed on by a wrapper come as fragments, and a `v-if` leaves a comment:\n// look through both for the first and last text. A fragment that holds\n// nothing but spaces is passed over for the next node.\n//\n// A soft link breaks with the line, and an icon must not be left alone at\n// the end of one: the first and last characters of the label are taken out\n// to sit beside the icons in a span that never breaks. A character inside\n// an element of its own (`<strong>`) stays where it is.\ntype Edge = 'start' | 'end'\ntype Walk = { nodes: unknown[]; done: boolean; char: string }\nfunction cut(text: string, edge: Edge, take: boolean): [rest: string, char: string] {\n const trimmed = edge === 'start' ? text.trimStart() : text.trimEnd()\n if (!take || !trimmed) return [trimmed, '']\n const chars = Array.from(trimmed)\n return edge === 'start'\n ? [chars.slice(1).join(''), chars[0] ?? '']\n : [chars.slice(0, -1).join(''), chars[chars.length - 1] ?? '']\n}\nfunction walk(nodes: unknown[], edge: Edge, take: boolean): Walk {\n const out = [...nodes]\n const step = edge === 'start' ? 1 : -1\n for (let index = step > 0 ? 0 : out.length - 1; index >= 0 && index < out.length; index += step) {\n const node = out[index]\n if (typeof node === 'string' || (isVNode(node) && node.type === Text)) {\n const text = typeof node === 'string' ? node : node.children\n if (typeof text !== 'string') return { nodes: out, done: true, char: '' }\n const [rest, char] = cut(text, edge, take)\n out[index] = typeof node === 'string' ? rest : createTextVNode(rest)\n if (char || rest) return { nodes: out, done: true, char }\n continue\n }\n if (!isVNode(node) || node.type === Comment) continue\n if (node.type === Fragment && Array.isArray(node.children)) {\n const inner = walk(node.children, edge, take)\n out[index] = { ...node, children: inner.nodes } as VNode\n if (inner.done) return { ...inner, nodes: out }\n continue\n }\n return { nodes: out, done: true, char: '' }\n }\n return { nodes: out, done: false, char: '' }\n}\n// Called in this component's own render, so it follows slots that come\n// and go; `Nodes` only puts the result down.\nconst parts = () => {\n const label = (slots.default?.() ?? []) as unknown[]\n const soft = props.variant === 'soft'\n // a slot that renders nothing counts as not passed: no empty icon, and\n // an external link keeps its arrow\n const leading = filled(slots.leading)\n const own = filled(slots.trailing)\n const arrow = !own\n const trailing = own ?? (props.external && !isButton.value ? h(ArrowUpRightIcon) : undefined)\n const head = walk(label, 'start', soft && !!leading)\n const tail = walk(head.nodes, 'end', soft && !!trailing)\n const icon = (content: unknown, external = false) =>\n h(\n 'span',\n {\n class: [ns.e('icon'), external && ns.e('external')],\n 'aria-hidden': external ? 'true' : undefined,\n },\n content as VNode[],\n )\n const before = leading ? icon(leading) : undefined\n const after = trailing ? icon(trailing, arrow) : undefined\n const body = h('span', { class: ns.e('label') }, tail.nodes as VNode[])\n if (!soft) return [before, body, after]\n // a single character between two icons: all three break as one\n if (before && after && head.char && !tail.char)\n return [h('span', { class: [ns.e('lead'), ns.e('trail')] }, [before, head.char, body, after])]\n return [\n before && h('span', { class: ns.e('lead') }, [before, head.char]),\n body,\n after && h('span', { class: ns.e('trail') }, [tail.char, after]),\n ]\n}\nconst Nodes = (nodes: { nodes: unknown }) => nodes.nodes as VNode[]\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.tone),\n ns.m(props.variant),\n ns.m(`underline-${props.underline ?? (props.variant === 'soft' ? 'none' : 'always')}`),\n ns.is('disabled', props.disabled),\n])\n\nconst attrs = computed(() =>\n isButton.value\n ? { type: 'button', disabled: props.disabled }\n : {\n href: props.disabled ? undefined : props.href,\n target: props.external ? '_blank' : undefined,\n rel: props.external ? 'noopener noreferrer' : undefined,\n 'aria-disabled': props.disabled || undefined,\n },\n)\n\nfunction onClick(event: MouseEvent) {\n if (props.disabled) {\n event.preventDefault()\n return\n }\n emit('click', event)\n}\n</script>\n\n<template>\n <component\n :is=\"isButton ? 'button' : 'a'\"\n ref=\"root\"\n :class=\"classes\"\n v-bind=\"attrs\"\n @click=\"onClick\"\n >\n <Nodes :nodes=\"parts()\" />\n </component>\n</template>\n"],"mappings":""}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useNamespace } from "../../utils/namespace.js";
|
|
2
2
|
import { devWarn } from "../../utils/status-check.js";
|
|
3
|
+
import { filled } from "../../utils/slot.js";
|
|
3
4
|
import { Comment, Fragment, Text, computed, createBlock, createTextVNode, createVNode, defineComponent, h, isVNode, mergeProps, onMounted, openBlock, resolveDynamicComponent, useSlots, useTemplateRef, watchEffect, withCtx } from "vue";
|
|
4
5
|
import { ArrowUpRightIcon } from "@dou-ui/icons";
|
|
5
6
|
// src/components/link/link.vue?vue&type=script&setup=true&lang.ts
|
|
@@ -89,17 +90,18 @@ var link_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineCompo
|
|
|
89
90
|
const parts = () => {
|
|
90
91
|
const label = slots.default?.() ?? [];
|
|
91
92
|
const soft = props.variant === "soft";
|
|
92
|
-
const leading = slots.leading
|
|
93
|
-
const
|
|
93
|
+
const leading = filled(slots.leading);
|
|
94
|
+
const own = filled(slots.trailing);
|
|
95
|
+
const arrow = !own;
|
|
96
|
+
const trailing = own ?? (props.external && !isButton.value ? h(ArrowUpRightIcon) : void 0);
|
|
94
97
|
const head = walk(label, "start", soft && !!leading);
|
|
95
98
|
const tail = walk(head.nodes, "end", soft && !!trailing);
|
|
96
99
|
const icon = (content, external = false) => h("span", {
|
|
97
100
|
class: [ns.e("icon"), external && ns.e("external")],
|
|
98
101
|
"aria-hidden": external ? "true" : void 0
|
|
99
102
|
}, content);
|
|
100
|
-
const external = !slots.trailing;
|
|
101
103
|
const before = leading ? icon(leading) : void 0;
|
|
102
|
-
const after = trailing ? icon(trailing,
|
|
104
|
+
const after = trailing ? icon(trailing, arrow) : void 0;
|
|
103
105
|
const body = h("span", { class: ns.e("label") }, tail.nodes);
|
|
104
106
|
if (!soft) return [
|
|
105
107
|
before,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createBlock","_resolveDynamicComponent","_mergeProps","_withCtx","_createVNode"],"sources":["../../../src/components/link/link.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ArrowUpRightIcon } from '@dou-ui/icons'\nimport {\n Comment,\n Fragment,\n Text,\n computed,\n createTextVNode,\n h,\n isVNode,\n onMounted,\n useTemplateRef,\n watchEffect,\n} from 'vue'\nimport type { VNode } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { devWarn } from '../../utils/status-check'\nimport type { LinkEmits, LinkProps, LinkSlots } from './link'\n\ndefineOptions({ name: 'DouLink' })\n\nconst props = withDefaults(defineProps<LinkProps>(), {\n tone: 'neutral',\n variant: 'text',\n underline: undefined,\n disabled: false,\n external: false,\n})\nconst emit = defineEmits<LinkEmits>()\nconst slots = defineSlots<LinkSlots>()\n\nconst ns = useNamespace('link')\n\n// Without an address there is nowhere to go: the link is an action, so it is\n// a button, which takes focus and responds to Enter and Space.\nconst isButton = computed(() => !props.href)\n\nif (process.env.NODE_ENV !== 'production')\n watchEffect(() => {\n if (props.external && !props.href)\n devWarn(\n '[dou-ui] DouLink: `external` opens `href` in a new tab; without an `href` the link is a button and `external` does nothing.',\n )\n })\n\n// A button inside a button is invalid: the parser splits them apart and\n// server-rendered markup no longer matches on hydration.\nconst root = useTemplateRef<HTMLElement>('root')\nif (process.env.NODE_ENV !== 'production')\n onMounted(() => {\n if (isButton.value && root.value?.parentElement?.closest('button'))\n devWarn(\n '[dou-ui] DouLink: without an `href` the link is a button, and it sits inside another button. Pass an `href`, or move it out of the clickable element.',\n )\n })\n\n// A label written on its own lines in a template starts and ends with a\n// space, which would show under the underline or inside a soft fill. Slots\n// passed on by a wrapper come as fragments, and a `v-if` leaves a comment:\n// look through both for the first and last text. A fragment that holds\n// nothing but spaces is passed over for the next node.\n//\n// A soft link breaks with the line, and an icon must not be left alone at\n// the end of one: the first and last characters of the label are taken out\n// to sit beside the icons in a span that never breaks. A character inside\n// an element of its own (`<strong>`) stays where it is.\ntype Edge = 'start' | 'end'\ntype Walk = { nodes: unknown[]; done: boolean; char: string }\nfunction cut(text: string, edge: Edge, take: boolean): [rest: string, char: string] {\n const trimmed = edge === 'start' ? text.trimStart() : text.trimEnd()\n if (!take || !trimmed) return [trimmed, '']\n const chars = Array.from(trimmed)\n return edge === 'start'\n ? [chars.slice(1).join(''), chars[0] ?? '']\n : [chars.slice(0, -1).join(''), chars[chars.length - 1] ?? '']\n}\nfunction walk(nodes: unknown[], edge: Edge, take: boolean): Walk {\n const out = [...nodes]\n const step = edge === 'start' ? 1 : -1\n for (let index = step > 0 ? 0 : out.length - 1; index >= 0 && index < out.length; index += step) {\n const node = out[index]\n if (typeof node === 'string' || (isVNode(node) && node.type === Text)) {\n const text = typeof node === 'string' ? node : node.children\n if (typeof text !== 'string') return { nodes: out, done: true, char: '' }\n const [rest, char] = cut(text, edge, take)\n out[index] = typeof node === 'string' ? rest : createTextVNode(rest)\n if (char || rest) return { nodes: out, done: true, char }\n continue\n }\n if (!isVNode(node) || node.type === Comment) continue\n if (node.type === Fragment && Array.isArray(node.children)) {\n const inner = walk(node.children, edge, take)\n out[index] = { ...node, children: inner.nodes } as VNode\n if (inner.done) return { ...inner, nodes: out }\n continue\n }\n return { nodes: out, done: true, char: '' }\n }\n return { nodes: out, done: false, char: '' }\n}\n// Called in this component's own render, so it follows slots that come\n// and go; `Nodes` only puts the result down.\nconst parts = () => {\n const label = (slots.default?.() ?? []) as unknown[]\n const soft = props.variant === 'soft'\n const leading = slots.leading?.()\n const trailing = slots.trailing\n ? slots.trailing()\n : props.external && !isButton.value\n ? h(ArrowUpRightIcon)\n : undefined\n const head = walk(label, 'start', soft && !!leading)\n const tail = walk(head.nodes, 'end', soft && !!trailing)\n const icon = (content: unknown, external = false) =>\n h(\n 'span',\n {\n class: [ns.e('icon'), external && ns.e('external')],\n 'aria-hidden': external ? 'true' : undefined,\n },\n content as VNode[],\n )\n const external = !slots.trailing\n const before = leading ? icon(leading) : undefined\n const after = trailing ? icon(trailing, external) : undefined\n const body = h('span', { class: ns.e('label') }, tail.nodes as VNode[])\n if (!soft) return [before, body, after]\n // a single character between two icons: all three break as one\n if (before && after && head.char && !tail.char)\n return [h('span', { class: [ns.e('lead'), ns.e('trail')] }, [before, head.char, body, after])]\n return [\n before && h('span', { class: ns.e('lead') }, [before, head.char]),\n body,\n after && h('span', { class: ns.e('trail') }, [tail.char, after]),\n ]\n}\nconst Nodes = (nodes: { nodes: unknown }) => nodes.nodes as VNode[]\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.tone),\n ns.m(props.variant),\n ns.m(`underline-${props.underline ?? (props.variant === 'soft' ? 'none' : 'always')}`),\n ns.is('disabled', props.disabled),\n])\n\nconst attrs = computed(() =>\n isButton.value\n ? { type: 'button', disabled: props.disabled }\n : {\n href: props.disabled ? undefined : props.href,\n target: props.external ? '_blank' : undefined,\n rel: props.external ? 'noopener noreferrer' : undefined,\n 'aria-disabled': props.disabled || undefined,\n },\n)\n\nfunction onClick(event: MouseEvent) {\n if (props.disabled) {\n event.preventDefault()\n return\n }\n emit('click', event)\n}\n</script>\n\n<template>\n <component\n :is=\"isButton ? 'button' : 'a'\"\n ref=\"root\"\n :class=\"classes\"\n v-bind=\"attrs\"\n @click=\"onClick\"\n >\n <Nodes :nodes=\"parts()\" />\n </component>\n</template>\n"],"m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AS,KAAK;EACrB;;GAIE,OAAAC,UAAA,GAAAC,YAQYC,wBAPL,SAAA,QAAQ,WAAA,GAAA,GADfC,WAQY;IANN,SAAA;IAAJ,KAAI;IACH,OAAO,QAAA;GACA,GAAA,MAAA,OAAK,EACL,QAAO,CAAA,GAAA;IAEf,SAAAC,cAA0B,CAA1BC,YAA0B,OAAA,EAAlB,OAAO,MAAK,E"}
|
|
1
|
+
{"version":3,"file":"link.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createBlock","_resolveDynamicComponent","_mergeProps","_withCtx","_createVNode"],"sources":["../../../src/components/link/link.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ArrowUpRightIcon } from '@dou-ui/icons'\nimport {\n Comment,\n Fragment,\n Text,\n computed,\n createTextVNode,\n h,\n isVNode,\n onMounted,\n useTemplateRef,\n watchEffect,\n} from 'vue'\nimport type { VNode } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { filled } from '../../utils/slot'\nimport { devWarn } from '../../utils/status-check'\nimport type { LinkEmits, LinkProps, LinkSlots } from './link'\n\ndefineOptions({ name: 'DouLink' })\n\nconst props = withDefaults(defineProps<LinkProps>(), {\n tone: 'neutral',\n variant: 'text',\n underline: undefined,\n disabled: false,\n external: false,\n})\nconst emit = defineEmits<LinkEmits>()\nconst slots = defineSlots<LinkSlots>()\n\nconst ns = useNamespace('link')\n\n// Without an address there is nowhere to go: the link is an action, so it is\n// a button, which takes focus and responds to Enter and Space.\nconst isButton = computed(() => !props.href)\n\nif (process.env.NODE_ENV !== 'production')\n watchEffect(() => {\n if (props.external && !props.href)\n devWarn(\n '[dou-ui] DouLink: `external` opens `href` in a new tab; without an `href` the link is a button and `external` does nothing.',\n )\n })\n\n// A button inside a button is invalid: the parser splits them apart and\n// server-rendered markup no longer matches on hydration.\nconst root = useTemplateRef<HTMLElement>('root')\nif (process.env.NODE_ENV !== 'production')\n onMounted(() => {\n if (isButton.value && root.value?.parentElement?.closest('button'))\n devWarn(\n '[dou-ui] DouLink: without an `href` the link is a button, and it sits inside another button. Pass an `href`, or move it out of the clickable element.',\n )\n })\n\n// A label written on its own lines in a template starts and ends with a\n// space, which would show under the underline or inside a soft fill. Slots\n// passed on by a wrapper come as fragments, and a `v-if` leaves a comment:\n// look through both for the first and last text. A fragment that holds\n// nothing but spaces is passed over for the next node.\n//\n// A soft link breaks with the line, and an icon must not be left alone at\n// the end of one: the first and last characters of the label are taken out\n// to sit beside the icons in a span that never breaks. A character inside\n// an element of its own (`<strong>`) stays where it is.\ntype Edge = 'start' | 'end'\ntype Walk = { nodes: unknown[]; done: boolean; char: string }\nfunction cut(text: string, edge: Edge, take: boolean): [rest: string, char: string] {\n const trimmed = edge === 'start' ? text.trimStart() : text.trimEnd()\n if (!take || !trimmed) return [trimmed, '']\n const chars = Array.from(trimmed)\n return edge === 'start'\n ? [chars.slice(1).join(''), chars[0] ?? '']\n : [chars.slice(0, -1).join(''), chars[chars.length - 1] ?? '']\n}\nfunction walk(nodes: unknown[], edge: Edge, take: boolean): Walk {\n const out = [...nodes]\n const step = edge === 'start' ? 1 : -1\n for (let index = step > 0 ? 0 : out.length - 1; index >= 0 && index < out.length; index += step) {\n const node = out[index]\n if (typeof node === 'string' || (isVNode(node) && node.type === Text)) {\n const text = typeof node === 'string' ? node : node.children\n if (typeof text !== 'string') return { nodes: out, done: true, char: '' }\n const [rest, char] = cut(text, edge, take)\n out[index] = typeof node === 'string' ? rest : createTextVNode(rest)\n if (char || rest) return { nodes: out, done: true, char }\n continue\n }\n if (!isVNode(node) || node.type === Comment) continue\n if (node.type === Fragment && Array.isArray(node.children)) {\n const inner = walk(node.children, edge, take)\n out[index] = { ...node, children: inner.nodes } as VNode\n if (inner.done) return { ...inner, nodes: out }\n continue\n }\n return { nodes: out, done: true, char: '' }\n }\n return { nodes: out, done: false, char: '' }\n}\n// Called in this component's own render, so it follows slots that come\n// and go; `Nodes` only puts the result down.\nconst parts = () => {\n const label = (slots.default?.() ?? []) as unknown[]\n const soft = props.variant === 'soft'\n // a slot that renders nothing counts as not passed: no empty icon, and\n // an external link keeps its arrow\n const leading = filled(slots.leading)\n const own = filled(slots.trailing)\n const arrow = !own\n const trailing = own ?? (props.external && !isButton.value ? h(ArrowUpRightIcon) : undefined)\n const head = walk(label, 'start', soft && !!leading)\n const tail = walk(head.nodes, 'end', soft && !!trailing)\n const icon = (content: unknown, external = false) =>\n h(\n 'span',\n {\n class: [ns.e('icon'), external && ns.e('external')],\n 'aria-hidden': external ? 'true' : undefined,\n },\n content as VNode[],\n )\n const before = leading ? icon(leading) : undefined\n const after = trailing ? icon(trailing, arrow) : undefined\n const body = h('span', { class: ns.e('label') }, tail.nodes as VNode[])\n if (!soft) return [before, body, after]\n // a single character between two icons: all three break as one\n if (before && after && head.char && !tail.char)\n return [h('span', { class: [ns.e('lead'), ns.e('trail')] }, [before, head.char, body, after])]\n return [\n before && h('span', { class: ns.e('lead') }, [before, head.char]),\n body,\n after && h('span', { class: ns.e('trail') }, [tail.char, after]),\n ]\n}\nconst Nodes = (nodes: { nodes: unknown }) => nodes.nodes as VNode[]\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.tone),\n ns.m(props.variant),\n ns.m(`underline-${props.underline ?? (props.variant === 'soft' ? 'none' : 'always')}`),\n ns.is('disabled', props.disabled),\n])\n\nconst attrs = computed(() =>\n isButton.value\n ? { type: 'button', disabled: props.disabled }\n : {\n href: props.disabled ? undefined : props.href,\n target: props.external ? '_blank' : undefined,\n rel: props.external ? 'noopener noreferrer' : undefined,\n 'aria-disabled': props.disabled || undefined,\n },\n)\n\nfunction onClick(event: MouseEvent) {\n if (props.disabled) {\n event.preventDefault()\n return\n }\n emit('click', event)\n}\n</script>\n\n<template>\n <component\n :is=\"isButton ? 'button' : 'a'\"\n ref=\"root\"\n :class=\"classes\"\n v-bind=\"attrs\"\n @click=\"onClick\"\n >\n <Nodes :nodes=\"parts()\" />\n </component>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;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B;;GAIE,OAAAC,UAAA,GAAAC,YAQYC,wBAPL,SAAA,QAAQ,WAAA,GAAA,GADfC,WAQY;IANN,SAAA;IAAJ,KAAI;IACH,OAAO,QAAA;GACA,GAAA,MAAA,OAAK,EACL,QAAO,CAAA,GAAA;IAEf,SAAAC,cAA0B,CAA1BC,YAA0B,OAAA,EAAlB,OAAO,MAAK,E"}
|
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
import { useNamespace } from "../../utils/namespace.js";
|
|
2
|
+
import { rendersSomething } from "../../utils/slot.js";
|
|
2
3
|
import { useResizeObserver } from "../../composables/use-element-size.js";
|
|
3
4
|
import { menuKey } from "./menu.js";
|
|
4
|
-
import {
|
|
5
|
+
import { defineComponent, h, inject, nextTick, onBeforeUpdate, onUpdated, shallowRef } from "vue";
|
|
5
6
|
// src/components/menu/menu-actions.ts
|
|
6
|
-
/** Whether the slot drew anything for this item: it may leave most items alone. */
|
|
7
|
-
function drawn(nodes) {
|
|
8
|
-
if (!Array.isArray(nodes)) return false;
|
|
9
|
-
return nodes.some((node) => {
|
|
10
|
-
if (!isVNode(node)) return node != null && node !== false && node !== "";
|
|
11
|
-
if (node.type === Comment) return false;
|
|
12
|
-
if (node.type === Text) return String(node.children ?? "").trim() !== "";
|
|
13
|
-
if (node.type === Fragment) return drawn(node.children);
|
|
14
|
-
return true;
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
7
|
var menu_actions_default = defineComponent({
|
|
18
8
|
name: "DouMenuActions",
|
|
19
9
|
props: {
|
|
@@ -53,7 +43,7 @@ var menu_actions_default = defineComponent({
|
|
|
53
43
|
item: props.item,
|
|
54
44
|
selected: props.selected
|
|
55
45
|
});
|
|
56
|
-
return
|
|
46
|
+
return rendersSomething(nodes) ? h("span", {
|
|
57
47
|
ref: setEl,
|
|
58
48
|
class: ns.e("actions")
|
|
59
49
|
}, nodes) : null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-actions.js","names":[],"sources":["../../../src/components/menu/menu-actions.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"menu-actions.js","names":[],"sources":["../../../src/components/menu/menu-actions.ts"],"sourcesContent":["import { defineComponent, h, inject, nextTick, onBeforeUpdate, onUpdated, shallowRef } from 'vue'\nimport type { PropType, VNode } from 'vue'\nimport { useResizeObserver } from '../../composables/use-element-size'\nimport { useNamespace } from '../../utils/namespace'\nimport { rendersSomething } from '../../utils/slot'\nimport { menuKey } from './menu'\nimport type { MenuItemOption } from './menu'\n\nexport default defineComponent({\n name: 'DouMenuActions',\n props: {\n item: { type: Object as PropType<MenuItemOption>, required: true },\n selected: { type: Boolean, default: false },\n },\n setup(props) {\n const ns = useNamespace('menu')\n const menu = inject(menuKey)!\n\n const el = shallowRef<HTMLElement | null>(null)\n const setEl = (value: unknown) => (el.value = value instanceof HTMLElement ? value : null)\n\n // The item keeps clear of the actions laid over its end: it takes their\n // width as end padding (see menu.css).\n useResizeObserver(el, ([entry]) => {\n const li = el.value?.parentElement\n if (li && entry)\n li.style.setProperty('--dou-menu-actions-width', `${entry.contentRect.width}px`)\n })\n\n // A button that goes away once pressed (\"done\") would leave the focus on\n // the page: hand it back to the item of the same row.\n let row: HTMLElement | null = null\n onBeforeUpdate(() => {\n row = el.value?.contains(document.activeElement) ? el.value.parentElement : null\n })\n onUpdated(() => {\n const li = row\n row = null\n if (!li) return\n void nextTick(() => {\n if (li.contains(document.activeElement)) return\n li.querySelector<HTMLElement>(':scope > .dou-menu__item')?.focus()\n })\n })\n\n // The slot is called once a render; nothing is drawn for an item it leaves\n // alone. Beside the item, never in it: a button may not hold another one.\n return () => {\n const nodes = menu.actionsSlot()?.({ item: props.item, selected: props.selected }) as\n VNode[] | undefined\n return rendersSomething(nodes)\n ? h('span', { ref: setEl, class: ns.e('actions') }, nodes)\n : null\n }\n },\n})\n"],"mappings":";;;;;;AAQA,IAAA,uBAAe,gBAAgB;CAC7B,MAAM;CACN,OAAO;EACL,MAAM;GAAE,MAAM;GAAoC,UAAU;EAAK;EACjE,UAAU;GAAE,MAAM;GAAS,SAAS;EAAM;CAC5C;CACA,MAAM,OAAO;EACX,MAAM,KAAK,aAAa,MAAM;EAC9B,MAAM,OAAO,OAAO,OAAO;EAE3B,MAAM,KAAK,WAA+B,IAAI;EAC9C,MAAM,SAAS,UAAoB,GAAG,QAAQ,iBAAiB,cAAc,QAAQ;EAIrF,kBAAkB,KAAK,CAAC,WAAW;GACjC,MAAM,KAAK,GAAG,OAAO;GACrB,IAAI,MAAM,OACR,GAAG,MAAM,YAAY,4BAA4B,GAAG,MAAM,YAAY,MAAM,GAAG;EACnF,CAAC;EAID,IAAI,MAA0B;EAC9B,qBAAqB;GACnB,MAAM,GAAG,OAAO,SAAS,SAAS,aAAa,IAAI,GAAG,MAAM,gBAAgB;EAC9E,CAAC;EACD,gBAAgB;GACd,MAAM,KAAK;GACX,MAAM;GACN,IAAI,CAAC,IAAI;GACT,eAAoB;IAClB,IAAI,GAAG,SAAS,SAAS,aAAa,GAAG;IACzC,GAAG,cAA2B,0BAA0B,CAAC,EAAE,MAAM;GACnE,CAAC;EACH,CAAC;EAID,aAAa;GACX,MAAM,QAAQ,KAAK,YAAY,CAAC,GAAG;IAAE,MAAM,MAAM;IAAM,UAAU,MAAM;GAAS,CAAC;GAEjF,OAAO,iBAAiB,KAAK,IACzB,EAAE,QAAQ;IAAE,KAAK;IAAO,OAAO,GAAG,EAAE,SAAS;GAAE,GAAG,KAAK,IACvD;EACN;CACF;AACF,CAAC"}
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import { useNamespace } from "../../utils/namespace.js";
|
|
2
|
+
import { rendersSomething } from "../../utils/slot.js";
|
|
2
3
|
import { statusDotProps } from "./status-dot.js";
|
|
3
|
-
import {
|
|
4
|
+
import { defineComponent, h } from "vue";
|
|
4
5
|
// src/components/status-dot/status-dot.vue?vue&type=script&lang.ts
|
|
5
|
-
/** Whether rendered slot content shows anything: comments, `v-if`s and empty text don't. */
|
|
6
|
-
function hasContent(nodes) {
|
|
7
|
-
return nodes.some((node) => {
|
|
8
|
-
if (node.type === Comment) return false;
|
|
9
|
-
if (node.type === Text) return String(node.children ?? "").trim() !== "";
|
|
10
|
-
if (node.type === Fragment) return Array.isArray(node.children) && hasContent(node.children);
|
|
11
|
-
return true;
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
6
|
var status_dot_vue_vue_type_script_lang_default = defineComponent({
|
|
15
7
|
name: "DouStatusDot",
|
|
16
8
|
props: statusDotProps,
|
|
@@ -19,7 +11,7 @@ var status_dot_vue_vue_type_script_lang_default = defineComponent({
|
|
|
19
11
|
const ns = useNamespace("status-dot");
|
|
20
12
|
return () => {
|
|
21
13
|
const content = slots.default?.();
|
|
22
|
-
const text =
|
|
14
|
+
const text = rendersSomething(content);
|
|
23
15
|
const label = text ? void 0 : props.label ?? attrs["aria-label"];
|
|
24
16
|
return h("span", {
|
|
25
17
|
class: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-dot.vue_vue_type_script_lang.js","names":[],"sources":["../../../src/components/status-dot/status-dot.vue"],"sourcesContent":["<script lang=\"ts\">\nimport {
|
|
1
|
+
{"version":3,"file":"status-dot.vue_vue_type_script_lang.js","names":[],"sources":["../../../src/components/status-dot/status-dot.vue"],"sourcesContent":["<script lang=\"ts\">\nimport { defineComponent, h, type SlotsType, type VNode } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { rendersSomething } from '../../utils/slot'\nimport { statusDotProps, type StatusDotSlots } from './status-dot'\n\n// A render function rather than a template: slots and attrs are not reactive,\n// so whether text sits beside the dot is read on every render, from what the\n// slot actually renders.\nexport default defineComponent({\n name: 'DouStatusDot',\n props: statusDotProps,\n slots: Object as SlotsType<StatusDotSlots>,\n setup(props, { slots, attrs }) {\n const ns = useNamespace('status-dot')\n return () => {\n const content = slots.default?.() as VNode[] | undefined\n const text = rendersSomething(content)\n // With text beside it the text speaks for the dot; a bare dot speaks\n // through `label`, or an `aria-label` written on it directly.\n const label = text ? undefined : (props.label ?? (attrs['aria-label'] as string | undefined))\n return h(\n 'span',\n {\n class: [ns.b(), ns.m(props.tone), ns.m(props.size), ns.is('ripple', props.ripple)],\n role: label ? 'img' : undefined,\n 'aria-label': label,\n 'aria-hidden': !text && !label ? 'true' : undefined,\n },\n [\n h('span', { class: ns.e('dot'), 'aria-hidden': 'true' }),\n text ? h('span', { class: ns.e('label') }, content) : null,\n ],\n )\n }\n },\n})\n</script>\n"],"mappings":";;;;;AASA,IAAA,8CAAe,gBAAgB;CAC7B,MAAM;CACN,OAAO;CACP,OAAO;CACP,MAAM,OAAO,EAAE,OAAO,SAAS;EAC7B,MAAM,KAAK,aAAa,YAAY;EACpC,aAAa;GACX,MAAM,UAAU,MAAM,UAAU;GAChC,MAAM,OAAO,iBAAiB,OAAO;GAGrC,MAAM,QAAQ,OAAO,KAAA,IAAa,MAAM,SAAU,MAAM;GACxD,OAAO,EACL,QACA;IACE,OAAO;KAAC,GAAG,EAAE;KAAG,GAAG,EAAE,MAAM,IAAI;KAAG,GAAG,EAAE,MAAM,IAAI;KAAG,GAAG,GAAG,UAAU,MAAM,MAAM;IAAC;IACjF,MAAM,QAAQ,QAAQ,KAAA;IACtB,cAAc;IACd,eAAe,CAAC,QAAQ,CAAC,QAAQ,SAAS,KAAA;GAC5C,GACA,CACE,EAAE,QAAQ;IAAE,OAAO,GAAG,EAAE,KAAK;IAAG,eAAe;GAAO,CAAC,GACvD,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,EAAE,OAAO,EAAE,GAAG,OAAO,IAAI,IACxD,CACF;EACF;CACF;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-dot2.js","names":["_sfc_main"],"sources":["../../../src/components/status-dot/status-dot.vue"],"sourcesContent":["<script lang=\"ts\">\nimport {
|
|
1
|
+
{"version":3,"file":"status-dot2.js","names":["_sfc_main"],"sources":["../../../src/components/status-dot/status-dot.vue"],"sourcesContent":["<script lang=\"ts\">\nimport { defineComponent, h, type SlotsType, type VNode } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { rendersSomething } from '../../utils/slot'\nimport { statusDotProps, type StatusDotSlots } from './status-dot'\n\n// A render function rather than a template: slots and attrs are not reactive,\n// so whether text sits beside the dot is read on every render, from what the\n// slot actually renders.\nexport default defineComponent({\n name: 'DouStatusDot',\n props: statusDotProps,\n slots: Object as SlotsType<StatusDotSlots>,\n setup(props, { slots, attrs }) {\n const ns = useNamespace('status-dot')\n return () => {\n const content = slots.default?.() as VNode[] | undefined\n const text = rendersSomething(content)\n // With text beside it the text speaks for the dot; a bare dot speaks\n // through `label`, or an `aria-label` written on it directly.\n const label = text ? undefined : (props.label ?? (attrs['aria-label'] as string | undefined))\n return h(\n 'span',\n {\n class: [ns.b(), ns.m(props.tone), ns.m(props.size), ns.is('ripple', props.ripple)],\n role: label ? 'img' : undefined,\n 'aria-label': label,\n 'aria-hidden': !text && !label ? 'true' : undefined,\n },\n [\n h('span', { class: ns.e('dot'), 'aria-hidden': 'true' }),\n text ? h('span', { class: ns.e('label') }, content) : null,\n ],\n )\n }\n },\n})\n</script>\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag.js","names":["_sfc_main"],"sources":["../../../src/components/tag/tag.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CloseIcon } from '@dou-ui/icons'\nimport { computed, ref, useAttrs, useTemplateRef } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { useLocale } from '../config-provider/use-config'\nimport { useFormSize } from '../form/use-form-item'\nimport type { TagEmits, TagProps, TagSlots } from './tag'\n\ndefineOptions({ name: 'DouTag' })\n\nconst props = withDefaults(defineProps<TagProps>(), {\n variant: 'soft',\n tone: 'neutral',\n closable: false,\n round: false,\n})\nconst emit = defineEmits<TagEmits>()\nconst slots = defineSlots<TagSlots>()\n\nconst ns = useNamespace('tag')\nconst { t } = useLocale()\nconst size = useFormSize(() => props.size)\n\n// A label cut short by the ellipsis shows the whole text on hover. Measured\n// only when the pointer arrives, so a page of tags costs nothing until then.\n// A `title` given to the tag is the user's own and always wins.\nconst attrs = useAttrs()\nconst labelRef = useTemplateRef<HTMLElement>('label')\nconst labelTitle = ref<string>()\nfunction onLabelEnter() {\n const el = labelRef.value\n if (!el || attrs.title != null) {\n labelTitle.value = undefined\n return\n }\n labelTitle.value =\n el.scrollWidth > el.clientWidth ? el.textContent?.trim() || undefined : undefined\n}\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.variant),\n ns.m(props.tone),\n ns.m(size.value),\n ns.is('round', props.round),\n])\n</script>\n\n<template>\n <span :class=\"classes\">\n <
|
|
1
|
+
{"version":3,"file":"tag.js","names":["_sfc_main"],"sources":["../../../src/components/tag/tag.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { CloseIcon } from '@dou-ui/icons'\nimport { computed, ref, useAttrs, useTemplateRef } from 'vue'\nimport { useNamespace } from '../../utils/namespace'\nimport { SlotNodes, filled } from '../../utils/slot'\nimport { useLocale } from '../config-provider/use-config'\nimport { useFormSize } from '../form/use-form-item'\nimport type { TagEmits, TagProps, TagSlots } from './tag'\n\ndefineOptions({ name: 'DouTag' })\n\nconst props = withDefaults(defineProps<TagProps>(), {\n variant: 'soft',\n tone: 'neutral',\n closable: false,\n round: false,\n})\nconst emit = defineEmits<TagEmits>()\nconst slots = defineSlots<TagSlots>()\n\nconst ns = useNamespace('tag')\nconst { t } = useLocale()\nconst size = useFormSize(() => props.size)\n\n// A label cut short by the ellipsis shows the whole text on hover. Measured\n// only when the pointer arrives, so a page of tags costs nothing until then.\n// A `title` given to the tag is the user's own and always wins.\nconst attrs = useAttrs()\nconst labelRef = useTemplateRef<HTMLElement>('label')\nconst labelTitle = ref<string>()\nfunction onLabelEnter() {\n const el = labelRef.value\n if (!el || attrs.title != null) {\n labelTitle.value = undefined\n return\n }\n labelTitle.value =\n el.scrollWidth > el.clientWidth ? el.textContent?.trim() || undefined : undefined\n}\n\nconst classes = computed(() => [\n ns.b(),\n ns.m(props.variant),\n ns.m(props.tone),\n ns.m(size.value),\n ns.is('round', props.round),\n])\n</script>\n\n<template>\n <span :class=\"classes\">\n <!-- rendered once: a leading slot that renders nothing leaves no icon -->\n <template v-for=\"leading in [filled(slots.leading)]\" :key=\"0\">\n <span v-if=\"leading\" :class=\"ns.e('icon')\"><SlotNodes :nodes=\"leading\" /></span>\n </template>\n <span ref=\"label\" :class=\"ns.e('label')\" :title=\"labelTitle\" @pointerenter=\"onLabelEnter\">\n <slot />\n </span>\n <button\n v-if=\"closable\"\n type=\"button\"\n :class=\"ns.e('close')\"\n :aria-label=\"closeLabel ?? t('tag.remove')\"\n @click=\"emit('close', $event)\"\n >\n <CloseIcon />\n </button>\n </span>\n</template>\n"],"mappings":""}
|