@veltra/sheet 4.1.1 → 4.1.3

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 (34) hide show
  1. package/dist/components/sheet/formula-bar.js +95 -11
  2. package/dist/components/sheet/sheet.js +5 -3
  3. package/dist/components/sheet/use-formula-ref-select.js +11 -3
  4. package/dist/components/sheet/use-sheet-grid.js +11 -3
  5. package/dist/components/sheet/use-sheet-state.js +1 -1
  6. package/dist/index.js +1 -2
  7. package/dist/tools/builtin.js +307 -305
  8. package/dist/tools/registry.d.ts +3 -1
  9. package/dist/tools/registry.js +7 -2
  10. package/package.json +4 -8
  11. package/src/components/sheet/__test__/canvas-mock.ts +3 -1
  12. package/src/components/sheet/__test__/find-shortcut-anchor.test.ts +2 -0
  13. package/src/components/sheet/__test__/formula-bar.test.ts +205 -0
  14. package/src/components/sheet/__test__/formula-capability.test.ts +2 -0
  15. package/src/components/sheet/__test__/functions-popup.test.ts +2 -0
  16. package/src/components/sheet/__test__/hyperlink-popup.test.ts +2 -0
  17. package/src/components/sheet/__test__/import-file.test.ts +2 -0
  18. package/src/components/sheet/__test__/insert-count-menu-item.test.ts +2 -0
  19. package/src/components/sheet/__test__/insert-image-popup.test.ts +2 -0
  20. package/src/components/sheet/__test__/insert-image.test.ts +2 -0
  21. package/src/components/sheet/__test__/sheet-component.test.ts +4 -1
  22. package/src/components/sheet/__test__/sheet-grow-on-scroll.test.ts +2 -0
  23. package/src/components/sheet/__test__/sheet-scrollbar.test.ts +2 -0
  24. package/src/components/sheet/__test__/sheet-theme.test.ts +2 -0
  25. package/src/components/sheet/__test__/use-formula-ref-select.test.ts +12 -1
  26. package/src/components/sheet/formula-bar.vue +106 -14
  27. package/src/components/sheet/sheet.vue +28 -26
  28. package/src/components/sheet/use-formula-ref-select.ts +13 -0
  29. package/src/components/sheet/use-sheet-grid.ts +26 -7
  30. package/src/index.ts +1 -3
  31. package/src/tools/__test__/builtin.test.ts +2 -2
  32. package/src/tools/builtin.ts +345 -344
  33. package/src/tools/registry.ts +8 -2
  34. package/src/tools/index.ts +0 -3
@@ -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')">
@@ -348,32 +349,33 @@ function handleImageLinkClick(event: ImageLinkClickEvent): void {
348
349
  const gridRef = useTemplateRef<HTMLElement>('gridRef')
349
350
  const formulaBarRef = useTemplateRef<InstanceType<typeof UFormulaBar>>('formulaBarRef')
350
351
 
351
- const { rebuildGrid, activateGrid, pruneCache, getGrid, setSelectionAnchor } = useSheetGrid({
352
- props,
353
- gridRef,
354
- getActiveSheet: () => activeSheet.value,
355
- context,
356
- formulaBarRef,
357
- // 工具栏「函数」弹框打开期间与 fx 入口一致:画布点击不清除目标格高亮
358
- isFunctionPopupOpen: () => popupTool.value?.popup === 'functions',
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
376
- })
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
+ })
377
379
 
378
380
  const exposed: _SheetExposed = {
379
381
  workbook,
@@ -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
 
@@ -198,10 +201,13 @@ export function useSheetGrid(options: UseSheetGridOptions) {
198
201
  onEditStart: (addr) => formulaBarRef.value?.mirrorGridEdit(addr),
199
202
  onEditEnd: (addr) => formulaBarRef.value?.exitMirror(addr),
200
203
  onColResizeEnd: options.onColResizeEnd,
201
- // 引用选择:不回写模型选区,序列化为 A1 / A1:B2 交给公式栏;
202
- // 函数弹框打开期间(fx / 工具栏两入口)同样拦截,画布点击不离开目标格
204
+ // 引用选择:不回写模型选区,序列化为 A1 / A1:B2 交给公式栏;函数弹框打开期间
205
+ // (fx / 工具栏两入口)同样拦截,画布点击不离开目标格;拾取会话延续中(上次插入
206
+ // 的引用未被打断)任何点击都拦截——Excel Point mode:普通点选替换上次引用、
207
+ // shift 点选以上次锚点扩展,编辑不中断
203
208
  interceptSelection: () =>
204
209
  (formulaBarRef.value?.isRefSelecting() ?? false) ||
210
+ (formulaBarRef.value?.hasRefInsert() ?? false) ||
205
211
  (formulaBarRef.value?.isFunctionPopupOpen() ?? false) ||
206
212
  (options.isFunctionPopupOpen?.() ?? false),
207
213
  onSelectionIntercept: (range) => formulaBarRef.value?.handleRefSelect(range)
@@ -305,10 +311,11 @@ export function useSheetGrid(options: UseSheetGridOptions) {
305
311
  const sheet = getActiveSheet()
306
312
  const host = gridRef.value
307
313
  if (!host) return
308
- // 换实例前清旧实例的选区锚点:fx 编辑会话随切 sheet 结束(公式栏同步复位
309
- // 编辑态),缓存实例复用时不得残留上次会话的高亮
314
+ // 换实例前清旧实例的编辑会话视图态(选区锚点 + 引用染色框):fx 编辑会话随切
315
+ // sheet 结束(公式栏同步复位编辑态),缓存实例复用时不得残留上次会话的高亮
310
316
  if (active && active.sheet !== sheet) {
311
317
  active.grid.setSelectionAnchor(null)
318
+ active.grid.setHighlightRanges([])
312
319
  }
313
320
  const cached = cache.get(sheet)
314
321
  if (cached && !cached.dirty) {
@@ -405,5 +412,17 @@ export function useSheetGrid(options: UseSheetGridOptions) {
405
412
  active?.grid.setSelectionAnchor(addr)
406
413
  }
407
414
 
408
- 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
+ }
409
428
  }
package/src/index.ts CHANGED
@@ -1,5 +1,3 @@
1
- import './tools/builtin'
2
-
3
1
  // SheetContextOptions:createSheetContext(公共导出)的第三参类型——导出函数
4
2
  // 签名引用的稳定类型须随函数可达(无头场景宿主需引用该类型),不属引擎符号
5
3
  export { createSheetContext, type SheetContext, type SheetContextOptions } from './tools/context'
@@ -13,6 +11,6 @@ export {
13
11
  type SheetToolGroup
14
12
  } from './tools/registry'
15
13
 
16
- export { type SheetProps, type SheetEmits, type SheetExposed } from './types'
14
+ export type { SheetProps, SheetEmits, SheetExposed } from './types'
17
15
 
18
16
  export { USheet } from './components/sheet'
@@ -1,6 +1,6 @@
1
- import { createRange } from 'infinitable/sheet'
1
+ // @vitest-environment happy-dom
2
2
 
3
- import '../builtin'
3
+ import { createRange } from 'infinitable/sheet'
4
4
  import { Sheet } from 'infinitable/sheet'
5
5
  import { Workbook } from 'infinitable/sheet'
6
6
  import { describe, expect, it, vi } from 'vite-plus/test'