@ysgroup/ui 0.1.43 → 0.1.44

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.44",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -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.2.6"
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;
@@ -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();