@veltra/sheet 2.0.1 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -26
- package/dist/index.js +3 -23
- package/dist/tools/builtin.js +279 -8
- package/dist/tools/context.d.ts +54 -11
- package/dist/tools/context.js +28 -5
- package/dist/tools/download.js +68 -0
- package/dist/tools/export.worker.d.ts +16 -0
- package/dist/tools/export.worker.js +29 -0
- package/dist/tools/registry.d.ts +7 -4
- package/dist/tools/registry.js +1 -3
- package/dist/types/index.d.ts +1 -0
- package/dist/types/sheet.d.ts +6 -5
- package/dist/vue/formula-bar.js +393 -0
- package/dist/vue/formula-suggest-list.js +66 -0
- package/dist/vue/import-file.js +140 -0
- package/dist/vue/insert-count-menu-item.js +68 -0
- package/dist/vue/insert-image.js +79 -0
- package/dist/vue/popup-helpers.js +73 -0
- package/dist/vue/popups/border-popup.js +75 -0
- package/dist/vue/popups/border-preset-glyph.js +106 -0
- package/dist/vue/popups/export-popup.js +51 -0
- package/dist/vue/popups/fill-color-popup.js +37 -0
- package/dist/vue/popups/find-popup.js +113 -0
- package/dist/vue/popups/font-color-popup.js +37 -0
- package/dist/vue/popups/font-size-popup.js +63 -0
- package/dist/vue/popups/import.worker.d.ts +21 -0
- package/dist/vue/popups/import.worker.js +41 -0
- package/dist/vue/popups/insert-image-popup.js +38 -0
- package/dist/vue/sheet-context-menu.js +200 -0
- package/dist/vue/sheet-tabs.js +162 -0
- package/dist/vue/sheet-toolbar.js +106 -0
- package/dist/vue/sheet.js +144 -164
- package/dist/vue/style.d.ts +11 -1
- package/dist/vue/style.js +10 -0
- package/dist/vue/style2.css +564 -3
- package/dist/vue/use-find-replace.js +161 -0
- package/dist/vue/use-formula-ref-select.js +37 -0
- package/dist/vue/use-formula-suggest.js +126 -0
- package/dist/vue/use-sheet-grid.js +180 -0
- package/dist/vue/use-sheet-state.js +122 -0
- package/dist/vue/use-sheet-tabs-bar.js +90 -0
- package/dist/vue/use-tool-groups.js +42 -0
- package/dist/vue/use-tool-popup.js +123 -0
- package/dist/vue/use-toolbar-scroll.js +72 -0
- package/package.json +12 -7
- package/src/env.d.ts +11 -0
- package/src/index.ts +203 -14
- package/src/tools/__test__/builtin.test.ts +208 -66
- package/src/tools/__test__/context.test.ts +62 -2
- package/src/tools/builtin.ts +350 -6
- package/src/tools/context.ts +89 -11
- package/src/tools/download.ts +82 -0
- package/src/tools/export.worker.ts +61 -0
- package/src/tools/registry.ts +16 -1
- package/src/types/index.ts +6 -0
- package/src/types/sheet.ts +5 -3
- package/src/vue/__test__/formula-bar.test.ts +455 -0
- package/src/vue/__test__/import-file.test.ts +183 -0
- package/src/vue/__test__/insert-count-menu-item.test.ts +123 -0
- package/src/vue/__test__/insert-image-popup.test.ts +89 -0
- package/src/vue/__test__/insert-image.test.ts +100 -0
- package/src/vue/__test__/sheet-component.test.ts +716 -27
- package/src/vue/__test__/sheet-context-menu.test.ts +206 -0
- package/src/vue/__test__/use-formula-ref-select.test.ts +35 -0
- package/src/vue/__test__/use-formula-suggest.test.ts +83 -0
- package/src/vue/formula-bar.vue +473 -0
- package/src/vue/formula-suggest-list.vue +64 -0
- package/src/vue/import-file.ts +173 -0
- package/src/vue/insert-count-menu-item.vue +69 -0
- package/src/vue/insert-image.ts +90 -0
- package/src/vue/parsing.ts +11 -0
- package/src/vue/popup-helpers.ts +50 -0
- package/src/vue/popups/border-popup.vue +93 -0
- package/src/vue/popups/border-preset-glyph.vue +111 -0
- package/src/vue/popups/export-popup.vue +52 -0
- package/src/vue/popups/fill-color-popup.vue +39 -0
- package/src/vue/popups/find-popup.vue +111 -0
- package/src/vue/popups/font-color-popup.vue +39 -0
- package/src/vue/popups/font-size-popup.vue +52 -0
- package/src/vue/popups/import.worker.ts +66 -0
- package/src/vue/popups/insert-image-popup.vue +39 -0
- package/src/vue/sheet-context-menu.ts +229 -0
- package/src/vue/sheet-tabs.vue +162 -0
- package/src/vue/sheet-toolbar.vue +91 -0
- package/src/vue/sheet.vue +161 -186
- package/src/vue/style.scss +646 -3
- package/src/vue/style.ts +11 -0
- package/src/vue/use-find-replace.ts +200 -0
- package/src/vue/use-formula-ref-select.ts +34 -0
- package/src/vue/use-formula-suggest.ts +150 -0
- package/src/vue/use-sheet-grid.ts +243 -0
- package/src/vue/use-sheet-state.ts +161 -0
- package/src/vue/use-sheet-tabs-bar.ts +115 -0
- package/src/vue/use-tool-groups.ts +61 -0
- package/src/vue/use-tool-popup.ts +150 -0
- package/src/vue/use-toolbar-scroll.ts +95 -0
- package/dist/core/address.d.ts +0 -60
- package/dist/core/address.js +0 -142
- package/dist/core/address.js.map +0 -1
- package/dist/core/cell-store.d.ts +0 -61
- package/dist/core/cell-store.js +0 -135
- package/dist/core/cell-store.js.map +0 -1
- package/dist/core/command/default-registry.d.ts +0 -10
- package/dist/core/command/default-registry.js +0 -18
- package/dist/core/command/default-registry.js.map +0 -1
- package/dist/core/command/history.d.ts +0 -64
- package/dist/core/command/history.js +0 -127
- package/dist/core/command/history.js.map +0 -1
- package/dist/core/command/merge-cells.d.ts +0 -21
- package/dist/core/command/merge-cells.js +0 -74
- package/dist/core/command/merge-cells.js.map +0 -1
- package/dist/core/command/registry.d.ts +0 -17
- package/dist/core/command/registry.js +0 -26
- package/dist/core/command/registry.js.map +0 -1
- package/dist/core/command/set-cell-formula.d.ts +0 -17
- package/dist/core/command/set-cell-formula.js +0 -29
- package/dist/core/command/set-cell-formula.js.map +0 -1
- package/dist/core/command/set-cell-value.d.ts +0 -22
- package/dist/core/command/set-cell-value.js +0 -35
- package/dist/core/command/set-cell-value.js.map +0 -1
- package/dist/core/command/types.d.ts +0 -68
- package/dist/core/events.js +0 -29
- package/dist/core/events.js.map +0 -1
- package/dist/core/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.map +0 -1
- package/dist/vue/sheet.vue.d.ts +0 -24
- package/src/core/__test__/address.test.ts +0 -113
- package/src/core/__test__/cell-store.test.ts +0 -97
- package/src/core/__test__/command.test.ts +0 -377
- package/src/core/__test__/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/dist/index.d.ts
CHANGED
|
@@ -1,29 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { CellData, CellSnapshotItem, CellStore, CellType, CellValue, cellDataEqual, inferCellType, isEmptyCellData } from "./core/cell-store.js";
|
|
3
|
-
import { DEFAULT_HISTORY_CAPACITY, HistoryManager, HistoryState } from "./core/command/history.js";
|
|
4
|
-
import { AstNode, AstReference, BinaryOperator, collectReferences } from "./core/formula/ast.js";
|
|
5
|
-
import { DependencyGraph, FormulaDependency, FormulaNode } from "./core/formula/dependency-graph.js";
|
|
6
|
-
import { CellInfo, MergeManager, MergeResult, MergedCellKind } from "./core/merge-manager.js";
|
|
7
|
-
import { SelectionModel, SelectionState } from "./core/selection.js";
|
|
8
|
-
import { Sheet, SheetEvents } from "./core/sheet.js";
|
|
9
|
-
import { CellPatch, Command, CommandContext, CommandResult, MergePatch, Mutation, Patch, PatchDirection } from "./core/command/types.js";
|
|
10
|
-
import { SetCellValueCommand, SetCellValueItem, SetCellValueParams } from "./core/command/set-cell-value.js";
|
|
11
|
-
import { FillDirection, GenerateFillOptions, computeFillTargetRange, generateFill, shiftFormulaRefs } from "./core/fill.js";
|
|
12
|
-
import { Workbook, WorkbookEvents } from "./core/workbook.js";
|
|
13
|
-
import { CommandRegistry } from "./core/command/registry.js";
|
|
14
|
-
import { SetCellFormulaCommand, SetCellFormulaParams } from "./core/command/set-cell-formula.js";
|
|
15
|
-
import { MergeCellsCommand, MergeCellsParams, UnmergeCellsCommand, UnmergeCellsParams } from "./core/command/merge-cells.js";
|
|
16
|
-
import { defaultCommandRegistry } from "./core/command/default-registry.js";
|
|
17
|
-
import { FORMULA_ERROR_CODES, FormulaError, FormulaErrorCode, formulaError, isFormulaError, isFormulaErrorCode } from "./core/formula/errors.js";
|
|
18
|
-
import { FormulaOperator, FormulaParseError, FormulaToken, tokenizeFormula } from "./core/formula/tokenizer.js";
|
|
19
|
-
import { parseFormula } from "./core/formula/parser.js";
|
|
20
|
-
import { EvalValue, FormulaEvalContext, ScalarValue, coerceToBoolean, coerceToNumber, coerceToText, compareScalars, evaluateAst } from "./core/formula/evaluator.js";
|
|
21
|
-
import { FormulaFunction, getFormulaFunction, invokeFormulaFunction, registerFormulaFunction } from "./core/formula/functions.js";
|
|
22
|
-
import { SheetGrid, SheetGridContextMenuInfo, SheetGridOptions } from "./grid/sheet-grid.js";
|
|
1
|
+
import _sfc_main from "./vue/sheet.js";
|
|
23
2
|
import { SheetContext, createSheetContext } from "./tools/context.js";
|
|
24
|
-
import {
|
|
3
|
+
import { SheetTool, SheetToolGroup, SheetToolPopupType, defaultToolRegistry, registerTool, unregisterTool } from "./tools/registry.js";
|
|
25
4
|
import { SheetEmits, SheetExposed, SheetProps, _SheetExposed } from "./types/sheet.js";
|
|
26
5
|
import "./types/index.js";
|
|
27
|
-
import
|
|
28
|
-
|
|
29
|
-
export { AstNode, AstReference, BinaryOperator, COL_KEY_BASE, CellAddress, CellData, CellInfo, CellPatch, CellRange, CellSnapshotItem, CellStore, CellType, CellValue, Command, CommandContext, CommandRegistry, CommandResult, DEFAULT_HISTORY_CAPACITY, DEFAULT_TOOL_GROUP, DependencyGraph, EvalValue, FORMULA_ERROR_CODES, FillDirection, FormulaDependency, FormulaError, FormulaErrorCode, FormulaEvalContext, FormulaFunction, FormulaNode, FormulaOperator, FormulaParseError, FormulaToken, GenerateFillOptions, HistoryManager, HistoryState, MergeCellsCommand, MergeCellsParams, MergeManager, MergePatch, MergeResult, MergedCellKind, Mutation, Patch, PatchDirection, ScalarValue, SelectionModel, SelectionState, SetCellFormulaCommand, SetCellFormulaParams, SetCellValueCommand, SetCellValueItem, SetCellValueParams, Sheet, SheetContext, SheetEmits, SheetEvents, SheetExposed, SheetGrid, SheetGridContextMenuInfo, SheetGridOptions, SheetProps, SheetTool, SheetToolGroup, ToolRegistry, _default as USheet, UnmergeCellsCommand, UnmergeCellsParams, Workbook, WorkbookEvents, _SheetExposed, addressFromKey, addressesEqual, boundingBox, cellDataEqual, cellKey, coerceToBoolean, coerceToNumber, coerceToText, colIndexToName, colNameToIndex, collectReferences, compareScalars, computeFillTargetRange, createRange, createSheetContext, defaultCommandRegistry, defaultToolRegistry, evaluateAst, formatAddress, formatRange, formulaError, generateFill, getFormulaFunction, inferCellType, invokeFormulaFunction, isEmptyCellData, isFormulaError, isFormulaErrorCode, iterateRange, parseAddress, parseFormula, parseRange, rangeContainsAddress, rangeContainsRange, rangeSize, rangesEqual, rangesIntersect, registerFormulaFunction, registerTool, shiftFormulaRefs, tokenizeFormula, unregisterTool };
|
|
6
|
+
import { ALIGN_STYLE_KEYS, AstNode, AstReference, BORDER_EDGE_DEFAULTS, BORDER_SIDES, BORDER_STYLE_WIDTH, BinaryOperator, BorderEdge, BorderLineStyle, BorderPreset, BorderPresetItem, BorderSide, CellAddress, CellAlign, CellData, CellFont, CellInfo, CellPatch, CellRange, CellSnapshotItem, CellStore, CellStyle, CellStylePatch, CellType, CellValue, Command, CommandContext, CommandResult, DependencyGraph, EvalValue, FONT_STYLE_KEYS, FORMULA_ERROR_CODES, FillDirection, FindMatch, FindOptions, FormulaDependency, FormulaError, FormulaErrorCode, FormulaEvalContext, FormulaFunction, FormulaFunctionMeta, FormulaNode, FormulaOperator, FormulaParseError, FormulaToken, FrozenState, GenerateFillOptions, HistoryManager, HistoryState, HorizontalAlign, ImageInput, ImagePatch, ImageUpdateFields, InsertCellsCommand, InsertCellsParams, InsertImageCommand, InsertImageParams, MergeCellsCommand, MergeCellsParams, MergeManager, MergePatch, MergeResult, MergedCellKind, Mutation, NUMERIC_TEXT_RE, Patch, PatchDirection, RemoveImageCommand, RemoveImageParams, ScalarValue, SelectionModel, SelectionState, SetCellFormulaCommand, SetCellFormulaParams, SetCellStyleCommand, SetCellStyleItem, SetCellStyleParams, SetCellValueCommand, SetCellValueItem, SetCellValueParams, Sheet, SheetEvents, SheetGrid, SheetGridContextMenuInfo, SheetGridContextMenuKind, SheetGridOptions, SheetImage, SheetImageAnchor, SheetImageType, SheetSnapshot, SnapshotPatch, StructureChange, StructurePatch, StyleId, StylePool, UnmergeCellsCommand, UnmergeCellsParams, UpdateImageCommand, UpdateImageParams, VerticalAlign, Workbook, WorkbookEvents, boundingBox, buildBorderPresetItems, cellDataEqual, cellKey, cloneImageAnchor, cloneSheetImage, coerceToBoolean, coerceToNumber, coerceToText, colIndexToName, colNameToIndex, collectReferences, computeFillTargetRange, createImageId, createRange, defaultCommandRegistry, evaluateAst, exportSheetCsv, exportWorkbookXlsx, findAll, findNext, findNextFrom, findPrev, findPrevFrom, formatAddress, formatRange, formulaError, generateFill, importCsv, importXlsx, inferCellType, invokeFormulaFunction, isEmptyCellData, isFormulaError, isFormulaErrorCode, iterateRange, listFormulaFunctions, normalizeInputValue, parseAddress, parseFormula, parseRange, rangeContainsAddress, rangesEqual, rangesIntersect, registerFormulaFunction, replaceWorkbook, tokenizeFormula } from "@veltra/sheet-core";
|
|
7
|
+
export { ALIGN_STYLE_KEYS, type AstNode, type AstReference, BORDER_EDGE_DEFAULTS, BORDER_SIDES, BORDER_STYLE_WIDTH, type BinaryOperator, type BorderEdge, type BorderLineStyle, type BorderPreset, type BorderPresetItem, type BorderSide, type CellAddress, type CellAlign, type CellData, type CellFont, type CellInfo, type CellPatch, type CellRange, type CellSnapshotItem, CellStore, type CellStyle, type CellStylePatch, type CellType, type CellValue, type Command, type CommandContext, type CommandResult, DependencyGraph, type EvalValue, FONT_STYLE_KEYS, FORMULA_ERROR_CODES, type FillDirection, type FindMatch, type FindOptions, type FormulaDependency, type FormulaError, type FormulaErrorCode, type FormulaEvalContext, type FormulaFunction, type FormulaFunctionMeta, type FormulaNode, type FormulaOperator, FormulaParseError, type FormulaToken, type FrozenState, type GenerateFillOptions, HistoryManager, type HistoryState, type HorizontalAlign, type ImageInput, type ImagePatch, type ImageUpdateFields, InsertCellsCommand, type InsertCellsParams, InsertImageCommand, type InsertImageParams, MergeCellsCommand, type MergeCellsParams, MergeManager, type MergePatch, type MergeResult, type MergedCellKind, type Mutation, NUMERIC_TEXT_RE, type Patch, type PatchDirection, RemoveImageCommand, type RemoveImageParams, type ScalarValue, SelectionModel, type SelectionState, SetCellFormulaCommand, type SetCellFormulaParams, SetCellStyleCommand, type SetCellStyleItem, type SetCellStyleParams, SetCellValueCommand, type SetCellValueItem, type SetCellValueParams, Sheet, type SheetContext, type SheetEmits, type SheetEvents, type SheetExposed, SheetGrid, type SheetGridContextMenuInfo, type SheetGridContextMenuKind, type SheetGridOptions, type SheetImage, type SheetImageAnchor, type SheetImageType, type SheetProps, type SheetSnapshot, type SheetTool, type SheetToolGroup, type SheetToolPopupType, type SnapshotPatch, type StructureChange, type StructurePatch, type StyleId, StylePool, _sfc_main as USheet, UnmergeCellsCommand, type UnmergeCellsParams, UpdateImageCommand, type UpdateImageParams, type VerticalAlign, Workbook, type WorkbookEvents, type _SheetExposed, boundingBox, buildBorderPresetItems, cellDataEqual, cellKey, cloneImageAnchor, cloneSheetImage, coerceToBoolean, coerceToNumber, coerceToText, colIndexToName, colNameToIndex, collectReferences, computeFillTargetRange, createImageId, createRange, createSheetContext, defaultCommandRegistry, defaultToolRegistry, evaluateAst, exportSheetCsv, exportWorkbookXlsx, findAll, findNext, findNextFrom, findPrev, findPrevFrom, formatAddress, formatRange, formulaError, generateFill, importCsv, importXlsx, inferCellType, invokeFormulaFunction, isEmptyCellData, isFormulaError, isFormulaErrorCode, iterateRange, listFormulaFunctions, normalizeInputValue, parseAddress, parseFormula, parseRange, rangeContainsAddress, rangesEqual, rangesIntersect, registerFormulaFunction, registerTool, replaceWorkbook, tokenizeFormula, unregisterTool };
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DEFAULT_TOOL_GROUP, ToolRegistry, defaultToolRegistry, registerTool, unregisterTool } from "./tools/registry.js";
|
|
1
|
+
import { defaultToolRegistry, registerTool, unregisterTool } from "./tools/registry.js";
|
|
3
2
|
import "./tools/builtin.js";
|
|
4
|
-
import { CellStore, cellDataEqual, inferCellType, isEmptyCellData } from "./core/cell-store.js";
|
|
5
|
-
import { computeFillTargetRange, generateFill, shiftFormulaRefs } from "./core/fill.js";
|
|
6
|
-
import { MergeManager } from "./core/merge-manager.js";
|
|
7
|
-
import { SelectionModel } from "./core/selection.js";
|
|
8
|
-
import { MergeCellsCommand, UnmergeCellsCommand } from "./core/command/merge-cells.js";
|
|
9
|
-
import { CommandRegistry } from "./core/command/registry.js";
|
|
10
|
-
import { SetCellFormulaCommand } from "./core/command/set-cell-formula.js";
|
|
11
|
-
import { SetCellValueCommand } from "./core/command/set-cell-value.js";
|
|
12
|
-
import { defaultCommandRegistry } from "./core/command/default-registry.js";
|
|
13
|
-
import { DEFAULT_HISTORY_CAPACITY, HistoryManager } from "./core/command/history.js";
|
|
14
|
-
import { collectReferences } from "./core/formula/ast.js";
|
|
15
|
-
import { FORMULA_ERROR_CODES, formulaError, isFormulaError, isFormulaErrorCode } from "./core/formula/errors.js";
|
|
16
|
-
import { coerceToBoolean, coerceToNumber, coerceToText, compareScalars, evaluateAst } from "./core/formula/evaluator.js";
|
|
17
|
-
import { getFormulaFunction, invokeFormulaFunction, registerFormulaFunction } from "./core/formula/functions.js";
|
|
18
|
-
import { FormulaParseError, tokenizeFormula } from "./core/formula/tokenizer.js";
|
|
19
|
-
import { parseFormula } from "./core/formula/parser.js";
|
|
20
|
-
import { DependencyGraph } from "./core/formula/dependency-graph.js";
|
|
21
|
-
import { Sheet } from "./core/sheet.js";
|
|
22
|
-
import { Workbook } from "./core/workbook.js";
|
|
23
|
-
import { SheetGrid } from "./grid/sheet-grid.js";
|
|
24
3
|
import { createSheetContext } from "./tools/context.js";
|
|
25
4
|
import _sfc_main from "./vue/sheet.js";
|
|
26
|
-
|
|
5
|
+
import { ALIGN_STYLE_KEYS, BORDER_EDGE_DEFAULTS, BORDER_SIDES, BORDER_STYLE_WIDTH, CellStore, DependencyGraph, FONT_STYLE_KEYS, FORMULA_ERROR_CODES, FormulaParseError, HistoryManager, InsertCellsCommand, InsertImageCommand, MergeCellsCommand, MergeManager, NUMERIC_TEXT_RE, RemoveImageCommand, SelectionModel, SetCellFormulaCommand, SetCellStyleCommand, SetCellValueCommand, Sheet, SheetGrid, StylePool, UnmergeCellsCommand, UpdateImageCommand, Workbook, boundingBox, buildBorderPresetItems, cellDataEqual, cellKey, cloneImageAnchor, cloneSheetImage, coerceToBoolean, coerceToNumber, coerceToText, colIndexToName, colNameToIndex, collectReferences, computeFillTargetRange, createImageId, createRange, defaultCommandRegistry, evaluateAst, exportSheetCsv, exportWorkbookXlsx, findAll, findNext, findNextFrom, findPrev, findPrevFrom, formatAddress, formatRange, formulaError, generateFill, importCsv, importXlsx, inferCellType, invokeFormulaFunction, isEmptyCellData, isFormulaError, isFormulaErrorCode, iterateRange, listFormulaFunctions, normalizeInputValue, parseAddress, parseFormula, parseRange, rangeContainsAddress, rangesEqual, rangesIntersect, registerFormulaFunction, replaceWorkbook, tokenizeFormula } from "@veltra/sheet-core";
|
|
6
|
+
export { ALIGN_STYLE_KEYS, BORDER_EDGE_DEFAULTS, BORDER_SIDES, BORDER_STYLE_WIDTH, CellStore, DependencyGraph, FONT_STYLE_KEYS, FORMULA_ERROR_CODES, FormulaParseError, HistoryManager, InsertCellsCommand, InsertImageCommand, MergeCellsCommand, MergeManager, NUMERIC_TEXT_RE, RemoveImageCommand, SelectionModel, SetCellFormulaCommand, SetCellStyleCommand, SetCellValueCommand, Sheet, SheetGrid, StylePool, _sfc_main as USheet, UnmergeCellsCommand, UpdateImageCommand, Workbook, boundingBox, buildBorderPresetItems, cellDataEqual, cellKey, cloneImageAnchor, cloneSheetImage, coerceToBoolean, coerceToNumber, coerceToText, colIndexToName, colNameToIndex, collectReferences, computeFillTargetRange, createImageId, createRange, createSheetContext, defaultCommandRegistry, defaultToolRegistry, evaluateAst, exportSheetCsv, exportWorkbookXlsx, findAll, findNext, findNextFrom, findPrev, findPrevFrom, formatAddress, formatRange, formulaError, generateFill, importCsv, importXlsx, inferCellType, invokeFormulaFunction, isEmptyCellData, isFormulaError, isFormulaErrorCode, iterateRange, listFormulaFunctions, normalizeInputValue, parseAddress, parseFormula, parseRange, rangeContainsAddress, rangesEqual, rangesIntersect, registerFormulaFunction, registerTool, replaceWorkbook, tokenizeFormula, unregisterTool };
|
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 { SetCellValueItem } from "
|
|
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 { HistoryState } from "@veltra/sheet-core/core/command/history";
|
|
6
|
+
import { ImageUpdateFields } from "@veltra/sheet-core/core/command/image";
|
|
7
|
+
import { SetCellValueItem } from "@veltra/sheet-core/core/command/set-cell-value";
|
|
8
|
+
import { ImageInput, SheetImage } from "@veltra/sheet-core/core/image";
|
|
9
|
+
import { CellInfo } from "@veltra/sheet-core/core/merge-manager";
|
|
10
|
+
import { SelectionState } from "@veltra/sheet-core/core/selection";
|
|
11
|
+
import { FrozenState, Sheet } from "@veltra/sheet-core/core/sheet";
|
|
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 };
|