@univerjs/docs-ui 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/lib/cjs/index.js +1189 -284
  2. package/lib/cjs/locale/ar-SA.js +12 -0
  3. package/lib/cjs/locale/ca-ES.js +12 -0
  4. package/lib/cjs/locale/de-DE.js +12 -0
  5. package/lib/cjs/locale/en-US.js +12 -0
  6. package/lib/cjs/locale/es-ES.js +12 -0
  7. package/lib/cjs/locale/fa-IR.js +12 -0
  8. package/lib/cjs/locale/fr-FR.js +12 -0
  9. package/lib/cjs/locale/id-ID.js +12 -0
  10. package/lib/cjs/locale/it-IT.js +12 -0
  11. package/lib/cjs/locale/ja-JP.js +12 -0
  12. package/lib/cjs/locale/ko-KR.js +12 -0
  13. package/lib/cjs/locale/pl-PL.js +12 -0
  14. package/lib/cjs/locale/pt-BR.js +12 -0
  15. package/lib/cjs/locale/ru-RU.js +12 -0
  16. package/lib/cjs/locale/sk-SK.js +12 -0
  17. package/lib/cjs/locale/vi-VN.js +12 -0
  18. package/lib/cjs/locale/zh-CN.js +12 -0
  19. package/lib/cjs/locale/zh-HK.js +12 -0
  20. package/lib/cjs/locale/zh-TW.js +12 -0
  21. package/lib/es/index.js +1194 -289
  22. package/lib/es/locale/ar-SA.js +12 -0
  23. package/lib/es/locale/ca-ES.js +12 -0
  24. package/lib/es/locale/de-DE.js +12 -0
  25. package/lib/es/locale/en-US.js +12 -0
  26. package/lib/es/locale/es-ES.js +12 -0
  27. package/lib/es/locale/fa-IR.js +12 -0
  28. package/lib/es/locale/fr-FR.js +12 -0
  29. package/lib/es/locale/id-ID.js +12 -0
  30. package/lib/es/locale/it-IT.js +12 -0
  31. package/lib/es/locale/ja-JP.js +12 -0
  32. package/lib/es/locale/ko-KR.js +12 -0
  33. package/lib/es/locale/pl-PL.js +12 -0
  34. package/lib/es/locale/pt-BR.js +12 -0
  35. package/lib/es/locale/ru-RU.js +12 -0
  36. package/lib/es/locale/sk-SK.js +12 -0
  37. package/lib/es/locale/vi-VN.js +12 -0
  38. package/lib/es/locale/zh-CN.js +12 -0
  39. package/lib/es/locale/zh-HK.js +12 -0
  40. package/lib/es/locale/zh-TW.js +12 -0
  41. package/lib/index.css +21 -0
  42. package/lib/index.js +1194 -289
  43. package/lib/locale/ar-SA.js +12 -0
  44. package/lib/locale/ca-ES.js +12 -0
  45. package/lib/locale/de-DE.js +12 -0
  46. package/lib/locale/en-US.js +12 -0
  47. package/lib/locale/es-ES.js +12 -0
  48. package/lib/locale/fa-IR.js +12 -0
  49. package/lib/locale/fr-FR.js +12 -0
  50. package/lib/locale/id-ID.js +12 -0
  51. package/lib/locale/it-IT.js +12 -0
  52. package/lib/locale/ja-JP.js +12 -0
  53. package/lib/locale/ko-KR.js +12 -0
  54. package/lib/locale/pl-PL.js +12 -0
  55. package/lib/locale/pt-BR.js +12 -0
  56. package/lib/locale/ru-RU.js +12 -0
  57. package/lib/locale/sk-SK.js +12 -0
  58. package/lib/locale/vi-VN.js +12 -0
  59. package/lib/locale/zh-CN.js +12 -0
  60. package/lib/locale/zh-HK.js +12 -0
  61. package/lib/locale/zh-TW.js +12 -0
  62. package/lib/types/commands/commands/doc-delete.command.d.ts +5 -2
  63. package/lib/types/commands/commands/doc-header-footer.command.d.ts +2 -0
  64. package/lib/types/commands/commands/insert-header-footer-field.command.d.ts +28 -0
  65. package/lib/types/commands/commands/refresh-header-footer-fields.command.d.ts +22 -0
  66. package/lib/types/commands/operations/doc-header-footer-ribbon.operation.d.ts +19 -0
  67. package/lib/types/controllers/doc-header-footer-ribbon.controller.d.ts +31 -0
  68. package/lib/types/controllers/render-controllers/doc-field.render-controller.d.ts +31 -0
  69. package/lib/types/controllers/ui.controller.d.ts +1 -0
  70. package/lib/types/locale/en-US.d.ts +12 -0
  71. package/lib/types/menu/header-footer-ribbon.d.ts +17 -0
  72. package/lib/types/services/clipboard/clipboard.service.d.ts +4 -0
  73. package/lib/types/services/doc-event-manager.service.d.ts +1 -0
  74. package/lib/types/services/selection/doc-selection-render.service.d.ts +2 -0
  75. package/lib/types/services/selection/word-boundary.d.ts +1 -0
  76. package/lib/types/shortcuts/core-editing.shortcut.d.ts +4 -0
  77. package/lib/types/shortcuts/format.shortcut.d.ts +1 -0
  78. package/lib/types/shortcuts/utils.d.ts +1 -0
  79. package/lib/types/utils/date-time-field.d.ts +22 -0
  80. package/lib/types/views/header-footer/panel/DocHeaderFooterFields.d.ts +19 -0
  81. package/lib/types/views/header-footer/panel/DocHeaderFooterRibbonControl.d.ts +20 -0
  82. package/lib/types/views/header-footer/panel/component-name.d.ts +2 -0
  83. package/lib/types/views/header-footer/panel/use-header-footer-options.d.ts +2 -2
  84. package/lib/umd/index.js +15 -14
  85. package/lib/umd/locale/ar-SA.js +1 -1
  86. package/lib/umd/locale/ca-ES.js +1 -1
  87. package/lib/umd/locale/de-DE.js +1 -1
  88. package/lib/umd/locale/en-US.js +1 -1
  89. package/lib/umd/locale/es-ES.js +1 -1
  90. package/lib/umd/locale/fa-IR.js +1 -1
  91. package/lib/umd/locale/fr-FR.js +1 -1
  92. package/lib/umd/locale/id-ID.js +1 -1
  93. package/lib/umd/locale/it-IT.js +1 -1
  94. package/lib/umd/locale/ja-JP.js +1 -1
  95. package/lib/umd/locale/ko-KR.js +1 -1
  96. package/lib/umd/locale/pl-PL.js +1 -1
  97. package/lib/umd/locale/pt-BR.js +1 -1
  98. package/lib/umd/locale/ru-RU.js +1 -1
  99. package/lib/umd/locale/sk-SK.js +1 -1
  100. package/lib/umd/locale/vi-VN.js +1 -1
  101. package/lib/umd/locale/zh-CN.js +1 -1
  102. package/lib/umd/locale/zh-HK.js +1 -1
  103. package/lib/umd/locale/zh-TW.js +1 -1
  104. package/package.json +10 -10
package/lib/cjs/index.js CHANGED
@@ -1671,10 +1671,10 @@ var NodePositionConvertToCursor = class {
1671
1671
  let segmentPage = page;
1672
1672
  if (pageType === _univerjs_engine_render.DocumentSkeletonPageType.HEADER) {
1673
1673
  var _skeHeaders$get;
1674
- segmentPage = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(pageWidth);
1674
+ segmentPage = (_skeHeaders$get = skeHeaders.get(headerId)) === null || _skeHeaders$get === void 0 ? void 0 : _skeHeaders$get.get(page.headerLayoutKey ?? pageWidth);
1675
1675
  } else if (pageType === _univerjs_engine_render.DocumentSkeletonPageType.FOOTER) {
1676
1676
  var _skeFooters$get;
1677
- segmentPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(pageWidth);
1677
+ segmentPage = (_skeFooters$get = skeFooters.get(footerId)) === null || _skeFooters$get === void 0 ? void 0 : _skeFooters$get.get(page.footerLayoutKey ?? pageWidth);
1678
1678
  } else if (pageType === _univerjs_engine_render.DocumentSkeletonPageType.NOTE) {
1679
1679
  var _getPageFromPath3, _page$notes;
1680
1680
  const noteId = (_getPageFromPath3 = (0, _univerjs_engine_render.getPageFromPath)(skeletonData, path)) === null || _getPageFromPath3 === void 0 ? void 0 : _getPageFromPath3.segmentId;
@@ -1841,8 +1841,8 @@ function getCellPageFromSegmentPath(skeletonData, rootPage, path) {
1841
1841
  if (path[0] === "pages") return null;
1842
1842
  const segmentPages = [];
1843
1843
  const { headerId, footerId, pageWidth } = rootPage;
1844
- const headerPage = headerId == null ? null : (_skeletonData$skeHead = skeletonData.skeHeaders.get(headerId)) === null || _skeletonData$skeHead === void 0 ? void 0 : _skeletonData$skeHead.get(pageWidth);
1845
- const footerPage = footerId == null ? null : (_skeletonData$skeFoot = skeletonData.skeFooters.get(footerId)) === null || _skeletonData$skeFoot === void 0 ? void 0 : _skeletonData$skeFoot.get(pageWidth);
1844
+ const headerPage = headerId == null ? null : (_skeletonData$skeHead = skeletonData.skeHeaders.get(headerId)) === null || _skeletonData$skeHead === void 0 ? void 0 : _skeletonData$skeHead.get(rootPage.headerLayoutKey ?? pageWidth);
1845
+ const footerPage = footerId == null ? null : (_skeletonData$skeFoot = skeletonData.skeFooters.get(footerId)) === null || _skeletonData$skeFoot === void 0 ? void 0 : _skeletonData$skeFoot.get(rootPage.footerLayoutKey ?? pageWidth);
1846
1846
  if (headerPage != null) segmentPages.push(headerPage);
1847
1847
  if (footerPage != null) segmentPages.push(footerPage);
1848
1848
  for (const segmentPage of segmentPages) {
@@ -2257,7 +2257,7 @@ function getCellPageFromPositionPath(skeletonData, position) {
2257
2257
  const rootPage = skeletonData.pages[segmentPage];
2258
2258
  if (rootPage == null) return null;
2259
2259
  const { headerId, footerId, pageWidth } = rootPage;
2260
- const segmentPages = [headerId == null ? null : (_skeletonData$skeHead = skeletonData.skeHeaders.get(headerId)) === null || _skeletonData$skeHead === void 0 ? void 0 : _skeletonData$skeHead.get(pageWidth), footerId == null ? null : (_skeletonData$skeFoot = skeletonData.skeFooters.get(footerId)) === null || _skeletonData$skeFoot === void 0 ? void 0 : _skeletonData$skeFoot.get(pageWidth)];
2260
+ const segmentPages = [headerId == null ? null : (_skeletonData$skeHead = skeletonData.skeHeaders.get(headerId)) === null || _skeletonData$skeHead === void 0 ? void 0 : _skeletonData$skeHead.get(rootPage.headerLayoutKey ?? pageWidth), footerId == null ? null : (_skeletonData$skeFoot = skeletonData.skeFooters.get(footerId)) === null || _skeletonData$skeFoot === void 0 ? void 0 : _skeletonData$skeFoot.get(rootPage.footerLayoutKey ?? pageWidth)];
2261
2261
  for (const segmentPage of segmentPages) {
2262
2262
  if (segmentPage == null) continue;
2263
2263
  const page = (0, _univerjs_engine_render.getPageFromPath)({
@@ -3197,6 +3197,20 @@ function getWordBoundaryByIndex(content, nodeIndex, paragraphStartOffset) {
3197
3197
  endOffset: paragraphStartOffset + range.end
3198
3198
  };
3199
3199
  }
3200
+ function getWordSelectionByIndex(content, nodeIndex, paragraphStartOffset, isBack) {
3201
+ var _segments;
3202
+ const text = content.replace(/[\r\n]+$/, "");
3203
+ if (!text.length || nodeIndex < 0) return null;
3204
+ const index = Math.min(nodeIndex, text.length - 1);
3205
+ const segments = Array.from(new Intl.Segmenter(void 0, { granularity: "word" }).segment(text));
3206
+ const segmentIndex = segments.findIndex((segment) => segment.index <= index && index < segment.index + segment.segment.length);
3207
+ const segment = segments[segmentIndex];
3208
+ const whitespace = /^\s+$/.test(segment.segment);
3209
+ return {
3210
+ startOffset: paragraphStartOffset + (whitespace ? ((_segments = segments[segmentIndex - 1]) === null || _segments === void 0 ? void 0 : _segments.index) ?? segment.index : segment.index),
3211
+ endOffset: paragraphStartOffset + (whitespace ? Math.min(nodeIndex + (isBack ? 0 : 1), text.length) : segment.index + segment.segment.length)
3212
+ };
3213
+ }
3200
3214
  function getNextWordBoundaryOffset(content, nodeIndex, paragraphStartOffset, direction) {
3201
3215
  if (nodeIndex < 0) return null;
3202
3216
  const ranges = getWordRanges(content);
@@ -3226,6 +3240,12 @@ let DocSelectionRenderService = class DocSelectionRenderService extends _univerj
3226
3240
  get isFocusing() {
3227
3241
  return this._input === this._getOwnerDocument().activeElement;
3228
3242
  }
3243
+ get inputElement() {
3244
+ return this._input;
3245
+ }
3246
+ get selectionContainer() {
3247
+ return this._container;
3248
+ }
3229
3249
  get isEditing() {
3230
3250
  var _this$_textSelectionI;
3231
3251
  return ((_this$_textSelectionI = this._textSelectionInner$.value) === null || _this$_textSelectionI === void 0 ? void 0 : _this$_textSelectionI.isEditing) === true;
@@ -3359,15 +3379,13 @@ let DocSelectionRenderService = class DocSelectionRenderService extends _univerj
3359
3379
  this._selectionStyle = style;
3360
3380
  }
3361
3381
  replaceDocRanges(ranges, isEditing = true, options) {
3362
- var _this$_context$unit$g;
3363
3382
  if (this._onPointerEvent) {
3364
3383
  this._pendingSelection = null;
3365
3384
  return false;
3366
3385
  }
3367
3386
  this._syncNoteSegment(ranges[0]);
3368
- const isBodyOrNote = this._currentSegmentId === "" || ((_this$_context$unit$g = this._context.unit.getSnapshot().notes) === null || _this$_context$unit$g === void 0 ? void 0 : _this$_context$unit$g[this._currentSegmentId]) != null;
3369
3387
  let currentLogicalSelection = null;
3370
- if (isBodyOrNote && ranges.length > 0) {
3388
+ if (ranges.length > 0) {
3371
3389
  const { unitId } = this._context;
3372
3390
  const selection = this._docSelectionManagerService.getSelectionInfo({
3373
3391
  unitId,
@@ -3458,7 +3476,7 @@ let DocSelectionRenderService = class DocSelectionRenderService extends _univerj
3458
3476
  if (startNodePosition && endNodePosition) textRange = getTextRangeFromCharIndex(startNodePosition.isBack ? startOffset : startOffset - 1, endNodePosition.isBack ? endOffset : endOffset - 1, scene, document, docSkeleton, rangeStyle, segmentId, segmentPage, startNodePosition.isBack, endNodePosition.isBack);
3459
3477
  else textRange = getTextRangeFromCharIndex(startOffset, endOffset, scene, document, docSkeleton, rangeStyle, segmentId, segmentPage);
3460
3478
  if (textRange) this._addTextRange(textRange);
3461
- } catch (_e) {
3479
+ } catch {
3462
3480
  generalAddRange(startOffset, endOffset, rangeStyle);
3463
3481
  }
3464
3482
  else generalAddRange(startOffset, endOffset, rangeStyle);
@@ -3548,7 +3566,7 @@ let DocSelectionRenderService = class DocSelectionRenderService extends _univerj
3548
3566
  if (paragraphInfo == null) return;
3549
3567
  const { content, st, nodeIndex } = paragraphInfo;
3550
3568
  if (nodeIndex === -1) return;
3551
- const wordBoundary = getWordBoundaryByIndex(content, nodeIndex, st);
3569
+ const wordBoundary = this._context.unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY || this._context.unitId === _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY ? getWordSelectionByIndex(content, nodeIndex, st, startNode.ratioX < .5) : getWordBoundaryByIndex(content, nodeIndex, st);
3552
3570
  if (wordBoundary != null) {
3553
3571
  this.removeAllRanges();
3554
3572
  const textRanges = [{
@@ -4137,10 +4155,26 @@ let DocSelectionRenderService = class DocSelectionRenderService extends _univerj
4137
4155
  }));
4138
4156
  }
4139
4157
  _refreshMissingInputRange(config) {
4158
+ var _this$_context$unit$g;
4140
4159
  if (config.activeRange == null) {
4141
4160
  config.activeRange = this._getActiveRange();
4142
4161
  config.rangeList = this._getAllTextRanges();
4143
4162
  }
4163
+ const { unitId } = this._context;
4164
+ if (config.activeRange != null || unitId !== _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY || ((_this$_context$unit$g = this._context.unit.getBody()) === null || _this$_context$unit$g === void 0 ? void 0 : _this$_context$unit$g.dataStream) !== "\r\n") return;
4165
+ const selection = this._docSelectionManagerService.getSelectionInfo({
4166
+ unitId,
4167
+ subUnitId: unitId
4168
+ });
4169
+ if (selection == null || selection.textRanges.length !== 1 || selection.rectRanges.length > 0) return;
4170
+ const caret = selection.textRanges[0];
4171
+ if (!caret.isActive || caret.startOffset !== 0 || caret.endOffset !== 0) return;
4172
+ config.activeRange = {
4173
+ ...caret,
4174
+ segmentId: selection.segmentId,
4175
+ segmentPage: selection.segmentPage
4176
+ };
4177
+ config.rangeList = [config.activeRange];
4144
4178
  }
4145
4179
  _handleInputFocus(event) {
4146
4180
  this._eventHandle(event, (config) => {
@@ -5685,7 +5719,7 @@ const CutContentCommand = {
5685
5719
  id: "doc.command.inner-cut",
5686
5720
  type: _univerjs_core.CommandType.COMMAND,
5687
5721
  handler: (accessor, params) => {
5688
- var _selectionInfo$option3;
5722
+ var _selectionInfo$option3, _docDataModel$getSelf7;
5689
5723
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
5690
5724
  const commandService = accessor.get(_univerjs_core.ICommandService);
5691
5725
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
@@ -5705,12 +5739,19 @@ const CutContentCommand = {
5705
5739
  const docSkeletonManagerService = getCommandSkeleton(accessor, unitId);
5706
5740
  if (docSkeletonManagerService == null) return false;
5707
5741
  const viewModel = docSkeletonManagerService.getViewModel();
5742
+ const body = (_docDataModel$getSelf7 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf7 === void 0 ? void 0 : _docDataModel$getSelf7.getBody();
5743
+ const clearsBody = wholeBodySelected || body != null && isWholeBodySelected(selections, rectRanges, body);
5708
5744
  const doMutation = {
5709
5745
  id: _univerjs_docs.RichTextEditingMutation.id,
5710
5746
  params: {
5711
5747
  unitId,
5712
5748
  actions: [],
5713
- textRanges,
5749
+ textRanges: clearsBody ? [{
5750
+ ...textRanges[0],
5751
+ startOffset: 0,
5752
+ endOffset: 0,
5753
+ collapsed: true
5754
+ }] : textRanges,
5714
5755
  trigger: CutContentCommand.id
5715
5756
  }
5716
5757
  };
@@ -5727,6 +5768,31 @@ function isHorizontalLineParagraph(dataStream, paragraph) {
5727
5768
  return Array.from(dataStream).every((token) => token === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH || token === _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK) && (paragraphStyle === null || paragraphStyle === void 0 ? void 0 : paragraphStyle.borderBottom) != null && paragraphStyle.borderTop == null && paragraphStyle.borderLeft == null && paragraphStyle.borderRight == null && paragraphStyle.borderBetween == null;
5728
5769
  }
5729
5770
 
5771
+ //#endregion
5772
+ //#region src/commands/operations/doc-cursor.operation.ts
5773
+ /**
5774
+ * The operation to move cursor in the current document.
5775
+ */
5776
+ const MoveCursorOperation = {
5777
+ id: "doc.operation.move-cursor",
5778
+ type: _univerjs_core.CommandType.OPERATION,
5779
+ handler: (accessor, params) => {
5780
+ if (!params) return false;
5781
+ return true;
5782
+ }
5783
+ };
5784
+ /**
5785
+ * The operation to move selection in the current document.
5786
+ */
5787
+ const MoveSelectionOperation = {
5788
+ id: "doc.operation.move-selection",
5789
+ type: _univerjs_core.CommandType.OPERATION,
5790
+ handler: (accessor, params) => {
5791
+ if (!params) return false;
5792
+ return true;
5793
+ }
5794
+ };
5795
+
5730
5796
  //#endregion
5731
5797
  //#region src/commands/commands/format-painter.command.ts
5732
5798
  function captureTextFormat(body, range, defaultStyle = {}, lists = {}, document = { documentStyle: {} }) {
@@ -6140,11 +6206,25 @@ function isDeleteOffsetInsideBlockRange(body, offset) {
6140
6206
  return interval.startOffset < offset && offset < interval.endOffset - 1;
6141
6207
  })) ?? false;
6142
6208
  }
6209
+ function selectDeleteBoundary(accessor, direction, granularity) {
6210
+ var _selections$getActive, _selections$getRectRa;
6211
+ const selections = accessor.get(_univerjs_docs.DocSelectionManagerService);
6212
+ if (((_selections$getActive = selections.getActiveTextRange()) === null || _selections$getActive === void 0 ? void 0 : _selections$getActive.collapsed) && !((_selections$getRectRa = selections.getRectRanges()) === null || _selections$getRectRa === void 0 ? void 0 : _selections$getRectRa.length)) {
6213
+ var _selections$getActive2;
6214
+ accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(MoveSelectionOperation.id, {
6215
+ direction,
6216
+ granularity
6217
+ });
6218
+ return ((_selections$getActive2 = selections.getActiveTextRange()) === null || _selections$getActive2 === void 0 ? void 0 : _selections$getActive2.collapsed) === false;
6219
+ }
6220
+ return true;
6221
+ }
6143
6222
  const DeleteLeftCommand = {
6144
6223
  id: "doc.command.delete-left",
6145
6224
  type: _univerjs_core.CommandType.COMMAND,
6146
- handler: async (accessor) => {
6225
+ handler: async (accessor, params) => {
6147
6226
  var _docDataModel$getSelf3, _docDataModel$getSelf4;
6227
+ if ((params === null || params === void 0 ? void 0 : params.granularity) && !selectDeleteBoundary(accessor, _univerjs_core.Direction.LEFT, params.granularity)) return true;
6148
6228
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
6149
6229
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
6150
6230
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -6304,8 +6384,9 @@ const DeleteLeftCommand = {
6304
6384
  const DeleteRightCommand = {
6305
6385
  id: "doc.command.delete-right",
6306
6386
  type: _univerjs_core.CommandType.COMMAND,
6307
- handler: async (accessor) => {
6387
+ handler: async (accessor, params) => {
6308
6388
  var _docDataModel$getSelf5;
6389
+ if ((params === null || params === void 0 ? void 0 : params.granularity) && !selectDeleteBoundary(accessor, _univerjs_core.Direction.RIGHT, params.granularity)) return true;
6309
6390
  const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
6310
6391
  const docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
6311
6392
  if (!docDataModel) return false;
@@ -8526,7 +8607,11 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
8526
8607
  _defineProperty(this, "_umdToHtml", void 0);
8527
8608
  this._umdToHtml = new UDMToHtmlService(docHtmlExportService);
8528
8609
  this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
8529
- if (!this._applyingPaste && command.type === _univerjs_core.CommandType.MUTATION) this.dismissPasteOptions();
8610
+ var _command$params, _this$_pasteOptions$$;
8611
+ if (this._applyingPaste || command.type !== _univerjs_core.CommandType.MUTATION) return;
8612
+ const unitId = (_command$params = command.params) === null || _command$params === void 0 ? void 0 : _command$params.unitId;
8613
+ const pasteUnitId = ((_this$_pasteOptions$$ = this._pasteOptions$.value) === null || _this$_pasteOptions$$ === void 0 ? void 0 : _this$_pasteOptions$$.unitId) ?? this._getCurrentDocumentUnitId();
8614
+ if (!unitId || unitId === pasteUnitId) this.dismissPasteOptions();
8530
8615
  }));
8531
8616
  const invalidateSelection = () => {
8532
8617
  const key = this._getPasteSelectionKey();
@@ -8600,6 +8685,12 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
8600
8685
  mode
8601
8686
  });
8602
8687
  }
8688
+ isPasteOptionsEnabled(unitId) {
8689
+ return !(0, _univerjs_core.isInternalEditorID)(unitId) || this._clipboardHooks.some((hook) => {
8690
+ var _hook$supportsPasteOp;
8691
+ return (_hook$supportsPasteOp = hook.supportsPasteOptions) === null || _hook$supportsPasteOp === void 0 ? void 0 : _hook$supportsPasteOp.call(hook, unitId);
8692
+ });
8693
+ }
8603
8694
  setNextPasteMode(mode) {
8604
8695
  this._nextPasteMode = mode;
8605
8696
  }
@@ -8690,7 +8781,7 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
8690
8781
  try {
8691
8782
  this._stateChangeManager.flushPendingChanges(unitId);
8692
8783
  const result = this._paste(doc, unitId);
8693
- if (result && !(0, _univerjs_core.isInternalEditorID)(unitId)) this._savePasteSession(payload, mode === "text" ? cachedSource : source, style, mode, unitId);
8784
+ if (result && this.isPasteOptionsEnabled(unitId)) this._savePasteSession(payload, mode === "text" ? cachedSource : source, style, mode, unitId);
8694
8785
  return result;
8695
8786
  } finally {
8696
8787
  this._applyingPaste = false;
@@ -8914,7 +9005,11 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
8914
9005
  this._clipboardHooks.push(hook);
8915
9006
  return (0, _univerjs_core.toDisposable)(() => {
8916
9007
  const index = this._clipboardHooks.indexOf(hook);
8917
- if (index > -1) this._clipboardHooks.splice(index, 1);
9008
+ if (index > -1) {
9009
+ this._clipboardHooks.splice(index, 1);
9010
+ const state = this._pasteOptions$.value;
9011
+ if (state && !this.isPasteOptionsEnabled(state.unitId)) this.dismissPasteOptions();
9012
+ }
8918
9013
  });
8919
9014
  }
8920
9015
  _applyCopyDocDataHooks(doc, sourceDocuments) {
@@ -11620,31 +11715,6 @@ const DocCreateTableOperation = {
11620
11715
  }
11621
11716
  };
11622
11717
 
11623
- //#endregion
11624
- //#region src/commands/operations/doc-cursor.operation.ts
11625
- /**
11626
- * The operation to move cursor in the current document.
11627
- */
11628
- const MoveCursorOperation = {
11629
- id: "doc.operation.move-cursor",
11630
- type: _univerjs_core.CommandType.OPERATION,
11631
- handler: (accessor, params) => {
11632
- if (!params) return false;
11633
- return true;
11634
- }
11635
- };
11636
- /**
11637
- * The operation to move selection in the current document.
11638
- */
11639
- const MoveSelectionOperation = {
11640
- id: "doc.operation.move-selection",
11641
- type: _univerjs_core.CommandType.OPERATION,
11642
- handler: (accessor, params) => {
11643
- if (!params) return false;
11644
- return true;
11645
- }
11646
- };
11647
-
11648
11718
  //#endregion
11649
11719
  //#region src/config/config.ts
11650
11720
  const DOCS_UI_PLUGIN_CONFIG_KEY = "docs-ui.config";
@@ -14351,6 +14421,8 @@ function getHeaderFooterTarget(viewModel, editArea, segmentPage, page) {
14351
14421
  * limitations under the License.
14352
14422
  */
14353
14423
  const COMPONENT_DOC_HEADER_FOOTER_PANEL = "COMPONENT_DOC_HEADER_FOOTER_PANEL";
14424
+ const DOC_HEADER_FOOTER_RIBBON_TAB = "docs-ui.ribbon.header-footer";
14425
+ const DOC_HEADER_FOOTER_RIBBON_CONTROL = "DocHeaderFooterRibbonControl";
14354
14426
 
14355
14427
  //#endregion
14356
14428
  //#region src/commands/operations/doc-header-footer-panel.operation.ts
@@ -14408,8 +14480,8 @@ const CoreHeaderFooterCommand = {
14408
14480
  let resolvedCreateType = createType;
14409
14481
  if (headerFooterProps != null) Object.keys(headerFooterProps).forEach((key) => {
14410
14482
  const value = headerFooterProps[key];
14411
- if (resolvedCreateType == null && key === "useFirstPageHeaderFooter" && value === _univerjs_core.BooleanNumber.TRUE && !headerFooterConfig.firstPageHeaderId) resolvedCreateType = editArea === _univerjs_engine_render.DocumentEditArea.HEADER ? _univerjs_docs.HeaderFooterType.FIRST_PAGE_HEADER : _univerjs_docs.HeaderFooterType.FIRST_PAGE_FOOTER;
14412
- else if (resolvedCreateType == null && key === "evenAndOddHeaders" && value === _univerjs_core.BooleanNumber.TRUE && !headerFooterConfig.evenPageHeaderId) resolvedCreateType = editArea === _univerjs_engine_render.DocumentEditArea.HEADER ? _univerjs_docs.HeaderFooterType.EVEN_PAGE_HEADER : _univerjs_docs.HeaderFooterType.EVEN_PAGE_FOOTER;
14483
+ if (resolvedCreateType == null && key === "useFirstPageHeaderFooter" && value === _univerjs_core.BooleanNumber.TRUE && !(editArea === _univerjs_engine_render.DocumentEditArea.HEADER ? headerFooterConfig.firstPageHeaderId : headerFooterConfig.firstPageFooterId)) resolvedCreateType = editArea === _univerjs_engine_render.DocumentEditArea.HEADER ? _univerjs_docs.HeaderFooterType.FIRST_PAGE_HEADER : _univerjs_docs.HeaderFooterType.FIRST_PAGE_FOOTER;
14484
+ else if (resolvedCreateType == null && key === "evenAndOddHeaders" && value === _univerjs_core.BooleanNumber.TRUE && !(editArea === _univerjs_engine_render.DocumentEditArea.HEADER ? headerFooterConfig.evenPageHeaderId : headerFooterConfig.evenPageFooterId)) resolvedCreateType = editArea === _univerjs_engine_render.DocumentEditArea.HEADER ? _univerjs_docs.HeaderFooterType.EVEN_PAGE_HEADER : _univerjs_docs.HeaderFooterType.EVEN_PAGE_FOOTER;
14413
14485
  });
14414
14486
  return commandService.syncExecuteCommand(_univerjs_docs.CreateHeaderFooterCommand.id, {
14415
14487
  unitId,
@@ -14424,8 +14496,8 @@ const CoreHeaderFooterCommand = {
14424
14496
  const OpenHeaderFooterPanelCommand = {
14425
14497
  id: "doc.command.open-header-footer-panel",
14426
14498
  type: _univerjs_core.CommandType.COMMAND,
14427
- handler: async (accessor, _params) => {
14428
- var _skeleton$getSkeleton;
14499
+ handler: async (accessor, params) => {
14500
+ var _skeleton$getSkeleton, _docDataModel$getSelf;
14429
14501
  const commandService = accessor.get(_univerjs_core.ICommandService);
14430
14502
  const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
14431
14503
  const renderManagerService = accessor.get(_univerjs_engine_render.IRenderManagerService);
@@ -14442,8 +14514,9 @@ const OpenHeaderFooterPanelCommand = {
14442
14514
  const currentPage = selectionRenderService.getSegmentPage();
14443
14515
  const pageNumber = currentPage >= 0 && currentPage < pages.length ? currentPage : 0;
14444
14516
  const page = pages[pageNumber];
14445
- viewModel.setEditArea(_univerjs_engine_render.DocumentEditArea.HEADER);
14446
- const { createType, headerFooterId, sectionId } = getHeaderFooterTarget(viewModel, _univerjs_engine_render.DocumentEditArea.HEADER, pageNumber, page);
14517
+ const editArea = (params === null || params === void 0 ? void 0 : params.editArea) ?? _univerjs_engine_render.DocumentEditArea.HEADER;
14518
+ viewModel.setEditArea(editArea);
14519
+ const { createType, headerFooterId, sectionId } = getHeaderFooterTarget(viewModel, editArea, pageNumber, page);
14447
14520
  selectionRenderService.setSegmentPage(pageNumber);
14448
14521
  if (createType != null) {
14449
14522
  const segmentId = (0, _univerjs_core.generateRandomId)(6);
@@ -14460,6 +14533,21 @@ const OpenHeaderFooterPanelCommand = {
14460
14533
  return false;
14461
14534
  }
14462
14535
  } else if (headerFooterId != null) selectionRenderService.setSegment(headerFooterId);
14536
+ const segmentId = selectionRenderService.getSegment();
14537
+ const segmentSnapshot = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getSnapshot();
14538
+ if (!segmentSnapshot) return false;
14539
+ const offset = findFirstCursorOffset(segmentSnapshot);
14540
+ accessor.get(_univerjs_docs.DocSelectionManagerService).replaceDocRanges([{
14541
+ startOffset: offset,
14542
+ endOffset: offset,
14543
+ collapsed: true,
14544
+ segmentId,
14545
+ segmentPage: pageNumber
14546
+ }], {
14547
+ unitId,
14548
+ subUnitId: unitId
14549
+ });
14550
+ selectionRenderService.focus();
14463
14551
  return commandService.executeCommand(SidebarDocHeaderFooterPanelOperation.id, { value: "open" });
14464
14552
  }
14465
14553
  };
@@ -14502,7 +14590,254 @@ const CloseHeaderFooterCommand = {
14502
14590
  endOffset: offset
14503
14591
  }]);
14504
14592
  });
14505
- commandService.executeCommand(SidebarDocHeaderFooterPanelOperation.id, { value: "close" });
14593
+ await commandService.executeCommand(SidebarDocHeaderFooterPanelOperation.id, { value: "close" });
14594
+ return true;
14595
+ }
14596
+ };
14597
+
14598
+ //#endregion
14599
+ //#region src/utils/date-time-field.ts
14600
+ function createDateTimeField(format, locale, date) {
14601
+ const options = format === "time" ? {
14602
+ hour: "2-digit",
14603
+ minute: "2-digit",
14604
+ second: "2-digit",
14605
+ hourCycle: "h23"
14606
+ } : {
14607
+ year: "numeric",
14608
+ month: format === "long" ? "long" : "2-digit",
14609
+ day: "2-digit"
14610
+ };
14611
+ const formatter = new Intl.DateTimeFormat(locale, {
14612
+ ...options,
14613
+ calendar: "gregory",
14614
+ numberingSystem: "latn"
14615
+ });
14616
+ const parts = formatter.formatToParts(date);
14617
+ const tokens = {
14618
+ year: "yyyy",
14619
+ month: format === "long" ? "MMMM" : "MM",
14620
+ day: "dd",
14621
+ hour: "HH",
14622
+ minute: "mm",
14623
+ second: "ss"
14624
+ };
14625
+ const mask = parts.map((part) => tokens[part.type] ?? `'${part.value.replace(/'/g, "''")}'`).join("");
14626
+ const fieldType = format === "time" ? "TIME" : "DATE";
14627
+ return {
14628
+ fieldType,
14629
+ instruction: `${fieldType} \\@ "${mask}"`,
14630
+ cachedResult: formatter.format(date)
14631
+ };
14632
+ }
14633
+ function resolveDateTimeField(instruction, locale, date) {
14634
+ try {
14635
+ Intl.getCanonicalLocales(locale);
14636
+ } catch {
14637
+ return;
14638
+ }
14639
+ for (const format of [
14640
+ "short",
14641
+ "long",
14642
+ "time"
14643
+ ]) {
14644
+ const field = createDateTimeField(format, locale, date);
14645
+ if (field.instruction === instruction) return field.cachedResult;
14646
+ }
14647
+ }
14648
+
14649
+ //#endregion
14650
+ //#region src/commands/commands/insert-header-footer-field.command.ts
14651
+ const InsertHeaderFooterFieldCommand = {
14652
+ id: "doc.command.insert-header-footer-field",
14653
+ type: _univerjs_core.CommandType.COMMAND,
14654
+ handler(accessor, params) {
14655
+ var _snapshot$headers, _snapshot$footers, _model$getSelfOrHeade, _body$customRanges;
14656
+ if (!params || ![
14657
+ "PAGE",
14658
+ "NUMPAGES",
14659
+ "DATE",
14660
+ "TIME"
14661
+ ].includes(params.fieldType)) return false;
14662
+ const model = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
14663
+ const active = accessor.get(_univerjs_docs.DocSelectionManagerService).getActiveTextRange();
14664
+ const selection = params.selection ?? active;
14665
+ const segmentId = params.segmentId ?? (active === null || active === void 0 ? void 0 : active.segmentId);
14666
+ const snapshot = model === null || model === void 0 ? void 0 : model.getSnapshot();
14667
+ if (!model || (snapshot === null || snapshot === void 0 ? void 0 : snapshot.disabled) || !selection || !segmentId || !(snapshot === null || snapshot === void 0 || (_snapshot$headers = snapshot.headers) === null || _snapshot$headers === void 0 ? void 0 : _snapshot$headers[segmentId]) && !(snapshot === null || snapshot === void 0 || (_snapshot$footers = snapshot.footers) === null || _snapshot$footers === void 0 ? void 0 : _snapshot$footers[segmentId])) return false;
14668
+ const body = (_model$getSelfOrHeade = model.getSelfOrHeaderFooterModel(segmentId)) === null || _model$getSelfOrHeade === void 0 ? void 0 : _model$getSelfOrHeade.getBody();
14669
+ if (!body || params.expectedDataStream != null && params.expectedDataStream !== body.dataStream || !Number.isInteger(selection.startOffset) || !Number.isInteger(selection.endOffset) || selection.startOffset < 0 || selection.endOffset < selection.startOffset || selection.endOffset > body.dataStream.length - 2) return false;
14670
+ if (!(0, _univerjs_docs.canEditDocumentTargets)(accessor.get(_univerjs_core.IPermissionService), params.unitId, (0, _univerjs_docs.getDocumentEditTargetObjectIds)(model, segmentId, selection))) return false;
14671
+ if ((_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.some((range) => {
14672
+ var _range$properties;
14673
+ return range.rangeType === _univerjs_core.CustomRangeType.FIELD && ((_range$properties = range.properties) === null || _range$properties === void 0 ? void 0 : _range$properties.locked) === _univerjs_core.BooleanNumber.TRUE && selection.startOffset <= range.endIndex && selection.endOffset > range.startIndex;
14674
+ })) return false;
14675
+ const locale = _univerjs_core.LOCALE_META[accessor.get(_univerjs_core.LocaleService).getCurrentLocale()].tag;
14676
+ let properties;
14677
+ if (params.fieldType === "DATE" || params.fieldType === "TIME") {
14678
+ const format = params.format ?? (params.fieldType === "TIME" ? "time" : "short");
14679
+ if (![
14680
+ "short",
14681
+ "long",
14682
+ "time"
14683
+ ].includes(format)) return false;
14684
+ properties = createDateTimeField(format, locale, /* @__PURE__ */ new Date());
14685
+ } else {
14686
+ var _accessor$get$getRend, _skeleton$getSkeleton;
14687
+ const skeleton = (_accessor$get$getRend = accessor.get(_univerjs_engine_render.IRenderManagerService).getRenderUnitById(params.unitId)) === null || _accessor$get$getRend === void 0 ? void 0 : _accessor$get$getRend.with(_univerjs_docs.DocSkeletonManagerService).getSkeleton();
14688
+ const pages = skeleton === null || skeleton === void 0 || (_skeleton$getSkeleton = skeleton.getSkeletonData()) === null || _skeleton$getSkeleton === void 0 ? void 0 : _skeleton$getSkeleton.pages;
14689
+ if (!(pages === null || pages === void 0 ? void 0 : pages.length)) return false;
14690
+ const pageIndex = params.segmentPage ?? (active === null || active === void 0 ? void 0 : active.segmentPage) ?? 0;
14691
+ const page = pages[Math.max(0, pageIndex)];
14692
+ if (!page) return false;
14693
+ properties = {
14694
+ fieldType: params.fieldType,
14695
+ instruction: params.fieldType,
14696
+ cachedResult: String(params.fieldType === "PAGE" ? page.pageNumber : (skeleton === null || skeleton === void 0 ? void 0 : skeleton.getCompletedPageCount()) ?? "…")
14697
+ };
14698
+ }
14699
+ const automatic = params.automatic !== false || params.fieldType === "PAGE" || params.fieldType === "NUMPAGES";
14700
+ const dataStream = automatic ? `${_univerjs_core.DataStreamTreeTokenType.CUSTOM_RANGE_START}${properties.cachedResult}${_univerjs_core.DataStreamTreeTokenType.CUSTOM_RANGE_END}` : properties.cachedResult;
14701
+ const style = accessor.get(DocMenuStyleService);
14702
+ const textRun = getTextRunForSelection(body, selection, style.getDefaultStyle(), style.getStyleCache(), false);
14703
+ return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(_univerjs_docs.InsertTextCommand.id, {
14704
+ unitId: params.unitId,
14705
+ segmentId,
14706
+ range: selection,
14707
+ debounce: false,
14708
+ body: {
14709
+ dataStream,
14710
+ textRuns: [{
14711
+ ...textRun,
14712
+ ts: {
14713
+ ...textRun.ts,
14714
+ lang: locale
14715
+ },
14716
+ st: 0,
14717
+ ed: dataStream.length
14718
+ }],
14719
+ customRanges: automatic ? [{
14720
+ startIndex: 0,
14721
+ endIndex: dataStream.length - 1,
14722
+ rangeId: (0, _univerjs_core.generateRandomId)(),
14723
+ rangeType: _univerjs_core.CustomRangeType.FIELD,
14724
+ wholeEntity: false,
14725
+ properties: {
14726
+ ...properties,
14727
+ sourceKind: "complex"
14728
+ }
14729
+ }] : []
14730
+ },
14731
+ textRanges: [{
14732
+ ...selection,
14733
+ segmentId,
14734
+ segmentPage: params.segmentPage ?? (active === null || active === void 0 ? void 0 : active.segmentPage),
14735
+ startOffset: selection.startOffset + dataStream.length,
14736
+ endOffset: selection.startOffset + dataStream.length,
14737
+ collapsed: true
14738
+ }]
14739
+ });
14740
+ }
14741
+ };
14742
+
14743
+ //#endregion
14744
+ //#region src/commands/commands/refresh-header-footer-fields.command.ts
14745
+ const RefreshHeaderFooterFieldsCommand = {
14746
+ id: "doc.command.refresh-header-footer-fields",
14747
+ type: _univerjs_core.CommandType.COMMAND,
14748
+ handler(accessor, params) {
14749
+ if (!params) return false;
14750
+ const model = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
14751
+ const snapshot = model === null || model === void 0 ? void 0 : model.getSnapshot();
14752
+ if (!model || !snapshot || snapshot.disabled) return false;
14753
+ const permissions = accessor.get(_univerjs_core.IPermissionService);
14754
+ const locale = _univerjs_core.LOCALE_META[accessor.get(_univerjs_core.LocaleService).getCurrentLocale()].tag;
14755
+ const now = /* @__PURE__ */ new Date();
14756
+ const selections = accessor.get(_univerjs_docs.DocSelectionManagerService).getTextRanges({
14757
+ unitId: params.unitId,
14758
+ subUnitId: params.unitId
14759
+ }) ?? [];
14760
+ let actions = null;
14761
+ for (const [segmentId, segment] of Object.entries({
14762
+ "": { body: snapshot.body },
14763
+ ...snapshot.headers,
14764
+ ...snapshot.footers
14765
+ })) {
14766
+ if (!segment.body) continue;
14767
+ const textX = refreshDateTimeFields(segment.body, locale, now, (field) => (!params.selectionOnly || selections.some((selection) => (selection.segmentId ?? "") === segmentId && selection.startOffset <= field.endIndex && selection.endOffset > field.startIndex)) && (0, _univerjs_docs.canEditDocumentTargets)(permissions, params.unitId, (0, _univerjs_docs.getDocumentEditTargetObjectIds)(model, segmentId, {
14768
+ startOffset: field.startIndex,
14769
+ endOffset: field.endIndex + 1
14770
+ })));
14771
+ if (textX.length) actions = _univerjs_core.JSONX.compose(actions, _univerjs_core.JSONX.getInstance().editOp(textX, (0, _univerjs_core.getRichTextEditPath)(model, segmentId)));
14772
+ }
14773
+ if (_univerjs_core.JSONX.isNoop(actions)) return true;
14774
+ if (!params.onOpen) accessor.get(_univerjs_docs.DocStateChangeManagerService).flushPendingChanges(params.unitId);
14775
+ return Boolean(accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(_univerjs_docs.RichTextEditingMutation.id, {
14776
+ unitId: params.unitId,
14777
+ actions,
14778
+ textRanges: (0, _univerjs_docs.transformDocumentTextRanges)(actions, [...selections]),
14779
+ noHistory: params.onOpen === true,
14780
+ debounce: false,
14781
+ trigger: RefreshHeaderFooterFieldsCommand.id
14782
+ }));
14783
+ }
14784
+ };
14785
+ const UpdateSelectedDocFieldsCommand = {
14786
+ id: "doc.command.update-selected-fields",
14787
+ type: _univerjs_core.CommandType.COMMAND,
14788
+ handler(accessor) {
14789
+ const model = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
14790
+ if (!model) return false;
14791
+ return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(RefreshHeaderFooterFieldsCommand.id, {
14792
+ unitId: model.getUnitId(),
14793
+ selectionOnly: true
14794
+ });
14795
+ }
14796
+ };
14797
+ function refreshDateTimeFields(body, locale, date, canEdit) {
14798
+ const textX = new _univerjs_core.TextX();
14799
+ let cursor = 0;
14800
+ const ranges = [...body.customRanges ?? []].sort((a, b) => a.startIndex - b.startIndex);
14801
+ for (const field of ranges) {
14802
+ var _body$textRuns, _run$ts;
14803
+ const properties = field.properties;
14804
+ if (field.rangeType !== _univerjs_core.CustomRangeType.FIELD || (properties === null || properties === void 0 ? void 0 : properties.locked) === _univerjs_core.BooleanNumber.TRUE || (properties === null || properties === void 0 ? void 0 : properties.fieldType) !== "DATE" && (properties === null || properties === void 0 ? void 0 : properties.fieldType) !== "TIME" || !canEdit(field) || ranges.some((range) => range !== field && range.startIndex > field.startIndex && range.endIndex < field.endIndex)) continue;
14805
+ const start = field.startIndex;
14806
+ const run = (_body$textRuns = body.textRuns) === null || _body$textRuns === void 0 ? void 0 : _body$textRuns.find((run) => run.st <= start + 1 && run.ed > start + 1);
14807
+ const value = resolveDateTimeField(properties.instruction, (run === null || run === void 0 || (_run$ts = run.ts) === null || _run$ts === void 0 ? void 0 : _run$ts.lang) ?? locale, date);
14808
+ if (value == null || start < cursor || body.dataStream.slice(start + 1, field.endIndex) === value && properties.cachedResult === value) continue;
14809
+ const dataStream = `${_univerjs_core.DataStreamTreeTokenType.CUSTOM_RANGE_START}${value}${_univerjs_core.DataStreamTreeTokenType.CUSTOM_RANGE_END}`;
14810
+ textX.retain(start - cursor).delete(field.endIndex - start + 1).insert(dataStream.length, {
14811
+ dataStream,
14812
+ textRuns: run ? [{
14813
+ ...run,
14814
+ st: 0,
14815
+ ed: dataStream.length
14816
+ }] : [],
14817
+ customRanges: [{
14818
+ ...field,
14819
+ startIndex: 0,
14820
+ endIndex: dataStream.length - 1,
14821
+ properties: {
14822
+ ...properties,
14823
+ cachedResult: value
14824
+ }
14825
+ }]
14826
+ });
14827
+ cursor = field.endIndex + 1;
14828
+ }
14829
+ return textX.serialize();
14830
+ }
14831
+
14832
+ //#endregion
14833
+ //#region src/commands/operations/doc-header-footer-ribbon.operation.ts
14834
+ const DocHeaderFooterRibbonOperation = {
14835
+ id: SidebarDocHeaderFooterPanelOperation.id,
14836
+ type: SidebarDocHeaderFooterPanelOperation.type,
14837
+ handler(accessor, params) {
14838
+ const ribbon = accessor.get(_univerjs_ui.IRibbonService);
14839
+ if ((params === null || params === void 0 ? void 0 : params.value) === "open") ribbon.showContextualTab(DOC_HEADER_FOOTER_RIBBON_TAB, { activate: true });
14840
+ else ribbon.hideContextualTab(DOC_HEADER_FOOTER_RIBBON_TAB);
14506
14841
  return true;
14507
14842
  }
14508
14843
  };
@@ -15131,8 +15466,12 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15131
15466
  }
15132
15467
  _initPointer() {
15133
15468
  let preCursor = _univerjs_engine_render.CURSOR_TYPE.TEXT;
15469
+ let pointing = false;
15134
15470
  this.disposeWithMe(this.hoverCustomRanges$.subscribe((ranges) => {
15135
- if (ranges.length) {
15471
+ const nextPointing = ranges.some(({ range }) => range.rangeType !== _univerjs_core.CustomRangeType.FIELD);
15472
+ if (nextPointing === pointing) return;
15473
+ pointing = nextPointing;
15474
+ if (pointing) {
15136
15475
  preCursor = this._context.scene.getCursor();
15137
15476
  this._context.scene.setCursor(_univerjs_engine_render.CURSOR_TYPE.POINTER);
15138
15477
  } else this._context.scene.setCursor(preCursor);
@@ -15255,6 +15594,10 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
15255
15594
  this._buildBulletBounds();
15256
15595
  return [...this._bulletBounds];
15257
15596
  }
15597
+ getCustomRangeBounds() {
15598
+ this._buildCustomRangeBounds();
15599
+ return [...this._customRangeBounds];
15600
+ }
15258
15601
  getListContextMenuBulletByOffset(offsetX, offsetY) {
15259
15602
  const point = transformOffset2Bound(offsetX, offsetY, this._context.scene);
15260
15603
  return this._calcActiveBullet(point) ?? this._calcActiveListParagraph(point);
@@ -15800,132 +16143,50 @@ const OpenDocPermissionPanelOperation = {
15800
16143
  };
15801
16144
 
15802
16145
  //#endregion
15803
- //#region src/controllers/doc-paragraph-setting.controller.ts
15804
- /**
15805
- * Copyright 2023-present DreamNum Co., Ltd.
15806
- *
15807
- * Licensed under the Apache License, Version 2.0 (the "License");
15808
- * you may not use this file except in compliance with the License.
15809
- * You may obtain a copy of the License at
15810
- *
15811
- * http://www.apache.org/licenses/LICENSE-2.0
15812
- *
15813
- * Unless required by applicable law or agreed to in writing, software
15814
- * distributed under the License is distributed on an "AS IS" BASIS,
15815
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15816
- * See the License for the specific language governing permissions and
15817
- * limitations under the License.
15818
- */
15819
- const paragraphSettingIndexKey$1 = "doc_ui_paragraph-setting-panel";
15820
- let DocParagraphSettingController = class DocParagraphSettingController extends _univerjs_core.Disposable {
15821
- constructor(_commandService, _sidebarService) {
15822
- super();
15823
- this._commandService = _commandService;
15824
- this._sidebarService = _sidebarService;
15825
- _defineProperty(this, "_id", void 0);
15826
- }
15827
- openPanel() {
15828
- const props = {
15829
- header: { title: "docs-ui.doc.slider.paragraphSetting" },
15830
- id: this._id,
15831
- children: { label: paragraphSettingIndexKey$1 },
15832
- width: 300
15833
- };
15834
- this._sidebarService.open(props);
15835
- }
15836
- closePanel() {
15837
- this._sidebarService.close(this._id);
15838
- }
15839
- };
15840
- DocParagraphSettingController = __decorate([__decorateParam(0, _univerjs_core.ICommandService), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.ISidebarService))], DocParagraphSettingController);
15841
-
15842
- //#endregion
15843
- //#region src/commands/operations/doc-paragraph-setting-panel.operation.ts
15844
- const DocParagraphSettingPanelOperation = {
15845
- id: "sidebar.operation.doc-paragraph-setting-panel",
15846
- type: _univerjs_core.CommandType.OPERATION,
15847
- handler: (accessor) => {
15848
- accessor.get(DocParagraphSettingController).openPanel();
15849
- return true;
15850
- }
15851
- };
15852
-
15853
- //#endregion
15854
- //#region src/views/section-setting/component-name.ts
15855
- /**
15856
- * Copyright 2023-present DreamNum Co., Ltd.
15857
- *
15858
- * Licensed under the Apache License, Version 2.0 (the "License");
15859
- * you may not use this file except in compliance with the License.
15860
- * You may obtain a copy of the License at
15861
- *
15862
- * http://www.apache.org/licenses/LICENSE-2.0
15863
- *
15864
- * Unless required by applicable law or agreed to in writing, software
15865
- * distributed under the License is distributed on an "AS IS" BASIS,
15866
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15867
- * See the License for the specific language governing permissions and
15868
- * limitations under the License.
15869
- */
15870
- const DOC_SECTION_SETTING_COMPONENT = "doc_ui_section-setting-panel";
15871
-
15872
- //#endregion
15873
- //#region src/controllers/doc-section-setting.controller.ts
15874
- /**
15875
- * Copyright 2023-present DreamNum Co., Ltd.
15876
- *
15877
- * Licensed under the Apache License, Version 2.0 (the "License");
15878
- * you may not use this file except in compliance with the License.
15879
- * You may obtain a copy of the License at
15880
- *
15881
- * http://www.apache.org/licenses/LICENSE-2.0
15882
- *
15883
- * Unless required by applicable law or agreed to in writing, software
15884
- * distributed under the License is distributed on an "AS IS" BASIS,
15885
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15886
- * See the License for the specific language governing permissions and
15887
- * limitations under the License.
15888
- */
15889
- let DocSectionSettingController = class DocSectionSettingController extends _univerjs_core.Disposable {
15890
- constructor(_sidebarService, _selectionManager) {
15891
- super();
15892
- this._sidebarService = _sidebarService;
15893
- this._selectionManager = _selectionManager;
15894
- _defineProperty(this, "_panelId", "DocSectionSetting");
15895
- }
15896
- openPanel() {
15897
- this._sidebarService.open({
15898
- header: { title: "docs-ui.doc.slider.sectionSetting" },
15899
- id: this._panelId,
15900
- children: { label: DOC_SECTION_SETTING_COMPONENT },
15901
- width: 300
15902
- });
15903
- }
15904
- closePanel() {
15905
- this._sidebarService.close(this._panelId);
15906
- }
15907
- navigateToSectionEnd(unitId, sectionStart, sectionEnd) {
15908
- const params = {
15909
- unitId,
15910
- subUnitId: unitId
15911
- };
15912
- const cursorOffset = Math.max(sectionStart, sectionEnd - 1);
15913
- this._selectionManager.replaceDocRanges([{
15914
- startOffset: cursorOffset,
15915
- endOffset: cursorOffset
15916
- }], params, true, { shouldFocus: false });
15917
- }
15918
- };
15919
- DocSectionSettingController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ISidebarService)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService))], DocSectionSettingController);
15920
-
15921
- //#endregion
15922
- //#region src/commands/operations/doc-section-setting-panel.operation.ts
15923
- const DocSectionSettingPanelOperation = {
15924
- id: "sidebar.operation.doc-section-setting-panel",
15925
- type: _univerjs_core.CommandType.OPERATION,
15926
- handler: (accessor) => {
15927
- accessor.get(DocSectionSettingController).openPanel();
15928
- return true;
16146
+ //#region src/commands/commands/insert-special-character.command.ts
16147
+ const InsertSpecialCharacterCommand = {
16148
+ id: "doc.command.insert-special-character",
16149
+ type: _univerjs_core.CommandType.COMMAND,
16150
+ handler: (accessor, params) => {
16151
+ var _docDataModel$getSelf, _getEditorRuntimeConf;
16152
+ if (!(params === null || params === void 0 ? void 0 : params.value)) return false;
16153
+ const commandService = accessor.get(_univerjs_core.ICommandService);
16154
+ const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
16155
+ const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
16156
+ const docMenuStyleService = accessor.get(DocMenuStyleService);
16157
+ const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
16158
+ const activeRange = docSelectionManagerService.getActiveTextRange();
16159
+ if (!docDataModel || !activeRange) return false;
16160
+ const { segmentId } = activeRange;
16161
+ const originBody = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
16162
+ if (!originBody) return false;
16163
+ const { value } = params;
16164
+ const curTextRun = getTextRunForSelection(originBody, activeRange, docMenuStyleService.getDefaultStyle(), docMenuStyleService.getStyleCache(), false, ((_getEditorRuntimeConf = getEditorRuntimeConfig(docDataModel)) === null || _getEditorRuntimeConf === void 0 ? void 0 : _getEditorRuntimeConf.inheritParagraphStartStyle) === true);
16165
+ const curCustomRange = getCustomRangeAtPosition(originBody.customRanges ?? [], activeRange.endOffset);
16166
+ const curCustomDecorations = getCustomDecorationAtPosition(originBody.customDecorations ?? [], activeRange.endOffset);
16167
+ return commandService.executeCommand(_univerjs_docs.InsertTextCommand.id, {
16168
+ unitId: docDataModel.getUnitId(),
16169
+ body: {
16170
+ dataStream: value,
16171
+ textRuns: [{
16172
+ ...curTextRun,
16173
+ st: 0,
16174
+ ed: value.length
16175
+ }],
16176
+ customRanges: curCustomRange ? [{
16177
+ ...curCustomRange,
16178
+ startIndex: 0,
16179
+ endIndex: value.length - 1
16180
+ }] : [],
16181
+ customDecorations: curCustomDecorations.map((customDecoration) => ({
16182
+ ...customDecoration,
16183
+ startIndex: 0,
16184
+ endIndex: value.length - 1
16185
+ }))
16186
+ },
16187
+ range: activeRange,
16188
+ segmentId
16189
+ });
15929
16190
  }
15930
16191
  };
15931
16192
 
@@ -16359,54 +16620,6 @@ const DocOpenPageSettingCommand = {
16359
16620
  }
16360
16621
  };
16361
16622
 
16362
- //#endregion
16363
- //#region src/commands/commands/insert-special-character.command.ts
16364
- const InsertSpecialCharacterCommand = {
16365
- id: "doc.command.insert-special-character",
16366
- type: _univerjs_core.CommandType.COMMAND,
16367
- handler: (accessor, params) => {
16368
- var _docDataModel$getSelf, _getEditorRuntimeConf;
16369
- if (!(params === null || params === void 0 ? void 0 : params.value)) return false;
16370
- const commandService = accessor.get(_univerjs_core.ICommandService);
16371
- const docSelectionManagerService = accessor.get(_univerjs_docs.DocSelectionManagerService);
16372
- const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
16373
- const docMenuStyleService = accessor.get(DocMenuStyleService);
16374
- const docDataModel = univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
16375
- const activeRange = docSelectionManagerService.getActiveTextRange();
16376
- if (!docDataModel || !activeRange) return false;
16377
- const { segmentId } = activeRange;
16378
- const originBody = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
16379
- if (!originBody) return false;
16380
- const { value } = params;
16381
- const curTextRun = getTextRunForSelection(originBody, activeRange, docMenuStyleService.getDefaultStyle(), docMenuStyleService.getStyleCache(), false, ((_getEditorRuntimeConf = getEditorRuntimeConfig(docDataModel)) === null || _getEditorRuntimeConf === void 0 ? void 0 : _getEditorRuntimeConf.inheritParagraphStartStyle) === true);
16382
- const curCustomRange = getCustomRangeAtPosition(originBody.customRanges ?? [], activeRange.endOffset);
16383
- const curCustomDecorations = getCustomDecorationAtPosition(originBody.customDecorations ?? [], activeRange.endOffset);
16384
- return commandService.executeCommand(_univerjs_docs.InsertTextCommand.id, {
16385
- unitId: docDataModel.getUnitId(),
16386
- body: {
16387
- dataStream: value,
16388
- textRuns: [{
16389
- ...curTextRun,
16390
- st: 0,
16391
- ed: value.length
16392
- }],
16393
- customRanges: curCustomRange ? [{
16394
- ...curCustomRange,
16395
- startIndex: 0,
16396
- endIndex: value.length - 1
16397
- }] : [],
16398
- customDecorations: curCustomDecorations.map((customDecoration) => ({
16399
- ...customDecoration,
16400
- startIndex: 0,
16401
- endIndex: value.length - 1
16402
- }))
16403
- },
16404
- range: activeRange,
16405
- segmentId
16406
- });
16407
- }
16408
- };
16409
-
16410
16623
  //#endregion
16411
16624
  //#region src/views/const.ts
16412
16625
  /**
@@ -17763,6 +17976,210 @@ function PageSettingMenuItemFactory(accessor) {
17763
17976
  };
17764
17977
  }
17765
17978
 
17979
+ //#endregion
17980
+ //#region src/menu/header-footer-ribbon.ts
17981
+ const headerFooterRibbonSchema = {
17982
+ [_univerjs_ui.ContextMenuPosition.MAIN_AREA]: { [_univerjs_ui.ContextMenuGroup.FORMAT]: { [UpdateSelectedDocFieldsCommand.id]: {
17983
+ order: 1,
17984
+ menuItemFactory: (accessor) => {
17985
+ const instances = accessor.get(_univerjs_core.IUniverInstanceService);
17986
+ const selections = accessor.get(_univerjs_docs.DocSelectionManagerService);
17987
+ return {
17988
+ id: UpdateSelectedDocFieldsCommand.id,
17989
+ type: _univerjs_ui.MenuItemType.BUTTON,
17990
+ title: "docs-ui.headerFooter.refreshFields",
17991
+ disabled$: disableMenuWithoutDocumentUnitPermission(accessor, _univerjs_protocol.UnitAction.Edit),
17992
+ hidden$: (0, rxjs.combineLatest)([instances.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC), selections.textSelection$.pipe((0, rxjs.startWith)(null))]).pipe((0, rxjs.map)(([model]) => !model || !(selections.getTextRanges({
17993
+ unitId: model.getUnitId(),
17994
+ subUnitId: model.getUnitId()
17995
+ }) ?? []).some((selection) => {
17996
+ var _model$getSelfOrHeade;
17997
+ return (_model$getSelfOrHeade = model.getSelfOrHeaderFooterModel(selection.segmentId)) === null || _model$getSelfOrHeade === void 0 || (_model$getSelfOrHeade = _model$getSelfOrHeade.getBody()) === null || _model$getSelfOrHeade === void 0 || (_model$getSelfOrHeade = _model$getSelfOrHeade.customRanges) === null || _model$getSelfOrHeade === void 0 ? void 0 : _model$getSelfOrHeade.some((field) => field.rangeType === _univerjs_core.CustomRangeType.FIELD && selection.startOffset <= field.endIndex && selection.endOffset > field.startIndex);
17998
+ })))
17999
+ };
18000
+ }
18001
+ } } },
18002
+ [_univerjs_ui.MenuManagerPosition.RIBBON]: { [DOC_HEADER_FOOTER_RIBBON_TAB]: {
18003
+ order: 90,
18004
+ title: "docs-ui.toolbar.headerFooter",
18005
+ contextual: true,
18006
+ ...Object.fromEntries([
18007
+ "insertion",
18008
+ "navigation",
18009
+ "options",
18010
+ "position"
18011
+ ].map((kind, order) => [`${DOC_HEADER_FOOTER_RIBBON_TAB}.${kind}`, {
18012
+ order,
18013
+ [`${DOC_HEADER_FOOTER_RIBBON_CONTROL}.${kind}`]: {
18014
+ order: 0,
18015
+ gridLayout: {
18016
+ row: 1,
18017
+ column: 1,
18018
+ rowSpan: 2
18019
+ },
18020
+ menuItemFactory: () => ({
18021
+ id: `${DOC_HEADER_FOOTER_RIBBON_CONTROL}.${kind}`,
18022
+ type: _univerjs_ui.MenuItemType.BUTTON,
18023
+ label: {
18024
+ name: DOC_HEADER_FOOTER_RIBBON_CONTROL,
18025
+ hoverable: false,
18026
+ props: { kind }
18027
+ }
18028
+ })
18029
+ }
18030
+ }])),
18031
+ "docs-ui.headerFooter.close": {
18032
+ order: 5,
18033
+ [CloseHeaderFooterCommand.id]: {
18034
+ order: 0,
18035
+ gridLayout: {
18036
+ row: 1,
18037
+ column: 1,
18038
+ rowSpan: 2,
18039
+ showLabel: true
18040
+ },
18041
+ menuItemFactory: () => ({
18042
+ id: CloseHeaderFooterCommand.id,
18043
+ type: _univerjs_ui.MenuItemType.BUTTON,
18044
+ icon: "CloseIcon",
18045
+ title: "docs-ui.headerFooter.closeHeaderFooter",
18046
+ tooltip: "docs-ui.headerFooter.closeHeaderFooter"
18047
+ })
18048
+ }
18049
+ }
18050
+ } }
18051
+ };
18052
+
18053
+ //#endregion
18054
+ //#region src/controllers/doc-paragraph-setting.controller.ts
18055
+ /**
18056
+ * Copyright 2023-present DreamNum Co., Ltd.
18057
+ *
18058
+ * Licensed under the Apache License, Version 2.0 (the "License");
18059
+ * you may not use this file except in compliance with the License.
18060
+ * You may obtain a copy of the License at
18061
+ *
18062
+ * http://www.apache.org/licenses/LICENSE-2.0
18063
+ *
18064
+ * Unless required by applicable law or agreed to in writing, software
18065
+ * distributed under the License is distributed on an "AS IS" BASIS,
18066
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18067
+ * See the License for the specific language governing permissions and
18068
+ * limitations under the License.
18069
+ */
18070
+ const paragraphSettingIndexKey$1 = "doc_ui_paragraph-setting-panel";
18071
+ let DocParagraphSettingController = class DocParagraphSettingController extends _univerjs_core.Disposable {
18072
+ constructor(_commandService, _sidebarService) {
18073
+ super();
18074
+ this._commandService = _commandService;
18075
+ this._sidebarService = _sidebarService;
18076
+ _defineProperty(this, "_id", void 0);
18077
+ }
18078
+ openPanel() {
18079
+ const props = {
18080
+ header: { title: "docs-ui.doc.slider.paragraphSetting" },
18081
+ id: this._id,
18082
+ children: { label: paragraphSettingIndexKey$1 },
18083
+ width: 300
18084
+ };
18085
+ this._sidebarService.open(props);
18086
+ }
18087
+ closePanel() {
18088
+ this._sidebarService.close(this._id);
18089
+ }
18090
+ };
18091
+ DocParagraphSettingController = __decorate([__decorateParam(0, _univerjs_core.ICommandService), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.ISidebarService))], DocParagraphSettingController);
18092
+
18093
+ //#endregion
18094
+ //#region src/commands/operations/doc-paragraph-setting-panel.operation.ts
18095
+ const DocParagraphSettingPanelOperation = {
18096
+ id: "sidebar.operation.doc-paragraph-setting-panel",
18097
+ type: _univerjs_core.CommandType.OPERATION,
18098
+ handler: (accessor) => {
18099
+ accessor.get(DocParagraphSettingController).openPanel();
18100
+ return true;
18101
+ }
18102
+ };
18103
+
18104
+ //#endregion
18105
+ //#region src/views/section-setting/component-name.ts
18106
+ /**
18107
+ * Copyright 2023-present DreamNum Co., Ltd.
18108
+ *
18109
+ * Licensed under the Apache License, Version 2.0 (the "License");
18110
+ * you may not use this file except in compliance with the License.
18111
+ * You may obtain a copy of the License at
18112
+ *
18113
+ * http://www.apache.org/licenses/LICENSE-2.0
18114
+ *
18115
+ * Unless required by applicable law or agreed to in writing, software
18116
+ * distributed under the License is distributed on an "AS IS" BASIS,
18117
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18118
+ * See the License for the specific language governing permissions and
18119
+ * limitations under the License.
18120
+ */
18121
+ const DOC_SECTION_SETTING_COMPONENT = "doc_ui_section-setting-panel";
18122
+
18123
+ //#endregion
18124
+ //#region src/controllers/doc-section-setting.controller.ts
18125
+ /**
18126
+ * Copyright 2023-present DreamNum Co., Ltd.
18127
+ *
18128
+ * Licensed under the Apache License, Version 2.0 (the "License");
18129
+ * you may not use this file except in compliance with the License.
18130
+ * You may obtain a copy of the License at
18131
+ *
18132
+ * http://www.apache.org/licenses/LICENSE-2.0
18133
+ *
18134
+ * Unless required by applicable law or agreed to in writing, software
18135
+ * distributed under the License is distributed on an "AS IS" BASIS,
18136
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18137
+ * See the License for the specific language governing permissions and
18138
+ * limitations under the License.
18139
+ */
18140
+ let DocSectionSettingController = class DocSectionSettingController extends _univerjs_core.Disposable {
18141
+ constructor(_sidebarService, _selectionManager) {
18142
+ super();
18143
+ this._sidebarService = _sidebarService;
18144
+ this._selectionManager = _selectionManager;
18145
+ _defineProperty(this, "_panelId", "DocSectionSetting");
18146
+ }
18147
+ openPanel() {
18148
+ this._sidebarService.open({
18149
+ header: { title: "docs-ui.doc.slider.sectionSetting" },
18150
+ id: this._panelId,
18151
+ children: { label: DOC_SECTION_SETTING_COMPONENT },
18152
+ width: 300
18153
+ });
18154
+ }
18155
+ closePanel() {
18156
+ this._sidebarService.close(this._panelId);
18157
+ }
18158
+ navigateToSectionEnd(unitId, sectionStart, sectionEnd) {
18159
+ const params = {
18160
+ unitId,
18161
+ subUnitId: unitId
18162
+ };
18163
+ const cursorOffset = Math.max(sectionStart, sectionEnd - 1);
18164
+ this._selectionManager.replaceDocRanges([{
18165
+ startOffset: cursorOffset,
18166
+ endOffset: cursorOffset
18167
+ }], params, true, { shouldFocus: false });
18168
+ }
18169
+ };
18170
+ DocSectionSettingController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ISidebarService)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService))], DocSectionSettingController);
18171
+
18172
+ //#endregion
18173
+ //#region src/commands/operations/doc-section-setting-panel.operation.ts
18174
+ const DocSectionSettingPanelOperation = {
18175
+ id: "sidebar.operation.doc-section-setting-panel",
18176
+ type: _univerjs_core.CommandType.OPERATION,
18177
+ handler: (accessor) => {
18178
+ accessor.get(DocSectionSettingController).openPanel();
18179
+ return true;
18180
+ }
18181
+ };
18182
+
17766
18183
  //#endregion
17767
18184
  //#region src/menu/context-menu.ts
17768
18185
  const getDisableOnCollapsedObservable = (accessor) => {
@@ -19520,6 +19937,9 @@ const menuSchema = {
19520
19937
 
19521
19938
  //#endregion
19522
19939
  //#region src/shortcuts/utils.ts
19940
+ function whenTextEditorFocused(contextService) {
19941
+ return contextService.getContextValue(_univerjs_core.FOCUSING_UNIVER_EDITOR) && !contextService.getContextValue(_univerjs_core.FOCUSING_COMMON_DRAWINGS) && (contextService.getContextValue(_univerjs_core.FOCUSING_DOC) || contextService.getContextValue(_univerjs_core.EDITOR_ACTIVATED) || contextService.getContextValue(_univerjs_core.FOCUSING_FX_BAR_EDITOR));
19942
+ }
19523
19943
  function whenDocAndEditorFocused(contextService) {
19524
19944
  return contextService.getContextValue(_univerjs_core.FOCUSING_DOC) && contextService.getContextValue(_univerjs_core.FOCUSING_UNIVER_EDITOR) && !contextService.getContextValue(_univerjs_core.FOCUSING_COMMON_DRAWINGS);
19525
19945
  }
@@ -19534,6 +19954,11 @@ const TabShortCut = {
19534
19954
  binding: _univerjs_ui.KeyCode.TAB,
19535
19955
  preconditions: whenDocAndEditorFocused
19536
19956
  };
19957
+ const UpdateDocFieldsShortcut = {
19958
+ id: UpdateSelectedDocFieldsCommand.id,
19959
+ binding: _univerjs_ui.KeyCode.F9,
19960
+ preconditions: whenDocAndEditorFocused
19961
+ };
19537
19962
  const ShiftTabShortCut = {
19538
19963
  id: TabCommand.id,
19539
19964
  binding: _univerjs_ui.KeyCode.TAB | _univerjs_ui.MetaKeys.SHIFT,
@@ -20543,21 +20968,6 @@ function DocSideMenuContent() {
20543
20968
 
20544
20969
  //#endregion
20545
20970
  //#region src/controllers/ui.controller.ts
20546
- /**
20547
- * Copyright 2023-present DreamNum Co., Ltd.
20548
- *
20549
- * Licensed under the Apache License, Version 2.0 (the "License");
20550
- * you may not use this file except in compliance with the License.
20551
- * You may obtain a copy of the License at
20552
- *
20553
- * http://www.apache.org/licenses/LICENSE-2.0
20554
- *
20555
- * Unless required by applicable law or agreed to in writing, software
20556
- * distributed under the License is distributed on an "AS IS" BASIS,
20557
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20558
- * See the License for the specific language governing permissions and
20559
- * limitations under the License.
20560
- */
20561
20971
  let DocUIController = class DocUIController extends _univerjs_core.Disposable {
20562
20972
  constructor(_injector, _commandService, _layoutService, _menuManagerService, _uiPartsService, _univerInstanceService, _shortcutService, _configService, _embedInteractionBoundaryService, _embedRuntimeFocusCoordinator) {
20563
20973
  super();
@@ -20579,6 +20989,7 @@ let DocUIController = class DocUIController extends _univerjs_core.Disposable {
20579
20989
  _initMenus() {
20580
20990
  this._menuManagerService.appendRootMenu(floatToolbarMenuSchema);
20581
20991
  this._menuManagerService.mergeMenu(menuSchema);
20992
+ this._menuManagerService.mergeMenu(headerFooterRibbonSchema);
20582
20993
  }
20583
20994
  _initShortCut() {
20584
20995
  [
@@ -20594,7 +21005,8 @@ let DocUIController = class DocUIController extends _univerjs_core.Disposable {
20594
21005
  AlignLeftShortCut,
20595
21006
  OrderListShortCut,
20596
21007
  BulletListShortCut,
20597
- TabShortCut
21008
+ TabShortCut,
21009
+ UpdateDocFieldsShortcut
20598
21010
  ].forEach((shortcut) => {
20599
21011
  this.disposeWithMe(this._shortcutService.registerShortcut(shortcut));
20600
21012
  });
@@ -20603,6 +21015,7 @@ let DocUIController = class DocUIController extends _univerjs_core.Disposable {
20603
21015
  this._initMenus();
20604
21016
  this._initFocusHandler();
20605
21017
  this._initCommands();
21018
+ this._initDateTimeFields();
20606
21019
  this._initUiParts();
20607
21020
  this._initShortCut();
20608
21021
  }
@@ -20611,10 +21024,25 @@ let DocUIController = class DocUIController extends _univerjs_core.Disposable {
20611
21024
  OpenDocPermissionPanelOperation,
20612
21025
  OpenDocParagraphPermissionOperation,
20613
21026
  CoreHeaderFooterCommand,
21027
+ InsertHeaderFooterFieldCommand,
21028
+ RefreshHeaderFooterFieldsCommand,
21029
+ UpdateSelectedDocFieldsCommand,
20614
21030
  OpenHeaderFooterPanelCommand,
20615
- SidebarDocHeaderFooterPanelOperation
21031
+ DocHeaderFooterRibbonOperation
20616
21032
  ].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
20617
21033
  }
21034
+ _initDateTimeFields() {
21035
+ const refreshed = /* @__PURE__ */ new WeakSet();
21036
+ this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC).subscribe((model) => {
21037
+ if (model && !refreshed.has(model)) {
21038
+ refreshed.add(model);
21039
+ this._commandService.syncExecuteCommand(RefreshHeaderFooterFieldsCommand.id, {
21040
+ unitId: model.getUnitId(),
21041
+ onOpen: true
21042
+ });
21043
+ }
21044
+ }));
21045
+ }
20618
21046
  _initFocusHandler() {
20619
21047
  this.disposeWithMe(this._layoutService.registerFocusHandler(_univerjs_core.UniverInstanceType.UNIVER_DOC, (unitId) => {
20620
21048
  if (this._shouldPreserveEmbedFocus(unitId)) return;
@@ -20912,7 +21340,7 @@ function resolveDocsCustomBlockRenderViewport(params) {
20912
21340
  //#endregion
20913
21341
  //#region package.json
20914
21342
  var name = "@univerjs/docs-ui";
20915
- var version = "1.0.3";
21343
+ var version = "1.0.4";
20916
21344
 
20917
21345
  //#endregion
20918
21346
  //#region src/commands/commands/doc-paragraph-setting.command.ts
@@ -21159,8 +21587,8 @@ var HeaderFooterContentCover = class extends _univerjs_engine_render.BaseObject
21159
21587
  right: pageLeft + page.pageWidth,
21160
21588
  bottom: pageTop + page.pageHeight
21161
21589
  });
21162
- const header = (_data$skeHeaders$get = data.skeHeaders.get(page.headerId)) === null || _data$skeHeaders$get === void 0 ? void 0 : _data$skeHeaders$get.get(page.pageWidth);
21163
- const footer = (_data$skeFooters$get = data.skeFooters.get(page.footerId)) === null || _data$skeFooters$get === void 0 ? void 0 : _data$skeFooters$get.get(page.pageWidth);
21590
+ const header = (_data$skeHeaders$get = data.skeHeaders.get(page.headerId)) === null || _data$skeHeaders$get === void 0 ? void 0 : _data$skeHeaders$get.get(page.headerLayoutKey ?? page.pageWidth);
21591
+ const footer = (_data$skeFooters$get = data.skeFooters.get(page.footerId)) === null || _data$skeFooters$get === void 0 ? void 0 : _data$skeFooters$get.get(page.footerLayoutKey ?? page.pageWidth);
21164
21592
  const local = [];
21165
21593
  if (header) this._collectTextAndTables(header, pageLeft + page.marginLeft, pageTop + header.marginTop, local);
21166
21594
  if (footer) this._collectTextAndTables(footer, pageLeft + page.marginLeft, pageTop + page.pageHeight - footer.height - footer.marginBottom, local);
@@ -21618,7 +22046,7 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
21618
22046
  const body = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(normalizedSegmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
21619
22047
  if (body == null) return;
21620
22048
  const dataStreamLength = body.dataStream.length ?? Number.POSITIVE_INFINITY;
21621
- const customRanges = docDataModel.getCustomRanges() ?? [];
22049
+ const customRanges = body.customRanges ?? [];
21622
22050
  if (granularity !== "character") {
21623
22051
  const nextOffset = this._getCursorOffsetByGranularity(skeleton, focusOffset, direction, granularity, normalizedSegmentId, normalizedSegmentPage, dataStreamLength, body.dataStream);
21624
22052
  if (nextOffset == null || nextOffset === focusOffset) return;
@@ -21690,7 +22118,7 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
21690
22118
  const body = (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(normalizedSegmentId)) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.getBody();
21691
22119
  if (body == null) return;
21692
22120
  const dataStreamLength = body.dataStream.length ?? Number.POSITIVE_INFINITY;
21693
- const customRanges = docDataModel.getCustomRanges() ?? [];
22121
+ const customRanges = body.customRanges ?? [];
21694
22122
  if (granularity !== "character") {
21695
22123
  let cursorOffset;
21696
22124
  if (!activeRange.collapsed || allRanges.length > 1) {
@@ -22313,26 +22741,33 @@ function DocPasteOptions() {
22313
22741
  const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
22314
22742
  const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
22315
22743
  const layoutService = (0, _univerjs_ui.useDependency)(_univerjs_ui.ILayoutService);
22744
+ const editorService = (0, _univerjs_ui.useDependency)(IEditorService);
22316
22745
  const state = (0, _univerjs_ui.useObservable)(clipboard.pasteOptions$, null);
22317
22746
  const [busy, setBusy] = (0, react.useState)(false);
22318
22747
  const [open, setOpen] = (0, react.useState)(false);
22748
+ const focusEditor = () => {
22749
+ const editor = state && clipboard.isPasteOptionsEnabled(state.unitId) && editorService.getEditor(state.unitId);
22750
+ if (editor) editor.focus();
22751
+ else layoutService.focus();
22752
+ };
22319
22753
  const changeMode = async (value) => {
22320
22754
  setBusy(true);
22321
22755
  try {
22322
22756
  await commandService.executeCommand(DocChangePasteModeCommand.id, { value });
22323
22757
  } finally {
22324
22758
  setBusy(false);
22325
- layoutService.focus();
22759
+ focusEditor();
22326
22760
  }
22327
22761
  };
22328
22762
  if (!state) return null;
22329
22763
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DropdownMenu, {
22764
+ "data-u-editor-interaction-boundary": "true",
22330
22765
  align: "start",
22331
22766
  open,
22332
22767
  onOpenChange: setOpen,
22333
22768
  onCloseAutoFocus: (event) => {
22334
22769
  event.preventDefault();
22335
- layoutService.focus();
22770
+ focusEditor();
22336
22771
  },
22337
22772
  onEscapeKeyDown: () => clipboard.dismissPasteOptions(),
22338
22773
  items: DOC_PASTE_OPTIONS.map((option) => ({
@@ -22344,6 +22779,7 @@ function DocPasteOptions() {
22344
22779
  onSelect: () => changeMode(option.value)
22345
22780
  })),
22346
22781
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.Button, {
22782
+ "data-u-editor-interaction-boundary": "true",
22347
22783
  size: "small",
22348
22784
  disabled: busy,
22349
22785
  "aria-label": localeService.t("docs-ui.pasteOptions.title"),
@@ -22352,7 +22788,7 @@ function DocPasteOptions() {
22352
22788
  onKeyDown: (event) => {
22353
22789
  if (event.key === "Escape") {
22354
22790
  clipboard.dismissPasteOptions();
22355
- layoutService.focus();
22791
+ focusEditor();
22356
22792
  }
22357
22793
  },
22358
22794
  className: "univer-shadow-sm",
@@ -22611,28 +23047,37 @@ function useHeaderFooterOptions(unitId) {
22611
23047
  page
22612
23048
  };
22613
23049
  };
22614
- const [options, setOptions] = (0, react.useState)(() => {
22615
- var _getCurrentSectionCon;
22616
- const config = (_getCurrentSectionCon = getCurrentSectionContext()) === null || _getCurrentSectionCon === void 0 ? void 0 : _getCurrentSectionCon.config;
22617
- return {
22618
- marginHeader: (config === null || config === void 0 ? void 0 : config.marginHeader) ?? 0,
22619
- marginFooter: (config === null || config === void 0 ? void 0 : config.marginFooter) ?? 0,
22620
- useFirstPageHeaderFooter: (config === null || config === void 0 ? void 0 : config.useFirstPageHeaderFooter) ?? _univerjs_core.BooleanNumber.FALSE,
22621
- evenAndOddHeaders: (config === null || config === void 0 ? void 0 : config.evenAndOddHeaders) ?? _univerjs_core.BooleanNumber.FALSE
23050
+ const [, refresh] = (0, react.useReducer)((revision) => revision + 1, 0);
23051
+ (0, react.useEffect)(() => {
23052
+ const commandListener = commandService.onCommandExecuted((command) => {
23053
+ var _command$params;
23054
+ if (command.id === _univerjs_docs.RichTextEditingMutation.id && ((_command$params = command.params) === null || _command$params === void 0 ? void 0 : _command$params.unitId) === unitId) refresh();
23055
+ });
23056
+ const segmentListener = docSelectionRenderService.segmentContext$.subscribe(() => refresh());
23057
+ return () => {
23058
+ commandListener.dispose();
23059
+ segmentListener.unsubscribe();
22622
23060
  };
22623
- });
23061
+ }, [
23062
+ commandService,
23063
+ docSelectionRenderService,
23064
+ unitId
23065
+ ]);
22624
23066
  const sectionContext = getCurrentSectionContext();
23067
+ const config = sectionContext === null || sectionContext === void 0 ? void 0 : sectionContext.config;
23068
+ const options = {
23069
+ marginHeader: (config === null || config === void 0 ? void 0 : config.marginHeader) ?? 0,
23070
+ marginFooter: (config === null || config === void 0 ? void 0 : config.marginFooter) ?? 0,
23071
+ useFirstPageHeaderFooter: (config === null || config === void 0 ? void 0 : config.useFirstPageHeaderFooter) ?? _univerjs_core.BooleanNumber.FALSE,
23072
+ evenAndOddHeaders: (config === null || config === void 0 ? void 0 : config.evenAndOddHeaders) ?? _univerjs_core.BooleanNumber.FALSE
23073
+ };
22625
23074
  const headerFooterKind = ((_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";
22626
23075
  const variant = getHeaderFooterVariant((sectionContext === null || sectionContext === void 0 ? void 0 : sectionContext.config) ?? {}, docSelectionRenderService.getSegmentPage(), sectionContext === null || sectionContext === void 0 ? void 0 : sectionContext.page);
22627
23076
  const referenceKey = (0, _univerjs_core.getSectionHeaderFooterReferenceKey)(headerFooterKind, variant);
22628
23077
  const canLinkToPrevious = ((sectionContext === null || sectionContext === void 0 ? void 0 : sectionContext.sectionIndex) ?? -1) > 0;
22629
- 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]));
22630
- const handleCheckboxChange = (val, type) => {
23078
+ const linkedToPrevious = canLinkToPrevious && !(sectionContext === null || sectionContext === void 0 || (_sectionContext$secti = sectionContext.section) === null || _sectionContext$secti === void 0 ? void 0 : _sectionContext$secti[referenceKey]);
23079
+ const handleCheckboxChange = async (val, type) => {
22631
23080
  var _renderManagerService3;
22632
- setOptions((prev) => ({
22633
- ...prev,
22634
- [type]: val ? _univerjs_core.BooleanNumber.TRUE : _univerjs_core.BooleanNumber.FALSE
22635
- }));
22636
23081
  const sectionContext = getCurrentSectionContext();
22637
23082
  const documentStyle = sectionContext === null || sectionContext === void 0 ? void 0 : sectionContext.config;
22638
23083
  const docSkeletonManagerService = (_renderManagerService3 = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService3 === void 0 ? void 0 : _renderManagerService3.with(_univerjs_docs.DocSkeletonManagerService);
@@ -22657,7 +23102,7 @@ function useHeaderFooterOptions(unitId) {
22657
23102
  if (needCreateHeaderFooter) {
22658
23103
  const segmentId = (0, _univerjs_core.generateRandomId)(6);
22659
23104
  if (needChangeSegmentId) docSelectionRenderService.setSegment(segmentId);
22660
- commandService.executeCommand(CoreHeaderFooterCommandId, {
23105
+ await commandService.executeCommand(CoreHeaderFooterCommandId, {
22661
23106
  unitId,
22662
23107
  segmentId,
22663
23108
  headerFooterProps: { [type]: val ? _univerjs_core.BooleanNumber.TRUE : _univerjs_core.BooleanNumber.FALSE },
@@ -22671,7 +23116,7 @@ function useHeaderFooterOptions(unitId) {
22671
23116
  [type]: val ? _univerjs_core.BooleanNumber.TRUE : _univerjs_core.BooleanNumber.FALSE
22672
23117
  }, editArea, segmentPageIndex, sectionContext === null || sectionContext === void 0 ? void 0 : sectionContext.page);
22673
23118
  if (needFocusSegmentId && needFocusSegmentId !== prevSegmentId) docSelectionRenderService.setSegment(needFocusSegmentId);
22674
- commandService.executeCommand(CoreHeaderFooterCommandId, {
23119
+ await commandService.executeCommand(CoreHeaderFooterCommandId, {
22675
23120
  unitId,
22676
23121
  headerFooterProps: { [type]: val ? _univerjs_core.BooleanNumber.TRUE : _univerjs_core.BooleanNumber.FALSE },
22677
23122
  sectionId: sectionContext === null || sectionContext === void 0 ? void 0 : sectionContext.sectionId
@@ -22680,21 +23125,16 @@ function useHeaderFooterOptions(unitId) {
22680
23125
  layoutService.focus();
22681
23126
  };
22682
23127
  const handleMarginChange = async (val, type) => {
22683
- var _getCurrentSectionCon2;
22684
- setOptions((prev) => ({
22685
- ...prev,
22686
- [type]: val
22687
- }));
23128
+ var _getCurrentSectionCon;
22688
23129
  await commandService.executeCommand(CoreHeaderFooterCommandId, {
22689
23130
  unitId,
22690
23131
  headerFooterProps: { [type]: val },
22691
- sectionId: (_getCurrentSectionCon2 = getCurrentSectionContext()) === null || _getCurrentSectionCon2 === void 0 ? void 0 : _getCurrentSectionCon2.sectionId
23132
+ sectionId: (_getCurrentSectionCon = getCurrentSectionContext()) === null || _getCurrentSectionCon === void 0 ? void 0 : _getCurrentSectionCon.sectionId
22692
23133
  });
22693
- docSelectionRenderService.removeAllRanges();
22694
23134
  docSelectionRenderService.blur();
22695
23135
  };
22696
23136
  const closeHeaderFooter = () => {
22697
- commandService.executeCommand(CloseHeaderFooterCommand.id, { unitId });
23137
+ return commandService.executeCommand(CloseHeaderFooterCommand.id, { unitId });
22698
23138
  };
22699
23139
  const handleLinkToPreviousChange = async (linked) => {
22700
23140
  var _renderManagerService4;
@@ -22713,7 +23153,6 @@ function useHeaderFooterOptions(unitId) {
22713
23153
  linkedToPrevious: linked,
22714
23154
  ...linked ? {} : { segmentId }
22715
23155
  })) return;
22716
- setLinkedToPrevious(linked);
22717
23156
  docSelectionRenderService.setSegment(linked ? previousSegmentId ?? "" : segmentId);
22718
23157
  layoutService.focus();
22719
23158
  };
@@ -25415,9 +25854,9 @@ let DocPasteOptionsRenderController = class DocPasteOptionsRenderController exte
25415
25854
  this._context = _context;
25416
25855
  this._clipboard = _clipboard;
25417
25856
  _defineProperty(this, "_popup", void 0);
25418
- if ((0, _univerjs_core.isInternalEditorID)(_context.unitId)) return;
25419
25857
  const mobile = contextService.getContextValue(_univerjs_ui.MOBILE_UI_MODE) === true;
25420
25858
  this.disposeWithMe(selection.onKeydown$.subscribe(({ event }) => {
25859
+ if (!this._clipboard.isPasteOptionsEnabled(this._context.unitId)) return;
25421
25860
  const key = event;
25422
25861
  if ((key.ctrlKey || key.metaKey) && key.shiftKey && key.key.toLowerCase() === "v") this._clipboard.setNextPasteMode("text");
25423
25862
  else if (![
@@ -25430,12 +25869,17 @@ let DocPasteOptionsRenderController = class DocPasteOptionsRenderController exte
25430
25869
  this._clipboard.dismissPasteOptions();
25431
25870
  }
25432
25871
  }));
25433
- this.disposeWithMe(selection.onInputBefore$.subscribe(() => this._clipboard.dismissPasteOptions()));
25872
+ this.disposeWithMe(selection.onInputBefore$.subscribe(() => {
25873
+ if (this._clipboard.isPasteOptionsEnabled(this._context.unitId)) this._clipboard.dismissPasteOptions();
25874
+ }));
25434
25875
  this.disposeWithMe(selection.onPointerDown$.subscribe(() => {
25876
+ if (!this._clipboard.isPasteOptionsEnabled(this._context.unitId)) return;
25435
25877
  this._clipboard.setNextPasteMode("source");
25436
25878
  if (!mobile) this._clipboard.dismissPasteOptions();
25437
25879
  }));
25438
- this.disposeWithMe(selection.onBlur$.subscribe(() => this._clipboard.setNextPasteMode("source")));
25880
+ this.disposeWithMe(selection.onBlur$.subscribe(() => {
25881
+ if (this._clipboard.isPasteOptionsEnabled(this._context.unitId)) this._clipboard.setNextPasteMode("source");
25882
+ }));
25439
25883
  this.disposeWithMe(this._clipboard.pasteOptions$.subscribe((state) => {
25440
25884
  var _this$_popup;
25441
25885
  (_this$_popup = this._popup) === null || _this$_popup === void 0 || _this$_popup.dispose();
@@ -25455,7 +25899,7 @@ let DocPasteOptionsRenderController = class DocPasteOptionsRenderController exte
25455
25899
  this.disposeWithMe(() => {
25456
25900
  var _this$_popup2;
25457
25901
  (_this$_popup2 = this._popup) === null || _this$_popup2 === void 0 || _this$_popup2.dispose();
25458
- this._clipboard.dismissPasteOptions();
25902
+ if (this._popup) this._clipboard.dismissPasteOptions();
25459
25903
  });
25460
25904
  }
25461
25905
  };
@@ -26492,8 +26936,8 @@ var DocPrintInterceptorService = class extends _univerjs_core.Disposable {
26492
26936
  const page = data.pages[pageIndex];
26493
26937
  if (!page) return drawingIds;
26494
26938
  collectPageDrawingIds(page, drawingIds);
26495
- const header = (_data$skeHeaders$get = data.skeHeaders.get(page.headerId)) === null || _data$skeHeaders$get === void 0 ? void 0 : _data$skeHeaders$get.get(page.pageWidth);
26496
- const footer = (_data$skeFooters$get = data.skeFooters.get(page.footerId)) === null || _data$skeFooters$get === void 0 ? void 0 : _data$skeFooters$get.get(page.pageWidth);
26939
+ const header = (_data$skeHeaders$get = data.skeHeaders.get(page.headerId)) === null || _data$skeHeaders$get === void 0 ? void 0 : _data$skeHeaders$get.get(page.headerLayoutKey ?? page.pageWidth);
26940
+ const footer = (_data$skeFooters$get = data.skeFooters.get(page.footerId)) === null || _data$skeFooters$get === void 0 ? void 0 : _data$skeFooters$get.get(page.footerLayoutKey ?? page.pageWidth);
26497
26941
  if (header) collectPageDrawingIds(header, drawingIds);
26498
26942
  if (footer) collectPageDrawingIds(footer, drawingIds);
26499
26943
  return drawingIds;
@@ -27494,6 +27938,319 @@ UniverDocsMobileUIPlugin = __decorate([
27494
27938
  __decorateParam(4, _univerjs_core.IConfigService)
27495
27939
  ], UniverDocsMobileUIPlugin);
27496
27940
 
27941
+ //#endregion
27942
+ //#region src/views/header-footer/panel/DocHeaderFooterFields.tsx
27943
+ function DocHeaderFooterFields({ unitId, disabled }) {
27944
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
27945
+ (0, _univerjs_ui.useObservable)(localeService.currentLocale$);
27946
+ const commands = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
27947
+ const layout = (0, _univerjs_ui.useDependency)(_univerjs_ui.ILayoutService);
27948
+ const shortcuts = (0, _univerjs_ui.useDependency)(_univerjs_ui.IShortcutService);
27949
+ const selections = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocSelectionManagerService);
27950
+ const instances = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
27951
+ const [target, setTarget] = (0, react.useState)(null);
27952
+ const [format, setFormat] = (0, react.useState)("short");
27953
+ const [automatic, setAutomatic] = (0, react.useState)(true);
27954
+ const [error, setError] = (0, react.useState)(false);
27955
+ const [previewDate, setPreviewDate] = (0, react.useState)(() => /* @__PURE__ */ new Date());
27956
+ const locale = _univerjs_core.LOCALE_META[localeService.getCurrentLocale()].tag;
27957
+ const dialogOpen = target !== null;
27958
+ const dialogFocusRef = (0, react.useRef)(null);
27959
+ (0, react.useEffect)(() => {
27960
+ var _instances$getFocused;
27961
+ if (dialogOpen) return;
27962
+ const focus = dialogFocusRef.current;
27963
+ dialogFocusRef.current = null;
27964
+ if ((focus === null || focus === void 0 ? void 0 : focus.unitId) === unitId && instances.getUnit(unitId) && ((_instances$getFocused = instances.getFocusedUnit()) === null || _instances$getFocused === void 0 ? void 0 : _instances$getFocused.getUnitId()) === focus.focusedUnitId) layout.focus(unitId);
27965
+ }, [
27966
+ dialogOpen,
27967
+ instances,
27968
+ layout,
27969
+ unitId
27970
+ ]);
27971
+ (0, react.useEffect)(() => {
27972
+ if (!dialogOpen) return;
27973
+ const escape = shortcuts.forceEscape();
27974
+ return () => escape.dispose();
27975
+ }, [dialogOpen, shortcuts]);
27976
+ function restoreFocus(event) {
27977
+ event.preventDefault();
27978
+ layout.focus(unitId);
27979
+ }
27980
+ function openDateTime() {
27981
+ var _instances$getUnit, _instances$getFocused2;
27982
+ const selection = selections.getActiveTextRange();
27983
+ const body = (_instances$getUnit = instances.getUnit(unitId)) === null || _instances$getUnit === void 0 || (_instances$getUnit = _instances$getUnit.getSelfOrHeaderFooterModel(selection === null || selection === void 0 ? void 0 : selection.segmentId)) === null || _instances$getUnit === void 0 ? void 0 : _instances$getUnit.getBody();
27984
+ if (!(selection === null || selection === void 0 ? void 0 : selection.segmentId) || !body) return;
27985
+ dialogFocusRef.current = {
27986
+ unitId,
27987
+ focusedUnitId: (_instances$getFocused2 = instances.getFocusedUnit()) === null || _instances$getFocused2 === void 0 ? void 0 : _instances$getFocused2.getUnitId()
27988
+ };
27989
+ setTarget({
27990
+ unitId,
27991
+ selection: { ...selection },
27992
+ segmentId: selection.segmentId,
27993
+ segmentPage: selection.segmentPage,
27994
+ expectedDataStream: body.dataStream
27995
+ });
27996
+ setPreviewDate(/* @__PURE__ */ new Date());
27997
+ setError(false);
27998
+ }
27999
+ async function insertDateTime() {
28000
+ if (!target) return;
28001
+ if (await commands.executeCommand(InsertHeaderFooterFieldCommand.id, {
28002
+ ...target,
28003
+ fieldType: format === "time" ? "TIME" : "DATE",
28004
+ format,
28005
+ automatic
28006
+ })) setTarget(null);
28007
+ else setError(true);
28008
+ }
28009
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
28010
+ className: "univer-flex univer-flex-col univer-gap-1 univer-text-xs",
28011
+ children: [
28012
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DropdownMenu, {
28013
+ onCloseAutoFocus: restoreFocus,
28014
+ disabled,
28015
+ items: [
28016
+ {
28017
+ type: "item",
28018
+ children: localeService.t("docs-ui.headerFooter.currentPage"),
28019
+ onSelect: () => commands.executeCommand(InsertHeaderFooterFieldCommand.id, {
28020
+ unitId,
28021
+ fieldType: "PAGE"
28022
+ })
28023
+ },
28024
+ {
28025
+ type: "item",
28026
+ children: localeService.t("docs-ui.headerFooter.totalPages"),
28027
+ onSelect: () => commands.executeCommand(InsertHeaderFooterFieldCommand.id, {
28028
+ unitId,
28029
+ fieldType: "NUMPAGES"
28030
+ })
28031
+ },
28032
+ { type: "separator" },
28033
+ {
28034
+ type: "item",
28035
+ children: localeService.t("docs-ui.headerFooter.refreshFields"),
28036
+ onSelect: () => commands.executeCommand(RefreshHeaderFooterFieldsCommand.id, { unitId })
28037
+ }
28038
+ ],
28039
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.Button, {
28040
+ className: "univer-justify-start",
28041
+ "data-u-command": InsertHeaderFooterFieldCommand.id,
28042
+ size: "small",
28043
+ variant: "text",
28044
+ disabled,
28045
+ onMouseDown: (event) => event.preventDefault(),
28046
+ children: [
28047
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.NumberIcon, { "aria-hidden": "true" }),
28048
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
28049
+ className: "univer-flex-1 univer-text-start",
28050
+ children: localeService.t("docs-ui.headerFooter.pageNumber")
28051
+ }),
28052
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { "aria-hidden": "true" })
28053
+ ]
28054
+ })
28055
+ }),
28056
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.Button, {
28057
+ className: "univer-justify-start",
28058
+ "data-u-command": InsertHeaderFooterFieldCommand.id,
28059
+ size: "small",
28060
+ variant: "text",
28061
+ disabled,
28062
+ onMouseDown: (event) => event.preventDefault(),
28063
+ onClick: openDateTime,
28064
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CalendarIcon, { "aria-hidden": "true" }), localeService.t("docs-ui.headerFooter.dateTime")]
28065
+ }),
28066
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dialog, {
28067
+ open: dialogOpen,
28068
+ width: 360,
28069
+ title: localeService.t("docs-ui.headerFooter.dateTime"),
28070
+ showOk: true,
28071
+ showCancel: true,
28072
+ onClose: () => setTarget(null),
28073
+ onCancel: () => setTarget(null),
28074
+ onOk: insertDateTime,
28075
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
28076
+ className: "univer-flex univer-flex-col univer-gap-4",
28077
+ children: [
28078
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DropdownMenu, {
28079
+ align: "start",
28080
+ className: "univer-w-[--radix-popper-anchor-width]",
28081
+ items: [{
28082
+ type: "radio",
28083
+ value: format,
28084
+ hideIndicator: true,
28085
+ onSelect: (value) => setFormat(value),
28086
+ options: [
28087
+ "short",
28088
+ "long",
28089
+ "time"
28090
+ ].map((value) => ({
28091
+ value,
28092
+ label: createDateTimeField(value, locale, previewDate).cachedResult
28093
+ }))
28094
+ }],
28095
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.Button, {
28096
+ "aria-label": localeService.t("docs-ui.headerFooter.dateTime"),
28097
+ className: _univerjs_design.selectClassName,
28098
+ "data-u-comp": "select",
28099
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
28100
+ className: "univer-flex-1 univer-truncate univer-text-start",
28101
+ children: createDateTimeField(format, locale, previewDate).cachedResult
28102
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { "aria-hidden": "true" })]
28103
+ })
28104
+ }),
28105
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
28106
+ checked: automatic,
28107
+ onChange: (value) => setAutomatic(Boolean(value)),
28108
+ children: localeService.t("docs-ui.headerFooter.updateAutomatically")
28109
+ }),
28110
+ error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
28111
+ role: "alert",
28112
+ children: localeService.t("docs-ui.headerFooter.insertFailed")
28113
+ })
28114
+ ]
28115
+ })
28116
+ })
28117
+ ]
28118
+ });
28119
+ }
28120
+
28121
+ //#endregion
28122
+ //#region src/views/header-footer/panel/DocHeaderFooterRibbonControl.tsx
28123
+ function DocHeaderFooterRibbonControl(props) {
28124
+ const instances = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
28125
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
28126
+ (0, _univerjs_ui.useObservable)(localeService.currentLocale$);
28127
+ const document = (0, _univerjs_ui.useObservable)(() => instances.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC), void 0, false, [instances]);
28128
+ const containerRef = (0, react.useRef)(null);
28129
+ const [compact, setCompact] = (0, react.useState)(false);
28130
+ const { kind } = props;
28131
+ (0, react.useEffect)(() => {
28132
+ var _containerRef$current;
28133
+ const toolbar = (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.closest("[role=\"toolbar\"]");
28134
+ if (!toolbar || kind === "insertion") return;
28135
+ const thresholds = {
28136
+ position: 1100,
28137
+ options: 900,
28138
+ navigation: 650
28139
+ };
28140
+ const resize = () => setCompact(toolbar.getBoundingClientRect().width < thresholds[kind]);
28141
+ const observer = new ResizeObserver(resize);
28142
+ observer.observe(toolbar);
28143
+ return () => observer.disconnect();
28144
+ }, [kind, document]);
28145
+ if (!document) return null;
28146
+ const content = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HeaderFooterRibbonControl, {
28147
+ ...props,
28148
+ unitId: document.getUnitId()
28149
+ }, document.getUnitId());
28150
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
28151
+ ref: containerRef,
28152
+ "data-u-command": OpenHeaderFooterPanelCommand.id,
28153
+ className: "univer-flex univer-items-center univer-whitespace-nowrap",
28154
+ children: compact && kind !== "insertion" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DropdownMenu, {
28155
+ items: [{
28156
+ type: "custom",
28157
+ className: "univer-p-2",
28158
+ children: content
28159
+ }],
28160
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
28161
+ "data-u-command": OpenHeaderFooterPanelCommand.id,
28162
+ size: "small",
28163
+ variant: "text",
28164
+ onMouseDown: (event) => event.preventDefault(),
28165
+ children: localeService.t(`docs-ui.headerFooter.${kind}`)
28166
+ })
28167
+ }) : content
28168
+ });
28169
+ }
28170
+ function HeaderFooterRibbonControl({ kind, unitId }) {
28171
+ var _instances$getUnit, _renders$getRenderUni;
28172
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
28173
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
28174
+ const renders = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
28175
+ const permissionService = (0, _univerjs_ui.useDependency)(_univerjs_core.IPermissionService);
28176
+ (0, _univerjs_ui.useObservable)(permissionService.permissionPointUpdate$);
28177
+ const instances = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
28178
+ const disabled = Boolean((_instances$getUnit = instances.getUnit(unitId)) === null || _instances$getUnit === void 0 ? void 0 : _instances$getUnit.getSnapshot().disabled) || !(0, _univerjs_docs.getDocumentPermissionValue)(permissionService, unitId, unitId, _univerjs_protocol.UnitAction.Edit);
28179
+ const { canLinkToPrevious, linkedToPrevious, options, handleLinkToPreviousChange, handleCheckboxChange, handleMarginChange } = useHeaderFooterOptions(unitId);
28180
+ const area = (_renders$getRenderUni = renders.getRenderUnitById(unitId)) === null || _renders$getRenderUni === void 0 ? void 0 : _renders$getRenderUni.with(_univerjs_docs.DocSkeletonManagerService).getViewModel().getEditArea();
28181
+ if (kind === "insertion") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocHeaderFooterFields, {
28182
+ unitId,
28183
+ disabled
28184
+ });
28185
+ if (kind === "navigation") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
28186
+ className: "univer-grid univer-grid-cols-[auto_auto] univer-items-center univer-gap-x-2 univer-gap-y-1 univer-text-start univer-text-xs",
28187
+ children: [
28188
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
28189
+ "data-u-command": OpenHeaderFooterPanelCommand.id,
28190
+ size: "small",
28191
+ variant: "text",
28192
+ disabled: disabled || area === _univerjs_engine_render.DocumentEditArea.HEADER,
28193
+ onMouseDown: (event) => event.preventDefault(),
28194
+ onClick: () => commandService.executeCommand(OpenHeaderFooterPanelCommand.id, { editArea: _univerjs_engine_render.DocumentEditArea.HEADER }),
28195
+ children: localeService.t("docs-ui.headerFooter.goToHeader")
28196
+ }),
28197
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
28198
+ disabled: disabled || !canLinkToPrevious,
28199
+ checked: linkedToPrevious,
28200
+ onChange: (value) => handleLinkToPreviousChange(Boolean(value)),
28201
+ children: localeService.t("docs-ui.headerFooter.linkToPrevious")
28202
+ }),
28203
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
28204
+ "data-u-command": OpenHeaderFooterPanelCommand.id,
28205
+ size: "small",
28206
+ variant: "text",
28207
+ disabled: disabled || area === _univerjs_engine_render.DocumentEditArea.FOOTER,
28208
+ onMouseDown: (event) => event.preventDefault(),
28209
+ onClick: () => commandService.executeCommand(OpenHeaderFooterPanelCommand.id, { editArea: _univerjs_engine_render.DocumentEditArea.FOOTER }),
28210
+ children: localeService.t("docs-ui.headerFooter.goToFooter")
28211
+ })
28212
+ ]
28213
+ });
28214
+ if (kind === "options") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
28215
+ className: "univer-flex univer-flex-col univer-gap-2 univer-text-start univer-text-xs",
28216
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
28217
+ disabled,
28218
+ checked: options.useFirstPageHeaderFooter === _univerjs_core.BooleanNumber.TRUE,
28219
+ onChange: (value) => handleCheckboxChange(Boolean(value), "useFirstPageHeaderFooter"),
28220
+ children: localeService.t("docs-ui.headerFooter.firstPageCheckBox")
28221
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
28222
+ disabled,
28223
+ checked: options.evenAndOddHeaders === _univerjs_core.BooleanNumber.TRUE,
28224
+ onChange: (value) => handleCheckboxChange(Boolean(value), "evenAndOddHeaders"),
28225
+ children: localeService.t("docs-ui.headerFooter.oddEvenCheckBox")
28226
+ })]
28227
+ });
28228
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
28229
+ className: "univer-flex univer-flex-col univer-gap-1 univer-text-start univer-text-xs",
28230
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
28231
+ className: "univer-grid univer-grid-cols-[1fr_5rem] univer-items-center univer-gap-x-2",
28232
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("docs-ui.headerFooter.headerTopMargin") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
28233
+ disabled,
28234
+ min: 0,
28235
+ max: 200,
28236
+ precision: 1,
28237
+ value: options.marginHeader,
28238
+ onChange: (value) => handleMarginChange(value ?? 0, "marginHeader")
28239
+ })]
28240
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
28241
+ className: "univer-grid univer-grid-cols-[1fr_5rem] univer-items-center univer-gap-x-2",
28242
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("docs-ui.headerFooter.footerBottomMargin") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
28243
+ disabled,
28244
+ min: 0,
28245
+ max: 200,
28246
+ precision: 1,
28247
+ value: options.marginFooter,
28248
+ onChange: (value) => handleMarginChange(value ?? 0, "marginFooter")
28249
+ })]
28250
+ })]
28251
+ });
28252
+ }
28253
+
27497
28254
  //#endregion
27498
28255
  //#region src/views/paragraph-menu/component-keys.ts
27499
28256
  /**
@@ -29289,6 +30046,7 @@ let ComponentsController = class ComponentsController extends _univerjs_core.Dis
29289
30046
  BoldIcon: _univerjs_icons.BoldIcon,
29290
30047
  CopyDoubleIcon: _univerjs_icons.CopyDoubleIcon,
29291
30048
  ColumnIcon: _univerjs_icons.ColumnIcon,
30049
+ CloseIcon: _univerjs_icons.CloseIcon,
29292
30050
  CutIcon: _univerjs_icons.CutIcon,
29293
30051
  DeleteColumnDoubleIcon: _univerjs_icons.DeleteColumnDoubleIcon,
29294
30052
  DeleteIcon: _univerjs_icons.DeleteIcon,
@@ -29367,7 +30125,8 @@ let ComponentsController = class ComponentsController extends _univerjs_core.Dis
29367
30125
  }));
29368
30126
  }
29369
30127
  _registerComponents() {
29370
- if (!this._componentManager.get("COMPONENT_DOC_HEADER_FOOTER_PANEL")) this.disposeWithMe(this._componentManager.register(COMPONENT_DOC_HEADER_FOOTER_PANEL, DocHeaderFooterPanel));
30128
+ this.disposeWithMe(this._componentManager.register(DOC_HEADER_FOOTER_RIBBON_CONTROL, DocHeaderFooterRibbonControl));
30129
+ if (!this._componentManager.hasDefault("COMPONENT_DOC_HEADER_FOOTER_PANEL")) this.disposeWithMe(this._componentManager.register(COMPONENT_DOC_HEADER_FOOTER_PANEL, DocHeaderFooterPanel));
29371
30130
  this.disposeWithMe(this._componentManager.register(paragraphSettingIndexKey, ParagraphSettingIndex));
29372
30131
  this.disposeWithMe(this._componentManager.register(DOC_SECTION_SETTING_COMPONENT, SectionSettingIndex));
29373
30132
  [
@@ -29385,6 +30144,43 @@ let ComponentsController = class ComponentsController extends _univerjs_core.Dis
29385
30144
  };
29386
30145
  ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.IconManager))], ComponentsController);
29387
30146
 
30147
+ //#endregion
30148
+ //#region src/controllers/doc-header-footer-ribbon.controller.ts
30149
+ let DocHeaderFooterRibbonController = class DocHeaderFooterRibbonController extends _univerjs_core.Disposable {
30150
+ constructor(_context, skeletonManager, _instanceService, _ribbonService, _renderManager) {
30151
+ super();
30152
+ this._context = _context;
30153
+ this._instanceService = _instanceService;
30154
+ this._ribbonService = _ribbonService;
30155
+ this._renderManager = _renderManager;
30156
+ _defineProperty(this, "_visible", false);
30157
+ this.disposeWithMe((0, rxjs.combineLatest)([skeletonManager.getViewModel().editAreaChange$, this._instanceService.focused$]).pipe((0, rxjs.map)(([area, focused]) => focused === this._context.unitId && this._context.unit.getDocumentStyle().documentFlavor === _univerjs_core.DocumentFlavor.TRADITIONAL && (area === _univerjs_engine_render.DocumentEditArea.HEADER || area === _univerjs_engine_render.DocumentEditArea.FOOTER)), (0, rxjs.distinctUntilChanged)()).subscribe((visible) => {
30158
+ if (visible === this._visible) return;
30159
+ this._visible = visible;
30160
+ if (visible) this._ribbonService.showContextualTab(DOC_HEADER_FOOTER_RIBBON_TAB, { activate: true });
30161
+ else if (!this._focusedDocumentEditsHeaderFooter()) this._ribbonService.hideContextualTab(DOC_HEADER_FOOTER_RIBBON_TAB);
30162
+ }));
30163
+ }
30164
+ _focusedDocumentEditsHeaderFooter() {
30165
+ var _this$_renderManager$;
30166
+ const focused = this._instanceService.getFocusedUnit();
30167
+ if (!focused || focused.type !== _univerjs_core.UniverInstanceType.UNIVER_DOC || focused.getUnitId() === this._context.unitId) return false;
30168
+ const manager = (_this$_renderManager$ = this._renderManager.getRenderUnitById(focused.getUnitId())) === null || _this$_renderManager$ === void 0 ? void 0 : _this$_renderManager$.with(_univerjs_docs.DocSkeletonManagerService);
30169
+ const area = manager === null || manager === void 0 ? void 0 : manager.getViewModel().getEditArea();
30170
+ return (area === _univerjs_engine_render.DocumentEditArea.HEADER || area === _univerjs_engine_render.DocumentEditArea.FOOTER) && (manager === null || manager === void 0 ? void 0 : manager.getViewModel().getDataModel().getDocumentStyle().documentFlavor) === _univerjs_core.DocumentFlavor.TRADITIONAL;
30171
+ }
30172
+ dispose() {
30173
+ if (this._visible && !this._focusedDocumentEditsHeaderFooter()) this._ribbonService.hideContextualTab(DOC_HEADER_FOOTER_RIBBON_TAB);
30174
+ super.dispose();
30175
+ }
30176
+ };
30177
+ DocHeaderFooterRibbonController = __decorate([
30178
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs.DocSkeletonManagerService)),
30179
+ __decorateParam(2, _univerjs_core.IUniverInstanceService),
30180
+ __decorateParam(3, _univerjs_ui.IRibbonService),
30181
+ __decorateParam(4, _univerjs_engine_render.IRenderManagerService)
30182
+ ], DocHeaderFooterRibbonController);
30183
+
29388
30184
  //#endregion
29389
30185
  //#region src/controllers/format-painter.controller.ts
29390
30186
  let DocFormatPainterController = class DocFormatPainterController extends _univerjs_core.Disposable {
@@ -29452,6 +30248,83 @@ DocFormatPainterController = __decorate([
29452
30248
  __decorateParam(7, _univerjs_core.ICommandService)
29453
30249
  ], DocFormatPainterController);
29454
30250
 
30251
+ //#endregion
30252
+ //#region src/controllers/render-controllers/doc-field.render-controller.ts
30253
+ let DocFieldRenderController = class DocFieldRenderController extends _univerjs_core.Disposable {
30254
+ constructor(_context, _events, _selections, theme, _instances) {
30255
+ super();
30256
+ this._context = _context;
30257
+ this._events = _events;
30258
+ this._selections = _selections;
30259
+ this._instances = _instances;
30260
+ _defineProperty(this, "_hovered", /* @__PURE__ */ new Set());
30261
+ _defineProperty(this, "_shade", "");
30262
+ const documents = this._context.mainComponent;
30263
+ this.disposeWithMe(theme.currentTheme$.subscribe(() => {
30264
+ this._shade = theme.getColorFromTheme("gray.200");
30265
+ documents.makeDirty(true);
30266
+ }));
30267
+ this.disposeWithMe(this._events.hoverCustomRanges$.subscribe((ranges) => {
30268
+ this._hovered = new Set(ranges.filter(({ range }) => range.rangeType === _univerjs_core.CustomRangeType.FIELD).map(({ range, segmentId, segmentPageIndex }) => `${segmentId ?? ""}:${segmentPageIndex}:${range.rangeId}`));
30269
+ documents.makeDirty(true);
30270
+ }));
30271
+ this.disposeWithMe(this._selections.textSelection$.subscribe(({ unitId }) => {
30272
+ if (unitId === this._context.unitId) documents.makeDirty(true);
30273
+ }));
30274
+ this.disposeWithMe(this._instances.focused$.subscribe(() => documents.makeDirty(true)));
30275
+ this.disposeWithMe(documents.getSkeleton().getViewModel().editAreaChange$.subscribe(() => documents.makeDirty(true)));
30276
+ this.disposeWithMe(documents.pageRender$.subscribe((config) => this._drawFields(config)));
30277
+ }
30278
+ _drawFields({ page, pageLeft, pageTop, ctx }) {
30279
+ var _this$_instances$getF;
30280
+ if (((_this$_instances$getF = this._instances.getFocusedUnit()) === null || _this$_instances$getF === void 0 ? void 0 : _this$_instances$getF.getUnitId()) !== this._context.unitId) return;
30281
+ const active = this._getActiveFields();
30282
+ if (!active.size) return;
30283
+ const documents = this._context.mainComponent;
30284
+ const skeleton = documents.getSkeleton();
30285
+ const pageIndex = skeleton.getSkeletonData().pages.indexOf(page);
30286
+ const { docsLeft, docsTop } = documents.getOffsetConfig();
30287
+ const area = skeleton.getViewModel().getEditArea();
30288
+ const snapshot = this._context.unit.getSnapshot();
30289
+ const activeSegments = area === _univerjs_engine_render.DocumentEditArea.HEADER ? snapshot.headers : snapshot.footers;
30290
+ ctx.save();
30291
+ ctx.beginPath();
30292
+ ctx.rect(pageLeft, pageTop, page.pageWidth, page.pageHeight);
30293
+ ctx.clip();
30294
+ ctx.fillStyle = this._shade;
30295
+ ctx.globalAlpha *= .45;
30296
+ for (const { customRange: field, segmentId, segmentPageIndex, rects } of this._events.getCustomRangeBounds()) {
30297
+ if (field.rangeType !== _univerjs_core.CustomRangeType.FIELD) continue;
30298
+ if (segmentId) {
30299
+ if (area === _univerjs_engine_render.DocumentEditArea.BODY || segmentPageIndex !== pageIndex || !(activeSegments === null || activeSegments === void 0 ? void 0 : activeSegments[segmentId])) continue;
30300
+ } else if (area !== _univerjs_engine_render.DocumentEditArea.BODY) continue;
30301
+ if (!active.has(`${segmentId ?? ""}:${segmentPageIndex}:${field.rangeId}`)) continue;
30302
+ for (const rect of rects) ctx.fillRect(rect.left - docsLeft, rect.top - docsTop, rect.right - rect.left, rect.bottom - rect.top);
30303
+ }
30304
+ ctx.restore();
30305
+ }
30306
+ _getActiveFields() {
30307
+ const active = new Set(this._hovered);
30308
+ const selections = this._selections.getTextRanges({
30309
+ unitId: this._context.unitId,
30310
+ subUnitId: this._context.unitId
30311
+ }) ?? [];
30312
+ for (const selection of selections) {
30313
+ var _this$_context$unit$g;
30314
+ const segmentId = selection.segmentId ?? "";
30315
+ const fields = ((_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) ?? [];
30316
+ for (const field of fields) if (field.rangeType === _univerjs_core.CustomRangeType.FIELD && selection.startOffset <= field.endIndex && selection.endOffset > field.startIndex) active.add(`${segmentId}:${segmentId ? selection.segmentPage : -1}:${field.rangeId}`);
30317
+ }
30318
+ return active;
30319
+ }
30320
+ };
30321
+ DocFieldRenderController = __decorate([
30322
+ __decorateParam(1, (0, _univerjs_core.Inject)(DocEventManagerService)),
30323
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService)),
30324
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService)),
30325
+ __decorateParam(4, _univerjs_core.IUniverInstanceService)
30326
+ ], DocFieldRenderController);
30327
+
29455
30328
  //#endregion
29456
30329
  //#region src/controllers/render-controllers/doc-selection-render.controller.ts
29457
30330
  let DocSelectionRenderController = class DocSelectionRenderController extends _univerjs_core.Disposable {
@@ -29776,6 +30649,32 @@ const CloseHeaderFooterShortcut = {
29776
30649
  preconditions: whenDocAndEditorFocused,
29777
30650
  binding: _univerjs_ui.KeyCode.ESC
29778
30651
  };
30652
+ const DeleteWordLeftShortcut = {
30653
+ id: DeleteLeftCommand.id,
30654
+ preconditions: whenTextEditorFocused,
30655
+ binding: _univerjs_ui.KeyCode.BACKSPACE | _univerjs_ui.MetaKeys.CTRL_COMMAND,
30656
+ mac: _univerjs_ui.KeyCode.BACKSPACE | _univerjs_ui.MetaKeys.ALT,
30657
+ staticParameters: { granularity: "word" }
30658
+ };
30659
+ const DeleteWordRightShortcut = {
30660
+ id: DeleteRightCommand.id,
30661
+ preconditions: whenTextEditorFocused,
30662
+ mac: _univerjs_ui.KeyCode.DELETE | _univerjs_ui.MetaKeys.ALT,
30663
+ staticParameters: { granularity: "word" }
30664
+ };
30665
+ const DeleteLineStartShortcut = {
30666
+ id: DeleteLeftCommand.id,
30667
+ preconditions: whenTextEditorFocused,
30668
+ mac: _univerjs_ui.KeyCode.BACKSPACE | _univerjs_ui.MetaKeys.CTRL_COMMAND,
30669
+ staticParameters: { granularity: "line" }
30670
+ };
30671
+ const DeleteLineEndShortcut = {
30672
+ id: DeleteRightCommand.id,
30673
+ preconditions: whenTextEditorFocused,
30674
+ binding: _univerjs_ui.KeyCode.DELETE | _univerjs_ui.MetaKeys.CTRL_COMMAND,
30675
+ mac: _univerjs_ui.KeyCode.DELETE | _univerjs_ui.MetaKeys.MAC_CTRL,
30676
+ staticParameters: { granularity: "line" }
30677
+ };
29779
30678
 
29780
30679
  //#endregion
29781
30680
  //#region src/shortcuts/cursor.shortcut.ts
@@ -29786,7 +30685,7 @@ function moveCursorShortcut(direction, granularity, binding, mac = binding, win
29786
30685
  mac,
29787
30686
  win,
29788
30687
  linux,
29789
- preconditions: whenDocAndEditorFocused,
30688
+ preconditions: whenTextEditorFocused,
29790
30689
  staticParameters: {
29791
30690
  direction,
29792
30691
  granularity
@@ -29800,7 +30699,7 @@ function moveSelectionShortcut(direction, granularity, binding, mac = binding, w
29800
30699
  mac,
29801
30700
  win,
29802
30701
  linux,
29803
- preconditions: whenDocAndEditorFocused,
30702
+ preconditions: whenTextEditorFocused,
29804
30703
  staticParameters: {
29805
30704
  direction,
29806
30705
  granularity
@@ -30063,6 +30962,10 @@ let UniverDocsUIPlugin = class UniverDocsUIPlugin extends _univerjs_core.Plugin
30063
30962
  MoveSelectionWordRightShortcut,
30064
30963
  SelectAllShortcut,
30065
30964
  DeleteLeftShortcut,
30965
+ DeleteWordLeftShortcut,
30966
+ DeleteWordRightShortcut,
30967
+ DeleteLineStartShortcut,
30968
+ DeleteLineEndShortcut,
30066
30969
  DeleteRightShortcut,
30067
30970
  CloseHeaderFooterShortcut,
30068
30971
  BreakLineShortcut,
@@ -30139,10 +31042,12 @@ let UniverDocsUIPlugin = class UniverDocsUIPlugin extends _univerjs_core.Plugin
30139
31042
  _initRenderModules() {
30140
31043
  [
30141
31044
  [DocEventManagerService],
31045
+ [DocFieldRenderController],
30142
31046
  [DocFloatMenuService],
30143
31047
  [DocPasteOptionsRenderController],
30144
31048
  [DocParagraphMenuService],
30145
31049
  [DocHeaderFooterController],
31050
+ [DocHeaderFooterRibbonController],
30146
31051
  [DocResizeRenderController],
30147
31052
  [DocParagraphPlaceholderRenderController],
30148
31053
  [DocContextMenuRenderController],