@veltra/sheet 2.0.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/report/binding-badge.js +76 -0
- package/dist/components/report/designer/cell-coords.js +46 -0
- package/dist/components/report/designer/col-widths.js +15 -0
- package/dist/components/report/designer/conditional-rules/helpers.js +139 -0
- package/dist/components/report/designer/drop-highlight-overlay.js +76 -0
- package/dist/components/report/designer/float-panel.js +385 -0
- package/dist/components/report/designer/role.js +17 -0
- package/dist/components/report/designer/rule-preview.js +33 -0
- package/dist/components/report/designer/rule-row.js +269 -0
- package/dist/components/report/designer/rules-dialog.js +135 -0
- package/dist/components/report/designer/topology-overlay.js +122 -0
- package/dist/components/report/designer/topology.js +64 -0
- package/dist/components/report/designer/use-grid-overlay.js +75 -0
- package/dist/components/report/designer-hub.js +177 -0
- package/dist/components/report/field-panel-helpers.js +33 -0
- package/dist/components/report/field-panel.js +132 -0
- package/dist/components/report/filter-bar.js +74 -0
- package/dist/components/report/hub-connection-form.js +145 -0
- package/dist/components/report/hub-dataset-editor.js +394 -0
- package/dist/components/report/report-designer.js +343 -0
- package/dist/components/report/report-viewer.js +111 -0
- package/dist/components/report/style.d.ts +17 -0
- package/dist/components/report/style.js +18 -0
- package/dist/components/report/style2.css +869 -0
- package/dist/components/report/use-report-designer.js +360 -0
- package/dist/components/report/use-report-viewer.js +50 -0
- package/dist/components/sheet/formula-bar.js +393 -0
- package/dist/components/sheet/formula-suggest-list.js +66 -0
- package/dist/components/sheet/import-file.js +140 -0
- package/dist/components/sheet/insert-count-menu-item.js +68 -0
- package/dist/components/sheet/insert-image.js +79 -0
- package/dist/components/sheet/popup-helpers.js +73 -0
- package/dist/components/sheet/popups/border-popup.js +75 -0
- package/dist/components/sheet/popups/border-preset-glyph.js +106 -0
- package/dist/components/sheet/popups/export-popup.js +51 -0
- package/dist/components/sheet/popups/fill-color-popup.js +37 -0
- package/dist/components/sheet/popups/find-popup.js +113 -0
- package/dist/components/sheet/popups/font-color-popup.js +37 -0
- package/dist/components/sheet/popups/font-size-popup.js +63 -0
- package/dist/components/sheet/popups/import.worker.d.ts +21 -0
- package/dist/components/sheet/popups/import.worker.js +41 -0
- package/dist/components/sheet/popups/insert-image-popup.js +38 -0
- package/dist/components/sheet/sheet-context-menu.js +200 -0
- package/dist/components/sheet/sheet-tabs.js +162 -0
- package/dist/components/sheet/sheet-toolbar.js +106 -0
- package/dist/components/sheet/sheet.js +198 -0
- package/dist/components/sheet/style.d.ts +11 -0
- package/dist/components/sheet/style.js +12 -0
- package/dist/components/sheet/style2.css +654 -0
- package/dist/components/sheet/use-find-replace.js +161 -0
- package/dist/components/sheet/use-formula-ref-select.js +37 -0
- package/dist/components/sheet/use-formula-suggest.js +126 -0
- package/dist/components/sheet/use-sheet-grid.js +188 -0
- package/dist/components/sheet/use-sheet-state.js +122 -0
- package/dist/components/sheet/use-sheet-tabs-bar.js +90 -0
- package/dist/components/sheet/use-tool-groups.js +42 -0
- package/dist/components/sheet/use-tool-popup.js +123 -0
- package/dist/components/sheet/use-toolbar-scroll.js +72 -0
- package/dist/index.d.ts +18 -26
- package/dist/index.js +14 -24
- package/dist/report/binding.d.ts +45 -0
- package/dist/report/binding.js +175 -0
- package/dist/report/connector.d.ts +66 -0
- package/dist/report/connector.js +159 -0
- package/dist/report/export-xlsx.d.ts +19 -0
- package/dist/report/export-xlsx.js +95 -0
- package/dist/report/filter-bar.d.ts +10 -0
- package/dist/report/filter-bar.js +31 -0
- package/dist/report/index.d.ts +12 -0
- package/dist/report/params.d.ts +13 -0
- package/dist/report/params.js +61 -0
- package/dist/report/render/aggregate.js +157 -0
- package/dist/report/render/builder.d.ts +12 -0
- package/dist/report/render/builder.js +139 -0
- package/dist/report/render/coordinate.d.ts +25 -0
- package/dist/report/render/coordinate.js +733 -0
- package/dist/report/render/index.d.ts +14 -0
- package/dist/report/render/index.js +21 -0
- package/dist/report/render/style-resolver.js +50 -0
- package/dist/report/render/template-index.d.ts +24 -0
- package/dist/report/render/template-index.js +137 -0
- package/dist/report/rules/evaluate.d.ts +25 -0
- package/dist/report/rules/evaluate.js +82 -0
- package/dist/report/rules/index.d.ts +2 -0
- package/dist/report/template.d.ts +59 -0
- package/dist/report/template.js +80 -0
- package/dist/report/types.d.ts +85 -0
- package/dist/tools/builtin.js +279 -8
- package/dist/tools/context.d.ts +54 -11
- package/dist/tools/context.js +28 -5
- package/dist/tools/download.js +68 -0
- package/dist/tools/export.worker.d.ts +16 -0
- package/dist/tools/export.worker.js +29 -0
- package/dist/tools/registry.d.ts +7 -4
- package/dist/tools/registry.js +1 -3
- package/dist/types/index.d.ts +3 -1
- package/dist/types/report-designer.d.ts +36 -0
- package/dist/types/report-viewer.d.ts +38 -0
- package/dist/types/sheet.d.ts +22 -5
- package/package.json +10 -7
- package/src/components/report/__test__/conditional-rules-helpers.test.ts +87 -0
- package/src/components/report/__test__/field-panel-helpers.test.ts +65 -0
- package/src/components/report/__test__/float-panel-position.test.ts +45 -0
- package/src/components/report/__test__/report-designer.test.ts +388 -0
- package/src/components/report/__test__/report-viewer.test.ts +334 -0
- package/src/components/report/__test__/topology.test.ts +143 -0
- package/src/components/report/__test__/use-report-designer.test.ts +565 -0
- package/src/components/report/binding-badge.ts +73 -0
- package/src/components/report/designer/cell-coords.ts +94 -0
- package/src/components/report/designer/col-widths.ts +33 -0
- package/src/components/report/designer/conditional-rules/helpers.ts +186 -0
- package/src/components/report/designer/drop-highlight-overlay.vue +74 -0
- package/src/components/report/designer/float-panel.vue +387 -0
- package/src/components/report/designer/role.ts +32 -0
- package/src/components/report/designer/rule-preview.vue +40 -0
- package/src/components/report/designer/rule-row.vue +252 -0
- package/src/components/report/designer/rules-dialog.vue +126 -0
- package/src/components/report/designer/topology-overlay.vue +127 -0
- package/src/components/report/designer/topology.ts +124 -0
- package/src/components/report/designer/use-grid-overlay.ts +113 -0
- package/src/components/report/designer-hub.vue +198 -0
- package/src/components/report/field-panel-helpers.ts +44 -0
- package/src/components/report/field-panel.vue +136 -0
- package/src/components/report/filter-bar.vue +77 -0
- package/src/components/report/hub-connection-form.vue +124 -0
- package/src/components/report/hub-dataset-editor.vue +369 -0
- package/src/components/report/index.ts +2 -0
- package/src/components/report/report-designer.vue +356 -0
- package/src/components/report/report-viewer.vue +128 -0
- package/src/components/report/style-designer.scss +583 -0
- package/src/components/report/style-hub.scss +292 -0
- package/src/components/report/style-viewer.scss +104 -0
- package/src/components/report/style.scss +3 -0
- package/src/components/report/style.ts +20 -0
- package/src/components/report/use-report-designer.ts +547 -0
- package/src/components/report/use-report-viewer.ts +79 -0
- package/src/components/sheet/__test__/formula-bar.test.ts +474 -0
- package/src/components/sheet/__test__/import-file.test.ts +183 -0
- package/src/components/sheet/__test__/insert-count-menu-item.test.ts +123 -0
- package/src/components/sheet/__test__/insert-image-popup.test.ts +89 -0
- package/src/components/sheet/__test__/insert-image.test.ts +100 -0
- package/src/components/sheet/__test__/sheet-component.test.ts +993 -0
- package/src/components/sheet/__test__/sheet-context-menu.test.ts +206 -0
- package/src/components/sheet/__test__/use-formula-ref-select.test.ts +35 -0
- package/src/components/sheet/__test__/use-formula-suggest.test.ts +83 -0
- package/src/components/sheet/formula-bar.vue +473 -0
- package/src/components/sheet/formula-suggest-list.vue +64 -0
- package/src/components/sheet/import-file.ts +173 -0
- package/src/components/sheet/insert-count-menu-item.vue +69 -0
- package/src/components/sheet/insert-image.ts +90 -0
- package/src/components/sheet/parsing.ts +11 -0
- package/src/components/sheet/popup-helpers.ts +50 -0
- package/src/components/sheet/popups/border-popup.vue +93 -0
- package/src/components/sheet/popups/border-preset-glyph.vue +111 -0
- package/src/components/sheet/popups/export-popup.vue +52 -0
- package/src/components/sheet/popups/fill-color-popup.vue +39 -0
- package/src/components/sheet/popups/find-popup.vue +111 -0
- package/src/components/sheet/popups/font-color-popup.vue +39 -0
- package/src/components/sheet/popups/font-size-popup.vue +52 -0
- package/src/components/sheet/popups/import.worker.ts +66 -0
- package/src/components/sheet/popups/insert-image-popup.vue +39 -0
- package/src/components/sheet/sheet-context-menu.ts +229 -0
- package/src/components/sheet/sheet-tabs.vue +162 -0
- package/src/components/sheet/sheet-toolbar.vue +91 -0
- package/src/components/sheet/sheet.vue +211 -0
- package/src/components/sheet/style.scss +737 -0
- package/src/components/sheet/style.ts +13 -0
- package/src/components/sheet/use-find-replace.ts +200 -0
- package/src/components/sheet/use-formula-ref-select.ts +34 -0
- package/src/components/sheet/use-formula-suggest.ts +150 -0
- package/src/components/sheet/use-sheet-grid.ts +247 -0
- package/src/components/sheet/use-sheet-state.ts +161 -0
- package/src/components/sheet/use-sheet-tabs-bar.ts +115 -0
- package/src/components/sheet/use-tool-groups.ts +61 -0
- package/src/components/sheet/use-tool-popup.ts +150 -0
- package/src/components/sheet/use-toolbar-scroll.ts +95 -0
- package/src/env.d.ts +11 -0
- package/src/index.ts +39 -14
- package/src/report/__test__/binding.test.ts +218 -0
- package/src/report/__test__/connector.test.ts +218 -0
- package/src/report/__test__/export-xlsx.test.ts +118 -0
- package/src/report/__test__/filter-bar.test.ts +58 -0
- package/src/report/__test__/params.test.ts +156 -0
- package/src/report/__test__/render.test.ts +728 -0
- package/src/report/__test__/rules.test.ts +131 -0
- package/src/report/__test__/template.test.ts +355 -0
- package/src/report/binding.ts +243 -0
- package/src/report/connector.ts +205 -0
- package/src/report/export-xlsx.ts +118 -0
- package/src/report/filter-bar.ts +36 -0
- package/src/report/index.ts +13 -0
- package/src/report/params.ts +96 -0
- package/src/report/render/__test__/aggregate.test.ts +16 -0
- package/src/report/render/__test__/coordinate.test.ts +405 -0
- package/src/report/render/aggregate.ts +240 -0
- package/src/report/render/builder.ts +211 -0
- package/src/report/render/coordinate.ts +1239 -0
- package/src/report/render/index.ts +30 -0
- package/src/report/render/style-resolver.ts +68 -0
- package/src/report/render/template-index.ts +200 -0
- package/src/report/rules/evaluate.ts +113 -0
- package/src/report/rules/index.ts +7 -0
- package/src/report/template.ts +141 -0
- package/src/report/types.ts +96 -0
- package/src/tools/__test__/builtin.test.ts +208 -66
- package/src/tools/__test__/context.test.ts +62 -2
- package/src/tools/builtin.ts +350 -6
- package/src/tools/context.ts +89 -11
- package/src/tools/download.ts +82 -0
- package/src/tools/export.worker.ts +61 -0
- package/src/tools/registry.ts +16 -1
- package/src/types/index.ts +2 -0
- package/src/types/report-designer.ts +36 -0
- package/src/types/report-viewer.ts +37 -0
- package/src/types/sheet.ts +26 -3
- package/dist/core/address.d.ts +0 -60
- package/dist/core/address.js +0 -142
- package/dist/core/address.js.map +0 -1
- package/dist/core/cell-store.d.ts +0 -61
- package/dist/core/cell-store.js +0 -135
- package/dist/core/cell-store.js.map +0 -1
- package/dist/core/command/default-registry.d.ts +0 -10
- package/dist/core/command/default-registry.js +0 -18
- package/dist/core/command/default-registry.js.map +0 -1
- package/dist/core/command/history.d.ts +0 -64
- package/dist/core/command/history.js +0 -127
- package/dist/core/command/history.js.map +0 -1
- package/dist/core/command/merge-cells.d.ts +0 -21
- package/dist/core/command/merge-cells.js +0 -74
- package/dist/core/command/merge-cells.js.map +0 -1
- package/dist/core/command/registry.d.ts +0 -17
- package/dist/core/command/registry.js +0 -26
- package/dist/core/command/registry.js.map +0 -1
- package/dist/core/command/set-cell-formula.d.ts +0 -17
- package/dist/core/command/set-cell-formula.js +0 -29
- package/dist/core/command/set-cell-formula.js.map +0 -1
- package/dist/core/command/set-cell-value.d.ts +0 -22
- package/dist/core/command/set-cell-value.js +0 -35
- package/dist/core/command/set-cell-value.js.map +0 -1
- package/dist/core/command/types.d.ts +0 -68
- package/dist/core/events.js +0 -29
- package/dist/core/events.js.map +0 -1
- package/dist/core/fill.d.ts +0 -34
- package/dist/core/fill.js +0 -320
- package/dist/core/fill.js.map +0 -1
- package/dist/core/formula/ast.d.ts +0 -58
- package/dist/core/formula/ast.js +0 -38
- package/dist/core/formula/ast.js.map +0 -1
- package/dist/core/formula/dependency-graph.d.ts +0 -70
- package/dist/core/formula/dependency-graph.js +0 -269
- package/dist/core/formula/dependency-graph.js.map +0 -1
- package/dist/core/formula/errors.d.ts +0 -25
- package/dist/core/formula/errors.js +0 -36
- package/dist/core/formula/errors.js.map +0 -1
- package/dist/core/formula/evaluator.d.ts +0 -41
- package/dist/core/formula/evaluator.js +0 -154
- package/dist/core/formula/evaluator.js.map +0 -1
- package/dist/core/formula/functions.d.ts +0 -30
- package/dist/core/formula/functions.js +0 -209
- package/dist/core/formula/functions.js.map +0 -1
- package/dist/core/formula/parser.d.ts +0 -7
- package/dist/core/formula/parser.js +0 -208
- package/dist/core/formula/parser.js.map +0 -1
- package/dist/core/formula/tokenizer.d.ts +0 -37
- package/dist/core/formula/tokenizer.js +0 -146
- package/dist/core/formula/tokenizer.js.map +0 -1
- package/dist/core/merge-manager.d.ts +0 -64
- package/dist/core/merge-manager.js +0 -111
- package/dist/core/merge-manager.js.map +0 -1
- package/dist/core/selection.d.ts +0 -31
- package/dist/core/selection.js +0 -62
- package/dist/core/selection.js.map +0 -1
- package/dist/core/sheet.d.ts +0 -116
- package/dist/core/sheet.js +0 -224
- package/dist/core/sheet.js.map +0 -1
- package/dist/core/workbook.d.ts +0 -43
- package/dist/core/workbook.js +0 -77
- package/dist/core/workbook.js.map +0 -1
- package/dist/grid/sheet-grid.d.ts +0 -81
- package/dist/grid/sheet-grid.js +0 -331
- package/dist/grid/sheet-grid.js.map +0 -1
- package/dist/grid/vtable-theme.js +0 -80
- package/dist/grid/vtable-theme.js.map +0 -1
- package/dist/tools/builtin.js.map +0 -1
- package/dist/tools/context.js.map +0 -1
- package/dist/tools/registry.js.map +0 -1
- package/dist/vue/index.d.ts +0 -2
- package/dist/vue/sheet.js +0 -211
- package/dist/vue/sheet.js.map +0 -1
- package/dist/vue/sheet.vue.d.ts +0 -24
- package/dist/vue/style.d.ts +0 -1
- package/dist/vue/style.js +0 -2
- package/dist/vue/style2.css +0 -93
- package/src/core/__test__/address.test.ts +0 -113
- package/src/core/__test__/cell-store.test.ts +0 -97
- package/src/core/__test__/command.test.ts +0 -377
- package/src/core/__test__/fill.test.ts +0 -140
- package/src/core/__test__/formula-adversarial.test.ts +0 -265
- package/src/core/__test__/formula-engine.test.ts +0 -470
- package/src/core/__test__/formula-functions.test.ts +0 -178
- package/src/core/__test__/formula-parser.test.ts +0 -160
- package/src/core/__test__/history.test.ts +0 -225
- package/src/core/__test__/merge-manager.test.ts +0 -106
- package/src/core/__test__/sheet.test.ts +0 -142
- package/src/core/address.ts +0 -166
- package/src/core/cell-store.ts +0 -173
- package/src/core/command/default-registry.ts +0 -15
- package/src/core/command/history.ts +0 -167
- package/src/core/command/index.ts +0 -7
- package/src/core/command/merge-cells.ts +0 -74
- package/src/core/command/registry.ts +0 -30
- package/src/core/command/set-cell-formula.ts +0 -29
- package/src/core/command/set-cell-value.ts +0 -38
- package/src/core/command/types.ts +0 -73
- package/src/core/events.ts +0 -37
- package/src/core/fill.ts +0 -314
- package/src/core/formula/ast.ts +0 -66
- package/src/core/formula/dependency-graph.ts +0 -329
- package/src/core/formula/errors.ts +0 -41
- package/src/core/formula/evaluator.ts +0 -219
- package/src/core/formula/functions.ts +0 -266
- package/src/core/formula/index.ts +0 -7
- package/src/core/formula/parser.ts +0 -198
- package/src/core/formula/tokenizer.ts +0 -160
- package/src/core/merge-manager.ts +0 -158
- package/src/core/selection.ts +0 -66
- package/src/core/sheet.ts +0 -282
- package/src/core/workbook.ts +0 -99
- package/src/grid/__test__/canvas-mock.ts +0 -49
- package/src/grid/__test__/setup.ts +0 -3
- package/src/grid/__test__/sheet-grid-formula.test.ts +0 -140
- package/src/grid/__test__/sheet-grid.test.ts +0 -275
- package/src/grid/sheet-grid.ts +0 -407
- package/src/grid/vtable-theme.ts +0 -61
- package/src/vue/__test__/sheet-component.test.ts +0 -267
- package/src/vue/sheet.vue +0 -235
- package/src/vue/style.scss +0 -94
- package/src/vue/style.ts +0 -2
- /package/src/{vue → components/sheet}/index.ts +0 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import _sfc_main$1 from "./formula-suggest-list.js";
|
|
2
|
+
import { insertRefText, isRefSelectContext } from "./use-formula-ref-select.js";
|
|
3
|
+
import { applySuggest, filterFormulaSuggestions, getSuggestContext, moveSuggestIndex } from "./use-formula-suggest.js";
|
|
4
|
+
import { formatAddress, formatRange, parseRange } from "@veltra/sheet-core/core/address";
|
|
5
|
+
import { computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, nextTick, normalizeClass, onBeforeUnmount, onMounted, openBlock, ref, shallowRef, unref, useTemplateRef, vModelText, watch, withDirectives, withModifiers } from "vue";
|
|
6
|
+
import { message } from "@veltra/desktop";
|
|
7
|
+
import { bem } from "@veltra/utils";
|
|
8
|
+
//#region src/components/sheet/formula-bar.vue
|
|
9
|
+
const _hoisted_1 = ["disabled", "readonly"];
|
|
10
|
+
const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
11
|
+
name: "UFormulaBar",
|
|
12
|
+
__name: "formula-bar",
|
|
13
|
+
props: {
|
|
14
|
+
sheet: {},
|
|
15
|
+
context: {}
|
|
16
|
+
},
|
|
17
|
+
setup(__props, { expose: __expose }) {
|
|
18
|
+
/**
|
|
19
|
+
* 公式栏(名称框 + fx 输入栏),USheet 顶部结构之一。
|
|
20
|
+
*
|
|
21
|
+
* - 名称框:显示当前选区(单格 A1 / 区域 A1:B2);合法地址回车跳转。
|
|
22
|
+
* - fx 输入栏:活动格内容;Enter/✓ 提交、Esc/✗ 取消、失焦提交。
|
|
23
|
+
* - 函数补全:`=` 开头且光标在函数名 token 上时弹出候选(↑↓ / Tab / Enter / 点击)。
|
|
24
|
+
* - 引用选择:光标在运算符/`(`/`,` 后时,画布点选/拖选插入引用(blur 抑制防误提交)。
|
|
25
|
+
* - 网格编辑镜像:只读显示网格编辑器文本。
|
|
26
|
+
*/
|
|
27
|
+
const props = __props;
|
|
28
|
+
const cls = bem("sheet");
|
|
29
|
+
const fxRef = useTemplateRef("fxRef");
|
|
30
|
+
const selection = shallowRef({
|
|
31
|
+
activeCell: null,
|
|
32
|
+
ranges: []
|
|
33
|
+
});
|
|
34
|
+
const nameDraft = ref("");
|
|
35
|
+
const nameFocused = ref(false);
|
|
36
|
+
const editing = ref(false);
|
|
37
|
+
let editAddr = null;
|
|
38
|
+
const mirroring = ref(false);
|
|
39
|
+
let mirrorAddr = null;
|
|
40
|
+
const fxDraft = ref("");
|
|
41
|
+
/** 输入面板是否因内容增高而浮出(文档流仍保持单行) */
|
|
42
|
+
const fxExpanded = ref(false);
|
|
43
|
+
/** textarea 光标(selectionStart);输入/点击/方向键后同步 */
|
|
44
|
+
const fxCursor = ref(0);
|
|
45
|
+
/** 画布 pointerdown 置位:下一帧 blur 跳过提交(引用选择模式) */
|
|
46
|
+
let suppressBlurCommit = false;
|
|
47
|
+
const suggestItems = shallowRef([]);
|
|
48
|
+
const suggestIndex = ref(0);
|
|
49
|
+
const suggestOpen = computed(() => suggestItems.value.length > 0);
|
|
50
|
+
const fxDisabled = computed(() => selection.value.activeCell == null);
|
|
51
|
+
/** 编排层查询:fx 编辑中且光标处于可插入引用位置 */
|
|
52
|
+
function isRefSelecting() {
|
|
53
|
+
return editing.value && !mirroring.value && isRefSelectContext(fxDraft.value, fxCursor.value);
|
|
54
|
+
}
|
|
55
|
+
/** 网格 pointerdown(capture)→ 挂起即将到来的 blur 提交 */
|
|
56
|
+
function beginBlurSuppress() {
|
|
57
|
+
if (!isRefSelecting()) return;
|
|
58
|
+
suppressBlurCommit = true;
|
|
59
|
+
}
|
|
60
|
+
/** 选区拦截回调:插入 A1 / A1:B2 到光标处 */
|
|
61
|
+
function handleRefSelect(range) {
|
|
62
|
+
if (!editing.value || mirroring.value) return;
|
|
63
|
+
const rangeText = formatRange(range);
|
|
64
|
+
const selEnd = fxRef.value?.selectionEnd ?? fxCursor.value;
|
|
65
|
+
const result = insertRefText(fxDraft.value, fxCursor.value, rangeText, selEnd);
|
|
66
|
+
fxDraft.value = result.text;
|
|
67
|
+
fxCursor.value = result.cursor;
|
|
68
|
+
closeSuggest();
|
|
69
|
+
nextTick(() => {
|
|
70
|
+
const input = fxRef.value;
|
|
71
|
+
if (!input) return;
|
|
72
|
+
input.focus();
|
|
73
|
+
input.setSelectionRange(result.cursor, result.cursor);
|
|
74
|
+
autosizeFx();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function nameText(state) {
|
|
78
|
+
const range = state.ranges[0];
|
|
79
|
+
if (range) return formatRange(range);
|
|
80
|
+
return state.activeCell ? formatAddress(state.activeCell) : "";
|
|
81
|
+
}
|
|
82
|
+
function cellText(addr) {
|
|
83
|
+
const data = props.context.getCellData(addr);
|
|
84
|
+
if (data?.f != null) return `=${data.f}`;
|
|
85
|
+
if (data?.v != null) return String(data.v);
|
|
86
|
+
return "";
|
|
87
|
+
}
|
|
88
|
+
function refreshName() {
|
|
89
|
+
nameDraft.value = nameText(selection.value);
|
|
90
|
+
}
|
|
91
|
+
function refreshFx() {
|
|
92
|
+
const active = selection.value.activeCell;
|
|
93
|
+
fxDraft.value = active ? cellText(active) : "";
|
|
94
|
+
fxCursor.value = fxDraft.value.length;
|
|
95
|
+
closeSuggest();
|
|
96
|
+
scheduleAutosize();
|
|
97
|
+
}
|
|
98
|
+
/** 每帧合并一次的 autosizeFx(批量 cell-change 同帧 N 次 nextTick → 1 次强制布局) */
|
|
99
|
+
let autosizePending = false;
|
|
100
|
+
function scheduleAutosize() {
|
|
101
|
+
if (autosizePending) return;
|
|
102
|
+
autosizePending = true;
|
|
103
|
+
nextTick(() => {
|
|
104
|
+
autosizePending = false;
|
|
105
|
+
autosizeFx();
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 按内容增高浮出面板,不超过 CSS max-height。
|
|
110
|
+
* 增高走绝对定位,公式栏文档流高度始终单行。
|
|
111
|
+
*/
|
|
112
|
+
function autosizeFx() {
|
|
113
|
+
const el = fxRef.value;
|
|
114
|
+
if (!el) return;
|
|
115
|
+
el.style.height = "0px";
|
|
116
|
+
const styles = getComputedStyle(el);
|
|
117
|
+
const max = Number.parseFloat(styles.maxHeight);
|
|
118
|
+
const min = Number.parseFloat(styles.minHeight);
|
|
119
|
+
const content = el.scrollHeight;
|
|
120
|
+
const next = Number.isFinite(max) && max > 0 ? Math.min(content, max) : content;
|
|
121
|
+
el.style.height = `${next}px`;
|
|
122
|
+
fxExpanded.value = Number.isFinite(min) ? next > min + 1 : next > 1;
|
|
123
|
+
}
|
|
124
|
+
function syncFxCursor() {
|
|
125
|
+
const el = fxRef.value;
|
|
126
|
+
if (!el) return;
|
|
127
|
+
fxCursor.value = el.selectionStart;
|
|
128
|
+
refreshSuggest();
|
|
129
|
+
}
|
|
130
|
+
function handleFxInput() {
|
|
131
|
+
syncFxCursor();
|
|
132
|
+
autosizeFx();
|
|
133
|
+
}
|
|
134
|
+
function closeSuggest() {
|
|
135
|
+
suggestItems.value = [];
|
|
136
|
+
suggestIndex.value = 0;
|
|
137
|
+
}
|
|
138
|
+
function refreshSuggest() {
|
|
139
|
+
if (!editing.value || mirroring.value) {
|
|
140
|
+
closeSuggest();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const ctx = getSuggestContext(fxDraft.value, fxCursor.value);
|
|
144
|
+
if (!ctx) {
|
|
145
|
+
closeSuggest();
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const items = filterFormulaSuggestions(ctx.prefix);
|
|
149
|
+
suggestItems.value = items;
|
|
150
|
+
if (suggestIndex.value >= items.length) suggestIndex.value = 0;
|
|
151
|
+
}
|
|
152
|
+
function confirmSuggest(item) {
|
|
153
|
+
const pick = item ?? suggestItems.value[suggestIndex.value];
|
|
154
|
+
if (!pick) return;
|
|
155
|
+
const ctx = getSuggestContext(fxDraft.value, fxCursor.value);
|
|
156
|
+
if (!ctx) return;
|
|
157
|
+
const result = applySuggest(fxDraft.value, ctx.start, ctx.end, pick.name);
|
|
158
|
+
fxDraft.value = result.text;
|
|
159
|
+
fxCursor.value = result.cursor;
|
|
160
|
+
closeSuggest();
|
|
161
|
+
nextTick(() => {
|
|
162
|
+
const el = fxRef.value;
|
|
163
|
+
if (!el) return;
|
|
164
|
+
el.focus();
|
|
165
|
+
el.setSelectionRange(result.cursor, result.cursor);
|
|
166
|
+
autosizeFx();
|
|
167
|
+
refreshSuggest();
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function handleNameKeydown(event) {
|
|
171
|
+
if (event.key === "Enter") {
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
commitName();
|
|
174
|
+
} else if (event.key === "Escape") {
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
refreshName();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function handleNameBlur() {
|
|
180
|
+
nameFocused.value = false;
|
|
181
|
+
refreshName();
|
|
182
|
+
}
|
|
183
|
+
function commitName() {
|
|
184
|
+
const range = parseRange(nameDraft.value);
|
|
185
|
+
if (!range) {
|
|
186
|
+
message.warn("无效的单元格地址");
|
|
187
|
+
refreshName();
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (range.start.row === range.end.row && range.start.col === range.end.col) props.context.selectCell(range.start);
|
|
191
|
+
else props.context.selectRange(range);
|
|
192
|
+
refreshName();
|
|
193
|
+
}
|
|
194
|
+
function handleFxFocus() {
|
|
195
|
+
if (fxDisabled.value) return;
|
|
196
|
+
mirroring.value = false;
|
|
197
|
+
mirrorAddr = null;
|
|
198
|
+
editing.value = true;
|
|
199
|
+
editAddr = selection.value.activeCell;
|
|
200
|
+
syncFxCursor();
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* 失焦提交;引用选择期间(画布 pointerdown 已挂起)跳过。
|
|
204
|
+
* ✓/✗ / 候选列表用 mousedown.prevent 拦截失焦。
|
|
205
|
+
*/
|
|
206
|
+
function handleFxBlur() {
|
|
207
|
+
if (!editing.value) return;
|
|
208
|
+
if (suppressBlurCommit) {
|
|
209
|
+
suppressBlurCommit = false;
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
commitEdit();
|
|
213
|
+
}
|
|
214
|
+
function handleFxKeydown(event) {
|
|
215
|
+
if (suggestOpen.value) {
|
|
216
|
+
if (event.key === "ArrowDown") {
|
|
217
|
+
event.preventDefault();
|
|
218
|
+
suggestIndex.value = moveSuggestIndex(suggestIndex.value, suggestItems.value.length, 1);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (event.key === "ArrowUp") {
|
|
222
|
+
event.preventDefault();
|
|
223
|
+
suggestIndex.value = moveSuggestIndex(suggestIndex.value, suggestItems.value.length, -1);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (event.key === "Enter" || event.key === "Tab") {
|
|
227
|
+
event.preventDefault();
|
|
228
|
+
confirmSuggest();
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (event.key === "Escape") {
|
|
232
|
+
event.preventDefault();
|
|
233
|
+
closeSuggest();
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
238
|
+
event.preventDefault();
|
|
239
|
+
commitEdit();
|
|
240
|
+
} else if (event.key === "Escape") {
|
|
241
|
+
event.preventDefault();
|
|
242
|
+
cancelEdit();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function commitEdit() {
|
|
246
|
+
if (!editing.value) return;
|
|
247
|
+
const addr = editAddr;
|
|
248
|
+
editing.value = false;
|
|
249
|
+
editAddr = null;
|
|
250
|
+
suppressBlurCommit = false;
|
|
251
|
+
closeSuggest();
|
|
252
|
+
if (addr) props.context.setCellValue(addr, fxDraft.value);
|
|
253
|
+
refreshFx();
|
|
254
|
+
}
|
|
255
|
+
function cancelEdit() {
|
|
256
|
+
if (!editing.value) return;
|
|
257
|
+
editing.value = false;
|
|
258
|
+
editAddr = null;
|
|
259
|
+
suppressBlurCommit = false;
|
|
260
|
+
closeSuggest();
|
|
261
|
+
refreshFx();
|
|
262
|
+
}
|
|
263
|
+
function handleSelectionChange(state) {
|
|
264
|
+
selection.value = state;
|
|
265
|
+
if (!nameFocused.value) refreshName();
|
|
266
|
+
if (editing.value) return;
|
|
267
|
+
mirroring.value = false;
|
|
268
|
+
mirrorAddr = null;
|
|
269
|
+
refreshFx();
|
|
270
|
+
}
|
|
271
|
+
function handleCellChange({ addr }) {
|
|
272
|
+
if (editing.value) return;
|
|
273
|
+
if (mirroring.value) {
|
|
274
|
+
if (mirrorAddr && addr.row === mirrorAddr.row && addr.col === mirrorAddr.col) {
|
|
275
|
+
mirroring.value = false;
|
|
276
|
+
mirrorAddr = null;
|
|
277
|
+
refreshFx();
|
|
278
|
+
}
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const active = selection.value.activeCell;
|
|
282
|
+
if (!active || addr.row !== active.row || addr.col !== active.col) return;
|
|
283
|
+
refreshFx();
|
|
284
|
+
}
|
|
285
|
+
function mirrorGridEdit(addr) {
|
|
286
|
+
if (editing.value || fxDisabled.value) return;
|
|
287
|
+
mirroring.value = true;
|
|
288
|
+
mirrorAddr = addr;
|
|
289
|
+
fxDraft.value = cellText(addr);
|
|
290
|
+
closeSuggest();
|
|
291
|
+
}
|
|
292
|
+
function exitMirror(addr) {
|
|
293
|
+
if (!mirroring.value) return;
|
|
294
|
+
if (mirrorAddr && addr.row === mirrorAddr.row && addr.col === mirrorAddr.col) {
|
|
295
|
+
mirroring.value = false;
|
|
296
|
+
mirrorAddr = null;
|
|
297
|
+
refreshFx();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
__expose({
|
|
301
|
+
mirrorGridEdit,
|
|
302
|
+
exitMirror,
|
|
303
|
+
isRefSelecting,
|
|
304
|
+
beginBlurSuppress,
|
|
305
|
+
handleRefSelect
|
|
306
|
+
});
|
|
307
|
+
let dispose = [];
|
|
308
|
+
function bindSheet(sheet) {
|
|
309
|
+
for (const off of dispose) off();
|
|
310
|
+
dispose = [sheet.on("selection-change", handleSelectionChange), sheet.on("cell-change", handleCellChange)];
|
|
311
|
+
}
|
|
312
|
+
watch(() => props.sheet, (sheet, prev) => {
|
|
313
|
+
if (sheet === prev) return;
|
|
314
|
+
editing.value = false;
|
|
315
|
+
editAddr = null;
|
|
316
|
+
mirroring.value = false;
|
|
317
|
+
mirrorAddr = null;
|
|
318
|
+
suppressBlurCommit = false;
|
|
319
|
+
closeSuggest();
|
|
320
|
+
bindSheet(sheet);
|
|
321
|
+
selection.value = sheet.getSelection();
|
|
322
|
+
refreshName();
|
|
323
|
+
refreshFx();
|
|
324
|
+
});
|
|
325
|
+
onMounted(() => {
|
|
326
|
+
bindSheet(props.sheet);
|
|
327
|
+
selection.value = props.sheet.getSelection();
|
|
328
|
+
refreshName();
|
|
329
|
+
refreshFx();
|
|
330
|
+
});
|
|
331
|
+
onBeforeUnmount(() => {
|
|
332
|
+
for (const off of dispose) off();
|
|
333
|
+
dispose = [];
|
|
334
|
+
});
|
|
335
|
+
return (_ctx, _cache) => {
|
|
336
|
+
return openBlock(), createElementBlock("div", { class: normalizeClass(unref(cls).e("formula-bar")) }, [
|
|
337
|
+
withDirectives(createElementVNode("input", {
|
|
338
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => nameDraft.value = $event),
|
|
339
|
+
class: normalizeClass(unref(cls).e("name-box")),
|
|
340
|
+
spellcheck: "false",
|
|
341
|
+
autocomplete: "off",
|
|
342
|
+
title: "单元格地址或区域(如 B3 或 B3:D5),回车跳转",
|
|
343
|
+
onFocus: _cache[1] || (_cache[1] = ($event) => nameFocused.value = true),
|
|
344
|
+
onBlur: handleNameBlur,
|
|
345
|
+
onKeydown: handleNameKeydown
|
|
346
|
+
}, null, 34), [[vModelText, nameDraft.value]]),
|
|
347
|
+
createElementVNode("span", { class: normalizeClass(unref(cls).e("fx-label")) }, "fx", 2),
|
|
348
|
+
createElementVNode("div", { class: normalizeClass(unref(cls).e("fx-editor")) }, [createCommentVNode(" 文档流只占单行;面板绝对定位向下浮起,不撑开公式栏 "), createElementVNode("div", { class: normalizeClass([unref(cls).e("fx-input-panel"), unref(bem).is("expanded", fxExpanded.value)]) }, [withDirectives(createElementVNode("textarea", {
|
|
349
|
+
ref_key: "fxRef",
|
|
350
|
+
ref: fxRef,
|
|
351
|
+
"onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => fxDraft.value = $event),
|
|
352
|
+
class: normalizeClass(unref(cls).e("fx-input")),
|
|
353
|
+
disabled: fxDisabled.value,
|
|
354
|
+
readonly: mirroring.value,
|
|
355
|
+
rows: "1",
|
|
356
|
+
spellcheck: "false",
|
|
357
|
+
autocomplete: "off",
|
|
358
|
+
title: "活动单元格内容('=' 开头为公式);Enter 提交,Esc 取消",
|
|
359
|
+
onFocus: handleFxFocus,
|
|
360
|
+
onBlur: handleFxBlur,
|
|
361
|
+
onKeydown: handleFxKeydown,
|
|
362
|
+
onInput: handleFxInput,
|
|
363
|
+
onClick: syncFxCursor,
|
|
364
|
+
onKeyup: syncFxCursor,
|
|
365
|
+
onSelect: syncFxCursor
|
|
366
|
+
}, null, 42, _hoisted_1), [[vModelText, fxDraft.value]]), createVNode(_sfc_main$1, {
|
|
367
|
+
items: suggestItems.value,
|
|
368
|
+
"active-index": suggestIndex.value,
|
|
369
|
+
onSelect: confirmSuggest,
|
|
370
|
+
onHover: _cache[3] || (_cache[3] = (i) => suggestIndex.value = i)
|
|
371
|
+
}, null, 8, ["items", "active-index"])], 2)], 2),
|
|
372
|
+
editing.value ? (openBlock(), createElementBlock("button", {
|
|
373
|
+
key: 0,
|
|
374
|
+
type: "button",
|
|
375
|
+
class: normalizeClass(unref(cls).e("fx-btn")),
|
|
376
|
+
title: "提交(Enter)",
|
|
377
|
+
onMousedown: _cache[4] || (_cache[4] = withModifiers(() => {}, ["prevent"])),
|
|
378
|
+
onClick: commitEdit
|
|
379
|
+
}, " ✓ ", 34)) : createCommentVNode("v-if", true),
|
|
380
|
+
editing.value ? (openBlock(), createElementBlock("button", {
|
|
381
|
+
key: 1,
|
|
382
|
+
type: "button",
|
|
383
|
+
class: normalizeClass(unref(cls).e("fx-btn")),
|
|
384
|
+
title: "取消(Esc)",
|
|
385
|
+
onMousedown: _cache[5] || (_cache[5] = withModifiers(() => {}, ["prevent"])),
|
|
386
|
+
onClick: cancelEdit
|
|
387
|
+
}, " ✗ ", 34)) : createCommentVNode("v-if", true)
|
|
388
|
+
], 2);
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
//#endregion
|
|
393
|
+
export { _sfc_main as default };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Fragment, computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, nextTick, normalizeClass, openBlock, renderList, toDisplayString, unref, watch, withCtx, withModifiers } from "vue";
|
|
2
|
+
import { UScroll } from "@veltra/desktop";
|
|
3
|
+
import { bem } from "@veltra/utils";
|
|
4
|
+
//#region src/components/sheet/formula-suggest-list.vue
|
|
5
|
+
const _hoisted_1 = [
|
|
6
|
+
"aria-selected",
|
|
7
|
+
"onMousedown",
|
|
8
|
+
"onMouseenter"
|
|
9
|
+
];
|
|
10
|
+
const SUGGEST_MAX_HEIGHT = 240;
|
|
11
|
+
/** 单项约高(含 padding + 签名/描述两行);用于估算 UScroll height */
|
|
12
|
+
const SUGGEST_ITEM_HEIGHT = 48;
|
|
13
|
+
const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
14
|
+
name: "UFormulaSuggestList",
|
|
15
|
+
__name: "formula-suggest-list",
|
|
16
|
+
props: {
|
|
17
|
+
items: {},
|
|
18
|
+
activeIndex: {}
|
|
19
|
+
},
|
|
20
|
+
emits: ["select", "hover"],
|
|
21
|
+
setup(__props, { emit: __emit }) {
|
|
22
|
+
const props = __props;
|
|
23
|
+
const emit = __emit;
|
|
24
|
+
const cls = bem("sheet");
|
|
25
|
+
/** 候选列表最大可视高度;内容更短时收缩,避免空前缀少量项时大片留白 */
|
|
26
|
+
const scrollHeight = computed(() => Math.min(Math.max(props.items.length, 1) * SUGGEST_ITEM_HEIGHT, SUGGEST_MAX_HEIGHT));
|
|
27
|
+
const itemEls = [];
|
|
28
|
+
function setItemRef(index, el) {
|
|
29
|
+
itemEls[index] = el instanceof HTMLElement ? el : null;
|
|
30
|
+
}
|
|
31
|
+
watch(() => [props.activeIndex, props.items], async ([index]) => {
|
|
32
|
+
await nextTick();
|
|
33
|
+
itemEls[index]?.scrollIntoView({ block: "nearest" });
|
|
34
|
+
});
|
|
35
|
+
return (_ctx, _cache) => {
|
|
36
|
+
return __props.items.length > 0 ? (openBlock(), createElementBlock("div", {
|
|
37
|
+
key: 0,
|
|
38
|
+
class: normalizeClass(unref(cls).e("fx-suggest")),
|
|
39
|
+
role: "listbox",
|
|
40
|
+
onMousedown: _cache[0] || (_cache[0] = withModifiers(() => {}, ["prevent"]))
|
|
41
|
+
}, [createCommentVNode(" 滚动用 desktop UScroll(自定义滚动条;原生 overflow 滚动条在浮层里常看不见) "), createVNode(unref(UScroll), {
|
|
42
|
+
height: scrollHeight.value,
|
|
43
|
+
class: normalizeClass(unref(cls).e("fx-suggest-scroll"))
|
|
44
|
+
}, {
|
|
45
|
+
default: withCtx(() => [createElementVNode("ul", { class: normalizeClass(unref(cls).e("fx-suggest-list")) }, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.items, (item, index) => {
|
|
46
|
+
return openBlock(), createElementBlock("li", {
|
|
47
|
+
key: item.name,
|
|
48
|
+
ref_for: true,
|
|
49
|
+
ref: (el) => setItemRef(index, el),
|
|
50
|
+
class: normalizeClass([unref(cls).e("fx-suggest-item"), unref(bem).is("active", index === __props.activeIndex)]),
|
|
51
|
+
role: "option",
|
|
52
|
+
"aria-selected": index === __props.activeIndex,
|
|
53
|
+
onMousedown: withModifiers(($event) => emit("select", item), ["prevent"]),
|
|
54
|
+
onMouseenter: ($event) => emit("hover", index)
|
|
55
|
+
}, [createElementVNode("span", { class: normalizeClass(unref(cls).e("fx-suggest-sig")) }, toDisplayString(item.signature), 3), item.description ? (openBlock(), createElementBlock("span", {
|
|
56
|
+
key: 0,
|
|
57
|
+
class: normalizeClass(unref(cls).e("fx-suggest-desc"))
|
|
58
|
+
}, toDisplayString(item.description), 3)) : createCommentVNode("v-if", true)], 42, _hoisted_1);
|
|
59
|
+
}), 128))], 2)]),
|
|
60
|
+
_: 1
|
|
61
|
+
}, 8, ["height", "class"])], 34)) : createCommentVNode("v-if", true);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
//#endregion
|
|
66
|
+
export { _sfc_main as default };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { message, messageConfirm } from "@veltra/desktop";
|
|
2
|
+
import { nextFrame } from "@veltra/utils";
|
|
3
|
+
import { importCsv, importXlsx, replaceWorkbookWithSnapshots } from "@veltra/sheet-core/core/io/import";
|
|
4
|
+
//#region src/components/sheet/import-file.ts
|
|
5
|
+
/** 导入文件 accept(工具栏直接选文件) */
|
|
6
|
+
const IMPORT_FILE_ACCEPT = ".xlsx,.csv";
|
|
7
|
+
/**
|
|
8
|
+
* xlsx 解析(worker 优先):importXlsx 是同步重活,主线程直接跑会冻结 UI。
|
|
9
|
+
* worker 返回纯数据快照;不可用时回退主线程解析。
|
|
10
|
+
*/
|
|
11
|
+
async function parseXlsxAsync(buffer, parseProgress) {
|
|
12
|
+
let worker;
|
|
13
|
+
try {
|
|
14
|
+
const url = import.meta.env?.DEV ? new URL("./popups/import.worker.ts", import.meta.url) : new URL("./popups/import.worker.js", import.meta.url);
|
|
15
|
+
worker = new Worker(url, { type: "module" });
|
|
16
|
+
} catch {
|
|
17
|
+
return toSnapshotArray(await importXlsx(new Uint8Array(buffer)));
|
|
18
|
+
}
|
|
19
|
+
return await new Promise((resolve, reject) => {
|
|
20
|
+
let settled = false;
|
|
21
|
+
const fallback = () => {
|
|
22
|
+
if (settled) return;
|
|
23
|
+
settled = true;
|
|
24
|
+
worker.terminate();
|
|
25
|
+
importXlsx(new Uint8Array(buffer)).then((wb) => resolve(toSnapshotArray(wb))).catch((err) => reject(err));
|
|
26
|
+
};
|
|
27
|
+
worker.onmessage = (e) => {
|
|
28
|
+
const data = e.data;
|
|
29
|
+
if (data.type === "progress") {
|
|
30
|
+
if (parseProgress) parseProgress.value = {
|
|
31
|
+
done: data.done,
|
|
32
|
+
total: data.total
|
|
33
|
+
};
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (settled) return;
|
|
37
|
+
settled = true;
|
|
38
|
+
if (!data.ok) {
|
|
39
|
+
worker.terminate();
|
|
40
|
+
reject(new Error(data.error ?? "worker 解析失败"));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
worker.terminate();
|
|
44
|
+
resolve({
|
|
45
|
+
sheets: data.sheets ?? [],
|
|
46
|
+
activeIndex: data.activeIndex ?? 0
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
worker.onerror = () => fallback();
|
|
50
|
+
const transfer = buffer.slice(0);
|
|
51
|
+
worker.postMessage({ buffer: transfer }, [transfer]);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function toSnapshotArray(wb) {
|
|
55
|
+
return {
|
|
56
|
+
sheets: wb.getSheets().map((s) => ({
|
|
57
|
+
name: s.name,
|
|
58
|
+
snapshot: s.snapshot()
|
|
59
|
+
})),
|
|
60
|
+
activeIndex: wb.activeSheetIndex
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 从本地 File 导入:
|
|
65
|
+
* - .csv → importCsv 写入当前活动表
|
|
66
|
+
* - .xlsx → 解析后经 messageConfirm 确认再 replaceWorkbookWithSnapshots
|
|
67
|
+
*/
|
|
68
|
+
function importFromFile(file, options) {
|
|
69
|
+
const { workbook, activeSheet, parsing, parseProgress, onCsvImported, onWorkbookReplaced } = options;
|
|
70
|
+
if (file.name.toLowerCase().endsWith(".csv")) {
|
|
71
|
+
file.text().then((text) => {
|
|
72
|
+
importCsv(text, activeSheet);
|
|
73
|
+
onCsvImported?.();
|
|
74
|
+
message.success(`已从 ${file.name} 导入到工作表「${activeSheet.name}」`);
|
|
75
|
+
});
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
file.arrayBuffer().then((buffer) => {
|
|
79
|
+
if (parsing) parsing.value = true;
|
|
80
|
+
if (parseProgress) parseProgress.value = {
|
|
81
|
+
done: 0,
|
|
82
|
+
total: 0
|
|
83
|
+
};
|
|
84
|
+
parseXlsxAsync(buffer, parseProgress).then((imported) => {
|
|
85
|
+
if (parsing) parsing.value = false;
|
|
86
|
+
messageConfirm.danger(`导入将替换当前工作簿(共 ${imported.sheets.length} 个工作表),确定吗?`, {
|
|
87
|
+
confirmButtonText: "导入",
|
|
88
|
+
onClosed: (action) => {
|
|
89
|
+
if (action !== "confirm") return;
|
|
90
|
+
const loading = message({
|
|
91
|
+
message: "正在导入…",
|
|
92
|
+
duration: 0
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
replaceWorkbookWithSnapshots(workbook, imported.sheets, imported.activeIndex);
|
|
96
|
+
onWorkbookReplaced?.();
|
|
97
|
+
nextFrame(() => {
|
|
98
|
+
message.success("导入完成");
|
|
99
|
+
loading.close();
|
|
100
|
+
});
|
|
101
|
+
} catch (err) {
|
|
102
|
+
console.error("[sheet] 导入失败:", err);
|
|
103
|
+
message.error(`导入失败:${err instanceof Error ? err.message : String(err)}`);
|
|
104
|
+
loading.close();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}).catch((err) => {
|
|
109
|
+
if (parsing) parsing.value = false;
|
|
110
|
+
message.error(`文件解析失败:${err instanceof Error ? err.message : String(err)}`);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 拉起系统文件选择框(工具栏导入用;不用 UFilePicker——无编程式打开 API)。
|
|
116
|
+
* 选中文件后走 importFromFile。
|
|
117
|
+
*/
|
|
118
|
+
function pickAndImportFile(options) {
|
|
119
|
+
const input = document.createElement("input");
|
|
120
|
+
input.type = "file";
|
|
121
|
+
input.accept = IMPORT_FILE_ACCEPT;
|
|
122
|
+
input.hidden = true;
|
|
123
|
+
const cleanup = () => {
|
|
124
|
+
input.remove();
|
|
125
|
+
};
|
|
126
|
+
input.addEventListener("change", () => {
|
|
127
|
+
const file = input.files?.[0];
|
|
128
|
+
cleanup();
|
|
129
|
+
if (file) importFromFile(file, options);
|
|
130
|
+
});
|
|
131
|
+
window.addEventListener("focus", () => {
|
|
132
|
+
setTimeout(() => {
|
|
133
|
+
if (document.body.contains(input) && !input.files?.length) cleanup();
|
|
134
|
+
}, 300);
|
|
135
|
+
}, { once: true });
|
|
136
|
+
document.body.appendChild(input);
|
|
137
|
+
input.click();
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
export { IMPORT_FILE_ACCEPT, importFromFile, pickAndImportFile };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createElementBlock, createElementVNode, createVNode, defineComponent, inject, normalizeClass, openBlock, ref, toDisplayString, unref, withKeys, withModifiers } from "vue";
|
|
2
|
+
import { ContextmenuRootDIKey, UNumberInput } from "@veltra/desktop";
|
|
3
|
+
import { bem } from "@veltra/utils";
|
|
4
|
+
//#region src/components/sheet/insert-count-menu-item.vue
|
|
5
|
+
const _hoisted_1 = ["onKeydownCapture"];
|
|
6
|
+
const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
7
|
+
name: "USheetInsertCountMenuItem",
|
|
8
|
+
__name: "insert-count-menu-item",
|
|
9
|
+
props: {
|
|
10
|
+
prefix: {},
|
|
11
|
+
suffix: {},
|
|
12
|
+
defaultValue: { default: 1 },
|
|
13
|
+
min: { default: 1 },
|
|
14
|
+
max: { default: 1e3 }
|
|
15
|
+
},
|
|
16
|
+
emits: ["confirm"],
|
|
17
|
+
setup(__props, { emit: __emit }) {
|
|
18
|
+
/**
|
|
19
|
+
* 右键菜单内嵌数量输入项:文案 + UNumberInput。
|
|
20
|
+
* 点击菜单项本体按当前值执行;输入框区域点击不冒泡。
|
|
21
|
+
* Enter 提交、Esc 关闭;提交/取消均经 ContextmenuRootDIKey 关闭菜单。
|
|
22
|
+
* Enter/Esc 使用 capture:UNumberInput 内部 `@keydown.stop`,冒泡阶段收不到。
|
|
23
|
+
*/
|
|
24
|
+
const props = __props;
|
|
25
|
+
const emit = __emit;
|
|
26
|
+
const cls = bem("sheet");
|
|
27
|
+
const root = inject(ContextmenuRootDIKey, null);
|
|
28
|
+
const count = ref(props.defaultValue);
|
|
29
|
+
function clamp(n) {
|
|
30
|
+
return Math.min(props.max, Math.max(props.min, Math.floor(n) || props.min));
|
|
31
|
+
}
|
|
32
|
+
function close() {
|
|
33
|
+
root?.onItemClickEnd();
|
|
34
|
+
}
|
|
35
|
+
function confirm() {
|
|
36
|
+
emit("confirm", clamp(count.value ?? props.defaultValue));
|
|
37
|
+
close();
|
|
38
|
+
}
|
|
39
|
+
return (_ctx, _cache) => {
|
|
40
|
+
return openBlock(), createElementBlock("div", {
|
|
41
|
+
class: normalizeClass(unref(cls).e("insert-count-menu")),
|
|
42
|
+
onClick: confirm,
|
|
43
|
+
onKeydownCapture: [withKeys(withModifiers(confirm, ["prevent"]), ["enter"]), withKeys(withModifiers(close, ["prevent"]), ["escape"])]
|
|
44
|
+
}, [
|
|
45
|
+
createElementVNode("span", { class: normalizeClass(unref(cls).e("insert-count-prefix")) }, toDisplayString(__props.prefix), 3),
|
|
46
|
+
createVNode(unref(UNumberInput), {
|
|
47
|
+
modelValue: count.value,
|
|
48
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => count.value = $event),
|
|
49
|
+
size: "small",
|
|
50
|
+
min: __props.min,
|
|
51
|
+
max: __props.max,
|
|
52
|
+
step: 1,
|
|
53
|
+
clearable: false,
|
|
54
|
+
class: normalizeClass(unref(cls).e("insert-count-input")),
|
|
55
|
+
onClick: _cache[1] || (_cache[1] = withModifiers(() => {}, ["stop"]))
|
|
56
|
+
}, null, 8, [
|
|
57
|
+
"modelValue",
|
|
58
|
+
"min",
|
|
59
|
+
"max",
|
|
60
|
+
"class"
|
|
61
|
+
]),
|
|
62
|
+
createElementVNode("span", { class: normalizeClass(unref(cls).e("insert-count-suffix")) }, toDisplayString(__props.suffix), 3)
|
|
63
|
+
], 42, _hoisted_1);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
//#endregion
|
|
68
|
+
export { _sfc_main as default };
|