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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/lib/cjs/facade.js +5 -5
  2. package/lib/cjs/index.js +1535 -1542
  3. package/lib/cjs/locale/ar-SA.js +14 -133
  4. package/lib/cjs/locale/ca-ES.js +16 -135
  5. package/lib/cjs/locale/de-DE.js +14 -133
  6. package/lib/cjs/locale/en-US.js +14 -133
  7. package/lib/cjs/locale/es-ES.js +14 -133
  8. package/lib/cjs/locale/fa-IR.js +14 -133
  9. package/lib/cjs/locale/fr-FR.js +14 -133
  10. package/lib/cjs/locale/id-ID.js +14 -133
  11. package/lib/cjs/locale/it-IT.js +14 -133
  12. package/lib/cjs/locale/ja-JP.js +14 -133
  13. package/lib/cjs/locale/ko-KR.js +14 -133
  14. package/lib/cjs/locale/pl-PL.js +14 -133
  15. package/lib/cjs/locale/pt-BR.js +14 -133
  16. package/lib/cjs/locale/ru-RU.js +14 -133
  17. package/lib/cjs/locale/sk-SK.js +16 -135
  18. package/lib/cjs/locale/vi-VN.js +14 -133
  19. package/lib/cjs/locale/zh-CN.js +14 -133
  20. package/lib/cjs/locale/zh-HK.js +14 -133
  21. package/lib/cjs/locale/zh-TW.js +14 -133
  22. package/lib/es/facade.js +6 -6
  23. package/lib/es/index.js +1543 -1551
  24. package/lib/es/locale/ar-SA.js +14 -133
  25. package/lib/es/locale/ca-ES.js +16 -135
  26. package/lib/es/locale/de-DE.js +14 -133
  27. package/lib/es/locale/en-US.js +14 -133
  28. package/lib/es/locale/es-ES.js +14 -133
  29. package/lib/es/locale/fa-IR.js +14 -133
  30. package/lib/es/locale/fr-FR.js +14 -133
  31. package/lib/es/locale/id-ID.js +14 -133
  32. package/lib/es/locale/it-IT.js +14 -133
  33. package/lib/es/locale/ja-JP.js +14 -133
  34. package/lib/es/locale/ko-KR.js +14 -133
  35. package/lib/es/locale/pl-PL.js +14 -133
  36. package/lib/es/locale/pt-BR.js +14 -133
  37. package/lib/es/locale/ru-RU.js +14 -133
  38. package/lib/es/locale/sk-SK.js +16 -135
  39. package/lib/es/locale/vi-VN.js +14 -133
  40. package/lib/es/locale/zh-CN.js +14 -133
  41. package/lib/es/locale/zh-HK.js +14 -133
  42. package/lib/es/locale/zh-TW.js +14 -133
  43. package/lib/facade.js +6 -6
  44. package/lib/index.css +54 -87
  45. package/lib/index.js +1543 -1551
  46. package/lib/locale/ar-SA.js +14 -133
  47. package/lib/locale/ca-ES.js +16 -135
  48. package/lib/locale/de-DE.js +14 -133
  49. package/lib/locale/en-US.js +14 -133
  50. package/lib/locale/es-ES.js +14 -133
  51. package/lib/locale/fa-IR.js +14 -133
  52. package/lib/locale/fr-FR.js +14 -133
  53. package/lib/locale/id-ID.js +14 -133
  54. package/lib/locale/it-IT.js +14 -133
  55. package/lib/locale/ja-JP.js +14 -133
  56. package/lib/locale/ko-KR.js +14 -133
  57. package/lib/locale/pl-PL.js +14 -133
  58. package/lib/locale/pt-BR.js +14 -133
  59. package/lib/locale/ru-RU.js +14 -133
  60. package/lib/locale/sk-SK.js +16 -135
  61. package/lib/locale/vi-VN.js +14 -133
  62. package/lib/locale/zh-CN.js +14 -133
  63. package/lib/locale/zh-HK.js +14 -133
  64. package/lib/locale/zh-TW.js +14 -133
  65. package/lib/types/controllers/editor/data-sync.controller.d.ts +4 -2
  66. package/lib/types/controllers/editor/editing.render-controller.d.ts +5 -2
  67. package/lib/types/controllers/force-string-alert-render.controller.d.ts +9 -4
  68. package/lib/types/controllers/render-controllers/contextmenu.render-controller.d.ts +4 -0
  69. package/lib/types/controllers/render-controllers/header-menu.render-controller.d.ts +4 -4
  70. package/lib/types/controllers/render-controllers/scroll.render-controller.d.ts +6 -0
  71. package/lib/types/controllers/utils/range-tools.d.ts +2 -0
  72. package/lib/types/embed-tab-anchor.d.ts +2 -1
  73. package/lib/types/index.d.ts +1 -1
  74. package/lib/types/locale/en-US.d.ts +1 -106
  75. package/lib/types/menu/header-menu-shape.d.ts +3 -3
  76. package/lib/types/services/cell-alert-manager.service.d.ts +6 -0
  77. package/lib/types/services/cell-popup-manager.service.d.ts +6 -7
  78. package/lib/types/services/editor-bridge.service.d.ts +3 -0
  79. package/lib/types/services/sheet-embed-integration.service.d.ts +5 -0
  80. package/lib/types/services/sheet-embed-runtime.service.d.ts +2 -1
  81. package/lib/types/views/CellPopup.d.ts +2 -1
  82. package/lib/types/views/hook.d.ts +0 -4
  83. package/lib/types/views/status-bar/CopyableStatisticItem.d.ts +0 -2
  84. package/lib/types/views/status-bar/StatusBar.d.ts +1 -1
  85. package/lib/umd/facade.js +1 -1
  86. package/lib/umd/index.js +14 -11
  87. package/lib/umd/locale/ar-SA.js +1 -1
  88. package/lib/umd/locale/ca-ES.js +1 -1
  89. package/lib/umd/locale/de-DE.js +1 -1
  90. package/lib/umd/locale/en-US.js +1 -1
  91. package/lib/umd/locale/es-ES.js +1 -1
  92. package/lib/umd/locale/fa-IR.js +1 -1
  93. package/lib/umd/locale/fr-FR.js +1 -1
  94. package/lib/umd/locale/id-ID.js +1 -1
  95. package/lib/umd/locale/it-IT.js +1 -1
  96. package/lib/umd/locale/ja-JP.js +1 -1
  97. package/lib/umd/locale/ko-KR.js +1 -1
  98. package/lib/umd/locale/pl-PL.js +1 -1
  99. package/lib/umd/locale/pt-BR.js +1 -1
  100. package/lib/umd/locale/ru-RU.js +1 -1
  101. package/lib/umd/locale/sk-SK.js +1 -1
  102. package/lib/umd/locale/vi-VN.js +1 -1
  103. package/lib/umd/locale/zh-CN.js +1 -1
  104. package/lib/umd/locale/zh-HK.js +1 -1
  105. package/lib/umd/locale/zh-TW.js +1 -1
  106. package/package.json +14 -14
  107. package/lib/types/services/sheet-loading-render.service.d.ts +0 -65
package/lib/cjs/index.js CHANGED
@@ -10,9 +10,9 @@ let _univerjs_protocol = require("@univerjs/protocol");
10
10
  let _univerjs_design = require("@univerjs/design");
11
11
  let _univerjs_icons = require("@univerjs/icons");
12
12
  let react = require("react");
13
+ let react_jsx_runtime = require("react/jsx-runtime");
13
14
  let _univerjs_engine_formula = require("@univerjs/engine-formula");
14
15
  let _univerjs_telemetry = require("@univerjs/telemetry");
15
- let react_jsx_runtime = require("react/jsx-runtime");
16
16
  let rxjs_operators = require("rxjs/operators");
17
17
 
18
18
  //#region src/basics/editor/get-editor-object.ts
@@ -93,6 +93,40 @@ function whenEditorDidNotInputFormulaActivated(contextService) {
93
93
 
94
94
  //#endregion
95
95
  //#region src/controllers/utils/range-tools.ts
96
+ function groupConsecutive(values, start, end) {
97
+ const groups = [];
98
+ for (let index = start; index <= end; index++) {
99
+ const value = values[index];
100
+ const previous = groups[groups.length - 1];
101
+ if (previous && value === previous.end + 1) previous.end = value;
102
+ else groups.push({
103
+ start: value,
104
+ end: value
105
+ });
106
+ }
107
+ return groups;
108
+ }
109
+ function projectLine(values, start, end) {
110
+ let low = 0;
111
+ let high = values.length;
112
+ while (low < high) {
113
+ const middle = Math.floor((low + high) / 2);
114
+ if (values[middle] < start) low = middle + 1;
115
+ else high = middle;
116
+ }
117
+ const first = low;
118
+ if (first === values.length || values[first] > end) return null;
119
+ high = values.length;
120
+ while (low < high) {
121
+ const middle = Math.floor((low + high) / 2);
122
+ if (values[middle] <= end) low = middle + 1;
123
+ else high = middle;
124
+ }
125
+ return {
126
+ start: first,
127
+ end: low - 1
128
+ };
129
+ }
96
130
  function virtualizeDiscreteRanges(ranges) {
97
131
  let totalRows = [];
98
132
  let totalCols = [];
@@ -116,7 +150,27 @@ function virtualizeDiscreteRanges(ranges) {
116
150
  mapFunc: (row, col) => ({
117
151
  row: totalRows[row],
118
152
  col: totalCols[col]
119
- })
153
+ }),
154
+ mapRange: (range) => {
155
+ const rowGroups = groupConsecutive(totalRows, range.startRow, range.endRow);
156
+ const columnGroups = groupConsecutive(totalCols, range.startColumn, range.endColumn);
157
+ return rowGroups.flatMap((row) => columnGroups.map((column) => ({
158
+ startRow: row.start,
159
+ endRow: row.end,
160
+ startColumn: column.start,
161
+ endColumn: column.end
162
+ })));
163
+ },
164
+ projectRange: (range) => {
165
+ const row = projectLine(totalRows, range.startRow, range.endRow);
166
+ const column = projectLine(totalCols, range.startColumn, range.endColumn);
167
+ return row && column ? {
168
+ startRow: row.start,
169
+ endRow: row.end,
170
+ startColumn: column.start,
171
+ endColumn: column.end
172
+ } : null;
173
+ }
120
174
  };
121
175
  }
122
176
 
@@ -131,7 +185,7 @@ let SELECTION_SHAPE_DEPTH = /* @__PURE__ */ function(SELECTION_SHAPE_DEPTH) {
131
185
  }({});
132
186
  function genNormalSelectionStyle(themeService) {
133
187
  const primaryColor = themeService.getColorFromTheme("primary.600");
134
- const whiteColor = themeService.getColorFromTheme("white");
188
+ const gray0Color = themeService.getColorFromTheme("gray.0");
135
189
  const fill = new _univerjs_core.ColorKit(primaryColor).setAlpha(.07).toRgbString();
136
190
  return {
137
191
  strokeWidth: 1,
@@ -140,10 +194,10 @@ function genNormalSelectionStyle(themeService) {
140
194
  widgets: {},
141
195
  widgetSize: 6,
142
196
  widgetStrokeWidth: 1,
143
- widgetStroke: whiteColor,
197
+ widgetStroke: gray0Color,
144
198
  autofillSize: 6,
145
199
  autofillStrokeWidth: 1,
146
- autofillStroke: whiteColor,
200
+ autofillStroke: gray0Color,
147
201
  rowHeaderFill: fill,
148
202
  rowHeaderStroke: primaryColor,
149
203
  rowHeaderStrokeWidth: 1,
@@ -3070,6 +3124,7 @@ var HtmlToUSMService = class HtmlToUSMService {
3070
3124
  let value = numfmtMatch[1].trim();
3071
3125
  if (value.startsWith("\"") && value.endsWith("\"")) value = value.slice(1, -1);
3072
3126
  const decoded = decodeMsoNumberFormat(value);
3127
+ if (!_univerjs_core.numfmt.isValidFormat(decoded)) continue;
3073
3128
  selectors.split(",").forEach((sel) => {
3074
3129
  this._msoNumfmtMap.set(sel.trim(), decoded);
3075
3130
  });
@@ -4010,6 +4065,10 @@ const IMAGE_MIME_TO_EXTENSION = {
4010
4065
  [_univerjs_ui.FILE__BMP_CLIPBOARD_MIME_TYPE]: "bmp"
4011
4066
  };
4012
4067
  const FORMULA_CLIPBOARD_MIME_TYPE = "web application/x-univer-sheets-formula";
4068
+ function wrapHtmlForExcel(html) {
4069
+ var _html$match;
4070
+ return `<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Excel.Sheet"><meta name="Generator" content="Univer"></head><body><!--StartFragment-->${((_html$match = html.match(/<table[\s\S]*<\/table>/)) === null || _html$match === void 0 ? void 0 : _html$match[0]) ?? html}<!--EndFragment--></body></html>`;
4071
+ }
4013
4072
  /**
4014
4073
  * This service provide hooks for sheet features to supplement content or modify behavior of clipboard.
4015
4074
  */
@@ -4104,7 +4163,7 @@ let SheetClipboardService = class SheetClipboardService extends _univerjs_core.D
4104
4163
  matrix: matrixFragment,
4105
4164
  copyType
4106
4165
  });
4107
- await this._clipboardInterfaceService.write(plain, html, formulaClipboardPayload ? { [FORMULA_CLIPBOARD_MIME_TYPE]: formulaClipboardPayload } : void 0);
4166
+ await this._clipboardInterfaceService.write(plain, wrapHtmlForExcel(html), formulaClipboardPayload ? { [FORMULA_CLIPBOARD_MIME_TYPE]: formulaClipboardPayload } : void 0);
4108
4167
  this._markSelectionService.removeAllShapes();
4109
4168
  const style = createCopyPasteSelectionStyle(this._themeService);
4110
4169
  this._copyMarkId = this._markSelectionService.addShape({
@@ -4124,7 +4183,9 @@ let SheetClipboardService = class SheetClipboardService extends _univerjs_core.D
4124
4183
  const imageIndex = types.findIndex((type) => _univerjs_ui.imageMimeTypeSet.has(type));
4125
4184
  const shouldUseHTMLPaste = imageIndex === -1 || !htmlContainsImage(html);
4126
4185
  if (html && shouldUseHTMLPaste) {
4127
- if (this._platformService.isWindows && htmlIsFromExcel(html)) this._notificationService.show({
4186
+ const copyId = extractId(html);
4187
+ const isInternalCopy = Boolean(copyId && this._copyContentCache.get(copyId));
4188
+ if (this._platformService.isWindows && htmlIsFromExcel(html) && !isInternalCopy) this._notificationService.show({
4128
4189
  type: "warning",
4129
4190
  title: this._localeService.t("sheets-ui.clipboard.shortCutNotify.title"),
4130
4191
  content: this._localeService.t("sheets-ui.clipboard.shortCutNotify.useShortCutInstead")
@@ -7233,6 +7294,9 @@ let SheetsScrollRenderController = class SheetsScrollRenderController extends _u
7233
7294
  this._commandService = _commandService;
7234
7295
  this._renderManagerService = _renderManagerService;
7235
7296
  this._scrollManagerService = _scrollManagerService;
7297
+ _defineProperty(this, "_pendingWheelOffsetX", 0);
7298
+ _defineProperty(this, "_pendingWheelOffsetY", 0);
7299
+ _defineProperty(this, "_pendingWheelFrameId", null);
7236
7300
  this._initCommandListener();
7237
7301
  this._wheelEventListener();
7238
7302
  this._scrollBarEventListener();
@@ -7243,6 +7307,12 @@ let SheetsScrollRenderController = class SheetsScrollRenderController extends _u
7243
7307
  if (!scene) return;
7244
7308
  const viewMain = scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN);
7245
7309
  if (!viewMain) return;
7310
+ this.disposeWithMe((0, _univerjs_core.toDisposable)(() => {
7311
+ if (this._pendingWheelFrameId != null) {
7312
+ cancelAnimationFrame(this._pendingWheelFrameId);
7313
+ this._pendingWheelFrameId = null;
7314
+ }
7315
+ }));
7246
7316
  this.disposeWithMe(scene.onMouseWheel$.subscribeEvent((evt, state) => {
7247
7317
  if (evt.ctrlKey || !this._contextService.getContextValue(_univerjs_core.FOCUSING_SHEET)) return;
7248
7318
  let offsetX = 0;
@@ -7258,14 +7328,15 @@ let SheetsScrollRenderController = class SheetsScrollRenderController extends _u
7258
7328
  if (absOffsetY >= absOffsetX * WHEEL_CROSS_AXIS_LOCK_RATIO) offsetX = 0;
7259
7329
  else if (absOffsetX >= absOffsetY * WHEEL_CROSS_AXIS_LOCK_RATIO) offsetY = 0;
7260
7330
  }
7261
- const targetViewportScrollX = viewMain.viewportScrollX + offsetX;
7262
- const targetViewportScrollY = viewMain.viewportScrollY + offsetY;
7263
- const { x: targetScrollX, y: targetScrollY } = viewMain.transViewportScroll2ScrollValue(targetViewportScrollX, targetViewportScrollY);
7264
- this._commandService.executeCommand(SetScrollRelativeCommand.id, {
7265
- offsetX,
7266
- offsetY
7331
+ this._pendingWheelOffsetX += offsetX;
7332
+ this._pendingWheelOffsetY += offsetY;
7333
+ if (this._pendingWheelFrameId == null) this._pendingWheelFrameId = requestAnimationFrame(() => {
7334
+ this._pendingWheelFrameId = null;
7335
+ this._flushPendingWheelScroll();
7267
7336
  });
7268
- this._context.scene.makeDirty(true);
7337
+ const targetViewportScrollX = viewMain.viewportScrollX + this._pendingWheelOffsetX;
7338
+ const targetViewportScrollY = viewMain.viewportScrollY + this._pendingWheelOffsetY;
7339
+ const { x: targetScrollX, y: targetScrollY } = viewMain.transViewportScroll2ScrollValue(targetViewportScrollX, targetViewportScrollY);
7269
7340
  const isLimitedStore = viewMain.limitedScroll(targetScrollX, targetScrollY);
7270
7341
  if (isLimitedStore && !isLimitedStore.isLimitedX && !isLimitedStore.isLimitedY) {
7271
7342
  evt.preventDefault();
@@ -7274,6 +7345,30 @@ let SheetsScrollRenderController = class SheetsScrollRenderController extends _u
7274
7345
  if (viewMain.isWheelPreventDefaultX && viewMain.isWheelPreventDefaultY) evt.preventDefault();
7275
7346
  }));
7276
7347
  }
7348
+ _flushPendingWheelScroll() {
7349
+ const offsetX = this._pendingWheelOffsetX;
7350
+ const offsetY = this._pendingWheelOffsetY;
7351
+ if (offsetX === 0 && offsetY === 0) return;
7352
+ this._pendingWheelOffsetX = 0;
7353
+ this._pendingWheelOffsetY = 0;
7354
+ const canUseScrollFastPath = this._canUseScrollFastPath();
7355
+ this._commandService.executeCommand(SetScrollRelativeCommand.id, {
7356
+ offsetX,
7357
+ offsetY
7358
+ });
7359
+ this._markSceneDirtyForScrolling(canUseScrollFastPath);
7360
+ }
7361
+ _canUseScrollFastPath() {
7362
+ var _this$_getSheetObject, _spreadsheet$getSkele;
7363
+ const { scene } = this._context;
7364
+ const spreadsheet = (_this$_getSheetObject = this._getSheetObject()) === null || _this$_getSheetObject === void 0 ? void 0 : _this$_getSheetObject.spreadsheet;
7365
+ return scene.getParent().classType === _univerjs_engine_render.RENDER_CLASS_TYPE.ENGINE && !scene.isDirty() && spreadsheet != null && !spreadsheet.isDirty() && !spreadsheet.isForceDirty() && ((_spreadsheet$getSkele = spreadsheet.getSkeleton()) === null || _spreadsheet$getSkele === void 0 ? void 0 : _spreadsheet$getSkele.worksheet.getMergeData().length) === 0 && scene.getViewports().every((viewport) => !viewport.shouldIntoRender() || !viewport.isDirty && !viewport.isForceDirty) && scene.getLayers().every((layer) => layer.getObjectsByOrder().every((object) => !object.isDirty()));
7366
+ }
7367
+ _markSceneDirtyForScrolling(canUseScrollFastPath) {
7368
+ const { scene } = this._context;
7369
+ if (canUseScrollFastPath) scene.makeDirtyForScrolling();
7370
+ else scene.makeDirty(true);
7371
+ }
7277
7372
  _scrollBarEventListener() {
7278
7373
  const { scene } = this._context;
7279
7374
  if (scene == null) return;
@@ -7526,8 +7621,8 @@ let SheetsScrollRenderController = class SheetsScrollRenderController extends _u
7526
7621
  return (0, _univerjs_sheets.getSelectionsService)(this._injector);
7527
7622
  }
7528
7623
  _getViewportBounding() {
7529
- var _this$_getSheetObject, _this$_sheetSkeletonM5;
7530
- const scene = (_this$_getSheetObject = this._getSheetObject()) === null || _this$_getSheetObject === void 0 ? void 0 : _this$_getSheetObject.scene;
7624
+ var _this$_getSheetObject2, _this$_sheetSkeletonM5;
7625
+ const scene = (_this$_getSheetObject2 = this._getSheetObject()) === null || _this$_getSheetObject2 === void 0 ? void 0 : _this$_getSheetObject2.scene;
7531
7626
  if (scene == null) return;
7532
7627
  const viewport = scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN);
7533
7628
  if (viewport == null) return;
@@ -7537,10 +7632,10 @@ let SheetsScrollRenderController = class SheetsScrollRenderController extends _u
7537
7632
  return skeleton.getRangeByViewBound(vpInfo.viewBound);
7538
7633
  }
7539
7634
  _scrollToCell(row, column, forceTop = false, forceLeft = false) {
7540
- var _this$_getSheetObject2, _this$_sheetSkeletonM6;
7635
+ var _this$_getSheetObject3, _this$_sheetSkeletonM6;
7541
7636
  const { rowHeightAccumulation, columnWidthAccumulation } = this._sheetSkeletonManagerService.getCurrentSkeleton() ?? {};
7542
7637
  if (rowHeightAccumulation == null || columnWidthAccumulation == null) return false;
7543
- const scene = (_this$_getSheetObject2 = this._getSheetObject()) === null || _this$_getSheetObject2 === void 0 ? void 0 : _this$_getSheetObject2.scene;
7638
+ const scene = (_this$_getSheetObject3 = this._getSheetObject()) === null || _this$_getSheetObject3 === void 0 ? void 0 : _this$_getSheetObject3.scene;
7544
7639
  if (scene == null) return false;
7545
7640
  const viewport = scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN);
7546
7641
  if (viewport == null) return false;
@@ -8255,7 +8350,8 @@ let EditorBridgeService = class EditorBridgeService extends _univerjs_core.Dispo
8255
8350
  sheetId,
8256
8351
  documentLayoutObject,
8257
8352
  editorUnitId: this._editorUnitId,
8258
- isInArrayFormulaRange: cell === null || cell === void 0 ? void 0 : cell.isInArrayFormulaRange
8353
+ isInArrayFormulaRange: cell === null || cell === void 0 ? void 0 : cell.isInArrayFormulaRange,
8354
+ isPercentFormat: cell === null || cell === void 0 ? void 0 : cell.isPercentFormat
8259
8355
  };
8260
8356
  }
8261
8357
  _getWorkbookForEditUnit(unitId) {
@@ -9241,867 +9337,192 @@ CellCustomRenderController = __decorate([
9241
9337
  ], CellCustomRenderController);
9242
9338
 
9243
9339
  //#endregion
9244
- //#region src/controllers/render-controllers/sheet.render-controller.ts
9245
- const FRAME_STACK_THRESHOLD = 60;
9246
- let SheetRenderController = class SheetRenderController extends _univerjs_core.RxDisposable {
9247
- constructor(_context, _configService, _sheetSkeletonManagerService, _sheetRenderService, _commandService, _telemetryService) {
9248
- super();
9249
- this._context = _context;
9250
- this._configService = _configService;
9251
- this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
9252
- this._sheetRenderService = _sheetRenderService;
9253
- this._commandService = _commandService;
9254
- this._telemetryService = _telemetryService;
9255
- _defineProperty(this, "_renderMetric$", new rxjs.Subject());
9256
- _defineProperty(this, "renderMetric$", this._renderMetric$.asObservable());
9257
- _defineProperty(this, "_renderFrameTimeMetric", null);
9258
- _defineProperty(this, "_renderFrameTags", {});
9259
- _defineProperty(this, "_afterRenderMetric$", new rxjs.Subject());
9260
- this._addNewRender();
9261
- this._initRenderMetricSubscriber();
9340
+ //#region src/views/hook.ts
9341
+ function useActiveWorkbook() {
9342
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
9343
+ return (0, _univerjs_ui.useObservable)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), void 0, void 0, []) ?? null;
9344
+ }
9345
+ function useActiveWorksheet(workbook) {
9346
+ return (0, _univerjs_ui.useObservable)(() => (workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) ?? (0, rxjs.of)(null), void 0, void 0, [workbook]);
9347
+ }
9348
+ function useWorkbooks() {
9349
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
9350
+ return (0, _univerjs_ui.useObservable)(() => {
9351
+ return (0, rxjs.merge)([univerInstanceService.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), univerInstanceService.getTypeOfUnitDisposed$(_univerjs_core.UniverInstanceType.UNIVER_SHEET)]).pipe((0, rxjs.map)(() => univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)), (0, rxjs.startWith)(univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)));
9352
+ }, [], void 0, [univerInstanceService]);
9353
+ }
9354
+
9355
+ //#endregion
9356
+ //#region src/views/clipboard/ClipboardPopupMenu.tsx
9357
+ const DEFAULT_PADDING = 2;
9358
+ const SheetPasteOptions = [
9359
+ {
9360
+ value: "DEFAULT_PASTE",
9361
+ label: "sheets-ui.rightClick.paste"
9362
+ },
9363
+ {
9364
+ value: "SPECIAL_PASTE_VALUE",
9365
+ label: "sheets-ui.rightClick.pasteValue"
9366
+ },
9367
+ {
9368
+ value: "SPECIAL_PASTE_FORMAT",
9369
+ label: "sheets-ui.rightClick.pasteFormat"
9370
+ },
9371
+ {
9372
+ value: "SPECIAL_PASTE_COL_WIDTH",
9373
+ label: "sheets-ui.rightClick.pasteColWidth"
9374
+ },
9375
+ {
9376
+ value: "SPECIAL_PASTE_BESIDES_BORDER",
9377
+ label: "sheets-ui.rightClick.pasteBesidesBorder"
9378
+ },
9379
+ {
9380
+ value: "SPECIAL_PASTE_FORMULA",
9381
+ label: "sheets-ui.rightClick.pasteFormula"
9262
9382
  }
9263
- _addNewRender() {
9264
- const { scene, engine, unit: workbook } = this._context;
9265
- this._addComponent(workbook);
9266
- this._initRerenderScheduler();
9267
- this._initCommandListener();
9268
- const worksheet = this._context.unit.getActiveSheet();
9269
- if (!worksheet) throw new Error("No active sheet found");
9270
- const sheetId = worksheet.getSheetId();
9271
- this._sheetSkeletonManagerService.setCurrent({ sheetId });
9272
- const frameFn = () => scene.render();
9273
- this.disposeWithMe(this._context.activated$.subscribe((activated) => {
9274
- if (activated) engine.runRenderLoop(frameFn);
9275
- else engine.stopRenderLoop(frameFn);
9276
- }));
9277
- }
9278
- _initRenderMetricSubscriber() {
9279
- const { engine } = this._context;
9280
- this.disposeWithMe(engine.beginFrame$.subscribe(() => {
9281
- this._renderFrameTimeMetric = null;
9282
- this._renderFrameTags = {};
9283
- }));
9284
- this.disposeWithMe(engine.endFrame$.subscribe(() => {
9285
- if (this._renderFrameTimeMetric && Object.keys(this._renderFrameTimeMetric).some((key) => key.startsWith(_univerjs_engine_render.SHEET_EXTENSION_PREFIX))) this._afterRenderMetric$.next({
9286
- frameTimeMetric: this._renderFrameTimeMetric,
9287
- tags: this._renderFrameTags
9288
- });
9289
- }));
9290
- this.disposeWithMe(engine.renderFrameTimeMetric$.subscribe(([key, value]) => {
9291
- if (!this._renderFrameTimeMetric) this._renderFrameTimeMetric = {};
9292
- if (!this._renderFrameTimeMetric[key]) this._renderFrameTimeMetric[key] = [];
9293
- this._renderFrameTimeMetric[key].push(Math.round(value * 100) / 100);
9294
- }));
9295
- this.disposeWithMe(engine.renderFrameTags$.subscribe(([key, value]) => {
9296
- this._renderFrameTags[key] = value;
9297
- }));
9298
- const frameInfoList = [];
9299
- this.disposeWithMe(this._afterRenderMetric$.pipe((0, rxjs.withLatestFrom)(engine.endFrame$)).subscribe(([sceneRenderDetail, basicFrameTimeInfo]) => {
9300
- frameInfoList.push({
9301
- FPS: basicFrameTimeInfo.FPS,
9302
- elapsedTime: basicFrameTimeInfo.elapsedTime,
9303
- frameTime: Math.round(basicFrameTimeInfo.frameTime * 100) / 100,
9304
- ...sceneRenderDetail.frameTimeMetric,
9305
- ...sceneRenderDetail.tags
9306
- });
9307
- if (frameInfoList.length > FRAME_STACK_THRESHOLD) {
9308
- this._captureRenderMetric(frameInfoList);
9309
- frameInfoList.length = 0;
9310
- }
9311
- }));
9312
- }
9313
- /**
9314
- * Send render metric to telemetry service
9315
- * @param frameInfoList
9316
- */
9317
- _captureRenderMetric(frameInfoList) {
9318
- var _this$_telemetryServi;
9319
- const filteredFrameInfo = frameInfoList;
9320
- if (filteredFrameInfo.length === 0) return;
9321
- const sumValueForNumListFields = (data) => {
9322
- let totalSum = 0;
9323
- const sums = Object.entries(data).filter(([_, value]) => Array.isArray(value)).map(([key]) => key).reduce((acc, key) => {
9324
- acc[key] = data[key].reduce((sum, num) => sum + num, 0);
9325
- return acc;
9326
- }, {});
9327
- Object.keys(data).filter((key) => key.startsWith(_univerjs_engine_render.SHEET_EXTENSION_PREFIX)).forEach((key) => {
9328
- totalSum += sums[key];
9329
- });
9330
- return {
9331
- ...sums,
9332
- extensionTotal: totalSum
9333
- };
9334
- };
9335
- const frameTimeListAfterSum = frameInfoList.map((info) => {
9336
- return {
9337
- ...info,
9338
- ...sumValueForNumListFields(info)
9339
- };
9340
- });
9341
- const getSummaryStats = (list) => {
9342
- return Object.entries(list[0]).filter(([key, _]) => !["elapsedTime"].includes(key)).filter(([_, value]) => typeof value === "number").map(([key]) => key).reduce((acc, key) => {
9343
- const values = list.map((obj) => obj[key]);
9344
- const max = Math.max(...values);
9345
- const min = Math.min(...values);
9346
- const avg = values.reduce((sum, val) => sum + val, 0) / values.length;
9347
- acc[key] = {
9348
- max: Math.round(max * 100) / 100,
9349
- min: Math.round(min * 100) / 100,
9350
- avg: Math.round(avg * 100) / 100
9351
- };
9352
- return acc;
9353
- }, {});
9354
- };
9355
- const summaryFrameStats = getSummaryStats(frameTimeListAfterSum);
9356
- const elapsedTimeToStart = filteredFrameInfo[filteredFrameInfo.length - 1].elapsedTime;
9357
- const telemetryData = {
9358
- sheetId: this._context.unit.getActiveSheet().getSheetId(),
9359
- unitId: this._context.unit.getUnitId(),
9360
- elapsedTimeToStart,
9361
- ...summaryFrameStats
9362
- };
9363
- this._renderMetric$.next(telemetryData);
9364
- (_this$_telemetryServi = this._telemetryService) === null || _this$_telemetryServi === void 0 || _this$_telemetryServi.capture("sheet_render_cost", telemetryData);
9365
- }
9366
- _addComponent(workbook) {
9367
- const { scene, components } = this._context;
9368
- const worksheet = workbook.getActiveSheet();
9369
- const spreadsheet = new _univerjs_engine_render.Spreadsheet("__SpreadsheetRender__");
9370
- this._addViewport(worksheet);
9371
- const spreadsheetRowHeader = new _univerjs_engine_render.SpreadsheetRowHeader("__SpreadsheetRowHeader__");
9372
- const spreadsheetColumnHeader = new _univerjs_engine_render.SpreadsheetColumnHeader("__SpreadsheetColumnHeader__");
9373
- const SpreadsheetLeftTopPlaceholder = new _univerjs_engine_render.Rect("__SpreadsheetLeftTopPlaceholder__", {
9374
- zIndex: 2,
9375
- left: -1,
9376
- top: -1,
9377
- fill: "rgb(248, 249, 250)",
9378
- stroke: "rgb(217, 217, 217)",
9379
- strokeWidth: 1
9380
- });
9381
- this._context.mainComponent = spreadsheet;
9382
- components.set("__SpreadsheetRender__", spreadsheet);
9383
- components.set("__SpreadsheetRowHeader__", spreadsheetRowHeader);
9384
- components.set("__SpreadsheetColumnHeader__", spreadsheetColumnHeader);
9385
- components.set("__SpreadsheetLeftTopPlaceholder__", SpreadsheetLeftTopPlaceholder);
9386
- scene.addObjects([spreadsheet], 0);
9387
- scene.addObjects([
9388
- spreadsheetRowHeader,
9389
- spreadsheetColumnHeader,
9390
- SpreadsheetLeftTopPlaceholder
9391
- ], 10);
9392
- scene.enableLayerCache(0, 10);
9393
- }
9394
- _initViewports(scene, rowHeader, columnHeader) {
9395
- const rowHeaderWidth = rowHeader.hidden ? 0 : rowHeader.width;
9396
- const columnHeaderHeight = columnHeader.hidden ? 0 : columnHeader.height;
9397
- const bufferEdgeX = 100;
9398
- const bufferEdgeY = 100;
9399
- const viewMain = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN, scene, {
9400
- left: rowHeaderWidth,
9401
- top: columnHeaderHeight,
9402
- bottom: 0,
9403
- right: 0,
9404
- isWheelPreventDefaultX: true,
9405
- allowCache: true,
9406
- bufferEdgeX,
9407
- bufferEdgeY
9408
- });
9409
- const viewMainLeftTop = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP, scene, {
9410
- isWheelPreventDefaultX: true,
9411
- active: false,
9412
- allowCache: true,
9413
- bufferEdgeX: 0,
9414
- bufferEdgeY: 0
9415
- });
9416
- const viewMainLeft = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT, scene, {
9417
- isWheelPreventDefaultX: true,
9418
- active: false,
9419
- allowCache: true,
9420
- bufferEdgeX: 0,
9421
- bufferEdgeY
9422
- });
9423
- const viewMainTop = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP, scene, {
9424
- isWheelPreventDefaultX: true,
9425
- active: false,
9426
- allowCache: true,
9427
- bufferEdgeX,
9428
- bufferEdgeY: 0
9429
- });
9430
- const viewRowTop = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP, scene, {
9431
- active: false,
9432
- isWheelPreventDefaultX: true
9433
- });
9434
- const viewRowBottom = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM, scene, {
9435
- left: 0,
9436
- top: columnHeaderHeight,
9437
- bottom: 0,
9438
- width: rowHeaderWidth + 1,
9439
- isWheelPreventDefaultX: true
9440
- });
9441
- const viewColumnLeft = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT, scene, {
9442
- active: false,
9443
- isWheelPreventDefaultX: true
9444
- });
9445
- const viewColumnRight = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT, scene, {
9446
- left: rowHeaderWidth,
9447
- top: 0,
9448
- height: columnHeaderHeight + 1,
9449
- right: 0,
9450
- isWheelPreventDefaultX: true
9451
- });
9452
- return {
9453
- viewMain,
9454
- viewLeftTop: new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP, scene, {
9455
- left: 0,
9456
- top: 0,
9457
- width: rowHeaderWidth,
9458
- height: columnHeaderHeight,
9459
- isWheelPreventDefaultX: true
9460
- }),
9461
- viewMainLeftTop,
9462
- viewMainLeft,
9463
- viewMainTop,
9464
- viewColumnLeft,
9465
- viewRowTop,
9466
- viewRowBottom,
9467
- viewColumnRight
9468
- };
9469
- }
9470
- /**
9471
- *
9472
- * initViewport & wheel event
9473
- * +-----------------+--------------------+-------------------+
9474
- * | VIEW_LEFT_TOP | VIEW_COLUMN_LEFT | VIEW_COLUMN_RIGHT |
9475
- * +-----------------+--------------------+-------------------+
9476
- * | VIEW_ROW_TOP | VIEW_MAIN_LEFT_TOP | VIEW_MAIN_TOP |
9477
- * +-----------------+--------------------+-------------------+
9478
- * | VIEW_ROW_BOTTOM | VIEW_MAIN_LEFT | VIEW_MAIN |
9479
- * +-----------------+--------------------+-------------------+
9480
- */
9481
- _addViewport(worksheet) {
9482
- const scene = this._context.scene;
9483
- const { rowHeader, columnHeader } = worksheet.getConfig();
9484
- const { viewMain } = this._initViewports(scene, rowHeader, columnHeader);
9485
- const sheetsUIConfig = this._configService.getConfig(SHEETS_UI_PLUGIN_CONFIG_KEY);
9486
- new _univerjs_engine_render.ScrollBar(viewMain, sheetsUIConfig === null || sheetsUIConfig === void 0 ? void 0 : sheetsUIConfig.scrollConfig);
9487
- scene.attachControl();
9488
- return viewMain;
9489
- }
9490
- _initRerenderScheduler() {
9491
- this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe((param) => {
9492
- if (!param) return null;
9493
- const { skeleton: spreadsheetSkeleton, sheetId } = param;
9494
- const workbook = this._context.unit;
9495
- const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(sheetId);
9496
- if (workbook == null || worksheet == null) return;
9497
- const { mainComponent, components } = this._context;
9498
- const spreadsheet = mainComponent;
9499
- const spreadsheetRowHeader = components.get("__SpreadsheetRowHeader__");
9500
- const spreadsheetColumnHeader = components.get("__SpreadsheetColumnHeader__");
9501
- const spreadsheetLeftTopPlaceholder = components.get("__SpreadsheetLeftTopPlaceholder__");
9502
- const leftTopPlaceholderSize = getLeftTopPlaceholderSize(spreadsheetSkeleton);
9503
- spreadsheet === null || spreadsheet === void 0 || spreadsheet.updateSkeleton(spreadsheetSkeleton);
9504
- spreadsheetRowHeader === null || spreadsheetRowHeader === void 0 || spreadsheetRowHeader.updateSkeleton(spreadsheetSkeleton);
9505
- spreadsheetColumnHeader === null || spreadsheetColumnHeader === void 0 || spreadsheetColumnHeader.updateSkeleton(spreadsheetSkeleton);
9506
- spreadsheetLeftTopPlaceholder === null || spreadsheetLeftTopPlaceholder === void 0 || spreadsheetLeftTopPlaceholder.transformByState({
9507
- width: leftTopPlaceholderSize.width,
9508
- height: leftTopPlaceholderSize.height
9509
- });
9510
- }));
9511
- }
9512
- _initCommandListener() {
9513
- this.disposeWithMe(this._commandService.onCommandExecuted((command, options) => {
9514
- const { unit: workbook } = this._context;
9515
- const { id: commandId } = command;
9516
- if (_univerjs_sheets.COMMAND_LISTENER_SKELETON_CHANGE.includes(commandId) || this._sheetRenderService.checkMutationShouldTriggerRerender(commandId)) {
9517
- const { unitId, subUnitId } = command.params;
9518
- const worksheet = workbook.getActiveSheet();
9519
- if (!worksheet) return;
9520
- const workbookId = this._context.unitId;
9521
- const worksheetId = worksheet.getSheetId();
9522
- if (unitId !== workbookId || subUnitId !== worksheetId) return;
9523
- this._sheetSkeletonManagerService.makeDirty({
9524
- sheetId: worksheetId,
9525
- commandId
9526
- }, true);
9527
- this._sheetSkeletonManagerService.setCurrent({
9528
- sheetId: worksheetId,
9529
- commandId
9530
- });
9531
- } else if (_univerjs_sheets.COMMAND_LISTENER_VALUE_CHANGE.includes(commandId)) this._sheetSkeletonManagerService.reCalculate();
9532
- if (command.type === _univerjs_core.CommandType.MUTATION) this._markUnitDirty(command, options);
9533
- }));
9534
- }
9535
- _markUnitDirty(command, options) {
9536
- if (command.id.substring(0, 3) === "doc") return;
9537
- const { mainComponent: spreadsheet, scene } = this._context;
9538
- if (command.id === _univerjs_engine_formula.SetFormulaCalculationNotificationMutation.id) {
9539
- if (command.params.stageInfo != null) return;
9540
- }
9541
- if (spreadsheet) spreadsheet.makeDirty();
9542
- scene.makeDirty();
9543
- if (!command.params) return;
9544
- const cmdParams = command.params;
9545
- const viewports = this._spreadsheetViewports(scene);
9546
- if (command.id === _univerjs_sheets.SetRangeValuesMutation.id && cmdParams.cellValue && !(options === null || options === void 0 ? void 0 : options.fromChangeset)) {
9547
- const dirtyRange = this._cellValueToRange(cmdParams.cellValue);
9548
- const dirtyBounds = this._rangeToBounds([dirtyRange]);
9549
- this._markViewportDirty(viewports, dirtyBounds);
9550
- spreadsheet.setDirtyArea(dirtyBounds);
9551
- }
9552
- if (command.id === _univerjs_sheets.MoveRangeMutation.id && cmdParams.from && cmdParams.to && !(options === null || options === void 0 ? void 0 : options.fromChangeset)) {
9553
- const fromRange = cmdParams.fromRange || this._cellValueToRange(cmdParams.from.value);
9554
- const toRange = cmdParams.toRange || this._cellValueToRange(cmdParams.to.value);
9555
- const dirtyBounds = this._rangeToBounds([fromRange, toRange]);
9556
- this._markViewportDirty(viewports, dirtyBounds);
9557
- spreadsheet.setDirtyArea(dirtyBounds);
9558
- }
9559
- }
9560
- /**
9561
- * cellValue data structure:
9562
- * {[row]: { [col]: value}}
9563
- * @param cellValue
9564
- * @returns IRange
9565
- */
9566
- _cellValueToRange(cellValue) {
9567
- const columns = [];
9568
- let minCol = 0;
9569
- let maxCol = 0;
9570
- let minRow = 0;
9571
- let maxRow = 0;
9572
- for (const [_row, columnObj] of Object.entries(cellValue)) {
9573
- for (const column in columnObj) {
9574
- columns.push(Number(column));
9575
- if (minCol > Number(column)) minCol = Number(column);
9576
- if (maxCol < Number(column)) maxCol = Number(column);
9577
- }
9578
- if (minRow > Number(_row)) minRow = Number(_row);
9579
- if (maxRow < Number(_row)) maxRow = Number(_row);
9580
- }
9581
- return {
9582
- startRow: minRow,
9583
- endRow: maxRow,
9584
- startColumn: minCol,
9585
- endColumn: maxCol
9586
- };
9587
- }
9588
- _rangeToBounds(ranges) {
9589
- const { rowHeightAccumulation, columnWidthAccumulation, rowHeaderWidth, columnHeaderHeight } = this._sheetSkeletonManagerService.getCurrentParam().skeleton;
9590
- const dirtyBounds = [];
9591
- for (const r of ranges) {
9592
- const { startRow, endRow, startColumn, endColumn } = r;
9593
- const top = startRow === 0 ? 0 : rowHeightAccumulation[startRow - 1] + columnHeaderHeight;
9594
- const bottom = rowHeightAccumulation[endRow] + columnHeaderHeight;
9595
- const left = startColumn === 0 ? 0 : columnWidthAccumulation[startColumn - 1] + rowHeaderWidth;
9596
- const right = columnWidthAccumulation[endColumn] + rowHeaderWidth;
9597
- dirtyBounds.push({
9598
- top,
9599
- left,
9600
- bottom,
9601
- right,
9602
- width: right - left,
9603
- height: bottom - top
9604
- });
9605
- }
9606
- return dirtyBounds;
9607
- }
9608
- _markViewportDirty(viewports, dirtyBounds) {
9609
- const activeViewports = viewports.filter((vp) => vp.isActive && vp.cacheBound);
9610
- for (const vp of activeViewports) for (const b of dirtyBounds) if (_univerjs_core.Rectangle.hasIntersectionBetweenTwoRect(vp.cacheBound, b)) vp.markDirty(true);
9611
- }
9612
- _spreadsheetViewports(scene) {
9613
- return scene.getViewports().filter((v) => [
9614
- "viewMain",
9615
- "viewMainLeftTop",
9616
- "viewMainTop",
9617
- "viewMainLeft"
9618
- ].includes(v.viewportKey));
9619
- }
9620
- };
9621
- SheetRenderController = __decorate([
9622
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.IConfigService)),
9623
- __decorateParam(2, (0, _univerjs_core.Inject)(SheetSkeletonManagerService)),
9624
- __decorateParam(3, (0, _univerjs_core.Inject)(SheetsRenderService)),
9625
- __decorateParam(4, _univerjs_core.ICommandService),
9626
- __decorateParam(5, (0, _univerjs_core.Optional)(_univerjs_telemetry.ITelemetryService))
9627
- ], SheetRenderController);
9628
- function getLeftTopPlaceholderSize(skeleton) {
9629
- return {
9630
- width: skeleton.rowHeaderWidthAndMarginLeft ?? skeleton.rowHeaderWidth,
9631
- height: skeleton.columnHeaderHeightAndMarginTop ?? skeleton.columnHeaderHeight
9632
- };
9633
- }
9634
-
9635
- //#endregion
9636
- //#region src/controllers/render-controllers/skeleton.render-controller.ts
9637
- let SheetSkeletonRenderController = class SheetSkeletonRenderController extends _univerjs_core.Disposable {
9638
- constructor(_context, _sheetSkeletonManagerService, _renderManagerService) {
9639
- super();
9640
- this._context = _context;
9641
- this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
9642
- this._renderManagerService = _renderManagerService;
9643
- this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe((param) => {
9644
- this._updateSceneSize(param);
9645
- }));
9646
- }
9647
- _updateSceneSize(param) {
9648
- var _this$_renderManagerS;
9649
- if (param == null) return;
9650
- const { unitId } = this._context;
9651
- const { skeleton } = param;
9652
- const scene = (_this$_renderManagerS = this._renderManagerService.getRenderUnitById(unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.scene;
9653
- if (skeleton == null || scene == null) return;
9654
- const { rowTotalHeight, columnTotalWidth, rowHeaderWidthAndMarginLeft, columnHeaderHeightAndMarginTop } = skeleton;
9655
- if (!this._context.unit.getActiveSheet()) return;
9656
- scene === null || scene === void 0 || scene.transformByState({
9657
- width: rowHeaderWidthAndMarginLeft + columnTotalWidth,
9658
- height: columnHeaderHeightAndMarginTop + rowTotalHeight
9659
- });
9660
- scene.getMainViewport().setMargin(rowHeaderWidthAndMarginLeft, columnHeaderHeightAndMarginTop);
9661
- }
9662
- };
9663
- SheetSkeletonRenderController = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(SheetSkeletonManagerService)), __decorateParam(2, _univerjs_engine_render.IRenderManagerService)], SheetSkeletonRenderController);
9664
-
9665
- //#endregion
9666
- //#region src/services/sheet-loading-render.service.ts
9667
- const PREVIEW_UNIT_SUFFIX = "__snapshot_loading_preview__";
9668
- const PREVIEW_SCENE_PREFIX = "_UNIVER_SCENE_";
9669
- const PREVIEW_CANVAS_Z_INDEX = "9";
9670
- const ISheetLoadingRenderService = (0, _univerjs_core.createIdentifier)("sheets-ui.sheet-loading-render.service");
9671
- let SheetLoadingRenderService = class SheetLoadingRenderService extends _univerjs_core.Disposable {
9672
- constructor(_injector, _layoutService, _sheetInterceptorService, _renderManagerService) {
9673
- super();
9674
- this._injector = _injector;
9675
- this._layoutService = _layoutService;
9676
- this._sheetInterceptorService = _sheetInterceptorService;
9677
- this._renderManagerService = _renderManagerService;
9678
- _defineProperty(this, "workbook$", new rxjs.BehaviorSubject(null));
9679
- _defineProperty(this, "loading$", new rxjs.BehaviorSubject(false));
9680
- _defineProperty(this, "previewReady$", new rxjs.BehaviorSubject(false));
9681
- _defineProperty(this, "_loadingRender", null);
9682
- _defineProperty(this, "_finalCanvasGuard", null);
9683
- _defineProperty(this, "_hiddenFinalCanvas", null);
9684
- _defineProperty(this, "_finalCanvasVisibility", "");
9685
- }
9686
- showSkeleton(workbookData, activeSheetId) {
9687
- var _this$_loadingRender;
9688
- const sourceUnitId = workbookData.id;
9689
- if (((_this$_loadingRender = this._loadingRender) === null || _this$_loadingRender === void 0 ? void 0 : _this$_loadingRender.sourceUnitId) !== sourceUnitId) {
9690
- this._disposeLoadingRender();
9691
- this.previewReady$.next(false);
9692
- this._loadingRender = {
9693
- sourceUnitId,
9694
- workbook: this._createLoadingWorkbook(workbookData, activeSheetId),
9695
- render: null
9696
- };
9697
- this.workbook$.next(this._loadingRender.workbook);
9698
- this.loading$.next(true);
9699
- this._guardFinalCanvas(sourceUnitId);
9700
- }
9701
- const worksheet = this._loadingRender.workbook.getSheetBySheetId(activeSheetId);
9702
- if (worksheet && this._loadingRender.workbook.getActiveSheet().getSheetId() !== activeSheetId) this._loadingRender.workbook.setActiveSheet(worksheet);
9703
- }
9704
- show(workbookData, activeSheetId, cellData) {
9705
- this.showSkeleton(workbookData, activeSheetId);
9706
- const loadingRender = this._loadingRender;
9707
- if (!loadingRender) return;
9708
- let shouldRender = false;
9709
- if (!loadingRender.render) {
9710
- const contentElement = this._layoutService.getContentElement();
9711
- if (!contentElement) return;
9712
- loadingRender.render = this._createLoadingRender(loadingRender.workbook, loadingRender.sourceUnitId, contentElement);
9713
- shouldRender = true;
9714
- }
9715
- const worksheet = loadingRender.workbook.getSheetBySheetId(activeSheetId);
9716
- if (!worksheet) return;
9717
- if (loadingRender.workbook.getActiveSheet().getSheetId() !== activeSheetId) {
9718
- loadingRender.workbook.setActiveSheet(worksheet);
9719
- loadingRender.render.with(SheetSkeletonManagerService).setCurrent({ sheetId: activeSheetId });
9720
- shouldRender = true;
9721
- }
9722
- if (cellData && cellData !== loadingRender.lastCellData) {
9723
- loadingRender.lastCellData = cellData;
9724
- const target = worksheet.getCellMatrix();
9725
- const getDisplayCell = this._sheetInterceptorService.fetchThroughInterceptors(_univerjs_sheets.INTERCEPTOR_POINT.CELL_CONTENT, _univerjs_core.InterceptorEffectEnum.Value | _univerjs_core.InterceptorEffectEnum.Style);
9726
- new _univerjs_core.ObjectMatrix(cellData).forValue((row, column, rawData) => {
9727
- const displayCell = getDisplayCell(rawData, {
9728
- unitId: loadingRender.sourceUnitId,
9729
- subUnitId: activeSheetId,
9730
- row,
9731
- col: column,
9732
- workbook: loadingRender.workbook,
9733
- worksheet,
9734
- rawData
9735
- });
9736
- target.setValue(row, column, displayCell);
9737
- });
9738
- const skeletonManager = loadingRender.render.with(SheetSkeletonManagerService);
9739
- skeletonManager.makeDirty({ sheetId: activeSheetId });
9740
- skeletonManager.reCalculate();
9741
- if (loadingRender.render.mainComponent instanceof _univerjs_engine_render.Spreadsheet) loadingRender.render.mainComponent.makeForceDirty(true);
9742
- loadingRender.render.scene.makeDirty(true);
9743
- shouldRender = true;
9744
- }
9745
- if (shouldRender) loadingRender.render.scene.render();
9746
- if (!this.previewReady$.value) this.previewReady$.next(true);
9747
- }
9748
- async handoff(sourceUnitId, timeoutMs) {
9749
- var _this$_loadingRender2, _this$_finalCanvasGua;
9750
- if (((_this$_loadingRender2 = this._loadingRender) === null || _this$_loadingRender2 === void 0 ? void 0 : _this$_loadingRender2.sourceUnitId) !== sourceUnitId) return true;
9751
- if (!this._loadingRender.render) {
9752
- this.hide(sourceUnitId);
9753
- return true;
9754
- }
9755
- (_this$_finalCanvasGua = this._finalCanvasGuard) === null || _this$_finalCanvasGua === void 0 || _this$_finalCanvasGua.unsubscribe();
9756
- this._finalCanvasGuard = null;
9757
- try {
9758
- await (0, rxjs.firstValueFrom)(this._getFinalRender$(sourceUnitId).pipe((0, rxjs.take)(1), (0, rxjs.switchMap)((render) => this._waitForFinalCanvas(render).pipe((0, rxjs.switchMap)(() => {
9759
- this._hideFinalCanvas(render);
9760
- return this._requestFinalRender(render);
9761
- }))), (0, rxjs.timeout)(timeoutMs)));
9762
- this.hide(sourceUnitId);
9763
- return true;
9764
- } catch {
9765
- return false;
9766
- }
9767
- }
9768
- hide(sourceUnitId) {
9769
- var _this$_loadingRender3;
9770
- if (((_this$_loadingRender3 = this._loadingRender) === null || _this$_loadingRender3 === void 0 ? void 0 : _this$_loadingRender3.sourceUnitId) !== sourceUnitId) return;
9771
- this._disposeLoadingRender();
9772
- }
9773
- dispose() {
9774
- this._disposeLoadingRender();
9775
- this.workbook$.complete();
9776
- this.loading$.complete();
9777
- this.previewReady$.complete();
9778
- super.dispose();
9779
- }
9780
- _createLoadingWorkbook(workbookData, activeSheetId) {
9781
- const previewUnitId = `${workbookData.id}${PREVIEW_UNIT_SUFFIX}`;
9782
- const workbook = this._injector.createInstance(_univerjs_core.Workbook, {
9783
- ...workbookData,
9784
- id: previewUnitId
9785
- });
9786
- const activeSheet = workbook.getSheetBySheetId(activeSheetId);
9787
- if (activeSheet) workbook.setActiveSheet(activeSheet);
9788
- return workbook;
9789
- }
9790
- _createLoadingRender(workbook, sourceUnitId, contentElement) {
9791
- const previewUnitId = workbook.getUnitId();
9792
- const { width, height } = contentElement.getBoundingClientRect();
9793
- const engine = this._injector.createInstance(_univerjs_engine_render.Engine, previewUnitId, void 0);
9794
- const scene = new _univerjs_engine_render.Scene(`${PREVIEW_SCENE_PREFIX}${previewUnitId}`, engine, {
9795
- width,
9796
- height
9797
- });
9798
- scene.disableObjectsEvent();
9799
- const render = this._injector.createInstance(_univerjs_engine_render.RenderUnit, {
9800
- unit: workbook,
9801
- engine,
9802
- scene,
9803
- isMainScene: true
9804
- });
9805
- try {
9806
- render.addRenderDependencies([
9807
- [SheetSkeletonManagerService],
9808
- [SheetSkeletonRenderController],
9809
- [SheetRenderController]
9810
- ]);
9811
- const canvas = engine.getCanvas();
9812
- canvas.setId(`univer-sheet-loading-canvas_${sourceUnitId}`);
9813
- canvas.getCanvasEle().dataset.uUnitId = sourceUnitId;
9814
- canvas.getCanvasEle().style.pointerEvents = "none";
9815
- canvas.getCanvasEle().style.zIndex = PREVIEW_CANVAS_Z_INDEX;
9816
- engine.mount(contentElement);
9817
- return render;
9818
- } catch (error) {
9819
- this._disposeRender(render);
9820
- throw error;
9821
- }
9822
- }
9823
- _waitForFinalCanvas(render) {
9824
- return new rxjs.Observable((subscriber) => {
9825
- let frameId;
9826
- const canvasElement = render.engine.getCanvasElement();
9827
- const checkMounted = () => {
9828
- const contentElement = this._layoutService.getContentElement();
9829
- if (contentElement && canvasElement.parentElement === contentElement && canvasElement.width > 0 && canvasElement.height > 0) {
9830
- subscriber.next();
9831
- subscriber.complete();
9832
- return;
9833
- }
9834
- frameId = window.requestAnimationFrame(checkMounted);
9835
- };
9836
- checkMounted();
9837
- return () => {
9838
- if (frameId !== void 0) window.cancelAnimationFrame(frameId);
9839
- };
9840
- });
9841
- }
9842
- _getFinalRender$(sourceUnitId) {
9843
- const existingRender = this._renderManagerService.getRenderUnitById(sourceUnitId);
9844
- return existingRender ? (0, rxjs.of)(existingRender) : this._renderManagerService.created$.pipe((0, rxjs.filter)((render) => render.unitId === sourceUnitId));
9845
- }
9846
- _guardFinalCanvas(sourceUnitId) {
9847
- var _this$_finalCanvasGua2;
9848
- (_this$_finalCanvasGua2 = this._finalCanvasGuard) === null || _this$_finalCanvasGua2 === void 0 || _this$_finalCanvasGua2.unsubscribe();
9849
- this._finalCanvasGuard = this._getFinalRender$(sourceUnitId).pipe((0, rxjs.take)(1), (0, rxjs.switchMap)((render) => this._waitForFinalCanvas(render).pipe((0, rxjs.map)(() => render)))).subscribe((render) => this._hideFinalCanvas(render));
9850
- }
9851
- _requestFinalRender(render) {
9852
- render.scene.makeDirty(true);
9853
- return (0, rxjs.from)(render.scene.requestRender()).pipe((0, rxjs.switchMap)(() => this._waitForNextAnimationFrame()));
9854
- }
9855
- _hideFinalCanvas(render) {
9856
- const canvasElement = render.engine.getCanvasElement();
9857
- if (this._hiddenFinalCanvas === canvasElement) return;
9858
- this._restoreFinalCanvas();
9859
- this._hiddenFinalCanvas = canvasElement;
9860
- this._finalCanvasVisibility = canvasElement.style.visibility;
9861
- canvasElement.style.visibility = "hidden";
9862
- }
9863
- _restoreFinalCanvas() {
9864
- if (!this._hiddenFinalCanvas) return;
9865
- this._hiddenFinalCanvas.style.visibility = this._finalCanvasVisibility;
9866
- this._hiddenFinalCanvas = null;
9867
- this._finalCanvasVisibility = "";
9868
- }
9869
- _waitForNextAnimationFrame() {
9870
- return new rxjs.Observable((subscriber) => {
9871
- const frameId = window.requestAnimationFrame(() => {
9872
- subscriber.next();
9873
- subscriber.complete();
9874
- });
9875
- return () => window.cancelAnimationFrame(frameId);
9876
- });
9877
- }
9878
- _disposeLoadingRender() {
9879
- var _this$_finalCanvasGua3;
9880
- (_this$_finalCanvasGua3 = this._finalCanvasGuard) === null || _this$_finalCanvasGua3 === void 0 || _this$_finalCanvasGua3.unsubscribe();
9881
- this._finalCanvasGuard = null;
9882
- this._restoreFinalCanvas();
9883
- const loadingRender = this._loadingRender;
9884
- this._loadingRender = null;
9885
- this.workbook$.next(null);
9886
- this.loading$.next(false);
9887
- this.previewReady$.next(false);
9888
- if (!loadingRender) return;
9889
- if (loadingRender.render) this._disposeRender(loadingRender.render);
9890
- loadingRender.workbook.dispose();
9891
- }
9892
- _disposeRender(render) {
9893
- render.components.forEach((component) => component.dispose());
9894
- render.scene.dispose();
9895
- render.dispose();
9896
- render.engine.dispose();
9897
- }
9898
- };
9899
- SheetLoadingRenderService = __decorate([
9900
- __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
9901
- __decorateParam(1, _univerjs_ui.ILayoutService),
9902
- __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
9903
- __decorateParam(3, _univerjs_engine_render.IRenderManagerService)
9904
- ], SheetLoadingRenderService);
9905
-
9906
- //#endregion
9907
- //#region src/views/hook.ts
9908
- const SheetLoadingWorkbookContext = (0, react.createContext)(null);
9909
- function useActiveWorkbook() {
9910
- const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
9911
- const loadingWorkbook = (0, react.useContext)(SheetLoadingWorkbookContext);
9912
- const workbook = (0, _univerjs_ui.useObservable)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), void 0, void 0, []);
9913
- return loadingWorkbook ?? workbook ?? null;
9914
- }
9915
- function useSheetLoadingWorkbook() {
9916
- return (0, _univerjs_ui.useObservable)((0, _univerjs_ui.useDependency)(ISheetLoadingRenderService).workbook$) ?? null;
9917
- }
9918
- function useSheetLoading() {
9919
- return (0, _univerjs_ui.useObservable)((0, _univerjs_ui.useDependency)(ISheetLoadingRenderService).loading$) ?? false;
9920
- }
9921
- function useSheetLoadingPreviewReady() {
9922
- return (0, _univerjs_ui.useObservable)((0, _univerjs_ui.useDependency)(ISheetLoadingRenderService).previewReady$) ?? false;
9923
- }
9924
- function useActiveWorksheet(workbook) {
9925
- return (0, _univerjs_ui.useObservable)(() => (workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) ?? (0, rxjs.of)(null), void 0, void 0, [workbook]);
9926
- }
9927
- function useWorkbooks() {
9928
- const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
9929
- return (0, _univerjs_ui.useObservable)(() => {
9930
- return (0, rxjs.merge)([univerInstanceService.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), univerInstanceService.getTypeOfUnitDisposed$(_univerjs_core.UniverInstanceType.UNIVER_SHEET)]).pipe((0, rxjs.map)(() => univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)), (0, rxjs.startWith)(univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)));
9931
- }, [], void 0, [univerInstanceService]);
9932
- }
9933
-
9934
- //#endregion
9935
- //#region src/views/clipboard/ClipboardPopupMenu.tsx
9936
- const DEFAULT_PADDING = 2;
9937
- const SheetPasteOptions = [
9938
- {
9939
- value: "DEFAULT_PASTE",
9940
- label: "sheets-ui.rightClick.paste"
9941
- },
9942
- {
9943
- value: "SPECIAL_PASTE_VALUE",
9944
- label: "sheets-ui.rightClick.pasteValue"
9945
- },
9946
- {
9947
- value: "SPECIAL_PASTE_FORMAT",
9948
- label: "sheets-ui.rightClick.pasteFormat"
9949
- },
9950
- {
9951
- value: "SPECIAL_PASTE_COL_WIDTH",
9952
- label: "sheets-ui.rightClick.pasteColWidth"
9953
- },
9954
- {
9955
- value: "SPECIAL_PASTE_BESIDES_BORDER",
9956
- label: "sheets-ui.rightClick.pasteBesidesBorder"
9957
- },
9958
- {
9959
- value: "SPECIAL_PASTE_FORMULA",
9960
- label: "sheets-ui.rightClick.pasteFormula"
9961
- }
9962
- ];
9963
- const useMenuPosition = (range) => {
9964
- var _scene$getEngine;
9965
- const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
9966
- const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
9967
- const workbook = useActiveWorkbook();
9968
- if (!range || !workbook) return null;
9969
- const anchor = {
9970
- startRow: range.rows[0],
9971
- startCol: range.cols[0],
9972
- endRow: range.rows[range.rows.length - 1],
9973
- endCol: range.cols[range.cols.length - 1]
9974
- };
9975
- if (anchor.endRow < 0 || anchor.endCol < 0) return null;
9976
- const ru = renderManagerService.getRenderUnitById(workbook.getUnitId());
9977
- const sheetSkeletonManagerService = ru === null || ru === void 0 ? void 0 : ru.with(SheetSkeletonManagerService);
9978
- const sheetObject = getSheetObject(univerInstanceService, renderManagerService);
9979
- if (!sheetObject) return null;
9980
- const { scene } = sheetObject;
9981
- const skeleton = sheetSkeletonManagerService === null || sheetSkeletonManagerService === void 0 ? void 0 : sheetSkeletonManagerService.getCurrentSkeleton();
9982
- const viewport = getViewportByCell(anchor.endRow, anchor.endCol, scene, workbook.getActiveSheet());
9983
- if (!viewport) return null;
9984
- const scaleX = scene === null || scene === void 0 ? void 0 : scene.scaleX;
9985
- const scaleY = scene === null || scene === void 0 ? void 0 : scene.scaleY;
9986
- const scrollXY = scene === null || scene === void 0 ? void 0 : scene.getViewportScrollXY(viewport);
9987
- const canvas = (_scene$getEngine = scene.getEngine()) === null || _scene$getEngine === void 0 ? void 0 : _scene$getEngine.getCanvas();
9988
- if (!scaleX || !scene || !scaleX || !scaleY || !scrollXY) return null;
9989
- const endPosition = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getNoMergeCellWithCoordByIndex(anchor.endRow, anchor.endCol);
9990
- const endX = (endPosition === null || endPosition === void 0 ? void 0 : endPosition.endX) ?? 0;
9991
- const endY = (endPosition === null || endPosition === void 0 ? void 0 : endPosition.endY) ?? 0;
9992
- const positionEndX = (0, _univerjs_engine_render.convertTransformToOffsetX)(endX, scaleX, scrollXY) ?? -9999;
9993
- const positionEndY = (0, _univerjs_engine_render.convertTransformToOffsetY)(endY, scaleY, scrollXY) ?? -9999;
9994
- const canvasWidth = canvas === null || canvas === void 0 ? void 0 : canvas.getWidth();
9995
- const canvasHeight = canvas === null || canvas === void 0 ? void 0 : canvas.getHeight();
9996
- if (!canvasWidth || !canvasHeight) return null;
9997
- const XInSideView = positionEndX + 50 <= canvasWidth;
9998
- const YInSideView = positionEndY + 50 <= canvasHeight;
9999
- let positionX = positionEndX;
10000
- let positionY = positionEndY;
10001
- if (!XInSideView) positionX = canvasWidth - 100;
10002
- if (!YInSideView) positionY = canvasHeight - 100;
10003
- return {
10004
- positionX,
10005
- positionY
10006
- };
10007
- };
10008
- const ClipboardPopupMenu = () => {
10009
- const clipboardService = (0, _univerjs_ui.useDependency)(ISheetClipboardService);
10010
- const showMenu = (0, _univerjs_ui.useObservable)(clipboardService.showMenu$, false);
10011
- const pasteOptionsCache = (0, _univerjs_ui.useObservable)(clipboardService.pasteOptionsCache$, null);
10012
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
10013
- const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
10014
- const [menuHovered, setMenuHovered] = (0, react.useState)(false);
10015
- const [visible, setVisible] = (0, react.useState)(false);
10016
- const range = pasteOptionsCache === null || pasteOptionsCache === void 0 ? void 0 : pasteOptionsCache.target.pastedRange;
10017
- const relativePosition = useMenuPosition(range);
10018
- if (!relativePosition || !showMenu) return null;
10019
- if (relativePosition.positionX < 50 || relativePosition.positionY < 30) return null;
10020
- const showMore = menuHovered || visible;
10021
- const handleClick = (type) => {
10022
- setVisible(false);
10023
- commandService.executeCommand(SheetOptionalPasteCommand.id, { type });
10024
- };
10025
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
10026
- className: "univer-absolute univer-inset-0 univer-z-10 univer-size-0",
10027
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
10028
- className: "univer-absolute",
10029
- style: {
10030
- left: relativePosition.positionX + DEFAULT_PADDING,
10031
- top: relativePosition.positionY + DEFAULT_PADDING
10032
- },
10033
- onMouseEnter: () => setMenuHovered(true),
10034
- onMouseLeave: () => setMenuHovered(false),
10035
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DropdownMenu, {
10036
- align: "start",
10037
- items: SheetPasteOptions.map((item) => ({
10038
- type: "checkbox",
10039
- value: item.value,
10040
- label: localeService.t(item.label),
10041
- checked: (pasteOptionsCache === null || pasteOptionsCache === void 0 ? void 0 : pasteOptionsCache.pasteType) === PREDEFINED_HOOK_NAME_PASTE[item.value],
10042
- onSelect: () => handleClick(item.value)
10043
- })),
10044
- open: visible,
10045
- onOpenChange: setVisible,
10046
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
10047
- className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800", _univerjs_design.borderClassName, {
10048
- "univer-bg-gray-100 dark:!univer-bg-gray-800": visible,
10049
- "univer-bg-white dark:!univer-bg-gray-900": !visible
10050
- }),
10051
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.PasteSpecialDoubleIcon, { className: "univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white" }), showMore && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "dark:!univer-text-white" })]
10052
- })
10053
- })
10054
- })
10055
- });
10056
- };
10057
-
10058
- //#endregion
10059
- //#region src/controllers/clipboard/const.ts
10060
- /**
10061
- * Copyright 2023-present DreamNum Co., Ltd.
10062
- *
10063
- * Licensed under the Apache License, Version 2.0 (the "License");
10064
- * you may not use this file except in compliance with the License.
10065
- * You may obtain a copy of the License at
10066
- *
10067
- * http://www.apache.org/licenses/LICENSE-2.0
10068
- *
10069
- * Unless required by applicable law or agreed to in writing, software
10070
- * distributed under the License is distributed on an "AS IS" BASIS,
10071
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10072
- * See the License for the specific language governing permissions and
10073
- * limitations under the License.
10074
- */
10075
- const RemovePasteMenuCommands = [
10076
- SetCellEditVisibleOperation.id,
10077
- _univerjs_sheets.SetRangeValuesCommand.id,
10078
- SetZoomRatioOperation.id,
10079
- _univerjs_sheets.MoveRangeMutation.id,
10080
- _univerjs_sheets.RemoveRowMutation.id,
10081
- _univerjs_sheets.RemoveColMutation.id,
10082
- _univerjs_sheets.InsertRowMutation.id,
10083
- _univerjs_sheets.InsertColMutation.id,
10084
- _univerjs_sheets.MoveRowsMutation.id,
10085
- _univerjs_sheets.MoveColsMutation.id,
10086
- _univerjs_sheets.SetWorksheetColWidthMutation.id,
10087
- _univerjs_sheets.SetWorksheetRowHeightMutation.id,
10088
- _univerjs_sheets.SetSelectionsOperation.id,
10089
- _univerjs_core.UndoCommandId
10090
- ];
10091
-
10092
- //#endregion
10093
- //#region src/services/editor/cell-editor-manager.service.ts
10094
- var CellEditorManagerService = class {
10095
- constructor() {
10096
- _defineProperty(this, "_state", null);
10097
- _defineProperty(this, "_rect", null);
10098
- _defineProperty(this, "_state$", new rxjs.BehaviorSubject(null));
10099
- _defineProperty(this, "state$", this._state$.asObservable());
10100
- _defineProperty(this, "_rect$", new rxjs.BehaviorSubject(null));
10101
- _defineProperty(this, "rect$", this._rect$.asObservable());
10102
- _defineProperty(this, "_focus", false);
10103
- _defineProperty(this, "_focus$", new rxjs.BehaviorSubject(this._focus));
10104
- _defineProperty(this, "focus$", this._focus$.asObservable());
9383
+ ];
9384
+ const useMenuPosition = (range) => {
9385
+ var _scene$getEngine;
9386
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
9387
+ const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
9388
+ const workbook = useActiveWorkbook();
9389
+ if (!range || !workbook) return null;
9390
+ const anchor = {
9391
+ startRow: range.rows[0],
9392
+ startCol: range.cols[0],
9393
+ endRow: range.rows[range.rows.length - 1],
9394
+ endCol: range.cols[range.cols.length - 1]
9395
+ };
9396
+ if (anchor.endRow < 0 || anchor.endCol < 0) return null;
9397
+ const ru = renderManagerService.getRenderUnitById(workbook.getUnitId());
9398
+ const sheetSkeletonManagerService = ru === null || ru === void 0 ? void 0 : ru.with(SheetSkeletonManagerService);
9399
+ const sheetObject = getSheetObject(univerInstanceService, renderManagerService);
9400
+ if (!sheetObject) return null;
9401
+ const { scene } = sheetObject;
9402
+ const skeleton = sheetSkeletonManagerService === null || sheetSkeletonManagerService === void 0 ? void 0 : sheetSkeletonManagerService.getCurrentSkeleton();
9403
+ const viewport = getViewportByCell(anchor.endRow, anchor.endCol, scene, workbook.getActiveSheet());
9404
+ if (!viewport) return null;
9405
+ const scaleX = scene === null || scene === void 0 ? void 0 : scene.scaleX;
9406
+ const scaleY = scene === null || scene === void 0 ? void 0 : scene.scaleY;
9407
+ const scrollXY = scene === null || scene === void 0 ? void 0 : scene.getViewportScrollXY(viewport);
9408
+ const canvas = (_scene$getEngine = scene.getEngine()) === null || _scene$getEngine === void 0 ? void 0 : _scene$getEngine.getCanvas();
9409
+ if (!scaleX || !scene || !scaleX || !scaleY || !scrollXY) return null;
9410
+ const endPosition = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getNoMergeCellWithCoordByIndex(anchor.endRow, anchor.endCol);
9411
+ const endX = (endPosition === null || endPosition === void 0 ? void 0 : endPosition.endX) ?? 0;
9412
+ const endY = (endPosition === null || endPosition === void 0 ? void 0 : endPosition.endY) ?? 0;
9413
+ const positionEndX = (0, _univerjs_engine_render.convertTransformToOffsetX)(endX, scaleX, scrollXY) ?? -9999;
9414
+ const positionEndY = (0, _univerjs_engine_render.convertTransformToOffsetY)(endY, scaleY, scrollXY) ?? -9999;
9415
+ const canvasWidth = canvas === null || canvas === void 0 ? void 0 : canvas.getWidth();
9416
+ const canvasHeight = canvas === null || canvas === void 0 ? void 0 : canvas.getHeight();
9417
+ if (!canvasWidth || !canvasHeight) return null;
9418
+ const XInSideView = positionEndX + 50 <= canvasWidth;
9419
+ const YInSideView = positionEndY + 50 <= canvasHeight;
9420
+ let positionX = positionEndX;
9421
+ let positionY = positionEndY;
9422
+ if (!XInSideView) positionX = canvasWidth - 100;
9423
+ if (!YInSideView) positionY = canvasHeight - 100;
9424
+ return {
9425
+ positionX,
9426
+ positionY
9427
+ };
9428
+ };
9429
+ const ClipboardPopupMenu = () => {
9430
+ const clipboardService = (0, _univerjs_ui.useDependency)(ISheetClipboardService);
9431
+ const showMenu = (0, _univerjs_ui.useObservable)(clipboardService.showMenu$, false);
9432
+ const pasteOptionsCache = (0, _univerjs_ui.useObservable)(clipboardService.pasteOptionsCache$, null);
9433
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
9434
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
9435
+ const [menuHovered, setMenuHovered] = (0, react.useState)(false);
9436
+ const [visible, setVisible] = (0, react.useState)(false);
9437
+ const range = pasteOptionsCache === null || pasteOptionsCache === void 0 ? void 0 : pasteOptionsCache.target.pastedRange;
9438
+ const relativePosition = useMenuPosition(range);
9439
+ if (!relativePosition || !showMenu) return null;
9440
+ if (relativePosition.positionX < 50 || relativePosition.positionY < 30) return null;
9441
+ const showMore = menuHovered || visible;
9442
+ const handleClick = (type) => {
9443
+ setVisible(false);
9444
+ commandService.executeCommand(SheetOptionalPasteCommand.id, { type });
9445
+ };
9446
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
9447
+ className: "univer-absolute univer-inset-0 univer-z-10 univer-size-0",
9448
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
9449
+ className: "univer-absolute",
9450
+ style: {
9451
+ left: relativePosition.positionX + DEFAULT_PADDING,
9452
+ top: relativePosition.positionY + DEFAULT_PADDING
9453
+ },
9454
+ onMouseEnter: () => setMenuHovered(true),
9455
+ onMouseLeave: () => setMenuHovered(false),
9456
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DropdownMenu, {
9457
+ align: "start",
9458
+ items: SheetPasteOptions.map((item) => ({
9459
+ type: "checkbox",
9460
+ value: item.value,
9461
+ label: localeService.t(item.label),
9462
+ checked: (pasteOptionsCache === null || pasteOptionsCache === void 0 ? void 0 : pasteOptionsCache.pasteType) === PREDEFINED_HOOK_NAME_PASTE[item.value],
9463
+ onSelect: () => handleClick(item.value)
9464
+ })),
9465
+ open: visible,
9466
+ onOpenChange: setVisible,
9467
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
9468
+ className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800", _univerjs_design.borderClassName, {
9469
+ "univer-bg-gray-100 dark:!univer-bg-gray-800": visible,
9470
+ "univer-bg-gray-0 dark:!univer-bg-gray-900": !visible
9471
+ }),
9472
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.PasteSpecialDoubleIcon, { className: "univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-gray-0" }), showMore && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "dark:!univer-text-gray-0" })]
9473
+ })
9474
+ })
9475
+ })
9476
+ });
9477
+ };
9478
+
9479
+ //#endregion
9480
+ //#region src/controllers/clipboard/const.ts
9481
+ /**
9482
+ * Copyright 2023-present DreamNum Co., Ltd.
9483
+ *
9484
+ * Licensed under the Apache License, Version 2.0 (the "License");
9485
+ * you may not use this file except in compliance with the License.
9486
+ * You may obtain a copy of the License at
9487
+ *
9488
+ * http://www.apache.org/licenses/LICENSE-2.0
9489
+ *
9490
+ * Unless required by applicable law or agreed to in writing, software
9491
+ * distributed under the License is distributed on an "AS IS" BASIS,
9492
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9493
+ * See the License for the specific language governing permissions and
9494
+ * limitations under the License.
9495
+ */
9496
+ const RemovePasteMenuCommands = [
9497
+ SetCellEditVisibleOperation.id,
9498
+ _univerjs_sheets.SetRangeValuesCommand.id,
9499
+ SetZoomRatioOperation.id,
9500
+ _univerjs_sheets.MoveRangeMutation.id,
9501
+ _univerjs_sheets.RemoveRowMutation.id,
9502
+ _univerjs_sheets.RemoveColMutation.id,
9503
+ _univerjs_sheets.InsertRowMutation.id,
9504
+ _univerjs_sheets.InsertColMutation.id,
9505
+ _univerjs_sheets.MoveRowsMutation.id,
9506
+ _univerjs_sheets.MoveColsMutation.id,
9507
+ _univerjs_sheets.SetWorksheetColWidthMutation.id,
9508
+ _univerjs_sheets.SetWorksheetRowHeightMutation.id,
9509
+ _univerjs_sheets.SetSelectionsOperation.id,
9510
+ _univerjs_core.UndoCommandId
9511
+ ];
9512
+
9513
+ //#endregion
9514
+ //#region src/services/editor/cell-editor-manager.service.ts
9515
+ var CellEditorManagerService = class {
9516
+ constructor() {
9517
+ _defineProperty(this, "_state", null);
9518
+ _defineProperty(this, "_rect", null);
9519
+ _defineProperty(this, "_state$", new rxjs.BehaviorSubject(null));
9520
+ _defineProperty(this, "state$", this._state$.asObservable());
9521
+ _defineProperty(this, "_rect$", new rxjs.BehaviorSubject(null));
9522
+ _defineProperty(this, "rect$", this._rect$.asObservable());
9523
+ _defineProperty(this, "_focus", false);
9524
+ _defineProperty(this, "_focus$", new rxjs.BehaviorSubject(this._focus));
9525
+ _defineProperty(this, "focus$", this._focus$.asObservable());
10105
9526
  }
10106
9527
  dispose() {
10107
9528
  this._state$.complete();
@@ -10569,7 +9990,9 @@ let EditorBridgeRenderController = class EditorBridgeRenderController extends _u
10569
9990
  if (!sheetObject) return;
10570
9991
  const { spreadsheet, spreadsheetColumnHeader, spreadsheetLeftTopPlaceholder, spreadsheetRowHeader } = sheetObject;
10571
9992
  d.add(spreadsheet.onDblclick$.subscribeEvent((evt) => {
9993
+ var _this$_editorBridgeSe;
10572
9994
  if (evt.button === 2) return;
9995
+ if ((0, _univerjs_sheets.isCellImage)((_this$_editorBridgeSe = this._editorBridgeService.getEditCellState()) === null || _this$_editorBridgeSe === void 0 || (_this$_editorBridgeSe = _this$_editorBridgeSe.documentLayoutObject.documentModel) === null || _this$_editorBridgeSe === void 0 ? void 0 : _this$_editorBridgeSe.getSnapshot())) return;
10573
9996
  this._commandService.executeCommand(SetCellEditVisibleOperation.id, {
10574
9997
  visible: true,
10575
9998
  eventType: _univerjs_engine_render.DeviceInputEventType.Dblclick,
@@ -10600,25 +10023,25 @@ let EditorBridgeRenderController = class EditorBridgeRenderController extends _u
10600
10023
  _initialKeyboardListener(d) {
10601
10024
  let disposable = null;
10602
10025
  const addEvent = (render) => {
10026
+ disposable === null || disposable === void 0 || disposable.dispose();
10027
+ disposable = null;
10603
10028
  const docSelectionRenderService = render.with(_univerjs_docs_ui.DocSelectionRenderService);
10604
- if (docSelectionRenderService) {
10605
- disposable = (0, _univerjs_core.toDisposable)(docSelectionRenderService.onInputBefore$.subscribe((config) => {
10606
- var _this$_embedRuntimeFo;
10607
- if (!this._isCurrentSheetFocused()) return;
10608
- const isFocusFormulaEditor = this._contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR);
10609
- 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;
10610
- const unitId = render.unitId;
10611
- if (this._editorBridgeService.isVisible().visible) return;
10612
- if (unitId && isFocusSheets && !isFocusFormulaEditor) this._showEditorByKeyboard(config);
10613
- }));
10614
- d.add(disposable);
10615
- }
10029
+ if (docSelectionRenderService) disposable = (0, _univerjs_core.toDisposable)(docSelectionRenderService.onInputBefore$.subscribe((config) => {
10030
+ var _this$_embedRuntimeFo;
10031
+ if (!this._isCurrentSheetFocused()) return;
10032
+ const isFocusFormulaEditor = this._contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR);
10033
+ const isFocusSheets = this._contextService.getContextValue(_univerjs_core.FOCUSING_SHEET) || ((_this$_embedRuntimeFo = this._embedRuntimeFocusCoordinator) === null || _this$_embedRuntimeFo === void 0 ? void 0 : _this$_embedRuntimeFo.isChildUnitInActiveSession(this._context.unitId)) === true;
10034
+ const unitId = render.unitId;
10035
+ if (this._editorBridgeService.isVisible().visible) return;
10036
+ if (unitId && isFocusSheets && !isFocusFormulaEditor) this._showEditorByKeyboard(config);
10037
+ }));
10616
10038
  };
10617
10039
  const render = this._renderManagerService.getRenderUnitById(_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
10618
10040
  if (render) addEvent(render);
10619
- else this.disposeWithMe(this._renderManagerService.created$.pipe((0, rxjs.filter)((render) => render.unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)).subscribe((render) => {
10041
+ d.add(this._renderManagerService.created$.pipe((0, rxjs.filter)((render) => render.unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)).subscribe(addEvent));
10042
+ d.add((0, _univerjs_core.toDisposable)(() => {
10620
10043
  disposable === null || disposable === void 0 || disposable.dispose();
10621
- addEvent(render);
10044
+ disposable = null;
10622
10045
  }));
10623
10046
  }
10624
10047
  _initSheetFocusListener(d) {
@@ -10665,9 +10088,9 @@ let EditorBridgeRenderController = class EditorBridgeRenderController extends _u
10665
10088
  this._hideEditor();
10666
10089
  }
10667
10090
  _isEmbeddedFormulaEditorActive() {
10668
- var _this$_embedRuntimeFo2, _this$_editorBridgeSe;
10091
+ var _this$_embedRuntimeFo2, _this$_editorBridgeSe2;
10669
10092
  if (((_this$_embedRuntimeFo2 = this._embedRuntimeFocusCoordinator) === null || _this$_embedRuntimeFo2 === void 0 ? void 0 : _this$_embedRuntimeFo2.isChildUnitInActiveSession(this._context.unitId)) !== true) return false;
10670
- 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;
10093
+ const dataStream = (_this$_editorBridgeSe2 = this._editorBridgeService.getEditCellState()) === null || _this$_editorBridgeSe2 === void 0 || (_this$_editorBridgeSe2 = _this$_editorBridgeSe2.documentLayoutObject.documentModel) === null || _this$_editorBridgeSe2 === void 0 || (_this$_editorBridgeSe2 = _this$_editorBridgeSe2.getSnapshot().body) === null || _this$_editorBridgeSe2 === void 0 ? void 0 : _this$_editorBridgeSe2.dataStream;
10671
10094
  return typeof dataStream === "string" && dataStream.startsWith("=");
10672
10095
  }
10673
10096
  _isCurrentEmbedRuntimeEvent(evt) {
@@ -11367,8 +10790,29 @@ const isRangeSelector = (unitId) => {
11367
10790
  //#endregion
11368
10791
  //#region src/controllers/editor/editing.render-controller.ts
11369
10792
  const HIDDEN_EDITOR_POSITION$1 = -1e3;
10793
+ function getPercentOffset(editCellState, dataStream) {
10794
+ if (!editCellState.isPercentFormat || editCellState.isInArrayFormulaRange) return null;
10795
+ const percentSuffix = `%${_univerjs_core.DEFAULT_EMPTY_DOCUMENT_VALUE}`;
10796
+ return (dataStream === null || dataStream === void 0 ? void 0 : dataStream.endsWith(percentSuffix)) ? dataStream.length - percentSuffix.length : null;
10797
+ }
10798
+ function getPercentEditorSelection(editCellState, visibleParam, dataStream) {
10799
+ const percentOffset = getPercentOffset(editCellState, dataStream);
10800
+ if (percentOffset == null) return null;
10801
+ const { eventType, initialValue, keycode } = visibleParam;
10802
+ if (eventType === _univerjs_engine_render.DeviceInputEventType.Dblclick || eventType === _univerjs_engine_render.DeviceInputEventType.Keyboard && keycode === _univerjs_ui.KeyCode.F2) return {
10803
+ startOffset: percentOffset,
10804
+ endOffset: percentOffset,
10805
+ collapsed: true
10806
+ };
10807
+ if (eventType !== _univerjs_engine_render.DeviceInputEventType.Keyboard || keycode === _univerjs_ui.KeyCode.BACKSPACE || keycode === _univerjs_ui.KeyCode.DELETE || !/^\d/.test(initialValue ?? "")) return null;
10808
+ return {
10809
+ startOffset: 0,
10810
+ endOffset: percentOffset,
10811
+ collapsed: false
10812
+ };
10813
+ }
11370
10814
  let EditingRenderController = class EditingRenderController extends _univerjs_core.Disposable {
11371
- constructor(_undoRedoService, _contextService, _renderManagerService, _editorBridgeService, _cellEditorManagerService, _lexerTreeBuilder, _functionService, _textSelectionManagerService, _commandService, _localService, _editorService, _univerInstanceService, _sheetInterceptorService, _sheetCellEditorResizeService, _selectionManagerService, _configService) {
10815
+ constructor(_undoRedoService, _contextService, _renderManagerService, _editorBridgeService, _cellEditorManagerService, _lexerTreeBuilder, _functionService, _textSelectionManagerService, _commandService, _localService, _editorService, _univerInstanceService, _sheetInterceptorService, _sheetCellEditorResizeService, _selectionManagerService, _configService, _docStateChangeManagerService) {
11372
10816
  super();
11373
10817
  this._undoRedoService = _undoRedoService;
11374
10818
  this._contextService = _contextService;
@@ -11386,6 +10830,7 @@ let EditingRenderController = class EditingRenderController extends _univerjs_co
11386
10830
  this._sheetCellEditorResizeService = _sheetCellEditorResizeService;
11387
10831
  this._selectionManagerService = _selectionManagerService;
11388
10832
  this._configService = _configService;
10833
+ this._docStateChangeManagerService = _docStateChangeManagerService;
11389
10834
  _defineProperty(this, "_cursorChange", 0);
11390
10835
  _defineProperty(this, "_editingUnit", "");
11391
10836
  _defineProperty(this, "_submitEmptyCellImageEdit", false);
@@ -11460,6 +10905,7 @@ let EditingRenderController = class EditingRenderController extends _univerjs_co
11460
10905
  const docSelectionRenderManager = (_this$_renderManagerS2 = this._renderManagerService.getRenderUnitById(docUnitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.with(_univerjs_docs_ui.DocSelectionRenderService);
11461
10906
  if (!docSelectionRenderManager) return;
11462
10907
  docSelectionRenderManager.sync();
10908
+ this._cacheEmptyCellTextStyle();
11463
10909
  }));
11464
10910
  }
11465
10911
  _initSkeletonListener(d) {
@@ -11540,6 +10986,30 @@ let EditingRenderController = class EditingRenderController extends _univerjs_co
11540
10986
  * Listen to document edits to refresh the size of the sheet editor, not for normal editor.
11541
10987
  */
11542
10988
  _commandExecutedListener(d) {
10989
+ d.add(this._commandService.beforeCommandExecuted((command) => {
10990
+ var _this$_getDocumentDat;
10991
+ if (command.id !== _univerjs_docs.InsertTextCommand.id) return;
10992
+ const params = command.params;
10993
+ const visibleParam = this._editorBridgeService.isVisible();
10994
+ const editCellState = this._editorBridgeService.getEditLocation();
10995
+ if (params.unitId !== _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY || !visibleParam.visible || editCellState == null) return;
10996
+ const dataStream = (_this$_getDocumentDat = this._getDocumentDataModel()) === null || _this$_getDocumentDat === void 0 || (_this$_getDocumentDat = _this$_getDocumentDat.getBody()) === null || _this$_getDocumentDat === void 0 ? void 0 : _this$_getDocumentDat.dataStream;
10997
+ if (dataStream == null) return;
10998
+ const percentOffset = getPercentOffset(editCellState, dataStream);
10999
+ if (percentOffset != null && !this._editorBridgeService.getEditorDirty() && visibleParam.eventType === _univerjs_engine_render.DeviceInputEventType.Keyboard && /^\d/.test(visibleParam.initialValue ?? "") && /^\d/.test(params.body.dataStream)) {
11000
+ params.range = {
11001
+ startOffset: 0,
11002
+ endOffset: percentOffset,
11003
+ collapsed: false
11004
+ };
11005
+ return;
11006
+ }
11007
+ if (percentOffset != null && params.body.dataStream === "%" && params.range.collapsed && params.range.startOffset === percentOffset && params.range.endOffset === percentOffset) params.range = {
11008
+ ...params.range,
11009
+ endOffset: percentOffset + 1,
11010
+ collapsed: false
11011
+ };
11012
+ }));
11543
11013
  d.add(this._commandService.onCommandExecuted((command) => {
11544
11014
  if (command.id === _univerjs_docs.RichTextEditingMutation.id) {
11545
11015
  const { unitId: commandUnitId } = command.params;
@@ -11572,12 +11042,13 @@ let EditingRenderController = class EditingRenderController extends _univerjs_co
11572
11042
  }));
11573
11043
  }
11574
11044
  _handleEditorVisible(param) {
11575
- var _this$_sheetCellEdito4, _this$_renderManagerS5;
11045
+ var _this$_sheetCellEdito4, _documentDataModel$ge, _this$_renderManagerS5;
11576
11046
  const { eventType, keycode } = param;
11577
11047
  this._cursorChange = eventType === _univerjs_engine_render.DeviceInputEventType.PointerDown || eventType === _univerjs_engine_render.DeviceInputEventType.Dblclick ? 2 : 1;
11578
11048
  const editCellState = this._editorBridgeService.getEditLocation();
11579
11049
  if (editCellState == null) return;
11580
11050
  const { unitId, isInArrayFormulaRange = false } = editCellState;
11051
+ this._clearEditorHistory();
11581
11052
  this._commandService.syncExecuteCommand(ScrollToRangeOperation.id, {
11582
11053
  unitId,
11583
11054
  range: {
@@ -11617,35 +11088,51 @@ let EditingRenderController = class EditingRenderController extends _univerjs_co
11617
11088
  subUnitId: _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY
11618
11089
  });
11619
11090
  };
11091
+ const replaceSelection = (selection) => {
11092
+ this._textSelectionManagerService.replaceDocRanges([selection], {
11093
+ unitId: _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
11094
+ subUnitId: _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY
11095
+ });
11096
+ };
11097
+ const percentSelection = getPercentEditorSelection(editCellState, param, (_documentDataModel$ge = documentDataModel.getBody()) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.dataStream);
11620
11098
  const cellImage = (0, _univerjs_sheets.isCellImage)(documentDataModel.getSnapshot());
11621
11099
  this._submitEmptyCellImageEdit = cellImage && eventType === _univerjs_engine_render.DeviceInputEventType.Keyboard && keycode === _univerjs_ui.KeyCode.BACKSPACE;
11622
11100
  if (cellImage) clearAndEdit();
11623
11101
  else if (eventType === _univerjs_engine_render.DeviceInputEventType.Keyboard && keycode === _univerjs_ui.KeyCode.F2) {
11624
- var _documentDataModel$ge;
11102
+ var _documentDataModel$ge2;
11625
11103
  document.makeDirty();
11626
11104
  this._textSelectionManagerService.replaceDocRanges([{
11627
11105
  startOffset: 0,
11628
11106
  endOffset: 0
11629
11107
  }]);
11630
- const endOffset = (((_documentDataModel$ge = documentDataModel.getBody()) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.dataStream.length) ?? 2) - 2;
11631
- this._textSelectionManagerService.replaceDocRanges([{
11108
+ const endOffset = (((_documentDataModel$ge2 = documentDataModel.getBody()) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.dataStream.length) ?? 2) - 2;
11109
+ if (percentSelection) replaceSelection(percentSelection);
11110
+ else this._textSelectionManagerService.replaceDocRanges([{
11632
11111
  startOffset: endOffset,
11633
11112
  endOffset
11634
11113
  }], {
11635
11114
  unitId: _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
11636
11115
  subUnitId: _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY
11637
11116
  });
11638
- } else if (eventType === _univerjs_engine_render.DeviceInputEventType.Keyboard || eventType === _univerjs_engine_render.DeviceInputEventType.Dblclick && isInArrayFormulaRange) clearAndEdit();
11117
+ } else if (eventType === _univerjs_engine_render.DeviceInputEventType.Keyboard || eventType === _univerjs_engine_render.DeviceInputEventType.Dblclick && isInArrayFormulaRange) if (percentSelection) replaceSelection(percentSelection);
11118
+ else clearAndEdit();
11639
11119
  else if (eventType === _univerjs_engine_render.DeviceInputEventType.Dblclick) {
11640
11120
  if (this._contextService.getContextValue(_univerjs_core.FOCUSING_EDITOR_INPUT_FORMULA)) return;
11641
11121
  const cursor = documentDataModel.getBody().dataStream.length - 2 || 0;
11642
- this._textSelectionManagerService.replaceDocRanges([{
11122
+ if (percentSelection) replaceSelection(percentSelection);
11123
+ else this._textSelectionManagerService.replaceDocRanges([{
11643
11124
  startOffset: cursor,
11644
11125
  endOffset: cursor
11645
11126
  }]);
11646
11127
  }
11647
11128
  (_this$_renderManagerS5 = this._renderManagerService.getRenderUnitById(unitId)) === null || _this$_renderManagerS5 === void 0 || _this$_renderManagerS5.scene.resetCursor();
11648
11129
  }
11130
+ _cacheEmptyCellTextStyle() {
11131
+ var _this$_editorBridgeSe, _sourceBody$textRuns;
11132
+ const sourceBody = (_this$_editorBridgeSe = this._editorBridgeService.getEditLocation()) === null || _this$_editorBridgeSe === void 0 || (_this$_editorBridgeSe = _this$_editorBridgeSe.documentLayoutObject.documentModel) === null || _this$_editorBridgeSe === void 0 ? void 0 : _this$_editorBridgeSe.getBody();
11133
+ const textRun = (sourceBody === null || sourceBody === void 0 || (_sourceBody$textRuns = sourceBody.textRuns) === null || _sourceBody$textRuns === void 0 ? void 0 : _sourceBody$textRuns.length) === 1 ? sourceBody.textRuns[0] : null;
11134
+ if ((sourceBody === null || sourceBody === void 0 ? void 0 : sourceBody.dataStream) === _univerjs_core.DEFAULT_EMPTY_DOCUMENT_VALUE && (textRun === null || textRun === void 0 ? void 0 : textRun.st) === 0 && textRun.ed === 0) this._commandService.syncExecuteCommand(_univerjs_docs_ui.SetDocInputStyleCommand.id, { style: _univerjs_core.Tools.deepClone(textRun.ts) });
11135
+ }
11649
11136
  _refreshCurrentSelections(sheetId) {
11650
11137
  const selections = this._workbookSelections.getSelectionsOfWorksheet(sheetId);
11651
11138
  if (selections) {
@@ -11769,8 +11256,13 @@ let EditingRenderController = class EditingRenderController extends _univerjs_co
11769
11256
  var _this$_getEditorSkele;
11770
11257
  (_this$_getEditorSkele = this._getEditorSkeleton(_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)) === null || _this$_getEditorSkele === void 0 || _this$_getEditorSkele.resetInitialWidth();
11771
11258
  }
11772
- this._undoRedoService.clearUndoRedo(editorUnitId);
11259
+ this._clearEditorHistory();
11260
+ }
11261
+ _clearEditorHistory() {
11262
+ this._undoRedoService.clearUndoRedo(_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
11773
11263
  this._undoRedoService.clearUndoRedo(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
11264
+ this._docStateChangeManagerService.clearHistory(_univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
11265
+ this._docStateChangeManagerService.clearHistory(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
11774
11266
  }
11775
11267
  _moveSelection(keycode, currentUnitId, worksheetId) {
11776
11268
  if (keycode == null || !MOVE_SELECTION_KEYCODE_LIST.includes(keycode)) {
@@ -11874,7 +11366,8 @@ EditingRenderController = __decorate([
11874
11366
  __decorateParam(12, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
11875
11367
  __decorateParam(13, (0, _univerjs_core.Inject)(SheetCellEditorResizeService)),
11876
11368
  __decorateParam(14, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
11877
- __decorateParam(15, _univerjs_core.IConfigService)
11369
+ __decorateParam(15, _univerjs_core.IConfigService),
11370
+ __decorateParam(16, (0, _univerjs_core.Inject)(_univerjs_docs.DocStateChangeManagerService))
11878
11371
  ], EditingRenderController);
11879
11372
  function getCellDataByInput(cellData, snapshot, lexerTreeBuilder, localeService, functionService, styles) {
11880
11373
  var _styles$get;
@@ -14003,7 +13496,7 @@ let SheetPermissionCheckUIController = class SheetPermissionCheckUIController ex
14003
13496
  workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
14004
13497
  worksheetTypes: [_univerjs_sheets.WorksheetSetCellValuePermission, _univerjs_sheets.WorksheetEditPermission],
14005
13498
  rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
14006
- });
13499
+ }, params.unitId);
14007
13500
  errorMsg = this._localeService.t("sheets-ui.permission.dialog.editErr");
14008
13501
  break;
14009
13502
  case ApplyFormatPainterCommand.id:
@@ -15754,9 +15247,9 @@ var HeaderUnhideRangeService = class {
15754
15247
 
15755
15248
  //#endregion
15756
15249
  //#region src/menu/header-menu-shape.ts
15757
- const HEADER_MENU_SHAPE_CIRCLE_FILL = "rgba(0, 0, 0, 0.15)";
15758
- const HEADER_MENU_SHAPE_TRIANGLE_FILL = "rgb(0, 0, 0)";
15759
- const HEADER_MENU_BACKGROUND_COLOR = "rgb(255, 255, 255, 1)";
15250
+ const HEADER_MENU_SHAPE_CIRCLE_FILL = "gray.200";
15251
+ const HEADER_MENU_SHAPE_TRIANGLE_FILL = "gray.900";
15252
+ const HEADER_MENU_BACKGROUND_COLOR = "gray.50";
15760
15253
  var HeaderMenuShape = class extends _univerjs_engine_render.Shape {
15761
15254
  constructor(key, props) {
15762
15255
  super(key, props);
@@ -15777,309 +15270,701 @@ var HeaderMenuShape = class extends _univerjs_engine_render.Shape {
15777
15270
  if (this._mode === 1) _univerjs_engine_render.Rect.drawWith(ctx, {
15778
15271
  width: this._size,
15779
15272
  height: this._size,
15780
- radius: this._size,
15781
- fill: HEADER_MENU_SHAPE_CIRCLE_FILL
15273
+ radius: this._size,
15274
+ fill: HEADER_MENU_SHAPE_CIRCLE_FILL
15275
+ });
15276
+ const iconSize = this._size * .5 * this._iconRatio;
15277
+ const sixtyDegree = Math.PI / 180 * 60;
15278
+ const left = iconSize * Math.sin(sixtyDegree);
15279
+ const top = iconSize * Math.cos(sixtyDegree);
15280
+ _univerjs_engine_render.RegularPolygon.drawWith(ctx, {
15281
+ pointsGroup: [[
15282
+ {
15283
+ x: -left + this._size / 2,
15284
+ y: -top + this._size / 2
15285
+ },
15286
+ {
15287
+ x: left + this._size / 2,
15288
+ y: -top + this._size / 2
15289
+ },
15290
+ {
15291
+ x: this._size / 2,
15292
+ y: iconSize + this._size / 2
15293
+ }
15294
+ ]],
15295
+ fill: HEADER_MENU_SHAPE_TRIANGLE_FILL
15296
+ });
15297
+ }
15298
+ };
15299
+
15300
+ //#endregion
15301
+ //#region src/views/header-unhide-shape.ts
15302
+ const UNHIDE_ICON_SIZE = 12;
15303
+ const UNHIDE_ARROW_RATIO = .4;
15304
+ var HeaderUnhideShape = class extends _univerjs_engine_render.Shape {
15305
+ constructor(key, props, onClick) {
15306
+ super(key, props);
15307
+ _defineProperty(this, "_size", 12);
15308
+ _defineProperty(this, "_iconRatio", UNHIDE_ARROW_RATIO);
15309
+ _defineProperty(this, "_hovered", true);
15310
+ _defineProperty(this, "_hasPrevious", true);
15311
+ _defineProperty(this, "_hasNext", true);
15312
+ _defineProperty(this, "_unhideType", void 0);
15313
+ if (props) this.setShapeProps(props);
15314
+ this.onPointerEnter$.subscribeEvent(() => this.setShapeProps({ hovered: true }));
15315
+ this.onPointerLeave$.subscribeEvent(() => this.setShapeProps({ hovered: false }));
15316
+ this.onPointerDown$.subscribeEvent(() => onClick === null || onClick === void 0 ? void 0 : onClick());
15317
+ }
15318
+ setShapeProps(props) {
15319
+ if (props.type !== void 0) this._unhideType = props.type;
15320
+ if (props.hovered !== void 0) this._hovered = props.hovered;
15321
+ if (props.hasPrevious !== void 0) this._hasPrevious = props.hasPrevious;
15322
+ if (props.hasNext !== void 0) this._hasNext = props.hasNext;
15323
+ this.transformByState({
15324
+ width: this._size * (this._unhideType === 1 ? 2 : 1),
15325
+ height: this._size * (this._unhideType === 0 ? 2 : 1)
15326
+ });
15327
+ }
15328
+ _draw(ctx) {
15329
+ if (this._unhideType === 0) this._drawOnRow(ctx);
15330
+ else this._drawOnCol(ctx);
15331
+ }
15332
+ _drawOnRow(ctx) {
15333
+ if (this._hovered) if (!this._hasNext || !this._hasPrevious) _univerjs_engine_render.Rect.drawWith(ctx, {
15334
+ width: this._size,
15335
+ height: this._size,
15336
+ stroke: HEADER_MENU_SHAPE_TRIANGLE_FILL,
15337
+ fill: HEADER_MENU_BACKGROUND_COLOR
15338
+ });
15339
+ else _univerjs_engine_render.Rect.drawWith(ctx, {
15340
+ width: this._size,
15341
+ height: 2 * this._size,
15342
+ stroke: HEADER_MENU_SHAPE_TRIANGLE_FILL,
15343
+ fill: HEADER_MENU_BACKGROUND_COLOR
15344
+ });
15345
+ const iconSize = this._size * .5 * this._iconRatio;
15346
+ const sixtyDegree = Math.PI / 3;
15347
+ const top = iconSize * Math.cos(sixtyDegree);
15348
+ const left = iconSize * Math.sin(sixtyDegree);
15349
+ if (this._hasPrevious) _univerjs_engine_render.RegularPolygon.drawWith(ctx, {
15350
+ pointsGroup: [[
15351
+ {
15352
+ x: this._size / 2,
15353
+ y: this._size / 2 - left
15354
+ },
15355
+ {
15356
+ x: this._size / 2 - left,
15357
+ y: this._size / 2 + top
15358
+ },
15359
+ {
15360
+ x: this._size / 2 + left,
15361
+ y: this._size / 2 + top
15362
+ }
15363
+ ]],
15364
+ fill: HEADER_MENU_SHAPE_TRIANGLE_FILL
15365
+ });
15366
+ if (this._hasNext) {
15367
+ const offset = this._hasPrevious ? 3 : 1;
15368
+ _univerjs_engine_render.RegularPolygon.drawWith(ctx, {
15369
+ pointsGroup: [[
15370
+ {
15371
+ x: this._size / 2,
15372
+ y: this._size * offset / 2 + left
15373
+ },
15374
+ {
15375
+ x: this._size / 2 - left,
15376
+ y: this._size * offset / 2 - top
15377
+ },
15378
+ {
15379
+ x: this._size / 2 + left,
15380
+ y: this._size * offset / 2 - top
15381
+ }
15382
+ ]],
15383
+ fill: HEADER_MENU_SHAPE_TRIANGLE_FILL
15384
+ });
15385
+ }
15386
+ }
15387
+ /**
15388
+ *
15389
+ * @param ctx
15390
+ */
15391
+ _drawOnCol(ctx) {
15392
+ if (this._hovered) if (!this._hasNext || !this._hasPrevious) _univerjs_engine_render.Rect.drawWith(ctx, {
15393
+ width: this._size,
15394
+ height: this._size,
15395
+ stroke: HEADER_MENU_SHAPE_TRIANGLE_FILL,
15396
+ fill: HEADER_MENU_BACKGROUND_COLOR
15397
+ });
15398
+ else _univerjs_engine_render.Rect.drawWith(ctx, {
15399
+ width: 2 * this._size,
15400
+ height: this._size,
15401
+ stroke: HEADER_MENU_SHAPE_TRIANGLE_FILL,
15402
+ fill: HEADER_MENU_BACKGROUND_COLOR
15782
15403
  });
15783
15404
  const iconSize = this._size * .5 * this._iconRatio;
15784
- const sixtyDegree = Math.PI / 180 * 60;
15785
- const left = iconSize * Math.sin(sixtyDegree);
15405
+ const sixtyDegree = Math.PI / 3;
15786
15406
  const top = iconSize * Math.cos(sixtyDegree);
15787
- _univerjs_engine_render.RegularPolygon.drawWith(ctx, {
15407
+ const left = iconSize * Math.sin(sixtyDegree);
15408
+ if (this._hasPrevious) _univerjs_engine_render.RegularPolygon.drawWith(ctx, {
15788
15409
  pointsGroup: [[
15789
15410
  {
15790
- x: -left + this._size / 2,
15791
- y: -top + this._size / 2
15411
+ x: -top + this._size / 2,
15412
+ y: this._size / 2
15792
15413
  },
15793
15414
  {
15794
- x: left + this._size / 2,
15795
- y: -top + this._size / 2
15415
+ x: this._size / 2 + left,
15416
+ y: this._size / 2 - left
15796
15417
  },
15797
15418
  {
15798
- x: this._size / 2,
15799
- y: iconSize + this._size / 2
15419
+ x: this._size / 2 + left,
15420
+ y: this._size / 2 + left
15800
15421
  }
15801
15422
  ]],
15802
15423
  fill: HEADER_MENU_SHAPE_TRIANGLE_FILL
15803
15424
  });
15425
+ if (this._hasNext) {
15426
+ const offset = this._hasPrevious ? 3 : 1;
15427
+ _univerjs_engine_render.RegularPolygon.drawWith(ctx, {
15428
+ pointsGroup: [[
15429
+ {
15430
+ x: top + this._size * offset / 2,
15431
+ y: this._size / 2
15432
+ },
15433
+ {
15434
+ x: -left + this._size * offset / 2,
15435
+ y: this._size / 2 - left
15436
+ },
15437
+ {
15438
+ x: -left + this._size * offset / 2,
15439
+ y: this._size / 2 + left
15440
+ }
15441
+ ]],
15442
+ fill: HEADER_MENU_SHAPE_TRIANGLE_FILL
15443
+ });
15444
+ }
15804
15445
  }
15805
15446
  };
15806
15447
 
15807
15448
  //#endregion
15808
- //#region src/views/header-unhide-shape.ts
15809
- const UNHIDE_ICON_SIZE = 12;
15810
- const UNHIDE_ARROW_RATIO = .4;
15811
- var HeaderUnhideShape = class extends _univerjs_engine_render.Shape {
15812
- constructor(key, props, onClick) {
15813
- super(key, props);
15814
- _defineProperty(this, "_size", 12);
15815
- _defineProperty(this, "_iconRatio", UNHIDE_ARROW_RATIO);
15816
- _defineProperty(this, "_hovered", true);
15817
- _defineProperty(this, "_hasPrevious", true);
15818
- _defineProperty(this, "_hasNext", true);
15819
- _defineProperty(this, "_unhideType", void 0);
15820
- if (props) this.setShapeProps(props);
15821
- this.onPointerEnter$.subscribeEvent(() => this.setShapeProps({ hovered: true }));
15822
- this.onPointerLeave$.subscribeEvent(() => this.setShapeProps({ hovered: false }));
15823
- this.onPointerDown$.subscribeEvent(() => onClick === null || onClick === void 0 ? void 0 : onClick());
15449
+ //#region src/controllers/render-controllers/header-unhide.render-controller.ts
15450
+ const HEADER_UNHIDE_CONTROLLER_SHAPE = "__SpreadsheetHeaderUnhideSHAPEControllerShape__";
15451
+ const HEADER_UNHIDE_RANGE_VISIBLE_CHECK = (0, _univerjs_core.createInterceptorKey)("headerUnhideRangeVisibleCheck");
15452
+ let HeaderUnhideRenderController = class HeaderUnhideRenderController extends _univerjs_core.RxDisposable {
15453
+ get _workbook() {
15454
+ return this._context.unit;
15455
+ }
15456
+ constructor(_context, _sheetSkeletonManagerService, _headerUnhideRangeService, _commandService) {
15457
+ super();
15458
+ this._context = _context;
15459
+ this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
15460
+ this._headerUnhideRangeService = _headerUnhideRangeService;
15461
+ this._commandService = _commandService;
15462
+ _defineProperty(this, "_shapes", {
15463
+ cols: [],
15464
+ rows: []
15465
+ });
15466
+ _defineProperty(this, "interceptor", new _univerjs_core.InterceptorManager({ HEADER_UNHIDE_RANGE_VISIBLE_CHECK }));
15467
+ this._init();
15468
+ }
15469
+ dispose() {
15470
+ super.dispose();
15471
+ this._clearShapes();
15472
+ }
15473
+ _init() {
15474
+ let activeSheetId = "";
15475
+ this._context.unit.activeSheet$.pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((worksheet) => {
15476
+ this._clearShapes();
15477
+ if (!worksheet) {
15478
+ activeSheetId = "";
15479
+ return;
15480
+ }
15481
+ activeSheetId = worksheet.getSheetId();
15482
+ this._update(this._workbook, worksheet);
15483
+ });
15484
+ this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe((param) => {
15485
+ if (param) {
15486
+ const { unitId, sheetId } = param;
15487
+ if (unitId === this._workbook.getUnitId() && sheetId === activeSheetId) {
15488
+ const worksheet = this._workbook.getSheetBySheetId(sheetId);
15489
+ if (worksheet) this._update(this._workbook, worksheet);
15490
+ }
15491
+ }
15492
+ }));
15493
+ }
15494
+ _update(workbook, worksheet) {
15495
+ var _this$_sheetSkeletonM;
15496
+ const skeleton = (_this$_sheetSkeletonM = this._sheetSkeletonManagerService.getSkeletonParam(worksheet.getSheetId())) === null || _this$_sheetSkeletonM === void 0 ? void 0 : _this$_sheetSkeletonM.skeleton;
15497
+ if (!skeleton) return;
15498
+ const visibleCheck = this.interceptor.fetchThroughInterceptors(HEADER_UNHIDE_RANGE_VISIBLE_CHECK);
15499
+ const shouldRenderRange = (payload) => this._headerUnhideRangeService.shouldRenderRange(visibleCheck(true, payload) ?? true, payload);
15500
+ const hiddenRowRanges = worksheet.getHiddenRows().filter((range) => shouldRenderRange({
15501
+ axis: "row",
15502
+ range,
15503
+ workbook,
15504
+ worksheet
15505
+ }));
15506
+ const hiddenColRanges = worksheet.getHiddenCols().filter((range) => shouldRenderRange({
15507
+ axis: "column",
15508
+ range,
15509
+ workbook,
15510
+ worksheet
15511
+ }));
15512
+ const { scene } = this._getSheetObject();
15513
+ const rowCount = worksheet.getRowCount();
15514
+ const rowShapes = hiddenRowRanges.map((range) => {
15515
+ const { startRow, endRow } = range;
15516
+ const position = getCoordByCell(startRow, 0, scene, skeleton);
15517
+ const hasPrevious = startRow !== 0;
15518
+ const hasNext = endRow !== rowCount - 1;
15519
+ return new HeaderUnhideShape(HEADER_UNHIDE_CONTROLLER_SHAPE, {
15520
+ type: 0,
15521
+ hovered: false,
15522
+ hasPrevious,
15523
+ hasNext,
15524
+ top: position.startY - (hasPrevious ? 12 : 0),
15525
+ left: position.startX - 12
15526
+ }, () => this._commandService.executeCommand(_univerjs_sheets.SetSpecificRowsVisibleCommand.id, {
15527
+ unitId: workbook.getUnitId(),
15528
+ subUnitId: worksheet.getSheetId(),
15529
+ ranges: [range]
15530
+ }));
15531
+ });
15532
+ const colCount = worksheet.getColumnCount();
15533
+ const colShapes = hiddenColRanges.map((range) => {
15534
+ const { startColumn, endColumn } = range;
15535
+ const position = getCoordByCell(0, startColumn, scene, skeleton);
15536
+ const hasPrevious = startColumn !== 0;
15537
+ const hasNext = endColumn !== colCount - 1;
15538
+ return new HeaderUnhideShape(HEADER_UNHIDE_CONTROLLER_SHAPE, {
15539
+ type: 1,
15540
+ hovered: false,
15541
+ hasPrevious,
15542
+ hasNext,
15543
+ top: Math.max(skeleton.columnHeaderHeight, skeleton.columnHeaderHeightAndMarginTop) - 12,
15544
+ left: position.startX - (hasPrevious ? 12 : 0)
15545
+ }, () => this._commandService.executeCommand(_univerjs_sheets.SetSpecificColsVisibleCommand.id, {
15546
+ unitId: workbook.getUnitId(),
15547
+ subUnitId: worksheet.getSheetId(),
15548
+ ranges: [range]
15549
+ }));
15550
+ });
15551
+ scene.addObjects(colShapes, 12);
15552
+ scene.addObjects(rowShapes, 12);
15553
+ this._clearShapes();
15554
+ this._shapes = {
15555
+ cols: colShapes,
15556
+ rows: rowShapes
15557
+ };
15558
+ }
15559
+ _clearShapes() {
15560
+ this._shapes.cols.forEach((shape) => shape.dispose());
15561
+ this._shapes.rows.forEach((shape) => shape.dispose());
15562
+ this._shapes = {
15563
+ cols: [],
15564
+ rows: []
15565
+ };
15566
+ }
15567
+ _getSheetObject() {
15568
+ return getSheetObject(this._workbook, this._context);
15569
+ }
15570
+ };
15571
+ HeaderUnhideRenderController = __decorate([
15572
+ __decorateParam(1, (0, _univerjs_core.Inject)(SheetSkeletonManagerService)),
15573
+ __decorateParam(2, (0, _univerjs_core.Inject)(HeaderUnhideRangeService)),
15574
+ __decorateParam(3, _univerjs_core.ICommandService)
15575
+ ], HeaderUnhideRenderController);
15576
+
15577
+ //#endregion
15578
+ //#region src/controllers/render-controllers/sheet.render-controller.ts
15579
+ const FRAME_STACK_THRESHOLD = 60;
15580
+ let SheetRenderController = class SheetRenderController extends _univerjs_core.RxDisposable {
15581
+ constructor(_context, _configService, _sheetSkeletonManagerService, _sheetRenderService, _commandService, _telemetryService) {
15582
+ super();
15583
+ this._context = _context;
15584
+ this._configService = _configService;
15585
+ this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
15586
+ this._sheetRenderService = _sheetRenderService;
15587
+ this._commandService = _commandService;
15588
+ this._telemetryService = _telemetryService;
15589
+ _defineProperty(this, "_renderMetric$", new rxjs.Subject());
15590
+ _defineProperty(this, "renderMetric$", this._renderMetric$.asObservable());
15591
+ _defineProperty(this, "_renderFrameTimeMetric", null);
15592
+ _defineProperty(this, "_renderFrameTags", {});
15593
+ _defineProperty(this, "_afterRenderMetric$", new rxjs.Subject());
15594
+ this._addNewRender();
15595
+ this._initRenderMetricSubscriber();
15596
+ }
15597
+ _addNewRender() {
15598
+ const { scene, engine, unit: workbook } = this._context;
15599
+ this._addComponent(workbook);
15600
+ this._initRerenderScheduler();
15601
+ this._initCommandListener();
15602
+ const worksheet = this._context.unit.getActiveSheet();
15603
+ if (!worksheet) throw new Error("No active sheet found");
15604
+ const sheetId = worksheet.getSheetId();
15605
+ this._sheetSkeletonManagerService.setCurrent({ sheetId });
15606
+ const frameFn = () => scene.render();
15607
+ this.disposeWithMe(this._context.activated$.subscribe((activated) => {
15608
+ if (activated) engine.runRenderLoop(frameFn);
15609
+ else engine.stopRenderLoop(frameFn);
15610
+ }));
15611
+ }
15612
+ _initRenderMetricSubscriber() {
15613
+ const { engine } = this._context;
15614
+ this.disposeWithMe(engine.beginFrame$.subscribe(() => {
15615
+ this._renderFrameTimeMetric = null;
15616
+ this._renderFrameTags = {};
15617
+ }));
15618
+ this.disposeWithMe(engine.endFrame$.subscribe(() => {
15619
+ if (this._renderFrameTimeMetric && Object.keys(this._renderFrameTimeMetric).some((key) => key.startsWith(_univerjs_engine_render.SHEET_EXTENSION_PREFIX))) this._afterRenderMetric$.next({
15620
+ frameTimeMetric: this._renderFrameTimeMetric,
15621
+ tags: this._renderFrameTags
15622
+ });
15623
+ }));
15624
+ this.disposeWithMe(engine.renderFrameTimeMetric$.subscribe(([key, value]) => {
15625
+ if (!this._renderFrameTimeMetric) this._renderFrameTimeMetric = {};
15626
+ if (!this._renderFrameTimeMetric[key]) this._renderFrameTimeMetric[key] = [];
15627
+ this._renderFrameTimeMetric[key].push(Math.round(value * 100) / 100);
15628
+ }));
15629
+ this.disposeWithMe(engine.renderFrameTags$.subscribe(([key, value]) => {
15630
+ this._renderFrameTags[key] = value;
15631
+ }));
15632
+ const frameInfoList = [];
15633
+ this.disposeWithMe(this._afterRenderMetric$.pipe((0, rxjs.withLatestFrom)(engine.endFrame$)).subscribe(([sceneRenderDetail, basicFrameTimeInfo]) => {
15634
+ frameInfoList.push({
15635
+ FPS: basicFrameTimeInfo.FPS,
15636
+ elapsedTime: basicFrameTimeInfo.elapsedTime,
15637
+ frameTime: Math.round(basicFrameTimeInfo.frameTime * 100) / 100,
15638
+ ...sceneRenderDetail.frameTimeMetric,
15639
+ ...sceneRenderDetail.tags
15640
+ });
15641
+ if (frameInfoList.length > FRAME_STACK_THRESHOLD) {
15642
+ this._captureRenderMetric(frameInfoList);
15643
+ frameInfoList.length = 0;
15644
+ }
15645
+ }));
15824
15646
  }
15825
- setShapeProps(props) {
15826
- if (props.type !== void 0) this._unhideType = props.type;
15827
- if (props.hovered !== void 0) this._hovered = props.hovered;
15828
- if (props.hasPrevious !== void 0) this._hasPrevious = props.hasPrevious;
15829
- if (props.hasNext !== void 0) this._hasNext = props.hasNext;
15830
- this.transformByState({
15831
- width: this._size * (this._unhideType === 1 ? 2 : 1),
15832
- height: this._size * (this._unhideType === 0 ? 2 : 1)
15647
+ /**
15648
+ * Send render metric to telemetry service
15649
+ * @param frameInfoList
15650
+ */
15651
+ _captureRenderMetric(frameInfoList) {
15652
+ var _this$_telemetryServi;
15653
+ const filteredFrameInfo = frameInfoList;
15654
+ if (filteredFrameInfo.length === 0) return;
15655
+ const sumValueForNumListFields = (data) => {
15656
+ let totalSum = 0;
15657
+ const sums = Object.entries(data).filter(([_, value]) => Array.isArray(value)).map(([key]) => key).reduce((acc, key) => {
15658
+ acc[key] = data[key].reduce((sum, num) => sum + num, 0);
15659
+ return acc;
15660
+ }, {});
15661
+ Object.keys(data).filter((key) => key.startsWith(_univerjs_engine_render.SHEET_EXTENSION_PREFIX)).forEach((key) => {
15662
+ totalSum += sums[key];
15663
+ });
15664
+ return {
15665
+ ...sums,
15666
+ extensionTotal: totalSum
15667
+ };
15668
+ };
15669
+ const frameTimeListAfterSum = frameInfoList.map((info) => {
15670
+ return {
15671
+ ...info,
15672
+ ...sumValueForNumListFields(info)
15673
+ };
15833
15674
  });
15675
+ const getSummaryStats = (list) => {
15676
+ return Object.entries(list[0]).filter(([key, _]) => !["elapsedTime"].includes(key)).filter(([_, value]) => typeof value === "number").map(([key]) => key).reduce((acc, key) => {
15677
+ const values = list.map((obj) => obj[key]);
15678
+ const max = Math.max(...values);
15679
+ const min = Math.min(...values);
15680
+ const avg = values.reduce((sum, val) => sum + val, 0) / values.length;
15681
+ acc[key] = {
15682
+ max: Math.round(max * 100) / 100,
15683
+ min: Math.round(min * 100) / 100,
15684
+ avg: Math.round(avg * 100) / 100
15685
+ };
15686
+ return acc;
15687
+ }, {});
15688
+ };
15689
+ const summaryFrameStats = getSummaryStats(frameTimeListAfterSum);
15690
+ const elapsedTimeToStart = filteredFrameInfo[filteredFrameInfo.length - 1].elapsedTime;
15691
+ const telemetryData = {
15692
+ sheetId: this._context.unit.getActiveSheet().getSheetId(),
15693
+ unitId: this._context.unit.getUnitId(),
15694
+ elapsedTimeToStart,
15695
+ ...summaryFrameStats
15696
+ };
15697
+ this._renderMetric$.next(telemetryData);
15698
+ (_this$_telemetryServi = this._telemetryService) === null || _this$_telemetryServi === void 0 || _this$_telemetryServi.capture("sheet_render_cost", telemetryData);
15834
15699
  }
15835
- _draw(ctx) {
15836
- if (this._unhideType === 0) this._drawOnRow(ctx);
15837
- else this._drawOnCol(ctx);
15700
+ _addComponent(workbook) {
15701
+ const { scene, components } = this._context;
15702
+ const worksheet = workbook.getActiveSheet();
15703
+ const spreadsheet = new _univerjs_engine_render.Spreadsheet("__SpreadsheetRender__");
15704
+ this._addViewport(worksheet);
15705
+ const spreadsheetRowHeader = new _univerjs_engine_render.SpreadsheetRowHeader("__SpreadsheetRowHeader__");
15706
+ const spreadsheetColumnHeader = new _univerjs_engine_render.SpreadsheetColumnHeader("__SpreadsheetColumnHeader__");
15707
+ const SpreadsheetLeftTopPlaceholder = new _univerjs_engine_render.Rect("__SpreadsheetLeftTopPlaceholder__", {
15708
+ zIndex: 2,
15709
+ left: -1,
15710
+ top: -1,
15711
+ fill: "gray.50",
15712
+ stroke: "gray.200",
15713
+ strokeWidth: 1
15714
+ });
15715
+ this._context.mainComponent = spreadsheet;
15716
+ components.set("__SpreadsheetRender__", spreadsheet);
15717
+ components.set("__SpreadsheetRowHeader__", spreadsheetRowHeader);
15718
+ components.set("__SpreadsheetColumnHeader__", spreadsheetColumnHeader);
15719
+ components.set("__SpreadsheetLeftTopPlaceholder__", SpreadsheetLeftTopPlaceholder);
15720
+ scene.addObjects([spreadsheet], 0);
15721
+ scene.addObjects([
15722
+ spreadsheetRowHeader,
15723
+ spreadsheetColumnHeader,
15724
+ SpreadsheetLeftTopPlaceholder
15725
+ ], 10);
15726
+ scene.enableLayerCache(0, 10);
15838
15727
  }
15839
- _drawOnRow(ctx) {
15840
- if (this._hovered) if (!this._hasNext || !this._hasPrevious) _univerjs_engine_render.Rect.drawWith(ctx, {
15841
- width: this._size,
15842
- height: this._size,
15843
- stroke: HEADER_MENU_SHAPE_TRIANGLE_FILL,
15844
- fill: HEADER_MENU_BACKGROUND_COLOR
15728
+ _initViewports(scene, rowHeader, columnHeader) {
15729
+ const rowHeaderWidth = rowHeader.hidden ? 0 : rowHeader.width;
15730
+ const columnHeaderHeight = columnHeader.hidden ? 0 : columnHeader.height;
15731
+ const bufferEdgeX = 100;
15732
+ const bufferEdgeY = 100;
15733
+ const viewMain = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN, scene, {
15734
+ left: rowHeaderWidth,
15735
+ top: columnHeaderHeight,
15736
+ bottom: 0,
15737
+ right: 0,
15738
+ isWheelPreventDefaultX: true,
15739
+ allowCache: true,
15740
+ bufferEdgeX,
15741
+ bufferEdgeY
15845
15742
  });
15846
- else _univerjs_engine_render.Rect.drawWith(ctx, {
15847
- width: this._size,
15848
- height: 2 * this._size,
15849
- stroke: HEADER_MENU_SHAPE_TRIANGLE_FILL,
15850
- fill: HEADER_MENU_BACKGROUND_COLOR
15743
+ const viewMainLeftTop = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP, scene, {
15744
+ isWheelPreventDefaultX: true,
15745
+ active: false,
15746
+ allowCache: true,
15747
+ bufferEdgeX: 0,
15748
+ bufferEdgeY: 0
15851
15749
  });
15852
- const iconSize = this._size * .5 * this._iconRatio;
15853
- const sixtyDegree = Math.PI / 3;
15854
- const top = iconSize * Math.cos(sixtyDegree);
15855
- const left = iconSize * Math.sin(sixtyDegree);
15856
- if (this._hasPrevious) _univerjs_engine_render.RegularPolygon.drawWith(ctx, {
15857
- pointsGroup: [[
15858
- {
15859
- x: this._size / 2,
15860
- y: this._size / 2 - left
15861
- },
15862
- {
15863
- x: this._size / 2 - left,
15864
- y: this._size / 2 + top
15865
- },
15866
- {
15867
- x: this._size / 2 + left,
15868
- y: this._size / 2 + top
15869
- }
15870
- ]],
15871
- fill: HEADER_MENU_SHAPE_TRIANGLE_FILL
15750
+ const viewMainLeft = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT, scene, {
15751
+ isWheelPreventDefaultX: true,
15752
+ active: false,
15753
+ allowCache: true,
15754
+ bufferEdgeX: 0,
15755
+ bufferEdgeY
15872
15756
  });
15873
- if (this._hasNext) {
15874
- const offset = this._hasPrevious ? 3 : 1;
15875
- _univerjs_engine_render.RegularPolygon.drawWith(ctx, {
15876
- pointsGroup: [[
15877
- {
15878
- x: this._size / 2,
15879
- y: this._size * offset / 2 + left
15880
- },
15881
- {
15882
- x: this._size / 2 - left,
15883
- y: this._size * offset / 2 - top
15884
- },
15885
- {
15886
- x: this._size / 2 + left,
15887
- y: this._size * offset / 2 - top
15888
- }
15889
- ]],
15890
- fill: HEADER_MENU_SHAPE_TRIANGLE_FILL
15891
- });
15892
- }
15893
- }
15894
- /**
15895
- *
15896
- * @param ctx
15897
- */
15898
- _drawOnCol(ctx) {
15899
- if (this._hovered) if (!this._hasNext || !this._hasPrevious) _univerjs_engine_render.Rect.drawWith(ctx, {
15900
- width: this._size,
15901
- height: this._size,
15902
- stroke: HEADER_MENU_SHAPE_TRIANGLE_FILL,
15903
- fill: HEADER_MENU_BACKGROUND_COLOR
15757
+ const viewMainTop = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP, scene, {
15758
+ isWheelPreventDefaultX: true,
15759
+ active: false,
15760
+ allowCache: true,
15761
+ bufferEdgeX,
15762
+ bufferEdgeY: 0
15904
15763
  });
15905
- else _univerjs_engine_render.Rect.drawWith(ctx, {
15906
- width: 2 * this._size,
15907
- height: this._size,
15908
- stroke: HEADER_MENU_SHAPE_TRIANGLE_FILL,
15909
- fill: HEADER_MENU_BACKGROUND_COLOR
15764
+ const viewRowTop = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP, scene, {
15765
+ active: false,
15766
+ isWheelPreventDefaultX: true
15910
15767
  });
15911
- const iconSize = this._size * .5 * this._iconRatio;
15912
- const sixtyDegree = Math.PI / 3;
15913
- const top = iconSize * Math.cos(sixtyDegree);
15914
- const left = iconSize * Math.sin(sixtyDegree);
15915
- if (this._hasPrevious) _univerjs_engine_render.RegularPolygon.drawWith(ctx, {
15916
- pointsGroup: [[
15917
- {
15918
- x: -top + this._size / 2,
15919
- y: this._size / 2
15920
- },
15921
- {
15922
- x: this._size / 2 + left,
15923
- y: this._size / 2 - left
15924
- },
15925
- {
15926
- x: this._size / 2 + left,
15927
- y: this._size / 2 + left
15928
- }
15929
- ]],
15930
- fill: HEADER_MENU_SHAPE_TRIANGLE_FILL
15768
+ const viewRowBottom = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM, scene, {
15769
+ left: 0,
15770
+ top: columnHeaderHeight,
15771
+ bottom: 0,
15772
+ width: rowHeaderWidth + 1,
15773
+ isWheelPreventDefaultX: true
15931
15774
  });
15932
- if (this._hasNext) {
15933
- const offset = this._hasPrevious ? 3 : 1;
15934
- _univerjs_engine_render.RegularPolygon.drawWith(ctx, {
15935
- pointsGroup: [[
15936
- {
15937
- x: top + this._size * offset / 2,
15938
- y: this._size / 2
15939
- },
15940
- {
15941
- x: -left + this._size * offset / 2,
15942
- y: this._size / 2 - left
15943
- },
15944
- {
15945
- x: -left + this._size * offset / 2,
15946
- y: this._size / 2 + left
15947
- }
15948
- ]],
15949
- fill: HEADER_MENU_SHAPE_TRIANGLE_FILL
15950
- });
15951
- }
15952
- }
15953
- };
15954
-
15955
- //#endregion
15956
- //#region src/controllers/render-controllers/header-unhide.render-controller.ts
15957
- const HEADER_UNHIDE_CONTROLLER_SHAPE = "__SpreadsheetHeaderUnhideSHAPEControllerShape__";
15958
- const HEADER_UNHIDE_RANGE_VISIBLE_CHECK = (0, _univerjs_core.createInterceptorKey)("headerUnhideRangeVisibleCheck");
15959
- let HeaderUnhideRenderController = class HeaderUnhideRenderController extends _univerjs_core.RxDisposable {
15960
- get _workbook() {
15961
- return this._context.unit;
15962
- }
15963
- constructor(_context, _sheetSkeletonManagerService, _headerUnhideRangeService, _commandService) {
15964
- super();
15965
- this._context = _context;
15966
- this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
15967
- this._headerUnhideRangeService = _headerUnhideRangeService;
15968
- this._commandService = _commandService;
15969
- _defineProperty(this, "_shapes", {
15970
- cols: [],
15971
- rows: []
15775
+ const viewColumnLeft = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT, scene, {
15776
+ active: false,
15777
+ isWheelPreventDefaultX: true
15972
15778
  });
15973
- _defineProperty(this, "interceptor", new _univerjs_core.InterceptorManager({ HEADER_UNHIDE_RANGE_VISIBLE_CHECK }));
15974
- this._init();
15779
+ const viewColumnRight = new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT, scene, {
15780
+ left: rowHeaderWidth,
15781
+ top: 0,
15782
+ height: columnHeaderHeight + 1,
15783
+ right: 0,
15784
+ isWheelPreventDefaultX: true
15785
+ });
15786
+ return {
15787
+ viewMain,
15788
+ viewLeftTop: new _univerjs_engine_render.Viewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP, scene, {
15789
+ left: 0,
15790
+ top: 0,
15791
+ width: rowHeaderWidth,
15792
+ height: columnHeaderHeight,
15793
+ isWheelPreventDefaultX: true
15794
+ }),
15795
+ viewMainLeftTop,
15796
+ viewMainLeft,
15797
+ viewMainTop,
15798
+ viewColumnLeft,
15799
+ viewRowTop,
15800
+ viewRowBottom,
15801
+ viewColumnRight
15802
+ };
15975
15803
  }
15976
- dispose() {
15977
- super.dispose();
15978
- this._clearShapes();
15804
+ /**
15805
+ *
15806
+ * initViewport & wheel event
15807
+ * +-----------------+--------------------+-------------------+
15808
+ * | VIEW_LEFT_TOP | VIEW_COLUMN_LEFT | VIEW_COLUMN_RIGHT |
15809
+ * +-----------------+--------------------+-------------------+
15810
+ * | VIEW_ROW_TOP | VIEW_MAIN_LEFT_TOP | VIEW_MAIN_TOP |
15811
+ * +-----------------+--------------------+-------------------+
15812
+ * | VIEW_ROW_BOTTOM | VIEW_MAIN_LEFT | VIEW_MAIN |
15813
+ * +-----------------+--------------------+-------------------+
15814
+ */
15815
+ _addViewport(worksheet) {
15816
+ const scene = this._context.scene;
15817
+ const { rowHeader, columnHeader } = worksheet.getConfig();
15818
+ const { viewMain } = this._initViewports(scene, rowHeader, columnHeader);
15819
+ const sheetsUIConfig = this._configService.getConfig(SHEETS_UI_PLUGIN_CONFIG_KEY);
15820
+ new _univerjs_engine_render.ScrollBar(viewMain, sheetsUIConfig === null || sheetsUIConfig === void 0 ? void 0 : sheetsUIConfig.scrollConfig);
15821
+ scene.attachControl();
15822
+ return viewMain;
15979
15823
  }
15980
- _init() {
15981
- let activeSheetId = "";
15982
- this._context.unit.activeSheet$.pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((worksheet) => {
15983
- this._clearShapes();
15984
- if (!worksheet) {
15985
- activeSheetId = "";
15986
- return;
15987
- }
15988
- activeSheetId = worksheet.getSheetId();
15989
- this._update(this._workbook, worksheet);
15990
- });
15824
+ _initRerenderScheduler() {
15991
15825
  this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe((param) => {
15992
- if (param) {
15993
- const { unitId, sheetId } = param;
15994
- if (unitId === this._workbook.getUnitId() && sheetId === activeSheetId) {
15995
- const worksheet = this._workbook.getSheetBySheetId(sheetId);
15996
- if (worksheet) this._update(this._workbook, worksheet);
15997
- }
15998
- }
15826
+ if (!param) return null;
15827
+ const { skeleton: spreadsheetSkeleton, sheetId } = param;
15828
+ const workbook = this._context.unit;
15829
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(sheetId);
15830
+ if (workbook == null || worksheet == null) return;
15831
+ const { mainComponent, components } = this._context;
15832
+ const spreadsheet = mainComponent;
15833
+ const spreadsheetRowHeader = components.get("__SpreadsheetRowHeader__");
15834
+ const spreadsheetColumnHeader = components.get("__SpreadsheetColumnHeader__");
15835
+ const spreadsheetLeftTopPlaceholder = components.get("__SpreadsheetLeftTopPlaceholder__");
15836
+ const leftTopPlaceholderSize = getLeftTopPlaceholderSize(spreadsheetSkeleton);
15837
+ spreadsheet === null || spreadsheet === void 0 || spreadsheet.updateSkeleton(spreadsheetSkeleton);
15838
+ spreadsheetRowHeader === null || spreadsheetRowHeader === void 0 || spreadsheetRowHeader.updateSkeleton(spreadsheetSkeleton);
15839
+ spreadsheetColumnHeader === null || spreadsheetColumnHeader === void 0 || spreadsheetColumnHeader.updateSkeleton(spreadsheetSkeleton);
15840
+ spreadsheetLeftTopPlaceholder === null || spreadsheetLeftTopPlaceholder === void 0 || spreadsheetLeftTopPlaceholder.transformByState({
15841
+ width: leftTopPlaceholderSize.width,
15842
+ height: leftTopPlaceholderSize.height
15843
+ });
15999
15844
  }));
16000
15845
  }
16001
- _update(workbook, worksheet) {
16002
- var _this$_sheetSkeletonM;
16003
- const skeleton = (_this$_sheetSkeletonM = this._sheetSkeletonManagerService.getSkeletonParam(worksheet.getSheetId())) === null || _this$_sheetSkeletonM === void 0 ? void 0 : _this$_sheetSkeletonM.skeleton;
16004
- if (!skeleton) return;
16005
- const visibleCheck = this.interceptor.fetchThroughInterceptors(HEADER_UNHIDE_RANGE_VISIBLE_CHECK);
16006
- const shouldRenderRange = (payload) => this._headerUnhideRangeService.shouldRenderRange(visibleCheck(true, payload) ?? true, payload);
16007
- const hiddenRowRanges = worksheet.getHiddenRows().filter((range) => shouldRenderRange({
16008
- axis: "row",
16009
- range,
16010
- workbook,
16011
- worksheet
16012
- }));
16013
- const hiddenColRanges = worksheet.getHiddenCols().filter((range) => shouldRenderRange({
16014
- axis: "column",
16015
- range,
16016
- workbook,
16017
- worksheet
15846
+ _initCommandListener() {
15847
+ this.disposeWithMe(this._commandService.onCommandExecuted((command, options) => {
15848
+ const { unit: workbook } = this._context;
15849
+ const { id: commandId } = command;
15850
+ if (_univerjs_sheets.COMMAND_LISTENER_SKELETON_CHANGE.includes(commandId) || this._sheetRenderService.checkMutationShouldTriggerRerender(commandId)) {
15851
+ const { unitId, subUnitId } = command.params;
15852
+ const worksheet = workbook.getActiveSheet();
15853
+ if (!worksheet) return;
15854
+ const workbookId = this._context.unitId;
15855
+ const worksheetId = worksheet.getSheetId();
15856
+ if (unitId !== workbookId || subUnitId !== worksheetId) return;
15857
+ this._sheetSkeletonManagerService.makeDirty({
15858
+ sheetId: worksheetId,
15859
+ commandId
15860
+ }, true);
15861
+ this._sheetSkeletonManagerService.setCurrent({
15862
+ sheetId: worksheetId,
15863
+ commandId
15864
+ });
15865
+ } else if (_univerjs_sheets.COMMAND_LISTENER_VALUE_CHANGE.includes(commandId)) this._sheetSkeletonManagerService.reCalculate();
15866
+ if (command.type === _univerjs_core.CommandType.MUTATION) this._markUnitDirty(command, options);
16018
15867
  }));
16019
- const { scene } = this._getSheetObject();
16020
- const rowCount = worksheet.getRowCount();
16021
- const rowShapes = hiddenRowRanges.map((range) => {
16022
- const { startRow, endRow } = range;
16023
- const position = getCoordByCell(startRow, 0, scene, skeleton);
16024
- const hasPrevious = startRow !== 0;
16025
- const hasNext = endRow !== rowCount - 1;
16026
- return new HeaderUnhideShape(HEADER_UNHIDE_CONTROLLER_SHAPE, {
16027
- type: 0,
16028
- hovered: false,
16029
- hasPrevious,
16030
- hasNext,
16031
- top: position.startY - (hasPrevious ? 12 : 0),
16032
- left: position.startX - 12
16033
- }, () => this._commandService.executeCommand(_univerjs_sheets.SetSpecificRowsVisibleCommand.id, {
16034
- unitId: workbook.getUnitId(),
16035
- subUnitId: worksheet.getSheetId(),
16036
- ranges: [range]
16037
- }));
16038
- });
16039
- const colCount = worksheet.getColumnCount();
16040
- const colShapes = hiddenColRanges.map((range) => {
16041
- const { startColumn, endColumn } = range;
16042
- const position = getCoordByCell(0, startColumn, scene, skeleton);
16043
- const hasPrevious = startColumn !== 0;
16044
- const hasNext = endColumn !== colCount - 1;
16045
- return new HeaderUnhideShape(HEADER_UNHIDE_CONTROLLER_SHAPE, {
16046
- type: 1,
16047
- hovered: false,
16048
- hasPrevious,
16049
- hasNext,
16050
- top: Math.max(skeleton.columnHeaderHeight, skeleton.columnHeaderHeightAndMarginTop) - 12,
16051
- left: position.startX - (hasPrevious ? 12 : 0)
16052
- }, () => this._commandService.executeCommand(_univerjs_sheets.SetSpecificColsVisibleCommand.id, {
16053
- unitId: workbook.getUnitId(),
16054
- subUnitId: worksheet.getSheetId(),
16055
- ranges: [range]
16056
- }));
16057
- });
16058
- scene.addObjects(colShapes, 12);
16059
- scene.addObjects(rowShapes, 12);
16060
- this._clearShapes();
16061
- this._shapes = {
16062
- cols: colShapes,
16063
- rows: rowShapes
16064
- };
16065
15868
  }
16066
- _clearShapes() {
16067
- this._shapes.cols.forEach((shape) => shape.dispose());
16068
- this._shapes.rows.forEach((shape) => shape.dispose());
16069
- this._shapes = {
16070
- cols: [],
16071
- rows: []
15869
+ _markUnitDirty(command, options) {
15870
+ if (command.id.substring(0, 3) === "doc") return;
15871
+ const { mainComponent: spreadsheet, scene } = this._context;
15872
+ if (command.id === _univerjs_engine_formula.SetFormulaCalculationNotificationMutation.id) {
15873
+ if (command.params.stageInfo != null) return;
15874
+ }
15875
+ if (spreadsheet) spreadsheet.makeDirty();
15876
+ scene.makeDirty();
15877
+ if (!command.params) return;
15878
+ const cmdParams = command.params;
15879
+ const viewports = this._spreadsheetViewports(scene);
15880
+ if (command.id === _univerjs_sheets.SetRangeValuesMutation.id && cmdParams.cellValue && !(options === null || options === void 0 ? void 0 : options.fromChangeset)) {
15881
+ const dirtyRange = this._cellValueToRange(cmdParams.cellValue);
15882
+ const dirtyBounds = this._rangeToBounds([dirtyRange]);
15883
+ this._markViewportDirty(viewports, dirtyBounds);
15884
+ spreadsheet.setDirtyArea(dirtyBounds);
15885
+ }
15886
+ if (command.id === _univerjs_sheets.MoveRangeMutation.id && cmdParams.from && cmdParams.to && !(options === null || options === void 0 ? void 0 : options.fromChangeset)) {
15887
+ const fromRange = cmdParams.fromRange || this._cellValueToRange(cmdParams.from.value);
15888
+ const toRange = cmdParams.toRange || this._cellValueToRange(cmdParams.to.value);
15889
+ const dirtyBounds = this._rangeToBounds([fromRange, toRange]);
15890
+ this._markViewportDirty(viewports, dirtyBounds);
15891
+ spreadsheet.setDirtyArea(dirtyBounds);
15892
+ }
15893
+ }
15894
+ /**
15895
+ * cellValue data structure:
15896
+ * {[row]: { [col]: value}}
15897
+ * @param cellValue
15898
+ * @returns IRange
15899
+ */
15900
+ _cellValueToRange(cellValue) {
15901
+ const columns = [];
15902
+ let minCol = 0;
15903
+ let maxCol = 0;
15904
+ let minRow = 0;
15905
+ let maxRow = 0;
15906
+ for (const [_row, columnObj] of Object.entries(cellValue)) {
15907
+ for (const column in columnObj) {
15908
+ columns.push(Number(column));
15909
+ if (minCol > Number(column)) minCol = Number(column);
15910
+ if (maxCol < Number(column)) maxCol = Number(column);
15911
+ }
15912
+ if (minRow > Number(_row)) minRow = Number(_row);
15913
+ if (maxRow < Number(_row)) maxRow = Number(_row);
15914
+ }
15915
+ return {
15916
+ startRow: minRow,
15917
+ endRow: maxRow,
15918
+ startColumn: minCol,
15919
+ endColumn: maxCol
16072
15920
  };
16073
15921
  }
16074
- _getSheetObject() {
16075
- return getSheetObject(this._workbook, this._context);
15922
+ _rangeToBounds(ranges) {
15923
+ const { rowHeightAccumulation, columnWidthAccumulation, rowHeaderWidth, columnHeaderHeight } = this._sheetSkeletonManagerService.getCurrentParam().skeleton;
15924
+ const dirtyBounds = [];
15925
+ for (const r of ranges) {
15926
+ const { startRow, endRow, startColumn, endColumn } = r;
15927
+ const top = startRow === 0 ? 0 : rowHeightAccumulation[startRow - 1] + columnHeaderHeight;
15928
+ const bottom = rowHeightAccumulation[endRow] + columnHeaderHeight;
15929
+ const left = startColumn === 0 ? 0 : columnWidthAccumulation[startColumn - 1] + rowHeaderWidth;
15930
+ const right = columnWidthAccumulation[endColumn] + rowHeaderWidth;
15931
+ dirtyBounds.push({
15932
+ top,
15933
+ left,
15934
+ bottom,
15935
+ right,
15936
+ width: right - left,
15937
+ height: bottom - top
15938
+ });
15939
+ }
15940
+ return dirtyBounds;
15941
+ }
15942
+ _markViewportDirty(viewports, dirtyBounds) {
15943
+ const activeViewports = viewports.filter((vp) => vp.isActive && vp.cacheBound);
15944
+ for (const vp of activeViewports) for (const b of dirtyBounds) if (_univerjs_core.Rectangle.hasIntersectionBetweenTwoRect(vp.cacheBound, b)) vp.markDirty(true);
15945
+ }
15946
+ _spreadsheetViewports(scene) {
15947
+ return scene.getViewports().filter((v) => [
15948
+ "viewMain",
15949
+ "viewMainLeftTop",
15950
+ "viewMainTop",
15951
+ "viewMainLeft"
15952
+ ].includes(v.viewportKey));
16076
15953
  }
16077
15954
  };
16078
- HeaderUnhideRenderController = __decorate([
16079
- __decorateParam(1, (0, _univerjs_core.Inject)(SheetSkeletonManagerService)),
16080
- __decorateParam(2, (0, _univerjs_core.Inject)(HeaderUnhideRangeService)),
16081
- __decorateParam(3, _univerjs_core.ICommandService)
16082
- ], HeaderUnhideRenderController);
15955
+ SheetRenderController = __decorate([
15956
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.IConfigService)),
15957
+ __decorateParam(2, (0, _univerjs_core.Inject)(SheetSkeletonManagerService)),
15958
+ __decorateParam(3, (0, _univerjs_core.Inject)(SheetsRenderService)),
15959
+ __decorateParam(4, _univerjs_core.ICommandService),
15960
+ __decorateParam(5, (0, _univerjs_core.Optional)(_univerjs_telemetry.ITelemetryService))
15961
+ ], SheetRenderController);
15962
+ function getLeftTopPlaceholderSize(skeleton) {
15963
+ return {
15964
+ width: skeleton.rowHeaderWidthAndMarginLeft ?? skeleton.rowHeaderWidth,
15965
+ height: skeleton.columnHeaderHeightAndMarginTop ?? skeleton.columnHeaderHeight
15966
+ };
15967
+ }
16083
15968
 
16084
15969
  //#endregion
16085
15970
  //#region src/services/status-bar.service.ts
@@ -17358,6 +17243,7 @@ function ToggleGridlinesMenuFactory(accessor) {
17358
17243
  type: _univerjs_ui.MenuItemType.BUTTON,
17359
17244
  tooltip: "sheets-ui.toolbar.toggleGridlines",
17360
17245
  icon: "HideGridlinesIcon",
17246
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
17361
17247
  activated$: new rxjs.Observable((observer) => {
17362
17248
  const getValue = () => {
17363
17249
  const workbook = instanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
@@ -18104,7 +17990,7 @@ function TextColorSelectorMenuItemFactory(accessor) {
18104
17990
  selectable: false
18105
17991
  },
18106
17992
  value$: new rxjs.Observable((subscriber) => {
18107
- const defaultValue = _univerjs_core.DEFAULT_STYLES.cl.rgb;
17993
+ const defaultValue = themeService.getColorFromTheme("gray.900");
18108
17994
  const { isAllValuesSame, value: currentValue } = selectionManagerService.getCellStylesProperty("cl");
18109
17995
  if (isAllValuesSame) subscriber.next((currentValue === null || currentValue === void 0 ? void 0 : currentValue.rgb) ?? defaultValue);
18110
17996
  else subscriber.next(defaultValue);
@@ -20180,7 +20066,7 @@ function getEmbedSheetsTabCustomData(snapshot) {
20180
20066
  function isEmbedSheetsTabCustomData(value) {
20181
20067
  if (!value || typeof value !== "object") return false;
20182
20068
  const candidate = value;
20183
- return candidate.version === 1 && typeof candidate.embedId === "string" && typeof candidate.hostAnchorId === "string";
20069
+ return candidate.version === 1 && typeof candidate.embedId === "string" && typeof candidate.hostAnchorId === "string" && (candidate.childType === void 0 || typeof candidate.childType === "number");
20184
20070
  }
20185
20071
 
20186
20072
  //#endregion
@@ -20189,10 +20075,6 @@ const ISheetEmbedRuntimeService = (0, _univerjs_core.createIdentifier)("sheet-ui
20189
20075
 
20190
20076
  //#endregion
20191
20077
  //#region src/views/auto-fill-popup-menu/AutoFillPopupMenu.tsx
20192
- const useUpdate = () => {
20193
- const [, setState] = (0, react.useState)({});
20194
- return (0, react.useCallback)(() => setState((prevState) => !prevState), []);
20195
- };
20196
20078
  function AutoFillPopupMenu() {
20197
20079
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
20198
20080
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
@@ -20222,7 +20104,8 @@ function AutoFillPopupMenu() {
20222
20104
  col: -1
20223
20105
  }, false, [autoFillService]);
20224
20106
  const selected = (0, _univerjs_ui.useObservable)(autoFillService.applyType$, _univerjs_sheets.AUTO_FILL_APPLY_TYPE.SERIES);
20225
- const [isHovered, setHovered] = (0, react.useState)(false);
20107
+ const [isHovered, setIsHovered] = (0, react.useState)(false);
20108
+ const [, forceUpdate] = (0, react.useReducer)((version) => version + 1, 0);
20226
20109
  const workbook = useActiveWorkbook();
20227
20110
  const sheetSkeletonManagerService = (0, react.useMemo)(() => {
20228
20111
  if (workbook) {
@@ -20232,14 +20115,13 @@ function AutoFillPopupMenu() {
20232
20115
  return null;
20233
20116
  }, [workbook, renderManagerService]);
20234
20117
  const handleMouseEnter = () => {
20235
- setHovered(true);
20118
+ setIsHovered(true);
20236
20119
  };
20237
20120
  const handleMouseLeave = () => {
20238
- setHovered(false);
20121
+ setIsHovered(false);
20239
20122
  };
20240
- const forceUpdate = useUpdate();
20241
20123
  (0, react.useEffect)(() => {
20242
- return commandService.onCommandExecuted((command, options) => {
20124
+ return commandService.onCommandExecuted((command) => {
20243
20125
  if (command.id === SetScrollOperation.id) forceUpdate();
20244
20126
  }).dispose;
20245
20127
  }, [forceUpdate, commandService]);
@@ -20284,7 +20166,11 @@ function AutoFillPopupMenu() {
20284
20166
  const showMore = visible || isHovered;
20285
20167
  const availableMenu = menu.filter((item) => !item.disable);
20286
20168
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
20287
- className: "univer-absolute univer-inset-0 univer-z-10 univer-size-0",
20169
+ className: "univer-absolute univer-z-10 univer-size-0",
20170
+ style: {
20171
+ left: 0,
20172
+ top: 0
20173
+ },
20288
20174
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
20289
20175
  className: "univer-absolute",
20290
20176
  style: {
@@ -20309,9 +20195,9 @@ function AutoFillPopupMenu() {
20309
20195
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
20310
20196
  className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800", _univerjs_design.borderClassName, {
20311
20197
  "univer-bg-gray-100 dark:!univer-bg-gray-800": visible,
20312
- "univer-bg-white dark:!univer-bg-gray-900": !visible
20198
+ "univer-bg-gray-0 dark:!univer-bg-gray-900": !visible
20313
20199
  }),
20314
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.AutofillDoubleIcon, { className: "univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white" }), showMore && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "dark:!univer-text-white" })]
20200
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.AutofillDoubleIcon, { className: "univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-gray-0" }), showMore && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "dark:!univer-text-gray-0" })]
20315
20201
  })
20316
20202
  })
20317
20203
  })
@@ -20458,7 +20344,7 @@ const EDITOR_DEFAULT_POSITION = {
20458
20344
  left: HIDDEN_EDITOR_POSITION
20459
20345
  };
20460
20346
  const CELL_EDITOR_DARK_SURFACE_THEME_COLOR = "gray.800";
20461
- const CELL_EDITOR_LIGHT_SURFACE_THEME_COLOR = "white";
20347
+ const CELL_EDITOR_LIGHT_SURFACE_THEME_COLOR = "gray.0";
20462
20348
  /**
20463
20349
  * @returns the host background color for the cell editor.
20464
20350
  */
@@ -20517,6 +20403,7 @@ function isEmbedRuntimeEditorOrPopup(target) {
20517
20403
  * @returns the rendered cell editor container.
20518
20404
  */
20519
20405
  function EditorContainer() {
20406
+ var _workbook$getSheetByS;
20520
20407
  const [state, setState] = (0, react.useState)({ ...EDITOR_DEFAULT_POSITION });
20521
20408
  const cellEditorManagerService = (0, _univerjs_ui.useDependency)(ICellEditorManagerService);
20522
20409
  const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
@@ -20535,9 +20422,12 @@ function EditorContainer() {
20535
20422
  const disableAutoFocus = (0, _univerjs_ui.useObservable)(() => contextService.subscribeContextValue$(_univerjs_ui.DISABLE_AUTO_FOCUS_KEY), false, void 0, [contextService, _univerjs_ui.DISABLE_AUTO_FOCUS_KEY]);
20536
20423
  const FormulaEditor = componentManager.get(EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY);
20537
20424
  const editState = (0, _univerjs_ui.useObservable)(editorBridgeService.currentEditCellState$);
20425
+ const workbook = editState ? instanceService.getUnit(editState.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET) ?? null : null;
20426
+ const activeSheet = useActiveWorksheet(workbook);
20538
20427
  const darkMode = (0, _univerjs_ui.useObservable)(themeService.darkMode$, themeService.darkMode);
20539
20428
  const [showEditCellAddress, setShowEditCellAddress] = (0, react.useState)(false);
20540
- const editCellAddress = editState ? `${(0, _univerjs_core.numberToABC)(editState.column)}${editState.row + 1}` : null;
20429
+ const editSheetName = editState ? workbook === null || workbook === void 0 || (_workbook$getSheetByS = workbook.getSheetBySheetId(editState.sheetId)) === null || _workbook$getSheetByS === void 0 ? void 0 : _workbook$getSheetByS.getName() : null;
20430
+ const editCellAddress = editState ? `${activeSheet && editSheetName && activeSheet.getSheetId() !== editState.sheetId ? `'${(0, _univerjs_engine_formula.quoteSheetName)(editSheetName)}'!` : ""}${(0, _univerjs_core.numberToABC)(editState.column)}${editState.row + 1}` : null;
20541
20431
  const editorBorderColor = genNormalSelectionStyle(themeService).stroke;
20542
20432
  const focusCoordinator = injector.has(ISheetEmbedRuntimeFocusCoordinator) ? injector.get(ISheetEmbedRuntimeFocusCoordinator) : void 0;
20543
20433
  const resolveRuntimeFocusState = () => {
@@ -20857,7 +20747,7 @@ function EditorContainer() {
20857
20747
  className: "univer-pointer-events-none univer-absolute univer-left-0 univer-top-0 univer-z-10 univer-whitespace-nowrap univer-rounded-t univer-px-1.5 univer-text-xs univer-leading-5",
20858
20748
  style: {
20859
20749
  backgroundColor: editorBorderColor,
20860
- color: themeService.getColorFromTheme("white"),
20750
+ color: themeService.getColorFromTheme("gray.0"),
20861
20751
  transform: "translateY(-100%)"
20862
20752
  },
20863
20753
  children: editCellAddress
@@ -21094,7 +20984,13 @@ function DefinedName({ disable }) {
21094
20984
  return () => {
21095
20985
  subscription.unsubscribe();
21096
20986
  };
21097
- }, []);
20987
+ }, [
20988
+ definedNamesService,
20989
+ lexerTreeBuilder,
20990
+ selectionManagerService,
20991
+ unitId,
20992
+ workbook
20993
+ ]);
21098
20994
  const handleDefinedNamesList = (0, _univerjs_core.debounce)((value) => {
21099
20995
  const hasMatch = definedNames.find((i) => i.name.toLowerCase().includes(value.toLowerCase()));
21100
20996
  if (hasMatch && !open) setOpen(true);
@@ -21196,7 +21092,7 @@ function DefinedName({ disable }) {
21196
21092
  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",
21197
21093
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
21198
21094
  ref: inputRef,
21199
- 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 }),
21095
+ className: (0, _univerjs_design.clsx)("univer-box-border univer-size-full univer-appearance-none univer-bg-transparent univer-pl-1.5 univer-pr-5 univer-text-gray-900 focus:univer-outline-none dark:!univer-border-r-gray-700 dark:!univer-text-gray-0", _univerjs_design.borderRightClassName, { "univer-cursor-not-allowed": disable }),
21200
21096
  type: "text",
21201
21097
  value: inputValue,
21202
21098
  onChange: handleChangeSelection,
@@ -21215,7 +21111,7 @@ function DefinedName({ disable }) {
21215
21111
  onOpenChange: setOpen,
21216
21112
  onOpenAutoFocus: (e) => e.preventDefault(),
21217
21113
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
21218
- 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 }),
21114
+ 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-gray-0 dark:hover:!univer-bg-gray-800", { "univer-cursor-not-allowed univer-text-gray-300 hover:univer-bg-transparent dark:!univer-text-gray-700": disable }),
21219
21115
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, {})
21220
21116
  })
21221
21117
  })]
@@ -21350,7 +21246,7 @@ function FormulaBar(props) {
21350
21246
  const workbookEditDisable = !((workbookEditablePermission === null || workbookEditablePermission === void 0 ? void 0 : workbookEditablePermission.value) ?? true);
21351
21247
  const editorActivationDisable = editDisable || workbookEditDisable;
21352
21248
  const disabled = editDisable || imageDisable;
21353
- const shouldSkipFocus = (0, react.useRef)(false);
21249
+ const shouldSkipFocusRef = (0, react.useRef)(false);
21354
21250
  const handlePointerDown = () => {
21355
21251
  try {
21356
21252
  contextService.setContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR, true);
@@ -21365,25 +21261,26 @@ function FormulaBar(props) {
21365
21261
  unitId: editState.unitId
21366
21262
  })) {
21367
21263
  contextService.setContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR, false);
21368
- shouldSkipFocus.current = true;
21264
+ shouldSkipFocusRef.current = true;
21369
21265
  }
21370
21266
  }
21371
21267
  } catch (e) {
21372
21268
  contextService.setContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR, false);
21373
- shouldSkipFocus.current = true;
21269
+ shouldSkipFocusRef.current = true;
21374
21270
  throw e;
21375
21271
  }
21376
21272
  };
21377
21273
  const handlePointerUp = () => {
21378
- if (shouldSkipFocus.current) setTimeout(() => {
21274
+ if (shouldSkipFocusRef.current) setTimeout(() => {
21379
21275
  editorService.blur(true);
21380
21276
  }, 30);
21381
- shouldSkipFocus.current = false;
21277
+ shouldSkipFocusRef.current = false;
21382
21278
  };
21383
21279
  const hideEditor = (0, _univerjs_sheets.isCellImage)(editState === null || editState === void 0 || (_editState$documentLa = editState.documentLayoutObject.documentModel) === null || _editState$documentLa === void 0 ? void 0 : _editState$documentLa.getSnapshot()) || viewDisable;
21384
21280
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
21281
+ dir: "ltr",
21385
21282
  "data-u-comp": "formula-bar",
21386
- className: (0, _univerjs_design.clsx)("univer-box-border univer-flex univer-bg-white univer-transition-[height] univer-ease-linear dark:!univer-bg-gray-800", _univerjs_design.borderBottomClassName, className, {
21283
+ className: (0, _univerjs_design.clsx)("univer-box-border univer-flex univer-bg-gray-0 univer-text-gray-900 univer-transition-[height] univer-ease-linear dark:!univer-bg-gray-800", _univerjs_design.borderBottomClassName, className, {
21387
21284
  "univer-h-7": arrowDirection === 0,
21388
21285
  "univer-h-20": arrowDirection === 1,
21389
21286
  "univer-pointer-events-none": editDisable
@@ -21401,17 +21298,17 @@ function FormulaBar(props) {
21401
21298
  className: (0, _univerjs_design.clsx)("univer-relative univer-box-border univer-flex univer-h-full univer-w-20 univer-items-center univer-justify-center univer-text-xs", _univerjs_design.borderRightClassName),
21402
21299
  children: [
21403
21300
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
21404
- className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-justify-center univer-rounded univer-p-1 univer-text-base dark:!univer-text-white", { "univer-cursor-pointer univer-text-red-600 hover:univer-bg-gray-100 dark:!univer-text-green-400 dark:hover:!univer-bg-gray-700": iconActivated }),
21301
+ className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-justify-center univer-rounded univer-p-1 univer-text-base dark:!univer-text-gray-0", { "univer-cursor-pointer univer-text-red-600 hover:univer-bg-gray-100 dark:!univer-text-green-400 dark:hover:!univer-bg-gray-700": iconActivated }),
21405
21302
  onClick: handleCloseBtnClick,
21406
21303
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CloseIcon, {})
21407
21304
  }),
21408
21305
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
21409
- className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-justify-center univer-rounded univer-p-1 univer-text-base dark:!univer-text-white", { "univer-cursor-pointer univer-text-green-600 hover:univer-bg-gray-100 dark:!univer-text-red-400 dark:hover:!univer-bg-gray-700": iconActivated }),
21306
+ className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-justify-center univer-rounded univer-p-1 univer-text-base dark:!univer-text-gray-0", { "univer-cursor-pointer univer-text-green-600 hover:univer-bg-gray-100 dark:!univer-text-red-400 dark:hover:!univer-bg-gray-700": iconActivated }),
21410
21307
  onClick: handleConfirmBtnClick,
21411
21308
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CheckMarkIcon, {})
21412
21309
  }),
21413
21310
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
21414
- className: "univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-p-1 univer-text-base hover:univer-bg-gray-100 dark:!univer-text-white dark:hover:!univer-bg-gray-700",
21311
+ className: "univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-p-1 univer-text-base hover:univer-bg-gray-100 dark:!univer-text-gray-0 dark:hover:!univer-bg-gray-700",
21415
21312
  onClick: handlerFxBtnClick,
21416
21313
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.FxIcon, {})
21417
21314
  })
@@ -21421,7 +21318,7 @@ function FormulaBar(props) {
21421
21318
  className: "univer-flex univer-w-full univer-flex-1 univer-overflow-hidden univer-pl-3",
21422
21319
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
21423
21320
  ref,
21424
- className: "univer-relative univer-flex-1 univer-bg-white dark:!univer-bg-gray-800",
21321
+ className: "univer-relative univer-flex-1 univer-bg-gray-0 dark:!univer-bg-gray-800",
21425
21322
  onPointerDown: handlePointerDown,
21426
21323
  onPointerUp: handlePointerUp,
21427
21324
  style: { pointerEvents: hideEditor ? "none" : "auto" },
@@ -21446,7 +21343,7 @@ function FormulaBar(props) {
21446
21343
  },
21447
21344
  autoScrollbar: false,
21448
21345
  disableContextMenu: false
21449
- }), hideEditor && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "univer-pointer-events-none univer-relative univer-left-0 univer-top-0 univer-z-[100] univer-size-full univer-cursor-not-allowed univer-bg-white dark:!univer-bg-gray-800" })]
21346
+ }), hideEditor && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "univer-pointer-events-none univer-relative univer-left-0 univer-top-0 univer-z-[100] univer-size-full univer-cursor-not-allowed univer-bg-gray-0 dark:!univer-bg-gray-800" })]
21450
21347
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
21451
21348
  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 }),
21452
21349
  onClick: handleArrowClick,
@@ -21587,7 +21484,7 @@ function SheetBarItem(props) {
21587
21484
  const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
21588
21485
  const getTextColor = (color) => {
21589
21486
  const darkTextColor = themeService.getColorFromTheme("gray.900");
21590
- const lightTextColor = themeService.getColorFromTheme("white");
21487
+ const lightTextColor = themeService.getColorFromTheme("gray.0");
21591
21488
  return new _univerjs_core.ColorKit(color).isDark() ? lightTextColor : darkTextColor;
21592
21489
  };
21593
21490
  const currentSelected = Boolean(selected);
@@ -21601,8 +21498,8 @@ function SheetBarItem(props) {
21601
21498
  onKeyDown,
21602
21499
  onClick,
21603
21500
  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", {
21604
- "dark:!univer-text-white": !color || color && !textColor,
21605
- "univer-justify-center univer-bg-white univer-font-bold univer-text-primary-700 univer-shadow": currentSelected,
21501
+ "dark:!univer-text-gray-0": !color || color && !textColor,
21502
+ "univer-justify-center univer-bg-gray-0 univer-font-bold univer-text-primary-700 univer-shadow": currentSelected,
21606
21503
  "dark:!univer-bg-gray-700": currentSelected && !color,
21607
21504
  "univer-font-medium univer-text-gray-900 hover:univer-bg-gray-100": !currentSelected,
21608
21505
  "dark:hover:!univer-bg-gray-700": !currentSelected && !color
@@ -22529,6 +22426,32 @@ const SCROLL_SHADOW_NONE = "";
22529
22426
  const SCROLL_SHADOW_LEFT = "inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2)";
22530
22427
  const SCROLL_SHADOW_RIGHT = "inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)";
22531
22428
  const SCROLL_SHADOW_BOTH = "inset 10px 0px 10px -10px rgba(0, 0, 0, 0.2), inset -10px 0px 10px -10px rgba(0, 0, 0, 0.2)";
22429
+ function EmbedSheetTabProductIcon({ childType }) {
22430
+ const className = "univer-size-4 univer-shrink-0";
22431
+ switch (childType) {
22432
+ case _univerjs_core.UniverInstanceType.UNIVER_SHEET: return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.SheetsMultiIcon, {
22433
+ "aria-hidden": true,
22434
+ className
22435
+ });
22436
+ case _univerjs_core.UniverInstanceType.UNIVER_DOC: return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DocsMultiIcon, {
22437
+ "aria-hidden": true,
22438
+ className
22439
+ });
22440
+ case _univerjs_core.UniverInstanceType.UNIVER_SLIDE: return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.SlidesMultiIcon, {
22441
+ "aria-hidden": true,
22442
+ className
22443
+ });
22444
+ case _univerjs_core.UniverInstanceType.UNIVER_BASE: return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.BasesMultiIcon, {
22445
+ "aria-hidden": true,
22446
+ className
22447
+ });
22448
+ case _univerjs_core.UniverInstanceType.UNIVER_BOARD: return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.BoardsMultiIcon, {
22449
+ "aria-hidden": true,
22450
+ className
22451
+ });
22452
+ default: return null;
22453
+ }
22454
+ }
22532
22455
  function getScrollShadow(state) {
22533
22456
  const { leftEnd, rightEnd } = state;
22534
22457
  if (leftEnd && rightEnd) return SCROLL_SHADOW_NONE;
@@ -22549,6 +22472,7 @@ function shouldRefreshSheetTabs(commandInfo) {
22549
22472
  }
22550
22473
  }
22551
22474
  function SheetBarTabs() {
22475
+ const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
22552
22476
  const [sheetList, setSheetList] = (0, react.useState)([]);
22553
22477
  const [activeSheetId, setActiveSheetId] = (0, react.useState)("");
22554
22478
  const [scrollShadow, setScrollShadow] = (0, react.useState)("");
@@ -22670,19 +22594,28 @@ function SheetBarTabs() {
22670
22594
  const updateSheetItems = (0, react.useCallback)(() => {
22671
22595
  const activeSheet = workbook.getActiveSheet();
22672
22596
  const currentSubUnitId = (activeSheet === null || activeSheet === void 0 ? void 0 : activeSheet.getSheetId()) ?? "";
22597
+ const embedRuntimeService = injector.has(ISheetEmbedRuntimeService) ? injector.get(ISheetEmbedRuntimeService) : void 0;
22673
22598
  const sheetListItems = workbook.getSheets().filter((sheet) => !sheet.isSheetHidden()).map((sheet, index) => {
22599
+ var _embedRuntimeService$;
22674
22600
  const worksheetRule = worksheetProtectionRuleModel.getRule(workbook.getUnitId(), sheet.getSheetId());
22675
22601
  const hasSelectionRule = rangeProtectionRuleModel.getSubunitRuleList(workbook.getUnitId(), sheet.getSheetId()).length > 0;
22676
22602
  const hasProtection = Boolean((worksheetRule === null || worksheetRule === void 0 ? void 0 : worksheetRule.permissionId) || hasSelectionRule);
22603
+ const embedData = getEmbedSheetsTabCustomData(sheet.getConfig());
22604
+ const embedChildType = (embedData === null || embedData === void 0 ? void 0 : embedData.childType) ?? (embedData ? embedRuntimeService === null || embedRuntimeService === void 0 || (_embedRuntimeService$ = embedRuntimeService.getSheetTabChildType) === null || _embedRuntimeService$ === void 0 ? void 0 : _embedRuntimeService$.call(embedRuntimeService, {
22605
+ hostUnitId: workbook.getUnitId(),
22606
+ hostAnchorId: embedData.hostAnchorId,
22607
+ embedId: embedData.embedId
22608
+ }) : void 0);
22677
22609
  return {
22678
22610
  sheetId: sheet.getSheetId(),
22679
- label: hasProtection ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.LockIcon, { className: "univer-shrink-0" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
22680
- className: "univer-truncate univer-outline-none",
22681
- children: sheet.getName()
22682
- })] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
22683
- className: "univer-truncate univer-outline-none",
22684
- children: sheet.getName()
22685
- }),
22611
+ label: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
22612
+ embedChildType != null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(EmbedSheetTabProductIcon, { childType: embedChildType }),
22613
+ hasProtection && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.LockIcon, { className: "univer-shrink-0" }),
22614
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
22615
+ className: "univer-truncate univer-outline-none",
22616
+ children: sheet.getName()
22617
+ })
22618
+ ] }),
22686
22619
  index,
22687
22620
  selected: activeSheet === sheet,
22688
22621
  color: sheet.getTabColor() ?? void 0
@@ -22691,6 +22624,7 @@ function SheetBarTabs() {
22691
22624
  setSheetList(sheetListItems);
22692
22625
  setActiveSheetId(currentSubUnitId);
22693
22626
  }, [
22627
+ injector,
22694
22628
  rangeProtectionRuleModel,
22695
22629
  workbook,
22696
22630
  worksheetProtectionRuleModel
@@ -23158,120 +23092,98 @@ const functionDisplayNames = {
23158
23092
  [_univerjs_engine_formula.FUNCTION_NAMES_STATISTICAL.COUNTA]: "sheets-ui.statusbar.countA",
23159
23093
  [_univerjs_engine_formula.FUNCTION_NAMES_TEXT.CONCATENATE]: "concatenate"
23160
23094
  };
23161
- const CopyableStatisticItem = (item) => {
23162
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
23163
- const messageService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IMessageService);
23164
- const clipboardService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IClipboardInterfaceService);
23165
- const formateValue = formatNumber(item);
23166
- const copyToClipboard = async () => {
23167
- await clipboardService.writeText(item.value.toString());
23168
- messageService.show({
23169
- type: _univerjs_design.MessageType.Success,
23170
- content: localeService.t("sheets-ui.statusbar.copied")
23171
- });
23172
- };
23173
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
23174
- title: localeService.t("sheets-ui.statusbar.clickToCopy"),
23175
- placement: "top",
23176
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23177
- className: "univer-flex univer-cursor-pointer univer-truncate univer-text-center univer-text-xs univer-text-gray-400",
23178
- onClick: copyToClipboard,
23179
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: `${localeService.t((functionDisplayNames === null || functionDisplayNames === void 0 ? void 0 : functionDisplayNames[item.name]) || item.name)}: ${formateValue}` })
23180
- }, item.name)
23181
- });
23182
- };
23183
23095
  function formatNumber(item) {
23184
23096
  const { pattern, value: num } = item;
23185
23097
  if (typeof num !== "number") return 0;
23186
- if (num >= 1e8) return num.toExponential(2);
23187
23098
  if (pattern && allowPatternFunctions.includes(item.name)) return _univerjs_core.numfmt.format(pattern, num, { throws: false });
23188
23099
  return num.toLocaleString();
23189
23100
  }
23190
23101
 
23191
23102
  //#endregion
23192
23103
  //#region src/views/status-bar/StatusBar.tsx
23193
- const SINGLE_MODE_WIDTH = 800;
23194
- const ROW_COUNT_THRESHOLD = 3;
23195
23104
  const StatusBar = () => {
23196
- const [isSingle, setIsSingle] = (0, react.useState)(window.innerWidth < SINGLE_MODE_WIDTH);
23105
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
23197
23106
  const statusBarService = (0, _univerjs_ui.useDependency)(IStatusBarService);
23198
- const items = statusBarService.getFunctions().map((item, index) => ({
23107
+ const [selectedFunction, setSelectedFunction] = (0, react.useState)(_univerjs_engine_formula.FUNCTION_NAMES_MATH.SUM);
23108
+ const [open, setOpen] = (0, react.useState)(false);
23109
+ const [statistics, setStatistics] = (0, react.useState)(() => statusBarService.getFunctions().map((item) => ({
23199
23110
  name: item.func,
23200
23111
  value: 0,
23201
23112
  show: true,
23202
- disable: false,
23113
+ disable: true,
23203
23114
  pattern: null
23204
- }));
23205
- const useStatistics = (initialItems, statusBarService, isSingle) => {
23206
- const [statistics, setStatistics] = (0, react.useState)(initialItems);
23207
- const [show, setShow] = (0, react.useState)(true);
23208
- const filteredStatistics = (0, react.useMemo)(() => statistics.filter((item) => item.show && !item.disable), [statistics]);
23209
- const firstItem = (0, react.useMemo)(() => filteredStatistics.find((item) => item.show && !item.disable), [filteredStatistics]);
23210
- const showList = (0, react.useMemo)(() => isSingle && firstItem ? [firstItem] : filteredStatistics, [
23211
- isSingle,
23212
- firstItem,
23213
- filteredStatistics
23214
- ]);
23215
- const updateStatistics = (0, react.useCallback)((state) => {
23216
- const items = state === null || state === void 0 ? void 0 : state.values;
23217
- if (!(items === null || items === void 0 ? void 0 : items.length)) {
23218
- setShow(false);
23219
- return;
23220
- }
23221
- setShow(true);
23222
- setStatistics((prevStats) => prevStats.map((stat) => {
23223
- var _items$find;
23115
+ })));
23116
+ (0, react.useEffect)(() => {
23117
+ const subscription = statusBarService.state$.subscribe((state) => {
23118
+ const values = (state === null || state === void 0 ? void 0 : state.values) ?? [];
23119
+ setStatistics((previousStatistics) => previousStatistics.map((statistic) => {
23120
+ const value = values.find((item) => item.func === statistic.name);
23224
23121
  return {
23225
- ...stat,
23226
- value: ((_items$find = items.find((i) => i.func === stat.name)) === null || _items$find === void 0 ? void 0 : _items$find.value) ?? stat.value,
23227
- disable: !items.some((i) => i.func === stat.name),
23122
+ ...statistic,
23123
+ value: (value === null || value === void 0 ? void 0 : value.value) ?? statistic.value,
23124
+ disable: !value,
23228
23125
  pattern: (state === null || state === void 0 ? void 0 : state.pattern) ?? null
23229
23126
  };
23230
23127
  }));
23231
- }, []);
23232
- (0, react.useEffect)(() => {
23233
- const subscription = statusBarService.state$.subscribe(updateStatistics);
23234
- return () => subscription.unsubscribe();
23235
- }, [statusBarService, updateStatistics]);
23236
- return {
23237
- statistics,
23238
- showList,
23239
- show
23240
- };
23128
+ });
23129
+ return () => subscription.unsubscribe();
23130
+ }, [statusBarService]);
23131
+ const availableStatistics = statistics.filter((item) => item.show && !item.disable);
23132
+ const selectedStatistic = availableStatistics.find((item) => item.name === selectedFunction) ?? availableStatistics.find((item) => item.name === _univerjs_engine_formula.FUNCTION_NAMES_MATH.SUM) ?? availableStatistics[0];
23133
+ if (!selectedStatistic) return null;
23134
+ const formatStatistic = (item) => {
23135
+ const localeKey = functionDisplayNames[item.name] || item.name;
23136
+ return `${localeService.t(localeKey)}: ${formatNumber(item)}`;
23241
23137
  };
23242
- const { showList, show } = useStatistics(items, statusBarService, isSingle);
23243
- const handleResize = (0, _univerjs_core.debounce)(() => {
23244
- const newSingleState = window.innerWidth < SINGLE_MODE_WIDTH;
23245
- if (isSingle !== newSingleState) setIsSingle(newSingleState);
23246
- }, 100);
23247
- (0, react.useEffect)(() => {
23248
- window.addEventListener("resize", handleResize);
23249
- return () => {
23250
- window.removeEventListener("resize", handleResize);
23251
- };
23252
- }, [isSingle]);
23253
- const getStatisticLayout = (showList, rowCountThreshold, CopyableStatisticItem) => {
23254
- if (showList.length > rowCountThreshold) return showList.reduce((acc, _, index) => {
23255
- if (index % 2 === 0) acc.push(showList.slice(index, index + 2));
23256
- return acc;
23257
- }, []).map((item, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
23258
- className: "univer-grid univer-h-full univer-items-center",
23259
- children: [item[0] && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopyableStatisticItem, { ...item[0] }, item[0].name), item[1] && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopyableStatisticItem, { ...item[1] }, item[1].name)]
23260
- }, `stat-col-${index}`));
23261
- return showList.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23262
- className: "univer-grid univer-h-full univer-items-center",
23263
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopyableStatisticItem, { ...item })
23264
- }, item.name));
23138
+ const handleSelect = (name) => {
23139
+ setSelectedFunction(name);
23140
+ setOpen(false);
23265
23141
  };
23266
- const renderContent = getStatisticLayout(showList, ROW_COUNT_THRESHOLD, CopyableStatisticItem);
23267
- return show && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23268
- className: (0, _univerjs_design.clsx)("univer-relative univer-box-border univer-flex univer-h-full univer-items-center univer-overflow-hidden univer-px-2 after:univer-absolute after:univer-right-0 after:univer-top-1/2 after:univer-block after:univer-h-4 after:univer-w-px after:-univer-translate-y-1/2 after:univer-bg-gray-200 after:univer-content-[\"\"]", {
23269
- "univer-max-w-32": isSingle,
23270
- "univer-max-w-fit": !isSingle
23271
- }),
23272
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23273
- className: "univer-flex univer-h-full univer-gap-x-2",
23274
- children: renderContent
23142
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23143
+ className: "univer-relative univer-box-border univer-flex univer-h-full univer-min-w-0 univer-max-w-64 univer-items-center univer-overflow-hidden univer-px-2 after:univer-absolute after:univer-right-0 after:univer-top-1/2 after:univer-block after:univer-h-4 after:univer-w-px after:-univer-translate-y-1/2 after:univer-bg-gray-200 after:univer-content-[\"\"]",
23144
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
23145
+ align: "end",
23146
+ side: "top",
23147
+ open,
23148
+ onOpenChange: setOpen,
23149
+ overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23150
+ "data-u-comp": "status-bar-statistic-menu",
23151
+ className: "univer-grid univer-w-max univer-max-w-[calc(100vw-16px)] univer-gap-0.5 univer-p-1.5",
23152
+ children: availableStatistics.map((item) => {
23153
+ const text = formatStatistic(item);
23154
+ const selected = item.name === selectedStatistic.name;
23155
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
23156
+ type: "button",
23157
+ className: (0, _univerjs_design.clsx)("univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded univer-border-none univer-bg-transparent univer-px-2 univer-py-1.5 univer-text-left univer-text-xs univer-text-gray-900 hover:univer-bg-gray-100 dark:!univer-text-gray-200 dark:hover:!univer-bg-gray-800", { "univer-bg-gray-100 dark:!univer-bg-gray-800": selected }),
23158
+ "aria-pressed": selected,
23159
+ onClick: () => handleSelect(item.name),
23160
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
23161
+ className: "univer-w-3 univer-shrink-0",
23162
+ children: selected && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CheckMarkIcon, {})
23163
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
23164
+ title: text,
23165
+ placement: "top",
23166
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
23167
+ className: "univer-min-w-0 univer-flex-1 univer-truncate",
23168
+ children: text
23169
+ })
23170
+ })]
23171
+ }, item.name);
23172
+ })
23173
+ }),
23174
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
23175
+ type: "button",
23176
+ "data-u-comp": "status-bar-statistic-picker",
23177
+ className: "univer-flex univer-min-w-0 univer-max-w-full univer-cursor-pointer univer-items-center univer-gap-1 univer-border-none univer-bg-transparent univer-p-0 univer-text-xs univer-text-gray-400",
23178
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
23179
+ title: formatStatistic(selectedStatistic),
23180
+ placement: "top",
23181
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
23182
+ className: "univer-min-w-0 univer-flex-1 univer-truncate",
23183
+ children: formatStatistic(selectedStatistic)
23184
+ })
23185
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "univer-shrink-0" })]
23186
+ })
23275
23187
  })
23276
23188
  });
23277
23189
  };
@@ -23283,68 +23195,49 @@ function RenderSheetFooter() {
23283
23195
  const config = (0, _univerjs_ui.useConfigValue)(SHEETS_UI_PLUGIN_CONFIG_KEY);
23284
23196
  const menuManagerService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IMenuManagerService);
23285
23197
  const showFooter = (config === null || config === void 0 ? void 0 : config.footer) ?? true;
23286
- const activeWorkbook = useActiveWorkbook();
23287
- const workbook = useSheetLoadingWorkbook() ?? activeWorkbook;
23288
- const isLoading = useSheetLoading();
23198
+ const workbook = useRootWorkbenchWorkbook();
23289
23199
  const activeWorkbookEmbeddedRender = useActiveWorkbookIsEmbeddedRender(workbook);
23290
- const focusedUnitType = useFocusedUnitType();
23200
+ const rootUnitType = useWorkbenchRootUnitType();
23291
23201
  const activeEmbedTab = useActiveSheetEmbedTabData(workbook);
23292
23202
  if (!workbook || !showFooter) return null;
23293
23203
  if (activeWorkbookEmbeddedRender) return null;
23294
- if (!activeEmbedTab && focusedUnitType != null && focusedUnitType !== _univerjs_core.UniverInstanceType.UNIVER_SHEET) return null;
23204
+ if (rootUnitType !== _univerjs_core.UniverInstanceType.UNIVER_SHEET) return null;
23295
23205
  const footerMenus = menuManagerService.getMenuByPositionKey(_univerjs_ui.ContextMenuPosition.FOOTER_MENU);
23296
23206
  const { sheetBar = true, statisticBar = true, menus = true, zoomSlider = true } = (config === null || config === void 0 ? void 0 : config.footer) || {};
23297
23207
  const showStatisticBar = activeEmbedTab ? false : statisticBar;
23298
23208
  const showMenus = activeEmbedTab ? false : menus;
23299
23209
  const showZoomSlider = activeEmbedTab ? false : zoomSlider;
23300
23210
  if (!sheetBar && !showStatisticBar && !showMenus && !showZoomSlider) return null;
23301
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetLoadingWorkbookContext.Provider, {
23302
- value: workbook,
23303
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
23304
- className: (0, _univerjs_design.clsx)("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", { "univer-pointer-events-none": isLoading }),
23305
- "data-range-selector": true,
23306
- "aria-disabled": isLoading,
23307
- style: { height: 36 },
23308
- children: [
23309
- sheetBar && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetBar, {}),
23310
- showStatisticBar && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StatusBar, {}),
23311
- showMenus && footerMenus.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23312
- className: "univer-box-border univer-flex univer-gap-2 univer-px-2",
23313
- children: footerMenus.map((item) => {
23314
- var _item$children;
23315
- 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));
23316
- })
23317
- }),
23318
- showZoomSlider && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetZoomSlider, {})
23319
- ]
23320
- })
23211
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
23212
+ 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-gray-0 univer-px-5 univer-text-gray-900 dark:!univer-bg-gray-900 dark:!univer-text-gray-200",
23213
+ "data-range-selector": true,
23214
+ style: { height: 36 },
23215
+ children: [
23216
+ sheetBar && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetBar, {}),
23217
+ showStatisticBar && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StatusBar, {}),
23218
+ showMenus && footerMenus.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23219
+ className: "univer-box-border univer-flex univer-gap-2 univer-px-2",
23220
+ children: footerMenus.map((item) => {
23221
+ var _item$children;
23222
+ 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));
23223
+ })
23224
+ }),
23225
+ showZoomSlider && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetZoomSlider, {})
23226
+ ]
23321
23227
  });
23322
23228
  }
23323
23229
  function RenderSheetHeader() {
23324
23230
  const config = (0, _univerjs_ui.useConfigValue)(SHEETS_UI_PLUGIN_CONFIG_KEY);
23325
- const activeWorkbook = useActiveWorkbook();
23326
- const workbook = useSheetLoadingWorkbook() ?? activeWorkbook;
23327
- const isLoading = useSheetLoading();
23231
+ const workbook = useRootWorkbenchWorkbook();
23328
23232
  const hasWorkbook = !!workbook;
23329
23233
  const activeWorkbookEmbeddedRender = useActiveWorkbookIsEmbeddedRender(workbook);
23330
- const focusedUnitType = useFocusedUnitType();
23234
+ const rootUnitType = useWorkbenchRootUnitType();
23331
23235
  const activeEmbedTab = useActiveSheetEmbedTabData(workbook);
23332
23236
  if (!hasWorkbook) return null;
23333
23237
  if (activeWorkbookEmbeddedRender) return null;
23334
23238
  if (activeEmbedTab) return null;
23335
- if (focusedUnitType != null && focusedUnitType !== _univerjs_core.UniverInstanceType.UNIVER_SHEET) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23336
- "aria-hidden": true,
23337
- className: "univer-h-7 univer-border-b univer-border-gray-200 univer-bg-white dark:!univer-border-gray-700 dark:!univer-bg-gray-900",
23338
- "data-u-comp": "formula-bar-placeholder"
23339
- });
23340
- if ((config === null || config === void 0 ? void 0 : config.formulaBar) !== false) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetLoadingWorkbookContext.Provider, {
23341
- value: workbook,
23342
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23343
- "aria-disabled": isLoading,
23344
- className: (0, _univerjs_design.clsx)({ "univer-pointer-events-none": isLoading }),
23345
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormulaBar, {})
23346
- })
23347
- });
23239
+ if (rootUnitType !== _univerjs_core.UniverInstanceType.UNIVER_SHEET) return null;
23240
+ if ((config === null || config === void 0 ? void 0 : config.formulaBar) !== false) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormulaBar, {});
23348
23241
  return null;
23349
23242
  }
23350
23243
  /**
@@ -23352,18 +23245,16 @@ function RenderSheetHeader() {
23352
23245
  */
23353
23246
  function RenderSheetContent() {
23354
23247
  const config = (0, _univerjs_ui.useConfigValue)(SHEETS_UI_PLUGIN_CONFIG_KEY);
23355
- const isLoading = useSheetLoading();
23356
- const isPreviewReady = useSheetLoadingPreviewReady();
23357
23248
  const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
23358
- const activeWorkbook = useActiveWorkbook();
23359
- const workbook = useSheetLoadingWorkbook() ?? activeWorkbook;
23249
+ const workbook = useRootWorkbenchWorkbook();
23360
23250
  const activeEmbedTab = useActiveSheetEmbedTabData(workbook);
23361
23251
  const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
23362
23252
  const activeWorkbookEmbeddedRender = useActiveWorkbookIsEmbeddedRender(workbook);
23253
+ const rootWorkbenchOwnsSheet = useWorkbenchRootUnitType() === _univerjs_core.UniverInstanceType.UNIVER_SHEET;
23363
23254
  const ShapeTextEditorContainer = componentManager.get("SheetShapeTextEditorContainer") ?? componentManager.get("ShapeTextEditorContainer");
23364
23255
  (0, react.useEffect)(() => {
23365
23256
  var _tryGetSheetEmbedRunt;
23366
- if (!workbook || isLoading || activeEmbedTab || activeWorkbookEmbeddedRender) return;
23257
+ if (!workbook || activeEmbedTab || activeWorkbookEmbeddedRender || !rootWorkbenchOwnsSheet) return;
23367
23258
  const instanceService = injector.get(_univerjs_core.IUniverInstanceService);
23368
23259
  instanceService.setCurrentUnitForType(workbook.getUnitId());
23369
23260
  instanceService.focusUnit(workbook.getUnitId());
@@ -23372,11 +23263,11 @@ function RenderSheetContent() {
23372
23263
  activeEmbedTab,
23373
23264
  activeWorkbookEmbeddedRender,
23374
23265
  injector,
23375
- isLoading,
23266
+ rootWorkbenchOwnsSheet,
23376
23267
  workbook
23377
23268
  ]);
23378
23269
  if (!workbook) return null;
23379
- if (isLoading) return isPreviewReady ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetLoadingSkeleton, {});
23270
+ if (!rootWorkbenchOwnsSheet) return null;
23380
23271
  if (activeWorkbookEmbeddedRender) return null;
23381
23272
  if (activeEmbedTab && workbook) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RenderSheetEmbedTabHost, {
23382
23273
  workbook,
@@ -23388,42 +23279,6 @@ function RenderSheetContent() {
23388
23279
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoFillPopupMenu, {})
23389
23280
  ] });
23390
23281
  }
23391
- function SheetLoadingSkeleton() {
23392
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
23393
- "data-u-comp": "sheet-loading-skeleton",
23394
- "aria-busy": true,
23395
- className: "univer-absolute univer-inset-0 univer-z-10 univer-overflow-hidden univer-bg-white dark:!univer-bg-gray-900",
23396
- children: [
23397
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23398
- className: "univer-absolute univer-right-0 univer-top-0 univer-border-b univer-border-gray-200 univer-bg-gray-50 dark:!univer-border-gray-700 dark:!univer-bg-gray-800",
23399
- style: {
23400
- left: _univerjs_core.DEFAULT_WORKSHEET_ROW_TITLE_WIDTH,
23401
- height: _univerjs_core.DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT
23402
- }
23403
- }),
23404
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23405
- className: "univer-absolute univer-bottom-0 univer-left-0 univer-border-r univer-border-gray-200 univer-bg-gray-50 dark:!univer-border-gray-700 dark:!univer-bg-gray-800",
23406
- style: {
23407
- top: _univerjs_core.DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT,
23408
- width: _univerjs_core.DEFAULT_WORKSHEET_ROW_TITLE_WIDTH
23409
- }
23410
- }),
23411
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23412
- className: "univer-absolute univer-bottom-0 univer-right-0 univer-animate-pulse univer-text-gray-200 dark:!univer-text-gray-700",
23413
- style: {
23414
- top: _univerjs_core.DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT,
23415
- left: _univerjs_core.DEFAULT_WORKSHEET_ROW_TITLE_WIDTH,
23416
- backgroundImage: "linear-gradient(to right, currentColor 1px, transparent 1px), linear-gradient(to bottom, currentColor 1px, transparent 1px)",
23417
- backgroundSize: `${_univerjs_core.DEFAULT_WORKSHEET_COLUMN_WIDTH}px ${_univerjs_core.DEFAULT_WORKSHEET_ROW_HEIGHT}px`
23418
- }
23419
- }),
23420
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.LoadingMultiIcon, {
23421
- "aria-hidden": true,
23422
- className: "univer-absolute univer-left-1/2 univer-top-1/2 univer-size-6 -univer-translate-x-1/2 -univer-translate-y-1/2 univer-animate-spin univer-text-violet-500"
23423
- })
23424
- ]
23425
- });
23426
- }
23427
23282
  function RenderSheetEmbedTabHost(props) {
23428
23283
  const { workbook, worksheet } = props;
23429
23284
  const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
@@ -23455,26 +23310,45 @@ function RenderSheetEmbedTabHost(props) {
23455
23310
  ]);
23456
23311
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
23457
23312
  "data-embed-sheets-sheet-tab-host": hostAnchorId,
23458
- className: "univer-absolute univer-inset-0 univer-z-40 univer-bg-white dark:!univer-bg-gray-900"
23313
+ className: "univer-absolute univer-inset-0 univer-z-40 univer-bg-gray-0 dark:!univer-bg-gray-900"
23459
23314
  });
23460
23315
  }
23461
23316
  function useActiveWorkbookIsEmbeddedRender(workbook) {
23462
23317
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
23318
+ const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
23319
+ const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
23320
+ const runtimeFocusCoordinator = injector.has(ISheetEmbedRuntimeFocusCoordinator) ? injector.get(ISheetEmbedRuntimeFocusCoordinator) : void 0;
23463
23321
  return (0, react.useMemo)(() => {
23464
- var _univerInstanceServic;
23322
+ var _renderManagerService, _univerInstanceServic;
23465
23323
  if (!workbook) return false;
23466
- return ((_univerInstanceServic = univerInstanceService.getUnitCreateOptions(workbook.getUnitId())) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.embeddedRender) === true;
23467
- }, [univerInstanceService, workbook]);
23324
+ return (runtimeFocusCoordinator === null || runtimeFocusCoordinator === void 0 ? void 0 : runtimeFocusCoordinator.resolveRuntimeScopeByChildUnitId(workbook.getUnitId())) != null || ((_renderManagerService = renderManagerService.getRenderUnitById(workbook.getUnitId())) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.isMainScene) === false || ((_univerInstanceServic = univerInstanceService.getUnitCreateOptions(workbook.getUnitId())) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.embeddedRender) === true;
23325
+ }, [
23326
+ (0, _univerjs_ui.useObservable)(() => (0, rxjs.merge)(renderManagerService.created$, renderManagerService.disposed$, (runtimeFocusCoordinator === null || runtimeFocusCoordinator === void 0 ? void 0 : runtimeFocusCoordinator.runtimeSessionChanged$) ?? rxjs.EMPTY), null, false, [renderManagerService, runtimeFocusCoordinator]),
23327
+ renderManagerService,
23328
+ runtimeFocusCoordinator,
23329
+ univerInstanceService,
23330
+ workbook
23331
+ ]);
23468
23332
  }
23469
- function useFocusedUnitType() {
23470
- const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
23471
- const focusedUnitId = (0, _univerjs_ui.useObservable)(() => univerInstanceService.focused$, null, false, [univerInstanceService]);
23333
+ function useRootWorkbenchWorkbook() {
23334
+ const activeWorkbook = useActiveWorkbook();
23335
+ const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
23336
+ const instanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
23337
+ const runtimeFocusCoordinator = injector.has(ISheetEmbedRuntimeFocusCoordinator) ? injector.get(ISheetEmbedRuntimeFocusCoordinator) : void 0;
23472
23338
  return (0, react.useMemo)(() => {
23473
- if (!focusedUnitId) return null;
23474
- if ((0, _univerjs_core.isInternalEditorID)(focusedUnitId) && univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)) return _univerjs_core.UniverInstanceType.UNIVER_SHEET;
23475
- const focusedUnit = univerInstanceService.getUnit(focusedUnitId);
23476
- return (focusedUnit === null || focusedUnit === void 0 ? void 0 : focusedUnit.type) ?? null;
23477
- }, [focusedUnitId, univerInstanceService]);
23339
+ if (!activeWorkbook || !runtimeFocusCoordinator) return activeWorkbook;
23340
+ const runtimeScope = runtimeFocusCoordinator.resolveRuntimeScopeByChildUnitId(activeWorkbook.getUnitId());
23341
+ if (!(runtimeScope === null || runtimeScope === void 0 ? void 0 : runtimeScope.hostUnitId)) return activeWorkbook;
23342
+ return instanceService.getUnit(runtimeScope.hostUnitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET) ?? activeWorkbook;
23343
+ }, [
23344
+ activeWorkbook,
23345
+ instanceService,
23346
+ runtimeFocusCoordinator,
23347
+ (0, _univerjs_ui.useObservable)(() => (runtimeFocusCoordinator === null || runtimeFocusCoordinator === void 0 ? void 0 : runtimeFocusCoordinator.runtimeSessionChanged$) ?? rxjs.EMPTY, null, false, [runtimeFocusCoordinator])
23348
+ ]);
23349
+ }
23350
+ function useWorkbenchRootUnitType() {
23351
+ return (0, _univerjs_ui.useObservable)((0, _univerjs_ui.useDependency)(_univerjs_ui.IWorkbenchService).rootUnitType$, null, true);
23478
23352
  }
23479
23353
  function useActiveSheetEmbedTabData(workbook) {
23480
23354
  const worksheet = useActiveWorksheet(workbook);
@@ -24099,7 +23973,7 @@ const useHighlightRange = (ranges = []) => {
24099
23973
  //#endregion
24100
23974
  //#region package.json
24101
23975
  var name = "@univerjs/sheets-ui";
24102
- var version = "1.0.0-beta.0";
23976
+ var version = "1.0.0-beta.2";
24103
23977
 
24104
23978
  //#endregion
24105
23979
  //#region src/views/cell-popup/config.ts
@@ -24269,6 +24143,8 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
24269
24143
  disposable.add(this._commandService.onCommandExecuted((commandInfo) => {
24270
24144
  if (shouldUpdatePosition(commandInfo.id)) position$.next(calc());
24271
24145
  }));
24146
+ const viewMain = currentRender.scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN);
24147
+ if (viewMain) disposable.add(viewMain.onScrollAfter$.subscribeEvent(() => position$.next(calc())));
24272
24148
  return {
24273
24149
  position,
24274
24150
  position$,
@@ -24315,6 +24191,10 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
24315
24191
  };
24316
24192
  const { position, position$, disposable } = this._createPositionObserver(bound, currentRender, skeleton, worksheet);
24317
24193
  const popupInjector = this._resolveEmbeddedPopupInjector(unitId, currentRender);
24194
+ const canvasElement = currentRender.engine.getCanvasElement();
24195
+ const scaleAdjust = canvasElement.getBoundingClientRect().width / pxToNum(canvasElement.style.width);
24196
+ const { scaleX, scaleY } = currentRender.scene.getAncestorScale();
24197
+ const viewMain = currentRender.scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN);
24318
24198
  const id = this._globalPopupManagerService.addPopup({
24319
24199
  ...popup,
24320
24200
  unitId,
@@ -24322,7 +24202,11 @@ let SheetCanvasPopManagerService = class SheetCanvasPopManagerService extends _u
24322
24202
  connectorInjector: popupInjector,
24323
24203
  anchorRect: position,
24324
24204
  anchorRect$: position$,
24325
- canvasElement: currentRender.engine.getCanvasElement()
24205
+ canvasElement,
24206
+ boundaryInsets: popup.constrainToCanvas ? {
24207
+ left: ((viewMain === null || viewMain === void 0 ? void 0 : viewMain.left) ?? skeleton.rowHeaderWidth * scaleX) * scaleAdjust,
24208
+ top: ((viewMain === null || viewMain === void 0 ? void 0 : viewMain.top) ?? skeleton.columnHeaderHeight * scaleY) * scaleAdjust
24209
+ } : popup.boundaryInsets
24326
24210
  });
24327
24211
  const disposableCollection = new _univerjs_core.DisposableCollection();
24328
24212
  disposableCollection.add(disposable);
@@ -24735,6 +24619,11 @@ function shouldUpdatePosition(commandId) {
24735
24619
 
24736
24620
  //#endregion
24737
24621
  //#region src/services/cell-popup-manager.service.ts
24622
+ const CELL_POPUP_DIRECTIONS = [
24623
+ "horizontal",
24624
+ "vertical",
24625
+ "left-center"
24626
+ ];
24738
24627
  let CellPopupManagerService = class CellPopupManagerService extends _univerjs_core.Disposable {
24739
24628
  constructor(_sheetCanvasPopManagerService) {
24740
24629
  super();
@@ -24790,7 +24679,7 @@ let CellPopupManagerService = class CellPopupManagerService extends _univerjs_co
24790
24679
  direction
24791
24680
  },
24792
24681
  noPushMinimumGap: true,
24793
- autoRelayout: false,
24682
+ autoRelayout: popup.autoRelayout ?? false,
24794
24683
  zIndex: 90
24795
24684
  }, unitId, subUnitId);
24796
24685
  subUnitMap.setValue(row, col, {
@@ -24818,31 +24707,21 @@ let CellPopupManagerService = class CellPopupManagerService extends _univerjs_co
24818
24707
  const subUnitMap = this._ensureCellPopupMap(unitId, subUnitId);
24819
24708
  const cache = subUnitMap.getValue(row, col);
24820
24709
  if (!cache) return;
24821
- if (cache.horizontal) {
24822
- var _cache$horizontal$dis;
24823
- (_cache$horizontal$dis = cache.horizontal.disposable) === null || _cache$horizontal$dis === void 0 || _cache$horizontal$dis.dispose();
24824
- cache.horizontal = void 0;
24825
- this._change$.next({
24826
- unitId,
24827
- subUnitId,
24828
- row,
24829
- col,
24830
- direction: "horizontal"
24831
- });
24832
- }
24833
- if (cache.vertical) {
24834
- var _cache$vertical$dispo;
24835
- (_cache$vertical$dispo = cache.vertical.disposable) === null || _cache$vertical$dispo === void 0 || _cache$vertical$dispo.dispose();
24836
- cache.vertical = void 0;
24710
+ CELL_POPUP_DIRECTIONS.forEach((direction) => {
24711
+ var _directionCache$dispo2;
24712
+ const directionCache = cache[direction];
24713
+ if (!directionCache) return;
24714
+ (_directionCache$dispo2 = directionCache.disposable) === null || _directionCache$dispo2 === void 0 || _directionCache$dispo2.dispose();
24715
+ cache[direction] = void 0;
24837
24716
  this._change$.next({
24838
24717
  unitId,
24839
24718
  subUnitId,
24840
24719
  row,
24841
24720
  col,
24842
- direction: "vertical"
24721
+ direction
24843
24722
  });
24844
- }
24845
- if (!cache.horizontal && !cache.vertical) subUnitMap.realDeleteValue(row, col);
24723
+ });
24724
+ if (CELL_POPUP_DIRECTIONS.every((direction) => !cache[direction])) subUnitMap.realDeleteValue(row, col);
24846
24725
  }
24847
24726
  hidePopupsForUnit(unitId, subUnitId) {
24848
24727
  const unitMap = this._cellPopupMap.get(unitId);
@@ -25561,12 +25440,12 @@ function BorderPanel(props) {
25561
25440
  })
25562
25441
  }),
25563
25442
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
25564
- className: "univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded univer-border-none univer-bg-transparent univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",
25443
+ className: "univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded univer-border-none univer-bg-transparent univer-p-1 univer-text-gray-900 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",
25565
25444
  type: "button",
25566
25445
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.PaintBucketDoubleIcon, {
25567
- className: "univer-fill-primary-600 dark:!univer-text-white",
25446
+ className: "univer-fill-primary-600 dark:!univer-text-gray-0",
25568
25447
  extend: { colorChannel1: (value === null || value === void 0 ? void 0 : value.color) ?? "" }
25569
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "dark:!univer-text-white" })]
25448
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "dark:!univer-text-gray-0" })]
25570
25449
  })
25571
25450
  }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
25572
25451
  overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
@@ -25577,19 +25456,19 @@ function BorderPanel(props) {
25577
25456
  className: "univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-px-1 univer-py-3 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",
25578
25457
  onClick: () => handleClick(item.value, "style"),
25579
25458
  children: [item.value === type && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CheckMarkIcon, { className: "univer-absolute univer-left-3 univer-text-primary-600" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BorderLine, {
25580
- className: "univer-ml-6 univer-fill-gray-900 dark:!univer-fill-white",
25459
+ className: "univer-ml-6 univer-fill-gray-900 dark:!univer-fill-gray-0",
25581
25460
  type: item.value
25582
25461
  })]
25583
25462
  }, item.value))
25584
25463
  })
25585
25464
  }),
25586
25465
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
25587
- className: "univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded univer-border-none univer-bg-transparent univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",
25466
+ className: "univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded univer-border-none univer-bg-transparent univer-p-1 univer-text-gray-900 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",
25588
25467
  type: "button",
25589
25468
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(BorderLine, {
25590
- className: "univer-fill-gray-900 dark:!univer-fill-white",
25469
+ className: "univer-fill-gray-900 dark:!univer-fill-gray-0",
25591
25470
  type: type ?? _univerjs_core.BorderStyleTypes.THIN
25592
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "dark:!univer-text-white" })]
25471
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "dark:!univer-text-gray-0" })]
25593
25472
  })
25594
25473
  }) })]
25595
25474
  })
@@ -25621,6 +25500,7 @@ let CellAlertManagerService = class CellAlertManagerService extends _univerjs_co
25621
25500
  });
25622
25501
  }
25623
25502
  showAlert(alert) {
25503
+ var _alert$menu, _alert$menu2, _alert$menu3;
25624
25504
  let lastPopup = this._currentAlert.get(alert.key);
25625
25505
  if (lastPopup) lastPopup.dispose.dispose();
25626
25506
  if (lastPopup) lastPopup.dispose.dispose();
@@ -25641,7 +25521,9 @@ let CellAlertManagerService = class CellAlertManagerService extends _univerjs_co
25641
25521
  col
25642
25522
  }, {
25643
25523
  componentKey: CELL_ALERT_KEY,
25644
- direction: "horizontal",
25524
+ direction: ((_alert$menu = alert.menu) === null || _alert$menu === void 0 ? void 0 : _alert$menu.length) ? "left-center" : "horizontal",
25525
+ autoRelayout: Boolean((_alert$menu2 = alert.menu) === null || _alert$menu2 === void 0 ? void 0 : _alert$menu2.length),
25526
+ showOnSelectionMoving: Boolean((_alert$menu3 = alert.menu) === null || _alert$menu3 === void 0 ? void 0 : _alert$menu3.length),
25645
25527
  extraProps: { alert },
25646
25528
  priority: 1
25647
25529
  });
@@ -25681,18 +25563,53 @@ CellAlertManagerService = __decorate([__decorateParam(0, _univerjs_engine_render
25681
25563
  */
25682
25564
  function CellAlert({ popup }) {
25683
25565
  var _popup$extraProps;
25566
+ const [visible, setVisible] = (0, react.useState)(false);
25567
+ const [isHovered, setIsHovered] = (0, react.useState)(false);
25684
25568
  const alert = (_popup$extraProps = popup.extraProps) === null || _popup$extraProps === void 0 ? void 0 : _popup$extraProps.alert;
25685
25569
  if (!alert) return null;
25686
- const { type, title, message } = alert;
25570
+ const { type, title, message, menu } = alert;
25571
+ if (menu === null || menu === void 0 ? void 0 : menu.length) {
25572
+ const accessibleLabel = [title, message].filter((value) => typeof value === "string").join(": ");
25573
+ const showMore = visible || isHovered;
25574
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
25575
+ onMouseEnter: () => setIsHovered(true),
25576
+ onMouseLeave: () => setIsHovered(false),
25577
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DropdownMenu, {
25578
+ align: "start",
25579
+ open: visible,
25580
+ onOpenChange: setVisible,
25581
+ items: [
25582
+ {
25583
+ type: "custom",
25584
+ className: "univer-px-2 univer-py-1.5 univer-font-medium univer-text-gray-900 dark:!univer-text-gray-0",
25585
+ children: message
25586
+ },
25587
+ { type: "separator" },
25588
+ ...menu.map((item) => ({
25589
+ type: "item",
25590
+ children: item.label,
25591
+ disabled: item.disabled,
25592
+ onSelect: item.onSelect
25593
+ }))
25594
+ ],
25595
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
25596
+ type: "button",
25597
+ "aria-label": accessibleLabel || void 0,
25598
+ className: "univer-flex univer-items-center univer-gap-1 univer-rounded univer-border univer-border-solid univer-border-gray-200 univer-bg-gray-0 univer-p-1 univer-shadow hover:univer-bg-gray-100 dark:!univer-border-gray-600 dark:!univer-bg-gray-900 dark:hover:!univer-bg-gray-800",
25599
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.WarningIcon, { className: "univer-text-yellow-500" }), showMore && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "univer-text-gray-600 dark:!univer-text-gray-300" })]
25600
+ })
25601
+ })
25602
+ });
25603
+ }
25687
25604
  const iconMap = {
25688
- [2]: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.ErrorIcon, { className: "univer-mr-1.5 univer-text-red-500" }),
25689
- [0]: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.InfoIcon, { className: "univer-mr-1.5 univer-text-blue-500" }),
25690
- [1]: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.WarningIcon, { className: "univer-mr-1.5 univer-text-yellow-500" })
25605
+ [2]: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.ErrorIcon, { className: "univer-text-red-500" }),
25606
+ [0]: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.InfoIcon, { className: "univer-text-blue-500" }),
25607
+ [1]: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.WarningIcon, { className: "univer-text-yellow-500" })
25691
25608
  };
25692
25609
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
25693
- className: "univer-z-[100] univer-box-border univer-w-[156px] univer-rounded-lg univer-bg-white univer-px-2 univer-py-1 univer-text-gray-900 univer-shadow dark:!univer-bg-black dark:!univer-text-white",
25610
+ className: "univer-z-[100] univer-box-border univer-w-[156px] univer-rounded-lg univer-bg-gray-0 univer-px-2 univer-py-1 univer-text-gray-900 univer-shadow dark:!univer-bg-gray-1000 dark:!univer-text-gray-0",
25694
25611
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
25695
- className: "univer-mb-1.5 univer-flex univer-h-5 univer-flex-row univer-items-center univer-text-sm univer-font-medium",
25612
+ className: "univer-mb-1.5 univer-flex univer-h-5 univer-flex-row univer-items-center univer-gap-x-1.5 univer-text-sm univer-font-medium",
25696
25613
  children: [type ? iconMap[type] : null, title]
25697
25614
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
25698
25615
  className: "univer-text-sm",
@@ -25722,7 +25639,10 @@ const CellPopup = (props) => {
25722
25639
  const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
25723
25640
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
25724
25641
  "data-u-comp": "sheets-ui-cell-popup",
25725
- className: "univer-ml-px univer-flex univer-flex-col",
25642
+ className: `
25643
+ ${direction === "left-center" ? "univer-mr-px" : "univer-ml-px"}
25644
+ univer-flex univer-flex-col
25645
+ `,
25726
25646
  children: popups.map((popup) => {
25727
25647
  const Component = componentManager.get(popup.componentKey);
25728
25648
  return Component ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, { popup }, popup.id ?? popup.componentKey) : null;
@@ -25864,7 +25784,7 @@ function DefinedNameInputContent(props) {
25864
25784
  className: "univer-relative univer-h-8 univer-select-none",
25865
25785
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormulaEditor, {
25866
25786
  ref: formulaEditorRef,
25867
- className: (0, _univerjs_design.clsx)("univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent", _univerjs_design.borderClassName),
25787
+ className: (0, _univerjs_design.clsx)("univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-gray-0 univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-gray-0 [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent", _univerjs_design.borderClassName),
25868
25788
  initValue: formulaOrRefStringValue,
25869
25789
  unitId,
25870
25790
  subUnitId,
@@ -26100,7 +26020,7 @@ const DefinedNameContainer = () => {
26100
26020
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
26101
26021
  title: definedName.comment,
26102
26022
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
26103
- className: "univer-my-1 univer-max-h-[100px] univer-max-w-[190px] univer-truncate univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-white",
26023
+ className: "univer-my-1 univer-max-h-[100px] univer-max-w-[190px] univer-truncate univer-text-sm univer-font-medium univer-text-gray-900 dark:!univer-text-gray-0",
26104
26024
  children: [definedName.name, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
26105
26025
  className: "univer-text-xxs univer-ml-1 univer-text-gray-400",
26106
26026
  children: definedName.localSheetId === _univerjs_sheets.SCOPE_WORKBOOK_VALUE_DEFINED_NAME || definedName.localSheetId == null ? "" : getSheetNameBySheetId(definedName.localSheetId)
@@ -26207,7 +26127,7 @@ function DateDropdown(props) {
26207
26127
  if (await (onChange === null || onChange === void 0 ? void 0 : onChange(date))) hideFn();
26208
26128
  };
26209
26129
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
26210
- className: "univer-rounded univer-bg-white univer-p-2 univer-shadow-lg dark:!univer-bg-black",
26130
+ className: "univer-rounded univer-bg-gray-0 univer-p-2 univer-shadow-lg dark:!univer-bg-gray-1000",
26211
26131
  children: [patternType === "time" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.TimeInput, {
26212
26132
  value: date.toDate(),
26213
26133
  onValueChange: (newValue) => {
@@ -26260,6 +26180,8 @@ function getListDropdownValue(value, multiple) {
26260
26180
  function SelectList(props) {
26261
26181
  const { value, onChange, multiple, options, onEdit, style, location, showEdit: showEditOnDropdown, showSearch: showSearchOnDropdown } = props;
26262
26182
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
26183
+ const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
26184
+ (0, _univerjs_ui.useObservable)(themeService.currentTheme$);
26263
26185
  const { row, col, unitId, subUnitId } = location;
26264
26186
  const searchRef = (0, react.useRef)(null);
26265
26187
  (0, react.useEffect)(() => {
@@ -26298,14 +26220,14 @@ function SelectList(props) {
26298
26220
  ]);
26299
26221
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
26300
26222
  "data-u-comp": "sheets-dropdown-list",
26301
- className: (0, _univerjs_design.clsx)("univer-box-border univer-rounded-lg univer-bg-white univer-py-1 univer-text-gray-900 univer-shadow dark:!univer-bg-black dark:!univer-text-white", _univerjs_design.borderClassName),
26223
+ className: (0, _univerjs_design.clsx)("univer-box-border univer-rounded-lg univer-bg-gray-0 univer-py-1 univer-text-gray-900 univer-shadow dark:!univer-bg-gray-1000 dark:!univer-text-gray-0", _univerjs_design.borderClassName),
26302
26224
  style,
26303
26225
  children: [
26304
26226
  showSearchOnDropdown && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
26305
26227
  className: "univer-box-border univer-flex univer-w-full univer-px-2",
26306
26228
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
26307
26229
  ref: searchRef,
26308
- className: (0, _univerjs_design.clsx)("univer-w-full univer-rounded-md univer-px-2 univer-py-1 univer-text-sm focus:univer-border-primary-500 focus:univer-outline-none dark:!univer-bg-black dark:!univer-text-white", _univerjs_design.borderClassName),
26230
+ className: (0, _univerjs_design.clsx)("univer-w-full univer-rounded-md univer-bg-gray-0 univer-px-2 univer-py-1 univer-text-sm univer-text-gray-900 focus:univer-border-primary-500 focus:univer-outline-none dark:!univer-bg-gray-1000 dark:!univer-text-gray-0", _univerjs_design.borderClassName),
26309
26231
  type: "text",
26310
26232
  value: lowerFilter,
26311
26233
  autoFocus: true,
@@ -26319,6 +26241,7 @@ function SelectList(props) {
26319
26241
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
26320
26242
  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),
26321
26243
  children: filteredOptions.map((item, i) => {
26244
+ var _item$color;
26322
26245
  const selected = value.indexOf(item.value) > -1;
26323
26246
  const handleClick = () => {
26324
26247
  let set;
@@ -26331,16 +26254,18 @@ function SelectList(props) {
26331
26254
  onChange(newValue);
26332
26255
  };
26333
26256
  const index = item.label.toLocaleLowerCase().indexOf(lowerFilter);
26334
- const isDark = new _univerjs_core.ColorKit(item.color).isDark();
26257
+ const isThemeColor = Boolean(((_item$color = item.color) === null || _item$color === void 0 ? void 0 : _item$color.includes(".")) && themeService.isValidThemeColor(item.color));
26258
+ const backgroundColor = isThemeColor ? themeService.getColorFromTheme(item.color) : item.color;
26259
+ const isDark = new _univerjs_core.ColorKit(backgroundColor).isDark();
26335
26260
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
26336
26261
  className: "univer-flex univer-cursor-pointer univer-flex-row univer-items-center univer-justify-between univer-rounded-md univer-px-1.5 univer-py-1 hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-700",
26337
26262
  onClick: handleClick,
26338
26263
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
26339
26264
  className: (0, _univerjs_design.clsx)("univer-inline-flex univer-h-4 univer-w-fit univer-items-center univer-truncate univer-rounded-full univer-px-1.5 univer-text-xs", {
26340
- "univer-text-gray-900": !isDark,
26341
- "univer-text-white": isDark
26265
+ "univer-text-gray-900": isThemeColor || !isDark,
26266
+ "univer-text-gray-0": !isThemeColor && isDark
26342
26267
  }),
26343
- style: { background: item.color },
26268
+ style: { background: backgroundColor },
26344
26269
  children: lowerFilter && item.label.toLowerCase().includes(lowerFilter) ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
26345
26270
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: item.label.substring(0, index) }),
26346
26271
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
@@ -26410,7 +26335,7 @@ const Spin = ({ loading, children }) => {
26410
26335
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
26411
26336
  className: "univer-relative univer-size-full",
26412
26337
  children: [loading && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
26413
- className: "univer-absolute -univer-bottom-0.5 -univer-left-0.5 -univer-right-0.5 -univer-top-0.5 univer-z-10 univer-flex univer-items-center univer-justify-center univer-bg-white univer-backdrop-blur dark:!univer-bg-black",
26338
+ className: "univer-absolute -univer-bottom-0.5 -univer-left-0.5 -univer-right-0.5 -univer-top-0.5 univer-z-10 univer-flex univer-items-center univer-justify-center univer-bg-gray-0 univer-backdrop-blur dark:!univer-bg-gray-1000",
26414
26339
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "univer-size-10 univer-animate-spin univer-rounded-full univer-border-4 univer-border-solid univer-border-gray-100 univer-border-t-primary-500" })
26415
26340
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
26416
26341
  className: loading ? "univer-pointer-events-none univer-blur-sm" : "",
@@ -27018,7 +26943,7 @@ const PermissionDetailUserPart = (props) => {
27018
26943
  src: (_item$subject2 = item.subject) === null || _item$subject2 === void 0 ? void 0 : _item$subject2.avatar
27019
26944
  }),
27020
26945
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
27021
- className: "univer-ml-1.5 univer-w-[130px] univer-truncate univer-text-gray-900 dark:!univer-text-white",
26946
+ className: "univer-ml-1.5 univer-w-[130px] univer-truncate univer-text-gray-900 dark:!univer-text-gray-0",
27022
26947
  children: (_item$subject3 = item.subject) === null || _item$subject3 === void 0 ? void 0 : _item$subject3.name
27023
26948
  }),
27024
26949
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
@@ -27385,11 +27310,11 @@ function SheetPermissionPanelListContent() {
27385
27310
  }) })
27386
27311
  }),
27387
27312
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
27388
- className: "univer-h-4 univer-flex-grow univer-text-xs univer-text-gray-900 dark:!univer-text-white",
27313
+ className: "univer-h-4 univer-flex-grow univer-text-xs univer-text-gray-900 dark:!univer-text-gray-0",
27389
27314
  children: localeService.t("sheets-ui.permission.panel.created")
27390
27315
  }),
27391
27316
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
27392
- className: "univer-h-4 univer-text-xs univer-text-gray-900 dark:!univer-text-white",
27317
+ className: "univer-h-4 univer-text-xs univer-text-gray-900 dark:!univer-text-gray-0",
27393
27318
  children: editPermission ? `${localeService.t("sheets-ui.permission.panel.iCanEdit")}` : `${localeService.t("sheets-ui.permission.panel.iCanNotEdit")}`
27394
27319
  })
27395
27320
  ]
@@ -27397,10 +27322,10 @@ function SheetPermissionPanelListContent() {
27397
27322
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
27398
27323
  className: "univer-mt-2 univer-flex univer-items-center",
27399
27324
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
27400
- className: "univer-h-4 univer-flex-grow univer-text-xs univer-text-gray-900 dark:!univer-text-white",
27325
+ className: "univer-h-4 univer-flex-grow univer-text-xs univer-text-gray-900 dark:!univer-text-gray-0",
27401
27326
  children: localeService.t("sheets-ui.permission.panel.viewPermission")
27402
27327
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
27403
- className: "univer-h-4 univer-text-xs univer-text-gray-900 dark:!univer-text-white",
27328
+ className: "univer-h-4 univer-text-xs univer-text-gray-900 dark:!univer-text-gray-0",
27404
27329
  children: viewPermission ? `${localeService.t("sheets-ui.permission.panel.iCanView")}` : `${localeService.t("sheets-ui.permission.panel.iCanNotView")}`
27405
27330
  })]
27406
27331
  }),
@@ -27842,7 +27767,7 @@ const formulaEditorStyle = {
27842
27767
  }
27843
27768
  };
27844
27769
  let EditorDataSyncController = class EditorDataSyncController extends _univerjs_core.Disposable {
27845
- constructor(_univerInstanceService, _renderManagerService, _editorBridgeService, _commandService, _rangeProtectionRuleModel, _worksheetProtectionRuleModel, _formulaEditorController, _formulaEditorManagerService, _contextService) {
27770
+ constructor(_univerInstanceService, _renderManagerService, _editorBridgeService, _commandService, _rangeProtectionRuleModel, _worksheetProtectionRuleModel, _formulaEditorController, _formulaEditorManagerService, _contextService, _themeService) {
27846
27771
  super();
27847
27772
  this._univerInstanceService = _univerInstanceService;
27848
27773
  this._renderManagerService = _renderManagerService;
@@ -27853,12 +27778,14 @@ let EditorDataSyncController = class EditorDataSyncController extends _univerjs_
27853
27778
  this._formulaEditorController = _formulaEditorController;
27854
27779
  this._formulaEditorManagerService = _formulaEditorManagerService;
27855
27780
  this._contextService = _contextService;
27781
+ this._themeService = _themeService;
27856
27782
  this._initialize();
27857
27783
  }
27858
27784
  _initialize() {
27859
27785
  this._syncFormulaEditorContent();
27860
27786
  this._commandExecutedListener();
27861
27787
  this._syncFormulaRefRenderStyleOnFocusChange();
27788
+ this._syncFormulaBarTextColorOnThemeChange();
27862
27789
  }
27863
27790
  _getEditorViewModel(unitId) {
27864
27791
  var _this$_renderManagerS;
@@ -27982,6 +27909,11 @@ let EditorDataSyncController = class EditorDataSyncController extends _univerjs_
27982
27909
  this._refreshRenderStyleConfig(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
27983
27910
  }));
27984
27911
  }
27912
+ _syncFormulaBarTextColorOnThemeChange() {
27913
+ this.disposeWithMe(this._themeService.currentTheme$.pipe((0, rxjs.skip)(1)).subscribe(() => {
27914
+ this._refreshRenderStyleConfig(_univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
27915
+ }));
27916
+ }
27985
27917
  _refreshRenderStyleConfig(unitId) {
27986
27918
  var _currentRender$mainCo3;
27987
27919
  const currentRender = this._renderManagerService.getRenderUnitById(unitId);
@@ -27996,11 +27928,15 @@ let EditorDataSyncController = class EditorDataSyncController extends _univerjs_
27996
27928
  if (unitId === _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) this._formulaEditorController.autoScroll();
27997
27929
  }
27998
27930
  _checkAndSetRenderStyleConfig(documentDataModel) {
27999
- var _snapshot$body;
27931
+ var _snapshot$documentSty, _snapshot$body;
28000
27932
  const snapshot = documentDataModel.getSnapshot();
28001
27933
  if (snapshot.id !== _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY && snapshot.id !== _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY) return;
28002
27934
  const isFormulaBar = snapshot.id === _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY;
28003
- if (isFormulaBar) snapshot.documentStyle = formulaEditorStyle;
27935
+ const previousPageWidth = (_snapshot$documentSty = snapshot.documentStyle) === null || _snapshot$documentSty === void 0 || (_snapshot$documentSty = _snapshot$documentSty.pageSize) === null || _snapshot$documentSty === void 0 ? void 0 : _snapshot$documentSty.width;
27936
+ if (isFormulaBar) snapshot.documentStyle = {
27937
+ ...formulaEditorStyle,
27938
+ textStyle: { cl: { rgb: this._themeService.getColorFromTheme("gray.900") } }
27939
+ };
28004
27940
  else snapshot.documentStyle ??= {};
28005
27941
  let renderConfig = snapshot.documentStyle.renderConfig;
28006
27942
  if (renderConfig == null) {
@@ -28009,8 +27945,8 @@ let EditorDataSyncController = class EditorDataSyncController extends _univerjs_
28009
27945
  }
28010
27946
  const position = isFormulaBar ? this._formulaEditorManagerService.getPosition() : null;
28011
27947
  if (isFormulaBar && position) {
28012
- const width = position.width;
28013
- snapshot.documentStyle.pageSize = {
27948
+ const width = position.width > 0 ? position.width : previousPageWidth;
27949
+ if (width != null && width > 0) snapshot.documentStyle.pageSize = {
28014
27950
  width,
28015
27951
  height: Infinity
28016
27952
  };
@@ -28037,84 +27973,97 @@ EditorDataSyncController = __decorate([
28037
27973
  __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_sheets.WorksheetProtectionRuleModel)),
28038
27974
  __decorateParam(6, (0, _univerjs_core.Inject)(FormulaEditorController)),
28039
27975
  __decorateParam(7, IFormulaEditorManagerService),
28040
- __decorateParam(8, _univerjs_core.IContextService)
27976
+ __decorateParam(8, _univerjs_core.IContextService),
27977
+ __decorateParam(9, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService))
28041
27978
  ], EditorDataSyncController);
28042
27979
 
28043
27980
  //#endregion
28044
27981
  //#region src/controllers/force-string-alert-render.controller.ts
28045
27982
  const ALERT_KEY = "SHEET_FORCE_STRING_ALERT";
28046
27983
  let ForceStringAlertRenderController = class ForceStringAlertRenderController extends _univerjs_core.Disposable {
28047
- constructor(_context, _hoverManagerService, _cellAlertManagerService, _localeService, _configService) {
27984
+ constructor(_context, _selectionManagerService, _cellAlertManagerService, _localeService, _configService, _commandService, _univerInstanceService) {
28048
27985
  super();
28049
27986
  this._context = _context;
28050
- this._hoverManagerService = _hoverManagerService;
27987
+ this._selectionManagerService = _selectionManagerService;
28051
27988
  this._cellAlertManagerService = _cellAlertManagerService;
28052
27989
  this._localeService = _localeService;
28053
27990
  this._configService = _configService;
27991
+ this._commandService = _commandService;
27992
+ this._univerInstanceService = _univerInstanceService;
28054
27993
  this._init();
28055
27994
  }
28056
27995
  _init() {
28057
27996
  this._initCellAlertPopup();
28058
27997
  }
28059
27998
  _initCellAlertPopup() {
28060
- this.disposeWithMe(this._hoverManagerService.currentCell$.subscribe((cellPos) => {
28061
- if (cellPos) {
28062
- const location = cellPos.location;
28063
- const workbook = this._context.unit;
28064
- const worksheet = workbook.getActiveSheet();
28065
- if (!worksheet) return this._hideAlert();
28066
- const cellData = worksheet.getCell(location.row, location.col);
28067
- if (!cellData || cellData.v === null || cellData.v === void 0) return this._hideAlert();
28068
- let numfmtValue;
28069
- if (cellData === null || cellData === void 0 ? void 0 : cellData.s) {
28070
- const style = workbook.getStyles().get(cellData.s);
28071
- if (style === null || style === void 0 ? void 0 : style.n) numfmtValue = style.n;
28072
- }
28073
- if ((0, _univerjs_core.isTextFormat)(numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern)) {
28074
- this._hideAlert();
28075
- return;
28076
- }
28077
- /**
28078
- * If the cell type is string or force string, and the value is a pure number or a string that can be converted to a number, show the force string alert.
28079
- * '123 -> yes
28080
- * '20% -> yes
28081
- * '1,234.56 -> yes
28082
- * 'abc -> no
28083
- * '2025-09-17 -> no
28084
- */
28085
- if ((cellData.t === _univerjs_core.CellValueType.FORCE_STRING || cellData.t === _univerjs_core.CellValueType.STRING) && ((0, _univerjs_core.isRealNum)(cellData.v) || typeof cellData.v === "string" && (0, _univerjs_core.getNumfmtParseValueFilter)(cellData.v))) {
28086
- var _this$_configService$, _currentAlert$alert;
28087
- if ((_this$_configService$ = this._configService.getConfig("sheets-ui.config")) === null || _this$_configService$ === void 0 ? void 0 : _this$_configService$.disableForceStringAlert) return;
28088
- const currentAlert = this._cellAlertManagerService.currentAlert.get(ALERT_KEY);
28089
- const currentLoc = currentAlert === null || currentAlert === void 0 || (_currentAlert$alert = currentAlert.alert) === null || _currentAlert$alert === void 0 ? void 0 : _currentAlert$alert.location;
28090
- if (currentLoc && currentLoc.row === cellPos.location.row && currentLoc.col === cellPos.location.col && currentLoc.subUnitId === cellPos.location.subUnitId && currentLoc.unitId === cellPos.location.unitId) {
28091
- this._hideAlert();
28092
- return;
28093
- }
28094
- this._cellAlertManagerService.showAlert({
28095
- type: 2,
28096
- title: this._localeService.t("sheets-ui.info.error"),
28097
- message: this._localeService.t("sheets-ui.info.forceStringInfo"),
28098
- location,
28099
- width: 200,
28100
- height: 74,
28101
- key: ALERT_KEY
28102
- });
28103
- return;
27999
+ this.disposeWithMe(this._selectionManagerService.selectionChanged$.subscribe((selections) => this._updateAlert(selections)));
28000
+ this.disposeWithMe(this._context.unit.activeSheet$.subscribe(() => this._updateAlert(this._selectionManagerService.getCurrentSelections())));
28001
+ this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe(() => this._updateAlert(this._selectionManagerService.getCurrentSelections())));
28002
+ }
28003
+ _isCurrentSheet(worksheet) {
28004
+ const selectionParam = this._selectionManagerService.currentSelectionParam;
28005
+ return Boolean(worksheet && (selectionParam === null || selectionParam === void 0 ? void 0 : selectionParam.unitId) === this._context.unit.getUnitId() && selectionParam.sheetId === worksheet.getSheetId());
28006
+ }
28007
+ _updateAlert(selections) {
28008
+ var _this$_configService$, _cellStyle$n;
28009
+ this._hideAlert();
28010
+ const workbook = this._context.unit;
28011
+ const worksheet = workbook.getActiveSheet();
28012
+ if (!this._isCurrentSheet(worksheet)) return;
28013
+ if ((selections === null || selections === void 0 ? void 0 : selections.length) !== 1) return;
28014
+ if ((_this$_configService$ = this._configService.getConfig("sheets-ui.config")) === null || _this$_configService$ === void 0 ? void 0 : _this$_configService$.disableForceStringAlert) return;
28015
+ const selection = selections[0];
28016
+ const primary = selection.primary;
28017
+ if (!primary) return;
28018
+ const row = primary.actualRow;
28019
+ const col = primary.actualColumn;
28020
+ const cellData = worksheet.getCell(row, col);
28021
+ if (!cellData || cellData.v === null || cellData.v === void 0) return;
28022
+ const cellStyle = workbook.getStyles().get(cellData.s);
28023
+ if ((0, _univerjs_core.isTextFormat)(cellStyle === null || cellStyle === void 0 || (_cellStyle$n = cellStyle.n) === null || _cellStyle$n === void 0 ? void 0 : _cellStyle$n.pattern)) return;
28024
+ if (cellData.t !== _univerjs_core.CellValueType.FORCE_STRING && cellData.t !== _univerjs_core.CellValueType.STRING || !(0, _univerjs_core.isRealNum)(cellData.v) && !(typeof cellData.v === "string" && (0, _univerjs_core.getNumfmtParseValueFilter)(cellData.v))) return;
28025
+ const unitId = workbook.getUnitId();
28026
+ const subUnitId = worksheet.getSheetId();
28027
+ const range = { ...selection.range };
28028
+ this._cellAlertManagerService.showAlert({
28029
+ type: 1,
28030
+ title: this._localeService.t("sheets-ui.info.error"),
28031
+ message: this._localeService.t("sheets-ui.info.forceStringInfo"),
28032
+ location: {
28033
+ unitId,
28034
+ subUnitId,
28035
+ row,
28036
+ col
28037
+ },
28038
+ width: 200,
28039
+ height: 74,
28040
+ key: this._alertKey,
28041
+ menu: [{
28042
+ label: this._localeService.t("sheets-ui.info.convertToNumber"),
28043
+ onSelect: () => {
28044
+ if (this._commandService.syncExecuteCommand(_univerjs_sheets.TextToNumberCommand.id, {
28045
+ unitId,
28046
+ subUnitId,
28047
+ ranges: [range]
28048
+ })) this._hideAlert();
28104
28049
  }
28105
- }
28106
- this._hideAlert();
28107
- }));
28050
+ }]
28051
+ });
28052
+ }
28053
+ get _alertKey() {
28054
+ return `${ALERT_KEY}:${this._context.unit.getUnitId()}`;
28108
28055
  }
28109
28056
  _hideAlert() {
28110
- this._cellAlertManagerService.removeAlert(ALERT_KEY);
28057
+ this._cellAlertManagerService.removeAlert(this._alertKey);
28111
28058
  }
28112
28059
  };
28113
28060
  ForceStringAlertRenderController = __decorate([
28114
- __decorateParam(1, (0, _univerjs_core.Inject)(HoverManagerService)),
28061
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
28115
28062
  __decorateParam(2, (0, _univerjs_core.Inject)(CellAlertManagerService)),
28116
28063
  __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
28117
- __decorateParam(4, _univerjs_core.IConfigService)
28064
+ __decorateParam(4, _univerjs_core.IConfigService),
28065
+ __decorateParam(5, _univerjs_core.ICommandService),
28066
+ __decorateParam(6, _univerjs_core.IUniverInstanceService)
28118
28067
  ], ForceStringAlertRenderController);
28119
28068
 
28120
28069
  //#endregion
@@ -28544,7 +28493,7 @@ function MobileSheetBarImpl(props) {
28544
28493
  tabMapRef.current.set(sheet.sheetId, element);
28545
28494
  },
28546
28495
  className: (0, _univerjs_design.clsx)("univer-relative univer-box-border univer-flex univer-h-full univer-max-w-36 univer-shrink-0 univer-cursor-pointer univer-select-none univer-items-center univer-justify-center univer-truncate univer-px-1 univer-py-0.5 univer-text-sm univer-font-medium univer-leading-6 univer-transition-all", _univerjs_design.borderRightClassName, {
28547
- "univer-bg-white univer-text-blue-600 dark:!univer-bg-gray-700 dark:!univer-text-blue-400": sheet.sheetId === activeKey,
28496
+ "univer-bg-gray-0 univer-text-blue-600 dark:!univer-bg-gray-700 dark:!univer-text-blue-400": sheet.sheetId === activeKey,
28548
28497
  "univer-text-gray-600 hover:univer-bg-gray-50 active:univer-bg-gray-100 dark:!univer-text-gray-300 dark:hover:!univer-bg-gray-700": sheet.sheetId !== activeKey
28549
28498
  }),
28550
28499
  role: "tab",
@@ -29360,35 +29309,37 @@ FormatPainterRenderController = __decorate([
29360
29309
  //#region src/controllers/render-controllers/header-menu.render-controller.ts
29361
29310
  const HEADER_MENU_CONTROLLER_SHAPE = "__SpreadsheetHeaderMenuSHAPEControllerShape__";
29362
29311
  const HEADER_MENU_CONTROLLER_MENU = "__SpreadsheetHeaderMenuMAINControllerShape__";
29363
- const HEADER_MENU_CONTROLLER_SHAPE_COLOR = "rgba(0, 0, 0, 0.1)";
29312
+ const HEADER_MENU_CONTROLLER_SHAPE_ALPHA = .1;
29364
29313
  let HeaderMenuRenderController = class HeaderMenuRenderController extends _univerjs_core.Disposable {
29365
- constructor(_context, _sheetSkeletonManagerService, _contextMenuService, _commandService, _selectionManagerService) {
29314
+ constructor(_context, _sheetSkeletonManagerService, _contextMenuService, _commandService, _selectionManagerService, _themeService) {
29366
29315
  super();
29367
29316
  this._context = _context;
29368
29317
  this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
29369
29318
  this._contextMenuService = _contextMenuService;
29370
29319
  this._commandService = _commandService;
29371
29320
  this._selectionManagerService = _selectionManagerService;
29321
+ this._themeService = _themeService;
29372
29322
  _defineProperty(this, "_hoverRect", void 0);
29373
29323
  _defineProperty(this, "_hoverMenu", void 0);
29374
29324
  _defineProperty(this, "_currentColumn", Number.POSITIVE_INFINITY);
29375
- _defineProperty(this, "_headerPointerSubs", void 0);
29376
- _defineProperty(this, "_colHeaderPointerSubs", void 0);
29325
+ _defineProperty(this, "_headerPointerSubs", new rxjs.Subscription());
29377
29326
  this._initialize();
29378
29327
  }
29379
29328
  dispose() {
29380
- var _this$_hoverRect, _this$_hoverMenu, _this$_headerPointerS;
29329
+ var _this$_hoverRect, _this$_hoverMenu;
29330
+ super.dispose();
29381
29331
  (_this$_hoverRect = this._hoverRect) === null || _this$_hoverRect === void 0 || _this$_hoverRect.dispose();
29382
29332
  (_this$_hoverMenu = this._hoverMenu) === null || _this$_hoverMenu === void 0 || _this$_hoverMenu.dispose();
29383
- (_this$_headerPointerS = this._headerPointerSubs) === null || _this$_headerPointerS === void 0 || _this$_headerPointerS.unsubscribe();
29384
- this._headerPointerSubs = null;
29333
+ this._headerPointerSubs.unsubscribe();
29385
29334
  }
29386
29335
  _initialize() {
29387
29336
  const scene = this._context.scene;
29388
- this._hoverRect = new _univerjs_engine_render.Rect(HEADER_MENU_CONTROLLER_SHAPE, {
29389
- fill: HEADER_MENU_CONTROLLER_SHAPE_COLOR,
29390
- evented: false
29391
- });
29337
+ this._hoverRect = new _univerjs_engine_render.Rect(HEADER_MENU_CONTROLLER_SHAPE, { evented: false });
29338
+ this.disposeWithMe(this._themeService.currentTheme$.subscribe(() => {
29339
+ var _this$_hoverRect2;
29340
+ const color = this._themeService.getColorFromTheme("gray.900");
29341
+ (_this$_hoverRect2 = this._hoverRect) === null || _this$_hoverRect2 === void 0 || _this$_hoverRect2.setProps({ fill: new _univerjs_core.ColorKit(color).setAlpha(HEADER_MENU_CONTROLLER_SHAPE_ALPHA).toRgbString() });
29342
+ }));
29392
29343
  this._hoverMenu = new HeaderMenuShape(HEADER_MENU_CONTROLLER_MENU, {
29393
29344
  zIndex: 100,
29394
29345
  visible: false
@@ -29399,7 +29350,6 @@ let HeaderMenuRenderController = class HeaderMenuRenderController extends _unive
29399
29350
  this._initialHoverMenu();
29400
29351
  }
29401
29352
  _initialHover(initialType = 0) {
29402
- var _this$_headerPointerS2, _this$_headerPointerS3, _this$_headerPointerS4;
29403
29353
  const spreadsheetColumnHeader = this._context.components.get("__SpreadsheetColumnHeader__");
29404
29354
  const spreadsheetRowHeader = this._context.components.get("__SpreadsheetRowHeader__");
29405
29355
  const eventBindingObject = initialType === 0 ? spreadsheetRowHeader : spreadsheetColumnHeader;
@@ -29410,17 +29360,17 @@ let HeaderMenuRenderController = class HeaderMenuRenderController extends _unive
29410
29360
  const { rowBaseWidth, rowGutterWidth, columnBaseHeight, columnGutterHeight } = getHeaderBaseLayout(skeleton);
29411
29361
  const { startX, startY, endX, endY, column } = getCoordByOffset(evt.offsetX, evt.offsetY, this._context.scene, skeleton);
29412
29362
  if (initialType === 0) {
29413
- var _this$_hoverRect2;
29414
- (_this$_hoverRect2 = this._hoverRect) === null || _this$_hoverRect2 === void 0 || _this$_hoverRect2.transformByState({
29363
+ var _this$_hoverRect3;
29364
+ (_this$_hoverRect3 = this._hoverRect) === null || _this$_hoverRect3 === void 0 || _this$_hoverRect3.transformByState({
29415
29365
  width: rowBaseWidth,
29416
29366
  height: endY - startY,
29417
29367
  left: rowGutterWidth,
29418
29368
  top: startY
29419
29369
  });
29420
29370
  } else {
29421
- var _this$_hoverRect3;
29371
+ var _this$_hoverRect4;
29422
29372
  this._currentColumn = column;
29423
- (_this$_hoverRect3 = this._hoverRect) === null || _this$_hoverRect3 === void 0 || _this$_hoverRect3.transformByState({
29373
+ (_this$_hoverRect4 = this._hoverRect) === null || _this$_hoverRect4 === void 0 || _this$_hoverRect4.transformByState({
29424
29374
  width: endX - startX,
29425
29375
  height: columnBaseHeight,
29426
29376
  left: startX,
@@ -29441,21 +29391,20 @@ let HeaderMenuRenderController = class HeaderMenuRenderController extends _unive
29441
29391
  }
29442
29392
  };
29443
29393
  const pointerEnterHandler = () => {
29444
- var _this$_hoverRect4;
29445
- (_this$_hoverRect4 = this._hoverRect) === null || _this$_hoverRect4 === void 0 || _this$_hoverRect4.show();
29394
+ var _this$_hoverRect5;
29395
+ (_this$_hoverRect5 = this._hoverRect) === null || _this$_hoverRect5 === void 0 || _this$_hoverRect5.show();
29446
29396
  };
29447
29397
  const pointerLeaveHandler = () => {
29448
- var _this$_hoverRect5, _this$_hoverMenu2;
29449
- (_this$_hoverRect5 = this._hoverRect) === null || _this$_hoverRect5 === void 0 || _this$_hoverRect5.hide();
29398
+ var _this$_hoverRect6, _this$_hoverMenu2;
29399
+ (_this$_hoverRect6 = this._hoverRect) === null || _this$_hoverRect6 === void 0 || _this$_hoverRect6.hide();
29450
29400
  (_this$_hoverMenu2 = this._hoverMenu) === null || _this$_hoverMenu2 === void 0 || _this$_hoverMenu2.hide();
29451
29401
  };
29452
- this._headerPointerSubs = new rxjs.Subscription();
29453
29402
  const headerPointerMoveSub = eventBindingObject.onPointerMove$.subscribeEvent(pointerMoveHandler);
29454
29403
  const headerPointerEnterSub = eventBindingObject.onPointerEnter$.subscribeEvent(pointerEnterHandler);
29455
29404
  const headerPointerLeaveSub = eventBindingObject.onPointerLeave$.subscribeEvent(pointerLeaveHandler);
29456
- (_this$_headerPointerS2 = this._headerPointerSubs) === null || _this$_headerPointerS2 === void 0 || _this$_headerPointerS2.add(headerPointerMoveSub);
29457
- (_this$_headerPointerS3 = this._headerPointerSubs) === null || _this$_headerPointerS3 === void 0 || _this$_headerPointerS3.add(headerPointerEnterSub);
29458
- (_this$_headerPointerS4 = this._headerPointerSubs) === null || _this$_headerPointerS4 === void 0 || _this$_headerPointerS4.add(headerPointerLeaveSub);
29405
+ this._headerPointerSubs.add(headerPointerMoveSub);
29406
+ this._headerPointerSubs.add(headerPointerEnterSub);
29407
+ this._headerPointerSubs.add(headerPointerLeaveSub);
29459
29408
  }
29460
29409
  _initialHoverMenu() {
29461
29410
  if (this._hoverMenu == null) return;
@@ -29526,7 +29475,8 @@ HeaderMenuRenderController = __decorate([
29526
29475
  __decorateParam(1, (0, _univerjs_core.Inject)(SheetSkeletonManagerService)),
29527
29476
  __decorateParam(2, _univerjs_ui.IContextMenuService),
29528
29477
  __decorateParam(3, _univerjs_core.ICommandService),
29529
- __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService))
29478
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
29479
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService))
29530
29480
  ], HeaderMenuRenderController);
29531
29481
  function getHeaderBaseLayout(skeleton) {
29532
29482
  var _skeleton$worksheet$g, _skeleton$worksheet, _config$rowHeader, _config$columnHeader;
@@ -30838,6 +30788,36 @@ MobileSheetsScrollRenderController = __decorate([
30838
30788
  __decorateParam(7, _univerjs_core.IContextService)
30839
30789
  ], MobileSheetsScrollRenderController);
30840
30790
 
30791
+ //#endregion
30792
+ //#region src/controllers/render-controllers/skeleton.render-controller.ts
30793
+ let SheetSkeletonRenderController = class SheetSkeletonRenderController extends _univerjs_core.Disposable {
30794
+ constructor(_context, _sheetSkeletonManagerService, _renderManagerService) {
30795
+ super();
30796
+ this._context = _context;
30797
+ this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
30798
+ this._renderManagerService = _renderManagerService;
30799
+ this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe((param) => {
30800
+ this._updateSceneSize(param);
30801
+ }));
30802
+ }
30803
+ _updateSceneSize(param) {
30804
+ var _this$_renderManagerS;
30805
+ if (param == null) return;
30806
+ const { unitId } = this._context;
30807
+ const { skeleton } = param;
30808
+ const scene = (_this$_renderManagerS = this._renderManagerService.getRenderUnitById(unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.scene;
30809
+ if (skeleton == null || scene == null) return;
30810
+ const { rowTotalHeight, columnTotalWidth, rowHeaderWidthAndMarginLeft, columnHeaderHeightAndMarginTop } = skeleton;
30811
+ if (!this._context.unit.getActiveSheet()) return;
30812
+ scene === null || scene === void 0 || scene.transformByState({
30813
+ width: rowHeaderWidthAndMarginLeft + columnTotalWidth,
30814
+ height: columnHeaderHeightAndMarginTop + rowTotalHeight
30815
+ });
30816
+ scene.getMainViewport().setMargin(rowHeaderWidthAndMarginLeft, columnHeaderHeightAndMarginTop);
30817
+ }
30818
+ };
30819
+ SheetSkeletonRenderController = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(SheetSkeletonManagerService)), __decorateParam(2, _univerjs_engine_render.IRenderManagerService)], SheetSkeletonRenderController);
30820
+
30841
30821
  //#endregion
30842
30822
  //#region src/services/auto-height.service.ts
30843
30823
  const IAutoHeightService = (0, _univerjs_core.createIdentifier)("sheets-ui.services.auto-height");
@@ -31743,7 +31723,6 @@ let UniverSheetsMobileUIPlugin = class UniverSheetsMobileUIPlugin extends _unive
31743
31723
  [SelectAllService],
31744
31724
  [ISheetCellDropdownManagerService, { useClass: SheetCellDropdownManagerService }],
31745
31725
  [SheetCellEditorResizeService],
31746
- [ISheetLoadingRenderService, { useClass: SheetLoadingRenderService }],
31747
31726
  [AutoHeightController],
31748
31727
  [AutoWidthController],
31749
31728
  [FormulaEditorController],
@@ -31878,6 +31857,7 @@ let SheetContextMenuRenderController = class SheetContextMenuRenderController ex
31878
31857
  this._selectionRenderService = _selectionRenderService;
31879
31858
  this._injector = _injector;
31880
31859
  this._init();
31860
+ this._initEmbedRuntimeSessionListener();
31881
31861
  }
31882
31862
  _init() {
31883
31863
  var _this$_context;
@@ -31925,6 +31905,13 @@ let SheetContextMenuRenderController = class SheetContextMenuRenderController ex
31925
31905
  });
31926
31906
  this.disposeWithMe(colHeaderObserver);
31927
31907
  }
31908
+ _initEmbedRuntimeSessionListener() {
31909
+ const runtimeFocusCoordinator = this._getSheetEmbedRuntimeFocusCoordinator();
31910
+ if (!runtimeFocusCoordinator) return;
31911
+ this.disposeWithMe(runtimeFocusCoordinator.runtimeSessionChanged$.subscribe(() => {
31912
+ if (shouldHideSheetHostContextMenuForEmbedSession(this._context.unitId, runtimeFocusCoordinator.resolveActiveChildSessionRuntimeScope())) this._contextMenuService.hideContextMenu();
31913
+ }));
31914
+ }
31928
31915
  _shouldSuppressHostContextMenu() {
31929
31916
  var _this$_getSheetHostCh, _this$_getSheetHostCh2;
31930
31917
  return shouldSuppressSheetContextMenuForEmbedOverride(this._context.unitId, (_this$_getSheetHostCh = this._getSheetHostChromeOverrideService()) === null || _this$_getSheetHostCh === void 0 || (_this$_getSheetHostCh2 = _this$_getSheetHostCh.getOverride) === null || _this$_getSheetHostCh2 === void 0 ? void 0 : _this$_getSheetHostCh2.call(_this$_getSheetHostCh));
@@ -31932,6 +31919,9 @@ let SheetContextMenuRenderController = class SheetContextMenuRenderController ex
31932
31919
  _getSheetHostChromeOverrideService() {
31933
31920
  return this._injector.has(ISheetHostChromeOverrideService) ? this._injector.get(ISheetHostChromeOverrideService) : void 0;
31934
31921
  }
31922
+ _getSheetEmbedRuntimeFocusCoordinator() {
31923
+ return this._injector.has(ISheetEmbedRuntimeFocusCoordinator) ? this._injector.get(ISheetEmbedRuntimeFocusCoordinator) : void 0;
31924
+ }
31935
31925
  };
31936
31926
  SheetContextMenuRenderController = __decorate([
31937
31927
  __decorateParam(1, _univerjs_ui.IContextMenuService),
@@ -31939,6 +31929,9 @@ SheetContextMenuRenderController = __decorate([
31939
31929
  __decorateParam(3, ISheetSelectionRenderService),
31940
31930
  __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
31941
31931
  ], SheetContextMenuRenderController);
31932
+ function shouldHideSheetHostContextMenuForEmbedSession(hostUnitId, activeScope) {
31933
+ return (activeScope === null || activeScope === void 0 ? void 0 : activeScope.hostUnitId) === hostUnitId && activeScope.sessionMode !== "host-passive";
31934
+ }
31942
31935
  function shouldSuppressSheetContextMenuForEmbedOverride(hostUnitId, override) {
31943
31936
  return override != null && override.hostUnitId === hostUnitId && override.entry === "sheets-sheet-tab";
31944
31937
  }
@@ -32361,7 +32354,6 @@ let UniverSheetsUIPlugin = class UniverSheetsUIPlugin extends _univerjs_core.Plu
32361
32354
  [SelectAllService],
32362
32355
  [ISheetCellDropdownManagerService, { useClass: SheetCellDropdownManagerService }],
32363
32356
  [SheetCellEditorResizeService],
32364
- [ISheetLoadingRenderService, { useClass: SheetLoadingRenderService }],
32365
32357
  [AutoHeightController],
32366
32358
  [AutoWidthController],
32367
32359
  [FormulaEditorController],
@@ -32623,6 +32615,7 @@ exports.IFormatPainterService = IFormatPainterService;
32623
32615
  exports.IFormulaEditorManagerService = IFormulaEditorManagerService;
32624
32616
  exports.IMarkSelectionService = IMarkSelectionService;
32625
32617
  exports.IRepeatLastActionService = IRepeatLastActionService;
32618
+ exports.ISheetBarService = ISheetBarService;
32626
32619
  exports.ISheetCellDropdownManagerService = ISheetCellDropdownManagerService;
32627
32620
  exports.ISheetClipboardService = ISheetClipboardService;
32628
32621
  exports.ISheetEmbedFloatingGeometryService = ISheetEmbedFloatingGeometryService;
@@ -32630,7 +32623,6 @@ exports.ISheetEmbedInteractionBoundaryService = ISheetEmbedInteractionBoundarySe
32630
32623
  exports.ISheetEmbedRuntimeFocusCoordinator = ISheetEmbedRuntimeFocusCoordinator;
32631
32624
  exports.ISheetEmbedRuntimeService = ISheetEmbedRuntimeService;
32632
32625
  exports.ISheetHostChromeOverrideService = ISheetHostChromeOverrideService;
32633
- exports.ISheetLoadingRenderService = ISheetLoadingRenderService;
32634
32626
  exports.ISheetSelectionRenderService = ISheetSelectionRenderService;
32635
32627
  exports.IStatusBarService = IStatusBarService;
32636
32628
  exports.InsertRangeMoveDownConfirmCommand = InsertRangeMoveDownConfirmCommand;
@@ -32708,6 +32700,7 @@ exports.SetWorksheetColAutoWidthCommand = SetWorksheetColAutoWidthCommand;
32708
32700
  exports.SetZoomRatioCommand = SetZoomRatioCommand;
32709
32701
  exports.SetZoomRatioOperation = SetZoomRatioOperation;
32710
32702
  exports.SheetBar = SheetBar;
32703
+ exports.SheetBarService = SheetBarService;
32711
32704
  Object.defineProperty(exports, 'SheetCanvasPopManagerService', {
32712
32705
  enumerable: true,
32713
32706
  get: function () {