@veltra/sheet 2.0.0 → 2.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/index.d.ts +4 -25
- package/dist/index.js +3 -22
- package/dist/tools/builtin.js +279 -8
- package/dist/tools/context.d.ts +54 -11
- package/dist/tools/context.js +28 -5
- package/dist/tools/download.js +68 -0
- package/dist/tools/export.worker.d.ts +16 -0
- package/dist/tools/export.worker.js +29 -0
- package/dist/tools/registry.d.ts +7 -4
- package/dist/tools/registry.js +1 -3
- package/dist/types/index.d.ts +1 -0
- package/dist/types/sheet.d.ts +6 -5
- package/dist/vue/formula-bar.js +393 -0
- package/dist/vue/formula-suggest-list.js +66 -0
- package/dist/vue/import-file.js +140 -0
- package/dist/vue/insert-count-menu-item.js +68 -0
- package/dist/vue/insert-image.js +79 -0
- package/dist/vue/popup-helpers.js +73 -0
- package/dist/vue/popups/border-popup.js +75 -0
- package/dist/vue/popups/border-preset-glyph.js +106 -0
- package/dist/vue/popups/export-popup.js +51 -0
- package/dist/vue/popups/fill-color-popup.js +37 -0
- package/dist/vue/popups/find-popup.js +113 -0
- package/dist/vue/popups/font-color-popup.js +37 -0
- package/dist/vue/popups/font-size-popup.js +63 -0
- package/dist/vue/popups/import.worker.d.ts +21 -0
- package/dist/vue/popups/import.worker.js +41 -0
- package/dist/vue/popups/insert-image-popup.js +38 -0
- package/dist/vue/sheet-context-menu.js +200 -0
- package/dist/vue/sheet-tabs.js +162 -0
- package/dist/vue/sheet-toolbar.js +106 -0
- package/dist/vue/sheet.js +144 -138
- package/dist/vue/style.d.ts +11 -1
- package/dist/vue/style.js +11 -0
- package/dist/vue/style2.css +564 -3
- package/dist/vue/use-find-replace.js +161 -0
- package/dist/vue/use-formula-ref-select.js +37 -0
- package/dist/vue/use-formula-suggest.js +126 -0
- package/dist/vue/use-sheet-grid.js +180 -0
- package/dist/vue/use-sheet-state.js +122 -0
- package/dist/vue/use-sheet-tabs-bar.js +90 -0
- package/dist/vue/use-tool-groups.js +42 -0
- package/dist/vue/use-tool-popup.js +123 -0
- package/dist/vue/use-toolbar-scroll.js +72 -0
- package/package.json +12 -6
- package/src/env.d.ts +14 -0
- package/src/index.ts +203 -13
- package/src/tools/__test__/builtin.test.ts +208 -66
- package/src/tools/__test__/context.test.ts +62 -2
- package/src/tools/builtin.ts +350 -6
- package/src/tools/context.ts +89 -11
- package/src/tools/download.ts +82 -0
- package/src/tools/export.worker.ts +61 -0
- package/src/tools/registry.ts +16 -1
- package/src/types/index.ts +6 -0
- package/src/types/sheet.ts +5 -3
- package/src/vue/__test__/formula-bar.test.ts +455 -0
- package/src/vue/__test__/import-file.test.ts +183 -0
- package/src/vue/__test__/insert-count-menu-item.test.ts +123 -0
- package/src/vue/__test__/insert-image-popup.test.ts +89 -0
- package/src/vue/__test__/insert-image.test.ts +100 -0
- package/src/vue/__test__/sheet-component.test.ts +716 -27
- package/src/vue/__test__/sheet-context-menu.test.ts +206 -0
- package/src/vue/__test__/use-formula-ref-select.test.ts +35 -0
- package/src/vue/__test__/use-formula-suggest.test.ts +83 -0
- package/src/vue/formula-bar.vue +473 -0
- package/src/vue/formula-suggest-list.vue +64 -0
- package/src/vue/import-file.ts +173 -0
- package/src/vue/insert-count-menu-item.vue +69 -0
- package/src/vue/insert-image.ts +90 -0
- package/src/vue/parsing.ts +11 -0
- package/src/vue/popup-helpers.ts +50 -0
- package/src/vue/popups/border-popup.vue +93 -0
- package/src/vue/popups/border-preset-glyph.vue +111 -0
- package/src/vue/popups/export-popup.vue +52 -0
- package/src/vue/popups/fill-color-popup.vue +39 -0
- package/src/vue/popups/find-popup.vue +111 -0
- package/src/vue/popups/font-color-popup.vue +39 -0
- package/src/vue/popups/font-size-popup.vue +52 -0
- package/src/vue/popups/import.worker.ts +66 -0
- package/src/vue/popups/insert-image-popup.vue +39 -0
- package/src/vue/sheet-context-menu.ts +229 -0
- package/src/vue/sheet-tabs.vue +162 -0
- package/src/vue/sheet-toolbar.vue +91 -0
- package/src/vue/sheet.vue +163 -148
- package/src/vue/style.scss +646 -3
- package/src/vue/style.ts +12 -0
- package/src/vue/use-find-replace.ts +200 -0
- package/src/vue/use-formula-ref-select.ts +34 -0
- package/src/vue/use-formula-suggest.ts +150 -0
- package/src/vue/use-sheet-grid.ts +243 -0
- package/src/vue/use-sheet-state.ts +161 -0
- package/src/vue/use-sheet-tabs-bar.ts +115 -0
- package/src/vue/use-tool-groups.ts +61 -0
- package/src/vue/use-tool-popup.ts +150 -0
- package/src/vue/use-toolbar-scroll.ts +95 -0
- package/dist/core/address.d.ts +0 -60
- package/dist/core/address.js +0 -142
- package/dist/core/address.js.map +0 -1
- package/dist/core/cell-store.d.ts +0 -61
- package/dist/core/cell-store.js +0 -135
- package/dist/core/cell-store.js.map +0 -1
- package/dist/core/command/default-registry.d.ts +0 -10
- package/dist/core/command/default-registry.js +0 -18
- package/dist/core/command/default-registry.js.map +0 -1
- package/dist/core/command/history.d.ts +0 -64
- package/dist/core/command/history.js +0 -127
- package/dist/core/command/history.js.map +0 -1
- package/dist/core/command/merge-cells.d.ts +0 -21
- package/dist/core/command/merge-cells.js +0 -74
- package/dist/core/command/merge-cells.js.map +0 -1
- package/dist/core/command/registry.d.ts +0 -17
- package/dist/core/command/registry.js +0 -26
- package/dist/core/command/registry.js.map +0 -1
- package/dist/core/command/set-cell-formula.d.ts +0 -17
- package/dist/core/command/set-cell-formula.js +0 -29
- package/dist/core/command/set-cell-formula.js.map +0 -1
- package/dist/core/command/set-cell-value.d.ts +0 -22
- package/dist/core/command/set-cell-value.js +0 -35
- package/dist/core/command/set-cell-value.js.map +0 -1
- package/dist/core/command/types.d.ts +0 -68
- package/dist/core/events.js +0 -29
- package/dist/core/events.js.map +0 -1
- package/dist/core/formula/ast.d.ts +0 -58
- package/dist/core/formula/ast.js +0 -38
- package/dist/core/formula/ast.js.map +0 -1
- package/dist/core/formula/dependency-graph.d.ts +0 -70
- package/dist/core/formula/dependency-graph.js +0 -269
- package/dist/core/formula/dependency-graph.js.map +0 -1
- package/dist/core/formula/errors.d.ts +0 -25
- package/dist/core/formula/errors.js +0 -36
- package/dist/core/formula/errors.js.map +0 -1
- package/dist/core/formula/evaluator.d.ts +0 -41
- package/dist/core/formula/evaluator.js +0 -154
- package/dist/core/formula/evaluator.js.map +0 -1
- package/dist/core/formula/functions.d.ts +0 -30
- package/dist/core/formula/functions.js +0 -209
- package/dist/core/formula/functions.js.map +0 -1
- package/dist/core/formula/parser.d.ts +0 -7
- package/dist/core/formula/parser.js +0 -208
- package/dist/core/formula/parser.js.map +0 -1
- package/dist/core/formula/tokenizer.d.ts +0 -37
- package/dist/core/formula/tokenizer.js +0 -146
- package/dist/core/formula/tokenizer.js.map +0 -1
- package/dist/core/merge-manager.d.ts +0 -64
- package/dist/core/merge-manager.js +0 -111
- package/dist/core/merge-manager.js.map +0 -1
- package/dist/core/selection.d.ts +0 -31
- package/dist/core/selection.js +0 -62
- package/dist/core/selection.js.map +0 -1
- package/dist/core/sheet.d.ts +0 -105
- package/dist/core/sheet.js +0 -202
- package/dist/core/sheet.js.map +0 -1
- package/dist/core/workbook.d.ts +0 -43
- package/dist/core/workbook.js +0 -77
- package/dist/core/workbook.js.map +0 -1
- package/dist/grid/sheet-grid.d.ts +0 -59
- package/dist/grid/sheet-grid.js +0 -230
- package/dist/grid/sheet-grid.js.map +0 -1
- package/dist/tools/builtin.js.map +0 -1
- package/dist/tools/context.js.map +0 -1
- package/dist/tools/registry.js.map +0 -1
- package/dist/vue/index.d.ts +0 -2
- package/dist/vue/sheet.js.map +0 -1
- package/dist/vue/sheet.vue.d.ts +0 -24
- package/src/core/__test__/address.test.ts +0 -113
- package/src/core/__test__/cell-store.test.ts +0 -97
- package/src/core/__test__/command.test.ts +0 -377
- package/src/core/__test__/formula-adversarial.test.ts +0 -265
- package/src/core/__test__/formula-engine.test.ts +0 -470
- package/src/core/__test__/formula-functions.test.ts +0 -178
- package/src/core/__test__/formula-parser.test.ts +0 -160
- package/src/core/__test__/history.test.ts +0 -225
- package/src/core/__test__/merge-manager.test.ts +0 -106
- package/src/core/__test__/sheet.test.ts +0 -142
- package/src/core/address.ts +0 -166
- package/src/core/cell-store.ts +0 -173
- package/src/core/command/default-registry.ts +0 -15
- package/src/core/command/history.ts +0 -167
- package/src/core/command/index.ts +0 -7
- package/src/core/command/merge-cells.ts +0 -74
- package/src/core/command/registry.ts +0 -30
- package/src/core/command/set-cell-formula.ts +0 -29
- package/src/core/command/set-cell-value.ts +0 -38
- package/src/core/command/types.ts +0 -73
- package/src/core/events.ts +0 -37
- package/src/core/formula/ast.ts +0 -66
- package/src/core/formula/dependency-graph.ts +0 -329
- package/src/core/formula/errors.ts +0 -41
- package/src/core/formula/evaluator.ts +0 -219
- package/src/core/formula/functions.ts +0 -266
- package/src/core/formula/index.ts +0 -7
- package/src/core/formula/parser.ts +0 -198
- package/src/core/formula/tokenizer.ts +0 -160
- package/src/core/merge-manager.ts +0 -158
- package/src/core/selection.ts +0 -66
- package/src/core/sheet.ts +0 -257
- package/src/core/workbook.ts +0 -99
- package/src/grid/__test__/canvas-mock.ts +0 -49
- package/src/grid/__test__/setup.ts +0 -3
- package/src/grid/__test__/sheet-grid-formula.test.ts +0 -140
- package/src/grid/__test__/sheet-grid.test.ts +0 -177
- package/src/grid/sheet-grid.ts +0 -283
package/src/grid/sheet-grid.ts
DELETED
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
import { ListTable, register } from '@visactor/vtable'
|
|
2
|
-
import type { ListTableConstructorOptions } from '@visactor/vtable'
|
|
3
|
-
import { InputEditor } from '@visactor/vtable-editors'
|
|
4
|
-
import type { EditContext } from '@visactor/vtable-editors'
|
|
5
|
-
|
|
6
|
-
import type { CellAddress } from '../core/address'
|
|
7
|
-
import { cellKey, colIndexToName, createRange } from '../core/address'
|
|
8
|
-
import type { CellValue } from '../core/cell-store'
|
|
9
|
-
import type { Sheet } from '../core/sheet'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* VTable 适配层:数据模型完全自持有,ListTable 只做渲染与输入。
|
|
13
|
-
*
|
|
14
|
-
* - 模型 → VTable:records 由 store 行视图桥接;customMergeCell 闭包直读 MergeManager
|
|
15
|
-
* (VTable 逐格动态求值、无缓存,合并变更后 setRecords 重建场景树即生效)
|
|
16
|
-
* - VTable → 模型:change_cell_value 回写 store;selected_cell 经 resolveAnchor 更新选区
|
|
17
|
-
* - 公式:公式格 record 存计算缓存(显示值);进入编辑时编辑器显示公式原文('=f')。
|
|
18
|
-
* 编辑提交期间模型变更(含公式重算派生格)先入待同步队列,提交结束统一回推表格——
|
|
19
|
-
* VTable 自己只更新了被编辑格的 record(还是输入文本),派生格它不知道
|
|
20
|
-
* - 键盘:容器 keydown 绑定 undo/redo(Cmd/Ctrl+Z、Cmd/Ctrl+Shift+Z、Ctrl+Y),
|
|
21
|
-
* 编辑器 input 打开时不拦截
|
|
22
|
-
* - 坐标换算:行号列不计入 rowHeaderLevelCount,偏移量在首个表格实例上
|
|
23
|
-
* 用 columnHeaderLevelCount + isSeriesNumber 实测并缓存(见 getOffsets)
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/** 公式感知编辑器:进入编辑时公式格显示原文(同 Excel),其余格显示当前值 */
|
|
27
|
-
class FormulaAwareInputEditor extends InputEditor {
|
|
28
|
-
/** 由 SheetGrid 注入:返回进入编辑时应显示的文本;undefined = 用 VTable 默认值 */
|
|
29
|
-
resolveEditText?: (col: number, row: number) => string | undefined
|
|
30
|
-
|
|
31
|
-
override onStart(context: EditContext<string>): void {
|
|
32
|
-
const text = this.resolveEditText?.(context.col, context.row)
|
|
33
|
-
super.onStart(text === undefined ? context : { ...context, value: text })
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** 编辑器按 grid 实例注册(hook 闭包各自 sheet),名称递增防冲突 */
|
|
38
|
-
let editorSeq = 0
|
|
39
|
-
|
|
40
|
-
export interface SheetGridOptions {
|
|
41
|
-
container: HTMLElement
|
|
42
|
-
sheet: Sheet
|
|
43
|
-
/** 渲染行数,默认 100 */
|
|
44
|
-
rows?: number
|
|
45
|
-
/** 渲染列数,默认 26(A..Z) */
|
|
46
|
-
cols?: number
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export class SheetGrid {
|
|
50
|
-
private readonly sheet: Sheet
|
|
51
|
-
private readonly table: ListTable
|
|
52
|
-
private readonly container: HTMLElement
|
|
53
|
-
private readonly rows: number
|
|
54
|
-
private readonly cols: number
|
|
55
|
-
private readonly editorName: string
|
|
56
|
-
private readonly disposers: (() => void)[] = []
|
|
57
|
-
/** 编辑提交期间累积的模型变更(提交结束统一回推表格,覆盖公式派生格) */
|
|
58
|
-
private pendingTableSync: Map<number, CellAddress> | null = null
|
|
59
|
-
/** 实测坐标偏移(行号列数 / 列头行数),首次使用时测量 */
|
|
60
|
-
private offsets?: { colOffset: number; rowOffset: number }
|
|
61
|
-
|
|
62
|
-
constructor(options: SheetGridOptions) {
|
|
63
|
-
this.sheet = options.sheet
|
|
64
|
-
this.container = options.container
|
|
65
|
-
this.rows = options.rows ?? 100
|
|
66
|
-
this.cols = options.cols ?? 26
|
|
67
|
-
|
|
68
|
-
// 每个 grid 实例注册自己的编辑器(hook 闭包本实例的 sheet 与坐标换算)
|
|
69
|
-
this.editorName = `veltra-sheet-input-${editorSeq++}`
|
|
70
|
-
const editor = new FormulaAwareInputEditor()
|
|
71
|
-
editor.resolveEditText = (col, row) => {
|
|
72
|
-
const addr = this.toSheetAddr(this.table, col, row)
|
|
73
|
-
if (!addr) return undefined
|
|
74
|
-
const data = this.sheet.getCellData(this.sheet.merges.resolveAnchor(addr))
|
|
75
|
-
return data?.f ? `=${data.f}` : undefined
|
|
76
|
-
}
|
|
77
|
-
register.editor(this.editorName, editor)
|
|
78
|
-
|
|
79
|
-
this.table = new ListTable(options.container, this.buildOptions())
|
|
80
|
-
this.bindTableEvents()
|
|
81
|
-
this.bindSheetEvents()
|
|
82
|
-
this.bindKeyboard()
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** 底层 ListTable 实例(调试与测试用) */
|
|
86
|
-
getTable(): ListTable {
|
|
87
|
-
return this.table
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** 全量刷新(合并结构变化、批量数据变更后调用) */
|
|
91
|
-
refresh(): void {
|
|
92
|
-
this.table.setRecords(this.buildRecords())
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** 撤销一步(模型命令历史) */
|
|
96
|
-
undo(): boolean {
|
|
97
|
-
return this.sheet.undo()
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** 重做一步(模型命令历史) */
|
|
101
|
-
redo(): boolean {
|
|
102
|
-
return this.sheet.redo()
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
release(): void {
|
|
106
|
-
for (const dispose of this.disposers) dispose()
|
|
107
|
-
this.disposers.length = 0
|
|
108
|
-
this.table.release()
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// ─── 坐标换算 ─────────────────────────────────────────────
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* 实测偏移:列头行数取 columnHeaderLevelCount;
|
|
115
|
-
* 行号列不被计入 rowHeaderLevelCount,用 isSeriesNumber 逐列探测。
|
|
116
|
-
* 结果缓存(表格实例不变,布局不变)。
|
|
117
|
-
*/
|
|
118
|
-
private getOffsets(table: ListTable): { colOffset: number; rowOffset: number } {
|
|
119
|
-
if (!this.offsets) {
|
|
120
|
-
const rowOffset = table.columnHeaderLevelCount
|
|
121
|
-
let colOffset = 0
|
|
122
|
-
while (colOffset < table.colCount && table.isSeriesNumber(colOffset, rowOffset)) colOffset++
|
|
123
|
-
this.offsets = { colOffset, rowOffset }
|
|
124
|
-
}
|
|
125
|
-
return this.offsets
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** VTable 坐标 → 模型地址;行号列/列头返回 null */
|
|
129
|
-
private toSheetAddr(table: ListTable, col: number, row: number): CellAddress | null {
|
|
130
|
-
const { colOffset, rowOffset } = this.getOffsets(table)
|
|
131
|
-
const addr = { row: row - rowOffset, col: col - colOffset }
|
|
132
|
-
if (addr.row < 0 || addr.col < 0) return null
|
|
133
|
-
return addr
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/** 模型地址 → VTable 坐标 */
|
|
137
|
-
private toTableCoord(table: ListTable, addr: CellAddress): { col: number; row: number } {
|
|
138
|
-
const { colOffset, rowOffset } = this.getOffsets(table)
|
|
139
|
-
return { col: addr.col + colOffset, row: addr.row + rowOffset }
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// ─── 模型 → VTable ────────────────────────────────────────
|
|
143
|
-
|
|
144
|
-
private buildColumns() {
|
|
145
|
-
return Array.from({ length: this.cols }, (_, col) => ({
|
|
146
|
-
field: String(col),
|
|
147
|
-
title: colIndexToName(col)
|
|
148
|
-
}))
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
private buildRecords(): Record<string, CellValue>[] {
|
|
152
|
-
const records: Record<string, CellValue>[] = Array.from({ length: this.rows }, () => ({}))
|
|
153
|
-
for (const [addr, data] of this.sheet.store.entries()) {
|
|
154
|
-
if (addr.row < this.rows && addr.col < this.cols && data.v != null) {
|
|
155
|
-
records[addr.row]![String(addr.col)] = data.v
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return records
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
private buildOptions(): ListTableConstructorOptions {
|
|
162
|
-
return {
|
|
163
|
-
records: this.buildRecords(),
|
|
164
|
-
columns: this.buildColumns(),
|
|
165
|
-
widthMode: 'standard',
|
|
166
|
-
rowSeriesNumber: { width: 46 },
|
|
167
|
-
editor: this.editorName,
|
|
168
|
-
editCellTrigger: 'doubleclick',
|
|
169
|
-
keyboardOptions: {
|
|
170
|
-
moveFocusCellOnTab: true,
|
|
171
|
-
editCellOnEnter: true,
|
|
172
|
-
moveFocusCellOnEnter: true,
|
|
173
|
-
moveEditCellOnArrowKeys: true,
|
|
174
|
-
selectAllOnCtrlA: true
|
|
175
|
-
},
|
|
176
|
-
customMergeCell: (col, row, table) => {
|
|
177
|
-
const addr = this.toSheetAddr(table as ListTable, col, row)
|
|
178
|
-
if (!addr) return undefined
|
|
179
|
-
const merge = this.sheet.merges.getMergeAt(addr)
|
|
180
|
-
if (!merge) return undefined
|
|
181
|
-
const anchorCoord = this.toTableCoord(table as ListTable, merge.start)
|
|
182
|
-
const recordValue = (table as ListTable).getCellOriginValue(
|
|
183
|
-
anchorCoord.col,
|
|
184
|
-
anchorCoord.row
|
|
185
|
-
)
|
|
186
|
-
return {
|
|
187
|
-
range: { start: anchorCoord, end: this.toTableCoord(table as ListTable, merge.end) },
|
|
188
|
-
// 关键 1:必须携带 text。VTable 的 getCellRange 仅在 text/customLayout/
|
|
189
|
-
// customRender 有效时才认这个自定义合并——没有 text 时选区与编辑不会
|
|
190
|
-
// 扩展为整个合并区域,且合并格渲染为空。
|
|
191
|
-
// 关键 2:text 必须读 VTable records 而非模型。编辑提交的顺序是
|
|
192
|
-
// 先更新 record → 重绘 → 最后才发 change_cell_value 回写模型;
|
|
193
|
-
// 若此时读模型,拿到的还是回写前的旧值(合并格显示旧文本)。
|
|
194
|
-
text: recordValue == null ? '' : String(recordValue)
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// ─── 事件桥接 ─────────────────────────────────────────────
|
|
201
|
-
|
|
202
|
-
private bindTableEvents(): void {
|
|
203
|
-
this.table.on(ListTable.EVENT_TYPE.CHANGE_CELL_VALUE, (args) => {
|
|
204
|
-
const addr = this.toSheetAddr(this.table, args.col, args.row)
|
|
205
|
-
if (addr == null) return
|
|
206
|
-
// 编辑提交期间模型变更(含公式重算派生格)先入队列,提交结束统一回推。
|
|
207
|
-
// 被编辑格自身也入队:VTable 已把输入文本写进 record,公式格需回推计算值
|
|
208
|
-
this.pendingTableSync = new Map([[cellKey(addr), addr]])
|
|
209
|
-
try {
|
|
210
|
-
this.sheet.setCellValue(addr, args.changedValue ?? null)
|
|
211
|
-
} finally {
|
|
212
|
-
const pending = this.pendingTableSync
|
|
213
|
-
this.pendingTableSync = null
|
|
214
|
-
if (pending) {
|
|
215
|
-
for (const pendingAddr of pending.values()) this.pushCellToTable(pendingAddr)
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
this.table.on(ListTable.EVENT_TYPE.SELECTED_CELL, (args) => {
|
|
221
|
-
const addr = this.toSheetAddr(this.table, args.col, args.row)
|
|
222
|
-
if (addr == null) return
|
|
223
|
-
this.sheet.selectCell(addr)
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
// 拖选结束 → 选区同步为区域(合并等区域操作的前提)
|
|
227
|
-
this.table.on(ListTable.EVENT_TYPE.DRAG_SELECT_END, () => {
|
|
228
|
-
const range = this.table.getSelectedCellRanges()[0]
|
|
229
|
-
if (!range) return
|
|
230
|
-
const start = this.toSheetAddr(this.table, range.start.col, range.start.row)
|
|
231
|
-
const end = this.toSheetAddr(this.table, range.end.col, range.end.row)
|
|
232
|
-
if (!start || !end) return
|
|
233
|
-
this.sheet.selectRange(createRange(start, end))
|
|
234
|
-
})
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
private bindSheetEvents(): void {
|
|
238
|
-
this.disposers.push(
|
|
239
|
-
this.sheet.on('cell-change', ({ addr }) => {
|
|
240
|
-
if (this.pendingTableSync) {
|
|
241
|
-
this.pendingTableSync.set(cellKey(addr), addr)
|
|
242
|
-
return
|
|
243
|
-
}
|
|
244
|
-
this.pushCellToTable(addr)
|
|
245
|
-
})
|
|
246
|
-
)
|
|
247
|
-
|
|
248
|
-
this.disposers.push(
|
|
249
|
-
this.sheet.on('merge-change', () => {
|
|
250
|
-
this.refresh()
|
|
251
|
-
})
|
|
252
|
-
)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/** 模型格 → 表格 record(显示值;公式格为计算缓存) */
|
|
256
|
-
private pushCellToTable(addr: CellAddress): void {
|
|
257
|
-
const { col, row } = this.toTableCoord(this.table, addr)
|
|
258
|
-
const value = this.sheet.getDisplayValue(addr)
|
|
259
|
-
this.table.changeCellValue(col, row, value as string | number | null, false, false)
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* 键盘绑定:Cmd/Ctrl+Z undo,Cmd/Ctrl+Shift+Z 与 Ctrl+Y redo。
|
|
264
|
-
* 编辑器打开时(事件来自编辑器 input)不拦截,保留文本编辑自身的撤销行为。
|
|
265
|
-
*/
|
|
266
|
-
private bindKeyboard(): void {
|
|
267
|
-
const onKeyDown = (event: KeyboardEvent): void => {
|
|
268
|
-
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) {
|
|
269
|
-
return
|
|
270
|
-
}
|
|
271
|
-
const mod = event.metaKey || event.ctrlKey
|
|
272
|
-
if (!mod) return
|
|
273
|
-
const key = event.key.toLowerCase()
|
|
274
|
-
if (key === 'z' && !event.shiftKey) {
|
|
275
|
-
if (this.undo()) event.preventDefault()
|
|
276
|
-
} else if ((key === 'z' && event.shiftKey) || (key === 'y' && event.ctrlKey)) {
|
|
277
|
-
if (this.redo()) event.preventDefault()
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
this.container.addEventListener('keydown', onKeyDown)
|
|
281
|
-
this.disposers.push(() => this.container.removeEventListener('keydown', onKeyDown))
|
|
282
|
-
}
|
|
283
|
-
}
|