@veltra/sheet 4.1.0 → 4.1.2

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.
@@ -57,6 +57,7 @@
57
57
  :sheet="activeSheet"
58
58
  :context="context"
59
59
  :set-selection-anchor="setSelectionAnchor"
60
+ :set-ref-highlights="setRefHighlights"
60
61
  />
61
62
 
62
63
  <div ref="gridRef" :class="cls.e('grid')">
@@ -105,9 +106,14 @@
105
106
  </template>
106
107
 
107
108
  <script lang="ts" setup>
108
- import { UDropdown, UImagePreviewer } from '@veltra/desktop'
109
+ import { UDropdown, UImagePreviewer, messageConfirm } from '@veltra/desktop'
109
110
  import { bem } from '@veltra/utils'
110
- import type { CellAddress, CellLinkPayload } from 'infinitable/sheet'
111
+ import type {
112
+ CellAddress,
113
+ CellLinkClickEvent,
114
+ CellLinkPayload,
115
+ ImageLinkClickEvent
116
+ } from 'infinitable/sheet'
111
117
  import { computed, ref, shallowRef, useTemplateRef, watch } from 'vue'
112
118
 
113
119
  import type { SheetTool } from '../../tools/registry'
@@ -311,37 +317,65 @@ function openImagePreview(source: ImagePreviewSource): void {
311
317
  imagePreview.value = source
312
318
  }
313
319
 
320
+ // ─── 链接打开(引擎 openCellLinkOnClick=false,打开行为由组件接管)────────
321
+
322
+ /** 新标签打开外链(对齐引擎默认打开语义:noopener) */
323
+ function openExternal(url: string): void {
324
+ window.open(url, '_blank', 'noopener,noreferrer')
325
+ }
326
+
327
+ /** 链接格单击:emit 后直开(保持引擎原默认行为) */
328
+ function handleCellLinkClick(event: CellLinkClickEvent): void {
329
+ emit('cell-link-click', event)
330
+ openExternal(event.url)
331
+ }
332
+
333
+ /** 图片链接单击(浮动图/嵌入图):emit 后确认再开——点击即跳转易误触 */
334
+ function handleImageLinkClick(event: ImageLinkClickEvent): void {
335
+ emit('image-link-click', event)
336
+ messageConfirm({
337
+ title: '打开图片链接',
338
+ message: `即将打开图片链接:${event.url}`,
339
+ confirmButtonText: '打开',
340
+ cancelButtonText: '取消',
341
+ onClose: (action) => {
342
+ if (action === 'confirm') openExternal(event.url)
343
+ }
344
+ })
345
+ }
346
+
314
347
  // ─── grid 生命周期(重建 / 右键菜单 / 公式栏编辑镜像)────────────────
315
348
 
316
349
  const gridRef = useTemplateRef<HTMLElement>('gridRef')
317
350
  const formulaBarRef = useTemplateRef<InstanceType<typeof UFormulaBar>>('formulaBarRef')
318
351
 
319
- const { rebuildGrid, activateGrid, pruneCache, getGrid, setSelectionAnchor } = useSheetGrid({
320
- props,
321
- gridRef,
322
- getActiveSheet: () => activeSheet.value,
323
- context,
324
- formulaBarRef,
325
- // 工具栏「函数」弹框打开期间与 fx 入口一致:画布点击不清除目标格高亮
326
- isFunctionPopupOpen: () => popupTool.value?.popup === 'functions',
327
- onColResizeEnd: (event) => emit('col-resize-end', event),
328
- // 引擎链接 / 浮动图事件透传(打开行为仍归引擎 openCellLinkOnClick 默认);
329
- // hover/leave 同时喂给 tooltip 状态机(与组件 emit 同源)
330
- onCellLinkHover: (event) => {
331
- emit('cell-link-hover', event)
332
- showCellLinkTooltip(event)
333
- },
334
- onCellLinkLeave: (event) => {
335
- emit('cell-link-leave', event)
336
- hideCellLinkTooltip(event)
337
- },
338
- onCellLinkClick: (event) => emit('cell-link-click', event),
339
- onImageLinkClick: (event) => emit('image-link-click', event),
340
- onFloatContextMenu: (event) => emit('float-context-menu', event),
341
- // body 菜单超链接项 → 拉起配置弹窗;右键「预览」→ 打开 lightbox
342
- openHyperlinkPopup,
343
- openImagePreview
344
- })
352
+ const { rebuildGrid, activateGrid, pruneCache, getGrid, setSelectionAnchor, setRefHighlights } =
353
+ useSheetGrid({
354
+ props,
355
+ gridRef,
356
+ getActiveSheet: () => activeSheet.value,
357
+ context,
358
+ formulaBarRef,
359
+ // 工具栏「函数」弹框打开期间与 fx 入口一致:画布点击不清除目标格高亮
360
+ isFunctionPopupOpen: () => popupTool.value?.popup === 'functions',
361
+ onColResizeEnd: (event) => emit('col-resize-end', event),
362
+ // 引擎链接 / 浮动图事件透传(openCellLinkOnClick=false:链接格直开、图片链接确认后开);
363
+ // hover/leave 同时喂给 tooltip 状态机(与组件 emit 同源)
364
+ onCellLinkHover: (event) => {
365
+ emit('cell-link-hover', event)
366
+ showCellLinkTooltip(event)
367
+ },
368
+ onCellLinkLeave: (event) => {
369
+ emit('cell-link-leave', event)
370
+ hideCellLinkTooltip(event)
371
+ },
372
+ onCellLinkClick: (event) => handleCellLinkClick(event),
373
+ onImageLinkClick: (event) => handleImageLinkClick(event),
374
+ onFloatContextMenu: (event) => emit('float-context-menu', event),
375
+ // body 菜单超链接项 → 拉起配置弹窗;右键「预览」→ 打开 lightbox
376
+ openHyperlinkPopup,
377
+ openImagePreview
378
+ })
345
379
 
346
380
  const exposed: _SheetExposed = {
347
381
  workbook,
@@ -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 插入)
@@ -1,6 +1,9 @@
1
1
  /** 引用选择上下文:光标前一个非空字符属于此集合时可插入单元格引用 */
2
2
  const REF_TRIGGER_CHARS = new Set(['=', '(', ',', '+', '-', '*', '/', '^', '&', '<', '>'])
3
3
 
4
+ /** 引用拾取染色框循环色板(对齐 Excel 蓝/绿/红循环惯例),按引用在公式中的出现顺序取色 */
5
+ export const REF_HIGHLIGHT_COLORS = ['#2563eb', '#16a34a', '#dc2626'] as const
6
+
4
7
  /**
5
8
  * 判定是否处于「可插入引用」位置(无状态:每次按文本 + 光标重算)。
6
9
  * `-` 的一元/二元歧义基础版不区分(`A1-` 后框选 → `A1-B2`,合法且误判无害)。
@@ -29,6 +32,16 @@ export function insertRefText(
29
32
  ): InsertRefResult {
30
33
  const start = Math.min(cursor, selectionEnd)
31
34
  const end = Math.max(cursor, selectionEnd)
35
+ return replaceRefText(text, start, end, rangeText)
36
+ }
37
+
38
+ /** 替换 [start, end) 区间为引用文本(shift+点选扩展:扩展上次插入的引用) */
39
+ export function replaceRefText(
40
+ text: string,
41
+ start: number,
42
+ end: number,
43
+ rangeText: string
44
+ ): InsertRefResult {
32
45
  const next = text.slice(0, start) + rangeText + text.slice(end)
33
46
  return { text: next, cursor: start + rangeText.length }
34
47
  }
@@ -10,6 +10,7 @@ import type {
10
10
  import type { CellAddress, CellRange } from 'infinitable/sheet'
11
11
  import type { Sheet } from 'infinitable/sheet'
12
12
  import { SheetGrid, type SheetGridContextMenuInfo } from 'infinitable/sheet'
13
+ import type { SheetGridHighlight } from 'infinitable/sheet'
13
14
  import { onBeforeUnmount, onMounted, watch } from 'vue'
14
15
 
15
16
  import type { SheetContext } from '../../tools/context'
@@ -33,11 +34,13 @@ export interface FormulaBarMirror {
33
34
  exitMirror: (addr: CellAddress) => void
34
35
  /** fx 编辑中且处于可插入引用位置 */
35
36
  isRefSelecting: () => boolean
37
+ /** 引用拾取延续中(上次插入的引用可被点选替换/扩展) */
38
+ hasRefInsert: () => boolean
36
39
  /** 函数弹框打开中(fx 入口)——画布点击不清除目标格高亮 */
37
40
  isFunctionPopupOpen: () => boolean
38
- /** 网格 pointerdown → 挂起 blur 提交 */
41
+ /** 网格 pointerdown → 挂起 blur 提交(引用选择或拾取会话延续中) */
39
42
  beginBlurSuppress: () => void
40
- /** 画布选区 → 插入引用文本 */
43
+ /** 画布选区 → 插入/替换引用文本(拾取会话延续中替换上次插入的引用) */
41
44
  handleRefSelect: (range: CellRange) => void
42
45
  }
43
46
 
@@ -55,9 +58,9 @@ interface UseSheetGridOptions {
55
58
  onCellLinkHover?: (event: CellLinkHoverEvent) => void
56
59
  /** 单元格超链接离开(引擎透传 → 宿主 emit cell-link-leave) */
57
60
  onCellLinkLeave?: (event: CellLinkLeaveEvent) => void
58
- /** 单元格超链接单击(引擎透传 → 宿主 emit cell-link-click;打开行为仍归引擎默认) */
61
+ /** 单元格超链接单击(引擎透传 → 宿主 emit cell-link-click;打开由 sheet.vue 直开接管) */
59
62
  onCellLinkClick?: (event: CellLinkClickEvent) => void
60
- /** 图片链接单击(引擎透传 → 宿主 emit image-link-click;kind 区分嵌入/浮动) */
63
+ /** 图片链接单击(引擎透传 → 宿主 emit image-link-click;打开由 sheet.vue 确认后接管) */
61
64
  onImageLinkClick?: (event: ImageLinkClickEvent) => void
62
65
  /** 浮动图右键(引擎透传 → 宿主 emit float-context-menu;右键不穿透到 body 菜单) */
63
66
  onFloatContextMenu?: (event: FloatContextMenuPayload) => void
@@ -192,14 +195,19 @@ export function useSheetGrid(options: UseSheetGridOptions) {
192
195
  // 画布跟随 UI 主题:loadTheme 注入的 CSS 变量换算为引擎 override
193
196
  //(未 loadTheme 时为 undefined,引擎保持缺省白底)
194
197
  theme: resolveCanvasThemeOverride(host),
198
+ // 关闭引擎默认打开:链接格单击直开、图片链接单击确认后开(sheet.vue 接管)
199
+ openCellLinkOnClick: false,
195
200
  onContextMenu: handleContextMenu,
196
201
  onEditStart: (addr) => formulaBarRef.value?.mirrorGridEdit(addr),
197
202
  onEditEnd: (addr) => formulaBarRef.value?.exitMirror(addr),
198
203
  onColResizeEnd: options.onColResizeEnd,
199
- // 引用选择:不回写模型选区,序列化为 A1 / A1:B2 交给公式栏;
200
- // 函数弹框打开期间(fx / 工具栏两入口)同样拦截,画布点击不离开目标格
204
+ // 引用选择:不回写模型选区,序列化为 A1 / A1:B2 交给公式栏;函数弹框打开期间
205
+ // (fx / 工具栏两入口)同样拦截,画布点击不离开目标格;拾取会话延续中(上次插入
206
+ // 的引用未被打断)任何点击都拦截——Excel Point mode:普通点选替换上次引用、
207
+ // shift 点选以上次锚点扩展,编辑不中断
201
208
  interceptSelection: () =>
202
209
  (formulaBarRef.value?.isRefSelecting() ?? false) ||
210
+ (formulaBarRef.value?.hasRefInsert() ?? false) ||
203
211
  (formulaBarRef.value?.isFunctionPopupOpen() ?? false) ||
204
212
  (options.isFunctionPopupOpen?.() ?? false),
205
213
  onSelectionIntercept: (range) => formulaBarRef.value?.handleRefSelect(range)
@@ -303,10 +311,11 @@ export function useSheetGrid(options: UseSheetGridOptions) {
303
311
  const sheet = getActiveSheet()
304
312
  const host = gridRef.value
305
313
  if (!host) return
306
- // 换实例前清旧实例的选区锚点:fx 编辑会话随切 sheet 结束(公式栏同步复位
307
- // 编辑态),缓存实例复用时不得残留上次会话的高亮
314
+ // 换实例前清旧实例的编辑会话视图态(选区锚点 + 引用染色框):fx 编辑会话随切
315
+ // sheet 结束(公式栏同步复位编辑态),缓存实例复用时不得残留上次会话的高亮
308
316
  if (active && active.sheet !== sheet) {
309
317
  active.grid.setSelectionAnchor(null)
318
+ active.grid.setHighlightRanges([])
310
319
  }
311
320
  const cached = cache.get(sheet)
312
321
  if (cached && !cached.dirty) {
@@ -403,5 +412,17 @@ export function useSheetGrid(options: UseSheetGridOptions) {
403
412
  active?.grid.setSelectionAnchor(addr)
404
413
  }
405
414
 
406
- return { rebuildGrid, activateGrid, pruneCache, getGrid: () => active?.grid, setSelectionAnchor }
415
+ /** 公式引用染色框同步(公式栏 → 活动实例透传;空数组清除;无活动实例时静默) */
416
+ function setRefHighlights(items: readonly SheetGridHighlight[]): void {
417
+ active?.grid.setHighlightRanges(items)
418
+ }
419
+
420
+ return {
421
+ rebuildGrid,
422
+ activateGrid,
423
+ pruneCache,
424
+ getGrid: () => active?.grid,
425
+ setSelectionAnchor,
426
+ setRefHighlights
427
+ }
407
428
  }
@@ -118,13 +118,14 @@ export interface SheetEmits {
118
118
  (name: 'cell-link-leave', payload: CellLinkLeaveEvent): void
119
119
  /**
120
120
  * 单元格超链接单击(引擎 `CellLinkClickEvent` 形态:真实指针 down+up 命中
121
- * 同一链接格;框选拖拽/键盘选中不触发)。单击打开仍由引擎
122
- * `openCellLinkOnClick` 默认处理,ultra-ui 不接管
121
+ * 同一链接格;框选拖拽/键盘选中不触发)。组件已接管打开:emit 后直接新标签
122
+ * 打开(引擎 `openCellLinkOnClick` 已关闭)
123
123
  */
124
124
  (name: 'cell-link-click', payload: CellLinkClickEvent): void
125
125
  /**
126
126
  * 图片链接单击(引擎 `ImageLinkClickEvent`,`kind` 区分 `cell` 嵌入图 /
127
- * `float` 浮动图);默认打开行为同上由引擎处理
127
+ * `float` 浮动图)。组件已接管打开:emit 后弹确认框,确认才新标签打开
128
+ * (防误触跳转;引擎 `openCellLinkOnClick` 已关闭)
128
129
  */
129
130
  (name: 'image-link-click', payload: ImageLinkClickEvent): void
130
131
  /**