@ysgroup/ui 0.1.43 → 0.1.45

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ysgroup/ui",
3
- "version": "0.1.43",
3
+ "version": "0.1.45",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -11,7 +11,7 @@
11
11
  "pdfjs-dist": "6.5.438"
12
12
  },
13
13
  "peerDependencies": {
14
- "@ysgroup/theme": ">=0.2.6",
14
+ "@ysgroup/theme": ">=0.3.0",
15
15
  "element-plus": ">=2.9",
16
16
  "vue": ">=3.5"
17
17
  },
@@ -24,7 +24,7 @@
24
24
  "access": "public"
25
25
  },
26
26
  "devDependencies": {
27
- "@ysgroup/theme": "^0.2.6",
28
- "docx-preview": "^0.4.1"
27
+ "docx-preview": "^0.4.1",
28
+ "@ysgroup/theme": "^0.3.0"
29
29
  }
30
30
  }
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { onBeforeUnmount, ref } from "vue";
3
+ import { ElMessage } from "element-plus";
3
4
  import { Moon, Setting, Sunny } from "@element-plus/icons-vue";
4
5
  import {
5
6
  applyTheme,
@@ -20,9 +21,16 @@ function onThemeChange() {
20
21
  mode.value = resolvedMode();
21
22
  }
22
23
  window.addEventListener(THEME_CHANGE_EVENT, onThemeChange);
23
- onBeforeUnmount(() =>
24
- window.removeEventListener(THEME_CHANGE_EVENT, onThemeChange),
25
- );
24
+ // @ysgroup/core 0.1.26 起切换后立即存到当前系统,存失败时派发这个事件(与 core 的 THEME_SAVE_FAILED_EVENT 同名)。
25
+ const THEME_SAVE_FAILED_EVENT = "ys-theme-save-failed";
26
+ function onThemeSaveFailed() {
27
+ ElMessage.warning("明暗模式没有保存成功,刷新页面后可能恢复为之前的模式");
28
+ }
29
+ window.addEventListener(THEME_SAVE_FAILED_EVENT, onThemeSaveFailed);
30
+ onBeforeUnmount(() => {
31
+ window.removeEventListener(THEME_CHANGE_EVENT, onThemeChange);
32
+ window.removeEventListener(THEME_SAVE_FAILED_EVENT, onThemeSaveFailed);
33
+ });
26
34
 
27
35
  function selectTheme(next: ThemeMode) {
28
36
  if (next !== "light" && next !== "dark") return;
@@ -22,9 +22,9 @@ defineProps<{
22
22
  vertical-align: middle;
23
23
  }
24
24
  .ys-bool-mark.is-yes {
25
- color: #5bb07a;
25
+ color: var(--ys-color-success);
26
26
  }
27
27
  .ys-bool-mark.is-no {
28
- color: #e6e9f0;
28
+ color: color-mix(in srgb, var(--ys-color-text-3) 35%, var(--ys-color-bg-elevated));
29
29
  }
30
30
  </style>
@@ -251,7 +251,7 @@ function toggleSidebar() {
251
251
  }
252
252
  .ys-layout__menu.is-active {
253
253
  background: var(--ys-color-primary);
254
- color: #fff;
254
+ color: var(--ys-color-on-solid);
255
255
  }
256
256
  .ys-layout__content {
257
257
  flex: 1;
@@ -74,7 +74,7 @@ const emit = defineEmits<{ open: [app: AppCard] }>();
74
74
  align-items: center;
75
75
  justify-content: center;
76
76
  background: var(--ys-color-primary);
77
- color: #fff;
77
+ color: var(--ys-color-on-solid);
78
78
  font-size: 22px;
79
79
  font-weight: 600;
80
80
  }
@@ -26,8 +26,8 @@ const roleClass = computed(() => {
26
26
  : "custom";
27
27
  });
28
28
  /**
29
- * 扩展角色与内置角色同一做法:浅色底、深色字、浅色边。暗色主题下也保持浅底,
30
- * 所以底色和边框按白色调配,不能按当前主题背景调配,否则深字压在深底上看不清。
29
+ * 扩展角色与内置角色同一做法:只给一个角色色,底色、边框、文字都由它和当前主题派生——
30
+ * 亮色是浅底深字,暗色是带一点角色色的深底、提亮的字,两种模式都清楚,不会在暗色里冒出一块亮片。
31
31
  */
32
32
  const customStyle = computed(() => {
33
33
  if (
@@ -35,11 +35,7 @@ const customStyle = computed(() => {
35
35
  !/^#[0-9a-fA-F]{6}$/.test(props.color ?? "")
36
36
  )
37
37
  return undefined;
38
- return {
39
- "--ys-role-text": props.color,
40
- "--ys-role-border": `color-mix(in srgb, ${props.color} 42%, #fff)`,
41
- "--ys-role-bg": `color-mix(in srgb, ${props.color} 8%, #fff)`,
42
- };
38
+ return { "--ys-role-color": props.color };
43
39
  });
44
40
  const displayLabel = computed(
45
41
  () =>
@@ -62,50 +58,37 @@ const displayLabel = computed(
62
58
  </template>
63
59
 
64
60
  <style scoped>
61
+ /* 文字往一级文字色里混:亮色变深、暗色变亮,对比度都够;底色、边框往卡片底色里混。 */
65
62
  .ys-role-tag {
66
- --ys-role-bg: #f8fafc;
67
- --ys-role-text: #475569;
68
- --ys-role-border: #cbd5e1;
63
+ --ys-role-color: #64748b;
69
64
 
70
- border-color: var(--ys-role-border);
71
- background-color: var(--ys-role-bg);
72
- color: var(--ys-role-text);
65
+ border-color: color-mix(in srgb, var(--ys-role-color) 42%, var(--ys-color-bg-elevated));
66
+ background-color: color-mix(in srgb, var(--ys-role-color) 10%, var(--ys-color-bg-elevated));
67
+ color: color-mix(in srgb, var(--ys-role-color) 74%, var(--ys-color-text-1));
73
68
  font-weight: 600;
74
69
  }
75
70
 
76
71
  .ys-role-tag--root {
77
- --ys-role-bg: #f5f3ff;
78
- --ys-role-text: #6d28d9;
79
- --ys-role-border: #c4b5fd;
72
+ --ys-role-color: #7c3aed;
80
73
  }
81
74
 
82
75
  .ys-role-tag--admin {
83
- --ys-role-bg: #fff1f2;
84
- --ys-role-text: #be123c;
85
- --ys-role-border: #fda4af;
76
+ --ys-role-color: #e11d48;
86
77
  }
87
78
 
88
79
  .ys-role-tag--manager {
89
- --ys-role-bg: #fffbeb;
90
- --ys-role-text: #a16207;
91
- --ys-role-border: #fcd34d;
80
+ --ys-role-color: #d97706;
92
81
  }
93
82
 
94
83
  .ys-role-tag--editor {
95
- --ys-role-bg: #ecfdf5;
96
- --ys-role-text: #047857;
97
- --ys-role-border: #6ee7b7;
84
+ --ys-role-color: #059669;
98
85
  }
99
86
 
100
87
  .ys-role-tag--viewer {
101
- --ys-role-bg: #eff6ff;
102
- --ys-role-text: #2563eb;
103
- --ys-role-border: #93c5fd;
88
+ --ys-role-color: #2563eb;
104
89
  }
105
90
 
106
91
  .ys-role-tag--initiate {
107
- --ys-role-bg: #f1f5f9;
108
- --ys-role-text: #475569;
109
- --ys-role-border: #94a3b8;
92
+ --ys-role-color: #64748b;
110
93
  }
111
94
  </style>
@@ -106,16 +106,16 @@ function select(action: YsRowAction) {
106
106
  --item-color: var(--ys-color-primary);
107
107
  }
108
108
  .ys-row-action__item.is-accent {
109
- --item-color: #0f8f83;
109
+ --item-color: var(--ys-color-accent);
110
110
  }
111
111
  .ys-row-action__item.is-warning {
112
- --item-color: #b7791f;
112
+ --item-color: var(--ys-color-warning);
113
113
  }
114
114
  .ys-row-action__item.is-success {
115
115
  --item-color: var(--ys-color-success);
116
116
  }
117
117
  .ys-row-action__item.is-neutral {
118
- --item-color: #58677f;
118
+ --item-color: var(--ys-color-text-2);
119
119
  }
120
120
  .ys-row-action__item.is-danger {
121
121
  --item-color: var(--ys-color-danger);
@@ -8,6 +8,8 @@ const props = defineProps<{
8
8
  role?: string;
9
9
  username?: string;
10
10
  passwordManagementUrl?: string;
11
+ /** 系统版本号,按构建时间标识,如「V 20261113.175015」;不传不显示。 */
12
+ version?: string;
11
13
  }>();
12
14
 
13
15
  const emit = defineEmits<{
@@ -196,6 +198,9 @@ defineExpose({
196
198
  </el-tab-pane>
197
199
  </el-tabs>
198
200
  <template #footer>
201
+ <span v-if="version" class="ys-settings__version"
202
+ >{{ version }}</span
203
+ >
199
204
  <el-button @click="close">关闭</el-button>
200
205
  <el-button
201
206
  v-if="
@@ -212,6 +217,14 @@ defineExpose({
212
217
  </template>
213
218
 
214
219
  <style scoped>
220
+ .ys-settings__version {
221
+ float: left;
222
+ line-height: 32px;
223
+ color: var(--ys-color-text-3);
224
+ font-size: 12px;
225
+ font-variant-numeric: tabular-nums;
226
+ user-select: all;
227
+ }
215
228
  .ys-settings {
216
229
  min-height: 300px;
217
230
  --ys-settings-heading-height: 40px;
package/src/index.ts CHANGED
@@ -30,7 +30,7 @@ export { default as YsDocViewer } from "./components/YsDocViewer.vue";
30
30
  export { default as YsMediaPlayer } from "./components/YsMediaPlayer.vue";
31
31
  export { formatMediaTime, MEDIA_SPEEDS } from "./preview/media";
32
32
  export type { PdfZoomMode } from "./preview/pdfLayout";
33
- export { vTip } from "./vTip";
33
+ export { isTextOverflowing, vTip } from "./vTip";
34
34
  export {
35
35
  previewKindOf,
36
36
  sniffPreviewKind,
package/src/vTip.ts CHANGED
@@ -1,12 +1,21 @@
1
1
  /* v-tip 悬停提示:`v-tip="文本"`,鼠标移上或键盘聚焦立即显示,移开/失焦/滚动即隐藏,代替浏览器原生 title(要等约 1 秒)。
2
2
  * 全页共用一个浮层(.ys-tip),外观由 @ysgroup/theme 的 --ys-tooltip-* 令牌决定,与 el-tooltip 一致;文本为空不显示。
3
3
  * 注册:app.directive("tip", vTip)。(模板类型提示需要时在业务仓自行声明 GlobalDirectives,这里不声明,免得与业务仓已有的同名声明冲突。)
4
- * 默认在元素上方,放不下时放下方;超长文字自动换行(最宽 360px),\n 换行。 */
4
+ * 默认在元素上方,放不下时放下方;超长文字自动换行(最宽 360px),\n 换行。
5
+ * `v-tip.overflow="文本"`:只在文字被截断(出现省略号)时才显示,适合配合 text-overflow: ellipsis 的单行文字。 */
5
6
  import type { Directive } from "vue";
6
7
 
7
8
  let layer: HTMLDivElement | null = null;
8
9
  let owner: HTMLElement | null = null;
9
10
  const texts = new WeakMap<HTMLElement, string>();
11
+ const overflowOnly = new WeakSet<HTMLElement>();
12
+
13
+ /** 元素内容是否被截断(横向或纵向放不下)。 */
14
+ export function isTextOverflowing(el: HTMLElement): boolean {
15
+ return (
16
+ el.scrollWidth > el.clientWidth + 1 || el.scrollHeight > el.clientHeight + 1
17
+ );
18
+ }
10
19
  let listening = false;
11
20
 
12
21
  function ensureLayer(): HTMLDivElement {
@@ -27,22 +36,31 @@ export function placeTip(
27
36
  viewport: { width: number; height: number },
28
37
  gap = 6,
29
38
  ): { left: number; top: number; placement: "top" | "bottom" } {
30
- const left = Math.min(Math.max(4, target.left + target.width / 2 - tip.width / 2), Math.max(4, viewport.width - tip.width - 4));
39
+ const left = Math.min(
40
+ Math.max(4, target.left + target.width / 2 - tip.width / 2),
41
+ Math.max(4, viewport.width - tip.width - 4),
42
+ );
31
43
  const above = target.top - tip.height - gap;
32
- if (above >= 4 || target.bottom + gap + tip.height > viewport.height) return { left, top: Math.max(4, above), placement: "top" };
44
+ if (above >= 4 || target.bottom + gap + tip.height > viewport.height)
45
+ return { left, top: Math.max(4, above), placement: "top" };
33
46
  return { left, top: target.bottom + gap, placement: "bottom" };
34
47
  }
35
48
 
36
49
  function show(el: HTMLElement) {
37
50
  const text = texts.get(el);
38
51
  if (!text) return;
52
+ if (overflowOnly.has(el) && !isTextOverflowing(el)) return;
39
53
  owner = el;
40
54
  const tip = ensureLayer();
41
55
  tip.textContent = text;
42
56
  tip.style.display = "block";
43
57
  tip.style.left = "0px";
44
58
  tip.style.top = "0px";
45
- const pos = placeTip(el.getBoundingClientRect(), { width: tip.offsetWidth, height: tip.offsetHeight }, { width: window.innerWidth, height: window.innerHeight });
59
+ const pos = placeTip(
60
+ el.getBoundingClientRect(),
61
+ { width: tip.offsetWidth, height: tip.offsetHeight },
62
+ { width: window.innerWidth, height: window.innerHeight },
63
+ );
46
64
  tip.style.left = `${pos.left}px`;
47
65
  tip.style.top = `${pos.top}px`;
48
66
  tip.dataset.placement = pos.placement;
@@ -70,6 +88,7 @@ function listen() {
70
88
  export const vTip: Directive<HTMLElement, string | null | undefined> = {
71
89
  mounted(el, binding) {
72
90
  texts.set(el, String(binding.value ?? ""));
91
+ if (binding.modifiers.overflow) overflowOnly.add(el);
73
92
  el.addEventListener("mouseenter", onEnter);
74
93
  el.addEventListener("focusin", onEnter);
75
94
  el.addEventListener("mouseleave", hide);
@@ -78,6 +97,8 @@ export const vTip: Directive<HTMLElement, string | null | undefined> = {
78
97
  },
79
98
  updated(el, binding) {
80
99
  texts.set(el, String(binding.value ?? ""));
100
+ if (binding.modifiers.overflow) overflowOnly.add(el);
101
+ else overflowOnly.delete(el);
81
102
  if (owner === el) {
82
103
  if (texts.get(el)) show(el);
83
104
  else hide();