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
feat(doc): update doc architecture
DR-Univerd783f8c52d88
diff --git a/packages/base-render/src/Basics/IDocumentSkeletonCached.ts b/packages/base-render/src/Basics/IDocumentSkeletonCached.tsindex 4064f4d635..8c03f29521 100644--- a/packages/base-render/src/Basics/IDocumentSkeletonCached.ts+++ b/packages/base-render/src/Basics/IDocumentSkeletonCached.ts@@ -1,15 +1,4 @@-import {- BulletAlignment,- ColumnSeparatorType,- IDrawing,- INestingLevel,- IParagraphStyle,- ITextStyle,- IDocumentRenderConfig,- IIndentStart,- PageOrientType,- IElement,-} from '@univerjs/core';+import { BulletAlignment, ColumnSeparatorType, IDrawing, INestingLevel, IParagraphStyle, ITextStyle, IDocumentRenderConfig, IIndentStart, PageOrientType } from '@univerjs/core';export interface IDocumentSkeletonCached extends ISkeletonResourceReference {pages: IDocumentSkeletonPage[];@@ -24,13 +13,12 @@ export interface ISkeletonResourceReference {skeFooters: Map<string, Map<number, IDocumentSkeletonFooter>>;/* Global cache, does not participate in rendering, only helps skeleton generation */skeListLevel?: Map<string, IDocumentSkeletonBullet[]>; // 有序列表缓存,id:{ level: max(width)的bullet }- blockAnchor?: Map<string, IDocumentSkeletonBlockAnchor>; // Anchor point to assist floating element positioning- features?: Map<string, IDocumentSkeletonSpanFeature>;+ drawingAnchor?: Map<number, IDocumentSkeletonDrawingAnchor>; // Anchor point to assist floating element positioning}-export interface IDocumentSkeletonBlockAnchor {+export interface IDocumentSkeletonDrawingAnchor {elements: IDocumentSkeletonLine[]; // element: lines, tr- blockId: string; // block id+ paragraphIndex: number; // block idtop: number; // relative height for previous block}@@ -104,7 +92,7 @@ export interface IDocumentSkeletonColumn {}export interface IDocumentSkeletonLine {- blockId: string; // ID number associated with block+ paragraphIndex: number; // ID number associated with blocktype: LineType; // 行的类型,可以是段落或者其他block// line坐标系相对于columndivides: IDocumentSkeletonDivide[]; // divides 受到对象影响,把行切分为N部分@@ -188,11 +176,6 @@ export interface IDocumentSkeletonDrawing {drawingOrigin: IDrawing;}-export interface IDocumentSkeletonSpanFeature {- featureId: string;- element: IElement;-}-export interface IDocumentSkeletonFontStyle {fontString: string;fontSize: number;diff --git a/packages/base-render/src/Basics/Interfaces.ts b/packages/base-render/src/Basics/Interfaces.tsindex 2e5936ca95..6dc88bf3bd 100644--- a/packages/base-render/src/Basics/Interfaces.ts+++ b/packages/base-render/src/Basics/Interfaces.ts@@ -11,11 +11,12 @@ import {ISize,ITextStyle,ITransformState,+ DocumentBodyModel,} from '@univerjs/core';import { TextSelection } from '../Component/Docs/Common/TextSelection';import { Documents } from '../Component/Docs/Document';import {- IDocumentSkeletonBlockAnchor,+ IDocumentSkeletonDrawingAnchor,IDocumentSkeletonBullet,IDocumentSkeletonDrawing,IDocumentSkeletonFontStyle,@@ -68,6 +69,8 @@ export interface IMeasureTextCache {export interface IDocsConfig extends IReferenceSource, IDocumentLayout {fontLocale: IFontLocale;documentTextStyle?: ITextStyle;+ headerTreeMap: Map<string, DocumentBodyModel>;+ footerTreeMap: Map<string, DocumentBodyModel>;}export interface IHeaderIds {@@ -90,7 +93,7 @@ export interface ISectionBreakConfig extends IDocStyleBase, ISectionBreakBase, I}export interface IParagraphConfig {- blockId: string;+ paragraphIndex: number;paragraphAffectSkeDrawings?: Map<string, IDocumentSkeletonDrawing>;// headerAndFooterAffectSkeDrawings?: Map<string, IDocumentSkeletonDrawing>;bulletSkeleton?: IDocumentSkeletonBullet;@@ -99,7 +102,7 @@ export interface IParagraphConfig {paragraphStyle?: IParagraphStyle;skeHeaders: Map<string, Map<number, IDocumentSkeletonHeader>>;skeFooters: Map<string, Map<number, IDocumentSkeletonFooter>>;- blockAnchor?: Map<string, IDocumentSkeletonBlockAnchor>;+ drawingAnchor?: Map<number, IDocumentSkeletonDrawingAnchor>;// sectionBreakConfig: ISectionBreakConfig;}diff --git a/packages/base-render/src/Component/Docs/Block/Paragraph/InlineDrawing.ts b/packages/base-render/src/Component/Docs/Block/Paragraph/InlineDrawing.tsindex b34dd0c9ce..3a6c1256aa 100644--- a/packages/base-render/src/Component/Docs/Block/Paragraph/InlineDrawing.ts+++ b/packages/base-render/src/Component/Docs/Block/Paragraph/InlineDrawing.ts@@ -4,9 +4,8 @@ import { IFontLocale, IParagraphConfig, ISectionBreakConfig } from '../../../../export function dealWidthInlineDrawing(drawing: IDrawing,- elementIndex: number,sectionBreakConfig: ISectionBreakConfig,- currentPage?: IDocumentSkeletonPage,+ allPages?: IDocumentSkeletonPage[],paragraphConfig?: IParagraphConfig,fontLocale?: IFontLocale) {diff --git a/packages/base-render/src/Component/Docs/Block/Paragraph/Language.Ruler.ts b/packages/base-render/src/Component/Docs/Block/Paragraph/Language.Ruler.tsindex 187a796564..a3c1e824d6 100644--- a/packages/base-render/src/Component/Docs/Block/Paragraph/Language.Ruler.ts+++ b/packages/base-render/src/Component/Docs/Block/Paragraph/Language.Ruler.ts@@ -9,7 +9,7 @@ interface LanguageResult {spanGroup: IDocumentSkeletonSpan[];}-export function composeCharForLanguage(char: string, charIndex: number, charArray: string[], config: IFontCreateConfig): Nullable<LanguageResult> {+export function composeCharForLanguage(char: string, charIndex: number, charArray: string, config: IFontCreateConfig): Nullable<LanguageResult> {if (hasArabic(char)) {return ArabicHandler(char, charIndex, charArray, config);}@@ -21,7 +21,7 @@ export function composeCharForLanguage(char: string, charIndex: number, charArra}}-function notCJKHandler(char: string, charIndex: number, charArray: string[], config: IFontCreateConfig) {+function notCJKHandler(char: string, charIndex: number, charArray: string, config: IFontCreateConfig) {// Chinese, Japanese, and Korean (CJK) characters.// https://en.wikipedia.org/wiki/CJK_charactersconst { pageWidth = Infinity } = config;@@ -51,7 +51,7 @@ function notCJKHandler(char: string, charIndex: number, charArray: string[], con};}-function ArabicHandler(char: string, charIndex: number, charArray: string[], config: IFontCreateConfig) {+function ArabicHandler(char: string, charIndex: number, charArray: string, config: IFontCreateConfig) {// 组合阿拉伯语的词组const span = [char];let newCharIndex = charIndex;@@ -70,7 +70,7 @@ function ArabicHandler(char: string, charIndex: number, charArray: string[], con};}-function TibetanHandler(char: string, charIndex: number, charArray: string[], config: IFontCreateConfig) {+function TibetanHandler(char: string, charIndex: number, charArray: string, config: IFontCreateConfig) {// 组合藏语词组const span = [char];let newCharIndex = charIndex;diff --git a/packages/base-render/src/Component/Docs/Block/Paragraph/Layout.Ruler.ts b/packages/base-render/src/Component/Docs/Block/Paragraph/Layout.Ruler.tsindex 7d8f7d6213..f95b21d22b 100644--- a/packages/base-render/src/Component/Docs/Block/Paragraph/Layout.Ruler.ts+++ b/packages/base-render/src/Component/Docs/Block/Paragraph/Layout.Ruler.ts@@ -18,7 +18,7 @@ import {isColumnFull,} from '../../Common/Tools';import { createSkeletonPage } from '../../Common/Page';-import { addSpanToDivide, calculateLineTopByDrawings, createAndUpdateBlockAnchor, createSkeletonLine, isParagraphStart, setDivideFullState } from '../../Common/Line';+import { addSpanToDivide, calculateLineTopByDrawings, createAndUpdateBlockAnchor, createSkeletonLine, setDivideFullState } from '../../Common/Line';import { createSkeletonBulletSpan, setSpanGroupLeft } from '../../Common/Span';import { setColumnFullState } from '../../Common/Section';import {@@ -38,10 +38,9 @@ export function calculateParagraphLayout(pages: IDocumentSkeletonPage[],sectionBreakConfig: ISectionBreakConfig,paragraphConfig: IParagraphConfig,- elementIndex: number = 0,- isFirstSpan: boolean = false+ paragraphStart: boolean = false) {- if (isParagraphStart(elementIndex, isFirstSpan)) {+ if (paragraphStart) {// elementIndex === 0 表示段落开始的第一个字符,需要新起一行,与之前的段落区分开if (paragraphConfig.bulletSkeleton) {const { bulletSkeleton, paragraphStyle = {} } = paragraphConfig;@@ -55,13 +54,13 @@ export function calculateParagraphLayout(__bulletIndentHandler(paragraphStyle, bulletSkeleton, charSpaceApply);const bulletSpan = createSkeletonBulletSpan(spanGroup[0], bulletSkeleton, charSpaceApply);- _lineOperator([bulletSpan, ...spanGroup], pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan);+ _lineOperator([bulletSpan, ...spanGroup], pages, sectionBreakConfig, paragraphConfig, paragraphStart);// _divideOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan);} else {- _lineOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan);+ _lineOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart);}} else {- _divideOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan);+ _divideOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart);}return [...pages];}@@ -71,8 +70,7 @@ function _divideOperator(pages: IDocumentSkeletonPage[],sectionBreakConfig: ISectionBreakConfig,paragraphConfig: IParagraphConfig,- elementIndex: number = 0,- isFirstSpan: boolean = false,+ paragraphStart: boolean = false,defaultSpanLineHeight?: number) {const lastPage = getLastPage(pages);@@ -99,7 +97,7 @@ function _divideOperator(// divide.spanGroup.push(...spanGroup);__makeColumnsFull(column?.parent?.columns);} else {- _pageOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan, defaultSpanLineHeight);+ _pageOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);}} else if (column && width > column.width) {// 一个字符超列宽@@ -109,14 +107,14 @@ function _divideOperator(addSpanToDivide(divide, spanGroup);// divide.spanGroup.push(...spanGroup);} else {- _columnOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan, defaultSpanLineHeight);+ _columnOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);}} else if (divideInfo.isLast) {// 最后一个divide- _lineOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan, defaultSpanLineHeight);+ _lineOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);} else {// 不是最后一个divide- _divideOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan, defaultSpanLineHeight);+ _divideOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);}} else {// w不超过div宽度,加入到divide中去@@ -142,11 +140,11 @@ function _divideOperator(}const column = currentLine.parent;column?.lines.pop(); // Delete the previous line and recalculate according to the maximum content height- _lineOperator(newSpanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan, boundingBoxAscent + boundingBoxDescent);+ _lineOperator(newSpanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, boundingBoxAscent + boundingBoxDescent);for (let i = startIndex; i < spanGroupCached.length; i++) {- _divideOperator([spanGroupCached[i]], pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan);+ _divideOperator([spanGroupCached[i]], pages, sectionBreakConfig, paragraphConfig, paragraphStart);}- _divideOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan);+ _divideOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart);return;}}@@ -159,7 +157,7 @@ function _divideOperator(// divide.spanGroup.push(...spanGroup);}} else {- _lineOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan, defaultSpanLineHeight);+ _lineOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);}}@@ -168,15 +166,14 @@ function _lineOperator(pages: IDocumentSkeletonPage[],sectionBreakConfig: ISectionBreakConfig,paragraphConfig: IParagraphConfig,- elementIndex: number = 0,- isFirstSpan: boolean = false,+ paragraphStart: boolean = false,defaultSpanLineHeight?: number) {let lastPage = getLastPage(pages);let columnInfo = getLastNotFullColumnInfo(lastPage);if (!columnInfo || !columnInfo.column) {// 如果列不存在,则做一个兜底策略,新增一页。- _pageOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex);+ _pageOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig);lastPage = getLastPage(pages);columnInfo = getLastNotFullColumnInfo(lastPage);}@@ -189,7 +186,7 @@ function _lineOperator(const { ba: ascent, bd: descent } = spanGroup[0].bBox;const spanLineHeight = defaultSpanLineHeight || ascent + descent;- const { paragraphStyle = {}, paragraphAffectSkeDrawings, skeHeaders, skeFooters, blockAnchor, blockId } = paragraphConfig;+ const { paragraphStyle = {}, paragraphAffectSkeDrawings, skeHeaders, skeFooters, drawingAnchor, paragraphIndex } = paragraphConfig;const {namedStyleType = NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED,@@ -220,7 +217,6 @@ function _lineOperator(const { paragraphLineGapDefault, linePitch, lineSpacing, spacingRule, snapToGrid, gridType } = getLineHeightConfig(sectionBreakConfig, paragraphConfig);- const paragraphStart = isParagraphStart(elementIndex, isFirstSpan);const { paddingTop, paddingBottom, contentHeight, lineSpacingApply } = __getLineHeight(spanLineHeight,paragraphLineGapDefault,@@ -247,15 +243,15 @@ function _lineOperator(const headersDrawings = skeHeaders?.get(headerId)?.get(width)?.skeDrawings;const footersDrawings = skeFooters?.get(footerId)?.get(width)?.skeDrawings;- __updateDrawingPosition(lineTop, lineHeight, column, blockAnchor?.get(blockId)?.top, paragraphAffectSkeDrawings); // 初始化paragraphAffectSkeDrawings的位置,drawing的布局参照Paragraph开始位置,如果段落中有换页的情况,换页之后的drawing参照位置是0, 0+ __updateDrawingPosition(lineTop, lineHeight, column, drawingAnchor?.get(paragraphIndex)?.top, paragraphAffectSkeDrawings); // 初始化paragraphAffectSkeDrawings的位置,drawing的布局参照Paragraph开始位置,如果段落中有换页的情况,换页之后的drawing参照位置是0, 0- const newLineTop = calculateLineTopByDrawings(lineHeight, lineTop, elementIndex, lastPage.skeDrawings, headersDrawings, footersDrawings); // WRAP_TOP_AND_BOTTOM的drawing会改变行的起始top+ const newLineTop = calculateLineTopByDrawings(lineHeight, lineTop, lastPage.skeDrawings, headersDrawings, footersDrawings); // WRAP_TOP_AND_BOTTOM的drawing会改变行的起始topif (lineHeight + newLineTop > section.height && column.lines.length > 0 && lastPage.sections.length > 0) {// 行高超过Col高度,且列中已存在一行以上,且section大于一个;// console.log('_lineOperator', { spanGroup, pages, lineHeight, newLineTop, sectionHeight: section.height, lastPage });setColumnFullState(column, true);- _columnOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan, defaultSpanLineHeight);+ _columnOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);return;}@@ -270,7 +266,7 @@ function _lineOperator(}// console.log(spanGroup[0].content, isParagraphStart(elementIndex, isFirstSpan), elementIndex, isFirstSpan);const newLine = createSkeletonLine(- blockId,+ paragraphIndex,LineType.PARAGRAPH,{lineHeight,@@ -285,16 +281,15 @@ function _lineOperator(},column.width,lineIndex,- elementIndex,- isFirstSpan,+ paragraphStart,lastPage.skeDrawings,headersDrawings,footersDrawings);column.lines.push(newLine);newLine.parent = column;- createAndUpdateBlockAnchor(blockId, newLine, lineTop, blockAnchor);- _divideOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan, defaultSpanLineHeight);+ createAndUpdateBlockAnchor(paragraphIndex, newLine, lineTop, drawingAnchor);+ _divideOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);}function _columnOperator(@@ -302,16 +297,15 @@ function _columnOperator(pages: IDocumentSkeletonPage[],sectionBreakConfig: ISectionBreakConfig,paragraphConfig: IParagraphConfig,- elementIndex: number = 0,- isFirstSpan: boolean = false,+ paragraphStart: boolean = false,defaultSpanLineHeight?: number) {const lastPage = getLastPage(pages);const column = isColumnFull(lastPage);if (column === true) {- _pageOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan, defaultSpanLineHeight);+ _pageOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);} else {- _lineOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan, defaultSpanLineHeight);+ _lineOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);}}@@ -320,14 +314,13 @@ function _pageOperator(pages: IDocumentSkeletonPage[],sectionBreakConfig: ISectionBreakConfig,paragraphConfig: IParagraphConfig,- elementIndex: number = 0,- isFirstSpan: boolean = false,+ paragraphStart: boolean = false,defaultSpanLineHeight?: number) {const curSkeletonPage: IDocumentSkeletonPage = getLastPage(pages);const { skeHeaders, skeFooters } = paragraphConfig;pages.push(createSkeletonPage(sectionBreakConfig, { skeHeaders, skeFooters }, curSkeletonPage?.pageNumber));- _columnOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan, defaultSpanLineHeight);+ _columnOperator(spanGroup, pages, sectionBreakConfig, paragraphConfig, paragraphStart, defaultSpanLineHeight);}/**diff --git a/packages/base-render/src/Component/Docs/Block/Paragraph/Paragraph.ts b/packages/base-render/src/Component/Docs/Block/Paragraph/Paragraph.tsindex 16cf1f1578..c779b65ac7 100644--- a/packages/base-render/src/Component/Docs/Block/Paragraph/Paragraph.ts+++ b/packages/base-render/src/Component/Docs/Block/Paragraph/Paragraph.ts@@ -1,28 +1,59 @@-import { ColumnSeparatorType, IBullet, IDrawing, IDrawings, IParagraph, Nullable, ParagraphElementType, PositionedObjectLayoutType, ContextBase, IElement } from '@univerjs/core';-import { dealWidthTextRun } from './TextRun';+import {+ ColumnSeparatorType,+ IBullet,+ IDrawing,+ IDrawings,+ Nullable,+ PositionedObjectLayoutType,+ ContextBase,+ DataStreamTreeNode,+ GridType,+ NamedStyleType,+ HorizontalAlign,+ SpacingRule,+ BooleanNumber,+ DataStreamTreeTokenType,+} from '@univerjs/core';import { dealWidthBullet } from './Bullet';import { dealWidthInlineDrawing } from './InlineDrawing';-import { getLastNotFullColumnInfo } from '../../Common/Tools';+import { getCharSpaceApply, getLastNotFullColumnInfo, getSpanGroupWidth, lineIterator } from '../../Common/Tools';import { createSkeletonPage } from '../../Common/Page';import { setColumnFullState } from '../../Common/Section';-import { BreakType, IDocumentSkeletonBullet, IDocumentSkeletonDrawing, IDocumentSkeletonPage, ISkeletonResourceReference } from '../../../../Basics/IDocumentSkeletonCached';+import { calculateParagraphLayout } from './Layout.Ruler';++import { composeCharForLanguage } from './Language.Ruler';++import {+ BreakType,+ IDocumentSkeletonBullet,+ IDocumentSkeletonDrawing,+ IDocumentSkeletonLine,+ IDocumentSkeletonPage,+ ISkeletonResourceReference,+} from '../../../../Basics/IDocumentSkeletonCached';import { IParagraphConfig, ISectionBreakConfig } from '../../../../Basics/Interfaces';+import { getFontStyleString } from '../../../../Basics/Tools';+import { createSkeletonTabSpan, createSkeletonWordSpan } from '../../Common/Span';export function dealWidthParagraph(- blockId: string,- paragraph: IParagraph,+ paragraphNode: DataStreamTreeNode,curPage: IDocumentSkeletonPage,sectionBreakConfig: ISectionBreakConfig,skeletonResourceReference: ISkeletonResourceReference,context?: ContextBase): IDocumentSkeletonPage[] {const {+ gridType = GridType.LINES,+ charSpace = 0,+ documentTextStyle = {},+ defaultTabStop = 10.5,+pageNumberStart,pageSize = {- w: Infinity,- h: Infinity,+ width: Infinity,+ height: Infinity,},marginRight = 0,@@ -39,13 +70,19 @@ export function dealWidthParagraph(fontLocale,} = sectionBreakConfig;- const { elements, paragraphStyle = {}, bullet } = paragraph;+ const { endIndex, startIndex, content = '' } = paragraphNode;++ const bodyModel = paragraphNode.bodyModel;++ const paragraph = bodyModel.getParagraph(endIndex) || { startIndex: 0 };++ const { paragraphStyle = {}, bullet } = paragraph;// const paragraphAffectSkeDrawings = _changeDrawingToSkeletonFormat(drawingIds, drawings);// curPage.skeDrawings = paragraphAffectSkeDrawings;- const { skeHeaders, skeFooters, skeListLevel, blockAnchor } = skeletonResourceReference;+ const { skeHeaders, skeFooters, skeListLevel, drawingAnchor } = skeletonResourceReference;// const pageWidth = pageSize.w || Infinity;// const pageHeight = pageSize.h || Infinity;@@ -58,16 +95,16 @@ export function dealWidthParagraph(// curPage.skeDrawings = affectSkeDrawings; // 加入本段落的对象const paragraphConfig: IParagraphConfig = {- blockId,+ paragraphIndex: endIndex,paragraphStyle,// paragraphAffectSkeDrawings,skeHeaders,skeFooters,- blockAnchor,+ drawingAnchor,};- const pages = [curPage];- let lastPage = curPage;+ // const pages = [curPage];+ // let lastPage = curPage;// if (pageSize.h === Infinity) {// // 无需分页的情况,适合表格单元格或者类似notion的block布局@@ -85,51 +122,110 @@ export function dealWidthParagraph(const listLevelAncestors = _getListLevelAncestors(bullet, skeListLevel); // 取得列表所有level的缓存const bulletSkeleton = dealWidthBullet(bullet, lists, listLevelAncestors, fontLocale, context); // 生成bullet_updateListLevelAncestors(bullet, bulletSkeleton, skeListLevel); // 更新最新的level缓存列表- paragraphConfig.bulletSkeleton = bulletSkeleton;+ // paragraphConfig.bulletSkeleton = bulletSkeleton;- elements.forEach((element: IElement, elementIndex: number) => {- const { eId: elementId, et: paragraphElementType } = element;- let currentPages: IDocumentSkeletonPage[] = [];- if (paragraphElementType === ParagraphElementType.DRAWING) {- const drawingOrigin = drawings[elementId];+ const {+ namedStyleType = NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED,+ horizontalAlign = HorizontalAlign.UNSPECIFIED,+ lineSpacing = 1,+ spacingRule = SpacingRule.AUTO,+ snapToGrid = BooleanNumber.TRUE,+ direction,+ spaceAbove = 0,+ spaceBelow = 0,+ borderBetween,+ borderTop,+ borderBottom,+ borderLeft,+ borderRight,+ indentFirstLine = 0,+ hanging = 0,+ indentStart = 0,+ indentEnd = 0,+ tabStops = [],+ keepLines = BooleanNumber.FALSE,+ keepNext = BooleanNumber.FALSE,+ wordWrap = BooleanNumber.FALSE,+ widowControl = BooleanNumber.FALSE,+ shading,+ } = paragraphStyle;++ let allPages: IDocumentSkeletonPage[] = [curPage];+ const pageWidth = pageSize.width || Infinity - marginLeft - marginRight;++ for (let i = 0, len = content.length; i < len; i++) {+ const charIndex = i + startIndex;+ const char = content[i];++ const textRun = bodyModel.getTextRun(charIndex) || { ts: {} };+ const { ts: textStyle = {} } = textRun;+ const fontStyle = getFontStyleString(textStyle, fontLocale);++ const mixTextStyle = {+ ...documentTextStyle,+ ...textStyle,+ };++ const fontCreateConfig = {+ fontStyle,+ textStyle: mixTextStyle,+ charSpace,+ gridType,+ snapToGrid,+ pageWidth,+ };++ if (char === DataStreamTreeTokenType.TAB) {+ const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);+ const tabSpan = createSkeletonTabSpan(fontCreateConfig, charSpaceApply); // measureText收敛到create中执行+ allPages = calculateParagraphLayout([tabSpan], allPages, sectionBreakConfig, paragraphConfig, true);+ } else if (char === DataStreamTreeTokenType.CUSTOM_BLOCK) {+ const customBlock = bodyModel.getCustomBlock(charIndex);+ if (customBlock == null) {+ continue;+ }+ const blockId = customBlock.blockId;+ const drawingOrigin = drawings[blockId];if (drawingOrigin.layoutType === PositionedObjectLayoutType.INLINE) {- currentPages = dealWidthInlineDrawing(drawingOrigin, elementIndex, sectionBreakConfig, lastPage, paragraphConfig, fontLocale);+ allPages = dealWidthInlineDrawing(drawingOrigin, sectionBreakConfig, allPages, paragraphConfig, fontLocale);} else {- paragraphAffectSkeDrawings.set(elementId, _getDrawingSkeletonFormat(drawingOrigin));- }- }- });-- // let currentLine = createSkeletonLine({ ...paragraphConfig, bulletSkeleton, affectSkeDrawings: affectAllSkeDrawings });- // 处理1列的情况- // 如果下一节是连续的,则按照1列进行计算,计算结果返回后,用来预估列高度,然后在接来下的流程进行二次计算- elements.forEach((element: IElement, elementIndex: number) => {- const { eId: elementId, et: paragraphElementType } = element;- let currentPages: IDocumentSkeletonPage[] = [];- if (paragraphElementType === ParagraphElementType.TEXT_RUN) {- const { tr: textRun, st, ed } = element;- if (!textRun) {- return false;+ paragraphAffectSkeDrawings.set(blockId, _getDrawingSkeletonFormat(drawingOrigin));}- currentPages = dealWidthTextRun(textRun, elementIndex, sectionBreakConfig, lastPage, { ...paragraphConfig, paragraphAffectSkeDrawings }, fontLocale);- } else if (paragraphElementType === ParagraphElementType.PAGE_BREAK) {- // 换页标识,换页后还在同一个节内- currentPages = [createSkeletonPage(sectionBreakConfig, skeletonResourceReference, _getNextPageNumber(lastPage), BreakType.PAGE)];+ } else if (char === DataStreamTreeTokenType.PAGE_BREAK) {+ allPages.push(createSkeletonPage(sectionBreakConfig, skeletonResourceReference, _getNextPageNumber(allPages[allPages.length - 1]), BreakType.PAGE));paragraphAffectSkeDrawings.clear();- } else if (paragraphElementType === ParagraphElementType.COLUMN_BREAK) {+ } else if (char === DataStreamTreeTokenType.COLUMN_BREAK) {// 换列标识,还在同一个节内+ const lastPage = allPages[allPages.length - 1];const columnInfo = getLastNotFullColumnInfo(lastPage);if (columnInfo && !columnInfo.isLast) {setColumnFullState(columnInfo.column, true);} else {- currentPages = [createSkeletonPage(sectionBreakConfig, skeletonResourceReference, _getNextPageNumber(lastPage), BreakType.COLUMN)];+ allPages.push(createSkeletonPage(sectionBreakConfig, skeletonResourceReference, _getNextPageNumber(lastPage), BreakType.COLUMN));}+ } else {+ const paragraphStart = i === 0;+ const languageHandlerResult = composeCharForLanguage(char, i, content, fontCreateConfig); // Handling special languages such as Tibetan, Arabic+ let newSpanGroup = [];+ if (languageHandlerResult) {+ const { charIndex: newCharIndex, spanGroup } = languageHandlerResult;+ i = newCharIndex;+ newSpanGroup = spanGroup;+ } else {+ const span = createSkeletonWordSpan(char, fontCreateConfig); // measureText收敛到create中执行+ newSpanGroup.push(span);+ }++ allPages = calculateParagraphLayout(newSpanGroup, allPages, sectionBreakConfig, paragraphConfig, paragraphStart);}+ }- lastPage = _checkAndPush(pages, currentPages); // The layout engine does not have a page break, so it does not need to be added to the page array+ lineIterator(allPages, (line: IDocumentSkeletonLine) => {+ horizontalAlignHandler(line, horizontalAlign);});- return pages;++ return allPages;}function _getListLevelAncestors(bullet?: IBullet, listLevel?: Map<string, IDocumentSkeletonBullet[]>): Array<Nullable<IDocumentSkeletonBullet>> | undefined {@@ -227,3 +323,28 @@ function _checkAndPush(pages: IDocumentSkeletonPage[], currentPages: IDocumentSkfunction _getNextPageNumber(lastPage: IDocumentSkeletonPage) {return lastPage.pageNumber + 1;}++function horizontalAlignHandler(line: IDocumentSkeletonLine, horizontalAlign: HorizontalAlign) {+ if (horizontalAlign === HorizontalAlign.UNSPECIFIED || horizontalAlign === HorizontalAlign.LEFT) {+ return;+ }++ const { divides } = line;+ const divideLength = divides.length;+ for (let i = 0; i < divideLength; i++) {+ const divide = divides[i];+ const { width, spanGroup } = divide;+ const spanGroupWidth = getSpanGroupWidth(divide);+ // console.log(spanGroup, spanGroupWidth, width);+ if (width === Infinity) {+ continue;+ }+ if (horizontalAlign === HorizontalAlign.CENTER) {+ divide.paddingLeft = (width - spanGroupWidth) / 2;+ } else if (horizontalAlign === HorizontalAlign.RIGHT) {+ divide.paddingLeft = width - spanGroupWidth;+ } else if (horizontalAlign === HorizontalAlign.JUSTIFIED) {+ /**todo */+ }+ }+}diff --git a/packages/base-render/src/Component/Docs/Block/Paragraph/TextRun.ts b/packages/base-render/src/Component/Docs/Block/Paragraph/TextRun.tsdeleted file mode 100644index 882d4af3b7..0000000000--- a/packages/base-render/src/Component/Docs/Block/Paragraph/TextRun.ts+++ /dev/null@@ -1,137 +0,0 @@-import { BooleanNumber, GridType, HorizontalAlign, ITextRun, NamedStyleType, SpacingRule } from '@univerjs/core';-import { composeCharForLanguage } from './Language.Ruler';-import { calculateParagraphLayout } from './Layout.Ruler';--import { IFontLocale, IParagraphConfig, ISectionBreakConfig } from '../../../../Basics/Interfaces';-import { getCharSpaceApply, getSpanGroupWidth, lineIterator } from '../../Common/Tools';-import { createSkeletonTabSpan, createSkeletonWordSpan } from '../../Common/Span';-import { getFontStyleString } from '../../../../Basics/Tools';--// import { getCharSpaceApply, getSpanGroupWidth, lineIterator } from '../../Common/Tools';-// import { createSkeletonTabSpan, createSkeletonWordSpan } from '../../Common/Span';-import { IDocumentSkeletonLine, IDocumentSkeletonPage } from '../../../../Basics/IDocumentSkeletonCached';--export function dealWidthTextRun(- textRun: ITextRun,- elementIndex: number = 0,- sectionBreakConfig: ISectionBreakConfig,- currentPage: IDocumentSkeletonPage,- paragraphConfig: IParagraphConfig,- fontLocale?: IFontLocale-): IDocumentSkeletonPage[] {- const { ct: content = '', ts: textStyle = {}, tab = false } = textRun;- const fontStyle = getFontStyleString(textStyle, fontLocale);- const { paragraphStyle = {} } = paragraphConfig;- const {- gridType = GridType.LINES,- charSpace = 0,- documentTextStyle = {},- defaultTabStop = 10.5,- pageSize = {- width: Infinity,- height: Infinity,- },- marginLeft = 0,- marginRight = 0,- } = sectionBreakConfig;- const {- namedStyleType = NamedStyleType.NAMED_STYLE_TYPE_UNSPECIFIED,- horizontalAlign = HorizontalAlign.UNSPECIFIED,- lineSpacing = 1,- spacingRule = SpacingRule.AUTO,- snapToGrid = BooleanNumber.TRUE,- direction,- spaceAbove = 0,- spaceBelow = 0,- borderBetween,- borderTop,- borderBottom,- borderLeft,- borderRight,- indentFirstLine = 0,- hanging = 0,- indentStart = 0,- indentEnd = 0,- tabStops = [],- keepLines = BooleanNumber.FALSE,- keepNext = BooleanNumber.FALSE,- wordWrap = BooleanNumber.FALSE,- widowControl = BooleanNumber.FALSE,- shading,- } = paragraphStyle;-- let allPages: IDocumentSkeletonPage[] = [currentPage];- const pageWidth = pageSize.width || Infinity - marginLeft - marginRight;- const mixTextStyle = {- ...documentTextStyle,- ...textStyle,- };-- const fontCreateConfig = {- fontStyle,- textStyle: mixTextStyle,- charSpace,- gridType,- snapToGrid,- pageWidth,- };-- if (tab) {- const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);- const tabSpan = createSkeletonTabSpan(fontCreateConfig, charSpaceApply); // measureText收敛到create中执行- allPages = calculateParagraphLayout([tabSpan], allPages, sectionBreakConfig, paragraphConfig, elementIndex, true);- return allPages;- }-- const arrayText = content.split('');-- // console.log(arrayText, pageSize);-- for (let charIndex = 0; charIndex < arrayText.length; charIndex++) {- const char = arrayText[charIndex];- const isFirstSpan = charIndex === 0;- const languageHandlerResult = composeCharForLanguage(char, charIndex, arrayText, fontCreateConfig); // Handling special languages such as Tibetan, Arabic- let newSpanGroup = [];- if (languageHandlerResult) {- const { charIndex: newCharIndex, spanGroup } = languageHandlerResult;- charIndex = newCharIndex;- newSpanGroup = spanGroup;- } else {- const span = createSkeletonWordSpan(char, fontCreateConfig); // measureText收敛到create中执行- newSpanGroup.push(span);- }-- allPages = calculateParagraphLayout(newSpanGroup, allPages, sectionBreakConfig, paragraphConfig, elementIndex, isFirstSpan);- }-- lineIterator(allPages, (line: IDocumentSkeletonLine) => {- horizontalAlignHandler(line, horizontalAlign);- });-- return allPages;-}--function horizontalAlignHandler(line: IDocumentSkeletonLine, horizontalAlign: HorizontalAlign) {- if (horizontalAlign === HorizontalAlign.UNSPECIFIED || horizontalAlign === HorizontalAlign.LEFT) {- return;- }-- const { divides } = line;- const divideLength = divides.length;- for (let i = 0; i < divideLength; i++) {- const divide = divides[i];- const { width, spanGroup } = divide;- const spanGroupWidth = getSpanGroupWidth(divide);- // console.log(spanGroup, spanGroupWidth, width);- if (width === Infinity) {- continue;- }- if (horizontalAlign === HorizontalAlign.CENTER) {- divide.paddingLeft = (width - spanGroupWidth) / 2;- } else if (horizontalAlign === HorizontalAlign.RIGHT) {- divide.paddingLeft = width - spanGroupWidth;- } else if (horizontalAlign === HorizontalAlign.JUSTIFIED) {- /**todo */- }- }-}diff --git a/packages/base-render/src/Component/Docs/Block/Paragraph/index.ts b/packages/base-render/src/Component/Docs/Block/Paragraph/index.tsindex 5f29ac7a01..7dcfd428b8 100644--- a/packages/base-render/src/Component/Docs/Block/Paragraph/index.ts+++ b/packages/base-render/src/Component/Docs/Block/Paragraph/index.ts@@ -4,4 +4,3 @@ export * from './InlineDrawing';export * from './Language.Ruler';export * from './Layout.Ruler';export * from './Paragraph';-export * from './TextRun';diff --git a/packages/base-render/src/Component/Docs/Block/Block.ts b/packages/base-render/src/Component/Docs/Block/Section.tssimilarity index 55%rename from packages/base-render/src/Component/Docs/Block/Block.tsrename to packages/base-render/src/Component/Docs/Block/Section.tsindex 49f16350cc..e0bd43e668 100644--- a/packages/base-render/src/Component/Docs/Block/Block.ts+++ b/packages/base-render/src/Component/Docs/Block/Section.ts@@ -1,12 +1,11 @@-import { BlockType, ContextBase, IBlockElement } from '@univerjs/core';+import { DataStreamTreeNodeType, ContextBase, DataStreamTreeNode } from '@univerjs/core';import { dealWidthParagraph } from './Paragraph';import { dealWithBlockError } from './BlockError';import { IDocumentSkeletonPage, ISkeletonResourceReference } from '../../../Basics/IDocumentSkeletonCached';import { ISectionBreakConfig } from '../../../Basics/Interfaces';-import { dealWidthCustomBlock } from '../../../Custom/UseCustom';-export function dealWithBlocks(- Blocks: IBlockElement[],+export function dealWithSections(+ sectionNode: DataStreamTreeNode,curPage: IDocumentSkeletonPage,sectionBreakConfig: ISectionBreakConfig,skeletonResourceReference: ISkeletonResourceReference,@@ -15,34 +14,30 @@ export function dealWithBlocks() {const allCurrentSkeletonPages: IDocumentSkeletonPage[] = [];const renderedBlockIdMap = new Map<string, boolean>();- for (let block of Blocks) {- const { paragraph, table, tableOfContents, blockType, customBlock, blockId } = block;- if (preRenderedBlockIdMap?.get(blockId)) {- continue;- }- let blockSkeletonPages: IDocumentSkeletonPage[] = [];+ for (let node of sectionNode.children) {+ // const { paragraph, table, tableOfContents, blockType, customBlock, blockId } = block;+ // if (preRenderedBlockIdMap?.get(blockId)) {+ // continue;+ // }+ let skeletonPages: IDocumentSkeletonPage[] = [];let currentPageCache = curPage;if (allCurrentSkeletonPages.length > 0) {currentPageCache = allCurrentSkeletonPages[allCurrentSkeletonPages.length - 1];}- if (blockType === BlockType.PARAGRAPH && paragraph) {+ if (node.nodeType === DataStreamTreeNodeType.PARAGRAPH) {// Paragraph 段落- blockSkeletonPages = dealWidthParagraph(block.blockId, paragraph, currentPageCache, sectionBreakConfig, skeletonResourceReference, context);- } else if (blockType === BlockType.TABLE && table) {+ skeletonPages = dealWidthParagraph(node, currentPageCache, sectionBreakConfig, skeletonResourceReference, context);+ } else if (node.nodeType === DataStreamTreeNodeType.TABLE) {// Table 表格- } else if (blockType === BlockType.SECTION_BREAK && tableOfContents) {- // TableOfContents 目录- } else if (blockType === BlockType.CUSTOM) {- blockSkeletonPages = dealWidthCustomBlock(block.blockId, customBlock, currentPageCache, sectionBreakConfig, skeletonResourceReference, context);}- if (blockSkeletonPages.length === 0) {- blockSkeletonPages = dealWithBlockError();+ if (skeletonPages.length === 0) {+ skeletonPages = dealWithBlockError();}- _pushPage(allCurrentSkeletonPages, blockSkeletonPages);+ _pushPage(allCurrentSkeletonPages, skeletonPages);- renderedBlockIdMap.set(blockId, true);+ // renderedBlockIdMap.set(blockId, true);}return {diff --git a/packages/base-render/src/Component/Docs/Block/TableOfContents.ts b/packages/base-render/src/Component/Docs/Block/TableOfContents.tsdeleted file mode 100644index 698ed86160..0000000000--- a/packages/base-render/src/Component/Docs/Block/TableOfContents.ts+++ /dev/null@@ -1 +0,0 @@-export class TableOfContents {}diff --git a/packages/base-render/src/Component/Docs/Block/index.ts b/packages/base-render/src/Component/Docs/Block/index.tsindex aa9a9eef7b..2110f37cde 100644--- a/packages/base-render/src/Component/Docs/Block/index.ts+++ b/packages/base-render/src/Component/Docs/Block/index.ts@@ -1,4 +1,3 @@export * from './Paragraph';-export * from './TableOfContents';export * from './BlockError';-export * from './Block';+export * from './Section';diff --git a/packages/base-render/src/Component/Docs/Common/Line.ts b/packages/base-render/src/Component/Docs/Common/Line.tsindex 78221762b7..3ef2ac860b 100644--- a/packages/base-render/src/Component/Docs/Common/Line.ts+++ b/packages/base-render/src/Component/Docs/Common/Line.ts@@ -1,6 +1,6 @@import { IDrawing, Nullable, PositionedObjectLayoutType, WrapTextType } from '@univerjs/core';import {- IDocumentSkeletonBlockAnchor,+ IDocumentSkeletonDrawingAnchor,IDocumentSkeletonDivide,IDocumentSkeletonDrawing,IDocumentSkeletonLine,@@ -44,13 +44,12 @@ interface ILineBoundingBox {// 处理divides, divideLen, lineIndex, 无序和有序列表标题, drawingTBIds 影响行的元素id集合export function createSkeletonLine(- blockId: string,+ paragraphIndex: number,lineType: LineType,lineBoundingBox: ILineBoundingBox,columnWidth: number,lineIndex: number = 0,- elementIndex: number = 0,- isFirstSpan: boolean = false,+ isParagraphStart: boolean = false,affectSkeDrawings?: Map<string, IDocumentSkeletonDrawing>,headersDrawings?: Map<string, IDocumentSkeletonDrawing>,footersDrawings?: Map<string, IDocumentSkeletonDrawing>@@ -67,9 +66,9 @@ export function createSkeletonLine(spaceBelowApply = 0,} = lineBoundingBox;- const lineSke = _getLineSke(lineType, blockId);+ const lineSke = _getLineSke(lineType, paragraphIndex);lineSke.lineIndex = lineIndex;- lineSke.paragraphStart = isParagraphStart(elementIndex, isFirstSpan); // 是否段落开始的第一行+ lineSke.paragraphStart = isParagraphStart; // 是否段落开始的第一行lineSke.contentHeight = contentHeight;lineSke.top = lineTop;lineSke.lineHeight = lineHeight;@@ -90,7 +89,6 @@ export function createSkeletonLine(export function calculateLineTopByDrawings(lineHeight: number = 15.6,lineTop: number = 0,- elementIndex: number = 0,pageSkeDrawings?: Map<string, IDocumentSkeletonDrawing>,headersDrawings?: Map<string, IDocumentSkeletonDrawing>,footersDrawings?: Map<string, IDocumentSkeletonDrawing>@@ -111,7 +109,7 @@ export function calculateLineTopByDrawings(});pageSkeDrawings?.forEach((drawing) => {- const top = _getLineTopWidthWrapTopBottom(drawing, lineHeight, lineTop, elementIndex);+ const top = _getLineTopWidthWrapTopBottom(drawing, lineHeight, lineTop);if (top) {maxTop = Math.max(maxTop, top);}@@ -120,7 +118,7 @@ export function calculateLineTopByDrawings(return maxTop;}-function _getLineTopWidthWrapTopBottom(drawing: IDocumentSkeletonDrawing, lineHeight: number, lineTop: number, elementIndex?: number) {+function _getLineTopWidthWrapTopBottom(drawing: IDocumentSkeletonDrawing, lineHeight: number, lineTop: number) {const { aTop, height, aLeft, width, angle = 0, drawingOrigin } = drawing;const { layoutType, distT = 0, distB = 0 } = drawingOrigin;@@ -399,9 +397,9 @@ function __getDivideSKe(left: number, width: number): IDocumentSkeletonDivide {};}-function _getLineSke(lineType: LineType, blockId: string): IDocumentSkeletonLine {+function _getLineSke(lineType: LineType, paragraphIndex: number): IDocumentSkeletonLine {return {- blockId,+ paragraphIndex,type: lineType,divides: [], // /divides 受到对象影响,把行切分为N部分lineHeight: 0, // lineHeight =max(span.fontBoundingBoxAscent + span.fontBoundingBoxDescent, span2.....) + space@@ -421,21 +419,17 @@ function _getLineSke(lineType: LineType, blockId: string): IDocumentSkeletonLine};}-export function isParagraphStart(elementIndex: number, isFirstSpan: boolean) {- return elementIndex === 0 && isFirstSpan === true;-}--export function createAndUpdateBlockAnchor(blockId: string, line: IDocumentSkeletonLine, top: number, blockAnchor?: Map<string, IDocumentSkeletonBlockAnchor>) {- if (!blockAnchor) {+export function createAndUpdateBlockAnchor(paragraphIndex: number, line: IDocumentSkeletonLine, top: number, drawingAnchor?: Map<number, IDocumentSkeletonDrawingAnchor>) {+ if (!drawingAnchor) {return;}- if (blockAnchor.has(blockId)) {- const anchor = blockAnchor.get(blockId);+ if (drawingAnchor.has(paragraphIndex)) {+ const anchor = drawingAnchor.get(paragraphIndex);anchor?.elements.push(line);} else {- blockAnchor.set(blockId, {+ drawingAnchor.set(paragraphIndex, {elements: [line],- blockId,+ paragraphIndex,top,});}diff --git a/packages/base-render/src/Component/Docs/Common/Page.ts b/packages/base-render/src/Component/Docs/Common/Page.tsindex 1c70f4969c..d1fa1d15ee 100644--- a/packages/base-render/src/Component/Docs/Common/Page.ts+++ b/packages/base-render/src/Component/Docs/Common/Page.ts@@ -1,8 +1,8 @@-import { IBlockElement, IFooterData, IHeaderData, Nullable, PageOrientType } from '@univerjs/core';+import { DocumentBodyModel, Nullable, PageOrientType } from '@univerjs/core';import { createSkeletonSection } from './Section';import { BreakType, IDocumentSkeletonFooter, IDocumentSkeletonHeader, IDocumentSkeletonPage, ISkeletonResourceReference } from '../../../Basics/IDocumentSkeletonCached';import { ISectionBreakConfig } from '../../../Basics/Interfaces';-import { dealWithBlocks } from '../Block';+import { dealWithSections } from '../Block/Section';import { updateBlockIndex } from './Tools';// 新增数据结构框架@@ -23,8 +23,8 @@ export function createSkeletonPage(footerIds = {},useFirstPageHeaderFooter,useEvenPageHeaderFooter,- footers,- headers,+ footerTreeMap,+ headerTreeMap,columnProperties = [],columnSeparatorType,marginTop = 0,@@ -69,8 +69,8 @@ export function createSkeletonPage(if (headerId) {if (skeHeaders.get(headerId)?.has(pageWidth)) {header = skeHeaders.get(headerId)?.get(pageWidth);- } else if (headers) {- header = _createSkeletonHeader(headers[headerId], sectionBreakConfig, skeletonResourceReference) as IDocumentSkeletonHeader;+ } else if (headerTreeMap && headerTreeMap.has(headerId)) {+ header = _createSkeletonHeader(headerTreeMap.get(headerId)!, sectionBreakConfig, skeletonResourceReference) as IDocumentSkeletonHeader;skeHeaders.set(headerId, new Map([[pageWidth, header]]));}page.headerId = headerId;@@ -79,8 +79,8 @@ export function createSkeletonPage(if (footerId) {if (skeFooters.get(footerId)?.has(pageWidth)) {footer = skeFooters.get(footerId)?.get(pageWidth);- } else if (footers) {- footer = _createSkeletonHeader(footers[footerId], sectionBreakConfig, skeletonResourceReference) as IDocumentSkeletonFooter;+ } else if (footerTreeMap && footerTreeMap.has(footerId)) {+ footer = _createSkeletonHeader(footerTreeMap.get(footerId)!, sectionBreakConfig, skeletonResourceReference) as IDocumentSkeletonFooter;skeFooters.set(headerId, new Map([[pageWidth, footer]]));}page.footerId = footerId;@@ -136,16 +136,15 @@ function _getNullPage() {}function _createSkeletonHeader(- headerOrFooter: IHeaderData | IFooterData,+ headerOrFooter: DocumentBodyModel,sectionBreakConfig: ISectionBreakConfig,skeletonResourceReference: ISkeletonResourceReference,isHeader = true): IDocumentSkeletonHeader | IDocumentSkeletonFooter {- const { body: headerOrFooterBody } = headerOrFooter;const {lists,- headers,- footers,+ footerTreeMap,+ headerTreeMap,fontLocale,pageSize,marginLeft = 0,@@ -159,8 +158,8 @@ function _createSkeletonHeader(const pageWidth = pageSize?.width || Infinity;const headerConfig: ISectionBreakConfig = {lists,- headers,- footers,+ footerTreeMap,+ headerTreeMap,pageSize: {width: pageWidth - marginLeft - marginRight,height: Infinity,@@ -169,14 +168,8 @@ function _createSkeletonHeader(drawings,};- const { blockElements } = headerOrFooterBody;- const blockElementArray: IBlockElement[] = [];- blockElements.forEach((dcd: IBlockElement) => {- blockElementArray.push(dcd);- });-const areaPage = createSkeletonPage(headerConfig, skeletonResourceReference);- const page = dealWithBlocks(blockElementArray, areaPage, headerConfig, skeletonResourceReference).pages[0];+ const page = dealWithSections(headerOrFooter.children[0], areaPage, headerConfig, skeletonResourceReference).pages[0];updateBlockIndex([page]);const column = page.sections[0].columns[0];const height = column.height || 0;diff --git a/packages/base-render/src/Component/Docs/DocSkeleton.ts b/packages/base-render/src/Component/Docs/DocSkeleton.tsindex 0e96078368..c2e81ff0e9 100644--- a/packages/base-render/src/Component/Docs/DocSkeleton.ts+++ b/packages/base-render/src/Component/Docs/DocSkeleton.ts@@ -1,10 +1,9 @@import {ColumnSeparatorType,ContextBase,+ DocumentModelOrSimple,GridType,HorizontalAlign,- IBlockElement,- IDocumentData,ISectionBreak,ISectionColumnProperties,Observable,@@ -19,17 +18,19 @@ import { createSkeletonPage } from './Common/Page';import { createSkeletonSection } from './Common/Section';-import { dealWithBlocks } from './Block/Block';+import { dealWithSections } from './Block/Section';import { IDocumentSkeletonCached, IDocumentSkeletonPage, ISkeletonResourceReference } from '../../Basics/IDocumentSkeletonCached';import { IDocsConfig, ISectionBreakConfig } from '../../Basics/Interfaces';import { Skeleton } from '../Skeleton';import { IBoundRect } from '../../Basics/Vector2';-interface IDocumentContentMap {- blockElements: IBlockElement[];- sectionBreak?: ISectionBreak;-}+const DEFAULT_SECTION_BREAK: ISectionBreak = {+ columnProperties: [],+ columnSeparatorType: ColumnSeparatorType.NONE,+ sectionType: SectionType.SECTION_TYPE_UNSPECIFIED,+ startIndex: 0,+};export enum DocumentSkeletonState {PENDING = 'pending',@@ -38,50 +39,26 @@ export enum DocumentSkeletonState {INVALID = 'invalid',}-interface IDrawingUpdateConfig {- left: number;- top: number;- height: number;- width: number;-}-export class DocumentSkeleton extends Skeleton {onRecalculateChangeObservable = new Observable<IDocumentSkeletonCached>();- private _documentData: IDocumentData;+ private _docModel: DocumentModelOrSimple;private _skeletonData: IDocumentSkeletonCached;private _renderedBlockIdMap = new Map<string, boolean>();- constructor(documentData: IDocumentData, context: ContextBase) {+ constructor(docModel: DocumentModelOrSimple, context: ContextBase) {super(context);- this._documentData = documentData;+ this._docModel = docModel;}- static create(documentData: IDocumentData, context: ContextBase) {- return new DocumentSkeleton(documentData, context);+ static create(docModel: DocumentModelOrSimple, context: ContextBase) {+ return new DocumentSkeleton(docModel, context);}- updateDrawing(id: string, config: IDrawingUpdateConfig) {- const drawings = this._documentData.drawings;- if (!drawings) {- return;- }-- const drawing = drawings[id];-- if (!drawing) {- return;- }-- const objectProperties = drawing.objectProperties;-- objectProperties.size.width = config.width;- objectProperties.size.height = config.height;-- objectProperties.positionH.posOffset = config.left;- objectProperties.positionV.posOffset = config.top;+ getModel() {+ return this._docModel;}calculate(bounds?: IBoundRect) {@@ -98,81 +75,61 @@ export class DocumentSkeleton extends Skeleton {}getPageSize() {- return this._documentData.documentStyle.pageSize;- }-- updateDocumentDataPageSize(width?: number, height?: number) {- const documentStyle = this._documentData.documentStyle;- if (!documentStyle.pageSize) {- width = width ?? Infinity;- height = height ?? Infinity;- documentStyle.pageSize = {- width,- height,- };- return;- }-- if (width !== undefined) {- documentStyle.pageSize.width = width;- }-- if (height !== undefined) {- documentStyle.pageSize.height = height;- }- }-- private __getContentMapArr() {- const { body } = this._documentData;- if (!body) {- return [];- }- const { blockElements } = body;-- if (blockElements.length === 0) {- return [];- }-- const documentContentMapArr: IDocumentContentMap[] = [];- let documentContentMap: IDocumentContentMap = {- blockElements: [],- sectionBreak: undefined,- };- // sectionBreak会在一个段落的底部,定义之前所有段落的页样式。- blockElements.forEach((dcd: IBlockElement) => {- const { sectionBreak: sSectionBreak } = dcd;- if (sSectionBreak) {- documentContentMap.sectionBreak = sSectionBreak;- documentContentMapArr.push(documentContentMap);- documentContentMap = {- blockElements: [],- sectionBreak: undefined,- };- } else {- documentContentMap.blockElements.push(dcd);- }- });-- if (!documentContentMap.sectionBreak) {- documentContentMap.sectionBreak = {- columnProperties: [],- columnSeparatorType: ColumnSeparatorType.NONE,- sectionType: SectionType.SECTION_TYPE_UNSPECIFIED,- };-- if (documentContentMap.blockElements.length > 0) {- documentContentMapArr.push(documentContentMap);- }- }- // console.log('documentContentMapArr', documentContentMapArr, blockElements);- return documentContentMapArr;+ return this._docModel.documentStyle.pageSize;}+ // updateDocumentDataPageSize(width?: number, height?: number) {+ // const documentStyle = this._docModel.documentStyle;+ // if (!documentStyle.pageSize) {+ // width = width ?? Infinity;+ // height = height ?? Infinity;+ // documentStyle.pageSize = {+ // width,+ // height,+ // };+ // return;+ // }++ // if (width !== undefined) {+ // documentStyle.pageSize.width = width;+ // }++ // if (height !== undefined) {+ // documentStyle.pageSize.height = height;+ // }+ // }++ /**+ * \v COLUMN_BREAK 换列+ * \f PAGE_BREAK 换页+ * \0 DOCS_END 文档结尾+ * \t TAB 制表符+ *+ * Needs to be changed:+ * \r PARAGRAPH 段落+ * \n SECTION_BREAK 章节+ *+ * \b customBlock 图片 mention等不参与文档流的场景+ *+ * 表格+ * \x1A table start 表格开始+ * \x1B table row start 表格开始+ * \x1C table cell start 表格开始+ * \x1D table cell end 表格开始+ * \x1E table row end 表格开始+ * \x1F table end 表格结束+ *+ * 文档流内的特殊范围:超链接,field,structured document tags, bookmark,comment+ * \x1F customRange start 自定义范围开始+ * \x1E customRange end 自定义范围结束+ *+ * 按照SectionBreak分割文档,进行布局计算+ * @returns view model: skeleton+ */private _createSkeleton(bounds?: IBoundRect) {- const documentContentMapArr = this.__getContentMapArr();// 每一个布局const DEFAULT_PAGE_SIZE = { width: Infinity, height: Infinity };- const { documentStyle, footers, headers, lists, drawings } = this._documentData;+ const { documentStyle, headerTreeMap, footerTreeMap, lists, drawings } = this._docModel;const {pageNumberStart: global_pageNumberStart = 1, // pageNumberStartpageSize: global_pageSize = DEFAULT_PAGE_SIZE,@@ -210,15 +167,12 @@ export class DocumentSkeleton extends Skeleton {},} = documentStyle;const skeleton = this.__getNullSke();- if (documentContentMapArr.length === 0) {- return skeleton;- }const fontLocale = this.getFontLocale();const docsConfig: IDocsConfig = {- footers,- headers,+ headerTreeMap,+ footerTreeMap,lists,drawings,@@ -231,26 +185,24 @@ export class DocumentSkeleton extends Skeleton {documentTextStyle: textStyle,};- const { skeHeaders, skeFooters, skeListLevel, blockAnchor } = skeleton;+ const { skeHeaders, skeFooters, skeListLevel, drawingAnchor } = skeleton;const skeletonResourceReference: ISkeletonResourceReference = {skeHeaders,skeFooters,skeListLevel,- blockAnchor,+ drawingAnchor,};const allSkeletonPages: IDocumentSkeletonPage[] = [];skeleton.pages = allSkeletonPages;- // 按照SectionBreak分割文档,进行布局计算- for (let i = 0; i < documentContentMapArr.length; i++) {- const documentContentMap = documentContentMapArr[i];- if (!documentContentMap.sectionBreak) {- continue;- }+ const bodyModel = this._docModel.bodyModel;+ for (let i = 0, len = bodyModel.children.length; i < len; i++) {+ const sectionNode = bodyModel.children[i];+ const sectionBreak = bodyModel.getSectionBreak(sectionNode.endIndex) || DEFAULT_SECTION_BREAK;const {pageNumberStart = global_pageNumberStart,pageSize = global_pageSize,@@ -277,10 +229,10 @@ export class DocumentSkeleton extends Skeleton {sectionType,textDirection,renderConfig = global_renderConfig,- } = documentContentMap.sectionBreak;+ } = sectionBreak;- const dcmNext = documentContentMapArr[i + 1];- const sectionTypeNext = dcmNext?.sectionBreak?.sectionType;+ const sectionNodeNext = bodyModel.children[i + 1];+ const sectionTypeNext = bodyModel.getSectionBreak(sectionNodeNext.endIndex)?.sectionType;const headerIds = { defaultHeaderId, evenPageHeaderId, firstPageHeaderId };const footerIds = { defaultFooterId, evenPageFooterId, firstPageFooterId };@@ -332,7 +284,7 @@ export class DocumentSkeleton extends Skeleton {}// 计算页内布局,block结构const context = this.getContext();- const blockInfo = dealWithBlocks(documentContentMap.blockElements, curSkeletonPage, sectionBreakConfig, skeletonResourceReference, this._renderedBlockIdMap, context);+ const blockInfo = dealWithSections(sectionNode, curSkeletonPage, sectionBreakConfig, skeletonResourceReference, this._renderedBlockIdMap, context);// todo: 当本节有多个列,且下一节为连续节类型的时候,需要按照列数分割,重新计算linesif (sectionTypeNext === SectionType.CONTINUOUS && columnProperties.length > 0) {@@ -380,7 +332,7 @@ export class DocumentSkeleton extends Skeleton {skeHeaders: new Map(),skeFooters: new Map(),skeListLevel: new Map(),- blockAnchor: new Map(),+ drawingAnchor: new Map(),};}}diff --git a/packages/base-render/src/Component/Sheets/SheetSkeleton.ts b/packages/base-render/src/Component/Sheets/SheetSkeleton.tsindex 886ba0644d..cea759fae4 100644--- a/packages/base-render/src/Component/Sheets/SheetSkeleton.ts+++ b/packages/base-render/src/Component/Sheets/SheetSkeleton.ts@@ -1,5 +1,4 @@import {- BlockType,BooleanNumber,SheetContext,HorizontalAlign,@@ -14,7 +13,6 @@ import {ITextStyle,ObjectArray,ObjectMatrix,- ParagraphElementType,Styles,TextDirection,TextDirectionType,@@ -29,6 +27,7 @@ import {Nullable,getColorStyle,IDocumentRenderConfig,+ DocumentModelSimple,} from '@univerjs/core';import { BORDER_TYPE, COLOR_BLACK_RGB } from '../../Basics/Const';import { IStylesCache, BorderCache } from './Interfaces';@@ -700,7 +699,7 @@ export class SpreadsheetSkeleton extends Skeleton {const content = cell.m || cell.v;- let documentData: Nullable<IDocumentData>;+ let documentModel: Nullable<DocumentModelSimple>;let fontString = 'document';const cellOtherConfig = this._getOtherStyle(style) as CellOtherConfig;// const {@@ -724,7 +723,7 @@ export class SpreadsheetSkeleton extends Skeleton {centerAngle = 90;vertexAngle = 90;}- documentData = this._updateRenderConfigAndHorizon(cell.p, horizontalAlign, {+ documentModel = this._updateRenderConfigAndHorizon(cell.p, horizontalAlign, {horizontalAlign,verticalAlign,centerAngle,@@ -738,7 +737,7 @@ export class SpreadsheetSkeleton extends Skeleton {cache.font![fontString] = new ObjectMatrix();}- documentData = this._getDocumentDataByStyle(content.toString(), textStyle, cellOtherConfig);+ documentModel = this._getDocumentDataByStyle(content.toString(), textStyle, cellOtherConfig);}const fontCache = cache.font![fontString];@@ -747,8 +746,8 @@ export class SpreadsheetSkeleton extends Skeleton {if (isVertical === BooleanNumber.TRUE) {angle = 90;}- if (documentData) {- const documentSkeleton = DocumentSkeleton.create(documentData, this.getContext());+ if (documentModel) {+ const documentSkeleton = DocumentSkeleton.create(documentModel, this.getContext());if (angle === 0 || wrapStrategy !== WrapStrategy.WRAP) {documentSkeleton.calculate();// console.log(cell.v, documentSkeleton);@@ -769,7 +768,7 @@ export class SpreadsheetSkeleton extends Skeleton {return;}- if (!document.body?.blockElements) {+ if (!document.body?.dataStream) {return;}@@ -778,28 +777,38 @@ export class SpreadsheetSkeleton extends Skeleton {}document.documentStyle.renderConfig = renderConfig;- const blockElements = document.body.blockElements;- for (let blockElement of blockElements) {- // if (blockElement.blockType === BlockType.SECTION_BREAK) {- // if (!blockElement.sectionBreak) {- // blockElement.sectionBreak = {};- // }-- // blockElement.sectionBreak.renderConfig = renderConfig;- // } else- if (blockElement.blockType === BlockType.PARAGRAPH) {- if (!blockElement.paragraph) {- continue;- }-- if (!blockElement.paragraph.paragraphStyle) {- blockElement.paragraph.paragraphStyle = {};- }+ const paragraphs = document.body.paragraphs || [];- blockElement.paragraph.paragraphStyle.horizontalAlign = horizontalAlign;+ for (let paragraph of paragraphs) {+ if (!paragraph.paragraphStyle) {+ paragraph.paragraphStyle = {};}++ paragraph.paragraphStyle.horizontalAlign = horizontalAlign;}- return document;++ // const blockElements = document.body.blockElements;+ // for (let blockElement of blockElements) {+ // // if (blockElement.blockType === BlockType.SECTION_BREAK) {+ // // if (!blockElement.sectionBreak) {+ // // blockElement.sectionBreak = {};+ // // }++ // // blockElement.sectionBreak.renderConfig = renderConfig;+ // // } else+ // if (blockElement.blockType === BlockType.PARAGRAPH) {+ // if (!blockElement.paragraph) {+ // continue;+ // }++ // if (!blockElement.paragraph.paragraphStyle) {+ // blockElement.paragraph.paragraphStyle = {};+ // }++ // blockElement.paragraph.paragraphStyle.horizontalAlign = horizontalAlign;+ // }+ // }+ return new DocumentModelSimple(document);}private _getDocumentDataByStyle(content: string, textStyle: ITextStyle, config: CellOtherConfig) {@@ -831,44 +840,60 @@ export class SpreadsheetSkeleton extends Skeleton {const documentData: IDocumentData = {id: 'd',body: {- blockElements: [+ dataStream: `${content}\r\n`,+ textRuns: [{- blockId: 'oneParagraph',+ ts: textStyle,st: 0,- ed: contentLength,- blockType: BlockType.PARAGRAPH,- paragraph: {- paragraphStyle: {- horizontalAlign,- },- elements: [- {- eId: 'oneElement',- st: 0,- ed: contentLength,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: content,- ts: textStyle,- },- },- ],+ ed: contentLength - 1,+ },+ ],+ paragraphs: [+ {+ startIndex: contentLength,+ paragraphStyle: {+ horizontalAlign,},},- // oneSectionBreak: {- // blockId: 'oneSectionBreak',- // st: 0,- // ed: 0,- // blockType: BlockType.SECTION_BREAK,- // sectionBreak: {- // columnProperties: [],- // columnSeparatorType: ColumnSeparatorType.NONE,- // sectionType: SectionType.SECTION_TYPE_UNSPECIFIED,- // // textDirection: textDirectionDocument,- // // contentDirection: textDirection!,- // },- // },],+ // blockElements: [+ // {+ // blockId: 'oneParagraph',+ // st: 0,+ // ed: contentLength,+ // blockType: BlockType.PARAGRAPH,+ // paragraph: {+ // paragraphStyle: {+ // horizontalAlign,+ // },+ // elements: [+ // {+ // eId: 'oneElement',+ // st: 0,+ // ed: contentLength,+ // et: ParagraphElementType.TEXT_RUN,+ // tr: {+ // ct: content,+ // ts: textStyle,+ // },+ // },+ // ],+ // },+ // },+ // // oneSectionBreak: {+ // // blockId: 'oneSectionBreak',+ // // st: 0,+ // // ed: 0,+ // // blockType: BlockType.SECTION_BREAK,+ // // sectionBreak: {+ // // columnProperties: [],+ // // columnSeparatorType: ColumnSeparatorType.NONE,+ // // sectionType: SectionType.SECTION_TYPE_UNSPECIFIED,+ // // // textDirection: textDirectionDocument,+ // // // contentDirection: textDirection!,+ // // },+ // // },+ // ],},documentStyle: {pageSize: {@@ -889,7 +914,7 @@ export class SpreadsheetSkeleton extends Skeleton {},};- return documentData;+ return new DocumentModelSimple(documentData);}private ___setBorderProps(r: number, c: number, type: BORDER_TYPE, style: IStyleData, cache: IStylesCache) {diff --git a/packages/base-render/src/Component/Sheets/Spreadsheet.ts b/packages/base-render/src/Component/Sheets/Spreadsheet.tsindex 4ef8ad5122..b61f3ddf63 100644--- a/packages/base-render/src/Component/Sheets/Spreadsheet.ts+++ b/packages/base-render/src/Component/Sheets/Spreadsheet.ts@@ -635,7 +635,7 @@ export class Spreadsheet extends SheetComponent {let { startY, endY } = getCellByIndex(row, column, rowHeightAccumulation, columnWidthAccumulation, dataMergeCache);const cellHeight = endY - startY;- documentSkeleton.updateDocumentDataPageSize(cellHeight);+ documentSkeleton.getModel().updateDocumentDataPageSize(cellHeight);documentSkeleton.calculate();const contentSize = this.getDocsSkeletonPageSize(documentSkeleton, angle);diff --git a/packages/base-render/src/Shape/RichText.ts b/packages/base-render/src/Shape/RichText.tsindex b4081bf388..75252d97c6 100644--- a/packages/base-render/src/Shape/RichText.ts+++ b/packages/base-render/src/Shape/RichText.ts@@ -1,10 +1,8 @@// import { IShapeProps, Shape, IObjectFullState, Group, Scene } from '.';import {- BlockType,IDocumentData,IKeyValue,- ParagraphElementType,ContextBase,ITransformState,IStyleBase,@@ -13,6 +11,7 @@ import {IColorStyle,IBorderData,Nullable,+ DocumentModelSimple,} from '@univerjs/core';import { Canvas } from '../Canvas';import { BaseObject } from '../BaseObject';@@ -30,6 +29,10 @@ export interface IRichTextProps extends ITransformState, IStyleBase {forceRender?: boolean;}+interface MyInterface {+ [key: string]: number | string;+}+export const RICHTEXT_OBJECT_ARRAY = ['text', 'richText'];export class RichText extends BaseObject {@@ -93,7 +96,9 @@ export class RichText extends BaseObject {this._context = context;- this._documentSkeleton = DocumentSkeleton.create(this._documentData, this._context);+ const docModel = new DocumentModelSimple(this._documentData);++ this._documentSkeleton = DocumentSkeleton.create(docModel, this._context);this._documents = new Documents(`${this.oKey}_DOCUMENTS`, this._documentSkeleton, {pageMarginLeft: 0,@@ -105,7 +110,7 @@ export class RichText extends BaseObject {this.onTransformChangeObservable.add((changeState) => {const { type, value, preValue } = changeState;if (type === TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize || type === TRANSFORM_CHANGE_OBSERVABLE_TYPE.all) {- this._documentSkeleton.updateDocumentDataPageSize(this.width);+ docModel.updateDocumentDataPageSize(this.width);this._documentSkeleton.makeDirty(true);this._documentSkeleton.calculate();const size = this.getDocsSkeletonPageSize();@@ -142,11 +147,13 @@ export class RichText extends BaseObject {return;}themeKeys.forEach((key) => {+ // @ts-ignoreif (props[key] === undefined) {return true;}if (RICHTEXT_OBJECT_ARRAY.indexOf(key) === -1) {+ // @ts-ignorethis[`_${key}`] = props[key];}});@@ -198,7 +205,9 @@ export class RichText extends BaseObject {toJson() {const props: IKeyValue = {};RICHTEXT_OBJECT_ARRAY.forEach((key) => {+ // @ts-ignoreif (this[key]) {+ // @ts-ignoreprops[key] = this[key];}});@@ -217,39 +226,58 @@ export class RichText extends BaseObject {const documentData: IDocumentData = {id: 'd',body: {- blockElements: [+ dataStream: `${text}\r\n`,+ textRuns: [{- blockId: 'oneParagraph',- st: 0,- ed: contentLength,- blockType: BlockType.PARAGRAPH,- paragraph: {- elements: [- {- eId: 'oneElement',- st: 0,- ed: contentLength,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: text,- ts: {- fs: this._fs || 14,- ff: this._ff,- it: this._it,- bl: this._bl,- ul: this._ul,- st: this._st,- ol: this._ol,- bg: this._bg,- bd: this._bd,- cl: this._cl,- },- },- },- ],+ ts: {+ fs: this._fs || 14,+ ff: this._ff,+ it: this._it,+ bl: this._bl,+ ul: this._ul,+ st: this._st,+ ol: this._ol,+ bg: this._bg,+ bd: this._bd,+ cl: this._cl,},+ st: 0,+ ed: contentLength - 1,},],+ // blockElements: [+ // {+ // blockId: 'oneParagraph',+ // st: 0,+ // ed: contentLength,+ // blockType: BlockType.PARAGRAPH,+ // paragraph: {+ // elements: [+ // {+ // eId: 'oneElement',+ // st: 0,+ // ed: contentLength,+ // et: ParagraphElementType.TEXT_RUN,+ // tr: {+ // ct: text,+ // ts: {+ // fs: this._fs || 14,+ // ff: this._ff,+ // it: this._it,+ // bl: this._bl,+ // ul: this._ul,+ // st: this._st,+ // ol: this._ol,+ // bg: this._bg,+ // bd: this._bd,+ // cl: this._cl,+ // },+ // },+ // },+ // ],+ // },+ // },+ // ],},documentStyle: {pageSize: {@@ -262,7 +290,7 @@ export class RichText extends BaseObject {}private _initialProps(props?: IRichTextProps) {- this._documentSkeleton.updateDocumentDataPageSize(props?.width, props?.height);+ this._documentSkeleton.getModel().updateDocumentDataPageSize(props?.width, props?.height);this._documentSkeleton.calculate();diff --git a/packages/common-plugin-data/src/Docs/DEFAULT_DOCUMENT_DATA_EN.ts b/packages/common-plugin-data/src/Docs/DEFAULT_DOCUMENT_DATA_EN.tsindex da1370aabf..0c5db2eba7 100644--- a/packages/common-plugin-data/src/Docs/DEFAULT_DOCUMENT_DATA_EN.ts+++ b/packages/common-plugin-data/src/Docs/DEFAULT_DOCUMENT_DATA_EN.ts@@ -1,15 +1,4 @@-import {- BlockType,- BooleanNumber,- ColumnSeparatorType,- IDocumentData,- ObjectRelativeFromH,- ObjectRelativeFromV,- ParagraphElementType,- PositionedObjectLayoutType,- SectionType,- WrapTextType,-} from '@univerjs/core';+import { BooleanNumber, ColumnSeparatorType, IDocumentData, ObjectRelativeFromH, ObjectRelativeFromV, PositionedObjectLayoutType, SectionType, WrapTextType } from '@univerjs/core';import { DEFAULT_LIST_TEST } from './DEFAULT_LIST';export const DEFAULT_DOCUMENT_DATA_EN: IDocumentData = {@@ -70,539 +59,328 @@ export const DEFAULT_DOCUMENT_DATA_EN: IDocumentData = {},lists: DEFAULT_LIST_TEST,body: {- blockElements: [+ dataStream:+ 'What’s New in the 2022 Gartner Hype Cycle for Emerging Technologies\rEmerging technologies for 2022 fit into three main themes: evolving/expanding immersive experiences, accelerated artificial intelligence automation, and optimized technologist delivery.\rThe 2022 Gartner Hype Cycle identifies 25 must-know emerging technologies designed to help enterprise architecture and technology innovation leaders: \rExpand immersive experiences\rAccelerate artificial intelligence (AI) automation\rOptimize technologist delivery \rThese technologies are expected to greatly impact business and society over the next two to 10 years, but will especially enable CIOs and IT leaders to deliver on\rThree Hype Cycle themes to think about in 2022 and beyond\rThe 2022 Gartner Hype Cycle features emerging technologies and distills insights from more than 2,000 technologies into a succinct high-potential set. Most technologies have multiple use cases but enterprise architecture and technology innovation leaders should prioritize those with the greatest potential benefit for their organization. (They will also need to launch a proof-of-concept project to demonstrate the feasibility of a technology for their target use case.)\b\r\nThe benefit of these technologies is that they provide individuals with more control over their identities and data, and expand their range of experiences into virtual venues and ecosystems that can be integrated with digital currencies. These technologies also provide new ways to reach customers to strengthen or open up new revenue streams.\rDigital twin of the customer (DToC) is a dynamic virtual representation of a customer that simulates and learns to emulate and anticipate behavior. It can be used to modify and enhance the customer experience (CX) and support new digitalization efforts, products, services and opportunities. DToC will take five to 10 years until mainstream adoption but will be transformational to organizations.\rOther critical technologies in immersive experiences include the following:\rDecentralized identity (DCI) allows an entity (typically a human user) to control their own digital identity by leveraging technologies such as blockchain or other distributed ledger technologies (DLTs), along with digital wallets.\rDigital humans are interactive, AI-driven representations that have some of the characteristics, personality, knowledge and mindset of a human.\rInternal talent marketplaces match internal employees and, in some cases, a pool of contingent workers, to time-boxed projects and various work opportunities, with no recruiter involvement.\r\n\0',+ textRuns: [{- blockId: 'p1',st: 0,ed: 66,- blockType: BlockType.PARAGRAPH,- paragraph: {- elements: [- {- eId: 'e1',- st: 0,- ed: 66,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'What’s New in the 2022 Gartner Hype Cycle for Emerging Technologies',- ts: {- bl: BooleanNumber.TRUE,- fs: 24,- cl: {- rgb: 'rgb(0,40,86)',- },- },- },- },- ],- },- },- {- blockId: 'p2',- st: 67,- ed: 251,- blockType: BlockType.PARAGRAPH,- paragraph: {- paragraphStyle: {- spaceAbove: 20,- indentFirstLine: 20,+ ts: {+ bl: BooleanNumber.TRUE,+ fs: 24,+ cl: {+ rgb: 'rgb(0,40,86)',},- elements: [- {- eId: 'e1',- st: 67,- ed: 251,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'Emerging technologies for 2022 fit into three main themes: evolving/expanding immersive experiences, accelerated artificial intelligence automation, and optimized technologist delivery.',- ts: {- fs: 18,- cl: {- rgb: 'rgb(0,40,86)',- },- },- },- },- ],- },- },- {- blockId: 'p3',- st: 252,- ed: 401,- blockType: BlockType.PARAGRAPH,- paragraph: {- paragraphStyle: {- spaceAbove: 20,- indentFirstLine: 20,- },- elements: [- {- eId: 'e1',- st: 252,- ed: 401,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'The 2022 Gartner Hype Cycle identifies 25 must-know emerging technologies designed to help enterprise architecture and technology innovation leaders: ',- ts: {- fs: 16,- },- },- },- ],- },- },- {- blockId: 'p4',- st: 402,- ed: 429,- blockType: BlockType.PARAGRAPH,- paragraph: {- bullet: {- listId: 'testBullet',- nestingLevel: 0,- textStyle: {- fs: 20,- },- },- paragraphStyle: {- lineSpacing: 1.5,- },- elements: [- {- eId: 'e1',- st: 402,- ed: 429,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'Expand immersive experiences',- ts: {- fs: 16,- },- },- },- ],- },- },- {- blockId: 'p5',- st: 430,- ed: 479,- blockType: BlockType.PARAGRAPH,- paragraph: {- bullet: {- listId: 'testBullet',- nestingLevel: 0,- textStyle: {- fs: 20,- },- },- paragraphStyle: {- lineSpacing: 1.5,- },- elements: [- {- eId: 'e1',- st: 430,- ed: 479,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'Accelerate artificial intelligence (AI) automation',- ts: {- fs: 16,- },- },- },- ],- },- },- {- blockId: 'p6',- st: 480,- ed: 510,- blockType: BlockType.PARAGRAPH,- paragraph: {- bullet: {- listId: 'testBullet',- nestingLevel: 0,- textStyle: {- fs: 20,- },- },- paragraphStyle: {- lineSpacing: 1.5,+ },+ },+ {+ st: 68,+ ed: 252,+ ts: {+ fs: 18,+ cl: {+ rgb: 'rgb(0,40,86)',},- elements: [- {- eId: 'e1',- st: 480,- ed: 510,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'Optimize technologist delivery ',- ts: {- fs: 16,- },- },- },- ],- },- },- {- blockId: 'p7',- st: 511,- ed: 705,- blockType: BlockType.PARAGRAPH,- paragraph: {- paragraphStyle: {- indentFirstLine: 20,+ },+ },+ {+ st: 254,+ ed: 403,+ ts: {+ fs: 16,+ },+ },+ {+ st: 405,+ ed: 432,+ ts: {+ fs: 16,+ },+ },+ {+ st: 434,+ ed: 483,+ ts: {+ fs: 16,+ },+ },+ {+ st: 485,+ ed: 515,+ ts: {+ fs: 16,+ },+ },+ {+ st: 517,+ ed: 678,+ ts: {+ fs: 16,+ },+ },+ {+ st: 679,+ ed: 711,+ ts: {+ fs: 16,+ cl: {+ rgb: 'rgb(0, 0, 211)',},- elements: [- {- eId: 'e1',- st: 511,- ed: 672,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'These technologies are expected to greatly impact business and society over the next two to 10 years, but will especially enable CIOs and IT leaders to deliver on',- ts: {- fs: 16,- },- },- },- {- eId: 'e2',- st: 673,- ed: 705,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'digital business transformation. ',- ts: {- fs: 16,- cl: {- rgb: 'rgb(0, 0, 211)',- },- bl: BooleanNumber.TRUE,- },- },- },- ],- },- },- {- blockId: 'p8',- st: 706,- ed: 762,- blockType: BlockType.PARAGRAPH,- paragraph: {- paragraphStyle: {- spaceAbove: 20,+ bl: BooleanNumber.TRUE,+ },+ },+ {+ st: 713,+ ed: 769,+ ts: {+ fs: 24,+ cl: {+ rgb: 'rgb(255,255,255)',},- elements: [- {- eId: 'e1',- st: 706,- ed: 762,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'Three Hype Cycle themes to think about in 2022 and beyond',- ts: {- fs: 24,- cl: {- rgb: 'rgb(255,255,255)',- },- bg: {- rgb: 'rgb(0,40,86)',- },- },- },- },- ],- },- },- {- blockId: 'p9',- st: 763,- ed: 1233,- blockType: BlockType.PARAGRAPH,- paragraph: {- paragraphStyle: {- spaceAbove: 20,- indentFirstLine: 20,+ bg: {+ rgb: 'rgb(0,40,86)',},- elements: [- {- eId: 'e1',- st: 763,- ed: 1233,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'The 2022 Gartner Hype Cycle features emerging technologies and distills insights from more than 2,000 technologies into a succinct high-potential set. Most technologies have multiple use cases but enterprise architecture and technology innovation leaders should prioritize those with the greatest potential benefit for their organization. (They will also need to launch a proof-of-concept project to demonstrate the feasibility of a technology for their target use case.)',- ts: {- fs: 16,- },- },- },- {- eId: 'shapeTest1',- st: 0,- ed: 0,- et: ParagraphElementType.DRAWING,- },- ],- },- },- {- blockId: 'oneSectionBreak',- st: 0,- ed: 0,- blockType: BlockType.SECTION_BREAK,- sectionBreak: {- columnProperties: [],- columnSeparatorType: ColumnSeparatorType.NONE,- sectionType: SectionType.SECTION_TYPE_UNSPECIFIED,- // textDirection: textDirectionDocument,- // contentDirection: textDirection!,- },- },- {- blockId: 'p10',- st: 1206 + 28,- ed: 1548 + 28,- blockType: BlockType.PARAGRAPH,- paragraph: {- paragraphStyle: {- indentFirstLine: 20,+ },+ },+ {+ st: 1245,+ ed: 1587,+ ts: {+ fs: 16,+ },+ },+ {+ st: 1589,+ ed: 1984,+ ts: {+ fs: 16,+ },+ },+ {+ st: 1986,+ ed: 2060,+ ts: {+ fs: 16,+ },+ },+ {+ st: 2062,+ ed: 2084,+ ts: {+ fs: 16,+ cl: {+ rgb: 'rgb(0, 0, 211)',},- elements: [- {- eId: 'e1',- st: 1206 + 28,- ed: 1548 + 28,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'The benefit of these technologies is that they provide individuals with more control over their identities and data, and expand their range of experiences into virtual venues and ecosystems that can be integrated with digital currencies. These technologies also provide new ways to reach customers to strengthen or open up new revenue streams.',- ts: {- fs: 16,- },- },- },- ],- },- },- {- blockId: 'p11',- st: 1549 + 28,- ed: 1944 + 28,- blockType: BlockType.PARAGRAPH,- paragraph: {- paragraphStyle: {- indentFirstLine: 20,+ bl: BooleanNumber.TRUE,+ },+ },+ {+ st: 2085,+ ed: 2292,+ ts: {+ fs: 16,+ },+ },+ {+ st: 2294,+ ed: 2308,+ ts: {+ fs: 16,+ cl: {+ rgb: 'rgb(0, 0, 211)',},- elements: [- {- eId: 'e1',- st: 1549 + 28,- ed: 1944 + 28,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'Digital twin of the customer (DToC) is a dynamic virtual representation of a customer that simulates and learns to emulate and anticipate behavior. It can be used to modify and enhance the customer experience (CX) and support new digitalization efforts, products, services and opportunities. DToC will take five to 10 years until mainstream adoption but will be transformational to organizations.',- ts: {- fs: 16,- },- },- },- ],- },- },- {- blockId: 'p12',- st: 1945 + 28,- ed: 2019 + 28,- blockType: BlockType.PARAGRAPH,- paragraph: {- paragraphStyle: {- indentFirstLine: 20,+ bl: BooleanNumber.TRUE,+ },+ },+ {+ st: 2309,+ ed: 2436,+ ts: {+ fs: 16,+ },+ },+ {+ st: 2438,+ ed: 2466,+ ts: {+ fs: 16,+ cl: {+ rgb: 'rgb(0, 0, 0)',},- elements: [- {- eId: 'e1',- st: 1945 + 28,- ed: 2019 + 28,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'Other critical technologies in immersive experiences include the following:',- ts: {- fs: 16,- },- },- },- ],- },- },- {- blockId: 'p13',- st: 2020 + 28,- ed: 2250 + 28,- blockType: BlockType.PARAGRAPH,- paragraph: {- paragraphStyle: {- indentFirstLine: 20,+ bl: BooleanNumber.TRUE,+ },+ },+ {+ st: 2467,+ ed: 2626,+ ts: {+ fs: 16,+ },+ },+ ],+ paragraphs: [+ {+ startIndex: 67,+ },+ {+ startIndex: 253,+ paragraphStyle: {+ spaceAbove: 20,+ indentFirstLine: 20,+ },+ },+ {+ startIndex: 404,+ paragraphStyle: {+ spaceAbove: 20,+ indentFirstLine: 20,+ },+ },+ {+ startIndex: 433,+ bullet: {+ listId: 'testBullet',+ nestingLevel: 0,+ textStyle: {+ fs: 20,},- bullet: {- listId: 'unorderedTest',- nestingLevel: 0,- textStyle: {- fs: 20,- },+ },+ paragraphStyle: {+ lineSpacing: 1.5,+ },+ },+ {+ startIndex: 484,+ bullet: {+ listId: 'testBullet',+ nestingLevel: 0,+ textStyle: {+ fs: 20,},- elements: [- {- eId: 'e1',- st: 2020 + 28,- ed: 2042 + 28,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'Decentralized identity ',- ts: {- fs: 16,- cl: {- rgb: 'rgb(0, 0, 211)',- },- bl: BooleanNumber.TRUE,- },- },- },- {- eId: 'e2',- st: 2043 + 28,- ed: 2250 + 28,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: '(DCI) allows an entity (typically a human user) to control their own digital identity by leveraging technologies such as blockchain or other distributed ledger technologies (DLTs), along with digital wallets.',- ts: {- fs: 16,- },- },- },- ],- },- },- {- blockId: 'p14',- st: 2251 + 28,- ed: 2393 + 28,- blockType: BlockType.PARAGRAPH,- paragraph: {- paragraphStyle: {- indentFirstLine: 20,+ },+ paragraphStyle: {+ lineSpacing: 1.5,+ },+ },+ {+ startIndex: 516,+ bullet: {+ listId: 'testBullet',+ nestingLevel: 0,+ textStyle: {+ fs: 20,},- bullet: {- listId: 'unorderedTest',- nestingLevel: 0,- textStyle: {- fs: 20,- },+ },+ paragraphStyle: {+ lineSpacing: 1.5,+ },+ },+ {+ startIndex: 712,+ paragraphStyle: {+ indentFirstLine: 20,+ },+ },+ {+ startIndex: 770,+ paragraphStyle: {+ spaceAbove: 20,+ },+ },+ {+ startIndex: 1243,+ paragraphStyle: {+ spaceAbove: 20,+ indentFirstLine: 20,+ },+ },+ {+ startIndex: 1588,+ paragraphStyle: {+ indentFirstLine: 20,+ },+ },+ {+ startIndex: 1985,+ paragraphStyle: {+ indentFirstLine: 20,+ },+ },+ {+ startIndex: 2061,+ paragraphStyle: {+ indentFirstLine: 20,+ },+ },+ {+ startIndex: 2293,+ paragraphStyle: {+ indentFirstLine: 20,+ },+ bullet: {+ listId: 'unorderedTest',+ nestingLevel: 0,+ textStyle: {+ fs: 20,},- elements: [- {- eId: 'e1',- st: 2251 + 28,- ed: 2265 + 28,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'Digital humans ',- ts: {- fs: 16,- cl: {- rgb: 'rgb(0, 0, 211)',- },- bl: BooleanNumber.TRUE,- },- },- },- {- eId: 'e2',- st: 2266 + 28,- ed: 2393 + 28,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'are interactive, AI-driven representations that have some of the characteristics, personality, knowledge and mindset of a human.',- ts: {- fs: 16,- },- },- },- ],- },- },- {- blockId: 'p15',- st: 2394 + 28,- ed: 2582 + 28,- blockType: BlockType.PARAGRAPH,- paragraph: {- paragraphStyle: {- indentFirstLine: 20,+ },+ },+ {+ startIndex: 2437,+ paragraphStyle: {+ indentFirstLine: 20,+ },+ bullet: {+ listId: 'unorderedTest',+ nestingLevel: 0,+ textStyle: {+ fs: 20,},- bullet: {- listId: 'unorderedTest',- nestingLevel: 0,- textStyle: {- fs: 20,- },+ },+ },+ {+ startIndex: 2627,+ paragraphStyle: {+ indentFirstLine: 20,+ },+ bullet: {+ listId: 'unorderedTest',+ nestingLevel: 0,+ textStyle: {+ fs: 20,},- elements: [- {- eId: 'e1',- st: 2394 + 28,- ed: 2422 + 28,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'Internal talent marketplaces ',- ts: {- fs: 16,- cl: {- rgb: 'rgb(0, 0, 0)',- },- bl: BooleanNumber.TRUE,- },- },- },- {- eId: 'e2',- st: 2423 + 28,- ed: 2582 + 28,- et: ParagraphElementType.TEXT_RUN,- tr: {- ct: 'match internal employees and, in some cases, a pool of contingent workers, to time-boxed projects and various work opportunities, with no recruiter involvement.',- ts: {- fs: 16,- },- },- },- ],- },- },- {- blockId: 'twoSectionBreak',- st: 0,- ed: 0,- blockType: BlockType.SECTION_BREAK,- sectionBreak: {- columnProperties: [- {- width: 200,- paddingEnd: 5,- },- ],- columnSeparatorType: ColumnSeparatorType.NONE,- sectionType: SectionType.SECTION_TYPE_UNSPECIFIED,- // textDirection: textDirectionDocument,- // contentDirection: textDirection!,},},],+ sectionBreaks: [+ {+ startIndex: 1244,+ columnProperties: [],+ columnSeparatorType: ColumnSeparatorType.NONE,+ sectionType: SectionType.SECTION_TYPE_UNSPECIFIED,+ // textDirection: textDirectionDocument,+ // contentDirection: textDirection!,+ },+ {+ startIndex: 2628,+ columnProperties: [+ {+ width: 200,+ paddingEnd: 5,+ },+ ],+ columnSeparatorType: ColumnSeparatorType.NONE,+ sectionType: SectionType.SECTION_TYPE_UNSPECIFIED,+ // textDirection: textDirectionDocument,+ // contentDirection: textDirection!,+ },+ ],+ customBlocks: [+ {+ startIndex: 1242,+ blockId: 'shapeTest1',+ },+ ],},documentStyle: {pageSize: {diff --git a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO.ts b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO.tsindex 03694815ad..67838e2488 100644--- a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO.ts+++ b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO.ts@@ -195,7 +195,7 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookConfig = {socketUrl: '',socketEnable: BooleanNumber.FALSE,extensions: [],- sheetOrder: ['sheet-0010','sheet-0009','sheet-0008','sheet-0007','sheet-0006','sheet-0005','sheet-0004','sheet-0003','sheet-0002','sheet-0001'],+ sheetOrder: ['sheet-0010', 'sheet-0009', 'sheet-0008', 'sheet-0007', 'sheet-0006', 'sheet-0005', 'sheet-0004', 'sheet-0003', 'sheet-0002', 'sheet-0001'],pluginMeta: {},styles: {'1': {diff --git a/packages/core/src/Docs/Apply/Common.ts b/packages/core/src/Docs/Apply/Common.tsindex a39a6746b1..aaa479376c 100644--- a/packages/core/src/Docs/Apply/Common.ts+++ b/packages/core/src/Docs/Apply/Common.ts@@ -1,9 +1,4 @@-import {- IBlockElement,- IDocumentData,- IElement,- ITextRun,-} from '../../Interfaces/IDocumentData';+import { IDocumentData, ITextRun } from '../../Interfaces/IDocumentData';import { deepCompare } from '../../Shared/Compare';export function getTextIndexByCursor(index: number, isBack: boolean = false) {diff --git a/packages/core/src/Docs/Apply/DeleteTextApply.ts b/packages/core/src/Docs/Apply/DeleteTextApply.tsindex 34edd520fb..df01936bb3 100644--- a/packages/core/src/Docs/Apply/DeleteTextApply.ts+++ b/packages/core/src/Docs/Apply/DeleteTextApply.ts@@ -1,10 +1,5 @@import { BooleanNumber } from '../../Enum/TextStyle';-import {- BlockType,- IBlockElement,- IParagraph,- ParagraphElementType,-} from '../../Interfaces/IDocumentData';+import { BlockType, IParagraph } from '../../Interfaces/IDocumentData';import { ITextSelectionRangeParam } from '../../Interfaces/ISelectionData';import { DocumentModel } from '../Domain/DocumentModel';import {diff --git a/packages/core/src/Docs/Apply/InsertTextApply.ts b/packages/core/src/Docs/Apply/InsertTextApply.tsindex bcf92fd6e9..2b40aaa6cb 100644--- a/packages/core/src/Docs/Apply/InsertTextApply.ts+++ b/packages/core/src/Docs/Apply/InsertTextApply.ts@@ -1,11 +1,5 @@import { BooleanNumber } from '../../Enum/TextStyle';-import {- BlockType,- IBlockElement,- IParagraph,- ParagraphElementType,- IElement,-} from '../../Interfaces/IDocumentData';+import { BlockType, IParagraph } from '../../Interfaces/IDocumentData';import { ITextSelectionRangeStartParam } from '../../Interfaces/ISelectionData';import { DocumentModel } from '../Domain/DocumentModel';import {@@ -146,8 +140,6 @@ function splitTextRun() {const trLen = insertTextRunList.length;- const insertFirstEle = insertTextRunList[0];-const insertLastTrEle = insertTextRunList[trLen - 1];const {diff --git a/packages/core/src/Docs/Apply/TextIndexAdjustApply.ts b/packages/core/src/Docs/Apply/TextIndexAdjustApply.tsindex 32bfc4a898..40b4ec5f45 100644--- a/packages/core/src/Docs/Apply/TextIndexAdjustApply.ts+++ b/packages/core/src/Docs/Apply/TextIndexAdjustApply.ts@@ -1,10 +1,4 @@-import {- BlockType,- IBlockElement,- IElement,- IParagraph,- ParagraphElementType,-} from '../../Interfaces/IDocumentData';+import { BlockType, IParagraph } from '../../Interfaces/IDocumentData';import { ITextSelectionRangeParam } from '../../Interfaces/ISelectionData';import { Nullable } from '../../Shared';import { DocumentModel } from '../Domain/DocumentModel';diff --git a/packages/core/src/Docs/Domain/DocumentBodyModel.ts b/packages/core/src/Docs/Domain/DocumentBodyModel.tsnew file mode 100644index 0000000000..66a988c9f3--- /dev/null+++ b/packages/core/src/Docs/Domain/DocumentBodyModel.ts@@ -0,0 +1,432 @@+import { IDocumentBody, ITextRun } from '../../Interfaces/IDocumentData';++export type DocumentBodyModelOrSimple = DocumentBodyModelSimple | DocumentBodyModel;++export class DocumentBodyModelSimple {+ body: IDocumentBody;++ children: DataStreamTreeNode[] = [];++ constructor(body?: IDocumentBody) {+ if (body == null) {+ return;+ }+ this.children = this.transformToTree(this.body.dataStream);+ }++ getSectionBreak(index: number) {+ return this.body.sectionBreaks?.[0];+ }++ getParagraph(index: number) {}++ getTextRun(index: number) {}++ getTextRunRange(startIndex: number = 0, endIndex: number) {+ return [+ {+ st: startIndex,+ ed: endIndex,+ },+ ] as ITextRun[];+ }++ getCustomBlock(index: number) {}++ getTable(index: number) {}++ getCustomRange(index: number) {}++ private transformToTree(dataStream: string) {+ const dataStreamLen = dataStream.length;++ let content = '';+ let sectionList: DataStreamTreeNode[] = [];+ let nodeList: DataStreamTreeNode[] = [];++ for (let i = 0; i < dataStreamLen; i++) {+ const char = dataStream[i];+ if (char === DataStreamTreeTokenType.PARAGRAPH) {+ content += DataStreamTreeTokenType.PARAGRAPH;+ const node = DataStreamTreeNode.create(+ DataStreamTreeNodeType.PARAGRAPH,+ this,+ content + DataStreamTreeTokenType.PARAGRAPH+ );+ node.setIndexRange(i, i + content.length);+ nodeList.push(node);+ content = '';+ } else if (char === DataStreamTreeTokenType.SECTION_BREAK) {+ const sectionTree = DataStreamTreeNode.create(+ DataStreamTreeNodeType.SECTION_BREAK,+ this+ );+ this.batchParent(sectionTree, nodeList);+ sectionList.push(sectionTree);+ nodeList = [];+ } else if (char === DataStreamTreeTokenType.TABLE_START) {+ nodeList.push(+ DataStreamTreeNode.create(DataStreamTreeNodeType.TABLE, this)+ );+ } else if (char === DataStreamTreeTokenType.TABLE_ROW_START) {+ nodeList.push(+ DataStreamTreeNode.create(DataStreamTreeNodeType.TABLE_ROW, this)+ );+ } else if (char === DataStreamTreeTokenType.TABLE_CELL_START) {+ nodeList.push(+ DataStreamTreeNode.create(+ DataStreamTreeNodeType.TABLE_CELL,+ this+ )+ );+ } else if (char === DataStreamTreeTokenType.TABLE_END) {+ this.processPreviousNodesUntil(+ nodeList,+ DataStreamTreeNodeType.TABLE+ );+ } else if (char === DataStreamTreeTokenType.TABLE_ROW_END) {+ this.processPreviousNodesUntil(+ nodeList,+ DataStreamTreeNodeType.TABLE_ROW+ );+ } else if (char === DataStreamTreeTokenType.TABLE_CELL_END) {+ this.processPreviousNodesUntil(+ nodeList,+ DataStreamTreeNodeType.TABLE_CELL+ );+ } else {+ content += char;+ }+ }++ return sectionList;+ }++ private processPreviousNodesUntil(+ nodeList: DataStreamTreeNode[],+ untilNodeType: DataStreamTreeNodeType+ ) {+ const nodeCollection: DataStreamTreeNode[] = [];+ let node = nodeList.pop();+ while (node) {+ if (node.nodeType === untilNodeType) {+ break;+ }++ nodeCollection.push(node);++ node = nodeList.pop();+ }++ const recentTree = nodeList[nodeList.length - 1];+ this.batchParent(recentTree, nodeCollection, DataStreamTreeNodeType.TABLE);+ }++ private batchParent(+ parent: DataStreamTreeNode,+ children: DataStreamTreeNode[],+ nodeType = DataStreamTreeNodeType.SECTION_BREAK+ ) {+ for (let child of children) {+ child.parent = parent;+ parent.children.push(child);+ }++ const startOffset =+ nodeType === DataStreamTreeNodeType.SECTION_BREAK ? 0 : 1;++ parent.setIndexRange(+ children[0].startIndex - startOffset,+ children[children.length - 1].endIndex + 1+ );+ }+}++export class DocumentBodyModel extends DocumentBodyModelSimple {+ private sectionBreakCurrentIndex = 0;++ private paragraphCurrentIndex = 0;++ private textRunCurrentIndex = 0;++ private customBlockCurrentIndex = 0;++ private tableBlockCurrentIndex = 0;++ private customRangeCurrentIndex = 0;++ static create(body?: IDocumentBody) {+ return new DocumentBodyModel(body);+ }++ insert() {}++ update() {}++ delete() {}++ resetCache() {+ this.sectionBreakCurrentIndex = 0;+ this.paragraphCurrentIndex = 0;+ this.textRunCurrentIndex = 0;+ this.customBlockCurrentIndex = 0;+ this.tableBlockCurrentIndex = 0;+ this.customRangeCurrentIndex = 0;+ }++ getSectionBreak(index: number) {+ const sectionBreaks = this.body.sectionBreaks;+ if (sectionBreaks == null) {+ return;+ }++ for (let i = this.sectionBreakCurrentIndex; i < sectionBreaks.length; i++) {+ const sectionBreak = sectionBreaks[i];+ if (sectionBreak.startIndex === index) {+ this.sectionBreakCurrentIndex = i;+ return sectionBreak;+ }+ }+ }++ getParagraph(index: number) {+ const paragraphs = this.body.paragraphs;+ if (paragraphs == null) {+ return;+ }++ for (let i = this.paragraphCurrentIndex; i < paragraphs.length; i++) {+ const paragraph = paragraphs[i];+ if (paragraph.startIndex === index) {+ this.paragraphCurrentIndex = i;+ return paragraph;+ }+ }+ }++ getTextRunRange(startIndex: number = 0, endIndex: number) {+ const textRuns = this.body.textRuns;+ if (textRuns == null) {+ return [+ {+ st: startIndex,+ ed: endIndex,+ },+ ];+ }++ const trRange: ITextRun[] = [];++ for (+ let i = this.textRunCurrentIndex, textRunsLen = textRuns.length;+ i < textRunsLen;+ i+++ ) {+ const textRun = textRuns[i];+ if (textRun.st > endIndex) {+ this.textRunCurrentIndex = i;+ break;+ } else if (textRun.ed < startIndex) {+ this.textRunCurrentIndex = i;+ continue;+ } else {+ trRange.push({+ st: textRun.st < startIndex ? startIndex : textRun.st,+ ed: textRun.ed > endIndex ? endIndex : textRun.ed,+ sId: textRun.sId,+ ts: textRun.ts,+ });+ this.textRunCurrentIndex = i;+ }+ }++ const firstTr = trRange[0] || { st: endIndex + 1 };+ if (firstTr.st > startIndex) {+ trRange.push({+ st: startIndex,+ ed: firstTr.st - 1,+ });+ }++ const lastTr = trRange[trRange.length - 1] || { ed: startIndex - 1 };+ if (lastTr.ed < endIndex) {+ trRange.push({+ st: lastTr.ed + 1,+ ed: endIndex,+ });+ }++ return trRange;+ }++ getTextRun(index: number) {+ const textRuns = this.body.textRuns;+ if (textRuns == null) {+ return;+ }++ const curTextRun = textRuns[this.textRunCurrentIndex];+ if (curTextRun != null) {+ if (index >= curTextRun.st && index <= curTextRun.ed) {+ return curTextRun;+ }++ if (index < curTextRun.st) {+ return;+ }+ }++ for (+ let i = this.textRunCurrentIndex, textRunsLen = textRuns.length;+ i < textRunsLen;+ i+++ ) {+ const textRun = textRuns[i];+ if (index >= textRun.st && index <= textRun.ed) {+ this.textRunCurrentIndex = i;+ return textRun;+ }+ }+ }++ getCustomBlock(index: number) {+ const customBlocks = this.body.customBlocks;+ if (customBlocks == null) {+ return;+ }++ for (let i = this.customBlockCurrentIndex; i < customBlocks.length; i++) {+ const customBlock = customBlocks[i];+ if (customBlock.startIndex === index) {+ this.customBlockCurrentIndex = i;+ return customBlock;+ }+ }+ }++ getTable(index: number) {+ const tables = this.body.tables;+ if (tables == null) {+ return;+ }++ for (let i = this.tableBlockCurrentIndex; i < tables.length; i++) {+ const table = tables[i];+ if (table.startIndex === index) {+ this.tableBlockCurrentIndex = i;+ return table;+ }+ }+ }++ getCustomRange(index: number) {+ const customRanges = this.body.customRanges;+ if (customRanges == null) {+ return;+ }+ for (+ let i = 0, customRangesLen = customRanges.length;+ i < customRangesLen;+ i+++ ) {+ const customRange = customRanges[i];+ if (index >= customRange.startIndex && index <= customRange.endIndex) {+ return customRange;+ }+ }+ }++ private move() {}++ private split() {}++ private merge() {}+}++export class DataStreamTreeNode {+ children: DataStreamTreeNode[] = [];++ parent: DataStreamTreeNode;++ startIndex: number;++ endIndex: number;++ constructor(+ public nodeType: DataStreamTreeNodeType,+ public bodyModel: DocumentBodyModelOrSimple,+ public content?: string+ ) {}++ static create(+ nodeType: DataStreamTreeNodeType,+ bodyModel: DocumentBodyModelOrSimple,+ content?: string+ ) {+ return new DataStreamTreeNode(nodeType, bodyModel, content);+ }++ forEach(+ func: (+ content: string,+ startIndex: number,+ endIndex: number,+ type: DataStreamTreeNodeType+ ) => void+ ) {+ for (let child of this.children) {+ child.forEach(func);+ }+ func(this.content || '', this.startIndex, this.endIndex, this.nodeType);+ }++ setIndexRange(startIndex: number, endIndex: number) {}++ include(index: number) {}++ plus(len: number) {}++ minus(len: number) {}++ moveTo(newParent: DataStreamTreeNode) {}+}++export enum DataStreamTreeNodeType {+ // COLUMN_BREAK, // \v 换列+ // PAGE_BREAK, // \f 换页+ // DOCS_END, // \0 文档结尾+ // TAB, // \t 制表符+ PARAGRAPH, // \r 段落+ SECTION_BREAK, // \n 章节+ TABLE,+ TABLE_ROW,+ TABLE_CELL,+ // CUSTOM_BLOCK, // \b 图片 mention等不参与文档流的场景+ // TABLE_START, // \x1A 表格开始+ // TABLE_ROW_START, // \x1B 表格开始+ // TABLE_CELL_START, // \x1C 表格开始+ // TABLE_CELL_END, //* \x1D 表格开始+ // TABLE_ROW_END, // \x1E 表格开始+ // TABLE_END, // \x1F 表格结束+ // CUSTOM_RANGE_START, // \x1F 自定义范围开始+ // CUSTOM_RANGE_END, // \x1E 自定义范围结束+}++export enum DataStreamTreeTokenType {+ PARAGRAPH = '\r', // 段落+ SECTION_BREAK = '\n', // 章节+ TABLE_START = '\x1A', // 表格开始+ TABLE_ROW_START = '\x1B', // 表格开始+ TABLE_CELL_START = '\x1C', // 表格开始+ TABLE_CELL_END = '\x1D', // 表格开始+ TABLE_ROW_END = '\x1E', // 表格开始+ TABLE_END = '\x1F', // 表格结束+ CUSTOM_RANGE_START = '\x1F', // 自定义范围开始+ CUSTOM_RANGE_END = '\x1E', // 自定义范围结束++ COLUMN_BREAK = '\v', // 换列+ PAGE_BREAK = '\f', // 换页+ DOCS_END = '\0', // 文档结尾+ TAB = '\t', // 制表符+ CUSTOM_BLOCK = '\b', // 图片 mention等不参与文档流的场景+}diff --git a/packages/core/src/Docs/Domain/DocumentModel.ts b/packages/core/src/Docs/Domain/DocumentModel.tsindex 4287ae8572..9e75f5649e 100644--- a/packages/core/src/Docs/Domain/DocumentModel.ts+++ b/packages/core/src/Docs/Domain/DocumentModel.ts@@ -1,31 +1,101 @@import { DocContext } from '../../Basics';-import { Command } from '../../Command';-import {- BlockType,- IDocumentData,- ITextRun,- ITextSelectionRange,-} from '../../Interfaces';-import { DEFAULT_DOC } from '../../Const';+import { Command, IActionData } from '../../Command';+import { IDocumentData, ITextRun, ITextSelectionRange } from '../../Interfaces';import { DOC_ACTION_NAMES } from '../../Const/DOC_ACTION_NAMES';import { getDocsUpdateBody } from '../Apply/Common';import { Nullable, Tools } from '../../Shared';+import { DocumentBodyModel } from './DocumentBodyModel';-export class DocumentModel {- private _snapshot: IDocumentData;+interface IDrawingUpdateConfig {+ left: number;+ top: number;+ height: number;+ width: number;+}++export type DocumentModelOrSimple = DocumentModelSimple | DocumentModel;++export class DocumentModelSimple {+ snapshot: IDocumentData;++ headerTreeMap: Map<string, DocumentBodyModel>;++ footerTreeMap: Map<string, DocumentBodyModel>;++ bodyModel: DocumentBodyModel;++ constructor(snapshot: IDocumentData) {+ this.snapshot = snapshot;++ this.bodyModel = DocumentBodyModel.create(this.snapshot.body);+ }++ get drawings() {+ return this.snapshot.drawings;+ }++ get documentStyle() {+ return this.snapshot.documentStyle;+ }++ get lists() {+ return this.snapshot.lists;+ }++ updateDocumentDataPageSize(width?: number, height?: number) {+ const documentStyle = this.snapshot.documentStyle;+ if (!documentStyle.pageSize) {+ width = width ?? Infinity;+ height = height ?? Infinity;+ documentStyle.pageSize = {+ width,+ height,+ };+ return;+ }+ if (width !== undefined) {+ documentStyle.pageSize.width = width;+ }++ if (height !== undefined) {+ documentStyle.pageSize.height = height;+ }+ }++ updateDrawing(id: string, config: IDrawingUpdateConfig) {+ const drawings = this.drawings;+ if (!drawings) {+ return;+ }++ const drawing = drawings[id];++ if (!drawing) {+ return;+ }++ const objectProperties = drawing.objectProperties;++ objectProperties.size.width = config.width;+ objectProperties.size.height = config.height;++ objectProperties.positionH.posOffset = config.left;+ objectProperties.positionV.posOffset = config.top;+ }+}++export class DocumentModel extends DocumentModelSimple {private _context: DocContext;private _unitId: string;- constructor(snapshot: Partial<IDocumentData>, context: DocContext) {+ constructor(snapshot: IDocumentData, context: DocContext) {+ super(snapshot);this._context = context;- this._snapshot = { ...DEFAULT_DOC, ...snapshot };- this._unitId = this._snapshot.id ?? Tools.generateRandomId(6);- }+ this._unitId = this.snapshot.id ?? Tools.generateRandomId(6);- getSnapshot() {- return this._snapshot;+ this.initializeRowColTree();}getUnitId(): string {@@ -89,7 +159,7 @@ export class DocumentModel {// length: oldText.length,// segmentId,// };- const deleteTextActionList = [];+ const deleteTextActionList: IActionData[] = [];if (oldText.length > 0) {deleteTextActionList.push(@@ -143,6 +213,33 @@ export class DocumentModel {return this;}+ private initializeRowColTree() {+ this.headerTreeMap = new Map();+ this.footerTreeMap = new Map();++ const { headers, footers } = this.snapshot;++ if (headers) {+ for (let headerId in headers) {+ const header = headers[headerId];+ this.headerTreeMap.set(+ headerId,+ DocumentBodyModel.create(header.body)+ );+ }+ }++ if (footers) {+ for (let footerId in footers) {+ const footer = footers[footerId];+ this.footerTreeMap.set(+ footerId,+ DocumentBodyModel.create(footer.body)+ );+ }+ }+ }+private _addTextIndexAdustAction(range: ITextSelectionRange,segmentId?: string@@ -189,19 +286,16 @@ export class DocumentModel {range: ITextSelectionRange,segmentId?: string) {- const snapshot = this._snapshot;+ const snapshot = this.snapshot;const body = getDocsUpdateBody(snapshot, segmentId);if (body == null) {return [];}-- const { blockElements } = body;-const { cursorStart, isCollapse, isStartBack } = range;- const actionList = [];+ // const actionList = [];let startBlockId: Nullable<string> = null;@@ -209,71 +303,73 @@ export class DocumentModel {let preBlockId: Nullable<string> = null;- for (let blockElement of blockElements) {- if (blockElement == null) {- continue;- }-- const { blockType, st, ed, blockId } = blockElement;-- if (blockType === BlockType.PARAGRAPH) {- if (cursorStart > ed || cursorStart < st) {- continue;- }-- if (cursorStart === st && isStartBack) {- if (blockElement.paragraph?.bullet) {- // bullet- actionList.push({- actionName: DOC_ACTION_NAMES.DELETE_BULLET_ACTION_NAME,- blockId,- blockElement,- segmentId,- });- } else {- startBlockId = preBlockId;- endBlockId = blockId;- }- } else {- // textRun- actionList.push({- actionName: DOC_ACTION_NAMES.DELETE_TEXT_ACTION_NAME,- cursorStart,- cursorEnd: cursorStart,- isCollapse: true,- isEndBack: isStartBack,- isStartBack,- segmentId,- });- }- }-- preBlockId = blockId;- }-- if (- startBlockId != null &&- endBlockId != null &&- startBlockId !== endBlockId- ) {- actionList.push({- actionName: DOC_ACTION_NAMES.MERGE_PARAGRAPH_ACTION_NAME,- startBlockId,- endBlockId,- segmentId,- cursorStart,- isStartBack,- });- }-- return actionList;+ // const { blockElements } = body;++ // for (let blockElement of blockElements) {+ // if (blockElement == null) {+ // continue;+ // }++ // const { blockType, st, ed, blockId } = blockElement;++ // if (blockType === BlockType.PARAGRAPH) {+ // if (cursorStart > ed || cursorStart < st) {+ // continue;+ // }++ // if (cursorStart === st && isStartBack) {+ // if (blockElement.paragraph?.bullet) {+ // // bullet+ // actionList.push({+ // actionName: DOC_ACTION_NAMES.DELETE_BULLET_ACTION_NAME,+ // blockId,+ // blockElement,+ // segmentId,+ // });+ // } else {+ // startBlockId = preBlockId;+ // endBlockId = blockId;+ // }+ // } else {+ // // textRun+ // actionList.push({+ // actionName: DOC_ACTION_NAMES.DELETE_TEXT_ACTION_NAME,+ // cursorStart,+ // cursorEnd: cursorStart,+ // isCollapse: true,+ // isEndBack: isStartBack,+ // isStartBack,+ // segmentId,+ // });+ // }+ // }++ // preBlockId = blockId;+ // }++ // if (+ // startBlockId != null &&+ // endBlockId != null &&+ // startBlockId !== endBlockId+ // ) {+ // actionList.push({+ // actionName: DOC_ACTION_NAMES.MERGE_PARAGRAPH_ACTION_NAME,+ // startBlockId,+ // endBlockId,+ // segmentId,+ // cursorStart,+ // isStartBack,+ // });+ // }++ return [];}private _getDeleteTextActionRange(range: ITextSelectionRange,segmentId?: string) {- const snapshot = this._snapshot;+ const snapshot = this.snapshot;const body = getDocsUpdateBody(snapshot, segmentId);@@ -281,8 +377,6 @@ export class DocumentModel {return [];}- const { blockElements } = body;-const { cursorStart, cursorEnd, isCollapse, isEndBack, isStartBack } = range;const actionList = [];@@ -291,87 +385,91 @@ export class DocumentModel {let endBlockId: Nullable<string> = null;- for (let blockElement of blockElements) {- if (blockElement == null) {- continue;- }-- const { blockType, st, ed, blockId } = blockElement;-- if (blockType === BlockType.PARAGRAPH) {- if (cursorStart > ed || cursorEnd < st) {- continue;- }-- let start = st;-- let end = ed;-- let isStartBackCurrent = isStartBack;-- let isEndBackCurrent = isEndBack;-- if (st <= cursorStart && ed >= cursorStart) {- startBlockId = blockId;- start = cursorStart;- } else {- isStartBackCurrent = true;- }-- if (st <= cursorEnd && ed >= cursorEnd) {- endBlockId = blockId;- end = cursorEnd;- } else {- isEndBackCurrent = false;- }-- if (- (cursorStart < st || (cursorStart === st && isStartBack)) &&- (cursorEnd > ed || (cursorEnd === ed && !isEndBack)) &&- !isCollapse- ) {- // Paragraph- actionList.push({- actionName: DOC_ACTION_NAMES.DELETE_PARAGRAPH_ACTION_NAME,- cursorStart: st,- cursorEnd: ed,- isCollapse: false,- isEndBack: false,- isStartBack: true,- blockId,- blockElement,- segmentId,- });- } else {- // textRun- actionList.push({- actionName: DOC_ACTION_NAMES.DELETE_TEXT_ACTION_NAME,- cursorStart: start,- cursorEnd: end,- isCollapse,- isEndBack: isEndBackCurrent,- isStartBack: isStartBackCurrent,- segmentId,- });- }- }- }-- if (- startBlockId != null &&- endBlockId != null &&- startBlockId !== endBlockId- ) {- actionList.push({- actionName: DOC_ACTION_NAMES.MERGE_PARAGRAPH_ACTION_NAME,- startBlockId,- endBlockId,- segmentId,- cursorStart,- isStartBack,- });- }-- return actionList;+ return [];++ // const { blockElements } = body;++ // for (let blockElement of blockElements) {+ // if (blockElement == null) {+ // continue;+ // }++ // const { blockType, st, ed, blockId } = blockElement;++ // if (blockType === BlockType.PARAGRAPH) {+ // if (cursorStart > ed || cursorEnd < st) {+ // continue;+ // }++ // let start = st;++ // let end = ed;++ // let isStartBackCurrent = isStartBack;++ // let isEndBackCurrent = isEndBack;++ // if (st <= cursorStart && ed >= cursorStart) {+ // startBlockId = blockId;+ // start = cursorStart;+ // } else {+ // isStartBackCurrent = true;+ // }++ // if (st <= cursorEnd && ed >= cursorEnd) {+ // endBlockId = blockId;+ // end = cursorEnd;+ // } else {+ // isEndBackCurrent = false;+ // }++ // if (+ // (cursorStart < st || (cursorStart === st && isStartBack)) &&+ // (cursorEnd > ed || (cursorEnd === ed && !isEndBack)) &&+ // !isCollapse+ // ) {+ // // Paragraph+ // actionList.push({+ // actionName: DOC_ACTION_NAMES.DELETE_PARAGRAPH_ACTION_NAME,+ // cursorStart: st,+ // cursorEnd: ed,+ // isCollapse: false,+ // isEndBack: false,+ // isStartBack: true,+ // blockId,+ // blockElement,+ // segmentId,+ // });+ // } else {+ // // textRun+ // actionList.push({+ // actionName: DOC_ACTION_NAMES.DELETE_TEXT_ACTION_NAME,+ // cursorStart: start,+ // cursorEnd: end,+ // isCollapse,+ // isEndBack: isEndBackCurrent,+ // isStartBack: isStartBackCurrent,+ // segmentId,+ // });+ // }+ // }+ // }++ // if (+ // startBlockId != null &&+ // endBlockId != null &&+ // startBlockId !== endBlockId+ // ) {+ // actionList.push({+ // actionName: DOC_ACTION_NAMES.MERGE_PARAGRAPH_ACTION_NAME,+ // startBlockId,+ // endBlockId,+ // segmentId,+ // cursorStart,+ // isStartBack,+ // });+ // }++ // return actionList;}}diff --git a/packages/core/src/Docs/Domain/index.ts b/packages/core/src/Docs/Domain/index.tsindex 94fa326abe..c08bfc8db2 100644--- a/packages/core/src/Docs/Domain/index.ts+++ b/packages/core/src/Docs/Domain/index.ts@@ -1 +1,2 @@export * from './DocumentModel';+export * from './DocumentBodyModel';diff --git a/packages/core/src/Interfaces/IDocumentData.ts b/packages/core/src/Interfaces/IDocumentData.tsindex 7066da6af2..8c11855448 100644--- a/packages/core/src/Interfaces/IDocumentData.ts+++ b/packages/core/src/Interfaces/IDocumentData.ts@@ -57,6 +57,13 @@ export interface IDrawings {[objectId: string]: IDrawing;}+/**+ * Set of IStyles+ */+export interface IDocStyles {+ [styleId: string]: IDocStyle;+}+/*** A width and height.*/@@ -67,9 +74,37 @@ export interface ISizeData {/*** Properties of document body+ * 三种更新类型,范围叠加、范围互斥、占位符*/export interface IDocumentBody {- blockElements: IBlockElement[]; // block elements+ dataStream: string;++ textRuns?: ITextRun[]; // textRun 样式,交互++ paragraphs?: IParagraph[]; // paragraph+ sectionBreaks?: ISectionBreak[]; // SectionBreak https://support.microsoft.com/en-us/office/insert-a-section-break-eef20fd8-e38c-4ba6-a027-e503bdf8375c+ customBlocks?: ICustomBlock[]; // customBlock 用户通过插件自定义的block+ tables?: ITable[]; // table+ // tableOfContents?: { [index: number]: ITableOfContent }; // tableOfContents 目录+ // links?: { [index: number]: IHyperlink }; // links 超链接+ customRanges?: ICustomRange[]; // plugin注册,实现针对stream的特殊逻辑,超链接,field,structured document tags, bookmark,comment+}++export interface placeHolder {}++export interface IDocStyle {+ name: string;+ basedOn: string;+ link: string;+ type: DocStyleType;+ textStyle: ITextStyle;+}++export enum DocStyleType {+ character,+ paragraph,+ table,+ numbering,}/**@@ -147,31 +182,21 @@ export enum BulletAlignment {END, // The bullet is aligned to the end of the space allotted for rendering the bullet. Right-aligned for LTR text, left-aligned otherwise.}-/**- * Properties of block element- */-export interface IBlockElement {- blockId: string; // blockId- st: number; // startIndex- ed: number; // endIndex- blockType: BlockType; // blockType- // Union field content can be only one of the following:- paragraph?: IParagraph; // paragraph- table?: ITable; // table- sectionBreak?: ISectionBreak; // SectionBreak https://support.microsoft.com/en-us/office/insert-a-section-break-eef20fd8-e38c-4ba6-a027-e503bdf8375c- tableOfContents?: IDocumentBody; // tableOfContents 目录- customBlock?: ICustomBlock; // customBlock 用户通过插件自定义的block-}--/**- * Type of block- */-export enum BlockType {- PARAGRAPH,- TABLE,- SECTION_BREAK,- CUSTOM,-}+// /**+// * Properties of block element+// */+// export interface IBlockElement {+// blockId: string; // blockId+// st: number; // startIndex+// ed: number; // endIndex+// blockType: BlockType; // blockType+// // Union field content can be only one of the following:+// paragraph?: IParagraph; // paragraph+// table?: ITable; // table+// sectionBreak?: ISectionBreak; // SectionBreak https://support.microsoft.com/en-us/office/insert-a-section-break-eef20fd8-e38c-4ba6-a027-e503bdf8375c+// tableOfContents?: IDocumentBody; // tableOfContents 目录+// customBlock?: ICustomBlock; // customBlock 用户通过插件自定义的block+// }export interface IMargin {marginTop?: number; // marginTop@@ -180,11 +205,58 @@ export interface IMargin {marginLeft?: number; // marginLeft}+export interface ITableOfContent {}++export interface IHyperlink {+ url?: string;+ bookmarkId?: string; // bookmarkId+ headingId?: string; // headingId+}++/**+ * A ParagraphElement that represents a run of text that all has the same styling.+ */+export interface ITextRun {+ // ct?: string; // content+ // len: number;+ st: number;+ ed: number;+ sId?: string; // styleID+ ts?: ITextStyle; // textStyle+ // tab?: BooleanNumber; // 是否tab,默认为false+}++export interface ICustomRange {+ startIndex: number;+ endIndex: number;+ rangeId: string;+ rangeType: CustomRangeType;+}++export enum CustomRangeType {+ HYPERLINK,+ FIELD, // 17.16 Fields and Hyperlinks+ SDT, // 17.5.2 Structured Document Tags+ BOOKMARK,+ COMMENT,+ CUSTOM,+}+/*** Custom Block*/-export interface ICustomBlock extends IMargin {- size: ISizeData;+export interface ICustomBlock {+ startIndex: number;+ blockType?: BlockType;+ blockId: string;+}++/**+ * Type of block+ */+export enum BlockType {+ DRAWING,+ CUSTOM,}export interface IHeaderAndFooterBase {@@ -266,7 +338,9 @@ export interface ISectionBreakBase {export interface ISectionBreakextends IDocStyleBase,ISectionBreakBase,- IHeaderAndFooterBase {}+ IHeaderAndFooterBase {+ startIndex: number;+}/*** Represents how the start of the current section is positioned relative to the previous section.@@ -306,47 +380,48 @@ export interface ISectionColumnProperties {}export interface IParagraph {- elements: IElement[]; // elements+ // elements: IElement[]; // elements+ startIndex: number;paragraphStyle?: IParagraphStyle; // paragraphStylebullet?: IBullet; // bullet// dIds?: string[]; // drawingIds objectId}-export interface IElementsOrder {- elementId: string; // elementId- paragraphElementType: ParagraphElementType; // paragraphElementType-}+// export interface IElementsOrder {+// elementId: string; // elementId+// paragraphElementType: ParagraphElementType; // paragraphElementType+// }-/**- * Properties of paragraph- */-export interface IElement {- eId: string; // elementId- st: number; // startIndex- ed: number; // endIndex- et: ParagraphElementType; // ParagraphElementType- // Union field content can be only one of the following:- tr?: ITextRun; // textRun- // dr?: IDrawing; // inlineDrawing https://developers.google.com/docs/api/reference/rest/v1/documents#InlineObjectElement- // https://developers.google.com/docs/api/reference/rest/v1/documents#AutoText- autoText?: {}; // autoText- pageBreak?: {}; // pageBreak- columnBreak?: {}; // columnBreak- footnoteReference?: {}; // footnoteReference- horizontalRule?: {}; // horizontalRule- equation?: {}; // equation- person?: {}; // person- richLink?: {}; // richLink- custom?: ICustomElement; // custom element-}--export interface ICustomElement {- size: ISizeData;-}+// /**+// * Properties of paragraph+// */+// export interface IElement {+// eId: string; // elementId+// st: number; // startIndex+// ed: number; // endIndex+// et: ParagraphElementType; // ParagraphElementType+// // Union field content can be only one of the following:+// tr?: ITextRun; // textRun+// // dr?: IDrawing; // inlineDrawing https://developers.google.com/docs/api/reference/rest/v1/documents#InlineObjectElement+// // https://developers.google.com/docs/api/reference/rest/v1/documents#AutoText+// autoText?: {}; // autoText+// pageBreak?: {}; // pageBreak+// columnBreak?: {}; // columnBreak+// footnoteReference?: {}; // footnoteReference+// horizontalRule?: {}; // horizontalRule+// equation?: {}; // equation+// person?: {}; // person+// richLink?: {}; // richLink+// custom?: ICustomElement; // custom element+// }-/**- * Types of paragraph element- */+// export interface ICustomElement {+// size: ISizeData;+// }++// /**+// * Types of paragraph element+// */export enum ParagraphElementType {TEXT_RUN,AUTO_TEXT,@@ -360,15 +435,6 @@ export enum ParagraphElementType {RICH_LINK,}-/**- * A ParagraphElement that represents a run of text that all has the same styling.- */-export interface ITextRun {- ct?: string; // content- ts?: ITextStyle; // textStyle- tab?: BooleanNumber; // 是否tab,默认为false-}-/*** Properties of list*/@@ -465,14 +531,6 @@ export interface ITextStyle extends IStyleBase {pos?: number; // positionsa?: number; // scale}-/**- * 3 选 1- */-interface ILink {- url?: string;- bookmarkId?: string; // bookmarkId- headingId?: string; // headingId-}export interface IIndentStart {indentFirstLine?: INumberUnit | number; // indentFirstLine,17.3.1.12 ind (Paragraph Indentation)@@ -601,6 +659,8 @@ export enum WidthType {* Properties of table*/export interface ITable {+ startIndex: number;+ endIndex: number;rows: number; // rowscolumns: number; // columnstableRows: ITableRow[]; // tableRows@@ -629,9 +689,9 @@ export interface ITableRowStyle {* Properties of table cell*/export interface ITableCell {- st: number; // startIndex- ed: number; // endIndex- content: IBlockElement[]; // content+ // st: number; // startIndex+ // ed: number; // endIndex+ // content: IBlockElement[]; // contenttableCellStyle: ITableCellStyle; // tableCellStyle}diff --git a/packages/core/src/Shared/Common.ts b/packages/core/src/Shared/Common.tsindex 677ef9e159..3780fc1d22 100644--- a/packages/core/src/Shared/Common.ts+++ b/packages/core/src/Shared/Common.ts@@ -5,10 +5,8 @@ import {ISelection,ICellData,IColorStyle,- BlockType,IDocumentData,IStyleData,- ParagraphElementType,} from '../Interfaces';import { ColorBuilder } from '../Sheets/Domain';import {@@ -118,41 +116,42 @@ export function isFormulaString(value: any): boolean {* @param p*/export function handleJsonToDom(p: IDocumentData): string {- let span = '';- // let span = `<span id="${p.id}">`;- if (p.body?.blockElements) {- for (let k in p.body.blockElements) {- const section = p.body.blockElements[k];- if (- section.blockType !== BlockType.PARAGRAPH &&- section.blockType !== BlockType.SECTION_BREAK- ) {- continue;- }- if (section.blockType === BlockType.PARAGRAPH) {- for (let i in section.paragraph) {- const element = section.paragraph[i];- for (let j in element) {- const item = element[j];- if (item.et === ParagraphElementType.TEXT_RUN) {- let style = `display:inline-block;${handleStyleToString(- item.tr.ts- )}`;- span += `<span id='${item.eId}' ${- style.length ? `style="${style}"` : ''- } >${item.tr.ct}</span>`;- }- }- }- }- // else if (section.blockType === BlockType.SECTION_BREAK) {- // span += '<br/>';- // }- }- }+ // let span = '';+ // // let span = `<span id="${p.id}">`;+ // if (p.body?.blockElements) {+ // for (let k in p.body.blockElements) {+ // const section = p.body.blockElements[k];+ // if (+ // section.blockType !== BlockType.PARAGRAPH &&+ // section.blockType !== BlockType.SECTION_BREAK+ // ) {+ // continue;+ // }+ // if (section.blockType === BlockType.PARAGRAPH) {+ // for (let i in section.paragraph) {+ // const element = section.paragraph[i];+ // for (let j in element) {+ // const item = element[j];+ // if (item.et === ParagraphElementType.TEXT_RUN) {+ // let style = `display:inline-block;${handleStyleToString(+ // item.tr.ts+ // )}`;+ // span += `<span id='${item.eId}' ${+ // style.length ? `style="${style}"` : ''+ // } >${item.tr.ct}</span>`;+ // }+ // }+ // }+ // }+ // // else if (section.blockType === BlockType.SECTION_BREAK) {+ // // span += '<br/>';+ // // }+ // }+ // }- // span += '</span>';- return span;+ // // span += '</span>';+ // return span;+ return '';}/**