@univerjs/sheets-ui 0.21.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +11 -8
- package/lib/cjs/index.js +281 -175
- package/lib/es/facade.js +11 -8
- package/lib/es/index.js +284 -178
- package/lib/facade.js +11 -8
- package/lib/index.css +8 -0
- package/lib/index.js +284 -178
- package/lib/types/services/scroll-manager.service.d.ts +1 -0
- package/lib/types/services/sheet-skeleton-manager.service.d.ts +1 -0
- package/lib/types/services/utils/defined-name-utils.d.ts +52 -0
- package/lib/umd/index.js +11 -11
- package/package.json +13 -13
package/lib/cjs/index.js
CHANGED
|
@@ -1013,6 +1013,11 @@ let SheetSkeletonManagerService = class SheetSkeletonManagerService extends _uni
|
|
|
1013
1013
|
_defineProperty(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
|
|
1014
1014
|
const { unitId, scene } = this._context;
|
|
1015
1015
|
this._sheetSkeletonService.setScene(unitId, scene);
|
|
1016
|
+
this._initSkeletonsRegisterGetCellHeight(unitId);
|
|
1017
|
+
}
|
|
1018
|
+
_initSkeletonsRegisterGetCellHeight(unitId) {
|
|
1019
|
+
this._sheetSkeletonService.getSkeletonsByUnitId(unitId).forEach((skeleton) => skeleton.registerGetCellHeight());
|
|
1020
|
+
this.disposeWithMe(this._sheetSkeletonService.buildSkeleton$.subscribe((skeleton) => skeleton.registerGetCellHeight()));
|
|
1016
1021
|
}
|
|
1017
1022
|
dispose() {
|
|
1018
1023
|
super.dispose();
|
|
@@ -6318,6 +6323,7 @@ let SheetScrollManagerService = class SheetScrollManagerService {
|
|
|
6318
6323
|
this._rawScrollInfo$.complete();
|
|
6319
6324
|
}
|
|
6320
6325
|
calcViewportScrollFromRowColOffset(scrollInfo) {
|
|
6326
|
+
var _skeleton$getCellWith, _skeleton$getCellWith2;
|
|
6321
6327
|
if (!scrollInfo) return {
|
|
6322
6328
|
viewportScrollX: 0,
|
|
6323
6329
|
viewportScrollY: 0
|
|
@@ -6326,10 +6332,10 @@ let SheetScrollManagerService = class SheetScrollManagerService {
|
|
|
6326
6332
|
sheetViewStartRow = sheetViewStartRow || 0;
|
|
6327
6333
|
offsetY = offsetY || 0;
|
|
6328
6334
|
const skeleton = this._sheetSkeletonManagerService.getCurrentSkeleton();
|
|
6329
|
-
const
|
|
6335
|
+
const { startX: colStart = (skeleton === null || skeleton === void 0 ? void 0 : skeleton.columnWidthAccumulation[sheetViewStartColumn - 1]) || 0, startY: rowStart = (skeleton === null || skeleton === void 0 ? void 0 : skeleton.rowHeightAccumulation[sheetViewStartRow - 1]) || 0 } = (_skeleton$getCellWith = skeleton === null || skeleton === void 0 || (_skeleton$getCellWith2 = skeleton.getCellWithCoordByIndex) === null || _skeleton$getCellWith2 === void 0 ? void 0 : _skeleton$getCellWith2.call(skeleton, sheetViewStartRow, sheetViewStartColumn, false)) !== null && _skeleton$getCellWith !== void 0 ? _skeleton$getCellWith : {};
|
|
6330
6336
|
return {
|
|
6331
|
-
viewportScrollX:
|
|
6332
|
-
viewportScrollY:
|
|
6337
|
+
viewportScrollX: colStart + offsetX,
|
|
6338
|
+
viewportScrollY: rowStart + offsetY
|
|
6333
6339
|
};
|
|
6334
6340
|
}
|
|
6335
6341
|
setSearchParam(param) {
|
|
@@ -6387,19 +6393,12 @@ let SheetScrollManagerService = class SheetScrollManagerService {
|
|
|
6387
6393
|
worksheetScrollInfoMap.set(sheetId, newScrollInfo);
|
|
6388
6394
|
}
|
|
6389
6395
|
_clearByParamAndNotify(param) {
|
|
6396
|
+
const defaultScrollState = this._getDefaultScrollState(param);
|
|
6390
6397
|
this._setScrollState({
|
|
6391
6398
|
...param,
|
|
6392
|
-
|
|
6393
|
-
sheetViewStartColumn: 0,
|
|
6394
|
-
offsetX: 0,
|
|
6395
|
-
offsetY: 0
|
|
6396
|
-
});
|
|
6397
|
-
this._emitRawScroll({
|
|
6398
|
-
sheetViewStartRow: 0,
|
|
6399
|
-
sheetViewStartColumn: 0,
|
|
6400
|
-
offsetX: 0,
|
|
6401
|
-
offsetY: 0
|
|
6399
|
+
...defaultScrollState
|
|
6402
6400
|
});
|
|
6401
|
+
this._emitRawScroll(defaultScrollState);
|
|
6403
6402
|
}
|
|
6404
6403
|
_getCurrentScroll(param) {
|
|
6405
6404
|
var _this$_scrollStateMap;
|
|
@@ -6411,7 +6410,19 @@ let SheetScrollManagerService = class SheetScrollManagerService {
|
|
|
6411
6410
|
};
|
|
6412
6411
|
if (param == null) return emptyState;
|
|
6413
6412
|
const { unitId, sheetId } = param;
|
|
6414
|
-
return ((_this$_scrollStateMap = this._scrollStateMap.get(unitId)) === null || _this$_scrollStateMap === void 0 ? void 0 : _this$_scrollStateMap.get(sheetId)) ||
|
|
6413
|
+
return ((_this$_scrollStateMap = this._scrollStateMap.get(unitId)) === null || _this$_scrollStateMap === void 0 ? void 0 : _this$_scrollStateMap.get(sheetId)) || this._getDefaultScrollState(param);
|
|
6414
|
+
}
|
|
6415
|
+
_getDefaultScrollState(param) {
|
|
6416
|
+
var _this$_sheetSkeletonM, _this$_sheetSkeletonM2, _this$_sheetSkeletonM3, _this$_sheetSkeletonM4, _this$_sheetSkeletonM5, _skeleton$getColGapSi, _skeleton$getRowGapSi;
|
|
6417
|
+
const skeleton = (_this$_sheetSkeletonM = (_this$_sheetSkeletonM2 = (_this$_sheetSkeletonM3 = this._sheetSkeletonManagerService).getSkeleton) === null || _this$_sheetSkeletonM2 === void 0 ? void 0 : _this$_sheetSkeletonM2.call(_this$_sheetSkeletonM3, param.sheetId)) !== null && _this$_sheetSkeletonM !== void 0 ? _this$_sheetSkeletonM : (_this$_sheetSkeletonM4 = (_this$_sheetSkeletonM5 = this._sheetSkeletonManagerService).getCurrentSkeleton) === null || _this$_sheetSkeletonM4 === void 0 ? void 0 : _this$_sheetSkeletonM4.call(_this$_sheetSkeletonM5);
|
|
6418
|
+
const colGapSize = (_skeleton$getColGapSi = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getColGapSize(0)) !== null && _skeleton$getColGapSi !== void 0 ? _skeleton$getColGapSi : 0;
|
|
6419
|
+
const rowGapSize = (_skeleton$getRowGapSi = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getRowGapSize(0)) !== null && _skeleton$getRowGapSi !== void 0 ? _skeleton$getRowGapSi : 0;
|
|
6420
|
+
return {
|
|
6421
|
+
sheetViewStartRow: 0,
|
|
6422
|
+
sheetViewStartColumn: 0,
|
|
6423
|
+
offsetX: colGapSize === 0 ? 0 : -colGapSize,
|
|
6424
|
+
offsetY: rowGapSize === 0 ? 0 : -rowGapSize
|
|
6425
|
+
};
|
|
6415
6426
|
}
|
|
6416
6427
|
_emitRawScroll(param) {
|
|
6417
6428
|
this._rawScrollInfo$.next(param);
|
|
@@ -8287,7 +8298,11 @@ const SidebarDefinedNameOperation = {
|
|
|
8287
8298
|
header: { title: localeService.t("definedName.featureTitle") },
|
|
8288
8299
|
children: { label: DEFINED_NAME_CONTAINER },
|
|
8289
8300
|
onClose: () => {},
|
|
8290
|
-
width: 333
|
|
8301
|
+
width: 333,
|
|
8302
|
+
bodyStyle: {
|
|
8303
|
+
height: "100%",
|
|
8304
|
+
overflow: "hidden"
|
|
8305
|
+
}
|
|
8291
8306
|
});
|
|
8292
8307
|
break;
|
|
8293
8308
|
default:
|
|
@@ -8552,11 +8567,11 @@ let SheetsRenderService = class SheetsRenderService extends _univerjs_core.RxDis
|
|
|
8552
8567
|
this._initContextListener();
|
|
8553
8568
|
}
|
|
8554
8569
|
_initWorkbookListener() {
|
|
8555
|
-
this._instanceSrv.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((
|
|
8570
|
+
this._instanceSrv.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((event) => this._createRenderer(event.unit, event.options));
|
|
8556
8571
|
this._instanceSrv.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).forEach((workbook) => this._createRenderer(workbook));
|
|
8557
8572
|
this._instanceSrv.getTypeOfUnitDisposed$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((workbook) => this._disposeRenderer(workbook));
|
|
8558
8573
|
}
|
|
8559
|
-
_createRenderer(workbook) {
|
|
8574
|
+
_createRenderer(workbook, createUnitOptions) {
|
|
8560
8575
|
const unitId = workbook.getUnitId();
|
|
8561
8576
|
this._renderManagerService.created$.subscribe((renderer) => {
|
|
8562
8577
|
if (renderer.unitId === unitId) {
|
|
@@ -8564,7 +8579,7 @@ let SheetsRenderService = class SheetsRenderService extends _univerjs_core.RxDis
|
|
|
8564
8579
|
renderer.engine.getCanvas().getContext().setId(`${SHEET_MAIN_CANVAS_ID}_${unitId}`);
|
|
8565
8580
|
}
|
|
8566
8581
|
});
|
|
8567
|
-
this._renderManagerService.createRender(unitId);
|
|
8582
|
+
this._renderManagerService.createRender(unitId, createUnitOptions);
|
|
8568
8583
|
}
|
|
8569
8584
|
_disposeRenderer(workbook) {
|
|
8570
8585
|
const unitId = workbook.getUnitId();
|
|
@@ -12048,8 +12063,8 @@ let FormulaEditorController = class FormulaEditorController extends _univerjs_co
|
|
|
12048
12063
|
});
|
|
12049
12064
|
}
|
|
12050
12065
|
_syncEditorSize() {
|
|
12051
|
-
const
|
|
12052
|
-
this.disposeWithMe((0, rxjs.combineLatest)([this._formulaEditorManagerService.position$,
|
|
12066
|
+
const addFormulaBar$ = this._univerInstanceService.unitAdded$.pipe((0, rxjs.filter)((event) => event.unit.getUnitId() === _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY));
|
|
12067
|
+
this.disposeWithMe((0, rxjs.combineLatest)([this._formulaEditorManagerService.position$, addFormulaBar$]).subscribe(([position]) => {
|
|
12053
12068
|
if (!position) return this._clearScheduledCallback();
|
|
12054
12069
|
const editorObject = getEditorObject(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, this._renderManagerService);
|
|
12055
12070
|
const formulaEditorDataModel = this._univerInstanceService.getUniverDocInstance(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
|
|
@@ -19875,7 +19890,8 @@ const CellPopup = (props) => {
|
|
|
19875
19890
|
//#region src/views/defined-name/DefinedNameInput.tsx
|
|
19876
19891
|
const DefinedNameInput = (props) => {
|
|
19877
19892
|
const { inputId, state = false, type = "range", confirm, cancel, name, formulaOrRefString, comment = "", localSheetId = _univerjs_sheets.SCOPE_WORKBOOK_VALUE_DEFINED_NAME, hidden = false, id } = props;
|
|
19878
|
-
const
|
|
19893
|
+
const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
|
|
19894
|
+
const workbook = univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
19879
19895
|
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
19880
19896
|
const definedNamesService = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.IDefinedNamesService);
|
|
19881
19897
|
const superTableService = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.ISuperTableService);
|
|
@@ -19929,37 +19945,23 @@ const DefinedNameInput = (props) => {
|
|
|
19929
19945
|
setFormulaOrRefStringValue(value || "");
|
|
19930
19946
|
};
|
|
19931
19947
|
const confirmChange = () => {
|
|
19932
|
-
|
|
19933
|
-
|
|
19934
|
-
|
|
19935
|
-
|
|
19936
|
-
|
|
19937
|
-
|
|
19938
|
-
|
|
19939
|
-
|
|
19940
|
-
|
|
19941
|
-
|
|
19942
|
-
|
|
19943
|
-
}
|
|
19944
|
-
if (workbook.getSheetOrders().map((sheetId) => {
|
|
19945
|
-
var _workbook$getSheetByS;
|
|
19946
|
-
return ((_workbook$getSheetByS = workbook.getSheetBySheetId(sheetId)) === null || _workbook$getSheetByS === void 0 ? void 0 : _workbook$getSheetByS.getName()) || "";
|
|
19947
|
-
}).includes(nameValue)) {
|
|
19948
|
-
setValidString(localeService.t("definedName.nameSheetConflict"));
|
|
19949
|
-
return;
|
|
19950
|
-
}
|
|
19951
|
-
if (formulaOrRefStringValue.length === 0) {
|
|
19952
|
-
setValidString(localeService.t("definedName.formulaOrRefStringEmpty"));
|
|
19948
|
+
const validationResult = (0, _univerjs_sheets.validateDefinedName)(nameValue, {
|
|
19949
|
+
unitId,
|
|
19950
|
+
formulaOrRefString: formulaOrRefStringValue,
|
|
19951
|
+
univerInstanceService,
|
|
19952
|
+
definedNamesService,
|
|
19953
|
+
superTableService,
|
|
19954
|
+
functionService,
|
|
19955
|
+
id
|
|
19956
|
+
});
|
|
19957
|
+
if (typeof validationResult === "string") {
|
|
19958
|
+
setValidString(localeService.t(validationResult));
|
|
19953
19959
|
return;
|
|
19954
19960
|
}
|
|
19955
19961
|
if (!validFormulaOrRange) {
|
|
19956
19962
|
setValidString(localeService.t("definedName.formulaOrRefStringInvalid"));
|
|
19957
19963
|
return;
|
|
19958
19964
|
}
|
|
19959
|
-
if (functionService.hasExecutor(nameValue.toUpperCase())) {
|
|
19960
|
-
setValidString(localeService.t("definedName.nameConflict"));
|
|
19961
|
-
return;
|
|
19962
|
-
}
|
|
19963
19965
|
const currentSheetName = workbook.getActiveSheet().getName();
|
|
19964
19966
|
confirm && confirm({
|
|
19965
19967
|
id: id || "",
|
|
@@ -20089,6 +20091,15 @@ const DefinedNameContainer = () => {
|
|
|
20089
20091
|
const [definedNames, setDefinedNames] = (0, react.useState)([]);
|
|
20090
20092
|
const [editorKey, setEditorKey] = (0, react.useState)(null);
|
|
20091
20093
|
const [deleteConformKey, setDeleteConformKey] = (0, react.useState)();
|
|
20094
|
+
const listContainerRef = (0, react.useRef)(void 0);
|
|
20095
|
+
const [virtualDefinedNames, virtualActions] = (0, _univerjs_ui.useVirtualList)(definedNames, {
|
|
20096
|
+
containerTarget: listContainerRef,
|
|
20097
|
+
itemHeight: (index, item) => {
|
|
20098
|
+
if (item.id === editorKey) return 240;
|
|
20099
|
+
return 72;
|
|
20100
|
+
},
|
|
20101
|
+
overscan: 6
|
|
20102
|
+
});
|
|
20092
20103
|
(0, react.useEffect)(() => {
|
|
20093
20104
|
setDefinedNames(getDefinedNameMap());
|
|
20094
20105
|
const definedNamesSubscription = definedNamesService.update$.subscribe(() => {
|
|
@@ -20191,100 +20202,105 @@ const DefinedNameContainer = () => {
|
|
|
20191
20202
|
if (sheet == null) return "";
|
|
20192
20203
|
return sheet.getName();
|
|
20193
20204
|
};
|
|
20194
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.
|
|
20205
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
20195
20206
|
"data-u-comp": "defined-name-container",
|
|
20196
|
-
className: "univer-relative univer-box-border univer-w-full",
|
|
20197
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
20198
|
-
className:
|
|
20199
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(
|
|
20200
|
-
className: "univer-
|
|
20201
|
-
|
|
20202
|
-
|
|
20203
|
-
|
|
20204
|
-
children:
|
|
20205
|
-
className: "univer-ml-1",
|
|
20206
|
-
children: localeService.t("definedName.addButton")
|
|
20207
|
-
})]
|
|
20208
|
-
}), editState && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefinedNameInput, {
|
|
20209
|
-
confirm: insertConfirm,
|
|
20210
|
-
cancel: closeInput,
|
|
20211
|
-
state: editState,
|
|
20212
|
-
inputId: "insertDefinedName",
|
|
20213
|
-
name: getInsertDefinedName(),
|
|
20214
|
-
formulaOrRefString: getInertFormulaOrRefString()
|
|
20207
|
+
className: "univer-relative univer-box-border univer-flex univer-h-full univer-w-full univer-flex-col",
|
|
20208
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
20209
|
+
className: "univer-mb-4",
|
|
20210
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.Button, {
|
|
20211
|
+
className: (0, _univerjs_design.clsx)("univer-w-full", { "univer-hidden": editState }),
|
|
20212
|
+
onClick: openInsertCloseKeyEditor,
|
|
20213
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.IncreaseIcon, {}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
20214
|
+
className: "univer-ml-1",
|
|
20215
|
+
children: localeService.t("definedName.addButton")
|
|
20215
20216
|
})]
|
|
20216
|
-
},
|
|
20217
|
-
|
|
20218
|
-
|
|
20219
|
-
|
|
20220
|
-
|
|
20221
|
-
|
|
20222
|
-
|
|
20223
|
-
|
|
20224
|
-
|
|
20225
|
-
|
|
20226
|
-
|
|
20217
|
+
}), editState && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefinedNameInput, {
|
|
20218
|
+
confirm: insertConfirm,
|
|
20219
|
+
cancel: closeInput,
|
|
20220
|
+
state: editState,
|
|
20221
|
+
inputId: "insertDefinedName",
|
|
20222
|
+
name: getInsertDefinedName(),
|
|
20223
|
+
formulaOrRefString: getInertFormulaOrRefString()
|
|
20224
|
+
})]
|
|
20225
|
+
}, "insertDefinedName"), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
20226
|
+
ref: listContainerRef,
|
|
20227
|
+
className: (0, _univerjs_design.clsx)("univer-min-h-0 univer-flex-1 univer-overflow-y-auto", _univerjs_design.scrollbarClassName),
|
|
20228
|
+
...virtualActions.containerProps,
|
|
20229
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
20230
|
+
style: virtualActions.wrapperStyle,
|
|
20231
|
+
children: virtualDefinedNames.map(({ data: definedName, index }) => {
|
|
20232
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
20233
|
+
className: "univer-relative univer-w-full univer-divide-x-0 univer-divide-y univer-divide-solid univer-divide-gray-200 dark:!univer-divide-gray-600",
|
|
20234
|
+
children: [
|
|
20235
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
20236
|
+
className: (0, _univerjs_design.clsx)("univer-group univer-relative univer-flex univer-w-full univer-cursor-default univer-select-none univer-items-center univer-justify-between univer-rounded-md univer-p-2 hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-700", { "univer-hidden": definedName.id === editorKey }),
|
|
20237
|
+
onClick: () => {
|
|
20238
|
+
focusDefinedName(definedName);
|
|
20239
|
+
},
|
|
20227
20240
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
20228
|
-
|
|
20229
|
-
children: [
|
|
20230
|
-
className: "univer-text-
|
|
20231
|
-
children: definedName.
|
|
20241
|
+
title: definedName.comment,
|
|
20242
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
20243
|
+
className: "univer-my-1 univer-max-h-[100px] univer-max-w-[190px] univer-truncate univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",
|
|
20244
|
+
children: [definedName.name, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
20245
|
+
className: "univer-text-xxs univer-ml-1 univer-text-gray-400",
|
|
20246
|
+
children: definedName.localSheetId === _univerjs_sheets.SCOPE_WORKBOOK_VALUE_DEFINED_NAME || definedName.localSheetId == null ? "" : getSheetNameBySheetId(definedName.localSheetId)
|
|
20247
|
+
})]
|
|
20248
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
20249
|
+
className: "univer-my-1 univer-max-h-[100px] univer-w-full univer-max-w-[190px] univer-truncate univer-text-xs univer-text-gray-500",
|
|
20250
|
+
title: definedName.formulaOrRefString,
|
|
20251
|
+
children: definedName.formulaOrRefString
|
|
20252
|
+
})]
|
|
20253
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
20254
|
+
className: "univer-absolute univer-right-5 univer-top-1/2 univer-hidden -univer-translate-y-1/2 univer-cursor-pointer univer-items-center univer-justify-end univer-gap-7 univer-text-xs univer-text-primary-600 group-hover:univer-flex dark:hover:!univer-bg-gray-600",
|
|
20255
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
|
|
20256
|
+
title: localeService.t("definedName.updateButton"),
|
|
20257
|
+
placement: "top",
|
|
20258
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
20259
|
+
className: "univer-rounded univer-p-1 hover:univer-bg-gray-100",
|
|
20260
|
+
onClick: (e) => {
|
|
20261
|
+
e.stopPropagation();
|
|
20262
|
+
closeInsertOpenKeyEditor(definedName.id);
|
|
20263
|
+
},
|
|
20264
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.PenIcon, {})
|
|
20265
|
+
})
|
|
20266
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
|
|
20267
|
+
title: localeService.t("definedName.deleteButton"),
|
|
20268
|
+
placement: "top",
|
|
20269
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
20270
|
+
className: "univer-rounded univer-p-1 univer-text-red-600 hover:univer-bg-gray-100",
|
|
20271
|
+
onClick: (e) => {
|
|
20272
|
+
e.stopPropagation();
|
|
20273
|
+
deleteDefinedName(definedName.id);
|
|
20274
|
+
},
|
|
20275
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DeleteIcon, {})
|
|
20276
|
+
})
|
|
20232
20277
|
})]
|
|
20233
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
20234
|
-
className: "univer-my-1 univer-max-h-[100px] univer-w-full univer-max-w-[190px] univer-truncate univer-text-xs univer-text-gray-500",
|
|
20235
|
-
title: definedName.formulaOrRefString,
|
|
20236
|
-
children: definedName.formulaOrRefString
|
|
20237
|
-
})]
|
|
20238
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
20239
|
-
className: "univer-absolute univer-right-5 univer-top-1/2 univer-hidden -univer-translate-y-1/2 univer-cursor-pointer univer-items-center univer-justify-end univer-gap-7 univer-text-xs univer-text-primary-600 group-hover:univer-flex dark:hover:!univer-bg-gray-600",
|
|
20240
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
|
|
20241
|
-
title: localeService.t("definedName.updateButton"),
|
|
20242
|
-
placement: "top",
|
|
20243
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
20244
|
-
className: "univer-rounded univer-p-1 hover:univer-bg-gray-100",
|
|
20245
|
-
onClick: (e) => {
|
|
20246
|
-
e.stopPropagation();
|
|
20247
|
-
closeInsertOpenKeyEditor(definedName.id);
|
|
20248
|
-
},
|
|
20249
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.PenIcon, {})
|
|
20250
|
-
})
|
|
20251
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
|
|
20252
|
-
title: localeService.t("definedName.deleteButton"),
|
|
20253
|
-
placement: "top",
|
|
20254
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
20255
|
-
className: "univer-rounded univer-p-1 univer-text-red-600 hover:univer-bg-gray-100",
|
|
20256
|
-
onClick: (e) => {
|
|
20257
|
-
e.stopPropagation();
|
|
20258
|
-
deleteDefinedName(definedName.id);
|
|
20259
|
-
},
|
|
20260
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DeleteIcon, {})
|
|
20261
|
-
})
|
|
20262
20278
|
})]
|
|
20263
|
-
})
|
|
20264
|
-
|
|
20265
|
-
|
|
20266
|
-
|
|
20267
|
-
|
|
20268
|
-
|
|
20269
|
-
|
|
20270
|
-
|
|
20271
|
-
|
|
20272
|
-
|
|
20273
|
-
|
|
20274
|
-
|
|
20275
|
-
|
|
20276
|
-
|
|
20277
|
-
|
|
20278
|
-
|
|
20279
|
-
|
|
20280
|
-
|
|
20281
|
-
|
|
20282
|
-
|
|
20283
|
-
|
|
20284
|
-
|
|
20285
|
-
}
|
|
20286
|
-
})
|
|
20287
|
-
})
|
|
20279
|
+
}),
|
|
20280
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Confirm, {
|
|
20281
|
+
visible: deleteConformKey === definedName.id,
|
|
20282
|
+
onClose: handleDeleteClose,
|
|
20283
|
+
onConfirm: () => {
|
|
20284
|
+
handleDeleteConfirm(definedName.id);
|
|
20285
|
+
},
|
|
20286
|
+
children: localeService.t("definedName.deleteConfirmText")
|
|
20287
|
+
}),
|
|
20288
|
+
definedName.id === editorKey && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefinedNameInput, {
|
|
20289
|
+
confirm: insertConfirm,
|
|
20290
|
+
cancel: closeInput,
|
|
20291
|
+
state: definedName.id === editorKey,
|
|
20292
|
+
id: definedName.id,
|
|
20293
|
+
inputId: definedName.id + index,
|
|
20294
|
+
name: definedName.name,
|
|
20295
|
+
formulaOrRefString: definedName.formulaOrRefString,
|
|
20296
|
+
comment: definedName.comment,
|
|
20297
|
+
localSheetId: definedName.localSheetId
|
|
20298
|
+
})
|
|
20299
|
+
]
|
|
20300
|
+
}, index);
|
|
20301
|
+
})
|
|
20302
|
+
})
|
|
20303
|
+
})]
|
|
20288
20304
|
});
|
|
20289
20305
|
};
|
|
20290
20306
|
|
|
@@ -20608,6 +20624,49 @@ const EditorContainer = () => {
|
|
|
20608
20624
|
});
|
|
20609
20625
|
};
|
|
20610
20626
|
|
|
20627
|
+
//#endregion
|
|
20628
|
+
//#region src/services/utils/defined-name-utils.ts
|
|
20629
|
+
let DefinedNameBoxActionType = /* @__PURE__ */ function(DefinedNameBoxActionType) {
|
|
20630
|
+
DefinedNameBoxActionType["Noop"] = "noop";
|
|
20631
|
+
DefinedNameBoxActionType["FocusDefinedName"] = "focusDefinedName";
|
|
20632
|
+
DefinedNameBoxActionType["FocusSelection"] = "focusSelection";
|
|
20633
|
+
DefinedNameBoxActionType["CreateDefinedName"] = "createDefinedName";
|
|
20634
|
+
DefinedNameBoxActionType["Reset"] = "reset";
|
|
20635
|
+
return DefinedNameBoxActionType;
|
|
20636
|
+
}({});
|
|
20637
|
+
function resolveDefinedNameBoxAction(params) {
|
|
20638
|
+
const { inputValue, rangeString, unitId, formulaOrRefString, univerInstanceService, definedNamesService, superTableService, functionService } = params;
|
|
20639
|
+
if (inputValue === rangeString) return { type: DefinedNameBoxActionType.Noop };
|
|
20640
|
+
const definedName = definedNamesService.getValueByName(unitId, inputValue);
|
|
20641
|
+
if (definedName) return {
|
|
20642
|
+
type: DefinedNameBoxActionType.FocusDefinedName,
|
|
20643
|
+
definedName
|
|
20644
|
+
};
|
|
20645
|
+
if ((0, _univerjs_engine_formula.isReferenceStringWithEffectiveColumn)(inputValue)) return {
|
|
20646
|
+
type: DefinedNameBoxActionType.FocusSelection,
|
|
20647
|
+
refString: inputValue
|
|
20648
|
+
};
|
|
20649
|
+
if ((0, _univerjs_sheets.validateDefinedName)(inputValue, {
|
|
20650
|
+
unitId,
|
|
20651
|
+
formulaOrRefString,
|
|
20652
|
+
univerInstanceService,
|
|
20653
|
+
definedNamesService,
|
|
20654
|
+
superTableService,
|
|
20655
|
+
functionService
|
|
20656
|
+
}) === true) return {
|
|
20657
|
+
type: DefinedNameBoxActionType.CreateDefinedName,
|
|
20658
|
+
name: inputValue
|
|
20659
|
+
};
|
|
20660
|
+
return { type: DefinedNameBoxActionType.Reset };
|
|
20661
|
+
}
|
|
20662
|
+
function getAbsoluteRefStringFromSelection(workbook, selections, lexerTreeBuilder) {
|
|
20663
|
+
var _workbook$getActiveSh;
|
|
20664
|
+
const sheetName = (_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getName();
|
|
20665
|
+
if (!sheetName || selections == null || selections.length === 0) return "";
|
|
20666
|
+
const formulaOrRefs = selections.map((selection) => (0, _univerjs_engine_formula.serializeRangeWithSheet)(sheetName, selection.range)).join(",");
|
|
20667
|
+
return lexerTreeBuilder.convertRefersToAbsolute(formulaOrRefs, _univerjs_core.AbsoluteRefType.ALL, _univerjs_core.AbsoluteRefType.ALL, sheetName);
|
|
20668
|
+
}
|
|
20669
|
+
|
|
20611
20670
|
//#endregion
|
|
20612
20671
|
//#region src/views/defined-name/DefinedNameOverlay.tsx
|
|
20613
20672
|
function DefinedNameOverlay({ search, isInputEvent }) {
|
|
@@ -20650,6 +20709,12 @@ function DefinedNameOverlay({ search, isInputEvent }) {
|
|
|
20650
20709
|
isInputEvent,
|
|
20651
20710
|
definedNames
|
|
20652
20711
|
]);
|
|
20712
|
+
const listContainerRef = (0, react.useRef)(void 0);
|
|
20713
|
+
const [virtualDefinedNames, virtualActions] = (0, _univerjs_ui.useVirtualList)(filteredDefinedNames, {
|
|
20714
|
+
containerTarget: listContainerRef,
|
|
20715
|
+
itemHeight: 30,
|
|
20716
|
+
overscan: 6
|
|
20717
|
+
});
|
|
20653
20718
|
const openSlider = () => {
|
|
20654
20719
|
commandService.executeCommand(SidebarDefinedNameOperation.id, { value: "open" });
|
|
20655
20720
|
};
|
|
@@ -20665,27 +20730,32 @@ function DefinedNameOverlay({ search, isInputEvent }) {
|
|
|
20665
20730
|
};
|
|
20666
20731
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
20667
20732
|
className: "univer-w-[300px]",
|
|
20668
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("
|
|
20669
|
-
|
|
20670
|
-
|
|
20671
|
-
|
|
20672
|
-
|
|
20673
|
-
|
|
20674
|
-
|
|
20675
|
-
|
|
20676
|
-
|
|
20677
|
-
|
|
20678
|
-
|
|
20679
|
-
|
|
20680
|
-
|
|
20681
|
-
|
|
20682
|
-
|
|
20683
|
-
|
|
20684
|
-
|
|
20685
|
-
|
|
20686
|
-
|
|
20687
|
-
|
|
20688
|
-
|
|
20733
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
20734
|
+
ref: listContainerRef,
|
|
20735
|
+
className: (0, _univerjs_design.clsx)("univer-max-h-[360px] univer-min-h-0 univer-overflow-y-auto", _univerjs_design.scrollbarClassName, { "univer-min-h-[30px]": filteredDefinedNames.length > 0 }),
|
|
20736
|
+
...virtualActions.containerProps,
|
|
20737
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
20738
|
+
style: virtualActions.wrapperStyle,
|
|
20739
|
+
children: virtualDefinedNames.map(({ data: definedName, index }) => {
|
|
20740
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
|
|
20741
|
+
className: "univer-cursor-pointer univer-px-2 univer-transition-colors univer-duration-200 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-600",
|
|
20742
|
+
onClick: () => {
|
|
20743
|
+
focusDefinedName(definedName);
|
|
20744
|
+
},
|
|
20745
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
20746
|
+
className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-justify-between univer-gap-2 univer-py-1", _univerjs_design.borderBottomClassName),
|
|
20747
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
20748
|
+
className: "univer-w-[50%] univer-flex-shrink-0 univer-truncate univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",
|
|
20749
|
+
title: definedName.name,
|
|
20750
|
+
children: definedName.name
|
|
20751
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
20752
|
+
className: "univer-w-[50%] univer-flex-shrink-0 univer-truncate univer-text-xs univer-text-gray-400",
|
|
20753
|
+
title: definedName.formulaOrRefString,
|
|
20754
|
+
children: definedName.formulaOrRefString
|
|
20755
|
+
})]
|
|
20756
|
+
})
|
|
20757
|
+
}, index);
|
|
20758
|
+
})
|
|
20689
20759
|
})
|
|
20690
20760
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
20691
20761
|
className: "univer-cursor-pointer univer-p-2 univer-transition-colors univer-duration-200 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-600",
|
|
@@ -20711,11 +20781,15 @@ function DefinedName({ disable }) {
|
|
|
20711
20781
|
const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
|
|
20712
20782
|
const selectionManagerService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.SheetsSelectionsService);
|
|
20713
20783
|
const lexerTreeBuilder = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.LexerTreeBuilder);
|
|
20784
|
+
const superTableService = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.ISuperTableService);
|
|
20785
|
+
const functionService = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.IFunctionService);
|
|
20786
|
+
const layoutService = (0, _univerjs_ui.useDependency)(_univerjs_ui.ILayoutService);
|
|
20714
20787
|
const workbook = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
20715
20788
|
const unitId = workbook === null || workbook === void 0 ? void 0 : workbook.getUnitId();
|
|
20716
20789
|
const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
|
|
20717
20790
|
const [open, setOpen] = (0, react.useState)(false);
|
|
20718
20791
|
const [isInputEvent, setIsInputEvent] = (0, react.useState)(false);
|
|
20792
|
+
const inputRef = (0, react.useRef)(null);
|
|
20719
20793
|
const getDefinedNameMap = () => {
|
|
20720
20794
|
const definedNameMap = definedNamesService.getDefinedNameMap(unitId);
|
|
20721
20795
|
if (definedNameMap) return Array.from(Object.values(definedNameMap));
|
|
@@ -20744,7 +20818,7 @@ function DefinedName({ disable }) {
|
|
|
20744
20818
|
commandService.executeCommand(ScrollToCellCommand.id, { range: selections[0].range });
|
|
20745
20819
|
});
|
|
20746
20820
|
};
|
|
20747
|
-
const [definedNames, setDefinedNames] = (0, react.useState)(getDefinedNameMap());
|
|
20821
|
+
const [definedNames, setDefinedNames] = (0, react.useState)(() => getDefinedNameMap());
|
|
20748
20822
|
(0, react.useEffect)(() => {
|
|
20749
20823
|
const definedNamesSubscription = definedNamesService.update$.subscribe(() => {
|
|
20750
20824
|
setDefinedNames(getDefinedNameMap());
|
|
@@ -20755,13 +20829,7 @@ function DefinedName({ disable }) {
|
|
|
20755
20829
|
}, []);
|
|
20756
20830
|
(0, react.useEffect)(() => {
|
|
20757
20831
|
const subscription = definedNamesService.currentRange$.subscribe(() => {
|
|
20758
|
-
|
|
20759
|
-
const selections = selectionManagerService.getCurrentSelections();
|
|
20760
|
-
const worksheet = workbook.getActiveSheet();
|
|
20761
|
-
const formulaOrRefs = selections === null || selections === void 0 || (_selections$map = selections.map((selection) => {
|
|
20762
|
-
return (0, _univerjs_engine_formula.serializeRangeWithSheet)(worksheet.getName(), selection.range);
|
|
20763
|
-
})) === null || _selections$map === void 0 ? void 0 : _selections$map.join(",");
|
|
20764
|
-
const absoluteRef = lexerTreeBuilder.convertRefersToAbsolute(formulaOrRefs, _univerjs_core.AbsoluteRefType.ALL, _univerjs_core.AbsoluteRefType.ALL, worksheet.getName());
|
|
20832
|
+
const absoluteRef = getAbsoluteRefStringFromSelection(workbook, selectionManagerService.getCurrentSelections(), lexerTreeBuilder);
|
|
20765
20833
|
const definedName = definedNamesService.getDefinedNameByRefString(unitId, absoluteRef);
|
|
20766
20834
|
if (definedName) {
|
|
20767
20835
|
setRangeString(definedName.name);
|
|
@@ -20792,22 +20860,59 @@ function DefinedName({ disable }) {
|
|
|
20792
20860
|
handleDefinedNamesList(value);
|
|
20793
20861
|
}
|
|
20794
20862
|
function confirm() {
|
|
20795
|
-
|
|
20796
|
-
const
|
|
20797
|
-
|
|
20798
|
-
|
|
20799
|
-
|
|
20800
|
-
|
|
20801
|
-
|
|
20802
|
-
|
|
20803
|
-
|
|
20863
|
+
const formulaOrRefString = getAbsoluteRefStringFromSelection(workbook, selectionManagerService.getCurrentSelections(), lexerTreeBuilder);
|
|
20864
|
+
const action = resolveDefinedNameBoxAction({
|
|
20865
|
+
inputValue,
|
|
20866
|
+
rangeString,
|
|
20867
|
+
unitId,
|
|
20868
|
+
formulaOrRefString,
|
|
20869
|
+
univerInstanceService,
|
|
20870
|
+
definedNamesService,
|
|
20871
|
+
superTableService,
|
|
20872
|
+
functionService
|
|
20873
|
+
});
|
|
20874
|
+
switch (action.type) {
|
|
20875
|
+
case DefinedNameBoxActionType.Noop: return true;
|
|
20876
|
+
case DefinedNameBoxActionType.FocusDefinedName:
|
|
20877
|
+
setRangeString(action.definedName.name);
|
|
20878
|
+
setInputValue(action.definedName.name);
|
|
20879
|
+
focusDefinedName(action.definedName);
|
|
20880
|
+
return true;
|
|
20881
|
+
case DefinedNameBoxActionType.FocusSelection:
|
|
20882
|
+
setRangeString(action.refString);
|
|
20883
|
+
setInputValue(action.refString);
|
|
20884
|
+
focusSelection(action.refString);
|
|
20885
|
+
return true;
|
|
20886
|
+
case DefinedNameBoxActionType.CreateDefinedName: {
|
|
20887
|
+
if (!formulaOrRefString) {
|
|
20888
|
+
resetValue();
|
|
20889
|
+
return false;
|
|
20890
|
+
}
|
|
20891
|
+
const result = commandService.syncExecuteCommand(_univerjs_sheets.InsertDefinedNameCommand.id, {
|
|
20892
|
+
id: (0, _univerjs_core.generateRandomId)(10),
|
|
20893
|
+
unitId,
|
|
20894
|
+
name: action.name,
|
|
20895
|
+
formulaOrRefString,
|
|
20896
|
+
localSheetId: _univerjs_sheets.SCOPE_WORKBOOK_VALUE_DEFINED_NAME
|
|
20897
|
+
});
|
|
20898
|
+
if (result) {
|
|
20899
|
+
setRangeString(action.name);
|
|
20900
|
+
setInputValue(action.name);
|
|
20901
|
+
} else resetValue();
|
|
20902
|
+
return !!result;
|
|
20903
|
+
}
|
|
20904
|
+
case DefinedNameBoxActionType.Reset:
|
|
20905
|
+
resetValue();
|
|
20906
|
+
return false;
|
|
20907
|
+
}
|
|
20804
20908
|
}
|
|
20805
20909
|
function handleKeyDown(e) {
|
|
20806
20910
|
if (disable) return;
|
|
20807
20911
|
if (e.key === "Enter") {
|
|
20808
|
-
confirm();
|
|
20912
|
+
const handled = confirm();
|
|
20809
20913
|
setIsInputEvent(false);
|
|
20810
20914
|
setOpen(false);
|
|
20915
|
+
if (handled) layoutService.focus();
|
|
20811
20916
|
} else if (e.key === "Escape") {
|
|
20812
20917
|
e.preventDefault();
|
|
20813
20918
|
setIsInputEvent(false);
|
|
@@ -20839,6 +20944,7 @@ function DefinedName({ disable }) {
|
|
|
20839
20944
|
"data-u-comp": "defined-name",
|
|
20840
20945
|
className: "univer-relative univer-box-border univer-flex univer-h-full univer-w-24 univer-border-r-gray-200 univer-py-1.5 univer-transition-all",
|
|
20841
20946
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
20947
|
+
ref: inputRef,
|
|
20842
20948
|
className: (0, _univerjs_design.clsx)("univer-box-border univer-size-full univer-appearance-none univer-pl-1.5 univer-pr-5 univer-text-gray-900 focus:univer-outline-none dark:!univer-border-r-gray-700 dark:!univer-bg-gray-900 dark:!univer-text-white", _univerjs_design.borderRightClassName, { "univer-cursor-not-allowed": disable }),
|
|
20843
20949
|
type: "text",
|
|
20844
20950
|
value: inputValue,
|
|
@@ -23815,7 +23921,7 @@ const useHighlightRange = (ranges = []) => {
|
|
|
23815
23921
|
//#endregion
|
|
23816
23922
|
//#region package.json
|
|
23817
23923
|
var name = "@univerjs/sheets-ui";
|
|
23818
|
-
var version = "0.21.
|
|
23924
|
+
var version = "0.21.1";
|
|
23819
23925
|
|
|
23820
23926
|
//#endregion
|
|
23821
23927
|
//#region src/services/cell-alert-manager.service.ts
|