@univerjs/sheets-ui 1.0.0-alpha.1 → 1.0.0-alpha.3

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.
Files changed (114) hide show
  1. package/lib/cjs/facade.js +51 -40
  2. package/lib/cjs/index.js +1187 -287
  3. package/lib/cjs/locale/ar-SA.js +7 -2
  4. package/lib/cjs/locale/ca-ES.js +7 -2
  5. package/lib/cjs/locale/de-DE.js +7 -2
  6. package/lib/cjs/locale/en-US.js +5 -0
  7. package/lib/cjs/locale/es-ES.js +8 -3
  8. package/lib/cjs/locale/fa-IR.js +7 -2
  9. package/lib/cjs/locale/fr-FR.js +7 -2
  10. package/lib/cjs/locale/id-ID.js +7 -2
  11. package/lib/cjs/locale/it-IT.js +7 -2
  12. package/lib/cjs/locale/ja-JP.js +5 -0
  13. package/lib/cjs/locale/ko-KR.js +5 -0
  14. package/lib/cjs/locale/pl-PL.js +7 -2
  15. package/lib/cjs/locale/pt-BR.js +7 -2
  16. package/lib/cjs/locale/ru-RU.js +7 -2
  17. package/lib/cjs/locale/sk-SK.js +7 -2
  18. package/lib/cjs/locale/vi-VN.js +7 -2
  19. package/lib/cjs/locale/zh-CN.js +5 -0
  20. package/lib/cjs/locale/zh-HK.js +5 -0
  21. package/lib/cjs/locale/zh-TW.js +5 -0
  22. package/lib/es/facade.js +51 -40
  23. package/lib/es/index.js +1168 -264
  24. package/lib/es/locale/ar-SA.js +7 -2
  25. package/lib/es/locale/ca-ES.js +7 -2
  26. package/lib/es/locale/de-DE.js +7 -2
  27. package/lib/es/locale/en-US.js +5 -0
  28. package/lib/es/locale/es-ES.js +8 -3
  29. package/lib/es/locale/fa-IR.js +7 -2
  30. package/lib/es/locale/fr-FR.js +7 -2
  31. package/lib/es/locale/id-ID.js +7 -2
  32. package/lib/es/locale/it-IT.js +7 -2
  33. package/lib/es/locale/ja-JP.js +5 -0
  34. package/lib/es/locale/ko-KR.js +5 -0
  35. package/lib/es/locale/pl-PL.js +7 -2
  36. package/lib/es/locale/pt-BR.js +7 -2
  37. package/lib/es/locale/ru-RU.js +7 -2
  38. package/lib/es/locale/sk-SK.js +7 -2
  39. package/lib/es/locale/vi-VN.js +7 -2
  40. package/lib/es/locale/zh-CN.js +5 -0
  41. package/lib/es/locale/zh-HK.js +5 -0
  42. package/lib/es/locale/zh-TW.js +5 -0
  43. package/lib/facade.js +51 -40
  44. package/lib/index.css +42 -4
  45. package/lib/index.js +1168 -264
  46. package/lib/locale/ar-SA.js +7 -2
  47. package/lib/locale/ca-ES.js +7 -2
  48. package/lib/locale/de-DE.js +7 -2
  49. package/lib/locale/en-US.js +5 -0
  50. package/lib/locale/es-ES.js +8 -3
  51. package/lib/locale/fa-IR.js +7 -2
  52. package/lib/locale/fr-FR.js +7 -2
  53. package/lib/locale/id-ID.js +7 -2
  54. package/lib/locale/it-IT.js +7 -2
  55. package/lib/locale/ja-JP.js +5 -0
  56. package/lib/locale/ko-KR.js +5 -0
  57. package/lib/locale/pl-PL.js +7 -2
  58. package/lib/locale/pt-BR.js +7 -2
  59. package/lib/locale/ru-RU.js +7 -2
  60. package/lib/locale/sk-SK.js +7 -2
  61. package/lib/locale/vi-VN.js +7 -2
  62. package/lib/locale/zh-CN.js +5 -0
  63. package/lib/locale/zh-HK.js +5 -0
  64. package/lib/locale/zh-TW.js +5 -0
  65. package/lib/types/commands/commands/set-scroll.command.d.ts +3 -0
  66. package/lib/types/controllers/editor/editing.render-controller.d.ts +1 -0
  67. package/lib/types/controllers/editor/formula-editor.controller.d.ts +1 -0
  68. package/lib/types/controllers/render-controllers/contextmenu.render-controller.d.ts +7 -2
  69. package/lib/types/controllers/render-controllers/editor-bridge.render-controller.d.ts +7 -1
  70. package/lib/types/controllers/render-controllers/header-unhide.render-controller.d.ts +0 -1
  71. package/lib/types/embed-tab-anchor.d.ts +23 -0
  72. package/lib/types/facade/f-range.d.ts +5 -4
  73. package/lib/types/facade/f-univer.d.ts +1 -0
  74. package/lib/types/index.d.ts +16 -3
  75. package/lib/types/locale/en-US.d.ts +5 -0
  76. package/lib/types/services/canvas-pop-manager.service.d.ts +9 -0
  77. package/lib/types/services/cell-popup-manager.service.d.ts +1 -0
  78. package/lib/types/services/editor/cell-editor-resize.service.d.ts +4 -1
  79. package/lib/types/services/editor-bridge.service.d.ts +2 -0
  80. package/lib/types/services/print-interceptor.service.d.ts +8 -0
  81. package/lib/types/services/selection/base-selection-render.service.d.ts +1 -0
  82. package/lib/types/services/sheet-embed-integration.service.d.ts +126 -0
  83. package/lib/types/services/sheet-embed-runtime.service.d.ts +26 -0
  84. package/lib/types/services/sheet-host-chrome-override.service.d.ts +25 -0
  85. package/lib/types/services/sheet-skeleton-manager.service.d.ts +2 -0
  86. package/lib/types/views/border-panel/interface.d.ts +63 -2
  87. package/lib/types/views/editor-container/EditorContainer.d.ts +7 -5
  88. package/lib/types/{menu/mobile-menu.d.ts → views/editor-container/EditorContainer.spec.d.ts} +1 -1
  89. package/lib/types/views/editor-container/focus-editor.d.ts +25 -0
  90. package/lib/types/views/sheet-bar/sheet-bar-tabs/SheetBarItem.d.ts +2 -1
  91. package/lib/types/views/sheet-bar/sheet-bar-tabs/utils/sheet-tab-drag-sort.d.ts +1 -0
  92. package/lib/types/views/sheet-bar/sheet-bar-tabs/utils/slide-tab-bar.d.ts +2 -1
  93. package/lib/umd/facade.js +1 -1
  94. package/lib/umd/index.js +12 -12
  95. package/lib/umd/locale/ar-SA.js +1 -1
  96. package/lib/umd/locale/ca-ES.js +1 -1
  97. package/lib/umd/locale/de-DE.js +1 -1
  98. package/lib/umd/locale/en-US.js +1 -1
  99. package/lib/umd/locale/es-ES.js +1 -1
  100. package/lib/umd/locale/fa-IR.js +1 -1
  101. package/lib/umd/locale/fr-FR.js +1 -1
  102. package/lib/umd/locale/id-ID.js +1 -1
  103. package/lib/umd/locale/it-IT.js +1 -1
  104. package/lib/umd/locale/ja-JP.js +1 -1
  105. package/lib/umd/locale/ko-KR.js +1 -1
  106. package/lib/umd/locale/pl-PL.js +1 -1
  107. package/lib/umd/locale/pt-BR.js +1 -1
  108. package/lib/umd/locale/ru-RU.js +1 -1
  109. package/lib/umd/locale/sk-SK.js +1 -1
  110. package/lib/umd/locale/vi-VN.js +1 -1
  111. package/lib/umd/locale/zh-CN.js +1 -1
  112. package/lib/umd/locale/zh-HK.js +1 -1
  113. package/lib/umd/locale/zh-TW.js +1 -1
  114. package/package.json +16 -16
package/lib/cjs/index.js CHANGED
@@ -1,31 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- //#region \0rolldown/runtime.js
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
- key = keys[i];
13
- if (!__hasOwnProp.call(to, key) && key !== except) {
14
- __defProp(to, key, {
15
- get: ((k) => from[k]).bind(null, key),
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
- });
18
- }
19
- }
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
- value: mod,
25
- enumerable: true
26
- }) : target, mod));
27
-
28
- //#endregion
29
2
  let _univerjs_docs_ui = require("@univerjs/docs-ui");
30
3
  let _univerjs_core = require("@univerjs/core");
31
4
  let _univerjs_ui = require("@univerjs/ui");
@@ -37,7 +10,6 @@ let _univerjs_protocol = require("@univerjs/protocol");
37
10
  let _univerjs_design = require("@univerjs/design");
38
11
  let _univerjs_icons = require("@univerjs/icons");
39
12
  let react = require("react");
40
- react = __toESM(react);
41
13
  let react_jsx_runtime = require("react/jsx-runtime");
42
14
  let _univerjs_engine_formula = require("@univerjs/engine-formula");
43
15
  let _univerjs_telemetry = require("@univerjs/telemetry");
@@ -489,6 +461,19 @@ var BaseSelectionRenderService = class extends _univerjs_core.Disposable {
489
461
  this._initSelectionThemeFromThemeService();
490
462
  this._initMoving();
491
463
  }
464
+ dispose() {
465
+ var _this$_escapeShortcut;
466
+ if (this._disposed) return;
467
+ this._clearUpdatingListeners();
468
+ this._reset();
469
+ (_this$_escapeShortcut = this._escapeShortcutDisposable) === null || _this$_escapeShortcut === void 0 || _this$_escapeShortcut.dispose();
470
+ this._escapeShortcutDisposable = null;
471
+ this._controlFillConfig$.complete();
472
+ this._selectionMoveEnd$.complete();
473
+ this._selectionMoving$.complete();
474
+ this._selectionMoveStart$.complete();
475
+ super.dispose();
476
+ }
492
477
  /**
493
478
  * If true, the selector will respond to the range of merged cells and automatically extend the selected range. If false, it will ignore the merged cells.
494
479
  */
@@ -665,10 +650,10 @@ var BaseSelectionRenderService = class extends _univerjs_core.Disposable {
665
650
  }
666
651
  }
667
652
  endSelection() {
668
- var _this$_escapeShortcut;
653
+ var _this$_escapeShortcut2;
669
654
  this._clearUpdatingListeners();
670
655
  this._selectionMoveEnd$.next(this.getSelectionDataWithStyle());
671
- (_this$_escapeShortcut = this._escapeShortcutDisposable) === null || _this$_escapeShortcut === void 0 || _this$_escapeShortcut.dispose();
656
+ (_this$_escapeShortcut2 = this._escapeShortcutDisposable) === null || _this$_escapeShortcut2 === void 0 || _this$_escapeShortcut2.dispose();
672
657
  this._escapeShortcutDisposable = null;
673
658
  }
674
659
  /**
@@ -1116,10 +1101,7 @@ let SheetSkeletonManagerService = class SheetSkeletonManagerService extends _uni
1116
1101
  render.scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM).setViewportSize({ top: size });
1117
1102
  render.scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP).setViewportSize({ top: size });
1118
1103
  render.scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({ height: size });
1119
- const selectionService = render === null || render === void 0 ? void 0 : render.with(_univerjs_sheets.SheetsSelectionsService);
1120
- const selectionRenderService = render === null || render === void 0 ? void 0 : render.with(ISheetSelectionRenderService);
1121
- const currSelections = selectionService.getCurrentSelections();
1122
- selectionRenderService.resetSelectionsByModelData(currSelections);
1104
+ this._resetSelectionsIfAvailable(render);
1123
1105
  const sheetSkeletonManagerParam = this._sheetSkeletonService.getSkeletonParam(render.unitId, sheetId);
1124
1106
  if (sheetSkeletonManagerParam) {
1125
1107
  sheetSkeletonManagerParam.commandId = SetColumnHeaderHeightCommand.id;
@@ -1140,16 +1122,28 @@ let SheetSkeletonManagerService = class SheetSkeletonManagerService extends _uni
1140
1122
  const prevLeft = render.scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).left || 0;
1141
1123
  render.scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT).setViewportSize({ left: prevLeft + deltaX });
1142
1124
  render.scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP).setViewportSize({ width: size });
1143
- const selectionService = render === null || render === void 0 ? void 0 : render.with(_univerjs_sheets.SheetsSelectionsService);
1144
- const selectionRenderService = render === null || render === void 0 ? void 0 : render.with(ISheetSelectionRenderService);
1145
- const currSelections = selectionService.getCurrentSelections();
1146
- selectionRenderService.resetSelectionsByModelData(currSelections);
1125
+ this._resetSelectionsIfAvailable(render);
1147
1126
  const sheetSkeletonManagerParam = this._sheetSkeletonService.getSkeletonParam(render.unitId, sheetId);
1148
1127
  if (sheetSkeletonManagerParam) {
1149
1128
  sheetSkeletonManagerParam.commandId = SetRowHeaderWidthCommand.id;
1150
1129
  this._currentSkeleton$.next(sheetSkeletonManagerParam);
1151
1130
  }
1152
1131
  }
1132
+ _resetSelectionsIfAvailable(render) {
1133
+ const selectionService = this._tryGetRenderDependency(render, _univerjs_sheets.SheetsSelectionsService);
1134
+ const selectionRenderService = this._tryGetRenderDependency(render, ISheetSelectionRenderService);
1135
+ if (!selectionService || !selectionRenderService) return;
1136
+ const currSelections = selectionService.getCurrentSelections();
1137
+ selectionRenderService.resetSelectionsByModelData(currSelections);
1138
+ }
1139
+ _tryGetRenderDependency(render, dependency) {
1140
+ try {
1141
+ return render.with(dependency);
1142
+ } catch (error) {
1143
+ if (error instanceof Error && (error.message.includes("DependencyNotFoundError") || error.message.includes("Cannot find"))) return null;
1144
+ throw error;
1145
+ }
1146
+ }
1153
1147
  };
1154
1148
  SheetSkeletonManagerService = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetSkeletonService))], SheetSkeletonManagerService);
1155
1149
 
@@ -1259,7 +1253,7 @@ var SelectionShapeExtension = class {
1259
1253
  ].forEach((control) => {
1260
1254
  control.onPointerEnter$.subscribeEvent(() => {
1261
1255
  var _this$_injector$get;
1262
- if (((_this$_injector$get = this._injector.get(ISheetSelectionRenderService, _univerjs_core.Quantity.OPTIONAL)) === null || _this$_injector$get === void 0 ? void 0 : _this$_injector$get.interceptor.fetchThroughInterceptors(RANGE_MOVE_PERMISSION_CHECK)(false, null)) === false) return;
1256
+ if (((_this$_injector$get = this._injector.get(ISheetSelectionRenderService, _univerjs_core.Quantity.OPTIONAL, _univerjs_core.LookUp.SELF)) === null || _this$_injector$get === void 0 ? void 0 : _this$_injector$get.interceptor.fetchThroughInterceptors(RANGE_MOVE_PERMISSION_CHECK)(false, null)) === false) return;
1263
1257
  control.setCursor(_univerjs_engine_render.CURSOR_TYPE.MOVE);
1264
1258
  });
1265
1259
  control.onPointerLeave$.subscribeEvent(() => {
@@ -1364,7 +1358,7 @@ var SelectionShapeExtension = class {
1364
1358
  var _this$_injector$get2;
1365
1359
  if (this._disabled) return;
1366
1360
  const { offsetX: moveOffsetX, offsetY: moveOffsetY } = moveEvt;
1367
- if (((_this$_injector$get2 = this._injector.get(ISheetSelectionRenderService, _univerjs_core.Quantity.OPTIONAL)) === null || _this$_injector$get2 === void 0 ? void 0 : _this$_injector$get2.interceptor.fetchThroughInterceptors(RANGE_MOVE_PERMISSION_CHECK)(false, null)) === false) return;
1361
+ if (((_this$_injector$get2 = this._injector.get(ISheetSelectionRenderService, _univerjs_core.Quantity.OPTIONAL, _univerjs_core.LookUp.SELF)) === null || _this$_injector$get2 === void 0 ? void 0 : _this$_injector$get2.interceptor.fetchThroughInterceptors(RANGE_MOVE_PERMISSION_CHECK)(false, null)) === false) return;
1368
1362
  const { x: newMoveOffsetX, y: newMoveOffsetY } = scene.getCoordRelativeToViewport(_univerjs_engine_render.Vector2.FromArray([moveOffsetX, moveOffsetY]));
1369
1363
  this._controlMoving(newMoveOffsetX, newMoveOffsetY);
1370
1364
  scene.setCursor(_univerjs_engine_render.CURSOR_TYPE.MOVE);
@@ -1529,7 +1523,7 @@ var SelectionShapeExtension = class {
1529
1523
  _initialAutoFill() {
1530
1524
  const { fillControl } = this._control;
1531
1525
  fillControl.onPointerEnter$.subscribeEvent((evt) => {
1532
- if (!this._injector.get(ISheetSelectionRenderService).interceptor.fetchThroughInterceptors(RANGE_FILL_PERMISSION_CHECK)(false, {
1526
+ if (!this._injector.get(ISheetSelectionRenderService, _univerjs_core.LookUp.SELF).interceptor.fetchThroughInterceptors(RANGE_FILL_PERMISSION_CHECK)(false, {
1533
1527
  x: evt.offsetX,
1534
1528
  y: evt.offsetY,
1535
1529
  skeleton: this._skeleton,
@@ -1660,7 +1654,7 @@ var SelectionShapeExtension = class {
1660
1654
  var _this$_activeViewport;
1661
1655
  const { offsetX: moveOffsetX, offsetY: moveOffsetY } = moveEvt;
1662
1656
  const currentViewport = scene.getActiveViewportByCoord(_univerjs_engine_render.Vector2.FromArray([moveOffsetX, moveOffsetY]));
1663
- if (!this._injector.get(ISheetSelectionRenderService).interceptor.fetchThroughInterceptors(RANGE_FILL_PERMISSION_CHECK)(false, {
1657
+ if (!this._injector.get(ISheetSelectionRenderService, _univerjs_core.LookUp.SELF).interceptor.fetchThroughInterceptors(RANGE_FILL_PERMISSION_CHECK)(false, {
1664
1658
  x: evt.offsetX,
1665
1659
  y: evt.offsetY,
1666
1660
  skeleton: this._skeleton,
@@ -7329,12 +7323,14 @@ let SheetsScrollRenderController = class SheetsScrollRenderController extends _u
7329
7323
  this.disposeWithMe(viewportMain.onScrollByBar$.subscribeEvent((param) => {
7330
7324
  var _this$_sheetSkeletonM3;
7331
7325
  const skeleton = (_this$_sheetSkeletonM3 = this._sheetSkeletonManagerService.getCurrentParam()) === null || _this$_sheetSkeletonM3 === void 0 ? void 0 : _this$_sheetSkeletonM3.skeleton;
7332
- if (skeleton == null || param.isTrigger === false) return;
7326
+ if (skeleton == null || param.isTrigger === false || param.isBarDragging && !param.isBarDragEnd) return;
7333
7327
  const sheetObject = this._getSheetObject();
7334
7328
  if (skeleton == null || sheetObject == null) return;
7335
7329
  const { viewportScrollX = 0, viewportScrollY = 0 } = param;
7336
7330
  const { row, column, rowOffset, columnOffset } = skeleton.getOffsetRelativeToRowCol(viewportScrollX, viewportScrollY);
7337
7331
  this._commandService.executeCommand(ScrollCommand.id, {
7332
+ unitId: this._context.unitId,
7333
+ sheetId: skeleton.getLocation()[1],
7338
7334
  sheetViewStartRow: row,
7339
7335
  sheetViewStartColumn: column,
7340
7336
  offsetX: columnOffset,
@@ -7422,8 +7418,11 @@ let SheetsScrollRenderController = class SheetsScrollRenderController extends _u
7422
7418
  * @returns {boolean} - true if scroll is successful
7423
7419
  */
7424
7420
  scrollToCell(row, column, duration) {
7425
- const { ySplit: freezeYSplit, xSplit: freezeXSplit } = this._context.unit.getActiveSheet().getFreeze();
7421
+ const worksheet = this._context.unit.getActiveSheet();
7422
+ const { ySplit: freezeYSplit, xSplit: freezeXSplit } = worksheet.getFreeze();
7426
7423
  return this._commandService.syncExecuteCommand(ScrollCommand.id, {
7424
+ unitId: this._context.unitId,
7425
+ sheetId: worksheet.getSheetId(),
7427
7426
  sheetViewStartRow: row - freezeYSplit,
7428
7427
  sheetViewStartColumn: column - freezeXSplit,
7429
7428
  offsetX: 0,
@@ -7596,6 +7595,8 @@ let SheetsScrollRenderController = class SheetsScrollRenderController extends _u
7596
7595
  startSheetViewRow = startSheetViewRow - hiddenRows.length;
7597
7596
  }
7598
7597
  return this._commandService.syncExecuteCommand(ScrollCommand.id, {
7598
+ unitId: this._context.unitId,
7599
+ sheetId: worksheet.getSheetId(),
7599
7600
  sheetViewStartRow: Math.max(0, startSheetViewRow - freezedRowCount),
7600
7601
  sheetViewStartColumn: Math.max(0, startSheetViewColumn - freezedColCount),
7601
7602
  offsetX,
@@ -7684,10 +7685,12 @@ const ScrollCommand = {
7684
7685
  if (!params) return false;
7685
7686
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
7686
7687
  const renderManagerSrv = accessor.get(_univerjs_engine_render.IRenderManagerService);
7687
- const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService);
7688
+ const target = params.unitId ? getScrollCommandTargetByParams(univerInstanceService, params) : (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService);
7688
7689
  if (!target) return false;
7689
7690
  const { workbook, worksheet, unitId } = target;
7690
- const currentScroll = renderManagerSrv.getRenderById(unitId).with(SheetScrollManagerService).getCurrentScrollState();
7691
+ const renderUnit = renderManagerSrv.getRenderById(unitId);
7692
+ if (!renderUnit) return false;
7693
+ const currentScroll = renderUnit.with(SheetScrollManagerService).getCurrentScrollState();
7691
7694
  if (!worksheet) return false;
7692
7695
  const { sheetViewStartRow, sheetViewStartColumn, offsetX, offsetY, duration } = params;
7693
7696
  const { sheetViewStartColumn: currentColumn, sheetViewStartRow: currentRow, offsetX: currentOffsetX, offsetY: currentOffsetY } = currentScroll || {};
@@ -7703,6 +7706,18 @@ const ScrollCommand = {
7703
7706
  });
7704
7707
  }
7705
7708
  };
7709
+ function getScrollCommandTargetByParams(univerInstanceService, params) {
7710
+ if (!params.unitId) return null;
7711
+ const workbook = univerInstanceService.getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
7712
+ const worksheet = params.sheetId ? workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(params.sheetId) : workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
7713
+ if (!workbook || !worksheet) return null;
7714
+ return {
7715
+ workbook,
7716
+ worksheet,
7717
+ unitId: params.unitId,
7718
+ subUnitId: worksheet.getSheetId()
7719
+ };
7720
+ }
7706
7721
  /**
7707
7722
  * The command is used to scroll to the specific cell if the target cell is not in the viewport.
7708
7723
  */
@@ -7898,7 +7913,7 @@ let EditorBridgeService = class EditorBridgeService extends _univerjs_core.Dispo
7898
7913
  refreshEditCellPosition(resetSizeOnly) {
7899
7914
  if (!this._currentEditCell || !this._currentEditCellState) return;
7900
7915
  const { unitId, sheetId, primary, scene, engine } = this._currentEditCell;
7901
- const workbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
7916
+ const workbook = this._getWorkbookForEditUnit(unitId);
7902
7917
  if (!workbook || workbook.getUnitId() !== unitId) return;
7903
7918
  const worksheet = workbook.getActiveSheet();
7904
7919
  if (!worksheet || worksheet.getSheetId() !== sheetId) return;
@@ -7997,7 +8012,7 @@ let EditorBridgeService = class EditorBridgeService extends _univerjs_core.Dispo
7997
8012
  var _documentLayoutObject, _documentLayoutObject2;
7998
8013
  if (!this._currentEditCell) return;
7999
8014
  const { unitId, sheetId, primary, scene, engine } = this._currentEditCell;
8000
- const workbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
8015
+ const workbook = this._getWorkbookForEditUnit(unitId);
8001
8016
  if (!workbook || workbook.getUnitId() !== unitId) return;
8002
8017
  const worksheet = workbook.getActiveSheet();
8003
8018
  if (!worksheet || worksheet.getSheetId() !== sheetId) return;
@@ -8075,6 +8090,10 @@ let EditorBridgeService = class EditorBridgeService extends _univerjs_core.Dispo
8075
8090
  isInArrayFormulaRange: cell === null || cell === void 0 ? void 0 : cell.isInArrayFormulaRange
8076
8091
  };
8077
8092
  }
8093
+ _getWorkbookForEditUnit(unitId) {
8094
+ var _this$_univerInstance;
8095
+ return (_this$_univerInstance = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) !== null && _this$_univerInstance !== void 0 ? _this$_univerInstance : this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
8096
+ }
8078
8097
  getCurrentEditorId() {
8079
8098
  return this._editorUnitId;
8080
8099
  }
@@ -8453,9 +8472,15 @@ const ScrollToRangeOperation = {
8453
8472
  id: "sheet.operation.scroll-to-range",
8454
8473
  type: _univerjs_core.CommandType.OPERATION,
8455
8474
  handler: (accessor, params) => {
8475
+ var _params$unitId, _instanceService$getC;
8456
8476
  if (!params) return false;
8457
8477
  const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
8458
- return accessor.get(_univerjs_engine_render.IRenderManagerService).getRenderById(instanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(SheetsScrollRenderController).scrollToRange(params.range, params.forceTop, params.forceLeft);
8478
+ const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
8479
+ const unitId = (_params$unitId = params.unitId) !== null && _params$unitId !== void 0 ? _params$unitId : (_instanceService$getC = instanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _instanceService$getC === void 0 ? void 0 : _instanceService$getC.getUnitId();
8480
+ if (!unitId) return false;
8481
+ const renderUnit = renderManagerService.getRenderById(unitId);
8482
+ if (!renderUnit) return false;
8483
+ return renderUnit.with(SheetsScrollRenderController).scrollToRange(params.range, params.forceTop, params.forceLeft);
8459
8484
  }
8460
8485
  };
8461
8486
 
@@ -8767,18 +8792,19 @@ let SheetsRenderService = class SheetsRenderService extends _univerjs_core.RxDis
8767
8792
  }
8768
8793
  _initWorkbookListener() {
8769
8794
  this._instanceSrv.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((event) => this._createRenderer(event.unit, event.options));
8770
- this._instanceSrv.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).forEach((workbook) => this._createRenderer(workbook));
8795
+ this._instanceSrv.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).forEach((workbook) => {
8796
+ var _this$_instanceSrv$ge;
8797
+ return this._createRenderer(workbook, (_this$_instanceSrv$ge = this._instanceSrv.getUnitCreateOptions(workbook.getUnitId())) !== null && _this$_instanceSrv$ge !== void 0 ? _this$_instanceSrv$ge : void 0);
8798
+ });
8771
8799
  this._instanceSrv.getTypeOfUnitDisposed$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((workbook) => this._disposeRenderer(workbook));
8772
8800
  }
8773
8801
  _createRenderer(workbook, createUnitOptions) {
8802
+ if (createUnitOptions === null || createUnitOptions === void 0 ? void 0 : createUnitOptions.skipAutoRender) return;
8774
8803
  const unitId = workbook.getUnitId();
8775
- this._renderManagerService.created$.subscribe((renderer) => {
8776
- if (renderer.unitId === unitId) {
8777
- renderer.engine.getCanvas().setId(`${SHEET_MAIN_CANVAS_ID}_${unitId}`);
8778
- renderer.engine.getCanvas().getContext().setId(`${SHEET_MAIN_CANVAS_ID}_${unitId}`);
8779
- }
8780
- });
8781
- this._renderManagerService.createRender(unitId, createUnitOptions);
8804
+ const canvas = this._renderManagerService.createRender(unitId, createUnitOptions).engine.getCanvas();
8805
+ canvas.setId(`${SHEET_MAIN_CANVAS_ID}_${unitId}`);
8806
+ canvas.getCanvasEle().dataset.uUnitId = unitId;
8807
+ canvas.getContext().setId(`${SHEET_MAIN_CANVAS_ID}_${unitId}`);
8782
8808
  }
8783
8809
  _disposeRenderer(workbook) {
8784
8810
  const unitId = workbook.getUnitId();
@@ -8873,11 +8899,28 @@ let AutoFillUIController = class AutoFillUIController extends _univerjs_core.Dis
8873
8899
  }
8874
8900
  _initSelectionControlFillChanged() {
8875
8901
  const disposableCollection = new _univerjs_core.DisposableCollection();
8902
+ let pendingRetry = false;
8903
+ let retryCount = 0;
8904
+ const scheduleUpdateListener = (listener) => {
8905
+ if (pendingRetry) return;
8906
+ pendingRetry = true;
8907
+ setTimeout(() => {
8908
+ pendingRetry = false;
8909
+ listener();
8910
+ }, 0);
8911
+ };
8876
8912
  const updateListener = () => {
8877
8913
  disposableCollection.dispose();
8878
8914
  const currentRenderer = (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_SHEET, this._univerInstanceService, this._renderManagerService);
8879
8915
  if (!currentRenderer) return;
8880
- currentRenderer.with(ISheetSelectionRenderService).getSelectionControls().forEach((controlSelection) => {
8916
+ const selectionRenderService = getResolvedSelectionRenderService(currentRenderer);
8917
+ if (!selectionRenderService) {
8918
+ retryCount += 1;
8919
+ if (retryCount <= 3) scheduleUpdateListener(updateListener);
8920
+ return;
8921
+ }
8922
+ retryCount = 0;
8923
+ selectionRenderService.getSelectionControls().forEach((controlSelection) => {
8881
8924
  disposableCollection.add(controlSelection.selectionFilled$.subscribe((filled) => {
8882
8925
  if (filled == null || filled.startColumn === -1 || filled.startRow === -1 || filled.endColumn === -1 || filled.endRow === -1) return;
8883
8926
  const source = {
@@ -8915,11 +8958,11 @@ let AutoFillUIController = class AutoFillUIController extends _univerjs_core.Dis
8915
8958
  }));
8916
8959
  });
8917
8960
  };
8918
- updateListener();
8961
+ scheduleUpdateListener(updateListener);
8919
8962
  this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
8920
- if (command.id === _univerjs_sheets.SetSelectionsOperation.id) updateListener();
8963
+ if (command.id === _univerjs_sheets.SetSelectionsOperation.id) scheduleUpdateListener(updateListener);
8921
8964
  }));
8922
- this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe(() => updateListener()));
8965
+ this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe(() => scheduleUpdateListener(updateListener)));
8923
8966
  }
8924
8967
  _handleDbClickFill(source) {
8925
8968
  const selection = this._detectFillRange(source);
@@ -8969,6 +9012,13 @@ AutoFillUIController = __decorate([
8969
9012
  __decorateParam(5, _univerjs_engine_render.IRenderManagerService),
8970
9013
  __decorateParam(6, (0, _univerjs_core.Inject)(SheetsRenderService))
8971
9014
  ], AutoFillUIController);
9015
+ function getResolvedSelectionRenderService(renderer) {
9016
+ var _getInjector, _resolvedDependencyCo;
9017
+ const injector = (_getInjector = renderer.getInjector) === null || _getInjector === void 0 ? void 0 : _getInjector.call(renderer);
9018
+ const resolvedDependencies = injector === null || injector === void 0 || (_resolvedDependencyCo = injector.resolvedDependencyCollection) === null || _resolvedDependencyCo === void 0 ? void 0 : _resolvedDependencyCo.resolvedDependencies;
9019
+ if (!resolvedDependencies) return;
9020
+ for (const [identifier, values] of resolvedDependencies) if (identifier.decoratorName === ISheetSelectionRenderService.decoratorName) return values.length === 1 ? values[0] : void 0;
9021
+ }
8972
9022
 
8973
9023
  //#endregion
8974
9024
  //#region src/controllers/auto-height.controller.ts
@@ -9421,12 +9471,60 @@ var CellEditorManagerService = class {
9421
9471
  };
9422
9472
  const ICellEditorManagerService = (0, _univerjs_core.createIdentifier)("univer.sheet-cell-editor-manager.service");
9423
9473
 
9474
+ //#endregion
9475
+ //#region src/services/sheet-embed-integration.service.ts
9476
+ const SHEET_EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE = "data-embed-interaction-boundary-owner";
9477
+ const SHEET_EMBED_RUNTIME_FOCUS_ROLE_ATTRIBUTE = "data-embed-runtime-focus-role";
9478
+ const SHEET_EMBED_FLOAT_DOM_ATTRIBUTE = "data-embed-float-dom";
9479
+ const SHEET_EMBED_ID_ATTRIBUTE = "data-embed-id";
9480
+ const SHEET_EMBED_HOST_UNIT_ID_ATTRIBUTE = "data-embed-host-unit-id";
9481
+ const SHEET_EMBED_CHILD_UNIT_ID_ATTRIBUTE = "data-embed-child-unit-id";
9482
+ const SHEET_EMBED_CHILD_TYPE_ATTRIBUTE = "data-embed-child-type";
9483
+ const ISheetEmbedInteractionBoundaryService = (0, _univerjs_core.createIdentifier)("sheets-ui.embed-interaction-boundary.service");
9484
+ const ISheetEmbedRuntimeFocusCoordinator = (0, _univerjs_core.createIdentifier)("sheets-ui.embed-runtime-focus-coordinator");
9485
+ const ISheetEmbedFloatingGeometryService = (0, _univerjs_core.createIdentifier)("sheets-ui.embed-floating-geometry.service");
9486
+ function resolveSheetEmbedRuntimeDomScope(element) {
9487
+ var _element$closest$getA, _element$closest, _container$getAttribu, _container$getAttribu2, _container$getAttribu3;
9488
+ if (!element) return;
9489
+ const embedId = (_element$closest$getA = (_element$closest = element.closest(`[${"data-embed-interaction-boundary-owner"}]`)) === null || _element$closest === void 0 ? void 0 : _element$closest.getAttribute("data-embed-interaction-boundary-owner")) !== null && _element$closest$getA !== void 0 ? _element$closest$getA : void 0;
9490
+ const container = resolveSheetEmbedFloatDomContainer(element, embedId);
9491
+ const resolvedEmbedId = (_container$getAttribu = container === null || container === void 0 ? void 0 : container.getAttribute("data-embed-id")) !== null && _container$getAttribu !== void 0 ? _container$getAttribu : embedId;
9492
+ if (!resolvedEmbedId) return;
9493
+ return {
9494
+ embedId: resolvedEmbedId,
9495
+ hostUnitId: (_container$getAttribu2 = container === null || container === void 0 ? void 0 : container.getAttribute("data-embed-host-unit-id")) !== null && _container$getAttribu2 !== void 0 ? _container$getAttribu2 : void 0,
9496
+ childUnitId: (_container$getAttribu3 = container === null || container === void 0 ? void 0 : container.getAttribute("data-embed-child-unit-id")) !== null && _container$getAttribu3 !== void 0 ? _container$getAttribu3 : void 0,
9497
+ childType: readChildType(container)
9498
+ };
9499
+ }
9500
+ function resolveActiveSheetEmbedRuntimeDomScope(ownerDocument = document) {
9501
+ const activeContainer = ownerDocument.querySelector(`[${SHEET_EMBED_FLOAT_DOM_ATTRIBUTE}="true"][data-embed-float-stage="stage2"]`);
9502
+ if (!activeContainer) return;
9503
+ return resolveSheetEmbedRuntimeDomScope(activeContainer);
9504
+ }
9505
+ function resolveSheetEmbedFloatDomContainer(element, embedId) {
9506
+ var _element$ownerDocumen, _ownerDocument$queryS;
9507
+ const ownContainer = element === null || element === void 0 ? void 0 : element.closest(`[${SHEET_EMBED_FLOAT_DOM_ATTRIBUTE}="true"]`);
9508
+ if (ownContainer && (!embedId || ownContainer.getAttribute("data-embed-id") === embedId)) return ownContainer;
9509
+ const ownerDocument = (_element$ownerDocumen = element === null || element === void 0 ? void 0 : element.ownerDocument) !== null && _element$ownerDocumen !== void 0 ? _element$ownerDocumen : typeof document === "undefined" ? void 0 : document;
9510
+ if (!ownerDocument || !embedId) return ownContainer !== null && ownContainer !== void 0 ? ownContainer : void 0;
9511
+ return (_ownerDocument$queryS = ownerDocument.querySelector(`[${"data-embed-float-dom"}="true"][${"data-embed-id"}="${escapeAttributeValue(embedId)}"]`)) !== null && _ownerDocument$queryS !== void 0 ? _ownerDocument$queryS : void 0;
9512
+ }
9513
+ function escapeAttributeValue(value) {
9514
+ return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
9515
+ }
9516
+ function readChildType(container) {
9517
+ const value = container === null || container === void 0 ? void 0 : container.getAttribute(SHEET_EMBED_CHILD_TYPE_ATTRIBUTE);
9518
+ if (value == null || value === "") return;
9519
+ return Number(value);
9520
+ }
9521
+
9424
9522
  //#endregion
9425
9523
  //#region src/services/editor/cell-editor-resize.service.ts
9426
9524
  const EDITOR_INPUT_SELF_EXTEND_GAP = 5;
9427
9525
  const EDITOR_BORDER_SIZE = 2;
9428
9526
  let SheetCellEditorResizeService = class SheetCellEditorResizeService extends _univerjs_core.Disposable {
9429
- constructor(_layoutService, _cellEditorManagerService, _editorBridgeService, _renderManagerService, _univerInstanceService, _configService) {
9527
+ constructor(_layoutService, _cellEditorManagerService, _editorBridgeService, _renderManagerService, _univerInstanceService, _configService, _embedFloatingGeometryService) {
9430
9528
  super();
9431
9529
  this._layoutService = _layoutService;
9432
9530
  this._cellEditorManagerService = _cellEditorManagerService;
@@ -9434,6 +9532,7 @@ let SheetCellEditorResizeService = class SheetCellEditorResizeService extends _u
9434
9532
  this._renderManagerService = _renderManagerService;
9435
9533
  this._univerInstanceService = _univerInstanceService;
9436
9534
  this._configService = _configService;
9535
+ this._embedFloatingGeometryService = _embedFloatingGeometryService;
9437
9536
  }
9438
9537
  get _currentRenderer() {
9439
9538
  return (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_SHEET, this._univerInstanceService, this._renderManagerService);
@@ -9446,9 +9545,8 @@ let SheetCellEditorResizeService = class SheetCellEditorResizeService extends _u
9446
9545
  return this._renderManagerService.getRenderById(this._editingUnitId);
9447
9546
  }
9448
9547
  get _renderer() {
9449
- var _this$_univerInstance;
9450
- const currentUnitId = (_this$_univerInstance = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getUnitId();
9451
- return this._editingUnitId === currentUnitId ? this._editingRenderer : this._currentRenderer;
9548
+ var _this$_editingRendere;
9549
+ return (_this$_editingRendere = this._editingRenderer) !== null && _this$_editingRendere !== void 0 ? _this$_editingRendere : this._currentRenderer;
9452
9550
  }
9453
9551
  get _sheetSkeletonManagerService() {
9454
9552
  var _this$_renderer;
@@ -9552,13 +9650,14 @@ let SheetCellEditorResizeService = class SheetCellEditorResizeService extends _u
9552
9650
  const { startX, startY, endX } = position;
9553
9651
  const enginWidth = engine.width;
9554
9652
  const maxHeight = height - startY - EDITOR_BORDER_SIZE * 2;
9653
+ const cellWidth = endX - startX;
9555
9654
  let maxWidth = width - startX;
9556
9655
  if (horizontalAlign === _univerjs_core.HorizontalAlign.CENTER) {
9557
9656
  const rightGap = enginWidth - endX;
9558
- const leftGap = startX;
9559
- maxWidth = endX - startX + Math.min(leftGap, rightGap) * 2;
9657
+ maxWidth = cellWidth + Math.min(startX, rightGap) * 2;
9560
9658
  } else if (horizontalAlign === _univerjs_core.HorizontalAlign.RIGHT) maxWidth = endX;
9561
9659
  maxWidth = maxWidth - EDITOR_BORDER_SIZE * 2;
9660
+ maxWidth = Math.max(maxWidth, cellWidth);
9562
9661
  return {
9563
9662
  height: maxHeight,
9564
9663
  width: maxWidth,
@@ -9615,7 +9714,7 @@ let SheetCellEditorResizeService = class SheetCellEditorResizeService extends _u
9615
9714
  docEngine.resizeBySize((0, _univerjs_engine_render.fixLineWidthByScale)(editorWidth, precisionScaleX), (0, _univerjs_engine_render.fixLineWidthByScale)(physicHeight, precisionScaleY));
9616
9715
  callback === null || callback === void 0 || callback();
9617
9716
  }, 0);
9618
- const contentBoundingRect = this._layoutService.getContentElement().getBoundingClientRect();
9717
+ const contentBoundingRect = this._getEditorContentElement().getBoundingClientRect();
9619
9718
  const canvasBoundingRect = canvasElement.getBoundingClientRect();
9620
9719
  startX = startX * scaleAdjust + (canvasBoundingRect.left - contentBoundingRect.left);
9621
9720
  startY = startY * scaleAdjust + (canvasBoundingRect.top - contentBoundingRect.top);
@@ -9630,6 +9729,10 @@ let SheetCellEditorResizeService = class SheetCellEditorResizeService extends _u
9630
9729
  show: true
9631
9730
  });
9632
9731
  }
9732
+ _getEditorContentElement() {
9733
+ var _this$_embedFloatingG, _this$_embedFloatingG2;
9734
+ return (_this$_embedFloatingG = (_this$_embedFloatingG2 = this._embedFloatingGeometryService) === null || _this$_embedFloatingG2 === void 0 || (_this$_embedFloatingG2 = _this$_embedFloatingG2.getRegistrationByChildUnitId(this._editingUnitId)) === null || _this$_embedFloatingG2 === void 0 ? void 0 : _this$_embedFloatingG2.contentRoot) !== null && _this$_embedFloatingG !== void 0 ? _this$_embedFloatingG : this._layoutService.getContentElement();
9735
+ }
9633
9736
  /**
9634
9737
  * Since the document does not support cell background color, an additional rect needs to be added.
9635
9738
  */
@@ -9692,13 +9795,14 @@ SheetCellEditorResizeService = __decorate([
9692
9795
  __decorateParam(2, IEditorBridgeService),
9693
9796
  __decorateParam(3, _univerjs_engine_render.IRenderManagerService),
9694
9797
  __decorateParam(4, _univerjs_core.IUniverInstanceService),
9695
- __decorateParam(5, _univerjs_core.IConfigService)
9798
+ __decorateParam(5, _univerjs_core.IConfigService),
9799
+ __decorateParam(6, (0, _univerjs_core.Optional)(ISheetEmbedFloatingGeometryService))
9696
9800
  ], SheetCellEditorResizeService);
9697
9801
 
9698
9802
  //#endregion
9699
9803
  //#region src/controllers/render-controllers/editor-bridge.render-controller.ts
9700
9804
  let EditorBridgeRenderController = class EditorBridgeRenderController extends _univerjs_core.RxDisposable {
9701
- constructor(_context, _instanceSrv, _commandService, _editorBridgeService, _selectionManagerService, _contextService, _renderManagerService, _sheetSkeletonManagerService) {
9805
+ constructor(_context, _instanceSrv, _commandService, _editorBridgeService, _selectionManagerService, _contextService, _renderManagerService, _sheetSkeletonManagerService, _embedRuntimeFocusCoordinator) {
9702
9806
  super();
9703
9807
  this._context = _context;
9704
9808
  this._instanceSrv = _instanceSrv;
@@ -9708,10 +9812,13 @@ let EditorBridgeRenderController = class EditorBridgeRenderController extends _u
9708
9812
  this._contextService = _contextService;
9709
9813
  this._renderManagerService = _renderManagerService;
9710
9814
  this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
9815
+ this._embedRuntimeFocusCoordinator = _embedRuntimeFocusCoordinator;
9711
9816
  _defineProperty(this, "_d", void 0);
9712
9817
  this.disposeWithMe(this._instanceSrv.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
9713
- if (workbook && workbook.getUnitId() === this._context.unitId) this._d = this._init();
9714
- else this._disposeCurrent();
9818
+ if (workbook && workbook.getUnitId() === this._context.unitId) {
9819
+ if (this._d) return;
9820
+ this._d = this._init();
9821
+ } else this._disposeCurrent();
9715
9822
  }));
9716
9823
  }
9717
9824
  _init() {
@@ -9720,6 +9827,7 @@ let EditorBridgeRenderController = class EditorBridgeRenderController extends _u
9720
9827
  this._initEventListener(d);
9721
9828
  this._commandExecutedListener(d);
9722
9829
  this._initialKeyboardListener(d);
9830
+ this._initSheetFocusListener(d);
9723
9831
  return d;
9724
9832
  }
9725
9833
  _disposeCurrent() {
@@ -9736,7 +9844,9 @@ let EditorBridgeRenderController = class EditorBridgeRenderController extends _u
9736
9844
  const primary = params === null || params === void 0 || (_params = params[params.length - 1]) === null || _params === void 0 ? void 0 : _params.primary;
9737
9845
  if (primary) {
9738
9846
  var _this$_context$unit$g, _this$_sheetSkeletonM;
9739
- const { scene, engine } = this._getSheetObject();
9847
+ const sheetObject = this._getSheetObject();
9848
+ if (!sheetObject) return;
9849
+ const { scene, engine } = sheetObject;
9740
9850
  const unitId = this._context.unitId;
9741
9851
  const sheetId = (_this$_context$unit$g = this._context.unit.getActiveSheet()) === null || _this$_context$unit$g === void 0 ? void 0 : _this$_context$unit$g.getSheetId();
9742
9852
  if (!sheetId) return;
@@ -9751,6 +9861,7 @@ let EditorBridgeRenderController = class EditorBridgeRenderController extends _u
9751
9861
  endColumn: mergeInfo.mergeInfo.endColumn,
9752
9862
  isMergedMainCell: mergeInfo.isMergedMainCell
9753
9863
  } : primary;
9864
+ if (isSameEditCell(this._editorBridgeService.getEditLocation(), unitId, sheetId, newPrimary)) return;
9754
9865
  this._commandService.executeCommand(SetActivateCellEditOperation.id, {
9755
9866
  scene,
9756
9867
  engine,
@@ -9768,7 +9879,9 @@ let EditorBridgeRenderController = class EditorBridgeRenderController extends _u
9768
9879
  }
9769
9880
  }
9770
9881
  _initEventListener(d) {
9771
- const { spreadsheet, spreadsheetColumnHeader, spreadsheetLeftTopPlaceholder, spreadsheetRowHeader } = this._getSheetObject();
9882
+ const sheetObject = this._getSheetObject();
9883
+ if (!sheetObject) return;
9884
+ const { spreadsheet, spreadsheetColumnHeader, spreadsheetLeftTopPlaceholder, spreadsheetRowHeader } = sheetObject;
9772
9885
  d.add(spreadsheet.onDblclick$.subscribeEvent((evt) => {
9773
9886
  if (evt.button === 2) return;
9774
9887
  this._commandService.executeCommand(SetCellEditVisibleOperation.id, {
@@ -9778,19 +9891,19 @@ let EditorBridgeRenderController = class EditorBridgeRenderController extends _u
9778
9891
  });
9779
9892
  }));
9780
9893
  d.add(spreadsheet.onPointerDown$.subscribeEvent({
9781
- next: this._tryHideEditor.bind(this),
9894
+ next: (payload) => this._tryHideEditor(resolvePointerEventPayload(payload)),
9782
9895
  priority: -1
9783
9896
  }));
9784
9897
  d.add(spreadsheetColumnHeader.onPointerDown$.subscribeEvent({
9785
- next: this._tryHideEditor.bind(this),
9898
+ next: (payload) => this._tryHideEditor(resolvePointerEventPayload(payload)),
9786
9899
  priority: -1
9787
9900
  }));
9788
9901
  d.add(spreadsheetLeftTopPlaceholder.onPointerDown$.subscribeEvent({
9789
- next: this._tryHideEditor.bind(this),
9902
+ next: (payload) => this._tryHideEditor(resolvePointerEventPayload(payload)),
9790
9903
  priority: -1
9791
9904
  }));
9792
9905
  d.add(spreadsheetRowHeader.onPointerDown$.subscribeEvent({
9793
- next: this._tryHideEditor.bind(this),
9906
+ next: (payload) => this._tryHideEditor(resolvePointerEventPayload(payload)),
9794
9907
  priority: -1
9795
9908
  }));
9796
9909
  }
@@ -9804,9 +9917,10 @@ let EditorBridgeRenderController = class EditorBridgeRenderController extends _u
9804
9917
  const docSelectionRenderService = render.with(_univerjs_docs_ui.DocSelectionRenderService);
9805
9918
  if (docSelectionRenderService) {
9806
9919
  disposable = (0, _univerjs_core.toDisposable)(docSelectionRenderService.onInputBefore$.subscribe((config) => {
9920
+ var _this$_embedRuntimeFo;
9807
9921
  if (!this._isCurrentSheetFocused()) return;
9808
9922
  const isFocusFormulaEditor = this._contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR);
9809
- const isFocusSheets = this._contextService.getContextValue(_univerjs_core.FOCUSING_SHEET);
9923
+ 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;
9810
9924
  const unitId = render.unitId;
9811
9925
  if (this._editorBridgeService.isVisible().visible) return;
9812
9926
  if (unitId && isFocusSheets && !isFocusFormulaEditor) this._showEditorByKeyboard(config);
@@ -9821,6 +9935,17 @@ let EditorBridgeRenderController = class EditorBridgeRenderController extends _u
9821
9935
  addEvent(render);
9822
9936
  }));
9823
9937
  }
9938
+ _initSheetFocusListener(d) {
9939
+ d.add(this._contextService.subscribeContextValue$(_univerjs_core.FOCUSING_SHEET).subscribe((isFocusingSheet) => {
9940
+ if (!isFocusingSheet || !this._isCurrentSheetFocused() || this._contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR) || this._editorBridgeService.isVisible().visible) return;
9941
+ this._focusCellEditorInput();
9942
+ }));
9943
+ }
9944
+ _focusCellEditorInput() {
9945
+ const render = this._renderManagerService.getRenderById(_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
9946
+ const docSelectionRenderService = render === null || render === void 0 ? void 0 : render.with(_univerjs_docs_ui.DocSelectionRenderService);
9947
+ if (!(docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing)) docSelectionRenderService === null || docSelectionRenderService === void 0 || docSelectionRenderService.focus();
9948
+ }
9824
9949
  _commandExecutedListener(d) {
9825
9950
  const refreshCommandSet = /* @__PURE__ */ new Set([_univerjs_sheets.ClearSelectionFormatCommand.id, SetZoomRatioCommand.id]);
9826
9951
  d.add(this._commandService.onCommandExecuted((command) => {
@@ -9835,19 +9960,35 @@ let EditorBridgeRenderController = class EditorBridgeRenderController extends _u
9835
9960
  }));
9836
9961
  }
9837
9962
  _showEditorByKeyboard(config) {
9963
+ var _ref, _config$content;
9838
9964
  const event = config === null || config === void 0 ? void 0 : config.event;
9839
9965
  if (config == null || !event.data && event.inputType !== "InsertParagraph") return;
9966
+ const initialValue = (_ref = (_config$content = config.content) !== null && _config$content !== void 0 ? _config$content : event.data) !== null && _ref !== void 0 ? _ref : "";
9840
9967
  this._commandService.syncExecuteCommand(SetCellEditVisibleOperation.id, {
9841
9968
  visible: true,
9842
9969
  eventType: _univerjs_engine_render.DeviceInputEventType.Keyboard,
9843
9970
  keycode: event.which,
9971
+ initialValue,
9844
9972
  unitId: this._context.unitId
9845
9973
  });
9846
9974
  }
9847
- _tryHideEditor() {
9975
+ _tryHideEditor(evt) {
9848
9976
  if (this._editorBridgeService.isForceKeepVisible()) return;
9977
+ if (!evt && this._isEmbeddedFormulaEditorActive()) return;
9978
+ if (this._isEmbeddedFormulaEditorActive() && this._isCurrentEmbedRuntimeEvent(evt)) return;
9979
+ if (isEmbedCellEditorInteraction(evt)) return;
9849
9980
  this._hideEditor();
9850
9981
  }
9982
+ _isEmbeddedFormulaEditorActive() {
9983
+ var _this$_embedRuntimeFo2, _this$_editorBridgeSe;
9984
+ if (((_this$_embedRuntimeFo2 = this._embedRuntimeFocusCoordinator) === null || _this$_embedRuntimeFo2 === void 0 ? void 0 : _this$_embedRuntimeFo2.isChildUnitInActiveSession(this._context.unitId)) !== true) return false;
9985
+ const dataStream = (_this$_editorBridgeSe = this._editorBridgeService.getEditCellState()) === null || _this$_editorBridgeSe === void 0 || (_this$_editorBridgeSe = _this$_editorBridgeSe.documentLayoutObject.documentModel) === null || _this$_editorBridgeSe === void 0 || (_this$_editorBridgeSe = _this$_editorBridgeSe.getSnapshot().body) === null || _this$_editorBridgeSe === void 0 ? void 0 : _this$_editorBridgeSe.dataStream;
9986
+ return typeof dataStream === "string" && dataStream.startsWith("=");
9987
+ }
9988
+ _isCurrentEmbedRuntimeEvent(evt) {
9989
+ var _this$_embedRuntimeFo3;
9990
+ return ((_this$_embedRuntimeFo3 = this._embedRuntimeFocusCoordinator) === null || _this$_embedRuntimeFo3 === void 0 ? void 0 : _this$_embedRuntimeFo3.isChildUnitRuntimeEvent(this._context.unitId, evt === null || evt === void 0 ? void 0 : evt.target, evt instanceof Event ? evt : evt)) === true;
9991
+ }
9851
9992
  _hideEditor() {
9852
9993
  if (this._editorBridgeService.isVisible().visible !== true) return;
9853
9994
  this._commandService.syncExecuteCommand(SetCellEditVisibleOperation.id, {
@@ -9857,11 +9998,12 @@ let EditorBridgeRenderController = class EditorBridgeRenderController extends _u
9857
9998
  });
9858
9999
  }
9859
10000
  _getSheetObject() {
10001
+ if (!this._context.unit) return null;
9860
10002
  return getSheetObject(this._context.unit, this._context);
9861
10003
  }
9862
10004
  _isCurrentSheetFocused() {
9863
- var _this$_instanceSrv$ge;
9864
- return ((_this$_instanceSrv$ge = this._instanceSrv.getFocusedUnit()) === null || _this$_instanceSrv$ge === void 0 ? void 0 : _this$_instanceSrv$ge.getUnitId()) === this._context.unitId;
10005
+ var _this$_instanceSrv$ge, _this$_embedRuntimeFo4;
10006
+ return ((_this$_instanceSrv$ge = this._instanceSrv.getFocusedUnit()) === null || _this$_instanceSrv$ge === void 0 ? void 0 : _this$_instanceSrv$ge.getUnitId()) === this._context.unitId || ((_this$_embedRuntimeFo4 = this._embedRuntimeFocusCoordinator) === null || _this$_embedRuntimeFo4 === void 0 ? void 0 : _this$_embedRuntimeFo4.isChildUnitInActiveSession(this._context.unitId)) === true;
9865
10007
  }
9866
10008
  };
9867
10009
  EditorBridgeRenderController = __decorate([
@@ -9871,8 +10013,46 @@ EditorBridgeRenderController = __decorate([
9871
10013
  __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
9872
10014
  __decorateParam(5, _univerjs_core.IContextService),
9873
10015
  __decorateParam(6, _univerjs_engine_render.IRenderManagerService),
9874
- __decorateParam(7, (0, _univerjs_core.Inject)(SheetSkeletonManagerService))
10016
+ __decorateParam(7, (0, _univerjs_core.Inject)(SheetSkeletonManagerService)),
10017
+ __decorateParam(8, (0, _univerjs_core.Optional)(ISheetEmbedRuntimeFocusCoordinator))
9875
10018
  ], EditorBridgeRenderController);
10019
+ function resolvePointerEventPayload(payload) {
10020
+ return Array.isArray(payload) ? payload[0] : payload;
10021
+ }
10022
+ function isEmbedCellEditorInteraction(evt) {
10023
+ return isEmbedCellEditorInteractionTarget(evt === null || evt === void 0 ? void 0 : evt.target) || isEmbedCellEditorInteractionPoint(resolvePointerEventPoint(evt));
10024
+ }
10025
+ function isEmbedCellEditorInteractionTarget(target) {
10026
+ if (typeof HTMLElement === "undefined" || !(target instanceof HTMLElement)) return false;
10027
+ return target.closest(`[${"data-embed-runtime-focus-role"}="child-editor"]`) != null || target.closest("[data-u-comp=\"editor\"]") != null || target.closest("[id^=\"__editor___INTERNAL_EDITOR__\"]") != null || target.closest("[id^=\"univer-doc-selection-container-__INTERNAL_EDITOR__\"]") != null;
10028
+ }
10029
+ function resolvePointerEventPoint(evt) {
10030
+ if (!evt) return;
10031
+ return {
10032
+ clientX: "clientX" in evt ? evt.clientX : void 0,
10033
+ clientY: "clientY" in evt ? evt.clientY : void 0,
10034
+ x: "x" in evt ? evt.x : void 0,
10035
+ y: "y" in evt ? evt.y : void 0
10036
+ };
10037
+ }
10038
+ function isEmbedCellEditorInteractionPoint(evt) {
10039
+ if (typeof document === "undefined") return false;
10040
+ const clientX = Number.isFinite(evt === null || evt === void 0 ? void 0 : evt.clientX) ? evt === null || evt === void 0 ? void 0 : evt.clientX : evt === null || evt === void 0 ? void 0 : evt.x;
10041
+ const clientY = Number.isFinite(evt === null || evt === void 0 ? void 0 : evt.clientY) ? evt === null || evt === void 0 ? void 0 : evt.clientY : evt === null || evt === void 0 ? void 0 : evt.y;
10042
+ if (!Number.isFinite(clientX) || !Number.isFinite(clientY)) return false;
10043
+ return [...document.querySelectorAll([
10044
+ `[${SHEET_EMBED_RUNTIME_FOCUS_ROLE_ATTRIBUTE}="child-editor"]`,
10045
+ "[data-u-comp=\"editor\"]",
10046
+ "[id^=\"__editor___INTERNAL_EDITOR__\"]",
10047
+ "[id^=\"univer-doc-selection-container-__INTERNAL_EDITOR__\"]"
10048
+ ].join(","))].some((element) => {
10049
+ const rect = element.getBoundingClientRect();
10050
+ return rect.width > 0 && rect.height > 0 && clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom;
10051
+ });
10052
+ }
10053
+ function isSameEditCell(current, unitId, sheetId, primary) {
10054
+ return (current === null || current === void 0 ? void 0 : current.unitId) === unitId && current.sheetId === sheetId && current.row === primary.startRow && current.column === primary.startColumn;
10055
+ }
9876
10056
 
9877
10057
  //#endregion
9878
10058
  //#region src/services/repeat-last-action.service.ts
@@ -10589,10 +10769,11 @@ let EditingRenderController = class EditingRenderController extends _univerjs_co
10589
10769
  }
10590
10770
  _initialCursorSync(d) {
10591
10771
  d.add(this._cellEditorManagerService.focus$.pipe((0, rxjs.filter)((f) => !!f)).subscribe(() => {
10592
- var _this$_renderManagerS2;
10593
- const currentDoc = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
10594
- if (!currentDoc) return;
10595
- const docSelectionRenderManager = (_this$_renderManagerS2 = this._renderManagerService.getRenderById(currentDoc === null || currentDoc === void 0 ? void 0 : currentDoc.getUnitId())) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(_univerjs_docs_ui.DocSelectionRenderService);
10772
+ var _this$_univerInstance, _this$_renderManagerS2;
10773
+ const editorId = this._contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR) ? _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY : this._editorBridgeService.getCurrentEditorId();
10774
+ const docUnitId = editorId !== null && editorId !== void 0 ? editorId : (_this$_univerInstance = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getUnitId();
10775
+ if (!docUnitId) return;
10776
+ const docSelectionRenderManager = (_this$_renderManagerS2 = this._renderManagerService.getRenderById(docUnitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(_univerjs_docs_ui.DocSelectionRenderService);
10596
10777
  if (!docSelectionRenderManager) return;
10597
10778
  docSelectionRenderManager.sync();
10598
10779
  }));
@@ -10713,14 +10894,17 @@ let EditingRenderController = class EditingRenderController extends _univerjs_co
10713
10894
  this._cursorChange = eventType === _univerjs_engine_render.DeviceInputEventType.PointerDown || eventType === _univerjs_engine_render.DeviceInputEventType.Dblclick ? 2 : 1;
10714
10895
  const editCellState = this._editorBridgeService.getEditLocation();
10715
10896
  if (editCellState == null) return;
10716
- this._commandService.syncExecuteCommand(ScrollToRangeOperation.id, { range: {
10717
- startRow: editCellState.row,
10718
- startColumn: editCellState.column,
10719
- endRow: editCellState.row,
10720
- endColumn: editCellState.column
10721
- } });
10722
- this._editorBridgeService.refreshEditCellPosition(false);
10723
10897
  const { unitId, isInArrayFormulaRange = false } = editCellState;
10898
+ this._commandService.syncExecuteCommand(ScrollToRangeOperation.id, {
10899
+ unitId,
10900
+ range: {
10901
+ startRow: editCellState.row,
10902
+ startColumn: editCellState.column,
10903
+ endRow: editCellState.row,
10904
+ endColumn: editCellState.column
10905
+ }
10906
+ });
10907
+ this._editorBridgeService.refreshEditCellPosition(false);
10724
10908
  const editorObject = this._getEditorObject();
10725
10909
  if (editorObject == null) return;
10726
10910
  const { document, scene } = editorObject;
@@ -11106,8 +11290,9 @@ function getCellStyleBySnapshot(snapshot) {
11106
11290
  return null;
11107
11291
  }
11108
11292
  function emptyBody(body, removeStyle = false) {
11293
+ var _body$textRuns;
11109
11294
  body.dataStream = _univerjs_core.DEFAULT_EMPTY_DOCUMENT_VALUE;
11110
- if (body.textRuns != null) if (body.textRuns.length === 1 && !removeStyle) {
11295
+ if ((_body$textRuns = body.textRuns) === null || _body$textRuns === void 0 ? void 0 : _body$textRuns.length) if (body.textRuns.length === 1 && !removeStyle) {
11111
11296
  body.textRuns[0].st = 0;
11112
11297
  body.textRuns[0].ed = 1;
11113
11298
  } else body.textRuns = void 0;
@@ -11474,7 +11659,10 @@ function generateBody(text) {
11474
11659
  return {
11475
11660
  dataStream,
11476
11661
  paragraphs,
11477
- sectionBreaks: [{ startIndex: dataStream.indexOf("\n") }]
11662
+ sectionBreaks: [{
11663
+ sectionId: (0, _univerjs_core.createSectionId)(/* @__PURE__ */ new Set()),
11664
+ startIndex: dataStream.indexOf("\n")
11665
+ }]
11478
11666
  };
11479
11667
  }
11480
11668
 
@@ -12210,11 +12398,18 @@ let FormulaEditorController = class FormulaEditorController extends _univerjs_co
12210
12398
  });
12211
12399
  this._create(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
12212
12400
  this.disposeWithMe(this._editorService.focus$.subscribe(() => {
12213
- var _this$_editorService$;
12214
- if (((_this$_editorService$ = this._editorService.getFocusEditor()) === null || _this$_editorService$ === void 0 ? void 0 : _this$_editorService$.getEditorId()) !== _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) this._contextService.setContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR, false);
12215
- else this._contextService.setContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR, true);
12401
+ this._syncFxBarFocusContext();
12216
12402
  }));
12217
12403
  }
12404
+ _syncFxBarFocusContext() {
12405
+ var _this$_editorService$;
12406
+ if (((_this$_editorService$ = this._editorService.getFocusEditor()) === null || _this$_editorService$ === void 0 ? void 0 : _this$_editorService$.getEditorId()) === _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) {
12407
+ this._contextService.setContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR, true);
12408
+ return;
12409
+ }
12410
+ if (this._contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR) && this._contextService.getContextValue(_univerjs_core.EDITOR_ACTIVATED)) return;
12411
+ this._contextService.setContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR, false);
12412
+ }
12218
12413
  _handleContentChange() {
12219
12414
  this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
12220
12415
  if (commandInfo.id === _univerjs_docs.RichTextEditingMutation.id) {
@@ -12236,7 +12431,7 @@ let FormulaEditorController = class FormulaEditorController extends _univerjs_co
12236
12431
  if (this._contextService.getContextValue(_univerjs_core.FOCUSING_EDITOR_BUT_HIDDEN) && !this._contextService.getContextValue(_univerjs_core.EDITOR_ACTIVATED)) {
12237
12432
  var _formulaEditorDataMod;
12238
12433
  this._univerInstanceService.setCurrentUnitForType(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
12239
- const formulaEditorDataModel = this._univerInstanceService.getUniverDocInstance(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
12434
+ const formulaEditorDataModel = this._univerInstanceService.getUnit(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, _univerjs_core.UniverInstanceType.UNIVER_DOC);
12240
12435
  if (this._editorBridgeService.isVisible().visible === false) this._commandService.syncExecuteCommand(SetCellEditVisibleOperation.id, {
12241
12436
  visible: true,
12242
12437
  eventType: _univerjs_engine_render.DeviceInputEventType.PointerDown,
@@ -12276,7 +12471,7 @@ let FormulaEditorController = class FormulaEditorController extends _univerjs_co
12276
12471
  this.disposeWithMe((0, rxjs.combineLatest)([this._formulaEditorManagerService.position$, addFormulaBar$]).subscribe(([position]) => {
12277
12472
  if (!position) return this._clearScheduledCallback();
12278
12473
  const editorObject = getEditorObject(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, this._renderManagerService);
12279
- const formulaEditorDataModel = this._univerInstanceService.getUniverDocInstance(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
12474
+ const formulaEditorDataModel = this._univerInstanceService.getUnit(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, _univerjs_core.UniverInstanceType.UNIVER_DOC);
12280
12475
  if (editorObject == null || formulaEditorDataModel == null) return this._clearScheduledCallback();
12281
12476
  const { width, height } = position;
12282
12477
  if (width === 0 || height === 0) return this._clearScheduledCallback();
@@ -12295,7 +12490,7 @@ let FormulaEditorController = class FormulaEditorController extends _univerjs_co
12295
12490
  const position = this._formulaEditorManagerService.getPosition();
12296
12491
  const skeleton = (_this$_renderManagerS = this._renderManagerService.getRenderById(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
12297
12492
  const editorObject = this._renderManagerService.getRenderById(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
12298
- const formulaEditorDataModel = this._univerInstanceService.getUniverDocInstance(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
12493
+ const formulaEditorDataModel = this._univerInstanceService.getUnit(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, _univerjs_core.UniverInstanceType.UNIVER_DOC);
12299
12494
  if (skeleton == null || position == null || editorObject == null || formulaEditorDataModel == null) return;
12300
12495
  const { marginTop = 0, marginBottom = 0 } = formulaEditorDataModel.getSnapshot().documentStyle;
12301
12496
  const { scene, mainComponent } = editorObject;
@@ -16079,6 +16274,56 @@ const BORDER_LINE_CHILDREN = [
16079
16274
  value: "mltr_bctr"
16080
16275
  }
16081
16276
  ];
16277
+ const BORDER_SIZE_CHILDREN = [
16278
+ {
16279
+ label: _univerjs_core.BorderStyleTypes.THIN,
16280
+ value: _univerjs_core.BorderStyleTypes.THIN
16281
+ },
16282
+ {
16283
+ label: _univerjs_core.BorderStyleTypes.HAIR,
16284
+ value: _univerjs_core.BorderStyleTypes.HAIR
16285
+ },
16286
+ {
16287
+ label: _univerjs_core.BorderStyleTypes.DOTTED,
16288
+ value: _univerjs_core.BorderStyleTypes.DOTTED
16289
+ },
16290
+ {
16291
+ label: _univerjs_core.BorderStyleTypes.DASHED,
16292
+ value: _univerjs_core.BorderStyleTypes.DASHED
16293
+ },
16294
+ {
16295
+ label: _univerjs_core.BorderStyleTypes.DASH_DOT,
16296
+ value: _univerjs_core.BorderStyleTypes.DASH_DOT
16297
+ },
16298
+ {
16299
+ label: _univerjs_core.BorderStyleTypes.DASH_DOT_DOT,
16300
+ value: _univerjs_core.BorderStyleTypes.DASH_DOT_DOT
16301
+ },
16302
+ {
16303
+ label: _univerjs_core.BorderStyleTypes.MEDIUM,
16304
+ value: _univerjs_core.BorderStyleTypes.MEDIUM
16305
+ },
16306
+ {
16307
+ label: _univerjs_core.BorderStyleTypes.MEDIUM_DASHED,
16308
+ value: _univerjs_core.BorderStyleTypes.MEDIUM_DASHED
16309
+ },
16310
+ {
16311
+ label: _univerjs_core.BorderStyleTypes.MEDIUM_DASH_DOT,
16312
+ value: _univerjs_core.BorderStyleTypes.MEDIUM_DASH_DOT
16313
+ },
16314
+ {
16315
+ label: _univerjs_core.BorderStyleTypes.MEDIUM_DASH_DOT_DOT,
16316
+ value: _univerjs_core.BorderStyleTypes.MEDIUM_DASH_DOT_DOT
16317
+ },
16318
+ {
16319
+ label: _univerjs_core.BorderStyleTypes.THICK,
16320
+ value: _univerjs_core.BorderStyleTypes.THICK
16321
+ },
16322
+ {
16323
+ label: _univerjs_core.BorderStyleTypes.DOUBLE,
16324
+ value: _univerjs_core.BorderStyleTypes.DOUBLE
16325
+ }
16326
+ ];
16082
16327
 
16083
16328
  //#endregion
16084
16329
  //#region src/menu/menu-util.ts
@@ -16839,6 +17084,9 @@ const MenuItemInput = (props) => {
16839
17084
  function handlePressEnter() {
16840
17085
  if (inputValue) onChange(inputValue);
16841
17086
  }
17087
+ function handleKeyDown(event) {
17088
+ event.stopPropagation();
17089
+ }
16842
17090
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
16843
17091
  className: "univer-inline-flex univer-items-center univer-gap-1",
16844
17092
  children: [
@@ -16854,6 +17102,7 @@ const MenuItemInput = (props) => {
16854
17102
  max,
16855
17103
  disabled,
16856
17104
  onPressEnter: handlePressEnter,
17105
+ onKeyDown: handleKeyDown,
16857
17106
  onChange: handleChange
16858
17107
  })
16859
17108
  }),
@@ -18089,7 +18338,7 @@ function ShowRowMenuItemFactory(accessor) {
18089
18338
  return {
18090
18339
  id: _univerjs_sheets.SetSelectedRowsVisibleCommand.id,
18091
18340
  type: _univerjs_ui.MenuItemType.BUTTON,
18092
- icon: "EyeOutlineIcon",
18341
+ icon: "EyeIcon",
18093
18342
  title: "sheets-ui.rightClick.showHideRow",
18094
18343
  hidden$: deriveStateFromActiveSheet$(univerInstanceService, true, ({ worksheet }) => new rxjs.Observable((subscriber) => {
18095
18344
  function hasHiddenRowsInSelections() {
@@ -18125,7 +18374,7 @@ function ShowColMenuItemFactory(accessor) {
18125
18374
  return {
18126
18375
  id: _univerjs_sheets.SetSelectedColsVisibleCommand.id,
18127
18376
  type: _univerjs_ui.MenuItemType.BUTTON,
18128
- icon: "EyeOutlineIcon",
18377
+ icon: "EyeIcon",
18129
18378
  title: "sheets-ui.rightClick.showHideColumn",
18130
18379
  hidden$: deriveStateFromActiveSheet$(univerInstanceService, true, ({ worksheet }) => new rxjs.Observable((subscriber) => {
18131
18380
  function hasHiddenColsInSelections() {
@@ -19410,6 +19659,25 @@ const menuSchema = {
19410
19659
  } } }
19411
19660
  };
19412
19661
 
19662
+ //#endregion
19663
+ //#region src/embed-tab-anchor.ts
19664
+ const EMBED_SHEETS_TAB_CUSTOM_KEY = "UNIVER_EMBED_SHEETS_TAB";
19665
+ function getEmbedSheetsTabCustomData(snapshot) {
19666
+ var _snapshot$custom;
19667
+ const value = (_snapshot$custom = snapshot.custom) === null || _snapshot$custom === void 0 ? void 0 : _snapshot$custom[EMBED_SHEETS_TAB_CUSTOM_KEY];
19668
+ if (!isEmbedSheetsTabCustomData(value)) return;
19669
+ return value;
19670
+ }
19671
+ function isEmbedSheetsTabCustomData(value) {
19672
+ if (!value || typeof value !== "object") return false;
19673
+ const candidate = value;
19674
+ return candidate.version === 1 && typeof candidate.embedId === "string" && typeof candidate.hostAnchorId === "string";
19675
+ }
19676
+
19677
+ //#endregion
19678
+ //#region src/services/sheet-embed-runtime.service.ts
19679
+ const ISheetEmbedRuntimeService = (0, _univerjs_core.createIdentifier)("sheet-ui.embed-runtime.service");
19680
+
19413
19681
  //#endregion
19414
19682
  //#region src/views/auto-fill-popup-menu/AutoFillPopupMenu.tsx
19415
19683
  const useUpdate = () => {
@@ -19559,6 +19827,93 @@ function AutoFillPopupMenu() {
19559
19827
  });
19560
19828
  }
19561
19829
 
19830
+ //#endregion
19831
+ //#region src/views/editor-container/focus-editor.ts
19832
+ const SHEET_CELL_EDITOR_ELEMENT_ID = `__editor_${_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY}`;
19833
+ const SHEET_CELL_EDITOR_SELECTION_CONTAINER_ID = `univer-doc-selection-container-${_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY}`;
19834
+ function focusSheetCellEditorElement(ownerDocument = document) {
19835
+ const element = ownerDocument.getElementById(SHEET_CELL_EDITOR_ELEMENT_ID);
19836
+ if (element == null || ownerDocument.activeElement === element) return false;
19837
+ if (!element.hasAttribute("tabindex")) element.tabIndex = -1;
19838
+ element.focus({ preventScroll: true });
19839
+ return ownerDocument.activeElement === element;
19840
+ }
19841
+ function registerSheetCellEditorRuntimePortal(options) {
19842
+ var _options$ownerDocumen;
19843
+ const ownerDocument = (_options$ownerDocumen = options.ownerDocument) !== null && _options$ownerDocumen !== void 0 ? _options$ownerDocumen : typeof document === "undefined" ? void 0 : document;
19844
+ if (!ownerDocument) return (0, _univerjs_core.toDisposable)(() => {});
19845
+ const collection = new _univerjs_core.DisposableCollection();
19846
+ const view = ownerDocument.defaultView;
19847
+ let disposed = false;
19848
+ let registeredPortalRoot = null;
19849
+ let portalRegistration;
19850
+ const frameHandles = [];
19851
+ let observer;
19852
+ const tryRegister = () => {
19853
+ if (disposed) return;
19854
+ const portalRoot = resolveSheetCellEditorPortalRoot(ownerDocument);
19855
+ if (portalRoot === registeredPortalRoot) return;
19856
+ portalRegistration === null || portalRegistration === void 0 || portalRegistration.dispose();
19857
+ portalRegistration = void 0;
19858
+ registeredPortalRoot = null;
19859
+ if (!portalRoot) return;
19860
+ const rootRegistration = new _univerjs_core.DisposableCollection();
19861
+ registeredPortalRoot = portalRoot;
19862
+ if (options.interactionBoundaryService) rootRegistration.add(options.interactionBoundaryService.registerOwnedElement(options.embedId, portalRoot));
19863
+ if (options.focusCoordinator) {
19864
+ rootRegistration.add(options.focusCoordinator.registerElement({
19865
+ embedId: options.embedId,
19866
+ role: "child-editor",
19867
+ element: portalRoot
19868
+ }));
19869
+ const editorElement = ownerDocument.getElementById(SHEET_CELL_EDITOR_ELEMENT_ID);
19870
+ if (editorElement && editorElement !== portalRoot) rootRegistration.add(options.focusCoordinator.registerElement({
19871
+ embedId: options.embedId,
19872
+ role: "child-editor",
19873
+ element: editorElement
19874
+ }));
19875
+ }
19876
+ portalRegistration = rootRegistration;
19877
+ };
19878
+ const scheduleRetry = (remaining) => {
19879
+ if (remaining <= 0 || !(view === null || view === void 0 ? void 0 : view.requestAnimationFrame)) return;
19880
+ const handle = view.requestAnimationFrame(() => {
19881
+ const index = frameHandles.indexOf(handle);
19882
+ if (index >= 0) frameHandles.splice(index, 1);
19883
+ tryRegister();
19884
+ if (!registeredPortalRoot) scheduleRetry(remaining - 1);
19885
+ });
19886
+ frameHandles.push(handle);
19887
+ };
19888
+ tryRegister();
19889
+ if (!registeredPortalRoot) scheduleRetry(2);
19890
+ if ((view === null || view === void 0 ? void 0 : view.MutationObserver) && ownerDocument.body) {
19891
+ observer = new view.MutationObserver(() => tryRegister());
19892
+ observer.observe(ownerDocument.body, {
19893
+ childList: true,
19894
+ subtree: true
19895
+ });
19896
+ }
19897
+ collection.add((0, _univerjs_core.toDisposable)(() => {
19898
+ disposed = true;
19899
+ frameHandles.forEach((handle) => {
19900
+ var _view$cancelAnimation;
19901
+ return view === null || view === void 0 || (_view$cancelAnimation = view.cancelAnimationFrame) === null || _view$cancelAnimation === void 0 ? void 0 : _view$cancelAnimation.call(view, handle);
19902
+ });
19903
+ frameHandles.length = 0;
19904
+ observer === null || observer === void 0 || observer.disconnect();
19905
+ observer = void 0;
19906
+ portalRegistration === null || portalRegistration === void 0 || portalRegistration.dispose();
19907
+ portalRegistration = void 0;
19908
+ registeredPortalRoot = null;
19909
+ }));
19910
+ return collection;
19911
+ }
19912
+ function resolveSheetCellEditorPortalRoot(ownerDocument = document) {
19913
+ var _ref;
19914
+ return (_ref = ownerDocument.getElementById(SHEET_CELL_EDITOR_SELECTION_CONTAINER_ID)) !== null && _ref !== void 0 ? _ref : ownerDocument.getElementById(SHEET_CELL_EDITOR_ELEMENT_ID);
19915
+ }
19916
+
19562
19917
  //#endregion
19563
19918
  //#region src/views/editor-container/hooks.ts
19564
19919
  /**
@@ -19628,19 +19983,65 @@ function isTransparentColor(color) {
19628
19983
  const normalizedColor = color.trim().toLowerCase().replace(/\s+/g, "");
19629
19984
  return normalizedColor === "transparent" || normalizedColor === "rgba(0,0,0,0)";
19630
19985
  }
19986
+ function shouldRefocusCellEditorAfterPointerDown(options) {
19987
+ const { root, target, activeElement, isEditorFocusing } = options;
19988
+ if (!root || !(target instanceof HTMLElement) || !(activeElement instanceof HTMLElement)) return true;
19989
+ const owner = root.closest(`[${SHEET_EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE}]`);
19990
+ const embedId = owner === null || owner === void 0 ? void 0 : owner.getAttribute(SHEET_EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE);
19991
+ if (!embedId) return true;
19992
+ const targetInOwner = target.closest(`[${SHEET_EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE}="${embedId}"]`) != null;
19993
+ const activeOwnerElement = activeElement.closest(`[${SHEET_EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE}="${embedId}"]`);
19994
+ if (targetInOwner && activeOwnerElement && isEmbedRuntimeInteractiveElement(activeElement)) return false;
19995
+ if (!isEditorFocusing) return true;
19996
+ return target.closest(`[${"data-embed-interaction-boundary-owner"}="${embedId}"]`) == null || activeOwnerElement == null;
19997
+ }
19998
+ function isEmbedRuntimeInteractiveElement(element) {
19999
+ const role = element.getAttribute(SHEET_EMBED_RUNTIME_FOCUS_ROLE_ATTRIBUTE);
20000
+ return role === "child-editor" || role === "child-popup" || role === "floating-menu";
20001
+ }
20002
+ function shouldPreserveEmbedPopupFocus(embedId, ownerDocument) {
20003
+ var _activeElement$getAtt, _activeElement$closes;
20004
+ if (!embedId) return false;
20005
+ const activeElement = ownerDocument.activeElement;
20006
+ if (!(activeElement instanceof HTMLElement)) return false;
20007
+ if (!activeElement.closest(`[${"data-embed-interaction-boundary-owner"}="${embedId}"]`)) return false;
20008
+ const role = (_activeElement$getAtt = activeElement.getAttribute("data-embed-runtime-focus-role")) !== null && _activeElement$getAtt !== void 0 ? _activeElement$getAtt : (_activeElement$closes = activeElement.closest(`[${"data-embed-runtime-focus-role"}]`)) === null || _activeElement$closes === void 0 ? void 0 : _activeElement$closes.getAttribute(SHEET_EMBED_RUNTIME_FOCUS_ROLE_ATTRIBUTE);
20009
+ return role === "child-popup" || role === "floating-menu";
20010
+ }
20011
+ function shouldPreserveEmbedInteractiveFocus(embedId, ownerDocument) {
20012
+ var _activeElement$getAtt2, _activeElement$closes2;
20013
+ if (!embedId) return false;
20014
+ const activeElement = ownerDocument.activeElement;
20015
+ if (!(activeElement instanceof HTMLElement)) return false;
20016
+ if (!activeElement.closest(`[${"data-embed-interaction-boundary-owner"}="${embedId}"]`)) return false;
20017
+ const role = (_activeElement$getAtt2 = activeElement.getAttribute("data-embed-runtime-focus-role")) !== null && _activeElement$getAtt2 !== void 0 ? _activeElement$getAtt2 : (_activeElement$closes2 = activeElement.closest(`[${"data-embed-runtime-focus-role"}]`)) === null || _activeElement$closes2 === void 0 ? void 0 : _activeElement$closes2.getAttribute(SHEET_EMBED_RUNTIME_FOCUS_ROLE_ATTRIBUTE);
20018
+ return role == null && activeElement.tagName !== "CANVAS" || role === "child-editor" || role === "child-popup" || role === "floating-menu";
20019
+ }
20020
+ function isEmbedRuntimeEditorOrPopup(target) {
20021
+ var _target$getAttribute, _target$closest;
20022
+ if (!(target instanceof HTMLElement)) return false;
20023
+ const role = (_target$getAttribute = target.getAttribute("data-embed-runtime-focus-role")) !== null && _target$getAttribute !== void 0 ? _target$getAttribute : (_target$closest = target.closest(`[${"data-embed-runtime-focus-role"}]`)) === null || _target$closest === void 0 ? void 0 : _target$closest.getAttribute(SHEET_EMBED_RUNTIME_FOCUS_ROLE_ATTRIBUTE);
20024
+ return role === "child-editor" || role === "child-popup" || role === "floating-menu";
20025
+ }
19631
20026
  /**
19632
20027
  * Cell editor container.
19633
20028
  * @returns the rendered cell editor container.
19634
20029
  */
19635
- const EditorContainer = () => {
20030
+ function EditorContainer() {
19636
20031
  const [state, setState] = (0, react.useState)({ ...EDITOR_DEFAULT_POSITION });
19637
20032
  const cellEditorManagerService = (0, _univerjs_ui.useDependency)(ICellEditorManagerService);
20033
+ const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
19638
20034
  const editorService = (0, _univerjs_ui.useDependency)(_univerjs_docs_ui.IEditorService);
20035
+ const instanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
19639
20036
  const contextService = (0, _univerjs_ui.useDependency)(_univerjs_core.IContextService);
19640
20037
  const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
19641
20038
  const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
19642
20039
  const editorBridgeService = (0, _univerjs_ui.useDependency)(IEditorBridgeService);
20040
+ const cellEditorResizeService = (0, _univerjs_ui.useDependency)(SheetCellEditorResizeService);
20041
+ const rootRef = (0, react.useRef)(null);
20042
+ const pointerRefocusTimerRef = (0, react.useRef)(void 0);
19643
20043
  const visible = (0, _univerjs_ui.useObservable)(editorBridgeService.visible$);
20044
+ const [runtimeFocusRevision, setRuntimeFocusRevision] = (0, react.useState)(0);
19644
20045
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
19645
20046
  const disableAutoFocus = (0, _univerjs_ui.useObservable)(() => contextService.subscribeContextValue$(_univerjs_ui.DISABLE_AUTO_FOCUS_KEY), false, void 0, [contextService, _univerjs_ui.DISABLE_AUTO_FOCUS_KEY]);
19646
20047
  const FormulaEditor = componentManager.get(EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY);
@@ -19673,17 +20074,54 @@ const EditorContainer = () => {
19673
20074
  sub.unsubscribe();
19674
20075
  };
19675
20076
  }, []);
20077
+ (0, react.useEffect)(() => {
20078
+ if (!injector.has(ISheetEmbedFloatingGeometryService)) return;
20079
+ const subscription = injector.get(ISheetEmbedFloatingGeometryService).geometryInvalidated$.subscribe(() => {
20080
+ cellEditorResizeService.resizeCellEditor();
20081
+ });
20082
+ return () => subscription.unsubscribe();
20083
+ }, [cellEditorResizeService, injector]);
20084
+ (0, react.useEffect)(() => {
20085
+ if (!injector.has(ISheetEmbedRuntimeFocusCoordinator)) return;
20086
+ const subscription = injector.get(ISheetEmbedRuntimeFocusCoordinator).runtimeSessionChanged$.subscribe(() => {
20087
+ setRuntimeFocusRevision((revision) => revision + 1);
20088
+ });
20089
+ return () => subscription.unsubscribe();
20090
+ }, [injector]);
19676
20091
  (0, react.useEffect)(() => {
19677
20092
  if (!disableAutoFocus) cellEditorManagerService.setFocus(true);
19678
20093
  }, [disableAutoFocus, state]);
19679
20094
  (0, react.useEffect)(() => {
20095
+ var _rootRef$current$owne, _rootRef$current, _ownerDocument$defaul;
19680
20096
  if (!(visible === null || visible === void 0 ? void 0 : visible.visible)) return;
20097
+ cellEditorResizeService.fitTextSize();
20098
+ if (contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR)) return;
20099
+ const ownerDocument = (_rootRef$current$owne = (_rootRef$current = rootRef.current) === null || _rootRef$current === void 0 ? void 0 : _rootRef$current.ownerDocument) !== null && _rootRef$current$owne !== void 0 ? _rootRef$current$owne : document;
20100
+ const ownerWindow = (_ownerDocument$defaul = ownerDocument.defaultView) !== null && _ownerDocument$defaul !== void 0 ? _ownerDocument$defaul : window;
19681
20101
  let focusRetryFrame = 0;
19682
20102
  let finalFocusRetryFrame = 0;
20103
+ let delayedFocusTimer;
20104
+ const focusCellEditorElement = () => {
20105
+ var _resolveSheetEmbedRun;
20106
+ const scope = rootRef.current ? (_resolveSheetEmbedRun = resolveSheetEmbedRuntimeDomScope(rootRef.current)) !== null && _resolveSheetEmbedRun !== void 0 ? _resolveSheetEmbedRun : resolveActiveSheetEmbedRuntimeDomScope(ownerDocument) : resolveActiveSheetEmbedRuntimeDomScope(ownerDocument);
20107
+ if (shouldPreserveEmbedInteractiveFocus(scope === null || scope === void 0 ? void 0 : scope.embedId, ownerDocument)) return;
20108
+ focusSheetCellEditorElement(ownerDocument);
20109
+ if (delayedFocusTimer != null) ownerWindow.clearTimeout(delayedFocusTimer);
20110
+ delayedFocusTimer = ownerWindow.setTimeout(() => {
20111
+ delayedFocusTimer = void 0;
20112
+ if (shouldPreserveEmbedInteractiveFocus(scope === null || scope === void 0 ? void 0 : scope.embedId, ownerDocument)) return;
20113
+ focusSheetCellEditorElement(ownerDocument);
20114
+ }, 0);
20115
+ };
19683
20116
  const focusEditor = () => {
20117
+ var _resolveSheetEmbedRun2;
20118
+ if (contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR)) return;
20119
+ const scope = rootRef.current ? (_resolveSheetEmbedRun2 = resolveSheetEmbedRuntimeDomScope(rootRef.current)) !== null && _resolveSheetEmbedRun2 !== void 0 ? _resolveSheetEmbedRun2 : resolveActiveSheetEmbedRuntimeDomScope(ownerDocument) : resolveActiveSheetEmbedRuntimeDomScope(ownerDocument);
20120
+ if (shouldPreserveEmbedPopupFocus(scope === null || scope === void 0 ? void 0 : scope.embedId, ownerDocument)) return;
19684
20121
  const editor = editorService.getEditor(_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
19685
20122
  const docSelectionRenderService = editor === null || editor === void 0 ? void 0 : editor.render.with(_univerjs_docs_ui.DocSelectionRenderService);
19686
20123
  if (!(docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing)) docSelectionRenderService === null || docSelectionRenderService === void 0 || docSelectionRenderService.focus();
20124
+ focusCellEditorElement();
19687
20125
  };
19688
20126
  focusEditor();
19689
20127
  focusRetryFrame = requestAnimationFrame(() => {
@@ -19693,8 +20131,185 @@ const EditorContainer = () => {
19693
20131
  return () => {
19694
20132
  cancelAnimationFrame(focusRetryFrame);
19695
20133
  cancelAnimationFrame(finalFocusRetryFrame);
20134
+ if (delayedFocusTimer != null) ownerWindow.clearTimeout(delayedFocusTimer);
19696
20135
  };
19697
- }, [editorService, visible === null || visible === void 0 ? void 0 : visible.visible]);
20136
+ }, [
20137
+ cellEditorResizeService,
20138
+ editorService,
20139
+ visible === null || visible === void 0 ? void 0 : visible.visible
20140
+ ]);
20141
+ (0, react.useEffect)(() => {
20142
+ var _instanceService$getF, _ref;
20143
+ if (!(visible === null || visible === void 0 ? void 0 : visible.visible) || !rootRef.current || !injector.has(ISheetEmbedRuntimeFocusCoordinator)) return;
20144
+ const focusCoordinator = injector.get(ISheetEmbedRuntimeFocusCoordinator);
20145
+ const focusedUnitId = (_instanceService$getF = instanceService.getFocusedUnit()) === null || _instanceService$getF === void 0 ? void 0 : _instanceService$getF.getUnitId();
20146
+ const rootRuntimeScope = resolveSheetEmbedRuntimeDomScope(rootRef.current);
20147
+ const unitRuntimeScope = [
20148
+ editState === null || editState === void 0 ? void 0 : editState.unitId,
20149
+ visible.unitId,
20150
+ focusedUnitId
20151
+ ].map((unitId) => focusCoordinator.resolveRuntimeScopeByChildUnitId(unitId)).find((resolvedScope) => resolvedScope != null);
20152
+ if (rootRuntimeScope && unitRuntimeScope && rootRuntimeScope.embedId !== unitRuntimeScope.embedId) return;
20153
+ const activeSessionScope = focusCoordinator.resolveActiveChildSessionRuntimeScope();
20154
+ const explicitRuntimeScope = unitRuntimeScope !== null && unitRuntimeScope !== void 0 ? unitRuntimeScope : rootRuntimeScope;
20155
+ if (activeSessionScope && rootRuntimeScope && !unitRuntimeScope && rootRuntimeScope.embedId !== activeSessionScope.embedId) return;
20156
+ const scope = (_ref = explicitRuntimeScope !== null && explicitRuntimeScope !== void 0 ? explicitRuntimeScope : activeSessionScope) !== null && _ref !== void 0 ? _ref : resolveActiveSheetEmbedRuntimeDomScope(rootRef.current.ownerDocument);
20157
+ if (!scope) return;
20158
+ const collection = new _univerjs_core.DisposableCollection();
20159
+ const interactionBoundaryService = injector.has(ISheetEmbedInteractionBoundaryService) ? injector.get(ISheetEmbedInteractionBoundaryService) : void 0;
20160
+ const editorRoot = rootRef.current;
20161
+ collection.add(focusCoordinator.acquireLease({
20162
+ embedId: scope.embedId,
20163
+ role: "child-editor",
20164
+ owner: "sheet-cell-editor",
20165
+ hostUnitId: scope.hostUnitId,
20166
+ childUnitId: scope.childUnitId,
20167
+ associatedChildUnitIds: [_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY]
20168
+ }));
20169
+ if (interactionBoundaryService) collection.add(interactionBoundaryService.registerOwnedElement(scope.embedId, editorRoot));
20170
+ collection.add(focusCoordinator.registerElement({
20171
+ embedId: scope.embedId,
20172
+ role: "child-editor",
20173
+ element: editorRoot
20174
+ }));
20175
+ collection.add(registerSheetCellEditorRuntimePortal({
20176
+ embedId: scope.embedId,
20177
+ ownerDocument: rootRef.current.ownerDocument,
20178
+ interactionBoundaryService,
20179
+ focusCoordinator
20180
+ }));
20181
+ if (scope.childType === _univerjs_core.UniverInstanceType.UNIVER_SHEET && scope.childUnitId) {
20182
+ const ownerDocument = rootRef.current.ownerDocument;
20183
+ let pointerRetryFrame = 0;
20184
+ const focusEditor = () => {
20185
+ if (contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR) || shouldPreserveEmbedPopupFocus(scope.embedId, ownerDocument)) return;
20186
+ const editor = editorService.getEditor(_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
20187
+ const docSelectionRenderService = editor === null || editor === void 0 ? void 0 : editor.render.with(_univerjs_docs_ui.DocSelectionRenderService);
20188
+ if (!(docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing)) docSelectionRenderService === null || docSelectionRenderService === void 0 || docSelectionRenderService.focus();
20189
+ focusSheetCellEditorElement(ownerDocument);
20190
+ };
20191
+ const refocusEditorAfterRuntimePointer = (event) => {
20192
+ if (!focusCoordinator.isChildUnitRuntimeEvent(scope.childUnitId, event.target, event) || isEmbedRuntimeEditorOrPopup(event.target)) return;
20193
+ cancelAnimationFrame(pointerRetryFrame);
20194
+ pointerRetryFrame = requestAnimationFrame(focusEditor);
20195
+ };
20196
+ ownerDocument.addEventListener("pointerdown", refocusEditorAfterRuntimePointer, true);
20197
+ ownerDocument.addEventListener("pointerup", refocusEditorAfterRuntimePointer, true);
20198
+ ownerDocument.addEventListener("click", refocusEditorAfterRuntimePointer, true);
20199
+ collection.add((0, _univerjs_core.toDisposable)(() => {
20200
+ cancelAnimationFrame(pointerRetryFrame);
20201
+ ownerDocument.removeEventListener("pointerdown", refocusEditorAfterRuntimePointer, true);
20202
+ ownerDocument.removeEventListener("pointerup", refocusEditorAfterRuntimePointer, true);
20203
+ ownerDocument.removeEventListener("click", refocusEditorAfterRuntimePointer, true);
20204
+ }));
20205
+ }
20206
+ return () => collection.dispose();
20207
+ }, [
20208
+ contextService,
20209
+ editState === null || editState === void 0 ? void 0 : editState.unitId,
20210
+ editorService,
20211
+ injector,
20212
+ instanceService,
20213
+ runtimeFocusRevision,
20214
+ visible === null || visible === void 0 ? void 0 : visible.unitId,
20215
+ visible === null || visible === void 0 ? void 0 : visible.visible
20216
+ ]);
20217
+ (0, react.useEffect)(() => {
20218
+ var _rootRef$current$owne2, _rootRef$current2, _ownerDocument$defaul2;
20219
+ if ((visible === null || visible === void 0 ? void 0 : visible.visible) || !injector.has(ISheetEmbedRuntimeFocusCoordinator)) return;
20220
+ const focusCoordinator = injector.get(ISheetEmbedRuntimeFocusCoordinator);
20221
+ const activeSessionScope = focusCoordinator.resolveActiveChildSessionRuntimeScope();
20222
+ const childUnitId = activeSessionScope === null || activeSessionScope === void 0 ? void 0 : activeSessionScope.childUnitId;
20223
+ if (!activeSessionScope || activeSessionScope.childType !== _univerjs_core.UniverInstanceType.UNIVER_SHEET || !childUnitId || !instanceService.getUnit(childUnitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET)) return;
20224
+ const ownerDocument = (_rootRef$current$owne2 = (_rootRef$current2 = rootRef.current) === null || _rootRef$current2 === void 0 ? void 0 : _rootRef$current2.ownerDocument) !== null && _rootRef$current$owne2 !== void 0 ? _rootRef$current$owne2 : document;
20225
+ const interactionBoundaryService = injector.has(ISheetEmbedInteractionBoundaryService) ? injector.get(ISheetEmbedInteractionBoundaryService) : void 0;
20226
+ const portalRegistration = registerSheetCellEditorRuntimePortal({
20227
+ embedId: activeSessionScope.embedId,
20228
+ ownerDocument,
20229
+ interactionBoundaryService,
20230
+ focusCoordinator
20231
+ });
20232
+ const ownerWindow = (_ownerDocument$defaul2 = ownerDocument.defaultView) !== null && _ownerDocument$defaul2 !== void 0 ? _ownerDocument$defaul2 : window;
20233
+ let delayedFocusTimer;
20234
+ const focusCellEditorElement = () => {
20235
+ if (shouldPreserveEmbedInteractiveFocus(activeSessionScope.embedId, ownerDocument)) return;
20236
+ focusSheetCellEditorElement(ownerDocument);
20237
+ if (delayedFocusTimer != null) ownerWindow.clearTimeout(delayedFocusTimer);
20238
+ delayedFocusTimer = ownerWindow.setTimeout(() => {
20239
+ delayedFocusTimer = void 0;
20240
+ if (shouldPreserveEmbedInteractiveFocus(activeSessionScope.embedId, ownerDocument)) return;
20241
+ focusSheetCellEditorElement(ownerDocument);
20242
+ }, 0);
20243
+ };
20244
+ const focusHiddenEditor = () => {
20245
+ if (shouldPreserveEmbedPopupFocus(activeSessionScope.embedId, ownerDocument)) return;
20246
+ const editor = editorService.getEditor(_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
20247
+ const docSelectionRenderService = editor === null || editor === void 0 ? void 0 : editor.render.with(_univerjs_docs_ui.DocSelectionRenderService);
20248
+ if (!(docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing)) docSelectionRenderService === null || docSelectionRenderService === void 0 || docSelectionRenderService.focus();
20249
+ focusCellEditorElement();
20250
+ };
20251
+ let retryFrame = 0;
20252
+ let finalRetryFrame = 0;
20253
+ let pointerRetryFrame = 0;
20254
+ focusHiddenEditor();
20255
+ retryFrame = requestAnimationFrame(() => {
20256
+ focusHiddenEditor();
20257
+ finalRetryFrame = requestAnimationFrame(focusHiddenEditor);
20258
+ });
20259
+ const refocusHiddenEditorAfterRuntimePointer = (event) => {
20260
+ if (!focusCoordinator.isChildUnitRuntimeEvent(childUnitId, event.target, event) || isEmbedRuntimeEditorOrPopup(event.target)) return;
20261
+ cancelAnimationFrame(pointerRetryFrame);
20262
+ pointerRetryFrame = requestAnimationFrame(focusHiddenEditor);
20263
+ };
20264
+ ownerDocument.addEventListener("pointerdown", refocusHiddenEditorAfterRuntimePointer, true);
20265
+ ownerDocument.addEventListener("pointerup", refocusHiddenEditorAfterRuntimePointer, true);
20266
+ ownerDocument.addEventListener("click", refocusHiddenEditorAfterRuntimePointer, true);
20267
+ return () => {
20268
+ cancelAnimationFrame(retryFrame);
20269
+ cancelAnimationFrame(finalRetryFrame);
20270
+ cancelAnimationFrame(pointerRetryFrame);
20271
+ if (delayedFocusTimer != null) ownerWindow.clearTimeout(delayedFocusTimer);
20272
+ ownerDocument.removeEventListener("pointerdown", refocusHiddenEditorAfterRuntimePointer, true);
20273
+ ownerDocument.removeEventListener("pointerup", refocusHiddenEditorAfterRuntimePointer, true);
20274
+ ownerDocument.removeEventListener("click", refocusHiddenEditorAfterRuntimePointer, true);
20275
+ portalRegistration.dispose();
20276
+ };
20277
+ }, [
20278
+ editorService,
20279
+ injector,
20280
+ instanceService,
20281
+ runtimeFocusRevision,
20282
+ visible === null || visible === void 0 ? void 0 : visible.visible
20283
+ ]);
20284
+ (0, react.useEffect)(() => {
20285
+ return () => {
20286
+ var _rootRef$current3;
20287
+ const ownerWindow = (_rootRef$current3 = rootRef.current) === null || _rootRef$current3 === void 0 ? void 0 : _rootRef$current3.ownerDocument.defaultView;
20288
+ if (ownerWindow && pointerRefocusTimerRef.current != null) ownerWindow.clearTimeout(pointerRefocusTimerRef.current);
20289
+ };
20290
+ }, []);
20291
+ const refocusEditorAfterPointerDown = (0, _univerjs_ui.useEvent)((event) => {
20292
+ var _rootRef$current$owne3, _rootRef$current4, _ownerDocument$defaul3;
20293
+ if (!(visible === null || visible === void 0 ? void 0 : visible.visible)) return;
20294
+ const ownerDocument = (_rootRef$current$owne3 = (_rootRef$current4 = rootRef.current) === null || _rootRef$current4 === void 0 ? void 0 : _rootRef$current4.ownerDocument) !== null && _rootRef$current$owne3 !== void 0 ? _rootRef$current$owne3 : document;
20295
+ const ownerWindow = (_ownerDocument$defaul3 = ownerDocument.defaultView) !== null && _ownerDocument$defaul3 !== void 0 ? _ownerDocument$defaul3 : window;
20296
+ const editor = editorService.getEditor(_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
20297
+ const docSelectionRenderService = editor === null || editor === void 0 ? void 0 : editor.render.with(_univerjs_docs_ui.DocSelectionRenderService);
20298
+ const pointerTarget = event.target;
20299
+ const activeElementAtPointerDown = ownerDocument.activeElement;
20300
+ if (!shouldRefocusCellEditorAfterPointerDown({
20301
+ root: rootRef.current,
20302
+ target: pointerTarget,
20303
+ activeElement: activeElementAtPointerDown,
20304
+ isEditorFocusing: docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing
20305
+ })) return;
20306
+ if (pointerRefocusTimerRef.current != null) ownerWindow.clearTimeout(pointerRefocusTimerRef.current);
20307
+ pointerRefocusTimerRef.current = ownerWindow.setTimeout(() => {
20308
+ pointerRefocusTimerRef.current = void 0;
20309
+ if (!(docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing)) docSelectionRenderService === null || docSelectionRenderService === void 0 || docSelectionRenderService.focus();
20310
+ focusSheetCellEditorElement(ownerDocument);
20311
+ }, 0);
20312
+ });
19698
20313
  (0, _univerjs_ui.useSidebarClick)((0, _univerjs_ui.useEvent)(() => {
19699
20314
  if (editorBridgeService.isVisible().visible) commandService.executeCommand(SetCellEditVisibleOperation.id, {
19700
20315
  visible: false,
@@ -19713,7 +20328,10 @@ const EditorContainer = () => {
19713
20328
  });
19714
20329
  });
19715
20330
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
20331
+ ref: rootRef,
20332
+ "data-u-comp": "editor",
19716
20333
  className: "univer-absolute univer-z-10 univer-flex",
20334
+ onPointerDownCapture: refocusEditorAfterPointerDown,
19717
20335
  style: {
19718
20336
  left: state.left,
19719
20337
  top: state.top,
@@ -19738,17 +20356,15 @@ const EditorContainer = () => {
19738
20356
  resetSelectionOnBlur: false,
19739
20357
  isSingle: false,
19740
20358
  autoScrollbar: false,
19741
- onFormulaSelectingChange: (isSelecting, isFocusing) => {
19742
- if (!isFocusing) return;
20359
+ onFormulaSelectingChange: (isSelecting) => {
19743
20360
  if (isSelecting) editorBridgeService.enableForceKeepVisible();
19744
20361
  else editorBridgeService.disableForceKeepVisible();
19745
20362
  },
19746
- disableSelectionOnClick: true,
19747
20363
  disableContextMenu: false,
19748
20364
  canvasStyle: { backgroundColor: "transparent" }
19749
20365
  })
19750
20366
  });
19751
- };
20367
+ }
19752
20368
 
19753
20369
  //#endregion
19754
20370
  //#region src/services/utils/defined-name-utils.ts
@@ -19793,6 +20409,7 @@ function DefinedNameOverlay({ search, isInputEvent }) {
19793
20409
  const definedNamesService = (0, _univerjs_ui.useDependency)(_univerjs_engine_formula.IDefinedNamesService);
19794
20410
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
19795
20411
  const sidebarService = (0, _univerjs_ui.useDependency)(_univerjs_ui.ISidebarService);
20412
+ const direction = localeService.getDirection();
19796
20413
  const unitId = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).getUnitId();
19797
20414
  const getDefinedNameMap = () => {
19798
20415
  const definedNameMap = definedNamesService.getDefinedNameMap(unitId);
@@ -19847,7 +20464,9 @@ function DefinedNameOverlay({ search, isInputEvent }) {
19847
20464
  definedNamesService.focusRange(unitId, id);
19848
20465
  };
19849
20466
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
19850
- className: "univer-w-[300px]",
20467
+ "data-u-comp": "defined-name-overlay",
20468
+ dir: direction,
20469
+ className: "univer-w-[300px] rtl:univer-text-right",
19851
20470
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
19852
20471
  ref: listContainerRef,
19853
20472
  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 }),
@@ -19861,13 +20480,16 @@ function DefinedNameOverlay({ search, isInputEvent }) {
19861
20480
  focusDefinedName(definedName);
19862
20481
  },
19863
20482
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
19864
- className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-justify-between univer-gap-2 univer-py-1", _univerjs_design.borderBottomClassName),
20483
+ "data-u-comp": "defined-name-overlay-row",
20484
+ className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-gap-2 univer-py-1 rtl:univer-flex-row-reverse", _univerjs_design.borderBottomClassName),
19865
20485
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
19866
- className: "univer-w-[50%] univer-flex-shrink-0 univer-truncate univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",
20486
+ "data-u-comp": "defined-name-overlay-name",
20487
+ className: "univer-min-w-0 univer-flex-1 univer-basis-0 univer-truncate univer-text-sm univer-text-gray-600 rtl:univer-text-right dark:!univer-text-gray-200",
19867
20488
  title: definedName.name,
19868
20489
  children: definedName.name
19869
20490
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
19870
- className: "univer-w-[50%] univer-flex-shrink-0 univer-truncate univer-text-xs univer-text-gray-400",
20491
+ "data-u-comp": "defined-name-overlay-reference",
20492
+ className: "univer-min-w-0 univer-flex-1 univer-basis-0 univer-truncate univer-text-xs univer-text-gray-400 rtl:univer-text-right",
19871
20493
  title: definedName.formulaOrRefString,
19872
20494
  children: definedName.formulaOrRefString
19873
20495
  })]
@@ -19876,7 +20498,8 @@ function DefinedNameOverlay({ search, isInputEvent }) {
19876
20498
  })
19877
20499
  })
19878
20500
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
19879
- className: "univer-cursor-pointer univer-p-2 univer-transition-colors univer-duration-200 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-600",
20501
+ "data-u-comp": "defined-name-overlay-footer",
20502
+ className: "univer-cursor-pointer univer-p-2 univer-transition-colors univer-duration-200 hover:univer-bg-gray-100 rtl:univer-text-right dark:hover:!univer-bg-gray-600",
19880
20503
  onClick: openSlider,
19881
20504
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
19882
20505
  className: "univer-mb-2 univer-text-sm univer-font-semibold univer-text-gray-600 dark:!univer-text-gray-200",
@@ -20064,7 +20687,7 @@ function DefinedName({ disable }) {
20064
20687
  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",
20065
20688
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
20066
20689
  ref: inputRef,
20067
- 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 }),
20690
+ 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 rtl:univer-pl-5 rtl:univer-pr-1.5 dark:!univer-border-r-gray-700 dark:!univer-bg-gray-900 dark:!univer-text-white", _univerjs_design.borderRightClassName, { "univer-cursor-not-allowed": disable }),
20068
20691
  type: "text",
20069
20692
  value: inputValue,
20070
20693
  onChange: handleChangeSelection,
@@ -20083,7 +20706,7 @@ function DefinedName({ disable }) {
20083
20706
  onOpenChange: setOpen,
20084
20707
  onOpenAutoFocus: (e) => e.preventDefault(),
20085
20708
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
20086
- className: (0, _univerjs_design.clsx)("univer-absolute univer-right-0 univer-top-0 univer-flex univer-h-full univer-cursor-pointer univer-items-center univer-justify-center univer-px-1 univer-transition-colors univer-duration-200 hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-800", { "univer-cursor-not-allowed univer-text-gray-300 hover:univer-bg-transparent dark:!univer-text-gray-700": disable }),
20709
+ className: (0, _univerjs_design.clsx)("univer-absolute univer-right-0 univer-top-0 univer-flex univer-h-full univer-cursor-pointer univer-items-center univer-justify-center univer-px-1 univer-transition-colors univer-duration-200 hover:univer-bg-gray-100 rtl:univer-left-0 rtl:univer-right-auto dark:!univer-text-white dark:hover:!univer-bg-gray-800", { "univer-cursor-not-allowed univer-text-gray-300 hover:univer-bg-transparent dark:!univer-text-gray-700": disable }),
20087
20710
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, {})
20088
20711
  })
20089
20712
  })]
@@ -20231,9 +20854,9 @@ function FormulaBar(props) {
20231
20854
  const shouldSkipFocus = (0, react.useRef)(false);
20232
20855
  const handlePointerDown = () => {
20233
20856
  try {
20857
+ contextService.setContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR, true);
20234
20858
  if (editorBridgeService.isVisible().visible === false) {
20235
20859
  if (editorActivationDisable) {
20236
- contextService.setContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR, true);
20237
20860
  editorService.focus(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
20238
20861
  return;
20239
20862
  }
@@ -20242,12 +20865,12 @@ function FormulaBar(props) {
20242
20865
  eventType: _univerjs_engine_render.DeviceInputEventType.PointerDown,
20243
20866
  unitId: editState.unitId
20244
20867
  })) {
20868
+ contextService.setContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR, false);
20245
20869
  shouldSkipFocus.current = true;
20246
- return;
20247
20870
  }
20248
20871
  }
20249
- contextService.setContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR, true);
20250
20872
  } catch (e) {
20873
+ contextService.setContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR, false);
20251
20874
  shouldSkipFocus.current = true;
20252
20875
  throw e;
20253
20876
  }
@@ -20328,7 +20951,7 @@ function FormulaBar(props) {
20328
20951
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
20329
20952
  className: (0, _univerjs_design.clsx)("univer-flex univer-h-full univer-w-5 univer-cursor-pointer univer-items-center univer-justify-center univer-text-xs univer-text-gray-700 dark:!univer-text-gray-200", { "univer-cursor-not-allowed univer-text-gray-200 dark:!univer-text-gray-700": editDisable }),
20330
20953
  onClick: handleArrowClick,
20331
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DropdownIcon, { className: (0, _univerjs_design.clsx)({ "univer-rotate-180": arrowDirection === 1 }) })
20954
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DownIcon, { className: (0, _univerjs_design.clsx)({ "univer-rotate-180": arrowDirection === 1 }) })
20332
20955
  })]
20333
20956
  })]
20334
20957
  }),
@@ -20460,7 +21083,7 @@ function SheetBarMenu() {
20460
21083
  //#endregion
20461
21084
  //#region src/views/sheet-bar/sheet-bar-tabs/SheetBarItem.tsx
20462
21085
  function SheetBarItem(props) {
20463
- const { sheetId, label, color, selected, className, onKeyDown, tabIndex } = props;
21086
+ const { sheetId, label, color, selected, className, onKeyDown, onClick, tabIndex } = props;
20464
21087
  const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
20465
21088
  const getTextColor = (color) => {
20466
21089
  const darkTextColor = themeService.getColorFromTheme("gray.900");
@@ -20476,6 +21099,7 @@ function SheetBarItem(props) {
20476
21099
  "aria-selected": currentSelected,
20477
21100
  tabIndex: tabIndex !== null && tabIndex !== void 0 ? tabIndex : currentSelected ? 0 : -1,
20478
21101
  onKeyDown,
21102
+ onClick,
20479
21103
  className: (0, _univerjs_design.clsx)("univer-mx-1 univer-box-border univer-flex univer-flex-grow univer-cursor-pointer univer-select-none univer-flex-row univer-items-center univer-rounded univer-text-xs univer-transition-[colors,box-shadow] focus-visible:univer-ring-2 focus-visible:univer-ring-primary-500", {
20480
21104
  "dark:!univer-text-white": !color || color && !textColor,
20481
21105
  "univer-justify-center univer-bg-white univer-font-bold univer-text-primary-700 univer-shadow": currentSelected,
@@ -20518,6 +21142,49 @@ function SheetBarTabsContextMenu(props) {
20518
21142
  })] });
20519
21143
  }
20520
21144
 
21145
+ //#endregion
21146
+ //#region src/views/sheet-bar/sheet-bar-tabs/utils/sheet-tab-drag-sort.ts
21147
+ function getMidline(item) {
21148
+ return item.left + item.width / 2;
21149
+ }
21150
+ function calculateSheetTabDragSort(items, activeIndex, dragOffsetX) {
21151
+ const itemOffsets = items.map(() => 0);
21152
+ const activeItem = items[activeIndex];
21153
+ if (!activeItem) return {
21154
+ targetIndex: activeIndex,
21155
+ itemOffsets
21156
+ };
21157
+ itemOffsets[activeIndex] = dragOffsetX;
21158
+ const activeLeft = activeItem.left + dragOffsetX;
21159
+ const activeRight = activeLeft + activeItem.width;
21160
+ let targetIndex = activeIndex;
21161
+ if (dragOffsetX > 0) {
21162
+ for (let index = activeIndex + 1; index < items.length; index++) if (activeRight > getMidline(items[index])) {
21163
+ itemOffsets[index] = -activeItem.width;
21164
+ targetIndex = index;
21165
+ }
21166
+ } else if (dragOffsetX < 0) {
21167
+ for (let index = activeIndex - 1; index >= 0; index--) if (activeLeft < getMidline(items[index])) {
21168
+ itemOffsets[index] = activeItem.width;
21169
+ targetIndex = index;
21170
+ }
21171
+ }
21172
+ return {
21173
+ targetIndex,
21174
+ itemOffsets
21175
+ };
21176
+ }
21177
+ function reorderItems(items, fromIndex, toIndex) {
21178
+ if (fromIndex === toIndex || fromIndex < 0 || toIndex < 0 || fromIndex >= items.length || toIndex >= items.length) return [...items];
21179
+ const nextItems = [...items];
21180
+ const [movedItem] = nextItems.splice(fromIndex, 1);
21181
+ nextItems.splice(toIndex, 0, movedItem);
21182
+ return nextItems;
21183
+ }
21184
+ function getSheetTabTargetOrder(sheetOrder, visibleSheetIds, targetIndex) {
21185
+ return sheetOrder.indexOf(visibleSheetIds[targetIndex]);
21186
+ }
21187
+
20521
21188
  //#endregion
20522
21189
  //#region src/views/sheet-bar/sheet-bar-tabs/utils/animate.ts
20523
21190
  /**
@@ -20630,46 +21297,6 @@ var Animate = class {
20630
21297
  }
20631
21298
  };
20632
21299
 
20633
- //#endregion
20634
- //#region src/views/sheet-bar/sheet-bar-tabs/utils/sheet-tab-drag-sort.ts
20635
- function getMidline(item) {
20636
- return item.left + item.width / 2;
20637
- }
20638
- function calculateSheetTabDragSort(items, activeIndex, dragOffsetX) {
20639
- const itemOffsets = items.map(() => 0);
20640
- const activeItem = items[activeIndex];
20641
- if (!activeItem) return {
20642
- targetIndex: activeIndex,
20643
- itemOffsets
20644
- };
20645
- itemOffsets[activeIndex] = dragOffsetX;
20646
- const activeLeft = activeItem.left + dragOffsetX;
20647
- const activeRight = activeLeft + activeItem.width;
20648
- let targetIndex = activeIndex;
20649
- if (dragOffsetX > 0) {
20650
- for (let index = activeIndex + 1; index < items.length; index++) if (activeRight > getMidline(items[index])) {
20651
- itemOffsets[index] = -activeItem.width;
20652
- targetIndex = index;
20653
- }
20654
- } else if (dragOffsetX < 0) {
20655
- for (let index = activeIndex - 1; index >= 0; index--) if (activeLeft < getMidline(items[index])) {
20656
- itemOffsets[index] = activeItem.width;
20657
- targetIndex = index;
20658
- }
20659
- }
20660
- return {
20661
- targetIndex,
20662
- itemOffsets
20663
- };
20664
- }
20665
- function reorderItems(items, fromIndex, toIndex) {
20666
- if (fromIndex === toIndex || fromIndex < 0 || toIndex < 0 || fromIndex >= items.length || toIndex >= items.length) return [...items];
20667
- const nextItems = [...items];
20668
- const [movedItem] = nextItems.splice(fromIndex, 1);
20669
- nextItems.splice(toIndex, 0, movedItem);
20670
- return nextItems;
20671
- }
20672
-
20673
21300
  //#endregion
20674
21301
  //#region src/views/sheet-bar/sheet-bar-tabs/utils/sheet-tab-name-editor.ts
20675
21302
  const MAX_SHEET_NAME_LENGTH = 31;
@@ -20839,7 +21466,7 @@ var SlideTabItem = class SlideTabItem {
20839
21466
  startSheetTabNameEditor({
20840
21467
  slideTabItem: this._slideTabItem,
20841
21468
  canStart: () => this._slideTabBar.getConfig().onNameChangeCheck(),
20842
- checkName: (name) => this._slideTabBar.getConfig().onNameCheckAlert(name),
21469
+ checkName: (name) => this._slideTabBar.getConfig().onNameCheckAlert(name, this.getId()),
20843
21470
  setEditMode: (editing) => {
20844
21471
  this._editMode = editing;
20845
21472
  },
@@ -20848,8 +21475,12 @@ var SlideTabItem = class SlideTabItem {
20848
21475
  this._slideTabBar.updateItems();
20849
21476
  },
20850
21477
  onCommit: (name, focusEvent) => {
20851
- this._slideTabBar.getConfig().onChangeName(this.getId(), name);
20852
- if (callback) callback(focusEvent);
21478
+ try {
21479
+ this._slideTabBar.getConfig().onChangeName(this.getId(), name);
21480
+ if (callback) callback(focusEvent);
21481
+ } finally {
21482
+ this._slideTabBar.addListener();
21483
+ }
20853
21484
  }
20854
21485
  });
20855
21486
  }
@@ -20858,7 +21489,7 @@ var SlideTabItem = class SlideTabItem {
20858
21489
  const input = this._slideTabItem.querySelector("span");
20859
21490
  if (!input) return false;
20860
21491
  const text = (_input$textContent = input.textContent) !== null && _input$textContent !== void 0 ? _input$textContent : "";
20861
- return this._slideTabBar.getConfig().onNameCheckAlert(text);
21492
+ return this._slideTabBar.getConfig().onNameCheckAlert(text, this.getId());
20862
21493
  }
20863
21494
  animate() {
20864
21495
  return {
@@ -21011,6 +21642,7 @@ var SlideTabBar = class SlideTabBar {
21011
21642
  _defineProperty(this, "_downAction", void 0);
21012
21643
  _defineProperty(this, "_wheelAction", void 0);
21013
21644
  _defineProperty(this, "_scrollIncremental", 0);
21645
+ _defineProperty(this, "_dragStartScrollX", 0);
21014
21646
  _defineProperty(this, "_compareDirection", 0);
21015
21647
  _defineProperty(this, "_autoScrollTime", null);
21016
21648
  _defineProperty(this, "_slideScrollbar", void 0);
@@ -21043,7 +21675,6 @@ var SlideTabBar = class SlideTabBar {
21043
21675
  var _this$_activeTabItem2, _this$_activeTabItem3;
21044
21676
  (_this$_activeTabItem2 = this._activeTabItem) === null || _this$_activeTabItem2 === void 0 || _this$_activeTabItem2.removeEventListener("pointermove", this._moveAction);
21045
21677
  (_this$_activeTabItem3 = this._activeTabItem) === null || _this$_activeTabItem3 === void 0 || _this$_activeTabItem3.removeEventListener("pointerup", this._upAction);
21046
- this.removeListener();
21047
21678
  this._config.onChangeTab(downEvent, slideItemId);
21048
21679
  return;
21049
21680
  }
@@ -21051,6 +21682,7 @@ var SlideTabBar = class SlideTabBar {
21051
21682
  this._downActionX = downEvent.pageX;
21052
21683
  this._moveActionX = 0;
21053
21684
  this._scrollIncremental = 0;
21685
+ this._dragStartScrollX = this._slideScrollbar.getScrollX();
21054
21686
  this._activeTabItem = this._slideTabItems[slideItemIndex];
21055
21687
  if (!this._activeTabItem) {
21056
21688
  console.error("Not found active slide-tab-item in sheet bar");
@@ -21087,23 +21719,29 @@ var SlideTabBar = class SlideTabBar {
21087
21719
  }, SlideTabBar.LongPressDelay);
21088
21720
  };
21089
21721
  this._upAction = (upEvent) => {
21090
- var _this$_activeTabItem8, _this$_activeTabItem9, _this$_activeTabItem10, _this$_activeTabItem11;
21091
- if ((_this$_activeTabItem8 = this._activeTabItem) === null || _this$_activeTabItem8 === void 0 ? void 0 : _this$_activeTabItem8.isEditMode()) return;
21722
+ var _this$_activeTabItem8, _this$_activeTabItem9, _this$_activeTabItem10;
21092
21723
  if (this._longPressTimer) {
21093
21724
  clearTimeout(this._longPressTimer);
21094
21725
  this._longPressTimer = null;
21095
21726
  }
21096
21727
  if (!this._activeTabItem) return;
21728
+ if (this._activeTabItem.isEditMode()) {
21729
+ const activeSlideItemElement = this._activeTabItem.getSlideTabItem();
21730
+ const pointerId = upEvent.pointerId;
21731
+ if (pointerId != null && activeSlideItemElement.hasPointerCapture(pointerId)) activeSlideItemElement.releasePointerCapture(pointerId);
21732
+ this._activeTabItem.removeEventListener("pointerup", this._upAction);
21733
+ return;
21734
+ }
21097
21735
  const isFromScroll = this._autoScrollTime !== null;
21098
21736
  this._closeAutoScroll();
21099
21737
  this._activeTabItem.disableFixed();
21100
21738
  this.updateItems();
21101
- const activeSlideItemElement = (_this$_activeTabItem9 = this._activeTabItem) === null || _this$_activeTabItem9 === void 0 ? void 0 : _this$_activeTabItem9.getSlideTabItem();
21739
+ const activeSlideItemElement = (_this$_activeTabItem8 = this._activeTabItem) === null || _this$_activeTabItem8 === void 0 ? void 0 : _this$_activeTabItem8.getSlideTabItem();
21102
21740
  if (!activeSlideItemElement) return;
21103
21741
  activeSlideItemElement.style.cursor = "";
21104
21742
  activeSlideItemElement.releasePointerCapture(upEvent.pointerId);
21105
- (_this$_activeTabItem10 = this._activeTabItem) === null || _this$_activeTabItem10 === void 0 || _this$_activeTabItem10.removeEventListener("pointermove", this._moveAction);
21106
- (_this$_activeTabItem11 = this._activeTabItem) === null || _this$_activeTabItem11 === void 0 || _this$_activeTabItem11.removeEventListener("pointerup", this._upAction);
21743
+ (_this$_activeTabItem9 = this._activeTabItem) === null || _this$_activeTabItem9 === void 0 || _this$_activeTabItem9.removeEventListener("pointermove", this._moveAction);
21744
+ (_this$_activeTabItem10 = this._activeTabItem) === null || _this$_activeTabItem10 === void 0 || _this$_activeTabItem10.removeEventListener("pointerup", this._upAction);
21107
21745
  if (this._config.onSlideEnd && this._activeTabItemIndex !== this._compareIndex && isFromScroll) {
21108
21746
  this.removeListener();
21109
21747
  this._config.onSlideEnd(upEvent, this._compareIndex || 0);
@@ -21111,6 +21749,7 @@ var SlideTabBar = class SlideTabBar {
21111
21749
  this._scrollIncremental = 0;
21112
21750
  this._downActionX = 0;
21113
21751
  this._moveActionX = 0;
21752
+ this._dragStartScrollX = this._slideScrollbar.getScrollX();
21114
21753
  this._compareIndex = 0;
21115
21754
  };
21116
21755
  this._moveAction = (moveEvent) => {
@@ -21147,9 +21786,9 @@ var SlideTabBar = class SlideTabBar {
21147
21786
  * @param currentIndex
21148
21787
  */
21149
21788
  update(currentIndex) {
21789
+ this.removeListener();
21150
21790
  this._config.currentIndex = currentIndex;
21151
21791
  this._initConfig();
21152
- this.removeListener();
21153
21792
  this.addListener();
21154
21793
  this.scrollToItem(currentIndex);
21155
21794
  }
@@ -21286,13 +21925,13 @@ var SlideTabBar = class SlideTabBar {
21286
21925
  return scrollX;
21287
21926
  }
21288
21927
  calculateActiveTabItemScrollX() {
21289
- var _this$_activeTabItem12;
21928
+ var _this$_activeTabItem11;
21290
21929
  let scrollX = 0;
21291
21930
  const padding = 4;
21292
21931
  const containerRect = this._slideTabBar.getBoundingClientRect();
21293
21932
  const containerLeftPosition = containerRect.left;
21294
21933
  const containerRightPosition = containerRect.left + containerRect.width;
21295
- const itemReact = (_this$_activeTabItem12 = this._activeTabItem) === null || _this$_activeTabItem12 === void 0 ? void 0 : _this$_activeTabItem12.getSlideTabItem().getBoundingClientRect();
21934
+ const itemReact = (_this$_activeTabItem11 = this._activeTabItem) === null || _this$_activeTabItem11 === void 0 ? void 0 : _this$_activeTabItem11.getSlideTabItem().getBoundingClientRect();
21296
21935
  if (!itemReact) return 0;
21297
21936
  const itemLeft = itemReact.left;
21298
21937
  const itemWidth = itemReact.width;
@@ -21304,6 +21943,7 @@ var SlideTabBar = class SlideTabBar {
21304
21943
  this.removeListener();
21305
21944
  this._downActionX = 0;
21306
21945
  this._moveActionX = 0;
21946
+ this._dragStartScrollX = this._slideScrollbar.getScrollX();
21307
21947
  this._compareDirection = 0;
21308
21948
  this._compareIndex = 0;
21309
21949
  this._slideTabItems = [];
@@ -21357,17 +21997,18 @@ var SlideTabBar = class SlideTabBar {
21357
21997
  }
21358
21998
  _updateDragSortState() {
21359
21999
  if (!this._activeTabItem) return;
22000
+ const dragSortOffsetX = this._moveActionX + this._slideScrollbar.getScrollX() - this._dragStartScrollX;
21360
22001
  const dragSortResult = calculateSheetTabDragSort(this._slideTabItems.map((item) => ({
21361
22002
  id: item.getId(),
21362
22003
  left: item.getMidLine() - item.getWidth() / 2,
21363
22004
  width: item.getWidth()
21364
- })), this._activeTabItemIndex, this._moveActionX);
22005
+ })), this._activeTabItemIndex, dragSortOffsetX);
21365
22006
  this._compareIndex = dragSortResult.targetIndex;
21366
22007
  dragSortResult.itemOffsets.forEach((offset, index) => {
21367
22008
  const item = this._slideTabItems[index];
21368
22009
  if (!item) return;
21369
22010
  if (item.equals(this._activeTabItem)) {
21370
- this._compareDirection = item.translateX(offset);
22011
+ this._compareDirection = item.translateX(this._moveActionX);
21371
22012
  return;
21372
22013
  }
21373
22014
  item.animate().translateX(offset);
@@ -21421,7 +22062,9 @@ function SheetBarTabs() {
21421
22062
  const [contextMenuAnchorRect, setContextMenuAnchorRect] = (0, react.useState)(null);
21422
22063
  const slideTabBarRef = (0, react.useRef)(null);
21423
22064
  const slideTabBarContainerRef = (0, react.useRef)(null);
22065
+ const activeSheetIdRef = (0, react.useRef)(activeSheetId);
21424
22066
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
22067
+ const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
21425
22068
  const sheetBarService = (0, _univerjs_ui.useDependency)(ISheetBarService);
21426
22069
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
21427
22070
  const confirmService = (0, _univerjs_ui.useDependency)(_univerjs_core.IConfirmService);
@@ -21430,6 +22073,7 @@ function SheetBarTabs() {
21430
22073
  const rangeProtectionRuleModel = (0, _univerjs_ui.useDependency)(_univerjs_sheets.RangeProtectionRuleModel);
21431
22074
  const permissionService = (0, _univerjs_ui.useDependency)(_univerjs_core.IPermissionService);
21432
22075
  const workbook = useActiveWorkbook();
22076
+ const workbookRef = (0, react.useRef)(workbook);
21433
22077
  const resetOrder = (0, _univerjs_ui.useObservable)(worksheetProtectionRuleModel.resetOrder$);
21434
22078
  const config = (0, _univerjs_ui.useConfigValue)(_univerjs_ui.UI_PLUGIN_CONFIG_KEY);
21435
22079
  const showContextMenu = (_config$contextMenu = config === null || config === void 0 ? void 0 : config.contextMenu) !== null && _config$contextMenu !== void 0 ? _config$contextMenu : true;
@@ -21483,9 +22127,9 @@ function SheetBarTabs() {
21483
22127
  openSheetNameErrorDialog("sheetNameSpecCharAlert", localeService.t("sheets-ui.sheetConfig.sheetNameSpecCharError"));
21484
22128
  return true;
21485
22129
  }, [localeService, openSheetNameErrorDialog]);
21486
- const nameRepeatCheck = (0, react.useCallback)((name) => {
21487
- var _workbook$getActiveSh;
21488
- if (((_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getName()) === name) return false;
22130
+ const nameRepeatCheck = (0, react.useCallback)((name, subUnitId) => {
22131
+ var _workbook$getSheetByS, _workbook$getActiveSh;
22132
+ if ((subUnitId ? (_workbook$getSheetByS = workbook.getSheetBySheetId(subUnitId)) === null || _workbook$getSheetByS === void 0 ? void 0 : _workbook$getSheetByS.getName() : (_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getName()) === name) return false;
21489
22133
  if (!workbook.checkSheetName(name)) return false;
21490
22134
  const id = "sheetNameRepeatAlert";
21491
22135
  confirmService.open({
@@ -21576,6 +22220,34 @@ function SheetBarTabs() {
21576
22220
  rightEnd: slideTabBar.isRightEnd()
21577
22221
  });
21578
22222
  }, [sheetBarService]);
22223
+ (0, react.useEffect)(() => {
22224
+ activeSheetIdRef.current = activeSheetId;
22225
+ }, [activeSheetId]);
22226
+ (0, react.useEffect)(() => {
22227
+ workbookRef.current = workbook;
22228
+ }, [workbook]);
22229
+ const syncActiveSheetRender = (0, react.useCallback)((subUnitId) => {
22230
+ const render = renderManagerService.getRenderById(workbookRef.current.getUnitId());
22231
+ try {
22232
+ render === null || render === void 0 || render.with(SheetSkeletonManagerService).setCurrent({ sheetId: subUnitId });
22233
+ render === null || render === void 0 || render.scene.makeDirty(true);
22234
+ render === null || render === void 0 || render.scene.render();
22235
+ } catch {}
22236
+ }, [renderManagerService]);
22237
+ const activateSheetTab = (0, react.useCallback)((subUnitId) => {
22238
+ if (!subUnitId || subUnitId === activeSheetIdRef.current) return;
22239
+ commandService.executeCommand(_univerjs_sheets.SetWorksheetActiveOperation.id, {
22240
+ subUnitId,
22241
+ unitId: workbookRef.current.getUnitId()
22242
+ }).then((result) => {
22243
+ if (result !== false) return;
22244
+ const worksheet = workbookRef.current.getSheetBySheetId(subUnitId);
22245
+ if (worksheet) {
22246
+ workbookRef.current.setActiveSheet(worksheet);
22247
+ syncActiveSheetRender(subUnitId);
22248
+ }
22249
+ });
22250
+ }, [commandService, syncActiveSheetRender]);
21579
22251
  const observeResize = (0, react.useCallback)((slideTabBar) => {
21580
22252
  var _slideTabBarContainer;
21581
22253
  const slideTabBarContainer = (_slideTabBarContainer = slideTabBarContainerRef.current) === null || _slideTabBarContainer === void 0 ? void 0 : _slideTabBarContainer.querySelector("[data-u-comp=slide-tab-bar]");
@@ -21684,8 +22356,8 @@ function SheetBarTabs() {
21684
22356
  slideTabBarContainer: slideTabBarContainerRef.current,
21685
22357
  currentIndex: 0,
21686
22358
  onChangeName: (subUnitId, worksheetName) => {
21687
- var _workbook$getSheetByS;
21688
- if (((_workbook$getSheetByS = workbook.getSheetBySheetId(subUnitId)) === null || _workbook$getSheetByS === void 0 ? void 0 : _workbook$getSheetByS.getName()) === worksheetName) {
22359
+ var _workbook$getSheetByS2;
22360
+ if (((_workbook$getSheetByS2 = workbook.getSheetBySheetId(subUnitId)) === null || _workbook$getSheetByS2 === void 0 ? void 0 : _workbook$getSheetByS2.getName()) === worksheetName) {
21689
22361
  updateSheetItems();
21690
22362
  return;
21691
22363
  }
@@ -21695,7 +22367,8 @@ function SheetBarTabs() {
21695
22367
  });
21696
22368
  },
21697
22369
  onSlideEnd: async (event, order) => {
21698
- await commandService.executeCommand(_univerjs_sheets.SetWorksheetOrderCommand.id, { order });
22370
+ const targetOrder = getSheetTabTargetOrder(workbook.getSheetOrders(), workbook.getUnhiddenWorksheets(), order);
22371
+ await commandService.executeCommand(_univerjs_sheets.SetWorksheetOrderCommand.id, { order: targetOrder });
21699
22372
  },
21700
22373
  onChangeTab: (_event, subUnitId) => {
21701
22374
  commandService.executeCommand(_univerjs_sheets.SetWorksheetActiveOperation.id, {
@@ -21706,8 +22379,8 @@ function SheetBarTabs() {
21706
22379
  onScroll: (state) => {
21707
22380
  sheetBarService.setScroll(state);
21708
22381
  },
21709
- onNameCheckAlert: (name) => {
21710
- return nameEmptyCheck(name) || sheetNameSpecCharCheck(name) || nameRepeatCheck(name);
22382
+ onNameCheckAlert: (name, subUnitId) => {
22383
+ return nameEmptyCheck(name) || sheetNameSpecCharCheck(name) || nameRepeatCheck(name, subUnitId);
21711
22384
  },
21712
22385
  onNameChangeCheck: canRenameActiveSheet
21713
22386
  });
@@ -21741,6 +22414,9 @@ function SheetBarTabs() {
21741
22414
  const renameSubscription = sheetBarService.renameId$.subscribe(() => {
21742
22415
  setTabEditor();
21743
22416
  });
22417
+ const activeSheetSubscription = workbook.activeSheet$.subscribe(() => {
22418
+ updateSheetItems();
22419
+ });
21744
22420
  return () => {
21745
22421
  commandDisposable.dispose();
21746
22422
  slideTabBar.destroy();
@@ -21748,6 +22424,7 @@ function SheetBarTabs() {
21748
22424
  scrollSubscription.unsubscribe();
21749
22425
  scrollXSubscription.unsubscribe();
21750
22426
  renameSubscription.unsubscribe();
22427
+ activeSheetSubscription.unsubscribe();
21751
22428
  disconnectResizeObserver === null || disconnectResizeObserver === void 0 || disconnectResizeObserver();
21752
22429
  };
21753
22430
  }, [
@@ -21766,6 +22443,19 @@ function SheetBarTabs() {
21766
22443
  const currentIndex = sheetList.findIndex((item) => item.sheetId === activeSheetId);
21767
22444
  (_slideTabBarRef$curre5 = slideTabBarRef.current) === null || _slideTabBarRef$curre5 === void 0 || _slideTabBarRef$curre5.update(currentIndex >= 0 ? currentIndex : 0);
21768
22445
  }, [activeSheetId, sheetList]);
22446
+ (0, react.useEffect)(() => {
22447
+ const handlePointerDownCapture = (event) => {
22448
+ var _tabElement$getAttrib;
22449
+ const container = slideTabBarContainerRef.current;
22450
+ const target = event.target;
22451
+ if (!container || !(target instanceof Element)) return;
22452
+ const tabElement = target.closest("[data-u-comp=slide-tab-item]");
22453
+ if (!tabElement || !container.contains(tabElement)) return;
22454
+ activateSheetTab((_tabElement$getAttrib = tabElement.getAttribute("data-id")) !== null && _tabElement$getAttrib !== void 0 ? _tabElement$getAttrib : void 0);
22455
+ };
22456
+ document.addEventListener("pointerdown", handlePointerDownCapture, true);
22457
+ return () => document.removeEventListener("pointerdown", handlePointerDownCapture, true);
22458
+ }, [activateSheetTab]);
21769
22459
  (0, react.useEffect)(() => {
21770
22460
  const subscription = (0, rxjs.merge)(worksheetProtectionRuleModel.ruleChange$, rangeProtectionRuleModel.ruleChange$).subscribe(() => {
21771
22461
  updateSheetItems();
@@ -21865,7 +22555,8 @@ const SheetBar = () => {
21865
22555
  }),
21866
22556
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetBarTabs, {}),
21867
22557
  (!leftScrollState || !rightScrollState) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
21868
- className: "univer-relative univer-flex univer-items-center univer-px-2 after:univer-absolute after:univer-right-0 after:univer-top-1/2 after:univer-h-4 after:univer-w-px after:-univer-translate-y-1/2 after:univer-bg-gray-200 after:univer-content-[\"\"]",
22558
+ "data-u-comp": "sheet-bar-scroll-buttons",
22559
+ className: "univer-relative univer-flex univer-items-center univer-px-2 after:univer-absolute after:univer-right-0 after:univer-top-1/2 after:univer-h-4 after:univer-w-px after:-univer-translate-y-1/2 after:univer-bg-gray-200 after:univer-content-[\"\"] rtl:univer-flex-row-reverse rtl:after:univer-left-0 rtl:after:univer-right-auto",
21869
22560
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetBarButton, {
21870
22561
  disabled: leftScrollState,
21871
22562
  onClick: handleScrollLeft,
@@ -22112,31 +22803,52 @@ function RenderSheetFooter() {
22112
22803
  const config = (0, _univerjs_ui.useConfigValue)(SHEETS_UI_PLUGIN_CONFIG_KEY);
22113
22804
  const menuManagerService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IMenuManagerService);
22114
22805
  const showFooter = (_config$footer = config === null || config === void 0 ? void 0 : config.footer) !== null && _config$footer !== void 0 ? _config$footer : true;
22115
- if (!useActiveWorkbook() || !showFooter) return null;
22806
+ const workbook = useActiveWorkbook();
22807
+ const activeWorkbookEmbeddedRender = useActiveWorkbookIsEmbeddedRender(workbook);
22808
+ const focusedUnitType = useFocusedUnitType();
22809
+ const activeEmbedTab = useActiveSheetEmbedTabData(workbook);
22810
+ if (!workbook || !showFooter) return null;
22811
+ if (activeWorkbookEmbeddedRender) return null;
22812
+ if (!activeEmbedTab && focusedUnitType != null && focusedUnitType !== _univerjs_core.UniverInstanceType.UNIVER_SHEET) return null;
22116
22813
  const footerMenus = menuManagerService.getMenuByPositionKey(_univerjs_ui.ContextMenuPosition.FOOTER_MENU);
22117
22814
  const { sheetBar = true, statisticBar = true, menus = true, zoomSlider = true } = (config === null || config === void 0 ? void 0 : config.footer) || {};
22118
- if (!sheetBar && !statisticBar && !menus && !zoomSlider) return null;
22815
+ const showStatisticBar = activeEmbedTab ? false : statisticBar;
22816
+ const showMenus = activeEmbedTab ? false : menus;
22817
+ const showZoomSlider = activeEmbedTab ? false : zoomSlider;
22818
+ if (!sheetBar && !showStatisticBar && !showMenus && !showZoomSlider) return null;
22119
22819
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
22120
22820
  className: "univer-box-border univer-grid univer-w-full univer-grid-flow-col univer-grid-cols-[1fr,auto,auto,auto] univer-items-center univer-justify-between univer-bg-white univer-px-5 univer-text-gray-900 dark:!univer-bg-gray-900 dark:!univer-text-gray-200",
22121
22821
  style: { height: 36 },
22122
22822
  "data-range-selector": true,
22123
22823
  children: [
22124
22824
  sheetBar && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetBar, {}),
22125
- statisticBar && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StatusBar, {}),
22126
- menus && footerMenus.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
22825
+ showStatisticBar && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StatusBar, {}),
22826
+ showMenus && footerMenus.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
22127
22827
  className: "univer-box-border univer-flex univer-gap-2 univer-px-2",
22128
22828
  children: footerMenus.map((item) => {
22129
22829
  var _item$children;
22130
22830
  return (_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.map((child) => (child === null || child === void 0 ? void 0 : child.item) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_ui.ToolbarItem, { ...child.item }, child.key));
22131
22831
  })
22132
22832
  }),
22133
- zoomSlider && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetZoomSlider, {})
22833
+ showZoomSlider && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetZoomSlider, {})
22134
22834
  ]
22135
22835
  });
22136
22836
  }
22137
22837
  function RenderSheetHeader() {
22138
22838
  const config = (0, _univerjs_ui.useConfigValue)(SHEETS_UI_PLUGIN_CONFIG_KEY);
22139
- if (!useHasWorkbook()) return null;
22839
+ const workbook = useActiveWorkbook();
22840
+ const hasWorkbook = !!workbook;
22841
+ const activeWorkbookEmbeddedRender = useActiveWorkbookIsEmbeddedRender(workbook);
22842
+ const focusedUnitType = useFocusedUnitType();
22843
+ const activeEmbedTab = useActiveSheetEmbedTabData(workbook);
22844
+ if (!hasWorkbook) return null;
22845
+ if (activeWorkbookEmbeddedRender) return null;
22846
+ if (activeEmbedTab) return null;
22847
+ if (focusedUnitType != null && focusedUnitType !== _univerjs_core.UniverInstanceType.UNIVER_SHEET) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
22848
+ "aria-hidden": true,
22849
+ className: "univer-h-7 univer-border-b univer-border-gray-200 univer-bg-white dark:!univer-border-gray-700 dark:!univer-bg-gray-900",
22850
+ "data-u-comp": "formula-bar-placeholder"
22851
+ });
22140
22852
  if ((config === null || config === void 0 ? void 0 : config.formulaBar) !== false) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormulaBar, {});
22141
22853
  return null;
22142
22854
  }
@@ -22144,19 +22856,108 @@ function RenderSheetHeader() {
22144
22856
  * @deprecated We should not write into this component anymore.
22145
22857
  */
22146
22858
  function RenderSheetContent() {
22859
+ var _componentManager$get;
22147
22860
  const config = (0, _univerjs_ui.useConfigValue)(SHEETS_UI_PLUGIN_CONFIG_KEY);
22148
22861
  const hasWorkbook = useHasWorkbook();
22149
- const ShapeTextEditorContainer = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager).get("ShapeTextEditorContainer");
22862
+ const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
22863
+ const workbook = useActiveWorkbook();
22864
+ const activeEmbedTab = useActiveSheetEmbedTabData(workbook);
22865
+ const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
22866
+ const activeWorkbookEmbeddedRender = useActiveWorkbookIsEmbeddedRender(workbook);
22867
+ const ShapeTextEditorContainer = (_componentManager$get = componentManager.get("SheetShapeTextEditorContainer")) !== null && _componentManager$get !== void 0 ? _componentManager$get : componentManager.get("ShapeTextEditorContainer");
22868
+ (0, react.useEffect)(() => {
22869
+ var _tryGetSheetEmbedRunt;
22870
+ if (!workbook || activeEmbedTab || activeWorkbookEmbeddedRender) return;
22871
+ const instanceService = injector.get(_univerjs_core.IUniverInstanceService);
22872
+ instanceService.setCurrentUnitForType(workbook.getUnitId());
22873
+ instanceService.focusUnit(workbook.getUnitId());
22874
+ (_tryGetSheetEmbedRunt = tryGetSheetEmbedRuntimeService(injector)) === null || _tryGetSheetEmbedRunt === void 0 || _tryGetSheetEmbedRunt.clearTab();
22875
+ }, [
22876
+ activeEmbedTab,
22877
+ activeWorkbookEmbeddedRender,
22878
+ injector,
22879
+ workbook
22880
+ ]);
22150
22881
  if (!hasWorkbook) return null;
22882
+ if (activeWorkbookEmbeddedRender) return null;
22883
+ if (activeEmbedTab && workbook) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderSheetEmbedTabHost, {
22884
+ workbook,
22885
+ worksheet: activeEmbedTab.worksheet
22886
+ });
22151
22887
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
22152
22888
  ShapeTextEditorContainer && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ShapeTextEditorContainer, {}),
22153
22889
  !(config === null || config === void 0 ? void 0 : config.disableEdit) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EditorContainer, {}),
22154
22890
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoFillPopupMenu, {})
22155
22891
  ] });
22156
22892
  }
22893
+ function RenderSheetEmbedTabHost(props) {
22894
+ const { workbook, worksheet } = props;
22895
+ const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
22896
+ const embedData = getEmbedSheetsTabCustomData(worksheet.getConfig());
22897
+ const hostUnitId = workbook.getUnitId();
22898
+ const hostAnchorId = embedData === null || embedData === void 0 ? void 0 : embedData.hostAnchorId;
22899
+ const embedId = embedData === null || embedData === void 0 ? void 0 : embedData.embedId;
22900
+ (0, react.useEffect)(() => {
22901
+ if (!embedId || !hostAnchorId) return;
22902
+ const embedRuntimeService = tryGetSheetEmbedRuntimeService(injector);
22903
+ if (!embedRuntimeService) return;
22904
+ try {
22905
+ const disposable = embedRuntimeService.mountSheetTab({
22906
+ hostUnitId,
22907
+ hostAnchorId,
22908
+ embedId
22909
+ });
22910
+ return () => {
22911
+ disposable === null || disposable === void 0 || disposable.dispose();
22912
+ };
22913
+ } catch (error) {
22914
+ console.warn("[sheets-ui] failed to mount embedded sheet-tab block", error);
22915
+ }
22916
+ }, [
22917
+ embedId,
22918
+ hostAnchorId,
22919
+ hostUnitId,
22920
+ injector
22921
+ ]);
22922
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
22923
+ "data-embed-sheets-sheet-tab-host": hostAnchorId,
22924
+ className: "univer-absolute univer-inset-0 univer-z-40 univer-bg-white dark:!univer-bg-gray-900"
22925
+ });
22926
+ }
22157
22927
  function useHasWorkbook() {
22158
22928
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
22159
- return (0, react.useMemo)(() => univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).length > 0, [univerInstanceService, !!(0, _univerjs_ui.useObservable)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), null, false, [])]);
22929
+ const workbook = (0, _univerjs_ui.useObservable)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), null, false, []);
22930
+ return (0, react.useMemo)(() => !!workbook, [workbook]);
22931
+ }
22932
+ function useActiveWorkbookIsEmbeddedRender(workbook) {
22933
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
22934
+ return (0, react.useMemo)(() => {
22935
+ var _univerInstanceServic;
22936
+ if (!workbook) return false;
22937
+ return ((_univerInstanceServic = univerInstanceService.getUnitCreateOptions(workbook.getUnitId())) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.embeddedRender) === true;
22938
+ }, [univerInstanceService, workbook]);
22939
+ }
22940
+ function useFocusedUnitType() {
22941
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
22942
+ const focusedUnitId = (0, _univerjs_ui.useObservable)(() => univerInstanceService.focused$, null, false, [univerInstanceService]);
22943
+ return (0, react.useMemo)(() => {
22944
+ var _focusedUnit$type;
22945
+ if (!focusedUnitId) return null;
22946
+ if ((0, _univerjs_core.isInternalEditorID)(focusedUnitId) && univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)) return _univerjs_core.UniverInstanceType.UNIVER_SHEET;
22947
+ const focusedUnit = univerInstanceService.getUnit(focusedUnitId);
22948
+ return (_focusedUnit$type = focusedUnit === null || focusedUnit === void 0 ? void 0 : focusedUnit.type) !== null && _focusedUnit$type !== void 0 ? _focusedUnit$type : null;
22949
+ }, [focusedUnitId, univerInstanceService]);
22950
+ }
22951
+ function useActiveSheetEmbedTabData(workbook) {
22952
+ const worksheet = useActiveWorksheet(workbook);
22953
+ return worksheet && getEmbedSheetsTabCustomData(worksheet.getConfig()) ? { worksheet } : void 0;
22954
+ }
22955
+ function tryGetSheetEmbedRuntimeService(injector) {
22956
+ try {
22957
+ return injector.get(ISheetEmbedRuntimeService);
22958
+ } catch {
22959
+ return;
22960
+ }
22160
22961
  }
22161
22962
 
22162
22963
  //#endregion
@@ -22727,10 +23528,8 @@ let SheetUIController = class SheetUIController extends _univerjs_core.Disposabl
22727
23528
  }
22728
23529
  _initFocusHandler() {
22729
23530
  this.disposeWithMe(this._layoutService.registerFocusHandler(_univerjs_core.UniverInstanceType.UNIVER_SHEET, (_unitId) => {
22730
- const renderManagerService = this._injector.get(_univerjs_engine_render.IRenderManagerService);
22731
- const instanceService = this._injector.get(_univerjs_core.IUniverInstanceService);
22732
- const currentEditorRender = (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_DOC, instanceService, renderManagerService);
22733
- const docSelectionRenderService = currentEditorRender === null || currentEditorRender === void 0 ? void 0 : currentEditorRender.with(_univerjs_docs_ui.DocSelectionRenderService);
23531
+ const cellEditorRender = this._injector.get(_univerjs_engine_render.IRenderManagerService).getRenderById(_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
23532
+ const docSelectionRenderService = cellEditorRender === null || cellEditorRender === void 0 ? void 0 : cellEditorRender.with(_univerjs_docs_ui.DocSelectionRenderService);
22734
23533
  docSelectionRenderService === null || docSelectionRenderService === void 0 || docSelectionRenderService.focus();
22735
23534
  }));
22736
23535
  }
@@ -22771,7 +23570,7 @@ const useHighlightRange = (ranges = []) => {
22771
23570
  //#endregion
22772
23571
  //#region package.json
22773
23572
  var name = "@univerjs/sheets-ui";
22774
- var version = "1.0.0-alpha.1";
23573
+ var version = "1.0.0-alpha.3";
22775
23574
 
22776
23575
  //#endregion
22777
23576
  //#region src/controllers/cell-alert.controller.ts
@@ -22817,6 +23616,7 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
22817
23616
  this._selectionManagerService = _selectionManagerService;
22818
23617
  _defineProperty(this, "_popupMenuFeatureMap", /* @__PURE__ */ new Map());
22819
23618
  _defineProperty(this, "_popupMenuOffsetMap", /* @__PURE__ */ new Map());
23619
+ _defineProperty(this, "_popupDisposables", /* @__PURE__ */ new Set());
22820
23620
  _defineProperty(this, "_isSelectionMoving", false);
22821
23621
  this._initMoving();
22822
23622
  }
@@ -22865,6 +23665,8 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
22865
23665
  if (callback) return callback(unitId, subUnitId, drawingId, drawingType);
22866
23666
  }
22867
23667
  dispose() {
23668
+ Array.from(this._popupDisposables).forEach((disposable) => disposable.dispose());
23669
+ this._popupDisposables.clear();
22868
23670
  super.dispose();
22869
23671
  this._popupMenuFeatureMap.clear();
22870
23672
  this._popupMenuOffsetMap.clear();
@@ -22995,20 +23797,25 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
22995
23797
  bottom: top + height
22996
23798
  };
22997
23799
  const { position, position$, disposable } = this._createPositionObserver(bound, currentRender, skeleton, worksheet);
23800
+ const popupInjector = this._resolveEmbeddedPopupInjector(unitId, currentRender);
22998
23801
  const id = this._globalPopupManagerService.addPopup({
22999
23802
  ...popup,
23000
23803
  unitId,
23001
23804
  subUnitId,
23805
+ connectorInjector: popupInjector,
23002
23806
  anchorRect: position,
23003
23807
  anchorRect$: position$,
23004
23808
  canvasElement: currentRender.engine.getCanvasElement()
23005
23809
  });
23810
+ const disposableCollection = new _univerjs_core.DisposableCollection();
23811
+ disposableCollection.add(disposable);
23812
+ disposableCollection.add((0, _univerjs_core.toDisposable)(() => {
23813
+ this._globalPopupManagerService.removePopup(id);
23814
+ position$.complete();
23815
+ }));
23816
+ const trackedDisposable = this._trackPopupDisposable(disposableCollection);
23006
23817
  return {
23007
- dispose: () => {
23008
- this._globalPopupManagerService.removePopup(id);
23009
- position$.complete();
23010
- disposable.dispose();
23011
- },
23818
+ dispose: () => trackedDisposable.dispose(),
23012
23819
  canDispose: () => this._globalPopupManagerService.activePopupId !== id
23013
23820
  };
23014
23821
  }
@@ -23032,28 +23839,42 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
23032
23839
  skeleton,
23033
23840
  currentRender
23034
23841
  });
23842
+ const popupInjector = this._resolveEmbeddedPopupInjector(unitId, currentRender);
23035
23843
  const id = this._globalPopupManagerService.addPopup({
23036
23844
  ...popup,
23037
23845
  unitId,
23038
23846
  subUnitId,
23847
+ connectorInjector: popupInjector,
23039
23848
  anchorRect: position,
23040
23849
  anchorRect$: position$,
23041
23850
  hiddenRects$: rects$,
23042
23851
  canvasElement: currentRender.engine.getCanvasElement()
23043
23852
  });
23853
+ const disposableCollection = new _univerjs_core.DisposableCollection();
23854
+ disposableCollection.add(disposable);
23855
+ disposableCollection.add(rectsObserverDisposable);
23856
+ disposableCollection.add((0, _univerjs_core.toDisposable)(() => {
23857
+ this._globalPopupManagerService.removePopup(id);
23858
+ position$.complete();
23859
+ workbook = null;
23860
+ worksheet = null;
23861
+ }));
23862
+ const trackedDisposable = this._trackPopupDisposable(disposableCollection);
23044
23863
  return {
23045
- dispose: () => {
23046
- this._globalPopupManagerService.removePopup(id);
23047
- position$.complete();
23048
- disposable.dispose();
23049
- rectsObserverDisposable.dispose();
23050
- workbook = null;
23051
- worksheet = null;
23052
- },
23864
+ dispose: () => trackedDisposable.dispose(),
23053
23865
  canDispose: () => this._globalPopupManagerService.activePopupId !== id
23054
23866
  };
23055
23867
  }
23056
23868
  attachPopupToAbsolutePosition(bound, popup, _unitId, _subUnitId) {
23869
+ const position$ = new rxjs.BehaviorSubject(bound);
23870
+ const disposable = this._attachAbsolutePopup(bound, position$.asObservable(), popup, _unitId, _subUnitId, () => position$.complete());
23871
+ if (!disposable) position$.complete();
23872
+ return disposable;
23873
+ }
23874
+ attachPopupToDynamicAbsolutePosition(bound, anchorRect$, popup, _unitId, _subUnitId) {
23875
+ return this._attachAbsolutePopup(bound, anchorRect$, popup, _unitId, _subUnitId);
23876
+ }
23877
+ _attachAbsolutePopup(bound, anchorRect$, popup, _unitId, _subUnitId, onDispose) {
23057
23878
  var _this$_renderManagerS3;
23058
23879
  const workbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
23059
23880
  const worksheet = workbook.getActiveSheet();
@@ -23065,20 +23886,24 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
23065
23886
  const currentRender = this._renderManagerService.getRenderById(unitId);
23066
23887
  if (!currentRender || !skeleton) return null;
23067
23888
  if (this._isSelectionMoving && !popup.showOnSelectionMoving) return;
23068
- const position$ = new rxjs.BehaviorSubject(bound);
23889
+ const popupInjector = this._resolveEmbeddedPopupInjector(unitId, currentRender);
23069
23890
  const id = this._globalPopupManagerService.addPopup({
23070
23891
  ...popup,
23071
23892
  unitId,
23072
23893
  subUnitId,
23894
+ connectorInjector: popupInjector,
23073
23895
  anchorRect: bound,
23074
- anchorRect$: position$.asObservable(),
23896
+ anchorRect$,
23075
23897
  canvasElement: currentRender.engine.getCanvasElement()
23076
23898
  });
23899
+ const disposableCollection = new _univerjs_core.DisposableCollection();
23900
+ disposableCollection.add((0, _univerjs_core.toDisposable)(() => {
23901
+ this._globalPopupManagerService.removePopup(id);
23902
+ onDispose === null || onDispose === void 0 || onDispose();
23903
+ }));
23904
+ const trackedDisposable = this._trackPopupDisposable(disposableCollection);
23077
23905
  return {
23078
- dispose: () => {
23079
- this._globalPopupManagerService.removePopup(id);
23080
- position$.complete();
23081
- },
23906
+ dispose: () => trackedDisposable.dispose(),
23082
23907
  canDispose: () => this._globalPopupManagerService.activePopupId !== id
23083
23908
  };
23084
23909
  }
@@ -23115,10 +23940,12 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
23115
23940
  skeleton,
23116
23941
  currentRender
23117
23942
  });
23943
+ const popupInjector = this._resolveEmbeddedPopupInjector(unitId, currentRender);
23118
23944
  const id = this._globalPopupManagerService.addPopup({
23119
23945
  ...popup,
23120
23946
  unitId,
23121
23947
  subUnitId,
23948
+ connectorInjector: popupInjector,
23122
23949
  anchorRect: position,
23123
23950
  anchorRect$: position$,
23124
23951
  canvasElement: currentRender.engine.getCanvasElement(),
@@ -23137,13 +23964,14 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
23137
23964
  startColumn: col,
23138
23965
  endColumn: col
23139
23966
  };
23967
+ const trackedDisposable = this._trackPopupDisposable(disposableCollection);
23140
23968
  disposableCollection.add(this._refRangeService.watchRange(unitId, subUnitId, watchedRange, (_, after) => {
23141
- if (!after) disposableCollection.dispose();
23969
+ if (!after) trackedDisposable.dispose();
23142
23970
  else updateRowCol(after.startRow, after.startColumn);
23143
23971
  }));
23144
23972
  return {
23145
23973
  dispose() {
23146
- disposableCollection.dispose();
23974
+ trackedDisposable.dispose();
23147
23975
  worksheet = null;
23148
23976
  workbook = null;
23149
23977
  },
@@ -23181,10 +24009,12 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
23181
24009
  skeleton,
23182
24010
  currentRender
23183
24011
  });
24012
+ const popupInjector = this._resolveEmbeddedPopupInjector(unitId, currentRender);
23184
24013
  const id = this._globalPopupManagerService.addPopup({
23185
24014
  ...popup,
23186
24015
  unitId,
23187
24016
  subUnitId,
24017
+ connectorInjector: popupInjector,
23188
24018
  anchorRect: position,
23189
24019
  anchorRect$: position$,
23190
24020
  canvasElement: currentRender.engine.getCanvasElement(),
@@ -23199,17 +24029,34 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
23199
24029
  }));
23200
24030
  disposableCollection.add(rectsObserverDisposable);
23201
24031
  const watchedRange = { ...range };
24032
+ const trackedDisposable = this._trackPopupDisposable(disposableCollection);
23202
24033
  disposableCollection.add(this._refRangeService.watchRange(unitId, subUnitId, watchedRange, (_, after) => {
23203
- if (!after) disposableCollection.dispose();
24034
+ if (!after) trackedDisposable.dispose();
23204
24035
  else updateRange(after);
23205
24036
  }));
23206
24037
  return {
23207
24038
  dispose() {
23208
- disposableCollection.dispose();
24039
+ trackedDisposable.dispose();
23209
24040
  },
23210
24041
  canDispose: () => this._globalPopupManagerService.activePopupId !== id
23211
24042
  };
23212
24043
  }
24044
+ _resolveEmbeddedPopupInjector(unitId, currentRender) {
24045
+ var _this$_univerInstance, _currentRender$getInj;
24046
+ return ((_this$_univerInstance = this._univerInstanceService.getUnitCreateOptions(unitId)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.embeddedRender) === true ? (_currentRender$getInj = currentRender.getInjector) === null || _currentRender$getInj === void 0 ? void 0 : _currentRender$getInj.call(currentRender) : void 0;
24047
+ }
24048
+ _trackPopupDisposable(disposable) {
24049
+ let disposed = false;
24050
+ const trackedDisposables = this._popupDisposables;
24051
+ const trackedDisposable = { dispose: () => {
24052
+ if (disposed) return;
24053
+ disposed = true;
24054
+ trackedDisposables.delete(trackedDisposable);
24055
+ disposable.dispose();
24056
+ } };
24057
+ trackedDisposables.add(trackedDisposable);
24058
+ return { dispose: () => trackedDisposable.dispose() };
24059
+ }
23213
24060
  /**
23214
24061
  *
23215
24062
  * @param initialRow
@@ -23225,7 +24072,10 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
23225
24072
  const position$ = new rxjs.BehaviorSubject(position);
23226
24073
  const updatePosition = () => position$.next(this._calcCellPositionByCell(row, col, currentRender, skeleton, activeViewport));
23227
24074
  const disposable = new _univerjs_core.DisposableCollection();
23228
- disposable.add(currentRender.engine.clientRect$.subscribe(() => updatePosition()));
24075
+ disposable.add(currentRender.engine.clientRect$.subscribe({
24076
+ next: () => updatePosition(),
24077
+ error: () => {}
24078
+ }));
23229
24079
  disposable.add((0, _univerjs_core.fromEventSubject)(currentRender.engine.onTransformChange$).pipe((0, rxjs.throttleTime)(16)).subscribe(() => updatePosition()));
23230
24080
  disposable.add(this._commandService.onCommandExecuted((commandInfo) => {
23231
24081
  if (commandInfo.id === _univerjs_sheets.SetWorksheetRowAutoHeightMutation.id) {
@@ -23302,7 +24152,10 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
23302
24152
  rightBottomPos$.next(rightBottomCoord);
23303
24153
  };
23304
24154
  const disposable = new _univerjs_core.DisposableCollection();
23305
- disposable.add(currentRender.engine.clientRect$.subscribe(() => updatePosition()));
24155
+ disposable.add(currentRender.engine.clientRect$.subscribe({
24156
+ next: () => updatePosition(),
24157
+ error: () => {}
24158
+ }));
23306
24159
  disposable.add(this._commandService.onCommandExecuted((commandInfo) => {
23307
24160
  if (commandInfo.id === _univerjs_sheets.SetWorksheetRowAutoHeightMutation.id) {
23308
24161
  if (commandInfo.params.rowsAutoHeightInfo.findIndex((item) => item.row === startRow) > -1) {
@@ -23474,6 +24327,23 @@ let CellPopupManagerService = class CellPopupManagerService extends _univerjs_co
23474
24327
  }
23475
24328
  if (!cache.horizontal && !cache.vertical) subUnitMap.realDeleteValue(row, col);
23476
24329
  }
24330
+ hidePopupsForUnit(unitId, subUnitId) {
24331
+ const unitMap = this._cellPopupMap.get(unitId);
24332
+ if (!unitMap) return;
24333
+ const targets = [];
24334
+ (subUnitId ? [[subUnitId, unitMap.get(subUnitId)]] : [...unitMap.entries()]).forEach(([currentSubUnitId, subUnitMap]) => {
24335
+ subUnitMap === null || subUnitMap === void 0 || subUnitMap.forValue((row, col) => {
24336
+ targets.push({
24337
+ subUnitId: currentSubUnitId,
24338
+ row,
24339
+ col
24340
+ });
24341
+ });
24342
+ });
24343
+ targets.forEach((target) => this.hidePopup(unitId, target.subUnitId, target.row, target.col));
24344
+ if (subUnitId) unitMap.delete(subUnitId);
24345
+ else this._cellPopupMap.delete(unitId);
24346
+ }
23477
24347
  };
23478
24348
  CellPopupManagerService = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(SheetCanvasPopManagerService))], CellPopupManagerService);
23479
24349
 
@@ -24112,56 +24982,6 @@ function BorderLine(props) {
24112
24982
 
24113
24983
  //#endregion
24114
24984
  //#region src/views/border-panel/BorderPanel.tsx
24115
- const BORDER_SIZE_CHILDREN = [
24116
- {
24117
- label: _univerjs_core.BorderStyleTypes.THIN,
24118
- value: _univerjs_core.BorderStyleTypes.THIN
24119
- },
24120
- {
24121
- label: _univerjs_core.BorderStyleTypes.HAIR,
24122
- value: _univerjs_core.BorderStyleTypes.HAIR
24123
- },
24124
- {
24125
- label: _univerjs_core.BorderStyleTypes.DOTTED,
24126
- value: _univerjs_core.BorderStyleTypes.DOTTED
24127
- },
24128
- {
24129
- label: _univerjs_core.BorderStyleTypes.DASHED,
24130
- value: _univerjs_core.BorderStyleTypes.DASHED
24131
- },
24132
- {
24133
- label: _univerjs_core.BorderStyleTypes.DASH_DOT,
24134
- value: _univerjs_core.BorderStyleTypes.DASH_DOT
24135
- },
24136
- {
24137
- label: _univerjs_core.BorderStyleTypes.DASH_DOT_DOT,
24138
- value: _univerjs_core.BorderStyleTypes.DASH_DOT_DOT
24139
- },
24140
- {
24141
- label: _univerjs_core.BorderStyleTypes.MEDIUM,
24142
- value: _univerjs_core.BorderStyleTypes.MEDIUM
24143
- },
24144
- {
24145
- label: _univerjs_core.BorderStyleTypes.MEDIUM_DASHED,
24146
- value: _univerjs_core.BorderStyleTypes.MEDIUM_DASHED
24147
- },
24148
- {
24149
- label: _univerjs_core.BorderStyleTypes.MEDIUM_DASH_DOT,
24150
- value: _univerjs_core.BorderStyleTypes.MEDIUM_DASH_DOT
24151
- },
24152
- {
24153
- label: _univerjs_core.BorderStyleTypes.MEDIUM_DASH_DOT_DOT,
24154
- value: _univerjs_core.BorderStyleTypes.MEDIUM_DASH_DOT_DOT
24155
- },
24156
- {
24157
- label: _univerjs_core.BorderStyleTypes.THICK,
24158
- value: _univerjs_core.BorderStyleTypes.THICK
24159
- },
24160
- {
24161
- label: _univerjs_core.BorderStyleTypes.DOUBLE,
24162
- value: _univerjs_core.BorderStyleTypes.DOUBLE
24163
- }
24164
- ];
24165
24985
  function getBorderColor(borderData) {
24166
24986
  if (!borderData) return;
24167
24987
  for (const key in borderData) {
@@ -24182,7 +25002,9 @@ function BorderPanel(props) {
24182
25002
  var _value$color;
24183
25003
  const iconManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.IconManager);
24184
25004
  const borderStyleManagerService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.BorderStyleManagerService);
24185
- const { isAllValuesSame, value: currentValue } = (0, _univerjs_ui.useDependency)(_univerjs_sheets.SheetsSelectionsService).getCellStylesProperty("bd");
25005
+ const selectionManagerService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.SheetsSelectionsService);
25006
+ const { direction } = (0, react.useContext)(_univerjs_design.ConfigContext);
25007
+ const { isAllValuesSame, value: currentValue } = selectionManagerService.getCellStylesProperty("bd");
24186
25008
  const color = isAllValuesSame ? getBorderColor(currentValue) : void 0;
24187
25009
  const type = isAllValuesSame ? getBorderStyle(currentValue) : void 0;
24188
25010
  const { onChange, value } = props;
@@ -24197,6 +25019,7 @@ function BorderPanel(props) {
24197
25019
  return Icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, { className: "univer-fill-primary-600" });
24198
25020
  }
24199
25021
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
25022
+ dir: direction,
24200
25023
  className: "univer-box-border univer-grid univer-gap-2 univer-p-1.5",
24201
25024
  children: [
24202
25025
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
@@ -26072,7 +26895,7 @@ let ComponentsController = class ComponentsController extends _univerjs_core.Dis
26072
26895
  DeleteRowDoubleIcon: _univerjs_icons.DeleteRowDoubleIcon,
26073
26896
  DownBorderDoubleIcon: _univerjs_icons.DownBorderDoubleIcon,
26074
26897
  DownloadImageIcon: _univerjs_icons.DownloadImageIcon,
26075
- EyeOutlineIcon: _univerjs_icons.EyeOutlineIcon,
26898
+ EyeIcon: _univerjs_icons.EyeIcon,
26076
26899
  FontColorDoubleIcon: _univerjs_icons.FontColorDoubleIcon,
26077
26900
  FontSizeIncreaseIcon: _univerjs_icons.FontSizeIncreaseIcon,
26078
26901
  FontSizeReduceIcon: _univerjs_icons.FontSizeReduceIcon,
@@ -28644,7 +29467,7 @@ let MobileSheetsScrollRenderController = class MobileSheetsScrollRenderControlle
28644
29467
  this.disposeWithMe(viewportMain.onScrollByBar$.subscribeEvent((param) => {
28645
29468
  var _this$_sheetSkeletonM4;
28646
29469
  const skeleton = (_this$_sheetSkeletonM4 = this._sheetSkeletonManagerService.getCurrentParam()) === null || _this$_sheetSkeletonM4 === void 0 ? void 0 : _this$_sheetSkeletonM4.skeleton;
28647
- if (skeleton == null || param.isTrigger === false) return;
29470
+ if (skeleton == null || param.isTrigger === false || param.isBarDragging && !param.isBarDragEnd) return;
28648
29471
  const sheetObject = this._getSheetObject();
28649
29472
  if (skeleton == null || sheetObject == null) return;
28650
29473
  const { viewportScrollX = 0, viewportScrollY = 0 } = param;
@@ -29519,7 +30342,7 @@ function getListDropdownValue(value, multiple) {
29519
30342
  //#endregion
29520
30343
  //#region src/views/dropdown/ListDropDown.tsx
29521
30344
  function SelectList(props) {
29522
- const { value, onChange, multiple, options, title, onEdit, style, location, showEdit: showEditOnDropdown, showSearch: showSearchOnDropdown } = props;
30345
+ const { value, onChange, multiple, options, onEdit, style, location, showEdit: showEditOnDropdown, showSearch: showSearchOnDropdown } = props;
29523
30346
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
29524
30347
  const { row, col, unitId, subUnitId } = location;
29525
30348
  const searchRef = (0, react.useRef)(null);
@@ -29575,7 +30398,7 @@ function SelectList(props) {
29575
30398
  }),
29576
30399
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
29577
30400
  className: "univer-px-3.5 univer-py-1 univer-pt-2 univer-text-xs",
29578
- children: title
30401
+ children: localeService.t(multiple ? "sheets-ui.data-validation.listMultiple.dropdown" : "sheets-ui.data-validation.list.dropdown")
29579
30402
  }),
29580
30403
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
29581
30404
  className: (0, _univerjs_design.clsx)("univer-flex univer-max-h-52 univer-flex-col univer-gap-1 univer-overflow-y-auto univer-px-2 univer-py-1", _univerjs_design.scrollbarClassName),
@@ -29634,7 +30457,6 @@ function ListDropDown(props) {
29634
30457
  const { location, hideFn, onChange, onEdit, options, defaultValue, multiple, showSearch, showEdit } = extraProps;
29635
30458
  const { worksheet } = location;
29636
30459
  if (!worksheet) return null;
29637
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
29638
30460
  const [localValue, setLocalValue] = (0, react.useState)(defaultValue);
29639
30461
  const cellWidth = ((_anchorRect$right = anchorRect === null || anchorRect === void 0 ? void 0 : anchorRect.right) !== null && _anchorRect$right !== void 0 ? _anchorRect$right : 0) - ((_anchorRect$left = anchorRect === null || anchorRect === void 0 ? void 0 : anchorRect.left) !== null && _anchorRect$left !== void 0 ? _anchorRect$left : 0);
29640
30462
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectList, {
@@ -29642,7 +30464,6 @@ function ListDropDown(props) {
29642
30464
  minWidth: cellWidth,
29643
30465
  maxWidth: Math.max(cellWidth, 200)
29644
30466
  },
29645
- title: multiple ? localeService.t("sheets-ui.data-validation.listMultiple.dropdown") : localeService.t("sheets-ui.data-validation.list.dropdown"),
29646
30467
  value: getListDropdownValue(localValue, multiple),
29647
30468
  multiple,
29648
30469
  onChange: async (newValue) => {
@@ -29718,6 +30539,28 @@ SheetCellDropdownManagerService = __decorate([
29718
30539
 
29719
30540
  //#endregion
29720
30541
  //#region src/services/print-interceptor.service.ts
30542
+ /** Tracks asynchronous resources registered by all interceptors for one print page. */
30543
+ var SheetPrintingResourceCollector = class {
30544
+ constructor() {
30545
+ _defineProperty(this, "_pending", /* @__PURE__ */ new Set());
30546
+ }
30547
+ add(resource) {
30548
+ const tracked = Promise.resolve(resource).catch(() => void 0).finally(() => this._pending.delete(tracked));
30549
+ this._pending.add(tracked);
30550
+ }
30551
+ async wait(timeout = 1e4) {
30552
+ const deadline = Date.now() + timeout;
30553
+ while (this._pending.size > 0) {
30554
+ const remaining = deadline - Date.now();
30555
+ if (remaining <= 0) return;
30556
+ let timeoutId;
30557
+ await Promise.race([Promise.allSettled(Array.from(this._pending)), new Promise((resolve) => {
30558
+ timeoutId = setTimeout(resolve, remaining);
30559
+ })]);
30560
+ if (timeoutId !== void 0) clearTimeout(timeoutId);
30561
+ }
30562
+ }
30563
+ };
29721
30564
  const PRINTING_RANGE = (0, _univerjs_core.createInterceptorKey)("PRINTING_RANGE");
29722
30565
  const PRINTING_COMPONENT_COLLECT = (0, _univerjs_core.createInterceptorKey)("PRINTING_COMPONENT_COLLECT");
29723
30566
  const PRINTING_DOM_COLLECT = (0, _univerjs_core.createInterceptorKey)("PRINTING_DOM_COLLECT");
@@ -30524,7 +31367,12 @@ let UniverSheetsMobileUIPlugin = class UniverSheetsMobileUIPlugin extends _unive
30524
31367
  }
30525
31368
  _initAutoFocus() {
30526
31369
  const univerInstanceService = this._univerInstanceService;
30527
- this.disposeWithMe(univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs_operators.filter)((v) => !!v)).subscribe((workbook) => univerInstanceService.focusUnit(workbook.getUnitId())));
31370
+ this.disposeWithMe(univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs_operators.filter)((v) => !!v)).subscribe((workbook) => {
31371
+ const unitId = workbook.getUnitId();
31372
+ const createOptions = univerInstanceService.getUnitCreateOptions(unitId);
31373
+ if ((createOptions === null || createOptions === void 0 ? void 0 : createOptions.makeCurrent) === false) return;
31374
+ univerInstanceService.focusUnit(unitId);
31375
+ }));
30528
31376
  }
30529
31377
  };
30530
31378
  _defineProperty(UniverSheetsMobileUIPlugin, "pluginName", "SHEET_UI_PLUGIN");
@@ -30539,15 +31387,20 @@ UniverSheetsMobileUIPlugin = __decorate([
30539
31387
  __decorateParam(4, _univerjs_core.IUniverInstanceService)
30540
31388
  ], UniverSheetsMobileUIPlugin);
30541
31389
 
31390
+ //#endregion
31391
+ //#region src/services/sheet-host-chrome-override.service.ts
31392
+ const ISheetHostChromeOverrideService = (0, _univerjs_core.createIdentifier)("sheet-ui.host-chrome-override.service");
31393
+
30542
31394
  //#endregion
30543
31395
  //#region src/controllers/render-controllers/contextmenu.render-controller.ts
30544
31396
  let SheetContextMenuRenderController = class SheetContextMenuRenderController extends _univerjs_core.Disposable {
30545
- constructor(_context, _contextMenuService, _selectionManagerService, _selectionRenderService) {
31397
+ constructor(_context, _contextMenuService, _selectionManagerService, _selectionRenderService, _injector) {
30546
31398
  super();
30547
31399
  this._context = _context;
30548
31400
  this._contextMenuService = _contextMenuService;
30549
31401
  this._selectionManagerService = _selectionManagerService;
30550
31402
  this._selectionRenderService = _selectionRenderService;
31403
+ this._injector = _injector;
30551
31404
  this._init();
30552
31405
  }
30553
31406
  _init() {
@@ -30570,6 +31423,7 @@ let SheetContextMenuRenderController = class SheetContextMenuRenderController ex
30570
31423
  }
30571
31424
  };
30572
31425
  const triggerMenu = (position) => {
31426
+ if (this._shouldSuppressHostContextMenu()) return;
30573
31427
  this._contextMenuService.triggerContextMenu(event, position);
30574
31428
  };
30575
31429
  if (!isPointerInRange()) triggerMenu(_univerjs_ui.ContextMenuPosition.MAIN_AREA);
@@ -30581,20 +31435,37 @@ let SheetContextMenuRenderController = class SheetContextMenuRenderController ex
30581
31435
  this.disposeWithMe(spreadsheetSubscription);
30582
31436
  const spreadsheetColumnHeader = this._context.components.get("__SpreadsheetColumnHeader__");
30583
31437
  const rowHeaderSub = this._context.components.get("__SpreadsheetRowHeader__").onPointerDown$.subscribeEvent((event) => {
30584
- if (event.button === 2) this._contextMenuService.triggerContextMenu(event, _univerjs_ui.ContextMenuPosition.ROW_HEADER);
31438
+ if (event.button === 2) {
31439
+ if (this._shouldSuppressHostContextMenu()) return;
31440
+ this._contextMenuService.triggerContextMenu(event, _univerjs_ui.ContextMenuPosition.ROW_HEADER);
31441
+ }
30585
31442
  });
30586
31443
  this.disposeWithMe(rowHeaderSub);
30587
31444
  const colHeaderObserver = spreadsheetColumnHeader.onPointerDown$.subscribeEvent((event) => {
30588
- if (event.button === 2) this._contextMenuService.triggerContextMenu(event, _univerjs_ui.ContextMenuPosition.COL_HEADER);
31445
+ if (event.button === 2) {
31446
+ if (this._shouldSuppressHostContextMenu()) return;
31447
+ this._contextMenuService.triggerContextMenu(event, _univerjs_ui.ContextMenuPosition.COL_HEADER);
31448
+ }
30589
31449
  });
30590
31450
  this.disposeWithMe(colHeaderObserver);
30591
31451
  }
31452
+ _shouldSuppressHostContextMenu() {
31453
+ var _this$_getSheetHostCh, _this$_getSheetHostCh2;
31454
+ 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));
31455
+ }
31456
+ _getSheetHostChromeOverrideService() {
31457
+ return this._injector.has(ISheetHostChromeOverrideService) ? this._injector.get(ISheetHostChromeOverrideService) : void 0;
31458
+ }
30592
31459
  };
30593
31460
  SheetContextMenuRenderController = __decorate([
30594
31461
  __decorateParam(1, _univerjs_ui.IContextMenuService),
30595
31462
  __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
30596
- __decorateParam(3, ISheetSelectionRenderService)
31463
+ __decorateParam(3, ISheetSelectionRenderService),
31464
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
30597
31465
  ], SheetContextMenuRenderController);
31466
+ function shouldSuppressSheetContextMenuForEmbedOverride(hostUnitId, override) {
31467
+ return override != null && override.hostUnitId === hostUnitId && override.entry === "sheets-sheet-tab";
31468
+ }
30598
31469
 
30599
31470
  //#endregion
30600
31471
  //#region src/controllers/repeat-last-action.controller.ts
@@ -31118,7 +31989,12 @@ let UniverSheetsUIPlugin = class UniverSheetsUIPlugin extends _univerjs_core.Plu
31118
31989
  }
31119
31990
  _initAutoFocus() {
31120
31991
  const univerInstanceService = this._univerInstanceService;
31121
- this.disposeWithMe(univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs_operators.filter)((v) => !!v)).subscribe((workbook) => univerInstanceService.focusUnit(workbook.getUnitId())));
31992
+ this.disposeWithMe(univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs_operators.filter)((v) => !!v)).subscribe((workbook) => {
31993
+ const unitId = workbook.getUnitId();
31994
+ const createOptions = univerInstanceService.getUnitCreateOptions(unitId);
31995
+ if ((createOptions === null || createOptions === void 0 ? void 0 : createOptions.makeCurrent) === false) return;
31996
+ univerInstanceService.focusUnit(unitId);
31997
+ }));
31122
31998
  }
31123
31999
  };
31124
32000
  _defineProperty(UniverSheetsUIPlugin, "pluginName", "SHEET_UI_PLUGIN");
@@ -31138,6 +32014,7 @@ exports.AddRangeProtectionFromContextMenuCommand = AddRangeProtectionFromContext
31138
32014
  exports.AddRangeProtectionFromSheetBarCommand = AddRangeProtectionFromSheetBarCommand;
31139
32015
  exports.AddRangeProtectionFromToolbarCommand = AddRangeProtectionFromToolbarCommand;
31140
32016
  exports.ApplyFormatPainterCommand = ApplyFormatPainterCommand;
32017
+ exports.AutoFillPopupMenu = AutoFillPopupMenu;
31141
32018
  Object.defineProperty(exports, 'AutoFillUIController', {
31142
32019
  enumerable: true,
31143
32020
  get: function () {
@@ -31156,7 +32033,10 @@ Object.defineProperty(exports, 'AutoWidthController', {
31156
32033
  return AutoWidthController;
31157
32034
  }
31158
32035
  });
32036
+ exports.BORDER_LINE_CHILDREN = BORDER_LINE_CHILDREN;
32037
+ exports.BORDER_SIZE_CHILDREN = BORDER_SIZE_CHILDREN;
31159
32038
  exports.BaseSelectionRenderService = BaseSelectionRenderService;
32039
+ exports.BorderLine = BorderLine;
31160
32040
  exports.COPY_SPECIAL_MENU_ID = COPY_SPECIAL_MENU_ID;
31161
32041
  exports.COPY_TYPE = COPY_TYPE;
31162
32042
  Object.defineProperty(exports, 'CellAlertManagerService', {
@@ -31211,9 +32091,11 @@ Object.defineProperty(exports, 'EditorBridgeService', {
31211
32091
  return EditorBridgeService;
31212
32092
  }
31213
32093
  });
32094
+ exports.EditorContainer = EditorContainer;
31214
32095
  exports.ExpandSelectionCommand = ExpandSelectionCommand;
31215
32096
  exports.FORMULA_CLIPBOARD_MIME_TYPE = FORMULA_CLIPBOARD_MIME_TYPE;
31216
32097
  exports.FormatPainterStatus = FormatPainterStatus;
32098
+ exports.FormulaBar = FormulaBar;
31217
32099
  Object.defineProperty(exports, 'FormulaEditorController', {
31218
32100
  enumerable: true,
31219
32101
  get: function () {
@@ -31269,6 +32151,11 @@ exports.IMarkSelectionService = IMarkSelectionService;
31269
32151
  exports.IRepeatLastActionService = IRepeatLastActionService;
31270
32152
  exports.ISheetCellDropdownManagerService = ISheetCellDropdownManagerService;
31271
32153
  exports.ISheetClipboardService = ISheetClipboardService;
32154
+ exports.ISheetEmbedFloatingGeometryService = ISheetEmbedFloatingGeometryService;
32155
+ exports.ISheetEmbedInteractionBoundaryService = ISheetEmbedInteractionBoundaryService;
32156
+ exports.ISheetEmbedRuntimeFocusCoordinator = ISheetEmbedRuntimeFocusCoordinator;
32157
+ exports.ISheetEmbedRuntimeService = ISheetEmbedRuntimeService;
32158
+ exports.ISheetHostChromeOverrideService = ISheetHostChromeOverrideService;
31272
32159
  exports.ISheetSelectionRenderService = ISheetSelectionRenderService;
31273
32160
  exports.IStatusBarService = IStatusBarService;
31274
32161
  exports.InsertRangeMoveDownConfirmCommand = InsertRangeMoveDownConfirmCommand;
@@ -31296,6 +32183,15 @@ exports.RepeatLastActionPermission = RepeatLastActionPermission;
31296
32183
  exports.ResetRangeTextColorCommand = ResetRangeTextColorCommand;
31297
32184
  exports.ResetScrollCommand = ResetScrollCommand;
31298
32185
  exports.SELECTION_SHAPE_DEPTH = SELECTION_SHAPE_DEPTH;
32186
+ exports.SHEETS_UI_PLUGIN_CONFIG_KEY = SHEETS_UI_PLUGIN_CONFIG_KEY;
32187
+ exports.SHEET_EMBED_CHILD_TYPE_ATTRIBUTE = SHEET_EMBED_CHILD_TYPE_ATTRIBUTE;
32188
+ exports.SHEET_EMBED_CHILD_UNIT_ID_ATTRIBUTE = SHEET_EMBED_CHILD_UNIT_ID_ATTRIBUTE;
32189
+ exports.SHEET_EMBED_FLOAT_DOM_ATTRIBUTE = SHEET_EMBED_FLOAT_DOM_ATTRIBUTE;
32190
+ exports.SHEET_EMBED_HOST_UNIT_ID_ATTRIBUTE = SHEET_EMBED_HOST_UNIT_ID_ATTRIBUTE;
32191
+ exports.SHEET_EMBED_ID_ATTRIBUTE = SHEET_EMBED_ID_ATTRIBUTE;
32192
+ exports.SHEET_EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE = SHEET_EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE;
32193
+ exports.SHEET_EMBED_RUNTIME_FOCUS_ROLE_ATTRIBUTE = SHEET_EMBED_RUNTIME_FOCUS_ROLE_ATTRIBUTE;
32194
+ exports.SHEET_FOOTER_BAR_HEIGHT = SHEET_FOOTER_BAR_HEIGHT;
31299
32195
  exports.SHEET_UI_PLUGIN_NAME = SHEET_UI_PLUGIN_NAME;
31300
32196
  exports.SHEET_VIEW_KEY = SHEET_VIEW_KEY;
31301
32197
  exports.ScrollCommand = ScrollCommand;
@@ -31336,6 +32232,7 @@ exports.SetSelectionFrozenCommand = SetSelectionFrozenCommand;
31336
32232
  exports.SetWorksheetColAutoWidthCommand = SetWorksheetColAutoWidthCommand;
31337
32233
  exports.SetZoomRatioCommand = SetZoomRatioCommand;
31338
32234
  exports.SetZoomRatioOperation = SetZoomRatioOperation;
32235
+ exports.SheetBar = SheetBar;
31339
32236
  Object.defineProperty(exports, 'SheetCanvasPopManagerService', {
31340
32237
  enumerable: true,
31341
32238
  get: function () {
@@ -31391,6 +32288,7 @@ Object.defineProperty(exports, 'SheetPermissionRenderManagerService', {
31391
32288
  });
31392
32289
  exports.SheetPermissionUserManagerService = SheetPermissionUserManagerService;
31393
32290
  exports.SheetPrintInterceptorService = SheetPrintInterceptorService;
32291
+ exports.SheetPrintingResourceCollector = SheetPrintingResourceCollector;
31394
32292
  Object.defineProperty(exports, 'SheetRenderController', {
31395
32293
  enumerable: true,
31396
32294
  get: function () {
@@ -31485,6 +32383,8 @@ exports.isEmbeddingFormulaEditor = isEmbeddingFormulaEditor;
31485
32383
  exports.isRangeSelector = isRangeSelector;
31486
32384
  exports.menuClipboardDisabledObservable = menuClipboardDisabledObservable;
31487
32385
  exports.mergeSetRangeValues = mergeSetRangeValues;
32386
+ exports.resolveActiveSheetEmbedRuntimeDomScope = resolveActiveSheetEmbedRuntimeDomScope;
32387
+ exports.resolveSheetEmbedRuntimeDomScope = resolveSheetEmbedRuntimeDomScope;
31488
32388
  exports.useActiveWorkbook = useActiveWorkbook;
31489
32389
  exports.useActiveWorksheet = useActiveWorksheet;
31490
32390
  exports.useHighlightRange = useHighlightRange;