@veltra/sheet 4.0.0 → 4.1.1

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 (36) hide show
  1. package/dist/components/sheet/float-image-menu.js +87 -0
  2. package/dist/components/sheet/insert-image.js +33 -4
  3. package/dist/components/sheet/popup-helpers.js +18 -2
  4. package/dist/components/sheet/popups/hyperlink-popup.js +127 -0
  5. package/dist/components/sheet/sheet-context-menu.js +122 -5
  6. package/dist/components/sheet/sheet.js +132 -15
  7. package/dist/components/sheet/style.d.ts +2 -0
  8. package/dist/components/sheet/style.js +2 -0
  9. package/dist/components/sheet/style2.css +62 -0
  10. package/dist/components/sheet/use-cell-link-tooltip.js +33 -0
  11. package/dist/components/sheet/use-sheet-grid.js +33 -1
  12. package/dist/components/sheet/use-sheet-state.js +1 -0
  13. package/dist/tools/context.d.ts +20 -2
  14. package/dist/tools/context.js +9 -1
  15. package/dist/types/index.d.ts +2 -2
  16. package/dist/types/sheet.d.ts +51 -1
  17. package/package.json +2 -2
  18. package/src/components/sheet/__test__/float-image-menu.test.ts +196 -0
  19. package/src/components/sheet/__test__/hyperlink-popup.test.ts +176 -0
  20. package/src/components/sheet/__test__/insert-image.test.ts +60 -0
  21. package/src/components/sheet/__test__/sheet-component.test.ts +539 -16
  22. package/src/components/sheet/__test__/sheet-context-menu.test.ts +293 -4
  23. package/src/components/sheet/float-image-menu.ts +100 -0
  24. package/src/components/sheet/insert-image.ts +32 -3
  25. package/src/components/sheet/popup-helpers.ts +68 -2
  26. package/src/components/sheet/popups/hyperlink-popup.vue +112 -0
  27. package/src/components/sheet/sheet-context-menu.ts +125 -6
  28. package/src/components/sheet/sheet.vue +149 -3
  29. package/src/components/sheet/style.scss +66 -0
  30. package/src/components/sheet/style.ts +3 -1
  31. package/src/components/sheet/use-cell-link-tooltip.ts +42 -0
  32. package/src/components/sheet/use-sheet-grid.ts +62 -3
  33. package/src/components/sheet/use-sheet-state.ts +8 -2
  34. package/src/tools/__test__/context.test.ts +89 -0
  35. package/src/tools/context.ts +33 -2
  36. package/src/types/sheet.ts +56 -0
@@ -1,13 +1,15 @@
1
1
  import type { ContextmenuItem } from '@veltra/desktop'
2
2
  import { createRange, type CellAddress, type CellRange } from 'infinitable/sheet'
3
- import type { NumFmt } from 'infinitable/sheet'
3
+ import type { ImageInput, NumFmt } from 'infinitable/sheet'
4
4
  import { defineComponent, h } from 'vue'
5
5
 
6
6
  import type { SheetContext } from '../../tools/context'
7
7
  import { MIN_ROW_COL_SIZE } from '../../tools/context'
8
8
  import { defaultToolRegistry } from '../../tools/registry'
9
9
  import InsertCountMenuItem from './insert-count-menu-item.vue'
10
- import { pickAndInsertImage } from './insert-image'
10
+ import { pickAndEmbedCellImage, pickAndInsertImage } from './insert-image'
11
+ import type { ImagePreviewSource, OpenHyperlinkPopup } from './popup-helpers'
12
+ import { imageLinkInitial, imagePreviewSource } from './popup-helpers'
11
13
 
12
14
  /** 插入数量钳制范围(对齐 univer) */
13
15
  export const INSERT_COUNT_MIN = 1
@@ -263,11 +265,126 @@ export function applyNumFmtToSelection(ctx: SheetContext, numFmt: NumFmt): void
263
265
  for (const range of ctx.getSelection().ranges) ctx.applyStyle(range, { numFmt })
264
266
  }
265
267
 
266
- /** body 格右键菜单:合并/取消合并 + 设置数据格式 + 插入图片(行列插入/删除仅行号/列头菜单) */
267
- export function buildBodyMenus(ctx: SheetContext): ContextmenuItem[] {
268
+ /** body 格右键菜单选项(超链接 / 图片预览项行为注入) */
269
+ export interface BodyMenuOptions {
270
+ /** 只读模式:超链接与嵌入图写入项禁用(对齐行高/列宽 readonly 禁用约定) */
271
+ readonly?: boolean
272
+ /** 拉起超链接配置弹窗的句柄(缺省时插入/编辑项禁用,保持 build 纯函数可测) */
273
+ openHyperlinkPopup?: OpenHyperlinkPopup
274
+ /** 打开 lightbox 预览的句柄(缺省时嵌入图「预览」项禁用) */
275
+ openImagePreview?: (source: ImagePreviewSource) => void
276
+ }
277
+
278
+ /**
279
+ * body 菜单超链接项:按目标格链接状态出项——
280
+ * 无链接「插入超链接」;有链接「编辑超链接」(回填原 url/text)+「取消超链接」。
281
+ * 取消直走 clearCellLink(可 undo);插入/编辑经注入句柄拉起弹窗。
282
+ */
283
+ function cellLinkMenuItems(
284
+ ctx: SheetContext,
285
+ active: CellAddress | null | undefined,
286
+ options?: BodyMenuOptions
287
+ ): ContextmenuItem[] {
288
+ if (!active) return [{ label: '插入超链接', disabled: true }]
289
+ const handle = options?.openHyperlinkPopup
290
+ const disabled = options?.readonly === true || !handle
291
+ const link = ctx.getCellLink(active)
292
+ if (!link) {
293
+ return [{ label: '插入超链接', disabled, callback: () => handle?.('cell') }]
294
+ }
295
+ return [
296
+ { label: '编辑超链接', disabled, callback: () => handle?.('cell', link) },
297
+ {
298
+ label: '取消超链接',
299
+ disabled: options?.readonly === true,
300
+ callback: () => ctx.clearCellLink(active)
301
+ }
302
+ ]
303
+ }
304
+
305
+ /**
306
+ * 按格嵌入图转为浮动图片(对齐 Excel「放置到单元格上」/ WPS 反向切换):浮动图
307
+ * 落在嵌入图锚点格、尺寸取该格宽高(视觉等价还原),fit 缺省 contain(对齐嵌入图
308
+ * 渲染约定,避免浮动图缺省 fill 拉伸变形),src/data/type/link 随载荷迁移。事务内
309
+ * insertImage + removeCellImage——一次转换 = 一个 undo 单元。
310
+ */
311
+ export function cellImageToFloat(ctx: SheetContext, addr: CellAddress): void {
312
+ const payload = ctx.getCellImage(addr)
313
+ if (!payload) return
314
+ const anchor = ctx.getCellInfo(addr).anchor
315
+ const input: ImageInput = {
316
+ data: payload.data ?? new Uint8Array(),
317
+ type: payload.type ?? 'png',
318
+ anchor: { from: { row: anchor.row, col: anchor.col } },
319
+ width: ctx.getColWidth(anchor.col) ?? FALLBACK_COL_WIDTH,
320
+ height: ctx.getRowHeight(anchor.row) ?? FALLBACK_ROW_HEIGHT,
321
+ fit: payload.fit ?? 'contain'
322
+ }
323
+ if (payload.src) input.src = payload.src
324
+ if (payload.link) input.link = payload.link
325
+ ctx.beginTransaction()
326
+ ctx.insertImage(input)
327
+ ctx.removeCellImage(addr)
328
+ ctx.commit()
329
+ }
330
+
331
+ /**
332
+ * body 菜单嵌入图项:预览 / 图片超链接 / 取消超链接(按载荷 link 状态出项)/
333
+ * 转为浮动图片 / 替换图片 / 移除图片。设置走 hyperlink 弹窗 image 模式(确认后由宿主覆盖写
334
+ * `insertCellImage(addr, { ...payload, link })`);取消直写覆盖 `link: undefined`
335
+ * (引擎 CellImagePayload 清除约定,其余字段保留);转换/替换/移除分别走
336
+ * `cellImageToFloat`、`insertCellImage` 覆盖与 `removeCellImage`(命令系统,可 undo)。
337
+ */
338
+ function cellImageMenuItems(
339
+ ctx: SheetContext,
340
+ active: CellAddress | null | undefined,
341
+ options?: BodyMenuOptions
342
+ ): ContextmenuItem[] {
343
+ if (!active || !ctx.hasCellImage(active)) return []
344
+ const payload = ctx.getCellImage(active)
345
+ if (!payload) return []
346
+ const handle = options?.openHyperlinkPopup
347
+ const readonly = options?.readonly === true
348
+ const items: ContextmenuItem[] = [
349
+ {
350
+ label: '预览',
351
+ disabled: !options?.openImagePreview,
352
+ callback: () => options?.openImagePreview?.(imagePreviewSource(payload))
353
+ },
354
+ {
355
+ label: '图片超链接',
356
+ disabled: readonly || !handle,
357
+ callback: () =>
358
+ handle?.('image', imageLinkInitial(payload.link), { kind: 'cell', addr: active })
359
+ }
360
+ ]
361
+ if (payload.link) {
362
+ items.push({
363
+ label: '取消超链接',
364
+ disabled: readonly,
365
+ callback: () => ctx.insertCellImage(active, { ...payload, link: undefined })
366
+ })
367
+ }
368
+ items.push(
369
+ { label: '转为浮动图片', disabled: readonly, callback: () => cellImageToFloat(ctx, active) },
370
+ { label: '替换图片', disabled: readonly, callback: () => pickAndEmbedCellImage(ctx) },
371
+ { label: '移除图片', disabled: readonly, callback: () => ctx.removeCellImage(active) }
372
+ )
373
+ return items
374
+ }
375
+
376
+ /**
377
+ * body 格右键菜单。目标格含嵌入图时出**纯图片菜单**(预览 / 超链接 / 转浮动 /
378
+ * 替换 / 移除)——图片盖住整格,右键语义是「图片」而非「单元格」,不出合并 /
379
+ * 数据格式 / 超链接等普通格项(对齐 Excel 图片右键约定)。普通格:合并 / 取消合并 +
380
+ * 设置数据格式 + 超链接 + 插入图片(浮动)+ 嵌入图片(入格);行列插入/删除仅行号/列头菜单。
381
+ */
382
+ export function buildBodyMenus(ctx: SheetContext, options?: BodyMenuOptions): ContextmenuItem[] {
383
+ const active = ctx.getSelection().activeCell
384
+ if (active && ctx.hasCellImage(active)) return cellImageMenuItems(ctx, active, options)
385
+
268
386
  const mergeTool = defaultToolRegistry.get('merge')
269
387
  const unmergeTool = defaultToolRegistry.get('unmerge')
270
- const active = ctx.getSelection().activeCell
271
388
 
272
389
  return [
273
390
  {
@@ -302,7 +419,9 @@ export function buildBodyMenus(ctx: SheetContext): ContextmenuItem[] {
302
419
  }
303
420
  ]
304
421
  },
305
- { label: '插入图片', disabled: !active, callback: () => pickAndInsertImage(ctx) }
422
+ ...cellLinkMenuItems(ctx, active, options),
423
+ { label: '插入图片', disabled: !active, callback: () => pickAndInsertImage(ctx) },
424
+ { label: '嵌入图片', disabled: !active, callback: () => pickAndEmbedCellImage(ctx) }
306
425
  ]
307
426
  }
308
427
 
@@ -66,6 +66,16 @@
66
66
  <div :class="cls.e('loading-spinner')"></div>
67
67
  <div :class="cls.e('loading-text')">{{ parseText }}</div>
68
68
  </div>
69
+
70
+ <!-- 悬停链接格 tooltip:引擎 cell link hover/leave 事件驱动挂载/卸载,
71
+ 层坐标 + 偏移后绝对定位于 grid 区(不遮指针;pointer-events: none) -->
72
+ <div
73
+ v-if="cellLinkTooltip"
74
+ :class="cls.e('link-tooltip')"
75
+ :style="{ left: `${cellLinkTooltip.left}px`, top: `${cellLinkTooltip.top}px` }"
76
+ >
77
+ {{ cellLinkTooltip.url }}
78
+ </div>
69
79
  </div>
70
80
 
71
81
  <u-sheet-tabs
@@ -74,18 +84,47 @@
74
84
  :sheet-list="sheetList"
75
85
  :active-index="activeIndex"
76
86
  />
87
+
88
+ <!-- 单元格/图片超链接配置弹窗(右键菜单拉起;confirm 按模式路由写入) -->
89
+ <u-sheet-hyperlink-popup
90
+ v-if="hyperlinkPopup"
91
+ :mode="hyperlinkPopup.mode"
92
+ :initial="hyperlinkPopup.initial"
93
+ @confirm="handleHyperlinkConfirm"
94
+ @close="hyperlinkPopup = null"
95
+ />
96
+
97
+ <!-- 图片 lightbox 预览(浮动图/嵌入图右键「预览」拉起;关闭卸载 → objectURL 由组件回收) -->
98
+ <u-image-previewer
99
+ v-if="imagePreview"
100
+ :src="imagePreview.src ?? imagePreview.data"
101
+ :mime="imagePreview.mime"
102
+ @close="imagePreview = null"
103
+ />
77
104
  </div>
78
105
  </template>
79
106
 
80
107
  <script lang="ts" setup>
81
- import { UDropdown } from '@veltra/desktop'
108
+ import { UDropdown, UImagePreviewer, messageConfirm } from '@veltra/desktop'
82
109
  import { bem } from '@veltra/utils'
83
- import { computed, ref, useTemplateRef, watch } from 'vue'
110
+ import type {
111
+ CellAddress,
112
+ CellLinkClickEvent,
113
+ CellLinkPayload,
114
+ ImageLinkClickEvent
115
+ } from 'infinitable/sheet'
116
+ import { computed, ref, shallowRef, useTemplateRef, watch } from 'vue'
84
117
 
85
118
  import type { SheetTool } from '../../tools/registry'
86
119
  import type { SheetEmits, SheetProps, _SheetExposed } from '../../types'
87
120
  import UFormulaBar from './formula-bar.vue'
88
121
  import { pickAndImportFile } from './import-file'
122
+ import type {
123
+ HyperlinkConfirmPayload,
124
+ HyperlinkImageTarget,
125
+ HyperlinkPopupMode,
126
+ ImagePreviewSource
127
+ } from './popup-helpers'
89
128
  import USheetBorderPopup from './popups/border-popup.vue'
90
129
  import USheetExportPopup from './popups/export-popup.vue'
91
130
  import USheetFillColorPopup from './popups/fill-color-popup.vue'
@@ -93,9 +132,11 @@ import USheetFindPopup from './popups/find-popup.vue'
93
132
  import USheetFontColorPopup from './popups/font-color-popup.vue'
94
133
  import USheetFontSizePopup from './popups/font-size-popup.vue'
95
134
  import USheetFunctionsPopup from './popups/functions-popup.vue'
135
+ import USheetHyperlinkPopup from './popups/hyperlink-popup.vue'
96
136
  import USheetInsertImagePopup from './popups/insert-image-popup.vue'
97
137
  import USheetTabs from './sheet-tabs.vue'
98
138
  import USheetToolbar from './sheet-toolbar.vue'
139
+ import { useCellLinkTooltip } from './use-cell-link-tooltip'
99
140
  import { useSheetGrid } from './use-sheet-grid'
100
141
  import { useSheetState } from './use-sheet-state'
101
142
  import { useToolGroups } from './use-tool-groups'
@@ -213,6 +254,95 @@ function handlePopupVisible(visible: boolean): void {
213
254
 
214
255
  const toolGroups = useToolGroups(context, stateTick)
215
256
 
257
+ // ─── 单元格超链接 / 图片 UI(右键菜单 → 配置弹窗 → 写入;悬停 tooltip;lightbox)──
258
+
259
+ /** 超链接配置弹层状态(右键菜单拉起):mode + 编辑回填 + 写入目标(cell 格 / image 浮动图或嵌入图) */
260
+ const hyperlinkPopup = shallowRef<{
261
+ mode: HyperlinkPopupMode
262
+ initial?: CellLinkPayload
263
+ addr?: CellAddress
264
+ imageTarget?: HyperlinkImageTarget
265
+ } | null>(null)
266
+
267
+ /** 悬停 tooltip 状态机(引擎 cell link hover/leave 事件驱动,层坐标换算见 use-cell-link-tooltip) */
268
+ const {
269
+ tooltip: cellLinkTooltip,
270
+ onCellLinkHover: showCellLinkTooltip,
271
+ onCellLinkLeave: hideCellLinkTooltip
272
+ } = useCellLinkTooltip()
273
+
274
+ /** 右键菜单超链接项句柄:记录写入目标并拉起弹窗(编辑回填原 url/text) */
275
+ function openHyperlinkPopup(
276
+ mode: HyperlinkPopupMode,
277
+ initial?: CellLinkPayload,
278
+ imageTarget?: HyperlinkImageTarget
279
+ ): void {
280
+ hyperlinkPopup.value = {
281
+ mode,
282
+ initial,
283
+ addr: mode === 'cell' ? (context.getSelection().activeCell ?? undefined) : undefined,
284
+ imageTarget: mode === 'image' ? imageTarget : undefined
285
+ }
286
+ }
287
+
288
+ /**
289
+ * 弹窗确认:关弹层并写目标链接,一次写入 = 一个 undo 单元。
290
+ * cell:setCellLink(显示文本留空不写入 text → 单元格沿用自身内容显示);
291
+ * 浮动图:updateImage(link 字段);嵌入图:insertCellImage 覆盖写(其余载荷保留)。
292
+ */
293
+ function handleHyperlinkConfirm(payload: HyperlinkConfirmPayload): void {
294
+ const current = hyperlinkPopup.value
295
+ hyperlinkPopup.value = null
296
+ if (current?.mode === 'cell') {
297
+ if (current.addr) context.setCellLink(current.addr, payload)
298
+ return
299
+ }
300
+ const target = current?.imageTarget
301
+ if (target?.kind === 'float') {
302
+ context.updateImage(target.id, { link: payload.url })
303
+ return
304
+ }
305
+ if (target?.kind === 'cell') {
306
+ const existing = context.getCellImage(target.addr)
307
+ if (existing) context.insertCellImage(target.addr, { ...existing, link: payload.url })
308
+ }
309
+ }
310
+
311
+ /** lightbox 预览状态(右键「预览」拉起):URL 或字节 + MIME;关闭置 null 卸载(objectURL 由 UImagePreviewer 回收) */
312
+ const imagePreview = shallowRef<ImagePreviewSource | null>(null)
313
+
314
+ /** 右键「预览」句柄:浮动图 / 嵌入图菜单共用 */
315
+ function openImagePreview(source: ImagePreviewSource): void {
316
+ imagePreview.value = source
317
+ }
318
+
319
+ // ─── 链接打开(引擎 openCellLinkOnClick=false,打开行为由组件接管)────────
320
+
321
+ /** 新标签打开外链(对齐引擎默认打开语义:noopener) */
322
+ function openExternal(url: string): void {
323
+ window.open(url, '_blank', 'noopener,noreferrer')
324
+ }
325
+
326
+ /** 链接格单击:emit 后直开(保持引擎原默认行为) */
327
+ function handleCellLinkClick(event: CellLinkClickEvent): void {
328
+ emit('cell-link-click', event)
329
+ openExternal(event.url)
330
+ }
331
+
332
+ /** 图片链接单击(浮动图/嵌入图):emit 后确认再开——点击即跳转易误触 */
333
+ function handleImageLinkClick(event: ImageLinkClickEvent): void {
334
+ emit('image-link-click', event)
335
+ messageConfirm({
336
+ title: '打开图片链接',
337
+ message: `即将打开图片链接:${event.url}`,
338
+ confirmButtonText: '打开',
339
+ cancelButtonText: '取消',
340
+ onClose: (action) => {
341
+ if (action === 'confirm') openExternal(event.url)
342
+ }
343
+ })
344
+ }
345
+
216
346
  // ─── grid 生命周期(重建 / 右键菜单 / 公式栏编辑镜像)────────────────
217
347
 
218
348
  const gridRef = useTemplateRef<HTMLElement>('gridRef')
@@ -226,7 +356,23 @@ const { rebuildGrid, activateGrid, pruneCache, getGrid, setSelectionAnchor } = u
226
356
  formulaBarRef,
227
357
  // 工具栏「函数」弹框打开期间与 fx 入口一致:画布点击不清除目标格高亮
228
358
  isFunctionPopupOpen: () => popupTool.value?.popup === 'functions',
229
- onColResizeEnd: (event) => emit('col-resize-end', event)
359
+ onColResizeEnd: (event) => emit('col-resize-end', event),
360
+ // 引擎链接 / 浮动图事件透传(openCellLinkOnClick=false:链接格直开、图片链接确认后开);
361
+ // hover/leave 同时喂给 tooltip 状态机(与组件 emit 同源)
362
+ onCellLinkHover: (event) => {
363
+ emit('cell-link-hover', event)
364
+ showCellLinkTooltip(event)
365
+ },
366
+ onCellLinkLeave: (event) => {
367
+ emit('cell-link-leave', event)
368
+ hideCellLinkTooltip(event)
369
+ },
370
+ onCellLinkClick: (event) => handleCellLinkClick(event),
371
+ onImageLinkClick: (event) => handleImageLinkClick(event),
372
+ onFloatContextMenu: (event) => emit('float-context-menu', event),
373
+ // body 菜单超链接项 → 拉起配置弹窗;右键「预览」→ 打开 lightbox
374
+ openHyperlinkPopup,
375
+ openImagePreview
230
376
  })
231
377
 
232
378
  const exposed: _SheetExposed = {
@@ -724,6 +724,72 @@
724
724
  visibility: hidden;
725
725
  }
726
726
 
727
+ /* 悬停链接格 tooltip:引擎 cell link hover/leave 事件驱动挂载/卸载,
728
+ 层坐标 + 偏移后绝对定位于 grid 区;pointer-events: none 避免浮层
729
+ 自身命中指针触发 leave 抖动(DOM 顺序在画布之后,天然盖在画布上) */
730
+ @include m.e(link-tooltip) {
731
+ position: absolute;
732
+ z-index: 10;
733
+ max-width: 320px;
734
+ padding: 2px 8px;
735
+ border: fn.use-var(border);
736
+ border-radius: fn.use-var(radius, small);
737
+ background-color: fn.use-var(bg-color, top);
738
+ box-shadow: fn.use-var(shadow, sm);
739
+ color: fn.use-var(text-color, main);
740
+ font-size: fn.use-var(font-size-main, small);
741
+ white-space: nowrap;
742
+ overflow: hidden;
743
+ text-overflow: ellipsis;
744
+ pointer-events: none;
745
+ }
746
+
747
+ /* ── 超链接配置弹窗(右键菜单拉起,无工具栏锚点:自绘遮罩 + 居中面板,
748
+ 对齐 loading-mask 自绘先例;遮罩半透明黑与 desktop dialog overlay 同口径) ── */
749
+
750
+ @include m.e(link-dialog-mask) {
751
+ position: fixed;
752
+ inset: 0;
753
+ display: flex;
754
+ align-items: center;
755
+ justify-content: center;
756
+ background-color: rgba($color: #000000, $alpha: 0.32);
757
+ }
758
+
759
+ @include m.e(link-dialog) {
760
+ display: flex;
761
+ flex-direction: column;
762
+ gap: fn.use-var(gap, small);
763
+ width: min(380px, 90vw);
764
+ padding: fn.use-var(gap, default);
765
+ border-radius: fn.use-var(radius, large);
766
+ background-color: fn.use-var(bg-color, top);
767
+ box-shadow: fn.use-var(shadow, lg);
768
+ }
769
+
770
+ @include m.e(link-dialog-title) {
771
+ color: fn.use-var(text-color, main);
772
+ font-size: fn.use-var(font-size-title, default);
773
+ font-weight: 600;
774
+ }
775
+
776
+ @include m.e(link-dialog-body) {
777
+ display: flex;
778
+ flex-direction: column;
779
+ gap: fn.use-var(gap, small);
780
+ }
781
+
782
+ @include m.e(link-dialog-input) {
783
+ flex: 1;
784
+ min-width: 0;
785
+ }
786
+
787
+ @include m.e(link-dialog-footer) {
788
+ display: flex;
789
+ justify-content: flex-end;
790
+ gap: fn.use-var(gap, small);
791
+ }
792
+
727
793
  @include m.e(tabs) {
728
794
  display: flex;
729
795
  align-items: center;
@@ -6,7 +6,9 @@ import '@veltra/desktop/components/palette/style'
6
6
  import '@veltra/desktop/components/scroll/style'
7
7
  import '@veltra/desktop/components/tip/style'
8
8
  import '@veltra/desktop/components/loading/style' // v-loading(sheet.vue grid 容器)
9
- import '@veltra/desktop/components/message/style' // message / messageConfirm(弹层、tabs、公式栏)
9
+ import '@veltra/desktop/components/message/style' // message(弹层、tabs、公式栏)
10
+ import '@veltra/desktop/components/message-confirm/style' // messageConfirm(导入替换 / 图片链接打开确认)
11
+ import '@veltra/desktop/components/image-previewer/style' // UImagePreviewer(右键「预览」lightbox)
10
12
  import '@veltra/desktop/components/input/style' // UInput(find-popup / insert-image-popup)
11
13
  import '@veltra/desktop/components/file-picker/style' // UFilePicker(insert-image-popup)
12
14
  import '@veltra/desktop/components/button/style' // UButton(insert-image-popup URL 插入)
@@ -0,0 +1,42 @@
1
+ import type { CellLinkHoverEvent } from 'infinitable'
2
+ import { shallowRef } from 'vue'
3
+
4
+ /**
5
+ * tooltip 相对悬停落点的偏移:右下错开,浮层不遮指针与命中的链接文本。
6
+ */
7
+ const TOOLTIP_OFFSET_X = 8
8
+ const TOOLTIP_OFFSET_Y = 20
9
+
10
+ /** 悬停链接格 tooltip 的视图状态(url + 相对 grid 区的绝对定位坐标) */
11
+ export interface CellLinkTooltipState {
12
+ /** 展示的链接 URL */
13
+ url: string
14
+ /** 浮层左边(层坐标 + 偏移,单位 px;grid 区内绝对定位) */
15
+ left: number
16
+ /** 浮层顶边(层坐标 + 偏移,单位 px) */
17
+ top: number
18
+ }
19
+
20
+ /**
21
+ * 单元格超链接悬停 tooltip(引擎 hover/leave 事件驱动):
22
+ * hover 时记录命中的层坐标 + URL(层坐标相对 grid 实例容器 = grid 区原点,
23
+ * 渲染层直接在 grid 区内绝对定位挂载浮层);leave 时卸载(置 null)。
24
+ * 事件源接线在 use-sheet-grid(与 cell-link-hover/leave 组件 emit 同源)。
25
+ */
26
+ export function useCellLinkTooltip() {
27
+ const tooltip = shallowRef<CellLinkTooltipState | null>(null)
28
+
29
+ function onCellLinkHover(event: CellLinkHoverEvent): void {
30
+ tooltip.value = {
31
+ url: event.url,
32
+ left: event.x + TOOLTIP_OFFSET_X,
33
+ top: event.y + TOOLTIP_OFFSET_Y
34
+ }
35
+ }
36
+
37
+ function onCellLinkLeave(): void {
38
+ tooltip.value = null
39
+ }
40
+
41
+ return { tooltip, onCellLinkHover, onCellLinkLeave }
42
+ }
@@ -1,13 +1,21 @@
1
1
  import { contextmenu } from '@veltra/desktop'
2
2
  import { currentTheme } from '@veltra/styles/theme'
3
- import type { ThemeOverride } from 'infinitable'
3
+ import type {
4
+ CellLinkClickEvent,
5
+ CellLinkHoverEvent,
6
+ CellLinkLeaveEvent,
7
+ ImageLinkClickEvent,
8
+ ThemeOverride
9
+ } from 'infinitable'
4
10
  import type { CellAddress, CellRange } from 'infinitable/sheet'
5
11
  import type { Sheet } from 'infinitable/sheet'
6
12
  import { SheetGrid, type SheetGridContextMenuInfo } from 'infinitable/sheet'
7
13
  import { onBeforeUnmount, onMounted, watch } from 'vue'
8
14
 
9
15
  import type { SheetContext } from '../../tools/context'
10
- import type { SheetProps } from '../../types'
16
+ import type { FloatContextMenuPayload, SheetProps } from '../../types'
17
+ import { popFloatImageMenu } from './float-image-menu'
18
+ import type { ImagePreviewSource, OpenHyperlinkPopup } from './popup-helpers'
11
19
  import {
12
20
  buildBodyMenus,
13
21
  buildColHeaderMenus,
@@ -43,6 +51,20 @@ interface UseSheetGridOptions {
43
51
  isFunctionPopupOpen?: () => boolean
44
52
  /** 列宽拖拽落定(SheetGrid 透传 → 宿主 emit col-resize-end) */
45
53
  onColResizeEnd?: (event: { col: number; width: number }) => void
54
+ /** 单元格超链接悬停(引擎透传 → 宿主 emit cell-link-hover) */
55
+ onCellLinkHover?: (event: CellLinkHoverEvent) => void
56
+ /** 单元格超链接离开(引擎透传 → 宿主 emit cell-link-leave) */
57
+ onCellLinkLeave?: (event: CellLinkLeaveEvent) => void
58
+ /** 单元格超链接单击(引擎透传 → 宿主 emit cell-link-click;打开由 sheet.vue 直开接管) */
59
+ onCellLinkClick?: (event: CellLinkClickEvent) => void
60
+ /** 图片链接单击(引擎透传 → 宿主 emit image-link-click;打开由 sheet.vue 确认后接管) */
61
+ onImageLinkClick?: (event: ImageLinkClickEvent) => void
62
+ /** 浮动图右键(引擎透传 → 宿主 emit float-context-menu;右键不穿透到 body 菜单) */
63
+ onFloatContextMenu?: (event: FloatContextMenuPayload) => void
64
+ /** body 菜单超链接项拉起配置弹窗的句柄(sheet.vue 挂载的弹层状态) */
65
+ openHyperlinkPopup?: OpenHyperlinkPopup
66
+ /** 右键「预览」打开 lightbox 的句柄(sheet.vue 挂载的 UImagePreviewer 状态) */
67
+ openImagePreview?: (source: ImagePreviewSource) => void
46
68
  }
47
69
 
48
70
  /** 缓存实例(LRU 淘汰):每个 sheet 一个独立容器 div,非激活容器 visibility:hidden 堆叠 */
@@ -119,7 +141,11 @@ export function useSheetGrid(options: UseSheetGridOptions) {
119
141
  ? buildRowHeaderMenus(context, { readonly: props.readonly, row: info.row })
120
142
  : info.kind === 'col-header'
121
143
  ? buildColHeaderMenus(context, { readonly: props.readonly, col: info.col })
122
- : buildBodyMenus(context)
144
+ : buildBodyMenus(context, {
145
+ readonly: props.readonly,
146
+ openHyperlinkPopup: options.openHyperlinkPopup,
147
+ openImagePreview: options.openImagePreview
148
+ })
123
149
 
124
150
  // 最小宽度兜底;实际宽度由最长菜单项撑开(勿固定 240 导致空白过大)
125
151
  contextmenu.pop({ mousePosition: { x: info.x, y: info.y }, width: 'max-content', menus })
@@ -166,6 +192,8 @@ export function useSheetGrid(options: UseSheetGridOptions) {
166
192
  // 画布跟随 UI 主题:loadTheme 注入的 CSS 变量换算为引擎 override
167
193
  //(未 loadTheme 时为 undefined,引擎保持缺省白底)
168
194
  theme: resolveCanvasThemeOverride(host),
195
+ // 关闭引擎默认打开:链接格单击直开、图片链接单击确认后开(sheet.vue 接管)
196
+ openCellLinkOnClick: false,
169
197
  onContextMenu: handleContextMenu,
170
198
  onEditStart: (addr) => formulaBarRef.value?.mirrorGridEdit(addr),
171
199
  onEditEnd: (addr) => formulaBarRef.value?.exitMirror(addr),
@@ -183,8 +211,39 @@ export function useSheetGrid(options: UseSheetGridOptions) {
183
211
  const offStructureChange = sheet.on('structure-change', () => {
184
212
  dirty = true
185
213
  })
214
+ // 引擎链接 / 浮动图事件透传:与 structure-change 订阅同生命周期,release 时解绑
215
+ //(LRU 多实例各持各的订阅,淘汰 / 重建不残留)
216
+ const table = grid.getTable()
217
+ const offEngineEvents = [
218
+ table.onCellLinkHover((event) => options.onCellLinkHover?.(event)),
219
+ table.onCellLinkLeave((event) => options.onCellLinkLeave?.(event)),
220
+ table.onCellLinkClick((event) => options.onCellLinkClick?.(event)),
221
+ table.onImageLinkClick((event) => options.onImageLinkClick?.(event)),
222
+ table.floatObjects.onContextMenu((event) => {
223
+ // 层坐标 → 页面视口坐标(层坐标 + grid 容器偏移,与 body 右键菜单同口径)
224
+ const rect = el.getBoundingClientRect()
225
+ const payload: FloatContextMenuPayload = {
226
+ ...event,
227
+ clientX: rect.left + event.x,
228
+ clientY: rect.top + event.y
229
+ }
230
+ options.onFloatContextMenu?.(payload)
231
+ // 产品侧浮动图独立菜单(预览 / 超链接 / 删除);与宿主 emit 并存,
232
+ // 不穿透到格菜单由引擎保证(floatObjects 命中即不派发单元格右键)
233
+ popFloatImageMenu({
234
+ ctx: context,
235
+ event: payload,
236
+ handles: {
237
+ openImagePreview: options.openImagePreview,
238
+ openHyperlinkPopup: options.openHyperlinkPopup
239
+ },
240
+ readonly: props.readonly
241
+ })
242
+ })
243
+ ]
186
244
  const release = (): void => {
187
245
  offStructureChange()
246
+ for (const off of offEngineEvents) off()
188
247
  grid.release()
189
248
  el.remove()
190
249
  }
@@ -1,4 +1,4 @@
1
- import type { Sheet } from 'infinitable/sheet'
1
+ import type { CellAddress, Sheet } from 'infinitable/sheet'
2
2
  import { Workbook } from 'infinitable/sheet'
3
3
  import { computed, onBeforeUnmount, onMounted, ref, shallowRef, watch } from 'vue'
4
4
 
@@ -25,7 +25,10 @@ export interface SheetStateHooks {
25
25
  syncAxisSizes: (axis: 'row' | 'col', indexes: number[]) => void
26
26
  }
27
27
 
28
- type Emit = (event: 'active-sheet-change', payload: { sheet: Sheet; index: number }) => void
28
+ type Emit = {
29
+ (event: 'active-sheet-change', payload: { sheet: Sheet; index: number }): void
30
+ (event: 'cell-image-change', payload: { addr?: CellAddress }): void
31
+ }
29
32
 
30
33
  /**
31
34
  * USheet 的状态源(单一数据源,其余状态由此推导):
@@ -86,6 +89,9 @@ export function useSheetState(props: SheetProps, emit: Emit, hooks: SheetStateHo
86
89
  sheet.on('cell-change', bump),
87
90
  sheet.on('merge-change', bump),
88
91
  sheet.on('frozen-change', bump),
92
+ // 按格嵌入图变化 → 宿主 emit cell-image-change(随活动 sheet 重绑,
93
+ // 非活动 sheet 的嵌入图变更不透传)
94
+ sheet.on('cell-image-change', (payload) => emit('cell-image-change', payload)),
89
95
  // 整表内容替换(导入 / undo/redo 回放):restore 静默不发 cell-change,
90
96
  // 状态源需 bump(grid 层自行订阅 content-reset 全量刷新,此处不重建)
91
97
  sheet.on('content-reset', scheduleBump),