@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
package/dist/tools/builtin.js
CHANGED
|
@@ -1,16 +1,43 @@
|
|
|
1
|
-
import { rangesEqual } from "../core/address.js";
|
|
2
1
|
import { registerTool } from "./registry.js";
|
|
2
|
+
import { FontColor } from "@veltra/icons/colorful";
|
|
3
|
+
import { AlignBottom, AlignCenter, AlignTop, Bold, Border, Download, Fill, FontSize, Italic, MergeCells, PictureRounded, Rollback, Rollfront, Search, Strikethrough, Underline, UnmergeCells, Upload, VerticalAlignCenter, VerticalAlignLeft, VerticalAlignRight, Wrap } from "@veltra/icons/normal";
|
|
4
|
+
import { rangesEqual } from "@veltra/sheet-core/core/address";
|
|
3
5
|
//#region src/tools/builtin.ts
|
|
6
|
+
/** 取活动格所在首选区;无选区返回 null */
|
|
7
|
+
function selectionRange(ctx) {
|
|
8
|
+
const { activeCell, ranges } = ctx.getSelection();
|
|
9
|
+
const range = ranges[0];
|
|
10
|
+
if (!activeCell || !range) return null;
|
|
11
|
+
return {
|
|
12
|
+
activeCell,
|
|
13
|
+
range
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** 字体 toggle:以活动格当前值为基准,对选区统一翻转(Excel 语义) */
|
|
17
|
+
function toggleFontFlag(ctx, field) {
|
|
18
|
+
const sel = selectionRange(ctx);
|
|
19
|
+
if (!sel) return;
|
|
20
|
+
const on = ctx.getCellStyle(sel.activeCell)?.font?.[field] === true;
|
|
21
|
+
ctx.setCellStyle(sel.range, { font: { [field]: on ? null : true } });
|
|
22
|
+
}
|
|
23
|
+
/** 对齐 toggle:点当前档 = 清除,点其它档 = 切换 */
|
|
24
|
+
function toggleAlign(ctx, axis, value) {
|
|
25
|
+
const sel = selectionRange(ctx);
|
|
26
|
+
if (!sel) return;
|
|
27
|
+
if (ctx.getCellStyle(sel.activeCell)?.align?.[axis] === value) ctx.setCellStyle(sel.range, { align: { [axis]: null } });
|
|
28
|
+
else ctx.setCellStyle(sel.range, { align: { [axis]: value } });
|
|
29
|
+
}
|
|
4
30
|
/**
|
|
5
|
-
* 内置工具(dogfood
|
|
31
|
+
* 内置工具(dogfood 扩展机制)。
|
|
6
32
|
*
|
|
33
|
+
* 分组:history | cell | text | edit | insert | file。
|
|
7
34
|
* 与第三方工具走同一注册通道,可由宿主 unregisterTool 移除或同 id 覆盖。
|
|
8
|
-
*
|
|
9
|
-
* 经包入口导入即完成注册,无头使用 core 深导入不涉及此全局副作用。
|
|
35
|
+
* 本模块由包入口引入:经包入口导入即完成注册。
|
|
10
36
|
*/
|
|
11
37
|
registerTool({
|
|
12
38
|
id: "undo",
|
|
13
39
|
title: "撤销",
|
|
40
|
+
icon: Rollback,
|
|
14
41
|
tooltip: "撤销(Ctrl/Cmd+Z)",
|
|
15
42
|
group: "history",
|
|
16
43
|
order: 0,
|
|
@@ -22,6 +49,7 @@ registerTool({
|
|
|
22
49
|
registerTool({
|
|
23
50
|
id: "redo",
|
|
24
51
|
title: "重做",
|
|
52
|
+
icon: Rollfront,
|
|
25
53
|
tooltip: "重做(Ctrl/Cmd+Shift+Z 或 Ctrl+Y)",
|
|
26
54
|
group: "history",
|
|
27
55
|
order: 1,
|
|
@@ -30,12 +58,35 @@ registerTool({
|
|
|
30
58
|
ctx.redo();
|
|
31
59
|
}
|
|
32
60
|
});
|
|
61
|
+
registerTool({
|
|
62
|
+
id: "border",
|
|
63
|
+
title: "边框",
|
|
64
|
+
icon: Border,
|
|
65
|
+
tooltip: "设置单元格边框",
|
|
66
|
+
group: "cell",
|
|
67
|
+
order: 0,
|
|
68
|
+
popup: "border",
|
|
69
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
70
|
+
onClick: () => {}
|
|
71
|
+
});
|
|
72
|
+
registerTool({
|
|
73
|
+
id: "fill-color",
|
|
74
|
+
title: "填充颜色",
|
|
75
|
+
icon: Fill,
|
|
76
|
+
tooltip: "设置单元格背景填充",
|
|
77
|
+
group: "cell",
|
|
78
|
+
order: 1,
|
|
79
|
+
popup: "fill-color",
|
|
80
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
81
|
+
onClick: () => {}
|
|
82
|
+
});
|
|
33
83
|
registerTool({
|
|
34
84
|
id: "merge",
|
|
35
85
|
title: "合并",
|
|
86
|
+
icon: MergeCells,
|
|
36
87
|
tooltip: "合并选中区域",
|
|
37
88
|
group: "cell",
|
|
38
|
-
order:
|
|
89
|
+
order: 2,
|
|
39
90
|
disabled: (ctx) => {
|
|
40
91
|
const { activeCell, ranges } = ctx.getSelection();
|
|
41
92
|
const range = ranges[0];
|
|
@@ -53,9 +104,10 @@ registerTool({
|
|
|
53
104
|
registerTool({
|
|
54
105
|
id: "unmerge",
|
|
55
106
|
title: "取消合并",
|
|
107
|
+
icon: UnmergeCells,
|
|
56
108
|
tooltip: "取消活动格所在合并",
|
|
57
109
|
group: "cell",
|
|
58
|
-
order:
|
|
110
|
+
order: 3,
|
|
59
111
|
disabled: (ctx) => {
|
|
60
112
|
const { activeCell } = ctx.getSelection();
|
|
61
113
|
if (!activeCell) return true;
|
|
@@ -67,6 +119,225 @@ registerTool({
|
|
|
67
119
|
ctx.unmergeCells(ranges[0]);
|
|
68
120
|
}
|
|
69
121
|
});
|
|
122
|
+
registerTool({
|
|
123
|
+
id: "bold",
|
|
124
|
+
title: "加粗",
|
|
125
|
+
icon: Bold,
|
|
126
|
+
tooltip: "加粗",
|
|
127
|
+
group: "text",
|
|
128
|
+
order: 0,
|
|
129
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
130
|
+
active: (ctx) => {
|
|
131
|
+
const active = ctx.getSelection().activeCell;
|
|
132
|
+
return !!active && ctx.getCellStyle(active)?.font?.bold === true;
|
|
133
|
+
},
|
|
134
|
+
onClick: (ctx) => toggleFontFlag(ctx, "bold")
|
|
135
|
+
});
|
|
136
|
+
registerTool({
|
|
137
|
+
id: "italic",
|
|
138
|
+
title: "斜体",
|
|
139
|
+
icon: Italic,
|
|
140
|
+
tooltip: "斜体",
|
|
141
|
+
group: "text",
|
|
142
|
+
order: 1,
|
|
143
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
144
|
+
active: (ctx) => {
|
|
145
|
+
const active = ctx.getSelection().activeCell;
|
|
146
|
+
return !!active && ctx.getCellStyle(active)?.font?.italic === true;
|
|
147
|
+
},
|
|
148
|
+
onClick: (ctx) => toggleFontFlag(ctx, "italic")
|
|
149
|
+
});
|
|
150
|
+
registerTool({
|
|
151
|
+
id: "underline",
|
|
152
|
+
title: "下划线",
|
|
153
|
+
icon: Underline,
|
|
154
|
+
tooltip: "下划线",
|
|
155
|
+
group: "text",
|
|
156
|
+
order: 2,
|
|
157
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
158
|
+
active: (ctx) => {
|
|
159
|
+
const active = ctx.getSelection().activeCell;
|
|
160
|
+
return !!active && ctx.getCellStyle(active)?.font?.underline === true;
|
|
161
|
+
},
|
|
162
|
+
onClick: (ctx) => toggleFontFlag(ctx, "underline")
|
|
163
|
+
});
|
|
164
|
+
registerTool({
|
|
165
|
+
id: "strikethrough",
|
|
166
|
+
title: "删除线",
|
|
167
|
+
icon: Strikethrough,
|
|
168
|
+
tooltip: "删除线",
|
|
169
|
+
group: "text",
|
|
170
|
+
order: 3,
|
|
171
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
172
|
+
active: (ctx) => {
|
|
173
|
+
const active = ctx.getSelection().activeCell;
|
|
174
|
+
return !!active && ctx.getCellStyle(active)?.font?.strikethrough === true;
|
|
175
|
+
},
|
|
176
|
+
onClick: (ctx) => toggleFontFlag(ctx, "strikethrough")
|
|
177
|
+
});
|
|
178
|
+
registerTool({
|
|
179
|
+
id: "font-color",
|
|
180
|
+
title: "字体颜色",
|
|
181
|
+
icon: FontColor,
|
|
182
|
+
tooltip: "设置字体颜色",
|
|
183
|
+
group: "text",
|
|
184
|
+
order: 4,
|
|
185
|
+
popup: "font-color",
|
|
186
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
187
|
+
onClick: () => {}
|
|
188
|
+
});
|
|
189
|
+
registerTool({
|
|
190
|
+
id: "font-size",
|
|
191
|
+
title: "字号",
|
|
192
|
+
icon: FontSize,
|
|
193
|
+
tooltip: "设置字体大小",
|
|
194
|
+
group: "text",
|
|
195
|
+
order: 5,
|
|
196
|
+
popup: "font-size",
|
|
197
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
198
|
+
onClick: () => {}
|
|
199
|
+
});
|
|
200
|
+
registerTool({
|
|
201
|
+
id: "align-left",
|
|
202
|
+
title: "左对齐",
|
|
203
|
+
icon: VerticalAlignLeft,
|
|
204
|
+
tooltip: "水平左对齐",
|
|
205
|
+
group: "text",
|
|
206
|
+
order: 6,
|
|
207
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
208
|
+
active: (ctx) => {
|
|
209
|
+
const active = ctx.getSelection().activeCell;
|
|
210
|
+
return !!active && ctx.getCellStyle(active)?.align?.horizontal === "left";
|
|
211
|
+
},
|
|
212
|
+
onClick: (ctx) => toggleAlign(ctx, "horizontal", "left")
|
|
213
|
+
});
|
|
214
|
+
registerTool({
|
|
215
|
+
id: "align-center",
|
|
216
|
+
title: "居中",
|
|
217
|
+
icon: VerticalAlignCenter,
|
|
218
|
+
tooltip: "水平居中",
|
|
219
|
+
group: "text",
|
|
220
|
+
order: 7,
|
|
221
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
222
|
+
active: (ctx) => {
|
|
223
|
+
const active = ctx.getSelection().activeCell;
|
|
224
|
+
return !!active && ctx.getCellStyle(active)?.align?.horizontal === "center";
|
|
225
|
+
},
|
|
226
|
+
onClick: (ctx) => toggleAlign(ctx, "horizontal", "center")
|
|
227
|
+
});
|
|
228
|
+
registerTool({
|
|
229
|
+
id: "align-right",
|
|
230
|
+
title: "右对齐",
|
|
231
|
+
icon: VerticalAlignRight,
|
|
232
|
+
tooltip: "水平右对齐",
|
|
233
|
+
group: "text",
|
|
234
|
+
order: 8,
|
|
235
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
236
|
+
active: (ctx) => {
|
|
237
|
+
const active = ctx.getSelection().activeCell;
|
|
238
|
+
return !!active && ctx.getCellStyle(active)?.align?.horizontal === "right";
|
|
239
|
+
},
|
|
240
|
+
onClick: (ctx) => toggleAlign(ctx, "horizontal", "right")
|
|
241
|
+
});
|
|
242
|
+
registerTool({
|
|
243
|
+
id: "valign-top",
|
|
244
|
+
title: "顶端对齐",
|
|
245
|
+
icon: AlignTop,
|
|
246
|
+
tooltip: "垂直顶端对齐",
|
|
247
|
+
group: "text",
|
|
248
|
+
order: 9,
|
|
249
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
250
|
+
active: (ctx) => {
|
|
251
|
+
const active = ctx.getSelection().activeCell;
|
|
252
|
+
return !!active && ctx.getCellStyle(active)?.align?.vertical === "top";
|
|
253
|
+
},
|
|
254
|
+
onClick: (ctx) => toggleAlign(ctx, "vertical", "top")
|
|
255
|
+
});
|
|
256
|
+
registerTool({
|
|
257
|
+
id: "valign-middle",
|
|
258
|
+
title: "垂直居中",
|
|
259
|
+
icon: AlignCenter,
|
|
260
|
+
tooltip: "垂直居中对齐",
|
|
261
|
+
group: "text",
|
|
262
|
+
order: 10,
|
|
263
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
264
|
+
active: (ctx) => {
|
|
265
|
+
const active = ctx.getSelection().activeCell;
|
|
266
|
+
return !!active && ctx.getCellStyle(active)?.align?.vertical === "middle";
|
|
267
|
+
},
|
|
268
|
+
onClick: (ctx) => toggleAlign(ctx, "vertical", "middle")
|
|
269
|
+
});
|
|
270
|
+
registerTool({
|
|
271
|
+
id: "valign-bottom",
|
|
272
|
+
title: "底端对齐",
|
|
273
|
+
icon: AlignBottom,
|
|
274
|
+
tooltip: "垂直底端对齐",
|
|
275
|
+
group: "text",
|
|
276
|
+
order: 11,
|
|
277
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
278
|
+
active: (ctx) => {
|
|
279
|
+
const active = ctx.getSelection().activeCell;
|
|
280
|
+
return !!active && ctx.getCellStyle(active)?.align?.vertical === "bottom";
|
|
281
|
+
},
|
|
282
|
+
onClick: (ctx) => toggleAlign(ctx, "vertical", "bottom")
|
|
283
|
+
});
|
|
284
|
+
registerTool({
|
|
285
|
+
id: "wrap-text",
|
|
286
|
+
title: "自动换行",
|
|
287
|
+
icon: Wrap,
|
|
288
|
+
tooltip: "自动换行",
|
|
289
|
+
group: "text",
|
|
290
|
+
order: 12,
|
|
291
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
292
|
+
active: (ctx) => {
|
|
293
|
+
const active = ctx.getSelection().activeCell;
|
|
294
|
+
return !!active && ctx.getCellStyle(active)?.align?.wrap === true;
|
|
295
|
+
},
|
|
296
|
+
onClick: (ctx) => {
|
|
297
|
+
const sel = selectionRange(ctx);
|
|
298
|
+
if (!sel) return;
|
|
299
|
+
const on = ctx.getCellStyle(sel.activeCell)?.align?.wrap === true;
|
|
300
|
+
ctx.setCellStyle(sel.range, { align: { wrap: on ? null : true } });
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
registerTool({
|
|
304
|
+
id: "find",
|
|
305
|
+
title: "查找",
|
|
306
|
+
icon: Search,
|
|
307
|
+
tooltip: "查找与替换(Ctrl/Cmd+F)",
|
|
308
|
+
group: "edit",
|
|
309
|
+
order: 0,
|
|
310
|
+
popup: "find",
|
|
311
|
+
onClick: () => {}
|
|
312
|
+
});
|
|
313
|
+
registerTool({
|
|
314
|
+
id: "insert-image",
|
|
315
|
+
title: "插入图片",
|
|
316
|
+
icon: PictureRounded,
|
|
317
|
+
tooltip: "插入浮动图片",
|
|
318
|
+
group: "insert",
|
|
319
|
+
order: 0,
|
|
320
|
+
popup: "insert-image",
|
|
321
|
+
disabled: (ctx) => !ctx.getSelection().activeCell,
|
|
322
|
+
onClick: () => {}
|
|
323
|
+
});
|
|
324
|
+
registerTool({
|
|
325
|
+
id: "import",
|
|
326
|
+
title: "导入",
|
|
327
|
+
icon: Download,
|
|
328
|
+
tooltip: "从 .xlsx / .csv 文件导入",
|
|
329
|
+
group: "file",
|
|
330
|
+
order: 0,
|
|
331
|
+
onClick: () => {}
|
|
332
|
+
});
|
|
333
|
+
registerTool({
|
|
334
|
+
id: "export",
|
|
335
|
+
title: "导出",
|
|
336
|
+
icon: Upload,
|
|
337
|
+
tooltip: "导出为 Excel 或 CSV",
|
|
338
|
+
group: "file",
|
|
339
|
+
order: 1,
|
|
340
|
+
popup: "export",
|
|
341
|
+
onClick: () => {}
|
|
342
|
+
});
|
|
70
343
|
//#endregion
|
|
71
|
-
|
|
72
|
-
//# sourceMappingURL=builtin.js.map
|
package/dist/tools/context.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { CellAddress, CellRange } from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { CellAddress, CellRange } from "@veltra/sheet-core/core/address";
|
|
2
|
+
import { CellStyle, CellStylePatch } from "@veltra/sheet-core/core/style/types";
|
|
3
|
+
import { CellData, CellValue } from "@veltra/sheet-core/core/cell-store";
|
|
4
|
+
import { Workbook } from "@veltra/sheet-core/core/workbook";
|
|
5
|
+
import { FrozenState, Sheet } from "@veltra/sheet-core/core/sheet";
|
|
6
|
+
import { HistoryState } from "@veltra/sheet-core/core/command/history";
|
|
7
|
+
import { ImageUpdateFields } from "@veltra/sheet-core/core/command/image";
|
|
8
|
+
import { SetCellValueItem } from "@veltra/sheet-core/core/command/set-cell-value";
|
|
9
|
+
import { ImageInput, SheetImage } from "@veltra/sheet-core/core/image";
|
|
10
|
+
import { CellInfo } from "@veltra/sheet-core/core/merge-manager";
|
|
11
|
+
import { SelectionState } from "@veltra/sheet-core/core/selection";
|
|
8
12
|
//#region src/tools/context.d.ts
|
|
9
13
|
/**
|
|
10
14
|
* SheetContext:工具的唯一操作门面。
|
|
@@ -18,16 +22,27 @@ import { SetCellValueItem } from "../core/command/set-cell-value.js";
|
|
|
18
22
|
interface SheetContext {
|
|
19
23
|
/** 当前活动 sheet 名 */
|
|
20
24
|
readonly sheetName: string;
|
|
25
|
+
/**
|
|
26
|
+
* 当前工作簿(导入导出等需要工作簿级操作的场景;无头/单 sheet 场景可能为 undefined)。
|
|
27
|
+
* 只读引用:sheet 增删改名等结构操作仍应经宿主直接操作 Workbook(Phase 3 门面边界)。
|
|
28
|
+
*/
|
|
29
|
+
readonly workbook?: Workbook;
|
|
21
30
|
getSelection(): SelectionState;
|
|
22
31
|
/** 选中单格(被覆盖格自动定位锚点) */
|
|
23
32
|
selectCell(addr: CellAddress): void;
|
|
24
|
-
selectRange(range: CellRange): void;
|
|
33
|
+
selectRange(range: CellRange, active?: CellAddress): void;
|
|
25
34
|
/** 原始存储语义读取(被合并覆盖格 → undefined) */
|
|
26
35
|
getCellData(addr: CellAddress): CellData | undefined;
|
|
27
36
|
/** 锚点解析语义读取(被覆盖格 → 锚点的值) */
|
|
28
37
|
getDisplayValue(addr: CellAddress): CellValue | undefined;
|
|
29
38
|
/** 合并语义下的单元格信息(普通格 / 合并锚点 / 被覆盖格) */
|
|
30
39
|
getCellInfo(addr: CellAddress): CellInfo;
|
|
40
|
+
/** 设置区域样式(部分合并语义,见 CellStylePatch);空样式 = 删除 s 字段 */
|
|
41
|
+
setCellStyle(range: CellRange, partial: CellStylePatch): void;
|
|
42
|
+
/** 清除区域样式(保留值 / 公式) */
|
|
43
|
+
clearCellStyle(range: CellRange): void;
|
|
44
|
+
/** 读取单元格样式(原始存储语义:被覆盖格 → undefined) */
|
|
45
|
+
getCellStyle(addr: CellAddress): CellStyle | undefined;
|
|
31
46
|
setCellValue(addr: CellAddress, value: CellValue): void;
|
|
32
47
|
setCellFormula(addr: CellAddress, formula: string): void;
|
|
33
48
|
/** 批量写入(一次调用 = 一个 undo 单元) */
|
|
@@ -43,15 +58,43 @@ interface SheetContext {
|
|
|
43
58
|
redo(): boolean;
|
|
44
59
|
readonly canUndo: boolean;
|
|
45
60
|
readonly canRedo: boolean;
|
|
61
|
+
/** 当前冻结状态(rows = 冻结顶部行数,cols = 冻结左侧列数) */
|
|
62
|
+
readonly frozen: FrozenState;
|
|
63
|
+
/** 设置冻结行列数(不进 undo,同 rowHeights 先例) */
|
|
64
|
+
setFrozen(rows: number, cols: number): void;
|
|
65
|
+
/** 插入 count 行到 at 行之前 */
|
|
66
|
+
insertRows(at: number, count?: number): void;
|
|
67
|
+
/** 插入 count 列到 at 列之前 */
|
|
68
|
+
insertCols(at: number, count?: number): void;
|
|
69
|
+
/** 删除 [at, at+count) 行 */
|
|
70
|
+
deleteRows(at: number, count?: number): void;
|
|
71
|
+
/** 删除 [at, at+count) 列 */
|
|
72
|
+
deleteCols(at: number, count?: number): void;
|
|
73
|
+
/** 插入浮动图片;返回生成的 id */
|
|
74
|
+
insertImage(input: ImageInput): string;
|
|
75
|
+
/** 删除浮动图片;不存在则无操作 */
|
|
76
|
+
removeImage(id: string): void;
|
|
77
|
+
/** 更新浮动图片锚点/尺寸/文案;不存在或无变更则无操作 */
|
|
78
|
+
updateImage(id: string, patch: ImageUpdateFields): void;
|
|
79
|
+
/** 只读图片列表(快照副本) */
|
|
80
|
+
getImages(): readonly SheetImage[];
|
|
46
81
|
onSelectionChange(handler: (state: SelectionState) => void): () => void;
|
|
47
82
|
onHistoryChange(handler: (state: HistoryState) => void): () => void;
|
|
83
|
+
onFrozenChange(handler: (state: FrozenState) => void): () => void;
|
|
84
|
+
/** 图片集合变化(单图带 id;整表替换时 id 缺省) */
|
|
85
|
+
onImageChange(handler: (payload: {
|
|
86
|
+
id?: string;
|
|
87
|
+
}) => void): () => void;
|
|
48
88
|
}
|
|
49
89
|
/**
|
|
50
90
|
* 创建工具上下文。
|
|
51
91
|
* @param resolveSheet 活动 sheet 解析器(USheet 传 `() => activeSheet`,
|
|
52
92
|
* tab 切换后上下文自动指向当前 sheet);也可直接传 Sheet 实例(无头 / 测试场景)
|
|
93
|
+
* @param workbook 当前工作簿(导入导出等工具需要;无头 / 单 sheet 场景可省略)。
|
|
94
|
+
* 支持传解析函数 `() => Workbook`——USheet 在 props.workbook 动态切换后,
|
|
95
|
+
* 上下文始终解析到**当前**工作簿(#2:旧实现取构造时值快照,宿主切换
|
|
96
|
+
* workbook prop 后导出工具仍导出旧工作簿)
|
|
53
97
|
*/
|
|
54
|
-
declare function createSheetContext(resolveSheet: Sheet | (() => Sheet)): SheetContext;
|
|
98
|
+
declare function createSheetContext(resolveSheet: Sheet | (() => Sheet), workbook?: Workbook | (() => Workbook)): SheetContext;
|
|
55
99
|
//#endregion
|
|
56
|
-
export { SheetContext, createSheetContext };
|
|
57
|
-
//# sourceMappingURL=context.d.ts.map
|
|
100
|
+
export { SheetContext, createSheetContext };
|
package/dist/tools/context.js
CHANGED
|
@@ -3,16 +3,24 @@
|
|
|
3
3
|
* 创建工具上下文。
|
|
4
4
|
* @param resolveSheet 活动 sheet 解析器(USheet 传 `() => activeSheet`,
|
|
5
5
|
* tab 切换后上下文自动指向当前 sheet);也可直接传 Sheet 实例(无头 / 测试场景)
|
|
6
|
+
* @param workbook 当前工作簿(导入导出等工具需要;无头 / 单 sheet 场景可省略)。
|
|
7
|
+
* 支持传解析函数 `() => Workbook`——USheet 在 props.workbook 动态切换后,
|
|
8
|
+
* 上下文始终解析到**当前**工作簿(#2:旧实现取构造时值快照,宿主切换
|
|
9
|
+
* workbook prop 后导出工具仍导出旧工作簿)
|
|
6
10
|
*/
|
|
7
|
-
function createSheetContext(resolveSheet) {
|
|
11
|
+
function createSheetContext(resolveSheet, workbook) {
|
|
8
12
|
const sheet = typeof resolveSheet === "function" ? resolveSheet : () => resolveSheet;
|
|
13
|
+
const resolveWorkbook = typeof workbook === "function" ? workbook : workbook != null ? () => workbook : void 0;
|
|
9
14
|
return {
|
|
15
|
+
get workbook() {
|
|
16
|
+
return resolveWorkbook?.();
|
|
17
|
+
},
|
|
10
18
|
get sheetName() {
|
|
11
19
|
return sheet().name;
|
|
12
20
|
},
|
|
13
21
|
getSelection: () => sheet().getSelection(),
|
|
14
22
|
selectCell: (addr) => sheet().selectCell(addr),
|
|
15
|
-
selectRange: (range) => sheet().selectRange(range),
|
|
23
|
+
selectRange: (range, active) => sheet().selectRange(range, active),
|
|
16
24
|
getCellData: (addr) => sheet().getCellData(addr),
|
|
17
25
|
getDisplayValue: (addr) => sheet().getDisplayValue(addr),
|
|
18
26
|
getCellInfo: (addr) => sheet().getCellInfo(addr),
|
|
@@ -21,7 +29,22 @@ function createSheetContext(resolveSheet) {
|
|
|
21
29
|
setCells: (items) => sheet().setCells(items),
|
|
22
30
|
mergeCells: (range) => sheet().mergeCells(range),
|
|
23
31
|
unmergeCells: (range) => sheet().unmergeCells(range),
|
|
32
|
+
setCellStyle: (range, partial) => sheet().setCellStyle(range, partial),
|
|
33
|
+
clearCellStyle: (range) => sheet().clearCellStyle(range),
|
|
34
|
+
getCellStyle: (addr) => sheet().getCellStyle(addr),
|
|
24
35
|
executeCommand: (commandId, params) => sheet().executeCommand(commandId, params),
|
|
36
|
+
get frozen() {
|
|
37
|
+
return sheet().frozen;
|
|
38
|
+
},
|
|
39
|
+
setFrozen: (rows, cols) => sheet().setFrozen(rows, cols),
|
|
40
|
+
insertRows: (at, count) => sheet().insertRows(at, count),
|
|
41
|
+
insertCols: (at, count) => sheet().insertCols(at, count),
|
|
42
|
+
deleteRows: (at, count) => sheet().deleteRows(at, count),
|
|
43
|
+
deleteCols: (at, count) => sheet().deleteCols(at, count),
|
|
44
|
+
insertImage: (input) => sheet().insertImage(input),
|
|
45
|
+
removeImage: (id) => sheet().removeImage(id),
|
|
46
|
+
updateImage: (id, patch) => sheet().updateImage(id, patch),
|
|
47
|
+
getImages: () => sheet().getImages(),
|
|
25
48
|
beginTransaction: () => sheet().beginTransaction(),
|
|
26
49
|
commit: () => sheet().commit(),
|
|
27
50
|
rollback: () => sheet().rollback(),
|
|
@@ -34,10 +57,10 @@ function createSheetContext(resolveSheet) {
|
|
|
34
57
|
return sheet().canRedo;
|
|
35
58
|
},
|
|
36
59
|
onSelectionChange: (handler) => sheet().on("selection-change", handler),
|
|
37
|
-
onHistoryChange: (handler) => sheet().on("history-change", handler)
|
|
60
|
+
onHistoryChange: (handler) => sheet().on("history-change", handler),
|
|
61
|
+
onFrozenChange: (handler) => sheet().on("frozen-change", handler),
|
|
62
|
+
onImageChange: (handler) => sheet().on("image-change", handler)
|
|
38
63
|
};
|
|
39
64
|
}
|
|
40
65
|
//#endregion
|
|
41
66
|
export { createSheetContext };
|
|
42
|
-
|
|
43
|
-
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { saveBlob } from "@cat-kit/fe";
|
|
2
|
+
import { exportSheetCsv, exportWorkbookXlsx } from "@veltra/sheet-core/core/io/export";
|
|
3
|
+
//#region src/tools/download.ts
|
|
4
|
+
/**
|
|
5
|
+
* 大工作簿的 XLSX 导出(hucre 序列化 + ZIP 压缩为秒级同步重活)移入 Web Worker:
|
|
6
|
+
* 主线程只采集快照(结构化克隆友好的纯数据,行高随 SheetSnapshot.rowHeights
|
|
7
|
+
* 携带),序列化与压缩在 worker 线程进行。worker 不可用(极端环境 / 打包产物
|
|
8
|
+
* 缺文件)回退主线程导出——与导入侧 parseXlsxAsync 同一模式。
|
|
9
|
+
*/
|
|
10
|
+
async function exportWorkbookXlsxAsync(workbook) {
|
|
11
|
+
let worker;
|
|
12
|
+
try {
|
|
13
|
+
const url = import.meta.env?.DEV ? new URL("./export.worker.ts", import.meta.url) : new URL("./export.worker.js", import.meta.url);
|
|
14
|
+
worker = new Worker(url, { type: "module" });
|
|
15
|
+
} catch {
|
|
16
|
+
return exportWorkbookXlsx(workbook);
|
|
17
|
+
}
|
|
18
|
+
const payload = {
|
|
19
|
+
sheets: workbook.getSheets().map((sheet) => ({
|
|
20
|
+
name: sheet.name,
|
|
21
|
+
snapshot: sheet.snapshot()
|
|
22
|
+
})),
|
|
23
|
+
activeIndex: workbook.activeSheetIndex
|
|
24
|
+
};
|
|
25
|
+
return await new Promise((resolve, reject) => {
|
|
26
|
+
let settled = false;
|
|
27
|
+
const fallback = () => {
|
|
28
|
+
if (settled) return;
|
|
29
|
+
settled = true;
|
|
30
|
+
worker.terminate();
|
|
31
|
+
resolve(exportWorkbookXlsx(workbook));
|
|
32
|
+
};
|
|
33
|
+
worker.onmessage = (e) => {
|
|
34
|
+
if (settled) return;
|
|
35
|
+
settled = true;
|
|
36
|
+
worker.terminate();
|
|
37
|
+
const data = e.data;
|
|
38
|
+
if (!data.ok || !data.buffer) {
|
|
39
|
+
reject(new Error(data.error ?? "worker 导出失败"));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
resolve(data.buffer);
|
|
43
|
+
};
|
|
44
|
+
worker.onerror = () => fallback();
|
|
45
|
+
worker.postMessage(payload);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 导出当前工作簿为 .xlsx(无 workbook 时空操作)。
|
|
50
|
+
* 下载动作复用 @cat-kit/fe 的 saveBlob(#28:不再自研 Object URL + a.click)。
|
|
51
|
+
* hucre 1.0 起 writeXlsx 会校验 sheet 名(Excel 非法字符 / 超长 / 保留名)并抛
|
|
52
|
+
* InvalidArgumentError——失败经返回的 Promise 传播,调用方(导出面板)负责提示。
|
|
53
|
+
*/
|
|
54
|
+
async function exportWorkbookFile(ctx) {
|
|
55
|
+
const workbook = ctx.workbook;
|
|
56
|
+
if (!workbook) return;
|
|
57
|
+
const buffer = await exportWorkbookXlsxAsync(workbook);
|
|
58
|
+
saveBlob(new Blob([buffer], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }), `${workbook.activeSheet.name || "workbook"}.xlsx`);
|
|
59
|
+
}
|
|
60
|
+
/** 导出当前工作表为 .csv(无 workbook 时空操作;同步,异常直接抛给调用方) */
|
|
61
|
+
function exportSheetCsvFile(ctx) {
|
|
62
|
+
const workbook = ctx.workbook;
|
|
63
|
+
if (!workbook) return;
|
|
64
|
+
const csv = exportSheetCsv(workbook.activeSheet);
|
|
65
|
+
saveBlob(new Blob([csv], { type: "text/csv;charset=utf-8" }), `${workbook.activeSheet.name || "sheet"}.csv`);
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { exportSheetCsvFile, exportWorkbookFile };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SheetSnapshot } from "@veltra/sheet-core/core/sheet";
|
|
2
|
+
//#region src/tools/export.worker.d.ts
|
|
3
|
+
interface ExportWorkerPayload {
|
|
4
|
+
sheets: {
|
|
5
|
+
name: string;
|
|
6
|
+
snapshot: SheetSnapshot;
|
|
7
|
+
}[];
|
|
8
|
+
activeIndex: number;
|
|
9
|
+
}
|
|
10
|
+
interface ExportWorkerResponse {
|
|
11
|
+
ok: boolean;
|
|
12
|
+
buffer?: Uint8Array;
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ExportWorkerPayload, ExportWorkerResponse };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/tools/export.worker.ts
|
|
2
|
+
self.onmessage = (e) => {
|
|
3
|
+
Promise.all([import("@veltra/sheet-core/core/io/export"), import("@veltra/sheet-core/core/workbook")]).then(([{ exportWorkbookXlsx }, { Workbook }]) => {
|
|
4
|
+
const wb = new Workbook();
|
|
5
|
+
const sheets = e.data.sheets;
|
|
6
|
+
for (let i = 0; i < sheets.length; i++) {
|
|
7
|
+
const { name, snapshot } = sheets[i];
|
|
8
|
+
const sheet = i === 0 ? wb.activeSheet : wb.addSheet(name);
|
|
9
|
+
if (i === 0 && sheet.name !== name) wb.renameSheet(sheet.name, name);
|
|
10
|
+
sheet.restore(snapshot);
|
|
11
|
+
}
|
|
12
|
+
wb.activateSheet(wb.getSheets()[Math.min(e.data.activeIndex, wb.sheetCount - 1)].name);
|
|
13
|
+
return exportWorkbookXlsx(wb);
|
|
14
|
+
}).then((buffer) => {
|
|
15
|
+
const exact = buffer.slice();
|
|
16
|
+
const response = {
|
|
17
|
+
ok: true,
|
|
18
|
+
buffer: exact
|
|
19
|
+
};
|
|
20
|
+
self.postMessage(response, [exact.buffer]);
|
|
21
|
+
}).catch((err) => {
|
|
22
|
+
const response = {
|
|
23
|
+
ok: false,
|
|
24
|
+
error: err instanceof Error ? err.message : String(err)
|
|
25
|
+
};
|
|
26
|
+
self.postMessage(response);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
package/dist/tools/registry.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ import { SheetContext } from "./context.js";
|
|
|
10
10
|
* - 默认注册表全局共享:所有 USheet 实例渲染同一组工具
|
|
11
11
|
* (与 defaultCommandRegistry 同语义;每个实例的 SheetContext 各自绑定当前 sheet)
|
|
12
12
|
*/
|
|
13
|
+
/** 弹层型工具类型:vue 层按类型渲染弹层面板(面板交互走 SheetContext 命令入口) */
|
|
14
|
+
type SheetToolPopupType = 'fill-color' | 'border' | 'font-color' | 'font-size' | 'find' | 'insert-image' | 'export';
|
|
13
15
|
/** 工具定义 */
|
|
14
16
|
interface SheetTool {
|
|
15
17
|
/** 唯一 id;同 id 重复注册视为替换(保留原位置) */
|
|
@@ -28,6 +30,10 @@ interface SheetTool {
|
|
|
28
30
|
visible?(ctx: SheetContext): boolean;
|
|
29
31
|
/** 是否禁用(工具栏状态刷新时求值);缺省可用 */
|
|
30
32
|
disabled?(ctx: SheetContext): boolean;
|
|
33
|
+
/** 是否处于激活/高亮状态(工具栏状态刷新时求值,vue 层渲染 is-active);缺省 false */
|
|
34
|
+
active?(ctx: SheetContext): boolean;
|
|
35
|
+
/** 弹层型工具:vue 层渲染弹层面板,onClick 不执行(面板交互走 SheetContext) */
|
|
36
|
+
popup?: SheetToolPopupType;
|
|
31
37
|
/** 点击执行;ctx 是唯一操作入口(写操作全走命令系统,天然可撤销) */
|
|
32
38
|
onClick(ctx: SheetContext): void;
|
|
33
39
|
}
|
|
@@ -36,8 +42,6 @@ interface SheetToolGroup {
|
|
|
36
42
|
name: string;
|
|
37
43
|
tools: SheetTool[];
|
|
38
44
|
}
|
|
39
|
-
/** 缺省分组名 */
|
|
40
|
-
declare const DEFAULT_TOOL_GROUP = "default";
|
|
41
45
|
declare class ToolRegistry {
|
|
42
46
|
private entries;
|
|
43
47
|
private seq;
|
|
@@ -64,5 +68,4 @@ declare function registerTool(tool: SheetTool): void;
|
|
|
64
68
|
/** 从默认注册表注销工具;id 不存在时返回 false */
|
|
65
69
|
declare function unregisterTool(id: string): boolean;
|
|
66
70
|
//#endregion
|
|
67
|
-
export {
|
|
68
|
-
//# sourceMappingURL=registry.d.ts.map
|
|
71
|
+
export { SheetTool, SheetToolGroup, SheetToolPopupType, ToolRegistry, defaultToolRegistry, registerTool, unregisterTool };
|
package/dist/tools/registry.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TypedEventEmitter } from "
|
|
1
|
+
import { TypedEventEmitter } from "@veltra/sheet-core/core/events";
|
|
2
2
|
//#region src/tools/registry.ts
|
|
3
3
|
/** 缺省分组名 */
|
|
4
4
|
const DEFAULT_TOOL_GROUP = "default";
|
|
@@ -73,5 +73,3 @@ function unregisterTool(id) {
|
|
|
73
73
|
}
|
|
74
74
|
//#endregion
|
|
75
75
|
export { DEFAULT_TOOL_GROUP, ToolRegistry, defaultToolRegistry, registerTool, unregisterTool };
|
|
76
|
-
|
|
77
|
-
//# sourceMappingURL=registry.js.map
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { SheetEmits, SheetExposed, SheetProps, _SheetExposed } from "./sheet.js";
|
|
2
|
-
|
|
2
|
+
import { ReportViewerExposed, ReportViewerProps, _ReportViewerExposed } from "./report-viewer.js";
|
|
3
|
+
import { ReportDesignerEmits, ReportDesignerExposed, ReportDesignerProps, _ReportDesignerExposed } from "./report-designer.js";
|
|
4
|
+
export { ReportDesignerEmits, ReportDesignerExposed, ReportDesignerProps, ReportViewerExposed, ReportViewerProps, SheetEmits, SheetExposed, SheetProps, _ReportDesignerExposed, _ReportViewerExposed, _SheetExposed };
|