@univerjs/docs-ui 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -0
- package/lib/cjs/index.js +527 -106
- package/lib/cjs/locale/ar-SA.js +4 -0
- package/lib/cjs/locale/ca-ES.js +4 -0
- package/lib/cjs/locale/de-DE.js +4 -0
- package/lib/cjs/locale/en-US.js +4 -0
- package/lib/cjs/locale/es-ES.js +4 -0
- package/lib/cjs/locale/fa-IR.js +4 -0
- package/lib/cjs/locale/fr-FR.js +4 -0
- package/lib/cjs/locale/id-ID.js +4 -0
- package/lib/cjs/locale/it-IT.js +4 -0
- package/lib/cjs/locale/ja-JP.js +4 -0
- package/lib/cjs/locale/ko-KR.js +4 -0
- package/lib/cjs/locale/pl-PL.js +4 -0
- package/lib/cjs/locale/pt-BR.js +4 -0
- package/lib/cjs/locale/ru-RU.js +4 -0
- package/lib/cjs/locale/sk-SK.js +4 -0
- package/lib/cjs/locale/vi-VN.js +4 -0
- package/lib/cjs/locale/zh-CN.js +4 -0
- package/lib/cjs/locale/zh-HK.js +4 -0
- package/lib/cjs/locale/zh-TW.js +4 -0
- package/lib/es/index.js +529 -108
- package/lib/es/locale/ar-SA.js +4 -0
- package/lib/es/locale/ca-ES.js +4 -0
- package/lib/es/locale/de-DE.js +4 -0
- package/lib/es/locale/en-US.js +4 -0
- package/lib/es/locale/es-ES.js +4 -0
- package/lib/es/locale/fa-IR.js +4 -0
- package/lib/es/locale/fr-FR.js +4 -0
- package/lib/es/locale/id-ID.js +4 -0
- package/lib/es/locale/it-IT.js +4 -0
- package/lib/es/locale/ja-JP.js +4 -0
- package/lib/es/locale/ko-KR.js +4 -0
- package/lib/es/locale/pl-PL.js +4 -0
- package/lib/es/locale/pt-BR.js +4 -0
- package/lib/es/locale/ru-RU.js +4 -0
- package/lib/es/locale/sk-SK.js +4 -0
- package/lib/es/locale/vi-VN.js +4 -0
- package/lib/es/locale/zh-CN.js +4 -0
- package/lib/es/locale/zh-HK.js +4 -0
- package/lib/es/locale/zh-TW.js +4 -0
- package/lib/index.css +36 -78
- package/lib/index.js +529 -108
- package/lib/locale/ar-SA.js +4 -0
- package/lib/locale/ca-ES.js +4 -0
- package/lib/locale/de-DE.js +4 -0
- package/lib/locale/en-US.js +4 -0
- package/lib/locale/es-ES.js +4 -0
- package/lib/locale/fa-IR.js +4 -0
- package/lib/locale/fr-FR.js +4 -0
- package/lib/locale/id-ID.js +4 -0
- package/lib/locale/it-IT.js +4 -0
- package/lib/locale/ja-JP.js +4 -0
- package/lib/locale/ko-KR.js +4 -0
- package/lib/locale/pl-PL.js +4 -0
- package/lib/locale/pt-BR.js +4 -0
- package/lib/locale/ru-RU.js +4 -0
- package/lib/locale/sk-SK.js +4 -0
- package/lib/locale/vi-VN.js +4 -0
- package/lib/locale/zh-CN.js +4 -0
- package/lib/locale/zh-HK.js +4 -0
- package/lib/locale/zh-TW.js +4 -0
- package/lib/types/config/config.d.ts +5 -0
- package/lib/types/locale/en-US.d.ts +4 -0
- package/lib/types/plugin.d.ts +1 -1
- package/lib/types/services/clipboard/clipboard.service.d.ts +1 -1
- package/lib/types/services/doc-heading-collapse.service.d.ts +38 -0
- package/lib/types/services/doc-paragraph-menu.service.d.ts +1 -1
- package/lib/types/services/doc-popup-manager.service.d.ts +4 -1
- package/lib/types/views/ParagraphMenu.d.ts +2 -2
- package/lib/types/views/doc-side-menu-layout.d.ts +17 -0
- package/lib/types/views/heading-collapse-shape.d.ts +38 -0
- package/lib/types/views/paragraph-setting/hook/utils.d.ts +2 -0
- package/lib/umd/index.js +12 -12
- package/lib/umd/locale/ar-SA.js +1 -1
- package/lib/umd/locale/ca-ES.js +1 -1
- package/lib/umd/locale/de-DE.js +1 -1
- package/lib/umd/locale/en-US.js +1 -1
- package/lib/umd/locale/es-ES.js +1 -1
- package/lib/umd/locale/fa-IR.js +1 -1
- package/lib/umd/locale/fr-FR.js +1 -1
- package/lib/umd/locale/id-ID.js +1 -1
- package/lib/umd/locale/it-IT.js +1 -1
- package/lib/umd/locale/ja-JP.js +1 -1
- package/lib/umd/locale/ko-KR.js +1 -1
- package/lib/umd/locale/pl-PL.js +1 -1
- package/lib/umd/locale/pt-BR.js +1 -1
- package/lib/umd/locale/ru-RU.js +1 -1
- package/lib/umd/locale/sk-SK.js +1 -1
- package/lib/umd/locale/vi-VN.js +1 -1
- package/lib/umd/locale/zh-CN.js +1 -1
- package/lib/umd/locale/zh-HK.js +1 -1
- package/lib/umd/locale/zh-TW.js +1 -1
- package/package.json +12 -12
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaselineOffset, BlockType, BooleanNumber, BuildTextUtils, COLORS, ColorKit, ColumnSeparatorType, CommandType, CustomDecorationType, CustomRangeType, DEFAULT_DOCUMENT_PARAGRAPH_LINE_SPACING, DEFAULT_DOCUMENT_PARAGRAPH_SPACE_ABOVE, DEFAULT_DOCUMENT_PARAGRAPH_SPACE_BELOW, DEFAULT_EMPTY_DOCUMENT_VALUE, DEFAULT_STYLES, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOC_RANGE_TYPE, DashStyleType, DataStreamTreeNodeType, DataStreamTreeTokenType, DeleteDirection, DependentOn, Direction, Disposable, DisposableCollection, DocumentBlockRangeType, DocumentBlockType, DocumentFlavor, DrawingTypeEnum, EDITOR_ACTIVATED, ErrorService, FOCUSING_COMMENT_EDITOR, FOCUSING_COMMON_DRAWINGS, FOCUSING_DOC, FOCUSING_EDITOR_STANDALONE, FOCUSING_FX_BAR_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, FOCUSING_UNIVER_EDITOR, HorizontalAlign, ICommandService, IConfigService, IConfirmService, IContextService, ILogService, IPermissionService, IUndoRedoService, IUniverInstanceService, ImageSourceType, Inject, Injector, InterceptorManager, JSON1, JSONX, LOCALE_META, LRUMap, ListGlyphType, LocaleService, MODERN_DOCUMENT_DEFAULT_MARGIN, MODERN_DOCUMENT_WIDTH, MemoryCursor, ModernDocumentWidthMode, NAMED_STYLE_MAP, NamedStyleType, ObjectPermissionService, ObjectRelativeFromH, ObjectRelativeFromV, Optional, PAGE_SIZE, PAPER_TYPES, PRESERVE_INSERTED_PARAGRAPH_IDS, PRESET_LIST_TYPE, PageOrientType, Plugin, PositionedObjectLayoutType, PresetListType, QuickListTypeMap, RANGE_DIRECTION, Rectangle, RedoCommand, RegionService, RichTextBuilder, RxDisposable, SHEET_EDITOR_UNITS, SectionType, SliceBodyType, SpacingRule, TableAlignmentType, TableRowHeightRule, TableSizeType, TableTextWrapType, TextX, TextXActionType, ThemeService, Tools, UndoCommand, UniverInstanceType, UpdateDocsAttributeType, VerticalAlign, checkForSubstrings, cloneBodyWithFreshParagraphIds, containsInteriorInsertionOffset, createIdentifier, createInterceptorKey, createInternalEditorID, createParagraphId, createSectionId, debounce, fromEventSubject, generateRandomId, getBlockRangeInterval, getBodySlice, getBodySliceForTextXAction, getColorStyle, getCustomBlockIdsInSelections, getParagraphContentStartOffset, getParagraphContentStartOffsets, getPlainText, getRichTextEditPath, getSectionHeaderFooterReferenceKey, getTableRangeInterval, getTextRunSlice, isCommentEditorID, isInternalEditorID, isSafeUrl, merge, mergeOverrideWithDependencies, normalizeBody, remove, resolveDocumentParagraphStyle, resolveSectionHeaderFooterReference, resolveSectionHeaderFooterReferences, sequenceExecuteAsync, skipParseTagNames, toDisposable, touchDependencies, validateDocBodyStructure } from "@univerjs/core";
|
|
2
|
-
import { CreateHeaderFooterCommand, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocHistoryAction, DocInterceptorService, DocLayoutExecutorService, DocLayoutExecutorState, DocLayoutSessionStatus, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, HeaderFooterType, IDocStateChangeInterceptorService, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentPermissionCommand, SetSectionHeaderFooterLinkCommand, SetTextSelectionsOperation, UniverDocsPlugin, UpdateDocumentSectionCommand, UpdateTextCommand, buildDocTransform, canEditDocumentTargets, consumeContentInsertRange, createSectionColumnProperties, generateParagraphs, getDocumentEditTargetObjectIds, getDocumentParagraphPermissionObjectId, getDocumentPermissionValue, getDocumentSectionPermissionObjectId, getTopLevelSectionBreaks, isSheetLikeDocsCustomBlockChildType, resolveDocsCustomBlockSize, shouldUseInlineTextSelectionForDocsCustomBlockDrawing, transformDocumentTextRanges } from "@univerjs/docs";
|
|
2
|
+
import { CreateHeaderFooterCommand, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocHistoryAction, DocInterceptorService, DocLayoutExecutorService, DocLayoutExecutorState, DocLayoutSessionStatus, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, HeaderFooterType, IDocStateChangeInterceptorService, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentPermissionCommand, SetHeadingCollapsedCommand, SetSectionHeaderFooterLinkCommand, SetTextSelectionsOperation, UniverDocsPlugin, UpdateDocumentSectionCommand, UpdateTextCommand, buildDocTransform, canEditDocumentTargets, consumeContentInsertRange, createSectionColumnProperties, generateParagraphs, getDocumentEditTargetObjectIds, getDocumentParagraphPermissionObjectId, getDocumentPermissionValue, getDocumentSectionPermissionObjectId, getTopLevelSectionBreaks, isSheetLikeDocsCustomBlockChildType, resolveDocsCustomBlockSize, shouldUseInlineTextSelectionForDocsCustomBlockDrawing, transformDocumentTextRanges } from "@univerjs/docs";
|
|
3
3
|
import * as EngineRender from "@univerjs/engine-render";
|
|
4
|
-
import { BaseObject, CURSOR_TYPE, DRAWING_OBJECT_UPPER_LAYER_INDEX, DeviceInputEventType, DocBackground, DocumentEditArea, DocumentSkeletonPageType, Documents, GlyphType, IRenderManagerService, Layer, LineType, Liquid, NORMAL_TEXT_SELECTION_PLUGIN_STYLE, PageLayoutType, Path, RENDER_CLASS_TYPE, Rect, RegularPolygon, ScrollBar, ScrollTimer, Shape, TRANSFORM_CHANGE_OBSERVABLE_TYPE, UniverRenderEnginePlugin, Vector2, Viewport, compareDocumentSkeletonNestedPagePathOrder, documentSkeletonLineIterator, documentSkeletonTableIterator, getColor, getDocsTableRenderViewport, getDocsTableViewportLeft, getDocumentSkeletonColumnPagePathInfo, getDocumentSkeletonNestedPageOffset, getLastColumn, getNextWheelZoomRatio, getNumberUnitValue, getOffsetRectForDom, getPageFromPath, getParagraphByGlyph, getSystemHighlightColor, getTableIdAndSliceIndex, getTopmostDocsTableHit, hasListGlyph, isFirstGlyph, isIndentByGlyph, parseDataStreamToTree, pixelToPt, ptToPixel, pxToNum, registerDocumentLayoutPresentation } from "@univerjs/engine-render";
|
|
4
|
+
import { BaseObject, CURSOR_TYPE, DRAWING_OBJECT_UPPER_LAYER_INDEX, DeviceInputEventType, DocBackground, DocumentEditArea, DocumentSkeletonPageType, DocumentViewModel, Documents, GlyphType, IRenderManagerService, Layer, LineType, Liquid, NORMAL_TEXT_SELECTION_PLUGIN_STYLE, PageLayoutType, Path, RENDER_CLASS_TYPE, Rect, RegularPolygon, ScrollBar, ScrollTimer, Shape, TRANSFORM_CHANGE_OBSERVABLE_TYPE, UniverRenderEnginePlugin, Vector2, Viewport, compareDocumentSkeletonNestedPagePathOrder, documentSkeletonLineIterator, documentSkeletonTableIterator, getColor, getDocsTableRenderViewport, getDocsTableViewportLeft, getDocumentSkeletonColumnPagePathInfo, getDocumentSkeletonNestedPageOffset, getLastColumn, getNextWheelZoomRatio, getNumberUnitValue, getOffsetRectForDom, getPageFromPath, getParagraphByGlyph, getSystemHighlightColor, getTableIdAndSliceIndex, getTopmostDocsTableHit, hasListGlyph, isFirstGlyph, isIndentByGlyph, parseDataStreamToTree, pixelToPt, ptToPixel, pxToNum, registerDocumentLayoutPresentation } from "@univerjs/engine-render";
|
|
5
5
|
import { Button, Checkbox, Dialog, Dropdown, DropdownMenu, InputNumber, MessageType, MobileColorPicker, MobileDropdown, MobileSelect, Popup, Select, Separator, Tooltip, borderClassName, clsx, resetButtonClassName, scrollbarClassName, selectClassName, useMobileKeyboardViewportLayout } from "@univerjs/design";
|
|
6
6
|
import { BuiltInUIPart, COLOR_PICKER_COMPONENT, COMMON_LABEL_COMPONENT, ComponentManager, ContextMenuGroup, ContextMenuPanel, ContextMenuPosition, CopyCommand, CutCommand, EMOJI_PICKER_COMPONENT, FILE_PNG_CLIPBOARD_MIME_TYPE, FILE__BMP_CLIPBOARD_MIME_TYPE, FILE__JPEG_CLIPBOARD_MIME_TYPE, FILE__WEBP_CLIPBOARD_MIME_TYPE, FONT_FAMILY_COMPONENT, FONT_FAMILY_ITEM_COMPONENT, FONT_SIZE_COMPONENT, FONT_SIZE_LIST, FormatPainterSessionService, HEADING_ITEM_COMPONENT, HEADING_LIST, HTML_CLIPBOARD_MIME_TYPE, ICanvasPopupService, IClipboardInterfaceService, IContextMenuService, ILayoutService, IMenuManagerService, IMessageService, IRibbonService, IShortcutService, ISidebarService, IUIPartsService, IWorkbenchService, IconManager, KeyCode, MOBILE_UI_MODE, MenuItemType, MenuManagerPosition, MetaKeys, MobileDrawer, MobileKeyboardInsetContext, MobileMenu, MobileZoomIndicator, PLAIN_TEXT_CLIPBOARD_MIME_TYPE, PasteCommand, RectPopup, RibbonInsertGroup, RibbonStartGroup, RibbonViewGroup, SYMBOL_PICKER_COMPONENT, Slider, ToggleFullscreenOperation, ToolbarButton, ToolbarItem, UniverMobileUIPlugin, bindFormatPainterCanvas, connectInjector, getMenuHiddenObservable, getMobileCanvasPanDelta, imageMimeTypeSet, objectPermissionMenuItemFactory, openObjectPermissionDialog, openObjectPermissionPanel, preventBrowserZoomInContainers, useConfigValue, useDependency, useEvent, useInjector, useMobileCanvasPanel, useMobileCanvasViewport, useObservable } from "@univerjs/ui";
|
|
7
7
|
import { UnitAction, UnitObject } from "@univerjs/protocol";
|
|
@@ -493,15 +493,34 @@ const BreakLineCommand = {
|
|
|
493
493
|
const { horizontalLine, insertionMode = "split-paragraph" } = params ?? {};
|
|
494
494
|
const { segmentId } = activeTextRange;
|
|
495
495
|
const docDataModel = (params === null || params === void 0 ? void 0 : params.unitId) ? univerInstanceService.getUnit(params.unitId, UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
496
|
-
|
|
496
|
+
let originBody = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId ?? "")) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
|
|
497
497
|
if (docDataModel == null || originBody == null) return false;
|
|
498
498
|
const unitId = docDataModel.getUnitId();
|
|
499
499
|
const { startOffset, endOffset } = activeTextRange;
|
|
500
500
|
const paragraphs = originBody.paragraphs ?? [];
|
|
501
501
|
const isBareStructuralGap = isTopLevelStructuralGap(originBody.dataStream, startOffset) && originBody.dataStream[startOffset] !== DataStreamTreeTokenType.PARAGRAPH;
|
|
502
502
|
const insertsAtStructuralGap = insertionMode === "insert-gap" || isBareStructuralGap;
|
|
503
|
-
|
|
503
|
+
let prevParagraph = insertsAtStructuralGap ? void 0 : paragraphs.find((p) => p.startIndex >= startOffset);
|
|
504
504
|
if (!prevParagraph && !insertsAtStructuralGap) return false;
|
|
505
|
+
if (!segmentId && (prevParagraph === null || prevParagraph === void 0 ? void 0 : prevParagraph.headingCollapsed) && docDataModel.getSnapshot().documentStyle.documentFlavor === DocumentFlavor.MODERN) {
|
|
506
|
+
const paragraphId = prevParagraph.paragraphId;
|
|
507
|
+
const viewModel = new DocumentViewModel(docDataModel);
|
|
508
|
+
try {
|
|
509
|
+
if (viewModel.getHeadingSections().some((section) => section.paragraphId === paragraphId)) {
|
|
510
|
+
var _originBody$paragraph;
|
|
511
|
+
if (!commandService.syncExecuteCommand(SetHeadingCollapsedCommand.id, {
|
|
512
|
+
unitId,
|
|
513
|
+
paragraphId,
|
|
514
|
+
collapsed: false
|
|
515
|
+
})) return false;
|
|
516
|
+
originBody = docDataModel.getBody();
|
|
517
|
+
prevParagraph = originBody === null || originBody === void 0 || (_originBody$paragraph = originBody.paragraphs) === null || _originBody$paragraph === void 0 ? void 0 : _originBody$paragraph.find((paragraph) => paragraph.startIndex >= startOffset);
|
|
518
|
+
if (!originBody || !prevParagraph) return false;
|
|
519
|
+
}
|
|
520
|
+
} finally {
|
|
521
|
+
viewModel.dispose();
|
|
522
|
+
}
|
|
523
|
+
}
|
|
505
524
|
const isAtParagraphEnd = startOffset === (prevParagraph === null || prevParagraph === void 0 ? void 0 : prevParagraph.startIndex);
|
|
506
525
|
const prevParagraphIndex = prevParagraph === null || prevParagraph === void 0 ? void 0 : prevParagraph.startIndex;
|
|
507
526
|
const defaultTextStyle = docMenuStyleService.getDefaultStyle();
|
|
@@ -2839,7 +2858,7 @@ function getTextRangeFromCharIndex(startOffset, endOffset, scene, document, skel
|
|
|
2839
2858
|
function getRectRangeFromCharIndex(startOffset, endOffset, scene, document, skeleton, style, segmentId, segmentPage) {
|
|
2840
2859
|
const startNodePosition = skeleton.findNodePositionByCharIndex(startOffset, true, segmentId, segmentPage);
|
|
2841
2860
|
const endNodePosition = skeleton.findNodePositionByCharIndex(endOffset, true, segmentId, segmentPage);
|
|
2842
|
-
if (startNodePosition == null || endNodePosition == null) return;
|
|
2861
|
+
if (startNodePosition == null || endNodePosition == null || startNodePosition.path.indexOf("cells") === -1 || endNodePosition.path.indexOf("cells") === -1) return;
|
|
2843
2862
|
return new RectRange(scene, document, skeleton, startNodePosition, endNodePosition, style, segmentId, segmentPage);
|
|
2844
2863
|
}
|
|
2845
2864
|
function getRangeListFromCharIndex(startOffset, endOffset, scene, document, skeleton, style, segmentId, segmentPage) {
|
|
@@ -6233,6 +6252,14 @@ const DeleteLeftCommand = {
|
|
|
6233
6252
|
const { segmentId, style, segmentPage } = activeRange;
|
|
6234
6253
|
const body = (_docDataModel$getSelf3 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf3 === void 0 ? void 0 : _docDataModel$getSelf3.getBody();
|
|
6235
6254
|
if (body == null) return false;
|
|
6255
|
+
if (activeRange.collapsed && !segmentId) {
|
|
6256
|
+
const hidden = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getViewModel().getCollapsedHeadingAtOffset(activeRange.startOffset - 1);
|
|
6257
|
+
if (hidden) return commandService.executeCommand(SetHeadingCollapsedCommand.id, {
|
|
6258
|
+
unitId,
|
|
6259
|
+
paragraphId: hidden.paragraphId,
|
|
6260
|
+
collapsed: false
|
|
6261
|
+
});
|
|
6262
|
+
}
|
|
6236
6263
|
const originalLength = body.dataStream.length;
|
|
6237
6264
|
const typingStyle = captureDeletedTypingStyle(accessor, docDataModel, body, activeRange);
|
|
6238
6265
|
const actualRange = activeRange;
|
|
@@ -6391,6 +6418,14 @@ const DeleteRightCommand = {
|
|
|
6391
6418
|
const { segmentId, style, segmentPage } = activeRange;
|
|
6392
6419
|
const body = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf5 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf5 === void 0 ? void 0 : _docDataModel$getSelf5.getBody();
|
|
6393
6420
|
if (!docDataModel || !body) return false;
|
|
6421
|
+
if (activeRange.collapsed && !segmentId) {
|
|
6422
|
+
const hidden = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getViewModel().getCollapsedHeadingAtOffset(activeRange.startOffset + 1);
|
|
6423
|
+
if (hidden) return commandService.executeCommand(SetHeadingCollapsedCommand.id, {
|
|
6424
|
+
unitId: docDataModel.getUnitId(),
|
|
6425
|
+
paragraphId: hidden.paragraphId,
|
|
6426
|
+
collapsed: false
|
|
6427
|
+
});
|
|
6428
|
+
}
|
|
6394
6429
|
const actualRange = activeRange;
|
|
6395
6430
|
const { startOffset, endOffset, collapsed } = actualRange;
|
|
6396
6431
|
if (collapsed && shouldResetEmptyCenteredParagraphAlignment(accessor, docDataModel)) {
|
|
@@ -8752,13 +8787,21 @@ let DocClipboardService = class DocClipboardService extends Disposable {
|
|
|
8752
8787
|
this.dismissPasteOptions();
|
|
8753
8788
|
const unitId = payload.unitId ?? this._getCurrentDocumentUnitId();
|
|
8754
8789
|
if (!unitId || !this._canEditTargets(unitId)) return false;
|
|
8755
|
-
|
|
8790
|
+
const isCommentEditor = isCommentEditorID(unitId);
|
|
8791
|
+
if (!cachedSource && !payload.html && !payload.text && !payload.internalJson && (isCommentEditor || !payload.files.length)) return false;
|
|
8756
8792
|
const generation = this._pasteGeneration;
|
|
8757
|
-
const mode = unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY ? "text" : payload.mode ?? "source";
|
|
8793
|
+
const mode = isCommentEditor || unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY ? "text" : payload.mode ?? "source";
|
|
8758
8794
|
const style = this._getPasteStyle(unitId);
|
|
8759
|
-
const source = await this._preparePaste(payload, mode, cachedSource);
|
|
8795
|
+
const source = await (isCommentEditor && payload.text !== void 0 ? { body: { dataStream: payload.text } } : this._preparePaste(payload, mode, cachedSource));
|
|
8760
8796
|
if (generation !== this._pasteGeneration || !this._canEditTargets(unitId)) return false;
|
|
8761
|
-
let doc
|
|
8797
|
+
let doc;
|
|
8798
|
+
if (isCommentEditor) {
|
|
8799
|
+
const text = payload.text ?? getClipboardPlainText(source);
|
|
8800
|
+
if (!text) return false;
|
|
8801
|
+
const body = BuildTextUtils.transform.fromPlainText(text);
|
|
8802
|
+
delete body.customRanges;
|
|
8803
|
+
doc = { body };
|
|
8804
|
+
} else doc = applyDocPasteMode(source, mode, style, payload.text);
|
|
8762
8805
|
if (unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) {
|
|
8763
8806
|
doc = {
|
|
8764
8807
|
...source,
|
|
@@ -11722,7 +11765,6 @@ const DEFAULT_DOC_FIT_TO_WIDTH_OPTIONS = {
|
|
|
11722
11765
|
align: "center"
|
|
11723
11766
|
};
|
|
11724
11767
|
const defaultPluginConfig = {
|
|
11725
|
-
toc: false,
|
|
11726
11768
|
footer: true,
|
|
11727
11769
|
wordCount: true,
|
|
11728
11770
|
placeholder: true,
|
|
@@ -13653,9 +13695,13 @@ let DocRenderController = class DocRenderController extends RxDisposable {
|
|
|
13653
13695
|
const interactionAnchor = priorityAnchorBelongsToMutation ? options.anchor : options.priorityAnchor ?? options.anchor;
|
|
13654
13696
|
let interactionViewportAnchor = priorityAnchorBelongsToMutation ? null : this._captureViewportAnchor(skeleton, options.priorityAnchor, options.invalidation);
|
|
13655
13697
|
const foregroundEndOffset = this._resolveContinuousForegroundEndOffset(skeleton, options.invalidation);
|
|
13698
|
+
const viewport = this._context.scene.getViewport("viewMain");
|
|
13699
|
+
const docsComponent = this._context.mainComponent;
|
|
13700
|
+
const minimumPublicationHeight = this._context.unit.documentStyle.documentFlavor === DocumentFlavor.MODERN && viewport != null && docsComponent instanceof Documents ? Math.max(0, viewport.calcViewportInfo().viewBound.bottom - docsComponent.getOffsetConfig().docsTop) : void 0;
|
|
13656
13701
|
this._layoutCoordinator.schedule(skeleton, {
|
|
13657
13702
|
...options,
|
|
13658
13703
|
anchor: interactionAnchor,
|
|
13704
|
+
...minimumPublicationHeight != null && Number.isFinite(minimumPublicationHeight) && minimumPublicationHeight > 0 ? { minimumPublicationHeight } : {},
|
|
13659
13705
|
...foregroundEndOffset == null ? {} : { foregroundEndOffset },
|
|
13660
13706
|
preserveInteractionWindow: interactionAnchor != null && interactionAnchor !== options.anchor,
|
|
13661
13707
|
reuseUnaffectedTail: false
|
|
@@ -15015,7 +15061,8 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends Dispos
|
|
|
15015
15061
|
const updatePosition = () => {
|
|
15016
15062
|
try {
|
|
15017
15063
|
const newPosition = calc();
|
|
15018
|
-
|
|
15064
|
+
const previous = position$.value;
|
|
15065
|
+
if (newPosition && (newPosition.left !== previous.left || newPosition.right !== previous.right || newPosition.top !== previous.top || newPosition.bottom !== previous.bottom)) position$.next(newPosition);
|
|
15019
15066
|
} catch {}
|
|
15020
15067
|
};
|
|
15021
15068
|
disposable.add(this._commandService.onCommandExecuted((commandInfo) => {
|
|
@@ -15071,6 +15118,7 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends Dispos
|
|
|
15071
15118
|
disposable.add(currentRender.scene.onTransformChange$.subscribeEvent(() => {
|
|
15072
15119
|
updatePositions();
|
|
15073
15120
|
}));
|
|
15121
|
+
if (currentRender.mainComponent) disposable.add(currentRender.mainComponent.onTransformChange$.subscribeEvent(updatePositions));
|
|
15074
15122
|
return {
|
|
15075
15123
|
positions,
|
|
15076
15124
|
positions$,
|
|
@@ -15082,14 +15130,18 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends Dispos
|
|
|
15082
15130
|
if (!currentRender) throw new Error(`Current render not found, unitId: ${unitId}`);
|
|
15083
15131
|
const popupInjector = this._resolveEmbeddedPopupInjector(unitId, currentRender);
|
|
15084
15132
|
const popupManagerService = this._resolvePopupManagerService(popupInjector);
|
|
15085
|
-
const { position, position$, disposable } = this._createRectPositionObserver(rect, currentRender);
|
|
15133
|
+
const { position, position$, disposable, updatePosition } = this._createRectPositionObserver(rect, currentRender);
|
|
15134
|
+
if (popup.positionChanges$) disposable.add(popup.positionChanges$.subscribe(updatePosition));
|
|
15086
15135
|
const id = popupManagerService.addPopup({
|
|
15087
15136
|
...popup,
|
|
15088
15137
|
unitId,
|
|
15089
15138
|
subUnitId: "default",
|
|
15090
15139
|
connectorInjector: popupInjector,
|
|
15091
15140
|
anchorRect: position,
|
|
15092
|
-
anchorRect$: position
|
|
15141
|
+
anchorRect$: position$.pipe(throttleTime(0, animationFrameScheduler, {
|
|
15142
|
+
leading: true,
|
|
15143
|
+
trailing: true
|
|
15144
|
+
})),
|
|
15093
15145
|
canvasElement: currentRender.engine.getCanvasElement()
|
|
15094
15146
|
});
|
|
15095
15147
|
const popupActivity = popup.requiresStableLayout === false ? null : this._beginPopupActivity(unitId);
|
|
@@ -15121,7 +15173,10 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends Dispos
|
|
|
15121
15173
|
subUnitId: "default",
|
|
15122
15174
|
connectorInjector: popupInjector,
|
|
15123
15175
|
anchorRect: position,
|
|
15124
|
-
anchorRect$: position
|
|
15176
|
+
anchorRect$: position$.pipe(throttleTime(0, animationFrameScheduler, {
|
|
15177
|
+
leading: true,
|
|
15178
|
+
trailing: true
|
|
15179
|
+
})),
|
|
15125
15180
|
canvasElement: currentRender.engine.getCanvasElement()
|
|
15126
15181
|
});
|
|
15127
15182
|
const popupActivity = popup.requiresStableLayout === false ? null : this._beginPopupActivity(unitId);
|
|
@@ -15163,7 +15218,11 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends Dispos
|
|
|
15163
15218
|
}
|
|
15164
15219
|
return direction.includes("top") ? bounds[0] : bounds[bounds.length - 1];
|
|
15165
15220
|
};
|
|
15166
|
-
const
|
|
15221
|
+
const popupBounds$ = bounds$.pipe(throttleTime(0, animationFrameScheduler, {
|
|
15222
|
+
leading: true,
|
|
15223
|
+
trailing: true
|
|
15224
|
+
}));
|
|
15225
|
+
const position$ = popupBounds$.pipe(filter((bounds) => bounds.length > 0), map(getAnchor));
|
|
15167
15226
|
let id;
|
|
15168
15227
|
let popupActivity = null;
|
|
15169
15228
|
const removePopup = () => {
|
|
@@ -15188,7 +15247,7 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends Dispos
|
|
|
15188
15247
|
anchorRect: getAnchor(bounds),
|
|
15189
15248
|
anchorRect$: position$,
|
|
15190
15249
|
excludeRects: bounds,
|
|
15191
|
-
excludeRects$:
|
|
15250
|
+
excludeRects$: popupBounds$,
|
|
15192
15251
|
direction: [
|
|
15193
15252
|
"top",
|
|
15194
15253
|
"bottom",
|
|
@@ -15497,6 +15556,12 @@ let DocEventManagerService = class DocEventManagerService extends Disposable {
|
|
|
15497
15556
|
}));
|
|
15498
15557
|
}
|
|
15499
15558
|
_initResetDirty() {
|
|
15559
|
+
this.disposeWithMe(this._documents.onTransformChange$.subscribeEvent(() => {
|
|
15560
|
+
this._customRangeDirty = true;
|
|
15561
|
+
this._bulletDirty = true;
|
|
15562
|
+
this._paragraphDirty = true;
|
|
15563
|
+
this._tableBoundsDirty = true;
|
|
15564
|
+
}));
|
|
15500
15565
|
this.disposeWithMe(this._skeleton.dirty$.subscribe(() => {
|
|
15501
15566
|
this._customRangeDirty = true;
|
|
15502
15567
|
this._bulletDirty = true;
|
|
@@ -15988,6 +16053,9 @@ let DocEventManagerService = class DocEventManagerService extends Disposable {
|
|
|
15988
16053
|
return (_this$_tableCellBound2 = this._tableCellBounds.get(tableId)) === null || _this$_tableCellBound2 === void 0 ? void 0 : _this$_tableCellBound2.find((bound) => bound.rowIndex === rowIndex && bound.colIndex === colIndex && (pageIndex == null || bound.pageIndex === pageIndex));
|
|
15989
16054
|
}
|
|
15990
16055
|
findParagraphBoundByIndex(index) {
|
|
16056
|
+
this._buildParagraphBounds();
|
|
16057
|
+
const paragraph = this._paragraphBounds.get(index);
|
|
16058
|
+
if (paragraph) return paragraph;
|
|
15991
16059
|
this._buildTableBounds();
|
|
15992
16060
|
this._buildTableCellsForDocumentRange(index, index);
|
|
15993
16061
|
let tableParagraph = this._tableParagraphBoundsByIndex.get(index);
|
|
@@ -15999,9 +16067,6 @@ let DocEventManagerService = class DocEventManagerService extends Disposable {
|
|
|
15999
16067
|
if (tableParagraph) return tableParagraph;
|
|
16000
16068
|
}
|
|
16001
16069
|
if (tableParagraph) return tableParagraph;
|
|
16002
|
-
this._buildParagraphBounds();
|
|
16003
|
-
const paragraph = this._paragraphBounds.get(index);
|
|
16004
|
-
if (paragraph) return paragraph;
|
|
16005
16070
|
}
|
|
16006
16071
|
findParagraphBoundsInRange(startIndex, endIndex) {
|
|
16007
16072
|
this._buildTableBounds();
|
|
@@ -20717,10 +20782,30 @@ function DocFooter() {
|
|
|
20717
20782
|
return /* @__PURE__ */ jsx(DocFooterContent, {});
|
|
20718
20783
|
}
|
|
20719
20784
|
|
|
20785
|
+
//#endregion
|
|
20786
|
+
//#region src/views/doc-side-menu-layout.ts
|
|
20787
|
+
function isDocSideMenuTableOverlapping(outline, table, viewport) {
|
|
20788
|
+
if (table.bottom <= outline.top || table.top >= outline.bottom) return false;
|
|
20789
|
+
let left = table.left;
|
|
20790
|
+
let right = table.right;
|
|
20791
|
+
if (viewport && (viewport.leadingInsetLeft ?? 0) + viewport.contentWidth + (viewport.trailingInsetRight ?? 0) > viewport.viewportWidth) {
|
|
20792
|
+
const clipLeft = viewport.viewportLeft ?? table.left - (viewport.leadingInsetLeft ?? 0);
|
|
20793
|
+
left = Math.max(clipLeft, table.left - viewport.scrollLeft);
|
|
20794
|
+
right = Math.min(clipLeft + viewport.viewportWidth, table.left + viewport.contentWidth - viewport.scrollLeft);
|
|
20795
|
+
}
|
|
20796
|
+
return right > left && left < outline.right && right > outline.left;
|
|
20797
|
+
}
|
|
20798
|
+
|
|
20720
20799
|
//#endregion
|
|
20721
20800
|
//#region src/views/SideMenu.tsx
|
|
20722
20801
|
const SideMenu = forwardRef((props, ref) => {
|
|
20723
|
-
const { label, menus, onClick, className, style, mode, maxHeight, activeId, open, onOpenChange, maxWidth, wrapperClass, wrapperStyle, iconClass, iconStyle } = props;
|
|
20802
|
+
const { label, menus, onClick, className, style, mode = "side-bar", maxHeight, activeId, open: controlledOpen, onOpenChange, maxWidth, wrapperClass, wrapperStyle, iconClass, iconStyle } = props;
|
|
20803
|
+
const [expanded, setExpanded] = useState(mode === "side-bar");
|
|
20804
|
+
const open = controlledOpen ?? expanded;
|
|
20805
|
+
const handleOpenChange = useCallback((nextOpen) => {
|
|
20806
|
+
if (controlledOpen === void 0) setExpanded(nextOpen);
|
|
20807
|
+
onOpenChange === null || onOpenChange === void 0 || onOpenChange(nextOpen);
|
|
20808
|
+
}, [controlledOpen, onOpenChange]);
|
|
20724
20809
|
const panelId = useId();
|
|
20725
20810
|
const wrapperRef = useRef(null);
|
|
20726
20811
|
const containerRef = useRef(null);
|
|
@@ -20748,13 +20833,13 @@ const SideMenu = forwardRef((props, ref) => {
|
|
|
20748
20833
|
if (!open || mode !== "float") return;
|
|
20749
20834
|
const handlePointerDown = (event) => {
|
|
20750
20835
|
var _wrapperRef$current;
|
|
20751
|
-
if (event.target instanceof Node && !((_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : _wrapperRef$current.contains(event.target)))
|
|
20836
|
+
if (event.target instanceof Node && !((_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : _wrapperRef$current.contains(event.target))) handleOpenChange(false);
|
|
20752
20837
|
};
|
|
20753
20838
|
document.addEventListener("pointerdown", handlePointerDown);
|
|
20754
20839
|
return () => document.removeEventListener("pointerdown", handlePointerDown);
|
|
20755
20840
|
}, [
|
|
20841
|
+
handleOpenChange,
|
|
20756
20842
|
mode,
|
|
20757
|
-
onOpenChange,
|
|
20758
20843
|
open
|
|
20759
20844
|
]);
|
|
20760
20845
|
const handleKeyDown = (event) => {
|
|
@@ -20763,7 +20848,7 @@ const SideMenu = forwardRef((props, ref) => {
|
|
|
20763
20848
|
var _toggleRef$current;
|
|
20764
20849
|
event.preventDefault();
|
|
20765
20850
|
event.stopPropagation();
|
|
20766
|
-
|
|
20851
|
+
handleOpenChange(false);
|
|
20767
20852
|
(_toggleRef$current = toggleRef.current) === null || _toggleRef$current === void 0 || _toggleRef$current.focus();
|
|
20768
20853
|
return;
|
|
20769
20854
|
}
|
|
@@ -20792,51 +20877,47 @@ const SideMenu = forwardRef((props, ref) => {
|
|
|
20792
20877
|
};
|
|
20793
20878
|
return /* @__PURE__ */ jsxs("div", {
|
|
20794
20879
|
ref: wrapperRef,
|
|
20795
|
-
className: clsx("univer-relative univer-
|
|
20880
|
+
className: clsx("univer-relative univer-ms-4", wrapperClass),
|
|
20796
20881
|
style: {
|
|
20797
|
-
width,
|
|
20882
|
+
width: open ? width : 32,
|
|
20798
20883
|
...wrapperStyle
|
|
20799
20884
|
},
|
|
20800
20885
|
onKeyDown: handleKeyDown,
|
|
20801
|
-
children: [/* @__PURE__ */ jsx(
|
|
20886
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
20802
20887
|
ref: toggleRef,
|
|
20803
20888
|
type: "button",
|
|
20889
|
+
variant: "ghost",
|
|
20890
|
+
size: "icon",
|
|
20804
20891
|
"aria-label": label,
|
|
20805
20892
|
"aria-expanded": !!open,
|
|
20806
20893
|
"aria-controls": open ? panelId : void 0,
|
|
20807
20894
|
title: label,
|
|
20808
|
-
onClick: () =>
|
|
20809
|
-
className: clsx("univer-absolute univer-
|
|
20810
|
-
style:
|
|
20811
|
-
|
|
20812
|
-
|
|
20813
|
-
|
|
20814
|
-
|
|
20815
|
-
|
|
20895
|
+
onClick: () => handleOpenChange(!open),
|
|
20896
|
+
className: clsx("univer-absolute univer-start-0 univer-top-0 univer-z-10 !univer-text-gray-500 hover:!univer-text-gray-900 focus-visible:univer-outline focus-visible:univer-outline-2 focus-visible:univer-outline-primary-600 dark:!univer-text-gray-400 dark:hover:!univer-text-gray-100", iconClass),
|
|
20897
|
+
style: iconStyle,
|
|
20898
|
+
children: open ? /* @__PURE__ */ jsx(MoreLeftIcon, {
|
|
20899
|
+
"aria-hidden": "true",
|
|
20900
|
+
className: "!univer-size-6"
|
|
20901
|
+
}) : /* @__PURE__ */ jsx(CatalogueIcon, {
|
|
20902
|
+
"aria-hidden": "true",
|
|
20903
|
+
className: "!univer-size-5"
|
|
20904
|
+
})
|
|
20905
|
+
}), open && /* @__PURE__ */ jsx("nav", {
|
|
20816
20906
|
id: panelId,
|
|
20817
20907
|
"aria-label": label,
|
|
20818
|
-
className: clsx("univer-box-border univer-flex univer-w-full univer-flex-col univer-overflow-hidden univer-
|
|
20908
|
+
className: clsx("univer-box-border univer-flex univer-w-full univer-flex-col univer-overflow-hidden univer-pt-10", mode === "float" && "univer-bg-gray-0 dark:univer-bg-gray-900", className),
|
|
20819
20909
|
style: {
|
|
20820
20910
|
maxHeight,
|
|
20821
20911
|
...style
|
|
20822
20912
|
},
|
|
20823
|
-
children:
|
|
20824
|
-
className: "univer-flex univer-h-11 univer-shrink-0 univer-items-center univer-gap-2 univer-px-3 univer-pr-12 univer-text-xs univer-font-medium univer-text-gray-500 dark:univer-text-gray-400",
|
|
20825
|
-
children: [/* @__PURE__ */ jsx(CatalogueIcon, {
|
|
20826
|
-
"aria-hidden": "true",
|
|
20827
|
-
className: "univer-shrink-0 univer-text-sm"
|
|
20828
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
20829
|
-
className: "univer-truncate",
|
|
20830
|
-
children: label
|
|
20831
|
-
})]
|
|
20832
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
20913
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
20833
20914
|
ref: containerRef,
|
|
20834
|
-
className: clsx("univer-relative univer-min-h-0 univer-overflow-y-auto univer-overscroll-contain univer-
|
|
20915
|
+
className: clsx("univer-relative univer-min-h-0 univer-overflow-y-auto univer-overscroll-contain univer-pb-2", scrollbarClassName),
|
|
20835
20916
|
children: /* @__PURE__ */ jsx("ol", {
|
|
20836
20917
|
className: "univer-m-0 univer-list-none univer-p-0",
|
|
20837
20918
|
children: menus === null || menus === void 0 ? void 0 : menus.map((menu) => /* @__PURE__ */ jsx("li", {
|
|
20838
|
-
className: menu.isTitle ? "univer-mb-
|
|
20839
|
-
children: /* @__PURE__ */
|
|
20919
|
+
className: menu.isTitle ? "univer-mb-2" : void 0,
|
|
20920
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
20840
20921
|
ref: (element) => {
|
|
20841
20922
|
if (element) itemsRef.current.set(menu.id, element);
|
|
20842
20923
|
else itemsRef.current.delete(menu.id);
|
|
@@ -20844,39 +20925,28 @@ const SideMenu = forwardRef((props, ref) => {
|
|
|
20844
20925
|
type: "button",
|
|
20845
20926
|
"aria-current": menu.id === activeId ? "location" : void 0,
|
|
20846
20927
|
title: menu.text,
|
|
20847
|
-
className: clsx("univer-
|
|
20848
|
-
"univer-
|
|
20849
|
-
"univer-text-gray-900 dark:univer-text-gray-100": menu.isTitle && menu.id !== activeId,
|
|
20850
|
-
"univer-text-gray-
|
|
20928
|
+
className: clsx("univer-box-border univer-flex univer-min-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-border-0 univer-bg-transparent univer-py-1.5 univer-pe-2 univer-text-start univer-text-sm univer-leading-5 univer-transition-colors focus-visible:univer-outline focus-visible:univer-outline-2 focus-visible:-univer-outline-offset-2 focus-visible:univer-outline-primary-600", menu.isTitle ? "univer-font-medium" : "univer-font-normal", {
|
|
20929
|
+
"univer-text-primary-600 dark:univer-text-primary-400": menu.id === activeId,
|
|
20930
|
+
"univer-text-gray-600 hover:univer-text-gray-900 dark:univer-text-gray-300 dark:hover:univer-text-gray-100": menu.isTitle && menu.id !== activeId,
|
|
20931
|
+
"univer-text-gray-500 hover:univer-text-gray-900 dark:univer-text-gray-400 dark:hover:univer-text-gray-100": !menu.isTitle && menu.id !== activeId
|
|
20851
20932
|
}),
|
|
20852
|
-
style: {
|
|
20933
|
+
style: { paddingInlineStart: menu.isTitle ? 0 : 12 + Math.max(0, menu.level - 1) * 12 },
|
|
20853
20934
|
onClick: () => {
|
|
20854
20935
|
onClick === null || onClick === void 0 || onClick(menu);
|
|
20855
20936
|
if (mode === "float") {
|
|
20856
20937
|
var _toggleRef$current2;
|
|
20857
|
-
|
|
20938
|
+
handleOpenChange(false);
|
|
20858
20939
|
(_toggleRef$current2 = toggleRef.current) === null || _toggleRef$current2 === void 0 || _toggleRef$current2.focus();
|
|
20859
20940
|
}
|
|
20860
20941
|
},
|
|
20861
|
-
children:
|
|
20862
|
-
menu.
|
|
20863
|
-
|
|
20864
|
-
|
|
20865
|
-
style: { left: 14 + Math.max(0, menu.level - 2) * 12 }
|
|
20866
|
-
}),
|
|
20867
|
-
menu.id === activeId && /* @__PURE__ */ jsx("span", {
|
|
20868
|
-
"aria-hidden": "true",
|
|
20869
|
-
className: "univer-absolute univer-bottom-2 univer-left-0 univer-top-2 univer-w-0.5 univer-rounded-full univer-bg-primary-600 dark:univer-bg-primary-400"
|
|
20870
|
-
}),
|
|
20871
|
-
/* @__PURE__ */ jsx("span", {
|
|
20872
|
-
className: menu.isTitle ? "univer-line-clamp-2 univer-break-words" : "univer-truncate",
|
|
20873
|
-
children: menu.text
|
|
20874
|
-
})
|
|
20875
|
-
]
|
|
20942
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
20943
|
+
className: menu.isTitle ? "univer-line-clamp-2 univer-break-words" : "univer-truncate",
|
|
20944
|
+
children: menu.text
|
|
20945
|
+
})
|
|
20876
20946
|
})
|
|
20877
20947
|
}, menu.id))
|
|
20878
20948
|
})
|
|
20879
|
-
})
|
|
20949
|
+
})
|
|
20880
20950
|
})]
|
|
20881
20951
|
});
|
|
20882
20952
|
});
|
|
@@ -20898,52 +20968,77 @@ function findActiveHeading(boundMap, paragraphMap, scrollTop, bottom) {
|
|
|
20898
20968
|
if (!boundMap) return;
|
|
20899
20969
|
const paragraphBounds = Array.from(boundMap.values());
|
|
20900
20970
|
const paragraphIndex = paragraphBounds.findIndex((p) => p.paragraphStart !== p.paragraphEnd && p.rect.top < bottom && p.rect.bottom > scrollTop);
|
|
20901
|
-
if (paragraphIndex === -1) return
|
|
20902
|
-
|
|
20971
|
+
if (paragraphIndex === -1) return;
|
|
20972
|
+
let lastParagraphIndex = paragraphBounds.length - 1;
|
|
20973
|
+
while (lastParagraphIndex > paragraphIndex) {
|
|
20974
|
+
const bound = paragraphBounds[lastParagraphIndex];
|
|
20975
|
+
if (bound.paragraphStart !== bound.paragraphEnd && bound.rect.top < bottom && bound.rect.bottom > scrollTop) break;
|
|
20976
|
+
lastParagraphIndex--;
|
|
20977
|
+
}
|
|
20903
20978
|
for (let i = paragraphIndex; i <= lastParagraphIndex; i++) {
|
|
20904
|
-
var _paragraph$paragraphS;
|
|
20905
20979
|
const bound = paragraphBounds[i];
|
|
20906
20980
|
const paragraph = paragraphMap.get(bound.startIndex);
|
|
20907
|
-
if (paragraph
|
|
20981
|
+
if (paragraph) return paragraph.paragraphId;
|
|
20908
20982
|
}
|
|
20909
20983
|
for (let i = paragraphIndex; i >= 0; i--) {
|
|
20910
|
-
var _paragraph$paragraphS2;
|
|
20911
20984
|
const bound = paragraphBounds[i];
|
|
20912
20985
|
const paragraph = paragraphMap.get(bound.startIndex);
|
|
20913
|
-
if (paragraph
|
|
20986
|
+
if (paragraph) return paragraph.paragraphId;
|
|
20914
20987
|
}
|
|
20915
20988
|
}
|
|
20916
20989
|
const TITLE_ID = "__title";
|
|
20917
20990
|
function DocSideMenu() {
|
|
20918
20991
|
const config = useConfigValue(DOCS_UI_PLUGIN_CONFIG_KEY);
|
|
20919
20992
|
const workbenchService = useDependency(IWorkbenchService);
|
|
20920
|
-
if (useObservable(workbenchService.rootUnitType$, null, true) === UniverInstanceType.UNIVER_DOC && (config === null || config === void 0 ? void 0 : config.toc)) return /* @__PURE__ */ jsx(DocSideMenuContent, {});
|
|
20993
|
+
if (useObservable(workbenchService.rootUnitType$, null, true) === UniverInstanceType.UNIVER_DOC && (config === null || config === void 0 ? void 0 : config.toc) !== false) return /* @__PURE__ */ jsx(DocSideMenuContent, { toc: config === null || config === void 0 ? void 0 : config.toc });
|
|
20921
20994
|
return null;
|
|
20922
20995
|
}
|
|
20923
|
-
function DocSideMenuContent() {
|
|
20924
|
-
var _documentData$body, _documentData$body3;
|
|
20996
|
+
function DocSideMenuContent({ toc }) {
|
|
20997
|
+
var _currentDoc$getSnapsh, _documentData$body, _documentData$body3, _menus$find;
|
|
20925
20998
|
const instanceService = useDependency(IUniverInstanceService);
|
|
20926
20999
|
const localeService = useDependency(LocaleService);
|
|
20927
21000
|
const currentDoc = useObservable(() => instanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC), void 0, false, [instanceService]);
|
|
21001
|
+
const enabled = toc ?? (currentDoc === null || currentDoc === void 0 || (_currentDoc$getSnapsh = currentDoc.getSnapshot().documentStyle) === null || _currentDoc$getSnapsh === void 0 ? void 0 : _currentDoc$getSnapsh.documentFlavor) === DocumentFlavor.MODERN;
|
|
20928
21002
|
const renderManagerService = useDependency(IRenderManagerService);
|
|
20929
21003
|
const documentData = useObservable(currentDoc ? () => currentDoc.change$.pipe(debounceTime(100), map(() => currentDoc.getSnapshot())) : null, currentDoc === null || currentDoc === void 0 ? void 0 : currentDoc.getSnapshot(), false, [currentDoc]);
|
|
20930
21004
|
const fullDataStream = (documentData === null || documentData === void 0 || (_documentData$body = documentData.body) === null || _documentData$body === void 0 ? void 0 : _documentData$body.dataStream) ?? "";
|
|
20931
21005
|
const [activeId, setActiveId] = useState(void 0);
|
|
21006
|
+
const [outlineHeight, setOutlineHeight] = useState(0);
|
|
21007
|
+
const containerRef = useRef(null);
|
|
20932
21008
|
const unitId = (currentDoc === null || currentDoc === void 0 ? void 0 : currentDoc.getUnitId()) ?? "";
|
|
20933
21009
|
const renderer = renderManagerService.getRenderUnitById(unitId);
|
|
20934
21010
|
const title = documentData === null || documentData === void 0 ? void 0 : documentData.title;
|
|
20935
21011
|
const docEventManagerService = renderer === null || renderer === void 0 ? void 0 : renderer.with(DocEventManagerService);
|
|
20936
|
-
const
|
|
21012
|
+
const viewport = renderer === null || renderer === void 0 ? void 0 : renderer.scene.getViewport("viewMain");
|
|
20937
21013
|
const readLayout = () => {
|
|
20938
21014
|
var _renderer$mainCompone;
|
|
21015
|
+
const scaleX = (renderer === null || renderer === void 0 ? void 0 : renderer.scene.scaleX) ?? 1;
|
|
21016
|
+
const scaleY = (renderer === null || renderer === void 0 ? void 0 : renderer.scene.scaleY) ?? 1;
|
|
21017
|
+
const scrollX = (viewport === null || viewport === void 0 ? void 0 : viewport.viewportScrollX) ?? 0;
|
|
21018
|
+
const scrollY = (viewport === null || viewport === void 0 ? void 0 : viewport.viewportScrollY) ?? 0;
|
|
21019
|
+
const canvasHeight = (renderer === null || renderer === void 0 ? void 0 : renderer.engine.height) ?? 0;
|
|
21020
|
+
const left = (((renderer === null || renderer === void 0 || (_renderer$mainCompone = renderer.mainComponent) === null || _renderer$mainCompone === void 0 ? void 0 : _renderer$mainCompone.left) ?? 0) - scrollX) * scaleX;
|
|
21021
|
+
const outlineRect = {
|
|
21022
|
+
left: scrollX + 16 / scaleX,
|
|
21023
|
+
right: scrollX + 272 / scaleX,
|
|
21024
|
+
top: scrollY + 16 / scaleY,
|
|
21025
|
+
bottom: scrollY + Math.min(canvasHeight - 16, 16 + outlineHeight) / scaleY
|
|
21026
|
+
};
|
|
21027
|
+
const overlapsTable = left >= 288 && outlineHeight > 0 && Array.from((docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.tableBounds.values()) ?? []).some(({ tableId, rect }) => isDocSideMenuTableOverlapping(outlineRect, rect, getDocsTableRenderViewport(unitId, getTableIdAndSliceIndex(tableId).tableId)));
|
|
20939
21028
|
return {
|
|
20940
|
-
left
|
|
20941
|
-
canvasHeight
|
|
21029
|
+
left,
|
|
21030
|
+
canvasHeight,
|
|
20942
21031
|
canvasWidth: (renderer === null || renderer === void 0 ? void 0 : renderer.engine.width) ?? 0,
|
|
20943
|
-
scaleY
|
|
21032
|
+
scaleY,
|
|
21033
|
+
overlapsTable
|
|
20944
21034
|
};
|
|
20945
21035
|
};
|
|
20946
|
-
const
|
|
21036
|
+
const layout = useObservable((renderer === null || renderer === void 0 ? void 0 : renderer.engine.onTransformChange$) ? () => merge$1(fromEventSubject(renderer.engine.onTransformChange$), fromEventSubject(renderer.scene.onTransformChange$), ...renderer.mainComponent instanceof Documents ? [renderer.mainComponent.pageRender$] : [], ...viewport ? [fromEventSubject(viewport.onScrollAfter$)] : [], ...renderer.mainComponent ? [fromEventSubject(renderer.mainComponent.onTransformChange$)] : []).pipe(auditTime(33), map(readLayout), startWith(readLayout()), distinctUntilChanged((previous, current) => previous.left === current.left && previous.canvasHeight === current.canvasHeight && previous.canvasWidth === current.canvasWidth && previous.scaleY === current.scaleY && previous.overlapsTable === current.overlapsTable)) : null, readLayout(), false, [
|
|
21037
|
+
renderer,
|
|
21038
|
+
viewport,
|
|
21039
|
+
outlineHeight
|
|
21040
|
+
]);
|
|
21041
|
+
const { left, canvasHeight, canvasWidth, scaleY } = layout;
|
|
20947
21042
|
const paragraphs = useMemo(() => {
|
|
20948
21043
|
var _documentData$body2;
|
|
20949
21044
|
return (documentData === null || documentData === void 0 || (_documentData$body2 = documentData.body) === null || _documentData$body2 === void 0 ? void 0 : _documentData$body2.paragraphs) ?? [];
|
|
@@ -20952,22 +21047,26 @@ function DocSideMenuContent() {
|
|
|
20952
21047
|
dataStream: fullDataStream,
|
|
20953
21048
|
paragraphs
|
|
20954
21049
|
}), [fullDataStream, paragraphs]);
|
|
21050
|
+
const headingParagraphs = useMemo(() => paragraphs.filter((p) => {
|
|
21051
|
+
var _p$paragraphStyle;
|
|
21052
|
+
return ((_p$paragraphStyle = p.paragraphStyle) === null || _p$paragraphStyle === void 0 ? void 0 : _p$paragraphStyle.namedStyleType) !== void 0 && p.paragraphStyle.namedStyleType !== NamedStyleType.SUBTITLE && p.paragraphStyle.namedStyleType !== NamedStyleType.NORMAL_TEXT;
|
|
21053
|
+
}).map((p) => p.paragraphId ? p : {
|
|
21054
|
+
...p,
|
|
21055
|
+
paragraphId: `__paragraph_${p.startIndex}`
|
|
21056
|
+
}), [paragraphs]);
|
|
20955
21057
|
const paragraphMap = useMemo(() => {
|
|
20956
21058
|
const map = /* @__PURE__ */ new Map();
|
|
20957
|
-
|
|
21059
|
+
headingParagraphs.forEach((p) => {
|
|
20958
21060
|
map.set(p.startIndex, p);
|
|
20959
21061
|
});
|
|
20960
21062
|
return map;
|
|
20961
|
-
}, [
|
|
20962
|
-
const mode = left <
|
|
20963
|
-
const paragraphMenus =
|
|
20964
|
-
var _p$paragraphStyle;
|
|
20965
|
-
return ((_p$paragraphStyle = p.paragraphStyle) === null || _p$paragraphStyle === void 0 ? void 0 : _p$paragraphStyle.namedStyleType) !== void 0 && p.paragraphStyle.namedStyleType !== NamedStyleType.SUBTITLE && p.paragraphStyle.namedStyleType !== NamedStyleType.NORMAL_TEXT;
|
|
20966
|
-
}).map((p) => {
|
|
21063
|
+
}, [headingParagraphs]);
|
|
21064
|
+
const mode = left < 288 || layout.overlapsTable ? "float" : "side-bar";
|
|
21065
|
+
const paragraphMenus = headingParagraphs.map((p) => {
|
|
20967
21066
|
var _p$paragraphStyle2;
|
|
20968
21067
|
const level = transformNamedStyleTypeToLevel(p.paragraphStyle.namedStyleType);
|
|
20969
21068
|
return {
|
|
20970
|
-
id: p.
|
|
21069
|
+
id: p.paragraphId,
|
|
20971
21070
|
text: getPlainText(fullDataStream.slice(paragraphStarts.get(p.startIndex), p.startIndex)),
|
|
20972
21071
|
level,
|
|
20973
21072
|
isTitle: ((_p$paragraphStyle2 = p.paragraphStyle) === null || _p$paragraphStyle2 === void 0 ? void 0 : _p$paragraphStyle2.namedStyleType) === NamedStyleType.TITLE
|
|
@@ -20976,7 +21075,7 @@ function DocSideMenuContent() {
|
|
|
20976
21075
|
const handleScroll = useEvent((params) => {
|
|
20977
21076
|
const scrollTop = params.viewportScrollY;
|
|
20978
21077
|
const bottom = scrollTop + canvasHeight / scaleY;
|
|
20979
|
-
const activeId = findActiveHeading(paragraphBounds, paragraphMap, scrollTop, bottom);
|
|
21078
|
+
const activeId = findActiveHeading(docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.paragraphBounds, paragraphMap, scrollTop, bottom);
|
|
20980
21079
|
if (activeId) setActiveId(activeId);
|
|
20981
21080
|
});
|
|
20982
21081
|
const menus = (paragraphMenus === null || paragraphMenus === void 0 ? void 0 : paragraphMenus.find((p) => p.isTitle)) ? paragraphMenus : [...title ? [{
|
|
@@ -20985,7 +21084,32 @@ function DocSideMenuContent() {
|
|
|
20985
21084
|
level: 1,
|
|
20986
21085
|
isTitle: true
|
|
20987
21086
|
}] : [], ...paragraphMenus ?? []].filter(Boolean);
|
|
20988
|
-
const
|
|
21087
|
+
const outlineTitle = (_menus$find = menus.find((menu) => menu.isTitle)) === null || _menus$find === void 0 ? void 0 : _menus$find.text;
|
|
21088
|
+
useLayoutEffect(() => {
|
|
21089
|
+
setOutlineHeight(0);
|
|
21090
|
+
}, [
|
|
21091
|
+
unitId,
|
|
21092
|
+
menus.length,
|
|
21093
|
+
outlineTitle
|
|
21094
|
+
]);
|
|
21095
|
+
useLayoutEffect(() => {
|
|
21096
|
+
const container = containerRef.current;
|
|
21097
|
+
const menu = container === null || container === void 0 ? void 0 : container.firstElementChild;
|
|
21098
|
+
if (!container || !menu) return;
|
|
21099
|
+
const measureOutline = () => {
|
|
21100
|
+
var _container$querySelec;
|
|
21101
|
+
const height = (_container$querySelec = container.querySelector("nav")) === null || _container$querySelec === void 0 ? void 0 : _container$querySelec.getBoundingClientRect().height;
|
|
21102
|
+
if (height) setOutlineHeight(height);
|
|
21103
|
+
};
|
|
21104
|
+
const observer = new ResizeObserver(measureOutline);
|
|
21105
|
+
observer.observe(menu);
|
|
21106
|
+
return () => observer.disconnect();
|
|
21107
|
+
}, [
|
|
21108
|
+
mode,
|
|
21109
|
+
unitId,
|
|
21110
|
+
menus.length,
|
|
21111
|
+
enabled
|
|
21112
|
+
]);
|
|
20989
21113
|
useEffect(() => {
|
|
20990
21114
|
const viewport = renderer === null || renderer === void 0 ? void 0 : renderer.scene.getViewport("viewMain");
|
|
20991
21115
|
if (!viewport) return;
|
|
@@ -21002,31 +21126,27 @@ function DocSideMenuContent() {
|
|
|
21002
21126
|
setActiveId(menu.id);
|
|
21003
21127
|
return;
|
|
21004
21128
|
}
|
|
21005
|
-
const paragraph =
|
|
21006
|
-
var _p$paragraphStyle3;
|
|
21007
|
-
return ((_p$paragraphStyle3 = p.paragraphStyle) === null || _p$paragraphStyle3 === void 0 ? void 0 : _p$paragraphStyle3.headingId) === menu.id;
|
|
21008
|
-
});
|
|
21129
|
+
const paragraph = headingParagraphs.find((p) => p.paragraphId === menu.id);
|
|
21009
21130
|
if (!paragraph) return;
|
|
21010
|
-
const bound =
|
|
21131
|
+
const bound = docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.paragraphBounds.get(paragraph.startIndex);
|
|
21011
21132
|
if (!bound) return;
|
|
21012
21133
|
viewport.scrollToViewportPos({ viewportScrollY: bound.rect.top });
|
|
21013
21134
|
setActiveId(menu.id);
|
|
21014
21135
|
});
|
|
21015
|
-
if (!currentDoc || isInternalEditorID(unitId) || !(menus === null || menus === void 0 ? void 0 : menus.length)) return null;
|
|
21136
|
+
if (!enabled || !currentDoc || isInternalEditorID(unitId) || !(menus === null || menus === void 0 ? void 0 : menus.length)) return null;
|
|
21016
21137
|
return /* @__PURE__ */ jsx("div", {
|
|
21138
|
+
ref: containerRef,
|
|
21017
21139
|
className: "univer-absolute univer-bottom-0 univer-left-0 univer-top-0 univer-z-[100] univer-w-[0px]",
|
|
21018
21140
|
children: /* @__PURE__ */ jsx(SideMenu, {
|
|
21019
21141
|
label: localeService.t("docs-ui.outline.title"),
|
|
21020
21142
|
menus,
|
|
21021
|
-
open,
|
|
21022
|
-
onOpenChange: setOpen,
|
|
21023
21143
|
mode,
|
|
21024
21144
|
maxWidth: Math.max(0, Math.floor(mode === "float" ? canvasWidth : left) - 24),
|
|
21025
21145
|
wrapperClass: "univer-mt-4",
|
|
21026
21146
|
activeId,
|
|
21027
21147
|
onClick: handleClick,
|
|
21028
21148
|
maxHeight: Math.max(0, canvasHeight - 32)
|
|
21029
|
-
})
|
|
21149
|
+
}, mode)
|
|
21030
21150
|
});
|
|
21031
21151
|
}
|
|
21032
21152
|
|
|
@@ -21404,7 +21524,7 @@ function resolveDocsCustomBlockRenderViewport(params) {
|
|
|
21404
21524
|
//#endregion
|
|
21405
21525
|
//#region package.json
|
|
21406
21526
|
var name = "@univerjs/docs-ui";
|
|
21407
|
-
var version = "1.
|
|
21527
|
+
var version = "1.2.0";
|
|
21408
21528
|
|
|
21409
21529
|
//#endregion
|
|
21410
21530
|
//#region src/commands/commands/doc-paragraph-setting.command.ts
|
|
@@ -22266,7 +22386,7 @@ let DocMoveCursorController = class DocMoveCursorController extends Disposable {
|
|
|
22266
22386
|
}
|
|
22267
22387
|
_deferUnmaterializedCursorMove(doc, skeleton, offset, segmentId, resume) {
|
|
22268
22388
|
var _skeleton$getSkeleton, _render$getInjector, _doc$getBody;
|
|
22269
|
-
if (segmentId !== "") return false;
|
|
22389
|
+
if (segmentId !== "" || skeleton.getViewModel().getCollapsedHeadingAtOffset(offset)) return false;
|
|
22270
22390
|
const pageIndex = skeleton.findBodyPageIndexByCharIndex(offset);
|
|
22271
22391
|
const page = (_skeleton$getSkeleton = skeleton.getSkeletonData()) === null || _skeleton$getSkeleton === void 0 ? void 0 : _skeleton$getSkeleton.pages[pageIndex];
|
|
22272
22392
|
if (pageIndex >= 0 && !(page === null || page === void 0 ? void 0 : page.isMaterializationPlaceholder)) return false;
|
|
@@ -22375,6 +22495,13 @@ let DocMoveCursorController = class DocMoveCursorController extends Disposable {
|
|
|
22375
22495
|
const visited = /* @__PURE__ */ new Set();
|
|
22376
22496
|
while (current >= 0 && current < dataStream.length && !visited.has(current)) {
|
|
22377
22497
|
visited.add(current);
|
|
22498
|
+
if (!segmentId) {
|
|
22499
|
+
const hidden = skeleton.getViewModel().getCollapsedHeadingAtOffset(current);
|
|
22500
|
+
if (hidden) {
|
|
22501
|
+
current = step < 0 ? hidden.paragraphIndex : hidden.endOffset;
|
|
22502
|
+
continue;
|
|
22503
|
+
}
|
|
22504
|
+
}
|
|
22378
22505
|
const normalizedCursor = this._normalizeCursorOffset(dataStream, customRanges, current, direction);
|
|
22379
22506
|
if (normalizedCursor < 0 || normalizedCursor >= dataStream.length) return;
|
|
22380
22507
|
if (this._isRenderableCursorOffset(skeleton, dataStream, normalizedCursor, segmentId, segmentPage)) return normalizedCursor;
|
|
@@ -28641,10 +28768,16 @@ let DocParagraphMenuService = class DocParagraphMenuService extends Disposable {
|
|
|
28641
28768
|
const targetParagraph = target.paragraph ?? paragraph;
|
|
28642
28769
|
const blockRange = target.blockRange;
|
|
28643
28770
|
const getFirstLine = () => {
|
|
28771
|
+
var _this$_context$unit$g;
|
|
28644
28772
|
const latestParagraphBound = this._docEventManagerService.findParagraphBoundByIndex(targetParagraph.startIndex) ?? targetParagraph;
|
|
28645
28773
|
const baseAnchor = blockRange ? getBlockRangeAnchorRect(this._docEventManagerService, blockRange, paragraph) : latestParagraphBound.firstLine ?? paragraph.firstLine;
|
|
28646
|
-
|
|
28647
|
-
|
|
28774
|
+
const menuAnchor = ((_this$_context$unit$g = this._context.unit.getSnapshot().documentStyle) === null || _this$_context$unit$g === void 0 ? void 0 : _this$_context$unit$g.documentFlavor) === DocumentFlavor.MODERN && this._docSkeletonManagerService.getViewModel().getHeadingSections().some((heading) => heading.paragraphIndex === targetParagraph.startIndex && heading.startOffset < heading.endOffset) ? {
|
|
28775
|
+
...baseAnchor,
|
|
28776
|
+
left: baseAnchor.left - 24,
|
|
28777
|
+
right: baseAnchor.right - 24
|
|
28778
|
+
} : baseAnchor;
|
|
28779
|
+
if (!target.cellRange) return menuAnchor;
|
|
28780
|
+
return getTableCellParagraphAnchorRect(this._docEventManagerService, latestParagraphBound, menuAnchor);
|
|
28648
28781
|
};
|
|
28649
28782
|
const disposable = this._docPopupManagerService.attachPopupToRect(getFirstLine, {
|
|
28650
28783
|
componentKey: DOC_PARAGRAPH_MENU_COMPONENT_KEY,
|
|
@@ -29649,6 +29782,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
|
|
|
29649
29782
|
}, [doc, startIndex]);
|
|
29650
29783
|
const isEmptyParagraph = (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.emptyMode) ?? isEmptyParagraphMenuTarget(dataStream, activeParagraphBound);
|
|
29651
29784
|
const namedStyleType = paragraphObj === null || paragraphObj === void 0 || (_paragraphObj$paragra = paragraphObj.paragraphStyle) === null || _paragraphObj$paragra === void 0 ? void 0 : _paragraphObj$paragra.namedStyleType;
|
|
29785
|
+
const isModernHeading = (doc === null || doc === void 0 ? void 0 : doc.getDocumentStyle().documentFlavor) === DocumentFlavor.MODERN && startIndex != null && (renderUnit === null || renderUnit === void 0 ? void 0 : renderUnit.with(DocSkeletonManagerService).getViewModel().getHeadingSections().some((heading) => heading.paragraphIndex === startIndex && heading.startOffset < heading.endOffset));
|
|
29652
29786
|
const targetIconKey = (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.icon) ?? getParagraphMenuTriggerIconKey(namedStyleType);
|
|
29653
29787
|
const TargetIcon = iconManager.get(targetIconKey);
|
|
29654
29788
|
const paragraphMenuType = useMemo(() => getParagraphMenuType(currentActiveTarget, isEmptyParagraph), [currentActiveTarget, isEmptyParagraph]);
|
|
@@ -29944,7 +30078,10 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
|
|
|
29944
30078
|
"data-u-table-menu": tableBlockOnly ? "true" : void 0,
|
|
29945
30079
|
"data-u-focused-table-menu": isFocusedTableMenu ? "true" : void 0,
|
|
29946
30080
|
ref: anchorRef,
|
|
29947
|
-
className: clsx("univer-
|
|
30081
|
+
className: clsx("univer-inline-flex univer-h-7 univer-cursor-pointer univer-items-center univer-gap-1 univer-rounded-md univer-border univer-border-solid univer-border-gray-200 univer-bg-gray-0 univer-px-2 univer-py-0 univer-shadow-sm univer-transition-colors hover:univer-bg-gray-50 hover:univer-shadow-md dark:!univer-border-gray-600 dark:!univer-bg-gray-900 dark:hover:!univer-bg-gray-800", {
|
|
30082
|
+
"univer-mr-1": !isModernHeading,
|
|
30083
|
+
"univer-bg-gray-100 univer-shadow-md dark:!univer-bg-gray-800": visible
|
|
30084
|
+
}),
|
|
29948
30085
|
onMouseEnter: (e) => {
|
|
29949
30086
|
var _popup$onPointerEnter;
|
|
29950
30087
|
(_popup$onPointerEnter = popup.onPointerEnter) === null || _popup$onPointerEnter === void 0 || _popup$onPointerEnter.call(popup, e);
|
|
@@ -30804,6 +30941,289 @@ let DocContextualRibbonService = class DocContextualRibbonService extends Dispos
|
|
|
30804
30941
|
};
|
|
30805
30942
|
DocContextualRibbonService = __decorate([__decorateParam(0, IRibbonService)], DocContextualRibbonService);
|
|
30806
30943
|
|
|
30944
|
+
//#endregion
|
|
30945
|
+
//#region src/views/heading-collapse-shape.ts
|
|
30946
|
+
var HeadingCollapseShape = class extends Shape {
|
|
30947
|
+
constructor(key, colors, activate) {
|
|
30948
|
+
super(key, {
|
|
30949
|
+
width: 24,
|
|
30950
|
+
height: 28,
|
|
30951
|
+
debounceParentDirty: false
|
|
30952
|
+
});
|
|
30953
|
+
_defineProperty(this, "_collapsed", false);
|
|
30954
|
+
_defineProperty(this, "_label", "");
|
|
30955
|
+
_defineProperty(this, "_colors", void 0);
|
|
30956
|
+
_defineProperty(this, "_hovered", false);
|
|
30957
|
+
_defineProperty(this, "_tooltipVisible", false);
|
|
30958
|
+
_defineProperty(this, "_tooltipTimer", null);
|
|
30959
|
+
_defineProperty(this, "_pressed", false);
|
|
30960
|
+
this._colors = colors;
|
|
30961
|
+
this.cursor = CURSOR_TYPE.POINTER;
|
|
30962
|
+
this.disposeWithMe(this.onPointerEnter$.subscribeEvent((event) => {
|
|
30963
|
+
if (this._hovered || event.buttons) return;
|
|
30964
|
+
this._hovered = true;
|
|
30965
|
+
this._tooltipTimer = setTimeout(() => {
|
|
30966
|
+
this._tooltipTimer = null;
|
|
30967
|
+
this._tooltipVisible = true;
|
|
30968
|
+
this.makeDirty(true);
|
|
30969
|
+
}, 500);
|
|
30970
|
+
this.makeDirty(true);
|
|
30971
|
+
}));
|
|
30972
|
+
this.disposeWithMe(this.onPointerLeave$.subscribeEvent(() => this.resetHover()));
|
|
30973
|
+
this.disposeWithMe(this.onPointerDown$.subscribeEvent((event, state) => {
|
|
30974
|
+
state.stopPropagation();
|
|
30975
|
+
event.preventDefault();
|
|
30976
|
+
this._pressed = event.button === 0;
|
|
30977
|
+
}));
|
|
30978
|
+
this.disposeWithMe(this.onPointerUp$.subscribeEvent((event, state) => {
|
|
30979
|
+
state.stopPropagation();
|
|
30980
|
+
event.preventDefault();
|
|
30981
|
+
const activateButton = this._pressed && event.button === 0;
|
|
30982
|
+
this._pressed = false;
|
|
30983
|
+
this._hideTooltip();
|
|
30984
|
+
if (activateButton) activate();
|
|
30985
|
+
}));
|
|
30986
|
+
this.disposeWithMe(this.onClick$.subscribeEvent((_event, state) => state.stopPropagation()));
|
|
30987
|
+
this.disposeWithMe(this.onDblclick$.subscribeEvent((_event, state) => state.stopPropagation()));
|
|
30988
|
+
}
|
|
30989
|
+
update(collapsed, label, colors) {
|
|
30990
|
+
if (collapsed === this._collapsed && label === this._label && colors === this._colors) return;
|
|
30991
|
+
this._collapsed = collapsed;
|
|
30992
|
+
this._label = label;
|
|
30993
|
+
this._colors = colors;
|
|
30994
|
+
this.makeDirty(true);
|
|
30995
|
+
}
|
|
30996
|
+
resetHover() {
|
|
30997
|
+
this._hideTooltip();
|
|
30998
|
+
this._pressed = false;
|
|
30999
|
+
if (this._hovered) {
|
|
31000
|
+
this._hovered = false;
|
|
31001
|
+
this.makeDirty(true);
|
|
31002
|
+
}
|
|
31003
|
+
}
|
|
31004
|
+
_hideTooltip() {
|
|
31005
|
+
if (this._tooltipTimer !== null) {
|
|
31006
|
+
clearTimeout(this._tooltipTimer);
|
|
31007
|
+
this._tooltipTimer = null;
|
|
31008
|
+
}
|
|
31009
|
+
if (this._tooltipVisible) {
|
|
31010
|
+
this._tooltipVisible = false;
|
|
31011
|
+
this.makeDirty(true);
|
|
31012
|
+
}
|
|
31013
|
+
}
|
|
31014
|
+
_draw(ctx, bounds) {
|
|
31015
|
+
ctx.fillStyle = this._hovered ? this._colors.hover : this._colors.normal;
|
|
31016
|
+
ctx.beginPath();
|
|
31017
|
+
if (this._collapsed) {
|
|
31018
|
+
ctx.moveTo(9, 8);
|
|
31019
|
+
ctx.lineTo(16, 14);
|
|
31020
|
+
ctx.lineTo(9, 20);
|
|
31021
|
+
} else {
|
|
31022
|
+
ctx.moveTo(6, 11);
|
|
31023
|
+
ctx.lineTo(18, 11);
|
|
31024
|
+
ctx.lineTo(12, 18);
|
|
31025
|
+
}
|
|
31026
|
+
ctx.closePath();
|
|
31027
|
+
ctx.fill();
|
|
31028
|
+
if (!this._tooltipVisible) return;
|
|
31029
|
+
ctx.save();
|
|
31030
|
+
ctx.font = "12px sans-serif";
|
|
31031
|
+
const width = ctx.measureText(this._label).width + 20;
|
|
31032
|
+
const viewport = bounds === null || bounds === void 0 ? void 0 : bounds.viewBound;
|
|
31033
|
+
const centeredLeft = (this.width - width) / 2;
|
|
31034
|
+
const left = viewport ? Math.max(viewport.left - this.left, Math.min(centeredLeft, viewport.right - this.left - width)) : centeredLeft;
|
|
31035
|
+
const below = viewport != null && this.top - 36 < viewport.top;
|
|
31036
|
+
ctx.translate(left, below ? this.height + 8 : -36);
|
|
31037
|
+
Rect.drawWith(ctx, {
|
|
31038
|
+
width,
|
|
31039
|
+
height: 28,
|
|
31040
|
+
radius: 6,
|
|
31041
|
+
fill: this._colors.tooltipBackground
|
|
31042
|
+
});
|
|
31043
|
+
ctx.fillStyle = this._colors.tooltipBackground;
|
|
31044
|
+
ctx.beginPath();
|
|
31045
|
+
const arrow = this.width / 2 - left;
|
|
31046
|
+
const arrowBase = below ? 0 : 28;
|
|
31047
|
+
ctx.moveTo(arrow - 4, arrowBase);
|
|
31048
|
+
ctx.lineTo(arrow, below ? -4 : 32);
|
|
31049
|
+
ctx.lineTo(arrow + 4, arrowBase);
|
|
31050
|
+
ctx.fill();
|
|
31051
|
+
ctx.fillStyle = this._colors.tooltipText;
|
|
31052
|
+
ctx.textAlign = "center";
|
|
31053
|
+
ctx.textBaseline = "middle";
|
|
31054
|
+
ctx.fillText(this._label, width / 2, 14);
|
|
31055
|
+
ctx.restore();
|
|
31056
|
+
}
|
|
31057
|
+
dispose() {
|
|
31058
|
+
this.resetHover();
|
|
31059
|
+
super.dispose();
|
|
31060
|
+
}
|
|
31061
|
+
};
|
|
31062
|
+
|
|
31063
|
+
//#endregion
|
|
31064
|
+
//#region src/services/doc-heading-collapse.service.ts
|
|
31065
|
+
let DocHeadingCollapseService = class DocHeadingCollapseService extends Disposable {
|
|
31066
|
+
constructor(_context, _skeletonManager, _eventManager, _selections, _commandService, _layoutService, themeService, localeService) {
|
|
31067
|
+
super();
|
|
31068
|
+
this._context = _context;
|
|
31069
|
+
this._skeletonManager = _skeletonManager;
|
|
31070
|
+
this._eventManager = _eventManager;
|
|
31071
|
+
this._selections = _selections;
|
|
31072
|
+
this._commandService = _commandService;
|
|
31073
|
+
this._layoutService = _layoutService;
|
|
31074
|
+
_defineProperty(this, "_buttons", /* @__PURE__ */ new Map());
|
|
31075
|
+
_defineProperty(this, "_colors", void 0);
|
|
31076
|
+
_defineProperty(this, "_expandLabel", "");
|
|
31077
|
+
_defineProperty(this, "_collapseLabel", "");
|
|
31078
|
+
this._colors = this._getColors(themeService);
|
|
31079
|
+
if (isInternalEditorID(_context.unitId)) return;
|
|
31080
|
+
this.disposeWithMe(themeService.currentTheme$.subscribe(() => {
|
|
31081
|
+
this._colors = this._getColors(themeService);
|
|
31082
|
+
this._update();
|
|
31083
|
+
}));
|
|
31084
|
+
this.disposeWithMe(localeService.currentLocale$.subscribe(() => {
|
|
31085
|
+
this._expandLabel = localeService.t("docs-ui.heading.expand");
|
|
31086
|
+
this._collapseLabel = localeService.t("docs-ui.heading.collapse");
|
|
31087
|
+
this._update();
|
|
31088
|
+
}));
|
|
31089
|
+
this.disposeWithMe(_context.scene.beforeRender$.subscribe(() => this._update()));
|
|
31090
|
+
this.disposeWithMe(this._skeletonManager.currentSkeleton$.subscribe(() => this._update()));
|
|
31091
|
+
this.disposeWithMe(this._skeletonManager.getSkeleton().dirty$.subscribe(() => this._update()));
|
|
31092
|
+
const resetHover = () => this._buttons.forEach((button) => button.resetHover());
|
|
31093
|
+
const viewport = _context.scene.getViewport("viewMain");
|
|
31094
|
+
if (viewport) {
|
|
31095
|
+
let scrollX = viewport.viewportScrollX;
|
|
31096
|
+
let scrollY = viewport.viewportScrollY;
|
|
31097
|
+
this.disposeWithMe(viewport.onScrollAfter$.subscribeEvent((event) => {
|
|
31098
|
+
if (event.viewportScrollX !== scrollX || event.viewportScrollY !== scrollY) {
|
|
31099
|
+
resetHover();
|
|
31100
|
+
scrollX = event.viewportScrollX;
|
|
31101
|
+
scrollY = event.viewportScrollY;
|
|
31102
|
+
}
|
|
31103
|
+
}));
|
|
31104
|
+
}
|
|
31105
|
+
this.disposeWithMe(_context.scene.onPointerCancel$.subscribeEvent(resetHover));
|
|
31106
|
+
this.disposeWithMe(_context.scene.onTransformChange$.subscribeEvent(({ value, preValue }) => {
|
|
31107
|
+
if (value.scaleX != null && value.scaleX !== preValue.scaleX || value.scaleY != null && value.scaleY !== preValue.scaleY) resetHover();
|
|
31108
|
+
}));
|
|
31109
|
+
this.disposeWithMe(_context.scene.onPointerLeave$.subscribeEvent(resetHover));
|
|
31110
|
+
this.disposeWithMe(this._selections.textSelection$.subscribe(({ unitId }) => {
|
|
31111
|
+
if (unitId === _context.unitId) this._normalizeSelection();
|
|
31112
|
+
}));
|
|
31113
|
+
}
|
|
31114
|
+
_getColors(themeService) {
|
|
31115
|
+
return {
|
|
31116
|
+
normal: themeService.getColorFromTheme("gray.900"),
|
|
31117
|
+
hover: themeService.getColorFromTheme("primary.600"),
|
|
31118
|
+
tooltipBackground: themeService.getColorFromTheme("gray.700"),
|
|
31119
|
+
tooltipText: themeService.getColorFromTheme("gray.0")
|
|
31120
|
+
};
|
|
31121
|
+
}
|
|
31122
|
+
_normalizeSelection() {
|
|
31123
|
+
const target = {
|
|
31124
|
+
unitId: this._context.unitId,
|
|
31125
|
+
subUnitId: this._context.unitId
|
|
31126
|
+
};
|
|
31127
|
+
const info = this._selections.getSelectionInfo(target);
|
|
31128
|
+
if (!info || info.segmentId) return;
|
|
31129
|
+
const viewModel = this._skeletonManager.getViewModel();
|
|
31130
|
+
const hiddenRect = info.rectRanges.find((range) => !range.segmentId && range.startOffset != null && viewModel.getCollapsedHeadingAtOffset(range.startOffset));
|
|
31131
|
+
if ((hiddenRect === null || hiddenRect === void 0 ? void 0 : hiddenRect.startOffset) != null) {
|
|
31132
|
+
const offset = viewModel.getCollapsedHeadingAtOffset(hiddenRect.startOffset).paragraphIndex;
|
|
31133
|
+
const textRanges = [{
|
|
31134
|
+
startOffset: offset,
|
|
31135
|
+
endOffset: offset,
|
|
31136
|
+
collapsed: true,
|
|
31137
|
+
isActive: true
|
|
31138
|
+
}];
|
|
31139
|
+
this._selections.replaceSelectionInfoWithoutRefresh({
|
|
31140
|
+
...info,
|
|
31141
|
+
textRanges,
|
|
31142
|
+
rectRanges: []
|
|
31143
|
+
}, target);
|
|
31144
|
+
this._selections.replaceDocRanges(textRanges, target, false, { forceFocus: false });
|
|
31145
|
+
return;
|
|
31146
|
+
}
|
|
31147
|
+
let changed = false;
|
|
31148
|
+
const textRanges = info.textRanges.map((range) => {
|
|
31149
|
+
var _viewModel$getCollaps, _viewModel$getCollaps2;
|
|
31150
|
+
if (range.segmentId) return range;
|
|
31151
|
+
const startOffset = ((_viewModel$getCollaps = viewModel.getCollapsedHeadingAtOffset(range.startOffset)) === null || _viewModel$getCollaps === void 0 ? void 0 : _viewModel$getCollaps.paragraphIndex) ?? range.startOffset;
|
|
31152
|
+
const endOffset = ((_viewModel$getCollaps2 = viewModel.getCollapsedHeadingAtOffset(range.endOffset)) === null || _viewModel$getCollaps2 === void 0 ? void 0 : _viewModel$getCollaps2.paragraphIndex) ?? range.endOffset;
|
|
31153
|
+
if (startOffset === range.startOffset && endOffset === range.endOffset) return range;
|
|
31154
|
+
changed = true;
|
|
31155
|
+
return {
|
|
31156
|
+
...range,
|
|
31157
|
+
startOffset,
|
|
31158
|
+
endOffset,
|
|
31159
|
+
collapsed: startOffset === endOffset,
|
|
31160
|
+
startNodePosition: void 0,
|
|
31161
|
+
endNodePosition: void 0
|
|
31162
|
+
};
|
|
31163
|
+
});
|
|
31164
|
+
if (changed) {
|
|
31165
|
+
this._selections.replaceSelectionInfoWithoutRefresh({
|
|
31166
|
+
...info,
|
|
31167
|
+
textRanges
|
|
31168
|
+
}, target);
|
|
31169
|
+
this._selections.replaceDocRanges([...textRanges, ...info.rectRanges], target, false, { forceFocus: false });
|
|
31170
|
+
}
|
|
31171
|
+
}
|
|
31172
|
+
_update() {
|
|
31173
|
+
this._normalizeSelection();
|
|
31174
|
+
const active = /* @__PURE__ */ new Set();
|
|
31175
|
+
const viewModel = this._skeletonManager.getViewModel();
|
|
31176
|
+
if (this._context.unit.getSnapshot().documentStyle.documentFlavor === DocumentFlavor.MODERN) for (const heading of viewModel.getHeadingSections()) {
|
|
31177
|
+
if (heading.startOffset >= heading.endOffset || viewModel.getCollapsedHeadingAtOffset(heading.paragraphIndex)) continue;
|
|
31178
|
+
const bound = this._eventManager.findParagraphBoundByIndex(heading.paragraphIndex);
|
|
31179
|
+
if (!bound || bound.segmentId) continue;
|
|
31180
|
+
active.add(heading.paragraphId);
|
|
31181
|
+
let button = this._buttons.get(heading.paragraphId);
|
|
31182
|
+
if (!button) {
|
|
31183
|
+
button = new HeadingCollapseShape(`__DocHeadingCollapse__${heading.paragraphId}`, this._colors, () => {
|
|
31184
|
+
var _this$_context$unit$g;
|
|
31185
|
+
const paragraph = (_this$_context$unit$g = this._context.unit.getBody()) === null || _this$_context$unit$g === void 0 || (_this$_context$unit$g = _this$_context$unit$g.paragraphs) === null || _this$_context$unit$g === void 0 ? void 0 : _this$_context$unit$g.find((item) => item.paragraphId === heading.paragraphId);
|
|
31186
|
+
if (paragraph && this._commandService.syncExecuteCommand(SetHeadingCollapsedCommand.id, {
|
|
31187
|
+
unitId: this._context.unitId,
|
|
31188
|
+
paragraphId: heading.paragraphId,
|
|
31189
|
+
collapsed: paragraph.headingCollapsed !== true
|
|
31190
|
+
})) this._layoutService.focus(this._context.unitId);
|
|
31191
|
+
});
|
|
31192
|
+
this._buttons.set(heading.paragraphId, button);
|
|
31193
|
+
this._context.scene.addObject(button, 3);
|
|
31194
|
+
}
|
|
31195
|
+
const left = bound.firstLine.left - button.width;
|
|
31196
|
+
const top = (bound.firstLine.top + bound.firstLine.bottom - button.height) / 2;
|
|
31197
|
+
if (button.left !== left || button.top !== top) {
|
|
31198
|
+
button.resetHover();
|
|
31199
|
+
button.transformByState({
|
|
31200
|
+
left,
|
|
31201
|
+
top
|
|
31202
|
+
});
|
|
31203
|
+
}
|
|
31204
|
+
button.update(heading.collapsed, heading.collapsed ? this._expandLabel : this._collapseLabel, this._colors);
|
|
31205
|
+
}
|
|
31206
|
+
for (const [id, button] of this._buttons) if (!active.has(id)) {
|
|
31207
|
+
button.dispose();
|
|
31208
|
+
this._buttons.delete(id);
|
|
31209
|
+
}
|
|
31210
|
+
}
|
|
31211
|
+
dispose() {
|
|
31212
|
+
super.dispose();
|
|
31213
|
+
this._buttons.forEach((button) => button.dispose());
|
|
31214
|
+
this._buttons.clear();
|
|
31215
|
+
}
|
|
31216
|
+
};
|
|
31217
|
+
DocHeadingCollapseService = __decorate([
|
|
31218
|
+
__decorateParam(1, Inject(DocSkeletonManagerService)),
|
|
31219
|
+
__decorateParam(2, Inject(DocEventManagerService)),
|
|
31220
|
+
__decorateParam(3, Inject(DocSelectionManagerService)),
|
|
31221
|
+
__decorateParam(4, ICommandService),
|
|
31222
|
+
__decorateParam(5, ILayoutService),
|
|
31223
|
+
__decorateParam(6, Inject(ThemeService)),
|
|
31224
|
+
__decorateParam(7, Inject(LocaleService))
|
|
31225
|
+
], DocHeadingCollapseService);
|
|
31226
|
+
|
|
30807
31227
|
//#endregion
|
|
30808
31228
|
//#region src/shortcuts/core-editing.shortcut.ts
|
|
30809
31229
|
const BreakLineShortcut = {
|
|
@@ -31228,6 +31648,7 @@ let UniverDocsUIPlugin = class UniverDocsUIPlugin extends Plugin {
|
|
|
31228
31648
|
[DocFloatMenuService],
|
|
31229
31649
|
[DocPasteOptionsRenderController],
|
|
31230
31650
|
[DocParagraphMenuService],
|
|
31651
|
+
[DocHeadingCollapseService],
|
|
31231
31652
|
[DocHeaderFooterController],
|
|
31232
31653
|
[DocHeaderFooterRibbonController],
|
|
31233
31654
|
[DocResizeRenderController],
|