@visactor/vtable-sheet 1.20.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/components/vtable-sheet.d.ts +78 -0
- package/cjs/components/vtable-sheet.js +474 -0
- package/cjs/components/vtable-sheet.js.map +1 -0
- package/cjs/core/WorkSheet.d.ts +69 -0
- package/cjs/core/WorkSheet.js +298 -0
- package/cjs/core/WorkSheet.js.map +1 -0
- package/cjs/core/table-plugins.d.ts +3 -0
- package/cjs/core/table-plugins.js +171 -0
- package/cjs/core/table-plugins.js.map +1 -0
- package/cjs/event/event-manager.d.ts +29 -0
- package/cjs/event/event-manager.js +71 -0
- package/cjs/event/event-manager.js.map +1 -0
- package/cjs/event/event-target.d.ts +12 -0
- package/cjs/event/event-target.js +50 -0
- package/cjs/event/event-target.js.map +1 -0
- package/cjs/formula/cell-highlight-manager.d.ts +29 -0
- package/cjs/formula/cell-highlight-manager.js +141 -0
- package/cjs/formula/cell-highlight-manager.js.map +1 -0
- package/cjs/formula/formula-autocomplete.d.ts +39 -0
- package/cjs/formula/formula-autocomplete.js +239 -0
- package/cjs/formula/formula-autocomplete.js.map +1 -0
- package/cjs/formula/formula-editor.d.ts +21 -0
- package/cjs/formula/formula-editor.js +162 -0
- package/cjs/formula/formula-editor.js.map +1 -0
- package/cjs/formula/formula-helper.d.ts +8 -0
- package/cjs/formula/formula-helper.js +66 -0
- package/cjs/formula/formula-helper.js.map +1 -0
- package/cjs/formula/formula-range-selector.d.ts +19 -0
- package/cjs/formula/formula-range-selector.js +201 -0
- package/cjs/formula/formula-range-selector.js.map +1 -0
- package/cjs/formula/formula-throttle.d.ts +10 -0
- package/cjs/formula/formula-throttle.js +39 -0
- package/cjs/formula/formula-throttle.js.map +1 -0
- package/cjs/formula/formula-ui-manager.d.ts +19 -0
- package/cjs/formula/formula-ui-manager.js +226 -0
- package/cjs/formula/formula-ui-manager.js.map +1 -0
- package/cjs/formula/index.d.ts +5 -0
- package/cjs/formula/index.js +23 -0
- package/cjs/formula/index.js.map +1 -0
- package/cjs/index.d.ts +6 -0
- package/cjs/index.js +50 -0
- package/cjs/index.js.map +1 -0
- package/cjs/managers/formula-manager.d.ts +82 -0
- package/cjs/managers/formula-manager.js +445 -0
- package/cjs/managers/formula-manager.js.map +1 -0
- package/cjs/managers/menu-manager.d.ts +12 -0
- package/cjs/managers/menu-manager.js +89 -0
- package/cjs/managers/menu-manager.js.map +1 -0
- package/cjs/managers/sheet-manager.d.ts +21 -0
- package/cjs/managers/sheet-manager.js +74 -0
- package/cjs/managers/sheet-manager.js.map +1 -0
- package/cjs/managers/tab-drag-manager.d.ts +24 -0
- package/cjs/managers/tab-drag-manager.js +121 -0
- package/cjs/managers/tab-drag-manager.js.map +1 -0
- package/cjs/sheet-helper.d.ts +16 -0
- package/cjs/sheet-helper.js +64 -0
- package/cjs/sheet-helper.js.map +1 -0
- package/cjs/styles/common.d.ts +1 -0
- package/cjs/styles/common.js +17 -0
- package/cjs/styles/common.js.map +1 -0
- package/cjs/styles/formula-autocomplete.d.ts +1 -0
- package/cjs/styles/formula-autocomplete.js +17 -0
- package/cjs/styles/formula-autocomplete.js.map +1 -0
- package/cjs/styles/formula-bar.d.ts +1 -0
- package/cjs/styles/formula-bar.js +17 -0
- package/cjs/styles/formula-bar.js.map +1 -0
- package/cjs/styles/menu.d.ts +1 -0
- package/cjs/styles/menu.js +17 -0
- package/cjs/styles/menu.js.map +1 -0
- package/cjs/styles/sheet-tab.d.ts +1 -0
- package/cjs/styles/sheet-tab.js +17 -0
- package/cjs/styles/sheet-tab.js.map +1 -0
- package/cjs/styles/sheet.d.ts +1 -0
- package/cjs/styles/sheet.js +17 -0
- package/cjs/styles/sheet.js.map +1 -0
- package/cjs/styles/style-manager.d.ts +1 -0
- package/cjs/styles/style-manager.js +15 -0
- package/cjs/styles/style-manager.js.map +1 -0
- package/cjs/test/formula-complete.test.d.ts +1 -0
- package/cjs/test/formula-complete.test.js +42 -0
- package/cjs/test/formula-complete.test.js.map +1 -0
- package/cjs/tools/env.d.ts +20 -0
- package/cjs/tools/env.js +59 -0
- package/cjs/tools/env.js.map +1 -0
- package/cjs/tools/index.d.ts +3 -0
- package/cjs/tools/index.js +16 -0
- package/cjs/tools/index.js.map +1 -0
- package/cjs/tools/ui/snackbar.d.ts +1 -0
- package/cjs/tools/ui/snackbar.js +20 -0
- package/cjs/tools/ui/snackbar.js.map +1 -0
- package/cjs/ts-types/base.d.ts +44 -0
- package/cjs/ts-types/base.js +14 -0
- package/cjs/ts-types/base.js.map +1 -0
- package/cjs/ts-types/event.d.ts +79 -0
- package/cjs/ts-types/event.js +6 -0
- package/cjs/ts-types/event.js.map +1 -0
- package/cjs/ts-types/events.d.ts +1 -0
- package/cjs/ts-types/events.js +3 -0
- package/cjs/ts-types/events.js.map +1 -0
- package/cjs/ts-types/filter.d.ts +58 -0
- package/cjs/ts-types/filter.js +16 -0
- package/cjs/ts-types/filter.js.map +1 -0
- package/cjs/ts-types/formula.d.ts +51 -0
- package/cjs/ts-types/formula.js +6 -0
- package/cjs/ts-types/formula.js.map +1 -0
- package/cjs/ts-types/index.d.ts +67 -0
- package/cjs/ts-types/index.js +37 -0
- package/cjs/ts-types/index.js.map +1 -0
- package/cjs/ts-types/sheet.d.ts +45 -0
- package/cjs/ts-types/sheet.js +6 -0
- package/cjs/ts-types/sheet.js.map +1 -0
- package/cjs/vtable.d.ts +1 -0
- package/cjs/vtable.js +35 -0
- package/cjs/vtable.js.map +1 -0
- package/dist/vtable-sheet.js +114494 -0
- package/dist/vtable-sheet.min.js +853 -0
- package/es/components/vtable-sheet.d.ts +78 -0
- package/es/components/vtable-sheet.js +462 -0
- package/es/components/vtable-sheet.js.map +1 -0
- package/es/core/WorkSheet.d.ts +69 -0
- package/es/core/WorkSheet.js +298 -0
- package/es/core/WorkSheet.js.map +1 -0
- package/es/core/table-plugins.d.ts +3 -0
- package/es/core/table-plugins.js +164 -0
- package/es/core/table-plugins.js.map +1 -0
- package/es/event/event-manager.d.ts +29 -0
- package/es/event/event-manager.js +63 -0
- package/es/event/event-manager.js.map +1 -0
- package/es/event/event-target.d.ts +12 -0
- package/es/event/event-target.js +42 -0
- package/es/event/event-target.js.map +1 -0
- package/es/formula/cell-highlight-manager.d.ts +29 -0
- package/es/formula/cell-highlight-manager.js +133 -0
- package/es/formula/cell-highlight-manager.js.map +1 -0
- package/es/formula/formula-autocomplete.d.ts +39 -0
- package/es/formula/formula-autocomplete.js +231 -0
- package/es/formula/formula-autocomplete.js.map +1 -0
- package/es/formula/formula-editor.d.ts +21 -0
- package/es/formula/formula-editor.js +135 -0
- package/es/formula/formula-editor.js.map +1 -0
- package/es/formula/formula-helper.d.ts +8 -0
- package/es/formula/formula-helper.js +60 -0
- package/es/formula/formula-helper.js.map +1 -0
- package/es/formula/formula-range-selector.d.ts +19 -0
- package/es/formula/formula-range-selector.js +195 -0
- package/es/formula/formula-range-selector.js.map +1 -0
- package/es/formula/formula-throttle.d.ts +10 -0
- package/es/formula/formula-throttle.js +31 -0
- package/es/formula/formula-throttle.js.map +1 -0
- package/es/formula/formula-ui-manager.d.ts +19 -0
- package/es/formula/formula-ui-manager.js +218 -0
- package/es/formula/formula-ui-manager.js.map +1 -0
- package/es/formula/index.d.ts +5 -0
- package/es/formula/index.js +10 -0
- package/es/formula/index.js.map +1 -0
- package/es/index.d.ts +6 -0
- package/es/index.js +13 -0
- package/es/index.js.map +1 -0
- package/es/managers/formula-manager.d.ts +82 -0
- package/es/managers/formula-manager.js +441 -0
- package/es/managers/formula-manager.js.map +1 -0
- package/es/managers/menu-manager.d.ts +12 -0
- package/es/managers/menu-manager.js +81 -0
- package/es/managers/menu-manager.js.map +1 -0
- package/es/managers/sheet-manager.d.ts +21 -0
- package/es/managers/sheet-manager.js +66 -0
- package/es/managers/sheet-manager.js.map +1 -0
- package/es/managers/tab-drag-manager.d.ts +24 -0
- package/es/managers/tab-drag-manager.js +113 -0
- package/es/managers/tab-drag-manager.js.map +1 -0
- package/es/sheet-helper.d.ts +16 -0
- package/es/sheet-helper.js +54 -0
- package/es/sheet-helper.js.map +1 -0
- package/es/styles/common.d.ts +1 -0
- package/es/styles/common.js +9 -0
- package/es/styles/common.js.map +1 -0
- package/es/styles/formula-autocomplete.d.ts +1 -0
- package/es/styles/formula-autocomplete.js +9 -0
- package/es/styles/formula-autocomplete.js.map +1 -0
- package/es/styles/formula-bar.d.ts +1 -0
- package/es/styles/formula-bar.js +9 -0
- package/es/styles/formula-bar.js.map +1 -0
- package/es/styles/menu.d.ts +1 -0
- package/es/styles/menu.js +9 -0
- package/es/styles/menu.js.map +1 -0
- package/es/styles/sheet-tab.d.ts +1 -0
- package/es/styles/sheet-tab.js +9 -0
- package/es/styles/sheet-tab.js.map +1 -0
- package/es/styles/sheet.d.ts +1 -0
- package/es/styles/sheet.js +9 -0
- package/es/styles/sheet.js.map +1 -0
- package/es/styles/style-manager.d.ts +1 -0
- package/es/styles/style-manager.js +17 -0
- package/es/styles/style-manager.js.map +1 -0
- package/es/test/formula-complete.test.d.ts +1 -0
- package/es/test/formula-complete.test.js +36 -0
- package/es/test/formula-complete.test.js.map +1 -0
- package/es/tools/env.d.ts +20 -0
- package/es/tools/env.js +53 -0
- package/es/tools/env.js.map +1 -0
- package/es/tools/index.d.ts +3 -0
- package/es/tools/index.js +9 -0
- package/es/tools/index.js.map +1 -0
- package/es/tools/ui/snackbar.d.ts +1 -0
- package/es/tools/ui/snackbar.js +14 -0
- package/es/tools/ui/snackbar.js.map +1 -0
- package/es/ts-types/base.d.ts +44 -0
- package/es/ts-types/base.js +14 -0
- package/es/ts-types/base.js.map +1 -0
- package/es/ts-types/event.d.ts +79 -0
- package/es/ts-types/event.js +2 -0
- package/es/ts-types/event.js.map +1 -0
- package/es/ts-types/events.d.ts +1 -0
- package/es/ts-types/events.js +3 -0
- package/es/ts-types/events.js.map +1 -0
- package/es/ts-types/filter.d.ts +58 -0
- package/es/ts-types/filter.js +16 -0
- package/es/ts-types/filter.js.map +1 -0
- package/es/ts-types/formula.d.ts +51 -0
- package/es/ts-types/formula.js +2 -0
- package/es/ts-types/formula.js.map +1 -0
- package/es/ts-types/index.d.ts +67 -0
- package/es/ts-types/index.js +14 -0
- package/es/ts-types/index.js.map +1 -0
- package/es/ts-types/sheet.d.ts +45 -0
- package/es/ts-types/sheet.js +2 -0
- package/es/ts-types/sheet.js.map +1 -0
- package/es/vtable.d.ts +1 -0
- package/es/vtable.js +2 -0
- package/es/vtable.js.map +1 -0
- package/package.json +120 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
export class FormulaAutocomplete {
|
|
2
|
+
constructor(container, sheet) {
|
|
3
|
+
this.dropdown = null, this.items = [], this.selectedIndex = -1, this.isVisible = !1,
|
|
4
|
+
this.inputElement = null, this.container = container, this.sheet = sheet, this.createDropdown();
|
|
5
|
+
}
|
|
6
|
+
createDropdown() {
|
|
7
|
+
this.dropdown = document.createElement("div"), this.dropdown.className = "vtable-formula-autocomplete",
|
|
8
|
+
this.dropdown.style.display = "none", this.container.appendChild(this.dropdown);
|
|
9
|
+
}
|
|
10
|
+
attachTo(input, onSelect, customPositioning) {
|
|
11
|
+
this.inputElement = input, this.onSelectCallback = onSelect, this.customPositioning = customPositioning,
|
|
12
|
+
input.addEventListener("input", this.handleInput.bind(this)), input.addEventListener("keydown", this.handleKeydown.bind(this)),
|
|
13
|
+
input.addEventListener("blur", (() => {
|
|
14
|
+
setTimeout((() => this.hide()), 200);
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
handleInput(event) {
|
|
18
|
+
const input = event.target, value = input.value, cursorPos = input.selectionStart || 0, context = this.parseInputContext(value, cursorPos);
|
|
19
|
+
context.shouldShowAutocomplete ? (this.updateSuggestions(context), this.show()) : this.hide();
|
|
20
|
+
}
|
|
21
|
+
parseInputContext(value, cursorPos) {
|
|
22
|
+
if (!value.startsWith("=")) return {
|
|
23
|
+
shouldShowAutocomplete: !1,
|
|
24
|
+
searchTerm: "",
|
|
25
|
+
type: "all",
|
|
26
|
+
insertPosition: 0
|
|
27
|
+
};
|
|
28
|
+
const textBeforeCursor = value.substring(1, cursorPos), lastOperatorMatch = textBeforeCursor.match(/[\+\-\*\/\(\,\s]([A-Za-z0-9]*)$/);
|
|
29
|
+
return lastOperatorMatch && "" !== lastOperatorMatch[1] ? {
|
|
30
|
+
shouldShowAutocomplete: !0,
|
|
31
|
+
searchTerm: lastOperatorMatch[1],
|
|
32
|
+
type: /^[A-Za-z]/.test(lastOperatorMatch[1]) ? "function" : "cell",
|
|
33
|
+
insertPosition: cursorPos - lastOperatorMatch[1].length
|
|
34
|
+
} : textBeforeCursor.match(/^[A-Za-z0-9]*$/) ? {
|
|
35
|
+
shouldShowAutocomplete: !0,
|
|
36
|
+
searchTerm: textBeforeCursor,
|
|
37
|
+
type: "all",
|
|
38
|
+
insertPosition: 1
|
|
39
|
+
} : {
|
|
40
|
+
shouldShowAutocomplete: !1,
|
|
41
|
+
searchTerm: "",
|
|
42
|
+
type: "all",
|
|
43
|
+
insertPosition: 0
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
updateSuggestions(context) {
|
|
47
|
+
const {searchTerm: searchTerm, type: type} = context;
|
|
48
|
+
if (this.items = [], "function" === type || "all" === type) {
|
|
49
|
+
const functionItems = this.sheet.formulaManager.getAvailableFunctions().filter((fn => fn.toUpperCase().startsWith(searchTerm.toUpperCase()))).slice(0, 10).map((fn => ({
|
|
50
|
+
type: "function",
|
|
51
|
+
value: fn,
|
|
52
|
+
label: fn,
|
|
53
|
+
description: this.getFunctionDescription(fn),
|
|
54
|
+
signature: this.getFunctionSignature(fn)
|
|
55
|
+
})));
|
|
56
|
+
this.items.push(...functionItems);
|
|
57
|
+
}
|
|
58
|
+
if ("cell" === type || "all" === type) {
|
|
59
|
+
const cellSuggestions = this.generateCellSuggestions(searchTerm);
|
|
60
|
+
this.items.push(...cellSuggestions);
|
|
61
|
+
}
|
|
62
|
+
this.renderDropdown();
|
|
63
|
+
}
|
|
64
|
+
generateCellSuggestions(searchTerm) {
|
|
65
|
+
const suggestions = [], cellMatch = searchTerm.match(/^([A-Za-z]*)([0-9]*)$/);
|
|
66
|
+
if (cellMatch) {
|
|
67
|
+
const [, colPart, rowPart] = cellMatch;
|
|
68
|
+
if (colPart && !rowPart) for (let row = 1; row <= 5; row++) suggestions.push({
|
|
69
|
+
type: "cell",
|
|
70
|
+
value: `${colPart.toUpperCase()}${row}`,
|
|
71
|
+
label: `${colPart.toUpperCase()}${row}`,
|
|
72
|
+
description: "单元格引用"
|
|
73
|
+
});
|
|
74
|
+
if (colPart && rowPart) {
|
|
75
|
+
const address = `${colPart.toUpperCase()}${rowPart}`;
|
|
76
|
+
suggestions.push({
|
|
77
|
+
type: "cell",
|
|
78
|
+
value: address,
|
|
79
|
+
label: address,
|
|
80
|
+
description: "单元格引用"
|
|
81
|
+
}), suggestions.push({
|
|
82
|
+
type: "range",
|
|
83
|
+
value: `${address}:`,
|
|
84
|
+
label: `${address}:...`,
|
|
85
|
+
description: "开始选择范围"
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return suggestions.slice(0, 5);
|
|
90
|
+
}
|
|
91
|
+
getFunctionDescription(functionName) {
|
|
92
|
+
return {
|
|
93
|
+
SUM: "计算数值总和",
|
|
94
|
+
AVERAGE: "计算平均值",
|
|
95
|
+
COUNT: "计数数值单元格",
|
|
96
|
+
MAX: "返回最大值",
|
|
97
|
+
MIN: "返回最小值",
|
|
98
|
+
IF: "条件判断",
|
|
99
|
+
VLOOKUP: "垂直查找",
|
|
100
|
+
CONCATENATE: "连接文本"
|
|
101
|
+
}[functionName] || "";
|
|
102
|
+
}
|
|
103
|
+
getFunctionSignature(functionName) {
|
|
104
|
+
return {
|
|
105
|
+
SUM: "(number1, [number2], ...)",
|
|
106
|
+
AVERAGE: "(number1, [number2], ...)",
|
|
107
|
+
COUNT: "(value1, [value2], ...)",
|
|
108
|
+
MAX: "(number1, [number2], ...)",
|
|
109
|
+
MIN: "(number1, [number2], ...)",
|
|
110
|
+
IF: "(logical_test, value_if_true, value_if_false)",
|
|
111
|
+
VLOOKUP: "(lookup_value, table_array, col_index_num, [range_lookup])",
|
|
112
|
+
CONCATENATE: "(text1, [text2], ...)"
|
|
113
|
+
}[functionName] || "()";
|
|
114
|
+
}
|
|
115
|
+
renderDropdown() {
|
|
116
|
+
if (!this.dropdown) return;
|
|
117
|
+
if (this.dropdown.innerHTML = "", 0 === this.items.length) {
|
|
118
|
+
const emptyEl = document.createElement("div");
|
|
119
|
+
return emptyEl.className = "vtable-formula-autocomplete-empty", emptyEl.textContent = "没有匹配的函数",
|
|
120
|
+
void this.dropdown.appendChild(emptyEl);
|
|
121
|
+
}
|
|
122
|
+
const groups = this.groupItems(this.items);
|
|
123
|
+
groups.forEach((group => {
|
|
124
|
+
if (groups.length > 1) {
|
|
125
|
+
const groupEl = document.createElement("div");
|
|
126
|
+
groupEl.className = "vtable-formula-autocomplete-group", groupEl.textContent = this.getGroupTitle(group.type),
|
|
127
|
+
this.dropdown.appendChild(groupEl);
|
|
128
|
+
}
|
|
129
|
+
group.items.forEach(((item, index) => {
|
|
130
|
+
const globalIndex = this.items.indexOf(item), itemEl = document.createElement("div");
|
|
131
|
+
itemEl.className = "vtable-formula-autocomplete-item", globalIndex === this.selectedIndex && itemEl.classList.add("selected");
|
|
132
|
+
const nameEl = document.createElement("div");
|
|
133
|
+
nameEl.className = "item-name";
|
|
134
|
+
const labelEl = document.createElement("span");
|
|
135
|
+
labelEl.textContent = item.label, nameEl.appendChild(labelEl);
|
|
136
|
+
const typeEl = document.createElement("span");
|
|
137
|
+
if (typeEl.className = `item-type ${item.type}`, typeEl.textContent = this.getTypeLabel(item.type),
|
|
138
|
+
nameEl.appendChild(typeEl), itemEl.appendChild(nameEl), item.signature) {
|
|
139
|
+
const signatureEl = document.createElement("div");
|
|
140
|
+
signatureEl.className = "item-signature", signatureEl.textContent = item.signature,
|
|
141
|
+
itemEl.appendChild(signatureEl);
|
|
142
|
+
}
|
|
143
|
+
if (item.description) {
|
|
144
|
+
const descEl = document.createElement("div");
|
|
145
|
+
descEl.className = "item-description", descEl.textContent = item.description, itemEl.appendChild(descEl);
|
|
146
|
+
}
|
|
147
|
+
itemEl.addEventListener("click", (() => this.selectItem(globalIndex))), itemEl.addEventListener("mouseenter", (() => {
|
|
148
|
+
this.selectedIndex = globalIndex, this.renderDropdown();
|
|
149
|
+
})), this.dropdown.appendChild(itemEl);
|
|
150
|
+
}));
|
|
151
|
+
}));
|
|
152
|
+
const footerEl = document.createElement("div");
|
|
153
|
+
footerEl.className = "vtable-formula-autocomplete-footer", footerEl.innerHTML = '\n <div class="shortcut">\n <span class="key">↑↓</span>\n <span>选择</span>\n </div>\n <div class="shortcut">\n <span class="key">Enter</span>\n <span>确认</span>\n </div>\n <div class="shortcut">\n <span class="key">Esc</span>\n <span>取消</span>\n </div>\n ',
|
|
154
|
+
this.dropdown.appendChild(footerEl), this.positionDropdown();
|
|
155
|
+
}
|
|
156
|
+
groupItems(items) {
|
|
157
|
+
const groups = {};
|
|
158
|
+
items.forEach((item => {
|
|
159
|
+
groups[item.type] || (groups[item.type] = []), groups[item.type].push(item);
|
|
160
|
+
}));
|
|
161
|
+
return [ "function", "cell", "range" ].filter((type => groups[type])).map((type => ({
|
|
162
|
+
type: type,
|
|
163
|
+
items: groups[type]
|
|
164
|
+
})));
|
|
165
|
+
}
|
|
166
|
+
getGroupTitle(type) {
|
|
167
|
+
return {
|
|
168
|
+
function: "函数",
|
|
169
|
+
cell: "单元格",
|
|
170
|
+
range: "范围"
|
|
171
|
+
}[type] || type;
|
|
172
|
+
}
|
|
173
|
+
getTypeLabel(type) {
|
|
174
|
+
return {
|
|
175
|
+
function: "fx",
|
|
176
|
+
cell: "A1",
|
|
177
|
+
range: "A:B"
|
|
178
|
+
}[type] || type;
|
|
179
|
+
}
|
|
180
|
+
positionDropdown() {
|
|
181
|
+
if (this.customPositioning) return void this.customPositioning();
|
|
182
|
+
if (!this.dropdown || !this.inputElement) return;
|
|
183
|
+
const inputRect = this.inputElement.getBoundingClientRect(), containerRect = this.container.getBoundingClientRect();
|
|
184
|
+
this.dropdown.style.position = "absolute", this.dropdown.style.left = inputRect.left - containerRect.left + "px",
|
|
185
|
+
this.dropdown.style.top = inputRect.bottom - containerRect.top + 2 + "px", this.dropdown.style.width = `${Math.max(300, inputRect.width)}px`;
|
|
186
|
+
}
|
|
187
|
+
handleKeydown(event) {
|
|
188
|
+
if (this.isVisible) switch (event.key) {
|
|
189
|
+
case "ArrowDown":
|
|
190
|
+
event.preventDefault(), this.selectedIndex = Math.min(this.selectedIndex + 1, this.items.length - 1),
|
|
191
|
+
this.renderDropdown();
|
|
192
|
+
break;
|
|
193
|
+
|
|
194
|
+
case "ArrowUp":
|
|
195
|
+
event.preventDefault(), this.selectedIndex = Math.max(this.selectedIndex - 1, 0),
|
|
196
|
+
this.renderDropdown();
|
|
197
|
+
break;
|
|
198
|
+
|
|
199
|
+
case "Enter":
|
|
200
|
+
case "Tab":
|
|
201
|
+
this.selectedIndex >= 0 && (event.preventDefault(), this.selectItem(this.selectedIndex));
|
|
202
|
+
break;
|
|
203
|
+
|
|
204
|
+
case "Escape":
|
|
205
|
+
this.hide();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
selectItem(index) {
|
|
209
|
+
const item = this.items[index];
|
|
210
|
+
if (item && this.inputElement) {
|
|
211
|
+
if (this.onSelectCallback) this.onSelectCallback(item); else {
|
|
212
|
+
const value = this.inputElement.value, cursorPos = this.inputElement.selectionStart || 0, context = this.parseInputContext(value, cursorPos), newValue = value.substring(0, context.insertPosition) + item.value + ("function" === item.type ? "(" : "") + value.substring(cursorPos);
|
|
213
|
+
this.inputElement.value = newValue;
|
|
214
|
+
const newCursorPos = context.insertPosition + item.value.length + ("function" === item.type ? 1 : 0);
|
|
215
|
+
this.inputElement.setSelectionRange(newCursorPos, newCursorPos);
|
|
216
|
+
}
|
|
217
|
+
this.hide();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
show() {
|
|
221
|
+
this.dropdown && this.items.length > 0 && (this.dropdown.style.display = "block",
|
|
222
|
+
this.isVisible = !0, this.selectedIndex = 0, this.renderDropdown());
|
|
223
|
+
}
|
|
224
|
+
hide() {
|
|
225
|
+
this.dropdown && (this.dropdown.style.display = "none", this.isVisible = !1, this.selectedIndex = -1);
|
|
226
|
+
}
|
|
227
|
+
release() {
|
|
228
|
+
this.dropdown && this.dropdown.parentNode && this.dropdown.parentNode.removeChild(this.dropdown);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=formula-autocomplete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/formula/formula-autocomplete.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,mBAAmB;IAY9B,YAAY,SAAsB,EAAE,KAAkB;QAV9C,aAAQ,GAAuB,IAAI,CAAC;QACpC,UAAK,GAAuB,EAAE,CAAC;QAC/B,kBAAa,GAAW,CAAC,CAAC,CAAC;QAC3B,cAAS,GAAY,KAAK,CAAC;QAC3B,iBAAY,GAA4B,IAAI,CAAC;QAOnD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAKO,cAAc;QACpB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC9C,IAAI,CAAC,QAAQ,CAAC,SAAS,GAAG,6BAA6B,CAAC;QACxD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;QACrC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAKD,QAAQ,CAAC,KAAuB,EAAE,QAA2C,EAAE,iBAA8B;QAC3G,IAAI,CAAC,YAAY,GAAG,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ACH,CAAC;IAKO,IAAI;QACV,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;YACrC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;YACvB,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;SACzB;IACH,CAAC;IAKD,OAAO;QACL,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE;YAC7C,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACrD;IACH,CAAC;CACF","file":"formula-autocomplete.js","sourcesContent":["import type VTableSheet from '../components/vtable-sheet';\n\ninterface AutocompleteItem {\n type: 'function' | 'cell' | 'range';\n value: string;\n label: string;\n description?: string;\n signature?: string;\n}\n\nexport class FormulaAutocomplete {\n private container: HTMLElement;\n private dropdown: HTMLElement | null = null;\n private items: AutocompleteItem[] = [];\n private selectedIndex: number = -1;\n private isVisible: boolean = false;\n private inputElement: HTMLInputElement | null = null;\n private sheet: VTableSheet;\n private onSelectCallback?: (item: AutocompleteItem) => void;\n\n private customPositioning?: () => void;\n\n constructor(container: HTMLElement, sheet: VTableSheet) {\n this.container = container;\n this.sheet = sheet;\n this.createDropdown();\n }\n\n /**\n * 创建下拉框元素\n */\n private createDropdown(): void {\n this.dropdown = document.createElement('div');\n this.dropdown.className = 'vtable-formula-autocomplete';\n this.dropdown.style.display = 'none';\n this.container.appendChild(this.dropdown);\n }\n\n /**\n * 绑定到输入框\n */\n attachTo(input: HTMLInputElement, onSelect?: (item: AutocompleteItem) => void, customPositioning?: () => void): void {\n this.inputElement = input;\n this.onSelectCallback = onSelect;\n this.customPositioning = customPositioning;\n\n // 绑定事件\n input.addEventListener('input', this.handleInput.bind(this));\n input.addEventListener('keydown', this.handleKeydown.bind(this));\n input.addEventListener('blur', () => {\n setTimeout(() => this.hide(), 200);\n });\n }\n\n /**\n * 处理输入事件\n */\n private handleInput(event: Event): void {\n const input = event.target as HTMLInputElement;\n const value = input.value;\n const cursorPos = input.selectionStart || 0;\n\n // 解析当前输入上下文\n const context = this.parseInputContext(value, cursorPos);\n\n if (context.shouldShowAutocomplete) {\n this.updateSuggestions(context);\n this.show();\n } else {\n this.hide();\n }\n }\n\n /**\n * 解析输入上下文\n */\n private parseInputContext(\n value: string,\n cursorPos: number\n ): {\n shouldShowAutocomplete: boolean;\n searchTerm: string;\n type: 'function' | 'cell' | 'all';\n insertPosition: number;\n } {\n // 如果不是公式,不显示\n if (!value.startsWith('=')) {\n return { shouldShowAutocomplete: false, searchTerm: '', type: 'all', insertPosition: 0 };\n }\n\n // 获取光标前的文本\n const textBeforeCursor = value.substring(1, cursorPos); // 去掉 '='\n\n // 查找最后一个函数或操作符\n const lastOperatorMatch = textBeforeCursor.match(/[\\+\\-\\*\\/\\(\\,\\s]([A-Za-z0-9]*)$/);\n\n if (lastOperatorMatch && lastOperatorMatch[1] !== '') {\n return {\n shouldShowAutocomplete: true,\n searchTerm: lastOperatorMatch[1],\n type: /^[A-Za-z]/.test(lastOperatorMatch[1]) ? 'function' : 'cell',\n insertPosition: cursorPos - lastOperatorMatch[1].length\n };\n }\n\n // 公式开始位置\n if (textBeforeCursor.match(/^[A-Za-z0-9]*$/)) {\n return {\n shouldShowAutocomplete: true,\n searchTerm: textBeforeCursor,\n type: 'all',\n insertPosition: 1\n };\n }\n\n return { shouldShowAutocomplete: false, searchTerm: '', type: 'all', insertPosition: 0 };\n }\n\n /**\n * 更新建议列表\n */\n private updateSuggestions(context: any): void {\n const { searchTerm, type } = context;\n this.items = [];\n\n // 获取函数列表\n if (type === 'function' || type === 'all') {\n const functions = this.sheet.formulaManager.getAvailableFunctions();\n const functionItems = functions\n .filter(fn => fn.toUpperCase().startsWith(searchTerm.toUpperCase()))\n .slice(0, 10) // 限制数量\n .map(fn => ({\n type: 'function' as const,\n value: fn,\n label: fn,\n description: this.getFunctionDescription(fn),\n signature: this.getFunctionSignature(fn)\n }));\n this.items.push(...functionItems);\n }\n\n // 添加单元格引用建议\n if (type === 'cell' || type === 'all') {\n const cellSuggestions = this.generateCellSuggestions(searchTerm);\n this.items.push(...cellSuggestions);\n }\n console.log('updateSuggestions', context, this.items);\n this.renderDropdown();\n }\n\n /**\n * 生成单元格引用建议\n */\n private generateCellSuggestions(searchTerm: string): AutocompleteItem[] {\n const suggestions: AutocompleteItem[] = [];\n\n // 如果是有效的部分单元格地址\n const cellMatch = searchTerm.match(/^([A-Za-z]*)([0-9]*)$/);\n if (cellMatch) {\n const [, colPart, rowPart] = cellMatch;\n\n // 生成列建议\n if (colPart && !rowPart) {\n // A -> A1, A2, A3...\n for (let row = 1; row <= 5; row++) {\n suggestions.push({\n type: 'cell',\n value: `${colPart.toUpperCase()}${row}`,\n label: `${colPart.toUpperCase()}${row}`,\n description: '单元格引用'\n });\n }\n }\n\n // 生成完整单元格建议\n if (colPart && rowPart) {\n const address = `${colPart.toUpperCase()}${rowPart}`;\n suggestions.push({\n type: 'cell',\n value: address,\n label: address,\n description: '单元格引用'\n });\n\n // 添加范围建议\n suggestions.push({\n type: 'range',\n value: `${address}:`,\n label: `${address}:...`,\n description: '开始选择范围'\n });\n }\n }\n\n return suggestions.slice(0, 5); // 限制建议数量\n }\n\n /**\n * 获取函数描述\n */\n private getFunctionDescription(functionName: string): string {\n const descriptions: Record<string, string> = {\n SUM: '计算数值总和',\n AVERAGE: '计算平均值',\n COUNT: '计数数值单元格',\n MAX: '返回最大值',\n MIN: '返回最小值',\n IF: '条件判断',\n VLOOKUP: '垂直查找',\n CONCATENATE: '连接文本'\n // ... 更多函数描述\n };\n return descriptions[functionName] || '';\n }\n\n /**\n * 获取函数签名\n */\n private getFunctionSignature(functionName: string): string {\n const signatures: Record<string, string> = {\n SUM: '(number1, [number2], ...)',\n AVERAGE: '(number1, [number2], ...)',\n COUNT: '(value1, [value2], ...)',\n MAX: '(number1, [number2], ...)',\n MIN: '(number1, [number2], ...)',\n IF: '(logical_test, value_if_true, value_if_false)',\n VLOOKUP: '(lookup_value, table_array, col_index_num, [range_lookup])',\n CONCATENATE: '(text1, [text2], ...)'\n // ... 更多函数签名\n };\n return signatures[functionName] || '()';\n }\n\n /**\n * 渲染下拉框\n */\n private renderDropdown(): void {\n if (!this.dropdown) {\n return;\n }\n\n this.dropdown.innerHTML = '';\n\n if (this.items.length === 0) {\n // 无结果提示\n const emptyEl = document.createElement('div');\n emptyEl.className = 'vtable-formula-autocomplete-empty';\n emptyEl.textContent = '没有匹配的函数';\n this.dropdown.appendChild(emptyEl);\n return;\n }\n\n // 按类型分组\n const groups = this.groupItems(this.items);\n\n groups.forEach(group => {\n // 添加分组标题\n if (groups.length > 1) {\n const groupEl = document.createElement('div');\n groupEl.className = 'vtable-formula-autocomplete-group';\n groupEl.textContent = this.getGroupTitle(group.type);\n this.dropdown.appendChild(groupEl);\n }\n\n // 渲染组内项目\n group.items.forEach((item, index) => {\n const globalIndex = this.items.indexOf(item);\n const itemEl = document.createElement('div');\n itemEl.className = 'vtable-formula-autocomplete-item';\n\n if (globalIndex === this.selectedIndex) {\n itemEl.classList.add('selected');\n }\n\n // 函数名和类型标签\n const nameEl = document.createElement('div');\n nameEl.className = 'item-name';\n\n const labelEl = document.createElement('span');\n labelEl.textContent = item.label;\n nameEl.appendChild(labelEl);\n\n const typeEl = document.createElement('span');\n typeEl.className = `item-type ${item.type}`;\n typeEl.textContent = this.getTypeLabel(item.type);\n nameEl.appendChild(typeEl);\n\n itemEl.appendChild(nameEl);\n\n // 函数签名\n if (item.signature) {\n const signatureEl = document.createElement('div');\n signatureEl.className = 'item-signature';\n signatureEl.textContent = item.signature;\n itemEl.appendChild(signatureEl);\n }\n\n // 描述\n if (item.description) {\n const descEl = document.createElement('div');\n descEl.className = 'item-description';\n descEl.textContent = item.description;\n itemEl.appendChild(descEl);\n }\n\n itemEl.addEventListener('click', () => this.selectItem(globalIndex));\n itemEl.addEventListener('mouseenter', () => {\n this.selectedIndex = globalIndex;\n this.renderDropdown();\n });\n\n this.dropdown.appendChild(itemEl);\n });\n });\n\n // 添加快捷键提示\n const footerEl = document.createElement('div');\n footerEl.className = 'vtable-formula-autocomplete-footer';\n footerEl.innerHTML = `\n <div class=\"shortcut\">\n <span class=\"key\">↑↓</span>\n <span>选择</span>\n </div>\n <div class=\"shortcut\">\n <span class=\"key\">Enter</span>\n <span>确认</span>\n </div>\n <div class=\"shortcut\">\n <span class=\"key\">Esc</span>\n <span>取消</span>\n </div>\n `;\n this.dropdown.appendChild(footerEl);\n\n this.positionDropdown();\n }\n\n /**\n * 对项目进行分组\n */\n private groupItems(items: AutocompleteItem[]): Array<{ type: string; items: AutocompleteItem[] }> {\n const groups: Record<string, AutocompleteItem[]> = {};\n\n items.forEach(item => {\n if (!groups[item.type]) {\n groups[item.type] = [];\n }\n groups[item.type].push(item);\n });\n\n // 按照优先级排序:function > cell > range\n const priority = ['function', 'cell', 'range'];\n return priority.filter(type => groups[type]).map(type => ({ type, items: groups[type] }));\n }\n\n /**\n * 获取分组标题\n */\n private getGroupTitle(type: string): string {\n const titles: Record<string, string> = {\n function: '函数',\n cell: '单元格',\n range: '范围'\n };\n return titles[type] || type;\n }\n\n /**\n * 获取类型标签\n */\n private getTypeLabel(type: string): string {\n const labels: Record<string, string> = {\n function: 'fx',\n cell: 'A1',\n range: 'A:B'\n };\n return labels[type] || type;\n }\n\n /**\n * 定位下拉框\n */\n private positionDropdown(): void {\n if (this.customPositioning) {\n this.customPositioning();\n return;\n }\n if (!this.dropdown || !this.inputElement) {\n return;\n }\n\n const inputRect = this.inputElement.getBoundingClientRect();\n const containerRect = this.container.getBoundingClientRect();\n\n this.dropdown.style.position = 'absolute';\n this.dropdown.style.left = `${inputRect.left - containerRect.left}px`;\n this.dropdown.style.top = `${inputRect.bottom - containerRect.top + 2}px`;\n this.dropdown.style.width = `${Math.max(300, inputRect.width)}px`;\n }\n\n /**\n * 处理键盘事件\n */\n private handleKeydown(event: KeyboardEvent): void {\n if (!this.isVisible) {\n return;\n }\n\n switch (event.key) {\n case 'ArrowDown':\n event.preventDefault();\n this.selectedIndex = Math.min(this.selectedIndex + 1, this.items.length - 1);\n this.renderDropdown();\n break;\n case 'ArrowUp':\n event.preventDefault();\n this.selectedIndex = Math.max(this.selectedIndex - 1, 0);\n this.renderDropdown();\n break;\n case 'Enter':\n if (this.selectedIndex >= 0) {\n event.preventDefault();\n this.selectItem(this.selectedIndex);\n }\n break;\n case 'Escape':\n this.hide();\n break;\n case 'Tab':\n if (this.selectedIndex >= 0) {\n event.preventDefault();\n this.selectItem(this.selectedIndex);\n }\n break;\n }\n }\n\n /**\n * 选择项目\n */\n private selectItem(index: number): void {\n const item = this.items[index];\n if (!item || !this.inputElement) {\n return;\n }\n\n if (this.onSelectCallback) {\n this.onSelectCallback(item);\n } else {\n // 默认插入行为\n const value = this.inputElement.value;\n const cursorPos = this.inputElement.selectionStart || 0;\n const context = this.parseInputContext(value, cursorPos);\n\n const newValue =\n value.substring(0, context.insertPosition) +\n item.value +\n (item.type === 'function' ? '(' : '') +\n value.substring(cursorPos);\n\n this.inputElement.value = newValue;\n\n // 设置光标位置\n const newCursorPos = context.insertPosition + item.value.length + (item.type === 'function' ? 1 : 0);\n this.inputElement.setSelectionRange(newCursorPos, newCursorPos);\n }\n\n this.hide();\n }\n\n /**\n * 显示下拉框\n */\n private show(): void {\n if (this.dropdown && this.items.length > 0) {\n this.dropdown.style.display = 'block';\n this.isVisible = true;\n this.selectedIndex = 0;\n this.renderDropdown();\n }\n }\n\n /**\n * 隐藏下拉框\n */\n private hide(): void {\n if (this.dropdown) {\n this.dropdown.style.display = 'none';\n this.isVisible = false;\n this.selectedIndex = -1;\n }\n }\n\n /**\n * 销毁组件\n */\n release(): void {\n if (this.dropdown && this.dropdown.parentNode) {\n this.dropdown.parentNode.removeChild(this.dropdown);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as VTable_editors from '@visactor/vtable-editors';
|
|
2
|
+
import type VTableSheet from '../components/vtable-sheet';
|
|
3
|
+
import type { EditContext } from '@visactor/vtable-editors';
|
|
4
|
+
export declare class FormulaInputEditor extends VTable_editors.InputEditor {
|
|
5
|
+
private formulaAutocomplete;
|
|
6
|
+
private sheet;
|
|
7
|
+
private eventHandlers;
|
|
8
|
+
setSheet(sheet: VTableSheet): void;
|
|
9
|
+
getInputElement(): HTMLElement;
|
|
10
|
+
targetIsOnEditor(target: HTMLElement): boolean;
|
|
11
|
+
createElement(): void;
|
|
12
|
+
private handleFormulaInput;
|
|
13
|
+
private initAutocomplete;
|
|
14
|
+
onStart(context: EditContext<string>): void;
|
|
15
|
+
beforeEnd(): void;
|
|
16
|
+
onEnd(): void;
|
|
17
|
+
getValue(): string;
|
|
18
|
+
validateValue(newValue?: any, oldValue?: any, position?: VTable_editors.CellAddress, table?: any, isClickOnTable?: boolean): boolean | VTable_editors.ValidateEnum;
|
|
19
|
+
private getCellRangeString;
|
|
20
|
+
}
|
|
21
|
+
export declare const formulaEditor: FormulaInputEditor;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import * as VTable_editors from "@visactor/vtable-editors";
|
|
2
|
+
|
|
3
|
+
import { FormulaAutocomplete } from "./formula-autocomplete";
|
|
4
|
+
|
|
5
|
+
import { detectFunctionParameterPosition } from "./formula-helper";
|
|
6
|
+
|
|
7
|
+
export class FormulaInputEditor extends VTable_editors.InputEditor {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments), this.formulaAutocomplete = null, this.sheet = null, this.eventHandlers = [];
|
|
10
|
+
}
|
|
11
|
+
setSheet(sheet) {
|
|
12
|
+
this.sheet = sheet;
|
|
13
|
+
}
|
|
14
|
+
getInputElement() {
|
|
15
|
+
return this.element;
|
|
16
|
+
}
|
|
17
|
+
targetIsOnEditor(target) {
|
|
18
|
+
return target === this.element || target === this.sheet.formulaUIManager.formulaInput;
|
|
19
|
+
}
|
|
20
|
+
createElement() {
|
|
21
|
+
if (super.createElement(), this.element && this.sheet) {
|
|
22
|
+
[ "click", "mouseup", "keyup", "select", "input", "focus" ].forEach((eventType => {
|
|
23
|
+
const handler = e => {
|
|
24
|
+
const cursorPos = this.element.selectionStart;
|
|
25
|
+
null != cursorPos && (this.sheet.formulaManager.lastKnownCursorPosInFormulaInput = cursorPos,
|
|
26
|
+
this.sheet.formulaManager.inputingElement = this.element);
|
|
27
|
+
};
|
|
28
|
+
this.element.addEventListener(eventType, handler), this.eventHandlers.push({
|
|
29
|
+
type: eventType,
|
|
30
|
+
handler: handler
|
|
31
|
+
});
|
|
32
|
+
}));
|
|
33
|
+
const inputHandler = e => {
|
|
34
|
+
this.handleFormulaInput(e);
|
|
35
|
+
};
|
|
36
|
+
this.element.addEventListener("input", inputHandler), this.eventHandlers.push({
|
|
37
|
+
type: "input",
|
|
38
|
+
handler: inputHandler
|
|
39
|
+
}), setTimeout((() => {
|
|
40
|
+
this.initAutocomplete();
|
|
41
|
+
}), 50);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
handleFormulaInput(event) {
|
|
45
|
+
if (!this.sheet || !this.element) return;
|
|
46
|
+
const value = this.element.value;
|
|
47
|
+
this.sheet.formulaUIManager.formulaInput.value = value;
|
|
48
|
+
const highlightManager = this.sheet.formulaManager.cellHighlightManager;
|
|
49
|
+
highlightManager && (value.startsWith("=") ? highlightManager.highlightFormulaCells(value) : highlightManager.clearHighlights());
|
|
50
|
+
}
|
|
51
|
+
initAutocomplete() {
|
|
52
|
+
if (!this.sheet || !this.element) return;
|
|
53
|
+
this.formulaAutocomplete && (this.formulaAutocomplete.release(), this.formulaAutocomplete = null);
|
|
54
|
+
const tableContainer = this.sheet.getContentElement();
|
|
55
|
+
this.formulaAutocomplete = new FormulaAutocomplete(tableContainer, this.sheet);
|
|
56
|
+
this.formulaAutocomplete.attachTo(this.element, void 0, (() => {
|
|
57
|
+
if (!this.formulaAutocomplete || !this.element) return;
|
|
58
|
+
const inputRect = this.element.getBoundingClientRect(), containerRect = tableContainer.getBoundingClientRect(), windowHeight = window.innerHeight, relativeLeft = inputRect.left - containerRect.left, idealWidth = Math.max(300, inputRect.width);
|
|
59
|
+
let relativeTop = inputRect.bottom - containerRect.top + 2;
|
|
60
|
+
const spaceBelow = windowHeight - inputRect.bottom, spaceAbove = inputRect.top;
|
|
61
|
+
spaceBelow < 250 && spaceAbove > spaceBelow && (relativeTop = inputRect.top - containerRect.top - 250 - 2);
|
|
62
|
+
const bottomOverflow = relativeTop + 250 - containerRect.height;
|
|
63
|
+
bottomOverflow > 0 && (relativeTop = Math.max(0, relativeTop - bottomOverflow)),
|
|
64
|
+
relativeTop < 0 && (relativeTop = 0);
|
|
65
|
+
const dropdown = this.formulaAutocomplete.dropdown;
|
|
66
|
+
dropdown && (dropdown.style.position = "absolute", dropdown.style.left = `${Math.max(0, relativeLeft)}px`,
|
|
67
|
+
dropdown.style.top = `${relativeTop}px`, dropdown.style.width = `${idealWidth}px`,
|
|
68
|
+
dropdown.style.maxHeight = "250px", dropdown.style.overflowY = "auto", dropdown.style.zIndex = "10000",
|
|
69
|
+
dropdown.style.boxShadow = "0 2px 8px rgba(0, 0, 0, 0.15)");
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
onStart(context) {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
const formula = this.sheet.formulaManager.getCellFormula({
|
|
75
|
+
sheet: (null === (_a = this.sheet.getActiveSheet()) || void 0 === _a ? void 0 : _a.getKey()) || "",
|
|
76
|
+
row: context.row,
|
|
77
|
+
col: context.col
|
|
78
|
+
});
|
|
79
|
+
if (formula && (context.value = formula), super.onStart(context), this.sheet.formulaManager.inputingElement = this.element,
|
|
80
|
+
this.sheet && "string" == typeof context.value) {
|
|
81
|
+
const formula = this.sheet.formulaManager.getCellFormula({
|
|
82
|
+
sheet: (null === (_b = this.sheet.getActiveSheet()) || void 0 === _b ? void 0 : _b.getKey()) || "",
|
|
83
|
+
row: context.row,
|
|
84
|
+
col: context.col
|
|
85
|
+
});
|
|
86
|
+
if (formula) {
|
|
87
|
+
this.setValue(formula);
|
|
88
|
+
const highlightManager = this.sheet.formulaManager.cellHighlightManager;
|
|
89
|
+
highlightManager && highlightManager.highlightFormulaCells(formula);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
beforeEnd() {
|
|
94
|
+
this.sheet.formulaManager.formulaWorkingOnCell = null;
|
|
95
|
+
}
|
|
96
|
+
onEnd() {
|
|
97
|
+
if (this.formulaAutocomplete && (this.formulaAutocomplete.release(), this.formulaAutocomplete = null),
|
|
98
|
+
this.sheet) {
|
|
99
|
+
const highlightManager = this.sheet.formulaManager.cellHighlightManager;
|
|
100
|
+
highlightManager && highlightManager.clearHighlights();
|
|
101
|
+
}
|
|
102
|
+
this.eventHandlers.forEach((({type: type, handler: handler}) => {
|
|
103
|
+
this.element.removeEventListener(type, handler);
|
|
104
|
+
})), super.onEnd();
|
|
105
|
+
}
|
|
106
|
+
getValue() {
|
|
107
|
+
var _a;
|
|
108
|
+
return (null === (_a = this.element) || void 0 === _a ? void 0 : _a.value) || "";
|
|
109
|
+
}
|
|
110
|
+
validateValue(newValue, oldValue, position, table, isClickOnTable) {
|
|
111
|
+
var _a;
|
|
112
|
+
if (isClickOnTable && newValue && newValue.startsWith("=")) {
|
|
113
|
+
if (this.sheet) {
|
|
114
|
+
const formulaInput = this.element;
|
|
115
|
+
return this.sheet.formulaManager.inputIsParamMode = detectFunctionParameterPosition(formulaInput.value, this.sheet.formulaManager.lastKnownCursorPosInFormulaInput),
|
|
116
|
+
this.sheet.formulaManager.inputIsParamMode.inParamMode ? (this.sheet.formulaManager.formulaWorkingOnCell = null === (_a = this.sheet.getActiveSheet()) || void 0 === _a ? void 0 : _a.editingCell,
|
|
117
|
+
VTable_editors.ValidateEnum.validateNotExit) : VTable_editors.ValidateEnum.validateExit;
|
|
118
|
+
}
|
|
119
|
+
if ((newValue.match(/\(/g) || []).length !== (newValue.match(/\)/g) || []).length) return VTable_editors.ValidateEnum.validateNotExit;
|
|
120
|
+
}
|
|
121
|
+
return !0;
|
|
122
|
+
}
|
|
123
|
+
getCellRangeString(range) {
|
|
124
|
+
if (!range || !range.start || !range.end) return "";
|
|
125
|
+
const colToLetter = col => {
|
|
126
|
+
let letter = "";
|
|
127
|
+
for (;col >= 0; ) letter = String.fromCharCode(65 + col % 26) + letter, col = Math.floor(col / 26) - 1;
|
|
128
|
+
return letter;
|
|
129
|
+
}, startCol = colToLetter(range.start.col), startRow = range.start.row + 1, endCol = colToLetter(range.end.col), endRow = range.end.row + 1;
|
|
130
|
+
return startCol === endCol && startRow === endRow ? `${startCol}${startRow}` : `${startCol}${startRow}:${endCol}${endRow}`;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export const formulaEditor = new FormulaInputEditor;
|
|
135
|
+
//# sourceMappingURL=formula-editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/formula/formula-editor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG7D,OAAO,EAAE,+BAA+B,EAAE,MAAM,kBAAkB,CAAC;AAEnE,MAAM,OAAO,kBAAmB,SAAQ,cAAc,CAAC,WAAW;IAAlE;;QACU,wBAAmB,GAA+B,IAAI,CAAC;QACvD,UAAK,GAAuB,IAAI,CAAC;QAEjC,kBAAa,GAAoD,EAAE,CAAC;IA6S9E,CAAC;IAzSC,QAAQ,CAAC,KAAkB;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IACD,eAAe;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,gBAAgB,CAAC,MAAmB;QAClC,OAAO,MAAM,KAAK,IAAI,CAAC,OAAO,IAAI,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC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I,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE;YACxC,OAAO,EAAE,CAAC;SACX;QAGD,MAAM,WAAW,GAAG,CAAC,GAAW,EAAU,EAAE;YAC1C,IAAI,MAAM,GAAG,EAAE,CAAC;YAChB,OAAO,GAAG,IAAI,CAAC,EAAE;gBACf,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;gBACvD,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;aAChC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;QAEF,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9C,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC;QACrC,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;QAGjC,IAAI,QAAQ,KAAK,MAAM,IAAI,QAAQ,KAAK,MAAM,EAAE;YAC9C,OAAO,GAAG,QAAQ,GAAG,QAAQ,EAAE,CAAC;SACjC;QAGD,OAAO,GAAG,QAAQ,GAAG,QAAQ,IAAI,MAAM,GAAG,MAAM,EAAE,CAAC;IACrD,CAAC;CACF;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,kBAAkB,EAAE,CAAC","file":"formula-editor.js","sourcesContent":["import * as VTable_editors from '@visactor/vtable-editors';\nimport { FormulaAutocomplete } from './formula-autocomplete';\nimport type VTableSheet from '../components/vtable-sheet';\nimport type { EditContext } from '@visactor/vtable-editors';\nimport { detectFunctionParameterPosition } from './formula-helper';\n\nexport class FormulaInputEditor extends VTable_editors.InputEditor {\n private formulaAutocomplete: FormulaAutocomplete | null = null;\n private sheet: VTableSheet | null = null;\n // 定义存储事件处理函数的数组\n private eventHandlers: Array<{ type: string; handler: EventListener }> = [];\n /**\n * 设置 Sheet 实例\n */\n setSheet(sheet: VTableSheet): void {\n this.sheet = sheet;\n }\n getInputElement(): HTMLElement {\n return this.element;\n }\n targetIsOnEditor(target: HTMLElement): boolean {\n return target === this.element || target === this.sheet.formulaUIManager.formulaInput;\n }\n /**\n * 创建编辑器元素\n * 重写父类方法以添加自动补全功能\n */\n createElement(): void {\n super.createElement();\n\n if (this.element && this.sheet) {\n const events = ['click', 'mouseup', 'keyup', 'select', 'input', 'focus'];\n events.forEach(eventType => {\n const handler = (e: Event) => {\n const cursorPos = this.element.selectionStart;\n if (cursorPos !== null && cursorPos !== undefined) {\n console.log(\n 'event',\n e,\n 'old',\n this.sheet.formulaManager.lastKnownCursorPosInFormulaInput,\n 'new',\n cursorPos\n );\n this.sheet.formulaManager.lastKnownCursorPosInFormulaInput = cursorPos;\n this.sheet.formulaManager.inputingElement = this.element;\n }\n };\n\n this.element.addEventListener(eventType, handler);\n this.eventHandlers.push({ type: eventType, handler });\n });\n\n // 添加输入事件监听\n const inputHandler = (e: Event) => {\n this.handleFormulaInput(e);\n };\n this.element.addEventListener('input', inputHandler);\n this.eventHandlers.push({ type: 'input', handler: inputHandler });\n\n // 延迟初始化自动补全\n setTimeout(() => {\n this.initAutocomplete();\n }, 50);\n }\n }\n\n /**\n * 处理公式输入\n */\n private handleFormulaInput(event: Event): void {\n if (!this.sheet || !this.element) {\n return;\n }\n\n const value = this.element.value;\n console.log('handleFormulaInput', value);\n // 同步内容到顶部输入栏\n this.sheet.formulaUIManager.formulaInput.value = value;\n // const inputEvent = new Event('input', { bubbles: true });\n // Object.defineProperty(inputEvent, 'isFormulaInsertion', { value: true });\n // this.sheet.formulaUIManager.formulaInput.dispatchEvent(inputEvent);\n // 获取高亮管理器\n const highlightManager = this.sheet.formulaManager.cellHighlightManager;\n\n if (highlightManager) {\n if (value.startsWith('=')) {\n highlightManager.highlightFormulaCells(value);\n } else {\n highlightManager.clearHighlights();\n }\n }\n }\n\n /**\n * 初始化自动补全\n */\n private initAutocomplete(): void {\n if (!this.sheet || !this.element) {\n return;\n }\n\n // 清理之前的实例\n if (this.formulaAutocomplete) {\n this.formulaAutocomplete.release();\n this.formulaAutocomplete = null;\n }\n\n const tableContainer = this.sheet.getContentElement();\n\n this.formulaAutocomplete = new FormulaAutocomplete(tableContainer, this.sheet);\n\n // 自定义定位逻辑\n const customPositioning = () => {\n if (!this.formulaAutocomplete || !this.element) {\n return;\n }\n\n // 获取编辑器元素和容器的位置信息\n const inputRect = this.element.getBoundingClientRect();\n const containerRect = tableContainer.getBoundingClientRect();\n const windowHeight = window.innerHeight;\n\n // 计算相对于表格容器的位置\n const relativeLeft = inputRect.left - containerRect.left;\n\n // 计算下拉框的最大高度和理想宽度\n const maxDropdownHeight = 250; // 最大高度限制\n const idealWidth = Math.max(300, inputRect.width); // 理想宽度\n\n // 计算下拉框在下方显示时的顶部位置\n let relativeTop = inputRect.bottom - containerRect.top + 2;\n\n // 检查是否有足够空间在下方显示下拉框\n const spaceBelow = windowHeight - inputRect.bottom;\n const spaceAbove = inputRect.top;\n\n // 判断应该将下拉框放在输入框的上方还是下方\n if (spaceBelow < maxDropdownHeight && spaceAbove > spaceBelow) {\n // 空间不足且上方空间更大,则放在上方\n relativeTop = inputRect.top - containerRect.top - maxDropdownHeight - 2;\n }\n\n // 确保下拉框不会超出容器底部\n const bottomOverflow = relativeTop + maxDropdownHeight - containerRect.height;\n if (bottomOverflow > 0) {\n relativeTop = Math.max(0, relativeTop - bottomOverflow);\n }\n\n // 确保下拉框不会超出容器顶部\n if (relativeTop < 0) {\n relativeTop = 0;\n }\n\n // 设置下拉框位置和样式\n const dropdown = (this.formulaAutocomplete as any).dropdown;\n if (dropdown) {\n dropdown.style.position = 'absolute';\n dropdown.style.left = `${Math.max(0, relativeLeft)}px`;\n dropdown.style.top = `${relativeTop}px`;\n dropdown.style.width = `${idealWidth}px`;\n dropdown.style.maxHeight = `${maxDropdownHeight}px`;\n dropdown.style.overflowY = 'auto';\n dropdown.style.zIndex = '10000';\n dropdown.style.boxShadow = '0 2px 8px rgba(0, 0, 0, 0.15)';\n }\n };\n\n // 附加自动补全到输入框\n this.formulaAutocomplete.attachTo(this.element, undefined, customPositioning);\n }\n\n /**\n * 开始编辑\n * 重写父类方法\n */\n onStart(context: EditContext<string>): void {\n // 获取公式\n const formula = this.sheet.formulaManager.getCellFormula({\n sheet: this.sheet.getActiveSheet()?.getKey() || '',\n row: context.row,\n col: context.col\n });\n if (formula) {\n context.value = formula;\n }\n super.onStart(context);\n this.sheet.formulaManager.inputingElement = this.element;\n // 如果是公式,显示公式而不是计算结果\n if (this.sheet && typeof context.value === 'string') {\n const formula = this.sheet.formulaManager.getCellFormula({\n sheet: this.sheet.getActiveSheet()?.getKey() || '',\n row: context.row,\n col: context.col\n });\n\n if (formula) {\n this.setValue(formula);\n // 触发高亮\n const highlightManager = this.sheet.formulaManager.cellHighlightManager;\n if (highlightManager) {\n highlightManager.highlightFormulaCells(formula);\n }\n }\n }\n }\n beforeEnd(): void {\n this.sheet.formulaManager.formulaWorkingOnCell = null;\n }\n /**\n * 结束编辑\n * 重写父类方法以清理自动补全\n */\n onEnd(): void {\n if (this.formulaAutocomplete) {\n this.formulaAutocomplete.release();\n this.formulaAutocomplete = null;\n }\n if (this.sheet) {\n const highlightManager = this.sheet.formulaManager.cellHighlightManager;\n if (highlightManager) {\n highlightManager.clearHighlights();\n }\n }\n //解绑所有事件\n // 解绑事件(在需要解绑的地方)\n this.eventHandlers.forEach(({ type, handler }) => {\n this.element.removeEventListener(type, handler);\n });\n super.onEnd();\n }\n\n /**\n * 获取编辑器的值\n */\n getValue(): string {\n return this.element?.value || '';\n }\n\n validateValue(\n newValue?: any,\n oldValue?: any,\n position?: VTable_editors.CellAddress,\n table?: any,\n isClickOnTable?: boolean\n ): boolean | VTable_editors.ValidateEnum {\n // 判断点击到表格其他单元格,且输入了公式,则检查公式是否完整\n if (isClickOnTable && newValue && newValue.startsWith('=')) {\n // 如果有sheet实例,使用FormulaManager检查公式完整性\n if (this.sheet) {\n const formulaInput = this.element;\n this.sheet.formulaManager.inputIsParamMode = detectFunctionParameterPosition(\n formulaInput.value,\n this.sheet.formulaManager.lastKnownCursorPosInFormulaInput\n );\n console.log('test formula complete', newValue, this.sheet.formulaManager.inputIsParamMode);\n if (this.sheet.formulaManager.inputIsParamMode.inParamMode) {\n // // 如果公式不完整,不退出编辑状态 TODO 这里不应该只判断完整性,如这种情况下按住ctrl连续点选 =SUM(H5) 这种情况应该允许继续编辑输入点选单元格范围\n // if (!formulaManager.isFormulaComplete(newValue)) {\n\n this.sheet.formulaManager.formulaWorkingOnCell = this.sheet.getActiveSheet()?.editingCell;\n\n return VTable_editors.ValidateEnum.validateNotExit;\n }\n return VTable_editors.ValidateEnum.validateExit;\n }\n // 如果没有sheet实例,使用简单的括号匹配检查\n const openParenCount = (newValue.match(/\\(/g) || []).length;\n const closeParenCount = (newValue.match(/\\)/g) || []).length;\n if (openParenCount !== closeParenCount) {\n return VTable_editors.ValidateEnum.validateNotExit;\n }\n }\n return true;\n }\n\n /**\n * 将选中的单元格范围转换为公式引用字符串\n * 例如:A1:B3\n */\n private getCellRangeString(range: {\n start: { col: number; row: number };\n end: { col: number; row: number };\n }): string {\n if (!range || !range.start || !range.end) {\n return '';\n }\n\n // 将列索引转换为字母表示(0->A, 1->B, 等)\n const colToLetter = (col: number): string => {\n let letter = '';\n while (col >= 0) {\n letter = String.fromCharCode(65 + (col % 26)) + letter;\n col = Math.floor(col / 26) - 1;\n }\n return letter;\n };\n\n const startCol = colToLetter(range.start.col);\n const startRow = range.start.row + 1; // 行索引从1开始\n const endCol = colToLetter(range.end.col);\n const endRow = range.end.row + 1;\n\n // 如果是单个单元格\n if (startCol === endCol && startRow === endRow) {\n return `${startCol}${startRow}`;\n }\n\n // 如果是范围\n return `${startCol}${startRow}:${endCol}${endRow}`;\n }\n}\n\nexport const formulaEditor = new FormulaInputEditor();\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export const supportedFunctions = [ "SUM", "AVERAGE", "MAX", "MIN", "COUNT", "COUNTA", "IF", "AND", "OR", "NOT", "ROUND", "FLOOR", "CEILING", "ABS", "SQRT", "POWER", "MOD", "INT", "RAND", "TODAY", "NOW", "YEAR", "MONTH", "DAY", "HOUR", "MINUTE", "SECOND" ];
|
|
2
|
+
|
|
3
|
+
function findMatchingCloseParen(formula, openParenIndex) {
|
|
4
|
+
let depth = 1;
|
|
5
|
+
for (let i = openParenIndex + 1; i < formula.length; i++) if ("(" === formula[i]) depth++; else if (")" === formula[i] && (depth--,
|
|
6
|
+
0 === depth)) return i;
|
|
7
|
+
return -1;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function detectFunctionParameterPosition(formula, cursorPosition) {
|
|
11
|
+
if (!formula.startsWith("=")) return {
|
|
12
|
+
inParamMode: !1,
|
|
13
|
+
functionParamPosition: null
|
|
14
|
+
};
|
|
15
|
+
const functionRegex = /([A-Za-z]+)\s*\(/g;
|
|
16
|
+
let match, positionBeforeCursor = -1;
|
|
17
|
+
for (;null !== (match = functionRegex.exec(formula)); ) {
|
|
18
|
+
match[1].toUpperCase();
|
|
19
|
+
const functionStart = match.index, openParenIndex = formula.indexOf("(", functionStart);
|
|
20
|
+
if (openParenIndex < cursorPosition && openParenIndex > positionBeforeCursor) {
|
|
21
|
+
const closeParenIndex = findMatchingCloseParen(formula, openParenIndex);
|
|
22
|
+
if (cursorPosition > openParenIndex && (-1 === closeParenIndex || cursorPosition <= closeParenIndex)) return {
|
|
23
|
+
inParamMode: !0,
|
|
24
|
+
functionParamPosition: {
|
|
25
|
+
start: openParenIndex + 1,
|
|
26
|
+
end: cursorPosition
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
if (cursorPosition === openParenIndex + 1) return {
|
|
30
|
+
inParamMode: !0,
|
|
31
|
+
functionParamPosition: {
|
|
32
|
+
start: openParenIndex + 1,
|
|
33
|
+
end: cursorPosition
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
positionBeforeCursor = openParenIndex;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (cursorPosition > 1 && cursorPosition <= formula.length) {
|
|
40
|
+
const prevChar = formula[cursorPosition - 1];
|
|
41
|
+
if ([ "+", "-", "*", "/", "=", ">", "<", "&", "|", "^", "(", "," ].includes(prevChar)) return {
|
|
42
|
+
inParamMode: !0,
|
|
43
|
+
functionParamPosition: {
|
|
44
|
+
start: cursorPosition,
|
|
45
|
+
end: cursorPosition
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return 1 === cursorPosition && "=" === formula[0] ? {
|
|
50
|
+
inParamMode: !0,
|
|
51
|
+
functionParamPosition: {
|
|
52
|
+
start: cursorPosition,
|
|
53
|
+
end: cursorPosition
|
|
54
|
+
}
|
|
55
|
+
} : {
|
|
56
|
+
inParamMode: !1,
|
|
57
|
+
functionParamPosition: null
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=formula-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/formula/formula-helper.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,KAAK;IACL,SAAS;IACT,KAAK;IACL,KAAK;IACL,OAAO;IACP,QAAQ;IACR,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,KAAK;IACL,OAAO;IACP,OAAO;IACP,SAAS;IACT,KAAK;IACL,MAAM;IACN,OAAO;IACP,KAAK;IACL,KAAK;IACL,MAAM;IACN,OAAO;IACP,KAAK;IACL,MAAM;IACN,OAAO;IACP,KAAK;IACL,MAAM;IACN,QAAQ;IACR,QAAQ;CACT,CAAC;AAQF,SAAS,sBAAsB,C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n 'SUM',\n 'AVERAGE',\n 'MAX',\n 'MIN',\n 'COUNT',\n 'COUNTA',\n 'IF',\n 'AND',\n 'OR',\n 'NOT',\n 'ROUND',\n 'FLOOR',\n 'CEILING',\n 'ABS',\n 'SQRT',\n 'POWER',\n 'MOD',\n 'INT',\n 'RAND',\n 'TODAY',\n 'NOW',\n 'YEAR',\n 'MONTH',\n 'DAY',\n 'HOUR',\n 'MINUTE',\n 'SECOND'\n];\n\n/**\n * 查找匹配的右括号\n * @param formula 公式内容\n * @param openParenIndex 左括号的位置\n * @returns 匹配的右括号位置,若未找到则返回-1\n */\nfunction findMatchingCloseParen(formula: string, openParenIndex: number): number {\n let depth = 1; // 括号深度计数\n\n for (let i = openParenIndex + 1; i < formula.length; i++) {\n if (formula[i] === '(') {\n depth++;\n } else if (formula[i] === ')') {\n depth--;\n if (depth === 0) {\n return i; // 找到匹配的右括号\n }\n }\n }\n\n return -1; // 未找到匹配的右括号\n}\n\n/**\n * 检测函数参数位置\n * @param formula 公式内容\n * @param cursorPosition 光标位置\n * @returns 是否在函数参数位置\n */\nexport function detectFunctionParameterPosition(\n formula: string,\n cursorPosition: number\n): {\n inParamMode: boolean;\n functionParamPosition: {\n start: number;\n end: number;\n } | null;\n} {\n // 基本检查\n if (!formula.startsWith('=')) {\n return {\n inParamMode: false,\n functionParamPosition: null\n };\n }\n\n // 1. 先检查是否在函数参数位置\n // 匹配所有函数调用模式:FUNCTION_NAME(\n const functionRegex = /([A-Za-z]+)\\s*\\(/g;\n let match;\n let positionBeforeCursor = -1;\n\n // 查找距离光标最近的左括号\n while ((match = functionRegex.exec(formula)) !== null) {\n const functionName = match[1].toUpperCase();\n const functionStart = match.index;\n const openParenIndex = formula.indexOf('(', functionStart);\n\n // 如果光标在函数名之后,且这个函数比之前找到的更接近光标\n if (openParenIndex < cursorPosition && openParenIndex > positionBeforeCursor) {\n // 查找对应的右括号位置\n const closeParenIndex = findMatchingCloseParen(formula, openParenIndex);\n\n // 检查光标是否在函数参数位置(在左括号之后且在右括号之前或没有找到右括号)\n if (cursorPosition > openParenIndex && (closeParenIndex === -1 || cursorPosition <= closeParenIndex)) {\n return {\n inParamMode: true,\n functionParamPosition: {\n start: openParenIndex + 1,\n end: cursorPosition\n }\n };\n }\n\n // 如果光标正好在括号后面,也认为是参数位置\n if (cursorPosition === openParenIndex + 1) {\n return {\n inParamMode: true,\n functionParamPosition: {\n start: openParenIndex + 1,\n end: cursorPosition\n }\n };\n }\n\n // 记录这个左括号位置,用于比较\n positionBeforeCursor = openParenIndex;\n }\n }\n\n // 2. 检查是否在操作符后面 - 也将此视为函数参数模式\n if (cursorPosition > 1 && cursorPosition <= formula.length) {\n const prevChar = formula[cursorPosition - 1];\n if (['+', '-', '*', '/', '=', '>', '<', '&', '|', '^', '(', ','].includes(prevChar)) {\n return {\n inParamMode: true,\n functionParamPosition: {\n start: cursorPosition,\n end: cursorPosition\n }\n };\n }\n }\n\n // 3. 检查是否在公式开始位置 - 公式开始后也视为可能需要函数输入\n if (cursorPosition === 1 && formula[0] === '=') {\n return {\n inParamMode: true,\n functionParamPosition: {\n start: cursorPosition,\n end: cursorPosition\n }\n };\n }\n\n // 默认情况,不在任何特殊位置\n return {\n inParamMode: false,\n functionParamPosition: null\n };\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FormulaManager } from '../managers/formula-manager';
|
|
2
|
+
import type { CellRange, CellValueChangedEvent } from '../ts-types';
|
|
3
|
+
export interface FunctionParamPosition {
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class FormulaRangeSelector {
|
|
8
|
+
private formulaManager;
|
|
9
|
+
constructor(formulaManager: FormulaManager);
|
|
10
|
+
selectionsToA1Notation(selections: any[], addressFromCoord: (row: number, col: number) => string): string;
|
|
11
|
+
insertA1ReferenceInFunction(formulaInput: HTMLInputElement, a1Notation: string, isCtrlAddSelection: boolean): void;
|
|
12
|
+
private findCurrentArgumentPosition;
|
|
13
|
+
handleSelectionChanged(selections: CellRange[], formulaInput: HTMLInputElement, isCtrlAddSelection: boolean, addressFromCoord: (row: number, col: number) => string): void;
|
|
14
|
+
handleCellValueChanged(event: CellValueChangedEvent): void;
|
|
15
|
+
handleSelectionChangedForRangeMode(event: any): void;
|
|
16
|
+
private hasFormulaDependents;
|
|
17
|
+
private ensureCursorVisible;
|
|
18
|
+
release(): void;
|
|
19
|
+
}
|