@univerjs/docs-ui 1.0.0-alpha.8 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -285,10 +285,7 @@ let DocAutoFormatService = class DocAutoFormatService extends _univerjs_core.Dis
285
285
  const matchList = this._matches.get(match.id);
286
286
  if (matchList) {
287
287
  matchList.push(match);
288
- matchList.sort((a, b) => {
289
- var _b$priority, _a$priority;
290
- return ((_b$priority = b.priority) !== null && _b$priority !== void 0 ? _b$priority : 0) - ((_a$priority = a.priority) !== null && _a$priority !== void 0 ? _a$priority : 0);
291
- });
288
+ matchList.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
292
289
  } else this._matches.set(match.id, [match]);
293
290
  return (0, _univerjs_core.toDisposable)(() => {
294
291
  const matchList = this._matches.get(match.id);
@@ -299,25 +296,24 @@ let DocAutoFormatService = class DocAutoFormatService extends _univerjs_core.Dis
299
296
  });
300
297
  }
301
298
  onAutoFormat(id, params) {
302
- var _this$_matches$get, _docRanges$find, _selection$segmentId;
303
- const autoFormats = (_this$_matches$get = this._matches.get(id)) !== null && _this$_matches$get !== void 0 ? _this$_matches$get : [];
299
+ const autoFormats = this._matches.get(id) ?? [];
304
300
  const unit = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
305
301
  const docRanges = this._textSelectionManagerService.getDocRanges();
306
- const selection = (_docRanges$find = docRanges.find((range) => range.isActive)) !== null && _docRanges$find !== void 0 ? _docRanges$find : docRanges[0];
307
- const documentDataModel = unit === null || unit === void 0 ? void 0 : unit.getSelfOrHeaderFooterModel((_selection$segmentId = selection === null || selection === void 0 ? void 0 : selection.segmentId) !== null && _selection$segmentId !== void 0 ? _selection$segmentId : "");
302
+ const selection = docRanges.find((range) => range.isActive) ?? docRanges[0];
303
+ const documentDataModel = unit === null || unit === void 0 ? void 0 : unit.getSelfOrHeaderFooterModel((selection === null || selection === void 0 ? void 0 : selection.segmentId) ?? "");
308
304
  if (unit && selection && documentDataModel) {
309
- var _documentDataModel$ge, _documentDataModel$ge2, _documentDataModel$ge3, _documentDataModel$ge4, _documentDataModel$ge5, _documentDataModel$ge6, _matched$getMutations;
305
+ var _documentDataModel$ge, _documentDataModel$ge2, _documentDataModel$ge3;
310
306
  const context = {
311
307
  unit: documentDataModel,
312
308
  selection,
313
309
  isBody: !selection.segmentId,
314
- paragraphs: _univerjs_core.BuildTextUtils.range.getParagraphsInRange(selection, (_documentDataModel$ge = (_documentDataModel$ge2 = documentDataModel.getBody()) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.paragraphs) !== null && _documentDataModel$ge !== void 0 ? _documentDataModel$ge : [], (_documentDataModel$ge3 = (_documentDataModel$ge4 = documentDataModel.getBody()) === null || _documentDataModel$ge4 === void 0 ? void 0 : _documentDataModel$ge4.dataStream) !== null && _documentDataModel$ge3 !== void 0 ? _documentDataModel$ge3 : ""),
315
- customRanges: _univerjs_core.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection, (_documentDataModel$ge5 = (_documentDataModel$ge6 = documentDataModel.getBody()) === null || _documentDataModel$ge6 === void 0 ? void 0 : _documentDataModel$ge6.customRanges) !== null && _documentDataModel$ge5 !== void 0 ? _documentDataModel$ge5 : []),
310
+ paragraphs: _univerjs_core.BuildTextUtils.range.getParagraphsInRange(selection, ((_documentDataModel$ge = documentDataModel.getBody()) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.paragraphs) ?? [], ((_documentDataModel$ge2 = documentDataModel.getBody()) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.dataStream) ?? ""),
311
+ customRanges: _univerjs_core.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection, ((_documentDataModel$ge3 = documentDataModel.getBody()) === null || _documentDataModel$ge3 === void 0 ? void 0 : _documentDataModel$ge3.customRanges) ?? []),
316
312
  commandId: id,
317
313
  commandParams: params
318
314
  };
319
315
  const matched = autoFormats.find((i) => i.match(context));
320
- return (_matched$getMutations = matched === null || matched === void 0 ? void 0 : matched.getMutations(context)) !== null && _matched$getMutations !== void 0 ? _matched$getMutations : [];
316
+ return (matched === null || matched === void 0 ? void 0 : matched.getMutations(context)) ?? [];
321
317
  }
322
318
  return [];
323
319
  }
@@ -420,12 +416,12 @@ const BreakLineCommand = {
420
416
  id: "doc.command.break-line",
421
417
  type: _univerjs_core.CommandType.COMMAND,
422
418
  handler: (accessor, params) => {
423
- var _params$textRange, _docDataModel$getSelf, _originBody$paragraph, _prevParagraph$bullet, _prevParagraph$paragr;
419
+ var _docDataModel$getSelf, _prevParagraph$bullet, _prevParagraph$paragr;
424
420
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
425
421
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
426
422
  const commandService = accessor.get(_univerjs_core.ICommandService);
427
423
  const docMenuStyleService = accessor.get(DocMenuStyleService);
428
- const activeTextRange = (_params$textRange = params === null || params === void 0 ? void 0 : params.textRange) !== null && _params$textRange !== void 0 ? _params$textRange : docSelectionManagerService.getActiveTextRange();
424
+ const activeTextRange = (params === null || params === void 0 ? void 0 : params.textRange) ?? docSelectionManagerService.getActiveTextRange();
429
425
  const rectRanges = docSelectionManagerService.getRectRanges();
430
426
  if (activeTextRange == null) return false;
431
427
  if (rectRanges && rectRanges.length) {
@@ -436,15 +432,16 @@ const BreakLineCommand = {
436
432
  }]);
437
433
  return true;
438
434
  }
439
- const { horizontalLine, insertionMode = "split-paragraph" } = params !== null && params !== void 0 ? params : {};
435
+ const { horizontalLine, insertionMode = "split-paragraph" } = params ?? {};
440
436
  const { segmentId } = activeTextRange;
441
437
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
442
- const originBody = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId !== null && segmentId !== void 0 ? segmentId : "")) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
438
+ const originBody = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId ?? "")) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
443
439
  if (docDataModel == null || originBody == null) return false;
444
440
  const unitId = docDataModel.getUnitId();
445
441
  const { startOffset, endOffset } = activeTextRange;
446
- const paragraphs = (_originBody$paragraph = originBody.paragraphs) !== null && _originBody$paragraph !== void 0 ? _originBody$paragraph : [];
447
- const insertsAtStructuralGap = insertionMode === "insert-gap" || isTopLevelStructuralGap(originBody.dataStream, startOffset);
442
+ const paragraphs = originBody.paragraphs ?? [];
443
+ const isBareStructuralGap = isTopLevelStructuralGap(originBody.dataStream, startOffset) && originBody.dataStream[startOffset] !== _univerjs_core.DataStreamTreeTokenType.PARAGRAPH;
444
+ const insertsAtStructuralGap = insertionMode === "insert-gap" || isBareStructuralGap;
448
445
  const prevParagraph = insertsAtStructuralGap ? void 0 : paragraphs.find((p) => p.startIndex >= startOffset);
449
446
  if (!prevParagraph && !insertsAtStructuralGap) return false;
450
447
  const isAtParagraphEnd = startOffset === (prevParagraph === null || prevParagraph === void 0 ? void 0 : prevParagraph.startIndex);
@@ -1129,7 +1126,6 @@ const InnerPasteCommand = {
1129
1126
  if (hasTable && hasRangeInTable(selections)) return false;
1130
1127
  if (selections.length && (rectRanges === null || rectRanges === void 0 ? void 0 : rectRanges.length)) return false;
1131
1128
  for (let i = 0; i < selections.length; i++) {
1132
- var _originBody$customRan, _originBody$customDec;
1133
1129
  const selection = selections[i];
1134
1130
  const { startOffset, endOffset, collapsed } = selection;
1135
1131
  const len = startOffset - memoryCursor.cursor;
@@ -1159,8 +1155,8 @@ const InnerPasteCommand = {
1159
1155
  rawActions.push(action);
1160
1156
  }
1161
1157
  if (hasCustomBlock && drawings) {
1162
- var _docDataModel$getSnap, _docDataModel$getSnap2;
1163
- const drawingLen = (_docDataModel$getSnap = (_docDataModel$getSnap2 = docDataModel.getSnapshot().drawingsOrder) === null || _docDataModel$getSnap2 === void 0 ? void 0 : _docDataModel$getSnap2.length) !== null && _docDataModel$getSnap !== void 0 ? _docDataModel$getSnap : 0;
1158
+ var _docDataModel$getSnap;
1159
+ const drawingLen = ((_docDataModel$getSnap = docDataModel.getSnapshot().drawingsOrder) === null || _docDataModel$getSnap === void 0 ? void 0 : _docDataModel$getSnap.length) ?? 0;
1164
1160
  for (const block of cloneBody.customBlocks) {
1165
1161
  const { blockId } = block;
1166
1162
  const drawingId = (0, _univerjs_core.generateRandomId)(6);
@@ -1199,8 +1195,8 @@ const InnerPasteCommand = {
1199
1195
  resourceMutationGroups.push(mutationInfos);
1200
1196
  }
1201
1197
  }
1202
- const customRange = getCustomRangeAtPosition((_originBody$customRan = originBody.customRanges) !== null && _originBody$customRan !== void 0 ? _originBody$customRan : [], endOffset, UNITS.includes(unitId));
1203
- const customDecorations = getCustomDecorationAtPosition((_originBody$customDec = originBody.customDecorations) !== null && _originBody$customDec !== void 0 ? _originBody$customDec : [], endOffset);
1198
+ const customRange = getCustomRangeAtPosition(originBody.customRanges ?? [], endOffset, UNITS.includes(unitId));
1199
+ const customDecorations = getCustomDecorationAtPosition(originBody.customDecorations ?? [], endOffset);
1204
1200
  if (customRange) cloneBody.customRanges = [{
1205
1201
  ...customRange,
1206
1202
  startIndex: 0,
@@ -1293,7 +1289,7 @@ function adjustSelectionByTable(selection, tables) {
1293
1289
  };
1294
1290
  }
1295
1291
  function getCutActionsFromTextRanges(selections, docDataModel, segmentId) {
1296
- var _docDataModel$getSelf2, _docDataModel$getDraw, _docDataModel$getDraw2;
1292
+ var _docDataModel$getSelf2;
1297
1293
  const originBody = (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.getBody();
1298
1294
  const textX = new _univerjs_core.TextX();
1299
1295
  const jsonX = _univerjs_core.JSONX.getInstance();
@@ -1317,8 +1313,8 @@ function getCutActionsFromTextRanges(selections, docDataModel, segmentId) {
1317
1313
  const path = (0, _univerjs_core.getRichTextEditPath)(docDataModel, segmentId);
1318
1314
  rawActions.push(jsonX.editOp(textX.serialize(), path));
1319
1315
  const removedCustomBlockIds = (0, _univerjs_core.getCustomBlockIdsInSelections)(originBody, selections);
1320
- const drawings = (_docDataModel$getDraw = docDataModel.getDrawings()) !== null && _docDataModel$getDraw !== void 0 ? _docDataModel$getDraw : {};
1321
- const drawingOrder = (_docDataModel$getDraw2 = docDataModel.getDrawingsOrder()) !== null && _docDataModel$getDraw2 !== void 0 ? _docDataModel$getDraw2 : [];
1316
+ const drawings = docDataModel.getDrawings() ?? {};
1317
+ const drawingOrder = docDataModel.getDrawingsOrder() ?? [];
1322
1318
  const sortedRemovedCustomBlockIds = removedCustomBlockIds.sort((a, b) => {
1323
1319
  if (drawingOrder.indexOf(a) > drawingOrder.indexOf(b)) return -1;
1324
1320
  else if (drawingOrder.indexOf(a) < drawingOrder.indexOf(b)) return 1;
@@ -1463,12 +1459,12 @@ const CutContentCommand = {
1463
1459
  //#endregion
1464
1460
  //#region src/commands/commands/util.ts
1465
1461
  function getCurrentParagraph(accessor) {
1466
- var _doc$getBody$paragrap, _doc$getBody, _doc$getBody$dataStre, _doc$getBody2;
1462
+ var _doc$getBody, _doc$getBody2;
1467
1463
  const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
1468
1464
  const range = accessor.get(_univerjs_docs.DocSelectionManagerService).getActiveTextRange();
1469
1465
  const doc = instanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
1470
1466
  if (!range || !range.collapsed || !doc || range.segmentId) return false;
1471
- return _univerjs_core.BuildTextUtils.range.getParagraphsInRange(range, (_doc$getBody$paragrap = (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.paragraphs) !== null && _doc$getBody$paragrap !== void 0 ? _doc$getBody$paragrap : [], (_doc$getBody$dataStre = (_doc$getBody2 = doc.getBody()) === null || _doc$getBody2 === void 0 ? void 0 : _doc$getBody2.dataStream) !== null && _doc$getBody$dataStre !== void 0 ? _doc$getBody$dataStre : "")[0];
1467
+ return _univerjs_core.BuildTextUtils.range.getParagraphsInRange(range, ((_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.paragraphs) ?? [], ((_doc$getBody2 = doc.getBody()) === null || _doc$getBody2 === void 0 ? void 0 : _doc$getBody2.dataStream) ?? "")[0];
1472
1468
  }
1473
1469
 
1474
1470
  //#endregion
@@ -1477,7 +1473,6 @@ const DeleteCustomBlockCommand = {
1477
1473
  id: "doc.command.delete-custom-block",
1478
1474
  type: _univerjs_core.CommandType.COMMAND,
1479
1475
  handler: async (accessor, params) => {
1480
- var _documentDataModel$ge;
1481
1476
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
1482
1477
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
1483
1478
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -1514,7 +1509,7 @@ const DeleteCustomBlockCommand = {
1514
1509
  });
1515
1510
  const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
1516
1511
  rawActions.push(jsonX.editOp(textX.serialize(), path));
1517
- const drawing = ((_documentDataModel$ge = documentDataModel.getDrawings()) !== null && _documentDataModel$ge !== void 0 ? _documentDataModel$ge : {})[drawingId];
1512
+ const drawing = (documentDataModel.getDrawings() ?? {})[drawingId];
1518
1513
  const drawingIndex = documentDataModel.getDrawingsOrder().indexOf(drawingId);
1519
1514
  const removeDrawingAction = jsonX.removeOp(["drawings", drawingId], drawing);
1520
1515
  const removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], drawingId);
@@ -1698,11 +1693,11 @@ function getCursorWhenDelete(textRanges, rectRanges) {
1698
1693
  return cursor;
1699
1694
  }
1700
1695
  function isDeleteOffsetInsideBlockRange(body, offset) {
1701
- var _body$blockRanges$som, _body$blockRanges;
1702
- return (_body$blockRanges$som = (_body$blockRanges = body.blockRanges) === null || _body$blockRanges === void 0 ? void 0 : _body$blockRanges.some((blockRange) => {
1696
+ var _body$blockRanges;
1697
+ return ((_body$blockRanges = body.blockRanges) === null || _body$blockRanges === void 0 ? void 0 : _body$blockRanges.some((blockRange) => {
1703
1698
  const interval = (0, _univerjs_core.getBlockRangeInterval)(blockRange);
1704
1699
  return interval.startOffset < offset && offset < interval.endOffset - 1;
1705
- })) !== null && _body$blockRanges$som !== void 0 ? _body$blockRanges$som : false;
1700
+ })) ?? false;
1706
1701
  }
1707
1702
  const DeleteLeftCommand = {
1708
1703
  id: "doc.command.delete-left",
@@ -1743,7 +1738,7 @@ const DeleteLeftCommand = {
1743
1738
  const { startOffset, collapsed } = actualRange;
1744
1739
  if (collapsed) {
1745
1740
  const emptyCenteredParagraph = getEmptyCenteredParagraphAtOffset(body, startOffset);
1746
- if (emptyCenteredParagraph != null) return resetEmptyCenteredParagraphAlignment(commandService, docDataModel, segmentId !== null && segmentId !== void 0 ? segmentId : "", emptyCenteredParagraph, style);
1741
+ if (emptyCenteredParagraph != null) return resetEmptyCenteredParagraphAlignment(commandService, docDataModel, segmentId ?? "", emptyCenteredParagraph, style);
1747
1742
  }
1748
1743
  const curGlyph = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage);
1749
1744
  const isBullet = (0, _univerjs_engine_render.hasListGlyph)(curGlyph);
@@ -1809,8 +1804,8 @@ const DeleteLeftCommand = {
1809
1804
  range: actualRange
1810
1805
  });
1811
1806
  } else if (preGlyph.streamType === "\b") {
1812
- var _docDataModel$getSnap, _preGlyph$drawingId, _docDataModel$getBody;
1813
- const drawing = (_docDataModel$getSnap = docDataModel.getSnapshot().drawings) === null || _docDataModel$getSnap === void 0 ? void 0 : _docDataModel$getSnap[(_preGlyph$drawingId = preGlyph.drawingId) !== null && _preGlyph$drawingId !== void 0 ? _preGlyph$drawingId : ""];
1807
+ var _docDataModel$getSnap, _docDataModel$getBody;
1808
+ const drawing = (_docDataModel$getSnap = docDataModel.getSnapshot().drawings) === null || _docDataModel$getSnap === void 0 ? void 0 : _docDataModel$getSnap[preGlyph.drawingId ?? ""];
1814
1809
  if (drawing == null) return true;
1815
1810
  const customBlock = (_docDataModel$getBody = docDataModel.getBody()) === null || _docDataModel$getBody === void 0 || (_docDataModel$getBody = _docDataModel$getBody.customBlocks) === null || _docDataModel$getBody === void 0 ? void 0 : _docDataModel$getBody.find((block) => block.blockId === preGlyph.drawingId);
1816
1811
  if (drawing.layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE || (customBlock === null || customBlock === void 0 ? void 0 : customBlock.blockType) === _univerjs_core.BlockType.CUSTOM) {
@@ -1895,7 +1890,7 @@ const DeleteRightCommand = {
1895
1890
  const { startOffset, endOffset, collapsed } = actualRange;
1896
1891
  if (collapsed) {
1897
1892
  const emptyCenteredParagraph = getEmptyCenteredParagraphAtOffset(body, startOffset);
1898
- if (emptyCenteredParagraph != null) return resetEmptyCenteredParagraphAlignment(commandService, docDataModel, segmentId !== null && segmentId !== void 0 ? segmentId : "", emptyCenteredParagraph, style);
1893
+ if (emptyCenteredParagraph != null) return resetEmptyCenteredParagraphAlignment(commandService, docDataModel, segmentId ?? "", emptyCenteredParagraph, style);
1899
1894
  }
1900
1895
  if (startOffset === body.dataStream.length - 2 && collapsed) return true;
1901
1896
  let result = false;
@@ -1908,8 +1903,8 @@ const DeleteRightCommand = {
1908
1903
  range: activeRange
1909
1904
  });
1910
1905
  else if (needDeleteGlyph.streamType === "\b") {
1911
- var _docDataModel$getSnap2, _needDeleteGlyph$draw;
1912
- const drawing = (_docDataModel$getSnap2 = docDataModel.getSnapshot().drawings) === null || _docDataModel$getSnap2 === void 0 ? void 0 : _docDataModel$getSnap2[(_needDeleteGlyph$draw = needDeleteGlyph.drawingId) !== null && _needDeleteGlyph$draw !== void 0 ? _needDeleteGlyph$draw : ""];
1906
+ var _docDataModel$getSnap2;
1907
+ const drawing = (_docDataModel$getSnap2 = docDataModel.getSnapshot().drawings) === null || _docDataModel$getSnap2 === void 0 ? void 0 : _docDataModel$getSnap2[needDeleteGlyph.drawingId ?? ""];
1913
1908
  if (drawing == null) return true;
1914
1909
  if (drawing.layoutType === _univerjs_core.PositionedObjectLayoutType.INLINE) {
1915
1910
  const unitId = docDataModel.getUnitId();
@@ -1972,8 +1967,7 @@ function getTextRangesWhenDelete(activeRange, ranges) {
1972
1967
  }];
1973
1968
  }
1974
1969
  function getEmptyCenteredParagraphAtOffset(body, offset) {
1975
- var _body$paragraphs2;
1976
- const paragraphs = (_body$paragraphs2 = body.paragraphs) !== null && _body$paragraphs2 !== void 0 ? _body$paragraphs2 : [];
1970
+ const paragraphs = body.paragraphs ?? [];
1977
1971
  for (let i = 0; i < paragraphs.length; i++) {
1978
1972
  var _paragraph$paragraphS2;
1979
1973
  const paragraph = paragraphs[i];
@@ -2017,12 +2011,12 @@ const DeleteCurrentParagraphCommand = {
2017
2011
  priority: 0,
2018
2012
  type: _univerjs_core.CommandType.COMMAND,
2019
2013
  handler: async (accessor) => {
2020
- var _docDataModel$getBody2, _docDataModel$getBody3;
2014
+ var _docDataModel$getBody2;
2021
2015
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
2022
2016
  const commandService = accessor.get(_univerjs_core.ICommandService);
2023
2017
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
2024
2018
  if (!docDataModel) return false;
2025
- const dataStream = (_docDataModel$getBody2 = (_docDataModel$getBody3 = docDataModel.getBody()) === null || _docDataModel$getBody3 === void 0 ? void 0 : _docDataModel$getBody3.dataStream) !== null && _docDataModel$getBody2 !== void 0 ? _docDataModel$getBody2 : "";
2019
+ const dataStream = ((_docDataModel$getBody2 = docDataModel.getBody()) === null || _docDataModel$getBody2 === void 0 ? void 0 : _docDataModel$getBody2.dataStream) ?? "";
2026
2020
  const paragraph = getCurrentParagraph(accessor);
2027
2021
  if (!paragraph) return false;
2028
2022
  const actions = _univerjs_core.BuildTextUtils.selection.delete([{
@@ -2197,9 +2191,9 @@ var HtmlToUDMService = class HtmlToUDMService {
2197
2191
  return (0, _univerjs_core.createSectionId)(new Set((_body$sectionBreaks = body.sectionBreaks) === null || _body$sectionBreaks === void 0 ? void 0 : _body$sectionBreaks.map((sectionBreak) => sectionBreak.sectionId)));
2198
2192
  }
2199
2193
  convert(html, metaConfig = {}) {
2200
- var _pastePlugin$preproce, _pastePlugin$preproce2, _metaConfig$unitId;
2194
+ var _pastePlugin$preproce;
2201
2195
  const pastePlugin = HtmlToUDMService._pluginList.find((plugin) => plugin.checkPasteType(html));
2202
- const dom = parseToDom((_pastePlugin$preproce = pastePlugin === null || pastePlugin === void 0 || (_pastePlugin$preproce2 = pastePlugin.preprocessHtml) === null || _pastePlugin$preproce2 === void 0 ? void 0 : _pastePlugin$preproce2.call(pastePlugin, html)) !== null && _pastePlugin$preproce !== void 0 ? _pastePlugin$preproce : html);
2196
+ const dom = parseToDom((pastePlugin === null || pastePlugin === void 0 || (_pastePlugin$preproce = pastePlugin.preprocessHtml) === null || _pastePlugin$preproce === void 0 ? void 0 : _pastePlugin$preproce.call(pastePlugin, html)) ?? html);
2203
2197
  const docData = {
2204
2198
  body: {
2205
2199
  dataStream: "",
@@ -2210,7 +2204,7 @@ var HtmlToUDMService = class HtmlToUDMService {
2210
2204
  customBlocks: []
2211
2205
  },
2212
2206
  tableSource: {},
2213
- id: (_metaConfig$unitId = metaConfig === null || metaConfig === void 0 ? void 0 : metaConfig.unitId) !== null && _metaConfig$unitId !== void 0 ? _metaConfig$unitId : ""
2207
+ id: (metaConfig === null || metaConfig === void 0 ? void 0 : metaConfig.unitId) ?? ""
2214
2208
  };
2215
2209
  if (pastePlugin) {
2216
2210
  this._styleRules = [...pastePlugin.stylesRules];
@@ -2240,16 +2234,15 @@ var HtmlToUDMService = class HtmlToUDMService {
2240
2234
  ts: style
2241
2235
  });
2242
2236
  } else if (node.nodeName === "IMG") {
2243
- var _element$dataset$imag;
2244
2237
  const element = node;
2245
- const imageSourceType = (_element$dataset$imag = element.dataset.imageSourceType) !== null && _element$dataset$imag !== void 0 ? _element$dataset$imag : element.src ? inferImageSourceType(element.src) : void 0;
2238
+ const imageSourceType = element.dataset.imageSourceType ?? (element.src ? inferImageSourceType(element.src) : void 0);
2246
2239
  const source = imageSourceType === _univerjs_core.ImageSourceType.UUID ? element.dataset.source : element.src;
2247
2240
  if (source && imageSourceType) {
2248
- var _readImageSize, _readImageSize2, _readCssSize, _readCssSize2, _doc$body;
2249
- const width = (_readImageSize = readImageSize(element, "width")) !== null && _readImageSize !== void 0 ? _readImageSize : 100;
2250
- const height = (_readImageSize2 = readImageSize(element, "height")) !== null && _readImageSize2 !== void 0 ? _readImageSize2 : 100;
2251
- const docTransformWidth = (_readCssSize = readCssSize(element.dataset.docTransformWidth || null, null, "width")) !== null && _readCssSize !== void 0 ? _readCssSize : width;
2252
- const docTransformHeight = (_readCssSize2 = readCssSize(element.dataset.docTransformHeight || null, null, "height")) !== null && _readCssSize2 !== void 0 ? _readCssSize2 : height;
2241
+ var _doc$body;
2242
+ const width = readImageSize(element, "width") ?? 100;
2243
+ const height = readImageSize(element, "height") ?? 100;
2244
+ const docTransformWidth = readCssSize(element.dataset.docTransformWidth || null, null, "width") ?? width;
2245
+ const docTransformHeight = readCssSize(element.dataset.docTransformHeight || null, null, "height") ?? height;
2253
2246
  const id = (0, _univerjs_core.generateRandomId)(6);
2254
2247
  (_doc$body = doc.body) === null || _doc$body === void 0 || (_doc$body = _doc$body.customBlocks) === null || _doc$body === void 0 || _doc$body.push({
2255
2248
  startIndex: body.dataStream.length,
@@ -2307,14 +2300,13 @@ var HtmlToUDMService = class HtmlToUDMService {
2307
2300
  }
2308
2301
  }
2309
2302
  _processCodeBlock(node, doc) {
2310
- var _node$textContent, _body$blockRanges;
2311
2303
  if (node.tagName.toUpperCase() !== "PRE") return false;
2312
2304
  const body = doc.body;
2313
2305
  const startIndex = body.dataStream.length;
2314
- const text = (_node$textContent = node.textContent) !== null && _node$textContent !== void 0 ? _node$textContent : "";
2306
+ const text = node.textContent ?? "";
2315
2307
  body.dataStream += text;
2316
2308
  this._appendParagraph(doc, node);
2317
- (_body$blockRanges = body.blockRanges) !== null && _body$blockRanges !== void 0 || (body.blockRanges = []);
2309
+ body.blockRanges ??= [];
2318
2310
  body.blockRanges.push({
2319
2311
  blockId: (0, _univerjs_core.generateRandomId)(6),
2320
2312
  blockType: _univerjs_core.DocumentBlockRangeType.CODE,
@@ -2328,11 +2320,10 @@ var HtmlToUDMService = class HtmlToUDMService {
2328
2320
  return doc.body.dataStream.length;
2329
2321
  }
2330
2322
  _processAfterStructuredBlock(node, doc, startIndex) {
2331
- var _body$blockRanges2;
2332
2323
  const blockType = getStructuredBlockType(node);
2333
2324
  const body = doc.body;
2334
2325
  if (!blockType || startIndex == null || body.dataStream.length <= startIndex) return;
2335
- (_body$blockRanges2 = body.blockRanges) !== null && _body$blockRanges2 !== void 0 || (body.blockRanges = []);
2326
+ body.blockRanges ??= [];
2336
2327
  body.blockRanges.push({
2337
2328
  blockId: (0, _univerjs_core.generateRandomId)(6),
2338
2329
  blockType,
@@ -2365,10 +2356,9 @@ var HtmlToUDMService = class HtmlToUDMService {
2365
2356
  this._appendParagraph(doc, node);
2366
2357
  }
2367
2358
  _appendParagraph(doc, node) {
2368
- var _body$paragraphs2, _this$_listStack;
2369
2359
  const body = doc.body;
2370
2360
  if (body.dataStream[this._lastParagraphIndex] === "\r" && this._lastParagraphIndex === body.dataStream.length - 1) return;
2371
- (_body$paragraphs2 = body.paragraphs) !== null && _body$paragraphs2 !== void 0 || (body.paragraphs = []);
2361
+ body.paragraphs ??= [];
2372
2362
  const paragraph = {
2373
2363
  startIndex: body.dataStream.length,
2374
2364
  paragraphId: this._createParagraphId(body)
@@ -2379,7 +2369,7 @@ var HtmlToUDMService = class HtmlToUDMService {
2379
2369
  headingId: (0, _univerjs_core.generateRandomId)(6),
2380
2370
  namedStyleType: heading
2381
2371
  };
2382
- const listContext = (_this$_listStack = this._listStack[this._listStack.length - 1]) !== null && _this$_listStack !== void 0 ? _this$_listStack : extractWordListInfo(node);
2372
+ const listContext = this._listStack[this._listStack.length - 1] ?? extractWordListInfo(node);
2383
2373
  if (listContext) {
2384
2374
  paragraph.bullet = {
2385
2375
  listId: listContext.listId,
@@ -2396,7 +2386,7 @@ var HtmlToUDMService = class HtmlToUDMService {
2396
2386
  var _doc$body2;
2397
2387
  const htmlListContext = this._listStack[this._listStack.length - 1];
2398
2388
  const wordListContext = extractWordListInfo(node);
2399
- const listContext = htmlListContext !== null && htmlListContext !== void 0 ? htmlListContext : wordListContext;
2389
+ const listContext = htmlListContext ?? wordListContext;
2400
2390
  const paragraph = (_doc$body2 = doc.body) === null || _doc$body2 === void 0 || (_doc$body2 = _doc$body2.paragraphs) === null || _doc$body2 === void 0 ? void 0 : _doc$body2[doc.body.paragraphs.length - 1];
2401
2391
  if (!listContext || !paragraph) return;
2402
2392
  paragraph.bullet = {
@@ -2407,20 +2397,18 @@ var HtmlToUDMService = class HtmlToUDMService {
2407
2397
  if (wordListContext) paragraph.startIndex -= stripListMarkerFromCurrentParagraph(doc.body);
2408
2398
  }
2409
2399
  _processHtmlTable(node, doc) {
2410
- var _doc$tableSource, _body$tables, _body$sectionBreaks2;
2411
2400
  const body = doc.body;
2412
2401
  if (body.dataStream[body.dataStream.length - 1] !== "\r") {
2413
- var _body$paragraphs3;
2414
2402
  body.dataStream += "\r";
2415
- (_body$paragraphs3 = body.paragraphs) !== null && _body$paragraphs3 !== void 0 || (body.paragraphs = []);
2403
+ body.paragraphs ??= [];
2416
2404
  body.paragraphs.push({
2417
2405
  startIndex: body.dataStream.length - 1,
2418
2406
  paragraphId: this._createParagraphId(body)
2419
2407
  });
2420
2408
  }
2421
- (_doc$tableSource = doc.tableSource) !== null && _doc$tableSource !== void 0 || (doc.tableSource = {});
2422
- (_body$tables = body.tables) !== null && _body$tables !== void 0 || (body.tables = []);
2423
- (_body$sectionBreaks2 = body.sectionBreaks) !== null && _body$sectionBreaks2 !== void 0 || (body.sectionBreaks = []);
2409
+ doc.tableSource ??= {};
2410
+ body.tables ??= [];
2411
+ body.sectionBreaks ??= [];
2424
2412
  const rows = collectHtmlTableRows(node);
2425
2413
  const grid = buildHtmlTableGrid(rows);
2426
2414
  const columnCount = Math.max(1, ...grid.map((row) => row.length));
@@ -2431,7 +2419,7 @@ var HtmlToUDMService = class HtmlToUDMService {
2431
2419
  table.tableColumns = columnWidths.map((width) => getTableColumn(width));
2432
2420
  table.size = {
2433
2421
  type: _univerjs_core.TableSizeType.SPECIFIED,
2434
- width: { v: tableWidth !== null && tableWidth !== void 0 ? tableWidth : table.tableColumns.reduce((sum, column) => sum + column.size.width.v, 0) }
2422
+ width: { v: tableWidth ?? table.tableColumns.reduce((sum, column) => sum + column.size.width.v, 0) }
2435
2423
  };
2436
2424
  const startIndex = body.dataStream.length;
2437
2425
  body.dataStream += _univerjs_core.DataStreamTreeTokenType.TABLE_START;
@@ -2446,8 +2434,7 @@ var HtmlToUDMService = class HtmlToUDMService {
2446
2434
  table.tableRows.push(tableRow);
2447
2435
  body.dataStream += _univerjs_core.DataStreamTreeTokenType.TABLE_ROW_START;
2448
2436
  for (let columnIndex = 0; columnIndex < columnCount; columnIndex++) {
2449
- var _row$columnIndex;
2450
- const parsedCell = (_row$columnIndex = row[columnIndex]) !== null && _row$columnIndex !== void 0 ? _row$columnIndex : {
2437
+ const parsedCell = row[columnIndex] ?? {
2451
2438
  element: null,
2452
2439
  rowSpan: 1,
2453
2440
  colSpan: 1,
@@ -2472,15 +2459,11 @@ var HtmlToUDMService = class HtmlToUDMService {
2472
2459
  });
2473
2460
  }
2474
2461
  _appendHtmlTableCell(cell, doc) {
2475
- var _body$sectionBreaks3;
2476
2462
  const body = doc.body;
2477
2463
  body.dataStream += _univerjs_core.DataStreamTreeTokenType.TABLE_CELL_START;
2478
2464
  if (cell.element && !cell.covered) this._process(cell.element, cell.element.childNodes, doc);
2479
- if (body.dataStream[body.dataStream.length - 1] !== "\r") {
2480
- var _cell$element;
2481
- this._appendParagraph(doc, (_cell$element = cell.element) !== null && _cell$element !== void 0 ? _cell$element : document.createElement("td"));
2482
- }
2483
- (_body$sectionBreaks3 = body.sectionBreaks) !== null && _body$sectionBreaks3 !== void 0 || (body.sectionBreaks = []);
2465
+ if (body.dataStream[body.dataStream.length - 1] !== "\r") this._appendParagraph(doc, cell.element ?? document.createElement("td"));
2466
+ body.sectionBreaks ??= [];
2484
2467
  body.sectionBreaks.push({
2485
2468
  sectionId: this._createSectionId(body),
2486
2469
  startIndex: body.dataStream.length
@@ -2493,10 +2476,10 @@ var HtmlToUDMService = class HtmlToUDMService {
2493
2476
  switch (tagName) {
2494
2477
  case "TABLE": {
2495
2478
  if (body.dataStream[body.dataStream.length - 1] !== "\r") {
2496
- var _body$paragraphs4;
2479
+ var _body$paragraphs2;
2497
2480
  body.dataStream += "\r";
2498
2481
  if (body.paragraphs == null) body.paragraphs = [];
2499
- (_body$paragraphs4 = body.paragraphs) === null || _body$paragraphs4 === void 0 || _body$paragraphs4.push({
2482
+ (_body$paragraphs2 = body.paragraphs) === null || _body$paragraphs2 === void 0 || _body$paragraphs2.push({
2500
2483
  startIndex: body.dataStream.length - 1,
2501
2484
  paragraphId: this._createParagraphId(body)
2502
2485
  });
@@ -2550,16 +2533,16 @@ var HtmlToUDMService = class HtmlToUDMService {
2550
2533
  body.dataStream += _univerjs_core.DataStreamTreeTokenType.TABLE_ROW_END;
2551
2534
  break;
2552
2535
  case "TD":
2553
- var _body$sectionBreaks4;
2536
+ var _body$sectionBreaks2;
2554
2537
  if (body.dataStream[body.dataStream.length - 1] !== "\r") {
2555
- var _body$paragraphs5;
2556
- (_body$paragraphs5 = body.paragraphs) === null || _body$paragraphs5 === void 0 || _body$paragraphs5.push({
2538
+ var _body$paragraphs3;
2539
+ (_body$paragraphs3 = body.paragraphs) === null || _body$paragraphs3 === void 0 || _body$paragraphs3.push({
2557
2540
  startIndex: body.dataStream.length,
2558
2541
  paragraphId: this._createParagraphId(body)
2559
2542
  });
2560
2543
  body.dataStream += "\r";
2561
2544
  }
2562
- (_body$sectionBreaks4 = body.sectionBreaks) === null || _body$sectionBreaks4 === void 0 || _body$sectionBreaks4.push({
2545
+ (_body$sectionBreaks2 = body.sectionBreaks) === null || _body$sectionBreaks2 === void 0 || _body$sectionBreaks2.push({
2563
2546
  sectionId: this._createSectionId(body),
2564
2547
  startIndex: body.dataStream.length
2565
2548
  });
@@ -2574,14 +2557,13 @@ var HtmlToUDMService = class HtmlToUDMService {
2574
2557
  const body = doc.body;
2575
2558
  const element = node;
2576
2559
  if (element.tagName.toUpperCase() === "A") {
2577
- var _body$customRanges, _element$dataset$rang;
2578
2560
  const href = element.href;
2579
2561
  if (!(0, _univerjs_core.isSafeUrl)(href)) return;
2580
- body.customRanges = (_body$customRanges = body.customRanges) !== null && _body$customRanges !== void 0 ? _body$customRanges : [];
2562
+ body.customRanges = body.customRanges ?? [];
2581
2563
  body.customRanges.push({
2582
2564
  startIndex: start,
2583
2565
  endIndex: body.dataStream.length - 1,
2584
- rangeId: (_element$dataset$rang = element.dataset.rangeid) !== null && _element$dataset$rang !== void 0 ? _element$dataset$rang : (0, _univerjs_core.generateRandomId)(),
2566
+ rangeId: element.dataset.rangeid ?? (0, _univerjs_core.generateRandomId)(),
2585
2567
  rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
2586
2568
  properties: { url: href }
2587
2569
  });
@@ -2599,8 +2581,7 @@ function collectHtmlTableRows(table) {
2599
2581
  return rows;
2600
2582
  }
2601
2583
  function normalizeTextNode(node) {
2602
- var _node$nodeValue;
2603
- const value = (_node$nodeValue = node.nodeValue) !== null && _node$nodeValue !== void 0 ? _node$nodeValue : "";
2584
+ const value = node.nodeValue ?? "";
2604
2585
  if (value.includes(WORD_SPACE_PLACEHOLDER)) return value.replace(/[\t\u00A0]+/g, " ").replace(/[ \r\n]+/g, " ").replace(/ *\uE000+ */g, (match) => " ".repeat(Array.from(match).filter((char) => char === WORD_SPACE_PLACEHOLDER).length));
2605
2586
  const hasExplicitSpacing = /[\t\u00A0]/.test(value);
2606
2587
  const text = value.replace(/[\t\u00A0]+/g, " ").replace(/[ \r\n]+/g, " ");
@@ -2614,9 +2595,9 @@ function inferImageSourceType(src) {
2614
2595
  function hasTextSibling(node, direction) {
2615
2596
  let current = node;
2616
2597
  while (current) {
2617
- var _current$nodeValue, _current$textContent;
2598
+ var _current$nodeValue;
2618
2599
  if (current.nodeType === Node.TEXT_NODE && ((_current$nodeValue = current.nodeValue) === null || _current$nodeValue === void 0 ? void 0 : _current$nodeValue.trim())) return true;
2619
- if (current.nodeType === Node.ELEMENT_NODE && ((_current$textContent = current.textContent) !== null && _current$textContent !== void 0 ? _current$textContent : "").trim()) return true;
2600
+ if (current.nodeType === Node.ELEMENT_NODE && (current.textContent ?? "").trim()) return true;
2620
2601
  current = direction === "previous" ? current.previousSibling : current.nextSibling;
2621
2602
  }
2622
2603
  return false;
@@ -2628,7 +2609,6 @@ function buildHtmlTableGrid(rows) {
2628
2609
  const parsedRow = [];
2629
2610
  let columnIndex = 0;
2630
2611
  getHtmlTableCells(row).forEach((cellElement) => {
2631
- var _cellElement$getAttri, _cellElement$getAttri2;
2632
2612
  while (occupied.has(`${rowIndex}:${columnIndex}`)) {
2633
2613
  parsedRow[columnIndex] = {
2634
2614
  element: null,
@@ -2638,8 +2618,8 @@ function buildHtmlTableGrid(rows) {
2638
2618
  };
2639
2619
  columnIndex++;
2640
2620
  }
2641
- const rowSpan = Math.max(1, Number((_cellElement$getAttri = cellElement.getAttribute("rowspan")) !== null && _cellElement$getAttri !== void 0 ? _cellElement$getAttri : 1));
2642
- const colSpan = Math.max(1, Number((_cellElement$getAttri2 = cellElement.getAttribute("colspan")) !== null && _cellElement$getAttri2 !== void 0 ? _cellElement$getAttri2 : 1));
2621
+ const rowSpan = Math.max(1, Number(cellElement.getAttribute("rowspan") ?? 1));
2622
+ const colSpan = Math.max(1, Number(cellElement.getAttribute("colspan") ?? 1));
2643
2623
  parsedRow[columnIndex] = {
2644
2624
  element: cellElement,
2645
2625
  rowSpan,
@@ -2701,20 +2681,19 @@ function collectHtmlTableColumnWidths(table, grid, columnCount) {
2701
2681
  }
2702
2682
  function resolveHtmlTableColumnWidths(table, grid, columnCount, tableWidth) {
2703
2683
  const explicitWidths = collectHtmlTableColumnWidths(table, grid, columnCount);
2704
- const fallbackTableWidth = tableWidth !== null && tableWidth !== void 0 ? tableWidth : DEFAULT_TABLE_WIDTH;
2705
- const explicitTotal = explicitWidths.reduce((sum, width) => sum + (width !== null && width !== void 0 ? width : 0), 0);
2684
+ const fallbackTableWidth = tableWidth ?? DEFAULT_TABLE_WIDTH;
2685
+ const explicitTotal = explicitWidths.reduce((sum, width) => sum + (width ?? 0), 0);
2706
2686
  const missingCount = explicitWidths.filter((width) => width == null).length;
2707
2687
  const fallbackColumnWidth = missingCount ? Math.max((fallbackTableWidth - explicitTotal) / missingCount, 1) : fallbackTableWidth / columnCount;
2708
- return explicitWidths.map((width) => width !== null && width !== void 0 ? width : roundCssNumber$1(fallbackColumnWidth));
2688
+ return explicitWidths.map((width) => width ?? roundCssNumber$1(fallbackColumnWidth));
2709
2689
  }
2710
2690
  function createTableCellFromHtml(element, rowSpan, colSpan) {
2711
- var _element$getAttribute, _ref, _readCssColor;
2712
2691
  const cell = getEmptyTableCell();
2713
2692
  if (rowSpan > 1) cell.rowSpan = rowSpan;
2714
2693
  if (colSpan > 1) cell.columnSpan = colSpan;
2715
- const style = (_element$getAttribute = element.getAttribute("style")) !== null && _element$getAttribute !== void 0 ? _element$getAttribute : "";
2694
+ const style = element.getAttribute("style") ?? "";
2716
2695
  const width = readCssSize(element.getAttribute("width"), style, "width");
2717
- const backgroundColor = (_ref = (_readCssColor = readCssColor(style, "background-color")) !== null && _readCssColor !== void 0 ? _readCssColor : readCssColor(style, "background")) !== null && _ref !== void 0 ? _ref : readHtmlAttributeColor(element, "bgcolor");
2696
+ const backgroundColor = readCssColor(style, "background-color") ?? readCssColor(style, "background") ?? readHtmlAttributeColor(element, "bgcolor");
2718
2697
  const borderTop = createTableCellBorder(style, "top");
2719
2698
  const borderRight = createTableCellBorder(style, "right");
2720
2699
  const borderBottom = createTableCellBorder(style, "bottom");
@@ -2731,14 +2710,14 @@ function createTableCellFromHtml(element, rowSpan, colSpan) {
2731
2710
  return cell;
2732
2711
  }
2733
2712
  function createTableCellBorder(style, side) {
2734
- var _ref2, _ref3, _ref4, _readCssColor2, _sideStyle$match, _readCssValue, _ref5, _ref6, _readCssLengthValue, _normalizeCssColor;
2713
+ var _sideStyle$match, _readCssValue;
2735
2714
  const sideStyle = readCssValue(style, `border-${side}`);
2736
- const color = (_ref2 = (_ref3 = (_ref4 = (_readCssColor2 = readCssColor(style, `border-${side}-color`)) !== null && _readCssColor2 !== void 0 ? _readCssColor2 : normalizeCssColor$1(sideStyle === null || sideStyle === void 0 || (_sideStyle$match = sideStyle.match(/(#[0-9a-f]{3,8}|rgb\([^)]+\))/i)) === null || _sideStyle$match === void 0 ? void 0 : _sideStyle$match[1])) !== null && _ref4 !== void 0 ? _ref4 : readCssColor(style, "border-color")) !== null && _ref3 !== void 0 ? _ref3 : normalizeCssColor$1((_readCssValue = readCssValue(style, "border")) === null || _readCssValue === void 0 || (_readCssValue = _readCssValue.match(/(#[0-9a-f]{3,8}|rgb\([^)]+\))/i)) === null || _readCssValue === void 0 ? void 0 : _readCssValue[1])) !== null && _ref2 !== void 0 ? _ref2 : readNamedBorderColor(style);
2737
- const width = (_ref5 = (_ref6 = (_readCssLengthValue = readCssLengthValue(readCssValue(style, `border-${side}-width`))) !== null && _readCssLengthValue !== void 0 ? _readCssLengthValue : readCssLengthValue(sideStyle)) !== null && _ref6 !== void 0 ? _ref6 : readCssLengthValue(readCssValue(style, "border-width"))) !== null && _ref5 !== void 0 ? _ref5 : readCssLengthValue(readCssValue(style, "border"));
2715
+ const color = readCssColor(style, `border-${side}-color`) ?? normalizeCssColor$1(sideStyle === null || sideStyle === void 0 || (_sideStyle$match = sideStyle.match(/(#[0-9a-f]{3,8}|rgb\([^)]+\))/i)) === null || _sideStyle$match === void 0 ? void 0 : _sideStyle$match[1]) ?? readCssColor(style, "border-color") ?? normalizeCssColor$1((_readCssValue = readCssValue(style, "border")) === null || _readCssValue === void 0 || (_readCssValue = _readCssValue.match(/(#[0-9a-f]{3,8}|rgb\([^)]+\))/i)) === null || _readCssValue === void 0 ? void 0 : _readCssValue[1]) ?? readNamedBorderColor(style);
2716
+ const width = readCssLengthValue(readCssValue(style, `border-${side}-width`)) ?? readCssLengthValue(sideStyle) ?? readCssLengthValue(readCssValue(style, "border-width")) ?? readCssLengthValue(readCssValue(style, "border"));
2738
2717
  if (!color && width == null) return;
2739
2718
  return {
2740
- color: { rgb: (_normalizeCssColor = normalizeCssColor$1(color)) !== null && _normalizeCssColor !== void 0 ? _normalizeCssColor : "#1f1f1f" },
2741
- width: { v: width !== null && width !== void 0 ? width : 1 }
2719
+ color: { rgb: normalizeCssColor$1(color) ?? "#1f1f1f" },
2720
+ width: { v: width ?? 1 }
2742
2721
  };
2743
2722
  }
2744
2723
  function readNamedBorderColor(style) {
@@ -2782,19 +2761,17 @@ function readCssValue(style, property) {
2782
2761
  }
2783
2762
  function readCssSize(attributeValue, style, property) {
2784
2763
  var _readCssValue2;
2785
- const styleMatch = (_readCssValue2 = readCssValue(style !== null && style !== void 0 ? style : "", property)) === null || _readCssValue2 === void 0 ? void 0 : _readCssValue2.match(/^([0-9.]+)\s*(px|pt|in|cm|mm)?$/i);
2764
+ const styleMatch = (_readCssValue2 = readCssValue(style ?? "", property)) === null || _readCssValue2 === void 0 ? void 0 : _readCssValue2.match(/^([0-9.]+)\s*(px|pt|in|cm|mm)?$/i);
2786
2765
  if (styleMatch) return toPixels(Number(styleMatch[1]), styleMatch[2]);
2787
2766
  const attrMatch = attributeValue === null || attributeValue === void 0 ? void 0 : attributeValue.match(/([0-9.]+)\s*(px|pt|in|cm|mm)?/i);
2788
2767
  return attrMatch ? toPixels(Number(attrMatch[1]), attrMatch[2]) : void 0;
2789
2768
  }
2790
2769
  function readCssLengthValue(value) {
2791
- var _value$match;
2792
- const match = (_value$match = value === null || value === void 0 ? void 0 : value.match(/(?:^|\s)([0-9.]+)\s*(px|pt|in|cm|mm)(?=\s|$)/i)) !== null && _value$match !== void 0 ? _value$match : value === null || value === void 0 ? void 0 : value.match(/^\s*([0-9.]+)\s*$/);
2770
+ const match = (value === null || value === void 0 ? void 0 : value.match(/(?:^|\s)([0-9.]+)\s*(px|pt|in|cm|mm)(?=\s|$)/i)) ?? (value === null || value === void 0 ? void 0 : value.match(/^\s*([0-9.]+)\s*$/));
2793
2771
  return match ? toPixels(Number(match[1]), match[2]) : void 0;
2794
2772
  }
2795
2773
  function readImageSize(element, property) {
2796
- var _readCssSize3;
2797
- return (_readCssSize3 = readCssSize((property === "width" ? element.dataset.width : element.dataset.height) || null, null, property)) !== null && _readCssSize3 !== void 0 ? _readCssSize3 : readCssSize(element.getAttribute(property), element.getAttribute("style"), property);
2774
+ return readCssSize((property === "width" ? element.dataset.width : element.dataset.height) || null, null, property) ?? readCssSize(element.getAttribute(property), element.getAttribute("style"), property);
2798
2775
  }
2799
2776
  function toPixels(value, unit) {
2800
2777
  switch (unit === null || unit === void 0 ? void 0 : unit.toLowerCase()) {
@@ -2842,18 +2819,16 @@ function getHeadingNamedStyleType(node) {
2842
2819
  }
2843
2820
  }
2844
2821
  function extractWordListInfo(node) {
2845
- var _node$getAttribute;
2846
- const match = ((_node$getAttribute = node.getAttribute("style")) !== null && _node$getAttribute !== void 0 ? _node$getAttribute : "").match(/mso-list:\s*([^ ;]+)\s+level(\d+)/i);
2822
+ const match = (node.getAttribute("style") ?? "").match(/mso-list:\s*([^ ;]+)\s+level(\d+)/i);
2847
2823
  if (!match && !/MsoListParagraph/i.test(node.className)) return null;
2848
2824
  {
2849
- var _node$textContent2, _marker$, _match$, _match$2;
2850
- const marker = ((_node$textContent2 = node.textContent) !== null && _node$textContent2 !== void 0 ? _node$textContent2 : "").trim().match(/^([0-9]+[.)]|[a-zA-Z][.)]|[ivxlcdmIVXLCDM]+[.)]|[\u2022\u00B7\u25CF\u25CB\u25AA\u25AB-])/);
2851
- const markerText = (_marker$ = marker === null || marker === void 0 ? void 0 : marker[1]) !== null && _marker$ !== void 0 ? _marker$ : "";
2825
+ const marker = (node.textContent ?? "").trim().match(/^([0-9]+[.)]|[a-zA-Z][.)]|[ivxlcdmIVXLCDM]+[.)]|[\u2022\u00B7\u25CF\u25CB\u25AA\u25AB-])/);
2826
+ const markerText = (marker === null || marker === void 0 ? void 0 : marker[1]) ?? "";
2852
2827
  const ordered = Boolean(markerText && !/^[\u2022\u00B7\u25CF\u25CB\u25AA\u25AB-]$/.test(markerText));
2853
2828
  return {
2854
- listId: (_match$ = match === null || match === void 0 ? void 0 : match[1]) !== null && _match$ !== void 0 ? _match$ : "mso-list",
2829
+ listId: (match === null || match === void 0 ? void 0 : match[1]) ?? "mso-list",
2855
2830
  listType: ordered ? _univerjs_core.PresetListType.ORDER_LIST : _univerjs_core.PresetListType.BULLET_LIST,
2856
- nestingLevel: Math.max(0, Number((_match$2 = match === null || match === void 0 ? void 0 : match[2]) !== null && _match$2 !== void 0 ? _match$2 : 1) - 1)
2831
+ nestingLevel: Math.max(0, Number((match === null || match === void 0 ? void 0 : match[2]) ?? 1) - 1)
2857
2832
  };
2858
2833
  }
2859
2834
  }
@@ -3050,12 +3025,12 @@ function readMsoTabCount(attributes) {
3050
3025
  return Number.isFinite(count) ? count : void 0;
3051
3026
  }
3052
3027
  function countWordSpaces(content) {
3053
- var _content$match$length, _content$match, _text$match$reduce, _text$match, _text$replace$match$l, _text$replace$match;
3054
- const entitySpaceCount = (_content$match$length = (_content$match = content.match(/&nbsp;|&#160;|&#x0*a0;/gi)) === null || _content$match === void 0 ? void 0 : _content$match.length) !== null && _content$match$length !== void 0 ? _content$match$length : 0;
3028
+ var _content$match, _text$match, _text$replace$match;
3029
+ const entitySpaceCount = ((_content$match = content.match(/&nbsp;|&#160;|&#x0*a0;/gi)) === null || _content$match === void 0 ? void 0 : _content$match.length) ?? 0;
3055
3030
  const text = content.replace(/&nbsp;|&#160;|&#x0*a0;/gi, "\xA0").replace(/<[^>]*>/g, "");
3056
- const literalSpaceCount = (_text$match$reduce = (_text$match = text.match(/[\u00A0\t]/g)) === null || _text$match === void 0 ? void 0 : _text$match.reduce((count, char) => count + (char === " " ? WORD_TAB_WIDTH : 1), 0)) !== null && _text$match$reduce !== void 0 ? _text$match$reduce : 0;
3031
+ const literalSpaceCount = ((_text$match = text.match(/[\u00A0\t]/g)) === null || _text$match === void 0 ? void 0 : _text$match.reduce((count, char) => count + (char === " " ? WORD_TAB_WIDTH : 1), 0)) ?? 0;
3057
3032
  if (entitySpaceCount || literalSpaceCount) return literalSpaceCount;
3058
- return (_text$replace$match$l = (_text$replace$match = text.replace(/\r?\n/g, "").match(/ /g)) === null || _text$replace$match === void 0 ? void 0 : _text$replace$match.length) !== null && _text$replace$match$l !== void 0 ? _text$replace$match$l : 0;
3033
+ return ((_text$replace$match = text.replace(/\r?\n/g, "").match(/ /g)) === null || _text$replace$match === void 0 ? void 0 : _text$replace$match.length) ?? 0;
3059
3034
  }
3060
3035
 
3061
3036
  //#endregion
@@ -3128,26 +3103,22 @@ function createInternalClipboardDocDataList(docs) {
3128
3103
  if (docs.length === 1) return createInternalClipboardDocData(docs[0]);
3129
3104
  const merged = { body: { dataStream: "" } };
3130
3105
  for (const doc of docs) {
3131
- var _body$dataStream;
3132
3106
  const part = createInternalClipboardDocData(doc);
3133
3107
  const body = part.body;
3134
3108
  if (!body) continue;
3135
3109
  const offset = merged.body.dataStream.length;
3136
- merged.body.dataStream += (_body$dataStream = body.dataStream) !== null && _body$dataStream !== void 0 ? _body$dataStream : "";
3110
+ merged.body.dataStream += body.dataStream ?? "";
3137
3111
  appendOffsetRanges(merged.body, body, offset);
3138
3112
  if (part.tableSource) {
3139
- var _merged$tableSource;
3140
- (_merged$tableSource = merged.tableSource) !== null && _merged$tableSource !== void 0 || (merged.tableSource = {});
3113
+ merged.tableSource ??= {};
3141
3114
  Object.assign(merged.tableSource, part.tableSource);
3142
3115
  }
3143
3116
  if (part.lists) {
3144
- var _merged$lists;
3145
- (_merged$lists = merged.lists) !== null && _merged$lists !== void 0 || (merged.lists = {});
3117
+ merged.lists ??= {};
3146
3118
  Object.assign(merged.lists, part.lists);
3147
3119
  }
3148
3120
  if (part.drawings) {
3149
- var _merged$drawings;
3150
- (_merged$drawings = merged.drawings) !== null && _merged$drawings !== void 0 || (merged.drawings = {});
3121
+ merged.drawings ??= {};
3151
3122
  Object.assign(merged.drawings, part.drawings);
3152
3123
  }
3153
3124
  }
@@ -3182,8 +3153,7 @@ function wrapClipboardHtml(fragmentHtml) {
3182
3153
  function appendOffsetRanges(target, source, offset) {
3183
3154
  var _source$textRuns, _source$paragraphs, _source$sectionBreaks, _source$tables, _source$blockRanges, _source$customRanges, _source$customDecorat, _source$customBlocks;
3184
3155
  if ((_source$textRuns = source.textRuns) === null || _source$textRuns === void 0 ? void 0 : _source$textRuns.length) {
3185
- var _target$textRuns;
3186
- (_target$textRuns = target.textRuns) !== null && _target$textRuns !== void 0 || (target.textRuns = []);
3156
+ target.textRuns ??= [];
3187
3157
  target.textRuns.push(...source.textRuns.map((textRun) => ({
3188
3158
  ...textRun,
3189
3159
  st: textRun.st + offset,
@@ -3191,24 +3161,21 @@ function appendOffsetRanges(target, source, offset) {
3191
3161
  })));
3192
3162
  }
3193
3163
  if ((_source$paragraphs = source.paragraphs) === null || _source$paragraphs === void 0 ? void 0 : _source$paragraphs.length) {
3194
- var _target$paragraphs;
3195
- (_target$paragraphs = target.paragraphs) !== null && _target$paragraphs !== void 0 || (target.paragraphs = []);
3164
+ target.paragraphs ??= [];
3196
3165
  target.paragraphs.push(...source.paragraphs.map((paragraph) => ({
3197
3166
  ...paragraph,
3198
3167
  startIndex: paragraph.startIndex + offset
3199
3168
  })));
3200
3169
  }
3201
3170
  if ((_source$sectionBreaks = source.sectionBreaks) === null || _source$sectionBreaks === void 0 ? void 0 : _source$sectionBreaks.length) {
3202
- var _target$sectionBreaks;
3203
- (_target$sectionBreaks = target.sectionBreaks) !== null && _target$sectionBreaks !== void 0 || (target.sectionBreaks = []);
3171
+ target.sectionBreaks ??= [];
3204
3172
  target.sectionBreaks.push(...source.sectionBreaks.map((sectionBreak) => ({
3205
3173
  ...sectionBreak,
3206
3174
  startIndex: sectionBreak.startIndex + offset
3207
3175
  })));
3208
3176
  }
3209
3177
  if ((_source$tables = source.tables) === null || _source$tables === void 0 ? void 0 : _source$tables.length) {
3210
- var _target$tables;
3211
- (_target$tables = target.tables) !== null && _target$tables !== void 0 || (target.tables = []);
3178
+ target.tables ??= [];
3212
3179
  target.tables.push(...source.tables.map((table) => ({
3213
3180
  ...table,
3214
3181
  startIndex: table.startIndex + offset,
@@ -3216,8 +3183,7 @@ function appendOffsetRanges(target, source, offset) {
3216
3183
  })));
3217
3184
  }
3218
3185
  if ((_source$blockRanges = source.blockRanges) === null || _source$blockRanges === void 0 ? void 0 : _source$blockRanges.length) {
3219
- var _target$blockRanges;
3220
- (_target$blockRanges = target.blockRanges) !== null && _target$blockRanges !== void 0 || (target.blockRanges = []);
3186
+ target.blockRanges ??= [];
3221
3187
  target.blockRanges.push(...source.blockRanges.map((blockRange) => ({
3222
3188
  ...blockRange,
3223
3189
  startIndex: blockRange.startIndex + offset,
@@ -3225,8 +3191,7 @@ function appendOffsetRanges(target, source, offset) {
3225
3191
  })));
3226
3192
  }
3227
3193
  if ((_source$customRanges = source.customRanges) === null || _source$customRanges === void 0 ? void 0 : _source$customRanges.length) {
3228
- var _target$customRanges;
3229
- (_target$customRanges = target.customRanges) !== null && _target$customRanges !== void 0 || (target.customRanges = []);
3194
+ target.customRanges ??= [];
3230
3195
  target.customRanges.push(...source.customRanges.map((customRange) => ({
3231
3196
  ...customRange,
3232
3197
  startIndex: customRange.startIndex + offset,
@@ -3234,8 +3199,7 @@ function appendOffsetRanges(target, source, offset) {
3234
3199
  })));
3235
3200
  }
3236
3201
  if ((_source$customDecorat = source.customDecorations) === null || _source$customDecorat === void 0 ? void 0 : _source$customDecorat.length) {
3237
- var _target$customDecorat;
3238
- (_target$customDecorat = target.customDecorations) !== null && _target$customDecorat !== void 0 || (target.customDecorations = []);
3202
+ target.customDecorations ??= [];
3239
3203
  target.customDecorations.push(...source.customDecorations.map((customDecoration) => ({
3240
3204
  ...customDecoration,
3241
3205
  startIndex: customDecoration.startIndex + offset,
@@ -3243,8 +3207,7 @@ function appendOffsetRanges(target, source, offset) {
3243
3207
  })));
3244
3208
  }
3245
3209
  if ((_source$customBlocks = source.customBlocks) === null || _source$customBlocks === void 0 ? void 0 : _source$customBlocks.length) {
3246
- var _target$customBlocks;
3247
- (_target$customBlocks = target.customBlocks) !== null && _target$customBlocks !== void 0 || (target.customBlocks = []);
3210
+ target.customBlocks ??= [];
3248
3211
  target.customBlocks.push(...source.customBlocks.map((customBlock) => ({
3249
3212
  ...customBlock,
3250
3213
  startIndex: customBlock.startIndex + offset
@@ -3291,7 +3254,7 @@ function covertTextRunToHtml(dataStream, textRun) {
3291
3254
  if ((ul === null || ul === void 0 ? void 0 : ul.s) === _univerjs_core.BooleanNumber.TRUE) html = `<u>${html}</u>`;
3292
3255
  if ((st === null || st === void 0 ? void 0 : st.s) === _univerjs_core.BooleanNumber.TRUE) html = `<s>${html}</s>`;
3293
3256
  if (bl === _univerjs_core.BooleanNumber.TRUE) html = `<strong>${html}</strong>`;
3294
- style.push(`font-family: ${ff !== null && ff !== void 0 ? ff : DEFAULT_CLIPBOARD_FONT_FAMILY}`);
3257
+ style.push(`font-family: ${ff ?? DEFAULT_CLIPBOARD_FONT_FAMILY}`);
3295
3258
  if (cl === null || cl === void 0 ? void 0 : cl.rgb) style.push(`color: ${normalizeCssColor(cl.rgb)}`);
3296
3259
  if (fs) style.push(`font-size: ${fs}pt`);
3297
3260
  if (ol) style.push("text-decoration: overline");
@@ -3368,8 +3331,8 @@ function getBodySliceHtml(doc, startIndex, endIndex) {
3368
3331
  const sliceHtml = handleCustomBlock(startIndex, endIndex + 1);
3369
3332
  switch (rangeType) {
3370
3333
  case _univerjs_core.CustomRangeType.HYPERLINK:
3371
- var _range$properties$url, _range$properties;
3372
- html += `<a data-rangeid="${rangeId}" href="${(_range$properties$url = (_range$properties = range.properties) === null || _range$properties === void 0 ? void 0 : _range$properties.url) !== null && _range$properties$url !== void 0 ? _range$properties$url : ""}">${sliceHtml.sliceHtml}</a>`;
3334
+ var _range$properties;
3335
+ html += `<a data-rangeid="${rangeId}" href="${((_range$properties = range.properties) === null || _range$properties === void 0 ? void 0 : _range$properties.url) ?? ""}">${sliceHtml.sliceHtml}</a>`;
3373
3336
  break;
3374
3337
  default:
3375
3338
  html += sliceHtml.sliceHtml;
@@ -3411,9 +3374,9 @@ function processNode(node, doc, result) {
3411
3374
  for (const n of node.children) processNode(n, doc, result);
3412
3375
  break;
3413
3376
  case _univerjs_core.DataStreamTreeNodeType.PARAGRAPH: {
3414
- var _doc$body$paragraphs$, _doc$body;
3377
+ var _doc$body;
3415
3378
  const { children, startIndex, endIndex } = node;
3416
- const paragraph = (_doc$body$paragraphs$ = (_doc$body = doc.body) === null || _doc$body === void 0 || (_doc$body = _doc$body.paragraphs) === null || _doc$body === void 0 ? void 0 : _doc$body.find((p) => p.startIndex === endIndex)) !== null && _doc$body$paragraphs$ !== void 0 ? _doc$body$paragraphs$ : {};
3379
+ const paragraph = ((_doc$body = doc.body) === null || _doc$body === void 0 || (_doc$body = _doc$body.paragraphs) === null || _doc$body === void 0 ? void 0 : _doc$body.find((p) => p.startIndex === endIndex)) ?? {};
3417
3380
  const { paragraphStyle = {} } = paragraph;
3418
3381
  const { horizontalAlign, spaceAbove, spaceBelow, lineSpacing } = paragraphStyle;
3419
3382
  const style = [];
@@ -3444,16 +3407,16 @@ function processNode(node, doc, result) {
3444
3407
  break;
3445
3408
  }
3446
3409
  case _univerjs_core.DataStreamTreeNodeType.TABLE: {
3447
- var _result$tableIndex, _result$tableStack, _doc$body2, _doc$tableSource, _table$tableColumns;
3410
+ var _doc$body2, _doc$tableSource, _table$tableColumns;
3448
3411
  const { children } = node;
3449
3412
  closeListStack(result);
3450
- (_result$tableIndex = result.tableIndex) !== null && _result$tableIndex !== void 0 || (result.tableIndex = 0);
3451
- (_result$tableStack = result.tableStack) !== null && _result$tableStack !== void 0 || (result.tableStack = []);
3413
+ result.tableIndex ??= 0;
3414
+ result.tableStack ??= [];
3452
3415
  const tableRange = (_doc$body2 = doc.body) === null || _doc$body2 === void 0 || (_doc$body2 = _doc$body2.tables) === null || _doc$body2 === void 0 ? void 0 : _doc$body2[result.tableIndex++];
3453
3416
  const table = tableRange ? (_doc$tableSource = doc.tableSource) === null || _doc$tableSource === void 0 ? void 0 : _doc$tableSource[tableRange.tableId] : void 0;
3454
3417
  const width = table === null || table === void 0 || (_table$tableColumns = table.tableColumns) === null || _table$tableColumns === void 0 ? void 0 : _table$tableColumns.reduce((sum, column) => {
3455
- var _column$size$width$v, _column$size;
3456
- return sum + ((_column$size$width$v = (_column$size = column.size) === null || _column$size === void 0 || (_column$size = _column$size.width) === null || _column$size === void 0 ? void 0 : _column$size.v) !== null && _column$size$width$v !== void 0 ? _column$size$width$v : 0);
3418
+ var _column$size;
3419
+ return sum + (((_column$size = column.size) === null || _column$size === void 0 || (_column$size = _column$size.width) === null || _column$size === void 0 ? void 0 : _column$size.v) ?? 0);
3457
3420
  }, 0);
3458
3421
  const tableStyle = ["border-collapse: collapse", width ? `width: ${roundCssNumber(width)}px` : "width: 100%"].join("; ");
3459
3422
  result.tableStack.push({
@@ -3468,9 +3431,9 @@ function processNode(node, doc, result) {
3468
3431
  break;
3469
3432
  }
3470
3433
  case _univerjs_core.DataStreamTreeNodeType.TABLE_ROW: {
3471
- var _result$tableStack2, _tableContext$table, _row$trHeight;
3434
+ var _result$tableStack, _tableContext$table, _row$trHeight;
3472
3435
  const { children } = node;
3473
- const tableContext = (_result$tableStack2 = result.tableStack) === null || _result$tableStack2 === void 0 ? void 0 : _result$tableStack2[result.tableStack.length - 1];
3436
+ const tableContext = (_result$tableStack = result.tableStack) === null || _result$tableStack === void 0 ? void 0 : _result$tableStack[result.tableStack.length - 1];
3474
3437
  if (tableContext) {
3475
3438
  tableContext.rowIndex++;
3476
3439
  tableContext.columnIndex = 0;
@@ -3483,11 +3446,11 @@ function processNode(node, doc, result) {
3483
3446
  break;
3484
3447
  }
3485
3448
  case _univerjs_core.DataStreamTreeNodeType.TABLE_CELL: {
3486
- var _result$tableStack3, _tableContext$table2, _row$tableCells, _tableContext$columnI;
3449
+ var _result$tableStack2, _tableContext$table2, _row$tableCells;
3487
3450
  const { children } = node;
3488
- const tableContext = (_result$tableStack3 = result.tableStack) === null || _result$tableStack3 === void 0 ? void 0 : _result$tableStack3[result.tableStack.length - 1];
3451
+ const tableContext = (_result$tableStack2 = result.tableStack) === null || _result$tableStack2 === void 0 ? void 0 : _result$tableStack2[result.tableStack.length - 1];
3489
3452
  const row = tableContext === null || tableContext === void 0 || (_tableContext$table2 = tableContext.table) === null || _tableContext$table2 === void 0 || (_tableContext$table2 = _tableContext$table2.tableRows) === null || _tableContext$table2 === void 0 ? void 0 : _tableContext$table2[tableContext.rowIndex];
3490
- const cell = row === null || row === void 0 || (_row$tableCells = row.tableCells) === null || _row$tableCells === void 0 ? void 0 : _row$tableCells[(_tableContext$columnI = tableContext === null || tableContext === void 0 ? void 0 : tableContext.columnIndex) !== null && _tableContext$columnI !== void 0 ? _tableContext$columnI : 0];
3453
+ const cell = row === null || row === void 0 || (_row$tableCells = row.tableCells) === null || _row$tableCells === void 0 ? void 0 : _row$tableCells[(tableContext === null || tableContext === void 0 ? void 0 : tableContext.columnIndex) ?? 0];
3491
3454
  if (tableContext) tableContext.columnIndex++;
3492
3455
  if ((cell === null || cell === void 0 ? void 0 : cell.rowSpan) === 0 || (cell === null || cell === void 0 ? void 0 : cell.columnSpan) === 0) break;
3493
3456
  result.html += `<td class="UniverTableCell"${serializeTableCellAttributes(cell)}>`;
@@ -3509,10 +3472,10 @@ function renderParagraphNodeHtml(doc, paragraph, startIndex, endIndex, innerHtml
3509
3472
  result.html += renderBlockParagraphHtml(doc, paragraph, startIndex, endIndex, innerHtml, style);
3510
3473
  }
3511
3474
  function renderBlockParagraphHtml(doc, paragraph, startIndex, endIndex, innerHtml, style) {
3512
- var _doc$body3, _renderHeadingParagra;
3475
+ var _doc$body3;
3513
3476
  const blockRange = (_doc$body3 = doc.body) === null || _doc$body3 === void 0 || (_doc$body3 = _doc$body3.blockRanges) === null || _doc$body3 === void 0 ? void 0 : _doc$body3.find((range) => range.startIndex <= startIndex && endIndex <= range.endIndex + 1);
3514
3477
  if (blockRange && !hasVisibleHtml(innerHtml)) return "";
3515
- const paragraphHtml = (_renderHeadingParagra = renderHeadingParagraphHtml(paragraph, innerHtml, style)) !== null && _renderHeadingParagra !== void 0 ? _renderHeadingParagra : `<p class="UniverNormal" ${style.length ? `style="${style.join("; ")};"` : ""}>${innerHtml}</p>`;
3478
+ const paragraphHtml = renderHeadingParagraphHtml(paragraph, innerHtml, style) ?? `<p class="UniverNormal" ${style.length ? `style="${style.join("; ")};"` : ""}>${innerHtml}</p>`;
3516
3479
  switch (blockRange === null || blockRange === void 0 ? void 0 : blockRange.blockType) {
3517
3480
  case _univerjs_core.DocumentBlockRangeType.QUOTE: return `<blockquote data-doc-type="quote" style="border-left: 4px solid #d0d7de; margin: 8px 0; padding: 4px 0 4px 12px; color: #57606a;">${paragraphHtml}</blockquote>`;
3518
3481
  case _univerjs_core.DocumentBlockRangeType.CODE: return `<pre data-doc-type="code-block" style="font-family: Consolas, 'Courier New', monospace; background: #f6f8fa; padding: 12px; border-radius: 6px; white-space: pre-wrap;"><code>${innerHtml.replace(/<\/?[^>]+>/g, "")}</code></pre>`;
@@ -3527,11 +3490,10 @@ function renderHeadingParagraphHtml(paragraph, innerHtml, style) {
3527
3490
  return `<p class="UniverHeading" role="heading" aria-level="${headingLevel}" data-heading-level="${headingLevel}" ${style.length ? `style="${style.join("; ")};"` : ""}>${innerHtml}</p>`;
3528
3491
  }
3529
3492
  function renderListParagraphItemHtml(doc, paragraph, innerHtml, style) {
3530
- var _bullet$nestingLevel;
3531
3493
  const bullet = paragraph.bullet;
3532
3494
  if (!bullet) return null;
3533
3495
  const tag = isOrderedListType(String(bullet.listType)) ? "ol" : "ul";
3534
- const level = (_bullet$nestingLevel = bullet.nestingLevel) !== null && _bullet$nestingLevel !== void 0 ? _bullet$nestingLevel : 0;
3496
+ const level = bullet.nestingLevel ?? 0;
3535
3497
  const listStyle = getListStyleType(doc, String(bullet.listType), level);
3536
3498
  return {
3537
3499
  tag,
@@ -3542,8 +3504,7 @@ function renderListParagraphItemHtml(doc, paragraph, innerHtml, style) {
3542
3504
  };
3543
3505
  }
3544
3506
  function appendListParagraphHtml(result, listItem) {
3545
- var _result$listStack;
3546
- (_result$listStack = result.listStack) !== null && _result$listStack !== void 0 || (result.listStack = []);
3507
+ result.listStack ??= [];
3547
3508
  const stack = result.listStack;
3548
3509
  while (stack.length > listItem.level + 1) result.html += `</li></${stack.pop().tag}>`;
3549
3510
  const current = stack[stack.length - 1];
@@ -3572,16 +3533,16 @@ function openList(result, listItem) {
3572
3533
  });
3573
3534
  }
3574
3535
  function closeListStack(result) {
3575
- var _result$listStack2;
3576
- while ((_result$listStack2 = result.listStack) === null || _result$listStack2 === void 0 ? void 0 : _result$listStack2.length) result.html += `</li></${result.listStack.pop().tag}>`;
3536
+ var _result$listStack;
3537
+ while ((_result$listStack = result.listStack) === null || _result$listStack === void 0 ? void 0 : _result$listStack.length) result.html += `</li></${result.listStack.pop().tag}>`;
3577
3538
  }
3578
3539
  function serializeTableCellAttributes(cell) {
3579
- var _cell$rowSpan, _cell$columnSpan, _cell$size, _cell$backgroundColor;
3540
+ var _cell$size, _cell$backgroundColor;
3580
3541
  if (!cell) return "";
3581
3542
  const attributes = [];
3582
3543
  const styles = [];
3583
- if (((_cell$rowSpan = cell.rowSpan) !== null && _cell$rowSpan !== void 0 ? _cell$rowSpan : 1) > 1) attributes.push(`rowspan="${cell.rowSpan}"`);
3584
- if (((_cell$columnSpan = cell.columnSpan) !== null && _cell$columnSpan !== void 0 ? _cell$columnSpan : 1) > 1) attributes.push(`colspan="${cell.columnSpan}"`);
3544
+ if ((cell.rowSpan ?? 1) > 1) attributes.push(`rowspan="${cell.rowSpan}"`);
3545
+ if ((cell.columnSpan ?? 1) > 1) attributes.push(`colspan="${cell.columnSpan}"`);
3585
3546
  if (((_cell$size = cell.size) === null || _cell$size === void 0 || (_cell$size = _cell$size.width) === null || _cell$size === void 0 ? void 0 : _cell$size.v) != null) styles.push(`width: ${roundCssNumber(cell.size.width.v)}px`);
3586
3547
  if ((_cell$backgroundColor = cell.backgroundColor) === null || _cell$backgroundColor === void 0 ? void 0 : _cell$backgroundColor.rgb) styles.push(`background-color: ${cell.backgroundColor.rgb}`);
3587
3548
  [
@@ -3590,9 +3551,9 @@ function serializeTableCellAttributes(cell) {
3590
3551
  ["bottom", cell.borderBottom],
3591
3552
  ["left", cell.borderLeft]
3592
3553
  ].forEach(([side, border]) => {
3593
- var _border$width$v, _border$width, _border$color$rgb, _border$color;
3554
+ var _border$width, _border$color;
3594
3555
  if (!border) return;
3595
- styles.push(`border-${side}: ${roundCssNumber((_border$width$v = (_border$width = border.width) === null || _border$width === void 0 ? void 0 : _border$width.v) !== null && _border$width$v !== void 0 ? _border$width$v : 1)}px solid ${(_border$color$rgb = (_border$color = border.color) === null || _border$color === void 0 ? void 0 : _border$color.rgb) !== null && _border$color$rgb !== void 0 ? _border$color$rgb : "#1f1f1f"}`);
3556
+ styles.push(`border-${side}: ${roundCssNumber(((_border$width = border.width) === null || _border$width === void 0 ? void 0 : _border$width.v) ?? 1)}px solid ${((_border$color = border.color) === null || _border$color === void 0 ? void 0 : _border$color.rgb) ?? "#1f1f1f"}`);
3596
3557
  });
3597
3558
  if (styles.length) attributes.push(`style="${styles.join("; ")};"`);
3598
3559
  return attributes.length ? ` ${attributes.join(" ")}` : "";
@@ -3601,7 +3562,7 @@ function serializeTextStyle(textStyle) {
3601
3562
  if (!textStyle) return [];
3602
3563
  const { ff, fs, it, bl, ul, st, ol, bg, cl } = textStyle;
3603
3564
  const style = [];
3604
- style.push(`font-family: ${ff !== null && ff !== void 0 ? ff : DEFAULT_CLIPBOARD_FONT_FAMILY}`);
3565
+ style.push(`font-family: ${ff ?? DEFAULT_CLIPBOARD_FONT_FAMILY}`);
3605
3566
  if (fs != null) style.push(`font-size: ${fs}pt`);
3606
3567
  if (cl === null || cl === void 0 ? void 0 : cl.rgb) style.push(`color: ${normalizeCssColor(cl.rgb)}`);
3607
3568
  if (bg === null || bg === void 0 ? void 0 : bg.rgb) style.push(`background-color: ${normalizeCssColor(bg.rgb)}`);
@@ -3686,8 +3647,8 @@ var UDMToHtmlService = class {
3686
3647
  if (docList.length === 0) throw new Error("The bodyList length at least to be 1");
3687
3648
  let html = "";
3688
3649
  for (const doc of _univerjs_core.Tools.deepClone(docList)) {
3689
- var _this$_docHtmlExportS, _this$_docHtmlExportS2;
3690
- html += convertBodyToHtml((_this$_docHtmlExportS = (_this$_docHtmlExportS2 = this._docHtmlExportService) === null || _this$_docHtmlExportS2 === void 0 ? void 0 : _this$_docHtmlExportS2.transformDocumentForHtmlExport(doc)) !== null && _this$_docHtmlExportS !== void 0 ? _this$_docHtmlExportS : doc);
3650
+ var _this$_docHtmlExportS;
3651
+ html += convertBodyToHtml(((_this$_docHtmlExportS = this._docHtmlExportService) === null || _this$_docHtmlExportS === void 0 ? void 0 : _this$_docHtmlExportS.transformDocumentForHtmlExport(doc)) ?? doc);
3691
3652
  }
3692
3653
  return html;
3693
3654
  }
@@ -3760,8 +3721,7 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
3760
3721
  this._umdToHtml = new UDMToHtmlService(docHtmlExportService);
3761
3722
  }
3762
3723
  async copy(sliceType = _univerjs_core.SliceBodyType.copy, ranges) {
3763
- var _this$_getDocumentBod;
3764
- const { newSnapshotList = [], needCache = false, plainTextList, snapshot, ranges: allRanges } = (_this$_getDocumentBod = this._getDocumentBodyInRanges(sliceType, ranges)) !== null && _this$_getDocumentBod !== void 0 ? _this$_getDocumentBod : {};
3724
+ const { newSnapshotList = [], needCache = false, plainTextList, snapshot, ranges: allRanges } = this._getDocumentBodyInRanges(sliceType, ranges) ?? {};
3765
3725
  if (newSnapshotList.length === 0 || snapshot == null) return false;
3766
3726
  try {
3767
3727
  var _allRanges$;
@@ -3800,10 +3760,9 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
3800
3760
  return this._paste(partDocData);
3801
3761
  }
3802
3762
  async _cut(ranges) {
3803
- var _ref, _ranges$filter, _ref2, _ref3, _textRanges$;
3804
- const textRanges = (_ref = (_ranges$filter = ranges === null || ranges === void 0 ? void 0 : ranges.filter((range) => range.rangeType === _univerjs_core.DOC_RANGE_TYPE.TEXT)) !== null && _ranges$filter !== void 0 ? _ranges$filter : this._docSelectionManagerService.getTextRanges()) !== null && _ref !== void 0 ? _ref : [];
3805
- const rectRanges = (_ref2 = (_ref3 = ranges === null || ranges === void 0 ? void 0 : ranges.filter((range) => range.rangeType === _univerjs_core.DOC_RANGE_TYPE.RECT)) !== null && _ref3 !== void 0 ? _ref3 : this._docSelectionManagerService.getRectRanges()) !== null && _ref2 !== void 0 ? _ref2 : [];
3806
- const { segmentId, endOffset: activeEndOffset, style } = (_textRanges$ = textRanges[0]) !== null && _textRanges$ !== void 0 ? _textRanges$ : {};
3763
+ const textRanges = (ranges === null || ranges === void 0 ? void 0 : ranges.filter((range) => range.rangeType === _univerjs_core.DOC_RANGE_TYPE.TEXT)) ?? this._docSelectionManagerService.getTextRanges() ?? [];
3764
+ const rectRanges = (ranges === null || ranges === void 0 ? void 0 : ranges.filter((range) => range.rangeType === _univerjs_core.DOC_RANGE_TYPE.RECT)) ?? this._docSelectionManagerService.getRectRanges() ?? [];
3765
+ const { segmentId, endOffset: activeEndOffset, style } = textRanges[0] ?? {};
3807
3766
  if (segmentId == null) this._logService.error("[DocClipboardController] segmentId is not existed");
3808
3767
  if (textRanges.length === 0 && rectRanges.length === 0) return false;
3809
3768
  this.copy(_univerjs_core.SliceBodyType.cut, ranges);
@@ -3835,7 +3794,7 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
3835
3794
  }
3836
3795
  }
3837
3796
  async _paste(docData) {
3838
- var _body$customRanges$ma, _body$customRanges, _body$paragraphs, _currentDocument$getS;
3797
+ var _body$customRanges, _body$paragraphs, _currentDocument$getS;
3839
3798
  const { body: _body } = docData;
3840
3799
  if (_body == null) return false;
3841
3800
  let body = (0, _univerjs_core.normalizeBody)(_body);
@@ -3847,12 +3806,12 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
3847
3806
  targetUnitId: currentDocument.getUnitId()
3848
3807
  });
3849
3808
  });
3850
- const customRangeMappings = (_body$customRanges$ma = (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.map((sourceRange) => {
3809
+ const customRangeMappings = ((_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.map((sourceRange) => {
3851
3810
  return {
3852
3811
  sourceRange,
3853
3812
  targetRange: _univerjs_core.BuildTextUtils.customRange.copyCustomRange(sourceRange)
3854
3813
  };
3855
- })) !== null && _body$customRanges$ma !== void 0 ? _body$customRanges$ma : [];
3814
+ })) ?? [];
3856
3815
  body.customRanges = customRangeMappings.map(({ targetRange }) => targetRange);
3857
3816
  (_body$paragraphs = body.paragraphs) === null || _body$paragraphs === void 0 || _body$paragraphs.forEach((copy) => {
3858
3817
  var _copy$paragraphStyle;
@@ -3925,14 +3884,14 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
3925
3884
  }
3926
3885
  _applyCopyDocDataHooks(doc, sourceDocuments) {
3927
3886
  return this._clipboardHooks.reduce((currentDoc, hook) => {
3928
- var _hook$onCopyDocData, _hook$onCopyDocData2;
3929
- return (_hook$onCopyDocData = (_hook$onCopyDocData2 = hook.onCopyDocData) === null || _hook$onCopyDocData2 === void 0 ? void 0 : _hook$onCopyDocData2.call(hook, currentDoc, { sourceDocuments })) !== null && _hook$onCopyDocData !== void 0 ? _hook$onCopyDocData : currentDoc;
3887
+ var _hook$onCopyDocData;
3888
+ return ((_hook$onCopyDocData = hook.onCopyDocData) === null || _hook$onCopyDocData === void 0 ? void 0 : _hook$onCopyDocData.call(hook, currentDoc, { sourceDocuments })) ?? currentDoc;
3930
3889
  }, doc);
3931
3890
  }
3932
3891
  _getDocumentBodyInRanges(sliceType, ranges) {
3933
3892
  var _this$_clipboardHooks, _docDataModel$getSelf;
3934
3893
  const docDataModel = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
3935
- const allRanges = ranges !== null && ranges !== void 0 ? ranges : this._docSelectionManagerService.getDocRanges();
3894
+ const allRanges = ranges ?? this._docSelectionManagerService.getDocRanges();
3936
3895
  const results = [];
3937
3896
  const plainTextResults = [];
3938
3897
  const copyContentHook = (_this$_clipboardHooks = this._clipboardHooks.find((hook) => hook.onCopyContent)) === null || _this$_clipboardHooks === void 0 ? void 0 : _this$_clipboardHooks.onCopyContent;
@@ -3943,7 +3902,7 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
3943
3902
  const snapshot = docDataModel.getSnapshot();
3944
3903
  if (body == null) return;
3945
3904
  for (const range of allRanges) {
3946
- var _docDataModel$getSelf2, _copyContentHook;
3905
+ var _docDataModel$getSelf2;
3947
3906
  const { startOffset, endOffset, collapsed, rangeType } = range;
3948
3907
  if (collapsed || startOffset == null || endOffset == null) continue;
3949
3908
  if (rangeType === _univerjs_core.DOC_RANGE_TYPE.RECT) {
@@ -3961,11 +3920,11 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
3961
3920
  const docBody = (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.sliceBody(deleteRange.startOffset, deleteRange.endOffset, sliceType);
3962
3921
  if (docBody == null) continue;
3963
3922
  results.push(docBody);
3964
- plainTextResults.push((_copyContentHook = copyContentHook === null || copyContentHook === void 0 ? void 0 : copyContentHook(deleteRange.startOffset, deleteRange.endOffset, {
3923
+ plainTextResults.push((copyContentHook === null || copyContentHook === void 0 ? void 0 : copyContentHook(deleteRange.startOffset, deleteRange.endOffset, {
3965
3924
  body,
3966
3925
  segmentId,
3967
3926
  unitId: docDataModel.getUnitId()
3968
- })) !== null && _copyContentHook !== void 0 ? _copyContentHook : docBody.dataStream);
3927
+ })) ?? docBody.dataStream);
3969
3928
  }
3970
3929
  return {
3971
3930
  newSnapshotList: results.map((e) => ({
@@ -3980,7 +3939,6 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
3980
3939
  }
3981
3940
  async _genDocDataFromClipboardItems(items) {
3982
3941
  try {
3983
- var _await$this$_uploadBa;
3984
3942
  let html = "";
3985
3943
  let text = "";
3986
3944
  let internalJson = "";
@@ -4006,15 +3964,14 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
4006
3964
  }
4007
3965
  }
4008
3966
  if (!html && !text && files.length) html = await this._createImagePasteHtml(files);
4009
- html = (_await$this$_uploadBa = await this._uploadBase64ImagesInHtml(html)) !== null && _await$this$_uploadBa !== void 0 ? _await$this$_uploadBa : "";
3967
+ html = await this._uploadBase64ImagesInHtml(html) ?? "";
4010
3968
  return this._genDocDataFromHtmlAndText(html, text, void 0, internalJson);
4011
3969
  } catch (e) {
4012
3970
  return Promise.reject(e);
4013
3971
  }
4014
3972
  }
4015
3973
  _genDocDataFromHtmlAndText(html, text, _unitId, internalJson) {
4016
- var _parseInternalClipboa;
4017
- const internalDocData = (_parseInternalClipboa = parseInternalClipboardFragment(internalJson)) !== null && _parseInternalClipboa !== void 0 ? _parseInternalClipboa : extractInternalClipboardFragmentFromHtml(html);
3974
+ const internalDocData = parseInternalClipboardFragment(internalJson) ?? extractInternalClipboardFragmentFromHtml(html);
4018
3975
  if (internalDocData === null || internalDocData === void 0 ? void 0 : internalDocData.body) return internalDocData;
4019
3976
  if (!html) if (text) return { body: _univerjs_core.BuildTextUtils.transform.fromPlainText(text) };
4020
3977
  else throw new Error("[DocClipboardService] html and text cannot be both empty!");
@@ -4056,7 +4013,7 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
4056
4013
  return doc.documentElement.outerHTML;
4057
4014
  }
4058
4015
  async _createImagePasteHtml(files) {
4059
- var _this$_clipboardHooks3, _this$_clipboardHooks4;
4016
+ var _this$_clipboardHooks3;
4060
4017
  const doc = {
4061
4018
  id: "",
4062
4019
  documentStyle: {},
@@ -4092,7 +4049,7 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
4092
4049
  };
4093
4050
  });
4094
4051
  };
4095
- const onBeforePasteImage = (_this$_clipboardHooks3 = (_this$_clipboardHooks4 = this._clipboardHooks.find((e) => e.onBeforePasteImage)) === null || _this$_clipboardHooks4 === void 0 ? void 0 : _this$_clipboardHooks4.onBeforePasteImage) !== null && _this$_clipboardHooks3 !== void 0 ? _this$_clipboardHooks3 : fileToBase64;
4052
+ const onBeforePasteImage = ((_this$_clipboardHooks3 = this._clipboardHooks.find((e) => e.onBeforePasteImage)) === null || _this$_clipboardHooks3 === void 0 ? void 0 : _this$_clipboardHooks3.onBeforePasteImage) ?? fileToBase64;
4096
4053
  await Promise.all(files.map(async (file, index) => {
4097
4054
  var _body$customBlocks;
4098
4055
  const image = await onBeforePasteImage(file);
@@ -4154,12 +4111,12 @@ function endsAtDocumentBoundary(dataStream) {
4154
4111
  return lastToken === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH || lastToken === _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK || lastToken === _univerjs_core.DataStreamTreeTokenType.BLOCK_END || lastToken === _univerjs_core.DataStreamTreeTokenType.TABLE_END || lastToken === _univerjs_core.DataStreamTreeTokenType.COLUMN_GROUP_END;
4155
4112
  }
4156
4113
  function ensureParagraphAtStructuralGap(body, originBody, ranges) {
4157
- var _body$paragraphs$map, _body$paragraphs2, _body$paragraphs3;
4114
+ var _body$paragraphs2;
4158
4115
  if (endsAtDocumentBoundary(body.dataStream) || !ranges.every((range) => range.collapsed && isTopLevelStructuralGap(originBody.dataStream, range.startOffset))) return;
4159
4116
  const paragraphIndex = body.dataStream.length;
4160
- const paragraphIds = new Set((_body$paragraphs$map = (_body$paragraphs2 = body.paragraphs) === null || _body$paragraphs2 === void 0 ? void 0 : _body$paragraphs2.map((paragraph) => paragraph.paragraphId)) !== null && _body$paragraphs$map !== void 0 ? _body$paragraphs$map : []);
4117
+ const paragraphIds = new Set(((_body$paragraphs2 = body.paragraphs) === null || _body$paragraphs2 === void 0 ? void 0 : _body$paragraphs2.map((paragraph) => paragraph.paragraphId)) ?? []);
4161
4118
  body.dataStream += _univerjs_core.DataStreamTreeTokenType.PARAGRAPH;
4162
- body.paragraphs = [...(_body$paragraphs3 = body.paragraphs) !== null && _body$paragraphs3 !== void 0 ? _body$paragraphs3 : [], {
4119
+ body.paragraphs = [...body.paragraphs ?? [], {
4163
4120
  startIndex: paragraphIndex,
4164
4121
  paragraphId: (0, _univerjs_core.createParagraphId)(paragraphIds)
4165
4122
  }];
@@ -4569,12 +4526,12 @@ const DocSelectAllCommand = {
4569
4526
  id: "doc.command.select-all",
4570
4527
  type: _univerjs_core.CommandType.COMMAND,
4571
4528
  handler: async (accessor) => {
4572
- var _docRanges$find, _docDataModel$getSelf;
4529
+ var _docDataModel$getSelf;
4573
4530
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
4574
4531
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
4575
4532
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
4576
4533
  const docRanges = docSelectionManagerService.getDocRanges();
4577
- const activeRange = (_docRanges$find = docRanges.find((range) => range.isActive)) !== null && _docRanges$find !== void 0 ? _docRanges$find : docRanges[0];
4534
+ const activeRange = docRanges.find((range) => range.isActive) ?? docRanges[0];
4578
4535
  if (docDataModel == null || activeRange == null) return false;
4579
4536
  const { segmentId } = activeRange;
4580
4537
  const unitId = docDataModel.getUnitId();
@@ -4596,8 +4553,7 @@ function getWholeDocumentRanges(body) {
4596
4553
  return getRangesForOffsets(body, 0, body.dataStream.length - 2);
4597
4554
  }
4598
4555
  function getRangesForOffsets(body, startOffset, endOffset) {
4599
- var _body$columnGroups;
4600
- const columnGroups = [...(_body$columnGroups = body.columnGroups) !== null && _body$columnGroups !== void 0 ? _body$columnGroups : []].sort((left, right) => left.startIndex - right.startIndex);
4556
+ const columnGroups = [...body.columnGroups ?? []].sort((left, right) => left.startIndex - right.startIndex);
4601
4557
  const ranges = [];
4602
4558
  let offset = startOffset;
4603
4559
  for (const columnGroup of columnGroups) {
@@ -4614,10 +4570,9 @@ function getRangesForOffsets(body, startOffset, endOffset) {
4614
4570
  return ranges;
4615
4571
  }
4616
4572
  function getRangesWithTables(body, startOffset, endOffset) {
4617
- var _body$tables;
4618
4573
  const ranges = [];
4619
4574
  let offset = startOffset;
4620
- for (const table of [...(_body$tables = body.tables) !== null && _body$tables !== void 0 ? _body$tables : []].sort((left, right) => left.startIndex - right.startIndex)) {
4575
+ for (const table of [...body.tables ?? []].sort((left, right) => left.startIndex - right.startIndex)) {
4621
4576
  const { startIndex, endIndex } = table;
4622
4577
  if (startIndex < startOffset || endIndex > endOffset) continue;
4623
4578
  if (offset !== startIndex) ranges.push(...getTextRangesByParagraphs(body, offset, startIndex - 1));
@@ -4628,9 +4583,8 @@ function getRangesWithTables(body, startOffset, endOffset) {
4628
4583
  return ranges;
4629
4584
  }
4630
4585
  function getTextRangesByParagraphs(body, startOffset, endOffset) {
4631
- var _body$paragraphs;
4632
4586
  if (startOffset > endOffset) return [];
4633
- const paragraphs = [...(_body$paragraphs = body.paragraphs) !== null && _body$paragraphs !== void 0 ? _body$paragraphs : []].sort((left, right) => left.startIndex - right.startIndex);
4587
+ const paragraphs = [...body.paragraphs ?? []].sort((left, right) => left.startIndex - right.startIndex);
4634
4588
  const ranges = [];
4635
4589
  let offset = startOffset;
4636
4590
  for (const paragraph of paragraphs) {
@@ -4651,7 +4605,6 @@ function getTextRangesByParagraphs(body, startOffset, endOffset) {
4651
4605
  return ranges;
4652
4606
  }
4653
4607
  function getSelectAllScopes(body, activeRange) {
4654
- var _body$tables2, _body$customBlocks, _body$blockRanges, _body$columnGroups2;
4655
4608
  const scopes = [];
4656
4609
  const addScope = (scope) => {
4657
4610
  if ((scope === null || scope === void 0 ? void 0 : scope.length) && !scopes.some((existing) => isSameRanges(existing, scope))) scopes.push(scope);
@@ -4659,9 +4612,9 @@ function getSelectAllScopes(body, activeRange) {
4659
4612
  const startOffset = activeRange.startOffset;
4660
4613
  const endOffset = activeRange.endOffset;
4661
4614
  if (startOffset == null || endOffset == null) return [getWholeDocumentRanges(body)];
4662
- const table = ((_body$tables2 = body.tables) !== null && _body$tables2 !== void 0 ? _body$tables2 : []).find((item) => isRangeInside(startOffset, endOffset, item.startIndex, item.endIndex));
4663
- const customBlock = ((_body$customBlocks = body.customBlocks) !== null && _body$customBlocks !== void 0 ? _body$customBlocks : []).find((item) => item.startIndex >= startOffset && item.startIndex <= endOffset);
4664
- const blockRange = ((_body$blockRanges = body.blockRanges) !== null && _body$blockRanges !== void 0 ? _body$blockRanges : []).find((item) => isRangeInside(startOffset, endOffset, item.startIndex, item.endIndex));
4615
+ const table = (body.tables ?? []).find((item) => isRangeInside(startOffset, endOffset, item.startIndex, item.endIndex));
4616
+ const customBlock = (body.customBlocks ?? []).find((item) => item.startIndex >= startOffset && item.startIndex <= endOffset);
4617
+ const blockRange = (body.blockRanges ?? []).find((item) => isRangeInside(startOffset, endOffset, item.startIndex, item.endIndex));
4665
4618
  if (table) addScope([getTableRectRange(table)]);
4666
4619
  else if (customBlock) addScope([{
4667
4620
  endOffset: customBlock.startIndex,
@@ -4674,14 +4627,13 @@ function getSelectAllScopes(body, activeRange) {
4674
4627
  startOffset: blockRange.startIndex + 1
4675
4628
  }]);
4676
4629
  else {
4677
- var _body$tables3;
4678
- const paragraphRange = clampParagraphRangeByTables(getParagraphRangeAtOffset(body, startOffset), (_body$tables3 = body.tables) !== null && _body$tables3 !== void 0 ? _body$tables3 : [], startOffset);
4630
+ const paragraphRange = clampParagraphRangeByTables(getParagraphRangeAtOffset(body, startOffset), body.tables ?? [], startOffset);
4679
4631
  addScope(paragraphRange ? [{
4680
4632
  ...paragraphRange,
4681
4633
  rangeType: _univerjs_core.DOC_RANGE_TYPE.TEXT
4682
4634
  }] : null);
4683
4635
  }
4684
- const columnGroup = ((_body$columnGroups2 = body.columnGroups) !== null && _body$columnGroups2 !== void 0 ? _body$columnGroups2 : []).find((item) => isRangeInside(startOffset, endOffset, item.startIndex, item.endIndex));
4636
+ const columnGroup = (body.columnGroups ?? []).find((item) => isRangeInside(startOffset, endOffset, item.startIndex, item.endIndex));
4685
4637
  if (columnGroup) {
4686
4638
  const column = getColumnRanges(body, columnGroup).find((item) => isRangeInside(startOffset, endOffset, item.startOffset, item.endOffset));
4687
4639
  if (column) addScope(getRangesForOffsets(body, column.startOffset, column.endOffset));
@@ -4722,12 +4674,10 @@ function getTableRectRange(table) {
4722
4674
  };
4723
4675
  }
4724
4676
  function getParagraphRangeAtOffset(body, offset) {
4725
- var _body$paragraphs2;
4726
- const sortedParagraphs = [...(_body$paragraphs2 = body.paragraphs) !== null && _body$paragraphs2 !== void 0 ? _body$paragraphs2 : []].sort((left, right) => left.startIndex - right.startIndex);
4677
+ const sortedParagraphs = [...body.paragraphs ?? []].sort((left, right) => left.startIndex - right.startIndex);
4727
4678
  const paragraphStartOffsets = (0, _univerjs_core.getParagraphContentStartOffsets)(body);
4728
4679
  for (const paragraph of sortedParagraphs) {
4729
- var _paragraphStartOffset;
4730
- const startOffset = (_paragraphStartOffset = paragraphStartOffsets.get(paragraph.startIndex)) !== null && _paragraphStartOffset !== void 0 ? _paragraphStartOffset : 0;
4680
+ const startOffset = paragraphStartOffsets.get(paragraph.startIndex) ?? 0;
4731
4681
  if (startOffset <= offset && offset <= paragraph.startIndex) return {
4732
4682
  endOffset: paragraph.startIndex,
4733
4683
  startOffset
@@ -4757,8 +4707,7 @@ function isSameTextRangeCoverage(currentRanges, nextRanges) {
4757
4707
  return startOffset === targetRange.startOffset && endOffset === targetRange.endOffset && currentRanges.every((range) => range.startOffset >= targetRange.startOffset && range.endOffset <= targetRange.endOffset);
4758
4708
  }
4759
4709
  function getRangeType(range) {
4760
- var _range$rangeType;
4761
- return (_range$rangeType = range.rangeType) !== null && _range$rangeType !== void 0 ? _range$rangeType : _univerjs_core.DOC_RANGE_TYPE.TEXT;
4710
+ return range.rangeType ?? _univerjs_core.DOC_RANGE_TYPE.TEXT;
4762
4711
  }
4763
4712
 
4764
4713
  //#endregion
@@ -4830,7 +4779,7 @@ const IMEInputCommand = {
4830
4779
  id: "doc.command.ime-input",
4831
4780
  type: _univerjs_core.CommandType.COMMAND,
4832
4781
  handler: async (accessor, params) => {
4833
- var _renderManagerService, _docDataModel$getSelf, _body$customRanges, _body$customDecoratio;
4782
+ var _renderManagerService, _docDataModel$getSelf;
4834
4783
  const { unitId, newText, oldTextLen, isCompositionEnd, isCompositionStart } = params;
4835
4784
  const commandService = accessor.get(_univerjs_core.ICommandService);
4836
4785
  const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
@@ -4863,9 +4812,9 @@ const IMEInputCommand = {
4863
4812
  };
4864
4813
  const defaultTextStyle = docMenuStyleService.getDefaultStyle();
4865
4814
  const styleCache = docMenuStyleService.getStyleCache();
4866
- const curCustomRange = getCustomRangeAtPosition((_body$customRanges = body.customRanges) !== null && _body$customRanges !== void 0 ? _body$customRanges : [], startOffset + oldTextLen, _univerjs_core.SHEET_EDITOR_UNITS.includes(unitId));
4815
+ const curCustomRange = getCustomRangeAtPosition(body.customRanges ?? [], startOffset + oldTextLen, _univerjs_core.SHEET_EDITOR_UNITS.includes(unitId));
4867
4816
  const curTextRun = getTextRunAtPosition(body, isCompositionStart ? endOffset : startOffset + oldTextLen, defaultTextStyle, styleCache, _univerjs_core.SHEET_EDITOR_UNITS.includes(unitId));
4868
- const customDecorations = getCustomDecorationAtPosition((_body$customDecoratio = body.customDecorations) !== null && _body$customDecoratio !== void 0 ? _body$customDecoratio : [], startOffset + oldTextLen);
4817
+ const customDecorations = getCustomDecorationAtPosition(body.customDecorations ?? [], startOffset + oldTextLen);
4869
4818
  const textX = new _univerjs_core.TextX();
4870
4819
  const jsonX = _univerjs_core.JSONX.getInstance();
4871
4820
  if (!previousActiveRange.collapsed && isCompositionStart) {
@@ -4921,7 +4870,7 @@ const IMEInputCommand = {
4921
4870
  function handleInlineFormat(preCommandId, params, commandService) {
4922
4871
  return commandService.executeCommand(SetInlineFormatCommand.id, {
4923
4872
  preCommandId,
4924
- ...params !== null && params !== void 0 ? params : {}
4873
+ ...params ?? {}
4925
4874
  });
4926
4875
  }
4927
4876
  const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold";
@@ -5059,15 +5008,15 @@ const SetInlineFormatCommand = {
5059
5008
  id: "doc.command.set-inline-format",
5060
5009
  type: _univerjs_core.CommandType.COMMAND,
5061
5010
  handler: async (accessor, params) => {
5062
- var _docSelectionManagerS, _docRanges$find, _docDataModel$getSelf;
5011
+ var _docDataModel$getSelf;
5063
5012
  const { value, preCommandId } = params;
5064
5013
  const commandService = accessor.get(_univerjs_core.ICommandService);
5065
5014
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
5066
5015
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
5067
5016
  const docMenuStyleService = accessor.get(DocMenuStyleService);
5068
- const textRanges = (_docSelectionManagerS = docSelectionManagerService.getTextRanges()) !== null && _docSelectionManagerS !== void 0 ? _docSelectionManagerS : [];
5017
+ const textRanges = docSelectionManagerService.getTextRanges() ?? [];
5069
5018
  const docRanges = textRanges.length > 0 ? textRanges.filter((range) => range.startOffset != null && range.endOffset != null) : docSelectionManagerService.getDocRanges();
5070
- const activeRange = (_docRanges$find = docRanges.find((r) => r.isActive)) !== null && _docRanges$find !== void 0 ? _docRanges$find : docRanges[0];
5019
+ const activeRange = docRanges.find((r) => r.isActive) ?? docRanges[0];
5071
5020
  if (docRanges.length === 0) return false;
5072
5021
  const { segmentId } = docRanges[0];
5073
5022
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
@@ -5116,7 +5065,6 @@ const SetInlineFormatCommand = {
5116
5065
  const memoryCursor = new _univerjs_core.MemoryCursor();
5117
5066
  memoryCursor.reset();
5118
5067
  for (const range of docRanges) {
5119
- var _formatPatch;
5120
5068
  let { startOffset, endOffset, rangeType } = range;
5121
5069
  if (startOffset == null || endOffset == null) continue;
5122
5070
  if (rangeType === _univerjs_core.DOC_RANGE_TYPE.RECT) startOffset = startOffset - 1;
@@ -5132,7 +5080,7 @@ const SetInlineFormatCommand = {
5132
5080
  textRuns: [{
5133
5081
  st: 0,
5134
5082
  ed: endOffset - startOffset,
5135
- ts: (_formatPatch = formatPatch) !== null && _formatPatch !== void 0 ? _formatPatch : { [COMMAND_ID_TO_FORMAT_KEY_MAP[preCommandId]]: formatValue }
5083
+ ts: formatPatch ?? { [COMMAND_ID_TO_FORMAT_KEY_MAP[preCommandId]]: formatValue }
5136
5084
  }]
5137
5085
  };
5138
5086
  const len = startOffset - memoryCursor.cursor;
@@ -5167,11 +5115,10 @@ function getReverseFormatValue(ts, key, preCommandId) {
5167
5115
  else return (ts === null || ts === void 0 ? void 0 : ts[key]) === _univerjs_core.BaselineOffset.SUPERSCRIPT ? _univerjs_core.BaselineOffset.NORMAL : _univerjs_core.BaselineOffset.SUPERSCRIPT;
5168
5116
  }
5169
5117
  function getStyleInTextRange(body, textRange, defaultStyle) {
5170
- var _textRuns$find$ts$ff, _textRuns$find, _textRuns$0$ts, _textRuns$0$ts2, _textRuns$find$ts$bg, _textRuns$find2, _textRuns$find$ts$cl, _textRuns$find3, _textRuns$find$ts$tex, _textRuns$find4;
5118
+ var _textRuns$find, _textRuns$0$ts, _textRuns$0$ts2, _textRuns$find2, _textRuns$find3, _textRuns$find4;
5171
5119
  const { startOffset, endOffset, collapsed } = textRange;
5172
5120
  if (collapsed) {
5173
- var _body$textRuns;
5174
- const textRuns = (_body$textRuns = body.textRuns) !== null && _body$textRuns !== void 0 ? _body$textRuns : [];
5121
+ const textRuns = body.textRuns ?? [];
5175
5122
  let textRun = null;
5176
5123
  for (let i = textRuns.length - 1; i >= 0; i--) {
5177
5124
  const curTextRun = textRuns[i];
@@ -5193,10 +5140,10 @@ function getStyleInTextRange(body, textRange, defaultStyle) {
5193
5140
  }).filter(Boolean);
5194
5141
  style.fs = style.fs ? Math.max(style.fs, ...fsArr) : fsArr.length ? Math.max(...fsArr) : void 0;
5195
5142
  style.fs = !style.fs || Number.isNaN(style.fs) ? void 0 : style.fs;
5196
- style.ff = (_textRuns$find$ts$ff = (_textRuns$find = textRuns.find((t) => {
5143
+ style.ff = ((_textRuns$find = textRuns.find((t) => {
5197
5144
  var _t$ts2;
5198
5145
  return ((_t$ts2 = t.ts) === null || _t$ts2 === void 0 ? void 0 : _t$ts2.ff) != null;
5199
- })) === null || _textRuns$find === void 0 || (_textRuns$find = _textRuns$find.ts) === null || _textRuns$find === void 0 ? void 0 : _textRuns$find.ff) !== null && _textRuns$find$ts$ff !== void 0 ? _textRuns$find$ts$ff : style.ff;
5146
+ })) === null || _textRuns$find === void 0 || (_textRuns$find = _textRuns$find.ts) === null || _textRuns$find === void 0 ? void 0 : _textRuns$find.ff) ?? style.ff;
5200
5147
  style.it = textRuns.length && textRuns.every((t) => {
5201
5148
  var _t$ts3;
5202
5149
  return ((_t$ts3 = t.ts) === null || _t$ts3 === void 0 ? void 0 : _t$ts3.it) === _univerjs_core.BooleanNumber.TRUE;
@@ -5213,18 +5160,18 @@ function getStyleInTextRange(body, textRange, defaultStyle) {
5213
5160
  var _t$ts6;
5214
5161
  return ((_t$ts6 = t.ts) === null || _t$ts6 === void 0 || (_t$ts6 = _t$ts6.st) === null || _t$ts6 === void 0 ? void 0 : _t$ts6.s) === _univerjs_core.BooleanNumber.TRUE;
5215
5162
  }) ? (_textRuns$0$ts2 = textRuns[0].ts) === null || _textRuns$0$ts2 === void 0 ? void 0 : _textRuns$0$ts2.st : style.st;
5216
- style.bg = (_textRuns$find$ts$bg = (_textRuns$find2 = textRuns.find((t) => {
5163
+ style.bg = ((_textRuns$find2 = textRuns.find((t) => {
5217
5164
  var _t$ts7;
5218
5165
  return ((_t$ts7 = t.ts) === null || _t$ts7 === void 0 ? void 0 : _t$ts7.bg) != null;
5219
- })) === null || _textRuns$find2 === void 0 || (_textRuns$find2 = _textRuns$find2.ts) === null || _textRuns$find2 === void 0 ? void 0 : _textRuns$find2.bg) !== null && _textRuns$find$ts$bg !== void 0 ? _textRuns$find$ts$bg : style.bg;
5220
- style.cl = (_textRuns$find$ts$cl = (_textRuns$find3 = textRuns.find((t) => {
5166
+ })) === null || _textRuns$find2 === void 0 || (_textRuns$find2 = _textRuns$find2.ts) === null || _textRuns$find2 === void 0 ? void 0 : _textRuns$find2.bg) ?? style.bg;
5167
+ style.cl = ((_textRuns$find3 = textRuns.find((t) => {
5221
5168
  var _t$ts8;
5222
5169
  return ((_t$ts8 = t.ts) === null || _t$ts8 === void 0 ? void 0 : _t$ts8.cl) != null;
5223
- })) === null || _textRuns$find3 === void 0 || (_textRuns$find3 = _textRuns$find3.ts) === null || _textRuns$find3 === void 0 ? void 0 : _textRuns$find3.cl) !== null && _textRuns$find$ts$cl !== void 0 ? _textRuns$find$ts$cl : style.cl;
5224
- style.textFill = (_textRuns$find$ts$tex = (_textRuns$find4 = textRuns.find((t) => {
5170
+ })) === null || _textRuns$find3 === void 0 || (_textRuns$find3 = _textRuns$find3.ts) === null || _textRuns$find3 === void 0 ? void 0 : _textRuns$find3.cl) ?? style.cl;
5171
+ style.textFill = ((_textRuns$find4 = textRuns.find((t) => {
5225
5172
  var _t$ts9;
5226
5173
  return ((_t$ts9 = t.ts) === null || _t$ts9 === void 0 ? void 0 : _t$ts9.textFill) != null;
5227
- })) === null || _textRuns$find4 === void 0 || (_textRuns$find4 = _textRuns$find4.ts) === null || _textRuns$find4 === void 0 ? void 0 : _textRuns$find4.textFill) !== null && _textRuns$find$ts$tex !== void 0 ? _textRuns$find$ts$tex : style.textFill;
5174
+ })) === null || _textRuns$find4 === void 0 || (_textRuns$find4 = _textRuns$find4.ts) === null || _textRuns$find4 === void 0 ? void 0 : _textRuns$find4.textFill) ?? style.textFill;
5228
5175
  const vas = textRuns.filter((t) => {
5229
5176
  var _t$ts10;
5230
5177
  return (t === null || t === void 0 || (_t$ts10 = t.ts) === null || _t$ts10 === void 0 ? void 0 : _t$ts10.va) != null;
@@ -5389,7 +5336,6 @@ const ReplaceSelectionCommand = {
5389
5336
  id: "doc.command.replace-selection",
5390
5337
  type: _univerjs_core.CommandType.COMMAND,
5391
5338
  handler(accessor, params) {
5392
- var _params$selection;
5393
5339
  if (!params) return false;
5394
5340
  const commandService = accessor.get(_univerjs_core.ICommandService);
5395
5341
  const { unitId, body: insertBody, textRanges } = params;
@@ -5397,7 +5343,7 @@ const ReplaceSelectionCommand = {
5397
5343
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
5398
5344
  if (!docDataModel) return false;
5399
5345
  const body = docDataModel.getBody();
5400
- const selection = (_params$selection = params.selection) !== null && _params$selection !== void 0 ? _params$selection : docSelectionManagerService.getActiveTextRange();
5346
+ const selection = params.selection ?? docSelectionManagerService.getActiveTextRange();
5401
5347
  if (!selection || !body) return false;
5402
5348
  const doMutation = {
5403
5349
  id: _univerjs_docs.RichTextEditingMutation.id,
@@ -5491,18 +5437,18 @@ const ListOperationCommand = {
5491
5437
  id: "doc.command.list-operation",
5492
5438
  type: _univerjs_core.CommandType.COMMAND,
5493
5439
  handler: (accessor, params) => {
5494
- var _ref, _params$docRange, _segment$getBody$para, _segment$getBody, _segment$getBody$data, _segment$getBody2;
5440
+ var _segment$getBody, _segment$getBody2;
5495
5441
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
5496
5442
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
5497
5443
  const commandService = accessor.get(_univerjs_core.ICommandService);
5498
5444
  const listType = params.listType;
5499
5445
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
5500
- const docRanges = (_ref = (_params$docRange = params.docRange) !== null && _params$docRange !== void 0 ? _params$docRange : docSelectionManagerService.getDocRanges()) !== null && _ref !== void 0 ? _ref : [];
5446
+ const docRanges = params.docRange ?? docSelectionManagerService.getDocRanges() ?? [];
5501
5447
  if (docDataModel == null || docRanges.length === 0) return false;
5502
5448
  const segmentId = docRanges[0].segmentId;
5503
5449
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
5504
- const paragraphs = (_segment$getBody$para = segment === null || segment === void 0 || (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) !== null && _segment$getBody$para !== void 0 ? _segment$getBody$para : [];
5505
- const dataStream = (_segment$getBody$data = segment === null || segment === void 0 || (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) !== null && _segment$getBody$data !== void 0 ? _segment$getBody$data : "";
5450
+ const paragraphs = (segment === null || segment === void 0 || (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) ?? [];
5451
+ const dataStream = (segment === null || segment === void 0 || (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) ?? "";
5506
5452
  if (!paragraphs.length) return false;
5507
5453
  const currentParagraphs = _univerjs_core.BuildTextUtils.range.getParagraphsInRanges(docRanges, paragraphs, dataStream);
5508
5454
  const unitId = docDataModel.getUnitId();
@@ -5533,18 +5479,18 @@ const ChangeListTypeCommand = {
5533
5479
  id: "doc.command.change-list-type",
5534
5480
  type: _univerjs_core.CommandType.COMMAND,
5535
5481
  handler: (accessor, params) => {
5536
- var _params$docRange2, _segment$getBody$para2, _segment$getBody3, _segment$getBody$data2, _segment$getBody4;
5482
+ var _segment$getBody3, _segment$getBody4;
5537
5483
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
5538
5484
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
5539
5485
  const commandService = accessor.get(_univerjs_core.ICommandService);
5540
5486
  const { listType } = params;
5541
5487
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
5542
- const activeRanges = (_params$docRange2 = params.docRange) !== null && _params$docRange2 !== void 0 ? _params$docRange2 : docSelectionManagerService.getDocRanges();
5488
+ const activeRanges = params.docRange ?? docSelectionManagerService.getDocRanges();
5543
5489
  if (docDataModel == null || activeRanges == null || !activeRanges.length) return false;
5544
5490
  const { segmentId } = activeRanges[0];
5545
5491
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
5546
- const paragraphs = (_segment$getBody$para2 = segment === null || segment === void 0 || (_segment$getBody3 = segment.getBody()) === null || _segment$getBody3 === void 0 ? void 0 : _segment$getBody3.paragraphs) !== null && _segment$getBody$para2 !== void 0 ? _segment$getBody$para2 : [];
5547
- const dataStream = (_segment$getBody$data2 = segment === null || segment === void 0 || (_segment$getBody4 = segment.getBody()) === null || _segment$getBody4 === void 0 ? void 0 : _segment$getBody4.dataStream) !== null && _segment$getBody$data2 !== void 0 ? _segment$getBody$data2 : "";
5492
+ const paragraphs = (segment === null || segment === void 0 || (_segment$getBody3 = segment.getBody()) === null || _segment$getBody3 === void 0 ? void 0 : _segment$getBody3.paragraphs) ?? [];
5493
+ const dataStream = (segment === null || segment === void 0 || (_segment$getBody4 = segment.getBody()) === null || _segment$getBody4 === void 0 ? void 0 : _segment$getBody4.dataStream) ?? "";
5548
5494
  if (!paragraphs.length) return false;
5549
5495
  const currentParagraphs = _univerjs_core.BuildTextUtils.range.getParagraphsInRanges(activeRanges, paragraphs, dataStream);
5550
5496
  const unitId = docDataModel.getUnitId();
@@ -5580,7 +5526,7 @@ const ChangeListNestingLevelCommand = {
5580
5526
  id: "doc.command.change-list-nesting-level",
5581
5527
  type: _univerjs_core.CommandType.COMMAND,
5582
5528
  handler: (accessor, params) => {
5583
- var _docSelectionManagerS, _segment$getBody$para3, _segment$getBody5, _segment$getBody$data3, _segment$getBody6;
5529
+ var _segment$getBody5, _segment$getBody6;
5584
5530
  if (!params) return false;
5585
5531
  const { type } = params;
5586
5532
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
@@ -5590,10 +5536,10 @@ const ChangeListNestingLevelCommand = {
5590
5536
  const activeRange = docSelectionManagerService.getActiveTextRange();
5591
5537
  if (docDataModel == null || activeRange == null) return false;
5592
5538
  const { segmentId } = activeRange;
5593
- const selections = (_docSelectionManagerS = docSelectionManagerService.getDocRanges()) !== null && _docSelectionManagerS !== void 0 ? _docSelectionManagerS : [];
5539
+ const selections = docSelectionManagerService.getDocRanges() ?? [];
5594
5540
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
5595
- const paragraphs = (_segment$getBody$para3 = segment === null || segment === void 0 || (_segment$getBody5 = segment.getBody()) === null || _segment$getBody5 === void 0 ? void 0 : _segment$getBody5.paragraphs) !== null && _segment$getBody$para3 !== void 0 ? _segment$getBody$para3 : [];
5596
- const dataStream = (_segment$getBody$data3 = segment === null || segment === void 0 || (_segment$getBody6 = segment.getBody()) === null || _segment$getBody6 === void 0 ? void 0 : _segment$getBody6.dataStream) !== null && _segment$getBody$data3 !== void 0 ? _segment$getBody$data3 : "";
5541
+ const paragraphs = (segment === null || segment === void 0 || (_segment$getBody5 = segment.getBody()) === null || _segment$getBody5 === void 0 ? void 0 : _segment$getBody5.paragraphs) ?? [];
5542
+ const dataStream = (segment === null || segment === void 0 || (_segment$getBody6 = segment.getBody()) === null || _segment$getBody6 === void 0 ? void 0 : _segment$getBody6.dataStream) ?? "";
5597
5543
  if (!paragraphs.length) return false;
5598
5544
  const currentParagraphs = _univerjs_core.BuildTextUtils.range.getParagraphsInRange(activeRange, paragraphs, dataStream);
5599
5545
  const unitId = docDataModel.getUnitId();
@@ -5667,7 +5613,7 @@ const ToggleCheckListCommand = {
5667
5613
  params: {
5668
5614
  unitId,
5669
5615
  actions: [],
5670
- textRanges: textRanges !== null && textRanges !== void 0 ? textRanges : [],
5616
+ textRanges: textRanges ?? [],
5671
5617
  segmentId,
5672
5618
  isEditing: false
5673
5619
  }
@@ -5704,7 +5650,7 @@ const QuickListCommand = {
5704
5650
  id: "doc.command.quick-list",
5705
5651
  type: _univerjs_core.CommandType.COMMAND,
5706
5652
  handler(accessor, params) {
5707
- var _docDataModel$getBody, _docDataModel$getBody2, _paragraph$bullet;
5653
+ var _docDataModel$getBody;
5708
5654
  if (!params) return false;
5709
5655
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
5710
5656
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
@@ -5720,7 +5666,7 @@ const QuickListCommand = {
5720
5666
  const { paragraphStyle = {} } = paragraph;
5721
5667
  const bulletParagraphTextStyle = (_univerjs_core.PRESET_LIST_TYPE[listType].nestingLevel[0].paragraphProperties || {}).textStyle;
5722
5668
  let listId = (0, _univerjs_core.generateRandomId)(6);
5723
- const paragraphs = (_docDataModel$getBody = (_docDataModel$getBody2 = docDataModel.getBody()) === null || _docDataModel$getBody2 === void 0 ? void 0 : _docDataModel$getBody2.paragraphs) !== null && _docDataModel$getBody !== void 0 ? _docDataModel$getBody : [];
5669
+ const paragraphs = ((_docDataModel$getBody = docDataModel.getBody()) === null || _docDataModel$getBody === void 0 ? void 0 : _docDataModel$getBody.paragraphs) ?? [];
5724
5670
  const curIndex = paragraphs.findIndex((i) => i.startIndex === paragraph.startIndex);
5725
5671
  const prevParagraph = paragraphs[curIndex - 1];
5726
5672
  const nextParagraph = paragraphs[curIndex + 1];
@@ -5768,7 +5714,7 @@ const QuickListCommand = {
5768
5714
  indentFirstLine: void 0
5769
5715
  },
5770
5716
  bullet: {
5771
- ...(_paragraph$bullet = paragraph.bullet) !== null && _paragraph$bullet !== void 0 ? _paragraph$bullet : {
5717
+ ...paragraph.bullet ?? {
5772
5718
  nestingLevel: 0,
5773
5719
  textStyle: { fs: 20 }
5774
5720
  },
@@ -5785,7 +5731,6 @@ const QuickListCommand = {
5785
5731
  }
5786
5732
  };
5787
5733
  function insertList(accessor, listType, trigger) {
5788
- var _contentInsertRange$s, _contentInsertRange$e, _sourceParagraph$para;
5789
5734
  const commandService = accessor.get(_univerjs_core.ICommandService);
5790
5735
  const docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
5791
5736
  if (!docDataModel) return false;
@@ -5798,13 +5743,13 @@ function insertList(accessor, listType, trigger) {
5798
5743
  const paragraph = contentInsertRange ? null : getCurrentParagraph(accessor);
5799
5744
  if (!contentInsertRange && !paragraph) return false;
5800
5745
  const sourceParagraph = paragraph || void 0;
5801
- const insertOffset = (_contentInsertRange$s = contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.startOffset) !== null && _contentInsertRange$s !== void 0 ? _contentInsertRange$s : sourceParagraph.startIndex + 1;
5746
+ const insertOffset = (contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.startOffset) ?? sourceParagraph.startIndex + 1;
5802
5747
  const sourceBullet = sourceParagraph === null || sourceParagraph === void 0 ? void 0 : sourceParagraph.bullet;
5803
5748
  const textX = _univerjs_core.BuildTextUtils.selection.replace({
5804
5749
  doc: docDataModel,
5805
5750
  selection: {
5806
5751
  startOffset: insertOffset,
5807
- endOffset: (_contentInsertRange$e = contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.endOffset) !== null && _contentInsertRange$e !== void 0 ? _contentInsertRange$e : insertOffset,
5752
+ endOffset: (contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.endOffset) ?? insertOffset,
5808
5753
  collapsed: true
5809
5754
  },
5810
5755
  body: {
@@ -5812,7 +5757,7 @@ function insertList(accessor, listType, trigger) {
5812
5757
  paragraphs: [{
5813
5758
  startIndex: 0,
5814
5759
  paragraphId: (0, _univerjs_core.createParagraphId)(/* @__PURE__ */ new Set()),
5815
- paragraphStyle: { ...(_sourceParagraph$para = sourceParagraph === null || sourceParagraph === void 0 ? void 0 : sourceParagraph.paragraphStyle) !== null && _sourceParagraph$para !== void 0 ? _sourceParagraph$para : {} },
5760
+ paragraphStyle: { ...(sourceParagraph === null || sourceParagraph === void 0 ? void 0 : sourceParagraph.paragraphStyle) ?? {} },
5816
5761
  bullet: {
5817
5762
  listType,
5818
5763
  listId: (sourceBullet === null || sourceBullet === void 0 ? void 0 : sourceBullet.listType) === listType ? sourceBullet.listId : (0, _univerjs_core.generateRandomId)(6),
@@ -5870,7 +5815,7 @@ const AlignOperationCommand = {
5870
5815
  id: "doc.command.align-action",
5871
5816
  type: _univerjs_core.CommandType.COMMAND,
5872
5817
  handler: (accessor, params) => {
5873
- var _segment$getBody$para, _segment$getBody, _segment$getBody$data, _segment$getBody2;
5818
+ var _segment$getBody, _segment$getBody2;
5874
5819
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
5875
5820
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
5876
5821
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -5881,8 +5826,8 @@ const AlignOperationCommand = {
5881
5826
  if (allRanges.length === 0) return false;
5882
5827
  const segmentId = allRanges[0].segmentId;
5883
5828
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
5884
- const paragraphs = (_segment$getBody$para = segment === null || segment === void 0 || (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) !== null && _segment$getBody$para !== void 0 ? _segment$getBody$para : [];
5885
- const dataStream = (_segment$getBody$data = segment === null || segment === void 0 || (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) !== null && _segment$getBody$data !== void 0 ? _segment$getBody$data : "";
5829
+ const paragraphs = (segment === null || segment === void 0 || (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) ?? [];
5830
+ const dataStream = (segment === null || segment === void 0 || (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) ?? "";
5886
5831
  if (paragraphs == null) return false;
5887
5832
  const currentParagraphs = _univerjs_core.BuildTextUtils.range.getParagraphsInRanges(allRanges, paragraphs, dataStream);
5888
5833
  const unitId = docDataModel.getUnitId();
@@ -6022,7 +5967,6 @@ const SetParagraphNamedStyleCommand = {
6022
5967
  id: "doc.command.set-paragraph-named-style",
6023
5968
  type: _univerjs_core.CommandType.COMMAND,
6024
5969
  handler(accessor, params) {
6025
- var _params$textRanges;
6026
5970
  if (!params) return false;
6027
5971
  const doc = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
6028
5972
  if (!doc) return false;
@@ -6030,7 +5974,7 @@ const SetParagraphNamedStyleCommand = {
6030
5974
  const selectionService = accessor.get(_univerjs_docs.DocSelectionManagerService);
6031
5975
  const contentInsertRange = params.textRanges ? null : (0, _univerjs_docs.consumeContentInsertRange)(accessor, unitId);
6032
5976
  if (contentInsertRange) return insertNamedStyleParagraph(accessor, doc, params.value, contentInsertRange.startOffset, contentInsertRange.endOffset, contentInsertRange.segmentId);
6033
- const selections = (_params$textRanges = params.textRanges) !== null && _params$textRanges !== void 0 ? _params$textRanges : selectionService.getTextRanges({
5977
+ const selections = params.textRanges ?? selectionService.getTextRanges({
6034
5978
  unitId,
6035
5979
  subUnitId: unitId
6036
5980
  });
@@ -6111,7 +6055,7 @@ const QuickHeadingCommand = {
6111
6055
  id: "doc.command.quick-heading",
6112
6056
  type: _univerjs_core.CommandType.COMMAND,
6113
6057
  handler(accessor, params) {
6114
- var _segment$getBody$para, _segment$getBody, _segment$getBody$data, _segment$getBody2;
6058
+ var _segment$getBody, _segment$getBody2;
6115
6059
  if (!params) return false;
6116
6060
  const { value } = params;
6117
6061
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
@@ -6122,8 +6066,8 @@ const QuickHeadingCommand = {
6122
6066
  if (docDataModel == null || activeRange == null || !activeRange.collapsed) return false;
6123
6067
  const { segmentId, startOffset } = activeRange;
6124
6068
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
6125
- const paragraphs = (_segment$getBody$para = segment === null || segment === void 0 || (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) !== null && _segment$getBody$para !== void 0 ? _segment$getBody$para : [];
6126
- const dataStream = (_segment$getBody$data = segment === null || segment === void 0 || (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) !== null && _segment$getBody$data !== void 0 ? _segment$getBody$data : "";
6069
+ const paragraphs = (segment === null || segment === void 0 || (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) ?? [];
6070
+ const dataStream = (segment === null || segment === void 0 || (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) ?? "";
6127
6071
  const paragraph = _univerjs_core.BuildTextUtils.paragraph.util.getParagraphsInRange(activeRange, paragraphs, dataStream)[0];
6128
6072
  if (!paragraph) return false;
6129
6073
  const { paragraphStart } = paragraph;
@@ -6463,7 +6407,7 @@ var NodePositionConvertToCursor = class {
6463
6407
  const isStartBack = start.glyph === start_sp && isFirst ? start.isBack : true;
6464
6408
  const isEndBack = end.glyph === end_sp && isLast ? end.isBack : false;
6465
6409
  const collapsed = start === end;
6466
- const rawAnchorGlyph = isStartBack ? preGlyph !== null && preGlyph !== void 0 ? preGlyph : firstGlyph : firstGlyph;
6410
+ const rawAnchorGlyph = isStartBack ? preGlyph ?? firstGlyph : firstGlyph;
6467
6411
  const anchorGlyph = this._getCaretGlyph(rawAnchorGlyph, glyphGroup, start_sp);
6468
6412
  const selectedGlyphs = glyphGroup.slice(start_sp, end_sp + 1);
6469
6413
  const isSelectionOnlyNonInlineDrawing = !collapsed && selectedGlyphs.length > 0 && selectedGlyphs.every((glyph) => this._isNonInlineDrawingGlyph(glyph));
@@ -6514,10 +6458,8 @@ var NodePositionConvertToCursor = class {
6514
6458
  };
6515
6459
  }
6516
6460
  _getCaretGlyph(glyph, glyphGroup, glyphIndex) {
6517
- var _this$_findTextLikeGl;
6518
6461
  if (!glyph || !this._isNonInlineDrawingGlyph(glyph)) return glyph;
6519
- const neighbor = (_this$_findTextLikeGl = this._findTextLikeGlyph(glyphGroup, glyphIndex - 1, -1)) !== null && _this$_findTextLikeGl !== void 0 ? _this$_findTextLikeGl : this._findTextLikeGlyph(glyphGroup, glyphIndex + 1, 1);
6520
- return neighbor !== null && neighbor !== void 0 ? neighbor : {
6462
+ return this._findTextLikeGlyph(glyphGroup, glyphIndex - 1, -1) ?? this._findTextLikeGlyph(glyphGroup, glyphIndex + 1, 1) ?? {
6521
6463
  ...glyph,
6522
6464
  bBox: getDefaultCaretBoundingBox(glyph)
6523
6465
  };
@@ -6687,8 +6629,7 @@ var NodePositionConvertToCursor = class {
6687
6629
  this._liquid.translatePagePadding(tablePage);
6688
6630
  }
6689
6631
  if (hasHorizontalViewport) {
6690
- var _viewport$leadingInse;
6691
- const visibleLeft = this._liquid.x + tableLeft - ((_viewport$leadingInse = viewport.leadingInsetLeft) !== null && _viewport$leadingInse !== void 0 ? _viewport$leadingInse : 0);
6632
+ const visibleLeft = this._liquid.x + tableLeft - (viewport.leadingInsetLeft ?? 0);
6692
6633
  this._horizontalClip = {
6693
6634
  left: visibleLeft,
6694
6635
  right: visibleLeft + viewport.viewportWidth
@@ -6706,11 +6647,13 @@ var NodePositionConvertToCursor = class {
6706
6647
  const section = sections[s];
6707
6648
  const columns = section.columns;
6708
6649
  const { start_next: start_c, end_next: end_c } = this._getSelectionRuler(NodePositionMap.section, startPosition, endPosition, columns.length - 1, s);
6650
+ this._liquid.translateSave();
6709
6651
  this._liquid.translateSection(section);
6710
6652
  for (let c = start_c; c <= end_c; c++) {
6711
6653
  const column = columns[c];
6712
6654
  const lines = column.lines;
6713
6655
  const { start_next: start_l, end_next: end_l } = this._getSelectionRuler(NodePositionMap.column, startPosition, endPosition, lines.length - 1, c);
6656
+ this._liquid.translateSave();
6714
6657
  this._liquid.translateColumn(column);
6715
6658
  for (let l = start_l; l <= end_l; l++) {
6716
6659
  const line = lines[l];
@@ -6733,7 +6676,9 @@ var NodePositionConvertToCursor = class {
6733
6676
  }
6734
6677
  this._liquid.translateRestore();
6735
6678
  }
6679
+ this._liquid.translateRestore();
6736
6680
  }
6681
+ this._liquid.translateRestore();
6737
6682
  }
6738
6683
  this._liquid.translateRestore();
6739
6684
  this._horizontalClip = previousHorizontalClip;
@@ -6742,8 +6687,7 @@ var NodePositionConvertToCursor = class {
6742
6687
  }
6743
6688
  };
6744
6689
  function hasHorizontalTableViewport$2(viewport) {
6745
- var _viewport$leadingInse2, _viewport$trailingIns;
6746
- return viewport != null && ((_viewport$leadingInse2 = viewport.leadingInsetLeft) !== null && _viewport$leadingInse2 !== void 0 ? _viewport$leadingInse2 : 0) + viewport.contentWidth + ((_viewport$trailingIns = viewport.trailingInsetRight) !== null && _viewport$trailingIns !== void 0 ? _viewport$trailingIns : 0) > viewport.viewportWidth;
6690
+ return viewport != null && (viewport.leadingInsetLeft ?? 0) + viewport.contentWidth + (viewport.trailingInsetRight ?? 0) > viewport.viewportWidth;
6747
6691
  }
6748
6692
  function clipPositionToHorizontalRange(position, clip) {
6749
6693
  if (!clip) return position;
@@ -6788,14 +6732,14 @@ function getDefaultCaretBoundingBox(glyph) {
6788
6732
  };
6789
6733
  }
6790
6734
  function getGlyphFontSize(glyph) {
6791
- var _ref, _glyph$fontStyle$orig, _glyph$fontStyle, _glyph$fontStyle2, _glyph$ts;
6792
- const fontSize = (_ref = (_glyph$fontStyle$orig = (_glyph$fontStyle = glyph.fontStyle) === null || _glyph$fontStyle === void 0 ? void 0 : _glyph$fontStyle.originFontSize) !== null && _glyph$fontStyle$orig !== void 0 ? _glyph$fontStyle$orig : (_glyph$fontStyle2 = glyph.fontStyle) === null || _glyph$fontStyle2 === void 0 ? void 0 : _glyph$fontStyle2.fontSize) !== null && _ref !== void 0 ? _ref : (_glyph$ts = glyph.ts) === null || _glyph$ts === void 0 ? void 0 : _glyph$ts.fs;
6735
+ var _glyph$fontStyle, _glyph$fontStyle2, _glyph$ts;
6736
+ const fontSize = ((_glyph$fontStyle = glyph.fontStyle) === null || _glyph$fontStyle === void 0 ? void 0 : _glyph$fontStyle.originFontSize) ?? ((_glyph$fontStyle2 = glyph.fontStyle) === null || _glyph$fontStyle2 === void 0 ? void 0 : _glyph$fontStyle2.fontSize) ?? ((_glyph$ts = glyph.ts) === null || _glyph$ts === void 0 ? void 0 : _glyph$ts.fs);
6793
6737
  return typeof fontSize === "number" && Number.isFinite(fontSize) && fontSize > 0 ? fontSize : 14;
6794
6738
  }
6795
6739
  function getDocumentUnitId$1(docSkeleton) {
6796
- var _viewModel$getDataMod, _viewModel$getDataMod2, _viewModel$getDataMod3, _viewModel$getDataMod4;
6740
+ var _viewModel$getDataMod, _viewModel$getDataMod2, _viewModel$getDataMod3;
6797
6741
  const viewModel = docSkeleton.getViewModel();
6798
- return (_viewModel$getDataMod = (_viewModel$getDataMod2 = viewModel.getDataModel) === null || _viewModel$getDataMod2 === void 0 || (_viewModel$getDataMod4 = (_viewModel$getDataMod3 = _viewModel$getDataMod2.call(viewModel)).getUnitId) === null || _viewModel$getDataMod4 === void 0 ? void 0 : _viewModel$getDataMod4.call(_viewModel$getDataMod3)) !== null && _viewModel$getDataMod !== void 0 ? _viewModel$getDataMod : "";
6742
+ return ((_viewModel$getDataMod = viewModel.getDataModel) === null || _viewModel$getDataMod === void 0 || (_viewModel$getDataMod3 = (_viewModel$getDataMod2 = _viewModel$getDataMod.call(viewModel)).getUnitId) === null || _viewModel$getDataMod3 === void 0 ? void 0 : _viewModel$getDataMod3.call(_viewModel$getDataMod2)) ?? "";
6799
6743
  }
6800
6744
 
6801
6745
  //#endregion
@@ -6885,8 +6829,8 @@ function getColumnBoundary(table, column) {
6885
6829
  var _table$tableSource;
6886
6830
  const columns = (_table$tableSource = table.tableSource) === null || _table$tableSource === void 0 ? void 0 : _table$tableSource.tableColumns;
6887
6831
  if (columns && column >= 0 && column <= columns.length) return columns.slice(0, column).reduce((total, tableColumn) => {
6888
- var _tableColumn$size$wid, _tableColumn$size;
6889
- return total + ((_tableColumn$size$wid = (_tableColumn$size = tableColumn.size) === null || _tableColumn$size === void 0 || (_tableColumn$size = _tableColumn$size.width) === null || _tableColumn$size === void 0 ? void 0 : _tableColumn$size.v) !== null && _tableColumn$size$wid !== void 0 ? _tableColumn$size$wid : 0);
6832
+ var _tableColumn$size;
6833
+ return total + (((_tableColumn$size = tableColumn.size) === null || _tableColumn$size === void 0 || (_tableColumn$size = _tableColumn$size.width) === null || _tableColumn$size === void 0 ? void 0 : _tableColumn$size.v) ?? 0);
6890
6834
  }, 0);
6891
6835
  const row = table.rows[0];
6892
6836
  const cell = row === null || row === void 0 ? void 0 : row.cells[column];
@@ -6896,15 +6840,14 @@ function getColumnBoundary(table, column) {
6896
6840
  return null;
6897
6841
  }
6898
6842
  function getDocumentUnitId(docSkeleton) {
6899
- var _viewModel$getDataMod, _viewModel$getDataMod2, _viewModel$getDataMod3, _viewModel$getDataMod4;
6843
+ var _viewModel$getDataMod, _viewModel$getDataMod2, _viewModel$getDataMod3;
6900
6844
  const viewModel = docSkeleton.getViewModel();
6901
- return (_viewModel$getDataMod = (_viewModel$getDataMod2 = viewModel.getDataModel) === null || _viewModel$getDataMod2 === void 0 || (_viewModel$getDataMod4 = (_viewModel$getDataMod3 = _viewModel$getDataMod2.call(viewModel)).getUnitId) === null || _viewModel$getDataMod4 === void 0 ? void 0 : _viewModel$getDataMod4.call(_viewModel$getDataMod3)) !== null && _viewModel$getDataMod !== void 0 ? _viewModel$getDataMod : "";
6845
+ return ((_viewModel$getDataMod = viewModel.getDataModel) === null || _viewModel$getDataMod === void 0 || (_viewModel$getDataMod3 = (_viewModel$getDataMod2 = _viewModel$getDataMod.call(viewModel)).getUnitId) === null || _viewModel$getDataMod3 === void 0 ? void 0 : _viewModel$getDataMod3.call(_viewModel$getDataMod2)) ?? "";
6902
6846
  }
6903
6847
  function pushViewportClippedPoints(pointGroup, position, viewport, tableLeft) {
6904
- var _viewport$leadingInse;
6905
6848
  const scrollLeft = hasHorizontalTableViewport$1(viewport) ? viewport.scrollLeft : 0;
6906
6849
  const viewportWidth = hasHorizontalTableViewport$1(viewport) ? viewport.viewportWidth : null;
6907
- const visibleLeft = tableLeft - ((_viewport$leadingInse = viewport === null || viewport === void 0 ? void 0 : viewport.leadingInsetLeft) !== null && _viewport$leadingInse !== void 0 ? _viewport$leadingInse : 0);
6850
+ const visibleLeft = tableLeft - ((viewport === null || viewport === void 0 ? void 0 : viewport.leadingInsetLeft) ?? 0);
6908
6851
  const startX = position.startX - scrollLeft;
6909
6852
  const endX = position.endX - scrollLeft;
6910
6853
  const clippedStartX = viewportWidth == null ? startX : Math.max(startX, visibleLeft);
@@ -6917,8 +6860,7 @@ function pushViewportClippedPoints(pointGroup, position, viewport, tableLeft) {
6917
6860
  }));
6918
6861
  }
6919
6862
  function hasHorizontalTableViewport$1(viewport) {
6920
- var _viewport$leadingInse2, _viewport$trailingIns;
6921
- return viewport != null && ((_viewport$leadingInse2 = viewport.leadingInsetLeft) !== null && _viewport$leadingInse2 !== void 0 ? _viewport$leadingInse2 : 0) + viewport.contentWidth + ((_viewport$trailingIns = viewport.trailingInsetRight) !== null && _viewport$trailingIns !== void 0 ? _viewport$trailingIns : 0) > viewport.viewportWidth;
6863
+ return viewport != null && (viewport.leadingInsetLeft ?? 0) + viewport.contentWidth + (viewport.trailingInsetRight ?? 0) > viewport.viewportWidth;
6922
6864
  }
6923
6865
  var NodePositionConvertToRectRange = class {
6924
6866
  constructor(_documentOffsetConfig, _docSkeleton) {
@@ -6927,7 +6869,6 @@ var NodePositionConvertToRectRange = class {
6927
6869
  _defineProperty(this, "_liquid", new _univerjs_engine_render.Liquid());
6928
6870
  }
6929
6871
  getRangePointData(startNodePosition, endNodePosition) {
6930
- var _this$_documentOffset, _this$_documentOffset2;
6931
6872
  const pointGroup = [];
6932
6873
  const docSkeleton = this._docSkeleton;
6933
6874
  const skeletonData = docSkeleton.getSkeletonData();
@@ -6942,8 +6883,8 @@ var NodePositionConvertToRectRange = class {
6942
6883
  const unitId = getDocumentUnitId(docSkeleton);
6943
6884
  const sourceTableId = (0, _univerjs_engine_render.getTableIdAndSliceIndex)(tableId).tableId;
6944
6885
  const nestedTableContexts = (0, _univerjs_engine_render.documentSkeletonTableIterator)(pages, {
6945
- docsLeft: (_this$_documentOffset = this._documentOffsetConfig.docsLeft) !== null && _this$_documentOffset !== void 0 ? _this$_documentOffset : 0,
6946
- docsTop: (_this$_documentOffset2 = this._documentOffsetConfig.docsTop) !== null && _this$_documentOffset2 !== void 0 ? _this$_documentOffset2 : 0,
6886
+ docsLeft: this._documentOffsetConfig.docsLeft ?? 0,
6887
+ docsTop: this._documentOffsetConfig.docsTop ?? 0,
6947
6888
  pageMarginTop,
6948
6889
  skeFooters: skeletonData === null || skeletonData === void 0 ? void 0 : skeletonData.skeFooters,
6949
6890
  skeHeaders: skeletonData === null || skeletonData === void 0 ? void 0 : skeletonData.skeHeaders,
@@ -6964,11 +6905,10 @@ var NodePositionConvertToRectRange = class {
6964
6905
  if (table == null) {
6965
6906
  const nestedTableContext = nestedTableContexts.find((context) => context.pageIndex === p && (context.source === "column" || context.source === "header" || context.source === "footer") && context.tableId.startsWith(tableId));
6966
6907
  if (nestedTableContext) {
6967
- var _this$_documentOffset3, _this$_documentOffset4;
6968
6908
  const nestedTable = nestedTableContext.table;
6969
6909
  const viewport = (0, _univerjs_engine_render.getDocsTableRenderViewport)(unitId, sourceTableId);
6970
- const nestedX = nestedTableContext.tableRect.left - nestedTable.left - ((_this$_documentOffset3 = this._documentOffsetConfig.docsLeft) !== null && _this$_documentOffset3 !== void 0 ? _this$_documentOffset3 : 0);
6971
- const nestedY = nestedTableContext.tableRect.top - ((_this$_documentOffset4 = this._documentOffsetConfig.docsTop) !== null && _this$_documentOffset4 !== void 0 ? _this$_documentOffset4 : 0);
6910
+ const nestedX = nestedTableContext.tableRect.left - nestedTable.left - (this._documentOffsetConfig.docsLeft ?? 0);
6911
+ const nestedY = nestedTableContext.tableRect.top - (this._documentOffsetConfig.docsTop ?? 0);
6972
6912
  if (intersectsMergedCell) {
6973
6913
  const rows = nestedTable.rows.filter((row) => row.index >= startRow && row.index <= endRow);
6974
6914
  const firstRow = rows[0];
@@ -7134,9 +7074,8 @@ function expandRangeByMergedCells(table, range) {
7134
7074
  changed = false;
7135
7075
  table.tableRows.forEach((row, rowIndex) => {
7136
7076
  row.tableCells.forEach((cell, columnIndex) => {
7137
- var _cell$rowSpan, _cell$columnSpan;
7138
- const rowSpan = (_cell$rowSpan = cell.rowSpan) !== null && _cell$rowSpan !== void 0 ? _cell$rowSpan : 1;
7139
- const columnSpan = (_cell$columnSpan = cell.columnSpan) !== null && _cell$columnSpan !== void 0 ? _cell$columnSpan : 1;
7077
+ const rowSpan = cell.rowSpan ?? 1;
7078
+ const columnSpan = cell.columnSpan ?? 1;
7140
7079
  if (rowSpan <= 0 || columnSpan <= 0 || rowSpan === 1 && columnSpan === 1) return;
7141
7080
  const mergedRange = {
7142
7081
  startRowIndex: rowIndex,
@@ -7164,9 +7103,8 @@ function rangeIntersectsMergedCell(table, range) {
7164
7103
  if (!table) return false;
7165
7104
  const normalized = normalizeRange(range);
7166
7105
  return table.tableRows.some((row, rowIndex) => row.tableCells.some((cell, columnIndex) => {
7167
- var _cell$rowSpan2, _cell$columnSpan2;
7168
- const rowSpan = (_cell$rowSpan2 = cell.rowSpan) !== null && _cell$rowSpan2 !== void 0 ? _cell$rowSpan2 : 1;
7169
- const columnSpan = (_cell$columnSpan2 = cell.columnSpan) !== null && _cell$columnSpan2 !== void 0 ? _cell$columnSpan2 : 1;
7106
+ const rowSpan = cell.rowSpan ?? 1;
7107
+ const columnSpan = cell.columnSpan ?? 1;
7170
7108
  if (rowSpan <= 0 || columnSpan <= 0 || rowSpan === 1 && columnSpan === 1) return false;
7171
7109
  return rangesIntersect(normalized, {
7172
7110
  startRowIndex: rowIndex,
@@ -7296,16 +7234,16 @@ var TextRange = class {
7296
7234
  }, 1e3);
7297
7235
  }
7298
7236
  get startOffset() {
7299
- var _getOneTextSelectionR, _this$_docSkeleton$ge;
7300
- const { startOffset } = (_getOneTextSelectionR = getOneTextSelectionRange(this._cursorList)) !== null && _getOneTextSelectionR !== void 0 ? _getOneTextSelectionR : {};
7237
+ var _this$_docSkeleton$ge;
7238
+ const { startOffset } = getOneTextSelectionRange(this._cursorList) ?? {};
7301
7239
  const body = (_this$_docSkeleton$ge = this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId)) === null || _this$_docSkeleton$ge === void 0 ? void 0 : _this$_docSkeleton$ge.getBody();
7302
7240
  if (startOffset == null || body == null) return startOffset;
7303
7241
  const maxLength = body.dataStream.length - 2;
7304
7242
  return Math.min(maxLength, startOffset);
7305
7243
  }
7306
7244
  get endOffset() {
7307
- var _getOneTextSelectionR2, _this$_docSkeleton$ge2;
7308
- const { endOffset } = (_getOneTextSelectionR2 = getOneTextSelectionRange(this._cursorList)) !== null && _getOneTextSelectionR2 !== void 0 ? _getOneTextSelectionR2 : {};
7245
+ var _this$_docSkeleton$ge2;
7246
+ const { endOffset } = getOneTextSelectionRange(this._cursorList) ?? {};
7309
7247
  const body = (_this$_docSkeleton$ge2 = this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId)) === null || _this$_docSkeleton$ge2 === void 0 ? void 0 : _this$_docSkeleton$ge2.getBody();
7310
7248
  if (endOffset == null || body == null) return endOffset;
7311
7249
  const maxLength = body.dataStream.length - 2;
@@ -7512,7 +7450,7 @@ function convertPositionsToRectRanges(scene, document, docSkeleton, anchorNodePo
7512
7450
  const nodePositionGroup = new NodePositionConvertToRectRange(document.getOffsetConfig(), docSkeleton).getNodePositionGroup(anchorNodePosition, focusNodePosition);
7513
7451
  const ranges = [];
7514
7452
  try {
7515
- for (const position of nodePositionGroup !== null && nodePositionGroup !== void 0 ? nodePositionGroup : []) ranges.push(new RectRange(scene, document, docSkeleton, position.anchor, position.focus, style, segmentId, segmentPage));
7453
+ for (const position of nodePositionGroup ?? []) ranges.push(new RectRange(scene, document, docSkeleton, position.anchor, position.focus, style, segmentId, segmentPage));
7516
7454
  return ranges;
7517
7455
  } catch (error) {
7518
7456
  ranges.forEach((range) => range.dispose());
@@ -7692,11 +7630,11 @@ function getDescendantTables(node) {
7692
7630
  return node.children.flatMap(getDescendantTables);
7693
7631
  }
7694
7632
  function isInSameColumnPage(anchorPosition, focusPosition) {
7695
- var _anchorPosition$path$, _anchorPosition$path, _focusPosition$path$i, _focusPosition$path;
7633
+ var _anchorPosition$path, _focusPosition$path;
7696
7634
  const anchorColumnInfo = (0, _univerjs_engine_render.getDocumentSkeletonColumnPagePathInfo)(anchorPosition);
7697
7635
  const focusColumnInfo = (0, _univerjs_engine_render.getDocumentSkeletonColumnPagePathInfo)(focusPosition);
7698
- const anchorPageIndex = (_anchorPosition$path$ = (_anchorPosition$path = anchorPosition.path) === null || _anchorPosition$path === void 0 ? void 0 : _anchorPosition$path.indexOf("page")) !== null && _anchorPosition$path$ !== void 0 ? _anchorPosition$path$ : -1;
7699
- const focusPageIndex = (_focusPosition$path$i = (_focusPosition$path = focusPosition.path) === null || _focusPosition$path === void 0 ? void 0 : _focusPosition$path.indexOf("page")) !== null && _focusPosition$path$i !== void 0 ? _focusPosition$path$i : -1;
7636
+ const anchorPageIndex = ((_anchorPosition$path = anchorPosition.path) === null || _anchorPosition$path === void 0 ? void 0 : _anchorPosition$path.indexOf("page")) ?? -1;
7637
+ const focusPageIndex = ((_focusPosition$path = focusPosition.path) === null || _focusPosition$path === void 0 ? void 0 : _focusPosition$path.indexOf("page")) ?? -1;
7700
7638
  return anchorPageIndex >= 0 && focusPageIndex >= 0 && anchorPageIndex === anchorPosition.path.length - 1 && focusPageIndex === focusPosition.path.length - 1 && !!anchorColumnInfo && !!focusColumnInfo && anchorColumnInfo.pageIndex === focusColumnInfo.pageIndex && anchorColumnInfo.columnGroupId === focusColumnInfo.columnGroupId && anchorColumnInfo.columnIndex === focusColumnInfo.columnIndex;
7701
7639
  }
7702
7640
  function getColumnInputBoundaryCollapsedPosition(anchorPosition, focusPosition, skeleton) {
@@ -7784,14 +7722,8 @@ function getRangeListFromSelection(anchorPosition, focusPosition, scene, documen
7784
7722
  const startOffset = Math.min(anchorOffset, focusOffset);
7785
7723
  const endOffset = Math.max(anchorOffset, focusOffset);
7786
7724
  const originRange = compareNodePosition(anchorPosition, focusPosition);
7787
- const findStartNodePositionByCharIndex = (charIndex, isBack = true) => {
7788
- var _skeleton$findNodePos;
7789
- return (_skeleton$findNodePos = skeleton.findNodePositionByCharIndex(charIndex, isBack, segmentId, segmentPage)) !== null && _skeleton$findNodePos !== void 0 ? _skeleton$findNodePos : charIndex === startOffset ? originRange.start : void 0;
7790
- };
7791
- const findEndNodePositionByCharIndex = (charIndex, isBack = true) => {
7792
- var _skeleton$findNodePos2;
7793
- return (_skeleton$findNodePos2 = skeleton.findNodePositionByCharIndex(charIndex, isBack, segmentId, segmentPage)) !== null && _skeleton$findNodePos2 !== void 0 ? _skeleton$findNodePos2 : charIndex === endOffset ? originRange.end : void 0;
7794
- };
7725
+ const findStartNodePositionByCharIndex = (charIndex, isBack = true) => skeleton.findNodePositionByCharIndex(charIndex, isBack, segmentId, segmentPage) ?? (charIndex === startOffset ? originRange.start : void 0);
7726
+ const findEndNodePositionByCharIndex = (charIndex, isBack = true) => skeleton.findNodePositionByCharIndex(charIndex, isBack, segmentId, segmentPage) ?? (charIndex === endOffset ? originRange.end : void 0);
7795
7727
  const appendTextRange = (rangeStart, rangeEnd, endIsBack = true) => {
7796
7728
  if (rangeStart > rangeEnd) return true;
7797
7729
  const sp = findStartNodePositionByCharIndex(rangeStart, true);
@@ -8055,9 +7987,8 @@ function getNextWordBoundaryOffset(content, nodeIndex, paragraphStartOffset, dir
8055
7987
  return paragraphStartOffset;
8056
7988
  }
8057
7989
  if (direction === _univerjs_core.Direction.RIGHT) {
8058
- var _target$end;
8059
7990
  const target = ranges.find((range) => range.end > nodeIndex);
8060
- return paragraphStartOffset + ((_target$end = target === null || target === void 0 ? void 0 : target.end) !== null && _target$end !== void 0 ? _target$end : content.length);
7991
+ return paragraphStartOffset + ((target === null || target === void 0 ? void 0 : target.end) ?? content.length);
8061
7992
  }
8062
7993
  return null;
8063
7994
  }
@@ -8189,9 +8120,8 @@ let DocSelectionRenderService = class DocSelectionRenderService extends _univerj
8189
8120
  this._addRectRanges(rectRanges);
8190
8121
  };
8191
8122
  for (const range of ranges) {
8192
- var _range$style;
8193
8123
  const { startOffset, endOffset, rangeType, startNodePosition, endNodePosition } = range;
8194
- const rangeStyle = (_range$style = range.style) !== null && _range$style !== void 0 ? _range$style : style;
8124
+ const rangeStyle = range.style ?? style;
8195
8125
  if (rangeType !== _univerjs_core.DOC_RANGE_TYPE.RECT && startOffset === endOffset) {
8196
8126
  const textRange = cursorConvertToTextRange(scene, {
8197
8127
  ...range,
@@ -8430,7 +8360,7 @@ let DocSelectionRenderService = class DocSelectionRenderService extends _univerj
8430
8360
  strokeWidth: 1,
8431
8361
  stroke: "rgba(0, 0, 0, 0)",
8432
8362
  strokeActive: "rgba(0, 0, 0, 1)",
8433
- fill: `rgba(${r}, ${g}, ${b}, ${a !== null && a !== void 0 ? a : .3})`
8363
+ fill: `rgba(${r}, ${g}, ${b}, ${a ?? .3})`
8434
8364
  };
8435
8365
  this._setRangeStyle(style);
8436
8366
  }
@@ -8516,8 +8446,8 @@ let DocSelectionRenderService = class DocSelectionRenderService extends _univerj
8516
8446
  if (this._container.parentElement !== document.body) document.body.appendChild(this._container);
8517
8447
  }
8518
8448
  _getOwnerDocument() {
8519
- var _this$_container$owne, _this$_container;
8520
- return (_this$_container$owne = (_this$_container = this._container) === null || _this$_container === void 0 ? void 0 : _this$_container.ownerDocument) !== null && _this$_container$owne !== void 0 ? _this$_container$owne : document;
8449
+ var _this$_container;
8450
+ return ((_this$_container = this._container) === null || _this$_container === void 0 ? void 0 : _this$_container.ownerDocument) ?? document;
8521
8451
  }
8522
8452
  _getNodePosition(node) {
8523
8453
  if (node == null) return;
@@ -8887,14 +8817,14 @@ let DocSelectionRenderService = class DocSelectionRenderService extends _univerj
8887
8817
  return this._getElementEmbedOwner(element) === currentEmbedOwner && this._containsCurrentLayoutElement(element);
8888
8818
  }
8889
8819
  _getCurrentEmbedOwner() {
8890
- var _this$_layoutService, _ref, _this$_getElementEmbe;
8820
+ var _this$_layoutService;
8891
8821
  const rootContainerElement = (_this$_layoutService = this._layoutService) === null || _this$_layoutService === void 0 ? void 0 : _this$_layoutService.rootContainerElement;
8892
- return (_ref = (_this$_getElementEmbe = this._getElementEmbedOwner(this._input)) !== null && _this$_getElementEmbe !== void 0 ? _this$_getElementEmbe : this._getElementEmbedOwner(this._container)) !== null && _ref !== void 0 ? _ref : this._getElementEmbedOwner(rootContainerElement instanceof HTMLElement ? rootContainerElement : void 0);
8822
+ return this._getElementEmbedOwner(this._input) ?? this._getElementEmbedOwner(this._container) ?? this._getElementEmbedOwner(rootContainerElement instanceof HTMLElement ? rootContainerElement : void 0);
8893
8823
  }
8894
8824
  _getElementEmbedOwner(element) {
8895
- var _element$closest$getA, _element$closest;
8825
+ var _element$closest;
8896
8826
  if (!element || typeof element.closest !== "function") return;
8897
- return (_element$closest$getA = (_element$closest = element.closest(`[${"data-embed-interaction-boundary-owner"}]`)) === null || _element$closest === void 0 ? void 0 : _element$closest.getAttribute("data-embed-interaction-boundary-owner")) !== null && _element$closest$getA !== void 0 ? _element$closest$getA : void 0;
8827
+ return ((_element$closest = element.closest(`[${"data-embed-interaction-boundary-owner"}]`)) === null || _element$closest === void 0 ? void 0 : _element$closest.getAttribute("data-embed-interaction-boundary-owner")) ?? void 0;
8898
8828
  }
8899
8829
  _containsOwnEditorElement(element) {
8900
8830
  var _this$_container2, _this$_inputParent;
@@ -8973,9 +8903,8 @@ const SwitchDocModeCommand = {
8973
8903
  if (action) rawActions.push(action);
8974
8904
  else return false;
8975
8905
  if (oldDocumentFlavor !== _univerjs_core.DocumentFlavor.MODERN) {
8976
- var _body$customBlocks;
8977
8906
  const { drawings = {}, body } = docDataModel.getSnapshot();
8978
- const customBlocks = (_body$customBlocks = body === null || body === void 0 ? void 0 : body.customBlocks) !== null && _body$customBlocks !== void 0 ? _body$customBlocks : [];
8907
+ const customBlocks = (body === null || body === void 0 ? void 0 : body.customBlocks) ?? [];
8979
8908
  for (const drawingId in drawings) {
8980
8909
  var _glyph$parent, _column$parent;
8981
8910
  const drawing = drawings[drawingId];
@@ -8998,7 +8927,7 @@ const SwitchDocModeCommand = {
8998
8927
  const newPositionV = {
8999
8928
  ...drawingPositionV,
9000
8929
  relativeFrom: _univerjs_core.ObjectRelativeFromV.PARAGRAPH,
9001
- posOffset: (prevPosOffset !== null && prevPosOffset !== void 0 ? prevPosOffset : 0) - delta
8930
+ posOffset: (prevPosOffset ?? 0) - delta
9002
8931
  };
9003
8932
  const updateDrawingAction = jsonX.replaceOp([
9004
8933
  "drawings",
@@ -9021,9 +8950,8 @@ const SwitchDocModeCommand = {
9021
8950
  //#region src/commands/commands/table/doc-table-create.command.ts
9022
8951
  const CreateDocTableCommandId = "doc.command.create-table";
9023
8952
  function buildDocTableInsertBody(params) {
9024
- var _params$existingParag;
9025
8953
  const { tableDataStream, tableParagraphs, sectionBreaks, tableId, textRun } = params;
9026
- const existingParagraphIds = (_params$existingParag = params.existingParagraphIds) !== null && _params$existingParag !== void 0 ? _params$existingParag : new Set(tableParagraphs.map((paragraph) => paragraph.paragraphId));
8954
+ const existingParagraphIds = params.existingParagraphIds ?? new Set(tableParagraphs.map((paragraph) => paragraph.paragraphId));
9027
8955
  const dataStream = `${tableDataStream}${_univerjs_core.DataStreamTreeTokenType.PARAGRAPH}`;
9028
8956
  const tableEnd = tableDataStream.length;
9029
8957
  return {
@@ -9070,7 +8998,7 @@ const CreateDocTableCommand = {
9070
8998
  id: CreateDocTableCommandId,
9071
8999
  type: _univerjs_core.CommandType.COMMAND,
9072
9000
  handler: async (accessor, params) => {
9073
- var _ref, _contentInsertRange$s, _docDataModel$getSelf, _contentInsertRange$s2, _body$paragraphs, _curGlyph$parent, _body$paragraphs2;
9001
+ var _docDataModel$getSelf, _curGlyph$parent, _body$paragraphs;
9074
9002
  const { rowCount, colCount } = params;
9075
9003
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
9076
9004
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
@@ -9086,7 +9014,7 @@ const CreateDocTableCommand = {
9086
9014
  }
9087
9015
  const activeRange = docSelectionManagerService.getActiveTextRange();
9088
9016
  if (activeRange == null && contentInsertRange == null) return false;
9089
- const segmentId = (_ref = (_contentInsertRange$s = contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.segmentId) !== null && _contentInsertRange$s !== void 0 ? _contentInsertRange$s : activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentId) !== null && _ref !== void 0 ? _ref : "";
9017
+ const segmentId = (contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.segmentId) ?? (activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentId) ?? "";
9090
9018
  const segmentPage = activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentPage;
9091
9019
  const body = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
9092
9020
  if (body == null) return false;
@@ -9094,9 +9022,9 @@ const CreateDocTableCommand = {
9094
9022
  const docSkeletonManagerService = getCommandSkeleton(accessor, unitId);
9095
9023
  const skeleton = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getSkeleton();
9096
9024
  if (skeleton == null) return false;
9097
- const startOffset = normalizeTableInsertOffset(body, (_contentInsertRange$s2 = contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.startOffset) !== null && _contentInsertRange$s2 !== void 0 ? _contentInsertRange$s2 : activeRange.startOffset);
9025
+ const startOffset = normalizeTableInsertOffset(body, (contentInsertRange === null || contentInsertRange === void 0 ? void 0 : contentInsertRange.startOffset) ?? activeRange.startOffset);
9098
9026
  if (!canInsertTableAtOffset(body, startOffset)) return false;
9099
- const prevParagraph = ((_body$paragraphs = body.paragraphs) !== null && _body$paragraphs !== void 0 ? _body$paragraphs : []).find((paragraph) => {
9027
+ const prevParagraph = (body.paragraphs ?? []).find((paragraph) => {
9100
9028
  return (0, _univerjs_core.getParagraphContentStartOffset)(body, paragraph) < startOffset && startOffset <= paragraph.startIndex;
9101
9029
  });
9102
9030
  const curGlyph = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage);
@@ -9143,7 +9071,7 @@ const CreateDocTableCommand = {
9143
9071
  sectionBreaks,
9144
9072
  tableId: tableSource.tableId,
9145
9073
  textRun: curTextRun,
9146
- existingParagraphIds: new Set((_body$paragraphs2 = body.paragraphs) === null || _body$paragraphs2 === void 0 ? void 0 : _body$paragraphs2.map((paragraph) => paragraph.paragraphId))
9074
+ existingParagraphIds: new Set((_body$paragraphs = body.paragraphs) === null || _body$paragraphs === void 0 ? void 0 : _body$paragraphs.map((paragraph) => paragraph.paragraphId))
9147
9075
  });
9148
9076
  textX.push({
9149
9077
  t: _univerjs_core.TextXActionType.INSERT,
@@ -9313,13 +9241,13 @@ const DocTableDeleteTableCommand = {
9313
9241
  id: "doc.table.delete-table",
9314
9242
  type: _univerjs_core.CommandType.COMMAND,
9315
9243
  handler: async (accessor, params) => {
9316
- var _params$targetRange, _docDataModel$getSelf3;
9244
+ var _docDataModel$getSelf3;
9317
9245
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
9318
9246
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
9319
9247
  const commandService = accessor.get(_univerjs_core.ICommandService);
9320
9248
  const activeRectRanges = docSelectionManagerService.getRectRanges();
9321
9249
  const activeTextRange = docSelectionManagerService.getActiveTextRange();
9322
- const rangeInfo = getRangeInfoFromRanges((_params$targetRange = params === null || params === void 0 ? void 0 : params.targetRange) !== null && _params$targetRange !== void 0 ? _params$targetRange : activeTextRange, (params === null || params === void 0 ? void 0 : params.targetRange) ? [] : activeRectRanges);
9250
+ const rangeInfo = getRangeInfoFromRanges((params === null || params === void 0 ? void 0 : params.targetRange) ?? activeTextRange, (params === null || params === void 0 ? void 0 : params.targetRange) ? [] : activeRectRanges);
9323
9251
  if (rangeInfo == null) return false;
9324
9252
  const { segmentId } = rangeInfo;
9325
9253
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
@@ -9481,7 +9409,7 @@ const DocTableInsertColumnCommand = {
9481
9409
  id: DocTableInsertColumnCommandId,
9482
9410
  type: _univerjs_core.CommandType.COMMAND,
9483
9411
  handler: async (accessor, params) => {
9484
- var _docDataModel$getSelf2, _snapshot$tableSource, _documentStyle$pageSi, _documentStyle$pageSi2;
9412
+ var _docDataModel$getSelf2, _snapshot$tableSource, _documentStyle$pageSi;
9485
9413
  const { position } = params;
9486
9414
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
9487
9415
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
@@ -9548,7 +9476,7 @@ const DocTableInsertColumnCommand = {
9548
9476
  const { marginLeft = 0, marginRight = 0 } = documentStyle;
9549
9477
  const tableColumns = snapshot === null || snapshot === void 0 || (_snapshot$tableSource = snapshot.tableSource) === null || _snapshot$tableSource === void 0 || (_snapshot$tableSource = _snapshot$tableSource[tableId]) === null || _snapshot$tableSource === void 0 ? void 0 : _snapshot$tableSource.tableColumns;
9550
9478
  if (!tableColumns) return false;
9551
- const pageWidth = ((_documentStyle$pageSi = (_documentStyle$pageSi2 = documentStyle.pageSize) === null || _documentStyle$pageSi2 === void 0 ? void 0 : _documentStyle$pageSi2.width) !== null && _documentStyle$pageSi !== void 0 ? _documentStyle$pageSi : 800) - marginLeft - marginRight;
9479
+ const pageWidth = (((_documentStyle$pageSi = documentStyle.pageSize) === null || _documentStyle$pageSi === void 0 ? void 0 : _documentStyle$pageSi.width) ?? 800) - marginLeft - marginRight;
9552
9480
  const tableWidth = tableColumns.reduce((sum, column) => sum + column.size.width.v, 0);
9553
9481
  const { newColWidth, widths } = getColumnWidths(tableWidth > 0 ? tableWidth : pageWidth, tableColumns, columnIndex);
9554
9482
  for (let i = 0; i < widths.length; i++) {
@@ -9585,14 +9513,13 @@ const DocTableTabCommand = {
9585
9513
  id: "doc.table.tab-in-table",
9586
9514
  type: _univerjs_core.CommandType.COMMAND,
9587
9515
  handler: async (accessor, params) => {
9588
- var _docRanges$find;
9589
9516
  const { shift } = params;
9590
9517
  const textSelectionManager = accessor.get(_univerjs_docs.DocSelectionManagerService);
9591
9518
  const docRanges = textSelectionManager.getDocRanges();
9592
9519
  const commandService = accessor.get(_univerjs_core.ICommandService);
9593
9520
  const docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
9594
9521
  if (!docDataModel) return false;
9595
- const activeRange = (_docRanges$find = docRanges.find((range) => range.isActive)) !== null && _docRanges$find !== void 0 ? _docRanges$find : docRanges[0];
9522
+ const activeRange = docRanges.find((range) => range.isActive) ?? docRanges[0];
9596
9523
  const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
9597
9524
  const skeleton = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getSkeleton();
9598
9525
  const viewModel = skeleton === null || skeleton === void 0 ? void 0 : skeleton.getViewModel().getSelfOrHeaderFooterViewModel(activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentId);
@@ -9725,15 +9652,14 @@ const DOC_TRADITIONAL_WORKSPACE_BACKGROUND_COLOR = "#fafafa";
9725
9652
  const DOC_MODERN_WORKSPACE_BACKGROUND_COLOR = "#fff";
9726
9653
  const DOC_EDITOR_INTERNAL_BACKGROUND_COLOR = "transparent";
9727
9654
  function resolveDocRenderBackground(options) {
9728
- var _canvasColorService$g;
9729
9655
  const { documentFlavor, canvasColorService, editorBackgroundColor, isEditor } = options;
9730
- const backgroundColor = editorBackgroundColor !== null && editorBackgroundColor !== void 0 ? editorBackgroundColor : getDefaultDocCanvasBackgroundColor(documentFlavor, isEditor);
9656
+ const backgroundColor = editorBackgroundColor ?? getDefaultDocCanvasBackgroundColor(documentFlavor, isEditor);
9731
9657
  if (isEditor) return {
9732
9658
  canvasElementBackgroundColor: backgroundColor,
9733
9659
  docBackgroundFillColor: DOC_EDITOR_INTERNAL_BACKGROUND_COLOR
9734
9660
  };
9735
9661
  return {
9736
- canvasElementBackgroundColor: (_canvasColorService$g = canvasColorService === null || canvasColorService === void 0 ? void 0 : canvasColorService.getRenderColor(backgroundColor)) !== null && _canvasColorService$g !== void 0 ? _canvasColorService$g : backgroundColor,
9662
+ canvasElementBackgroundColor: (canvasColorService === null || canvasColorService === void 0 ? void 0 : canvasColorService.getRenderColor(backgroundColor)) ?? backgroundColor,
9737
9663
  docBackgroundFillColor: void 0
9738
9664
  };
9739
9665
  }
@@ -9850,8 +9776,8 @@ var Editor = class extends _univerjs_core.Disposable {
9850
9776
  return this._docSelectionManagerService.getDocRanges(params);
9851
9777
  }
9852
9778
  getCursorPosition() {
9853
- var _selectionRanges$find, _selectionRanges$find2;
9854
- return (_selectionRanges$find = (_selectionRanges$find2 = this.getSelectionRanges().find((range) => range.collapsed)) === null || _selectionRanges$find2 === void 0 ? void 0 : _selectionRanges$find2.startOffset) !== null && _selectionRanges$find !== void 0 ? _selectionRanges$find : -1;
9779
+ var _selectionRanges$find;
9780
+ return ((_selectionRanges$find = this.getSelectionRanges().find((range) => range.collapsed)) === null || _selectionRanges$find === void 0 ? void 0 : _selectionRanges$find.startOffset) ?? -1;
9855
9781
  }
9856
9782
  getEditorId() {
9857
9783
  return this._getEditorId();
@@ -9905,9 +9831,8 @@ var Editor = class extends _univerjs_core.Disposable {
9905
9831
  return this._param.cancelDefaultResizeListener;
9906
9832
  }
9907
9833
  getRenderConfig() {
9908
- var _this$_param$canvasSt;
9909
9834
  return {
9910
- canvasStyle: (_this$_param$canvasSt = this._param.canvasStyle) !== null && _this$_param$canvasSt !== void 0 ? _this$_param$canvasSt : {},
9835
+ canvasStyle: this._param.canvasStyle ?? {},
9911
9836
  scrollBar: this._param.scrollBar,
9912
9837
  ...this._param.backScrollOffset === void 0 ? {} : { backScrollOffset: this._param.backScrollOffset }
9913
9838
  };
@@ -10007,14 +9932,14 @@ let EditorService = class EditorService extends _univerjs_core.Disposable {
10007
9932
  this._blur$.next(null);
10008
9933
  }
10009
9934
  focus(editorUnitId) {
10010
- var _editor$getDocumentDa, _editor$getDocumentDa2;
9935
+ var _editor$getDocumentDa;
10011
9936
  if (editorUnitId === this._focusEditorUnitId) return;
10012
9937
  if (this._focusEditorUnitId) this.blur();
10013
9938
  if (editorUnitId == null) return;
10014
9939
  const editor = this.getEditor(editorUnitId);
10015
9940
  if (editor == null) return;
10016
9941
  this._univerInstanceService.setCurrentUnitForType(editorUnitId);
10017
- const valueCount = ((_editor$getDocumentDa = (_editor$getDocumentDa2 = editor.getDocumentData().body) === null || _editor$getDocumentDa2 === void 0 ? void 0 : _editor$getDocumentDa2.dataStream) !== null && _editor$getDocumentDa !== void 0 ? _editor$getDocumentDa : "").replace(/\r?\n/g, "").length;
9942
+ const valueCount = (((_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream) ?? "").replace(/\r?\n/g, "").length;
10018
9943
  this._contextService.setContextValue(_univerjs_core.EDITOR_ACTIVATED, true);
10019
9944
  if (!(0, _univerjs_core.isInternalEditorID)(editorUnitId)) this._contextService.setContextValue(_univerjs_core.FOCUSING_EDITOR_STANDALONE, true);
10020
9945
  if ((0, _univerjs_core.isCommentEditorID)(editorUnitId)) this._contextService.setContextValue(_univerjs_core.FOCUSING_COMMENT_EDITOR, true);
@@ -10037,9 +9962,8 @@ let EditorService = class EditorService extends _univerjs_core.Disposable {
10037
9962
  return this._editors;
10038
9963
  }
10039
9964
  getEditorRenderConfig(editorUnitId) {
10040
- var _ref, _this$_editorRenderCo;
10041
9965
  const editor = this._editors.get(editorUnitId);
10042
- return (_ref = (_this$_editorRenderCo = this._editorRenderConfigs.get(editorUnitId)) !== null && _this$_editorRenderCo !== void 0 ? _this$_editorRenderCo : editor === null || editor === void 0 ? void 0 : editor.getRenderConfig()) !== null && _ref !== void 0 ? _ref : null;
9966
+ return this._editorRenderConfigs.get(editorUnitId) ?? (editor === null || editor === void 0 ? void 0 : editor.getRenderConfig()) ?? null;
10043
9967
  }
10044
9968
  register(config, container) {
10045
9969
  const { initialSnapshot, canvasStyle = {} } = config;
@@ -10047,7 +9971,8 @@ let EditorService = class EditorService extends _univerjs_core.Disposable {
10047
9971
  this._editorRenderConfigs.set(editorUnitId, {
10048
9972
  canvasStyle,
10049
9973
  scrollBar: config.scrollBar,
10050
- ...config.backScrollOffset === void 0 ? {} : { backScrollOffset: config.backScrollOffset }
9974
+ ...config.backScrollOffset === void 0 ? {} : { backScrollOffset: config.backScrollOffset },
9975
+ ...config.preserveHostFocus === void 0 ? {} : { preserveHostFocus: config.preserveHostFocus }
10051
9976
  });
10052
9977
  if (this._univerInstanceService.getUnit(editorUnitId, _univerjs_core.UniverInstanceType.UNIVER_DOC) == null) this._univerInstanceService.createUnit(_univerjs_core.UniverInstanceType.UNIVER_DOC, initialSnapshot || this._getBlank(editorUnitId), { makeCurrent: false });
10053
9978
  let render = this._renderManagerService.getRenderUnitById(editorUnitId);
@@ -10163,7 +10088,6 @@ let DocBackScrollRenderController = class DocBackScrollRenderController extends
10163
10088
  anchorNodePosition && this.scrollToNode(anchorNodePosition);
10164
10089
  }
10165
10090
  scrollToNode(startNodePosition) {
10166
- var _editorRenderConfig$b;
10167
10091
  const { unitId, scene, mainComponent } = this._context;
10168
10092
  const skeleton = this._docSkeletonManagerService.getSkeleton();
10169
10093
  if (mainComponent == null || skeleton == null) return;
@@ -10179,7 +10103,7 @@ let DocBackScrollRenderController = class DocBackScrollRenderController extends
10179
10103
  let offsetY = 0;
10180
10104
  let offsetX = 0;
10181
10105
  const editorRenderConfig = this._editorService.getEditorRenderConfig(unitId);
10182
- const delta = editorRenderConfig ? (_editorRenderConfig$b = editorRenderConfig.backScrollOffset) !== null && _editorRenderConfig$b !== void 0 ? _editorRenderConfig$b : 0 : 100;
10106
+ const delta = editorRenderConfig ? editorRenderConfig.backScrollOffset ?? 0 : 100;
10183
10107
  if (top < boundTop) offsetY = top - boundTop - delta;
10184
10108
  else if (top > boundBottom - height) offsetY = top - boundBottom + height + delta;
10185
10109
  if (left < boundLeft) offsetX = left - boundLeft;
@@ -10225,11 +10149,11 @@ let DocParagraphPlaceholderRenderController = class DocParagraphPlaceholderRende
10225
10149
  this.disposeWithMe(documents.pageRender$.subscribe((pageRenderConfig) => this._drawPagePlaceholders(pageRenderConfig)));
10226
10150
  }
10227
10151
  _drawPagePlaceholders({ page, pageLeft, pageTop, ctx }) {
10228
- var _this$_context$unit$g, _activeRange$segmentI, _page$segmentId, _this$_context$mainCo;
10152
+ var _this$_context$unit$g, _this$_context$mainCo;
10229
10153
  const body = (_this$_context$unit$g = this._context.unit.getSelfOrHeaderFooterModel(page.segmentId)) === null || _this$_context$unit$g === void 0 ? void 0 : _this$_context$unit$g.getBody();
10230
10154
  if (!body) return;
10231
10155
  const activeRange = this._docSelectionManagerService.getActiveTextRange();
10232
- if (!activeRange || ((_activeRange$segmentI = activeRange.segmentId) !== null && _activeRange$segmentI !== void 0 ? _activeRange$segmentI : "") !== ((_page$segmentId = page.segmentId) !== null && _page$segmentId !== void 0 ? _page$segmentId : "")) return;
10156
+ if (!activeRange || (activeRange.segmentId ?? "") !== (page.segmentId ?? "")) return;
10233
10157
  const placeholders = getParagraphPlaceholderLayouts(page, body, this._getLocale(), pageLeft, pageTop, activeRange.startOffset, {
10234
10158
  docsLeft: (_this$_context$mainCo = this._context.mainComponent) === null || _this$_context$mainCo === void 0 ? void 0 : _this$_context$mainCo.getOffsetConfig().docsLeft,
10235
10159
  unitId: this._context.unitId
@@ -10261,20 +10185,19 @@ function shouldRenderParagraphPlaceholder(documentModel, unitId, config) {
10261
10185
  return ((_documentModel$getSna = documentModel.getSnapshot().documentStyle) === null || _documentModel$getSna === void 0 ? void 0 : _documentModel$getSna.documentFlavor) === _univerjs_core.DocumentFlavor.MODERN;
10262
10186
  }
10263
10187
  function getParagraphPlaceholderLayouts(page, body, locale, pageLeft = 0, pageTop = 0, activeOffset, options) {
10264
- var _body$paragraphs, _page$skeTables;
10265
- const paragraphs = new Map(((_body$paragraphs = body.paragraphs) !== null && _body$paragraphs !== void 0 ? _body$paragraphs : []).map((paragraph) => [paragraph.startIndex, paragraph]));
10188
+ var _page$skeTables;
10189
+ const paragraphs = new Map((body.paragraphs ?? []).map((paragraph) => [paragraph.startIndex, paragraph]));
10266
10190
  const layouts = [];
10267
10191
  const visitSection = (section, originLeft, originTop, clip) => {
10268
10192
  for (const column of section.columns) visitColumn(column, body, paragraphs, locale, layouts, originLeft + column.left, originTop + section.top, activeOffset, clip);
10269
10193
  };
10270
10194
  for (const section of page.sections) visitSection(section, pageLeft + page.marginLeft, pageTop + page.marginTop);
10271
10195
  (_page$skeTables = page.skeTables) === null || _page$skeTables === void 0 || _page$skeTables.forEach((table, tableId) => {
10272
- var _table$tableId, _options$unitId, _viewport$leadingInse, _viewport$trailingIns, _viewport$leadingInse2;
10273
- const sourceTableId = (0, _univerjs_engine_render.getTableIdAndSliceIndex)((_table$tableId = table.tableId) !== null && _table$tableId !== void 0 ? _table$tableId : tableId).tableId;
10274
- const viewport = (0, _univerjs_engine_render.getDocsTableRenderViewport)((_options$unitId = options === null || options === void 0 ? void 0 : options.unitId) !== null && _options$unitId !== void 0 ? _options$unitId : "", sourceTableId);
10275
- const hasHorizontalViewport = viewport != null && ((_viewport$leadingInse = viewport.leadingInsetLeft) !== null && _viewport$leadingInse !== void 0 ? _viewport$leadingInse : 0) + viewport.contentWidth + ((_viewport$trailingIns = viewport.trailingInsetRight) !== null && _viewport$trailingIns !== void 0 ? _viewport$trailingIns : 0) > viewport.viewportWidth;
10196
+ const sourceTableId = (0, _univerjs_engine_render.getTableIdAndSliceIndex)(table.tableId ?? tableId).tableId;
10197
+ const viewport = (0, _univerjs_engine_render.getDocsTableRenderViewport)((options === null || options === void 0 ? void 0 : options.unitId) ?? "", sourceTableId);
10198
+ const hasHorizontalViewport = viewport != null && (viewport.leadingInsetLeft ?? 0) + viewport.contentWidth + (viewport.trailingInsetRight ?? 0) > viewport.viewportWidth;
10276
10199
  const tableLeft = pageLeft + page.marginLeft + table.left;
10277
- const tableViewportLeft = hasHorizontalViewport ? (0, _univerjs_engine_render.getDocsTableViewportLeft)(viewport, tableLeft - ((_viewport$leadingInse2 = viewport.leadingInsetLeft) !== null && _viewport$leadingInse2 !== void 0 ? _viewport$leadingInse2 : 0), options === null || options === void 0 ? void 0 : options.docsLeft) : tableLeft;
10200
+ const tableViewportLeft = hasHorizontalViewport ? (0, _univerjs_engine_render.getDocsTableViewportLeft)(viewport, tableLeft - (viewport.leadingInsetLeft ?? 0), options === null || options === void 0 ? void 0 : options.docsLeft) : tableLeft;
10278
10201
  const tableViewportRight = tableViewportLeft + (hasHorizontalViewport ? viewport.viewportWidth : table.width);
10279
10202
  const tableScrollLeft = hasHorizontalViewport ? viewport.scrollLeft : 0;
10280
10203
  for (const row of table.rows) for (const cell of row.cells) {
@@ -10321,19 +10244,19 @@ function getPlaceholderText(paragraph, locale) {
10321
10244
  }
10322
10245
  }
10323
10246
  function getLinePlaceholderLayout(line, paragraph, text, originLeft, originTop, clip) {
10324
- var _divide$glyphGroup, _paragraph$paragraphS2, _paragraph$paragraphS3, _getLineFontFamily, _divide$left, _divide$paddingLeft, _ref, _divide$width, _clip$left, _clip$right;
10247
+ var _paragraph$paragraphS2;
10325
10248
  const divide = line.divides[0];
10326
- const firstGlyph = ((_divide$glyphGroup = divide === null || divide === void 0 ? void 0 : divide.glyphGroup) !== null && _divide$glyphGroup !== void 0 ? _divide$glyphGroup : [])[0];
10327
- const textStyle = _univerjs_core.NAMED_STYLE_MAP[(_paragraph$paragraphS2 = (_paragraph$paragraphS3 = paragraph.paragraphStyle) === null || _paragraph$paragraphS3 === void 0 ? void 0 : _paragraph$paragraphS3.namedStyleType) !== null && _paragraph$paragraphS2 !== void 0 ? _paragraph$paragraphS2 : _univerjs_core.NamedStyleType.NORMAL_TEXT];
10249
+ const firstGlyph = ((divide === null || divide === void 0 ? void 0 : divide.glyphGroup) ?? [])[0];
10250
+ const textStyle = _univerjs_core.NAMED_STYLE_MAP[((_paragraph$paragraphS2 = paragraph.paragraphStyle) === null || _paragraph$paragraphS2 === void 0 ? void 0 : _paragraph$paragraphS2.namedStyleType) ?? _univerjs_core.NamedStyleType.NORMAL_TEXT];
10328
10251
  const fontSize = getPlaceholderFontSize(line, paragraph);
10329
- const fontFamily = (_getLineFontFamily = getLineFontFamily(line)) !== null && _getLineFontFamily !== void 0 ? _getLineFontFamily : DEFAULT_PLACEHOLDER_FONT_FAMILY;
10252
+ const fontFamily = getLineFontFamily(line) ?? DEFAULT_PLACEHOLDER_FONT_FAMILY;
10330
10253
  const fontWeight = (textStyle === null || textStyle === void 0 ? void 0 : textStyle.bl) ? "bold" : "normal";
10331
- const lineStartX = originLeft + ((_divide$left = divide === null || divide === void 0 ? void 0 : divide.left) !== null && _divide$left !== void 0 ? _divide$left : 0) + ((_divide$paddingLeft = divide === null || divide === void 0 ? void 0 : divide.paddingLeft) !== null && _divide$paddingLeft !== void 0 ? _divide$paddingLeft : 0);
10254
+ const lineStartX = originLeft + ((divide === null || divide === void 0 ? void 0 : divide.left) ?? 0) + ((divide === null || divide === void 0 ? void 0 : divide.paddingLeft) ?? 0);
10332
10255
  const listOffset = paragraph.bullet && firstGlyph ? firstGlyph.left + firstGlyph.width + LIST_PLACEHOLDER_GAP : 0;
10333
10256
  const x = lineStartX + listOffset;
10334
- const naturalMaxWidth = Math.max(0, ((_ref = (_divide$width = divide === null || divide === void 0 ? void 0 : divide.width) !== null && _divide$width !== void 0 ? _divide$width : line.width) !== null && _ref !== void 0 ? _ref : 0) - listOffset);
10335
- const clipLeft = Math.max(x, (_clip$left = clip === null || clip === void 0 ? void 0 : clip.left) !== null && _clip$left !== void 0 ? _clip$left : x);
10336
- const clipRight = Math.min(x + naturalMaxWidth, (_clip$right = clip === null || clip === void 0 ? void 0 : clip.right) !== null && _clip$right !== void 0 ? _clip$right : x + naturalMaxWidth);
10257
+ const naturalMaxWidth = Math.max(0, ((divide === null || divide === void 0 ? void 0 : divide.width) ?? line.width ?? 0) - listOffset);
10258
+ const clipLeft = Math.max(x, (clip === null || clip === void 0 ? void 0 : clip.left) ?? x);
10259
+ const clipRight = Math.min(x + naturalMaxWidth, (clip === null || clip === void 0 ? void 0 : clip.right) ?? x + naturalMaxWidth);
10337
10260
  const clipTop = originTop + line.top;
10338
10261
  return {
10339
10262
  clipBottom: clipTop + line.lineHeight,
@@ -10350,32 +10273,31 @@ function getLinePlaceholderLayout(line, paragraph, text, originLeft, originTop,
10350
10273
  };
10351
10274
  }
10352
10275
  function isEmptyParagraph(dataStream, paragraphStart, paragraphEnd) {
10353
- var _dataStream$slice;
10354
- return stripNonTextTokens((_dataStream$slice = dataStream === null || dataStream === void 0 ? void 0 : dataStream.slice(paragraphStart, paragraphEnd)) !== null && _dataStream$slice !== void 0 ? _dataStream$slice : "").trim() === "";
10276
+ return stripNonTextTokens((dataStream === null || dataStream === void 0 ? void 0 : dataStream.slice(paragraphStart, paragraphEnd)) ?? "").trim() === "";
10355
10277
  }
10356
10278
  function stripNonTextTokens(text) {
10357
10279
  return text.replaceAll(_univerjs_core.DataStreamTreeTokenType.PARAGRAPH, "").replaceAll(_univerjs_core.DataStreamTreeTokenType.SECTION_BREAK, "").replaceAll(_univerjs_core.DataStreamTreeTokenType.DOCS_END, "");
10358
10280
  }
10359
10281
  function getLineFontSize(line) {
10360
10282
  for (const divide of line.divides) for (const glyph of divide.glyphGroup) {
10361
- var _ref2, _glyph$fontStyle$orig, _glyph$fontStyle, _glyph$fontStyle2, _glyph$ts;
10362
- const fontSize = (_ref2 = (_glyph$fontStyle$orig = (_glyph$fontStyle = glyph.fontStyle) === null || _glyph$fontStyle === void 0 ? void 0 : _glyph$fontStyle.originFontSize) !== null && _glyph$fontStyle$orig !== void 0 ? _glyph$fontStyle$orig : (_glyph$fontStyle2 = glyph.fontStyle) === null || _glyph$fontStyle2 === void 0 ? void 0 : _glyph$fontStyle2.fontSize) !== null && _ref2 !== void 0 ? _ref2 : (_glyph$ts = glyph.ts) === null || _glyph$ts === void 0 ? void 0 : _glyph$ts.fs;
10283
+ var _glyph$fontStyle, _glyph$fontStyle2, _glyph$ts;
10284
+ const fontSize = ((_glyph$fontStyle = glyph.fontStyle) === null || _glyph$fontStyle === void 0 ? void 0 : _glyph$fontStyle.originFontSize) ?? ((_glyph$fontStyle2 = glyph.fontStyle) === null || _glyph$fontStyle2 === void 0 ? void 0 : _glyph$fontStyle2.fontSize) ?? ((_glyph$ts = glyph.ts) === null || _glyph$ts === void 0 ? void 0 : _glyph$ts.fs);
10363
10285
  if (fontSize) return fontSize;
10364
10286
  }
10365
10287
  return null;
10366
10288
  }
10367
10289
  function getPlaceholderFontSize(line, paragraph) {
10368
- var _paragraph$paragraphS4, _paragraph$paragraphS5, _ref3, _getLineFontSize;
10369
- const namedStyleType = (_paragraph$paragraphS4 = (_paragraph$paragraphS5 = paragraph.paragraphStyle) === null || _paragraph$paragraphS5 === void 0 ? void 0 : _paragraph$paragraphS5.namedStyleType) !== null && _paragraph$paragraphS4 !== void 0 ? _paragraph$paragraphS4 : _univerjs_core.NamedStyleType.NORMAL_TEXT;
10290
+ var _paragraph$paragraphS3;
10291
+ const namedStyleType = ((_paragraph$paragraphS3 = paragraph.paragraphStyle) === null || _paragraph$paragraphS3 === void 0 ? void 0 : _paragraph$paragraphS3.namedStyleType) ?? _univerjs_core.NamedStyleType.NORMAL_TEXT;
10370
10292
  const textStyle = _univerjs_core.NAMED_STYLE_MAP[namedStyleType];
10371
- const fontSize = (_ref3 = (_getLineFontSize = getLineFontSize(line)) !== null && _getLineFontSize !== void 0 ? _getLineFontSize : textStyle === null || textStyle === void 0 ? void 0 : textStyle.fs) !== null && _ref3 !== void 0 ? _ref3 : DEFAULT_PLACEHOLDER_FONT_SIZE;
10293
+ const fontSize = getLineFontSize(line) ?? (textStyle === null || textStyle === void 0 ? void 0 : textStyle.fs) ?? DEFAULT_PLACEHOLDER_FONT_SIZE;
10372
10294
  if (namedStyleType !== _univerjs_core.NamedStyleType.NORMAL_TEXT) return fontSize;
10373
10295
  return Math.max(fontSize, MIN_BODY_TEXT_PLACEHOLDER_FONT_SIZE);
10374
10296
  }
10375
10297
  function getLineFontFamily(line) {
10376
10298
  for (const divide of line.divides) for (const glyph of divide.glyphGroup) {
10377
- var _glyph$fontStyle$font, _glyph$fontStyle3, _glyph$ts2;
10378
- const fontFamily = (_glyph$fontStyle$font = (_glyph$fontStyle3 = glyph.fontStyle) === null || _glyph$fontStyle3 === void 0 ? void 0 : _glyph$fontStyle3.fontFamily) !== null && _glyph$fontStyle$font !== void 0 ? _glyph$fontStyle$font : (_glyph$ts2 = glyph.ts) === null || _glyph$ts2 === void 0 ? void 0 : _glyph$ts2.ff;
10299
+ var _glyph$fontStyle3, _glyph$ts2;
10300
+ const fontFamily = ((_glyph$fontStyle3 = glyph.fontStyle) === null || _glyph$fontStyle3 === void 0 ? void 0 : _glyph$fontStyle3.fontFamily) ?? ((_glyph$ts2 = glyph.ts) === null || _glyph$ts2 === void 0 ? void 0 : _glyph$ts2.ff);
10379
10301
  if (fontFamily) return fontFamily;
10380
10302
  }
10381
10303
  return null;
@@ -10385,11 +10307,10 @@ function drawParagraphPlaceholders(ctx, placeholders) {
10385
10307
  ctx.fillStyle = PLACEHOLDER_COLOR;
10386
10308
  ctx.textBaseline = "alphabetic";
10387
10309
  for (const placeholder of placeholders) {
10388
- var _placeholder$clipLeft, _placeholder$clipRigh, _placeholder$clipTop, _placeholder$clipBott;
10389
- const clipLeft = (_placeholder$clipLeft = placeholder.clipLeft) !== null && _placeholder$clipLeft !== void 0 ? _placeholder$clipLeft : placeholder.x;
10390
- const clipRight = (_placeholder$clipRigh = placeholder.clipRight) !== null && _placeholder$clipRigh !== void 0 ? _placeholder$clipRigh : placeholder.x + placeholder.maxWidth;
10391
- const clipTop = (_placeholder$clipTop = placeholder.clipTop) !== null && _placeholder$clipTop !== void 0 ? _placeholder$clipTop : placeholder.y - placeholder.fontSize;
10392
- const clipBottom = (_placeholder$clipBott = placeholder.clipBottom) !== null && _placeholder$clipBott !== void 0 ? _placeholder$clipBott : placeholder.y + placeholder.fontSize;
10310
+ const clipLeft = placeholder.clipLeft ?? placeholder.x;
10311
+ const clipRight = placeholder.clipRight ?? placeholder.x + placeholder.maxWidth;
10312
+ const clipTop = placeholder.clipTop ?? placeholder.y - placeholder.fontSize;
10313
+ const clipBottom = placeholder.clipBottom ?? placeholder.y + placeholder.fontSize;
10393
10314
  if (clipRight <= clipLeft || clipBottom <= clipTop) continue;
10394
10315
  ctx.save();
10395
10316
  ctx.beginPath();
@@ -10434,13 +10355,12 @@ function resolveDocFitPaddingX(availableWidth, paddingX) {
10434
10355
  return 0;
10435
10356
  }
10436
10357
  function calcDocFitToWidthScale(params) {
10437
- var _options$maxScale;
10438
10358
  const options = normalizeDocFitToWidthOptions(params.options);
10439
10359
  if (options.mode !== "fit-width") return 1;
10440
10360
  if (!Number.isFinite(params.availableWidth) || !Number.isFinite(params.baseWidth) || params.baseWidth <= 0) return 1;
10441
10361
  const paddingX = resolveDocFitPaddingX(params.availableWidth, options.paddingX);
10442
10362
  const rawScale = Math.max(0, params.availableWidth - paddingX * 2) / params.baseWidth;
10443
- const maxScale = (_options$maxScale = options.maxScale) !== null && _options$maxScale !== void 0 ? _options$maxScale : Number.POSITIVE_INFINITY;
10363
+ const maxScale = options.maxScale ?? Number.POSITIVE_INFINITY;
10444
10364
  return Math.min(maxScale, Math.max(options.minScale, rawScale));
10445
10365
  }
10446
10366
  function resolveDocFitBaseWidth(params) {
@@ -10459,12 +10379,10 @@ let DocViewScaleService = class DocViewScaleService extends _univerjs_core.Dispo
10459
10379
  this._configService = _configService;
10460
10380
  }
10461
10381
  getPluginConfig() {
10462
- var _this$_configService$;
10463
- return (_this$_configService$ = this._configService.getConfig("docs-ui.config")) !== null && _this$_configService$ !== void 0 ? _this$_configService$ : {};
10382
+ return this._configService.getConfig("docs-ui.config") ?? {};
10464
10383
  }
10465
10384
  getOptions() {
10466
- var _this$getPluginConfig;
10467
- return (_this$getPluginConfig = this.getPluginConfig().fitToWidth) !== null && _this$getPluginConfig !== void 0 ? _this$getPluginConfig : DEFAULT_DOC_FIT_TO_WIDTH_OPTIONS;
10385
+ return this.getPluginConfig().fitToWidth ?? DEFAULT_DOC_FIT_TO_WIDTH_OPTIONS;
10468
10386
  }
10469
10387
  getBaseWidth() {
10470
10388
  var _this$_context$unit, _this$_context$unit$g, _documentStyle$pageSi;
@@ -10499,10 +10417,7 @@ let DocViewScaleService = class DocViewScaleService extends _univerjs_core.Dispo
10499
10417
  }
10500
10418
  _resolveContainer(container) {
10501
10419
  if (container == null) return;
10502
- if (typeof container === "string") {
10503
- var _ref, _document$querySelect;
10504
- return (_ref = (_document$querySelect = document.querySelector(container)) !== null && _document$querySelect !== void 0 ? _document$querySelect : document.getElementById(container)) !== null && _ref !== void 0 ? _ref : void 0;
10505
- }
10420
+ if (typeof container === "string") return document.querySelector(container) ?? document.getElementById(container) ?? void 0;
10506
10421
  return container;
10507
10422
  }
10508
10423
  };
@@ -10794,8 +10709,7 @@ function getPageSizeInModernMode(page) {
10794
10709
  //#endregion
10795
10710
  //#region src/basics/selection.ts
10796
10711
  function findFirstCursorOffset(snapshot) {
10797
- var _snapshot$body;
10798
- const { dataStream } = (_snapshot$body = snapshot.body) !== null && _snapshot$body !== void 0 ? _snapshot$body : {};
10712
+ const { dataStream } = snapshot.body ?? {};
10799
10713
  const EXCLUDE_TOKENS = [
10800
10714
  _univerjs_core.DataStreamTreeTokenType.TABLE_START,
10801
10715
  _univerjs_core.DataStreamTreeTokenType.TABLE_CELL_END,
@@ -10917,12 +10831,12 @@ const CloseHeaderFooterCommand = {
10917
10831
  id: "doc.command.close-header-footer",
10918
10832
  type: _univerjs_core.CommandType.COMMAND,
10919
10833
  handler: async (accessor, params) => {
10920
- var _params$unitId, _instanceService$getC, _renderObject$mainCom;
10834
+ var _instanceService$getC, _renderObject$mainCom;
10921
10835
  const commandService = accessor.get(_univerjs_core.ICommandService);
10922
10836
  const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
10923
10837
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
10924
10838
  const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
10925
- const unitId = (_params$unitId = params === null || params === void 0 ? void 0 : params.unitId) !== null && _params$unitId !== void 0 ? _params$unitId : (_instanceService$getC = instanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC)) === null || _instanceService$getC === void 0 ? void 0 : _instanceService$getC.getUnitId();
10839
+ const unitId = (params === null || params === void 0 ? void 0 : params.unitId) ?? ((_instanceService$getC = instanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC)) === null || _instanceService$getC === void 0 ? void 0 : _instanceService$getC.getUnitId());
10926
10840
  if (unitId == null) return false;
10927
10841
  const renderObject = renderManagerService.getRenderUnitById(unitId);
10928
10842
  if (renderObject == null) return false;
@@ -11141,16 +11055,14 @@ const MODERN_WIDTH_OPTIONS = [
11141
11055
  _univerjs_core.ModernDocumentWidthMode.WIDE
11142
11056
  ];
11143
11057
  const getPaperSize = (size) => {
11144
- const result = Object.keys(_univerjs_core.PAGE_SIZE).find((key) => {
11058
+ return Object.keys(_univerjs_core.PAGE_SIZE).find((key) => {
11145
11059
  const { width, height } = _univerjs_core.PAGE_SIZE[key];
11146
11060
  if (size.width === width && size.height === height) return true;
11147
11061
  return false;
11148
- });
11149
- return result !== null && result !== void 0 ? result : "A4";
11062
+ }) ?? "A4";
11150
11063
  };
11151
11064
  const getModernWidthMode = (size) => {
11152
- var _size$width;
11153
- const width = (_size$width = size === null || size === void 0 ? void 0 : size.width) !== null && _size$width !== void 0 ? _size$width : _univerjs_core.MODERN_DOCUMENT_WIDTH[_univerjs_core.ModernDocumentWidthMode.MEDIUM];
11065
+ const width = (size === null || size === void 0 ? void 0 : size.width) ?? _univerjs_core.MODERN_DOCUMENT_WIDTH[_univerjs_core.ModernDocumentWidthMode.MEDIUM];
11154
11066
  return MODERN_WIDTH_OPTIONS.reduce((nearest, option) => {
11155
11067
  const nearestDistance = Math.abs(_univerjs_core.MODERN_DOCUMENT_WIDTH[nearest] - width);
11156
11068
  return Math.abs(_univerjs_core.MODERN_DOCUMENT_WIDTH[option] - width) < nearestDistance ? option : nearest;
@@ -11168,21 +11080,21 @@ function PageSettings(props) {
11168
11080
  const documentStyle = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC).getDocumentStyle();
11169
11081
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
11170
11082
  const [settings, setSettings] = (0, react.useState)(() => {
11171
- var _documentStyle$pageSi, _documentStyle$pageSi2, _documentStyle$pageSi3, _documentStyle$pageSi4, _documentStyle$pageSi5, _documentStyle$pageOr, _documentStyle$margin, _documentStyle$margin2, _documentStyle$margin3, _documentStyle$margin4;
11083
+ var _documentStyle$pageSi, _documentStyle$pageSi2;
11172
11084
  return {
11173
11085
  mode: documentStyle.documentFlavor === _univerjs_core.DocumentFlavor.TRADITIONAL ? _univerjs_core.DocumentFlavor.TRADITIONAL : _univerjs_core.DocumentFlavor.MODERN,
11174
11086
  modernWidth: getModernWidthMode(documentStyle.pageSize),
11175
- paperSize: getPaperSize((_documentStyle$pageSi = documentStyle.pageSize) !== null && _documentStyle$pageSi !== void 0 ? _documentStyle$pageSi : _univerjs_core.PAGE_SIZE.A4),
11087
+ paperSize: getPaperSize(documentStyle.pageSize ?? _univerjs_core.PAGE_SIZE.A4),
11176
11088
  pageSize: {
11177
- width: (_documentStyle$pageSi2 = (_documentStyle$pageSi3 = documentStyle.pageSize) === null || _documentStyle$pageSi3 === void 0 ? void 0 : _documentStyle$pageSi3.width) !== null && _documentStyle$pageSi2 !== void 0 ? _documentStyle$pageSi2 : 0,
11178
- height: (_documentStyle$pageSi4 = (_documentStyle$pageSi5 = documentStyle.pageSize) === null || _documentStyle$pageSi5 === void 0 ? void 0 : _documentStyle$pageSi5.height) !== null && _documentStyle$pageSi4 !== void 0 ? _documentStyle$pageSi4 : 0
11089
+ width: ((_documentStyle$pageSi = documentStyle.pageSize) === null || _documentStyle$pageSi === void 0 ? void 0 : _documentStyle$pageSi.width) ?? 0,
11090
+ height: ((_documentStyle$pageSi2 = documentStyle.pageSize) === null || _documentStyle$pageSi2 === void 0 ? void 0 : _documentStyle$pageSi2.height) ?? 0
11179
11091
  },
11180
- orientation: (_documentStyle$pageOr = documentStyle.pageOrient) !== null && _documentStyle$pageOr !== void 0 ? _documentStyle$pageOr : _univerjs_core.PageOrientType.PORTRAIT,
11092
+ orientation: documentStyle.pageOrient ?? _univerjs_core.PageOrientType.PORTRAIT,
11181
11093
  margins: {
11182
- top: (_documentStyle$margin = documentStyle.marginTop) !== null && _documentStyle$margin !== void 0 ? _documentStyle$margin : 0,
11183
- bottom: (_documentStyle$margin2 = documentStyle.marginBottom) !== null && _documentStyle$margin2 !== void 0 ? _documentStyle$margin2 : 0,
11184
- left: (_documentStyle$margin3 = documentStyle.marginLeft) !== null && _documentStyle$margin3 !== void 0 ? _documentStyle$margin3 : 0,
11185
- right: (_documentStyle$margin4 = documentStyle.marginRight) !== null && _documentStyle$margin4 !== void 0 ? _documentStyle$margin4 : 0
11094
+ top: documentStyle.marginTop ?? 0,
11095
+ bottom: documentStyle.marginBottom ?? 0,
11096
+ left: documentStyle.marginLeft ?? 0,
11097
+ right: documentStyle.marginRight ?? 0
11186
11098
  }
11187
11099
  };
11188
11100
  });
@@ -11311,17 +11223,14 @@ const PAGE_SETTING_COMPONENT_ID = "docs.component.page-setting";
11311
11223
  //#region src/commands/commands/doc-page-setup.command.ts
11312
11224
  const PAGE_FILL_TABLE_TOLERANCE = 2;
11313
11225
  function getPageContentWidth(config) {
11314
- var _config$pageSize$widt, _config$pageSize, _config$marginLeft, _config$marginRight;
11315
- const pageWidth = (_config$pageSize$widt = (_config$pageSize = config.pageSize) === null || _config$pageSize === void 0 ? void 0 : _config$pageSize.width) !== null && _config$pageSize$widt !== void 0 ? _config$pageSize$widt : 0;
11226
+ var _config$pageSize;
11227
+ const pageWidth = ((_config$pageSize = config.pageSize) === null || _config$pageSize === void 0 ? void 0 : _config$pageSize.width) ?? 0;
11316
11228
  if (!pageWidth) return 0;
11317
11229
  if (config.documentFlavor === _univerjs_core.DocumentFlavor.MODERN) return Math.max(0, pageWidth - _univerjs_core.MODERN_DOCUMENT_DEFAULT_MARGIN * 2);
11318
- return Math.max(0, pageWidth - ((_config$marginLeft = config.marginLeft) !== null && _config$marginLeft !== void 0 ? _config$marginLeft : 0) - ((_config$marginRight = config.marginRight) !== null && _config$marginRight !== void 0 ? _config$marginRight : 0));
11230
+ return Math.max(0, pageWidth - (config.marginLeft ?? 0) - (config.marginRight ?? 0));
11319
11231
  }
11320
11232
  function getTableColumnTotalWidth(table) {
11321
- return table.tableColumns.reduce((total, column) => {
11322
- var _column$size$width$v;
11323
- return total + ((_column$size$width$v = column.size.width.v) !== null && _column$size$width$v !== void 0 ? _column$size$width$v : 0);
11324
- }, 0);
11233
+ return table.tableColumns.reduce((total, column) => total + (column.size.width.v ?? 0), 0);
11325
11234
  }
11326
11235
  function isPageFillTable(table, oldContentWidth) {
11327
11236
  if (oldContentWidth <= 0 || table.tableColumns.length === 0) return false;
@@ -11372,7 +11281,7 @@ const DocPageSetupCommand = {
11372
11281
  const snapshot = docDataModel.getSnapshot();
11373
11282
  const newDocumentStyle = {
11374
11283
  ...documentStyle,
11375
- documentFlavor: documentFlavor !== null && documentFlavor !== void 0 ? documentFlavor : documentStyle.documentFlavor,
11284
+ documentFlavor: documentFlavor ?? documentStyle.documentFlavor,
11376
11285
  marginBottom,
11377
11286
  marginLeft,
11378
11287
  marginRight,
@@ -11721,7 +11630,7 @@ const InsertSpecialCharacterCommand = {
11721
11630
  id: "doc.command.insert-special-character",
11722
11631
  type: _univerjs_core.CommandType.COMMAND,
11723
11632
  handler: (accessor, params) => {
11724
- var _docDataModel$getSelf, _originBody$customRan, _originBody$customDec;
11633
+ var _docDataModel$getSelf;
11725
11634
  if (!(params === null || params === void 0 ? void 0 : params.value)) return false;
11726
11635
  const commandService = accessor.get(_univerjs_core.ICommandService);
11727
11636
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
@@ -11735,8 +11644,8 @@ const InsertSpecialCharacterCommand = {
11735
11644
  if (!originBody) return false;
11736
11645
  const { value } = params;
11737
11646
  const curTextRun = getTextRunAtPosition(originBody, activeRange.endOffset, docMenuStyleService.getDefaultStyle(), docMenuStyleService.getStyleCache());
11738
- const curCustomRange = getCustomRangeAtPosition((_originBody$customRan = originBody.customRanges) !== null && _originBody$customRan !== void 0 ? _originBody$customRan : [], activeRange.endOffset);
11739
- const curCustomDecorations = getCustomDecorationAtPosition((_originBody$customDec = originBody.customDecorations) !== null && _originBody$customDec !== void 0 ? _originBody$customDec : [], activeRange.endOffset);
11647
+ const curCustomRange = getCustomRangeAtPosition(originBody.customRanges ?? [], activeRange.endOffset);
11648
+ const curCustomDecorations = getCustomDecorationAtPosition(originBody.customDecorations ?? [], activeRange.endOffset);
11740
11649
  return commandService.executeCommand(_univerjs_docs.InsertTextCommand.id, {
11741
11650
  unitId: docDataModel.getUnitId(),
11742
11651
  body: {
@@ -11973,7 +11882,7 @@ function disableMenuWhenHeaderFooterEditing(accessor) {
11973
11882
  return;
11974
11883
  }
11975
11884
  const emitDisabled = (editArea) => {
11976
- const currentEditArea = editArea !== null && editArea !== void 0 ? editArea : viewModel.getEditArea();
11885
+ const currentEditArea = editArea ?? viewModel.getEditArea();
11977
11886
  emit(currentEditArea === _univerjs_engine_render.DocumentEditArea.HEADER || currentEditArea === _univerjs_engine_render.DocumentEditArea.FOOTER);
11978
11887
  };
11979
11888
  emitDisabled();
@@ -12067,7 +11976,7 @@ function disableMenuWhenNoDocRange(accessor) {
12067
11976
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
12068
11977
  return new rxjs.Observable((subscriber) => {
12069
11978
  const subscription = docSelectionManagerService.textSelection$.subscribe((selection) => {
12070
- var _document$getBody$blo, _document$getBody;
11979
+ var _document$getBody;
12071
11980
  if (selection == null) {
12072
11981
  subscriber.next(true);
12073
11982
  return;
@@ -12078,7 +11987,7 @@ function disableMenuWhenNoDocRange(accessor) {
12078
11987
  return;
12079
11988
  }
12080
11989
  const document = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
12081
- if (((_document$getBody$blo = document === null || document === void 0 || (_document$getBody = document.getBody()) === null || _document$getBody === void 0 || (_document$getBody = _document$getBody.blockRanges) === null || _document$getBody === void 0 ? void 0 : _document$getBody.filter((range) => range.blockType === _univerjs_core.DocumentBlockRangeType.CODE)) !== null && _document$getBody$blo !== void 0 ? _document$getBody$blo : []).some((blockRange) => textRanges.some((range) => Math.max(range.startOffset, blockRange.startIndex) <= Math.min(range.endOffset, blockRange.endIndex)))) {
11990
+ if (((document === null || document === void 0 || (_document$getBody = document.getBody()) === null || _document$getBody === void 0 || (_document$getBody = _document$getBody.blockRanges) === null || _document$getBody === void 0 ? void 0 : _document$getBody.filter((range) => range.blockType === _univerjs_core.DocumentBlockRangeType.CODE)) ?? []).some((blockRange) => textRanges.some((range) => Math.max(range.startOffset, blockRange.startIndex) <= Math.min(range.endOffset, blockRange.endIndex)))) {
12082
11991
  subscriber.next(true);
12083
11992
  return;
12084
11993
  }
@@ -12124,8 +12033,8 @@ function SymbolPickerMenuItemFactory(accessor) {
12124
12033
  };
12125
12034
  }
12126
12035
  function isTextRangeInAnyBlockRange(document, range) {
12127
- var _document$getBody$blo2, _document$getBody2;
12128
- const blockRanges = (_document$getBody$blo2 = document === null || document === void 0 || (_document$getBody2 = document.getBody()) === null || _document$getBody2 === void 0 ? void 0 : _document$getBody2.blockRanges) !== null && _document$getBody$blo2 !== void 0 ? _document$getBody$blo2 : [];
12036
+ var _document$getBody2;
12037
+ const blockRanges = (document === null || document === void 0 || (_document$getBody2 = document.getBody()) === null || _document$getBody2 === void 0 ? void 0 : _document$getBody2.blockRanges) ?? [];
12129
12038
  const startOffset = range.startOffset;
12130
12039
  const endOffset = range.collapsed ? range.startOffset : range.endOffset - 1;
12131
12040
  return blockRanges.some((blockRange) => Math.max(startOffset, blockRange.startIndex) <= Math.min(endOffset, blockRange.endIndex));
@@ -12135,10 +12044,10 @@ function hideMenuWhenSelectionInBlockRange(accessor) {
12135
12044
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
12136
12045
  return new rxjs.Observable((subscriber) => {
12137
12046
  const calc = (selection) => {
12138
- var _getCurrentSelection, _selection$textRanges, _docSelectionManagerS, _selection$unitId;
12047
+ var _getCurrentSelection;
12139
12048
  const currentSelection = (_getCurrentSelection = docSelectionManagerService.__getCurrentSelection) === null || _getCurrentSelection === void 0 ? void 0 : _getCurrentSelection.call(docSelectionManagerService);
12140
- const textRanges = (_selection$textRanges = selection === null || selection === void 0 ? void 0 : selection.textRanges) !== null && _selection$textRanges !== void 0 ? _selection$textRanges : [...(_docSelectionManagerS = docSelectionManagerService.getTextRanges()) !== null && _docSelectionManagerS !== void 0 ? _docSelectionManagerS : []];
12141
- const unitId = (_selection$unitId = selection === null || selection === void 0 ? void 0 : selection.unitId) !== null && _selection$unitId !== void 0 ? _selection$unitId : currentSelection === null || currentSelection === void 0 ? void 0 : currentSelection.unitId;
12049
+ const textRanges = (selection === null || selection === void 0 ? void 0 : selection.textRanges) ?? [...docSelectionManagerService.getTextRanges() ?? []];
12050
+ const unitId = (selection === null || selection === void 0 ? void 0 : selection.unitId) ?? (currentSelection === null || currentSelection === void 0 ? void 0 : currentSelection.unitId);
12142
12051
  const document = unitId ? univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
12143
12052
  subscriber.next(textRanges.some((range) => isTextRangeInAnyBlockRange(document, range)));
12144
12053
  };
@@ -12358,7 +12267,7 @@ function FontFamilySelectorMenuItemFactory(accessor) {
12358
12267
  return;
12359
12268
  }
12360
12269
  const ff = (_textRun$ts7 = textRun.ts) === null || _textRun$ts7 === void 0 ? void 0 : _textRun$ts7.ff;
12361
- subscriber.next(ff !== null && ff !== void 0 ? ff : defaultValue);
12270
+ subscriber.next(ff ?? defaultValue);
12362
12271
  };
12363
12272
  const disposable = commandService.onCommandExecuted((c) => {
12364
12273
  const id = c.id;
@@ -12396,7 +12305,7 @@ function FontSizeSelectorMenuItemFactory(accessor) {
12396
12305
  return;
12397
12306
  }
12398
12307
  const fs = (_textRun$ts8 = textRun.ts) === null || _textRun$ts8 === void 0 ? void 0 : _textRun$ts8.fs;
12399
- subscriber.next(fs !== null && fs !== void 0 ? fs : DEFAULT_SIZE);
12308
+ subscriber.next(fs ?? DEFAULT_SIZE);
12400
12309
  };
12401
12310
  const disposable = commandService.onCommandExecuted((c) => {
12402
12311
  const id = c.id;
@@ -12432,14 +12341,14 @@ function HeadingSelectorMenuItemFactory(accessor) {
12432
12341
  value$: new rxjs.Observable((subscriber) => {
12433
12342
  const DEFAULT_TYPE = _univerjs_core.NamedStyleType.NORMAL_TEXT;
12434
12343
  const calc = () => {
12435
- var _paragraph$paragraphS, _paragraph$paragraphS2;
12344
+ var _paragraph$paragraphS;
12436
12345
  if (shouldSuppressDocMenuStateRefresh(accessor)) return;
12437
12346
  const paragraph = getParagraphStyleAtCursor(accessor);
12438
12347
  if (paragraph == null) {
12439
12348
  subscriber.next(DEFAULT_TYPE);
12440
12349
  return;
12441
12350
  }
12442
- const namedStyleType = (_paragraph$paragraphS = (_paragraph$paragraphS2 = paragraph.paragraphStyle) === null || _paragraph$paragraphS2 === void 0 ? void 0 : _paragraph$paragraphS2.namedStyleType) !== null && _paragraph$paragraphS !== void 0 ? _paragraph$paragraphS : DEFAULT_TYPE;
12351
+ const namedStyleType = ((_paragraph$paragraphS = paragraph.paragraphStyle) === null || _paragraph$paragraphS === void 0 ? void 0 : _paragraph$paragraphS.namedStyleType) ?? DEFAULT_TYPE;
12443
12352
  subscriber.next(namedStyleType);
12444
12353
  };
12445
12354
  const disposable = commandService.onCommandExecuted((c) => {
@@ -12506,12 +12415,12 @@ const FLOAT_TEXT_STYLE_OPTIONS = [
12506
12415
  }
12507
12416
  ];
12508
12417
  function normalizeFloatingTextStyleValue(paragraph) {
12509
- var _paragraph$bullet, _paragraph$paragraphS3, _paragraph$paragraphS4;
12418
+ var _paragraph$bullet, _paragraph$paragraphS2;
12510
12419
  const listType = paragraph === null || paragraph === void 0 || (_paragraph$bullet = paragraph.bullet) === null || _paragraph$bullet === void 0 ? void 0 : _paragraph$bullet.listType;
12511
12420
  if (listType === null || listType === void 0 ? void 0 : listType.startsWith(_univerjs_core.PresetListType.ORDER_LIST)) return _univerjs_core.PresetListType.ORDER_LIST;
12512
12421
  if (listType === null || listType === void 0 ? void 0 : listType.startsWith(_univerjs_core.PresetListType.BULLET_LIST)) return _univerjs_core.PresetListType.BULLET_LIST;
12513
12422
  if (listType === _univerjs_core.PresetListType.CHECK_LIST || listType === _univerjs_core.PresetListType.CHECK_LIST_CHECKED) return _univerjs_core.PresetListType.CHECK_LIST;
12514
- return (_paragraph$paragraphS3 = paragraph === null || paragraph === void 0 || (_paragraph$paragraphS4 = paragraph.paragraphStyle) === null || _paragraph$paragraphS4 === void 0 ? void 0 : _paragraph$paragraphS4.namedStyleType) !== null && _paragraph$paragraphS3 !== void 0 ? _paragraph$paragraphS3 : _univerjs_core.NamedStyleType.NORMAL_TEXT;
12423
+ return (paragraph === null || paragraph === void 0 || (_paragraph$paragraphS2 = paragraph.paragraphStyle) === null || _paragraph$paragraphS2 === void 0 ? void 0 : _paragraph$paragraphS2.namedStyleType) ?? _univerjs_core.NamedStyleType.NORMAL_TEXT;
12515
12424
  }
12516
12425
  function FloatTextStyleMenuItemFactory(accessor) {
12517
12426
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -12563,7 +12472,7 @@ function TextColorSelectorMenuItemFactory(accessor) {
12563
12472
  return;
12564
12473
  }
12565
12474
  const color = (_textRun$ts9 = textRun.ts) === null || _textRun$ts9 === void 0 || (_textRun$ts9 = _textRun$ts9.cl) === null || _textRun$ts9 === void 0 ? void 0 : _textRun$ts9.rgb;
12566
- subscriber.next(color !== null && color !== void 0 ? color : defaultValue);
12475
+ subscriber.next(color ?? defaultValue);
12567
12476
  };
12568
12477
  const disposable = commandService.onCommandExecuted((c) => {
12569
12478
  if (c.id === SetInlineFormatTextColorCommand.id) calc();
@@ -12578,7 +12487,7 @@ function TextColorSelectorMenuItemFactory(accessor) {
12578
12487
  if (c.id === SetInlineFormatTextColorCommand.id) {
12579
12488
  if (shouldSuppressDocMenuStateRefresh(accessor)) return;
12580
12489
  const color = c.params.value;
12581
- subscriber.next(color !== null && color !== void 0 ? color : defaultColor);
12490
+ subscriber.next(color ?? defaultColor);
12582
12491
  }
12583
12492
  });
12584
12493
  subscriber.next(defaultColor);
@@ -12697,11 +12606,11 @@ function AlignLeftMenuItemFactory(accessor) {
12697
12606
  const disposable = commandService.onCommandExecuted((c) => {
12698
12607
  const id = c.id;
12699
12608
  if (id === _univerjs_docs.SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
12700
- var _paragraph$paragraphS5;
12609
+ var _paragraph$paragraphS3;
12701
12610
  if (shouldSuppressDocMenuStateRefresh(accessor)) return;
12702
12611
  const paragraph = getParagraphStyleAtCursor(accessor);
12703
12612
  if (paragraph == null) return;
12704
- const alignType = (_paragraph$paragraphS5 = paragraph.paragraphStyle) === null || _paragraph$paragraphS5 === void 0 ? void 0 : _paragraph$paragraphS5.horizontalAlign;
12613
+ const alignType = (_paragraph$paragraphS3 = paragraph.paragraphStyle) === null || _paragraph$paragraphS3 === void 0 ? void 0 : _paragraph$paragraphS3.horizontalAlign;
12705
12614
  subscriber.next(alignType === _univerjs_core.HorizontalAlign.LEFT);
12706
12615
  }
12707
12616
  });
@@ -12722,11 +12631,11 @@ function AlignCenterMenuItemFactory(accessor) {
12722
12631
  const disposable = commandService.onCommandExecuted((c) => {
12723
12632
  const id = c.id;
12724
12633
  if (id === _univerjs_docs.SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
12725
- var _paragraph$paragraphS6;
12634
+ var _paragraph$paragraphS4;
12726
12635
  if (shouldSuppressDocMenuStateRefresh(accessor)) return;
12727
12636
  const paragraph = getParagraphStyleAtCursor(accessor);
12728
12637
  if (paragraph == null) return;
12729
- const alignType = (_paragraph$paragraphS6 = paragraph.paragraphStyle) === null || _paragraph$paragraphS6 === void 0 ? void 0 : _paragraph$paragraphS6.horizontalAlign;
12638
+ const alignType = (_paragraph$paragraphS4 = paragraph.paragraphStyle) === null || _paragraph$paragraphS4 === void 0 ? void 0 : _paragraph$paragraphS4.horizontalAlign;
12730
12639
  subscriber.next(alignType === _univerjs_core.HorizontalAlign.CENTER);
12731
12640
  }
12732
12641
  });
@@ -12748,11 +12657,11 @@ function AlignRightMenuItemFactory(accessor) {
12748
12657
  const disposable = commandService.onCommandExecuted((c) => {
12749
12658
  const id = c.id;
12750
12659
  if (id === _univerjs_docs.SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
12751
- var _paragraph$paragraphS7;
12660
+ var _paragraph$paragraphS5;
12752
12661
  if (shouldSuppressDocMenuStateRefresh(accessor)) return;
12753
12662
  const paragraph = getParagraphStyleAtCursor(accessor);
12754
12663
  if (paragraph == null) return;
12755
- const alignType = (_paragraph$paragraphS7 = paragraph.paragraphStyle) === null || _paragraph$paragraphS7 === void 0 ? void 0 : _paragraph$paragraphS7.horizontalAlign;
12664
+ const alignType = (_paragraph$paragraphS5 = paragraph.paragraphStyle) === null || _paragraph$paragraphS5 === void 0 ? void 0 : _paragraph$paragraphS5.horizontalAlign;
12756
12665
  subscriber.next(alignType === _univerjs_core.HorizontalAlign.RIGHT);
12757
12666
  }
12758
12667
  });
@@ -12774,11 +12683,11 @@ function AlignJustifyMenuItemFactory(accessor) {
12774
12683
  const disposable = commandService.onCommandExecuted((c) => {
12775
12684
  const id = c.id;
12776
12685
  if (id === _univerjs_docs.SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
12777
- var _paragraph$paragraphS8;
12686
+ var _paragraph$paragraphS6;
12778
12687
  if (shouldSuppressDocMenuStateRefresh(accessor)) return;
12779
12688
  const paragraph = getParagraphStyleAtCursor(accessor);
12780
12689
  if (paragraph == null) return;
12781
- const alignType = (_paragraph$paragraphS8 = paragraph.paragraphStyle) === null || _paragraph$paragraphS8 === void 0 ? void 0 : _paragraph$paragraphS8.horizontalAlign;
12690
+ const alignType = (_paragraph$paragraphS6 = paragraph.paragraphStyle) === null || _paragraph$paragraphS6 === void 0 ? void 0 : _paragraph$paragraphS6.horizontalAlign;
12782
12691
  subscriber.next(alignType === _univerjs_core.HorizontalAlign.JUSTIFIED);
12783
12692
  }
12784
12693
  });
@@ -12819,13 +12728,13 @@ function AlignMenuItemFactory(accessor) {
12819
12728
  const commandService = accessor.get(_univerjs_core.ICommandService);
12820
12729
  const value$ = new rxjs.Observable((subscriber) => {
12821
12730
  const calc = () => {
12822
- var _paragraph$paragraphS9, _paragraph$paragraphS10;
12731
+ var _paragraph$paragraphS7;
12823
12732
  if (shouldSuppressDocMenuStateRefresh(accessor)) {
12824
12733
  subscriber.next(_univerjs_core.HorizontalAlign.LEFT);
12825
12734
  return;
12826
12735
  }
12827
12736
  const paragraph = getParagraphStyleAtCursor(accessor);
12828
- subscriber.next((_paragraph$paragraphS9 = paragraph === null || paragraph === void 0 || (_paragraph$paragraphS10 = paragraph.paragraphStyle) === null || _paragraph$paragraphS10 === void 0 ? void 0 : _paragraph$paragraphS10.horizontalAlign) !== null && _paragraph$paragraphS9 !== void 0 ? _paragraph$paragraphS9 : _univerjs_core.HorizontalAlign.LEFT);
12737
+ subscriber.next((paragraph === null || paragraph === void 0 || (_paragraph$paragraphS7 = paragraph.paragraphStyle) === null || _paragraph$paragraphS7 === void 0 ? void 0 : _paragraph$paragraphS7.horizontalAlign) ?? _univerjs_core.HorizontalAlign.LEFT);
12829
12738
  };
12830
12739
  const disposable = commandService.onCommandExecuted((c) => {
12831
12740
  if (c.id === _univerjs_docs.SetTextSelectionsOperation.id || c.id === AlignOperationCommand.id) calc();
@@ -12840,8 +12749,8 @@ function AlignMenuItemFactory(accessor) {
12840
12749
  id: AlignOperationCommand.id,
12841
12750
  type: _univerjs_ui.MenuItemType.SELECTOR,
12842
12751
  icon: value$.pipe((0, rxjs.map)((alignType) => {
12843
- var _HORIZONTAL_ALIGN_OPT, _HORIZONTAL_ALIGN_OPT2;
12844
- return (_HORIZONTAL_ALIGN_OPT = (_HORIZONTAL_ALIGN_OPT2 = HORIZONTAL_ALIGN_OPTIONS.find((option) => option.value === alignType)) === null || _HORIZONTAL_ALIGN_OPT2 === void 0 ? void 0 : _HORIZONTAL_ALIGN_OPT2.icon) !== null && _HORIZONTAL_ALIGN_OPT !== void 0 ? _HORIZONTAL_ALIGN_OPT : "LeftJustifyingIcon";
12752
+ var _HORIZONTAL_ALIGN_OPT;
12753
+ return ((_HORIZONTAL_ALIGN_OPT = HORIZONTAL_ALIGN_OPTIONS.find((option) => option.value === alignType)) === null || _HORIZONTAL_ALIGN_OPT === void 0 ? void 0 : _HORIZONTAL_ALIGN_OPT.icon) ?? "LeftJustifyingIcon";
12845
12754
  })),
12846
12755
  tooltip: "docs-ui.toolbar.alignLeft",
12847
12756
  selections: HORIZONTAL_ALIGN_OPTIONS,
@@ -12865,17 +12774,16 @@ const listValueFactory$ = (accessor) => {
12865
12774
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
12866
12775
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
12867
12776
  const subscription = univerInstanceService.focused$.subscribe((unitId) => {
12868
- var _docRanges$find;
12869
12777
  if (shouldSuppressDocMenuStateRefresh(accessor)) return;
12870
12778
  if (unitId == null) return;
12871
12779
  const docDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
12872
12780
  if (docDataModel == null) return;
12873
12781
  const docRanges = docSelectionManagerService.getDocRanges();
12874
- const range = (_docRanges$find = docRanges.find((r) => r.isActive)) !== null && _docRanges$find !== void 0 ? _docRanges$find : docRanges[0];
12782
+ const range = docRanges.find((r) => r.isActive) ?? docRanges[0];
12875
12783
  if (range) {
12876
- var _doc$getBody$paragrap, _doc$getBody, _doc$getBody$dataStre, _doc$getBody2;
12784
+ var _doc$getBody, _doc$getBody2;
12877
12785
  const doc = docDataModel.getSelfOrHeaderFooterModel(range === null || range === void 0 ? void 0 : range.segmentId);
12878
- const paragraphs = _univerjs_core.BuildTextUtils.range.getParagraphsInRange(range, (_doc$getBody$paragrap = doc === null || doc === void 0 || (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.paragraphs) !== null && _doc$getBody$paragrap !== void 0 ? _doc$getBody$paragrap : [], (_doc$getBody$dataStre = doc === null || doc === void 0 || (_doc$getBody2 = doc.getBody()) === null || _doc$getBody2 === void 0 ? void 0 : _doc$getBody2.dataStream) !== null && _doc$getBody$dataStre !== void 0 ? _doc$getBody$dataStre : "");
12786
+ const paragraphs = _univerjs_core.BuildTextUtils.range.getParagraphsInRange(range, (doc === null || doc === void 0 || (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.paragraphs) ?? [], (doc === null || doc === void 0 || (_doc$getBody2 = doc.getBody()) === null || _doc$getBody2 === void 0 ? void 0 : _doc$getBody2.dataStream) ?? "");
12879
12787
  let listType;
12880
12788
  if (paragraphs.every((p) => {
12881
12789
  if (!listType) {
@@ -12987,7 +12895,7 @@ function BackgroundColorSelectorMenuItemFactory(accessor) {
12987
12895
  return;
12988
12896
  }
12989
12897
  const color = (_textRun$ts10 = textRun.ts) === null || _textRun$ts10 === void 0 || (_textRun$ts10 = _textRun$ts10.bg) === null || _textRun$ts10 === void 0 ? void 0 : _textRun$ts10.rgb;
12990
- subscriber.next(color !== null && color !== void 0 ? color : defaultValue);
12898
+ subscriber.next(color ?? defaultValue);
12991
12899
  };
12992
12900
  const disposable = commandService.onCommandExecuted((c) => {
12993
12901
  if (c.id === SetInlineFormatTextBackgroundColorCommand.id) calc();
@@ -13002,7 +12910,7 @@ function BackgroundColorSelectorMenuItemFactory(accessor) {
13002
12910
  if (c.id === SetInlineFormatTextBackgroundColorCommand.id) {
13003
12911
  if (shouldSuppressDocMenuStateRefresh(accessor)) return;
13004
12912
  const color = c.params.value;
13005
- subscriber.next(color !== null && color !== void 0 ? color : defaultColor);
12913
+ subscriber.next(color ?? defaultColor);
13006
12914
  }
13007
12915
  });
13008
12916
  subscriber.next(defaultColor);
@@ -13013,7 +12921,7 @@ function BackgroundColorSelectorMenuItemFactory(accessor) {
13013
12921
  };
13014
12922
  }
13015
12923
  function getFontStyleAtCursor(accessor) {
13016
- var _docRanges$find2, _docMenuStyleService$, _paragraph$paragraphS11, _paragraph$paragraphS12, _docDataModel$getSelf;
12924
+ var _paragraph$paragraphS8, _paragraph$paragraphS9, _docDataModel$getSelf;
13017
12925
  if (shouldSuppressDocMenuStateRefresh(accessor)) return;
13018
12926
  let univerInstanceService;
13019
12927
  let textSelectionService;
@@ -13028,11 +12936,11 @@ function getFontStyleAtCursor(accessor) {
13028
12936
  }
13029
12937
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
13030
12938
  const docRanges = textSelectionService.getDocRanges();
13031
- const activeRange = (_docRanges$find2 = docRanges.find((r) => r.isActive)) !== null && _docRanges$find2 !== void 0 ? _docRanges$find2 : docRanges[0];
12939
+ const activeRange = docRanges.find((r) => r.isActive) ?? docRanges[0];
13032
12940
  const defaultTextStyle = docMenuStyleService.getDefaultStyle();
13033
- const cacheStyle = (_docMenuStyleService$ = docMenuStyleService.getStyleCache()) !== null && _docMenuStyleService$ !== void 0 ? _docMenuStyleService$ : {};
12941
+ const cacheStyle = docMenuStyleService.getStyleCache() ?? {};
13034
12942
  const paragraph = getParagraphStyleAtCursor(accessor);
13035
- const namedStyle = (paragraph === null || paragraph === void 0 || (_paragraph$paragraphS11 = paragraph.paragraphStyle) === null || _paragraph$paragraphS11 === void 0 ? void 0 : _paragraph$paragraphS11.namedStyleType) ? _univerjs_core.NAMED_STYLE_MAP[paragraph === null || paragraph === void 0 || (_paragraph$paragraphS12 = paragraph.paragraphStyle) === null || _paragraph$paragraphS12 === void 0 ? void 0 : _paragraph$paragraphS12.namedStyleType] : null;
12943
+ const namedStyle = (paragraph === null || paragraph === void 0 || (_paragraph$paragraphS8 = paragraph.paragraphStyle) === null || _paragraph$paragraphS8 === void 0 ? void 0 : _paragraph$paragraphS8.namedStyleType) ? _univerjs_core.NAMED_STYLE_MAP[paragraph === null || paragraph === void 0 || (_paragraph$paragraphS9 = paragraph.paragraphStyle) === null || _paragraph$paragraphS9 === void 0 ? void 0 : _paragraph$paragraphS9.namedStyleType] : null;
13036
12944
  if (docDataModel == null || activeRange == null) return { ts: {
13037
12945
  ...defaultTextStyle,
13038
12946
  ...namedStyle,
@@ -13055,7 +12963,7 @@ function getFontStyleAtCursor(accessor) {
13055
12963
  } };
13056
12964
  }
13057
12965
  function getParagraphStyleAtCursor(accessor) {
13058
- var _docRanges$find3, _docDataModel$getSelf2;
12966
+ var _docDataModel$getSelf2;
13059
12967
  if (shouldSuppressDocMenuStateRefresh(accessor)) return;
13060
12968
  let univerInstanceService;
13061
12969
  let textSelectionService;
@@ -13068,7 +12976,7 @@ function getParagraphStyleAtCursor(accessor) {
13068
12976
  }
13069
12977
  const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
13070
12978
  const docRanges = textSelectionService.getDocRanges();
13071
- const activeRange = (_docRanges$find3 = docRanges.find((r) => r.isActive)) !== null && _docRanges$find3 !== void 0 ? _docRanges$find3 : docRanges[0];
12979
+ const activeRange = docRanges.find((r) => r.isActive) ?? docRanges[0];
13072
12980
  if (docDataModel == null || activeRange == null) return;
13073
12981
  const { startOffset, segmentId } = activeRange;
13074
12982
  const paragraphs = (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf2 === void 0 || (_docDataModel$getSelf2 = _docDataModel$getSelf2.getBody()) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.paragraphs;
@@ -13098,11 +13006,10 @@ function PageSettingMenuItemFactory(accessor) {
13098
13006
  //#endregion
13099
13007
  //#region src/views/paragraph-menu/theme-color.ts
13100
13008
  function getHighlightBackgroundColor(themeService, index) {
13101
- var _themeService$getColo;
13102
13009
  const tokenPath = `highlight.background.${index + 1}`;
13103
13010
  const token = themeService.getColorFromTheme(tokenPath);
13104
13011
  if (token == null || typeof token.color !== "string" || typeof token.alpha !== "number") throw new Error(`Theme token ${tokenPath} is required.`);
13105
- return new _univerjs_core.ColorKit((_themeService$getColo = themeService.getColorFromTheme(token.color)) !== null && _themeService$getColo !== void 0 ? _themeService$getColo : token.color).setAlpha(token.alpha).toRgbString();
13012
+ return new _univerjs_core.ColorKit(themeService.getColorFromTheme(token.color) ?? token.color).setAlpha(token.alpha).toRgbString();
13106
13013
  }
13107
13014
 
13108
13015
  //#endregion
@@ -13140,22 +13047,21 @@ const BACKGROUND_COLOR_SWATCH_ICONS = [
13140
13047
  "DocParagraphBackgroundColorSwatchIcon.11",
13141
13048
  "DocParagraphBackgroundColorSwatchIcon.12",
13142
13049
  "DocParagraphBackgroundColorSwatchIcon.13",
13143
- "DocParagraphBackgroundColorSwatchIcon.14",
13144
- "DocParagraphBackgroundColorSwatchIcon.15"
13050
+ "DocParagraphBackgroundColorSwatchIcon.14"
13145
13051
  ];
13146
13052
  function getHeadingActivatedObservable(accessor, headingType) {
13147
13053
  const commandService = accessor.get(_univerjs_core.ICommandService);
13148
13054
  return new rxjs.Observable((subscriber) => {
13149
13055
  const DEFAULT_TYPE = _univerjs_core.NamedStyleType.NORMAL_TEXT;
13150
13056
  const calc = () => {
13151
- var _paragraph$paragraphS, _paragraph$paragraphS2;
13057
+ var _paragraph$paragraphS;
13152
13058
  if (shouldSuppressDocMenuStateRefresh(accessor)) return;
13153
13059
  const paragraph = getParagraphStyleAtCursor(accessor);
13154
13060
  if (paragraph == null) {
13155
13061
  subscriber.next(DEFAULT_TYPE === headingType);
13156
13062
  return;
13157
13063
  }
13158
- const namedStyleType = (_paragraph$paragraphS = (_paragraph$paragraphS2 = paragraph.paragraphStyle) === null || _paragraph$paragraphS2 === void 0 ? void 0 : _paragraph$paragraphS2.namedStyleType) !== null && _paragraph$paragraphS !== void 0 ? _paragraph$paragraphS : DEFAULT_TYPE;
13064
+ const namedStyleType = ((_paragraph$paragraphS = paragraph.paragraphStyle) === null || _paragraph$paragraphS === void 0 ? void 0 : _paragraph$paragraphS.namedStyleType) ?? DEFAULT_TYPE;
13159
13065
  subscriber.next(namedStyleType === headingType);
13160
13066
  };
13161
13067
  const disposable = commandService.onCommandExecuted((c) => {
@@ -14681,9 +14587,8 @@ function CountBar(_props) {
14681
14587
  //#endregion
14682
14588
  //#region src/views/doc-footer/DocFooter.tsx
14683
14589
  function DocFooterContent() {
14684
- var _config$footer;
14685
14590
  const config = (0, _univerjs_ui.useConfigValue)(DOCS_UI_PLUGIN_CONFIG_KEY);
14686
- return ((_config$footer = config === null || config === void 0 ? void 0 : config.footer) !== null && _config$footer !== void 0 ? _config$footer : true) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
14591
+ return ((config === null || config === void 0 ? void 0 : config.footer) ?? true) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
14687
14592
  className: "univer-box-border univer-flex univer-items-center univer-justify-between univer-px-5 univer-py-1.5",
14688
14593
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CountBar, {})]
14689
14594
  });
@@ -14848,8 +14753,7 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends _unive
14848
14753
  return this._createRectPositionObserver(getBound, currentRender);
14849
14754
  }
14850
14755
  _createRangePositionObserver(range, currentRender) {
14851
- var _calcDocRangePosition;
14852
- const positions = (_calcDocRangePosition = calcDocRangePositions(range, currentRender)) !== null && _calcDocRangePosition !== void 0 ? _calcDocRangePosition : [];
14756
+ const positions = calcDocRangePositions(range, currentRender) ?? [];
14853
14757
  const positions$ = new rxjs.BehaviorSubject(positions);
14854
14758
  const disposable = new _univerjs_core.DisposableCollection();
14855
14759
  disposable.add(this._commandService.onCommandExecuted((commandInfo) => {
@@ -14955,7 +14859,7 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends _unive
14955
14859
  "top",
14956
14860
  "bottom",
14957
14861
  "horizontal"
14958
- ].some((i) => direction.includes(i)) ? bounds.length > 1 ? multipleDirection !== null && multipleDirection !== void 0 ? multipleDirection : direction : direction : direction,
14862
+ ].some((i) => direction.includes(i)) ? bounds.length > 1 ? multipleDirection ?? direction : direction : direction,
14959
14863
  canvasElement: currentRender.engine.getCanvasElement()
14960
14864
  });
14961
14865
  return {
@@ -14986,8 +14890,8 @@ const calcDocRangePositions$1 = (range, documents, skeleton, pageIndex) => {
14986
14890
  const skeletonData = skeleton.getSkeletonData();
14987
14891
  let end = range.collapsed ? range.startOffset : range.endOffset - 1;
14988
14892
  if (range.segmentId) {
14989
- var _Array$from$, _skeletonData$skeFoot, _skeletonData$skeFoot2, _skeletonData$skeHead, _skeletonData$skeHead2;
14990
- const root = (_Array$from$ = Array.from((_skeletonData$skeFoot = skeletonData === null || skeletonData === void 0 || (_skeletonData$skeFoot2 = skeletonData.skeFooters.get(range.segmentId)) === null || _skeletonData$skeFoot2 === void 0 ? void 0 : _skeletonData$skeFoot2.values()) !== null && _skeletonData$skeFoot !== void 0 ? _skeletonData$skeFoot : [])[0]) !== null && _Array$from$ !== void 0 ? _Array$from$ : Array.from((_skeletonData$skeHead = skeletonData === null || skeletonData === void 0 || (_skeletonData$skeHead2 = skeletonData.skeHeaders.get(range.segmentId)) === null || _skeletonData$skeHead2 === void 0 ? void 0 : _skeletonData$skeHead2.values()) !== null && _skeletonData$skeHead !== void 0 ? _skeletonData$skeHead : [])[0];
14893
+ var _skeletonData$skeFoot, _skeletonData$skeHead;
14894
+ const root = Array.from((skeletonData === null || skeletonData === void 0 || (_skeletonData$skeFoot = skeletonData.skeFooters.get(range.segmentId)) === null || _skeletonData$skeFoot === void 0 ? void 0 : _skeletonData$skeFoot.values()) ?? [])[0] ?? Array.from((skeletonData === null || skeletonData === void 0 || (_skeletonData$skeHead = skeletonData.skeHeaders.get(range.segmentId)) === null || _skeletonData$skeHead === void 0 ? void 0 : _skeletonData$skeHead.values()) ?? [])[0];
14991
14895
  if (root) end = Math.min(root.ed, end);
14992
14896
  }
14993
14897
  const endPosition = skeleton.findNodePositionByCharIndex(end, true, range.segmentId, pageIndex);
@@ -15081,7 +14985,7 @@ const calcParagraphPositionsFromLineContexts = (contexts, docsLeft, docsTop) =>
15081
14985
  };
15082
14986
  function getParagraphLineBottom(context, lineTop) {
15083
14987
  const lineBottom = lineTop + context.line.lineHeight;
15084
- if (context.source !== "column" || context.line !== context.column.lines.at(-1) || !Number.isFinite(context.page.pageHeight)) return lineBottom;
14988
+ if (context.source !== "column" || context.line !== context.column.lines[context.column.lines.length - 1] || !Number.isFinite(context.page.pageHeight)) return lineBottom;
15085
14989
  const pageTop = lineTop - context.line.top - context.section.top;
15086
14990
  return Math.max(lineBottom, pageTop + context.page.pageHeight);
15087
14991
  }
@@ -15160,9 +15064,8 @@ function getTableBlockMenuHoverRect(tableRect) {
15160
15064
  };
15161
15065
  }
15162
15066
  function getTableHorizontalViewportGeometry(tableLeft, tableWidth, viewport) {
15163
- var _viewport$leadingInse;
15164
15067
  const hasHorizontalViewport = hasHorizontalTableViewport(viewport);
15165
- const visibleLeft = hasHorizontalViewport ? tableLeft - ((_viewport$leadingInse = viewport.leadingInsetLeft) !== null && _viewport$leadingInse !== void 0 ? _viewport$leadingInse : 0) : tableLeft;
15068
+ const visibleLeft = hasHorizontalViewport ? tableLeft - (viewport.leadingInsetLeft ?? 0) : tableLeft;
15166
15069
  return {
15167
15070
  scrollLeft: hasHorizontalViewport ? viewport.scrollLeft : 0,
15168
15071
  visibleLeft,
@@ -15170,8 +15073,7 @@ function getTableHorizontalViewportGeometry(tableLeft, tableWidth, viewport) {
15170
15073
  };
15171
15074
  }
15172
15075
  function hasHorizontalTableViewport(viewport) {
15173
- var _viewport$leadingInse2, _viewport$trailingIns;
15174
- return viewport != null && ((_viewport$leadingInse2 = viewport.leadingInsetLeft) !== null && _viewport$leadingInse2 !== void 0 ? _viewport$leadingInse2 : 0) + viewport.contentWidth + ((_viewport$trailingIns = viewport.trailingInsetRight) !== null && _viewport$trailingIns !== void 0 ? _viewport$trailingIns : 0) > viewport.viewportWidth;
15076
+ return viewport != null && (viewport.leadingInsetLeft ?? 0) + viewport.contentWidth + (viewport.trailingInsetRight ?? 0) > viewport.viewportWidth;
15175
15077
  }
15176
15078
  let DocEventManagerService = class DocEventManagerService extends _univerjs_core.Disposable {
15177
15079
  get hoverParagraph() {
@@ -15303,8 +15205,7 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15303
15205
  })))), (0, rxjs.filter)(({ down, up }) => down.target === up.target && (down.button === 2 || up.timeStamp - down.timeStamp < 300))).subscribe(({ down }) => {
15304
15206
  const point = transformOffset2Bound(down.offsetX, down.offsetY, this._context.scene);
15305
15207
  if (down.button === 2) {
15306
- var _this$_calcActiveBull;
15307
- const bullet = (_this$_calcActiveBull = this._calcActiveBullet(point)) !== null && _this$_calcActiveBull !== void 0 ? _this$_calcActiveBull : this._calcActiveListParagraph(point);
15208
+ const bullet = this._calcActiveBullet(point) ?? this._calcActiveListParagraph(point);
15308
15209
  if (bullet) this._contextMenuBullet$.next({
15309
15210
  ...bullet,
15310
15211
  x: down.offsetX,
@@ -15331,13 +15232,12 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15331
15232
  return [...this._bulletBounds];
15332
15233
  }
15333
15234
  getListContextMenuBulletByOffset(offsetX, offsetY) {
15334
- var _this$_calcActiveBull2;
15335
15235
  const point = transformOffset2Bound(offsetX, offsetY, this._context.scene);
15336
- return (_this$_calcActiveBull2 = this._calcActiveBullet(point)) !== null && _this$_calcActiveBull2 !== void 0 ? _this$_calcActiveBull2 : this._calcActiveListParagraph(point);
15236
+ return this._calcActiveBullet(point) ?? this._calcActiveListParagraph(point);
15337
15237
  }
15338
15238
  _buildCustomRangeBoundsBySegment(segmentId, segmentPage = -1) {
15339
- var _this$_context$unit$g, _this$_context$unit$g2;
15340
- const customRanges = (_this$_context$unit$g = (_this$_context$unit$g2 = this._context.unit.getSelfOrHeaderFooterModel(segmentId)) === null || _this$_context$unit$g2 === void 0 || (_this$_context$unit$g2 = _this$_context$unit$g2.getBody()) === null || _this$_context$unit$g2 === void 0 ? void 0 : _this$_context$unit$g2.customRanges) !== null && _this$_context$unit$g !== void 0 ? _this$_context$unit$g : [];
15239
+ var _this$_context$unit$g;
15240
+ const customRanges = ((_this$_context$unit$g = this._context.unit.getSelfOrHeaderFooterModel(segmentId)) === null || _this$_context$unit$g === void 0 || (_this$_context$unit$g = _this$_context$unit$g.getBody()) === null || _this$_context$unit$g === void 0 ? void 0 : _this$_context$unit$g.customRanges) ?? [];
15341
15241
  const layouts = [];
15342
15242
  customRanges.forEach((range) => {
15343
15243
  const textRange = {
@@ -15382,9 +15282,9 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15382
15282
  }));
15383
15283
  }
15384
15284
  _buildBulletBoundsBySegment(segmentId, segmentPage = -1) {
15385
- var _this$_context$unit$g3, _body$paragraphs;
15386
- const body = (_this$_context$unit$g3 = this._context.unit.getSelfOrHeaderFooterModel(segmentId)) === null || _this$_context$unit$g3 === void 0 ? void 0 : _this$_context$unit$g3.getBody();
15387
- const paragraphs = ((_body$paragraphs = body === null || body === void 0 ? void 0 : body.paragraphs) !== null && _body$paragraphs !== void 0 ? _body$paragraphs : []).filter((p) => p.bullet);
15285
+ var _this$_context$unit$g2;
15286
+ const body = (_this$_context$unit$g2 = this._context.unit.getSelfOrHeaderFooterModel(segmentId)) === null || _this$_context$unit$g2 === void 0 ? void 0 : _this$_context$unit$g2.getBody();
15287
+ const paragraphs = ((body === null || body === void 0 ? void 0 : body.paragraphs) ?? []).filter((p) => p.bullet);
15388
15288
  const bounds = [];
15389
15289
  const skeletonData = this._skeleton.getSkeletonData();
15390
15290
  if (!skeletonData) return bounds;
@@ -15416,8 +15316,8 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15416
15316
  return bounds;
15417
15317
  };
15418
15318
  if (segmentId) {
15419
- var _skeletonData$skeFoot3, _skeletonData$skeFoot4, _skeletonData$skeHead3;
15420
- const page = (_skeletonData$skeFoot3 = (_skeletonData$skeFoot4 = skeletonData.skeFooters.get(segmentId)) === null || _skeletonData$skeFoot4 === void 0 ? void 0 : _skeletonData$skeFoot4.values()) !== null && _skeletonData$skeFoot3 !== void 0 ? _skeletonData$skeFoot3 : (_skeletonData$skeHead3 = skeletonData.skeHeaders.get(segmentId)) === null || _skeletonData$skeHead3 === void 0 ? void 0 : _skeletonData$skeHead3.values();
15319
+ var _skeletonData$skeFoot2, _skeletonData$skeHead2;
15320
+ const page = ((_skeletonData$skeFoot2 = skeletonData.skeFooters.get(segmentId)) === null || _skeletonData$skeFoot2 === void 0 ? void 0 : _skeletonData$skeFoot2.values()) ?? ((_skeletonData$skeHead2 = skeletonData.skeHeaders.get(segmentId)) === null || _skeletonData$skeHead2 === void 0 ? void 0 : _skeletonData$skeHead2.values());
15421
15321
  if (!page) return bounds;
15422
15322
  return calc(Array.from(page));
15423
15323
  }
@@ -15449,8 +15349,8 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15449
15349
  return getListParagraphContextMenuHit(paragraphBound, this._getParagraphByStartIndex(paragraphBound.startIndex, paragraphBound.segmentId), evt);
15450
15350
  }
15451
15351
  _getParagraphByStartIndex(startIndex, segmentId) {
15452
- var _this$_context$unit$g4;
15453
- return (_this$_context$unit$g4 = this._context.unit.getSelfOrHeaderFooterModel(segmentId)) === null || _this$_context$unit$g4 === void 0 || (_this$_context$unit$g4 = _this$_context$unit$g4.getBody()) === null || _this$_context$unit$g4 === void 0 || (_this$_context$unit$g4 = _this$_context$unit$g4.paragraphs) === null || _this$_context$unit$g4 === void 0 ? void 0 : _this$_context$unit$g4.find((paragraph) => paragraph.startIndex === startIndex);
15352
+ var _this$_context$unit$g3;
15353
+ return (_this$_context$unit$g3 = this._context.unit.getSelfOrHeaderFooterModel(segmentId)) === null || _this$_context$unit$g3 === void 0 || (_this$_context$unit$g3 = _this$_context$unit$g3.getBody()) === null || _this$_context$unit$g3 === void 0 || (_this$_context$unit$g3 = _this$_context$unit$g3.paragraphs) === null || _this$_context$unit$g3 === void 0 ? void 0 : _this$_context$unit$g3.find((paragraph) => paragraph.startIndex === startIndex);
15454
15354
  }
15455
15355
  _buildParagraphBoundsBySegment(segmentId) {
15456
15356
  const skeletonData = this._skeleton.getSkeletonData();
@@ -15485,9 +15385,8 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15485
15385
  pageMarginTop: documentOffsetConfig.pageMarginTop,
15486
15386
  unitId: this._context.unitId
15487
15387
  }, (context) => {
15488
- var _lineContextsBySource;
15489
15388
  if (context.source === "table-cell") return;
15490
- const lineContexts = (_lineContextsBySource = lineContextsBySource.get(context.pageIndex)) !== null && _lineContextsBySource !== void 0 ? _lineContextsBySource : [];
15389
+ const lineContexts = lineContextsBySource.get(context.pageIndex) ?? [];
15491
15390
  lineContexts.push(context);
15492
15391
  lineContextsBySource.set(context.pageIndex, lineContexts);
15493
15392
  });
@@ -15512,9 +15411,8 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15512
15411
  tableId
15513
15412
  });
15514
15413
  for (const cellGeometry of tableContext.cells) {
15515
- var _cell$pageWidth, _cell$marginLeft, _cell$marginRight;
15516
15414
  const cell = cellGeometry.cell;
15517
- const cellContentWidth = ((_cell$pageWidth = cell.pageWidth) !== null && _cell$pageWidth !== void 0 ? _cell$pageWidth : 0) - ((_cell$marginLeft = cell.marginLeft) !== null && _cell$marginLeft !== void 0 ? _cell$marginLeft : 0) - ((_cell$marginRight = cell.marginRight) !== null && _cell$marginRight !== void 0 ? _cell$marginRight : 0);
15415
+ const cellContentWidth = (cell.pageWidth ?? 0) - (cell.marginLeft ?? 0) - (cell.marginRight ?? 0);
15518
15416
  const bounds = calcDocParagraphPositions(cell.sections, cellGeometry.pageTop, cellGeometry.pageLeft, cellContentWidth).map((bound) => clipParagraphBoundHorizontally(bound, cellGeometry.clipLeft, cellGeometry.clipRight)).filter((bound) => bound != null);
15519
15417
  let arr = this._tableParagraphBounds.get(tableId);
15520
15418
  if (!arr) {
@@ -15550,15 +15448,15 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15550
15448
  return paragraphMap;
15551
15449
  };
15552
15450
  if (segmentId) {
15553
- var _skeletonData$skeFoot5, _skeletonData$skeFoot6, _skeletonData$skeHead4;
15554
- const page = (_skeletonData$skeFoot5 = (_skeletonData$skeFoot6 = skeletonData.skeFooters.get(segmentId)) === null || _skeletonData$skeFoot6 === void 0 ? void 0 : _skeletonData$skeFoot6.values()) !== null && _skeletonData$skeFoot5 !== void 0 ? _skeletonData$skeFoot5 : (_skeletonData$skeHead4 = skeletonData.skeHeaders.get(segmentId)) === null || _skeletonData$skeHead4 === void 0 ? void 0 : _skeletonData$skeHead4.values();
15451
+ var _skeletonData$skeFoot3, _skeletonData$skeHead3;
15452
+ const page = ((_skeletonData$skeFoot3 = skeletonData.skeFooters.get(segmentId)) === null || _skeletonData$skeFoot3 === void 0 ? void 0 : _skeletonData$skeFoot3.values()) ?? ((_skeletonData$skeHead3 = skeletonData.skeHeaders.get(segmentId)) === null || _skeletonData$skeHead3 === void 0 ? void 0 : _skeletonData$skeHead3.values());
15555
15453
  if (!page) return null;
15556
15454
  return calc(Array.from(page));
15557
15455
  }
15558
15456
  return calc(skeletonData.pages);
15559
15457
  }
15560
15458
  _buildParagraphBounds() {
15561
- var _this$_buildParagraph, _this$_skeleton$getSk3;
15459
+ var _this$_skeleton$getSk3;
15562
15460
  const tableViewportSignature = this._getTableViewportSignature();
15563
15461
  if (!this._paragraphDirty && this._tableViewportSignature === tableViewportSignature) return;
15564
15462
  this._paragraphDirty = false;
@@ -15566,7 +15464,7 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15566
15464
  this._tableParagraphBounds = /* @__PURE__ */ new Map();
15567
15465
  this._tableCellBounds = /* @__PURE__ */ new Map();
15568
15466
  this._tableBounds = /* @__PURE__ */ new Map();
15569
- this._paragraphBounds = (_this$_buildParagraph = this._buildParagraphBoundsBySegment()) !== null && _this$_buildParagraph !== void 0 ? _this$_buildParagraph : /* @__PURE__ */ new Map();
15467
+ this._paragraphBounds = this._buildParagraphBoundsBySegment() ?? /* @__PURE__ */ new Map();
15570
15468
  this._paragraphLeftBounds = Array.from(this._paragraphBounds.values()).map((bound) => ({
15571
15469
  ...bound,
15572
15470
  rect: {
@@ -15577,8 +15475,7 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15577
15475
  }
15578
15476
  }));
15579
15477
  const handleSegment = (segmentId) => {
15580
- var _this$_buildParagraph2;
15581
- this._segmentParagraphBounds.set(segmentId, (_this$_buildParagraph2 = this._buildParagraphBoundsBySegment(segmentId)) !== null && _this$_buildParagraph2 !== void 0 ? _this$_buildParagraph2 : /* @__PURE__ */ new Map());
15478
+ this._segmentParagraphBounds.set(segmentId, this._buildParagraphBoundsBySegment(segmentId) ?? /* @__PURE__ */ new Map());
15582
15479
  };
15583
15480
  (_this$_skeleton$getSk3 = this._skeleton.getSkeletonData()) === null || _this$_skeleton$getSk3 === void 0 || _this$_skeleton$getSk3.pages.forEach((page) => {
15584
15481
  if (page.headerId) handleSegment(page.headerId);
@@ -15643,8 +15540,8 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15643
15540
  })), startIndex, endIndex);
15644
15541
  }
15645
15542
  _getTableViewportSignature() {
15646
- var _this$_skeleton$getSk4, _this$_skeleton$getSk5;
15647
- const pages = (_this$_skeleton$getSk4 = (_this$_skeleton$getSk5 = this._skeleton.getSkeletonData()) === null || _this$_skeleton$getSk5 === void 0 ? void 0 : _this$_skeleton$getSk5.pages) !== null && _this$_skeleton$getSk4 !== void 0 ? _this$_skeleton$getSk4 : [];
15543
+ var _this$_skeleton$getSk4;
15544
+ const pages = ((_this$_skeleton$getSk4 = this._skeleton.getSkeletonData()) === null || _this$_skeleton$getSk4 === void 0 ? void 0 : _this$_skeleton$getSk4.pages) ?? [];
15648
15545
  const signatures = [];
15649
15546
  for (const tableContext of (0, _univerjs_engine_render.documentSkeletonTableIterator)(pages, {
15650
15547
  pageMarginTop: this._documents.getOffsetConfig().pageMarginTop,
@@ -15672,13 +15569,12 @@ function isRangeOverlappingParagraph(bound, startIndex, endIndex) {
15672
15569
  return Math.max(bound.paragraphStart, startIndex) <= Math.min(bound.paragraphEnd, endIndex);
15673
15570
  }
15674
15571
  function clipParagraphBoundHorizontally(bound, visibleLeft, visibleRight) {
15675
- var _clipRectHorizontally;
15676
15572
  const rect = clipRectHorizontally(bound.rect, visibleLeft, visibleRight);
15677
15573
  if (!rect) return null;
15678
15574
  return {
15679
15575
  ...bound,
15680
15576
  rect,
15681
- fisrtLine: (_clipRectHorizontally = clipRectHorizontally(bound.fisrtLine, visibleLeft, visibleRight)) !== null && _clipRectHorizontally !== void 0 ? _clipRectHorizontally : rect
15577
+ fisrtLine: clipRectHorizontally(bound.fisrtLine, visibleLeft, visibleRight) ?? rect
15682
15578
  };
15683
15579
  }
15684
15580
  function clipRectHorizontally(rect, visibleLeft, visibleRight) {
@@ -15734,7 +15630,7 @@ const SideMenu = (0, react.forwardRef)((props, ref) => {
15734
15630
  transform: open ? "translateX(0)" : "translateX(-100%)",
15735
15631
  maxHeight,
15736
15632
  opacity: open ? 1 : 0,
15737
- maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth : mode === "side-bar" ? 320 : 180,
15633
+ maxWidth: maxWidth ?? (mode === "side-bar" ? 320 : 180),
15738
15634
  paddingRight: mode === "float" ? void 0 : 0
15739
15635
  },
15740
15636
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
@@ -15799,28 +15695,28 @@ function DocSideMenu() {
15799
15695
  return null;
15800
15696
  }
15801
15697
  function DocSideMenuContent() {
15802
- var _documentData$body$da, _documentData$body, _currentDoc$getUnitId, _documentData$body$pa, _documentData$body2;
15698
+ var _documentData$body, _documentData$body2;
15803
15699
  const instanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
15804
15700
  const currentDoc = (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => instanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC), []));
15805
15701
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
15806
15702
  const documentData = (0, _univerjs_ui.useObservable)(currentDoc ? () => currentDoc.change$.pipe((0, rxjs.debounceTime)(100), (0, rxjs.map)(() => currentDoc.getSnapshot())) : null, currentDoc === null || currentDoc === void 0 ? void 0 : currentDoc.getSnapshot(), false, [currentDoc]);
15807
- const fullDataStream = (_documentData$body$da = documentData === null || documentData === void 0 || (_documentData$body = documentData.body) === null || _documentData$body === void 0 ? void 0 : _documentData$body.dataStream) !== null && _documentData$body$da !== void 0 ? _documentData$body$da : "";
15703
+ const fullDataStream = (documentData === null || documentData === void 0 || (_documentData$body = documentData.body) === null || _documentData$body === void 0 ? void 0 : _documentData$body.dataStream) ?? "";
15808
15704
  const [activeId, setActiveId] = (0, react.useState)(void 0);
15809
- const unitId = (_currentDoc$getUnitId = currentDoc === null || currentDoc === void 0 ? void 0 : currentDoc.getUnitId()) !== null && _currentDoc$getUnitId !== void 0 ? _currentDoc$getUnitId : "";
15705
+ const unitId = (currentDoc === null || currentDoc === void 0 ? void 0 : currentDoc.getUnitId()) ?? "";
15810
15706
  const renderer = renderManagerService.getRenderUnitById(unitId);
15811
15707
  const title = documentData === null || documentData === void 0 ? void 0 : documentData.title;
15812
15708
  const docEventManagerService = renderer === null || renderer === void 0 ? void 0 : renderer.with(DocEventManagerService);
15813
15709
  const paragraphBounds = docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.paragraphBounds;
15814
15710
  const readLayout = () => {
15815
- var _renderer$mainCompone, _renderer$mainCompone2, _renderer$engine$heig, _renderer$scene$scale;
15711
+ var _renderer$mainCompone;
15816
15712
  return {
15817
- left: (_renderer$mainCompone = renderer === null || renderer === void 0 || (_renderer$mainCompone2 = renderer.mainComponent) === null || _renderer$mainCompone2 === void 0 ? void 0 : _renderer$mainCompone2.left) !== null && _renderer$mainCompone !== void 0 ? _renderer$mainCompone : 0,
15818
- canvasHeight: (_renderer$engine$heig = renderer === null || renderer === void 0 ? void 0 : renderer.engine.height) !== null && _renderer$engine$heig !== void 0 ? _renderer$engine$heig : 0,
15819
- scaleY: (_renderer$scene$scale = renderer === null || renderer === void 0 ? void 0 : renderer.scene.scaleY) !== null && _renderer$scene$scale !== void 0 ? _renderer$scene$scale : 1
15713
+ left: (renderer === null || renderer === void 0 || (_renderer$mainCompone = renderer.mainComponent) === null || _renderer$mainCompone === void 0 ? void 0 : _renderer$mainCompone.left) ?? 0,
15714
+ canvasHeight: (renderer === null || renderer === void 0 ? void 0 : renderer.engine.height) ?? 0,
15715
+ scaleY: (renderer === null || renderer === void 0 ? void 0 : renderer.scene.scaleY) ?? 1
15820
15716
  };
15821
15717
  };
15822
15718
  const { left, canvasHeight, scaleY } = (0, _univerjs_ui.useObservable)((renderer === null || renderer === void 0 ? void 0 : renderer.engine.onTransformChange$) ? () => (0, _univerjs_core.fromEventSubject)(renderer.engine.onTransformChange$).pipe((0, rxjs.throttleTime)(33), (0, rxjs.map)(readLayout), (0, rxjs.startWith)(readLayout())) : null, readLayout(), false, [renderer]);
15823
- const paragraphs = (_documentData$body$pa = documentData === null || documentData === void 0 || (_documentData$body2 = documentData.body) === null || _documentData$body2 === void 0 ? void 0 : _documentData$body2.paragraphs) !== null && _documentData$body$pa !== void 0 ? _documentData$body$pa : [];
15719
+ const paragraphs = (documentData === null || documentData === void 0 || (_documentData$body2 = documentData.body) === null || _documentData$body2 === void 0 ? void 0 : _documentData$body2.paragraphs) ?? [];
15824
15720
  const paragraphMap = (0, react.useMemo)(() => {
15825
15721
  const map = /* @__PURE__ */ new Map();
15826
15722
  paragraphs.forEach((p) => {
@@ -15858,7 +15754,7 @@ function DocSideMenuContent() {
15858
15754
  text: title,
15859
15755
  level: 1,
15860
15756
  isTitle: true
15861
- }] : [], ...paragraphMenus !== null && paragraphMenus !== void 0 ? paragraphMenus : []].filter(Boolean);
15757
+ }] : [], ...paragraphMenus ?? []].filter(Boolean);
15862
15758
  const [open, setOpen] = (0, react.useState)(true);
15863
15759
  (0, react.useEffect)(() => {
15864
15760
  const viewport = renderer === null || renderer === void 0 ? void 0 : renderer.scene.getViewport("viewMain");
@@ -16036,12 +15932,22 @@ function createDefaultDocsTableLikeCustomBlockBleedViewport() {
16036
15932
  }
16037
15933
  function resolveDocsTableLikeCustomBlockBleedViewport(root, contentWidth, hint) {
16038
15934
  const rootRect = root.getBoundingClientRect();
16039
- const rootWidth = Math.max(1, rootRect.width);
15935
+ const hintedViewScale = hint === null || hint === void 0 ? void 0 : hint.viewScale;
15936
+ const viewScale = typeof hintedViewScale === "number" && Number.isFinite(hintedViewScale) && hintedViewScale > 0 ? hintedViewScale : 1;
15937
+ const rootWidth = Math.max(1, rootRect.width / viewScale);
16040
15938
  const normalizedContentWidth = Math.max(1, contentWidth);
16041
15939
  const hintedBleedLeft = hint === null || hint === void 0 ? void 0 : hint.bleedLeft;
16042
15940
  const hintedBleedWidth = hint === null || hint === void 0 ? void 0 : hint.bleedWidth;
16043
- if (Number.isFinite(hintedBleedWidth) && (hintedBleedWidth !== null && hintedBleedWidth !== void 0 ? hintedBleedWidth : 0) > 0) {
16044
- const bleedLeft = Math.max(0, hintedBleedLeft !== null && hintedBleedLeft !== void 0 ? hintedBleedLeft : 0);
15941
+ const hasBleedHint = Number.isFinite(hintedBleedWidth) && (hintedBleedWidth ?? 0) > 0;
15942
+ if (normalizedContentWidth <= rootWidth && ((hint === null || hint === void 0 ? void 0 : hint.authoritativeContentWidth) || !hasBleedHint)) return {
15943
+ bleedLeft: 0,
15944
+ bleedRight: 0,
15945
+ bleedWidth: rootWidth,
15946
+ contentWidth: normalizedContentWidth,
15947
+ virtualWidth: rootWidth
15948
+ };
15949
+ if (hasBleedHint) {
15950
+ const bleedLeft = Math.max(0, hintedBleedLeft ?? 0);
16045
15951
  const bleedWidth = Math.max(1, hintedBleedWidth);
16046
15952
  return {
16047
15953
  bleedLeft,
@@ -16051,30 +15957,25 @@ function resolveDocsTableLikeCustomBlockBleedViewport(root, contentWidth, hint)
16051
15957
  virtualWidth: Math.max(bleedWidth, bleedLeft + normalizedContentWidth)
16052
15958
  };
16053
15959
  }
16054
- if (normalizedContentWidth <= rootWidth) return {
16055
- bleedLeft: 0,
16056
- bleedRight: 0,
16057
- bleedWidth: rootWidth,
16058
- contentWidth: normalizedContentWidth,
16059
- virtualWidth: rootWidth
16060
- };
16061
15960
  const bounds = resolveDocsTableLikeCustomBlockBleedBounds(root);
16062
15961
  const viewportLeft = bounds.left + DOCS_CUSTOM_BLOCK_VIEWPORT_INSET;
16063
15962
  const viewportWidth = Math.max(1, bounds.width - DOCS_CUSTOM_BLOCK_VIEWPORT_INSET * 2);
16064
- const bleedLeft = Math.max(0, rootRect.left - viewportLeft);
15963
+ const bleedLeft = Math.max(0, (rootRect.left - viewportLeft) / viewScale);
15964
+ const bleedRight = Math.max(0, (viewportLeft + viewportWidth - rootRect.right) / viewScale);
15965
+ const logicalViewportWidth = viewportWidth / viewScale;
16065
15966
  return {
16066
15967
  bleedLeft,
16067
- bleedRight: Math.max(0, viewportLeft + viewportWidth - rootRect.right),
16068
- bleedWidth: viewportWidth,
15968
+ bleedRight,
15969
+ bleedWidth: logicalViewportWidth,
16069
15970
  contentWidth: normalizedContentWidth,
16070
- virtualWidth: Math.max(viewportWidth, bleedLeft + normalizedContentWidth)
15971
+ virtualWidth: Math.max(logicalViewportWidth, bleedLeft + normalizedContentWidth)
16071
15972
  };
16072
15973
  }
16073
15974
  function resolveDocsTableLikeCustomBlockContentWidth(authoritativeContentWidth, fallbackContentWidth) {
16074
- return Number.isFinite(authoritativeContentWidth) && (authoritativeContentWidth !== null && authoritativeContentWidth !== void 0 ? authoritativeContentWidth : 0) > 0 ? authoritativeContentWidth : Math.max(1, fallbackContentWidth);
15975
+ return Number.isFinite(authoritativeContentWidth) && (authoritativeContentWidth ?? 0) > 0 ? authoritativeContentWidth : Math.max(1, fallbackContentWidth);
16075
15976
  }
16076
15977
  function resolveDocsTableLikeCustomBlockContentHeight(authoritativeContentHeight, fallbackContentHeight) {
16077
- return Number.isFinite(authoritativeContentHeight) && (authoritativeContentHeight !== null && authoritativeContentHeight !== void 0 ? authoritativeContentHeight : 0) > 0 ? authoritativeContentHeight : Math.max(1, fallbackContentHeight);
15978
+ return Number.isFinite(authoritativeContentHeight) && (authoritativeContentHeight ?? 0) > 0 ? authoritativeContentHeight : Math.max(1, fallbackContentHeight);
16078
15979
  }
16079
15980
  function resolveDocsTableLikeCustomBlockBleedBounds(root) {
16080
15981
  const clippingAncestor = findClippingAncestor(root);
@@ -16110,10 +16011,9 @@ function hasClippingOverflow(value) {
16110
16011
  //#region src/embed-docs-custom-block-refresh.ts
16111
16012
  function collectDocsTableLikeEmbedChildUnitIds(drawings, resolveChildUnitId) {
16112
16013
  const childUnitIds = /* @__PURE__ */ new Set();
16113
- Object.values(drawings !== null && drawings !== void 0 ? drawings : {}).forEach((drawing) => {
16114
- var _resolveChildUnitId;
16014
+ Object.values(drawings ?? {}).forEach((drawing) => {
16115
16015
  const data = getDrawingData(drawing);
16116
- const childUnitId = data ? (_resolveChildUnitId = resolveChildUnitId === null || resolveChildUnitId === void 0 ? void 0 : resolveChildUnitId(data)) !== null && _resolveChildUnitId !== void 0 ? _resolveChildUnitId : typeof data.childUnitId === "string" ? data.childUnitId : void 0 : void 0;
16016
+ const childUnitId = data ? (resolveChildUnitId === null || resolveChildUnitId === void 0 ? void 0 : resolveChildUnitId(data)) ?? (typeof data.childUnitId === "string" ? data.childUnitId : void 0) : void 0;
16117
16017
  const childType = typeof (data === null || data === void 0 ? void 0 : data.childType) === "number" ? data.childType : void 0;
16118
16018
  if (!childUnitId || !(0, _univerjs_docs.isSheetLikeDocsCustomBlockChildType)(childType)) return;
16119
16019
  childUnitIds.add(childUnitId);
@@ -16196,31 +16096,31 @@ function clampScroll(value, min, max) {
16196
16096
  function resolveMaxScrollLeft(element, requestedMaxScrollLeft) {
16197
16097
  const nativeMaxScrollLeft = Math.max(0, element.scrollWidth - element.clientWidth);
16198
16098
  if (!Number.isFinite(requestedMaxScrollLeft)) return nativeMaxScrollLeft;
16199
- return clampScroll(requestedMaxScrollLeft !== null && requestedMaxScrollLeft !== void 0 ? requestedMaxScrollLeft : nativeMaxScrollLeft, 0, nativeMaxScrollLeft);
16099
+ return clampScroll(requestedMaxScrollLeft ?? nativeMaxScrollLeft, 0, nativeMaxScrollLeft);
16200
16100
  }
16201
16101
 
16202
16102
  //#endregion
16203
16103
  //#region src/embed-host-anchor.ts
16204
16104
  const MODERN_DOCS_CUSTOM_BLOCK_VIEWPORT_INSET = 10;
16205
16105
  function resolveDocsCustomBlockRenderViewport(params) {
16206
- var _params$fallbackWidth, _params$fallbackHeigh, _params$contentHeight, _params$visibleCanvas, _params$pageMarginLef, _params$pageMarginRig, _params$contentWidth, _params$docsLeft, _params$visibleCanvas2;
16207
16106
  const defaultSize = (0, _univerjs_docs.resolveDocsCustomBlockSize)(params.childType);
16208
- const fallbackWidth = (_params$fallbackWidth = params.fallbackWidth) !== null && _params$fallbackWidth !== void 0 ? _params$fallbackWidth : defaultSize.width;
16209
- const fallbackHeight = (_params$fallbackHeigh = params.fallbackHeight) !== null && _params$fallbackHeigh !== void 0 ? _params$fallbackHeigh : defaultSize.height;
16107
+ const fallbackWidth = params.fallbackWidth ?? defaultSize.width;
16108
+ const fallbackHeight = params.fallbackHeight ?? defaultSize.height;
16210
16109
  const sheetLike = (0, _univerjs_docs.isSheetLikeDocsCustomBlockChildType)(params.childType);
16211
- const contentHeight = Number.isFinite(params.contentHeight) && ((_params$contentHeight = params.contentHeight) !== null && _params$contentHeight !== void 0 ? _params$contentHeight : 0) > 0 ? params.contentHeight : fallbackHeight;
16212
- const visibleCanvasHeight = Number.isFinite(params.visibleCanvasHeight) && ((_params$visibleCanvas = params.visibleCanvasHeight) !== null && _params$visibleCanvas !== void 0 ? _params$visibleCanvas : 0) > 0 ? params.visibleCanvasHeight : void 0;
16110
+ const contentHeight = Number.isFinite(params.contentHeight) && (params.contentHeight ?? 0) > 0 ? params.contentHeight : fallbackHeight;
16111
+ const visibleCanvasHeight = Number.isFinite(params.visibleCanvasHeight) && (params.visibleCanvasHeight ?? 0) > 0 ? params.visibleCanvasHeight : void 0;
16213
16112
  const height = sheetLike ? contentHeight : fallbackHeight;
16214
16113
  const viewportHeight = sheetLike && visibleCanvasHeight != null ? Math.min(contentHeight, visibleCanvasHeight) : height;
16114
+ const viewScale = params.scale && params.scale > 0 ? params.scale : 1;
16215
16115
  if (!sheetLike) return {
16216
16116
  height,
16217
16117
  width: fallbackWidth
16218
16118
  };
16219
16119
  const pageWidth = params.pageWidth;
16220
- const pageMarginLeft = (_params$pageMarginLef = params.pageMarginLeft) !== null && _params$pageMarginLef !== void 0 ? _params$pageMarginLef : 0;
16221
- const pageMarginRight = (_params$pageMarginRig = params.pageMarginRight) !== null && _params$pageMarginRig !== void 0 ? _params$pageMarginRig : 0;
16120
+ const pageMarginLeft = params.pageMarginLeft ?? 0;
16121
+ const pageMarginRight = params.pageMarginRight ?? 0;
16222
16122
  const pageContentWidth = Number.isFinite(pageWidth) ? Math.max(0, pageWidth - pageMarginLeft - pageMarginRight) : fallbackWidth;
16223
- const contentWidth = Number.isFinite(params.contentWidth) && ((_params$contentWidth = params.contentWidth) !== null && _params$contentWidth !== void 0 ? _params$contentWidth : 0) > 0 ? params.contentWidth : fallbackWidth;
16123
+ const contentWidth = Number.isFinite(params.contentWidth) && (params.contentWidth ?? 0) > 0 ? params.contentWidth : fallbackWidth;
16224
16124
  if (params.documentFlavor !== _univerjs_core.DocumentFlavor.MODERN || !Number.isFinite(pageWidth)) {
16225
16125
  const layoutWidth = Math.min(contentWidth, pageContentWidth || contentWidth);
16226
16126
  return {
@@ -16229,16 +16129,17 @@ function resolveDocsCustomBlockRenderViewport(params) {
16229
16129
  height,
16230
16130
  layoutWidth,
16231
16131
  offsetLeft: 0,
16132
+ pageContentWidth,
16133
+ viewScale,
16232
16134
  viewportHeight,
16233
16135
  width: layoutWidth
16234
16136
  };
16235
16137
  }
16236
- const scale = params.scale && params.scale > 0 ? params.scale : 1;
16237
- const inset = MODERN_DOCS_CUSTOM_BLOCK_VIEWPORT_INSET / scale;
16238
- const docsLeft = (_params$docsLeft = params.docsLeft) !== null && _params$docsLeft !== void 0 ? _params$docsLeft : 0;
16138
+ const inset = MODERN_DOCS_CUSTOM_BLOCK_VIEWPORT_INSET / viewScale;
16139
+ const docsLeft = params.docsLeft ?? 0;
16239
16140
  const fallbackViewportLeft = docsLeft + inset;
16240
16141
  const fallbackViewportWidth = Math.max(0, pageWidth - inset * 2);
16241
- const hasVisibleCanvas = Number.isFinite(params.visibleCanvasLeft) && Number.isFinite(params.visibleCanvasWidth) && ((_params$visibleCanvas2 = params.visibleCanvasWidth) !== null && _params$visibleCanvas2 !== void 0 ? _params$visibleCanvas2 : 0) > 0;
16142
+ const hasVisibleCanvas = Number.isFinite(params.visibleCanvasLeft) && Number.isFinite(params.visibleCanvasWidth) && (params.visibleCanvasWidth ?? 0) > 0;
16242
16143
  const viewportLeft = hasVisibleCanvas ? params.visibleCanvasLeft + inset : fallbackViewportLeft;
16243
16144
  const viewportWidth = hasVisibleCanvas ? Math.max(0, params.visibleCanvasWidth - inset * 2) : fallbackViewportWidth;
16244
16145
  const paragraphTextStart = docsLeft + pageMarginLeft;
@@ -16252,6 +16153,8 @@ function resolveDocsCustomBlockRenderViewport(params) {
16252
16153
  height,
16253
16154
  layoutWidth,
16254
16155
  offsetLeft: 0,
16156
+ pageContentWidth,
16157
+ viewScale,
16255
16158
  viewportHeight,
16256
16159
  width: layoutWidth
16257
16160
  };
@@ -16260,7 +16163,7 @@ function resolveDocsCustomBlockRenderViewport(params) {
16260
16163
  //#endregion
16261
16164
  //#region package.json
16262
16165
  var name = "@univerjs/docs-ui";
16263
- var version = "1.0.0-alpha.8";
16166
+ var version = "1.0.0-beta.0";
16264
16167
 
16265
16168
  //#endregion
16266
16169
  //#region src/commands/commands/doc-paragraph-setting.command.ts
@@ -16268,7 +16171,6 @@ const DocParagraphSettingCommand = {
16268
16171
  id: "doc-paragraph-setting.command",
16269
16172
  type: _univerjs_core.CommandType.COMMAND,
16270
16173
  handler: async (accessor, config) => {
16271
- var _segmentBody$paragrap, _segmentBody$dataStre, _BuildTextUtils$range;
16272
16174
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
16273
16175
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
16274
16176
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -16279,9 +16181,9 @@ const DocParagraphSettingCommand = {
16279
16181
  const unitId = docDataModel.getUnitId();
16280
16182
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
16281
16183
  const segmentBody = segment === null || segment === void 0 ? void 0 : segment.getBody();
16282
- const allParagraphs = (_segmentBody$paragrap = segmentBody === null || segmentBody === void 0 ? void 0 : segmentBody.paragraphs) !== null && _segmentBody$paragrap !== void 0 ? _segmentBody$paragrap : [];
16283
- const dataStream = (_segmentBody$dataStre = segmentBody === null || segmentBody === void 0 ? void 0 : segmentBody.dataStream) !== null && _segmentBody$dataStre !== void 0 ? _segmentBody$dataStre : "";
16284
- const paragraphs = (_BuildTextUtils$range = _univerjs_core.BuildTextUtils.range.getParagraphsInRanges(docRanges, allParagraphs, dataStream)) !== null && _BuildTextUtils$range !== void 0 ? _BuildTextUtils$range : [];
16184
+ const allParagraphs = (segmentBody === null || segmentBody === void 0 ? void 0 : segmentBody.paragraphs) ?? [];
16185
+ const dataStream = (segmentBody === null || segmentBody === void 0 ? void 0 : segmentBody.dataStream) ?? "";
16186
+ const paragraphs = _univerjs_core.BuildTextUtils.range.getParagraphsInRanges(docRanges, allParagraphs, dataStream) ?? [];
16285
16187
  const doMutation = {
16286
16188
  id: _univerjs_docs.RichTextEditingMutation.id,
16287
16189
  params: {
@@ -16431,16 +16333,15 @@ function getSegmentId(documentStyle, editArea, pageIndex, page) {
16431
16333
  else return evenAndOddHeaders === _univerjs_core.BooleanNumber.TRUE && isEvenPage ? evenPageFooterId : defaultFooterId;
16432
16334
  }
16433
16335
  const DocHeaderFooterOptions = (props) => {
16434
- var _segmentContext$segme, _segmentContext$segme2;
16435
16336
  const docSelectionRenderService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService).getRenderUnitById(props.unitId).with(DocSelectionRenderService);
16436
16337
  const segmentContext = (0, _univerjs_ui.useObservable)(docSelectionRenderService.segmentContext$, {
16437
16338
  segmentId: docSelectionRenderService.getSegment(),
16438
16339
  segmentPage: docSelectionRenderService.getSegmentPage()
16439
16340
  });
16440
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocHeaderFooterOptionsContent, { ...props }, `${(_segmentContext$segme = segmentContext === null || segmentContext === void 0 ? void 0 : segmentContext.segmentId) !== null && _segmentContext$segme !== void 0 ? _segmentContext$segme : ""}:${(_segmentContext$segme2 = segmentContext === null || segmentContext === void 0 ? void 0 : segmentContext.segmentPage) !== null && _segmentContext$segme2 !== void 0 ? _segmentContext$segme2 : -1}`);
16341
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocHeaderFooterOptionsContent, { ...props }, `${(segmentContext === null || segmentContext === void 0 ? void 0 : segmentContext.segmentId) ?? ""}:${(segmentContext === null || segmentContext === void 0 ? void 0 : segmentContext.segmentPage) ?? -1}`);
16441
16342
  };
16442
16343
  function DocHeaderFooterOptionsContent(props) {
16443
- var _renderManagerService2, _sectionContext$confi, _sectionContext$secti, _sectionContext$secti2;
16344
+ var _renderManagerService2, _sectionContext$secti;
16444
16345
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
16445
16346
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
16446
16347
  const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
@@ -16460,19 +16361,19 @@ function DocHeaderFooterOptionsContent(props) {
16460
16361
  };
16461
16362
  };
16462
16363
  const [options, setOptions] = (0, react.useState)(() => {
16463
- var _getCurrentSectionCon, _config$marginHeader, _config$marginFooter, _config$useFirstPageH, _config$evenAndOddHea;
16364
+ var _getCurrentSectionCon;
16464
16365
  const config = (_getCurrentSectionCon = getCurrentSectionContext()) === null || _getCurrentSectionCon === void 0 ? void 0 : _getCurrentSectionCon.config;
16465
16366
  return {
16466
- marginHeader: (_config$marginHeader = config === null || config === void 0 ? void 0 : config.marginHeader) !== null && _config$marginHeader !== void 0 ? _config$marginHeader : 0,
16467
- marginFooter: (_config$marginFooter = config === null || config === void 0 ? void 0 : config.marginFooter) !== null && _config$marginFooter !== void 0 ? _config$marginFooter : 0,
16468
- useFirstPageHeaderFooter: (_config$useFirstPageH = config === null || config === void 0 ? void 0 : config.useFirstPageHeaderFooter) !== null && _config$useFirstPageH !== void 0 ? _config$useFirstPageH : _univerjs_core.BooleanNumber.FALSE,
16469
- evenAndOddHeaders: (_config$evenAndOddHea = config === null || config === void 0 ? void 0 : config.evenAndOddHeaders) !== null && _config$evenAndOddHea !== void 0 ? _config$evenAndOddHea : _univerjs_core.BooleanNumber.FALSE
16367
+ marginHeader: (config === null || config === void 0 ? void 0 : config.marginHeader) ?? 0,
16368
+ marginFooter: (config === null || config === void 0 ? void 0 : config.marginFooter) ?? 0,
16369
+ useFirstPageHeaderFooter: (config === null || config === void 0 ? void 0 : config.useFirstPageHeaderFooter) ?? _univerjs_core.BooleanNumber.FALSE,
16370
+ evenAndOddHeaders: (config === null || config === void 0 ? void 0 : config.evenAndOddHeaders) ?? _univerjs_core.BooleanNumber.FALSE
16470
16371
  };
16471
16372
  });
16472
16373
  const sectionContext = getCurrentSectionContext();
16473
- const referenceKey = (0, _univerjs_core.getSectionHeaderFooterReferenceKey)(((_renderManagerService2 = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService2 === void 0 || (_renderManagerService2 = _renderManagerService2.with(_univerjs_docs.DocSkeletonManagerService)) === null || _renderManagerService2 === void 0 || (_renderManagerService2 = _renderManagerService2.getViewModel()) === null || _renderManagerService2 === void 0 ? void 0 : _renderManagerService2.getEditArea()) === _univerjs_engine_render.DocumentEditArea.FOOTER ? "footer" : "header", getHeaderFooterVariant((_sectionContext$confi = sectionContext === null || sectionContext === void 0 ? void 0 : sectionContext.config) !== null && _sectionContext$confi !== void 0 ? _sectionContext$confi : {}, docSelectionRenderService.getSegmentPage(), sectionContext === null || sectionContext === void 0 ? void 0 : sectionContext.page));
16474
- const canLinkToPrevious = ((_sectionContext$secti = sectionContext === null || sectionContext === void 0 ? void 0 : sectionContext.sectionIndex) !== null && _sectionContext$secti !== void 0 ? _sectionContext$secti : -1) > 0;
16475
- const [linkedToPrevious, setLinkedToPrevious] = (0, react.useState)(canLinkToPrevious && !(sectionContext === null || sectionContext === void 0 || (_sectionContext$secti2 = sectionContext.section) === null || _sectionContext$secti2 === void 0 ? void 0 : _sectionContext$secti2[referenceKey]));
16374
+ const referenceKey = (0, _univerjs_core.getSectionHeaderFooterReferenceKey)(((_renderManagerService2 = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService2 === void 0 || (_renderManagerService2 = _renderManagerService2.with(_univerjs_docs.DocSkeletonManagerService)) === null || _renderManagerService2 === void 0 || (_renderManagerService2 = _renderManagerService2.getViewModel()) === null || _renderManagerService2 === void 0 ? void 0 : _renderManagerService2.getEditArea()) === _univerjs_engine_render.DocumentEditArea.FOOTER ? "footer" : "header", getHeaderFooterVariant((sectionContext === null || sectionContext === void 0 ? void 0 : sectionContext.config) ?? {}, docSelectionRenderService.getSegmentPage(), sectionContext === null || sectionContext === void 0 ? void 0 : sectionContext.page));
16375
+ const canLinkToPrevious = ((sectionContext === null || sectionContext === void 0 ? void 0 : sectionContext.sectionIndex) ?? -1) > 0;
16376
+ const [linkedToPrevious, setLinkedToPrevious] = (0, react.useState)(canLinkToPrevious && !(sectionContext === null || sectionContext === void 0 || (_sectionContext$secti = sectionContext.section) === null || _sectionContext$secti === void 0 ? void 0 : _sectionContext$secti[referenceKey]));
16476
16377
  const handleCheckboxChange = (val, type) => {
16477
16378
  var _renderManagerService3;
16478
16379
  setOptions((prev) => ({
@@ -16560,7 +16461,7 @@ function DocHeaderFooterOptionsContent(props) {
16560
16461
  ...linked ? {} : { segmentId }
16561
16462
  })) return;
16562
16463
  setLinkedToPrevious(linked);
16563
- docSelectionRenderService.setSegment(linked ? previousSegmentId !== null && previousSegmentId !== void 0 ? previousSegmentId : "" : segmentId);
16464
+ docSelectionRenderService.setSegment(linked ? previousSegmentId ?? "" : segmentId);
16564
16465
  layoutService.focus();
16565
16466
  };
16566
16467
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -16702,21 +16603,22 @@ function TextColorSwatchIcon({ className, style, onClick, color }) {
16702
16603
  "aria-hidden": "true",
16703
16604
  onClick,
16704
16605
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
16705
- x: 3,
16706
- y: 3,
16707
- width: 18,
16708
- height: 18,
16709
- rx: 4,
16606
+ x: 1,
16607
+ y: 1,
16608
+ width: 22,
16609
+ height: 22,
16610
+ rx: 2.5,
16710
16611
  fill: "none",
16711
16612
  stroke: "currentColor",
16712
- strokeOpacity: .16
16613
+ strokeWidth: 1,
16614
+ strokeOpacity: .12
16713
16615
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("text", {
16714
16616
  x: 12,
16715
- y: 16.5,
16617
+ y: 17.25,
16716
16618
  direction: "ltr",
16717
16619
  fontFamily: "Arial, sans-serif",
16718
- fontSize: 12,
16719
- fontWeight: 700,
16620
+ fontSize: 15,
16621
+ fontWeight: 400,
16720
16622
  fill: color,
16721
16623
  textAnchor: "middle",
16722
16624
  children: "A"
@@ -16738,7 +16640,7 @@ function BackgroundColorSwatchIcon({ className, style, onClick, color }) {
16738
16640
  y: 3,
16739
16641
  width: 18,
16740
16642
  height: 18,
16741
- rx: 5,
16643
+ rx: 3,
16742
16644
  fill: color,
16743
16645
  stroke: "currentColor",
16744
16646
  strokeOpacity: .12
@@ -16746,12 +16648,11 @@ function BackgroundColorSwatchIcon({ className, style, onClick, color }) {
16746
16648
  });
16747
16649
  }
16748
16650
  function HeaderTextColorIcon({ className, style, onClick, extend }) {
16749
- var _extend$colorChannel;
16750
16651
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextColorSwatchIcon, {
16751
16652
  className,
16752
16653
  style,
16753
16654
  onClick,
16754
- color: (_extend$colorChannel = extend === null || extend === void 0 ? void 0 : extend.colorChannel1) !== null && _extend$colorChannel !== void 0 ? _extend$colorChannel : "currentColor"
16655
+ color: (extend === null || extend === void 0 ? void 0 : extend.colorChannel1) ?? "currentColor"
16755
16656
  });
16756
16657
  }
16757
16658
  function DefaultTextColorIcon({ className, style, onClick }) {
@@ -16866,19 +16767,15 @@ function convertDisplayLineSpacingToStoredValue(lineSpacing, spacingRule) {
16866
16767
  return spacingRule === _univerjs_core.SpacingRule.AUTO ? lineSpacing : round(lineSpacing, 4);
16867
16768
  }
16868
16769
  function getLineSpacingMetrics(lineNode) {
16869
- var _lineNode$divides, _lineNode$paddingTop, _lineNode$contentHeig, _lineNode$paddingBott;
16870
16770
  if (!lineNode) return null;
16871
- const glyphLineHeight = Math.max(0, ...((_lineNode$divides = lineNode.divides) !== null && _lineNode$divides !== void 0 ? _lineNode$divides : []).flatMap((divide) => {
16872
- var _divide$glyphGroup;
16873
- return ((_divide$glyphGroup = divide.glyphGroup) !== null && _divide$glyphGroup !== void 0 ? _divide$glyphGroup : []).map((glyph) => {
16874
- var _glyph$bBox$ba, _glyph$bBox, _glyph$bBox$bd, _glyph$bBox2;
16875
- return ((_glyph$bBox$ba = (_glyph$bBox = glyph.bBox) === null || _glyph$bBox === void 0 ? void 0 : _glyph$bBox.ba) !== null && _glyph$bBox$ba !== void 0 ? _glyph$bBox$ba : 0) + ((_glyph$bBox$bd = (_glyph$bBox2 = glyph.bBox) === null || _glyph$bBox2 === void 0 ? void 0 : _glyph$bBox2.bd) !== null && _glyph$bBox$bd !== void 0 ? _glyph$bBox$bd : 0);
16876
- });
16877
- })) || lineNode.contentHeight || 0;
16771
+ const glyphLineHeight = Math.max(0, ...(lineNode.divides ?? []).flatMap((divide) => (divide.glyphGroup ?? []).map((glyph) => {
16772
+ var _glyph$bBox, _glyph$bBox2;
16773
+ return (((_glyph$bBox = glyph.bBox) === null || _glyph$bBox === void 0 ? void 0 : _glyph$bBox.ba) ?? 0) + (((_glyph$bBox2 = glyph.bBox) === null || _glyph$bBox2 === void 0 ? void 0 : _glyph$bBox2.bd) ?? 0);
16774
+ }))) || lineNode.contentHeight || 0;
16878
16775
  if (!glyphLineHeight) return null;
16879
16776
  return {
16880
16777
  glyphLineHeight,
16881
- renderedLineHeight: ((_lineNode$paddingTop = lineNode.paddingTop) !== null && _lineNode$paddingTop !== void 0 ? _lineNode$paddingTop : 0) + ((_lineNode$contentHeig = lineNode.contentHeight) !== null && _lineNode$contentHeig !== void 0 ? _lineNode$contentHeig : glyphLineHeight) + ((_lineNode$paddingBott = lineNode.paddingBottom) !== null && _lineNode$paddingBott !== void 0 ? _lineNode$paddingBott : 0) || glyphLineHeight
16778
+ renderedLineHeight: (lineNode.paddingTop ?? 0) + (lineNode.contentHeight ?? glyphLineHeight) + (lineNode.paddingBottom ?? 0) || glyphLineHeight
16882
16779
  };
16883
16780
  }
16884
16781
  function convertLineSpacingForRuleChange(currentStoredValue, currentRule, nextRule, metrics) {
@@ -16900,8 +16797,8 @@ const PARAGRAPH_LAYOUT_BLOCK_TYPES = /* @__PURE__ */ new Set([
16900
16797
  ]);
16901
16798
  function resolveParagraphsForSettingPanel(paragraphs, body, documentStyle) {
16902
16799
  return paragraphs.map((paragraph) => {
16903
- var _body$blockRanges$som, _body$blockRanges;
16904
- const hasLayoutBlockRange = (_body$blockRanges$som = (_body$blockRanges = body.blockRanges) === null || _body$blockRanges === void 0 ? void 0 : _body$blockRanges.some((range) => PARAGRAPH_LAYOUT_BLOCK_TYPES.has(range.blockType) && paragraph.startIndex > range.startIndex && paragraph.startIndex < range.endIndex)) !== null && _body$blockRanges$som !== void 0 ? _body$blockRanges$som : false;
16800
+ var _body$blockRanges;
16801
+ const hasLayoutBlockRange = ((_body$blockRanges = body.blockRanges) === null || _body$blockRanges === void 0 ? void 0 : _body$blockRanges.some((range) => PARAGRAPH_LAYOUT_BLOCK_TYPES.has(range.blockType) && paragraph.startIndex > range.startIndex && paragraph.startIndex < range.endIndex)) ?? false;
16905
16802
  return {
16906
16803
  ...paragraph,
16907
16804
  paragraphStyle: (0, _univerjs_core.resolveDocumentParagraphStyle)(documentStyle, paragraph.paragraphStyle, { excludeDocumentOuterSpacing: hasLayoutBlockRange })
@@ -16918,25 +16815,24 @@ const useDocRanges = () => {
16918
16815
  return docRanges;
16919
16816
  };
16920
16817
  const useCurrentParagraph = () => {
16921
- var _body$paragraphs, _body$dataStream, _BuildTextUtils$range;
16922
16818
  const docDataModel = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
16923
16819
  const docRanges = useDocRanges();
16924
16820
  if (!docDataModel || docRanges.length === 0) return [];
16925
16821
  const segmentId = docRanges[0].segmentId;
16926
16822
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
16927
16823
  const body = segment === null || segment === void 0 ? void 0 : segment.getBody();
16928
- const paragraphs = (_body$paragraphs = body === null || body === void 0 ? void 0 : body.paragraphs) !== null && _body$paragraphs !== void 0 ? _body$paragraphs : [];
16929
- const dataStream = (_body$dataStream = body === null || body === void 0 ? void 0 : body.dataStream) !== null && _body$dataStream !== void 0 ? _body$dataStream : "";
16930
- const currentParagraphs = (_BuildTextUtils$range = _univerjs_core.BuildTextUtils.range.getParagraphsInRanges(docRanges, paragraphs, dataStream)) !== null && _BuildTextUtils$range !== void 0 ? _BuildTextUtils$range : [];
16824
+ const paragraphs = (body === null || body === void 0 ? void 0 : body.paragraphs) ?? [];
16825
+ const dataStream = (body === null || body === void 0 ? void 0 : body.dataStream) ?? "";
16826
+ const currentParagraphs = _univerjs_core.BuildTextUtils.range.getParagraphsInRanges(docRanges, paragraphs, dataStream) ?? [];
16931
16827
  return body == null ? currentParagraphs : resolveParagraphsForSettingPanel(currentParagraphs, body, docDataModel.getDocumentStyle());
16932
16828
  };
16933
16829
  const useFirstParagraphHorizontalAlign = (paragraph, defaultValue) => {
16934
16830
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
16935
16831
  const [horizontalAlign, setHorizontalAlignSetInternal] = (0, react.useState)(() => {
16936
- var _firstParagraph$parag, _firstParagraph$parag2;
16832
+ var _firstParagraph$parag;
16937
16833
  const firstParagraph = paragraph[0];
16938
16834
  if (!firstParagraph) return defaultValue;
16939
- return String((_firstParagraph$parag = (_firstParagraph$parag2 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag2 === void 0 ? void 0 : _firstParagraph$parag2.horizontalAlign) !== null && _firstParagraph$parag !== void 0 ? _firstParagraph$parag : defaultValue);
16835
+ return String(((_firstParagraph$parag = firstParagraph.paragraphStyle) === null || _firstParagraph$parag === void 0 ? void 0 : _firstParagraph$parag.horizontalAlign) ?? defaultValue);
16940
16836
  });
16941
16837
  const sethorizontalAlign = (v) => {
16942
16838
  setHorizontalAlignSetInternal(v);
@@ -16947,10 +16843,10 @@ const useFirstParagraphHorizontalAlign = (paragraph, defaultValue) => {
16947
16843
  const useFirstParagraphIndentStart = (paragraph) => {
16948
16844
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
16949
16845
  const [indentStart, setIndentStartInternal] = (0, react.useState)(() => {
16950
- var _firstParagraph$parag3;
16846
+ var _firstParagraph$parag2;
16951
16847
  const firstParagraph = paragraph[0];
16952
16848
  if (!firstParagraph) return 0;
16953
- return (0, _univerjs_engine_render.getNumberUnitValue)((_firstParagraph$parag3 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag3 === void 0 ? void 0 : _firstParagraph$parag3.indentStart, 0);
16849
+ return (0, _univerjs_engine_render.getNumberUnitValue)((_firstParagraph$parag2 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag2 === void 0 ? void 0 : _firstParagraph$parag2.indentStart, 0);
16954
16850
  });
16955
16851
  const setIndentStart = (v) => {
16956
16852
  setIndentStartInternal(v);
@@ -16961,10 +16857,10 @@ const useFirstParagraphIndentStart = (paragraph) => {
16961
16857
  const useFirstParagraphIndentEnd = (paragraph) => {
16962
16858
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
16963
16859
  const [indentEnd, setIndentEndInternal] = (0, react.useState)(() => {
16964
- var _firstParagraph$parag4;
16860
+ var _firstParagraph$parag3;
16965
16861
  const firstParagraph = paragraph[0];
16966
16862
  if (!firstParagraph) return 0;
16967
- return (0, _univerjs_engine_render.getNumberUnitValue)((_firstParagraph$parag4 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag4 === void 0 ? void 0 : _firstParagraph$parag4.indentEnd, 0);
16863
+ return (0, _univerjs_engine_render.getNumberUnitValue)((_firstParagraph$parag3 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag3 === void 0 ? void 0 : _firstParagraph$parag3.indentEnd, 0);
16968
16864
  });
16969
16865
  const setIndentEnd = (v) => {
16970
16866
  setIndentEndInternal(v);
@@ -16975,10 +16871,10 @@ const useFirstParagraphIndentEnd = (paragraph) => {
16975
16871
  const useFirstParagraphIndentFirstLine = (paragraph) => {
16976
16872
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
16977
16873
  const [indentFirstLine, setIndentFirstLineInternal] = (0, react.useState)(() => {
16978
- var _firstParagraph$parag5;
16874
+ var _firstParagraph$parag4;
16979
16875
  const firstParagraph = paragraph[0];
16980
16876
  if (!firstParagraph) return 0;
16981
- return (0, _univerjs_engine_render.getNumberUnitValue)((_firstParagraph$parag5 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag5 === void 0 ? void 0 : _firstParagraph$parag5.indentFirstLine, 0);
16877
+ return (0, _univerjs_engine_render.getNumberUnitValue)((_firstParagraph$parag4 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag4 === void 0 ? void 0 : _firstParagraph$parag4.indentFirstLine, 0);
16982
16878
  });
16983
16879
  const setIndentFirstLine = (v) => {
16984
16880
  setIndentFirstLineInternal(v);
@@ -16989,10 +16885,10 @@ const useFirstParagraphIndentFirstLine = (paragraph) => {
16989
16885
  const useFirstParagraphIndentHanging = (paragraph) => {
16990
16886
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
16991
16887
  const [hanging, setHangingInternal] = (0, react.useState)(() => {
16992
- var _firstParagraph$parag6;
16888
+ var _firstParagraph$parag5;
16993
16889
  const firstParagraph = paragraph[0];
16994
16890
  if (!firstParagraph) return 0;
16995
- return (0, _univerjs_engine_render.getNumberUnitValue)((_firstParagraph$parag6 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag6 === void 0 ? void 0 : _firstParagraph$parag6.hanging, 0);
16891
+ return (0, _univerjs_engine_render.getNumberUnitValue)((_firstParagraph$parag5 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag5 === void 0 ? void 0 : _firstParagraph$parag5.hanging, 0);
16996
16892
  });
16997
16893
  const setHanging = (v) => {
16998
16894
  setHangingInternal(v);
@@ -17003,10 +16899,10 @@ const useFirstParagraphIndentHanging = (paragraph) => {
17003
16899
  const useFirstParagraphIndentSpaceAbove = (paragraph) => {
17004
16900
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
17005
16901
  const [spaceAbove, setSpaceAboveInternal] = (0, react.useState)(() => {
17006
- var _firstParagraph$parag7;
16902
+ var _firstParagraph$parag6;
17007
16903
  const firstParagraph = paragraph[0];
17008
16904
  if (!firstParagraph) return 0;
17009
- return (0, _univerjs_engine_render.getNumberUnitValue)((_firstParagraph$parag7 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag7 === void 0 ? void 0 : _firstParagraph$parag7.spaceAbove, _univerjs_core.DEFAULT_DOCUMENT_PARAGRAPH_SPACE_ABOVE);
16905
+ return (0, _univerjs_engine_render.getNumberUnitValue)((_firstParagraph$parag6 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag6 === void 0 ? void 0 : _firstParagraph$parag6.spaceAbove, _univerjs_core.DEFAULT_DOCUMENT_PARAGRAPH_SPACE_ABOVE);
17010
16906
  });
17011
16907
  const setSpaceAbove = (v) => {
17012
16908
  setSpaceAboveInternal(v);
@@ -17017,10 +16913,10 @@ const useFirstParagraphIndentSpaceAbove = (paragraph) => {
17017
16913
  const useFirstParagraphSpaceBelow = (paragraph) => {
17018
16914
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
17019
16915
  const [spaceBelow, setSpaceBelowInternal] = (0, react.useState)(() => {
17020
- var _firstParagraph$parag8;
16916
+ var _firstParagraph$parag7;
17021
16917
  const firstParagraph = paragraph[0];
17022
16918
  if (!firstParagraph) return 0;
17023
- return (0, _univerjs_engine_render.getNumberUnitValue)((_firstParagraph$parag8 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag8 === void 0 ? void 0 : _firstParagraph$parag8.spaceBelow, _univerjs_core.DEFAULT_DOCUMENT_PARAGRAPH_SPACE_BELOW);
16919
+ return (0, _univerjs_engine_render.getNumberUnitValue)((_firstParagraph$parag7 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag7 === void 0 ? void 0 : _firstParagraph$parag7.spaceBelow, _univerjs_core.DEFAULT_DOCUMENT_PARAGRAPH_SPACE_BELOW);
17024
16920
  });
17025
16921
  const setSpaceBelow = (v) => {
17026
16922
  setSpaceBelowInternal(v);
@@ -17040,17 +16936,17 @@ const useFirstParagraphLineSpacing = (paragraph) => {
17040
16936
  }, []);
17041
16937
  const stateChange$ = (0, react.useMemo)(() => new rxjs.BehaviorSubject({}), []);
17042
16938
  const [spacingRule, setSpacingRuleInternal] = (0, react.useState)(() => {
17043
- var _firstParagraph$parag9, _firstParagraph$parag10;
16939
+ var _firstParagraph$parag8;
17044
16940
  const firstParagraph = paragraph[0];
17045
16941
  if (!firstParagraph) return _univerjs_core.SpacingRule.AUTO;
17046
- return (_firstParagraph$parag9 = (_firstParagraph$parag10 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag10 === void 0 ? void 0 : _firstParagraph$parag10.spacingRule) !== null && _firstParagraph$parag9 !== void 0 ? _firstParagraph$parag9 : _univerjs_core.SpacingRule.AUTO;
16942
+ return ((_firstParagraph$parag8 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag8 === void 0 ? void 0 : _firstParagraph$parag8.spacingRule) ?? _univerjs_core.SpacingRule.AUTO;
17047
16943
  });
17048
16944
  const [lineSpacing, setLineSpacingInternal] = (0, react.useState)(() => {
17049
- var _firstParagraph$parag11, _firstParagraph$parag12, _firstParagraph$parag13, _firstParagraph$parag14;
16945
+ var _firstParagraph$parag9, _firstParagraph$parag10;
17050
16946
  const firstParagraph = paragraph[0];
17051
16947
  if (!firstParagraph) return _univerjs_core.DEFAULT_DOCUMENT_PARAGRAPH_LINE_SPACING;
17052
- const currentSpacingRule = (_firstParagraph$parag11 = (_firstParagraph$parag12 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag12 === void 0 ? void 0 : _firstParagraph$parag12.spacingRule) !== null && _firstParagraph$parag11 !== void 0 ? _firstParagraph$parag11 : _univerjs_core.SpacingRule.AUTO;
17053
- return convertStoredLineSpacingToDisplayValue((_firstParagraph$parag13 = (_firstParagraph$parag14 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag14 === void 0 ? void 0 : _firstParagraph$parag14.lineSpacing) !== null && _firstParagraph$parag13 !== void 0 ? _firstParagraph$parag13 : _univerjs_core.DEFAULT_DOCUMENT_PARAGRAPH_LINE_SPACING, currentSpacingRule);
16948
+ const currentSpacingRule = ((_firstParagraph$parag9 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag9 === void 0 ? void 0 : _firstParagraph$parag9.spacingRule) ?? _univerjs_core.SpacingRule.AUTO;
16949
+ return convertStoredLineSpacingToDisplayValue(((_firstParagraph$parag10 = firstParagraph.paragraphStyle) === null || _firstParagraph$parag10 === void 0 ? void 0 : _firstParagraph$parag10.lineSpacing) ?? _univerjs_core.DEFAULT_DOCUMENT_PARAGRAPH_LINE_SPACING, currentSpacingRule);
17054
16950
  });
17055
16951
  const setLineSpacing = async (v) => {
17056
16952
  setLineSpacingInternal(v);
@@ -17118,13 +17014,12 @@ const ALIGNMENT_OPTIONS = [
17118
17014
  }
17119
17015
  ];
17120
17016
  const ParagraphSettingSection = (props) => {
17121
- const { titleKey, children, first = false } = props;
17122
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
17017
+ const { title, children, first = false } = props;
17123
17018
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
17124
17019
  className: (0, _univerjs_design.clsx)(!first && "univer-mt-5"),
17125
17020
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
17126
17021
  className: "univer-text-sm univer-font-medium univer-leading-5",
17127
- children: localeService.t(titleKey)
17022
+ children: title
17128
17023
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
17129
17024
  className: "univer-mt-3",
17130
17025
  children
@@ -17132,13 +17027,13 @@ const ParagraphSettingSection = (props) => {
17132
17027
  });
17133
17028
  };
17134
17029
  const ParagraphSettingRow = (props) => {
17135
- const { labelKey, unit, children } = props;
17030
+ const { label, unit, children } = props;
17136
17031
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
17137
17032
  className: "univer-grid univer-min-h-8 univer-items-center univer-gap-3",
17138
17033
  style: { gridTemplateColumns: "minmax(0, 1fr) minmax(160px, 180px)" },
17139
17034
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
17140
17035
  className: "univer-min-w-0 univer-text-xs univer-leading-5 univer-text-gray-900 dark:!univer-text-gray-100",
17141
- children: [(0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService).t(labelKey), unit]
17036
+ children: [label, unit]
17142
17037
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
17143
17038
  className: "univer-w-full univer-min-w-0",
17144
17039
  children
@@ -17156,7 +17051,7 @@ const AutoFocusInputNumber = (props) => {
17156
17051
  max,
17157
17052
  value,
17158
17053
  onChange: (v) => {
17159
- onChange(v !== null && v !== void 0 ? v : 0).finally(() => {
17054
+ onChange(v ?? 0).finally(() => {
17160
17055
  setTimeout(() => {
17161
17056
  var _ref$current;
17162
17057
  (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.focus();
@@ -17186,7 +17081,7 @@ function ParagraphSetting() {
17186
17081
  className: "univer-box-border univer-w-full",
17187
17082
  children: [
17188
17083
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ParagraphSettingSection, {
17189
- titleKey: "docs-ui.doc.paragraphSetting.alignment",
17084
+ title: localeService.t("docs-ui.doc.paragraphSetting.alignment"),
17190
17085
  first: true,
17191
17086
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
17192
17087
  className: (0, _univerjs_design.clsx)("univer-flex univer-grid-cols-4 univer-items-center univer-justify-around univer-gap-2 univer-rounded-lg univer-bg-white univer-p-1 dark:!univer-bg-gray-900", _univerjs_design.borderClassName),
@@ -17212,68 +17107,68 @@ function ParagraphSetting() {
17212
17107
  })
17213
17108
  }),
17214
17109
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ParagraphSettingSection, {
17215
- titleKey: "docs-ui.doc.paragraphSetting.indentation",
17110
+ title: localeService.t("docs-ui.doc.paragraphSetting.indentation"),
17216
17111
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
17217
17112
  className: "univer-grid univer-gap-3",
17218
17113
  children: [
17219
17114
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ParagraphSettingRow, {
17220
- labelKey: "docs-ui.doc.paragraphSetting.left",
17115
+ label: localeService.t("docs-ui.doc.paragraphSetting.left"),
17221
17116
  unit: "(px)",
17222
17117
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoFocusInputNumber, {
17223
17118
  value: indentStart,
17224
- onChange: (v) => setIndentStart(v !== null && v !== void 0 ? v : 0)
17119
+ onChange: (v) => setIndentStart(v ?? 0)
17225
17120
  })
17226
17121
  }),
17227
17122
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ParagraphSettingRow, {
17228
- labelKey: "docs-ui.doc.paragraphSetting.right",
17123
+ label: localeService.t("docs-ui.doc.paragraphSetting.right"),
17229
17124
  unit: "(px)",
17230
17125
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoFocusInputNumber, {
17231
17126
  value: indentEnd,
17232
- onChange: (v) => setIndentEnd(v !== null && v !== void 0 ? v : 0)
17127
+ onChange: (v) => setIndentEnd(v ?? 0)
17233
17128
  })
17234
17129
  }),
17235
17130
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ParagraphSettingRow, {
17236
- labelKey: "docs-ui.doc.paragraphSetting.firstLine",
17131
+ label: localeService.t("docs-ui.doc.paragraphSetting.firstLine"),
17237
17132
  unit: "(px)",
17238
17133
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoFocusInputNumber, {
17239
17134
  value: indentFirstLine,
17240
- onChange: (v) => setIndentFirstLine(v !== null && v !== void 0 ? v : 0)
17135
+ onChange: (v) => setIndentFirstLine(v ?? 0)
17241
17136
  })
17242
17137
  }),
17243
17138
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ParagraphSettingRow, {
17244
- labelKey: "docs-ui.doc.paragraphSetting.hanging",
17139
+ label: localeService.t("docs-ui.doc.paragraphSetting.hanging"),
17245
17140
  unit: "(px)",
17246
17141
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoFocusInputNumber, {
17247
17142
  value: hanging,
17248
- onChange: (v) => setHanging(v !== null && v !== void 0 ? v : 0)
17143
+ onChange: (v) => setHanging(v ?? 0)
17249
17144
  })
17250
17145
  })
17251
17146
  ]
17252
17147
  })
17253
17148
  }),
17254
17149
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ParagraphSettingSection, {
17255
- titleKey: "docs-ui.doc.paragraphSetting.spacing",
17150
+ title: localeService.t("docs-ui.doc.paragraphSetting.spacing"),
17256
17151
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
17257
17152
  className: "univer-grid univer-gap-3",
17258
17153
  children: [
17259
17154
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ParagraphSettingRow, {
17260
- labelKey: "docs-ui.doc.paragraphSetting.before",
17155
+ label: localeService.t("docs-ui.doc.paragraphSetting.before"),
17261
17156
  unit: "(px)",
17262
17157
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoFocusInputNumber, {
17263
17158
  value: spaceAbove,
17264
- onChange: (v) => setSpaceAbove(v !== null && v !== void 0 ? v : 0)
17159
+ onChange: (v) => setSpaceAbove(v ?? 0)
17265
17160
  })
17266
17161
  }),
17267
17162
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ParagraphSettingRow, {
17268
- labelKey: "docs-ui.doc.paragraphSetting.after",
17163
+ label: localeService.t("docs-ui.doc.paragraphSetting.after"),
17269
17164
  unit: "(px)",
17270
17165
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoFocusInputNumber, {
17271
17166
  value: spaceBelow,
17272
- onChange: (v) => setSpaceBelow(v !== null && v !== void 0 ? v : 0)
17167
+ onChange: (v) => setSpaceBelow(v ?? 0)
17273
17168
  })
17274
17169
  }),
17275
17170
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ParagraphSettingRow, {
17276
- labelKey: "docs-ui.doc.paragraphSetting.lineSpace",
17171
+ label: localeService.t("docs-ui.doc.paragraphSetting.lineSpace"),
17277
17172
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
17278
17173
  className: "univer-flex univer-w-full univer-flex-col univer-gap-2",
17279
17174
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
@@ -17284,7 +17179,7 @@ function ParagraphSetting() {
17284
17179
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoFocusInputNumber, {
17285
17180
  ...lineSpaceConfig,
17286
17181
  value: lineSpacing,
17287
- onChange: (v) => setLineSpacing(v !== null && v !== void 0 ? v : 0)
17182
+ onChange: (v) => setLineSpacing(v ?? 0)
17288
17183
  })]
17289
17184
  })
17290
17185
  })
@@ -17421,8 +17316,8 @@ DocFloatMenuService = __decorate([
17421
17316
  __decorateParam(5, _univerjs_core.IContextService)
17422
17317
  ], DocFloatMenuService);
17423
17318
  function isRangeInCodeBlock(documentDataModel, range) {
17424
- var _documentDataModel$ge3, _documentDataModel$ge4;
17425
- return ((_documentDataModel$ge3 = (_documentDataModel$ge4 = documentDataModel.getBody()) === null || _documentDataModel$ge4 === void 0 ? void 0 : _documentDataModel$ge4.blockRanges) !== null && _documentDataModel$ge3 !== void 0 ? _documentDataModel$ge3 : []).some((blockRange) => blockRange.blockType === _univerjs_core.DocumentBlockRangeType.CODE && Math.max(range.startOffset, blockRange.startIndex) <= Math.min(range.endOffset, blockRange.endIndex));
17319
+ var _documentDataModel$ge3;
17320
+ return (((_documentDataModel$ge3 = documentDataModel.getBody()) === null || _documentDataModel$ge3 === void 0 ? void 0 : _documentDataModel$ge3.blockRanges) ?? []).some((blockRange) => blockRange.blockType === _univerjs_core.DocumentBlockRangeType.CODE && Math.max(range.startOffset, blockRange.startIndex) <= Math.min(range.endOffset, blockRange.endIndex));
17426
17321
  }
17427
17322
 
17428
17323
  //#endregion
@@ -17459,8 +17354,8 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
17459
17354
  return (_this$_paragraphMenu = this._paragraphMenu) === null || _this$_paragraphMenu === void 0 ? void 0 : _this$_paragraphMenu.paragraph;
17460
17355
  }
17461
17356
  get activeTarget() {
17462
- var _this$_paragraphMenu$, _this$_paragraphMenu2;
17463
- return (_this$_paragraphMenu$ = (_this$_paragraphMenu2 = this._paragraphMenu) === null || _this$_paragraphMenu2 === void 0 ? void 0 : _this$_paragraphMenu2.target) !== null && _this$_paragraphMenu$ !== void 0 ? _this$_paragraphMenu$ : null;
17357
+ var _this$_paragraphMenu2;
17358
+ return ((_this$_paragraphMenu2 = this._paragraphMenu) === null || _this$_paragraphMenu2 === void 0 ? void 0 : _this$_paragraphMenu2.target) ?? null;
17464
17359
  }
17465
17360
  setBlockMenuDragging(isDragging) {
17466
17361
  this._isBlockMenuDragging = isDragging;
@@ -17526,7 +17421,6 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
17526
17421
  if (this._paragraphMenu) this._paragraphMenu.active = active;
17527
17422
  }
17528
17423
  _init() {
17529
- var _this$_docEventManage;
17530
17424
  const handleHoverTarget = (paragraph, tableBound) => {
17531
17425
  if (this._isBlockMenuDragging) return;
17532
17426
  if (this._docSelectionRenderService.isOnPointerEvent) {
@@ -17565,12 +17459,12 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
17565
17459
  this.disposeWithMe((0, rxjs.combineLatest)([
17566
17460
  this._docEventManagerService.hoverParagraphRealTime$,
17567
17461
  this._docEventManagerService.hoverParagraphLeft$,
17568
- (_this$_docEventManage = this._docEventManagerService.hoverTableRealTime$) !== null && _this$_docEventManage !== void 0 ? _this$_docEventManage : new rxjs.BehaviorSubject(null)
17462
+ this._docEventManagerService.hoverTableRealTime$ ?? new rxjs.BehaviorSubject(null)
17569
17463
  ]).pipe((0, rxjs.throttleTime)(16, void 0, {
17570
17464
  leading: true,
17571
17465
  trailing: true
17572
17466
  })).subscribe(([p, left, table]) => {
17573
- handleHoverTarget(p !== null && p !== void 0 ? p : left, table);
17467
+ handleHoverTarget(p ?? left, table);
17574
17468
  }));
17575
17469
  this.disposeWithMe(this._docSelectionRenderService.onSelectionStart$.subscribe(() => {
17576
17470
  this.hideParagraphMenu(true);
@@ -17633,14 +17527,12 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
17633
17527
  return this._getCollapsedTextRange(config) != null;
17634
17528
  }
17635
17529
  _shouldOpenSlashMenuFromInput(config) {
17636
- var _ref, _config$content;
17637
17530
  const event = config.event;
17638
- if (((_ref = (_config$content = config.content) !== null && _config$content !== void 0 ? _config$content : event.data) !== null && _ref !== void 0 ? _ref : "") !== "/") return false;
17531
+ if ((config.content ?? event.data ?? "") !== "/") return false;
17639
17532
  return this._getCollapsedTextRange(config) != null;
17640
17533
  }
17641
17534
  _getCollapsedTextRange(config) {
17642
- var _config$activeRange;
17643
- const activeRange = (_config$activeRange = config.activeRange) !== null && _config$activeRange !== void 0 ? _config$activeRange : this._docSelectionManagerService.getActiveTextRange();
17535
+ const activeRange = config.activeRange ?? this._docSelectionManagerService.getActiveTextRange();
17644
17536
  if (!activeRange) return null;
17645
17537
  if (activeRange.collapsed || activeRange.startOffset === activeRange.endOffset) return {
17646
17538
  ...activeRange,
@@ -17649,31 +17541,31 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
17649
17541
  return null;
17650
17542
  }
17651
17543
  _getSlashMenuParagraph(config) {
17652
- var _this$_paragraphMenu$2, _this$_paragraphMenu7, _find;
17544
+ var _this$_paragraphMenu7;
17653
17545
  const activeRange = this._getCollapsedTextRange(config);
17654
17546
  const offset = activeRange === null || activeRange === void 0 ? void 0 : activeRange.startOffset;
17655
- const activeParagraph = (_this$_paragraphMenu$2 = (_this$_paragraphMenu7 = this._paragraphMenu) === null || _this$_paragraphMenu7 === void 0 ? void 0 : _this$_paragraphMenu7.paragraph) !== null && _this$_paragraphMenu$2 !== void 0 ? _this$_paragraphMenu$2 : null;
17547
+ const activeParagraph = ((_this$_paragraphMenu7 = this._paragraphMenu) === null || _this$_paragraphMenu7 === void 0 ? void 0 : _this$_paragraphMenu7.paragraph) ?? null;
17656
17548
  if (activeParagraph && offset != null && offset >= activeParagraph.paragraphStart && offset <= activeParagraph.paragraphEnd) return activeParagraph;
17657
17549
  if (activeParagraph && offset == null) return activeParagraph;
17658
17550
  if (offset == null) return null;
17659
- return (_find = [...this._docEventManagerService.paragraphBounds.values()].find((paragraph) => offset >= paragraph.paragraphStart && offset <= paragraph.paragraphEnd)) !== null && _find !== void 0 ? _find : null;
17551
+ return [...this._docEventManagerService.paragraphBounds.values()].find((paragraph) => offset >= paragraph.paragraphStart && offset <= paragraph.paragraphEnd) ?? null;
17660
17552
  }
17661
17553
  _getSlashMenuAnchorRect(config, paragraph) {
17662
17554
  const activeRange = this._getCollapsedTextRange(config);
17663
17555
  if (!activeRange) return paragraph.firstLine;
17664
17556
  try {
17665
- var _calcDocRangePosition, _calcDocRangePosition2;
17666
- return (_calcDocRangePosition = (_calcDocRangePosition2 = calcDocRangePositions({
17557
+ var _calcDocRangePosition;
17558
+ return ((_calcDocRangePosition = calcDocRangePositions({
17667
17559
  ...activeRange,
17668
17560
  collapsed: true,
17669
17561
  endOffset: activeRange.startOffset
17670
- }, this._context)) === null || _calcDocRangePosition2 === void 0 ? void 0 : _calcDocRangePosition2[0]) !== null && _calcDocRangePosition !== void 0 ? _calcDocRangePosition : paragraph.firstLine;
17562
+ }, this._context)) === null || _calcDocRangePosition === void 0 ? void 0 : _calcDocRangePosition[0]) ?? paragraph.firstLine;
17671
17563
  } catch {
17672
17564
  return paragraph.firstLine;
17673
17565
  }
17674
17566
  }
17675
17567
  showParagraphMenu(paragraph) {
17676
- var _this$_paragraphMenu8, _target$paragraph;
17568
+ var _this$_paragraphMenu8;
17677
17569
  if (this._hasExpandedSelection()) {
17678
17570
  this.hideParagraphMenu(true);
17679
17571
  return;
@@ -17685,12 +17577,11 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
17685
17577
  }
17686
17578
  if (((_this$_paragraphMenu8 = this._paragraphMenu) === null || _this$_paragraphMenu8 === void 0 ? void 0 : _this$_paragraphMenu8.target.key) === target.key) return;
17687
17579
  this.hideParagraphMenu(true);
17688
- const targetParagraph = (_target$paragraph = target.paragraph) !== null && _target$paragraph !== void 0 ? _target$paragraph : paragraph;
17580
+ const targetParagraph = target.paragraph ?? paragraph;
17689
17581
  const blockRange = target.blockRange;
17690
17582
  const getFirstLine = () => {
17691
- var _this$_docEventManage2, _latestParagraphBound;
17692
- const latestParagraphBound = (_this$_docEventManage2 = this._docEventManagerService.findParagraphBoundByIndex(targetParagraph.startIndex)) !== null && _this$_docEventManage2 !== void 0 ? _this$_docEventManage2 : targetParagraph;
17693
- const baseAnchor = blockRange ? getBlockRangeAnchorRect(this._docEventManagerService, blockRange, paragraph) : (_latestParagraphBound = latestParagraphBound.firstLine) !== null && _latestParagraphBound !== void 0 ? _latestParagraphBound : paragraph.firstLine;
17583
+ const latestParagraphBound = this._docEventManagerService.findParagraphBoundByIndex(targetParagraph.startIndex) ?? targetParagraph;
17584
+ const baseAnchor = blockRange ? getBlockRangeAnchorRect(this._docEventManagerService, blockRange, paragraph) : latestParagraphBound.firstLine ?? paragraph.firstLine;
17694
17585
  if (!target.cellRange) return baseAnchor;
17695
17586
  return getTableCellParagraphAnchorRect(this._docEventManagerService, latestParagraphBound, baseAnchor);
17696
17587
  };
@@ -17756,10 +17647,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
17756
17647
  firstLine: anchorRect
17757
17648
  };
17758
17649
  this.hideParagraphMenu(true);
17759
- const getFirstLine = () => {
17760
- var _this$_docEventManage3;
17761
- return getTableAnchorRect((_this$_docEventManage3 = this._docEventManagerService.tableBounds.get(table.tableId)) !== null && _this$_docEventManage3 !== void 0 ? _this$_docEventManage3 : tableBound);
17762
- };
17650
+ const getFirstLine = () => getTableAnchorRect(this._docEventManagerService.tableBounds.get(table.tableId) ?? tableBound);
17763
17651
  const disposable = this._docPopupManagerService.attachPopupToRect(getFirstLine, {
17764
17652
  componentKey: DOC_TABLE_BLOCK_MENU_COMPONENT_KEY,
17765
17653
  direction: "top-right",
@@ -17828,9 +17716,9 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
17828
17716
  }
17829
17717
  }
17830
17718
  _buildParagraphMenuTarget(paragraph) {
17831
- var _body$dataStream, _body$paragraphs, _paragraphModel$bulle, _paragraphModel$parag, _body$customBlocks;
17719
+ var _body$paragraphs, _paragraphModel$bulle, _paragraphModel$parag, _body$customBlocks;
17832
17720
  const body = this._context.unit.getBody();
17833
- const dataStream = (_body$dataStream = body === null || body === void 0 ? void 0 : body.dataStream) !== null && _body$dataStream !== void 0 ? _body$dataStream : "";
17721
+ const dataStream = (body === null || body === void 0 ? void 0 : body.dataStream) ?? "";
17834
17722
  const cellRange = getContainingTableCellRange(dataStream, paragraph.paragraphStart);
17835
17723
  const inTable = cellRange != null || isParagraphInTable(this._context.unit, paragraph.paragraphStart);
17836
17724
  const blockRange = getParagraphBlockRange(this._context.unit, paragraph);
@@ -17848,7 +17736,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
17848
17736
  paragraph: targetParagraph,
17849
17737
  blockRange,
17850
17738
  icon: BLOCK_RANGE_ICON_MAP[blockRange.blockType],
17851
- cellRange: cellRange !== null && cellRange !== void 0 ? cellRange : void 0,
17739
+ cellRange: cellRange ?? void 0,
17852
17740
  menuRange: {
17853
17741
  startOffset: blockRange.startIndex,
17854
17742
  endOffset: blockRange.endIndex + 1,
@@ -17874,7 +17762,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
17874
17762
  paragraph,
17875
17763
  customBlock,
17876
17764
  icon: "TextTypeIcon",
17877
- cellRange: cellRange !== null && cellRange !== void 0 ? cellRange : void 0,
17765
+ cellRange: cellRange ?? void 0,
17878
17766
  menuRange: {
17879
17767
  startOffset: customBlock.startIndex,
17880
17768
  endOffset: customBlock.startIndex,
@@ -17890,7 +17778,7 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
17890
17778
  key: `${_univerjs_core.DocumentBlockType.PARAGRAPH}:${paragraph.startIndex}`,
17891
17779
  paragraph,
17892
17780
  icon: isHorizontalRuleParagraph ? "ReduceIcon" : listIcon,
17893
- cellRange: cellRange !== null && cellRange !== void 0 ? cellRange : void 0,
17781
+ cellRange: cellRange ?? void 0,
17894
17782
  menuRange: {
17895
17783
  startOffset: paragraph.paragraphStart,
17896
17784
  endOffset: paragraph.paragraphStart,
@@ -17902,11 +17790,10 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
17902
17790
  };
17903
17791
  }
17904
17792
  _getBodyBlockTargets() {
17905
- var _body$tables2, _body$blockRanges;
17906
17793
  const body = this._context.unit.getBody();
17907
17794
  if (!body) return [];
17908
- const tableRanges = (_body$tables2 = body.tables) !== null && _body$tables2 !== void 0 ? _body$tables2 : [];
17909
- const blockRanges = (_body$blockRanges = body.blockRanges) !== null && _body$blockRanges !== void 0 ? _body$blockRanges : [];
17795
+ const tableRanges = body.tables ?? [];
17796
+ const blockRanges = body.blockRanges ?? [];
17910
17797
  const paragraphBounds = [...this._docEventManagerService.paragraphBounds.values()];
17911
17798
  const targets = [];
17912
17799
  for (const table of tableRanges) {
@@ -17966,10 +17853,9 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
17966
17853
  return targets;
17967
17854
  }
17968
17855
  _getCellBlockTargets(cellRange) {
17969
- var _body$blockRanges2;
17970
17856
  const body = this._context.unit.getBody();
17971
17857
  if (!body) return [];
17972
- const blockRanges = (_body$blockRanges2 = body.blockRanges) !== null && _body$blockRanges2 !== void 0 ? _body$blockRanges2 : [];
17858
+ const blockRanges = body.blockRanges ?? [];
17973
17859
  const paragraphBounds = [...this._docEventManagerService.paragraphBounds.values()].filter((paragraph) => paragraph.paragraphStart > cellRange.startOffset && paragraph.paragraphStart < cellRange.endOffset);
17974
17860
  const targets = [];
17975
17861
  for (const blockRange of blockRanges) {
@@ -18017,8 +17903,8 @@ DocParagraphMenuService = __decorate([
18017
17903
  __decorateParam(6, (0, _univerjs_core.Inject)(DocSelectionRenderService))
18018
17904
  ], DocParagraphMenuService);
18019
17905
  function isParagraphInTable(documentDataModel, paragraphStart) {
18020
- var _documentDataModel$ge, _documentDataModel$ge2;
18021
- return ((_documentDataModel$ge = (_documentDataModel$ge2 = documentDataModel.getBody()) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.tables) !== null && _documentDataModel$ge !== void 0 ? _documentDataModel$ge : []).some((table) => paragraphStart > table.startIndex && paragraphStart < table.endIndex);
17906
+ var _documentDataModel$ge;
17907
+ return (((_documentDataModel$ge = documentDataModel.getBody()) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.tables) ?? []).some((table) => paragraphStart > table.startIndex && paragraphStart < table.endIndex);
18022
17908
  }
18023
17909
  function getParagraphMoveRange(documentDataModel, paragraph, cellRange) {
18024
17910
  const body = documentDataModel.getBody();
@@ -18078,13 +17964,13 @@ function unionRects(rects) {
18078
17964
  }));
18079
17965
  }
18080
17966
  function getParagraphBlockRange(documentDataModel, paragraph) {
18081
- var _documentDataModel$ge3, _documentDataModel$ge4;
18082
- return ((_documentDataModel$ge3 = (_documentDataModel$ge4 = documentDataModel.getBody()) === null || _documentDataModel$ge4 === void 0 ? void 0 : _documentDataModel$ge4.blockRanges) !== null && _documentDataModel$ge3 !== void 0 ? _documentDataModel$ge3 : []).find((range) => Math.max(paragraph.paragraphStart, range.startIndex) <= Math.min(paragraph.paragraphEnd, range.endIndex));
17967
+ var _documentDataModel$ge2;
17968
+ return (((_documentDataModel$ge2 = documentDataModel.getBody()) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.blockRanges) ?? []).find((range) => Math.max(paragraph.paragraphStart, range.startIndex) <= Math.min(paragraph.paragraphEnd, range.endIndex));
18083
17969
  }
18084
17970
  function getBlockRangeAnchorRect(docEventManagerService, blockRange, fallbackParagraph) {
18085
- var _bounds$0$firstLine, _bounds$;
17971
+ var _bounds$;
18086
17972
  const bounds = docEventManagerService.findParagraphBoundsInRange(blockRange.startIndex, blockRange.endIndex).sort((left, right) => left.firstLine.top - right.firstLine.top || left.firstLine.left - right.firstLine.left);
18087
- const anchor = (_bounds$0$firstLine = (_bounds$ = bounds[0]) === null || _bounds$ === void 0 ? void 0 : _bounds$.firstLine) !== null && _bounds$0$firstLine !== void 0 ? _bounds$0$firstLine : fallbackParagraph.firstLine;
17973
+ const anchor = ((_bounds$ = bounds[0]) === null || _bounds$ === void 0 ? void 0 : _bounds$.firstLine) ?? fallbackParagraph.firstLine;
18088
17974
  const left = Math.min(...(bounds.length ? bounds : [fallbackParagraph]).map((bound) => bound.firstLine.left));
18089
17975
  const top = anchor.top;
18090
17976
  return {
@@ -18109,6 +17995,9 @@ const PARAGRAPH_MENU_HOVER_OPEN_DELAY = 800;
18109
17995
  const PARAGRAPH_MENU_HOVER_HIDE_DELAY = 240;
18110
17996
  const PARAGRAPH_MENU_HOVER_BRIDGE_EDGE_OVERLAP = 12;
18111
17997
  const PARAGRAPH_MENU_HOVER_BRIDGE_VERTICAL_PADDING = 8;
17998
+ function getParagraphMenuIconSizeClass(iconKey) {
17999
+ return iconKey === "TextTypeIcon" ? "univer-size-3" : "univer-size-4";
18000
+ }
18112
18001
  function shouldExecuteParagraphMenuMove(validatorService, context) {
18113
18002
  return validatorService.canMoveBlock(context);
18114
18003
  }
@@ -18202,8 +18091,7 @@ const NAMED_STYLE_HEADING_COMMAND_IDS = {
18202
18091
  [_univerjs_core.NamedStyleType.SUBTITLE]: SubtitleHeadingCommand.id
18203
18092
  };
18204
18093
  function getParagraphMenuActiveHeadingCommandId(namedStyleType) {
18205
- var _NAMED_STYLE_HEADING_;
18206
- return (_NAMED_STYLE_HEADING_ = NAMED_STYLE_HEADING_COMMAND_IDS[namedStyleType !== null && namedStyleType !== void 0 ? namedStyleType : _univerjs_core.NamedStyleType.NORMAL_TEXT]) !== null && _NAMED_STYLE_HEADING_ !== void 0 ? _NAMED_STYLE_HEADING_ : NormalTextHeadingCommand.id;
18094
+ return NAMED_STYLE_HEADING_COMMAND_IDS[namedStyleType ?? _univerjs_core.NamedStyleType.NORMAL_TEXT] ?? NormalTextHeadingCommand.id;
18207
18095
  }
18208
18096
  function getParagraphMenuHiddenHeadingCommandIds(namedStyleType) {
18209
18097
  if (namedStyleType === _univerjs_core.NamedStyleType.TITLE) return [
@@ -18272,8 +18160,7 @@ function shouldRestoreParagraphMenuSelectionAfterCommand(commandId) {
18272
18160
  return !!commandId && PARAGRAPH_MENU_RESTORE_SELECTION_COMMAND_IDS.has(commandId);
18273
18161
  }
18274
18162
  function getParagraphMenuCommand(params, targetRange) {
18275
- var _ref, _params$commandId;
18276
- const commandId = (_ref = (_params$commandId = params.commandId) !== null && _params$commandId !== void 0 ? _params$commandId : params.id) !== null && _ref !== void 0 ? _ref : typeof params.label === "string" ? params.label : void 0;
18163
+ const commandId = params.commandId ?? params.id ?? (typeof params.label === "string" ? params.label : void 0);
18277
18164
  if (commandId && targetRange && commandId in HEADING_COMMAND_VALUES) return {
18278
18165
  commandId: SetParagraphNamedStyleCommand.id,
18279
18166
  params: {
@@ -18297,19 +18184,18 @@ function getParagraphMenuCommand(params, targetRange) {
18297
18184
  };
18298
18185
  }
18299
18186
  function getParagraphMenuResolvedCommand(option, targetRange) {
18300
- var _ref2, _option$commandId, _option$id;
18301
- const commandId = (_ref2 = (_option$commandId = option.commandId) !== null && _option$commandId !== void 0 ? _option$commandId : option.id) !== null && _ref2 !== void 0 ? _ref2 : typeof option.label === "string" ? option.label : void 0;
18187
+ const commandId = option.commandId ?? option.id ?? (typeof option.label === "string" ? option.label : void 0);
18302
18188
  if (!commandId) return {};
18303
18189
  return getParagraphMenuCommand({
18304
18190
  ...option,
18305
18191
  commandId,
18306
- id: (_option$id = option.id) !== null && _option$id !== void 0 ? _option$id : commandId
18192
+ id: option.id ?? commandId
18307
18193
  }, targetRange);
18308
18194
  }
18309
18195
  function getParagraphMenuCommandParams(commandId, commandParams, target, unitId) {
18310
18196
  if (commandId !== DeleteCurrentParagraphCommand.id || (target === null || target === void 0 ? void 0 : target.kind) !== "blockRange" || !target.blockRange) return commandParams;
18311
18197
  return {
18312
- ...commandParams !== null && commandParams !== void 0 ? commandParams : {},
18198
+ ...commandParams ?? {},
18313
18199
  unitId,
18314
18200
  blockRange: target.blockRange
18315
18201
  };
@@ -18427,10 +18313,10 @@ function stripBlockParagraphStyle(style, blockType) {
18427
18313
  return nextStyle;
18428
18314
  }
18429
18315
  function unwrapBlockRangeBody(documentBody, blockRange) {
18430
- var _body$paragraphs, _body$blockRanges;
18316
+ var _body$blockRanges;
18431
18317
  const body = _univerjs_core.Tools.deepClone(documentBody);
18432
18318
  const endTokenOffset = getEndTokenOffset(body, blockRange);
18433
- ((_body$paragraphs = body.paragraphs) !== null && _body$paragraphs !== void 0 ? _body$paragraphs : []).filter((paragraph) => paragraph.startIndex > blockRange.startIndex && paragraph.startIndex < endTokenOffset).forEach((paragraph) => {
18319
+ (body.paragraphs ?? []).filter((paragraph) => paragraph.startIndex > blockRange.startIndex && paragraph.startIndex < endTokenOffset).forEach((paragraph) => {
18434
18320
  paragraph.paragraphStyle = stripBlockParagraphStyle(paragraph.paragraphStyle, blockRange.blockType);
18435
18321
  });
18436
18322
  deleteBodyText(body, endTokenOffset, endTokenOffset + 1);
@@ -18534,8 +18420,8 @@ function getParagraphFormattingRange(target, paragraph) {
18534
18420
  }
18535
18421
  function getParagraphMenuCommandTargetRange(commandId, targetRange, formattingRange) {
18536
18422
  if (commandId === DocPasteCommand.id) return targetRange;
18537
- if (commandId && PARAGRAPH_MENU_SELECTION_COMMAND_IDS.has(commandId)) return formattingRange !== null && formattingRange !== void 0 ? formattingRange : targetRange;
18538
- return targetRange !== null && targetRange !== void 0 ? targetRange : formattingRange;
18423
+ if (commandId && PARAGRAPH_MENU_SELECTION_COMMAND_IDS.has(commandId)) return formattingRange ?? targetRange;
18424
+ return targetRange ?? formattingRange;
18539
18425
  }
18540
18426
  function finishParagraphMenuCommand(docParagraphMenuService, layoutService, hideMenu) {
18541
18427
  docParagraphMenuService === null || docParagraphMenuService === void 0 || docParagraphMenuService.hideParagraphMenu(true);
@@ -18561,11 +18447,11 @@ function getBlockRangeClipboardTargetRange(commandId, target, paragraph) {
18561
18447
  collapsed: true,
18562
18448
  segmentId: paragraph === null || paragraph === void 0 ? void 0 : paragraph.segmentId
18563
18449
  };
18564
- if (commandId === DocCopyCurrentParagraphCommand.id || commandId === DocCutCurrentParagraphCommand.id) return getBlockSelectionRange(target, paragraph !== null && paragraph !== void 0 ? paragraph : void 0);
18450
+ if (commandId === DocCopyCurrentParagraphCommand.id || commandId === DocCutCurrentParagraphCommand.id) return getBlockSelectionRange(target, paragraph ?? void 0);
18565
18451
  return null;
18566
18452
  }
18567
18453
  function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
18568
- var _ref3, _ref4, _currentActiveTarget$, _doc$getBody$dataStre, _doc$getBody, _currentActiveTarget$2, _paragraphObj$paragra, _currentActiveTarget$3;
18454
+ var _doc$getBody, _paragraphObj$paragra;
18569
18455
  const [visible, setVisible] = (0, react.useState)(false);
18570
18456
  const [openMode, setOpenMode] = (0, react.useState)("pointer");
18571
18457
  const [anchorRect, setAnchorRect] = (0, react.useState)(null);
@@ -18600,18 +18486,18 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
18600
18486
  const slashMenuRequest = (0, _univerjs_ui.useObservable)(docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.slashMenuRequest$);
18601
18487
  const paragraph = (0, _univerjs_ui.useObservable)(docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.hoverParagraph$);
18602
18488
  const paragraphLeft = (0, _univerjs_ui.useObservable)(docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.hoverParagraphLeft$);
18603
- const rawActiveTarget = activeTarget !== null && activeTarget !== void 0 ? activeTarget : docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget;
18489
+ const rawActiveTarget = activeTarget ?? (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget);
18604
18490
  const currentActiveTarget = tableBlockOnly ? (rawActiveTarget === null || rawActiveTarget === void 0 ? void 0 : rawActiveTarget.kind) === "table" ? rawActiveTarget : null : (rawActiveTarget === null || rawActiveTarget === void 0 ? void 0 : rawActiveTarget.kind) === "table" ? null : rawActiveTarget;
18605
- const activeParagraphBound = (_ref3 = (_ref4 = (_currentActiveTarget$ = currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.paragraph) !== null && _currentActiveTarget$ !== void 0 ? _currentActiveTarget$ : docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeParagraph) !== null && _ref4 !== void 0 ? _ref4 : paragraph) !== null && _ref3 !== void 0 ? _ref3 : paragraphLeft;
18491
+ const activeParagraphBound = (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.paragraph) ?? (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeParagraph) ?? paragraph ?? paragraphLeft;
18606
18492
  const startIndex = activeParagraphBound === null || activeParagraphBound === void 0 ? void 0 : activeParagraphBound.startIndex;
18607
- const dataStream = (_doc$getBody$dataStre = doc === null || doc === void 0 || (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.dataStream) !== null && _doc$getBody$dataStre !== void 0 ? _doc$getBody$dataStre : "";
18493
+ const dataStream = (doc === null || doc === void 0 || (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.dataStream) ?? "";
18608
18494
  const paragraphObj = (0, react.useMemo)(() => {
18609
18495
  var _doc$getBody2;
18610
18496
  return doc === null || doc === void 0 || (_doc$getBody2 = doc.getBody()) === null || _doc$getBody2 === void 0 || (_doc$getBody2 = _doc$getBody2.paragraphs) === null || _doc$getBody2 === void 0 ? void 0 : _doc$getBody2.find((p) => p.startIndex === startIndex);
18611
18497
  }, [doc, startIndex]);
18612
- const isEmptyParagraph = (_currentActiveTarget$2 = currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.emptyMode) !== null && _currentActiveTarget$2 !== void 0 ? _currentActiveTarget$2 : isEmptyParagraphMenuTarget(dataStream, activeParagraphBound);
18498
+ const isEmptyParagraph = (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.emptyMode) ?? isEmptyParagraphMenuTarget(dataStream, activeParagraphBound);
18613
18499
  const namedStyleType = paragraphObj === null || paragraphObj === void 0 || (_paragraphObj$paragra = paragraphObj.paragraphStyle) === null || _paragraphObj$paragra === void 0 ? void 0 : _paragraphObj$paragra.namedStyleType;
18614
- const targetIconKey = (_currentActiveTarget$3 = currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.icon) !== null && _currentActiveTarget$3 !== void 0 ? _currentActiveTarget$3 : getParagraphMenuTriggerIconKey(namedStyleType);
18500
+ const targetIconKey = (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.icon) ?? getParagraphMenuTriggerIconKey(namedStyleType);
18615
18501
  const TargetIcon = iconManager.get(targetIconKey);
18616
18502
  const paragraphMenuType = (0, react.useMemo)(() => getParagraphMenuType(currentActiveTarget, isEmptyParagraph), [currentActiveTarget, isEmptyParagraph]);
18617
18503
  const paragraphMenuActiveItemIds = (0, react.useMemo)(() => getParagraphMenuActiveItemIds(currentActiveTarget, namedStyleType), [currentActiveTarget, namedStyleType]);
@@ -18627,11 +18513,11 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
18627
18513
  bottom: 0
18628
18514
  }), []);
18629
18515
  const updateAnchorRect = () => {
18630
- var _anchorRef$current, _boundingRect$left, _boundingRect$right, _anchorRef$current$ow, _anchorRef$current2, _boundingRect$top, _boundingRect$bottom;
18516
+ var _anchorRef$current, _anchorRef$current2;
18631
18517
  const boundingRect = (_anchorRef$current = anchorRef.current) === null || _anchorRef$current === void 0 ? void 0 : _anchorRef$current.getBoundingClientRect();
18632
- const left = ((_boundingRect$left = boundingRect === null || boundingRect === void 0 ? void 0 : boundingRect.left) !== null && _boundingRect$left !== void 0 ? _boundingRect$left : 0) - 4;
18633
- const right = (_boundingRect$right = boundingRect === null || boundingRect === void 0 ? void 0 : boundingRect.right) !== null && _boundingRect$right !== void 0 ? _boundingRect$right : 0;
18634
- const viewportWidth = (_anchorRef$current$ow = (_anchorRef$current2 = anchorRef.current) === null || _anchorRef$current2 === void 0 || (_anchorRef$current2 = _anchorRef$current2.ownerDocument.defaultView) === null || _anchorRef$current2 === void 0 ? void 0 : _anchorRef$current2.innerWidth) !== null && _anchorRef$current$ow !== void 0 ? _anchorRef$current$ow : window.innerWidth;
18518
+ const left = ((boundingRect === null || boundingRect === void 0 ? void 0 : boundingRect.left) ?? 0) - 4;
18519
+ const right = (boundingRect === null || boundingRect === void 0 ? void 0 : boundingRect.right) ?? 0;
18520
+ const viewportWidth = ((_anchorRef$current2 = anchorRef.current) === null || _anchorRef$current2 === void 0 || (_anchorRef$current2 = _anchorRef$current2.ownerDocument.defaultView) === null || _anchorRef$current2 === void 0 ? void 0 : _anchorRef$current2.innerWidth) ?? window.innerWidth;
18635
18521
  setMenuDirection(getParagraphMenuPopupDirection(left, 212, 8, {
18636
18522
  anchorRight: right,
18637
18523
  direction,
@@ -18640,8 +18526,8 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
18640
18526
  const nextAnchorRect = {
18641
18527
  left,
18642
18528
  right,
18643
- top: (_boundingRect$top = boundingRect === null || boundingRect === void 0 ? void 0 : boundingRect.top) !== null && _boundingRect$top !== void 0 ? _boundingRect$top : 0,
18644
- bottom: (_boundingRect$bottom = boundingRect === null || boundingRect === void 0 ? void 0 : boundingRect.bottom) !== null && _boundingRect$bottom !== void 0 ? _boundingRect$bottom : 0
18529
+ top: (boundingRect === null || boundingRect === void 0 ? void 0 : boundingRect.top) ?? 0,
18530
+ bottom: (boundingRect === null || boundingRect === void 0 ? void 0 : boundingRect.bottom) ?? 0
18645
18531
  };
18646
18532
  setAnchorRect(nextAnchorRect);
18647
18533
  anchorRect$.next(nextAnchorRect);
@@ -18665,9 +18551,8 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
18665
18551
  }, PARAGRAPH_MENU_HOVER_HIDE_DELAY);
18666
18552
  };
18667
18553
  const handleOpenMenu = (mode = "pointer") => {
18668
- var _docParagraphMenuServ;
18669
18554
  clearHideTimer();
18670
- const latestTarget = (_docParagraphMenuServ = docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) !== null && _docParagraphMenuServ !== void 0 ? _docParagraphMenuServ : activeTarget;
18555
+ const latestTarget = (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) ?? activeTarget;
18671
18556
  setParagraphMenuInteractionActive(docParagraphMenuService, true);
18672
18557
  const targetRange = latestTarget ? {
18673
18558
  ...latestTarget.menuRange,
@@ -18680,11 +18565,11 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
18680
18565
  };
18681
18566
  openMenuRef.current = handleOpenMenu;
18682
18567
  const handleOpenSlashMenu = (request) => {
18683
- var _request$target$parag, _request$target$parag2;
18568
+ var _request$target$parag;
18684
18569
  clearHideTimer();
18685
18570
  targetRangeRef.current = {
18686
18571
  ...request.target.menuRange,
18687
- segmentId: (_request$target$parag = (_request$target$parag2 = request.target.paragraph) === null || _request$target$parag2 === void 0 ? void 0 : _request$target$parag2.segmentId) !== null && _request$target$parag !== void 0 ? _request$target$parag : activeParagraphBound === null || activeParagraphBound === void 0 ? void 0 : activeParagraphBound.segmentId
18572
+ segmentId: ((_request$target$parag = request.target.paragraph) === null || _request$target$parag === void 0 ? void 0 : _request$target$parag.segmentId) ?? (activeParagraphBound === null || activeParagraphBound === void 0 ? void 0 : activeParagraphBound.segmentId)
18688
18573
  };
18689
18574
  setMenuDirection("vertical");
18690
18575
  setAnchorRect(request.anchorRect);
@@ -18704,8 +18589,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
18704
18589
  docSelectionManagerService.replaceDocRanges([range], void 0, false);
18705
18590
  };
18706
18591
  const getCurrentTextRangesSnapshot = () => {
18707
- var _docSelectionManagerS;
18708
- return ((_docSelectionManagerS = docSelectionManagerService.getTextRanges()) !== null && _docSelectionManagerS !== void 0 ? _docSelectionManagerS : []).map((range) => ({ ...range }));
18592
+ return (docSelectionManagerService.getTextRanges() ?? []).map((range) => ({ ...range }));
18709
18593
  };
18710
18594
  const restoreTextRanges = (ranges) => {
18711
18595
  if (!ranges) return;
@@ -18717,13 +18601,12 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
18717
18601
  return commandService.executeCommand(resolved.commandId, resolved.params);
18718
18602
  };
18719
18603
  const unwrapActiveBlockRange = async () => {
18720
- var _docParagraphMenuServ2, _activeParagraphBound;
18721
- const latestTarget = (_docParagraphMenuServ2 = docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) !== null && _docParagraphMenuServ2 !== void 0 ? _docParagraphMenuServ2 : activeTarget;
18604
+ const latestTarget = (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) ?? activeTarget;
18722
18605
  if (!latestTarget || latestTarget.kind !== "blockRange" || !latestTarget.blockRange || !(doc === null || doc === void 0 ? void 0 : doc.getBody())) return null;
18723
18606
  const previousBody = doc.getBody();
18724
18607
  const { body, range } = unwrapBlockRangeBody(previousBody, latestTarget.blockRange);
18725
18608
  const actions = buildUnwrapBlockRangeActions(previousBody, body, latestTarget.blockRange);
18726
- const segmentId = (_activeParagraphBound = activeParagraphBound === null || activeParagraphBound === void 0 ? void 0 : activeParagraphBound.segmentId) !== null && _activeParagraphBound !== void 0 ? _activeParagraphBound : "";
18609
+ const segmentId = (activeParagraphBound === null || activeParagraphBound === void 0 ? void 0 : activeParagraphBound.segmentId) ?? "";
18727
18610
  if (!await commandService.executeCommand(_univerjs_docs.RichTextEditingMutation.id, {
18728
18611
  unitId: popup.unitId,
18729
18612
  actions,
@@ -18741,12 +18624,11 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
18741
18624
  return nextRange;
18742
18625
  };
18743
18626
  const executeParagraphMenuOption = async (option) => {
18744
- var _docParagraphMenuServ3, _ref5, _option$commandId2;
18745
- const latestTarget = (_docParagraphMenuServ3 = docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) !== null && _docParagraphMenuServ3 !== void 0 ? _docParagraphMenuServ3 : activeTarget;
18746
- const targetRange = getTargetSelectionRange(latestTarget, activeParagraphBound !== null && activeParagraphBound !== void 0 ? activeParagraphBound : void 0);
18747
- const blockRange = getBlockSelectionRange(latestTarget, activeParagraphBound !== null && activeParagraphBound !== void 0 ? activeParagraphBound : void 0);
18748
- const formattingRange = getParagraphFormattingRange(latestTarget, activeParagraphBound !== null && activeParagraphBound !== void 0 ? activeParagraphBound : void 0);
18749
- const commandId = (_ref5 = (_option$commandId2 = option.commandId) !== null && _option$commandId2 !== void 0 ? _option$commandId2 : option.id) !== null && _ref5 !== void 0 ? _ref5 : typeof option.label === "string" ? option.label : void 0;
18627
+ const latestTarget = (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) ?? activeTarget;
18628
+ const targetRange = getTargetSelectionRange(latestTarget, activeParagraphBound ?? void 0);
18629
+ const blockRange = getBlockSelectionRange(latestTarget, activeParagraphBound ?? void 0);
18630
+ const formattingRange = getParagraphFormattingRange(latestTarget, activeParagraphBound ?? void 0);
18631
+ const commandId = option.commandId ?? option.id ?? (typeof option.label === "string" ? option.label : void 0);
18750
18632
  const commandParams = typeof option.params === "function" ? option.params() : option.params;
18751
18633
  if (!commandId) return;
18752
18634
  if (commandId === "doc.menu.paragraph-t.reset-colors") {
@@ -18757,9 +18639,9 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
18757
18639
  return;
18758
18640
  }
18759
18641
  if (commandId === "doc.menu.paragraph-t.indent.increase" || commandId === "doc.menu.paragraph-t.indent.decrease") {
18760
- var _paragraphObj$paragra2, _paragraphObj$paragra3;
18642
+ var _paragraphObj$paragra2;
18761
18643
  if (formattingRange) replaceSelection(formattingRange);
18762
- const currentIndent = (_paragraphObj$paragra2 = paragraphObj === null || paragraphObj === void 0 || (_paragraphObj$paragra3 = paragraphObj.paragraphStyle) === null || _paragraphObj$paragra3 === void 0 || (_paragraphObj$paragra3 = _paragraphObj$paragra3.indentFirstLine) === null || _paragraphObj$paragra3 === void 0 ? void 0 : _paragraphObj$paragra3.v) !== null && _paragraphObj$paragra2 !== void 0 ? _paragraphObj$paragra2 : 0;
18644
+ const currentIndent = (paragraphObj === null || paragraphObj === void 0 || (_paragraphObj$paragra2 = paragraphObj.paragraphStyle) === null || _paragraphObj$paragra2 === void 0 || (_paragraphObj$paragra2 = _paragraphObj$paragra2.indentFirstLine) === null || _paragraphObj$paragra2 === void 0 ? void 0 : _paragraphObj$paragra2.v) ?? 0;
18763
18645
  const delta = commandId === "doc.menu.paragraph-t.indent.increase" ? 20 : -20;
18764
18646
  await commandService.executeCommand(DocParagraphSettingCommand.id, { paragraph: { indentFirstLine: { v: Math.max(0, currentIndent + delta) } } });
18765
18647
  finishParagraphMenuCommand(docParagraphMenuService, layoutService, handleHideMenu);
@@ -18825,15 +18707,13 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
18825
18707
  return;
18826
18708
  }
18827
18709
  const previousTextRanges = shouldRestoreParagraphMenuSelectionAfterCommand(commandId) ? getCurrentTextRangesSnapshot() : null;
18828
- if (commandId && shouldUseInsertBelowRange(commandId, option) && (latestTarget === null || latestTarget === void 0 ? void 0 : latestTarget.moveRange)) {
18829
- var _ref6, _targetRange$segmentI;
18830
- docContentInsertService.setInsertRange({
18831
- unitId: popup.unitId,
18832
- startOffset: latestTarget.moveRange.endOffset,
18833
- endOffset: latestTarget.moveRange.endOffset,
18834
- segmentId: (_ref6 = (_targetRange$segmentI = targetRange === null || targetRange === void 0 ? void 0 : targetRange.segmentId) !== null && _targetRange$segmentI !== void 0 ? _targetRange$segmentI : activeParagraphBound === null || activeParagraphBound === void 0 ? void 0 : activeParagraphBound.segmentId) !== null && _ref6 !== void 0 ? _ref6 : ""
18835
- });
18836
- } else if (PARAGRAPH_MENU_SELECTION_COMMAND_IDS.has(commandId) && !PARAGRAPH_MENU_SKIP_REPLACE_SELECTION_COMMAND_IDS.has(commandId)) replaceSelection(getParagraphMenuCommandTargetRange(commandId, targetRange, formattingRange));
18710
+ if (commandId && shouldUseInsertBelowRange(commandId, option) && (latestTarget === null || latestTarget === void 0 ? void 0 : latestTarget.moveRange)) docContentInsertService.setInsertRange({
18711
+ unitId: popup.unitId,
18712
+ startOffset: latestTarget.moveRange.endOffset,
18713
+ endOffset: latestTarget.moveRange.endOffset,
18714
+ segmentId: (targetRange === null || targetRange === void 0 ? void 0 : targetRange.segmentId) ?? (activeParagraphBound === null || activeParagraphBound === void 0 ? void 0 : activeParagraphBound.segmentId) ?? ""
18715
+ });
18716
+ else if (PARAGRAPH_MENU_SELECTION_COMMAND_IDS.has(commandId) && !PARAGRAPH_MENU_SKIP_REPLACE_SELECTION_COMMAND_IDS.has(commandId)) replaceSelection(getParagraphMenuCommandTargetRange(commandId, targetRange, formattingRange));
18837
18717
  try {
18838
18718
  await executeResolvedCommand({
18839
18719
  ...option,
@@ -18888,14 +18768,14 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
18888
18768
  isMouseOver.current = true;
18889
18769
  hoverOpenSchedulerRef.current.openNow();
18890
18770
  },
18891
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TargetIcon, {}), (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.draggable) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
18771
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TargetIcon, { className: (0, _univerjs_design.clsx)(getParagraphMenuIconSizeClass(targetIconKey), "univer-shrink-0 univer-text-gray-700 dark:!univer-text-white") }), (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.draggable) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
18892
18772
  type: "button",
18893
18773
  className: "univer-group univer-flex univer-h-4 univer-w-2.5 univer-cursor-grab univer-items-center univer-justify-center univer-border-none univer-bg-transparent univer-p-0 active:univer-cursor-grabbing",
18894
18774
  "aria-label": localeService.t("docs-ui.doc.blockMenu.dragBlock"),
18895
18775
  title: localeService.t("docs-ui.doc.blockMenu.dragBlock"),
18896
18776
  onPointerDown: (event) => {
18897
- var _docParagraphMenuServ4, _event$currentTarget$, _event$currentTarget;
18898
- const latestTarget = (_docParagraphMenuServ4 = docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) !== null && _docParagraphMenuServ4 !== void 0 ? _docParagraphMenuServ4 : activeTarget;
18777
+ var _event$currentTarget$, _event$currentTarget;
18778
+ const latestTarget = (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) ?? activeTarget;
18899
18779
  const moveRange = latestTarget === null || latestTarget === void 0 ? void 0 : latestTarget.moveRange;
18900
18780
  if (!moveRange || !(latestTarget === null || latestTarget === void 0 ? void 0 : latestTarget.draggable)) return;
18901
18781
  event.preventDefault();
@@ -18910,14 +18790,13 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
18910
18790
  setDropRect(null);
18911
18791
  const pointerId = event.pointerId;
18912
18792
  const handlePointerMove = (moveEvent) => {
18913
- var _target$targetOffset, _target$rect;
18914
18793
  if (moveEvent.pointerId !== pointerId) return;
18915
18794
  moveEvent.preventDefault();
18916
18795
  const range = dragRangeRef.current;
18917
18796
  if (!range) return;
18918
18797
  const target = docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.getDropTargetFromClientPoint(moveEvent.clientX, moveEvent.clientY, range);
18919
- dragTargetOffsetRef.current = (_target$targetOffset = target === null || target === void 0 ? void 0 : target.targetOffset) !== null && _target$targetOffset !== void 0 ? _target$targetOffset : null;
18920
- setDropRect((_target$rect = target === null || target === void 0 ? void 0 : target.rect) !== null && _target$rect !== void 0 ? _target$rect : null);
18798
+ dragTargetOffsetRef.current = (target === null || target === void 0 ? void 0 : target.targetOffset) ?? null;
18799
+ setDropRect((target === null || target === void 0 ? void 0 : target.rect) ?? null);
18921
18800
  };
18922
18801
  const finishDrag = (shouldDrop) => {
18923
18802
  window.removeEventListener("pointermove", handlePointerMove);
@@ -18998,6 +18877,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
18998
18877
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_ui.ContextMenuPanel, {
18999
18878
  className: "univer-w-[212px]",
19000
18879
  menuType: resolvedParagraphMenuType,
18880
+ flowQuickGroups: true,
19001
18881
  activeItemIds: (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.kind) === "table" ? void 0 : paragraphMenuActiveItemIds,
19002
18882
  hiddenItemIds: openMode === "slash" || (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.kind) === "table" ? void 0 : paragraphMenuHiddenItemIds,
19003
18883
  autoFocus: openMode === "slash",
@@ -19017,22 +18897,20 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
19017
18897
  finishParagraphMenuCommand(docParagraphMenuService, layoutService, handleHideMenu);
19018
18898
  },
19019
18899
  onOptionSelect: async (params) => {
19020
- var _targetRangeRef$curre, _docParagraphMenuServ5;
19021
- const targetRange = (_targetRangeRef$curre = targetRangeRef.current) !== null && _targetRangeRef$curre !== void 0 ? _targetRangeRef$curre : getParagraphMenuTargetRange(activeParagraphBound);
18900
+ const targetRange = targetRangeRef.current ?? getParagraphMenuTargetRange(activeParagraphBound);
19022
18901
  const { commandId, params: commandParams } = getParagraphMenuCommand(params, targetRange);
19023
- const latestTarget = (_docParagraphMenuServ5 = docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) !== null && _docParagraphMenuServ5 !== void 0 ? _docParagraphMenuServ5 : activeTarget;
18902
+ const latestTarget = (docParagraphMenuService === null || docParagraphMenuService === void 0 ? void 0 : docParagraphMenuService.activeTarget) ?? activeTarget;
19024
18903
  if ((latestTarget === null || latestTarget === void 0 ? void 0 : latestTarget.kind) === "table" && commandId && targetRange) {
19025
- var _targetRange$segmentI2, _targetRange$segmentI3;
19026
18904
  const tableRange = {
19027
18905
  ...targetRange,
19028
- segmentId: (_targetRange$segmentI2 = targetRange.segmentId) !== null && _targetRange$segmentI2 !== void 0 ? _targetRange$segmentI2 : "",
18906
+ segmentId: targetRange.segmentId ?? "",
19029
18907
  collapsed: false
19030
18908
  };
19031
18909
  const afterTableRange = {
19032
18910
  startOffset: latestTarget.moveRange.endOffset,
19033
18911
  endOffset: latestTarget.moveRange.endOffset,
19034
18912
  collapsed: true,
19035
- segmentId: (_targetRange$segmentI3 = targetRange.segmentId) !== null && _targetRange$segmentI3 !== void 0 ? _targetRange$segmentI3 : ""
18913
+ segmentId: targetRange.segmentId ?? ""
19036
18914
  };
19037
18915
  if (commandId === DocCopyCommand.id || commandId === DocCopyCommand.name) {
19038
18916
  await docClipboardService.copy(_univerjs_core.SliceBodyType.copy, [tableRange]);
@@ -19103,53 +18981,29 @@ function getSectionColumnCount(section) {
19103
18981
  return ((_section$columnProper = section.columnProperties) === null || _section$columnProper === void 0 ? void 0 : _section$columnProper.length) || 1;
19104
18982
  }
19105
18983
  function getSectionColumnGap(section) {
19106
- var _section$columnProper2, _section$columnProper3;
19107
- return (_section$columnProper2 = (_section$columnProper3 = section.columnProperties) === null || _section$columnProper3 === void 0 || (_section$columnProper3 = _section$columnProper3[0]) === null || _section$columnProper3 === void 0 ? void 0 : _section$columnProper3.paddingEnd) !== null && _section$columnProper2 !== void 0 ? _section$columnProper2 : DEFAULT_SECTION_COLUMN_GAP;
18984
+ var _section$columnProper2;
18985
+ return ((_section$columnProper2 = section.columnProperties) === null || _section$columnProper2 === void 0 || (_section$columnProper2 = _section$columnProper2[0]) === null || _section$columnProper2 === void 0 ? void 0 : _section$columnProper2.paddingEnd) ?? DEFAULT_SECTION_COLUMN_GAP;
19108
18986
  }
19109
18987
  function getSectionSettingValues(sections, documentStyle) {
19110
18988
  return {
19111
18989
  columnCount: getCommonValue(sections.map(getSectionColumnCount)),
19112
18990
  columnGap: getCommonValue(sections.map(getSectionColumnGap)),
19113
- separatorType: getCommonValue(sections.map((section) => {
19114
- var _section$columnSepara;
19115
- return (_section$columnSepara = section.columnSeparatorType) !== null && _section$columnSepara !== void 0 ? _section$columnSepara : _univerjs_core.ColumnSeparatorType.NONE;
19116
- })),
19117
- sectionType: getCommonValue(sections.map((section) => {
19118
- var _section$sectionType;
19119
- return (_section$sectionType = section.sectionType) !== null && _section$sectionType !== void 0 ? _section$sectionType : _univerjs_core.SectionType.SECTION_TYPE_UNSPECIFIED;
19120
- })),
18991
+ separatorType: getCommonValue(sections.map((section) => section.columnSeparatorType ?? _univerjs_core.ColumnSeparatorType.NONE)),
18992
+ sectionType: getCommonValue(sections.map((section) => section.sectionType ?? _univerjs_core.SectionType.SECTION_TYPE_UNSPECIFIED)),
19121
18993
  pageWidth: getCommonValue(sections.map((section) => {
19122
- var _section$pageSize$wid, _section$pageSize, _documentStyle$pageSi;
19123
- return (_section$pageSize$wid = (_section$pageSize = section.pageSize) === null || _section$pageSize === void 0 ? void 0 : _section$pageSize.width) !== null && _section$pageSize$wid !== void 0 ? _section$pageSize$wid : (_documentStyle$pageSi = documentStyle.pageSize) === null || _documentStyle$pageSi === void 0 ? void 0 : _documentStyle$pageSi.width;
18994
+ var _section$pageSize, _documentStyle$pageSi;
18995
+ return ((_section$pageSize = section.pageSize) === null || _section$pageSize === void 0 ? void 0 : _section$pageSize.width) ?? ((_documentStyle$pageSi = documentStyle.pageSize) === null || _documentStyle$pageSi === void 0 ? void 0 : _documentStyle$pageSi.width);
19124
18996
  })),
19125
18997
  pageHeight: getCommonValue(sections.map((section) => {
19126
- var _section$pageSize$hei, _section$pageSize2, _documentStyle$pageSi2;
19127
- return (_section$pageSize$hei = (_section$pageSize2 = section.pageSize) === null || _section$pageSize2 === void 0 ? void 0 : _section$pageSize2.height) !== null && _section$pageSize$hei !== void 0 ? _section$pageSize$hei : (_documentStyle$pageSi2 = documentStyle.pageSize) === null || _documentStyle$pageSi2 === void 0 ? void 0 : _documentStyle$pageSi2.height;
19128
- })),
19129
- pageOrient: getCommonValue(sections.map((section) => {
19130
- var _section$pageOrient;
19131
- return (_section$pageOrient = section.pageOrient) !== null && _section$pageOrient !== void 0 ? _section$pageOrient : documentStyle.pageOrient;
19132
- })),
19133
- marginTop: getCommonValue(sections.map((section) => {
19134
- var _ref, _section$marginTop;
19135
- return (_ref = (_section$marginTop = section.marginTop) !== null && _section$marginTop !== void 0 ? _section$marginTop : documentStyle.marginTop) !== null && _ref !== void 0 ? _ref : 0;
19136
- })),
19137
- marginBottom: getCommonValue(sections.map((section) => {
19138
- var _ref2, _section$marginBottom;
19139
- return (_ref2 = (_section$marginBottom = section.marginBottom) !== null && _section$marginBottom !== void 0 ? _section$marginBottom : documentStyle.marginBottom) !== null && _ref2 !== void 0 ? _ref2 : 0;
19140
- })),
19141
- marginLeft: getCommonValue(sections.map((section) => {
19142
- var _ref3, _section$marginLeft;
19143
- return (_ref3 = (_section$marginLeft = section.marginLeft) !== null && _section$marginLeft !== void 0 ? _section$marginLeft : documentStyle.marginLeft) !== null && _ref3 !== void 0 ? _ref3 : 0;
19144
- })),
19145
- marginRight: getCommonValue(sections.map((section) => {
19146
- var _ref4, _section$marginRight;
19147
- return (_ref4 = (_section$marginRight = section.marginRight) !== null && _section$marginRight !== void 0 ? _section$marginRight : documentStyle.marginRight) !== null && _ref4 !== void 0 ? _ref4 : 0;
18998
+ var _section$pageSize2, _documentStyle$pageSi2;
18999
+ return ((_section$pageSize2 = section.pageSize) === null || _section$pageSize2 === void 0 ? void 0 : _section$pageSize2.height) ?? ((_documentStyle$pageSi2 = documentStyle.pageSize) === null || _documentStyle$pageSi2 === void 0 ? void 0 : _documentStyle$pageSi2.height);
19148
19000
  })),
19149
- pageNumberStart: getCommonValue(sections.map((section) => {
19150
- var _ref5, _section$pageNumberSt;
19151
- return (_ref5 = (_section$pageNumberSt = section.pageNumberStart) !== null && _section$pageNumberSt !== void 0 ? _section$pageNumberSt : documentStyle.pageNumberStart) !== null && _ref5 !== void 0 ? _ref5 : 1;
19152
- }))
19001
+ pageOrient: getCommonValue(sections.map((section) => section.pageOrient ?? documentStyle.pageOrient)),
19002
+ marginTop: getCommonValue(sections.map((section) => section.marginTop ?? documentStyle.marginTop ?? 0)),
19003
+ marginBottom: getCommonValue(sections.map((section) => section.marginBottom ?? documentStyle.marginBottom ?? 0)),
19004
+ marginLeft: getCommonValue(sections.map((section) => section.marginLeft ?? documentStyle.marginLeft ?? 0)),
19005
+ marginRight: getCommonValue(sections.map((section) => section.marginRight ?? documentStyle.marginRight ?? 0)),
19006
+ pageNumberStart: getCommonValue(sections.map((section) => section.pageNumberStart ?? documentStyle.pageNumberStart ?? 1))
19153
19007
  };
19154
19008
  }
19155
19009
  function createSectionColumnUpdates(sections, documentStyle, change) {
@@ -19164,9 +19018,8 @@ function createSectionColumnUpdates(sections, documentStyle, change) {
19164
19018
  }
19165
19019
  function createSectionOrientationUpdates(sections, documentStyle, pageOrient) {
19166
19020
  return sections.map((section) => {
19167
- var _ref6, _section$pageOrient2, _section$pageSize3;
19168
- const currentOrient = (_ref6 = (_section$pageOrient2 = section.pageOrient) !== null && _section$pageOrient2 !== void 0 ? _section$pageOrient2 : documentStyle.pageOrient) !== null && _ref6 !== void 0 ? _ref6 : _univerjs_core.PageOrientType.PORTRAIT;
19169
- const currentPageSize = (_section$pageSize3 = section.pageSize) !== null && _section$pageSize3 !== void 0 ? _section$pageSize3 : documentStyle.pageSize;
19021
+ const currentOrient = section.pageOrient ?? documentStyle.pageOrient ?? _univerjs_core.PageOrientType.PORTRAIT;
19022
+ const currentPageSize = section.pageSize ?? documentStyle.pageSize;
19170
19023
  return {
19171
19024
  sectionId: section.sectionId,
19172
19025
  config: {
@@ -19198,7 +19051,6 @@ function navigateToSection(controller, documentDataModel, sections, sectionId) {
19198
19051
  controller.navigateToSectionEnd(documentDataModel.getUnitId(), index === 0 ? 0 : sections[index - 1].startIndex + 1, sections[index].startIndex);
19199
19052
  }
19200
19053
  function useSectionSetting() {
19201
- var _documentDataModel$ge;
19202
19054
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
19203
19055
  const instanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
19204
19056
  const selectionManager = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocSelectionManagerService);
@@ -19206,7 +19058,7 @@ function useSectionSetting() {
19206
19058
  const documentDataModel = (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => instanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC), [instanceService]));
19207
19059
  const resolveSections = () => (documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getDocumentStyle().documentFlavor) === _univerjs_core.DocumentFlavor.TRADITIONAL ? getSelectedSections(documentDataModel, selectionManager.getDocRanges()) : [];
19208
19060
  const sections = (0, _univerjs_ui.useObservable)(documentDataModel ? () => (0, rxjs.combineLatest)([selectionManager.textSelection$.pipe((0, rxjs.startWith)(void 0)), documentDataModel.change$.pipe((0, rxjs.startWith)(void 0))]).pipe((0, rxjs.map)(resolveSections)) : null, resolveSections(), false, [documentDataModel, selectionManager]);
19209
- const documentStyle = (_documentDataModel$ge = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getDocumentStyle()) !== null && _documentDataModel$ge !== void 0 ? _documentDataModel$ge : {};
19061
+ const documentStyle = (documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getDocumentStyle()) ?? {};
19210
19062
  const values = getSectionSettingValues(sections, documentStyle);
19211
19063
  const body = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getBody();
19212
19064
  const allSections = (documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getDocumentStyle().documentFlavor) === _univerjs_core.DocumentFlavor.TRADITIONAL && body ? (0, _univerjs_docs.getTopLevelSectionBreaks)(body) : [];
@@ -19231,7 +19083,7 @@ function useSectionSetting() {
19231
19083
  selectedSectionId: sections.length === 1 ? sections[0].sectionId : void 0,
19232
19084
  ...values,
19233
19085
  selectSection(sectionId) {
19234
- navigateToSection(controller, documentDataModel !== null && documentDataModel !== void 0 ? documentDataModel : void 0, allSections, sectionId);
19086
+ navigateToSection(controller, documentDataModel ?? void 0, allSections, sectionId);
19235
19087
  },
19236
19088
  setColumnCount(value) {
19237
19089
  const next = Math.max(1, Math.round(value));
@@ -19304,7 +19156,6 @@ function SettingRow(props) {
19304
19156
  });
19305
19157
  }
19306
19158
  function SectionSetting() {
19307
- var _setting$selectedSect;
19308
19159
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
19309
19160
  const controller = (0, _univerjs_ui.useDependency)(DocSectionSettingController);
19310
19161
  const setting = useSectionSetting();
@@ -19325,7 +19176,7 @@ function SectionSetting() {
19325
19176
  label: localeService.t("docs-ui.doc.slider.sectionSetting"),
19326
19177
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
19327
19178
  className: "univer-w-full",
19328
- value: (_setting$selectedSect = setting.selectedSectionId) !== null && _setting$selectedSect !== void 0 ? _setting$selectedSect : "",
19179
+ value: setting.selectedSectionId ?? "",
19329
19180
  options: [...setting.selectedSectionId == null ? [{
19330
19181
  label: localeService.t("docs-ui.doc.sectionSetting.multipleValues"),
19331
19182
  value: "",
@@ -19884,11 +19735,10 @@ const COLLAB_CURSOR_LABEL_MAX_WIDTH = 200;
19884
19735
  const COLLAB_CURSOR_LABEL_TEXT_PADDING_LR = 6;
19885
19736
  const COLLAB_CURSOR_LABEL_TEXT_PADDING_TB = 4;
19886
19737
  function drawBubble(ctx, props) {
19887
- var _radius, _width, _height;
19888
19738
  let { radius, width, height } = props;
19889
- radius = (_radius = radius) !== null && _radius !== void 0 ? _radius : 0;
19890
- width = (_width = width) !== null && _width !== void 0 ? _width : 30;
19891
- height = (_height = height) !== null && _height !== void 0 ? _height : 30;
19739
+ radius = radius ?? 0;
19740
+ width = width ?? 30;
19741
+ height = height ?? 30;
19892
19742
  let bottomRight = 0;
19893
19743
  bottomRight = Math.min(radius, width / 2, height / 2);
19894
19744
  ctx.beginPath();
@@ -19985,7 +19835,7 @@ function checkCreateHeaderFooterType(viewModel, editArea, segmentPage, page) {
19985
19835
  const [headerFooterId, createType] = useFirstPageHeaderFooter === _univerjs_core.BooleanNumber.TRUE && isFirstPage ? variants.first : evenAndOddHeaders === _univerjs_core.BooleanNumber.TRUE && isEvenPage ? variants.even : variants.default;
19986
19836
  return {
19987
19837
  createType: headerFooterId ? null : createType,
19988
- headerFooterId: headerFooterId !== null && headerFooterId !== void 0 ? headerFooterId : null,
19838
+ headerFooterId: headerFooterId ?? null,
19989
19839
  sectionId
19990
19840
  };
19991
19841
  }
@@ -20236,18 +20086,14 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
20236
20086
  if (!updateCommandList.includes(command.id)) return;
20237
20087
  const param = command.params;
20238
20088
  switch (command.id) {
20239
- case MoveCursorOperation.id:
20240
- var _param$granularity;
20241
- return this._handleMoveCursor(param.direction, (_param$granularity = param.granularity) !== null && _param$granularity !== void 0 ? _param$granularity : "character");
20242
- case MoveSelectionOperation.id:
20243
- var _param$granularity2;
20244
- return this._handleShiftMoveSelection(param.direction, (_param$granularity2 = param.granularity) !== null && _param$granularity2 !== void 0 ? _param$granularity2 : "character");
20089
+ case MoveCursorOperation.id: return this._handleMoveCursor(param.direction, param.granularity ?? "character");
20090
+ case MoveSelectionOperation.id: return this._handleShiftMoveSelection(param.direction, param.granularity ?? "character");
20245
20091
  default: throw new Error("Unknown command");
20246
20092
  }
20247
20093
  }));
20248
20094
  }
20249
20095
  _handleShiftMoveSelection(direction, granularity = "character") {
20250
- var _docDataModel$getSelf, _body$dataStream$leng, _docDataModel$getCust;
20096
+ var _docDataModel$getSelf;
20251
20097
  const activeRange = this._textSelectionManagerService.getActiveTextRange();
20252
20098
  const allRanges = this._textSelectionManagerService.getTextRanges();
20253
20099
  const docDataModel = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
@@ -20257,8 +20103,8 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
20257
20103
  const docObject = currentRender ? neoGetDocObject(currentRender) : null;
20258
20104
  if (activeRange == null || skeleton == null || docObject == null) return;
20259
20105
  const { startOffset, endOffset, style, collapsed, direction: rangeDirection, segmentId, startNodePosition, endNodePosition, segmentPage } = activeRange;
20260
- const normalizedSegmentId = segmentId !== null && segmentId !== void 0 ? segmentId : "";
20261
- const normalizedSegmentPage = segmentPage !== null && segmentPage !== void 0 ? segmentPage : -1;
20106
+ const normalizedSegmentId = segmentId ?? "";
20107
+ const normalizedSegmentPage = segmentPage ?? -1;
20262
20108
  if (allRanges.length > 1) {
20263
20109
  let min = Number.POSITIVE_INFINITY;
20264
20110
  let max = Number.NEGATIVE_INFINITY;
@@ -20277,8 +20123,8 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
20277
20123
  let focusOffset = collapsed ? endOffset : rangeDirection === _univerjs_core.RANGE_DIRECTION.FORWARD ? endOffset : startOffset;
20278
20124
  const body = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(normalizedSegmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
20279
20125
  if (body == null) return;
20280
- const dataStreamLength = (_body$dataStream$leng = body.dataStream.length) !== null && _body$dataStream$leng !== void 0 ? _body$dataStream$leng : Number.POSITIVE_INFINITY;
20281
- const customRanges = (_docDataModel$getCust = docDataModel.getCustomRanges()) !== null && _docDataModel$getCust !== void 0 ? _docDataModel$getCust : [];
20126
+ const dataStreamLength = body.dataStream.length ?? Number.POSITIVE_INFINITY;
20127
+ const customRanges = docDataModel.getCustomRanges() ?? [];
20282
20128
  if (granularity !== "character") {
20283
20129
  const nextOffset = this._getCursorOffsetByGranularity(skeleton, focusOffset, direction, granularity, normalizedSegmentId, normalizedSegmentPage, dataStreamLength, body.dataStream);
20284
20130
  if (nextOffset == null || nextOffset === focusOffset) return;
@@ -20293,10 +20139,9 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
20293
20139
  return;
20294
20140
  }
20295
20141
  if (direction === _univerjs_core.Direction.LEFT || direction === _univerjs_core.Direction.RIGHT) {
20296
- var _preGlyph$count;
20297
20142
  const preGlyph = skeleton.findNodeByCharIndex(focusOffset - 1, segmentId, segmentPage);
20298
20143
  const curGlyph = skeleton.findNodeByCharIndex(focusOffset, segmentId, segmentPage);
20299
- focusOffset = direction === _univerjs_core.Direction.RIGHT ? focusOffset + curGlyph.count : focusOffset - ((_preGlyph$count = preGlyph === null || preGlyph === void 0 ? void 0 : preGlyph.count) !== null && _preGlyph$count !== void 0 ? _preGlyph$count : 0);
20144
+ focusOffset = direction === _univerjs_core.Direction.RIGHT ? focusOffset + curGlyph.count : focusOffset - ((preGlyph === null || preGlyph === void 0 ? void 0 : preGlyph.count) ?? 0);
20300
20145
  focusOffset = Math.min(dataStreamLength - 2, Math.max(0, focusOffset));
20301
20146
  this._textSelectionManagerService.replaceDocRanges([{
20302
20147
  startOffset: anchorOffset,
@@ -20331,7 +20176,7 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
20331
20176
  }
20332
20177
  }
20333
20178
  _handleMoveCursor(direction, granularity = "character") {
20334
- var _docDataModel$getSelf2, _body$dataStream$leng2, _docDataModel$getCust2;
20179
+ var _docDataModel$getSelf2;
20335
20180
  const activeRange = this._textSelectionManagerService.getActiveTextRange();
20336
20181
  const allRanges = this._textSelectionManagerService.getTextRanges();
20337
20182
  const docDataModel = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
@@ -20341,12 +20186,12 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
20341
20186
  const docObject = currentRender ? neoGetDocObject(currentRender) : null;
20342
20187
  if (activeRange == null || skeleton == null || docObject == null || allRanges == null) return;
20343
20188
  const { startOffset, endOffset, style, collapsed, segmentId, startNodePosition, endNodePosition, segmentPage } = activeRange;
20344
- const normalizedSegmentId = segmentId !== null && segmentId !== void 0 ? segmentId : "";
20345
- const normalizedSegmentPage = segmentPage !== null && segmentPage !== void 0 ? segmentPage : -1;
20189
+ const normalizedSegmentId = segmentId ?? "";
20190
+ const normalizedSegmentPage = segmentPage ?? -1;
20346
20191
  const body = (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(normalizedSegmentId)) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.getBody();
20347
20192
  if (body == null) return;
20348
- const dataStreamLength = (_body$dataStream$leng2 = body.dataStream.length) !== null && _body$dataStream$leng2 !== void 0 ? _body$dataStream$leng2 : Number.POSITIVE_INFINITY;
20349
- const customRanges = (_docDataModel$getCust2 = docDataModel.getCustomRanges()) !== null && _docDataModel$getCust2 !== void 0 ? _docDataModel$getCust2 : [];
20193
+ const dataStreamLength = body.dataStream.length ?? Number.POSITIVE_INFINITY;
20194
+ const customRanges = docDataModel.getCustomRanges() ?? [];
20350
20195
  if (granularity !== "character") {
20351
20196
  let cursorOffset;
20352
20197
  if (!activeRange.collapsed || allRanges.length > 1) {
@@ -20384,10 +20229,8 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
20384
20229
  const preSpan = skeleton.findNodeByCharIndex(startOffset - 1, segmentId, segmentPage);
20385
20230
  const curSpan = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage);
20386
20231
  const nextGlyph = skeleton.findNodeByCharIndex(startOffset + 1, segmentId, segmentPage);
20387
- if (direction === _univerjs_core.Direction.LEFT) {
20388
- var _preSpan$count;
20389
- cursor = Math.max(0, startOffset - ((_preSpan$count = preSpan === null || preSpan === void 0 ? void 0 : preSpan.count) !== null && _preSpan$count !== void 0 ? _preSpan$count : 1));
20390
- } else cursor = Math.min(dataStreamLength - 2, endOffset + curSpan.count + ((nextGlyph === null || nextGlyph === void 0 ? void 0 : nextGlyph.streamType) === _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK ? 1 : 0));
20232
+ if (direction === _univerjs_core.Direction.LEFT) cursor = Math.max(0, startOffset - ((preSpan === null || preSpan === void 0 ? void 0 : preSpan.count) ?? 1));
20233
+ else cursor = Math.min(dataStreamLength - 2, endOffset + curSpan.count + ((nextGlyph === null || nextGlyph === void 0 ? void 0 : nextGlyph.streamType) === _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK ? 1 : 0));
20391
20234
  }
20392
20235
  const skipTokens = [...this._getCursorSkipTokens()];
20393
20236
  if (direction === _univerjs_core.Direction.LEFT) while (skipTokens.includes(body.dataStream[cursor])) cursor--;
@@ -20458,9 +20301,8 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
20458
20301
  return 0;
20459
20302
  }
20460
20303
  _getWordBoundaryOffset(skeleton, focusOffset, direction, segmentId, segmentPage, dataStreamLength) {
20461
- var _skeleton$findNodeByC;
20462
20304
  if (direction !== _univerjs_core.Direction.LEFT && direction !== _univerjs_core.Direction.RIGHT) return;
20463
- const glyph = (_skeleton$findNodeByC = skeleton.findNodeByCharIndex(focusOffset, segmentId, segmentPage)) !== null && _skeleton$findNodeByC !== void 0 ? _skeleton$findNodeByC : skeleton.findNodeByCharIndex(Math.max(0, focusOffset - 1), segmentId, segmentPage);
20305
+ const glyph = skeleton.findNodeByCharIndex(focusOffset, segmentId, segmentPage) ?? skeleton.findNodeByCharIndex(Math.max(0, focusOffset - 1), segmentId, segmentPage);
20464
20306
  if (glyph == null) return direction === _univerjs_core.Direction.LEFT ? 0 : dataStreamLength - 2;
20465
20307
  const paragraphInfo = getParagraphInfoByGlyph(glyph);
20466
20308
  if (paragraphInfo == null) return;
@@ -20470,9 +20312,9 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
20470
20312
  return Math.min(dataStreamLength - 2, Math.max(0, nextOffset));
20471
20313
  }
20472
20314
  _getLineBoundaryOffset(skeleton, focusOffset, direction, segmentId, segmentPage, dataStreamLength) {
20473
- var _skeleton$findNodeByC2, _glyph$parent;
20315
+ var _glyph$parent;
20474
20316
  if (direction !== _univerjs_core.Direction.LEFT && direction !== _univerjs_core.Direction.RIGHT) return;
20475
- const glyph = (_skeleton$findNodeByC2 = skeleton.findNodeByCharIndex(focusOffset, segmentId, segmentPage)) !== null && _skeleton$findNodeByC2 !== void 0 ? _skeleton$findNodeByC2 : skeleton.findNodeByCharIndex(Math.max(0, focusOffset - 1), segmentId, segmentPage);
20317
+ const glyph = skeleton.findNodeByCharIndex(focusOffset, segmentId, segmentPage) ?? skeleton.findNodeByCharIndex(Math.max(0, focusOffset - 1), segmentId, segmentPage);
20476
20318
  const line = glyph === null || glyph === void 0 || (_glyph$parent = glyph.parent) === null || _glyph$parent === void 0 ? void 0 : _glyph$parent.parent;
20477
20319
  if (line == null) return direction === _univerjs_core.Direction.LEFT ? 0 : dataStreamLength - 2;
20478
20320
  const boundaryGlyph = direction === _univerjs_core.Direction.LEFT ? this._getFirstCursorGlyphInLine(line) : this._getLastCursorGlyphInLine(line);
@@ -20582,7 +20424,6 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
20582
20424
  return divideLeft + left;
20583
20425
  }
20584
20426
  _matchPositionByLeftOffset(docSkeleton, line, offsetLeft, nodePosition) {
20585
- var _nearestNode$glyph;
20586
20427
  const nearestNode = { distance: Number.POSITIVE_INFINITY };
20587
20428
  const nearestEmptyParagraphNode = { distance: Number.POSITIVE_INFINITY };
20588
20429
  for (const divide of line.divides) {
@@ -20609,7 +20450,7 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
20609
20450
  }
20610
20451
  }
20611
20452
  }
20612
- const nearestGlyph = (_nearestNode$glyph = nearestNode.glyph) !== null && _nearestNode$glyph !== void 0 ? _nearestNode$glyph : nearestEmptyParagraphNode.glyph;
20453
+ const nearestGlyph = nearestNode.glyph ?? nearestEmptyParagraphNode.glyph;
20613
20454
  if (nearestGlyph == null) return;
20614
20455
  const { segmentPage } = nodePosition;
20615
20456
  return docSkeleton.findPositionByGlyph(nearestGlyph, segmentPage);
@@ -20764,10 +20605,10 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
20764
20605
  }
20765
20606
  }
20766
20607
  _findLineAroundTable(table, direction) {
20767
- var _pages, _tablePage$parent;
20608
+ var _tablePage$parent;
20768
20609
  const tablePage = table.parent;
20769
20610
  if (tablePage == null) return;
20770
- const pages = (_pages = (_tablePage$parent = tablePage.parent) === null || _tablePage$parent === void 0 ? void 0 : _tablePage$parent.pages) !== null && _pages !== void 0 ? _pages : [tablePage];
20611
+ const pages = ((_tablePage$parent = tablePage.parent) === null || _tablePage$parent === void 0 ? void 0 : _tablePage$parent.pages) ?? [tablePage];
20771
20612
  const lineMatcher = direction ? (line) => line.st === table.ed + 1 : (line) => line.ed === table.st - 1;
20772
20613
  for (const page of pages) for (const section of page.sections) for (const column of section.columns) {
20773
20614
  const line = (direction ? column.lines : [...column.lines].reverse()).find(lineMatcher);
@@ -20781,14 +20622,12 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
20781
20622
  return Math.min(Math.abs(offsetLeft - left), Math.abs(offsetLeft - right));
20782
20623
  }
20783
20624
  _getTableCellHostOffsetLeft(cell) {
20784
- var _table$left, _cell$left, _cell$marginLeft;
20785
20625
  const row = cell.parent;
20786
20626
  const table = row === null || row === void 0 ? void 0 : row.parent;
20787
- return ((_table$left = table === null || table === void 0 ? void 0 : table.left) !== null && _table$left !== void 0 ? _table$left : 0) + ((_cell$left = cell.left) !== null && _cell$left !== void 0 ? _cell$left : 0) + ((_cell$marginLeft = cell.marginLeft) !== null && _cell$marginLeft !== void 0 ? _cell$marginLeft : 0);
20627
+ return ((table === null || table === void 0 ? void 0 : table.left) ?? 0) + (cell.left ?? 0) + (cell.marginLeft ?? 0);
20788
20628
  }
20789
20629
  _getTableCellContentWidth(cell) {
20790
- var _cell$pageWidth, _cell$marginLeft2, _cell$marginRight;
20791
- return Math.max(0, ((_cell$pageWidth = cell.pageWidth) !== null && _cell$pageWidth !== void 0 ? _cell$pageWidth : 0) - ((_cell$marginLeft2 = cell.marginLeft) !== null && _cell$marginLeft2 !== void 0 ? _cell$marginLeft2 : 0) - ((_cell$marginRight = cell.marginRight) !== null && _cell$marginRight !== void 0 ? _cell$marginRight : 0));
20630
+ return Math.max(0, (cell.pageWidth ?? 0) - (cell.marginLeft ?? 0) - (cell.marginRight ?? 0));
20792
20631
  }
20793
20632
  _isTableCellContentPage(page) {
20794
20633
  var _table$rows;
@@ -20829,8 +20668,8 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
20829
20668
  };
20830
20669
  }
20831
20670
  _findColumnGroupByBlockLine(page, line) {
20832
- var _page$skeColumnGroups, _page$skeColumnGroups2;
20833
- for (const columnGroup of (_page$skeColumnGroups = (_page$skeColumnGroups2 = page.skeColumnGroups) === null || _page$skeColumnGroups2 === void 0 ? void 0 : _page$skeColumnGroups2.values()) !== null && _page$skeColumnGroups !== void 0 ? _page$skeColumnGroups : []) if (line.paragraphIndex === columnGroup.ed || line.st <= columnGroup.ed && line.ed >= columnGroup.st) return columnGroup;
20671
+ var _page$skeColumnGroups;
20672
+ for (const columnGroup of ((_page$skeColumnGroups = page.skeColumnGroups) === null || _page$skeColumnGroups === void 0 ? void 0 : _page$skeColumnGroups.values()) ?? []) if (line.paragraphIndex === columnGroup.ed || line.st <= columnGroup.ed && line.ed >= columnGroup.st) return columnGroup;
20834
20673
  }
20835
20674
  _findColumnGroupBlockLine(columnGroup) {
20836
20675
  const page = columnGroup.parent;
@@ -20989,7 +20828,7 @@ let DocClipboardController = class DocClipboardController extends _univerjs_core
20989
20828
  _initLegacyPasteCommand() {
20990
20829
  var _this$_docSelectionRe;
20991
20830
  (_this$_docSelectionRe = this._docSelectionRenderService) === null || _this$_docSelectionRe === void 0 || _this$_docSelectionRe.onPaste$.pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((config) => {
20992
- var _clipboardEvent$clipb, _clipboardEvent$clipb2, _clipboardEvent$clipb3, _clipboardEvent$clipb4, _htmlContent;
20831
+ var _clipboardEvent$clipb, _clipboardEvent$clipb2, _clipboardEvent$clipb3, _clipboardEvent$clipb4;
20993
20832
  if (!whenDocOrEditor(this._contextService)) return;
20994
20833
  config.event.preventDefault();
20995
20834
  const clipboardEvent = config.event;
@@ -20997,7 +20836,7 @@ let DocClipboardController = class DocClipboardController extends _univerjs_core
20997
20836
  const internalJson = (_clipboardEvent$clipb2 = clipboardEvent.clipboardData) === null || _clipboardEvent$clipb2 === void 0 ? void 0 : _clipboardEvent$clipb2.getData("application/x-doc-fragment+json");
20998
20837
  const textContent = (_clipboardEvent$clipb3 = clipboardEvent.clipboardData) === null || _clipboardEvent$clipb3 === void 0 ? void 0 : _clipboardEvent$clipb3.getData(_univerjs_ui.PLAIN_TEXT_CLIPBOARD_MIME_TYPE);
20999
20838
  const files = [...((_clipboardEvent$clipb4 = clipboardEvent.clipboardData) === null || _clipboardEvent$clipb4 === void 0 ? void 0 : _clipboardEvent$clipb4.items) || []].filter((item) => _univerjs_ui.imageMimeTypeSet.has(item.type)).map((item) => item.getAsFile()).filter((e) => !!e);
21000
- if (!!this._editorService.getEditor(this._context.unitId) && ((_htmlContent = htmlContent) !== null && _htmlContent !== void 0 ? _htmlContent : "").indexOf("</table>") > -1) htmlContent = "";
20839
+ if (!!this._editorService.getEditor(this._context.unitId) && (htmlContent ?? "").indexOf("</table>") > -1) htmlContent = "";
21001
20840
  this._docClipboardService.legacyPaste({
21002
20841
  html: htmlContent,
21003
20842
  internalJson,
@@ -21055,10 +20894,10 @@ let DocContextMenuRenderController = class DocContextMenuRenderController extend
21055
20894
  }));
21056
20895
  }
21057
20896
  _isSelectionInCodeBlock() {
21058
- var _documentDataModel$ge, _documentDataModel$ge2, _this$_docSelectionMa;
20897
+ var _documentDataModel$ge;
21059
20898
  const documentDataModel = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
21060
- const blockRanges = (_documentDataModel$ge = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge2 = documentDataModel.getBody()) === null || _documentDataModel$ge2 === void 0 || (_documentDataModel$ge2 = _documentDataModel$ge2.blockRanges) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.filter((range) => range.blockType === _univerjs_core.DocumentBlockRangeType.CODE)) !== null && _documentDataModel$ge !== void 0 ? _documentDataModel$ge : [];
21061
- const textRanges = (_this$_docSelectionMa = this._docSelectionManagerService.getTextRanges()) !== null && _this$_docSelectionMa !== void 0 ? _this$_docSelectionMa : [];
20899
+ const blockRanges = (documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getBody()) === null || _documentDataModel$ge === void 0 || (_documentDataModel$ge = _documentDataModel$ge.blockRanges) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.filter((range) => range.blockType === _univerjs_core.DocumentBlockRangeType.CODE)) ?? [];
20900
+ const textRanges = this._docSelectionManagerService.getTextRanges() ?? [];
21062
20901
  if (!blockRanges.length || !textRanges.length) return false;
21063
20902
  return blockRanges.some((blockRange) => textRanges.some((range) => isRangeIntersectingBlock(range, blockRange.startIndex, blockRange.endIndex)));
21064
20903
  }
@@ -21321,7 +21160,7 @@ let DocInputController = class DocInputController extends _univerjs_core.Disposa
21321
21160
  }
21322
21161
  _initialNormalInput() {
21323
21162
  this._onInputSubscription = this._docSelectionRenderService.onInput$.subscribe(async (config) => {
21324
- var _docDataModel$getSelf, _originBody$customRan, _originBody$customDec;
21163
+ var _docDataModel$getSelf;
21325
21164
  if (config == null) return;
21326
21165
  const { unitId } = this._context;
21327
21166
  const { event, content = "", activeRange } = config;
@@ -21335,9 +21174,9 @@ let DocInputController = class DocInputController extends _univerjs_core.Disposa
21335
21174
  if (!originBody) return;
21336
21175
  const defaultTextStyle = this._docMenuStyleService.getDefaultStyle();
21337
21176
  const cacheStyle = this._docMenuStyleService.getStyleCache();
21338
- const curCustomRange = getCustomRangeAtPosition((_originBody$customRan = originBody === null || originBody === void 0 ? void 0 : originBody.customRanges) !== null && _originBody$customRan !== void 0 ? _originBody$customRan : [], activeRange.endOffset, _univerjs_core.SHEET_EDITOR_UNITS.includes(unitId));
21177
+ const curCustomRange = getCustomRangeAtPosition((originBody === null || originBody === void 0 ? void 0 : originBody.customRanges) ?? [], activeRange.endOffset, _univerjs_core.SHEET_EDITOR_UNITS.includes(unitId));
21339
21178
  const curTextRun = getTextRunAtPosition(originBody, activeRange.endOffset, defaultTextStyle, cacheStyle, _univerjs_core.SHEET_EDITOR_UNITS.includes(unitId));
21340
- const curCustomDecorations = getCustomDecorationAtPosition((_originBody$customDec = originBody === null || originBody === void 0 ? void 0 : originBody.customDecorations) !== null && _originBody$customDec !== void 0 ? _originBody$customDec : [], activeRange.endOffset);
21179
+ const curCustomDecorations = getCustomDecorationAtPosition((originBody === null || originBody === void 0 ? void 0 : originBody.customDecorations) ?? [], activeRange.endOffset);
21341
21180
  await this._commandService.executeCommand(_univerjs_docs.InsertTextCommand.id, {
21342
21181
  unitId,
21343
21182
  body: {
@@ -21465,11 +21304,12 @@ let DocSelectionRenderController = class DocSelectionRenderController extends _u
21465
21304
  scene.resetCursor();
21466
21305
  }));
21467
21306
  this.disposeWithMe(document.onPointerDown$.subscribeEvent((evt, state) => {
21307
+ var _this$_editorService$;
21468
21308
  if (this._isEditorReadOnly(unitId)) return;
21469
21309
  if (this._isEmbedInteractionEvent(evt, unitId)) return;
21470
21310
  const docDataModel = this._instanceSrv.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
21471
21311
  if ((docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getUnitId()) !== unitId) this._instanceSrv.setCurrentUnitForType(unitId);
21472
- this._instanceSrv.focusUnit(unitId);
21312
+ if (!((_this$_editorService$ = this._editorService.getEditorRenderConfig(unitId)) === null || _this$_editorService$ === void 0 ? void 0 : _this$_editorService$.preserveHostFocus)) this._instanceSrv.focusUnit(unitId);
21473
21313
  const skeleton = this._docSkeletonManagerService.getSkeleton();
21474
21314
  const { offsetX, offsetY } = evt;
21475
21315
  const coord = this._getTransformCoordForDocumentOffset(offsetX, offsetY);
@@ -21803,10 +21643,7 @@ let DocsRenderService = class DocsRenderService extends _univerjs_core.RxDisposa
21803
21643
  this._init();
21804
21644
  }
21805
21645
  _init() {
21806
- this._instanceSrv.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_DOC).forEach((documentModel) => {
21807
- var _this$_instanceSrv$ge;
21808
- return this._createRenderer(documentModel, (_this$_instanceSrv$ge = this._instanceSrv.getUnitCreateOptions(documentModel.getUnitId())) !== null && _this$_instanceSrv$ge !== void 0 ? _this$_instanceSrv$ge : void 0);
21809
- });
21646
+ this._instanceSrv.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_DOC).forEach((documentModel) => this._createRenderer(documentModel, this._instanceSrv.getUnitCreateOptions(documentModel.getUnitId()) ?? void 0));
21810
21647
  this._instanceSrv.getTypeOfUnitAdded$(_univerjs_core.UniverInstanceType.UNIVER_DOC).pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((event) => this._createRenderer(event.unit, event.options));
21811
21648
  this._instanceSrv.getTypeOfUnitDisposed$(_univerjs_core.UniverInstanceType.UNIVER_DOC).pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((doc) => this._disposeRenderer(doc));
21812
21649
  }
@@ -22246,17 +22083,17 @@ UniverDocsUIPlugin = __decorate([
22246
22083
  //#endregion
22247
22084
  //#region src/views/rich-text-editor/hooks/editor-undo-redo-keyboard.ts
22248
22085
  function isSheetFormulaEditor(editorUnitId, univerInstanceService) {
22249
- var _documentModel$getBod, _documentModel$getBod2;
22086
+ var _documentModel$getBod;
22250
22087
  if (editorUnitId !== _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY && editorUnitId !== _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) return false;
22251
22088
  const documentModel = univerInstanceService.getUnit(editorUnitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
22252
- return (_documentModel$getBod = documentModel === null || documentModel === void 0 || (_documentModel$getBod2 = documentModel.getBody()) === null || _documentModel$getBod2 === void 0 || (_documentModel$getBod2 = _documentModel$getBod2.dataStream) === null || _documentModel$getBod2 === void 0 ? void 0 : _documentModel$getBod2.startsWith("=")) !== null && _documentModel$getBod !== void 0 ? _documentModel$getBod : false;
22089
+ return (documentModel === null || documentModel === void 0 || (_documentModel$getBod = documentModel.getBody()) === null || _documentModel$getBod === void 0 || (_documentModel$getBod = _documentModel$getBod.dataStream) === null || _documentModel$getBod === void 0 ? void 0 : _documentModel$getBod.startsWith("=")) ?? false;
22253
22090
  }
22254
22091
  function executeEditorUndoRedoCommand(options) {
22255
- var _univerInstanceServic, _univerInstanceServic2;
22092
+ var _univerInstanceServic;
22256
22093
  const { commandId, commandService, editorUnitId, univerInstanceService } = options;
22257
22094
  const shouldUseSheetEditorContext = editorUnitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY || editorUnitId === _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY;
22258
22095
  if (isSheetFormulaEditor(editorUnitId, univerInstanceService)) return;
22259
- const previousFocusedUnitId = (_univerInstanceServic = (_univerInstanceServic2 = univerInstanceService.getFocusedUnit()) === null || _univerInstanceServic2 === void 0 ? void 0 : _univerInstanceServic2.getUnitId()) !== null && _univerInstanceServic !== void 0 ? _univerInstanceServic : null;
22096
+ const previousFocusedUnitId = ((_univerInstanceServic = univerInstanceService.getFocusedUnit()) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId()) ?? null;
22260
22097
  const shouldRestoreFocus = !shouldUseSheetEditorContext && previousFocusedUnitId !== null && previousFocusedUnitId !== editorUnitId;
22261
22098
  if (!shouldUseSheetEditorContext && previousFocusedUnitId !== editorUnitId) univerInstanceService.focusUnit(editorUnitId);
22262
22099
  commandService.executeCommand(commandId).finally(() => {
@@ -22284,7 +22121,7 @@ function createEditorUndoRedoKeyboardConfig(options) {
22284
22121
  ...keyCodes
22285
22122
  ],
22286
22123
  handler: (keyCode, metaKey) => {
22287
- switch (`${keyCode}:${metaKey !== null && metaKey !== void 0 ? metaKey : 0}`) {
22124
+ switch (`${keyCode}:${metaKey ?? 0}`) {
22288
22125
  case `${_univerjs_ui.KeyCode.Z}:${ctrlCommand}`:
22289
22126
  executeEditorUndoRedoCommand({
22290
22127
  commandId: _univerjs_core.UndoCommand.id,
@@ -22311,8 +22148,8 @@ function createEditorUndoRedoKeyboardConfig(options) {
22311
22148
  //#endregion
22312
22149
  //#region src/views/rich-text-editor/hooks/use-editor.ts
22313
22150
  function useEditor(opts) {
22314
- const { editorId, initialValue, container, autoFocus: _autoFocus, isSingle, canvasStyle } = opts;
22315
- const autoFocus = (0, react.useMemo)(() => _autoFocus !== null && _autoFocus !== void 0 ? _autoFocus : false, []);
22151
+ const { editorId, initialValue, container, preserveHostFocus, autoFocus: _autoFocus, isSingle, canvasStyle } = opts;
22152
+ const autoFocus = (0, react.useMemo)(() => _autoFocus ?? false, []);
22316
22153
  const [editor, setEditor] = (0, react.useState)();
22317
22154
  const editorService = (0, _univerjs_ui.useDependency)(IEditorService);
22318
22155
  (0, react.useLayoutEffect)(() => {
@@ -22344,14 +22181,15 @@ function useEditor(opts) {
22344
22181
  autofocus: true,
22345
22182
  canvasStyle,
22346
22183
  editorUnitId: editorId,
22347
- initialSnapshot: snapshot
22184
+ initialSnapshot: snapshot,
22185
+ preserveHostFocus
22348
22186
  }, container.current);
22349
22187
  const editor = editorService.getEditor(editorId);
22350
22188
  setEditor(editor);
22351
22189
  if (autoFocus) {
22352
- var _snapshot$body$dataSt, _snapshot$body;
22190
+ var _snapshot$body;
22353
22191
  editorService.focus(editorId);
22354
- const end = ((_snapshot$body$dataSt = (_snapshot$body = snapshot.body) === null || _snapshot$body === void 0 ? void 0 : _snapshot$body.dataStream.length) !== null && _snapshot$body$dataSt !== void 0 ? _snapshot$body$dataSt : 2) - 2;
22192
+ const end = (((_snapshot$body = snapshot.body) === null || _snapshot$body === void 0 ? void 0 : _snapshot$body.dataStream.length) ?? 2) - 2;
22355
22193
  editor.setSelectionRanges([{
22356
22194
  startOffset: end,
22357
22195
  endOffset: end
@@ -22409,11 +22247,10 @@ const useEditorClickOutside = (editorId, containerRef, onClickOutside) => {
22409
22247
  * limitations under the License.
22410
22248
  */
22411
22249
  function useIsFocusing(editorId) {
22412
- var _docSelectionRenderSe;
22413
22250
  const renderer = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService).getRenderUnitById(editorId);
22414
22251
  const docSelectionRenderService = renderer === null || renderer === void 0 ? void 0 : renderer.with(DocSelectionRenderService);
22415
22252
  const selections = (0, _univerjs_ui.useObservable)(docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.textSelectionInner$);
22416
- return Boolean(((_docSelectionRenderSe = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) !== null && _docSelectionRenderSe !== void 0 ? _docSelectionRenderSe : false) && (selections === null || selections === void 0 ? void 0 : selections.textRanges.some((r) => r.collapsed)));
22253
+ return Boolean(((docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) ?? false) && (selections === null || selections === void 0 ? void 0 : selections.textRanges.some((r) => r.collapsed)));
22417
22254
  }
22418
22255
 
22419
22256
  //#endregion
@@ -22554,10 +22391,10 @@ function useOnChange(editor, onChange) {
22554
22391
  if (!editor) return;
22555
22392
  const dispose = commandService.onCommandExecuted((command) => {
22556
22393
  if (command.id === _univerjs_docs.RichTextEditingMutation.id) {
22557
- var _data$body$dataStream, _data$body;
22394
+ var _data$body;
22558
22395
  if (command.params.unitId !== editor.getEditorId()) return;
22559
22396
  const data = editor.getDocumentData();
22560
- onChange(data, (0, _univerjs_core.getPlainText)((_data$body$dataStream = (_data$body = data.body) === null || _data$body === void 0 ? void 0 : _data$body.dataStream) !== null && _data$body$dataStream !== void 0 ? _data$body$dataStream : ""));
22397
+ onChange(data, (0, _univerjs_core.getPlainText)(((_data$body = data.body) === null || _data$body === void 0 ? void 0 : _data$body.dataStream) ?? ""));
22561
22398
  }
22562
22399
  });
22563
22400
  return () => {
@@ -22699,8 +22536,7 @@ const useResize = (editor, isSingle = true, autoScrollbar, autoScroll) => {
22699
22536
  //#endregion
22700
22537
  //#region src/views/RichTextEditor.tsx
22701
22538
  const RichTextEditor = (props) => {
22702
- var _docSelectionRenderSe3;
22703
- const { className, autoFocus, onFocusChange: _onFocusChange, initialValue, onClickOutside: _onClickOutside, keyboardEventConfig, moveCursor = true, style, isSingle, editorId: propsEditorId, onHeightChange, onChange: _onChange, defaultHeight = 32, maxHeight = 32, icon, editorRef, placeholder, noStyle } = props;
22539
+ const { className, autoFocus, onFocusChange: _onFocusChange, initialValue, onClickOutside: _onClickOutside, preserveHostFocus, keyboardEventConfig, moveCursor = true, style, isSingle, editorId: propsEditorId, onHeightChange, onChange: _onChange, defaultHeight = 32, maxHeight = 32, icon, editorRef, placeholder, noStyle } = props;
22704
22540
  (0, _univerjs_ui.useDependency)(IEditorService);
22705
22541
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
22706
22542
  const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
@@ -22708,29 +22544,24 @@ const RichTextEditor = (props) => {
22708
22544
  const onClickOutside = (0, _univerjs_ui.useEvent)(_onClickOutside);
22709
22545
  const [height, setHeight] = (0, react.useState)(defaultHeight);
22710
22546
  const formulaEditorContainerRef = (0, react.useRef)(null);
22711
- const editorId = (0, react.useMemo)(() => propsEditorId !== null && propsEditorId !== void 0 ? propsEditorId : (0, _univerjs_core.createInternalEditorID)(`RICH_TEXT_EDITOR-${(0, _univerjs_core.generateRandomId)(4)}`), [propsEditorId]);
22547
+ const editorId = (0, react.useMemo)(() => propsEditorId ?? (0, _univerjs_core.createInternalEditorID)(`RICH_TEXT_EDITOR-${(0, _univerjs_core.generateRandomId)(4)}`), [propsEditorId]);
22712
22548
  const editor = useEditor({
22713
22549
  editorId,
22714
22550
  initialValue,
22715
22551
  container: formulaEditorContainerRef,
22552
+ preserveHostFocus,
22716
22553
  autoFocus,
22717
22554
  isSingle
22718
22555
  });
22719
22556
  const renderer = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService).getRenderUnitById(editorId);
22720
22557
  const selectionIsFocusing = useIsFocusing(editorId);
22721
22558
  const docSelectionRenderService = renderer === null || renderer === void 0 ? void 0 : renderer.with(DocSelectionRenderService);
22722
- const editorFocused = (0, _univerjs_ui.useObservable)(editor ? () => {
22723
- var _docSelectionRenderSe2;
22724
- return (0, rxjs.merge)(editor.focus$, editor.blur$).pipe((0, rxjs.map)(() => {
22725
- var _docSelectionRenderSe;
22726
- return (_docSelectionRenderSe = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) !== null && _docSelectionRenderSe !== void 0 ? _docSelectionRenderSe : false;
22727
- }), (0, rxjs.startWith)((_docSelectionRenderSe2 = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) !== null && _docSelectionRenderSe2 !== void 0 ? _docSelectionRenderSe2 : false));
22728
- } : null, (_docSelectionRenderSe3 = docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) !== null && _docSelectionRenderSe3 !== void 0 ? _docSelectionRenderSe3 : false, false, [docSelectionRenderService, editor]);
22559
+ const editorFocused = (0, _univerjs_ui.useObservable)(editor ? () => (0, rxjs.merge)(editor.focus$, editor.blur$).pipe((0, rxjs.map)(() => (docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) ?? false), (0, rxjs.startWith)((docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) ?? false)) : null, (docSelectionRenderService === null || docSelectionRenderService === void 0 ? void 0 : docSelectionRenderService.isFocusing) ?? false, false, [docSelectionRenderService, editor]);
22729
22560
  const isFocusing = selectionIsFocusing && editorFocused;
22730
22561
  const sheetEmbeddingRef = (0, react.useRef)(null);
22731
22562
  const resolveShowPlaceholder = () => {
22732
- var _editor$getDocumentDa, _editor$getDocumentDa2;
22733
- return !_univerjs_core.BuildTextUtils.transform.getPlainText((_editor$getDocumentDa = editor === null || editor === void 0 || (_editor$getDocumentDa2 = editor.getDocumentData().body) === null || _editor$getDocumentDa2 === void 0 ? void 0 : _editor$getDocumentDa2.dataStream) !== null && _editor$getDocumentDa !== void 0 ? _editor$getDocumentDa : "");
22563
+ var _editor$getDocumentDa;
22564
+ return !_univerjs_core.BuildTextUtils.transform.getPlainText((editor === null || editor === void 0 || (_editor$getDocumentDa = editor.getDocumentData().body) === null || _editor$getDocumentDa === void 0 ? void 0 : _editor$getDocumentDa.dataStream) ?? "");
22734
22565
  };
22735
22566
  const showPlaceholder = (0, _univerjs_ui.useObservable)(editor ? () => editor.selectionChange$.pipe((0, rxjs.map)(resolveShowPlaceholder), (0, rxjs.startWith)(resolveShowPlaceholder())) : null, resolveShowPlaceholder(), false, [editor]);
22736
22567
  const { checkScrollBar } = useResize(editor, isSingle, true, true);
@@ -22743,20 +22574,20 @@ const RichTextEditor = (props) => {
22743
22574
  editorRef.current = editor;
22744
22575
  }, [editor]);
22745
22576
  const onChange = (0, _univerjs_ui.useEvent)((data) => {
22746
- var _data$body$dataStream, _data$body;
22577
+ var _data$body;
22747
22578
  const docSkeleton = renderer === null || renderer === void 0 ? void 0 : renderer.with(_univerjs_docs.DocSkeletonManagerService);
22748
22579
  const size = docSkeleton === null || docSkeleton === void 0 ? void 0 : docSkeleton.getSkeleton().getActualSize();
22749
22580
  if (size) {
22750
22581
  onHeightChange === null || onHeightChange === void 0 || onHeightChange(size.actualHeight);
22751
22582
  setHeight(Math.max(defaultHeight, Math.min(size.actualHeight + 10, maxHeight)));
22752
22583
  }
22753
- _onChange === null || _onChange === void 0 || _onChange(data, (0, _univerjs_core.getPlainText)((_data$body$dataStream = (_data$body = data.body) === null || _data$body === void 0 ? void 0 : _data$body.dataStream) !== null && _data$body$dataStream !== void 0 ? _data$body$dataStream : ""));
22584
+ _onChange === null || _onChange === void 0 || _onChange(data, (0, _univerjs_core.getPlainText)(((_data$body = data.body) === null || _data$body === void 0 ? void 0 : _data$body.dataStream) ?? ""));
22754
22585
  checkScrollBar();
22755
22586
  });
22756
22587
  (0, react.useEffect)(() => {
22757
- var _data$body$dataStream2, _data$body2;
22588
+ var _data$body2;
22758
22589
  const data = editor === null || editor === void 0 ? void 0 : editor.getDocumentData();
22759
- onFocusChange === null || onFocusChange === void 0 || onFocusChange(isFocusing, (0, _univerjs_core.getPlainText)((_data$body$dataStream2 = data === null || data === void 0 || (_data$body2 = data.body) === null || _data$body2 === void 0 ? void 0 : _data$body2.dataStream) !== null && _data$body$dataStream2 !== void 0 ? _data$body$dataStream2 : ""));
22590
+ onFocusChange === null || onFocusChange === void 0 || onFocusChange(isFocusing, (0, _univerjs_core.getPlainText)((data === null || data === void 0 || (_data$body2 = data.body) === null || _data$body2 === void 0 ? void 0 : _data$body2.dataStream) ?? ""));
22760
22591
  }, [isFocusing, onFocusChange]);
22761
22592
  useEditorClickOutside(editorId, sheetEmbeddingRef, onClickOutside);
22762
22593
  const resolvedKeyboardEventConfig = (0, react.useMemo)(() => createEditorUndoRedoKeyboardConfig({