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