@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
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { imageLinkInitial, imagePreviewSource } from "./popup-helpers.js";
|
|
2
|
+
import { contextmenu } from "@veltra/desktop";
|
|
3
|
+
//#region src/components/sheet/float-image-menu.ts
|
|
4
|
+
/**
|
|
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
|
+
* 调用方不弹菜单。
|
|
32
|
+
*/
|
|
33
|
+
function buildFloatImageMenus(ctx, id, handles, options) {
|
|
34
|
+
const image = ctx.getImages().find((item) => item.id === id);
|
|
35
|
+
if (!image) return [];
|
|
36
|
+
const readonly = options?.readonly === true;
|
|
37
|
+
const target = {
|
|
38
|
+
kind: "float",
|
|
39
|
+
id
|
|
40
|
+
};
|
|
41
|
+
return [
|
|
42
|
+
{
|
|
43
|
+
label: "预览",
|
|
44
|
+
disabled: !handles?.openImagePreview,
|
|
45
|
+
callback: () => handles?.openImagePreview?.(imagePreviewSource(image))
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
label: "设置超链接",
|
|
49
|
+
disabled: readonly || !handles?.openHyperlinkPopup,
|
|
50
|
+
callback: () => handles?.openHyperlinkPopup?.("image", imageLinkInitial(image.link), target)
|
|
51
|
+
},
|
|
52
|
+
...image.link ? [{
|
|
53
|
+
label: "取消超链接",
|
|
54
|
+
disabled: readonly,
|
|
55
|
+
callback: () => ctx.updateImage(id, { link: null })
|
|
56
|
+
}] : [],
|
|
57
|
+
{
|
|
58
|
+
label: "嵌入单元格",
|
|
59
|
+
disabled: readonly,
|
|
60
|
+
callback: () => embedFloatImageToCell(ctx, id)
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
label: "删除图片",
|
|
64
|
+
disabled: readonly,
|
|
65
|
+
callback: () => ctx.removeImage(id)
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 消费引擎浮动图右键事件:按命中浮动图 link 状态构建独立菜单并经 `contextmenu.pop`
|
|
71
|
+
* 弹出(viewport 坐标定位,与 body 右键菜单同口径)。右键不穿透到格菜单由引擎
|
|
72
|
+
* 保证(floatObjects 命中即不派发单元格 contextmenu),此处只弹浮动图菜单。
|
|
73
|
+
*/
|
|
74
|
+
function popFloatImageMenu(options) {
|
|
75
|
+
const menus = buildFloatImageMenus(options.ctx, options.event.id, options.handles, { readonly: options.readonly });
|
|
76
|
+
if (menus.length === 0) return;
|
|
77
|
+
contextmenu.pop({
|
|
78
|
+
mousePosition: {
|
|
79
|
+
x: options.event.clientX,
|
|
80
|
+
y: options.event.clientY
|
|
81
|
+
},
|
|
82
|
+
width: "max-content",
|
|
83
|
+
menus
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
export { buildFloatImageMenus, embedFloatImageToCell, popFloatImageMenu };
|
|
@@ -87,9 +87,9 @@ function insertImageFromUrl(ctx, url) {
|
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* 拉起系统文件选择框(右键菜单用;不用 UFilePicker——无编程式打开 API)。
|
|
90
|
-
*
|
|
90
|
+
* 选中文件后交给 onPick;取消选择时清理节点。
|
|
91
91
|
*/
|
|
92
|
-
function
|
|
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)
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { BORDER_STYLE_WIDTH } from "infinitable/sheet";
|
|
1
|
+
import { BORDER_STYLE_WIDTH, IMAGE_MIME } from "infinitable/sheet";
|
|
2
2
|
//#region src/components/sheet/popup-helpers.ts
|
|
3
3
|
/** 当前选区(ranges[0] 优先;无区域选区时用活动格单格) */
|
|
4
4
|
function currentRange(context) {
|
|
@@ -8,6 +8,22 @@ function currentRange(context) {
|
|
|
8
8
|
end: activeCell
|
|
9
9
|
} : null);
|
|
10
10
|
}
|
|
11
|
+
/** 图片链接 → 弹窗回填载荷(无链接 → undefined 插入态;浮动图与嵌入图共用) */
|
|
12
|
+
function imageLinkInitial(link) {
|
|
13
|
+
return link ? { url: link } : void 0;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 图片载荷 → 预览源归一:src 优先(URL 来源直接引用);否则取字节 + 模型 type
|
|
17
|
+
* 映射 MIME(type 缺省按 png,同引擎嵌入图渲染约定)。浮动图(type 必填)与
|
|
18
|
+
* 嵌入图(type 可选)共用。
|
|
19
|
+
*/
|
|
20
|
+
function imagePreviewSource(payload) {
|
|
21
|
+
if (payload.src) return { src: payload.src };
|
|
22
|
+
return {
|
|
23
|
+
data: payload.data,
|
|
24
|
+
mime: IMAGE_MIME[payload.type ?? "png"]
|
|
25
|
+
};
|
|
26
|
+
}
|
|
11
27
|
const BORDER_LINE_STYLES = [
|
|
12
28
|
"thin",
|
|
13
29
|
"medium",
|
|
@@ -70,4 +86,4 @@ function lineSwatchStyle(line) {
|
|
|
70
86
|
return { borderBottom: `${BORDER_STYLE_WIDTH[line]}px ${dash} #000` };
|
|
71
87
|
}
|
|
72
88
|
//#endregion
|
|
73
|
-
export { BORDER_LINE_STYLES, BORDER_LINE_TITLES, BORDER_PRESETS, currentRange, lineSwatchStyle };
|
|
89
|
+
export { BORDER_LINE_STYLES, BORDER_LINE_TITLES, BORDER_PRESETS, currentRange, imageLinkInitial, imagePreviewSource, lineSwatchStyle };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Teleport, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, openBlock, ref, toDisplayString, unref, useId, withCtx, withKeys, withModifiers } from "vue";
|
|
2
|
+
import { UButton, UInput, message } from "@veltra/desktop";
|
|
3
|
+
import { bem, zIndex } from "@veltra/utils";
|
|
4
|
+
//#region src/components/sheet/popups/hyperlink-popup.vue
|
|
5
|
+
const _hoisted_1 = ["for"];
|
|
6
|
+
const _hoisted_2 = ["for"];
|
|
7
|
+
const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
8
|
+
name: "USheetHyperlinkPopup",
|
|
9
|
+
__name: "hyperlink-popup",
|
|
10
|
+
props: {
|
|
11
|
+
mode: {},
|
|
12
|
+
initial: {}
|
|
13
|
+
},
|
|
14
|
+
emits: ["confirm", "close"],
|
|
15
|
+
setup(__props, { emit: __emit }) {
|
|
16
|
+
/**
|
|
17
|
+
* 超链接配置弹窗(右键菜单拉起,无工具栏锚点——不走 UDropdown 工具面板链路,
|
|
18
|
+
* 自绘遮罩 + 居中面板,对齐 loading-mask 自绘先例):
|
|
19
|
+
* - 地址必填:空提交拦截并 message.error,弹窗不关
|
|
20
|
+
* - 显示文本可留空:留空不写入 text(单元格沿用自身内容作为显示)
|
|
21
|
+
* - mode="cell" 两字段;mode="image" 仅地址(图片超链接复用,写入目标由宿主收口)
|
|
22
|
+
* - 确认仅 emit confirm;关闭(取消/Esc/遮罩点击)emit close,均由宿主收口
|
|
23
|
+
*/
|
|
24
|
+
const props = __props;
|
|
25
|
+
const emit = __emit;
|
|
26
|
+
const cls = bem("sheet");
|
|
27
|
+
/** 字段输入 id(useId:多实例同开不撞固定 id) */
|
|
28
|
+
const urlId = useId();
|
|
29
|
+
const textId = useId();
|
|
30
|
+
const url = ref(props.initial?.url ?? "");
|
|
31
|
+
const text = ref(props.initial?.text ?? "");
|
|
32
|
+
/** 遮罩层级:挂载时取全局递增 z-index(与 desktop 弹层互不压盖) */
|
|
33
|
+
const maskZIndex = zIndex();
|
|
34
|
+
const title = computed(() => {
|
|
35
|
+
if (props.mode === "image") return "设置图片超链接";
|
|
36
|
+
return props.initial ? "编辑超链接" : "插入超链接";
|
|
37
|
+
});
|
|
38
|
+
function handleConfirm() {
|
|
39
|
+
const nextUrl = url.value.trim();
|
|
40
|
+
if (!nextUrl) {
|
|
41
|
+
message.error("请输入链接地址");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const nextText = text.value.trim();
|
|
45
|
+
emit("confirm", nextText ? {
|
|
46
|
+
url: nextUrl,
|
|
47
|
+
text: nextText
|
|
48
|
+
} : { url: nextUrl });
|
|
49
|
+
}
|
|
50
|
+
function handleCancel() {
|
|
51
|
+
emit("close");
|
|
52
|
+
}
|
|
53
|
+
/** Esc 关闭(window 级监听:弹窗内输入框未聚焦时同样生效) */
|
|
54
|
+
function onKeydown(event) {
|
|
55
|
+
if (event.key === "Escape") handleCancel();
|
|
56
|
+
}
|
|
57
|
+
onMounted(() => {
|
|
58
|
+
window.addEventListener("keydown", onKeydown);
|
|
59
|
+
});
|
|
60
|
+
onBeforeUnmount(() => {
|
|
61
|
+
window.removeEventListener("keydown", onKeydown);
|
|
62
|
+
});
|
|
63
|
+
return (_ctx, _cache) => {
|
|
64
|
+
return openBlock(), createBlock(Teleport, { to: "body" }, [createElementVNode("div", {
|
|
65
|
+
class: normalizeClass(unref(cls).e("link-dialog-mask")),
|
|
66
|
+
style: normalizeStyle({ zIndex: unref(maskZIndex) }),
|
|
67
|
+
onMousedown: withModifiers(handleCancel, ["self"])
|
|
68
|
+
}, [createElementVNode("div", {
|
|
69
|
+
class: normalizeClass(unref(cls).e("link-dialog")),
|
|
70
|
+
role: "dialog",
|
|
71
|
+
"aria-modal": "true"
|
|
72
|
+
}, [
|
|
73
|
+
createElementVNode("div", { class: normalizeClass(unref(cls).e("link-dialog-title")) }, toDisplayString(title.value), 3),
|
|
74
|
+
createElementVNode("div", { class: normalizeClass(unref(cls).e("link-dialog-body")) }, [createElementVNode("div", { class: normalizeClass(unref(cls).e("popup-row")) }, [createElementVNode("label", {
|
|
75
|
+
class: normalizeClass(unref(cls).e("popup-label")),
|
|
76
|
+
for: unref(urlId)
|
|
77
|
+
}, "地址", 10, _hoisted_1), createVNode(unref(UInput), {
|
|
78
|
+
id: unref(urlId),
|
|
79
|
+
modelValue: url.value,
|
|
80
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => url.value = $event),
|
|
81
|
+
class: normalizeClass(unref(cls).e("link-dialog-input")),
|
|
82
|
+
placeholder: "https://example.com",
|
|
83
|
+
size: "small",
|
|
84
|
+
onKeydown: withKeys(handleConfirm, ["enter"])
|
|
85
|
+
}, null, 8, [
|
|
86
|
+
"id",
|
|
87
|
+
"modelValue",
|
|
88
|
+
"class"
|
|
89
|
+
])], 2), __props.mode === "cell" ? (openBlock(), createElementBlock("div", {
|
|
90
|
+
key: 0,
|
|
91
|
+
class: normalizeClass(unref(cls).e("popup-row"))
|
|
92
|
+
}, [createElementVNode("label", {
|
|
93
|
+
class: normalizeClass(unref(cls).e("popup-label")),
|
|
94
|
+
for: unref(textId)
|
|
95
|
+
}, "显示文本", 10, _hoisted_2), createVNode(unref(UInput), {
|
|
96
|
+
id: unref(textId),
|
|
97
|
+
modelValue: text.value,
|
|
98
|
+
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => text.value = $event),
|
|
99
|
+
class: normalizeClass(unref(cls).e("link-dialog-input")),
|
|
100
|
+
placeholder: "留空沿用单元格内容",
|
|
101
|
+
size: "small",
|
|
102
|
+
onKeydown: withKeys(handleConfirm, ["enter"])
|
|
103
|
+
}, null, 8, [
|
|
104
|
+
"id",
|
|
105
|
+
"modelValue",
|
|
106
|
+
"class"
|
|
107
|
+
])], 2)) : createCommentVNode("v-if", true)], 2),
|
|
108
|
+
createElementVNode("div", { class: normalizeClass(unref(cls).e("link-dialog-footer")) }, [createVNode(unref(UButton), {
|
|
109
|
+
size: "small",
|
|
110
|
+
onClick: handleCancel
|
|
111
|
+
}, {
|
|
112
|
+
default: withCtx(() => [..._cache[2] || (_cache[2] = [createTextVNode("取消", -1)])]),
|
|
113
|
+
_: 1
|
|
114
|
+
}), createVNode(unref(UButton), {
|
|
115
|
+
size: "small",
|
|
116
|
+
type: "primary",
|
|
117
|
+
onClick: handleConfirm
|
|
118
|
+
}, {
|
|
119
|
+
default: withCtx(() => [..._cache[3] || (_cache[3] = [createTextVNode("确定", -1)])]),
|
|
120
|
+
_: 1
|
|
121
|
+
})], 2)
|
|
122
|
+
], 2)], 38)]);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
//#endregion
|
|
127
|
+
export { _sfc_main as default };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defaultToolRegistry } from "../../tools/registry.js";
|
|
2
|
-
import {
|
|
2
|
+
import { imageLinkInitial, imagePreviewSource } from "./popup-helpers.js";
|
|
3
|
+
import { pickAndEmbedCellImage, pickAndInsertImage } from "./insert-image.js";
|
|
3
4
|
import _sfc_main from "./insert-count-menu-item.js";
|
|
4
5
|
import { createRange } from "infinitable/sheet";
|
|
5
6
|
import { defineComponent, h } from "vue";
|
|
@@ -211,11 +212,121 @@ function buildColHeaderMenus(ctx, options) {
|
|
|
211
212
|
function applyNumFmtToSelection(ctx, numFmt) {
|
|
212
213
|
for (const range of ctx.getSelection().ranges) ctx.applyStyle(range, { numFmt });
|
|
213
214
|
}
|
|
214
|
-
/**
|
|
215
|
-
|
|
215
|
+
/**
|
|
216
|
+
* body 菜单超链接项:按目标格链接状态出项——
|
|
217
|
+
* 无链接「插入超链接」;有链接「编辑超链接」(回填原 url/text)+「取消超链接」。
|
|
218
|
+
* 取消直走 clearCellLink(可 undo);插入/编辑经注入句柄拉起弹窗。
|
|
219
|
+
*/
|
|
220
|
+
function cellLinkMenuItems(ctx, active, options) {
|
|
221
|
+
if (!active) return [{
|
|
222
|
+
label: "插入超链接",
|
|
223
|
+
disabled: true
|
|
224
|
+
}];
|
|
225
|
+
const handle = options?.openHyperlinkPopup;
|
|
226
|
+
const disabled = options?.readonly === true || !handle;
|
|
227
|
+
const link = ctx.getCellLink(active);
|
|
228
|
+
if (!link) return [{
|
|
229
|
+
label: "插入超链接",
|
|
230
|
+
disabled,
|
|
231
|
+
callback: () => handle?.("cell")
|
|
232
|
+
}];
|
|
233
|
+
return [{
|
|
234
|
+
label: "编辑超链接",
|
|
235
|
+
disabled,
|
|
236
|
+
callback: () => handle?.("cell", link)
|
|
237
|
+
}, {
|
|
238
|
+
label: "取消超链接",
|
|
239
|
+
disabled: options?.readonly === true,
|
|
240
|
+
callback: () => ctx.clearCellLink(active)
|
|
241
|
+
}];
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
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)。
|
|
277
|
+
*/
|
|
278
|
+
function cellImageMenuItems(ctx, active, options) {
|
|
279
|
+
if (!active || !ctx.hasCellImage(active)) return [];
|
|
280
|
+
const payload = ctx.getCellImage(active);
|
|
281
|
+
if (!payload) return [];
|
|
282
|
+
const handle = options?.openHyperlinkPopup;
|
|
283
|
+
const readonly = options?.readonly === true;
|
|
284
|
+
const items = [{
|
|
285
|
+
label: "预览",
|
|
286
|
+
disabled: !options?.openImagePreview,
|
|
287
|
+
callback: () => options?.openImagePreview?.(imagePreviewSource(payload))
|
|
288
|
+
}, {
|
|
289
|
+
label: "图片超链接",
|
|
290
|
+
disabled: readonly || !handle,
|
|
291
|
+
callback: () => handle?.("image", imageLinkInitial(payload.link), {
|
|
292
|
+
kind: "cell",
|
|
293
|
+
addr: active
|
|
294
|
+
})
|
|
295
|
+
}];
|
|
296
|
+
if (payload.link) items.push({
|
|
297
|
+
label: "取消超链接",
|
|
298
|
+
disabled: readonly,
|
|
299
|
+
callback: () => ctx.insertCellImage(active, {
|
|
300
|
+
...payload,
|
|
301
|
+
link: void 0
|
|
302
|
+
})
|
|
303
|
+
});
|
|
304
|
+
items.push({
|
|
305
|
+
label: "转为浮动图片",
|
|
306
|
+
disabled: readonly,
|
|
307
|
+
callback: () => cellImageToFloat(ctx, active)
|
|
308
|
+
}, {
|
|
309
|
+
label: "替换图片",
|
|
310
|
+
disabled: readonly,
|
|
311
|
+
callback: () => pickAndEmbedCellImage(ctx)
|
|
312
|
+
}, {
|
|
313
|
+
label: "移除图片",
|
|
314
|
+
disabled: readonly,
|
|
315
|
+
callback: () => ctx.removeCellImage(active)
|
|
316
|
+
});
|
|
317
|
+
return items;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* body 格右键菜单。目标格含嵌入图时出**纯图片菜单**(预览 / 超链接 / 转浮动 /
|
|
321
|
+
* 替换 / 移除)——图片盖住整格,右键语义是「图片」而非「单元格」,不出合并 /
|
|
322
|
+
* 数据格式 / 超链接等普通格项(对齐 Excel 图片右键约定)。普通格:合并 / 取消合并 +
|
|
323
|
+
* 设置数据格式 + 超链接 + 插入图片(浮动)+ 嵌入图片(入格);行列插入/删除仅行号/列头菜单。
|
|
324
|
+
*/
|
|
325
|
+
function buildBodyMenus(ctx, options) {
|
|
326
|
+
const active = ctx.getSelection().activeCell;
|
|
327
|
+
if (active && ctx.hasCellImage(active)) return cellImageMenuItems(ctx, active, options);
|
|
216
328
|
const mergeTool = defaultToolRegistry.get("merge");
|
|
217
329
|
const unmergeTool = defaultToolRegistry.get("unmerge");
|
|
218
|
-
const active = ctx.getSelection().activeCell;
|
|
219
330
|
return [
|
|
220
331
|
{
|
|
221
332
|
label: "合并单元格",
|
|
@@ -261,10 +372,16 @@ function buildBodyMenus(ctx) {
|
|
|
261
372
|
}
|
|
262
373
|
]
|
|
263
374
|
},
|
|
375
|
+
...cellLinkMenuItems(ctx, active, options),
|
|
264
376
|
{
|
|
265
377
|
label: "插入图片",
|
|
266
378
|
disabled: !active,
|
|
267
379
|
callback: () => pickAndInsertImage(ctx)
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
label: "嵌入图片",
|
|
383
|
+
disabled: !active,
|
|
384
|
+
callback: () => pickAndEmbedCellImage(ctx)
|
|
268
385
|
}
|
|
269
386
|
];
|
|
270
387
|
}
|
|
@@ -287,4 +404,4 @@ function ensureContextMenuSelection(ctx, info, renderSize) {
|
|
|
287
404
|
}
|
|
288
405
|
}
|
|
289
406
|
//#endregion
|
|
290
|
-
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 };
|
|
@@ -7,15 +7,17 @@ import _sfc_main$5 from "./popups/fill-color-popup.js";
|
|
|
7
7
|
import _sfc_main$6 from "./popups/find-popup.js";
|
|
8
8
|
import _sfc_main$7 from "./popups/font-color-popup.js";
|
|
9
9
|
import _sfc_main$8 from "./popups/font-size-popup.js";
|
|
10
|
-
import _sfc_main$9 from "./popups/
|
|
11
|
-
import _sfc_main$10 from "./
|
|
12
|
-
import _sfc_main$11 from "./sheet-
|
|
10
|
+
import _sfc_main$9 from "./popups/hyperlink-popup.js";
|
|
11
|
+
import _sfc_main$10 from "./popups/insert-image-popup.js";
|
|
12
|
+
import _sfc_main$11 from "./sheet-tabs.js";
|
|
13
|
+
import _sfc_main$12 from "./sheet-toolbar.js";
|
|
14
|
+
import { useCellLinkTooltip } from "./use-cell-link-tooltip.js";
|
|
13
15
|
import { useSheetGrid } from "./use-sheet-grid.js";
|
|
14
16
|
import { useSheetState } from "./use-sheet-state.js";
|
|
15
17
|
import { useToolGroups } from "./use-tool-groups.js";
|
|
16
18
|
import { useToolPopup } from "./use-tool-popup.js";
|
|
17
|
-
import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, openBlock, ref, toDisplayString, unref, useTemplateRef, watch, withCtx, withModifiers } from "vue";
|
|
18
|
-
import { UDropdown } from "@veltra/desktop";
|
|
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, messageConfirm } from "@veltra/desktop";
|
|
19
21
|
import { bem } from "@veltra/utils";
|
|
20
22
|
//#region src/components/sheet/sheet.vue
|
|
21
23
|
const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
@@ -67,7 +69,16 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
67
69
|
default: true
|
|
68
70
|
}
|
|
69
71
|
},
|
|
70
|
-
emits: [
|
|
72
|
+
emits: [
|
|
73
|
+
"active-sheet-change",
|
|
74
|
+
"col-resize-end",
|
|
75
|
+
"cell-link-hover",
|
|
76
|
+
"cell-link-leave",
|
|
77
|
+
"cell-link-click",
|
|
78
|
+
"image-link-click",
|
|
79
|
+
"cell-image-change",
|
|
80
|
+
"float-context-menu"
|
|
81
|
+
],
|
|
71
82
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
72
83
|
const props = __props;
|
|
73
84
|
const emit = __emit;
|
|
@@ -123,6 +134,72 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
123
134
|
if (!visible) closePopup();
|
|
124
135
|
}
|
|
125
136
|
const toolGroups = useToolGroups(context, stateTick);
|
|
137
|
+
/** 超链接配置弹层状态(右键菜单拉起):mode + 编辑回填 + 写入目标(cell 格 / image 浮动图或嵌入图) */
|
|
138
|
+
const hyperlinkPopup = shallowRef(null);
|
|
139
|
+
/** 悬停 tooltip 状态机(引擎 cell link hover/leave 事件驱动,层坐标换算见 use-cell-link-tooltip) */
|
|
140
|
+
const { tooltip: cellLinkTooltip, onCellLinkHover: showCellLinkTooltip, onCellLinkLeave: hideCellLinkTooltip } = useCellLinkTooltip();
|
|
141
|
+
/** 右键菜单超链接项句柄:记录写入目标并拉起弹窗(编辑回填原 url/text) */
|
|
142
|
+
function openHyperlinkPopup(mode, initial, imageTarget) {
|
|
143
|
+
hyperlinkPopup.value = {
|
|
144
|
+
mode,
|
|
145
|
+
initial,
|
|
146
|
+
addr: mode === "cell" ? context.getSelection().activeCell ?? void 0 : void 0,
|
|
147
|
+
imageTarget: mode === "image" ? imageTarget : void 0
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 弹窗确认:关弹层并写目标链接,一次写入 = 一个 undo 单元。
|
|
152
|
+
* cell:setCellLink(显示文本留空不写入 text → 单元格沿用自身内容显示);
|
|
153
|
+
* 浮动图:updateImage(link 字段);嵌入图:insertCellImage 覆盖写(其余载荷保留)。
|
|
154
|
+
*/
|
|
155
|
+
function handleHyperlinkConfirm(payload) {
|
|
156
|
+
const current = hyperlinkPopup.value;
|
|
157
|
+
hyperlinkPopup.value = null;
|
|
158
|
+
if (current?.mode === "cell") {
|
|
159
|
+
if (current.addr) context.setCellLink(current.addr, payload);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const target = current?.imageTarget;
|
|
163
|
+
if (target?.kind === "float") {
|
|
164
|
+
context.updateImage(target.id, { link: payload.url });
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (target?.kind === "cell") {
|
|
168
|
+
const existing = context.getCellImage(target.addr);
|
|
169
|
+
if (existing) context.insertCellImage(target.addr, {
|
|
170
|
+
...existing,
|
|
171
|
+
link: payload.url
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** lightbox 预览状态(右键「预览」拉起):URL 或字节 + MIME;关闭置 null 卸载(objectURL 由 UImagePreviewer 回收) */
|
|
176
|
+
const imagePreview = shallowRef(null);
|
|
177
|
+
/** 右键「预览」句柄:浮动图 / 嵌入图菜单共用 */
|
|
178
|
+
function openImagePreview(source) {
|
|
179
|
+
imagePreview.value = source;
|
|
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
|
+
}
|
|
126
203
|
const gridRef = useTemplateRef("gridRef");
|
|
127
204
|
const formulaBarRef = useTemplateRef("formulaBarRef");
|
|
128
205
|
const { rebuildGrid, activateGrid, pruneCache, getGrid, setSelectionAnchor } = useSheetGrid({
|
|
@@ -132,7 +209,20 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
132
209
|
context,
|
|
133
210
|
formulaBarRef,
|
|
134
211
|
isFunctionPopupOpen: () => popupTool.value?.popup === "functions",
|
|
135
|
-
onColResizeEnd: (event) => emit("col-resize-end", event)
|
|
212
|
+
onColResizeEnd: (event) => emit("col-resize-end", event),
|
|
213
|
+
onCellLinkHover: (event) => {
|
|
214
|
+
emit("cell-link-hover", event);
|
|
215
|
+
showCellLinkTooltip(event);
|
|
216
|
+
},
|
|
217
|
+
onCellLinkLeave: (event) => {
|
|
218
|
+
emit("cell-link-leave", event);
|
|
219
|
+
hideCellLinkTooltip(event);
|
|
220
|
+
},
|
|
221
|
+
onCellLinkClick: (event) => handleCellLinkClick(event),
|
|
222
|
+
onImageLinkClick: (event) => handleImageLinkClick(event),
|
|
223
|
+
onFloatContextMenu: (event) => emit("float-context-menu", event),
|
|
224
|
+
openHyperlinkPopup,
|
|
225
|
+
openImagePreview
|
|
136
226
|
});
|
|
137
227
|
__expose({
|
|
138
228
|
workbook,
|
|
@@ -151,7 +241,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
151
241
|
ref: toolbarWrapRef,
|
|
152
242
|
class: normalizeClass(unref(cls).e("toolbar-wrap"))
|
|
153
243
|
}, [
|
|
154
|
-
__props.showToolbar ? (openBlock(), createBlock(_sfc_main$
|
|
244
|
+
__props.showToolbar ? (openBlock(), createBlock(_sfc_main$12, {
|
|
155
245
|
key: 0,
|
|
156
246
|
groups: unref(toolGroups),
|
|
157
247
|
onToolClick: handleToolClick
|
|
@@ -193,7 +283,7 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
193
283
|
])) : unref(popupTool).popup === "functions" ? (openBlock(), createBlock(_sfc_main$1, {
|
|
194
284
|
key: 5,
|
|
195
285
|
onSelect: handleFunctionSelect
|
|
196
|
-
})) : unref(popupTool).popup === "insert-image" ? (openBlock(), createBlock(_sfc_main$
|
|
286
|
+
})) : unref(popupTool).popup === "insert-image" ? (openBlock(), createBlock(_sfc_main$10, {
|
|
197
287
|
key: 6,
|
|
198
288
|
context: unref(context),
|
|
199
289
|
onClose: unref(closePopup)
|
|
@@ -221,11 +311,23 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
221
311
|
ref_key: "gridRef",
|
|
222
312
|
ref: gridRef,
|
|
223
313
|
class: normalizeClass(unref(cls).e("grid"))
|
|
224
|
-
}, [
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
314
|
+
}, [
|
|
315
|
+
createCommentVNode(" 导入解析覆盖层(自绘,不动 desktop Loading 组件):遮罩 + 动画 + 文字\n 同一层,动画在上、文字在下,不存在被遮罩掩盖的问题 "),
|
|
316
|
+
parsing.value ? (openBlock(), createElementBlock("div", {
|
|
317
|
+
key: 0,
|
|
318
|
+
class: normalizeClass(unref(cls).e("loading-mask"))
|
|
319
|
+
}, [createElementVNode("div", { class: normalizeClass(unref(cls).e("loading-spinner")) }, null, 2), createElementVNode("div", { class: normalizeClass(unref(cls).e("loading-text")) }, toDisplayString(parseText.value), 3)], 2)) : createCommentVNode("v-if", true),
|
|
320
|
+
createCommentVNode(" 悬停链接格 tooltip:引擎 cell link hover/leave 事件驱动挂载/卸载,\n 层坐标 + 偏移后绝对定位于 grid 区(不遮指针;pointer-events: none) "),
|
|
321
|
+
unref(cellLinkTooltip) ? (openBlock(), createElementBlock("div", {
|
|
322
|
+
key: 1,
|
|
323
|
+
class: normalizeClass(unref(cls).e("link-tooltip")),
|
|
324
|
+
style: normalizeStyle({
|
|
325
|
+
left: `${unref(cellLinkTooltip).left}px`,
|
|
326
|
+
top: `${unref(cellLinkTooltip).top}px`
|
|
327
|
+
})
|
|
328
|
+
}, toDisplayString(unref(cellLinkTooltip).url), 7)) : createCommentVNode("v-if", true)
|
|
329
|
+
], 2),
|
|
330
|
+
__props.showTabs ? (openBlock(), createBlock(_sfc_main$11, {
|
|
229
331
|
key: 1,
|
|
230
332
|
workbook: unref(workbook),
|
|
231
333
|
"sheet-list": unref(sheetList),
|
|
@@ -234,7 +336,22 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
234
336
|
"workbook",
|
|
235
337
|
"sheet-list",
|
|
236
338
|
"active-index"
|
|
237
|
-
])) : createCommentVNode("v-if", true)
|
|
339
|
+
])) : createCommentVNode("v-if", true),
|
|
340
|
+
createCommentVNode(" 单元格/图片超链接配置弹窗(右键菜单拉起;confirm 按模式路由写入) "),
|
|
341
|
+
hyperlinkPopup.value ? (openBlock(), createBlock(_sfc_main$9, {
|
|
342
|
+
key: 2,
|
|
343
|
+
mode: hyperlinkPopup.value.mode,
|
|
344
|
+
initial: hyperlinkPopup.value.initial,
|
|
345
|
+
onConfirm: handleHyperlinkConfirm,
|
|
346
|
+
onClose: _cache[1] || (_cache[1] = ($event) => hyperlinkPopup.value = null)
|
|
347
|
+
}, null, 8, ["mode", "initial"])) : createCommentVNode("v-if", true),
|
|
348
|
+
createCommentVNode(" 图片 lightbox 预览(浮动图/嵌入图右键「预览」拉起;关闭卸载 → objectURL 由组件回收) "),
|
|
349
|
+
imagePreview.value ? (openBlock(), createBlock(unref(UImagePreviewer), {
|
|
350
|
+
key: 3,
|
|
351
|
+
src: imagePreview.value.src ?? imagePreview.value.data,
|
|
352
|
+
mime: imagePreview.value.mime,
|
|
353
|
+
onClose: _cache[2] || (_cache[2] = ($event) => imagePreview.value = null)
|
|
354
|
+
}, null, 8, ["src", "mime"])) : createCommentVNode("v-if", true)
|
|
238
355
|
], 2);
|
|
239
356
|
};
|
|
240
357
|
}
|
|
@@ -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";
|