@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
|
@@ -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";
|
|
@@ -645,6 +645,68 @@
|
|
|
645
645
|
inset: 0;
|
|
646
646
|
visibility: hidden;
|
|
647
647
|
}
|
|
648
|
+
.u-sheet {
|
|
649
|
+
/* 悬停链接格 tooltip:引擎 cell link hover/leave 事件驱动挂载/卸载,
|
|
650
|
+
层坐标 + 偏移后绝对定位于 grid 区;pointer-events: none 避免浮层
|
|
651
|
+
自身命中指针触发 leave 抖动(DOM 顺序在画布之后,天然盖在画布上) */
|
|
652
|
+
}
|
|
653
|
+
.u-sheet__link-tooltip {
|
|
654
|
+
position: absolute;
|
|
655
|
+
z-index: 10;
|
|
656
|
+
max-width: 320px;
|
|
657
|
+
padding: 2px 8px;
|
|
658
|
+
border: var(--u-border);
|
|
659
|
+
border-radius: var(--u-radius-small);
|
|
660
|
+
background-color: var(--u-bg-color-top);
|
|
661
|
+
box-shadow: var(--u-shadow-sm);
|
|
662
|
+
color: var(--u-text-color-main);
|
|
663
|
+
font-size: var(--u-font-size-main-small);
|
|
664
|
+
white-space: nowrap;
|
|
665
|
+
overflow: hidden;
|
|
666
|
+
text-overflow: ellipsis;
|
|
667
|
+
pointer-events: none;
|
|
668
|
+
}
|
|
669
|
+
.u-sheet {
|
|
670
|
+
/* ── 超链接配置弹窗(右键菜单拉起,无工具栏锚点:自绘遮罩 + 居中面板,
|
|
671
|
+
对齐 loading-mask 自绘先例;遮罩半透明黑与 desktop dialog overlay 同口径) ── */
|
|
672
|
+
}
|
|
673
|
+
.u-sheet__link-dialog-mask {
|
|
674
|
+
position: fixed;
|
|
675
|
+
inset: 0;
|
|
676
|
+
display: flex;
|
|
677
|
+
align-items: center;
|
|
678
|
+
justify-content: center;
|
|
679
|
+
background-color: rgba(0, 0, 0, 0.32);
|
|
680
|
+
}
|
|
681
|
+
.u-sheet__link-dialog {
|
|
682
|
+
display: flex;
|
|
683
|
+
flex-direction: column;
|
|
684
|
+
gap: var(--u-gap-small);
|
|
685
|
+
width: min(380px, 90vw);
|
|
686
|
+
padding: var(--u-gap-default);
|
|
687
|
+
border-radius: var(--u-radius-large);
|
|
688
|
+
background-color: var(--u-bg-color-top);
|
|
689
|
+
box-shadow: var(--u-shadow-lg);
|
|
690
|
+
}
|
|
691
|
+
.u-sheet__link-dialog-title {
|
|
692
|
+
color: var(--u-text-color-main);
|
|
693
|
+
font-size: var(--u-font-size-title-default);
|
|
694
|
+
font-weight: 600;
|
|
695
|
+
}
|
|
696
|
+
.u-sheet__link-dialog-body {
|
|
697
|
+
display: flex;
|
|
698
|
+
flex-direction: column;
|
|
699
|
+
gap: var(--u-gap-small);
|
|
700
|
+
}
|
|
701
|
+
.u-sheet__link-dialog-input {
|
|
702
|
+
flex: 1;
|
|
703
|
+
min-width: 0;
|
|
704
|
+
}
|
|
705
|
+
.u-sheet__link-dialog-footer {
|
|
706
|
+
display: flex;
|
|
707
|
+
justify-content: flex-end;
|
|
708
|
+
gap: var(--u-gap-small);
|
|
709
|
+
}
|
|
648
710
|
.u-sheet__tabs {
|
|
649
711
|
display: flex;
|
|
650
712
|
align-items: center;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { shallowRef } from "vue";
|
|
2
|
+
//#region src/components/sheet/use-cell-link-tooltip.ts
|
|
3
|
+
/**
|
|
4
|
+
* tooltip 相对悬停落点的偏移:右下错开,浮层不遮指针与命中的链接文本。
|
|
5
|
+
*/
|
|
6
|
+
const TOOLTIP_OFFSET_X = 8;
|
|
7
|
+
const TOOLTIP_OFFSET_Y = 20;
|
|
8
|
+
/**
|
|
9
|
+
* 单元格超链接悬停 tooltip(引擎 hover/leave 事件驱动):
|
|
10
|
+
* hover 时记录命中的层坐标 + URL(层坐标相对 grid 实例容器 = grid 区原点,
|
|
11
|
+
* 渲染层直接在 grid 区内绝对定位挂载浮层);leave 时卸载(置 null)。
|
|
12
|
+
* 事件源接线在 use-sheet-grid(与 cell-link-hover/leave 组件 emit 同源)。
|
|
13
|
+
*/
|
|
14
|
+
function useCellLinkTooltip() {
|
|
15
|
+
const tooltip = shallowRef(null);
|
|
16
|
+
function onCellLinkHover(event) {
|
|
17
|
+
tooltip.value = {
|
|
18
|
+
url: event.url,
|
|
19
|
+
left: event.x + TOOLTIP_OFFSET_X,
|
|
20
|
+
top: event.y + TOOLTIP_OFFSET_Y
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function onCellLinkLeave() {
|
|
24
|
+
tooltip.value = null;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
tooltip,
|
|
28
|
+
onCellLinkHover,
|
|
29
|
+
onCellLinkLeave
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { useCellLinkTooltip };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { popFloatImageMenu } from "./float-image-menu.js";
|
|
1
2
|
import { buildBodyMenus, buildColHeaderMenus, buildRowHeaderMenus, ensureContextMenuSelection, resolveRenderSize } from "./sheet-context-menu.js";
|
|
2
3
|
import { SheetGrid } from "infinitable/sheet";
|
|
3
4
|
import { onBeforeUnmount, onMounted, watch } from "vue";
|
|
@@ -68,7 +69,11 @@ function useSheetGrid(options) {
|
|
|
68
69
|
}) : info.kind === "col-header" ? buildColHeaderMenus(context, {
|
|
69
70
|
readonly: props.readonly,
|
|
70
71
|
col: info.col
|
|
71
|
-
}) : buildBodyMenus(context
|
|
72
|
+
}) : buildBodyMenus(context, {
|
|
73
|
+
readonly: props.readonly,
|
|
74
|
+
openHyperlinkPopup: options.openHyperlinkPopup,
|
|
75
|
+
openImagePreview: options.openImagePreview
|
|
76
|
+
});
|
|
72
77
|
contextmenu.pop({
|
|
73
78
|
mousePosition: {
|
|
74
79
|
x: info.x,
|
|
@@ -114,6 +119,7 @@ function useSheetGrid(options) {
|
|
|
114
119
|
scrollbar: props.scrollbar,
|
|
115
120
|
growOnScroll: props.growOnScroll,
|
|
116
121
|
theme: resolveCanvasThemeOverride(host),
|
|
122
|
+
openCellLinkOnClick: false,
|
|
117
123
|
onContextMenu: handleContextMenu,
|
|
118
124
|
onEditStart: (addr) => formulaBarRef.value?.mirrorGridEdit(addr),
|
|
119
125
|
onEditEnd: (addr) => formulaBarRef.value?.exitMirror(addr),
|
|
@@ -125,8 +131,34 @@ function useSheetGrid(options) {
|
|
|
125
131
|
const offStructureChange = sheet.on("structure-change", () => {
|
|
126
132
|
dirty = true;
|
|
127
133
|
});
|
|
134
|
+
const table = grid.getTable();
|
|
135
|
+
const offEngineEvents = [
|
|
136
|
+
table.onCellLinkHover((event) => options.onCellLinkHover?.(event)),
|
|
137
|
+
table.onCellLinkLeave((event) => options.onCellLinkLeave?.(event)),
|
|
138
|
+
table.onCellLinkClick((event) => options.onCellLinkClick?.(event)),
|
|
139
|
+
table.onImageLinkClick((event) => options.onImageLinkClick?.(event)),
|
|
140
|
+
table.floatObjects.onContextMenu((event) => {
|
|
141
|
+
const rect = el.getBoundingClientRect();
|
|
142
|
+
const payload = {
|
|
143
|
+
...event,
|
|
144
|
+
clientX: rect.left + event.x,
|
|
145
|
+
clientY: rect.top + event.y
|
|
146
|
+
};
|
|
147
|
+
options.onFloatContextMenu?.(payload);
|
|
148
|
+
popFloatImageMenu({
|
|
149
|
+
ctx: context,
|
|
150
|
+
event: payload,
|
|
151
|
+
handles: {
|
|
152
|
+
openImagePreview: options.openImagePreview,
|
|
153
|
+
openHyperlinkPopup: options.openHyperlinkPopup
|
|
154
|
+
},
|
|
155
|
+
readonly: props.readonly
|
|
156
|
+
});
|
|
157
|
+
})
|
|
158
|
+
];
|
|
128
159
|
const release = () => {
|
|
129
160
|
offStructureChange();
|
|
161
|
+
for (const off of offEngineEvents) off();
|
|
130
162
|
grid.release();
|
|
131
163
|
el.remove();
|
|
132
164
|
};
|
|
@@ -49,6 +49,7 @@ function useSheetState(props, emit, hooks) {
|
|
|
49
49
|
sheet.on("cell-change", bump),
|
|
50
50
|
sheet.on("merge-change", bump),
|
|
51
51
|
sheet.on("frozen-change", bump),
|
|
52
|
+
sheet.on("cell-image-change", (payload) => emit("cell-image-change", payload)),
|
|
52
53
|
sheet.on("content-reset", scheduleBump),
|
|
53
54
|
sheet.on("structure-change", hooks.rebuildGrid)
|
|
54
55
|
];
|
package/dist/tools/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CellAddress, CellData, CellInfo, CellRange, CellStyle, CellStylePatch, CellValue, FrozenState, HistoryState, ImageInput, ImageUpdateFields, SelectionState, SetCellValueItem, Sheet, SheetImage, Workbook } from "infinitable/sheet";
|
|
1
|
+
import { CellAddress, CellData, CellImagePayload, CellInfo, CellLinkPayload, CellRange, CellStyle, CellStylePatch, CellValue, FrozenState, HistoryState, ImageInput, ImageUpdateFields, SelectionState, SetCellValueItem, Sheet, SheetImage, Workbook } from "infinitable/sheet";
|
|
2
2
|
//#region src/tools/context.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* SheetContext:工具的唯一操作门面。
|
|
@@ -93,10 +93,24 @@ export interface SheetContext {
|
|
|
93
93
|
insertImage(input: ImageInput): string;
|
|
94
94
|
/** 删除浮动图片;不存在则无操作 */
|
|
95
95
|
removeImage(id: string): void;
|
|
96
|
-
/**
|
|
96
|
+
/** 更新浮动图片锚点/尺寸/文案/链接(link 传 null 清除);不存在或无变更则无操作 */
|
|
97
97
|
updateImage(id: string, patch: ImageUpdateFields): void;
|
|
98
98
|
/** 只读图片列表(快照副本) */
|
|
99
99
|
getImages(): readonly SheetImage[];
|
|
100
|
+
/** 写入单元格超链接;link 为 null 时清除该格链接(合并格解析锚点) */
|
|
101
|
+
setCellLink(addr: CellAddress, link: CellLinkPayload | null): void;
|
|
102
|
+
/** 读取单元格超链接载荷(副本);无链接返回 undefined(合并格解析锚点) */
|
|
103
|
+
getCellLink(addr: CellAddress): CellLinkPayload | undefined;
|
|
104
|
+
/** 清除单元格超链接;无链接则无操作(合并格解析锚点) */
|
|
105
|
+
clearCellLink(addr: CellAddress): void;
|
|
106
|
+
/** 插入(或覆盖)按格嵌入图;相同载荷视为无操作(合并格解析锚点) */
|
|
107
|
+
insertCellImage(addr: CellAddress, image: CellImagePayload): void;
|
|
108
|
+
/** 移除按格嵌入图;无图时无操作(合并格解析锚点) */
|
|
109
|
+
removeCellImage(addr: CellAddress): void;
|
|
110
|
+
/** 读取按格嵌入图载荷(副本);无图返回 undefined(合并格解析锚点) */
|
|
111
|
+
getCellImage(addr: CellAddress): CellImagePayload | undefined;
|
|
112
|
+
/** 该格是否有嵌入图(供右键菜单等判定;合并格解析锚点) */
|
|
113
|
+
hasCellImage(addr: CellAddress): boolean;
|
|
100
114
|
onSelectionChange(handler: (state: SelectionState) => void): () => void;
|
|
101
115
|
onHistoryChange(handler: (state: HistoryState) => void): () => void;
|
|
102
116
|
onFrozenChange(handler: (state: FrozenState) => void): () => void;
|
|
@@ -104,6 +118,10 @@ export interface SheetContext {
|
|
|
104
118
|
onImageChange(handler: (payload: {
|
|
105
119
|
id?: string;
|
|
106
120
|
}) => void): () => void;
|
|
121
|
+
/** 按格嵌入图变化(单格带 addr;结构平移/整表替换时缺省) */
|
|
122
|
+
onCellImageChange(handler: (payload: {
|
|
123
|
+
addr?: CellAddress;
|
|
124
|
+
}) => void): () => void;
|
|
107
125
|
}
|
|
108
126
|
/** createSheetContext 可选配置 */
|
|
109
127
|
export interface SheetContextOptions {
|
package/dist/tools/context.js
CHANGED
|
@@ -103,6 +103,13 @@ function createSheetContext(resolveSheet, workbook, options) {
|
|
|
103
103
|
removeImage: (id) => sheet().removeImage(id),
|
|
104
104
|
updateImage: (id, patch) => sheet().updateImage(id, patch),
|
|
105
105
|
getImages: () => sheet().getImages(),
|
|
106
|
+
setCellLink: (addr, link) => sheet().setCellLink(addr, link),
|
|
107
|
+
getCellLink: (addr) => sheet().getCellLink(addr),
|
|
108
|
+
clearCellLink: (addr) => sheet().clearCellLink(addr),
|
|
109
|
+
insertCellImage: (addr, image) => sheet().insertCellImage(addr, image),
|
|
110
|
+
removeCellImage: (addr) => sheet().removeCellImage(addr),
|
|
111
|
+
getCellImage: (addr) => sheet().getCellImage(addr),
|
|
112
|
+
hasCellImage: (addr) => sheet().hasCellImage(addr),
|
|
106
113
|
beginTransaction: () => sheet().beginTransaction(),
|
|
107
114
|
commit: () => sheet().commit(),
|
|
108
115
|
rollback: () => sheet().rollback(),
|
|
@@ -117,7 +124,8 @@ function createSheetContext(resolveSheet, workbook, options) {
|
|
|
117
124
|
onSelectionChange: (handler) => sheet().on("selection-change", handler),
|
|
118
125
|
onHistoryChange: (handler) => sheet().on("history-change", handler),
|
|
119
126
|
onFrozenChange: (handler) => sheet().on("frozen-change", handler),
|
|
120
|
-
onImageChange: (handler) => sheet().on("image-change", handler)
|
|
127
|
+
onImageChange: (handler) => sheet().on("image-change", handler),
|
|
128
|
+
onCellImageChange: (handler) => sheet().on("cell-image-change", handler)
|
|
121
129
|
};
|
|
122
130
|
}
|
|
123
131
|
//#endregion
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SheetEmits, SheetExposed, SheetProps, _SheetExposed } from "./sheet.js";
|
|
2
|
-
export { SheetEmits, SheetExposed, SheetProps, _SheetExposed };
|
|
1
|
+
import { FloatContextMenuPayload, SheetEmits, SheetExposed, SheetProps, _SheetExposed } from "./sheet.js";
|
|
2
|
+
export { FloatContextMenuPayload, SheetEmits, SheetExposed, SheetProps, _SheetExposed };
|
package/dist/types/sheet.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { SheetContext } from "../tools/context.js";
|
|
2
|
-
import { ResolveCellRenderer, ResolveCellStyleHook, ResolveDisplayValue, Sheet, SheetGrid, SheetGridEditorsOptions, SheetGridHeaderOptions, Workbook } from "infinitable/sheet";
|
|
2
|
+
import { CellAddress, ResolveCellRenderer, ResolveCellStyleHook, ResolveDisplayValue, Sheet, SheetGrid, SheetGridEditorsOptions, SheetGridHeaderOptions, Workbook } from "infinitable/sheet";
|
|
3
3
|
import { ComputedRef } from "vue";
|
|
4
4
|
import { DeconstructValue } from "@veltra/utils";
|
|
5
|
+
import { CellLinkClickEvent, CellLinkHoverEvent, CellLinkLeaveEvent, FloatContextMenuEvent, ImageLinkClickEvent } from "infinitable";
|
|
5
6
|
//#region src/types/sheet.d.ts
|
|
6
7
|
/** 电子表格组件属性 */
|
|
7
8
|
export interface SheetProps {
|
|
@@ -66,6 +67,24 @@ export interface SheetProps {
|
|
|
66
67
|
*/
|
|
67
68
|
growOnScroll?: boolean;
|
|
68
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* 浮动图右键事件载荷:引擎 `FloatContextMenuEvent` 关键字段 + 页面坐标。
|
|
72
|
+
*
|
|
73
|
+
* 右键命中浮动图时引擎不穿透到单元格右键(body 菜单不弹),宿主经
|
|
74
|
+
* `float-context-menu` 自行弹浮动图菜单(预览 / 超链接 / 删除等)。
|
|
75
|
+
*/
|
|
76
|
+
export interface FloatContextMenuPayload {
|
|
77
|
+
/** 命中的浮动对象 id */
|
|
78
|
+
id: string;
|
|
79
|
+
/** 层坐标(CSS 像素,相对 grid 实例容器) */
|
|
80
|
+
x: number;
|
|
81
|
+
y: number;
|
|
82
|
+
/** 页面视口坐标(层坐标 + grid 容器偏移;与 body 右键菜单同口径,供菜单定位) */
|
|
83
|
+
clientX: number;
|
|
84
|
+
clientY: number;
|
|
85
|
+
/** 引擎原始右键事件(最小 DOM 事件结构) */
|
|
86
|
+
originalEvent: FloatContextMenuEvent['originalEvent'];
|
|
87
|
+
}
|
|
69
88
|
export interface SheetEmits {
|
|
70
89
|
/** 激活 sheet 切换(点击 tab 或宿主调用 workbook.activateSheet) */
|
|
71
90
|
(name: 'active-sheet-change', payload: {
|
|
@@ -77,6 +96,37 @@ export interface SheetEmits {
|
|
|
77
96
|
col: number;
|
|
78
97
|
width: number;
|
|
79
98
|
}): void;
|
|
99
|
+
/**
|
|
100
|
+
* 单元格超链接悬停(引擎 `CellLinkHoverEvent` 形态:格坐标 + URL/显示文本 +
|
|
101
|
+
* 落点层坐标);tooltip 由宿主渲染,ultra-ui 不接管
|
|
102
|
+
*/
|
|
103
|
+
(name: 'cell-link-hover', payload: CellLinkHoverEvent): void;
|
|
104
|
+
/** 单元格超链接离开(引擎 `CellLinkLeaveEvent` 形态:刚离开的链接格坐标) */
|
|
105
|
+
(name: 'cell-link-leave', payload: CellLinkLeaveEvent): void;
|
|
106
|
+
/**
|
|
107
|
+
* 单元格超链接单击(引擎 `CellLinkClickEvent` 形态:真实指针 down+up 命中
|
|
108
|
+
* 同一链接格;框选拖拽/键盘选中不触发)。组件已接管打开:emit 后直接新标签
|
|
109
|
+
* 打开(引擎 `openCellLinkOnClick` 已关闭)
|
|
110
|
+
*/
|
|
111
|
+
(name: 'cell-link-click', payload: CellLinkClickEvent): void;
|
|
112
|
+
/**
|
|
113
|
+
* 图片链接单击(引擎 `ImageLinkClickEvent`,`kind` 区分 `cell` 嵌入图 /
|
|
114
|
+
* `float` 浮动图)。组件已接管打开:emit 后弹确认框,确认才新标签打开
|
|
115
|
+
* (防误触跳转;引擎 `openCellLinkOnClick` 已关闭)
|
|
116
|
+
*/
|
|
117
|
+
(name: 'image-link-click', payload: ImageLinkClickEvent): void;
|
|
118
|
+
/**
|
|
119
|
+
* 按格嵌入图变化(`{ addr?: CellAddress }` 定向语义:单格变更带 addr,
|
|
120
|
+
* 结构平移/整表替换时缺省);仅当前活动 sheet 的事件被透传
|
|
121
|
+
*/
|
|
122
|
+
(name: 'cell-image-change', payload: {
|
|
123
|
+
addr?: CellAddress;
|
|
124
|
+
}): void;
|
|
125
|
+
/**
|
|
126
|
+
* 浮动图右键(载荷见 {@link FloatContextMenuPayload};右键不穿透到
|
|
127
|
+
* 单元格 body 菜单,宿主据此弹浮动图独立菜单)
|
|
128
|
+
*/
|
|
129
|
+
(name: 'float-context-menu', payload: FloatContextMenuPayload): void;
|
|
80
130
|
}
|
|
81
131
|
/** 在组件内部引用 */
|
|
82
132
|
export interface _SheetExposed {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veltra/sheet",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.1",
|
|
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"
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"infinitable": "^0.1.
|
|
37
|
+
"infinitable": "^0.1.8"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@cat-kit/core": ">=1.2.1",
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { Sheet } from 'infinitable/sheet'
|
|
2
|
+
import { describe, expect, it } from 'vite-plus/test'
|
|
3
|
+
|
|
4
|
+
import { createSheetContext } from '../../../tools/context'
|
|
5
|
+
import { buildFloatImageMenus, embedFloatImageToCell } from '../float-image-menu'
|
|
6
|
+
import type { ImagePreviewSource } from '../popup-helpers'
|
|
7
|
+
|
|
8
|
+
/** 插入一张浮动图(data 字节 + 可选 src/link),返回 id */
|
|
9
|
+
function insertFloatImage(sheet: Sheet, input: { src?: string; link?: string } = {}): string {
|
|
10
|
+
return sheet.insertImage({
|
|
11
|
+
data: new Uint8Array([1, 2, 3]),
|
|
12
|
+
type: 'png',
|
|
13
|
+
anchor: { from: { row: 0, col: 0 } },
|
|
14
|
+
src: input.src,
|
|
15
|
+
link: input.link
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** 句柄 spy:记录预览源与弹窗调用(mode + 回填 + 目标) */
|
|
20
|
+
function handlesSpy() {
|
|
21
|
+
const previews: ImagePreviewSource[] = []
|
|
22
|
+
const popups: Array<{
|
|
23
|
+
mode: 'image'
|
|
24
|
+
initial?: { url: string }
|
|
25
|
+
target?: { kind: 'float'; id: string }
|
|
26
|
+
}> = []
|
|
27
|
+
return {
|
|
28
|
+
previews,
|
|
29
|
+
popups,
|
|
30
|
+
handles: {
|
|
31
|
+
openImagePreview: (source: ImagePreviewSource): void => {
|
|
32
|
+
previews.push(source)
|
|
33
|
+
},
|
|
34
|
+
openHyperlinkPopup: (
|
|
35
|
+
mode: 'image',
|
|
36
|
+
initial?: { url: string },
|
|
37
|
+
target?: { kind: 'float'; id: string }
|
|
38
|
+
): void => {
|
|
39
|
+
popups.push({ mode, initial, target })
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe('buildFloatImageMenus(浮动图右键独立菜单)', () => {
|
|
46
|
+
it('无链接浮动图:预览 / 设置超链接 / 嵌入单元格 / 删除图片(无取消超链接);预览源 src 优先', () => {
|
|
47
|
+
const sheet = new Sheet()
|
|
48
|
+
const ctx = createSheetContext(sheet)
|
|
49
|
+
const id = insertFloatImage(sheet, { src: 'https://example.com/a.png' })
|
|
50
|
+
const spy = handlesSpy()
|
|
51
|
+
|
|
52
|
+
const menus = buildFloatImageMenus(ctx, id, spy.handles)
|
|
53
|
+
expect(menus.map((m) => m.label)).toEqual(['预览', '设置超链接', '嵌入单元格', '删除图片'])
|
|
54
|
+
|
|
55
|
+
menus.find((m) => m.label === '预览')!.callback!()
|
|
56
|
+
expect(spy.previews).toEqual([{ src: 'https://example.com/a.png' }])
|
|
57
|
+
|
|
58
|
+
menus.find((m) => m.label === '设置超链接')!.callback!()
|
|
59
|
+
expect(spy.popups).toEqual([
|
|
60
|
+
{ mode: 'image', initial: undefined, target: { kind: 'float', id } }
|
|
61
|
+
])
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('data 字节图预览源:字节 + 引擎 type 映射 MIME', () => {
|
|
65
|
+
const sheet = new Sheet()
|
|
66
|
+
const ctx = createSheetContext(sheet)
|
|
67
|
+
const id = insertFloatImage(sheet)
|
|
68
|
+
const spy = handlesSpy()
|
|
69
|
+
|
|
70
|
+
buildFloatImageMenus(ctx, id, spy.handles).find((m) => m.label === '预览')!.callback!()
|
|
71
|
+
expect(spy.previews).toEqual([{ data: new Uint8Array([1, 2, 3]), mime: 'image/png' }])
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('有链接浮动图:含取消超链接;设置超链接回填原 url;取消清 link 且 undo 还原', () => {
|
|
75
|
+
const sheet = new Sheet()
|
|
76
|
+
const ctx = createSheetContext(sheet)
|
|
77
|
+
const id = insertFloatImage(sheet, { link: 'https://example.com' })
|
|
78
|
+
const spy = handlesSpy()
|
|
79
|
+
|
|
80
|
+
const menus = buildFloatImageMenus(ctx, id, spy.handles)
|
|
81
|
+
expect(menus.map((m) => m.label)).toEqual([
|
|
82
|
+
'预览',
|
|
83
|
+
'设置超链接',
|
|
84
|
+
'取消超链接',
|
|
85
|
+
'嵌入单元格',
|
|
86
|
+
'删除图片'
|
|
87
|
+
])
|
|
88
|
+
|
|
89
|
+
menus.find((m) => m.label === '设置超链接')!.callback!()
|
|
90
|
+
expect(spy.popups).toEqual([
|
|
91
|
+
{ mode: 'image', initial: { url: 'https://example.com' }, target: { kind: 'float', id } }
|
|
92
|
+
])
|
|
93
|
+
|
|
94
|
+
menus.find((m) => m.label === '取消超链接')!.callback!()
|
|
95
|
+
expect(ctx.getImages().find((img) => img.id === id)?.link).toBeUndefined()
|
|
96
|
+
expect(ctx.undo()).toBe(true)
|
|
97
|
+
expect(ctx.getImages().find((img) => img.id === id)?.link).toBe('https://example.com')
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('删除图片:getImages 不含该 id 且 undo 还原', () => {
|
|
101
|
+
const sheet = new Sheet()
|
|
102
|
+
const ctx = createSheetContext(sheet)
|
|
103
|
+
const id = insertFloatImage(sheet)
|
|
104
|
+
|
|
105
|
+
buildFloatImageMenus(ctx, id, handlesSpy().handles).find((m) => m.label === '删除图片')!
|
|
106
|
+
.callback!()
|
|
107
|
+
expect(ctx.getImages().some((img) => img.id === id)).toBe(false)
|
|
108
|
+
expect(ctx.undo()).toBe(true)
|
|
109
|
+
expect(ctx.getImages().some((img) => img.id === id)).toBe(true)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('id 不存在(并发删除):返回空菜单', () => {
|
|
113
|
+
const sheet = new Sheet()
|
|
114
|
+
const ctx = createSheetContext(sheet)
|
|
115
|
+
expect(buildFloatImageMenus(ctx, 'missing', handlesSpy().handles)).toEqual([])
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('嵌入单元格:浮动图转锚点格嵌入图(src 优先 / data 字节两形态,link 随迁),单 undo 还原', () => {
|
|
119
|
+
const sheet = new Sheet()
|
|
120
|
+
const ctx = createSheetContext(sheet)
|
|
121
|
+
const addr = { row: 2, col: 3 }
|
|
122
|
+
const id = sheet.insertImage({
|
|
123
|
+
data: new Uint8Array([1, 2, 3]),
|
|
124
|
+
type: 'png',
|
|
125
|
+
anchor: { from: addr },
|
|
126
|
+
src: 'https://example.com/a.png',
|
|
127
|
+
link: 'https://example.com'
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
embedFloatImageToCell(ctx, id)
|
|
131
|
+
// 浮动图消失,锚点格出现同源嵌入图(src 优先于字节),link 随迁
|
|
132
|
+
expect(ctx.getImages().some((img) => img.id === id)).toBe(false)
|
|
133
|
+
expect(ctx.getCellImage(addr)).toEqual({
|
|
134
|
+
src: 'https://example.com/a.png',
|
|
135
|
+
type: 'png',
|
|
136
|
+
link: 'https://example.com'
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
// 事务合并:一次 undo 同时还原浮动图、清掉嵌入图
|
|
140
|
+
expect(ctx.undo()).toBe(true)
|
|
141
|
+
expect(ctx.getImages().some((img) => img.id === id)).toBe(true)
|
|
142
|
+
expect(ctx.hasCellImage(addr)).toBe(false)
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
it('嵌入单元格:data 字节图迁字节;目标格已有嵌入图则覆盖;id 不存在无操作', () => {
|
|
146
|
+
const sheet = new Sheet()
|
|
147
|
+
const ctx = createSheetContext(sheet)
|
|
148
|
+
const addr = { row: 1, col: 1 }
|
|
149
|
+
const id = sheet.insertImage({
|
|
150
|
+
data: new Uint8Array([1, 2, 3]),
|
|
151
|
+
type: 'png',
|
|
152
|
+
anchor: { from: addr }
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
embedFloatImageToCell(ctx, id)
|
|
156
|
+
expect(ctx.getCellImage(addr)).toEqual({ data: new Uint8Array([1, 2, 3]), type: 'png' })
|
|
157
|
+
|
|
158
|
+
// 目标格已有嵌入图 → 覆盖(undo 一次仍回到转换前)
|
|
159
|
+
const other = insertFloatImage(sheet)
|
|
160
|
+
sheet.updateImage(other, { anchor: { from: { row: 5, col: 5 } } })
|
|
161
|
+
embedFloatImageToCell(ctx, other)
|
|
162
|
+
expect(ctx.hasCellImage({ row: 5, col: 5 })).toBe(true)
|
|
163
|
+
expect(ctx.getCellImage({ row: 5, col: 5 })).toEqual({
|
|
164
|
+
data: new Uint8Array([1, 2, 3]),
|
|
165
|
+
type: 'png'
|
|
166
|
+
})
|
|
167
|
+
expect(ctx.undo()).toBe(true)
|
|
168
|
+
expect(ctx.hasCellImage({ row: 5, col: 5 })).toBe(false)
|
|
169
|
+
expect(ctx.getImages().some((img) => img.id === other)).toBe(true)
|
|
170
|
+
|
|
171
|
+
// id 不存在(并发删除):无操作
|
|
172
|
+
embedFloatImageToCell(ctx, 'missing')
|
|
173
|
+
expect(ctx.getImages().some((img) => img.id === other)).toBe(true)
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it('readonly:设置/取消/删除/嵌入单元格禁用、预览可用;句柄缺省:预览/设置禁用', () => {
|
|
177
|
+
const sheet = new Sheet()
|
|
178
|
+
const ctx = createSheetContext(sheet)
|
|
179
|
+
const id = insertFloatImage(sheet, { link: 'https://example.com' })
|
|
180
|
+
|
|
181
|
+
const readonly = buildFloatImageMenus(ctx, id, handlesSpy().handles, { readonly: true })
|
|
182
|
+
expect(readonly.find((m) => m.label === '预览')?.disabled).toBeFalsy()
|
|
183
|
+
expect(readonly.find((m) => m.label === '设置超链接')?.disabled).toBe(true)
|
|
184
|
+
expect(readonly.find((m) => m.label === '取消超链接')?.disabled).toBe(true)
|
|
185
|
+
expect(readonly.find((m) => m.label === '嵌入单元格')?.disabled).toBe(true)
|
|
186
|
+
expect(readonly.find((m) => m.label === '删除图片')?.disabled).toBe(true)
|
|
187
|
+
|
|
188
|
+
const noHandles = buildFloatImageMenus(ctx, id)
|
|
189
|
+
expect(noHandles.find((m) => m.label === '预览')?.disabled).toBe(true)
|
|
190
|
+
expect(noHandles.find((m) => m.label === '设置超链接')?.disabled).toBe(true)
|
|
191
|
+
// 取消/嵌入/删除只依赖 ctx,句柄缺省仍可用
|
|
192
|
+
expect(noHandles.find((m) => m.label === '取消超链接')?.disabled).toBeFalsy()
|
|
193
|
+
expect(noHandles.find((m) => m.label === '嵌入单元格')?.disabled).toBeFalsy()
|
|
194
|
+
expect(noHandles.find((m) => m.label === '删除图片')?.disabled).toBeFalsy()
|
|
195
|
+
})
|
|
196
|
+
})
|