@univerjs/sheets-formula-ui 1.0.0-alpha.8 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +93 -116
- package/lib/es/index.js +94 -117
- package/lib/index.js +94 -117
- package/lib/types/views/formula-editor/help-function/HelpFunction.d.ts +2 -4
- package/lib/umd/index.js +4 -4
- package/package.json +14 -14
package/lib/es/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { DocBackScrollRenderController, DocSelectionRenderService, IEditorServic
|
|
|
6
6
|
import { DeviceInputEventType, IRenderManagerService, SHEET_VIEWPORT_KEY, ScrollTimerType, UniverRenderEnginePlugin, Vector2 } from "@univerjs/engine-render";
|
|
7
7
|
import { BEFORE_CELL_EDIT, INTERCEPTOR_POINT, IRefSelectionsService, REF_SELECTIONS_ENABLED, RangeProtectionPermissionEditPoint, RangeProtectionPermissionViewPoint, ReorderRangeCommand, SelectionMoveType, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SetSelectionsOperation, SetWorksheetActiveOperation, SetWorksheetRowAutoHeightMutation, SheetInterceptorService, SheetSkeletonService, SheetsSelectionsService, UniverSheetsPlugin, WorkbookCopyPermission, WorkbookEditablePermission, WorksheetCopyPermission, WorksheetEditPermission, WorksheetSetCellValuePermission, attachSelectionWithCoord, convertSelectionDataToRange, getCellAtRowCol, getSheetCommandTarget, setEndForRange } from "@univerjs/sheets";
|
|
8
8
|
import { ImageFormulaCellInterceptorController, InsertFunctionCommand, PLUGIN_CONFIG_KEY_BASE, QuickSumCommand, TriggerCalculationController, UniverSheetsFormulaPlugin } from "@univerjs/sheets-formula";
|
|
9
|
-
import { BuiltInUIPart, ComponentManager, IContextMenuService, IMenuManagerService, IShortcutService, ISidebarService, IUIPartsService, IconManager, KeyCode, MenuItemType, MetaKeys, ProgressBar, RectPopup, RibbonFormulasGroup,
|
|
9
|
+
import { BuiltInUIPart, ComponentManager, IContextMenuService, IMenuManagerService, IShortcutService, ISidebarService, IUIPartsService, IconManager, KeyCode, MenuItemType, MetaKeys, ProgressBar, RectPopup, RibbonFormulasGroup, connectInjector, getMenuHiddenObservable, useDependency, useEvent, useObservable, useUpdateEffect } from "@univerjs/ui";
|
|
10
10
|
import { DocSelectionManagerService } from "@univerjs/docs";
|
|
11
11
|
import { CheckMarkIcon, CloseIcon, DatabaseFunctionIcon, DateFunctionIcon, DeleteIcon, EngineeringFunctionIcon, FinancialFunctionIcon, FunctionIcon, IncreaseIcon, InformationFunctionIcon, LogicalFunctionIcon, LookupFunctionIcon, MathFunctionIcon, MoreRightIcon, SelectRangeIcon, StatisticalFunctionIcon, TextFunctionIcon } from "@univerjs/icons";
|
|
12
12
|
import { Button, Dialog, Input, Select, Tooltip, borderClassName, borderLeftClassName, borderTopClassName, clsx, divideYClassName, scrollbarClassName } from "@univerjs/design";
|
|
@@ -305,10 +305,9 @@ const InsertFunctionOperation = {
|
|
|
305
305
|
let editColumn = 0;
|
|
306
306
|
let editFormulaRangeString = "";
|
|
307
307
|
if (currentSelections.length === 1 && (isSingleCell(currentSelections[0].range) || isMultiRowsColumnsRange(currentSelections[0].range) && rangeHasNoNumber(cellMatrix, currentSelections[0].range))) {
|
|
308
|
-
var _primary$actualRow, _primary$actualColumn;
|
|
309
308
|
const { range, primary } = currentSelections[0];
|
|
310
|
-
const row = (
|
|
311
|
-
const column = (
|
|
309
|
+
const row = (primary === null || primary === void 0 ? void 0 : primary.actualRow) ?? range.startRow;
|
|
310
|
+
const column = (primary === null || primary === void 0 ? void 0 : primary.actualColumn) ?? range.startColumn;
|
|
312
311
|
editRange = range;
|
|
313
312
|
editRow = row;
|
|
314
313
|
editColumn = column;
|
|
@@ -317,9 +316,8 @@ const InsertFunctionOperation = {
|
|
|
317
316
|
} else currentSelections.some((selection) => {
|
|
318
317
|
const { range, primary } = selection;
|
|
319
318
|
if (rangeHasNoNumber(cellMatrix, range)) {
|
|
320
|
-
|
|
321
|
-
const
|
|
322
|
-
const column = (_primary$actualColumn2 = primary === null || primary === void 0 ? void 0 : primary.actualColumn) !== null && _primary$actualColumn2 !== void 0 ? _primary$actualColumn2 : range.startColumn;
|
|
319
|
+
const row = (primary === null || primary === void 0 ? void 0 : primary.actualRow) ?? range.startRow;
|
|
320
|
+
const column = (primary === null || primary === void 0 ? void 0 : primary.actualColumn) ?? range.startColumn;
|
|
323
321
|
const refRange = findRefRange(cellMatrix, row, column);
|
|
324
322
|
if (!refRange) {
|
|
325
323
|
editRange = range;
|
|
@@ -666,7 +664,7 @@ const ReferenceAbsoluteOperation = {
|
|
|
666
664
|
id: "formula-ui.operation.change-ref-to-absolute",
|
|
667
665
|
type: CommandType.OPERATION,
|
|
668
666
|
handler: async (accessor) => {
|
|
669
|
-
var _focusEditor$getDocum
|
|
667
|
+
var _focusEditor$getDocum;
|
|
670
668
|
const editorService = accessor.get(IEditorService);
|
|
671
669
|
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
|
|
672
670
|
const lexerTreeBuilder = accessor.get(LexerTreeBuilder);
|
|
@@ -676,7 +674,7 @@ const ReferenceAbsoluteOperation = {
|
|
|
676
674
|
if (editorId !== DOCS_NORMAL_EDITOR_UNIT_ID_KEY && editorId !== DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) return false;
|
|
677
675
|
const activeTextRange = docSelectionManagerService.getActiveTextRange();
|
|
678
676
|
if (!activeTextRange) return false;
|
|
679
|
-
const nextReferenceState = toggleReferenceAbsoluteAtCursor(lexerTreeBuilder, BuildTextUtils.transform.getPlainText((_focusEditor$getDocum =
|
|
677
|
+
const nextReferenceState = toggleReferenceAbsoluteAtCursor(lexerTreeBuilder, BuildTextUtils.transform.getPlainText(((_focusEditor$getDocum = focusEditor.getDocumentData().body) === null || _focusEditor$getDocum === void 0 ? void 0 : _focusEditor$getDocum.dataStream) ?? ""), activeTextRange.endOffset);
|
|
680
678
|
if (!nextReferenceState) return false;
|
|
681
679
|
focusEditor.replaceText(nextReferenceState.formulaText, [{
|
|
682
680
|
startOffset: nextReferenceState.cursorOffset,
|
|
@@ -995,7 +993,7 @@ const menuSchema = {
|
|
|
995
993
|
//#endregion
|
|
996
994
|
//#region package.json
|
|
997
995
|
var name = "@univerjs/sheets-formula-ui";
|
|
998
|
-
var version = "1.0.0-
|
|
996
|
+
var version = "1.0.0-beta.0";
|
|
999
997
|
|
|
1000
998
|
//#endregion
|
|
1001
999
|
//#region src/config/config.ts
|
|
@@ -1049,8 +1047,7 @@ const FORMULA_EMBED_CHILD_UNIT_ID_ATTRIBUTE = "data-embed-child-unit-id";
|
|
|
1049
1047
|
const IFormulaEmbedRuntimeFocusCoordinator = createIdentifier("sheets-formula-ui.embed-runtime-focus-coordinator");
|
|
1050
1048
|
const IFormulaEmbedInteractionBoundaryService = createIdentifier("sheets-formula-ui.embed-interaction-boundary.service");
|
|
1051
1049
|
function registerFormulaEditorRuntimePortal(options) {
|
|
1052
|
-
|
|
1053
|
-
const ownerDocument = (_options$ownerDocumen = options.ownerDocument) !== null && _options$ownerDocumen !== void 0 ? _options$ownerDocumen : typeof document === "undefined" ? void 0 : document;
|
|
1050
|
+
const ownerDocument = options.ownerDocument ?? (typeof document === "undefined" ? void 0 : document);
|
|
1054
1051
|
if (!ownerDocument) return toDisposable(() => {});
|
|
1055
1052
|
const collection = new DisposableCollection();
|
|
1056
1053
|
const view = ownerDocument.defaultView;
|
|
@@ -1105,8 +1102,7 @@ function registerFormulaEditorRuntimePortal(options) {
|
|
|
1105
1102
|
return collection;
|
|
1106
1103
|
}
|
|
1107
1104
|
function resolveFormulaEditorPortalRoot(editorId, ownerDocument) {
|
|
1108
|
-
|
|
1109
|
-
return (_ref = ownerDocument.getElementById(`univer-doc-selection-container-${editorId}`)) !== null && _ref !== void 0 ? _ref : ownerDocument.getElementById(`__editor_${editorId}`);
|
|
1105
|
+
return ownerDocument.getElementById(`univer-doc-selection-container-${editorId}`) ?? ownerDocument.getElementById(`__editor_${editorId}`);
|
|
1110
1106
|
}
|
|
1111
1107
|
function registerFormulaEditorPortalRoot(options, ownerDocument, portalRoot) {
|
|
1112
1108
|
const collection = new DisposableCollection();
|
|
@@ -1122,14 +1118,13 @@ function registerFormulaEditorPortalRoot(options, ownerDocument, portalRoot) {
|
|
|
1122
1118
|
return collection;
|
|
1123
1119
|
}
|
|
1124
1120
|
function resolveFormulaEmbedRuntimeDomScope(root) {
|
|
1125
|
-
var _scopeElement$getAttr, _scopeElement$getAttr2;
|
|
1126
1121
|
const scopeElement = root === null || root === void 0 ? void 0 : root.closest(`[${FORMULA_EMBED_ID_ATTRIBUTE}]`);
|
|
1127
1122
|
const embedId = scopeElement === null || scopeElement === void 0 ? void 0 : scopeElement.getAttribute(FORMULA_EMBED_ID_ATTRIBUTE);
|
|
1128
1123
|
if (!scopeElement || !embedId) return;
|
|
1129
1124
|
return {
|
|
1130
1125
|
embedId,
|
|
1131
|
-
hostUnitId:
|
|
1132
|
-
childUnitId:
|
|
1126
|
+
hostUnitId: scopeElement.getAttribute("data-embed-host-unit-id") ?? void 0,
|
|
1127
|
+
childUnitId: scopeElement.getAttribute("data-embed-child-unit-id") ?? void 0
|
|
1133
1128
|
};
|
|
1134
1129
|
}
|
|
1135
1130
|
function resolveActiveFormulaEmbedRuntimeDomScope(ownerDocument) {
|
|
@@ -1141,9 +1136,9 @@ function isEventTargetInSameFormulaEmbedInteractionBoundary(left, right) {
|
|
|
1141
1136
|
return Boolean(leftOwner && leftOwner === resolveFormulaEmbedInteractionOwnerId(right));
|
|
1142
1137
|
}
|
|
1143
1138
|
function resolveFormulaEmbedInteractionOwnerId(target) {
|
|
1144
|
-
var _target$closest
|
|
1139
|
+
var _target$closest;
|
|
1145
1140
|
if (!(target instanceof Element)) return;
|
|
1146
|
-
return (
|
|
1141
|
+
return ((_target$closest = target.closest(`[${"data-embed-interaction-boundary-owner"}]`)) === null || _target$closest === void 0 ? void 0 : _target$closest.getAttribute("data-embed-interaction-boundary-owner")) ?? void 0;
|
|
1147
1142
|
}
|
|
1148
1143
|
|
|
1149
1144
|
//#endregion
|
|
@@ -1255,7 +1250,7 @@ function useEditorPosition(editorId, ready, deps) {
|
|
|
1255
1250
|
univerInstanceService.unitAdded$,
|
|
1256
1251
|
updatePosition,
|
|
1257
1252
|
ready,
|
|
1258
|
-
...deps
|
|
1253
|
+
...deps ?? []
|
|
1259
1254
|
]);
|
|
1260
1255
|
useResizeScrollObserver(updatePosition);
|
|
1261
1256
|
useEffect(() => {
|
|
@@ -1309,7 +1304,7 @@ const useFormulaDescribe = (isNeed, formulaText, editor) => {
|
|
|
1309
1304
|
};
|
|
1310
1305
|
useEffect(() => {
|
|
1311
1306
|
const nodes = lexerTreeBuilder.sequenceNodesBuilder(formulaText.slice(1));
|
|
1312
|
-
formulaPromptService.setSequenceNodes(nodes
|
|
1307
|
+
formulaPromptService.setSequenceNodes(nodes ?? []);
|
|
1313
1308
|
}, [formulaText]);
|
|
1314
1309
|
useEffect(() => {
|
|
1315
1310
|
if (editor && isNeed) {
|
|
@@ -1387,20 +1382,19 @@ const HelpHiddenTip = ({ onClick }) => {
|
|
|
1387
1382
|
|
|
1388
1383
|
//#endregion
|
|
1389
1384
|
//#region src/views/formula-editor/help-function/HelpFunction.tsx
|
|
1390
|
-
|
|
1391
|
-
const localeService = useDependency(LocaleService);
|
|
1385
|
+
function Params({ className, title, value }) {
|
|
1392
1386
|
return /* @__PURE__ */ jsxs("div", {
|
|
1393
1387
|
className: "univer-my-2",
|
|
1394
1388
|
children: [/* @__PURE__ */ jsx("div", {
|
|
1395
1389
|
className: clsx("univer-mb-2 univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white", className),
|
|
1396
|
-
children:
|
|
1390
|
+
children: title
|
|
1397
1391
|
}), /* @__PURE__ */ jsx("div", {
|
|
1398
1392
|
className: "univer-whitespace-pre-wrap univer-break-words univer-text-xs univer-text-gray-500",
|
|
1399
1393
|
children: value
|
|
1400
1394
|
})]
|
|
1401
1395
|
});
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1396
|
+
}
|
|
1397
|
+
function Help(props) {
|
|
1404
1398
|
const { prefix, value, active, onClick } = props;
|
|
1405
1399
|
return /* @__PURE__ */ jsxs("div", { children: [
|
|
1406
1400
|
/* @__PURE__ */ jsxs("span", { children: [prefix, "("] }),
|
|
@@ -1411,7 +1405,7 @@ const Help = (props) => {
|
|
|
1411
1405
|
}), i === value.length - 1 ? "" : ","] }, item.name)),
|
|
1412
1406
|
")"
|
|
1413
1407
|
] });
|
|
1414
|
-
}
|
|
1408
|
+
}
|
|
1415
1409
|
function HelpFunction(props) {
|
|
1416
1410
|
const { onParamsSwitch = noop, onClose: propColose = noop, isFocus, editor, formulaText } = props;
|
|
1417
1411
|
const { functionInfo, paramIndex, reset } = useFormulaDescribe(isFocus, formulaText, editor);
|
|
@@ -1475,11 +1469,11 @@ function HelpFunction(props) {
|
|
|
1475
1469
|
className: "univer-mt-3",
|
|
1476
1470
|
children: [
|
|
1477
1471
|
/* @__PURE__ */ jsx(Params, {
|
|
1478
|
-
|
|
1472
|
+
title: localeService.t("sheets-formula-ui.prompt.helpExample"),
|
|
1479
1473
|
value: `${functionInfo.functionName}(${functionInfo.functionParameter.map((item) => item.example).join(",")})`
|
|
1480
1474
|
}),
|
|
1481
1475
|
/* @__PURE__ */ jsx(Params, {
|
|
1482
|
-
|
|
1476
|
+
title: localeService.t("sheets-formula-ui.prompt.helpAbstract"),
|
|
1483
1477
|
value: functionInfo.description
|
|
1484
1478
|
}),
|
|
1485
1479
|
functionInfo && functionInfo.functionParameter && functionInfo.functionParameter.map((item, i) => /* @__PURE__ */ jsx(Params, {
|
|
@@ -1507,8 +1501,8 @@ function focusFormulaEditor(editorService, editor, offset) {
|
|
|
1507
1501
|
endOffset: offset
|
|
1508
1502
|
}]);
|
|
1509
1503
|
else if (!selections.length) {
|
|
1510
|
-
var _editor$getDocumentDa
|
|
1511
|
-
const body = (_editor$getDocumentDa =
|
|
1504
|
+
var _editor$getDocumentDa;
|
|
1505
|
+
const body = ((_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream) ?? "\r\n";
|
|
1512
1506
|
const offset = Math.max(body.length - 2, 0);
|
|
1513
1507
|
editor.setSelectionRanges([{
|
|
1514
1508
|
startOffset: offset,
|
|
@@ -1517,8 +1511,8 @@ function focusFormulaEditor(editorService, editor, offset) {
|
|
|
1517
1511
|
} else editor.setSelectionRanges(selections);
|
|
1518
1512
|
}
|
|
1519
1513
|
function focusFormulaEditorElement(editor) {
|
|
1520
|
-
var _editor$editorDOM
|
|
1521
|
-
const editorElement = ((
|
|
1514
|
+
var _editor$editorDOM;
|
|
1515
|
+
const editorElement = (((_editor$editorDOM = editor.editorDOM) === null || _editor$editorDOM === void 0 ? void 0 : _editor$editorDOM.ownerDocument) ?? document).getElementById(`__editor_${editor.getEditorId()}`);
|
|
1522
1516
|
editorElement === null || editorElement === void 0 || editorElement.focus({ preventScroll: true });
|
|
1523
1517
|
}
|
|
1524
1518
|
function shouldSkipFormulaEditorMouseUpFocus(_target) {
|
|
@@ -1652,9 +1646,8 @@ let RefSelectionsRenderService = class RefSelectionsRenderService extends BaseSe
|
|
|
1652
1646
|
* @param {ISelectionWithCoord} selectionWithStyle
|
|
1653
1647
|
*/
|
|
1654
1648
|
_addSelectionControlByModelData(selectionWithStyle) {
|
|
1655
|
-
var _selectionWithStyle$s;
|
|
1656
1649
|
const skeleton = this._skeleton;
|
|
1657
|
-
const style =
|
|
1650
|
+
const style = selectionWithStyle.style ?? genNormalSelectionStyle(this._themeService);
|
|
1658
1651
|
const scene = this._scene;
|
|
1659
1652
|
selectionWithStyle.style = style;
|
|
1660
1653
|
return this.newSelectionControl(scene, skeleton, selectionWithStyle);
|
|
@@ -1886,18 +1879,17 @@ function getDefaultRefSelectionStyle(themeService) {
|
|
|
1886
1879
|
//#endregion
|
|
1887
1880
|
//#region src/views/formula-editor/hooks/use-formula-selection.ts
|
|
1888
1881
|
function resolveFormulaSelectionDataStream(accssor, editor, editorId) {
|
|
1889
|
-
var _editor$getDocumentDa, _documentModel$getBod
|
|
1882
|
+
var _editor$getDocumentDa, _documentModel$getBod;
|
|
1890
1883
|
const editorDataStream = editor === null || editor === void 0 || (_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream;
|
|
1891
1884
|
if (editorDataStream != null) return {
|
|
1892
1885
|
dataStream: editorDataStream,
|
|
1893
1886
|
offset: 0
|
|
1894
1887
|
};
|
|
1895
1888
|
const univerInstanceService = accssor.get(IUniverInstanceService);
|
|
1896
|
-
const
|
|
1897
|
-
const documentModel = editorDocumentModel !== null && editorDocumentModel !== void 0 ? editorDocumentModel : univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
1889
|
+
const documentModel = (editorId ? univerInstanceService.getUnit(editorId, UniverInstanceType.UNIVER_DOC) : void 0) ?? univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
1898
1890
|
if (!(documentModel === null || documentModel === void 0 ? void 0 : documentModel.getBody())) return;
|
|
1899
1891
|
return {
|
|
1900
|
-
dataStream: (_documentModel$getBod =
|
|
1892
|
+
dataStream: ((_documentModel$getBod = documentModel.getBody()) === null || _documentModel$getBod === void 0 ? void 0 : _documentModel$getBod.dataStream) ?? "",
|
|
1901
1893
|
offset: 0
|
|
1902
1894
|
};
|
|
1903
1895
|
}
|
|
@@ -1905,8 +1897,7 @@ function shouldSkipReferenceEditingByPointer(isDisabledByPointer, disableOnClick
|
|
|
1905
1897
|
return isDisabledByPointer && !disableOnClick;
|
|
1906
1898
|
}
|
|
1907
1899
|
function resolveFormulaSelectionWorkbook(currentWorkbook, fallbackWorkbook) {
|
|
1908
|
-
|
|
1909
|
-
return (_ref = currentWorkbook !== null && currentWorkbook !== void 0 ? currentWorkbook : fallbackWorkbook) !== null && _ref !== void 0 ? _ref : void 0;
|
|
1900
|
+
return currentWorkbook ?? fallbackWorkbook ?? void 0;
|
|
1910
1901
|
}
|
|
1911
1902
|
function resolveFormulaSelectionCursorIndex(activeRange, dataStream) {
|
|
1912
1903
|
const index = (activeRange === null || activeRange === void 0 ? void 0 : activeRange.collapsed) ? activeRange.startOffset : -1;
|
|
@@ -1955,16 +1946,16 @@ function useFormulaSelecting(opts) {
|
|
|
1955
1946
|
innerSetIsSelecting(v);
|
|
1956
1947
|
});
|
|
1957
1948
|
const calculateSelectingType = useEvent(() => {
|
|
1958
|
-
var _editor$getSelectionR,
|
|
1949
|
+
var _editor$getSelectionR, _config$dataStream;
|
|
1959
1950
|
const currentWorkbook = resolveFormulaSelectionWorkbook(univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET), workbook);
|
|
1960
1951
|
if (!currentWorkbook) return;
|
|
1961
1952
|
const currentSheet = currentWorkbook.getActiveSheet();
|
|
1962
|
-
const activeRange = (
|
|
1953
|
+
const activeRange = (editor === null || editor === void 0 || (_editor$getSelectionR = editor.getSelectionRanges()) === null || _editor$getSelectionR === void 0 ? void 0 : _editor$getSelectionR[0]) ?? (docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.getActiveTextRange());
|
|
1963
1954
|
const config = resolveFormulaSelectionDataStream(injector, editor, editorId);
|
|
1964
1955
|
if (!config) return;
|
|
1965
1956
|
const dataStream = config === null || config === void 0 || (_config$dataStream = config.dataStream) === null || _config$dataStream === void 0 ? void 0 : _config$dataStream.slice(0, -2);
|
|
1966
|
-
const index = resolveFormulaSelectionCursorIndex(
|
|
1967
|
-
const nodes = (
|
|
1957
|
+
const index = resolveFormulaSelectionCursorIndex(getSelectionAfterLaggingFormulaInput(dataStream, activeRange, lastInputContentRef.current) ?? activeRange, dataStream);
|
|
1958
|
+
const nodes = (lexerTreeBuilder.sequenceNodesBuilder(dataStream) ?? []).map((node) => {
|
|
1968
1959
|
if (typeof node === "object") {
|
|
1969
1960
|
if (node.nodeType === sequenceNodeType.REFERENCE) return {
|
|
1970
1961
|
...node,
|
|
@@ -2172,7 +2163,7 @@ function useSheetHighlight(unitId, subUnitId) {
|
|
|
2172
2163
|
const ownerWorkbook = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
2173
2164
|
const currentWorkbook = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
|
|
2174
2165
|
const currentUnitId = currentWorkbook === null || currentWorkbook === void 0 ? void 0 : currentWorkbook.getUnitId();
|
|
2175
|
-
return Boolean(currentUnitId) && refSelections.some((refSelection) => deserializeRangeWithSheet(refSelection.token).unitId === currentUnitId) ? currentWorkbook : ownerWorkbook
|
|
2166
|
+
return Boolean(currentUnitId) && refSelections.some((refSelection) => deserializeRangeWithSheet(refSelection.token).unitId === currentUnitId) ? currentWorkbook : ownerWorkbook ?? currentWorkbook;
|
|
2176
2167
|
});
|
|
2177
2168
|
const highlightSheet = useEvent((refSelections, editor, isEnd = false) => {
|
|
2178
2169
|
var _currentWorkbook$getA;
|
|
@@ -2252,7 +2243,7 @@ function useDocHight(_leadingCharacter = "") {
|
|
|
2252
2243
|
commandService.syncExecuteCommand(ReplaceTextRunsCommand.id, {
|
|
2253
2244
|
unitId: editorId,
|
|
2254
2245
|
body: createFormulaHighlightBody(highlightDataStream.slice(0, -2), highlightTextRuns),
|
|
2255
|
-
textRanges: newSelections
|
|
2246
|
+
textRanges: newSelections ?? selections
|
|
2256
2247
|
});
|
|
2257
2248
|
return refSelections;
|
|
2258
2249
|
}
|
|
@@ -2304,10 +2295,9 @@ function shouldMoveFormulaSelectionFromCurrentSelection(selectingType, refSelect
|
|
|
2304
2295
|
return selectingType === 3;
|
|
2305
2296
|
}
|
|
2306
2297
|
function isFormulaEditorInteractionOwner(focusEditorId, editorId, options) {
|
|
2307
|
-
var _options$formulaBarEd, _options$normalEditor;
|
|
2308
2298
|
if (focusEditorId === editorId) return true;
|
|
2309
2299
|
if (!(options === null || options === void 0 ? void 0 : options.fxBarFocused)) return false;
|
|
2310
|
-
return editorId === (
|
|
2300
|
+
return editorId === (options.formulaBarEditorId ?? DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) && focusEditorId === (options.normalEditorId ?? DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
|
|
2311
2301
|
}
|
|
2312
2302
|
const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEditor, getRefSelectionCount) => {
|
|
2313
2303
|
const commandService = useDependency(ICommandService);
|
|
@@ -2353,8 +2343,8 @@ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEdito
|
|
|
2353
2343
|
else if (keycode === KeyCode.ARROW_LEFT) direction = Direction.LEFT;
|
|
2354
2344
|
else if (keycode === KeyCode.ARROW_RIGHT) direction = Direction.RIGHT;
|
|
2355
2345
|
if (shouldMoveSelectionRef.current) {
|
|
2356
|
-
var _getRefSelectionCount
|
|
2357
|
-
const fromCurrentSelection = shouldMoveFormulaSelectionFromCurrentSelection(shouldMoveSelectionRef.current, (_getRefSelectionCount =
|
|
2346
|
+
var _getRefSelectionCount;
|
|
2347
|
+
const fromCurrentSelection = shouldMoveFormulaSelectionFromCurrentSelection(shouldMoveSelectionRef.current, ((_getRefSelectionCount = getRefSelectionCountRef.current) === null || _getRefSelectionCount === void 0 ? void 0 : _getRefSelectionCount.call(getRefSelectionCountRef)) ?? 0);
|
|
2358
2348
|
if (metaKey === MetaKeys.CTRL_COMMAND) commandService.executeCommand(MoveSelectionCommand.id, {
|
|
2359
2349
|
direction,
|
|
2360
2350
|
jumpOver: JumpOver.moveGap,
|
|
@@ -2470,14 +2460,13 @@ const useLeftAndRightArrow = (isNeed, shouldMoveSelection, editor, onMoveInEdito
|
|
|
2470
2460
|
//#endregion
|
|
2471
2461
|
//#region src/views/formula-editor/hooks/use-refactor-effect.ts
|
|
2472
2462
|
const useRefactorEffect = (isNeed, selecting, unitId, editorId, disableContextMenu = true) => {
|
|
2473
|
-
var _currentUnit$getUnitI;
|
|
2474
2463
|
const renderManagerService = useDependency(IRenderManagerService);
|
|
2475
2464
|
const contextService = useDependency(IContextService);
|
|
2476
2465
|
const contextMenuService = useDependency(IContextMenuService);
|
|
2477
2466
|
const refSelectionsService = useDependency(IRefSelectionsService);
|
|
2478
2467
|
const univerInstanceService = useDependency(IUniverInstanceService);
|
|
2479
2468
|
const currentUnit = useObservable(useMemo(() => univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET), [univerInstanceService]));
|
|
2480
|
-
const render = renderManagerService.getRenderUnitById((
|
|
2469
|
+
const render = renderManagerService.getRenderUnitById((currentUnit === null || currentUnit === void 0 ? void 0 : currentUnit.getUnitId()) ?? "");
|
|
2481
2470
|
const refSelectionsRenderService = render === null || render === void 0 ? void 0 : render.with(RefSelectionsRenderService);
|
|
2482
2471
|
useLayoutEffect(() => {
|
|
2483
2472
|
if (isNeed) {
|
|
@@ -2566,11 +2555,11 @@ const unitRangesToText = (ranges, isNeedSheetName = false, originSheetName = "",
|
|
|
2566
2555
|
//#endregion
|
|
2567
2556
|
//#region src/views/formula-editor/hooks/use-sheet-selection-change.ts
|
|
2568
2557
|
const prepareSelectionChangeContext = (opts) => {
|
|
2569
|
-
var _editor$getDocumentDa
|
|
2558
|
+
var _editor$getDocumentDa;
|
|
2570
2559
|
const { editor, lexerTreeBuilder } = opts;
|
|
2571
2560
|
const currentDocSelections = editor === null || editor === void 0 ? void 0 : editor.getSelectionRanges();
|
|
2572
|
-
const dataStream = ((
|
|
2573
|
-
const sequenceNodes =
|
|
2561
|
+
const dataStream = ((editor === null || editor === void 0 || (_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream) ?? "\r\n").slice(0, -2);
|
|
2562
|
+
const sequenceNodes = lexerTreeBuilder.sequenceNodesBuilder(dataStream.slice(1)) ?? [];
|
|
2574
2563
|
let offset;
|
|
2575
2564
|
if ((currentDocSelections === null || currentDocSelections === void 0 ? void 0 : currentDocSelections.length) === 1) offset = currentDocSelections[0].startOffset - 1;
|
|
2576
2565
|
else if (dataStream.startsWith("=")) offset = Math.max(dataStream.length - 1, 0);
|
|
@@ -2605,14 +2594,13 @@ function getLastFormulaSelection(selections) {
|
|
|
2605
2594
|
return selections[selections.length - 1];
|
|
2606
2595
|
}
|
|
2607
2596
|
function getFormulaSelectionIdentityKey(selection) {
|
|
2608
|
-
var _ref, _item$rangeWithCoord, _range$startRow, _range$endRow, _range$startColumn, _range$endColumn;
|
|
2609
2597
|
const item = selection;
|
|
2610
|
-
const range =
|
|
2598
|
+
const range = item.rangeWithCoord ?? item.range ?? item;
|
|
2611
2599
|
return [
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2600
|
+
range.startRow ?? "",
|
|
2601
|
+
range.endRow ?? "",
|
|
2602
|
+
range.startColumn ?? "",
|
|
2603
|
+
range.endColumn ?? ""
|
|
2616
2604
|
].join(":");
|
|
2617
2605
|
}
|
|
2618
2606
|
function isSameFormulaSelection(first, second) {
|
|
@@ -2647,10 +2635,9 @@ function createSelectionChangeDuplicateEndGuard() {
|
|
|
2647
2635
|
};
|
|
2648
2636
|
}
|
|
2649
2637
|
function createSelectionChangeHandler(opts) {
|
|
2650
|
-
var _opts$duplicateEndGua;
|
|
2651
2638
|
let prevSelectionsCount = opts.initialSelectionsCount;
|
|
2652
2639
|
let pendingCtrlAddCount = 0;
|
|
2653
|
-
const duplicateEndGuard =
|
|
2640
|
+
const duplicateEndGuard = opts.duplicateEndGuard ?? createSelectionChangeDuplicateEndGuard();
|
|
2654
2641
|
return (selections, isEnd, options) => {
|
|
2655
2642
|
if (options === null || options === void 0 ? void 0 : options.initial) return;
|
|
2656
2643
|
if (selections.length === 0) return;
|
|
@@ -2696,7 +2683,6 @@ function getInitialFormulaReferenceSelectionCount(renderSelectionCount, formulaR
|
|
|
2696
2683
|
return Math.max(renderSelectionCount, formulaReferenceCount);
|
|
2697
2684
|
}
|
|
2698
2685
|
const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUnitId, getRefSelections, isSupportAcrossSheet, listenSelectionSet, editor, handleRangeChange = noop) => {
|
|
2699
|
-
var _activeWorkbook$getUn;
|
|
2700
2686
|
const renderManagerService = useDependency(IRenderManagerService);
|
|
2701
2687
|
const univerInstanceService = useDependency(IUniverInstanceService);
|
|
2702
2688
|
const commandService = useDependency(ICommandService);
|
|
@@ -2707,8 +2693,8 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
|
|
|
2707
2693
|
const lexerTreeBuilder = useDependency(LexerTreeBuilder);
|
|
2708
2694
|
const workbook = univerInstanceService.getUnit(unitId);
|
|
2709
2695
|
const getSheetNameById = useEvent((unitId, sheetId) => {
|
|
2710
|
-
var _univerInstanceServic
|
|
2711
|
-
return (_univerInstanceServic =
|
|
2696
|
+
var _univerInstanceServic;
|
|
2697
|
+
return ((_univerInstanceServic = univerInstanceService.getUnit(unitId)) === null || _univerInstanceServic === void 0 || (_univerInstanceServic = _univerInstanceServic.getSheetBySheetId(sheetId)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getName()) ?? "";
|
|
2712
2698
|
});
|
|
2713
2699
|
const sheetName = useMemo(() => getSheetNameById(unitId, subUnitId), [
|
|
2714
2700
|
getSheetNameById,
|
|
@@ -2721,7 +2707,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
|
|
|
2721
2707
|
sheetName
|
|
2722
2708
|
});
|
|
2723
2709
|
const activeWorkbook = resolveFormulaSelectionWorkbook(useObservable(useMemo(() => univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET), [univerInstanceService])), workbook);
|
|
2724
|
-
const render = renderManagerService.getRenderUnitById((
|
|
2710
|
+
const render = renderManagerService.getRenderUnitById((activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) ?? unitId);
|
|
2725
2711
|
const refSelectionsRenderService = render === null || render === void 0 ? void 0 : render.with(RefSelectionsRenderService);
|
|
2726
2712
|
const sheetSkeletonManagerService = render === null || render === void 0 ? void 0 : render.with(SheetSkeletonManagerService);
|
|
2727
2713
|
const refSelectionsService = useDependency(IRefSelectionsService);
|
|
@@ -2735,16 +2721,15 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
|
|
|
2735
2721
|
if (!ctx) return;
|
|
2736
2722
|
const { nodeIndex, updatingRefIndex, formulaText, sequenceNodes, offset } = ctx;
|
|
2737
2723
|
if (isSelectingRef.current === 1 || isFormulaReferenceAddingContext(sequenceNodes, offset) || isFormulaReferenceAddingTextContext(formulaText, offset)) if (offset !== 0) {
|
|
2738
|
-
var _range$sheetId, _range$unitId, _range$unitId2;
|
|
2739
2724
|
if (nodeIndex === -1 && sequenceNodes.length) return;
|
|
2740
2725
|
const range = getLastFormulaSelection(selections);
|
|
2741
2726
|
if (!range) return;
|
|
2742
2727
|
const lastNodes = sequenceNodes.splice(nodeIndex + 1);
|
|
2743
|
-
const rangeSheetId =
|
|
2728
|
+
const rangeSheetId = range.sheetId ?? subUnitId;
|
|
2744
2729
|
const unitRangeName = {
|
|
2745
2730
|
range,
|
|
2746
|
-
unitId:
|
|
2747
|
-
sheetName: getSheetNameById(
|
|
2731
|
+
unitId: range.unitId ?? activeWorkbook.getUnitId(),
|
|
2732
|
+
sheetName: getSheetNameById(range.unitId ?? activeWorkbook.getUnitId(), rangeSheetId)
|
|
2748
2733
|
};
|
|
2749
2734
|
const isAcrossSheet = rangeSheetId !== subUnitId;
|
|
2750
2735
|
const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
|
|
@@ -2759,14 +2744,13 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
|
|
|
2759
2744
|
});
|
|
2760
2745
|
handleRangeChange(sequenceNodeToText([...sequenceNodes, ...lastNodes]), getOffsetFromSequenceNodes(sequenceNodes), isEnd);
|
|
2761
2746
|
} else {
|
|
2762
|
-
var _range$sheetId2, _range$unitId3, _range$unitId4;
|
|
2763
2747
|
const range = getLastFormulaSelection(selections);
|
|
2764
2748
|
if (!range) return;
|
|
2765
|
-
const rangeSheetId =
|
|
2749
|
+
const rangeSheetId = range.sheetId ?? subUnitId;
|
|
2766
2750
|
const unitRangeName = {
|
|
2767
2751
|
range,
|
|
2768
|
-
unitId:
|
|
2769
|
-
sheetName: getSheetNameById(
|
|
2752
|
+
unitId: range.unitId ?? activeWorkbook.getUnitId(),
|
|
2753
|
+
sheetName: getSheetNameById(range.unitId ?? activeWorkbook.getUnitId(), rangeSheetId)
|
|
2770
2754
|
};
|
|
2771
2755
|
const isAcrossSheet = rangeSheetId !== subUnitId;
|
|
2772
2756
|
const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
|
|
@@ -2783,22 +2767,19 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
|
|
|
2783
2767
|
const node = sequenceNodes[nodeIndex];
|
|
2784
2768
|
if (typeof node === "object" && node.nodeType === sequenceNodeType.REFERENCE) {
|
|
2785
2769
|
const oldToken = node.token;
|
|
2786
|
-
if ((activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId)
|
|
2787
|
-
|
|
2788
|
-
node.token = serializeRangeWithSpreadsheet((_activeWorkbook$getUn2 = activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== null && _activeWorkbook$getUn2 !== void 0 ? _activeWorkbook$getUn2 : "", sheetName, last);
|
|
2789
|
-
} else node.token = sheetName === (activeSheet === null || activeSheet === void 0 ? void 0 : activeSheet.getName()) ? serializeRange(last) : serializeRangeWithSheet(activeSheet.getName(), last);
|
|
2770
|
+
if ((activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId) node.token = serializeRangeWithSpreadsheet((activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) ?? "", sheetName, last);
|
|
2771
|
+
else node.token = sheetName === (activeSheet === null || activeSheet === void 0 ? void 0 : activeSheet.getName()) ? serializeRange(last) : serializeRangeWithSheet(activeSheet.getName(), last);
|
|
2790
2772
|
const newOffset = offset + (node.token.length - oldToken.length);
|
|
2791
2773
|
handleRangeChange(generateStringWithSequence(sequenceNodes), newOffset, isEnd);
|
|
2792
2774
|
}
|
|
2793
2775
|
} else {
|
|
2794
2776
|
const { orderedSelections, insertedSelection } = getSelectionsForFormulaRefUpdate(selections, updatingRefIndex, isCtrlAddMode);
|
|
2795
2777
|
const getRefRangeText = (range) => {
|
|
2796
|
-
|
|
2797
|
-
const rangeSheetId = (_range$sheetId3 = range.sheetId) !== null && _range$sheetId3 !== void 0 ? _range$sheetId3 : subUnitId;
|
|
2778
|
+
const rangeSheetId = range.sheetId ?? subUnitId;
|
|
2798
2779
|
const unitRangeName = {
|
|
2799
2780
|
range,
|
|
2800
|
-
unitId:
|
|
2801
|
-
sheetName: getSheetNameById(
|
|
2781
|
+
unitId: range.unitId ?? activeWorkbook.getUnitId(),
|
|
2782
|
+
sheetName: getSheetNameById(range.unitId ?? activeWorkbook.getUnitId(), rangeSheetId)
|
|
2802
2783
|
};
|
|
2803
2784
|
const isAcrossWorkbook = (activeWorkbook === null || activeWorkbook === void 0 ? void 0 : activeWorkbook.getUnitId()) !== unitId;
|
|
2804
2785
|
return unitRangesToText([unitRangeName], isSupportAcrossSheet && (rangeSheetId !== subUnitId || isAcrossWorkbook), sheetName, isAcrossWorkbook)[0];
|
|
@@ -2926,7 +2907,6 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
|
|
|
2926
2907
|
if (params.selections.length) {
|
|
2927
2908
|
const last = params.selections[params.selections.length - 1];
|
|
2928
2909
|
if (last) {
|
|
2929
|
-
var _refSelectionsRenderS;
|
|
2930
2910
|
const { range, primary } = last;
|
|
2931
2911
|
if (((primary === null || primary === void 0 ? void 0 : primary.isMergedMainCell) || (primary === null || primary === void 0 ? void 0 : primary.isMerged)) && Rectangle.contains(primary, range)) {
|
|
2932
2912
|
range.startRow = primary.startRow;
|
|
@@ -2941,7 +2921,7 @@ const useSheetSelectionChange = (isNeed, isFocus, isSelectingRef, unitId, subUni
|
|
|
2941
2921
|
lexerTreeBuilder
|
|
2942
2922
|
});
|
|
2943
2923
|
const isAdd = isSelectingRef.current === 1 || Boolean(ctx && (isFormulaReferenceAddingContext(ctx.sequenceNodes, ctx.offset) || isFormulaReferenceAddingTextContext(ctx.formulaText, ctx.offset)));
|
|
2944
|
-
const selections = ((
|
|
2924
|
+
const selections = ((refSelectionsRenderService === null || refSelectionsRenderService === void 0 ? void 0 : refSelectionsRenderService.getSelectionDataWithStyle()) ?? []).map((i) => i.rangeWithCoord);
|
|
2945
2925
|
if (isAdd) {
|
|
2946
2926
|
if (selections.length > 0 && isSameFormulaSelection(selections[selections.length - 1], range)) return;
|
|
2947
2927
|
selections.push(range);
|
|
@@ -3341,7 +3321,7 @@ function syncCounterpartFormulaEditorSelection(editorService, editorId, selectio
|
|
|
3341
3321
|
(_editorService$getEdi = editorService.getEditor(syncEditorId)) === null || _editorService$getEdi === void 0 || _editorService$getEdi.setSelectionRanges(selections, false);
|
|
3342
3322
|
}
|
|
3343
3323
|
const FormulaEditor = forwardRef((props, ref) => {
|
|
3344
|
-
var _document$
|
|
3324
|
+
var _document$getBody2, _configService$getCon;
|
|
3345
3325
|
const { errorText, initValue, unitId, subUnitId, isFocus: _isFocus = true, isSupportAcrossSheet = false, onFocus = noop, onBlur = noop, onChange: propOnChange, onVerify, className, editorId: propEditorId, moveCursor = true, onFormulaSelectingChange: propOnFormulaSelectingChange, keyboardEventConfig, onMoveInEditor, resetSelectionOnBlur = true, autoScrollbar = true, isSingle = true, disableSelectionOnClick = false, autofocus = true, disableContextMenu, style, borderless = false, canvasStyle } = props;
|
|
3346
3326
|
const editorService = useDependency(IEditorService);
|
|
3347
3327
|
const commandService = useDependency(ICommandService);
|
|
@@ -3358,15 +3338,15 @@ const FormulaEditor = forwardRef((props, ref) => {
|
|
|
3358
3338
|
const [editor, setEditor] = useState();
|
|
3359
3339
|
const [isFocus, setIsFocus] = useState(_isFocus);
|
|
3360
3340
|
const formulaEditorContainerRef = useRef(null);
|
|
3361
|
-
const editorId = useMemo(() => propEditorId
|
|
3341
|
+
const editorId = useMemo(() => propEditorId ?? createInternalEditorID(`${EMBEDDING_FORMULA_EDITOR}-${generateRandomId(4)}`), []);
|
|
3362
3342
|
const isError = errorText !== void 0;
|
|
3363
3343
|
const univerInstanceService = useDependency(IUniverInstanceService);
|
|
3364
3344
|
const document = univerInstanceService.getUnit(editorId);
|
|
3365
3345
|
const getFormulaToken = useFormulaToken();
|
|
3366
3346
|
const formulaText = useObservable(document ? () => document.change$.pipe(map(() => {
|
|
3367
|
-
var _document$getBody
|
|
3368
|
-
return BuildTextUtils.transform.getPlainText((
|
|
3369
|
-
})) : null, BuildTextUtils.transform.getPlainText((
|
|
3347
|
+
var _document$getBody;
|
|
3348
|
+
return BuildTextUtils.transform.getPlainText(((_document$getBody = document.getBody()) === null || _document$getBody === void 0 ? void 0 : _document$getBody.dataStream) ?? "");
|
|
3349
|
+
})) : null, BuildTextUtils.transform.getPlainText((document === null || document === void 0 || (_document$getBody2 = document.getBody()) === null || _document$getBody2 === void 0 ? void 0 : _document$getBody2.dataStream) ?? ""), false, [document]);
|
|
3370
3350
|
const formulaTextRef = useStateRef(formulaText);
|
|
3371
3351
|
const formulaWithoutEqualSymbol = useMemo(() => getFormulaText(formulaText), [formulaText]);
|
|
3372
3352
|
const sequenceNodes = useMemo(() => getFormulaToken(formulaWithoutEqualSymbol), [formulaWithoutEqualSymbol, getFormulaToken]);
|
|
@@ -3388,7 +3368,7 @@ const FormulaEditor = forwardRef((props, ref) => {
|
|
|
3388
3368
|
const getRefSelections = useEvent(() => refSelectionsRef.current);
|
|
3389
3369
|
const getRefSelectionCount = useEvent(() => getRefSelections().length);
|
|
3390
3370
|
const selectingMode = isSelecting;
|
|
3391
|
-
const functionScreenTips = (_configService$getCon =
|
|
3371
|
+
const functionScreenTips = ((_configService$getCon = useDependency(IConfigService).getConfig("sheets-formula-ui.base.config")) === null || _configService$getCon === void 0 ? void 0 : _configService$getCon.functionScreenTips) ?? true;
|
|
3392
3372
|
useUpdateEffect(() => {
|
|
3393
3373
|
onChange(formulaText);
|
|
3394
3374
|
}, [formulaText, onChange]);
|
|
@@ -3397,9 +3377,9 @@ const FormulaEditor = forwardRef((props, ref) => {
|
|
|
3397
3377
|
const subscription = editor.input$.subscribe(({ content, isComposing }) => {
|
|
3398
3378
|
if (isComposing) return;
|
|
3399
3379
|
queueMicrotask(() => {
|
|
3400
|
-
var _editor$getSelectionR, _editor$getDocumentDa
|
|
3380
|
+
var _editor$getSelectionR, _editor$getDocumentDa;
|
|
3401
3381
|
const selection = (_editor$getSelectionR = editor.getSelectionRanges()) === null || _editor$getSelectionR === void 0 ? void 0 : _editor$getSelectionR[0];
|
|
3402
|
-
const normalizedSelection = getSelectionAfterLaggingFormulaInput((_editor$getDocumentDa =
|
|
3382
|
+
const normalizedSelection = getSelectionAfterLaggingFormulaInput(((_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream) ?? "", selection, content);
|
|
3403
3383
|
if (!normalizedSelection) return;
|
|
3404
3384
|
const selections = [normalizedSelection];
|
|
3405
3385
|
editor.setSelectionRanges(selections, false);
|
|
@@ -3423,7 +3403,7 @@ const FormulaEditor = forwardRef((props, ref) => {
|
|
|
3423
3403
|
const ranges = highlightDoc(editorRef.current, sequenceNodes, isNeedResetSelection, newSelections, formulaStr);
|
|
3424
3404
|
refSelectionsRef.current = ranges;
|
|
3425
3405
|
if (isEnd) {
|
|
3426
|
-
const currentDocSelections = newSelections
|
|
3406
|
+
const currentDocSelections = newSelections ?? (editor === null || editor === void 0 ? void 0 : editor.getSelectionRanges());
|
|
3427
3407
|
if ((currentDocSelections === null || currentDocSelections === void 0 ? void 0 : currentDocSelections.length) === 1) {
|
|
3428
3408
|
const refIndex = findRefSequenceIndex(sequenceNodes, findIndexFromSequenceNodes(sequenceNodes, currentDocSelections[0].startOffset - 1, false));
|
|
3429
3409
|
if (refIndex >= 0) {
|
|
@@ -3447,8 +3427,7 @@ const FormulaEditor = forwardRef((props, ref) => {
|
|
|
3447
3427
|
const focus = useFocus(editor);
|
|
3448
3428
|
const resetSelection = useResetSelection(isFocus, unitId, subUnitId);
|
|
3449
3429
|
useEffect(() => {
|
|
3450
|
-
|
|
3451
|
-
onFormulaSelectingChange(isSelecting, (_docSelectionRenderSe = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) !== null && _docSelectionRenderSe !== void 0 ? _docSelectionRenderSe : true);
|
|
3430
|
+
onFormulaSelectingChange(isSelecting, (docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) ?? true);
|
|
3452
3431
|
}, [onFormulaSelectingChange, isSelecting]);
|
|
3453
3432
|
useKeyboardEvent(isFocus, useMemo(() => createEditorUndoRedoKeyboardConfig({
|
|
3454
3433
|
commandService,
|
|
@@ -3507,11 +3486,10 @@ const FormulaEditor = forwardRef((props, ref) => {
|
|
|
3507
3486
|
};
|
|
3508
3487
|
}, []);
|
|
3509
3488
|
useEffect(() => {
|
|
3510
|
-
var _ref, _resolveFormulaEmbedR;
|
|
3511
3489
|
const formulaEditorContainer = formulaEditorContainerRef.current;
|
|
3512
3490
|
if (!isFocus || !formulaEditorContainer || !injector.has(IFormulaEmbedRuntimeFocusCoordinator)) return;
|
|
3513
3491
|
const focusCoordinator = injector.get(IFormulaEmbedRuntimeFocusCoordinator);
|
|
3514
|
-
const scope =
|
|
3492
|
+
const scope = resolveFormulaEmbedRuntimeDomScope(formulaEditorContainer) ?? focusCoordinator.resolveRuntimeScopeByChildUnitId(editorId) ?? resolveActiveFormulaEmbedRuntimeDomScope(formulaEditorContainer.ownerDocument);
|
|
3515
3493
|
if (!scope) return;
|
|
3516
3494
|
const collection = new DisposableCollection();
|
|
3517
3495
|
const interactionBoundaryService = injector.has(IFormulaEmbedInteractionBoundaryService) ? injector.get(IFormulaEmbedInteractionBoundaryService) : void 0;
|
|
@@ -4016,7 +3994,7 @@ function useRangesHighlight(editor, focusing, unitId, subUnitId) {
|
|
|
4016
3994
|
if (last.current === text) return;
|
|
4017
3995
|
last.current = text;
|
|
4018
3996
|
const nodes = lexerTreeBuilder.sequenceNodesBuilder(text);
|
|
4019
|
-
setSequenceNodes(nodes
|
|
3997
|
+
setSequenceNodes(nodes ?? []);
|
|
4020
3998
|
}, [
|
|
4021
3999
|
change,
|
|
4022
4000
|
editor,
|
|
@@ -4025,13 +4003,13 @@ function useRangesHighlight(editor, focusing, unitId, subUnitId) {
|
|
|
4025
4003
|
useEffect(() => {
|
|
4026
4004
|
if (!editor) return;
|
|
4027
4005
|
if (!focusing) {
|
|
4028
|
-
var _current$body
|
|
4006
|
+
var _current$body;
|
|
4029
4007
|
const current = editor.getDocumentData();
|
|
4030
4008
|
editor.setDocumentData({
|
|
4031
4009
|
...current,
|
|
4032
4010
|
body: {
|
|
4033
4011
|
...current.body,
|
|
4034
|
-
dataStream: (
|
|
4012
|
+
dataStream: ((_current$body = current.body) === null || _current$body === void 0 ? void 0 : _current$body.dataStream) ?? "",
|
|
4035
4013
|
textRuns: []
|
|
4036
4014
|
}
|
|
4037
4015
|
});
|
|
@@ -4265,7 +4243,7 @@ function stringifyRanges(ranges) {
|
|
|
4265
4243
|
function RangeSelector(props) {
|
|
4266
4244
|
const [editor, setEditor] = useState(null);
|
|
4267
4245
|
const { onVerify, selectorRef, unitId, subUnitId, maxRangeCount, supportAcrossSheet, keepSheetReference, autoFocus, onChange, onRangeSelectorDialogVisibleChange, onClickOutside, onFocusChange, forceShowDialogWhenSelectionChanged, hideEditor, resetRange } = props;
|
|
4268
|
-
const [focusing, setFocusing] = useState(autoFocus
|
|
4246
|
+
const [focusing, setFocusing] = useState(autoFocus ?? false);
|
|
4269
4247
|
const [popupVisible, setPopupVisible] = useState(false);
|
|
4270
4248
|
const [rangeSelectorRanges, setRangeSelectorRanges] = useState([]);
|
|
4271
4249
|
const localeService = useDependency(LocaleService);
|
|
@@ -4279,9 +4257,9 @@ function RangeSelector(props) {
|
|
|
4279
4257
|
editorService.blur();
|
|
4280
4258
|
});
|
|
4281
4259
|
const handleOpenModal = useEvent(() => {
|
|
4282
|
-
var _editor$getDocumentDa
|
|
4260
|
+
var _editor$getDocumentDa;
|
|
4283
4261
|
blurEditor();
|
|
4284
|
-
setRangeSelectorRanges(parseRanges((
|
|
4262
|
+
setRangeSelectorRanges(parseRanges((editor === null || editor === void 0 || (_editor$getDocumentDa = editor.getDocumentDataModel()) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.getPlainText()) ?? ""));
|
|
4285
4263
|
setPopupVisible(true);
|
|
4286
4264
|
});
|
|
4287
4265
|
useEffect(() => {
|
|
@@ -4305,8 +4283,8 @@ function RangeSelector(props) {
|
|
|
4305
4283
|
setPopupVisible(false);
|
|
4306
4284
|
},
|
|
4307
4285
|
getValue: () => {
|
|
4308
|
-
var _editor$
|
|
4309
|
-
return (
|
|
4286
|
+
var _editor$getDocumentDa2;
|
|
4287
|
+
return (editor === null || editor === void 0 || (_editor$getDocumentDa2 = editor.getDocumentDataModel()) === null || _editor$getDocumentDa2 === void 0 ? void 0 : _editor$getDocumentDa2.getPlainText()) ?? "";
|
|
4310
4288
|
}
|
|
4311
4289
|
};
|
|
4312
4290
|
}, [
|
|
@@ -4317,8 +4295,8 @@ function RangeSelector(props) {
|
|
|
4317
4295
|
sequenceNodesRef
|
|
4318
4296
|
]);
|
|
4319
4297
|
useEffect(() => {
|
|
4320
|
-
var _editor$
|
|
4321
|
-
onVerify === null || onVerify === void 0 || onVerify(verifyRange(sequenceNodes), (
|
|
4298
|
+
var _editor$getDocumentDa3;
|
|
4299
|
+
onVerify === null || onVerify === void 0 || onVerify(verifyRange(sequenceNodes), (editor === null || editor === void 0 || (_editor$getDocumentDa3 = editor.getDocumentDataModel()) === null || _editor$getDocumentDa3 === void 0 ? void 0 : _editor$getDocumentDa3.getPlainText()) ?? "");
|
|
4322
4300
|
}, [sequenceNodes]);
|
|
4323
4301
|
useEffect(() => {
|
|
4324
4302
|
onRangeSelectorDialogVisibleChange === null || onRangeSelectorDialogVisibleChange === void 0 || onRangeSelectorDialogVisibleChange(popupVisible);
|
|
@@ -4336,6 +4314,7 @@ function RangeSelector(props) {
|
|
|
4336
4314
|
return /* @__PURE__ */ jsxs(Fragment, { children: [!hideEditor ? /* @__PURE__ */ jsx(RichTextEditor, {
|
|
4337
4315
|
isSingle: true,
|
|
4338
4316
|
...props,
|
|
4317
|
+
preserveHostFocus: true,
|
|
4339
4318
|
onFocusChange: (focusing, newValue) => {
|
|
4340
4319
|
setFocusing(focusing);
|
|
4341
4320
|
onFocusChange === null || onFocusChange === void 0 || onFocusChange(focusing, newValue);
|
|
@@ -5275,13 +5254,12 @@ var GlobalRangeSelectorService = class {
|
|
|
5275
5254
|
//#endregion
|
|
5276
5255
|
//#region src/views/range-selector/Global.tsx
|
|
5277
5256
|
const GlobalRangeSelector = () => {
|
|
5278
|
-
var _current$unitId, _current$subUnitId;
|
|
5279
5257
|
const current = useObservable(useDependency(GlobalRangeSelectorService).currentSelector$);
|
|
5280
5258
|
const instance = useRef(null);
|
|
5281
5259
|
useEffect(() => {
|
|
5282
5260
|
if (current) {
|
|
5283
|
-
var _instance$current
|
|
5284
|
-
(_instance$current = instance.current) === null || _instance$current === void 0 || _instance$current.showDialog(
|
|
5261
|
+
var _instance$current;
|
|
5262
|
+
(_instance$current = instance.current) === null || _instance$current === void 0 || _instance$current.showDialog(current.initialValue ?? []);
|
|
5285
5263
|
return () => {
|
|
5286
5264
|
var _instance$current2;
|
|
5287
5265
|
(_instance$current2 = instance.current) === null || _instance$current2 === void 0 || _instance$current2.hideDialog();
|
|
@@ -5289,13 +5267,12 @@ const GlobalRangeSelector = () => {
|
|
|
5289
5267
|
}
|
|
5290
5268
|
}, [current]);
|
|
5291
5269
|
return /* @__PURE__ */ jsx(RangeSelector, {
|
|
5292
|
-
unitId: (
|
|
5293
|
-
subUnitId: (
|
|
5270
|
+
unitId: (current === null || current === void 0 ? void 0 : current.unitId) ?? "",
|
|
5271
|
+
subUnitId: (current === null || current === void 0 ? void 0 : current.subUnitId) ?? "",
|
|
5294
5272
|
hideEditor: true,
|
|
5295
5273
|
selectorRef: instance,
|
|
5296
5274
|
onChange: (_, value) => {
|
|
5297
|
-
|
|
5298
|
-
current === null || current === void 0 || current.callback((_value$split$map = value === null || value === void 0 ? void 0 : value.split(",").map((i) => deserializeRangeWithSheet(i))) !== null && _value$split$map !== void 0 ? _value$split$map : []);
|
|
5275
|
+
current === null || current === void 0 || current.callback((value === null || value === void 0 ? void 0 : value.split(",").map((i) => deserializeRangeWithSheet(i))) ?? []);
|
|
5299
5276
|
}
|
|
5300
5277
|
});
|
|
5301
5278
|
};
|
|
@@ -5357,7 +5334,7 @@ _defineProperty(UniverSheetsFormulaUIPlugin, "packageName", name);
|
|
|
5357
5334
|
_defineProperty(UniverSheetsFormulaUIPlugin, "version", version);
|
|
5358
5335
|
_defineProperty(UniverSheetsFormulaUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
|
|
5359
5336
|
UniverSheetsFormulaUIPlugin = __decorate([
|
|
5360
|
-
DependentOn(UniverFormulaEnginePlugin, UniverRenderEnginePlugin, UniverSheetsPlugin,
|
|
5337
|
+
DependentOn(UniverFormulaEnginePlugin, UniverRenderEnginePlugin, UniverSheetsPlugin, UniverSheetsFormulaPlugin, UniverSheetsUIPlugin),
|
|
5361
5338
|
__decorateParam(1, Inject(Injector)),
|
|
5362
5339
|
__decorateParam(2, IRenderManagerService),
|
|
5363
5340
|
__decorateParam(3, IConfigService),
|