@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/cjs/index.js
CHANGED
|
@@ -521,15 +521,34 @@ const BreakLineCommand = {
|
|
|
521
521
|
const { horizontalLine, insertionMode = "split-paragraph" } = params ?? {};
|
|
522
522
|
const { segmentId } = activeTextRange;
|
|
523
523
|
const docDataModel = (params === null || params === void 0 ? void 0 : params.unitId) ? univerInstanceService.getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
524
|
-
|
|
524
|
+
let originBody = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId ?? "")) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
|
|
525
525
|
if (docDataModel == null || originBody == null) return false;
|
|
526
526
|
const unitId = docDataModel.getUnitId();
|
|
527
527
|
const { startOffset, endOffset } = activeTextRange;
|
|
528
528
|
const paragraphs = originBody.paragraphs ?? [];
|
|
529
529
|
const isBareStructuralGap = isTopLevelStructuralGap(originBody.dataStream, startOffset) && originBody.dataStream[startOffset] !== _univerjs_core.DataStreamTreeTokenType.PARAGRAPH;
|
|
530
530
|
const insertsAtStructuralGap = insertionMode === "insert-gap" || isBareStructuralGap;
|
|
531
|
-
|
|
531
|
+
let prevParagraph = insertsAtStructuralGap ? void 0 : paragraphs.find((p) => p.startIndex >= startOffset);
|
|
532
532
|
if (!prevParagraph && !insertsAtStructuralGap) return false;
|
|
533
|
+
if (!segmentId && (prevParagraph === null || prevParagraph === void 0 ? void 0 : prevParagraph.headingCollapsed) && docDataModel.getSnapshot().documentStyle.documentFlavor === _univerjs_core.DocumentFlavor.MODERN) {
|
|
534
|
+
const paragraphId = prevParagraph.paragraphId;
|
|
535
|
+
const viewModel = new _univerjs_engine_render.DocumentViewModel(docDataModel);
|
|
536
|
+
try {
|
|
537
|
+
if (viewModel.getHeadingSections().some((section) => section.paragraphId === paragraphId)) {
|
|
538
|
+
var _originBody$paragraph;
|
|
539
|
+
if (!commandService.syncExecuteCommand(_univerjs_docs.SetHeadingCollapsedCommand.id, {
|
|
540
|
+
unitId,
|
|
541
|
+
paragraphId,
|
|
542
|
+
collapsed: false
|
|
543
|
+
})) return false;
|
|
544
|
+
originBody = docDataModel.getBody();
|
|
545
|
+
prevParagraph = originBody === null || originBody === void 0 || (_originBody$paragraph = originBody.paragraphs) === null || _originBody$paragraph === void 0 ? void 0 : _originBody$paragraph.find((paragraph) => paragraph.startIndex >= startOffset);
|
|
546
|
+
if (!originBody || !prevParagraph) return false;
|
|
547
|
+
}
|
|
548
|
+
} finally {
|
|
549
|
+
viewModel.dispose();
|
|
550
|
+
}
|
|
551
|
+
}
|
|
533
552
|
const isAtParagraphEnd = startOffset === (prevParagraph === null || prevParagraph === void 0 ? void 0 : prevParagraph.startIndex);
|
|
534
553
|
const prevParagraphIndex = prevParagraph === null || prevParagraph === void 0 ? void 0 : prevParagraph.startIndex;
|
|
535
554
|
const defaultTextStyle = docMenuStyleService.getDefaultStyle();
|
|
@@ -2867,7 +2886,7 @@ function getTextRangeFromCharIndex(startOffset, endOffset, scene, document, skel
|
|
|
2867
2886
|
function getRectRangeFromCharIndex(startOffset, endOffset, scene, document, skeleton, style, segmentId, segmentPage) {
|
|
2868
2887
|
const startNodePosition = skeleton.findNodePositionByCharIndex(startOffset, true, segmentId, segmentPage);
|
|
2869
2888
|
const endNodePosition = skeleton.findNodePositionByCharIndex(endOffset, true, segmentId, segmentPage);
|
|
2870
|
-
if (startNodePosition == null || endNodePosition == null) return;
|
|
2889
|
+
if (startNodePosition == null || endNodePosition == null || startNodePosition.path.indexOf("cells") === -1 || endNodePosition.path.indexOf("cells") === -1) return;
|
|
2871
2890
|
return new RectRange(scene, document, skeleton, startNodePosition, endNodePosition, style, segmentId, segmentPage);
|
|
2872
2891
|
}
|
|
2873
2892
|
function getRangeListFromCharIndex(startOffset, endOffset, scene, document, skeleton, style, segmentId, segmentPage) {
|
|
@@ -6261,6 +6280,14 @@ const DeleteLeftCommand = {
|
|
|
6261
6280
|
const { segmentId, style, segmentPage } = activeRange;
|
|
6262
6281
|
const body = (_docDataModel$getSelf3 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf3 === void 0 ? void 0 : _docDataModel$getSelf3.getBody();
|
|
6263
6282
|
if (body == null) return false;
|
|
6283
|
+
if (activeRange.collapsed && !segmentId) {
|
|
6284
|
+
const hidden = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getViewModel().getCollapsedHeadingAtOffset(activeRange.startOffset - 1);
|
|
6285
|
+
if (hidden) return commandService.executeCommand(_univerjs_docs.SetHeadingCollapsedCommand.id, {
|
|
6286
|
+
unitId,
|
|
6287
|
+
paragraphId: hidden.paragraphId,
|
|
6288
|
+
collapsed: false
|
|
6289
|
+
});
|
|
6290
|
+
}
|
|
6264
6291
|
const originalLength = body.dataStream.length;
|
|
6265
6292
|
const typingStyle = captureDeletedTypingStyle(accessor, docDataModel, body, activeRange);
|
|
6266
6293
|
const actualRange = activeRange;
|
|
@@ -6419,6 +6446,14 @@ const DeleteRightCommand = {
|
|
|
6419
6446
|
const { segmentId, style, segmentPage } = activeRange;
|
|
6420
6447
|
const body = docDataModel === null || docDataModel === void 0 || (_docDataModel$getSelf5 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf5 === void 0 ? void 0 : _docDataModel$getSelf5.getBody();
|
|
6421
6448
|
if (!docDataModel || !body) return false;
|
|
6449
|
+
if (activeRange.collapsed && !segmentId) {
|
|
6450
|
+
const hidden = docSkeletonManagerService === null || docSkeletonManagerService === void 0 ? void 0 : docSkeletonManagerService.getViewModel().getCollapsedHeadingAtOffset(activeRange.startOffset + 1);
|
|
6451
|
+
if (hidden) return commandService.executeCommand(_univerjs_docs.SetHeadingCollapsedCommand.id, {
|
|
6452
|
+
unitId: docDataModel.getUnitId(),
|
|
6453
|
+
paragraphId: hidden.paragraphId,
|
|
6454
|
+
collapsed: false
|
|
6455
|
+
});
|
|
6456
|
+
}
|
|
6422
6457
|
const actualRange = activeRange;
|
|
6423
6458
|
const { startOffset, endOffset, collapsed } = actualRange;
|
|
6424
6459
|
if (collapsed && shouldResetEmptyCenteredParagraphAlignment(accessor, docDataModel)) {
|
|
@@ -8780,13 +8815,21 @@ let DocClipboardService = class DocClipboardService extends _univerjs_core.Dispo
|
|
|
8780
8815
|
this.dismissPasteOptions();
|
|
8781
8816
|
const unitId = payload.unitId ?? this._getCurrentDocumentUnitId();
|
|
8782
8817
|
if (!unitId || !this._canEditTargets(unitId)) return false;
|
|
8783
|
-
|
|
8818
|
+
const isCommentEditor = (0, _univerjs_core.isCommentEditorID)(unitId);
|
|
8819
|
+
if (!cachedSource && !payload.html && !payload.text && !payload.internalJson && (isCommentEditor || !payload.files.length)) return false;
|
|
8784
8820
|
const generation = this._pasteGeneration;
|
|
8785
|
-
const mode = unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY ? "text" : payload.mode ?? "source";
|
|
8821
|
+
const mode = isCommentEditor || unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY ? "text" : payload.mode ?? "source";
|
|
8786
8822
|
const style = this._getPasteStyle(unitId);
|
|
8787
|
-
const source = await this._preparePaste(payload, mode, cachedSource);
|
|
8823
|
+
const source = await (isCommentEditor && payload.text !== void 0 ? { body: { dataStream: payload.text } } : this._preparePaste(payload, mode, cachedSource));
|
|
8788
8824
|
if (generation !== this._pasteGeneration || !this._canEditTargets(unitId)) return false;
|
|
8789
|
-
let doc
|
|
8825
|
+
let doc;
|
|
8826
|
+
if (isCommentEditor) {
|
|
8827
|
+
const text = payload.text ?? getClipboardPlainText(source);
|
|
8828
|
+
if (!text) return false;
|
|
8829
|
+
const body = _univerjs_core.BuildTextUtils.transform.fromPlainText(text);
|
|
8830
|
+
delete body.customRanges;
|
|
8831
|
+
doc = { body };
|
|
8832
|
+
} else doc = applyDocPasteMode(source, mode, style, payload.text);
|
|
8790
8833
|
if (unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY) {
|
|
8791
8834
|
doc = {
|
|
8792
8835
|
...source,
|
|
@@ -11750,7 +11793,6 @@ const DEFAULT_DOC_FIT_TO_WIDTH_OPTIONS = {
|
|
|
11750
11793
|
align: "center"
|
|
11751
11794
|
};
|
|
11752
11795
|
const defaultPluginConfig = {
|
|
11753
|
-
toc: false,
|
|
11754
11796
|
footer: true,
|
|
11755
11797
|
wordCount: true,
|
|
11756
11798
|
placeholder: true,
|
|
@@ -13681,9 +13723,13 @@ let DocRenderController = class DocRenderController extends _univerjs_core.RxDis
|
|
|
13681
13723
|
const interactionAnchor = priorityAnchorBelongsToMutation ? options.anchor : options.priorityAnchor ?? options.anchor;
|
|
13682
13724
|
let interactionViewportAnchor = priorityAnchorBelongsToMutation ? null : this._captureViewportAnchor(skeleton, options.priorityAnchor, options.invalidation);
|
|
13683
13725
|
const foregroundEndOffset = this._resolveContinuousForegroundEndOffset(skeleton, options.invalidation);
|
|
13726
|
+
const viewport = this._context.scene.getViewport("viewMain");
|
|
13727
|
+
const docsComponent = this._context.mainComponent;
|
|
13728
|
+
const minimumPublicationHeight = this._context.unit.documentStyle.documentFlavor === _univerjs_core.DocumentFlavor.MODERN && viewport != null && docsComponent instanceof _univerjs_engine_render.Documents ? Math.max(0, viewport.calcViewportInfo().viewBound.bottom - docsComponent.getOffsetConfig().docsTop) : void 0;
|
|
13684
13729
|
this._layoutCoordinator.schedule(skeleton, {
|
|
13685
13730
|
...options,
|
|
13686
13731
|
anchor: interactionAnchor,
|
|
13732
|
+
...minimumPublicationHeight != null && Number.isFinite(minimumPublicationHeight) && minimumPublicationHeight > 0 ? { minimumPublicationHeight } : {},
|
|
13687
13733
|
...foregroundEndOffset == null ? {} : { foregroundEndOffset },
|
|
13688
13734
|
preserveInteractionWindow: interactionAnchor != null && interactionAnchor !== options.anchor,
|
|
13689
13735
|
reuseUnaffectedTail: false
|
|
@@ -15043,7 +15089,8 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends _unive
|
|
|
15043
15089
|
const updatePosition = () => {
|
|
15044
15090
|
try {
|
|
15045
15091
|
const newPosition = calc();
|
|
15046
|
-
|
|
15092
|
+
const previous = position$.value;
|
|
15093
|
+
if (newPosition && (newPosition.left !== previous.left || newPosition.right !== previous.right || newPosition.top !== previous.top || newPosition.bottom !== previous.bottom)) position$.next(newPosition);
|
|
15047
15094
|
} catch {}
|
|
15048
15095
|
};
|
|
15049
15096
|
disposable.add(this._commandService.onCommandExecuted((commandInfo) => {
|
|
@@ -15099,6 +15146,7 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends _unive
|
|
|
15099
15146
|
disposable.add(currentRender.scene.onTransformChange$.subscribeEvent(() => {
|
|
15100
15147
|
updatePositions();
|
|
15101
15148
|
}));
|
|
15149
|
+
if (currentRender.mainComponent) disposable.add(currentRender.mainComponent.onTransformChange$.subscribeEvent(updatePositions));
|
|
15102
15150
|
return {
|
|
15103
15151
|
positions,
|
|
15104
15152
|
positions$,
|
|
@@ -15110,14 +15158,18 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends _unive
|
|
|
15110
15158
|
if (!currentRender) throw new Error(`Current render not found, unitId: ${unitId}`);
|
|
15111
15159
|
const popupInjector = this._resolveEmbeddedPopupInjector(unitId, currentRender);
|
|
15112
15160
|
const popupManagerService = this._resolvePopupManagerService(popupInjector);
|
|
15113
|
-
const { position, position$, disposable } = this._createRectPositionObserver(rect, currentRender);
|
|
15161
|
+
const { position, position$, disposable, updatePosition } = this._createRectPositionObserver(rect, currentRender);
|
|
15162
|
+
if (popup.positionChanges$) disposable.add(popup.positionChanges$.subscribe(updatePosition));
|
|
15114
15163
|
const id = popupManagerService.addPopup({
|
|
15115
15164
|
...popup,
|
|
15116
15165
|
unitId,
|
|
15117
15166
|
subUnitId: "default",
|
|
15118
15167
|
connectorInjector: popupInjector,
|
|
15119
15168
|
anchorRect: position,
|
|
15120
|
-
anchorRect$: position
|
|
15169
|
+
anchorRect$: position$.pipe((0, rxjs.throttleTime)(0, rxjs.animationFrameScheduler, {
|
|
15170
|
+
leading: true,
|
|
15171
|
+
trailing: true
|
|
15172
|
+
})),
|
|
15121
15173
|
canvasElement: currentRender.engine.getCanvasElement()
|
|
15122
15174
|
});
|
|
15123
15175
|
const popupActivity = popup.requiresStableLayout === false ? null : this._beginPopupActivity(unitId);
|
|
@@ -15149,7 +15201,10 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends _unive
|
|
|
15149
15201
|
subUnitId: "default",
|
|
15150
15202
|
connectorInjector: popupInjector,
|
|
15151
15203
|
anchorRect: position,
|
|
15152
|
-
anchorRect$: position
|
|
15204
|
+
anchorRect$: position$.pipe((0, rxjs.throttleTime)(0, rxjs.animationFrameScheduler, {
|
|
15205
|
+
leading: true,
|
|
15206
|
+
trailing: true
|
|
15207
|
+
})),
|
|
15153
15208
|
canvasElement: currentRender.engine.getCanvasElement()
|
|
15154
15209
|
});
|
|
15155
15210
|
const popupActivity = popup.requiresStableLayout === false ? null : this._beginPopupActivity(unitId);
|
|
@@ -15191,7 +15246,11 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends _unive
|
|
|
15191
15246
|
}
|
|
15192
15247
|
return direction.includes("top") ? bounds[0] : bounds[bounds.length - 1];
|
|
15193
15248
|
};
|
|
15194
|
-
const
|
|
15249
|
+
const popupBounds$ = bounds$.pipe((0, rxjs.throttleTime)(0, rxjs.animationFrameScheduler, {
|
|
15250
|
+
leading: true,
|
|
15251
|
+
trailing: true
|
|
15252
|
+
}));
|
|
15253
|
+
const position$ = popupBounds$.pipe((0, rxjs.filter)((bounds) => bounds.length > 0), (0, rxjs.map)(getAnchor));
|
|
15195
15254
|
let id;
|
|
15196
15255
|
let popupActivity = null;
|
|
15197
15256
|
const removePopup = () => {
|
|
@@ -15216,7 +15275,7 @@ let DocCanvasPopManagerService = class DocCanvasPopManagerService extends _unive
|
|
|
15216
15275
|
anchorRect: getAnchor(bounds),
|
|
15217
15276
|
anchorRect$: position$,
|
|
15218
15277
|
excludeRects: bounds,
|
|
15219
|
-
excludeRects$:
|
|
15278
|
+
excludeRects$: popupBounds$,
|
|
15220
15279
|
direction: [
|
|
15221
15280
|
"top",
|
|
15222
15281
|
"bottom",
|
|
@@ -15525,6 +15584,12 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
|
|
|
15525
15584
|
}));
|
|
15526
15585
|
}
|
|
15527
15586
|
_initResetDirty() {
|
|
15587
|
+
this.disposeWithMe(this._documents.onTransformChange$.subscribeEvent(() => {
|
|
15588
|
+
this._customRangeDirty = true;
|
|
15589
|
+
this._bulletDirty = true;
|
|
15590
|
+
this._paragraphDirty = true;
|
|
15591
|
+
this._tableBoundsDirty = true;
|
|
15592
|
+
}));
|
|
15528
15593
|
this.disposeWithMe(this._skeleton.dirty$.subscribe(() => {
|
|
15529
15594
|
this._customRangeDirty = true;
|
|
15530
15595
|
this._bulletDirty = true;
|
|
@@ -16016,6 +16081,9 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
|
|
|
16016
16081
|
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));
|
|
16017
16082
|
}
|
|
16018
16083
|
findParagraphBoundByIndex(index) {
|
|
16084
|
+
this._buildParagraphBounds();
|
|
16085
|
+
const paragraph = this._paragraphBounds.get(index);
|
|
16086
|
+
if (paragraph) return paragraph;
|
|
16019
16087
|
this._buildTableBounds();
|
|
16020
16088
|
this._buildTableCellsForDocumentRange(index, index);
|
|
16021
16089
|
let tableParagraph = this._tableParagraphBoundsByIndex.get(index);
|
|
@@ -16027,9 +16095,6 @@ let DocEventManagerService = class DocEventManagerService extends _univerjs_core
|
|
|
16027
16095
|
if (tableParagraph) return tableParagraph;
|
|
16028
16096
|
}
|
|
16029
16097
|
if (tableParagraph) return tableParagraph;
|
|
16030
|
-
this._buildParagraphBounds();
|
|
16031
|
-
const paragraph = this._paragraphBounds.get(index);
|
|
16032
|
-
if (paragraph) return paragraph;
|
|
16033
16098
|
}
|
|
16034
16099
|
findParagraphBoundsInRange(startIndex, endIndex) {
|
|
16035
16100
|
this._buildTableBounds();
|
|
@@ -20745,10 +20810,30 @@ function DocFooter() {
|
|
|
20745
20810
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocFooterContent, {});
|
|
20746
20811
|
}
|
|
20747
20812
|
|
|
20813
|
+
//#endregion
|
|
20814
|
+
//#region src/views/doc-side-menu-layout.ts
|
|
20815
|
+
function isDocSideMenuTableOverlapping(outline, table, viewport) {
|
|
20816
|
+
if (table.bottom <= outline.top || table.top >= outline.bottom) return false;
|
|
20817
|
+
let left = table.left;
|
|
20818
|
+
let right = table.right;
|
|
20819
|
+
if (viewport && (viewport.leadingInsetLeft ?? 0) + viewport.contentWidth + (viewport.trailingInsetRight ?? 0) > viewport.viewportWidth) {
|
|
20820
|
+
const clipLeft = viewport.viewportLeft ?? table.left - (viewport.leadingInsetLeft ?? 0);
|
|
20821
|
+
left = Math.max(clipLeft, table.left - viewport.scrollLeft);
|
|
20822
|
+
right = Math.min(clipLeft + viewport.viewportWidth, table.left + viewport.contentWidth - viewport.scrollLeft);
|
|
20823
|
+
}
|
|
20824
|
+
return right > left && left < outline.right && right > outline.left;
|
|
20825
|
+
}
|
|
20826
|
+
|
|
20748
20827
|
//#endregion
|
|
20749
20828
|
//#region src/views/SideMenu.tsx
|
|
20750
20829
|
const SideMenu = (0, react.forwardRef)((props, ref) => {
|
|
20751
|
-
const { label, menus, onClick, className, style, mode, maxHeight, activeId, open, onOpenChange, maxWidth, wrapperClass, wrapperStyle, iconClass, iconStyle } = props;
|
|
20830
|
+
const { label, menus, onClick, className, style, mode = "side-bar", maxHeight, activeId, open: controlledOpen, onOpenChange, maxWidth, wrapperClass, wrapperStyle, iconClass, iconStyle } = props;
|
|
20831
|
+
const [expanded, setExpanded] = (0, react.useState)(mode === "side-bar");
|
|
20832
|
+
const open = controlledOpen ?? expanded;
|
|
20833
|
+
const handleOpenChange = (0, react.useCallback)((nextOpen) => {
|
|
20834
|
+
if (controlledOpen === void 0) setExpanded(nextOpen);
|
|
20835
|
+
onOpenChange === null || onOpenChange === void 0 || onOpenChange(nextOpen);
|
|
20836
|
+
}, [controlledOpen, onOpenChange]);
|
|
20752
20837
|
const panelId = (0, react.useId)();
|
|
20753
20838
|
const wrapperRef = (0, react.useRef)(null);
|
|
20754
20839
|
const containerRef = (0, react.useRef)(null);
|
|
@@ -20776,13 +20861,13 @@ const SideMenu = (0, react.forwardRef)((props, ref) => {
|
|
|
20776
20861
|
if (!open || mode !== "float") return;
|
|
20777
20862
|
const handlePointerDown = (event) => {
|
|
20778
20863
|
var _wrapperRef$current;
|
|
20779
|
-
if (event.target instanceof Node && !((_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : _wrapperRef$current.contains(event.target)))
|
|
20864
|
+
if (event.target instanceof Node && !((_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : _wrapperRef$current.contains(event.target))) handleOpenChange(false);
|
|
20780
20865
|
};
|
|
20781
20866
|
document.addEventListener("pointerdown", handlePointerDown);
|
|
20782
20867
|
return () => document.removeEventListener("pointerdown", handlePointerDown);
|
|
20783
20868
|
}, [
|
|
20869
|
+
handleOpenChange,
|
|
20784
20870
|
mode,
|
|
20785
|
-
onOpenChange,
|
|
20786
20871
|
open
|
|
20787
20872
|
]);
|
|
20788
20873
|
const handleKeyDown = (event) => {
|
|
@@ -20791,7 +20876,7 @@ const SideMenu = (0, react.forwardRef)((props, ref) => {
|
|
|
20791
20876
|
var _toggleRef$current;
|
|
20792
20877
|
event.preventDefault();
|
|
20793
20878
|
event.stopPropagation();
|
|
20794
|
-
|
|
20879
|
+
handleOpenChange(false);
|
|
20795
20880
|
(_toggleRef$current = toggleRef.current) === null || _toggleRef$current === void 0 || _toggleRef$current.focus();
|
|
20796
20881
|
return;
|
|
20797
20882
|
}
|
|
@@ -20820,51 +20905,47 @@ const SideMenu = (0, react.forwardRef)((props, ref) => {
|
|
|
20820
20905
|
};
|
|
20821
20906
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
20822
20907
|
ref: wrapperRef,
|
|
20823
|
-
className: (0, _univerjs_design.clsx)("univer-relative univer-
|
|
20908
|
+
className: (0, _univerjs_design.clsx)("univer-relative univer-ms-4", wrapperClass),
|
|
20824
20909
|
style: {
|
|
20825
|
-
width,
|
|
20910
|
+
width: open ? width : 32,
|
|
20826
20911
|
...wrapperStyle
|
|
20827
20912
|
},
|
|
20828
20913
|
onKeyDown: handleKeyDown,
|
|
20829
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
20914
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
20830
20915
|
ref: toggleRef,
|
|
20831
20916
|
type: "button",
|
|
20917
|
+
variant: "ghost",
|
|
20918
|
+
size: "icon",
|
|
20832
20919
|
"aria-label": label,
|
|
20833
20920
|
"aria-expanded": !!open,
|
|
20834
20921
|
"aria-controls": open ? panelId : void 0,
|
|
20835
20922
|
title: label,
|
|
20836
|
-
onClick: () =>
|
|
20837
|
-
className: (0, _univerjs_design.clsx)("univer-absolute univer-
|
|
20838
|
-
style:
|
|
20839
|
-
|
|
20840
|
-
|
|
20841
|
-
|
|
20842
|
-
|
|
20843
|
-
|
|
20923
|
+
onClick: () => handleOpenChange(!open),
|
|
20924
|
+
className: (0, _univerjs_design.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),
|
|
20925
|
+
style: iconStyle,
|
|
20926
|
+
children: open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreLeftIcon, {
|
|
20927
|
+
"aria-hidden": "true",
|
|
20928
|
+
className: "!univer-size-6"
|
|
20929
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CatalogueIcon, {
|
|
20930
|
+
"aria-hidden": "true",
|
|
20931
|
+
className: "!univer-size-5"
|
|
20932
|
+
})
|
|
20933
|
+
}), open && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("nav", {
|
|
20844
20934
|
id: panelId,
|
|
20845
20935
|
"aria-label": label,
|
|
20846
|
-
className: (0, _univerjs_design.clsx)("univer-box-border univer-flex univer-w-full univer-flex-col univer-overflow-hidden univer-
|
|
20936
|
+
className: (0, _univerjs_design.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),
|
|
20847
20937
|
style: {
|
|
20848
20938
|
maxHeight,
|
|
20849
20939
|
...style
|
|
20850
20940
|
},
|
|
20851
|
-
children:
|
|
20852
|
-
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",
|
|
20853
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CatalogueIcon, {
|
|
20854
|
-
"aria-hidden": "true",
|
|
20855
|
-
className: "univer-shrink-0 univer-text-sm"
|
|
20856
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
20857
|
-
className: "univer-truncate",
|
|
20858
|
-
children: label
|
|
20859
|
-
})]
|
|
20860
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
20941
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
20861
20942
|
ref: containerRef,
|
|
20862
|
-
className: (0, _univerjs_design.clsx)("univer-relative univer-min-h-0 univer-overflow-y-auto univer-overscroll-contain univer-
|
|
20943
|
+
className: (0, _univerjs_design.clsx)("univer-relative univer-min-h-0 univer-overflow-y-auto univer-overscroll-contain univer-pb-2", _univerjs_design.scrollbarClassName),
|
|
20863
20944
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ol", {
|
|
20864
20945
|
className: "univer-m-0 univer-list-none univer-p-0",
|
|
20865
20946
|
children: menus === null || menus === void 0 ? void 0 : menus.map((menu) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
|
|
20866
|
-
className: menu.isTitle ? "univer-mb-
|
|
20867
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.
|
|
20947
|
+
className: menu.isTitle ? "univer-mb-2" : void 0,
|
|
20948
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
20868
20949
|
ref: (element) => {
|
|
20869
20950
|
if (element) itemsRef.current.set(menu.id, element);
|
|
20870
20951
|
else itemsRef.current.delete(menu.id);
|
|
@@ -20872,39 +20953,28 @@ const SideMenu = (0, react.forwardRef)((props, ref) => {
|
|
|
20872
20953
|
type: "button",
|
|
20873
20954
|
"aria-current": menu.id === activeId ? "location" : void 0,
|
|
20874
20955
|
title: menu.text,
|
|
20875
|
-
className: (0, _univerjs_design.clsx)("univer-
|
|
20876
|
-
"univer-
|
|
20877
|
-
"univer-text-gray-900 dark:univer-text-gray-100": menu.isTitle && menu.id !== activeId,
|
|
20878
|
-
"univer-text-gray-
|
|
20956
|
+
className: (0, _univerjs_design.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", {
|
|
20957
|
+
"univer-text-primary-600 dark:univer-text-primary-400": menu.id === activeId,
|
|
20958
|
+
"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,
|
|
20959
|
+
"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
|
|
20879
20960
|
}),
|
|
20880
|
-
style: {
|
|
20961
|
+
style: { paddingInlineStart: menu.isTitle ? 0 : 12 + Math.max(0, menu.level - 1) * 12 },
|
|
20881
20962
|
onClick: () => {
|
|
20882
20963
|
onClick === null || onClick === void 0 || onClick(menu);
|
|
20883
20964
|
if (mode === "float") {
|
|
20884
20965
|
var _toggleRef$current2;
|
|
20885
|
-
|
|
20966
|
+
handleOpenChange(false);
|
|
20886
20967
|
(_toggleRef$current2 = toggleRef.current) === null || _toggleRef$current2 === void 0 || _toggleRef$current2.focus();
|
|
20887
20968
|
}
|
|
20888
20969
|
},
|
|
20889
|
-
children:
|
|
20890
|
-
menu.
|
|
20891
|
-
|
|
20892
|
-
|
|
20893
|
-
style: { left: 14 + Math.max(0, menu.level - 2) * 12 }
|
|
20894
|
-
}),
|
|
20895
|
-
menu.id === activeId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
20896
|
-
"aria-hidden": "true",
|
|
20897
|
-
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"
|
|
20898
|
-
}),
|
|
20899
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
20900
|
-
className: menu.isTitle ? "univer-line-clamp-2 univer-break-words" : "univer-truncate",
|
|
20901
|
-
children: menu.text
|
|
20902
|
-
})
|
|
20903
|
-
]
|
|
20970
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
20971
|
+
className: menu.isTitle ? "univer-line-clamp-2 univer-break-words" : "univer-truncate",
|
|
20972
|
+
children: menu.text
|
|
20973
|
+
})
|
|
20904
20974
|
})
|
|
20905
20975
|
}, menu.id))
|
|
20906
20976
|
})
|
|
20907
|
-
})
|
|
20977
|
+
})
|
|
20908
20978
|
})]
|
|
20909
20979
|
});
|
|
20910
20980
|
});
|
|
@@ -20926,52 +20996,77 @@ function findActiveHeading(boundMap, paragraphMap, scrollTop, bottom) {
|
|
|
20926
20996
|
if (!boundMap) return;
|
|
20927
20997
|
const paragraphBounds = Array.from(boundMap.values());
|
|
20928
20998
|
const paragraphIndex = paragraphBounds.findIndex((p) => p.paragraphStart !== p.paragraphEnd && p.rect.top < bottom && p.rect.bottom > scrollTop);
|
|
20929
|
-
if (paragraphIndex === -1) return
|
|
20930
|
-
|
|
20999
|
+
if (paragraphIndex === -1) return;
|
|
21000
|
+
let lastParagraphIndex = paragraphBounds.length - 1;
|
|
21001
|
+
while (lastParagraphIndex > paragraphIndex) {
|
|
21002
|
+
const bound = paragraphBounds[lastParagraphIndex];
|
|
21003
|
+
if (bound.paragraphStart !== bound.paragraphEnd && bound.rect.top < bottom && bound.rect.bottom > scrollTop) break;
|
|
21004
|
+
lastParagraphIndex--;
|
|
21005
|
+
}
|
|
20931
21006
|
for (let i = paragraphIndex; i <= lastParagraphIndex; i++) {
|
|
20932
|
-
var _paragraph$paragraphS;
|
|
20933
21007
|
const bound = paragraphBounds[i];
|
|
20934
21008
|
const paragraph = paragraphMap.get(bound.startIndex);
|
|
20935
|
-
if (paragraph
|
|
21009
|
+
if (paragraph) return paragraph.paragraphId;
|
|
20936
21010
|
}
|
|
20937
21011
|
for (let i = paragraphIndex; i >= 0; i--) {
|
|
20938
|
-
var _paragraph$paragraphS2;
|
|
20939
21012
|
const bound = paragraphBounds[i];
|
|
20940
21013
|
const paragraph = paragraphMap.get(bound.startIndex);
|
|
20941
|
-
if (paragraph
|
|
21014
|
+
if (paragraph) return paragraph.paragraphId;
|
|
20942
21015
|
}
|
|
20943
21016
|
}
|
|
20944
21017
|
const TITLE_ID = "__title";
|
|
20945
21018
|
function DocSideMenu() {
|
|
20946
21019
|
const config = (0, _univerjs_ui.useConfigValue)(DOCS_UI_PLUGIN_CONFIG_KEY);
|
|
20947
21020
|
const workbenchService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IWorkbenchService);
|
|
20948
|
-
if ((0, _univerjs_ui.useObservable)(workbenchService.rootUnitType$, null, true) === _univerjs_core.UniverInstanceType.UNIVER_DOC && (config === null || config === void 0 ? void 0 : config.toc)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocSideMenuContent, {});
|
|
21021
|
+
if ((0, _univerjs_ui.useObservable)(workbenchService.rootUnitType$, null, true) === _univerjs_core.UniverInstanceType.UNIVER_DOC && (config === null || config === void 0 ? void 0 : config.toc) !== false) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DocSideMenuContent, { toc: config === null || config === void 0 ? void 0 : config.toc });
|
|
20949
21022
|
return null;
|
|
20950
21023
|
}
|
|
20951
|
-
function DocSideMenuContent() {
|
|
20952
|
-
var _documentData$body, _documentData$body3;
|
|
21024
|
+
function DocSideMenuContent({ toc }) {
|
|
21025
|
+
var _currentDoc$getSnapsh, _documentData$body, _documentData$body3, _menus$find;
|
|
20953
21026
|
const instanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
|
|
20954
21027
|
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
20955
21028
|
const currentDoc = (0, _univerjs_ui.useObservable)(() => instanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC), void 0, false, [instanceService]);
|
|
21029
|
+
const enabled = toc ?? (currentDoc === null || currentDoc === void 0 || (_currentDoc$getSnapsh = currentDoc.getSnapshot().documentStyle) === null || _currentDoc$getSnapsh === void 0 ? void 0 : _currentDoc$getSnapsh.documentFlavor) === _univerjs_core.DocumentFlavor.MODERN;
|
|
20956
21030
|
const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
|
|
20957
21031
|
const documentData = (0, _univerjs_ui.useObservable)(currentDoc ? () => currentDoc.change$.pipe((0, rxjs.debounceTime)(100), (0, rxjs.map)(() => currentDoc.getSnapshot())) : null, currentDoc === null || currentDoc === void 0 ? void 0 : currentDoc.getSnapshot(), false, [currentDoc]);
|
|
20958
21032
|
const fullDataStream = (documentData === null || documentData === void 0 || (_documentData$body = documentData.body) === null || _documentData$body === void 0 ? void 0 : _documentData$body.dataStream) ?? "";
|
|
20959
21033
|
const [activeId, setActiveId] = (0, react.useState)(void 0);
|
|
21034
|
+
const [outlineHeight, setOutlineHeight] = (0, react.useState)(0);
|
|
21035
|
+
const containerRef = (0, react.useRef)(null);
|
|
20960
21036
|
const unitId = (currentDoc === null || currentDoc === void 0 ? void 0 : currentDoc.getUnitId()) ?? "";
|
|
20961
21037
|
const renderer = renderManagerService.getRenderUnitById(unitId);
|
|
20962
21038
|
const title = documentData === null || documentData === void 0 ? void 0 : documentData.title;
|
|
20963
21039
|
const docEventManagerService = renderer === null || renderer === void 0 ? void 0 : renderer.with(DocEventManagerService);
|
|
20964
|
-
const
|
|
21040
|
+
const viewport = renderer === null || renderer === void 0 ? void 0 : renderer.scene.getViewport("viewMain");
|
|
20965
21041
|
const readLayout = () => {
|
|
20966
21042
|
var _renderer$mainCompone;
|
|
21043
|
+
const scaleX = (renderer === null || renderer === void 0 ? void 0 : renderer.scene.scaleX) ?? 1;
|
|
21044
|
+
const scaleY = (renderer === null || renderer === void 0 ? void 0 : renderer.scene.scaleY) ?? 1;
|
|
21045
|
+
const scrollX = (viewport === null || viewport === void 0 ? void 0 : viewport.viewportScrollX) ?? 0;
|
|
21046
|
+
const scrollY = (viewport === null || viewport === void 0 ? void 0 : viewport.viewportScrollY) ?? 0;
|
|
21047
|
+
const canvasHeight = (renderer === null || renderer === void 0 ? void 0 : renderer.engine.height) ?? 0;
|
|
21048
|
+
const left = (((renderer === null || renderer === void 0 || (_renderer$mainCompone = renderer.mainComponent) === null || _renderer$mainCompone === void 0 ? void 0 : _renderer$mainCompone.left) ?? 0) - scrollX) * scaleX;
|
|
21049
|
+
const outlineRect = {
|
|
21050
|
+
left: scrollX + 16 / scaleX,
|
|
21051
|
+
right: scrollX + 272 / scaleX,
|
|
21052
|
+
top: scrollY + 16 / scaleY,
|
|
21053
|
+
bottom: scrollY + Math.min(canvasHeight - 16, 16 + outlineHeight) / scaleY
|
|
21054
|
+
};
|
|
21055
|
+
const overlapsTable = left >= 288 && outlineHeight > 0 && Array.from((docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.tableBounds.values()) ?? []).some(({ tableId, rect }) => isDocSideMenuTableOverlapping(outlineRect, rect, (0, _univerjs_engine_render.getDocsTableRenderViewport)(unitId, (0, _univerjs_engine_render.getTableIdAndSliceIndex)(tableId).tableId)));
|
|
20967
21056
|
return {
|
|
20968
|
-
left
|
|
20969
|
-
canvasHeight
|
|
21057
|
+
left,
|
|
21058
|
+
canvasHeight,
|
|
20970
21059
|
canvasWidth: (renderer === null || renderer === void 0 ? void 0 : renderer.engine.width) ?? 0,
|
|
20971
|
-
scaleY
|
|
21060
|
+
scaleY,
|
|
21061
|
+
overlapsTable
|
|
20972
21062
|
};
|
|
20973
21063
|
};
|
|
20974
|
-
const
|
|
21064
|
+
const layout = (0, _univerjs_ui.useObservable)((renderer === null || renderer === void 0 ? void 0 : renderer.engine.onTransformChange$) ? () => (0, rxjs.merge)((0, _univerjs_core.fromEventSubject)(renderer.engine.onTransformChange$), (0, _univerjs_core.fromEventSubject)(renderer.scene.onTransformChange$), ...renderer.mainComponent instanceof _univerjs_engine_render.Documents ? [renderer.mainComponent.pageRender$] : [], ...viewport ? [(0, _univerjs_core.fromEventSubject)(viewport.onScrollAfter$)] : [], ...renderer.mainComponent ? [(0, _univerjs_core.fromEventSubject)(renderer.mainComponent.onTransformChange$)] : []).pipe((0, rxjs.auditTime)(33), (0, rxjs.map)(readLayout), (0, rxjs.startWith)(readLayout()), (0, rxjs.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, [
|
|
21065
|
+
renderer,
|
|
21066
|
+
viewport,
|
|
21067
|
+
outlineHeight
|
|
21068
|
+
]);
|
|
21069
|
+
const { left, canvasHeight, canvasWidth, scaleY } = layout;
|
|
20975
21070
|
const paragraphs = (0, react.useMemo)(() => {
|
|
20976
21071
|
var _documentData$body2;
|
|
20977
21072
|
return (documentData === null || documentData === void 0 || (_documentData$body2 = documentData.body) === null || _documentData$body2 === void 0 ? void 0 : _documentData$body2.paragraphs) ?? [];
|
|
@@ -20980,22 +21075,26 @@ function DocSideMenuContent() {
|
|
|
20980
21075
|
dataStream: fullDataStream,
|
|
20981
21076
|
paragraphs
|
|
20982
21077
|
}), [fullDataStream, paragraphs]);
|
|
21078
|
+
const headingParagraphs = (0, react.useMemo)(() => paragraphs.filter((p) => {
|
|
21079
|
+
var _p$paragraphStyle;
|
|
21080
|
+
return ((_p$paragraphStyle = p.paragraphStyle) === null || _p$paragraphStyle === void 0 ? void 0 : _p$paragraphStyle.namedStyleType) !== void 0 && p.paragraphStyle.namedStyleType !== _univerjs_core.NamedStyleType.SUBTITLE && p.paragraphStyle.namedStyleType !== _univerjs_core.NamedStyleType.NORMAL_TEXT;
|
|
21081
|
+
}).map((p) => p.paragraphId ? p : {
|
|
21082
|
+
...p,
|
|
21083
|
+
paragraphId: `__paragraph_${p.startIndex}`
|
|
21084
|
+
}), [paragraphs]);
|
|
20983
21085
|
const paragraphMap = (0, react.useMemo)(() => {
|
|
20984
21086
|
const map = /* @__PURE__ */ new Map();
|
|
20985
|
-
|
|
21087
|
+
headingParagraphs.forEach((p) => {
|
|
20986
21088
|
map.set(p.startIndex, p);
|
|
20987
21089
|
});
|
|
20988
21090
|
return map;
|
|
20989
|
-
}, [
|
|
20990
|
-
const mode = left <
|
|
20991
|
-
const paragraphMenus =
|
|
20992
|
-
var _p$paragraphStyle;
|
|
20993
|
-
return ((_p$paragraphStyle = p.paragraphStyle) === null || _p$paragraphStyle === void 0 ? void 0 : _p$paragraphStyle.namedStyleType) !== void 0 && p.paragraphStyle.namedStyleType !== _univerjs_core.NamedStyleType.SUBTITLE && p.paragraphStyle.namedStyleType !== _univerjs_core.NamedStyleType.NORMAL_TEXT;
|
|
20994
|
-
}).map((p) => {
|
|
21091
|
+
}, [headingParagraphs]);
|
|
21092
|
+
const mode = left < 288 || layout.overlapsTable ? "float" : "side-bar";
|
|
21093
|
+
const paragraphMenus = headingParagraphs.map((p) => {
|
|
20995
21094
|
var _p$paragraphStyle2;
|
|
20996
21095
|
const level = transformNamedStyleTypeToLevel(p.paragraphStyle.namedStyleType);
|
|
20997
21096
|
return {
|
|
20998
|
-
id: p.
|
|
21097
|
+
id: p.paragraphId,
|
|
20999
21098
|
text: (0, _univerjs_core.getPlainText)(fullDataStream.slice(paragraphStarts.get(p.startIndex), p.startIndex)),
|
|
21000
21099
|
level,
|
|
21001
21100
|
isTitle: ((_p$paragraphStyle2 = p.paragraphStyle) === null || _p$paragraphStyle2 === void 0 ? void 0 : _p$paragraphStyle2.namedStyleType) === _univerjs_core.NamedStyleType.TITLE
|
|
@@ -21004,7 +21103,7 @@ function DocSideMenuContent() {
|
|
|
21004
21103
|
const handleScroll = (0, _univerjs_ui.useEvent)((params) => {
|
|
21005
21104
|
const scrollTop = params.viewportScrollY;
|
|
21006
21105
|
const bottom = scrollTop + canvasHeight / scaleY;
|
|
21007
|
-
const activeId = findActiveHeading(paragraphBounds, paragraphMap, scrollTop, bottom);
|
|
21106
|
+
const activeId = findActiveHeading(docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.paragraphBounds, paragraphMap, scrollTop, bottom);
|
|
21008
21107
|
if (activeId) setActiveId(activeId);
|
|
21009
21108
|
});
|
|
21010
21109
|
const menus = (paragraphMenus === null || paragraphMenus === void 0 ? void 0 : paragraphMenus.find((p) => p.isTitle)) ? paragraphMenus : [...title ? [{
|
|
@@ -21013,7 +21112,32 @@ function DocSideMenuContent() {
|
|
|
21013
21112
|
level: 1,
|
|
21014
21113
|
isTitle: true
|
|
21015
21114
|
}] : [], ...paragraphMenus ?? []].filter(Boolean);
|
|
21016
|
-
const
|
|
21115
|
+
const outlineTitle = (_menus$find = menus.find((menu) => menu.isTitle)) === null || _menus$find === void 0 ? void 0 : _menus$find.text;
|
|
21116
|
+
(0, react.useLayoutEffect)(() => {
|
|
21117
|
+
setOutlineHeight(0);
|
|
21118
|
+
}, [
|
|
21119
|
+
unitId,
|
|
21120
|
+
menus.length,
|
|
21121
|
+
outlineTitle
|
|
21122
|
+
]);
|
|
21123
|
+
(0, react.useLayoutEffect)(() => {
|
|
21124
|
+
const container = containerRef.current;
|
|
21125
|
+
const menu = container === null || container === void 0 ? void 0 : container.firstElementChild;
|
|
21126
|
+
if (!container || !menu) return;
|
|
21127
|
+
const measureOutline = () => {
|
|
21128
|
+
var _container$querySelec;
|
|
21129
|
+
const height = (_container$querySelec = container.querySelector("nav")) === null || _container$querySelec === void 0 ? void 0 : _container$querySelec.getBoundingClientRect().height;
|
|
21130
|
+
if (height) setOutlineHeight(height);
|
|
21131
|
+
};
|
|
21132
|
+
const observer = new ResizeObserver(measureOutline);
|
|
21133
|
+
observer.observe(menu);
|
|
21134
|
+
return () => observer.disconnect();
|
|
21135
|
+
}, [
|
|
21136
|
+
mode,
|
|
21137
|
+
unitId,
|
|
21138
|
+
menus.length,
|
|
21139
|
+
enabled
|
|
21140
|
+
]);
|
|
21017
21141
|
(0, react.useEffect)(() => {
|
|
21018
21142
|
const viewport = renderer === null || renderer === void 0 ? void 0 : renderer.scene.getViewport("viewMain");
|
|
21019
21143
|
if (!viewport) return;
|
|
@@ -21030,31 +21154,27 @@ function DocSideMenuContent() {
|
|
|
21030
21154
|
setActiveId(menu.id);
|
|
21031
21155
|
return;
|
|
21032
21156
|
}
|
|
21033
|
-
const paragraph =
|
|
21034
|
-
var _p$paragraphStyle3;
|
|
21035
|
-
return ((_p$paragraphStyle3 = p.paragraphStyle) === null || _p$paragraphStyle3 === void 0 ? void 0 : _p$paragraphStyle3.headingId) === menu.id;
|
|
21036
|
-
});
|
|
21157
|
+
const paragraph = headingParagraphs.find((p) => p.paragraphId === menu.id);
|
|
21037
21158
|
if (!paragraph) return;
|
|
21038
|
-
const bound =
|
|
21159
|
+
const bound = docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.paragraphBounds.get(paragraph.startIndex);
|
|
21039
21160
|
if (!bound) return;
|
|
21040
21161
|
viewport.scrollToViewportPos({ viewportScrollY: bound.rect.top });
|
|
21041
21162
|
setActiveId(menu.id);
|
|
21042
21163
|
});
|
|
21043
|
-
if (!currentDoc || (0, _univerjs_core.isInternalEditorID)(unitId) || !(menus === null || menus === void 0 ? void 0 : menus.length)) return null;
|
|
21164
|
+
if (!enabled || !currentDoc || (0, _univerjs_core.isInternalEditorID)(unitId) || !(menus === null || menus === void 0 ? void 0 : menus.length)) return null;
|
|
21044
21165
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
21166
|
+
ref: containerRef,
|
|
21045
21167
|
className: "univer-absolute univer-bottom-0 univer-left-0 univer-top-0 univer-z-[100] univer-w-[0px]",
|
|
21046
21168
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SideMenu, {
|
|
21047
21169
|
label: localeService.t("docs-ui.outline.title"),
|
|
21048
21170
|
menus,
|
|
21049
|
-
open,
|
|
21050
|
-
onOpenChange: setOpen,
|
|
21051
21171
|
mode,
|
|
21052
21172
|
maxWidth: Math.max(0, Math.floor(mode === "float" ? canvasWidth : left) - 24),
|
|
21053
21173
|
wrapperClass: "univer-mt-4",
|
|
21054
21174
|
activeId,
|
|
21055
21175
|
onClick: handleClick,
|
|
21056
21176
|
maxHeight: Math.max(0, canvasHeight - 32)
|
|
21057
|
-
})
|
|
21177
|
+
}, mode)
|
|
21058
21178
|
});
|
|
21059
21179
|
}
|
|
21060
21180
|
|
|
@@ -21432,7 +21552,7 @@ function resolveDocsCustomBlockRenderViewport(params) {
|
|
|
21432
21552
|
//#endregion
|
|
21433
21553
|
//#region package.json
|
|
21434
21554
|
var name = "@univerjs/docs-ui";
|
|
21435
|
-
var version = "1.
|
|
21555
|
+
var version = "1.2.0";
|
|
21436
21556
|
|
|
21437
21557
|
//#endregion
|
|
21438
21558
|
//#region src/commands/commands/doc-paragraph-setting.command.ts
|
|
@@ -22294,7 +22414,7 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
|
|
|
22294
22414
|
}
|
|
22295
22415
|
_deferUnmaterializedCursorMove(doc, skeleton, offset, segmentId, resume) {
|
|
22296
22416
|
var _skeleton$getSkeleton, _render$getInjector, _doc$getBody;
|
|
22297
|
-
if (segmentId !== "") return false;
|
|
22417
|
+
if (segmentId !== "" || skeleton.getViewModel().getCollapsedHeadingAtOffset(offset)) return false;
|
|
22298
22418
|
const pageIndex = skeleton.findBodyPageIndexByCharIndex(offset);
|
|
22299
22419
|
const page = (_skeleton$getSkeleton = skeleton.getSkeletonData()) === null || _skeleton$getSkeleton === void 0 ? void 0 : _skeleton$getSkeleton.pages[pageIndex];
|
|
22300
22420
|
if (pageIndex >= 0 && !(page === null || page === void 0 ? void 0 : page.isMaterializationPlaceholder)) return false;
|
|
@@ -22403,6 +22523,13 @@ let DocMoveCursorController = class DocMoveCursorController extends _univerjs_co
|
|
|
22403
22523
|
const visited = /* @__PURE__ */ new Set();
|
|
22404
22524
|
while (current >= 0 && current < dataStream.length && !visited.has(current)) {
|
|
22405
22525
|
visited.add(current);
|
|
22526
|
+
if (!segmentId) {
|
|
22527
|
+
const hidden = skeleton.getViewModel().getCollapsedHeadingAtOffset(current);
|
|
22528
|
+
if (hidden) {
|
|
22529
|
+
current = step < 0 ? hidden.paragraphIndex : hidden.endOffset;
|
|
22530
|
+
continue;
|
|
22531
|
+
}
|
|
22532
|
+
}
|
|
22406
22533
|
const normalizedCursor = this._normalizeCursorOffset(dataStream, customRanges, current, direction);
|
|
22407
22534
|
if (normalizedCursor < 0 || normalizedCursor >= dataStream.length) return;
|
|
22408
22535
|
if (this._isRenderableCursorOffset(skeleton, dataStream, normalizedCursor, segmentId, segmentPage)) return normalizedCursor;
|
|
@@ -28669,10 +28796,16 @@ let DocParagraphMenuService = class DocParagraphMenuService extends _univerjs_co
|
|
|
28669
28796
|
const targetParagraph = target.paragraph ?? paragraph;
|
|
28670
28797
|
const blockRange = target.blockRange;
|
|
28671
28798
|
const getFirstLine = () => {
|
|
28799
|
+
var _this$_context$unit$g;
|
|
28672
28800
|
const latestParagraphBound = this._docEventManagerService.findParagraphBoundByIndex(targetParagraph.startIndex) ?? targetParagraph;
|
|
28673
28801
|
const baseAnchor = blockRange ? getBlockRangeAnchorRect(this._docEventManagerService, blockRange, paragraph) : latestParagraphBound.firstLine ?? paragraph.firstLine;
|
|
28674
|
-
|
|
28675
|
-
|
|
28802
|
+
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) === _univerjs_core.DocumentFlavor.MODERN && this._docSkeletonManagerService.getViewModel().getHeadingSections().some((heading) => heading.paragraphIndex === targetParagraph.startIndex && heading.startOffset < heading.endOffset) ? {
|
|
28803
|
+
...baseAnchor,
|
|
28804
|
+
left: baseAnchor.left - 24,
|
|
28805
|
+
right: baseAnchor.right - 24
|
|
28806
|
+
} : baseAnchor;
|
|
28807
|
+
if (!target.cellRange) return menuAnchor;
|
|
28808
|
+
return getTableCellParagraphAnchorRect(this._docEventManagerService, latestParagraphBound, menuAnchor);
|
|
28676
28809
|
};
|
|
28677
28810
|
const disposable = this._docPopupManagerService.attachPopupToRect(getFirstLine, {
|
|
28678
28811
|
componentKey: DOC_PARAGRAPH_MENU_COMPONENT_KEY,
|
|
@@ -29677,6 +29810,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
|
|
|
29677
29810
|
}, [doc, startIndex]);
|
|
29678
29811
|
const isEmptyParagraph = (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.emptyMode) ?? isEmptyParagraphMenuTarget(dataStream, activeParagraphBound);
|
|
29679
29812
|
const namedStyleType = paragraphObj === null || paragraphObj === void 0 || (_paragraphObj$paragra = paragraphObj.paragraphStyle) === null || _paragraphObj$paragra === void 0 ? void 0 : _paragraphObj$paragra.namedStyleType;
|
|
29813
|
+
const isModernHeading = (doc === null || doc === void 0 ? void 0 : doc.getDocumentStyle().documentFlavor) === _univerjs_core.DocumentFlavor.MODERN && startIndex != null && (renderUnit === null || renderUnit === void 0 ? void 0 : renderUnit.with(_univerjs_docs.DocSkeletonManagerService).getViewModel().getHeadingSections().some((heading) => heading.paragraphIndex === startIndex && heading.startOffset < heading.endOffset));
|
|
29680
29814
|
const targetIconKey = (currentActiveTarget === null || currentActiveTarget === void 0 ? void 0 : currentActiveTarget.icon) ?? getParagraphMenuTriggerIconKey(namedStyleType);
|
|
29681
29815
|
const TargetIcon = iconManager.get(targetIconKey);
|
|
29682
29816
|
const paragraphMenuType = (0, react.useMemo)(() => getParagraphMenuType(currentActiveTarget, isEmptyParagraph), [currentActiveTarget, isEmptyParagraph]);
|
|
@@ -29972,7 +30106,10 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }) {
|
|
|
29972
30106
|
"data-u-table-menu": tableBlockOnly ? "true" : void 0,
|
|
29973
30107
|
"data-u-focused-table-menu": isFocusedTableMenu ? "true" : void 0,
|
|
29974
30108
|
ref: anchorRef,
|
|
29975
|
-
className: (0, _univerjs_design.clsx)("univer-
|
|
30109
|
+
className: (0, _univerjs_design.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", {
|
|
30110
|
+
"univer-mr-1": !isModernHeading,
|
|
30111
|
+
"univer-bg-gray-100 univer-shadow-md dark:!univer-bg-gray-800": visible
|
|
30112
|
+
}),
|
|
29976
30113
|
onMouseEnter: (e) => {
|
|
29977
30114
|
var _popup$onPointerEnter;
|
|
29978
30115
|
(_popup$onPointerEnter = popup.onPointerEnter) === null || _popup$onPointerEnter === void 0 || _popup$onPointerEnter.call(popup, e);
|
|
@@ -30832,6 +30969,289 @@ let DocContextualRibbonService = class DocContextualRibbonService extends _unive
|
|
|
30832
30969
|
};
|
|
30833
30970
|
DocContextualRibbonService = __decorate([__decorateParam(0, _univerjs_ui.IRibbonService)], DocContextualRibbonService);
|
|
30834
30971
|
|
|
30972
|
+
//#endregion
|
|
30973
|
+
//#region src/views/heading-collapse-shape.ts
|
|
30974
|
+
var HeadingCollapseShape = class extends _univerjs_engine_render.Shape {
|
|
30975
|
+
constructor(key, colors, activate) {
|
|
30976
|
+
super(key, {
|
|
30977
|
+
width: 24,
|
|
30978
|
+
height: 28,
|
|
30979
|
+
debounceParentDirty: false
|
|
30980
|
+
});
|
|
30981
|
+
_defineProperty(this, "_collapsed", false);
|
|
30982
|
+
_defineProperty(this, "_label", "");
|
|
30983
|
+
_defineProperty(this, "_colors", void 0);
|
|
30984
|
+
_defineProperty(this, "_hovered", false);
|
|
30985
|
+
_defineProperty(this, "_tooltipVisible", false);
|
|
30986
|
+
_defineProperty(this, "_tooltipTimer", null);
|
|
30987
|
+
_defineProperty(this, "_pressed", false);
|
|
30988
|
+
this._colors = colors;
|
|
30989
|
+
this.cursor = _univerjs_engine_render.CURSOR_TYPE.POINTER;
|
|
30990
|
+
this.disposeWithMe(this.onPointerEnter$.subscribeEvent((event) => {
|
|
30991
|
+
if (this._hovered || event.buttons) return;
|
|
30992
|
+
this._hovered = true;
|
|
30993
|
+
this._tooltipTimer = setTimeout(() => {
|
|
30994
|
+
this._tooltipTimer = null;
|
|
30995
|
+
this._tooltipVisible = true;
|
|
30996
|
+
this.makeDirty(true);
|
|
30997
|
+
}, 500);
|
|
30998
|
+
this.makeDirty(true);
|
|
30999
|
+
}));
|
|
31000
|
+
this.disposeWithMe(this.onPointerLeave$.subscribeEvent(() => this.resetHover()));
|
|
31001
|
+
this.disposeWithMe(this.onPointerDown$.subscribeEvent((event, state) => {
|
|
31002
|
+
state.stopPropagation();
|
|
31003
|
+
event.preventDefault();
|
|
31004
|
+
this._pressed = event.button === 0;
|
|
31005
|
+
}));
|
|
31006
|
+
this.disposeWithMe(this.onPointerUp$.subscribeEvent((event, state) => {
|
|
31007
|
+
state.stopPropagation();
|
|
31008
|
+
event.preventDefault();
|
|
31009
|
+
const activateButton = this._pressed && event.button === 0;
|
|
31010
|
+
this._pressed = false;
|
|
31011
|
+
this._hideTooltip();
|
|
31012
|
+
if (activateButton) activate();
|
|
31013
|
+
}));
|
|
31014
|
+
this.disposeWithMe(this.onClick$.subscribeEvent((_event, state) => state.stopPropagation()));
|
|
31015
|
+
this.disposeWithMe(this.onDblclick$.subscribeEvent((_event, state) => state.stopPropagation()));
|
|
31016
|
+
}
|
|
31017
|
+
update(collapsed, label, colors) {
|
|
31018
|
+
if (collapsed === this._collapsed && label === this._label && colors === this._colors) return;
|
|
31019
|
+
this._collapsed = collapsed;
|
|
31020
|
+
this._label = label;
|
|
31021
|
+
this._colors = colors;
|
|
31022
|
+
this.makeDirty(true);
|
|
31023
|
+
}
|
|
31024
|
+
resetHover() {
|
|
31025
|
+
this._hideTooltip();
|
|
31026
|
+
this._pressed = false;
|
|
31027
|
+
if (this._hovered) {
|
|
31028
|
+
this._hovered = false;
|
|
31029
|
+
this.makeDirty(true);
|
|
31030
|
+
}
|
|
31031
|
+
}
|
|
31032
|
+
_hideTooltip() {
|
|
31033
|
+
if (this._tooltipTimer !== null) {
|
|
31034
|
+
clearTimeout(this._tooltipTimer);
|
|
31035
|
+
this._tooltipTimer = null;
|
|
31036
|
+
}
|
|
31037
|
+
if (this._tooltipVisible) {
|
|
31038
|
+
this._tooltipVisible = false;
|
|
31039
|
+
this.makeDirty(true);
|
|
31040
|
+
}
|
|
31041
|
+
}
|
|
31042
|
+
_draw(ctx, bounds) {
|
|
31043
|
+
ctx.fillStyle = this._hovered ? this._colors.hover : this._colors.normal;
|
|
31044
|
+
ctx.beginPath();
|
|
31045
|
+
if (this._collapsed) {
|
|
31046
|
+
ctx.moveTo(9, 8);
|
|
31047
|
+
ctx.lineTo(16, 14);
|
|
31048
|
+
ctx.lineTo(9, 20);
|
|
31049
|
+
} else {
|
|
31050
|
+
ctx.moveTo(6, 11);
|
|
31051
|
+
ctx.lineTo(18, 11);
|
|
31052
|
+
ctx.lineTo(12, 18);
|
|
31053
|
+
}
|
|
31054
|
+
ctx.closePath();
|
|
31055
|
+
ctx.fill();
|
|
31056
|
+
if (!this._tooltipVisible) return;
|
|
31057
|
+
ctx.save();
|
|
31058
|
+
ctx.font = "12px sans-serif";
|
|
31059
|
+
const width = ctx.measureText(this._label).width + 20;
|
|
31060
|
+
const viewport = bounds === null || bounds === void 0 ? void 0 : bounds.viewBound;
|
|
31061
|
+
const centeredLeft = (this.width - width) / 2;
|
|
31062
|
+
const left = viewport ? Math.max(viewport.left - this.left, Math.min(centeredLeft, viewport.right - this.left - width)) : centeredLeft;
|
|
31063
|
+
const below = viewport != null && this.top - 36 < viewport.top;
|
|
31064
|
+
ctx.translate(left, below ? this.height + 8 : -36);
|
|
31065
|
+
_univerjs_engine_render.Rect.drawWith(ctx, {
|
|
31066
|
+
width,
|
|
31067
|
+
height: 28,
|
|
31068
|
+
radius: 6,
|
|
31069
|
+
fill: this._colors.tooltipBackground
|
|
31070
|
+
});
|
|
31071
|
+
ctx.fillStyle = this._colors.tooltipBackground;
|
|
31072
|
+
ctx.beginPath();
|
|
31073
|
+
const arrow = this.width / 2 - left;
|
|
31074
|
+
const arrowBase = below ? 0 : 28;
|
|
31075
|
+
ctx.moveTo(arrow - 4, arrowBase);
|
|
31076
|
+
ctx.lineTo(arrow, below ? -4 : 32);
|
|
31077
|
+
ctx.lineTo(arrow + 4, arrowBase);
|
|
31078
|
+
ctx.fill();
|
|
31079
|
+
ctx.fillStyle = this._colors.tooltipText;
|
|
31080
|
+
ctx.textAlign = "center";
|
|
31081
|
+
ctx.textBaseline = "middle";
|
|
31082
|
+
ctx.fillText(this._label, width / 2, 14);
|
|
31083
|
+
ctx.restore();
|
|
31084
|
+
}
|
|
31085
|
+
dispose() {
|
|
31086
|
+
this.resetHover();
|
|
31087
|
+
super.dispose();
|
|
31088
|
+
}
|
|
31089
|
+
};
|
|
31090
|
+
|
|
31091
|
+
//#endregion
|
|
31092
|
+
//#region src/services/doc-heading-collapse.service.ts
|
|
31093
|
+
let DocHeadingCollapseService = class DocHeadingCollapseService extends _univerjs_core.Disposable {
|
|
31094
|
+
constructor(_context, _skeletonManager, _eventManager, _selections, _commandService, _layoutService, themeService, localeService) {
|
|
31095
|
+
super();
|
|
31096
|
+
this._context = _context;
|
|
31097
|
+
this._skeletonManager = _skeletonManager;
|
|
31098
|
+
this._eventManager = _eventManager;
|
|
31099
|
+
this._selections = _selections;
|
|
31100
|
+
this._commandService = _commandService;
|
|
31101
|
+
this._layoutService = _layoutService;
|
|
31102
|
+
_defineProperty(this, "_buttons", /* @__PURE__ */ new Map());
|
|
31103
|
+
_defineProperty(this, "_colors", void 0);
|
|
31104
|
+
_defineProperty(this, "_expandLabel", "");
|
|
31105
|
+
_defineProperty(this, "_collapseLabel", "");
|
|
31106
|
+
this._colors = this._getColors(themeService);
|
|
31107
|
+
if ((0, _univerjs_core.isInternalEditorID)(_context.unitId)) return;
|
|
31108
|
+
this.disposeWithMe(themeService.currentTheme$.subscribe(() => {
|
|
31109
|
+
this._colors = this._getColors(themeService);
|
|
31110
|
+
this._update();
|
|
31111
|
+
}));
|
|
31112
|
+
this.disposeWithMe(localeService.currentLocale$.subscribe(() => {
|
|
31113
|
+
this._expandLabel = localeService.t("docs-ui.heading.expand");
|
|
31114
|
+
this._collapseLabel = localeService.t("docs-ui.heading.collapse");
|
|
31115
|
+
this._update();
|
|
31116
|
+
}));
|
|
31117
|
+
this.disposeWithMe(_context.scene.beforeRender$.subscribe(() => this._update()));
|
|
31118
|
+
this.disposeWithMe(this._skeletonManager.currentSkeleton$.subscribe(() => this._update()));
|
|
31119
|
+
this.disposeWithMe(this._skeletonManager.getSkeleton().dirty$.subscribe(() => this._update()));
|
|
31120
|
+
const resetHover = () => this._buttons.forEach((button) => button.resetHover());
|
|
31121
|
+
const viewport = _context.scene.getViewport("viewMain");
|
|
31122
|
+
if (viewport) {
|
|
31123
|
+
let scrollX = viewport.viewportScrollX;
|
|
31124
|
+
let scrollY = viewport.viewportScrollY;
|
|
31125
|
+
this.disposeWithMe(viewport.onScrollAfter$.subscribeEvent((event) => {
|
|
31126
|
+
if (event.viewportScrollX !== scrollX || event.viewportScrollY !== scrollY) {
|
|
31127
|
+
resetHover();
|
|
31128
|
+
scrollX = event.viewportScrollX;
|
|
31129
|
+
scrollY = event.viewportScrollY;
|
|
31130
|
+
}
|
|
31131
|
+
}));
|
|
31132
|
+
}
|
|
31133
|
+
this.disposeWithMe(_context.scene.onPointerCancel$.subscribeEvent(resetHover));
|
|
31134
|
+
this.disposeWithMe(_context.scene.onTransformChange$.subscribeEvent(({ value, preValue }) => {
|
|
31135
|
+
if (value.scaleX != null && value.scaleX !== preValue.scaleX || value.scaleY != null && value.scaleY !== preValue.scaleY) resetHover();
|
|
31136
|
+
}));
|
|
31137
|
+
this.disposeWithMe(_context.scene.onPointerLeave$.subscribeEvent(resetHover));
|
|
31138
|
+
this.disposeWithMe(this._selections.textSelection$.subscribe(({ unitId }) => {
|
|
31139
|
+
if (unitId === _context.unitId) this._normalizeSelection();
|
|
31140
|
+
}));
|
|
31141
|
+
}
|
|
31142
|
+
_getColors(themeService) {
|
|
31143
|
+
return {
|
|
31144
|
+
normal: themeService.getColorFromTheme("gray.900"),
|
|
31145
|
+
hover: themeService.getColorFromTheme("primary.600"),
|
|
31146
|
+
tooltipBackground: themeService.getColorFromTheme("gray.700"),
|
|
31147
|
+
tooltipText: themeService.getColorFromTheme("gray.0")
|
|
31148
|
+
};
|
|
31149
|
+
}
|
|
31150
|
+
_normalizeSelection() {
|
|
31151
|
+
const target = {
|
|
31152
|
+
unitId: this._context.unitId,
|
|
31153
|
+
subUnitId: this._context.unitId
|
|
31154
|
+
};
|
|
31155
|
+
const info = this._selections.getSelectionInfo(target);
|
|
31156
|
+
if (!info || info.segmentId) return;
|
|
31157
|
+
const viewModel = this._skeletonManager.getViewModel();
|
|
31158
|
+
const hiddenRect = info.rectRanges.find((range) => !range.segmentId && range.startOffset != null && viewModel.getCollapsedHeadingAtOffset(range.startOffset));
|
|
31159
|
+
if ((hiddenRect === null || hiddenRect === void 0 ? void 0 : hiddenRect.startOffset) != null) {
|
|
31160
|
+
const offset = viewModel.getCollapsedHeadingAtOffset(hiddenRect.startOffset).paragraphIndex;
|
|
31161
|
+
const textRanges = [{
|
|
31162
|
+
startOffset: offset,
|
|
31163
|
+
endOffset: offset,
|
|
31164
|
+
collapsed: true,
|
|
31165
|
+
isActive: true
|
|
31166
|
+
}];
|
|
31167
|
+
this._selections.replaceSelectionInfoWithoutRefresh({
|
|
31168
|
+
...info,
|
|
31169
|
+
textRanges,
|
|
31170
|
+
rectRanges: []
|
|
31171
|
+
}, target);
|
|
31172
|
+
this._selections.replaceDocRanges(textRanges, target, false, { forceFocus: false });
|
|
31173
|
+
return;
|
|
31174
|
+
}
|
|
31175
|
+
let changed = false;
|
|
31176
|
+
const textRanges = info.textRanges.map((range) => {
|
|
31177
|
+
var _viewModel$getCollaps, _viewModel$getCollaps2;
|
|
31178
|
+
if (range.segmentId) return range;
|
|
31179
|
+
const startOffset = ((_viewModel$getCollaps = viewModel.getCollapsedHeadingAtOffset(range.startOffset)) === null || _viewModel$getCollaps === void 0 ? void 0 : _viewModel$getCollaps.paragraphIndex) ?? range.startOffset;
|
|
31180
|
+
const endOffset = ((_viewModel$getCollaps2 = viewModel.getCollapsedHeadingAtOffset(range.endOffset)) === null || _viewModel$getCollaps2 === void 0 ? void 0 : _viewModel$getCollaps2.paragraphIndex) ?? range.endOffset;
|
|
31181
|
+
if (startOffset === range.startOffset && endOffset === range.endOffset) return range;
|
|
31182
|
+
changed = true;
|
|
31183
|
+
return {
|
|
31184
|
+
...range,
|
|
31185
|
+
startOffset,
|
|
31186
|
+
endOffset,
|
|
31187
|
+
collapsed: startOffset === endOffset,
|
|
31188
|
+
startNodePosition: void 0,
|
|
31189
|
+
endNodePosition: void 0
|
|
31190
|
+
};
|
|
31191
|
+
});
|
|
31192
|
+
if (changed) {
|
|
31193
|
+
this._selections.replaceSelectionInfoWithoutRefresh({
|
|
31194
|
+
...info,
|
|
31195
|
+
textRanges
|
|
31196
|
+
}, target);
|
|
31197
|
+
this._selections.replaceDocRanges([...textRanges, ...info.rectRanges], target, false, { forceFocus: false });
|
|
31198
|
+
}
|
|
31199
|
+
}
|
|
31200
|
+
_update() {
|
|
31201
|
+
this._normalizeSelection();
|
|
31202
|
+
const active = /* @__PURE__ */ new Set();
|
|
31203
|
+
const viewModel = this._skeletonManager.getViewModel();
|
|
31204
|
+
if (this._context.unit.getSnapshot().documentStyle.documentFlavor === _univerjs_core.DocumentFlavor.MODERN) for (const heading of viewModel.getHeadingSections()) {
|
|
31205
|
+
if (heading.startOffset >= heading.endOffset || viewModel.getCollapsedHeadingAtOffset(heading.paragraphIndex)) continue;
|
|
31206
|
+
const bound = this._eventManager.findParagraphBoundByIndex(heading.paragraphIndex);
|
|
31207
|
+
if (!bound || bound.segmentId) continue;
|
|
31208
|
+
active.add(heading.paragraphId);
|
|
31209
|
+
let button = this._buttons.get(heading.paragraphId);
|
|
31210
|
+
if (!button) {
|
|
31211
|
+
button = new HeadingCollapseShape(`__DocHeadingCollapse__${heading.paragraphId}`, this._colors, () => {
|
|
31212
|
+
var _this$_context$unit$g;
|
|
31213
|
+
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);
|
|
31214
|
+
if (paragraph && this._commandService.syncExecuteCommand(_univerjs_docs.SetHeadingCollapsedCommand.id, {
|
|
31215
|
+
unitId: this._context.unitId,
|
|
31216
|
+
paragraphId: heading.paragraphId,
|
|
31217
|
+
collapsed: paragraph.headingCollapsed !== true
|
|
31218
|
+
})) this._layoutService.focus(this._context.unitId);
|
|
31219
|
+
});
|
|
31220
|
+
this._buttons.set(heading.paragraphId, button);
|
|
31221
|
+
this._context.scene.addObject(button, 3);
|
|
31222
|
+
}
|
|
31223
|
+
const left = bound.firstLine.left - button.width;
|
|
31224
|
+
const top = (bound.firstLine.top + bound.firstLine.bottom - button.height) / 2;
|
|
31225
|
+
if (button.left !== left || button.top !== top) {
|
|
31226
|
+
button.resetHover();
|
|
31227
|
+
button.transformByState({
|
|
31228
|
+
left,
|
|
31229
|
+
top
|
|
31230
|
+
});
|
|
31231
|
+
}
|
|
31232
|
+
button.update(heading.collapsed, heading.collapsed ? this._expandLabel : this._collapseLabel, this._colors);
|
|
31233
|
+
}
|
|
31234
|
+
for (const [id, button] of this._buttons) if (!active.has(id)) {
|
|
31235
|
+
button.dispose();
|
|
31236
|
+
this._buttons.delete(id);
|
|
31237
|
+
}
|
|
31238
|
+
}
|
|
31239
|
+
dispose() {
|
|
31240
|
+
super.dispose();
|
|
31241
|
+
this._buttons.forEach((button) => button.dispose());
|
|
31242
|
+
this._buttons.clear();
|
|
31243
|
+
}
|
|
31244
|
+
};
|
|
31245
|
+
DocHeadingCollapseService = __decorate([
|
|
31246
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs.DocSkeletonManagerService)),
|
|
31247
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(DocEventManagerService)),
|
|
31248
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService)),
|
|
31249
|
+
__decorateParam(4, _univerjs_core.ICommandService),
|
|
31250
|
+
__decorateParam(5, _univerjs_ui.ILayoutService),
|
|
31251
|
+
__decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService)),
|
|
31252
|
+
__decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService))
|
|
31253
|
+
], DocHeadingCollapseService);
|
|
31254
|
+
|
|
30835
31255
|
//#endregion
|
|
30836
31256
|
//#region src/shortcuts/core-editing.shortcut.ts
|
|
30837
31257
|
const BreakLineShortcut = {
|
|
@@ -31256,6 +31676,7 @@ let UniverDocsUIPlugin = class UniverDocsUIPlugin extends _univerjs_core.Plugin
|
|
|
31256
31676
|
[DocFloatMenuService],
|
|
31257
31677
|
[DocPasteOptionsRenderController],
|
|
31258
31678
|
[DocParagraphMenuService],
|
|
31679
|
+
[DocHeadingCollapseService],
|
|
31259
31680
|
[DocHeaderFooterController],
|
|
31260
31681
|
[DocHeaderFooterRibbonController],
|
|
31261
31682
|
[DocResizeRenderController],
|