@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,265 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
2
|
-
|
|
3
|
-
import { parseRange } from '../address'
|
|
4
|
-
import { registerFormulaFunction } from '../formula/functions'
|
|
5
|
-
import { Sheet } from '../sheet'
|
|
6
|
-
import { Workbook } from '../workbook'
|
|
7
|
-
|
|
8
|
-
const A1 = { row: 0, col: 0 }
|
|
9
|
-
const B1 = { row: 0, col: 1 }
|
|
10
|
-
const C1 = { row: 0, col: 2 }
|
|
11
|
-
const D1 = { row: 0, col: 3 }
|
|
12
|
-
|
|
13
|
-
describe('对抗:区域依赖', () => {
|
|
14
|
-
it('删除区域公式后,区域内改动不再触发重算(ranged 反向索引清理)', () => {
|
|
15
|
-
const sheet = new Sheet()
|
|
16
|
-
sheet.setCellValue(A1, 1)
|
|
17
|
-
sheet.setCellFormula(D1, '=SUM(A1:A10)')
|
|
18
|
-
expect(sheet.getCellData(D1)).toMatchObject({ v: 1 })
|
|
19
|
-
|
|
20
|
-
sheet.setCellValue(D1, 0) // 删除公式
|
|
21
|
-
const handler = vi.fn()
|
|
22
|
-
sheet.on('cell-change', handler)
|
|
23
|
-
sheet.setCellValue({ row: 5, col: 0 }, 99)
|
|
24
|
-
// 只有 A6 自身变更;D1 已删公式不应重算
|
|
25
|
-
expect(handler).toHaveBeenCalledTimes(1)
|
|
26
|
-
expect(sheet.getCellData(D1)).toMatchObject({ v: 0 })
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('跨表区域公式改写后,Sheet2 改动不再触发 Sheet1 重算', () => {
|
|
30
|
-
const workbook = new Workbook()
|
|
31
|
-
const sheet1 = workbook.activeSheet
|
|
32
|
-
const sheet2 = workbook.addSheet('Sheet2')
|
|
33
|
-
sheet2.setCellValue(B1, 5)
|
|
34
|
-
sheet1.setCellFormula(A1, '=SUM(Sheet2!B1:B10)')
|
|
35
|
-
expect(sheet1.getCellData(A1)).toMatchObject({ v: 5 })
|
|
36
|
-
|
|
37
|
-
// 改写为不引用 Sheet2 的公式 → 旧跨表区域依赖解除
|
|
38
|
-
sheet1.setCellFormula(A1, '=1')
|
|
39
|
-
const handler = vi.fn()
|
|
40
|
-
sheet1.on('cell-change', handler)
|
|
41
|
-
sheet2.setCellValue(B1, 99)
|
|
42
|
-
expect(handler).not.toHaveBeenCalled()
|
|
43
|
-
expect(sheet1.getCellData(A1)).toMatchObject({ v: 1 })
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('经由区域形成的循环:A1=SUM(B1:B2),B1=A1+1 → 双格 #CYCLE!', () => {
|
|
47
|
-
const sheet = new Sheet()
|
|
48
|
-
sheet.setCellFormula(A1, '=SUM(B1:B2)')
|
|
49
|
-
sheet.setCellFormula(B1, '=A1+1')
|
|
50
|
-
expect(sheet.getCellData(A1)).toMatchObject({ v: '#CYCLE!', t: 'e' })
|
|
51
|
-
expect(sheet.getCellData(B1)).toMatchObject({ v: '#CYCLE!', t: 'e' })
|
|
52
|
-
|
|
53
|
-
sheet.setCellValue(B1, 4)
|
|
54
|
-
expect(sheet.getCellData(A1)).toMatchObject({ v: 4 })
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it('自包含区域:A1=SUM(A1:A3) → #CYCLE!', () => {
|
|
58
|
-
const sheet = new Sheet()
|
|
59
|
-
sheet.setCellFormula(A1, '=SUM(A1:A3)')
|
|
60
|
-
expect(sheet.getCellData(A1)).toMatchObject({ v: '#CYCLE!', t: 'e' })
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('区域内的脏公式格:区域聚合拿到的是本轮新值(拓扑序)', () => {
|
|
64
|
-
const sheet = new Sheet()
|
|
65
|
-
sheet.setCellValue(B1, 2)
|
|
66
|
-
sheet.setCellFormula({ row: 1, col: 0 }, '=B1*2') // A2,位于 A1:A3 区域内
|
|
67
|
-
sheet.setCellFormula(D1, '=SUM(A1:A3)')
|
|
68
|
-
expect(sheet.getCellData(D1)).toMatchObject({ v: 4 })
|
|
69
|
-
|
|
70
|
-
sheet.setCellValue(B1, 10)
|
|
71
|
-
expect(sheet.getCellData({ row: 1, col: 0 })).toMatchObject({ v: 20 })
|
|
72
|
-
expect(sheet.getCellData(D1)).toMatchObject({ v: 20 })
|
|
73
|
-
})
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
describe('对抗:循环的生命周期', () => {
|
|
77
|
-
it('循环建立的 undo/redo:状态精确还原', () => {
|
|
78
|
-
const sheet = new Sheet()
|
|
79
|
-
sheet.setCellFormula(A1, '=B1+1')
|
|
80
|
-
expect(sheet.getCellData(A1)).toMatchObject({ v: 1 }) // B1 空 → 1
|
|
81
|
-
sheet.history.clear()
|
|
82
|
-
|
|
83
|
-
sheet.setCellFormula(B1, '=A1+1') // 成环
|
|
84
|
-
expect(sheet.getCellData(A1)).toMatchObject({ v: '#CYCLE!' })
|
|
85
|
-
expect(sheet.getCellData(B1)).toMatchObject({ v: '#CYCLE!' })
|
|
86
|
-
|
|
87
|
-
sheet.undo() // B1 公式撤销 → A1 复原
|
|
88
|
-
expect(sheet.getCellData(B1)).toBeUndefined()
|
|
89
|
-
expect(sheet.getCellData(A1)).toMatchObject({ v: 1 })
|
|
90
|
-
|
|
91
|
-
sheet.redo() // 再次成环
|
|
92
|
-
expect(sheet.getCellData(A1)).toMatchObject({ v: '#CYCLE!' })
|
|
93
|
-
expect(sheet.getCellData(B1)).toMatchObject({ v: '#CYCLE!' })
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('删除环上一格 → 另一格自动恢复', () => {
|
|
97
|
-
const sheet = new Sheet()
|
|
98
|
-
sheet.setCellFormula(A1, '=B1+1')
|
|
99
|
-
sheet.setCellFormula(B1, '=A1+1')
|
|
100
|
-
expect(sheet.getCellData(A1)).toMatchObject({ v: '#CYCLE!' })
|
|
101
|
-
|
|
102
|
-
sheet.setCellValue(A1, null)
|
|
103
|
-
expect(sheet.getCellData(A1)).toBeUndefined()
|
|
104
|
-
expect(sheet.getCellData(B1)).toMatchObject({ v: 1 })
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
it('IF 未选分支中的静态自引用不算环(求值期动态检测)', () => {
|
|
108
|
-
const sheet = new Sheet()
|
|
109
|
-
sheet.setCellFormula(A1, '=IF(FALSE,A1+1,5)')
|
|
110
|
-
expect(sheet.getCellData(A1)).toMatchObject({ v: 5 })
|
|
111
|
-
})
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
describe('对抗:事务与回滚', () => {
|
|
115
|
-
it('事务内公式写入 + 重算:提交后是一个 undo 单元', () => {
|
|
116
|
-
const sheet = new Sheet()
|
|
117
|
-
sheet.setCellFormula(C1, '=A1+B1')
|
|
118
|
-
sheet.history.clear()
|
|
119
|
-
|
|
120
|
-
sheet.beginTransaction()
|
|
121
|
-
sheet.setCellValue(A1, 3)
|
|
122
|
-
sheet.setCellFormula(D1, '=C1*10')
|
|
123
|
-
sheet.commit()
|
|
124
|
-
expect(sheet.getCellData(C1)).toMatchObject({ v: 3 })
|
|
125
|
-
expect(sheet.getCellData(D1)).toMatchObject({ v: 30 })
|
|
126
|
-
expect(sheet.history.undoSize).toBe(1)
|
|
127
|
-
|
|
128
|
-
sheet.undo()
|
|
129
|
-
expect(sheet.getCellData(A1)).toBeUndefined()
|
|
130
|
-
expect(sheet.getCellData(C1)).toMatchObject({ v: 0 })
|
|
131
|
-
expect(sheet.getCellData(D1)).toBeUndefined()
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it('事务回滚:公式与派生值全部还原,图节点清理', () => {
|
|
135
|
-
const sheet = new Sheet()
|
|
136
|
-
sheet.setCellValue(A1, 1)
|
|
137
|
-
const nodesBefore = sheet.formulaGraph.nodeCount
|
|
138
|
-
|
|
139
|
-
sheet.beginTransaction()
|
|
140
|
-
sheet.setCellFormula(B1, '=A1*2')
|
|
141
|
-
expect(sheet.getCellData(B1)).toMatchObject({ v: 2 })
|
|
142
|
-
sheet.rollback()
|
|
143
|
-
|
|
144
|
-
expect(sheet.getCellData(B1)).toBeUndefined()
|
|
145
|
-
expect(sheet.formulaGraph.nodeCount).toBe(nodesBefore)
|
|
146
|
-
// 图已清理:改 A1 不再有任何重算
|
|
147
|
-
const handler = vi.fn()
|
|
148
|
-
sheet.on('cell-change', handler)
|
|
149
|
-
sheet.setCellValue(A1, 9)
|
|
150
|
-
expect(handler).toHaveBeenCalledTimes(1)
|
|
151
|
-
})
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
describe('对抗:合并与公式交互', () => {
|
|
155
|
-
it('合并清除被覆盖格的值后,区域聚合同步变小', () => {
|
|
156
|
-
const sheet = new Sheet()
|
|
157
|
-
sheet.setCellValue({ row: 1, col: 1 }, 10) // B2
|
|
158
|
-
sheet.setCellValue({ row: 2, col: 2 }, 5) // C3
|
|
159
|
-
sheet.setCellFormula(D1, '=SUM(B2:C3)')
|
|
160
|
-
expect(sheet.getCellData(D1)).toMatchObject({ v: 15 })
|
|
161
|
-
|
|
162
|
-
sheet.mergeCells(parseRange('B2:C3')!) // C3 被清空
|
|
163
|
-
expect(sheet.getCellData(D1)).toMatchObject({ v: 10 })
|
|
164
|
-
|
|
165
|
-
sheet.undo() // C3 恢复
|
|
166
|
-
expect(sheet.getCellData(D1)).toMatchObject({ v: 15 })
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
it('合并把非锚点公式格的值(含公式)搬迁到锚点,公式继续求值', () => {
|
|
170
|
-
const sheet = new Sheet()
|
|
171
|
-
sheet.setCellValue(A1, 5)
|
|
172
|
-
sheet.setCellFormula({ row: 2, col: 2 }, '=A1+1') // C3:包围盒内唯一有值格
|
|
173
|
-
sheet.mergeCells(parseRange('B2:C3')!)
|
|
174
|
-
|
|
175
|
-
// 值保留规则:C3 的数据(含公式原文)迁到锚点 B2
|
|
176
|
-
expect(sheet.getCellData({ row: 1, col: 1 })).toMatchObject({ f: 'A1+1', v: 6 })
|
|
177
|
-
sheet.setCellValue(A1, 7)
|
|
178
|
-
expect(sheet.getCellData({ row: 1, col: 1 })).toMatchObject({ v: 8 })
|
|
179
|
-
})
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
describe('对抗:其它边界', () => {
|
|
183
|
-
it('批量写入同一地址两次 + 公式依赖:undo 按逆序还原', () => {
|
|
184
|
-
const sheet = new Sheet()
|
|
185
|
-
sheet.setCellFormula(B1, '=A1*2')
|
|
186
|
-
sheet.setCells([
|
|
187
|
-
{ addr: A1, data: { v: 1, t: 'n' } },
|
|
188
|
-
{ addr: A1, data: { v: 2, t: 'n' } }
|
|
189
|
-
])
|
|
190
|
-
expect(sheet.getCellData(A1)).toMatchObject({ v: 2 })
|
|
191
|
-
expect(sheet.getCellData(B1)).toMatchObject({ v: 4 })
|
|
192
|
-
|
|
193
|
-
sheet.undo()
|
|
194
|
-
expect(sheet.getCellData(A1)).toBeUndefined()
|
|
195
|
-
expect(sheet.getCellData(B1)).toMatchObject({ v: 0 })
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
it('数字文本参与算术(Excel 强转)', () => {
|
|
199
|
-
const sheet = new Sheet()
|
|
200
|
-
sheet.setCellValue(A1, '5')
|
|
201
|
-
sheet.setCellFormula(B1, '=A1+1')
|
|
202
|
-
expect(sheet.getCellData(B1)).toMatchObject({ v: 6 })
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
it('比较运算:文本大小写不敏感;混合类型 数字 < 文本 < 布尔', () => {
|
|
206
|
-
const sheet = new Sheet()
|
|
207
|
-
sheet.setCellFormula(A1, '="apple"="APPLE"')
|
|
208
|
-
expect(sheet.getCellData(A1)).toMatchObject({ v: true })
|
|
209
|
-
sheet.setCellFormula(B1, '=1<"a"')
|
|
210
|
-
expect(sheet.getCellData(B1)).toMatchObject({ v: true })
|
|
211
|
-
sheet.setCellFormula(C1, '="a"<TRUE')
|
|
212
|
-
expect(sheet.getCellData(C1)).toMatchObject({ v: true })
|
|
213
|
-
sheet.setCellFormula(D1, '=A1=B1')
|
|
214
|
-
expect(sheet.getCellData(D1)).toMatchObject({ v: true })
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
it('百分号作用于引用与表达式', () => {
|
|
218
|
-
const sheet = new Sheet()
|
|
219
|
-
sheet.setCellValue(A1, 50)
|
|
220
|
-
sheet.setCellFormula(B1, '=A1%')
|
|
221
|
-
expect(sheet.getCellData(B1)).toMatchObject({ v: 0.5 })
|
|
222
|
-
sheet.setCellFormula(C1, '=(20+30)%')
|
|
223
|
-
expect(sheet.getCellData(C1)).toMatchObject({ v: 0.5 })
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
it('removeSheet 清理被删表的公式节点', () => {
|
|
227
|
-
const workbook = new Workbook()
|
|
228
|
-
const sheet2 = workbook.addSheet('Sheet2')
|
|
229
|
-
sheet2.setCellFormula(A1, '=1+1')
|
|
230
|
-
sheet2.setCellFormula(B1, '=A1*2')
|
|
231
|
-
const before = workbook.formulaGraph.nodeCount
|
|
232
|
-
expect(before).toBe(2)
|
|
233
|
-
|
|
234
|
-
workbook.removeSheet('Sheet2')
|
|
235
|
-
expect(workbook.formulaGraph.nodeCount).toBe(0)
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
it('求值期抛错的自定义函数 → #ERROR!(不击穿重算)', () => {
|
|
239
|
-
registerFormulaFunction('__BOOM__', {
|
|
240
|
-
impl() {
|
|
241
|
-
throw new Error('boom')
|
|
242
|
-
}
|
|
243
|
-
})
|
|
244
|
-
const sheet = new Sheet()
|
|
245
|
-
sheet.setCellFormula(A1, '=__BOOM__()')
|
|
246
|
-
expect(sheet.getCellData(A1)).toMatchObject({ v: '#ERROR!', t: 'e' })
|
|
247
|
-
// 其它公式格不受影响
|
|
248
|
-
sheet.setCellFormula(B1, '=1+1')
|
|
249
|
-
expect(sheet.getCellData(B1)).toMatchObject({ v: 2 })
|
|
250
|
-
})
|
|
251
|
-
|
|
252
|
-
it('扩展注册表:自定义函数可正常使用', () => {
|
|
253
|
-
registerFormulaFunction('__DOUBLE__', {
|
|
254
|
-
minArgs: 1,
|
|
255
|
-
maxArgs: 1,
|
|
256
|
-
impl(args) {
|
|
257
|
-
const n = typeof args[0] === 'number' ? args[0] : 0
|
|
258
|
-
return n * 2
|
|
259
|
-
}
|
|
260
|
-
})
|
|
261
|
-
const sheet = new Sheet()
|
|
262
|
-
sheet.setCellFormula(A1, '=__DOUBLE__(21)')
|
|
263
|
-
expect(sheet.getCellData(A1)).toMatchObject({ v: 42 })
|
|
264
|
-
})
|
|
265
|
-
})
|