@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.
- package/dist/components/sheet/float-image-menu.js +87 -0
- package/dist/components/sheet/insert-image.js +33 -4
- package/dist/components/sheet/popup-helpers.js +18 -2
- package/dist/components/sheet/popups/hyperlink-popup.js +127 -0
- package/dist/components/sheet/sheet-context-menu.js +122 -5
- package/dist/components/sheet/sheet.js +132 -15
- package/dist/components/sheet/style.d.ts +2 -0
- package/dist/components/sheet/style.js +2 -0
- package/dist/components/sheet/style2.css +62 -0
- package/dist/components/sheet/use-cell-link-tooltip.js +33 -0
- package/dist/components/sheet/use-sheet-grid.js +33 -1
- package/dist/components/sheet/use-sheet-state.js +1 -0
- package/dist/tools/context.d.ts +20 -2
- package/dist/tools/context.js +9 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/sheet.d.ts +51 -1
- package/package.json +2 -2
- package/src/components/sheet/__test__/float-image-menu.test.ts +196 -0
- package/src/components/sheet/__test__/hyperlink-popup.test.ts +176 -0
- package/src/components/sheet/__test__/insert-image.test.ts +60 -0
- package/src/components/sheet/__test__/sheet-component.test.ts +539 -16
- package/src/components/sheet/__test__/sheet-context-menu.test.ts +293 -4
- package/src/components/sheet/float-image-menu.ts +100 -0
- package/src/components/sheet/insert-image.ts +32 -3
- package/src/components/sheet/popup-helpers.ts +68 -2
- package/src/components/sheet/popups/hyperlink-popup.vue +112 -0
- package/src/components/sheet/sheet-context-menu.ts +125 -6
- package/src/components/sheet/sheet.vue +149 -3
- package/src/components/sheet/style.scss +66 -0
- package/src/components/sheet/style.ts +3 -1
- package/src/components/sheet/use-cell-link-tooltip.ts +42 -0
- package/src/components/sheet/use-sheet-grid.ts +62 -3
- package/src/components/sheet/use-sheet-state.ts +8 -2
- package/src/tools/__test__/context.test.ts +89 -0
- package/src/tools/context.ts +33 -2
- package/src/types/sheet.ts +56 -0
|
@@ -278,4 +278,93 @@ describe('SheetContext', () => {
|
|
|
278
278
|
expect(ctx.getImages()).toHaveLength(0)
|
|
279
279
|
expect(onImage).not.toHaveBeenCalled()
|
|
280
280
|
})
|
|
281
|
+
|
|
282
|
+
it('updateImage 写/清 SheetImage.link(null 清除),经命令可 undo', () => {
|
|
283
|
+
const sheet = new Sheet()
|
|
284
|
+
const ctx = createSheetContext(sheet)
|
|
285
|
+
const id = ctx.insertImage({
|
|
286
|
+
data: new Uint8Array([1]),
|
|
287
|
+
type: 'png',
|
|
288
|
+
anchor: { from: { row: 0, col: 0 } }
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
ctx.updateImage(id, { link: 'https://example.com' })
|
|
292
|
+
expect(ctx.getImages()[0]?.link).toBe('https://example.com')
|
|
293
|
+
|
|
294
|
+
ctx.updateImage(id, { link: null })
|
|
295
|
+
expect(ctx.getImages()[0]?.link).toBeUndefined()
|
|
296
|
+
|
|
297
|
+
// undo 一次还原清除前的链接
|
|
298
|
+
expect(ctx.undo()).toBe(true)
|
|
299
|
+
expect(ctx.getImages()[0]?.link).toBe('https://example.com')
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
it('cell link 门面:写入 → 读取 → 清除 → undo 还原,均经命令可 undo', () => {
|
|
303
|
+
const sheet = new Sheet()
|
|
304
|
+
const ctx = createSheetContext(sheet)
|
|
305
|
+
const addr = { row: 0, col: 0 }
|
|
306
|
+
const link = { url: 'https://example.com', text: '示例' }
|
|
307
|
+
|
|
308
|
+
ctx.setCellLink(addr, link)
|
|
309
|
+
expect(ctx.getCellLink(addr)).toEqual(link)
|
|
310
|
+
expect(ctx.canUndo).toBe(true)
|
|
311
|
+
|
|
312
|
+
// null 即清除
|
|
313
|
+
ctx.setCellLink(addr, null)
|
|
314
|
+
expect(ctx.getCellLink(addr)).toBeUndefined()
|
|
315
|
+
|
|
316
|
+
// undo 还原写入的链接
|
|
317
|
+
expect(ctx.undo()).toBe(true)
|
|
318
|
+
expect(ctx.getCellLink(addr)).toEqual(link)
|
|
319
|
+
|
|
320
|
+
ctx.clearCellLink(addr)
|
|
321
|
+
expect(ctx.getCellLink(addr)).toBeUndefined()
|
|
322
|
+
|
|
323
|
+
// undo 还原 clear
|
|
324
|
+
expect(ctx.undo()).toBe(true)
|
|
325
|
+
expect(ctx.getCellLink(addr)).toEqual(link)
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
it('cell image 门面:插入 → get/has → 移除 → undo 还原,经命令可 undo', () => {
|
|
329
|
+
const sheet = new Sheet()
|
|
330
|
+
const ctx = createSheetContext(sheet)
|
|
331
|
+
const addr = { row: 1, col: 2 }
|
|
332
|
+
const payload = { src: 'https://example.com/a.png' }
|
|
333
|
+
|
|
334
|
+
expect(ctx.hasCellImage(addr)).toBe(false)
|
|
335
|
+
expect(ctx.getCellImage(addr)).toBeUndefined()
|
|
336
|
+
|
|
337
|
+
ctx.insertCellImage(addr, payload)
|
|
338
|
+
expect(ctx.hasCellImage(addr)).toBe(true)
|
|
339
|
+
expect(ctx.getCellImage(addr)).toEqual(payload)
|
|
340
|
+
|
|
341
|
+
ctx.removeCellImage(addr)
|
|
342
|
+
expect(ctx.hasCellImage(addr)).toBe(false)
|
|
343
|
+
expect(ctx.getCellImage(addr)).toBeUndefined()
|
|
344
|
+
|
|
345
|
+
// undo 还原移除的嵌入图
|
|
346
|
+
expect(ctx.undo()).toBe(true)
|
|
347
|
+
expect(ctx.hasCellImage(addr)).toBe(true)
|
|
348
|
+
expect(ctx.getCellImage(addr)).toEqual(payload)
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
it('onCellImageChange 订阅/退订:单格变更带 addr 定向载荷', () => {
|
|
352
|
+
const sheet = new Sheet()
|
|
353
|
+
const ctx = createSheetContext(sheet)
|
|
354
|
+
const onCellImage = vi.fn()
|
|
355
|
+
const off = ctx.onCellImageChange(onCellImage)
|
|
356
|
+
|
|
357
|
+
const addr = { row: 0, col: 0 }
|
|
358
|
+
ctx.insertCellImage(addr, { src: 'https://example.com/a.png' })
|
|
359
|
+
expect(onCellImage).toHaveBeenCalledWith({ addr })
|
|
360
|
+
|
|
361
|
+
ctx.removeCellImage(addr)
|
|
362
|
+
expect(onCellImage).toHaveBeenCalledTimes(2)
|
|
363
|
+
|
|
364
|
+
// 退订后不再回调
|
|
365
|
+
off()
|
|
366
|
+
onCellImage.mockClear()
|
|
367
|
+
ctx.insertCellImage(addr, { src: 'https://example.com/b.png' })
|
|
368
|
+
expect(onCellImage).not.toHaveBeenCalled()
|
|
369
|
+
})
|
|
281
370
|
})
|
package/src/tools/context.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { SelectionState } from 'infinitable/sheet'
|
|
|
9
9
|
import type { FrozenState, Sheet } from 'infinitable/sheet'
|
|
10
10
|
import type { CellStyle, CellStylePatch } from 'infinitable/sheet'
|
|
11
11
|
import type { Workbook } from 'infinitable/sheet'
|
|
12
|
+
import type { CellImagePayload, CellLinkPayload } from 'infinitable/sheet'
|
|
12
13
|
|
|
13
14
|
import { axisStyleItemsForRange, classifySelectionStyleTarget } from './apply-style'
|
|
14
15
|
|
|
@@ -128,17 +129,37 @@ export interface SheetContext {
|
|
|
128
129
|
insertImage(input: ImageInput): string
|
|
129
130
|
/** 删除浮动图片;不存在则无操作 */
|
|
130
131
|
removeImage(id: string): void
|
|
131
|
-
/**
|
|
132
|
+
/** 更新浮动图片锚点/尺寸/文案/链接(link 传 null 清除);不存在或无变更则无操作 */
|
|
132
133
|
updateImage(id: string, patch: ImageUpdateFields): void
|
|
133
134
|
/** 只读图片列表(快照副本) */
|
|
134
135
|
getImages(): readonly SheetImage[]
|
|
135
136
|
|
|
137
|
+
// ─── 单元格超链接(写入经 cell-link 命令,可 undo) ─────────
|
|
138
|
+
/** 写入单元格超链接;link 为 null 时清除该格链接(合并格解析锚点) */
|
|
139
|
+
setCellLink(addr: CellAddress, link: CellLinkPayload | null): void
|
|
140
|
+
/** 读取单元格超链接载荷(副本);无链接返回 undefined(合并格解析锚点) */
|
|
141
|
+
getCellLink(addr: CellAddress): CellLinkPayload | undefined
|
|
142
|
+
/** 清除单元格超链接;无链接则无操作(合并格解析锚点) */
|
|
143
|
+
clearCellLink(addr: CellAddress): void
|
|
144
|
+
|
|
145
|
+
// ─── 按格嵌入图(写入经 cell-image 命令,可 undo) ─────────
|
|
146
|
+
/** 插入(或覆盖)按格嵌入图;相同载荷视为无操作(合并格解析锚点) */
|
|
147
|
+
insertCellImage(addr: CellAddress, image: CellImagePayload): void
|
|
148
|
+
/** 移除按格嵌入图;无图时无操作(合并格解析锚点) */
|
|
149
|
+
removeCellImage(addr: CellAddress): void
|
|
150
|
+
/** 读取按格嵌入图载荷(副本);无图返回 undefined(合并格解析锚点) */
|
|
151
|
+
getCellImage(addr: CellAddress): CellImagePayload | undefined
|
|
152
|
+
/** 该格是否有嵌入图(供右键菜单等判定;合并格解析锚点) */
|
|
153
|
+
hasCellImage(addr: CellAddress): boolean
|
|
154
|
+
|
|
136
155
|
// ─── 事件订阅(订阅时绑定到当前活动 sheet;tab 切换后需重新订阅) ──
|
|
137
156
|
onSelectionChange(handler: (state: SelectionState) => void): () => void
|
|
138
157
|
onHistoryChange(handler: (state: HistoryState) => void): () => void
|
|
139
158
|
onFrozenChange(handler: (state: FrozenState) => void): () => void
|
|
140
159
|
/** 图片集合变化(单图带 id;整表替换时 id 缺省) */
|
|
141
160
|
onImageChange(handler: (payload: { id?: string }) => void): () => void
|
|
161
|
+
/** 按格嵌入图变化(单格带 addr;结构平移/整表替换时缺省) */
|
|
162
|
+
onCellImageChange(handler: (payload: { addr?: CellAddress }) => void): () => void
|
|
142
163
|
}
|
|
143
164
|
|
|
144
165
|
/** createSheetContext 可选配置 */
|
|
@@ -273,6 +294,15 @@ export function createSheetContext(
|
|
|
273
294
|
updateImage: (id, patch) => sheet().updateImage(id, patch),
|
|
274
295
|
getImages: () => sheet().getImages(),
|
|
275
296
|
|
|
297
|
+
setCellLink: (addr, link) => sheet().setCellLink(addr, link),
|
|
298
|
+
getCellLink: (addr) => sheet().getCellLink(addr),
|
|
299
|
+
clearCellLink: (addr) => sheet().clearCellLink(addr),
|
|
300
|
+
|
|
301
|
+
insertCellImage: (addr, image) => sheet().insertCellImage(addr, image),
|
|
302
|
+
removeCellImage: (addr) => sheet().removeCellImage(addr),
|
|
303
|
+
getCellImage: (addr) => sheet().getCellImage(addr),
|
|
304
|
+
hasCellImage: (addr) => sheet().hasCellImage(addr),
|
|
305
|
+
|
|
276
306
|
beginTransaction: () => sheet().beginTransaction(),
|
|
277
307
|
commit: () => sheet().commit(),
|
|
278
308
|
rollback: () => sheet().rollback(),
|
|
@@ -289,6 +319,7 @@ export function createSheetContext(
|
|
|
289
319
|
onSelectionChange: (handler) => sheet().on('selection-change', handler),
|
|
290
320
|
onHistoryChange: (handler) => sheet().on('history-change', handler),
|
|
291
321
|
onFrozenChange: (handler) => sheet().on('frozen-change', handler),
|
|
292
|
-
onImageChange: (handler) => sheet().on('image-change', handler)
|
|
322
|
+
onImageChange: (handler) => sheet().on('image-change', handler),
|
|
323
|
+
onCellImageChange: (handler) => sheet().on('cell-image-change', handler)
|
|
293
324
|
}
|
|
294
325
|
}
|
package/src/types/sheet.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import type { DeconstructValue } from '@veltra/utils'
|
|
2
|
+
import type {
|
|
3
|
+
CellLinkClickEvent,
|
|
4
|
+
CellLinkHoverEvent,
|
|
5
|
+
CellLinkLeaveEvent,
|
|
6
|
+
FloatContextMenuEvent,
|
|
7
|
+
ImageLinkClickEvent
|
|
8
|
+
} from 'infinitable'
|
|
2
9
|
import type { Sheet } from 'infinitable/sheet'
|
|
3
10
|
import type { Workbook } from 'infinitable/sheet'
|
|
4
11
|
import type {
|
|
12
|
+
CellAddress,
|
|
5
13
|
ResolveCellRenderer,
|
|
6
14
|
ResolveCellStyleHook,
|
|
7
15
|
ResolveDisplayValue,
|
|
@@ -77,11 +85,59 @@ export interface SheetProps {
|
|
|
77
85
|
growOnScroll?: boolean
|
|
78
86
|
}
|
|
79
87
|
|
|
88
|
+
/**
|
|
89
|
+
* 浮动图右键事件载荷:引擎 `FloatContextMenuEvent` 关键字段 + 页面坐标。
|
|
90
|
+
*
|
|
91
|
+
* 右键命中浮动图时引擎不穿透到单元格右键(body 菜单不弹),宿主经
|
|
92
|
+
* `float-context-menu` 自行弹浮动图菜单(预览 / 超链接 / 删除等)。
|
|
93
|
+
*/
|
|
94
|
+
export interface FloatContextMenuPayload {
|
|
95
|
+
/** 命中的浮动对象 id */
|
|
96
|
+
id: string
|
|
97
|
+
/** 层坐标(CSS 像素,相对 grid 实例容器) */
|
|
98
|
+
x: number
|
|
99
|
+
y: number
|
|
100
|
+
/** 页面视口坐标(层坐标 + grid 容器偏移;与 body 右键菜单同口径,供菜单定位) */
|
|
101
|
+
clientX: number
|
|
102
|
+
clientY: number
|
|
103
|
+
/** 引擎原始右键事件(最小 DOM 事件结构) */
|
|
104
|
+
originalEvent: FloatContextMenuEvent['originalEvent']
|
|
105
|
+
}
|
|
106
|
+
|
|
80
107
|
export interface SheetEmits {
|
|
81
108
|
/** 激活 sheet 切换(点击 tab 或宿主调用 workbook.activateSheet) */
|
|
82
109
|
(name: 'active-sheet-change', payload: { sheet: Sheet; index: number }): void
|
|
83
110
|
/** 列宽拖拽落定(写模型之后):载荷含列索引与最终宽度 */
|
|
84
111
|
(name: 'col-resize-end', payload: { col: number; width: number }): void
|
|
112
|
+
/**
|
|
113
|
+
* 单元格超链接悬停(引擎 `CellLinkHoverEvent` 形态:格坐标 + URL/显示文本 +
|
|
114
|
+
* 落点层坐标);tooltip 由宿主渲染,ultra-ui 不接管
|
|
115
|
+
*/
|
|
116
|
+
(name: 'cell-link-hover', payload: CellLinkHoverEvent): void
|
|
117
|
+
/** 单元格超链接离开(引擎 `CellLinkLeaveEvent` 形态:刚离开的链接格坐标) */
|
|
118
|
+
(name: 'cell-link-leave', payload: CellLinkLeaveEvent): void
|
|
119
|
+
/**
|
|
120
|
+
* 单元格超链接单击(引擎 `CellLinkClickEvent` 形态:真实指针 down+up 命中
|
|
121
|
+
* 同一链接格;框选拖拽/键盘选中不触发)。组件已接管打开:emit 后直接新标签
|
|
122
|
+
* 打开(引擎 `openCellLinkOnClick` 已关闭)
|
|
123
|
+
*/
|
|
124
|
+
(name: 'cell-link-click', payload: CellLinkClickEvent): void
|
|
125
|
+
/**
|
|
126
|
+
* 图片链接单击(引擎 `ImageLinkClickEvent`,`kind` 区分 `cell` 嵌入图 /
|
|
127
|
+
* `float` 浮动图)。组件已接管打开:emit 后弹确认框,确认才新标签打开
|
|
128
|
+
* (防误触跳转;引擎 `openCellLinkOnClick` 已关闭)
|
|
129
|
+
*/
|
|
130
|
+
(name: 'image-link-click', payload: ImageLinkClickEvent): void
|
|
131
|
+
/**
|
|
132
|
+
* 按格嵌入图变化(`{ addr?: CellAddress }` 定向语义:单格变更带 addr,
|
|
133
|
+
* 结构平移/整表替换时缺省);仅当前活动 sheet 的事件被透传
|
|
134
|
+
*/
|
|
135
|
+
(name: 'cell-image-change', payload: { addr?: CellAddress }): void
|
|
136
|
+
/**
|
|
137
|
+
* 浮动图右键(载荷见 {@link FloatContextMenuPayload};右键不穿透到
|
|
138
|
+
* 单元格 body 菜单,宿主据此弹浮动图独立菜单)
|
|
139
|
+
*/
|
|
140
|
+
(name: 'float-context-menu', payload: FloatContextMenuPayload): void
|
|
85
141
|
}
|
|
86
142
|
|
|
87
143
|
/** 在组件内部引用 */
|