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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
refactor(doc): move section break (#2780)
Univer870c1d408019
diff --git a/packages/core/src/types/interfaces/i-document-data.ts b/packages/core/src/types/interfaces/i-document-data.tsindex 63d2e8e661..6adaa53367 100644--- a/packages/core/src/types/interfaces/i-document-data.ts+++ b/packages/core/src/types/interfaces/i-document-data.ts@@ -352,10 +352,6 @@ export interface IDocStyleBase extends IMargin {}export interface IDocumentLayout {- // docGrid (Document Grid), open xml $17.6.5- charSpace?: number; // charSpace- linePitch?: number; // linePitch- gridType?: GridType; // gridTypedefaultTabStop?: number; // 17.15.1.25 defaultTabStop (Distance Between Automatic Tab Stops) 0.5 in = 36pt,this value should be converted to the default font size when exportingcharacterSpacingControl?: characterSpacingControlType; // characterSpacingControl 17.18.7 ST_CharacterSpacing (Character-Level Whitespace Compression Settings),default compressPunctuation@@ -407,10 +403,16 @@ export interface IDocumentRenderConfig {}export interface ISectionBreakBase {- columnProperties?: ISectionColumnProperties[]; // columnProperties+ // docGrid (Document Grid), open xml $17.6.5+ charSpace?: number; // charSpace+ linePitch?: number; // linePitch+ gridType?: GridType; // gridType++ columnProperties?: ISectionColumnProperties[]; // columnProperties 17.6.4 cols (Column Definitions)columnSeparatorType?: ColumnSeparatorType; // ColumnSeparatorTypecontentDirection?: TextDirection; // contentDirection- sectionType?: SectionType; // sectionType+ sectionType?: SectionType; // sectionType 17.6.22 type (Section Type)+ // deprecated: The attribute does not exist in Word and should be deprecated.sectionTypeNext?: SectionType; // sectionTypetextDirection?: TextDirectionType; // textDirection}@@ -884,6 +886,8 @@ export enum AlignTypeH {LEFT,OUTSIDE,RIGHT,+ BOTH,+ DISTRIBUTE,}// 20.4.3.2 ST_AlignV (Vertical Alignment Definition)diff --git a/packages/docs/src/commands/commands/list.command.ts b/packages/docs/src/commands/commands/list.command.tsindex 807a164bb7..7f06464759 100644--- a/packages/docs/src/commands/commands/list.command.ts+++ b/packages/docs/src/commands/commands/list.command.ts@@ -14,15 +14,17 @@* limitations under the License.*/-import type { ICommand, IMutationInfo, IParagraph } from '@univerjs/core';+import type { ICommand, IMutationInfo, IParagraph, ISectionBreak } from '@univerjs/core';import {CommandType,+ GridType,ICommandService,IUniverInstanceService,JSONX,MemoryCursor,PRESET_LIST_TYPE,PresetListType,+ sortRulesFactory,TextX,TextXActionType,Tools,@@ -68,6 +70,8 @@ export const ListOperationCommand: ICommand<IListOperationCommandParams> = {return false;}+ const sectionBreaks = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()?.sectionBreaks ?? [];+const currentParagraphs = getParagraphsInRange(activeRange, paragraphs);const unitId = docDataModel.getUnitId();@@ -113,12 +117,13 @@ export const ListOperationCommand: ICommand<IListOperationCommandParams> = {...customLists,};- const { charSpace, defaultTabStop = 36, gridType } = docDataModel.getSnapshot().documentStyle;+ const { defaultTabStop = 36 } = docDataModel.getSnapshot().documentStyle;for (const paragraph of currentParagraphs) {const { startIndex, paragraphStyle = {} } = paragraph;const { indentFirstLine, snapToGrid, indentStart } = paragraphStyle;const { hanging: listHanging, indentStart: listIndentStart } = lists[listType].nestingLevel[0];+ const { charSpace, gridType } = findNearestSectionBreak(startIndex, sectionBreaks) || { charSpace: 0, gridType: GridType.LINES };const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);@@ -235,3 +240,13 @@ export function getParagraphsInRange(activeRange: IActiveTextRange, paragraphs:return results;}++export function findNearestSectionBreak(currentIndex: number, sectionBreaks: ISectionBreak[]) {+ const sortedSectionBreaks = sectionBreaks.sort(sortRulesFactory('startIndex'));+ for (let i = 0; i < sortedSectionBreaks.length; i++) {+ const sectionBreak = sectionBreaks[i];+ if (sectionBreak.startIndex >= currentIndex) {+ return sectionBreak;+ }+ }+}diff --git a/packages/engine-render/src/components/docs/layout/doc-skeleton.ts b/packages/engine-render/src/components/docs/layout/doc-skeleton.tsindex 295e2194b5..d93136fec0 100644--- a/packages/engine-render/src/components/docs/layout/doc-skeleton.ts+++ b/packages/engine-render/src/components/docs/layout/doc-skeleton.ts@@ -15,7 +15,7 @@*/import type { ColumnSeparatorType, ISectionColumnProperties, LocaleService, Nullable } from '@univerjs/core';-import { GridType, PRESET_LIST_TYPE, SectionType } from '@univerjs/core';+import { PRESET_LIST_TYPE, SectionType } from '@univerjs/core';import type {IDocumentSkeletonCached,IDocumentSkeletonGlyph,@@ -621,9 +621,6 @@ export class DocumentSkeleton extends Skeleton {...customLists,};const {- charSpace = 0, // charSpace- linePitch = 15.6, // linePitch pt- gridType = GridType.LINES, // gridTypeparagraphLineGapDefault = 0,defaultTabStop = 10.5,textStyle = {},@@ -635,9 +632,6 @@ export class DocumentSkeleton extends Skeleton {lists,drawings,- charSpace,- linePitch,- gridType,localeService: this._localService,paragraphLineGapDefault,defaultTabStop,diff --git a/packages/engine-render/src/components/docs/layout/tools.ts b/packages/engine-render/src/components/docs/layout/tools.tsindex eb42817007..9ec6ab775b 100644--- a/packages/engine-render/src/components/docs/layout/tools.ts+++ b/packages/engine-render/src/components/docs/layout/tools.ts@@ -283,7 +283,7 @@ export function validationGrid(gridType = GridType.LINES, snapToGrid = BooleanNuexport function getLineHeightConfig(sectionBreakConfig: ISectionBreakConfig, paragraphConfig: IParagraphConfig) {const { paragraphStyle = {} } = paragraphConfig;const { linePitch = 15.6, gridType = GridType.LINES, paragraphLineGapDefault = 0 } = sectionBreakConfig;- const { lineSpacing = 1, spacingRule = SpacingRule.AUTO, snapToGrid = BooleanNumber.TRUE } = paragraphStyle;+ const { lineSpacing = 0, spacingRule = SpacingRule.AUTO, snapToGrid = BooleanNumber.TRUE } = paragraphStyle;return { paragraphLineGapDefault, linePitch, gridType, lineSpacing, spacingRule, snapToGrid };}@@ -950,6 +950,10 @@ export function prepareSectionBreakConfig(ctx: ILayoutContext, nodeIndex: number},} = documentStyle;const {+ charSpace = 0, // charSpace+ linePitch = 15.6, // linePitch pt+ gridType = GridType.LINES, // gridType+pageNumberStart = global_pageNumberStart,pageSize = global_pageSize,pageOrient = global_pageOrient,@@ -992,6 +996,10 @@ export function prepareSectionBreakConfig(ctx: ILayoutContext, nodeIndex: number}const sectionBreakConfig: ISectionBreakConfig = {+ charSpace,+ linePitch,+ gridType,+pageNumberStart,pageSize,pageOrient,diff --git a/packages/ui/src/services/editor/editor.service.ts b/packages/ui/src/services/editor/editor.service.tsindex 33cb84057f..d666829580 100644--- a/packages/ui/src/services/editor/editor.service.ts+++ b/packages/ui/src/services/editor/editor.service.ts@@ -192,6 +192,10 @@ export class Editor {const { width, height } = this._param.editorDom.getBoundingClientRect();+ if (height === 0 || width === 0) {+ return;+ }+if (!this.isSingle()) {documentDataModel.updateDocumentDataPageSize(width, undefined);return;