@searsuite/sear-plugin-selection 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +29 -0
- package/README.md +8 -2
- package/dist/AnalyzeSheetRangeMove.d.ts +5 -0
- package/dist/AnalyzeSheetRangeMove.d.ts.map +1 -0
- package/dist/AnalyzeSheetRangeMove.js +7 -0
- package/dist/AnalyzeSheetRangeMove.js.map +1 -0
- package/dist/GetActiveCell.d.ts +3 -0
- package/dist/GetActiveCell.d.ts.map +1 -0
- package/dist/GetActiveCell.js +7 -0
- package/dist/GetActiveCell.js.map +1 -0
- package/dist/SheetAxisDrag.d.ts +15 -0
- package/dist/SheetAxisDrag.d.ts.map +1 -0
- package/dist/SheetAxisDrag.js +42 -0
- package/dist/SheetAxisDrag.js.map +1 -0
- package/dist/SheetDragAxis.d.ts +7 -0
- package/dist/SheetDragAxis.d.ts.map +1 -0
- package/dist/SheetDragAxis.js +6 -0
- package/dist/SheetDragAxis.js.map +1 -0
- package/dist/SheetFillRangeCommand.d.ts +18 -0
- package/dist/SheetFillRangeCommand.d.ts.map +1 -0
- package/dist/SheetFillRangeCommand.js +114 -0
- package/dist/SheetFillRangeCommand.js.map +1 -0
- package/dist/SheetFillSeries.d.ts +7 -0
- package/dist/SheetFillSeries.d.ts.map +1 -0
- package/dist/SheetFillSeries.js +46 -0
- package/dist/SheetFillSeries.js.map +1 -0
- package/dist/SheetHighlightPipelineNames.d.ts +5 -0
- package/dist/SheetHighlightPipelineNames.d.ts.map +1 -0
- package/dist/SheetHighlightPipelineNames.js +9 -0
- package/dist/SheetHighlightPipelineNames.js.map +1 -0
- package/dist/SheetHighlightRegistry.d.ts +67 -0
- package/dist/SheetHighlightRegistry.d.ts.map +1 -0
- package/dist/SheetHighlightRegistry.js +114 -0
- package/dist/SheetHighlightRegistry.js.map +1 -0
- package/dist/SheetRangeDrag.d.ts +54 -0
- package/dist/SheetRangeDrag.d.ts.map +1 -0
- package/dist/SheetRangeDrag.js +631 -0
- package/dist/SheetRangeDrag.js.map +1 -0
- package/dist/SheetRangeDragCommand.d.ts +19 -0
- package/dist/SheetRangeDragCommand.d.ts.map +1 -0
- package/dist/SheetRangeDragCommand.js +15 -0
- package/dist/SheetRangeDragCommand.js.map +1 -0
- package/dist/SheetRangeMoveCommands.d.ts +12 -0
- package/dist/SheetRangeMoveCommands.d.ts.map +1 -0
- package/dist/SheetRangeMoveCommands.js +8 -0
- package/dist/SheetRangeMoveCommands.js.map +1 -0
- package/dist/SheetRangeMoveError.d.ts +12 -0
- package/dist/SheetRangeMoveError.d.ts.map +1 -0
- package/dist/SheetRangeMoveError.js +18 -0
- package/dist/SheetRangeMoveError.js.map +1 -0
- package/dist/SheetSelectionCommands.d.ts +52 -0
- package/dist/SheetSelectionCommands.d.ts.map +1 -0
- package/dist/SheetSelectionCommands.js +29 -0
- package/dist/SheetSelectionCommands.js.map +1 -0
- package/dist/SheetSelectionInteractionReducer.d.ts +13 -0
- package/dist/SheetSelectionInteractionReducer.d.ts.map +1 -0
- package/dist/SheetSelectionInteractionReducer.js +21 -0
- package/dist/SheetSelectionInteractionReducer.js.map +1 -0
- package/dist/SheetSelectionPipelineNames.d.ts +21 -0
- package/dist/SheetSelectionPipelineNames.d.ts.map +1 -0
- package/dist/SheetSelectionPipelineNames.js +28 -0
- package/dist/SheetSelectionPipelineNames.js.map +1 -0
- package/dist/SheetSelectionPointerCommand.d.ts +29 -0
- package/dist/SheetSelectionPointerCommand.d.ts.map +1 -0
- package/dist/SheetSelectionPointerCommand.js +15 -0
- package/dist/SheetSelectionPointerCommand.js.map +1 -0
- package/dist/SheetSelectionRenderSemantics.d.ts +6 -0
- package/dist/SheetSelectionRenderSemantics.d.ts.map +1 -0
- package/dist/SheetSelectionRenderSemantics.js +9 -0
- package/dist/SheetSelectionRenderSemantics.js.map +1 -0
- package/dist/createRangeMovePreview.d.ts +5 -0
- package/dist/createRangeMovePreview.d.ts.map +1 -0
- package/dist/createRangeMovePreview.js +21 -0
- package/dist/createRangeMovePreview.js.map +1 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +88 -0
- package/dist/index.js.map +1 -0
- package/dist/resolveAxisInsertionBoundary.d.ts +4 -0
- package/dist/resolveAxisInsertionBoundary.d.ts.map +1 -0
- package/dist/resolveAxisInsertionBoundary.js +16 -0
- package/dist/resolveAxisInsertionBoundary.js.map +1 -0
- package/dist/resolveSheetRangeMove.d.ts +5 -0
- package/dist/resolveSheetRangeMove.d.ts.map +1 -0
- package/dist/resolveSheetRangeMove.js +24 -0
- package/dist/resolveSheetRangeMove.js.map +1 -0
- package/dist/sheetHighlight/SheetHighlightPlugin.d.ts +30 -0
- package/dist/sheetHighlight/SheetHighlightPlugin.d.ts.map +1 -0
- package/dist/sheetHighlight/SheetHighlightPlugin.js +113 -0
- package/dist/sheetHighlight/SheetHighlightPlugin.js.map +1 -0
- package/dist/sheetSelection/SheetSelectionPlugin.d.ts +150 -0
- package/dist/sheetSelection/SheetSelectionPlugin.d.ts.map +1 -0
- package/dist/sheetSelection/SheetSelectionPlugin.js +1652 -0
- package/dist/sheetSelection/SheetSelectionPlugin.js.map +1 -0
- package/package.json +65 -3
|
@@ -0,0 +1,1652 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
9
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
10
|
+
};
|
|
11
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
+
};
|
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
+
};
|
|
22
|
+
var _SheetSelectionPlugin_instances, _SheetSelectionPlugin_isSelecting, _SheetSelectionPlugin_selectionPointer, _SheetSelectionPlugin_selectionScrollFrame, _SheetSelectionPlugin_disposeSelectionCapture, _SheetSelectionPlugin_additionalRanges, _SheetSelectionPlugin_disposeAdditionalHighlight, _SheetSelectionPlugin_headerDragMode, _SheetSelectionPlugin_selectionOrigin, _SheetSelectionPlugin_selectionCursor, _SheetSelectionPlugin_commandCore, _SheetSelectionPlugin_core, _SheetSelectionPlugin_queries, _SheetSelectionPlugin_commands, _SheetSelectionPlugin_rangeDragOwnerToken, _SheetSelectionPlugin_sheetCellMergePlugin, _SheetSelectionPlugin_bindCoreReference, _SheetSelectionPlugin_captureSessionState, _SheetSelectionPlugin_restoreSessionState, _SheetSelectionPlugin_dispatchPointerInput, _SheetSelectionPlugin_applyPointerInput, _SheetSelectionPlugin_handlePointerDown, _SheetSelectionPlugin_handlePointerMove, _SheetSelectionPlugin_updatePointerPosition, _SheetSelectionPlugin_planPointerMove, _SheetSelectionPlugin_handlePointerUp, _SheetSelectionPlugin_restartNavigation;
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.SheetSelectionPlugin = exports.SheetAdditionalSelectionsSessionStateDefinition = exports.SheetSelectionSessionStateDefinition = void 0;
|
|
25
|
+
const sear_foundation_error_1 = require("@searsuite/sear-foundation-error");
|
|
26
|
+
const sear_assembly_core_1 = require("@searsuite/sear-assembly-core");
|
|
27
|
+
const GetActiveCell_1 = require("../GetActiveCell");
|
|
28
|
+
const sear_domain_ot_1 = require("@searsuite/sear-domain-ot");
|
|
29
|
+
const sear_assembly_plugin_1 = require("@searsuite/sear-assembly-plugin");
|
|
30
|
+
const sear_assembly_config_1 = require("@searsuite/sear-assembly-config");
|
|
31
|
+
const sear_foundation_di_1 = require("@searsuite/sear-foundation-di");
|
|
32
|
+
const sear_render_input_1 = require("@searsuite/sear-render-input");
|
|
33
|
+
const sear_render_1 = require("@searsuite/sear-render");
|
|
34
|
+
const sear_plugin_cell_merge_1 = require("@searsuite/sear-plugin-cell-merge");
|
|
35
|
+
const sear_domain_cell_types_1 = require("@searsuite/sear-domain-cell-types");
|
|
36
|
+
const sear_plugin_freeze_1 = require("@searsuite/sear-plugin-freeze");
|
|
37
|
+
const sear_plugin_fixed_row_1 = require("@searsuite/sear-plugin-fixed-row");
|
|
38
|
+
const sear_render_2 = require("@searsuite/sear-render");
|
|
39
|
+
const sear_foundation_rect_1 = require("@searsuite/sear-foundation-rect");
|
|
40
|
+
const sear_foundation_platform_1 = require("@searsuite/sear-foundation-platform");
|
|
41
|
+
const sear_render_engine_1 = require("@searsuite/sear-render-engine");
|
|
42
|
+
const sear_render_registry_1 = require("@searsuite/sear-render-registry");
|
|
43
|
+
const SheetHighlightPlugin_1 = require("../sheetHighlight/SheetHighlightPlugin");
|
|
44
|
+
const SheetHighlightRegistry_1 = require("../SheetHighlightRegistry");
|
|
45
|
+
const SheetHighlightPipelineNames_1 = require("../SheetHighlightPipelineNames");
|
|
46
|
+
const SheetSelectionRenderSemantics_1 = require("../SheetSelectionRenderSemantics");
|
|
47
|
+
const SheetSelectionPipelineNames_1 = require("../SheetSelectionPipelineNames");
|
|
48
|
+
const SheetSelectionInteractionReducer_1 = require("../SheetSelectionInteractionReducer");
|
|
49
|
+
const SheetRangeMoveCommands_1 = require("../SheetRangeMoveCommands");
|
|
50
|
+
const resolveSheetRangeMove_1 = require("../resolveSheetRangeMove");
|
|
51
|
+
const AnalyzeSheetRangeMove_1 = require("../AnalyzeSheetRangeMove");
|
|
52
|
+
const SheetRangeMoveError_1 = require("../SheetRangeMoveError");
|
|
53
|
+
const SheetRangeDrag_1 = require("../SheetRangeDrag");
|
|
54
|
+
const SheetFillRangeCommand_1 = require("../SheetFillRangeCommand");
|
|
55
|
+
const SheetSelectionPointerCommand_1 = require("../SheetSelectionPointerCommand");
|
|
56
|
+
const sear_assembly_commands_1 = require("@searsuite/sear-assembly-commands");
|
|
57
|
+
const SheetSelectionCommands_1 = require("../SheetSelectionCommands");
|
|
58
|
+
const key = new sear_assembly_plugin_1.PluginKey('SheetSelection');
|
|
59
|
+
/** Stable session-state identity owned by SheetSelectionPlugin. */
|
|
60
|
+
exports.SheetSelectionSessionStateDefinition = (0, sear_assembly_plugin_1.defineSessionState)('sheet.selection');
|
|
61
|
+
exports.SheetAdditionalSelectionsSessionStateDefinition = (0, sear_assembly_plugin_1.defineSessionState)('sheet.selection.additional');
|
|
62
|
+
const sheetSelectionPluginConfig = {
|
|
63
|
+
defaultBorderColor: 'rgba(56, 110, 246, 1)',
|
|
64
|
+
// defaultBackgroundColor: 'rgba(0, 120, 215, 0.3)',
|
|
65
|
+
};
|
|
66
|
+
function readSheetGeometry(dataEngine) {
|
|
67
|
+
const rowSizes = (0, sear_render_engine_1.readSheetRowSizes)(dataEngine);
|
|
68
|
+
const columnSizes = (0, sear_render_engine_1.readSheetColumnSizes)(dataEngine);
|
|
69
|
+
return rowSizes && columnSizes ? { rowSizes, columnSizes } : null;
|
|
70
|
+
}
|
|
71
|
+
function selectionPointerInput(action, event) {
|
|
72
|
+
var _a;
|
|
73
|
+
const properties = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.properties;
|
|
74
|
+
const origin = event === null || event === void 0 ? void 0 : event.origin;
|
|
75
|
+
return Object.assign(Object.assign({ action, target: properties
|
|
76
|
+
? {
|
|
77
|
+
region: properties.region,
|
|
78
|
+
startRowIndex: properties.startRowIndex,
|
|
79
|
+
startColIndex: properties.startColIndex,
|
|
80
|
+
endRowIndex: properties.endRowIndex,
|
|
81
|
+
endColIndex: properties.endColIndex,
|
|
82
|
+
}
|
|
83
|
+
: null }, (typeof (origin === null || origin === void 0 ? void 0 : origin.offsetX) === 'number' && typeof origin.offsetY === 'number'
|
|
84
|
+
? { view: { x: origin.offsetX, y: origin.offsetY } }
|
|
85
|
+
: {})), { shiftKey: Boolean(origin === null || origin === void 0 ? void 0 : origin.shiftKey), metaKey: Boolean(origin === null || origin === void 0 ? void 0 : origin.metaKey), ctrlKey: Boolean(origin === null || origin === void 0 ? void 0 : origin.ctrlKey) });
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Owns the active Sheet range, additional ranges, and selection navigation.
|
|
89
|
+
*
|
|
90
|
+
* Pointer and keyboard input reach this plugin through registered commands.
|
|
91
|
+
* It keeps selection values in editor session state, publishes typed queries
|
|
92
|
+
* and observations for hosts, and contributes the visual highlight. Hosts
|
|
93
|
+
* should use those public contracts instead of reading plugin fields.
|
|
94
|
+
*/
|
|
95
|
+
let SheetSelectionPlugin = class SheetSelectionPlugin extends sear_assembly_plugin_1.Plugin {
|
|
96
|
+
/** Returns the plugin config. */
|
|
97
|
+
getPluginConfig(searCore) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
/** Creates a SheetSelectionPlugin instance. */
|
|
101
|
+
constructor(sheetCellMergePlugin, keyboardRouter, platform, interactionReducers, commands, rangeMoves, rangeDrag, highlights, inputValidation, pointerCapture, textInput, formats) {
|
|
102
|
+
super({
|
|
103
|
+
key: key,
|
|
104
|
+
state: [(0, sear_foundation_rect_1.createEmptyRect)(), (0, sear_foundation_rect_1.createEmptyRect)()],
|
|
105
|
+
});
|
|
106
|
+
_SheetSelectionPlugin_instances.add(this);
|
|
107
|
+
this.keyboardRouter = keyboardRouter;
|
|
108
|
+
this.platform = platform;
|
|
109
|
+
this.rangeMoves = rangeMoves;
|
|
110
|
+
this.rangeDrag = rangeDrag;
|
|
111
|
+
this.highlights = highlights;
|
|
112
|
+
this.inputValidation = inputValidation;
|
|
113
|
+
this.pointerCapture = pointerCapture;
|
|
114
|
+
this.textInput = textInput;
|
|
115
|
+
this.formats = formats;
|
|
116
|
+
_SheetSelectionPlugin_isSelecting.set(this, false);
|
|
117
|
+
_SheetSelectionPlugin_selectionPointer.set(this, null);
|
|
118
|
+
_SheetSelectionPlugin_selectionScrollFrame.set(this, null);
|
|
119
|
+
_SheetSelectionPlugin_disposeSelectionCapture.set(this, null);
|
|
120
|
+
_SheetSelectionPlugin_additionalRanges.set(this, []);
|
|
121
|
+
_SheetSelectionPlugin_disposeAdditionalHighlight.set(this, null);
|
|
122
|
+
_SheetSelectionPlugin_headerDragMode.set(this, 'none');
|
|
123
|
+
/** The cell that was originally clicked — used as the fixed anchor for Shift+arrow multi-select. */
|
|
124
|
+
_SheetSelectionPlugin_selectionOrigin.set(this, null);
|
|
125
|
+
/** The current cursor position during Shift+arrow extension — tracks the moving end independently of the displayed range. */
|
|
126
|
+
_SheetSelectionPlugin_selectionCursor.set(this, null);
|
|
127
|
+
_SheetSelectionPlugin_commandCore.set(this, null);
|
|
128
|
+
_SheetSelectionPlugin_core.set(this, null);
|
|
129
|
+
_SheetSelectionPlugin_queries.set(this, null);
|
|
130
|
+
_SheetSelectionPlugin_commands.set(this, void 0);
|
|
131
|
+
_SheetSelectionPlugin_rangeDragOwnerToken.set(this, {});
|
|
132
|
+
/** Optional merge capability used to normalize selection movement. */
|
|
133
|
+
_SheetSelectionPlugin_sheetCellMergePlugin.set(this, void 0);
|
|
134
|
+
/** @inheritdoc */
|
|
135
|
+
this.depth = -1;
|
|
136
|
+
/** @inheritdoc */
|
|
137
|
+
this.interestedIn = [
|
|
138
|
+
sear_domain_ot_1.MatrixOTActionName.ResizeRow,
|
|
139
|
+
sear_domain_ot_1.MatrixOTActionName.ResizeCol,
|
|
140
|
+
sear_domain_ot_1.MatrixOTActionName.RowInsert,
|
|
141
|
+
sear_domain_ot_1.MatrixOTActionName.RowDelete,
|
|
142
|
+
sear_domain_ot_1.MatrixOTActionName.RowMove,
|
|
143
|
+
sear_domain_ot_1.MatrixOTActionName.ColInsert,
|
|
144
|
+
sear_domain_ot_1.MatrixOTActionName.ColDelete,
|
|
145
|
+
sear_domain_ot_1.MatrixOTActionName.ColMove,
|
|
146
|
+
];
|
|
147
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_commands, commands, "f");
|
|
148
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_sheetCellMergePlugin, sheetCellMergePlugin, "f");
|
|
149
|
+
if (interactionReducers)
|
|
150
|
+
(0, SheetSelectionInteractionReducer_1.registerSheetSelectionInteractionReducers)(interactionReducers);
|
|
151
|
+
this.subscribeNavigationHandlers();
|
|
152
|
+
this.keyboardRouter.startListener();
|
|
153
|
+
}
|
|
154
|
+
/** Binds this plugin to the core owned by its editor-local container. */
|
|
155
|
+
bindCore(core) {
|
|
156
|
+
var _a;
|
|
157
|
+
__classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_bindCoreReference).call(this, core);
|
|
158
|
+
(_a = this.rangeDrag) === null || _a === void 0 ? void 0 : _a.bind(core, () => this.getState()[1], __classPrivateFieldGet(this, _SheetSelectionPlugin_rangeDragOwnerToken, "f"));
|
|
159
|
+
if (this.highlights && !__classPrivateFieldGet(this, _SheetSelectionPlugin_disposeAdditionalHighlight, "f")) {
|
|
160
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_disposeAdditionalHighlight, this.highlights.register({
|
|
161
|
+
key: 'sheet.selection.additional',
|
|
162
|
+
getHighlights: () => __classPrivateFieldGet(this, _SheetSelectionPlugin_additionalRanges, "f").map((range) => ({
|
|
163
|
+
start: [...range.getPoint(0)],
|
|
164
|
+
end: [...range.getPoint(1)],
|
|
165
|
+
stroke: sheetSelectionPluginConfig.defaultBorderColor,
|
|
166
|
+
strokeWidth: 2,
|
|
167
|
+
skipHit: true,
|
|
168
|
+
overlay: true,
|
|
169
|
+
})),
|
|
170
|
+
}), "f");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/** Registers the active selection as a typed query rather than a DataEngine field. */
|
|
174
|
+
registerQueries(queries) {
|
|
175
|
+
this.assertRuntimeWriteAllowed();
|
|
176
|
+
if (__classPrivateFieldGet(this, _SheetSelectionPlugin_queries, "f") && __classPrivateFieldGet(this, _SheetSelectionPlugin_queries, "f") !== queries) {
|
|
177
|
+
throw new sear_foundation_error_1.SearError('Sheet selection queries are already bound to an editor.');
|
|
178
|
+
}
|
|
179
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_queries, queries, "f");
|
|
180
|
+
if (this.rangeMoves) {
|
|
181
|
+
queries.register(AnalyzeSheetRangeMove_1.AnalyzeSheetRangeMove, (input) => this.analyzeRangeMove(input));
|
|
182
|
+
queries.register(SheetRangeMoveCommands_1.GetSheetRangeMoveConflict, (input) => {
|
|
183
|
+
const analysis = this.analyzeRangeMove(input);
|
|
184
|
+
if (analysis.status === sear_assembly_plugin_1.SheetRangeMoveStatus.Blocked)
|
|
185
|
+
throw new sear_assembly_plugin_1.SheetRangeMoveRejectedError(analysis);
|
|
186
|
+
return analysis.status === sear_assembly_plugin_1.SheetRangeMoveStatus.RequiresConfirmation;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
queries.register(GetActiveCell_1.GetActiveCell, () => {
|
|
190
|
+
const point = this.getState()[0].getPoint(0);
|
|
191
|
+
return point[0] < 0 || point[1] < 0 ? null : [...point];
|
|
192
|
+
});
|
|
193
|
+
(0, SheetSelectionCommands_1.registerSelectionQueries)(queries, () => {
|
|
194
|
+
const selection = this.getState();
|
|
195
|
+
const start = selection[1].getPoint(0);
|
|
196
|
+
const end = selection[1].getPoint(1);
|
|
197
|
+
if (start[0] < 0 || start[1] < 0 || end[0] < 0 || end[1] < 0)
|
|
198
|
+
return null;
|
|
199
|
+
return { start: [...start], end: [...end] };
|
|
200
|
+
});
|
|
201
|
+
queries.register(SheetSelectionCommands_1.GetSelections, () => {
|
|
202
|
+
const ranges = [...__classPrivateFieldGet(this, _SheetSelectionPlugin_additionalRanges, "f"), this.getState()[1]];
|
|
203
|
+
return ranges
|
|
204
|
+
.filter((range) => range.getPoint(0)[0] >= 0)
|
|
205
|
+
.map((range) => ({
|
|
206
|
+
start: [...range.getPoint(0)],
|
|
207
|
+
end: [...range.getPoint(1)],
|
|
208
|
+
}));
|
|
209
|
+
});
|
|
210
|
+
queries.register(SheetSelectionCommands_1.GetSelectionNavigation, () => ({
|
|
211
|
+
origin: __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionOrigin, "f") ? [...__classPrivateFieldGet(this, _SheetSelectionPlugin_selectionOrigin, "f")] : null,
|
|
212
|
+
cursor: __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionCursor, "f") ? [...__classPrivateFieldGet(this, _SheetSelectionPlugin_selectionCursor, "f")] : null,
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
/** Registers selection-owned local remount state. */
|
|
216
|
+
registerSessionState(registry) {
|
|
217
|
+
this.registerOwnedSessionState(registry, () => {
|
|
218
|
+
registry.register(exports.SheetSelectionSessionStateDefinition, {
|
|
219
|
+
restorePhase: sear_assembly_plugin_1.SessionStateRestorePhase.BeforeInitialize,
|
|
220
|
+
capture: __classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_captureSessionState).bind(this),
|
|
221
|
+
restore: (selection) => {
|
|
222
|
+
sear_assembly_plugin_1.SessionStateRegistry.prototype.assertRestorationOpen.call(registry);
|
|
223
|
+
__classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_restoreSessionState).call(this, selection);
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
registry.register(exports.SheetAdditionalSelectionsSessionStateDefinition, {
|
|
227
|
+
restorePhase: sear_assembly_plugin_1.SessionStateRestorePhase.BeforeInitialize,
|
|
228
|
+
capture: () => __classPrivateFieldGet(this, _SheetSelectionPlugin_additionalRanges, "f").map((range) => range.clone()),
|
|
229
|
+
restore: (ranges) => {
|
|
230
|
+
var _a;
|
|
231
|
+
sear_assembly_plugin_1.SessionStateRegistry.prototype.assertRestorationOpen.call(registry);
|
|
232
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_additionalRanges, ranges.map((range) => range.clone()), "f");
|
|
233
|
+
(_a = this.highlights) === null || _a === void 0 ? void 0 : _a.invalidate();
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
requireCore() {
|
|
239
|
+
if (!__classPrivateFieldGet(this, _SheetSelectionPlugin_core, "f"))
|
|
240
|
+
throw new sear_foundation_error_1.SearError('SheetSelectionPlugin is not bound to a Sheet editor core.');
|
|
241
|
+
return __classPrivateFieldGet(this, _SheetSelectionPlugin_core, "f");
|
|
242
|
+
}
|
|
243
|
+
/** Returns whether in merged cell. */
|
|
244
|
+
isInMergedCell(rangeRect) {
|
|
245
|
+
loop: for (let rowIndex = rangeRect.getPoint(0)[0]; rowIndex <= rangeRect.getPoint(1)[0]; rowIndex++) {
|
|
246
|
+
for (let colIndex = rangeRect.getPoint(0)[1]; colIndex <= rangeRect.getPoint(1)[1]; colIndex++) {
|
|
247
|
+
const mergedCell = __classPrivateFieldGet(this, _SheetSelectionPlugin_sheetCellMergePlugin, "f").isMergedCell(rowIndex, colIndex);
|
|
248
|
+
if (mergedCell && !sear_foundation_rect_1.Rect.contains(rangeRect, mergedCell))
|
|
249
|
+
return mergedCell;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
/** Handles the dbl click lifecycle event. */
|
|
255
|
+
onDblClick(searCore, event) {
|
|
256
|
+
if (this.onFillHandleDoubleClick(event))
|
|
257
|
+
return false;
|
|
258
|
+
// Double-click selection behavior intentionally mirrors `onMouseDown`.
|
|
259
|
+
// `mouseDown` already updates anchor/focus before `dblClick` fires.
|
|
260
|
+
// SheetCellEditorPlugin may consume `dblClick` by returning `false`; this path remains as fallback.
|
|
261
|
+
return this.onMouseDown(searCore, event);
|
|
262
|
+
}
|
|
263
|
+
/** Lets the editor distinguish the fill handle from a cell-body double click. */
|
|
264
|
+
onFillHandleDoubleClick(event) {
|
|
265
|
+
var _a, _b;
|
|
266
|
+
return (_b = (_a = this.rangeDrag) === null || _a === void 0 ? void 0 : _a.onFillHandleDoubleClick(event)) !== null && _b !== void 0 ? _b : false;
|
|
267
|
+
}
|
|
268
|
+
/** Handles the mouse down lifecycle event. */
|
|
269
|
+
onMouseDown(searCore, event) {
|
|
270
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
271
|
+
if (((_a = event.origin) === null || _a === void 0 ? void 0 : _a.button) === 2 && event.target) {
|
|
272
|
+
const { region, startRowIndex, startColIndex } = event.target.properties;
|
|
273
|
+
const range = this.getState()[1];
|
|
274
|
+
const start = range.getPoint(0);
|
|
275
|
+
const end = range.getPoint(1);
|
|
276
|
+
const insideRows = startRowIndex !== void 0 && startRowIndex >= start[0] && startRowIndex <= end[0];
|
|
277
|
+
const inside = region === sear_render_registry_1.CellRegion.Grid
|
|
278
|
+
? insideRows && startColIndex !== void 0 && startColIndex >= start[1] && startColIndex <= end[1]
|
|
279
|
+
: region === sear_render_registry_1.CellRegion.RowHeader &&
|
|
280
|
+
insideRows &&
|
|
281
|
+
start[1] === 0 &&
|
|
282
|
+
end[1] === ((_c = (_b = readSheetGeometry(searCore.getDataEngine())) === null || _b === void 0 ? void 0 : _b.columnSizes.shape[1]) !== null && _c !== void 0 ? _c : 0) - 1;
|
|
283
|
+
if (inside)
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
const additive = Boolean((((_d = event.origin) === null || _d === void 0 ? void 0 : _d.metaKey) || ((_e = event.origin) === null || _e === void 0 ? void 0 : _e.ctrlKey)) && ((_f = event.target) === null || _f === void 0 ? void 0 : _f.properties.region) === sear_render_registry_1.CellRegion.Grid);
|
|
287
|
+
if (!additive && ((_g = this.rangeDrag) === null || _g === void 0 ? void 0 : _g.onMouseDown(event)))
|
|
288
|
+
return false;
|
|
289
|
+
return __classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_dispatchPointerInput).call(this, searCore, selectionPointerInput(SheetSelectionPointerCommand_1.SheetSelectionPointerAction.Down, event));
|
|
290
|
+
}
|
|
291
|
+
/** Handles the mouse move lifecycle event. */
|
|
292
|
+
onMouseMove(searCore, event) {
|
|
293
|
+
var _a;
|
|
294
|
+
if ((_a = this.rangeDrag) === null || _a === void 0 ? void 0 : _a.isActive())
|
|
295
|
+
return false;
|
|
296
|
+
if (!__classPrivateFieldGet(this, _SheetSelectionPlugin_isSelecting, "f"))
|
|
297
|
+
return;
|
|
298
|
+
return __classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_dispatchPointerInput).call(this, searCore, selectionPointerInput(SheetSelectionPointerCommand_1.SheetSelectionPointerAction.Move, event));
|
|
299
|
+
}
|
|
300
|
+
/** Handles the mouse up lifecycle event. */
|
|
301
|
+
onMouseUp(_searCore, _event) {
|
|
302
|
+
if (!__classPrivateFieldGet(this, _SheetSelectionPlugin_isSelecting, "f") && __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionScrollFrame, "f") === null)
|
|
303
|
+
return;
|
|
304
|
+
return __classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_dispatchPointerInput).call(this, _searCore, selectionPointerInput(SheetSelectionPointerCommand_1.SheetSelectionPointerAction.Up));
|
|
305
|
+
}
|
|
306
|
+
scheduleSelectionScroll() {
|
|
307
|
+
if (!this.platform || __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionScrollFrame, "f") !== null || !__classPrivateFieldGet(this, _SheetSelectionPlugin_selectionPointer, "f"))
|
|
308
|
+
return;
|
|
309
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionScrollFrame, this.platform.requestAnimationFrame(() => {
|
|
310
|
+
if (this.hasStateWriteBoundary()) {
|
|
311
|
+
if (!__classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f"))
|
|
312
|
+
throw new sear_foundation_error_1.SearError('Sheet selection pointer command is unavailable.');
|
|
313
|
+
__classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f").run(SheetSelectionPointerCommand_1.HandleSheetSelectionPointerCommand, {
|
|
314
|
+
action: SheetSelectionPointerCommand_1.SheetSelectionPointerAction.Tick,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionScrollFrame, null, "f");
|
|
319
|
+
this.advanceSelectionScroll();
|
|
320
|
+
}
|
|
321
|
+
}), "f");
|
|
322
|
+
}
|
|
323
|
+
advanceSelectionScroll() {
|
|
324
|
+
var _a, _b, _c, _d;
|
|
325
|
+
if (!__classPrivateFieldGet(this, _SheetSelectionPlugin_isSelecting, "f") || !__classPrivateFieldGet(this, _SheetSelectionPlugin_selectionPointer, "f"))
|
|
326
|
+
return;
|
|
327
|
+
const core = this.requireCore();
|
|
328
|
+
const geometry = readSheetGeometry(core.getDataEngine());
|
|
329
|
+
if (!geometry)
|
|
330
|
+
return;
|
|
331
|
+
const scroll = core.renderEngine.scrollManager;
|
|
332
|
+
const [width, height] = scroll.getShape();
|
|
333
|
+
const config = core.configEngine.getDefaultConfig();
|
|
334
|
+
const xOffset = (_a = config.sheetOffsetX) !== null && _a !== void 0 ? _a : 50;
|
|
335
|
+
const yOffset = (_b = config.sheetOffsetY) !== null && _b !== void 0 ? _b : 24;
|
|
336
|
+
const pointer = __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionPointer, "f");
|
|
337
|
+
const speed = (position, start, end) => position < start + 24 ? -12 : position > end - 24 ? 12 : 0;
|
|
338
|
+
const dx = __classPrivateFieldGet(this, _SheetSelectionPlugin_headerDragMode, "f") === 'row' ? 0 : speed(pointer.x, xOffset, width);
|
|
339
|
+
const dy = __classPrivateFieldGet(this, _SheetSelectionPlugin_headerDragMode, "f") === 'col' ? 0 : speed(pointer.y, yOffset, height);
|
|
340
|
+
if (!dx && !dy)
|
|
341
|
+
return;
|
|
342
|
+
const before = scroll.getState();
|
|
343
|
+
scroll.requestScrollTo(before.x + dx, before.y + dy);
|
|
344
|
+
const after = scroll.getState();
|
|
345
|
+
if (after.x === before.x && after.y === before.y)
|
|
346
|
+
return;
|
|
347
|
+
{
|
|
348
|
+
const rowPosition = after.y + Math.max(0, Math.min(height - yOffset - 1, pointer.y - yOffset));
|
|
349
|
+
const colPosition = after.x + Math.max(0, Math.min(width - xOffset - 1, pointer.x - xOffset));
|
|
350
|
+
const row = Math.min(geometry.rowSizes.shape[1] - 1, geometry.rowSizes.getLeftBoundaryColIndexByDimension(rowPosition));
|
|
351
|
+
const col = Math.min(geometry.columnSizes.shape[1] - 1, geometry.columnSizes.getLeftBoundaryColIndexByDimension(colPosition));
|
|
352
|
+
const anchor = (_c = __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionOrigin, "f")) !== null && _c !== void 0 ? _c : this.getState()[0].getPoint(0);
|
|
353
|
+
const end = __classPrivateFieldGet(this, _SheetSelectionPlugin_headerDragMode, "f") === 'row'
|
|
354
|
+
? [row, geometry.columnSizes.shape[1] - 1]
|
|
355
|
+
: __classPrivateFieldGet(this, _SheetSelectionPlugin_headerDragMode, "f") === 'col'
|
|
356
|
+
? [geometry.rowSizes.shape[1] - 1, col]
|
|
357
|
+
: [row, col];
|
|
358
|
+
const start = __classPrivateFieldGet(this, _SheetSelectionPlugin_headerDragMode, "f") === 'row' ? [anchor[0], 0] : __classPrivateFieldGet(this, _SheetSelectionPlugin_headerDragMode, "f") === 'col' ? [0, anchor[1]] : [...anchor];
|
|
359
|
+
this.executeSelectionCommand(core, start, end, SheetSelectionPipelineNames_1.SheetSelectionSource.Pointer, false, start, end, void 0, {
|
|
360
|
+
origin: (_d = __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionOrigin, "f")) !== null && _d !== void 0 ? _d : start,
|
|
361
|
+
cursor: end,
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
this.scheduleSelectionScroll();
|
|
365
|
+
}
|
|
366
|
+
findMergedSelectionRange(point) {
|
|
367
|
+
const merge = __classPrivateFieldGet(this, _SheetSelectionPlugin_sheetCellMergePlugin, "f").isMergedCell(point[0], point[1]);
|
|
368
|
+
return merge ? { start: merge.getPoint(0), end: merge.getPoint(1) } : void 0;
|
|
369
|
+
}
|
|
370
|
+
// ─── Arrow / Enter key navigation ────────────────────────────────────────
|
|
371
|
+
subscribeNavigationHandlers() {
|
|
372
|
+
this.keyboardRouter.subscribe({
|
|
373
|
+
onDelete: this.handleSelectionDeleteKey.bind(this),
|
|
374
|
+
onSelectAll: this.handleSelectionSelectAllKey.bind(this),
|
|
375
|
+
onHome: this.handleSelectionHomeKey.bind(this),
|
|
376
|
+
onEnd: this.handleSelectionEndKey.bind(this),
|
|
377
|
+
onPage: this.handleSelectionPageKey.bind(this),
|
|
378
|
+
onHorizontalPage: this.handleSelectionHorizontalPageKey.bind(this),
|
|
379
|
+
onSelectRow: this.handleSelectionSelectRowKey.bind(this),
|
|
380
|
+
onSelectColumn: this.handleSelectionSelectColumnKey.bind(this),
|
|
381
|
+
onEnter: this.handleSelectionEnterKey.bind(this),
|
|
382
|
+
onArrowDown: this.handleSelectionArrowDown.bind(this),
|
|
383
|
+
onArrowUp: this.handleSelectionArrowUp.bind(this),
|
|
384
|
+
onArrowLeft: this.handleSelectionArrowLeft.bind(this),
|
|
385
|
+
onArrowRight: this.handleSelectionArrowRight.bind(this),
|
|
386
|
+
onTab: this.handleSelectionTabKey.bind(this),
|
|
387
|
+
onFillDown: () => this.fillSelectionFromEdge('down'),
|
|
388
|
+
onFillRight: () => this.fillSelectionFromEdge('right'),
|
|
389
|
+
onCopyFormulaAbove: () => this.copyFormulaFromAbove(),
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
fillSelectionFromEdge(direction) {
|
|
393
|
+
var _a;
|
|
394
|
+
if (__classPrivateFieldGet(this, _SheetSelectionPlugin_additionalRanges, "f").length)
|
|
395
|
+
return;
|
|
396
|
+
const range = this.getState()[1];
|
|
397
|
+
const anchor = range.getPoint(0);
|
|
398
|
+
const focus = range.getPoint(1);
|
|
399
|
+
if (anchor[0] < 0 || anchor[1] < 0)
|
|
400
|
+
return;
|
|
401
|
+
const top = Math.min(anchor[0], focus[0]);
|
|
402
|
+
const bottom = Math.max(anchor[0], focus[0]);
|
|
403
|
+
const left = Math.min(anchor[1], focus[1]);
|
|
404
|
+
const right = Math.max(anchor[1], focus[1]);
|
|
405
|
+
if (direction === 'down' && top === bottom)
|
|
406
|
+
return;
|
|
407
|
+
if (direction === 'right' && left === right)
|
|
408
|
+
return;
|
|
409
|
+
(_a = __classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f")) === null || _a === void 0 ? void 0 : _a.run(SheetFillRangeCommand_1.FillSheetRangeCommand, {
|
|
410
|
+
source: direction === 'down'
|
|
411
|
+
? { start: [top, left], end: [top, right] }
|
|
412
|
+
: { start: [top, left], end: [bottom, left] },
|
|
413
|
+
target: [bottom, right],
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
copyFormulaFromAbove() {
|
|
417
|
+
var _a, _b, _c;
|
|
418
|
+
if (__classPrivateFieldGet(this, _SheetSelectionPlugin_additionalRanges, "f").length)
|
|
419
|
+
return;
|
|
420
|
+
const range = this.getState()[1];
|
|
421
|
+
const cell = range.getPoint(0);
|
|
422
|
+
if (cell[0] <= 0 || cell[1] < 0 || cell.some((value, index) => value !== range.getPoint(1)[index]))
|
|
423
|
+
return;
|
|
424
|
+
if (((_b = (_a = this.readCells()) === null || _a === void 0 ? void 0 : _a.getItem(cell[0] - 1, cell[1])) === null || _b === void 0 ? void 0 : _b.type) !== sear_domain_cell_types_1.CellType.Formula)
|
|
425
|
+
return;
|
|
426
|
+
const above = [cell[0] - 1, cell[1]];
|
|
427
|
+
(_c = __classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f")) === null || _c === void 0 ? void 0 : _c.run(SheetFillRangeCommand_1.FillSheetRangeCommand, {
|
|
428
|
+
source: { start: above, end: above }, target: cell, mode: 'exact',
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
handleSelectionDeleteKey() {
|
|
432
|
+
var _a, _b;
|
|
433
|
+
if (__classPrivateFieldGet(this, _SheetSelectionPlugin_additionalRanges, "f").length) {
|
|
434
|
+
(_a = __classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f")) === null || _a === void 0 ? void 0 : _a.run(SheetSelectionCommands_1.ClearSelectedContentsCommand, void 0);
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
const range = this.getState()[1];
|
|
438
|
+
const anchor = range.getPoint(0);
|
|
439
|
+
const focus = range.getPoint(1);
|
|
440
|
+
if (anchor[0] < 0 || focus[0] < 0)
|
|
441
|
+
return;
|
|
442
|
+
(_b = __classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f")) === null || _b === void 0 ? void 0 : _b.run(sear_assembly_commands_1.ClearRangeContentsCommand, { anchor, focus });
|
|
443
|
+
}
|
|
444
|
+
handleSelectionSelectAllKey() {
|
|
445
|
+
const core = this.requireCore();
|
|
446
|
+
const geometry = readSheetGeometry(core.getDataEngine());
|
|
447
|
+
if (!geometry || geometry.rowSizes.shape[1] === 0 || geometry.columnSizes.shape[1] === 0)
|
|
448
|
+
return;
|
|
449
|
+
const current = this.getState();
|
|
450
|
+
const active = current[0].getPoint(0);
|
|
451
|
+
const cells = this.readCells();
|
|
452
|
+
const occupied = (row, col) => {
|
|
453
|
+
const cell = cells === null || cells === void 0 ? void 0 : cells.getItem(row, col);
|
|
454
|
+
return cell != null && (cell.value != null || Boolean(cell.formula));
|
|
455
|
+
};
|
|
456
|
+
const rowHasData = (row, left, right) => {
|
|
457
|
+
for (let col = left; col <= right; col++)
|
|
458
|
+
if (occupied(row, col))
|
|
459
|
+
return true;
|
|
460
|
+
return false;
|
|
461
|
+
};
|
|
462
|
+
const columnHasData = (col, top, bottom) => {
|
|
463
|
+
for (let row = top; row <= bottom; row++)
|
|
464
|
+
if (occupied(row, col))
|
|
465
|
+
return true;
|
|
466
|
+
return false;
|
|
467
|
+
};
|
|
468
|
+
if (active[0] >= 0 && occupied(active[0], active[1])) {
|
|
469
|
+
let top = active[0];
|
|
470
|
+
let bottom = top;
|
|
471
|
+
let left = active[1];
|
|
472
|
+
let right = left;
|
|
473
|
+
let expanded;
|
|
474
|
+
do {
|
|
475
|
+
expanded = false;
|
|
476
|
+
if (top > 0 && rowHasData(top - 1, left, right)) {
|
|
477
|
+
top--;
|
|
478
|
+
expanded = true;
|
|
479
|
+
}
|
|
480
|
+
if (bottom < geometry.rowSizes.shape[1] - 1 && rowHasData(bottom + 1, left, right)) {
|
|
481
|
+
bottom++;
|
|
482
|
+
expanded = true;
|
|
483
|
+
}
|
|
484
|
+
if (left > 0 && columnHasData(left - 1, top, bottom)) {
|
|
485
|
+
left--;
|
|
486
|
+
expanded = true;
|
|
487
|
+
}
|
|
488
|
+
if (right < geometry.columnSizes.shape[1] - 1 && columnHasData(right + 1, top, bottom)) {
|
|
489
|
+
right++;
|
|
490
|
+
expanded = true;
|
|
491
|
+
}
|
|
492
|
+
} while (expanded);
|
|
493
|
+
const selectedStart = current[1].getPoint(0);
|
|
494
|
+
const selectedEnd = current[1].getPoint(1);
|
|
495
|
+
if ((top !== bottom || left !== right) &&
|
|
496
|
+
(selectedStart[0] !== top || selectedStart[1] !== left || selectedEnd[0] !== bottom || selectedEnd[1] !== right)) {
|
|
497
|
+
this.executeSelectionCommand(core, [top, left], [bottom, right], SheetSelectionPipelineNames_1.SheetSelectionSource.Keyboard);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
this.executeSelectionCommand(core, [0, 0], [geometry.rowSizes.shape[1] - 1, geometry.columnSizes.shape[1] - 1], SheetSelectionPipelineNames_1.SheetSelectionSource.Keyboard);
|
|
502
|
+
}
|
|
503
|
+
handleSelectionHomeKey(primaryModifier, shiftKey) {
|
|
504
|
+
var _a;
|
|
505
|
+
const cell = shiftKey ? (_a = __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionCursor, "f")) !== null && _a !== void 0 ? _a : this.getState()[0].getPoint(0) : this.getState()[0].getPoint(0);
|
|
506
|
+
if (cell[0] < 0)
|
|
507
|
+
return;
|
|
508
|
+
const target = [primaryModifier ? 0 : cell[0], 0];
|
|
509
|
+
this.selectNavigationTarget(target, shiftKey);
|
|
510
|
+
}
|
|
511
|
+
readCells() {
|
|
512
|
+
var _a;
|
|
513
|
+
return ((_a = __classPrivateFieldGet(this, _SheetSelectionPlugin_queries, "f")) === null || _a === void 0 ? void 0 : _a.has(sear_render_engine_1.ReadSheetCellDataQuery)) ? __classPrivateFieldGet(this, _SheetSelectionPlugin_queries, "f").run(sear_render_engine_1.ReadSheetCellDataQuery, void 0) : null;
|
|
514
|
+
}
|
|
515
|
+
handleSelectionEndKey(shiftKey) {
|
|
516
|
+
var _a;
|
|
517
|
+
const cells = this.readCells();
|
|
518
|
+
if (!(cells === null || cells === void 0 ? void 0 : cells.forEachStoredInRange) || cells.shape[0] === 0 || cells.shape[1] === 0)
|
|
519
|
+
return;
|
|
520
|
+
let row = 0;
|
|
521
|
+
let col = 0;
|
|
522
|
+
cells.forEachStoredInRange(0, 0, cells.shape[0] - 1, cells.shape[1] - 1, (cell, cellRow, cellCol) => {
|
|
523
|
+
if (cell.value == null && !cell.formula)
|
|
524
|
+
return;
|
|
525
|
+
row = Math.max(row, cellRow);
|
|
526
|
+
col = Math.max(col, cellCol);
|
|
527
|
+
});
|
|
528
|
+
const formatted = (_a = this.formats) === null || _a === void 0 ? void 0 : _a.usedExtent(cells.shape[0] - 1, cells.shape[1] - 1);
|
|
529
|
+
if (formatted) {
|
|
530
|
+
row = Math.max(row, formatted[0]);
|
|
531
|
+
col = Math.max(col, formatted[1]);
|
|
532
|
+
}
|
|
533
|
+
const target = [row, col];
|
|
534
|
+
this.selectNavigationTarget(target, shiftKey);
|
|
535
|
+
}
|
|
536
|
+
handleSelectionPageKey(direction, shiftKey) {
|
|
537
|
+
var _a, _b;
|
|
538
|
+
const core = this.requireCore();
|
|
539
|
+
const geometry = readSheetGeometry(core.getDataEngine());
|
|
540
|
+
const cell = shiftKey ? (_a = __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionCursor, "f")) !== null && _a !== void 0 ? _a : this.getState()[0].getPoint(0) : this.getState()[0].getPoint(0);
|
|
541
|
+
if (!geometry || cell[0] < 0)
|
|
542
|
+
return;
|
|
543
|
+
const rows = geometry.rowSizes;
|
|
544
|
+
const scrollManager = core.renderEngine.scrollManager;
|
|
545
|
+
const viewportHeight = scrollManager.getShape()[1];
|
|
546
|
+
const scroll = scrollManager.getState();
|
|
547
|
+
const sheetOffset = (_b = core.configEngine.getDefaultConfig().sheetOffsetY) !== null && _b !== void 0 ? _b : 24;
|
|
548
|
+
const currentTop = rows.getDimensionLeftBoundaryByIndex(cell[0]);
|
|
549
|
+
const pageSize = Math.max(1, viewportHeight - sheetOffset);
|
|
550
|
+
const targetOffset = Math.max(0, currentTop + direction * pageSize);
|
|
551
|
+
const row = Math.max(0, Math.min(rows.shape[1] - 1, rows.getLeftBoundaryColIndexByDimension(targetOffset)));
|
|
552
|
+
const target = [row, cell[1]];
|
|
553
|
+
this.selectNavigationTarget(target, shiftKey);
|
|
554
|
+
scrollManager.requestScrollTo(scroll.x, Math.max(0, scroll.y + direction * pageSize));
|
|
555
|
+
}
|
|
556
|
+
handleSelectionHorizontalPageKey(direction, shiftKey) {
|
|
557
|
+
var _a, _b;
|
|
558
|
+
const core = this.requireCore();
|
|
559
|
+
const geometry = readSheetGeometry(core.getDataEngine());
|
|
560
|
+
const cell = shiftKey ? (_a = __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionCursor, "f")) !== null && _a !== void 0 ? _a : this.getState()[0].getPoint(0) : this.getState()[0].getPoint(0);
|
|
561
|
+
if (!geometry || cell[1] < 0)
|
|
562
|
+
return;
|
|
563
|
+
const scrollManager = core.renderEngine.scrollManager;
|
|
564
|
+
const scroll = scrollManager.getState();
|
|
565
|
+
const sheetOffset = (_b = core.configEngine.getDefaultConfig().sheetOffsetX) !== null && _b !== void 0 ? _b : 50;
|
|
566
|
+
const pageSize = Math.max(1, scrollManager.getShape()[0] - sheetOffset);
|
|
567
|
+
const columns = geometry.columnSizes;
|
|
568
|
+
const currentLeft = columns.getDimensionLeftBoundaryByIndex(cell[1]);
|
|
569
|
+
const targetOffset = Math.max(0, currentLeft + direction * pageSize);
|
|
570
|
+
const col = Math.max(0, Math.min(columns.shape[1] - 1, columns.getLeftBoundaryColIndexByDimension(targetOffset)));
|
|
571
|
+
this.selectNavigationTarget([cell[0], col], shiftKey);
|
|
572
|
+
scrollManager.requestScrollTo(Math.max(0, scroll.x + direction * pageSize), scroll.y);
|
|
573
|
+
}
|
|
574
|
+
selectNavigationTarget(target, extend) {
|
|
575
|
+
var _a;
|
|
576
|
+
const core = this.requireCore();
|
|
577
|
+
if (!extend) {
|
|
578
|
+
this.executeSelectionCommand(core, target, target, SheetSelectionPipelineNames_1.SheetSelectionSource.Keyboard, true);
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
const origin = (_a = __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionOrigin, "f")) !== null && _a !== void 0 ? _a : this.getState()[0].getPoint(0);
|
|
582
|
+
const anchor = [Math.min(origin[0], target[0]), Math.min(origin[1], target[1])];
|
|
583
|
+
const focus = [Math.max(origin[0], target[0]), Math.max(origin[1], target[1])];
|
|
584
|
+
this.executeSelectionCommand(core, anchor, focus, SheetSelectionPipelineNames_1.SheetSelectionSource.Keyboard, true, anchor, anchor, void 0, {
|
|
585
|
+
origin,
|
|
586
|
+
cursor: target,
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
findDataBoundary(cells, current, direction, lastRow, lastCol) {
|
|
590
|
+
if (!cells.forEachStoredInRange)
|
|
591
|
+
return current;
|
|
592
|
+
const vertical = direction === sear_assembly_commands_1.SelectionMoveDirection.Up || direction === sear_assembly_commands_1.SelectionMoveDirection.Down;
|
|
593
|
+
const positive = direction === sear_assembly_commands_1.SelectionMoveDirection.Down || direction === sear_assembly_commands_1.SelectionMoveDirection.Right;
|
|
594
|
+
const coordinate = vertical ? current[0] : current[1];
|
|
595
|
+
const limit = vertical ? lastRow : lastCol;
|
|
596
|
+
const currentCell = cells.getItem(current[0], current[1]);
|
|
597
|
+
const occupied = currentCell != null && (currentCell.value != null || Boolean(currentCell.formula));
|
|
598
|
+
const occupiedIndices = new Set();
|
|
599
|
+
const visit = (cell, row, col) => {
|
|
600
|
+
if (cell.value == null && !cell.formula)
|
|
601
|
+
return;
|
|
602
|
+
occupiedIndices.add(vertical ? row : col);
|
|
603
|
+
};
|
|
604
|
+
if (vertical)
|
|
605
|
+
cells.forEachStoredInRange(0, current[1], lastRow, current[1], visit);
|
|
606
|
+
else
|
|
607
|
+
cells.forEachStoredInRange(current[0], 0, current[0], lastCol, visit);
|
|
608
|
+
const step = positive ? 1 : -1;
|
|
609
|
+
let target = positive ? limit : 0;
|
|
610
|
+
if (occupied && occupiedIndices.has(coordinate + step)) {
|
|
611
|
+
target = coordinate + step;
|
|
612
|
+
while (occupiedIndices.has(target + step))
|
|
613
|
+
target += step;
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
for (const index of occupiedIndices) {
|
|
617
|
+
if (positive && index > coordinate && index < target)
|
|
618
|
+
target = index;
|
|
619
|
+
if (!positive && index < coordinate && index > target)
|
|
620
|
+
target = index;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
return vertical ? [target, current[1]] : [current[0], target];
|
|
624
|
+
}
|
|
625
|
+
handleSelectionSelectRowKey() {
|
|
626
|
+
const core = this.requireCore();
|
|
627
|
+
const range = this.getState()[1];
|
|
628
|
+
const start = range.getPoint(0);
|
|
629
|
+
const end = range.getPoint(1);
|
|
630
|
+
const geometry = readSheetGeometry(core.getDataEngine());
|
|
631
|
+
if (start[0] < 0 || !geometry)
|
|
632
|
+
return;
|
|
633
|
+
this.executeSelectionCommand(core, [start[0], 0], [end[0], geometry.columnSizes.shape[1] - 1], SheetSelectionPipelineNames_1.SheetSelectionSource.Keyboard);
|
|
634
|
+
}
|
|
635
|
+
handleSelectionSelectColumnKey() {
|
|
636
|
+
const core = this.requireCore();
|
|
637
|
+
const cell = this.getState()[0].getPoint(0);
|
|
638
|
+
const geometry = readSheetGeometry(core.getDataEngine());
|
|
639
|
+
if (cell[1] < 0 || !geometry)
|
|
640
|
+
return;
|
|
641
|
+
this.executeSelectionCommand(core, [0, cell[1]], [geometry.rowSizes.shape[1] - 1, cell[1]], SheetSelectionPipelineNames_1.SheetSelectionSource.Keyboard);
|
|
642
|
+
}
|
|
643
|
+
handleSelectionEnterKey(shiftKey) {
|
|
644
|
+
const state = this.getState();
|
|
645
|
+
const start = state[1].getPoint(0);
|
|
646
|
+
const end = state[1].getPoint(1);
|
|
647
|
+
if (start[0] >= 0 && (start[0] !== end[0] || start[1] !== end[1])) {
|
|
648
|
+
const active = state[0].getPoint(0);
|
|
649
|
+
let row = active[0] + (shiftKey ? -1 : 1);
|
|
650
|
+
let col = active[1];
|
|
651
|
+
if (row > end[0]) {
|
|
652
|
+
row = start[0];
|
|
653
|
+
col = col < end[1] ? col + 1 : start[1];
|
|
654
|
+
}
|
|
655
|
+
else if (row < start[0]) {
|
|
656
|
+
row = end[0];
|
|
657
|
+
col = col > start[1] ? col - 1 : end[1];
|
|
658
|
+
}
|
|
659
|
+
const target = [row, col];
|
|
660
|
+
this.executeSelectionCommand(this.requireCore(), [...start], [...end], SheetSelectionPipelineNames_1.SheetSelectionSource.Keyboard, false, target, target);
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
if (!shiftKey)
|
|
664
|
+
this.extendForDownwardEntry();
|
|
665
|
+
this.navigate(shiftKey ? sear_assembly_commands_1.SelectionMoveDirection.Up : sear_assembly_commands_1.SelectionMoveDirection.Down);
|
|
666
|
+
}
|
|
667
|
+
/** Returns the destination row when Enter requires a structural extension. */
|
|
668
|
+
getDownwardEntryExtensionIndex() {
|
|
669
|
+
var _a, _b;
|
|
670
|
+
const core = this.requireCore();
|
|
671
|
+
const geometry = readSheetGeometry(core.getDataEngine());
|
|
672
|
+
const row = this.getState()[0].getPoint(0)[0];
|
|
673
|
+
const lastRow = ((_a = geometry === null || geometry === void 0 ? void 0 : geometry.rowSizes.shape[1]) !== null && _a !== void 0 ? _a : 0) - 1;
|
|
674
|
+
return row >= 0 && row === lastRow && ((_b = __classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f")) === null || _b === void 0 ? void 0 : _b.has(sear_assembly_commands_1.InsertRowCommand)) ? lastRow + 1 : null;
|
|
675
|
+
}
|
|
676
|
+
/** Adds a destination row only when Enter would otherwise keep the active cell in place. */
|
|
677
|
+
extendForDownwardEntry(historyGroup) {
|
|
678
|
+
var _a;
|
|
679
|
+
const index = this.getDownwardEntryExtensionIndex();
|
|
680
|
+
if (index !== null)
|
|
681
|
+
(_a = __classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f")) === null || _a === void 0 ? void 0 : _a.run(sear_assembly_commands_1.InsertRowCommand, { index, historyGroup });
|
|
682
|
+
}
|
|
683
|
+
handleSelectionArrowDown(shiftKey, metaKey) {
|
|
684
|
+
this.navigate(sear_assembly_commands_1.SelectionMoveDirection.Down, shiftKey, metaKey);
|
|
685
|
+
}
|
|
686
|
+
handleSelectionArrowUp(shiftKey, metaKey) {
|
|
687
|
+
this.navigate(sear_assembly_commands_1.SelectionMoveDirection.Up, shiftKey, metaKey);
|
|
688
|
+
}
|
|
689
|
+
handleSelectionArrowLeft(shiftKey, metaKey) {
|
|
690
|
+
this.navigate(sear_assembly_commands_1.SelectionMoveDirection.Left, shiftKey, metaKey);
|
|
691
|
+
}
|
|
692
|
+
handleSelectionArrowRight(shiftKey, metaKey) {
|
|
693
|
+
this.navigate(sear_assembly_commands_1.SelectionMoveDirection.Right, shiftKey, metaKey);
|
|
694
|
+
}
|
|
695
|
+
handleSelectionTabKey(shiftKey) {
|
|
696
|
+
const state = this.getState();
|
|
697
|
+
const start = state[1].getPoint(0);
|
|
698
|
+
const end = state[1].getPoint(1);
|
|
699
|
+
if (start[0] < 0)
|
|
700
|
+
return;
|
|
701
|
+
const merge = this.findMergedSelectionRange(start);
|
|
702
|
+
const singleMergedCell = merge &&
|
|
703
|
+
merge.start[0] === start[0] &&
|
|
704
|
+
merge.start[1] === start[1] &&
|
|
705
|
+
merge.end[0] === end[0] &&
|
|
706
|
+
merge.end[1] === end[1];
|
|
707
|
+
if ((start[0] === end[0] && start[1] === end[1]) || singleMergedCell) {
|
|
708
|
+
if (!shiftKey)
|
|
709
|
+
this.extendForRightwardEntry();
|
|
710
|
+
this.navigate(shiftKey ? sear_assembly_commands_1.SelectionMoveDirection.Left : sear_assembly_commands_1.SelectionMoveDirection.Right);
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
const active = state[0].getPoint(0);
|
|
714
|
+
let row = active[0];
|
|
715
|
+
let col = active[1] + (shiftKey ? -1 : 1);
|
|
716
|
+
if (col > end[1]) {
|
|
717
|
+
col = start[1];
|
|
718
|
+
row = row < end[0] ? row + 1 : start[0];
|
|
719
|
+
}
|
|
720
|
+
else if (col < start[1]) {
|
|
721
|
+
col = end[1];
|
|
722
|
+
row = row > start[0] ? row - 1 : end[0];
|
|
723
|
+
}
|
|
724
|
+
const target = [row, col];
|
|
725
|
+
this.executeSelectionCommand(this.requireCore(), [...start], [...end], SheetSelectionPipelineNames_1.SheetSelectionSource.Keyboard, false, target, target);
|
|
726
|
+
}
|
|
727
|
+
/** Returns the destination column when Tab requires a structural extension. */
|
|
728
|
+
getRightwardEntryExtensionIndex() {
|
|
729
|
+
var _a, _b;
|
|
730
|
+
const core = this.requireCore();
|
|
731
|
+
const geometry = readSheetGeometry(core.getDataEngine());
|
|
732
|
+
const col = this.getState()[0].getPoint(0)[1];
|
|
733
|
+
const lastCol = ((_a = geometry === null || geometry === void 0 ? void 0 : geometry.columnSizes.shape[1]) !== null && _a !== void 0 ? _a : 0) - 1;
|
|
734
|
+
return col >= 0 && col === lastCol && ((_b = __classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f")) === null || _b === void 0 ? void 0 : _b.has(sear_assembly_commands_1.InsertColumnCommand)) ? lastCol + 1 : null;
|
|
735
|
+
}
|
|
736
|
+
/** Adds a destination column only when Tab would otherwise keep the active cell in place. */
|
|
737
|
+
extendForRightwardEntry(historyGroup) {
|
|
738
|
+
var _a;
|
|
739
|
+
const index = this.getRightwardEntryExtensionIndex();
|
|
740
|
+
if (index !== null)
|
|
741
|
+
(_a = __classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f")) === null || _a === void 0 ? void 0 : _a.run(sear_assembly_commands_1.InsertColumnCommand, { index, historyGroup });
|
|
742
|
+
}
|
|
743
|
+
/** Moves the current Sheet selection according to the requested direction. */
|
|
744
|
+
navigate(direction, shiftKey = false, metaKey = false) {
|
|
745
|
+
var _a, _b;
|
|
746
|
+
const searCore = this.requireCore();
|
|
747
|
+
const dataEngine = searCore.getDataEngine();
|
|
748
|
+
const selectionState = dataEngine.getDataType(this.pluginKey);
|
|
749
|
+
const dataState = readSheetGeometry(dataEngine);
|
|
750
|
+
if (!selectionState || !dataState)
|
|
751
|
+
return;
|
|
752
|
+
const anchor = selectionState[1].getPoint(0);
|
|
753
|
+
const focus = selectionState[1].getPoint(1);
|
|
754
|
+
if (focus[0] === -1)
|
|
755
|
+
return;
|
|
756
|
+
const lastRow = dataState.rowSizes.shape[1] - 1;
|
|
757
|
+
const lastCol = dataState.columnSizes.shape[1] - 1;
|
|
758
|
+
let nextAnchor;
|
|
759
|
+
let nextFocus;
|
|
760
|
+
let nextOrigin;
|
|
761
|
+
let nextCursor;
|
|
762
|
+
if (shiftKey) {
|
|
763
|
+
// Extend selection: selectionOrigin is the fixed anchor, selectionCursor tracks the moving end
|
|
764
|
+
const origin = (_a = __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionOrigin, "f")) !== null && _a !== void 0 ? _a : [...focus];
|
|
765
|
+
const cursor = (_b = __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionCursor, "f")) !== null && _b !== void 0 ? _b : [...focus];
|
|
766
|
+
const cells = metaKey ? this.readCells() : null;
|
|
767
|
+
const result = (0, sear_assembly_commands_1.extendSelection)(Object.assign(Object.assign({ origin,
|
|
768
|
+
cursor,
|
|
769
|
+
direction,
|
|
770
|
+
lastRow,
|
|
771
|
+
lastCol, jumpToEdge: metaKey }, ((cells === null || cells === void 0 ? void 0 : cells.forEachStoredInRange)
|
|
772
|
+
? { jumpTarget: this.findDataBoundary(cells, cursor, direction, lastRow, lastCol) }
|
|
773
|
+
: {})), { findMerge: this.findMergedSelectionRange.bind(this) }));
|
|
774
|
+
nextOrigin = origin;
|
|
775
|
+
nextCursor = result.cursor;
|
|
776
|
+
// Determine which corner is top-left vs bottom-right
|
|
777
|
+
nextAnchor = result.anchor;
|
|
778
|
+
nextFocus = result.focus;
|
|
779
|
+
}
|
|
780
|
+
else if (metaKey) {
|
|
781
|
+
// Jump to edge: move focus to the boundary
|
|
782
|
+
let targetRow = focus[0];
|
|
783
|
+
let targetCol = focus[1];
|
|
784
|
+
if (direction === sear_assembly_commands_1.SelectionMoveDirection.Down) {
|
|
785
|
+
targetRow = lastRow;
|
|
786
|
+
}
|
|
787
|
+
else if (direction === sear_assembly_commands_1.SelectionMoveDirection.Up) {
|
|
788
|
+
targetRow = 0;
|
|
789
|
+
}
|
|
790
|
+
else if (direction === sear_assembly_commands_1.SelectionMoveDirection.Right) {
|
|
791
|
+
targetCol = lastCol;
|
|
792
|
+
}
|
|
793
|
+
else {
|
|
794
|
+
targetCol = 0;
|
|
795
|
+
}
|
|
796
|
+
const cells = this.readCells();
|
|
797
|
+
const target = (cells === null || cells === void 0 ? void 0 : cells.forEachStoredInRange)
|
|
798
|
+
? this.findDataBoundary(cells, [...focus], direction, lastRow, lastCol)
|
|
799
|
+
: [targetRow, targetCol];
|
|
800
|
+
nextAnchor = target;
|
|
801
|
+
nextFocus = target;
|
|
802
|
+
nextOrigin = nextFocus;
|
|
803
|
+
nextCursor = nextFocus;
|
|
804
|
+
}
|
|
805
|
+
else {
|
|
806
|
+
const result = (0, sear_assembly_commands_1.moveSelection)({
|
|
807
|
+
focus,
|
|
808
|
+
direction,
|
|
809
|
+
lastRow,
|
|
810
|
+
lastCol,
|
|
811
|
+
findMerge: this.findMergedSelectionRange.bind(this),
|
|
812
|
+
});
|
|
813
|
+
nextAnchor = result.anchor;
|
|
814
|
+
nextFocus = result.focus;
|
|
815
|
+
nextOrigin = nextFocus;
|
|
816
|
+
nextCursor = nextFocus;
|
|
817
|
+
}
|
|
818
|
+
const rowDirection = direction === sear_assembly_commands_1.SelectionMoveDirection.Up ? -1 : 1;
|
|
819
|
+
const visibleRow = this.findVisibleNavigationRow(dataState.rowSizes, nextCursor[0], rowDirection);
|
|
820
|
+
if (visibleRow === null)
|
|
821
|
+
return;
|
|
822
|
+
if (visibleRow !== nextCursor[0]) {
|
|
823
|
+
nextCursor = [visibleRow, nextCursor[1]];
|
|
824
|
+
if (shiftKey) {
|
|
825
|
+
nextAnchor = [Math.min(nextOrigin[0], visibleRow), Math.min(nextOrigin[1], nextCursor[1])];
|
|
826
|
+
nextFocus = [Math.max(nextOrigin[0], visibleRow), Math.max(nextOrigin[1], nextCursor[1])];
|
|
827
|
+
}
|
|
828
|
+
else {
|
|
829
|
+
nextAnchor = nextCursor;
|
|
830
|
+
nextFocus = nextCursor;
|
|
831
|
+
nextOrigin = nextCursor;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
this.executeSelectionCommand(searCore, nextAnchor, nextFocus, SheetSelectionPipelineNames_1.SheetSelectionSource.Keyboard, true, nextAnchor, nextAnchor, void 0, { origin: nextOrigin, cursor: nextCursor });
|
|
835
|
+
}
|
|
836
|
+
findVisibleNavigationRow(rowSizes, row, direction) {
|
|
837
|
+
if (rowSizes.getItem(0, row) !== 0)
|
|
838
|
+
return row;
|
|
839
|
+
const lastRow = rowSizes.shape[1] - 1;
|
|
840
|
+
for (let next = row + direction; next >= 0 && next <= lastRow; next += direction) {
|
|
841
|
+
if (rowSizes.getItem(0, next) !== 0)
|
|
842
|
+
return next;
|
|
843
|
+
}
|
|
844
|
+
for (let next = row - direction; next >= 0 && next <= lastRow; next -= direction) {
|
|
845
|
+
if (rowSizes.getItem(0, next) !== 0)
|
|
846
|
+
return next;
|
|
847
|
+
}
|
|
848
|
+
return null;
|
|
849
|
+
}
|
|
850
|
+
scrollIntoView(searCore, dataState, targetAnchor, targetFocus) {
|
|
851
|
+
var _a, _b, _c;
|
|
852
|
+
const { rowSizes, columnSizes } = dataState;
|
|
853
|
+
const scrollManager = searCore.renderEngine.scrollManager;
|
|
854
|
+
const [viewportWidth, viewportHeight] = scrollManager.getShape();
|
|
855
|
+
const { x: scrollX, y: scrollY } = scrollManager.getState();
|
|
856
|
+
const config = searCore.configEngine.getDefaultConfig();
|
|
857
|
+
const sheetOffsetX = (_a = config.sheetOffsetX) !== null && _a !== void 0 ? _a : 50;
|
|
858
|
+
const sheetOffsetY = (_b = config.sheetOffsetY) !== null && _b !== void 0 ? _b : 24;
|
|
859
|
+
const viewportContentWidth = viewportWidth - sheetOffsetX;
|
|
860
|
+
const selectionBottomInset = 8;
|
|
861
|
+
const viewportContentHeight = viewportHeight - sheetOffsetY - selectionBottomInset;
|
|
862
|
+
const cellLeft = columnSizes.getDimensionLeftBoundaryByIndex(targetAnchor[1]);
|
|
863
|
+
const cellRight = columnSizes.getDimensionRightBoundaryByIndex(targetFocus[1]);
|
|
864
|
+
const cellTop = rowSizes.getDimensionLeftBoundaryByIndex(targetAnchor[0]);
|
|
865
|
+
const cellBottom = rowSizes.getDimensionRightBoundaryByIndex(targetFocus[0]);
|
|
866
|
+
const freeze = (0, sear_plugin_freeze_1.readSheetFreeze)(searCore.getDataEngine());
|
|
867
|
+
const frozenWidth = columnSizes.getDimensionLeftBoundaryByIndex(freeze.columns);
|
|
868
|
+
const frozenHeight = rowSizes.getDimensionLeftBoundaryByIndex(freeze.rows);
|
|
869
|
+
const targetInFrozenColumns = targetFocus[1] < freeze.columns;
|
|
870
|
+
const targetInFrozenRows = targetFocus[0] < freeze.rows;
|
|
871
|
+
let fixedHeight = 0;
|
|
872
|
+
(_c = (0, sear_plugin_fixed_row_1.readSheetFixedRows)(searCore.getDataEngine())) === null || _c === void 0 ? void 0 : _c.forEachStored((fixed, _matrixRow, row) => {
|
|
873
|
+
if (fixed === true && row >= freeze.rows && row < targetAnchor[0]) {
|
|
874
|
+
fixedHeight += Math.max(0, rowSizes.getItem(0, row) || 0);
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
let newScrollX = scrollX;
|
|
878
|
+
let newScrollY = scrollY;
|
|
879
|
+
if (!targetInFrozenColumns && cellRight > scrollX + viewportContentWidth) {
|
|
880
|
+
newScrollX = cellRight - viewportContentWidth;
|
|
881
|
+
}
|
|
882
|
+
else if (!targetInFrozenColumns && cellLeft < scrollX + frozenWidth) {
|
|
883
|
+
newScrollX = Math.max(0, cellLeft - frozenWidth);
|
|
884
|
+
}
|
|
885
|
+
if (!targetInFrozenRows && cellBottom > scrollY + viewportContentHeight) {
|
|
886
|
+
newScrollY = cellBottom - viewportContentHeight;
|
|
887
|
+
}
|
|
888
|
+
else if (!targetInFrozenRows && cellTop < scrollY + frozenHeight + fixedHeight) {
|
|
889
|
+
newScrollY = Math.max(0, cellTop - frozenHeight - fixedHeight);
|
|
890
|
+
}
|
|
891
|
+
if (newScrollX !== scrollX || newScrollY !== scrollY) {
|
|
892
|
+
scrollManager.scrollTo(newScrollX, newScrollY);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
/** Bridges command results into the existing selection interaction pipeline. */
|
|
896
|
+
executeSelectionCommand(searCore, anchor, focus, source, ensureVisible = false, activeAnchor, activeFocus, additionalSelectionMode, navigation) {
|
|
897
|
+
const commands = this.getCommandBus(searCore);
|
|
898
|
+
if (!commands)
|
|
899
|
+
return;
|
|
900
|
+
const input = Object.assign(Object.assign(Object.assign(Object.assign({ anchor,
|
|
901
|
+
focus,
|
|
902
|
+
source,
|
|
903
|
+
ensureVisible }, (activeAnchor ? { activeAnchor } : {})), (activeFocus ? { activeFocus } : {})), (additionalSelectionMode ? { additionalSelectionMode } : {})), (navigation ? { navigation } : {}));
|
|
904
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_commandCore, searCore, "f");
|
|
905
|
+
try {
|
|
906
|
+
commands.run(SheetSelectionCommands_1.SelectRangeCommand, input);
|
|
907
|
+
}
|
|
908
|
+
finally {
|
|
909
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_commandCore, null, "f");
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
/** Moves the current Sheet selection to the next selectable row. */
|
|
913
|
+
navigateDown() {
|
|
914
|
+
this.navigate(sear_assembly_commands_1.SelectionMoveDirection.Down);
|
|
915
|
+
}
|
|
916
|
+
/** Repositions an active cell that became hidden after a data reorder. */
|
|
917
|
+
reconcileActiveCellVisibility() {
|
|
918
|
+
var _a, _b;
|
|
919
|
+
const core = __classPrivateFieldGet(this, _SheetSelectionPlugin_core, "f");
|
|
920
|
+
const commands = __classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f");
|
|
921
|
+
if (!core || !commands)
|
|
922
|
+
return;
|
|
923
|
+
const dataEngine = core.getDataEngine();
|
|
924
|
+
const visibility = (0, sear_render_engine_1.readSheetRowVisibility)(dataEngine);
|
|
925
|
+
const active = this.getState()[0].getPoint(0);
|
|
926
|
+
if (!(visibility === null || visibility === void 0 ? void 0 : visibility.active) || active[0] < 0 || !visibility.isRowFiltered(active[0]))
|
|
927
|
+
return;
|
|
928
|
+
const rowCount = (_b = (_a = (0, sear_render_engine_1.readSheetRowSizes)(dataEngine)) === null || _a === void 0 ? void 0 : _a.shape[1]) !== null && _b !== void 0 ? _b : 0;
|
|
929
|
+
let target = -1;
|
|
930
|
+
for (let row = active[0] + 1; row < rowCount; row += 1) {
|
|
931
|
+
if (!visibility.isRowFiltered(row)) {
|
|
932
|
+
target = row;
|
|
933
|
+
break;
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
if (target < 0) {
|
|
937
|
+
for (let row = active[0] - 1; row >= 0; row -= 1) {
|
|
938
|
+
if (!visibility.isRowFiltered(row)) {
|
|
939
|
+
target = row;
|
|
940
|
+
break;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
if (target < 0)
|
|
945
|
+
return;
|
|
946
|
+
const point = [target, active[1]];
|
|
947
|
+
commands.run(SheetSelectionCommands_1.SelectRangeCommand, { anchor: point, focus: point, ensureVisible: true });
|
|
948
|
+
}
|
|
949
|
+
createSelectRangeCommand(input) {
|
|
950
|
+
var _a;
|
|
951
|
+
const searCore = (_a = __classPrivateFieldGet(this, _SheetSelectionPlugin_commandCore, "f")) !== null && _a !== void 0 ? _a : this.requireCore();
|
|
952
|
+
return new sear_assembly_commands_1.PipelineExecutionCommand(SheetSelectionCommands_1.SelectRangeCommand.id, this.createSelectRangePipeline(input, searCore));
|
|
953
|
+
}
|
|
954
|
+
createSelectRangePipeline(input, searCore) {
|
|
955
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
956
|
+
const dataState = readSheetGeometry(searCore.getDataEngine());
|
|
957
|
+
const hasActiveRange = input.activeAnchor !== void 0 || input.activeFocus !== void 0;
|
|
958
|
+
const anchor = [...input.anchor];
|
|
959
|
+
const focus = [...input.focus];
|
|
960
|
+
const activeAnchor = [...((_a = input.activeAnchor) !== null && _a !== void 0 ? _a : input.anchor)];
|
|
961
|
+
const activeFocus = [...((_b = input.activeFocus) !== null && _b !== void 0 ? _b : input.focus)];
|
|
962
|
+
const navigationOrigin = [...((_d = (_c = input.navigation) === null || _c === void 0 ? void 0 : _c.origin) !== null && _d !== void 0 ? _d : activeFocus)];
|
|
963
|
+
const navigationCursor = [...((_f = (_e = input.navigation) === null || _e === void 0 ? void 0 : _e.cursor) !== null && _f !== void 0 ? _f : activeFocus)];
|
|
964
|
+
const normalized = hasActiveRange
|
|
965
|
+
? { anchor, focus }
|
|
966
|
+
: (0, sear_assembly_commands_1.selectRange)({
|
|
967
|
+
start: input.anchor,
|
|
968
|
+
end: input.focus,
|
|
969
|
+
findMerge: this.findMergedSelectionRange.bind(this),
|
|
970
|
+
lastRow: (dataState === null || dataState === void 0 ? void 0 : dataState.rowSizes.shape[1]) ? dataState.rowSizes.shape[1] - 1 : void 0,
|
|
971
|
+
lastCol: (dataState === null || dataState === void 0 ? void 0 : dataState.columnSizes.shape[1]) ? dataState.columnSizes.shape[1] - 1 : void 0,
|
|
972
|
+
});
|
|
973
|
+
const operations = [
|
|
974
|
+
(0, sear_domain_ot_1.createUpdateRectOTOperation)([0], activeAnchor, activeFocus),
|
|
975
|
+
(0, sear_domain_ot_1.createUpdateRectOTOperation)([1], normalized.anchor, normalized.focus),
|
|
976
|
+
];
|
|
977
|
+
const pipeline = this.createSelectionPipeline((0, sear_assembly_commands_1.createSheetTransaction)(this.pluginKey, operations), normalized.anchor, normalized.focus, (_g = input.source) !== null && _g !== void 0 ? _g : SheetSelectionPipelineNames_1.SheetSelectionSource.Api);
|
|
978
|
+
pipeline.addPostCommit('update-selection-navigation', () => {
|
|
979
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionOrigin, navigationOrigin[0] < 0 ? null : navigationOrigin, "f");
|
|
980
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionCursor, navigationCursor[0] < 0 ? null : navigationCursor, "f");
|
|
981
|
+
});
|
|
982
|
+
const additionalMode = (_h = input.additionalSelectionMode) !== null && _h !== void 0 ? _h : (input.source === SheetSelectionPipelineNames_1.SheetSelectionSource.Pointer
|
|
983
|
+
? SheetSelectionCommands_1.SheetAdditionalSelectionMode.Preserve
|
|
984
|
+
: SheetSelectionCommands_1.SheetAdditionalSelectionMode.Clear);
|
|
985
|
+
if (additionalMode === SheetSelectionCommands_1.SheetAdditionalSelectionMode.AppendCurrent) {
|
|
986
|
+
const previous = this.getState()[1];
|
|
987
|
+
if (previous.getPoint(0)[0] >= 0) {
|
|
988
|
+
const previousSnapshot = previous.clone();
|
|
989
|
+
pipeline.addPostCommit('append-additional-selection', () => {
|
|
990
|
+
__classPrivateFieldGet(this, _SheetSelectionPlugin_additionalRanges, "f").push(previousSnapshot);
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
else if (additionalMode === SheetSelectionCommands_1.SheetAdditionalSelectionMode.Clear) {
|
|
995
|
+
if (__classPrivateFieldGet(this, _SheetSelectionPlugin_additionalRanges, "f").length) {
|
|
996
|
+
pipeline.addPostCommit('clear-additional-selections', () => {
|
|
997
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_additionalRanges, [], "f");
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
else if (additionalMode !== SheetSelectionCommands_1.SheetAdditionalSelectionMode.Preserve) {
|
|
1002
|
+
throw new sear_foundation_error_1.SearError(`Unsupported additional selection mode: ${String(additionalMode)}`);
|
|
1003
|
+
}
|
|
1004
|
+
if (input.ensureVisible) {
|
|
1005
|
+
pipeline.addPostCommit(SheetSelectionPipelineNames_1.SheetSelectionPipelineStepName.EnsureSelectionVisible, () => {
|
|
1006
|
+
const state = readSheetGeometry(searCore.getDataEngine());
|
|
1007
|
+
if (state)
|
|
1008
|
+
this.scrollIntoView(searCore, state, [...normalized.anchor], [...normalized.focus]);
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
return pipeline;
|
|
1012
|
+
}
|
|
1013
|
+
getCommandBus(_searCore) {
|
|
1014
|
+
var _a;
|
|
1015
|
+
if (__classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f"))
|
|
1016
|
+
return __classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f");
|
|
1017
|
+
(_a = this.platform) === null || _a === void 0 ? void 0 : _a.warn('SheetSelectionPlugin getCommandBus skipped: SheetCommandBus is missing.');
|
|
1018
|
+
return null;
|
|
1019
|
+
}
|
|
1020
|
+
/** Registers the commands. */
|
|
1021
|
+
registerCommands(commands) {
|
|
1022
|
+
var _a;
|
|
1023
|
+
this.assertRuntimeWriteAllowed();
|
|
1024
|
+
if (__classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f") && __classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f") !== commands) {
|
|
1025
|
+
throw new sear_foundation_error_1.SearError('Sheet selection commands are already bound to an editor.');
|
|
1026
|
+
}
|
|
1027
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_commands, commands, "f");
|
|
1028
|
+
(_a = this.rangeDrag) === null || _a === void 0 ? void 0 : _a.registerCommands(commands);
|
|
1029
|
+
commands.register(SheetSelectionCommands_1.RestartSheetSelectionNavigationCommand, () => new sear_assembly_commands_1.LocalActionCommand(SheetSelectionCommands_1.RestartSheetSelectionNavigationCommand.id, () => __classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_restartNavigation).call(this)));
|
|
1030
|
+
commands.register(SheetSelectionPointerCommand_1.HandleSheetSelectionPointerCommand, (input) => {
|
|
1031
|
+
const core = this.requireCore();
|
|
1032
|
+
if (input.action === SheetSelectionPointerCommand_1.SheetSelectionPointerAction.Move) {
|
|
1033
|
+
const plan = __classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_planPointerMove).call(this, core, input);
|
|
1034
|
+
if (plan) {
|
|
1035
|
+
const pipeline = this.createSelectRangePipeline(plan, core);
|
|
1036
|
+
pipeline.addPostCommit('update-selection-pointer', () => __classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_updatePointerPosition).call(this, input.view));
|
|
1037
|
+
return new sear_assembly_commands_1.PipelineExecutionCommand(SheetSelectionPointerCommand_1.HandleSheetSelectionPointerCommand.id, pipeline);
|
|
1038
|
+
}
|
|
1039
|
+
return new sear_assembly_commands_1.LocalActionCommand(SheetSelectionPointerCommand_1.HandleSheetSelectionPointerCommand.id, () => __classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_updatePointerPosition).call(this, input.view));
|
|
1040
|
+
}
|
|
1041
|
+
return new sear_assembly_commands_1.LocalActionCommand(SheetSelectionPointerCommand_1.HandleSheetSelectionPointerCommand.id, () => __classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_applyPointerInput).call(this, core, input));
|
|
1042
|
+
});
|
|
1043
|
+
commands.register(SheetSelectionCommands_1.ClearSelectedContentsCommand, () => {
|
|
1044
|
+
const cells = this.readCells();
|
|
1045
|
+
if (!cells)
|
|
1046
|
+
return new sear_assembly_commands_1.TransactionPipelineCommand(SheetSelectionCommands_1.ClearSelectedContentsCommand.id, (0, sear_assembly_commands_1.createSheetTransaction)(sear_render_engine_1.SheetDataPlugin.pluginKey, []));
|
|
1047
|
+
const rowVisibility = __classPrivateFieldGet(this, _SheetSelectionPlugin_core, "f") ? (0, sear_render_engine_1.readSheetRowVisibility)(__classPrivateFieldGet(this, _SheetSelectionPlugin_core, "f").getDataEngine()) : null;
|
|
1048
|
+
const source = {
|
|
1049
|
+
target: sear_render_engine_1.SheetDataPlugin.pluginKey,
|
|
1050
|
+
getRowCount: () => cells.shape[0],
|
|
1051
|
+
getColumnCount: () => cells.shape[1],
|
|
1052
|
+
readCell: (row, col) => cells.getItem(row, col),
|
|
1053
|
+
includeCell: (row) => !(rowVisibility === null || rowVisibility === void 0 ? void 0 : rowVisibility.active) || !rowVisibility.isRowFiltered(row),
|
|
1054
|
+
validateClearCell: (row, col) => { var _a, _b; return (_b = (_a = this.inputValidation) === null || _a === void 0 ? void 0 : _a.validateClear(row, col)) !== null && _b !== void 0 ? _b : { reject: false }; },
|
|
1055
|
+
};
|
|
1056
|
+
const seen = new Set();
|
|
1057
|
+
const operations = __classPrivateFieldGet(this, _SheetSelectionPlugin_queries, "f").run(SheetSelectionCommands_1.GetSelections, void 0).flatMap((range) => (0, sear_assembly_commands_1.createClearRangeContentsOperations)({ anchor: range.start, focus: range.end }, source).filter((operation) => {
|
|
1058
|
+
const key = operation.p.join(':');
|
|
1059
|
+
if (seen.has(key))
|
|
1060
|
+
return false;
|
|
1061
|
+
seen.add(key);
|
|
1062
|
+
return true;
|
|
1063
|
+
}));
|
|
1064
|
+
return new sear_assembly_commands_1.TransactionPipelineCommand(SheetSelectionCommands_1.ClearSelectedContentsCommand.id, (0, sear_assembly_commands_1.createSheetTransaction)(sear_render_engine_1.SheetDataPlugin.pluginKey, operations));
|
|
1065
|
+
});
|
|
1066
|
+
if (this.rangeMoves)
|
|
1067
|
+
commands.register(SheetRangeMoveCommands_1.MoveSheetRangeCommand, (input) => {
|
|
1068
|
+
const analysis = this.analyzeRangeMove(input);
|
|
1069
|
+
if (analysis.status === sear_assembly_plugin_1.SheetRangeMoveStatus.Blocked)
|
|
1070
|
+
throw new sear_assembly_plugin_1.SheetRangeMoveRejectedError(analysis);
|
|
1071
|
+
const context = analysis.context;
|
|
1072
|
+
const pipeline = new sear_assembly_core_1.Pipeline(SheetRangeMoveCommands_1.MoveSheetRangeCommand.id);
|
|
1073
|
+
if (context.source.start.every((coordinate, axis) => coordinate === context.destination.start[axis]))
|
|
1074
|
+
return new sear_assembly_commands_1.PipelineExecutionCommand(SheetRangeMoveCommands_1.MoveSheetRangeCommand.id, pipeline);
|
|
1075
|
+
if (analysis.status === sear_assembly_plugin_1.SheetRangeMoveStatus.RequiresConfirmation && !input.overwrite)
|
|
1076
|
+
throw new SheetRangeMoveError_1.SheetRangeMoveError(SheetRangeMoveError_1.SheetRangeMoveErrorCode.DestinationOccupied, 'The destination contains existing cell data.', { context });
|
|
1077
|
+
this.rangeMoves.plan(context).forEach((plan, index) => {
|
|
1078
|
+
if (plan.operations.length)
|
|
1079
|
+
pipeline.add(`move-owner:${index}`, (0, sear_assembly_commands_1.createSheetTransaction)(plan.target, [...plan.operations]));
|
|
1080
|
+
});
|
|
1081
|
+
const { start, end } = context.destination;
|
|
1082
|
+
pipeline.addPostCommit('reset-selection-navigation', () => {
|
|
1083
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionOrigin, [...start], "f");
|
|
1084
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionCursor, [...start], "f");
|
|
1085
|
+
});
|
|
1086
|
+
pipeline.add('move-selection', (0, sear_assembly_commands_1.createSheetTransaction)(this.key, [
|
|
1087
|
+
(0, sear_domain_ot_1.createUpdateRectOTOperation)([0], [...start], [...start]),
|
|
1088
|
+
(0, sear_domain_ot_1.createUpdateRectOTOperation)([1], [...start], [...end]),
|
|
1089
|
+
]));
|
|
1090
|
+
pipeline.addInteraction('move-selection-changed', {
|
|
1091
|
+
type: SheetSelectionPipelineNames_1.SheetSelectionInteractionName.Changed,
|
|
1092
|
+
anchor: start,
|
|
1093
|
+
focus: end,
|
|
1094
|
+
source: SheetSelectionPipelineNames_1.SheetSelectionSource.Pointer,
|
|
1095
|
+
});
|
|
1096
|
+
pipeline.addPostRender(SheetHighlightPipelineNames_1.SheetHighlightPipelineStepName.Refresh, SheetHighlightPlugin_1.SheetHighlightPlugin.pluginKey);
|
|
1097
|
+
return new sear_assembly_commands_1.PipelineExecutionCommand(SheetRangeMoveCommands_1.MoveSheetRangeCommand.id, pipeline);
|
|
1098
|
+
});
|
|
1099
|
+
const selectionPlugin = this;
|
|
1100
|
+
commands.register(SheetSelectionCommands_1.SelectRangeCommand, function createSelectRangeCommand(input) {
|
|
1101
|
+
return selectionPlugin.createSelectRangeCommand(input);
|
|
1102
|
+
});
|
|
1103
|
+
commands.register(SheetSelectionCommands_1.EnsureSelectionVisibleCommand, function createEnsureSelectionVisibleCommand(input) {
|
|
1104
|
+
return new sear_assembly_commands_1.LocalActionCommand(SheetSelectionCommands_1.EnsureSelectionVisibleCommand.id, function ensureSelectionVisible() {
|
|
1105
|
+
const core = selectionPlugin.requireCore();
|
|
1106
|
+
const state = readSheetGeometry(core.getDataEngine());
|
|
1107
|
+
if (state)
|
|
1108
|
+
selectionPlugin.scrollIntoView(core, state, [...input.anchor], [...input.focus]);
|
|
1109
|
+
});
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
createSelectionPipeline(transaction, anchor, focus, source) {
|
|
1113
|
+
const pipeline = new sear_assembly_core_1.Pipeline(SheetSelectionPipelineNames_1.SheetSelectionPipelineName.SelectionChange);
|
|
1114
|
+
pipeline.add(SheetSelectionPipelineNames_1.SheetSelectionPipelineStepName.UpdateSelection, transaction);
|
|
1115
|
+
pipeline.addInteraction(SheetSelectionPipelineNames_1.SheetSelectionPipelineStepName.RecordSelectionChange, {
|
|
1116
|
+
type: SheetSelectionPipelineNames_1.SheetSelectionInteractionName.Changed,
|
|
1117
|
+
anchor,
|
|
1118
|
+
focus,
|
|
1119
|
+
source,
|
|
1120
|
+
});
|
|
1121
|
+
pipeline.addPostRender(SheetHighlightPipelineNames_1.SheetHighlightPipelineStepName.Refresh, SheetHighlightPlugin_1.SheetHighlightPlugin.pluginKey);
|
|
1122
|
+
return pipeline;
|
|
1123
|
+
}
|
|
1124
|
+
validateRangeMove(input) {
|
|
1125
|
+
const context = (0, resolveSheetRangeMove_1.resolveSheetRangeMove)(input);
|
|
1126
|
+
const geometry = readSheetGeometry(this.requireCore().getDataEngine());
|
|
1127
|
+
const valid = geometry &&
|
|
1128
|
+
[context.source, context.destination].every((range) => [range.start, range.end].every((point) => point.every((value) => Number.isSafeInteger(value) && value >= 0)) &&
|
|
1129
|
+
range.end[0] < geometry.rowSizes.shape[1] &&
|
|
1130
|
+
range.end[1] < geometry.columnSizes.shape[1]);
|
|
1131
|
+
if (!valid)
|
|
1132
|
+
throw new SheetRangeMoveError_1.SheetRangeMoveError(SheetRangeMoveError_1.SheetRangeMoveErrorCode.InvalidRange, 'Range move is outside sheet bounds.', {
|
|
1133
|
+
input,
|
|
1134
|
+
});
|
|
1135
|
+
return context;
|
|
1136
|
+
}
|
|
1137
|
+
analyzeRangeMove(input) {
|
|
1138
|
+
let context;
|
|
1139
|
+
try {
|
|
1140
|
+
context = this.validateRangeMove(input);
|
|
1141
|
+
}
|
|
1142
|
+
catch (error) {
|
|
1143
|
+
if (!(error instanceof SheetRangeMoveError_1.SheetRangeMoveError))
|
|
1144
|
+
throw error;
|
|
1145
|
+
return {
|
|
1146
|
+
status: sear_assembly_plugin_1.SheetRangeMoveStatus.Blocked,
|
|
1147
|
+
context: (0, resolveSheetRangeMove_1.resolveSheetRangeMove)(input),
|
|
1148
|
+
issue: {
|
|
1149
|
+
ownerId: 'sheet.selection.rangeMove',
|
|
1150
|
+
code: error.code,
|
|
1151
|
+
message: error.message,
|
|
1152
|
+
details: error.details,
|
|
1153
|
+
},
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
return this.rangeMoves.analyze(context);
|
|
1157
|
+
}
|
|
1158
|
+
/** Cancels transient pointer work before this editor is released. */
|
|
1159
|
+
onEditorDestroy() {
|
|
1160
|
+
var _a, _b;
|
|
1161
|
+
this.assertRuntimeWriteAllowed();
|
|
1162
|
+
__classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_handlePointerUp).call(this);
|
|
1163
|
+
(_a = this.rangeDrag) === null || _a === void 0 ? void 0 : _a.destroy(__classPrivateFieldGet(this, _SheetSelectionPlugin_rangeDragOwnerToken, "f"));
|
|
1164
|
+
(_b = __classPrivateFieldGet(this, _SheetSelectionPlugin_disposeAdditionalHighlight, "f")) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
1165
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_disposeAdditionalHighlight, null, "f");
|
|
1166
|
+
}
|
|
1167
|
+
/** Restarts selection navigation from the current active cell. */
|
|
1168
|
+
restartNavigation() {
|
|
1169
|
+
if (this.hasStateWriteBoundary()) {
|
|
1170
|
+
if (!__classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f"))
|
|
1171
|
+
throw new sear_foundation_error_1.SearError('Sheet selection navigation command is unavailable.');
|
|
1172
|
+
__classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f").run(SheetSelectionCommands_1.RestartSheetSelectionNavigationCommand, void 0);
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
__classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_restartNavigation).call(this);
|
|
1176
|
+
}
|
|
1177
|
+
/** Applies a transaction to SheetSelectionPlugin state. */
|
|
1178
|
+
apply(pluginState, transaction) {
|
|
1179
|
+
let changed = false;
|
|
1180
|
+
const geometry = __classPrivateFieldGet(this, _SheetSelectionPlugin_core, "f") ? readSheetGeometry(__classPrivateFieldGet(this, _SheetSelectionPlugin_core, "f").getDataEngine()) : null;
|
|
1181
|
+
let lastRow = geometry ? geometry.rowSizes.shape[1] - 1 : Infinity;
|
|
1182
|
+
let lastColumn = geometry ? geometry.columnSizes.shape[1] - 1 : Infinity;
|
|
1183
|
+
for (const operation of transaction.operations) {
|
|
1184
|
+
if (sear_domain_ot_1.RectOTActionName.UpdateRect in operation && operation.ur !== void 0) {
|
|
1185
|
+
pluginState[operation.p[0]] = sear_domain_ot_1.RectOT.apply(pluginState[operation.p[0]], [operation]);
|
|
1186
|
+
changed = true;
|
|
1187
|
+
}
|
|
1188
|
+
else if ((0, sear_domain_ot_1.isMatrixStructureOperation)(operation)) {
|
|
1189
|
+
if (sear_domain_ot_1.MatrixOTActionName.RowInsert in operation)
|
|
1190
|
+
lastRow += 1;
|
|
1191
|
+
if (sear_domain_ot_1.MatrixOTActionName.RowDelete in operation)
|
|
1192
|
+
lastRow -= 1;
|
|
1193
|
+
if (sear_domain_ot_1.MatrixOTActionName.ColInsert in operation)
|
|
1194
|
+
lastColumn += 1;
|
|
1195
|
+
if (sear_domain_ot_1.MatrixOTActionName.ColDelete in operation)
|
|
1196
|
+
lastColumn -= 1;
|
|
1197
|
+
pluginState[0] = sear_domain_ot_1.RectOT.apply(pluginState[0], [operation]);
|
|
1198
|
+
pluginState[1] = sear_domain_ot_1.RectOT.apply(pluginState[1], [operation]);
|
|
1199
|
+
normalizeDeletedSelection(pluginState[0], lastRow, lastColumn);
|
|
1200
|
+
normalizeDeletedSelection(pluginState[1], lastRow, lastColumn);
|
|
1201
|
+
changed = true;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
const hasResize = transaction.operations.some((operation) => (0, sear_domain_ot_1.isResizeRowOperation)(operation) || (0, sear_domain_ot_1.isResizeColOperation)(operation));
|
|
1205
|
+
if (!changed && !hasResize)
|
|
1206
|
+
return null;
|
|
1207
|
+
return pluginState;
|
|
1208
|
+
}
|
|
1209
|
+
/** Rebases local keyboard anchors only after structural transactions commit. */
|
|
1210
|
+
onTransactionCommitted(transaction) {
|
|
1211
|
+
if (__classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f") && !__classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f").isExecuting()) {
|
|
1212
|
+
throw new sear_foundation_error_1.SearError('Sheet selection changes must run through editor.commands.run(...).');
|
|
1213
|
+
}
|
|
1214
|
+
for (const operation of transaction.operations) {
|
|
1215
|
+
if (!(0, sear_domain_ot_1.isMatrixStructureOperation)(operation))
|
|
1216
|
+
continue;
|
|
1217
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionOrigin, this.rebaseSelectionPoint(__classPrivateFieldGet(this, _SheetSelectionPlugin_selectionOrigin, "f"), operation), "f");
|
|
1218
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionCursor, this.rebaseSelectionPoint(__classPrivateFieldGet(this, _SheetSelectionPlugin_selectionCursor, "f"), operation), "f");
|
|
1219
|
+
}
|
|
1220
|
+
const selection = this.getState();
|
|
1221
|
+
const range = selection[1];
|
|
1222
|
+
if (range.getPoint(0)[0] < 0)
|
|
1223
|
+
return;
|
|
1224
|
+
const active = selection[0].getPoint(0);
|
|
1225
|
+
if (__classPrivateFieldGet(this, _SheetSelectionPlugin_selectionOrigin, "f") && !selectionContainsPoint(range, __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionOrigin, "f")))
|
|
1226
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionOrigin, [...active], "f");
|
|
1227
|
+
if (__classPrivateFieldGet(this, _SheetSelectionPlugin_selectionCursor, "f") && !selectionContainsPoint(range, __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionCursor, "f")))
|
|
1228
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionCursor, [...active], "f");
|
|
1229
|
+
}
|
|
1230
|
+
/** @inheritdoc */
|
|
1231
|
+
registerConfig() {
|
|
1232
|
+
return [{ key: this.key, config: new sear_assembly_config_1.ConfigUnit(sheetSelectionPluginConfig) }];
|
|
1233
|
+
}
|
|
1234
|
+
/** @inheritdoc */
|
|
1235
|
+
registerState() {
|
|
1236
|
+
return { key: this.key, state: this.getState() };
|
|
1237
|
+
}
|
|
1238
|
+
/** Locks committed selection rectangles while transaction clones remain writable. */
|
|
1239
|
+
lockCommittedState(state) {
|
|
1240
|
+
state.forEach((range) => range.lockMutations());
|
|
1241
|
+
Object.freeze(state);
|
|
1242
|
+
}
|
|
1243
|
+
rebaseSelectionPoint(point, operation) {
|
|
1244
|
+
if (!point)
|
|
1245
|
+
return null;
|
|
1246
|
+
const rect = new sear_foundation_rect_1.Rect([[...point], [...point]]);
|
|
1247
|
+
sear_domain_ot_1.RectOT.apply(rect, [operation]);
|
|
1248
|
+
return [...rect.getPoint(0)];
|
|
1249
|
+
}
|
|
1250
|
+
/** Renders SheetSelectionPlugin scene output. */
|
|
1251
|
+
render(searCore, offset = (() => {
|
|
1252
|
+
var _a, _b;
|
|
1253
|
+
const config = searCore.configEngine.getDefaultConfig();
|
|
1254
|
+
return { x: (_a = config.sheetOffsetX) !== null && _a !== void 0 ? _a : 50, y: (_b = config.sheetOffsetY) !== null && _b !== void 0 ? _b : 24 };
|
|
1255
|
+
})()) {
|
|
1256
|
+
__classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_bindCoreReference).call(this, searCore);
|
|
1257
|
+
const dataEngine = searCore.getDataEngine();
|
|
1258
|
+
const selectionState = dataEngine.getDataType(this.pluginKey);
|
|
1259
|
+
if (!selectionState)
|
|
1260
|
+
return [];
|
|
1261
|
+
if (selectionState[1].shape.join('') === sear_foundation_rect_1.Rect.Empty.join(''))
|
|
1262
|
+
return [];
|
|
1263
|
+
const pluginConfig = searCore.configEngine.getPluginConfig(this.key);
|
|
1264
|
+
const state = readSheetGeometry(dataEngine);
|
|
1265
|
+
if (!state)
|
|
1266
|
+
throw new sear_foundation_error_1.SearError('sheet geometry fields are not found in SheetSelectionPlugin render.');
|
|
1267
|
+
const { rowSizes, columnSizes } = state;
|
|
1268
|
+
const anchor = selectionState[1].getPoint(0);
|
|
1269
|
+
const focus = selectionState[1].getPoint(1);
|
|
1270
|
+
const freeze = (0, sear_plugin_freeze_1.readSheetFreeze)(dataEngine);
|
|
1271
|
+
const scrollState = searCore.renderEngine.scrollManager.getState();
|
|
1272
|
+
const fixedY = anchor[0] === focus[0]
|
|
1273
|
+
? (0, sear_render_2.activeFixedRowOffsets)((0, sear_plugin_fixed_row_1.readSheetFixedRows)(dataEngine), rowSizes, scrollState.y, freeze.rows, offset.y).get(anchor[0])
|
|
1274
|
+
: undefined;
|
|
1275
|
+
const frozenTop = (freeze.rows > 0 && Math.max(anchor[0], focus[0]) < freeze.rows) || fixedY !== void 0;
|
|
1276
|
+
const frozenLeft = freeze.columns > 0 && Math.max(anchor[1], focus[1]) < freeze.columns;
|
|
1277
|
+
const positionRect = (0, sear_render_1.getSheetRangePositionRect)(anchor, focus, {
|
|
1278
|
+
rowSizes,
|
|
1279
|
+
columnSizes,
|
|
1280
|
+
offsetX: offset.x,
|
|
1281
|
+
offsetY: offset.y,
|
|
1282
|
+
});
|
|
1283
|
+
if (!positionRect)
|
|
1284
|
+
return [];
|
|
1285
|
+
if (fixedY !== void 0)
|
|
1286
|
+
positionRect.y = fixedY;
|
|
1287
|
+
const { renderCoordinatorManager } = searCore.renderEngine;
|
|
1288
|
+
const lastRow = rowSizes.shape[1] - 1;
|
|
1289
|
+
const lastCol = columnSizes.shape[1] - 1;
|
|
1290
|
+
const isFullRowSelection = anchor[1] === 0 && focus[1] === lastCol;
|
|
1291
|
+
const isFullColumnSelection = anchor[0] === 0 && focus[0] === lastRow;
|
|
1292
|
+
const shouldBeClipInDirtyRender = isFullRowSelection || isFullColumnSelection;
|
|
1293
|
+
const [viewportWidth, viewportHeight] = searCore.renderEngine.scrollManager.getShape();
|
|
1294
|
+
const cell = renderCoordinatorManager.create({ type: sear_render_registry_1.EmptyCell.symbol }, positionRect, {
|
|
1295
|
+
type: sear_render_registry_1.EmptyCell.symbol,
|
|
1296
|
+
strokeWidth: 2,
|
|
1297
|
+
depth: this.depth + 4,
|
|
1298
|
+
stroke: pluginConfig.defaultBorderColor,
|
|
1299
|
+
// Selection is stroke-only; clicks inside should pass through to underlying cells.
|
|
1300
|
+
skipHit: true,
|
|
1301
|
+
shouldBeClipInDirtyRender,
|
|
1302
|
+
semanticOwner: SheetSelectionRenderSemantics_1.SheetSelectionRenderSemantics.owner,
|
|
1303
|
+
semanticRole: SheetSelectionRenderSemantics_1.SheetSelectionRenderSemantics.outlineRole,
|
|
1304
|
+
// Selection is an overlay for the grid content, not for sticky UI.
|
|
1305
|
+
// Keep it below row/column headers even though OverlayRenderStrategy
|
|
1306
|
+
// renders edit nodes after the sticky pass.
|
|
1307
|
+
overlayClipRect: frozenTop || frozenLeft
|
|
1308
|
+
? undefined
|
|
1309
|
+
: {
|
|
1310
|
+
x: scrollState.x + offset.x,
|
|
1311
|
+
y: scrollState.y + offset.y,
|
|
1312
|
+
width: Math.max(0, viewportWidth - offset.x),
|
|
1313
|
+
height: Math.max(0, viewportHeight - offset.y),
|
|
1314
|
+
},
|
|
1315
|
+
});
|
|
1316
|
+
const rect = cell === null || cell === void 0 ? void 0 : cell.render();
|
|
1317
|
+
if (rect) {
|
|
1318
|
+
const nodes = [rect].flat();
|
|
1319
|
+
nodes.forEach((n) => {
|
|
1320
|
+
n.properties['isEdit'] = true;
|
|
1321
|
+
if (frozenTop || frozenLeft)
|
|
1322
|
+
n.setStickyTree(true, Object.assign(Object.assign({}, (frozenTop ? { top: positionRect.y } : {})), (frozenLeft ? { left: positionRect.x } : {})));
|
|
1323
|
+
});
|
|
1324
|
+
if (!isFullRowSelection && !isFullColumnSelection) {
|
|
1325
|
+
const handleRect = {
|
|
1326
|
+
x: positionRect.x + positionRect.width - 4,
|
|
1327
|
+
y: positionRect.y + positionRect.height - 4,
|
|
1328
|
+
width: 8,
|
|
1329
|
+
height: 8,
|
|
1330
|
+
};
|
|
1331
|
+
const handle = renderCoordinatorManager.create({ type: sear_render_registry_1.EmptyCell.symbol }, handleRect, {
|
|
1332
|
+
type: sear_render_registry_1.EmptyCell.symbol,
|
|
1333
|
+
fill: pluginConfig.defaultBorderColor,
|
|
1334
|
+
stroke: '#ffffff',
|
|
1335
|
+
strokeWidth: 1,
|
|
1336
|
+
depth: this.depth + 5,
|
|
1337
|
+
skipHit: true,
|
|
1338
|
+
overlayClipRect: frozenTop || frozenLeft
|
|
1339
|
+
? undefined
|
|
1340
|
+
: {
|
|
1341
|
+
x: scrollState.x + offset.x,
|
|
1342
|
+
y: scrollState.y + offset.y,
|
|
1343
|
+
width: Math.max(0, viewportWidth - offset.x),
|
|
1344
|
+
height: Math.max(0, viewportHeight - offset.y),
|
|
1345
|
+
},
|
|
1346
|
+
});
|
|
1347
|
+
const marker = handle === null || handle === void 0 ? void 0 : handle.render();
|
|
1348
|
+
if (marker)
|
|
1349
|
+
nodes.push(...[marker].flat());
|
|
1350
|
+
}
|
|
1351
|
+
return nodes;
|
|
1352
|
+
}
|
|
1353
|
+
return [];
|
|
1354
|
+
}
|
|
1355
|
+
};
|
|
1356
|
+
exports.SheetSelectionPlugin = SheetSelectionPlugin;
|
|
1357
|
+
_SheetSelectionPlugin_isSelecting = new WeakMap();
|
|
1358
|
+
_SheetSelectionPlugin_selectionPointer = new WeakMap();
|
|
1359
|
+
_SheetSelectionPlugin_selectionScrollFrame = new WeakMap();
|
|
1360
|
+
_SheetSelectionPlugin_disposeSelectionCapture = new WeakMap();
|
|
1361
|
+
_SheetSelectionPlugin_additionalRanges = new WeakMap();
|
|
1362
|
+
_SheetSelectionPlugin_disposeAdditionalHighlight = new WeakMap();
|
|
1363
|
+
_SheetSelectionPlugin_headerDragMode = new WeakMap();
|
|
1364
|
+
_SheetSelectionPlugin_selectionOrigin = new WeakMap();
|
|
1365
|
+
_SheetSelectionPlugin_selectionCursor = new WeakMap();
|
|
1366
|
+
_SheetSelectionPlugin_commandCore = new WeakMap();
|
|
1367
|
+
_SheetSelectionPlugin_core = new WeakMap();
|
|
1368
|
+
_SheetSelectionPlugin_queries = new WeakMap();
|
|
1369
|
+
_SheetSelectionPlugin_commands = new WeakMap();
|
|
1370
|
+
_SheetSelectionPlugin_rangeDragOwnerToken = new WeakMap();
|
|
1371
|
+
_SheetSelectionPlugin_sheetCellMergePlugin = new WeakMap();
|
|
1372
|
+
_SheetSelectionPlugin_instances = new WeakSet();
|
|
1373
|
+
_SheetSelectionPlugin_bindCoreReference = function _SheetSelectionPlugin_bindCoreReference(core) {
|
|
1374
|
+
if (__classPrivateFieldGet(this, _SheetSelectionPlugin_core, "f") === core)
|
|
1375
|
+
return;
|
|
1376
|
+
if (this.hasStateWriteBoundary() && __classPrivateFieldGet(this, _SheetSelectionPlugin_core, "f")) {
|
|
1377
|
+
throw new sear_foundation_error_1.SearError('Sheet selection core cannot be replaced after editor assembly.');
|
|
1378
|
+
}
|
|
1379
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_core, core, "f");
|
|
1380
|
+
};
|
|
1381
|
+
_SheetSelectionPlugin_captureSessionState = function _SheetSelectionPlugin_captureSessionState() {
|
|
1382
|
+
const state = this.getState();
|
|
1383
|
+
return [state[0].clone(), state[1].clone()];
|
|
1384
|
+
};
|
|
1385
|
+
_SheetSelectionPlugin_restoreSessionState = function _SheetSelectionPlugin_restoreSessionState(selection) {
|
|
1386
|
+
const next = [selection[0].clone(), selection[1].clone()];
|
|
1387
|
+
this.setState(next);
|
|
1388
|
+
const focus = next[1].getPoint(1);
|
|
1389
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionOrigin, focus[0] < 0 ? null : [...focus], "f");
|
|
1390
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionCursor, focus[0] < 0 ? null : [...focus], "f");
|
|
1391
|
+
};
|
|
1392
|
+
_SheetSelectionPlugin_dispatchPointerInput = function _SheetSelectionPlugin_dispatchPointerInput(searCore, input) {
|
|
1393
|
+
if (!this.hasStateWriteBoundary())
|
|
1394
|
+
return __classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_applyPointerInput).call(this, searCore, input);
|
|
1395
|
+
if (!__classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f"))
|
|
1396
|
+
throw new sear_foundation_error_1.SearError('Sheet selection pointer command is unavailable.');
|
|
1397
|
+
__classPrivateFieldGet(this, _SheetSelectionPlugin_commands, "f").run(SheetSelectionPointerCommand_1.HandleSheetSelectionPointerCommand, input);
|
|
1398
|
+
};
|
|
1399
|
+
_SheetSelectionPlugin_applyPointerInput = function _SheetSelectionPlugin_applyPointerInput(searCore, input) {
|
|
1400
|
+
switch (input.action) {
|
|
1401
|
+
case SheetSelectionPointerCommand_1.SheetSelectionPointerAction.Down:
|
|
1402
|
+
return __classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_handlePointerDown).call(this, searCore, input);
|
|
1403
|
+
case SheetSelectionPointerCommand_1.SheetSelectionPointerAction.Move:
|
|
1404
|
+
return __classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_handlePointerMove).call(this, searCore, input);
|
|
1405
|
+
case SheetSelectionPointerCommand_1.SheetSelectionPointerAction.Up:
|
|
1406
|
+
__classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_handlePointerUp).call(this);
|
|
1407
|
+
return;
|
|
1408
|
+
case SheetSelectionPointerCommand_1.SheetSelectionPointerAction.Tick:
|
|
1409
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionScrollFrame, null, "f");
|
|
1410
|
+
this.advanceSelectionScroll();
|
|
1411
|
+
}
|
|
1412
|
+
};
|
|
1413
|
+
_SheetSelectionPlugin_handlePointerDown = function _SheetSelectionPlugin_handlePointerDown(searCore, input) {
|
|
1414
|
+
var _a, _b, _c, _d, _e;
|
|
1415
|
+
const target = input.target;
|
|
1416
|
+
if (!target)
|
|
1417
|
+
throw new sear_foundation_error_1.SearError('SheetSelectionPlugin onMouseDown event target is null');
|
|
1418
|
+
const properties = target;
|
|
1419
|
+
const additive = Boolean((input.metaKey || input.ctrlKey) && properties.region === sear_render_registry_1.CellRegion.Grid);
|
|
1420
|
+
const { startRowIndex, startColIndex } = properties;
|
|
1421
|
+
const { endRowIndex, endColIndex } = properties;
|
|
1422
|
+
const region = properties.region;
|
|
1423
|
+
if (region === sear_render_registry_1.CellRegion.RowHeader) {
|
|
1424
|
+
if (!Number.isSafeInteger(startRowIndex) || !Number.isSafeInteger(endRowIndex !== null && endRowIndex !== void 0 ? endRowIndex : startRowIndex))
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
else if (region === sear_render_registry_1.CellRegion.ColumnHeader) {
|
|
1428
|
+
if (!Number.isSafeInteger(startColIndex) || !Number.isSafeInteger(endColIndex !== null && endColIndex !== void 0 ? endColIndex : startColIndex))
|
|
1429
|
+
return;
|
|
1430
|
+
}
|
|
1431
|
+
else if (![startRowIndex, startColIndex, endRowIndex, endColIndex].every(Number.isSafeInteger)) {
|
|
1432
|
+
return;
|
|
1433
|
+
}
|
|
1434
|
+
const dataEngine = searCore.getDataEngine();
|
|
1435
|
+
const dataState = readSheetGeometry(dataEngine);
|
|
1436
|
+
let anchor;
|
|
1437
|
+
let focus;
|
|
1438
|
+
if (region === sear_render_registry_1.CellRegion.RowHeader && startRowIndex !== void 0) {
|
|
1439
|
+
if (!dataState) {
|
|
1440
|
+
(_a = this.platform) === null || _a === void 0 ? void 0 : _a.warn('SheetSelectionPlugin onMouseDown row-header selection skipped: sheet geometry fields are missing.');
|
|
1441
|
+
return;
|
|
1442
|
+
}
|
|
1443
|
+
const lastCol = dataState.columnSizes.shape[1] - 1;
|
|
1444
|
+
anchor = [startRowIndex, 0];
|
|
1445
|
+
focus = [endRowIndex !== null && endRowIndex !== void 0 ? endRowIndex : startRowIndex, lastCol];
|
|
1446
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_headerDragMode, 'row', "f");
|
|
1447
|
+
}
|
|
1448
|
+
else if (region === sear_render_registry_1.CellRegion.ColumnHeader && startColIndex !== void 0) {
|
|
1449
|
+
if (!dataState) {
|
|
1450
|
+
(_b = this.platform) === null || _b === void 0 ? void 0 : _b.warn('SheetSelectionPlugin onMouseDown column-header selection skipped: sheet geometry fields are missing.');
|
|
1451
|
+
return;
|
|
1452
|
+
}
|
|
1453
|
+
const lastRow = dataState.rowSizes.shape[1] - 1;
|
|
1454
|
+
anchor = [0, startColIndex];
|
|
1455
|
+
focus = [lastRow, endColIndex !== null && endColIndex !== void 0 ? endColIndex : startColIndex];
|
|
1456
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_headerDragMode, 'col', "f");
|
|
1457
|
+
}
|
|
1458
|
+
else if (input.shiftKey && __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionOrigin, "f") && region === sear_render_registry_1.CellRegion.Grid) {
|
|
1459
|
+
anchor = [...__classPrivateFieldGet(this, _SheetSelectionPlugin_selectionOrigin, "f")];
|
|
1460
|
+
focus = [Number(endRowIndex), Number(endColIndex)];
|
|
1461
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_headerDragMode, 'none', "f");
|
|
1462
|
+
}
|
|
1463
|
+
else {
|
|
1464
|
+
anchor = [Number(startRowIndex), Number(startColIndex)];
|
|
1465
|
+
focus = [Number(endRowIndex), Number(endColIndex)];
|
|
1466
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_headerDragMode, 'none', "f");
|
|
1467
|
+
}
|
|
1468
|
+
const normalized = (0, sear_assembly_commands_1.selectRange)({
|
|
1469
|
+
start: anchor,
|
|
1470
|
+
end: focus,
|
|
1471
|
+
findMerge: this.findMergedSelectionRange.bind(this),
|
|
1472
|
+
lastRow: dataState ? dataState.rowSizes.shape[1] - 1 : void 0,
|
|
1473
|
+
lastCol: dataState ? dataState.columnSizes.shape[1] - 1 : void 0,
|
|
1474
|
+
});
|
|
1475
|
+
anchor = normalized.anchor;
|
|
1476
|
+
focus = normalized.focus;
|
|
1477
|
+
const additionalSelectionMode = additive
|
|
1478
|
+
? SheetSelectionCommands_1.SheetAdditionalSelectionMode.AppendCurrent
|
|
1479
|
+
: input.shiftKey
|
|
1480
|
+
? SheetSelectionCommands_1.SheetAdditionalSelectionMode.Preserve
|
|
1481
|
+
: SheetSelectionCommands_1.SheetAdditionalSelectionMode.Clear;
|
|
1482
|
+
// Keep the original anchor when extending a selection with Shift+click.
|
|
1483
|
+
const extendingFromPointer = Boolean(input.shiftKey && __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionOrigin, "f") && region === sear_render_registry_1.CellRegion.Grid);
|
|
1484
|
+
const navigationOrigin = extendingFromPointer ? __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionOrigin, "f") : focus;
|
|
1485
|
+
if (extendingFromPointer) {
|
|
1486
|
+
this.executeSelectionCommand(searCore, anchor, focus, SheetSelectionPipelineNames_1.SheetSelectionSource.Pointer, false, navigationOrigin, focus, additionalSelectionMode, { origin: navigationOrigin, cursor: focus });
|
|
1487
|
+
}
|
|
1488
|
+
else {
|
|
1489
|
+
this.executeSelectionCommand(searCore, anchor, focus, SheetSelectionPipelineNames_1.SheetSelectionSource.Pointer, false, void 0, void 0, additionalSelectionMode, { origin: navigationOrigin, cursor: focus });
|
|
1490
|
+
}
|
|
1491
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_isSelecting, true, "f");
|
|
1492
|
+
(_c = __classPrivateFieldGet(this, _SheetSelectionPlugin_disposeSelectionCapture, "f")) === null || _c === void 0 ? void 0 : _c.call(this);
|
|
1493
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_disposeSelectionCapture, (_e = (_d = this.pointerCapture) === null || _d === void 0 ? void 0 : _d.start({
|
|
1494
|
+
onRelease: () => {
|
|
1495
|
+
var _a, _b;
|
|
1496
|
+
if (!__classPrivateFieldGet(this, _SheetSelectionPlugin_isSelecting, "f"))
|
|
1497
|
+
return;
|
|
1498
|
+
__classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_dispatchPointerInput).call(this, searCore, selectionPointerInput(SheetSelectionPointerCommand_1.SheetSelectionPointerAction.Up));
|
|
1499
|
+
(_a = this.textInput) === null || _a === void 0 ? void 0 : _a.startListener();
|
|
1500
|
+
(_b = this.textInput) === null || _b === void 0 ? void 0 : _b.refocus();
|
|
1501
|
+
},
|
|
1502
|
+
})) !== null && _e !== void 0 ? _e : null, "f");
|
|
1503
|
+
};
|
|
1504
|
+
_SheetSelectionPlugin_handlePointerMove = function _SheetSelectionPlugin_handlePointerMove(searCore, input) {
|
|
1505
|
+
__classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_updatePointerPosition).call(this, input.view);
|
|
1506
|
+
const plan = __classPrivateFieldGet(this, _SheetSelectionPlugin_instances, "m", _SheetSelectionPlugin_planPointerMove).call(this, searCore, input);
|
|
1507
|
+
if (!plan)
|
|
1508
|
+
return;
|
|
1509
|
+
this.executeSelectionCommand(searCore, plan.anchor, plan.focus, SheetSelectionPipelineNames_1.SheetSelectionSource.Pointer, false, plan.activeAnchor, plan.activeFocus, void 0, plan.navigation);
|
|
1510
|
+
};
|
|
1511
|
+
_SheetSelectionPlugin_updatePointerPosition = function _SheetSelectionPlugin_updatePointerPosition(view) {
|
|
1512
|
+
if (!view)
|
|
1513
|
+
return;
|
|
1514
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionPointer, { x: view.x, y: view.y }, "f");
|
|
1515
|
+
this.scheduleSelectionScroll();
|
|
1516
|
+
};
|
|
1517
|
+
_SheetSelectionPlugin_planPointerMove = function _SheetSelectionPlugin_planPointerMove(searCore, input) {
|
|
1518
|
+
var _a, _b, _c, _d;
|
|
1519
|
+
const target = input.target;
|
|
1520
|
+
if (!target) {
|
|
1521
|
+
(_a = this.platform) === null || _a === void 0 ? void 0 : _a.warn('SheetSelectionPlugin onMouseMove event target is null');
|
|
1522
|
+
return null;
|
|
1523
|
+
}
|
|
1524
|
+
const properties = target;
|
|
1525
|
+
const { startRowIndex, startColIndex } = properties;
|
|
1526
|
+
const { endRowIndex, endColIndex } = properties;
|
|
1527
|
+
if (startRowIndex === void 0 || startColIndex === void 0 || endRowIndex === void 0 || endColIndex === void 0) {
|
|
1528
|
+
(_b = this.platform) === null || _b === void 0 ? void 0 : _b.warn('SheetSelectionPlugin onMouseMove target properties is missing ExcelNodeProperties');
|
|
1529
|
+
return null;
|
|
1530
|
+
}
|
|
1531
|
+
const dataEngine = searCore.getDataEngine();
|
|
1532
|
+
const state = dataEngine.getDataType(this.pluginKey);
|
|
1533
|
+
if (!state) {
|
|
1534
|
+
(_c = this.platform) === null || _c === void 0 ? void 0 : _c.warn('SheetSelectionPlugin onMouseMove selection state is not found');
|
|
1535
|
+
return null;
|
|
1536
|
+
}
|
|
1537
|
+
const dataState = readSheetGeometry(dataEngine);
|
|
1538
|
+
if (!dataState)
|
|
1539
|
+
return null;
|
|
1540
|
+
const anchor = state[0].getPoint(0);
|
|
1541
|
+
const focus = state[0].getPoint(1);
|
|
1542
|
+
let currentAnchor;
|
|
1543
|
+
let currentFocus;
|
|
1544
|
+
if (__classPrivateFieldGet(this, _SheetSelectionPlugin_headerDragMode, "f") === 'row') {
|
|
1545
|
+
const lastCol = dataState.columnSizes.shape[1] - 1;
|
|
1546
|
+
const currentRow = Number(startRowIndex);
|
|
1547
|
+
const rowStart = Math.min(anchor[0], currentRow);
|
|
1548
|
+
const rowEnd = Math.max(anchor[0], currentRow);
|
|
1549
|
+
currentAnchor = [rowStart, 0];
|
|
1550
|
+
currentFocus = [rowEnd, lastCol];
|
|
1551
|
+
}
|
|
1552
|
+
else if (__classPrivateFieldGet(this, _SheetSelectionPlugin_headerDragMode, "f") === 'col') {
|
|
1553
|
+
const lastRow = dataState.rowSizes.shape[1] - 1;
|
|
1554
|
+
const currentCol = Number(startColIndex);
|
|
1555
|
+
const colStart = Math.min(anchor[1], currentCol);
|
|
1556
|
+
const colEnd = Math.max(anchor[1], currentCol);
|
|
1557
|
+
currentAnchor = [0, colStart];
|
|
1558
|
+
currentFocus = [lastRow, colEnd];
|
|
1559
|
+
}
|
|
1560
|
+
else {
|
|
1561
|
+
currentAnchor = [Number(startRowIndex), Number(startColIndex)];
|
|
1562
|
+
currentFocus = [Number(endRowIndex), Number(endColIndex)];
|
|
1563
|
+
}
|
|
1564
|
+
let anchorNode;
|
|
1565
|
+
let focusNode;
|
|
1566
|
+
if (__classPrivateFieldGet(this, _SheetSelectionPlugin_headerDragMode, "f") !== 'none') {
|
|
1567
|
+
anchorNode = currentAnchor;
|
|
1568
|
+
focusNode = currentFocus;
|
|
1569
|
+
}
|
|
1570
|
+
else {
|
|
1571
|
+
const boundingRect = sear_foundation_rect_1.Rect.findBoundingRectangle([
|
|
1572
|
+
new sear_foundation_rect_1.Rect([anchor, focus]),
|
|
1573
|
+
new sear_foundation_rect_1.Rect([currentAnchor, currentFocus]),
|
|
1574
|
+
]);
|
|
1575
|
+
anchorNode = boundingRect.getPoint(0);
|
|
1576
|
+
focusNode = boundingRect.getPoint(1);
|
|
1577
|
+
let mergedCell = this.isInMergedCell(new sear_foundation_rect_1.Rect(boundingRect.shape));
|
|
1578
|
+
let times = 0;
|
|
1579
|
+
while (mergedCell) {
|
|
1580
|
+
times++;
|
|
1581
|
+
const boundingRect = sear_foundation_rect_1.Rect.findBoundingRectangle([new sear_foundation_rect_1.Rect([anchorNode, focusNode]), mergedCell]);
|
|
1582
|
+
anchorNode = boundingRect.getPoint(0);
|
|
1583
|
+
focusNode = boundingRect.getPoint(1);
|
|
1584
|
+
mergedCell = this.isInMergedCell(new sear_foundation_rect_1.Rect(boundingRect.shape));
|
|
1585
|
+
if (times > 1000)
|
|
1586
|
+
break;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
return {
|
|
1590
|
+
anchor: anchorNode,
|
|
1591
|
+
focus: focusNode,
|
|
1592
|
+
source: SheetSelectionPipelineNames_1.SheetSelectionSource.Pointer,
|
|
1593
|
+
ensureVisible: false,
|
|
1594
|
+
activeAnchor: anchor,
|
|
1595
|
+
activeFocus: currentFocus,
|
|
1596
|
+
navigation: { origin: (_d = __classPrivateFieldGet(this, _SheetSelectionPlugin_selectionOrigin, "f")) !== null && _d !== void 0 ? _d : anchor, cursor: focusNode },
|
|
1597
|
+
};
|
|
1598
|
+
};
|
|
1599
|
+
_SheetSelectionPlugin_handlePointerUp = function _SheetSelectionPlugin_handlePointerUp() {
|
|
1600
|
+
var _a, _b;
|
|
1601
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_isSelecting, false, "f");
|
|
1602
|
+
(_a = __classPrivateFieldGet(this, _SheetSelectionPlugin_disposeSelectionCapture, "f")) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
1603
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_disposeSelectionCapture, null, "f");
|
|
1604
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionPointer, null, "f");
|
|
1605
|
+
if (__classPrivateFieldGet(this, _SheetSelectionPlugin_selectionScrollFrame, "f") !== null)
|
|
1606
|
+
(_b = this.platform) === null || _b === void 0 ? void 0 : _b.cancelAnimationFrame(__classPrivateFieldGet(this, _SheetSelectionPlugin_selectionScrollFrame, "f"));
|
|
1607
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_selectionScrollFrame, null, "f");
|
|
1608
|
+
__classPrivateFieldSet(this, _SheetSelectionPlugin_headerDragMode, 'none', "f");
|
|
1609
|
+
};
|
|
1610
|
+
_SheetSelectionPlugin_restartNavigation = function _SheetSelectionPlugin_restartNavigation() {
|
|
1611
|
+
this.subscribeNavigationHandlers();
|
|
1612
|
+
this.keyboardRouter.startListener();
|
|
1613
|
+
};
|
|
1614
|
+
/** DI token for resolving SheetSelectionPlugin. */
|
|
1615
|
+
SheetSelectionPlugin.symbol = Symbol.for('SheetSelectionPlugin');
|
|
1616
|
+
/** Stable plugin key for SheetSelectionPlugin. */
|
|
1617
|
+
SheetSelectionPlugin.pluginKey = key;
|
|
1618
|
+
exports.SheetSelectionPlugin = SheetSelectionPlugin = __decorate([
|
|
1619
|
+
(0, sear_foundation_di_1.Injectable)(),
|
|
1620
|
+
__param(0, (0, sear_foundation_di_1.Inject)(sear_plugin_cell_merge_1.SheetCellMergePlugin.symbol)),
|
|
1621
|
+
__param(1, (0, sear_foundation_di_1.Inject)(sear_render_input_1.KeyboardRouter.symbol)),
|
|
1622
|
+
__param(2, (0, sear_foundation_di_1.Inject)(sear_foundation_platform_1.Platform.symbol)),
|
|
1623
|
+
__param(3, (0, sear_foundation_di_1.Inject)(sear_assembly_core_1.SheetInteractionReducerRegistry.symbol)),
|
|
1624
|
+
__param(4, (0, sear_foundation_di_1.Inject)(sear_assembly_commands_1.SheetCommandBus.symbol)),
|
|
1625
|
+
__param(5, (0, sear_foundation_di_1.Inject)(sear_assembly_plugin_1.SheetRangeMoveRegistry.symbol)),
|
|
1626
|
+
__param(6, (0, sear_foundation_di_1.Inject)(SheetRangeDrag_1.SheetRangeDrag.symbol)),
|
|
1627
|
+
__param(7, (0, sear_foundation_di_1.Inject)(SheetHighlightRegistry_1.SheetHighlightRegistry.symbol)),
|
|
1628
|
+
__param(8, (0, sear_foundation_di_1.Inject)(sear_domain_cell_types_1.SheetCellInputValidationRegistry.symbol)),
|
|
1629
|
+
__param(9, (0, sear_foundation_di_1.Inject)(sear_render_input_1.PointerCapture.symbol)),
|
|
1630
|
+
__param(10, (0, sear_foundation_di_1.Inject)(sear_render_input_1.TextInput.symbol)),
|
|
1631
|
+
__param(11, (0, sear_foundation_di_1.Inject)(sear_assembly_plugin_1.SheetFormatTransferRegistry.symbol))
|
|
1632
|
+
], SheetSelectionPlugin);
|
|
1633
|
+
function normalizeDeletedSelection(selection, lastRow, lastColumn) {
|
|
1634
|
+
const start = selection.getPoint(0);
|
|
1635
|
+
const end = selection.getPoint(1);
|
|
1636
|
+
if (start[0] > end[0]) {
|
|
1637
|
+
const row = Math.max(0, Math.min(end[0], lastRow));
|
|
1638
|
+
start[0] = row;
|
|
1639
|
+
end[0] = row;
|
|
1640
|
+
}
|
|
1641
|
+
if (start[1] > end[1]) {
|
|
1642
|
+
const column = Math.max(0, Math.min(end[1], lastColumn));
|
|
1643
|
+
start[1] = column;
|
|
1644
|
+
end[1] = column;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
function selectionContainsPoint(selection, point) {
|
|
1648
|
+
const start = selection.getPoint(0);
|
|
1649
|
+
const end = selection.getPoint(1);
|
|
1650
|
+
return point[0] >= start[0] && point[0] <= end[0] && point[1] >= start[1] && point[1] <= end[1];
|
|
1651
|
+
}
|
|
1652
|
+
//# sourceMappingURL=SheetSelectionPlugin.js.map
|