@veltra/sheet 2.0.1 → 2.2.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/report/binding-badge.js +76 -0
- package/dist/components/report/designer/cell-coords.js +46 -0
- package/dist/components/report/designer/col-widths.js +15 -0
- package/dist/components/report/designer/conditional-rules/helpers.js +139 -0
- package/dist/components/report/designer/drop-highlight-overlay.js +76 -0
- package/dist/components/report/designer/float-panel.js +385 -0
- package/dist/components/report/designer/role.js +17 -0
- package/dist/components/report/designer/rule-preview.js +33 -0
- package/dist/components/report/designer/rule-row.js +269 -0
- package/dist/components/report/designer/rules-dialog.js +135 -0
- package/dist/components/report/designer/topology-overlay.js +122 -0
- package/dist/components/report/designer/topology.js +64 -0
- package/dist/components/report/designer/use-grid-overlay.js +75 -0
- package/dist/components/report/designer-hub.js +177 -0
- package/dist/components/report/field-panel-helpers.js +33 -0
- package/dist/components/report/field-panel.js +132 -0
- package/dist/components/report/filter-bar.js +74 -0
- package/dist/components/report/hub-connection-form.js +145 -0
- package/dist/components/report/hub-dataset-editor.js +394 -0
- package/dist/components/report/report-designer.js +343 -0
- package/dist/components/report/report-viewer.js +111 -0
- package/dist/components/report/style.d.ts +17 -0
- package/dist/components/report/style.js +18 -0
- package/dist/components/report/style2.css +869 -0
- package/dist/components/report/use-report-designer.js +360 -0
- package/dist/components/report/use-report-viewer.js +50 -0
- package/dist/components/sheet/formula-bar.js +393 -0
- package/dist/components/sheet/formula-suggest-list.js +66 -0
- package/dist/components/sheet/import-file.js +140 -0
- package/dist/components/sheet/insert-count-menu-item.js +68 -0
- package/dist/components/sheet/insert-image.js +79 -0
- package/dist/components/sheet/popup-helpers.js +73 -0
- package/dist/components/sheet/popups/border-popup.js +75 -0
- package/dist/components/sheet/popups/border-preset-glyph.js +106 -0
- package/dist/components/sheet/popups/export-popup.js +51 -0
- package/dist/components/sheet/popups/fill-color-popup.js +37 -0
- package/dist/components/sheet/popups/find-popup.js +113 -0
- package/dist/components/sheet/popups/font-color-popup.js +37 -0
- package/dist/components/sheet/popups/font-size-popup.js +63 -0
- package/dist/components/sheet/popups/import.worker.d.ts +21 -0
- package/dist/components/sheet/popups/import.worker.js +41 -0
- package/dist/components/sheet/popups/insert-image-popup.js +38 -0
- package/dist/components/sheet/sheet-context-menu.js +200 -0
- package/dist/components/sheet/sheet-tabs.js +162 -0
- package/dist/components/sheet/sheet-toolbar.js +106 -0
- package/dist/components/sheet/sheet.js +198 -0
- package/dist/components/sheet/style.d.ts +11 -0
- package/dist/components/sheet/style.js +12 -0
- package/dist/components/sheet/style2.css +654 -0
- package/dist/components/sheet/use-find-replace.js +161 -0
- package/dist/components/sheet/use-formula-ref-select.js +37 -0
- package/dist/components/sheet/use-formula-suggest.js +126 -0
- package/dist/components/sheet/use-sheet-grid.js +188 -0
- package/dist/components/sheet/use-sheet-state.js +122 -0
- package/dist/components/sheet/use-sheet-tabs-bar.js +90 -0
- package/dist/components/sheet/use-tool-groups.js +42 -0
- package/dist/components/sheet/use-tool-popup.js +123 -0
- package/dist/components/sheet/use-toolbar-scroll.js +72 -0
- package/dist/index.d.ts +18 -26
- package/dist/index.js +14 -24
- package/dist/report/binding.d.ts +45 -0
- package/dist/report/binding.js +175 -0
- package/dist/report/connector.d.ts +66 -0
- package/dist/report/connector.js +159 -0
- package/dist/report/export-xlsx.d.ts +19 -0
- package/dist/report/export-xlsx.js +95 -0
- package/dist/report/filter-bar.d.ts +10 -0
- package/dist/report/filter-bar.js +31 -0
- package/dist/report/index.d.ts +12 -0
- package/dist/report/params.d.ts +13 -0
- package/dist/report/params.js +61 -0
- package/dist/report/render/aggregate.js +157 -0
- package/dist/report/render/builder.d.ts +12 -0
- package/dist/report/render/builder.js +139 -0
- package/dist/report/render/coordinate.d.ts +25 -0
- package/dist/report/render/coordinate.js +733 -0
- package/dist/report/render/index.d.ts +14 -0
- package/dist/report/render/index.js +21 -0
- package/dist/report/render/style-resolver.js +50 -0
- package/dist/report/render/template-index.d.ts +24 -0
- package/dist/report/render/template-index.js +137 -0
- package/dist/report/rules/evaluate.d.ts +25 -0
- package/dist/report/rules/evaluate.js +82 -0
- package/dist/report/rules/index.d.ts +2 -0
- package/dist/report/template.d.ts +59 -0
- package/dist/report/template.js +80 -0
- package/dist/report/types.d.ts +85 -0
- 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 +3 -1
- package/dist/types/report-designer.d.ts +36 -0
- package/dist/types/report-viewer.d.ts +38 -0
- package/dist/types/sheet.d.ts +22 -5
- package/package.json +10 -7
- package/src/components/report/__test__/conditional-rules-helpers.test.ts +87 -0
- package/src/components/report/__test__/field-panel-helpers.test.ts +65 -0
- package/src/components/report/__test__/float-panel-position.test.ts +45 -0
- package/src/components/report/__test__/report-designer.test.ts +388 -0
- package/src/components/report/__test__/report-viewer.test.ts +334 -0
- package/src/components/report/__test__/topology.test.ts +143 -0
- package/src/components/report/__test__/use-report-designer.test.ts +565 -0
- package/src/components/report/binding-badge.ts +73 -0
- package/src/components/report/designer/cell-coords.ts +94 -0
- package/src/components/report/designer/col-widths.ts +33 -0
- package/src/components/report/designer/conditional-rules/helpers.ts +186 -0
- package/src/components/report/designer/drop-highlight-overlay.vue +74 -0
- package/src/components/report/designer/float-panel.vue +387 -0
- package/src/components/report/designer/role.ts +32 -0
- package/src/components/report/designer/rule-preview.vue +40 -0
- package/src/components/report/designer/rule-row.vue +252 -0
- package/src/components/report/designer/rules-dialog.vue +126 -0
- package/src/components/report/designer/topology-overlay.vue +127 -0
- package/src/components/report/designer/topology.ts +124 -0
- package/src/components/report/designer/use-grid-overlay.ts +113 -0
- package/src/components/report/designer-hub.vue +198 -0
- package/src/components/report/field-panel-helpers.ts +44 -0
- package/src/components/report/field-panel.vue +136 -0
- package/src/components/report/filter-bar.vue +77 -0
- package/src/components/report/hub-connection-form.vue +124 -0
- package/src/components/report/hub-dataset-editor.vue +369 -0
- package/src/components/report/index.ts +2 -0
- package/src/components/report/report-designer.vue +356 -0
- package/src/components/report/report-viewer.vue +128 -0
- package/src/components/report/style-designer.scss +583 -0
- package/src/components/report/style-hub.scss +292 -0
- package/src/components/report/style-viewer.scss +104 -0
- package/src/components/report/style.scss +3 -0
- package/src/components/report/style.ts +20 -0
- package/src/components/report/use-report-designer.ts +547 -0
- package/src/components/report/use-report-viewer.ts +79 -0
- package/src/components/sheet/__test__/formula-bar.test.ts +474 -0
- package/src/components/sheet/__test__/import-file.test.ts +183 -0
- package/src/components/sheet/__test__/insert-count-menu-item.test.ts +123 -0
- package/src/components/sheet/__test__/insert-image-popup.test.ts +89 -0
- package/src/components/sheet/__test__/insert-image.test.ts +100 -0
- package/src/components/sheet/__test__/sheet-component.test.ts +993 -0
- package/src/components/sheet/__test__/sheet-context-menu.test.ts +206 -0
- package/src/components/sheet/__test__/use-formula-ref-select.test.ts +35 -0
- package/src/components/sheet/__test__/use-formula-suggest.test.ts +83 -0
- package/src/components/sheet/formula-bar.vue +473 -0
- package/src/components/sheet/formula-suggest-list.vue +64 -0
- package/src/components/sheet/import-file.ts +173 -0
- package/src/components/sheet/insert-count-menu-item.vue +69 -0
- package/src/components/sheet/insert-image.ts +90 -0
- package/src/components/sheet/parsing.ts +11 -0
- package/src/components/sheet/popup-helpers.ts +50 -0
- package/src/components/sheet/popups/border-popup.vue +93 -0
- package/src/components/sheet/popups/border-preset-glyph.vue +111 -0
- package/src/components/sheet/popups/export-popup.vue +52 -0
- package/src/components/sheet/popups/fill-color-popup.vue +39 -0
- package/src/components/sheet/popups/find-popup.vue +111 -0
- package/src/components/sheet/popups/font-color-popup.vue +39 -0
- package/src/components/sheet/popups/font-size-popup.vue +52 -0
- package/src/components/sheet/popups/import.worker.ts +66 -0
- package/src/components/sheet/popups/insert-image-popup.vue +39 -0
- package/src/components/sheet/sheet-context-menu.ts +229 -0
- package/src/components/sheet/sheet-tabs.vue +162 -0
- package/src/components/sheet/sheet-toolbar.vue +91 -0
- package/src/components/sheet/sheet.vue +211 -0
- package/src/components/sheet/style.scss +737 -0
- package/src/components/sheet/style.ts +13 -0
- package/src/components/sheet/use-find-replace.ts +200 -0
- package/src/components/sheet/use-formula-ref-select.ts +34 -0
- package/src/components/sheet/use-formula-suggest.ts +150 -0
- package/src/components/sheet/use-sheet-grid.ts +247 -0
- package/src/components/sheet/use-sheet-state.ts +161 -0
- package/src/components/sheet/use-sheet-tabs-bar.ts +115 -0
- package/src/components/sheet/use-tool-groups.ts +61 -0
- package/src/components/sheet/use-tool-popup.ts +150 -0
- package/src/components/sheet/use-toolbar-scroll.ts +95 -0
- package/src/env.d.ts +11 -0
- package/src/index.ts +39 -14
- package/src/report/__test__/binding.test.ts +218 -0
- package/src/report/__test__/connector.test.ts +218 -0
- package/src/report/__test__/export-xlsx.test.ts +118 -0
- package/src/report/__test__/filter-bar.test.ts +58 -0
- package/src/report/__test__/params.test.ts +156 -0
- package/src/report/__test__/render.test.ts +728 -0
- package/src/report/__test__/rules.test.ts +131 -0
- package/src/report/__test__/template.test.ts +355 -0
- package/src/report/binding.ts +243 -0
- package/src/report/connector.ts +205 -0
- package/src/report/export-xlsx.ts +118 -0
- package/src/report/filter-bar.ts +36 -0
- package/src/report/index.ts +13 -0
- package/src/report/params.ts +96 -0
- package/src/report/render/__test__/aggregate.test.ts +16 -0
- package/src/report/render/__test__/coordinate.test.ts +405 -0
- package/src/report/render/aggregate.ts +240 -0
- package/src/report/render/builder.ts +211 -0
- package/src/report/render/coordinate.ts +1239 -0
- package/src/report/render/index.ts +30 -0
- package/src/report/render/style-resolver.ts +68 -0
- package/src/report/render/template-index.ts +200 -0
- package/src/report/rules/evaluate.ts +113 -0
- package/src/report/rules/index.ts +7 -0
- package/src/report/template.ts +141 -0
- package/src/report/types.ts +96 -0
- 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 +2 -0
- package/src/types/report-designer.ts +36 -0
- package/src/types/report-viewer.ts +37 -0
- package/src/types/sheet.ts +26 -3
- 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/fill.d.ts +0 -34
- package/dist/core/fill.js +0 -320
- package/dist/core/fill.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 -116
- package/dist/core/sheet.js +0 -224
- 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 -81
- package/dist/grid/sheet-grid.js +0 -331
- package/dist/grid/sheet-grid.js.map +0 -1
- package/dist/grid/vtable-theme.js +0 -80
- package/dist/grid/vtable-theme.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 +0 -211
- package/dist/vue/sheet.js.map +0 -1
- package/dist/vue/sheet.vue.d.ts +0 -24
- package/dist/vue/style.d.ts +0 -1
- package/dist/vue/style.js +0 -2
- package/dist/vue/style2.css +0 -93
- 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__/fill.test.ts +0 -140
- 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/fill.ts +0 -314
- 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 -282
- 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 -275
- package/src/grid/sheet-grid.ts +0 -407
- package/src/grid/vtable-theme.ts +0 -61
- package/src/vue/__test__/sheet-component.test.ts +0 -267
- package/src/vue/sheet.vue +0 -235
- package/src/vue/style.scss +0 -94
- package/src/vue/style.ts +0 -2
- /package/src/{vue → components/sheet}/index.ts +0 -0
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { parseRange, type CellAddress } from '../address'
|
|
4
|
-
import type { CellRange } from '../address'
|
|
5
|
-
import type { CellSnapshotItem } from '../cell-store'
|
|
6
|
-
import { Sheet } from '../sheet'
|
|
7
|
-
|
|
8
|
-
const B2 = { row: 1, col: 1 }
|
|
9
|
-
const C3 = { row: 2, col: 2 }
|
|
10
|
-
|
|
11
|
-
/** Sheet 状态快照(cells + merges,排序后比较,与写入顺序无关) */
|
|
12
|
-
function snapshotSheet(sheet: Sheet): { cells: CellSnapshotItem[]; merges: CellRange[] } {
|
|
13
|
-
const byAddr = (a: { row: number; col: number }, b: { row: number; col: number }) =>
|
|
14
|
-
a.row - b.row || a.col - b.col
|
|
15
|
-
return {
|
|
16
|
-
cells: [...sheet.store.snapshot()].sort(byAddr),
|
|
17
|
-
merges: sheet.merges.getMerges().sort((a, b) => byAddr(a.start, b.start))
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** 生成 100 个连续地址(行主序) */
|
|
22
|
-
function hundredAddrs(): CellAddress[] {
|
|
23
|
-
return Array.from({ length: 100 }, (_, i) => ({ row: Math.floor(i / 10), col: i % 10 }))
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
describe('SetCellValueCommand undo/redo', () => {
|
|
27
|
-
it('写入 → undo 删除(旧值为空)→ redo 重放', () => {
|
|
28
|
-
const sheet = new Sheet()
|
|
29
|
-
sheet.setCellValue(B2, 'hello')
|
|
30
|
-
expect(sheet.getCellData(B2)).toEqual({ v: 'hello', t: 's' })
|
|
31
|
-
|
|
32
|
-
expect(sheet.undo()).toBe(true)
|
|
33
|
-
// 旧值为空 = 存储中不存在该 key
|
|
34
|
-
expect(sheet.getCellData(B2)).toBeUndefined()
|
|
35
|
-
expect(sheet.store.size).toBe(0)
|
|
36
|
-
|
|
37
|
-
expect(sheet.redo()).toBe(true)
|
|
38
|
-
expect(sheet.getCellData(B2)).toEqual({ v: 'hello', t: 's' })
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('覆盖写入 → undo 恢复旧值 → redo 再到新值', () => {
|
|
42
|
-
const sheet = new Sheet()
|
|
43
|
-
sheet.setCellValue(B2, 'old')
|
|
44
|
-
sheet.setCellValue(B2, 'new')
|
|
45
|
-
|
|
46
|
-
sheet.undo()
|
|
47
|
-
expect(sheet.getCellData(B2)).toEqual({ v: 'old', t: 's' })
|
|
48
|
-
|
|
49
|
-
sheet.redo()
|
|
50
|
-
expect(sheet.getCellData(B2)).toEqual({ v: 'new', t: 's' })
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
it('清除值(null)→ undo 恢复原值', () => {
|
|
54
|
-
const sheet = new Sheet()
|
|
55
|
-
sheet.setCellValue(B2, 42)
|
|
56
|
-
sheet.setCellValue(B2, null)
|
|
57
|
-
expect(sheet.getCellData(B2)).toBeUndefined()
|
|
58
|
-
|
|
59
|
-
sheet.undo()
|
|
60
|
-
expect(sheet.getCellData(B2)).toEqual({ v: 42, t: 'n' })
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('同值写入 = 无实际变更,不产生历史条目', () => {
|
|
64
|
-
const sheet = new Sheet()
|
|
65
|
-
sheet.setCellValue(B2, 'x')
|
|
66
|
-
const depth = sheet.history.undoSize
|
|
67
|
-
|
|
68
|
-
sheet.setCellValue(B2, 'x')
|
|
69
|
-
expect(sheet.history.undoSize).toBe(depth)
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
it('对被覆盖格写入落锚点 → undo 还原锚点旧值', () => {
|
|
73
|
-
const sheet = new Sheet()
|
|
74
|
-
sheet.setCellValue(B2, 'anchor-old')
|
|
75
|
-
sheet.mergeCells(parseRange('B2:C3')!)
|
|
76
|
-
|
|
77
|
-
sheet.setCellValue(C3, 'via-covered')
|
|
78
|
-
expect(sheet.getCellData(B2)).toMatchObject({ v: 'via-covered' })
|
|
79
|
-
|
|
80
|
-
sheet.undo()
|
|
81
|
-
expect(sheet.getCellData(B2)).toMatchObject({ v: 'anchor-old' })
|
|
82
|
-
expect(sheet.getCellData(C3)).toBeUndefined()
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
it('批量 100 格(setCells 单命令)= 一次 undo 全回滚', () => {
|
|
86
|
-
const sheet = new Sheet()
|
|
87
|
-
const addrs = hundredAddrs()
|
|
88
|
-
sheet.setCells(addrs.map((addr, i) => ({ addr, data: { v: i, t: 'n' as const } })))
|
|
89
|
-
expect(sheet.store.size).toBe(100)
|
|
90
|
-
expect(sheet.history.undoSize).toBe(1)
|
|
91
|
-
|
|
92
|
-
expect(sheet.undo()).toBe(true)
|
|
93
|
-
expect(sheet.store.size).toBe(0)
|
|
94
|
-
|
|
95
|
-
expect(sheet.redo()).toBe(true)
|
|
96
|
-
expect(sheet.store.size).toBe(100)
|
|
97
|
-
expect(sheet.getCellData({ row: 9, col: 9 })).toEqual({ v: 99, t: 'n' })
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
it('事务内 100 次单独写入 = 一次 undo 全回滚(事务原子性)', () => {
|
|
101
|
-
const sheet = new Sheet()
|
|
102
|
-
const addrs = hundredAddrs()
|
|
103
|
-
|
|
104
|
-
sheet.beginTransaction()
|
|
105
|
-
for (const [i, addr] of addrs.entries()) {
|
|
106
|
-
sheet.setCellValue(addr, i)
|
|
107
|
-
}
|
|
108
|
-
sheet.commit()
|
|
109
|
-
|
|
110
|
-
expect(sheet.store.size).toBe(100)
|
|
111
|
-
expect(sheet.history.undoSize).toBe(1)
|
|
112
|
-
|
|
113
|
-
sheet.undo()
|
|
114
|
-
expect(sheet.store.size).toBe(0)
|
|
115
|
-
sheet.redo()
|
|
116
|
-
expect(sheet.store.size).toBe(100)
|
|
117
|
-
})
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
describe('MergeCellsCommand undo/redo', () => {
|
|
121
|
-
it('merge → undo 全还原(合并记录 + 被清空各格原值)→ redo 结果一致', () => {
|
|
122
|
-
const sheet = new Sheet()
|
|
123
|
-
sheet.setCellValue(B2, 'keep')
|
|
124
|
-
sheet.setCellValue(C3, 'drop')
|
|
125
|
-
const before = snapshotSheet(sheet)
|
|
126
|
-
|
|
127
|
-
sheet.mergeCells(parseRange('B2:C3')!)
|
|
128
|
-
expect(sheet.getCellInfo(B2).kind).toBe('merged-anchor')
|
|
129
|
-
expect(sheet.getCellData(C3)).toBeUndefined()
|
|
130
|
-
const merged = snapshotSheet(sheet)
|
|
131
|
-
|
|
132
|
-
// undo:合并记录移除 + 两格原值全部还原
|
|
133
|
-
sheet.undo()
|
|
134
|
-
expect(sheet.merges.size).toBe(0)
|
|
135
|
-
expect(sheet.getCellData(B2)).toEqual({ v: 'keep', t: 's' })
|
|
136
|
-
expect(sheet.getCellData(C3)).toEqual({ v: 'drop', t: 's' })
|
|
137
|
-
expect(snapshotSheet(sheet)).toEqual(before)
|
|
138
|
-
|
|
139
|
-
// redo:再合并结果一致
|
|
140
|
-
sheet.redo()
|
|
141
|
-
expect(snapshotSheet(sheet)).toEqual(merged)
|
|
142
|
-
expect(sheet.getDisplayValue(C3)).toBe('keep')
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
it('锚点为空、非锚点格有值:merge 保留值落锚点 → undo 原样还原', () => {
|
|
146
|
-
const sheet = new Sheet()
|
|
147
|
-
sheet.setCellValue(C3, 'first-valued')
|
|
148
|
-
|
|
149
|
-
sheet.mergeCells(parseRange('B2:C3')!)
|
|
150
|
-
expect(sheet.getDisplayValue(B2)).toBe('first-valued')
|
|
151
|
-
expect(sheet.getCellData(C3)).toBeUndefined()
|
|
152
|
-
|
|
153
|
-
sheet.undo()
|
|
154
|
-
expect(sheet.getCellData(B2)).toBeUndefined()
|
|
155
|
-
expect(sheet.getCellData(C3)).toEqual({ v: 'first-valued', t: 's' })
|
|
156
|
-
expect(sheet.merges.size).toBe(0)
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
it('合并已合并区域(包围盒扩大)→ 两次 undo 逐步还原', () => {
|
|
160
|
-
const sheet = new Sheet()
|
|
161
|
-
sheet.setCellValue(B2, 'v-b2')
|
|
162
|
-
sheet.mergeCells(parseRange('B2:C3')!)
|
|
163
|
-
sheet.setCellValue({ row: 3, col: 3 }, 'v-d4')
|
|
164
|
-
const afterFirstMerge = snapshotSheet(sheet)
|
|
165
|
-
|
|
166
|
-
// 再合并 C3:D4 → 包围盒 B2:D4,旧合并 B2:C3 被解除
|
|
167
|
-
const finalRange = sheet.mergeCells(parseRange('C3:D4')!)
|
|
168
|
-
expect(finalRange).toEqual(parseRange('B2:D4'))
|
|
169
|
-
expect(sheet.getCellData({ row: 3, col: 3 })).toBeUndefined()
|
|
170
|
-
|
|
171
|
-
// 第一次 undo:恢复旧合并 B2:C3 + 被清空的 D4 原值
|
|
172
|
-
sheet.undo()
|
|
173
|
-
expect(snapshotSheet(sheet)).toEqual(afterFirstMerge)
|
|
174
|
-
expect(sheet.getCellInfo(B2).mergeRange).toEqual(parseRange('B2:C3'))
|
|
175
|
-
expect(sheet.getCellData({ row: 3, col: 3 })).toEqual({ v: 'v-d4', t: 's' })
|
|
176
|
-
|
|
177
|
-
// 第二次 undo:撤销 setCellValue(D4)
|
|
178
|
-
sheet.undo()
|
|
179
|
-
expect(sheet.getCellData({ row: 3, col: 3 })).toBeUndefined()
|
|
180
|
-
expect(sheet.merges.size).toBe(1)
|
|
181
|
-
|
|
182
|
-
// 第三次 undo:连第一个合并也还原
|
|
183
|
-
sheet.undo()
|
|
184
|
-
expect(sheet.merges.size).toBe(0)
|
|
185
|
-
expect(sheet.getCellData(B2)).toEqual({ v: 'v-b2', t: 's' })
|
|
186
|
-
})
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
describe('UnmergeCellsCommand undo/redo', () => {
|
|
190
|
-
it('unmerge → undo 恢复合并记录 → redo 再解除', () => {
|
|
191
|
-
const sheet = new Sheet()
|
|
192
|
-
sheet.setCellValue(B2, 'keep')
|
|
193
|
-
sheet.mergeCells(parseRange('B2:C3')!)
|
|
194
|
-
|
|
195
|
-
sheet.unmergeCells(parseRange('B2:C3')!)
|
|
196
|
-
expect(sheet.merges.size).toBe(0)
|
|
197
|
-
expect(sheet.getCellData(B2)).toMatchObject({ v: 'keep' })
|
|
198
|
-
|
|
199
|
-
sheet.undo()
|
|
200
|
-
expect(sheet.merges.size).toBe(1)
|
|
201
|
-
expect(sheet.getCellInfo(C3).kind).toBe('merged-covered')
|
|
202
|
-
expect(sheet.getDisplayValue(C3)).toBe('keep')
|
|
203
|
-
|
|
204
|
-
sheet.redo()
|
|
205
|
-
expect(sheet.merges.size).toBe(0)
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
it('unmerge 无相交合并 = 空操作,不入历史', () => {
|
|
209
|
-
const sheet = new Sheet()
|
|
210
|
-
sheet.setCellValue(B2, 'x')
|
|
211
|
-
const depth = sheet.history.undoSize
|
|
212
|
-
|
|
213
|
-
sheet.unmergeCells(parseRange('D4:E5')!)
|
|
214
|
-
expect(sheet.history.undoSize).toBe(depth)
|
|
215
|
-
})
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
describe('历史栈语义(经 Sheet)', () => {
|
|
219
|
-
it('空栈 undo/redo 返回 false', () => {
|
|
220
|
-
const sheet = new Sheet()
|
|
221
|
-
expect(sheet.canUndo).toBe(false)
|
|
222
|
-
expect(sheet.canRedo).toBe(false)
|
|
223
|
-
expect(sheet.undo()).toBe(false)
|
|
224
|
-
expect(sheet.redo()).toBe(false)
|
|
225
|
-
})
|
|
226
|
-
|
|
227
|
-
it('交错序列:A → B → undo → 新 C → redo 栈已清空', () => {
|
|
228
|
-
const sheet = new Sheet()
|
|
229
|
-
sheet.setCellValue({ row: 0, col: 0 }, 'A')
|
|
230
|
-
sheet.setCellValue({ row: 0, col: 1 }, 'B')
|
|
231
|
-
|
|
232
|
-
sheet.undo()
|
|
233
|
-
expect(sheet.canRedo).toBe(true)
|
|
234
|
-
|
|
235
|
-
sheet.setCellValue({ row: 0, col: 2 }, 'C')
|
|
236
|
-
expect(sheet.canRedo).toBe(false)
|
|
237
|
-
expect(sheet.redo()).toBe(false)
|
|
238
|
-
// B 永远丢失,A/C 保留
|
|
239
|
-
expect(sheet.getCellData({ row: 0, col: 0 })).toMatchObject({ v: 'A' })
|
|
240
|
-
expect(sheet.getCellData({ row: 0, col: 1 })).toBeUndefined()
|
|
241
|
-
expect(sheet.getCellData({ row: 0, col: 2 })).toMatchObject({ v: 'C' })
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
it('容量上限:超过 200 条淘汰最旧,且不破坏栈一致性', () => {
|
|
245
|
-
const sheet = new Sheet()
|
|
246
|
-
// 201 次写入到不同格(第 0 次将被淘汰)
|
|
247
|
-
for (let i = 0; i <= 200; i++) {
|
|
248
|
-
sheet.setCellValue({ row: 0, col: i }, i)
|
|
249
|
-
}
|
|
250
|
-
expect(sheet.history.undoSize).toBe(200)
|
|
251
|
-
|
|
252
|
-
// 只能 undo 最近 200 条;最旧一条(col 0)已被淘汰
|
|
253
|
-
for (let i = 0; i < 200; i++) {
|
|
254
|
-
expect(sheet.undo()).toBe(true)
|
|
255
|
-
}
|
|
256
|
-
expect(sheet.undo()).toBe(false)
|
|
257
|
-
expect(sheet.getCellData({ row: 0, col: 0 })).toEqual({ v: 0, t: 'n' })
|
|
258
|
-
expect(sheet.getCellData({ row: 0, col: 1 })).toBeUndefined()
|
|
259
|
-
|
|
260
|
-
// redo 栈一致:200 条全部可重做
|
|
261
|
-
for (let i = 0; i < 200; i++) {
|
|
262
|
-
expect(sheet.redo()).toBe(true)
|
|
263
|
-
}
|
|
264
|
-
expect(sheet.redo()).toBe(false)
|
|
265
|
-
expect(sheet.store.size).toBe(201)
|
|
266
|
-
})
|
|
267
|
-
|
|
268
|
-
it('快速连续 undo/redo 50 次无状态错乱', () => {
|
|
269
|
-
const sheet = new Sheet()
|
|
270
|
-
sheet.setCellValue({ row: 0, col: 0 }, 'a')
|
|
271
|
-
sheet.setCellValue(B2, 'b')
|
|
272
|
-
sheet.mergeCells(parseRange('C3:D4')!)
|
|
273
|
-
const initial = snapshotSheet(sheet)
|
|
274
|
-
// 以当前状态为历史起点(排除上述准备操作)
|
|
275
|
-
sheet.history.clear()
|
|
276
|
-
|
|
277
|
-
// 10 步操作
|
|
278
|
-
for (let i = 0; i < 10; i++) {
|
|
279
|
-
sheet.setCellValue({ row: 5, col: i }, i)
|
|
280
|
-
}
|
|
281
|
-
const afterOps = snapshotSheet(sheet)
|
|
282
|
-
|
|
283
|
-
// 交替 undo/redo 各 25 次(每对 undo+redo 应回到同一状态)
|
|
284
|
-
for (let i = 0; i < 25; i++) {
|
|
285
|
-
sheet.undo()
|
|
286
|
-
sheet.redo()
|
|
287
|
-
}
|
|
288
|
-
expect(snapshotSheet(sheet)).toEqual(afterOps)
|
|
289
|
-
|
|
290
|
-
// 连续 50 次 undo(10 步有效 + 40 步空转)→ 回到初始
|
|
291
|
-
for (let i = 0; i < 50; i++) sheet.undo()
|
|
292
|
-
expect(snapshotSheet(sheet)).toEqual(initial)
|
|
293
|
-
|
|
294
|
-
// 连续 50 次 redo(10 步有效 + 40 步空转)→ 回到操作后
|
|
295
|
-
for (let i = 0; i < 50; i++) sheet.redo()
|
|
296
|
-
expect(snapshotSheet(sheet)).toEqual(afterOps)
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
it('history-change 事件携带 canUndo/canRedo', () => {
|
|
300
|
-
const sheet = new Sheet()
|
|
301
|
-
const handler = vi.fn()
|
|
302
|
-
sheet.on('history-change', handler)
|
|
303
|
-
|
|
304
|
-
sheet.setCellValue(B2, 'x')
|
|
305
|
-
expect(handler).toHaveBeenLastCalledWith({ canUndo: true, canRedo: false })
|
|
306
|
-
|
|
307
|
-
sheet.undo()
|
|
308
|
-
expect(handler).toHaveBeenLastCalledWith({ canUndo: false, canRedo: true })
|
|
309
|
-
|
|
310
|
-
sheet.redo()
|
|
311
|
-
expect(handler).toHaveBeenLastCalledWith({ canUndo: true, canRedo: false })
|
|
312
|
-
})
|
|
313
|
-
|
|
314
|
-
it('嵌套事务拍平为一个 undo 单元', () => {
|
|
315
|
-
const sheet = new Sheet()
|
|
316
|
-
sheet.beginTransaction()
|
|
317
|
-
sheet.setCellValue({ row: 0, col: 0 }, 'a')
|
|
318
|
-
sheet.beginTransaction()
|
|
319
|
-
sheet.setCellValue({ row: 0, col: 1 }, 'b')
|
|
320
|
-
sheet.commit()
|
|
321
|
-
sheet.commit()
|
|
322
|
-
|
|
323
|
-
expect(sheet.history.undoSize).toBe(1)
|
|
324
|
-
sheet.undo()
|
|
325
|
-
expect(sheet.store.size).toBe(0)
|
|
326
|
-
})
|
|
327
|
-
|
|
328
|
-
it('事务中途异常:rollback 还原模型且不入历史', () => {
|
|
329
|
-
const sheet = new Sheet()
|
|
330
|
-
sheet.setCellValue({ row: 0, col: 0 }, 'before')
|
|
331
|
-
const depth = sheet.history.undoSize
|
|
332
|
-
|
|
333
|
-
sheet.beginTransaction()
|
|
334
|
-
sheet.setCellValue({ row: 0, col: 1 }, 'tx-a')
|
|
335
|
-
sheet.setCellValue({ row: 0, col: 2 }, 'tx-b')
|
|
336
|
-
sheet.rollback()
|
|
337
|
-
|
|
338
|
-
expect(sheet.getCellData({ row: 0, col: 1 })).toBeUndefined()
|
|
339
|
-
expect(sheet.getCellData({ row: 0, col: 2 })).toBeUndefined()
|
|
340
|
-
expect(sheet.getCellData({ row: 0, col: 0 })).toMatchObject({ v: 'before' })
|
|
341
|
-
expect(sheet.history.undoSize).toBe(depth)
|
|
342
|
-
expect(sheet.history.inTransaction).toBe(false)
|
|
343
|
-
})
|
|
344
|
-
|
|
345
|
-
it('事务进行中 undo/redo 返回 false', () => {
|
|
346
|
-
const sheet = new Sheet()
|
|
347
|
-
sheet.setCellValue({ row: 0, col: 0 }, 'a')
|
|
348
|
-
sheet.beginTransaction()
|
|
349
|
-
sheet.setCellValue({ row: 0, col: 1 }, 'b')
|
|
350
|
-
|
|
351
|
-
expect(sheet.undo()).toBe(false)
|
|
352
|
-
expect(sheet.redo()).toBe(false)
|
|
353
|
-
expect(sheet.getCellData({ row: 0, col: 1 })).toMatchObject({ v: 'b' })
|
|
354
|
-
sheet.commit()
|
|
355
|
-
})
|
|
356
|
-
|
|
357
|
-
it('undo 后选区不被历史追踪,且不崩溃、可继续正常选中', () => {
|
|
358
|
-
const sheet = new Sheet()
|
|
359
|
-
sheet.setCellValue(B2, 'keep')
|
|
360
|
-
sheet.mergeCells(parseRange('B2:C3')!)
|
|
361
|
-
sheet.selectCell(C3)
|
|
362
|
-
expect(sheet.getSelection().activeCell).toEqual(B2)
|
|
363
|
-
|
|
364
|
-
// undo 解除合并;选区保持原样(选区不进历史)
|
|
365
|
-
sheet.undo()
|
|
366
|
-
expect(sheet.getSelection().activeCell).toEqual(B2)
|
|
367
|
-
|
|
368
|
-
// 合并已解除,C3 现在是普通格
|
|
369
|
-
sheet.selectCell(C3)
|
|
370
|
-
expect(sheet.getSelection().activeCell).toEqual(C3)
|
|
371
|
-
|
|
372
|
-
// redo 重新合并后,C3 又解析到锚点
|
|
373
|
-
sheet.redo()
|
|
374
|
-
sheet.selectCell(C3)
|
|
375
|
-
expect(sheet.getSelection().activeCell).toEqual(B2)
|
|
376
|
-
})
|
|
377
|
-
})
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { parseRange } from '../address'
|
|
4
|
-
import { computeFillTargetRange, generateFill, shiftFormulaRefs } from '../fill'
|
|
5
|
-
import { Sheet } from '../sheet'
|
|
6
|
-
|
|
7
|
-
describe('shiftFormulaRefs', () => {
|
|
8
|
-
it('相对引用随行列位移', () => {
|
|
9
|
-
expect(shiftFormulaRefs('A1+B2', 1, 0)).toBe('A2+B3')
|
|
10
|
-
expect(shiftFormulaRefs('A1+B2', 0, 1)).toBe('B1+C2')
|
|
11
|
-
expect(shiftFormulaRefs('SUM(A1:B2)', 2, 1)).toBe('SUM(B3:C4)')
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('尊重 $ 绝对行列', () => {
|
|
15
|
-
expect(shiftFormulaRefs('$A$1+A1', 1, 1)).toBe('$A$1+B2')
|
|
16
|
-
expect(shiftFormulaRefs('$A1+A$1', 2, 3)).toBe('$A3+D$1')
|
|
17
|
-
expect(shiftFormulaRefs('Sheet2!$B2+C$3', 1, 1)).toBe('Sheet2!$B3+D$3')
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it('出界变为 #REF!;不改写字符串字面量', () => {
|
|
21
|
-
expect(shiftFormulaRefs('A1', 0, -1)).toBe('#REF!')
|
|
22
|
-
expect(shiftFormulaRefs('A1', -1, 0)).toBe('#REF!')
|
|
23
|
-
expect(shiftFormulaRefs('"A1"&B1', 1, 0)).toBe('"A1"&B2')
|
|
24
|
-
expect(shiftFormulaRefs('LOG10(A1)', 1, 0)).toBe('LOG10(A2)')
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
describe('computeFillTargetRange', () => {
|
|
29
|
-
it('按方向裁剪扩展选区中的新增区域', () => {
|
|
30
|
-
const source = parseRange('A1:B2')!
|
|
31
|
-
expect(computeFillTargetRange(source, 'bottom', parseRange('A1:B5')!)).toEqual(
|
|
32
|
-
parseRange('A3:B5')
|
|
33
|
-
)
|
|
34
|
-
expect(computeFillTargetRange(source, 'right', parseRange('A1:D2')!)).toEqual(
|
|
35
|
-
parseRange('C1:D2')
|
|
36
|
-
)
|
|
37
|
-
expect(computeFillTargetRange(source, 'top', parseRange('A1:B2')!)).toBeNull()
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
describe('generateFill', () => {
|
|
42
|
-
it('非数字 → tile 复制(含空格覆盖清空)', () => {
|
|
43
|
-
const sheet = new Sheet()
|
|
44
|
-
sheet.setCellValue({ row: 0, col: 0 }, 'a')
|
|
45
|
-
sheet.setCellValue({ row: 1, col: 0 }, 'b')
|
|
46
|
-
|
|
47
|
-
const items = generateFill({
|
|
48
|
-
source: parseRange('A1:A2')!,
|
|
49
|
-
target: parseRange('A3:A6')!,
|
|
50
|
-
direction: 'bottom',
|
|
51
|
-
getCellData: (addr) => sheet.getCellData(addr)
|
|
52
|
-
})
|
|
53
|
-
expect(items).toEqual([
|
|
54
|
-
{ addr: { row: 2, col: 0 }, data: { v: 'a', t: 's' } },
|
|
55
|
-
{ addr: { row: 3, col: 0 }, data: { v: 'b', t: 's' } },
|
|
56
|
-
{ addr: { row: 4, col: 0 }, data: { v: 'a', t: 's' } },
|
|
57
|
-
{ addr: { row: 5, col: 0 }, data: { v: 'b', t: 's' } }
|
|
58
|
-
])
|
|
59
|
-
|
|
60
|
-
// 空源覆盖:源 B1 空 → 目标格被清
|
|
61
|
-
sheet.setCellValue({ row: 2, col: 1 }, 'keep')
|
|
62
|
-
const clearItems = generateFill({
|
|
63
|
-
source: parseRange('B1')!,
|
|
64
|
-
target: parseRange('B3')!,
|
|
65
|
-
direction: 'bottom',
|
|
66
|
-
getCellData: (addr) => sheet.getCellData(addr)
|
|
67
|
-
})
|
|
68
|
-
expect(clearItems).toEqual([{ addr: { row: 2, col: 1 }, data: undefined }])
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('数字等差:单格步长 1;多格按 delta 延续', () => {
|
|
72
|
-
const sheet = new Sheet()
|
|
73
|
-
sheet.setCellValue({ row: 0, col: 0 }, 1)
|
|
74
|
-
|
|
75
|
-
const single = generateFill({
|
|
76
|
-
source: parseRange('A1')!,
|
|
77
|
-
target: parseRange('A2:A4')!,
|
|
78
|
-
direction: 'bottom',
|
|
79
|
-
getCellData: (addr) => sheet.getCellData(addr)
|
|
80
|
-
})
|
|
81
|
-
expect(single.map((item) => item.data?.v)).toEqual([2, 3, 4])
|
|
82
|
-
|
|
83
|
-
sheet.setCellValue({ row: 0, col: 1 }, 1)
|
|
84
|
-
sheet.setCellValue({ row: 1, col: 1 }, 3)
|
|
85
|
-
const multi = generateFill({
|
|
86
|
-
source: parseRange('B1:B2')!,
|
|
87
|
-
target: parseRange('B3:B4')!,
|
|
88
|
-
direction: 'bottom',
|
|
89
|
-
getCellData: (addr) => sheet.getCellData(addr)
|
|
90
|
-
})
|
|
91
|
-
expect(multi.map((item) => item.data?.v)).toEqual([5, 7])
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('日期类型(t=d)按数值序列延续', () => {
|
|
95
|
-
const sheet = new Sheet()
|
|
96
|
-
sheet.setCell({ row: 0, col: 0 }, { v: 100, t: 'd' })
|
|
97
|
-
sheet.setCell({ row: 1, col: 0 }, { v: 101, t: 'd' })
|
|
98
|
-
|
|
99
|
-
const items = generateFill({
|
|
100
|
-
source: parseRange('A1:A2')!,
|
|
101
|
-
target: parseRange('A3')!,
|
|
102
|
-
direction: 'bottom',
|
|
103
|
-
getCellData: (addr) => sheet.getCellData(addr)
|
|
104
|
-
})
|
|
105
|
-
expect(items).toEqual([{ addr: { row: 2, col: 0 }, data: { v: 102, t: 'd' } }])
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
it('公式格:相对引用位移,绝对引用锁定', () => {
|
|
109
|
-
const sheet = new Sheet()
|
|
110
|
-
sheet.setCellFormula({ row: 0, col: 0 }, '=$B$1+C1')
|
|
111
|
-
|
|
112
|
-
const items = generateFill({
|
|
113
|
-
source: parseRange('A1')!,
|
|
114
|
-
target: parseRange('A2:A3')!,
|
|
115
|
-
direction: 'bottom',
|
|
116
|
-
getCellData: (addr) => sheet.getCellData(addr)
|
|
117
|
-
})
|
|
118
|
-
expect(items.map((item) => item.data?.f)).toEqual(['$B$1+C2', '$B$1+C3'])
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it('经 setCells 写入后可一次 undo', () => {
|
|
122
|
-
const sheet = new Sheet()
|
|
123
|
-
sheet.setCellValue({ row: 0, col: 0 }, 10)
|
|
124
|
-
sheet.history.clear()
|
|
125
|
-
|
|
126
|
-
const items = generateFill({
|
|
127
|
-
source: parseRange('A1')!,
|
|
128
|
-
target: parseRange('A2:A3')!,
|
|
129
|
-
direction: 'bottom',
|
|
130
|
-
getCellData: (addr) => sheet.getCellData(addr)
|
|
131
|
-
})
|
|
132
|
-
sheet.setCells(items)
|
|
133
|
-
expect(sheet.getCellData({ row: 1, col: 0 })?.v).toBe(11)
|
|
134
|
-
expect(sheet.getCellData({ row: 2, col: 0 })?.v).toBe(12)
|
|
135
|
-
|
|
136
|
-
expect(sheet.undo()).toBe(true)
|
|
137
|
-
expect(sheet.getCellData({ row: 1, col: 0 })).toBeUndefined()
|
|
138
|
-
expect(sheet.getCellData({ row: 2, col: 0 })).toBeUndefined()
|
|
139
|
-
})
|
|
140
|
-
})
|