@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,140 +0,0 @@
|
|
|
1
|
-
import type { ListTable } from '@visactor/vtable'
|
|
2
|
-
import { describe, expect, it } from 'vitest'
|
|
3
|
-
|
|
4
|
-
import { Sheet } from '../../core/sheet'
|
|
5
|
-
import { SheetGrid } from '../sheet-grid'
|
|
6
|
-
|
|
7
|
-
function createContainer(): HTMLElement {
|
|
8
|
-
const el = document.createElement('div')
|
|
9
|
-
el.style.width = '800px'
|
|
10
|
-
el.style.height = '600px'
|
|
11
|
-
document.body.appendChild(el)
|
|
12
|
-
return el
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function createGrid() {
|
|
16
|
-
const sheet = new Sheet()
|
|
17
|
-
const container = createContainer()
|
|
18
|
-
const grid = new SheetGrid({ container, sheet, rows: 20, cols: 6 })
|
|
19
|
-
return { sheet, grid, table: grid.getTable(), container }
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** 当前编辑器 input(容器里另有 VTable 内部 input,不能靠 querySelector 取) */
|
|
23
|
-
function editorInput(table: ListTable): HTMLInputElement | undefined {
|
|
24
|
-
const manager = (
|
|
25
|
-
table as unknown as {
|
|
26
|
-
editorManager?: { editingEditor?: { getInputElement?: () => HTMLInputElement } }
|
|
27
|
-
}
|
|
28
|
-
).editorManager
|
|
29
|
-
return manager?.editingEditor?.getInputElement?.()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
describe('SheetGrid 公式集成(happy-dom)', () => {
|
|
33
|
-
it('公式格显示计算值(模型写入公式 → 表格显示缓存值)', () => {
|
|
34
|
-
const { sheet, grid, table } = createGrid()
|
|
35
|
-
try {
|
|
36
|
-
sheet.setCellValue({ row: 0, col: 0 }, 21)
|
|
37
|
-
sheet.setCellFormula({ row: 0, col: 1 }, '=A1*2')
|
|
38
|
-
// 模型 (0,1) → 表格 (2,1)
|
|
39
|
-
expect(table.getCellValue(2, 1)).toBe(42)
|
|
40
|
-
} finally {
|
|
41
|
-
grid.release()
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('编辑提交 = 开头文本 → 模型存公式,表格回推计算值', () => {
|
|
46
|
-
const { sheet, grid, table } = createGrid()
|
|
47
|
-
try {
|
|
48
|
-
sheet.setCellValue({ row: 0, col: 0 }, 5)
|
|
49
|
-
// 模拟编辑提交(Playwright 无法触发双击编辑,changeCellValue 走同一提交路径)
|
|
50
|
-
table.changeCellValue(2, 1, '=A1*2', false, true)
|
|
51
|
-
expect(sheet.getCellData({ row: 0, col: 1 })).toMatchObject({ f: 'A1*2', v: 10, t: 'n' })
|
|
52
|
-
// VTable 先把输入文本写进 record;回推后必须是计算值而非公式原文
|
|
53
|
-
expect(table.getCellValue(2, 1)).toBe(10)
|
|
54
|
-
} finally {
|
|
55
|
-
grid.release()
|
|
56
|
-
}
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('编辑提交引发的派生变更同步到表格(源格 + 全部依赖格)', () => {
|
|
60
|
-
const { sheet, grid, table } = createGrid()
|
|
61
|
-
try {
|
|
62
|
-
sheet.setCellValue({ row: 0, col: 0 }, 1)
|
|
63
|
-
sheet.setCellFormula({ row: 0, col: 1 }, '=A1*2')
|
|
64
|
-
sheet.setCellFormula({ row: 0, col: 2 }, '=B1+1')
|
|
65
|
-
expect(table.getCellValue(2, 1)).toBe(2)
|
|
66
|
-
expect(table.getCellValue(3, 1)).toBe(3)
|
|
67
|
-
|
|
68
|
-
// 编辑 A1 → B1/C1 派生重算,两格都要同步到表格
|
|
69
|
-
// (编辑提交回写的是输入文本,A1 落为字符串 '10';公式按数字文本强转)
|
|
70
|
-
table.changeCellValue(1, 1, '10', false, true)
|
|
71
|
-
expect(sheet.getCellData({ row: 0, col: 0 })).toMatchObject({ v: '10' })
|
|
72
|
-
expect(table.getCellValue(1, 1)).toBe('10')
|
|
73
|
-
expect(table.getCellValue(2, 1)).toBe(20)
|
|
74
|
-
expect(table.getCellValue(3, 1)).toBe(21)
|
|
75
|
-
} finally {
|
|
76
|
-
grid.release()
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
it('进入编辑时公式格显示原文,提交新公式后模型与显示更新', () => {
|
|
81
|
-
const { sheet, grid, table } = createGrid()
|
|
82
|
-
try {
|
|
83
|
-
sheet.setCellValue({ row: 0, col: 0 }, 21)
|
|
84
|
-
sheet.setCellFormula({ row: 0, col: 1 }, '=A1*2')
|
|
85
|
-
|
|
86
|
-
// 程序化进入编辑(等价双击):编辑器文本 = 公式原文
|
|
87
|
-
table.startEditCell(2, 1)
|
|
88
|
-
const input = editorInput(table)
|
|
89
|
-
expect(input).toBeDefined()
|
|
90
|
-
expect(input!.value).toBe('=A1*2')
|
|
91
|
-
|
|
92
|
-
// 输入新公式并提交
|
|
93
|
-
input!.value = '=A1*3'
|
|
94
|
-
table.completeEditCell()
|
|
95
|
-
expect(sheet.getCellData({ row: 0, col: 1 })).toMatchObject({ f: 'A1*3', v: 63 })
|
|
96
|
-
expect(table.getCellValue(2, 1)).toBe(63)
|
|
97
|
-
} finally {
|
|
98
|
-
grid.release()
|
|
99
|
-
}
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
it('普通格进入编辑显示当前值', () => {
|
|
103
|
-
const { sheet, grid, table } = createGrid()
|
|
104
|
-
try {
|
|
105
|
-
sheet.setCellValue({ row: 0, col: 0 }, 'plain')
|
|
106
|
-
table.startEditCell(1, 1)
|
|
107
|
-
expect(editorInput(table)!.value).toBe('plain')
|
|
108
|
-
table.completeEditCell()
|
|
109
|
-
} finally {
|
|
110
|
-
grid.release()
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
it('公式错误值直接显示(#DIV/0!)', () => {
|
|
115
|
-
const { sheet, grid, table } = createGrid()
|
|
116
|
-
try {
|
|
117
|
-
sheet.setCellFormula({ row: 0, col: 0 }, '=1/0')
|
|
118
|
-
expect(table.getCellValue(1, 1)).toBe('#DIV/0!')
|
|
119
|
-
} finally {
|
|
120
|
-
grid.release()
|
|
121
|
-
}
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
it('undo 公式编辑后表格恢复显示', () => {
|
|
125
|
-
const { sheet, grid, table } = createGrid()
|
|
126
|
-
try {
|
|
127
|
-
sheet.setCellValue({ row: 0, col: 0 }, 21)
|
|
128
|
-
sheet.setCellFormula({ row: 0, col: 1 }, '=A1*2')
|
|
129
|
-
expect(table.getCellValue(2, 1)).toBe(42)
|
|
130
|
-
|
|
131
|
-
sheet.undo()
|
|
132
|
-
expect(table.getCellValue(2, 1)).toBeUndefined()
|
|
133
|
-
|
|
134
|
-
sheet.redo()
|
|
135
|
-
expect(table.getCellValue(2, 1)).toBe(42)
|
|
136
|
-
} finally {
|
|
137
|
-
grid.release()
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
})
|
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
import { ListTable } from '@visactor/vtable'
|
|
2
|
-
import { describe, expect, it } from 'vitest'
|
|
3
|
-
|
|
4
|
-
import { Sheet } from '../../core/sheet'
|
|
5
|
-
import { SheetGrid } from '../sheet-grid'
|
|
6
|
-
|
|
7
|
-
function createContainer(): HTMLElement {
|
|
8
|
-
const el = document.createElement('div')
|
|
9
|
-
el.style.width = '800px'
|
|
10
|
-
el.style.height = '600px'
|
|
11
|
-
document.body.appendChild(el)
|
|
12
|
-
return el
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function createGrid() {
|
|
16
|
-
const sheet = new Sheet()
|
|
17
|
-
const grid = new SheetGrid({ container: createContainer(), sheet, rows: 20, cols: 6 })
|
|
18
|
-
return { sheet, grid, table: grid.getTable() }
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
describe('SheetGrid(happy-dom smoke)', () => {
|
|
22
|
-
it('能挂载:列头 A..F + 行号列,坐标带偏移', () => {
|
|
23
|
-
const { grid, table } = createGrid()
|
|
24
|
-
try {
|
|
25
|
-
// (0,*) 为行号列,(*,0) 为列头;模型 (0,0) → 表格 (1,1)
|
|
26
|
-
expect(table.isSeriesNumber(0, 1)).toBe(true)
|
|
27
|
-
expect(table.isHeader(1, 0)).toBe(true)
|
|
28
|
-
expect(table.getCellValue(1, 0)).toBe('A')
|
|
29
|
-
} finally {
|
|
30
|
-
grid.release()
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('主题与交互选项:fillHandle / rowResize / clip / 编辑态方向键不换格', () => {
|
|
35
|
-
const { grid, table } = createGrid()
|
|
36
|
-
try {
|
|
37
|
-
const options = table.options
|
|
38
|
-
expect(options.excelOptions?.fillHandle).toBe(true)
|
|
39
|
-
expect(options.resize?.columnResizeMode).toBe('header')
|
|
40
|
-
expect(options.resize?.rowResizeMode).toBe('all')
|
|
41
|
-
// 列宽:仅列头;行高:仅行号列(body 格不可拖,避免干扰选区/编辑)
|
|
42
|
-
expect(table._canResizeColumn(1, 0)).toBe(true) // 列头 A
|
|
43
|
-
expect(table._canResizeColumn(1, 1)).toBe(false) // body
|
|
44
|
-
expect(table.isSeriesNumber(0, 1)).toBe(true)
|
|
45
|
-
expect(table._canResizeRow(0, 1)).toBe(true) // 行号列
|
|
46
|
-
expect(table._canResizeRow(1, 1)).toBe(false) // body
|
|
47
|
-
expect(options.keyboardOptions?.moveEditCellOnArrowKeys).toBe(false)
|
|
48
|
-
expect(options.defaultRowHeight).toBe(28)
|
|
49
|
-
expect(options.eventOptions?.preventDefaultContextMenu).toBe(true)
|
|
50
|
-
// theme 为 TableTheme 实例(DEFAULT.extends),读运行时解析值
|
|
51
|
-
const theme = table.theme
|
|
52
|
-
expect(theme.bodyStyle?.bgColor).toBe('#FFF')
|
|
53
|
-
expect(theme.bodyStyle?.textOverflow).toBe('clip')
|
|
54
|
-
expect(theme.defaultStyle?.textOverflow).toBe('clip')
|
|
55
|
-
expect(theme.defaultStyle?.borderColor).toBe('#E1E4E8')
|
|
56
|
-
// VTable DEFAULT 为 [10,16,10,16];收紧后贴近 Excel
|
|
57
|
-
expect(theme.defaultStyle?.padding).toEqual([2, 6, 2, 6])
|
|
58
|
-
expect(theme.bodyStyle?.padding).toEqual([2, 6, 2, 6])
|
|
59
|
-
expect(theme.frameStyle?.borderColor).toBe('#E1E4E8')
|
|
60
|
-
expect(theme.selectionStyle?.cellBorderColor).toBe('#2170E7')
|
|
61
|
-
expect(theme.selectionStyle?.cellBorderColor).not.toBe('#000')
|
|
62
|
-
expect(options.rowSeriesNumber).toMatchObject({
|
|
63
|
-
width: 46,
|
|
64
|
-
style: { bgColor: '#F5F5F5', padding: [2, 6, 2, 6], textOverflow: 'clip' }
|
|
65
|
-
})
|
|
66
|
-
} finally {
|
|
67
|
-
grid.release()
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('右键 CONTEXTMENU_CELL → onContextMenu(client 坐标 + 模型地址)', async () => {
|
|
72
|
-
const sheet = new Sheet()
|
|
73
|
-
const container = createContainer()
|
|
74
|
-
const calls: Array<{ x: number; y: number; addr: { row: number; col: number } | null }> = []
|
|
75
|
-
const grid = new SheetGrid({
|
|
76
|
-
container,
|
|
77
|
-
sheet,
|
|
78
|
-
rows: 20,
|
|
79
|
-
cols: 6,
|
|
80
|
-
onContextMenu: (info) => calls.push(info)
|
|
81
|
-
})
|
|
82
|
-
try {
|
|
83
|
-
const table = grid.getTable()
|
|
84
|
-
// 表格坐标 (2,3) → 模型 B3(colOffset/rowOffset 各 1)
|
|
85
|
-
table.fireListeners(ListTable.EVENT_TYPE.CONTEXTMENU_CELL, {
|
|
86
|
-
col: 2,
|
|
87
|
-
row: 3,
|
|
88
|
-
event: { clientX: 120, clientY: 80, preventDefault() {} }
|
|
89
|
-
})
|
|
90
|
-
await Promise.resolve() // queueMicrotask
|
|
91
|
-
expect(calls).toHaveLength(1)
|
|
92
|
-
expect(calls[0]).toMatchObject({ x: 120, y: 80, addr: { row: 2, col: 1 } })
|
|
93
|
-
} finally {
|
|
94
|
-
grid.release()
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
it('行高:RESIZE_ROW_END 写入 Sheet,重建后还原', () => {
|
|
99
|
-
const container = createContainer()
|
|
100
|
-
const sheet = new Sheet()
|
|
101
|
-
let grid = new SheetGrid({ container, sheet, rows: 20, cols: 6 })
|
|
102
|
-
try {
|
|
103
|
-
grid.getTable().fireListeners(ListTable.EVENT_TYPE.RESIZE_ROW_END, { row: 2, rowHeight: 48 })
|
|
104
|
-
expect(sheet.getRowHeight(1)).toBe(48)
|
|
105
|
-
|
|
106
|
-
grid.release()
|
|
107
|
-
grid = new SheetGrid({ container, sheet, rows: 20, cols: 6 })
|
|
108
|
-
expect(grid.getTable().getRowHeight(2)).toBe(48)
|
|
109
|
-
} finally {
|
|
110
|
-
grid.release()
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
it('填充柄:DRAG_FILL_HANDLE_END 数字序列写入模型', () => {
|
|
115
|
-
const { sheet, grid, table } = createGrid()
|
|
116
|
-
try {
|
|
117
|
-
sheet.setCellValue({ row: 0, col: 0 }, 1)
|
|
118
|
-
sheet.selectRange({ start: { row: 0, col: 0 }, end: { row: 0, col: 0 } })
|
|
119
|
-
// 模拟源选区(表格坐标含偏移)
|
|
120
|
-
table.getSelectedCellRanges = () => [{ start: { col: 1, row: 1 }, end: { col: 1, row: 1 } }]
|
|
121
|
-
table.fireListeners(ListTable.EVENT_TYPE.MOUSEDOWN_FILL_HANDLE, {})
|
|
122
|
-
// 拖到底部扩展至 A1:A3
|
|
123
|
-
table.getSelectedCellRanges = () => [{ start: { col: 1, row: 1 }, end: { col: 1, row: 3 } }]
|
|
124
|
-
table.fireListeners(ListTable.EVENT_TYPE.DRAG_FILL_HANDLE_END, { direction: 'bottom' })
|
|
125
|
-
expect(sheet.getCellData({ row: 1, col: 0 })?.v).toBe(2)
|
|
126
|
-
expect(sheet.getCellData({ row: 2, col: 0 })?.v).toBe(3)
|
|
127
|
-
} finally {
|
|
128
|
-
grid.release()
|
|
129
|
-
}
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
it('模型 → 表格:setCellValue 后表格可见', () => {
|
|
133
|
-
const { sheet, grid, table } = createGrid()
|
|
134
|
-
try {
|
|
135
|
-
sheet.setCellValue({ row: 0, col: 0 }, 'hello')
|
|
136
|
-
expect(table.getCellValue(1, 1)).toBe('hello')
|
|
137
|
-
} finally {
|
|
138
|
-
grid.release()
|
|
139
|
-
}
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
it('表格 → 模型:change_cell_value 回写 store', () => {
|
|
143
|
-
const { sheet, grid, table } = createGrid()
|
|
144
|
-
try {
|
|
145
|
-
table.changeCellValue(2, 3, 'world', false, true)
|
|
146
|
-
expect(sheet.getCellData({ row: 2, col: 1 })).toEqual({ v: 'world', t: 's' })
|
|
147
|
-
} finally {
|
|
148
|
-
grid.release()
|
|
149
|
-
}
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
it('合并映射:customMergeCell 反映 MergeManager 的包围盒', () => {
|
|
153
|
-
const { sheet, grid, table } = createGrid()
|
|
154
|
-
try {
|
|
155
|
-
sheet.mergeCells({ start: { row: 1, col: 1 }, end: { row: 2, col: 2 } })
|
|
156
|
-
// 模型 B2:C3 → 表格坐标 (2..3, 2..3)
|
|
157
|
-
const merge = table.getCustomMerge(3, 3)
|
|
158
|
-
expect(merge?.range).toMatchObject({ start: { col: 2, row: 2 }, end: { col: 3, row: 3 } })
|
|
159
|
-
expect(table.getCustomMerge(1, 1)).toBeUndefined()
|
|
160
|
-
} finally {
|
|
161
|
-
grid.release()
|
|
162
|
-
}
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
it('合并区域是单一可操作单位:被覆盖格的 getCellRange 扩展为整个合并', () => {
|
|
166
|
-
const { sheet, grid, table } = createGrid()
|
|
167
|
-
try {
|
|
168
|
-
sheet.setCellValue({ row: 1, col: 1 }, 'anchor-value')
|
|
169
|
-
sheet.mergeCells({ start: { row: 1, col: 1 }, end: { row: 2, col: 2 } })
|
|
170
|
-
|
|
171
|
-
// 点击被覆盖格(表格坐标 3,3)→ 选区/编辑范围 = 整个合并区域
|
|
172
|
-
const range = table.getCellRange(3, 3)
|
|
173
|
-
expect(range).toMatchObject({
|
|
174
|
-
start: { col: 2, row: 2 },
|
|
175
|
-
end: { col: 3, row: 3 },
|
|
176
|
-
isCustom: true
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
// 合并格文本 = 锚点显示值(否则渲染为空)
|
|
180
|
-
expect(table.getCustomMerge(3, 3)?.text).toBe('anchor-value')
|
|
181
|
-
expect(table.getCustomMerge(2, 2)?.text).toBe('anchor-value')
|
|
182
|
-
} finally {
|
|
183
|
-
grid.release()
|
|
184
|
-
}
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
it('编辑提交后合并格文本立即刷新(text 读 records,与 VTable 更新次序一致)', () => {
|
|
188
|
-
const { sheet, grid, table } = createGrid()
|
|
189
|
-
try {
|
|
190
|
-
sheet.setCellValue({ row: 1, col: 1 }, 'old')
|
|
191
|
-
sheet.mergeCells({ start: { row: 1, col: 1 }, end: { row: 2, col: 2 } })
|
|
192
|
-
|
|
193
|
-
// 模拟编辑提交:doExit 的 isCustom 分支 → changeCellValue(锚点, 新值)
|
|
194
|
-
const range = table.getCellRange(3, 3)
|
|
195
|
-
table.changeCellValue(range.start.col, range.start.row, 'new')
|
|
196
|
-
|
|
197
|
-
// 模型已回写;且重绘发生在 change_cell_value 之前,text 必须已是新值
|
|
198
|
-
expect(sheet.getCellData({ row: 1, col: 1 })).toMatchObject({ v: 'new' })
|
|
199
|
-
expect(table.getCustomMerge(3, 3)?.text).toBe('new')
|
|
200
|
-
} finally {
|
|
201
|
-
grid.release()
|
|
202
|
-
}
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
it('编辑回写走命令系统:change_cell_value 后可 undo/redo', () => {
|
|
206
|
-
const { sheet, grid, table } = createGrid()
|
|
207
|
-
try {
|
|
208
|
-
table.changeCellValue(1, 1, 'edited', false, true)
|
|
209
|
-
expect(sheet.getCellData({ row: 0, col: 0 })).toEqual({ v: 'edited', t: 's' })
|
|
210
|
-
|
|
211
|
-
expect(sheet.undo()).toBe(true)
|
|
212
|
-
expect(sheet.getCellData({ row: 0, col: 0 })).toBeUndefined()
|
|
213
|
-
|
|
214
|
-
expect(sheet.redo()).toBe(true)
|
|
215
|
-
expect(sheet.getCellData({ row: 0, col: 0 })).toEqual({ v: 'edited', t: 's' })
|
|
216
|
-
} finally {
|
|
217
|
-
grid.release()
|
|
218
|
-
}
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
it('拖选结束 → 模型选区同步为区域(合并工具的前提)', () => {
|
|
222
|
-
const { sheet, grid, table } = createGrid()
|
|
223
|
-
try {
|
|
224
|
-
// 模拟 VTable 拖选结果(表格坐标含偏移:行号列 1 + 列头行 1)
|
|
225
|
-
table.getSelectedCellRanges = () => [{ start: { col: 1, row: 1 }, end: { col: 3, row: 2 } }]
|
|
226
|
-
table.fireListeners(ListTable.EVENT_TYPE.DRAG_SELECT_END, {})
|
|
227
|
-
expect(sheet.getSelection().ranges[0]).toEqual({
|
|
228
|
-
start: { row: 0, col: 0 },
|
|
229
|
-
end: { row: 1, col: 2 }
|
|
230
|
-
})
|
|
231
|
-
expect(sheet.getSelection().activeCell).toEqual({ row: 0, col: 0 })
|
|
232
|
-
} finally {
|
|
233
|
-
grid.release()
|
|
234
|
-
}
|
|
235
|
-
})
|
|
236
|
-
|
|
237
|
-
it('键盘绑定:Ctrl+Z undo、Ctrl+Shift+Z / Ctrl+Y redo;编辑器 input 不拦截', () => {
|
|
238
|
-
const container = createContainer()
|
|
239
|
-
const sheet = new Sheet()
|
|
240
|
-
const grid = new SheetGrid({ container, sheet, rows: 20, cols: 6 })
|
|
241
|
-
try {
|
|
242
|
-
sheet.setCellValue({ row: 0, col: 0 }, 'x')
|
|
243
|
-
|
|
244
|
-
// Ctrl+Z → undo
|
|
245
|
-
container.dispatchEvent(
|
|
246
|
-
new KeyboardEvent('keydown', { key: 'z', ctrlKey: true, bubbles: true })
|
|
247
|
-
)
|
|
248
|
-
expect(sheet.getCellData({ row: 0, col: 0 })).toBeUndefined()
|
|
249
|
-
|
|
250
|
-
// Ctrl+Shift+Z → redo
|
|
251
|
-
container.dispatchEvent(
|
|
252
|
-
new KeyboardEvent('keydown', { key: 'z', ctrlKey: true, shiftKey: true, bubbles: true })
|
|
253
|
-
)
|
|
254
|
-
expect(sheet.getCellData({ row: 0, col: 0 })).toMatchObject({ v: 'x' })
|
|
255
|
-
|
|
256
|
-
// Ctrl+Z → undo;Ctrl+Y → redo
|
|
257
|
-
container.dispatchEvent(
|
|
258
|
-
new KeyboardEvent('keydown', { key: 'z', ctrlKey: true, bubbles: true })
|
|
259
|
-
)
|
|
260
|
-
container.dispatchEvent(
|
|
261
|
-
new KeyboardEvent('keydown', { key: 'y', ctrlKey: true, bubbles: true })
|
|
262
|
-
)
|
|
263
|
-
expect(sheet.getCellData({ row: 0, col: 0 })).toMatchObject({ v: 'x' })
|
|
264
|
-
|
|
265
|
-
// 事件来自编辑器 input(编辑中)→ 不拦截
|
|
266
|
-
const input = document.createElement('input')
|
|
267
|
-
container.appendChild(input)
|
|
268
|
-
sheet.setCellValue({ row: 0, col: 1 }, 'y')
|
|
269
|
-
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'z', ctrlKey: true, bubbles: true }))
|
|
270
|
-
expect(sheet.getCellData({ row: 0, col: 1 })).toMatchObject({ v: 'y' })
|
|
271
|
-
} finally {
|
|
272
|
-
grid.release()
|
|
273
|
-
}
|
|
274
|
-
})
|
|
275
|
-
})
|