@visactor/vtable-plugins 1.22.6-alpha.2 → 1.22.6
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/cjs/auto-fill/__tests__/formula-integration.test.d.ts +23 -0
- package/cjs/auto-fill/__tests__/formula-integration.test.js +61 -0
- package/cjs/auto-fill/__tests__/formula-integration.test.js.map +1 -0
- package/cjs/auto-fill/auto-fill-manager.d.ts +1 -0
- package/cjs/auto-fill/auto-fill-manager.js +27 -10
- package/cjs/auto-fill/auto-fill-manager.js.map +1 -1
- package/cjs/auto-fill/auto-fill-services.js +1 -1
- package/cjs/auto-fill/auto-fill-services.js.map +1 -1
- package/cjs/auto-fill/formula-integration.d.ts +40 -0
- package/cjs/auto-fill/formula-integration.js +77 -0
- package/cjs/auto-fill/formula-integration.js.map +1 -0
- package/cjs/auto-fill/index.d.ts +6 -0
- package/cjs/auto-fill/index.js +19 -1
- package/cjs/auto-fill/index.js.map +1 -1
- package/cjs/auto-fill/rules.d.ts +1 -0
- package/cjs/auto-fill/rules.js +128 -3
- package/cjs/auto-fill/rules.js.map +1 -1
- package/cjs/contextmenu/index.js +1 -2
- package/cjs/contextmenu/menu-manager.js +2 -1
- package/cjs/excel-edit-cell-keyboard.d.ts +1 -0
- package/cjs/excel-edit-cell-keyboard.js +5 -4
- package/cjs/excel-edit-cell-keyboard.js.map +1 -1
- package/cjs/filter/filter-state-manager.js +1 -1
- package/cjs/filter/filter-state-manager.js.map +1 -1
- package/cjs/filter/filter-toolbar.d.ts +1 -0
- package/cjs/filter/filter-toolbar.js +10 -2
- package/cjs/filter/filter-toolbar.js.map +1 -1
- package/cjs/filter/filter.js +2 -1
- package/cjs/filter/filter.js.map +1 -1
- package/cjs/filter/types.d.ts +1 -1
- package/cjs/filter/types.js.map +1 -1
- package/cjs/filter/value-filter.d.ts +14 -9
- package/cjs/filter/value-filter.js +102 -182
- package/cjs/filter/value-filter.js.map +1 -1
- package/cjs/master-detail-plugin/config.js +1 -2
- package/cjs/master-detail-plugin/core.js +2 -1
- package/cjs/table-export/index.js +1 -1
- package/dist/vtable-plugins.js +698 -403
- package/dist/vtable-plugins.min.js +3 -3
- package/es/auto-fill/__tests__/formula-integration.test.d.ts +23 -0
- package/es/auto-fill/__tests__/formula-integration.test.js +54 -0
- package/es/auto-fill/__tests__/formula-integration.test.js.map +1 -0
- package/es/auto-fill/auto-fill-manager.d.ts +1 -0
- package/es/auto-fill/auto-fill-manager.js +34 -15
- package/es/auto-fill/auto-fill-manager.js.map +1 -1
- package/es/auto-fill/auto-fill-services.js +2 -2
- package/es/auto-fill/auto-fill-services.js.map +1 -1
- package/es/auto-fill/formula-integration.d.ts +40 -0
- package/es/auto-fill/formula-integration.js +67 -0
- package/es/auto-fill/formula-integration.js.map +1 -0
- package/es/auto-fill/index.d.ts +6 -0
- package/es/auto-fill/index.js +7 -1
- package/es/auto-fill/index.js.map +1 -1
- package/es/auto-fill/rules.d.ts +1 -0
- package/es/auto-fill/rules.js +127 -0
- package/es/auto-fill/rules.js.map +1 -1
- package/es/contextmenu/index.js +1 -2
- package/es/contextmenu/menu-manager.js +2 -1
- package/es/excel-edit-cell-keyboard.d.ts +1 -0
- package/es/excel-edit-cell-keyboard.js +5 -4
- package/es/excel-edit-cell-keyboard.js.map +1 -1
- package/es/filter/filter-state-manager.js +1 -1
- package/es/filter/filter-state-manager.js.map +1 -1
- package/es/filter/filter-toolbar.d.ts +1 -0
- package/es/filter/filter-toolbar.js +10 -2
- package/es/filter/filter-toolbar.js.map +1 -1
- package/es/filter/filter.js +2 -1
- package/es/filter/filter.js.map +1 -1
- package/es/filter/types.d.ts +1 -1
- package/es/filter/types.js.map +1 -1
- package/es/filter/value-filter.d.ts +14 -9
- package/es/filter/value-filter.js +101 -182
- package/es/filter/value-filter.js.map +1 -1
- package/es/master-detail-plugin/config.js +1 -2
- package/es/master-detail-plugin/core.js +2 -1
- package/es/table-export/index.js +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ListTable } from '@visactor/vtable';
|
|
2
|
+
export declare function setupAutoFillWithFormulas(table: ListTable, formulaManager?: any): any;
|
|
3
|
+
export declare function demonstrateFormulaAdapter(table: ListTable, formulaManager?: any): void;
|
|
4
|
+
export declare const formulaAutoFillExamples: {
|
|
5
|
+
simpleSeries: {
|
|
6
|
+
cell: string;
|
|
7
|
+
formula: string;
|
|
8
|
+
}[];
|
|
9
|
+
mixedReferences: {
|
|
10
|
+
cell: string;
|
|
11
|
+
formula: string;
|
|
12
|
+
}[];
|
|
13
|
+
mathematicalSeries: {
|
|
14
|
+
cell: string;
|
|
15
|
+
formula: string;
|
|
16
|
+
}[];
|
|
17
|
+
functionSeries: {
|
|
18
|
+
cell: string;
|
|
19
|
+
formula: string;
|
|
20
|
+
}[];
|
|
21
|
+
};
|
|
22
|
+
export declare function testFormulaAutoFill(): void;
|
|
23
|
+
export declare function testVTableSheetIntegration(table: ListTable): void;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.testVTableSheetIntegration = exports.testFormulaAutoFill = exports.formulaAutoFillExamples = exports.demonstrateFormulaAdapter = exports.setupAutoFillWithFormulas = void 0;
|
|
6
|
+
|
|
7
|
+
const auto_fill_1 = require("../src/auto-fill");
|
|
8
|
+
|
|
9
|
+
function setupAutoFillWithFormulas(table, formulaManager) {
|
|
10
|
+
const autoFillPlugin = new auto_fill_1.AutoFillPlugin({
|
|
11
|
+
fillMode: "series"
|
|
12
|
+
});
|
|
13
|
+
return table.registerPlugin(autoFillPlugin), autoFillPlugin;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function demonstrateFormulaAdapter(table, formulaManager) {
|
|
17
|
+
const formulaAdapter = (0, auto_fill_1.createFormulaAdapter)(table, formulaManager);
|
|
18
|
+
formulaAdapter.isFormulaCell(0, 0), formulaAdapter.getCellFormula(0, 0);
|
|
19
|
+
formulaAdapter.setCellFormula(1, 0, "=A1+1");
|
|
20
|
+
formulaAdapter.getCalculatedValue(1, 0);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function testFormulaAutoFill() {}
|
|
24
|
+
|
|
25
|
+
function testVTableSheetIntegration(table) {
|
|
26
|
+
table.changeCellValue(1, 0, "10"), table.changeCellValue(1, 1, "20"), table.changeCellValue(1, 2, "30");
|
|
27
|
+
(0, auto_fill_1.createFormulaAdapter)(table).setCellFormula(0, 0, "=B1*2");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.setupAutoFillWithFormulas = setupAutoFillWithFormulas, exports.demonstrateFormulaAdapter = demonstrateFormulaAdapter,
|
|
31
|
+
exports.formulaAutoFillExamples = {
|
|
32
|
+
simpleSeries: [ {
|
|
33
|
+
cell: "A1",
|
|
34
|
+
formula: "=B1"
|
|
35
|
+
}, {
|
|
36
|
+
cell: "A2",
|
|
37
|
+
formula: "=B2"
|
|
38
|
+
} ],
|
|
39
|
+
mixedReferences: [ {
|
|
40
|
+
cell: "C1",
|
|
41
|
+
formula: "=$A$1+B1"
|
|
42
|
+
}, {
|
|
43
|
+
cell: "C2",
|
|
44
|
+
formula: "=$A$1+B2"
|
|
45
|
+
} ],
|
|
46
|
+
mathematicalSeries: [ {
|
|
47
|
+
cell: "D1",
|
|
48
|
+
formula: "=A1+1"
|
|
49
|
+
}, {
|
|
50
|
+
cell: "D2",
|
|
51
|
+
formula: "=A2+2"
|
|
52
|
+
} ],
|
|
53
|
+
functionSeries: [ {
|
|
54
|
+
cell: "E1",
|
|
55
|
+
formula: "=SUM(A1:B1)"
|
|
56
|
+
}, {
|
|
57
|
+
cell: "E2",
|
|
58
|
+
formula: "=SUM(A2:B2)"
|
|
59
|
+
} ]
|
|
60
|
+
}, exports.testFormulaAutoFill = testFormulaAutoFill, exports.testVTableSheetIntegration = testVTableSheetIntegration;
|
|
61
|
+
//# sourceMappingURL=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OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IACxC,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;AAChD,CAAC;AAfD,gEAeC","file":"formula-integration.test.js","sourcesContent":["/**\n * Test file for formula-aware auto-fill functionality\n * This demonstrates the integration between auto-fill plugin and vtable-sheet formula system\n */\n\nimport { AutoFillPlugin, createFormulaAdapter } from '../src/auto-fill';\nimport type { ListTable } from '@visactor/vtable';\n\n/**\n * Example: Setting up auto-fill with formula support\n */\nexport function setupAutoFillWithFormulas(table: ListTable, formulaManager?: any) {\n // Create auto-fill plugin with formula support\n const autoFillPlugin = new AutoFillPlugin({\n fillMode: 'series' // Enable series fill for formula adjustment\n });\n\n // The plugin will automatically detect and integrate with formula system\n table.registerPlugin(autoFillPlugin);\n\n return autoFillPlugin;\n}\n\n/**\n * Example: Manual formula adapter usage\n */\nexport function demonstrateFormulaAdapter(table: ListTable, formulaManager?: any) {\n // Create formula adapter\n const formulaAdapter = createFormulaAdapter(table, formulaManager);\n\n // Check if cell contains formula\n const hasFormula = formulaAdapter.isFormulaCell(0, 0);\n console.log('Cell A1 has formula:', hasFormula);\n\n // Get formula from cell\n const formula = formulaAdapter.getCellFormula(0, 0);\n console.log('Formula in A1:', formula);\n\n // Set formula in cell\n formulaAdapter.setCellFormula(1, 0, '=A1+1');\n\n // Get calculated value\n const value = formulaAdapter.getCalculatedValue(1, 0);\n console.log('Calculated value:', value);\n}\n\n/**\n * Example: Formula auto-fill scenarios\n */\nexport const formulaAutoFillExamples = {\n /**\n * Simple formula series: =A1, =A2, =A3, ...\n */\n simpleSeries: [\n { cell: 'A1', formula: '=B1' },\n { cell: 'A2', formula: '=B2' }\n ],\n\n /**\n * Complex formula with mixed references: =$A$1+B1, =$A$1+B2, =$A$1+B3, ...\n */\n mixedReferences: [\n { cell: 'C1', formula: '=$A$1+B1' },\n { cell: 'C2', formula: '=$A$1+B2' }\n ],\n\n /**\n * Mathematical series: =A1+1, =A2+2, =A3+3, ...\n */\n mathematicalSeries: [\n { cell: 'D1', formula: '=A1+1' },\n { cell: 'D2', formula: '=A2+2' }\n ],\n\n /**\n * Function-based formulas: =SUM(A1:B1), =SUM(A2:B2), ...\n */\n functionSeries: [\n { cell: 'E1', formula: '=SUM(A1:B1)' },\n { cell: 'E2', formula: '=SUM(A2:B2)' }\n ]\n};\n\n/**\n * Test function to verify formula auto-fill behavior\n */\nexport function testFormulaAutoFill() {\n console.log('Formula Auto-Fill Test Cases:');\n console.log('============================');\n\n // Test case 1: Simple relative reference\n console.log('\\n1. Simple Relative Reference:');\n console.log('Source: A1 contains \"=B1\"');\n console.log('Auto-fill down 3 rows should produce:');\n console.log(' A2: \"=B2\"');\n console.log(' A3: \"=B3\"');\n console.log(' A4: \"=B4\"');\n\n // Test case 2: Absolute reference\n console.log('\\n2. Absolute Reference:');\n console.log('Source: A1 contains \"=$B$1\"');\n console.log('Auto-fill down 3 rows should produce:');\n console.log(' A2: \"=$B$1\"');\n console.log(' A3: \"=$B$1\"');\n console.log(' A4: \"=$B$1\"');\n\n // Test case 3: Mixed reference\n console.log('\\n3. Mixed Reference:');\n console.log('Source: A1 contains \"=$B1\"');\n console.log('Auto-fill down 3 rows should produce:');\n console.log(' A2: \"=$B2\"');\n console.log(' A3: \"=$B3\"');\n console.log(' A4: \"=$B4\"');\n\n // Test case 4: Series pattern detection\n console.log('\\n4. Series Pattern Detection:');\n console.log('Source: A1 contains \"=B1+1\", A2 contains \"=B2+2\"');\n console.log('Auto-fill down 2 rows should produce:');\n console.log(' A3: \"=B3+3\"');\n console.log(' A4: \"=B4+4\"');\n\n // Test case 5: Copy mode\n console.log('\\n5. Copy Mode:');\n console.log('Source: A1 contains \"=B1+C1\"');\n console.log('Copy fill down 3 rows should produce:');\n console.log(' A2: \"=B1+C1\"');\n console.log(' A3: \"=B1+C1\"');\n console.log(' A4: \"=B1+C1\"');\n}\n\n/**\n * Integration test for vtable-sheet\n */\nexport function testVTableSheetIntegration(table: ListTable) {\n // This would be used in actual vtable-sheet environment\n console.log('Testing VTableSheet Formula Integration...');\n\n // Set up some test data\n table.changeCellValue(1, 0, '10'); // B1 = 10\n table.changeCellValue(1, 1, '20'); // B2 = 20\n table.changeCellValue(1, 2, '30'); // B3 = 30\n\n // Set up formula\n const formulaAdapter = createFormulaAdapter(table);\n formulaAdapter.setCellFormula(0, 0, '=B1*2'); // A1 = B1 * 2\n\n console.log('Test data setup complete');\n console.log('Ready for auto-fill testing...');\n}\n"]}
|
|
@@ -11,6 +11,7 @@ export declare class AutoFillManager {
|
|
|
11
11
|
private direction;
|
|
12
12
|
private headers;
|
|
13
13
|
private options?;
|
|
14
|
+
private formulaAdapter;
|
|
14
15
|
constructor(options?: IAutoFillPluginOptions);
|
|
15
16
|
setTable(table: ListTable): void;
|
|
16
17
|
handleStartDrag(selectedRange: CellRange): void;
|
|
@@ -4,17 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.AutoFillManager = void 0;
|
|
6
6
|
|
|
7
|
-
const types_1 = require("./types"),
|
|
7
|
+
const types_1 = require("./types"), vtable_1 = require("@visactor/vtable"), auto_fill_helper_1 = require("./auto-fill-helper"), ts_types_1 = require("@visactor/vtable/es/ts-types"), formula_integration_1 = require("./formula-integration"), auto_fill_services_1 = require("./auto-fill-services"), rules_1 = require("./rules"), fill_1 = require("./utils/fill");
|
|
8
8
|
|
|
9
9
|
class AutoFillManager {
|
|
10
10
|
constructor(options) {
|
|
11
|
-
this.sourceData = [], this.options = options, this.autoFillService = new auto_fill_services_1.AutoFillService
|
|
11
|
+
this.sourceData = [], this.options = options, this.autoFillService = new auto_fill_services_1.AutoFillService,
|
|
12
|
+
this.formulaAdapter = new formula_integration_1.DefaultFormulaAdapter({});
|
|
12
13
|
}
|
|
13
14
|
setTable(table) {
|
|
15
|
+
var _a, _b, _c;
|
|
14
16
|
this.headers = {
|
|
15
17
|
row: new Set,
|
|
16
18
|
col: new Set
|
|
17
|
-
}, this.tableInstance = table, table.
|
|
19
|
+
}, this.tableInstance = table, this.formulaAdapter = (0, formula_integration_1.createFormulaAdapter)(table, null === (_a = this.options) || void 0 === _a ? void 0 : _a.isFormulaCell, null === (_b = this.options) || void 0 === _b ? void 0 : _b.getCellFormula, null === (_c = this.options) || void 0 === _c ? void 0 : _c.setCellFormula),
|
|
20
|
+
table.on(vtable_1.TABLE_EVENT_TYPE.DROPDOWN_MENU_CLICK, (args => {
|
|
18
21
|
"复制填充" === args.text ? this.fillData(types_1.APPLY_TYPE.COPY) : "序列填充" === args.text && this.fillData(types_1.APPLY_TYPE.SERIES);
|
|
19
22
|
}));
|
|
20
23
|
const rowHeaderCells = this.tableInstance.getAllRowHeaderCells()[0];
|
|
@@ -77,8 +80,14 @@ class AutoFillManager {
|
|
|
77
80
|
};
|
|
78
81
|
bArray.forEach((b => {
|
|
79
82
|
let data;
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
const col = isVertical ? a : b, row = isVertical ? b : a;
|
|
84
|
+
if (data = isVertical ? matrix.getValue(b, a) : matrix.getValue(a, b), data && this.formulaAdapter.isFormulaCell(col, row)) {
|
|
85
|
+
const formula = this.formulaAdapter.getCellFormula(col, row);
|
|
86
|
+
formula && (data = Object.assign(Object.assign({}, data), {
|
|
87
|
+
v: formula
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
const ruleMatch = rules.find((r => r.match(data, null))) || rules_1.otherRule, {type: type, isContinue: isContinue} = ruleMatch;
|
|
82
91
|
if (isContinue(prevData, data)) {
|
|
83
92
|
const typeInfo = sourceDataPiece[type], last = typeInfo[typeInfo.length - 1];
|
|
84
93
|
last.data.push(data), last.index.push(b - bArray[0]);
|
|
@@ -162,18 +171,26 @@ class AutoFillManager {
|
|
|
162
171
|
applyDatas.push(row);
|
|
163
172
|
}));
|
|
164
173
|
}
|
|
165
|
-
const values = [];
|
|
174
|
+
const values = [], formulaUpdates = [];
|
|
166
175
|
targetRows.forEach(((row, rowIndex) => {
|
|
167
176
|
const rowValues = [];
|
|
168
177
|
targetCols.forEach(((col, colIndex) => {
|
|
169
|
-
var _a;
|
|
170
178
|
const range = (0, auto_fill_helper_1.isMergeCell)(this.tableInstance, col, row);
|
|
171
|
-
range && this.tableInstance.unmergeCells(range.start.col, range.start.row, range.end.col, range.end.row),
|
|
172
|
-
applyDatas[rowIndex][colIndex]
|
|
179
|
+
if (range && this.tableInstance.unmergeCells(range.start.col, range.start.row, range.end.col, range.end.row),
|
|
180
|
+
applyDatas[rowIndex][colIndex]) {
|
|
181
|
+
const cellData = applyDatas[rowIndex][colIndex], cellValue = (null == cellData ? void 0 : cellData.v) + "";
|
|
182
|
+
cellData && "string" == typeof cellData.v && cellData.v.startsWith("=") ? (formulaUpdates.push({
|
|
183
|
+
col: col,
|
|
184
|
+
row: row,
|
|
185
|
+
formula: cellData.v
|
|
186
|
+
}), rowValues.push(cellValue)) : rowValues.push(cellValue);
|
|
187
|
+
}
|
|
173
188
|
})), values.push(rowValues);
|
|
174
189
|
}));
|
|
175
190
|
const minRow = Math.min(...targetRows), minCol = Math.min(...targetCols);
|
|
176
|
-
this.tableInstance.changeCellValues(minCol, minRow, values)
|
|
191
|
+
this.tableInstance.changeCellValues(minCol, minRow, values), formulaUpdates.length > 0 && (formulaUpdates.forEach((({col: col, row: row, formula: formula}) => {
|
|
192
|
+
this.formulaAdapter.setCellFormula(col, row, formula);
|
|
193
|
+
})), this.formulaAdapter.hasFormulaEngine() && this.formulaAdapter.refreshFormulas());
|
|
177
194
|
}
|
|
178
195
|
getApplyData(sourceDataPiece, csLen, asLen, direction, applyType, location) {
|
|
179
196
|
const applyData = [], num = Math.floor(asLen / csLen), rsd = asLen % csLen, rules = this.autoFillService.getRules(), applyDataInTypes = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/auto-fill/auto-fill-manager.ts"],"names":[],"mappings":";;;AAeA,mCAA+D;AAS/D,6DAAuD;AACvD,mCAAoC;AACpC,uCAA+D;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I,IAAI,CAAC,OAAO,EAAE,CAAC;YAE5B,IAAI,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAG,kBAAU,CAAC,IAAI,CAAC,EAAE;gBAC3C,OAAO,oBAAoB,CAAC,kBAAU,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC;aACpG;YACD,OAAO,IAAA,eAAQ,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC;SAC5B;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AA3bD,0CA2bC","file":"auto-fill-manager.js","sourcesContent":["/**\n * Copyright 2023-present DreamNum Co., Ltd.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Direction, APPLY_TYPE, CellValueType } from './types';\nimport type {\n ISourceDataPiece,\n ICellData,\n Nullable,\n IRuleConfirmedData,\n IDiscreteRange,\n IAutoFillLocation\n} from './types';\nimport { AutoFillService } from './auto-fill-services';\nimport { otherRule } from './rules';\nimport { fillCopy, getDataIndex, getLenS } from './utils/fill';\nimport type { ICopyDataInType } from './utils/fill';\nimport type { APPLY_FUNCTIONS } from './types';\nimport type { CellRange } from '@visactor/vtable/es/ts-types/table-engine';\nimport { TABLE_EVENT_TYPE } from '@visactor/vtable';\nimport type { ListTable } from '@visactor/vtable';\nimport {\n getSelectedRangeArray,\n getTargetRange,\n openAutoFillMenu,\n getCellMatrix,\n isMergeCell\n} from './auto-fill-helper';\nimport type { IAutoFillPluginOptions } from '.';\nimport { InteractionState } from '@visactor/vtable/es/ts-types';\nexport class AutoFillManager {\n // 源数据\n private sourceData: ISourceDataPiece[] = [];\n // autoFillService 维护规则列表\n private autoFillService: AutoFillService;\n // 表格实例\n private tableInstance: ListTable;\n // 源范围\n private sourceRange: IDiscreteRange;\n // 目标范围\n private targetRange: IDiscreteRange;\n // 填充方向\n private direction: Direction;\n // 行列头\n private headers: {\n row: Set<number>;\n col: Set<number>;\n };\n\n private options?: IAutoFillPluginOptions;\n\n constructor(options?: IAutoFillPluginOptions) {\n this.options = options;\n this.autoFillService = new AutoFillService();\n }\n\n setTable(table: ListTable) {\n this.headers = {\n row: new Set(),\n col: new Set()\n };\n this.tableInstance = table;\n table.on(TABLE_EVENT_TYPE.DROPDOWN_MENU_CLICK, (args: any) => {\n if (args.text === '复制填充') {\n this.fillData(APPLY_TYPE.COPY);\n } else if (args.text === '序列填充') {\n this.fillData(APPLY_TYPE.SERIES);\n }\n });\n\n //cal headers\n const rowHeaderCells = this.tableInstance.getAllRowHeaderCells()[0];\n if (rowHeaderCells) {\n rowHeaderCells.forEach(cell => {\n this.headers.col.add(cell.col);\n });\n }\n const colHeaderCells = this.tableInstance.getAllColumnHeaderCells()[0];\n if (colHeaderCells) {\n colHeaderCells.forEach(cell => {\n this.headers.row.add(cell.row);\n });\n }\n }\n\n // 开始拖拽\n handleStartDrag(selectedRange: CellRange) {\n this.sourceRange = getSelectedRangeArray(selectedRange);\n this.sourceRange.cols = this.sourceRange.cols.filter(col => !this.headers.col.has(col));\n this.sourceRange.rows = this.sourceRange.rows.filter(row => !this.headers.row.has(row));\n }\n // 结束拖拽\n handleEndDrag(endSelectCellRange: CellRange, direction: string) {\n // set direction\n this.direction = direction as Direction;\n // set target range\n const selectedRange = getSelectedRangeArray(endSelectCellRange);\n this.targetRange = getTargetRange(this.direction, this.sourceRange, selectedRange);\n this.targetRange.cols = this.targetRange.cols.filter(col => !this.headers.col.has(col));\n this.targetRange.rows = this.targetRange.rows.filter(row => !this.headers.row.has(row));\n // open auto fill menu\n if (!this.options?.fillMode) {\n openAutoFillMenu(this.tableInstance, Math.max(...selectedRange.cols), Math.max(...selectedRange.rows));\n } else {\n this.fillData(this.options.fillMode as APPLY_TYPE);\n }\n }\n\n handleDbClick() {\n if (!this.sourceRange) {\n return;\n }\n this.direction = Direction.DOWN;\n // 双击填充时,自动检测填充范围\n const detectFillRange = getSelectedRangeArray(this._detectFillRange());\n this.targetRange = getTargetRange(this.direction, this.sourceRange, detectFillRange);\n this.targetRange.cols = this.targetRange.cols.filter(col => !this.headers.col.has(col));\n this.targetRange.rows = this.targetRange.rows.filter(row => !this.headers.row.has(row));\n if (this.targetRange.cols.length === 0 || this.targetRange.rows.length === 0) {\n return;\n }\n const startCol = this.sourceRange.cols[0];\n const startRow = this.sourceRange.rows[0];\n const endCol = this.targetRange.cols[this.targetRange.cols.length - 1];\n const endRow = this.targetRange.rows[this.targetRange.rows.length - 1];\n // 更新选区\n const stateManager = this.tableInstance.stateManager;\n stateManager.updateSelectPos(startCol, startRow, false, false, false, true, true);\n stateManager.updateInteractionState(InteractionState.grabing);\n stateManager.updateSelectPos(endCol, endRow, false, false, false, true, true);\n stateManager.endSelectCells(false, false);\n stateManager.updateInteractionState(InteractionState.default);\n // 快速填充\n if (!this.options?.fastFillMode) {\n // 打开自动填充菜单\n openAutoFillMenu(this.tableInstance, endCol, endRow);\n } else {\n this.fillData(this.options.fastFillMode as APPLY_TYPE);\n }\n }\n\n /**\n * 填充数据\n * @param applyType - 填充类型\n */\n fillData(applyType: APPLY_TYPE) {\n console.log('fill data applyType', applyType);\n // 获取源数据\n this.sourceData = this.getSourceData(this.sourceRange, this.direction);\n const location = {\n source: this.sourceRange,\n target: this.targetRange\n };\n\n // 填充数据\n this._fillData(location, this.direction, applyType);\n }\n /**\n * 获取源数据\n * @param source - 源范围\n * @param direction - 方向\n * @returns 源数据\n */\n private getSourceData(source: IDiscreteRange, direction: Direction) {\n const rules = this.autoFillService.getRules();\n const sourceData: ISourceDataPiece[] = [];\n const isVertical = direction === Direction.DOWN || direction === Direction.UP;\n let aArray: number[];\n let bArray: number[];\n if (isVertical) {\n aArray = source.cols;\n bArray = source.rows;\n } else {\n aArray = source.rows;\n bArray = source.cols;\n }\n const matrix = getCellMatrix(this.tableInstance);\n // 按照行或列将源数据分成多个片段,获取单元格数据\n aArray.forEach(a => {\n const sourceDataPiece = this.getEmptySourceDataPiece();\n const prevData: IRuleConfirmedData = {\n type: undefined,\n cellData: undefined\n };\n bArray.forEach(b => {\n let data: Nullable<ICellData>;\n if (isVertical) {\n data = matrix.getValue(b, a);\n } else {\n data = matrix.getValue(a, b);\n }\n // find rules to match data\n const { type, isContinue } = rules.find(r => r.match(data, null)) || otherRule;\n if (isContinue(prevData, data)) {\n const typeInfo = sourceDataPiece[type];\n\n const last = typeInfo![typeInfo!.length - 1];\n last.data.push(data);\n last.index.push(b - bArray[0]);\n } else {\n const typeInfo = sourceDataPiece[type];\n if (typeInfo) {\n typeInfo.push({\n data: [data],\n index: [b - bArray[0]]\n });\n } else {\n sourceDataPiece[type] = [\n {\n data: [data],\n index: [b - bArray[0]]\n }\n ];\n }\n }\n prevData.type = type;\n prevData.cellData = data;\n });\n sourceData.push(sourceDataPiece);\n });\n return sourceData;\n }\n /**\n * 获取空的片段数据对象\n * @returns 空的片段数据对象\n */\n private getEmptySourceDataPiece() {\n const sourceDataPiece: ISourceDataPiece = {};\n this.autoFillService.getRules().forEach(r => {\n sourceDataPiece[r.type] = [];\n });\n\n return sourceDataPiece;\n }\n /**\n * 快速填充检测填充范围\n * @returns 填充范围\n */\n private _detectFillRange() {\n // sourceRange\n const start = { row: Math.min(...this.sourceRange.rows), col: Math.min(...this.sourceRange.cols) };\n const end = { row: Math.max(...this.sourceRange.rows), col: Math.max(...this.sourceRange.cols) };\n // matrix\n const matrix = getCellMatrix(this.tableInstance);\n const maxRow = matrix.getMaxRows();\n const maxColumn = matrix.getMaxColumns();\n let detectEndRow = end.row;\n // left column first, or consider right column.\n if (start.col > 0 && matrix.getValue(start.row, start.col - 1)?.v) {\n let cur = start.row;\n while (matrix.getValue(cur, start.col - 1)?.v && cur <= maxRow) {\n cur += 1;\n }\n detectEndRow = cur - 1;\n } else if (end.col < maxColumn && matrix.getValue(end.row, end.col + 1)?.v) {\n let cur = start.row;\n while (matrix.getValue(cur, end.col + 1)?.v && cur <= maxRow) {\n cur += 1;\n }\n detectEndRow = cur - 1;\n }\n for (let i = end.row + 1; i <= detectEndRow; i++) {\n for (let j = start.col; j <= end.col; j++) {\n if (matrix.getValue(i, j)?.v) {\n detectEndRow = i - 1;\n break;\n }\n }\n }\n return {\n start: { row: start.row, col: start.col },\n end: { row: detectEndRow, col: end.col }\n };\n }\n\n /**\n * 填充数据\n * @param location - 位置\n * @param direction - 方向\n * @param applyType - 填充类型\n */\n private _fillData(location: IAutoFillLocation, direction: Direction, applyType: APPLY_TYPE) {\n const { source, target } = location;\n if (!source || !target || direction == null) {\n return;\n }\n\n const { cols: targetCols, rows: targetRows } = target;\n const { cols: sourceCols, rows: sourceRows } = source;\n\n const sourceData = this.sourceData;\n\n let csLen: number;\n if (direction === Direction.DOWN || direction === Direction.UP) {\n csLen = sourceRows.length;\n } else {\n csLen = sourceCols.length;\n }\n\n const applyDatas: Array<Array<Nullable<ICellData>>> = [];\n\n if (direction === Direction.DOWN || direction === Direction.UP) {\n const asLen = targetRows.length;\n const untransformedApplyDatas: Nullable<ICellData>[][] = [];\n targetCols.forEach((_, i) => {\n const copyD = sourceData[i];\n const applyData = this.getApplyData(copyD, csLen, asLen, direction, applyType, location);\n untransformedApplyDatas.push(applyData);\n });\n for (let i = 0; i < untransformedApplyDatas[0].length; i++) {\n const row: Array<Nullable<ICellData>> = [];\n for (let j = 0; j < untransformedApplyDatas.length; j++) {\n row.push(untransformedApplyDatas[j][i]);\n }\n applyDatas.push(row);\n }\n } else {\n const asLen = targetCols.length;\n targetRows.forEach((_, i) => {\n const copyD = sourceData[i];\n const applyData = this.getApplyData(copyD, csLen, asLen, direction, applyType, location);\n const row: Array<Nullable<ICellData>> = [];\n for (let j = 0; j < applyData.length; j++) {\n row.push(applyData[j]);\n }\n applyDatas.push(row);\n });\n }\n\n // 获取填充的值\n const values: string[][] = [];\n targetRows.forEach((row, rowIndex) => {\n const rowValues: string[] = [];\n targetCols.forEach((col, colIndex) => {\n // 如果当前单元格是合并单元格,则先进行拆开单元格,再进行填充\n const range = isMergeCell(this.tableInstance, col, row);\n if (range) {\n this.tableInstance.unmergeCells(range.start.col, range.start.row, range.end.col, range.end.row);\n }\n // 填充数据存入rowValues,再一次性填充到表格中\n if (applyDatas[rowIndex][colIndex]) {\n rowValues.push((applyDatas[rowIndex][colIndex] as any)?.v + '');\n }\n });\n values.push(rowValues);\n });\n // 获取填充开始的行和列,设置表格值\n const minRow = Math.min(...targetRows);\n const minCol = Math.min(...targetCols);\n this.tableInstance.changeCellValues(minCol, minRow, values);\n }\n\n /**\n * 根据源数据计算填充数据\n * @param sourceDataPiece - 源数据片段\n * @param csLen - 源长度\n * @param asLen - 目标长度\n * @param direction - 方向\n * @param applyType - 填充类型\n * @param location - 位置\n * @returns 填充数据\n */\n private getApplyData(\n sourceDataPiece: ISourceDataPiece,\n csLen: number,\n asLen: number,\n direction: Direction,\n applyType: APPLY_TYPE,\n location: IAutoFillLocation\n ) {\n const applyData: Array<Nullable<ICellData>> = [];\n const num = Math.floor(asLen / csLen);\n const rsd = asLen % csLen;\n const rules = this.autoFillService.getRules();\n\n const applyDataInTypes: { [key: string]: any[] } = {};\n\n rules.forEach(r => {\n applyDataInTypes[r.type] = [];\n });\n\n // calc cell data to apply\n rules.forEach(r => {\n const { type, applyFunctions: customApplyFunctions = {} } = r;\n const copyDataInType = sourceDataPiece[type];\n if (!copyDataInType) {\n return;\n }\n // copyDataInType is an array of copy-squads in same types\n // a copy-squad is an array of continuous cells that has the same type, e.g. [1, 3, 5] is a copy squad, but [1, 3, ab, 5] will be divided into two copy-squads\n copyDataInType.forEach(copySquad => {\n const s = getLenS(copySquad.index, rsd);\n const len = copySquad.index.length * num + s;\n\n // We do not process cell.custom by default. If the user needs to process it, they can do so in the hook extension.\n const arrData = this.applyFunctions(\n copySquad,\n len,\n direction,\n applyType,\n customApplyFunctions,\n sourceDataPiece,\n location\n );\n\n const arrIndex = getDataIndex(csLen, asLen, copySquad.index);\n applyDataInTypes[type].push({ data: arrData, index: arrIndex });\n });\n });\n\n // calc index\n for (let x = 0; x < asLen; x++) {\n rules.forEach(r => {\n const { type } = r;\n const applyDataInType = applyDataInTypes[type];\n for (let y = 0; y < applyDataInType.length; y++) {\n if (x in applyDataInType[y].index) {\n applyData.push(applyDataInType[y].data[applyDataInType[y].index[x]]);\n }\n }\n });\n }\n\n return applyData;\n }\n /**\n * 根据规则计算填充函数\n * @param copySquad - 复制数据\n * @param len - 长度\n * @param direction - 方向\n * @param applyType - 填充类型\n * @param customApplyFunctions - 自定义应用函数\n * @param sourceDataPiece - 源数据片段\n * @param location - 位置\n * @returns 填充数据\n */\n private applyFunctions(\n copySquad: ICopyDataInType,\n len: number,\n direction: Direction,\n applyType: APPLY_TYPE,\n customApplyFunctions: APPLY_FUNCTIONS,\n sourceDataPiece: ISourceDataPiece,\n location: IAutoFillLocation\n ) {\n const { data } = copySquad;\n const isReverse = direction === Direction.UP || direction === Direction.LEFT;\n\n // 复制填充\n if (applyType === APPLY_TYPE.COPY) {\n const custom = customApplyFunctions?.[APPLY_TYPE.COPY];\n if (custom) {\n return custom(copySquad, len, direction, sourceDataPiece, location);\n }\n isReverse && data.reverse();\n return fillCopy(data, len);\n }\n // 序列填充\n if (applyType === APPLY_TYPE.SERIES) {\n const custom = customApplyFunctions?.[APPLY_TYPE.SERIES];\n if (custom) {\n return custom(copySquad, len, direction, sourceDataPiece);\n }\n isReverse && data.reverse();\n // special rules, if not provide custom SERIES apply functions, will be applied as copy\n if (customApplyFunctions?.[APPLY_TYPE.COPY]) {\n return customApplyFunctions[APPLY_TYPE.COPY](copySquad, len, direction, sourceDataPiece, location);\n }\n return fillCopy(data, len);\n }\n // Default case: return empty array\n return [];\n }\n}\n"]}
|
|
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,IAAI,MAAM,EAAE;gBACV,OAAO,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC;aACrE;YACD,SAAS,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC5B,OAAO,IAAA,eAAQ,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC;SAC5B;QAED,IAAI,SAAS,KAAK,kBAAU,CAAC,MAAM,EAAE;YACnC,MAAM,MAAM,GAAG,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAG,kBAAU,CAAC,MAAM,CAAC,CAAC;YACzD,IAAI,MAAM,EAAE;gBACV,OAAO,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC;aAC3D;YACD,SAAS,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAE5B,IAAI,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAG,kBAAU,CAAC,IAAI,CAAC,EAAE;gBAC3C,OAAO,oBAAoB,CAAC,kBAAU,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC;aACpG;YACD,OAAO,IAAA,eAAQ,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC;SAC5B;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AApfD,0CAofC","file":"auto-fill-manager.js","sourcesContent":["/**\n * Copyright 2023-present DreamNum Co., Ltd.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Direction, APPLY_TYPE } from './types';\nimport type {\n ISourceDataPiece,\n ICellData,\n Nullable,\n IRuleConfirmedData,\n IDiscreteRange,\n IAutoFillLocation,\n APPLY_FUNCTIONS\n} from './types';\nimport type { CellRange } from '@visactor/vtable/es/ts-types/table-engine';\nimport { TABLE_EVENT_TYPE } from '@visactor/vtable';\nimport type { ListTable } from '@visactor/vtable';\nimport {\n getSelectedRangeArray,\n getTargetRange,\n openAutoFillMenu,\n getCellMatrix,\n isMergeCell\n} from './auto-fill-helper';\nimport type { IAutoFillPluginOptions } from '.';\nimport { InteractionState } from '@visactor/vtable/es/ts-types';\nimport { createFormulaAdapter, type IFormulaAwareTable, DefaultFormulaAdapter } from './formula-integration';\nimport { AutoFillService } from './auto-fill-services';\nimport { otherRule } from './rules';\nimport { fillCopy, getDataIndex, getLenS } from './utils/fill';\nimport type { ICopyDataInType } from './utils/fill';\nexport class AutoFillManager {\n // 源数据\n private sourceData: ISourceDataPiece[] = [];\n // autoFillService 维护规则列表\n private autoFillService: AutoFillService;\n // 表格实例\n private tableInstance: ListTable;\n // 源范围\n private sourceRange: IDiscreteRange;\n // 目标范围\n private targetRange: IDiscreteRange;\n // 填充方向\n private direction: Direction;\n // 行列头\n private headers: {\n row: Set<number>;\n col: Set<number>;\n };\n\n private options?: IAutoFillPluginOptions;\n private formulaAdapter: IFormulaAwareTable;\n\n constructor(options?: IAutoFillPluginOptions) {\n this.options = options;\n this.autoFillService = new AutoFillService();\n this.formulaAdapter = new DefaultFormulaAdapter({} as ListTable); // Will be updated in setTable\n }\n\n setTable(table: ListTable) {\n this.headers = {\n row: new Set(),\n col: new Set()\n };\n this.tableInstance = table;\n // Create formula adapter based on table capabilities and custom functions\n this.formulaAdapter = createFormulaAdapter(\n table,\n this.options?.isFormulaCell,\n this.options?.getCellFormula,\n this.options?.setCellFormula\n );\n\n table.on(TABLE_EVENT_TYPE.DROPDOWN_MENU_CLICK, (args: any) => {\n if (args.text === '复制填充') {\n this.fillData(APPLY_TYPE.COPY);\n } else if (args.text === '序列填充') {\n this.fillData(APPLY_TYPE.SERIES);\n }\n });\n\n //cal headers\n const rowHeaderCells = this.tableInstance.getAllRowHeaderCells()[0];\n if (rowHeaderCells) {\n rowHeaderCells.forEach(cell => {\n this.headers.col.add(cell.col);\n });\n }\n const colHeaderCells = this.tableInstance.getAllColumnHeaderCells()[0];\n if (colHeaderCells) {\n colHeaderCells.forEach(cell => {\n this.headers.row.add(cell.row);\n });\n }\n }\n\n // 开始拖拽\n handleStartDrag(selectedRange: CellRange) {\n this.sourceRange = getSelectedRangeArray(selectedRange);\n this.sourceRange.cols = this.sourceRange.cols.filter(col => !this.headers.col.has(col));\n this.sourceRange.rows = this.sourceRange.rows.filter(row => !this.headers.row.has(row));\n }\n // 结束拖拽\n handleEndDrag(endSelectCellRange: CellRange, direction: string) {\n // set direction\n this.direction = direction as Direction;\n // set target range\n const selectedRange = getSelectedRangeArray(endSelectCellRange);\n this.targetRange = getTargetRange(this.direction, this.sourceRange, selectedRange);\n this.targetRange.cols = this.targetRange.cols.filter(col => !this.headers.col.has(col));\n this.targetRange.rows = this.targetRange.rows.filter(row => !this.headers.row.has(row));\n // open auto fill menu\n if (!this.options?.fillMode) {\n openAutoFillMenu(this.tableInstance, Math.max(...selectedRange.cols), Math.max(...selectedRange.rows));\n } else {\n this.fillData(this.options.fillMode as APPLY_TYPE);\n }\n }\n\n handleDbClick() {\n if (!this.sourceRange) {\n return;\n }\n this.direction = Direction.DOWN;\n // 双击填充时,自动检测填充范围\n const detectFillRange = getSelectedRangeArray(this._detectFillRange());\n this.targetRange = getTargetRange(this.direction, this.sourceRange, detectFillRange);\n this.targetRange.cols = this.targetRange.cols.filter(col => !this.headers.col.has(col));\n this.targetRange.rows = this.targetRange.rows.filter(row => !this.headers.row.has(row));\n if (this.targetRange.cols.length === 0 || this.targetRange.rows.length === 0) {\n return;\n }\n const startCol = this.sourceRange.cols[0];\n const startRow = this.sourceRange.rows[0];\n const endCol = this.targetRange.cols[this.targetRange.cols.length - 1];\n const endRow = this.targetRange.rows[this.targetRange.rows.length - 1];\n // 更新选区\n const stateManager = this.tableInstance.stateManager;\n stateManager.updateSelectPos(startCol, startRow, false, false, false, true, true);\n stateManager.updateInteractionState(InteractionState.grabing);\n stateManager.updateSelectPos(endCol, endRow, false, false, false, true, true);\n stateManager.endSelectCells(false, false);\n stateManager.updateInteractionState(InteractionState.default);\n // 快速填充\n if (!this.options?.fastFillMode) {\n // 打开自动填充菜单\n openAutoFillMenu(this.tableInstance, endCol, endRow);\n } else {\n this.fillData(this.options.fastFillMode as APPLY_TYPE);\n }\n }\n\n /**\n * 填充数据\n * @param applyType - 填充类型\n */\n fillData(applyType: APPLY_TYPE) {\n console.log('fill data applyType', applyType);\n // 获取源数据\n this.sourceData = this.getSourceData(this.sourceRange, this.direction);\n const location = {\n source: this.sourceRange,\n target: this.targetRange\n };\n\n // 填充数据\n this._fillData(location, this.direction, applyType);\n }\n /**\n * 获取源数据\n * @param source - 源范围\n * @param direction - 方向\n * @returns 源数据\n */\n private getSourceData(source: IDiscreteRange, direction: Direction) {\n const rules = this.autoFillService.getRules();\n const sourceData: ISourceDataPiece[] = [];\n const isVertical = direction === Direction.DOWN || direction === Direction.UP;\n let aArray: number[];\n let bArray: number[];\n if (isVertical) {\n aArray = source.cols;\n bArray = source.rows;\n } else {\n aArray = source.rows;\n bArray = source.cols;\n }\n const matrix = getCellMatrix(this.tableInstance);\n // 按照行或列将源数据分成多个片段,获取单元格数据\n aArray.forEach(a => {\n const sourceDataPiece = this.getEmptySourceDataPiece();\n const prevData: IRuleConfirmedData = {\n type: undefined,\n cellData: undefined\n };\n bArray.forEach(b => {\n let data: Nullable<ICellData>;\n const col = isVertical ? a : b;\n const row = isVertical ? b : a;\n\n if (isVertical) {\n data = matrix.getValue(b, a);\n } else {\n data = matrix.getValue(a, b);\n }\n\n // Enhance cell data with formula information if available\n if (data && this.formulaAdapter.isFormulaCell(col, row)) {\n const formula = this.formulaAdapter.getCellFormula(col, row);\n if (formula) {\n data = {\n ...data,\n v: formula // Use formula string as value for auto-fill processing\n };\n }\n }\n\n // find rules to match data\n const ruleMatch = rules.find((r: any) => r.match(data, null)) || otherRule;\n const { type, isContinue } = ruleMatch;\n if (isContinue(prevData, data)) {\n const typeInfo = sourceDataPiece[type];\n\n const last = typeInfo![typeInfo!.length - 1];\n last.data.push(data);\n last.index.push(b - bArray[0]);\n } else {\n const typeInfo = sourceDataPiece[type];\n if (typeInfo) {\n typeInfo.push({\n data: [data],\n index: [b - bArray[0]]\n });\n } else {\n sourceDataPiece[type] = [\n {\n data: [data],\n index: [b - bArray[0]]\n }\n ];\n }\n }\n prevData.type = type;\n prevData.cellData = data;\n });\n sourceData.push(sourceDataPiece);\n });\n return sourceData;\n }\n /**\n * 获取空的片段数据对象\n * @returns 空的片段数据对象\n */\n private getEmptySourceDataPiece() {\n const sourceDataPiece: ISourceDataPiece = {};\n this.autoFillService.getRules().forEach(r => {\n sourceDataPiece[r.type] = [];\n });\n\n return sourceDataPiece;\n }\n /**\n * 快速填充检测填充范围\n * @returns 填充范围\n */\n private _detectFillRange() {\n // sourceRange\n const start = { row: Math.min(...this.sourceRange.rows), col: Math.min(...this.sourceRange.cols) };\n const end = { row: Math.max(...this.sourceRange.rows), col: Math.max(...this.sourceRange.cols) };\n // matrix\n const matrix = getCellMatrix(this.tableInstance);\n const maxRow = matrix.getMaxRows();\n const maxColumn = matrix.getMaxColumns();\n let detectEndRow = end.row;\n // left column first, or consider right column.\n if (start.col > 0 && matrix.getValue(start.row, start.col - 1)?.v) {\n let cur = start.row;\n while (matrix.getValue(cur, start.col - 1)?.v && cur <= maxRow) {\n cur += 1;\n }\n detectEndRow = cur - 1;\n } else if (end.col < maxColumn && matrix.getValue(end.row, end.col + 1)?.v) {\n let cur = start.row;\n while (matrix.getValue(cur, end.col + 1)?.v && cur <= maxRow) {\n cur += 1;\n }\n detectEndRow = cur - 1;\n }\n for (let i = end.row + 1; i <= detectEndRow; i++) {\n for (let j = start.col; j <= end.col; j++) {\n if (matrix.getValue(i, j)?.v) {\n detectEndRow = i - 1;\n break;\n }\n }\n }\n return {\n start: { row: start.row, col: start.col },\n end: { row: detectEndRow, col: end.col }\n };\n }\n\n /**\n * 填充数据\n * @param location - 位置\n * @param direction - 方向\n * @param applyType - 填充类型\n */\n private _fillData(location: IAutoFillLocation, direction: Direction, applyType: APPLY_TYPE) {\n const { source, target } = location;\n if (!source || !target || direction == null) {\n return;\n }\n\n const { cols: targetCols, rows: targetRows } = target;\n const { cols: sourceCols, rows: sourceRows } = source;\n\n const sourceData = this.sourceData;\n\n let csLen: number;\n if (direction === Direction.DOWN || direction === Direction.UP) {\n csLen = sourceRows.length;\n } else {\n csLen = sourceCols.length;\n }\n\n const applyDatas: Array<Array<Nullable<ICellData>>> = [];\n\n if (direction === Direction.DOWN || direction === Direction.UP) {\n const asLen = targetRows.length;\n const untransformedApplyDatas: Nullable<ICellData>[][] = [];\n targetCols.forEach((_, i) => {\n const copyD = sourceData[i];\n const applyData = this.getApplyData(copyD, csLen, asLen, direction, applyType, location);\n untransformedApplyDatas.push(applyData);\n });\n for (let i = 0; i < untransformedApplyDatas[0].length; i++) {\n const row: Array<Nullable<ICellData>> = [];\n for (let j = 0; j < untransformedApplyDatas.length; j++) {\n row.push(untransformedApplyDatas[j][i]);\n }\n applyDatas.push(row);\n }\n } else {\n const asLen = targetCols.length;\n targetRows.forEach((_, i) => {\n const copyD = sourceData[i];\n const applyData = this.getApplyData(copyD, csLen, asLen, direction, applyType, location);\n const row: Array<Nullable<ICellData>> = [];\n for (let j = 0; j < applyData.length; j++) {\n row.push(applyData[j]);\n }\n applyDatas.push(row);\n });\n }\n\n // 获取填充的值\n const values: string[][] = [];\n const formulaUpdates: Array<{ col: number; row: number; formula: string }> = [];\n\n targetRows.forEach((row, rowIndex) => {\n const rowValues: string[] = [];\n targetCols.forEach((col, colIndex) => {\n // 如果当前单元格是合并单元格,则先进行拆开单元格,再进行填充\n const range = isMergeCell(this.tableInstance, col, row);\n if (range) {\n this.tableInstance.unmergeCells(range.start.col, range.start.row, range.end.col, range.end.row);\n }\n // 填充数据存入rowValues,再一次性填充到表格中\n if (applyDatas[rowIndex][colIndex]) {\n const cellData = applyDatas[rowIndex][colIndex];\n const cellValue = (cellData as any)?.v + '';\n\n // Check if this is a formula that needs special handling\n if (cellData && typeof cellData.v === 'string' && cellData.v.startsWith('=')) {\n // Store formula for separate processing\n formulaUpdates.push({\n col,\n row,\n formula: cellData.v\n });\n rowValues.push(cellValue);\n } else {\n rowValues.push(cellValue);\n }\n }\n });\n values.push(rowValues);\n });\n\n // 获取填充开始的行和列,设置表格值\n const minRow = Math.min(...targetRows);\n const minCol = Math.min(...targetCols);\n\n // Set regular values first\n this.tableInstance.changeCellValues(minCol, minRow, values);\n\n // Then set formulas using the formula adapter for proper integration\n if (formulaUpdates.length > 0) {\n formulaUpdates.forEach(({ col, row, formula }) => {\n this.formulaAdapter.setCellFormula(col, row, formula);\n });\n\n // Refresh formula calculations if we have a formula engine\n if (this.formulaAdapter.hasFormulaEngine()) {\n this.formulaAdapter.refreshFormulas();\n }\n }\n }\n\n /**\n * 根据源数据计算填充数据\n * @param sourceDataPiece - 源数据片段\n * @param csLen - 源长度\n * @param asLen - 目标长度\n * @param direction - 方向\n * @param applyType - 填充类型\n * @param location - 位置\n * @returns 填充数据\n */\n private getApplyData(\n sourceDataPiece: ISourceDataPiece,\n csLen: number,\n asLen: number,\n direction: Direction,\n applyType: APPLY_TYPE,\n location: IAutoFillLocation\n ) {\n const applyData: Array<Nullable<ICellData>> = [];\n const num = Math.floor(asLen / csLen);\n const rsd = asLen % csLen;\n const rules = this.autoFillService.getRules();\n\n const applyDataInTypes: { [key: string]: any[] } = {};\n\n rules.forEach((r: any) => {\n applyDataInTypes[r.type] = [];\n });\n\n // calc cell data to apply\n rules.forEach((r: any) => {\n const { type, applyFunctions: customApplyFunctions = {} } = r;\n const copyDataInType = sourceDataPiece[type];\n if (!copyDataInType) {\n return;\n }\n // copyDataInType is an array of copy-squads in same types\n // a copy-squad is an array of continuous cells that has the same type, e.g. [1, 3, 5] is a copy squad, but [1, 3, ab, 5] will be divided into two copy-squads\n copyDataInType.forEach(copySquad => {\n const s = getLenS(copySquad.index, rsd);\n const len = copySquad.index.length * num + s;\n\n // We do not process cell.custom by default. If the user needs to process it, they can do so in the hook extension.\n const arrData = this.applyFunctions(\n copySquad,\n len,\n direction,\n applyType,\n customApplyFunctions,\n sourceDataPiece,\n location\n );\n\n const arrIndex = getDataIndex(csLen, asLen, copySquad.index);\n applyDataInTypes[type].push({ data: arrData, index: arrIndex });\n });\n });\n\n // calc index\n for (let x = 0; x < asLen; x++) {\n rules.forEach((r: any) => {\n const { type } = r;\n const applyDataInType = applyDataInTypes[type];\n for (let y = 0; y < applyDataInType.length; y++) {\n if (x in applyDataInType[y].index) {\n applyData.push(applyDataInType[y].data[applyDataInType[y].index[x]]);\n }\n }\n });\n }\n\n return applyData;\n }\n /**\n * 根据规则计算填充函数\n * @param copySquad - 复制数据\n * @param len - 长度\n * @param direction - 方向\n * @param applyType - 填充类型\n * @param customApplyFunctions - 自定义应用函数\n * @param sourceDataPiece - 源数据片段\n * @param location - 位置\n * @returns 填充数据\n */\n private applyFunctions(\n copySquad: ICopyDataInType,\n len: number,\n direction: Direction,\n applyType: APPLY_TYPE,\n customApplyFunctions: APPLY_FUNCTIONS,\n sourceDataPiece: ISourceDataPiece,\n location: IAutoFillLocation\n ) {\n const { data } = copySquad;\n const isReverse = direction === Direction.UP || direction === Direction.LEFT;\n\n // 复制填充\n if (applyType === APPLY_TYPE.COPY) {\n const custom = customApplyFunctions?.[APPLY_TYPE.COPY];\n if (custom) {\n return custom(copySquad, len, direction, sourceDataPiece, location);\n }\n isReverse && data.reverse();\n return fillCopy(data, len);\n }\n // 序列填充\n if (applyType === APPLY_TYPE.SERIES) {\n const custom = customApplyFunctions?.[APPLY_TYPE.SERIES];\n if (custom) {\n return custom(copySquad, len, direction, sourceDataPiece);\n }\n isReverse && data.reverse();\n // special rules, if not provide custom SERIES apply functions, will be applied as copy\n if (customApplyFunctions?.[APPLY_TYPE.COPY]) {\n return customApplyFunctions[APPLY_TYPE.COPY](copySquad, len, direction, sourceDataPiece, location);\n }\n return fillCopy(data, len);\n }\n // Default case: return empty array\n return [];\n }\n}\n"]}
|
|
@@ -11,7 +11,7 @@ class AutoFillService {
|
|
|
11
11
|
this._rules = [], this._init();
|
|
12
12
|
}
|
|
13
13
|
_init() {
|
|
14
|
-
this._rules = [ rules_1.dateRule, rules_1.numberRule, rules_1.extendNumberRule, rules_1.chnNumberRule, rules_1.chnWeek2Rule, rules_1.chnWeek3Rule, rules_1.loopSeriesRule, rules_1.otherRule ].sort(((a, b) => b.priority - a.priority));
|
|
14
|
+
this._rules = [ rules_1.formulaRule, rules_1.dateRule, rules_1.numberRule, rules_1.extendNumberRule, rules_1.chnNumberRule, rules_1.chnWeek2Rule, rules_1.chnWeek3Rule, rules_1.loopSeriesRule, rules_1.otherRule ].sort(((a, b) => b.priority - a.priority));
|
|
15
15
|
}
|
|
16
16
|
registerRule(rule) {
|
|
17
17
|
if (this._rules.find((r => r.type === rule.type))) throw new Error(`Registry rule failed, type '${rule.type}' already exist!`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/auto-fill/auto-fill-services.ts"],"names":[],"mappings":";;;AAgBA,
|
|
1
|
+
{"version":3,"sources":["../src/auto-fill/auto-fill-services.ts"],"names":[],"mappings":";;;AAgBA,mCAUiB;AAOjB,MAAa,eAAe;IAG1B;QAFQ,WAAM,GAAoB,EAAE,CAAC;QAGnC,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAEO,KAAK;QACX,IAAI,CAAC,MAAM,GAAG;YACZ,mBAAW;YACX,gBAAQ;YACR,kBAAU;YACV,wBAAgB;YAChB,qBAAa;YACb,oBAAY;YACZ,oBAAY;YACZ,sBAAc;YACd,iBAAS;SACV,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAED,YAAY,CAAC,IAAmB;QAE9B,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,EAAE;YAC/C,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,CAAC,IAAI,kBAAkB,CAAC,CAAC;SAC7E;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QACrE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IACzE,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAlCD,0CAkCC","file":"auto-fill-services.js","sourcesContent":["/**\n * Copyright 2023-present DreamNum Co., Ltd.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type { IAutoFillRule } from './types';\nimport {\n dateRule,\n numberRule,\n extendNumberRule,\n chnNumberRule,\n chnWeek2Rule,\n chnWeek3Rule,\n loopSeriesRule,\n formulaRule,\n otherRule\n} from './rules';\n\nexport interface IAutoFillService {\n getRules: () => IAutoFillRule[];\n registerRule: (rule: IAutoFillRule) => void;\n}\n\nexport class AutoFillService implements IAutoFillService {\n private _rules: IAutoFillRule[] = [];\n\n constructor() {\n this._init();\n }\n\n private _init() {\n this._rules = [\n formulaRule,\n dateRule,\n numberRule,\n extendNumberRule,\n chnNumberRule,\n chnWeek2Rule,\n chnWeek3Rule,\n loopSeriesRule,\n otherRule\n ].sort((a, b) => b.priority - a.priority);\n }\n\n registerRule(rule: IAutoFillRule) {\n // if rule.type is used, console error\n if (this._rules.find(r => r.type === rule.type)) {\n throw new Error(`Registry rule failed, type '${rule.type}' already exist!`);\n }\n // insert rules according to the rule.priority, the higher priority will be inserted at the beginning of the array\n const index = this._rules.findIndex(r => r.priority < rule.priority);\n this._rules.splice(index === -1 ? this._rules.length : index, 0, rule);\n }\n\n getRules() {\n return this._rules;\n }\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ListTable } from '@visactor/vtable';
|
|
2
|
+
import type { ICellData } from './types';
|
|
3
|
+
export interface IFormulaAwareTable {
|
|
4
|
+
isFormulaCell: (col: number, row: number) => boolean;
|
|
5
|
+
getCellFormula: (col: number, row: number) => string | undefined;
|
|
6
|
+
setCellFormula: (col: number, row: number, formula: string) => void;
|
|
7
|
+
getCalculatedValue: (col: number, row: number) => any;
|
|
8
|
+
refreshFormulas: () => void;
|
|
9
|
+
hasFormulaEngine: () => boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class DefaultFormulaAdapter implements IFormulaAwareTable {
|
|
12
|
+
private table;
|
|
13
|
+
constructor(table: ListTable);
|
|
14
|
+
isFormulaCell(col: number, row: number): boolean;
|
|
15
|
+
getCellFormula(col: number, row: number): string | undefined;
|
|
16
|
+
setCellFormula(col: number, row: number, formula: string): void;
|
|
17
|
+
getCalculatedValue(col: number, row: number): any;
|
|
18
|
+
refreshFormulas(): void;
|
|
19
|
+
hasFormulaEngine(): boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function createFormulaAdapter(table: ListTable, customIsFormulaCell?: (col: number, row: number, cellData: any, table: ListTable) => boolean, customGetCellFormula?: (col: number, row: number, cellData: any, table: ListTable) => string | undefined, customSetCellFormula?: (col: number, row: number, formula: string, table: ListTable) => void): IFormulaAwareTable;
|
|
22
|
+
export declare class CustomFormulaAdapter implements IFormulaAwareTable {
|
|
23
|
+
private table;
|
|
24
|
+
private isFormulaCellFn?;
|
|
25
|
+
private getCellFormulaFn?;
|
|
26
|
+
private setCellFormulaFn?;
|
|
27
|
+
constructor(table: ListTable, isFormulaCellFn?: (col: number, row: number, cellData: any, table: ListTable) => boolean, getCellFormulaFn?: (col: number, row: number, cellData: any, table: ListTable) => string | undefined, setCellFormulaFn?: (col: number, row: number, formula: string, table: ListTable) => void);
|
|
28
|
+
isFormulaCell(col: number, row: number): boolean;
|
|
29
|
+
getCellFormula(col: number, row: number): string | undefined;
|
|
30
|
+
setCellFormula(col: number, row: number, formula: string): void;
|
|
31
|
+
getCalculatedValue(col: number, row: number): any;
|
|
32
|
+
refreshFormulas(): void;
|
|
33
|
+
hasFormulaEngine(): boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface IFormulaCellData extends ICellData {
|
|
36
|
+
formula?: string;
|
|
37
|
+
isFormula?: boolean;
|
|
38
|
+
calculatedValue?: any;
|
|
39
|
+
}
|
|
40
|
+
export declare function enhanceCellDataWithFormula(cellData: ICellData, col: number, row: number, formulaAdapter: IFormulaAwareTable): IFormulaCellData;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.enhanceCellDataWithFormula = exports.CustomFormulaAdapter = exports.createFormulaAdapter = exports.DefaultFormulaAdapter = void 0;
|
|
6
|
+
|
|
7
|
+
class DefaultFormulaAdapter {
|
|
8
|
+
constructor(table) {
|
|
9
|
+
this.table = table;
|
|
10
|
+
}
|
|
11
|
+
isFormulaCell(col, row) {
|
|
12
|
+
const cellValue = this.table.getCellValue(col, row);
|
|
13
|
+
return "string" == typeof cellValue && cellValue.startsWith("=");
|
|
14
|
+
}
|
|
15
|
+
getCellFormula(col, row) {
|
|
16
|
+
const cellValue = this.table.getCellValue(col, row);
|
|
17
|
+
if ("string" == typeof cellValue && cellValue.startsWith("=")) return cellValue;
|
|
18
|
+
}
|
|
19
|
+
setCellFormula(col, row, formula) {
|
|
20
|
+
this.table.changeCellValue(col, row, formula);
|
|
21
|
+
}
|
|
22
|
+
getCalculatedValue(col, row) {
|
|
23
|
+
return this.table.getCellValue(col, row);
|
|
24
|
+
}
|
|
25
|
+
refreshFormulas() {}
|
|
26
|
+
hasFormulaEngine() {
|
|
27
|
+
return !1;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function createFormulaAdapter(table, customIsFormulaCell, customGetCellFormula, customSetCellFormula) {
|
|
32
|
+
return customIsFormulaCell || customGetCellFormula || customSetCellFormula ? new CustomFormulaAdapter(table, customIsFormulaCell, customGetCellFormula, customSetCellFormula) : new DefaultFormulaAdapter(table);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
exports.DefaultFormulaAdapter = DefaultFormulaAdapter, exports.createFormulaAdapter = createFormulaAdapter;
|
|
36
|
+
|
|
37
|
+
class CustomFormulaAdapter {
|
|
38
|
+
constructor(table, isFormulaCellFn, getCellFormulaFn, setCellFormulaFn) {
|
|
39
|
+
this.table = table, this.isFormulaCellFn = isFormulaCellFn, this.getCellFormulaFn = getCellFormulaFn,
|
|
40
|
+
this.setCellFormulaFn = setCellFormulaFn;
|
|
41
|
+
}
|
|
42
|
+
isFormulaCell(col, row) {
|
|
43
|
+
if (this.isFormulaCellFn) {
|
|
44
|
+
const cellData = this.table.getCellValue(col, row);
|
|
45
|
+
return this.isFormulaCellFn(col, row, cellData, this.table);
|
|
46
|
+
}
|
|
47
|
+
const cellValue = this.table.getCellValue(col, row);
|
|
48
|
+
return "string" == typeof cellValue && cellValue.startsWith("=");
|
|
49
|
+
}
|
|
50
|
+
getCellFormula(col, row) {
|
|
51
|
+
if (this.getCellFormulaFn) {
|
|
52
|
+
const cellData = this.table.getCellValue(col, row);
|
|
53
|
+
return this.getCellFormulaFn(col, row, cellData, this.table);
|
|
54
|
+
}
|
|
55
|
+
const cellValue = this.table.getCellValue(col, row);
|
|
56
|
+
if ("string" == typeof cellValue && cellValue.startsWith("=")) return cellValue;
|
|
57
|
+
}
|
|
58
|
+
setCellFormula(col, row, formula) {
|
|
59
|
+
this.setCellFormulaFn ? this.setCellFormulaFn(col, row, formula, this.table) : this.table.changeCellValue(col, row, formula);
|
|
60
|
+
}
|
|
61
|
+
getCalculatedValue(col, row) {
|
|
62
|
+
return this.table.getCellValue(col, row);
|
|
63
|
+
}
|
|
64
|
+
refreshFormulas() {}
|
|
65
|
+
hasFormulaEngine() {
|
|
66
|
+
return !1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function enhanceCellDataWithFormula(cellData, col, row, formulaAdapter) {
|
|
71
|
+
const enhanced = Object.assign({}, cellData);
|
|
72
|
+
return formulaAdapter.isFormulaCell(col, row) && (enhanced.isFormula = !0, enhanced.formula = formulaAdapter.getCellFormula(col, row),
|
|
73
|
+
enhanced.calculatedValue = formulaAdapter.getCalculatedValue(col, row)), enhanced;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
exports.CustomFormulaAdapter = CustomFormulaAdapter, exports.enhanceCellDataWithFormula = enhanceCellDataWithFormula;
|
|
77
|
+
//# sourceMappingURL=formula-integration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/auto-fill/formula-integration.ts"],"names":[],"mappings":";;;AA0DA,MAAa,qBAAqB;IAGhC,YAAY,KAAgB;QAC1B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,aAAa,CAAC,GAAW,EAAE,GAAW;QACpC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG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AAE,IAAI,CAAC,KAAK,CAAC,CAAC;YACrD,OAAO;SACR;QAGD,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;IAED,kBAAkB,CAAC,GAAW,EAAE,GAAW;QAGzC,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC3C,CAAC;IAED,eAAe;IAEf,CAAC;IAED,gBAAgB;QACd,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAlED,oDAkEC;AAyBD,SAAgB,0BAA0B,CACxC,QAAmB,EACnB,GAAW,EACX,GAAW,EACX,cAAkC;IAElC,MAAM,QAAQ,GAAG,kBAAK,QAAQ,CAAsB,CAAC;IAErD,IAAI,cAAc,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;QAC1C,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC;QAC1B,QAAQ,CAAC,OAAO,GAAG,cAAc,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC3D,QAAQ,CAAC,eAAe,GAAG,cAAc,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;KACxE;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAfD,gEAeC","file":"formula-integration.js","sourcesContent":["/**\n * Copyright 2023-present DreamNum Co., Ltd.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ListTable } from '@visactor/vtable';\nimport type { ICellData } from './types';\n\n/**\n * Interface for formula-aware table operations\n * This provides a low-coupling integration point between auto-fill and formula systems\n */\nexport interface IFormulaAwareTable {\n /**\n * Check if a cell contains a formula\n */\n isFormulaCell: (col: number, row: number) => boolean;\n\n /**\n * Get the formula string from a cell\n */\n getCellFormula: (col: number, row: number) => string | undefined;\n\n /**\n * Set a formula in a cell\n */\n setCellFormula: (col: number, row: number, formula: string) => void;\n\n /**\n * Get the calculated value of a cell\n */\n getCalculatedValue: (col: number, row: number) => any;\n\n /**\n * Refresh formula calculations after auto-fill\n */\n refreshFormulas: () => void;\n\n /**\n * Check if formula engine is available\n */\n hasFormulaEngine: () => boolean;\n}\n\n/**\n * Default implementation that works without formula engine\n */\nexport class DefaultFormulaAdapter implements IFormulaAwareTable {\n private table: ListTable;\n\n constructor(table: ListTable) {\n this.table = table;\n }\n\n isFormulaCell(col: number, row: number): boolean {\n const cellValue = this.table.getCellValue(col, row);\n return typeof cellValue === 'string' && cellValue.startsWith('=');\n }\n\n getCellFormula(col: number, row: number): string | undefined {\n const cellValue = this.table.getCellValue(col, row);\n if (typeof cellValue === 'string' && cellValue.startsWith('=')) {\n return cellValue;\n }\n return undefined;\n }\n\n setCellFormula(col: number, row: number, formula: string): void {\n this.table.changeCellValue(col, row, formula);\n }\n\n getCalculatedValue(col: number, row: number): any {\n // Without formula engine, just return the raw value\n return this.table.getCellValue(col, row);\n }\n\n refreshFormulas(): void {\n // No-op without formula engine\n }\n\n hasFormulaEngine(): boolean {\n return false;\n }\n}\n\n/**\n * Factory to create appropriate formula adapter with custom functions\n */\nexport function createFormulaAdapter(\n table: ListTable,\n customIsFormulaCell?: (col: number, row: number, cellData: any, table: ListTable) => boolean,\n customGetCellFormula?: (col: number, row: number, cellData: any, table: ListTable) => string | undefined,\n customSetCellFormula?: (col: number, row: number, formula: string, table: ListTable) => void\n): IFormulaAwareTable {\n // If custom functions are provided, create a custom adapter\n if (customIsFormulaCell || customGetCellFormula || customSetCellFormula) {\n return new CustomFormulaAdapter(table, customIsFormulaCell, customGetCellFormula, customSetCellFormula);\n }\n\n return new DefaultFormulaAdapter(table);\n}\n\n/**\n * Custom formula adapter that uses user-provided functions\n */\nexport class CustomFormulaAdapter implements IFormulaAwareTable {\n private table: ListTable;\n private isFormulaCellFn?: (col: number, row: number, cellData: any, table: ListTable) => boolean;\n private getCellFormulaFn?: (col: number, row: number, cellData: any, table: ListTable) => string | undefined;\n private setCellFormulaFn?: (col: number, row: number, formula: string, table: ListTable) => void;\n\n constructor(\n table: ListTable,\n isFormulaCellFn?: (col: number, row: number, cellData: any, table: ListTable) => boolean,\n getCellFormulaFn?: (col: number, row: number, cellData: any, table: ListTable) => string | undefined,\n setCellFormulaFn?: (col: number, row: number, formula: string, table: ListTable) => void\n ) {\n this.table = table;\n this.isFormulaCellFn = isFormulaCellFn;\n this.getCellFormulaFn = getCellFormulaFn;\n this.setCellFormulaFn = setCellFormulaFn;\n }\n\n isFormulaCell(col: number, row: number): boolean {\n if (this.isFormulaCellFn) {\n const cellData = this.table.getCellValue(col, row);\n return this.isFormulaCellFn(col, row, cellData, this.table);\n }\n\n // Fallback to default logic\n const cellValue = this.table.getCellValue(col, row);\n return typeof cellValue === 'string' && cellValue.startsWith('=');\n }\n\n getCellFormula(col: number, row: number): string | undefined {\n if (this.getCellFormulaFn) {\n const cellData = this.table.getCellValue(col, row);\n return this.getCellFormulaFn(col, row, cellData, this.table);\n }\n\n // Fallback to default logic\n const cellValue = this.table.getCellValue(col, row);\n if (typeof cellValue === 'string' && cellValue.startsWith('=')) {\n return cellValue;\n }\n return undefined;\n }\n\n setCellFormula(col: number, row: number, formula: string): void {\n if (this.setCellFormulaFn) {\n this.setCellFormulaFn(col, row, formula, this.table);\n return;\n }\n\n // Fallback to default logic\n this.table.changeCellValue(col, row, formula);\n }\n\n getCalculatedValue(col: number, row: number): any {\n // For custom adapter, we don't have access to formula engine\n // Just return the raw value\n return this.table.getCellValue(col, row);\n }\n\n refreshFormulas(): void {\n // No-op for custom adapter without formula engine\n }\n\n hasFormulaEngine(): boolean {\n return false;\n }\n}\n\n/**\n * Enhanced cell data with formula information\n */\nexport interface IFormulaCellData extends ICellData {\n /**\n * Original formula string (if applicable)\n */\n formula?: string;\n\n /**\n * Whether this is a formula cell\n */\n isFormula?: boolean;\n\n /**\n * Calculated value (if formula)\n */\n calculatedValue?: any;\n}\n\n/**\n * Helper to enhance cell data with formula information\n */\nexport function enhanceCellDataWithFormula(\n cellData: ICellData,\n col: number,\n row: number,\n formulaAdapter: IFormulaAwareTable\n): IFormulaCellData {\n const enhanced = { ...cellData } as IFormulaCellData;\n\n if (formulaAdapter.isFormulaCell(col, row)) {\n enhanced.isFormula = true;\n enhanced.formula = formulaAdapter.getCellFormula(col, row);\n enhanced.calculatedValue = formulaAdapter.getCalculatedValue(col, row);\n }\n\n return enhanced;\n}\n"]}
|
package/cjs/auto-fill/index.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { pluginsDefinition, ListTable, BaseTableAPI } from '@visactor/vtable';
|
|
2
2
|
import type { TableEvents } from '@visactor/vtable/src/core/TABLE_EVENT_TYPE';
|
|
3
|
+
export * from './formula-integration';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export * from './rules';
|
|
3
6
|
export interface IAutoFillPluginOptions {
|
|
4
7
|
fillMode?: 'copy' | 'series';
|
|
5
8
|
fastFillMode?: 'copy' | 'series';
|
|
9
|
+
isFormulaCell?: (col: number, row: number, cellData: any, table: ListTable) => boolean;
|
|
10
|
+
getCellFormula?: (col: number, row: number, cellData: any, table: ListTable) => string | undefined;
|
|
11
|
+
setCellFormula?: (col: number, row: number, formula: string, table: ListTable) => void;
|
|
6
12
|
}
|
|
7
13
|
export declare class AutoFillPlugin implements pluginsDefinition.IVTablePlugin {
|
|
8
14
|
id: string;
|
package/cjs/auto-fill/index.js
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4
|
+
void 0 === k2 && (k2 = k);
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
|
|
7
|
+
enumerable: !0,
|
|
8
|
+
get: function() {
|
|
9
|
+
return m[k];
|
|
10
|
+
}
|
|
11
|
+
}), Object.defineProperty(o, k2, desc);
|
|
12
|
+
} : function(o, m, k, k2) {
|
|
13
|
+
void 0 === k2 && (k2 = k), o[k2] = m[k];
|
|
14
|
+
}), __exportStar = this && this.__exportStar || function(m, exports) {
|
|
15
|
+
for (var p in m) "default" === p || Object.prototype.hasOwnProperty.call(exports, p) || __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
|
|
3
18
|
Object.defineProperty(exports, "__esModule", {
|
|
4
19
|
value: !0
|
|
5
20
|
}), exports.AutoFillPlugin = void 0;
|
|
6
21
|
|
|
7
22
|
const vtable_1 = require("@visactor/vtable"), auto_fill_manager_1 = require("./auto-fill-manager");
|
|
8
23
|
|
|
24
|
+
__exportStar(require("./formula-integration"), exports), __exportStar(require("./types"), exports),
|
|
25
|
+
__exportStar(require("./rules"), exports);
|
|
26
|
+
|
|
9
27
|
class AutoFillPlugin {
|
|
10
28
|
constructor(options) {
|
|
11
29
|
this.id = "auto-fill", this.name = "Auto Fill", this.runTime = [ vtable_1.TABLE_EVENT_TYPE.MOUSEDOWN_FILL_HANDLE, vtable_1.TABLE_EVENT_TYPE.DRAG_FILL_HANDLE_END, vtable_1.TABLE_EVENT_TYPE.DBLCLICK_FILL_HANDLE ],
|
|
@@ -14,7 +32,7 @@ class AutoFillPlugin {
|
|
|
14
32
|
run(...args) {
|
|
15
33
|
var _a, _b;
|
|
16
34
|
if (args[1] === vtable_1.TABLE_EVENT_TYPE.MOUSEDOWN_FILL_HANDLE) {
|
|
17
|
-
const [
|
|
35
|
+
const [, , table] = args;
|
|
18
36
|
this.table = table, this.autoFillManager.setTable(this.table), this.autoFillManager.handleStartDrag(null === (_a = this.table) || void 0 === _a ? void 0 : _a.getSelectedCellRanges()[0]);
|
|
19
37
|
} else if (args[1] === vtable_1.TABLE_EVENT_TYPE.DRAG_FILL_HANDLE_END) {
|
|
20
38
|
const [{direction: direction}] = args;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/auto-fill/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/auto-fill/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,6CAAoD;AAEpD,2DAAsD;AACtD,wDAAsC;AACtC,0CAAwB;AACxB,0CAAwB;AAkDxB,MAAa,cAAc;IAUzB,YAAY,OAAgC;QAT5C,OAAE,GAAG,WAAW,CAAC;QACjB,SAAI,GAAG,WAAW,CAAC;QACnB,YAAO,GAAG;YACR,yBAAgB,CAAC,qBAAqB;YACtC,yBAAgB,CAAC,oBAAoB;YACrC,yBAAgB,CAAC,oBAAoB;SACtC,CAAC;QAIA,IAAI,CAAC,eAAe,GAAG,IAAI,mCAAe,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC;IACD,GAAG,CACD,GAAG,IAA8G;;QAGjH,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,yBAAgB,CAAC,qBAAqB,EAAE;YACtD,MAAM,CAAC,EAAC,AAAC,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;YACzB,IAAI,CAAC,KAAK,GAAG,KAAkB,CAAC;YAChC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1C,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,MAAA,IAAI,CAAC,KAAK,0CAAE,qBAAqB,GAAG,CAAC,CAAC,CAAC,CAAC;SAC9E;aAAM,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,yBAAgB,CAAC,oBAAoB,EAAE;YAE5D,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,IAAI,CAAC;YAC7B,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,MAAA,IAAI,CAAC,KAAK,0CAAE,qBAAqB,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;SACvF;aAAM,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,yBAAgB,CAAC,oBAAoB,EAAE;YAC5D,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,CAAC;SACtC;IACH,CAAC;CACF;AA9BD,wCA8BC","file":"index.js","sourcesContent":["import type { pluginsDefinition, ListTable, BaseTableAPI } from '@visactor/vtable';\nimport { TABLE_EVENT_TYPE } from '@visactor/vtable';\nimport type { TableEvents } from '@visactor/vtable/src/core/TABLE_EVENT_TYPE';\nimport { AutoFillManager } from './auto-fill-manager';\nexport * from './formula-integration';\nexport * from './types';\nexport * from './rules';\n/**\n * 自动填充插件\n */\nexport interface IAutoFillPluginOptions {\n /**\n * 填充模式\n * 'copy': 复制填充\n * 'series': 序列填充\n * 不填写则开启自动填充菜单\n */\n fillMode?: 'copy' | 'series';\n /**\n * 快速填充模式\n * 'copy': 复制填充\n * 'series': 序列填充\n * 不填写则开启自动填充菜单\n */\n fastFillMode?: 'copy' | 'series';\n /**\n * 自定义公式检测函数\n * 用于判断单元格是否包含公式\n * @param col 列索引\n * @param row 行索引\n * @param cellData 单元格数据\n * @param table 表格实例\n * @returns 是否为公式\n */\n isFormulaCell?: (col: number, row: number, cellData: any, table: ListTable) => boolean;\n /**\n * 自定义公式获取函数\n * 用于获取单元格的公式字符串\n * @param col 列索引\n * @param row 行索引\n * @param cellData 单元格数据\n * @param table 表格实例\n * @returns 公式字符串,如果没有公式则返回undefined\n */\n getCellFormula?: (col: number, row: number, cellData: any, table: ListTable) => string | undefined;\n /**\n * 自定义公式设置函数\n * 用于设置单元格的公式\n * @param col 列索引\n * @param row 行索引\n * @param formula 公式字符串\n * @param table 表格实例\n */\n setCellFormula?: (col: number, row: number, formula: string, table: ListTable) => void;\n}\n\nexport class AutoFillPlugin implements pluginsDefinition.IVTablePlugin {\n id = `auto-fill`;\n name = 'Auto Fill';\n runTime = [\n TABLE_EVENT_TYPE.MOUSEDOWN_FILL_HANDLE,\n TABLE_EVENT_TYPE.DRAG_FILL_HANDLE_END,\n TABLE_EVENT_TYPE.DBLCLICK_FILL_HANDLE\n ];\n table: ListTable;\n private autoFillManager: AutoFillManager;\n constructor(options?: IAutoFillPluginOptions) {\n this.autoFillManager = new AutoFillManager(options);\n }\n run(\n ...args: [{ direction: string }, TableEvents[keyof TableEvents] | TableEvents[keyof TableEvents][], BaseTableAPI]\n ) {\n // start drag\n if (args[1] === TABLE_EVENT_TYPE.MOUSEDOWN_FILL_HANDLE) {\n const [, , table] = args;\n this.table = table as ListTable;\n this.autoFillManager.setTable(this.table);\n this.autoFillManager.handleStartDrag(this.table?.getSelectedCellRanges()[0]);\n } else if (args[1] === TABLE_EVENT_TYPE.DRAG_FILL_HANDLE_END) {\n // end drag\n const [{ direction }] = args;\n this.autoFillManager.handleEndDrag(this.table?.getSelectedCellRanges()[0], direction);\n } else if (args[1] === TABLE_EVENT_TYPE.DBLCLICK_FILL_HANDLE) {\n this.autoFillManager.handleDbClick();\n }\n }\n}\n"]}
|
package/cjs/auto-fill/rules.d.ts
CHANGED
|
@@ -8,3 +8,4 @@ export declare const chnWeek2Rule: IAutoFillRule;
|
|
|
8
8
|
export declare const chnWeek3Rule: IAutoFillRule;
|
|
9
9
|
export declare const loopSeriesRule: IAutoFillRule;
|
|
10
10
|
export declare function reverseIfNeed<T>(data: T[], reverse: boolean): T[];
|
|
11
|
+
export declare const formulaRule: IAutoFillRule;
|