@veltra/sheet 4.0.0 → 4.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 (30) hide show
  1. package/dist/components/sheet/float-image-menu.js +59 -0
  2. package/dist/components/sheet/popup-helpers.js +18 -2
  3. package/dist/components/sheet/popups/hyperlink-popup.js +127 -0
  4. package/dist/components/sheet/sheet-context-menu.js +75 -3
  5. package/dist/components/sheet/sheet.js +110 -15
  6. package/dist/components/sheet/style2.css +62 -0
  7. package/dist/components/sheet/use-cell-link-tooltip.js +33 -0
  8. package/dist/components/sheet/use-sheet-grid.js +32 -1
  9. package/dist/components/sheet/use-sheet-state.js +1 -0
  10. package/dist/tools/context.d.ts +20 -2
  11. package/dist/tools/context.js +9 -1
  12. package/dist/types/index.d.ts +2 -2
  13. package/dist/types/sheet.d.ts +50 -1
  14. package/package.json +1 -1
  15. package/src/components/sheet/__test__/float-image-menu.test.ts +130 -0
  16. package/src/components/sheet/__test__/hyperlink-popup.test.ts +176 -0
  17. package/src/components/sheet/__test__/sheet-component.test.ts +474 -16
  18. package/src/components/sheet/__test__/sheet-context-menu.test.ts +212 -2
  19. package/src/components/sheet/float-image-menu.ts +78 -0
  20. package/src/components/sheet/popup-helpers.ts +68 -2
  21. package/src/components/sheet/popups/hyperlink-popup.vue +112 -0
  22. package/src/components/sheet/sheet-context-menu.ts +86 -3
  23. package/src/components/sheet/sheet.vue +117 -3
  24. package/src/components/sheet/style.scss +66 -0
  25. package/src/components/sheet/use-cell-link-tooltip.ts +42 -0
  26. package/src/components/sheet/use-sheet-grid.ts +60 -3
  27. package/src/components/sheet/use-sheet-state.ts +8 -2
  28. package/src/tools/__test__/context.test.ts +89 -0
  29. package/src/tools/context.ts +33 -2
  30. package/src/types/sheet.ts +55 -0
@@ -0,0 +1,59 @@
1
+ import { imageLinkInitial, imagePreviewSource } from "./popup-helpers.js";
2
+ import { contextmenu } from "@veltra/desktop";
3
+ //#region src/components/sheet/float-image-menu.ts
4
+ /**
5
+ * 浮动图右键独立菜单:预览 / 设置超链接 / 取消超链接(无链接不出现)/ 删除图片。
6
+ * 设置走 hyperlink 弹窗 image 模式(确认 `updateImage(id, { link })`);取消直写
7
+ * `updateImage(id, { link: null })`(null 清除,可 undo);删除走 `removeImage`
8
+ * (命令系统,可 undo)。命中 id 不存在(并发删除)返回空数组,调用方不弹菜单。
9
+ */
10
+ function buildFloatImageMenus(ctx, id, handles, options) {
11
+ const image = ctx.getImages().find((item) => item.id === id);
12
+ if (!image) return [];
13
+ const readonly = options?.readonly === true;
14
+ const target = {
15
+ kind: "float",
16
+ id
17
+ };
18
+ return [
19
+ {
20
+ label: "预览",
21
+ disabled: !handles?.openImagePreview,
22
+ callback: () => handles?.openImagePreview?.(imagePreviewSource(image))
23
+ },
24
+ {
25
+ label: "设置超链接",
26
+ disabled: readonly || !handles?.openHyperlinkPopup,
27
+ callback: () => handles?.openHyperlinkPopup?.("image", imageLinkInitial(image.link), target)
28
+ },
29
+ ...image.link ? [{
30
+ label: "取消超链接",
31
+ disabled: readonly,
32
+ callback: () => ctx.updateImage(id, { link: null })
33
+ }] : [],
34
+ {
35
+ label: "删除图片",
36
+ disabled: readonly,
37
+ callback: () => ctx.removeImage(id)
38
+ }
39
+ ];
40
+ }
41
+ /**
42
+ * 消费引擎浮动图右键事件:按命中浮动图 link 状态构建独立菜单并经 `contextmenu.pop`
43
+ * 弹出(viewport 坐标定位,与 body 右键菜单同口径)。右键不穿透到格菜单由引擎
44
+ * 保证(floatObjects 命中即不派发单元格 contextmenu),此处只弹浮动图菜单。
45
+ */
46
+ function popFloatImageMenu(options) {
47
+ const menus = buildFloatImageMenus(options.ctx, options.event.id, options.handles, { readonly: options.readonly });
48
+ if (menus.length === 0) return;
49
+ contextmenu.pop({
50
+ mousePosition: {
51
+ x: options.event.clientX,
52
+ y: options.event.clientY
53
+ },
54
+ width: "max-content",
55
+ menus
56
+ });
57
+ }
58
+ //#endregion
59
+ export { buildFloatImageMenus, popFloatImageMenu };
@@ -1,4 +1,4 @@
1
- import { BORDER_STYLE_WIDTH } from "infinitable/sheet";
1
+ import { BORDER_STYLE_WIDTH, IMAGE_MIME } from "infinitable/sheet";
2
2
  //#region src/components/sheet/popup-helpers.ts
3
3
  /** 当前选区(ranges[0] 优先;无区域选区时用活动格单格) */
4
4
  function currentRange(context) {
@@ -8,6 +8,22 @@ function currentRange(context) {
8
8
  end: activeCell
9
9
  } : null);
10
10
  }
11
+ /** 图片链接 → 弹窗回填载荷(无链接 → undefined 插入态;浮动图与嵌入图共用) */
12
+ function imageLinkInitial(link) {
13
+ return link ? { url: link } : void 0;
14
+ }
15
+ /**
16
+ * 图片载荷 → 预览源归一:src 优先(URL 来源直接引用);否则取字节 + 模型 type
17
+ * 映射 MIME(type 缺省按 png,同引擎嵌入图渲染约定)。浮动图(type 必填)与
18
+ * 嵌入图(type 可选)共用。
19
+ */
20
+ function imagePreviewSource(payload) {
21
+ if (payload.src) return { src: payload.src };
22
+ return {
23
+ data: payload.data,
24
+ mime: IMAGE_MIME[payload.type ?? "png"]
25
+ };
26
+ }
11
27
  const BORDER_LINE_STYLES = [
12
28
  "thin",
13
29
  "medium",
@@ -70,4 +86,4 @@ function lineSwatchStyle(line) {
70
86
  return { borderBottom: `${BORDER_STYLE_WIDTH[line]}px ${dash} #000` };
71
87
  }
72
88
  //#endregion
73
- export { BORDER_LINE_STYLES, BORDER_LINE_TITLES, BORDER_PRESETS, currentRange, lineSwatchStyle };
89
+ export { BORDER_LINE_STYLES, BORDER_LINE_TITLES, BORDER_PRESETS, currentRange, imageLinkInitial, imagePreviewSource, lineSwatchStyle };
@@ -0,0 +1,127 @@
1
+ import { Teleport, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, openBlock, ref, toDisplayString, unref, useId, withCtx, withKeys, withModifiers } from "vue";
2
+ import { UButton, UInput, message } from "@veltra/desktop";
3
+ import { bem, zIndex } from "@veltra/utils";
4
+ //#region src/components/sheet/popups/hyperlink-popup.vue
5
+ const _hoisted_1 = ["for"];
6
+ const _hoisted_2 = ["for"];
7
+ const _sfc_main = /*@__PURE__*/ defineComponent({
8
+ name: "USheetHyperlinkPopup",
9
+ __name: "hyperlink-popup",
10
+ props: {
11
+ mode: {},
12
+ initial: {}
13
+ },
14
+ emits: ["confirm", "close"],
15
+ setup(__props, { emit: __emit }) {
16
+ /**
17
+ * 超链接配置弹窗(右键菜单拉起,无工具栏锚点——不走 UDropdown 工具面板链路,
18
+ * 自绘遮罩 + 居中面板,对齐 loading-mask 自绘先例):
19
+ * - 地址必填:空提交拦截并 message.error,弹窗不关
20
+ * - 显示文本可留空:留空不写入 text(单元格沿用自身内容作为显示)
21
+ * - mode="cell" 两字段;mode="image" 仅地址(图片超链接复用,写入目标由宿主收口)
22
+ * - 确认仅 emit confirm;关闭(取消/Esc/遮罩点击)emit close,均由宿主收口
23
+ */
24
+ const props = __props;
25
+ const emit = __emit;
26
+ const cls = bem("sheet");
27
+ /** 字段输入 id(useId:多实例同开不撞固定 id) */
28
+ const urlId = useId();
29
+ const textId = useId();
30
+ const url = ref(props.initial?.url ?? "");
31
+ const text = ref(props.initial?.text ?? "");
32
+ /** 遮罩层级:挂载时取全局递增 z-index(与 desktop 弹层互不压盖) */
33
+ const maskZIndex = zIndex();
34
+ const title = computed(() => {
35
+ if (props.mode === "image") return "设置图片超链接";
36
+ return props.initial ? "编辑超链接" : "插入超链接";
37
+ });
38
+ function handleConfirm() {
39
+ const nextUrl = url.value.trim();
40
+ if (!nextUrl) {
41
+ message.error("请输入链接地址");
42
+ return;
43
+ }
44
+ const nextText = text.value.trim();
45
+ emit("confirm", nextText ? {
46
+ url: nextUrl,
47
+ text: nextText
48
+ } : { url: nextUrl });
49
+ }
50
+ function handleCancel() {
51
+ emit("close");
52
+ }
53
+ /** Esc 关闭(window 级监听:弹窗内输入框未聚焦时同样生效) */
54
+ function onKeydown(event) {
55
+ if (event.key === "Escape") handleCancel();
56
+ }
57
+ onMounted(() => {
58
+ window.addEventListener("keydown", onKeydown);
59
+ });
60
+ onBeforeUnmount(() => {
61
+ window.removeEventListener("keydown", onKeydown);
62
+ });
63
+ return (_ctx, _cache) => {
64
+ return openBlock(), createBlock(Teleport, { to: "body" }, [createElementVNode("div", {
65
+ class: normalizeClass(unref(cls).e("link-dialog-mask")),
66
+ style: normalizeStyle({ zIndex: unref(maskZIndex) }),
67
+ onMousedown: withModifiers(handleCancel, ["self"])
68
+ }, [createElementVNode("div", {
69
+ class: normalizeClass(unref(cls).e("link-dialog")),
70
+ role: "dialog",
71
+ "aria-modal": "true"
72
+ }, [
73
+ createElementVNode("div", { class: normalizeClass(unref(cls).e("link-dialog-title")) }, toDisplayString(title.value), 3),
74
+ createElementVNode("div", { class: normalizeClass(unref(cls).e("link-dialog-body")) }, [createElementVNode("div", { class: normalizeClass(unref(cls).e("popup-row")) }, [createElementVNode("label", {
75
+ class: normalizeClass(unref(cls).e("popup-label")),
76
+ for: unref(urlId)
77
+ }, "地址", 10, _hoisted_1), createVNode(unref(UInput), {
78
+ id: unref(urlId),
79
+ modelValue: url.value,
80
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => url.value = $event),
81
+ class: normalizeClass(unref(cls).e("link-dialog-input")),
82
+ placeholder: "https://example.com",
83
+ size: "small",
84
+ onKeydown: withKeys(handleConfirm, ["enter"])
85
+ }, null, 8, [
86
+ "id",
87
+ "modelValue",
88
+ "class"
89
+ ])], 2), __props.mode === "cell" ? (openBlock(), createElementBlock("div", {
90
+ key: 0,
91
+ class: normalizeClass(unref(cls).e("popup-row"))
92
+ }, [createElementVNode("label", {
93
+ class: normalizeClass(unref(cls).e("popup-label")),
94
+ for: unref(textId)
95
+ }, "显示文本", 10, _hoisted_2), createVNode(unref(UInput), {
96
+ id: unref(textId),
97
+ modelValue: text.value,
98
+ "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => text.value = $event),
99
+ class: normalizeClass(unref(cls).e("link-dialog-input")),
100
+ placeholder: "留空沿用单元格内容",
101
+ size: "small",
102
+ onKeydown: withKeys(handleConfirm, ["enter"])
103
+ }, null, 8, [
104
+ "id",
105
+ "modelValue",
106
+ "class"
107
+ ])], 2)) : createCommentVNode("v-if", true)], 2),
108
+ createElementVNode("div", { class: normalizeClass(unref(cls).e("link-dialog-footer")) }, [createVNode(unref(UButton), {
109
+ size: "small",
110
+ onClick: handleCancel
111
+ }, {
112
+ default: withCtx(() => [..._cache[2] || (_cache[2] = [createTextVNode("取消", -1)])]),
113
+ _: 1
114
+ }), createVNode(unref(UButton), {
115
+ size: "small",
116
+ type: "primary",
117
+ onClick: handleConfirm
118
+ }, {
119
+ default: withCtx(() => [..._cache[3] || (_cache[3] = [createTextVNode("确定", -1)])]),
120
+ _: 1
121
+ })], 2)
122
+ ], 2)], 38)]);
123
+ };
124
+ }
125
+ });
126
+ //#endregion
127
+ export { _sfc_main as default };
@@ -1,4 +1,5 @@
1
1
  import { defaultToolRegistry } from "../../tools/registry.js";
2
+ import { imageLinkInitial, imagePreviewSource } from "./popup-helpers.js";
2
3
  import { pickAndInsertImage } from "./insert-image.js";
3
4
  import _sfc_main from "./insert-count-menu-item.js";
4
5
  import { createRange } from "infinitable/sheet";
@@ -211,11 +212,80 @@ function buildColHeaderMenus(ctx, options) {
211
212
  function applyNumFmtToSelection(ctx, numFmt) {
212
213
  for (const range of ctx.getSelection().ranges) ctx.applyStyle(range, { numFmt });
213
214
  }
214
- /** body 格右键菜单:合并/取消合并 + 设置数据格式 + 插入图片(行列插入/删除仅行号/列头菜单) */
215
- function buildBodyMenus(ctx) {
215
+ /**
216
+ * body 菜单超链接项:按目标格链接状态出项——
217
+ * 无链接「插入超链接」;有链接「编辑超链接」(回填原 url/text)+「取消超链接」。
218
+ * 取消直走 clearCellLink(可 undo);插入/编辑经注入句柄拉起弹窗。
219
+ */
220
+ function cellLinkMenuItems(ctx, active, options) {
221
+ if (!active) return [{
222
+ label: "插入超链接",
223
+ disabled: true
224
+ }];
225
+ const handle = options?.openHyperlinkPopup;
226
+ const disabled = options?.readonly === true || !handle;
227
+ const link = ctx.getCellLink(active);
228
+ if (!link) return [{
229
+ label: "插入超链接",
230
+ disabled,
231
+ callback: () => handle?.("cell")
232
+ }];
233
+ return [{
234
+ label: "编辑超链接",
235
+ disabled,
236
+ callback: () => handle?.("cell", link)
237
+ }, {
238
+ label: "取消超链接",
239
+ disabled: options?.readonly === true,
240
+ callback: () => ctx.clearCellLink(active)
241
+ }];
242
+ }
243
+ /**
244
+ * body 菜单嵌入图项:目标格含嵌入图时附加——预览 / 图片超链接 / 取消超链接
245
+ * (按载荷 link 状态出项)/ 移除图片。设置走 hyperlink 弹窗 image 模式(确认后
246
+ * 由宿主覆盖写 `insertCellImage(addr, { ...payload, link })`);取消直写覆盖
247
+ * `link: undefined`(引擎 CellImagePayload 清除约定,其余字段保留);移除走
248
+ * `removeCellImage`(命令系统,可 undo)。无嵌入图返回空数组(不出现图片项)。
249
+ */
250
+ function cellImageMenuItems(ctx, active, options) {
251
+ if (!active || !ctx.hasCellImage(active)) return [];
252
+ const payload = ctx.getCellImage(active);
253
+ if (!payload) return [];
254
+ const handle = options?.openHyperlinkPopup;
255
+ const readonly = options?.readonly === true;
256
+ const items = [{
257
+ label: "预览",
258
+ disabled: !options?.openImagePreview,
259
+ callback: () => options?.openImagePreview?.(imagePreviewSource(payload))
260
+ }, {
261
+ label: "图片超链接",
262
+ disabled: readonly || !handle,
263
+ callback: () => handle?.("image", imageLinkInitial(payload.link), {
264
+ kind: "cell",
265
+ addr: active
266
+ })
267
+ }];
268
+ if (payload.link) items.push({
269
+ label: "取消超链接",
270
+ disabled: readonly,
271
+ callback: () => ctx.insertCellImage(active, {
272
+ ...payload,
273
+ link: void 0
274
+ })
275
+ });
276
+ items.push({
277
+ label: "移除图片",
278
+ disabled: readonly,
279
+ callback: () => ctx.removeCellImage(active)
280
+ });
281
+ return items;
282
+ }
283
+ /** body 格右键菜单:合并/取消合并 + 设置数据格式 + 超链接 + 插入图片(+ 嵌入图四项;行列插入/删除仅行号/列头菜单) */
284
+ function buildBodyMenus(ctx, options) {
216
285
  const mergeTool = defaultToolRegistry.get("merge");
217
286
  const unmergeTool = defaultToolRegistry.get("unmerge");
218
287
  const active = ctx.getSelection().activeCell;
288
+ const imageItems = cellImageMenuItems(ctx, active, options);
219
289
  return [
220
290
  {
221
291
  label: "合并单元格",
@@ -261,11 +331,13 @@ function buildBodyMenus(ctx) {
261
331
  }
262
332
  ]
263
333
  },
334
+ ...cellLinkMenuItems(ctx, active, options),
264
335
  {
265
336
  label: "插入图片",
266
337
  disabled: !active,
267
338
  callback: () => pickAndInsertImage(ctx)
268
- }
339
+ },
340
+ ...imageItems.length > 0 ? [{ divider: true }, ...imageItems] : []
269
341
  ];
270
342
  }
271
343
  /**
@@ -7,15 +7,17 @@ import _sfc_main$5 from "./popups/fill-color-popup.js";
7
7
  import _sfc_main$6 from "./popups/find-popup.js";
8
8
  import _sfc_main$7 from "./popups/font-color-popup.js";
9
9
  import _sfc_main$8 from "./popups/font-size-popup.js";
10
- import _sfc_main$9 from "./popups/insert-image-popup.js";
11
- import _sfc_main$10 from "./sheet-tabs.js";
12
- import _sfc_main$11 from "./sheet-toolbar.js";
10
+ import _sfc_main$9 from "./popups/hyperlink-popup.js";
11
+ import _sfc_main$10 from "./popups/insert-image-popup.js";
12
+ import _sfc_main$11 from "./sheet-tabs.js";
13
+ import _sfc_main$12 from "./sheet-toolbar.js";
14
+ import { useCellLinkTooltip } from "./use-cell-link-tooltip.js";
13
15
  import { useSheetGrid } from "./use-sheet-grid.js";
14
16
  import { useSheetState } from "./use-sheet-state.js";
15
17
  import { useToolGroups } from "./use-tool-groups.js";
16
18
  import { useToolPopup } from "./use-tool-popup.js";
17
- import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, openBlock, ref, toDisplayString, unref, useTemplateRef, watch, withCtx, withModifiers } from "vue";
18
- import { UDropdown } from "@veltra/desktop";
19
+ import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, normalizeStyle, openBlock, ref, shallowRef, toDisplayString, unref, useTemplateRef, watch, withCtx, withModifiers } from "vue";
20
+ import { UDropdown, UImagePreviewer } from "@veltra/desktop";
19
21
  import { bem } from "@veltra/utils";
20
22
  //#region src/components/sheet/sheet.vue
21
23
  const _sfc_main = /*@__PURE__*/ defineComponent({
@@ -67,7 +69,16 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
67
69
  default: true
68
70
  }
69
71
  },
70
- emits: ["active-sheet-change", "col-resize-end"],
72
+ emits: [
73
+ "active-sheet-change",
74
+ "col-resize-end",
75
+ "cell-link-hover",
76
+ "cell-link-leave",
77
+ "cell-link-click",
78
+ "image-link-click",
79
+ "cell-image-change",
80
+ "float-context-menu"
81
+ ],
71
82
  setup(__props, { expose: __expose, emit: __emit }) {
72
83
  const props = __props;
73
84
  const emit = __emit;
@@ -123,6 +134,50 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
123
134
  if (!visible) closePopup();
124
135
  }
125
136
  const toolGroups = useToolGroups(context, stateTick);
137
+ /** 超链接配置弹层状态(右键菜单拉起):mode + 编辑回填 + 写入目标(cell 格 / image 浮动图或嵌入图) */
138
+ const hyperlinkPopup = shallowRef(null);
139
+ /** 悬停 tooltip 状态机(引擎 cell link hover/leave 事件驱动,层坐标换算见 use-cell-link-tooltip) */
140
+ const { tooltip: cellLinkTooltip, onCellLinkHover: showCellLinkTooltip, onCellLinkLeave: hideCellLinkTooltip } = useCellLinkTooltip();
141
+ /** 右键菜单超链接项句柄:记录写入目标并拉起弹窗(编辑回填原 url/text) */
142
+ function openHyperlinkPopup(mode, initial, imageTarget) {
143
+ hyperlinkPopup.value = {
144
+ mode,
145
+ initial,
146
+ addr: mode === "cell" ? context.getSelection().activeCell ?? void 0 : void 0,
147
+ imageTarget: mode === "image" ? imageTarget : void 0
148
+ };
149
+ }
150
+ /**
151
+ * 弹窗确认:关弹层并写目标链接,一次写入 = 一个 undo 单元。
152
+ * cell:setCellLink(显示文本留空不写入 text → 单元格沿用自身内容显示);
153
+ * 浮动图:updateImage(link 字段);嵌入图:insertCellImage 覆盖写(其余载荷保留)。
154
+ */
155
+ function handleHyperlinkConfirm(payload) {
156
+ const current = hyperlinkPopup.value;
157
+ hyperlinkPopup.value = null;
158
+ if (current?.mode === "cell") {
159
+ if (current.addr) context.setCellLink(current.addr, payload);
160
+ return;
161
+ }
162
+ const target = current?.imageTarget;
163
+ if (target?.kind === "float") {
164
+ context.updateImage(target.id, { link: payload.url });
165
+ return;
166
+ }
167
+ if (target?.kind === "cell") {
168
+ const existing = context.getCellImage(target.addr);
169
+ if (existing) context.insertCellImage(target.addr, {
170
+ ...existing,
171
+ link: payload.url
172
+ });
173
+ }
174
+ }
175
+ /** lightbox 预览状态(右键「预览」拉起):URL 或字节 + MIME;关闭置 null 卸载(objectURL 由 UImagePreviewer 回收) */
176
+ const imagePreview = shallowRef(null);
177
+ /** 右键「预览」句柄:浮动图 / 嵌入图菜单共用 */
178
+ function openImagePreview(source) {
179
+ imagePreview.value = source;
180
+ }
126
181
  const gridRef = useTemplateRef("gridRef");
127
182
  const formulaBarRef = useTemplateRef("formulaBarRef");
128
183
  const { rebuildGrid, activateGrid, pruneCache, getGrid, setSelectionAnchor } = useSheetGrid({
@@ -132,7 +187,20 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
132
187
  context,
133
188
  formulaBarRef,
134
189
  isFunctionPopupOpen: () => popupTool.value?.popup === "functions",
135
- onColResizeEnd: (event) => emit("col-resize-end", event)
190
+ onColResizeEnd: (event) => emit("col-resize-end", event),
191
+ onCellLinkHover: (event) => {
192
+ emit("cell-link-hover", event);
193
+ showCellLinkTooltip(event);
194
+ },
195
+ onCellLinkLeave: (event) => {
196
+ emit("cell-link-leave", event);
197
+ hideCellLinkTooltip(event);
198
+ },
199
+ onCellLinkClick: (event) => emit("cell-link-click", event),
200
+ onImageLinkClick: (event) => emit("image-link-click", event),
201
+ onFloatContextMenu: (event) => emit("float-context-menu", event),
202
+ openHyperlinkPopup,
203
+ openImagePreview
136
204
  });
137
205
  __expose({
138
206
  workbook,
@@ -151,7 +219,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
151
219
  ref: toolbarWrapRef,
152
220
  class: normalizeClass(unref(cls).e("toolbar-wrap"))
153
221
  }, [
154
- __props.showToolbar ? (openBlock(), createBlock(_sfc_main$11, {
222
+ __props.showToolbar ? (openBlock(), createBlock(_sfc_main$12, {
155
223
  key: 0,
156
224
  groups: unref(toolGroups),
157
225
  onToolClick: handleToolClick
@@ -193,7 +261,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
193
261
  ])) : unref(popupTool).popup === "functions" ? (openBlock(), createBlock(_sfc_main$1, {
194
262
  key: 5,
195
263
  onSelect: handleFunctionSelect
196
- })) : unref(popupTool).popup === "insert-image" ? (openBlock(), createBlock(_sfc_main$9, {
264
+ })) : unref(popupTool).popup === "insert-image" ? (openBlock(), createBlock(_sfc_main$10, {
197
265
  key: 6,
198
266
  context: unref(context),
199
267
  onClose: unref(closePopup)
@@ -221,11 +289,23 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
221
289
  ref_key: "gridRef",
222
290
  ref: gridRef,
223
291
  class: normalizeClass(unref(cls).e("grid"))
224
- }, [createCommentVNode(" 导入解析覆盖层(自绘,不动 desktop Loading 组件):遮罩 + 动画 + 文字\n 同一层,动画在上、文字在下,不存在被遮罩掩盖的问题 "), parsing.value ? (openBlock(), createElementBlock("div", {
225
- key: 0,
226
- class: normalizeClass(unref(cls).e("loading-mask"))
227
- }, [createElementVNode("div", { class: normalizeClass(unref(cls).e("loading-spinner")) }, null, 2), createElementVNode("div", { class: normalizeClass(unref(cls).e("loading-text")) }, toDisplayString(parseText.value), 3)], 2)) : createCommentVNode("v-if", true)], 2),
228
- __props.showTabs ? (openBlock(), createBlock(_sfc_main$10, {
292
+ }, [
293
+ createCommentVNode(" 导入解析覆盖层(自绘,不动 desktop Loading 组件):遮罩 + 动画 + 文字\n 同一层,动画在上、文字在下,不存在被遮罩掩盖的问题 "),
294
+ parsing.value ? (openBlock(), createElementBlock("div", {
295
+ key: 0,
296
+ class: normalizeClass(unref(cls).e("loading-mask"))
297
+ }, [createElementVNode("div", { class: normalizeClass(unref(cls).e("loading-spinner")) }, null, 2), createElementVNode("div", { class: normalizeClass(unref(cls).e("loading-text")) }, toDisplayString(parseText.value), 3)], 2)) : createCommentVNode("v-if", true),
298
+ createCommentVNode(" 悬停链接格 tooltip:引擎 cell link hover/leave 事件驱动挂载/卸载,\n 层坐标 + 偏移后绝对定位于 grid 区(不遮指针;pointer-events: none) "),
299
+ unref(cellLinkTooltip) ? (openBlock(), createElementBlock("div", {
300
+ key: 1,
301
+ class: normalizeClass(unref(cls).e("link-tooltip")),
302
+ style: normalizeStyle({
303
+ left: `${unref(cellLinkTooltip).left}px`,
304
+ top: `${unref(cellLinkTooltip).top}px`
305
+ })
306
+ }, toDisplayString(unref(cellLinkTooltip).url), 7)) : createCommentVNode("v-if", true)
307
+ ], 2),
308
+ __props.showTabs ? (openBlock(), createBlock(_sfc_main$11, {
229
309
  key: 1,
230
310
  workbook: unref(workbook),
231
311
  "sheet-list": unref(sheetList),
@@ -234,7 +314,22 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
234
314
  "workbook",
235
315
  "sheet-list",
236
316
  "active-index"
237
- ])) : createCommentVNode("v-if", true)
317
+ ])) : createCommentVNode("v-if", true),
318
+ createCommentVNode(" 单元格/图片超链接配置弹窗(右键菜单拉起;confirm 按模式路由写入) "),
319
+ hyperlinkPopup.value ? (openBlock(), createBlock(_sfc_main$9, {
320
+ key: 2,
321
+ mode: hyperlinkPopup.value.mode,
322
+ initial: hyperlinkPopup.value.initial,
323
+ onConfirm: handleHyperlinkConfirm,
324
+ onClose: _cache[1] || (_cache[1] = ($event) => hyperlinkPopup.value = null)
325
+ }, null, 8, ["mode", "initial"])) : createCommentVNode("v-if", true),
326
+ createCommentVNode(" 图片 lightbox 预览(浮动图/嵌入图右键「预览」拉起;关闭卸载 → objectURL 由组件回收) "),
327
+ imagePreview.value ? (openBlock(), createBlock(unref(UImagePreviewer), {
328
+ key: 3,
329
+ src: imagePreview.value.src ?? imagePreview.value.data,
330
+ mime: imagePreview.value.mime,
331
+ onClose: _cache[2] || (_cache[2] = ($event) => imagePreview.value = null)
332
+ }, null, 8, ["src", "mime"])) : createCommentVNode("v-if", true)
238
333
  ], 2);
239
334
  };
240
335
  }
@@ -645,6 +645,68 @@
645
645
  inset: 0;
646
646
  visibility: hidden;
647
647
  }
648
+ .u-sheet {
649
+ /* 悬停链接格 tooltip:引擎 cell link hover/leave 事件驱动挂载/卸载,
650
+ 层坐标 + 偏移后绝对定位于 grid 区;pointer-events: none 避免浮层
651
+ 自身命中指针触发 leave 抖动(DOM 顺序在画布之后,天然盖在画布上) */
652
+ }
653
+ .u-sheet__link-tooltip {
654
+ position: absolute;
655
+ z-index: 10;
656
+ max-width: 320px;
657
+ padding: 2px 8px;
658
+ border: var(--u-border);
659
+ border-radius: var(--u-radius-small);
660
+ background-color: var(--u-bg-color-top);
661
+ box-shadow: var(--u-shadow-sm);
662
+ color: var(--u-text-color-main);
663
+ font-size: var(--u-font-size-main-small);
664
+ white-space: nowrap;
665
+ overflow: hidden;
666
+ text-overflow: ellipsis;
667
+ pointer-events: none;
668
+ }
669
+ .u-sheet {
670
+ /* ── 超链接配置弹窗(右键菜单拉起,无工具栏锚点:自绘遮罩 + 居中面板,
671
+ 对齐 loading-mask 自绘先例;遮罩半透明黑与 desktop dialog overlay 同口径) ── */
672
+ }
673
+ .u-sheet__link-dialog-mask {
674
+ position: fixed;
675
+ inset: 0;
676
+ display: flex;
677
+ align-items: center;
678
+ justify-content: center;
679
+ background-color: rgba(0, 0, 0, 0.32);
680
+ }
681
+ .u-sheet__link-dialog {
682
+ display: flex;
683
+ flex-direction: column;
684
+ gap: var(--u-gap-small);
685
+ width: min(380px, 90vw);
686
+ padding: var(--u-gap-default);
687
+ border-radius: var(--u-radius-large);
688
+ background-color: var(--u-bg-color-top);
689
+ box-shadow: var(--u-shadow-lg);
690
+ }
691
+ .u-sheet__link-dialog-title {
692
+ color: var(--u-text-color-main);
693
+ font-size: var(--u-font-size-title-default);
694
+ font-weight: 600;
695
+ }
696
+ .u-sheet__link-dialog-body {
697
+ display: flex;
698
+ flex-direction: column;
699
+ gap: var(--u-gap-small);
700
+ }
701
+ .u-sheet__link-dialog-input {
702
+ flex: 1;
703
+ min-width: 0;
704
+ }
705
+ .u-sheet__link-dialog-footer {
706
+ display: flex;
707
+ justify-content: flex-end;
708
+ gap: var(--u-gap-small);
709
+ }
648
710
  .u-sheet__tabs {
649
711
  display: flex;
650
712
  align-items: center;
@@ -0,0 +1,33 @@
1
+ import { shallowRef } from "vue";
2
+ //#region src/components/sheet/use-cell-link-tooltip.ts
3
+ /**
4
+ * tooltip 相对悬停落点的偏移:右下错开,浮层不遮指针与命中的链接文本。
5
+ */
6
+ const TOOLTIP_OFFSET_X = 8;
7
+ const TOOLTIP_OFFSET_Y = 20;
8
+ /**
9
+ * 单元格超链接悬停 tooltip(引擎 hover/leave 事件驱动):
10
+ * hover 时记录命中的层坐标 + URL(层坐标相对 grid 实例容器 = grid 区原点,
11
+ * 渲染层直接在 grid 区内绝对定位挂载浮层);leave 时卸载(置 null)。
12
+ * 事件源接线在 use-sheet-grid(与 cell-link-hover/leave 组件 emit 同源)。
13
+ */
14
+ function useCellLinkTooltip() {
15
+ const tooltip = shallowRef(null);
16
+ function onCellLinkHover(event) {
17
+ tooltip.value = {
18
+ url: event.url,
19
+ left: event.x + TOOLTIP_OFFSET_X,
20
+ top: event.y + TOOLTIP_OFFSET_Y
21
+ };
22
+ }
23
+ function onCellLinkLeave() {
24
+ tooltip.value = null;
25
+ }
26
+ return {
27
+ tooltip,
28
+ onCellLinkHover,
29
+ onCellLinkLeave
30
+ };
31
+ }
32
+ //#endregion
33
+ export { useCellLinkTooltip };
@@ -1,3 +1,4 @@
1
+ import { popFloatImageMenu } from "./float-image-menu.js";
1
2
  import { buildBodyMenus, buildColHeaderMenus, buildRowHeaderMenus, ensureContextMenuSelection, resolveRenderSize } from "./sheet-context-menu.js";
2
3
  import { SheetGrid } from "infinitable/sheet";
3
4
  import { onBeforeUnmount, onMounted, watch } from "vue";
@@ -68,7 +69,11 @@ function useSheetGrid(options) {
68
69
  }) : info.kind === "col-header" ? buildColHeaderMenus(context, {
69
70
  readonly: props.readonly,
70
71
  col: info.col
71
- }) : buildBodyMenus(context);
72
+ }) : buildBodyMenus(context, {
73
+ readonly: props.readonly,
74
+ openHyperlinkPopup: options.openHyperlinkPopup,
75
+ openImagePreview: options.openImagePreview
76
+ });
72
77
  contextmenu.pop({
73
78
  mousePosition: {
74
79
  x: info.x,
@@ -125,8 +130,34 @@ function useSheetGrid(options) {
125
130
  const offStructureChange = sheet.on("structure-change", () => {
126
131
  dirty = true;
127
132
  });
133
+ const table = grid.getTable();
134
+ const offEngineEvents = [
135
+ table.onCellLinkHover((event) => options.onCellLinkHover?.(event)),
136
+ table.onCellLinkLeave((event) => options.onCellLinkLeave?.(event)),
137
+ table.onCellLinkClick((event) => options.onCellLinkClick?.(event)),
138
+ table.onImageLinkClick((event) => options.onImageLinkClick?.(event)),
139
+ table.floatObjects.onContextMenu((event) => {
140
+ const rect = el.getBoundingClientRect();
141
+ const payload = {
142
+ ...event,
143
+ clientX: rect.left + event.x,
144
+ clientY: rect.top + event.y
145
+ };
146
+ options.onFloatContextMenu?.(payload);
147
+ popFloatImageMenu({
148
+ ctx: context,
149
+ event: payload,
150
+ handles: {
151
+ openImagePreview: options.openImagePreview,
152
+ openHyperlinkPopup: options.openHyperlinkPopup
153
+ },
154
+ readonly: props.readonly
155
+ });
156
+ })
157
+ ];
128
158
  const release = () => {
129
159
  offStructureChange();
160
+ for (const off of offEngineEvents) off();
130
161
  grid.release();
131
162
  el.remove();
132
163
  };
@@ -49,6 +49,7 @@ function useSheetState(props, emit, hooks) {
49
49
  sheet.on("cell-change", bump),
50
50
  sheet.on("merge-change", bump),
51
51
  sheet.on("frozen-change", bump),
52
+ sheet.on("cell-image-change", (payload) => emit("cell-image-change", payload)),
52
53
  sheet.on("content-reset", scheduleBump),
53
54
  sheet.on("structure-change", hooks.rebuildGrid)
54
55
  ];