@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.
@@ -2,10 +2,33 @@ import { imageLinkInitial, imagePreviewSource } from "./popup-helpers.js";
2
2
  import { contextmenu } from "@veltra/desktop";
3
3
  //#region src/components/sheet/float-image-menu.ts
4
4
  /**
5
- * 浮动图右键独立菜单:预览 / 设置超链接 / 取消超链接(无链接不出现)/ 删除图片。
6
- * 设置走 hyperlink 弹窗 image 模式(确认 `updateImage(id, { link })`);取消直写
7
- * `updateImage(id, { link: null })`(null 清除,可 undo);删除走 `removeImage`
8
- * (命令系统,可 undo)。命中 id 不存在(并发删除)返回空数组,调用方不弹菜单。
5
+ * 浮动图转为按格嵌入图(对齐 WPS/Excel「放置在单元格中」):落点为图片锚点格
6
+ * (anchor.from,即图片左上角所在格),src/data/type/link 随载荷迁移。事务内
7
+ * insertCellImage + removeImage——一次转换 = 一个 undo 单元。
8
+ */
9
+ function embedFloatImageToCell(ctx, id) {
10
+ const image = ctx.getImages().find((item) => item.id === id);
11
+ if (!image) return;
12
+ const payload = image.src ? {
13
+ src: image.src,
14
+ type: image.type
15
+ } : {
16
+ data: image.data,
17
+ type: image.type
18
+ };
19
+ if (image.link) payload.link = image.link;
20
+ ctx.beginTransaction();
21
+ ctx.insertCellImage(image.anchor.from, payload);
22
+ ctx.removeImage(id);
23
+ ctx.commit();
24
+ }
25
+ /**
26
+ * 浮动图右键独立菜单:预览 / 设置超链接 / 取消超链接(无链接不出现)/
27
+ * 嵌入单元格 / 删除图片。设置走 hyperlink 弹窗 image 模式(confirm
28
+ * `updateImage(id, { link })`);取消直写 `updateImage(id, { link: null })`
29
+ * (null 清除,可 undo);嵌入单元格走 `embedFloatImageToCell`(事务合并单 undo);
30
+ * 删除走 `removeImage`(命令系统,可 undo)。命中 id 不存在(并发删除)返回空数组,
31
+ * 调用方不弹菜单。
9
32
  */
10
33
  function buildFloatImageMenus(ctx, id, handles, options) {
11
34
  const image = ctx.getImages().find((item) => item.id === id);
@@ -31,6 +54,11 @@ function buildFloatImageMenus(ctx, id, handles, options) {
31
54
  disabled: readonly,
32
55
  callback: () => ctx.updateImage(id, { link: null })
33
56
  }] : [],
57
+ {
58
+ label: "嵌入单元格",
59
+ disabled: readonly,
60
+ callback: () => embedFloatImageToCell(ctx, id)
61
+ },
34
62
  {
35
63
  label: "删除图片",
36
64
  disabled: readonly,
@@ -56,4 +84,4 @@ function popFloatImageMenu(options) {
56
84
  });
57
85
  }
58
86
  //#endregion
59
- export { buildFloatImageMenus, popFloatImageMenu };
87
+ export { buildFloatImageMenus, embedFloatImageToCell, popFloatImageMenu };
@@ -1,11 +1,12 @@
1
1
  import _sfc_main$1 from "./formula-suggest-list.js";
2
2
  import { applySuggest, filterFormulaSuggestions, getSuggestContext, moveSuggestIndex } from "./use-formula-suggest.js";
3
3
  import _sfc_main$2 from "./popups/functions-popup.js";
4
- import { insertRefText, isRefSelectContext } from "./use-formula-ref-select.js";
4
+ import { REF_HIGHLIGHT_COLORS, insertRefText, isRefSelectContext, replaceRefText } from "./use-formula-ref-select.js";
5
5
  import { formatAddress, formatRange, parseRange } from "infinitable/sheet";
6
6
  import { computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, nextTick, normalizeClass, onBeforeUnmount, onMounted, openBlock, ref, shallowRef, unref, useTemplateRef, vModelText, watch, withCtx, withDirectives, withModifiers } from "vue";
7
7
  import { UDropdown, message } from "@veltra/desktop";
8
8
  import { bem } from "@veltra/utils";
9
+ import { scanFormulaReferences } from "infinitable";
9
10
  //#region src/components/sheet/formula-bar.vue
10
11
  const _hoisted_1 = ["disabled"];
11
12
  const _hoisted_2 = ["disabled", "readonly"];
@@ -15,7 +16,8 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
15
16
  props: {
16
17
  sheet: {},
17
18
  context: {},
18
- setSelectionAnchor: { type: Function }
19
+ setSelectionAnchor: { type: Function },
20
+ setRefHighlights: { type: Function }
19
21
  },
20
22
  setup(__props, { expose: __expose }) {
21
23
  /**
@@ -60,28 +62,102 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
60
62
  function isRefSelecting() {
61
63
  return editing.value && !mirroring.value && isRefSelectContext(fxDraft.value, fxCursor.value);
62
64
  }
63
- /** 网格 pointerdown(capture)→ 挂起即将到来的 blur 提交 */
65
+ /** 上次引用插入的文本区间(fxDraft 内 [start, end)):插入引用后光标离开触发位、
66
+ * isRefSelectContext 判定失效,拾取会话延续依赖它维持 blur 抑制与替换/扩展语义 */
67
+ let lastRefInsert = null;
68
+ function clearRefInsert() {
69
+ lastRefInsert = null;
70
+ }
71
+ /** 引用拾取延续中(上次插入的引用可被后续点选替换/扩展,点击画布不退出编辑) */
72
+ function hasRefInsert() {
73
+ return lastRefInsert !== null;
74
+ }
75
+ /** 网格 pointerdown(capture)→ 挂起即将到来的 blur 提交;拾取会话延续中
76
+ * (上次插入的引用未被打断)同样挂起——任意点击都消费为引用替换/扩展 */
64
77
  function beginBlurSuppress() {
65
- if (!isRefSelecting()) return;
78
+ if (!isRefSelecting() && !lastRefInsert) return;
66
79
  suppressBlurCommit = true;
67
80
  }
68
- /** 选区拦截回调:插入 A1 / A1:B2 到光标处(仅引用选择模式;弹框打开但非引用上下文时不插入) */
81
+ /** 选区拦截回调:插入 A1 / A1:B2 到光标处(仅引用选择模式;弹框打开但非引用上下文时不插入)。
82
+ * 拾取会话延续(lastRefInsert 存在):替换上次插入的引用——shift 扩展回交(Excel 锚点
83
+ * 恒定连续扩展)与普通点选(Point mode 换目标)同走此路径,编辑不中断 */
69
84
  function handleRefSelect(range) {
70
- if (!isRefSelecting()) return;
85
+ if (!isRefSelecting() && !lastRefInsert) return;
86
+ if (editAddr && range.start.row === range.end.row && range.start.col === range.end.col && range.start.row === editAddr.row && range.start.col === editAddr.col) return;
71
87
  const rangeText = formatRange(range);
72
- const selEnd = fxRef.value?.selectionEnd ?? fxCursor.value;
73
- const result = insertRefText(fxDraft.value, fxCursor.value, rangeText, selEnd);
74
- fxDraft.value = result.text;
75
- fxCursor.value = result.cursor;
88
+ if (lastRefInsert) {
89
+ const { start } = lastRefInsert;
90
+ const result = replaceRefText(fxDraft.value, start, lastRefInsert.end, rangeText);
91
+ fxDraft.value = result.text;
92
+ fxCursor.value = result.cursor;
93
+ lastRefInsert = {
94
+ start,
95
+ end: result.cursor
96
+ };
97
+ } else {
98
+ const selEnd = fxRef.value?.selectionEnd ?? fxCursor.value;
99
+ const result = insertRefText(fxDraft.value, fxCursor.value, rangeText, selEnd);
100
+ fxDraft.value = result.text;
101
+ fxCursor.value = result.cursor;
102
+ lastRefInsert = {
103
+ start: result.cursor - rangeText.length,
104
+ end: result.cursor
105
+ };
106
+ }
76
107
  closeSuggest();
77
108
  nextTick(() => {
78
109
  const input = fxRef.value;
79
110
  if (!input) return;
80
111
  input.focus();
81
- input.setSelectionRange(result.cursor, result.cursor);
112
+ input.setSelectionRange(fxCursor.value, fxCursor.value);
82
113
  autosizeFx();
83
114
  });
84
115
  }
116
+ /** 公式文本扫描 → 画布染色框:编辑中且 `=` 开头时逐引用上框(颜色按出现顺序循环),
117
+ * 手输/点选/扩展一视同仁(对齐 Excel:编辑公式即染色全部引用);其余状态清除 */
118
+ function syncRefHighlights() {
119
+ if (!editing.value || mirroring.value || !fxDraft.value.startsWith("=")) {
120
+ props.setRefHighlights?.([]);
121
+ return;
122
+ }
123
+ props.setRefHighlights?.(scanFormulaReferences(fxDraft.value).map(refToHighlight));
124
+ }
125
+ /** 扫描结果 → 染色框条目(RangeRef 展开为区域,单格引用同形) */
126
+ function refToHighlight(scanned, index) {
127
+ const color = REF_HIGHLIGHT_COLORS[index % REF_HIGHLIGHT_COLORS.length];
128
+ const ref = scanned.ref;
129
+ if (scanned.isRange) return {
130
+ range: {
131
+ start: {
132
+ row: ref.startRow,
133
+ col: ref.startCol
134
+ },
135
+ end: {
136
+ row: ref.endRow,
137
+ col: ref.endCol
138
+ }
139
+ },
140
+ color
141
+ };
142
+ return {
143
+ range: {
144
+ start: {
145
+ row: ref.row,
146
+ col: ref.col
147
+ },
148
+ end: {
149
+ row: ref.row,
150
+ col: ref.col
151
+ }
152
+ },
153
+ color
154
+ };
155
+ }
156
+ watch([
157
+ fxDraft,
158
+ editing,
159
+ mirroring
160
+ ], syncRefHighlights);
85
161
  function nameText(state) {
86
162
  const range = state.ranges[0];
87
163
  if (range) {
@@ -164,6 +240,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
164
240
  refreshSuggest();
165
241
  }
166
242
  function handleFxInput() {
243
+ clearRefInsert();
167
244
  syncFxCursor();
168
245
  autosizeFx();
169
246
  }
@@ -193,6 +270,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
193
270
  const result = applySuggest(fxDraft.value, ctx.start, ctx.end, pick.name);
194
271
  fxDraft.value = result.text;
195
272
  fxCursor.value = result.cursor;
273
+ clearRefInsert();
196
274
  closeSuggest();
197
275
  nextTick(() => {
198
276
  const el = fxRef.value;
@@ -293,6 +371,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
293
371
  editAddr = null;
294
372
  suppressBlurCommit = false;
295
373
  props.setSelectionAnchor?.(null);
374
+ clearRefInsert();
296
375
  closeSuggest();
297
376
  if (addr) {
298
377
  props.context.setCellValue(addr, fxDraft.value);
@@ -307,6 +386,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
307
386
  editAddr = null;
308
387
  suppressBlurCommit = false;
309
388
  props.setSelectionAnchor?.(null);
389
+ clearRefInsert();
310
390
  closeSuggest();
311
391
  refreshFx();
312
392
  }
@@ -337,6 +417,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
337
417
  mirroring.value = true;
338
418
  mirrorAddr = addr;
339
419
  fxDraft.value = cellText(addr);
420
+ clearRefInsert();
340
421
  closeSuggest();
341
422
  }
342
423
  function exitMirror(addr) {
@@ -398,6 +479,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
398
479
  fxDraft.value = text;
399
480
  fxCursor.value = cursor;
400
481
  suppressBlurCommit = false;
482
+ clearRefInsert();
401
483
  props.setSelectionAnchor?.(addr);
402
484
  closeSuggest();
403
485
  nextTick(() => {
@@ -414,6 +496,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
414
496
  mirrorGridEdit,
415
497
  exitMirror,
416
498
  isRefSelecting,
499
+ hasRefInsert,
417
500
  isFunctionPopupOpen: () => functionsOpen.value,
418
501
  beginBlurSuppress,
419
502
  handleRefSelect,
@@ -431,6 +514,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
431
514
  mirroring.value = false;
432
515
  mirrorAddr = null;
433
516
  suppressBlurCommit = false;
517
+ clearRefInsert();
434
518
  functionsOpen.value = false;
435
519
  closeSuggest();
436
520
  bindSheet(sheet);
@@ -87,9 +87,9 @@ function insertImageFromUrl(ctx, url) {
87
87
  }
88
88
  /**
89
89
  * 拉起系统文件选择框(右键菜单用;不用 UFilePicker——无编程式打开 API)。
90
- * 选中文件后走 insertImageFromFile。
90
+ * 选中文件后交给 onPick;取消选择时清理节点。
91
91
  */
92
- function pickAndInsertImage(ctx) {
92
+ function pickImageFile(onPick) {
93
93
  const input = document.createElement("input");
94
94
  input.type = "file";
95
95
  input.accept = INSERT_IMAGE_ACCEPT;
@@ -100,7 +100,7 @@ function pickAndInsertImage(ctx) {
100
100
  input.addEventListener("change", () => {
101
101
  const file = input.files?.[0];
102
102
  cleanup();
103
- if (file) insertImageFromFile(ctx, file);
103
+ if (file) onPick(file);
104
104
  });
105
105
  window.addEventListener("focus", () => {
106
106
  setTimeout(() => {
@@ -110,5 +110,34 @@ function pickAndInsertImage(ctx) {
110
110
  document.body.appendChild(input);
111
111
  input.click();
112
112
  }
113
+ /** 拉起系统文件选择框,选中后插入浮动图片 */
114
+ function pickAndInsertImage(ctx) {
115
+ pickImageFile((file) => void insertImageFromFile(ctx, file));
116
+ }
117
+ /**
118
+ * 从本地 File 嵌入图片到活动格:读字节 → 映射类型 → ctx.insertCellImage
119
+ * (格内已有嵌入图时整体覆盖)。不支持的格式 / 无活动格时 message.error 提示。
120
+ */
121
+ async function insertCellImageFromFile(ctx, file) {
122
+ const type = resolveImageType(file);
123
+ if (!type) {
124
+ message.error("不支持的图片格式,请选择 png / jpeg / gif / svg / webp");
125
+ return;
126
+ }
127
+ const active = ctx.getSelection().activeCell;
128
+ if (!active) {
129
+ message.error("请先选择单元格");
130
+ return;
131
+ }
132
+ const buffer = await file.arrayBuffer();
133
+ ctx.insertCellImage(active, {
134
+ data: new Uint8Array(buffer),
135
+ type
136
+ });
137
+ }
138
+ /** 拉起系统文件选择框,选中后嵌入图片到活动格(已有嵌入图时覆盖替换) */
139
+ function pickAndEmbedCellImage(ctx) {
140
+ pickImageFile((file) => void insertCellImageFromFile(ctx, file));
141
+ }
113
142
  //#endregion
114
- export { INSERT_IMAGE_ACCEPT, insertImageFromFile, insertImageFromUrl, pickAndInsertImage, resolveImageType };
143
+ export { INSERT_IMAGE_ACCEPT, insertCellImageFromFile, insertImageFromFile, insertImageFromUrl, pickAndEmbedCellImage, pickAndInsertImage, resolveImageType };
@@ -1,6 +1,6 @@
1
1
  import { defaultToolRegistry } from "../../tools/registry.js";
2
2
  import { imageLinkInitial, imagePreviewSource } from "./popup-helpers.js";
3
- import { pickAndInsertImage } from "./insert-image.js";
3
+ import { pickAndEmbedCellImage, pickAndInsertImage } from "./insert-image.js";
4
4
  import _sfc_main from "./insert-count-menu-item.js";
5
5
  import { createRange } from "infinitable/sheet";
6
6
  import { defineComponent, h } from "vue";
@@ -241,11 +241,39 @@ function cellLinkMenuItems(ctx, active, options) {
241
241
  }];
242
242
  }
243
243
  /**
244
- * body 菜单嵌入图项:目标格含嵌入图时附加——预览 / 图片超链接 / 取消超链接
245
- * (按载荷 link 状态出项)/ 移除图片。设置走 hyperlink 弹窗 image 模式(确认后
246
- * 由宿主覆盖写 `insertCellImage(addr, { ...payload, link })`);取消直写覆盖
247
- * `link: undefined`(引擎 CellImagePayload 清除约定,其余字段保留);移除走
248
- * `removeCellImage`(命令系统,可 undo)。无嵌入图返回空数组(不出现图片项)。
244
+ * 按格嵌入图转为浮动图片(对齐 Excel「放置到单元格上」/ WPS 反向切换):浮动图
245
+ * 落在嵌入图锚点格、尺寸取该格宽高(视觉等价还原),fit 缺省 contain(对齐嵌入图
246
+ * 渲染约定,避免浮动图缺省 fill 拉伸变形),src/data/type/link 随载荷迁移。事务内
247
+ * insertImage + removeCellImage——一次转换 = 一个 undo 单元。
248
+ */
249
+ function cellImageToFloat(ctx, addr) {
250
+ const payload = ctx.getCellImage(addr);
251
+ if (!payload) return;
252
+ const anchor = ctx.getCellInfo(addr).anchor;
253
+ const input = {
254
+ data: payload.data ?? /* @__PURE__ */ new Uint8Array(),
255
+ type: payload.type ?? "png",
256
+ anchor: { from: {
257
+ row: anchor.row,
258
+ col: anchor.col
259
+ } },
260
+ width: ctx.getColWidth(anchor.col) ?? 80,
261
+ height: ctx.getRowHeight(anchor.row) ?? 28,
262
+ fit: payload.fit ?? "contain"
263
+ };
264
+ if (payload.src) input.src = payload.src;
265
+ if (payload.link) input.link = payload.link;
266
+ ctx.beginTransaction();
267
+ ctx.insertImage(input);
268
+ ctx.removeCellImage(addr);
269
+ ctx.commit();
270
+ }
271
+ /**
272
+ * body 菜单嵌入图项:预览 / 图片超链接 / 取消超链接(按载荷 link 状态出项)/
273
+ * 转为浮动图片 / 替换图片 / 移除图片。设置走 hyperlink 弹窗 image 模式(确认后由宿主覆盖写
274
+ * `insertCellImage(addr, { ...payload, link })`);取消直写覆盖 `link: undefined`
275
+ * (引擎 CellImagePayload 清除约定,其余字段保留);转换/替换/移除分别走
276
+ * `cellImageToFloat`、`insertCellImage` 覆盖与 `removeCellImage`(命令系统,可 undo)。
249
277
  */
250
278
  function cellImageMenuItems(ctx, active, options) {
251
279
  if (!active || !ctx.hasCellImage(active)) return [];
@@ -274,18 +302,31 @@ function cellImageMenuItems(ctx, active, options) {
274
302
  })
275
303
  });
276
304
  items.push({
305
+ label: "转为浮动图片",
306
+ disabled: readonly,
307
+ callback: () => cellImageToFloat(ctx, active)
308
+ }, {
309
+ label: "替换图片",
310
+ disabled: readonly,
311
+ callback: () => pickAndEmbedCellImage(ctx)
312
+ }, {
277
313
  label: "移除图片",
278
314
  disabled: readonly,
279
315
  callback: () => ctx.removeCellImage(active)
280
316
  });
281
317
  return items;
282
318
  }
283
- /** body 格右键菜单:合并/取消合并 + 设置数据格式 + 超链接 + 插入图片(+ 嵌入图四项;行列插入/删除仅行号/列头菜单) */
319
+ /**
320
+ * body 格右键菜单。目标格含嵌入图时出**纯图片菜单**(预览 / 超链接 / 转浮动 /
321
+ * 替换 / 移除)——图片盖住整格,右键语义是「图片」而非「单元格」,不出合并 /
322
+ * 数据格式 / 超链接等普通格项(对齐 Excel 图片右键约定)。普通格:合并 / 取消合并 +
323
+ * 设置数据格式 + 超链接 + 插入图片(浮动)+ 嵌入图片(入格);行列插入/删除仅行号/列头菜单。
324
+ */
284
325
  function buildBodyMenus(ctx, options) {
326
+ const active = ctx.getSelection().activeCell;
327
+ if (active && ctx.hasCellImage(active)) return cellImageMenuItems(ctx, active, options);
285
328
  const mergeTool = defaultToolRegistry.get("merge");
286
329
  const unmergeTool = defaultToolRegistry.get("unmerge");
287
- const active = ctx.getSelection().activeCell;
288
- const imageItems = cellImageMenuItems(ctx, active, options);
289
330
  return [
290
331
  {
291
332
  label: "合并单元格",
@@ -337,7 +378,11 @@ function buildBodyMenus(ctx, options) {
337
378
  disabled: !active,
338
379
  callback: () => pickAndInsertImage(ctx)
339
380
  },
340
- ...imageItems.length > 0 ? [{ divider: true }, ...imageItems] : []
381
+ {
382
+ label: "嵌入图片",
383
+ disabled: !active,
384
+ callback: () => pickAndEmbedCellImage(ctx)
385
+ }
341
386
  ];
342
387
  }
343
388
  /**
@@ -359,4 +404,4 @@ function ensureContextMenuSelection(ctx, info, renderSize) {
359
404
  }
360
405
  }
361
406
  //#endregion
362
- export { AXIS_SIZE_MAX, INSERT_COUNT_MAX, applyNumFmtToSelection, buildBodyMenus, buildColHeaderMenus, buildRowHeaderMenus, defaultInsertCount, ensureContextMenuSelection, isColInSelection, isRowInSelection, resolveRenderSize, wholeColRange, wholeRowRange };
407
+ export { AXIS_SIZE_MAX, INSERT_COUNT_MAX, applyNumFmtToSelection, buildBodyMenus, buildColHeaderMenus, buildRowHeaderMenus, cellImageToFloat, defaultInsertCount, ensureContextMenuSelection, isColInSelection, isRowInSelection, resolveRenderSize, wholeColRange, wholeRowRange };
@@ -17,7 +17,7 @@ import { useSheetState } from "./use-sheet-state.js";
17
17
  import { useToolGroups } from "./use-tool-groups.js";
18
18
  import { useToolPopup } from "./use-tool-popup.js";
19
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";
20
+ import { UDropdown, UImagePreviewer, messageConfirm } from "@veltra/desktop";
21
21
  import { bem } from "@veltra/utils";
22
22
  //#region src/components/sheet/sheet.vue
23
23
  const _sfc_main = /*@__PURE__*/ defineComponent({
@@ -178,9 +178,31 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
178
178
  function openImagePreview(source) {
179
179
  imagePreview.value = source;
180
180
  }
181
+ /** 新标签打开外链(对齐引擎默认打开语义:noopener) */
182
+ function openExternal(url) {
183
+ window.open(url, "_blank", "noopener,noreferrer");
184
+ }
185
+ /** 链接格单击:emit 后直开(保持引擎原默认行为) */
186
+ function handleCellLinkClick(event) {
187
+ emit("cell-link-click", event);
188
+ openExternal(event.url);
189
+ }
190
+ /** 图片链接单击(浮动图/嵌入图):emit 后确认再开——点击即跳转易误触 */
191
+ function handleImageLinkClick(event) {
192
+ emit("image-link-click", event);
193
+ messageConfirm({
194
+ title: "打开图片链接",
195
+ message: `即将打开图片链接:${event.url}`,
196
+ confirmButtonText: "打开",
197
+ cancelButtonText: "取消",
198
+ onClose: (action) => {
199
+ if (action === "confirm") openExternal(event.url);
200
+ }
201
+ });
202
+ }
181
203
  const gridRef = useTemplateRef("gridRef");
182
204
  const formulaBarRef = useTemplateRef("formulaBarRef");
183
- const { rebuildGrid, activateGrid, pruneCache, getGrid, setSelectionAnchor } = useSheetGrid({
205
+ const { rebuildGrid, activateGrid, pruneCache, getGrid, setSelectionAnchor, setRefHighlights } = useSheetGrid({
184
206
  props,
185
207
  gridRef,
186
208
  getActiveSheet: () => activeSheet.value,
@@ -196,8 +218,8 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
196
218
  emit("cell-link-leave", event);
197
219
  hideCellLinkTooltip(event);
198
220
  },
199
- onCellLinkClick: (event) => emit("cell-link-click", event),
200
- onImageLinkClick: (event) => emit("image-link-click", event),
221
+ onCellLinkClick: (event) => handleCellLinkClick(event),
222
+ onImageLinkClick: (event) => handleImageLinkClick(event),
201
223
  onFloatContextMenu: (event) => emit("float-context-menu", event),
202
224
  openHyperlinkPopup,
203
225
  openImagePreview
@@ -279,11 +301,13 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
279
301
  ref: formulaBarRef,
280
302
  sheet: unref(activeSheet),
281
303
  context: unref(context),
282
- "set-selection-anchor": unref(setSelectionAnchor)
304
+ "set-selection-anchor": unref(setSelectionAnchor),
305
+ "set-ref-highlights": unref(setRefHighlights)
283
306
  }, null, 8, [
284
307
  "sheet",
285
308
  "context",
286
- "set-selection-anchor"
309
+ "set-selection-anchor",
310
+ "set-ref-highlights"
287
311
  ])) : createCommentVNode("v-if", true),
288
312
  createElementVNode("div", {
289
313
  ref_key: "gridRef",
@@ -6,6 +6,8 @@ import "@veltra/desktop/components/scroll/style";
6
6
  import "@veltra/desktop/components/tip/style";
7
7
  import "@veltra/desktop/components/loading/style";
8
8
  import "@veltra/desktop/components/message/style";
9
+ import "@veltra/desktop/components/message-confirm/style";
10
+ import "@veltra/desktop/components/image-previewer/style";
9
11
  import "@veltra/desktop/components/input/style";
10
12
  import "@veltra/desktop/components/file-picker/style";
11
13
  import "@veltra/desktop/components/button/style";
@@ -7,6 +7,8 @@ import "@veltra/desktop/components/scroll/style";
7
7
  import "@veltra/desktop/components/tip/style";
8
8
  import "@veltra/desktop/components/loading/style";
9
9
  import "@veltra/desktop/components/message/style";
10
+ import "@veltra/desktop/components/message-confirm/style";
11
+ import "@veltra/desktop/components/image-previewer/style";
10
12
  import "@veltra/desktop/components/input/style";
11
13
  import "@veltra/desktop/components/file-picker/style";
12
14
  import "@veltra/desktop/components/button/style";
@@ -13,6 +13,12 @@ const REF_TRIGGER_CHARS = /* @__PURE__ */ new Set([
13
13
  "<",
14
14
  ">"
15
15
  ]);
16
+ /** 引用拾取染色框循环色板(对齐 Excel 蓝/绿/红循环惯例),按引用在公式中的出现顺序取色 */
17
+ const REF_HIGHLIGHT_COLORS = [
18
+ "#2563eb",
19
+ "#16a34a",
20
+ "#dc2626"
21
+ ];
16
22
  /**
17
23
  * 判定是否处于「可插入引用」位置(无状态:每次按文本 + 光标重算)。
18
24
  * `-` 的一元/二元歧义基础版不区分(`A1-` 后框选 → `A1-B2`,合法且误判无害)。
@@ -26,12 +32,14 @@ function isRefSelectContext(text, cursor) {
26
32
  }
27
33
  /** 在光标处插入引用文本(替换空选区;有选区时覆盖选区) */
28
34
  function insertRefText(text, cursor, rangeText, selectionEnd = cursor) {
29
- const start = Math.min(cursor, selectionEnd);
30
- const end = Math.max(cursor, selectionEnd);
35
+ return replaceRefText(text, Math.min(cursor, selectionEnd), Math.max(cursor, selectionEnd), rangeText);
36
+ }
37
+ /** 替换 [start, end) 区间为引用文本(shift+点选扩展:扩展上次插入的引用) */
38
+ function replaceRefText(text, start, end, rangeText) {
31
39
  return {
32
40
  text: text.slice(0, start) + rangeText + text.slice(end),
33
41
  cursor: start + rangeText.length
34
42
  };
35
43
  }
36
44
  //#endregion
37
- export { insertRefText, isRefSelectContext };
45
+ export { REF_HIGHLIGHT_COLORS, insertRefText, isRefSelectContext, replaceRefText };
@@ -119,11 +119,12 @@ function useSheetGrid(options) {
119
119
  scrollbar: props.scrollbar,
120
120
  growOnScroll: props.growOnScroll,
121
121
  theme: resolveCanvasThemeOverride(host),
122
+ openCellLinkOnClick: false,
122
123
  onContextMenu: handleContextMenu,
123
124
  onEditStart: (addr) => formulaBarRef.value?.mirrorGridEdit(addr),
124
125
  onEditEnd: (addr) => formulaBarRef.value?.exitMirror(addr),
125
126
  onColResizeEnd: options.onColResizeEnd,
126
- interceptSelection: () => (formulaBarRef.value?.isRefSelecting() ?? false) || (formulaBarRef.value?.isFunctionPopupOpen() ?? false) || (options.isFunctionPopupOpen?.() ?? false),
127
+ interceptSelection: () => (formulaBarRef.value?.isRefSelecting() ?? false) || (formulaBarRef.value?.hasRefInsert() ?? false) || (formulaBarRef.value?.isFunctionPopupOpen() ?? false) || (options.isFunctionPopupOpen?.() ?? false),
127
128
  onSelectionIntercept: (range) => formulaBarRef.value?.handleRefSelect(range)
128
129
  });
129
130
  let dirty = false;
@@ -211,7 +212,10 @@ function useSheetGrid(options) {
211
212
  function activateGrid() {
212
213
  const sheet = getActiveSheet();
213
214
  if (!gridRef.value) return;
214
- if (active && active.sheet !== sheet) active.grid.setSelectionAnchor(null);
215
+ if (active && active.sheet !== sheet) {
216
+ active.grid.setSelectionAnchor(null);
217
+ active.grid.setHighlightRanges([]);
218
+ }
215
219
  const cached = cache.get(sheet);
216
220
  if (cached && !cached.dirty) {
217
221
  cached.lastUsed = ++seq;
@@ -283,12 +287,17 @@ function useSheetGrid(options) {
283
287
  function setSelectionAnchor(addr) {
284
288
  active?.grid.setSelectionAnchor(addr);
285
289
  }
290
+ /** 公式引用染色框同步(公式栏 → 活动实例透传;空数组清除;无活动实例时静默) */
291
+ function setRefHighlights(items) {
292
+ active?.grid.setHighlightRanges(items);
293
+ }
286
294
  return {
287
295
  rebuildGrid,
288
296
  activateGrid,
289
297
  pruneCache,
290
298
  getGrid: () => active?.grid,
291
- setSelectionAnchor
299
+ setSelectionAnchor,
300
+ setRefHighlights
292
301
  };
293
302
  }
294
303
  //#endregion
@@ -105,13 +105,14 @@ export interface SheetEmits {
105
105
  (name: 'cell-link-leave', payload: CellLinkLeaveEvent): void;
106
106
  /**
107
107
  * 单元格超链接单击(引擎 `CellLinkClickEvent` 形态:真实指针 down+up 命中
108
- * 同一链接格;框选拖拽/键盘选中不触发)。单击打开仍由引擎
109
- * `openCellLinkOnClick` 默认处理,ultra-ui 不接管
108
+ * 同一链接格;框选拖拽/键盘选中不触发)。组件已接管打开:emit 后直接新标签
109
+ * 打开(引擎 `openCellLinkOnClick` 已关闭)
110
110
  */
111
111
  (name: 'cell-link-click', payload: CellLinkClickEvent): void;
112
112
  /**
113
113
  * 图片链接单击(引擎 `ImageLinkClickEvent`,`kind` 区分 `cell` 嵌入图 /
114
- * `float` 浮动图);默认打开行为同上由引擎处理
114
+ * `float` 浮动图)。组件已接管打开:emit 后弹确认框,确认才新标签打开
115
+ * (防误触跳转;引擎 `openCellLinkOnClick` 已关闭)
115
116
  */
116
117
  (name: 'image-link-click', payload: ImageLinkClickEvent): void;
117
118
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veltra/sheet",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "homepage": "https://github.com/cabinet-fe/ultra-ui#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/cabinet-fe/ultra-ui/issues"
@@ -33,9 +33,6 @@
33
33
  "import": "./dist/*"
34
34
  }
35
35
  },
36
- "dependencies": {
37
- "infinitable": "^0.1.7"
38
- },
39
36
  "peerDependencies": {
40
37
  "@cat-kit/core": ">=1.2.1",
41
38
  "@cat-kit/fe": ">=1.2.1",
@@ -43,6 +40,7 @@
43
40
  "@veltra/icons": "^1.5.0",
44
41
  "@veltra/styles": "^1.7.14",
45
42
  "@veltra/utils": "^1.7.14",
43
+ "infinitable": "^0.2.2",
46
44
  "vue": ">=3.5.43"
47
45
  }
48
46
  }