@univerjs/docs-ui 0.2.11 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/es/index.js CHANGED
@@ -2,15 +2,16 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { FOCUSING_DOC, FOCUSING_UNIVER_EDITOR, FOCUSING_COMMON_DRAWINGS, FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE, Tools, LRUMap, BaselineOffset, BooleanNumber, ColorKit, DataStreamTreeTokenType, CustomRangeType, skipParseTagNames, DataStreamTreeNodeType, createIdentifier, Inject, IUniverInstanceService, ILogService, ICommandService, Disposable, SliceBodyType, UniverInstanceType, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, normalizeBody, toDisposable, getBodySlice, RxDisposable, Direction, EDITOR_ACTIVATED, LocaleService, Injector, Optional, useDependency, DocumentFlavor, CommandType, JSONX, useObservable, PresetListType, ThemeService, HorizontalAlign, MemoryCursor, TextX, TextXActionType, UpdateDocsAttributeType, generateRandomId, OnLifecycle, LifecycleStages, connectInjector, IContextService, checkForSubstrings, IConfigService, isInternalEditorID, DisposableCollection, DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, fromEventSubject, QuickListTypeMap, Plugin, mergeOverrideWithDependencies, ObjectRelativeFromH, ObjectRelativeFromV } from "@univerjs/core";
6
- import { IClipboardInterfaceService, PLAIN_TEXT_CLIPBOARD_MIME_TYPE, HTML_CLIPBOARD_MIME_TYPE, IEditorService, KeyCode, MetaKeys, ILayoutService, ComponentManager, ISidebarService, IConfirmService, MenuGroup, MenuItemType, MenuPosition, getMenuHiddenObservable, FONT_FAMILY_LIST, FONT_SIZE_LIST, getHeaderFooterMenuHiddenObservable, CopyCommand, CutCommand, PasteCommand, FontFamily, FontFamilyItem, FontSize, BuiltInUIPart, IMenuService, IUIPartsService, IShortcutService, SetEditorResizeOperation, ICanvasPopupService, IContextMenuService } from "@univerjs/ui";
7
- import { getEmptyTableCell, getEmptyTableRow, genTableSource, getTableColumn, TextSelectionManagerService, DocCustomRangeService, getCursorWhenDelete, CutContentCommand, InnerPasteCommand, getDeleteSelection, DocSkeletonManagerService, VIEWPORT_KEY, getDocObject, MoveCursorOperation, MoveSelectionOperation, SelectAllOperation, neoGetDocObject, RichTextEditingMutation, SetDocZoomRatioOperation, SetInlineFormatBoldCommand, SetInlineFormatItalicCommand, SetInlineFormatUnderlineCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, AlignLeftCommand, AlignRightCommand, AlignCenterCommand, AlignJustifyCommand, OrderListCommand, BulletListCommand, TabCommand, CreateDocTableCommand, SetTextSelectionsOperation, SetInlineFormatCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatTextColorCommand, AlignOperationCommand, CheckListCommand, ResetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextBackgroundColorCommand, getCommandSkeleton, getParagraphsInRange, getParagraphsInRanges, serializeDocRange, getRichTextEditPath, DeleteLeftCommand, DocTableInsertRowAboveCommand, DocTableInsertRowBellowCommand, DocTableInsertColumnLeftCommand, DocTableInsertColumnRightCommand, DocTableDeleteRowsCommand, DocTableDeleteColumnsCommand, DocTableDeleteTableCommand, EnterCommand, DeleteRightCommand, CoverContentCommand, DOCS_COMPONENT_MAIN_LAYER_INDEX, DOCS_COMPONENT_HEADER_LAYER_INDEX, DOCS_VIEW_KEY, DOCS_COMPONENT_DEFAULT_Z_INDEX, DOCS_COMPONENT_BACKGROUND_LAYER_INDEX, SetDocZoomRatioCommand, ChangeListNestingLevelCommand, ChangeListNestingLevelType, DocTableTabCommand, AfterSpaceCommand, QuickListCommand, ListOperationCommand, BreakLineCommand, DocAutoFormatService, ToggleCheckListCommand, DocInterceptorService } from "@univerjs/docs";
5
+ import { FOCUSING_DOC, FOCUSING_UNIVER_EDITOR, FOCUSING_COMMON_DRAWINGS, FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE, Tools, LRUMap, BaselineOffset, BooleanNumber, ColorKit, skipParseTagNames, DataStreamTreeTokenType, generateRandomId, CustomRangeType, DataStreamTreeNodeType, createIdentifier, Inject, IUniverInstanceService, ILogService, ICommandService, Disposable, SliceBodyType, UniverInstanceType, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, normalizeBody, toDisposable, getBodySlice, RxDisposable, Direction, EDITOR_ACTIVATED, LocaleService, Injector, IConfigService, Optional, useDependency, DocumentFlavor, CommandType, JSONX, useObservable, PresetListType, MemoryCursor, TextX, TextXActionType, UpdateDocsAttributeType, SpacingRule, HorizontalAlign, OnLifecycle, LifecycleStages, ThemeService, connectInjector, IContextService, checkForSubstrings, isInternalEditorID, DisposableCollection, DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, fromEventSubject, QuickListTypeMap, Plugin, mergeOverrideWithDependencies, ObjectRelativeFromH, ObjectRelativeFromV } from "@univerjs/core";
6
+ import { IClipboardInterfaceService, PLAIN_TEXT_CLIPBOARD_MIME_TYPE, HTML_CLIPBOARD_MIME_TYPE, IEditorService, KeyCode, MetaKeys, ILayoutService, ComponentManager, ISidebarService, IConfirmService, CopyCommand, CutCommand, PasteCommand, MenuItemType, getMenuHiddenObservable, FONT_FAMILY_LIST, FONT_SIZE_LIST, getHeaderFooterMenuHiddenObservable, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup, FontFamily, FontFamilyItem, FontSize, BuiltInUIPart, IMenuManagerService, IUIPartsService, IShortcutService, SetEditorResizeOperation, ICanvasPopupService, IContextMenuService } from "@univerjs/ui";
7
+ import { getEmptyTableCell, getEmptyTableRow, genTableSource, getTableColumn, TextSelectionManagerService, getCursorWhenDelete, CutContentCommand, copyCustomRange, InnerPasteCommand, getDeleteSelection, DocSkeletonManagerService, VIEWPORT_KEY, getDocObject, MoveCursorOperation, MoveSelectionOperation, SelectAllOperation, neoGetDocObject, RichTextEditingMutation, SetDocZoomRatioOperation, SetInlineFormatBoldCommand, SetInlineFormatItalicCommand, SetInlineFormatUnderlineCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, AlignLeftCommand, AlignRightCommand, AlignCenterCommand, AlignJustifyCommand, OrderListCommand, BulletListCommand, TabCommand, CreateDocTableCommand, getParagraphsInRanges, serializeDocRange, getRichTextEditPath, SetTextSelectionsOperation, SetInlineFormatCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatTextColorCommand, AlignOperationCommand, CheckListCommand, ResetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextBackgroundColorCommand, getCommandSkeleton, getParagraphsInRange, DeleteLeftCommand, DocTableInsertRowAboveCommand, DocTableInsertRowBellowCommand, DocTableInsertColumnLeftCommand, DocTableInsertColumnRightCommand, DocTableDeleteRowsCommand, DocTableDeleteColumnsCommand, DocTableDeleteTableCommand, EnterCommand, DeleteRightCommand, CoverContentCommand, DOCS_COMPONENT_MAIN_LAYER_INDEX, DOCS_COMPONENT_HEADER_LAYER_INDEX, DOCS_VIEW_KEY, DOCS_COMPONENT_DEFAULT_Z_INDEX, DOCS_COMPONENT_BACKGROUND_LAYER_INDEX, SetDocZoomRatioCommand, ChangeListNestingLevelCommand, ChangeListNestingLevelType, DocTableTabCommand, AfterSpaceCommand, QuickListCommand, ListOperationCommand, BreakLineCommand, DocAutoFormatService, ToggleCheckListCommand, DocInterceptorService } from "@univerjs/docs";
8
8
  import { pixelToPt, ptToPixel, parseDataStreamToTree, DOC_RANGE_TYPE, NodePositionConvertToCursor, getAnchorBounding, IRenderManagerService, ITextSelectionRenderManager, Shape, DocumentEditArea, PageLayoutType, Vector2, Rect, Path, getNumberUnitValue, ScrollBar, Viewport, Layer, Documents, DocBackground, CURSOR_TYPE, pxToNum, getLineBounding, TRANSFORM_CHANGE_OBSERVABLE_TYPE, isInSameTableCell } from "@univerjs/engine-render";
9
- import { takeUntil, Observable, combineLatest, map, fromEvent, BehaviorSubject, filter, throttleTime, animationFrameScheduler, Subject, distinctUntilChanged, mergeMap, take } from "rxjs";
9
+ import { takeUntil, BehaviorSubject, Observable, combineLatest, map as map$1, fromEvent, filter as filter$1, throttleTime, animationFrameScheduler, Subject, distinctUntilChanged, mergeMap, take } from "rxjs";
10
10
  import * as require$$0 from "react";
11
11
  import require$$0__default, { forwardRef, useRef, createElement, useState, useEffect, useMemo, useCallback } from "react";
12
- import { Checkbox, InputNumber, Button, Slider, Tooltip, ColorPicker } from "@univerjs/design";
12
+ import { Checkbox, InputNumber, Button, Slider, Tooltip, Select, ColorPicker } from "@univerjs/design";
13
13
  import clsx from "clsx";
14
+ import { filter, bufferTime, map } from "rxjs/operators";
14
15
  function whenDocAndEditorFocused(contextService) {
15
16
  return contextService.getContextValue(FOCUSING_DOC) && contextService.getContextValue(FOCUSING_UNIVER_EDITOR) && !contextService.getContextValue(FOCUSING_COMMON_DRAWINGS);
16
17
  }
@@ -165,28 +166,14 @@ const DEFAULT_TABLE_WIDTH = 600, _HtmlToUDMService = class _HtmlToUDMService {
165
166
  return pastePlugin && (this._styleRules = [...pastePlugin.stylesRules], this._afterProcessRules = [...pastePlugin.afterProcessRules]), this._tableCache = [], this._styleCache.clear(), this._process(null, dom.childNodes, docData), this._styleCache.clear(), this._styleRules = [], this._afterProcessRules = [], docData;
166
167
  }
167
168
  _process(parent, nodes, doc) {
168
- var _a22, _b, _c;
169
+ var _a22, _b;
169
170
  const body = doc.body;
170
171
  for (const node of nodes)
171
172
  if (node.nodeType === Node.TEXT_NODE) {
172
173
  if (((_a22 = node.nodeValue) == null ? void 0 : _a22.trim()) === "")
173
174
  continue;
174
- let text = (_b = node.nodeValue) == null ? void 0 : _b.replace(/[\r\n]/g, ""), style;
175
- if (parent && parent.nodeType === Node.ELEMENT_NODE && parent.tagName.toUpperCase() === "A") {
176
- const id = Tools.generateRandomId();
177
- text = `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${text}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`, body.customRanges = [
178
- ...(_c = body.customRanges) != null ? _c : [],
179
- {
180
- startIndex: body.dataStream.length,
181
- endIndex: body.dataStream.length + text.length - 1,
182
- rangeId: id,
183
- rangeType: CustomRangeType.HYPERLINK
184
- }
185
- ], body.payloads = {
186
- ...body.payloads,
187
- [id]: parent.href
188
- };
189
- }
175
+ const text = (_b = node.nodeValue) == null ? void 0 : _b.replace(/[\r\n]/g, "");
176
+ let style;
190
177
  parent && this._styleCache.has(parent) && (style = this._styleCache.get(parent)), body.dataStream += text, style && Object.getOwnPropertyNames(style).length && body.textRuns.push({
191
178
  st: body.dataStream.length - text.length,
192
179
  ed: body.dataStream.length,
@@ -196,14 +183,14 @@ const DEFAULT_TABLE_WIDTH = 600, _HtmlToUDMService = class _HtmlToUDMService {
196
183
  if (skipParseTagNames.includes(node.nodeName.toLowerCase()))
197
184
  continue;
198
185
  if (node.nodeType === Node.ELEMENT_NODE) {
199
- const parentStyles = parent ? this._styleCache.get(parent) : {}, styleRule = this._styleRules.find(({ filter: filter2 }) => matchFilter(node, filter2)), nodeStyles = styleRule ? styleRule.getStyle(node) : extractNodeStyle(node);
186
+ const element2 = node, linkStart = this._processBeforeLink(element2, doc), parentStyles = parent ? this._styleCache.get(parent) : {}, styleRule = this._styleRules.find(({ filter: filter2 }) => matchFilter(node, filter2)), nodeStyles = styleRule ? styleRule.getStyle(node) : extractNodeStyle(node);
200
187
  this._styleCache.set(node, { ...parentStyles, ...nodeStyles });
201
188
  const { childNodes } = node;
202
189
  this._processBeforeTable(node, doc), this._process(node, childNodes, doc), this._processAfterTable(node, doc);
203
190
  const afterProcessRule = this._afterProcessRules.find(
204
191
  ({ filter: filter2 }) => matchFilter(node, filter2)
205
192
  );
206
- afterProcessRule && afterProcessRule.handler(doc, node);
193
+ afterProcessRule && afterProcessRule.handler(doc, node), this._processAfterLink(element2, doc, linkStart);
207
194
  }
208
195
  }
209
196
  }
@@ -264,6 +251,21 @@ ${DataStreamTreeTokenType.TABLE_CELL_END}`;
264
251
  }
265
252
  }
266
253
  }
254
+ _processBeforeLink(node, doc) {
255
+ const body = doc.body, element2 = node, start = body.dataStream.length;
256
+ return element2.tagName.toUpperCase() === "A" && (body.dataStream += DataStreamTreeTokenType.CUSTOM_RANGE_START), start;
257
+ }
258
+ _processAfterLink(node, doc, start) {
259
+ var _a22, _b;
260
+ const body = doc.body, element2 = node;
261
+ element2.tagName.toUpperCase() === "A" && (body.dataStream += DataStreamTreeTokenType.CUSTOM_RANGE_END, body.customRanges = (_a22 = body.customRanges) != null ? _a22 : [], body.customRanges.push({
262
+ startIndex: start,
263
+ endIndex: body.dataStream.length - 1,
264
+ rangeId: (_b = element2.dataset.rangeid) != null ? _b : generateRandomId(),
265
+ rangeType: CustomRangeType.HYPERLINK,
266
+ properties: { url: element2.href }
267
+ }));
268
+ }
267
269
  };
268
270
  __name(_HtmlToUDMService, "HtmlToUDMService"), __publicField(_HtmlToUDMService, "_pluginList", []);
269
271
  let HtmlToUDMService = _HtmlToUDMService;
@@ -384,7 +386,7 @@ function covertTextRunToHtml(dataStream, textRun) {
384
386
  return it === BooleanNumber.TRUE && (html = `<i>${html}</i>`), va === BaselineOffset.SUPERSCRIPT ? html = `<sup>${html}</sup>` : va === BaselineOffset.SUBSCRIPT && (html = `<sub>${html}</sub>`), (ul == null ? void 0 : ul.s) === BooleanNumber.TRUE && (html = `<u>${html}</u>`), (st == null ? void 0 : st.s) === BooleanNumber.TRUE && (html = `<s>${html}</s>`), bl === BooleanNumber.TRUE && (html = `<strong>${html}</strong>`), ff && style.push(`font-family: ${ff}`), cl && style.push(`color: ${cl.rgb}`), fs && style.push(`font-size: ${fs}pt`), ol && style.push("text-decoration: overline"), bg && style.push(`background: ${bg.rgb}`), style.length ? `<span style="${style.join("; ")};">${html}</span>` : html;
385
387
  }
386
388
  __name(covertTextRunToHtml, "covertTextRunToHtml");
387
- function getBodySliceHtml(body, startIndex, endIndex) {
389
+ function getBodyInlineSlice(body, startIndex, endIndex) {
388
390
  const { dataStream, textRuns = [] } = body;
389
391
  let cursorIndex = startIndex;
390
392
  const spanList = [];
@@ -401,6 +403,30 @@ function getBodySliceHtml(body, startIndex, endIndex) {
401
403
  }
402
404
  return cursorIndex !== endIndex && spanList.push(dataStream.slice(cursorIndex, endIndex)), spanList.join("");
403
405
  }
406
+ __name(getBodyInlineSlice, "getBodyInlineSlice");
407
+ function getBodySliceHtml(body, startIndex, endIndex) {
408
+ const { customRanges = [] } = body, customRangesInRange = customRanges.filter((range) => range.startIndex >= startIndex && range.endIndex <= endIndex);
409
+ let cursorIndex = startIndex, html = "";
410
+ customRangesInRange.forEach((range) => {
411
+ var _a22, _b;
412
+ const { startIndex: startIndex2, endIndex: endIndex2, rangeType, rangeId } = range, preHtml = getBodyInlineSlice(body, cursorIndex, startIndex2);
413
+ html += preHtml;
414
+ const sliceHtml = getBodyInlineSlice(body, startIndex2 + 1, endIndex2);
415
+ switch (rangeType) {
416
+ case CustomRangeType.HYPERLINK: {
417
+ html += `<a data-rangeid="${rangeId}" href="${(_b = (_a22 = range.properties) == null ? void 0 : _a22.url) != null ? _b : ""}">${sliceHtml}</a>`;
418
+ break;
419
+ }
420
+ default: {
421
+ html += sliceHtml;
422
+ break;
423
+ }
424
+ }
425
+ cursorIndex = endIndex2 + 1;
426
+ });
427
+ const endHtml = getBodyInlineSlice(body, cursorIndex, endIndex);
428
+ return html += endHtml, html;
429
+ }
404
430
  __name(getBodySliceHtml, "getBodySliceHtml");
405
431
  function convertBodyToHtml(body) {
406
432
  const { paragraphs = [], sectionBreaks = [] } = body;
@@ -501,12 +527,12 @@ __name(getTableSlice, "getTableSlice");
501
527
  const IDocClipboardService = createIdentifier("doc.clipboard-service");
502
528
  var _a;
503
529
  let DocClipboardService = (_a = class extends Disposable {
504
- constructor(_univerInstanceService, _logService, _commandService, _clipboardInterfaceService, _textSelectionManagerService, _docCustomRangeService) {
530
+ constructor(_univerInstanceService, _logService, _commandService, _clipboardInterfaceService, _textSelectionManagerService) {
505
531
  super();
506
532
  __publicField(this, "_clipboardHooks", []);
507
533
  __publicField(this, "_htmlToUDM", new HtmlToUDMService());
508
534
  __publicField(this, "_umdToHtml", new UDMToHtmlService());
509
- this._univerInstanceService = _univerInstanceService, this._logService = _logService, this._commandService = _commandService, this._clipboardInterfaceService = _clipboardInterfaceService, this._textSelectionManagerService = _textSelectionManagerService, this._docCustomRangeService = _docCustomRangeService;
535
+ this._univerInstanceService = _univerInstanceService, this._logService = _logService, this._commandService = _commandService, this._clipboardInterfaceService = _clipboardInterfaceService, this._textSelectionManagerService = _textSelectionManagerService;
510
536
  }
511
537
  async copy(sliceType = SliceBodyType.copy) {
512
538
  var _a22;
@@ -578,12 +604,11 @@ let DocClipboardService = (_a = class extends Disposable {
578
604
  if (_body == null)
579
605
  return !1;
580
606
  let body = normalizeBody(_body);
581
- const unitId = (_a22 = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)) == null ? void 0 : _a22.getUnitId();
582
- if (!unitId)
607
+ if (!((_a22 = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)) == null ? void 0 : _a22.getUnitId()))
583
608
  return !1;
584
609
  this._clipboardHooks.forEach((hook) => {
585
610
  hook.onBeforePaste && (body = hook.onBeforePaste(body));
586
- }), body.customRanges = (_b = body.customRanges) == null ? void 0 : _b.map((range) => this._docCustomRangeService.copyCustomRange(unitId, range));
611
+ }), body.customRanges = (_b = body.customRanges) == null ? void 0 : _b.map(copyCustomRange);
587
612
  const activeRange = this._textSelectionManagerService.getActiveTextRangeWithStyle(), { segmentId, endOffset: activeEndOffset, style } = activeRange || {}, ranges = this._textSelectionManagerService.getCurrentTextRanges();
588
613
  if (segmentId == null && this._logService.error("[DocClipboardController] segmentId does not exist!"), activeEndOffset == null || ranges == null)
589
614
  return !1;
@@ -643,7 +668,6 @@ let DocClipboardService = (_a = class extends Disposable {
643
668
  index > -1 && this._clipboardHooks.splice(index, 1);
644
669
  });
645
670
  }
646
- // eslint-disable-next-line max-lines-per-function
647
671
  _getDocumentBodyInRanges(sliceType) {
648
672
  var _a22;
649
673
  const docDataModel = this._univerInstanceService.getCurrentUniverDocInstance(), allRanges = this._textSelectionManagerService.getDocRanges(), results = [];
@@ -664,19 +688,7 @@ let DocClipboardService = (_a = class extends Disposable {
664
688
  continue;
665
689
  }
666
690
  const deleteRange = getDeleteSelection({ startOffset, endOffset, collapsed }, body), docBody = docDataModel.getSelfOrHeaderFooterModel(segmentId).sliceBody(deleteRange.startOffset, deleteRange.endOffset, sliceType);
667
- if (docBody != null) {
668
- if (docBody.customRanges) {
669
- const deleteRange2 = [];
670
- docBody.customRanges.forEach((range2) => {
671
- range2.startIndex === range2.endIndex && deleteRange2.push(range2);
672
- }), docBody.customRanges = docBody.customRanges.filter((range2) => deleteRange2.indexOf(range2) === -1);
673
- let text = "", cursor = 0;
674
- deleteRange2.forEach((range2) => {
675
- text += docBody.dataStream.slice(cursor, range2.endIndex), cursor = range2.endIndex + 1;
676
- }), text += docBody.dataStream.slice(cursor, docBody.dataStream.length), docBody.dataStream = text;
677
- }
678
- results.push(docBody);
679
- }
691
+ docBody != null && results.push(docBody);
680
692
  }
681
693
  return {
682
694
  bodyList: results,
@@ -699,16 +711,15 @@ let DocClipboardService = (_a = class extends Disposable {
699
711
  _generateBody(text) {
700
712
  const dataStream = text.replace(/\n/g, "\r");
701
713
  if (!text.includes("\r") && Tools.isLegalUrl(text)) {
702
- const id = Tools.generateRandomId(), docDataModel = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), urlText = `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${dataStream}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`, range = this._docCustomRangeService.copyCustomRange(
703
- docDataModel.getUnitId(),
704
- {
705
- startIndex: 0,
706
- endIndex: urlText.length - 1,
707
- rangeId: id,
708
- rangeType: CustomRangeType.HYPERLINK,
709
- data: text
714
+ const id = generateRandomId(), urlText = `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${dataStream}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`, range = {
715
+ startIndex: 0,
716
+ endIndex: urlText.length - 1,
717
+ rangeId: id,
718
+ rangeType: CustomRangeType.HYPERLINK,
719
+ properties: {
720
+ url: text
710
721
  }
711
- );
722
+ };
712
723
  return {
713
724
  dataStream: urlText,
714
725
  customRanges: [range]
@@ -742,8 +753,7 @@ DocClipboardService = __decorateClass$k([
742
753
  __decorateParam$k(1, ILogService),
743
754
  __decorateParam$k(2, ICommandService),
744
755
  __decorateParam$k(3, IClipboardInterfaceService),
745
- __decorateParam$k(4, Inject(TextSelectionManagerService)),
746
- __decorateParam$k(5, Inject(DocCustomRangeService))
756
+ __decorateParam$k(4, Inject(TextSelectionManagerService))
747
757
  ], DocClipboardService);
748
758
  var __defProp$j = Object.defineProperty, __getOwnPropDesc$j = Object.getOwnPropertyDescriptor, __decorateClass$j = /* @__PURE__ */ __name((decorators, target, key, kind) => {
749
759
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$j(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
@@ -851,11 +861,6 @@ const DefaultToolbarConfig = {
851
861
  frozenContent: !1,
852
862
  infoBar: !0,
853
863
  toolbar: !0
854
- }, DefaultDocUiConfig = {
855
- layout: {
856
- docContainerConfig: DefaultDocContainerConfig,
857
- toolbarConfig: DefaultToolbarConfig
858
- }
859
864
  }, DOC_UI_PLUGIN_NAME = "DocUI", MoveCursorUpShortcut = {
860
865
  id: MoveCursorOperation.id,
861
866
  binding: KeyCode.ARROW_UP,
@@ -916,6 +921,11 @@ const DefaultToolbarConfig = {
916
921
  id: SelectAllOperation.id,
917
922
  binding: KeyCode.A | MetaKeys.CTRL_COMMAND,
918
923
  preconditions: /* @__PURE__ */ __name((contextService) => contextService.getContextValue(FOCUSING_UNIVER_EDITOR) && (contextService.getContextValue(FOCUSING_DOC) || contextService.getContextValue(EDITOR_ACTIVATED)), "preconditions")
924
+ }, PLUGIN_CONFIG_KEY = "docs-ui.config", defaultPluginConfig = {
925
+ layout: {
926
+ docContainerConfig: DefaultDocContainerConfig,
927
+ toolbarConfig: DefaultToolbarConfig
928
+ }
919
929
  };
920
930
  var __defProp$i = Object.defineProperty, __getOwnPropDesc$i = Object.getOwnPropertyDescriptor, __decorateClass$i = /* @__PURE__ */ __name((decorators, target, key, kind) => {
921
931
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$i(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
@@ -923,7 +933,7 @@ var __defProp$i = Object.defineProperty, __getOwnPropDesc$i = Object.getOwnPrope
923
933
  return kind && result && __defProp$i(target, key, result), result;
924
934
  }, "__decorateClass$i"), __decorateParam$i = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$i"), _a3;
925
935
  let DocContainerUIController = (_a3 = class {
926
- constructor(_config, _localeService, _injector) {
936
+ constructor(_localeService, _injector, _configService) {
927
937
  __publicField(this, "_docContainer");
928
938
  // 获取SheetContainer组件
929
939
  __publicField(this, "getComponent", /* @__PURE__ */ __name((ref) => {
@@ -940,12 +950,12 @@ let DocContainerUIController = (_a3 = class {
940
950
  __publicField(this, "changeLocale", /* @__PURE__ */ __name((locale) => {
941
951
  this._localeService.setLocale(locale);
942
952
  }, "changeLocale"));
943
- this._config = _config, this._localeService = _localeService, this._injector = _injector;
953
+ this._localeService = _localeService, this._injector = _injector, this._configService = _configService;
944
954
  }
945
955
  getUIConfig() {
946
956
  return {
947
957
  injector: this._injector,
948
- config: this._config,
958
+ config: this._configService.getConfig(PLUGIN_CONFIG_KEY),
949
959
  changeLocale: this.changeLocale,
950
960
  getComponent: this.getComponent
951
961
  };
@@ -962,8 +972,9 @@ let DocContainerUIController = (_a3 = class {
962
972
  }
963
973
  }, __name(_a3, "DocContainerUIController"), _a3);
964
974
  DocContainerUIController = __decorateClass$i([
965
- __decorateParam$i(1, Inject(LocaleService)),
966
- __decorateParam$i(2, Inject(Injector))
975
+ __decorateParam$i(0, Inject(LocaleService)),
976
+ __decorateParam$i(1, Inject(Injector)),
977
+ __decorateParam$i(2, IConfigService)
967
978
  ], DocContainerUIController);
968
979
  var __defProp$h = Object.defineProperty, __getOwnPropDesc$h = Object.getOwnPropertyDescriptor, __decorateClass$h = /* @__PURE__ */ __name((decorators, target, key, kind) => {
969
980
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$h(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
@@ -971,20 +982,10 @@ var __defProp$h = Object.defineProperty, __getOwnPropDesc$h = Object.getOwnPrope
971
982
  return kind && result && __defProp$h(target, key, result), result;
972
983
  }, "__decorateClass$h"), __decorateParam$h = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$h"), _a4;
973
984
  let AppUIController = (_a4 = class extends RxDisposable {
974
- constructor(_config, _localeService, _injector, _textSelectionRenderManager, _layoutService) {
985
+ constructor(_injector, _textSelectionRenderManager, _layoutService) {
975
986
  super();
976
987
  __publicField(this, "_docContainerController");
977
- /**
978
- * Change language
979
- * @param {string} locale new language
980
- *
981
- * e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771
982
- *
983
- */
984
- __publicField(this, "changeLocale", /* @__PURE__ */ __name((locale) => {
985
- this._localeService.setLocale(locale);
986
- }, "changeLocale"));
987
- this._localeService = _localeService, this._injector = _injector, this._textSelectionRenderManager = _textSelectionRenderManager, this._layoutService = _layoutService, this._docContainerController = this._injector.createInstance(DocContainerUIController, _config), this._registerContainer();
988
+ this._injector = _injector, this._textSelectionRenderManager = _textSelectionRenderManager, this._layoutService = _layoutService, this._docContainerController = this._injector.createInstance(DocContainerUIController), this._registerContainer();
988
989
  }
989
990
  _registerContainer() {
990
991
  this._layoutService && this.disposeWithMe(
@@ -992,15 +993,11 @@ let AppUIController = (_a4 = class extends RxDisposable {
992
993
  this._layoutService.registerContainerElement(this._textSelectionRenderManager.__getEditorContainer())
993
994
  );
994
995
  }
995
- getDocContainerController() {
996
- return this._docContainerController;
997
- }
998
996
  }, __name(_a4, "AppUIController"), _a4);
999
997
  AppUIController = __decorateClass$h([
1000
- __decorateParam$h(1, Inject(LocaleService)),
1001
- __decorateParam$h(2, Inject(Injector)),
1002
- __decorateParam$h(3, ITextSelectionRenderManager),
1003
- __decorateParam$h(4, Optional(ILayoutService))
998
+ __decorateParam$h(0, Inject(Injector)),
999
+ __decorateParam$h(1, ITextSelectionRenderManager),
1000
+ __decorateParam$h(2, Optional(ILayoutService))
1004
1001
  ], AppUIController);
1005
1002
  var __assign = function() {
1006
1003
  return __assign = Object.assign || function(t) {
@@ -1870,253 +1867,495 @@ const docFooterContainer = "univer-doc-footer-container", styles$3 = {
1870
1867
  }), !0;
1871
1868
  }, "handler")
1872
1869
  };
1873
- function getInsertTableHiddenObservable(accessor) {
1874
- const univerInstanceService = accessor.get(IUniverInstanceService), renderManagerService = accessor.get(IRenderManagerService);
1875
- return new Observable((subscriber) => {
1876
- const subscription = univerInstanceService.focused$.subscribe((unitId) => {
1877
- if (unitId == null || univerInstanceService.getUnitType(unitId) !== UniverInstanceType.UNIVER_DOC)
1878
- return subscriber.next(!0);
1879
- const currentRender2 = renderManagerService.getRenderById(unitId);
1880
- if (currentRender2 == null)
1881
- return subscriber.next(!0);
1882
- currentRender2.with(DocSkeletonManagerService).getViewModel().editAreaChange$.subscribe((editArea) => {
1883
- subscriber.next(editArea === DocumentEditArea.HEADER || editArea === DocumentEditArea.FOOTER);
1884
- });
1885
- }), currentRender = renderManagerService.getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_DOC);
1886
- if (currentRender == null)
1887
- return subscriber.next(!0);
1888
- const viewModel = currentRender.with(DocSkeletonManagerService).getViewModel();
1889
- return subscriber.next(viewModel.getEditArea() !== DocumentEditArea.BODY), () => subscription.unsubscribe();
1890
- });
1870
+ function whenDocOrEditor(contextService) {
1871
+ return contextService.getContextValue(FOCUSING_DOC) || contextService.getContextValue(EDITOR_ACTIVATED);
1891
1872
  }
1892
- __name(getInsertTableHiddenObservable, "getInsertTableHiddenObservable");
1893
- function getTableDisabledObservable(accessor) {
1894
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService);
1895
- return new Observable((subscriber) => {
1896
- const subscription = textSelectionManagerService.textSelection$.subscribe((selection) => {
1897
- if (selection == null) {
1898
- subscriber.next(!0);
1899
- return;
1900
- }
1901
- const { textRanges } = selection;
1902
- if (textRanges.length !== 1) {
1903
- subscriber.next(!0);
1904
- return;
1905
- }
1906
- const textRange = textRanges[0], { collapsed, anchorNodePosition, startOffset } = textRange;
1907
- if (!collapsed || startOffset == null) {
1908
- subscriber.next(!0);
1909
- return;
1910
- }
1911
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
1912
- if (docDataModel == null) {
1913
- subscriber.next(!0);
1914
- return;
1915
- }
1916
- const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
1917
- if (docSkeletonManagerService == null) {
1918
- subscriber.next(!0);
1919
- return;
1920
- }
1921
- if (docSkeletonManagerService.getViewModel().getCustomRangeRaw(startOffset)) {
1922
- subscriber.next(!0);
1923
- return;
1924
- }
1925
- if (anchorNodePosition != null) {
1926
- const { path } = anchorNodePosition;
1927
- if (path.indexOf("cells") !== -1) {
1928
- subscriber.next(!0);
1929
- return;
1930
- }
1931
- }
1932
- subscriber.next(!1);
1933
- });
1934
- return () => subscription.unsubscribe();
1935
- });
1873
+ __name(whenDocOrEditor, "whenDocOrEditor");
1874
+ function whenFocusEditor(contextService) {
1875
+ return contextService.getContextValue(EDITOR_ACTIVATED);
1936
1876
  }
1937
- __name(getTableDisabledObservable, "getTableDisabledObservable");
1938
- function disableMenuWhenNoDocRange(accessor) {
1939
- const textSelectionManagerService = accessor.get(TextSelectionManagerService);
1940
- return new Observable((subscriber) => {
1941
- const subscription = textSelectionManagerService.textSelection$.subscribe((selection) => {
1942
- if (selection == null) {
1943
- subscriber.next(!0);
1944
- return;
1945
- }
1946
- const { textRanges, rectRanges } = selection;
1947
- if (textRanges.length === 0 && rectRanges.length === 0) {
1948
- subscriber.next(!0);
1949
- return;
1877
+ __name(whenFocusEditor, "whenFocusEditor");
1878
+ const DOC_CLIPBOARD_PRIORITY = 999, DocCopyCommand = {
1879
+ id: CopyCommand.id,
1880
+ name: "doc.command.copy",
1881
+ type: CommandType.COMMAND,
1882
+ multi: !0,
1883
+ priority: DOC_CLIPBOARD_PRIORITY,
1884
+ preconditions: whenDocOrEditor,
1885
+ handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(IDocClipboardService).copy(), "handler")
1886
+ }, DocCutCommand = {
1887
+ id: CutCommand.id,
1888
+ name: "doc.command.cut",
1889
+ type: CommandType.COMMAND,
1890
+ multi: !0,
1891
+ priority: DOC_CLIPBOARD_PRIORITY,
1892
+ preconditions: whenDocOrEditor,
1893
+ handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(IDocClipboardService).cut(), "handler")
1894
+ }, DocPasteCommand = {
1895
+ id: PasteCommand.id,
1896
+ name: "doc.command.paste",
1897
+ type: CommandType.COMMAND,
1898
+ multi: !0,
1899
+ priority: DOC_CLIPBOARD_PRIORITY,
1900
+ preconditions: whenDocOrEditor,
1901
+ handler: /* @__PURE__ */ __name(async (accessor) => {
1902
+ const docClipboardService = accessor.get(IDocClipboardService), clipboardItems = await accessor.get(IClipboardInterfaceService).read();
1903
+ return clipboardItems.length === 0 ? !1 : docClipboardService.paste(clipboardItems);
1904
+ }, "handler")
1905
+ }, DocParagraphSettingCommand = {
1906
+ id: "doc-paragraph-setting.command",
1907
+ type: CommandType.COMMAND,
1908
+ handler: /* @__PURE__ */ __name(async (accessor, config) => {
1909
+ var _a22, _b, _c;
1910
+ const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), docDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), docRanges = textSelectionManagerService.getDocRanges();
1911
+ if (!docDataModel || docRanges.length === 0 || !config)
1912
+ return !1;
1913
+ const segmentId = docRanges[0].segmentId, unitId = docDataModel.getUnitId(), allParagraphs = (_b = (_a22 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a22.paragraphs) != null ? _b : [], paragraphs = (_c = getParagraphsInRanges(docRanges, allParagraphs)) != null ? _c : [], serializedSelections = docRanges.map(serializeDocRange), doMutation = {
1914
+ id: RichTextEditingMutation.id,
1915
+ params: {
1916
+ unitId,
1917
+ actions: [],
1918
+ textRanges: serializedSelections
1950
1919
  }
1951
- subscriber.next(!1);
1952
- });
1953
- return () => subscription.unsubscribe();
1954
- });
1955
- }
1956
- __name(disableMenuWhenNoDocRange, "disableMenuWhenNoDocRange");
1957
- function BoldMenuItemFactory(accessor) {
1958
- const commandService = accessor.get(ICommandService);
1959
- return {
1960
- id: SetInlineFormatBoldCommand.id,
1961
- group: MenuGroup.TOOLBAR_FORMAT,
1962
- type: MenuItemType.BUTTON,
1963
- icon: "BoldSingle",
1964
- title: "Set bold",
1965
- tooltip: "toolbar.bold",
1966
- positions: [MenuPosition.TOOLBAR_START],
1967
- activated$: new Observable((subscriber) => {
1968
- const disposable = commandService.onCommandExecuted((c) => {
1969
- var _a22;
1970
- const id = c.id;
1971
- if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
1972
- const textRun = getFontStyleAtCursor(accessor);
1973
- if (textRun == null) {
1974
- subscriber.next(!1);
1975
- return;
1976
- }
1977
- const bl = (_a22 = textRun.ts) == null ? void 0 : _a22.bl;
1978
- subscriber.next(bl === BooleanNumber.TRUE);
1979
- }
1980
- });
1981
- return subscriber.next(!1), disposable.dispose;
1982
- }),
1983
- disabled$: disableMenuWhenNoDocRange(accessor),
1984
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1985
- };
1986
- }
1987
- __name(BoldMenuItemFactory, "BoldMenuItemFactory");
1988
- function ItalicMenuItemFactory(accessor) {
1989
- const commandService = accessor.get(ICommandService);
1990
- return {
1991
- id: SetInlineFormatItalicCommand.id,
1992
- group: MenuGroup.TOOLBAR_FORMAT,
1993
- type: MenuItemType.BUTTON,
1994
- icon: "ItalicSingle",
1995
- title: "Set italic",
1996
- tooltip: "toolbar.italic",
1997
- positions: [MenuPosition.TOOLBAR_START],
1998
- activated$: new Observable((subscriber) => {
1999
- const disposable = commandService.onCommandExecuted((c) => {
2000
- var _a22;
2001
- const id = c.id;
2002
- if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
2003
- const textRun = getFontStyleAtCursor(accessor);
2004
- if (textRun == null) {
2005
- subscriber.next(!1);
2006
- return;
2007
- }
2008
- const it = (_a22 = textRun.ts) == null ? void 0 : _a22.it;
2009
- subscriber.next(it === BooleanNumber.TRUE);
2010
- }
1920
+ }, memoryCursor = new MemoryCursor();
1921
+ memoryCursor.reset();
1922
+ const textX = new TextX(), jsonX = JSONX.getInstance();
1923
+ for (const paragraph of paragraphs) {
1924
+ const { startIndex } = paragraph;
1925
+ textX.push({
1926
+ t: TextXActionType.RETAIN,
1927
+ len: startIndex - memoryCursor.cursor,
1928
+ segmentId
2011
1929
  });
2012
- return subscriber.next(!1), disposable.dispose;
2013
- }),
2014
- disabled$: disableMenuWhenNoDocRange(accessor),
2015
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2016
- };
2017
- }
2018
- __name(ItalicMenuItemFactory, "ItalicMenuItemFactory");
2019
- function UnderlineMenuItemFactory(accessor) {
2020
- const commandService = accessor.get(ICommandService);
2021
- return {
2022
- id: SetInlineFormatUnderlineCommand.id,
2023
- group: MenuGroup.TOOLBAR_FORMAT,
2024
- type: MenuItemType.BUTTON,
2025
- icon: "UnderlineSingle",
2026
- title: "Set underline",
2027
- tooltip: "toolbar.underline",
2028
- positions: [MenuPosition.TOOLBAR_START],
2029
- activated$: new Observable((subscriber) => {
2030
- const disposable = commandService.onCommandExecuted((c) => {
2031
- var _a22;
2032
- const id = c.id;
2033
- if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
2034
- const textRun = getFontStyleAtCursor(accessor);
2035
- if (textRun == null) {
2036
- subscriber.next(!1);
2037
- return;
2038
- }
2039
- const ul = (_a22 = textRun.ts) == null ? void 0 : _a22.ul;
2040
- subscriber.next((ul == null ? void 0 : ul.s) === BooleanNumber.TRUE);
2041
- }
1930
+ const paragraphStyle = {
1931
+ ...paragraph.paragraphStyle,
1932
+ ...config.paragraph
1933
+ };
1934
+ textX.push({
1935
+ t: TextXActionType.RETAIN,
1936
+ len: 1,
1937
+ body: {
1938
+ dataStream: "",
1939
+ paragraphs: [
1940
+ {
1941
+ ...paragraph,
1942
+ paragraphStyle,
1943
+ startIndex: 0
1944
+ }
1945
+ ]
1946
+ },
1947
+ segmentId,
1948
+ coverType: UpdateDocsAttributeType.REPLACE
1949
+ }), memoryCursor.moveCursorTo(startIndex + 1);
1950
+ }
1951
+ const path = getRichTextEditPath(docDataModel, segmentId);
1952
+ return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
1953
+ }, "handler")
1954
+ }, useDocRanges = /* @__PURE__ */ __name(() => {
1955
+ const textSelectionManagerService = useDependency(TextSelectionManagerService), docParagraphSettingController = useDependency(DocParagraphSettingController), docRanges = useMemo(() => textSelectionManagerService.getDocRanges(), []);
1956
+ return useEffect(() => {
1957
+ docRanges.length || docParagraphSettingController.closePanel();
1958
+ }, [docRanges]), docRanges;
1959
+ }, "useDocRanges"), useCurrentParagraph = /* @__PURE__ */ __name(() => {
1960
+ var _a22, _b, _c;
1961
+ const docDataModel = useDependency(IUniverInstanceService).getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), docRanges = useDocRanges();
1962
+ if (!docDataModel || docRanges.length === 0)
1963
+ return [];
1964
+ const segmentId = docRanges[0].segmentId, paragraphs = (_b = (_a22 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a22.paragraphs) != null ? _b : [];
1965
+ return (_c = getParagraphsInRanges(docRanges, paragraphs)) != null ? _c : [];
1966
+ }, "useCurrentParagraph"), useFirstParagraphHorizontalAlign = /* @__PURE__ */ __name((paragraph, defaultValue) => {
1967
+ const commandService = useDependency(ICommandService), [horizontalAlign, _horizontalAlignSet] = useState(() => {
1968
+ var _a22, _b;
1969
+ const firstParagraph = paragraph[0];
1970
+ return firstParagraph ? String((_b = (_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.horizontalAlign) != null ? _b : defaultValue) : defaultValue;
1971
+ });
1972
+ return [horizontalAlign, /* @__PURE__ */ __name((v) => (_horizontalAlignSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
1973
+ paragraph: { horizontalAlign: Number(v) }
1974
+ })), "horizontalAlignSet")];
1975
+ }, "useFirstParagraphHorizontalAlign"), useFirstParagraphIndentStart = /* @__PURE__ */ __name((paragraph) => {
1976
+ const commandService = useDependency(ICommandService), [indentStart, _indentStartSet] = useState(() => {
1977
+ var _a22;
1978
+ const firstParagraph = paragraph[0];
1979
+ return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.indentStart, 0) : 0;
1980
+ });
1981
+ return [indentStart, /* @__PURE__ */ __name((v) => (_indentStartSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
1982
+ paragraph: { indentStart: { v } }
1983
+ })), "indentStartSet")];
1984
+ }, "useFirstParagraphIndentStart"), useFirstParagraphIndentEnd = /* @__PURE__ */ __name((paragraph) => {
1985
+ const commandService = useDependency(ICommandService), [indentEnd, _indentEndSet] = useState(() => {
1986
+ var _a22;
1987
+ const firstParagraph = paragraph[0];
1988
+ return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.indentEnd, 0) : 0;
1989
+ });
1990
+ return [indentEnd, /* @__PURE__ */ __name((v) => (_indentEndSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
1991
+ paragraph: { indentEnd: { v } }
1992
+ })), "indentEndSet")];
1993
+ }, "useFirstParagraphIndentEnd"), useFirstParagraphIndentFirstLine = /* @__PURE__ */ __name((paragraph) => {
1994
+ const commandService = useDependency(ICommandService), [indentFirstLine, _indentFirstLineSet] = useState(() => {
1995
+ var _a22;
1996
+ const firstParagraph = paragraph[0];
1997
+ return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.indentFirstLine, 0) : 0;
1998
+ });
1999
+ return [indentFirstLine, /* @__PURE__ */ __name((v) => (_indentFirstLineSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2000
+ paragraph: { indentFirstLine: { v } }
2001
+ })), "indentFirstLineSet")];
2002
+ }, "useFirstParagraphIndentFirstLine"), useFirstParagraphIndentHanging = /* @__PURE__ */ __name((paragraph) => {
2003
+ const commandService = useDependency(ICommandService), [hanging, _hangingSet] = useState(() => {
2004
+ var _a22;
2005
+ const firstParagraph = paragraph[0];
2006
+ return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.hanging, 0) : 0;
2007
+ });
2008
+ return [hanging, /* @__PURE__ */ __name((v) => (_hangingSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2009
+ paragraph: { hanging: { v } }
2010
+ })), "hangingSet")];
2011
+ }, "useFirstParagraphIndentHanging"), useFirstParagraphIndentSpaceAbove = /* @__PURE__ */ __name((paragraph) => {
2012
+ const commandService = useDependency(ICommandService), [spaceAbove, _spaceAboveSet] = useState(() => {
2013
+ var _a22;
2014
+ const firstParagraph = paragraph[0];
2015
+ return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.spaceAbove, 0) : 0;
2016
+ });
2017
+ return [spaceAbove, /* @__PURE__ */ __name((v) => (_spaceAboveSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2018
+ paragraph: { spaceAbove: { v } }
2019
+ })), "spaceAboveSet")];
2020
+ }, "useFirstParagraphIndentSpaceAbove"), useFirstParagraphSpaceBelow = /* @__PURE__ */ __name((paragraph) => {
2021
+ const commandService = useDependency(ICommandService), [spaceBelow, _spaceBelowSet] = useState(() => {
2022
+ var _a22;
2023
+ const firstParagraph = paragraph[0];
2024
+ return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.spaceBelow, 0) : 0;
2025
+ });
2026
+ return [spaceBelow, /* @__PURE__ */ __name((v) => (_spaceBelowSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2027
+ paragraph: { spaceBelow: { v } }
2028
+ })), "spaceBelowSet")];
2029
+ }, "useFirstParagraphSpaceBelow"), useFirstParagraphLineSpacing = /* @__PURE__ */ __name((paragraph) => {
2030
+ const commandService = useDependency(ICommandService), renderManagerService = useDependency(IRenderManagerService), univerInstanceService = useDependency(IUniverInstanceService), skeleton = useMemo(() => {
2031
+ var _a22;
2032
+ const docDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
2033
+ if (docDataModel)
2034
+ return (_a22 = renderManagerService.getRenderById(docDataModel == null ? void 0 : docDataModel.getUnitId())) == null ? void 0 : _a22.with(DocSkeletonManagerService).getSkeleton();
2035
+ }, []), stateChange$ = useMemo(() => new BehaviorSubject({}), []), [lineSpacing, _lineSpacingSet] = useState(() => {
2036
+ var _a22, _b;
2037
+ const firstParagraph = paragraph[0];
2038
+ return firstParagraph && (_b = (_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.lineSpacing) != null ? _b : 1;
2039
+ }), lineSpacingCache = useRef(lineSpacing), [spacingRule, _spacingRuleSet] = useState(() => {
2040
+ var _a22, _b;
2041
+ const firstParagraph = paragraph[0];
2042
+ return firstParagraph ? (_b = (_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.spacingRule) != null ? _b : SpacingRule.AUTO : SpacingRule.AUTO;
2043
+ }), lineSpacingSet = /* @__PURE__ */ __name(async (v) => {
2044
+ _lineSpacingSet(v), stateChange$.next({ lineSpacing: v, spacingRule });
2045
+ }, "lineSpacingSet"), spacingRuleSet = /* @__PURE__ */ __name(async (v) => {
2046
+ if (v !== spacingRule) {
2047
+ let cache = lineSpacingCache.current;
2048
+ if (v === SpacingRule.AT_LEAST) {
2049
+ const glyphNode = skeleton == null ? void 0 : skeleton.findNodeByCharIndex(paragraph[0].startIndex), divideNode = glyphNode == null ? void 0 : glyphNode.parent, lineNode = divideNode == null ? void 0 : divideNode.parent;
2050
+ (lineNode == null ? void 0 : lineNode.contentHeight) !== void 0 && (cache = Math.max(lineNode.contentHeight, cache));
2051
+ } else
2052
+ cache > 5 && (cache = 2);
2053
+ lineSpacingCache.current = lineSpacing, lineSpacingSet(cache), _spacingRuleSet(v), stateChange$.next({ spacingRule: v });
2054
+ }
2055
+ }, "spacingRuleSet");
2056
+ return useEffect(() => {
2057
+ const dispose = stateChange$.pipe(
2058
+ filter((obj) => !!Object.keys(obj).length),
2059
+ bufferTime(16),
2060
+ filter((list) => !!list.length),
2061
+ map((list) => list.reduce((a, b) => (Object.keys(b).forEach((key) => {
2062
+ a[key] = b[key];
2063
+ }), a), {}))
2064
+ ).subscribe((v) => commandService.executeCommand(DocParagraphSettingCommand.id, {
2065
+ paragraph: { ...v }
2066
+ }));
2067
+ return () => dispose.unsubscribe();
2068
+ }, []), {
2069
+ lineSpacing: [lineSpacing, lineSpacingSet],
2070
+ spacingRule: [spacingRule, spacingRuleSet]
2071
+ };
2072
+ }, "useFirstParagraphLineSpacing"), paragraphSettingIconList = "univer-paragraph-setting-icon-list", paragraphSettingIconListItem = "univer-paragraph-setting-icon-list-item", paragraphSettingIconListActive = "univer-paragraph-setting-icon-list-active", paragraphSettingTitle = "univer-paragraph-setting-title", paragraphSettingLabel = "univer-paragraph-setting-label", paragraphSettingMtBase = "univer-paragraph-setting-mt-base", paragraphSettingFlexCol = "univer-paragraph-setting-flex-col", paragraphSettingSpaceLine = "univer-paragraph-setting-space-line", styles$1 = {
2073
+ paragraphSettingIconList,
2074
+ paragraphSettingIconListItem,
2075
+ paragraphSettingIconListActive,
2076
+ paragraphSettingTitle,
2077
+ paragraphSettingLabel,
2078
+ paragraphSettingMtBase,
2079
+ paragraphSettingFlexCol,
2080
+ paragraphSettingSpaceLine
2081
+ }, AutoFocusInputNumber = /* @__PURE__ */ __name((props) => {
2082
+ const { value, onChange, className = "", min = 0, max = 100, step = 1 } = props, ref = require$$0.useRef(null);
2083
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
2084
+ InputNumber,
2085
+ {
2086
+ step,
2087
+ ref,
2088
+ min,
2089
+ max,
2090
+ value,
2091
+ onChange: /* @__PURE__ */ __name((v) => {
2092
+ onChange(v != null ? v : 0).finally(() => {
2093
+ setTimeout(() => {
2094
+ var _a22;
2095
+ (_a22 = ref.current) == null || _a22.focus();
2096
+ }, 30);
2097
+ });
2098
+ }, "onChange"),
2099
+ className
2100
+ }
2101
+ );
2102
+ }, "AutoFocusInputNumber");
2103
+ function ParagraphSetting() {
2104
+ const localeService = useDependency(LocaleService), alignmentOptions = useMemo(
2105
+ () => [
2106
+ { label: localeService.t("toolbar.alignLeft"), value: String(HorizontalAlign.LEFT), icon: /* @__PURE__ */ jsxRuntimeExports.jsx(LeftJustifyingSingle, {}) },
2107
+ { label: localeService.t("toolbar.alignCenter"), value: String(HorizontalAlign.CENTER), icon: /* @__PURE__ */ jsxRuntimeExports.jsx(HorizontallySingle, {}) },
2108
+ { label: localeService.t("toolbar.alignRight"), value: String(HorizontalAlign.RIGHT), icon: /* @__PURE__ */ jsxRuntimeExports.jsx(RightJustifyingSingle, {}) },
2109
+ { label: localeService.t("toolbar.alignJustify"), value: String(HorizontalAlign.JUSTIFIED), icon: /* @__PURE__ */ jsxRuntimeExports.jsx(AlignTextBothSingle, {}) }
2110
+ ],
2111
+ []
2112
+ ), currentParagraph = useCurrentParagraph(), [horizontalAlignValue, horizontalAlignSet] = useFirstParagraphHorizontalAlign(currentParagraph, alignmentOptions[0].value), [indentStart, indentStartSet] = useFirstParagraphIndentStart(currentParagraph), [indentEnd, indentEndSet] = useFirstParagraphIndentEnd(currentParagraph), [indentFirstLine, indentFirstLineSet] = useFirstParagraphIndentFirstLine(currentParagraph), [hanging, hangingSet] = useFirstParagraphIndentHanging(currentParagraph), [spaceAbove, spaceAboveSet] = useFirstParagraphIndentSpaceAbove(currentParagraph), [spaceBelow, spaceBelowSet] = useFirstParagraphSpaceBelow(currentParagraph), { lineSpacing: [lineSpacing, lineSpacingSet], spacingRule: [spacingRule, spacingRuleSet] } = useFirstParagraphLineSpacing(currentParagraph), lineSpaceConfig = useMemo(() => spacingRule === SpacingRule.AUTO ? { min: 1, max: 5, step: lineSpacing < 2 ? 0.5 : 1 } : { min: 1, max: 100 }, [spacingRule, lineSpacing]);
2113
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSetting, children: [
2114
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles$1.paragraphSettingTitle, children: localeService.t("doc.paragraphSetting.alignment") }),
2115
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `${styles$1.paragraphSettingIconList} ${styles$1.paragraphSettingMtBase}`, children: alignmentOptions.map((item) => /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { title: item.label, placement: "bottom", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
2116
+ "span",
2117
+ {
2118
+ className: clsx(
2119
+ styles$1.paragraphSettingIconListItem,
2120
+ { [styles$1.paragraphSettingIconListActive]: horizontalAlignValue === item.value }
2121
+ ),
2122
+ onClick: /* @__PURE__ */ __name(() => horizontalAlignSet(item.value), "onClick"),
2123
+ children: item.icon
2124
+ }
2125
+ ) }, item.value)) }),
2126
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles$1.paragraphSettingTitle, children: localeService.t("doc.paragraphSetting.indentation") }),
2127
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2128
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingFlexCol, children: [
2129
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingLabel, children: [
2130
+ localeService.t("doc.paragraphSetting.left"),
2131
+ "(px)"
2132
+ ] }),
2133
+ /* @__PURE__ */ jsxRuntimeExports.jsx(AutoFocusInputNumber, { className: styles$1.paragraphSettingMtBase, value: indentStart, onChange: /* @__PURE__ */ __name((v) => indentStartSet(v != null ? v : 0), "onChange") })
2134
+ ] }),
2135
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingFlexCol, children: [
2136
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingLabel, children: [
2137
+ localeService.t("doc.paragraphSetting.right"),
2138
+ "(px)"
2139
+ ] }),
2140
+ /* @__PURE__ */ jsxRuntimeExports.jsx(AutoFocusInputNumber, { className: styles$1.paragraphSettingMtBase, value: indentEnd, onChange: /* @__PURE__ */ __name((v) => indentEndSet(v != null ? v : 0), "onChange") })
2141
+ ] }),
2142
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingFlexCol, children: [
2143
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingLabel, children: [
2144
+ localeService.t("doc.paragraphSetting.firstLine"),
2145
+ "(px)"
2146
+ ] }),
2147
+ /* @__PURE__ */ jsxRuntimeExports.jsx(AutoFocusInputNumber, { className: styles$1.paragraphSettingMtBase, value: indentFirstLine, onChange: /* @__PURE__ */ __name((v) => indentFirstLineSet(v != null ? v : 0), "onChange") })
2148
+ ] }),
2149
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingFlexCol, children: [
2150
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingLabel, children: [
2151
+ localeService.t("doc.paragraphSetting.hanging"),
2152
+ "(px)"
2153
+ ] }),
2154
+ /* @__PURE__ */ jsxRuntimeExports.jsx(AutoFocusInputNumber, { className: styles$1.paragraphSettingMtBase, value: hanging, onChange: /* @__PURE__ */ __name((v) => hangingSet(v != null ? v : 0), "onChange") })
2155
+ ] })
2156
+ ] }),
2157
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles$1.paragraphSettingTitle, children: localeService.t("doc.paragraphSetting.spacing") }),
2158
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2159
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingFlexCol, children: [
2160
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingLabel, children: [
2161
+ localeService.t("doc.paragraphSetting.before"),
2162
+ "(px)"
2163
+ ] }),
2164
+ /* @__PURE__ */ jsxRuntimeExports.jsx(AutoFocusInputNumber, { className: styles$1.paragraphSettingMtBase, value: spaceAbove, onChange: /* @__PURE__ */ __name((v) => spaceAboveSet(v != null ? v : 0), "onChange") })
2165
+ ] }),
2166
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingFlexCol, children: [
2167
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingLabel, children: [
2168
+ localeService.t("doc.paragraphSetting.after"),
2169
+ "(px)"
2170
+ ] }),
2171
+ /* @__PURE__ */ jsxRuntimeExports.jsx(AutoFocusInputNumber, { className: styles$1.paragraphSettingMtBase, value: spaceBelow, onChange: /* @__PURE__ */ __name((v) => spaceBelowSet(v != null ? v : 0), "onChange") })
2172
+ ] }),
2173
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingFlexCol, children: [
2174
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles$1.paragraphSettingLabel, children: localeService.t("doc.paragraphSetting.lineSpace") }),
2175
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `${styles$1.paragraphSettingMtBase} ${styles$1.paragraphSettingSpaceLine}`, style: { width: 162 }, children: [
2176
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
2177
+ Select,
2178
+ {
2179
+ value: `${spacingRule}`,
2180
+ options: [
2181
+ { label: localeService.t("doc.paragraphSetting.multiSpace"), value: `${SpacingRule.AUTO}` },
2182
+ { label: localeService.t("doc.paragraphSetting.fixedValue"), value: `${SpacingRule.AT_LEAST}` }
2183
+ ],
2184
+ onChange: /* @__PURE__ */ __name((v) => spacingRuleSet(Number(v)), "onChange")
2185
+ }
2186
+ ),
2187
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
2188
+ AutoFocusInputNumber,
2189
+ {
2190
+ ...lineSpaceConfig,
2191
+ value: lineSpacing,
2192
+ onChange: /* @__PURE__ */ __name((v) => lineSpacingSet(v != null ? v : 0), "onChange")
2193
+ }
2194
+ )
2195
+ ] })
2196
+ ] })
2197
+ ] })
2198
+ ] });
2199
+ }
2200
+ __name(ParagraphSetting, "ParagraphSetting");
2201
+ const isRangesEqual = /* @__PURE__ */ __name((oldRanges, ranges) => ranges.length === oldRanges.length && oldRanges.some((oldRange) => ranges.some((range) => range.startOffset === oldRange.startOffset && range.endOffset === oldRange.endOffset)), "isRangesEqual"), isRangesIntersection = /* @__PURE__ */ __name((oldRanges, ranges) => oldRanges.some((oldRange) => ranges.some((range) => {
2202
+ const { startOffset: activeStart, endOffset: activeEnd } = oldRange, { startOffset: compareStart, endOffset: compareEnd } = range;
2203
+ return activeStart == null || activeEnd == null || compareStart == null || compareEnd == null ? !1 : activeStart <= compareEnd && activeEnd >= compareStart;
2204
+ })), "isRangesIntersection");
2205
+ function ParagraphSettingIndex() {
2206
+ const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), currentLocale = useObservable(localeService.currentLocale$), [key, keySet] = useState(""), rangeRef = useRef([]);
2207
+ return useEffect(() => {
2208
+ const dispose = commandService.onCommandExecuted((info) => {
2209
+ var _a22;
2210
+ if (SetTextSelectionsOperation.id === info.id) {
2211
+ const ranges = info.params.ranges;
2212
+ isRangesEqual(ranges, rangeRef.current) || keySet(generateRandomId(4)), rangeRef.current = ranges;
2213
+ }
2214
+ if (RichTextEditingMutation.id === info.id) {
2215
+ const params = info.params, ranges = (_a22 = params.textRanges) != null ? _a22 : [];
2216
+ params.trigger !== DocParagraphSettingCommand.id && isRangesIntersection(ranges, rangeRef.current) && keySet(generateRandomId(4));
2217
+ }
2218
+ });
2219
+ return () => dispose.dispose();
2220
+ }, []), useEffect(() => {
2221
+ keySet(generateRandomId(4));
2222
+ }, [currentLocale]), /* @__PURE__ */ jsxRuntimeExports.jsx(ParagraphSetting, {}, key);
2223
+ }
2224
+ __name(ParagraphSettingIndex, "ParagraphSettingIndex");
2225
+ var __defProp$f = Object.defineProperty, __getOwnPropDesc$f = Object.getOwnPropertyDescriptor, __decorateClass$f = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2226
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$f(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2227
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2228
+ return kind && result && __defProp$f(target, key, result), result;
2229
+ }, "__decorateClass$f"), __decorateParam$f = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$f");
2230
+ const paragraphSettingIndexKey = "doc_ui_paragraph-setting-panel";
2231
+ var _a6;
2232
+ let DocParagraphSettingController = (_a6 = class extends Disposable {
2233
+ constructor(_commandService, _componentManager, _sidebarService) {
2234
+ super();
2235
+ __publicField(this, "_id");
2236
+ this._commandService = _commandService, this._componentManager = _componentManager, this._sidebarService = _sidebarService, this._init();
2237
+ }
2238
+ _init() {
2239
+ this.disposeWithMe(this._componentManager.register(paragraphSettingIndexKey, ParagraphSettingIndex));
2240
+ }
2241
+ openPanel() {
2242
+ const props = {
2243
+ header: { title: "doc.slider.paragraphSetting" },
2244
+ id: this._id,
2245
+ children: {
2246
+ label: paragraphSettingIndexKey
2247
+ },
2248
+ width: 300
2249
+ };
2250
+ this._sidebarService.open(props);
2251
+ }
2252
+ closePanel() {
2253
+ this._sidebarService.close(this._id);
2254
+ }
2255
+ }, __name(_a6, "DocParagraphSettingController"), _a6);
2256
+ DocParagraphSettingController = __decorateClass$f([
2257
+ OnLifecycle(LifecycleStages.Rendered, DocParagraphSettingController),
2258
+ __decorateParam$f(0, ICommandService),
2259
+ __decorateParam$f(1, Inject(ComponentManager)),
2260
+ __decorateParam$f(2, Inject(ISidebarService))
2261
+ ], DocParagraphSettingController);
2262
+ const DocParagraphSettingPanelOperation = {
2263
+ id: "sidebar.operation.doc-paragraph-setting-panel",
2264
+ type: CommandType.OPERATION,
2265
+ handler: /* @__PURE__ */ __name((accessor) => (accessor.get(DocParagraphSettingController).openPanel(), !0), "handler")
2266
+ };
2267
+ function getInsertTableHiddenObservable(accessor) {
2268
+ const univerInstanceService = accessor.get(IUniverInstanceService), renderManagerService = accessor.get(IRenderManagerService);
2269
+ return new Observable((subscriber) => {
2270
+ const subscription = univerInstanceService.focused$.subscribe((unitId) => {
2271
+ if (unitId == null || univerInstanceService.getUnitType(unitId) !== UniverInstanceType.UNIVER_DOC)
2272
+ return subscriber.next(!0);
2273
+ const currentRender2 = renderManagerService.getRenderById(unitId);
2274
+ if (currentRender2 == null)
2275
+ return subscriber.next(!0);
2276
+ currentRender2.with(DocSkeletonManagerService).getViewModel().editAreaChange$.subscribe((editArea) => {
2277
+ subscriber.next(editArea === DocumentEditArea.HEADER || editArea === DocumentEditArea.FOOTER);
2042
2278
  });
2043
- return subscriber.next(!1), disposable.dispose;
2044
- }),
2045
- disabled$: disableMenuWhenNoDocRange(accessor),
2046
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2047
- };
2279
+ }), currentRender = renderManagerService.getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_DOC);
2280
+ if (currentRender == null)
2281
+ return subscriber.next(!0);
2282
+ const viewModel = currentRender.with(DocSkeletonManagerService).getViewModel();
2283
+ return subscriber.next(viewModel.getEditArea() !== DocumentEditArea.BODY), () => subscription.unsubscribe();
2284
+ });
2048
2285
  }
2049
- __name(UnderlineMenuItemFactory, "UnderlineMenuItemFactory");
2050
- function StrikeThroughMenuItemFactory(accessor) {
2051
- const commandService = accessor.get(ICommandService);
2052
- return {
2053
- id: SetInlineFormatStrikethroughCommand.id,
2054
- group: MenuGroup.TOOLBAR_FORMAT,
2055
- type: MenuItemType.BUTTON,
2056
- icon: "StrikethroughSingle",
2057
- title: "Set strike through",
2058
- tooltip: "toolbar.strikethrough",
2059
- positions: [MenuPosition.TOOLBAR_START],
2060
- activated$: new Observable((subscriber) => {
2061
- const disposable = commandService.onCommandExecuted((c) => {
2062
- var _a22;
2063
- const id = c.id;
2064
- if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
2065
- const textRun = getFontStyleAtCursor(accessor);
2066
- if (textRun == null) {
2067
- subscriber.next(!1);
2068
- return;
2069
- }
2070
- const st = (_a22 = textRun.ts) == null ? void 0 : _a22.st;
2071
- subscriber.next((st == null ? void 0 : st.s) === BooleanNumber.TRUE);
2286
+ __name(getInsertTableHiddenObservable, "getInsertTableHiddenObservable");
2287
+ function getTableDisabledObservable(accessor) {
2288
+ const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService);
2289
+ return new Observable((subscriber) => {
2290
+ const subscription = textSelectionManagerService.textSelection$.subscribe((selection) => {
2291
+ if (selection == null) {
2292
+ subscriber.next(!0);
2293
+ return;
2294
+ }
2295
+ const { textRanges } = selection;
2296
+ if (textRanges.length !== 1) {
2297
+ subscriber.next(!0);
2298
+ return;
2299
+ }
2300
+ const textRange = textRanges[0], { collapsed, anchorNodePosition, startOffset } = textRange;
2301
+ if (!collapsed || startOffset == null) {
2302
+ subscriber.next(!0);
2303
+ return;
2304
+ }
2305
+ const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
2306
+ if (docDataModel == null) {
2307
+ subscriber.next(!0);
2308
+ return;
2309
+ }
2310
+ const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId());
2311
+ if (docSkeletonManagerService == null) {
2312
+ subscriber.next(!0);
2313
+ return;
2314
+ }
2315
+ if (docSkeletonManagerService.getViewModel().getCustomRangeRaw(startOffset)) {
2316
+ subscriber.next(!0);
2317
+ return;
2318
+ }
2319
+ if (anchorNodePosition != null) {
2320
+ const { path } = anchorNodePosition;
2321
+ if (path.indexOf("cells") !== -1) {
2322
+ subscriber.next(!0);
2323
+ return;
2072
2324
  }
2073
- });
2074
- return subscriber.next(!1), disposable.dispose;
2075
- }),
2076
- disabled$: disableMenuWhenNoDocRange(accessor),
2077
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2078
- };
2325
+ }
2326
+ subscriber.next(!1);
2327
+ });
2328
+ return () => subscription.unsubscribe();
2329
+ });
2079
2330
  }
2080
- __name(StrikeThroughMenuItemFactory, "StrikeThroughMenuItemFactory");
2081
- function SubscriptMenuItemFactory(accessor) {
2082
- const commandService = accessor.get(ICommandService);
2083
- return {
2084
- id: SetInlineFormatSubscriptCommand.id,
2085
- group: MenuGroup.TOOLBAR_FORMAT,
2086
- type: MenuItemType.BUTTON,
2087
- icon: "SubscriptSingle",
2088
- tooltip: "toolbar.subscript",
2089
- positions: [MenuPosition.TOOLBAR_START],
2090
- activated$: new Observable((subscriber) => {
2091
- const disposable = commandService.onCommandExecuted((c) => {
2092
- var _a22;
2093
- const id = c.id;
2094
- if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
2095
- const textRun = getFontStyleAtCursor(accessor);
2096
- if (textRun == null) {
2097
- subscriber.next(!1);
2098
- return;
2099
- }
2100
- const va = (_a22 = textRun.ts) == null ? void 0 : _a22.va;
2101
- subscriber.next(va === BaselineOffset.SUBSCRIPT);
2102
- }
2103
- });
2104
- return subscriber.next(!1), disposable.dispose;
2105
- }),
2106
- disabled$: disableMenuWhenNoDocRange(accessor),
2107
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2108
- };
2331
+ __name(getTableDisabledObservable, "getTableDisabledObservable");
2332
+ function disableMenuWhenNoDocRange(accessor) {
2333
+ const textSelectionManagerService = accessor.get(TextSelectionManagerService);
2334
+ return new Observable((subscriber) => {
2335
+ const subscription = textSelectionManagerService.textSelection$.subscribe((selection) => {
2336
+ if (selection == null) {
2337
+ subscriber.next(!0);
2338
+ return;
2339
+ }
2340
+ const { textRanges, rectRanges } = selection;
2341
+ if (textRanges.length === 0 && rectRanges.length === 0) {
2342
+ subscriber.next(!0);
2343
+ return;
2344
+ }
2345
+ subscriber.next(!1);
2346
+ });
2347
+ return () => subscription.unsubscribe();
2348
+ });
2109
2349
  }
2110
- __name(SubscriptMenuItemFactory, "SubscriptMenuItemFactory");
2111
- function SuperscriptMenuItemFactory(accessor) {
2350
+ __name(disableMenuWhenNoDocRange, "disableMenuWhenNoDocRange");
2351
+ function BoldMenuItemFactory(accessor) {
2112
2352
  const commandService = accessor.get(ICommandService);
2113
2353
  return {
2114
- id: SetInlineFormatSuperscriptCommand.id,
2115
- group: MenuGroup.TOOLBAR_FORMAT,
2354
+ id: SetInlineFormatBoldCommand.id,
2116
2355
  type: MenuItemType.BUTTON,
2117
- icon: "SuperscriptSingle",
2118
- tooltip: "toolbar.superscript",
2119
- positions: [MenuPosition.TOOLBAR_START],
2356
+ icon: "BoldSingle",
2357
+ title: "Set bold",
2358
+ tooltip: "toolbar.bold",
2120
2359
  activated$: new Observable((subscriber) => {
2121
2360
  const disposable = commandService.onCommandExecuted((c) => {
2122
2361
  var _a22;
@@ -2124,213 +2363,69 @@ function SuperscriptMenuItemFactory(accessor) {
2124
2363
  if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
2125
2364
  const textRun = getFontStyleAtCursor(accessor);
2126
2365
  if (textRun == null) {
2127
- subscriber.next(!1);
2128
- return;
2129
- }
2130
- const va = (_a22 = textRun.ts) == null ? void 0 : _a22.va;
2131
- subscriber.next(va === BaselineOffset.SUPERSCRIPT);
2132
- }
2133
- });
2134
- return subscriber.next(!1), disposable.dispose;
2135
- }),
2136
- disabled$: disableMenuWhenNoDocRange(accessor),
2137
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2138
- };
2139
- }
2140
- __name(SuperscriptMenuItemFactory, "SuperscriptMenuItemFactory");
2141
- function FontFamilySelectorMenuItemFactory(accessor) {
2142
- const commandService = accessor.get(ICommandService);
2143
- return {
2144
- id: SetInlineFormatFontFamilyCommand.id,
2145
- tooltip: "toolbar.font",
2146
- group: MenuGroup.TOOLBAR_FORMAT,
2147
- type: MenuItemType.SELECTOR,
2148
- label: FONT_FAMILY_COMPONENT,
2149
- positions: [MenuPosition.TOOLBAR_START],
2150
- selections: FONT_FAMILY_LIST.map((item) => ({
2151
- label: {
2152
- name: FONT_FAMILY_ITEM_COMPONENT,
2153
- hoverable: !0
2154
- },
2155
- value: item.value
2156
- })),
2157
- // disabled$: getCurrentSheetDisabled$(accessor),
2158
- value$: new Observable((subscriber) => {
2159
- const defaultValue = FONT_FAMILY_LIST[0].value, disposable = commandService.onCommandExecuted((c) => {
2160
- var _a22;
2161
- const id = c.id;
2162
- if (id === SetTextSelectionsOperation.id || id === SetInlineFormatFontFamilyCommand.id) {
2163
- const textRun = getFontStyleAtCursor(accessor);
2164
- if (textRun == null) {
2165
- subscriber.next(defaultValue);
2166
- return;
2167
- }
2168
- const ff = (_a22 = textRun.ts) == null ? void 0 : _a22.ff;
2169
- subscriber.next(ff != null ? ff : defaultValue);
2170
- }
2171
- });
2172
- return subscriber.next(defaultValue), disposable.dispose;
2173
- }),
2174
- disabled$: disableMenuWhenNoDocRange(accessor),
2175
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2176
- };
2177
- }
2178
- __name(FontFamilySelectorMenuItemFactory, "FontFamilySelectorMenuItemFactory");
2179
- function FontSizeSelectorMenuItemFactory(accessor) {
2180
- const commandService = accessor.get(ICommandService);
2181
- return {
2182
- id: SetInlineFormatFontSizeCommand.id,
2183
- group: MenuGroup.TOOLBAR_FORMAT,
2184
- type: MenuItemType.SELECTOR,
2185
- tooltip: "toolbar.fontSize",
2186
- label: {
2187
- name: FONT_SIZE_COMPONENT,
2188
- props: {
2189
- min: 1,
2190
- max: 400
2191
- // disabled$,
2192
- }
2193
- },
2194
- positions: [MenuPosition.TOOLBAR_START],
2195
- selections: FONT_SIZE_LIST,
2196
- // disabled$,
2197
- value$: new Observable((subscriber) => {
2198
- const disposable = commandService.onCommandExecuted((c) => {
2199
- var _a22;
2200
- const id = c.id;
2201
- if (id === SetTextSelectionsOperation.id || id === SetInlineFormatFontSizeCommand.id) {
2202
- const textRun = getFontStyleAtCursor(accessor);
2203
- if (textRun == null) {
2204
- subscriber.next(14);
2205
- return;
2206
- }
2207
- const fs = (_a22 = textRun.ts) == null ? void 0 : _a22.fs;
2208
- subscriber.next(fs != null ? fs : 14);
2209
- }
2210
- });
2211
- return subscriber.next(14), disposable.dispose;
2212
- }),
2213
- disabled$: disableMenuWhenNoDocRange(accessor),
2214
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2215
- };
2216
- }
2217
- __name(FontSizeSelectorMenuItemFactory, "FontSizeSelectorMenuItemFactory");
2218
- function TextColorSelectorMenuItemFactory(accessor) {
2219
- const commandService = accessor.get(ICommandService), themeService = accessor.get(ThemeService);
2220
- return {
2221
- id: SetInlineFormatTextColorCommand.id,
2222
- icon: "FontColor",
2223
- tooltip: "toolbar.textColor.main",
2224
- group: MenuGroup.TOOLBAR_FORMAT,
2225
- type: MenuItemType.BUTTON_SELECTOR,
2226
- positions: [MenuPosition.TOOLBAR_START],
2227
- selections: [
2228
- {
2229
- label: {
2230
- name: COLOR_PICKER_COMPONENT,
2231
- hoverable: !1
2232
- }
2233
- }
2234
- ],
2235
- value$: new Observable((subscriber) => {
2236
- const defaultColor = themeService.getCurrentTheme().textColor, disposable = commandService.onCommandExecuted((c) => {
2237
- if (c.id === SetInlineFormatTextColorCommand.id) {
2238
- const color = c.params.value;
2239
- subscriber.next(color != null ? color : defaultColor);
2366
+ subscriber.next(!1);
2367
+ return;
2368
+ }
2369
+ const bl = (_a22 = textRun.ts) == null ? void 0 : _a22.bl;
2370
+ subscriber.next(bl === BooleanNumber.TRUE);
2240
2371
  }
2241
2372
  });
2242
- return subscriber.next(defaultColor), disposable.dispose;
2373
+ return subscriber.next(!1), disposable.dispose;
2243
2374
  }),
2244
2375
  disabled$: disableMenuWhenNoDocRange(accessor),
2245
2376
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2246
- // disabled$: getCurrentSheetDisabled$(accessor),
2247
- };
2248
- }
2249
- __name(TextColorSelectorMenuItemFactory, "TextColorSelectorMenuItemFactory");
2250
- function HeaderFooterMenuItemFactory(accessor) {
2251
- return {
2252
- id: OpenHeaderFooterPanelCommand.id,
2253
- group: MenuGroup.TOOLBAR_OTHERS,
2254
- type: MenuItemType.BUTTON,
2255
- icon: "FreezeRowSingle",
2256
- tooltip: "toolbar.headerFooter",
2257
- positions: [MenuPosition.TOOLBAR_START],
2258
- hidden$: combineLatest(getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC), getHeaderFooterMenuHiddenObservable(accessor), (one, two) => one || two)
2259
- };
2260
- }
2261
- __name(HeaderFooterMenuItemFactory, "HeaderFooterMenuItemFactory");
2262
- const TableIcon = "GridSingle", TABLE_MENU_ID = "doc.menu.table";
2263
- function TableMenuFactory(accessor) {
2264
- return {
2265
- id: TABLE_MENU_ID,
2266
- type: MenuItemType.SUBITEMS,
2267
- positions: [MenuPosition.TOOLBAR_START],
2268
- group: MenuGroup.TOOLBAR_LAYOUT,
2269
- icon: TableIcon,
2270
- tooltip: "toolbar.table.main",
2271
- disabled$: getTableDisabledObservable(accessor),
2272
- // Do not show header footer menu and insert table at zen mode.
2273
- hidden$: combineLatest(getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC), getInsertTableHiddenObservable(accessor), getHeaderFooterMenuHiddenObservable(accessor), (one, two, three) => one || two || three)
2274
- };
2275
- }
2276
- __name(TableMenuFactory, "TableMenuFactory");
2277
- function InsertTableMenuFactory(_accessor) {
2278
- return {
2279
- id: DocCreateTableOperation.id,
2280
- title: "toolbar.table.insert",
2281
- type: MenuItemType.BUTTON,
2282
- positions: [TABLE_MENU_ID],
2283
- hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_DOC)
2284
2377
  };
2285
2378
  }
2286
- __name(InsertTableMenuFactory, "InsertTableMenuFactory");
2287
- function AlignLeftMenuItemFactory(accessor) {
2379
+ __name(BoldMenuItemFactory, "BoldMenuItemFactory");
2380
+ function ItalicMenuItemFactory(accessor) {
2288
2381
  const commandService = accessor.get(ICommandService);
2289
2382
  return {
2290
- id: AlignLeftCommand.id,
2291
- group: MenuGroup.TOOLBAR_LAYOUT,
2383
+ id: SetInlineFormatItalicCommand.id,
2292
2384
  type: MenuItemType.BUTTON,
2293
- icon: "LeftJustifyingSingle",
2294
- tooltip: "toolbar.alignLeft",
2295
- positions: [MenuPosition.TOOLBAR_START],
2296
- disabled$: disableMenuWhenNoDocRange(accessor),
2385
+ icon: "ItalicSingle",
2386
+ title: "Set italic",
2387
+ tooltip: "toolbar.italic",
2297
2388
  activated$: new Observable((subscriber) => {
2298
2389
  const disposable = commandService.onCommandExecuted((c) => {
2299
2390
  var _a22;
2300
2391
  const id = c.id;
2301
- if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
2302
- const paragraph = getParagraphStyleAtCursor(accessor);
2303
- if (paragraph == null)
2392
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
2393
+ const textRun = getFontStyleAtCursor(accessor);
2394
+ if (textRun == null) {
2395
+ subscriber.next(!1);
2304
2396
  return;
2305
- const alignType = (_a22 = paragraph.paragraphStyle) == null ? void 0 : _a22.horizontalAlign;
2306
- subscriber.next(alignType === HorizontalAlign.LEFT);
2397
+ }
2398
+ const it = (_a22 = textRun.ts) == null ? void 0 : _a22.it;
2399
+ subscriber.next(it === BooleanNumber.TRUE);
2307
2400
  }
2308
2401
  });
2309
2402
  return subscriber.next(!1), disposable.dispose;
2310
2403
  }),
2404
+ disabled$: disableMenuWhenNoDocRange(accessor),
2311
2405
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2312
2406
  };
2313
2407
  }
2314
- __name(AlignLeftMenuItemFactory, "AlignLeftMenuItemFactory");
2315
- function AlignCenterMenuItemFactory(accessor) {
2408
+ __name(ItalicMenuItemFactory, "ItalicMenuItemFactory");
2409
+ function UnderlineMenuItemFactory(accessor) {
2316
2410
  const commandService = accessor.get(ICommandService);
2317
2411
  return {
2318
- id: AlignCenterCommand.id,
2319
- group: MenuGroup.TOOLBAR_LAYOUT,
2412
+ id: SetInlineFormatUnderlineCommand.id,
2320
2413
  type: MenuItemType.BUTTON,
2321
- icon: "HorizontallySingle",
2322
- tooltip: "toolbar.alignCenter",
2323
- positions: [MenuPosition.TOOLBAR_START],
2414
+ icon: "UnderlineSingle",
2415
+ title: "Set underline",
2416
+ tooltip: "toolbar.underline",
2324
2417
  activated$: new Observable((subscriber) => {
2325
2418
  const disposable = commandService.onCommandExecuted((c) => {
2326
2419
  var _a22;
2327
2420
  const id = c.id;
2328
- if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
2329
- const paragraph = getParagraphStyleAtCursor(accessor);
2330
- if (paragraph == null)
2421
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
2422
+ const textRun = getFontStyleAtCursor(accessor);
2423
+ if (textRun == null) {
2424
+ subscriber.next(!1);
2331
2425
  return;
2332
- const alignType = (_a22 = paragraph.paragraphStyle) == null ? void 0 : _a22.horizontalAlign;
2333
- subscriber.next(alignType === HorizontalAlign.CENTER);
2426
+ }
2427
+ const ul = (_a22 = textRun.ts) == null ? void 0 : _a22.ul;
2428
+ subscriber.next((ul == null ? void 0 : ul.s) === BooleanNumber.TRUE);
2334
2429
  }
2335
2430
  });
2336
2431
  return subscriber.next(!1), disposable.dispose;
@@ -2339,26 +2434,27 @@ function AlignCenterMenuItemFactory(accessor) {
2339
2434
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2340
2435
  };
2341
2436
  }
2342
- __name(AlignCenterMenuItemFactory, "AlignCenterMenuItemFactory");
2343
- function AlignRightMenuItemFactory(accessor) {
2437
+ __name(UnderlineMenuItemFactory, "UnderlineMenuItemFactory");
2438
+ function StrikeThroughMenuItemFactory(accessor) {
2344
2439
  const commandService = accessor.get(ICommandService);
2345
2440
  return {
2346
- id: AlignRightCommand.id,
2347
- group: MenuGroup.TOOLBAR_LAYOUT,
2441
+ id: SetInlineFormatStrikethroughCommand.id,
2348
2442
  type: MenuItemType.BUTTON,
2349
- icon: "RightJustifyingSingle",
2350
- tooltip: "toolbar.alignRight",
2351
- positions: [MenuPosition.TOOLBAR_START],
2443
+ icon: "StrikethroughSingle",
2444
+ title: "Set strike through",
2445
+ tooltip: "toolbar.strikethrough",
2352
2446
  activated$: new Observable((subscriber) => {
2353
2447
  const disposable = commandService.onCommandExecuted((c) => {
2354
2448
  var _a22;
2355
2449
  const id = c.id;
2356
- if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
2357
- const paragraph = getParagraphStyleAtCursor(accessor);
2358
- if (paragraph == null)
2450
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
2451
+ const textRun = getFontStyleAtCursor(accessor);
2452
+ if (textRun == null) {
2453
+ subscriber.next(!1);
2359
2454
  return;
2360
- const alignType = (_a22 = paragraph.paragraphStyle) == null ? void 0 : _a22.horizontalAlign;
2361
- subscriber.next(alignType === HorizontalAlign.RIGHT);
2455
+ }
2456
+ const st = (_a22 = textRun.ts) == null ? void 0 : _a22.st;
2457
+ subscriber.next((st == null ? void 0 : st.s) === BooleanNumber.TRUE);
2362
2458
  }
2363
2459
  });
2364
2460
  return subscriber.next(!1), disposable.dispose;
@@ -2367,26 +2463,26 @@ function AlignRightMenuItemFactory(accessor) {
2367
2463
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2368
2464
  };
2369
2465
  }
2370
- __name(AlignRightMenuItemFactory, "AlignRightMenuItemFactory");
2371
- function AlignJustifyMenuItemFactory(accessor) {
2466
+ __name(StrikeThroughMenuItemFactory, "StrikeThroughMenuItemFactory");
2467
+ function SubscriptMenuItemFactory(accessor) {
2372
2468
  const commandService = accessor.get(ICommandService);
2373
2469
  return {
2374
- id: AlignJustifyCommand.id,
2375
- group: MenuGroup.TOOLBAR_LAYOUT,
2470
+ id: SetInlineFormatSubscriptCommand.id,
2376
2471
  type: MenuItemType.BUTTON,
2377
- icon: "AlignTextBothSingle",
2378
- tooltip: "toolbar.alignJustify",
2379
- positions: [MenuPosition.TOOLBAR_START],
2472
+ icon: "SubscriptSingle",
2473
+ tooltip: "toolbar.subscript",
2380
2474
  activated$: new Observable((subscriber) => {
2381
2475
  const disposable = commandService.onCommandExecuted((c) => {
2382
2476
  var _a22;
2383
2477
  const id = c.id;
2384
- if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
2385
- const paragraph = getParagraphStyleAtCursor(accessor);
2386
- if (paragraph == null)
2478
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
2479
+ const textRun = getFontStyleAtCursor(accessor);
2480
+ if (textRun == null) {
2481
+ subscriber.next(!1);
2387
2482
  return;
2388
- const alignType = (_a22 = paragraph.paragraphStyle) == null ? void 0 : _a22.horizontalAlign;
2389
- subscriber.next(alignType === HorizontalAlign.JUSTIFIED);
2483
+ }
2484
+ const va = (_a22 = textRun.ts) == null ? void 0 : _a22.va;
2485
+ subscriber.next(va === BaselineOffset.SUBSCRIPT);
2390
2486
  }
2391
2487
  });
2392
2488
  return subscriber.next(!1), disposable.dispose;
@@ -2395,503 +2491,432 @@ function AlignJustifyMenuItemFactory(accessor) {
2395
2491
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2396
2492
  };
2397
2493
  }
2398
- __name(AlignJustifyMenuItemFactory, "AlignJustifyMenuItemFactory");
2399
- const listValueFactory$ = /* @__PURE__ */ __name((accessor) => new Observable((subscriber) => {
2400
- const univerInstanceService = accessor.get(IUniverInstanceService), textSelectionManagerService = accessor.get(TextSelectionManagerService);
2401
- let textSubscription;
2402
- const subscription = univerInstanceService.focused$.subscribe((unitId) => {
2403
- if (textSubscription == null || textSubscription.unsubscribe(), unitId == null)
2404
- return;
2405
- const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
2406
- docDataModel != null && (textSubscription = textSelectionManagerService.textSelection$.subscribe(() => {
2407
- var _a22, _b;
2408
- const range = textSelectionManagerService.getActiveTextRangeWithStyle();
2409
- if (range) {
2410
- const doc = docDataModel.getSelfOrHeaderFooterModel(range == null ? void 0 : range.segmentId), paragraphs = getParagraphsInRange(range, (_b = (_a22 = doc.getBody()) == null ? void 0 : _a22.paragraphs) != null ? _b : []);
2411
- let listType;
2412
- if (paragraphs.every((p2) => {
2413
- var _a23;
2414
- return listType || (listType = (_a23 = p2.bullet) == null ? void 0 : _a23.listType), p2.bullet && p2.bullet.listType === listType;
2415
- })) {
2416
- subscriber.next(listType);
2417
- return;
2418
- }
2419
- }
2420
- subscriber.next(void 0);
2421
- }));
2422
- });
2423
- return () => {
2424
- subscription.unsubscribe(), textSubscription == null || textSubscription.unsubscribe();
2425
- };
2426
- }), "listValueFactory$");
2427
- function OrderListMenuItemFactory(accessor) {
2428
- return {
2429
- id: OrderListCommand.id,
2430
- group: MenuGroup.TOOLBAR_LAYOUT,
2431
- type: MenuItemType.BUTTON_SELECTOR,
2432
- selections: [
2433
- {
2434
- label: {
2435
- name: ORDER_LIST_TYPE_COMPONENT,
2436
- hoverable: !1
2437
- },
2438
- value$: listValueFactory$(accessor)
2439
- }
2440
- ],
2441
- icon: "OrderSingle",
2442
- tooltip: "toolbar.order",
2443
- positions: [MenuPosition.TOOLBAR_START],
2444
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
2445
- disabled$: disableMenuWhenNoDocRange(accessor),
2446
- activated$: listValueFactory$(accessor).pipe(map((v) => v && v.indexOf("ORDER_LIST") === 0))
2447
- };
2448
- }
2449
- __name(OrderListMenuItemFactory, "OrderListMenuItemFactory");
2450
- function BulletListMenuItemFactory(accessor) {
2451
- return {
2452
- id: BulletListCommand.id,
2453
- group: MenuGroup.TOOLBAR_LAYOUT,
2454
- type: MenuItemType.BUTTON_SELECTOR,
2455
- selections: [
2456
- {
2457
- label: {
2458
- name: BULLET_LIST_TYPE_COMPONENT,
2459
- hoverable: !1
2460
- },
2461
- value$: listValueFactory$(accessor)
2462
- }
2463
- ],
2464
- icon: "UnorderSingle",
2465
- tooltip: "toolbar.unorder",
2466
- positions: [MenuPosition.TOOLBAR_START],
2467
- disabled$: disableMenuWhenNoDocRange(accessor),
2468
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
2469
- activated$: listValueFactory$(accessor).pipe(map((v) => v && v.indexOf("BULLET_LIST") === 0))
2470
- };
2471
- }
2472
- __name(BulletListMenuItemFactory, "BulletListMenuItemFactory");
2473
- function CheckListMenuItemFactory(accessor) {
2494
+ __name(SubscriptMenuItemFactory, "SubscriptMenuItemFactory");
2495
+ function SuperscriptMenuItemFactory(accessor) {
2496
+ const commandService = accessor.get(ICommandService);
2474
2497
  return {
2475
- id: CheckListCommand.id,
2476
- group: MenuGroup.TOOLBAR_LAYOUT,
2498
+ id: SetInlineFormatSuperscriptCommand.id,
2477
2499
  type: MenuItemType.BUTTON,
2478
- icon: "TodoList",
2479
- tooltip: "toolbar.checklist",
2480
- positions: [MenuPosition.TOOLBAR_START],
2500
+ icon: "SuperscriptSingle",
2501
+ tooltip: "toolbar.superscript",
2502
+ activated$: new Observable((subscriber) => {
2503
+ const disposable = commandService.onCommandExecuted((c) => {
2504
+ var _a22;
2505
+ const id = c.id;
2506
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
2507
+ const textRun = getFontStyleAtCursor(accessor);
2508
+ if (textRun == null) {
2509
+ subscriber.next(!1);
2510
+ return;
2511
+ }
2512
+ const va = (_a22 = textRun.ts) == null ? void 0 : _a22.va;
2513
+ subscriber.next(va === BaselineOffset.SUPERSCRIPT);
2514
+ }
2515
+ });
2516
+ return subscriber.next(!1), disposable.dispose;
2517
+ }),
2481
2518
  disabled$: disableMenuWhenNoDocRange(accessor),
2482
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
2483
- activated$: listValueFactory$(accessor).pipe(map((v) => v && v.indexOf("CHECK_LIST") === 0))
2484
- };
2485
- }
2486
- __name(CheckListMenuItemFactory, "CheckListMenuItemFactory");
2487
- function ResetBackgroundColorMenuItemFactory(accessor) {
2488
- return {
2489
- id: ResetInlineFormatTextBackgroundColorCommand.id,
2490
- type: MenuItemType.BUTTON,
2491
- title: "toolbar.resetColor",
2492
- icon: "NoColor",
2493
- positions: SetInlineFormatTextBackgroundColorCommand.id
2519
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2494
2520
  };
2495
2521
  }
2496
- __name(ResetBackgroundColorMenuItemFactory, "ResetBackgroundColorMenuItemFactory");
2497
- function BackgroundColorSelectorMenuItemFactory(accessor) {
2498
- const commandService = accessor.get(ICommandService), themeService = accessor.get(ThemeService);
2522
+ __name(SuperscriptMenuItemFactory, "SuperscriptMenuItemFactory");
2523
+ function FontFamilySelectorMenuItemFactory(accessor) {
2524
+ const commandService = accessor.get(ICommandService);
2499
2525
  return {
2500
- id: SetInlineFormatTextBackgroundColorCommand.id,
2501
- tooltip: "toolbar.fillColor.main",
2502
- group: MenuGroup.TOOLBAR_FORMAT,
2503
- type: MenuItemType.BUTTON_SELECTOR,
2504
- positions: [MenuPosition.TOOLBAR_START],
2505
- icon: "PaintBucket",
2506
- selections: [
2507
- {
2508
- label: {
2509
- name: COLOR_PICKER_COMPONENT,
2510
- hoverable: !1
2511
- }
2512
- }
2513
- ],
2526
+ id: SetInlineFormatFontFamilyCommand.id,
2527
+ tooltip: "toolbar.font",
2528
+ type: MenuItemType.SELECTOR,
2529
+ label: FONT_FAMILY_COMPONENT,
2530
+ selections: FONT_FAMILY_LIST.map((item) => ({
2531
+ label: {
2532
+ name: FONT_FAMILY_ITEM_COMPONENT,
2533
+ hoverable: !0
2534
+ },
2535
+ value: item.value
2536
+ })),
2537
+ // disabled$: getCurrentSheetDisabled$(accessor),
2514
2538
  value$: new Observable((subscriber) => {
2515
- const defaultColor = themeService.getCurrentTheme().primaryColor, disposable = commandService.onCommandExecuted((c) => {
2516
- if (c.id === SetInlineFormatTextBackgroundColorCommand.id) {
2517
- const color = c.params.value;
2518
- subscriber.next(color != null ? color : defaultColor);
2539
+ const defaultValue = FONT_FAMILY_LIST[0].value, disposable = commandService.onCommandExecuted((c) => {
2540
+ var _a22;
2541
+ const id = c.id;
2542
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatFontFamilyCommand.id) {
2543
+ const textRun = getFontStyleAtCursor(accessor);
2544
+ if (textRun == null) {
2545
+ subscriber.next(defaultValue);
2546
+ return;
2547
+ }
2548
+ const ff = (_a22 = textRun.ts) == null ? void 0 : _a22.ff;
2549
+ subscriber.next(ff != null ? ff : defaultValue);
2519
2550
  }
2520
2551
  });
2521
- return subscriber.next(defaultColor), disposable.dispose;
2552
+ return subscriber.next(defaultValue), disposable.dispose;
2522
2553
  }),
2523
2554
  disabled$: disableMenuWhenNoDocRange(accessor),
2524
2555
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2525
2556
  };
2526
2557
  }
2527
- __name(BackgroundColorSelectorMenuItemFactory, "BackgroundColorSelectorMenuItemFactory");
2528
- function getFontStyleAtCursor(accessor) {
2529
- var _a22;
2530
- const univerInstanceService = accessor.get(IUniverInstanceService), textSelectionService = accessor.get(TextSelectionManagerService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeTextRange = textSelectionService.getActiveTextRangeWithStyle();
2531
- if (docDataModel == null || activeTextRange == null)
2532
- return;
2533
- const { startOffset, segmentId } = activeTextRange, textRuns = (_a22 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a22.textRuns;
2534
- if (textRuns == null)
2535
- return;
2536
- let textRun;
2537
- for (let i = textRuns.length - 1; i >= 0; i--) {
2538
- const curTextRun = textRuns[i];
2539
- if (curTextRun.st <= startOffset && startOffset <= curTextRun.ed) {
2540
- textRun = curTextRun;
2541
- break;
2542
- }
2543
- }
2544
- return textRun;
2545
- }
2546
- __name(getFontStyleAtCursor, "getFontStyleAtCursor");
2547
- function getParagraphStyleAtCursor(accessor) {
2548
- var _a22;
2549
- const univerInstanceService = accessor.get(IUniverInstanceService), textSelectionService = accessor.get(TextSelectionManagerService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeTextRange = textSelectionService.getActiveTextRangeWithStyle();
2550
- if (docDataModel == null || activeTextRange == null)
2551
- return;
2552
- const { startOffset, segmentId } = activeTextRange, paragraphs = (_a22 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a22.paragraphs;
2553
- if (paragraphs == null)
2554
- return;
2555
- let prevIndex = -1;
2556
- for (const paragraph of paragraphs) {
2557
- const { startIndex } = paragraph;
2558
- if (startOffset > prevIndex && startOffset <= startIndex)
2559
- return paragraph;
2560
- prevIndex = startIndex;
2561
- }
2562
- return null;
2563
- }
2564
- __name(getParagraphStyleAtCursor, "getParagraphStyleAtCursor");
2565
- function whenDocOrEditor(contextService) {
2566
- return contextService.getContextValue(FOCUSING_DOC) || contextService.getContextValue(EDITOR_ACTIVATED);
2567
- }
2568
- __name(whenDocOrEditor, "whenDocOrEditor");
2569
- function whenFocusEditor(contextService) {
2570
- return contextService.getContextValue(EDITOR_ACTIVATED);
2571
- }
2572
- __name(whenFocusEditor, "whenFocusEditor");
2573
- const DOC_CLIPBOARD_PRIORITY = 999, DocCopyCommand = {
2574
- id: CopyCommand.id,
2575
- name: "doc.command.copy",
2576
- type: CommandType.COMMAND,
2577
- multi: !0,
2578
- priority: DOC_CLIPBOARD_PRIORITY,
2579
- preconditions: whenDocOrEditor,
2580
- handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(IDocClipboardService).copy(), "handler")
2581
- }, DocCutCommand = {
2582
- id: CutCommand.id,
2583
- name: "doc.command.cut",
2584
- type: CommandType.COMMAND,
2585
- multi: !0,
2586
- priority: DOC_CLIPBOARD_PRIORITY,
2587
- preconditions: whenDocOrEditor,
2588
- handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(IDocClipboardService).cut(), "handler")
2589
- }, DocPasteCommand = {
2590
- id: PasteCommand.id,
2591
- name: "doc.command.paste",
2592
- type: CommandType.COMMAND,
2593
- multi: !0,
2594
- priority: DOC_CLIPBOARD_PRIORITY,
2595
- preconditions: whenDocOrEditor,
2596
- handler: /* @__PURE__ */ __name(async (accessor) => {
2597
- const docClipboardService = accessor.get(IDocClipboardService), clipboardItems = await accessor.get(IClipboardInterfaceService).read();
2598
- return clipboardItems.length === 0 ? !1 : docClipboardService.paste(clipboardItems);
2599
- }, "handler")
2600
- }, DocParagraphSettingCommand = {
2601
- id: "doc-paragraph-setting.command",
2602
- type: CommandType.COMMAND,
2603
- handler: /* @__PURE__ */ __name(async (accessor, config) => {
2604
- var _a22, _b, _c;
2605
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), docDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), docRanges = textSelectionManagerService.getDocRanges();
2606
- if (!docDataModel || docRanges.length === 0 || !config)
2607
- return !1;
2608
- const segmentId = docRanges[0].segmentId, unitId = docDataModel.getUnitId(), allParagraphs = (_b = (_a22 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a22.paragraphs) != null ? _b : [], paragraphs = (_c = getParagraphsInRanges(docRanges, allParagraphs)) != null ? _c : [], serializedSelections = docRanges.map(serializeDocRange), doMutation = {
2609
- id: RichTextEditingMutation.id,
2610
- params: {
2611
- unitId,
2612
- actions: [],
2613
- textRanges: serializedSelections
2614
- }
2615
- }, memoryCursor = new MemoryCursor();
2616
- memoryCursor.reset();
2617
- const textX = new TextX(), jsonX = JSONX.getInstance();
2618
- for (const paragraph of paragraphs) {
2619
- const { startIndex } = paragraph;
2620
- textX.push({
2621
- t: TextXActionType.RETAIN,
2622
- len: startIndex - memoryCursor.cursor,
2623
- segmentId
2624
- });
2625
- const paragraphStyle = {
2626
- ...paragraph.paragraphStyle,
2627
- ...config
2628
- };
2629
- textX.push({
2630
- t: TextXActionType.RETAIN,
2631
- len: 1,
2632
- body: {
2633
- dataStream: "",
2634
- paragraphs: [
2635
- {
2636
- ...paragraph,
2637
- paragraphStyle,
2638
- startIndex: 0
2639
- }
2640
- ]
2641
- },
2642
- segmentId,
2643
- coverType: UpdateDocsAttributeType.REPLACE
2644
- }), memoryCursor.moveCursorTo(startIndex + 1);
2645
- }
2646
- const path = getRichTextEditPath(docDataModel, segmentId);
2647
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
2648
- }, "handler")
2649
- }, useCurrentParagraph = /* @__PURE__ */ __name(() => {
2650
- var _a22, _b, _c;
2651
- const textSelectionManagerService = useDependency(TextSelectionManagerService), docDataModel = useDependency(IUniverInstanceService).getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), docRanges = useMemo(() => textSelectionManagerService.getDocRanges(), []);
2652
- if (!docDataModel || docRanges.length === 0)
2653
- return [];
2654
- const segmentId = docRanges[0].segmentId, paragraphs = (_b = (_a22 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a22.paragraphs) != null ? _b : [];
2655
- return (_c = getParagraphsInRanges(docRanges, paragraphs)) != null ? _c : [];
2656
- }, "useCurrentParagraph"), useFirstParagraphHorizontalAlign = /* @__PURE__ */ __name((paragraph, defaultValue) => {
2657
- const commandService = useDependency(ICommandService), [horizontalAlign, _horizontalAlignSet] = useState(() => {
2658
- var _a22, _b;
2659
- const firstParagraph = paragraph[0];
2660
- return firstParagraph ? String((_b = (_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.horizontalAlign) != null ? _b : defaultValue) : defaultValue;
2661
- });
2662
- return [horizontalAlign, /* @__PURE__ */ __name((v) => (_horizontalAlignSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2663
- horizontalAlign: Number(v)
2664
- })), "horizontalAlignSet")];
2665
- }, "useFirstParagraphHorizontalAlign"), useFirstParagraphIndentStart = /* @__PURE__ */ __name((paragraph) => {
2666
- const commandService = useDependency(ICommandService), [indentStart, _indentStartSet] = useState(() => {
2667
- var _a22;
2668
- const firstParagraph = paragraph[0];
2669
- return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.indentStart, 0) : 0;
2670
- });
2671
- return [indentStart, /* @__PURE__ */ __name((v) => (_indentStartSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2672
- indentStart: { v }
2673
- })), "indentStartSet")];
2674
- }, "useFirstParagraphIndentStart"), useFirstParagraphIndentEnd = /* @__PURE__ */ __name((paragraph) => {
2675
- const commandService = useDependency(ICommandService), [indentEnd, _indentEndSet] = useState(() => {
2676
- var _a22;
2677
- const firstParagraph = paragraph[0];
2678
- return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.indentEnd, 0) : 0;
2679
- });
2680
- return [indentEnd, /* @__PURE__ */ __name((v) => (_indentEndSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2681
- indentEnd: { v }
2682
- })), "indentEndSet")];
2683
- }, "useFirstParagraphIndentEnd"), useFirstParagraphIndentFirstLine = /* @__PURE__ */ __name((paragraph) => {
2684
- const commandService = useDependency(ICommandService), [indentFirstLine, _indentFirstLineSet] = useState(() => {
2685
- var _a22;
2686
- const firstParagraph = paragraph[0];
2687
- return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.indentFirstLine, 0) : 0;
2688
- });
2689
- return [indentFirstLine, /* @__PURE__ */ __name((v) => (_indentFirstLineSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2690
- indentFirstLine: { v }
2691
- })), "indentFirstLineSet")];
2692
- }, "useFirstParagraphIndentFirstLine"), useFirstParagraphIndentHanging = /* @__PURE__ */ __name((paragraph) => {
2693
- const commandService = useDependency(ICommandService), [hanging, _hangingSet] = useState(() => {
2694
- var _a22;
2695
- const firstParagraph = paragraph[0];
2696
- return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.hanging, 0) : 0;
2697
- });
2698
- return [hanging, /* @__PURE__ */ __name((v) => (_hangingSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2699
- hanging: { v }
2700
- })), "hangingSet")];
2701
- }, "useFirstParagraphIndentHanging"), useFirstParagraphIndentSpaceAbove = /* @__PURE__ */ __name((paragraph) => {
2702
- const commandService = useDependency(ICommandService), [spaceAbove, _spaceAboveSet] = useState(() => {
2703
- var _a22;
2704
- const firstParagraph = paragraph[0];
2705
- return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.spaceAbove, 0) : 0;
2706
- });
2707
- return [spaceAbove, /* @__PURE__ */ __name((v) => (_spaceAboveSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2708
- spaceAbove: { v }
2709
- })), "spaceAboveSet")];
2710
- }, "useFirstParagraphIndentSpaceAbove"), useFirstParagraphSpaceBelow = /* @__PURE__ */ __name((paragraph) => {
2711
- const commandService = useDependency(ICommandService), [spaceBelow, _spaceBelowSet] = useState(() => {
2712
- var _a22;
2713
- const firstParagraph = paragraph[0];
2714
- return firstParagraph ? getNumberUnitValue((_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.spaceBelow, 0) : 0;
2715
- });
2716
- return [spaceBelow, /* @__PURE__ */ __name((v) => (_spaceBelowSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2717
- spaceBelow: { v }
2718
- })), "spaceBelowSet")];
2719
- }, "useFirstParagraphSpaceBelow"), useFirstParagraphLineSpacing = /* @__PURE__ */ __name((paragraph) => {
2720
- const commandService = useDependency(ICommandService), [lineSpacing, _lineSpacingSet] = useState(() => {
2721
- var _a22, _b;
2722
- const firstParagraph = paragraph[0];
2723
- return firstParagraph && (_b = (_a22 = firstParagraph.paragraphStyle) == null ? void 0 : _a22.lineSpacing) != null ? _b : 1;
2724
- });
2725
- return [lineSpacing, /* @__PURE__ */ __name((v) => (_lineSpacingSet(v), commandService.executeCommand(DocParagraphSettingCommand.id, {
2726
- lineSpacing: v
2727
- })), "lineSpacingSet")];
2728
- }, "useFirstParagraphLineSpacing"), paragraphSettingIconList = "univer-paragraph-setting-icon-list", paragraphSettingIconListItem = "univer-paragraph-setting-icon-list-item", paragraphSettingIconListActive = "univer-paragraph-setting-icon-list-active", paragraphSettingTitle = "univer-paragraph-setting-title", paragraphSettingLabel = "univer-paragraph-setting-label", paragraphSettingMtBase = "univer-paragraph-setting-mt-base", paragraphSettingFlexCol = "univer-paragraph-setting-flex-col", styles$1 = {
2729
- paragraphSettingIconList,
2730
- paragraphSettingIconListItem,
2731
- paragraphSettingIconListActive,
2732
- paragraphSettingTitle,
2733
- paragraphSettingLabel,
2734
- paragraphSettingMtBase,
2735
- paragraphSettingFlexCol
2736
- }, AutoFocusInputNumber = /* @__PURE__ */ __name((props) => {
2737
- const { value, onChange, className = "", min = 0, max = 100 } = props, ref = require$$0.useRef(null);
2738
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
2739
- InputNumber,
2740
- {
2741
- ref,
2742
- min,
2743
- max,
2744
- value,
2745
- onChange: /* @__PURE__ */ __name((v) => {
2746
- onChange(v != null ? v : 0).finally(() => {
2747
- setTimeout(() => {
2748
- var _a22;
2749
- (_a22 = ref.current) == null || _a22.focus();
2750
- }, 2);
2751
- });
2752
- }, "onChange"),
2753
- className
2754
- }
2755
- );
2756
- }, "AutoFocusInputNumber");
2757
- function ParagraphSetting() {
2758
- const localeService = useDependency(LocaleService), alignmentOptions = useMemo(
2759
- () => [
2760
- { label: localeService.t("toolbar.alignLeft"), value: String(HorizontalAlign.LEFT), icon: /* @__PURE__ */ jsxRuntimeExports.jsx(LeftJustifyingSingle, {}) },
2761
- { label: localeService.t("toolbar.alignCenter"), value: String(HorizontalAlign.CENTER), icon: /* @__PURE__ */ jsxRuntimeExports.jsx(HorizontallySingle, {}) },
2762
- { label: localeService.t("toolbar.alignRight"), value: String(HorizontalAlign.RIGHT), icon: /* @__PURE__ */ jsxRuntimeExports.jsx(RightJustifyingSingle, {}) },
2763
- { label: localeService.t("toolbar.alignJustify"), value: String(HorizontalAlign.JUSTIFIED), icon: /* @__PURE__ */ jsxRuntimeExports.jsx(AlignTextBothSingle, {}) }
2764
- ],
2765
- []
2766
- ), currentParagraph = useCurrentParagraph(), [horizontalAlignValue, horizontalAlignSet] = useFirstParagraphHorizontalAlign(currentParagraph, alignmentOptions[0].value), [indentStart, indentStartSet] = useFirstParagraphIndentStart(currentParagraph), [indentEnd, indentEndSet] = useFirstParagraphIndentEnd(currentParagraph), [indentFirstLine, indentFirstLineSet] = useFirstParagraphIndentFirstLine(currentParagraph), [hanging, hangingSet] = useFirstParagraphIndentHanging(currentParagraph), [spaceAbove, spaceAboveSet] = useFirstParagraphIndentSpaceAbove(currentParagraph), [spaceBelow, spaceBelowSet] = useFirstParagraphSpaceBelow(currentParagraph), [lineSpacing, lineSpacingSet] = useFirstParagraphLineSpacing(currentParagraph);
2767
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSetting, children: [
2768
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles$1.paragraphSettingTitle, children: localeService.t("doc.paragraphSetting.alignment") }),
2769
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `${styles$1.paragraphSettingIconList} ${styles$1.paragraphSettingMtBase}`, children: alignmentOptions.map((item) => /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { title: item.label, placement: "bottom", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
2770
- "span",
2558
+ __name(FontFamilySelectorMenuItemFactory, "FontFamilySelectorMenuItemFactory");
2559
+ function FontSizeSelectorMenuItemFactory(accessor) {
2560
+ const commandService = accessor.get(ICommandService);
2561
+ return {
2562
+ id: SetInlineFormatFontSizeCommand.id,
2563
+ type: MenuItemType.SELECTOR,
2564
+ tooltip: "toolbar.fontSize",
2565
+ label: {
2566
+ name: FONT_SIZE_COMPONENT,
2567
+ props: {
2568
+ min: 1,
2569
+ max: 400
2570
+ // disabled$,
2571
+ }
2572
+ },
2573
+ selections: FONT_SIZE_LIST,
2574
+ // disabled$,
2575
+ value$: new Observable((subscriber) => {
2576
+ const disposable = commandService.onCommandExecuted((c) => {
2577
+ var _a22;
2578
+ const id = c.id;
2579
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatFontSizeCommand.id) {
2580
+ const textRun = getFontStyleAtCursor(accessor);
2581
+ if (textRun == null) {
2582
+ subscriber.next(14);
2583
+ return;
2584
+ }
2585
+ const fs = (_a22 = textRun.ts) == null ? void 0 : _a22.fs;
2586
+ subscriber.next(fs != null ? fs : 14);
2587
+ }
2588
+ });
2589
+ return subscriber.next(14), disposable.dispose;
2590
+ }),
2591
+ disabled$: disableMenuWhenNoDocRange(accessor),
2592
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2593
+ };
2594
+ }
2595
+ __name(FontSizeSelectorMenuItemFactory, "FontSizeSelectorMenuItemFactory");
2596
+ function TextColorSelectorMenuItemFactory(accessor) {
2597
+ const commandService = accessor.get(ICommandService), themeService = accessor.get(ThemeService);
2598
+ return {
2599
+ id: SetInlineFormatTextColorCommand.id,
2600
+ icon: "FontColor",
2601
+ tooltip: "toolbar.textColor.main",
2602
+ type: MenuItemType.BUTTON_SELECTOR,
2603
+ selections: [
2771
2604
  {
2772
- className: clsx(
2773
- styles$1.paragraphSettingIconListItem,
2774
- { [styles$1.paragraphSettingIconListActive]: horizontalAlignValue === item.value }
2775
- ),
2776
- onClick: /* @__PURE__ */ __name(() => horizontalAlignSet(item.value), "onClick"),
2777
- children: item.icon
2605
+ label: {
2606
+ name: COLOR_PICKER_COMPONENT,
2607
+ hoverable: !1
2608
+ }
2778
2609
  }
2779
- ) }, item.value)) }),
2780
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles$1.paragraphSettingTitle, children: localeService.t("doc.paragraphSetting.indentation") }),
2781
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2782
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingFlexCol, children: [
2783
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingLabel, children: [
2784
- localeService.t("doc.paragraphSetting.left"),
2785
- "(px)"
2786
- ] }),
2787
- /* @__PURE__ */ jsxRuntimeExports.jsx(AutoFocusInputNumber, { className: styles$1.paragraphSettingMtBase, value: indentStart, onChange: /* @__PURE__ */ __name((v) => indentStartSet(v != null ? v : 0), "onChange") })
2788
- ] }),
2789
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingFlexCol, children: [
2790
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingLabel, children: [
2791
- localeService.t("doc.paragraphSetting.right"),
2792
- "(px)"
2793
- ] }),
2794
- /* @__PURE__ */ jsxRuntimeExports.jsx(AutoFocusInputNumber, { className: styles$1.paragraphSettingMtBase, value: indentEnd, onChange: /* @__PURE__ */ __name((v) => indentEndSet(v != null ? v : 0), "onChange") })
2795
- ] }),
2796
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingFlexCol, children: [
2797
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingLabel, children: [
2798
- localeService.t("doc.paragraphSetting.firstLine"),
2799
- "(px)"
2800
- ] }),
2801
- /* @__PURE__ */ jsxRuntimeExports.jsx(AutoFocusInputNumber, { className: styles$1.paragraphSettingMtBase, value: indentFirstLine, onChange: /* @__PURE__ */ __name((v) => indentFirstLineSet(v != null ? v : 0), "onChange") })
2802
- ] }),
2803
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingFlexCol, children: [
2804
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingLabel, children: [
2805
- localeService.t("doc.paragraphSetting.hanging"),
2806
- "(px)"
2807
- ] }),
2808
- /* @__PURE__ */ jsxRuntimeExports.jsx(AutoFocusInputNumber, { className: styles$1.paragraphSettingMtBase, value: hanging, onChange: /* @__PURE__ */ __name((v) => hangingSet(v != null ? v : 0), "onChange") })
2809
- ] })
2810
- ] }),
2811
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles$1.paragraphSettingTitle, children: localeService.t("doc.paragraphSetting.spacing") }),
2812
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2813
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingFlexCol, children: [
2814
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingLabel, children: [
2815
- localeService.t("doc.paragraphSetting.before"),
2816
- "(px)"
2817
- ] }),
2818
- /* @__PURE__ */ jsxRuntimeExports.jsx(AutoFocusInputNumber, { className: styles$1.paragraphSettingMtBase, value: spaceAbove, onChange: /* @__PURE__ */ __name((v) => spaceAboveSet(v != null ? v : 0), "onChange") })
2819
- ] }),
2820
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingFlexCol, children: [
2821
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingLabel, children: [
2822
- localeService.t("doc.paragraphSetting.after"),
2823
- "(px)"
2824
- ] }),
2825
- /* @__PURE__ */ jsxRuntimeExports.jsx(AutoFocusInputNumber, { className: styles$1.paragraphSettingMtBase, value: spaceBelow, onChange: /* @__PURE__ */ __name((v) => spaceBelowSet(v != null ? v : 0), "onChange") })
2826
- ] }),
2827
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.paragraphSettingFlexCol, children: [
2828
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles$1.paragraphSettingLabel, children: localeService.t("doc.paragraphSetting.lineSpace") }),
2829
- /* @__PURE__ */ jsxRuntimeExports.jsx(AutoFocusInputNumber, { min: 1, max: 5, className: styles$1.paragraphSettingMtBase, value: lineSpacing, onChange: /* @__PURE__ */ __name((v) => lineSpacingSet(v != null ? v : 0), "onChange") })
2830
- ] })
2831
- ] })
2832
- ] });
2610
+ ],
2611
+ value$: new Observable((subscriber) => {
2612
+ const defaultColor = themeService.getCurrentTheme().textColor, disposable = commandService.onCommandExecuted((c) => {
2613
+ if (c.id === SetInlineFormatTextColorCommand.id) {
2614
+ const color = c.params.value;
2615
+ subscriber.next(color != null ? color : defaultColor);
2616
+ }
2617
+ });
2618
+ return subscriber.next(defaultColor), disposable.dispose;
2619
+ }),
2620
+ disabled$: disableMenuWhenNoDocRange(accessor),
2621
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2622
+ // disabled$: getCurrentSheetDisabled$(accessor),
2623
+ };
2624
+ }
2625
+ __name(TextColorSelectorMenuItemFactory, "TextColorSelectorMenuItemFactory");
2626
+ function HeaderFooterMenuItemFactory(accessor) {
2627
+ return {
2628
+ id: OpenHeaderFooterPanelCommand.id,
2629
+ type: MenuItemType.BUTTON,
2630
+ icon: "FreezeRowSingle",
2631
+ tooltip: "toolbar.headerFooter",
2632
+ hidden$: combineLatest(getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC), getHeaderFooterMenuHiddenObservable(accessor), (one, two) => one || two)
2633
+ };
2634
+ }
2635
+ __name(HeaderFooterMenuItemFactory, "HeaderFooterMenuItemFactory");
2636
+ const TableIcon = "GridSingle", TABLE_MENU_ID = "doc.menu.table";
2637
+ function TableMenuFactory(accessor) {
2638
+ return {
2639
+ id: TABLE_MENU_ID,
2640
+ type: MenuItemType.SUBITEMS,
2641
+ icon: TableIcon,
2642
+ tooltip: "toolbar.table.main",
2643
+ disabled$: getTableDisabledObservable(accessor),
2644
+ // Do not show header footer menu and insert table at zen mode.
2645
+ hidden$: combineLatest(getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC), getInsertTableHiddenObservable(accessor), getHeaderFooterMenuHiddenObservable(accessor), (one, two, three) => one || two || three)
2646
+ };
2647
+ }
2648
+ __name(TableMenuFactory, "TableMenuFactory");
2649
+ function InsertTableMenuFactory(_accessor) {
2650
+ return {
2651
+ id: DocCreateTableOperation.id,
2652
+ title: "toolbar.table.insert",
2653
+ type: MenuItemType.BUTTON,
2654
+ hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_DOC)
2655
+ };
2656
+ }
2657
+ __name(InsertTableMenuFactory, "InsertTableMenuFactory");
2658
+ function AlignLeftMenuItemFactory(accessor) {
2659
+ const commandService = accessor.get(ICommandService);
2660
+ return {
2661
+ id: AlignLeftCommand.id,
2662
+ type: MenuItemType.BUTTON,
2663
+ icon: "LeftJustifyingSingle",
2664
+ tooltip: "toolbar.alignLeft",
2665
+ disabled$: disableMenuWhenNoDocRange(accessor),
2666
+ activated$: new Observable((subscriber) => {
2667
+ const disposable = commandService.onCommandExecuted((c) => {
2668
+ var _a22;
2669
+ const id = c.id;
2670
+ if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
2671
+ const paragraph = getParagraphStyleAtCursor(accessor);
2672
+ if (paragraph == null)
2673
+ return;
2674
+ const alignType = (_a22 = paragraph.paragraphStyle) == null ? void 0 : _a22.horizontalAlign;
2675
+ subscriber.next(alignType === HorizontalAlign.LEFT);
2676
+ }
2677
+ });
2678
+ return subscriber.next(!1), disposable.dispose;
2679
+ }),
2680
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2681
+ };
2682
+ }
2683
+ __name(AlignLeftMenuItemFactory, "AlignLeftMenuItemFactory");
2684
+ function AlignCenterMenuItemFactory(accessor) {
2685
+ const commandService = accessor.get(ICommandService);
2686
+ return {
2687
+ id: AlignCenterCommand.id,
2688
+ type: MenuItemType.BUTTON,
2689
+ icon: "HorizontallySingle",
2690
+ tooltip: "toolbar.alignCenter",
2691
+ activated$: new Observable((subscriber) => {
2692
+ const disposable = commandService.onCommandExecuted((c) => {
2693
+ var _a22;
2694
+ const id = c.id;
2695
+ if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
2696
+ const paragraph = getParagraphStyleAtCursor(accessor);
2697
+ if (paragraph == null)
2698
+ return;
2699
+ const alignType = (_a22 = paragraph.paragraphStyle) == null ? void 0 : _a22.horizontalAlign;
2700
+ subscriber.next(alignType === HorizontalAlign.CENTER);
2701
+ }
2702
+ });
2703
+ return subscriber.next(!1), disposable.dispose;
2704
+ }),
2705
+ disabled$: disableMenuWhenNoDocRange(accessor),
2706
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2707
+ };
2708
+ }
2709
+ __name(AlignCenterMenuItemFactory, "AlignCenterMenuItemFactory");
2710
+ function AlignRightMenuItemFactory(accessor) {
2711
+ const commandService = accessor.get(ICommandService);
2712
+ return {
2713
+ id: AlignRightCommand.id,
2714
+ type: MenuItemType.BUTTON,
2715
+ icon: "RightJustifyingSingle",
2716
+ tooltip: "toolbar.alignRight",
2717
+ activated$: new Observable((subscriber) => {
2718
+ const disposable = commandService.onCommandExecuted((c) => {
2719
+ var _a22;
2720
+ const id = c.id;
2721
+ if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
2722
+ const paragraph = getParagraphStyleAtCursor(accessor);
2723
+ if (paragraph == null)
2724
+ return;
2725
+ const alignType = (_a22 = paragraph.paragraphStyle) == null ? void 0 : _a22.horizontalAlign;
2726
+ subscriber.next(alignType === HorizontalAlign.RIGHT);
2727
+ }
2728
+ });
2729
+ return subscriber.next(!1), disposable.dispose;
2730
+ }),
2731
+ disabled$: disableMenuWhenNoDocRange(accessor),
2732
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2733
+ };
2734
+ }
2735
+ __name(AlignRightMenuItemFactory, "AlignRightMenuItemFactory");
2736
+ function AlignJustifyMenuItemFactory(accessor) {
2737
+ const commandService = accessor.get(ICommandService);
2738
+ return {
2739
+ id: AlignJustifyCommand.id,
2740
+ type: MenuItemType.BUTTON,
2741
+ icon: "AlignTextBothSingle",
2742
+ tooltip: "toolbar.alignJustify",
2743
+ activated$: new Observable((subscriber) => {
2744
+ const disposable = commandService.onCommandExecuted((c) => {
2745
+ var _a22;
2746
+ const id = c.id;
2747
+ if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
2748
+ const paragraph = getParagraphStyleAtCursor(accessor);
2749
+ if (paragraph == null)
2750
+ return;
2751
+ const alignType = (_a22 = paragraph.paragraphStyle) == null ? void 0 : _a22.horizontalAlign;
2752
+ subscriber.next(alignType === HorizontalAlign.JUSTIFIED);
2753
+ }
2754
+ });
2755
+ return subscriber.next(!1), disposable.dispose;
2756
+ }),
2757
+ disabled$: disableMenuWhenNoDocRange(accessor),
2758
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2759
+ };
2833
2760
  }
2834
- __name(ParagraphSetting, "ParagraphSetting");
2835
- const isRangesEqual = /* @__PURE__ */ __name((oldRanges, ranges) => ranges.length === oldRanges.length && oldRanges.some((oldRange) => ranges.some((range) => range.startOffset === oldRange.startOffset && range.endOffset === oldRange.endOffset)), "isRangesEqual"), isRangesIntersection = /* @__PURE__ */ __name((oldRanges, ranges) => oldRanges.some((oldRange) => ranges.some((range) => {
2836
- const { startOffset: activeStart, endOffset: activeEnd } = oldRange, { startOffset: compareStart, endOffset: compareEnd } = range;
2837
- return activeStart == null || activeEnd == null || compareStart == null || compareEnd == null ? !1 : activeStart <= compareEnd && activeEnd >= compareStart;
2838
- })), "isRangesIntersection");
2839
- function ParagraphSettingIndex() {
2840
- const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), currentLocale = useObservable(localeService.currentLocale$), [key, keySet] = useState(""), rangeRef = useRef([]);
2841
- return useEffect(() => {
2842
- const dispose = commandService.onCommandExecuted((info) => {
2843
- var _a22;
2844
- if (SetTextSelectionsOperation.id === info.id) {
2845
- const ranges = info.params.ranges;
2846
- isRangesEqual(ranges, rangeRef.current) || keySet(generateRandomId(4)), rangeRef.current = ranges;
2761
+ __name(AlignJustifyMenuItemFactory, "AlignJustifyMenuItemFactory");
2762
+ const listValueFactory$ = /* @__PURE__ */ __name((accessor) => new Observable((subscriber) => {
2763
+ const univerInstanceService = accessor.get(IUniverInstanceService), textSelectionManagerService = accessor.get(TextSelectionManagerService);
2764
+ let textSubscription;
2765
+ const subscription = univerInstanceService.focused$.subscribe((unitId) => {
2766
+ if (textSubscription == null || textSubscription.unsubscribe(), unitId == null)
2767
+ return;
2768
+ const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
2769
+ docDataModel != null && (textSubscription = textSelectionManagerService.textSelection$.subscribe(() => {
2770
+ var _a22, _b;
2771
+ const range = textSelectionManagerService.getActiveTextRangeWithStyle();
2772
+ if (range) {
2773
+ const doc = docDataModel.getSelfOrHeaderFooterModel(range == null ? void 0 : range.segmentId), paragraphs = getParagraphsInRange(range, (_b = (_a22 = doc.getBody()) == null ? void 0 : _a22.paragraphs) != null ? _b : []);
2774
+ let listType;
2775
+ if (paragraphs.every((p2) => {
2776
+ var _a23;
2777
+ return listType || (listType = (_a23 = p2.bullet) == null ? void 0 : _a23.listType), p2.bullet && p2.bullet.listType === listType;
2778
+ })) {
2779
+ subscriber.next(listType);
2780
+ return;
2781
+ }
2847
2782
  }
2848
- if (RichTextEditingMutation.id === info.id) {
2849
- const params = info.params, ranges = (_a22 = params.textRanges) != null ? _a22 : [];
2850
- params.trigger !== DocParagraphSettingCommand.id && isRangesIntersection(ranges, rangeRef.current) && keySet(generateRandomId(4));
2783
+ subscriber.next(void 0);
2784
+ }));
2785
+ });
2786
+ return () => {
2787
+ subscription.unsubscribe(), textSubscription == null || textSubscription.unsubscribe();
2788
+ };
2789
+ }), "listValueFactory$");
2790
+ function OrderListMenuItemFactory(accessor) {
2791
+ return {
2792
+ id: OrderListCommand.id,
2793
+ type: MenuItemType.BUTTON_SELECTOR,
2794
+ selections: [
2795
+ {
2796
+ label: {
2797
+ name: ORDER_LIST_TYPE_COMPONENT,
2798
+ hoverable: !1
2799
+ },
2800
+ value$: listValueFactory$(accessor)
2851
2801
  }
2852
- });
2853
- return () => dispose.dispose();
2854
- }, []), useEffect(() => {
2855
- keySet(generateRandomId(4));
2856
- }, [currentLocale]), /* @__PURE__ */ jsxRuntimeExports.jsx(ParagraphSetting, {}, key);
2802
+ ],
2803
+ icon: "OrderSingle",
2804
+ tooltip: "toolbar.order",
2805
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
2806
+ disabled$: disableMenuWhenNoDocRange(accessor),
2807
+ activated$: listValueFactory$(accessor).pipe(map$1((v) => v && v.indexOf("ORDER_LIST") === 0))
2808
+ };
2857
2809
  }
2858
- __name(ParagraphSettingIndex, "ParagraphSettingIndex");
2859
- var __defProp$f = Object.defineProperty, __getOwnPropDesc$f = Object.getOwnPropertyDescriptor, __decorateClass$f = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2860
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$f(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2861
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2862
- return kind && result && __defProp$f(target, key, result), result;
2863
- }, "__decorateClass$f"), __decorateParam$f = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$f");
2864
- const paragraphSettingIndexKey = "doc_ui_paragraph-setting-panel";
2865
- var _a6;
2866
- let DocParagraphSettingController = (_a6 = class extends Disposable {
2867
- constructor(_commandService, _componentManager, _sidebarService) {
2868
- super(), this._commandService = _commandService, this._componentManager = _componentManager, this._sidebarService = _sidebarService, this._init();
2869
- }
2870
- _init() {
2871
- this.disposeWithMe(this._componentManager.register(paragraphSettingIndexKey, ParagraphSettingIndex));
2810
+ __name(OrderListMenuItemFactory, "OrderListMenuItemFactory");
2811
+ function BulletListMenuItemFactory(accessor) {
2812
+ return {
2813
+ id: BulletListCommand.id,
2814
+ type: MenuItemType.BUTTON_SELECTOR,
2815
+ selections: [
2816
+ {
2817
+ label: {
2818
+ name: BULLET_LIST_TYPE_COMPONENT,
2819
+ hoverable: !1
2820
+ },
2821
+ value$: listValueFactory$(accessor)
2822
+ }
2823
+ ],
2824
+ icon: "UnorderSingle",
2825
+ tooltip: "toolbar.unorder",
2826
+ disabled$: disableMenuWhenNoDocRange(accessor),
2827
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
2828
+ activated$: listValueFactory$(accessor).pipe(map$1((v) => v && v.indexOf("BULLET_LIST") === 0))
2829
+ };
2830
+ }
2831
+ __name(BulletListMenuItemFactory, "BulletListMenuItemFactory");
2832
+ function CheckListMenuItemFactory(accessor) {
2833
+ return {
2834
+ id: CheckListCommand.id,
2835
+ type: MenuItemType.BUTTON,
2836
+ icon: "TodoList",
2837
+ tooltip: "toolbar.checklist",
2838
+ disabled$: disableMenuWhenNoDocRange(accessor),
2839
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
2840
+ activated$: listValueFactory$(accessor).pipe(map$1((v) => v && v.indexOf("CHECK_LIST") === 0))
2841
+ };
2842
+ }
2843
+ __name(CheckListMenuItemFactory, "CheckListMenuItemFactory");
2844
+ function ResetBackgroundColorMenuItemFactory(accessor) {
2845
+ return {
2846
+ id: ResetInlineFormatTextBackgroundColorCommand.id,
2847
+ type: MenuItemType.BUTTON,
2848
+ title: "toolbar.resetColor",
2849
+ icon: "NoColor"
2850
+ };
2851
+ }
2852
+ __name(ResetBackgroundColorMenuItemFactory, "ResetBackgroundColorMenuItemFactory");
2853
+ function BackgroundColorSelectorMenuItemFactory(accessor) {
2854
+ const commandService = accessor.get(ICommandService), themeService = accessor.get(ThemeService);
2855
+ return {
2856
+ id: SetInlineFormatTextBackgroundColorCommand.id,
2857
+ tooltip: "toolbar.fillColor.main",
2858
+ type: MenuItemType.BUTTON_SELECTOR,
2859
+ icon: "PaintBucket",
2860
+ selections: [
2861
+ {
2862
+ label: {
2863
+ name: COLOR_PICKER_COMPONENT,
2864
+ hoverable: !1
2865
+ }
2866
+ }
2867
+ ],
2868
+ value$: new Observable((subscriber) => {
2869
+ const defaultColor = themeService.getCurrentTheme().primaryColor, disposable = commandService.onCommandExecuted((c) => {
2870
+ if (c.id === SetInlineFormatTextBackgroundColorCommand.id) {
2871
+ const color = c.params.value;
2872
+ subscriber.next(color != null ? color : defaultColor);
2873
+ }
2874
+ });
2875
+ return subscriber.next(defaultColor), disposable.dispose;
2876
+ }),
2877
+ disabled$: disableMenuWhenNoDocRange(accessor),
2878
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2879
+ };
2880
+ }
2881
+ __name(BackgroundColorSelectorMenuItemFactory, "BackgroundColorSelectorMenuItemFactory");
2882
+ function getFontStyleAtCursor(accessor) {
2883
+ var _a22;
2884
+ const univerInstanceService = accessor.get(IUniverInstanceService), textSelectionService = accessor.get(TextSelectionManagerService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeTextRange = textSelectionService.getActiveTextRangeWithStyle();
2885
+ if (docDataModel == null || activeTextRange == null)
2886
+ return;
2887
+ const { startOffset, segmentId } = activeTextRange, textRuns = (_a22 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a22.textRuns;
2888
+ if (textRuns == null)
2889
+ return;
2890
+ let textRun;
2891
+ for (let i = textRuns.length - 1; i >= 0; i--) {
2892
+ const curTextRun = textRuns[i];
2893
+ if (curTextRun.st <= startOffset && startOffset <= curTextRun.ed) {
2894
+ textRun = curTextRun;
2895
+ break;
2896
+ }
2872
2897
  }
2873
- openPanel() {
2874
- const props = {
2875
- header: { title: "doc.slider.paragraphSetting" },
2876
- children: {
2877
- label: paragraphSettingIndexKey
2878
- },
2879
- width: 300
2880
- };
2881
- this._sidebarService.open(props);
2898
+ return textRun;
2899
+ }
2900
+ __name(getFontStyleAtCursor, "getFontStyleAtCursor");
2901
+ function getParagraphStyleAtCursor(accessor) {
2902
+ var _a22;
2903
+ const univerInstanceService = accessor.get(IUniverInstanceService), textSelectionService = accessor.get(TextSelectionManagerService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeTextRange = textSelectionService.getActiveTextRangeWithStyle();
2904
+ if (docDataModel == null || activeTextRange == null)
2905
+ return;
2906
+ const { startOffset, segmentId } = activeTextRange, paragraphs = (_a22 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a22.paragraphs;
2907
+ if (paragraphs == null)
2908
+ return;
2909
+ let prevIndex = -1;
2910
+ for (const paragraph of paragraphs) {
2911
+ const { startIndex } = paragraph;
2912
+ if (startOffset > prevIndex && startOffset <= startIndex)
2913
+ return paragraph;
2914
+ prevIndex = startIndex;
2882
2915
  }
2883
- }, __name(_a6, "DocParagraphSettingController"), _a6);
2884
- DocParagraphSettingController = __decorateClass$f([
2885
- OnLifecycle(LifecycleStages.Rendered, DocParagraphSettingController),
2886
- __decorateParam$f(0, ICommandService),
2887
- __decorateParam$f(1, Inject(ComponentManager)),
2888
- __decorateParam$f(2, Inject(ISidebarService))
2889
- ], DocParagraphSettingController);
2890
- const DocParagraphSettingPanelOperation = {
2891
- id: "sidebar.operation.doc-paragraph-setting-panel",
2892
- type: CommandType.OPERATION,
2893
- handler: /* @__PURE__ */ __name((accessor) => (accessor.get(DocParagraphSettingController).openPanel(), !0), "handler")
2894
- }, getDisableOnCollapsedObservable = /* @__PURE__ */ __name((accessor) => {
2916
+ return null;
2917
+ }
2918
+ __name(getParagraphStyleAtCursor, "getParagraphStyleAtCursor");
2919
+ const getDisableOnCollapsedObservable = /* @__PURE__ */ __name((accessor) => {
2895
2920
  const textSelectionManagerService = accessor.get(TextSelectionManagerService);
2896
2921
  return new Observable((subscriber) => {
2897
2922
  const observable = textSelectionManagerService.textSelection$.subscribe(() => {
@@ -2935,11 +2960,9 @@ const getDisableWhenSelectionNotInTableObservable = /* @__PURE__ */ __name((acce
2935
2960
  }, "getDisableWhenSelectionNotInTableObservable"), CopyMenuFactory = /* @__PURE__ */ __name((accessor) => ({
2936
2961
  id: DocCopyCommand.name,
2937
2962
  commandId: DocCopyCommand.id,
2938
- group: MenuGroup.CONTEXT_MENU_FORMAT,
2939
2963
  type: MenuItemType.BUTTON,
2940
2964
  icon: "Copy",
2941
2965
  title: "rightClick.copy",
2942
- positions: [MenuPosition.CONTEXT_MENU],
2943
2966
  disabled$: getDisableOnCollapsedObservable(accessor),
2944
2967
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2945
2968
  }), "CopyMenuFactory"), ParagraphSettingMenuFactory = /* @__PURE__ */ __name((accessor) => ({
@@ -2947,43 +2970,34 @@ const getDisableWhenSelectionNotInTableObservable = /* @__PURE__ */ __name((acce
2947
2970
  type: MenuItemType.BUTTON,
2948
2971
  icon: "MenuSingle24",
2949
2972
  title: "doc.menu.paragraphSetting",
2950
- positions: [MenuPosition.CONTEXT_MENU],
2951
2973
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2952
2974
  }), "ParagraphSettingMenuFactory"), CutMenuFactory = /* @__PURE__ */ __name((accessor) => ({
2953
2975
  id: DocCutCommand.id,
2954
- group: MenuGroup.CONTEXT_MENU_FORMAT,
2955
2976
  type: MenuItemType.BUTTON,
2956
2977
  icon: "Copy",
2957
2978
  title: "rightClick.cut",
2958
- positions: [MenuPosition.CONTEXT_MENU],
2959
2979
  disabled$: getDisableOnCollapsedObservable(accessor),
2960
2980
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2961
2981
  }), "CutMenuFactory"), PasteMenuFactory = /* @__PURE__ */ __name((accessor) => ({
2962
2982
  id: DocPasteCommand.id,
2963
- group: MenuGroup.CONTEXT_MENU_FORMAT,
2964
2983
  type: MenuItemType.BUTTON,
2965
2984
  icon: "PasteSpecial",
2966
2985
  title: "rightClick.paste",
2967
- positions: [MenuPosition.CONTEXT_MENU],
2968
2986
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2969
2987
  }), "PasteMenuFactory"), DeleteMenuFactory = /* @__PURE__ */ __name((accessor) => ({
2970
2988
  id: DeleteLeftCommand.id,
2971
- group: MenuGroup.CONTEXT_MENU_FORMAT,
2972
2989
  type: MenuItemType.BUTTON,
2973
2990
  icon: "PasteSpecial",
2974
2991
  title: "rightClick.delete",
2975
- positions: [MenuPosition.CONTEXT_MENU],
2976
2992
  disabled$: getDisableOnCollapsedObservable(accessor),
2977
2993
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
2978
2994
  }), "DeleteMenuFactory"), TABLE_INSERT_MENU_ID = "doc.menu.table-insert";
2979
2995
  function TableInsertMenuItemFactory(accessor) {
2980
2996
  return {
2981
2997
  id: TABLE_INSERT_MENU_ID,
2982
- group: MenuGroup.CONTEXT_MENU_LAYOUT,
2983
2998
  type: MenuItemType.SUBITEMS,
2984
2999
  title: "table.insert",
2985
3000
  icon: "Insert",
2986
- positions: [MenuPosition.CONTEXT_MENU],
2987
3001
  hidden$: combineLatest(getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC), getDisableWhenSelectionNotInTableObservable(accessor), (one, two) => one || two)
2988
3002
  };
2989
3003
  }
@@ -2994,7 +3008,6 @@ function InsertRowBeforeMenuItemFactory(accessor) {
2994
3008
  type: MenuItemType.BUTTON,
2995
3009
  title: "table.insertRowAbove",
2996
3010
  icon: "InsertRowAbove",
2997
- positions: [TABLE_INSERT_MENU_ID],
2998
3011
  disabled$: getDisableWhenSelectionNotInTableObservable(accessor),
2999
3012
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
3000
3013
  };
@@ -3004,7 +3017,6 @@ function InsertRowAfterMenuItemFactory(accessor) {
3004
3017
  return {
3005
3018
  id: DocTableInsertRowBellowCommand.id,
3006
3019
  type: MenuItemType.BUTTON,
3007
- positions: [TABLE_INSERT_MENU_ID],
3008
3020
  title: "table.insertRowBelow",
3009
3021
  icon: "InsertRowBelow",
3010
3022
  disabled$: getDisableWhenSelectionNotInTableObservable(accessor),
@@ -3018,7 +3030,6 @@ function InsertColumnLeftMenuItemFactory(accessor) {
3018
3030
  type: MenuItemType.BUTTON,
3019
3031
  title: "table.insertColumnLeft",
3020
3032
  icon: "LeftInsertColumn",
3021
- positions: [TABLE_INSERT_MENU_ID],
3022
3033
  disabled$: getDisableWhenSelectionNotInTableObservable(accessor),
3023
3034
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
3024
3035
  };
@@ -3028,7 +3039,6 @@ function InsertColumnRightMenuItemFactory(accessor) {
3028
3039
  return {
3029
3040
  id: DocTableInsertColumnRightCommand.id,
3030
3041
  type: MenuItemType.BUTTON,
3031
- positions: [TABLE_INSERT_MENU_ID],
3032
3042
  title: "table.insertColumnRight",
3033
3043
  icon: "RightInsertColumn",
3034
3044
  disabled$: getDisableWhenSelectionNotInTableObservable(accessor),
@@ -3040,11 +3050,9 @@ const TABLE_DELETE_MENU_ID = "doc.menu.table-delete";
3040
3050
  function TableDeleteMenuItemFactory(accessor) {
3041
3051
  return {
3042
3052
  id: TABLE_DELETE_MENU_ID,
3043
- group: MenuGroup.CONTEXT_MENU_LAYOUT,
3044
3053
  type: MenuItemType.SUBITEMS,
3045
3054
  title: "table.delete",
3046
3055
  icon: "Reduce",
3047
- positions: [MenuPosition.CONTEXT_MENU],
3048
3056
  hidden$: combineLatest(getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC), getDisableWhenSelectionNotInTableObservable(accessor), (one, two) => one || two)
3049
3057
  };
3050
3058
  }
@@ -3055,7 +3063,6 @@ function DeleteRowsMenuItemFactory(accessor) {
3055
3063
  type: MenuItemType.BUTTON,
3056
3064
  title: "table.deleteRows",
3057
3065
  icon: "DeleteRow",
3058
- positions: [TABLE_DELETE_MENU_ID],
3059
3066
  disabled$: getDisableWhenSelectionNotInTableObservable(accessor),
3060
3067
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
3061
3068
  };
@@ -3065,7 +3072,6 @@ function DeleteColumnsMenuItemFactory(accessor) {
3065
3072
  return {
3066
3073
  id: DocTableDeleteColumnsCommand.id,
3067
3074
  type: MenuItemType.BUTTON,
3068
- positions: [TABLE_DELETE_MENU_ID],
3069
3075
  title: "table.deleteColumns",
3070
3076
  icon: "DeleteColumn",
3071
3077
  disabled$: getDisableWhenSelectionNotInTableObservable(accessor),
@@ -3077,7 +3083,6 @@ function DeleteTableMenuItemFactory(accessor) {
3077
3083
  return {
3078
3084
  id: DocTableDeleteTableCommand.id,
3079
3085
  type: MenuItemType.BUTTON,
3080
- positions: [TABLE_DELETE_MENU_ID],
3081
3086
  title: "table.deleteTable",
3082
3087
  icon: "GridSingle",
3083
3088
  disabled$: getDisableWhenSelectionNotInTableObservable(accessor),
@@ -3085,14 +3090,166 @@ function DeleteTableMenuItemFactory(accessor) {
3085
3090
  };
3086
3091
  }
3087
3092
  __name(DeleteTableMenuItemFactory, "DeleteTableMenuItemFactory");
3093
+ const menuSchema = {
3094
+ [RibbonStartGroup.FORMAT]: {
3095
+ [SetInlineFormatBoldCommand.id]: {
3096
+ order: 0,
3097
+ menuItemFactory: BoldMenuItemFactory
3098
+ },
3099
+ [SetInlineFormatItalicCommand.id]: {
3100
+ order: 1,
3101
+ menuItemFactory: ItalicMenuItemFactory
3102
+ },
3103
+ [SetInlineFormatUnderlineCommand.id]: {
3104
+ order: 2,
3105
+ menuItemFactory: UnderlineMenuItemFactory
3106
+ },
3107
+ [SetInlineFormatStrikethroughCommand.id]: {
3108
+ order: 3,
3109
+ menuItemFactory: StrikeThroughMenuItemFactory
3110
+ },
3111
+ [SetInlineFormatSubscriptCommand.id]: {
3112
+ order: 4,
3113
+ menuItemFactory: SubscriptMenuItemFactory
3114
+ },
3115
+ [SetInlineFormatSuperscriptCommand.id]: {
3116
+ order: 5,
3117
+ menuItemFactory: SuperscriptMenuItemFactory
3118
+ },
3119
+ [SetInlineFormatFontSizeCommand.id]: {
3120
+ order: 6,
3121
+ menuItemFactory: FontSizeSelectorMenuItemFactory
3122
+ },
3123
+ [SetInlineFormatFontFamilyCommand.id]: {
3124
+ order: 7,
3125
+ menuItemFactory: FontFamilySelectorMenuItemFactory
3126
+ },
3127
+ [SetInlineFormatTextColorCommand.id]: {
3128
+ order: 8,
3129
+ menuItemFactory: TextColorSelectorMenuItemFactory
3130
+ },
3131
+ [SetInlineFormatTextBackgroundColorCommand.id]: {
3132
+ order: 9,
3133
+ menuItemFactory: BackgroundColorSelectorMenuItemFactory,
3134
+ [ResetInlineFormatTextBackgroundColorCommand.id]: {
3135
+ order: 0,
3136
+ menuItemFactory: ResetBackgroundColorMenuItemFactory
3137
+ }
3138
+ }
3139
+ },
3140
+ [RibbonStartGroup.LAYOUT]: {
3141
+ [TABLE_MENU_ID]: {
3142
+ order: 1,
3143
+ menuItemFactory: TableMenuFactory,
3144
+ [DocCreateTableOperation.id]: {
3145
+ order: 0,
3146
+ menuItemFactory: InsertTableMenuFactory
3147
+ }
3148
+ },
3149
+ [AlignLeftCommand.id]: {
3150
+ order: 2,
3151
+ menuItemFactory: AlignLeftMenuItemFactory
3152
+ },
3153
+ [AlignCenterCommand.id]: {
3154
+ order: 3,
3155
+ menuItemFactory: AlignCenterMenuItemFactory
3156
+ },
3157
+ [AlignRightCommand.id]: {
3158
+ order: 4,
3159
+ menuItemFactory: AlignRightMenuItemFactory
3160
+ },
3161
+ [AlignJustifyCommand.id]: {
3162
+ order: 5,
3163
+ menuItemFactory: AlignJustifyMenuItemFactory
3164
+ },
3165
+ [OrderListCommand.id]: {
3166
+ order: 6,
3167
+ menuItemFactory: OrderListMenuItemFactory
3168
+ },
3169
+ [BulletListCommand.id]: {
3170
+ order: 7,
3171
+ menuItemFactory: BulletListMenuItemFactory
3172
+ },
3173
+ [CheckListCommand.id]: {
3174
+ order: 8,
3175
+ menuItemFactory: CheckListMenuItemFactory
3176
+ },
3177
+ [OpenHeaderFooterPanelCommand.id]: {
3178
+ order: 9,
3179
+ menuItemFactory: HeaderFooterMenuItemFactory
3180
+ }
3181
+ },
3182
+ [ContextMenuPosition.MAIN_AREA]: {
3183
+ [ContextMenuGroup.FORMAT]: {
3184
+ [DocCopyCommand.name]: {
3185
+ order: 0,
3186
+ menuItemFactory: CopyMenuFactory
3187
+ },
3188
+ [DocCutCommand.id]: {
3189
+ order: 1,
3190
+ menuItemFactory: CutMenuFactory
3191
+ },
3192
+ [DocPasteCommand.id]: {
3193
+ order: 2,
3194
+ menuItemFactory: PasteMenuFactory
3195
+ },
3196
+ [DeleteLeftCommand.id]: {
3197
+ order: 3,
3198
+ menuItemFactory: DeleteMenuFactory
3199
+ }
3200
+ },
3201
+ [ContextMenuGroup.LAYOUT]: {
3202
+ [DocParagraphSettingPanelOperation.id]: {
3203
+ order: 0,
3204
+ menuItemFactory: ParagraphSettingMenuFactory
3205
+ },
3206
+ [TABLE_INSERT_MENU_ID]: {
3207
+ order: 1,
3208
+ menuItemFactory: TableInsertMenuItemFactory,
3209
+ [DocTableInsertRowAboveCommand.id]: {
3210
+ order: 1,
3211
+ menuItemFactory: InsertRowBeforeMenuItemFactory
3212
+ },
3213
+ [DocTableInsertRowBellowCommand.id]: {
3214
+ order: 2,
3215
+ menuItemFactory: InsertRowAfterMenuItemFactory
3216
+ },
3217
+ [DocTableInsertColumnLeftCommand.id]: {
3218
+ order: 3,
3219
+ menuItemFactory: InsertColumnLeftMenuItemFactory
3220
+ },
3221
+ [DocTableInsertColumnRightCommand.id]: {
3222
+ order: 4,
3223
+ menuItemFactory: InsertColumnRightMenuItemFactory
3224
+ }
3225
+ },
3226
+ [TABLE_DELETE_MENU_ID]: {
3227
+ order: 2,
3228
+ menuItemFactory: TableDeleteMenuItemFactory,
3229
+ [DocTableDeleteRowsCommand.id]: {
3230
+ order: 1,
3231
+ menuItemFactory: DeleteRowsMenuItemFactory
3232
+ },
3233
+ [DocTableDeleteColumnsCommand.id]: {
3234
+ order: 2,
3235
+ menuItemFactory: DeleteColumnsMenuItemFactory
3236
+ },
3237
+ [DocTableDeleteTableCommand.id]: {
3238
+ order: 3,
3239
+ menuItemFactory: DeleteTableMenuItemFactory
3240
+ }
3241
+ }
3242
+ }
3243
+ }
3244
+ };
3088
3245
  var __defProp$e = Object.defineProperty, __getOwnPropDesc$e = Object.getOwnPropertyDescriptor, __decorateClass$e = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3089
3246
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$e(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3090
3247
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3091
3248
  return kind && result && __defProp$e(target, key, result), result;
3092
3249
  }, "__decorateClass$e"), __decorateParam$e = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$e"), _a7;
3093
3250
  let DocUIController = (_a7 = class extends Disposable {
3094
- constructor(_config, _injector, _componentManager, _commandService, _layoutService, _menuService, _uiPartsService, _univerInstanceService, _shortcutService) {
3095
- super(), this._config = _config, this._injector = _injector, this._componentManager = _componentManager, this._commandService = _commandService, this._layoutService = _layoutService, this._menuService = _menuService, this._uiPartsService = _uiPartsService, this._univerInstanceService = _univerInstanceService, this._shortcutService = _shortcutService, this._init();
3251
+ constructor(_injector, _componentManager, _commandService, _layoutService, _menuManagerService, _uiPartsService, _univerInstanceService, _shortcutService, _configService) {
3252
+ super(), this._injector = _injector, this._componentManager = _componentManager, this._commandService = _commandService, this._layoutService = _layoutService, this._menuManagerService = _menuManagerService, this._uiPartsService = _uiPartsService, this._univerInstanceService = _univerInstanceService, this._shortcutService = _shortcutService, this._configService = _configService, this._init();
3096
3253
  }
3097
3254
  _initCustomComponents() {
3098
3255
  const componentManager = this._componentManager;
@@ -3100,56 +3257,11 @@ let DocUIController = (_a7 = class extends Disposable {
3100
3257
  }
3101
3258
  _initUiParts() {
3102
3259
  var _a22, _b;
3103
- const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
3104
- (_b = (_a22 = this._config.layout) == null ? void 0 : _a22.docContainerConfig) != null && _b.footer && !workbook && this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.FOOTER, () => connectInjector(DocFooter, this._injector)));
3260
+ const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), config = this._configService.getConfig(PLUGIN_CONFIG_KEY);
3261
+ (_b = (_a22 = config == null ? void 0 : config.layout) == null ? void 0 : _a22.docContainerConfig) != null && _b.footer && !workbook && this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.FOOTER, () => connectInjector(DocFooter, this._injector)));
3105
3262
  }
3106
3263
  _initMenus() {
3107
- const { menu = {} } = this._config;
3108
- [
3109
- BoldMenuItemFactory,
3110
- ItalicMenuItemFactory,
3111
- UnderlineMenuItemFactory,
3112
- StrikeThroughMenuItemFactory,
3113
- SubscriptMenuItemFactory,
3114
- SuperscriptMenuItemFactory,
3115
- FontSizeSelectorMenuItemFactory,
3116
- FontFamilySelectorMenuItemFactory,
3117
- TextColorSelectorMenuItemFactory,
3118
- HeaderFooterMenuItemFactory,
3119
- TableMenuFactory,
3120
- InsertTableMenuFactory,
3121
- AlignLeftMenuItemFactory,
3122
- AlignCenterMenuItemFactory,
3123
- AlignRightMenuItemFactory,
3124
- AlignJustifyMenuItemFactory,
3125
- OrderListMenuItemFactory,
3126
- BulletListMenuItemFactory,
3127
- CheckListMenuItemFactory,
3128
- ResetBackgroundColorMenuItemFactory,
3129
- BackgroundColorSelectorMenuItemFactory
3130
- ].forEach((factory) => {
3131
- this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), menu));
3132
- }), [
3133
- CopyMenuFactory,
3134
- CutMenuFactory,
3135
- PasteMenuFactory,
3136
- DeleteMenuFactory,
3137
- ParagraphSettingMenuFactory,
3138
- TableInsertMenuItemFactory,
3139
- InsertRowBeforeMenuItemFactory,
3140
- InsertRowAfterMenuItemFactory,
3141
- InsertColumnLeftMenuItemFactory,
3142
- InsertColumnRightMenuItemFactory,
3143
- TableDeleteMenuItemFactory,
3144
- DeleteRowsMenuItemFactory,
3145
- DeleteColumnsMenuItemFactory,
3146
- DeleteTableMenuItemFactory
3147
- ].forEach((factory) => {
3148
- try {
3149
- this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), menu));
3150
- } catch {
3151
- }
3152
- });
3264
+ this._menuManagerService.mergeMenu(menuSchema);
3153
3265
  }
3154
3266
  _initShortCut() {
3155
3267
  [
@@ -3190,14 +3302,15 @@ let DocUIController = (_a7 = class extends Disposable {
3190
3302
  }, __name(_a7, "DocUIController"), _a7);
3191
3303
  DocUIController = __decorateClass$e([
3192
3304
  OnLifecycle(LifecycleStages.Rendered, DocUIController),
3193
- __decorateParam$e(1, Inject(Injector)),
3194
- __decorateParam$e(2, Inject(ComponentManager)),
3195
- __decorateParam$e(3, ICommandService),
3196
- __decorateParam$e(4, ILayoutService),
3197
- __decorateParam$e(5, IMenuService),
3198
- __decorateParam$e(6, IUIPartsService),
3199
- __decorateParam$e(7, IUniverInstanceService),
3200
- __decorateParam$e(8, IShortcutService)
3305
+ __decorateParam$e(0, Inject(Injector)),
3306
+ __decorateParam$e(1, Inject(ComponentManager)),
3307
+ __decorateParam$e(2, ICommandService),
3308
+ __decorateParam$e(3, ILayoutService),
3309
+ __decorateParam$e(4, IMenuManagerService),
3310
+ __decorateParam$e(5, IUIPartsService),
3311
+ __decorateParam$e(6, IUniverInstanceService),
3312
+ __decorateParam$e(7, IShortcutService),
3313
+ __decorateParam$e(8, IConfigService)
3201
3314
  ], DocUIController);
3202
3315
  const BreakLineShortcut = {
3203
3316
  id: EnterCommand.id,
@@ -3431,7 +3544,7 @@ let DocRenderController = (_a10 = class extends RxDisposable {
3431
3544
  scrollNum *= e.deltaY > 0 ? -1 : 1, scene.scaleX < 1 && (scrollNum /= 2), scene.scaleX + scrollNum > 4 ? scene.scale(4, 4) : scene.scaleX + scrollNum < 0.1 ? scene.scale(0.1, 0.1) : e.preventDefault();
3432
3545
  } else
3433
3546
  viewMain.onMouseWheel(e, state);
3434
- }), this._configService.getConfig("hasScroll") !== !1 && new ScrollBar(viewMain), scene.addLayer(
3547
+ }), new ScrollBar(viewMain), scene.addLayer(
3435
3548
  new Layer(scene, [], DOCS_COMPONENT_MAIN_LAYER_INDEX),
3436
3549
  new Layer(scene, [], DOCS_COMPONENT_HEADER_LAYER_INDEX)
3437
3550
  ), this._addComponent(), engine.runRenderLoop(() => {
@@ -3798,13 +3911,10 @@ let DocCanvasPopManagerService = (_a13 = class extends Disposable {
3798
3911
  * @param popup popup item
3799
3912
  * @returns disposable
3800
3913
  */
3801
- attachPopupToObject(targetObject, popup) {
3802
- const unitId = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC).getUnitId(), currentRender = this._renderManagerService.getRenderById(unitId);
3914
+ attachPopupToObject(targetObject, popup, unitId) {
3915
+ const currentRender = this._renderManagerService.getRenderById(unitId);
3803
3916
  if (!currentRender)
3804
- return {
3805
- dispose: /* @__PURE__ */ __name(() => {
3806
- }, "dispose")
3807
- };
3917
+ throw new Error(`Current render not found, unitId: ${unitId}`);
3808
3918
  const { position, position$, disposable } = this._createObjectPositionObserver(targetObject, currentRender), id = this._globalPopupManagerService.addPopup({
3809
3919
  ...popup,
3810
3920
  unitId,
@@ -3819,22 +3929,28 @@ let DocCanvasPopManagerService = (_a13 = class extends Disposable {
3819
3929
  }, "dispose")
3820
3930
  };
3821
3931
  }
3822
- attachPopupToRange(range, popup) {
3823
- const unitId = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC).getUnitId(), { direction = "top" } = popup, currentRender = this._renderManagerService.getRenderById(unitId);
3932
+ /**
3933
+ * attach a popup to doc range
3934
+ * @param range doc range
3935
+ * @param popup popup item
3936
+ * @param unitId unit id
3937
+ * @returns disposable
3938
+ */
3939
+ attachPopupToRange(range, popup, unitId) {
3940
+ if (!this._univerInstanceService.getUnit(unitId))
3941
+ throw new Error(`Document not found, unitId: ${unitId}`);
3942
+ const { direction = "top", multipleDirection } = popup, currentRender = this._renderManagerService.getRenderById(unitId);
3824
3943
  if (!currentRender)
3825
- return {
3826
- dispose: /* @__PURE__ */ __name(() => {
3827
- }, "dispose")
3828
- };
3829
- const { positions: bounds, positions$: bounds$, disposable } = this._createRangePositionObserver(range, currentRender), position$ = bounds$.pipe(map((bounds2) => direction === "top" ? bounds2[0] : bounds2[bounds2.length - 1])), id = this._globalPopupManagerService.addPopup({
3944
+ throw new Error(`Current render not found, unitId: ${unitId}`);
3945
+ const { positions: bounds, positions$: bounds$, disposable } = this._createRangePositionObserver(range, currentRender), position$ = bounds$.pipe(map$1((bounds2) => direction.includes("top") ? bounds2[0] : bounds2[bounds2.length - 1])), id = this._globalPopupManagerService.addPopup({
3830
3946
  ...popup,
3831
3947
  unitId,
3832
3948
  subUnitId: "default",
3833
- anchorRect: direction === "top" ? bounds[0] : bounds[bounds.length - 1],
3949
+ anchorRect: direction.includes("top") ? bounds[0] : bounds[bounds.length - 1],
3834
3950
  anchorRect$: position$,
3835
3951
  excludeRects: bounds,
3836
3952
  excludeRects$: bounds$,
3837
- direction: direction === "top" ? "top" : "bottom",
3953
+ direction: direction.includes("top") || direction.includes("bottom") ? bounds.length > 1 ? multipleDirection : direction : "bottom",
3838
3954
  canvasElement: currentRender.engine.getCanvasElement()
3839
3955
  });
3840
3956
  return {
@@ -3898,7 +4014,7 @@ let DocContextMenuRenderController = (_a15 = class extends Disposable {
3898
4014
  _initPointerDown() {
3899
4015
  var _a22, _b;
3900
4016
  const documentsSubscription = ((_b = (_a22 = this._context) == null ? void 0 : _a22.mainComponent) == null ? void 0 : _b.onPointerDown$).subscribeEvent((event) => {
3901
- event.button === 2 && this._contextMenuService.triggerContextMenu(event, MenuPosition.CONTEXT_MENU);
4017
+ event.button === 2 && this._contextMenuService.triggerContextMenu(event, ContextMenuPosition.MAIN_AREA);
3902
4018
  });
3903
4019
  this.disposeWithMe(documentsSubscription);
3904
4020
  }
@@ -3930,7 +4046,7 @@ let DocResizeRenderController = (_a16 = class extends Disposable {
3930
4046
  _initResize() {
3931
4047
  this.disposeWithMe(
3932
4048
  fromEventSubject(this._context.engine.onTransformChange$).pipe(
3933
- filter((evt) => evt.type === TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize),
4049
+ filter$1((evt) => evt.type === TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize),
3934
4050
  throttleTime(0, animationFrameScheduler)
3935
4051
  ).subscribe(() => {
3936
4052
  this._docPageLayoutService.calculatePagePosition(), this._textSelectionManagerService.refreshSelection();
@@ -4023,14 +4139,14 @@ let DocEventManagerService = (_a17 = class extends Disposable {
4023
4139
  this._customRangeDirty = !0, this._bulletDirty = !0;
4024
4140
  })), this.disposeWithMe(
4025
4141
  fromEventSubject(this._context.engine.onTransformChange$).pipe(
4026
- filter((evt) => evt.type === TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize)
4142
+ filter$1((evt) => evt.type === TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize)
4027
4143
  ).subscribe(() => {
4028
4144
  this._customRangeDirty = !0, this._bulletDirty = !0;
4029
4145
  })
4030
4146
  );
4031
4147
  }
4032
4148
  _initEvents() {
4033
- this.disposeWithMe(fromEventSubject(this._context.scene.onPointerMove$).pipe(throttleTime(0, animationFrameScheduler)).subscribe((evt) => {
4149
+ this.disposeWithMe(fromEventSubject(this._context.scene.onPointerMove$).pipe(throttleTime(30)).subscribe((evt) => {
4034
4150
  this._hoverCustomRanges$.next(
4035
4151
  this._calcActiveRanges(evt)
4036
4152
  ), this._hoverBullet$.next(
@@ -4039,8 +4155,8 @@ let DocEventManagerService = (_a17 = class extends Disposable {
4039
4155
  }));
4040
4156
  const onPointerDown$ = fromEventSubject(this._context.mainComponent.onPointerDown$), onPointerUp$ = fromEventSubject(this._context.scene.onPointerUp$);
4041
4157
  this.disposeWithMe(onPointerDown$.pipe(
4042
- mergeMap((down) => onPointerUp$.pipe(take(1), map((up) => ({ down, up })))),
4043
- filter(({ down, up }) => down.target === up.target && up.timeStamp - down.timeStamp < 300)
4158
+ mergeMap((down) => onPointerUp$.pipe(take(1), map$1((up) => ({ down, up })))),
4159
+ filter$1(({ down, up }) => down.target === up.target && up.timeStamp - down.timeStamp < 300)
4044
4160
  // filter(({ down, up }) => down.offsetX === up.offsetX && down.offsetY === up.offsetY)
4045
4161
  ).subscribe(({ down }) => {
4046
4162
  if (down.button === 2)
@@ -4385,8 +4501,10 @@ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnProperty
4385
4501
  return kind && result && __defProp2(target, key, result), result;
4386
4502
  }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a21;
4387
4503
  let UniverDocsUIPlugin = (_a21 = class extends Plugin {
4388
- constructor(_config, _injector, _renderManagerSrv, _commandService, _logService) {
4389
- super(), this._config = _config, this._injector = _injector, this._renderManagerSrv = _renderManagerSrv, this._commandService = _commandService, this._logService = _logService, this._config = Tools.deepMerge({}, DefaultDocUiConfig, this._config), this._initDependencies(_injector), this._initializeShortcut(), this._initCommand();
4504
+ constructor(_config = defaultPluginConfig, _injector, _renderManagerSrv, _commandService, _logService, _configService) {
4505
+ super(), this._config = _config, this._injector = _injector, this._renderManagerSrv = _renderManagerSrv, this._commandService = _commandService, this._logService = _logService, this._configService = _configService;
4506
+ const { menu, ...rest } = this._config;
4507
+ menu && this._configService.setConfig("menu", menu, { merge: !0 }), this._configService.setConfig(PLUGIN_CONFIG_KEY, rest), this._initDependencies(_injector), this._initializeShortcut(), this._initCommand();
4390
4508
  }
4391
4509
  onReady() {
4392
4510
  this._initRenderBasics(), this._markDocAsFocused();
@@ -4422,13 +4540,13 @@ let UniverDocsUIPlugin = (_a21 = class extends Plugin {
4422
4540
  }
4423
4541
  _initDependencies(injector) {
4424
4542
  mergeOverrideWithDependencies([
4425
- [DocUIController, { useFactory: /* @__PURE__ */ __name(() => this._injector.createInstance(DocUIController, this._config), "useFactory") }],
4543
+ [DocUIController],
4426
4544
  [DocClipboardController],
4427
4545
  [DocEditorBridgeController],
4428
4546
  [DocAutoFormatController],
4429
4547
  [DocTableController],
4430
4548
  [DocsRenderService],
4431
- [AppUIController, { useFactory: /* @__PURE__ */ __name(() => this._injector.createInstance(AppUIController, this._config), "useFactory") }],
4549
+ [AppUIController],
4432
4550
  [IDocClipboardService, { useClass: DocClipboardService }],
4433
4551
  [DocCanvasPopManagerService],
4434
4552
  [DocParagraphSettingController]
@@ -4477,7 +4595,8 @@ UniverDocsUIPlugin = __decorateClass([
4477
4595
  __decorateParam(1, Inject(Injector)),
4478
4596
  __decorateParam(2, IRenderManagerService),
4479
4597
  __decorateParam(3, ICommandService),
4480
- __decorateParam(4, ILogService)
4598
+ __decorateParam(4, ILogService),
4599
+ __decorateParam(5, IConfigService)
4481
4600
  ], UniverDocsUIPlugin);
4482
4601
  function docDrawingPositionToTransform(position) {
4483
4602
  return {
@@ -4509,7 +4628,6 @@ __name(transformToDocDrawingPosition, "transformToDocDrawingPosition");
4509
4628
  export {
4510
4629
  DOC_UI_PLUGIN_NAME,
4511
4630
  DefaultDocContainerConfig,
4512
- DefaultDocUiConfig,
4513
4631
  DefaultToolbarConfig,
4514
4632
  DocBackScrollRenderController,
4515
4633
  DocCanvasPopManagerService,
@@ -4527,6 +4645,7 @@ export {
4527
4645
  PastePluginWord,
4528
4646
  UniverDocsUIPlugin,
4529
4647
  docDrawingPositionToTransform,
4648
+ menuSchema,
4530
4649
  transformToDocDrawingPosition,
4531
4650
  whenDocAndEditorFocused
4532
4651
  };