@veltra/sheet 3.0.0 → 4.0.0
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/import-file.js +3 -1
- package/dist/components/sheet/popups/import.worker.d.ts +4 -0
- package/dist/components/sheet/popups/import.worker.js +3 -1
- package/dist/components/sheet/sheet-context-menu.js +6 -4
- package/dist/components/sheet/sheet.js +2 -2
- package/dist/components/sheet/use-sheet-grid.js +51 -2
- package/dist/types/sheet.d.ts +5 -7
- package/package.json +2 -2
- package/src/components/sheet/__test__/grid-test-utils.ts +2 -3
- package/src/components/sheet/__test__/import-file.test.ts +33 -2
- package/src/components/sheet/__test__/sheet-component.test.ts +2 -2
- package/src/components/sheet/__test__/sheet-context-menu.test.ts +43 -0
- package/src/components/sheet/__test__/sheet-scrollbar.test.ts +23 -73
- package/src/components/sheet/__test__/sheet-theme.test.ts +212 -0
- package/src/components/sheet/import-file.ts +19 -2
- package/src/components/sheet/popups/import.worker.ts +18 -4
- package/src/components/sheet/sheet-context-menu.ts +14 -4
- package/src/components/sheet/sheet.vue +3 -4
- package/src/components/sheet/use-sheet-grid.ts +52 -2
- package/src/types/sheet.ts +4 -7
|
@@ -55,7 +55,9 @@ function toSnapshotArray(wb) {
|
|
|
55
55
|
return {
|
|
56
56
|
sheets: wb.getSheets().map((s) => ({
|
|
57
57
|
name: s.name,
|
|
58
|
-
snapshot: s.snapshot()
|
|
58
|
+
snapshot: s.snapshot(),
|
|
59
|
+
...s.defaultRowHeight !== void 0 ? { defaultRowHeight: s.defaultRowHeight } : {},
|
|
60
|
+
...s.defaultColWidth !== void 0 ? { defaultColWidth: s.defaultColWidth } : {}
|
|
59
61
|
})),
|
|
60
62
|
activeIndex: wb.activeSheetIndex
|
|
61
63
|
};
|
|
@@ -10,6 +10,10 @@ export type ImportWorkerResponse = {
|
|
|
10
10
|
sheets: {
|
|
11
11
|
name: string;
|
|
12
12
|
snapshot: SheetSnapshot;
|
|
13
|
+
/** 默认行高 px(模型未声明则不携带;形状同上游 SheetReplaceItem 对应字段) */
|
|
14
|
+
defaultRowHeight?: number;
|
|
15
|
+
/** 默认列宽 px(模型未声明则不携带;形状同上游 SheetReplaceItem 对应字段) */
|
|
16
|
+
defaultColWidth?: number;
|
|
13
17
|
}[];
|
|
14
18
|
activeIndex: number;
|
|
15
19
|
} | {
|
|
@@ -22,7 +22,9 @@ self.onmessage = (e) => {
|
|
|
22
22
|
ok: true,
|
|
23
23
|
sheets: wb.getSheets().map((s) => ({
|
|
24
24
|
name: s.name,
|
|
25
|
-
snapshot: s.snapshot()
|
|
25
|
+
snapshot: s.snapshot(),
|
|
26
|
+
...s.defaultRowHeight !== void 0 ? { defaultRowHeight: s.defaultRowHeight } : {},
|
|
27
|
+
...s.defaultColWidth !== void 0 ? { defaultColWidth: s.defaultColWidth } : {}
|
|
26
28
|
})),
|
|
27
29
|
activeIndex: wb.activeSheetIndex
|
|
28
30
|
};
|
|
@@ -106,7 +106,8 @@ function buildRowHeaderMenus(ctx, options) {
|
|
|
106
106
|
const rowCount = defaultInsertCount(range, "row");
|
|
107
107
|
const deleteCount = range ? endRow - startRow + 1 : 1;
|
|
108
108
|
const frozen = ctx.frozen;
|
|
109
|
-
const
|
|
109
|
+
const freezeRow = (options?.row ?? endRow) + 1;
|
|
110
|
+
const freezeActive = frozen.rows === freezeRow;
|
|
110
111
|
return [
|
|
111
112
|
{
|
|
112
113
|
label: "在上方插入行",
|
|
@@ -141,7 +142,7 @@ function buildRowHeaderMenus(ctx, options) {
|
|
|
141
142
|
{ divider: true },
|
|
142
143
|
{
|
|
143
144
|
label: freezeActive ? "✓ 冻结到当前行" : "冻结到当前行",
|
|
144
|
-
callback: () => ctx.setFrozen(
|
|
145
|
+
callback: () => ctx.setFrozen(freezeRow, frozen.cols)
|
|
145
146
|
},
|
|
146
147
|
{
|
|
147
148
|
label: "取消冻结",
|
|
@@ -158,7 +159,8 @@ function buildColHeaderMenus(ctx, options) {
|
|
|
158
159
|
const colCount = defaultInsertCount(range, "col");
|
|
159
160
|
const deleteCount = range ? endCol - startCol + 1 : 1;
|
|
160
161
|
const frozen = ctx.frozen;
|
|
161
|
-
const
|
|
162
|
+
const freezeCol = (options?.col ?? endCol) + 1;
|
|
163
|
+
const freezeActive = frozen.cols === freezeCol;
|
|
162
164
|
return [
|
|
163
165
|
{
|
|
164
166
|
label: "在左侧插入列",
|
|
@@ -193,7 +195,7 @@ function buildColHeaderMenus(ctx, options) {
|
|
|
193
195
|
{ divider: true },
|
|
194
196
|
{
|
|
195
197
|
label: freezeActive ? "✓ 冻结到当前列" : "冻结到当前列",
|
|
196
|
-
callback: () => ctx.setFrozen(frozen.rows,
|
|
198
|
+
callback: () => ctx.setFrozen(frozen.rows, freezeCol)
|
|
197
199
|
},
|
|
198
200
|
{
|
|
199
201
|
label: "取消冻结",
|
|
@@ -2,6 +2,7 @@ import { buildBodyMenus, buildColHeaderMenus, buildRowHeaderMenus, ensureContext
|
|
|
2
2
|
import { SheetGrid } from "infinitable/sheet";
|
|
3
3
|
import { onBeforeUnmount, onMounted, watch } from "vue";
|
|
4
4
|
import { contextmenu } from "@veltra/desktop";
|
|
5
|
+
import { currentTheme } from "@veltra/styles/theme";
|
|
5
6
|
//#region src/components/sheet/use-sheet-grid.ts
|
|
6
7
|
/**
|
|
7
8
|
* 缓存容量:最近 N 个 sheet 的 SheetGrid 实例常驻(tab 来回切换零重建)。
|
|
@@ -11,6 +12,38 @@ import { contextmenu } from "@veltra/desktop";
|
|
|
11
12
|
*/
|
|
12
13
|
const GRID_CACHE_CAPACITY = 3;
|
|
13
14
|
/**
|
|
15
|
+
* 画布主题映射:读 grid 宿主元素上生效的 `--u-*` CSS 变量(loadTheme 注入 html、
|
|
16
|
+
* 继承到宿主),换算为引擎 `ThemeOverride`——画布底色 / 表头 / 文字 / 网格线 /
|
|
17
|
+
* 冻结分隔线跟随 UI 主题。rowHeader / corner 由引擎随生效 header 派生,无需单写。
|
|
18
|
+
*
|
|
19
|
+
* 任一变量为空(未 loadTheme)返回 `undefined`:SheetGrid 不传 theme、保持引擎
|
|
20
|
+
* 缺省白底,不破坏无主题环境。
|
|
21
|
+
*/
|
|
22
|
+
function resolveCanvasThemeOverride(el) {
|
|
23
|
+
const style = getComputedStyle(el);
|
|
24
|
+
const bgColorTop = style.getPropertyValue("--u-bg-color-top").trim();
|
|
25
|
+
const bgColorBottom = style.getPropertyValue("--u-bg-color-bottom").trim();
|
|
26
|
+
const textColorMain = style.getPropertyValue("--u-text-color-main").trim();
|
|
27
|
+
const borderColor = style.getPropertyValue("--u-border-color").trim();
|
|
28
|
+
const borderMutedColor = style.getPropertyValue("--u-border-muted-color").trim();
|
|
29
|
+
if (!bgColorTop || !bgColorBottom || !textColorMain || !borderColor || !borderMutedColor) return;
|
|
30
|
+
return {
|
|
31
|
+
body: {
|
|
32
|
+
background: bgColorTop,
|
|
33
|
+
color: textColorMain,
|
|
34
|
+
borderColor
|
|
35
|
+
},
|
|
36
|
+
header: {
|
|
37
|
+
background: bgColorBottom,
|
|
38
|
+
color: textColorMain,
|
|
39
|
+
borderColor
|
|
40
|
+
},
|
|
41
|
+
underlayBackgroundColor: bgColorTop,
|
|
42
|
+
interaction: { freezeDividerColor: borderMutedColor },
|
|
43
|
+
frameStyle: { color: borderColor }
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
14
47
|
* SheetGrid 生命周期与网格右键菜单(LRU 实例缓存):
|
|
15
48
|
* - activateGrid:tab 切换入口——命中缓存 → 显示 + 模型同步(零重建);
|
|
16
49
|
* 未命中 → 新建实例入缓存,超容量淘汰最久未用(release + 移除容器)
|
|
@@ -29,7 +62,13 @@ function useSheetGrid(options) {
|
|
|
29
62
|
const sheet = getActiveSheet();
|
|
30
63
|
const renderSize = resolveRenderSize(props.rows, props.cols, sheet.rows, sheet.cols);
|
|
31
64
|
ensureContextMenuSelection(context, info, renderSize);
|
|
32
|
-
const menus = info.kind === "row-header" ? buildRowHeaderMenus(context, {
|
|
65
|
+
const menus = info.kind === "row-header" ? buildRowHeaderMenus(context, {
|
|
66
|
+
readonly: props.readonly,
|
|
67
|
+
row: info.row
|
|
68
|
+
}) : info.kind === "col-header" ? buildColHeaderMenus(context, {
|
|
69
|
+
readonly: props.readonly,
|
|
70
|
+
col: info.col
|
|
71
|
+
}) : buildBodyMenus(context);
|
|
33
72
|
contextmenu.pop({
|
|
34
73
|
mousePosition: {
|
|
35
74
|
x: info.x,
|
|
@@ -74,6 +113,7 @@ function useSheetGrid(options) {
|
|
|
74
113
|
colResize: props.colResize,
|
|
75
114
|
scrollbar: props.scrollbar,
|
|
76
115
|
growOnScroll: props.growOnScroll,
|
|
116
|
+
theme: resolveCanvasThemeOverride(host),
|
|
77
117
|
onContextMenu: handleContextMenu,
|
|
78
118
|
onEditStart: (addr) => formulaBarRef.value?.mirrorGridEdit(addr),
|
|
79
119
|
onEditEnd: (addr) => formulaBarRef.value?.exitMirror(addr),
|
|
@@ -199,6 +239,15 @@ function useSheetGrid(options) {
|
|
|
199
239
|
onBeforeUnmount(() => {
|
|
200
240
|
invalidateAll();
|
|
201
241
|
});
|
|
242
|
+
watch([() => currentTheme.value?.theme, currentTheme], () => {
|
|
243
|
+
const host = gridRef.value;
|
|
244
|
+
const override = host ? resolveCanvasThemeOverride(host) : void 0;
|
|
245
|
+
if (!override) return;
|
|
246
|
+
for (const item of cache.values()) item.grid.updateTheme(override);
|
|
247
|
+
}, {
|
|
248
|
+
deep: true,
|
|
249
|
+
flush: "post"
|
|
250
|
+
});
|
|
202
251
|
/** fx 引用拾取会话置/清选区锚点(公式栏 → 活动实例透传;无活动实例时静默) */
|
|
203
252
|
function setSelectionAnchor(addr) {
|
|
204
253
|
active?.grid.setSelectionAnchor(addr);
|
|
@@ -212,4 +261,4 @@ function useSheetGrid(options) {
|
|
|
212
261
|
};
|
|
213
262
|
}
|
|
214
263
|
//#endregion
|
|
215
|
-
export { useSheetGrid };
|
|
264
|
+
export { resolveCanvasThemeOverride, useSheetGrid };
|
package/dist/types/sheet.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SheetContext } from "../tools/context.js";
|
|
2
|
-
import { ResolveCellRenderer, ResolveCellStyleHook, ResolveDisplayValue,
|
|
2
|
+
import { 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
5
|
//#region src/types/sheet.d.ts
|
|
@@ -54,13 +54,11 @@ export interface SheetProps {
|
|
|
54
54
|
colResize?: boolean;
|
|
55
55
|
/**
|
|
56
56
|
* 滚动条(透传 SheetGrid → 引擎内建,构造期选项):false 整体关闭(不显示任何
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* canvas 档显示策略)。对象形态引用更替触发网格重建——沿用 header / editors
|
|
61
|
-
* 的稳定引用约定,宿主勿在模板内联对象字面量
|
|
57
|
+
* 滚动条);缺省 true 画布常驻档——引擎归一化 canvas always + reserve,滚动条
|
|
58
|
+
* 常驻画在画布内(reserve 只在画布内预留轨道,不占页面布局、不遮挡单元格)。
|
|
59
|
+
* 变化触发网格重建
|
|
62
60
|
*/
|
|
63
|
-
scrollbar?: boolean
|
|
61
|
+
scrollbar?: boolean;
|
|
64
62
|
/**
|
|
65
63
|
* 滚动近端动态增长(透传 SheetGrid,构造期选项):滚动缓冲末端触到当前行列数
|
|
66
64
|
* 时模型与引擎同步扩容(引擎缺省 true);false 为固定尺寸网格——内容定尺寸的
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veltra/sheet",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
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.7"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@cat-kit/core": ">=1.2.1",
|
|
@@ -13,9 +13,8 @@ export const cellX = (col: number) => ROW_HEADER_WIDTH + col * DEFAULT_COL_WIDTH
|
|
|
13
13
|
export const cellY = (row: number) => HEADER_HEIGHT + row * DEFAULT_ROW_HEIGHT + 5
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* 引擎指针事件派发目标:body
|
|
17
|
-
*
|
|
18
|
-
* 在两档下都是其后代,从它派发(冒泡)对两种形态都到达引擎监听。
|
|
16
|
+
* 引擎指针事件派发目标:body 层画布。引擎事件源是挂载容器,body 画布
|
|
17
|
+
* 是其后代,从它派发(冒泡)到达引擎监听。
|
|
19
18
|
*/
|
|
20
19
|
export function gridEventTarget(root: HTMLElement): HTMLElement {
|
|
21
20
|
return root.querySelector<HTMLElement>(".u-sheet__grid-instance canvas[data-layer-kind='body']")!
|
|
@@ -16,7 +16,9 @@ const mocks = vi.hoisted(() => {
|
|
|
16
16
|
importCsv: vi.fn(),
|
|
17
17
|
importXlsx: vi.fn(() =>
|
|
18
18
|
Promise.resolve({
|
|
19
|
-
getSheets: ()
|
|
19
|
+
getSheets: (): MockSheet[] => [
|
|
20
|
+
{ name: 'S1', snapshot: () => EMPTY_SNAPSHOT, defaultRowHeight: 20, defaultColWidth: 64 }
|
|
21
|
+
],
|
|
20
22
|
activeSheetIndex: 0
|
|
21
23
|
})
|
|
22
24
|
),
|
|
@@ -34,6 +36,14 @@ const EMPTY_SNAPSHOT = {
|
|
|
34
36
|
cols: 0
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
/** importXlsx mock 的 sheet 形状(默认尺寸可选:不写即未声明 → 不透传路径) */
|
|
40
|
+
type MockSheet = {
|
|
41
|
+
name: string
|
|
42
|
+
snapshot: () => typeof EMPTY_SNAPSHOT
|
|
43
|
+
defaultRowHeight?: number
|
|
44
|
+
defaultColWidth?: number
|
|
45
|
+
}
|
|
46
|
+
|
|
37
47
|
vi.mock('@veltra/desktop', () => ({ message: mocks.message, messageConfirm: mocks.messageConfirm }))
|
|
38
48
|
|
|
39
49
|
vi.mock('infinitable/sheet', async (importActual) => {
|
|
@@ -110,7 +120,7 @@ describe('importFromFile 导入确认兜底', () => {
|
|
|
110
120
|
expect(mocks.replaceWorkbookWithSnapshots).toHaveBeenCalledTimes(1)
|
|
111
121
|
expect(mocks.replaceWorkbookWithSnapshots).toHaveBeenCalledWith(
|
|
112
122
|
expect.anything(),
|
|
113
|
-
[{ name: 'S1', snapshot: EMPTY_SNAPSHOT }],
|
|
123
|
+
[{ name: 'S1', snapshot: EMPTY_SNAPSHOT, defaultRowHeight: 20, defaultColWidth: 64 }],
|
|
114
124
|
0
|
|
115
125
|
)
|
|
116
126
|
expect(replaced).toHaveBeenCalledTimes(1)
|
|
@@ -173,6 +183,27 @@ describe('importFromFile 导入确认兜底', () => {
|
|
|
173
183
|
})
|
|
174
184
|
})
|
|
175
185
|
|
|
186
|
+
describe('importFromFile 默认行列尺寸透传', () => {
|
|
187
|
+
it('文件未声明默认尺寸:条目不携带两字段(目标保持现状)', async () => {
|
|
188
|
+
mocks.importXlsx.mockImplementationOnce(() =>
|
|
189
|
+
Promise.resolve({
|
|
190
|
+
getSheets: () => [{ name: 'S1', snapshot: () => EMPTY_SNAPSHOT }],
|
|
191
|
+
activeSheetIndex: 0
|
|
192
|
+
})
|
|
193
|
+
)
|
|
194
|
+
const options = makeOptions()
|
|
195
|
+
await triggerXlsxAndAwait(options)
|
|
196
|
+
const onClosed = getOnClosed()
|
|
197
|
+
await onClosed('confirm')
|
|
198
|
+
|
|
199
|
+
expect(mocks.replaceWorkbookWithSnapshots).toHaveBeenCalledTimes(1)
|
|
200
|
+
const [entry] = mocks.replaceWorkbookWithSnapshots.mock.calls[0]![1]
|
|
201
|
+
expect(entry).toEqual({ name: 'S1', snapshot: EMPTY_SNAPSHOT })
|
|
202
|
+
expect(entry).not.toHaveProperty('defaultRowHeight')
|
|
203
|
+
expect(entry).not.toHaveProperty('defaultColWidth')
|
|
204
|
+
})
|
|
205
|
+
})
|
|
206
|
+
|
|
176
207
|
describe('pickAndImportFile', () => {
|
|
177
208
|
it('创建隐藏 file input(同一 accept)并 click', () => {
|
|
178
209
|
const click = vi.spyOn(HTMLInputElement.prototype, 'click').mockImplementation(() => {})
|
|
@@ -84,8 +84,8 @@ afterEach(() => {
|
|
|
84
84
|
})
|
|
85
85
|
|
|
86
86
|
describe('USheet 组件', () => {
|
|
87
|
-
// scrollbar
|
|
88
|
-
//
|
|
87
|
+
// scrollbar 形态与语义(缺省画布常驻档 / false / watch 重建)见同目录
|
|
88
|
+
// sheet-scrollbar.test.ts
|
|
89
89
|
|
|
90
90
|
it('挂载后默认选区 A1:名称框显示 A1、fx 输入栏可用', async () => {
|
|
91
91
|
const workbook = createWorkbook()
|
|
@@ -134,6 +134,49 @@ describe('build*Menus', () => {
|
|
|
134
134
|
expect(menus.find((m) => m.label === '取消冻结')?.disabled).toBe(false)
|
|
135
135
|
})
|
|
136
136
|
|
|
137
|
+
it('冻结以右键命中行列为准,不放大整行/整列残留选区(先冻行再冻列不失效)', () => {
|
|
138
|
+
const sheet = new Sheet()
|
|
139
|
+
const ctx = createSheetContext(sheet)
|
|
140
|
+
// 用户路径:右键行号 2 冻结到第 3 行 → 残留整行选区(行 2 × 全部列 0..5)
|
|
141
|
+
sheet.selectRange(wholeRowRange(2, 6))
|
|
142
|
+
sheet.setFrozen(3, 0)
|
|
143
|
+
// 随后右键列头 col 1:落点在整行选区内 → ensureContextMenuSelection 保留选区,
|
|
144
|
+
// 冻结列必须用命中的 col=1 而非选区末端 col=5(否则冻结全部列,视觉不生效)
|
|
145
|
+
ensureContextMenuSelection(
|
|
146
|
+
ctx,
|
|
147
|
+
{ kind: 'col-header', addr: null, col: 1 },
|
|
148
|
+
{ rows: 10, cols: 6 }
|
|
149
|
+
)
|
|
150
|
+
expect(ctx.getSelection().ranges[0]).toEqual(wholeRowRange(2, 6))
|
|
151
|
+
const menus = buildColHeaderMenus(ctx, { col: 1 })
|
|
152
|
+
menus.find((m) => m.label === '冻结到当前列')!.callback!()
|
|
153
|
+
expect(sheet.frozen).toEqual({ rows: 3, cols: 2 })
|
|
154
|
+
|
|
155
|
+
// 对称路径:先冻列 → 残留整列选区(全部行 0..9 × col 1)→ 右键行号 4 冻结到第 5 行
|
|
156
|
+
sheet.setFrozen(0, 0)
|
|
157
|
+
sheet.selectRange(wholeColRange(1, 10))
|
|
158
|
+
sheet.setFrozen(0, 2)
|
|
159
|
+
ensureContextMenuSelection(
|
|
160
|
+
ctx,
|
|
161
|
+
{ kind: 'row-header', addr: null, row: 4 },
|
|
162
|
+
{ rows: 10, cols: 6 }
|
|
163
|
+
)
|
|
164
|
+
const rowMenus = buildRowHeaderMenus(ctx, { row: 4 })
|
|
165
|
+
rowMenus.find((m) => m.label === '冻结到当前行')!.callback!()
|
|
166
|
+
expect(sheet.frozen).toEqual({ rows: 5, cols: 2 })
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
it('冻结项未传命中行列时回落选区末端(旧调用方兼容)', () => {
|
|
170
|
+
const sheet = new Sheet()
|
|
171
|
+
const ctx = createSheetContext(sheet)
|
|
172
|
+
sheet.selectRange(createRange({ row: 0, col: 0 }, { row: 2, col: 5 }))
|
|
173
|
+
buildRowHeaderMenus(ctx).find((m) => m.label === '冻结到当前行')!.callback!()
|
|
174
|
+
expect(sheet.frozen.rows).toBe(3)
|
|
175
|
+
sheet.setFrozen(0, 0)
|
|
176
|
+
buildColHeaderMenus(ctx).find((m) => m.label === '冻结到当前列')!.callback!()
|
|
177
|
+
expect(sheet.frozen.cols).toBe(6)
|
|
178
|
+
})
|
|
179
|
+
|
|
137
180
|
it('列头菜单对称', () => {
|
|
138
181
|
const sheet = new Sheet()
|
|
139
182
|
const ctx = createSheetContext(sheet)
|
|
@@ -10,7 +10,6 @@ const containers: HTMLElement[] = []
|
|
|
10
10
|
|
|
11
11
|
function mount(props: () => Record<string, unknown>): {
|
|
12
12
|
exposed: { value: SheetExposed | undefined }
|
|
13
|
-
el: HTMLElement
|
|
14
13
|
} {
|
|
15
14
|
const exposed: { value: SheetExposed | undefined } = { value: undefined }
|
|
16
15
|
const el = document.createElement('div')
|
|
@@ -29,12 +28,7 @@ function mount(props: () => Record<string, unknown>): {
|
|
|
29
28
|
})
|
|
30
29
|
app.mount(el)
|
|
31
30
|
apps.push(app)
|
|
32
|
-
return { exposed
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** 引擎装配的原生滚动容器(wrapper 带 data-native-scroll 标记,见引擎 NativeScrollbarHost) */
|
|
36
|
-
function nativeScrollHost(el: HTMLElement): HTMLElement | null {
|
|
37
|
-
return el.querySelector<HTMLElement>('.u-sheet__grid-instance [data-native-scroll]')
|
|
31
|
+
return { exposed }
|
|
38
32
|
}
|
|
39
33
|
|
|
40
34
|
afterEach(() => {
|
|
@@ -42,20 +36,17 @@ afterEach(() => {
|
|
|
42
36
|
while (containers.length) containers.pop()!.remove()
|
|
43
37
|
})
|
|
44
38
|
|
|
45
|
-
describe('USheet scrollbar
|
|
46
|
-
it('
|
|
47
|
-
const { exposed
|
|
39
|
+
describe('USheet scrollbar(缺省画布常驻档,boolean 透传)', () => {
|
|
40
|
+
it('缺省 true:画布常驻档下发引擎', async () => {
|
|
41
|
+
const { exposed } = mount(() => ({ workbook: new Workbook(), rows: 10, cols: 6 }))
|
|
48
42
|
await nextTick()
|
|
49
43
|
|
|
50
|
-
|
|
51
|
-
expect(
|
|
52
|
-
expect(table.usesNativeScrollbar).toBe(true)
|
|
53
|
-
// DOM 断言:引擎在挂载容器内装配真实 overflow 滚动容器(scrollbar-gutter: stable)
|
|
54
|
-
expect(nativeScrollHost(el)).not.toBeNull()
|
|
44
|
+
// 组件缺省 true:引擎归一化为 canvas always + reserve,滚动条常驻画在画布内
|
|
45
|
+
expect(exposed.value!.getGrid()!.getTable().options.scrollbar).toBe(true)
|
|
55
46
|
})
|
|
56
47
|
|
|
57
|
-
it('scrollbar: false
|
|
58
|
-
const { exposed
|
|
48
|
+
it('scrollbar: false:整体关闭语义透传', async () => {
|
|
49
|
+
const { exposed } = mount(() => ({
|
|
59
50
|
workbook: new Workbook(),
|
|
60
51
|
rows: 10,
|
|
61
52
|
cols: 6,
|
|
@@ -63,47 +54,12 @@ describe('USheet scrollbar(缺省原生档,全形态透传)', () => {
|
|
|
63
54
|
}))
|
|
64
55
|
await nextTick()
|
|
65
56
|
|
|
66
|
-
|
|
67
|
-
expect(table.options.scrollbar).toBe(false)
|
|
68
|
-
expect(table.usesNativeScrollbar).toBe(false)
|
|
69
|
-
expect(nativeScrollHost(el)).toBeNull()
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
it('scrollbar: true:旧语义(画布常驻滚动条)透传,不装配原生容器', async () => {
|
|
73
|
-
const { exposed, el } = mount(() => ({
|
|
74
|
-
workbook: new Workbook(),
|
|
75
|
-
rows: 10,
|
|
76
|
-
cols: 6,
|
|
77
|
-
scrollbar: true
|
|
78
|
-
}))
|
|
79
|
-
await nextTick()
|
|
80
|
-
|
|
81
|
-
const table = exposed.value!.getGrid()!.getTable()
|
|
82
|
-
expect(table.options.scrollbar).toBe(true)
|
|
83
|
-
expect(table.usesNativeScrollbar).toBe(false)
|
|
84
|
-
expect(nativeScrollHost(el)).toBeNull()
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('对象形态按引用透传(mode: canvas 显式回画布档)', async () => {
|
|
88
|
-
const canvasOption = { mode: 'canvas', visibility: 'always' } as const
|
|
89
|
-
const { exposed, el } = mount(() => ({
|
|
90
|
-
workbook: new Workbook(),
|
|
91
|
-
rows: 10,
|
|
92
|
-
cols: 6,
|
|
93
|
-
scrollbar: canvasOption
|
|
94
|
-
}))
|
|
95
|
-
await nextTick()
|
|
96
|
-
|
|
97
|
-
const table = exposed.value!.getGrid()!.getTable()
|
|
98
|
-
// 引用透传:引擎收到宿主的同一对象(构造期选项,宿主保持稳定引用即可)
|
|
99
|
-
expect(table.options.scrollbar).toBe(canvasOption)
|
|
100
|
-
expect(table.usesNativeScrollbar).toBe(false)
|
|
101
|
-
expect(nativeScrollHost(el)).toBeNull()
|
|
57
|
+
expect(exposed.value!.getGrid()!.getTable().options.scrollbar).toBe(false)
|
|
102
58
|
})
|
|
103
59
|
|
|
104
|
-
it('watch
|
|
105
|
-
const state = ref
|
|
106
|
-
const { exposed
|
|
60
|
+
it('watch 重建:boolean 切换触发网格重建,新配置生效', async () => {
|
|
61
|
+
const state = ref(true)
|
|
62
|
+
const { exposed } = mount(() => ({
|
|
107
63
|
workbook: new Workbook(),
|
|
108
64
|
rows: 10,
|
|
109
65
|
cols: 6,
|
|
@@ -111,27 +67,21 @@ describe('USheet scrollbar(缺省原生档,全形态透传)', () => {
|
|
|
111
67
|
}))
|
|
112
68
|
await nextTick()
|
|
113
69
|
|
|
114
|
-
const
|
|
115
|
-
expect(
|
|
116
|
-
|
|
117
|
-
// 对象引用更替(native → canvas 常驻):构造期选项变化 → 重建
|
|
118
|
-
state.value = { mode: 'canvas', visibility: 'always' }
|
|
119
|
-
await nextTick()
|
|
120
|
-
const gridCanvas = exposed.value!.getGrid()
|
|
121
|
-
expect(gridCanvas).not.toBe(gridNative)
|
|
122
|
-
expect(gridCanvas!.getTable().options.scrollbar).toEqual({
|
|
123
|
-
mode: 'canvas',
|
|
124
|
-
visibility: 'always'
|
|
125
|
-
})
|
|
126
|
-
expect(gridCanvas!.getTable().usesNativeScrollbar).toBe(false)
|
|
127
|
-
expect(nativeScrollHost(el)).toBeNull()
|
|
70
|
+
const gridOn = exposed.value!.getGrid()
|
|
71
|
+
expect(gridOn!.getTable().options.scrollbar).toBe(true)
|
|
128
72
|
|
|
129
|
-
//
|
|
73
|
+
// true → false:构造期选项变化 → 重建,整体关闭
|
|
130
74
|
state.value = false
|
|
131
75
|
await nextTick()
|
|
132
76
|
const gridOff = exposed.value!.getGrid()
|
|
133
|
-
expect(gridOff).not.toBe(
|
|
77
|
+
expect(gridOff).not.toBe(gridOn)
|
|
134
78
|
expect(gridOff!.getTable().options.scrollbar).toBe(false)
|
|
135
|
-
|
|
79
|
+
|
|
80
|
+
// false → true:恢复画布常驻档,同样重建
|
|
81
|
+
state.value = true
|
|
82
|
+
await nextTick()
|
|
83
|
+
const gridOnAgain = exposed.value!.getGrid()
|
|
84
|
+
expect(gridOnAgain).not.toBe(gridOff)
|
|
85
|
+
expect(gridOnAgain!.getTable().options.scrollbar).toBe(true)
|
|
136
86
|
})
|
|
137
87
|
})
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { currentTheme, lightTheme } from '@veltra/styles/theme'
|
|
2
|
+
import { Workbook } from 'infinitable/sheet'
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from 'vite-plus/test'
|
|
4
|
+
import { createApp, h, nextTick, type App } from 'vue'
|
|
5
|
+
|
|
6
|
+
import { USheet } from '../../../index'
|
|
7
|
+
import type { SheetExposed } from '../../../types'
|
|
8
|
+
import { resolveCanvasThemeOverride } from '../use-sheet-grid'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 画布主题接入(B3):CSS 变量 → 引擎 ThemeOverride 映射 + loadTheme 后缓存
|
|
12
|
+
* 实例原地换肤。变量样本值刻意避开引擎内置缺省色(body #FFF / 表头 #F5F5F5 /
|
|
13
|
+
* 网格线 #E1E4E8 / 冻结线 #B6BABF),断言命中即可区分 override 生效而非缺省。
|
|
14
|
+
*/
|
|
15
|
+
const THEME_VARS = {
|
|
16
|
+
'--u-bg-color-top': '#123456',
|
|
17
|
+
'--u-bg-color-bottom': '#234567',
|
|
18
|
+
'--u-text-color-main': '#abcdef',
|
|
19
|
+
'--u-border-color': '#987654',
|
|
20
|
+
'--u-border-muted-color': '#654321'
|
|
21
|
+
} as const
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* mock 全局 getComputedStyle:仅覆盖 getPropertyValue 返回的主题 CSS 变量,
|
|
25
|
+
* 未给的变量回退真实计算值,其余属性 / 方法原样透传(挂载路径中引擎
|
|
26
|
+
* normalizeContainer 等仍真实消费 computed style)。返回还原函数。
|
|
27
|
+
*/
|
|
28
|
+
function mockThemeVars(vars: Record<string, string>): () => void {
|
|
29
|
+
const real = getComputedStyle
|
|
30
|
+
vi.stubGlobal('getComputedStyle', (el: Element, pseudo?: string | null): CSSStyleDeclaration => {
|
|
31
|
+
const style = real(el, pseudo ?? undefined)
|
|
32
|
+
return new Proxy(style, {
|
|
33
|
+
get(target, prop) {
|
|
34
|
+
if (prop === 'getPropertyValue') {
|
|
35
|
+
return (name: string) => (name in vars ? vars[name]! : target.getPropertyValue(name))
|
|
36
|
+
}
|
|
37
|
+
const value = Reflect.get(target, prop, target)
|
|
38
|
+
return typeof value === 'function' ? value.bind(target) : value
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
return () => vi.unstubAllGlobals()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const apps: App[] = []
|
|
46
|
+
const containers: HTMLElement[] = []
|
|
47
|
+
|
|
48
|
+
function mount(props: () => Record<string, unknown>): {
|
|
49
|
+
exposed: { value: SheetExposed | undefined }
|
|
50
|
+
el: HTMLElement
|
|
51
|
+
} {
|
|
52
|
+
const exposed: { value: SheetExposed | undefined } = { value: undefined }
|
|
53
|
+
const el = document.createElement('div')
|
|
54
|
+
el.style.width = '800px'
|
|
55
|
+
el.style.height = '600px'
|
|
56
|
+
document.body.appendChild(el)
|
|
57
|
+
containers.push(el)
|
|
58
|
+
const app = createApp({
|
|
59
|
+
render: () =>
|
|
60
|
+
h(USheet, {
|
|
61
|
+
...props(),
|
|
62
|
+
ref: (value: unknown) => {
|
|
63
|
+
exposed.value = value as SheetExposed | undefined
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
app.mount(el)
|
|
68
|
+
apps.push(app)
|
|
69
|
+
return { exposed, el }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function tabs(el: HTMLElement): HTMLButtonElement[] {
|
|
73
|
+
return [...el.querySelectorAll<HTMLButtonElement>('.u-sheet__tab')]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
afterEach(() => {
|
|
77
|
+
while (apps.length) apps.pop()!.unmount()
|
|
78
|
+
while (containers.length) containers.pop()!.remove()
|
|
79
|
+
// 主题单例复位(换肤测试副作用),避免用例间串扰;此时实例已卸载、watcher 已停
|
|
80
|
+
currentTheme.value = undefined
|
|
81
|
+
vi.unstubAllGlobals()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
describe('resolveCanvasThemeOverride:CSS 变量 → 引擎 ThemeOverride', () => {
|
|
85
|
+
it('变量齐全:按映射表换算(底色/表头/文字/网格线/冻结分隔线)', () => {
|
|
86
|
+
const restore = mockThemeVars({ ...THEME_VARS })
|
|
87
|
+
try {
|
|
88
|
+
expect(resolveCanvasThemeOverride(document.createElement('div'))).toEqual({
|
|
89
|
+
body: { background: '#123456', color: '#abcdef', borderColor: '#987654' },
|
|
90
|
+
header: { background: '#234567', color: '#abcdef', borderColor: '#987654' },
|
|
91
|
+
underlayBackgroundColor: '#123456',
|
|
92
|
+
interaction: { freezeDividerColor: '#654321' },
|
|
93
|
+
frameStyle: { color: '#987654' }
|
|
94
|
+
})
|
|
95
|
+
} finally {
|
|
96
|
+
restore()
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('未 loadTheme(变量全空):返回 undefined,保持引擎缺省白底', () => {
|
|
101
|
+
const restore = mockThemeVars({})
|
|
102
|
+
try {
|
|
103
|
+
expect(resolveCanvasThemeOverride(document.createElement('div'))).toBeUndefined()
|
|
104
|
+
} finally {
|
|
105
|
+
restore()
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it('任一变量为空:返回 undefined,不半套主题', () => {
|
|
110
|
+
for (const key of Object.keys(THEME_VARS)) {
|
|
111
|
+
const restore = mockThemeVars({ ...THEME_VARS, [key]: '' })
|
|
112
|
+
try {
|
|
113
|
+
expect(resolveCanvasThemeOverride(document.createElement('div'))).toBeUndefined()
|
|
114
|
+
} finally {
|
|
115
|
+
restore()
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
describe('USheet 画布主题跟随', () => {
|
|
122
|
+
it('挂载时主题已生效:构造期 override 进入引擎主题', async () => {
|
|
123
|
+
const restore = mockThemeVars({ ...THEME_VARS })
|
|
124
|
+
try {
|
|
125
|
+
const { exposed } = mount(() => ({ workbook: new Workbook(), rows: 10, cols: 6 }))
|
|
126
|
+
await nextTick()
|
|
127
|
+
|
|
128
|
+
const theme = exposed.value!.getGrid()!.getTable().getTheme()
|
|
129
|
+
expect(theme.body.background).toBe('#123456')
|
|
130
|
+
expect(theme.header.background).toBe('#234567')
|
|
131
|
+
expect(theme.body.color).toBe('#abcdef')
|
|
132
|
+
expect(theme.header.color).toBe('#abcdef')
|
|
133
|
+
expect(theme.body.borderColor).toBe('#987654')
|
|
134
|
+
expect(theme.underlayBackgroundColor).toBe('#123456')
|
|
135
|
+
expect(theme.interaction.freezeDividerColor).toBe('#654321')
|
|
136
|
+
expect(theme.frameStyle.color).toBe('#987654')
|
|
137
|
+
} finally {
|
|
138
|
+
restore()
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('未 loadTheme 挂载:不带 override,保持引擎内置缺省色', async () => {
|
|
143
|
+
const { exposed } = mount(() => ({ workbook: new Workbook(), rows: 10, cols: 6 }))
|
|
144
|
+
await nextTick()
|
|
145
|
+
|
|
146
|
+
const theme = exposed.value!.getGrid()!.getTable().getTheme()
|
|
147
|
+
expect(theme.body.background).toBe('#FFF')
|
|
148
|
+
expect(theme.header.background).toBe('#F5F5F5')
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('loadTheme 实例替换:缓存中所有实例原地 updateTheme,零重建', async () => {
|
|
152
|
+
const workbook = new Workbook()
|
|
153
|
+
workbook.addSheet('Sheet2')
|
|
154
|
+
const { exposed, el } = mount(() => ({ workbook, rows: 10, cols: 6 }))
|
|
155
|
+
await nextTick()
|
|
156
|
+
|
|
157
|
+
// 切到 Sheet2 再切回:两个实例均入缓存(LRU)
|
|
158
|
+
tabs(el)[1]!.click()
|
|
159
|
+
await nextTick()
|
|
160
|
+
const grid2 = exposed.value!.getGrid()!
|
|
161
|
+
tabs(el)[0]!.click()
|
|
162
|
+
await nextTick()
|
|
163
|
+
const grid1 = exposed.value!.getGrid()!
|
|
164
|
+
expect(el.querySelectorAll('.u-sheet__grid-instance')).toHaveLength(2)
|
|
165
|
+
const instancesBefore = [...el.querySelectorAll('.u-sheet__grid-instance')]
|
|
166
|
+
|
|
167
|
+
// 换主题:CSS 变量就位 + loadTheme 替换主题实例 → flush 'post' 后全实例换肤
|
|
168
|
+
const restore = mockThemeVars({ ...THEME_VARS })
|
|
169
|
+
try {
|
|
170
|
+
currentTheme.value = lightTheme
|
|
171
|
+
await nextTick()
|
|
172
|
+
} finally {
|
|
173
|
+
restore()
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// 缓存中所有实例(含隐藏的 Sheet2 实例)都已换肤
|
|
177
|
+
for (const grid of [grid1, grid2]) {
|
|
178
|
+
const theme = grid.getTable().getTheme()
|
|
179
|
+
expect(theme.body.background).toBe('#123456')
|
|
180
|
+
expect(theme.header.background).toBe('#234567')
|
|
181
|
+
expect(theme.interaction.freezeDividerColor).toBe('#654321')
|
|
182
|
+
}
|
|
183
|
+
// 零重建:实例容器与激活实例都是原对象(updateTheme 原地覆盖,不重建网格)
|
|
184
|
+
const instancesAfter = el.querySelectorAll('.u-sheet__grid-instance')
|
|
185
|
+
expect(instancesAfter).toHaveLength(2)
|
|
186
|
+
expect(instancesAfter[0]).toBe(instancesBefore[0])
|
|
187
|
+
expect(instancesAfter[1]).toBe(instancesBefore[1])
|
|
188
|
+
expect(exposed.value!.getGrid()).toBe(grid1)
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
it('主题 token 原地修改(deep):同样触发换肤', async () => {
|
|
192
|
+
const { exposed } = mount(() => ({ workbook: new Workbook(), rows: 10, cols: 6 }))
|
|
193
|
+
await nextTick()
|
|
194
|
+
const grid = exposed.value!.getGrid()!
|
|
195
|
+
|
|
196
|
+
// 实例替换但变量未注入:不换肤,保持缺省白底
|
|
197
|
+
currentTheme.value = lightTheme
|
|
198
|
+
await nextTick()
|
|
199
|
+
expect(grid.getTable().getTheme().body.background).toBe('#FFF')
|
|
200
|
+
|
|
201
|
+
// 主题 token 原地改(reactive deep)→ 重读 CSS 变量 → updateTheme
|
|
202
|
+
const restore = mockThemeVars({ ...THEME_VARS })
|
|
203
|
+
try {
|
|
204
|
+
lightTheme.theme.bg.color.top = '#123456'
|
|
205
|
+
await nextTick()
|
|
206
|
+
} finally {
|
|
207
|
+
restore()
|
|
208
|
+
lightTheme.theme.bg.color.top = '#ffffff'
|
|
209
|
+
}
|
|
210
|
+
expect(grid.getTable().getTheme().body.background).toBe('#123456')
|
|
211
|
+
})
|
|
212
|
+
})
|
|
@@ -24,7 +24,18 @@ export interface ImportFileOptions {
|
|
|
24
24
|
onWorkbookReplaced?: () => void
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
/** worker done 载荷 / 主线程降级解析共用的条目形状(结构化可赋给 SheetReplaceItem) */
|
|
28
|
+
type ParsedXlsx = {
|
|
29
|
+
sheets: {
|
|
30
|
+
name: string
|
|
31
|
+
snapshot: SheetSnapshot
|
|
32
|
+
/** 默认行高 px(模型未声明则不携带) */
|
|
33
|
+
defaultRowHeight?: number
|
|
34
|
+
/** 默认列宽 px(模型未声明则不携带) */
|
|
35
|
+
defaultColWidth?: number
|
|
36
|
+
}[]
|
|
37
|
+
activeIndex: number
|
|
38
|
+
}
|
|
28
39
|
|
|
29
40
|
/**
|
|
30
41
|
* xlsx 解析(worker 优先):importXlsx 是同步重活,主线程直接跑会冻结 UI。
|
|
@@ -79,7 +90,13 @@ async function parseXlsxAsync(
|
|
|
79
90
|
|
|
80
91
|
function toSnapshotArray(wb: Workbook): ParsedXlsx {
|
|
81
92
|
return {
|
|
82
|
-
sheets: wb.getSheets().map((s) => ({
|
|
93
|
+
sheets: wb.getSheets().map((s) => ({
|
|
94
|
+
name: s.name,
|
|
95
|
+
snapshot: s.snapshot(),
|
|
96
|
+
// 模型未声明默认尺寸不序列化(口径同 snapshot() 的条件字段写法)
|
|
97
|
+
...(s.defaultRowHeight !== undefined ? { defaultRowHeight: s.defaultRowHeight } : {}),
|
|
98
|
+
...(s.defaultColWidth !== undefined ? { defaultColWidth: s.defaultColWidth } : {})
|
|
99
|
+
})),
|
|
83
100
|
activeIndex: wb.activeSheetIndex
|
|
84
101
|
}
|
|
85
102
|
}
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
*
|
|
6
6
|
* 协议:主线程 postMessage({ buffer: ArrayBuffer }) → worker 返回
|
|
7
7
|
* - { type: 'progress', done, total }(模型分片构建进度,xlsx 解析段无进度)
|
|
8
|
-
* - { type: 'done', ok: true, sheets: [{ name, snapshot
|
|
9
|
-
*
|
|
8
|
+
* - { type: 'done', ok: true, sheets: [{ name, snapshot, defaultRowHeight?,
|
|
9
|
+
* defaultColWidth? }], activeIndex }(快照为纯数据,可结构化克隆;默认行列
|
|
10
|
+
* 尺寸未声明不携带);失败 { type: 'done', ok: false, error }。
|
|
10
11
|
*
|
|
11
12
|
* 解析与构建经 infinitable/sheet importXlsx 完成(hucre 已内联进引擎统一包);
|
|
12
13
|
* 名字唯一化与活动表对齐在 worker 内完成,主线程直接把快照替换进目标
|
|
@@ -22,7 +23,14 @@ export type ImportWorkerResponse =
|
|
|
22
23
|
| {
|
|
23
24
|
type: 'done'
|
|
24
25
|
ok: true
|
|
25
|
-
sheets: {
|
|
26
|
+
sheets: {
|
|
27
|
+
name: string
|
|
28
|
+
snapshot: SheetSnapshot
|
|
29
|
+
/** 默认行高 px(模型未声明则不携带;形状同上游 SheetReplaceItem 对应字段) */
|
|
30
|
+
defaultRowHeight?: number
|
|
31
|
+
/** 默认列宽 px(模型未声明则不携带;形状同上游 SheetReplaceItem 对应字段) */
|
|
32
|
+
defaultColWidth?: number
|
|
33
|
+
}[]
|
|
26
34
|
activeIndex: number
|
|
27
35
|
}
|
|
28
36
|
| { type: 'done'; ok: false; error: string }
|
|
@@ -43,7 +51,13 @@ self.onmessage = (e: MessageEvent<{ buffer: ArrayBuffer }>): void => {
|
|
|
43
51
|
;(self as unknown as Worker).postMessage(progress)
|
|
44
52
|
}
|
|
45
53
|
})
|
|
46
|
-
const sheets = wb.getSheets().map((s) => ({
|
|
54
|
+
const sheets = wb.getSheets().map((s) => ({
|
|
55
|
+
name: s.name,
|
|
56
|
+
snapshot: s.snapshot(),
|
|
57
|
+
// 模型未声明默认尺寸不序列化(口径同 snapshot() 的条件字段写法)
|
|
58
|
+
...(s.defaultRowHeight !== undefined ? { defaultRowHeight: s.defaultRowHeight } : {}),
|
|
59
|
+
...(s.defaultColWidth !== undefined ? { defaultColWidth: s.defaultColWidth } : {})
|
|
60
|
+
}))
|
|
47
61
|
const response: ImportWorkerResponse = {
|
|
48
62
|
type: 'done',
|
|
49
63
|
ok: true,
|
|
@@ -106,6 +106,10 @@ function insertCountRender(options: {
|
|
|
106
106
|
export interface HeaderMenuOptions {
|
|
107
107
|
/** 只读模式:行高/列宽项禁用(尺寸写入属编辑操作) */
|
|
108
108
|
readonly?: boolean
|
|
109
|
+
/** 右键命中的行号(行头菜单):冻结以点击行为准,缺省回落选区末端 */
|
|
110
|
+
row?: number
|
|
111
|
+
/** 右键命中的列号(列头菜单):冻结以点击列为准,缺省回落选区末端 */
|
|
112
|
+
col?: number
|
|
109
113
|
}
|
|
110
114
|
|
|
111
115
|
/**
|
|
@@ -148,7 +152,11 @@ export function buildRowHeaderMenus(
|
|
|
148
152
|
const rowCount = defaultInsertCount(range, 'row')
|
|
149
153
|
const deleteCount = range ? endRow - startRow + 1 : 1
|
|
150
154
|
const frozen = ctx.frozen
|
|
151
|
-
|
|
155
|
+
// 冻结目标 = 右键命中的行;缺省回落选区末端。不能直接用选区末端:先冻结行的
|
|
156
|
+
// 整行选区横跨全部列,随后列头右键判定「在选区内」保留选区,选区末端列会把
|
|
157
|
+
// 冻结列放大到全部列(反之亦然),表现为冻结不生效
|
|
158
|
+
const freezeRow = (options?.row ?? endRow) + 1
|
|
159
|
+
const freezeActive = frozen.rows === freezeRow
|
|
152
160
|
|
|
153
161
|
return [
|
|
154
162
|
{
|
|
@@ -181,7 +189,7 @@ export function buildRowHeaderMenus(
|
|
|
181
189
|
{ divider: true },
|
|
182
190
|
{
|
|
183
191
|
label: freezeActive ? '✓ 冻结到当前行' : '冻结到当前行',
|
|
184
|
-
callback: () => ctx.setFrozen(
|
|
192
|
+
callback: () => ctx.setFrozen(freezeRow, frozen.cols)
|
|
185
193
|
},
|
|
186
194
|
{
|
|
187
195
|
label: '取消冻结',
|
|
@@ -202,7 +210,9 @@ export function buildColHeaderMenus(
|
|
|
202
210
|
const colCount = defaultInsertCount(range, 'col')
|
|
203
211
|
const deleteCount = range ? endCol - startCol + 1 : 1
|
|
204
212
|
const frozen = ctx.frozen
|
|
205
|
-
|
|
213
|
+
// 冻结目标 = 右键命中的列(同 buildRowHeaderMenus:整行/整列选区残留时选区末端会放大冻结范围)
|
|
214
|
+
const freezeCol = (options?.col ?? endCol) + 1
|
|
215
|
+
const freezeActive = frozen.cols === freezeCol
|
|
206
216
|
|
|
207
217
|
return [
|
|
208
218
|
{
|
|
@@ -235,7 +245,7 @@ export function buildColHeaderMenus(
|
|
|
235
245
|
{ divider: true },
|
|
236
246
|
{
|
|
237
247
|
label: freezeActive ? '✓ 冻结到当前列' : '冻结到当前列',
|
|
238
|
-
callback: () => ctx.setFrozen(frozen.rows,
|
|
248
|
+
callback: () => ctx.setFrozen(frozen.rows, freezeCol)
|
|
239
249
|
},
|
|
240
250
|
{
|
|
241
251
|
label: '取消冻结',
|
|
@@ -113,10 +113,9 @@ const props = withDefaults(defineProps<SheetProps>(), {
|
|
|
113
113
|
showColHeader: true,
|
|
114
114
|
readonly: false,
|
|
115
115
|
colResize: false,
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
scrollbar: { mode: 'native' },
|
|
116
|
+
// 缺省画布常驻档:true 经引擎归一化为 canvas always + reserve——滚动条常驻
|
|
117
|
+
// 画在画布内,reserve 只在画布内预留轨道(不占页面布局、不遮挡单元格)
|
|
118
|
+
scrollbar: true,
|
|
120
119
|
// 显式对齐引擎当前缺省(true 近边增长):boolean prop 不写 default 会被
|
|
121
120
|
// Vue 铸成 false,把引擎缺省翻成固定尺寸网格
|
|
122
121
|
growOnScroll: true
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { contextmenu } from '@veltra/desktop'
|
|
2
|
+
import { currentTheme } from '@veltra/styles/theme'
|
|
3
|
+
import type { ThemeOverride } from 'infinitable'
|
|
2
4
|
import type { CellAddress, CellRange } from 'infinitable/sheet'
|
|
3
5
|
import type { Sheet } from 'infinitable/sheet'
|
|
4
6
|
import { SheetGrid, type SheetGridContextMenuInfo } from 'infinitable/sheet'
|
|
@@ -63,6 +65,34 @@ interface CachedGrid {
|
|
|
63
65
|
*/
|
|
64
66
|
const GRID_CACHE_CAPACITY = 3
|
|
65
67
|
|
|
68
|
+
/**
|
|
69
|
+
* 画布主题映射:读 grid 宿主元素上生效的 `--u-*` CSS 变量(loadTheme 注入 html、
|
|
70
|
+
* 继承到宿主),换算为引擎 `ThemeOverride`——画布底色 / 表头 / 文字 / 网格线 /
|
|
71
|
+
* 冻结分隔线跟随 UI 主题。rowHeader / corner 由引擎随生效 header 派生,无需单写。
|
|
72
|
+
*
|
|
73
|
+
* 任一变量为空(未 loadTheme)返回 `undefined`:SheetGrid 不传 theme、保持引擎
|
|
74
|
+
* 缺省白底,不破坏无主题环境。
|
|
75
|
+
*/
|
|
76
|
+
export function resolveCanvasThemeOverride(el: HTMLElement): ThemeOverride | undefined {
|
|
77
|
+
const style = getComputedStyle(el)
|
|
78
|
+
const bgColorTop = style.getPropertyValue('--u-bg-color-top').trim()
|
|
79
|
+
const bgColorBottom = style.getPropertyValue('--u-bg-color-bottom').trim()
|
|
80
|
+
const textColorMain = style.getPropertyValue('--u-text-color-main').trim()
|
|
81
|
+
const borderColor = style.getPropertyValue('--u-border-color').trim()
|
|
82
|
+
const borderMutedColor = style.getPropertyValue('--u-border-muted-color').trim()
|
|
83
|
+
if (!bgColorTop || !bgColorBottom || !textColorMain || !borderColor || !borderMutedColor) {
|
|
84
|
+
return undefined
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
// 底色与 .u-sheet 外层同底;underlay 是数据区外空白处直接可见的底
|
|
88
|
+
body: { background: bgColorTop, color: textColorMain, borderColor },
|
|
89
|
+
header: { background: bgColorBottom, color: textColorMain, borderColor },
|
|
90
|
+
underlayBackgroundColor: bgColorTop,
|
|
91
|
+
interaction: { freezeDividerColor: borderMutedColor },
|
|
92
|
+
frameStyle: { color: borderColor }
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
66
96
|
/**
|
|
67
97
|
* SheetGrid 生命周期与网格右键菜单(LRU 实例缓存):
|
|
68
98
|
* - activateGrid:tab 切换入口——命中缓存 → 显示 + 模型同步(零重建);
|
|
@@ -86,9 +116,9 @@ export function useSheetGrid(options: UseSheetGridOptions) {
|
|
|
86
116
|
|
|
87
117
|
const menus =
|
|
88
118
|
info.kind === 'row-header'
|
|
89
|
-
? buildRowHeaderMenus(context, { readonly: props.readonly })
|
|
119
|
+
? buildRowHeaderMenus(context, { readonly: props.readonly, row: info.row })
|
|
90
120
|
: info.kind === 'col-header'
|
|
91
|
-
? buildColHeaderMenus(context, { readonly: props.readonly })
|
|
121
|
+
? buildColHeaderMenus(context, { readonly: props.readonly, col: info.col })
|
|
92
122
|
: buildBodyMenus(context)
|
|
93
123
|
|
|
94
124
|
// 最小宽度兜底;实际宽度由最长菜单项撑开(勿固定 240 导致空白过大)
|
|
@@ -133,6 +163,9 @@ export function useSheetGrid(options: UseSheetGridOptions) {
|
|
|
133
163
|
colResize: props.colResize,
|
|
134
164
|
scrollbar: props.scrollbar,
|
|
135
165
|
growOnScroll: props.growOnScroll,
|
|
166
|
+
// 画布跟随 UI 主题:loadTheme 注入的 CSS 变量换算为引擎 override
|
|
167
|
+
//(未 loadTheme 时为 undefined,引擎保持缺省白底)
|
|
168
|
+
theme: resolveCanvasThemeOverride(host),
|
|
136
169
|
onContextMenu: handleContextMenu,
|
|
137
170
|
onEditStart: (addr) => formulaBarRef.value?.mirrorGridEdit(addr),
|
|
138
171
|
onEditEnd: (addr) => formulaBarRef.value?.exitMirror(addr),
|
|
@@ -291,6 +324,23 @@ export function useSheetGrid(options: UseSheetGridOptions) {
|
|
|
291
324
|
invalidateAll()
|
|
292
325
|
})
|
|
293
326
|
|
|
327
|
+
// 主题切换换肤:loadTheme 换实例(ref 替换)或主题 token 原地改(deep)后,
|
|
328
|
+
// 等 UITheme 把 CSS 变量渲染进 html(flush: 'post' 晚于其渲染)再重读映射,
|
|
329
|
+
// 对缓存中所有实例原地 updateTheme——零重建,滚动 / 选区 / 冻结等运行时状态
|
|
330
|
+
// 不受影响;未 loadTheme(解析为 undefined)时不动,保持引擎缺省白底
|
|
331
|
+
watch(
|
|
332
|
+
[() => currentTheme.value?.theme, currentTheme],
|
|
333
|
+
() => {
|
|
334
|
+
const host = gridRef.value
|
|
335
|
+
const override = host ? resolveCanvasThemeOverride(host) : undefined
|
|
336
|
+
if (!override) return
|
|
337
|
+
for (const item of cache.values()) {
|
|
338
|
+
item.grid.updateTheme(override)
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
{ deep: true, flush: 'post' }
|
|
342
|
+
)
|
|
343
|
+
|
|
294
344
|
/** fx 引用拾取会话置/清选区锚点(公式栏 → 活动实例透传;无活动实例时静默) */
|
|
295
345
|
function setSelectionAnchor(addr: CellAddress | null): void {
|
|
296
346
|
active?.grid.setSelectionAnchor(addr)
|
package/src/types/sheet.ts
CHANGED
|
@@ -5,7 +5,6 @@ import type {
|
|
|
5
5
|
ResolveCellRenderer,
|
|
6
6
|
ResolveCellStyleHook,
|
|
7
7
|
ResolveDisplayValue,
|
|
8
|
-
ScrollbarOptions,
|
|
9
8
|
SheetGrid,
|
|
10
9
|
SheetGridEditorsOptions,
|
|
11
10
|
SheetGridHeaderOptions
|
|
@@ -65,13 +64,11 @@ export interface SheetProps {
|
|
|
65
64
|
colResize?: boolean
|
|
66
65
|
/**
|
|
67
66
|
* 滚动条(透传 SheetGrid → 引擎内建,构造期选项):false 整体关闭(不显示任何
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* canvas 档显示策略)。对象形态引用更替触发网格重建——沿用 header / editors
|
|
72
|
-
* 的稳定引用约定,宿主勿在模板内联对象字面量
|
|
67
|
+
* 滚动条);缺省 true 画布常驻档——引擎归一化 canvas always + reserve,滚动条
|
|
68
|
+
* 常驻画在画布内(reserve 只在画布内预留轨道,不占页面布局、不遮挡单元格)。
|
|
69
|
+
* 变化触发网格重建
|
|
73
70
|
*/
|
|
74
|
-
scrollbar?: boolean
|
|
71
|
+
scrollbar?: boolean
|
|
75
72
|
/**
|
|
76
73
|
* 滚动近端动态增长(透传 SheetGrid,构造期选项):滚动缓冲末端触到当前行列数
|
|
77
74
|
* 时模型与引擎同步扩容(引擎缺省 true);false 为固定尺寸网格——内容定尺寸的
|