@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
@@ -0,0 +1,17 @@
1
+ /**
2
+ * 公开操作面板组件,供插件页面内的 ⌘K 面板使用。
3
+ */
4
+ export { default } from './LingActionPanel.vue'
5
+ /**
6
+ * 公开操作面板的过滤函数(名称或别名,不区分大小写)。
7
+ */
8
+ export { filterActionPanelItems } from './filter'
9
+ /**
10
+ * 公开操作面板的操作项、输入、事件与实例契约。
11
+ */
12
+ export type {
13
+ LingActionPanelEmits,
14
+ LingActionPanelInstance,
15
+ LingActionPanelItem,
16
+ LingActionPanelProps,
17
+ } from './LingActionPanel'
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 开发版角标契约(Figma「DevBadge」):插件图标右下角绿色的小「dev」,表示这个插件是开发者工具安装的开发版
3
+ * (ADR-0019)。搜索栏的结果行、插件的顶栏与标题栏、开发者工具的项目行共用。角标没有输入与事件。
4
+ */
5
+ export {}
@@ -0,0 +1,33 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * 开发版角标:绿底白字的 11 高小标签,外圈描一圈卡片底色,让它在任何图标上都清楚。父元素用绝对定位摆放
4
+ * (盖在图标右下角,略探出图标外)。
5
+ */
6
+ </script>
7
+
8
+ <template>
9
+ <span
10
+ class="ling-dev-badge"
11
+ title="开发版"
12
+ >
13
+ dev
14
+ </span>
15
+ </template>
16
+
17
+ <style lang="less" scoped>
18
+ .ling-dev-badge {
19
+ display: inline-flex;
20
+ align-items: center;
21
+ box-sizing: border-box;
22
+ height: 11px;
23
+ padding: 0 2.5px;
24
+ border-radius: 3px;
25
+ background: var(--u-launcher-dev);
26
+ box-shadow: 0 0 0 1.5px var(--u-launcher-bg);
27
+ color: #fff;
28
+ font-size: 8px;
29
+ font-weight: 700;
30
+ line-height: 10px;
31
+ pointer-events: none;
32
+ }
33
+ </style>
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 公开开发版角标组件,供搜索栏、插件顶栏与开发者工具使用。
3
+ */
4
+ export { default } from './LingDevBadge.vue'
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 插件底栏外壳:高 40、顶部一条分隔线,左区放返回按钮 / 提示 / 状态,右区放按钮与竖分隔线。
3
+ * 只负责布局,没有输入、实例方法与事件;内容全部经插槽提供。
4
+ */
5
+ export {}
@@ -0,0 +1,55 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * 插件底栏外壳:左区占满剩余宽度(内容超长时由内容自己省略),右区靠右不收缩。
4
+ */
5
+ defineSlots<{
6
+ /**
7
+ * 左区:返回按钮、提示、状态文字。
8
+ */
9
+ start?(): unknown
10
+ /**
11
+ * 右区:`LingShortcutButton` 与 `LingFooterDivider`。
12
+ */
13
+ default?(): unknown
14
+ }>()
15
+ </script>
16
+
17
+ <template>
18
+ <footer class="ling-footer">
19
+ <div class="ling-footer__start">
20
+ <slot name="start" />
21
+ </div>
22
+ <div class="ling-footer__end">
23
+ <slot />
24
+ </div>
25
+ </footer>
26
+ </template>
27
+
28
+ <style lang="less" scoped>
29
+ .ling-footer {
30
+ display: flex;
31
+ flex: none;
32
+ align-items: center;
33
+ gap: 4px;
34
+ box-sizing: border-box;
35
+ height: 40px;
36
+ padding: 0 8px 0 14px;
37
+ border-top: 1px solid var(--u-launcher-border);
38
+ color: var(--u-launcher-text);
39
+ font-size: var(--u-launcher-secondary-font-size);
40
+ }
41
+
42
+ .ling-footer__start {
43
+ display: flex;
44
+ flex: 1;
45
+ align-items: center;
46
+ min-width: 0;
47
+ }
48
+
49
+ .ling-footer__end {
50
+ display: flex;
51
+ flex: none;
52
+ align-items: center;
53
+ gap: 4px;
54
+ }
55
+ </style>
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 公开插件底栏外壳组件。
3
+ */
4
+ export { default } from './LingFooter.vue'
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 底栏竖分隔线:按钮之间的一条细竖线,没有输入、实例方法与事件。
3
+ */
4
+ export {}
@@ -0,0 +1,23 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * 底栏竖分隔线:`el-divider` 竖向。颜色经 `--el-border-color` 设为启动器边框色;
4
+ * Element Plus 写死的高度(1em)与左右外边距(8px)在本组件根元素 class 上改为 14px 与 2px。
5
+ */
6
+ </script>
7
+
8
+ <template>
9
+ <el-divider
10
+ class="ling-footer-divider"
11
+ direction="vertical"
12
+ />
13
+ </template>
14
+
15
+ <style lang="less" scoped>
16
+ .ling-footer-divider {
17
+ --el-border-color: var(--u-launcher-border);
18
+
19
+ flex: none;
20
+ height: 14px;
21
+ margin: 0 2px;
22
+ }
23
+ </style>
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 公开底栏竖分隔线组件,供搜索栏与插件底栏使用。
3
+ */
4
+ export { default } from './LingFooterDivider.vue'
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 键帽契约:一组按键的显示文字。
3
+ */
4
+
5
+ /**
6
+ * 键帽的输入。
7
+ */
8
+ export interface LingKeycapsProps {
9
+ /**
10
+ * 每个键帽的文字,按显示顺序,如 `['⇧', '⌘', 'K']`;由调用方按平台生成。
11
+ */
12
+ keys: readonly string[]
13
+ }
@@ -0,0 +1,51 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * 键帽:把快捷键显示成一排圆角小方块(参照 Raycast 底栏与弹层右侧的按键提示)。
4
+ * 搜索栏与内置插件共用(`@lingtools/ui`)。
5
+ * 只负责展示,按键文字由调用方按平台生成(`shortcutKeycaps`)。
6
+ */
7
+ import type { LingKeycapsProps } from './LingKeycaps'
8
+
9
+ defineProps<LingKeycapsProps>()
10
+ </script>
11
+
12
+ <template>
13
+ <span
14
+ class="ling-keycaps"
15
+ aria-hidden="true"
16
+ >
17
+ <kbd
18
+ v-for="(key, index) in keys"
19
+ :key="index"
20
+ class="ling-keycaps__key"
21
+ >
22
+ {{ key }}
23
+ </kbd>
24
+ </span>
25
+ </template>
26
+
27
+ <style lang="less" scoped>
28
+ .ling-keycaps {
29
+ display: inline-flex;
30
+ flex: none;
31
+ gap: 4px;
32
+
33
+ &__key {
34
+ display: inline-flex;
35
+ align-items: center;
36
+ justify-content: center;
37
+ box-sizing: border-box;
38
+ min-width: 20px;
39
+ height: 20px;
40
+ padding: 0 5px;
41
+ /* 亮色键帽带描边,暗色描边透明;box-sizing 为 border-box,高度不变 */
42
+ border: 1px solid var(--u-launcher-key-border);
43
+ border-radius: var(--border-radius-medium);
44
+ background: var(--u-launcher-key-bg);
45
+ color: var(--u-launcher-text-secondary);
46
+ font-family: inherit;
47
+ font-size: var(--u-launcher-key-font-size);
48
+ line-height: 1;
49
+ }
50
+ }
51
+ </style>
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 公开键帽组件,供搜索栏与内置插件显示快捷键。
3
+ */
4
+ export { default } from './LingKeycaps.vue'
5
+ /**
6
+ * 公开键帽组件的输入契约。
7
+ */
8
+ export type { LingKeycapsProps } from './LingKeycaps'
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 底栏按钮契约:可选的前置图标、文字、一组键帽(参照 Raycast 底栏右侧的动作按钮)。
3
+ * 只负责外观;快捷键由页面自己的键盘分派处理,键帽只是提示。
4
+ * `disabled`、`@click`、`@mousedown.prevent` 等经属性透传到根元素 `el-button`。
5
+ */
6
+
7
+ /**
8
+ * 底栏按钮的输入。
9
+ */
10
+ export interface LingShortcutButtonProps {
11
+ /**
12
+ * 键帽文字,按显示顺序,如 `['⌘', 'K']`;由调用方按平台生成(`acceleratorKeycaps`),空数组时不画键帽。
13
+ */
14
+ keys: readonly string[]
15
+ }
@@ -0,0 +1,71 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * 底栏按钮:`el-button` 文字按钮,内容是「[图标] 文字 键帽」。
4
+ * 颜色经 Element Plus 公开变量改成启动器令牌;高度取 `size="small"`(24),左右内边距、圆角、外边距
5
+ * 只写在本组件根元素的 class 上,不覆盖 Element Plus 内部结构。
6
+ */
7
+ import LingKeycaps from '../LingKeycaps'
8
+ import type { LingShortcutButtonProps } from './LingShortcutButton'
9
+
10
+ defineProps<LingShortcutButtonProps>()
11
+
12
+ defineSlots<{
13
+ /**
14
+ * 按钮文字。
15
+ */
16
+ default(): unknown
17
+ /**
18
+ * 文字前的图标(如返回箭头、应用图标)。
19
+ */
20
+ icon?(): unknown
21
+ }>()
22
+ </script>
23
+
24
+ <template>
25
+ <el-button
26
+ class="ling-shortcut-button"
27
+ text
28
+ size="small"
29
+ >
30
+ <span class="ling-shortcut-button__content">
31
+ <slot name="icon" />
32
+ <slot />
33
+ <LingKeycaps
34
+ v-if="keys.length > 0"
35
+ class="ling-shortcut-button__keys"
36
+ :keys="keys"
37
+ />
38
+ </span>
39
+ </el-button>
40
+ </template>
41
+
42
+ <style lang="less" scoped>
43
+ /* 颜色只经 Element Plus 公开变量;尺寸写在本组件根元素 class 上(清掉相邻按钮自带的 12px 左外边距)。
44
+ 变量写在 `.is-text` 上:element-plus-theme-arco 暗色有 `html.dark .el-button.is-text` 把禁用色设成浅主色(蓝),
45
+ 只写根 class 的优先级比它低,暗色下禁用会变蓝 */
46
+ .ling-shortcut-button.is-text {
47
+ --el-button-text-color: var(--u-launcher-text);
48
+ --el-button-hover-text-color: var(--u-launcher-text);
49
+ --el-button-hover-link-text-color: var(--u-launcher-text);
50
+ --el-button-active-text-color: var(--u-launcher-text);
51
+ --el-button-disabled-text-color: var(--u-launcher-placeholder);
52
+ --el-fill-color-light: var(--u-launcher-item-current-bg);
53
+ --el-fill-color: var(--u-launcher-item-current-bg);
54
+
55
+ margin: 0;
56
+ padding: 0 6px;
57
+ border-radius: 6px;
58
+ font-size: var(--u-launcher-secondary-font-size);
59
+ }
60
+
61
+ .ling-shortcut-button__content {
62
+ display: inline-flex;
63
+ align-items: center;
64
+ gap: 6px;
65
+ }
66
+
67
+ /* 禁用时键帽一起变淡 */
68
+ .ling-shortcut-button.is-disabled .ling-shortcut-button__keys {
69
+ opacity: 0.5;
70
+ }
71
+ </style>
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 公开底栏按钮组件,供搜索栏与插件底栏使用。
3
+ */
4
+ export { default } from './LingShortcutButton.vue'
5
+ /**
6
+ * 公开底栏按钮的输入契约。
7
+ */
8
+ export type { LingShortcutButtonProps } from './LingShortcutButton'
@@ -0,0 +1,202 @@
1
+ /**
2
+ * 列表的当前行:插件页面里「子输入框在上、列表在下,↑↓ 选一行、快捷键对它执行操作」这类列表共用的单选逻辑。
3
+ *
4
+ * 焦点一直在宿主的子输入框里,当前行不是浏览器焦点,而是页面自己维护的选中标识;行组件只按它画高亮。
5
+ * 这里只管选中哪一行:选中并滚到可见、上下移动、列表变化后保留选中、接近末尾时通知读下一页。
6
+ * 按键分派(哪些键算移动、浮层打开时谁接管)留在各页面,与它们自己的快捷键表一起判断。
7
+ *
8
+ * 行元素须带 {@link LIST_KEY_ATTRIBUTE} 属性(值为行标识),滚到可见时靠它找到元素。
9
+ */
10
+ import {
11
+ computed,
12
+ nextTick,
13
+ shallowRef,
14
+ toValue,
15
+ watch,
16
+ type ComputedRef,
17
+ type MaybeRefOrGetter,
18
+ type ShallowRef,
19
+ } from 'vue'
20
+
21
+ /**
22
+ * 行元素上标记行标识的属性。
23
+ */
24
+ export const LIST_KEY_ATTRIBUTE = 'data-list-key'
25
+
26
+ /**
27
+ * `onNearEnd` 的默认阈值:↓ 后选中落在最后 2 行以内时回调。
28
+ */
29
+ const DEFAULT_NEAR_END_ROWS = 2
30
+
31
+ /**
32
+ * 行标识的类型:数据库 id 或字符串键。
33
+ */
34
+ export type ListKey = string | number
35
+
36
+ /**
37
+ * {@link useListSelection} 的输入。
38
+ */
39
+ export interface UseListSelectionOptions<T, K extends ListKey> {
40
+ /**
41
+ * 当前显示的行,顺序即上下移动的顺序。
42
+ */
43
+ items: MaybeRefOrGetter<readonly T[]>
44
+ /**
45
+ * 取行标识。
46
+ */
47
+ keyOf: (item: T) => K
48
+ /**
49
+ * 列表的滚动容器;省略时不滚动。
50
+ */
51
+ listElement?: MaybeRefOrGetter<HTMLElement | null | undefined>
52
+ /**
53
+ * ↓ 后选中落在最后 `nearEndRows` 行以内时调用(用于读下一页,去重由调用方负责);省略时不调用。
54
+ */
55
+ onNearEnd?: () => void
56
+ /**
57
+ * 见 `onNearEnd`,默认 2。
58
+ */
59
+ nearEndRows?: number
60
+ }
61
+
62
+ /**
63
+ * {@link useListSelection} 的返回值。
64
+ */
65
+ export interface UseListSelectionResult<T, K extends ListKey> {
66
+ /**
67
+ * 选中行的标识。可以直接赋值(例如删除前先定好下一条、清空前先置空);列表变化时仍按保留规则校正。
68
+ */
69
+ selectedKey: ShallowRef<K | null>
70
+ /**
71
+ * 选中的行;没有选中或不在列表里时为 null。
72
+ */
73
+ current: ComputedRef<T | null>
74
+ /**
75
+ * 选中一行并滚到可见。
76
+ * @param key 行标识。
77
+ */
78
+ select(key: K): void
79
+ /**
80
+ * 上下移动一行并滚到可见,首尾不循环;列表为空时不动,没有选中时选第一行。
81
+ * @param step 1 为下移,-1 为上移。
82
+ */
83
+ move(step: 1 | -1): void
84
+ /**
85
+ * 把当前选中行滚到可见。数据变化本身不滚动(定时刷新的列表不能把用户滚走的位置拉回来),需要时由调用方显式调用。
86
+ */
87
+ scrollToSelected(): void
88
+ }
89
+
90
+ /**
91
+ * 列表变化后的选中:原条目还在就是它;不在了就选原来的位置(越界取最后一行);列表为空时为 null。
92
+ * @param items 变化后的行。
93
+ * @param keyOf 取行标识。
94
+ * @param previousKey 变化前选中的标识。
95
+ * @param previousIndex 变化前选中的位置;原来没有选中时传 0。
96
+ * @returns 新的选中标识。
97
+ */
98
+ export function keepListSelection<T, K extends ListKey>(
99
+ items: readonly T[],
100
+ keyOf: (item: T) => K,
101
+ previousKey: K | null,
102
+ previousIndex: number,
103
+ ): K | null {
104
+ if (previousKey !== null && items.some((item) => keyOf(item) === previousKey)) {
105
+ return previousKey
106
+ }
107
+ const fallback = items[Math.min(Math.max(previousIndex, 0), items.length - 1)]
108
+ return fallback === undefined ? null : keyOf(fallback)
109
+ }
110
+
111
+ /**
112
+ * 创建列表的当前行。
113
+ * @param options 行、行标识、滚动容器与读下一页的回调。
114
+ * @returns 选中标识、选中行与选中操作。
115
+ */
116
+ export function useListSelection<T, K extends ListKey>(
117
+ options: UseListSelectionOptions<T, K>,
118
+ ): UseListSelectionResult<T, K> {
119
+ const { keyOf } = options
120
+ const nearEndRows = options.nearEndRows ?? DEFAULT_NEAR_END_ROWS
121
+ // shallowRef 的重载按值的类型分支,泛型 K 推不出来,这里写明类型
122
+ const selectedKey = shallowRef<K | null>(null) as ShallowRef<K | null>
123
+
124
+ /**
125
+ * 某个标识在行里的位置;不在时为 -1。
126
+ * @param items 行。
127
+ * @param key 行标识。
128
+ * @returns 位置。
129
+ */
130
+ function indexOf(items: readonly T[], key: K | null): number {
131
+ return key === null ? -1 : items.findIndex((item) => keyOf(item) === key)
132
+ }
133
+
134
+ const current = computed(() => {
135
+ const items = toValue(options.items)
136
+ return items[indexOf(items, selectedKey.value)] ?? null
137
+ })
138
+
139
+ // 列表一变就同步校正,界面不会出现「有选中但不在列表里」的中间状态;调用方先改 selectedKey 再换列表时,
140
+ // 新值已在列表里,这里不再另选
141
+ watch(
142
+ () => toValue(options.items),
143
+ (items, previous) => {
144
+ const previousIndex = indexOf(previous ?? [], selectedKey.value)
145
+ selectedKey.value = keepListSelection(
146
+ items,
147
+ keyOf,
148
+ selectedKey.value,
149
+ Math.max(previousIndex, 0),
150
+ )
151
+ },
152
+ { immediate: true, flush: 'sync' },
153
+ )
154
+
155
+ /**
156
+ * 把当前选中行滚到可见。行标识可能含路径,逐个比较属性值,不拼进选择器。
157
+ */
158
+ function scrollToSelected(): void {
159
+ void nextTick(() => {
160
+ const key = selectedKey.value
161
+ const container = toValue(options.listElement)
162
+ if (key === null || !container) {
163
+ return
164
+ }
165
+ const element = [...container.querySelectorAll(`[${LIST_KEY_ATTRIBUTE}]`)].find(
166
+ (item) => item.getAttribute(LIST_KEY_ATTRIBUTE) === String(key),
167
+ )
168
+ element?.scrollIntoView?.({ block: 'nearest' })
169
+ })
170
+ }
171
+
172
+ /**
173
+ * 选中一行并滚到可见。
174
+ * @param key 行标识。
175
+ */
176
+ function select(key: K): void {
177
+ selectedKey.value = key
178
+ scrollToSelected()
179
+ }
180
+
181
+ /**
182
+ * 上下移动一行,首尾不循环;↓ 后接近末尾时调用 `onNearEnd`。
183
+ * @param step 1 为下移,-1 为上移。
184
+ */
185
+ function move(step: 1 | -1): void {
186
+ const items = toValue(options.items)
187
+ if (items.length === 0) {
188
+ return
189
+ }
190
+ const index = indexOf(items, selectedKey.value)
191
+ // 没有选中时(只在调用方手动置空后出现)任一方向都先选第一行
192
+ const target = index < 0 ? items[0] : items[index + step]
193
+ if (target !== undefined) {
194
+ select(keyOf(target))
195
+ }
196
+ if (step === 1 && indexOf(items, selectedKey.value) >= items.length - nearEndRows) {
197
+ options.onNearEnd?.()
198
+ }
199
+ }
200
+
201
+ return { selectedKey, current, select, move, scrollToSelected }
202
+ }
package/src/index.ts ADDED
@@ -0,0 +1,97 @@
1
+ /**
2
+ * `@lingtools/ui`:搜索栏(Client)与插件(内置插件、官方独立插件)共用的界面资源——设计令牌与基础样式
3
+ * (`@lingtools/ui/theme`)、亮暗切换、通用组件,以及共用的 Vite 插件组(`@lingtools/ui/vite`)。
4
+ * 只放搜索栏或两个以上插件实际都用到的东西,不为「以后可能复用」预先抽取。
5
+ * 组件里不出现项目图标类名(`i-app-*`,各项目的图标集合不同),图标由使用方经插槽提供;
6
+ * Element Plus 只用公开属性与 `--el-*` 变量,尺寸只调本组件根元素自己的 class,不用 `:deep(.el-*)`。
7
+ */
8
+
9
+ /**
10
+ * 开发版角标:插件图标右下角绿色的小「dev」。
11
+ */
12
+ export { default as LingDevBadge } from './components/LingDevBadge'
13
+ /**
14
+ * 插件底栏外壳:左区(返回、提示、状态)与右区(按钮、竖分隔线)两个插槽。
15
+ */
16
+ export { default as LingFooter } from './components/LingFooter'
17
+ /**
18
+ * 底栏按钮:「[图标] 文字 键帽」的文字按钮。
19
+ */
20
+ export { default as LingShortcutButton } from './components/LingShortcutButton'
21
+ /**
22
+ * 底栏按钮的输入契约。
23
+ */
24
+ export type { LingShortcutButtonProps } from './components/LingShortcutButton'
25
+ /**
26
+ * 底栏竖分隔线:按钮之间的一条细竖线。
27
+ */
28
+ export { default as LingFooterDivider } from './components/LingFooterDivider'
29
+ /**
30
+ * 操作面板:插件页面内的 ⌘K 面板(标题、分组操作行、底部搜索)与它的过滤函数。
31
+ */
32
+ export { default as LingActionPanel, filterActionPanelItems } from './components/LingActionPanel'
33
+ /**
34
+ * 操作面板的操作项、输入、事件与实例契约。
35
+ */
36
+ export type {
37
+ LingActionPanelEmits,
38
+ LingActionPanelInstance,
39
+ LingActionPanelItem,
40
+ LingActionPanelProps,
41
+ } from './components/LingActionPanel'
42
+ /**
43
+ * 操作行:操作面板里的一行(图标、名称、后缀、键帽,当前 / 禁用 / 危险)。
44
+ */
45
+ export { default as LingActionItem } from './components/LingActionItem'
46
+ /**
47
+ * 操作行的输入契约。
48
+ */
49
+ export type { LingActionItemProps } from './components/LingActionItem'
50
+ /**
51
+ * 键帽组件:把快捷键显示成一排圆角小方块。
52
+ */
53
+ export { default as LingKeycaps } from './components/LingKeycaps'
54
+ /**
55
+ * 键帽组件的输入契约。
56
+ */
57
+ export type { LingKeycapsProps } from './components/LingKeycaps'
58
+ /**
59
+ * 列表的当前行:选中并滚到可见、↑↓ 移动、列表变化后保留选中、接近末尾时通知读下一页;
60
+ * 行元素用 `LIST_KEY_ATTRIBUTE` 标记行标识,`keepListSelection` 是保留规则的纯函数。
61
+ */
62
+ export {
63
+ keepListSelection,
64
+ LIST_KEY_ATTRIBUTE,
65
+ useListSelection,
66
+ } from './composables/use-list-selection'
67
+ /**
68
+ * 列表当前行的行标识、输入与返回值契约。
69
+ */
70
+ export type {
71
+ ListKey,
72
+ UseListSelectionOptions,
73
+ UseListSelectionResult,
74
+ } from './composables/use-list-selection'
75
+ /**
76
+ * 页面亮暗与毛玻璃切换:入口调用一次 `useTheme`,组件经 `useCurrentTheme` / `useCurrentGlass` / `getCurrentTheme`
77
+ * 读取当前值;`glassModeOf` 是毛玻璃模式的判定表。
78
+ */
79
+ export {
80
+ getCurrentTheme,
81
+ glassModeOf,
82
+ useCurrentGlass,
83
+ useCurrentTheme,
84
+ useTheme,
85
+ } from './theme/use-theme'
86
+ /**
87
+ * 页面亮暗与毛玻璃切换的模式、来源、选项与返回值契约。
88
+ */
89
+ export type {
90
+ GlassMode,
91
+ PageKind,
92
+ ThemeMode,
93
+ ThemeSnapshot,
94
+ ThemeSource,
95
+ UseThemeOptions,
96
+ UseThemeResult,
97
+ } from './theme/use-theme'
@@ -0,0 +1,45 @@
1
+ /* 全局 reset 放入最低层:无层样式(UnoCSS utilities、Element Plus)与其余分层组件样式都能覆盖它。 */
2
+ @layer base {
3
+ * {
4
+ padding: 0;
5
+ margin: 0;
6
+ }
7
+
8
+ html,
9
+ body,
10
+ #app {
11
+ height: 100%;
12
+ }
13
+
14
+ body {
15
+ font-family:
16
+ system-ui,
17
+ -apple-system,
18
+ 'Segoe UI',
19
+ 'PingFang SC',
20
+ 'Microsoft YaHei',
21
+ sans-serif;
22
+ font-size: var(--el-font-size-base);
23
+ color: var(--color-text-1);
24
+ }
25
+
26
+ /* 主窗口是透明窗口,由搜索栏自己绘制圆角卡片;页面底色必须透明。
27
+ 页面铺满窗口、只在内部区域滚动:根元素不滚动,也关掉 macOS WebView 的弹性回弹(否则整张卡片能被拉上拉下) */
28
+ html,
29
+ body {
30
+ overflow: hidden;
31
+ overscroll-behavior: none;
32
+ background: transparent;
33
+ }
34
+ }
35
+
36
+ /* Element Plus(Arco 主题)对话框的关闭按钮:主题把按钮放在 top: 1px、高 48px 的块里,图标按行内基线排,
37
+ 和按钮上居中画的悬停圆底错开,看起来 × 不居中。改成 flex 居中,并与 48px 高的标题栏对齐。
38
+ 不放进 @layer base:组件库样式不分层,分层样式压不过它。 */
39
+ .el-dialog .el-dialog__headerbtn {
40
+ top: 0;
41
+ display: inline-flex;
42
+ align-items: center;
43
+ justify-content: center;
44
+ height: 48px;
45
+ }