@lingtools/ui 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +78 -2
  3. package/dist/index.js +320 -0
  4. package/dist/src/components/LingActionItem/LingActionItem.d.ts +31 -0
  5. package/dist/src/components/LingActionItem/LingActionItem.vue.d.ts +25 -0
  6. package/dist/src/components/LingActionItem/index.d.ts +8 -0
  7. package/dist/src/components/LingActionPanel/LingActionPanel.d.ts +85 -0
  8. package/dist/src/components/LingActionPanel/LingActionPanel.vue.d.ts +35 -0
  9. package/dist/src/components/LingActionPanel/filter.d.ts +11 -0
  10. package/dist/src/components/LingActionPanel/index.d.ts +12 -0
  11. package/dist/src/components/LingDevBadge/LingDevBadge.d.ts +5 -0
  12. package/dist/src/components/LingDevBadge/LingDevBadge.vue.d.ts +3 -0
  13. package/dist/src/components/LingDevBadge/index.d.ts +4 -0
  14. package/dist/src/components/LingFooter/LingFooter.d.ts +5 -0
  15. package/dist/src/components/LingFooter/LingFooter.vue.d.ts +22 -0
  16. package/dist/src/components/LingFooter/index.d.ts +4 -0
  17. package/dist/src/components/LingFooterDivider/LingFooterDivider.d.ts +4 -0
  18. package/dist/src/components/LingFooterDivider/LingFooterDivider.vue.d.ts +3 -0
  19. package/dist/src/components/LingFooterDivider/index.d.ts +4 -0
  20. package/dist/src/components/LingKeycaps/LingKeycaps.d.ts +12 -0
  21. package/dist/src/components/LingKeycaps/LingKeycaps.vue.d.ts +9 -0
  22. package/dist/src/components/LingKeycaps/index.d.ts +8 -0
  23. package/dist/src/components/LingShortcutButton/LingShortcutButton.d.ts +14 -0
  24. package/dist/src/components/LingShortcutButton/LingShortcutButton.vue.d.ts +20 -0
  25. package/dist/src/components/LingShortcutButton/index.d.ts +8 -0
  26. package/dist/src/composables/use-list-selection.d.ts +85 -0
  27. package/dist/src/index.d.ts +69 -0
  28. package/dist/src/theme/index.d.ts +13 -0
  29. package/dist/src/theme/use-theme.d.ts +130 -0
  30. package/dist/style.css +2 -0
  31. package/dist/theme.js +4 -0
  32. package/dist/tokens.generated.less +127 -0
  33. package/dist/tokens.less +50 -0
  34. package/dist/vite.d.ts +22 -0
  35. package/dist/vite.js +49 -0
  36. package/package.json +77 -3
  37. package/src/components/LingActionItem/LingActionItem.ts +32 -0
  38. package/src/components/LingActionItem/LingActionItem.vue +105 -0
  39. package/src/components/LingActionItem/index.ts +8 -0
  40. package/src/components/LingActionPanel/LingActionPanel.ts +89 -0
  41. package/src/components/LingActionPanel/LingActionPanel.vue +340 -0
  42. package/src/components/LingActionPanel/filter.ts +25 -0
  43. package/src/components/LingActionPanel/index.ts +17 -0
  44. package/src/components/LingDevBadge/LingDevBadge.ts +5 -0
  45. package/src/components/LingDevBadge/LingDevBadge.vue +33 -0
  46. package/src/components/LingDevBadge/index.ts +4 -0
  47. package/src/components/LingFooter/LingFooter.ts +5 -0
  48. package/src/components/LingFooter/LingFooter.vue +55 -0
  49. package/src/components/LingFooter/index.ts +4 -0
  50. package/src/components/LingFooterDivider/LingFooterDivider.ts +4 -0
  51. package/src/components/LingFooterDivider/LingFooterDivider.vue +23 -0
  52. package/src/components/LingFooterDivider/index.ts +4 -0
  53. package/src/components/LingKeycaps/LingKeycaps.ts +13 -0
  54. package/src/components/LingKeycaps/LingKeycaps.vue +51 -0
  55. package/src/components/LingKeycaps/index.ts +8 -0
  56. package/src/components/LingShortcutButton/LingShortcutButton.ts +15 -0
  57. package/src/components/LingShortcutButton/LingShortcutButton.vue +71 -0
  58. package/src/components/LingShortcutButton/index.ts +8 -0
  59. package/src/composables/use-list-selection.ts +202 -0
  60. package/src/index.ts +97 -0
  61. package/src/theme/base.css +45 -0
  62. package/src/theme/index.ts +13 -0
  63. package/src/theme/tokens.generated.less +127 -0
  64. package/src/theme/tokens.json +308 -0
  65. package/src/theme/tokens.less +50 -0
  66. package/src/theme/use-theme.ts +227 -0
package/package.json CHANGED
@@ -1,6 +1,80 @@
1
1
  {
2
2
  "name": "@lingtools/ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "lingtools 插件界面库:主题、底栏、键帽、操作面板与 Vite 插件",
5
+ "type": "module",
6
+ "license": "MPL-2.0",
7
+ "author": "xiaou66",
8
+ "keywords": [
9
+ "lingtools",
10
+ "plugin",
11
+ "ui",
12
+ "vue",
13
+ "element-plus",
14
+ "arco-design",
15
+ "unocss",
16
+ "vite"
17
+ ],
18
+ "types": "./dist/src/index.d.ts",
19
+ "files": [
20
+ "dist",
21
+ "src",
22
+ "!src/**/__tests__/**"
23
+ ],
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/src/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ },
29
+ "./theme": {
30
+ "types": "./dist/src/theme/index.d.ts",
31
+ "default": "./dist/theme.js"
32
+ },
33
+ "./tokens.less": "./dist/tokens.less",
34
+ "./vite": {
35
+ "types": "./dist/vite.d.ts",
36
+ "default": "./dist/vite.js"
37
+ }
38
+ },
39
+ "publishConfig": {
40
+ "access": "public",
41
+ "registry": "https://registry.npmjs.org/"
42
+ },
43
+ "peerDependencies": {
44
+ "@vueuse/core": "^14.4.0",
45
+ "element-plus": "^2.14.7",
46
+ "vite": "^8.3.5",
47
+ "vue": "^3.5.44"
48
+ },
49
+ "dependencies": {
50
+ "@vitejs/plugin-vue": "^6.0.10",
51
+ "@vitejs/plugin-vue-jsx": "^5.1.6",
52
+ "code-inspector-plugin": "^2.0.9",
53
+ "element-plus-theme-arco": "^1.1.0",
54
+ "unocss": "^66.11.0",
55
+ "unplugin-auto-import": "^21.1.0",
56
+ "unplugin-vue-components": "^32.1.0",
57
+ "vite-plugin-vue-devtools": "^8.2.1"
58
+ },
59
+ "devDependencies": {
60
+ "@types/node": "^24.19.2",
61
+ "@vue/test-utils": "^2.5.1",
62
+ "@vueuse/core": "^14.4.0",
63
+ "element-plus": "^2.14.7",
64
+ "jsdom": "^29.1.1",
65
+ "less": "^4.9.1",
66
+ "oxlint": "~1.83.0",
67
+ "typescript": "~6.0.3",
68
+ "vite": "^8.3.5",
69
+ "vitest": "^4.1.12",
70
+ "vue": "^3.5.44",
71
+ "vue-tsc": "^3.3.13"
72
+ },
73
+ "scripts": {
74
+ "build": "pnpm run build:package",
75
+ "build:package": "vite build -c vite.lib.config.ts && vue-tsc -p tsconfig.build.json && node scripts/package-assets.mjs",
76
+ "typecheck": "vue-tsc --noEmit",
77
+ "lint": "oxlint . --fix",
78
+ "test": "vitest run"
79
+ }
6
80
  }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * 操作行契约:操作面板里的一行,「[图标] 名称 [后缀] 键帽」,带当前 / 禁用 / 危险三种状态。
3
+ * 只负责显示与无障碍属性;键盘、过滤与执行由所在面板负责。
4
+ * `id`、`click`、`mousemove`、`mousedown.prevent`、`aria-checked` 等经属性透传到根元素。
5
+ * 行高取 CSS 变量 `--ling-action-item-height`(默认 36px),需要按行高计算面板高度的使用方用同一个常量设置它。
6
+ */
7
+
8
+ /**
9
+ * 操作行的输入。
10
+ */
11
+ export interface LingActionItemProps {
12
+ /**
13
+ * 显示名称。
14
+ */
15
+ title: string
16
+ /**
17
+ * 键帽文字,按显示顺序;由调用方按平台生成,空数组(默认)时不画键帽。
18
+ */
19
+ keys?: readonly string[]
20
+ /**
21
+ * 是否为键盘 / 鼠标的当前项(画选中底色);由所在面板持有。
22
+ */
23
+ current?: boolean
24
+ /**
25
+ * 是否不可执行:文字置灰、键帽变淡;是否响应单击由所在面板决定。
26
+ */
27
+ disabled?: boolean
28
+ /**
29
+ * 是否为危险操作(删除、清空):图标与文字用危险色。
30
+ */
31
+ danger?: boolean
32
+ }
@@ -0,0 +1,105 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * 操作行:图标、名称(占满剩余宽度,超长省略)、后缀、键帽靠右;当前行整行高亮。
4
+ * 图标与后缀由使用方经插槽提供(项目图标类名只写在使用方自己的 `.vue` 里)。
5
+ */
6
+ import LingKeycaps from '../LingKeycaps'
7
+ import type { LingActionItemProps } from './LingActionItem'
8
+
9
+ withDefaults(defineProps<LingActionItemProps>(), {
10
+ keys: () => [],
11
+ current: false,
12
+ disabled: false,
13
+ danger: false,
14
+ })
15
+
16
+ defineSlots<{
17
+ /**
18
+ * 名称前的图标,16px,颜色跟随文字色。
19
+ */
20
+ icon?(): unknown
21
+ /**
22
+ * 名称与键帽之间的附加标记(如开关项开启时的勾)。
23
+ */
24
+ suffix?(): unknown
25
+ }>()
26
+ </script>
27
+
28
+ <template>
29
+ <div
30
+ class="ling-action-item"
31
+ :class="{
32
+ 'ling-action-item--current': current,
33
+ 'ling-action-item--disabled': disabled,
34
+ 'ling-action-item--danger': danger,
35
+ }"
36
+ role="option"
37
+ :aria-selected="current"
38
+ :aria-disabled="disabled"
39
+ >
40
+ <span
41
+ v-if="$slots.icon"
42
+ class="ling-action-item__icon"
43
+ aria-hidden="true"
44
+ >
45
+ <slot name="icon" />
46
+ </span>
47
+ <span class="ling-action-item__title">{{ title }}</span>
48
+ <slot name="suffix" />
49
+ <LingKeycaps
50
+ v-if="keys.length > 0"
51
+ class="ling-action-item__keys"
52
+ :keys="keys"
53
+ />
54
+ </div>
55
+ </template>
56
+
57
+ <style lang="less" scoped>
58
+ .ling-action-item {
59
+ display: flex;
60
+ align-items: center;
61
+ gap: 10px;
62
+ box-sizing: border-box;
63
+ height: var(--ling-action-item-height, 36px);
64
+ padding: 0 10px;
65
+ border-radius: var(--u-launcher-item-radius);
66
+ color: var(--u-launcher-text);
67
+ cursor: default;
68
+
69
+ &--current {
70
+ background: var(--u-launcher-item-current-bg);
71
+ }
72
+
73
+ &--disabled {
74
+ color: var(--u-launcher-placeholder);
75
+
76
+ .ling-action-item__keys {
77
+ opacity: 0.5;
78
+ }
79
+ }
80
+
81
+ &--danger {
82
+ color: var(--u-launcher-danger);
83
+ }
84
+ }
85
+
86
+ /* 图标容器:16px,颜色跟随行的文字色(当前行、禁用行、危险行一致) */
87
+ .ling-action-item__icon {
88
+ display: inline-flex;
89
+ flex: none;
90
+ align-items: center;
91
+ justify-content: center;
92
+ width: 16px;
93
+ height: 16px;
94
+ font-size: 16px;
95
+ }
96
+
97
+ .ling-action-item__title {
98
+ flex: 1;
99
+ min-width: 0;
100
+ overflow: hidden;
101
+ font-size: var(--u-launcher-item-font-size);
102
+ text-overflow: ellipsis;
103
+ white-space: nowrap;
104
+ }
105
+ </style>
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 公开操作行组件,供搜索栏与插件的操作面板使用。
3
+ */
4
+ export { default } from './LingActionItem.vue'
5
+ /**
6
+ * 公开操作行的输入契约。
7
+ */
8
+ export type { LingActionItemProps } from './LingActionItem'
@@ -0,0 +1,89 @@
1
+ /**
2
+ * 操作面板契约(插件页面内的 ⌘K 面板):标题、按组分隔的操作行(组可以带小标题)、底部搜索框。
3
+ * 面板只负责选择:过滤、当前项、键盘与点外收起在面板内完成;执行由父级按操作标识处理,
4
+ * 显隐由父级 `v-if` 控制、定位由父级给 class。
5
+ * 按键冒泡:只有 Esc 在面板内 `stopPropagation`(不让 SDK 当成退出插件);↑↓、↵ 只 `preventDefault`,
6
+ * 仍会冒泡到父级的键盘分派,父级在面板打开时要忽略它们;其他组合键照常交给父级。
7
+ */
8
+
9
+ /**
10
+ * 操作面板里的一项。
11
+ */
12
+ export interface LingActionPanelItem<T extends string> {
13
+ /**
14
+ * 操作标识,`run` 事件原样带回。
15
+ */
16
+ id: T
17
+ /**
18
+ * 显示名称(中文)。
19
+ */
20
+ title: string
21
+ /**
22
+ * 英文别名,只参与搜索、不显示;没有时只按名称搜索。
23
+ */
24
+ alias?: string
25
+ /**
26
+ * 是否可执行:不可执行的置灰、键盘移动时跳过、单击无效。
27
+ */
28
+ enabled: boolean
29
+ /**
30
+ * 分组标识:未搜索时,相邻两项分组不同就在中间画分隔线。
31
+ */
32
+ section: string | number
33
+ /**
34
+ * 键帽文字,由调用方按平台换算好;没有快捷键时不传。
35
+ */
36
+ keys?: readonly string[]
37
+ /**
38
+ * 是否为危险操作(删除、清空),画危险色。
39
+ */
40
+ danger?: boolean
41
+ /**
42
+ * 开关项的当前状态:有这个字段时行尾画开关(只显示,切换由父级在 `run` 里完成),行上标出 `aria-checked`;
43
+ * 普通操作不传。
44
+ */
45
+ checked?: boolean
46
+ }
47
+
48
+ /**
49
+ * 操作面板的输入。
50
+ */
51
+ export interface LingActionPanelProps<T extends string> {
52
+ /**
53
+ * 面板标题:选中行的名称与概况(如「Google Chrome · 24 个进程」)。
54
+ */
55
+ title: string
56
+ /**
57
+ * 选中行的全部操作,已按显示顺序排列;父级持有,面板打开期间可以更新(如可用性变化)。
58
+ */
59
+ actions: readonly LingActionPanelItem<T>[]
60
+ /**
61
+ * 组的小标题,按 `section` 取;未搜索时画在该组第一项上方,代替与上一组之间的分隔线。没有标题的组照常画分隔线。
62
+ * 由父级持有,缺省时都不画。
63
+ */
64
+ sections?: Readonly<Partial<Record<string | number, string>>>
65
+ }
66
+
67
+ /**
68
+ * 操作面板的事件。
69
+ */
70
+ export interface LingActionPanelEmits<T extends string> {
71
+ /**
72
+ * 单击或回车执行一项可用的操作。
73
+ */
74
+ run: [id: T]
75
+ /**
76
+ * Esc(搜索框为空时)或单击面板外:收起。
77
+ */
78
+ close: []
79
+ }
80
+
81
+ /**
82
+ * 父级驱动的一次性动作。
83
+ */
84
+ export interface LingActionPanelInstance {
85
+ /**
86
+ * 把焦点交给底部搜索框;父级在面板挂载后调用。
87
+ */
88
+ focus(): void
89
+ }
@@ -0,0 +1,340 @@
1
+ <script setup lang="ts" generic="T extends string">
2
+ /**
3
+ * 操作面板:打开时父级调用 `focus()`,焦点在底部搜索框;↑ / ↓ 在可用的操作间移动(跳过禁用项,首尾不循环),
4
+ * Enter 执行,Esc 先清空搜索、再收起;单击面板外收起;输入法组合中的按键不处理。
5
+ * 组之间画分隔线;组有小标题(`sections`)时画小标题代替分隔线;搜索时两者都不画。
6
+ * 开关项(`checked`)的行尾是只显示的 `el-switch`:点击穿透到行,由行执行,焦点不离开搜索框。
7
+ * 容器没有用 ElPopover / ElDropdown:面板固定在页面右下角、底栏上方,按 ⌘K 打开时不一定有可见的触发按钮;
8
+ * 两者 teleport 到 body,自带的点外关闭与焦点处理会和「焦点留在搜索框、Esc 在面板内拦下」冲突;下拉菜单也没有过滤输入。
9
+ */
10
+ import { computed, ref, useTemplateRef, watch } from 'vue'
11
+ import { onClickOutside } from '@vueuse/core'
12
+ import type { InputInstance } from 'element-plus'
13
+ import LingActionItem from '../LingActionItem'
14
+ import { filterActionPanelItems } from './filter'
15
+ import type {
16
+ LingActionPanelEmits,
17
+ LingActionPanelInstance,
18
+ LingActionPanelItem,
19
+ LingActionPanelProps,
20
+ } from './LingActionPanel'
21
+
22
+ const props = defineProps<LingActionPanelProps<T>>()
23
+ const emit = defineEmits<LingActionPanelEmits<T>>()
24
+
25
+ defineSlots<{
26
+ /**
27
+ * 每一项名称前的图标(项目图标类名写在使用方自己的 `.vue` 里)。
28
+ */
29
+ icon?(props: { action: LingActionPanelItem<T> }): unknown
30
+ /**
31
+ * 每一项名称与键帽之间的附加内容(如子列表的当前值与箭头、单选项的勾),图标同样由使用方提供。
32
+ */
33
+ suffix?(props: { action: LingActionPanelItem<T> }): unknown
34
+ }>()
35
+
36
+ const rootElement = useTemplateRef<HTMLElement>('root')
37
+ const inputInstance = useTemplateRef<InputInstance>('input')
38
+ /**
39
+ * 操作的搜索输入;每次挂载从空开始。
40
+ */
41
+ const queryParams = ref({ keyword: '' })
42
+ const filtered = computed(() => filterActionPanelItems(props.actions, queryParams.value.keyword))
43
+ /**
44
+ * 键盘 / 鼠标的当前项;过滤结果变化后回到第一项可用的操作。
45
+ */
46
+ const currentId = ref<T | null>(null)
47
+
48
+ /**
49
+ * 第 index 项上方的组标题:没有搜索、该项是所在组的第一项、且父级给这组写了标题。
50
+ * @param index 过滤后列表中的序号。
51
+ * @returns 标题文字;不画时为 null。
52
+ */
53
+ function sectionTitleBefore(index: number): string | null {
54
+ const item = filtered.value[index]!
55
+ const previous = filtered.value[index - 1]
56
+ if (queryParams.value.keyword.trim() || previous?.section === item.section) {
57
+ return null
58
+ }
59
+ return props.sections?.[item.section] ?? null
60
+ }
61
+
62
+ /**
63
+ * 第 index 项前是否画分隔线:没有搜索、与上一项不在同一组,且这组没有标题(有标题时标题代替分隔线)。
64
+ * @param index 过滤后列表中的序号。
65
+ * @returns 画分隔线时为 true。
66
+ */
67
+ function separatorBefore(index: number): boolean {
68
+ const previous = filtered.value[index - 1]
69
+ return (
70
+ !queryParams.value.keyword.trim() &&
71
+ previous !== undefined &&
72
+ previous.section !== filtered.value[index]!.section &&
73
+ sectionTitleBefore(index) === null
74
+ )
75
+ }
76
+
77
+ /**
78
+ * 按方向移动到下一项可用的操作,首尾不循环。
79
+ * @param step 1 为下移,-1 为上移。
80
+ */
81
+ function moveCurrent(step: 1 | -1) {
82
+ const items = filtered.value
83
+ let index = items.findIndex((item) => item.id === currentId.value)
84
+ for (index += step; index >= 0 && index < items.length; index += step) {
85
+ if (items[index]!.enabled) {
86
+ currentId.value = items[index]!.id
87
+ return
88
+ }
89
+ }
90
+ }
91
+
92
+ /**
93
+ * 执行一项(不可执行的不处理)。
94
+ * @param id 操作标识。
95
+ */
96
+ function run(id: T) {
97
+ if (props.actions.find((action) => action.id === id)?.enabled) {
98
+ emit('run', id)
99
+ }
100
+ }
101
+
102
+ /**
103
+ * 搜索框按键分派;输入法组合中的按键不处理。
104
+ * @param event 搜索框的按键事件(`el-input` 的事件类型含普通 Event)。
105
+ */
106
+ function handleKeydown(event: KeyboardEvent | Event) {
107
+ if (!(event instanceof KeyboardEvent) || event.isComposing) {
108
+ return
109
+ }
110
+ switch (event.key) {
111
+ case 'ArrowDown':
112
+ event.preventDefault()
113
+ moveCurrent(1)
114
+ break
115
+ case 'ArrowUp':
116
+ event.preventDefault()
117
+ moveCurrent(-1)
118
+ break
119
+ case 'Enter':
120
+ event.preventDefault()
121
+ if (currentId.value !== null) {
122
+ run(currentId.value)
123
+ }
124
+ break
125
+ case 'Escape':
126
+ // 在这里拦下,不让 SDK 当作「退出插件」
127
+ event.preventDefault()
128
+ event.stopPropagation()
129
+ if (queryParams.value.keyword) {
130
+ queryParams.value.keyword = ''
131
+ } else {
132
+ emit('close')
133
+ }
134
+ break
135
+ }
136
+ }
137
+
138
+ watch(
139
+ filtered,
140
+ (items) => {
141
+ currentId.value = items.find((item) => item.enabled)?.id ?? null
142
+ },
143
+ { immediate: true },
144
+ )
145
+
146
+ onClickOutside(rootElement, () => emit('close'))
147
+
148
+ defineExpose<LingActionPanelInstance>({
149
+ focus: () => inputInstance.value?.focus(),
150
+ })
151
+ </script>
152
+
153
+ <template>
154
+ <div
155
+ ref="root"
156
+ class="ling-action-panel"
157
+ role="dialog"
158
+ :aria-label="title"
159
+ >
160
+ <div class="ling-action-panel__title">{{ title }}</div>
161
+ <div
162
+ class="ling-action-panel__list"
163
+ role="listbox"
164
+ >
165
+ <template
166
+ v-for="(action, index) in filtered"
167
+ :key="action.id"
168
+ >
169
+ <div
170
+ v-if="sectionTitleBefore(index) !== null"
171
+ class="ling-action-panel__section-title"
172
+ >
173
+ {{ sectionTitleBefore(index) }}
174
+ </div>
175
+ <div
176
+ v-else-if="separatorBefore(index)"
177
+ class="ling-action-panel__separator"
178
+ aria-hidden="true"
179
+ />
180
+ <LingActionItem
181
+ :title="action.title"
182
+ :keys="action.keys"
183
+ :current="action.id === currentId"
184
+ :disabled="!action.enabled"
185
+ :danger="action.danger"
186
+ :aria-checked="action.checked"
187
+ :data-action="action.id"
188
+ @mousemove="action.enabled && (currentId = action.id)"
189
+ @click="run(action.id)"
190
+ >
191
+ <template
192
+ v-if="$slots.icon"
193
+ #icon
194
+ >
195
+ <slot
196
+ name="icon"
197
+ :action="action"
198
+ />
199
+ </template>
200
+ <template
201
+ v-if="$slots.suffix || action.checked !== undefined"
202
+ #suffix
203
+ >
204
+ <slot
205
+ name="suffix"
206
+ :action="action"
207
+ />
208
+ <el-switch
209
+ v-if="action.checked !== undefined"
210
+ class="ling-action-panel__switch"
211
+ :model-value="action.checked"
212
+ :disabled="!action.enabled"
213
+ :tabindex="-1"
214
+ size="small"
215
+ aria-hidden="true"
216
+ />
217
+ </template>
218
+ </LingActionItem>
219
+ </template>
220
+ <el-empty
221
+ v-if="filtered.length === 0"
222
+ class="ling-action-panel__empty"
223
+ :image-size="0"
224
+ description="没有匹配的操作"
225
+ />
226
+ </div>
227
+ <div class="ling-action-panel__search-row">
228
+ <el-input
229
+ ref="input"
230
+ v-model="queryParams.keyword"
231
+ class="ling-action-panel__search"
232
+ placeholder="搜索操作…"
233
+ autocomplete="off"
234
+ @keydown="handleKeydown"
235
+ />
236
+ </div>
237
+ </div>
238
+ </template>
239
+
240
+ <style lang="less" scoped>
241
+ /* 面板卡片:与插件菜单同一套令牌(毛玻璃底、边框与内高光、阴影、背景模糊) */
242
+ .ling-action-panel {
243
+ display: flex;
244
+ flex-direction: column;
245
+ box-sizing: border-box;
246
+ width: 344px;
247
+ max-height: 393px;
248
+ overflow: hidden;
249
+ border: 1px solid var(--u-launcher-border);
250
+ border-radius: var(--u-launcher-radius);
251
+ background: var(--u-launcher-panel-bg);
252
+ box-shadow:
253
+ inset 0 0 0 1px var(--u-launcher-panel-glass-highlight, transparent),
254
+ var(--u-launcher-panel-shadow);
255
+ color: var(--u-launcher-text);
256
+ /* WKWebView 在 Safari 18 之前只认带前缀的写法(macOS 14 及更早) */
257
+ -webkit-backdrop-filter: var(--u-panel-backdrop);
258
+ backdrop-filter: var(--u-panel-backdrop);
259
+ }
260
+
261
+ /* 支持背景模糊时换成更透明的玻璃底,模糊才看得出来;不支持时保留上面 0.92 的厚底,文字始终可读。
262
+ 拷了旧版令牌的插件没有玻璃令牌,退回厚底 */
263
+ @supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
264
+ .ling-action-panel {
265
+ background: var(--u-launcher-panel-glass-bg, var(--u-launcher-panel-bg));
266
+ }
267
+ }
268
+
269
+ .ling-action-panel__title {
270
+ flex: none;
271
+ padding: 12px 16px 6px;
272
+ overflow: hidden;
273
+ color: var(--u-launcher-text-secondary);
274
+ font-size: var(--u-launcher-secondary-font-size);
275
+ text-overflow: ellipsis;
276
+ white-space: nowrap;
277
+ }
278
+
279
+ .ling-action-panel__list {
280
+ flex: 1;
281
+ min-height: 0;
282
+ padding: 0 6px 6px;
283
+ overflow-y: auto;
284
+ }
285
+
286
+ .ling-action-panel__section-title {
287
+ padding: 8px 10px 4px;
288
+ overflow: hidden;
289
+ color: var(--u-launcher-text-secondary);
290
+ font-size: var(--u-launcher-secondary-font-size);
291
+ text-overflow: ellipsis;
292
+ white-space: nowrap;
293
+ }
294
+
295
+ /* 行尾开关只显示状态:点击穿透到所在行,由行执行(切换由父级在 run 里完成) */
296
+ .ling-action-panel__switch {
297
+ flex: none;
298
+ pointer-events: none;
299
+ }
300
+
301
+ .ling-action-panel__separator {
302
+ height: 1px;
303
+ margin: 4px 10px;
304
+ background: var(--u-launcher-border);
305
+ }
306
+
307
+ /* 空状态:只留一行描述文字(Element Plus 公开变量去掉图片与大块留白) */
308
+ .ling-action-panel__empty {
309
+ --el-empty-padding: 10px;
310
+ --el-empty-image-width: 0;
311
+ --el-empty-description-margin-top: 0;
312
+ --el-text-color-secondary: var(--u-launcher-text-secondary);
313
+ --el-font-size-base: var(--u-launcher-item-font-size);
314
+ }
315
+
316
+ .ling-action-panel__search-row {
317
+ flex: none;
318
+ border-top: 1px solid var(--u-launcher-border);
319
+ }
320
+
321
+ /* 搜索框压平:只用 Element Plus 与主题包的公开变量(背景、描边、聚焦描边都透明;
322
+ * 毛玻璃模式的输入底色与聚焦光圈也是变量),不覆盖组件内部选择器 */
323
+ .ling-action-panel__search {
324
+ --el-input-bg-color: transparent;
325
+ --el-input-border-color: transparent;
326
+ --el-input-hover-border-color: transparent;
327
+ --el-input-focus-border-color: transparent;
328
+ --el-input-border-radius: 0;
329
+ --el-input-height: 40px;
330
+ --el-input-text-color: var(--u-launcher-text);
331
+ --el-input-placeholder-color: var(--u-launcher-placeholder);
332
+ --glass-input-bg: transparent;
333
+ --glass-input-bg-hover: transparent;
334
+ --glass-focus-ring: 0 0 transparent;
335
+ /* 毛玻璃模式聚焦时的 1px 主色内描边取 --el-color-primary;搜索框里没有其他用到主色的元素 */
336
+ --el-color-primary: transparent;
337
+
338
+ font-size: var(--u-launcher-item-font-size);
339
+ }
340
+ </style>
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 操作面板的过滤:按中文名称或英文别名,不区分大小写。
3
+ */
4
+ import type { LingActionPanelItem } from './LingActionPanel'
5
+
6
+ /**
7
+ * 过滤操作:去掉首尾空格后不区分大小写,名称或别名包含关键字即保留;关键字为空时返回全部(新数组)。
8
+ * @param actions 全部操作,按显示顺序。
9
+ * @param keyword 搜索框的输入。
10
+ * @returns 保留的操作,顺序不变。
11
+ */
12
+ export function filterActionPanelItems<T extends string>(
13
+ actions: readonly LingActionPanelItem<T>[],
14
+ keyword: string,
15
+ ): LingActionPanelItem<T>[] {
16
+ const text = keyword.trim().toLowerCase()
17
+ if (!text) {
18
+ return [...actions]
19
+ }
20
+ return actions.filter(
21
+ (action) =>
22
+ action.title.toLowerCase().includes(text) ||
23
+ (action.alias?.toLowerCase().includes(text) ?? false),
24
+ )
25
+ }