Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat(docs): support modern mode (#3706)

Ran Luobea0e7805d43
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 2949bf6bdf..b72a19becd 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -70,6 +70,7 @@
"Liti",
"localforage",
"LRTBV",
+ "LTRB",
"Luckysheet",
"makearray",
"mengshukeji",
diff --git a/e2e/visual-comparison/docs/docs-visual-comparison.spec.ts-snapshots/default-doc-ci-chromium-linux.png b/e2e/visual-comparison/docs/docs-visual-comparison.spec.ts-snapshots/default-doc-ci-chromium-linux.png
index 3a64235c97..625e99fe5b 100644
Binary files a/e2e/visual-comparison/docs/docs-visual-comparison.spec.ts-snapshots/default-doc-ci-chromium-linux.png and b/e2e/visual-comparison/docs/docs-visual-comparison.spec.ts-snapshots/default-doc-ci-chromium-linux.png differ
diff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png
index 4d076738ef..d575956f13 100644
Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png differ
diff --git a/packages-experimental/debugger/src/controllers/e2e/data/default-doc.ts b/packages-experimental/debugger/src/controllers/e2e/data/default-doc.ts
index 8a08176996..99eadc790a 100644
--- a/packages-experimental/debugger/src/controllers/e2e/data/default-doc.ts
+++ b/packages-experimental/debugger/src/controllers/e2e/data/default-doc.ts
@@ -14,9 +14,9 @@
* limitations under the License.
*/
+import type { IDocumentData } from '@univerjs/core';
import { BooleanNumber, DocumentFlavor } from '@univerjs/core';
import { ptToPixel } from '@univerjs/engine-render';
-import type { IDocumentData } from '@univerjs/core';
// eslint-disable-next-line max-lines-per-function
export function getDefaultDocData(): IDocumentData {
diff --git a/packages-experimental/uni-formula-ui/src/views/components/DocFormulaPopup.tsx b/packages-experimental/uni-formula-ui/src/views/components/DocFormulaPopup.tsx
index 18a72b9f86..1b0b3b7e1b 100644
--- a/packages-experimental/uni-formula-ui/src/views/components/DocFormulaPopup.tsx
+++ b/packages-experimental/uni-formula-ui/src/views/components/DocFormulaPopup.tsx
@@ -14,18 +14,18 @@
* limitations under the License.
*/
+import type { IDocumentData, Nullable } from '@univerjs/core';
+import type { IUniFormulaPopupInfo } from '../../services/formula-popup.service';
import { BooleanNumber, createInternalEditorID, DEFAULT_EMPTY_DOCUMENT_VALUE, DocumentFlavor, HorizontalAlign, ICommandService, LocaleService, useDependency, VerticalAlign, WrapStrategy } from '@univerjs/core';
import { TextEditor } from '@univerjs/docs-ui';
import { CheckMarkSingle, CloseSingle } from '@univerjs/icons';
import { useObservable } from '@univerjs/ui';
import clsx from 'clsx';
import React, { useCallback, useEffect, useRef, useState } from 'react';
-import type { IDocumentData, Nullable } from '@univerjs/core';
-import { CloseFormulaPopupOperation, ConfirmFormulaPopupCommand } from '../../commands/operations/operation';
+import { CloseFormulaPopupOperation, ConfirmFormulaPopupCommand } from '../../commands/operations/operation';
import { DOC_FORMULA_POPUP_KEY, UniFormulaPopupService } from '../../services/formula-popup.service';
import styles from './index.module.less';
-import type { IUniFormulaPopupInfo } from '../../services/formula-popup.service';
export const UNI_FORMULA_EDITOR_ID = createInternalEditorID('UNI_FORMULA');
@@ -42,7 +42,7 @@ function makeSnapshot(f: string): IDocumentData {
],
},
documentStyle: {
- documentFlavor: DocumentFlavor.MODERN,
+ documentFlavor: DocumentFlavor.UNSPECIFIED,
marginTop: 5,
marginBottom: 5,
marginRight: 0,
diff --git a/packages-experimental/uniui/src/views/uni-toolbar/UniFormulaBar.tsx b/packages-experimental/uniui/src/views/uni-toolbar/UniFormulaBar.tsx
index 5eefe3230f..07819ffb5d 100644
--- a/packages-experimental/uniui/src/views/uni-toolbar/UniFormulaBar.tsx
+++ b/packages-experimental/uniui/src/views/uni-toolbar/UniFormulaBar.tsx
@@ -147,7 +147,7 @@ export function FormulaBar() {
width: Number.POSITIVE_INFINITY,
height: Number.POSITIVE_INFINITY,
},
- documentFlavor: DocumentFlavor.MODERN,
+ documentFlavor: DocumentFlavor.UNSPECIFIED,
marginTop: 5,
marginBottom: 5,
marginRight: 0,
diff --git a/packages/core/src/types/interfaces/i-document-data.ts b/packages/core/src/types/interfaces/i-document-data.ts
index 419de46330..37bbff5439 100644
--- a/packages/core/src/types/interfaces/i-document-data.ts
+++ b/packages/core/src/types/interfaces/i-document-data.ts
@@ -411,6 +411,7 @@ export interface IHeaderAndFooterBase {
}
export enum DocumentFlavor {
+ UNSPECIFIED,
TRADITIONAL,
MODERN,
}
diff --git a/packages/docs-drawing-ui/src/controllers/doc-drawing-notification.controller.ts b/packages/docs-drawing-ui/src/controllers/doc-drawing-notification.controller.ts
index 3af604ea6b..20615ee1da 100644
--- a/packages/docs-drawing-ui/src/controllers/doc-drawing-notification.controller.ts
+++ b/packages/docs-drawing-ui/src/controllers/doc-drawing-notification.controller.ts
@@ -40,6 +40,7 @@ interface IAddOrRemoveDrawing {
}
// Check whether drawings are added or deleted from the mutation and obtain the drawing ID.
+// eslint-disable-next-line complexity
function getAddOrRemoveDrawings(actions: JSONXActions): Nullable<IAddOrRemoveDrawing[]> {
if (JSONX.isNoop(actions) || !Array.isArray(actions)) {
return null;
diff --git a/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-transform-update.controller.ts b/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-transform-update.controller.ts
index d95cce9c10..5d2c44b508 100644
--- a/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-transform-update.controller.ts
+++ b/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-transform-update.controller.ts
@@ -14,6 +14,9 @@
* limitations under the License.
*/
+import type { DocumentDataModel, ICommandInfo, IDrawingParam, ITransformState } from '@univerjs/core';
+import type { IRichTextEditingMutationParams } from '@univerjs/docs';
+import type { Documents, DocumentSkeleton, IDocumentSkeletonHeaderFooter, IDocumentSkeletonPage, Image, IRenderContext, IRenderModule } from '@univerjs/engine-render';
import {
BooleanNumber,
Disposable,
@@ -30,9 +33,6 @@ import { IEditorService, SetDocZoomRatioOperation } from '@univerjs/docs-ui';
import { IDrawingManagerService } from '@univerjs/drawing';
import { Liquid, TRANSFORM_CHANGE_OBSERVABLE_TYPE } from '@univerjs/engine-render';
import { debounceTime, filter } from 'rxjs';
-import type { DocumentDataModel, ICommandInfo, IDrawingParam, ITransformState } from '@univerjs/core';
-import type { IRichTextEditingMutationParams } from '@univerjs/docs';
-import type { Documents, DocumentSkeleton, IDocumentSkeletonHeaderFooter, IDocumentSkeletonPage, Image, IRenderContext, IRenderModule } from '@univerjs/engine-render';
import { DocRefreshDrawingsService } from '../../services/doc-refresh-drawings.service';
interface IDrawingParamsWithBehindText {
@@ -195,9 +195,8 @@ export class DocDrawingTransformUpdateController extends Disposable implements I
this._drawingManagerService.refreshTransform(nonMultiDrawings as unknown as IDrawingParam[]);
}
- if (multiDrawings.length > 0) {
- this._handleMultiDrawingsTransform(multiDrawings as unknown as IDrawingParam[]);
- }
+ // if multiDrawings length is 0, also need to remove current multi drawings.
+ this._handleMultiDrawingsTransform(multiDrawings as unknown as IDrawingParam[]);
}
private _handleMultiDrawingsTransform(multiDrawings: IDrawingParam[]) {
@@ -224,7 +223,9 @@ export class DocDrawingTransformUpdateController extends Disposable implements I
this._drawingManagerService.removeNotification(allMultiDrawings);
// Step 3: create new drawing shapes.
- this._drawingManagerService.addNotification(multiDrawings);
+ if (multiDrawings.length > 0) {
+ this._drawingManagerService.addNotification(multiDrawings);
+ }
// Step 4: reSelect previous shapes and focus previous drawings.
for (const key of selectedObjectKeys) {
diff --git a/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-update.render-controller.ts b/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-update.render-controller.ts
index 33c255c03c..53d539cd5f 100644
--- a/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-update.render-controller.ts
+++ b/packages/docs-drawing-ui/src/controllers/render-controllers/doc-drawing-update.render-controller.ts
@@ -190,6 +190,7 @@ export class DocDrawingUpdateRenderController extends Disposable implements IRen
imageWidth: number, imageHeight: number
): Nullable<IDocDrawingPosition> {
const activeTextRange = this._docSelectionRenderService.getActiveTextRange();
+ // TODO: NO need to get the cursor position, because the insert image is inline.
const position = activeTextRange?.getAbsolutePosition() || {
left: 0,
top: 0,
@@ -205,8 +206,8 @@ export class DocDrawingUpdateRenderController extends Disposable implements IRen
posOffset: position.left,
},
positionV: {
- relativeFrom: ObjectRelativeFromV.MARGIN,
- posOffset: position.top,
+ relativeFrom: ObjectRelativeFromV.PARAGRAPH,
+ posOffset: 0,
},
angle: 0,
};
diff --git a/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPanel.tsx b/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPanel.tsx
index c5a814ffbb..435c66cb5b 100644
--- a/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPanel.tsx
+++ b/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPanel.tsx
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-import { useDependency } from '@univerjs/core';
-import React, { useEffect, useState } from 'react';
-import { DrawingCommonPanel } from '@univerjs/drawing-ui';
import type { IDrawingParam } from '@univerjs/drawing';
+import { useDependency } from '@univerjs/core';
import { IDrawingManagerService } from '@univerjs/drawing';
-import styles from './index.module.less';
-import { DocDrawingTextWrap } from './DocDrawingTextWrap';
+import { DrawingCommonPanel } from '@univerjs/drawing-ui';
+import React, { useEffect, useState } from 'react';
import { DocDrawingPosition } from './DocDrawingPosition';
+import { DocDrawingTextWrap } from './DocDrawingTextWrap';
+import styles from './index.module.less';
export const DocDrawingPanel = () => {
const drawingManagerService = useDependency(IDrawingManagerService);
diff --git a/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPosition.tsx b/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPosition.tsx
index 2ceeb84349..015563ff7f 100644
--- a/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPosition.tsx
+++ b/packages/docs-drawing-ui/src/views/doc-image-panel/DocDrawingPosition.tsx
@@ -14,18 +14,18 @@
* limitations under the License.
*/
-import { ICommandService, IUniverInstanceService, LocaleService, ObjectRelativeFromH, ObjectRelativeFromV, PositionedObjectLayoutType, useDependency } from '@univerjs/core';
+import type { ICommandInfo, IObjectPositionH, IObjectPositionV, Nullable } from '@univerjs/core';
+import type { IDocDrawing } from '@univerjs/docs-drawing';
+import type { IDocumentSkeletonDrawing } from '@univerjs/engine-render';
+import { DocumentFlavor, ICommandService, IUniverInstanceService, LocaleService, ObjectRelativeFromH, ObjectRelativeFromV, PositionedObjectLayoutType, useDependency } from '@univerjs/core';
import { Checkbox, InputNumber, Select } from '@univerjs/design';
import { DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';
import { DocSelectionRenderService } from '@univerjs/docs-ui';
import { IDrawingManagerService, type IDrawingParam } from '@univerjs/drawing';
import { IRenderManagerService } from '@univerjs/engine-render';
+
import clsx from 'clsx';
import React, { useEffect, useState } from 'react';
-import type { ICommandInfo, IObjectPositionH, IObjectPositionV, Nullable } from '@univerjs/core';
-
-import type { IDocDrawing } from '@univerjs/docs-drawing';
-import type { IDocumentSkeletonDrawing } from '@univerjs/engine-render';
import { UpdateDrawingDocTransformCommand } from '../../commands/commands/update-doc-drawing.command';
import styles from './index.module.less';
@@ -55,6 +55,8 @@ export const DocDrawingPosition = (props: IDocDrawingPositionProps) => {
const documentDataModel = univerInstanceService.getUniverDocInstance(unitId);
+ const documentFlavor = documentDataModel?.getSnapshot().documentStyle.documentFlavor;
+
const renderObject = renderManagerService.getRenderById(unitId);
const scene = renderObject?.scene;
if (scene == null) {
@@ -76,12 +78,15 @@ export const DocDrawingPosition = (props: IDocDrawingPositionProps) => {
const VERTICAL_RELATIVE_FROM = [{
label: localeService.t('image-position.line'),
value: String(ObjectRelativeFromV.LINE),
+ disabled: documentFlavor === DocumentFlavor.MODERN,
}, {
label: localeService.t('image-position.page'),
value: String(ObjectRelativeFromV.PAGE),
+ disabled: documentFlavor === DocumentFlavor.MODERN,
}, {
label: localeService.t('image-position.margin'),
value: String(ObjectRelativeFromV.MARGIN),
+ disabled: documentFlavor === DocumentFlavor.MODERN,
}, {
label: localeService.t('image-position.paragraph'),
value: String(ObjectRelativeFromV.PARAGRAPH),
diff --git a/packages/docs-ui/src/commands/commands/doc-header-footer.command.ts b/packages/docs-ui/src/commands/commands/doc-header-footer.command.ts
index 9d6fadc2b1..8c7b29eee7 100644
--- a/packages/docs-ui/src/commands/commands/doc-header-footer.command.ts
+++ b/packages/docs-ui/src/commands/commands/doc-header-footer.command.ts
@@ -17,9 +17,10 @@
import type { ICommand, IDocumentBody, IMutationInfo, JSONXActions } from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '@univerjs/docs';
import { BooleanNumber, CommandType, ICommandService, IUniverInstanceService, JSONX, Tools } from '@univerjs/core';
-import { DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';
+import { DocSelectionManagerService, DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';
import { DocumentEditArea, IRenderManagerService, type ITextRangeWithStyle } from '@univerjs/engine-render';
import { HeaderFooterType } from '../../controllers/doc-header-footer.controller';
+import { DocSelectionRenderService } from '../../services/selection/doc-selection-render.service';
import { SidebarDocHeaderFooterPanelOperation } from '../operations/doc-header-footer-panel.operation';
function getEmptyHeaderFooterBody(): IDocumentBody {
@@ -241,3 +242,47 @@ export const OpenHeaderFooterPanelCommand: ICommand<IOpenHeaderFooterPanelParams
return commandService.executeCommand(SidebarDocHeaderFooterPanelOperation.id, { value: 'open' });
},
};
+
+interface ICloseHeaderFooterParams {
+ unitId: string;
+}
+
+export const CloseHeaderFooterCommand: ICommand<ICloseHeaderFooterParams> = {
+ id: 'doc.command.close-header-footer',
+ type: CommandType.COMMAND,
+
+ handler: async (accessor, params: ICloseHeaderFooterParams) => {
+ const commandService = accessor.get(ICommandService);
+ const renderManagerService = accessor.get(IRenderManagerService);
+ const docSelectionManagerService = accessor.get(DocSelectionManagerService);
+
+ const { unitId } = params;
+
+ const renderObject = renderManagerService.getRenderById(unitId);
+ if (renderObject == null) {
+ return false;
+ }
+
+ const { scene } = renderObject;
+ const transformer = scene.getTransformerByCreate();
+ const docSkeletonManagerService = renderObject.with(DocSkeletonManagerService);
+ const docSelectionRenderService = renderObject.with(DocSelectionRenderService);
+ const skeleton = docSkeletonManagerService?.getSkeleton();
+ const viewModel = docSkeletonManagerService?.getViewModel();
+
+ if (viewModel == null || skeleton == null) {
+ return false;
+ }
+
+ // TODO: @JOCS, these codes bellow should be automatically executed?
+ docSelectionManagerService.replaceTextRanges([]); // Clear text selection.
+ transformer.clearSelectedObjects();
+ docSelectionRenderService.setSegment('');
+ docSelectionRenderService.setSegmentPage(-1);
+ viewModel.setEditArea(DocumentEditArea.BODY);
+ skeleton.calculate();
+ renderObject.mainComponent?.makeDirty(true);
+
+ return commandService.executeCommand(SidebarDocHeaderFooterPanelOperation.id, { value: 'close' });
+ },
+};
diff --git a/packages/docs-ui/src/commands/commands/ime-input.command.ts b/packages/docs-ui/src/commands/commands/ime-input.command.ts
index 2b20d186ba..828d583155 100644
--- a/packages/docs-ui/src/commands/commands/ime-input.command.ts
+++ b/packages/docs-ui/src/commands/commands/ime-input.command.ts
@@ -14,11 +14,11 @@
* limitations under the License.
*/
+import type { ICommand, ICommandInfo } from '@univerjs/core';
+import type { IRichTextEditingMutationParams } from '@univerjs/docs';
import { BuildTextUtils, CommandType, ICommandService, IUniverInstanceService, JSONX, TextX, TextXActionType } from '@univerjs/core';
import { RichTextEditingMutation } from '@univerjs/docs';
import { IRenderManagerService, type ITextRangeWithStyle } from '@univerjs/engine-render';
-import type { ICommand, ICommandInfo } from '@univerjs/core';
-import type { IRichTextEditingMutationParams } from '@univerjs/docs';
import { DocIMEInputManagerService } from '../../services/doc-ime-input-manager.service';
import { getRichTextEditPath } from '../util';
diff --git a/packages/docs-ui/src/commands/commands/set-doc-zoom-ratio.command.ts b/packages/docs-ui/src/commands/commands/set-doc-zoom-ratio.command.ts
index 62b2f0a789..642aa08051 100644
--- a/packages/docs-ui/src/commands/commands/set-doc-zoom-ratio.command.ts
+++ b/packages/docs-ui/src/commands/commands/set-doc-zoom-ratio.command.ts
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-import { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService } from '@univerjs/core';
import type { IAccessor, ICommand } from '@univerjs/core';
+import type { ISetDocZoomRatioOperationParams } from '../operations/set-doc-zoom-ratio.operation';
+import { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService } from '@univerjs/core';
import {
SetDocZoomRatioOperation,
SetDocZoomRatioUndoMutationFactory,
} from '../operations/set-doc-zoom-ratio.operation';
-import type { ISetDocZoomRatioOperationParams } from '../operations/set-doc-zoom-ratio.operation';
export interface ISetDocZoomRatioCommandParams {
zoomRatio?: number;
diff --git a/packages/docs-ui/src/commands/commands/switch-doc-mode.command.ts b/packages/docs-ui/src/commands/commands/switch-doc-mode.command.ts
new file mode 100644
index 0000000000..57dc8ad9a9
--- /dev/null
+++ b/packages/docs-ui/src/commands/commands/switch-doc-mode.command.ts
@@ -0,0 +1,170 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { ICommand, ICommandInfo, JSONXActions } from '@univerjs/core';
+import type { IRichTextEditingMutationParams } from '@univerjs/docs';
+import { CommandType, DocumentFlavor, ICommandService, IUniverInstanceService, JSONX, ObjectRelativeFromV } from '@univerjs/core';
+import { DocSelectionManagerService, DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';
+import { IRenderManagerService } from '@univerjs/engine-render';
+import { DocSelectionRenderService } from '../../services/selection/doc-selection-render.service';
+
+export interface ISwitchDocModeCommandParams { }
+
+export const SwitchDocModeCommand: ICommand<ISwitchDocModeCommandParams> = {
+ id: 'doc.command.switch-mode',
+
+ type: CommandType.COMMAND,
+
+ // eslint-disable-next-line max-lines-per-function, complexity
+ handler: async (accessor) => {
+ const commandService = accessor.get(ICommandService);
+ const renderManagerService = accessor.get(IRenderManagerService);
+ const docSelectionManagerService = accessor.get(DocSelectionManagerService);
+
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
+
+ if (docDataModel == null) {
+ return false;
+ }
+
+ const unitId = docDataModel.getUnitId();
+
+ const skeleton = renderManagerService.getRenderById(unitId)
+ ?.with(DocSkeletonManagerService)
+ .getSkeleton();
+
+ const docSelectionRenderService = renderManagerService.getRenderById(unitId)?.with(DocSelectionRenderService);
+
+ if (skeleton == null || docSelectionRenderService == null) {
+ return false;
+ }
+
+ const segmentId = docSelectionRenderService?.getSegment();
+
+ const segmentPage = docSelectionRenderService?.getSegmentPage();
+
+ const documentFlavor = docDataModel.getSnapshot().documentStyle.documentFlavor;
+
+ const docRanges = docSelectionManagerService.getDocRanges();
+
+ const doMutation: ICommandInfo<IRichTextEditingMutationParams> = {
+ id: RichTextEditingMutation.id,
+ params: {
+ unitId,
+ actions: [],
+ textRanges: docRanges,
+ },
+ };
+
+ const jsonX = JSONX.getInstance();
+
+ const rawActions: JSONXActions = [];
+ let action;
+
+ if (documentFlavor === undefined) {
+ action = jsonX.insertOp(['documentStyle', 'documentFlavor'], DocumentFlavor.MODERN);
+ } else {
+ if (documentFlavor === DocumentFlavor.MODERN) {
+ action = jsonX.replaceOp(['documentStyle', 'documentFlavor'], documentFlavor, DocumentFlavor.TRADITIONAL);
+ } else {
+ action = jsonX.replaceOp(['documentStyle', 'documentFlavor'], documentFlavor, DocumentFlavor.MODERN);
+ }
+ }
+
+ if (action) {
+ rawActions.push(action);
+ } else {
+ return false;
+ }
+
+ // Change all drawings' position to relative to paragraph if necessary.
+ // And only need to change drawing in body.
+ if (documentFlavor !== DocumentFlavor.MODERN) {
+ const snapshot = docDataModel.getSnapshot();
+ const { drawings = {}, body } = snapshot;
+ const customBlocks = body?.customBlocks ?? [];
+
+ for (const drawingId in drawings) {
+ const drawing = drawings[drawingId];
+
+ // if (drawing.layoutType === PositionedObjectLayoutType.INLINE) {
+ // continue;
+ // }
+
+ const customBlock = customBlocks.find((block) => block.blockId === drawingId);
+
+ // If drawing is not in body, skip it.
+ if (customBlock == null) {
+ continue;
+ }
+
+ const drawingPositionV = drawing.docTransform.positionV;
+
+ const { relativeFrom: prevRelativeFrom, posOffset: prevPosOffset } = drawingPositionV;
+
+ if (prevRelativeFrom === ObjectRelativeFromV.PARAGRAPH) {
+ continue;
+ }
+
+ const { startIndex } = customBlock;
+
+ const glyph = skeleton.findNodeByCharIndex(startIndex, segmentId, segmentPage);
+ const line = glyph?.parent?.parent;
+ const column = line?.parent;
+ const paragraphStartLine = column?.lines.find((l) => l.paragraphIndex === line?.paragraphIndex && l.paragraphStart);
+ const page = column?.parent?.parent;
+
+ if (glyph == null || line == null || paragraphStartLine == null || column == null || page == null) {
+ continue;
+ }
+
+ let delta = 0;
+
+ if (prevRelativeFrom === ObjectRelativeFromV.LINE) {
+ delta -= line.top;
+ } else if (prevRelativeFrom === ObjectRelativeFromV.PAGE) {
+ delta += page.marginTop;
+ }
+
+ delta += paragraphStartLine.top;
+
+ const newPositionV = {
+ ...drawingPositionV,
+ relativeFrom: ObjectRelativeFromV.PARAGRAPH,
+ posOffset: (prevPosOffset ?? 0) - delta,
+ };
+
+ const updateDrawingAction = jsonX.replaceOp(['drawings', drawingId, 'docTransform', 'positionV'], drawingPositionV, newPositionV);
+
+ if (updateDrawingAction) {
+ rawActions.push(updateDrawingAction);
+ }
+ }
+ }
+
+ doMutation.params!.actions = rawActions.reduce((acc, cur) => {
+ return JSONX.compose(acc, cur as JSONXActions);
+ }, null as JSONXActions);
+
+ const result = commandService.syncExecuteCommand<
+ IRichTextEditingMutationParams,
+ IRichTextEditingMutationParams
+ >(doMutation.id, doMutation.params);
+
+ return Boolean(result);
+ },
+};
diff --git a/packages/docs-ui/src/components/editor/utils.ts b/packages/docs-ui/src/components/editor/utils.ts
index f1d97fc609..b7e9e65532 100644
--- a/packages/docs-ui/src/components/editor/utils.ts
+++ b/packages/docs-ui/src/components/editor/utils.ts
@@ -52,7 +52,7 @@ export function genSnapShotByValue(id = '', value = '') {
},
tableSource: {},
documentStyle: {
- documentFlavor: DocumentFlavor.MODERN,
+ documentFlavor: DocumentFlavor.UNSPECIFIED,
},
};
diff --git a/packages/docs-ui/src/controllers/doc-header-footer.controller.ts b/packages/docs-ui/src/controllers/doc-header-footer.controller.ts
index 1650aa1b60..37d562e7eb 100644
--- a/packages/docs-ui/src/controllers/doc-header-footer.controller.ts
+++ b/packages/docs-ui/src/controllers/doc-header-footer.controller.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { DocumentDataModel } from '@univerjs/core';
+import type { DocumentDataModel, ICommandInfo } from '@univerjs/core';
import type { Documents, DocumentViewModel, IMouseEvent, IPageRenderConfig, IPathProps, IPointerEvent, IRenderContext, IRenderModule, RenderComponentType } from '@univerjs/engine-render';
import type { Nullable } from 'vitest';
import { BooleanNumber, Disposable, DocumentFlavor, ICommandService, Inject, IUniverInstanceService, LocaleService, toDisposable, Tools } from '@univerjs/core';
@@ -23,7 +23,8 @@ import { DocSkeletonManagerService } from '@univerjs/docs';
import { DocumentEditArea, IRenderManagerService, PageLayoutType, Path, Rect, Vector2 } from '@univerjs/engine-render';
import { ComponentManager } from '@univerjs/ui';
import { neoGetDocObject } from '../basics/component-tools';
-import { CoreHeaderFooterCommand } from '../commands/commands/doc-header-footer.command';
+import { CloseHeaderFooterCommand, CoreHeaderFooterCommand } from '../commands/commands/doc-header-footer.command';
+import { SwitchDocModeCommand } from '../commands/commands/switch-doc-mode.command';
import { IEditorService } from '../services/editor/editor-manager.service';
import { DocSelectionRenderService } from '../services/selection/doc-selection-render.service';
import { COMPONENT_DOC_HEADER_FOOTER_PANEL } from '../views/header-footer/panel/component-name';
@@ -142,19 +143,28 @@ export class DocHeaderFooterController extends Disposable implements IRenderModu
}
private _initialize() {
- // FIXME: @Jocs, NO need to register this controller in Modern Document???
- const docDataModel = this._context.unit;
-
- const documentFlavor = docDataModel.getSnapshot().documentStyle.documentFlavor;
-
- // Only traditional document support header/footer.
- if (documentFlavor !== DocumentFlavor.TRADITIONAL) {
- return;
- }
-
this._init();
this._drawHeaderFooterLabel();
this._initCustomComponents();
+ this._listenSwitchMode();
+ }
+
+ // Close header footer panel when switch mode.
+ private _listenSwitchMode() {
+ this.disposeWithMe(
+ this._commandService.beforeCommandExecuted((command: ICommandInfo) => {
+ if (SwitchDocModeCommand.id === command.id) {
+ const viewModel = this._docSkeletonManagerService.getViewModel();
+ const editArea = viewModel.getEditArea();
+
+ if (editArea !== DocumentEditArea.BODY) {
+ this._commandService.executeCommand(CloseHeaderFooterCommand.id, {
+ unitId: this._context.unitId,
+ });
+ }
+ }
+ })
+ );
}
private _initCustomComponents(): void {
@@ -184,6 +194,10 @@ export class DocHeaderFooterController extends Disposable implements IRenderModu
return;
}
+ if (!this._isTraditionalMode()) {
+ return;
+ }
+
const { offsetX, offsetY } = evt;
const {
@@ -271,6 +285,10 @@ export class DocHeaderFooterController extends Disposable implements IRenderModu
return;
}
+ if (!this._isTraditionalMode()) {
+ return;
+ }
+
if (currentRender == null) {
return;
}
@@ -383,6 +401,14 @@ export class DocHeaderFooterController extends Disposable implements IRenderModu
return editor.isReadOnly();
}
+ private _isTraditionalMode() {
+ const docDataModel = this._context.unit;
+
+ const documentFlavor = docDataModel.getSnapshot().documentStyle.documentFlavor;
+
+ return documentFlavor === DocumentFlavor.TRADITIONAL;
+ }
+
private _getDocDataModel() {
return this._context.unit;
}
diff --git a/packages/docs-ui/src/controllers/menu.schema.ts b/packages/docs-ui/src/controllers/menu.schema.ts
index cfc52705df..0bc9de828f 100644
--- a/packages/docs-ui/src/controllers/menu.schema.ts
+++ b/packages/docs-ui/src/controllers/menu.schema.ts
@@ -23,6 +23,7 @@ import { ResetInlineFormatTextBackgroundColorCommand, SetInlineFormatBoldCommand
import { BulletListCommand, CheckListCommand, OrderListCommand } from '../commands/commands/list.command';
import { AlignCenterCommand, AlignJustifyCommand, AlignLeftCommand, AlignRightCommand } from '../commands/commands/paragraph-align.command';
+import { SwitchDocModeCommand } from '../commands/commands/switch-doc-mode.command';
import { DocTableDeleteColumnsCommand, DocTableDeleteRowsCommand, DocTableDeleteTableCommand } from '../commands/commands/table/doc-table-delete.command';
import { DocTableInsertColumnLeftCommand, DocTableInsertColumnRightCommand, DocTableInsertRowAboveCommand, DocTableInsertRowBellowCommand } from '../commands/commands/table/doc-table-insert.command';
import { DocCreateTableOperation } from '../commands/operations/doc-create-table.operation';
@@ -54,6 +55,7 @@ import {
BoldMenuItemFactory,
BulletListMenuItemFactory,
CheckListMenuItemFactory,
+ DocSwitchModeMenuItemFactory,
FontFamilySelectorMenuItemFactory,
FontSizeSelectorMenuItemFactory,
HeaderFooterMenuItemFactory,
@@ -158,6 +160,10 @@ export const menuSchema: MenuSchemaType = {
order: 9,
menuItemFactory: HeaderFooterMenuItemFactory,
},
+ [SwitchDocModeCommand.id]: {
+ order: 10,
+ menuItemFactory: DocSwitchModeMenuItemFactory,
+ },
},
[ContextMenuPosition.MAIN_AREA]: {
[ContextMenuGroup.FORMAT]: {
diff --git a/packages/docs-ui/src/controllers/menu/menu.ts b/packages/docs-ui/src/controllers/menu/menu.ts
index 10ea8cb030..65f0aa113a 100644
--- a/packages/docs-ui/src/controllers/menu/menu.ts
+++ b/packages/docs-ui/src/controllers/menu/menu.ts
@@ -14,12 +14,14 @@
* limitations under the License.
*/
-import type { IAccessor, PresetListType } from '@univerjs/core';
+import type { DocumentDataModel, IAccessor, PresetListType } from '@univerjs/core';
import type { IMenuButtonItem, IMenuItem, IMenuSelectorItem } from '@univerjs/ui';
import type { Subscription } from 'rxjs';
import {
BaselineOffset,
BooleanNumber,
+ DOCS_ZEN_EDITOR_UNIT_ID_KEY,
+ DocumentFlavor,
HorizontalAlign,
ICommandService,
IUniverInstanceService,
@@ -45,6 +47,7 @@ import { OpenHeaderFooterPanelCommand } from '../../commands/commands/doc-header
import { ResetInlineFormatTextBackgroundColorCommand, SetInlineFormatBoldCommand, SetInlineFormatCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand, SetInlineFormatUnderlineCommand } from '../../commands/commands/inline-format.command';
import { BulletListCommand, CheckListCommand, getParagraphsInRange, OrderListCommand } from '../../commands/commands/list.command';
import { AlignCenterCommand, AlignJustifyCommand, AlignLeftCommand, AlignOperationCommand, AlignRightCommand } from '../../commands/commands/paragraph-align.command';
+import { SwitchDocModeCommand } from '../../commands/commands/switch-doc-mode.command';
import { DocCreateTableOperation } from '../../commands/operations/doc-create-table.operation';
import { getCommandSkeleton } from '../../commands/util';
import { COLOR_PICKER_COMPONENT } from '../../components/color-picker';
@@ -94,6 +97,47 @@ function getInsertTableHiddenObservable(
});
}
+function getHeaderFooterDisabledObservable(accessor: IAccessor): Observable<boolean> {
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const commandService = accessor.get(ICommandService);
+
+ return new Observable((subscriber) => {
+ const subscription0 = commandService.onCommandExecuted((command) => {
+ if (command.id === SwitchDocModeCommand.id) {
+ const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
+ if (docDataModel == null) {
+ subscriber.next(true);
+ return;
+ }
+
+ const documentStyle = docDataModel.getSnapshot().documentStyle;
+ subscriber.next(documentStyle?.documentFlavor !== DocumentFlavor.TRADITIONAL);
+ }
+ });
+
+ const subscription = univerInstanceService.focused$.subscribe((unitId) => {
+ if (unitId == null) {
+ subscriber.next(true);
+ return;
+ }
+
+ const docDataModel = univerInstanceService.getUnit<DocumentDataModel>(unitId);
+
+ if (docDataModel == null) {
+ subscriber.next(true);
+ return;
+ }
+
+ return subscriber.next(docDataModel.getSnapshot().documentStyle?.documentFlavor !== DocumentFlavor.TRADITIONAL);
+ });
+
+ return () => {
+ subscription.unsubscribe();
+ subscription0.dispose();
+ };
+ });
+}
+
function getTableDisabledObservable(accessor: IAccessor): Observable<boolean> {
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -528,6 +572,7 @@ export function HeaderFooterMenuItemFactory(accessor: IAccessor): IMenuButtonIte
type: MenuItemType.BUTTON,
icon: 'HeaderFooterSingle',
tooltip: 'toolbar.headerFooter',
+ disabled$: getHeaderFooterDisabledObservable(accessor),
hidden$: combineLatest(getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC), getHeaderFooterMenuHiddenObservable(accessor), (one, two) => {
return one || two;
}),
@@ -794,6 +839,34 @@ export function CheckListMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
};
}
+export function DocSwitchModeMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ const commandService = accessor.get(ICommandService);
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+
+ return {
+ id: SwitchDocModeCommand.id,
+ type: MenuItemType.BUTTON,
+ icon: 'KeyboardSingle',
+ tooltip: 'toolbar.documentFlavor',
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC, undefined, DOCS_ZEN_EDITOR_UNIT_ID_KEY),
+ activated$: new Observable<boolean>((subscriber) => {
+ const subscription = commandService.onCommandExecuted((c) => {
+ if (c.id === SwitchDocModeCommand.id) {
+ const instance = univerInstanceService.getCurrentUnitForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC);
+
+ subscriber.next(instance?.getSnapshot()?.documentStyle.documentFlavor === DocumentFlavor.MODERN);
+ }
+ });
+
+ const instance = univerInstanceService.getCurrentUnitForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC);
+
+ subscriber.next(instance?.getSnapshot()?.documentStyle.documentFlavor === DocumentFlavor.MODERN);
+
+ return () => subscription.dispose();
+ }),
+ };
+}
+
export function ResetBackgroundColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: ResetInlineFormatTextBackgroundColorCommand.id,
diff --git a/packages/docs-ui/src/controllers/render-controllers/doc.render-controller.ts b/packages/docs-ui/src/controllers/render-controllers/doc.render-controller.ts
index 120974abce..25474f16f3 100644
--- a/packages/docs-ui/src/controllers/render-controllers/doc.render-controller.ts
+++ b/packages/docs-ui/src/controllers/render-controllers/doc.render-controller.ts
@@ -17,7 +17,7 @@
import type { DocumentDataModel, EventState, ICommandInfo, Nullable } from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '@univerjs/docs';
import type { DocumentSkeleton, IRenderContext, IRenderModule, IWheelEvent } from '@univerjs/engine-render';
-import { ICommandService, IContextService, Inject, IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';
+import { DocumentFlavor, ICommandService, Inject, IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';
import { DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';
import { DocBackground, Documents, IRenderManagerService, Layer, PageLayoutType, ScrollBar, Viewport } from '@univerjs/engine-render';
import { takeUntil } from 'rxjs';
@@ -28,7 +28,6 @@ import { DocSelectionRenderService } from '../../services/selection/doc-selectio
export class DocRenderController extends RxDisposable implements IRenderModule {
constructor(
private readonly _context: IRenderContext<DocumentDataModel>,
- @IContextService private readonly _contextService: IContextService,
@ICommandService private readonly _commandService: ICommandService,
@Inject(DocSelectionRenderService) private readonly _docSelectionRenderService: DocSelectionRenderService,
@Inject(DocSkeletonManagerService) private readonly _docSkeletonManagerService: DocSkeletonManagerService,
@@ -138,9 +137,11 @@ export class DocRenderController extends RxDisposable implements IRenderModule {
private _addComponent() {
const { scene, unit: documentModel, components } = this._context;
+ const DEFAULT_PAGE_MARGIN_LEFT = 20;
+ const DEFAULT_PAGE_MARGIN_TOP = 20;
const config = {
- pageMarginLeft: documentModel.documentStyle.marginLeft || 0,
- pageMarginTop: documentModel.documentStyle.marginTop || 0,
+ pageMarginLeft: DEFAULT_PAGE_MARGIN_LEFT,
+ pageMarginTop: DEFAULT_PAGE_MARGIN_TOP,
};
const documents = new Documents(DOCS_VIEW_KEY.MAIN, undefined, config);
@@ -211,9 +212,24 @@ export class DocRenderController extends RxDisposable implements IRenderModule {
let width = 0;
let height = 0;
+ const docDataModel = this._context.unit;
+
+ const documentFlavor = docDataModel.getSnapshot().documentStyle.documentFlavor;
+
for (let i = 0, len = pages.length; i < len; i++) {
const page = pages[i];
- const { pageWidth, pageHeight } = page;
+ let { pageWidth, pageHeight, marginLeft, marginRight, marginTop, marginBottom } = page;
+
+ // Mainly for modern mode, because pageHeight will be INFINITY in modern mode.
+ if (documentFlavor === DocumentFlavor.MODERN) {
+ if (pageWidth === Number.POSITIVE_INFINITY) {
+ pageWidth = page.width + marginLeft + marginRight;
+ }
+
+ if (pageHeight === Number.POSITIVE_INFINITY) {
+ pageHeight = page.height + marginTop + marginBottom;
+ }
+ }
if (docsComponent.pageLayoutType === PageLayoutType.VERTICAL) {
height += pageHeight;
diff --git a/packages/docs-ui/src/controllers/render-controllers/zoom.render-controller.ts b/packages/docs-ui/src/controllers/render-controllers/zoom.render-controller.ts
index b16b83f877..7177f6055e 100644
--- a/packages/docs-ui/src/controllers/render-controllers/zoom.render-controller.ts
+++ b/packages/docs-ui/src/controllers/render-controllers/zoom.render-controller.ts
@@ -14,8 +14,13 @@
* limitations under the License.
*/
+import type { DocumentDataModel, ICommandInfo } from '@univerjs/core';
+import type { IRenderContext, IRenderModule, IWheelEvent } from '@univerjs/engine-render';
+
+import type { ISetDocZoomRatioOperationParams } from '../../commands/operations/set-doc-zoom-ratio.operation';
import {
Disposable,
+ DocumentFlavor,
FOCUSING_DOC,
ICommandService,
IContextService,
@@ -23,15 +28,12 @@ import {
IUniverInstanceService,
} from '@univerjs/core';
import { DocSelectionManagerService, DocSkeletonManagerService } from '@univerjs/docs';
-
-import type { DocumentDataModel, ICommandInfo } from '@univerjs/core';
-import type { IRenderContext, IRenderModule, IWheelEvent } from '@univerjs/engine-render';
import { neoGetDocObject } from '../../basics/component-tools';
import { SetDocZoomRatioCommand } from '../../commands/commands/set-doc-zoom-ratio.command';
+import { SwitchDocModeCommand } from '../../commands/commands/switch-doc-mode.command';
import { SetDocZoomRatioOperation } from '../../commands/operations/set-doc-zoom-ratio.operation';
import { DocPageLayoutService } from '../../services/doc-page-layout.service';
import { IEditorService } from '../../services/editor/editor-manager.service';
-import type { ISetDocZoomRatioOperationParams } from '../../commands/operations/set-doc-zoom-ratio.operation';
export class DocZoomRenderController extends Disposable implements IRenderModule {
constructor(
@@ -75,6 +77,13 @@ export class DocZoomRenderController extends Disposable implements IRenderModule
return;
}
+ const { documentFlavor } = documentModel.getSnapshot().documentStyle;
+
+ // Modern document does not support zooming.
+ if (documentFlavor === DocumentFlavor.MODERN) {
+ return;
+ }
+
const deltaFactor = Math.abs(e.deltaX);
let ratioDelta = deltaFactor < 40 ? 0.2 : deltaFactor < 80 ? 0.4 : 0.2;
ratioDelta *= e.deltaY > 0 ? -1 : 1;
@@ -122,13 +131,26 @@ export class DocZoomRenderController extends Disposable implements IRenderModule
this.updateViewZoom(zoomRatio);
}
}));
+
+ this.disposeWithMe(
+ this._commandService.beforeCommandExecuted((command: ICommandInfo) => {
+ if (command.id === SwitchDocModeCommand.id) {
+ this._commandService.executeCommand(SetDocZoomRatioCommand.id, {
+ zoomRatio: 1,
+ unitId: this._context.unitId,
+ });
+ }
+ })
+ );
}
updateViewZoom(zoomRatio: number, needRefreshSelection = true) {
const docObject = neoGetDocObject(this._context);
docObject.scene.scale(zoomRatio, zoomRatio);
- this._docPageLayoutService.calculatePagePosition();
+ if (!this._editorService.isEditor(this._context.unitId)) {
+ this._docPageLayoutService.calculatePagePosition();
+ }
if (needRefreshSelection && !this._editorService.isEditor(this._context.unitId)) {
this._textSelectionManagerService.refreshSelection();
diff --git a/packages/docs-ui/src/docs-ui-plugin.ts b/packages/docs-ui/src/docs-ui-plugin.ts
index 0f9decc17d..967b56c295 100644
--- a/packages/docs-ui/src/docs-ui-plugin.ts
+++ b/packages/docs-ui/src/docs-ui-plugin.ts
@@ -36,6 +36,7 @@ import { DocCopyCommand, DocCutCommand, DocPasteCommand } from './commands/comma
import { CutContentCommand, InnerPasteCommand } from './commands/commands/clipboard.inner.command';
import { DeleteCommand, InsertCommand, UpdateCommand } from './commands/commands/core-editing.command';
import { DeleteCustomBlockCommand, DeleteLeftCommand, DeleteRightCommand, MergeTwoParagraphCommand } from './commands/commands/delete.command';
+import { CloseHeaderFooterCommand } from './commands/commands/doc-header-footer.command';
import { DocParagraphSettingCommand } from './commands/commands/doc-paragraph-setting.command';
import { IMEInputCommand } from './commands/commands/ime-input.command';
import { ResetInlineFormatTextBackgroundColorCommand, SetInlineFormatBoldCommand, SetInlineFormatCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand, SetInlineFormatUnderlineCommand } from './commands/commands/inline-format.command';
@@ -43,6 +44,7 @@ import { BulletListCommand, ChangeListNestingLevelCommand, ChangeListTypeCommand
import { AlignCenterCommand, AlignJustifyCommand, AlignLeftCommand, AlignOperationCommand, AlignRightCommand } from './commands/commands/paragraph-align.command';
import { CoverContentCommand, ReplaceContentCommand, ReplaceSnapshotCommand } from './commands/commands/replace-content.command';
import { SetDocZoomRatioCommand } from './commands/commands/set-doc-zoom-ratio.command';
+import { SwitchDocModeCommand } from './commands/commands/switch-doc-mode.command';
import { CreateDocTableCommand } from './commands/commands/table/doc-table-create.command';
import { DocTableDeleteColumnsCommand, DocTableDeleteRowsCommand, DocTableDeleteTableCommand } from './commands/commands/table/doc-table-delete.command';
import { DocTableInsertColumnCommand, DocTableInsertColumnLeftCommand, DocTableInsertColumnRightCommand, DocTableInsertRowAboveCommand, DocTableInsertRowBellowCommand, DocTableInsertRowCommand } from './commands/commands/table/doc-table-insert.command';
@@ -189,6 +191,7 @@ export class UniverDocsUIPlugin extends Plugin {
DocTableDeleteRowsCommand,
DocTableDeleteColumnsCommand,
DocTableDeleteTableCommand,
+ CloseHeaderFooterCommand,
DocTableTabCommand,
TabCommand,
AfterSpaceCommand,
@@ -199,6 +202,7 @@ export class UniverDocsUIPlugin extends Plugin {
ToggleCheckListCommand,
QuickListCommand,
IMEInputCommand,
+ SwitchDocModeCommand,
DocParagraphSettingCommand,
InnerPasteCommand,
CutContentCommand,
diff --git a/packages/docs-ui/src/locale/en-US.ts b/packages/docs-ui/src/locale/en-US.ts
index 15027d6cc9..3f594b1d21 100644
--- a/packages/docs-ui/src/locale/en-US.ts
+++ b/packages/docs-ui/src/locale/en-US.ts
@@ -46,6 +46,7 @@ const locale: typeof zhCN = {
order: 'Ordered list',
unorder: 'Unordered list',
checklist: 'Task list',
+ documentFlavor: 'Modern Mode',
alignLeft: 'Align Left',
alignCenter: 'Align Center',
alignRight: 'Align Right',
diff --git a/packages/docs-ui/src/locale/fa-IR.ts b/packages/docs-ui/src/locale/fa-IR.ts
index f88a3c0d80..ea1963ddd7 100644
--- a/packages/docs-ui/src/locale/fa-IR.ts
+++ b/packages/docs-ui/src/locale/fa-IR.ts
@@ -46,6 +46,7 @@ const locale: typeof zhCN = {
order: 'لیست شماره‌دار',
unorder: 'لیست بدون شماره',
checklist: 'لیست وظیفه',
+ documentFlavor: 'Modern Mode',
alignLeft: 'تراز چپ',
alignCenter: 'تراز وسط',
alignRight: 'تراز راست',
diff --git a/packages/docs-ui/src/locale/ru-RU.ts b/packages/docs-ui/src/locale/ru-RU.ts
index 87e0644618..e6018e9bd5 100644
--- a/packages/docs-ui/src/locale/ru-RU.ts
+++ b/packages/docs-ui/src/locale/ru-RU.ts
@@ -51,6 +51,7 @@ const locale: typeof zhCN = {
alignJustify: 'Выровнять по ширине',
headerFooter: 'Header & Footer',
checklist: 'Task list',
+ documentFlavor: 'Modern Mode',
},
table: {
insert: 'Insert',
diff --git a/packages/docs-ui/src/locale/vi-VN.ts b/packages/docs-ui/src/locale/vi-VN.ts
index 1eeb16c95b..d6c9a0c607 100644
--- a/packages/docs-ui/src/locale/vi-VN.ts
+++ b/packages/docs-ui/src/locale/vi-VN.ts
@@ -51,6 +51,7 @@ const locale: typeof zhCN = {
alignJustify: 'Căn đều hai bên',
headerFooter: 'Đầu trang và chân trang',
checklist: 'Task list',
+ documentFlavor: 'Modern Mode',
},
table: {
insert: 'Insert',
diff --git a/packages/docs-ui/src/locale/zh-CN.ts b/packages/docs-ui/src/locale/zh-CN.ts
index a26b8d6734..c9cfff3b52 100644
--- a/packages/docs-ui/src/locale/zh-CN.ts
+++ b/packages/docs-ui/src/locale/zh-CN.ts
@@ -44,6 +44,7 @@ const locale = {
order: '有序列表',
unorder: '无序列表',
checklist: '任务列表',
+ documentFlavor: '现代模式',
alignLeft: '左对齐',
alignCenter: '居中对齐',
alignRight: '右对齐',
diff --git a/packages/docs-ui/src/locale/zh-TW.ts b/packages/docs-ui/src/locale/zh-TW.ts
index cd72cc169c..fa8bb2aa4b 100644
--- a/packages/docs-ui/src/locale/zh-TW.ts
+++ b/packages/docs-ui/src/locale/zh-TW.ts
@@ -51,6 +51,7 @@ const locale: typeof zhCN = {
alignJustify: '兩端對齊',
headerFooter: '頁眉頁腳',
checklist: '任務列表',
+ documentFlavor: '现代模式',
},
table: {
insert: 'Insert',
diff --git a/packages/docs-ui/src/services/doc-page-layout.service.ts b/packages/docs-ui/src/services/doc-page-layout.service.ts
index 7e6b9c8c09..b80d555895 100644
--- a/packages/docs-ui/src/services/doc-page-layout.service.ts
+++ b/packages/docs-ui/src/services/doc-page-layout.service.ts
@@ -36,12 +36,13 @@ export class DocPageLayoutService extends Disposable implements IRenderModule {
const parent = scene?.getParent();
const { width: docsWidth, height: docsHeight, pageMarginLeft, pageMarginTop } = docsComponent;
+
if (parent == null || docsWidth === Number.POSITIVE_INFINITY || docsHeight === Number.POSITIVE_INFINITY) {
return;
}
const { width: engineWidth, height: engineHeight } = parent;
let docsLeft = 0;
- let docsTop = 0;
+ let docsTop = pageMarginTop;
let sceneWidth = 0;
@@ -63,14 +64,12 @@ export class DocPageLayoutService extends Disposable implements IRenderModule {
}
if (engineHeight > docsHeight) {
- docsTop = engineHeight / 2 - docsHeight / 2;
sceneHeight = (engineHeight - pageMarginTop * 2) / zoomRatio;
} else {
- docsTop = pageMarginTop;
sceneHeight = docsHeight + pageMarginTop * 2;
}
- scene.resize(sceneWidth, sceneHeight + 200);
+ scene.resize(sceneWidth, sceneHeight);
// the engine width is 1, when engine has no container.
// Use to fix flickering issues into the page.
diff --git a/packages/docs-ui/src/services/selection/text-range.ts b/packages/docs-ui/src/services/selection/text-range.ts
index 4bda36f8dd..d6ea2e5b49 100644
--- a/packages/docs-ui/src/services/selection/text-range.ts
+++ b/packages/docs-ui/src/services/selection/text-range.ts
@@ -14,10 +14,11 @@
* limitations under the License.
*/
-import { BooleanNumber, COLORS, DOC_RANGE_TYPE, RANGE_DIRECTION, Tools } from '@univerjs/core';
-import { getColor, NORMAL_TEXT_SELECTION_PLUGIN_STYLE, Rect, RegularPolygon } from '@univerjs/engine-render';
import type { ITextRange, Nullable } from '@univerjs/core';
import type { Documents, DocumentSkeleton, IDocumentSkeletonGlyph, INodePosition, IPoint, ISuccinctDocRangeParam, ITextSelectionStyle, Scene, ThinScene } from '@univerjs/engine-render';
+import type { IDocRange } from './range-interface';
+import { BooleanNumber, COLORS, DOC_RANGE_TYPE, RANGE_DIRECTION, Tools } from '@univerjs/core';
+import { getColor, NORMAL_TEXT_SELECTION_PLUGIN_STYLE, Rect, RegularPolygon } from '@univerjs/engine-render';
import {
compareNodePosition,
compareNodePositionLogic,
@@ -25,7 +26,6 @@ import {
NodePositionConvertToCursor,
NodePositionMap,
} from './convert-text-range';
-import type { IDocRange } from './range-interface';
const TEXT_RANGE_KEY_PREFIX = '__TestSelectionRange__';
const TEXT_ANCHOR_KEY_PREFIX = '__TestSelectionAnchor__';
diff --git a/packages/docs-ui/src/views/doc-container/DocContainer.tsx b/packages/docs-ui/src/views/doc-container/DocContainer.tsx
index fe0211b04d..3ccad180e9 100644
--- a/packages/docs-ui/src/views/doc-container/DocContainer.tsx
+++ b/packages/docs-ui/src/views/doc-container/DocContainer.tsx
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-import React, { Component, createRef } from 'react';
-
import type { IUniverDocsUIConfig } from '../../controllers/config.schema';
+
+import React, { Component, createRef } from 'react';
import style from './index.module.less';
interface IBaseDocContainerProps {
diff --git a/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterOptions.tsx b/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterOptions.tsx
index 37ffa23865..7df1f5f46b 100644
--- a/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterOptions.tsx
+++ b/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterOptions.tsx
@@ -17,12 +17,12 @@
import type { IDocumentStyle } from '@univerjs/core';
import { BooleanNumber, ICommandService, IUniverInstanceService, LocaleService, Tools, useDependency } from '@univerjs/core';
import { Button, Checkbox, InputNumber } from '@univerjs/design';
-import { DocSelectionManagerService, DocSkeletonManagerService } from '@univerjs/docs';
+import { DocSkeletonManagerService } from '@univerjs/docs';
import { DocumentEditArea, IRenderManagerService } from '@univerjs/engine-render';
import { ILayoutService } from '@univerjs/ui';
import clsx from 'clsx';
import React, { useEffect, useState } from 'react';
-import { CoreHeaderFooterCommandId, type IHeaderFooterProps } from '../../../commands/commands/doc-header-footer.command';
+import { CloseHeaderFooterCommand, CoreHeaderFooterCommandId, type IHeaderFooterProps } from '../../../commands/commands/doc-header-footer.command';
import { DocSelectionRenderService } from '../../../services/selection/doc-selection-render.service';
import styles from './index.module.less';
@@ -61,8 +61,9 @@ export const DocHeaderFooterOptions = (props: IDocHeaderFooterOptionsProps) => {
const univerInstanceService = useDependency(IUniverInstanceService);
const renderManagerService = useDependency(IRenderManagerService);
const commandService = useDependency(ICommandService);
- const docSelectionManagerService = useDependency(DocSelectionManagerService);
+
const layoutService = useDependency(ILayoutService);
+
const { unitId } = props;
const docSelectionRenderService = renderManagerService.getRenderById(unitId)!.with(DocSelectionRenderService)!;
@@ -175,30 +176,9 @@ export const DocHeaderFooterOptions = (props: IDocHeaderFooterOptionsProps) => {
};
const closeHeaderFooter = () => {
- const renderObject = renderManagerService.getRenderById(unitId);
- if (renderObject == null) {
- return;
- }
-
- const { scene } = renderObject;
- const transformer = scene.getTransformerByCreate();
- const docSkeletonManagerService = renderObject.with(DocSkeletonManagerService);
- const skeleton = docSkeletonManagerService?.getSkeleton();
- const viewModel = docSkeletonManagerService?.getViewModel();
- const render = renderManagerService.getRenderById(unitId);
-
- if (render == null || viewModel == null || skeleton == null) {
- return;
- }
-
- // TODO: @JOCS, these codes bellow should be automatically executed?
- docSelectionManagerService.replaceTextRanges([]); // Clear text selection.
- transformer.clearSelectedObjects();
- docSelectionRenderService.setSegment('');
- docSelectionRenderService.setSegmentPage(-1);
- viewModel.setEditArea(DocumentEditArea.BODY);
- skeleton.calculate();
- render.mainComponent?.makeDirty(true);
+ commandService.executeCommand(CloseHeaderFooterCommand.id, {
+ unitId,
+ });
};
useEffect(() => {
diff --git a/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterPanel.tsx b/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterPanel.tsx
index f7e64f20b7..b9dd544606 100644
--- a/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterPanel.tsx
+++ b/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterPanel.tsx
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-import React, { useEffect, useState } from 'react';
import { IUniverInstanceService, LocaleService, useDependency } from '@univerjs/core';
import { DocSkeletonManagerService } from '@univerjs/docs';
import { DocumentEditArea, IRenderManagerService } from '@univerjs/engine-render';
+import React, { useEffect, useState } from 'react';
-import styles from './index.module.less';
import { DocHeaderFooterOptions } from './DocHeaderFooterOptions';
+import styles from './index.module.less';
export const DocHeaderFooterPanel = () => {
const localeService = useDependency(LocaleService);
diff --git a/packages/drawing-ui/src/views/panel/DrawingCommonPanel.tsx b/packages/drawing-ui/src/views/panel/DrawingCommonPanel.tsx
index 75b10ce2e9..80a5083b1a 100644
--- a/packages/drawing-ui/src/views/panel/DrawingCommonPanel.tsx
+++ b/packages/drawing-ui/src/views/panel/DrawingCommonPanel.tsx
@@ -15,15 +15,15 @@
*/
import { LocaleService, useDependency } from '@univerjs/core';
-import React, { useEffect, useState } from 'react';
-import { IRenderManagerService } from '@univerjs/engine-render';
import { IDrawingManagerService, type IDrawingParam } from '@univerjs/drawing';
+import { IRenderManagerService } from '@univerjs/engine-render';
+import React, { useEffect, useState } from 'react';
import { getUpdateParams } from '../../utils/get-update-params';
+import { DrawingAlign } from './DrawingAlign';
import { DrawingArrange } from './DrawingArrange';
+import { DrawingGroup } from './DrawingGroup';
import { DrawingTransform } from './DrawingTransform';
-import { DrawingAlign } from './DrawingAlign';
import { ImageCropper } from './ImageCropper';
-import { DrawingGroup } from './DrawingGroup';
export interface IDrawingCommonPanelProps {
drawings: IDrawingParam[];
diff --git a/packages/engine-render/src/components/docs/doc-background.ts b/packages/engine-render/src/components/docs/doc-background.ts
index 43be40b11d..6dafdd074f 100644
--- a/packages/engine-render/src/components/docs/doc-background.ts
+++ b/packages/engine-render/src/components/docs/doc-background.ts
@@ -14,15 +14,15 @@
* limitations under the License.
*/
-import { DocumentFlavor } from '@univerjs/core';
import type { IViewportInfo } from '../../basics/vector2';
import type { UniverRenderingContext } from '../../context';
import type { IPathProps } from '../../shape';
-import { Path, Rect } from '../../shape';
-import { Liquid } from './liquid';
import type { IDocumentsConfig } from './doc-component';
-import { DocComponent } from './doc-component';
import type { DocumentSkeleton } from './layout/doc-skeleton';
+import { DocumentFlavor } from '@univerjs/core';
+import { Path, Rect } from '../../shape';
+import { DocComponent } from './doc-component';
+import { Liquid } from './liquid';
const PAGE_STROKE_COLOR = 'rgba(198, 198, 198, 1)';
const PAGE_FILL_COLOR = 'rgba(255, 255, 255, 1)';
@@ -51,7 +51,12 @@ export class DocBackground extends DocComponent {
return;
}
- const documentFlavor = docDataModel.getSnapshot().documentStyle.documentFlavor;
+ const { documentFlavor } = docDataModel.getSnapshot().documentStyle;
+
+ if (documentFlavor !== DocumentFlavor.TRADITIONAL) {
+ return;
+ }
+
this._drawLiquid.reset();
const { pages } = skeletonData;
@@ -92,51 +97,49 @@ export class DocBackground extends DocComponent {
Rect.drawWith(ctx, backgroundOptions);
- if (documentFlavor === DocumentFlavor.TRADITIONAL) {
- const IDENTIFIER_WIDTH = 15;
- const marginIdentification: IPathProps = {
- dataArray: [{
- command: 'M',
- points: [marginLeft - IDENTIFIER_WIDTH, originMarginTop],
- }, {
- command: 'L',
- points: [marginLeft, originMarginTop],
- }, {
- command: 'L',
- points: [marginLeft, originMarginTop - IDENTIFIER_WIDTH],
- }, {
- command: 'M',
- points: [pageWidth - marginRight + IDENTIFIER_WIDTH, originMarginTop],
- }, {
- command: 'L',
- points: [pageWidth - marginRight, originMarginTop],
- }, {
- command: 'L',
- points: [pageWidth - marginRight, originMarginTop - IDENTIFIER_WIDTH],
- }, {
- command: 'M',
- points: [marginLeft - IDENTIFIER_WIDTH, pageHeight - originMarginBottom],
- }, {
- command: 'L',
- points: [marginLeft, pageHeight - originMarginBottom],
- }, {
- command: 'L',
- points: [marginLeft, pageHeight - originMarginBottom + IDENTIFIER_WIDTH],
- }, {
- command: 'M',
- points: [pageWidth - marginRight + IDENTIFIER_WIDTH, pageHeight - originMarginBottom],
- }, {
- command: 'L',
- points: [pageWidth - marginRight, pageHeight - originMarginBottom],
- }, {
- command: 'L',
- points: [pageWidth - marginRight, pageHeight - originMarginBottom + IDENTIFIER_WIDTH],
- }] as unknown as IPathProps['dataArray'],
- strokeWidth: 1.5,
- stroke: MARGIN_STROKE_COLOR,
- };
- Path.drawWith(ctx, marginIdentification);
- }
+ const IDENTIFIER_WIDTH = 15;
+ const marginIdentification: IPathProps = {
+ dataArray: [{
+ command: 'M',
+ points: [marginLeft - IDENTIFIER_WIDTH, originMarginTop],
+ }, {
+ command: 'L',
+ points: [marginLeft, originMarginTop],
+ }, {
+ command: 'L',
+ points: [marginLeft, originMarginTop - IDENTIFIER_WIDTH],
+ }, {
+ command: 'M',
+ points: [pageWidth - marginRight + IDENTIFIER_WIDTH, originMarginTop],
+ }, {
+ command: 'L',
+ points: [pageWidth - marginRight, originMarginTop],
+ }, {
+ command: 'L',
+ points: [pageWidth - marginRight, originMarginTop - IDENTIFIER_WIDTH],
+ }, {
+ command: 'M',
+ points: [marginLeft - IDENTIFIER_WIDTH, pageHeight - originMarginBottom],
+ }, {
+ command: 'L',
+ points: [marginLeft, pageHeight - originMarginBottom],
+ }, {
+ command: 'L',
+ points: [marginLeft, pageHeight - originMarginBottom + IDENTIFIER_WIDTH],
+ }, {
+ command: 'M',
+ points: [pageWidth - marginRight + IDENTIFIER_WIDTH, pageHeight - originMarginBottom],
+ }, {
+ command: 'L',
+ points: [pageWidth - marginRight, pageHeight - originMarginBottom],
+ }, {
+ command: 'L',
+ points: [pageWidth - marginRight, pageHeight - originMarginBottom + IDENTIFIER_WIDTH],
+ }] as unknown as IPathProps['dataArray'],
+ strokeWidth: 1.5,
+ stroke: MARGIN_STROKE_COLOR,
+ };
+ Path.drawWith(ctx, marginIdentification);
ctx.restore();
const { x, y } = this._drawLiquid.translatePage(
diff --git a/packages/engine-render/src/components/docs/document.ts b/packages/engine-render/src/components/docs/document.ts
index dd2087ed14..f30a1da056 100644
--- a/packages/engine-render/src/components/docs/document.ts
+++ b/packages/engine-render/src/components/docs/document.ts
@@ -53,11 +53,8 @@ export interface IDocumentOffsetConfig extends IPageMarginLayout {
export class Documents extends DocComponent {
private readonly _pageRender$ = new Subject<IPageRenderConfig>();
- readonly pageRender$ = this._pageRender$.asObservable();
-
- docsLeft: number = 0;
- docsTop: number = 0;
+ readonly pageRender$ = this._pageRender$.asObservable();
private _drawLiquid: Nullable<Liquid> = new Liquid();
diff --git a/packages/engine-render/src/components/docs/layout/tools.ts b/packages/engine-render/src/components/docs/layout/tools.ts
index 6b43f42609..170c5bcc99 100644
--- a/packages/engine-render/src/components/docs/layout/tools.ts
+++ b/packages/engine-render/src/components/docs/layout/tools.ts
@@ -17,6 +17,7 @@
import type {
DocumentDataModel,
IBullet,
+ IDocumentStyle,
INumberUnit,
IObjectPositionH,
IObjectPositionV,
@@ -49,6 +50,7 @@ import {
AlignTypeV,
BooleanNumber,
ColumnSeparatorType,
+ DocumentFlavor,
GridType,
HorizontalAlign,
mergeWith,
@@ -64,7 +66,7 @@ import {
} from '@univerjs/core';
import { DEFAULT_DOCUMENT_FONTSIZE } from '../../../basics/const';
import { GlyphType } from '../../../basics/i-document-skeleton-cached';
-import { getFontStyleString, isFunction } from '../../../basics/tools';
+import { getFontStyleString, isFunction, ptToPixel } from '../../../basics/tools';
import { updateInlineDrawingPosition } from './block/paragraph/layout-ruler';
import { getCustomDecorationStyle } from './style/custom-decoration';
import { getCustomRangeStyle } from './style/custom-range';
@@ -950,11 +952,55 @@ const DEFAULT_SECTION_BREAK: ISectionBreak = {
export const DEFAULT_PAGE_SIZE = { width: Number.POSITIVE_INFINITY, height: Number.POSITIVE_INFINITY };
+const DEFAULT_MODERN_DOCUMENT_STYLE: IDocumentStyle = {
+ pageNumberStart: 1,
+ pageSize: {
+ width: ptToPixel(595),
+ height: Number.POSITIVE_INFINITY,
+ },
+ marginTop: ptToPixel(50),
+ marginBottom: ptToPixel(50),
+ marginRight: ptToPixel(50),
+ marginLeft: ptToPixel(50),
+ renderConfig: {
+ vertexAngle: 0,
+ centerAngle: 0,
+ background: {
+ rgb: '#FFFFFF',
+ },
+ },
+ defaultHeaderId: '',
+ defaultFooterId: '',
+ evenPageHeaderId: '',
+ evenPageFooterId: '',
+ firstPageHeaderId: '',
+ firstPageFooterId: '',
+ evenAndOddHeaders: BooleanNumber.FALSE,
+ useFirstPageHeaderFooter: BooleanNumber.FALSE,
+ marginHeader: 0,
+ marginFooter: 0,
+};
+
+const DEFAULT_MODERN_SECTION_BREAK: Partial<ISectionBreak> = {
+ columnProperties: [],
+ columnSeparatorType: ColumnSeparatorType.NONE,
+ sectionType: SectionType.SECTION_TYPE_UNSPECIFIED,
+};
+
export function prepareSectionBreakConfig(ctx: ILayoutContext, nodeIndex: number) {
const { viewModel, dataModel, docsConfig } = ctx;
const sectionNode = viewModel.children[nodeIndex];
- const sectionBreak = viewModel.getSectionBreak(sectionNode.endIndex) || DEFAULT_SECTION_BREAK;
- const { documentStyle } = dataModel;
+ let { documentStyle } = dataModel;
+ const { documentFlavor } = documentStyle;
+ let sectionBreak = viewModel.getSectionBreak(sectionNode.endIndex) || DEFAULT_SECTION_BREAK;
+
+ // If the configuration is in modern mode, use the style configuration of modern mode to overwrite the original configuration.
+ // In modern mode, there are no pages, no sections, no columns. There are no headers and footers, and margins are all defaults.
+ if (documentFlavor === DocumentFlavor.MODERN) {
+ sectionBreak = Object.assign({}, sectionBreak, DEFAULT_MODERN_SECTION_BREAK);
+ documentStyle = Object.assign({}, documentStyle, DEFAULT_MODERN_DOCUMENT_STYLE);
+ }
+
const {
pageNumberStart: global_pageNumberStart = 1, // pageNumberStart
pageSize: global_pageSize = DEFAULT_PAGE_SIZE,
diff --git a/packages/sheets-formula-ui/src/views/range-selector/hooks/useHighlight.ts b/packages/sheets-formula-ui/src/views/range-selector/hooks/useHighlight.ts
index 1761506e65..27bce7459c 100644
--- a/packages/sheets-formula-ui/src/views/range-selector/hooks/useHighlight.ts
+++ b/packages/sheets-formula-ui/src/views/range-selector/hooks/useHighlight.ts
@@ -149,6 +149,7 @@ export function useDocHight(editorId: string, sequenceNodes: (string | ISequence
// Switching between uppercase and lowercase will trigger a reflow, causing the cursor to be misplaced. Let's refresh the cursor position here.
const selection = editor.getSelectionRanges();
const cloneData = { ...data, body: cloneBody };
+
editor.setDocumentData(cloneData, selection);
}, [editorId, sequenceNodes, colorMap]);
diff --git a/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx b/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx
index 5a47326787..2522069a32 100644
--- a/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx
+++ b/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx
@@ -73,7 +73,7 @@ export const EditorContainer: React.FC<ICellIEditorProps> = () => {
},
tableSource: {},
documentStyle: {
- documentFlavor: DocumentFlavor.MODERN,
+ documentFlavor: DocumentFlavor.UNSPECIFIED,
},
};
diff --git a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
index c175a98423..1ebc8cae0c 100644
--- a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
+++ b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { IDocumentData, Nullable, Workbook } from '@univerjs/core';
import { BooleanNumber, DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DocumentFlavor, HorizontalAlign, IPermissionService, IUniverInstanceService, Rectangle, ThemeService, UniverInstanceType, useDependency, useObservable, VerticalAlign, WrapStrategy } from '@univerjs/core';
import { TextEditor } from '@univerjs/docs-ui';
import { DeviceInputEventType } from '@univerjs/engine-render';
@@ -21,10 +22,9 @@ import { CheckMarkSingle, CloseSingle, DropdownSingle, FxSingle } from '@univerj
import { RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetProtectionRuleModel, WorksheetSetCellValuePermission } from '@univerjs/sheets';
import { KeyCode, ProgressBar } from '@univerjs/ui';
import clsx from 'clsx';
-import React, { useEffect, useLayoutEffect, useState } from 'react';
+import React, { useEffect, useLayoutEffect, useState } from 'react';
import { EMPTY, merge, switchMap } from 'rxjs';
-import type { IDocumentData, Nullable, Workbook } from '@univerjs/core';
import { useActiveWorkbook } from '../../components/hook';
import { IFormulaEditorManagerService } from '../../services/editor/formula-editor-manager.service';
@@ -126,7 +126,7 @@ export function FormulaBar() {
width: Number.POSITIVE_INFINITY,
height: Number.POSITIVE_INFINITY,
},
- documentFlavor: DocumentFlavor.MODERN,
+ documentFlavor: DocumentFlavor.UNSPECIFIED,
marginTop: 5,
marginBottom: 5,
marginRight: 0,
diff --git a/packages/sheets-zen-editor/src/commands/commands/zen-editor.command.ts b/packages/sheets-zen-editor/src/commands/commands/zen-editor.command.ts
index bdd50a2e00..38f947878c 100644
--- a/packages/sheets-zen-editor/src/commands/commands/zen-editor.command.ts
+++ b/packages/sheets-zen-editor/src/commands/commands/zen-editor.command.ts
@@ -15,7 +15,7 @@
*/
import type { ICommand, Workbook } from '@univerjs/core';
-import { CommandType, DOCS_ZEN_EDITOR_UNIT_ID_KEY, DocumentDataModel, IUniverInstanceService, Tools, UniverInstanceType } from '@univerjs/core';
+import { CommandType, DOCS_ZEN_EDITOR_UNIT_ID_KEY, DocumentDataModel, DocumentFlavor, IUniverInstanceService, Tools, UniverInstanceType } from '@univerjs/core';
import { IEditorService } from '@univerjs/docs-ui';
import { IRenderManagerService } from '@univerjs/engine-render';
import { EditingRenderController, IEditorBridgeService } from '@univerjs/sheets-ui';
@@ -131,6 +131,8 @@ export const ConfirmZenEditCommand: ICommand = {
if (editingRenderController) {
const snapshot = Tools.deepClone(editor.getDocumentData());
+ // Maybe we need a third Document flavor for sheet editor?
+ snapshot.documentStyle.documentFlavor = DocumentFlavor.UNSPECIFIED;
editingRenderController.submitCellData(new DocumentDataModel(snapshot));
}
diff --git a/packages/sheets-zen-editor/src/controllers/zen-editor.controller.ts b/packages/sheets-zen-editor/src/controllers/zen-editor.controller.ts
index f7cfe12e44..ec66486a6e 100644
--- a/packages/sheets-zen-editor/src/controllers/zen-editor.controller.ts
+++ b/packages/sheets-zen-editor/src/controllers/zen-editor.controller.ts
@@ -78,7 +78,7 @@ export class ZenEditorController extends RxDisposable {
const { width: engineWidth, height: engineHeight } = parent;
let docsLeft = 0;
- let docsTop = 0;
+ const docsTop = pageMarginTop;
let sceneWidth = 0;
@@ -102,14 +102,12 @@ export class ZenEditorController extends RxDisposable {
}
if (engineHeight > docsHeight) {
- docsTop = engineHeight / 2 - docsHeight / 2;
sceneHeight = (engineHeight - pageMarginTop * 2) / scaleY;
} else {
- docsTop = pageMarginTop;
sceneHeight = docsHeight + pageMarginTop * 2;
}
- scene.resize(sceneWidth, sceneHeight + 200);
+ scene.resize(sceneWidth, sceneHeight);
docsComponent.translate(docsLeft, docsTop);
docBackground.translate(docsLeft, docsTop);
diff --git a/packages/sheets-zen-editor/src/views/zen-editor/ZenEditor.tsx b/packages/sheets-zen-editor/src/views/zen-editor/ZenEditor.tsx
index 7311b60942..7f7bada4fa 100644
--- a/packages/sheets-zen-editor/src/views/zen-editor/ZenEditor.tsx
+++ b/packages/sheets-zen-editor/src/views/zen-editor/ZenEditor.tsx
@@ -50,13 +50,13 @@ const INITIAL_SNAPSHOT: IDocumentData = {
documentStyle: {
pageSize: {
width: 595,
- height: 842,
+ height: Number.POSITIVE_INFINITY,
},
documentFlavor: DocumentFlavor.MODERN,
- marginTop: 50,
- marginBottom: 50,
- marginRight: 40,
- marginLeft: 40,
+ marginTop: 0,
+ marginBottom: 0,
+ marginRight: 0,
+ marginLeft: 0,
renderConfig: {
vertexAngle: 0,
centerAngle: 0,
diff --git a/packages/sheets-zen-editor/src/views/zen-editor/index.module.less b/packages/sheets-zen-editor/src/views/zen-editor/index.module.less
index 58e8ebaa3b..4511694fec 100644
--- a/packages/sheets-zen-editor/src/views/zen-editor/index.module.less
+++ b/packages/sheets-zen-editor/src/views/zen-editor/index.module.less
@@ -6,6 +6,8 @@
width: 100%;
height: 100%;
+ background-color: rgb(var(--color-white));
+
&-icon {
&-wrapper {
position: absolute;
diff --git a/packages/slides-ui/src/views/editor-container/EditorContainer.tsx b/packages/slides-ui/src/views/editor-container/EditorContainer.tsx
index 72f77408aa..a04b58dcbd 100644
--- a/packages/slides-ui/src/views/editor-container/EditorContainer.tsx
+++ b/packages/slides-ui/src/views/editor-container/EditorContainer.tsx
@@ -14,13 +14,13 @@
* limitations under the License.
*/
+import type { IDocumentData } from '@univerjs/core';
import { DEFAULT_EMPTY_DOCUMENT_VALUE, DocumentFlavor, IContextService, useDependency } from '@univerjs/core';
import { IEditorService, TextEditor } from '@univerjs/docs-ui';
-import { FIX_ONE_PIXEL_BLUR_OFFSET } from '@univerjs/engine-render';
+import { FIX_ONE_PIXEL_BLUR_OFFSET } from '@univerjs/engine-render';
import { DISABLE_AUTO_FOCUS_KEY, useObservable } from '@univerjs/ui';
import React, { useEffect, useState } from 'react';
-import type { IDocumentData } from '@univerjs/core';
import { SLIDE_EDITOR_ID } from '../../const';
// import { ICellEditorManagerService } from '../../services/editor/cell-editor-manager.service';
import { ISlideEditorManagerService } from '../../services/slide-editor-manager.service';
@@ -70,7 +70,7 @@ export const SlideEditorContainer: React.FC<ICellIEditorProps> = () => {
],
},
documentStyle: {
- documentFlavor: DocumentFlavor.MODERN,
+ documentFlavor: DocumentFlavor.UNSPECIFIED,
},
};
diff --git a/packages/slides/src/basics/demo-data.ts b/packages/slides/src/basics/demo-data.ts
index 05d5221186..5eb3530448 100644
--- a/packages/slides/src/basics/demo-data.ts
+++ b/packages/slides/src/basics/demo-data.ts
@@ -204,7 +204,7 @@ export const docsDemoData: IDocumentData = {
width: 594.3,
height: 840.51,
},
- documentFlavor: DocumentFlavor.MODERN,
+ documentFlavor: DocumentFlavor.UNSPECIFIED,
marginTop: 72,
marginBottom: 72,
marginRight: 90,
diff --git a/packages/ui/src/common/menu-hidden-observable.ts b/packages/ui/src/common/menu-hidden-observable.ts
index 2d045e8fb7..4b7469ab37 100644
--- a/packages/ui/src/common/menu-hidden-observable.ts
+++ b/packages/ui/src/common/menu-hidden-observable.ts
@@ -21,7 +21,8 @@ import { Observable } from 'rxjs';
export function getMenuHiddenObservable(
accessor: IAccessor,
targetUniverType: UniverInstanceType,
- matchUnitId?: string
+ matchUnitId?: string,
+ needHideUnitId?: string
): Observable<boolean> {
const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -33,6 +34,9 @@ export function getMenuHiddenObservable(
if (matchUnitId && matchUnitId !== unitId) {
return subscriber.next(true);
}
+ if (needHideUnitId && needHideUnitId === unitId) {
+ return subscriber.next(true);
+ }
const univerType = univerInstanceService.getUnitType(unitId);
subscriber.next(univerType !== targetUniverType);
diff --git a/packages/ui/src/views/MobileApp.tsx b/packages/ui/src/views/MobileApp.tsx
index 89514c672b..e7e59e5362 100644
--- a/packages/ui/src/views/MobileApp.tsx
+++ b/packages/ui/src/views/MobileApp.tsx
@@ -14,19 +14,19 @@
* limitations under the License.
*/
-import { LocaleService, ThemeService, useDependency } from '@univerjs/core';
import type { ILocale } from '@univerjs/design';
+import type { IWorkbenchOptions } from '../controllers/ui/ui.controller';
+import { LocaleService, ThemeService, useDependency } from '@univerjs/core';
import { ConfigProvider, defaultTheme, themeInstance } from '@univerjs/design';
import React, { useEffect, useMemo, useRef, useState } from 'react';
-import type { IWorkbenchOptions } from '../controllers/ui/ui.controller';
import { IMessageService } from '../services/message/message.service';
import { BuiltInUIPart } from '../services/parts/parts.service';
-import styles from './mobile-app.module.less';
import { ComponentContainer, useComponentsOfPart } from './components/ComponentContainer';
+import { MobileContextMenu } from './components/context-menu/MobileContextMenu';
import { Sidebar } from './components/sidebar/Sidebar';
import { ZenZone } from './components/zen-zone/ZenZone';
+import styles from './mobile-app.module.less';
import { builtInGlobalComponents } from './parts';
-import { MobileContextMenu } from './components/context-menu/MobileContextMenu';
export interface IUniverAppProps extends IWorkbenchOptions {
mountContainer: HTMLElement;
diff --git a/packages/ui/src/views/workbench/Workbench.tsx b/packages/ui/src/views/workbench/Workbench.tsx
index e5b9142512..0889c00cb2 100644
--- a/packages/ui/src/views/workbench/Workbench.tsx
+++ b/packages/ui/src/views/workbench/Workbench.tsx
@@ -14,13 +14,15 @@
* limitations under the License.
*/
-import { IUniverInstanceService, LocaleService, ThemeService, UniverInstanceType, useDependency } from '@univerjs/core';
+import type { DocumentDataModel, IDocumentData, Nullable } from '@univerjs/core';
+import type { ILocale } from '@univerjs/design';
+import type { IWorkbenchOptions } from '../../controllers/ui/ui.controller';
+import { DocumentFlavor, IUniverInstanceService, LocaleService, ThemeService, UniverInstanceType, useDependency } from '@univerjs/core';
import { ConfigContext, ConfigProvider, defaultTheme, themeInstance } from '@univerjs/design';
+
import clsx from 'clsx';
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
-
import { createPortal } from 'react-dom';
-import type { ILocale } from '@univerjs/design';
import { IMessageService } from '../../services/message/message.service';
import { BuiltInUIPart } from '../../services/parts/parts.service';
import { ComponentContainer, useComponentsOfPart } from '../components/ComponentContainer';
@@ -28,10 +30,9 @@ import { DesktopContextMenu } from '../components/context-menu/ContextMenu';
import { Ribbon } from '../components/ribbon/Ribbon';
import { Sidebar } from '../components/sidebar/Sidebar';
import { ZenZone } from '../components/zen-zone/ZenZone';
-import { builtInGlobalComponents } from '../parts';
+import { builtInGlobalComponents } from '../parts';
import styles from './workbench.module.less';
-import type { IWorkbenchOptions } from '../../controllers/ui/ui.controller';
export interface IUniverWorkbenchProps extends IWorkbenchOptions {
mountContainer: HTMLElement;
@@ -62,7 +63,7 @@ export function DesktopWorkbench(props: IUniverWorkbenchProps) {
const leftSidebarComponents = useComponentsOfPart(BuiltInUIPart.LEFT_SIDEBAR);
const globalComponents = useComponentsOfPart(BuiltInUIPart.GLOBAL);
- const [focusUnitType, setFocusUnitType] = useState<UniverInstanceType>(UniverInstanceType.UNIVER_UNKNOWN);
+ const [docSnapShot, setDocSnapShot] = useState<Nullable<IDocumentData>>(null);
useEffect(() => {
const sub = instanceService.focused$.subscribe((id) => {
@@ -70,8 +71,11 @@ export function DesktopWorkbench(props: IUniverWorkbenchProps) {
return;
}
const instanceType = instanceService.getUnitType(id);
+ const instance = instanceService.getUnit(id);
- setFocusUnitType(instanceType);
+ if (instanceType === UniverInstanceType.UNIVER_DOC && instance) {
+ setDocSnapShot((instance as DocumentDataModel).getSnapshot());
+ }
});
return () => {
@@ -148,7 +152,7 @@ export function DesktopWorkbench(props: IUniverWorkbenchProps) {
<section className={clsx(
styles.workbenchContainerContent,
{
- [styles.workbenchContainerDocContent]: focusUnitType === UniverInstanceType.UNIVER_DOC,
+ [styles.workbenchContainerDocContent]: docSnapShot?.documentStyle.documentFlavor === DocumentFlavor.TRADITIONAL,
}
)}
>
diff --git a/packages/ui/src/views/workbench/workbench.module.less b/packages/ui/src/views/workbench/workbench.module.less
index 8f4cda4f12..03b360ff3a 100644
--- a/packages/ui/src/views/workbench/workbench.module.less
+++ b/packages/ui/src/views/workbench/workbench.module.less
@@ -46,7 +46,7 @@
}
&-doc-content {
- background: rgb(var(--grey-50));
+ background: rgb(var(--bg-color-secondary));
}
&-canvas {