@univerjs/sheets-ui 1.0.0-beta.1 → 1.0.0-beta.2

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 CHANGED
@@ -3124,6 +3124,7 @@ var HtmlToUSMService = class HtmlToUSMService {
3124
3124
  let value = numfmtMatch[1].trim();
3125
3125
  if (value.startsWith("\"") && value.endsWith("\"")) value = value.slice(1, -1);
3126
3126
  const decoded = decodeMsoNumberFormat(value);
3127
+ if (!_univerjs_core.numfmt.isValidFormat(decoded)) continue;
3127
3128
  selectors.split(",").forEach((sel) => {
3128
3129
  this._msoNumfmtMap.set(sel.trim(), decoded);
3129
3130
  });
@@ -8349,7 +8350,8 @@ let EditorBridgeService = class EditorBridgeService extends _univerjs_core.Dispo
8349
8350
  sheetId,
8350
8351
  documentLayoutObject,
8351
8352
  editorUnitId: this._editorUnitId,
8352
- isInArrayFormulaRange: cell === null || cell === void 0 ? void 0 : cell.isInArrayFormulaRange
8353
+ isInArrayFormulaRange: cell === null || cell === void 0 ? void 0 : cell.isInArrayFormulaRange,
8354
+ isPercentFormat: cell === null || cell === void 0 ? void 0 : cell.isPercentFormat
8353
8355
  };
8354
8356
  }
8355
8357
  _getWorkbookForEditUnit(unitId) {
@@ -10021,25 +10023,25 @@ let EditorBridgeRenderController = class EditorBridgeRenderController extends _u
10021
10023
  _initialKeyboardListener(d) {
10022
10024
  let disposable = null;
10023
10025
  const addEvent = (render) => {
10026
+ disposable === null || disposable === void 0 || disposable.dispose();
10027
+ disposable = null;
10024
10028
  const docSelectionRenderService = render.with(_univerjs_docs_ui.DocSelectionRenderService);
10025
- if (docSelectionRenderService) {
10026
- disposable = (0, _univerjs_core.toDisposable)(docSelectionRenderService.onInputBefore$.subscribe((config) => {
10027
- var _this$_embedRuntimeFo;
10028
- if (!this._isCurrentSheetFocused()) return;
10029
- const isFocusFormulaEditor = this._contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR);
10030
- const isFocusSheets = this._contextService.getContextValue(_univerjs_core.FOCUSING_SHEET) || ((_this$_embedRuntimeFo = this._embedRuntimeFocusCoordinator) === null || _this$_embedRuntimeFo === void 0 ? void 0 : _this$_embedRuntimeFo.isChildUnitInActiveSession(this._context.unitId)) === true;
10031
- const unitId = render.unitId;
10032
- if (this._editorBridgeService.isVisible().visible) return;
10033
- if (unitId && isFocusSheets && !isFocusFormulaEditor) this._showEditorByKeyboard(config);
10034
- }));
10035
- d.add(disposable);
10036
- }
10029
+ if (docSelectionRenderService) disposable = (0, _univerjs_core.toDisposable)(docSelectionRenderService.onInputBefore$.subscribe((config) => {
10030
+ var _this$_embedRuntimeFo;
10031
+ if (!this._isCurrentSheetFocused()) return;
10032
+ const isFocusFormulaEditor = this._contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR);
10033
+ const isFocusSheets = this._contextService.getContextValue(_univerjs_core.FOCUSING_SHEET) || ((_this$_embedRuntimeFo = this._embedRuntimeFocusCoordinator) === null || _this$_embedRuntimeFo === void 0 ? void 0 : _this$_embedRuntimeFo.isChildUnitInActiveSession(this._context.unitId)) === true;
10034
+ const unitId = render.unitId;
10035
+ if (this._editorBridgeService.isVisible().visible) return;
10036
+ if (unitId && isFocusSheets && !isFocusFormulaEditor) this._showEditorByKeyboard(config);
10037
+ }));
10037
10038
  };
10038
10039
  const render = this._renderManagerService.getRenderUnitById(_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
10039
10040
  if (render) addEvent(render);
10040
- else this.disposeWithMe(this._renderManagerService.created$.pipe((0, rxjs.filter)((render) => render.unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)).subscribe((render) => {
10041
+ d.add(this._renderManagerService.created$.pipe((0, rxjs.filter)((render) => render.unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)).subscribe(addEvent));
10042
+ d.add((0, _univerjs_core.toDisposable)(() => {
10041
10043
  disposable === null || disposable === void 0 || disposable.dispose();
10042
- addEvent(render);
10044
+ disposable = null;
10043
10045
  }));
10044
10046
  }
10045
10047
  _initSheetFocusListener(d) {
@@ -10788,8 +10790,29 @@ const isRangeSelector = (unitId) => {
10788
10790
  //#endregion
10789
10791
  //#region src/controllers/editor/editing.render-controller.ts
10790
10792
  const HIDDEN_EDITOR_POSITION$1 = -1e3;
10793
+ function getPercentOffset(editCellState, dataStream) {
10794
+ if (!editCellState.isPercentFormat || editCellState.isInArrayFormulaRange) return null;
10795
+ const percentSuffix = `%${_univerjs_core.DEFAULT_EMPTY_DOCUMENT_VALUE}`;
10796
+ return (dataStream === null || dataStream === void 0 ? void 0 : dataStream.endsWith(percentSuffix)) ? dataStream.length - percentSuffix.length : null;
10797
+ }
10798
+ function getPercentEditorSelection(editCellState, visibleParam, dataStream) {
10799
+ const percentOffset = getPercentOffset(editCellState, dataStream);
10800
+ if (percentOffset == null) return null;
10801
+ const { eventType, initialValue, keycode } = visibleParam;
10802
+ if (eventType === _univerjs_engine_render.DeviceInputEventType.Dblclick || eventType === _univerjs_engine_render.DeviceInputEventType.Keyboard && keycode === _univerjs_ui.KeyCode.F2) return {
10803
+ startOffset: percentOffset,
10804
+ endOffset: percentOffset,
10805
+ collapsed: true
10806
+ };
10807
+ if (eventType !== _univerjs_engine_render.DeviceInputEventType.Keyboard || keycode === _univerjs_ui.KeyCode.BACKSPACE || keycode === _univerjs_ui.KeyCode.DELETE || !/^\d/.test(initialValue ?? "")) return null;
10808
+ return {
10809
+ startOffset: 0,
10810
+ endOffset: percentOffset,
10811
+ collapsed: false
10812
+ };
10813
+ }
10791
10814
  let EditingRenderController = class EditingRenderController extends _univerjs_core.Disposable {
10792
- constructor(_undoRedoService, _contextService, _renderManagerService, _editorBridgeService, _cellEditorManagerService, _lexerTreeBuilder, _functionService, _textSelectionManagerService, _commandService, _localService, _editorService, _univerInstanceService, _sheetInterceptorService, _sheetCellEditorResizeService, _selectionManagerService, _configService) {
10815
+ constructor(_undoRedoService, _contextService, _renderManagerService, _editorBridgeService, _cellEditorManagerService, _lexerTreeBuilder, _functionService, _textSelectionManagerService, _commandService, _localService, _editorService, _univerInstanceService, _sheetInterceptorService, _sheetCellEditorResizeService, _selectionManagerService, _configService, _docStateChangeManagerService) {
10793
10816
  super();
10794
10817
  this._undoRedoService = _undoRedoService;
10795
10818
  this._contextService = _contextService;
@@ -10807,6 +10830,7 @@ let EditingRenderController = class EditingRenderController extends _univerjs_co
10807
10830
  this._sheetCellEditorResizeService = _sheetCellEditorResizeService;
10808
10831
  this._selectionManagerService = _selectionManagerService;
10809
10832
  this._configService = _configService;
10833
+ this._docStateChangeManagerService = _docStateChangeManagerService;
10810
10834
  _defineProperty(this, "_cursorChange", 0);
10811
10835
  _defineProperty(this, "_editingUnit", "");
10812
10836
  _defineProperty(this, "_submitEmptyCellImageEdit", false);
@@ -10881,6 +10905,7 @@ let EditingRenderController = class EditingRenderController extends _univerjs_co
10881
10905
  const docSelectionRenderManager = (_this$_renderManagerS2 = this._renderManagerService.getRenderUnitById(docUnitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(_univerjs_docs_ui.DocSelectionRenderService);
10882
10906
  if (!docSelectionRenderManager) return;
10883
10907
  docSelectionRenderManager.sync();
10908
+ this._cacheEmptyCellTextStyle();
10884
10909
  }));
10885
10910
  }
10886
10911
  _initSkeletonListener(d) {
@@ -10961,6 +10986,30 @@ let EditingRenderController = class EditingRenderController extends _univerjs_co
10961
10986
  * Listen to document edits to refresh the size of the sheet editor, not for normal editor.
10962
10987
  */
10963
10988
  _commandExecutedListener(d) {
10989
+ d.add(this._commandService.beforeCommandExecuted((command) => {
10990
+ var _this$_getDocumentDat;
10991
+ if (command.id !== _univerjs_docs.InsertTextCommand.id) return;
10992
+ const params = command.params;
10993
+ const visibleParam = this._editorBridgeService.isVisible();
10994
+ const editCellState = this._editorBridgeService.getEditLocation();
10995
+ if (params.unitId !== _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY || !visibleParam.visible || editCellState == null) return;
10996
+ const dataStream = (_this$_getDocumentDat = this._getDocumentDataModel()) === null || _this$_getDocumentDat === void 0 || (_this$_getDocumentDat = _this$_getDocumentDat.getBody()) === null || _this$_getDocumentDat === void 0 ? void 0 : _this$_getDocumentDat.dataStream;
10997
+ if (dataStream == null) return;
10998
+ const percentOffset = getPercentOffset(editCellState, dataStream);
10999
+ if (percentOffset != null && !this._editorBridgeService.getEditorDirty() && visibleParam.eventType === _univerjs_engine_render.DeviceInputEventType.Keyboard && /^\d/.test(visibleParam.initialValue ?? "") && /^\d/.test(params.body.dataStream)) {
11000
+ params.range = {
11001
+ startOffset: 0,
11002
+ endOffset: percentOffset,
11003
+ collapsed: false
11004
+ };
11005
+ return;
11006
+ }
11007
+ if (percentOffset != null && params.body.dataStream === "%" && params.range.collapsed && params.range.startOffset === percentOffset && params.range.endOffset === percentOffset) params.range = {
11008
+ ...params.range,
11009
+ endOffset: percentOffset + 1,
11010
+ collapsed: false
11011
+ };
11012
+ }));
10964
11013
  d.add(this._commandService.onCommandExecuted((command) => {
10965
11014
  if (command.id === _univerjs_docs.RichTextEditingMutation.id) {
10966
11015
  const { unitId: commandUnitId } = command.params;
@@ -10993,12 +11042,13 @@ let EditingRenderController = class EditingRenderController extends _univerjs_co
10993
11042
  }));
10994
11043
  }
10995
11044
  _handleEditorVisible(param) {
10996
- var _this$_sheetCellEdito4, _this$_renderManagerS5;
11045
+ var _this$_sheetCellEdito4, _documentDataModel$ge, _this$_renderManagerS5;
10997
11046
  const { eventType, keycode } = param;
10998
11047
  this._cursorChange = eventType === _univerjs_engine_render.DeviceInputEventType.PointerDown || eventType === _univerjs_engine_render.DeviceInputEventType.Dblclick ? 2 : 1;
10999
11048
  const editCellState = this._editorBridgeService.getEditLocation();
11000
11049
  if (editCellState == null) return;
11001
11050
  const { unitId, isInArrayFormulaRange = false } = editCellState;
11051
+ this._clearEditorHistory();
11002
11052
  this._commandService.syncExecuteCommand(ScrollToRangeOperation.id, {
11003
11053
  unitId,
11004
11054
  range: {
@@ -11038,35 +11088,51 @@ let EditingRenderController = class EditingRenderController extends _univerjs_co
11038
11088
  subUnitId: _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY
11039
11089
  });
11040
11090
  };
11091
+ const replaceSelection = (selection) => {
11092
+ this._textSelectionManagerService.replaceDocRanges([selection], {
11093
+ unitId: _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
11094
+ subUnitId: _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY
11095
+ });
11096
+ };
11097
+ const percentSelection = getPercentEditorSelection(editCellState, param, (_documentDataModel$ge = documentDataModel.getBody()) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.dataStream);
11041
11098
  const cellImage = (0, _univerjs_sheets.isCellImage)(documentDataModel.getSnapshot());
11042
11099
  this._submitEmptyCellImageEdit = cellImage && eventType === _univerjs_engine_render.DeviceInputEventType.Keyboard && keycode === _univerjs_ui.KeyCode.BACKSPACE;
11043
11100
  if (cellImage) clearAndEdit();
11044
11101
  else if (eventType === _univerjs_engine_render.DeviceInputEventType.Keyboard && keycode === _univerjs_ui.KeyCode.F2) {
11045
- var _documentDataModel$ge;
11102
+ var _documentDataModel$ge2;
11046
11103
  document.makeDirty();
11047
11104
  this._textSelectionManagerService.replaceDocRanges([{
11048
11105
  startOffset: 0,
11049
11106
  endOffset: 0
11050
11107
  }]);
11051
- const endOffset = (((_documentDataModel$ge = documentDataModel.getBody()) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.dataStream.length) ?? 2) - 2;
11052
- this._textSelectionManagerService.replaceDocRanges([{
11108
+ const endOffset = (((_documentDataModel$ge2 = documentDataModel.getBody()) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.dataStream.length) ?? 2) - 2;
11109
+ if (percentSelection) replaceSelection(percentSelection);
11110
+ else this._textSelectionManagerService.replaceDocRanges([{
11053
11111
  startOffset: endOffset,
11054
11112
  endOffset
11055
11113
  }], {
11056
11114
  unitId: _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
11057
11115
  subUnitId: _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY
11058
11116
  });
11059
- } else if (eventType === _univerjs_engine_render.DeviceInputEventType.Keyboard || eventType === _univerjs_engine_render.DeviceInputEventType.Dblclick && isInArrayFormulaRange) clearAndEdit();
11117
+ } else if (eventType === _univerjs_engine_render.DeviceInputEventType.Keyboard || eventType === _univerjs_engine_render.DeviceInputEventType.Dblclick && isInArrayFormulaRange) if (percentSelection) replaceSelection(percentSelection);
11118
+ else clearAndEdit();
11060
11119
  else if (eventType === _univerjs_engine_render.DeviceInputEventType.Dblclick) {
11061
11120
  if (this._contextService.getContextValue(_univerjs_core.FOCUSING_EDITOR_INPUT_FORMULA)) return;
11062
11121
  const cursor = documentDataModel.getBody().dataStream.length - 2 || 0;
11063
- this._textSelectionManagerService.replaceDocRanges([{
11122
+ if (percentSelection) replaceSelection(percentSelection);
11123
+ else this._textSelectionManagerService.replaceDocRanges([{
11064
11124
  startOffset: cursor,
11065
11125
  endOffset: cursor
11066
11126
  }]);
11067
11127
  }
11068
11128
  (_this$_renderManagerS5 = this._renderManagerService.getRenderUnitById(unitId)) === null || _this$_renderManagerS5 === void 0 || _this$_renderManagerS5.scene.resetCursor();
11069
11129
  }
11130
+ _cacheEmptyCellTextStyle() {
11131
+ var _this$_editorBridgeSe, _sourceBody$textRuns;
11132
+ const sourceBody = (_this$_editorBridgeSe = this._editorBridgeService.getEditLocation()) === null || _this$_editorBridgeSe === void 0 || (_this$_editorBridgeSe = _this$_editorBridgeSe.documentLayoutObject.documentModel) === null || _this$_editorBridgeSe === void 0 ? void 0 : _this$_editorBridgeSe.getBody();
11133
+ const textRun = (sourceBody === null || sourceBody === void 0 || (_sourceBody$textRuns = sourceBody.textRuns) === null || _sourceBody$textRuns === void 0 ? void 0 : _sourceBody$textRuns.length) === 1 ? sourceBody.textRuns[0] : null;
11134
+ if ((sourceBody === null || sourceBody === void 0 ? void 0 : sourceBody.dataStream) === _univerjs_core.DEFAULT_EMPTY_DOCUMENT_VALUE && (textRun === null || textRun === void 0 ? void 0 : textRun.st) === 0 && textRun.ed === 0) this._commandService.syncExecuteCommand(_univerjs_docs_ui.SetDocInputStyleCommand.id, { style: _univerjs_core.Tools.deepClone(textRun.ts) });
11135
+ }
11070
11136
  _refreshCurrentSelections(sheetId) {
11071
11137
  const selections = this._workbookSelections.getSelectionsOfWorksheet(sheetId);
11072
11138
  if (selections) {
@@ -11190,8 +11256,13 @@ let EditingRenderController = class EditingRenderController extends _univerjs_co
11190
11256
  var _this$_getEditorSkele;
11191
11257
  (_this$_getEditorSkele = this._getEditorSkeleton(_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)) === null || _this$_getEditorSkele === void 0 || _this$_getEditorSkele.resetInitialWidth();
11192
11258
  }
11193
- this._undoRedoService.clearUndoRedo(editorUnitId);
11259
+ this._clearEditorHistory();
11260
+ }
11261
+ _clearEditorHistory() {
11262
+ this._undoRedoService.clearUndoRedo(_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
11194
11263
  this._undoRedoService.clearUndoRedo(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
11264
+ this._docStateChangeManagerService.clearHistory(_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
11265
+ this._docStateChangeManagerService.clearHistory(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
11195
11266
  }
11196
11267
  _moveSelection(keycode, currentUnitId, worksheetId) {
11197
11268
  if (keycode == null || !MOVE_SELECTION_KEYCODE_LIST.includes(keycode)) {
@@ -11295,7 +11366,8 @@ EditingRenderController = __decorate([
11295
11366
  __decorateParam(12, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
11296
11367
  __decorateParam(13, (0, _univerjs_core.Inject)(SheetCellEditorResizeService)),
11297
11368
  __decorateParam(14, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
11298
- __decorateParam(15, _univerjs_core.IConfigService)
11369
+ __decorateParam(15, _univerjs_core.IConfigService),
11370
+ __decorateParam(16, (0, _univerjs_core.Inject)(_univerjs_docs.DocStateChangeManagerService))
11299
11371
  ], EditingRenderController);
11300
11372
  function getCellDataByInput(cellData, snapshot, lexerTreeBuilder, localeService, functionService, styles) {
11301
11373
  var _styles$get;
@@ -23125,11 +23197,11 @@ function RenderSheetFooter() {
23125
23197
  const showFooter = (config === null || config === void 0 ? void 0 : config.footer) ?? true;
23126
23198
  const workbook = useRootWorkbenchWorkbook();
23127
23199
  const activeWorkbookEmbeddedRender = useActiveWorkbookIsEmbeddedRender(workbook);
23128
- const focusedUnitType = useFocusedUnitType();
23200
+ const rootUnitType = useWorkbenchRootUnitType();
23129
23201
  const activeEmbedTab = useActiveSheetEmbedTabData(workbook);
23130
23202
  if (!workbook || !showFooter) return null;
23131
23203
  if (activeWorkbookEmbeddedRender) return null;
23132
- if (!activeEmbedTab && focusedUnitType != null && focusedUnitType !== _univerjs_core.UniverInstanceType.UNIVER_SHEET) return null;
23204
+ if (rootUnitType !== _univerjs_core.UniverInstanceType.UNIVER_SHEET) return null;
23133
23205
  const footerMenus = menuManagerService.getMenuByPositionKey(_univerjs_ui.ContextMenuPosition.FOOTER_MENU);
23134
23206
  const { sheetBar = true, statisticBar = true, menus = true, zoomSlider = true } = (config === null || config === void 0 ? void 0 : config.footer) || {};
23135
23207
  const showStatisticBar = activeEmbedTab ? false : statisticBar;
@@ -23159,16 +23231,12 @@ function RenderSheetHeader() {
23159
23231
  const workbook = useRootWorkbenchWorkbook();
23160
23232
  const hasWorkbook = !!workbook;
23161
23233
  const activeWorkbookEmbeddedRender = useActiveWorkbookIsEmbeddedRender(workbook);
23162
- const focusedUnitType = useFocusedUnitType();
23234
+ const rootUnitType = useWorkbenchRootUnitType();
23163
23235
  const activeEmbedTab = useActiveSheetEmbedTabData(workbook);
23164
23236
  if (!hasWorkbook) return null;
23165
23237
  if (activeWorkbookEmbeddedRender) return null;
23166
23238
  if (activeEmbedTab) return null;
23167
- if (focusedUnitType != null && focusedUnitType !== _univerjs_core.UniverInstanceType.UNIVER_SHEET) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23168
- "aria-hidden": true,
23169
- className: "univer-h-7 univer-border-b univer-border-gray-200 univer-bg-gray-0 dark:!univer-border-gray-700 dark:!univer-bg-gray-900",
23170
- "data-u-comp": "formula-bar-placeholder"
23171
- });
23239
+ if (rootUnitType !== _univerjs_core.UniverInstanceType.UNIVER_SHEET) return null;
23172
23240
  if ((config === null || config === void 0 ? void 0 : config.formulaBar) !== false) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormulaBar, {});
23173
23241
  return null;
23174
23242
  }
@@ -23182,8 +23250,7 @@ function RenderSheetContent() {
23182
23250
  const activeEmbedTab = useActiveSheetEmbedTabData(workbook);
23183
23251
  const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
23184
23252
  const activeWorkbookEmbeddedRender = useActiveWorkbookIsEmbeddedRender(workbook);
23185
- const focusedUnitType = useFocusedUnitType();
23186
- const rootWorkbenchOwnsSheet = activeEmbedTab != null || focusedUnitType == null || focusedUnitType === _univerjs_core.UniverInstanceType.UNIVER_SHEET;
23253
+ const rootWorkbenchOwnsSheet = useWorkbenchRootUnitType() === _univerjs_core.UniverInstanceType.UNIVER_SHEET;
23187
23254
  const ShapeTextEditorContainer = componentManager.get("SheetShapeTextEditorContainer") ?? componentManager.get("ShapeTextEditorContainer");
23188
23255
  (0, react.useEffect)(() => {
23189
23256
  var _tryGetSheetEmbedRunt;
@@ -23280,15 +23347,8 @@ function useRootWorkbenchWorkbook() {
23280
23347
  (0, _univerjs_ui.useObservable)(() => (runtimeFocusCoordinator === null || runtimeFocusCoordinator === void 0 ? void 0 : runtimeFocusCoordinator.runtimeSessionChanged$) ?? rxjs.EMPTY, null, false, [runtimeFocusCoordinator])
23281
23348
  ]);
23282
23349
  }
23283
- function useFocusedUnitType() {
23284
- const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
23285
- const focusedUnitId = (0, _univerjs_ui.useObservable)(() => univerInstanceService.focused$, null, false, [univerInstanceService]);
23286
- return (0, react.useMemo)(() => {
23287
- if (!focusedUnitId) return null;
23288
- if ((0, _univerjs_core.isInternalEditorID)(focusedUnitId) && univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)) return _univerjs_core.UniverInstanceType.UNIVER_SHEET;
23289
- const focusedUnit = univerInstanceService.getUnit(focusedUnitId);
23290
- return (focusedUnit === null || focusedUnit === void 0 ? void 0 : focusedUnit.type) ?? null;
23291
- }, [focusedUnitId, univerInstanceService]);
23350
+ function useWorkbenchRootUnitType() {
23351
+ return (0, _univerjs_ui.useObservable)((0, _univerjs_ui.useDependency)(_univerjs_ui.IWorkbenchService).rootUnitType$, null, true);
23292
23352
  }
23293
23353
  function useActiveSheetEmbedTabData(workbook) {
23294
23354
  const worksheet = useActiveWorksheet(workbook);
@@ -23913,7 +23973,7 @@ const useHighlightRange = (ranges = []) => {
23913
23973
  //#endregion
23914
23974
  //#region package.json
23915
23975
  var name = "@univerjs/sheets-ui";
23916
- var version = "1.0.0-beta.1";
23976
+ var version = "1.0.0-beta.2";
23917
23977
 
23918
23978
  //#endregion
23919
23979
  //#region src/views/cell-popup/config.ts
@@ -24134,6 +24194,7 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
24134
24194
  const canvasElement = currentRender.engine.getCanvasElement();
24135
24195
  const scaleAdjust = canvasElement.getBoundingClientRect().width / pxToNum(canvasElement.style.width);
24136
24196
  const { scaleX, scaleY } = currentRender.scene.getAncestorScale();
24197
+ const viewMain = currentRender.scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN);
24137
24198
  const id = this._globalPopupManagerService.addPopup({
24138
24199
  ...popup,
24139
24200
  unitId,
@@ -24143,8 +24204,8 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
24143
24204
  anchorRect$: position$,
24144
24205
  canvasElement,
24145
24206
  boundaryInsets: popup.constrainToCanvas ? {
24146
- left: skeleton.rowHeaderWidth * scaleAdjust * scaleX,
24147
- top: skeleton.columnHeaderHeight * scaleAdjust * scaleY
24207
+ left: ((viewMain === null || viewMain === void 0 ? void 0 : viewMain.left) ?? skeleton.rowHeaderWidth * scaleX) * scaleAdjust,
24208
+ top: ((viewMain === null || viewMain === void 0 ? void 0 : viewMain.top) ?? skeleton.columnHeaderHeight * scaleY) * scaleAdjust
24148
24209
  } : popup.boundaryInsets
24149
24210
  });
24150
24211
  const disposableCollection = new _univerjs_core.DisposableCollection();
@@ -27867,10 +27928,11 @@ let EditorDataSyncController = class EditorDataSyncController extends _univerjs_
27867
27928
  if (unitId === _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) this._formulaEditorController.autoScroll();
27868
27929
  }
27869
27930
  _checkAndSetRenderStyleConfig(documentDataModel) {
27870
- var _snapshot$body;
27931
+ var _snapshot$documentSty, _snapshot$body;
27871
27932
  const snapshot = documentDataModel.getSnapshot();
27872
27933
  if (snapshot.id !== _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY && snapshot.id !== _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY) return;
27873
27934
  const isFormulaBar = snapshot.id === _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY;
27935
+ const previousPageWidth = (_snapshot$documentSty = snapshot.documentStyle) === null || _snapshot$documentSty === void 0 || (_snapshot$documentSty = _snapshot$documentSty.pageSize) === null || _snapshot$documentSty === void 0 ? void 0 : _snapshot$documentSty.width;
27874
27936
  if (isFormulaBar) snapshot.documentStyle = {
27875
27937
  ...formulaEditorStyle,
27876
27938
  textStyle: { cl: { rgb: this._themeService.getColorFromTheme("gray.900") } }
@@ -27883,8 +27945,8 @@ let EditorDataSyncController = class EditorDataSyncController extends _univerjs_
27883
27945
  }
27884
27946
  const position = isFormulaBar ? this._formulaEditorManagerService.getPosition() : null;
27885
27947
  if (isFormulaBar && position) {
27886
- const width = position.width;
27887
- snapshot.documentStyle.pageSize = {
27948
+ const width = position.width > 0 ? position.width : previousPageWidth;
27949
+ if (width != null && width > 0) snapshot.documentStyle.pageSize = {
27888
27950
  width,
27889
27951
  height: Infinity
27890
27952
  };
@@ -29247,35 +29309,37 @@ FormatPainterRenderController = __decorate([
29247
29309
  //#region src/controllers/render-controllers/header-menu.render-controller.ts
29248
29310
  const HEADER_MENU_CONTROLLER_SHAPE = "__SpreadsheetHeaderMenuSHAPEControllerShape__";
29249
29311
  const HEADER_MENU_CONTROLLER_MENU = "__SpreadsheetHeaderMenuMAINControllerShape__";
29250
- const HEADER_MENU_CONTROLLER_SHAPE_COLOR = "gray.100";
29312
+ const HEADER_MENU_CONTROLLER_SHAPE_ALPHA = .1;
29251
29313
  let HeaderMenuRenderController = class HeaderMenuRenderController extends _univerjs_core.Disposable {
29252
- constructor(_context, _sheetSkeletonManagerService, _contextMenuService, _commandService, _selectionManagerService) {
29314
+ constructor(_context, _sheetSkeletonManagerService, _contextMenuService, _commandService, _selectionManagerService, _themeService) {
29253
29315
  super();
29254
29316
  this._context = _context;
29255
29317
  this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
29256
29318
  this._contextMenuService = _contextMenuService;
29257
29319
  this._commandService = _commandService;
29258
29320
  this._selectionManagerService = _selectionManagerService;
29321
+ this._themeService = _themeService;
29259
29322
  _defineProperty(this, "_hoverRect", void 0);
29260
29323
  _defineProperty(this, "_hoverMenu", void 0);
29261
29324
  _defineProperty(this, "_currentColumn", Number.POSITIVE_INFINITY);
29262
- _defineProperty(this, "_headerPointerSubs", void 0);
29263
- _defineProperty(this, "_colHeaderPointerSubs", void 0);
29325
+ _defineProperty(this, "_headerPointerSubs", new rxjs.Subscription());
29264
29326
  this._initialize();
29265
29327
  }
29266
29328
  dispose() {
29267
- var _this$_hoverRect, _this$_hoverMenu, _this$_headerPointerS;
29329
+ var _this$_hoverRect, _this$_hoverMenu;
29330
+ super.dispose();
29268
29331
  (_this$_hoverRect = this._hoverRect) === null || _this$_hoverRect === void 0 || _this$_hoverRect.dispose();
29269
29332
  (_this$_hoverMenu = this._hoverMenu) === null || _this$_hoverMenu === void 0 || _this$_hoverMenu.dispose();
29270
- (_this$_headerPointerS = this._headerPointerSubs) === null || _this$_headerPointerS === void 0 || _this$_headerPointerS.unsubscribe();
29271
- this._headerPointerSubs = null;
29333
+ this._headerPointerSubs.unsubscribe();
29272
29334
  }
29273
29335
  _initialize() {
29274
29336
  const scene = this._context.scene;
29275
- this._hoverRect = new _univerjs_engine_render.Rect(HEADER_MENU_CONTROLLER_SHAPE, {
29276
- fill: HEADER_MENU_CONTROLLER_SHAPE_COLOR,
29277
- evented: false
29278
- });
29337
+ this._hoverRect = new _univerjs_engine_render.Rect(HEADER_MENU_CONTROLLER_SHAPE, { evented: false });
29338
+ this.disposeWithMe(this._themeService.currentTheme$.subscribe(() => {
29339
+ var _this$_hoverRect2;
29340
+ const color = this._themeService.getColorFromTheme("gray.900");
29341
+ (_this$_hoverRect2 = this._hoverRect) === null || _this$_hoverRect2 === void 0 || _this$_hoverRect2.setProps({ fill: new _univerjs_core.ColorKit(color).setAlpha(HEADER_MENU_CONTROLLER_SHAPE_ALPHA).toRgbString() });
29342
+ }));
29279
29343
  this._hoverMenu = new HeaderMenuShape(HEADER_MENU_CONTROLLER_MENU, {
29280
29344
  zIndex: 100,
29281
29345
  visible: false
@@ -29286,7 +29350,6 @@ let HeaderMenuRenderController = class HeaderMenuRenderController extends _unive
29286
29350
  this._initialHoverMenu();
29287
29351
  }
29288
29352
  _initialHover(initialType = 0) {
29289
- var _this$_headerPointerS2, _this$_headerPointerS3, _this$_headerPointerS4;
29290
29353
  const spreadsheetColumnHeader = this._context.components.get("__SpreadsheetColumnHeader__");
29291
29354
  const spreadsheetRowHeader = this._context.components.get("__SpreadsheetRowHeader__");
29292
29355
  const eventBindingObject = initialType === 0 ? spreadsheetRowHeader : spreadsheetColumnHeader;
@@ -29297,17 +29360,17 @@ let HeaderMenuRenderController = class HeaderMenuRenderController extends _unive
29297
29360
  const { rowBaseWidth, rowGutterWidth, columnBaseHeight, columnGutterHeight } = getHeaderBaseLayout(skeleton);
29298
29361
  const { startX, startY, endX, endY, column } = getCoordByOffset(evt.offsetX, evt.offsetY, this._context.scene, skeleton);
29299
29362
  if (initialType === 0) {
29300
- var _this$_hoverRect2;
29301
- (_this$_hoverRect2 = this._hoverRect) === null || _this$_hoverRect2 === void 0 || _this$_hoverRect2.transformByState({
29363
+ var _this$_hoverRect3;
29364
+ (_this$_hoverRect3 = this._hoverRect) === null || _this$_hoverRect3 === void 0 || _this$_hoverRect3.transformByState({
29302
29365
  width: rowBaseWidth,
29303
29366
  height: endY - startY,
29304
29367
  left: rowGutterWidth,
29305
29368
  top: startY
29306
29369
  });
29307
29370
  } else {
29308
- var _this$_hoverRect3;
29371
+ var _this$_hoverRect4;
29309
29372
  this._currentColumn = column;
29310
- (_this$_hoverRect3 = this._hoverRect) === null || _this$_hoverRect3 === void 0 || _this$_hoverRect3.transformByState({
29373
+ (_this$_hoverRect4 = this._hoverRect) === null || _this$_hoverRect4 === void 0 || _this$_hoverRect4.transformByState({
29311
29374
  width: endX - startX,
29312
29375
  height: columnBaseHeight,
29313
29376
  left: startX,
@@ -29328,21 +29391,20 @@ let HeaderMenuRenderController = class HeaderMenuRenderController extends _unive
29328
29391
  }
29329
29392
  };
29330
29393
  const pointerEnterHandler = () => {
29331
- var _this$_hoverRect4;
29332
- (_this$_hoverRect4 = this._hoverRect) === null || _this$_hoverRect4 === void 0 || _this$_hoverRect4.show();
29394
+ var _this$_hoverRect5;
29395
+ (_this$_hoverRect5 = this._hoverRect) === null || _this$_hoverRect5 === void 0 || _this$_hoverRect5.show();
29333
29396
  };
29334
29397
  const pointerLeaveHandler = () => {
29335
- var _this$_hoverRect5, _this$_hoverMenu2;
29336
- (_this$_hoverRect5 = this._hoverRect) === null || _this$_hoverRect5 === void 0 || _this$_hoverRect5.hide();
29398
+ var _this$_hoverRect6, _this$_hoverMenu2;
29399
+ (_this$_hoverRect6 = this._hoverRect) === null || _this$_hoverRect6 === void 0 || _this$_hoverRect6.hide();
29337
29400
  (_this$_hoverMenu2 = this._hoverMenu) === null || _this$_hoverMenu2 === void 0 || _this$_hoverMenu2.hide();
29338
29401
  };
29339
- this._headerPointerSubs = new rxjs.Subscription();
29340
29402
  const headerPointerMoveSub = eventBindingObject.onPointerMove$.subscribeEvent(pointerMoveHandler);
29341
29403
  const headerPointerEnterSub = eventBindingObject.onPointerEnter$.subscribeEvent(pointerEnterHandler);
29342
29404
  const headerPointerLeaveSub = eventBindingObject.onPointerLeave$.subscribeEvent(pointerLeaveHandler);
29343
- (_this$_headerPointerS2 = this._headerPointerSubs) === null || _this$_headerPointerS2 === void 0 || _this$_headerPointerS2.add(headerPointerMoveSub);
29344
- (_this$_headerPointerS3 = this._headerPointerSubs) === null || _this$_headerPointerS3 === void 0 || _this$_headerPointerS3.add(headerPointerEnterSub);
29345
- (_this$_headerPointerS4 = this._headerPointerSubs) === null || _this$_headerPointerS4 === void 0 || _this$_headerPointerS4.add(headerPointerLeaveSub);
29405
+ this._headerPointerSubs.add(headerPointerMoveSub);
29406
+ this._headerPointerSubs.add(headerPointerEnterSub);
29407
+ this._headerPointerSubs.add(headerPointerLeaveSub);
29346
29408
  }
29347
29409
  _initialHoverMenu() {
29348
29410
  if (this._hoverMenu == null) return;
@@ -29413,7 +29475,8 @@ HeaderMenuRenderController = __decorate([
29413
29475
  __decorateParam(1, (0, _univerjs_core.Inject)(SheetSkeletonManagerService)),
29414
29476
  __decorateParam(2, _univerjs_ui.IContextMenuService),
29415
29477
  __decorateParam(3, _univerjs_core.ICommandService),
29416
- __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService))
29478
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
29479
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService))
29417
29480
  ], HeaderMenuRenderController);
29418
29481
  function getHeaderBaseLayout(skeleton) {
29419
29482
  var _skeleton$worksheet$g, _skeleton$worksheet, _config$rowHeader, _config$columnHeader;
@@ -31794,6 +31857,7 @@ let SheetContextMenuRenderController = class SheetContextMenuRenderController ex
31794
31857
  this._selectionRenderService = _selectionRenderService;
31795
31858
  this._injector = _injector;
31796
31859
  this._init();
31860
+ this._initEmbedRuntimeSessionListener();
31797
31861
  }
31798
31862
  _init() {
31799
31863
  var _this$_context;
@@ -31841,6 +31905,13 @@ let SheetContextMenuRenderController = class SheetContextMenuRenderController ex
31841
31905
  });
31842
31906
  this.disposeWithMe(colHeaderObserver);
31843
31907
  }
31908
+ _initEmbedRuntimeSessionListener() {
31909
+ const runtimeFocusCoordinator = this._getSheetEmbedRuntimeFocusCoordinator();
31910
+ if (!runtimeFocusCoordinator) return;
31911
+ this.disposeWithMe(runtimeFocusCoordinator.runtimeSessionChanged$.subscribe(() => {
31912
+ if (shouldHideSheetHostContextMenuForEmbedSession(this._context.unitId, runtimeFocusCoordinator.resolveActiveChildSessionRuntimeScope())) this._contextMenuService.hideContextMenu();
31913
+ }));
31914
+ }
31844
31915
  _shouldSuppressHostContextMenu() {
31845
31916
  var _this$_getSheetHostCh, _this$_getSheetHostCh2;
31846
31917
  return shouldSuppressSheetContextMenuForEmbedOverride(this._context.unitId, (_this$_getSheetHostCh = this._getSheetHostChromeOverrideService()) === null || _this$_getSheetHostCh === void 0 || (_this$_getSheetHostCh2 = _this$_getSheetHostCh.getOverride) === null || _this$_getSheetHostCh2 === void 0 ? void 0 : _this$_getSheetHostCh2.call(_this$_getSheetHostCh));
@@ -31848,6 +31919,9 @@ let SheetContextMenuRenderController = class SheetContextMenuRenderController ex
31848
31919
  _getSheetHostChromeOverrideService() {
31849
31920
  return this._injector.has(ISheetHostChromeOverrideService) ? this._injector.get(ISheetHostChromeOverrideService) : void 0;
31850
31921
  }
31922
+ _getSheetEmbedRuntimeFocusCoordinator() {
31923
+ return this._injector.has(ISheetEmbedRuntimeFocusCoordinator) ? this._injector.get(ISheetEmbedRuntimeFocusCoordinator) : void 0;
31924
+ }
31851
31925
  };
31852
31926
  SheetContextMenuRenderController = __decorate([
31853
31927
  __decorateParam(1, _univerjs_ui.IContextMenuService),
@@ -31855,6 +31929,9 @@ SheetContextMenuRenderController = __decorate([
31855
31929
  __decorateParam(3, ISheetSelectionRenderService),
31856
31930
  __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
31857
31931
  ], SheetContextMenuRenderController);
31932
+ function shouldHideSheetHostContextMenuForEmbedSession(hostUnitId, activeScope) {
31933
+ return (activeScope === null || activeScope === void 0 ? void 0 : activeScope.hostUnitId) === hostUnitId && activeScope.sessionMode !== "host-passive";
31934
+ }
31858
31935
  function shouldSuppressSheetContextMenuForEmbedOverride(hostUnitId, override) {
31859
31936
  return override != null && override.hostUnitId === hostUnitId && override.entry === "sheets-sheet-tab";
31860
31937
  }
@@ -296,8 +296,8 @@ const locale = { "sheets-ui": {
296
296
  allowedPermissionType: "Tipus de permisos permesos",
297
297
  alert: "Alerta",
298
298
  search: "Cercar",
299
- ownerInherit: "Propietario del documento, herencia de permisos habilitada",
300
- ownerWithoutInherit: "Propietario del documento, herencia de permisos no habilitada",
299
+ ownerInherit: "Propietari del document, herència de permisos activada",
300
+ ownerWithoutInherit: "Propietari del document, herència de permisos desactivada",
301
301
  alertContent: "Aquest interval està protegit i actualment no hi ha permisos d'edició disponibles. Si necessiteu editar, contacteu amb el creador.",
302
302
  userEmpty: "cap persona designada, compartiu l'enllaç per convidar persones específiques.",
303
303
  listEmpty: "No heu configurat cap interval o full com a protegit.",
@@ -296,8 +296,8 @@ const locale = { "sheets-ui": {
296
296
  allowedPermissionType: "Povolené typy oprávnení",
297
297
  alert: "Upozornenie",
298
298
  search: "Hľadať",
299
- ownerInherit: "Vlastník dokumentu, dědičnost oprávnění povolena",
300
- ownerWithoutInherit: "Vlastník dokumentu, dědičnost oprávnění není povolena",
299
+ ownerInherit: "Vlastník dokumentu, dedenie oprávnení je povolené",
300
+ ownerWithoutInherit: "Vlastník dokumentu, dedenie oprávnení nie je povolené",
301
301
  alertContent: "Tento rozsah je chránený a momentálne nemáte povolenie na úpravy. Ak potrebujete upravovať, kontaktujte autora.",
302
302
  userEmpty: "žiadna určená osoba, zdieľajte odkaz na pozvanie konkrétnych ľudí.",
303
303
  listEmpty: "Nenastavili ste žiadne rozsahy ani hárky ako chránené.",